diff options
Diffstat (limited to 'src/utils.c')
| -rw-r--r-- | src/utils.c | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/src/utils.c b/src/utils.c new file mode 100644 index 0000000..e54403b --- /dev/null +++ b/src/utils.c | |||
| @@ -0,0 +1,80 @@ | |||
| 1 | /* | ||
| 2 | * utils.c | ||
| 3 | * contains utilitary methos for logging and debugging | ||
| 4 | * | ||
| 5 | * Copyright (c) 2008 Jonathan Beck All Rights Reserved. | ||
| 6 | * | ||
| 7 | * This library is free software; you can redistribute it and/or | ||
| 8 | * modify it under the terms of the GNU Lesser General Public | ||
| 9 | * License as published by the Free Software Foundation; either | ||
| 10 | * version 2.1 of the License, or (at your option) any later version. | ||
| 11 | * | ||
| 12 | * This library is distributed in the hope that it will be useful, | ||
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 15 | * Lesser General Public License for more details. | ||
| 16 | * | ||
| 17 | * You should have received a copy of the GNU Lesser General Public | ||
| 18 | * License along with this library; if not, write to the Free Software | ||
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 20 | */ | ||
| 21 | #include <stdarg.h> | ||
| 22 | #include <stdio.h> | ||
| 23 | #include "utils.h" | ||
| 24 | |||
| 25 | int toto_debug = 0; | ||
| 26 | |||
| 27 | /** | ||
| 28 | * Sets the level of debugging. Currently the only acceptable values are 0 and | ||
| 29 | * 1. | ||
| 30 | * | ||
| 31 | * @param level Set to 0 for no debugging or 1 for debugging. | ||
| 32 | */ | ||
| 33 | void iphone_set_debug(int level) | ||
| 34 | { | ||
| 35 | toto_debug = level; | ||
| 36 | } | ||
| 37 | |||
| 38 | |||
| 39 | |||
| 40 | void log_debug_msg(const char *format, ...) | ||
| 41 | { | ||
| 42 | #ifndef STRIP_DEBUG | ||
| 43 | |||
| 44 | va_list args; | ||
| 45 | /* run the real fprintf */ | ||
| 46 | va_start(args, format); | ||
| 47 | |||
| 48 | if (toto_debug) | ||
| 49 | fprintf(stderr, format, args); | ||
| 50 | |||
| 51 | va_end(args); | ||
| 52 | |||
| 53 | #endif | ||
| 54 | } | ||
| 55 | |||
| 56 | inline void log_debug_buffer(const char *data, const int length) | ||
| 57 | { | ||
| 58 | #ifndef STRIP_DEBUG | ||
| 59 | |||
| 60 | /* run the real fprintf */ | ||
| 61 | if (toto_debug) | ||
| 62 | fwrite(data, 1, length, stderr); | ||
| 63 | |||
| 64 | #endif | ||
| 65 | } | ||
| 66 | |||
| 67 | inline void dump_debug_buffer(const char *file, const char *data, const int length) | ||
| 68 | { | ||
| 69 | #ifndef STRIP_DEBUG | ||
| 70 | |||
| 71 | /* run the real fprintf */ | ||
| 72 | if (toto_debug) { | ||
| 73 | FILE *my_ssl_packet = fopen(file, "w+"); | ||
| 74 | fwrite(data, 1, length, my_ssl_packet); | ||
| 75 | fflush(my_ssl_packet); | ||
| 76 | fprintf(stderr, "Wrote SSL packet to drive, too.\n"); | ||
| 77 | fclose(my_ssl_packet); | ||
| 78 | } | ||
| 79 | #endif | ||
| 80 | } | ||
