jingle-ft/filetransfer.c
changeset 160 e149e868d501
parent 159 1df5f5e3f1e7
child 166 c42c167a2a5c
equal deleted inserted replaced
159:1df5f5e3f1e7 160:e149e868d501
    59 static gchar *_convert_size(guint64 size);
    59 static gchar *_convert_size(guint64 size);
    60 static int _next_index(void);
    60 static int _next_index(void);
    61 static void _free(JingleFT *jft);
    61 static void _free(JingleFT *jft);
    62 static gboolean _check_hash(const gchar *hash1, GChecksum *md5);
    62 static gboolean _check_hash(const gchar *hash1, GChecksum *md5);
    63 static gboolean _is_md5_hash(const gchar *hash);
    63 static gboolean _is_md5_hash(const gchar *hash);
    64 static void _jft_send(char **args);
    64 static void _jft_send(char **args, JingleFT *jft);
    65 static void _jft_info(char **args);
    65 static void _jft_info(char **args);
    66 static void _jft_flush(char **args);
    66 static void _jft_flush(char **args);
    67 static JingleFT* _new(const gchar *name);
    67 static JingleFT* _new(const gchar *name);
    68 
    68 
    69 const gchar *deps[] = { "jingle", NULL };
    69 const gchar *deps[] = { "jingle", NULL };
   420   }
   420   }
   421   
   421   
   422   return jft;
   422   return jft;
   423 }
   423 }
   424 
   424 
   425 static void _jft_send(char **args)
   425 static void _jft_send(char **args, JingleFT *jft2)
   426 {
   426 {
   427   JingleFT *jft;
   427   JingleFT *jft = jft2;
   428 
   428 
   429   if (!args[1]) {
   429   if (jft == NULL && !args[1]) {
   430     scr_LogPrint(LPRINT_LOGNORM, "Jingle File Transfer: give me a name!");
   430     scr_LogPrint(LPRINT_LOGNORM, "Jingle File Transfer: give me a name!");
   431     return;
   431     return;
   432   }
   432   }
   433 
   433 
   434   scr_LogPrint(LPRINT_LOGNORM, "Jingle File Transfer: Trying to send %s",
   434   scr_LogPrint(LPRINT_LOGNORM, "Jingle File Transfer: Trying to send %s",
   435                args[1]);
   435                args[1]);
   436 
   436 
   437   if ((jft = _new(args[1])) == NULL)
   437   if (jft == NULL && (jft = _new(args[1])) == NULL)
   438     return;
   438     return;
   439   
   439   
   440   {
   440   {
   441     gchar *ressource, *recipientjid;
   441     gchar *ressource, *recipientjid;
   442     const gchar *namespaces[] = {NS_JINGLE, NS_JINGLE_APP_FT, NULL};
   442     const gchar *namespaces[] = {NS_JINGLE, NS_JINGLE_APP_FT, NULL};
   463     g_free(recipientjid);
   463     g_free(recipientjid);
   464     g_free(ressource);
   464     g_free(ressource);
   465   }
   465   }
   466 }
   466 }
   467 
   467 
       
   468 static void _jft_retry(char **args)
       
   469 {
       
   470   GSList *el;
       
   471   JingleFT *jft;
       
   472   JingleFTInfo *jftinf;
       
   473   gint index = g_ascii_strtoll(args[1], NULL, 10);
       
   474   for (el = info_list; el; el = el->next) {
       
   475     jftinf = el->data;
       
   476     if (jftinf->index == index);
       
   477       break;
       
   478   }
       
   479   
       
   480   if (!args[1]) {
       
   481     scr_LogPrint(LPRINT_LOGNORM, "Jingle File Transfer: give me a number!");
       
   482     return;  
       
   483   }
       
   484   
       
   485 
       
   486   
       
   487   if (el == NULL) {
       
   488     scr_LogPrint(LPRINT_LOGNORM, "Jingle File Transfer: give me a correct number!");
       
   489     return;  
       
   490   }
       
   491   
       
   492   jft = jftinf->jft;
       
   493   jft->hash = NULL;
       
   494   jft->size = 0;
       
   495   jft->transmit = 0;
       
   496   jft->outfile = NULL;
       
   497   jft->state = JINGLE_FT_PENDING;
       
   498   jft->desc = NULL;
       
   499   jft->md5 = NULL;
       
   500   
       
   501   _jft_send(args, jft);
       
   502 }
       
   503 
   468 static void do_sendfile(char *arg)
   504 static void do_sendfile(char *arg)
   469 {
   505 {
   470   char **args = split_arg(arg, 3, 0);
   506   char **args = split_arg(arg, 3, 0);
   471 
   507 
   472   if (!g_strcmp0(args[0], "send"))
   508   if (!g_strcmp0(args[0], "send"))
   473     _jft_send(args);
   509     _jft_send(args, NULL);
   474   else if (!g_strcmp0(args[0], "info"))
   510   else if (!g_strcmp0(args[0], "info"))
   475     _jft_info(args);
   511     _jft_info(args);
   476   else if (!g_strcmp0(args[0], "flush"))
   512   else if (!g_strcmp0(args[0], "flush"))
   477     _jft_flush(args);
   513     _jft_flush(args);
       
   514   else if (!g_strcmp0(args[0], "retry"))
       
   515     _jft_retry(args);
   478   else
   516   else
   479     scr_LogPrint(LPRINT_LOGNORM, "/jft: %s is not a correct option.", args[0]);
   517     scr_LogPrint(LPRINT_LOGNORM, "/jft: %s is not a correct option.", args[0]);
   480 
   518 
   481   free_arg_lst(args);
   519   free_arg_lst(args);
   482 }
   520 }
   484 static void _free(JingleFT *jft)
   522 static void _free(JingleFT *jft)
   485 {
   523 {
   486   g_free(jft->hash);
   524   g_free(jft->hash);
   487   g_free(jft->name);
   525   g_free(jft->name);
   488   g_free(jft->desc);
   526   g_free(jft->desc);
   489   g_io_channel_unref(jft->outfile);
   527   if (jft->outfile != NULL)
       
   528     g_io_channel_unref(jft->outfile);
   490   if (jft->dir == JINGLE_FT_INCOMING)
   529   if (jft->dir == JINGLE_FT_INCOMING)
   491     g_checksum_free(jft->md5);
   530     g_checksum_free(jft->md5);
   492   g_free(jft);
   531   g_free(jft);
   493 }
   532 }
   494 
   533