* Escape video tags.

This commit is contained in:
Justin Maggard 2011-04-21 08:50:44 +00:00
parent 5c7cf70e02
commit 88b992bd51
7 changed files with 30 additions and 33 deletions

View File

@ -118,7 +118,7 @@ inotify.o: inotify.h playlist.h
image_utils.o: image_utils.h image_utils.o: image_utils.h
tivo_utils.o: config.h tivo_utils.h tivo_utils.o: config.h tivo_utils.h
tivo_beacon.o: config.h tivo_beacon.h tivo_utils.h tivo_beacon.o: config.h tivo_beacon.h tivo_utils.h
tivo_commands.o: config.h tivo_commands.h tivo_utils.h tivo_commands.o: config.h tivo_commands.h tivo_utils.h utils.h
utils.o: utils.h utils.o: utils.h
sql.o: sql.h sql.o: sql.h
log.o: log.h log.o: log.h

View File

@ -492,9 +492,7 @@ inotify_insert_directory(int fd, char *name, const char * path)
{ {
if( e->d_name[0] == '.' ) if( e->d_name[0] == '.' )
continue; continue;
esc_name = escape_tag(e->d_name); esc_name = escape_tag(e->d_name, 1);
if( !esc_name )
esc_name = strdup(e->d_name);
asprintf(&path_buf, "%s/%s", path, e->d_name); asprintf(&path_buf, "%s/%s", path, e->d_name);
switch( e->d_type ) switch( e->d_type )
{ {

View File

@ -381,7 +381,7 @@ GetAudioMetadata(const char * path, char * name)
if( song.title && *song.title ) if( song.title && *song.title )
{ {
m.title = trim(song.title); m.title = trim(song.title);
if( (esc_tag = escape_tag(m.title)) ) if( (esc_tag = escape_tag(m.title, 0)) )
{ {
free_flags |= FLAG_TITLE; free_flags |= FLAG_TITLE;
m.title = esc_tag; m.title = esc_tag;
@ -401,7 +401,7 @@ GetAudioMetadata(const char * path, char * name)
m.creator = strdup("Various Artists"); m.creator = strdup("Various Artists");
free_flags |= FLAG_CREATOR; free_flags |= FLAG_CREATOR;
} }
else if( (esc_tag = escape_tag(m.creator)) ) else if( (esc_tag = escape_tag(m.creator, 0)) )
{ {
m.creator = esc_tag; m.creator = esc_tag;
free_flags |= FLAG_CREATOR; free_flags |= FLAG_CREATOR;
@ -422,7 +422,7 @@ GetAudioMetadata(const char * path, char * name)
m.artist = strdup("Various Artists"); m.artist = strdup("Various Artists");
free_flags |= FLAG_ARTIST; free_flags |= FLAG_ARTIST;
} }
else if( (esc_tag = escape_tag(m.artist)) ) else if( (esc_tag = escape_tag(m.artist, 0)) )
{ {
m.artist = esc_tag; m.artist = esc_tag;
free_flags |= FLAG_ARTIST; free_flags |= FLAG_ARTIST;
@ -432,7 +432,7 @@ GetAudioMetadata(const char * path, char * name)
if( song.album && *song.album ) if( song.album && *song.album )
{ {
m.album = trim(song.album); m.album = trim(song.album);
if( (esc_tag = escape_tag(m.album)) ) if( (esc_tag = escape_tag(m.album, 0)) )
{ {
free_flags |= FLAG_ALBUM; free_flags |= FLAG_ALBUM;
m.album = esc_tag; m.album = esc_tag;
@ -441,7 +441,7 @@ GetAudioMetadata(const char * path, char * name)
if( song.genre && *song.genre ) if( song.genre && *song.genre )
{ {
m.genre = trim(song.genre); m.genre = trim(song.genre);
if( (esc_tag = escape_tag(m.genre)) ) if( (esc_tag = escape_tag(m.genre, 0)) )
{ {
free_flags |= FLAG_GENRE; free_flags |= FLAG_GENRE;
m.genre = esc_tag; m.genre = esc_tag;
@ -450,7 +450,7 @@ GetAudioMetadata(const char * path, char * name)
if( song.comment && *song.comment ) if( song.comment && *song.comment )
{ {
m.comment = trim(song.comment); m.comment = trim(song.comment);
if( (esc_tag = escape_tag(m.comment)) ) if( (esc_tag = escape_tag(m.comment, 0)) )
{ {
free_flags |= FLAG_COMMENT; free_flags |= FLAG_COMMENT;
m.comment = esc_tag; m.comment = esc_tag;
@ -1398,19 +1398,19 @@ GetVideoMetadata(const char * path, char * name)
{ {
if( video.title && *video.title ) if( video.title && *video.title )
{ {
m.title = strdup(trim(video.title)); m.title = escape_tag(trim(video.title), 1);
} }
if( video.genre && *video.genre ) if( video.genre && *video.genre )
{ {
m.genre = strdup(trim(video.genre)); m.genre = escape_tag(trim(video.genre), 1);
} }
if( video.contributor[ROLE_TRACKARTIST] && *video.contributor[ROLE_TRACKARTIST] ) if( video.contributor[ROLE_TRACKARTIST] && *video.contributor[ROLE_TRACKARTIST] )
{ {
m.artist = strdup(trim(video.contributor[ROLE_TRACKARTIST])); m.artist = escape_tag(trim(video.contributor[ROLE_TRACKARTIST]), 1);
} }
if( video.contributor[ROLE_ALBUMARTIST] && *video.contributor[ROLE_ALBUMARTIST] ) if( video.contributor[ROLE_ALBUMARTIST] && *video.contributor[ROLE_ALBUMARTIST] )
{ {
m.creator = strdup(trim(video.contributor[ROLE_ALBUMARTIST])); m.creator = escape_tag(trim(video.contributor[ROLE_ALBUMARTIST]), 1);
} }
else else
{ {
@ -1419,6 +1419,7 @@ GetVideoMetadata(const char * path, char * name)
} }
} }
} }
#ifndef NETGEAR
#if LIBAVFORMAT_VERSION_INT >= ((52<<16)+(31<<8)+0) #if LIBAVFORMAT_VERSION_INT >= ((52<<16)+(31<<8)+0)
else if( strcmp(ctx->iformat->name, "mov,mp4,m4a,3gp,3g2,mj2") == 0 ) else if( strcmp(ctx->iformat->name, "mov,mp4,m4a,3gp,3g2,mj2") == 0 )
{ {
@ -1431,17 +1432,18 @@ GetVideoMetadata(const char * path, char * name)
{ {
//DEBUG DPRINTF(E_DEBUG, L_METADATA, " %-16s: %s\n", tag->key, tag->value); //DEBUG DPRINTF(E_DEBUG, L_METADATA, " %-16s: %s\n", tag->key, tag->value);
if( strcmp(tag->key, "title") == 0 ) if( strcmp(tag->key, "title") == 0 )
m.title = strdup(trim(tag->value)); m.title = escape_tag(trim(tag->value), 1);
else if( strcmp(tag->key, "genre") == 0 ) else if( strcmp(tag->key, "genre") == 0 )
m.genre = strdup(trim(tag->value)); m.genre = escape_tag(trim(tag->value), 1);
else if( strcmp(tag->key, "artist") == 0 ) else if( strcmp(tag->key, "artist") == 0 )
m.artist = strdup(trim(tag->value)); m.artist = escape_tag(trim(tag->value), 1);
else if( strcmp(tag->key, "comment") == 0 ) else if( strcmp(tag->key, "comment") == 0 )
m.comment = strdup(trim(tag->value)); m.comment = escape_tag(trim(tag->value), 1);
} }
} }
} }
#endif #endif
#endif
video_no_dlna: video_no_dlna:
av_close_input_file(ctx); av_close_input_file(ctx);

View File

@ -760,7 +760,7 @@ ScanDirectory(const char * dir, const char * parent, enum media_types dir_type)
#endif #endif
type = TYPE_UNKNOWN; type = TYPE_UNKNOWN;
sprintf(full_path, "%s/%s", dir, namelist[i]->d_name); sprintf(full_path, "%s/%s", dir, namelist[i]->d_name);
name = escape_tag(namelist[i]->d_name); name = escape_tag(namelist[i]->d_name, 1);
if( namelist[i]->d_type == DT_DIR ) if( namelist[i]->d_type == DT_DIR )
{ {
type = TYPE_DIR; type = TYPE_DIR;
@ -775,16 +775,15 @@ ScanDirectory(const char * dir, const char * parent, enum media_types dir_type)
} }
if( (type == TYPE_DIR) && (access(full_path, R_OK|X_OK) == 0) ) if( (type == TYPE_DIR) && (access(full_path, R_OK|X_OK) == 0) )
{ {
insert_directory(name?name:namelist[i]->d_name, full_path, BROWSEDIR_ID, (parent ? parent:""), i+startID); insert_directory(name, full_path, BROWSEDIR_ID, (parent ? parent:""), i+startID);
sprintf(parent_id, "%s$%X", (parent ? parent:""), i+startID); sprintf(parent_id, "%s$%X", (parent ? parent:""), i+startID);
ScanDirectory(full_path, parent_id, dir_type); ScanDirectory(full_path, parent_id, dir_type);
} }
else if( type == TYPE_FILE ) else if( type == TYPE_FILE )
{ {
if( insert_file(name?name:namelist[i]->d_name, full_path, (parent ? parent:""), i+startID) == 0 ) if( insert_file(name, full_path, (parent ? parent:""), i+startID) == 0 )
fileno++; fileno++;
} }
if( name )
free(name); free(name);
free(namelist[i]); free(namelist[i]);
} }

View File

@ -256,15 +256,13 @@ int callback(void *args, int argc, char **argv, char **azColName)
passed_args->size += ret; passed_args->size += ret;
if( flags & FLAG_VIDEO ) if( flags & FLAG_VIDEO )
{ {
char *name = basename(path); char *esc_name = escape_tag(basename(path), 1);
char *esc_name = escape_tag(name);
ret = sprintf(str_buf, "<CustomIcon>" ret = sprintf(str_buf, "<CustomIcon>"
"<ContentType>video/*</ContentType>" "<ContentType>video/*</ContentType>"
"<Url>urn:tivo:image:save-until-i-delete-recording</Url>" "<Url>urn:tivo:image:save-until-i-delete-recording</Url>"
"</CustomIcon>" "</CustomIcon>"
"<Push><Container>Videos</Container></Push>" "<Push><Container>Videos</Container></Push>"
"<File>%s</File> </Links>", esc_name?esc_name:name); "<File>%s</File> </Links>", esc_name);
if( esc_name )
free(esc_name); free(esc_name);
} }
else else
@ -415,9 +413,7 @@ SendContainer(struct upnphttp * h, const char * objectID, int itemStart, int ite
sql = sqlite3_mprintf("SELECT NAME from OBJECTS where OBJECT_ID = '%s'", objectID); sql = sqlite3_mprintf("SELECT NAME from OBJECTS where OBJECT_ID = '%s'", objectID);
if( (sql_get_table(db, sql, &result, &ret, NULL) == SQLITE_OK) && ret ) if( (sql_get_table(db, sql, &result, &ret, NULL) == SQLITE_OK) && ret )
{ {
title = escape_tag(result[1]); title = escape_tag(result[1], 1);
if( !title )
title = strdup(result[1]);
} }
else else
title = strdup("UNKNOWN"); title = strdup("UNKNOWN");

View File

@ -136,7 +136,7 @@ modifyString(char * string, const char * before, const char * after, short like)
} }
char * char *
escape_tag(const char *tag) escape_tag(const char *tag, uint8_t force_alloc)
{ {
char *esc_tag = NULL; char *esc_tag = NULL;
@ -147,6 +147,8 @@ escape_tag(const char *tag)
esc_tag = modifyString(esc_tag, "<", "&amp;lt;", 0); esc_tag = modifyString(esc_tag, "<", "&amp;lt;", 0);
esc_tag = modifyString(esc_tag, ">", "&amp;gt;", 0); esc_tag = modifyString(esc_tag, ">", "&amp;gt;", 0);
} }
else if( force_alloc )
esc_tag = strdup(tag);
return esc_tag; return esc_tag;
} }

View File

@ -37,7 +37,7 @@ char *
modifyString(char * string, const char * before, const char * after, short like); modifyString(char * string, const char * before, const char * after, short like);
char * char *
escape_tag(const char *tag); escape_tag(const char *tag, uint8_t force_alloc);
void void
strip_ext(char * name); strip_ext(char * name);