cpw.malu.xmpp.google_ft: 99ea19f5: wait for iq responses when sending trans...
malu at pidgin.im
malu at pidgin.im
Wed Sep 15 16:06:29 EDT 2010
----------------------------------------------------------------------
Revision: 99ea19f591116be7fb6e5c0ac3be63f5674f98d8
Parent: f1792777d16a5e521697a716d38847ce4ef2521d
Author: malu at pidgin.im
Date: 09/15/10 16:03:19
Branch: im.pidgin.cpw.malu.xmpp.google_ft
URL: http://d.pidgin.im/viewmtn/revision/info/99ea19f591116be7fb6e5c0ac3be63f5674f98d8
Changelog:
wait for iq responses when sending transport accept, accept and channel message. attempt to fall back to older specification for sending candidates (they don't have separate namespaces...)
Changes against parent f1792777d16a5e521697a716d38847ce4ef2521d
patched libpurple/protocols/jabber/google/google_share.c
-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/google/google_share.c e35cb83146380f1bd261c3a03c37c0c5f45ef561
+++ libpurple/protocols/jabber/google/google_share.c 4a58e1b09220595ee7b110487f0ee5e8f2b55d0f
@@ -35,6 +35,7 @@ typedef struct {
gchar *channel_name;
GList *remote_candidates; /* list of PurpleMediaCandidate */
gboolean got_relay; /* this indicates if gotten relay credentials */
+ gboolean old_protocol;
} GoogleShareSessionData;
static void
@@ -80,6 +81,33 @@ google_share_nice_candidate_to_xml(const
return candidate;
}
+static xmlnode *
+google_share_create_candidate_node(GoogleSession *session,
+ const NiceCandidate *candidate)
+{
+ GoogleShareSessionData *session_data =
+ (GoogleShareSessionData *) session->session_data;
+ xmlnode *sess;
+
+ if (session_data->old_protocol) {
+ sess = google_session_create_xmlnode(session, "candidates");
+ xmlnode_insert_child(sess,
+ google_share_nice_candidate_to_xml(candidate,
+ session_data->channel_name));
+ } else {
+ xmlnode *transport;
+
+ sess = google_session_create_xmlnode(session, "transport-info");
+ transport = xmlnode_new_child(sess, "tranport");
+ xmlnode_set_namespace(transport, NS_GOOGLE_TRANSPORT_P2P);
+ xmlnode_insert_child(transport,
+ google_share_nice_candidate_to_xml(candidate,
+ session_data->channel_name));
+ }
+
+ return sess;
+}
+
static void
google_share_candidate_gathering_done_cb(NiceAgent *agent,
guint stream_id, gpointer user_data)
@@ -95,17 +123,10 @@ google_share_candidate_gathering_done_cb
while (candidates) {
NiceCandidate *candidate = (NiceCandidate *) candidates->data;
JabberIq *iq = jabber_iq_new(session->js, JABBER_IQ_SET);
- xmlnode *sess =
- google_session_create_xmlnode(session, "transport-info");
- xmlnode *transport = xmlnode_new_child(sess, "tranport");
+ xmlnode *sess = google_share_create_candidate_node(session, candidate);
- xmlnode_set_namespace(transport, NS_GOOGLE_TRANSPORT_P2P);
xmlnode_insert_child(iq->node, sess);
xmlnode_set_attrib(iq->node, "to", session->remote_jid);
- xmlnode_insert_child(transport,
- google_share_nice_candidate_to_xml(candidate,
- session_data->channel_name));
-
jabber_iq_send(iq);
nice_candidate_free(candidate);
@@ -122,65 +143,119 @@ static void
}
static void
-google_share_init(PurpleXfer *xfer)
+google_share_channel_cb(JabberStream *js, const gchar *from,
+ JabberIqType type, const gchar *id, xmlnode *packet, gpointer data)
{
- GoogleSession *session = (GoogleSession *) xfer->data;
+ purple_debug_info("google-share", "got response to channel\n");
+
+ if (type == JABBER_IQ_RESULT) {
+ GoogleSession *session = (GoogleSession *) data;
+ GoogleShareSessionData *session_data =
+ (GoogleShareSessionData *) session->session_data;
+
+ /* start agent */
+ nice_agent_gather_candidates(session_data->agent, session_data->stream_id);
+ /* set up signal */
+ nice_agent_attach_recv(session_data->agent, session_data->stream_id,
+ NICE_COMPONENT_TYPE_RTP, g_main_context_default(),
+ google_share_data_received_cb, session);
+ g_signal_connect(G_OBJECT(session_data->agent),
+ "candidate-gathering-done",
+ G_CALLBACK(google_share_candidate_gathering_done_cb), session);
+ g_signal_connect(G_OBJECT(session_data->agent),
+ "reliable-transport-writable",
+ G_CALLBACK(google_share_writable_cb), session);
+ }
+}
+
+static void
+google_share_accept_cb(JabberStream *js, const gchar *from,
+ JabberIqType type, const gchar *id, xmlnode *packet, gpointer data)
+{
+ purple_debug_info("google-share", "got response to session accept\n");
+
+ if (type == JABBER_IQ_RESULT) {
+ GoogleSession *session = (GoogleSession *) data;
+ GoogleShareSessionData *session_data =
+ (GoogleShareSessionData *) session->session_data;
+ gchar *me = g_strdup_printf("%s@%s/%s",
+ session->js->user->node,
+ session->js->user->domain,
+ session->js->user->resource);
+
+ /* create channel */
+ JabberIq *iq = jabber_iq_new(session->js, JABBER_IQ_SET);
+ xmlnode *sess = google_session_create_xmlnode(session, "info");
+ xmlnode *channel = xmlnode_new_child(sess, "channel");
+
+ session_data->channel_name = jabber_get_next_id(session->js);
+
+ xmlnode_set_namespace(channel, NS_GOOGLE_SESSION_SHARE);
+ xmlnode_set_attrib(channel, "name", session_data->channel_name);
+ xmlnode_set_attrib(iq->node, "to", session->remote_jid);
+ xmlnode_set_attrib(iq->node, "from", me);
+ xmlnode_insert_child(iq->node, sess);
+ jabber_iq_set_callback(iq, google_share_channel_cb, session);
+ jabber_iq_send(iq);
+ }
+}
+
+static void
+google_share_transport_accept_cb(JabberStream *js, const gchar *from,
+ JabberIqType type, const gchar *id, xmlnode *packet, gpointer data)
+{
+ GoogleSession *session = (GoogleSession *) data;
GoogleShareSessionData *session_data =
(GoogleShareSessionData *) session->session_data;
gchar *me = g_strdup_printf("%s@%s/%s",
session->js->user->node,
session->js->user->domain,
session->js->user->resource);
+
+ JabberIq *iq = jabber_iq_new(session->js, JABBER_IQ_SET);
+ xmlnode *sess = google_session_create_xmlnode(session, "accept");
+ xmlnode *transport = xmlnode_new_child(sess, "transport");
+
+ purple_debug_info("google-share", "got response to transport-accept\n");
+
+ if (type == JABBER_IQ_ERROR) {
+ purple_debug_info("google-share",
+ "initiator doesn't support the v4 protocol\n");
+ session_data->old_protocol = TRUE;
+ }
+
+ xmlnode_set_attrib(iq->node, "to", session->remote_jid);
+ xmlnode_set_attrib(iq->node, "from", me);
+ xmlnode_insert_child(iq->node, sess);
+ xmlnode_insert_child(sess, xmlnode_copy(session->description));
+ xmlnode_set_namespace(transport, NS_GOOGLE_TRANSPORT_P2P);
+ jabber_iq_set_callback(iq, google_share_accept_cb, session);
+ jabber_iq_send(iq);
+}
+
+static void
+google_share_init(PurpleXfer *xfer)
+{
+ GoogleSession *session = (GoogleSession *) xfer->data;
+ gchar *me = g_strdup_printf("%s@%s/%s",
+ session->js->user->node,
+ session->js->user->domain,
+ session->js->user->resource);
JabberIq *iq;
xmlnode *sess;
- xmlnode *channel;
xmlnode *transport;
-
+
/* send transport-accept
should this only be for Google session v0.4? */
iq = jabber_iq_new(session->js, JABBER_IQ_SET);
sess = google_session_create_xmlnode(session, "transport-accept");
transport = xmlnode_new_child(sess, "transport");
xmlnode_set_namespace(transport, NS_GOOGLE_TRANSPORT_P2P);
- xmlnode_set_attrib(transport, "name", session_data->channel_name);
xmlnode_set_attrib(iq->node, "to", session->remote_jid);
xmlnode_set_attrib(iq->node, "from", me);
xmlnode_insert_child(iq->node, sess);
+ jabber_iq_set_callback(iq, google_share_transport_accept_cb, session);
jabber_iq_send(iq);
-
- /* send accept */
- iq = jabber_iq_new(session->js, JABBER_IQ_SET);
- sess = google_session_create_xmlnode(session, "accept");
- xmlnode_set_attrib(iq->node, "to", session->remote_jid);
- xmlnode_set_attrib(iq->node, "from", me);
- xmlnode_insert_child(iq->node, sess);
- xmlnode_insert_child(sess, xmlnode_copy(session->description));
- jabber_iq_send(iq);
-
- /* create channel */
- session_data->channel_name = jabber_get_next_id(session->js);
- iq = jabber_iq_new(session->js, JABBER_IQ_SET);
- sess = google_session_create_xmlnode(session, "info");
- channel = xmlnode_new_child(sess, "channel");
- xmlnode_set_namespace(channel, NS_GOOGLE_SHARE);
- xmlnode_set_attrib(channel, "name", session_data->channel_name);
- xmlnode_set_attrib(iq->node, "to", session->remote_jid);
- xmlnode_set_attrib(iq->node, "from", me);
- xmlnode_insert_child(iq->node, sess);
- jabber_iq_send(iq);
-
- /* start agent */
- nice_agent_gather_candidates(session_data->agent, session_data->stream_id);
- /* set up signal */
- nice_agent_attach_recv(session_data->agent, session_data->stream_id,
- NICE_COMPONENT_TYPE_RTP, g_main_context_default(),
- google_share_data_received_cb, session);
- g_signal_connect(G_OBJECT(session_data->agent),
- "candidate-gathering-done",
- G_CALLBACK(google_share_candidate_gathering_done_cb), session);
- g_signal_connect(G_OBJECT(session_data->agent),
- "reliable-transport-writable",
- G_CALLBACK(google_share_writable_cb), session);
}
static void
More information about the Commits
mailing list