/soc/2013/ashmew2/filetransferX: 2972c9d6c851: _READY state for LAN
Ashish Gupta
ashmew2 at gmail.com
Tue Aug 20 19:07:21 EDT 2013
Changeset: 2972c9d6c851973fa3ba2ee9dcd7994e3a58c2bb
Author: Ashish Gupta <ashmew2 at gmail.com>
Date: 2013-08-20 16:09 +0530
Branch: filetransferX
URL: https://hg.pidgin.im/soc/2013/ashmew2/filetransferX/rev/2972c9d6c851
Description:
_READY state for LAN
diffstat:
libpurple/protocols/jabber/google/google_session.c | 92 +++++++++++++++++++--
libpurple/xmlnode.c | 1 +
2 files changed, 81 insertions(+), 12 deletions(-)
diffs (184 lines):
diff --git a/libpurple/protocols/jabber/google/google_session.c b/libpurple/protocols/jabber/google/google_session.c
--- a/libpurple/protocols/jabber/google/google_session.c
+++ b/libpurple/protocols/jabber/google/google_session.c
@@ -477,12 +477,13 @@ jabber_google_relay_response_session_ini
nice_agent_attach_recv(agent, stream_id, 1, g_main_context_default(),
cb_nice_recv, session);
+
g_signal_connect(G_OBJECT(agent), "candidate-gathering-done",
G_CALLBACK(cb_candidate_gathering_done), session);
g_signal_connect(G_OBJECT(agent), "reliable-transport-writable",
G_CALLBACK(cb_nice_component_writable), session);
g_signal_connect(G_OBJECT(agent), "component-state-changed",
- G_CALLBACK(cb_nice_component_state_changed), session);
+ G_CALLBACK(cb_nice_component_state_changed), share_session);
/*Add relay candidates to our candidate list?*/
/* * candidate address='49.248.181.68' port='46448' username='HKmLfAkZB81f7r8x' password='' preference='0.000000' protocol='udp' type='stun' component='1' network='0' generation='0' name='private-1'
*/
@@ -1203,8 +1204,8 @@ nice_candidate_from_xml(const xmlnode *c
nice_address_init(&cand->addr);
if (!nice_address_set_from_string(&cand->addr, address)) {
- purple_debug_error("google-share",
- "got invalid address in remote candidate\n");
+ purple_debug_error("google_session",
+ "Invalid NiceAddress in NiceCandidate.\n");
nice_candidate_free(cand);
return NULL;
}
@@ -1215,7 +1216,7 @@ nice_candidate_from_xml(const xmlnode *c
cand->username = g_strdup(xmlnode_get_attrib(candidate, "username"));
cand->password = g_strdup(xmlnode_get_attrib(candidate, "password"));
} else {
- purple_debug_error("google-share", "received invalid candidate!\n");
+ purple_debug_error("google_session", "received invalid candidate!\n");
}
return cand;
@@ -1272,7 +1273,6 @@ gtalk_xfer_handle_candidates(JabberStrea
jabber_iq_set_id(result, iq_id);
xmlnode_set_attrib(result->node, "to", session->remote_jid);
jabber_iq_send(result);
-
}
static void
@@ -1367,6 +1367,7 @@ google_session_handle_terminate(JabberSt
{
GoogleAVSessionData *session_data =
(GoogleAVSessionData *) session->session_data;
+
purple_media_end(session_data->media, NULL, NULL);
}
@@ -1549,18 +1550,27 @@ gtalk_xfer_send_candidates(GoogleSession
/*Thanks for this, malu :D*/
static xmlnode *
nice_candidate_to_xml(const NiceCandidate *cand,
- const gchar *channel_name)
+ GoogleXferSessionData *share_session)
{
xmlnode *candidate = xmlnode_new("candidate");
gchar address[NICE_ADDRESS_STRING_LEN];
gchar pref[16];
+ gchar *local_ufrag, *local_password;
nice_address_to_string(&cand->addr, address);
xmlnode_set_attrib(candidate, "address", address);
xmlnode_set_attrib(candidate, "port",
g_strdup_printf("%d", nice_address_get_port(&cand->addr)));
- xmlnode_set_attrib(candidate, "name", channel_name);
- xmlnode_set_attrib(candidate, "username", cand->username);
+ xmlnode_set_attrib(candidate, "name", share_session->channel_name);
+
+ if(!cand->username) {
+ nice_agent_get_local_credentials(share_session->share_agent, share_session->stream_id,
+ &local_ufrag, &local_password);
+ xmlnode_set_attrib(candidate, "username", local_ufrag);
+ }
+ else
+ xmlnode_set_attrib(candidate, "username", cand->username);
+
xmlnode_set_attrib(candidate, "password",
cand->password != NULL ? cand->password : "");
g_ascii_dtostr(pref, 16, cand->priority / 1000.0);
@@ -1589,8 +1599,8 @@ cb_candidate_gathering_done(NiceAgent *a
GoogleAVSessionData *session_data = session->session_data;
GoogleXferSessionData *share_session = session_data->share_session;
GList *local_candidates = nice_agent_get_local_candidates(agent, stream_id, 1);
-
- purple_debug_info("google-share", "candidate gathering done!\n");
+
+ purple_debug_info("google_session", "candidate gathering done!\n");
share_session->candidates_gathered = TRUE;
/* add remote candidates received while gathering local candidates */
@@ -1619,7 +1629,7 @@ cb_candidate_gathering_done(NiceAgent *a
xmlnode *sess = google_session_create_xmlnode(session, "transport-info");
xmlnode *transport = xmlnode_new_child(sess, "transport");
- xmlnode_insert_child(transport, nice_candidate_to_xml(candidate, share_session->channel_name));
+ xmlnode_insert_child(transport, nice_candidate_to_xml(candidate, share_session));
xmlnode_set_namespace(transport, NS_GOOGLE_TRANSPORT_P2P);
xmlnode_insert_child(iq->node, sess);
@@ -1715,8 +1725,66 @@ char *nice_component_state_to_str(guint
void cb_nice_component_state_changed(NiceAgent *agent,guint stream_id, guint component_id,
guint state, gpointer user_data)
{
- purple_debug_info("google_session", "__State of NiceAgent Changed...Current State : [%d]%s.Stream ID: %d", state, nice_component_state_to_str(state), stream_id);
+ GoogleXferSessionData *share_session = (GoogleXferSessionData *)user_data;
+ share_session->agent_state = state;
+ purple_debug_info("google_session", "__State of NiceAgent Changed...Current State : [%d]%s.Stream ID: %d\n", state, nice_component_state_to_str(state), stream_id);
+ if(state == NICE_COMPONENT_STATE_CONNECTED) {
+ GSList *remote_candids = nice_agent_get_remote_candidates(agent, stream_id, component_id);
+ GSList *local_candids = nice_agent_get_local_candidates(agent, stream_id, component_id);
+ NiceCandidate *rc = (NiceCandidate *)remote_candids->data;
+ NiceCandidate *lc = (NiceCandidate *)local_candids->data;
+ gchar *ip = g_malloc(NICE_ADDRESS_STRING_LEN + 1);
+ gboolean set_pair;
+
+/* strcpy(rc->foundation, "rf");
+ strcpy(lc->foundation, "lf");
+*/
+ purple_debug_info("google_session", "Foundations of rc and lc are : %s and %s\n",rc->foundation, lc->foundation);
+ nice_address_to_string(&lc->addr, ip);
+ purple_debug_info("google_session", "LC => IP: %s, Port:%u\n",ip,nice_address_get_port(&lc->addr));
+ nice_address_to_string(&rc->addr, ip);
+ purple_debug_info("google_session", "RC =>IP: %s, Port:%u\n",ip,nice_address_get_port(&rc->addr));
+
+ set_pair = nice_agent_set_selected_pair(agent, stream_id, component_id, lc->foundation, rc->foundation);
+
+ if(set_pair)
+ purple_debug_info("google_session", "Candidate Pair SET!\n");
+ else
+
+ purple_debug_info("google_session", "Candidate Pair COULD NOT BE SET..\n");
+
+/*TODO: REMOVE ME: Prints out useful list of remote and local candidates so far..*/
+/*
+ purple_debug_info("google_session", "List of remote candidates : \n********\n");
+ while(remote_candids) {
+ gchar *ip = g_malloc(NICE_ADDRESS_STRING_LEN + 1);
+ NiceCandidate *c = (NiceCandidate *)remote_candids->data;
+ nice_address_to_string(&c->addr, ip);
+
+ purple_debug_info("google_session", "IP: %s, Port:%u\n",ip,nice_address_get_port(&c->addr));
+/* nice_candidate_free(c);
+ remote_candids = g_slist_remove(remote_candids, remote_candids);
+*/
+/* remote_candids = remote_candids->next;
+ }
+ purple_debug_info("google_session", "***********\n");
+
+ purple_debug_info("google_session", "List of local candidates : \n********\n");
+ while(local_candids) {
+ gchar *ip = g_malloc(NICE_ADDRESS_STRING_LEN + 1);
+ NiceCandidate *c = (NiceCandidate *)local_candids->data;
+ nice_address_to_string(&c->addr, ip);
+
+ purple_debug_info("google_session", "IP: %s, Port:%u\n",ip,nice_address_get_port(&c->addr));
+/* nice_candidate_free(c);
+ local_candids = g_slist_remove(local_candids, local_candids);
+*/
+/* local_candids = local_candids->next;
+ }
+ purple_debug_info("google_session", "***********\n");
+*/
+ }
}
/*TODO: Add more stuff related to state changes here*/
diff --git a/libpurple/xmlnode.c b/libpurple/xmlnode.c
--- a/libpurple/xmlnode.c
+++ b/libpurple/xmlnode.c
@@ -209,6 +209,7 @@ xmlnode_set_attrib_full(xmlnode *node, c
g_return_if_fail(node != NULL);
g_return_if_fail(attr != NULL);
+ if(!value) purple_debug_info("google_session", "Name of attribute/prefix we tried to set : %s/%s\n", attr, prefix);
g_return_if_fail(value != NULL);
xmlnode_remove_attrib_with_namespace(node, attr, xmlns);
More information about the Commits
mailing list