comparison libpurple/protocols/qq/utils.c @ 23052:51dbe83ebbd3

patch-04-tcp-pending
author SHiNE CsyFeK <csyfek@gmail.com>
date Tue, 24 Jun 2008 12:22:40 +0000
parents 190bc4ecf6c3
children 55f986ccbb6a
comparison
equal deleted inserted replaced
23051:190bc4ecf6c3 23052:51dbe83ebbd3
20 * You should have received a copy of the GNU General Public License 20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software 21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA 22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
23 */ 23 */
24 24
25 #include "cipher.h"
26 #include "limits.h" 25 #include "limits.h"
27 #include "stdlib.h" 26 #include "stdlib.h"
28 #include "string.h" 27 #include "string.h"
29 28
30 #ifdef _WIN32 29 #ifdef _WIN32
111 } 110 }
112 111
113 return segments; 112 return segments;
114 } 113 }
115 114
116 /* generate a md5 key using uid and session_key */
117 guint8 *_gen_session_md5(gint uid, guint8 *session_key)
118 {
119 guint8 *src, md5_str[QQ_KEY_LENGTH];
120 PurpleCipher *cipher;
121 PurpleCipherContext *context;
122
123 src = g_newa(guint8, 20);
124 memcpy(src, &uid, 4);
125 memcpy(src, session_key, QQ_KEY_LENGTH);
126
127 cipher = purple_ciphers_find_cipher("md5");
128 context = purple_cipher_context_new(cipher, NULL);
129 purple_cipher_context_append(context, src, 20);
130 purple_cipher_context_digest(context, sizeof(md5_str), md5_str, NULL);
131 purple_cipher_context_destroy(context);
132
133 return g_memdup(md5_str, QQ_KEY_LENGTH);
134 }
135
136 /* given a four-byte ip data, convert it into a human readable ip string 115 /* given a four-byte ip data, convert it into a human readable ip string
137 * the return needs to be freed */ 116 * the return needs to be freed */
138 gchar *gen_ip_str(guint8 *ip) 117 gchar *gen_ip_str(guint8 *ip)
139 { 118 {
140 gchar *ret; 119 gchar *ret;
192 171
193 return ret; 172 return ret;
194 } 173 }
195 174
196 /* try to dump the data as GBK */ 175 /* try to dump the data as GBK */
197 void try_dump_as_gbk(const guint8 *const data, gint len) 176 gchar* try_dump_as_gbk(const guint8 *const data, gint len)
198 { 177 {
199 gint i; 178 gint i;
200 guint8 *incoming; 179 guint8 *incoming;
201 gchar *msg_utf8; 180 gchar *msg_utf8;
202 181
213 192
214 msg_utf8 = i < len ? qq_to_utf8((gchar *) &incoming[i], QQ_CHARSET_DEFAULT) : NULL; 193 msg_utf8 = i < len ? qq_to_utf8((gchar *) &incoming[i], QQ_CHARSET_DEFAULT) : NULL;
215 194
216 if (msg_utf8 != NULL) { 195 if (msg_utf8 != NULL) {
217 purple_debug(PURPLE_DEBUG_WARNING, "QQ", "Try extract GB msg: %s\n", msg_utf8); 196 purple_debug(PURPLE_DEBUG_WARNING, "QQ", "Try extract GB msg: %s\n", msg_utf8);
218 g_free(msg_utf8); 197 }
219 } 198 return msg_utf8;
220 } 199 }
221 200
222 /* strips whitespace */ 201 /* strips whitespace */
223 static gchar *strstrip(const gchar *const buffer) 202 static gchar *strstrip(const gchar *const buffer)
224 { 203 {
354 phex = hex_dump_to_str(pdata, bytes); 333 phex = hex_dump_to_str(pdata, bytes);
355 purple_debug(level, category, "%s - (len %d)\n%s", arg_s, bytes, phex); 334 purple_debug(level, category, "%s - (len %d)\n%s", arg_s, bytes, phex);
356 g_free(phex); 335 g_free(phex);
357 } 336 }
358 337
338 void qq_show_packet(const gchar *desc, const guint8 *buf, gint len)
339 {
340 /*
341 char buf1[8*len+2], buf2[10];
342 int i;
343 buf1[0] = 0;
344 for (i = 0; i < len; i++) {
345 sprintf(buf2, " %02x(%d)", buf[i] & 0xff, buf[i] & 0xff);
346 strcat(buf1, buf2);
347 }
348 strcat(buf1, "\n");
349 purple_debug(PURPLE_DEBUG_INFO, desc, "%s", buf1);
350 */
351
352 /* modified by s3e, 20080424 */
353 qq_hex_dump(PURPLE_DEBUG_INFO, desc,
354 buf, len,
355 "");
356 }
357
359 /* convert face num from packet (0-299) to local face (1-100) */ 358 /* convert face num from packet (0-299) to local face (1-100) */
360 gchar *face_to_icon_str(gint face) 359 gchar *face_to_icon_str(gint face)
361 { 360 {
362 gchar *icon_num_str; 361 gchar *icon_num_str;
363 gint icon_num = face / 3 + 1; 362 gint icon_num = face / 3 + 1;