Handle incoming transport-info messages
authorNicolas Cornu <nicolas.cornu@ensi-bourges.fr>
Wed, 01 Sep 2010 01:19:40 +0200
changeset 165 763c26abd99d
parent 164 6866328b34bd
child 166 c42c167a2a5c
Handle incoming transport-info messages
jingle-s5b/socks5.c
jingle/action-handlers.c
jingle/action-handlers.h
jingle/jingle.c
--- a/jingle-s5b/socks5.c	Mon Aug 30 18:03:48 2010 +0200
+++ b/jingle-s5b/socks5.c	Wed Sep 01 01:19:40 2010 +0200
@@ -264,20 +264,27 @@
   return js5b;
 }
 
-static JingleHandleStatus
-handle_session_accept(JingleS5B *js5b, LmMessageNode *node, GError **err)
-{
-  js5b->candidates = parse_candidates(node);
-  return JINGLE_STATUS_HANDLED;
-}
-
 static JingleHandleStatus handle(JingleAction action, gconstpointer data,
                                  LmMessageNode *node, GError **err)
 {
   JingleS5B *js5b = (JingleS5B *)data;
 
   if (action == JINGLE_SESSION_ACCEPT) {
-    return handle_session_accept(js5b, node, err);
+    js5b->candidates = parse_candidates(node);
+    return JINGLE_STATUS_HANDLED;
+  } else if (action == JINGLE_TRANSPORT_INFO) {
+    LmMessageNode *errorn, *usedn;
+    if (g_strcmp0(lm_message_node_get_attribute(node, "sid"), js5b->sid))
+      return JINGLE_STATUS_HANDLED; // huh.. not the same socks5 sid ?
+
+    errorn = lm_message_node_get_child(node, "candidate-error");
+    usedn = lm_message_node_get_child(node, "candidate-used");
+    if (errorn != FALSE) {
+      //got_candidate_error
+    } else if (usedn != FALSE) {
+      //got_candidate_used
+    }
+    return JINGLE_STATUS_HANDLED;
   }
   return JINGLE_STATUS_NOT_HANDLED;
 }
@@ -394,6 +401,19 @@
 }
 
 /**
+ * @brief Called when a connection was established
+ * 
+ * This function free/unref everything created by init like
+ * the GSocketListener and GClientSocket objects.
+ */
+static void free_after_connection(JingleS5B *js5b)
+{
+  g_socket_listener_close(js5b->listener);
+  g_object_unref(js5b->listener);
+  g_object_unref(js5b->client);
+}
+
+/**
  * @brief Cancel an ongoing connection after 5 seconds
  * @param data  A GPtrArray
  * 
@@ -409,6 +429,7 @@
   g_ptr_array_unref(args);
 
   g_cancellable_cancel(js5b->cancelconnect);
+  // we need to send a candidate-error in case we cannot connect.
   return FALSE;
 }
 
@@ -500,7 +521,6 @@
     g_source_destroy(s);
     g_ptr_array_unref(args);
     connect_next_candidate(js5b, cand);
-    // we need to send a candidate-error in case we cannot connect.
     return;
   }
 
@@ -517,8 +537,8 @@
     connect_next_candidate(js5b, cand);
     return;
   }
-  js5b->connection = conn;
-  // we have a valid connection
+  js5b->connection = conn; // we have a valid connection
+  // TODO: send transport-info activated IQ
 }
 
 /**
--- a/jingle/action-handlers.c	Mon Aug 30 18:03:48 2010 +0200
+++ b/jingle/action-handlers.c	Wed Sep 01 01:19:40 2010 +0200
@@ -215,7 +215,7 @@
   JingleContent *jc;
   SessionContent *sc;
   session_content *sc2 = g_new0(session_content, 1);
-  GError *err;
+  GError *err = NULL;
   GSList *el;
   const gchar *from = lm_message_get_from(jn->message);
   
@@ -287,3 +287,29 @@
   session_delete(sess);
   jingle_ack_iq(jn->message);
 }
+
+void handle_transport_info(JingleNode *jn)
+{
+  JingleSession *sess;
+  SessionContent *sc;
+  JingleContent *jc;
+
+  if ((sess = session_find(jn)) == NULL) {
+    jingle_send_iq_error(jn->message, "cancel", "item-not-found", "unknown-session");
+    return;
+  }
+
+  if (jn->content == NULL) {
+    jingle_send_iq_error(jn->message, "modify", "bad-request", NULL);
+    return;
+  }
+  jc = (JingleContent*) jn->content->data;
+
+  sc = session_find_sessioncontent(sess, jc->name);
+  if (sc == NULL) {
+    jingle_send_iq_error(jn->message, "modify", "bad-request", NULL);
+    return;
+  }
+
+  sc->appfuncs->handle(JINGLE_TRANSPORT_INFO, sc->transport, jc->transport, NULL);
+}
--- a/jingle/action-handlers.h	Mon Aug 30 18:03:48 2010 +0200
+++ b/jingle/action-handlers.h	Wed Sep 01 01:19:40 2010 +0200
@@ -13,5 +13,6 @@
 void handle_session_info(JingleNode *jn);
 void handle_session_initiate(JingleNode *jn);
 void handle_session_terminate(JingleNode *jn);
+void handle_transport_info(JingleNode *jn);
 
 #endif
--- a/jingle/jingle.c	Mon Aug 30 18:03:48 2010 +0200
+++ b/jingle/jingle.c	Wed Sep 01 01:19:40 2010 +0200
@@ -73,7 +73,7 @@
   { "session-initiate",  handle_session_initiate },
   { "session-terminate", handle_session_terminate },
   { "transport-accept",  NULL },
-  { "transport-info",    NULL },
+  { "transport-info",    handle_transport_info },
   { "transport-reject",  NULL },
   { "transport-replace", NULL },
 };