Mercurial > pidgin
annotate libpurple/protocols/qq/packet_parse.c @ 23048:9a5d140400f1
patch-02-fix-multiarch
author | SHiNE CsyFeK <csyfek@gmail.com> |
---|---|
date | Tue, 24 Jun 2008 11:58:57 +0000 |
parents | 44b4e8bd759b |
children | 190bc4ecf6c3 |
rev | line source |
---|---|
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1 /** |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2 * @file packet_parse.c |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3 * |
15822 | 4 * purple |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
5 * |
15822 | 6 * Purple is the legal property of its developers, whose names are too numerous |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
7 * to list here. Please refer to the COPYRIGHT file distributed with this |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
8 * source distribution. |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
9 * |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
10 * This program is free software; you can redistribute it and/or modify |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
11 * it under the terms of the GNU General Public License as published by |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
12 * the Free Software Foundation; either version 2 of the License, or |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
13 * (at your option) any later version. |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
14 * |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
15 * This program is distributed in the hope that it will be useful, |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
18 * GNU General Public License for more details. |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
19 * |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
20 * You should have received a copy of the GNU General Public License |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
21 * along with this program; if not, write to the Free Software |
19681
44b4e8bd759b
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
18141
diff
changeset
|
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
23 */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
24 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
25 #include <string.h> |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
26 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
27 #include "packet_parse.h" |
23048 | 28 #include "debug.h" |
29 | |
30 | |
31 /*------------------------------------------------PUT------------------------------------------------*/ | |
32 | |
33 /* note: | |
34 * 1, in these functions, 'b' stands for byte, 'w' stands for word, 'dw' stands for double word. | |
35 * 2, we use '*cursor' and 'buf' as two addresses to calculate the length. | |
36 * 3, fixed obscure bugs, thanks ccpaging. | |
37 * 4, change '0' to '1', if want to get more info about the packet parsing. | |
38 * by s3e, 20070717 */ | |
39 | |
40 #if 0 | |
41 #define PARSER_DEBUG | |
42 #endif | |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
43 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
44 /* read one byte from buf, |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
45 * return the number of bytes read if succeeds, otherwise return -1 */ |
23048 | 46 /* |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
47 gint read_packet_b(guint8 *buf, guint8 **cursor, gint buflen, guint8 *b) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
48 { |
23048 | 49 guint8 *b_ship = NULL; |
50 #ifdef PARSER_DEBUG | |
51 purple_debug(PURPLE_DEBUG_INFO, "QQ_DEBUGGER", | |
52 "[read_b] buf addr: 0x%x\n", (gpointer)buf); | |
53 #endif | |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
54 if (*cursor <= buf + buflen - sizeof(*b)) { |
23048 | 55 #ifdef PARSER_DEBUG |
56 purple_debug(PURPLE_DEBUG_INFO, "QQ_DEBUGGER", | |
57 "[read_b] *cursor addr: 0x%x, buf expected addr: 0x%x\n", | |
58 (gpointer)*cursor, (gpointer)(buf + buflen - sizeof(*b))); | |
59 #endif | |
60 b_ship = g_new0(guint8, sizeof(guint8)); | |
61 g_memmove(b_ship, *cursor, sizeof(guint8)); | |
62 *b = *b_ship; | |
63 #ifdef PARSER_DEBUG | |
64 purple_debug(PURPLE_DEBUG_INFO, "QQ_DEBUGGER", | |
65 "[read_b] data: 0x%02x->0x%02x\n", | |
66 **(guint8 **)cursor, *b); | |
67 #endif | |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
68 *cursor += sizeof(*b); |
23048 | 69 // free |
70 g_free(b_ship); | |
71 b_ship = NULL; | |
72 | |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
73 return sizeof(*b); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
74 } else { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
75 return -1; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
76 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
77 } |
23048 | 78 */ |
79 gint qq_get8(guint8 *b, guint8 *buf) | |
80 { | |
81 guint8 b_dest; | |
82 memcpy(&b_dest, buf, sizeof(b_dest)); | |
83 *b = b_dest; | |
84 purple_debug(PURPLE_DEBUG_ERROR, "QQ", "[DBG][get8] buf %d\n", (void *)buf); | |
85 purple_debug(PURPLE_DEBUG_ERROR, "QQ", "[DBG][get8] b_dest 0x%2x, *b 0x%02x\n", b_dest, *b); | |
86 return sizeof(b_dest); | |
87 } | |
88 | |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
89 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
90 /* read two bytes as "guint16" from buf, |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
91 * return the number of bytes read if succeeds, otherwise return -1 */ |
23048 | 92 /* |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
93 gint read_packet_w(guint8 *buf, guint8 **cursor, gint buflen, guint16 *w) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
94 { |
23048 | 95 guint8 *w_ship = NULL; |
96 guint16 w_dest; | |
97 #ifdef PARSER_DEBUG | |
98 purple_debug(PURPLE_DEBUG_INFO, "QQ_DEBUGGER", | |
99 "[read_w] buf addr: 0x%x\n", (gpointer)buf); | |
100 #endif | |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
101 if (*cursor <= buf + buflen - sizeof(*w)) { |
23048 | 102 #ifdef PARSER_DEBUG |
103 purple_debug(PURPLE_DEBUG_INFO, "QQ_DEBUGGER", | |
104 "[read_w] *cursor addr: 0x%x, buf expected addr: 0x%x\n", | |
105 (gpointer)*cursor, (gpointer)(buf + buflen - sizeof(*w))); | |
106 #endif | |
107 // type should match memory buffer | |
108 w_ship = (guint8 *)g_new0(guint16, 1); | |
109 // copy bytes into temporary buffer | |
110 g_memmove(w_ship, *cursor, sizeof(guint16)); | |
111 // type convert and assign value | |
112 w_dest = *(guint16 *)w_ship; | |
113 // ntohs | |
114 *w = g_ntohs(w_dest); | |
115 #ifdef PARSER_DEBUG | |
116 purple_debug(PURPLE_DEBUG_INFO, "QQ_DEBUGGER", | |
117 "[read_w] data: 0x%04x->0x%04x-g_ntohs->0x%04x\n", | |
118 **(guint16 **)cursor, w_dest, *w); | |
119 #endif | |
120 // *cursor goes on | |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
121 *cursor += sizeof(*w); |
23048 | 122 |
123 // free mem | |
124 g_free(w_ship); | |
125 w_ship = NULL; | |
126 | |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
127 return sizeof(*w); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
128 } else { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
129 return -1; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
130 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
131 } |
23048 | 132 */ |
133 gint qq_get16(guint16 *w, guint8 *buf) | |
134 { | |
135 guint16 w_dest; | |
136 memcpy(&w_dest, buf, sizeof(w_dest)); | |
137 *w = g_ntohs(w_dest); | |
138 purple_debug(PURPLE_DEBUG_ERROR, "QQ", "[DBG][get16] buf %d\n", (void *)buf); | |
139 purple_debug(PURPLE_DEBUG_ERROR, "QQ", "[DBG][get16] w_dest 0x%04x, *w 0x%04x\n", w_dest, *w); | |
140 return sizeof(w_dest); | |
141 } | |
142 | |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
143 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
144 /* read four bytes as "guint32" from buf, |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
145 * return the number of bytes read if succeeds, otherwise return -1 */ |
23048 | 146 /* |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
147 gint read_packet_dw(guint8 *buf, guint8 **cursor, gint buflen, guint32 *dw) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
148 { |
23048 | 149 guint8 *dw_ship = NULL; |
150 guint32 dw_dest; | |
151 #ifdef PARSER_DEBUG | |
152 purple_debug(PURPLE_DEBUG_INFO, "QQ_DEBUGGER", | |
153 "[read_dw] buf addr: 0x%x\n", (gpointer)buf); | |
154 #endif | |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
155 if (*cursor <= buf + buflen - sizeof(*dw)) { |
23048 | 156 #ifdef PARSER_DEBUG |
157 purple_debug(PURPLE_DEBUG_INFO, "QQ_DEBUGGER", | |
158 "[read_dw] *cursor addr: 0x%x, buf expected addr: 0x%x\n", | |
159 (gpointer)*cursor, (gpointer)(buf + buflen - sizeof(*dw))); | |
160 #endif | |
161 dw_ship = (guint8 *)g_new0(guint32, 1); | |
162 g_memmove(dw_ship, *cursor, sizeof(guint32)); | |
163 dw_dest = *(guint32 *)dw_ship; | |
164 *dw = g_ntohl(dw_dest); | |
165 #ifdef PARSER_DEBUG | |
166 purple_debug(PURPLE_DEBUG_INFO, "QQ_DEBUGGER", | |
167 "[read_dw] data: 0x%08x->0x%08x-g_ntohl->0x%08x\n", | |
168 **(guint32 **)cursor, dw_dest, *dw); | |
169 #endif | |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
170 *cursor += sizeof(*dw); |
23048 | 171 |
172 g_free(dw_ship); | |
173 dw_ship = NULL; | |
174 | |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
175 return sizeof(*dw); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
176 } else { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
177 return -1; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
178 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
179 } |
23048 | 180 */ |
181 gint qq_get32(guint32 *dw, guint8 *buf) | |
182 { | |
183 guint32 dw_dest; | |
184 memcpy(&dw_dest, buf, sizeof(dw_dest)); | |
185 *dw = g_ntohl(dw_dest); | |
186 purple_debug(PURPLE_DEBUG_ERROR, "QQ", "[DBG][get32] buf %d\n", (void *)buf); | |
187 purple_debug(PURPLE_DEBUG_ERROR, "QQ", "[DBG][get32] dw_dest 0x%08x, *dw 0x%08x\n", dw_dest, *dw); | |
188 return sizeof(dw_dest); | |
189 } | |
190 | |
191 | |
192 /* read datalen bytes from buf, | |
193 * return the number of bytes read if succeeds, otherwise return -1 */ | |
194 /* | |
195 gint read_packet_data(guint8 *buf, guint8 **cursor, gint buflen, guint8 *data, gint datalen) { | |
196 #ifdef PARSER_DEBUG | |
197 purple_debug(PURPLE_DEBUG_INFO, "QQ_DEBUGGER", | |
198 "[read_data] buf addr: 0x%x\n", (gpointer)buf); | |
199 #endif | |
200 if (*cursor <= buf + buflen - datalen) { | |
201 #ifdef PARSER_DEBUG | |
202 purple_debug(PURPLE_DEBUG_INFO, "QQ_DEBUGGER", | |
203 "[read_data] *cursor addr: 0x%x, buf expected addr: 0x%x\n", | |
204 (gpointer)*cursor, (gpointer)(buf + buflen - datalen)); | |
205 #endif | |
206 g_memmove(data, *cursor, datalen); | |
207 *cursor += datalen; | |
208 return datalen; | |
209 } else { | |
210 return -1; | |
211 } | |
212 } | |
213 */ | |
214 gint qq_getdata(guint8 *data, gint datalen, guint8 *buf) | |
215 { | |
216 memcpy(data, buf, datalen); | |
217 purple_debug(PURPLE_DEBUG_ERROR, "QQ", "[DBG][getdata] buf %d\n", (void *)buf); | |
218 return datalen; | |
219 } | |
220 | |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
221 |
18141
833f7cbe4f12
A patch from o_sukhodolsky to fix a compiler warning in the QQ code. I've
Richard Laager <rlaager@wiktel.com>
parents:
15822
diff
changeset
|
222 /* read four bytes as "time_t" from buf, |
833f7cbe4f12
A patch from o_sukhodolsky to fix a compiler warning in the QQ code. I've
Richard Laager <rlaager@wiktel.com>
parents:
15822
diff
changeset
|
223 * return the number of bytes read if succeeds, otherwise return -1 |
833f7cbe4f12
A patch from o_sukhodolsky to fix a compiler warning in the QQ code. I've
Richard Laager <rlaager@wiktel.com>
parents:
15822
diff
changeset
|
224 * This function is a wrapper around read_packet_dw() to avoid casting. */ |
23048 | 225 /* |
18141
833f7cbe4f12
A patch from o_sukhodolsky to fix a compiler warning in the QQ code. I've
Richard Laager <rlaager@wiktel.com>
parents:
15822
diff
changeset
|
226 gint read_packet_time(guint8 *buf, guint8 **cursor, gint buflen, time_t *t) |
833f7cbe4f12
A patch from o_sukhodolsky to fix a compiler warning in the QQ code. I've
Richard Laager <rlaager@wiktel.com>
parents:
15822
diff
changeset
|
227 { |
833f7cbe4f12
A patch from o_sukhodolsky to fix a compiler warning in the QQ code. I've
Richard Laager <rlaager@wiktel.com>
parents:
15822
diff
changeset
|
228 guint32 time; |
833f7cbe4f12
A patch from o_sukhodolsky to fix a compiler warning in the QQ code. I've
Richard Laager <rlaager@wiktel.com>
parents:
15822
diff
changeset
|
229 gint ret = read_packet_dw(buf, cursor, buflen, &time); |
833f7cbe4f12
A patch from o_sukhodolsky to fix a compiler warning in the QQ code. I've
Richard Laager <rlaager@wiktel.com>
parents:
15822
diff
changeset
|
230 if (ret != -1 ) { |
833f7cbe4f12
A patch from o_sukhodolsky to fix a compiler warning in the QQ code. I've
Richard Laager <rlaager@wiktel.com>
parents:
15822
diff
changeset
|
231 *t = time; |
833f7cbe4f12
A patch from o_sukhodolsky to fix a compiler warning in the QQ code. I've
Richard Laager <rlaager@wiktel.com>
parents:
15822
diff
changeset
|
232 } |
833f7cbe4f12
A patch from o_sukhodolsky to fix a compiler warning in the QQ code. I've
Richard Laager <rlaager@wiktel.com>
parents:
15822
diff
changeset
|
233 return ret; |
833f7cbe4f12
A patch from o_sukhodolsky to fix a compiler warning in the QQ code. I've
Richard Laager <rlaager@wiktel.com>
parents:
15822
diff
changeset
|
234 } |
23048 | 235 */ |
236 gint qq_getime(time_t *t, guint8 *buf) | |
237 { | |
238 guint32 dw_dest; | |
239 memcpy(&dw_dest, buf, sizeof(dw_dest)); | |
240 purple_debug(PURPLE_DEBUG_ERROR, "QQ", "[DBG][getime] buf %d\n", (void *)buf); | |
241 purple_debug(PURPLE_DEBUG_ERROR, "QQ", "[DBG][getime] dw_dest before 0x%08x\n", dw_dest); | |
242 dw_dest = g_ntohl(dw_dest); | |
243 purple_debug(PURPLE_DEBUG_ERROR, "QQ", "[DBG][getime] dw_dest after 0x%08x\n", dw_dest); | |
244 memcpy(t, &dw_dest, sizeof(dw_dest)); | |
245 return sizeof(dw_dest); | |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
246 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
247 |
23048 | 248 /*------------------------------------------------PUT------------------------------------------------*/ |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
249 /* pack one byte into buf |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
250 * return the number of bytes packed, otherwise return -1 */ |
23048 | 251 /* |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
252 gint create_packet_b(guint8 *buf, guint8 **cursor, guint8 b) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
253 { |
23048 | 254 guint8 b_dest; |
255 #ifdef PARSER_DEBUG | |
256 // show me the address! | |
257 purple_debug(PURPLE_DEBUG_INFO, "QQ_DEBUGGER", | |
258 "[create_b] buf addr: 0x%x\n", (gpointer)buf); | |
259 #endif | |
260 // using gpointer is more safe, s3e, 20070704 | |
261 if ((gpointer)*cursor <= (gpointer)(buf + MAX_PACKET_SIZE - sizeof(guint8))) { | |
262 #ifdef PARSER_DEBUG | |
263 purple_debug(PURPLE_DEBUG_INFO, "QQ_DEBUGGER", | |
264 "[create_b] *cursor addr: 0x%x, buf expected addr: 0x%x\n", | |
265 (gpointer)*cursor, | |
266 (gpointer)(buf + MAX_PACKET_SIZE - sizeof(guint8))); | |
267 #endif | |
268 b_dest = b; | |
269 g_memmove(*cursor, &b_dest, sizeof(guint8)); | |
270 #ifdef PARSER_DEBUG | |
271 // show data | |
272 purple_debug(PURPLE_DEBUG_INFO, "QQ_DEBUGGER", | |
273 "[create_b] data: 0x%02x->0x%02x\n", b, **(guint8 **)cursor); | |
274 #endif | |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
275 *cursor += sizeof(guint8); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
276 return sizeof(guint8); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
277 } else { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
278 return -1; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
279 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
280 } |
23048 | 281 */ |
282 gint qq_put8(guint8 *buf, guint8 b) | |
283 { | |
284 memcpy(buf, &b, sizeof(b)); | |
285 purple_debug(PURPLE_DEBUG_ERROR, "QQ", "[DBG][put8] buf %d\n", (void *)buf); | |
286 purple_debug(PURPLE_DEBUG_ERROR, "QQ", "[DBG][put8] b 0x%02x\n", b); | |
287 return sizeof(b); | |
288 } | |
289 | |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
290 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
291 /* pack two bytes as "guint16" into buf |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
292 * return the number of bytes packed, otherwise return -1 */ |
23048 | 293 /* |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
294 gint create_packet_w(guint8 *buf, guint8 **cursor, guint16 w) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
295 { |
23048 | 296 guint16 w_dest; |
297 guint8 *w_ship = NULL; | |
298 #ifdef PARSER_DEBUG | |
299 purple_debug(PURPLE_DEBUG_INFO, "QQ_DEBUGGER", | |
300 "[create_w] buf addr: 0x%x\n", (gpointer)buf); | |
301 #endif | |
302 if ((gpointer)*cursor <= (gpointer)(buf + MAX_PACKET_SIZE - sizeof(guint16))) { | |
303 #ifdef PARSER_DEBUG | |
304 purple_debug(PURPLE_DEBUG_INFO, "QQ_DEBUGGER", | |
305 "[create_w] *cursor addr: 0x%x, buf expected addr: 0x%x\n", | |
306 (gpointer)*cursor, | |
307 (gpointer)(buf + MAX_PACKET_SIZE - sizeof(guint16))); | |
308 #endif | |
309 // obscure bugs found by ccpaging, patches from him. | |
310 // similar bugs have been fixed, s3e, 20070710 | |
311 w_dest = g_htons(w); | |
312 w_ship = (guint8 *)&w_dest; | |
313 g_memmove(*cursor, w_ship, sizeof(guint16)); | |
314 #ifdef PARSER_DEBUG | |
315 purple_debug(PURPLE_DEBUG_INFO, "QQ_DEBUGGER", | |
316 "[create_w] data: 0x%04x-g_htons->0x%04x->0x%04x\n", | |
317 w, w_dest, **(guint16 **)cursor); | |
318 #endif | |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
319 *cursor += sizeof(guint16); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
320 return sizeof(guint16); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
321 } else { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
322 return -1; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
323 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
324 } |
23048 | 325 */ |
326 gint qq_put16(guint8 *buf, guint16 w) | |
327 { | |
328 guint16 w_porter; | |
329 w_porter = g_htons(w); | |
330 purple_debug(PURPLE_DEBUG_ERROR, "QQ", "[DBG][put16] buf %d\n", (void *)buf); | |
331 purple_debug(PURPLE_DEBUG_ERROR, "QQ", "[DBG][put16] w 0x%04x, w_porter 0x%04x\n", w, w_porter); | |
332 memcpy(buf, &w_porter, sizeof(w_porter)); | |
333 return sizeof(w_porter); | |
334 } | |
335 | |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
336 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
337 /* pack four bytes as "guint32" into buf |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
338 * return the number of bytes packed, otherwise return -1 */ |
23048 | 339 /* |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
340 gint create_packet_dw(guint8 *buf, guint8 **cursor, guint32 dw) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
341 { |
23048 | 342 guint32 dw_dest; |
343 guint8 *dw_ship = NULL; | |
344 #ifdef PARSER_DEBUG | |
345 purple_debug(PURPLE_DEBUG_INFO, "QQ_DEBUGGER", "[create_dw] buf addr: 0x%x\n", (gpointer)buf); | |
346 #endif | |
347 if ((gpointer)*cursor <= (gpointer)(buf + MAX_PACKET_SIZE - sizeof(guint32))) { | |
348 #ifdef PARSER_DEBUG | |
349 purple_debug(PURPLE_DEBUG_INFO, "QQ_DEBUGGER", | |
350 "[create_dw] *cursor addr: 0x%x, buf expected addr: 0x%x\n", | |
351 (gpointer)*cursor, | |
352 (gpointer)(buf + MAX_PACKET_SIZE -sizeof(guint32))); | |
353 #endif | |
354 dw_dest = g_htonl(dw); | |
355 dw_ship = (guint8 *)&dw_dest; | |
356 g_memmove(*cursor, dw_ship, sizeof(guint32)); | |
357 #ifdef PARSER_DEBUG | |
358 purple_debug(PURPLE_DEBUG_INFO, "QQ_DEBUGGER", | |
359 "[create_dw] data: 0x%08x-g_htonl->0x%08x->0x%08x\n", | |
360 dw, dw_dest, **(guint32 **)cursor); | |
361 #endif | |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
362 *cursor += sizeof(guint32); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
363 return sizeof(guint32); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
364 } else { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
365 return -1; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
366 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
367 } |
23048 | 368 */ |
369 gint qq_put32(guint8 *buf, guint32 dw) | |
370 { | |
371 guint32 dw_porter; | |
372 dw_porter = g_htonl(dw); | |
373 purple_debug(PURPLE_DEBUG_ERROR, "QQ", "[DBG][put32] buf %d\n", (void *)buf); | |
374 purple_debug(PURPLE_DEBUG_ERROR, "QQ", "[DBG][put32] dw 0x%08x, dw_porter 0x%08x\n", dw, dw_porter); | |
375 memcpy(buf, &dw_porter, sizeof(dw_porter)); | |
376 return sizeof(dw_porter); | |
377 } | |
378 | |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
379 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
380 /* pack datalen bytes into buf |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
381 * return the number of bytes packed, otherwise return -1 */ |
23048 | 382 /* |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
383 gint create_packet_data(guint8 *buf, guint8 **cursor, guint8 *data, gint datalen) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
384 { |
23048 | 385 #ifdef PARSER_DEBUG |
386 purple_debug(PURPLE_DEBUG_INFO, "QQ_DEBUGGER", | |
387 "[create_data] buf addr: 0x%x\n", (gpointer)buf); | |
388 #endif | |
389 if ((gpointer)*cursor <= (gpointer)(buf + MAX_PACKET_SIZE - datalen)) { | |
390 #ifdef PARSER_DEBUG | |
391 purple_debug(PURPLE_DEBUG_INFO, "QQ_DEBUGGER", | |
392 "[create_data] *cursor addr: 0x%x, buf expected addr: 0x%x\n", | |
393 (gpointer)*cursor, | |
394 (gpointer)(buf + MAX_PACKET_SIZE - datalen)); | |
395 #endif | |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
396 g_memmove(*cursor, data, datalen); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
397 *cursor += datalen; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
398 return datalen; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
399 } else { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
400 return -1; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
401 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
402 } |
23048 | 403 */ |
404 gint qq_putdata(guint8 *buf, guint8 *data, const int datalen) | |
405 { | |
406 memcpy(buf, data, datalen); | |
407 purple_debug(PURPLE_DEBUG_ERROR, "QQ", "[DBG][putdata] buf %d\n", (void *)buf); | |
408 return datalen; | |
409 } | |
410 | |
411 |