Author: dzzinstant
Date: Wed Aug 13 03:53:10 2014
New Revision: 32

URL: http://svn.gna.org/viewcvs/pidgin-zrtp?rev=32&view=rev
Log:
Use 'new-zrtpfilter' signal, registry for zrtpfilters in encrypt.c

Modified:
    trunk/src/pidgin-plugin/simplezrtp/encrypt-backend-zrtp.c
    trunk/src/pidgin-plugin/simplezrtp/encrypt.c
    trunk/src/pidgin-plugin/simplezrtp/encrypt.h
    trunk/src/pidgin-plugin/simplezrtp/zrtp-conference.c

Modified: trunk/src/pidgin-plugin/simplezrtp/encrypt-backend-zrtp.c
URL: 
http://svn.gna.org/viewcvs/pidgin-zrtp/trunk/src/pidgin-plugin/simplezrtp/encrypt-backend-zrtp.c?rev=32&r1=31&r2=32&view=diff
==============================================================================
--- trunk/src/pidgin-plugin/simplezrtp/encrypt-backend-zrtp.c   (original)
+++ trunk/src/pidgin-plugin/simplezrtp/encrypt-backend-zrtp.c   Wed Aug 13 
03:53:10 2014
@@ -74,9 +74,9 @@
 
 
 static gboolean
-connect_filter(PurpleEncryptBackend *self, const gchar *sess_id, const gchar 
*participant);
-static gboolean
-disconnect_filter(PurpleEncryptBackend *self, const gchar *sess_id, const 
gchar *participant);
+connect_filter(PurpleEncryptBackend *self, const gchar *session_id, const 
gchar *participant);
+static gboolean
+disconnect_filter(PurpleEncryptBackend *self, const gchar *session_id, const 
gchar *participant);
 
 /*
  * Helpers
@@ -223,10 +223,17 @@
  * Local storage
  */
 static GstElement *
-get_zrtpfilter(PurpleEncryptBackend *self, 
-               const gchar *sess_id, const gchar *who)
-{
-       return NULL; // TODO
+find_zrtpfilter(PurpleEncryptBackend *self, 
+               const gchar *participant, guint sid)
+{
+       PurpleEncryptBackendZrtpPrivate *priv =
+               PURPLE_ENCRYPT_BACKEND_ZRTP_GET_PRIVATE(self);
+       gchar *key = g_strdup_printf("%u_%s", sid, participant);
+       GstElement *filter;
+
+       filter = g_hash_table_lookup(priv->filters, key);
+       g_free(key);
+       return filter;
 }
 
 static GObject *
@@ -245,11 +252,11 @@
  */
 static void
 candidates_prepared_cb(PurpleMediaBackendFs2 *backend,
-               const gchar *sess_id, const gchar *name, 
PurpleEncryptBackendZrtp *self)
+               const gchar *session_id, const gchar *name, 
PurpleEncryptBackendZrtp *self)
 {
        purple_debug_info(PLUGIN_ID " backend",
-                       "'candidates-prepared' (sess_id=%s name=%s self=%p 
backend=%p): no-op\n",
-                       sess_id, name, self, backend);
+                       "'candidates-prepared' (session_id=%s name=%s self=%p 
backend=%p): no-op\n",
+                       session_id, name, self, backend);
 }
 
 static void
@@ -365,11 +372,21 @@
 
 static void
 new_zrtpfilter_cb(GObject *zrtpconf,
-               gchar *name, PurpleEncryptBackendZrtp *self)
-{
+               GstElement *filter, PurpleEncryptBackendZrtp *self)
+{
+       PurpleEncryptBackendZrtpPrivate *priv =
+               PURPLE_ENCRYPT_BACKEND_ZRTP_GET_PRIVATE(self);
+       gchar **splitstring;
+       gchar *key;
+
+       splitstring = g_strsplit(GST_ELEMENT_NAME(filter), "_", 2);
+       key = g_strdup(splitstring[1]);
+       g_strfreev(splitstring);
+
        purple_debug_info(PLUGIN_ID " backend",
-                       "'new-zrtpfilter' (name=%s self=%p zrtpconf=%p): 
no-op\n",
-                       name, self, zrtpconf);
+                       "'new-zrtpfilter' (self=%p zrtpconf=%p): key=%s\n",
+                       self, zrtpconf, key);
+       g_hash_table_insert(priv->filters, key, filter);
 }
 
 static void
@@ -797,20 +814,21 @@
 }
 
 static gboolean
-connect_filter(PurpleEncryptBackend *self, const gchar *sess_id, const gchar 
*participant)
+connect_filter(PurpleEncryptBackend *self, const gchar *session_id, const 
gchar *participant)
 {
        PurpleEncryptBackendZrtpPrivate *priv =
                PURPLE_ENCRYPT_BACKEND_ZRTP_GET_PRIVATE(self);
        GstElement *filter = NULL;
        g_return_val_if_fail(PURPLE_IS_ENCRYPT_BACKEND_ZRTP(self), FALSE);
 
-       if (sess_id && participant) { /* scope: a Stream Pair  */
-               filter = get_zrtpfilter(self, sess_id, participant);
+       if (session_id && participant) { /* scope: a Stream Pair  */
+               filter = find_zrtpfilter(self,
+                               participant, get_sid_by_mediatype(priv->media, 
session_id));
                purple_debug_info(PLUGIN_ID " backend",
                                "connect_filter(self=%p zrtpfilter=%p) for 
session=%s, participant=%s (no-op)\n", 
-                               self, filter, sess_id, participant);
+                               self, filter, session_id, participant);
        } 
-       else if (!sess_id && participant) { /* scope: a Call/Participant */
+       else if (!session_id && participant) { /* scope: a Call/Participant */
                GObject *zrtpcall = find_zrtpcall(self, participant);
                g_object_get(zrtpcall, "zrtpmaster", &filter, NULL);
 
@@ -826,25 +844,36 @@
 }
 
 static gboolean
-disconnect_filter(PurpleEncryptBackend *self, const gchar *sess_id, const 
gchar *participant)
+disconnect_filter(PurpleEncryptBackend *self, const gchar *session_id, const 
gchar *participant)
 {
        PurpleEncryptBackendZrtpPrivate *priv =
                PURPLE_ENCRYPT_BACKEND_ZRTP_GET_PRIVATE(self);
        GstElement *filter;
+       gchar *key = NULL;
        guint count = 0;
 
-       if (!sess_id && participant) { /* scope: a Call/Participant */
-               filter = g_hash_table_lookup(priv->filters, participant);
-               g_return_val_if_fail(filter, FALSE);
-
-               count = g_signal_handlers_disconnect_matched(G_OBJECT(filter),
-                               G_SIGNAL_MATCH_DATA, 0, 0,
-                               NULL, NULL, self);
-               g_hash_table_remove(priv->filters, participant);
-
-               purple_debug_info(PLUGIN_ID " backend",
-                               "disconnect_filter(self=%p filter=%p) for 
participant=%s): disconnected %u signals\n", 
-                               self, filter, participant, count);
-       }
+       if (session_id && participant) { /* scope: a Stream Pair  */
+               key = g_strdup_printf("%u_%s",
+                               get_sid_by_mediatype(priv->media, session_id), 
participant);
+       } 
+       else if (!session_id && participant) { /* scope: a Call/Participant */
+               key = g_strdup(participant);
+       }
+       else {
+               return FALSE;
+       }
+
+       filter = g_hash_table_lookup(priv->filters, key);
+       g_return_val_if_fail(filter, FALSE);
+
+       count = g_signal_handlers_disconnect_matched(G_OBJECT(filter),
+                       G_SIGNAL_MATCH_DATA, 0, 0,
+                       NULL, NULL, self);
+       g_hash_table_remove(priv->filters, key);
+
+       purple_debug_info(PLUGIN_ID " backend",
+                       "disconnect_filter(self=%p filter=%p) for key=%s): 
disconnected %u signals\n", 
+                       self, filter, key, count);
+       g_free(key);
        return TRUE;
 }

Modified: trunk/src/pidgin-plugin/simplezrtp/encrypt.c
URL: 
http://svn.gna.org/viewcvs/pidgin-zrtp/trunk/src/pidgin-plugin/simplezrtp/encrypt.c?rev=32&r1=31&r2=32&view=diff
==============================================================================
--- trunk/src/pidgin-plugin/simplezrtp/encrypt.c        (original)
+++ trunk/src/pidgin-plugin/simplezrtp/encrypt.c        Wed Aug 13 03:53:10 2014
@@ -74,6 +74,30 @@
        PROP_LAST
 };
 
+/*
+ * Helpers
+ */
+guint get_sid_by_mediatype(PurpleMedia *media, const gchar *mediatype)
+{
+       GList *items;
+       guint sid = 0;
+       g_return_val_if_fail(mediatype, 0);
+
+       for (items = purple_media_get_session_ids(media);
+                       items; items = g_list_delete_link(items, items))
+       {
+               const gchar *session_id = (const gchar *) items->data;
+               sid++;
+               if (!items->data)
+                       continue;
+
+               if (session_id[0] == mediatype[0]) { /* compare only first 
letter: a/v */
+                       g_list_free(items);
+                       return sid;
+               }
+       }
+       return 0;
+}
 
 /*
  * PurpleEncryptManager (Singleton)

Modified: trunk/src/pidgin-plugin/simplezrtp/encrypt.h
URL: 
http://svn.gna.org/viewcvs/pidgin-zrtp/trunk/src/pidgin-plugin/simplezrtp/encrypt.h?rev=32&r1=31&r2=32&view=diff
==============================================================================
--- trunk/src/pidgin-plugin/simplezrtp/encrypt.h        (original)
+++ trunk/src/pidgin-plugin/simplezrtp/encrypt.h        Wed Aug 13 03:53:10 2014
@@ -187,6 +187,11 @@
 
 G_END_DECLS
 
+/*
+ * Helpers
+ */
+guint get_sid_by_mediatype(PurpleMedia *media, const gchar *session_id);
+
 /**
  * PurpleEncryptManager
  **/

Modified: trunk/src/pidgin-plugin/simplezrtp/zrtp-conference.c
URL: 
http://svn.gna.org/viewcvs/pidgin-zrtp/trunk/src/pidgin-plugin/simplezrtp/zrtp-conference.c?rev=32&r1=31&r2=32&view=diff
==============================================================================
--- trunk/src/pidgin-plugin/simplezrtp/zrtp-conference.c        (original)
+++ trunk/src/pidgin-plugin/simplezrtp/zrtp-conference.c        Wed Aug 13 
03:53:10 2014
@@ -641,8 +641,8 @@
                g_signal_new("new-zrtpfilter",
                                G_TYPE_FROM_CLASS(klass),
                                G_SIGNAL_RUN_LAST, 0, NULL, NULL,
-                               g_cclosure_marshal_VOID__STRING,
-                               G_TYPE_NONE, 1, G_TYPE_STRING);
+                               g_cclosure_marshal_VOID__OBJECT,
+                               G_TYPE_NONE, 1, G_TYPE_OBJECT);
 
        g_type_class_add_private(klass, sizeof(ZrtpConferencePrivate));
 }


_______________________________________________
Pidgin-zrtp-commits mailing list
Pidgin-zrtp-commits@gna.org
https://mail.gna.org/listinfo/pidgin-zrtp-commits

Reply via email to