JFT: add a func to send data
authorNicolas Cornu <nicolas.cornu@ensi-bourges.fr>
Wed, 11 Aug 2010 18:23:56 +0200
changeset 101 4235aa1a7664
parent 100 c033d2fc0f7d
child 102 ec430b98c115
JFT: add a func to send data
jingle-filetransfer/filetransfer.c
jingle/register.h
jingle/send.c
--- a/jingle-filetransfer/filetransfer.c	Wed Aug 11 00:47:36 2010 +0200
+++ b/jingle-filetransfer/filetransfer.c	Wed Aug 11 18:23:56 2010 +0200
@@ -46,6 +46,7 @@
 gconstpointer jingle_ft_check(JingleContent *cn, GError **err);
 void jingle_ft_tomessage(gconstpointer data, LmMessageNode *node);
 gboolean jingle_ft_handle_data(gconstpointer data, const gchar *data2, guint len);
+void jingle_ft_start(gconstpointer data);
 static gboolean is_md5_hash(const gchar *hash);
 static void jingle_ft_init(void);
 static void jingle_ft_uninit(void);
@@ -307,6 +308,47 @@
   //if (jft->data != 0)
 }
 
+void jingle_ft_send(gconstpointer data, gsize size)
+{
+  JingleFT *jft = (JingleFT*)data;
+  gchar *buf = g_new0(gchar, size);
+  gsize read;
+  GIOStatus status;
+  int count = 0;
+  
+  do {
+    count++;
+    status = g_io_channel_read_chars(jft->outfile, buf, size, &read, NULL);
+  while (status == GIO_STATUS_AGAIN && count < 10);
+  
+  if (status == GIO_STATUS_AGAIN) {
+    // TODO: something better
+    scr_LogPrint(LPRINT_LOGNORM, "Jingle File Transfer: file unavailable");
+    return;
+  }
+  
+  if (status == GIO_STATUS_ERROR) {
+    scr_LogPrint(LPRINT_LOGNORM, "Jingle File Transfer: an error occured");
+    return;
+  }
+  
+  // Call a handle in jingle who will call the trans
+  //jingle_handle_data
+  
+  if (status == GIO_STATUS_EOF) {
+    scr_LogPrint(LPRINT_LOGNORM, "Jingle File Transfer: transfer finish (%s)", jft->name);
+    // Call a function to say state is ended
+    
+  }
+}
+
+void jingle_ft_start(gconstpointer data, gsize size)
+{
+  JingleFT *jft = (JingleFT*)data;
+
+
+}
+
 static void jingle_ft_init(void)
 {
   jingle_register_app(NS_JINGLE_APP_FT, &funcs, JINGLE_TRANSPORT_STREAMING);
--- a/jingle/register.h	Wed Aug 11 00:47:36 2010 +0200
+++ b/jingle/register.h	Wed Aug 11 18:23:56 2010 +0200
@@ -38,6 +38,7 @@
 typedef gconstpointer (*JingleAppCheck) (JingleContent *cn, GError **err);
 typedef void (*JingleAppToMessage) (gconstpointer data, LmMessageNode *node);
 typedef gboolean (*JingleAppHandleData) (gconstpointer data, const gchar *data2, guint len);
+typedef void (*JingleAppStart) (gconstpointer data, gsize size);
 
 typedef gconstpointer (*JingleTransportCheck) (JingleContent *cn, GError **err);
 typedef void (*JingleTransportToMessage) (gconstpointer data, LmMessageNode *node);
@@ -53,6 +54,8 @@
   JingleAppToMessage tomessage;
   
   JingleAppHandleData handle_data;
+  
+  JingleAppStart start;
 
 } JingleAppFuncs;
 
--- a/jingle/send.c	Wed Aug 11 00:47:36 2010 +0200
+++ b/jingle/send.c	Wed Aug 11 18:23:56 2010 +0200
@@ -65,10 +65,20 @@
 {
   LmMessageNode *node;
   const gchar *type, *cause;
+  GSList *child = NULL;
   JingleSession *sess = (JingleSession*)data;
+  SessionContent *sc;
   
-  if(lm_message_get_sub_type(mess) == LM_MESSAGE_SUB_TYPE_RESULT)
+  if(lm_message_get_sub_type(mess) == LM_MESSAGE_SUB_TYPE_RESULT) {
+    // Go go go! We start jobs!
+    for (child = sess->content; child; child = child->next) {
+      sc = (SessionContent*)child->data;
+      // TODO size!
+      sc->appfuncs->start(sc, 2048); 
+    }
     return;
+  }
+  
   if(lm_message_get_sub_type(mess) == LM_MESSAGE_SUB_TYPE_ERROR) {
     node = lm_message_get_node(mess);
     node = lm_message_node_get_child(node,"error");