From: Nathan W. <fac...@us...> - 2003-10-25 15:20:56
|
Update of /cvsroot/gaim/gaim/src/protocols/jabber In directory sc8-pr-cvs1:/tmp/cvs-serv29607/src/protocols/jabber Modified Files: chat.c jabber.c jutil.c jutil.h presence.c Log Message: all sorts of stuff including tweaks to logging so it mostly works again for jabber. Index: chat.c =================================================================== RCS file: /cvsroot/gaim/gaim/src/protocols/jabber/chat.c,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -p -r1.7 -r1.8 --- chat.c 21 Oct 2003 17:18:45 -0000 1.7 +++ chat.c 24 Oct 2003 05:46:01 -0000 1.8 @@ -69,7 +69,7 @@ JabberChat *jabber_chat_find(JabberStrea room_jid = g_strdup_printf("%s@%s", room, server); - chat = g_hash_table_lookup(js->chats, jabber_normalize(room_jid)); + chat = g_hash_table_lookup(js->chats, jabber_normalize(NULL, room_jid)); g_free(room_jid); return chat; @@ -147,8 +147,6 @@ void jabber_chat_whisper(GaimConnection chat = jabber_chat_find_by_id(js, id); - /* TODO: we get real Jabber IDs from MUC sometimes, we need to cache - * them eventually */ full_jid = g_strdup_printf("%s@%s/%s", chat->room, chat->server, who); jabber_message_send_im(gc, full_jid, message, 0); @@ -194,7 +192,7 @@ void jabber_chat_join(GaimConnection *gc return; tmp = g_strdup_printf("%s@%s", room, server); - room_jid = g_strdup(jabber_normalize(tmp)); + room_jid = g_strdup(jabber_normalize(NULL, tmp)); g_free(tmp); chat = g_new0(JabberChat, 1); @@ -248,7 +246,7 @@ void jabber_chat_destroy(JabberChat *cha JabberStream *js = chat->js; char *room_jid = g_strdup_printf("%s@%s", chat->room, chat->server); - g_hash_table_remove(js->chats, jabber_normalize(room_jid)); + g_hash_table_remove(js->chats, jabber_normalize(NULL, room_jid)); g_free(room_jid); g_free(chat->room); Index: jabber.c =================================================================== RCS file: /cvsroot/gaim/gaim/src/protocols/jabber/jabber.c,v retrieving revision 1.206 retrieving revision 1.207 diff -u -d -p -r1.206 -r1.207 --- jabber.c 21 Oct 2003 17:18:45 -0000 1.206 +++ jabber.c 24 Oct 2003 05:46:01 -0000 1.207 @@ -361,6 +361,7 @@ jabber_login(GaimAccount *account) js->chats = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); js->user = jabber_id_new(gaim_account_get_username(account)); + js->next_id = g_random_int(); if(!js->user) { gaim_connection_error(gc, _("Invalid Jabber ID")); @@ -654,6 +655,7 @@ 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)); + js->next_id = g_random_int(); if(!js->user) { gaim_connection_error(gc, _("Invalid Jabber ID")); @@ -762,7 +764,7 @@ void jabber_stream_set_state(JabberStrea char *jabber_get_next_id(JabberStream *js) { - return g_strdup_printf("gaim%d", js->next_id++); + return g_strdup_printf("gaim%x", js->next_id++); } void jabber_idle_set(GaimConnection *gc, int idle) Index: jutil.c =================================================================== RCS file: /cvsroot/gaim/gaim/src/protocols/jabber/jutil.c,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -p -r1.8 -r1.9 --- jutil.c 21 Oct 2003 17:18:45 -0000 1.8 +++ jutil.c 24 Oct 2003 05:46:01 -0000 1.9 @@ -21,6 +21,7 @@ #include "internal.h" #include "server.h" +#include "chat.h" #include "presence.h" #include "jutil.h" @@ -260,24 +261,33 @@ char *jabber_get_bare_jid(const char *in if(!jid) return NULL; - out = g_strdup_printf("%s@%s", jid->node, jid->domain); + out = g_strdup_printf("%s%s%s", jid->node ? jid->node : "", + jid->node ? "@" : "", jid->domain); jabber_id_free(jid); return out; } -const char *jabber_normalize(const char *in) +const char *jabber_normalize(const GaimAccount *account, const char *in) { - static char buf[2048]; /* maximum legal length of a jabber jid */ - char *tmp; + GaimConnection *gc = account ? account->gc : NULL; + JabberStream *js = gc ? gc->proto_data : NULL; + static char buf[3072]; /* maximum legal length of a jabber jid */ + JabberID *jid; - tmp = jabber_get_bare_jid(in); + jid = jabber_id_new(in); - if(!tmp) + if(!jid) return NULL; - g_snprintf(buf, sizeof(buf), "%s", tmp); - g_free(tmp); + if(js && jid->node && jid->resource && + jabber_chat_find(js, jid->node, jid->domain)) + g_snprintf(buf, sizeof(buf), "%s@%s/%s", jid->node, jid->domain, + jid->resource); + else + g_snprintf(buf, sizeof(buf), "%s%s%s", jid->node ? jid->node : "", + jid->node ? "@" : "", jid->domain); + return buf; } Index: jutil.h =================================================================== RCS file: /cvsroot/gaim/gaim/src/protocols/jabber/jutil.h,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -p -r1.5 -r1.6 --- jutil.h 21 Oct 2003 17:18:46 -0000 1.5 +++ jutil.h 24 Oct 2003 05:46:01 -0000 1.6 @@ -40,7 +40,7 @@ char *jabber_get_bare_jid(const char *ji time_t str_to_time(const char *timestamp); const char *jabber_get_state_string(int state); -const char *jabber_normalize(const char *in); +const char *jabber_normalize(const GaimAccount *account, const char *in); gboolean jabber_nodeprep_validate(const char *); gboolean jabber_nameprep_validate(const char *); Index: presence.c =================================================================== RCS file: /cvsroot/gaim/gaim/src/protocols/jabber/presence.c,v retrieving revision 1.16 retrieving revision 1.17 diff -u -d -p -r1.16 -r1.17 --- presence.c 23 Oct 2003 21:56:16 -0000 1.16 +++ presence.c 24 Oct 2003 05:46:01 -0000 1.17 @@ -236,7 +236,7 @@ void jabber_presence_parse(JabberStream } - if((chat = jabber_chat_find(js, jid->node, jid->domain))) { + if(jid->node && (chat = jabber_chat_find(js, jid->node, jid->domain))) { static int i = 0; char *room_jid = g_strdup_printf("%s@%s", jid->node, jid->domain); @@ -305,7 +305,8 @@ void jabber_presence_parse(JabberStream return; } - buddy_name = g_strdup_printf("%s@%s", jid->node, jid->domain); + buddy_name = g_strdup_printf("%s%s%s", jid->node ? jid->node : "", + jid->node ? "@" : "", jid->domain); if((b = gaim_find_buddy(js->gc->account, buddy_name)) == NULL) { jabber_id_free(jid); g_free(buddy_name); |