Mercurial > pidgin
changeset 7310:dd4b4a187171
[gaim-migrate @ 7894]
assorted jabber tweaks
committer: Tailor Script <tailor@pidgin.im>
author | Nathan Walp <nwalp@pidgin.im> |
---|---|
date | Tue, 21 Oct 2003 17:18:46 +0000 |
parents | 153fbf9b6a7f |
children | 1c8830db0189 |
files | src/protocols/jabber/chat.c src/protocols/jabber/jabber.c src/protocols/jabber/jutil.c src/protocols/jabber/jutil.h src/protocols/jabber/message.c src/protocols/jabber/presence.c src/protocols/jabber/roster.c |
diffstat | 7 files changed, 154 insertions(+), 54 deletions(-) [+] |
line wrap: on
line diff
--- a/src/protocols/jabber/chat.c Tue Oct 21 16:34:12 2003 +0000 +++ b/src/protocols/jabber/chat.c Tue Oct 21 17:18:46 2003 +0000 @@ -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" @@ -171,6 +172,24 @@ 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;
--- a/src/protocols/jabber/jabber.c Tue Oct 21 16:34:12 2003 +0000 +++ b/src/protocols/jabber/jabber.c Tue Oct 21 17:18:46 2003 +0000 @@ -362,6 +362,11 @@ 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"); @@ -650,6 +655,11 @@ 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");
--- a/src/protocols/jabber/jutil.c Tue Oct 21 16:34:12 2003 +0000 +++ b/src/protocols/jabber/jutil.c Tue Oct 21 17:18:46 2003 +0000 @@ -111,13 +111,80 @@ } } +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 @@ } - /* 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 @@ char *tmp; tmp = jabber_get_bare_jid(in); + + if(!tmp) + return NULL; + g_snprintf(buf, sizeof(buf), "%s", tmp); g_free(tmp); return buf;
--- a/src/protocols/jabber/jutil.h Tue Oct 21 16:34:12 2003 +0000 +++ b/src/protocols/jabber/jutil.h Tue Oct 21 17:18:46 2003 +0000 @@ -42,4 +42,8 @@ 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_ */
--- a/src/protocols/jabber/message.c Tue Oct 21 16:34:12 2003 +0000 +++ b/src/protocols/jabber/message.c Tue Oct 21 17:18:46 2003 +0000 @@ -78,6 +78,9 @@ 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_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,10 +189,14 @@ 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); g_hash_table_replace(components, g_strdup("handle"), jm->js->user->node);
--- a/src/protocols/jabber/presence.c Tue Oct 21 16:34:12 2003 +0000 +++ b/src/protocols/jabber/presence.c Tue Oct 21 17:18:46 2003 +0000 @@ -209,6 +209,9 @@ } } + 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 @@ } } - jid = jabber_id_new(from); if((chat = jabber_chat_find(js, jid->node, jid->domain))) { static int i = 0; @@ -262,6 +264,7 @@ g_free(buf); jabber_chat_destroy(chat); + jabber_id_free(jid); return; }
--- a/src/protocols/jabber/roster.c Tue Oct 21 16:34:12 2003 +0000 +++ b/src/protocols/jabber/roster.c Tue Oct 21 17:18:46 2003 +0000 @@ -117,20 +117,36 @@ { xmlnode *query, *item, *group; const char *from = xmlnode_get_attrib(packet, "from"); - char *me1, *me2; + + if(from) { + char *me, *from_norm; + JabberID *from_jid = jabber_id_new(from); + gboolean invalid; - me1 = g_strdup_printf("%s@%s", js->user->node, js->user->domain); - me2 = g_strdup_printf("%s/%s", me1, js->user->resource); + if(!from_jid) + return; + + 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 && strcmp(from, me1) && strcmp(from, me2)) { - g_free(me1); - g_free(me2); - return; + 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; } - g_free(me1); - g_free(me2); - query = xmlnode_get_child(packet, "query"); if(!query) return;