# HG changeset patch # User Mike Ruprecht # Date 1211593234 0 # Node ID 16543025aed1658c2e89af75f8a9b1a8946e1264 # Parent e1c8ec1259de544776f2955d3b1e967bed97993c Moved jingle.c global variable "sessions" into JabberStream. Allows media sessions between two accounts in the same client. diff -r e1c8ec1259de -r 16543025aed1 libpurple/protocols/jabber/jabber.c --- a/libpurple/protocols/jabber/jabber.c Fri May 23 02:42:32 2008 +0000 +++ b/libpurple/protocols/jabber/jabber.c Sat May 24 01:40:34 2008 +0000 @@ -632,6 +632,10 @@ js->keepalive_timeout = -1; js->certificate_CN = g_strdup(connect_server[0] ? connect_server : js->user->domain); +#ifdef USE_FARSIGHT + js->sessions = NULL; +#endif + if(!js->user) { purple_connection_error_reason (gc, PURPLE_CONNECTION_ERROR_INVALID_SETTINGS, @@ -1244,12 +1248,15 @@ #ifdef USE_FARSIGHT /* Close all of the open media sessions on this stream */ - GList *iter = jabber_jingle_session_find_by_js(js); + GList *values = g_hash_table_get_values(js->sessions); + GList *iter = values; for (; iter; iter = iter->next) { JingleSession *session = (JingleSession *)iter->data; purple_media_hangup(session->media); } + + g_list_free(values); #endif /* Don't perform any actions on the ssl connection @@ -2625,7 +2632,7 @@ xmlnode *content = xmlnode_get_child(jingle, "content"); const char *sid = xmlnode_get_attrib(jingle, "sid"); const char *action = xmlnode_get_attrib(jingle, "action"); - JingleSession *session = jabber_jingle_session_find_by_id(sid); + JingleSession *session = jabber_jingle_session_find_by_id(js, sid); GList *remote_codecs = NULL; GList *remote_transports = NULL; GList *codec_intersection; @@ -2706,7 +2713,7 @@ JabberIq *result = jabber_iq_new(js, JABBER_IQ_SET); xmlnode *jingle = xmlnode_get_child(packet, "jingle"); const char *sid = xmlnode_get_attrib(jingle, "sid"); - JingleSession *session = jabber_jingle_session_find_by_id(sid); + JingleSession *session = jabber_jingle_session_find_by_id(js, sid); xmlnode_set_attrib(result->node, "to", jabber_jingle_session_get_remote_jid(session)); @@ -2732,7 +2739,7 @@ xmlnode *transport = xmlnode_get_child(content, "transport"); GList *remote_candidates = jabber_jingle_get_candidates(transport); const char *sid = xmlnode_get_attrib(jingle, "sid"); - JingleSession *session = jabber_jingle_session_find_by_id(sid); + JingleSession *session = jabber_jingle_session_find_by_id(js, sid); if(!session) purple_debug_error("jabber", "jabber_handle_session_candidates couldn't find session\n"); @@ -2757,7 +2764,7 @@ { xmlnode *jingle = xmlnode_get_child(packet, "jingle"); const char *sid = xmlnode_get_attrib(jingle, "sid"); - JingleSession *session = jabber_jingle_session_find_by_id(sid); + JingleSession *session = jabber_jingle_session_find_by_id(js, sid); if (!jabber_jingle_session_is_initiator(session) && session->session_started) { JabberIq *result = jabber_iq_new(js, JABBER_IQ_RESULT); @@ -2799,7 +2806,7 @@ sid = xmlnode_get_attrib(jingle, "sid"); initiator = xmlnode_get_attrib(jingle, "initiator"); - if (jabber_jingle_session_find_by_id(sid)) { + if (jabber_jingle_session_find_by_id(js, sid)) { /* This should only happen if you start a session with yourself */ purple_debug_error("jabber", "Jingle session with id={%s} already exists\n", sid); return; diff -r e1c8ec1259de -r 16543025aed1 libpurple/protocols/jabber/jabber.h --- a/libpurple/protocols/jabber/jabber.h Fri May 23 02:42:32 2008 +0000 +++ b/libpurple/protocols/jabber/jabber.h Sat May 24 01:40:34 2008 +0000 @@ -203,6 +203,11 @@ /* A purple timeout tag for the keepalive */ int keepalive_timeout; + +#ifdef USE_FARSIGHT + /* keep a hash table of JingleSessions */ + GHashTable *sessions; +#endif }; typedef gboolean (JabberFeatureEnabled)(JabberStream *js, const gchar *shortname, const gchar *namespace); diff -r e1c8ec1259de -r 16543025aed1 libpurple/protocols/jabber/jingle.c --- a/libpurple/protocols/jabber/jingle.c Fri May 23 02:42:32 2008 +0000 +++ b/libpurple/protocols/jabber/jingle.c Sat May 24 01:40:34 2008 +0000 @@ -30,9 +30,6 @@ #include -/* keep a hash table of JingleSessions */ -static GHashTable *sessions = NULL; - static gboolean jabber_jingle_session_equal(gconstpointer a, gconstpointer b) { @@ -58,13 +55,13 @@ } /* insert it into the hash table */ - if (!sessions) { + if (!js->sessions) { purple_debug_info("jingle", "Creating hash table for sessions\n"); - sessions = g_hash_table_new(g_str_hash, g_str_equal); + js->sessions = g_hash_table_new(g_str_hash, g_str_equal); } purple_debug_info("jingle", "inserting session with key: %s into table\n", sess->id); - g_hash_table_insert(sessions, sess->id, sess); + g_hash_table_insert(js->sessions, sess->id, sess); sess->session_started = FALSE; @@ -102,43 +99,25 @@ void jabber_jingle_session_destroy(JingleSession *sess) { - g_hash_table_remove(sessions, sess->id); + g_hash_table_remove(sess->js->sessions, sess->id); g_free(sess->id); g_free(sess); } JingleSession * -jabber_jingle_session_find_by_id(const char *id) +jabber_jingle_session_find_by_id(JabberStream *js, const char *id) { purple_debug_info("jingle", "find_by_id %s\n", id); - purple_debug_info("jingle", "hash table: %p\n", sessions); + purple_debug_info("jingle", "hash table: %p\n", js->sessions); purple_debug_info("jingle", "hash table size %d\n", - g_hash_table_size(sessions)); - purple_debug_info("jingle", "lookup: %p\n", g_hash_table_lookup(sessions, id)); - return (JingleSession *) g_hash_table_lookup(sessions, id); -} - -GList * -jabber_jingle_session_find_by_js(JabberStream *js) -{ - GList *values = g_hash_table_get_values(sessions); - GList *iter = values; - GList *found = NULL; - - for (; iter; iter = iter->next) { - JingleSession *session = (JingleSession *)iter->data; - if (session->js == js) { - found = g_list_prepend(found, session); - } - } - - g_list_free(values); - return found; + g_hash_table_size(js->sessions)); + purple_debug_info("jingle", "lookup: %p\n", g_hash_table_lookup(js->sessions, id)); + return (JingleSession *) g_hash_table_lookup(js->sessions, id); } JingleSession *jabber_jingle_session_find_by_jid(JabberStream *js, const char *jid) { - GList *values = g_hash_table_get_values(sessions); + GList *values = g_hash_table_get_values(js->sessions); GList *iter = values; for (; iter; iter = iter->next) { diff -r e1c8ec1259de -r 16543025aed1 libpurple/protocols/jabber/jingle.h --- a/libpurple/protocols/jabber/jingle.h Fri May 23 02:42:32 2008 +0000 +++ b/libpurple/protocols/jabber/jingle.h Sat May 24 01:40:34 2008 +0000 @@ -47,8 +47,7 @@ void jabber_jingle_session_destroy(JingleSession *sess); -JingleSession *jabber_jingle_session_find_by_id(const char *id); -GList *jabber_jingle_session_find_by_js(JabberStream *js); +JingleSession *jabber_jingle_session_find_by_id(JabberStream *js, const char *id); JingleSession *jabber_jingle_session_find_by_jid(JabberStream *js, const char *jid); PurpleMedia *jabber_jingle_session_get_media(const JingleSession *sess);