comparison libpurple/protocols/jabber/google.c @ 28767:9ab75ab032b4

jabber: The google roster request code was so lonely, so let's just drop-kick it and add the little custom logic to roster.c
author Paul Aurich <paul@darkrain42.org>
date Sun, 06 Dec 2009 22:44:20 +0000
parents edf0aa0e55cb
children c38f6e6bf4ce d4ec9ba82814
comparison
equal deleted inserted replaced
28766:4e9a36bdda0f 28767:9ab75ab032b4
948 iq = jabber_iq_new_query(js, JABBER_IQ_GET, NS_GOOGLE_MAIL_NOTIFY); 948 iq = jabber_iq_new_query(js, JABBER_IQ_GET, NS_GOOGLE_MAIL_NOTIFY);
949 jabber_iq_set_callback(iq, jabber_gmail_parse, NULL); 949 jabber_iq_set_callback(iq, jabber_gmail_parse, NULL);
950 jabber_iq_send(iq); 950 jabber_iq_send(iq);
951 } 951 }
952 952
953 static void
954 roster_init_cb(JabberStream *js, const char *from, JabberIqType type,
955 const char *id, xmlnode *packet, gpointer data)
956 {
957 xmlnode *query = xmlnode_get_child(packet, "query");
958
959 if (type == JABBER_IQ_RESULT && query)
960 jabber_roster_parse(js, from, type, id, query);
961
962 jabber_stream_set_state(js, JABBER_STREAM_CONNECTED);
963 }
964
965 void jabber_google_roster_init(JabberStream *js)
966 {
967 JabberIq *iq;
968 xmlnode *query;
969
970 iq = jabber_iq_new_query(js, JABBER_IQ_GET, "jabber:iq:roster");
971 query = xmlnode_get_child(iq->node, "query");
972
973 xmlnode_set_attrib(query, "xmlns:gr", "google:roster");
974 xmlnode_set_attrib(query, "gr:ext", "2");
975
976 jabber_iq_set_callback(iq, roster_init_cb, NULL);
977 jabber_iq_send(iq);
978 }
979
980 void jabber_google_roster_outgoing(JabberStream *js, xmlnode *query, xmlnode *item) 953 void jabber_google_roster_outgoing(JabberStream *js, xmlnode *query, xmlnode *item)
981 { 954 {
982 PurpleAccount *account = purple_connection_get_account(js->gc); 955 PurpleAccount *account = purple_connection_get_account(js->gc);
983 GSList *list = account->deny; 956 GSList *list = account->deny;
984 const char *jid = xmlnode_get_attrib(item, "jid"); 957 const char *jid = xmlnode_get_attrib(item, "jid");
985 char *jid_norm = (char *)jabber_normalize(account, jid); 958 char *jid_norm = (char *)jabber_normalize(account, jid);
986 959
987 while (list) { 960 while (list) {
988 if (!strcmp(jid_norm, (char*)list->data)) { 961 if (!strcmp(jid_norm, (char*)list->data)) {
989 xmlnode_set_attrib(query, "xmlns:gr", "google:roster"); 962 xmlnode_set_attrib(query, "xmlns:gr", NS_GOOGLE_ROSTER);
990 xmlnode_set_attrib(query, "gr:ext", "2"); 963 xmlnode_set_attrib(query, "gr:ext", "2");
991 xmlnode_set_attrib(item, "gr:t", "B"); 964 xmlnode_set_attrib(item, "gr:t", "B");
992 return; 965 return;
993 } 966 }
994 list = list->next; 967 list = list->next;
1001 const char *jid = xmlnode_get_attrib(item, "jid"); 974 const char *jid = xmlnode_get_attrib(item, "jid");
1002 gboolean on_block_list = FALSE; 975 gboolean on_block_list = FALSE;
1003 976
1004 char *jid_norm; 977 char *jid_norm;
1005 978
1006 const char *grt = xmlnode_get_attrib_with_namespace(item, "t", "google:roster"); 979 const char *grt = xmlnode_get_attrib_with_namespace(item, "t", NS_GOOGLE_ROSTER);
1007 const char *subscription = xmlnode_get_attrib(item, "subscription"); 980 const char *subscription = xmlnode_get_attrib(item, "subscription");
1008 const char *ask = xmlnode_get_attrib(item, "ask"); 981 const char *ask = xmlnode_get_attrib(item, "ask");
1009 982
1010 if ((!subscription || !strcmp(subscription, "none")) && !ask) { 983 if ((!subscription || !strcmp(subscription, "none")) && !ask) {
1011 /* The Google Talk servers will automatically add people from your Gmail address book 984 /* The Google Talk servers will automatically add people from your Gmail address book
1086 1059
1087 balias = purple_buddy_get_local_buddy_alias(b); 1060 balias = purple_buddy_get_local_buddy_alias(b);
1088 xmlnode_set_attrib(item, "jid", who); 1061 xmlnode_set_attrib(item, "jid", who);
1089 xmlnode_set_attrib(item, "name", balias ? balias : ""); 1062 xmlnode_set_attrib(item, "name", balias ? balias : "");
1090 xmlnode_set_attrib(item, "gr:t", "B"); 1063 xmlnode_set_attrib(item, "gr:t", "B");
1091 xmlnode_set_attrib(query, "xmlns:gr", "google:roster"); 1064 xmlnode_set_attrib(query, "xmlns:gr", NS_GOOGLE_ROSTER);
1092 xmlnode_set_attrib(query, "gr:ext", "2"); 1065 xmlnode_set_attrib(query, "gr:ext", "2");
1093 1066
1094 jabber_iq_send(iq); 1067 jabber_iq_send(iq);
1095 1068
1096 /* Synthesize a sign-off */ 1069 /* Synthesize a sign-off */
1145 } 1118 }
1146 1119
1147 balias = purple_buddy_get_local_buddy_alias(b); 1120 balias = purple_buddy_get_local_buddy_alias(b);
1148 xmlnode_set_attrib(item, "jid", who); 1121 xmlnode_set_attrib(item, "jid", who);
1149 xmlnode_set_attrib(item, "name", balias ? balias : ""); 1122 xmlnode_set_attrib(item, "name", balias ? balias : "");
1150 xmlnode_set_attrib(query, "xmlns:gr", "google:roster"); 1123 xmlnode_set_attrib(query, "xmlns:gr", NS_GOOGLE_ROSTER);
1151 xmlnode_set_attrib(query, "gr:ext", "2"); 1124 xmlnode_set_attrib(query, "gr:ext", "2");
1152 1125
1153 jabber_iq_send(iq); 1126 jabber_iq_send(iq);
1154 1127
1155 /* See if he's online */ 1128 /* See if he's online */