From: Rory Y. <ror...@gm...> - 2014-02-16 06:37:46
|
All printf(...) and fprintf(stderr,...) calls are replaced by itdb_log_debug(...) and itdb_log_error(...); the behaviour of the latter is controlled by an environment variable ITDB_LOGLEVEL. Not all calls were replaced; those inside preprocessor conditionals (e.g. "#if ITUNESDB_DEBUG") were not replaced, and no commented-out code was changed. --- src/Makefile.am | 2 + src/itdb_artwork.c | 2 +- src/itdb_hash72.c | 5 +- src/itdb_hashAB.c | 3 +- src/itdb_iphone.c | 62 ++++++------ src/itdb_itunesdb.c | 3 +- src/itdb_logger.c | 59 ++++++++++++ src/itdb_logger.h | 96 +++++++++++++++++++ src/itdb_sqlite.c | 270 ++++++++++++++++++++++++++-------------------------- 9 files changed, 331 insertions(+), 171 deletions(-) create mode 100644 src/itdb_logger.c create mode 100644 src/itdb_logger.h diff --git a/src/Makefile.am b/src/Makefile.am index 26fd515..56b815d 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -14,6 +14,7 @@ libgpod_la_SOURCES = \ itdb_hashAB.c \ itdb_iphone.c \ itdb_itunesdb.c \ + itdb_logger.c \ itdb_photoalbum.c \ itdb_playlist.c \ itdb_plist.c \ @@ -42,6 +43,7 @@ noinst_HEADERS = \ db-parse-context.h \ itdb_device.h \ itdb_endianness.h \ + itdb_logger.h \ itdb_plist.h \ itdb_private.h \ itdb_sqlite_queries.h \ diff --git a/src/itdb_artwork.c b/src/itdb_artwork.c index c595d70..6590c1d 100644 --- a/src/itdb_artwork.c +++ b/src/itdb_artwork.c @@ -489,7 +489,7 @@ unpack_experimental (guint16 *pixels, guint bytes_len, guint byte_order, guint32 cur_pixel; /* FIXME: endianness */ cur_pixel = get_gint32 (rpixels[i], byte_order); -printf ("%8x\n", cur_pixel); +itdb_log_debug ("%8x\n", cur_pixel); /* Unpack pixels */ result[3*i] = (cur_pixel & RED_MASK_888) >> RED_SHIFT_888; result[3*i+1] = (cur_pixel & GREEN_MASK_888) >> GREEN_SHIFT_888; diff --git a/src/itdb_hash72.c b/src/itdb_hash72.c index ce61757..c893e00 100644 --- a/src/itdb_hash72.c +++ b/src/itdb_hash72.c @@ -35,6 +35,7 @@ #include "itdb_device.h" #include "db-itunes-parser.h" #include "itdb_private.h" +#include "itdb_logger.h" static const uint8_t AES_KEY[16] = { 0x61, 0x8c, 0xa1, 0x0d, 0xc7, 0xf5, 0x7f, 0xd3, 0xb4, 0x72, 0x3e, 0x08, 0x15, 0x74, 0x63, 0xd7 }; @@ -77,7 +78,7 @@ static int hash_extract(const uint8_t signature[46], uint8_t plaintext[32] = { 0 }, output[32] = { 0 }; if (signature[0] != 0x01 || signature[1] != 0x00) { - fprintf(stderr, "Invalid signature prefix!\n"); + itdb_log_error("Invalid signature prefix!\n"); return -1; } @@ -90,7 +91,7 @@ static int hash_extract(const uint8_t signature[46], aes_decrypt(plaintext, (uint8_t *)&signature[14], output, 16); if (memcmp(&plaintext[16], &output[16], 16)) { - fprintf(stderr, "uh oh\n"); + itdb_log_error("uh oh\n"); return -1; } diff --git a/src/itdb_hashAB.c b/src/itdb_hashAB.c index 7b9f833..b02178d 100644 --- a/src/itdb_hashAB.c +++ b/src/itdb_hashAB.c @@ -36,6 +36,7 @@ #include "itdb_device.h" #include "db-itunes-parser.h" #include "itdb_private.h" +#include "itdb_logger.h" typedef void (*calcHashAB_t)(unsigned char target[57], const unsigned char sha1[20], const unsigned char uuid[20], const unsigned char rnd_bytes[23]); static calcHashAB_t calc_hashAB = NULL; @@ -62,7 +63,7 @@ static gboolean load_libhashab() } g_module_make_resident(handle); - printf("***** hashAB support successfully loaded *****\n"); + itdb_log_debug("***** hashAB support successfully loaded *****\n"); return TRUE; } diff --git a/src/itdb_iphone.c b/src/itdb_iphone.c index 694a701..6187af5 100644 --- a/src/itdb_iphone.c +++ b/src/itdb_iphone.c @@ -50,7 +50,7 @@ static int itdb_iphone_post_notification(idevice_t device, lockdownd_start_service(client, "com.apple.mobile.notification_proxy", &service); if (!service || !service->port) { - fprintf(stderr, "notification_proxy could not be started!\n"); + itdb_log_error("notification_proxy could not be started!\n"); return -1; } @@ -60,7 +60,7 @@ static int itdb_iphone_post_notification(idevice_t device, lockdownd_start_service(client, "com.apple.mobile.notification_proxy", &nport); if (!nport) { - fprintf(stderr, "notification_proxy could not be started!\n"); + itdb_log_error("notification_proxy could not be started!\n"); return -1; } @@ -68,12 +68,12 @@ static int itdb_iphone_post_notification(idevice_t device, #endif if(!np) { - fprintf(stderr, "connection to notification_proxy failed!\n"); + itdb_log_error("connection to notification_proxy failed!\n"); return -1; } if(np_post_notification(np, notification)) { - fprintf(stderr, "failed to post notification!\n"); + itdb_log_error("failed to post notification!\n"); np_client_free(np); return -1; } @@ -99,24 +99,24 @@ int itdb_iphone_start_sync(Itdb_Device *device, void **prepdata) uuid = itdb_device_get_uuid (device); if (!uuid) { - fprintf(stderr, "Couldn't find get device UUID itdbprep processing won't work!"); + itdb_log_error("Couldn't find get device UUID itdbprep processing won't work!"); return -ENODEV; } - printf("libitdbprep: %s called with uuid=%s\n", __func__, uuid); + itdb_log_debug("libitdbprep: %s called with uuid=%s\n", __func__, uuid); *prepdata = NULL; pdata_loc = g_new0 (struct itdbprep_int, 1); res = idevice_new(&pdata_loc->device, uuid); if (IDEVICE_E_SUCCESS != res) { - fprintf(stderr, "No iPhone found, is it plugged in?\n"); + itdb_log_error("No iPhone found, is it plugged in?\n"); res = -ENODEV; goto leave_with_err; } if (LOCKDOWN_E_SUCCESS != lockdownd_client_new_with_handshake(pdata_loc->device, &client, "libgpod")) { - fprintf(stderr, "Error: Could not establish lockdownd connection!\n"); + itdb_log_error("Error: Could not establish lockdownd connection!\n"); res = -1; goto leave_with_err; } @@ -124,7 +124,7 @@ int itdb_iphone_start_sync(Itdb_Device *device, void **prepdata) #ifdef HAVE_LIBIMOBILEDEVICE_1_1_5 lockdownd_start_service(client, "com.apple.afc", &service); if (!service || !service->port) { - fprintf(stderr, "Error: Could not start AFC service!\n"); + itdb_log_error("Error: Could not start AFC service!\n"); res = -1; goto leave_with_err; } @@ -132,44 +132,44 @@ int itdb_iphone_start_sync(Itdb_Device *device, void **prepdata) #else lockdownd_start_service(client, "com.apple.afc", &afcport); if (!afcport) { - fprintf(stderr, "Error: Could not start AFC service!\n"); + itdb_log_error("Error: Could not start AFC service!\n"); res = -1; goto leave_with_err; } afc_client_new(pdata_loc->device, afcport, &pdata_loc->afc); #endif if (!pdata_loc->afc) { - fprintf(stderr, "Error: Could not start AFC client!\n"); + itdb_log_error("Error: Could not start AFC client!\n"); res = -1; goto leave_with_err; } if (itdb_iphone_post_notification(pdata_loc->device, client, NP_SYNC_WILL_START)) { - fprintf(stderr, "could not post syncWillStart notification!\n"); + itdb_log_error("could not post syncWillStart notification!\n"); res = -1; goto leave_with_err; } - printf("%s: posted syncWillStart\n", __func__); + itdb_log_debug("%s: posted syncWillStart\n", __func__); sync_starting = 1; /* OPEN AND LOCK /com.apple.itunes.lock_sync */ afc_file_open(pdata_loc->afc, "/com.apple.itunes.lock_sync", AFC_FOPEN_RW, &pdata_loc->lockfile); if (!pdata_loc->lockfile) { - fprintf(stderr, "could not open lockfile\n"); + itdb_log_error("could not open lockfile\n"); res = -1; goto leave_with_err; } if (itdb_iphone_post_notification(pdata_loc->device, client, "com.apple.itunes-mobdev.syncLockRequest")) { - fprintf(stderr, "could not post syncLockRequest\n"); + itdb_log_error("could not post syncLockRequest\n"); res = -1; goto leave_with_err; } - printf("%s: posted syncLockRequest\n", __func__); + itdb_log_debug("%s: posted syncLockRequest\n", __func__); for (i=0; i<LOCK_ATTEMPTS; i++) { - fprintf(stderr, "Locking for sync, attempt %d...\n", i); + itdb_log_error("Locking for sync, attempt %d...\n", i); res = afc_file_lock(pdata_loc->afc, pdata_loc->lockfile, AFC_LOCK_EX); if (res == AFC_E_SUCCESS) { break; @@ -177,23 +177,23 @@ int itdb_iphone_start_sync(Itdb_Device *device, void **prepdata) usleep(LOCK_WAIT); continue; } else { - fprintf(stderr, "ERROR: could not lock file! error code: %d\n", res); + itdb_log_error("ERROR: could not lock file! error code: %d\n", res); res = -1; goto leave_with_err; } } if (i == LOCK_ATTEMPTS) { - fprintf(stderr, "ERROR: timeout while locking for sync\n"); + itdb_log_error("ERROR: timeout while locking for sync\n"); res = -1; goto leave_with_err; } if (itdb_iphone_post_notification(pdata_loc->device, client, NP_SYNC_DID_START)) { - fprintf(stderr, "could not post syncDidStart\n"); + itdb_log_error("could not post syncDidStart\n"); res = -1; goto leave_with_err; } - printf("%s: posted syncDidStart\n", __func__); + itdb_log_debug("%s: posted syncDidStart\n", __func__); lockdownd_client_free(client); client = NULL; @@ -205,7 +205,7 @@ int itdb_iphone_start_sync(Itdb_Device *device, void **prepdata) leave_with_err: if (client && sync_starting) { itdb_iphone_post_notification(pdata_loc->device, client, "com.apple.itunes-mobdev.syncFailedToStart"); - printf("%s: posted syncFailedToStart\n", __func__); + itdb_log_debug("%s: posted syncFailedToStart\n", __func__); } if (pdata_loc) { @@ -241,44 +241,44 @@ int itdb_iphone_stop_sync(void *sync_ctx) lockdownd_client_t client = NULL; itdbprep_t prepdata = sync_ctx; - printf("libitdbprep: %s called\n", __func__); + itdb_log_debug("libitdbprep: %s called\n", __func__); if (!prepdata) { - printf("%s called but prepdata is NULL!\n", __func__); + itdb_log_debug("%s called but prepdata is NULL!\n", __func__); return -1; } if (!prepdata->afc) { - printf("%s called but prepdata->afc is NULL!\n", __func__); + itdb_log_debug("%s called but prepdata->afc is NULL!\n", __func__); } else { /* remove .status-com.apple.itdbprep.command.runPostProcess */ if (afc_remove_path(prepdata->afc, "/iTunes_Control/iTunes/iTunes Library.itlp/DBTemp/.status-com.apple.itdprep.command.runPostProcess") != IDEVICE_E_SUCCESS) { - fprintf(stderr, "Could not delete '.status-com.apple.itdprep.command.runPostProcess'\n"); + itdb_log_error("Could not delete '.status-com.apple.itdprep.command.runPostProcess'\n"); } /* remove ddd.itdbm */ if (afc_remove_path(prepdata->afc, "/iTunes_Control/iTunes/iTunes Library.itlp/DBTemp/ddd.itdbm") != IDEVICE_E_SUCCESS) { - fprintf(stderr, "Could not delete 'ddd.itdbm'\n"); + itdb_log_error("Could not delete 'ddd.itdbm'\n"); } if (prepdata->lockfile) { afc_file_lock(prepdata->afc, prepdata->lockfile, AFC_LOCK_UN); afc_file_close(prepdata->afc, prepdata->lockfile); prepdata->lockfile = 0; } else { - printf("%s called but lockfile is 0\n", __func__); + itdb_log_debug("%s called but lockfile is 0\n", __func__); } afc_client_free(prepdata->afc); prepdata->afc = NULL; } if (LOCKDOWN_E_SUCCESS != lockdownd_client_new_with_handshake(prepdata->device, &client, "libgpod")) { - fprintf(stderr, "Error: Could not establish lockdownd connection!\n"); + itdb_log_error("Error: Could not establish lockdownd connection!\n"); goto leave; } if(itdb_iphone_post_notification(prepdata->device, client, NP_SYNC_DID_FINISH)) { - fprintf(stderr, "failed to post syncDidFinish\n"); + itdb_log_error("failed to post syncDidFinish\n"); } - printf("%s: posted syncDidFinish\n", __func__); + itdb_log_debug("%s: posted syncDidFinish\n", __func__); lockdownd_client_free(client); diff --git a/src/itdb_itunesdb.c b/src/itdb_itunesdb.c index a177e26..cd0e97a 100644 --- a/src/itdb_itunesdb.c +++ b/src/itdb_itunesdb.c @@ -112,6 +112,7 @@ #include "itdb_private.h" #include "itdb_zlib.h" #include "itdb_plist.h" +#include "itdb_logger.h" #include <errno.h> #include <fcntl.h> @@ -4270,7 +4271,7 @@ static gunichar2 jump_table_letter (gchar *p) upperchr = g_unichar_toupper (chr); str = g_ucs4_to_utf16 (&upperchr, 1, NULL, NULL, &err); if (err != NULL) { - fprintf (stderr, "Error in UCS4 to UTF16 conversion: %s, original unichar: %x, toupper unichar: %x\n", err->message, chr, upperchr); + itdb_log_error("Error in UCS4 to UTF16 conversion: %s, original unichar: %x, toupper unichar: %x\n", err->message, chr, upperchr); g_error_free (err); return '0'; } diff --git a/src/itdb_logger.c b/src/itdb_logger.c new file mode 100644 index 0000000..6dc676b --- /dev/null +++ b/src/itdb_logger.c @@ -0,0 +1,59 @@ +/* +| Copyright (C) 2014 Rory Yorke <roryyorke at gmail.com> +| Part of the gtkpod project. +| +| URL: http://www.gtkpod.org/ +| URL: http://gtkpod.sourceforge.net/ +| +| The itdb_logger module provides a simple, run-time controllable +| capability for logging debug and error messages to the standard +| error stream. +| +| The code contained in this file is free software; you can redistribute +| it and/or modify it under the terms of the GNU Lesser General Public +| License as published by the Free Software Foundation; either version +| 2.1 of the License, or (at your option) any later version. +| +| This file is distributed in the hope that it will be useful, +| but WITHOUT ANY WARRANTY; without even the implied warranty of +| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +| Lesser General Public License for more details. +| +| You should have received a copy of the GNU Lesser General Public +| License along with this code; if not, write to the Free Software +| Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +| +| iTunes and iPod are trademarks of Apple +| +| This product is not supported/written/published by Apple! +| +*/ +#include <stdarg.h> /* vfprintf */ +#include <stdio.h> /* vfprintf */ +#include <stdlib.h> /* getenv, strtol */ + +#include "itdb_logger.h" + +#define ITDB_LOGLEVEL_NAME "ITDB_LOGLEVEL" + +void itdb_log(int message_level, const char *fmt, ...) +{ + char const *loglevelstring = getenv(ITDB_LOGLEVEL_NAME); + + if(loglevelstring && *loglevelstring) + { /* env var exists and is non-empty */ + char *endptr=0; + long loglevel= strtol(loglevelstring, &endptr, 10); + if(!*endptr) + { /* entire string is valid */ + if(message_level<=loglevel) + { + va_list ap; + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); + va_end(ap); + fflush(stderr); + } + } + } +} diff --git a/src/itdb_logger.h b/src/itdb_logger.h new file mode 100644 index 0000000..b474832 --- /dev/null +++ b/src/itdb_logger.h @@ -0,0 +1,96 @@ +/* +| Copyright (C) 2014 Rory Yorke <roryyorke at gmail.com> +| Part of the gtkpod project. +| +| URL: http://www.gtkpod.org/ +| URL: http://gtkpod.sourceforge.net/ +| +| The itdb_logger module provides a simple, run-time controllable +| capability for logging debug and error messages to the standard +| error stream. +| +| The code contained in this file is free software; you can redistribute +| it and/or modify it under the terms of the GNU Lesser General Public +| License as published by the Free Software Foundation; either version +| 2.1 of the License, or (at your option) any later version. +| +| This file is distributed in the hope that it will be useful, +| but WITHOUT ANY WARRANTY; without even the implied warranty of +| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +| Lesser General Public License for more details. +| +| You should have received a copy of the GNU Lesser General Public +| License along with this code; if not, write to the Free Software +| Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +| +| iTunes and iPod are trademarks of Apple +| +| This product is not supported/written/published by Apple! +| +*/ +#ifndef __ITDB_LOGGER_H__ +#define __ITDB_LOGGER_H__ + +#include <glib.h> + +G_BEGIN_DECLS + +/* G_GNUC_INTERNAL is defined in glib 2.6 */ +#ifndef G_GNUC_INTERNAL +#define G_GNUC_INTERNAL +#endif + +/** + * ITDB_LOG_ERROR: + * + * Tag for error-level logging + * + * Since: TBD + */ +#define ITDB_LOG_ERROR 1 + +/** + * ITDB_LOG_DEBUG: + * Tag for debug-level logging + * + * Since: TBD + */ +#define ITDB_LOG_DEBUG 2 + +/** + * itdb_log: + * + * Log a message + * + * @message_level Log level of message + * @fmt printf-style format string + * @... print-style arguments + * + * If message_level is less than or equal to the current log level + * (determined by environment variable ITDB_LOGLEVEL), the message is + * printed to standard error stream. + * + * Since: TBD + */ +void itdb_log(int message_level, const char *fmt, ...) + __attribute__ ((format (printf, 2, 3))); + +/** + * itdb_log_error: + * + * Convenience macro for calling itdb_log with message level ITDB_LOG_ERROR. + */ +#define itdb_log_error(...) \ + itdb_log(ITDB_LOG_ERROR, __VA_ARGS__) + +/** + * itdb_log_debug: + * + * Convenience macro for calling itdb_log with message level ITDB_LOG_DEBUG. + */ +#define itdb_log_debug(...) \ + itdb_log(ITDB_LOG_DEBUG, __VA_ARGS__) + +G_END_DECLS + +#endif /* ifndef __ITDB_LOGGER_H__ */ diff --git a/src/itdb_sqlite.c b/src/itdb_sqlite.c index b5b2975..b1f56d3 100644 --- a/src/itdb_sqlite.c +++ b/src/itdb_sqlite.c @@ -42,7 +42,7 @@ #include "itdb.h" #include "itdb_private.h" #include "itdb_sqlite_queries.h" - +#include "itdb_logger.h" /** time zone offset in seconds */ static uint32_t tzoffset = 0; @@ -192,35 +192,35 @@ static int mk_Dynamic(Itdb_iTunesDB *itdb, const char *outpath) GList *gl = NULL; dbf = g_build_filename(outpath, "Dynamic.itdb", NULL); - printf("[%s] Processing '%s'\n", __func__, dbf); + itdb_log_debug("[%s] Processing '%s'\n", __func__, dbf); if (stat(dbf, &fst) != 0) { if (errno == ENOENT) { /* file is not present. so we'll create it */ } else { - fprintf(stderr, "[%s] Error: stat: %s\n", __func__, strerror(errno)); + itdb_log_error("[%s] Error: stat: %s\n", __func__, strerror(errno)); goto leave; } } else { /* file is present. delete it, we'll re-create it. */ if (unlink(dbf) != 0) { - fprintf(stderr, "[%s] could not delete '%s': %s\n", __func__, dbf, strerror(errno)); + itdb_log_error("[%s] could not delete '%s': %s\n", __func__, dbf, strerror(errno)); goto leave; } } if (SQLITE_OK != sqlite3_open((const char*)dbf, &db)) { - fprintf(stderr, "Error opening database '%s': %s\n", dbf, sqlite3_errmsg(db)); + itdb_log_error("Error opening database '%s': %s\n", dbf, sqlite3_errmsg(db)); goto leave; } sqlite3_exec(db, "PRAGMA synchronous = OFF;", NULL, NULL, NULL); - fprintf(stderr, "[%s] creating table structure\n", __func__); + itdb_log_error("[%s] creating table structure\n", __func__); /* db structure needs to be created. */ if (SQLITE_OK != sqlite3_exec(db, Dynamic_create, NULL, NULL, &errmsg)) { - fprintf(stderr, "[%s] sqlite3_exec error: %s\n", __func__, sqlite3_errmsg(db)); + itdb_log_error("[%s] sqlite3_exec error: %s\n", __func__, sqlite3_errmsg(db)); if (errmsg) { - fprintf(stderr, "[%s] additional error information: %s\n", __func__, errmsg); + itdb_log_error("[%s] additional error information: %s\n", __func__, errmsg); sqlite3_free(errmsg); errmsg = NULL; } @@ -230,9 +230,9 @@ static int mk_Dynamic(Itdb_iTunesDB *itdb, const char *outpath) sqlite3_exec(db, "BEGIN;", NULL, NULL, NULL); if (itdb->tracks) { - printf("[%s] - processing %d tracks\n", __func__, g_list_length(itdb->tracks)); + itdb_log_debug("[%s] - processing %d tracks\n", __func__, g_list_length(itdb->tracks)); if (SQLITE_OK != sqlite3_prepare_v2(db, "INSERT INTO \"item_stats\" (item_pid,has_been_played,date_played,play_count_user,play_count_recent,date_skipped,skip_count_user,skip_count_recent,bookmark_time_ms,bookmark_time_ms_common,user_rating,user_rating_common) VALUES(?,?,?,?,?,?,?,?,?,?,?,?);", -1, &stmt, NULL)) { - fprintf(stderr, "[%s] sqlite3_prepare error: %s\n", __func__, sqlite3_errmsg(db)); + itdb_log_error("[%s] sqlite3_prepare error: %s\n", __func__, sqlite3_errmsg(db)); goto leave; } for (gl=itdb->tracks; gl; gl=gl->next) { @@ -242,7 +242,7 @@ static int mk_Dynamic(Itdb_iTunesDB *itdb, const char *outpath) } res = sqlite3_reset(stmt); if (res != SQLITE_OK) { - fprintf(stderr, "[%s] 1 sqlite3_reset returned %d\n", __func__, res); + itdb_log_error("[%s] 1 sqlite3_reset returned %d\n", __func__, res); } idx = 0; /* item_pid */ @@ -276,7 +276,7 @@ static int mk_Dynamic(Itdb_iTunesDB *itdb, const char *outpath) if (res == SQLITE_DONE) { /* expected result */ } else { - fprintf(stderr, "[%s] 1 sqlite3_step returned %d\n", __func__, res); + itdb_log_error("[%s] 1 sqlite3_step returned %d\n", __func__, res); } } if (stmt) { @@ -284,22 +284,22 @@ static int mk_Dynamic(Itdb_iTunesDB *itdb, const char *outpath) stmt = NULL; } } else { - printf("[%s] - No tracks available, none written.\n", __func__); + itdb_log_debug("[%s] - No tracks available, none written.\n", __func__); } /* add playlist info to container_ui */ if (SQLITE_OK != sqlite3_prepare_v2(db, "INSERT INTO \"container_ui\" VALUES(?,?,?,?,?,?,?);", -1, &stmt, NULL)) { - fprintf(stderr, "[%s] 2 sqlite3_prepare error: %s\n", __func__, sqlite3_errmsg(db)); + itdb_log_error("[%s] 2 sqlite3_prepare error: %s\n", __func__, sqlite3_errmsg(db)); goto leave; } - printf("[%s] - processing %d playlists\n", __func__, g_list_length(itdb->playlists)); + itdb_log_debug("[%s] - processing %d playlists\n", __func__, g_list_length(itdb->playlists)); for (gl = itdb->playlists; gl; gl = gl->next) { Itdb_Playlist *pl = (Itdb_Playlist*)gl->data; res = sqlite3_reset(stmt); if (res != SQLITE_OK) { - fprintf(stderr, "[%s] 2 sqlite3_reset returned %d\n", __func__, res); + itdb_log_error("[%s] 2 sqlite3_reset returned %d\n", __func__, res); } idx = 0; /* container_pid */ @@ -332,7 +332,7 @@ static int mk_Dynamic(Itdb_iTunesDB *itdb, const char *outpath) if (res == SQLITE_DONE) { /* expected result */ } else { - fprintf(stderr, "[%s] 2 sqlite3_step returned %d\n", __func__, res); + itdb_log_error("[%s] 2 sqlite3_step returned %d\n", __func__, res); } } @@ -344,7 +344,7 @@ static int mk_Dynamic(Itdb_iTunesDB *itdb, const char *outpath) } res = 0; - printf("[%s] done.\n", __func__); + itdb_log_debug("[%s] done.\n", __func__); leave: if (db) { sqlite3_close(db); @@ -367,31 +367,31 @@ static int mk_Extras(Itdb_iTunesDB *itdb, const char *outpath) GList *gl = NULL; dbf = g_build_filename(outpath, "Extras.itdb", NULL); - printf("[%s] Processing '%s'\n", __func__, dbf); + itdb_log_debug("[%s] Processing '%s'\n", __func__, dbf); if (stat(dbf, &fst) != 0) { if (errno == ENOENT) { /* file is not present. so we need to create the tables in it ;) */ rebuild = 1; } else { - fprintf(stderr, "[%s] Error: stat: %s\n", __func__, strerror(errno)); + itdb_log_error("[%s] Error: stat: %s\n", __func__, strerror(errno)); goto leave; } } if (SQLITE_OK != sqlite3_open((const char*)dbf, &db)) { - fprintf(stderr, "Error opening database '%s': %s\n", dbf, sqlite3_errmsg(db)); + itdb_log_error("Error opening database '%s': %s\n", dbf, sqlite3_errmsg(db)); goto leave; } sqlite3_exec(db, "PRAGMA synchronous = OFF;", NULL, NULL, NULL); if (rebuild) { - fprintf(stderr, "[%s] re-building table structure\n", __func__); + itdb_log_error("[%s] re-building table structure\n", __func__); /* db structure needs to be created. */ if (SQLITE_OK != sqlite3_exec(db, Extras_create, NULL, NULL, &errmsg)) { - fprintf(stderr, "[%s] sqlite3_exec error: %s\n", __func__, sqlite3_errmsg(db)); + itdb_log_error("[%s] sqlite3_exec error: %s\n", __func__, sqlite3_errmsg(db)); if (errmsg) { - fprintf(stderr, "[%s] additional error information: %s\n", __func__, errmsg); + itdb_log_error("[%s] additional error information: %s\n", __func__, errmsg); sqlite3_free(errmsg); errmsg = NULL; } @@ -401,15 +401,15 @@ static int mk_Extras(Itdb_iTunesDB *itdb, const char *outpath) sqlite3_exec(db, "BEGIN;", NULL, NULL, NULL); if (SQLITE_OK != sqlite3_prepare_v2(db, "INSERT INTO \"chapter\" VALUES(?,?);", -1, &stmt_chapter, NULL)) { - fprintf(stderr, "[%s] sqlite3_prepare error: %s\n", __func__, sqlite3_errmsg(db)); + itdb_log_error("[%s] sqlite3_prepare error: %s\n", __func__, sqlite3_errmsg(db)); goto leave; } /* kill all entries in 'chapter' as they will be re-inserted */ if (SQLITE_OK != sqlite3_exec(db, "DELETE FROM chapter;", NULL, NULL, &errmsg)) { - fprintf(stderr, "[%s] sqlite3_exec error: %s\n", __func__, sqlite3_errmsg(db)); + itdb_log_error("[%s] sqlite3_exec error: %s\n", __func__, sqlite3_errmsg(db)); if (errmsg) { - fprintf(stderr, "[%s] additional error information: %s\n", __func__, errmsg); + itdb_log_error("[%s] additional error information: %s\n", __func__, errmsg); sqlite3_free(errmsg); errmsg = NULL; } @@ -419,7 +419,7 @@ static int mk_Extras(Itdb_iTunesDB *itdb, const char *outpath) /* kill all entries in 'lyrics' as they will be re-inserted */ /* TODO: we do not support this in the moment, so don't touch this */ /*if (SQLITE_OK != sqlite3_exec(db, "DELETE FROM lyrics;", NULL, NULL, &errmsg)) { - fprintf(stderr, "[%s] sqlite3_exec error: %s\n", __func__, sqlite3_errmsg(db)); + fprintf("[%s] sqlite3_exec error: %s\n", __func__, sqlite3_errmsg(db)); if (errmsg) { fprintf(stderr, "[%s] additional error information: %s\n", __func__, errmsg); sqlite3_free(errmsg); @@ -436,7 +436,7 @@ static int mk_Extras(Itdb_iTunesDB *itdb, const char *outpath) /* printf("[%s] -- inserting into \"chapter\"\n", __func__); */ res = sqlite3_reset(stmt_chapter); if (res != SQLITE_OK) { - fprintf(stderr, "[%s] 1 sqlite3_reset returned %d\n", __func__, res); + itdb_log_error("[%s] 1 sqlite3_reset returned %d\n", __func__, res); } /* item_pid INTEGER NOT NULL */ sqlite3_bind_int64(stmt_chapter, ++idx, track->dbid); @@ -447,7 +447,7 @@ static int mk_Extras(Itdb_iTunesDB *itdb, const char *outpath) if (res == SQLITE_DONE) { /* expected result */ } else { - fprintf(stderr, "[%s] 8 sqlite3_step returned %d\n", __func__, res); + itdb_log_error("[%s] 8 sqlite3_step returned %d\n", __func__, res); } g_byte_array_free(chapter_blob, TRUE); } @@ -455,7 +455,7 @@ static int mk_Extras(Itdb_iTunesDB *itdb, const char *outpath) sqlite3_exec(db, "COMMIT;", NULL, NULL, NULL); res = 0; - printf("[%s] done.\n", __func__); + itdb_log_debug("[%s] done.\n", __func__); leave: if (stmt_chapter) { sqlite3_finalize(stmt_chapter); @@ -479,31 +479,31 @@ static int mk_Genius(Itdb_iTunesDB *itdb, const char *outpath) struct stat fst; dbf = g_build_filename(outpath, "Genius.itdb", NULL); - printf("[%s] Processing '%s'\n", __func__, dbf); + itdb_log_debug("[%s] Processing '%s'\n", __func__, dbf); if (stat(dbf, &fst) != 0) { if (errno == ENOENT) { /* file is not present. so we need to create the tables in it ;) */ rebuild = 1; } else { - fprintf(stderr, "[%s] Error: stat: %s\n", __func__, strerror(errno)); + itdb_log_error("[%s] Error: stat: %s\n", __func__, strerror(errno)); goto leave; } } if (SQLITE_OK != sqlite3_open((const char*)dbf, &db)) { - fprintf(stderr, "Error opening database '%s': %s\n", dbf, sqlite3_errmsg(db)); + itdb_log_error("Error opening database '%s': %s\n", dbf, sqlite3_errmsg(db)); goto leave; } sqlite3_exec(db, "PRAGMA synchronous = OFF;", NULL, NULL, NULL); if (rebuild) { - fprintf(stderr, "[%s] re-building table structure\n", __func__); + itdb_log_error("[%s] re-building table structure\n", __func__); /* db structure needs to be created. */ if (SQLITE_OK != sqlite3_exec(db, Genius_create, NULL, NULL, &errmsg)) { - fprintf(stderr, "[%s] sqlite3_exec error: %s\n", __func__, sqlite3_errmsg(db)); + itdb_log_error("[%s] sqlite3_exec error: %s\n", __func__, sqlite3_errmsg(db)); if (errmsg) { - fprintf(stderr, "[%s] additional error information: %s\n", __func__, errmsg); + itdb_log_error("[%s] additional error information: %s\n", __func__, errmsg); sqlite3_free(errmsg); errmsg = NULL; } @@ -552,7 +552,7 @@ static int mk_Genius(Itdb_iTunesDB *itdb, const char *outpath) sqlite3_exec(db, "COMMIT;", NULL, NULL, NULL); res = 0; - printf("[%s] done.\n", __func__); + itdb_log_debug("[%s] done.\n", __func__); leave: if (db) { sqlite3_close(db); @@ -615,38 +615,38 @@ static int mk_Library(Itdb_iTunesDB *itdb, GHashTable *genre_map = NULL; GHashTable **orders = NULL; guint32 genre_index; - printf("library_persistent_id = 0x%016"G_GINT64_MODIFIER"x\n", itdb->priv->pid); + itdb_log_debug("library_persistent_id = 0x%016"G_GINT64_MODIFIER"x\n", itdb->priv->pid); dbf = g_build_filename(outpath, "Library.itdb", NULL); - printf("[%s] Processing '%s'\n", __func__, dbf); + itdb_log_debug("[%s] Processing '%s'\n", __func__, dbf); if (stat(dbf, &fst) != 0) { if (errno == ENOENT) { /* file is not present. so we will create it */ } else { - fprintf(stderr, "[%s] Error: stat: %s\n", __func__, strerror(errno)); + itdb_log_error("[%s] Error: stat: %s\n", __func__, strerror(errno)); goto leave; } } else { /* file is present. delete it, we'll re-create it. */ if (unlink(dbf) != 0) { - fprintf(stderr, "[%s] could not delete '%s': %s\n", __func__, dbf, strerror(errno)); + itdb_log_error("[%s] could not delete '%s': %s\n", __func__, dbf, strerror(errno)); goto leave; } } if (SQLITE_OK != sqlite3_open((const char*)dbf, &db)) { - fprintf(stderr, "Error opening database '%s': %s\n", dbf, sqlite3_errmsg(db)); + itdb_log_error("Error opening database '%s': %s\n", dbf, sqlite3_errmsg(db)); goto leave; } sqlite3_exec(db, "PRAGMA synchronous = OFF;", NULL, NULL, NULL); - fprintf(stderr, "[%s] building table structure\n", __func__); + itdb_log_error("[%s] building table structure\n", __func__); /* db structure needs to be created. */ if (SQLITE_OK != sqlite3_exec(db, Library_create, NULL, NULL, &errmsg)) { - fprintf(stderr, "[%s] sqlite3_exec error: %s\n", __func__, sqlite3_errmsg(db)); + itdb_log_error("[%s] sqlite3_exec error: %s\n", __func__, sqlite3_errmsg(db)); if (errmsg) { - fprintf(stderr, "[%s] additional error information: %s\n", __func__, errmsg); + itdb_log_error("[%s] additional error information: %s\n", __func__, errmsg); sqlite3_free(errmsg); errmsg = NULL; } @@ -655,22 +655,22 @@ static int mk_Library(Itdb_iTunesDB *itdb, sqlite3_exec(db, "BEGIN;", NULL, NULL, NULL); - fprintf(stderr, "[%s] compiling SQL statements\n", __func__); + itdb_log_error("[%s] compiling SQL statements\n", __func__); if (SQLITE_OK != sqlite3_prepare_v2(db, "INSERT INTO \"version_info\" VALUES(?,?,?,?,?,?,?);", -1, &stmt_version_info, NULL)) { - fprintf(stderr, "[%s] sqlite3_prepare error: %s\n", __func__, sqlite3_errmsg(db)); + itdb_log_error("[%s] sqlite3_prepare error: %s\n", __func__, sqlite3_errmsg(db)); goto leave; } if (SQLITE_OK != sqlite3_prepare_v2(db, "INSERT INTO \"db_info\" VALUES(?,?,?,?,?,?,?,?);", -1, &stmt_db_info, NULL)) { - fprintf(stderr, "[%s] sqlite3_prepare error: %s\n", __func__, sqlite3_errmsg(db)); + itdb_log_error("[%s] sqlite3_prepare error: %s\n", __func__, sqlite3_errmsg(db)); goto leave; } if (SQLITE_OK != sqlite3_prepare_v2(db, "INSERT INTO \"container\" " "VALUES(?,?,?,?,:name,?,?,?,?,?,?,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);", -1, &stmt_container, NULL)) { - fprintf(stderr, "[%s] sqlite3_prepare error: %s\n", __func__, sqlite3_errmsg(db)); + itdb_log_error("[%s] sqlite3_prepare error: %s\n", __func__, sqlite3_errmsg(db)); goto leave; } if (SQLITE_OK != sqlite3_prepare_v2(db, "INSERT INTO \"genre_map\" (id,genre,genre_order) VALUES(?,?,0);", -1, &stmt_genre_map, NULL)) { - fprintf(stderr, "[%s] sqlite3_prepare error: %s\n", __func__, sqlite3_errmsg(db)); + itdb_log_error("[%s] sqlite3_prepare error: %s\n", __func__, sqlite3_errmsg(db)); goto leave; } if (SQLITE_OK != sqlite3_prepare_v2(db, "INSERT INTO \"item\" " @@ -681,39 +681,39 @@ static int mk_Library(Itdb_iTunesDB *itdb, "album_order,genre_order,composer_order,album_artist_order,album_by_artist_order,series_name_order,comment,grouping," "description,description_long) " "VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);", -1, &stmt_item, NULL)) { - fprintf(stderr, "[%s] sqlite3_prepare error: %s\n", __func__, sqlite3_errmsg(db)); + itdb_log_error("[%s] sqlite3_prepare error: %s\n", __func__, sqlite3_errmsg(db)); goto leave; } if (SQLITE_OK != sqlite3_prepare_v2(db, "INSERT OR IGNORE INTO \"location_kind_map\" VALUES(?,:kind);", -1, &stmt_location_kind_map, NULL)) { - fprintf(stderr, "[%s] sqlite3_prepare error: %s\n", __func__, sqlite3_errmsg(db)); + itdb_log_error("[%s] sqlite3_prepare error: %s\n", __func__, sqlite3_errmsg(db)); goto leave; } if (SQLITE_OK != sqlite3_prepare_v2(db, "INSERT INTO \"avformat_info\" VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?);", -1, &stmt_avformat_info, NULL)) { - fprintf(stderr, "[%s] sqlite3_prepare error: %s\n", __func__, sqlite3_errmsg(db)); + itdb_log_error("[%s] sqlite3_prepare error: %s\n", __func__, sqlite3_errmsg(db)); goto leave; } if (SQLITE_OK != sqlite3_prepare_v2(db, "INSERT INTO \"item_to_container\" VALUES(?,?,?,?);", -1, &stmt_item_to_container, NULL)) { - fprintf(stderr, "[%s] sqlite3_prepare error: %s\n", __func__, sqlite3_errmsg(db)); + itdb_log_error("[%s] sqlite3_prepare error: %s\n", __func__, sqlite3_errmsg(db)); goto leave; } if (SQLITE_OK != sqlite3_prepare_v2(db, "INSERT OR IGNORE INTO \"album\" VALUES(?,?,?,?,?,?,?,?,?,?,?);", -1, &stmt_album, NULL)) { - fprintf(stderr, "[%s] sqlite3_prepare error: %s\n", __func__, sqlite3_errmsg(db)); + itdb_log_error("[%s] sqlite3_prepare error: %s\n", __func__, sqlite3_errmsg(db)); goto leave; } if (SQLITE_OK != sqlite3_prepare_v2(db, "INSERT OR IGNORE INTO \"artist\" VALUES(?,?,?,?,?,?,?);", -1, &stmt_artist, NULL)) { - fprintf(stderr, "[%s] sqlite3_prepare error: %s\n", __func__, sqlite3_errmsg(db)); + itdb_log_error("[%s] sqlite3_prepare error: %s\n", __func__, sqlite3_errmsg(db)); goto leave; } if (SQLITE_OK != sqlite3_prepare_v2(db, "INSERT OR IGNORE INTO \"composer\" (pid,name,name_order,sort_name) VALUES(?,?,?,?);", -1, &stmt_composer, NULL)) { - fprintf(stderr, "[%s] sqlite3_prepare error: %s\n", __func__, sqlite3_errmsg(db)); + itdb_log_error("[%s] sqlite3_prepare error: %s\n", __func__, sqlite3_errmsg(db)); goto leave; } if (SQLITE_OK != sqlite3_prepare_v2(db, "INSERT INTO \"video_info\" VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);", -1, &stmt_video_info, NULL)) { - fprintf(stderr, "[%s] sqlite3_prepare error: %s\n", __func__, sqlite3_errmsg(db)); + itdb_log_error("[%s] sqlite3_prepare error: %s\n", __func__, sqlite3_errmsg(db)); goto leave; } - printf("[%s] - inserting into \"version_info\"\n", __func__); + itdb_log_debug("[%s] - inserting into \"version_info\"\n", __func__); /* INSERT INTO "version_info" VALUES(1,2,40,0,0,0,2); */ idx = 0; /* id */ @@ -739,10 +739,10 @@ static int mk_Library(Itdb_iTunesDB *itdb, if (res == SQLITE_DONE) { /* expected result */ } else { - fprintf(stderr, "[%s] 2 sqlite3_step returned %d\n", __func__, res); + itdb_log_error("[%s] 2 sqlite3_step returned %d\n", __func__, res); } - printf("[%s] - inserting into \"genre_map\"\n", __func__); + itdb_log_debug("[%s] - inserting into \"genre_map\"\n", __func__); genre_map = g_hash_table_new(g_str_hash, g_str_equal); /* build genre_map */ @@ -755,7 +755,7 @@ static int mk_Library(Itdb_iTunesDB *itdb, res = sqlite3_reset(stmt_genre_map); if (res != SQLITE_OK) { - fprintf(stderr, "[%s] 1 sqlite3_reset returned %d\n", __func__, res); + itdb_log_error("[%s] 1 sqlite3_reset returned %d\n", __func__, res); } idx = 0; @@ -766,7 +766,7 @@ static int mk_Library(Itdb_iTunesDB *itdb, res = sqlite3_step(stmt_genre_map); if (res != SQLITE_DONE) { - fprintf(stderr, "[%s] sqlite3_step returned %d\n", __func__, res); + itdb_log_error("[%s] sqlite3_step returned %d\n", __func__, res); goto leave; } } @@ -783,7 +783,7 @@ static int mk_Library(Itdb_iTunesDB *itdb, dev_playlist = pl; } - printf("[%s] - inserting songs into \"item_to_container\"\n", __func__); + itdb_log_debug("[%s] - inserting songs into \"item_to_container\"\n", __func__); for (glt = pl->members; glt; glt = glt->next) { Itdb_Track *track = glt->data; @@ -791,7 +791,7 @@ static int mk_Library(Itdb_iTunesDB *itdb, /* printf("[%s] -- inserting into \"item_to_container\"\n", __func__); */ res = sqlite3_reset(stmt_item_to_container); if (res != SQLITE_OK) { - fprintf(stderr, "[%s] 1 sqlite3_reset returned %d\n", __func__, res); + itdb_log_error("[%s] 1 sqlite3_reset returned %d\n", __func__, res); } /* INSERT INTO "item_to_container" VALUES(-6197982141081478573,959107999841118509,0,NULL); */ idx = 0; /* item_pid */ @@ -808,16 +808,16 @@ static int mk_Library(Itdb_iTunesDB *itdb, if (res == SQLITE_DONE) { /* expected result */ } else { - fprintf(stderr, "[%s] 8 sqlite3_step returned %d\n", __func__, res); + itdb_log_error("[%s] 8 sqlite3_step returned %d\n", __func__, res); } types |= track->mediatype; } - printf("[%s] - inserting playlist '%s' into \"container\"\n", __func__, pl->name); + itdb_log_debug("[%s] - inserting playlist '%s' into \"container\"\n", __func__, pl->name); res = sqlite3_reset(stmt_container); if (res != SQLITE_OK) { - fprintf(stderr, "[%s] 1 sqlite3_reset returned %d\n", __func__, res); + itdb_log_error("[%s] 1 sqlite3_reset returned %d\n", __func__, res); } /* INSERT INTO "container" VALUES(959107999841118509,0,267295295,'Hamouda',400,0,1,0,1,0,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL); */ idx = 0; @@ -862,23 +862,23 @@ static int mk_Library(Itdb_iTunesDB *itdb, if (res == SQLITE_DONE) { /* expected result */ } else { - fprintf(stderr, "[%s] 4 sqlite3_step returned %d\n", __func__, res); + itdb_log_error("[%s] 4 sqlite3_step returned %d\n", __func__, res); } } if (!dev_playlist) { - fprintf(stderr, "Could not find special device playlist!\n"); + itdb_log_error("Could not find special device playlist!\n"); goto leave; } - printf("library_persistent_id = 0x%016"G_GINT64_MODIFIER"x\n", itdb->priv->pid); + itdb_log_debug("library_persistent_id = 0x%016"G_GINT64_MODIFIER"x\n", itdb->priv->pid); if (!dev_playlist->name) { - fprintf(stderr, "Could not fetch device name from itdb!\n"); + itdb_log_error("Could not fetch device name from itdb!\n"); goto leave; } - printf("device name = %s\n", dev_playlist->name); + itdb_log_debug("device name = %s\n", dev_playlist->name); - printf("[%s] - inserting into \"db_info\"\n", __func__); + itdb_log_debug("[%s] - inserting into \"db_info\"\n", __func__); idx = 0; /* pid */ sqlite3_bind_int64(stmt_db_info, ++idx, itdb->priv->pid); @@ -910,11 +910,11 @@ static int mk_Library(Itdb_iTunesDB *itdb, if (res == SQLITE_DONE) { /* expected result */ } else { - fprintf(stderr, "[%s] 3 sqlite3_step returned %d\n", __func__, res); + itdb_log_error("[%s] 3 sqlite3_step returned %d\n", __func__, res); } /* for each track: */ - printf("[%s] - processing %d tracks\n", __func__, g_list_length(itdb->tracks)); + itdb_log_debug("[%s] - processing %d tracks\n", __func__, g_list_length(itdb->tracks)); orders = compute_key_orders(itdb->tracks); for (gl = itdb->tracks; gl; gl = gl->next) { @@ -932,7 +932,7 @@ static int mk_Library(Itdb_iTunesDB *itdb, /* printf("[%s] -- inserting into \"item\"\n", __func__); */ res = sqlite3_reset(stmt_item); if (res != SQLITE_OK) { - fprintf(stderr, "[%s] 1 sqlite3_reset returned %d\n", __func__, res); + itdb_log_error("[%s] 1 sqlite3_reset returned %d\n", __func__, res); } /* INSERT INTO "item" VALUES(-6197982141081478573,NULL,1,1,0,0,0,0,0,0,0,0,0,0,2004,0,0,0,0,0,0,2,0,0.0,0.0,213812.0,NULL,1,0,0,0,0,0,NULL,NULL,0,0,0,-7670716306765259718,-7576753259813584028,0,'Enjoy the silence 2004 (Reinterpreted by Mike Shinoda)','Depeche Mode','Enjoy The Silence 04 CDS','Depeche Mode',NULL,'Enjoy the silence 2004 (Reinterpreted by Mike Shinoda)','Depeche Mode','Enjoy The Silence 04 CDS','Depeche Mode',NULL,100,100,100,100,100,100,NULL,100,'Lbl MUTE C:MUTE RCDBONG034',NULL,NULL,NULL,1,0,0,0,0,1,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL); */ idx = 0; @@ -1068,14 +1068,14 @@ static int mk_Library(Itdb_iTunesDB *itdb, res = sqlite3_step(stmt_item); if (res != SQLITE_DONE) { - fprintf(stderr, "[%s] 6 sqlite3_step returned %d\n", __func__, res); + itdb_log_error("[%s] 6 sqlite3_step returned %d\n", __func__, res); goto leave; } /* printf("[%s] -- inserting into \"location_kind_map\" (if required)\n", __func__); */ res = sqlite3_reset(stmt_location_kind_map); if (res != SQLITE_OK) { - fprintf(stderr, "[%s] 1 sqlite3_reset returned %d\n", __func__, res); + itdb_log_error("[%s] 1 sqlite3_reset returned %d\n", __func__, res); } /* INSERT INTO "location_kind_map" VALUES(1,'MPEG-Audiodatei'); */ idx = 0; /* id */ @@ -1087,13 +1087,13 @@ static int mk_Library(Itdb_iTunesDB *itdb, if (res == SQLITE_DONE) { /* expected result */ } else { - fprintf(stderr, "[%s] 5 sqlite3_step returned %d: %s\n", __func__, res, sqlite3_errmsg(db)); + itdb_log_error("[%s] 5 sqlite3_step returned %d: %s\n", __func__, res, sqlite3_errmsg(db)); } /* printf("[%s] -- inserting into \"avformat_info\"\n", __func__); */ res = sqlite3_reset(stmt_avformat_info); if (res != SQLITE_OK) { - fprintf(stderr, "[%s] 1 sqlite3_reset returned %d\n", __func__, res); + itdb_log_error("[%s] 1 sqlite3_reset returned %d\n", __func__, res); } /* INSERT INTO "avformat_info" VALUES(-6197982141081478573,0,301,232,44100.0,9425664,1,576,2880,6224207,0,0,0); */ idx = 0; /* item_pid */ @@ -1143,7 +1143,7 @@ static int mk_Library(Itdb_iTunesDB *itdb, if (res == SQLITE_DONE) { /* expected result */ } else { - fprintf(stderr, "[%s] 7 sqlite3_step returned %d\n", __func__, res); + itdb_log_error("[%s] 7 sqlite3_step returned %d\n", __func__, res); } /* this is done by a trigger, so we don't need to do this :-D */ @@ -1153,7 +1153,7 @@ static int mk_Library(Itdb_iTunesDB *itdb, /* printf("[%s] -- inserting into \"album\" (if required)\n", __func__); */ res = sqlite3_reset(stmt_album); if (res != SQLITE_OK) { - fprintf(stderr, "[%s] 1 sqlite3_reset returned %d\n", __func__, res); + itdb_log_error("[%s] 1 sqlite3_reset returned %d\n", __func__, res); } /* INSERT INTO "album" VALUES(-7670716306765259718,2,0,0,-7576753259813584028,0,'Enjoy The Silence 04 CDS',100,0,NULL,0); */ idx = 0; @@ -1190,7 +1190,7 @@ static int mk_Library(Itdb_iTunesDB *itdb, if (res == SQLITE_DONE) { /* expected result */ } else { - fprintf(stderr, "[%s] 8 sqlite3_step returned %d\n", __func__, res); + itdb_log_error("[%s] 8 sqlite3_step returned %d\n", __func__, res); } } @@ -1199,7 +1199,7 @@ static int mk_Library(Itdb_iTunesDB *itdb, /* printf("[%s] -- inserting into \"artist\" (if required)\n", __func__); */ res = sqlite3_reset(stmt_artist); if (res != SQLITE_OK) { - fprintf(stderr, "[%s] 1 sqlite3_reset returned %d\n", __func__, res); + itdb_log_error("[%s] 1 sqlite3_reset returned %d\n", __func__, res); } /* INSERT INTO "artist" VALUES(-7576753259813584028,2,0,0,'Depeche Mode',100,'Depeche Mode'); */ idx = 0; @@ -1226,7 +1226,7 @@ static int mk_Library(Itdb_iTunesDB *itdb, if (res == SQLITE_DONE) { /* expected result */ } else { - fprintf(stderr, "[%s] 8 sqlite3_step returned %d\n", __func__, res); + itdb_log_error("[%s] 8 sqlite3_step returned %d\n", __func__, res); } } @@ -1234,7 +1234,7 @@ static int mk_Library(Itdb_iTunesDB *itdb, /* printf("[%s] -- inserting into \"composer\" (if required)\n", __func__); */ res = sqlite3_reset(stmt_composer); if (res != SQLITE_OK) { - fprintf(stderr, "[%s] 1 sqlite3_reset returned %d\n", __func__, res); + itdb_log_error("[%s] 1 sqlite3_reset returned %d\n", __func__, res); } idx = 0; /* pid */ @@ -1251,7 +1251,7 @@ static int mk_Library(Itdb_iTunesDB *itdb, if (res == SQLITE_DONE) { /* expected result */ } else { - fprintf(stderr, "[%s] 8 sqlite3_step returned %d\n", __func__, res); + itdb_log_error("[%s] 8 sqlite3_step returned %d\n", __func__, res); } } /* if it's a movie, music video or tv show */ @@ -1261,7 +1261,7 @@ static int mk_Library(Itdb_iTunesDB *itdb, /* printf("[%s] -- inserting into \"video_info\"\n", __func__); */ res = sqlite3_reset(stmt_video_info); if (res != SQLITE_OK) { - fprintf(stderr, "[%s] 1 sqlite3_reset returned %d\n", __func__, res); + itdb_log_error("[%s] 1 sqlite3_reset returned %d\n", __func__, res); } idx = 0; /* item_pid INTEGER NOT NULL */ @@ -1313,7 +1313,7 @@ static int mk_Library(Itdb_iTunesDB *itdb, if (res == SQLITE_DONE) { /* expected result */ } else { - fprintf(stderr, "[%s] 8 sqlite3_step returned %d\n", __func__, res); + itdb_log_error("[%s] 8 sqlite3_step returned %d\n", __func__, res); } } } @@ -1323,7 +1323,7 @@ static int mk_Library(Itdb_iTunesDB *itdb, sqlite3_exec(db, "COMMIT;", NULL, NULL, NULL); res = 0; - printf("[%s] done.\n", __func__); + itdb_log_debug("[%s] done.\n", __func__); leave: if (orders != NULL) { destroy_key_orders(orders); @@ -1387,28 +1387,28 @@ static int mk_Locations(Itdb_iTunesDB *itdb, const char *outpath, const char *uu int idx = 0; dbf = g_build_filename(outpath, "Locations.itdb", NULL); - printf("[%s] Processing '%s'\n", __func__, dbf); + itdb_log_debug("[%s] Processing '%s'\n", __func__, dbf); /* file is present. delete it, we'll re-create it. */ if (g_unlink(dbf) != 0) { if (errno != ENOENT) { - fprintf(stderr, "[%s] could not delete '%s': %s\n", __func__, dbf, strerror(errno)); + itdb_log_error("[%s] could not delete '%s': %s\n", __func__, dbf, strerror(errno)); goto leave; } } if (SQLITE_OK != sqlite3_open((const char*)dbf, &db)) { - fprintf(stderr, "Error opening database '%s': %s\n", dbf, sqlite3_errmsg(db)); + itdb_log_error("Error opening database '%s': %s\n", dbf, sqlite3_errmsg(db)); goto leave; } sqlite3_exec(db, "PRAGMA synchronous = OFF;", NULL, NULL, NULL); - fprintf(stderr, "[%s] re-building table structure\n", __func__); + itdb_log_error("[%s] re-building table structure\n", __func__); /* db structure needs to be created. */ if (SQLITE_OK != sqlite3_exec(db, Locations_create, NULL, NULL, &errmsg)) { - fprintf(stderr, "[%s] sqlite3_exec error: %s\n", __func__, sqlite3_errmsg(db)); + itdb_log_error("[%s] sqlite3_exec error: %s\n", __func__, sqlite3_errmsg(db)); if (errmsg) { - fprintf(stderr, "[%s] additional error information: %s\n", __func__, errmsg); + itdb_log_error("[%s] additional error information: %s\n", __func__, errmsg); sqlite3_free(errmsg); errmsg = NULL; } @@ -1418,13 +1418,13 @@ static int mk_Locations(Itdb_iTunesDB *itdb, const char *outpath, const char *uu sqlite3_exec(db, "BEGIN;", NULL, NULL, NULL); if (SQLITE_OK != sqlite3_prepare_v2(db, "INSERT INTO \"base_location\" (id, path) VALUES (?,?);", -1, &stmt, NULL)) { - fprintf(stderr, "[%s] sqlite3_prepare error: %s\n", __func__, sqlite3_errmsg(db)); + itdb_log_error("[%s] sqlite3_prepare error: %s\n", __func__, sqlite3_errmsg(db)); goto leave; } idx = 0; res = sqlite3_reset(stmt); if (res != SQLITE_OK) { - fprintf(stderr, "[%s] sqlite3_reset returned %d\n", __func__, res); + itdb_log_error("[%s] sqlite3_reset returned %d\n", __func__, res); } sqlite3_bind_int(stmt, ++idx, 1); @@ -1437,14 +1437,14 @@ static int mk_Locations(Itdb_iTunesDB *itdb, const char *outpath, const char *uu if (res == SQLITE_DONE) { /* expected result */ } else { - fprintf(stderr, "[%s] sqlite3_step returned %d\n", __func__, res); + itdb_log_error("[%s] sqlite3_step returned %d\n", __func__, res); } if (itdb_device_is_iphone_family(itdb->device)) { idx = 0; res = sqlite3_reset(stmt); if (res != SQLITE_OK) { - fprintf(stderr, "[%s] sqlite3_reset returned %d\n", __func__, res); + itdb_log_error("[%s] sqlite3_reset returned %d\n", __func__, res); } sqlite3_bind_int(stmt, ++idx, 4); sqlite3_bind_text(stmt, ++idx, "Podcasts", -1, SQLITE_STATIC); @@ -1452,13 +1452,13 @@ static int mk_Locations(Itdb_iTunesDB *itdb, const char *outpath, const char *uu if (res == SQLITE_DONE) { /* expected result */ } else { - fprintf(stderr, "[%s] sqlite3_step returned %d\n", __func__, res); + itdb_log_error("[%s] sqlite3_step returned %d\n", __func__, res); } idx = 0; res = sqlite3_reset(stmt); if (res != SQLITE_OK) { - fprintf(stderr, "[%s] sqlite3_reset returned %d\n", __func__, res); + itdb_log_error("[%s] sqlite3_reset returned %d\n", __func__, res); } sqlite3_bind_int(stmt, ++idx, 6); sqlite3_bind_text(stmt, ++idx, "iTunes_Control/Ringtones", -1, SQLITE_STATIC); @@ -1466,7 +1466,7 @@ static int mk_Locations(Itdb_iTunesDB *itdb, const char *outpath, const char *uu if (res == SQLITE_DONE) { /* expected result */ } else { - fprintf(stderr, "[%s] sqlite3_step returned %d\n", __func__, res); + itdb_log_error("[%s] sqlite3_step returned %d\n", __func__, res); } } @@ -1475,14 +1475,14 @@ static int mk_Locations(Itdb_iTunesDB *itdb, const char *outpath, const char *uu } if (SQLITE_OK != sqlite3_prepare_v2(db, "INSERT INTO \"location\" (item_pid, sub_id, base_location_id, location_type, location, extension, kind_id, date_created, file_size) VALUES(?,?,?,?,?,?,?,?,?);", -1, &stmt, NULL)) { - fprintf(stderr, "[%s] sqlite3_prepare error: %s\n", __func__, sqlite3_errmsg(db)); + itdb_log_error("[%s] sqlite3_prepare error: %s\n", __func__, sqlite3_errmsg(db)); goto leave; } if (itdb->tracks) { GList *gl = NULL; - printf("[%s] Processing %d tracks...\n", __func__, g_list_length(itdb->tracks)); + itdb_log_debug("[%s] Processing %d tracks...\n", __func__, g_list_length(itdb->tracks)); for (gl=itdb->tracks; gl; gl=gl->next) { Itdb_Track *track = gl->data; char *ipod_path; @@ -1498,7 +1498,7 @@ static int mk_Locations(Itdb_iTunesDB *itdb, const char *outpath, const char *uu idx = 0; res = sqlite3_reset(stmt); if (res != SQLITE_OK) { - fprintf(stderr, "[%s] sqlite3_reset returned %d\n", __func__, res); + itdb_log_error("[%s] sqlite3_reset returned %d\n", __func__, res); } /* item_pid */ sqlite3_bind_int64(stmt, ++idx, track->dbid); @@ -1550,7 +1550,7 @@ static int mk_Locations(Itdb_iTunesDB *itdb, const char *outpath, const char *uu if (res == SQLITE_DONE) { /* expected result */ } else { - fprintf(stderr, "[%s] 10 sqlite3_step returned %d\n", __func__, res); + itdb_log_error("[%s] 10 sqlite3_step returned %d\n", __func__, res); } if (ipod_path) { free(ipod_path); @@ -1558,13 +1558,13 @@ static int mk_Locations(Itdb_iTunesDB *itdb, const char *outpath, const char *uu } } } else { - printf("[%s] No tracks available, none written.\n", __func__); + itdb_log_debug("[%s] No tracks available, none written.\n", __func__); } sqlite3_exec(db, "COMMIT;", NULL, NULL, NULL); res = 0; - printf("[%s] done.\n", __func__); + itdb_log_debug("[%s] done.\n", __func__); leave: if (stmt) { sqlite3_finalize(stmt); @@ -1637,7 +1637,7 @@ static void sqlite_func_iphone_sort_key(sqlite3_context *context, int argc, sqli int buffer_size = 0; if (argc != 1) - fprintf(stderr, "[%s] Error: Unexpected number of arguments: %d\n", __func__, argc); + itdb_log_error("[%s] Error: Unexpected number of arguments: %d\n", __func__, argc); switch (sqlite3_value_type(argv[0])) { case SQLITE_TEXT: @@ -1736,7 +1736,7 @@ static void sqlite_func_iphone_sort_section(sqlite3_context *context, int argc, int res = 26; if (argc != 1) - fprintf(stderr, "[%s] Error: Unexpected number of arguments: %d\n", __func__, argc); + itdb_log_error("[%s] Error: Unexpected number of arguments: %d\n", __func__, argc); switch (sqlite3_value_type(argv[0])) { case SQLITE_BLOB: @@ -1771,12 +1771,12 @@ static void run_post_process_commands(Itdb_iTunesDB *itdb, const char *outpath, ret = idevice_new(&phone, uuid); if (ret != IDEVICE_E_SUCCESS) { - printf("[%s] ERROR: Could not find device with uuid %s, is it plugged in?\n", __func__, uuid); + itdb_log_debug("[%s] ERROR: Could not find device with uuid %s, is it plugged in?\n", __func__, uuid); goto leave; } if (LOCKDOWN_E_SUCCESS != lockdownd_client_new_with_handshake(phone, &client, "libgpod")) { - printf("[%s] ERROR: Could not connect to device's lockdownd!\n", __func__); + itdb_log_debug("[%s] ERROR: Could not connect to device's lockdownd!\n", __func__); idevice_free(phone); goto leave; } @@ -1826,7 +1826,7 @@ static void run_post_process_commands(Itdb_iTunesDB *itdb, const char *outpath, plist_t sql_cmds = NULL; plist_t user_ver_cmds = NULL; - printf("[%s] Getting SQL post process commands\n", __func__); + itdb_log_debug("[%s] Getting SQL post process commands\n", __func__); sql_cmds = plist_dict_get_item(ppc_dict, "SQLCommands"); user_ver_cmds = plist_dict_get_item(ppc_dict, "UserVersionCommandSets"); @@ -1884,7 +1884,7 @@ static void run_post_process_commands(Itdb_iTunesDB *itdb, const char *outpath, g_hash_table_insert(sqlcmd_map, key, val); val = NULL; } else { - printf("[%s] WARNING: ignoring non-string value for key '%s'\n", __func__, key); + itdb_log_debug("[%s] WARNING: ignoring non-string value for key '%s'\n", __func__, key); free(key); } subnode = NULL; @@ -1899,7 +1899,7 @@ static void run_post_process_commands(Itdb_iTunesDB *itdb, const char *outpath, dbf = g_build_filename(outpath, basedb, NULL); if (SQLITE_OK != sqlite3_open((const char*)dbf, &db)) { - fprintf(stderr, "Error opening database '%s': %s\n", dbf, sqlite3_errmsg(db)); + itdb_log_error("Error opening database '%s': %s\n", dbf, sqlite3_errmsg(db)); g_free(dbf); goto leave; } @@ -1915,7 +1915,7 @@ static void run_post_process_commands(Itdb_iTunesDB *itdb, const char *outpath, res = sqlite3_exec(db, attach_str, NULL, NULL, &errmsg); g_free(attach_str); if (res != SQLITE_OK) { - printf("[%s] WARNING: Could not attach database '%s': %s\n", __func__, otherdbs[i], errmsg); + itdb_log_debug("[%s] WARNING: Could not attach database '%s': %s\n", __func__, otherdbs[i], errmsg); } if (errmsg) { free(errmsg); @@ -1923,12 +1923,12 @@ static void run_post_process_commands(Itdb_iTunesDB *itdb, const char *outpath, i++; } - printf("[%s] binding functions\n", __func__); + itdb_log_debug("[%s] binding functions\n", __func__); sqlite3_create_function(db, "iPhoneSortKey", 1, SQLITE_ANY, NULL, &sqlite_func_iphone_sort_key, NULL, NULL); sqlite3_create_function(db, "iPhoneSortSection", 1, SQLITE_ANY, NULL, &sqlite_func_iphone_sort_section, NULL, NULL); cnt = plist_array_get_size(user_ver_cmds); - printf("[%s] Running %d post process commands now\n", __func__, cnt); + itdb_log_debug("[%s] Running %d post process commands now\n", __func__, cnt); sqlite3_exec(db, "BEGIN;", NULL, NULL, NULL); for (i=0; i<cnt; i++) { @@ -1942,13 +1942,13 @@ static void run_post_process_commands(Itdb_iTunesDB *itdb, const char *outpath, /*printf("[%s] executing '%s': OK", __func__, key);*/ ok_cnt++; } else { - printf("[%s] ERROR when executing '%s': %s\n", __func__, key, errmsg); + itdb_log_debug("[%s] ERROR when executing '%s': %s\n", __func__, key, errmsg); } if (errmsg) { sqlite3_free(errmsg); } } else { - printf("[%s] value for '%s' not found in hashmap!\n", __func__, key); + itdb_log_debug("[%s] value for '%s' not found in hashmap!\n", __func__, key); } free(key); key = NULL; @@ -1957,24 +1957,24 @@ static void run_post_process_commands(Itdb_iTunesDB *itdb, const char *outpath, g_hash_table_foreach(sqlcmd_map, free_key_val_strings, NULL); g_hash_table_destroy(sqlcmd_map); - printf("[%s] %d out of %d post process commands successfully executed\n", __func__, ok_cnt, cnt); + itdb_log_debug("[%s] %d out of %d post process commands successfully executed\n", __func__, ok_cnt, cnt); /* TODO perhaps we want to roll back when an error has occured ? */ sqlite3_exec(db, "COMMIT;", NULL, NULL, NULL); } else { - printf("[%s]: Error: could not create hash table!\n", __func__); + itdb_log_debug("[%s]: Error: could not create hash table!\n", __func__); } } else { - printf("[%s]: Error fetching commands array\n", __func__); + itdb_log_debug("[%s]: Error fetching commands array\n", __func__); } } else { - printf("[%s]: Error fetching user version command set\n", __func__); + itdb_log_debug("[%s]: Error fetching user version command set\n", __func__); } } else { - printf("[%s]: Error fetching post process commands from device!\n", __func__); + itdb_log_debug("[%s]: Error fetching post process commands from device!\n", __func__); } } - printf("[%s] done.\n", __func__); + itdb_log_debug("[%s] done.\n", __func__); leave: if (db) { @@ -2091,7 +2091,7 @@ static gboolean mk_Locations_cbk(Itdb_iTunesDB *itdb, const char *dirname) break; } if (cbk_header_size == 0) { - fprintf(stderr, "ERROR: Unsupported checksum type '%d' in cbk file generation!\n", checksum_type); + itdb_log_error("ERROR: Unsupported checksum type '%d' in cbk file generation!\n", checksum_type); return FALSE; } @@ -2208,11 +2208,11 @@ static int copy_itdb_file(const gchar *from_dir, const gchar *to_dir, gchar *dstname = g_build_filename(to_dir, fname, NULL); if (itdb_cp(srcname, dstname, error)) { - fprintf(stderr, "itdbprep: copying '%s'\n", fname); + itdb_log_error("itdbprep: copying '%s'\n", fname); res++; } if (error && *error) { - fprintf(stderr, "Error copying '%s' to '%s': %s\n", srcname, dstname, (*error)->message); + itdb_log_error("Error copying '%s' to '%s': %s\n", srcname, dstname, (*error)->message); } if (srcname) { @@ -2257,21 +2257,21 @@ int itdb_sqlite_generate_itdbs(FExport *fexp) gchar *dirname; gchar *tmpdir = NULL; - printf("libitdbprep: %s called with file %s and uuid %s\n", __func__, + itdb_log_debug("libitdbprep: %s called with file %s and uuid %s\n", __func__, fexp->itdb->filename, itdb_device_get_uuid(fexp->itdb->device)); dirname = itdb_get_itunes_dir(itdb_get_mountpoint(fexp->itdb)); itlpdir = g_build_filename(dirname, "iTunes Library.itlp", NULL); g_free(dirname); - printf("itlp directory='%s'\n", itlpdir); + itdb_log_debug("itlp directory='%s'\n", itlpdir); if (... [truncated message content] |