jingle/jingle.c
changeset 47 964b3ebeba8d
parent 46 f33c814d5b3a
child 48 3c08b78be871
equal deleted inserted replaced
46:f33c814d5b3a 47:964b3ebeba8d
    27 #include <mcabber/xmpp.h>
    27 #include <mcabber/xmpp.h>
    28 #include <mcabber/hooks.h>
    28 #include <mcabber/hooks.h>
    29 #include <mcabber/modules.h>
    29 #include <mcabber/modules.h>
    30 #include <mcabber/logprint.h>
    30 #include <mcabber/logprint.h>
    31 #include <mcabber/xmpp_helper.h>
    31 #include <mcabber/xmpp_helper.h>
    32 #include <mcabber/xmpp_defines.h> 
       
    33 #include <mcabber/events.h>
       
    34 
    32 
    35 #include <jingle/jingle.h>
    33 #include <jingle/jingle.h>
    36 #include <jingle/check.h>
    34 #include <jingle/check.h>
    37 #include <jingle/action-handlers.h>
    35 #include <jingle/action-handlers.h>
    38 #include <jingle/register.h>
    36 #include <jingle/register.h>
    39 #include <jingle/send.h>
    37 #include <jingle/send.h>
       
    38 #include <jingle/general-handlers.h>
    40 
    39 
    41 static void  jingle_register_lm_handlers(void);
    40 static void  jingle_register_lm_handlers(void);
    42 static void  jingle_unregister_lm_handlers(void);
    41 static void  jingle_unregister_lm_handlers(void);
    43 static guint jingle_connect_hh(const gchar *hname, hk_arg_t *args,
    42 static guint jingle_connect_hh(const gchar *hname, hk_arg_t *args,
    44                                gpointer ignore);
    43                                gpointer ignore);
    48 static void  jingle_uninit(void);
    47 static void  jingle_uninit(void);
    49 static void lm_insert_jinglecontent(gpointer data, gpointer userdata);
    48 static void lm_insert_jinglecontent(gpointer data, gpointer userdata);
    50 
    49 
    51 
    50 
    52 static LmMessageHandler* jingle_iq_handler = NULL;
    51 static LmMessageHandler* jingle_iq_handler = NULL;
       
    52 LmMessageHandler* jingle_ack_iq_handler = NULL;
    53 static guint connect_hid = 0;
    53 static guint connect_hid = 0;
    54 static guint disconn_hid = 0;
    54 static guint disconn_hid = 0;
    55 
    55 
    56 /**
    56 /**
    57  * Must be aligned with the values in JingleAction
    57  * Must be aligned with the values in JingleAction
   244 }
   244 }
   245 
   245 
   246 static void jingle_init(void)
   246 static void jingle_init(void)
   247 {
   247 {
   248   jingle_iq_handler = lm_message_handler_new(jingle_handle_iq, NULL, NULL);
   248   jingle_iq_handler = lm_message_handler_new(jingle_handle_iq, NULL, NULL);
       
   249   jingle_ack_iq_handler = lm_message_handler_new(jingle_handle_ack_iq, NULL,
       
   250                                                  NULL);
   249   xmpp_add_feature(NS_JINGLE);
   251   xmpp_add_feature(NS_JINGLE);
   250 
   252 
   251   connect_hid = hk_add_handler(jingle_connect_hh, HOOK_POST_CONNECT,
   253   connect_hid = hk_add_handler(jingle_connect_hh, HOOK_POST_CONNECT,
   252       G_PRIORITY_DEFAULT_IDLE, NULL);
   254       G_PRIORITY_DEFAULT_IDLE, NULL);
   253   disconn_hid = hk_add_handler(jingle_disconn_hh, HOOK_PRE_DISCONNECT,
   255   disconn_hid = hk_add_handler(jingle_disconn_hh, HOOK_PRE_DISCONNECT,
   263   hk_del_handler(HOOK_PRE_DISCONNECT, disconn_hid);
   265   hk_del_handler(HOOK_PRE_DISCONNECT, disconn_hid);
   264   jingle_unregister_lm_handlers();
   266   jingle_unregister_lm_handlers();
   265 
   267 
   266   lm_message_handler_invalidate(jingle_iq_handler);
   268   lm_message_handler_invalidate(jingle_iq_handler);
   267   lm_message_handler_unref(jingle_iq_handler);
   269   lm_message_handler_unref(jingle_iq_handler);
       
   270   lm_message_handler_invalidate(jingle_ack_iq_handler);
       
   271   lm_message_handler_unref(jingle_ack_iq_handler);
   268 }
   272 }
   269 
   273 
   270 LmMessage *lm_message_from_jinglenode(const JingleNode *jn, const gchar *to)
   274 LmMessage *lm_message_from_jinglenode(const JingleNode *jn, const gchar *to)
   271 {
   275 {
   272   LmMessage* m; 
   276   LmMessage* m; 
   321     lm_message_node_set_attribute(node, "senders", "initiator");
   325     lm_message_node_set_attribute(node, "senders", "initiator");
   322   else if (content->senders == JINGLE_SENDERS_RESPONDER)
   326   else if (content->senders == JINGLE_SENDERS_RESPONDER)
   323     lm_message_node_set_attribute(node, "senders", "responder");
   327     lm_message_node_set_attribute(node, "senders", "responder");
   324 }
   328 }
   325 
   329 
   326 gboolean evscallback_jingle(guint evcontext, const gchar *arg,
       
   327                             gpointer userdata)
       
   328 {
       
   329   JingleNode *jn = userdata;
       
   330 
       
   331   // Demande à mcKael l'utilité de ce truc
       
   332   /*
       
   333   if (G_UNLIKELY(!jn)) {
       
   334     scr_LogPrint(LPRINT_LOGNORM, "Error in evs callback.");
       
   335     return FALSE;
       
   336   }
       
   337   */
       
   338 
       
   339   if (evcontext == EVS_CONTEXT_TIMEOUT) {
       
   340     scr_LogPrint(LPRINT_LOGNORM, "Jingle event from %s timed out, cancelled.",
       
   341                  jn->initiator);
       
   342     jingle_free_jinglenode(jn);
       
   343     return FALSE;
       
   344   }
       
   345   if (evcontext = EVS_CONTEXT_CANCEL) {
       
   346     scr_LogPrint(LPRINT_LOGNORM, "Jingle event from %s cancelled.",
       
   347                  jn->initiator);
       
   348     jingle_free_jinglenode(jn);
       
   349     return FALSE;
       
   350   }
       
   351   if (!(evcontext == EVS_CONTEXT_ACCEPT || evcontext == EVS_CONTEXT_REJECT)) {
       
   352     jingle_free_jinglenode(jn);
       
   353     return FALSE;
       
   354   }
       
   355   
       
   356   if (evcontext == EVS_CONTEXT_ACCEPT) {
       
   357     jingle_send_session_accept(jn);
       
   358   } else {
       
   359     jingle_send_session_terminate(jn, "decline");
       
   360     jingle_free_jinglenode(jn);
       
   361   }
       
   362 
       
   363   return FALSE;
       
   364 }