/soc/2013/ashmew2/filetransferX: 55c8b5d71ef4: Candidates_prepare()
Ashish Gupta
ashmew2 at gmail.com
Fri Aug 16 16:49:29 EDT 2013
Changeset: 55c8b5d71ef4e2385c81c536f08900e9fa5bbf8f
Author: Ashish Gupta <ashmew2 at gmail.com>
Date: 2013-08-17 00:13 +0530
Branch: filetransferX
URL: https://hg.pidgin.im/soc/2013/ashmew2/filetransferX/rev/55c8b5d71ef4
Description:
Candidates_prepare()
diffstat:
libpurple/protocols/jabber/google/google_session.c | 299 +++++++++-----------
1 files changed, 142 insertions(+), 157 deletions(-)
diffs (truncated from 437 to 300 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
@@ -438,7 +438,7 @@ jabber_google_relay_response_session_ini
share_session->local_share_candidates = g_list_prepend(share_session->local_share_candidates, relay_candidate_tcp);
share_session->local_share_candidates = g_list_prepend(share_session->local_share_candidates, relay_candidate_ssltcp);
- purple_debug_info("google_session", "Added relay candidates without a crash");
+ purple_debug_info("google_session", "Added relay candidates without a crash.\n");
purple_debug_info("google_session", "Trying to Set Relay IP : %s\n", relay_ip);
if(!nice_agent_set_relay_info (agent, share_session->stream_id, 0, relay_ip, relay_udp, relay_username,
@@ -446,6 +446,7 @@ jabber_google_relay_response_session_ini
purple_debug_info("google_session","Setting Relay on Niceagent Failed..\n");
else
purple_debug_info("google_session","Setting Relay on Niceagent Succeeded..\n");
+
return;
}
@@ -878,7 +879,8 @@ gtalk_get_request_cb(PurpleUtilFetchUrlD
gpointer user_data, const gchar *url_text, gsize len,
const gchar *error_message)
{
- purple_debug_info("google_session", "inside gtalk_get_request_cb");
+
+ purple_debug_info("google_session", "inside gtalk_get_request_cb, url_text : %s", url_text);
}
static void
@@ -997,6 +999,8 @@ google_session_handle_candidates(JabberS
jabber_iq_send(result);
/* TODO: Relocate me to proper place */
+/* TODO: Please use the below somewhere..looks right?*/
+/*
if(1) {
PurpleUtilFetchUrlData *url_data = NULL;
@@ -1019,7 +1023,8 @@ google_session_handle_candidates(JabberS
else
purple_debug_info("google_session", "Got no data....\n");
- }
+ }
+*/
}
static void
@@ -1139,6 +1144,100 @@ gtalk_port_cb(int listenfd, gpointer dat
}
+
+static void
+gtalk_xfer_send_candidates(GoogleSession *session)
+{
+
+ GoogleAVSessionData *session_data = (GoogleAVSessionData *)session->session_data;
+ GoogleXferSessionData *share_session = session_data->share_session;
+ GList *candidates = share_session->local_share_candidates;
+ GList *iter;
+
+ /*Is component ID necessary? This is a share session TODO*/
+/* component_id = purple_media_candidate_get_component_id(
+ transport);
+*/ /*Format we want to use : TODO REMOVE :
+ <iq to="doondoon1234 at gmail.com/F0529E73" type="set" id="249" from="ashmew2 at gmail.com/Talk.v1040217A105"><session type="transport-info" id="1195983148" initiator="ashmew2 at gmail.com/Talk.v1040217A105" xmlns="http://www.google.com/session"><transport xmlns="http://www.google.com/transport/p2p"><candidate name="private-1" address="10.0.2.15" port="58919" preference="1" username="j8xIQAN/LvaC/dxb" protocol="udp" generation="0" password="eEy12J+BFBmZO0jj" type="local" network="0"/></transport></session></iq>
+ */
+/*TODO: Figure out why getting local credentials is required*/
+/*
+ if(!nice_agent_get_local_credentials(agent, stream_id,
+ &username, &password))
+ purple_debug_info("google_session","Getting local credentials FAILED..\n");
+ else
+ purple_debug_info("google_session","Getting local credentials SUCCESSFUL..\n");
+*/
+ for(iter = candidates; iter; iter = iter->next) {
+ JabberIq *iq;
+ gchar *ip = g_malloc(NICE_ADDRESS_STRING_LEN + 1);
+ gchar *pref, *port;
+ gchar *username, *password;
+ xmlnode *sess;
+ xmlnode *candidate, *transport;
+ NiceCandidate *nice_candid = (NiceCandidate *)iter->data;
+ NiceCandidateType type;
+
+ iq = jabber_iq_new(session->js, JABBER_IQ_SET);
+ sess = google_session_create_xmlnode(session, "transport-info");
+ xmlnode_insert_child(iq->node, sess);
+ xmlnode_set_attrib(iq->node, "to", session->remote_jid);
+
+ purple_debug_info("google_session", "IQ Created. Now Transport Node : \n");
+ transport = xmlnode_new("transport");
+ xmlnode_set_namespace(transport, NS_GOOGLE_TRANSPORT_P2P);
+ xmlnode_insert_child(sess, transport);
+
+ candidate = xmlnode_new("candidate");
+
+ nice_address_to_string(&nice_candid->addr, ip);
+ port = g_strdup_printf("%u",nice_address_get_port(&nice_candid->addr));
+
+ purple_debug_info("google_session", "IP and port : %s:%s\n",ip,port);
+ pref = g_strdup_printf("%u",nice_candid->priority);
+
+ type = nice_candid->type;
+// purple_debug_info("google_session", "Setting attributes now.. : \n");
+
+ xmlnode_set_attrib(candidate, "address", ip);
+ xmlnode_set_attrib(candidate, "port", port);
+ xmlnode_set_attrib(candidate, "name", "private-1"); /*TODO: Seems to work?*/
+
+ username = g_strdup(nice_candid->username);
+ password = g_strdup(nice_candid->password);
+
+ xmlnode_set_attrib(candidate, "username", username != NULL ? username : "");
+ xmlnode_set_attrib(candidate, "password",
+ password != NULL ? password : "");
+
+// purple_debug_info("google_session", "Setting even more attributes now.. : \n");
+/*TODO: Fix preference*/
+ xmlnode_set_attrib(candidate, "preference", "0.9");
+ xmlnode_set_attrib(candidate, "protocol", "udp");
+/*TODO: ADD RELAY SERVERS ASAP! Are they working now?*/
+ /*CHECK THIS : TODO Type*/
+
+// purple_debug_info("google_session", "Setting type attrib : \n");
+ xmlnode_set_attrib(candidate, "type",
+ type == NICE_CANDIDATE_TYPE_HOST ? "local":
+ type == NICE_CANDIDATE_TYPE_SERVER_REFLEXIVE ? "stun":
+ type == NICE_CANDIDATE_TYPE_PEER_REFLEXIVE ? "prflx":
+ type == NICE_CANDIDATE_TYPE_RELAYED ? "relay"
+ : "local");
+
+ xmlnode_set_attrib(candidate, "generation", "0");
+ xmlnode_set_attrib(candidate, "network", "0");
+ xmlnode_insert_child(transport, candidate);
+
+ g_free(ip);
+ g_free(port);
+ g_free(username);
+ g_free(password);
+ jabber_iq_send(iq);
+
+ }
+}
+
void
cb_candidate_gathering_done(NiceAgent *agent, guint stream_id, gpointer user_data)
{
@@ -1166,109 +1265,20 @@ cb_candidate_gathering_done(NiceAgent *a
GoogleAVSessionData *session_data = (GoogleAVSessionData *)session->session_data;
GoogleXferSessionData *share_session = (GoogleXferSessionData *)session_data->share_session;
purple_debug_info("google_session", "lcands is NOT null..\n");
+
for(; iter; iter = iter->next) {
NiceCandidate *candid = (NiceCandidate *)iter->data;
+ candid->username = g_strdup(local_ufrag);
+ candid->password = g_strdup(local_password);
+
/*Insert it into our GoogleXferSession's local_share_candidates*/
share_session->local_share_candidates = g_list_prepend(share_session->local_share_candidates, candid);
-
- if(1) {
- JabberIq *iq;
- gchar *username, *password, *port;
- gchar *ip = g_malloc(NICE_ADDRESS_STRING_LEN + 1);
- gchar *pref;
- NiceCandidateType type;
- xmlnode *sess;
- xmlnode *candidate, *transport;
- guint component_id;
- /*TODO : REMOVE ME : transport needs to be replaced by candid*/
- /*Is component ID necessary? This is a share session TODO*/
-/* component_id = purple_media_candidate_get_component_id(
- transport);
-*/ /*Format we want to use : TODO REMOVE :
-<iq to="doondoon1234 at gmail.com/F0529E73" type="set" id="249" from="ashmew2 at gmail.com/Talk.v1040217A105"><session type="transport-info" id="1195983148" initiator="ashmew2 at gmail.com/Talk.v1040217A105" xmlns="http://www.google.com/session"><transport xmlns="http://www.google.com/transport/p2p"><candidate name="private-1" address="10.0.2.15" port="58919" preference="1" username="j8xIQAN/LvaC/dxb" protocol="udp" generation="0" password="eEy12J+BFBmZO0jj" type="local" network="0"/></transport></session></iq>
- */
-
- if(!nice_agent_get_local_credentials(agent, stream_id,
- &username, &password))
- purple_debug_info("google_session","Getting local credentials FAILED..\n");
- else
- purple_debug_info("google_session","Getting local credentials SUCCESSFUL..\n");
-
- iq = jabber_iq_new(session->js, JABBER_IQ_SET);
- sess = google_session_create_xmlnode(session, "transport-info");
- xmlnode_insert_child(iq->node, sess);
- xmlnode_set_attrib(iq->node, "to", session->remote_jid);
-
- purple_debug_info("google_session", "IQ Created. Now Transport Node : \n");
- transport = xmlnode_new("transport");
- xmlnode_set_namespace(transport, NS_GOOGLE_TRANSPORT_P2P);
- xmlnode_insert_child(sess, transport);
-
- candidate = xmlnode_new("candidate");
-
- /*We already have an IP, use that*/
- /*ip = purple_media_candidate_get_ip(transport); >= REMOVE ME : TODO*/
- purple_debug_info("google_session", "Using nice_address_to_string : \n");
- nice_address_to_string(&candid->addr, ip);
- port = g_strdup_printf("%u",nice_address_get_port(&candid->addr));
-
- purple_debug_info("google_session", "IP and port : %s:%s\n",ip,port);
- pref = g_strdup_printf("%u",candid->priority);
-
-/* username = candid->username;
- password = candid->password;
-*/
- username = g_strdup(local_ufrag);
- password = g_strdup(local_password);
-
- type = candid->type;
- purple_debug_info("google_session", "Setting attributes now.. : \n");
-
- xmlnode_set_attrib(candidate, "address", ip);
- xmlnode_set_attrib(candidate, "port", port);
- xmlnode_set_attrib(candidate, "name", "private-1");
-
- purple_debug_info("google_session", "Setting some more attributes now.. : \n");
- xmlnode_set_attrib(candidate, "username", username != NULL ? username : "");
- xmlnode_set_attrib(candidate, "password",
- password != NULL ? password : "");
-
- purple_debug_info("google_session", "Setting even more attributes now.. : \n");
-/*TODO: Fix preference*/
- xmlnode_set_attrib(candidate, "preference", "0.9");
- xmlnode_set_attrib(candidate, "protocol", "udp");
-/*TODO: ADD RELAY SERVERS ASAP!*/
- /*CHECK THIS : TODO Type*/
- purple_debug_info("google_session", "Setting type attrib : \n");
- xmlnode_set_attrib(candidate, "type",
- type == NICE_CANDIDATE_TYPE_HOST ? "local":
- type == NICE_CANDIDATE_TYPE_SERVER_REFLEXIVE ? "stun":
- type == NICE_CANDIDATE_TYPE_PEER_REFLEXIVE ? "prflx":
- type == NICE_CANDIDATE_TYPE_RELAYED ? "relay"
- : "local");
-
- xmlnode_set_attrib(candidate, "generation", "0");
- xmlnode_set_attrib(candidate, "network", "0");
- xmlnode_insert_child(transport, candidate);
-
- purple_debug_info("google_session", "We Send : Candidate's IP and PORT : %s:%s",ip,port);
- g_free(ip);
- g_free(port);
- g_free(username);
- g_free(password);
- jabber_iq_send(iq);
- }
- /*TODO: Put me at my proper location*/
- /*Sending each candidate here itself*/
+ /*TODO: local_share_candidates are being added to the list here itself. What about the part that follows?
+ Shouldn't relay candidates and these candidates be togeter?*/
}
-
-
- }
- else
- purple_debug_info("google_session", "lcands is NULL\n");
/*Send relay candidates. TODO: Relocate and Fix Initiator*/
- buf1=g_strdup_printf("<iq to=\"%s\" type=\"set\" id=\"%s\" from=\"%s\"><session type=\"transport-info\" id=\"%s\" initiator=\"%s\" xmlns=\"http://www.google.com/session\"><transport xmlns=\"http://www.google.com/transport/p2p\"><candidate name=\"private-1\" address=\"74.125.135.127\" port=\"19305\" preference=\"0\" username=\"foob0aasdasda\" protocol=\"udp\" generation=\"0\" password=\"lalalsdlsad2\" type=\"relay\" network=\"0\"/></transport></session></iq>", session->remote_jid, jabber_get_next_id(js), me, session->id.id, session->remote_jid);
+/* buf1=g_strdup_printf("<iq to=\"%s\" type=\"set\" id=\"%s\" from=\"%s\"><session type=\"transport-info\" id=\"%s\" initiator=\"%s\" xmlns=\"http://www.google.com/session\"><transport xmlns=\"http://www.google.com/transport/p2p\"><candidate name=\"private-1\" address=\"74.125.135.127\" port=\"19305\" preference=\"0\" username=\"foob0aasdasda\" protocol=\"udp\" generation=\"0\" password=\"lalalsdlsad2\" type=\"relay\" network=\"0\"/></transport></session></iq>", session->remote_jid, jabber_get_next_id(js), me, session->id.id, session->remote_jid);
buf2=g_strdup_printf("<iq to=\"%s\" type=\"set\" id=\"%s\" from=\"%s\"><session type=\"transport-info\" id=\"%s\" initiator=\"%s\" xmlns=\"http://www.google.com/session\"><transport xmlns=\"http://www.google.com/transport/p2p\"><candidate name=\"private-1\" address=\"74.125.135.127\" port=\"19305\" preference=\"0\" username=\"foob0aasdasda\" protocol=\"udp\" generation=\"0\" password=\"lalalsdlsad2\" type=\"relay\" network=\"0\"/></transport></session></iq>", session->remote_jid, jabber_get_next_id(js), me, session->id.id, session->remote_jid);
buf3=g_strdup_printf("<iq to=\"%s\" type=\"set\" id=\"%s\" from=\"%s\"><session type=\"transport-info\" id=\"%s\" initiator=\"%s\" xmlns=\"http://www.google.com/session\"><transport xmlns=\"http://www.google.com/transport/p2p\"><candidate name=\"private-1\" address=\"74.125.135.127\" port=\"443\" preference=\"0\" username=\"foob0aasdasda\" protocol=\"udp\" generation=\"0\" password=\"lalalsdlsad2\" type=\"relay\" network=\"0\"/></transport></session></iq>", session->remote_jid, jabber_get_next_id(js), me, session->id.id, session->remote_jid);
@@ -1276,6 +1286,13 @@ cb_candidate_gathering_done(NiceAgent *a
jabber_send_raw(js,buf2,strlen(buf2));
jabber_send_raw(js,buf3,strlen(buf3));
purple_debug_info("google_session", "Sent ALL CANDIDATES \n");
+*/
+ }
+
+/*TODO: Once the candidates have beeng gthered, we must send out our GList of NiceCandidates.
+Call gtalk_xfer_send_candidates() Here .
+*/
+ gtalk_xfer_send_candidates(session);
}
void
@@ -1286,7 +1303,7 @@ cb_nice_recv(NiceAgent *agent, guint str
}
void
-gtalk_xfer_send_candidates(GoogleSession *session)
+gtalk_xfer_prepare_candidates(GoogleSession *session)
{
/*Successful sample of sending candidates :
Received this list :
@@ -1317,8 +1334,7 @@ OUR Response :
This will most probably end in successful candidate exchange.
*/
- gchar buffer[] = "hello world!";
- GSList *lcands = NULL, *rcands = NULL;
+ GSList *lcands = NULL;
TempStruct *temp_struct = g_new0(TempStruct, 1);
GMainLoop *gloop;
GoogleAVSessionData *session_data = (GoogleAVSessionData *)session->session_data;
More information about the Commits
mailing list