Mercurial > pidgin
comparison libpurple/protocols/oscar/oscar.c @ 30377:b8f47c07ca42
Cleanup some code I wrote a long time ago in a galaxy far far away.
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Thu, 08 Jul 2010 17:00:45 +0000 |
parents | 50d472b3d752 |
children | 1dd3ed053628 |
comparison
equal
deleted
inserted
replaced
30376:50d472b3d752 | 30377:b8f47c07ca42 |
---|---|
4279 { | 4279 { |
4280 PurpleConnection *gc; | 4280 PurpleConnection *gc; |
4281 PurpleAccount *account; | 4281 PurpleAccount *account; |
4282 PurpleGroup *g; | 4282 PurpleGroup *g; |
4283 PurpleBuddy *b; | 4283 PurpleBuddy *b; |
4284 GSList *cur, *next, *buddies; | |
4284 struct aim_ssi_item *curitem; | 4285 struct aim_ssi_item *curitem; |
4285 guint32 tmp; | 4286 guint32 tmp; |
4286 PurpleStoredImage *img; | 4287 PurpleStoredImage *img; |
4287 va_list ap; | 4288 va_list ap; |
4288 guint16 fmtver, numitems; | 4289 guint16 fmtver, numitems; |
4298 numitems = (guint16)va_arg(ap, int); | 4299 numitems = (guint16)va_arg(ap, int); |
4299 timestamp = va_arg(ap, guint32); | 4300 timestamp = va_arg(ap, guint32); |
4300 va_end(ap); | 4301 va_end(ap); |
4301 | 4302 |
4302 /* Don't attempt to re-request our buddy list later */ | 4303 /* Don't attempt to re-request our buddy list later */ |
4303 if (od->getblisttimer != 0) | 4304 if (od->getblisttimer != 0) { |
4304 purple_timeout_remove(od->getblisttimer); | 4305 purple_timeout_remove(od->getblisttimer); |
4305 od->getblisttimer = 0; | 4306 od->getblisttimer = 0; |
4306 | 4307 } |
4307 purple_debug_info("oscar", | 4308 |
4308 "ssi: syncing local list and server list\n"); | 4309 purple_debug_info("oscar", "ssi: syncing local list and server list\n"); |
4309 | 4310 |
4310 /* Clean the buddy list */ | 4311 /* Clean the buddy list */ |
4311 aim_ssi_cleanlist(od); | 4312 aim_ssi_cleanlist(od); |
4312 | 4313 |
4313 { /* If not in server list then prune from local list */ | 4314 /*** Begin code for pruning buddies from local list if they're not in server list ***/ |
4314 GSList *cur, *next; | 4315 |
4315 GSList *buddies = purple_find_buddies(account, NULL); | 4316 /* Buddies */ |
4316 | 4317 cur = NULL; |
4317 /* Buddies */ | 4318 for (buddies = purple_find_buddies(account, NULL); |
4318 cur = NULL; | 4319 buddies; |
4319 | 4320 buddies = g_slist_delete_link(buddies, buddies)) |
4320 while(buddies) { | 4321 { |
4321 PurpleGroup *g; | 4322 PurpleGroup *g; |
4322 const char *gname; | 4323 const char *gname; |
4323 const char *bname; | 4324 const char *bname; |
4324 | 4325 |
4325 b = buddies->data; | 4326 b = buddies->data; |
4326 g = purple_buddy_get_group(b); | 4327 g = purple_buddy_get_group(b); |
4327 gname = purple_group_get_name(g); | 4328 gname = purple_group_get_name(g); |
4328 bname = purple_buddy_get_name(b); | 4329 bname = purple_buddy_get_name(b); |
4329 | 4330 |
4330 if (aim_ssi_itemlist_exists(od->ssi.local, bname)) { | 4331 if (aim_ssi_itemlist_exists(od->ssi.local, bname)) { |
4331 /* If the buddy is an ICQ user then load his nickname */ | 4332 /* If the buddy is an ICQ user then load his nickname */ |
4332 const char *servernick = purple_blist_node_get_string((PurpleBlistNode*)b, "servernick"); | 4333 const char *servernick = purple_blist_node_get_string((PurpleBlistNode*)b, "servernick"); |
4333 char *alias; | 4334 char *alias; |
4334 const char *balias; | 4335 const char *balias; |
4335 if (servernick) | 4336 if (servernick) |
4336 serv_got_alias(gc, bname, servernick); | 4337 serv_got_alias(gc, bname, servernick); |
4337 | 4338 |
4338 /* Store local alias on server */ | 4339 /* Store local alias on server */ |
4339 alias = aim_ssi_getalias(od->ssi.local, gname, bname); | 4340 alias = aim_ssi_getalias(od->ssi.local, gname, bname); |
4340 balias = purple_buddy_get_local_buddy_alias(b); | 4341 balias = purple_buddy_get_local_buddy_alias(b); |
4341 if (!alias && balias && *balias) | 4342 if (!alias && balias && *balias) |
4342 aim_ssi_aliasbuddy(od, gname, bname, balias); | 4343 aim_ssi_aliasbuddy(od, gname, bname, balias); |
4343 g_free(alias); | 4344 g_free(alias); |
4344 } else { | 4345 } else { |
4346 purple_debug_info("oscar", | |
4347 "ssi: removing buddy %s from local list\n", bname); | |
4348 /* Queue the buddy for removal from the local list */ | |
4349 cur = g_slist_prepend(cur, b); | |
4350 } | |
4351 } | |
4352 while (cur != NULL) { | |
4353 purple_blist_remove_buddy(cur->data); | |
4354 cur = g_slist_delete_link(cur, cur); | |
4355 } | |
4356 | |
4357 /* Permit list (ICQ doesn't have one) */ | |
4358 if (!od->icq) { | |
4359 next = account->permit; | |
4360 while (next != NULL) { | |
4361 cur = next; | |
4362 next = next->next; | |
4363 if (!aim_ssi_itemlist_finditem(od->ssi.local, NULL, cur->data, AIM_SSI_TYPE_PERMIT)) { | |
4345 purple_debug_info("oscar", | 4364 purple_debug_info("oscar", |
4346 "ssi: removing buddy %s from local list\n", bname); | 4365 "ssi: removing permit %s from local list\n", (const char *)cur->data); |
4347 /* We can't actually remove now because it will screw up our looping */ | 4366 purple_privacy_permit_remove(account, cur->data, TRUE); |
4348 cur = g_slist_prepend(cur, b); | |
4349 } | 4367 } |
4350 buddies = g_slist_delete_link(buddies, buddies); | 4368 } |
4351 } | 4369 } |
4352 | 4370 |
4353 while (cur != NULL) { | 4371 /* Deny list */ |
4354 b = cur->data; | 4372 next = account->deny; |
4355 cur = g_slist_remove(cur, b); | 4373 while (next != NULL) { |
4356 purple_blist_remove_buddy(b); | 4374 cur = next; |
4357 } | 4375 next = next->next; |
4358 | 4376 if (!aim_ssi_itemlist_finditem(od->ssi.local, NULL, cur->data, deny_entry_type)) { |
4359 /* Permit list (ICQ doesn't have one) */ | 4377 purple_debug_info("oscar", |
4360 if (!od->icq && account->permit) { | 4378 "ssi: removing deny %s from local list\n", (const char *)cur->data); |
4361 next = account->permit; | 4379 purple_privacy_deny_remove(account, cur->data, TRUE); |
4362 while (next != NULL) { | 4380 } |
4363 cur = next; | 4381 } |
4364 next = next->next; | 4382 |
4365 if (!aim_ssi_itemlist_finditem(od->ssi.local, NULL, cur->data, AIM_SSI_TYPE_PERMIT)) { | 4383 /* Presence settings (idle time visibility) */ |
4366 purple_debug_info("oscar", | 4384 tmp = aim_ssi_getpresence(od->ssi.local); |
4367 "ssi: removing permit %s from local list\n", (const char *)cur->data); | 4385 if (tmp != 0xFFFFFFFF) { |
4368 purple_privacy_permit_remove(account, cur->data, TRUE); | 4386 const char *idle_reporting_pref; |
4369 } | 4387 gboolean report_idle; |
4370 } | 4388 |
4371 } | 4389 idle_reporting_pref = purple_prefs_get_string("/purple/away/idle_reporting"); |
4372 | 4390 report_idle = strcmp(idle_reporting_pref, "none") != 0; |
4373 /* Deny list */ | 4391 |
4374 if (account->deny) { | 4392 if (report_idle) |
4375 next = account->deny; | 4393 aim_ssi_setpresence(od, tmp | AIM_SSI_PRESENCE_FLAG_SHOWIDLE); |
4376 while (next != NULL) { | 4394 else |
4377 cur = next; | 4395 aim_ssi_setpresence(od, tmp & ~AIM_SSI_PRESENCE_FLAG_SHOWIDLE); |
4378 next = next->next; | 4396 } |
4379 if (!aim_ssi_itemlist_finditem(od->ssi.local, NULL, cur->data, deny_entry_type)) { | 4397 |
4380 purple_debug_info("oscar", | 4398 /*** End code for pruning buddies from local list ***/ |
4381 "ssi: removing deny %s from local list\n", (const char *)cur->data); | 4399 |
4382 purple_privacy_deny_remove(account, cur->data, TRUE); | 4400 /*** Begin code for adding from server list to local list ***/ |
4383 } | 4401 |
4384 } | |
4385 } | |
4386 /* Presence settings (idle time visibility) */ | |
4387 tmp = aim_ssi_getpresence(od->ssi.local); | |
4388 if (tmp != 0xFFFFFFFF) { | |
4389 const char *idle_reporting_pref; | |
4390 gboolean report_idle; | |
4391 | |
4392 idle_reporting_pref = purple_prefs_get_string("/purple/away/idle_reporting"); | |
4393 report_idle = strcmp(idle_reporting_pref, "none") != 0; | |
4394 | |
4395 if (report_idle) | |
4396 aim_ssi_setpresence(od, tmp | AIM_SSI_PRESENCE_FLAG_SHOWIDLE); | |
4397 else | |
4398 aim_ssi_setpresence(od, tmp & ~AIM_SSI_PRESENCE_FLAG_SHOWIDLE); | |
4399 } | |
4400 | |
4401 | |
4402 } /* end pruning buddies from local list */ | |
4403 | |
4404 /* Add from server list to local list */ | |
4405 for (curitem=od->ssi.local; curitem; curitem=curitem->next) { | 4402 for (curitem=od->ssi.local; curitem; curitem=curitem->next) { |
4406 if ((curitem->name == NULL) || (g_utf8_validate(curitem->name, -1, NULL))) | 4403 if (curitem->name && !g_utf8_validate(curitem->name, -1, NULL)) |
4404 /* Got node with invalid UTF-8 in the name. Skip it. */ | |
4405 break; | |
4406 | |
4407 switch (curitem->type) { | 4407 switch (curitem->type) { |
4408 case AIM_SSI_TYPE_BUDDY: { /* Buddy */ | 4408 case AIM_SSI_TYPE_BUDDY: { /* Buddy */ |
4409 if (curitem->name) { | 4409 if (curitem->name) { |
4410 struct aim_ssi_item *groupitem; | 4410 struct aim_ssi_item *groupitem; |
4411 char *gname, *gname_utf8, *alias, *alias_utf8; | 4411 char *gname, *gname_utf8, *alias, *alias_utf8; |
4491 g_free(gname_utf8); | 4491 g_free(gname_utf8); |
4492 } break; | 4492 } break; |
4493 | 4493 |
4494 case AIM_SSI_TYPE_PERMIT: { /* Permit buddy (unless we're on ICQ) */ | 4494 case AIM_SSI_TYPE_PERMIT: { /* Permit buddy (unless we're on ICQ) */ |
4495 if (!od->icq && curitem->name) { | 4495 if (!od->icq && curitem->name) { |
4496 /* if (!find_permdeny_by_name(gc->permit, curitem->name)) { AAA */ | 4496 for (cur = account->permit; (cur && oscar_util_name_compare(curitem->name, cur->data)); cur = cur->next); |
4497 GSList *list; | 4497 if (!cur) { |
4498 for (list=account->permit; (list && oscar_util_name_compare(curitem->name, list->data)); list=list->next); | |
4499 if (!list) { | |
4500 purple_debug_info("oscar", | 4498 purple_debug_info("oscar", |
4501 "ssi: adding permit buddy %s to local list\n", curitem->name); | 4499 "ssi: adding permit buddy %s to local list\n", curitem->name); |
4502 purple_privacy_permit_add(account, curitem->name, TRUE); | 4500 purple_privacy_permit_add(account, curitem->name, TRUE); |
4503 } | 4501 } |
4504 } | 4502 } |
4505 } break; | 4503 } break; |
4506 | 4504 |
4507 case AIM_SSI_TYPE_ICQDENY: | 4505 case AIM_SSI_TYPE_ICQDENY: |
4508 case AIM_SSI_TYPE_DENY: { /* Deny buddy */ | 4506 case AIM_SSI_TYPE_DENY: { /* Deny buddy */ |
4509 if (curitem->type == deny_entry_type && curitem->name) { | 4507 if (curitem->type == deny_entry_type && curitem->name) { |
4510 GSList *list; | 4508 for (cur = account->deny; (cur && oscar_util_name_compare(curitem->name, cur->data)); cur = cur->next); |
4511 for (list=account->deny; (list && oscar_util_name_compare(curitem->name, list->data)); list=list->next); | 4509 if (!cur) { |
4512 if (!list) { | |
4513 purple_debug_info("oscar", | 4510 purple_debug_info("oscar", |
4514 "ssi: adding deny buddy %s to local list\n", curitem->name); | 4511 "ssi: adding deny buddy %s to local list\n", curitem->name); |
4515 purple_privacy_deny_add(account, curitem->name, TRUE); | 4512 purple_privacy_deny_add(account, curitem->name, TRUE); |
4516 } | 4513 } |
4517 } | 4514 } |
4539 /* We don't want to change Purple's setting because it applies to all accounts */ | 4536 /* We don't want to change Purple's setting because it applies to all accounts */ |
4540 } break; | 4537 } break; |
4541 } /* End of switch on curitem->type */ | 4538 } /* End of switch on curitem->type */ |
4542 } /* End of for loop */ | 4539 } /* End of for loop */ |
4543 | 4540 |
4541 /*** End code for adding from server list to local list ***/ | |
4542 | |
4544 if (od->icq) { | 4543 if (od->icq) { |
4545 oscar_set_icq_permdeny(account); | 4544 oscar_set_icq_permdeny(account); |
4546 } else { | 4545 } else { |
4547 oscar_set_aim_permdeny(gc); | 4546 oscar_set_aim_permdeny(gc); |
4548 } | 4547 } |