Mercurial > pidgin.yaz
comparison src/protocols/jabber/jabber.c @ 3770:a72e303e6f5c
[gaim-migrate @ 3909]
I think I'm out of that sort of mood now.
committer: Tailor Script <tailor@pidgin.im>
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Sun, 20 Oct 2002 19:41:28 +0000 |
parents | 303e40b66b96 |
children | 43e396e94095 |
comparison
equal
deleted
inserted
replaced
3769:303e40b66b96 | 3770:a72e303e6f5c |
---|---|
174 | 174 |
175 /* | 175 /* |
176 * per-resource info | 176 * per-resource info |
177 */ | 177 */ |
178 typedef struct jabber_resource_info { | 178 typedef struct jabber_resource_info { |
179 char *name; | 179 char *name; |
180 int priority; | 180 int priority; |
181 int state; | 181 int state; |
182 char *away_msg; | 182 char *away_msg; |
183 char *thread_id; | 183 char *thread_id; |
184 gboolean has_composing; | 184 gboolean has_composing; |
1030 g_hash_table_insert(jd->buddies, g_strdup(realwho), jbd); | 1030 g_hash_table_insert(jd->buddies, g_strdup(realwho), jbd); |
1031 g_free(realwho); | 1031 g_free(realwho); |
1032 return jbd; | 1032 return jbd; |
1033 } | 1033 } |
1034 } | 1034 } |
1035 | 1035 |
1036 /* | 1036 /* |
1037 * find a resource by name, or if no name given, return the "default" resource | 1037 * find a resource by name, or if no name given, return the "default" resource |
1038 * default being the highest priority one. | 1038 * default being the highest priority one. |
1039 */ | 1039 */ |
1040 | 1040 |
1041 static jab_res_info jabber_find_resource(struct gaim_connection *gc, char *who) | 1041 static jab_res_info jabber_find_resource(struct gaim_connection *gc, char *who) |
1042 { | 1042 { |
1043 GSList *resources; | 1043 GSList *resources; |
1154 | 1154 |
1155 jri = jabber_find_resource(GJ_GC(gjc), jid_full(p->from)); | 1155 jri = jabber_find_resource(GJ_GC(gjc), jid_full(p->from)); |
1156 | 1156 |
1157 if(!jri) | 1157 if(!jri) |
1158 return; | 1158 return; |
1159 | 1159 |
1160 if (type && (strcasecmp(type, "unavailable") == 0)) { | 1160 if (type && (strcasecmp(type, "unavailable") == 0)) { |
1161 vshow = _("Unavailable"); | 1161 vshow = _("Unavailable"); |
1162 } else { | 1162 } else { |
1163 if((show = xmlnode_get_tag_data(p->x, "show")) != NULL) { | 1163 if((show = xmlnode_get_tag_data(p->x, "show")) != NULL) { |
1164 if (!strcasecmp(show, "away")) { | 1164 if (!strcasecmp(show, "away")) { |
1381 if ((y = xmlnode_get_tag(p->x, "body"))) { | 1381 if ((y = xmlnode_get_tag(p->x, "body"))) { |
1382 msg = xmlnode_get_data(y); | 1382 msg = xmlnode_get_data(y); |
1383 } | 1383 } |
1384 | 1384 |
1385 if ((subj = xmlnode_get_tag(p->x, "subject"))) { | 1385 if ((subj = xmlnode_get_tag(p->x, "subject"))) { |
1386 topic = xmlnode_get_data(subj); | 1386 topic = xmlnode_get_data(subj); |
1387 } | 1387 } |
1388 | 1388 |
1389 jc = find_existing_chat(GJ_GC(gjc), p->from); | 1389 jc = find_existing_chat(GJ_GC(gjc), p->from); |
1390 if (!jc) { | 1390 if (!jc) { |
1391 /* we're not in this chat. are we supposed to be? */ | 1391 /* we're not in this chat. are we supposed to be? */ |
1392 if ((jc = find_pending_chat(GJ_GC(gjc), p->from)) != NULL) { | 1392 if ((jc = find_pending_chat(GJ_GC(gjc), p->from)) != NULL) { |
1419 g_snprintf(buf, sizeof(buf), "%s", msg); | 1419 g_snprintf(buf, sizeof(buf), "%s", msg); |
1420 serv_got_chat_in(GJ_GC(gjc), jc->b->id, p->from->resource, 0, buf, | 1420 serv_got_chat_in(GJ_GC(gjc), jc->b->id, p->from->resource, 0, buf, |
1421 time_sent); | 1421 time_sent); |
1422 } | 1422 } |
1423 } else { /* message from the server */ | 1423 } else { /* message from the server */ |
1424 if(jc->b && topic) { | 1424 if(jc->b && topic) { |
1425 char tbuf[8192]; | 1425 char tbuf[8192]; |
1426 g_snprintf(tbuf, sizeof(tbuf), "%s", topic); | 1426 g_snprintf(tbuf, sizeof(tbuf), "%s", topic); |
1427 chat_set_topic(jc->b, "", tbuf); | 1427 chat_set_topic(jc->b, "", tbuf); |
1428 } | 1428 } |
1429 } | 1429 } |
1430 | 1430 |
1431 } else { | 1431 } else { |
1432 debug_printf("unhandled message %s\n", type); | 1432 debug_printf("unhandled message %s\n", type); |
1433 } | 1433 } |
1434 } | 1434 } |
1435 | 1435 |
1436 static void jabber_handlepresence(gjconn gjc, jpacket p) | 1436 static void jabber_handlepresence(gjconn gjc, jpacket p) |
1437 { | 1437 { |
1438 char *to, *from, *type; | 1438 char *to, *from, *type; |
1439 struct buddy *b = NULL; | 1439 struct buddy *b = NULL; |
1440 gaim_jid gjid; | 1440 gaim_jid gjid; |
1444 int state = 0; | 1444 int state = 0; |
1445 struct conversation *cnv = NULL; | 1445 struct conversation *cnv = NULL; |
1446 struct jabber_chat *jc = NULL; | 1446 struct jabber_chat *jc = NULL; |
1447 int priority = 0; | 1447 int priority = 0; |
1448 struct jabber_buddy_data *jbd; | 1448 struct jabber_buddy_data *jbd; |
1449 | 1449 |
1450 to = xmlnode_get_attrib(p->x, "to"); | 1450 to = xmlnode_get_attrib(p->x, "to"); |
1451 from = xmlnode_get_attrib(p->x, "from"); | 1451 from = xmlnode_get_attrib(p->x, "from"); |
1452 type = xmlnode_get_attrib(p->x, "type"); | 1452 type = xmlnode_get_attrib(p->x, "type"); |
1453 | 1453 |
1454 if((buddy = get_realwho(gjc, from, FALSE, &gjid)) == NULL) | 1454 if((buddy = get_realwho(gjc, from, FALSE, &gjid)) == NULL) |
1455 return; | 1455 return; |
1456 | 1456 |
1457 if (gjid->user == NULL) { | 1457 if (gjid->user == NULL) { |
1458 /* FIXME: transport */ | 1458 /* FIXME: transport */ |
1494 state = 0; | 1494 state = 0; |
1495 } | 1495 } |
1496 } | 1496 } |
1497 | 1497 |
1498 if ((y = xmlnode_get_tag(p->x, "priority"))) | 1498 if ((y = xmlnode_get_tag(p->x, "priority"))) |
1499 priority = atoi(xmlnode_get_data(y)); | 1499 priority = atoi(xmlnode_get_data(y)); |
1500 | 1500 |
1501 /* um. we're going to check if it's a chat. if it isn't, and there are pending | 1501 /* um. we're going to check if it's a chat. if it isn't, and there are pending |
1502 * chats, create the chat. if there aren't pending chats and we don't have the | 1502 * chats, create the chat. if there aren't pending chats and we don't have the |
1503 * buddy on our list, simply bail out. */ | 1503 * buddy on our list, simply bail out. */ |
1504 if ((cnv = find_chat(GJ_GC(gjc), gjid->user)) == NULL) { | 1504 if ((cnv = find_chat(GJ_GC(gjc), gjid->user)) == NULL) { |
1520 jabber_track_resource(GJ_GC(gjc), buddy, gjid->resource, priority, state); | 1520 jabber_track_resource(GJ_GC(gjc), buddy, gjid->resource, priority, state); |
1521 | 1521 |
1522 /* keep track of away msg somewhat the same as the yahoo plugin */ | 1522 /* keep track of away msg somewhat the same as the yahoo plugin */ |
1523 jabber_track_away(gjc, p, type); | 1523 jabber_track_away(gjc, p, type); |
1524 } | 1524 } |
1525 | 1525 |
1526 | 1526 |
1527 if (!cnv) { | 1527 if (!cnv) { |
1528 /* this is where we handle presence information for "regular" buddies */ | 1528 /* this is where we handle presence information for "regular" buddies */ |
1529 jab_res_info jri = jabber_find_resource(GJ_GC(gjc), buddy); | 1529 jab_res_info jri = jabber_find_resource(GJ_GC(gjc), buddy); |
1530 if(jri) { | 1530 if(jri) { |
1687 | 1687 |
1688 /* | 1688 /* |
1689 * Pending subscription to a buddy? | 1689 * Pending subscription to a buddy? |
1690 */ | 1690 */ |
1691 #define BUD_SUB_TO_PEND(sub, ask) ((!strcasecmp((sub), "none") || !strcasecmp((sub), "from")) && \ | 1691 #define BUD_SUB_TO_PEND(sub, ask) ((!strcasecmp((sub), "none") || !strcasecmp((sub), "from")) && \ |
1692 (ask) != NULL && !strcasecmp((ask), "subscribe")) | 1692 (ask) != NULL && !strcasecmp((ask), "subscribe")) |
1693 | 1693 |
1694 /* | 1694 /* |
1695 * Subscribed to a buddy? | 1695 * Subscribed to a buddy? |
1696 */ | 1696 */ |
1697 #define BUD_SUBD_TO(sub, ask) ((!strcasecmp((sub), "to") || !strcasecmp((sub), "both")) && \ | 1697 #define BUD_SUBD_TO(sub, ask) ((!strcasecmp((sub), "to") || !strcasecmp((sub), "both")) && \ |
1758 name ? name : buddyname); | 1758 name ? name : buddyname); |
1759 do_export(GJ_GC(gjc)); | 1759 do_export(GJ_GC(gjc)); |
1760 } else { | 1760 } else { |
1761 struct group *c_grp = find_group_by_buddy(GJ_GC(gjc), buddyname); | 1761 struct group *c_grp = find_group_by_buddy(GJ_GC(gjc), buddyname); |
1762 | 1762 |
1763 /* | 1763 /* |
1764 * If the buddy's in a new group or his/her alias is changed... | 1764 * If the buddy's in a new group or his/her alias is changed... |
1765 */ | 1765 */ |
1766 if(groupname && c_grp && strcmp(c_grp->name, groupname)) { | 1766 if(groupname && c_grp && strcmp(c_grp->name, groupname)) { |
1767 int present = b->present; /* save presence state */ | 1767 int present = b->present; /* save presence state */ |
1768 int uc = b->uc; /* and away state (?) */ | 1768 int uc = b->uc; /* and away state (?) */ |
1885 } | 1885 } |
1886 | 1886 |
1887 static void jabber_handletime(gjconn gjc, xmlnode iqnode) { | 1887 static void jabber_handletime(gjconn gjc, xmlnode iqnode) { |
1888 xmlnode querynode, x; | 1888 xmlnode querynode, x; |
1889 char *id, *from; | 1889 char *id, *from; |
1890 time_t now_t; | 1890 time_t now_t; |
1891 struct tm *now; | 1891 struct tm *now; |
1892 char buf[1024]; | 1892 char buf[1024]; |
1893 | 1893 |
1894 time(&now_t); | 1894 time(&now_t); |
1895 now = localtime(&now_t); | 1895 now = localtime(&now_t); |
1907 xmlnode_insert_cdata(xmlnode_insert_tag(querynode, "utc"), buf, -1); | 1907 xmlnode_insert_cdata(xmlnode_insert_tag(querynode, "utc"), buf, -1); |
1908 strftime(buf, 1024, "%Z", now); | 1908 strftime(buf, 1024, "%Z", now); |
1909 xmlnode_insert_cdata(xmlnode_insert_tag(querynode, "tz"), buf, -1); | 1909 xmlnode_insert_cdata(xmlnode_insert_tag(querynode, "tz"), buf, -1); |
1910 strftime(buf, 1024, "%d %b %Y %T", now); | 1910 strftime(buf, 1024, "%d %b %Y %T", now); |
1911 xmlnode_insert_cdata(xmlnode_insert_tag(querynode, "display"), buf, -1); | 1911 xmlnode_insert_cdata(xmlnode_insert_tag(querynode, "display"), buf, -1); |
1912 | 1912 |
1913 gjab_send(gjc, x); | 1913 gjab_send(gjc, x); |
1914 | 1914 |
1915 xmlnode_free(x); | 1915 xmlnode_free(x); |
1916 } | 1916 } |
1917 | 1917 |
2190 jabber_handlebuddy(gjc, xmlnode_get_firstchild(querynode)); | 2190 jabber_handlebuddy(gjc, xmlnode_get_firstchild(querynode)); |
2191 } else if(NSCHECK(querynode, "jabber:iq:oob")) { | 2191 } else if(NSCHECK(querynode, "jabber:iq:oob")) { |
2192 jabber_handleoob(gjc, p->x); | 2192 jabber_handleoob(gjc, p->x); |
2193 } | 2193 } |
2194 } else if (jpacket_subtype(p) == JPACKET__GET) { | 2194 } else if (jpacket_subtype(p) == JPACKET__GET) { |
2195 xmlnode querynode; | 2195 xmlnode querynode; |
2196 querynode = xmlnode_get_tag(p->x, "query"); | 2196 querynode = xmlnode_get_tag(p->x, "query"); |
2197 if (NSCHECK(querynode, NS_VERSION)) { | 2197 if (NSCHECK(querynode, NS_VERSION)) { |
2198 jabber_handleversion(gjc, p->x); | 2198 jabber_handleversion(gjc, p->x); |
2199 } else if (NSCHECK(querynode, NS_TIME)) { | 2199 } else if (NSCHECK(querynode, NS_TIME)) { |
2200 jabber_handletime(gjc, p->x); | 2200 jabber_handletime(gjc, p->x); |
2201 } else if (NSCHECK(querynode, "jabber:iq:last")) { | 2201 } else if (NSCHECK(querynode, "jabber:iq:last")) { |
2202 jabber_handlelast(gjc, p->x); | 2202 jabber_handlelast(gjc, p->x); |
2203 } | 2203 } |
2204 } else if (jpacket_subtype(p) == JPACKET__RESULT) { | 2204 } else if (jpacket_subtype(p) == JPACKET__RESULT) { |
2205 xmlnode querynode, vcard; | 2205 xmlnode querynode, vcard; |
2206 char *xmlns, *from; | 2206 char *xmlns, *from; |
2207 | 2207 |
2216 | 2216 |
2217 if (NSCHECK(querynode, NS_ROSTER)) { | 2217 if (NSCHECK(querynode, NS_ROSTER)) { |
2218 jabber_handleroster(gjc, querynode); | 2218 jabber_handleroster(gjc, querynode); |
2219 } else if (NSCHECK(querynode, NS_VCARD)) { | 2219 } else if (NSCHECK(querynode, NS_VCARD)) { |
2220 jabber_track_queries(gjc->queries, id, TRUE); /* delete query track */ | 2220 jabber_track_queries(gjc->queries, id, TRUE); /* delete query track */ |
2221 jabber_handlevcard(gjc, querynode, from); | 2221 jabber_handlevcard(gjc, querynode, from); |
2222 } else if (vcard) { | 2222 } else if (vcard) { |
2223 jabber_track_queries(gjc->queries, id, TRUE); /* delete query track */ | 2223 jabber_track_queries(gjc->queries, id, TRUE); /* delete query track */ |
2224 jabber_handlevcard(gjc, vcard, from); | 2224 jabber_handlevcard(gjc, vcard, from); |
2225 } else if((xmlns = xmlnode_get_attrib(querynode, "xmlns")) != NULL) { | 2225 } else if((xmlns = xmlnode_get_attrib(querynode, "xmlns")) != NULL) { |
2226 debug_printf("jabber:iq:query: %s\n", xmlns); | 2226 debug_printf("jabber:iq:query: %s\n", xmlns); |
2328 jd->gjc->queries = g_hash_table_new(g_str_hash, g_str_equal); | 2328 jd->gjc->queries = g_hash_table_new(g_str_hash, g_str_equal); |
2329 gjab_start(jd->gjc); | 2329 gjab_start(jd->gjc); |
2330 } | 2330 } |
2331 | 2331 |
2332 static gboolean jabber_destroy_hash(gpointer key, gpointer val, gpointer data) { | 2332 static gboolean jabber_destroy_hash(gpointer key, gpointer val, gpointer data) { |
2333 g_free(key); | 2333 g_free(key); |
2334 g_free(val); | 2334 g_free(val); |
2335 return TRUE; | 2335 return TRUE; |
2336 } | 2336 } |
2337 | 2337 |
2338 static gboolean jabber_destroy_buddy_hash(gpointer key, gpointer val, gpointer data) { | 2338 static gboolean jabber_destroy_buddy_hash(gpointer key, gpointer val, gpointer data) { |
2496 gjconn gjc; | 2496 gjconn gjc; |
2497 struct buddy *buddy = NULL; | 2497 struct buddy *buddy = NULL; |
2498 struct group *buddy_group = NULL; | 2498 struct group *buddy_group = NULL; |
2499 char *my_alias = NULL; | 2499 char *my_alias = NULL; |
2500 char *my_group = NULL; | 2500 char *my_group = NULL; |
2501 | 2501 |
2502 if(gc && gc->proto_data && ((struct jabber_data *)gc->proto_data)->gjc && name) { | 2502 if(gc && gc->proto_data && ((struct jabber_data *)gc->proto_data)->gjc && name) { |
2503 gaim_jid gjid; | 2503 gaim_jid gjid; |
2504 gjc = ((struct jabber_data *)gc->proto_data)->gjc; | 2504 gjc = ((struct jabber_data *)gc->proto_data)->gjc; |
2505 | 2505 |
2506 if((realwho = get_realwho(gjc, name, FALSE, &gjid)) == NULL) | 2506 if((realwho = get_realwho(gjc, name, FALSE, &gjid)) == NULL) |
3123 jbd = jabber_find_buddy(gc, realwho); | 3123 jbd = jabber_find_buddy(gc, realwho); |
3124 | 3124 |
3125 *ap++ = g_strdup_printf("<B>Jabber ID:</B> %s<BR>\n", realwho); | 3125 *ap++ = g_strdup_printf("<B>Jabber ID:</B> %s<BR>\n", realwho); |
3126 *ap++ = g_strdup_printf("<B>Error:</B> %s<BR>\n", jbd->error_msg); | 3126 *ap++ = g_strdup_printf("<B>Error:</B> %s<BR>\n", jbd->error_msg); |
3127 *ap = NULL; | 3127 *ap = NULL; |
3128 | 3128 |
3129 final= g_strjoinv(NULL, str_arr); | 3129 final= g_strjoinv(NULL, str_arr); |
3130 | 3130 |
3131 g_strfreev(str_arr); | 3131 g_strfreev(str_arr); |
3132 | 3132 |
3133 g_show_info_text(gc, realwho, 2, final, NULL); | 3133 g_show_info_text(gc, realwho, 2, final, NULL); |
3134 g_free(realwho); | 3134 g_free(realwho); |
3135 g_free(final); | 3135 g_free(final); |
3176 g_free(realwho); | 3176 g_free(realwho); |
3177 resources = resources->next; | 3177 resources = resources->next; |
3178 } | 3178 } |
3179 | 3179 |
3180 *ap = NULL; | 3180 *ap = NULL; |
3181 | 3181 |
3182 g_free(buddy); | 3182 g_free(buddy); |
3183 | 3183 |
3184 final= g_strjoinv(NULL, str_arr); | 3184 final= g_strjoinv(NULL, str_arr); |
3185 g_strfreev(str_arr); | 3185 g_strfreev(str_arr); |
3186 | 3186 |
3187 g_show_info_text(gc, who, 2, final, NULL); | 3187 g_show_info_text(gc, who, 2, final, NULL); |
3188 g_free(final); | 3188 g_free(final); |
3189 | 3189 |
3190 } | 3190 } |
3191 | 3191 |
3192 static void jabber_get_cb_info(struct gaim_connection *gc, int cid, char *who) { | 3192 static void jabber_get_cb_info(struct gaim_connection *gc, int cid, char *who) { |
3193 struct jabber_chat *jc = NULL; | 3193 struct jabber_chat *jc = NULL; |
3194 char *realwho; | 3194 char *realwho; |
3379 } | 3379 } |
3380 | 3380 |
3381 static void jabber_set_idle(struct gaim_connection *gc, int idle) { | 3381 static void jabber_set_idle(struct gaim_connection *gc, int idle) { |
3382 struct jabber_data *jd = (struct jabber_data *)gc->proto_data; | 3382 struct jabber_data *jd = (struct jabber_data *)gc->proto_data; |
3383 debug_printf("jabber_set_idle: setting idle %i\n", idle); | 3383 debug_printf("jabber_set_idle: setting idle %i\n", idle); |
3384 jd->idle = idle ? time(NULL) - idle : idle; | 3384 jd->idle = idle ? time(NULL) - idle : idle; |
3385 } | 3385 } |
3386 | 3386 |
3387 static void jabber_keepalive(struct gaim_connection *gc) { | 3387 static void jabber_keepalive(struct gaim_connection *gc) { |
3388 struct jabber_data *jd = (struct jabber_data *)gc->proto_data; | 3388 struct jabber_data *jd = (struct jabber_data *)gc->proto_data; |
3389 gjab_send_raw(jd->gjc, " \t "); | 3389 gjab_send_raw(jd->gjc, " \t "); |
3762 | 3762 |
3763 x = xmlnode_new_tag("iq"); | 3763 x = xmlnode_new_tag("iq"); |
3764 xmlnode_put_attrib(x, "type", "set"); | 3764 xmlnode_put_attrib(x, "type", "set"); |
3765 | 3765 |
3766 id = gjab_getid(gjc); | 3766 id = gjab_getid(gjc); |
3767 | 3767 |
3768 xmlnode_put_attrib(x, "id", id); | 3768 xmlnode_put_attrib(x, "id", id); |
3769 | 3769 |
3770 /* | 3770 /* |
3771 * Send only if there's actually any *information* to send | 3771 * Send only if there's actually any *information* to send |
3772 */ | 3772 */ |