pidgin.2.4.3: 1ee6cc25: patch-03-add-qq_hex_dump
csyfek at gmail.com
csyfek at gmail.com
Tue Jun 24 08:40:44 EDT 2008
-----------------------------------------------------------------
Revision: 1ee6cc253824c05fec211e0416e8bb5391278fa9
Ancestor: 63af192c8f63b2cb283c36e92bd72343a85b0424
Author: csyfek at gmail.com
Date: 2008-06-24T12:09:16
Branch: im.pidgin.pidgin.2.4.3
URL: http://d.pidgin.im/viewmtn/revision/info/1ee6cc253824c05fec211e0416e8bb5391278fa9
Added files:
libpurple/protocols/qq/ChangeLog
Modified files:
libpurple/protocols/qq/char_conv.c
libpurple/protocols/qq/file_trans.c
libpurple/protocols/qq/group_im.c
libpurple/protocols/qq/group_network.c
libpurple/protocols/qq/im.c
libpurple/protocols/qq/login_logout.c
libpurple/protocols/qq/packet_parse.c
libpurple/protocols/qq/qq_proxy.c
libpurple/protocols/qq/recv_core.c
libpurple/protocols/qq/utils.c
libpurple/protocols/qq/utils.h
ChangeLog:
patch-03-add-qq_hex_dump
-------------- next part --------------
============================================================
--- libpurple/protocols/qq/ChangeLog 74834c1fda007327cf685f705151dfa8c309b0b1
+++ libpurple/protocols/qq/ChangeLog 74834c1fda007327cf685f705151dfa8c309b0b1
@@ -0,0 +1,11 @@
+2008.05.05 - ccpaging <ecc_hy(at)hotmail.com>
+ * Add qq_hex_dump function
+
+2008.04.25 - ccpaging <ecc_hy(at)hotmail.com>, csyfek <csyfek(at)gmail.com>
+ * Rewrite read_packet and create_packet functions, use qq_put and qq_get functions instead
+ * New logic in accord with protocol models to handle packets, some related functions rewritten
+
+2008.03.24 - ccpaging <ecc_hy(at)hotmail.com>
+ * Remove qq_crypt function in crypt.c, use qq_crypt and qq_decrypt directly
+
+** since pidgin-2.4.0 ***
============================================================
--- libpurple/protocols/qq/char_conv.c bb9420fc5c51eeb7876a58d602d0cbd98a574ffb
+++ libpurple/protocols/qq/char_conv.c 8d6f5265c225bb6c8c9b2ae5d7834b9c7d2356c7
@@ -114,10 +114,12 @@ static gchar *_my_convert(const gchar *s
if (error == NULL)
return ret; /* conversion is OK */
else { /* conversion error */
- gchar *failed = hex_dump_to_str((guint8 *) str, (len == -1) ? strlen(str) : len);
purple_debug(PURPLE_DEBUG_ERROR, "QQ", "%s\n", error->message);
- purple_debug(PURPLE_DEBUG_WARNING, "QQ", "Dump failed text\n%s", failed);
- g_free(failed);
+
+ qq_hex_dump(PURPLE_DEBUG_WARNING, "QQ",
+ (guint8 *) str, (len == -1) ? strlen(str) : len,
+ "Dump failed text");
+
g_error_free(error);
return g_strdup(QQ_NULL_MSG);
}
============================================================
--- libpurple/protocols/qq/file_trans.c ab5bfa8d905cf4e857bc91bc323aad9c3c6b1f4f
+++ libpurple/protocols/qq/file_trans.c 9aa7babe032da796a32376265d7578f157f5bd22
@@ -293,7 +293,6 @@ void qq_send_file_ctl_packet(PurpleConne
guint8 *raw_data, *encrypted_data;
time_t now;
ft_info *info;
- gchar *hex_dump;
qd = (qq_data *) gc->proto_data;
info = (ft_info *) qd->xfer->data;
@@ -355,9 +354,9 @@ void qq_send_file_ctl_packet(PurpleConne
return;
}
- hex_dump = hex_dump_to_str(raw_data, bytes);
- purple_debug(PURPLE_DEBUG_INFO, "QQ", "sending packet[%s]: \n%s", qq_get_file_cmd_desc(packet_type), hex_dump);
- g_free(hex_dump);
+ qq_hex_dump(PURPLE_DEBUG_INFO, "QQ",
+ raw_data, bytes,
+ "sending packet[%s]:", qq_get_file_cmd_desc(packet_type));
encrypted_len = bytes + 16;
encrypted_data = g_newa(guint8, encrypted_len);
@@ -531,7 +530,6 @@ static void _qq_process_recv_file_ctl_pa
guint16 seq;
guint8 hellobyte;
ft_info *info = (ft_info *) qd->xfer->data;
- gchar *hex_dump;
bytes = 0;
bytes += _qq_get_file_header(&fh, data + bytes);
@@ -551,9 +549,9 @@ static void _qq_process_recv_file_ctl_pa
decryped_bytes += 4+1+1+19+1; /* skip something */
purple_debug(PURPLE_DEBUG_INFO, "QQ", "==> [%d] receive %s packet\n", seq, qq_get_file_cmd_desc(packet_type));
- hex_dump = hex_dump_to_str(decrypted_data, decrypted_len);
- purple_debug(PURPLE_DEBUG_INFO, "QQ", "decrypted control packet received: \n%s", hex_dump);
- g_free(hex_dump);
+ qq_hex_dump(PURPLE_DEBUG_INFO, "QQ",
+ decrypted_data, decrypted_len,
+ "decrypted control packet received:");
switch (packet_type) {
case QQ_FILE_CMD_NOTIFY_IP_ACK:
============================================================
--- libpurple/protocols/qq/group_im.c 86b5edef1465b499551a6c5a09071eb9436c815d
+++ libpurple/protocols/qq/group_im.c 78175de05126d2650ef372a672f84bb81ec6e833
@@ -294,7 +294,7 @@ void qq_process_recv_group_im(guint8 *da
/* recv an IM from a group chat */
void qq_process_recv_group_im(guint8 *data, gint data_len, guint32 internal_group_id, PurpleConnection *gc, guint16 im_type)
{
- gchar *msg_with_purple_smiley, *msg_utf8_encoded, *im_src_name, *hex_dump;
+ gchar *msg_with_purple_smiley, *msg_utf8_encoded, *im_src_name;
guint16 unknown;
guint32 unknown4;
PurpleConversation *conv;
@@ -311,8 +311,9 @@ void qq_process_recv_group_im(guint8 *da
qd = (qq_data *) gc->proto_data;
- hex_dump = hex_dump_to_str(data, data_len);
- purple_debug(PURPLE_DEBUG_INFO, "QQ", "group im hex dump\n%s\n", hex_dump);
+ qq_hex_dump(PURPLE_DEBUG_INFO, "QQ",
+ data, data_len,
+ "group im hex dump");
im_group = g_newa(qq_recv_group_im, 1);
@@ -393,7 +394,6 @@ void qq_process_recv_group_im(guint8 *da
(conv)), im_src_name, 0, msg_utf8_encoded, im_group->send_time);
g_free(im_src_name);
}
- g_free(hex_dump);
g_free(msg_with_purple_smiley);
g_free(msg_utf8_encoded);
g_free(im_group->msg);
============================================================
--- libpurple/protocols/qq/group_network.c 40eb155ba5274bc1a2bd02b2dc8f58a9b38d4677
+++ libpurple/protocols/qq/group_network.c 3fafccf0c35fd48708f3d338cc64099df102798b
@@ -98,12 +98,11 @@ static void _qq_process_group_cmd_reply_
/* default process, dump only */
static void _qq_process_group_cmd_reply_default(guint8 *data, gint len, PurpleConnection *gc)
{
- gchar *hex_dump;
g_return_if_fail(data != NULL && len > 0);
- hex_dump = hex_dump_to_str(data, len);
- purple_debug(PURPLE_DEBUG_INFO, "QQ", "Dump unprocessed group cmd reply:\n%s", hex_dump);
- g_free(hex_dump);
+ qq_hex_dump(PURPLE_DEBUG_INFO, "QQ",
+ data, len,
+ "Dump unprocessed group cmd reply:");
}
/* The lower layer command of send group cmd */
============================================================
--- libpurple/protocols/qq/im.c be7396fb76d987d1270293fed855a1f6e50c310d
+++ libpurple/protocols/qq/im.c e670e2d144edd9eb3d861492771bc0f36b9d2cd9
@@ -340,7 +340,6 @@ static void _qq_process_recv_normal_im(g
gint bytes = 0;
qq_recv_normal_im_common *common;
qq_recv_normal_im_unprocessed *im_unprocessed;
- gchar *hex_dump;
g_return_if_fail (data != NULL && len != 0);
@@ -389,9 +388,9 @@ static void _qq_process_recv_normal_im(g
purple_debug (PURPLE_DEBUG_WARNING, "QQ",
"Normal IM, unprocessed type [0x%04x]\n",
common->normal_im_type);
- hex_dump = hex_dump_to_str(im_unprocessed->unknown, im_unprocessed->length);
- purple_debug (PURPLE_DEBUG_WARNING, "QQ", "Dump unknown part.\n%s", hex_dump);
- g_free(hex_dump);
+ purple_debug (PURPLE_DEBUG_WARNING, "QQ",
+ im_unprocessed->unknown, im_unprocessed->length,
+ "Dump unknown part.");
g_free (common->session_md5);
return;
}
============================================================
--- libpurple/protocols/qq/login_logout.c 55dd20dfcfdda178a2d2ebdf9b2a10e9b2a45ae3
+++ libpurple/protocols/qq/login_logout.c 04590221b4bd53171616bee7c3df9094bdfa8cad
@@ -385,7 +385,6 @@ void qq_process_request_login_token_repl
void qq_process_request_login_token_reply(guint8 *buf, gint buf_len, PurpleConnection *gc)
{
qq_data *qd;
- gchar *hex_dump;
g_return_if_fail(buf != NULL && buf_len != 0);
@@ -398,20 +397,18 @@ void qq_process_request_login_token_repl
purple_debug(PURPLE_DEBUG_INFO, "QQ",
"Attempting to proceed with the actual packet length.\n");
}
- hex_dump = hex_dump_to_str(buf+2, buf_len-2);
- purple_debug(PURPLE_DEBUG_INFO, "QQ",
- "<<< got a token with %d bytes -> [default] decrypt and dump\n%s", buf_len-2, hex_dump);
+ qq_hex_dump(PURPLE_DEBUG_INFO, "QQ",
+ buf+2, buf_len-2,
+ "<<< got a token -> [default] decrypt and dump");
qq_send_packet_login(gc, buf_len-2, buf+2);
} else {
purple_debug(PURPLE_DEBUG_ERROR, "QQ", "Unknown request login token reply code : %d\n", buf[0]);
- hex_dump = hex_dump_to_str(buf, buf_len);
- purple_debug(PURPLE_DEBUG_WARNING, "QQ",
- ">>> %d bytes -> [default] decrypt and dump\n%s",
- buf_len, hex_dump);
+ qq_hex_dump(PURPLE_DEBUG_WARNING, "QQ",
+ buf, buf_len,
+ ">>> [default] decrypt and dump");
try_dump_as_gbk(buf, buf_len);
purple_connection_error_reason(gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, _("Error requesting login token"));
}
- g_free(hex_dump);
}
/* send logout packets to QQ server */
@@ -433,7 +430,6 @@ void qq_process_login_reply(guint8 *buf,
gint len, ret, bytes;
guint8 *data;
qq_data *qd;
- gchar *hex_dump;
g_return_if_fail(buf != NULL && buf_len != 0);
@@ -466,11 +462,9 @@ void qq_process_login_reply(guint8 *buf,
break;
default:
purple_debug(PURPLE_DEBUG_ERROR, "QQ", "Unknown reply code: %d\n", data[0]);
- hex_dump = hex_dump_to_str(data, len);
- purple_debug(PURPLE_DEBUG_WARNING, "QQ",
- ">>> %d bytes -> [default] decrypt and dump\n%s",
- buf_len, hex_dump);
- g_free(hex_dump);
+ qq_hex_dump(PURPLE_DEBUG_WARNING, "QQ",
+ data, len,
+ ">>> [default] decrypt and dump");
try_dump_as_gbk(data, len);
ret = QQ_LOGIN_REPLY_MISC_ERROR;
============================================================
--- libpurple/protocols/qq/packet_parse.c c29950de5842e68b3c67a492387842cc8fe987c0
+++ libpurple/protocols/qq/packet_parse.c 9bcbaef736ee2464e3caa9485916bafdb3aa2694
@@ -81,7 +81,7 @@ gint qq_get8(guint8 *b, guint8 *buf)
guint8 b_dest;
memcpy(&b_dest, buf, sizeof(b_dest));
*b = b_dest;
- purple_debug(PURPLE_DEBUG_ERROR, "QQ", "[DBG][get8] buf %d\n", (void *)buf);
+ purple_debug(PURPLE_DEBUG_ERROR, "QQ", "[DBG][get8] buf %lu\n", (void *)buf);
purple_debug(PURPLE_DEBUG_ERROR, "QQ", "[DBG][get8] b_dest 0x%2x, *b 0x%02x\n", b_dest, *b);
return sizeof(b_dest);
}
@@ -135,7 +135,7 @@ gint qq_get16(guint16 *w, guint8 *buf)
guint16 w_dest;
memcpy(&w_dest, buf, sizeof(w_dest));
*w = g_ntohs(w_dest);
- purple_debug(PURPLE_DEBUG_ERROR, "QQ", "[DBG][get16] buf %d\n", (void *)buf);
+ purple_debug(PURPLE_DEBUG_ERROR, "QQ", "[DBG][get16] buf %lu\n", (void *)buf);
purple_debug(PURPLE_DEBUG_ERROR, "QQ", "[DBG][get16] w_dest 0x%04x, *w 0x%04x\n", w_dest, *w);
return sizeof(w_dest);
}
@@ -183,7 +183,7 @@ gint qq_get32(guint32 *dw, guint8 *buf)
guint32 dw_dest;
memcpy(&dw_dest, buf, sizeof(dw_dest));
*dw = g_ntohl(dw_dest);
- purple_debug(PURPLE_DEBUG_ERROR, "QQ", "[DBG][get32] buf %d\n", (void *)buf);
+ purple_debug(PURPLE_DEBUG_ERROR, "QQ", "[DBG][get32] buf %lu\n", (void *)buf);
purple_debug(PURPLE_DEBUG_ERROR, "QQ", "[DBG][get32] dw_dest 0x%08x, *dw 0x%08x\n", dw_dest, *dw);
return sizeof(dw_dest);
}
@@ -214,7 +214,7 @@ gint qq_getdata(guint8 *data, gint datal
gint qq_getdata(guint8 *data, gint datalen, guint8 *buf)
{
memcpy(data, buf, datalen);
- purple_debug(PURPLE_DEBUG_ERROR, "QQ", "[DBG][getdata] buf %d\n", (void *)buf);
+ purple_debug(PURPLE_DEBUG_ERROR, "QQ", "[DBG][getdata] buf %lu\n", (void *)buf);
return datalen;
}
@@ -237,7 +237,7 @@ gint qq_getime(time_t *t, guint8 *buf)
{
guint32 dw_dest;
memcpy(&dw_dest, buf, sizeof(dw_dest));
- purple_debug(PURPLE_DEBUG_ERROR, "QQ", "[DBG][getime] buf %d\n", (void *)buf);
+ purple_debug(PURPLE_DEBUG_ERROR, "QQ", "[DBG][getime] buf %lu\n", (void *)buf);
purple_debug(PURPLE_DEBUG_ERROR, "QQ", "[DBG][getime] dw_dest before 0x%08x\n", dw_dest);
dw_dest = g_ntohl(dw_dest);
purple_debug(PURPLE_DEBUG_ERROR, "QQ", "[DBG][getime] dw_dest after 0x%08x\n", dw_dest);
@@ -282,7 +282,7 @@ gint qq_put8(guint8 *buf, guint8 b)
gint qq_put8(guint8 *buf, guint8 b)
{
memcpy(buf, &b, sizeof(b));
- purple_debug(PURPLE_DEBUG_ERROR, "QQ", "[DBG][put8] buf %d\n", (void *)buf);
+ purple_debug(PURPLE_DEBUG_ERROR, "QQ", "[DBG][put8] buf %lu\n", (void *)buf);
purple_debug(PURPLE_DEBUG_ERROR, "QQ", "[DBG][put8] b 0x%02x\n", b);
return sizeof(b);
}
@@ -327,7 +327,7 @@ gint qq_put16(guint8 *buf, guint16 w)
{
guint16 w_porter;
w_porter = g_htons(w);
- purple_debug(PURPLE_DEBUG_ERROR, "QQ", "[DBG][put16] buf %d\n", (void *)buf);
+ purple_debug(PURPLE_DEBUG_ERROR, "QQ", "[DBG][put16] buf %lu\n", (void *)buf);
purple_debug(PURPLE_DEBUG_ERROR, "QQ", "[DBG][put16] w 0x%04x, w_porter 0x%04x\n", w, w_porter);
memcpy(buf, &w_porter, sizeof(w_porter));
return sizeof(w_porter);
@@ -370,7 +370,7 @@ gint qq_put32(guint8 *buf, guint32 dw)
{
guint32 dw_porter;
dw_porter = g_htonl(dw);
- purple_debug(PURPLE_DEBUG_ERROR, "QQ", "[DBG][put32] buf %d\n", (void *)buf);
+ purple_debug(PURPLE_DEBUG_ERROR, "QQ", "[DBG][put32] buf %lu\n", (void *)buf);
purple_debug(PURPLE_DEBUG_ERROR, "QQ", "[DBG][put32] dw 0x%08x, dw_porter 0x%08x\n", dw, dw_porter);
memcpy(buf, &dw_porter, sizeof(dw_porter));
return sizeof(dw_porter);
@@ -404,7 +404,7 @@ gint qq_putdata(guint8 *buf, guint8 *dat
gint qq_putdata(guint8 *buf, guint8 *data, const int datalen)
{
memcpy(buf, data, datalen);
- purple_debug(PURPLE_DEBUG_ERROR, "QQ", "[DBG][putdata] buf %d\n", (void *)buf);
+ purple_debug(PURPLE_DEBUG_ERROR, "QQ", "[DBG][putdata] buf %lu\n", (void *)buf);
return datalen;
}
============================================================
--- libpurple/protocols/qq/qq_proxy.c 9912b5e748492d1452b8d85612860e1dd4d80bb1
+++ libpurple/protocols/qq/qq_proxy.c 6e9bb7d45399042a525047fdbb6d73ae1a54f972
@@ -70,9 +70,9 @@ void _qq_show_packet(const gchar *desc,
*/
/* modified by s3e, 20080424 */
- gchar *packet_dump = hex_dump_to_str(buf, len);
- purple_debug(PURPLE_DEBUG_INFO, desc, "\n%s\n", packet_dump);
- g_free(packet_dump);
+ qq_hex_dump(PURPLE_DEBUG_INFO, desc,
+ buf, len,
+ "");
}
/* QQ 2003iii uses double MD5 for the pwkey to get the session key */
============================================================
--- libpurple/protocols/qq/recv_core.c 75b620ec94f55d660b640f10dbf23fcc96c93c4a
+++ libpurple/protocols/qq/recv_core.c 9eeca2303acbad41339962379b6063be82878d14
@@ -92,11 +92,10 @@ static void _qq_process_packet_default(g
_qq_show_packet("Processing unknown packet", buf, len);
if (qq_decrypt(buf, buf_len, qd->session_key, data, &len)) {
- gchar *hex_dump = hex_dump_to_str(data, len);
- purple_debug(PURPLE_DEBUG_WARNING, "QQ",
- ">>> [%d] %s, %d bytes -> [default] decrypt and dump\n%s",
- seq, qq_get_cmd_desc(cmd), buf_len, hex_dump);
- g_free(hex_dump);
+ qq_hex_dump(PURPLE_DEBUG_WARNING, "QQ",
+ data, len,
+ ">>> [%d] %s -> [default] decrypt and dump",
+ seq, qq_get_cmd_desc(cmd));
try_dump_as_gbk(data, len);
} else {
purple_debug(PURPLE_DEBUG_ERROR, "QQ", "Fail decrypt packet with default process\n");
@@ -118,10 +117,9 @@ static void _qq_packet_process(guint8 *b
bytes_expected = qd->use_tcp ? QQ_TCP_HEADER_LENGTH : QQ_UDP_HEADER_LENGTH;
if (buf_len < bytes_expected) {
- gchar *hex_dump = hex_dump_to_str(buf, buf_len);
- purple_debug(PURPLE_DEBUG_ERROR,
- "QQ", "Received packet is too short, dump and drop\n%s", hex_dump);
- g_free(hex_dump);
+ qq_hex_dump(PURPLE_DEBUG_ERROR, "QQ",
+ buf, buf_len,
+ "Received packet is too short, dump and drop");
return;
}
@@ -153,10 +151,9 @@ static void _qq_packet_process(guint8 *b
}
if ((buf[buf_len - 1] != QQ_PACKET_TAIL) || (header.header_tag != QQ_PACKET_TAG)) {
- gchar *hex_dump = hex_dump_to_str(buf, buf_len);
- purple_debug(PURPLE_DEBUG_ERROR,
- "QQ", "Unknown QQ proctocol, dump and drop\n%s", hex_dump);
- g_free(hex_dump);
+ qq_hex_dump(PURPLE_DEBUG_ERROR, "QQ",
+ buf, buf_len,
+ "Unknown QQ proctocol, dump and drop");
return;
}
============================================================
--- libpurple/protocols/qq/utils.c b63ddf3a000048d481cb6b56fe0f035bce538c28
+++ libpurple/protocols/qq/utils.c e59b26e6b4b9683e8a161cef8dbe81c5da935e5f
@@ -294,7 +294,7 @@ guint8 *hex_str_to_bytes(const gchar *co
/* Dumps a chunk of raw data into an ASCII hex string.
* The return should be freed later. */
-gchar *hex_dump_to_str(const guint8 *const buffer, gint bytes)
+static gchar *hex_dump_to_str(const guint8 *const buffer, gint bytes)
{
GString *str;
gchar *ret;
@@ -331,6 +331,31 @@ gchar *hex_dump_to_str(const guint8 *con
return ret;
}
+void qq_hex_dump(PurpleDebugLevel level, const char *category,
+ const guint8 *pdata, gint bytes,
+ const char *format, ...)
+{
+ va_list args;
+ char *arg_s = NULL;
+ gchar *phex = NULL;
+
+ g_return_if_fail(level != PURPLE_DEBUG_ALL);
+ g_return_if_fail(format != NULL);
+
+ va_start(args, format);
+ arg_s = g_strdup_vprintf(format, args);
+ va_end(args);
+
+ if (bytes <= 0) {
+ purple_debug(level, category, arg_s);
+ return;
+ }
+
+ phex = hex_dump_to_str(pdata, bytes);
+ purple_debug(level, category, "%s - (len %d)\n%s", arg_s, bytes, phex);
+ g_free(phex);
+}
+
/* convert face num from packet (0-299) to local face (1-100) */
gchar *face_to_icon_str(gint face)
{
============================================================
--- libpurple/protocols/qq/utils.h 2fe54f528abae61a305fad9f316b97aa8ee41721
+++ libpurple/protocols/qq/utils.h 234f20c24b8ffe74a312c2fede83156f9740cbc1
@@ -28,6 +28,8 @@
#include <stdio.h>
#include <glib.h>
+#include "debug.h"
+
gchar *get_name_by_index_str(gchar **array, const gchar *index_str, gint amount);
gchar *get_index_str_by_name(gchar **array, const gchar *name, gint amount);
gint qq_string_to_dec_value(const gchar *str);
@@ -46,8 +48,10 @@ void try_dump_as_gbk(const guint8 *const
void try_dump_as_gbk(const guint8 *const data, gint len);
+void qq_hex_dump(PurpleDebugLevel level, const char *category,
+ const guint8 *pdata, gint bytes,
+ const char *format, ...);
guint8 *hex_str_to_bytes(const gchar *buf, gint *out_len);
-gchar *hex_dump_to_str(const guint8 *buf, gint buf_len);
const gchar *qq_buddy_icon_dir(void);
const gchar *qq_win32_buddy_icon_dir(void);
More information about the Commits
mailing list