comparison src/protocols/sametime/meanwhile/mw_debug.c @ 10969:3ef77720e577

[gaim-migrate @ 12790] importing meanwhile library for use in the sametime plugin committer: Tailor Script <tailor@pidgin.im>
author Christopher O'Brien <siege@pidgin.im>
date Sun, 05 Jun 2005 02:50:13 +0000
parents
children 0110fc7c6a8a
comparison
equal deleted inserted replaced
10968:e0d5038fbb7e 10969:3ef77720e577
1
2 /*
3 Meanwhile - Unofficial Lotus Sametime Community Client Library
4 Copyright (C) 2004 Christopher (siege) O'Brien
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public
17 License along with this library; if not, write to the Free
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21 #include <glib/gstring.h>
22
23 #include "mw_debug.h"
24
25
26 #define FRM "%02x"
27 #define FRMT "%02x%02x "
28 #define BUF(n) ((unsigned char) buf[n])
29 #define ADVANCE(b, n, c) {b += c; n -= c;}
30
31
32 #ifdef DEBUG
33 /** writes hex pairs of buf to str */
34 static void t_pretty_print(GString *str, const char *buf, gsize len) {
35 while(len) {
36 if(len >= 16) {
37 g_string_append_printf(str,
38 FRMT FRMT FRMT FRMT FRMT FRMT FRMT FRMT "\n",
39 BUF(0), BUF(1), BUF(2), BUF(3),
40 BUF(4), BUF(5), BUF(6), BUF(7),
41 BUF(8), BUF(9), BUF(10), BUF(11),
42 BUF(12), BUF(13), BUF(14), BUF(15));
43 ADVANCE(buf, len, 16);
44
45 } else if(len == 2) {
46 g_string_append_printf(str, FRMT "\n", BUF(0), BUF(1));
47 ADVANCE(buf, len, 2);
48
49 } else if(len > 1) {
50 g_string_append_printf(str, FRMT, BUF(0), BUF(1));
51 ADVANCE(buf, len, 2);
52
53 } else {
54 g_string_append_printf(str, FRM "\n", BUF(0));
55 ADVANCE(buf, len, 1);
56 }
57 }
58 }
59 #endif
60
61
62 void pretty_print(const char *buf, gsize len) {
63 #ifdef DEBUG
64 GString *str;
65
66 if(! len) return;
67
68 g_return_if_fail(buf != NULL);
69
70 str = g_string_new(NULL);
71 t_pretty_print(str, buf, len);
72 g_debug(str->str);
73 g_string_free(str, TRUE);
74 #endif
75 ;
76 }
77
78
79 void pretty_print_opaque(struct mwOpaque *o) {
80 if(! o) return;
81 pretty_print(o->data, o->len);
82 }
83
84
85 void mw_debug_mailme_v(struct mwOpaque *block,
86 const char *info, va_list args) {
87 /*
88 MW_MAILME_MESSAGE
89 begin here
90 info % args
91 pretty_print
92 end here
93 */
94
95 #ifdef DEBUG
96 GString *str;
97 char *txt;
98
99 str = g_string_new(MW_MAILME_MESSAGE "\n"
100 " Please send mail to: " MW_MAILME_ADDRESS "\n"
101 MW_MAILME_CUT_START "\n");
102
103 txt = g_strdup_vprintf(info, args);
104 g_string_append(str, txt);
105 g_free(txt);
106
107 g_string_append(str, "\n");
108
109 if(block) {
110 t_pretty_print(str, block->data, block->len);
111 }
112
113 g_string_append(str, MW_MAILME_CUT_STOP);
114
115 g_debug(str->str);
116 g_string_free(str, TRUE);
117 #endif
118 ;
119 }
120
121
122 void mw_debug_mailme(struct mwOpaque *block,
123 const char *info, ...) {
124 va_list args;
125 va_start(args, info);
126 mw_debug_mailme_v(block, info, args);
127 va_end(args);
128 }
129