comparison src/protocols/jabber/jabber.c @ 4491:3196d9044a45

[gaim-migrate @ 4766] aim_user is dead. long live gaim_account. committer: Tailor Script <tailor@pidgin.im>
author Nathan Walp <nwalp@pidgin.im>
date Fri, 31 Jan 2003 13:03:47 +0000
parents 2afc0f845e74
children 4c40fccbd7c9
comparison
equal deleted inserted replaced
4490:70b892694e0b 4491:3196d9044a45
799 gc->inpa = gaim_input_add(gjc->fd, GAIM_INPUT_READ, jabber_callback, gc); 799 gc->inpa = gaim_input_add(gjc->fd, GAIM_INPUT_READ, jabber_callback, gc);
800 } 800 }
801 801
802 static void gjab_start(gjconn gjc) 802 static void gjab_start(gjconn gjc)
803 { 803 {
804 struct aim_user *user; 804 struct gaim_account *account;
805 int port, rc; 805 int port, rc;
806 char *server; 806 char *server;
807 807
808 if (!gjc || gjc->state != JCONN_STATE_OFF) 808 if (!gjc || gjc->state != JCONN_STATE_OFF)
809 return; 809 return;
810 810
811 user = GJ_GC(gjc)->user; 811 account = GJ_GC(gjc)->account;
812 port = user->proto_opt[USEROPT_PORT][0] ? atoi(user->proto_opt[USEROPT_PORT]) : DEFAULT_PORT; 812 port = account->proto_opt[USEROPT_PORT][0] ? atoi(account->proto_opt[USEROPT_PORT]) : DEFAULT_PORT;
813 server = user->proto_opt[USEROPT_CONN_SERVER][0] ? user->proto_opt[USEROPT_CONN_SERVER] : gjc->user->server; 813 server = account->proto_opt[USEROPT_CONN_SERVER][0] ? account->proto_opt[USEROPT_CONN_SERVER] : gjc->user->server;
814 814
815 815
816 gjc->parser = XML_ParserCreate(NULL); 816 gjc->parser = XML_ParserCreate(NULL);
817 XML_SetUserData(gjc->parser, (void *)gjc); 817 XML_SetUserData(gjc->parser, (void *)gjc);
818 XML_SetElementHandler(gjc->parser, startElement, endElement); 818 XML_SetElementHandler(gjc->parser, startElement, endElement);
819 XML_SetCharacterDataHandler(gjc->parser, charData); 819 XML_SetCharacterDataHandler(gjc->parser, charData);
820 820
821 rc = proxy_connect(server, port, gjab_connected, GJ_GC(gjc)); 821 rc = proxy_connect(server, port, gjab_connected, GJ_GC(gjc));
822 if (!user->gc || (rc != 0)) { 822 if (!account->gc || (rc != 0)) {
823 STATE_EVT(JCONN_STATE_OFF) 823 STATE_EVT(JCONN_STATE_OFF)
824 return; 824 return;
825 } 825 }
826 } 826 }
827 827
962 */ 962 */
963 static void jabber_remove_gaim_buddy(struct gaim_connection *gc, const char *buddyname) 963 static void jabber_remove_gaim_buddy(struct gaim_connection *gc, const char *buddyname)
964 { 964 {
965 struct buddy *b; 965 struct buddy *b;
966 966
967 if ((b = find_buddy(gc->user, buddyname)) != NULL) { 967 if ((b = find_buddy(gc->account, buddyname)) != NULL) {
968 debug_printf("removing buddy [1]: %s\n", buddyname); 968 debug_printf("removing buddy [1]: %s\n", buddyname);
969 remove_buddy(b); 969 remove_buddy(b);
970 gaim_blist_save(); 970 gaim_blist_save();
971 } 971 }
972 } 972 }
1517 static int i = 0x70; 1517 static int i = 0x70;
1518 if ((jc = find_pending_chat(GJ_GC(gjc), gjid)) != NULL) { 1518 if ((jc = find_pending_chat(GJ_GC(gjc), gjid)) != NULL) {
1519 jc->b = cnv = serv_got_joined_chat(GJ_GC(gjc), i++, gjid->user); 1519 jc->b = cnv = serv_got_joined_chat(GJ_GC(gjc), i++, gjid->user);
1520 jc->id = gaim_chat_get_id(GAIM_CHAT(jc->b)); 1520 jc->id = gaim_chat_get_id(GAIM_CHAT(jc->b));
1521 jc->state = JCS_ACTIVE; 1521 jc->state = JCS_ACTIVE;
1522 } else if ((b = find_buddy(GJ_GC(gjc)->user, buddy)) == NULL) { 1522 } else if ((b = find_buddy(GJ_GC(gjc)->account, buddy)) == NULL) {
1523 g_free(buddy); 1523 g_free(buddy);
1524 gaim_jid_free(gjid); 1524 gaim_jid_free(gjid);
1525 return; 1525 return;
1526 } 1526 }
1527 } 1527 }
1622 jabber_accept_deny_add(jap, "subscribed"); 1622 jabber_accept_deny_add(jap, "subscribed");
1623 /* 1623 /*
1624 * If we don't already have the buddy on *our* buddylist, 1624 * If we don't already have the buddy on *our* buddylist,
1625 * ask if we want him or her added. 1625 * ask if we want him or her added.
1626 */ 1626 */
1627 if(find_buddy(jap->gc->user, jap->user) == NULL) { 1627 if(find_buddy(jap->gc->account, jap->user) == NULL) {
1628 show_got_added(jap->gc, NULL, jap->user, NULL, NULL); 1628 show_got_added(jap->gc, NULL, jap->user, NULL, NULL);
1629 } 1629 }
1630 } 1630 }
1631 1631
1632 g_free(jap->user); 1632 g_free(jap->user);
1769 1769
1770 /* 1770 /*
1771 * Add or remove a buddy? Change buddy's alias or group? 1771 * Add or remove a buddy? Change buddy's alias or group?
1772 */ 1772 */
1773 if (BUD_SUB_TO_PEND(sub, ask) || BUD_SUBD_TO(sub, ask)) { 1773 if (BUD_SUB_TO_PEND(sub, ask) || BUD_SUBD_TO(sub, ask)) {
1774 if ((b = find_buddy(GJ_GC(gjc)->user, buddyname)) == NULL) { 1774 if ((b = find_buddy(GJ_GC(gjc)->account, buddyname)) == NULL) {
1775 debug_printf("adding buddy [4]: %s\n", buddyname); 1775 debug_printf("adding buddy [4]: %s\n", buddyname);
1776 b = add_buddy(GJ_GC(gjc)->user, groupname ? groupname : _("Buddies"), buddyname, 1776 b = add_buddy(GJ_GC(gjc)->account,
1777 name ? name : buddyname); 1777 groupname ? groupname : _("Buddies"), buddyname,
1778 name ? name : buddyname);
1778 gaim_blist_save(); 1779 gaim_blist_save();
1779 } else { 1780 } else {
1780 struct group *c_grp = find_group_by_buddy(b); 1781 struct group *c_grp = find_group_by_buddy(b);
1781 1782
1782 /* 1783 /*
1790 1791
1791 /* 1792 /*
1792 * seems rude, but it seems to be the only way... 1793 * seems rude, but it seems to be the only way...
1793 */ 1794 */
1794 remove_buddy(b); 1795 remove_buddy(b);
1795 b = add_buddy(GJ_GC(gjc)->user, groupname, buddyname, 1796 b = add_buddy(GJ_GC(gjc)->account, groupname, buddyname,
1796 name ? name : buddyname); 1797 name ? name : buddyname);
1797 gaim_blist_save(); 1798 gaim_blist_save();
1798 if(present) { 1799 if(present) {
1799 serv_got_update(GJ_GC(gjc), buddyname, 1, 0, signon, idle, 1800 serv_got_update(GJ_GC(gjc), buddyname, 1, 0, signon, idle,
1800 uc, 0); 1801 uc, 0);
2317 debug_printf("state change: %d\n", state); 2318 debug_printf("state change: %d\n", state);
2318 } 2319 }
2319 return; 2320 return;
2320 } 2321 }
2321 2322
2322 static void jabber_login(struct aim_user *user) 2323 static void jabber_login(struct gaim_account *account)
2323 { 2324 {
2324 struct gaim_connection *gc = new_gaim_conn(user); 2325 struct gaim_connection *gc = new_gaim_conn(account);
2325 struct jabber_data *jd = gc->proto_data = g_new0(struct jabber_data, 1); 2326 struct jabber_data *jd = gc->proto_data = g_new0(struct jabber_data, 1);
2326 char *loginname = create_valid_jid(user->username, DEFAULT_SERVER, "Gaim"); 2327 char *loginname = create_valid_jid(account->username, DEFAULT_SERVER, "Gaim");
2327 2328
2328 jd->buddies = g_hash_table_new(g_str_hash, g_str_equal); 2329 jd->buddies = g_hash_table_new(g_str_hash, g_str_equal);
2329 jd->chats = NULL; /* we have no chats yet */ 2330 jd->chats = NULL; /* we have no chats yet */
2330 2331
2331 set_login_progress(gc, 1, _("Connecting")); 2332 set_login_progress(gc, 1, _("Connecting"));
2332 2333
2333 if (!(jd->gjc = gjab_new(loginname, user->password, gc))) { 2334 if (!(jd->gjc = gjab_new(loginname, account->password, gc))) {
2334 g_free(loginname); 2335 g_free(loginname);
2335 debug_printf("jabber: unable to connect (jab_new failed)\n"); 2336 debug_printf("jabber: unable to connect (jab_new failed)\n");
2336 hide_login_progress(gc, _("Unable to connect")); 2337 hide_login_progress(gc, _("Unable to connect"));
2337 signoff(gc); 2338 signoff(gc);
2338 return; 2339 return;
2532 2533
2533 x = jutil_iqnew(JPACKET__SET, NS_ROSTER); 2534 x = jutil_iqnew(JPACKET__SET, NS_ROSTER);
2534 y = xmlnode_insert_tag(xmlnode_get_tag(x, "query"), "item"); 2535 y = xmlnode_insert_tag(xmlnode_get_tag(x, "query"), "item");
2535 xmlnode_put_attrib(y, "jid", realwho); 2536 xmlnode_put_attrib(y, "jid", realwho);
2536 2537
2537 buddy = find_buddy(gc->user, realwho); 2538 buddy = find_buddy(gc->account, realwho);
2538 2539
2539 /* 2540 /*
2540 * See if there's an explict (new?) alias for the buddy or we can pull 2541 * See if there's an explict (new?) alias for the buddy or we can pull
2541 * one out of current Gaim buddylist data for him. 2542 * one out of current Gaim buddylist data for him.
2542 */ 2543 */
2935 debug_printf("joining completely new Jabber chat\n"); 2936 debug_printf("joining completely new Jabber chat\n");
2936 jc = g_new0(struct jabber_chat, 1); 2937 jc = g_new0(struct jabber_chat, 1);
2937 jc->gjid = gjid; 2938 jc->gjid = gjid;
2938 jc->gc = gc; 2939 jc->gc = gc;
2939 ((struct jabber_data *)gc->proto_data)->chats = g_slist_append(jcs, jc); 2940 ((struct jabber_data *)gc->proto_data)->chats = g_slist_append(jcs, jc);
2940 add_buddy(gc->user, _("Chats"), realwho, realwho); 2941 add_buddy(gc->account, _("Chats"), realwho, realwho);
2941 } 2942 }
2942 2943
2943 jc->state = JCS_PENDING; 2944 jc->state = JCS_PENDING;
2944 2945
2945 x = jutil_presnew(0, realwho, NULL); 2946 x = jutil_presnew(0, realwho, NULL);
3240 } 3241 }
3241 3242
3242 static GList *jabber_buddy_menu(struct gaim_connection *gc, char *who) { 3243 static GList *jabber_buddy_menu(struct gaim_connection *gc, char *who) {
3243 GList *m = NULL; 3244 GList *m = NULL;
3244 struct proto_buddy_menu *pbm; 3245 struct proto_buddy_menu *pbm;
3245 struct buddy *b = find_buddy(gc->user, who); 3246 struct buddy *b = find_buddy(gc->account, who);
3246 3247
3247 if(b->uc == UC_ERROR) 3248 if(b->uc == UC_ERROR)
3248 { 3249 {
3249 pbm = g_new0(struct proto_buddy_menu, 1); 3250 pbm = g_new0(struct proto_buddy_menu, 1);
3250 pbm->label = _("View Error Msg"); 3251 pbm->label = _("View Error Msg");
3874 const struct vcard_template *vc_tp; 3875 const struct vcard_template *vc_tp;
3875 char *user_info; 3876 char *user_info;
3876 MultiEntryDlg *b = multi_entry_dialog_new(); 3877 MultiEntryDlg *b = multi_entry_dialog_new();
3877 char *cdata; 3878 char *cdata;
3878 xmlnode x_vc_data = NULL; 3879 xmlnode x_vc_data = NULL;
3879 struct aim_user *tmp = gc->user; 3880 struct gaim_account *tmp = gc->account;
3880 b->user = tmp; 3881 b->account = tmp;
3881 3882
3882 3883
3883 /* 3884 /*
3884 * Get existing, XML-formatted, user info 3885 * Get existing, XML-formatted, user info
3885 */ 3886 */
4125 } 4126 }
4126 4127
4127 /* 4128 /*
4128 * Like jabber_login(), only different 4129 * Like jabber_login(), only different
4129 */ 4130 */
4130 void jabber_register_user(struct aim_user *au) 4131 void jabber_register_user(struct gaim_account *account)
4131 { 4132 {
4132 struct gaim_connection *gc = new_gaim_conn(au); 4133 struct gaim_connection *gc = new_gaim_conn(account);
4133 struct jabber_data *jd = gc->proto_data = g_new0(struct jabber_data, 1); 4134 struct jabber_data *jd = gc->proto_data = g_new0(struct jabber_data, 1);
4134 char *loginname = create_valid_jid(au->username, DEFAULT_SERVER, "Gaim"); 4135 char *loginname = create_valid_jid(account->username, DEFAULT_SERVER, "Gaim");
4135 4136
4136 /* 4137 /*
4137 * These do nothing during registration 4138 * These do nothing during registration
4138 */ 4139 */
4139 jd->buddies = NULL; 4140 jd->buddies = NULL;
4140 jd->chats = NULL; 4141 jd->chats = NULL;
4141 4142
4142 if ((jd->gjc = gjab_new(loginname, au->password, gc)) == NULL) { 4143 if ((jd->gjc = gjab_new(loginname, account->password, gc)) == NULL) {
4143 g_free(loginname); 4144 g_free(loginname);
4144 debug_printf("jabber: unable to connect (jab_new failed)\n"); 4145 debug_printf("jabber: unable to connect (jab_new failed)\n");
4145 hide_login_progress(gc, _("Unable to connect")); 4146 hide_login_progress(gc, _("Unable to connect"));
4146 signoff(gc); 4147 signoff(gc);
4147 } else { 4148 } else {