Mercurial > pidgin.yaz
comparison libpurple/protocols/qq/utils.c @ 15823:32c366eeeb99
sed -ie 's/gaim/purple/g'
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Mon, 19 Mar 2007 07:01:17 +0000 |
parents | 5fe8042783c1 |
children | 44b4e8bd759b |
comparison
equal
deleted
inserted
replaced
15822:84b0f9b23ede | 15823:32c366eeeb99 |
---|---|
1 /** | 1 /** |
2 * @file utils.c | 2 * @file utils.c |
3 * | 3 * |
4 * gaim | 4 * purple |
5 * | 5 * |
6 * Gaim is the legal property of its developers, whose names are too numerous | 6 * Purple is the legal property of its developers, whose names are too numerous |
7 * to list here. Please refer to the COPYRIGHT file distributed with this | 7 * to list here. Please refer to the COPYRIGHT file distributed with this |
8 * source distribution. | 8 * source distribution. |
9 * | 9 * |
10 * This program is free software; you can redistribute it and/or modify | 10 * This program is free software; you can redistribute it and/or modify |
11 * it under the terms of the GNU General Public License as published by | 11 * it under the terms of the GNU General Public License as published by |
92 return segments; | 92 return segments; |
93 | 93 |
94 for (i = 0; segments[i] != NULL; i++) {; | 94 for (i = 0; segments[i] != NULL; i++) {; |
95 } | 95 } |
96 if (i < expected_fields) { /* not enough fields */ | 96 if (i < expected_fields) { /* not enough fields */ |
97 gaim_debug(GAIM_DEBUG_ERROR, "QQ", | 97 purple_debug(PURPLE_DEBUG_ERROR, "QQ", |
98 "Invalid data, expect %d fields, found only %d, discard\n", expected_fields, i); | 98 "Invalid data, expect %d fields, found only %d, discard\n", expected_fields, i); |
99 g_strfreev(segments); | 99 g_strfreev(segments); |
100 return NULL; | 100 return NULL; |
101 } else if (i > expected_fields) { /* more fields, OK */ | 101 } else if (i > expected_fields) { /* more fields, OK */ |
102 gaim_debug(GAIM_DEBUG_WARNING, "QQ", | 102 purple_debug(PURPLE_DEBUG_WARNING, "QQ", |
103 "Dangerous data, expect %d fields, found %d, return all\n", expected_fields, i); | 103 "Dangerous data, expect %d fields, found %d, return all\n", expected_fields, i); |
104 /* free up those not used */ | 104 /* free up those not used */ |
105 for (j = expected_fields; j < i; j++) { | 105 for (j = expected_fields; j < i; j++) { |
106 gaim_debug(GAIM_DEBUG_WARNING, "QQ", "field[%d] is %s\n", j, segments[j]); | 106 purple_debug(PURPLE_DEBUG_WARNING, "QQ", "field[%d] is %s\n", j, segments[j]); |
107 g_free(segments[j]); | 107 g_free(segments[j]); |
108 } | 108 } |
109 | 109 |
110 segments[expected_fields] = NULL; | 110 segments[expected_fields] = NULL; |
111 } | 111 } |
115 | 115 |
116 /* generate a md5 key using uid and session_key */ | 116 /* generate a md5 key using uid and session_key */ |
117 guint8 *_gen_session_md5(gint uid, guint8 *session_key) | 117 guint8 *_gen_session_md5(gint uid, guint8 *session_key) |
118 { | 118 { |
119 guint8 *src, md5_str[QQ_KEY_LENGTH]; | 119 guint8 *src, md5_str[QQ_KEY_LENGTH]; |
120 GaimCipher *cipher; | 120 PurpleCipher *cipher; |
121 GaimCipherContext *context; | 121 PurpleCipherContext *context; |
122 | 122 |
123 src = g_newa(guint8, 20); | 123 src = g_newa(guint8, 20); |
124 memcpy(src, &uid, 4); | 124 memcpy(src, &uid, 4); |
125 memcpy(src, session_key, QQ_KEY_LENGTH); | 125 memcpy(src, session_key, QQ_KEY_LENGTH); |
126 | 126 |
127 cipher = gaim_ciphers_find_cipher("md5"); | 127 cipher = purple_ciphers_find_cipher("md5"); |
128 context = gaim_cipher_context_new(cipher, NULL); | 128 context = purple_cipher_context_new(cipher, NULL); |
129 gaim_cipher_context_append(context, src, 20); | 129 purple_cipher_context_append(context, src, 20); |
130 gaim_cipher_context_digest(context, sizeof(md5_str), md5_str, NULL); | 130 purple_cipher_context_digest(context, sizeof(md5_str), md5_str, NULL); |
131 gaim_cipher_context_destroy(context); | 131 purple_cipher_context_destroy(context); |
132 | 132 |
133 return g_memdup(md5_str, QQ_KEY_LENGTH); | 133 return g_memdup(md5_str, QQ_KEY_LENGTH); |
134 } | 134 } |
135 | 135 |
136 /* given a four-byte ip data, convert it into a human readable ip string | 136 /* given a four-byte ip data, convert it into a human readable ip string |
157 ip[2] = c; | 157 ip[2] = c; |
158 ip[3] = d; | 158 ip[3] = d; |
159 return ip; | 159 return ip; |
160 } | 160 } |
161 | 161 |
162 /* convert Gaim name to original QQ UID */ | 162 /* convert Purple name to original QQ UID */ |
163 guint32 gaim_name_to_uid(const gchar *const name) | 163 guint32 purple_name_to_uid(const gchar *const name) |
164 { | 164 { |
165 guint32 ret; | 165 guint32 ret; |
166 g_return_val_if_fail(name != NULL, 0); | 166 g_return_val_if_fail(name != NULL, 0); |
167 | 167 |
168 ret = strtol(name, NULL, 10); | 168 ret = strtol(name, NULL, 10); |
170 return 0; | 170 return 0; |
171 else | 171 else |
172 return ret; | 172 return ret; |
173 } | 173 } |
174 | 174 |
175 /* convert a QQ UID to a unique name of Gaim | 175 /* convert a QQ UID to a unique name of Purple |
176 * the return needs to be freed */ | 176 * the return needs to be freed */ |
177 gchar *uid_to_gaim_name(guint32 uid) | 177 gchar *uid_to_purple_name(guint32 uid) |
178 { | 178 { |
179 return g_strdup_printf(QQ_NAME_FORMAT, uid); | 179 return g_strdup_printf(QQ_NAME_FORMAT, uid); |
180 } | 180 } |
181 | 181 |
182 /* convert name displayed in a chat channel to original QQ UID */ | 182 /* convert name displayed in a chat channel to original QQ UID */ |
183 gchar *chat_name_to_gaim_name(const gchar *const name) | 183 gchar *chat_name_to_purple_name(const gchar *const name) |
184 { | 184 { |
185 const gchar *tmp; | 185 const gchar *tmp; |
186 gchar *ret; | 186 gchar *ret; |
187 | 187 |
188 g_return_val_if_fail(name != NULL, NULL); | 188 g_return_val_if_fail(name != NULL, NULL); |
189 | 189 |
190 tmp = (gchar *) gaim_strcasestr(name, "(qq-"); | 190 tmp = (gchar *) purple_strcasestr(name, "(qq-"); |
191 ret = g_strndup(tmp + 4, strlen(name) - (tmp - name) - 4 - 1); | 191 ret = g_strndup(tmp + 4, strlen(name) - (tmp - name) - 4 - 1); |
192 | 192 |
193 return ret; | 193 return ret; |
194 } | 194 } |
195 | 195 |
212 break; | 212 break; |
213 | 213 |
214 msg_utf8 = i < len ? qq_to_utf8((gchar *) &incoming[i], QQ_CHARSET_DEFAULT) : NULL; | 214 msg_utf8 = i < len ? qq_to_utf8((gchar *) &incoming[i], QQ_CHARSET_DEFAULT) : NULL; |
215 | 215 |
216 if (msg_utf8 != NULL) { | 216 if (msg_utf8 != NULL) { |
217 gaim_debug(GAIM_DEBUG_WARNING, "QQ", "Try extract GB msg: %s\n", msg_utf8); | 217 purple_debug(PURPLE_DEBUG_WARNING, "QQ", "Try extract GB msg: %s\n", msg_utf8); |
218 g_free(msg_utf8); | 218 g_free(msg_utf8); |
219 } | 219 } |
220 } | 220 } |
221 | 221 |
222 /* strips whitespace */ | 222 /* strips whitespace */ |
251 g_return_val_if_fail(buffer != NULL, NULL); | 251 g_return_val_if_fail(buffer != NULL, NULL); |
252 | 252 |
253 hex_buffer = strstrip(buffer); | 253 hex_buffer = strstrip(buffer); |
254 | 254 |
255 if (strlen(hex_buffer) % 2 != 0) { | 255 if (strlen(hex_buffer) % 2 != 0) { |
256 gaim_debug(GAIM_DEBUG_WARNING, "QQ", | 256 purple_debug(PURPLE_DEBUG_WARNING, "QQ", |
257 "Unable to convert an odd number of nibbles to a string of bytes!\n"); | 257 "Unable to convert an odd number of nibbles to a string of bytes!\n"); |
258 g_free(hex_buffer); | 258 g_free(hex_buffer); |
259 return NULL; | 259 return NULL; |
260 } | 260 } |
261 bytes = g_newa(guint8, strlen(hex_buffer) / 2); | 261 bytes = g_newa(guint8, strlen(hex_buffer) / 2); |
266 if (g_ascii_isdigit(*cursor)) { | 266 if (g_ascii_isdigit(*cursor)) { |
267 tmp = *cursor; nibble1 = atoi(&tmp); | 267 tmp = *cursor; nibble1 = atoi(&tmp); |
268 } else if (g_ascii_isalpha(*cursor) && (gint) *cursor - 87 < 16) { | 268 } else if (g_ascii_isalpha(*cursor) && (gint) *cursor - 87 < 16) { |
269 nibble1 = (gint) *cursor - 87; | 269 nibble1 = (gint) *cursor - 87; |
270 } else { | 270 } else { |
271 gaim_debug(GAIM_DEBUG_WARNING, "QQ", | 271 purple_debug(PURPLE_DEBUG_WARNING, "QQ", |
272 "Invalid char \'%c\' found in hex string!\n", *cursor); | 272 "Invalid char \'%c\' found in hex string!\n", *cursor); |
273 g_free(hex_str); | 273 g_free(hex_str); |
274 return NULL; | 274 return NULL; |
275 } | 275 } |
276 nibble1 = nibble1 << 4; | 276 nibble1 = nibble1 << 4; |
278 if (g_ascii_isdigit(*cursor)) { | 278 if (g_ascii_isdigit(*cursor)) { |
279 tmp = *cursor; nibble2 = atoi(&tmp); | 279 tmp = *cursor; nibble2 = atoi(&tmp); |
280 } else if (g_ascii_isalpha(*cursor) && (gint) (*cursor - 87) < 16) { | 280 } else if (g_ascii_isalpha(*cursor) && (gint) (*cursor - 87) < 16) { |
281 nibble2 = (gint) *cursor - 87; | 281 nibble2 = (gint) *cursor - 87; |
282 } else { | 282 } else { |
283 gaim_debug(GAIM_DEBUG_WARNING, "QQ", | 283 purple_debug(PURPLE_DEBUG_WARNING, "QQ", |
284 "Invalid char found in hex string!\n"); | 284 "Invalid char found in hex string!\n"); |
285 g_free(hex_str); | 285 g_free(hex_str); |
286 return NULL; | 286 return NULL; |
287 } | 287 } |
288 bytes[index++] = nibble1 + nibble2; | 288 bytes[index++] = nibble1 + nibble2; |
339 icon_num_str = g_strdup_printf("%d", icon_num); | 339 icon_num_str = g_strdup_printf("%d", icon_num); |
340 return icon_num_str; | 340 return icon_num_str; |
341 } | 341 } |
342 | 342 |
343 /* return the location of the buddy icon dir | 343 /* return the location of the buddy icon dir |
344 * any application using libgaim but not installing the QQ buddy icons | 344 * any application using libpurple but not installing the QQ buddy icons |
345 * under datadir needs to set the pref below, or buddy icons won't work */ | 345 * under datadir needs to set the pref below, or buddy icons won't work */ |
346 const char *qq_buddy_icon_dir(void) | 346 const char *qq_buddy_icon_dir(void) |
347 { | 347 { |
348 if (gaim_prefs_exists("/prpl/qq/buddy_icon_dir")) | 348 if (purple_prefs_exists("/prpl/qq/buddy_icon_dir")) |
349 return gaim_prefs_get_string("/prpl/qq/buddy_icon_dir"); | 349 return purple_prefs_get_string("/prpl/qq/buddy_icon_dir"); |
350 else | 350 else |
351 return QQ_BUDDY_ICON_DIR; | 351 return QQ_BUDDY_ICON_DIR; |
352 } | 352 } |
353 | 353 |
354 #ifdef _WIN32 | 354 #ifdef _WIN32 |
355 const char *qq_win32_buddy_icon_dir(void) | 355 const char *qq_win32_buddy_icon_dir(void) |
356 { | 356 { |
357 static char *dir = NULL; | 357 static char *dir = NULL; |
358 if (dir == NULL) | 358 if (dir == NULL) |
359 dir = g_build_filename(wgaim_install_dir(), "pixmaps", | 359 dir = g_build_filename(wpurple_install_dir(), "pixmaps", |
360 "gaim", "buddy_icons", "qq", NULL); | 360 "purple", "buddy_icons", "qq", NULL); |
361 return dir; | 361 return dir; |
362 } | 362 } |
363 #endif | 363 #endif |