libpurple/protocols/qq/buddy_memo.c

branch
openq
changeset 25659
2bbb8a5e37e5
parent 25658
d3a305c0fce8
child 25662
c5525da702b3
equal deleted inserted replaced
25658:d3a305c0fce8 25659:2bbb8a5e37e5
35 QQ_MEMO_SIZE 35 QQ_MEMO_SIZE
36 }; 36 };
37 37
38 /* memo id */ 38 /* memo id */
39 static const gchar *memo_id[] = { 39 static const gchar *memo_id[] = {
40 N_("mm_alias"), 40 "mm_alias",
41 N_("mm_mobile"), 41 "mm_mobile",
42 N_("mm_telephone"), 42 "mm_telephone",
43 N_("mm_address"), 43 "mm_address",
44 N_("mm_email"), 44 "mm_email",
45 N_("mm_zipcode"), 45 "mm_zipcode",
46 N_("mm_note") 46 "mm_note"
47 }; 47 };
48 48
49 /* memo text */ 49 /* memo text */
50 static const gchar *memo_txt[] = { 50 static const gchar *memo_txt[] = {
51 N_("Alias"), 51 N_("Alias"),
95 95
96 who = uid_to_purple_name(bd_uid); 96 who = uid_to_purple_name(bd_uid);
97 buddy = purple_find_buddy(account, who); 97 buddy = purple_find_buddy(account, who);
98 if (buddy == NULL || buddy->proto_data == NULL) { 98 if (buddy == NULL || buddy->proto_data == NULL) {
99 g_free(who); 99 g_free(who);
100 purple_debug_info("QQ", "Error Can not find %d!\n", bd_uid); 100 purple_debug_info("QQ", "Error...Can NOT find %d!\n", bd_uid);
101 return; 101 return;
102 } 102 }
103 purple_blist_alias_buddy(buddy, (const char*)alias); 103 purple_blist_alias_buddy(buddy, (const char*)alias);
104 } 104 }
105 105
106 static void request_change_memo(PurpleConnection *gc, guint32 bd_uid, gchar **segments) 106 static void request_change_memo(PurpleConnection *gc, guint32 bd_uid, gchar **segments)
107 { 107 {
108 gint bytes; 108 gint bytes;
109 /* Attention, length of each segment must be guint8(0~255), 109 /* Attention, length of each segment must be guint8(0~255),
110 * so length of memo string is limited. 110 * so length of memo string is limited.
111 * convert it to guint8 first before put data */ 111 * convert it to guint8 first before putting data */
112 guint seg_len; 112 guint seg_len;
113 gint index; 113 gint index;
114 guint8 raw_data[MAX_PACKET_SIZE - 16] = {0}; 114 guint8 raw_data[MAX_PACKET_SIZE - 16] = {0};
115 115
116 purple_debug_info( "QQ", "request_change_memo\n" ); 116 purple_debug_info( "QQ", "request_change_memo\n" );
187 memo_free(segments); 187 memo_free(segments);
188 g_free(memo_request); 188 g_free(memo_request);
189 } 189 }
190 190
191 /* memo modify dialogue */ 191 /* memo modify dialogue */
192 static void memo_modify_dialogue(PurpleConnection *gc, guint32 bd_uid, gchar **segments, gint iclass) 192 static void memo_modify_dialogue(PurpleConnection *gc, guint32 bd_uid, gchar **segments, guint32 action)
193 { 193 {
194 modify_memo_request *memo_request; 194 modify_memo_request *memo_request;
195 PurpleRequestField *field; 195 PurpleRequestField *field;
196 PurpleRequestFields *fields; 196 PurpleRequestFields *fields;
197 PurpleRequestFieldGroup *group; 197 PurpleRequestFieldGroup *group;
199 gchar *utf8_title; 199 gchar *utf8_title;
200 gchar *utf8_primary; 200 gchar *utf8_primary;
201 201
202 g_return_if_fail(NULL != gc && NULL != segments); 202 g_return_if_fail(NULL != gc && NULL != segments);
203 203
204 switch (iclass) { 204 switch (action) {
205 case QQ_BUDDY_MEMO_GET: 205 case QQ_BUDDY_MEMO_GET:
206 memo_free(segments);
206 break; 207 break;
207 case QQ_BUDDY_MEMO_MODIFY: 208 case QQ_BUDDY_MEMO_MODIFY:
208 /* Keep one dialog once a time */ 209 /* keep one dialog once a time */
209 purple_request_close_with_handle(gc); 210 purple_request_close_with_handle(gc);
210 /* show dialog */ 211 /* show dialog */
211 fields = purple_request_fields_new(); 212 fields = purple_request_fields_new();
212 group = purple_request_field_group_new(NULL); 213 group = purple_request_field_group_new(NULL);
213 purple_request_fields_add_group(fields, group); 214 purple_request_fields_add_group(fields, group);
215 for(index = 0; index < QQ_MEMO_SIZE; index++) { 216 for(index = 0; index < QQ_MEMO_SIZE; index++) {
216 /* 217 /*
217 purple_debug_info("QQ", "id:%s txt:%s segment:%s\n", 218 purple_debug_info("QQ", "id:%s txt:%s segment:%s\n",
218 memo_id[index], memo_txt[index], segments[index]); 219 memo_id[index], memo_txt[index], segments[index]);
219 */ 220 */
220
221 field = purple_request_field_string_new(memo_id[index], memo_txt[index], 221 field = purple_request_field_string_new(memo_id[index], memo_txt[index],
222 segments[index], FALSE); 222 segments[index], FALSE);
223 purple_request_field_group_add_field(group, field); 223 purple_request_field_group_add_field(group, field);
224 } 224 }
225 225
241 241
242 g_free(utf8_title); 242 g_free(utf8_title);
243 g_free(utf8_primary); 243 g_free(utf8_primary);
244 break; 244 break;
245 default: 245 default:
246 purple_debug_info("QQ", "unknown memo action\n"); 246 purple_debug_info("QQ", "Error...unknown memo action, please tell us\n");
247 break; 247 break;
248 } 248 }
249 }
250
251 static void qq_create_buddy_memo(PurpleConnection *gc, guint32 bd_uid, guint32 action)
252 {
253 gchar **segments;
254 gint index;
255 g_return_if_fail(NULL != gc);
256
257 segments = g_new0(gchar*, QQ_MEMO_SIZE);
258 for (index = 0; index < QQ_MEMO_SIZE; index++) {
259 segments[index] = g_strdup("");;
260 }
261 memo_modify_dialogue(gc, bd_uid, segments, action);
249 } 262 }
250 263
251 /* process reply to get_memo packet */ 264 /* process reply to get_memo packet */
252 void qq_process_get_buddy_memo(PurpleConnection *gc, guint8* data, gint data_len, guint32 action) 265 void qq_process_get_buddy_memo(PurpleConnection *gc, guint8* data, gint data_len,
266 guint32 update_class, guint32 action)
253 { 267 {
254 gchar **segments; 268 gchar **segments;
255 gint bytes; 269 gint bytes;
256 gint index; 270 gint index;
257 guint8 rcv_cmd; 271 guint8 rcv_cmd;
258 guint32 rcv_uid; 272 guint32 rcv_uid;
259 guint8 unk1_8; 273 guint8 unk1_8;
260 guint8 is_success; 274 guint8 is_success;
261 275
262 g_return_if_fail(data != NULL && data_len != 0); 276 g_return_if_fail(NULL != gc && NULL != data && 0 != data_len);
263 /* 277 /*
264 qq_show_packet("MEMO REACH", data, data_len); 278 qq_show_packet("MEMO REACH", data, data_len);
265 */ 279 */
266 purple_debug_info("QQ", "action:0x%x\n", action); 280 purple_debug_info("QQ", "action=0x%02X\n", action);
267 281
268 bytes = 0; 282 bytes = 0;
269 283
270 /* TX looks a bit clever than before... :) */ 284 /* TX looks a bit clever than before... :) */
271 bytes += qq_get8(&rcv_cmd, data+bytes); 285 bytes += qq_get8(&rcv_cmd, data+bytes);
272 purple_debug_info("QQ", "rcv_cmd:0x%x\n", rcv_cmd); 286 purple_debug_info("QQ", "rcv_cmd=0x%02X\n", rcv_cmd);
273 /* it's possible that no buddy uid and no memo!!! */ 287
274 if (1 == data_len) { 288 /* it's possible that packet contains no buddy uid and no memo!!!
289 * go to next step according to previous action sent */
290 if (1 == data_len) { /* only one byte */
275 purple_debug_info("QQ", "memo packet contains no buddy uid and memo...\n"); 291 purple_debug_info("QQ", "memo packet contains no buddy uid and memo...\n");
292 if (QQ_BUDDY_MEMO_MODIFY == action) {
293 qq_create_buddy_memo(gc, (guint32)update_class, QQ_BUDDY_MEMO_MODIFY);
294 return;
295 }
276 return; 296 return;
277 } 297 }
278 298
279 switch (rcv_cmd) { 299 switch (rcv_cmd) {
280 case QQ_BUDDY_MEMO_MODIFY: 300 case QQ_BUDDY_MEMO_MODIFY:
281 case QQ_BUDDY_MEMO_REMOVE: 301 case QQ_BUDDY_MEMO_REMOVE:
282 bytes += qq_get8(&is_success, data+bytes); 302 bytes += qq_get8(&is_success, data+bytes);
283 if (QQ_BUDDY_MEMO_REQUEST_SUCCESS == is_success) { 303 if (QQ_BUDDY_MEMO_REQUEST_SUCCESS == is_success) {
284 purple_notify_message(gc, PURPLE_NOTIFY_MSG_INFO, 304 purple_notify_message(gc, PURPLE_NOTIFY_MSG_INFO,
285 _("Memo Modify"), _("Your request was accepted."), NULL, 305 _("Memo Modify"), _("Server says:"),
306 _("Your request was accepted."),
286 NULL, NULL); 307 NULL, NULL);
287 purple_debug_info("QQ", "memo change succeessfully!"); 308 purple_debug_info("QQ", "memo change succeessfully!\n");
288 } 309 }
289 else { 310 else {
290 purple_notify_message(gc, PURPLE_NOTIFY_MSG_INFO, 311 purple_notify_message(gc, PURPLE_NOTIFY_MSG_INFO,
291 _("Memo Modify"), _("Your request was rejected."), NULL, 312 _("Memo Modify"), _("Server says:"),
313 _("Your request was rejected."),
292 NULL, NULL); 314 NULL, NULL);
293 purple_debug_info("QQ", "memo change failed"); 315 purple_debug_info("QQ", "memo change failed\n");
294 } 316 }
295 break; 317 break;
296 case QQ_BUDDY_MEMO_GET: 318 case QQ_BUDDY_MEMO_GET:
297 bytes += qq_get32(&rcv_uid, data+bytes); 319 bytes += qq_get32(&rcv_uid, data+bytes);
298 purple_debug_info("QQ", "rcv_uid:%u\n", rcv_uid); 320 purple_debug_info("QQ", "rcv_uid=%u\n", rcv_uid);
299 bytes += qq_get8(&unk1_8, data+bytes); 321 bytes += qq_get8(&unk1_8, data+bytes);
300 purple_debug_info("QQ", "unk1_8:0x%x\n", unk1_8); 322 purple_debug_info("QQ", "unk1_8=0x%02X\n", unk1_8);
301 segments = g_new0(gchar*, QQ_MEMO_SIZE); 323 segments = g_new0(gchar*, QQ_MEMO_SIZE);
302 for (index = 0; index < QQ_MEMO_SIZE; index++) { 324 for (index = 0; index < QQ_MEMO_SIZE; index++) {
303 /* get utf8 string */ 325 /* get utf8 string */
304 bytes += qq_get_vstr(&segments[index], QQ_CHARSET_DEFAULT, data+bytes); 326 bytes += qq_get_vstr(&segments[index], QQ_CHARSET_DEFAULT, data+bytes);
305 /* 327 /*
310 /* common action, update buddy memo */ 332 /* common action, update buddy memo */
311 update_buddy_memo(gc, rcv_uid, segments[QQ_MEMO_ALIAS]); 333 update_buddy_memo(gc, rcv_uid, segments[QQ_MEMO_ALIAS]);
312 334
313 /* memo is thing that we regard our buddy as, so we need one more buddy_uid */ 335 /* memo is thing that we regard our buddy as, so we need one more buddy_uid */
314 memo_modify_dialogue(gc, rcv_uid, segments, action); 336 memo_modify_dialogue(gc, rcv_uid, segments, action);
315
316 break; 337 break;
317 default: 338 default:
318 purple_debug_info("QQ", "received an UNKNOWN memo cmd!!!"); 339 purple_debug_info("QQ", "received an UNKNOWN memo cmd!!!\n");
319 break; 340 break;
320 } 341 }
321 } 342 }
322 343
323 /* request buddy memo */ 344 /* request buddy memo */
324 void qq_request_buddy_memo(PurpleConnection *gc, guint32 bd_uid, guint32 update_class, int action) 345 void qq_request_buddy_memo(PurpleConnection *gc, guint32 bd_uid, guint32 update_class, guint32 action)
325 { 346 {
326 guint8 raw_data[16] = {0}; 347 guint8 raw_data[16] = {0};
327 gint bytes; 348 gint bytes;
328 349
329 purple_debug_info("QQ", "qq_request_buddy_memo, buddy uid=%u\n", bd_uid); 350 purple_debug_info("QQ", "qq_request_buddy_memo, buddy uid=%u, update_class=%u\n",
351 bd_uid, update_class);
330 g_return_if_fail(NULL != gc); 352 g_return_if_fail(NULL != gc);
331 /* '0' is ok 353 /* '0' is ok
332 g_return_if_fail(uid != 0); 354 g_return_if_fail(uid != 0);
333 */ 355 */
334 bytes = 0; 356 bytes = 0;
339 */ 361 */
340 362
341 qq_send_cmd_mess(gc, QQ_CMD_BUDDY_MEMO, (guint8*)raw_data, bytes, update_class, action); 363 qq_send_cmd_mess(gc, QQ_CMD_BUDDY_MEMO, (guint8*)raw_data, bytes, update_class, action);
342 } 364 }
343 365
344 void qq_create_buddy_memo(PurpleConnection *gc, guint32 bd_uid, int action) 366
345 {
346 gchar **segments;
347 gint index;
348 g_return_if_fail(NULL != gc);
349
350 segments = g_new0(gchar*, QQ_MEMO_SIZE);
351 for (index = 0; index < QQ_MEMO_SIZE; index++) {
352 segments[index] = g_strdup("");;
353 }
354 memo_modify_dialogue(gc, bd_uid, segments, action);
355 }
356

mercurial