Mercurial > pidgin.yaz
comparison libpurple/protocols/qq/buddy_info.c @ 20878:38b12aff6d5a
deryni noticed that my previous fix didn't address what was really wrong with this function. The request callback was removing stuff from the request internals without cleaning up. This is also cleaner and (hopefully) less error prone. I'm not at all happy with how other parts of this work, but I don't have a good way of testing, so I'm not going to make drastic changes.
author | Daniel Atallah <daniel.atallah@gmail.com> |
---|---|
date | Wed, 10 Oct 2007 20:29:16 +0000 |
parents | 27d2d6cc8d36 |
children | 7821fa7b22db fc80a99f6f40 |
comparison
equal
deleted
inserted
replaced
20877:7dfb2ff2e75c | 20878:38b12aff6d5a |
---|---|
304 | 304 |
305 g_strfreev((gchar **) mid->info); | 305 g_strfreev((gchar **) mid->info); |
306 g_free(mid); | 306 g_free(mid); |
307 } | 307 } |
308 | 308 |
309 static gchar *parse_field(GList **list, gboolean choice) | 309 static gchar *parse_field(PurpleRequestField *field, gboolean choice) |
310 { | 310 { |
311 gchar *value; | 311 gchar *value; |
312 PurpleRequestField *field; | 312 |
313 | |
314 field = (PurpleRequestField *) (*list)->data; | |
315 if (choice) { | 313 if (choice) { |
316 value = g_strdup_printf("%d", purple_request_field_choice_get_value(field)); | 314 value = g_strdup_printf("%d", purple_request_field_choice_get_value(field)); |
317 } else { | 315 } else { |
318 value = (gchar *) purple_request_field_string_get_value(field); | 316 value = (gchar *) purple_request_field_string_get_value(field); |
319 if (value == NULL) | 317 if (value == NULL) |
320 value = g_strdup("-"); | 318 value = g_strdup("-"); |
321 else | 319 else |
322 value = utf8_to_qq(value, QQ_CHARSET_DEFAULT); | 320 value = utf8_to_qq(value, QQ_CHARSET_DEFAULT); |
323 } | 321 } |
324 *list = g_list_remove_link(*list, *list); | |
325 | 322 |
326 return value; | 323 return value; |
327 } | 324 } |
328 | 325 |
329 /* parse fields and send info packet */ | 326 /* parse fields and send info packet */ |
330 static void modify_info_ok_cb(modify_info_data *mid, PurpleRequestFields *fields) | 327 static void modify_info_ok_cb(modify_info_data *mid, PurpleRequestFields *fields) |
331 { | 328 { |
332 PurpleConnection *gc; | 329 PurpleConnection *gc; |
333 qq_data *qd; | 330 qq_data *qd; |
334 GList *list, *groups; | 331 GList *groups; |
335 contact_info *info; | 332 contact_info *info; |
336 | 333 |
337 gc = mid->gc; | 334 gc = mid->gc; |
338 qd = (qq_data *) gc->proto_data; | 335 qd = (qq_data *) gc->proto_data; |
339 qd->modifying_info = FALSE; | 336 qd->modifying_info = FALSE; |
340 | 337 |
341 info = mid->info; | 338 info = mid->info; |
342 | 339 |
343 groups = purple_request_fields_get_groups(fields); | 340 groups = purple_request_fields_get_groups(fields); |
344 list = purple_request_field_group_get_fields(groups->data); | 341 while (groups != NULL) { |
345 info->uid = parse_field(&list, FALSE); | 342 PurpleRequestFieldGroup *group = groups->data; |
346 info->nick = parse_field(&list, FALSE); | 343 const char *g_name = purple_request_field_group_get_title(group); |
347 info->name = parse_field(&list, FALSE); | 344 GList *fields = purple_request_field_group_get_fields(group); |
348 info->age = parse_field(&list, FALSE); | 345 |
349 info->gender = parse_field(&list, TRUE); | 346 if (g_name == NULL) |
350 info->country = parse_field(&list, FALSE); | 347 continue; |
351 info->province = parse_field(&list, FALSE); | 348 |
352 info->city = parse_field(&list, FALSE); | 349 while (fields != NULL) { |
353 groups = g_list_remove_link(groups, groups); | 350 PurpleRequestField *field = fields->data; |
354 list = purple_request_field_group_get_fields(groups->data); | 351 const char *f_id = purple_request_field_get_id(field); |
355 info->horoscope = parse_field(&list, TRUE); | 352 |
356 info->occupation = parse_field(&list, FALSE); | 353 if (!strcmp(QQ_PRIMARY_INFORMATION, g_name)) { |
357 info->zodiac = parse_field(&list, TRUE); | 354 |
358 info->blood = parse_field(&list, TRUE); | 355 if (!strcmp(f_id, "uid")) |
359 info->college = parse_field(&list, FALSE); | 356 info->uid = parse_field(field, FALSE); |
360 info->email = parse_field(&list, FALSE); | 357 else if (!strcmp(f_id, "nick")) |
361 info->address = parse_field(&list, FALSE); | 358 info->nick = parse_field(field, FALSE); |
362 info->zipcode = parse_field(&list, FALSE); | 359 else if (!strcmp(f_id, "name")) |
363 info->hp_num = parse_field(&list, FALSE); | 360 info->name = parse_field(field, FALSE); |
364 info->tel = parse_field(&list, FALSE); | 361 else if (!strcmp(f_id, "age")) |
365 info->homepage = parse_field(&list, FALSE); | 362 info->age = parse_field(field, FALSE); |
366 groups = g_list_remove_link(groups, groups); | 363 else if (!strcmp(f_id, "gender")) |
367 list = purple_request_field_group_get_fields(groups->data); | 364 info->gender = parse_field(field, TRUE); |
368 info->intro = parse_field(&list, FALSE); | 365 else if (!strcmp(f_id, "country")) |
369 | 366 info->country = parse_field(field, FALSE); |
370 g_list_free(groups); | 367 else if (!strcmp(f_id, "province")) |
371 | 368 info->province = parse_field(field, FALSE); |
369 else if (!strcmp(f_id, "city")) | |
370 info->city = parse_field(field, FALSE); | |
371 | |
372 } else if (!strcmp(QQ_ADDITIONAL_INFORMATION, g_name)) { | |
373 | |
374 if (!strcmp(f_id, "horoscope")) | |
375 info->horoscope = parse_field(field, TRUE); | |
376 else if (!strcmp(f_id, "occupation")) | |
377 info->occupation = parse_field(field, FALSE); | |
378 else if (!strcmp(f_id, "zodiac")) | |
379 info->zodiac = parse_field(field, TRUE); | |
380 else if (!strcmp(f_id, "blood")) | |
381 info->blood = parse_field(field, TRUE); | |
382 else if (!strcmp(f_id, "college")) | |
383 info->college = parse_field(field, FALSE); | |
384 else if (!strcmp(f_id, "email")) | |
385 info->email = parse_field(field, FALSE); | |
386 else if (!strcmp(f_id, "address")) | |
387 info->address = parse_field(field, FALSE); | |
388 else if (!strcmp(f_id, "zipcode")) | |
389 info->zipcode = parse_field(field, FALSE); | |
390 else if (!strcmp(f_id, "hp_num")) | |
391 info->hp_num = parse_field(field, FALSE); | |
392 else if (!strcmp(f_id, "tel")) | |
393 info->tel = parse_field(field, FALSE); | |
394 else if (!strcmp(f_id, "homepage")) | |
395 info->homepage = parse_field(field, FALSE); | |
396 | |
397 } else if (!strcmp(QQ_INTRO, g_name)) { | |
398 | |
399 if (!strcmp(f_id, "intro")) | |
400 info->intro = parse_field(field, FALSE); | |
401 | |
402 } | |
403 | |
404 fields = fields->next; | |
405 } | |
406 | |
407 groups = groups->next; | |
408 } | |
409 | |
410 /* This casting looks like a horrible idea to me -DAA */ | |
372 qq_send_packet_modify_info(gc, (gchar **) info); | 411 qq_send_packet_modify_info(gc, (gchar **) info); |
373 | 412 |
374 g_strfreev((gchar **) mid->info); | 413 g_strfreev((gchar **) mid->info); |
375 g_free(mid); | 414 g_free(mid); |
376 } | 415 } |
436 add_string_field_to_group(group, "age", QQ_AGE, info->age); | 475 add_string_field_to_group(group, "age", QQ_AGE, info->age); |
437 add_choice_field_to_group(group, "gender", QQ_GENDER, info->gender, genders, QQ_GENDER_SIZE); | 476 add_choice_field_to_group(group, "gender", QQ_GENDER, info->gender, genders, QQ_GENDER_SIZE); |
438 add_string_field_to_group(group, "country", QQ_COUNTRY, info->country); | 477 add_string_field_to_group(group, "country", QQ_COUNTRY, info->country); |
439 add_string_field_to_group(group, "province", QQ_PROVINCE, info->province); | 478 add_string_field_to_group(group, "province", QQ_PROVINCE, info->province); |
440 add_string_field_to_group(group, "city", QQ_CITY, info->city); | 479 add_string_field_to_group(group, "city", QQ_CITY, info->city); |
480 | |
441 group = setup_field_group(fields, QQ_ADDITIONAL_INFORMATION); | 481 group = setup_field_group(fields, QQ_ADDITIONAL_INFORMATION); |
442 add_choice_field_to_group(group, "horoscope", QQ_HOROSCOPE, info->horoscope, horoscope_names, QQ_HOROSCOPE_SIZE); | 482 add_choice_field_to_group(group, "horoscope", QQ_HOROSCOPE, info->horoscope, horoscope_names, QQ_HOROSCOPE_SIZE); |
443 add_string_field_to_group(group, "occupation", QQ_OCCUPATION, info->occupation); | 483 add_string_field_to_group(group, "occupation", QQ_OCCUPATION, info->occupation); |
444 add_choice_field_to_group(group, "zodiac", QQ_ZODIAC, info->zodiac, zodiac_names, QQ_ZODIAC_SIZE); | 484 add_choice_field_to_group(group, "zodiac", QQ_ZODIAC, info->zodiac, zodiac_names, QQ_ZODIAC_SIZE); |
445 add_choice_field_to_group(group, "blood", QQ_BLOOD, info->blood, blood_types, QQ_BLOOD_SIZE); | 485 add_choice_field_to_group(group, "blood", QQ_BLOOD, info->blood, blood_types, QQ_BLOOD_SIZE); |