[Telepathy-commits] [telepathy-gabble/master] allocate/free helpers for JingleCodec and JingleCandidate structs
Senko Rasic
senko at phyrexia.lan
Tue Dec 2 04:34:07 PST 2008
---
src/jingle-media-rtp.c | 54 +++++++++++++++++++++++++++-------------
src/jingle-media-rtp.h | 5 ++++
src/jingle-session.c | 3 +-
src/jingle-transport-google.c | 39 ++++-------------------------
src/jingle-transport-iface.c | 40 ++++++++++++++++++++++++++++++
src/jingle-transport-iface.h | 8 ++++++
src/media-stream.c | 42 ++++++++++++++++----------------
7 files changed, 117 insertions(+), 74 deletions(-)
diff --git a/src/jingle-media-rtp.c b/src/jingle-media-rtp.c
index 014383c..e7d2431 100644
--- a/src/jingle-media-rtp.c
+++ b/src/jingle-media-rtp.c
@@ -84,19 +84,42 @@ gabble_jingle_media_rtp_init (GabbleJingleMediaRtp *obj)
priv->dispose_has_run = FALSE;
}
-static void
-_free_codecs (GList *codecs)
+JingleCodec *
+jingle_media_rtp_codec_new (guint id, const gchar *name,
+ guint clockrate, guint channels, GHashTable *params)
{
- while (codecs != NULL)
- {
- JingleCodec *p = (JingleCodec *) codecs->data;
+ JingleCodec *p = g_slice_new0 (JingleCodec);
- if (p->params != NULL)
- g_hash_table_destroy (p->params);
+ p->id = id;
+ p->name = g_strdup (name);
+ p->clockrate = clockrate;
+ p->channels = channels;
+
+ if (params != NULL)
+ p->params = params;
+ else
+ p->params = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_free);
+
+ return p;
+}
- g_free (p->name);
- g_slice_free (JingleCodec, p);
+void
+jingle_media_rtp_codec_free (JingleCodec *p)
+{
+ if (p->params != NULL)
+ g_hash_table_destroy (p->params);
+ g_free (p->name);
+ g_slice_free (JingleCodec, p);
+}
+
+void
+jingle_media_rtp_free_codecs (GList *codecs)
+{
+ while (codecs != NULL)
+ {
+ JingleCodec *p = (JingleCodec *) codecs->data;
+ jingle_media_rtp_codec_free (p);
codecs = g_list_remove (codecs, p);
}
}
@@ -113,10 +136,10 @@ gabble_jingle_media_rtp_dispose (GObject *object)
DEBUG ("dispose called");
priv->dispose_has_run = TRUE;
- _free_codecs (priv->remote_codecs);
+ jingle_media_rtp_free_codecs (priv->remote_codecs);
priv->remote_codecs = NULL;
- _free_codecs (priv->local_codecs);
+ jingle_media_rtp_free_codecs (priv->local_codecs);
priv->local_codecs = NULL;
if (G_OBJECT_CLASS (gabble_jingle_media_rtp_parent_class)->dispose)
@@ -312,12 +335,7 @@ parse_description (GabbleJingleContent *content,
channels = 1;
}
- p = g_slice_new0 (JingleCodec);
- p->id = id;
- p->name = g_strdup (name);
- p->clockrate = clockrate;
- p->channels = channels;
- p->params = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_free);
+ p = jingle_media_rtp_codec_new (id, name, clockrate, channels, NULL);
for (i = 0; video_codec_params[i] != NULL; i++)
{
@@ -336,7 +354,7 @@ parse_description (GabbleJingleContent *content,
if (node != NULL)
{
/* rollback these */
- _free_codecs (codecs);
+ jingle_media_rtp_free_codecs (codecs);
SET_BAD_REQ ("invalid payload");
return;
}
diff --git a/src/jingle-media-rtp.h b/src/jingle-media-rtp.h
index 970e2a2..4bb3efa 100644
--- a/src/jingle-media-rtp.h
+++ b/src/jingle-media-rtp.h
@@ -75,5 +75,10 @@ void jingle_media_rtp_set_local_codecs (GabbleJingleMediaRtp *self,
GList *codecs);
GList *gabble_jingle_media_rtp_get_remote_codecs (GabbleJingleMediaRtp *self);
+JingleCodec * jingle_media_rtp_codec_new (guint id, const gchar *name,
+ guint clockrate, guint channels, GHashTable *params);
+void jingle_media_rtp_codec_free (JingleCodec *p);
+void jingle_media_rtp_free_codecs (GList *codecs);
+
#endif /* __JINGLE_MEDIA_RTP_H__ */
diff --git a/src/jingle-session.c b/src/jingle-session.c
index 94aeb65..d08d730 100644
--- a/src/jingle-session.c
+++ b/src/jingle-session.c
@@ -110,7 +110,8 @@ static JingleAction allowed_actions[MAX_JINGLE_STATES][MAX_ACTIONS_PER_STATE] =
JINGLE_ACTION_CONTENT_REMOVE,
JINGLE_ACTION_TRANSPORT_ACCEPT, JINGLE_ACTION_UNKNOWN },
/* JS_STATE_PENDING_ACCEPT_SENT */
- { JINGLE_ACTION_SESSION_TERMINATE, JINGLE_ACTION_UNKNOWN },
+ { JINGLE_ACTION_TRANSPORT_INFO,
+ JINGLE_ACTION_SESSION_TERMINATE, JINGLE_ACTION_UNKNOWN },
/* JS_STATE_ACTIVE */
{ JINGLE_ACTION_CONTENT_MODIFY, JINGLE_ACTION_CONTENT_ADD,
JINGLE_ACTION_CONTENT_REMOVE, JINGLE_ACTION_CONTENT_REPLACE,
diff --git a/src/jingle-transport-google.c b/src/jingle-transport-google.c
index b22ca8a..7ca41d6 100644
--- a/src/jingle-transport-google.c
+++ b/src/jingle-transport-google.c
@@ -97,23 +97,6 @@ gabble_jingle_transport_google_init (GabbleJingleTransportGoogle *obj)
}
static void
-_free_candidates (GList *candidates)
-{
- while (candidates != NULL)
- {
- JingleCandidate *c = (JingleCandidate *) candidates->data;
-
- g_free (c->address);
- g_free (c->username);
- g_free (c->password);
-
- g_slice_free (JingleCandidate, c);
-
- candidates = g_list_remove (candidates, c);
- }
-}
-
-static void
gabble_jingle_transport_google_dispose (GObject *object)
{
GabbleJingleTransportGoogle *trans = GABBLE_JINGLE_TRANSPORT_GOOGLE (object);
@@ -125,10 +108,10 @@ gabble_jingle_transport_google_dispose (GObject *object)
DEBUG ("dispose called");
priv->dispose_has_run = TRUE;
- _free_candidates (priv->remote_candidates);
+ jingle_transport_free_candidates (priv->remote_candidates);
priv->remote_candidates = NULL;
- _free_candidates (priv->local_candidates);
+ jingle_transport_free_candidates (priv->local_candidates);
priv->local_candidates = NULL;
g_free (priv->transport_ns);
@@ -365,16 +348,8 @@ parse_candidates (GabbleJingleTransportIface *obj,
gen = atoi (str);
- c = g_slice_new0 (JingleCandidate);
- c->address = g_strdup (address);
- c->port = port;
- c->protocol = proto;
- c->preference = pref;
- c->type = ctype;
- c->username = g_strdup (user);
- c->password = g_strdup (pass);
- c->network = net;
- c->generation = gen;
+ c = jingle_candidate_new (address, port, proto, pref,
+ ctype, user, pass, net, gen);
candidates = g_list_append (candidates, c);
}
@@ -383,7 +358,7 @@ parse_candidates (GabbleJingleTransportIface *obj,
{
DEBUG ("not all nodes were processed, reporting error");
/* rollback these */
- _free_candidates (candidates);
+ jingle_transport_free_candidates (candidates);
SET_BAD_REQ ("invalid candidate");
return;
}
@@ -393,10 +368,6 @@ parse_candidates (GabbleJingleTransportIface *obj,
g_signal_emit (obj, signals[NEW_CANDIDATES], 0, candidates);
/* append them to the known remote candidates */
-
- /* OK this sucks, do we really need to save it? if we want to save it we
- * can't borrow the strings, malloc hell ensues */
- /* we need to free the fields, make a custom function for it */
priv->remote_candidates = g_list_concat (priv->remote_candidates, candidates);
}
diff --git a/src/jingle-transport-iface.c b/src/jingle-transport-iface.c
index 7075fe2..55479d4 100644
--- a/src/jingle-transport-iface.c
+++ b/src/jingle-transport-iface.c
@@ -148,3 +148,43 @@ gabble_jingle_transport_iface_get_type (void)
return type;
}
+JingleCandidate *
+jingle_candidate_new (const gchar *address, guint port,
+ JingleTransportProtocol proto, gdouble pref, JingleCandidateType type,
+ const gchar *user, const gchar *pass, guint net, guint gen)
+{
+ JingleCandidate *c = g_slice_new0 (JingleCandidate);
+ c->address = g_strdup (address);
+ c->port = port;
+ c->protocol = proto;
+ c->preference = pref;
+ c->type = type;
+ c->username = g_strdup (user);
+ c->password = g_strdup (pass);
+ c->network = net;
+ c->generation = gen;
+
+ return c;
+}
+
+void
+jingle_candidate_free (JingleCandidate *c)
+{
+ g_free (c->address);
+ g_free (c->username);
+ g_free (c->password);
+
+ g_slice_free (JingleCandidate, c);
+}
+
+void
+jingle_transport_free_candidates (GList *candidates)
+{
+ while (candidates != NULL)
+ {
+ JingleCandidate *c = (JingleCandidate *) candidates->data;
+ jingle_candidate_free (c);
+ candidates = g_list_remove (candidates, c);
+ }
+}
+
diff --git a/src/jingle-transport-iface.h b/src/jingle-transport-iface.h
index ab3f8e7..90cf47b 100644
--- a/src/jingle-transport-iface.h
+++ b/src/jingle-transport-iface.h
@@ -23,6 +23,7 @@
#include <glib-object.h>
#include <loudmouth/loudmouth.h>
+#include "jingle-factory.h"
#include "types.h"
G_BEGIN_DECLS
@@ -67,6 +68,13 @@ void gabble_jingle_transport_iface_add_candidates (GabbleJingleTransportIface *,
void gabble_jingle_transport_iface_retransmit_candidates (GabbleJingleTransportIface *, gboolean);
GList *gabble_jingle_transport_iface_get_remote_candidates (GabbleJingleTransportIface *);
+JingleCandidate *jingle_candidate_new (const gchar *address, guint port,
+ JingleTransportProtocol proto, gdouble pref, JingleCandidateType type,
+ const gchar *user, const gchar *pass, guint net, guint gen);
+void jingle_candidate_free (JingleCandidate *c);
+void jingle_transport_free_candidates (GList *candidates);
+
+
G_END_DECLS
#endif /* #ifndef __GABBLE_JINGLE_TRANSPORT_IFACE_H__ */
diff --git a/src/media-stream.c b/src/media-stream.c
index 9858a86..f01c8e0 100644
--- a/src/media-stream.c
+++ b/src/media-stream.c
@@ -874,14 +874,25 @@ gabble_media_stream_new_native_candidate (TpSvcMediaStreamHandler *iface,
DEBUG ("put 1 native candidate from stream-engine into cache");
- c = g_slice_new0 (JingleCandidate);
- c->address = g_value_dup_string (g_value_array_get_nth (transport, 1));
- c->port = g_value_get_uint (g_value_array_get_nth (transport, 2));
- c->protocol = g_value_get_uint (g_value_array_get_nth (transport, 3));
- c->preference = g_value_get_double (g_value_array_get_nth (transport, 6));
- c->type = g_value_get_uint (g_value_array_get_nth (transport, 7));
- c->username = g_value_dup_string (g_value_array_get_nth (transport, 8));
- c->password = g_value_dup_string (g_value_array_get_nth (transport, 9));
+ c = jingle_candidate_new (
+ /* address */
+ g_value_get_string (g_value_array_get_nth (transport, 1)),
+ /* port */
+ g_value_get_uint (g_value_array_get_nth (transport, 2)),
+ /* protocol */
+ g_value_get_uint (g_value_array_get_nth (transport, 3)),
+ /* preference */
+ g_value_get_double (g_value_array_get_nth (transport, 6)),
+ /* candidate type, we're relying on 1:1 candidate type mapping */
+ g_value_get_uint (g_value_array_get_nth (transport, 7)),
+ /* username */
+ g_value_get_string (g_value_array_get_nth (transport, 8)),
+ /* password */
+ g_value_dup_string (g_value_array_get_nth (transport, 9)),
+ /* FIXME: network is hardcoded for now */
+ 0,
+ /* FIXME: generation is also hardcoded for now */
+ 0);
li = g_list_prepend (NULL, c);
gabble_jingle_content_add_candidates (priv->content, li);
@@ -979,13 +990,8 @@ gabble_media_stream_set_local_codecs (TpSvcMediaStreamHandler *iface,
5, ¶ms,
G_MAXUINT);
- c = g_slice_new0 (JingleCodec);
-
- c->id = id;
- c->name = g_strdup (name);
- c->clockrate = clock_rate;
- c->channels = channels;
- c->params = params;
+ c = jingle_media_rtp_codec_new (id, name,
+ clock_rate, channels, params);
DEBUG ("adding codec %s (%u %u %u)", c->name, c->id, c->clockrate, c->channels);
li = g_list_append (li, c);
@@ -1213,12 +1219,6 @@ new_remote_candidates_cb (GabbleJingleContent *content,
}
push_remote_candidates (stream);
-
- while (clist != NULL)
- {
- g_free (clist->data);
- clist = clist->next;
- }
}
static void
--
1.5.6.5
More information about the Telepathy-commits
mailing list