Mercurial > pidgin
annotate libpurple/protocols/qq/packet_parse.c @ 23878:967344bc404d
applied changes from f12c8903079425d7850fa183df0b3f937b2952be
through 8cebefbc6cd5d84acb69c74e69e8821f11dd225d
Backport of 8cebefbc6cd5d84acb69c74e69e8821f11dd225d to avoid having other changes overwritten.
2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
* Rename group to room. If you used pidginqq before, this may create a new room with same title, you may
delete old one
* Replace purple_debug with purple_debug_info, purple_debug_warning, purple_debug_error
* Add server notice and server new, and two options to turn on/off
* Minor modify for reducing transaction's debug infor
* Minor modifies for system notice and QQ news.
* Add 4 new strings need translate compare with p10.
committer: Daniel Atallah <daniel.atallah@gmail.com>
author | SHiNE CsyFeK <csyfek@gmail.com> |
---|---|
date | Mon, 15 Sep 2008 02:59:23 +0000 |
parents | 1c50f12b1c52 |
children | 25f62d21b3f8 |
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 /*------------------------------------------------PUT------------------------------------------------*/ | |
31 | |
32 /* note: | |
33 * 1, in these functions, 'b' stands for byte, 'w' stands for word, 'dw' stands for double word. | |
34 * 2, we use '*cursor' and 'buf' as two addresses to calculate the length. | |
23051
55f986ccbb6a
patch-05-reconnect-and-code-cleanup
SHiNE CsyFeK <csyfek@gmail.com>
parents:
23050
diff
changeset
|
35 * 3, change '0' to '1', if want to get more info about the packet parsing. */ |
23048 | 36 |
37 #if 0 | |
38 #define PARSER_DEBUG | |
39 #endif | |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
40 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
41 /* read one byte from buf, |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
42 * return the number of bytes read if succeeds, otherwise return -1 */ |
23048 | 43 gint qq_get8(guint8 *b, guint8 *buf) |
44 { | |
45 guint8 b_dest; | |
46 memcpy(&b_dest, buf, sizeof(b_dest)); | |
47 *b = b_dest; | |
23050 | 48 #ifdef PARSER_DEBUG |
23878
967344bc404d
applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents:
23638
diff
changeset
|
49 purple_debug_info("QQ", "[DBG][get8] buf %p\n", (void *)buf); |
967344bc404d
applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents:
23638
diff
changeset
|
50 purple_debug_info("QQ", "[DBG][get8] b_dest 0x%2x, *b 0x%02x\n", b_dest, *b); |
23050 | 51 #endif |
23048 | 52 return sizeof(b_dest); |
53 } | |
54 | |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
55 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
56 /* read two bytes as "guint16" from buf, |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
57 * return the number of bytes read if succeeds, otherwise return -1 */ |
23048 | 58 gint qq_get16(guint16 *w, guint8 *buf) |
59 { | |
60 guint16 w_dest; | |
61 memcpy(&w_dest, buf, sizeof(w_dest)); | |
62 *w = g_ntohs(w_dest); | |
23050 | 63 #ifdef PARSER_DEBUG |
23878
967344bc404d
applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents:
23638
diff
changeset
|
64 purple_debug_info("QQ", "[DBG][get16] buf %p\n", (void *)buf); |
967344bc404d
applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents:
23638
diff
changeset
|
65 purple_debug_info("QQ", "[DBG][get16] w_dest 0x%04x, *w 0x%04x\n", w_dest, *w); |
23050 | 66 #endif |
23048 | 67 return sizeof(w_dest); |
68 } | |
69 | |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
70 /* read four bytes as "guint32" from buf, |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
71 * return the number of bytes read if succeeds, otherwise return -1 */ |
23048 | 72 gint qq_get32(guint32 *dw, guint8 *buf) |
73 { | |
74 guint32 dw_dest; | |
75 memcpy(&dw_dest, buf, sizeof(dw_dest)); | |
76 *dw = g_ntohl(dw_dest); | |
23050 | 77 #ifdef PARSER_DEBUG |
23878
967344bc404d
applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents:
23638
diff
changeset
|
78 purple_debug_info("QQ", "[DBG][get32] buf %p\n", (void *)buf); |
967344bc404d
applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents:
23638
diff
changeset
|
79 purple_debug_info("QQ", "[DBG][get32] dw_dest 0x%08x, *dw 0x%08x\n", dw_dest, *dw); |
23050 | 80 #endif |
23048 | 81 return sizeof(dw_dest); |
82 } | |
83 | |
23638
1c50f12b1c52
2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents:
23051
diff
changeset
|
84 gint qq_getIP(struct in_addr *ip, guint8 *buf) |
1c50f12b1c52
2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents:
23051
diff
changeset
|
85 { |
1c50f12b1c52
2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents:
23051
diff
changeset
|
86 memcpy(ip, buf, sizeof(struct in_addr)); |
1c50f12b1c52
2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents:
23051
diff
changeset
|
87 return sizeof(struct in_addr); |
1c50f12b1c52
2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents:
23051
diff
changeset
|
88 } |
23048 | 89 |
90 /* read datalen bytes from buf, | |
91 * return the number of bytes read if succeeds, otherwise return -1 */ | |
92 gint qq_getdata(guint8 *data, gint datalen, guint8 *buf) | |
93 { | |
94 memcpy(data, buf, datalen); | |
23050 | 95 #ifdef PARSER_DEBUG |
23878
967344bc404d
applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents:
23638
diff
changeset
|
96 purple_debug_info("QQ", "[DBG][getdata] buf %p\n", (void *)buf); |
23050 | 97 #endif |
23048 | 98 return datalen; |
99 } | |
100 | |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
101 |
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
|
102 /* 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
|
103 * 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
|
104 * This function is a wrapper around read_packet_dw() to avoid casting. */ |
23048 | 105 gint qq_getime(time_t *t, guint8 *buf) |
106 { | |
107 guint32 dw_dest; | |
108 memcpy(&dw_dest, buf, sizeof(dw_dest)); | |
23050 | 109 #ifdef PARSER_DEBUG |
23878
967344bc404d
applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents:
23638
diff
changeset
|
110 purple_debug_info("QQ", "[DBG][getime] buf %p\n", (void *)buf); |
967344bc404d
applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents:
23638
diff
changeset
|
111 purple_debug_info("QQ", "[DBG][getime] dw_dest before 0x%08x\n", dw_dest); |
23050 | 112 #endif |
23048 | 113 dw_dest = g_ntohl(dw_dest); |
23050 | 114 #ifdef PARSER_DEBUG |
23878
967344bc404d
applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents:
23638
diff
changeset
|
115 purple_debug_info("QQ", "[DBG][getime] dw_dest after 0x%08x\n", dw_dest); |
23050 | 116 #endif |
23048 | 117 memcpy(t, &dw_dest, sizeof(dw_dest)); |
118 return sizeof(dw_dest); | |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
119 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
120 |
23048 | 121 /*------------------------------------------------PUT------------------------------------------------*/ |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
122 /* pack one byte into buf |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
123 * return the number of bytes packed, otherwise return -1 */ |
23048 | 124 gint qq_put8(guint8 *buf, guint8 b) |
125 { | |
126 memcpy(buf, &b, sizeof(b)); | |
23050 | 127 #ifdef PARSER_DEBUG |
23878
967344bc404d
applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents:
23638
diff
changeset
|
128 purple_debug_info("QQ", "[DBG][put8] buf %p\n", (void *)buf); |
967344bc404d
applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents:
23638
diff
changeset
|
129 purple_debug_info("QQ", "[DBG][put8] b 0x%02x\n", b); |
23050 | 130 #endif |
23048 | 131 return sizeof(b); |
132 } | |
133 | |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
134 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
135 /* pack two bytes as "guint16" into buf |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
136 * return the number of bytes packed, otherwise return -1 */ |
23048 | 137 gint qq_put16(guint8 *buf, guint16 w) |
138 { | |
139 guint16 w_porter; | |
140 w_porter = g_htons(w); | |
23050 | 141 #ifdef PARSER_DEBUG |
23878
967344bc404d
applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents:
23638
diff
changeset
|
142 purple_debug_info("QQ", "[DBG][put16] buf %p\n", (void *)buf); |
967344bc404d
applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents:
23638
diff
changeset
|
143 purple_debug_info("QQ", "[DBG][put16] w 0x%04x, w_porter 0x%04x\n", w, w_porter); |
23050 | 144 #endif |
23048 | 145 memcpy(buf, &w_porter, sizeof(w_porter)); |
146 return sizeof(w_porter); | |
147 } | |
148 | |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
149 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
150 /* pack four bytes as "guint32" into buf |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
151 * return the number of bytes packed, otherwise return -1 */ |
23048 | 152 gint qq_put32(guint8 *buf, guint32 dw) |
153 { | |
154 guint32 dw_porter; | |
155 dw_porter = g_htonl(dw); | |
23050 | 156 #ifdef PARSER_DEBUG |
23878
967344bc404d
applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents:
23638
diff
changeset
|
157 purple_debug_info("QQ", "[DBG][put32] buf %p\n", (void *)buf); |
967344bc404d
applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents:
23638
diff
changeset
|
158 purple_debug_info("QQ", "[DBG][put32] dw 0x%08x, dw_porter 0x%08x\n", dw, dw_porter); |
23050 | 159 #endif |
23048 | 160 memcpy(buf, &dw_porter, sizeof(dw_porter)); |
161 return sizeof(dw_porter); | |
162 } | |
163 | |
23638
1c50f12b1c52
2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents:
23051
diff
changeset
|
164 gint qq_putIP(guint8* buf, struct in_addr *ip) |
1c50f12b1c52
2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents:
23051
diff
changeset
|
165 { |
1c50f12b1c52
2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents:
23051
diff
changeset
|
166 memcpy(buf, ip, sizeof(struct in_addr)); |
1c50f12b1c52
2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents:
23051
diff
changeset
|
167 return sizeof(struct in_addr); |
1c50f12b1c52
2008.08.02 - csyfek <csyfek(at)gmail.com>
SHiNE CsyFeK <csyfek@gmail.com>
parents:
23051
diff
changeset
|
168 } |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
169 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
170 /* pack datalen bytes into buf |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
171 * return the number of bytes packed, otherwise return -1 */ |
23050 | 172 gint qq_putdata(guint8 *buf, const guint8 *data, const int datalen) |
23048 | 173 { |
174 memcpy(buf, data, datalen); | |
23050 | 175 #ifdef PARSER_DEBUG |
23878
967344bc404d
applied changes from f12c8903079425d7850fa183df0b3f937b2952be
SHiNE CsyFeK <csyfek@gmail.com>
parents:
23638
diff
changeset
|
176 purple_debug_info("QQ", "[DBG][putdata] buf %p\n", (void *)buf); |
23050 | 177 #endif |
23048 | 178 return datalen; |
179 } |