From 3b57fa5d0ed2d8060233fa9604bd7f98a7d6cdab Mon Sep 17 00:00:00 2001 From: Martin Szulecki Date: Tue, 12 Jan 2010 17:38:36 +0100 Subject: Rename utils to debug as it does exactly that, contain debug code --- src/AFC.c | 2 +- src/InstallationProxy.c | 2 +- src/Makefile.am | 2 +- src/MobileSync.c | 2 +- src/NotificationProxy.c | 2 +- src/SBServices.c | 2 +- src/debug.c | 131 ++++++++++++++++++++++++++++++++++++++++++++ src/debug.h | 33 +++++++++++ src/device_link_service.c | 2 +- src/iphone.c | 2 +- src/lockdown.c | 2 +- src/property_list_service.c | 2 +- src/userpref.c | 2 +- src/utils.c | 131 -------------------------------------------- src/utils.h | 33 ----------- 15 files changed, 175 insertions(+), 175 deletions(-) create mode 100644 src/debug.c create mode 100644 src/debug.h delete mode 100644 src/utils.c delete mode 100644 src/utils.h (limited to 'src') diff --git a/src/AFC.c b/src/AFC.c index 956c8fc..fe8e1af 100644 --- a/src/AFC.c +++ b/src/AFC.c @@ -25,7 +25,7 @@ #include "AFC.h" #include "iphone.h" -#include "utils.h" +#include "debug.h" // This is the maximum size an AFC data packet can be static const int MAXIMUM_PACKET_SIZE = (2 << 15); diff --git a/src/InstallationProxy.c b/src/InstallationProxy.c index 34777d1..8d994c6 100644 --- a/src/InstallationProxy.c +++ b/src/InstallationProxy.c @@ -27,7 +27,7 @@ #include "InstallationProxy.h" #include "property_list_service.h" -#include "utils.h" +#include "debug.h" struct instproxy_status_data { instproxy_client_t client; diff --git a/src/Makefile.am b/src/Makefile.am index bc98de4..bb7252e 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -13,5 +13,5 @@ libiphone_la_SOURCES = iphone.c iphone.h \ InstallationProxy.c InstallationProxy.h\ SBServices.c SBServices.h\ userpref.c userpref.h\ - utils.c utils.h\ + debug.c debug.h\ MobileSync.c MobileSync.h diff --git a/src/MobileSync.c b/src/MobileSync.c index 5102619..e904fcc 100644 --- a/src/MobileSync.c +++ b/src/MobileSync.c @@ -26,7 +26,7 @@ #include "MobileSync.h" #include "device_link_service.h" -#include "utils.h" +#include "debug.h" #define MSYNC_VERSION_INT1 100 #define MSYNC_VERSION_INT2 100 diff --git a/src/NotificationProxy.c b/src/NotificationProxy.c index ef2063c..1b13a29 100644 --- a/src/NotificationProxy.c +++ b/src/NotificationProxy.c @@ -28,7 +28,7 @@ #include "NotificationProxy.h" #include "property_list_service.h" -#include "utils.h" +#include "debug.h" struct np_thread { np_client_t client; diff --git a/src/SBServices.c b/src/SBServices.c index 2a724d1..2b65785 100644 --- a/src/SBServices.c +++ b/src/SBServices.c @@ -27,7 +27,7 @@ #include "SBServices.h" #include "property_list_service.h" -#include "utils.h" +#include "debug.h" /** Locks an sbservices client, done for thread safety stuff. * diff --git a/src/debug.c b/src/debug.c new file mode 100644 index 0000000..b5f74ad --- /dev/null +++ b/src/debug.c @@ -0,0 +1,131 @@ +/* + * debug.c + * contains utilitary methos for logging and debugging + * + * Copyright (c) 2008 Jonathan Beck All Rights Reserved. + * + * This library 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 library 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 library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ +#include +#include +#include + +#include "debug.h" +#include "libiphone/libiphone.h" + +int toto_debug = 0; +uint16_t dbg_mask = 0; + +/** + * Sets the level of debugging. Currently the only acceptable values are 0 and + * 1. + * + * @param level Set to 0 for no debugging or 1 for debugging. + */ +void iphone_set_debug_level(int level) +{ + toto_debug = level; +} + + +/** + * Set debug ids to display. Values can be OR-ed + * + * @param level Set to 0 for no debugging or 1 for debugging. + */ +void iphone_set_debug_mask(uint16_t mask) +{ + dbg_mask = mask; +} + +void log_debug_msg(const char *format, ...) +{ +#ifndef STRIP_DEBUG_CODE + + va_list args; + /* run the real fprintf */ + va_start(args, format); + + if (toto_debug) + vfprintf(stderr, format, args); + + va_end(args); + +#endif +} + +void log_dbg_msg(uint16_t id, const char *format, ...) +{ +#ifndef STRIP_DEBUG_CODE + if (id & dbg_mask) { + va_list args; + /* run the real fprintf */ + va_start(args, format); + + vfprintf(stderr, format, args); + + va_end(args); + } +#endif +} + +inline void log_debug_buffer(const char *data, const int length) +{ +#ifndef STRIP_DEBUG_CODE + int i; + int j; + unsigned char c; + + if (toto_debug) { + for (i = 0; i < length; i += 16) { + fprintf(stderr, "%04x: ", i); + for (j = 0; j < 16; j++) { + if (i + j >= length) { + fprintf(stderr, " "); + continue; + } + fprintf(stderr, "%02hhx ", *(data + i + j)); + } + fprintf(stderr, " | "); + for (j = 0; j < 16; j++) { + if (i + j >= length) + break; + c = *(data + i + j); + if ((c < 32) || (c > 127)) { + fprintf(stderr, "."); + continue; + } + fprintf(stderr, "%c", c); + } + fprintf(stderr, "\n"); + } + fprintf(stderr, "\n"); + } +#endif +} + +inline void dump_debug_buffer(const char *file, const char *data, const int length) +{ +#ifndef STRIP_DEBUG_CODE + /* run the real fprintf */ + if (toto_debug) { + FILE *my_ssl_packet = fopen(file, "w+"); + fwrite(data, 1, length, my_ssl_packet); + fflush(my_ssl_packet); + fprintf(stderr, "%s: Wrote SSL packet to drive, too.\n", __func__); + fclose(my_ssl_packet); + } +#endif +} diff --git a/src/debug.h b/src/debug.h new file mode 100644 index 0000000..96844dd --- /dev/null +++ b/src/debug.h @@ -0,0 +1,33 @@ +/* + * debug.h + * contains utilitary methos for logging and debugging + * + * Copyright (c) 2008 Jonathan Beck All Rights Reserved. + * + * This library 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 library 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 library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef DEBUG_H +#define DEBUG_H + +#include + +G_GNUC_INTERNAL inline void log_debug_msg(const char *format, ...); +G_GNUC_INTERNAL inline void log_dbg_msg(uint16_t id, const char *format, ...); + +G_GNUC_INTERNAL inline void log_debug_buffer(const char *data, const int length); +G_GNUC_INTERNAL inline void dump_debug_buffer(const char *file, const char *data, const int length); + +#endif diff --git a/src/device_link_service.c b/src/device_link_service.c index 83b0676..b1106fe 100644 --- a/src/device_link_service.c +++ b/src/device_link_service.c @@ -22,7 +22,7 @@ #include #include "device_link_service.h" #include "property_list_service.h" -#include "utils.h" +#include "debug.h" /** * Internally used function to extract the message string from a DLMessage* diff --git a/src/iphone.c b/src/iphone.c index 9307b19..7b21bb5 100644 --- a/src/iphone.c +++ b/src/iphone.c @@ -27,7 +27,7 @@ #include #include "iphone.h" -#include "utils.h" +#include "debug.h" static iphone_event_cb_t event_cb = NULL; diff --git a/src/lockdown.c b/src/lockdown.c index f78fbb4..5927192 100644 --- a/src/lockdown.c +++ b/src/lockdown.c @@ -31,7 +31,7 @@ #include "property_list_service.h" #include "lockdown.h" #include "iphone.h" -#include "utils.h" +#include "debug.h" #include "userpref.h" #define RESULT_SUCCESS 0 diff --git a/src/property_list_service.c b/src/property_list_service.c index 9d16bbc..b549cb4 100644 --- a/src/property_list_service.c +++ b/src/property_list_service.c @@ -25,7 +25,7 @@ #include "property_list_service.h" #include "iphone.h" -#include "utils.h" +#include "debug.h" /** * Convert an iphone_error_t value to an property_list_service_error_t value. diff --git a/src/userpref.c b/src/userpref.c index 54fdafc..c677fda 100644 --- a/src/userpref.c +++ b/src/userpref.c @@ -31,7 +31,7 @@ #include #include "userpref.h" -#include "utils.h" +#include "debug.h" #define LIBIPHONE_CONF_DIR "libiphone" #define LIBIPHONE_CONF_FILE "libiphonerc" diff --git a/src/utils.c b/src/utils.c deleted file mode 100644 index 3c08351..0000000 --- a/src/utils.c +++ /dev/null @@ -1,131 +0,0 @@ -/* - * utils.c - * contains utilitary methos for logging and debugging - * - * Copyright (c) 2008 Jonathan Beck All Rights Reserved. - * - * This library 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 library 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 library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ -#include -#include -#include - -#include "utils.h" -#include "libiphone/libiphone.h" - -int toto_debug = 0; -uint16_t dbg_mask = 0; - -/** - * Sets the level of debugging. Currently the only acceptable values are 0 and - * 1. - * - * @param level Set to 0 for no debugging or 1 for debugging. - */ -void iphone_set_debug_level(int level) -{ - toto_debug = level; -} - - -/** - * Set debug ids to display. Values can be OR-ed - * - * @param level Set to 0 for no debugging or 1 for debugging. - */ -void iphone_set_debug_mask(uint16_t mask) -{ - dbg_mask = mask; -} - -void log_debug_msg(const char *format, ...) -{ -#ifndef STRIP_DEBUG_CODE - - va_list args; - /* run the real fprintf */ - va_start(args, format); - - if (toto_debug) - vfprintf(stderr, format, args); - - va_end(args); - -#endif -} - -void log_dbg_msg(uint16_t id, const char *format, ...) -{ -#ifndef STRIP_DEBUG_CODE - if (id & dbg_mask) { - va_list args; - /* run the real fprintf */ - va_start(args, format); - - vfprintf(stderr, format, args); - - va_end(args); - } -#endif -} - -inline void log_debug_buffer(const char *data, const int length) -{ -#ifndef STRIP_DEBUG_CODE - int i; - int j; - unsigned char c; - - if (toto_debug) { - for (i = 0; i < length; i += 16) { - fprintf(stderr, "%04x: ", i); - for (j = 0; j < 16; j++) { - if (i + j >= length) { - fprintf(stderr, " "); - continue; - } - fprintf(stderr, "%02hhx ", *(data + i + j)); - } - fprintf(stderr, " | "); - for (j = 0; j < 16; j++) { - if (i + j >= length) - break; - c = *(data + i + j); - if ((c < 32) || (c > 127)) { - fprintf(stderr, "."); - continue; - } - fprintf(stderr, "%c", c); - } - fprintf(stderr, "\n"); - } - fprintf(stderr, "\n"); - } -#endif -} - -inline void dump_debug_buffer(const char *file, const char *data, const int length) -{ -#ifndef STRIP_DEBUG_CODE - /* run the real fprintf */ - if (toto_debug) { - FILE *my_ssl_packet = fopen(file, "w+"); - fwrite(data, 1, length, my_ssl_packet); - fflush(my_ssl_packet); - fprintf(stderr, "%s: Wrote SSL packet to drive, too.\n", __func__); - fclose(my_ssl_packet); - } -#endif -} diff --git a/src/utils.h b/src/utils.h deleted file mode 100644 index c99730a..0000000 --- a/src/utils.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * utils.h - * contains utilitary methos for logging and debugging - * - * Copyright (c) 2008 Jonathan Beck All Rights Reserved. - * - * This library 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 library 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 library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef UTILS_H -#define UTILS_H - -#include - -G_GNUC_INTERNAL inline void log_debug_msg(const char *format, ...); -G_GNUC_INTERNAL inline void log_dbg_msg(uint16_t id, const char *format, ...); - -G_GNUC_INTERNAL inline void log_debug_buffer(const char *data, const int length); -G_GNUC_INTERNAL inline void dump_debug_buffer(const char *file, const char *data, const int length); - -#endif -- cgit v1.1-32-gdbae