summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcus Lundblad <malu@pidgin.im>2009-08-31 20:23:51 +0000
committerMarcus Lundblad <malu@pidgin.im>2009-08-31 20:23:51 +0000
commitb3f807005a22605239fbe43bc100eb24c27214ea (patch)
treecfa11a01c7e3addf86020b527759e6824529d273
parentc9a3e5d288586ff8790a49bec178d891c3817bd7 (diff)
downloadpidgin-b3f807005a22605239fbe43bc100eb24c27214ea.tar.gz
Some unfinished code to take advantage of Google's relays
-rw-r--r--libpurple/media.c2
-rw-r--r--libpurple/protocols/jabber/google.c130
-rw-r--r--libpurple/protocols/jabber/jabber.c15
-rw-r--r--libpurple/protocols/jabber/jabber.h7
4 files changed, 115 insertions, 39 deletions
diff --git a/libpurple/media.c b/libpurple/media.c
index 015bf9f589..5dc9b6518e 100644
--- a/libpurple/media.c
+++ b/libpurple/media.c
@@ -2413,7 +2413,7 @@ purple_media_candidate_pair_established_cb(FsStream *fsstream,
FsParticipant *participant;
PurpleMediaStream *stream;
GList *iter;
-
+
g_return_if_fail(FS_IS_STREAM(fsstream));
g_return_if_fail(session != NULL);
diff --git a/libpurple/protocols/jabber/google.c b/libpurple/protocols/jabber/google.c
index 5619881289..b48469dd97 100644
--- a/libpurple/protocols/jabber/google.c
+++ b/libpurple/protocols/jabber/google.c
@@ -341,47 +341,27 @@ jabber_google_session_get_params(JabberStream *js, guint *num)
return new_params;
}
-
-gboolean
-jabber_google_session_initiate(JabberStream *js, const gchar *who, PurpleMediaSessionType type)
+static void
+jabber_google_relay_response_cb(PurpleUtilFetchUrlData *url_data,
+ gpointer user_data, const gchar *url_text, gsize len,
+ const gchar *error_message)
{
- GoogleSession *session;
- JabberBuddy *jb;
- JabberBuddyResource *jbr;
- gchar *jid;
+ GoogleSession *session = (GoogleSession *) user_data;
GParameter *params;
guint num_params;
+ JabberStream *js = session->js;
- /* construct JID to send to */
- jb = jabber_buddy_find(js, who, FALSE);
- if (!jb) {
- purple_debug_error("jingle-rtp",
- "Could not find Jabber buddy\n");
- return FALSE;
- }
- jbr = jabber_buddy_find_resource(jb, NULL);
- if (!jbr) {
- purple_debug_error("jingle-rtp",
- "Could not find buddy's resource\n");
- }
+ js->google_relay_request = NULL;
- if ((strchr(who, '/') == NULL) && jbr && (jbr->name != NULL)) {
- jid = g_strdup_printf("%s/%s", who, jbr->name);
+ purple_debug_info("jabber", "got response on HTTP request to relay server\n");
+
+ if (url_text && len > 0) {
+ purple_debug_info("jabber", "got Google relay request response:\n%s\n",
+ url_text);
} else {
- jid = g_strdup(who);
+
}
- session = g_new0(GoogleSession, 1);
- session->id.id = jabber_get_next_id(js);
- session->id.initiator = g_strdup_printf("%s@%s/%s", js->user->node,
- js->user->domain, js->user->resource);
- session->state = SENT_INITIATE;
- session->js = js;
- session->remote_jid = jid;
-
- if (type & PURPLE_MEDIA_VIDEO)
- session->video = TRUE;
-
session->media = purple_media_manager_create_media(
purple_media_manager_get(),
purple_connection_get_account(js->gc),
@@ -414,9 +394,69 @@ jabber_google_session_initiate(JabberStream *js, const gchar *who, PurpleMediaSe
return FALSE;
}
- g_free(params);
+ g_free(params);
+}
- return (session->media != NULL) ? TRUE : FALSE;
+gboolean
+jabber_google_session_initiate(JabberStream *js, const gchar *who, PurpleMediaSessionType type)
+{
+ GoogleSession *session;
+ JabberBuddy *jb;
+ JabberBuddyResource *jbr;
+ gchar *jid;
+
+ /* construct JID to send to */
+ jb = jabber_buddy_find(js, who, FALSE);
+ if (!jb) {
+ purple_debug_error("jingle-rtp",
+ "Could not find Jabber buddy\n");
+ return FALSE;
+ }
+ jbr = jabber_buddy_find_resource(jb, NULL);
+ if (!jbr) {
+ purple_debug_error("jingle-rtp",
+ "Could not find buddy's resource\n");
+ }
+
+ if ((strchr(who, '/') == NULL) && jbr && (jbr->name != NULL)) {
+ jid = g_strdup_printf("%s/%s", who, jbr->name);
+ } else {
+ jid = g_strdup(who);
+ }
+
+ session = g_new0(GoogleSession, 1);
+ session->id.id = jabber_get_next_id(js);
+ session->id.initiator = g_strdup_printf("%s@%s/%s", js->user->node,
+ js->user->domain, js->user->resource);
+ session->state = SENT_INITIATE;
+ session->js = js;
+ session->remote_jid = jid;
+
+ if (type & PURPLE_MEDIA_VIDEO)
+ session->video = TRUE;
+
+ /* if we got a relay token and relay host in google:jingleinfo, issue an
+ HTTP request to get that data */
+ if (js->google_relay_host && js->google_relay_token) {
+ const gchar *url =
+ g_strdup_printf("http://%s/create_session", js->google_relay_host);
+ const gchar *request =
+ g_strdup_printf("GET /create_session HTTP 1.1\r\n"
+ "X-Talk-Google-Relay-Auth: %s\r\n"
+ "X-Google-Relay-Auth: %s\r\n",
+ js->google_relay_token, js->google_relay_token);
+ js->google_relay_request =
+ purple_util_fetch_url_request(url, TRUE, NULL, TRUE, request, FALSE,
+ jabber_google_relay_response_cb, session);
+ g_free(url);
+ g_free(request);
+ } else {
+ jabber_google_relay_response_cb(NULL, session, NULL, 0, NULL);
+ }
+
+ /* we don't actually know yet wether it succeeded... maybe this is very
+ wrong... */
+ return TRUE;
}
static gboolean
@@ -1345,6 +1385,7 @@ jabber_google_jingle_info_common(JabberStream *js, const char *from,
JabberIqType type, xmlnode *query)
{
const xmlnode *stun = xmlnode_get_child(query, "stun");
+ const xmlnode *relay = xmlnode_get_child(query, "relay");
gchar *my_bare_jid;
/*
@@ -1388,8 +1429,23 @@ jabber_google_jingle_info_common(JabberStream *js, const char *from,
}
}
}
- /* should perhaps handle relays later on, or maybe wait until
- Google supports a common standard... */
+
+ if (relay) {
+ const xmlnode *token = xmlnode_get_child(relay, "token");
+ const xmlnode *server = xmlnode_get_child(relay, "server");
+
+ if (token) {
+ gchar *relay_token = xmlnode_get_data(token);
+
+ /* we let js own the string returned from xmlnode_get_data */
+ js->google_relay_token = relay_token;
+ }
+
+ if (server) {
+ js->google_relay_host =
+ g_strdup(xmlnode_get_attrib(server, "host"));
+ }
+ }
}
static void
diff --git a/libpurple/protocols/jabber/jabber.c b/libpurple/protocols/jabber/jabber.c
index 9c746ac908..fb7d9f4388 100644
--- a/libpurple/protocols/jabber/jabber.c
+++ b/libpurple/protocols/jabber/jabber.c
@@ -842,6 +842,9 @@ jabber_stream_new(PurpleAccount *account)
js->stun_ip = NULL;
js->stun_port = 0;
js->stun_query = NULL;
+ js->google_relay_token = NULL;
+ js->google_relay_host = NULL;
+ js->google_relay_request = NULL;
/* if we are idle, set idle-ness on the stream (this could happen if we get
disconnected and the reconnects while being idle. I don't think it makes
@@ -1563,6 +1566,15 @@ void jabber_close(PurpleConnection *gc)
js->stun_query = NULL;
}
+ /* remove Google relay-related stuff */
+ g_free(js->google_relay_token);
+ g_free(js->google_relay_host);
+
+ if (js->google_relay_request != NULL) {
+ purple_util_fetch_url_cancel(js->google_relay_request);
+ js->google_relay_request = NULL;
+ }
+
g_free(js);
gc->proto_data = NULL;
@@ -3021,6 +3033,9 @@ jabber_initiate_media(PurpleAccount *account, const char *who,
jbr = jabber_buddy_find_resource(jb, resource);
g_free(resource);
+ /*
+ return jabber_google_session_initiate(js, who, type);
+ */
if (type & PURPLE_MEDIA_AUDIO &&
!jabber_resource_has_capability(jbr,
JINGLE_APP_RTP_SUPPORT_AUDIO) &&
diff --git a/libpurple/protocols/jabber/jabber.h b/libpurple/protocols/jabber/jabber.h
index 27a7139bff..d56889ecb0 100644
--- a/libpurple/protocols/jabber/jabber.h
+++ b/libpurple/protocols/jabber/jabber.h
@@ -272,7 +272,12 @@ struct _JabberStream
gchar *stun_ip;
int stun_port;
PurpleDnsQueryData *stun_query;
- /* later add stuff to handle TURN relays... */
+
+ /* stuff for Google's relay handling */
+ gchar *google_relay_token;
+ gchar *google_relay_host;
+ PurpleUtilFetchUrlData *google_relay_request; /* the HTTP request to get */
+ /* relay info */
};
typedef gboolean (JabberFeatureEnabled)(JabberStream *js, const gchar *namespace);