Skip to content

Commit

Permalink
Merge pull request #20 from mkrufky/escape-quotes-dr_4d#15
Browse files Browse the repository at this point in the history
escape name & text in EIT descriptor 0x4d before storage for now -
this functionality should eventually be moved to the rendering portion rather than stored.
  • Loading branch information
mkrufky committed Jun 20, 2016
2 parents e229849 + 97c1393 commit 43a02ac
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
20 changes: 18 additions & 2 deletions libdvbtee/decode/descriptor/desc_4d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
*
*****************************************************************************/

#include <stdlib.h>

#include "desc_4d.h"

#include "dvbpsi/dr_4d.h" /* short event descriptor */
Expand Down Expand Up @@ -53,8 +55,22 @@ desc_4d::desc_4d(Decoder *parent, dvbpsi_descriptor_t *p_descriptor)
get_descriptor_text(dr->i_text, dr->i_text_length, text);

set("lang", std::string((const char*)lang));
set("name", std::string((const char*)name));
set("text", std::string((const char*)text));

/* FIXME: we should escape these strings on output rather than on store */
if (strchr((char*)name, '"')) {
char* escaped = escape_quotes((char*)name);
set("name", std::string(escaped));
free(escaped);
} else {
set("name", std::string((char*)name));
}
if (strchr((char*)text, '"')) {
char* escaped = escape_quotes((char*)text);
set("text", std::string(escaped));
free(escaped);
} else {
set("text", std::string((char*)text));
}

dPrintf("%s", toJson().c_str());

Expand Down
14 changes: 14 additions & 0 deletions libdvbtee/functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,3 +287,17 @@ char *url_decode(char *str) {
*pbuf = '\0';
return buf;
}

/* Returns a quote-escaped version of str */
/* IMPORTANT: be sure to free() the returned string after use */
char *escape_quotes(char *str) {
char *pstr = str, *buf = (char *)malloc(strlen(str) * 2 + 1), *pbuf = buf;
while (*pstr) {
if (*pstr == '"')
*pbuf++ = '\\';
*pbuf++ = *pstr;
pstr++;
}
*pbuf = '\0';
return buf;
}
1 change: 1 addition & 0 deletions libdvbtee/functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,6 @@ time_t atsc_datetime_utc(uint32_t in_time);
int decode_multiple_string(const uint8_t* data, uint8_t len, unsigned char* text, size_t sizeof_text);

char *url_encode(char *str);
char *escape_quotes(char *str);

#endif /* __FUNCTIONS_H__ */

0 comments on commit 43a02ac

Please sign in to comment.