Mercurial > pidgin.yaz
changeset 7306:7c12dab8e513
[gaim-migrate @ 7890]
this should implement the full nodeprep, nameprep, and resourceprep string
profiles, so we compare JIDs correctly
committer: Tailor Script <tailor@pidgin.im>
author | Nathan Walp <nwalp@pidgin.im> |
---|---|
date | Mon, 20 Oct 2003 20:41:42 +0000 |
parents | fa25f82dda21 |
children | e11fa8e10a2e |
files | src/protocols/jabber/buddy.c src/protocols/jabber/jutil.c src/protocols/jabber/jutil.h src/protocols/jabber/message.c |
diffstat | 4 files changed, 90 insertions(+), 29 deletions(-) [+] |
line wrap: on
line diff
--- a/src/protocols/jabber/buddy.c Mon Oct 20 05:08:05 2003 +0000 +++ b/src/protocols/jabber/buddy.c Mon Oct 20 20:41:42 2003 +0000 @@ -537,7 +537,7 @@ JabberBuddy *jb; JabberBuddyResource *jbr; GString *info_text; - const char *resource_name; + char *resource_name; char *title; xmlnode *vcard; @@ -587,6 +587,8 @@ } } + g_free(resource_name); + if((vcard = xmlnode_get_child(packet, "vCard"))) { xmlnode *child; for(child = vcard->child; child; child = child->next)
--- a/src/protocols/jabber/jutil.c Mon Oct 20 05:08:05 2003 +0000 +++ b/src/protocols/jabber/jutil.c Mon Oct 20 20:41:42 2003 +0000 @@ -116,32 +116,76 @@ { char *at; char *slash; + char *c; JabberID *jid; - if(!str) + if(!str || !g_utf8_validate(str, -1, NULL)) return NULL; jid = g_new0(JabberID, 1); - at = strchr(str, '@'); - slash = strchr(str, '/'); + at = g_utf8_strchr(str, -1, '@'); + slash = g_utf8_strchr(str, -1, '/'); if(at) { - jid->node = g_strndup(str, at-str); + jid->node = g_utf8_normalize(str, at-str, G_NORMALIZE_NFKC); if(slash) { - jid->domain = g_strndup(at+1, slash-(at+1)); - jid->resource = g_strdup(slash+1); + jid->domain = g_utf8_normalize(at+1, slash-(at+1), G_NORMALIZE_NFKC); + jid->resource = g_utf8_normalize(slash+1, -1, G_NORMALIZE_NFKC); } else { - jid->domain = g_strdup(at+1); + jid->domain = g_utf8_normalize(at+1, -1, G_NORMALIZE_NFKC); } } else { if(slash) { - jid->domain = g_strndup(str, slash-str); - jid->resource = g_strdup(slash+1); + jid->domain = g_utf8_normalize(str, slash-str, G_NORMALIZE_NFKC); + jid->resource = g_utf8_normalize(slash+1, -1, G_NORMALIZE_NFKC); } else { - jid->domain = g_strdup(str); + jid->domain = g_utf8_normalize(str, -1, G_NORMALIZE_NFKC); + } + } + + + /* check lengths */ + if((jid->node && strlen(jid->node) > 1023) || + (jid->domain && strlen(jid->domain) > 1023) || + (jid->resource && strlen(jid->resource) > 1023)) { + 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; @@ -162,26 +206,32 @@ } -const char *jabber_get_resource(const char *jid) +char *jabber_get_resource(const char *in) { - char *slash; + JabberID *jid = jabber_id_new(in); + char *out; - slash = strrchr(jid, '/'); - if(slash) - return slash+1; - else + if(!jid) return NULL; + + out = g_strdup(jid->resource); + jabber_id_free(jid); + + return out; } -char *jabber_get_bare_jid(const char *jid) +char *jabber_get_bare_jid(const char *in) { - char *slash; - slash = strrchr(jid, '/'); + JabberID *jid = jabber_id_new(in); + char *out; - if(slash) - return g_utf8_strdown(jid, slash - jid); - else - return g_utf8_strdown(jid, -1); + if(!jid) + return NULL; + + out = g_strdup_printf("%s@%s", jid->node, jid->domain); + jabber_id_free(jid); + + return out; } const char *jabber_normalize(const char *in) @@ -194,3 +244,4 @@ g_free(tmp); return buf; } +
--- a/src/protocols/jabber/jutil.h Mon Oct 20 05:08:05 2003 +0000 +++ b/src/protocols/jabber/jutil.h Mon Oct 20 20:41:42 2003 +0000 @@ -34,7 +34,7 @@ JabberID* jabber_id_new(const char *str); void jabber_id_free(JabberID *jid); -const char *jabber_get_resource(const char *jid); +char *jabber_get_resource(const char *jid); char *jabber_get_bare_jid(const char *jid); time_t str_to_time(const char *timestamp);
--- a/src/protocols/jabber/message.c Mon Oct 20 05:08:05 2003 +0000 +++ b/src/protocols/jabber/message.c Mon Oct 20 20:41:42 2003 +0000 @@ -79,7 +79,7 @@ JabberBuddyResource *jbr; jb = jabber_buddy_find(jm->js, jm->from, TRUE); - jbr = jabber_buddy_find_resource(jb, jabber_get_resource(jm->from)); + jbr = jabber_buddy_find_resource(jb, jid->resource); if(find_unnormalized_conv(jm->from, jm->js->gc->account)) { from = g_strdup(jm->from); @@ -174,7 +174,7 @@ jm->subject); if(jm->xhtml || jm->body) - serv_got_chat_in(jm->js->gc, chat->id, jabber_get_resource(jm->from), + serv_got_chat_in(jm->js->gc, chat->id, jid->resource, 0, jm->xhtml ? jm->xhtml : jm->body, jm->sent); jabber_id_free(jid); } @@ -412,12 +412,17 @@ JabberBuddyResource *jbr; char *buf; char *xhtml; + char *resource; if(!who || !msg) return 0; + resource = jabber_get_resource(who); + jb = jabber_buddy_find(gc->proto_data, who, TRUE); - jbr = jabber_buddy_find_resource(jb, jabber_get_resource(who)); + jbr = jabber_buddy_find_resource(jb, resource); + + g_free(resource); jm = g_new0(JabberMessage, 1); jm->js = gc->proto_data; @@ -468,9 +473,12 @@ JabberMessage *jm; JabberBuddy *jb; JabberBuddyResource *jbr; + char *resource = jabber_get_resource(who); jb = jabber_buddy_find(gc->proto_data, who, TRUE); - jbr = jabber_buddy_find_resource(jb, jabber_get_resource(who)); + jbr = jabber_buddy_find_resource(jb, resource); + + g_free(resource); if(!jbr || !(jbr->capabilities & JABBER_CAP_COMPOSING)) return 0;