/pidgin/main: 19eaf308a449: Initial support for Google's P2P tra...

Elliott Sales de Andrade qulogic at pidgin.im
Sun Jan 20 21:30:49 EST 2013


Changeset: 19eaf308a449f6a9a331c6ba3e90000ca41b9c83
Author:	 Elliott Sales de Andrade <qulogic at pidgin.im>
Date:	 2013-01-20 21:06 -0500
Branch:	 default
URL: http://hg.pidgin.im/pidgin/main/rev/19eaf308a449

Description:

Initial support for Google's P2P transport.

I have no idea if it'll work; I just set up the XML stuff based on the
Google Talk for Developers page [1]. Apparently this transport is used
for G+ calls.

[1] https://developers.google.com/talk/call_signaling

diffstat:

 libpurple/protocols/jabber/Makefile.am         |    2 +
 libpurple/protocols/jabber/google/google_p2p.c |  442 +++++++++++++++++++++++++
 libpurple/protocols/jabber/google/google_p2p.h |  102 +++++
 libpurple/protocols/jabber/jingle/jingle.c     |    3 +
 libpurple/protocols/jabber/jingle/rtp.c        |    5 +
 libpurple/protocols/jabber/namespaces.h        |    2 +
 6 files changed, 556 insertions(+), 0 deletions(-)

diffs (truncated from 627 to 300 lines):

diff --git a/libpurple/protocols/jabber/Makefile.am b/libpurple/protocols/jabber/Makefile.am
--- a/libpurple/protocols/jabber/Makefile.am
+++ b/libpurple/protocols/jabber/Makefile.am
@@ -31,6 +31,8 @@ JABBERSOURCES = \
 			  google/gmail.h \
 			  google/google.c \
 			  google/google.h \
+			  google/google_p2p.c \
+			  google/google_p2p.h \
 			  google/google_presence.c \
 			  google/google_presence.h \
 			  google/google_roster.c \
diff --git a/libpurple/protocols/jabber/google/google_p2p.c b/libpurple/protocols/jabber/google/google_p2p.c
new file mode 100644
--- /dev/null
+++ b/libpurple/protocols/jabber/google/google_p2p.c
@@ -0,0 +1,442 @@
+/**
+ * @file google_p2p.c
+ *
+ * purple
+ *
+ * Purple is the legal property of its developers, whose names are too numerous
+ * to list here.  Please refer to the COPYRIGHT file distributed with this
+ * source distribution.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
+ */
+
+#include "internal.h"
+
+#include "google_p2p.h"
+#include "jingle/jingle.h"
+#include "debug.h"
+
+#include <string.h>
+
+struct _JingleGoogleP2PPrivate
+{
+	GList *local_candidates;
+	GList *remote_candidates;
+};
+
+#define JINGLE_GOOGLE_P2P_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), JINGLE_TYPE_GOOGLE_P2P, JingleGoogleP2PPrivate))
+
+static void jingle_google_p2p_class_init (JingleGoogleP2PClass *klass);
+static void jingle_google_p2p_init (JingleGoogleP2P *google_p2p);
+static void jingle_google_p2p_finalize (GObject *object);
+static void jingle_google_p2p_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec);
+static void jingle_google_p2p_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);
+static JingleTransport *jingle_google_p2p_parse_internal(xmlnode *google_p2p);
+static xmlnode *jingle_google_p2p_to_xml_internal(JingleTransport *transport, xmlnode *content, JingleActionType action);
+static void jingle_google_p2p_add_local_candidate(JingleTransport *transport, const gchar *id, guint generation, PurpleMediaCandidate *candidate);
+static GList *jingle_google_p2p_get_remote_candidates(JingleTransport *transport);
+
+static JingleTransportClass *parent_class = NULL;
+
+enum {
+	PROP_0,
+	PROP_LOCAL_CANDIDATES,
+	PROP_REMOTE_CANDIDATES,
+};
+
+static JingleGoogleP2PCandidate *
+jingle_google_p2p_candidate_copy(JingleGoogleP2PCandidate *candidate)
+{
+	JingleGoogleP2PCandidate *new_candidate = g_new0(JingleGoogleP2PCandidate, 1);
+	new_candidate->id = g_strdup(candidate->id);
+	new_candidate->address = g_strdup(candidate->address);
+	new_candidate->port = candidate->port;
+	new_candidate->preference = candidate->preference;
+	new_candidate->type = g_strdup(candidate->type);
+	new_candidate->protocol = g_strdup(candidate->protocol);
+	new_candidate->username = g_strdup(candidate->username);
+	new_candidate->password = g_strdup(candidate->password);
+	new_candidate->generation = candidate->generation;
+
+	new_candidate->rem_known = candidate->rem_known;
+
+	return new_candidate;
+}
+
+static void
+jingle_google_p2p_candidate_free(JingleGoogleP2PCandidate *candidate)
+{
+	g_free(candidate->id);
+	g_free(candidate->address);
+	g_free(candidate->type);
+	g_free(candidate->protocol);
+	g_free(candidate->username);
+	g_free(candidate->password);
+}
+
+GType
+jingle_google_p2p_candidate_get_type(void)
+{
+	static GType type = 0;
+
+	if (type == 0) {
+		type = g_boxed_type_register_static("JingleGoogleP2PCandidate",
+				(GBoxedCopyFunc)jingle_google_p2p_candidate_copy,
+				(GBoxedFreeFunc)jingle_google_p2p_candidate_free);
+	}
+	return type;
+}
+
+JingleGoogleP2PCandidate *
+jingle_google_p2p_candidate_new(const gchar *id, guint generation,
+		const gchar *address, guint port, guint preference,
+		const gchar *type, const gchar *protocol,
+		const gchar *username, const gchar *password)
+{
+	JingleGoogleP2PCandidate *candidate = g_new0(JingleGoogleP2PCandidate, 1);
+	candidate->id = g_strdup(id);
+	candidate->address = g_strdup(address);
+	candidate->port = port;
+	candidate->preference = preference;
+	candidate->type = g_strdup(type);
+	candidate->protocol = g_strdup(protocol);
+	candidate->username = g_strdup(username);
+	candidate->password = g_strdup(password);
+	candidate->generation = generation;
+
+	candidate->rem_known = FALSE;
+	return candidate;
+}
+
+GType
+jingle_google_p2p_get_type(void)
+{
+	static GType type = 0;
+
+	if (type == 0) {
+		static const GTypeInfo info = {
+			sizeof(JingleGoogleP2PClass),
+			NULL,
+			NULL,
+			(GClassInitFunc) jingle_google_p2p_class_init,
+			NULL,
+			NULL,
+			sizeof(JingleGoogleP2P),
+			0,
+			(GInstanceInitFunc) jingle_google_p2p_init,
+			NULL
+		};
+		type = g_type_register_static(JINGLE_TYPE_TRANSPORT, "JingleGoogleP2P", &info, 0);
+	}
+	return type;
+}
+
+static void
+jingle_google_p2p_class_init(JingleGoogleP2PClass *klass)
+{
+	GObjectClass *gobject_class = (GObjectClass *)klass;
+	parent_class = g_type_class_peek_parent(klass);
+
+	gobject_class->finalize = jingle_google_p2p_finalize;
+	gobject_class->set_property = jingle_google_p2p_set_property;
+	gobject_class->get_property = jingle_google_p2p_get_property;
+	klass->parent_class.to_xml = jingle_google_p2p_to_xml_internal;
+	klass->parent_class.parse = jingle_google_p2p_parse_internal;
+	klass->parent_class.transport_type = NS_GOOGLE_TRANSPORT_P2P;
+	klass->parent_class.add_local_candidate = jingle_google_p2p_add_local_candidate;
+	klass->parent_class.get_remote_candidates = jingle_google_p2p_get_remote_candidates;
+
+	g_object_class_install_property(gobject_class, PROP_LOCAL_CANDIDATES,
+			g_param_spec_pointer("local-candidates",
+			"Local candidates",
+			"The local candidates for this transport.",
+			G_PARAM_READABLE));
+
+	g_object_class_install_property(gobject_class, PROP_REMOTE_CANDIDATES,
+			g_param_spec_pointer("remote-candidates",
+			"Remote candidates",
+			"The remote candidates for this transport.",
+			G_PARAM_READABLE));
+
+	g_type_class_add_private(klass, sizeof(JingleGoogleP2PPrivate));
+}
+
+static void
+jingle_google_p2p_init(JingleGoogleP2P *google_p2p)
+{
+	google_p2p->priv = JINGLE_GOOGLE_P2P_GET_PRIVATE(google_p2p);
+	google_p2p->priv->local_candidates = NULL;
+	google_p2p->priv->remote_candidates = NULL;
+}
+
+static void
+jingle_google_p2p_finalize(GObject *google_p2p)
+{
+/*	JingleGoogleP2PPrivate *priv = JINGLE_GOOGLE_P2P_GET_PRIVATE(google_p2p); */
+	purple_debug_info("jingle","jingle_google_p2p_finalize\n");
+
+	G_OBJECT_CLASS(parent_class)->finalize(google_p2p);
+}
+
+static void
+jingle_google_p2p_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
+{
+	JingleGoogleP2P *google_p2p;
+
+	g_return_if_fail(object != NULL);
+	g_return_if_fail(JINGLE_IS_GOOGLE_P2P(object));
+
+	google_p2p = JINGLE_GOOGLE_P2P(object);
+
+	switch (prop_id) {
+		case PROP_LOCAL_CANDIDATES:
+			google_p2p->priv->local_candidates = g_value_get_pointer(value);
+			break;
+		case PROP_REMOTE_CANDIDATES:
+			google_p2p->priv->remote_candidates = g_value_get_pointer(value);
+			break;
+		default:
+			G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+			break;
+	}
+}
+
+static void
+jingle_google_p2p_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
+{
+	JingleGoogleP2P *google_p2p;
+
+	g_return_if_fail(object != NULL);
+	g_return_if_fail(JINGLE_IS_GOOGLE_P2P(object));
+
+	google_p2p = JINGLE_GOOGLE_P2P(object);
+
+	switch (prop_id) {
+		case PROP_LOCAL_CANDIDATES:
+			g_value_set_pointer(value, google_p2p->priv->local_candidates);
+			break;
+		case PROP_REMOTE_CANDIDATES:
+			g_value_set_pointer(value, google_p2p->priv->remote_candidates);
+			break;
+		default:
+			G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+			break;
+	}
+}
+
+static void
+jingle_google_p2p_add_local_candidate(JingleTransport *transport, const gchar *id,
+                                      guint generation, PurpleMediaCandidate *candidate)
+{
+	JingleGoogleP2P *google_p2p = JINGLE_GOOGLE_P2P(transport);
+	JingleGoogleP2PCandidate *google_p2p_candidate;
+	gchar *ip;
+	gchar *username;
+	gchar *password;
+	PurpleMediaCandidateType type;
+	PurpleMediaNetworkProtocol protocol;
+	GList *iter;
+
+	ip = purple_media_candidate_get_ip(candidate);
+	username = purple_media_candidate_get_username(candidate);
+	password = purple_media_candidate_get_password(candidate);
+	type = purple_media_candidate_get_candidate_type(candidate);
+	protocol = purple_media_candidate_get_protocol(candidate);
+
+	google_p2p_candidate = jingle_google_p2p_candidate_new(id, generation,
+			ip, purple_media_candidate_get_port(candidate),
+			purple_media_candidate_get_priority(candidate),
+			type == PURPLE_MEDIA_CANDIDATE_TYPE_HOST ? "host" :
+			type == PURPLE_MEDIA_CANDIDATE_TYPE_SRFLX ? "srflx" :
+			type == PURPLE_MEDIA_CANDIDATE_TYPE_PRFLX ? "prflx" :
+			type == PURPLE_MEDIA_CANDIDATE_TYPE_RELAY ? "relay" :
+			"",
+			protocol == PURPLE_MEDIA_NETWORK_PROTOCOL_UDP ? "udp" : "tcp",
+			username, password);
+
+	g_free(password);
+	g_free(username);
+	g_free(ip);
+
+	for (iter = google_p2p->priv->local_candidates; iter; iter = g_list_next(iter)) {
+		JingleGoogleP2PCandidate *c = iter->data;
+		if (!strcmp(c->id, id)) {
+			generation = c->generation + 1;
+
+			g_boxed_free(JINGLE_TYPE_GOOGLE_P2P_CANDIDATE, c);
+			google_p2p->priv->local_candidates = g_list_delete_link(
+					google_p2p->priv->local_candidates, iter);
+
+			google_p2p_candidate->generation = generation;
+



More information about the Commits mailing list