comparison libpurple/protocols/qq/buddy_memo.c @ 31639:4deef745de87

2010.01.23 - flos <lonicerae(at)gmail.com> * added an option to force incoming message in chat room to use a default font instead of the font in message itself 2010.01.18 - flos <lonicerae(at)gmail.com> * added type 'UPDCLS' and 'UID' for implementing business logic layer 2010.01.13 - ccpaging <ccpaging(at)gmail.com> * qq2009-1 patch from ccpaging
author SHiNE CsyFeK <csyfek@gmail.com>
date Sun, 06 Feb 2011 05:23:22 +0000
parents dba5d0f7bb39
children
comparison
equal deleted inserted replaced
31638:f0e6aaf942f8 31639:4deef745de87
81 N_("Note") 81 N_("Note")
82 }; 82 };
83 83
84 typedef struct _modify_memo_request { 84 typedef struct _modify_memo_request {
85 PurpleConnection *gc; 85 PurpleConnection *gc;
86 guint32 bd_uid; 86 UID bd_uid;
87 gchar **segments; 87 gchar **segments;
88 } modify_memo_request; 88 } modify_memo_request;
89 89
90 90
91 static void memo_debug(gchar **segments) 91 static void memo_debug(gchar **segments)
105 g_free(segments[index]); 105 g_free(segments[index]);
106 } 106 }
107 purple_debug_info("QQ", "memo freed\n"); 107 purple_debug_info("QQ", "memo freed\n");
108 } 108 }
109 109
110 static void update_buddy_memo(PurpleConnection *gc, guint32 bd_uid, gchar *alias) 110 static void update_buddy_memo(PurpleConnection *gc, UID bd_uid, gchar *alias)
111 { 111 {
112 PurpleAccount *account; 112 PurpleAccount *account;
113 PurpleBuddy *buddy; 113 PurpleBuddy *buddy;
114 gchar *who; 114 gchar *who;
115 g_return_if_fail(NULL != gc && NULL != alias); 115 g_return_if_fail(NULL != gc && NULL != alias);
125 return; 125 return;
126 } 126 }
127 purple_blist_alias_buddy(buddy, (const char*)alias); 127 purple_blist_alias_buddy(buddy, (const char*)alias);
128 } 128 }
129 129
130 static void request_change_memo(PurpleConnection *gc, guint32 bd_uid, gchar **segments) 130 static void request_change_memo(PurpleConnection *gc, UID bd_uid, gchar **segments)
131 { 131 {
132 gint bytes; 132 gint bytes;
133 /* Attention, length of each segment must be guint8(0~255), 133 /* Attention, length of each segment must be guint8(0~255),
134 * so length of memo string is limited. 134 * so length of memo string is limited.
135 * convert it to guint8 first before putting data */ 135 * convert it to guint8 first before putting data */
168 168
169 /* prepare segments to be sent, string all convert to qq charset */ 169 /* prepare segments to be sent, string all convert to qq charset */
170 static void memo_modify_ok_cb(modify_memo_request *memo_request, PurpleRequestFields *fields) 170 static void memo_modify_ok_cb(modify_memo_request *memo_request, PurpleRequestFields *fields)
171 { 171 {
172 PurpleConnection *gc; 172 PurpleConnection *gc;
173 guint32 bd_uid; 173 UID bd_uid;
174 gchar **segments; 174 gchar **segments;
175 const gchar *utf8_str; 175 const gchar *utf8_str;
176 gchar *value = NULL; 176 gchar *value = NULL;
177 gint index; 177 gint index;
178 178
185 185
186 for (index = 0; index < QQ_MEMO_SIZE; index++) { 186 for (index = 0; index < QQ_MEMO_SIZE; index++) {
187 utf8_str = purple_request_fields_get_string(fields, memo_id[index]); 187 utf8_str = purple_request_fields_get_string(fields, memo_id[index]);
188 /* update alias */ 188 /* update alias */
189 if (QQ_MEMO_ALIAS == index) { 189 if (QQ_MEMO_ALIAS == index) {
190 update_buddy_memo(gc, bd_uid, segments[QQ_MEMO_ALIAS]); 190 update_buddy_memo(gc, (UID)bd_uid, segments[QQ_MEMO_ALIAS]);
191 } 191 }
192 if (NULL == utf8_str) { 192 if (NULL == utf8_str) {
193 value = g_strdup(""); 193 value = g_strdup("");
194 } 194 }
195 else { 195 else {
211 memo_free(segments); 211 memo_free(segments);
212 g_free(memo_request); 212 g_free(memo_request);
213 } 213 }
214 214
215 /* memo modify dialogue */ 215 /* memo modify dialogue */
216 static void memo_modify_dialogue(PurpleConnection *gc, guint32 bd_uid, gchar **segments, guint32 action) 216 static void memo_modify_dialogue(PurpleConnection *gc, UID bd_uid, gchar **segments, guint32 action)
217 { 217 {
218 modify_memo_request *memo_request; 218 modify_memo_request *memo_request;
219 PurpleRequestField *field; 219 PurpleRequestField *field;
220 PurpleRequestFields *fields; 220 PurpleRequestFields *fields;
221 PurpleRequestFieldGroup *group; 221 PurpleRequestFieldGroup *group;
270 purple_debug_info("QQ", "Error...unknown memo action, please tell us\n"); 270 purple_debug_info("QQ", "Error...unknown memo action, please tell us\n");
271 break; 271 break;
272 } 272 }
273 } 273 }
274 274
275 static void qq_create_buddy_memo(PurpleConnection *gc, guint32 bd_uid, guint32 action) 275 static void qq_create_buddy_memo(PurpleConnection *gc, UID bd_uid, guint32 action)
276 { 276 {
277 gchar **segments; 277 gchar **segments;
278 gint index; 278 gint index;
279 g_return_if_fail(NULL != gc); 279 g_return_if_fail(NULL != gc);
280 280
283 segments[index] = g_strdup("");; 283 segments[index] = g_strdup("");;
284 } 284 }
285 memo_modify_dialogue(gc, bd_uid, segments, action); 285 memo_modify_dialogue(gc, bd_uid, segments, action);
286 } 286 }
287 287
288 /* process reply to get_memo packet */ 288 /* process reply to get_memo packet
289 * here, update_class will be regarded as buddy's uid. because some
290 * memo packages returned without uid, which will make us confused */
289 void qq_process_get_buddy_memo(PurpleConnection *gc, guint8* data, gint data_len, 291 void qq_process_get_buddy_memo(PurpleConnection *gc, guint8* data, gint data_len,
290 guint32 update_class, guint32 action) 292 UPDCLS update_class, guint32 action)
291 { 293 {
292 gchar **segments; 294 gchar **segments;
293 gint bytes; 295 gint bytes;
294 gint index; 296 gint index;
295 guint8 rcv_cmd; 297 guint8 rcv_cmd;
312 /* it's possible that packet contains no buddy uid and no memo!!! 314 /* it's possible that packet contains no buddy uid and no memo!!!
313 * go to next step according to previous action sent */ 315 * go to next step according to previous action sent */
314 if (1 == data_len) { /* only one byte */ 316 if (1 == data_len) { /* only one byte */
315 purple_debug_info("QQ", "memo packet contains no buddy uid and memo...\n"); 317 purple_debug_info("QQ", "memo packet contains no buddy uid and memo...\n");
316 if (QQ_BUDDY_MEMO_MODIFY == action) { 318 if (QQ_BUDDY_MEMO_MODIFY == action) {
317 qq_create_buddy_memo(gc, (guint32)update_class, QQ_BUDDY_MEMO_MODIFY); 319 UID mod_uid;
320 mod_uid = (UID)update_class;
321 qq_create_buddy_memo(gc, mod_uid, QQ_BUDDY_MEMO_MODIFY);
318 return; 322 return;
319 } 323 }
320 return; 324 return;
321 } 325 }
322 326
352 purple_debug_info("QQ", "bytes:%d, seg:%s\n", bytes, segments[index]); 356 purple_debug_info("QQ", "bytes:%d, seg:%s\n", bytes, segments[index]);
353 */ 357 */
354 } 358 }
355 359
356 /* common action, update buddy memo */ 360 /* common action, update buddy memo */
357 update_buddy_memo(gc, rcv_uid, segments[QQ_MEMO_ALIAS]); 361 update_buddy_memo(gc, (UID)rcv_uid, segments[QQ_MEMO_ALIAS]);
358 362
359 /* memo is thing that we regard our buddy as, so we need one more buddy_uid */ 363 /* memo is a thing that we regard our buddy as, so we need one more buddy_uid */
360 memo_modify_dialogue(gc, rcv_uid, segments, action); 364 memo_modify_dialogue(gc, rcv_uid, segments, action);
361 break; 365 break;
362 default: 366 default:
363 purple_debug_info("QQ", "received an UNKNOWN memo cmd!!!\n"); 367 purple_debug_info("QQ", "received an UNKNOWN memo cmd!!!\n");
364 break; 368 break;
365 } 369 }
366 } 370 }
367 371
368 /* request buddy memo */ 372 /* request buddy memo
369 void qq_request_buddy_memo(PurpleConnection *gc, guint32 bd_uid, guint32 update_class, guint32 action) 373 *
374 * param: gc, uid, update_class, action
375 * here, update_class will be set to buddy's uid. because some memo
376 * packages returned without uid, which will make us confused */
377 void qq_request_buddy_memo(PurpleConnection *gc, UID bd_uid, UPDCLS update_class, guint32 action)
370 { 378 {
371 guint8 raw_data[16] = {0}; 379 guint8 raw_data[16] = {0};
372 gint bytes; 380 gint bytes;
373 381
374 purple_debug_info("QQ", "qq_request_buddy_memo, buddy uid=%u, update_class=%u\n", 382 purple_debug_info("QQ", "qq_request_buddy_memo, buddy uid=%u, update_class=%u\n",