comparison src/protocols/oscar/oscar.c @ 8150:20262ccefdd8

[gaim-migrate @ 8862] Nope, it's humor. Trust me, I know--I define it. Oh, also, this should make oscar ssi lists take precedence over local lists. So if you sign on while you're in Rome and delete someone, the next time you sign in with Gaim the dude will be deleted from your local list as well. committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Tue, 20 Jan 2004 15:27:33 +0000
parents 8633dc570442
children b619ee745ec0
comparison
equal deleted inserted replaced
8149:eb2a420060f8 8150:20262ccefdd8
4655 aim_search_address(od->sess, od->conn, email); 4655 aim_search_address(od->sess, od->conn, email);
4656 } 4656 }
4657 4657
4658 static void oscar_add_buddy(GaimConnection *gc, const char *name, GaimGroup *g) { 4658 static void oscar_add_buddy(GaimConnection *gc, const char *name, GaimGroup *g) {
4659 OscarData *od = (OscarData *)gc->proto_data; 4659 OscarData *od = (OscarData *)gc->proto_data;
4660 GaimBuddy *b;
4661
4662 if (g == NULL) {
4663 /* If we were called from oscar_add_buddies... */
4664 b = gaim_find_buddy(gaim_connection_get_account(gc), name);
4665 g = gaim_find_buddys_group(b);
4666 } else
4667 b = gaim_find_buddy_in_group(gaim_connection_get_account(gc), name, g);
4660 4668
4661 if (!aim_snvalid(name)) { 4669 if (!aim_snvalid(name)) {
4662 gchar *buf; 4670 gchar *buf;
4663 buf = g_strdup_printf(_("Could not add the buddy %s because the screen name is invalid. Screen names must either start with a letter and contain only letters, numbers and spaces, or contain only numbers. The buddy will be removed from your buddy list."), name); 4671 buf = g_strdup_printf(_("Could not add the buddy %s because the screen name is invalid. Screen names must either start with a letter and contain only letters, numbers and spaces, or contain only numbers."), name);
4664 gaim_notify_error(gc, NULL, _("Unable To Add"), buf); 4672 gaim_notify_error(gc, NULL, _("Unable To Add"), buf);
4665 g_free(buf); 4673 g_free(buf);
4666 /* ABC - Remove from locate list! */ 4674
4675 /* Remove from local list */
4676 gaim_blist_remove_buddy(b);
4677
4667 return; 4678 return;
4668 } 4679 }
4669 4680
4670 #ifdef NOSSI 4681 #ifdef NOSSI
4671 aim_buddylist_addbuddy(od->sess, od->conn, name); 4682 aim_buddylist_addbuddy(od->sess, od->conn, name);
4672 #else 4683 #else
4673 if ((od->sess->ssi.received_data) && !(aim_ssi_itemlist_exists(od->sess->ssi.local, name))) { 4684 if ((od->sess->ssi.received_data) && !(aim_ssi_itemlist_exists(od->sess->ssi.local, name))) {
4674 GaimBuddy *buddy = gaim_find_buddy(gc->account, name); 4685 if (b && g) {
4675 GaimGroup *group = gaim_find_buddys_group(buddy);
4676 if (buddy && group) {
4677 gaim_debug(GAIM_DEBUG_INFO, "oscar", 4686 gaim_debug(GAIM_DEBUG_INFO, "oscar",
4678 "ssi: adding buddy %s to group %s\n", name, group->name); 4687 "ssi: adding buddy %s to group %s\n", name, g->name);
4679 aim_ssi_addbuddy(od->sess, buddy->name, group->name, gaim_get_buddy_alias_only(buddy), NULL, NULL, 0); 4688 aim_ssi_addbuddy(od->sess, b->name, g->name, gaim_get_buddy_alias_only(b), NULL, NULL, 0);
4680 } 4689 }
4681 } 4690 }
4682 #endif 4691 #endif
4692
4683 if (od->icq) 4693 if (od->icq)
4684 aim_icq_getalias(od->sess, name); 4694 aim_icq_getalias(od->sess, name);
4685 } 4695 }
4686 4696
4687 static void oscar_add_buddies(GaimConnection *gc, GList *buddies) { 4697 static void oscar_add_buddies(GaimConnection *gc, GList *buddies) {
4692 while (buddies) { 4702 while (buddies) {
4693 if (n > MSG_LEN - 18) { 4703 if (n > MSG_LEN - 18) {
4694 aim_buddylist_set(od->sess, od->conn, buf); 4704 aim_buddylist_set(od->sess, od->conn, buf);
4695 n = 0; 4705 n = 0;
4696 } 4706 }
4697 n += g_snprintf(buf + n, sizeof(buf) - n, "%s&", (char *)buddies->data); 4707 n += g_snprintf(buf + n, sizeof(buf) - n, "%s&", (const char *)buddies->data);
4698 buddies = buddies->next; 4708 buddies = buddies->next;
4699 } 4709 }
4700 aim_buddylist_set(od->sess, od->conn, buf); 4710 aim_buddylist_set(od->sess, od->conn, buf);
4701 #else 4711 #else
4702 if (od->sess->ssi.received_data) { 4712 if (od->sess->ssi.received_data) {
4728 for (cur=buddies; cur; cur=cur->next) 4738 for (cur=buddies; cur; cur=cur->next)
4729 aim_buddylist_removebuddy(od->sess, od->conn, cur->data); 4739 aim_buddylist_removebuddy(od->sess, od->conn, cur->data);
4730 #else 4740 #else
4731 if (od->sess->ssi.received_data) { 4741 if (od->sess->ssi.received_data) {
4732 while (buddies) { 4742 while (buddies) {
4733 gaim_debug(GAIM_DEBUG_INFO, "oscar", 4743 oscar_remove_buddy(gc, buddies->data, group);
4734 "ssi: deleting buddy %s from group %s\n", (char *)buddies->data, group);
4735 aim_ssi_delbuddy(od->sess, buddies->data, group);
4736 buddies = buddies->next; 4744 buddies = buddies->next;
4737 } 4745 }
4738 } 4746 }
4739 #endif 4747 #endif
4740 } 4748 }
4845 4853
4846 static int gaim_ssi_parselist(aim_session_t *sess, aim_frame_t *fr, ...) { 4854 static int gaim_ssi_parselist(aim_session_t *sess, aim_frame_t *fr, ...) {
4847 GaimConnection *gc = sess->aux_data; 4855 GaimConnection *gc = sess->aux_data;
4848 GaimAccount *account = gaim_connection_get_account(gc); 4856 GaimAccount *account = gaim_connection_get_account(gc);
4849 OscarData *od = (OscarData *)gc->proto_data; 4857 OscarData *od = (OscarData *)gc->proto_data;
4858 GaimGroup *g;
4859 GaimBuddy *b;
4850 struct aim_ssi_item *curitem; 4860 struct aim_ssi_item *curitem;
4851 int tmp; 4861 int tmp;
4852 gboolean export = FALSE;
4853 /* XXX - use these? 4862 /* XXX - use these?
4854 va_list ap; 4863 va_list ap;
4855 4864
4856 va_start(ap, fr); 4865 va_start(ap, fr);
4857 fmtver = (fu16_t)va_arg(ap, int); 4866 fmtver = (fu16_t)va_arg(ap, int);
4863 gaim_debug(GAIM_DEBUG_INFO, "oscar", 4872 gaim_debug(GAIM_DEBUG_INFO, "oscar",
4864 "ssi: syncing local list and server list\n"); 4873 "ssi: syncing local list and server list\n");
4865 4874
4866 /* Clean the buddy list */ 4875 /* Clean the buddy list */
4867 aim_ssi_cleanlist(sess); 4876 aim_ssi_cleanlist(sess);
4877
4878 { /* If not in server list then prune from local list */
4879 GaimBlistNode *gnode, *cnode, *bnode;
4880 GaimBuddyList *blist;
4881 GSList *cur;
4882
4883 /* Buddies */
4884 cur = NULL;
4885 if ((blist = gaim_get_blist()) != NULL) {
4886 for (gnode = blist->root; gnode; gnode = gnode->next) {
4887 if(!GAIM_BLIST_NODE_IS_GROUP(gnode))
4888 continue;
4889 g = (GaimGroup *)gnode;
4890 for (cnode = gnode->child; cnode; cnode = cnode->next) {
4891 if(!GAIM_BLIST_NODE_IS_CONTACT(cnode))
4892 continue;
4893 for (bnode = cnode->child; bnode; bnode = bnode->next) {
4894 if(!GAIM_BLIST_NODE_IS_BUDDY(bnode))
4895 continue;
4896 b = (GaimBuddy *)bnode;
4897 if (b->account == gc->account) {
4898 if (aim_ssi_itemlist_exists(sess->ssi.local, b->name)) {
4899 /* If the buddy is an ICQ user then load his nickname */
4900 const char *servernick = gaim_blist_node_get_string((GaimBlistNode*)b, "servernick");
4901 if (servernick)
4902 serv_got_alias(gc, b->name, servernick);
4903
4904 /* Store local alias on server */
4905 char *alias = aim_ssi_getalias(sess->ssi.local, g->name, b->name);
4906 if (!alias && b->alias && strlen(b->alias))
4907 aim_ssi_aliasbuddy(sess, g->name, b->name, b->alias);
4908 free(alias);
4909 } else {
4910 gaim_debug(GAIM_DEBUG_INFO, "oscar",
4911 "ssi: removing buddy %s from local list\n", b->name);
4912 /* We can't actually remove now because it will screw up our looping */
4913 cur = g_slist_prepend(cur, b);
4914 }
4915 }
4916 }
4917 }
4918 }
4919 }
4920 while (cur != NULL) {
4921 b = cur->data;
4922 cur = g_slist_remove(cur, b);
4923 gaim_blist_remove_buddy(b);
4924 }
4925
4926 /* Permit list */
4927 if (gc->account->permit) {
4928 for (cur=gc->account->permit; cur; cur=cur->next)
4929 if (!aim_ssi_itemlist_finditem(sess->ssi.local, NULL, cur->data, AIM_SSI_TYPE_PERMIT)) {
4930 gaim_debug(GAIM_DEBUG_INFO, "oscar",
4931 "ssi: removing permit %s from local list\n", (const char *)cur->data);
4932 gaim_privacy_permit_remove(account, cur->data, TRUE);
4933 cur = gc->account->permit;
4934 }
4935 }
4936
4937 /* Deny list */
4938 if (gc->account->deny) {
4939 for (cur=gc->account->deny; cur; cur=cur->next)
4940 if (!aim_ssi_itemlist_finditem(sess->ssi.local, NULL, cur->data, AIM_SSI_TYPE_DENY)) {
4941 gaim_debug(GAIM_DEBUG_INFO, "oscar",
4942 "ssi: removing deny %s from local list\n", (const char *)cur->data);
4943 gaim_privacy_deny_remove(account, cur->data, TRUE);
4944 cur = gc->account->deny;
4945 }
4946 }
4947 /* Presence settings (idle time visibility) */
4948 if ((tmp = aim_ssi_getpresence(sess->ssi.local)) != 0xFFFFFFFF)
4949 if (!(tmp & 0x400))
4950 aim_ssi_setpresence(sess, tmp | 0x400);
4951 } /* end pruning buddies from local list */
4868 4952
4869 /* Add from server list to local list */ 4953 /* Add from server list to local list */
4870 for (curitem=sess->ssi.local; curitem; curitem=curitem->next) { 4954 for (curitem=sess->ssi.local; curitem; curitem=curitem->next) {
4871 if ((curitem->name == NULL) || (g_utf8_validate(curitem->name, -1, NULL))) 4955 if ((curitem->name == NULL) || (g_utf8_validate(curitem->name, -1, NULL)))
4872 switch (curitem->type) { 4956 switch (curitem->type) {
4874 if (curitem->name) { 4958 if (curitem->name) {
4875 char *gname = aim_ssi_itemlist_findparentname(sess->ssi.local, curitem->name); 4959 char *gname = aim_ssi_itemlist_findparentname(sess->ssi.local, curitem->name);
4876 char *gname_utf8 = gname ? gaim_utf8_try_convert(gname) : NULL; 4960 char *gname_utf8 = gname ? gaim_utf8_try_convert(gname) : NULL;
4877 char *alias = aim_ssi_getalias(sess->ssi.local, gname, curitem->name); 4961 char *alias = aim_ssi_getalias(sess->ssi.local, gname, curitem->name);
4878 char *alias_utf8 = alias ? gaim_utf8_try_convert(alias) : NULL; 4962 char *alias_utf8 = alias ? gaim_utf8_try_convert(alias) : NULL;
4879 GaimBuddy *buddy = gaim_find_buddy(gc->account, curitem->name); 4963 b = gaim_find_buddy(gc->account, curitem->name);
4880 /* Should gname be freed here? -- elb */ 4964 /* Should gname be freed here? -- elb */
4881 /* Not with the current code, but that might be cleaner -- med */ 4965 /* Not with the current code, but that might be cleaner -- med */
4882 free(alias); 4966 free(alias);
4883 if (buddy) { 4967 if (b) {
4884 /* Get server stored alias */ 4968 /* Get server stored alias */
4885 if (alias_utf8) { 4969 if (alias_utf8) {
4886 g_free(buddy->alias); 4970 g_free(b->alias);
4887 buddy->alias = g_strdup(alias_utf8); 4971 b->alias = g_strdup(alias_utf8);
4888 } 4972 }
4889 } else { 4973 } else {
4890 GaimGroup *g; 4974 b = gaim_buddy_new(gc->account, curitem->name, alias_utf8);
4891 buddy = gaim_buddy_new(gc->account, curitem->name, alias_utf8);
4892 4975
4893 if (!(g = gaim_find_group(gname_utf8 ? gname_utf8 : _("Orphans")))) { 4976 if (!(g = gaim_find_group(gname_utf8 ? gname_utf8 : _("Orphans")))) {
4894 g = gaim_group_new(gname_utf8 ? gname_utf8 : _("Orphans")); 4977 g = gaim_group_new(gname_utf8 ? gname_utf8 : _("Orphans"));
4895 gaim_blist_add_group(g, NULL); 4978 gaim_blist_add_group(g, NULL);
4896 } 4979 }
4897 4980
4898 gaim_debug(GAIM_DEBUG_INFO, "oscar", 4981 gaim_debug(GAIM_DEBUG_INFO, "oscar",
4899 "ssi: adding buddy %s to group %s to local list\n", curitem->name, gname_utf8 ? gname_utf8 : _("Orphans")); 4982 "ssi: adding b %s to group %s to local list\n", curitem->name, gname_utf8 ? gname_utf8 : _("Orphans"));
4900 gaim_blist_add_buddy(buddy, NULL, g, NULL); 4983 gaim_blist_add_buddy(b, NULL, g, NULL);
4901 export = TRUE;
4902 } 4984 }
4903 g_free(gname_utf8); 4985 g_free(gname_utf8);
4904 g_free(alias_utf8); 4986 g_free(alias_utf8);
4905 } 4987 }
4906 } break; 4988 } break;
4916 for (list=account->permit; (list && aim_sncmp(curitem->name, list->data)); list=list->next); 4998 for (list=account->permit; (list && aim_sncmp(curitem->name, list->data)); list=list->next);
4917 if (!list) { 4999 if (!list) {
4918 gaim_debug(GAIM_DEBUG_INFO, "oscar", 5000 gaim_debug(GAIM_DEBUG_INFO, "oscar",
4919 "ssi: adding permit buddy %s to local list\n", curitem->name); 5001 "ssi: adding permit buddy %s to local list\n", curitem->name);
4920 gaim_privacy_permit_add(account, curitem->name, TRUE); 5002 gaim_privacy_permit_add(account, curitem->name, TRUE);
4921 export = TRUE;
4922 } 5003 }
4923 } 5004 }
4924 } break; 5005 } break;
4925 5006
4926 case 0x0003: { /* Deny buddy */ 5007 case 0x0003: { /* Deny buddy */
4929 for (list=account->deny; (list && aim_sncmp(curitem->name, list->data)); list=list->next); 5010 for (list=account->deny; (list && aim_sncmp(curitem->name, list->data)); list=list->next);
4930 if (!list) { 5011 if (!list) {
4931 gaim_debug(GAIM_DEBUG_INFO, "oscar", 5012 gaim_debug(GAIM_DEBUG_INFO, "oscar",
4932 "ssi: adding deny buddy %s to local list\n", curitem->name); 5013 "ssi: adding deny buddy %s to local list\n", curitem->name);
4933 gaim_privacy_deny_add(account, curitem->name, TRUE); 5014 gaim_privacy_deny_add(account, curitem->name, TRUE);
4934 export = TRUE;
4935 } 5015 }
4936 } 5016 }
4937 } break; 5017 } break;
4938 5018
4939 case 0x0004: { /* Permit/deny setting */ 5019 case 0x0004: { /* Permit/deny setting */
4944 "ssi: changing permdeny from %d to %hhu\n", account->perm_deny, permdeny); 5024 "ssi: changing permdeny from %d to %hhu\n", account->perm_deny, permdeny);
4945 account->perm_deny = permdeny; 5025 account->perm_deny = permdeny;
4946 if (od->icq && account->perm_deny == 0x03) { 5026 if (od->icq && account->perm_deny == 0x03) {
4947 serv_set_away(gc, "Invisible", ""); 5027 serv_set_away(gc, "Invisible", "");
4948 } 5028 }
4949 export = TRUE;
4950 } 5029 }
4951 } 5030 }
4952 } break; 5031 } break;
4953 5032
4954 case 0x0005: { /* Presence setting */ 5033 case 0x0005: { /* Presence setting */
4955 /* We don't want to change Gaim's setting because it applies to all accounts */ 5034 /* We don't want to change Gaim's setting because it applies to all accounts */
4956 } break; 5035 } break;
4957 } /* End of switch on curitem->type */ 5036 } /* End of switch on curitem->type */
4958 } /* End of for loop */ 5037 } /* End of for loop */
4959
4960 /* If changes were made, then flush buddy list to file */
4961 if (export)
4962 gaim_blist_save();
4963
4964 { /* Add from local list to server list */
4965 GaimBlistNode *gnode, *cnode, *bnode;
4966 GaimGroup *group;
4967 GaimBuddy *buddy;
4968 GaimBuddyList *blist;
4969 GSList *cur;
4970
4971 /* Buddies */
4972 if ((blist = gaim_get_blist()))
4973 for (gnode = blist->root; gnode; gnode = gnode->next) {
4974 if(!GAIM_BLIST_NODE_IS_GROUP(gnode))
4975 continue;
4976 group = (GaimGroup *)gnode;
4977 for (cnode = gnode->child; cnode; cnode = cnode->next) {
4978 if(!GAIM_BLIST_NODE_IS_CONTACT(cnode))
4979 continue;
4980 for (bnode = cnode->child; bnode; bnode = bnode->next) {
4981 if(!GAIM_BLIST_NODE_IS_BUDDY(bnode))
4982 continue;
4983 buddy = (GaimBuddy *)bnode;
4984 if (buddy->account == gc->account) {
4985 const char *servernick = gaim_blist_node_get_string((GaimBlistNode*)buddy, "servernick");
4986 if (servernick)
4987 serv_got_alias(gc, buddy->name, servernick);
4988
4989 if (aim_ssi_itemlist_exists(sess->ssi.local, buddy->name)) {
4990 /* Store local alias on server */
4991 char *alias = aim_ssi_getalias(sess->ssi.local, group->name, buddy->name);
4992 if (!alias && buddy->alias && strlen(buddy->alias))
4993 aim_ssi_aliasbuddy(sess, group->name, buddy->name, buddy->alias);
4994 free(alias);
4995 } else {
4996 gaim_debug(GAIM_DEBUG_INFO, "oscar",
4997 "ssi: adding buddy %s from local list to server list\n", buddy->name);
4998 oscar_add_buddy(gc, buddy->name, group);
4999 }
5000 }
5001 }
5002 }
5003 }
5004
5005 /* Permit list */
5006 if (gc->account->permit) {
5007 for (cur=gc->account->permit; cur; cur=cur->next)
5008 if (!aim_ssi_itemlist_finditem(sess->ssi.local, NULL, cur->data, AIM_SSI_TYPE_PERMIT)) {
5009 gaim_debug(GAIM_DEBUG_INFO, "oscar",
5010 "ssi: adding permit %s from local list to server list\n", (char *)cur->data);
5011 aim_ssi_addpermit(sess, cur->data);
5012 }
5013 }
5014
5015 /* Deny list */
5016 if (gc->account->deny) {
5017 for (cur=gc->account->deny; cur; cur=cur->next)
5018 if (!aim_ssi_itemlist_finditem(sess->ssi.local, NULL, cur->data, AIM_SSI_TYPE_DENY)) {
5019 gaim_debug(GAIM_DEBUG_INFO, "oscar",
5020 "ssi: adding deny %s from local list to server list\n", (char *)cur->data);
5021 aim_ssi_adddeny(sess, cur->data);
5022 }
5023 }
5024 /* Presence settings (idle time visibility) */
5025 if ((tmp = aim_ssi_getpresence(sess->ssi.local)) != 0xFFFFFFFF)
5026 if (!(tmp & 0x400))
5027 aim_ssi_setpresence(sess, tmp | 0x400);
5028 } /* end adding buddies from local list to server list */
5029 5038
5030 /* Set our ICQ status */ 5039 /* Set our ICQ status */
5031 if (od->icq && !gc->away) { 5040 if (od->icq && !gc->away) {
5032 aim_setextstatus(sess, AIM_ICQ_STATE_NORMAL); 5041 aim_setextstatus(sess, AIM_ICQ_STATE_NORMAL);
5033 } 5042 }