comparison src/protocols/jabber/jabber.c @ 3236:6796fdeed022

[gaim-migrate @ 3253] Added code to detect invalid JIDs and prevent Gaim from crashing on them. Removed "safety check" call in jabber_handlebuddy() to apparently broken xmlnode_get_datasz() function. committer: Tailor Script <tailor@pidgin.im>
author Jim Seymour <jseymour>
date Thu, 09 May 2002 13:53:12 +0000
parents 6a96436a542a
children d7ae897770d9
comparison
equal deleted inserted replaced
3235:59cad0db9a6b 3236:6796fdeed022
208 pool_free(p); /* no need for this anymore! */ 208 pool_free(p); /* no need for this anymore! */
209 return (NULL); 209 return (NULL);
210 } 210 }
211 gjc->p = p; 211 gjc->p = p;
212 212
213 gjc->user = jid_new(p, user); 213 if((gjc->user = jid_new(p, user)) == NULL) {
214 pool_free(p); /* no need for this anymore! */
215 return (NULL);
216 }
214 gjc->pass = pstrdup(p, pass); 217 gjc->pass = pstrdup(p, pass);
215 218
216 gjc->state = JCONN_STATE_OFF; 219 gjc->state = JCONN_STATE_OFF;
217 gjc->was_connected = 0; 220 gjc->was_connected = 0;
218 gjc->id = 1; 221 gjc->id = 1;
679 return TRUE; 682 return TRUE;
680 m = m->next; 683 m = m->next;
681 } 684 }
682 685
683 return FALSE; 686 return FALSE;
687 }
688
689 /*
690 * Remove a buddy from the (gaim) buddylist (if he's on it)
691 */
692 static void jabber_remove_gaim_buddy(struct gaim_connection *gc, char *buddyname)
693 {
694 struct buddy *b;
695
696 if ((b = find_buddy(gc, buddyname)) != NULL) {
697 struct group *group;
698
699 group = find_group_by_buddy(gc, buddyname);
700 debug_printf("removing buddy [1]: %s, from group: %s\n", buddyname, group->name);
701 remove_buddy(gc, group, b);
702 do_export(gc);
703 }
684 } 704 }
685 705
686 /* 706 /*
687 * keep track of away msg same as yahoo plugin 707 * keep track of away msg same as yahoo plugin
688 */ 708 */
1222 return; 1242 return;
1223 } 1243 }
1224 1244
1225 buddyname = g_strdup_printf("%s@%s", who->user, who->server); 1245 buddyname = g_strdup_printf("%s@%s", who->user, who->server);
1226 1246
1227 if((g = xmlnode_get_tag(x, "group")) != NULL && xmlnode_get_datasz(g) > 0) { 1247 if((g = xmlnode_get_tag(x, "group")) != NULL) {
1228 groupname = xmlnode_get_data(g); 1248 groupname = xmlnode_get_data(g);
1229 } 1249 }
1230 1250
1231 /* 1251 /*
1232 * Add or remove a buddy? Change buddy's alias or group? 1252 * Add or remove a buddy? Change buddy's alias or group?
1264 b->show[BUDDY_ALIAS_MAXLEN - 1] = '\0'; /* cheap safety feature */ 1284 b->show[BUDDY_ALIAS_MAXLEN - 1] = '\0'; /* cheap safety feature */
1265 handle_buddy_rename(b, buddyname); 1285 handle_buddy_rename(b, buddyname);
1266 } 1286 }
1267 } 1287 }
1268 } else if (BUD_USUB_TO_PEND(sub, ask) || BUD_USUBD_TO(sub, ask) || !strcasecmp(sub, "remove")) { 1288 } else if (BUD_USUB_TO_PEND(sub, ask) || BUD_USUBD_TO(sub, ask) || !strcasecmp(sub, "remove")) {
1269 if ((b = find_buddy(GJ_GC(gjc), buddyname)) != NULL) { 1289 jabber_remove_gaim_buddy(GJ_GC(gjc), buddyname);
1270 struct group *group;
1271
1272 group = find_group_by_buddy(GJ_GC(gjc), buddyname);
1273 debug_printf("removing buddy [1]: %s, from group: %s\n",
1274 buddyname, group->name);
1275 remove_buddy(GJ_GC(gjc), group, b);
1276 do_export(GJ_GC(gjc));
1277 }
1278 } 1290 }
1279 g_free(buddyname); 1291 g_free(buddyname);
1280 1292
1281 } 1293 }
1282 1294
1621 1633
1622 static gboolean jabber_free(gpointer data) 1634 static gboolean jabber_free(gpointer data)
1623 { 1635 {
1624 struct jabber_data *jd = data; 1636 struct jabber_data *jd = data;
1625 1637
1626 gjab_delete(jd->gjc); 1638 if(jd->gjc != NULL) {
1627 g_free(jd->gjc->sid); 1639 gjab_delete(jd->gjc);
1628 jd->gjc = NULL; 1640 g_free(jd->gjc->sid);
1641 jd->gjc = NULL;
1642 }
1629 g_free(jd); 1643 g_free(jd);
1630 1644
1631 return FALSE; 1645 return FALSE;
1632 } 1646 }
1633 1647
1651 g_hash_table_destroy(jd->hash); 1665 g_hash_table_destroy(jd->hash);
1652 jd->hash = NULL; 1666 jd->hash = NULL;
1653 } 1667 }
1654 1668
1655 /* Free-up the pending queries memories and the list */ 1669 /* Free-up the pending queries memories and the list */
1656 if(jd->gjc->queries != NULL) { 1670 if(jd->gjc != NULL && jd->gjc->queries != NULL) {
1657 g_hash_table_foreach_remove(jd->gjc->queries, jabber_destroy_hash, NULL); 1671 g_hash_table_foreach_remove(jd->gjc->queries, jabber_destroy_hash, NULL);
1658 g_hash_table_destroy(jd->gjc->queries); 1672 g_hash_table_destroy(jd->gjc->queries);
1659 jd->gjc->queries = NULL; 1673 jd->gjc->queries = NULL;
1660 } 1674 }
1661 } 1675 }
1662 if (gc->inpa) 1676 if (gc->inpa)
1663 gaim_input_remove(gc->inpa); 1677 gaim_input_remove(gc->inpa);
1664 1678
1665 if(jd) { 1679 if(jd) {
1666 g_timeout_add(50, jabber_free, jd); 1680 g_timeout_add(50, jabber_free, jd);
1667 xmlnode_free(jd->gjc->current); 1681 if(jd->gjc != NULL)
1682 xmlnode_free(jd->gjc->current);
1668 } 1683 }
1669 gc->proto_data = NULL; 1684 gc->proto_data = NULL;
1670 } 1685 }
1671 1686
1672 static int jabber_send_im(struct gaim_connection *gc, char *who, char *message, int len, int flags) 1687 static int jabber_send_im(struct gaim_connection *gc, char *who, char *message, int len, int flags)
1785 return; 1800 return;
1786 1801
1787 if (!strchr(name, '@')) 1802 if (!strchr(name, '@'))
1788 realwho = g_strdup_printf("%s@%s", name, gjc->user->server); 1803 realwho = g_strdup_printf("%s@%s", name, gjc->user->server);
1789 else { 1804 else {
1790 jid who = jid_new(gjc->p, name); 1805 jid who;
1806
1807 if((who = jid_new(gjc->p, name)) == NULL) {
1808 char *msg = g_strdup_printf("%s: \"%s\"", _("Invalid Jabber I.D."), name);
1809 do_error_dialog(msg, _("Jabber Error"));
1810 g_free(msg);
1811 jabber_remove_gaim_buddy(gc, name);
1812 return;
1813 }
1791 if (who->user == NULL) { 1814 if (who->user == NULL) {
1792 /* FIXME: transport */ 1815 /* FIXME: transport */
1793 return; 1816 return;
1794 } 1817 }
1795 realwho = g_strdup_printf("%s@%s", who->user, who->server); 1818 realwho = g_strdup_printf("%s@%s", who->user, who->server);
1925 1948
1926 realwho = create_valid_jid(data->data, data->next->data, 1949 realwho = create_valid_jid(data->data, data->next->data,
1927 data->next->next->data); 1950 data->next->next->data);
1928 debug_printf("%s\n", realwho); 1951 debug_printf("%s\n", realwho);
1929 1952
1930 Jid = jid_new(gjc->p, realwho); 1953 if((Jid = jid_new(gjc->p, realwho)) == NULL) {
1954 char *msg = g_strdup_printf("%s: \"%s\"", _("Invalid Jabber I.D."), realwho);
1955 do_error_dialog(msg, _("Jabber Error"));
1956 g_free(msg);
1957 return;
1958 }
1931 1959
1932 if((jc = find_any_chat(gc, Jid)) != NULL) { 1960 if((jc = find_any_chat(gc, Jid)) != NULL) {
1933 free(Jid); /* don't need it, after all */ 1961 free(Jid); /* don't need it, after all */
1934 switch(jc->state) { 1962 switch(jc->state) {
1935 case JCS_PENDING: 1963 case JCS_PENDING: