comparison libpurple/protocols/qq/utils.c @ 23683:1c50f12b1c52

2008.08.02 - csyfek <csyfek(at)gmail.com> * Commit to Pidgin * Tickets: Fixes #1861 Fixes #1902 References #5112 2008.08.02 - ccpaging <ecc_hy(at)hotmail.com> * Store all keys and md5 values of qq_data in char[QQ_KEY_LENGTH] * Use random value in inikey * TEA header padding in crypt.c * Rewrite login part of qq_process 2008.07.31 - ccpaging <ecc_hy(at)hotmail.com> * Fixed: send reply when get duplicate server command. The server may not get our reply before. * Tag custom picture as text "(Broken)" 2008.07.30 - ccpaging <ecc_hy(at)hotmail.com>, csyfek <csyfek(at)gmail.com> * Change some debug message * Modify buddy status flag according to eva for QQ2006 * Modify buddy status parse and correspond to eva2 * Add getIP/putIP functions to packet_parse.c, and replace some gen_ip_str * Replace guint32 *ip with struct in_addr, and reduce g_new/g_free operation * Source file changed: Merge buddy_status into buddy_list Change login_logout to qq_base Merge keep_alive into qq_base New qq_process extract from qq_network * Fixed: Byte alignment bug in crypt.c, tested in ARM PDA * Fixed: group chat message may get in before getting group info, and so group info is empty * Add qq_send_cmd_group_get_group_info when joined a group chat in group_im.c * Add some new group command identify according eva but further program * Add some new QQ client version identify * Fixed: Identify buddy's client version by IM packet, and not by status * Add some new info in buddy's tooltip text * Add video falg to buddy's emblem. But those flag in buddy status may not prasing correctly * Use new timeout function to handle send keep_alive, resend packet, update buddy status * Add new advanced options: The end user may change interval of keep_alive, resend packet, update buddy status to feed their need. For example, saving network flow when use mobile phone. Keep alive packet must be sent in 60-120 seconds whatever client rcved data of not. The intervals of keep alive and update status should be multiple of resend's interval, Since we use counter not time() in a single timeout function for efficiency. * Rewrite qq_trans.c, and use one g_list to manage: Store server packet before login, and prase all of them when get login Store client send packet for resend scanning, confirm server reply, filter duplicate server reply Store server packet for filter out duplicate * Add QQ_MSG_SYS_NOTICE = 0x06 in sys_msg.c * Rewrite qq_proc_cmd_reply and qq_proc_cmd_server: In QQ protocol, one packet reply may need a new packet send later. We may call it packet trigger. The triggers always is hided in every qq_process_reply. Now we try to extract those triggers and put into a single function, and then every trigger should be obviously and easy to manage.
author SHiNE CsyFeK <csyfek@gmail.com>
date Sat, 02 Aug 2008 15:00:46 +0000
parents ebad75b719f5
children 5f454b975a99
comparison
equal deleted inserted replaced
23682:21e591b55339 23683:1c50f12b1c52
28 28
29 #ifdef _WIN32 29 #ifdef _WIN32
30 #include "win32dep.h" 30 #include "win32dep.h"
31 #endif 31 #endif
32 32
33 #include "cipher.h"
34
33 #include "char_conv.h" 35 #include "char_conv.h"
34 #include "debug.h" 36 #include "debug.h"
35 #include "prefs.h" 37 #include "prefs.h"
36 #include "qq.h" 38 #include "qq.h"
37 #include "util.h" 39 #include "util.h"
48 purple_debug(PURPLE_DEBUG_INFO, desc, "%s:%d\n", 50 purple_debug(PURPLE_DEBUG_INFO, desc, "%s:%d\n",
49 inet_ntoa(sin.sin_addr), g_ntohs(sin.sin_port)); 51 inet_ntoa(sin.sin_addr), g_ntohs(sin.sin_port));
50 } 52 }
51 */ 53 */
52 54
55 void qq_get_md5(guint8 *md5, gint md5_len, const guint8* const src, gint src_len)
56 {
57 PurpleCipher *cipher;
58 PurpleCipherContext *context;
59
60 g_return_if_fail(md5 != NULL && md5_len > 0);
61 g_return_if_fail(src != NULL && src_len > 0);
62
63 cipher = purple_ciphers_find_cipher("md5");
64 context = purple_cipher_context_new(cipher, NULL);
65 purple_cipher_context_append(context, src, src_len);
66 purple_cipher_context_digest(context, md5_len, md5, NULL);
67 purple_cipher_context_destroy(context);
68 }
69
53 gchar *get_name_by_index_str(gchar **array, const gchar *index_str, gint amount) 70 gchar *get_name_by_index_str(gchar **array, const gchar *index_str, gint amount)
54 { 71 {
55 gint index; 72 gint index;
56 73
57 index = atoi(index_str); 74 index = atoi(index_str);
95 * we have to duplicate the data and append a 0x00 at the end */ 112 * we have to duplicate the data and append a 0x00 at the end */
96 input = g_newa(guint8, len + 1); 113 input = g_newa(guint8, len + 1);
97 g_memmove(input, data, len); 114 g_memmove(input, data, len);
98 input[len] = 0x00; 115 input[len] = 0x00;
99 116
100 segments = g_strsplit((gchar *) input, delimit, 0); 117 segments = g_strsplit_set((gchar *) input, delimit, 0);
101 if (expected_fields <= 0) 118 if (expected_fields <= 0)
102 return segments; 119 return segments;
103 120
104 for (i = 0; segments[i] != NULL; i++) {; 121 for (i = 0; segments[i] != NULL; i++) {;
105 } 122 }
121 } 138 }
122 139
123 return segments; 140 return segments;
124 } 141 }
125 142
126 /* given a four-byte ip data, convert it into a human readable ip string 143 /* convert Purple name to original QQ UID */
127 * the return needs to be freed */ 144 guint32 purple_name_to_uid(const gchar *const name)
128 gchar *gen_ip_str(guint8 *ip) 145 {
129 { 146 guint32 ret;
147 g_return_val_if_fail(name != NULL, 0);
148
149 ret = strtol(name, NULL, 10);
150 if (errno == ERANGE)
151 return 0;
152 else
153 return ret;
154 }
155
156 gchar *gen_ip_str(guint8 *ip) {
130 gchar *ret; 157 gchar *ret;
131 if (ip == NULL || ip[0] == 0) { 158 if (ip == NULL || ip[0] == 0) {
132 ret = g_new(gchar, 1); 159 ret = g_new(gchar, 1);
133 *ret = '\0'; 160 *ret = '\0';
134 return ret; 161 return ret;
145 ip[0] = a; 172 ip[0] = a;
146 ip[1] = b; 173 ip[1] = b;
147 ip[2] = c; 174 ip[2] = c;
148 ip[3] = d; 175 ip[3] = d;
149 return ip; 176 return ip;
150 }
151
152 /* convert Purple name to original QQ UID */
153 guint32 purple_name_to_uid(const gchar *const name)
154 {
155 guint32 ret;
156 g_return_val_if_fail(name != NULL, 0);
157
158 ret = strtol(name, NULL, 10);
159 if (errno == ERANGE)
160 return 0;
161 else
162 return ret;
163 } 177 }
164 178
165 /* convert a QQ UID to a unique name of Purple 179 /* convert a QQ UID to a unique name of Purple
166 * the return needs to be freed */ 180 * the return needs to be freed */
167 gchar *uid_to_purple_name(guint32 uid) 181 gchar *uid_to_purple_name(guint32 uid)