* Fix some issues reported by cppcheck.

This commit is contained in:
Justin Maggard 2011-05-02 23:50:52 +00:00
parent e0e0fa254d
commit 9a9270cecf
18 changed files with 298 additions and 282 deletions

View File

@ -44,10 +44,10 @@ art_cache_exists(const char * orig_path, char ** cache_file)
} }
char * char *
save_resized_album_art(image * imsrc, const char * path) save_resized_album_art(image_s * imsrc, const char * path)
{ {
int dstw, dsth; int dstw, dsth;
image * imdst; image_s * imdst;
char * cache_file; char * cache_file;
char * cache_dir; char * cache_dir;
@ -174,8 +174,7 @@ check_embedded_art(const char * path, const char * image_data, int image_size)
char * art_path = NULL; char * art_path = NULL;
char * cache_dir; char * cache_dir;
FILE * dstfile; FILE * dstfile;
image * imsrc; image_s * imsrc;
size_t nwritten;
static char last_path[PATH_MAX]; static char last_path[PATH_MAX];
static unsigned int last_hash = 0; static unsigned int last_hash = 0;
static int last_success = 0; static int last_success = 0;
@ -229,6 +228,7 @@ check_embedded_art(const char * path, const char * image_data, int image_size)
} }
else if( width > 0 && height > 0 ) else if( width > 0 && height > 0 )
{ {
size_t nwritten;
if( art_cache_exists(path, &art_path) ) if( art_cache_exists(path, &art_path) )
goto end_art; goto end_art;
cache_dir = strdup(art_path); cache_dir = strdup(art_path);
@ -272,7 +272,7 @@ check_for_album_file(char * dir, const char * path)
{ {
char * file = malloc(PATH_MAX); char * file = malloc(PATH_MAX);
struct album_art_name_s * album_art_name; struct album_art_name_s * album_art_name;
image * imsrc = NULL; image_s * imsrc = NULL;
int width=0, height=0; int width=0, height=0;
char * art_file; char * art_file;

View File

@ -217,7 +217,7 @@ get_remote_mac(struct in_addr ip_addr, unsigned char * mac)
return 1; return 1;
while( !feof(arp) ) while( !feof(arp) )
{ {
matches = fscanf(arp, "%s 0x%X 0x%X %hhx:%hhx:%hhx:%hhx:%hhx:%hhx", matches = fscanf(arp, "%15s 0x%8X 0x%8X %2hhx:%2hhx:%2hhx:%2hhx:%2hhx:%2hhx",
remote_ip, &hwtype, &flags, remote_ip, &hwtype, &flags,
&mac[0], &mac[1], &mac[2], &mac[3], &mac[4], &mac[5]); &mac[0], &mac[1], &mac[2], &mac[3], &mac[4], &mac[5]);
if( matches != 9 ) if( matches != 9 )

View File

@ -203,14 +203,14 @@ libjpeg_error_handler(j_common_ptr cinfo)
} }
void void
image_free(image *pimage) image_free(image_s *pimage)
{ {
free(pimage->buf); free(pimage->buf);
free(pimage); free(pimage);
} }
pix pix
get_pix(image *pimage, int32_t x, int32_t y) get_pix(image_s *pimage, int32_t x, int32_t y)
{ {
if((x >= 0) && (y >= 0) && (x < pimage->width) && (y < pimage->height)) if((x >= 0) && (y >= 0) && (x < pimage->width) && (y < pimage->height))
{ {
@ -224,7 +224,7 @@ get_pix(image *pimage, int32_t x, int32_t y)
} }
void void
put_pix_alpha_replace(image *pimage, int32_t x, int32_t y, pix col) put_pix_alpha_replace(image_s *pimage, int32_t x, int32_t y, pix col)
{ {
if((x >= 0) && (y >= 0) && (x < pimage->width) && (y < pimage->height)) if((x >= 0) && (y >= 0) && (x < pimage->width) && (y < pimage->height))
pimage->buf[(y * pimage->width) + x] = col; pimage->buf[(y * pimage->width) + x] = col;
@ -295,7 +295,7 @@ image_get_jpeg_date_xmp(const char * path, char ** date)
{ {
FILE *img; FILE *img;
unsigned char buf[8]; unsigned char buf[8];
char *data = NULL; char *data = NULL, *newdata;
u_int16_t offset; u_int16_t offset;
struct NameValueParserData xml; struct NameValueParserData xml;
char * exif; char * exif;
@ -337,7 +337,11 @@ image_get_jpeg_date_xmp(const char * path, char ** date)
continue; continue;
} }
data = realloc(data, 30); newdata = realloc(data, 30);
if( !newdata )
break;
data = newdata;
fread(data, 29, 1, img); fread(data, 29, 1, img);
offset -= 29; offset -= 29;
if( strcmp(data, "http://ns.adobe.com/xap/1.0/") != 0 ) if( strcmp(data, "http://ns.adobe.com/xap/1.0/") != 0 )
@ -346,7 +350,10 @@ image_get_jpeg_date_xmp(const char * path, char ** date)
continue; continue;
} }
data = realloc(data, offset+1); newdata = realloc(data, offset+1);
if( !newdata )
break;
data = newdata;
fread(data, offset, 1, img); fread(data, offset, 1, img);
ParseNameValue(data, offset, &xml); ParseNameValue(data, offset, &xml);
@ -378,12 +385,12 @@ image_get_jpeg_date_xmp(const char * path, char ** date)
return ret; return ret;
} }
image * image_s *
image_new(int32_t width, int32_t height) image_new(int32_t width, int32_t height)
{ {
image *vimage; image_s *vimage;
if((vimage = (image *)malloc(sizeof(image))) == NULL) if((vimage = (image_s *)malloc(sizeof(image_s))) == NULL)
{ {
DPRINTF(E_WARN, L_METADATA, "malloc failed\n"); DPRINTF(E_WARN, L_METADATA, "malloc failed\n");
return NULL; return NULL;
@ -399,10 +406,10 @@ image_new(int32_t width, int32_t height)
return(vimage); return(vimage);
} }
image * image_s *
image_new_from_jpeg(const char * path, int is_file, const char * buf, int size, int scale) image_new_from_jpeg(const char * path, int is_file, const char * buf, int size, int scale)
{ {
image *vimage; image_s *vimage;
FILE *file = NULL; FILE *file = NULL;
struct jpeg_decompress_struct cinfo; struct jpeg_decompress_struct cinfo;
unsigned char *line[16], *ptr; unsigned char *line[16], *ptr;
@ -478,6 +485,9 @@ image_new_from_jpeg(const char * path, int is_file, const char * buf, int size,
if((ptr = (unsigned char *)malloc(w * 3 * cinfo.rec_outbuf_height + 8)) == NULL) if((ptr = (unsigned char *)malloc(w * 3 * cinfo.rec_outbuf_height + 8)) == NULL)
{ {
DPRINTF(E_WARN, L_METADATA, "malloc failed\n"); DPRINTF(E_WARN, L_METADATA, "malloc failed\n");
image_free(vimage);
if( is_file )
fclose(file);
return NULL; return NULL;
} }
@ -541,7 +551,7 @@ image_new_from_jpeg(const char * path, int is_file, const char * buf, int size,
} }
void void
image_upsize(image * pdest, image * psrc, int32_t width, int32_t height) image_upsize(image_s * pdest, image_s * psrc, int32_t width, int32_t height)
{ {
int32_t vx, vy; int32_t vx, vy;
#if !defined __i386__ && !defined __x86_64__ #if !defined __i386__ && !defined __x86_64__
@ -604,7 +614,7 @@ image_upsize(image * pdest, image * psrc, int32_t width, int32_t height)
} }
void void
image_downsize(image * pdest, image * psrc, int32_t width, int32_t height) image_downsize(image_s * pdest, image_s * psrc, int32_t width, int32_t height)
{ {
int32_t vx, vy; int32_t vx, vy;
pix vcol; pix vcol;
@ -747,10 +757,10 @@ image_downsize(image * pdest, image * psrc, int32_t width, int32_t height)
} }
} }
image * image_s *
image_resize(image * src_image, int32_t width, int32_t height) image_resize(image_s * src_image, int32_t width, int32_t height)
{ {
image * dst_image; image_s * dst_image;
dst_image = image_new(width, height); dst_image = image_new(width, height);
if( !dst_image ) if( !dst_image )
@ -765,7 +775,7 @@ image_resize(image * src_image, int32_t width, int32_t height)
unsigned char * unsigned char *
image_save_to_jpeg_buf(image * pimage, int * size) image_save_to_jpeg_buf(image_s * pimage, int * size)
{ {
struct jpeg_compress_struct cinfo; struct jpeg_compress_struct cinfo;
struct jpeg_error_mgr jerr; struct jpeg_error_mgr jerr;
@ -813,7 +823,7 @@ image_save_to_jpeg_buf(image * pimage, int * size)
} }
int int
image_save_to_jpeg_file(image * pimage, const char * path) image_save_to_jpeg_file(image_s * pimage, const char * path)
{ {
int nwritten, size = 0; int nwritten, size = 0;
unsigned char * buf; unsigned char * buf;

View File

@ -29,10 +29,10 @@ typedef struct {
int32_t width; int32_t width;
int32_t height; int32_t height;
pix *buf; pix *buf;
} image; } image_s;
void void
image_free(image *pimage); image_free(image_s *pimage);
int int
image_get_jpeg_date_xmp(const char * path, char ** date); image_get_jpeg_date_xmp(const char * path, char ** date);
@ -40,14 +40,14 @@ image_get_jpeg_date_xmp(const char * path, char ** date);
int int
image_get_jpeg_resolution(const char * path, int * width, int * height); image_get_jpeg_resolution(const char * path, int * width, int * height);
image * image_s *
image_new_from_jpeg(const char * path, int is_file, const char * ptr, int size, int scale); image_new_from_jpeg(const char * path, int is_file, const char * ptr, int size, int scale);
image * image_s *
image_resize(image * src_image, int32_t width, int32_t height); image_resize(image_s * src_image, int32_t width, int32_t height);
unsigned char * unsigned char *
image_save_to_jpeg_buf(image * pimage, int * size); image_save_to_jpeg_buf(image_s * pimage, int * size);
int int
image_save_to_jpeg_file(image * pimage, const char * path); image_save_to_jpeg_file(image_s * pimage, const char * path);

129
inotify.c
View File

@ -154,7 +154,7 @@ inotify_create_watches(int fd)
max_watches = fopen("/proc/sys/fs/inotify/max_user_watches", "r"); max_watches = fopen("/proc/sys/fs/inotify/max_user_watches", "r");
if( max_watches ) if( max_watches )
{ {
fscanf(max_watches, "%u", &watch_limit); fscanf(max_watches, "%10u", &watch_limit);
fclose(max_watches); fclose(max_watches);
if( (watch_limit < DESIRED_WATCH_LIMIT) || (watch_limit < (num_watches*3/4)) ) if( (watch_limit < DESIRED_WATCH_LIMIT) || (watch_limit < (num_watches*3/4)) )
{ {
@ -276,16 +276,15 @@ int add_dir_watch(int fd, char * path, char * filename)
int int
inotify_insert_file(char * name, const char * path) inotify_insert_file(char * name, const char * path)
{ {
char * sql; int len;
char **result; char * last_dir;
int rows; char * path_buf;
char * last_dir = strdup(path); char * base_name;
char * path_buf = strdup(path); char * base_copy;
char * base_name = malloc(strlen(path));
char * base_copy = base_name;
char * parent_buf = NULL; char * parent_buf = NULL;
char * id = NULL; char * id = NULL;
int depth = 1; int depth = 1;
int ts;
enum media_types type = ALL_MEDIA; enum media_types type = ALL_MEDIA;
struct media_dir_s * media_path = media_dirs; struct media_dir_s * media_path = media_dirs;
struct stat st; struct stat st;
@ -337,74 +336,59 @@ inotify_insert_file(char * name, const char * path)
if( stat(path, &st) != 0 ) if( stat(path, &st) != 0 )
return -1; return -1;
sql = sqlite3_mprintf("SELECT TIMESTAMP from DETAILS where PATH = '%q'", path); ts = sql_get_int_field(db, "SELECT TIMESTAMP from DETAILS where PATH = '%q'", path);
if( sql_get_table(db, sql, &result, &rows, NULL) == SQLITE_OK ) if( !ts && is_playlist(path) && (sql_get_int_field(db, "SELECT ID from PLAYLISTS where PATH = '%q'", path) > 0) )
{
if( rows )
{
if( atoi(result[1]) < st.st_mtime )
{
DPRINTF(E_DEBUG, L_INOTIFY, "%s is newer than the last db entry.\n", path);
inotify_remove_file(path_buf);
}
else
{
free(last_dir);
free(path_buf);
free(base_name);
sqlite3_free(sql);
sqlite3_free_table(result);
return -1;
}
}
else if( is_playlist(path) && (sql_get_int_field(db, "SELECT ID from PLAYLISTS where PATH = '%q'", path) > 0) )
{ {
DPRINTF(E_DEBUG, L_INOTIFY, "Re-reading modified playlist.\n", path); DPRINTF(E_DEBUG, L_INOTIFY, "Re-reading modified playlist.\n", path);
inotify_remove_file(path_buf); inotify_remove_file(path);
next_pl_fill = 1; next_pl_fill = 1;
} }
sqlite3_free_table(result); else if( ts < st.st_mtime )
{
if( ts > 0 )
DPRINTF(E_DEBUG, L_INOTIFY, "%s is newer than the last db entry.\n", path);
inotify_remove_file(path);
} }
sqlite3_free(sql);
/* Find the parentID. If it's not found, create all necessary parents. */ /* Find the parentID. If it's not found, create all necessary parents. */
len = strlen(path)+1;
if( !(path_buf = malloc(len)) ||
!(last_dir = malloc(len)) ||
!(base_name = malloc(len)) )
return -1;
base_copy = base_name;
while( depth ) while( depth )
{ {
depth = 0; depth = 0;
strcpy(path_buf, path); strcpy(path_buf, path);
parent_buf = dirname(path_buf); parent_buf = dirname(path_buf);
strcpy(last_dir, path_buf);
do do
{ {
//DEBUG DPRINTF(E_DEBUG, L_INOTIFY, "Checking %s\n", parent_buf); //DEBUG DPRINTF(E_DEBUG, L_INOTIFY, "Checking %s\n", parent_buf);
sql = sqlite3_mprintf("SELECT OBJECT_ID from OBJECTS o left join DETAILS d on (d.ID = o.DETAIL_ID)" id = sql_get_text_field(db, "SELECT OBJECT_ID from OBJECTS o left join DETAILS d on (d.ID = o.DETAIL_ID)"
" where d.PATH = '%q' and REF_ID is NULL", parent_buf); " where d.PATH = '%q' and REF_ID is NULL", parent_buf);
if( (sql_get_table(db, sql, &result, &rows, NULL) == SQLITE_OK) && rows ) if( id )
{ {
id = strdup(result[1]);
sqlite3_free_table(result);
sqlite3_free(sql);
if( !depth ) if( !depth )
break; break;
DPRINTF(E_DEBUG, L_INOTIFY, "Found first known parentID: %s\n", id); DPRINTF(E_DEBUG, L_INOTIFY, "Found first known parentID: %s [%s]\n", id, parent_buf);
/* Insert newly-found directory */ /* Insert newly-found directory */
strcpy(base_name, last_dir); strcpy(base_name, last_dir);
base_copy = basename(base_name); base_copy = basename(base_name);
insert_directory(base_copy, last_dir, BROWSEDIR_ID, id+2, get_next_available_id("OBJECTS", id)); insert_directory(base_copy, last_dir, BROWSEDIR_ID, id+2, get_next_available_id("OBJECTS", id));
free(id); sqlite3_free(id);
break; break;
} }
depth++; depth++;
strcpy(last_dir, path_buf); strcpy(last_dir, parent_buf);
parent_buf = dirname(parent_buf); parent_buf = dirname(parent_buf);
sqlite3_free_table(result);
sqlite3_free(sql);
} }
while( strcmp(parent_buf, "/") != 0 ); while( strcmp(parent_buf, "/") != 0 );
if( strcmp(parent_buf, "/") == 0 ) if( strcmp(parent_buf, "/") == 0 )
{ {
id = strdup(BROWSEDIR_ID); id = sqlite3_mprintf("%s", BROWSEDIR_ID);
depth = 0; depth = 0;
break; break;
} }
@ -418,7 +402,7 @@ inotify_insert_file(char * name, const char * path)
{ {
//DEBUG DPRINTF(E_DEBUG, L_INOTIFY, "Inserting %s\n", name); //DEBUG DPRINTF(E_DEBUG, L_INOTIFY, "Inserting %s\n", name);
insert_file(name, path, id+2, get_next_available_id("OBJECTS", id)); insert_file(name, path, id+2, get_next_available_id("OBJECTS", id));
free(id); sqlite3_free(id);
if( (is_audio(path) || is_playlist(path)) && next_pl_fill != 1 ) if( (is_audio(path) || is_playlist(path)) && next_pl_fill != 1 )
{ {
next_pl_fill = time(NULL) + 120; // Schedule a playlist scan for 2 minutes from now. next_pl_fill = time(NULL) + 120; // Schedule a playlist scan for 2 minutes from now.
@ -433,11 +417,8 @@ inotify_insert_directory(int fd, char *name, const char * path)
{ {
DIR * ds; DIR * ds;
struct dirent * e; struct dirent * e;
char * sql; char *id, *path_buf, *parent_buf, *esc_name;
char **result;
char *id=NULL, *path_buf, *parent_buf, *esc_name;
int wd; int wd;
int rows;
enum file_types type = TYPE_UNKNOWN; enum file_types type = TYPE_UNKNOWN;
enum media_types dir_type = ALL_MEDIA; enum media_types dir_type = ALL_MEDIA;
struct media_dir_s * media_path; struct media_dir_s * media_path;
@ -448,18 +429,20 @@ inotify_insert_directory(int fd, char *name, const char * path)
DPRINTF(E_WARN, L_INOTIFY, "Could not access %s [%s]\n", path, strerror(errno)); DPRINTF(E_WARN, L_INOTIFY, "Could not access %s [%s]\n", path, strerror(errno));
return -1; return -1;
} }
if( sql_get_int_field(db, "SELECT ID from DETAILS where PATH = '%q'", path) > 0 )
parent_buf = dirname(strdup(path));
sql = sqlite3_mprintf("SELECT OBJECT_ID from OBJECTS o left join DETAILS d on (d.ID = o.DETAIL_ID)"
" where d.PATH = '%q' and REF_ID is NULL", parent_buf);
if( sql_get_table(db, sql, &result, &rows, NULL) == SQLITE_OK )
{ {
id = strdup(rows?result[1]:BROWSEDIR_ID); DPRINTF(E_DEBUG, L_INOTIFY, "%s already exists\n", path);
insert_directory(name, path, BROWSEDIR_ID, id+2, get_next_available_id("OBJECTS", id)); return 0;
free(id);
} }
parent_buf = strdup(path);
id = sql_get_text_field(db, "SELECT OBJECT_ID from OBJECTS o left join DETAILS d on (d.ID = o.DETAIL_ID)"
" where d.PATH = '%q' and REF_ID is NULL", dirname(parent_buf));
if( !id )
id = sqlite3_mprintf("%s", BROWSEDIR_ID);
insert_directory(name, path, BROWSEDIR_ID, id+2, get_next_available_id("OBJECTS", id));
sqlite3_free(id);
free(parent_buf); free(parent_buf);
sqlite3_free(sql);
wd = add_watch(fd, path); wd = add_watch(fd, path);
if( wd == -1 ) if( wd == -1 )
@ -529,24 +512,19 @@ inotify_remove_file(const char * path)
char * sql; char * sql;
char **result; char **result;
char * art_cache; char * art_cache;
sqlite_int64 detailID = 0; char * ptr;
int i, rows, children, playlist, ret = 1; sqlite_int64 detailID;
int rows, playlist;
/* Invalidate the scanner cache so we don't insert files into non-existent containers */ /* Invalidate the scanner cache so we don't insert files into non-existent containers */
valid_cache = 0; valid_cache = 0;
playlist = is_playlist(path); playlist = is_playlist(path);
sql = sqlite3_mprintf("SELECT ID from %s where PATH = '%q'", playlist?"PLAYLISTS":"DETAILS", path); sql = sql_get_text_field(db, "SELECT ID from %s where PATH = '%q'", playlist?"PLAYLISTS":"DETAILS", path);
if( (sql_get_table(db, sql, &result, &rows, NULL) == SQLITE_OK) ) if( !sql )
{ return 1;
if( rows ) detailID = strtoll(sql, NULL, 10);
{
detailID = strtoll(result[1], NULL, 10);
ret = 0;
}
sqlite3_free_table(result);
}
sqlite3_free(sql); sqlite3_free(sql);
if( playlist && detailID ) if( playlist )
{ {
sql_exec(db, "DELETE from PLAYLISTS where ID = %lld", detailID); sql_exec(db, "DELETE from PLAYLISTS where ID = %lld", detailID);
sql_exec(db, "DELETE from DETAILS where ID =" sql_exec(db, "DELETE from DETAILS where ID ="
@ -555,12 +533,13 @@ inotify_remove_file(const char * path)
sql_exec(db, "DELETE from OBJECTS where OBJECT_ID = '%s$%lld' or PARENT_ID = '%s$%lld'", sql_exec(db, "DELETE from OBJECTS where OBJECT_ID = '%s$%lld' or PARENT_ID = '%s$%lld'",
MUSIC_PLIST_ID, detailID, MUSIC_PLIST_ID, detailID); MUSIC_PLIST_ID, detailID, MUSIC_PLIST_ID, detailID);
} }
else if( detailID ) else
{ {
/* Delete the parent containers if we are about to empty them. */ /* Delete the parent containers if we are about to empty them. */
asprintf(&sql, "SELECT PARENT_ID from OBJECTS where DETAIL_ID = %lld", detailID); asprintf(&sql, "SELECT PARENT_ID from OBJECTS where DETAIL_ID = %lld", detailID);
if( (sql_get_table(db, sql, &result, &rows, NULL) == SQLITE_OK) ) if( (sql_get_table(db, sql, &result, &rows, NULL) == SQLITE_OK) )
{ {
int i, children;
for( i=1; i <= rows; i++ ) for( i=1; i <= rows; i++ )
{ {
/* If it's a playlist item, adjust the item count of the playlist */ /* If it's a playlist item, adjust the item count of the playlist */
@ -579,7 +558,9 @@ inotify_remove_file(const char * path)
" (SELECT DETAIL_ID from OBJECTS where OBJECT_ID = '%s')", result[i]); " (SELECT DETAIL_ID from OBJECTS where OBJECT_ID = '%s')", result[i]);
sql_exec(db, "DELETE from OBJECTS where OBJECT_ID = '%s'", result[i]); sql_exec(db, "DELETE from OBJECTS where OBJECT_ID = '%s'", result[i]);
*rindex(result[i], '$') = '\0'; ptr = strrchr(result[i], '$');
if( ptr )
*ptr = '\0';
if( sql_get_int_field(db, "SELECT count(*) from OBJECTS where PARENT_ID = '%s'", result[i]) == 0 ) if( sql_get_int_field(db, "SELECT count(*) from OBJECTS where PARENT_ID = '%s'", result[i]) == 0 )
{ {
sql_exec(db, "DELETE from DETAILS where ID =" sql_exec(db, "DELETE from DETAILS where ID ="
@ -599,7 +580,7 @@ inotify_remove_file(const char * path)
remove(art_cache); remove(art_cache);
free(art_cache); free(art_cache);
return ret; return 0;
} }
int int

View File

@ -137,10 +137,8 @@ is_tivo_file(const char * path)
void void
check_for_captions(const char * path, sqlite_int64 detailID) check_for_captions(const char * path, sqlite_int64 detailID)
{ {
char * sql; char *file = malloc(PATH_MAX);
char * file = malloc(PATH_MAX); char *id = NULL;
char **result;
int ret, rows;
sprintf(file, "%s", path); sprintf(file, "%s", path);
strip_ext(file); strip_ext(file);
@ -148,26 +146,19 @@ check_for_captions(const char * path, sqlite_int64 detailID)
/* If we weren't given a detail ID, look for one. */ /* If we weren't given a detail ID, look for one. */
if( !detailID ) if( !detailID )
{ {
sql = sqlite3_mprintf("SELECT ID from DETAILS where PATH glob '%q.*'" id = sql_get_text_field(db, "SELECT ID from DETAILS where PATH glob '%q.*'"
" and MIME glob 'video/*' limit 1", file); " and MIME glob 'video/*' limit 1", file);
ret = sql_get_table(db, sql, &result, &rows, NULL); if( id )
if( ret == SQLITE_OK )
{ {
if( rows )
{
detailID = strtoll(result[1], NULL, 10);
//DEBUG DPRINTF(E_DEBUG, L_METADATA, "New file %s looks like a caption file.\n", path); //DEBUG DPRINTF(E_DEBUG, L_METADATA, "New file %s looks like a caption file.\n", path);
detailID = strtoll(id, NULL, 10);
} }
/*else else
{ {
DPRINTF(E_DEBUG, L_METADATA, "No file found for caption %s.\n", path); //DPRINTF(E_DEBUG, L_METADATA, "No file found for caption %s.\n", path);
}*/
sqlite3_free_table(result);
}
sqlite3_free(sql);
if( !detailID )
goto no_source_video; goto no_source_video;
} }
}
strcat(file, ".srt"); strcat(file, ".srt");
if( access(file, R_OK) == 0 ) if( access(file, R_OK) == 0 )
@ -178,6 +169,8 @@ check_for_captions(const char * path, sqlite_int64 detailID)
" (%lld, %Q)", detailID, file); " (%lld, %Q)", detailID, file);
} }
no_source_video: no_source_video:
if( id )
sqlite3_free(id);
free(file); free(file);
} }
@ -506,7 +499,7 @@ GetImageMetadata(const char * path, char * name)
char b[1024]; char b[1024];
struct stat file; struct stat file;
sqlite_int64 ret; sqlite_int64 ret;
image * imsrc; image_s * imsrc;
metadata_t m; metadata_t m;
uint32_t free_flags = 0xFFFFFFFF; uint32_t free_flags = 0xFFFFFFFF;
memset(&m, '\0', sizeof(metadata_t)); memset(&m, '\0', sizeof(metadata_t));
@ -646,11 +639,7 @@ GetVideoMetadata(const char * path, char * name)
int audio_stream = -1, video_stream = -1; int audio_stream = -1, video_stream = -1;
enum audio_profiles audio_profile = PROFILE_AUDIO_UNKNOWN; enum audio_profiles audio_profile = PROFILE_AUDIO_UNKNOWN;
tsinfo_t *ts; tsinfo_t *ts;
ts_timestamp_t ts_timestamp = NONE;
char fourcc[4]; char fourcc[4];
int off;
int duration, hours, min, sec, ms;
aac_object_type_t aac_type = AAC_INVALID;
sqlite_int64 album_art = 0; sqlite_int64 album_art = 0;
char nfo[PATH_MAX], *ext; char nfo[PATH_MAX], *ext;
struct song_metadata video; struct song_metadata video;
@ -719,6 +708,7 @@ GetVideoMetadata(const char * path, char * name)
if( ac ) if( ac )
{ {
aac_object_type_t aac_type = AAC_INVALID;
switch( ac->codec_id ) switch( ac->codec_id )
{ {
case CODEC_ID_MP3: case CODEC_ID_MP3:
@ -807,6 +797,9 @@ GetVideoMetadata(const char * path, char * name)
} }
if( vc ) if( vc )
{ {
int off;
int duration, hours, min, sec, ms;
ts_timestamp_t ts_timestamp = NONE;
DPRINTF(E_DEBUG, L_METADATA, "Container: '%s' [%s]\n", ctx->iformat->name, basename(path)); DPRINTF(E_DEBUG, L_METADATA, "Container: '%s' [%s]\n", ctx->iformat->name, basename(path));
asprintf(&m.resolution, "%dx%d", vc->width, vc->height); asprintf(&m.resolution, "%dx%d", vc->width, vc->height);
if( ctx->bit_rate > 8 ) if( ctx->bit_rate > 8 )

View File

@ -223,6 +223,16 @@ static const char * const known_service_types[] =
0 0
}; };
static void
_usleep(long usecs)
{
struct timespec sleep_time;
sleep_time.tv_sec = 0;
sleep_time.tv_nsec = usecs * 1000;
nanosleep(&sleep_time, NULL);
}
/* not really an SSDP "announce" as it is the response /* not really an SSDP "announce" as it is the response
* to a SSDP "M-SEARCH" */ * to a SSDP "M-SEARCH" */
static void static void
@ -282,7 +292,7 @@ SendSSDPNotifies(int s, const char * host, unsigned short port,
for( dup=0; dup<2; dup++ ) for( dup=0; dup<2; dup++ )
{ {
if( dup ) if( dup )
usleep(200000); _usleep(200000);
i=0; i=0;
while(known_service_types[i]) while(known_service_types[i])
{ {
@ -477,10 +487,9 @@ ProcessSSDPRequest(int s, unsigned short port)
char bufr[1500]; char bufr[1500];
socklen_t len_r; socklen_t len_r;
struct sockaddr_in sendername; struct sockaddr_in sendername;
int i, l; int i;
int lan_addr_index = 0;
char *st = NULL, *mx = NULL, *man = NULL, *mx_end = NULL, *loc = NULL, *srv = NULL; char *st = NULL, *mx = NULL, *man = NULL, *mx_end = NULL, *loc = NULL, *srv = NULL;
int st_len = 0, mx_len = 0, man_len = 0, mx_val = 0, loc_len = 0, srv_len = 0; int man_len = 0;
len_r = sizeof(struct sockaddr_in); len_r = sizeof(struct sockaddr_in);
n = recvfrom(s, bufr, sizeof(bufr)-1, 0, n = recvfrom(s, bufr, sizeof(bufr)-1, 0,
@ -494,6 +503,7 @@ ProcessSSDPRequest(int s, unsigned short port)
if(memcmp(bufr, "NOTIFY", 6) == 0) if(memcmp(bufr, "NOTIFY", 6) == 0)
{ {
int loc_len = 0, srv_len = 0;
//DEBUG DPRINTF(E_DEBUG, L_SSDP, "Received SSDP notify:\n%.*s", n, bufr); //DEBUG DPRINTF(E_DEBUG, L_SSDP, "Received SSDP notify:\n%.*s", n, bufr);
for(i=0; i < n; i++) for(i=0; i < n; i++)
{ {
@ -551,6 +561,7 @@ ProcessSSDPRequest(int s, unsigned short port)
} }
else if(memcmp(bufr, "M-SEARCH", 8) == 0) else if(memcmp(bufr, "M-SEARCH", 8) == 0)
{ {
int st_len = 0, mx_len = 0, mx_val = 0;
//DPRINTF(E_DEBUG, L_SSDP, "Received SSDP request:\n%.*s", n, bufr); //DPRINTF(E_DEBUG, L_SSDP, "Received SSDP request:\n%.*s", n, bufr);
for(i=0; i < n; i++) for(i=0; i < n; i++)
{ {
@ -608,6 +619,8 @@ ProcessSSDPRequest(int s, unsigned short port)
} }
else if( st && (st_len > 0) ) else if( st && (st_len > 0) )
{ {
int l;
int lan_addr_index = 0;
/* find in which sub network the client is */ /* find in which sub network the client is */
for(i = 0; i<n_lan_addr; i++) for(i = 0; i<n_lan_addr; i++)
{ {
@ -637,7 +650,7 @@ ProcessSSDPRequest(int s, unsigned short port)
/* Check version number - must always be 1 currently. */ /* Check version number - must always be 1 currently. */
if( (st[st_len-2] == ':') && (atoi(st+st_len-1) != 1) ) if( (st[st_len-2] == ':') && (atoi(st+st_len-1) != 1) )
break; break;
usleep(random()>>20); _usleep(random()>>20);
SendSSDPAnnounce2(s, sendername, SendSSDPAnnounce2(s, sendername,
i, i,
lan_addr[lan_addr_index].str, port); lan_addr[lan_addr_index].str, port);

209
scanner.c
View File

@ -22,6 +22,7 @@
#include <dirent.h> #include <dirent.h>
#include <locale.h> #include <locale.h>
#include <libgen.h> #include <libgen.h>
#include <inttypes.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/time.h> #include <sys/time.h>
#include <sys/resource.h> #include <sys/resource.h>
@ -45,7 +46,7 @@ int valid_cache = 0;
struct virtual_item struct virtual_item
{ {
int objectID; sqlite3_int64 objectID;
char parentID[64]; char parentID[64];
char name[256]; char name[256];
}; };
@ -53,63 +54,55 @@ struct virtual_item
sqlite_int64 sqlite_int64
get_next_available_id(const char * table, const char * parentID) get_next_available_id(const char * table, const char * parentID)
{ {
char * sql; char *ret, *base;
char **result;
int ret, rows;
sqlite_int64 objectID = 0; sqlite_int64 objectID = 0;
asprintf(&sql, "SELECT OBJECT_ID from %s where ID = " ret = sql_get_text_field(db, "SELECT OBJECT_ID from %s where ID = "
"(SELECT max(ID) from %s where PARENT_ID = '%s')", table, table, parentID); "(SELECT max(ID) from %s where PARENT_ID = '%s')",
ret = sql_get_table(db, sql, &result, &rows, NULL); table, table, parentID);
if( rows ) if( ret )
{ {
objectID = strtoll(strrchr(result[1], '$')+1, NULL, 16) + 1; base = strrchr(ret, '$');
if( base )
objectID = strtoll(base+1, NULL, 16) + 1;
sqlite3_free(ret);
} }
sqlite3_free_table(result);
free(sql);
return objectID; return objectID;
} }
long long int int
insert_container(const char * item, const char * rootParent, const char * refID, const char *class, insert_container(const char * item, const char * rootParent, const char * refID, const char *class,
const char *artist, const char *genre, const char *album_art) const char *artist, const char *genre, const char *album_art, sqlite3_int64 *objectID, sqlite3_int64 *parentID)
{ {
char **result; char *result;
char **result2; char *base;
char *sql; int ret = 0;
int cols, rows, ret;
int parentID = 0, objectID = 0;
sqlite_int64 detailID = 0; sqlite_int64 detailID = 0;
sql = sqlite3_mprintf("SELECT OBJECT_ID from OBJECTS" result = sql_get_text_field(db, "SELECT OBJECT_ID from OBJECTS"
" where PARENT_ID = '%s'" " where PARENT_ID = '%s'"
" and NAME = '%q'" " and NAME = '%q'"
" and CLASS = 'container.%s' limit 1", " and CLASS = 'container.%s' limit 1",
rootParent, item, class); rootParent, item, class);
ret = sql_get_table(db, sql, &result, &rows, &cols); if( result )
sqlite3_free(sql);
if( cols )
{ {
parentID = strtol(rindex(result[1], '$')+1, NULL, 16); base = strrchr(result, '$');
objectID = get_next_available_id("OBJECTS", result[1]); if( base )
*parentID = strtoll(base+1, NULL, 16);
else
*parentID = 0;
*objectID = get_next_available_id("OBJECTS", result);
} }
else else
{ {
parentID = get_next_available_id("OBJECTS", rootParent); *objectID = 0;
*parentID = get_next_available_id("OBJECTS", rootParent);
if( refID ) if( refID )
{ {
sql = sqlite3_mprintf("SELECT DETAIL_ID from OBJECTS where OBJECT_ID = %Q", refID); result = sql_get_text_field(db, "SELECT DETAIL_ID from OBJECTS where OBJECT_ID = %Q", refID);
ret = sql_get_table(db, sql, &result2, &rows, NULL); if( result )
if( ret == SQLITE_OK ) detailID = strtoll(result, NULL, 10);
{
if( rows )
{
detailID = strtoll(result2[1], NULL, 10);
}
sqlite3_free_table(result2);
}
sqlite3_free(sql);
} }
if( !detailID ) if( !detailID )
{ {
@ -118,22 +111,22 @@ insert_container(const char * item, const char * rootParent, const char * refID,
ret = sql_exec(db, "INSERT into OBJECTS" ret = sql_exec(db, "INSERT into OBJECTS"
" (OBJECT_ID, PARENT_ID, REF_ID, DETAIL_ID, CLASS, NAME) " " (OBJECT_ID, PARENT_ID, REF_ID, DETAIL_ID, CLASS, NAME) "
"VALUES" "VALUES"
" ('%s$%X', '%s', %Q, %lld, 'container.%s', '%q')", " ('%s$%"PRIX64"', '%s', %Q, %"PRId64", 'container.%s', '%q')",
rootParent, parentID, rootParent, refID, detailID, class, item); rootParent, *parentID, rootParent, refID, detailID, class, item);
} }
sqlite3_free_table(result); sqlite3_free(result);
return (long long)parentID<<32|objectID; return ret;
} }
void static void
insert_containers(const char * name, const char *path, const char * refID, const char * class, long unsigned int detailID) insert_containers(const char * name, const char *path, const char * refID, const char * class, sqlite3_int64 detailID)
{ {
char *sql; char *sql;
char **result; char **result;
int ret; int ret;
int cols, row; int cols, row;
sqlite_int64 container; sqlite_int64 objectID, parentID;
if( strstr(class, "imageItem") ) if( strstr(class, "imageItem") )
{ {
@ -144,7 +137,7 @@ insert_containers(const char * name, const char *path, const char * refID, const
static struct virtual_item last_camdate; static struct virtual_item last_camdate;
static sqlite_int64 last_all_objectID = 0; static sqlite_int64 last_all_objectID = 0;
asprintf(&sql, "SELECT DATE, CREATOR from DETAILS where ID = %lu", detailID); asprintf(&sql, "SELECT DATE, CREATOR from DETAILS where ID = %"PRId64, detailID);
ret = sql_get_table(db, sql, &result, &row, &cols); ret = sql_get_table(db, sql, &result, &row, &cols);
free(sql); free(sql);
if( ret == SQLITE_OK ) if( ret == SQLITE_OK )
@ -169,16 +162,16 @@ insert_containers(const char * name, const char *path, const char * refID, const
} }
else else
{ {
container = insert_container(date_taken, IMAGE_DATE_ID, NULL, "album.photoAlbum", NULL, NULL, NULL); insert_container(date_taken, IMAGE_DATE_ID, NULL, "album.photoAlbum", NULL, NULL, NULL, &objectID, &parentID);
sprintf(last_date.parentID, IMAGE_DATE_ID"$%llX", container>>32); sprintf(last_date.parentID, IMAGE_DATE_ID"$%"PRIX64, parentID);
last_date.objectID = (int)container; last_date.objectID = objectID;
strcpy(last_date.name, date_taken); strcpy(last_date.name, date_taken);
//DEBUG DPRINTF(E_DEBUG, L_SCANNER, "Creating cached date item: %s/%s/%X\n", last_date.name, last_date.parentID, last_date.objectID); //DEBUG DPRINTF(E_DEBUG, L_SCANNER, "Creating cached date item: %s/%s/%X\n", last_date.name, last_date.parentID, last_date.objectID);
} }
sql_exec(db, "INSERT into OBJECTS" sql_exec(db, "INSERT into OBJECTS"
" (OBJECT_ID, PARENT_ID, REF_ID, CLASS, DETAIL_ID, NAME) " " (OBJECT_ID, PARENT_ID, REF_ID, CLASS, DETAIL_ID, NAME) "
"VALUES" "VALUES"
" ('%s$%X', '%s', '%s', '%s', %lu, %Q)", " ('%s$%"PRIX64"', '%s', '%s', '%s', %"PRId64", %Q)",
last_date.parentID, last_date.objectID, last_date.parentID, refID, class, detailID, name); last_date.parentID, last_date.objectID, last_date.parentID, refID, class, detailID, name);
if( cam ) if( cam )
@ -192,8 +185,8 @@ insert_containers(const char * name, const char *path, const char * refID, const
} }
if( !valid_cache || strcmp(camera, last_cam.name) != 0 ) if( !valid_cache || strcmp(camera, last_cam.name) != 0 )
{ {
container = insert_container(camera, IMAGE_CAMERA_ID, NULL, "storageFolder", NULL, NULL, NULL); insert_container(camera, IMAGE_CAMERA_ID, NULL, "storageFolder", NULL, NULL, NULL, &objectID, &parentID);
sprintf(last_cam.parentID, IMAGE_CAMERA_ID"$%llX", container>>32); sprintf(last_cam.parentID, IMAGE_CAMERA_ID"$%"PRIX64, parentID);
strncpy(last_cam.name, camera, 255); strncpy(last_cam.name, camera, 255);
last_camdate.name[0] = '\0'; last_camdate.name[0] = '\0';
} }
@ -204,16 +197,16 @@ insert_containers(const char * name, const char *path, const char * refID, const
} }
else else
{ {
container = insert_container(date_taken, last_cam.parentID, NULL, "album.photoAlbum", NULL, NULL, NULL); insert_container(date_taken, last_cam.parentID, NULL, "album.photoAlbum", NULL, NULL, NULL, &objectID, &parentID);
sprintf(last_camdate.parentID, "%s$%llX", last_cam.parentID, container>>32); sprintf(last_camdate.parentID, "%s$%"PRIX64, last_cam.parentID, parentID);
last_camdate.objectID = (int)container; last_camdate.objectID = objectID;
strcpy(last_camdate.name, date_taken); strcpy(last_camdate.name, date_taken);
//DEBUG DPRINTF(E_DEBUG, L_SCANNER, "Creating cached camdate item: %s/%s/%s/%X\n", camera, last_camdate.name, last_camdate.parentID, last_camdate.objectID); //DEBUG DPRINTF(E_DEBUG, L_SCANNER, "Creating cached camdate item: %s/%s/%s/%X\n", camera, last_camdate.name, last_camdate.parentID, last_camdate.objectID);
} }
sql_exec(db, "INSERT into OBJECTS" sql_exec(db, "INSERT into OBJECTS"
" (OBJECT_ID, PARENT_ID, REF_ID, CLASS, DETAIL_ID, NAME) " " (OBJECT_ID, PARENT_ID, REF_ID, CLASS, DETAIL_ID, NAME) "
"VALUES" "VALUES"
" ('%s$%X', '%s', '%s', '%s', %lu, %Q)", " ('%s$%"PRIX64"', '%s', '%s', '%s', %"PRId64", %Q)",
last_camdate.parentID, last_camdate.objectID, last_camdate.parentID, refID, class, detailID, name); last_camdate.parentID, last_camdate.objectID, last_camdate.parentID, refID, class, detailID, name);
/* All Images */ /* All Images */
if( !last_all_objectID ) if( !last_all_objectID )
@ -223,12 +216,12 @@ insert_containers(const char * name, const char *path, const char * refID, const
sql_exec(db, "INSERT into OBJECTS" sql_exec(db, "INSERT into OBJECTS"
" (OBJECT_ID, PARENT_ID, REF_ID, CLASS, DETAIL_ID, NAME) " " (OBJECT_ID, PARENT_ID, REF_ID, CLASS, DETAIL_ID, NAME) "
"VALUES" "VALUES"
" ('"IMAGE_ALL_ID"$%llX', '"IMAGE_ALL_ID"', '%s', '%s', %lu, %Q)", " ('"IMAGE_ALL_ID"$%"PRIX64"', '"IMAGE_ALL_ID"', '%s', '%s', %"PRId64", %Q)",
last_all_objectID++, refID, class, detailID, name); last_all_objectID++, refID, class, detailID, name);
} }
else if( strstr(class, "audioItem") ) else if( strstr(class, "audioItem") )
{ {
asprintf(&sql, "SELECT ALBUM, ARTIST, GENRE, ALBUM_ART from DETAILS where ID = %lu", detailID); asprintf(&sql, "SELECT ALBUM, ARTIST, GENRE, ALBUM_ART from DETAILS where ID = %"PRId64, detailID);
ret = sql_get_table(db, sql, &result, &row, &cols); ret = sql_get_table(db, sql, &result, &row, &cols);
free(sql); free(sql);
if( ret != SQLITE_OK ) if( ret != SQLITE_OK )
@ -259,29 +252,29 @@ insert_containers(const char * name, const char *path, const char * refID, const
else else
{ {
strcpy(last_album.name, album); strcpy(last_album.name, album);
container = insert_container(album, MUSIC_ALBUM_ID, NULL, "album.musicAlbum", artist, genre, album_art); insert_container(album, MUSIC_ALBUM_ID, NULL, "album.musicAlbum", artist, genre, album_art, &objectID, &parentID);
sprintf(last_album.parentID, MUSIC_ALBUM_ID"$%llX", container>>32); sprintf(last_album.parentID, MUSIC_ALBUM_ID"$%llX", parentID);
last_album.objectID = (int)container; last_album.objectID = objectID;
//DEBUG DPRINTF(E_DEBUG, L_SCANNER, "Creating cached album item: %s/%s/%X\n", last_album.name, last_album.parentID, last_album.objectID); //DEBUG DPRINTF(E_DEBUG, L_SCANNER, "Creating cached album item: %s/%s/%X\n", last_album.name, last_album.parentID, last_album.objectID);
} }
sql_exec(db, "INSERT into OBJECTS" sql_exec(db, "INSERT into OBJECTS"
" (OBJECT_ID, PARENT_ID, REF_ID, CLASS, DETAIL_ID, NAME) " " (OBJECT_ID, PARENT_ID, REF_ID, CLASS, DETAIL_ID, NAME) "
"VALUES" "VALUES"
" ('%s$%X', '%s', '%s', '%s', %lu, %Q)", " ('%s$%"PRIX64"', '%s', '%s', '%s', %"PRId64", %Q)",
last_album.parentID, last_album.objectID, last_album.parentID, refID, class, detailID, name); last_album.parentID, last_album.objectID, last_album.parentID, refID, class, detailID, name);
} }
if( artist ) if( artist )
{ {
if( !valid_cache || strcmp(artist, last_artist.name) != 0 ) if( !valid_cache || strcmp(artist, last_artist.name) != 0 )
{ {
container = insert_container(artist, MUSIC_ARTIST_ID, NULL, "person.musicArtist", NULL, genre, NULL); insert_container(artist, MUSIC_ARTIST_ID, NULL, "person.musicArtist", NULL, genre, NULL, &objectID, &parentID);
sprintf(last_artist.parentID, MUSIC_ARTIST_ID"$%llX", container>>32); sprintf(last_artist.parentID, MUSIC_ARTIST_ID"$%"PRIX64, parentID);
strcpy(last_artist.name, artist); strcpy(last_artist.name, artist);
last_artistAlbum.name[0] = '\0'; last_artistAlbum.name[0] = '\0';
/* Add this file to the "- All Albums -" container as well */ /* Add this file to the "- All Albums -" container as well */
container = insert_container(_("- All Albums -"), last_artist.parentID, NULL, "album", artist, genre, NULL); insert_container(_("- All Albums -"), last_artist.parentID, NULL, "album", artist, genre, NULL, &objectID, &parentID);
sprintf(last_artistAlbumAll.parentID, "%s$%llX", last_artist.parentID, container>>32); sprintf(last_artistAlbumAll.parentID, "%s$%"PRIX64, last_artist.parentID, parentID);
last_artistAlbumAll.objectID = (int)container; last_artistAlbumAll.objectID = objectID;
} }
else else
{ {
@ -294,35 +287,36 @@ insert_containers(const char * name, const char *path, const char * refID, const
} }
else else
{ {
container = insert_container(album?album:_("Unknown Album"), last_artist.parentID, album?last_album.parentID:NULL, "album.musicAlbum", artist, genre, album_art); insert_container(album?album:_("Unknown Album"), last_artist.parentID, album?last_album.parentID:NULL,
sprintf(last_artistAlbum.parentID, "%s$%llX", last_artist.parentID, container>>32); "album.musicAlbum", artist, genre, album_art, &objectID, &parentID);
last_artistAlbum.objectID = (int)container; sprintf(last_artistAlbum.parentID, "%s$%"PRIX64, last_artist.parentID, parentID);
last_artistAlbum.objectID = objectID;
strcpy(last_artistAlbum.name, album?album:_("Unknown Album")); strcpy(last_artistAlbum.name, album?album:_("Unknown Album"));
//DEBUG DPRINTF(E_DEBUG, L_SCANNER, "Creating cached artist/album item: %s/%s/%X\n", last_artist.name, last_artist.parentID, last_artist.objectID); //DEBUG DPRINTF(E_DEBUG, L_SCANNER, "Creating cached artist/album item: %s/%s/%X\n", last_artist.name, last_artist.parentID, last_artist.objectID);
} }
sql_exec(db, "INSERT into OBJECTS" sql_exec(db, "INSERT into OBJECTS"
" (OBJECT_ID, PARENT_ID, REF_ID, CLASS, DETAIL_ID, NAME) " " (OBJECT_ID, PARENT_ID, REF_ID, CLASS, DETAIL_ID, NAME) "
"VALUES" "VALUES"
" ('%s$%X', '%s', '%s', '%s', %lu, %Q)", " ('%s$%"PRIX64"', '%s', '%s', '%s', %"PRId64", %Q)",
last_artistAlbum.parentID, last_artistAlbum.objectID, last_artistAlbum.parentID, refID, class, detailID, name); last_artistAlbum.parentID, last_artistAlbum.objectID, last_artistAlbum.parentID, refID, class, detailID, name);
sql_exec(db, "INSERT into OBJECTS" sql_exec(db, "INSERT into OBJECTS"
" (OBJECT_ID, PARENT_ID, REF_ID, CLASS, DETAIL_ID, NAME) " " (OBJECT_ID, PARENT_ID, REF_ID, CLASS, DETAIL_ID, NAME) "
"VALUES" "VALUES"
" ('%s$%X', '%s', '%s', '%s', %lu, %Q)", " ('%s$%"PRIX64"', '%s', '%s', '%s', %"PRId64", %Q)",
last_artistAlbumAll.parentID, last_artistAlbumAll.objectID, last_artistAlbumAll.parentID, refID, class, detailID, name); last_artistAlbumAll.parentID, last_artistAlbumAll.objectID, last_artistAlbumAll.parentID, refID, class, detailID, name);
} }
if( genre ) if( genre )
{ {
if( !valid_cache || strcmp(genre, last_genre.name) != 0 ) if( !valid_cache || strcmp(genre, last_genre.name) != 0 )
{ {
container = insert_container(genre, MUSIC_GENRE_ID, NULL, "genre.musicGenre", NULL, NULL, NULL); insert_container(genre, MUSIC_GENRE_ID, NULL, "genre.musicGenre", NULL, NULL, NULL, &objectID, &parentID);
sprintf(last_genre.parentID, MUSIC_GENRE_ID"$%llX", container>>32); sprintf(last_genre.parentID, MUSIC_GENRE_ID"$%"PRIX64, parentID);
strcpy(last_genre.name, genre); strcpy(last_genre.name, genre);
last_genreArtist.name[0] = '\0'; last_genreArtist.name[0] = '\0';
/* Add this file to the "- All Artists -" container as well */ /* Add this file to the "- All Artists -" container as well */
container = insert_container(_("- All Artists -"), last_genre.parentID, NULL, "person", NULL, genre, NULL); insert_container(_("- All Artists -"), last_genre.parentID, NULL, "person", NULL, genre, NULL, &objectID, &parentID);
sprintf(last_genreArtistAll.parentID, "%s$%llX", last_genre.parentID, container>>32); sprintf(last_genreArtistAll.parentID, "%s$%"PRIX64, last_genre.parentID, parentID);
last_genreArtistAll.objectID = (int)container; last_genreArtistAll.objectID = objectID;
} }
else else
{ {
@ -334,21 +328,22 @@ insert_containers(const char * name, const char *path, const char * refID, const
} }
else else
{ {
container = insert_container(artist?artist:_("Unknown Artist"), last_genre.parentID, artist?last_artist.parentID:NULL, "person.musicArtist", NULL, genre, NULL); insert_container(artist?artist:_("Unknown Artist"), last_genre.parentID, artist?last_artist.parentID:NULL,
sprintf(last_genreArtist.parentID, "%s$%llX", last_genre.parentID, container>>32); "person.musicArtist", NULL, genre, NULL, &objectID, &parentID);
last_genreArtist.objectID = (int)container; sprintf(last_genreArtist.parentID, "%s$%"PRIX64, last_genre.parentID, parentID);
last_genreArtist.objectID = objectID;
strcpy(last_genreArtist.name, artist?artist:_("Unknown Artist")); strcpy(last_genreArtist.name, artist?artist:_("Unknown Artist"));
//DEBUG DPRINTF(E_DEBUG, L_SCANNER, "Creating cached genre/artist item: %s/%s/%X\n", last_genreArtist.name, last_genreArtist.parentID, last_genreArtist.objectID); //DEBUG DPRINTF(E_DEBUG, L_SCANNER, "Creating cached genre/artist item: %s/%s/%X\n", last_genreArtist.name, last_genreArtist.parentID, last_genreArtist.objectID);
} }
sql_exec(db, "INSERT into OBJECTS" sql_exec(db, "INSERT into OBJECTS"
" (OBJECT_ID, PARENT_ID, REF_ID, CLASS, DETAIL_ID, NAME) " " (OBJECT_ID, PARENT_ID, REF_ID, CLASS, DETAIL_ID, NAME) "
"VALUES" "VALUES"
" ('%s$%X', '%s', '%s', '%s', %lu, %Q)", " ('%s$%"PRIX64"', '%s', '%s', '%s', %"PRId64", %Q)",
last_genreArtist.parentID, last_genreArtist.objectID, last_genreArtist.parentID, refID, class, detailID, name); last_genreArtist.parentID, last_genreArtist.objectID, last_genreArtist.parentID, refID, class, detailID, name);
sql_exec(db, "INSERT into OBJECTS" sql_exec(db, "INSERT into OBJECTS"
" (OBJECT_ID, PARENT_ID, REF_ID, CLASS, DETAIL_ID, NAME) " " (OBJECT_ID, PARENT_ID, REF_ID, CLASS, DETAIL_ID, NAME) "
"VALUES" "VALUES"
" ('%s$%X', '%s', '%s', '%s', %lu, %Q)", " ('%s$%"PRIX64"', '%s', '%s', '%s', %"PRId64", %Q)",
last_genreArtistAll.parentID, last_genreArtistAll.objectID, last_genreArtistAll.parentID, refID, class, detailID, name); last_genreArtistAll.parentID, last_genreArtistAll.objectID, last_genreArtistAll.parentID, refID, class, detailID, name);
} }
/* All Music */ /* All Music */
@ -359,7 +354,7 @@ insert_containers(const char * name, const char *path, const char * refID, const
sql_exec(db, "INSERT into OBJECTS" sql_exec(db, "INSERT into OBJECTS"
" (OBJECT_ID, PARENT_ID, REF_ID, CLASS, DETAIL_ID, NAME) " " (OBJECT_ID, PARENT_ID, REF_ID, CLASS, DETAIL_ID, NAME) "
"VALUES" "VALUES"
" ('"MUSIC_ALL_ID"$%llX', '"MUSIC_ALL_ID"', '%s', '%s', %lu, %Q)", " ('"MUSIC_ALL_ID"$%"PRIX64"', '"MUSIC_ALL_ID"', '%s', '%s', %"PRId64", %Q)",
last_all_objectID++, refID, class, detailID, name); last_all_objectID++, refID, class, detailID, name);
} }
else if( strstr(class, "videoItem") ) else if( strstr(class, "videoItem") )
@ -374,7 +369,7 @@ insert_containers(const char * name, const char *path, const char * refID, const
sql_exec(db, "INSERT into OBJECTS" sql_exec(db, "INSERT into OBJECTS"
" (OBJECT_ID, PARENT_ID, REF_ID, CLASS, DETAIL_ID, NAME) " " (OBJECT_ID, PARENT_ID, REF_ID, CLASS, DETAIL_ID, NAME) "
"VALUES" "VALUES"
" ('"VIDEO_ALL_ID"$%llX', '"VIDEO_ALL_ID"', '%s', '%s', %lu, %Q)", " ('"VIDEO_ALL_ID"$%"PRIX64"', '"VIDEO_ALL_ID"', '%s', '%s', %"PRId64", %Q)",
last_all_objectID++, refID, class, detailID, name); last_all_objectID++, refID, class, detailID, name);
return; return;
} }
@ -389,15 +384,14 @@ insert_containers(const char * name, const char *path, const char * refID, const
int int
insert_directory(const char * name, const char * path, const char * base, const char * parentID, int objectID) insert_directory(const char * name, const char * path, const char * base, const char * parentID, int objectID)
{ {
char * sql; int found = 0;
int rows, found = 0;
sqlite_int64 detailID = 0; sqlite_int64 detailID = 0;
char * refID = NULL; char * refID = NULL;
char class[] = "container.storageFolder"; char class[] = "container.storageFolder";
char * id_buf = NULL; char * id_buf = NULL;
char * parent_buf = NULL; char * parent_buf = NULL;
char **result; char *dir_buf, *dir;
char *dir = NULL; char *result, *p;
static char last_found[256] = "-1"; static char last_found[256] = "-1";
if( strcmp(base, BROWSEDIR_ID) != 0 ) if( strcmp(base, BROWSEDIR_ID) != 0 )
@ -405,8 +399,8 @@ insert_directory(const char * name, const char * path, const char * base, const
if( refID ) if( refID )
{ {
dir = strdup(path); dir_buf = strdup(path);
dir = dirname(dir); dir = dirname(dir_buf);
asprintf(&id_buf, "%s%s$%X", base, parentID, objectID); asprintf(&id_buf, "%s%s$%X", base, parentID, objectID);
asprintf(&parent_buf, "%s%s", base, parentID); asprintf(&parent_buf, "%s%s", base, parentID);
while( !found ) while( !found )
@ -419,30 +413,29 @@ insert_directory(const char * name, const char * path, const char * base, const
break; break;
} }
/* Does not exist. Need to create, and may need to create parents also */ /* Does not exist. Need to create, and may need to create parents also */
sql = sqlite3_mprintf("SELECT DETAIL_ID from OBJECTS where OBJECT_ID = '%s'", refID); result = sql_get_text_field(db, "SELECT DETAIL_ID from OBJECTS where OBJECT_ID = '%s'", refID);
if( (sql_get_table(db, sql, &result, &rows, NULL) == SQLITE_OK) && rows ) if( result )
{ {
detailID = atoi(result[1]); detailID = strtoll(result, NULL, 10);
sqlite3_free(result);
} }
sqlite3_free_table(result);
sqlite3_free(sql);
sql_exec(db, "INSERT into OBJECTS" sql_exec(db, "INSERT into OBJECTS"
" (OBJECT_ID, PARENT_ID, REF_ID, DETAIL_ID, CLASS, NAME) " " (OBJECT_ID, PARENT_ID, REF_ID, DETAIL_ID, CLASS, NAME) "
"VALUES" "VALUES"
" ('%s', '%s', %Q, '%lld', '%s', '%q')", " ('%s', '%s', %Q, %"PRId64", '%s', '%q')",
id_buf, parent_buf, refID, detailID, class, rindex(dir, '/')+1); id_buf, parent_buf, refID, detailID, class, strrchr(dir, '/')+1);
if( rindex(id_buf, '$') ) if( (p = strrchr(id_buf, '$')) )
*rindex(id_buf, '$') = '\0'; *p = '\0';
if( rindex(parent_buf, '$') ) if( (p = strrchr(parent_buf, '$')) )
*rindex(parent_buf, '$') = '\0'; *p = '\0';
if( rindex(refID, '$') ) if( (p = strrchr(refID, '$')) )
*rindex(refID, '$') = '\0'; *p = '\0';
dir = dirname(dir); dir = dirname(dir);
} }
free(refID); free(refID);
free(parent_buf); free(parent_buf);
free(id_buf); free(id_buf);
free(dir); free(dir_buf);
return 1; return 1;
} }
@ -450,7 +443,7 @@ insert_directory(const char * name, const char * path, const char * base, const
sql_exec(db, "INSERT into OBJECTS" sql_exec(db, "INSERT into OBJECTS"
" (OBJECT_ID, PARENT_ID, REF_ID, DETAIL_ID, CLASS, NAME) " " (OBJECT_ID, PARENT_ID, REF_ID, DETAIL_ID, CLASS, NAME) "
"VALUES" "VALUES"
" ('%s%s$%X', '%s%s', %Q, '%lld', '%s', '%q')", " ('%s%s$%X', '%s%s', %Q, %"PRId64", '%s', '%q')",
base, parentID, objectID, base, parentID, refID, detailID, class, name); base, parentID, objectID, base, parentID, refID, detailID, class, name);
if( refID ) if( refID )
free(refID); free(refID);
@ -463,7 +456,7 @@ insert_file(char * name, const char * path, const char * parentID, int object)
{ {
char class[32]; char class[32];
char objectID[64]; char objectID[64];
unsigned long int detailID = 0; sqlite3_int64 detailID = 0;
char base[8]; char base[8];
char * typedir_parentID; char * typedir_parentID;
int typedir_objectID; int typedir_objectID;
@ -511,17 +504,17 @@ insert_file(char * name, const char * path, const char * parentID, int object)
sql_exec(db, "INSERT into OBJECTS" sql_exec(db, "INSERT into OBJECTS"
" (OBJECT_ID, PARENT_ID, CLASS, DETAIL_ID, NAME) " " (OBJECT_ID, PARENT_ID, CLASS, DETAIL_ID, NAME) "
"VALUES" "VALUES"
" ('%s', '%s%s', '%s', %lu, '%q')", " ('%s', '%s%s', '%s', %"PRId64", '%q')",
objectID, BROWSEDIR_ID, parentID, class, detailID, name); objectID, BROWSEDIR_ID, parentID, class, detailID, name);
if( *parentID ) if( *parentID )
{ {
typedir_objectID = 0; typedir_objectID = 0;
typedir_parentID = strdup(parentID); typedir_parentID = strdup(parentID);
baseid = rindex(typedir_parentID, '$'); baseid = strrchr(typedir_parentID, '$');
if( baseid ) if( baseid )
{ {
sscanf(baseid+1, "%X", &typedir_objectID); typedir_objectID = strtol(baseid+1, NULL, 16);
*baseid = '\0'; *baseid = '\0';
} }
insert_directory(name, path, base, typedir_parentID, typedir_objectID); insert_directory(name, path, base, typedir_parentID, typedir_objectID);
@ -530,7 +523,7 @@ insert_file(char * name, const char * path, const char * parentID, int object)
sql_exec(db, "INSERT into OBJECTS" sql_exec(db, "INSERT into OBJECTS"
" (OBJECT_ID, PARENT_ID, REF_ID, CLASS, DETAIL_ID, NAME) " " (OBJECT_ID, PARENT_ID, REF_ID, CLASS, DETAIL_ID, NAME) "
"VALUES" "VALUES"
" ('%s%s$%X', '%s%s', '%s', '%s', %lu, '%q')", " ('%s%s$%X', '%s%s', '%s', '%s', %"PRId64", '%q')",
base, parentID, object, base, parentID, objectID, class, detailID, name); base, parentID, object, base, parentID, objectID, class, detailID, name);
insert_containers(name, path, objectID, class, detailID); insert_containers(name, path, objectID, class, detailID);

View File

@ -310,9 +310,7 @@ _asf_load_picture(FILE *fp, int size, void *bm, int *bm_size)
{ {
int i; int i;
char buf[256]; char buf[256];
char pic_type; #if 0
long pic_size;
// //
// Picture type $xx // Picture type $xx
// Data length $xx $xx $xx $xx // Data length $xx $xx $xx $xx
@ -320,9 +318,15 @@ _asf_load_picture(FILE *fp, int size, void *bm, int *bm_size)
// Description <text string> $00 // Description <text string> $00
// Picture data <binary data> // Picture data <binary data>
char pic_type;
long pic_size;
pic_type = fget_byte(fp); size -= 1; pic_type = fget_byte(fp); size -= 1;
pic_size = fget_le32(fp); size -= 4; pic_size = fget_le32(fp); size -= 4;
#else
fseek(fp, 5, SEEK_CUR);
size -= 5;
#endif
for(i = 0; i < sizeof(buf) - 1; i++) for(i = 0; i < sizeof(buf) - 1; i++)
{ {
buf[i] = fget_le16(fp); size -= 2; buf[i] = fget_le16(fp); size -= 2;
@ -388,7 +392,6 @@ _get_asffileinfo(char *file, struct song_metadata *psong)
asf_object_t hdr; asf_object_t hdr;
asf_object_t tmp; asf_object_t tmp;
unsigned long NumObjects; unsigned long NumObjects;
unsigned short Reserved;
unsigned short TitleLength; unsigned short TitleLength;
unsigned short AuthorLength; unsigned short AuthorLength;
unsigned short CopyrightLength; unsigned short CopyrightLength;
@ -400,7 +403,6 @@ _get_asffileinfo(char *file, struct song_metadata *psong)
unsigned short ValueLength; unsigned short ValueLength;
off_t pos; off_t pos;
char buf[2048]; char buf[2048];
int mask;
asf_file_properties_t FileProperties; asf_file_properties_t FileProperties;
psong->vbr_scale = -1; psong->vbr_scale = -1;
@ -426,10 +428,9 @@ _get_asffileinfo(char *file, struct song_metadata *psong)
return -1; return -1;
} }
NumObjects = fget_le32(fp); NumObjects = fget_le32(fp);
Reserved = fget_le16(fp); fseek(fp, 2, SEEK_CUR); // Reserved le16
pos = ftell(fp); pos = ftell(fp);
mask = 0;
while(NumObjects > 0) while(NumObjects > 0)
{ {
if(sizeof(tmp) != fread(&tmp, 1, sizeof(tmp), fp)) if(sizeof(tmp) != fread(&tmp, 1, sizeof(tmp), fp))

View File

@ -25,7 +25,6 @@ _get_flctags(char *filename, struct song_metadata *psong)
{ {
FLAC__Metadata_SimpleIterator *iterator = 0; FLAC__Metadata_SimpleIterator *iterator = 0;
FLAC__StreamMetadata *block; FLAC__StreamMetadata *block;
int block_number;
unsigned int sec, ms; unsigned int sec, ms;
int i; int i;
int err = 0; int err = 0;
@ -36,7 +35,6 @@ _get_flctags(char *filename, struct song_metadata *psong)
return -1; return -1;
} }
block_number = 0;
if(!FLAC__metadata_simple_iterator_init(iterator, filename, true, true)) if(!FLAC__metadata_simple_iterator_init(iterator, filename, true, true))
{ {
DPRINTF(E_ERROR, L_SCANNER, "Cannot extract tag from %s\n", filename); DPRINTF(E_ERROR, L_SCANNER, "Cannot extract tag from %s\n", filename);

View File

@ -196,7 +196,6 @@ static void
_ogg_vorbis_end(ogg_stream_processor *stream, struct song_metadata *psong) _ogg_vorbis_end(ogg_stream_processor *stream, struct song_metadata *psong)
{ {
ogg_misc_vorbis_info *inf = stream->data; ogg_misc_vorbis_info *inf = stream->data;
long minutes, seconds;
double bitrate, time; double bitrate, time;
time = (double)inf->lastgranulepos / inf->vi.rate; time = (double)inf->lastgranulepos / inf->vi.rate;
@ -211,9 +210,6 @@ _ogg_vorbis_end(ogg_stream_processor *stream, struct song_metadata *psong)
psong->song_length = time * 1000; psong->song_length = time * 1000;
} }
minutes = (long)time / 60;
seconds = (long)time - minutes * 60;
vorbis_comment_clear(&inf->vc); vorbis_comment_clear(&inf->vc);
vorbis_info_clear(&inf->vi); vorbis_info_clear(&inf->vi);
@ -307,7 +303,7 @@ static ogg_stream_processor *
_ogg_find_stream_processor(ogg_stream_set *set, ogg_page *page) _ogg_find_stream_processor(ogg_stream_set *set, ogg_page *page)
{ {
ogg_uint32_t serial = ogg_page_serialno(page); ogg_uint32_t serial = ogg_page_serialno(page);
int i, found = 0; int i;
int invalid = 0; int invalid = 0;
int constraint = 0; int constraint = 0;
ogg_stream_processor *stream; ogg_stream_processor *stream;
@ -316,7 +312,6 @@ _ogg_find_stream_processor(ogg_stream_set *set, ogg_page *page)
{ {
if(serial == set->streams[i].serial) if(serial == set->streams[i].serial)
{ {
found = 1;
stream = &(set->streams[i]); stream = &(set->streams[i]);
set->in_headers = 0; set->in_headers = 0;

View File

@ -289,6 +289,7 @@ fetch_string_txt(char *fname, char *lang, int n, ...)
if (!*strs[i]) if (!*strs[i])
*strs[i] = defstr[i]; *strs[i] = defstr[i];
} }
fclose(fp);
_exit: _exit:
free(keys); free(keys);

View File

@ -74,6 +74,8 @@ decodeString(char * string, int inplace)
} }
if( inplace ) if( inplace )
{ {
if( ns )
free(ns);
return string; return string;
} }
else else

View File

@ -527,6 +527,7 @@ static const struct serviceDesc scpdX_MS_MediaReceiverRegistrar =
static char * static char *
strcat_str(char * str, int * len, int * tmplen, const char * s2) strcat_str(char * str, int * len, int * tmplen, const char * s2)
{ {
char *p;
int s2len; int s2len;
s2len = (int)strlen(s2); s2len = (int)strlen(s2);
if(*tmplen <= (*len + s2len)) if(*tmplen <= (*len + s2len))
@ -535,7 +536,17 @@ strcat_str(char * str, int * len, int * tmplen, const char * s2)
*tmplen += 256; *tmplen += 256;
else else
*tmplen += s2len + 1; *tmplen += s2len + 1;
str = (char *)realloc(str, *tmplen); p = realloc(str, *tmplen);
if (!p)
{
if(s2len < 256)
*tmplen -= 256;
else
*tmplen -= s2len + 1;
return str;
}
else
str = p;
} }
/*strcpy(str + *len, s2); */ /*strcpy(str + *len, s2); */
memcpy(str + *len, s2, s2len + 1); memcpy(str + *len, s2, s2len + 1);
@ -549,10 +560,18 @@ strcat_str(char * str, int * len, int * tmplen, const char * s2)
static char * static char *
strcat_char(char * str, int * len, int * tmplen, char c) strcat_char(char * str, int * len, int * tmplen, char c)
{ {
char *p;
if(*tmplen <= (*len + 1)) if(*tmplen <= (*len + 1))
{ {
*tmplen += 256; *tmplen += 256;
str = (char *)realloc(str, *tmplen); p = (char *)realloc(str, *tmplen);
if (!p)
{
*tmplen -= 256;
return str;
}
else
str = p;
} }
str[*len] = c; str[*len] = c;
(*len)++; (*len)++;

View File

@ -1469,21 +1469,24 @@ SendResp_resizedimg(struct upnphttp * h, char * object)
char date[30]; char date[30];
char dlna_pn[4]; char dlna_pn[4];
time_t curtime = time(NULL); time_t curtime = time(NULL);
int width=640, height=480, dstw, dsth, rotation, size; int width=640, height=480, dstw, dsth, size;
long srcw, srch; long srcw, srch;
unsigned char * data = NULL; unsigned char * data = NULL;
char *path, *file_path; char *path, *file_path;
char *resolution, *tn; char *resolution;
char *key, *val; char *key, *val;
char *saveptr=NULL, *item=NULL; char *saveptr=NULL, *item=NULL;
/* Not implemented yet *
char *pixelshape=NULL; char *pixelshape=NULL;
int rotation; */
sqlite_int64 id; sqlite_int64 id;
int rows=0, chunked=0, ret; int rows=0, chunked=0, ret;
#ifdef __sparc__ #ifdef __sparc__
char *tn;
ExifData *ed; ExifData *ed;
ExifLoader *l; ExifLoader *l;
#endif #endif
image *imsrc = NULL, *imdst = NULL; image_s *imsrc = NULL, *imdst = NULL;
int scale = 1; int scale = 1;
id = strtoll(object, NULL, 10); id = strtoll(object, NULL, 10);
@ -1510,7 +1513,6 @@ SendResp_resizedimg(struct upnphttp * h, char * object)
#endif #endif
file_path = result[3]; file_path = result[3];
resolution = result[4]; resolution = result[4];
tn = result[5];
srcw = strtol(resolution, &saveptr, 10); srcw = strtol(resolution, &saveptr, 10);
srch = strtol(saveptr+1, NULL, 10); srch = strtol(saveptr+1, NULL, 10);
@ -1535,6 +1537,7 @@ SendResp_resizedimg(struct upnphttp * h, char * object)
{ {
height = atoi(val); height = atoi(val);
} }
/* Not implemented yet *
else if( strcasecmp(key, "rotation") == 0 ) else if( strcasecmp(key, "rotation") == 0 )
{ {
rotation = atoi(val); rotation = atoi(val);
@ -1542,7 +1545,7 @@ SendResp_resizedimg(struct upnphttp * h, char * object)
else if( strcasecmp(key, "pixelshape") == 0 ) else if( strcasecmp(key, "pixelshape") == 0 )
{ {
pixelshape = val; pixelshape = val;
} } */
item = strtok_r(NULL, "&,", &saveptr); item = strtok_r(NULL, "&,", &saveptr);
} }
free(path); free(path);
@ -1600,6 +1603,7 @@ SendResp_resizedimg(struct upnphttp * h, char * object)
/* Resizing from a thumbnail is much faster than from a large image */ /* Resizing from a thumbnail is much faster than from a large image */
#ifdef __sparc__ #ifdef __sparc__
tn = result[5];
if( dstw <= 160 && dsth <= 120 && atoi(tn) ) if( dstw <= 160 && dsth <= 120 && atoi(tn) )
{ {
l = exif_loader_new(); l = exif_loader_new();

View File

@ -652,7 +652,7 @@ callback(void *args, int argc, char **argv, char **azColName)
char dlna_buf[96]; char dlna_buf[96];
char ext[5]; char ext[5];
char str_buf[512]; char str_buf[512];
int children, ret = 0; int ret = 0;
/* Make sure we have at least 4KB left of allocated memory to finish the response. */ /* Make sure we have at least 4KB left of allocated memory to finish the response. */
if( passed_args->size > (passed_args->alloced - 4096) ) if( passed_args->size > (passed_args->alloced - 4096) )
@ -956,6 +956,7 @@ callback(void *args, int argc, char **argv, char **azColName)
passed_args->size += ret; passed_args->size += ret;
if( passed_args->filter & FILTER_CHILDCOUNT ) if( passed_args->filter & FILTER_CHILDCOUNT )
{ {
int children;
ret = sql_get_int_field(db, "SELECT count(*) from OBJECTS where PARENT_ID = '%s';", id); ret = sql_get_int_field(db, "SELECT count(*) from OBJECTS where PARENT_ID = '%s';", id);
children = (ret > 0) ? ret : 0; children = (ret > 0) ? ret : 0;
ret = sprintf(str_buf, "childCount=\"%d\"", children); ret = sprintf(str_buf, "childCount=\"%d\"", children);
@ -1545,14 +1546,14 @@ void
ExecuteSoapAction(struct upnphttp * h, const char * action, int n) ExecuteSoapAction(struct upnphttp * h, const char * action, int n)
{ {
char * p; char * p;
char * p2;
int i, len, methodlen;
i = 0;
p = strchr(action, '#'); p = strchr(action, '#');
if(p) if(p)
{ {
int i = 0;
int len;
int methodlen;
char * p2;
p++; p++;
p2 = strchr(p, '"'); p2 = strchr(p, '"');
if(p2) if(p2)

View File

@ -100,7 +100,12 @@ modifyString(char * string, const char * before, const char * after, short like)
chgcnt++; chgcnt++;
s = p+oldlen; s = p+oldlen;
} }
string = realloc(string, strlen(string)+((newlen-oldlen)*chgcnt)+1+like); s = realloc(string, strlen(string)+((newlen-oldlen)*chgcnt)+1+like);
/* If we failed to realloc, return the original alloc'd string */
if( s )
string = s;
else
return string;
} }
s = string; s = string;
@ -136,7 +141,7 @@ modifyString(char * string, const char * before, const char * after, short like)
} }
char * char *
escape_tag(const char *tag, uint8_t force_alloc) escape_tag(const char *tag, int force_alloc)
{ {
char *esc_tag = NULL; char *esc_tag = NULL;

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, uint8_t force_alloc); escape_tag(const char *tag, int force_alloc);
void void
strip_ext(char * name); strip_ext(char * name);