diff --git a/albumart.c b/albumart.c index e3be12a..9ba5c8f 100644 --- a/albumart.c +++ b/albumart.c @@ -44,10 +44,10 @@ art_cache_exists(const char * orig_path, char ** cache_file) } char * -save_resized_album_art(image * imsrc, const char * path) +save_resized_album_art(image_s * imsrc, const char * path) { int dstw, dsth; - image * imdst; + image_s * imdst; char * cache_file; 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 * cache_dir; FILE * dstfile; - image * imsrc; - size_t nwritten; + image_s * imsrc; static char last_path[PATH_MAX]; static unsigned int last_hash = 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 ) { + size_t nwritten; if( art_cache_exists(path, &art_path) ) goto end_art; cache_dir = strdup(art_path); @@ -272,7 +272,7 @@ check_for_album_file(char * dir, const char * path) { char * file = malloc(PATH_MAX); struct album_art_name_s * album_art_name; - image * imsrc = NULL; + image_s * imsrc = NULL; int width=0, height=0; char * art_file; diff --git a/getifaddr.c b/getifaddr.c index 2d18cbd..b34a379 100644 --- a/getifaddr.c +++ b/getifaddr.c @@ -217,7 +217,7 @@ get_remote_mac(struct in_addr ip_addr, unsigned char * mac) return 1; 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, &mac[0], &mac[1], &mac[2], &mac[3], &mac[4], &mac[5]); if( matches != 9 ) diff --git a/image_utils.c b/image_utils.c index 8ce4bb6..79b4625 100644 --- a/image_utils.c +++ b/image_utils.c @@ -203,14 +203,14 @@ libjpeg_error_handler(j_common_ptr cinfo) } void -image_free(image *pimage) +image_free(image_s *pimage) { free(pimage->buf); free(pimage); } 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)) { @@ -224,7 +224,7 @@ get_pix(image *pimage, int32_t x, int32_t y) } 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)) pimage->buf[(y * pimage->width) + x] = col; @@ -295,7 +295,7 @@ image_get_jpeg_date_xmp(const char * path, char ** date) { FILE *img; unsigned char buf[8]; - char *data = NULL; + char *data = NULL, *newdata; u_int16_t offset; struct NameValueParserData xml; char * exif; @@ -337,7 +337,11 @@ image_get_jpeg_date_xmp(const char * path, char ** date) continue; } - data = realloc(data, 30); + newdata = realloc(data, 30); + if( !newdata ) + break; + data = newdata; + fread(data, 29, 1, img); offset -= 29; 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; } - data = realloc(data, offset+1); + newdata = realloc(data, offset+1); + if( !newdata ) + break; + data = newdata; fread(data, offset, 1, img); ParseNameValue(data, offset, &xml); @@ -378,12 +385,12 @@ image_get_jpeg_date_xmp(const char * path, char ** date) return ret; } -image * +image_s * 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"); return NULL; @@ -399,10 +406,10 @@ image_new(int32_t width, int32_t height) return(vimage); } -image * +image_s * 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; struct jpeg_decompress_struct cinfo; 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) { DPRINTF(E_WARN, L_METADATA, "malloc failed\n"); + image_free(vimage); + if( is_file ) + fclose(file); return NULL; } @@ -541,7 +551,7 @@ image_new_from_jpeg(const char * path, int is_file, const char * buf, int size, } 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; #if !defined __i386__ && !defined __x86_64__ @@ -604,7 +614,7 @@ image_upsize(image * pdest, image * psrc, int32_t width, int32_t height) } 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; pix vcol; @@ -747,10 +757,10 @@ image_downsize(image * pdest, image * psrc, int32_t width, int32_t height) } } -image * -image_resize(image * src_image, int32_t width, int32_t height) +image_s * +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); if( !dst_image ) @@ -765,7 +775,7 @@ image_resize(image * src_image, int32_t width, int32_t height) 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_error_mgr jerr; @@ -813,7 +823,7 @@ image_save_to_jpeg_buf(image * pimage, int * size) } 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; unsigned char * buf; diff --git a/image_utils.h b/image_utils.h index 74d684e..40ffaea 100644 --- a/image_utils.h +++ b/image_utils.h @@ -29,10 +29,10 @@ typedef struct { int32_t width; int32_t height; pix *buf; -} image; +} image_s; void -image_free(image *pimage); +image_free(image_s *pimage); int 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 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 * -image_resize(image * src_image, int32_t width, int32_t height); +image_s * +image_resize(image_s * src_image, int32_t width, int32_t height); unsigned char * -image_save_to_jpeg_buf(image * pimage, int * size); +image_save_to_jpeg_buf(image_s * pimage, int * size); int -image_save_to_jpeg_file(image * pimage, const char * path); +image_save_to_jpeg_file(image_s * pimage, const char * path); diff --git a/inotify.c b/inotify.c index 06f1529..51ab35f 100644 --- a/inotify.c +++ b/inotify.c @@ -154,7 +154,7 @@ inotify_create_watches(int fd) max_watches = fopen("/proc/sys/fs/inotify/max_user_watches", "r"); if( max_watches ) { - fscanf(max_watches, "%u", &watch_limit); + fscanf(max_watches, "%10u", &watch_limit); fclose(max_watches); 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 inotify_insert_file(char * name, const char * path) { - char * sql; - char **result; - int rows; - char * last_dir = strdup(path); - char * path_buf = strdup(path); - char * base_name = malloc(strlen(path)); - char * base_copy = base_name; + int len; + char * last_dir; + char * path_buf; + char * base_name; + char * base_copy; char * parent_buf = NULL; char * id = NULL; int depth = 1; + int ts; enum media_types type = ALL_MEDIA; struct media_dir_s * media_path = media_dirs; struct stat st; @@ -337,74 +336,59 @@ inotify_insert_file(char * name, const char * path) if( stat(path, &st) != 0 ) return -1; - sql = sqlite3_mprintf("SELECT TIMESTAMP from DETAILS where PATH = '%q'", path); - if( sql_get_table(db, sql, &result, &rows, NULL) == SQLITE_OK ) + ts = sql_get_int_field(db, "SELECT TIMESTAMP from DETAILS where PATH = '%q'", path); + 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); - inotify_remove_file(path_buf); - next_pl_fill = 1; - } - sqlite3_free_table(result); + DPRINTF(E_DEBUG, L_INOTIFY, "Re-reading modified playlist.\n", path); + inotify_remove_file(path); + next_pl_fill = 1; } - sqlite3_free(sql); + 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); + } + /* 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 ) { depth = 0; strcpy(path_buf, path); parent_buf = dirname(path_buf); - strcpy(last_dir, path_buf); do { //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)" - " where d.PATH = '%q' and REF_ID is NULL", parent_buf); - if( (sql_get_table(db, sql, &result, &rows, NULL) == SQLITE_OK) && rows ) + 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); + if( id ) { - id = strdup(result[1]); - sqlite3_free_table(result); - sqlite3_free(sql); if( !depth ) 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 */ strcpy(base_name, last_dir); base_copy = basename(base_name); insert_directory(base_copy, last_dir, BROWSEDIR_ID, id+2, get_next_available_id("OBJECTS", id)); - free(id); + sqlite3_free(id); break; } depth++; - strcpy(last_dir, path_buf); + strcpy(last_dir, parent_buf); parent_buf = dirname(parent_buf); - sqlite3_free_table(result); - sqlite3_free(sql); } while( strcmp(parent_buf, "/") != 0 ); if( strcmp(parent_buf, "/") == 0 ) { - id = strdup(BROWSEDIR_ID); + id = sqlite3_mprintf("%s", BROWSEDIR_ID); depth = 0; break; } @@ -418,7 +402,7 @@ inotify_insert_file(char * name, const char * path) { //DEBUG DPRINTF(E_DEBUG, L_INOTIFY, "Inserting %s\n", name); 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 ) { 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; struct dirent * e; - char * sql; - char **result; - char *id=NULL, *path_buf, *parent_buf, *esc_name; + char *id, *path_buf, *parent_buf, *esc_name; int wd; - int rows; enum file_types type = TYPE_UNKNOWN; enum media_types dir_type = ALL_MEDIA; 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)); return -1; } - - 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 ) + if( sql_get_int_field(db, "SELECT ID from DETAILS where PATH = '%q'", path) > 0 ) { - id = strdup(rows?result[1]:BROWSEDIR_ID); - insert_directory(name, path, BROWSEDIR_ID, id+2, get_next_available_id("OBJECTS", id)); - free(id); + DPRINTF(E_DEBUG, L_INOTIFY, "%s already exists\n", path); + return 0; } + + 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); - sqlite3_free(sql); wd = add_watch(fd, path); if( wd == -1 ) @@ -529,24 +512,19 @@ inotify_remove_file(const char * path) char * sql; char **result; char * art_cache; - sqlite_int64 detailID = 0; - int i, rows, children, playlist, ret = 1; + char * ptr; + sqlite_int64 detailID; + int rows, playlist; /* Invalidate the scanner cache so we don't insert files into non-existent containers */ valid_cache = 0; playlist = is_playlist(path); - sql = sqlite3_mprintf("SELECT ID from %s where PATH = '%q'", playlist?"PLAYLISTS":"DETAILS", path); - if( (sql_get_table(db, sql, &result, &rows, NULL) == SQLITE_OK) ) - { - if( rows ) - { - detailID = strtoll(result[1], NULL, 10); - ret = 0; - } - sqlite3_free_table(result); - } + sql = sql_get_text_field(db, "SELECT ID from %s where PATH = '%q'", playlist?"PLAYLISTS":"DETAILS", path); + if( !sql ) + return 1; + detailID = strtoll(sql, NULL, 10); sqlite3_free(sql); - if( playlist && detailID ) + if( playlist ) { sql_exec(db, "DELETE from PLAYLISTS where ID = %lld", detailID); 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'", MUSIC_PLIST_ID, detailID, MUSIC_PLIST_ID, detailID); } - else if( detailID ) + else { /* Delete the parent containers if we are about to empty them. */ asprintf(&sql, "SELECT PARENT_ID from OBJECTS where DETAIL_ID = %lld", detailID); if( (sql_get_table(db, sql, &result, &rows, NULL) == SQLITE_OK) ) { + int i, children; for( i=1; i <= rows; i++ ) { /* 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]); 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 ) { sql_exec(db, "DELETE from DETAILS where ID =" @@ -599,7 +580,7 @@ inotify_remove_file(const char * path) remove(art_cache); free(art_cache); - return ret; + return 0; } int diff --git a/metadata.c b/metadata.c index 0b7ec5c..7cda7e7 100644 --- a/metadata.c +++ b/metadata.c @@ -137,10 +137,8 @@ is_tivo_file(const char * path) void check_for_captions(const char * path, sqlite_int64 detailID) { - char * sql; - char * file = malloc(PATH_MAX); - char **result; - int ret, rows; + char *file = malloc(PATH_MAX); + char *id = NULL; sprintf(file, "%s", path); strip_ext(file); @@ -148,25 +146,18 @@ check_for_captions(const char * path, sqlite_int64 detailID) /* If we weren't given a detail ID, look for one. */ if( !detailID ) { - sql = sqlite3_mprintf("SELECT ID from DETAILS where PATH glob '%q.*'" - " and MIME glob 'video/*' limit 1", file); - ret = sql_get_table(db, sql, &result, &rows, NULL); - if( ret == SQLITE_OK ) + id = sql_get_text_field(db, "SELECT ID from DETAILS where PATH glob '%q.*'" + " and MIME glob 'video/*' limit 1", file); + if( id ) { - if( rows ) - { - detailID = strtoll(result[1], NULL, 10); - //DEBUG DPRINTF(E_DEBUG, L_METADATA, "New file %s looks like a caption file.\n", path); - } - /*else - { - DPRINTF(E_DEBUG, L_METADATA, "No file found for caption %s.\n", path); - }*/ - sqlite3_free_table(result); + //DEBUG DPRINTF(E_DEBUG, L_METADATA, "New file %s looks like a caption file.\n", path); + detailID = strtoll(id, NULL, 10); } - sqlite3_free(sql); - if( !detailID ) + else + { + //DPRINTF(E_DEBUG, L_METADATA, "No file found for caption %s.\n", path); goto no_source_video; + } } strcat(file, ".srt"); @@ -178,6 +169,8 @@ check_for_captions(const char * path, sqlite_int64 detailID) " (%lld, %Q)", detailID, file); } no_source_video: + if( id ) + sqlite3_free(id); free(file); } @@ -506,7 +499,7 @@ GetImageMetadata(const char * path, char * name) char b[1024]; struct stat file; sqlite_int64 ret; - image * imsrc; + image_s * imsrc; metadata_t m; uint32_t free_flags = 0xFFFFFFFF; memset(&m, '\0', sizeof(metadata_t)); @@ -646,11 +639,7 @@ GetVideoMetadata(const char * path, char * name) int audio_stream = -1, video_stream = -1; enum audio_profiles audio_profile = PROFILE_AUDIO_UNKNOWN; tsinfo_t *ts; - ts_timestamp_t ts_timestamp = NONE; char fourcc[4]; - int off; - int duration, hours, min, sec, ms; - aac_object_type_t aac_type = AAC_INVALID; sqlite_int64 album_art = 0; char nfo[PATH_MAX], *ext; struct song_metadata video; @@ -719,6 +708,7 @@ GetVideoMetadata(const char * path, char * name) if( ac ) { + aac_object_type_t aac_type = AAC_INVALID; switch( ac->codec_id ) { case CODEC_ID_MP3: @@ -807,6 +797,9 @@ GetVideoMetadata(const char * path, char * name) } 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)); asprintf(&m.resolution, "%dx%d", vc->width, vc->height); if( ctx->bit_rate > 8 ) diff --git a/minissdp.c b/minissdp.c index d9d5e29..a3d7d90 100644 --- a/minissdp.c +++ b/minissdp.c @@ -223,6 +223,16 @@ static const char * const known_service_types[] = 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 * to a SSDP "M-SEARCH" */ static void @@ -282,7 +292,7 @@ SendSSDPNotifies(int s, const char * host, unsigned short port, for( dup=0; dup<2; dup++ ) { if( dup ) - usleep(200000); + _usleep(200000); i=0; while(known_service_types[i]) { @@ -477,10 +487,9 @@ ProcessSSDPRequest(int s, unsigned short port) char bufr[1500]; socklen_t len_r; struct sockaddr_in sendername; - int i, l; - int lan_addr_index = 0; + int i; 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); n = recvfrom(s, bufr, sizeof(bufr)-1, 0, @@ -494,6 +503,7 @@ ProcessSSDPRequest(int s, unsigned short port) 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); for(i=0; i < n; i++) { @@ -551,6 +561,7 @@ ProcessSSDPRequest(int s, unsigned short port) } 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); for(i=0; i < n; i++) { @@ -608,6 +619,8 @@ ProcessSSDPRequest(int s, unsigned short port) } else if( st && (st_len > 0) ) { + int l; + int lan_addr_index = 0; /* find in which sub network the client is */ for(i = 0; i>20); + _usleep(random()>>20); SendSSDPAnnounce2(s, sendername, i, lan_addr[lan_addr_index].str, port); diff --git a/scanner.c b/scanner.c index a2880d0..84f0b4c 100644 --- a/scanner.c +++ b/scanner.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -45,7 +46,7 @@ int valid_cache = 0; struct virtual_item { - int objectID; + sqlite3_int64 objectID; char parentID[64]; char name[256]; }; @@ -53,63 +54,55 @@ struct virtual_item sqlite_int64 get_next_available_id(const char * table, const char * parentID) { - char * sql; - char **result; - int ret, rows; + char *ret, *base; sqlite_int64 objectID = 0; - asprintf(&sql, "SELECT OBJECT_ID from %s where ID = " - "(SELECT max(ID) from %s where PARENT_ID = '%s')", table, table, parentID); - ret = sql_get_table(db, sql, &result, &rows, NULL); - if( rows ) + 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); + 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; } -long long int +int 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 **result2; - char *sql; - int cols, rows, ret; - int parentID = 0, objectID = 0; + char *result; + char *base; + int ret = 0; sqlite_int64 detailID = 0; - sql = sqlite3_mprintf("SELECT OBJECT_ID from OBJECTS" - " where PARENT_ID = '%s'" - " and NAME = '%q'" - " and CLASS = 'container.%s' limit 1", - rootParent, item, class); - ret = sql_get_table(db, sql, &result, &rows, &cols); - sqlite3_free(sql); - if( cols ) + result = sql_get_text_field(db, "SELECT OBJECT_ID from OBJECTS" + " where PARENT_ID = '%s'" + " and NAME = '%q'" + " and CLASS = 'container.%s' limit 1", + rootParent, item, class); + if( result ) { - parentID = strtol(rindex(result[1], '$')+1, NULL, 16); - objectID = get_next_available_id("OBJECTS", result[1]); + base = strrchr(result, '$'); + if( base ) + *parentID = strtoll(base+1, NULL, 16); + else + *parentID = 0; + *objectID = get_next_available_id("OBJECTS", result); } else { - parentID = get_next_available_id("OBJECTS", rootParent); + *objectID = 0; + *parentID = get_next_available_id("OBJECTS", rootParent); if( refID ) { - sql = sqlite3_mprintf("SELECT DETAIL_ID from OBJECTS where OBJECT_ID = %Q", refID); - ret = sql_get_table(db, sql, &result2, &rows, NULL); - if( ret == SQLITE_OK ) - { - if( rows ) - { - detailID = strtoll(result2[1], NULL, 10); - } - sqlite3_free_table(result2); - } - sqlite3_free(sql); + result = sql_get_text_field(db, "SELECT DETAIL_ID from OBJECTS where OBJECT_ID = %Q", refID); + if( result ) + detailID = strtoll(result, NULL, 10); } if( !detailID ) { @@ -118,22 +111,22 @@ insert_container(const char * item, const char * rootParent, const char * refID, ret = sql_exec(db, "INSERT into OBJECTS" " (OBJECT_ID, PARENT_ID, REF_ID, DETAIL_ID, CLASS, NAME) " "VALUES" - " ('%s$%X', '%s', %Q, %lld, 'container.%s', '%q')", - rootParent, parentID, rootParent, refID, detailID, class, item); + " ('%s$%"PRIX64"', '%s', %Q, %"PRId64", 'container.%s', '%q')", + rootParent, *parentID, rootParent, refID, detailID, class, item); } - sqlite3_free_table(result); + sqlite3_free(result); - return (long long)parentID<<32|objectID; + return ret; } -void -insert_containers(const char * name, const char *path, const char * refID, const char * class, long unsigned int detailID) +static void +insert_containers(const char * name, const char *path, const char * refID, const char * class, sqlite3_int64 detailID) { char *sql; char **result; int ret; int cols, row; - sqlite_int64 container; + sqlite_int64 objectID, parentID; 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 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); free(sql); if( ret == SQLITE_OK ) @@ -169,16 +162,16 @@ insert_containers(const char * name, const char *path, const char * refID, const } else { - container = insert_container(date_taken, IMAGE_DATE_ID, NULL, "album.photoAlbum", NULL, NULL, NULL); - sprintf(last_date.parentID, IMAGE_DATE_ID"$%llX", container>>32); - last_date.objectID = (int)container; + insert_container(date_taken, IMAGE_DATE_ID, NULL, "album.photoAlbum", NULL, NULL, NULL, &objectID, &parentID); + sprintf(last_date.parentID, IMAGE_DATE_ID"$%"PRIX64, parentID); + last_date.objectID = objectID; 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); } sql_exec(db, "INSERT into OBJECTS" " (OBJECT_ID, PARENT_ID, REF_ID, CLASS, DETAIL_ID, NAME) " "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); 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 ) { - container = insert_container(camera, IMAGE_CAMERA_ID, NULL, "storageFolder", NULL, NULL, NULL); - sprintf(last_cam.parentID, IMAGE_CAMERA_ID"$%llX", container>>32); + insert_container(camera, IMAGE_CAMERA_ID, NULL, "storageFolder", NULL, NULL, NULL, &objectID, &parentID); + sprintf(last_cam.parentID, IMAGE_CAMERA_ID"$%"PRIX64, parentID); strncpy(last_cam.name, camera, 255); last_camdate.name[0] = '\0'; } @@ -204,16 +197,16 @@ insert_containers(const char * name, const char *path, const char * refID, const } else { - container = insert_container(date_taken, last_cam.parentID, NULL, "album.photoAlbum", NULL, NULL, NULL); - sprintf(last_camdate.parentID, "%s$%llX", last_cam.parentID, container>>32); - last_camdate.objectID = (int)container; + insert_container(date_taken, last_cam.parentID, NULL, "album.photoAlbum", NULL, NULL, NULL, &objectID, &parentID); + sprintf(last_camdate.parentID, "%s$%"PRIX64, last_cam.parentID, parentID); + last_camdate.objectID = objectID; 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); } sql_exec(db, "INSERT into OBJECTS" " (OBJECT_ID, PARENT_ID, REF_ID, CLASS, DETAIL_ID, NAME) " "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); /* All Images */ 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" " (OBJECT_ID, PARENT_ID, REF_ID, CLASS, DETAIL_ID, NAME) " "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); } 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); free(sql); if( ret != SQLITE_OK ) @@ -259,29 +252,29 @@ insert_containers(const char * name, const char *path, const char * refID, const else { strcpy(last_album.name, album); - container = insert_container(album, MUSIC_ALBUM_ID, NULL, "album.musicAlbum", artist, genre, album_art); - sprintf(last_album.parentID, MUSIC_ALBUM_ID"$%llX", container>>32); - last_album.objectID = (int)container; + insert_container(album, MUSIC_ALBUM_ID, NULL, "album.musicAlbum", artist, genre, album_art, &objectID, &parentID); + sprintf(last_album.parentID, MUSIC_ALBUM_ID"$%llX", parentID); + 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); } sql_exec(db, "INSERT into OBJECTS" " (OBJECT_ID, PARENT_ID, REF_ID, CLASS, DETAIL_ID, NAME) " "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); } if( artist ) { if( !valid_cache || strcmp(artist, last_artist.name) != 0 ) { - container = insert_container(artist, MUSIC_ARTIST_ID, NULL, "person.musicArtist", NULL, genre, NULL); - sprintf(last_artist.parentID, MUSIC_ARTIST_ID"$%llX", container>>32); + insert_container(artist, MUSIC_ARTIST_ID, NULL, "person.musicArtist", NULL, genre, NULL, &objectID, &parentID); + sprintf(last_artist.parentID, MUSIC_ARTIST_ID"$%"PRIX64, parentID); strcpy(last_artist.name, artist); last_artistAlbum.name[0] = '\0'; /* Add this file to the "- All Albums -" container as well */ - container = insert_container(_("- All Albums -"), last_artist.parentID, NULL, "album", artist, genre, NULL); - sprintf(last_artistAlbumAll.parentID, "%s$%llX", last_artist.parentID, container>>32); - last_artistAlbumAll.objectID = (int)container; + insert_container(_("- All Albums -"), last_artist.parentID, NULL, "album", artist, genre, NULL, &objectID, &parentID); + sprintf(last_artistAlbumAll.parentID, "%s$%"PRIX64, last_artist.parentID, parentID); + last_artistAlbumAll.objectID = objectID; } else { @@ -294,35 +287,36 @@ insert_containers(const char * name, const char *path, const char * refID, const } else { - container = insert_container(album?album:_("Unknown Album"), last_artist.parentID, album?last_album.parentID:NULL, "album.musicAlbum", artist, genre, album_art); - sprintf(last_artistAlbum.parentID, "%s$%llX", last_artist.parentID, container>>32); - last_artistAlbum.objectID = (int)container; + insert_container(album?album:_("Unknown Album"), last_artist.parentID, album?last_album.parentID:NULL, + "album.musicAlbum", artist, genre, album_art, &objectID, &parentID); + sprintf(last_artistAlbum.parentID, "%s$%"PRIX64, last_artist.parentID, parentID); + last_artistAlbum.objectID = objectID; 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); } sql_exec(db, "INSERT into OBJECTS" " (OBJECT_ID, PARENT_ID, REF_ID, CLASS, DETAIL_ID, NAME) " "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); sql_exec(db, "INSERT into OBJECTS" " (OBJECT_ID, PARENT_ID, REF_ID, CLASS, DETAIL_ID, NAME) " "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); } if( genre ) { if( !valid_cache || strcmp(genre, last_genre.name) != 0 ) { - container = insert_container(genre, MUSIC_GENRE_ID, NULL, "genre.musicGenre", NULL, NULL, NULL); - sprintf(last_genre.parentID, MUSIC_GENRE_ID"$%llX", container>>32); + insert_container(genre, MUSIC_GENRE_ID, NULL, "genre.musicGenre", NULL, NULL, NULL, &objectID, &parentID); + sprintf(last_genre.parentID, MUSIC_GENRE_ID"$%"PRIX64, parentID); strcpy(last_genre.name, genre); last_genreArtist.name[0] = '\0'; /* Add this file to the "- All Artists -" container as well */ - container = insert_container(_("- All Artists -"), last_genre.parentID, NULL, "person", NULL, genre, NULL); - sprintf(last_genreArtistAll.parentID, "%s$%llX", last_genre.parentID, container>>32); - last_genreArtistAll.objectID = (int)container; + insert_container(_("- All Artists -"), last_genre.parentID, NULL, "person", NULL, genre, NULL, &objectID, &parentID); + sprintf(last_genreArtistAll.parentID, "%s$%"PRIX64, last_genre.parentID, parentID); + last_genreArtistAll.objectID = objectID; } else { @@ -334,21 +328,22 @@ insert_containers(const char * name, const char *path, const char * refID, const } else { - container = insert_container(artist?artist:_("Unknown Artist"), last_genre.parentID, artist?last_artist.parentID:NULL, "person.musicArtist", NULL, genre, NULL); - sprintf(last_genreArtist.parentID, "%s$%llX", last_genre.parentID, container>>32); - last_genreArtist.objectID = (int)container; + insert_container(artist?artist:_("Unknown Artist"), last_genre.parentID, artist?last_artist.parentID:NULL, + "person.musicArtist", NULL, genre, NULL, &objectID, &parentID); + sprintf(last_genreArtist.parentID, "%s$%"PRIX64, last_genre.parentID, parentID); + last_genreArtist.objectID = objectID; 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); } sql_exec(db, "INSERT into OBJECTS" " (OBJECT_ID, PARENT_ID, REF_ID, CLASS, DETAIL_ID, NAME) " "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); sql_exec(db, "INSERT into OBJECTS" " (OBJECT_ID, PARENT_ID, REF_ID, CLASS, DETAIL_ID, NAME) " "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); } /* All Music */ @@ -359,7 +354,7 @@ insert_containers(const char * name, const char *path, const char * refID, const sql_exec(db, "INSERT into OBJECTS" " (OBJECT_ID, PARENT_ID, REF_ID, CLASS, DETAIL_ID, NAME) " "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); } 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" " (OBJECT_ID, PARENT_ID, REF_ID, CLASS, DETAIL_ID, NAME) " "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); return; } @@ -389,15 +384,14 @@ insert_containers(const char * name, const char *path, const char * refID, const int insert_directory(const char * name, const char * path, const char * base, const char * parentID, int objectID) { - char * sql; - int rows, found = 0; + int found = 0; sqlite_int64 detailID = 0; char * refID = NULL; char class[] = "container.storageFolder"; char * id_buf = NULL; char * parent_buf = NULL; - char **result; - char *dir = NULL; + char *dir_buf, *dir; + char *result, *p; static char last_found[256] = "-1"; if( strcmp(base, BROWSEDIR_ID) != 0 ) @@ -405,8 +399,8 @@ insert_directory(const char * name, const char * path, const char * base, const if( refID ) { - dir = strdup(path); - dir = dirname(dir); + dir_buf = strdup(path); + dir = dirname(dir_buf); asprintf(&id_buf, "%s%s$%X", base, parentID, objectID); asprintf(&parent_buf, "%s%s", base, parentID); while( !found ) @@ -419,30 +413,29 @@ insert_directory(const char * name, const char * path, const char * base, const break; } /* 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); - if( (sql_get_table(db, sql, &result, &rows, NULL) == SQLITE_OK) && rows ) + result = sql_get_text_field(db, "SELECT DETAIL_ID from OBJECTS where OBJECT_ID = '%s'", refID); + 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" " (OBJECT_ID, PARENT_ID, REF_ID, DETAIL_ID, CLASS, NAME) " "VALUES" - " ('%s', '%s', %Q, '%lld', '%s', '%q')", - id_buf, parent_buf, refID, detailID, class, rindex(dir, '/')+1); - if( rindex(id_buf, '$') ) - *rindex(id_buf, '$') = '\0'; - if( rindex(parent_buf, '$') ) - *rindex(parent_buf, '$') = '\0'; - if( rindex(refID, '$') ) - *rindex(refID, '$') = '\0'; + " ('%s', '%s', %Q, %"PRId64", '%s', '%q')", + id_buf, parent_buf, refID, detailID, class, strrchr(dir, '/')+1); + if( (p = strrchr(id_buf, '$')) ) + *p = '\0'; + if( (p = strrchr(parent_buf, '$')) ) + *p = '\0'; + if( (p = strrchr(refID, '$')) ) + *p = '\0'; dir = dirname(dir); } free(refID); free(parent_buf); free(id_buf); - free(dir); + free(dir_buf); return 1; } @@ -450,7 +443,7 @@ insert_directory(const char * name, const char * path, const char * base, const sql_exec(db, "INSERT into OBJECTS" " (OBJECT_ID, PARENT_ID, REF_ID, DETAIL_ID, CLASS, NAME) " "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); if( refID ) free(refID); @@ -463,7 +456,7 @@ insert_file(char * name, const char * path, const char * parentID, int object) { char class[32]; char objectID[64]; - unsigned long int detailID = 0; + sqlite3_int64 detailID = 0; char base[8]; char * typedir_parentID; 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" " (OBJECT_ID, PARENT_ID, CLASS, DETAIL_ID, NAME) " "VALUES" - " ('%s', '%s%s', '%s', %lu, '%q')", + " ('%s', '%s%s', '%s', %"PRId64", '%q')", objectID, BROWSEDIR_ID, parentID, class, detailID, name); if( *parentID ) { typedir_objectID = 0; typedir_parentID = strdup(parentID); - baseid = rindex(typedir_parentID, '$'); + baseid = strrchr(typedir_parentID, '$'); if( baseid ) { - sscanf(baseid+1, "%X", &typedir_objectID); + typedir_objectID = strtol(baseid+1, NULL, 16); *baseid = '\0'; } 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" " (OBJECT_ID, PARENT_ID, REF_ID, CLASS, DETAIL_ID, NAME) " "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); insert_containers(name, path, objectID, class, detailID); diff --git a/tagutils/tagutils-asf.c b/tagutils/tagutils-asf.c index fcb62f0..66cffed 100644 --- a/tagutils/tagutils-asf.c +++ b/tagutils/tagutils-asf.c @@ -310,9 +310,7 @@ _asf_load_picture(FILE *fp, int size, void *bm, int *bm_size) { int i; char buf[256]; - char pic_type; - long pic_size; - +#if 0 // // Picture type $xx // Data length $xx $xx $xx $xx @@ -320,9 +318,15 @@ _asf_load_picture(FILE *fp, int size, void *bm, int *bm_size) // Description $00 // Picture data + char pic_type; + long pic_size; + pic_type = fget_byte(fp); size -= 1; pic_size = fget_le32(fp); size -= 4; - +#else + fseek(fp, 5, SEEK_CUR); + size -= 5; +#endif for(i = 0; i < sizeof(buf) - 1; i++) { 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 tmp; unsigned long NumObjects; - unsigned short Reserved; unsigned short TitleLength; unsigned short AuthorLength; unsigned short CopyrightLength; @@ -400,7 +403,6 @@ _get_asffileinfo(char *file, struct song_metadata *psong) unsigned short ValueLength; off_t pos; char buf[2048]; - int mask; asf_file_properties_t FileProperties; psong->vbr_scale = -1; @@ -426,10 +428,9 @@ _get_asffileinfo(char *file, struct song_metadata *psong) return -1; } NumObjects = fget_le32(fp); - Reserved = fget_le16(fp); + fseek(fp, 2, SEEK_CUR); // Reserved le16 pos = ftell(fp); - mask = 0; while(NumObjects > 0) { if(sizeof(tmp) != fread(&tmp, 1, sizeof(tmp), fp)) diff --git a/tagutils/tagutils-flc.c b/tagutils/tagutils-flc.c index a2a9ec8..b8f41d4 100644 --- a/tagutils/tagutils-flc.c +++ b/tagutils/tagutils-flc.c @@ -25,7 +25,6 @@ _get_flctags(char *filename, struct song_metadata *psong) { FLAC__Metadata_SimpleIterator *iterator = 0; FLAC__StreamMetadata *block; - int block_number; unsigned int sec, ms; int i; int err = 0; @@ -36,7 +35,6 @@ _get_flctags(char *filename, struct song_metadata *psong) return -1; } - block_number = 0; if(!FLAC__metadata_simple_iterator_init(iterator, filename, true, true)) { DPRINTF(E_ERROR, L_SCANNER, "Cannot extract tag from %s\n", filename); diff --git a/tagutils/tagutils-ogg.c b/tagutils/tagutils-ogg.c index 9efd5cc..ed9de40 100644 --- a/tagutils/tagutils-ogg.c +++ b/tagutils/tagutils-ogg.c @@ -196,7 +196,6 @@ static void _ogg_vorbis_end(ogg_stream_processor *stream, struct song_metadata *psong) { ogg_misc_vorbis_info *inf = stream->data; - long minutes, seconds; double bitrate, time; 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; } - minutes = (long)time / 60; - seconds = (long)time - minutes * 60; - vorbis_comment_clear(&inf->vc); 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_uint32_t serial = ogg_page_serialno(page); - int i, found = 0; + int i; int invalid = 0; int constraint = 0; 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) { - found = 1; stream = &(set->streams[i]); set->in_headers = 0; diff --git a/tagutils/textutils.c b/tagutils/textutils.c index d80da3d..6cffa17 100644 --- a/tagutils/textutils.c +++ b/tagutils/textutils.c @@ -289,6 +289,7 @@ fetch_string_txt(char *fname, char *lang, int n, ...) if (!*strs[i]) *strs[i] = defstr[i]; } + fclose(fp); _exit: free(keys); diff --git a/tivo_utils.c b/tivo_utils.c index 8adbe57..2ae6247 100644 --- a/tivo_utils.c +++ b/tivo_utils.c @@ -74,6 +74,8 @@ decodeString(char * string, int inplace) } if( inplace ) { + if( ns ) + free(ns); return string; } else diff --git a/upnpdescgen.c b/upnpdescgen.c index bc577a9..c52ad8c 100644 --- a/upnpdescgen.c +++ b/upnpdescgen.c @@ -527,6 +527,7 @@ static const struct serviceDesc scpdX_MS_MediaReceiverRegistrar = static char * strcat_str(char * str, int * len, int * tmplen, const char * s2) { + char *p; int s2len; s2len = (int)strlen(s2); if(*tmplen <= (*len + s2len)) @@ -535,7 +536,17 @@ strcat_str(char * str, int * len, int * tmplen, const char * s2) *tmplen += 256; else *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); */ memcpy(str + *len, s2, s2len + 1); @@ -549,10 +560,18 @@ strcat_str(char * str, int * len, int * tmplen, const char * s2) static char * strcat_char(char * str, int * len, int * tmplen, char c) { + char *p; if(*tmplen <= (*len + 1)) { *tmplen += 256; - str = (char *)realloc(str, *tmplen); + p = (char *)realloc(str, *tmplen); + if (!p) + { + *tmplen -= 256; + return str; + } + else + str = p; } str[*len] = c; (*len)++; diff --git a/upnphttp.c b/upnphttp.c index d33b2fe..8495340 100644 --- a/upnphttp.c +++ b/upnphttp.c @@ -1469,21 +1469,24 @@ SendResp_resizedimg(struct upnphttp * h, char * object) char date[30]; char dlna_pn[4]; 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; unsigned char * data = NULL; char *path, *file_path; - char *resolution, *tn; + char *resolution; char *key, *val; char *saveptr=NULL, *item=NULL; + /* Not implemented yet * char *pixelshape=NULL; + int rotation; */ sqlite_int64 id; int rows=0, chunked=0, ret; #ifdef __sparc__ + char *tn; ExifData *ed; ExifLoader *l; #endif - image *imsrc = NULL, *imdst = NULL; + image_s *imsrc = NULL, *imdst = NULL; int scale = 1; id = strtoll(object, NULL, 10); @@ -1510,7 +1513,6 @@ SendResp_resizedimg(struct upnphttp * h, char * object) #endif file_path = result[3]; resolution = result[4]; - tn = result[5]; srcw = strtol(resolution, &saveptr, 10); srch = strtol(saveptr+1, NULL, 10); @@ -1535,6 +1537,7 @@ SendResp_resizedimg(struct upnphttp * h, char * object) { height = atoi(val); } + /* Not implemented yet * else if( strcasecmp(key, "rotation") == 0 ) { rotation = atoi(val); @@ -1542,7 +1545,7 @@ SendResp_resizedimg(struct upnphttp * h, char * object) else if( strcasecmp(key, "pixelshape") == 0 ) { pixelshape = val; - } + } */ item = strtok_r(NULL, "&,", &saveptr); } 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 */ #ifdef __sparc__ + tn = result[5]; if( dstw <= 160 && dsth <= 120 && atoi(tn) ) { l = exif_loader_new(); diff --git a/upnpsoap.c b/upnpsoap.c index 7fb69d0..1014374 100644 --- a/upnpsoap.c +++ b/upnpsoap.c @@ -652,7 +652,7 @@ callback(void *args, int argc, char **argv, char **azColName) char dlna_buf[96]; char ext[5]; 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. */ 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; if( passed_args->filter & FILTER_CHILDCOUNT ) { + int children; ret = sql_get_int_field(db, "SELECT count(*) from OBJECTS where PARENT_ID = '%s';", id); children = (ret > 0) ? ret : 0; ret = sprintf(str_buf, "childCount=\"%d\"", children); @@ -1545,14 +1546,14 @@ void ExecuteSoapAction(struct upnphttp * h, const char * action, int n) { char * p; - char * p2; - int i, len, methodlen; - i = 0; p = strchr(action, '#'); - if(p) { + int i = 0; + int len; + int methodlen; + char * p2; p++; p2 = strchr(p, '"'); if(p2) diff --git a/utils.c b/utils.c index acd3796..f0e8788 100644 --- a/utils.c +++ b/utils.c @@ -100,7 +100,12 @@ modifyString(char * string, const char * before, const char * after, short like) chgcnt++; 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; @@ -136,7 +141,7 @@ modifyString(char * string, const char * before, const char * after, short like) } char * -escape_tag(const char *tag, uint8_t force_alloc) +escape_tag(const char *tag, int force_alloc) { char *esc_tag = NULL; diff --git a/utils.h b/utils.h index 8bb79e7..abc4260 100644 --- a/utils.h +++ b/utils.h @@ -37,7 +37,7 @@ char * modifyString(char * string, const char * before, const char * after, short like); char * -escape_tag(const char *tag, uint8_t force_alloc); +escape_tag(const char *tag, int force_alloc); void strip_ext(char * name);