jingle-ft/filetransfer.c
changeset 152 a8623ca21574
parent 151 b1acef78e4f5
child 156 653fa009fea3
equal deleted inserted replaced
151:b1acef78e4f5 152:a8623ca21574
    30 #include <mcabber/settings.h>
    30 #include <mcabber/settings.h>
    31 #include <mcabber/logprint.h>
    31 #include <mcabber/logprint.h>
    32 #include <mcabber/compl.h>
    32 #include <mcabber/compl.h>
    33 #include <mcabber/commands.h>
    33 #include <mcabber/commands.h>
    34 #include <mcabber/roster.h>
    34 #include <mcabber/roster.h>
    35 #include <mcabber/utils.h>
       
    36 
    35 
    37 #include <jingle/jingle.h>
    36 #include <jingle/jingle.h>
    38 #include <jingle/check.h>
    37 #include <jingle/check.h>
    39 #include <jingle/register.h>
    38 #include <jingle/register.h>
    40 #include <jingle/sessions.h>
    39 #include <jingle/sessions.h>
   436 
   435 
   437   if ((jft = _new(args[1])) == NULL)
   436   if ((jft = _new(args[1])) == NULL)
   438     return;
   437     return;
   439   
   438   
   440   {
   439   {
   441     JingleSession *sess;
       
   442     gchar *sid = jingle_generate_sid();
       
   443     gchar *ressource, *recipientjid;
   440     gchar *ressource, *recipientjid;
   444     const gchar *namespaces[] = {NS_JINGLE, NS_JINGLE_APP_FT, NULL};
   441     const gchar *namespaces[] = {NS_JINGLE, NS_JINGLE_APP_FT, NULL};
   445     const gchar *myjid = g_strdup(lm_connection_get_jid(lconnection));
       
   446 
   442 
   447     if (CURRENT_JID == NULL) { // CURRENT_JID = the jid of the user which has focus
   443     if (CURRENT_JID == NULL) { // CURRENT_JID = the jid of the user which has focus
   448       scr_LogPrint(LPRINT_LOGNORM, "Jingle File Transfer: Please, choose a valid JID in the roster");
   444       scr_LogPrint(LPRINT_LOGNORM, "Jingle File Transfer: Please, choose a valid JID in the roster");
   449       return;
   445       return;
   450     }
   446     }
   451     ressource = jingle_find_compatible_res(CURRENT_JID, namespaces);
   447     ressource = jingle_find_compatible_res(CURRENT_JID, namespaces);
   452     if (ressource == NULL) {
   448     if (ressource == NULL) {
   453       scr_LogPrint(LPRINT_LOGNORM, "Jingle File Transfer: Cannot send file, because there is no ressource available");
   449       scr_LogPrint(LPRINT_LOGNORM, "Jingle File Transfer: Cannot send file,"
       
   450                                    " because there is no ressource available");
   454       return;
   451       return;
   455     }
   452     }
   456 
   453 
   457     recipientjid = g_strdup_printf("%s/%s", CURRENT_JID, ressource);
   454     recipientjid = g_strdup_printf("%s/%s", CURRENT_JID, ressource);
   458 
   455 
   459     sess = session_new(sid, myjid, recipientjid, JINGLE_SESSION_OUTGOING);
   456     new_session_with_apps(recipientjid, (const gchar*[]){"file", NULL},
   460     session_add_content(sess, "file", JINGLE_SESSION_STATE_PENDING);
   457                           (gconstpointer[]){jft, NULL},
   461 
   458                           (const gchar*[]){NS_JINGLE_APP_FT, NULL});
   462     session_add_app(sess, "file", NS_JINGLE_APP_FT, jft);
   459 
   463 
   460     jingle_handle_app("file", NS_JINGLE_APP_FT, jft, recipientjid);
   464     {
   461     
   465       JingleFTInfo *jfti = g_new0(JingleFTInfo, 1);
   462     g_free(recipientjid);
   466       jfti->index = _next_index();
       
   467       jfti->jft = jft;
       
   468       info_list = g_slist_append(info_list, jfti);
       
   469     }
       
   470 
       
   471     jingle_handle_app(sess, "file", NS_JINGLE_APP_FT, jft, recipientjid);
       
   472 
       
   473     g_free(ressource);
   463     g_free(ressource);
   474     g_free(sid);
       
   475   }
   464   }
   476 }
   465 }
   477 
   466 
   478 static void do_sendfile(char *arg)
   467 static void do_sendfile(char *arg)
   479 {
   468 {