From: Nathan W. <fac...@us...> - 2003-10-22 07:48:23
|
Update of /cvsroot/gaim/gaim/src/protocols/jabber In directory sc8-pr-cvs1:/tmp/cvs-serv6548 Modified Files: chat.c jabber.c jutil.c jutil.h message.c presence.c roster.c Log Message: assorted jabber tweaks Index: chat.c =================================================================== RCS file: /cvsroot/gaim/gaim/src/protocols/jabber/chat.c,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -p -r1.6 -r1.7 --- chat.c 17 Oct 2003 21:29:15 -0000 1.6 +++ chat.c 21 Oct 2003 17:18:45 -0000 1.7 @@ -21,6 +21,7 @@ #include "internal.h" #include "debug.h" #include "multi.h" /* for proto_chat_entry */ +#include "notify.h" #include "chat.h" #include "message.h" @@ -170,6 +171,24 @@ void jabber_chat_join(GaimConnection *gc if(!room || !server || !handle) return; + + if(!jabber_nodeprep_validate(room)) { + char *buf = g_strdup_printf(_("%s is not a valid room name"), room); + gaim_notify_error(gc, _("Invalid Room Name"), _("Invalid Room Name"), + buf); + g_free(buf); + return; + } else if(!jabber_nameprep_validate(server)) { + char *buf = g_strdup_printf(_("%s is not a valid server name"), server); + gaim_notify_error(gc, _("Invalid Server Name"), + _("Invalid Server Name"), buf); + g_free(buf); + return; + } else if(!jabber_resourceprep_validate(handle)) { + char *buf = g_strdup_printf(_("%s is not a valid room handle"), handle); + gaim_notify_error(gc, _("Invalid Room Handle"), + _("Invalid Room Handle"), buf); + } if(jabber_chat_find(js, room, server)) return; Index: jabber.c =================================================================== RCS file: /cvsroot/gaim/gaim/src/protocols/jabber/jabber.c,v retrieving revision 1.205 retrieving revision 1.206 diff -u -d -p -r1.205 -r1.206 --- jabber.c 17 Oct 2003 20:03:43 -0000 1.205 +++ jabber.c 21 Oct 2003 17:18:45 -0000 1.206 @@ -362,6 +362,11 @@ jabber_login(GaimAccount *account) g_free, NULL); js->user = jabber_id_new(gaim_account_get_username(account)); + if(!js->user) { + gaim_connection_error(gc, _("Invalid Jabber ID")); + return; + } + if(!js->user->resource) { char *me; js->user->resource = g_strdup("Gaim"); @@ -649,6 +654,11 @@ static void jabber_register_account(Gaim js->callbacks = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); js->user = jabber_id_new(gaim_account_get_username(account)); + + if(!js->user) { + gaim_connection_error(gc, _("Invalid Jabber ID")); + return; + } if(!js->user->resource) { char *me; Index: jutil.c =================================================================== RCS file: /cvsroot/gaim/gaim/src/protocols/jabber/jutil.c,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -p -r1.7 -r1.8 --- jutil.c 20 Oct 2003 20:41:42 -0000 1.7 +++ jutil.c 21 Oct 2003 17:18:45 -0000 1.8 @@ -111,13 +111,80 @@ const char *jabber_get_state_string(int } } +gboolean jabber_nodeprep_validate(const char *str) +{ + const char *c; + + if(!str) + return TRUE; + + if(strlen(str) > 1023) + return FALSE; + + c = str; + while(c && *c) { + gunichar ch = g_utf8_get_char(c); + if(ch == '\"' || ch == '&' || ch == '\'' || ch == '/' || ch == ':' || + ch == '<' || ch == '>' || ch == '@' || !g_unichar_isgraph(ch)) { + return FALSE; + } + c = g_utf8_next_char(c); + } + + return TRUE; +} + +gboolean jabber_nameprep_validate(const char *str) +{ + const char *c; + + if(!str) + return TRUE; + + if(strlen(str) > 1023) + return FALSE; + + c = str; + while(c && *c) { + gunichar ch = g_utf8_get_char(c); + if(!g_unichar_isgraph(ch)) + return FALSE; + + c = g_utf8_next_char(c); + } + + + return TRUE; +} + +gboolean jabber_resourceprep_validate(const char *str) +{ + const char *c; + + if(!str) + return TRUE; + + if(strlen(str) > 1023) + return FALSE; + + c = str; + while(c && *c) { + gunichar ch = g_utf8_get_char(c); + if(!g_unichar_isgraph(ch)) + return FALSE; + + c = g_utf8_next_char(c); + } + + return TRUE; +} + + JabberID* jabber_id_new(const char *str) { char *at; char *slash; - char *c; - JabberID *jid; if(!str || !g_utf8_validate(str, -1, NULL)) @@ -146,48 +213,13 @@ jabber_id_new(const char *str) } - /* check lengths */ - if((jid->node && strlen(jid->node) > 1023) || - (jid->domain && strlen(jid->domain) > 1023) || - (jid->resource && strlen(jid->resource) > 1023)) { + if(!jabber_nodeprep_validate(jid->node) || + !jabber_nameprep_validate(jid->domain) || + !jabber_resourceprep_validate(jid->resource)) { jabber_id_free(jid); return NULL; } - /* nodeprep */ - c = jid->node; - while(c && *c) { - gunichar ch = g_utf8_get_char(c); - if(ch == '\"' || ch == '&' || ch == '\'' || ch == '/' || ch == ':' || - ch == '<' || ch == '>' || ch == '@' || !g_unichar_isgraph(ch)) { - jabber_id_free(jid); - return NULL; - } - c = g_utf8_next_char(c); - } - - /* nameprep */ - c = jid->domain; - while(c && *c) { - gunichar ch = g_utf8_get_char(c); - if(!g_unichar_isgraph(ch)) { - jabber_id_free(jid); - return NULL; - } - c = g_utf8_next_char(c); - } - - /* resourceprep */ - c = jid->resource; - while(c && *c) { - gunichar ch = g_utf8_get_char(c); - if(!g_unichar_isgraph(ch)) { - jabber_id_free(jid); - return NULL; - } - c = g_utf8_next_char(c); - } - return jid; } @@ -240,6 +272,10 @@ const char *jabber_normalize(const char char *tmp; tmp = jabber_get_bare_jid(in); + + if(!tmp) + return NULL; + g_snprintf(buf, sizeof(buf), "%s", tmp); g_free(tmp); return buf; Index: jutil.h =================================================================== RCS file: /cvsroot/gaim/gaim/src/protocols/jabber/jutil.h,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -p -r1.4 -r1.5 --- jutil.h 20 Oct 2003 20:41:42 -0000 1.4 +++ jutil.h 21 Oct 2003 17:18:46 -0000 1.5 @@ -42,4 +42,8 @@ const char *jabber_get_state_string(int const char *jabber_normalize(const char *in); +gboolean jabber_nodeprep_validate(const char *); +gboolean jabber_nameprep_validate(const char *); +gboolean jabber_resourceprep_validate(const char *); + #endif /* _GAIM_JABBER_JID_H_ */ Index: message.c =================================================================== RCS file: /cvsroot/gaim/gaim/src/protocols/jabber/message.c,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -p -r1.11 -r1.12 --- message.c 20 Oct 2003 20:41:42 -0000 1.11 +++ message.c 21 Oct 2003 17:18:46 -0000 1.12 @@ -78,6 +78,9 @@ static void handle_chat(JabberMessage *j JabberBuddy *jb; JabberBuddyResource *jbr; + if(!jid) + return; + jb = jabber_buddy_find(jm->js, jm->from, TRUE); jbr = jabber_buddy_find_resource(jb, jid->resource); @@ -164,7 +167,12 @@ static void handle_headline(JabberMessag static void handle_groupchat(JabberMessage *jm) { JabberID *jid = jabber_id_new(jm->from); - JabberChat *chat = jabber_chat_find(jm->js, jid->node, jid->domain); + JabberChat *chat; + + if(!jid) + return; + + chat = jabber_chat_find(jm->js, jid->node, jid->domain); if(!chat) return; @@ -181,9 +189,13 @@ static void handle_groupchat(JabberMessa static void handle_groupchat_invite(JabberMessage *jm) { - GHashTable *components = g_hash_table_new_full(g_str_hash, g_str_equal, - g_free, g_free); + GHashTable *components; JabberID *jid = jabber_id_new(jm->to); + + if(!jid) + return; + + components = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); g_hash_table_replace(components, g_strdup("room"), jid->node); g_hash_table_replace(components, g_strdup("server"), jid->node); Index: presence.c =================================================================== RCS file: /cvsroot/gaim/gaim/src/protocols/jabber/presence.c,v retrieving revision 1.13 retrieving revision 1.14 diff -u -d -p -r1.13 -r1.14 --- presence.c 16 Oct 2003 04:17:25 -0000 1.13 +++ presence.c 21 Oct 2003 17:18:46 -0000 1.14 @@ -209,6 +209,9 @@ void jabber_presence_parse(JabberStream } } + if(!(jid = jabber_id_new(from))) + return; + for(y = packet->child; y; y = y->next) { if(y->type != NODE_TYPE_TAG) continue; @@ -232,7 +235,6 @@ void jabber_presence_parse(JabberStream } } - jid = jabber_id_new(from); if((chat = jabber_chat_find(js, jid->node, jid->domain))) { static int i = 0; @@ -262,6 +264,7 @@ void jabber_presence_parse(JabberStream g_free(buf); jabber_chat_destroy(chat); + jabber_id_free(jid); return; } Index: roster.c =================================================================== RCS file: /cvsroot/gaim/gaim/src/protocols/jabber/roster.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -p -r1.4 -r1.5 --- roster.c 13 Oct 2003 00:11:23 -0000 1.4 +++ roster.c 21 Oct 2003 17:18:46 -0000 1.5 @@ -117,19 +117,35 @@ void jabber_roster_parse(JabberStream *j { xmlnode *query, *item, *group; const char *from = xmlnode_get_attrib(packet, "from"); - char *me1, *me2; - me1 = g_strdup_printf("%s@%s", js->user->node, js->user->domain); - me2 = g_strdup_printf("%s/%s", me1, js->user->resource); + if(from) { + char *me, *from_norm; + JabberID *from_jid = jabber_id_new(from); + gboolean invalid; - if(from && strcmp(from, me1) && strcmp(from, me2)) { - g_free(me1); - g_free(me2); - return; - } + if(!from_jid) + return; - g_free(me1); - g_free(me2); + from_norm = g_strdup_printf("%s@%s%s%s", + from_jid->node ? from_jid->node : "", + from_jid->domain, + from_jid->resource ? "/" : "", + from_jid->resource ? from_jid->resource : ""); + + if(from_jid->resource) + me = g_strdup_printf("%s@%s/%s", js->user->node, js->user->domain, + js->user->resource); + else + me = g_strdup_printf("%s@%s", js->user->node, js->user->domain); + + invalid = g_utf8_collate(from_norm, me); + g_free(from_norm); + g_free(me); + jabber_id_free(from_jid); + + if(invalid) + return; + } query = xmlnode_get_child(packet, "query"); if(!query) |