comparison libpurple/protocols/qq/utils.c @ 23754: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 5f454b975a99
children bcfc98c7a55f
comparison
equal deleted inserted replaced
23753:5f454b975a99 23754:967344bc404d
45 /* 45 /*
46 static void _qq_show_socket(gchar *desc, gint fd) { 46 static void _qq_show_socket(gchar *desc, gint fd) {
47 struct sockaddr_in sin; 47 struct sockaddr_in sin;
48 socklen_t len = sizeof(sin); 48 socklen_t len = sizeof(sin);
49 getsockname(fd, (struct sockaddr *)&sin, &len); 49 getsockname(fd, (struct sockaddr *)&sin, &len);
50 purple_debug(PURPLE_DEBUG_INFO, desc, "%s:%d\n", 50 purple_debug_info(desc, "%s:%d\n",
51 inet_ntoa(sin.sin_addr), g_ntohs(sin.sin_port)); 51 inet_ntoa(sin.sin_addr), g_ntohs(sin.sin_port));
52 } 52 }
53 */ 53 */
54 54
55 void qq_get_md5(guint8 *md5, gint md5_len, const guint8* const src, gint src_len) 55 void qq_get_md5(guint8 *md5, gint md5_len, const guint8* const src, gint src_len)
56 { 56 {
119 return segments; 119 return segments;
120 120
121 for (i = 0; segments[i] != NULL; i++) {; 121 for (i = 0; segments[i] != NULL; i++) {;
122 } 122 }
123 if (i < expected_fields) { /* not enough fields */ 123 if (i < expected_fields) { /* not enough fields */
124 purple_debug(PURPLE_DEBUG_ERROR, "QQ", 124 purple_debug_error("QQ", "Invalid data, expect %d fields, found only %d, discard\n",
125 "Invalid data, expect %d fields, found only %d, discard\n", expected_fields, i); 125 expected_fields, i);
126 g_strfreev(segments); 126 g_strfreev(segments);
127 return NULL; 127 return NULL;
128 } else if (i > expected_fields) { /* more fields, OK */ 128 } else if (i > expected_fields) { /* more fields, OK */
129 purple_debug(PURPLE_DEBUG_WARNING, "QQ", 129 purple_debug_warning("QQ", "Dangerous data, expect %d fields, found %d, return all\n",
130 "Dangerous data, expect %d fields, found %d, return all\n", expected_fields, i); 130 expected_fields, i);
131 /* free up those not used */ 131 /* free up those not used */
132 for (j = expected_fields; j < i; j++) { 132 for (j = expected_fields; j < i; j++) {
133 purple_debug(PURPLE_DEBUG_WARNING, "QQ", "field[%d] is %s\n", j, segments[j]); 133 purple_debug_warning("QQ", "field[%d] is %s\n", j, segments[j]);
134 g_free(segments[j]); 134 g_free(segments[j]);
135 } 135 }
136 136
137 segments[expected_fields] = NULL; 137 segments[expected_fields] = NULL;
138 } 138 }
216 break; 216 break;
217 217
218 msg_utf8 = i < len ? qq_to_utf8((gchar *) &incoming[i], QQ_CHARSET_DEFAULT) : NULL; 218 msg_utf8 = i < len ? qq_to_utf8((gchar *) &incoming[i], QQ_CHARSET_DEFAULT) : NULL;
219 219
220 if (msg_utf8 != NULL) { 220 if (msg_utf8 != NULL) {
221 purple_debug(PURPLE_DEBUG_WARNING, "QQ", "Try extract GB msg: %s\n", msg_utf8); 221 purple_debug_warning("QQ", "Try extract GB msg: %s\n", msg_utf8);
222 } 222 }
223 return msg_utf8; 223 return msg_utf8;
224 } 224 }
225 225
226 /* strips whitespace */ 226 /* strips whitespace */
255 g_return_val_if_fail(buffer != NULL, NULL); 255 g_return_val_if_fail(buffer != NULL, NULL);
256 256
257 hex_buffer = strstrip(buffer); 257 hex_buffer = strstrip(buffer);
258 258
259 if (strlen(hex_buffer) % 2 != 0) { 259 if (strlen(hex_buffer) % 2 != 0) {
260 purple_debug(PURPLE_DEBUG_WARNING, "QQ", 260 purple_debug_warning("QQ",
261 "Unable to convert an odd number of nibbles to a string of bytes!\n"); 261 "Unable to convert an odd number of nibbles to a string of bytes!\n");
262 g_free(hex_buffer); 262 g_free(hex_buffer);
263 return NULL; 263 return NULL;
264 } 264 }
265 bytes = g_newa(guint8, strlen(hex_buffer) / 2); 265 bytes = g_newa(guint8, strlen(hex_buffer) / 2);
270 if (g_ascii_isdigit(*cursor)) { 270 if (g_ascii_isdigit(*cursor)) {
271 tmp = *cursor; nibble1 = atoi(&tmp); 271 tmp = *cursor; nibble1 = atoi(&tmp);
272 } else if (g_ascii_isalpha(*cursor) && (gint) *cursor - 87 < 16) { 272 } else if (g_ascii_isalpha(*cursor) && (gint) *cursor - 87 < 16) {
273 nibble1 = (gint) *cursor - 87; 273 nibble1 = (gint) *cursor - 87;
274 } else { 274 } else {
275 purple_debug(PURPLE_DEBUG_WARNING, "QQ", 275 purple_debug_warning("QQ", "Invalid char \'%c\' found in hex string!\n",
276 "Invalid char \'%c\' found in hex string!\n", *cursor); 276 *cursor);
277 g_free(hex_str); 277 g_free(hex_str);
278 return NULL; 278 return NULL;
279 } 279 }
280 nibble1 = nibble1 << 4; 280 nibble1 = nibble1 << 4;
281 cursor++; 281 cursor++;
282 if (g_ascii_isdigit(*cursor)) { 282 if (g_ascii_isdigit(*cursor)) {
283 tmp = *cursor; nibble2 = atoi(&tmp); 283 tmp = *cursor; nibble2 = atoi(&tmp);
284 } else if (g_ascii_isalpha(*cursor) && (gint) (*cursor - 87) < 16) { 284 } else if (g_ascii_isalpha(*cursor) && (gint) (*cursor - 87) < 16) {
285 nibble2 = (gint) *cursor - 87; 285 nibble2 = (gint) *cursor - 87;
286 } else { 286 } else {
287 purple_debug(PURPLE_DEBUG_WARNING, "QQ", 287 purple_debug_warning("QQ", "Invalid char found in hex string!\n");
288 "Invalid char found in hex string!\n");
289 g_free(hex_str); 288 g_free(hex_str);
290 return NULL; 289 return NULL;
291 } 290 }
292 bytes[index++] = nibble1 + nibble2; 291 bytes[index++] = nibble1 + nibble2;
293 } 292 }
360 g_free(phex); 359 g_free(phex);
361 } 360 }
362 361
363 void qq_show_packet(const gchar *desc, const guint8 *buf, gint len) 362 void qq_show_packet(const gchar *desc, const guint8 *buf, gint len)
364 { 363 {
365 /* 364 qq_hex_dump(PURPLE_DEBUG_INFO, "QQ", buf, len, desc);
366 char buf1[8*len+2], buf2[10];
367 int i;
368 buf1[0] = 0;
369 for (i = 0; i < len; i++) {
370 sprintf(buf2, " %02x(%d)", buf[i] & 0xff, buf[i] & 0xff);
371 strcat(buf1, buf2);
372 }
373 strcat(buf1, "\n");
374 purple_debug(PURPLE_DEBUG_INFO, desc, "%s", buf1);
375 */
376
377 /* modified by s3e, 20080424 */
378 qq_hex_dump(PURPLE_DEBUG_INFO, desc,
379 buf, len,
380 "");
381 } 365 }
382 366
383 /* convert face num from packet (0-299) to local face (1-100) */ 367 /* convert face num from packet (0-299) to local face (1-100) */
384 gchar *face_to_icon_str(gint face) 368 gchar *face_to_icon_str(gint face)
385 { 369 {