Mercurial > pidgin
comparison plugins/jabber/jabber.c @ 1778:9bc21732ba79
[gaim-migrate @ 1788]
i'm kinda tired
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Mon, 30 Apr 2001 11:45:49 +0000 |
parents | 896432d66303 |
children | cf7806e63d0c |
comparison
equal
deleted
inserted
replaced
1777:c728b05731b8 | 1778:9bc21732ba79 |
---|---|
114 struct jabber_data { | 114 struct jabber_data { |
115 gjconn jc; | 115 gjconn jc; |
116 gboolean did_import; | 116 gboolean did_import; |
117 GSList *pending_chats; | 117 GSList *pending_chats; |
118 GSList *existing_chats; | 118 GSList *existing_chats; |
119 GHashTable *hash; | |
119 }; | 120 }; |
120 | 121 |
121 static char *jabber_name() | 122 static char *jabber_name() |
122 { | 123 { |
123 return "Jabber"; | 124 return "Jabber"; |
715 } | 716 } |
716 if (!b->proto_data) { | 717 if (!b->proto_data) { |
717 serv_got_update(GJ_GC(j), buddy, 0, 0, 0, 0, 0, 0); | 718 serv_got_update(GJ_GC(j), buddy, 0, 0, 0, 0, 0, 0); |
718 } | 719 } |
719 } else { | 720 } else { |
721 /* keep track of away msg same as yahoo plugin */ | |
722 struct jabber_data *jd = GJ_GC(j)->proto_data; | |
723 gpointer val = g_hash_table_lookup(jd->hash, b->name); | |
724 if (val) | |
725 g_free(val); | |
726 g_hash_table_insert(jd->hash, g_strdup(b->name), g_strdup(xmlnode_get_tag_data(p->x, "status"))); | |
727 | |
728 | |
720 if (!resources) { | 729 if (!resources) { |
721 b->proto_data = g_slist_append(b->proto_data, g_strdup(res)); | 730 b->proto_data = g_slist_append(b->proto_data, g_strdup(res)); |
722 } | 731 } |
732 | |
723 serv_got_update(GJ_GC(j), buddy, 1, 0, 0, 0, state, 0); | 733 serv_got_update(GJ_GC(j), buddy, 1, 0, 0, 0, state, 0); |
734 | |
724 } | 735 } |
725 } else { | 736 } else { |
726 if (who->resource) { | 737 if (who->resource) { |
727 if (type && !strcmp(type, "unavailable")) { | 738 if (type && !strcmp(type, "unavailable")) { |
728 struct jabber_data *jd = GJ_GC(j)->proto_data; | 739 struct jabber_data *jd = GJ_GC(j)->proto_data; |
855 x = jutil_presnew(0, NULL, "Online"); | 866 x = jutil_presnew(0, NULL, "Online"); |
856 gjab_send(j, x); | 867 gjab_send(j, x); |
857 xmlnode_free(x); | 868 xmlnode_free(x); |
858 } | 869 } |
859 | 870 |
871 static void jabber_handlevcard(gjconn j, xmlnode querynode, char *from) { | |
872 char buf[1024]; | |
873 char *fn, *url, *email, *nickname, *status; | |
874 jid who; | |
875 char *buddy; | |
876 struct jabber_data *jd = GJ_GC(j)->proto_data; | |
877 int at = 0; | |
878 | |
879 who = jid_new(j->p, from); | |
880 buddy = g_strdup_printf("%s@%s", who->user, who->server); | |
881 | |
882 fn = xmlnode_get_tag_data(querynode, "FN"); | |
883 url = xmlnode_get_tag_data(querynode, "URL"); | |
884 email = xmlnode_get_tag_data(querynode, "EMAIL"); | |
885 nickname = xmlnode_get_tag_data(querynode, "NICKNAME"); | |
886 status = g_hash_table_lookup(jd->hash, buddy); | |
887 if (!status) | |
888 status = "Online"; | |
889 | |
890 at = g_snprintf(buf, sizeof buf, "<B>Jabber ID:</B> %s<BR>", buddy); | |
891 if (fn) | |
892 at += g_snprintf(buf + at, sizeof(buf) - at, "<B>Full Name:</B> %s<BR>", fn); | |
893 if (nickname) | |
894 at += g_snprintf(buf + at, sizeof(buf) - at, "<B>Nickname:</B> %s<BR>", nickname); | |
895 if (url) | |
896 at += g_snprintf(buf + at, sizeof(buf) - at, "<B>URL:</B> <A HREF=\"%s\">%s</A><BR>", | |
897 url, url); | |
898 if (email) | |
899 at += g_snprintf(buf + at, sizeof(buf) - at, | |
900 "<B>Email:</B> <A HREF=\"mailto:%s\">%s</A><BR>", email, email); | |
901 at += g_snprintf(buf + at, sizeof(buf) - at, "<B>Status:</B> %s\n", status); | |
902 | |
903 g_show_info_text(buf); | |
904 g_free(buddy); | |
905 } | |
906 | |
860 static void jabber_handlepacket(gjconn j, jpacket p) | 907 static void jabber_handlepacket(gjconn j, jpacket p) |
861 { | 908 { |
862 switch (p->type) { | 909 switch (p->type) { |
863 case JPACKET_MESSAGE: | 910 case JPACKET_MESSAGE: |
864 jabber_handlemessage(j, p); | 911 jabber_handlemessage(j, p); |
870 debug_printf("jpacket_subtype: %d\n", jpacket_subtype(p)); | 917 debug_printf("jpacket_subtype: %d\n", jpacket_subtype(p)); |
871 | 918 |
872 if (jpacket_subtype(p) == JPACKET__SET) { | 919 if (jpacket_subtype(p) == JPACKET__SET) { |
873 } else if (jpacket_subtype(p) == JPACKET__GET) { | 920 } else if (jpacket_subtype(p) == JPACKET__GET) { |
874 } else if (jpacket_subtype(p) == JPACKET__RESULT) { | 921 } else if (jpacket_subtype(p) == JPACKET__RESULT) { |
875 xmlnode querynode; | 922 xmlnode querynode, vcard; |
876 char *xmlns, *from; | 923 char *xmlns, *from; |
877 | 924 |
878 from = xmlnode_get_attrib(p->x, "from"); | 925 from = xmlnode_get_attrib(p->x, "from"); |
879 querynode = xmlnode_get_tag(p->x, "query"); | 926 querynode = xmlnode_get_tag(p->x, "query"); |
880 xmlns = xmlnode_get_attrib(querynode, "xmlns"); | 927 xmlns = xmlnode_get_attrib(querynode, "xmlns"); |
928 vcard = xmlnode_get_tag(p->x, "vCard"); | |
881 | 929 |
882 if ((!xmlns && !from) || NSCHECK(querynode, NS_AUTH)) { | 930 if ((!xmlns && !from) || NSCHECK(querynode, NS_AUTH)) { |
883 debug_printf("auth success\n"); | 931 debug_printf("auth success\n"); |
884 | 932 |
885 account_online(GJ_GC(j)); | 933 account_online(GJ_GC(j)); |
892 | 940 |
893 gjab_reqroster(j); | 941 gjab_reqroster(j); |
894 | 942 |
895 } else if (NSCHECK(querynode, NS_ROSTER)) { | 943 } else if (NSCHECK(querynode, NS_ROSTER)) { |
896 jabber_handleroster(j, querynode); | 944 jabber_handleroster(j, querynode); |
945 } else if (NSCHECK(querynode, NS_VCARD)) { | |
946 jabber_handlevcard(j, querynode, from); | |
947 } else if(vcard) { | |
948 jabber_handlevcard(j, vcard, from); | |
897 } else { | 949 } else { |
898 /* debug_printf("jabber:iq:query: %s\n", xmlns); */ | 950 /* debug_printf("jabber:iq:query: %s\n", xmlns); */ |
899 } | 951 } |
900 } else { | 952 } else { |
901 xmlnode x; | 953 xmlnode x; |
950 { | 1002 { |
951 struct gaim_connection *gc = new_gaim_conn(user); | 1003 struct gaim_connection *gc = new_gaim_conn(user); |
952 struct jabber_data *jd = gc->proto_data = g_new0(struct jabber_data, 1); | 1004 struct jabber_data *jd = gc->proto_data = g_new0(struct jabber_data, 1); |
953 char *loginname = create_valid_jid(user->username, DEFAULT_SERVER, "GAIM"); | 1005 char *loginname = create_valid_jid(user->username, DEFAULT_SERVER, "GAIM"); |
954 | 1006 |
1007 jd->hash = g_hash_table_new(g_str_hash, g_str_equal); | |
1008 | |
955 set_login_progress(gc, 1, "Connecting"); | 1009 set_login_progress(gc, 1, "Connecting"); |
956 | 1010 |
957 if (!(jd->jc = gjab_new(loginname, user->password, gc))) { | 1011 if (!(jd->jc = gjab_new(loginname, user->password, gc))) { |
958 g_free(loginname); | 1012 g_free(loginname); |
959 debug_printf("jabber: unable to connect (jab_new failed)\n"); | 1013 debug_printf("jabber: unable to connect (jab_new failed)\n"); |
972 jabber_callback, gc); | 1026 jabber_callback, gc); |
973 | 1027 |
974 return; | 1028 return; |
975 } | 1029 } |
976 | 1030 |
1031 static gboolean jabber_destroy_hash(gpointer key, gpointer val, gpointer data) { | |
1032 g_free(key); | |
1033 g_free(val); | |
1034 return TRUE; | |
1035 } | |
1036 | |
977 static void jabber_close(struct gaim_connection *gc) | 1037 static void jabber_close(struct gaim_connection *gc) |
978 { | 1038 { |
979 struct jabber_data *jd = gc->proto_data; | 1039 struct jabber_data *jd = gc->proto_data; |
1040 g_hash_table_foreach_remove(jd->hash, jabber_destroy_hash, NULL); | |
1041 g_hash_table_destroy(jd->hash); | |
980 gdk_input_remove(gc->inpa); | 1042 gdk_input_remove(gc->inpa); |
981 gjab_delete(jd->jc); | 1043 gjab_delete(jd->jc); |
982 jd->jc = NULL; | 1044 jd->jc = NULL; |
983 g_free(jd); | 1045 g_free(jd); |
984 gc->proto_data = NULL; | 1046 gc->proto_data = NULL; |
1351 } | 1413 } |
1352 | 1414 |
1353 static void regpacket(jconn j, jpacket p) | 1415 static void regpacket(jconn j, jpacket p) |
1354 { | 1416 { |
1355 static int here = 0; | 1417 static int here = 0; |
1356 g_print("here\n"); | |
1357 switch (p->type) { | 1418 switch (p->type) { |
1358 case JPACKET_MESSAGE: | 1419 case JPACKET_MESSAGE: |
1359 break; | 1420 break; |
1360 case JPACKET_PRESENCE: | 1421 case JPACKET_PRESENCE: |
1361 break; | 1422 break; |
1378 " added to the Account Editor.", "Jabber " | 1439 " added to the Account Editor.", "Jabber " |
1379 "Registration"); | 1440 "Registration"); |
1380 gtk_entry_set_text(GTK_ENTRY(newname), ""); | 1441 gtk_entry_set_text(GTK_ENTRY(newname), ""); |
1381 gtk_entry_set_text(GTK_ENTRY(newpass1), ""); | 1442 gtk_entry_set_text(GTK_ENTRY(newpass1), ""); |
1382 gtk_entry_set_text(GTK_ENTRY(newpass2), ""); | 1443 gtk_entry_set_text(GTK_ENTRY(newpass2), ""); |
1383 g_print("reg\n"); | |
1384 return; | 1444 return; |
1385 } else if (here == 1) { | 1445 } else if (here == 1) { |
1386 x = jutil_iqnew(JPACKET__SET, NS_AUTH); | 1446 x = jutil_iqnew(JPACKET__SET, NS_AUTH); |
1387 here = 2; | 1447 here = 2; |
1388 } else if (here == 0) { | 1448 } else if (here == 0) { |
1506 } | 1566 } |
1507 | 1567 |
1508 return buf; | 1568 return buf; |
1509 } | 1569 } |
1510 | 1570 |
1571 static void jabber_get_info(struct gaim_connection *gc, char *who) { | |
1572 xmlnode x; | |
1573 char *id; | |
1574 struct jabber_data *jd = gc->proto_data; | |
1575 gjconn j = jd->jc; | |
1576 | |
1577 x = jutil_iqnew(JPACKET__GET, NS_VCARD); | |
1578 xmlnode_put_attrib(x, "to", who); | |
1579 id = gjab_getid(j); | |
1580 xmlnode_put_attrib(x, "id", id); | |
1581 | |
1582 gjab_send(j, x); | |
1583 | |
1584 xmlnode_free(x); | |
1585 | |
1586 } | |
1587 | |
1588 static void jabber_info(GtkObject *obj, char *who) { | |
1589 serv_get_info(gtk_object_get_user_data(obj), who); | |
1590 } | |
1591 | |
1592 static void jabber_buddy_menu(GtkWidget *menu, struct gaim_connection *gc, char *who) { | |
1593 GtkWidget *button; | |
1594 char buf[1024]; | |
1595 struct buddy *b = find_buddy(gc, who); | |
1596 struct jabber_data *jd = gc->proto_data; | |
1597 char *status; | |
1598 | |
1599 button = gtk_menu_item_new_with_label(_("Get Info")); | |
1600 gtk_signal_connect(GTK_OBJECT(button), "activate", | |
1601 GTK_SIGNAL_FUNC(jabber_info), who); | |
1602 gtk_object_set_user_data(GTK_OBJECT(button), gc); | |
1603 gtk_menu_append(GTK_MENU(menu), button); | |
1604 gtk_widget_show(button); | |
1605 | |
1606 status = g_hash_table_lookup(jd->hash, b->name); | |
1607 if (!status || !strcasecmp("Online", status)) | |
1608 return; | |
1609 | |
1610 g_snprintf(buf, sizeof buf, "Status: %s",status); | |
1611 | |
1612 button = gtk_menu_item_new_with_label(buf); | |
1613 gtk_menu_append(GTK_MENU(menu), button); | |
1614 gtk_widget_show(button); | |
1615 } | |
1616 | |
1511 static GList *jabber_away_states() { | 1617 static GList *jabber_away_states() { |
1512 GList *m = NULL; | 1618 GList *m = NULL; |
1513 | 1619 |
1514 m = g_list_append(m, "Online"); | 1620 m = g_list_append(m, "Online"); |
1515 m = g_list_append(m, "Chatty"); | 1621 m = g_list_append(m, "Chatty"); |
1577 ret->protocol = PROTO_JABBER; | 1683 ret->protocol = PROTO_JABBER; |
1578 ret->options = OPT_PROTO_UNIQUE_CHATNAME | OPT_PROTO_CHAT_TOPIC; | 1684 ret->options = OPT_PROTO_UNIQUE_CHATNAME | OPT_PROTO_CHAT_TOPIC; |
1579 ret->name = jabber_name; | 1685 ret->name = jabber_name; |
1580 ret->list_icon = jabber_list_icon; | 1686 ret->list_icon = jabber_list_icon; |
1581 ret->away_states = jabber_away_states; | 1687 ret->away_states = jabber_away_states; |
1582 ret->buddy_menu = NULL; | 1688 ret->buddy_menu = jabber_buddy_menu; |
1583 ret->user_opts = NULL; | 1689 ret->user_opts = NULL; |
1584 ret->draw_new_user = jabber_draw_new_user; | 1690 ret->draw_new_user = jabber_draw_new_user; |
1585 ret->do_new_user = jabber_do_new_user; | 1691 ret->do_new_user = jabber_do_new_user; |
1586 ret->login = jabber_login; | 1692 ret->login = jabber_login; |
1587 ret->close = jabber_close; | 1693 ret->close = jabber_close; |
1588 ret->send_im = jabber_send_im; | 1694 ret->send_im = jabber_send_im; |
1589 ret->set_info = NULL; | 1695 ret->set_info = NULL; |
1590 ret->get_info = NULL; | 1696 ret->get_info = jabber_get_info; |
1591 ret->set_away = jabber_set_away; | 1697 ret->set_away = jabber_set_away; |
1592 ret->get_away_msg = NULL; | 1698 ret->get_away_msg = NULL; |
1593 ret->set_dir = NULL; | 1699 ret->set_dir = NULL; |
1594 ret->get_dir = NULL; | 1700 ret->get_dir = NULL; |
1595 ret->dir_search = NULL; | 1701 ret->dir_search = NULL; |