jingle/jingle.c
changeset 15 61ffa66f8288
parent 14 77966ed56e14
child 16 cb085682970f
equal deleted inserted replaced
14:77966ed56e14 15:61ffa66f8288
    16  * You should have received a copy of the GNU General Public License
    16  * You should have received a copy of the GNU General Public License
    17  * along with this program; if not, write to the Free Software
    17  * along with this program; if not, write to the Free Software
    18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
    18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
    19  * USA
    19  * USA
    20  */
    20  */
       
    21 
       
    22 #include "config.h"
    21 
    23 
    22 #include <glib.h>
    24 #include <glib.h>
    23 #include <loudmouth/loudmouth.h>
    25 #include <loudmouth/loudmouth.h>
    24 
    26 
    25 #include <mcabber/xmpp.h>
    27 #include <mcabber/xmpp.h>
    29 #include <mcabber/xmpp_helper.h>
    31 #include <mcabber/xmpp_helper.h>
    30 #include <mcabber/xmpp_defines.h> 
    32 #include <mcabber/xmpp_defines.h> 
    31 
    33 
    32 #include "jingle.h"
    34 #include "jingle.h"
    33 #include "check.h"
    35 #include "check.h"
       
    36 #include "action-handlers.h"
    34 #include "register.h"
    37 #include "register.h"
    35 
    38 
    36 
    39 
    37 static void  jingle_register_lm_handlers(void);
    40 static void  jingle_register_lm_handlers(void);
    38 static void  jingle_unregister_lm_handlers(void);
    41 static void  jingle_unregister_lm_handlers(void);
    59   { "content-remove",    NULL },
    62   { "content-remove",    NULL },
    60   { "description-info",  NULL },
    63   { "description-info",  NULL },
    61   { "security-info",     NULL },
    64   { "security-info",     NULL },
    62   { "session-accept",    NULL },
    65   { "session-accept",    NULL },
    63   { "session-info",      NULL },
    66   { "session-info",      NULL },
    64   { "session-initiate",  NULL },
    67   { "session-initiate",  handle_session_initiate },
    65   { "session-terminate", NULL },
    68   { "session-terminate", NULL },
    66   { "transport-accept",  NULL },
    69   { "transport-accept",  NULL },
    67   { "transport-info",    NULL },
    70   { "transport-info",    NULL },
    68   { "transport-reject",  NULL },
    71   { "transport-reject",  NULL },
    69   { "transport-replace", NULL },
    72   { "transport-replace", NULL },
    70 };
    73 };
    71 
    74 
    72 module_info_t info_jingle = {
    75 module_info_t info_jingle = {
    73   .branch          = MCABBER_BRANCH,
    76   .branch          = MCABBER_BRANCH,
    74   .api             = MCABBER_API_VERSION,
    77   .api             = MCABBER_API_VERSION,
    75   .version         = MCABBER_VERSION,
    78   .version         = PROJECT_VERSION,
    76   .description     = "Main Jingle module,"
    79   .description     = "Main Jingle module,"
    77                      " required for file transport, voip...\n",
    80                      " required for file transport, voip...\n",
    78   .requires        = NULL,
    81   .requires        = NULL,
    79   .init            = jingle_init,
    82   .init            = jingle_init,
    80   .uninit          = jingle_uninit,
    83   .uninit          = jingle_uninit,
    90   LmMessageSubType iqtype = lm_message_get_sub_type(message);
    93   LmMessageSubType iqtype = lm_message_get_sub_type(message);
    91   if (iqtype != LM_MESSAGE_SUB_TYPE_SET)
    94   if (iqtype != LM_MESSAGE_SUB_TYPE_SET)
    92     return LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS;
    95     return LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS;
    93 
    96 
    94   JingleNode *jn = g_new0(JingleNode, 1);
    97   JingleNode *jn = g_new0(JingleNode, 1);
    95   GError *error;
    98   GError *error = NULL;
    96   LmMessageNode *root = lm_message_get_node(message)->children;
    99   LmMessageNode *root = lm_message_get_node(message)->children;
    97   LmMessageNode *node = lm_message_node_get_child(root, "jingle");
   100   LmMessageNode *node = lm_message_node_get_child(root, "jingle");
    98 
   101 
    99   if (!node) // no <jingle> element found
   102   if (!node) // no <jingle> element found
   100     return LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS;
   103     return LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS;
   104     return LM_HANDLER_RESULT_REMOVE_MESSAGE;
   107     return LM_HANDLER_RESULT_REMOVE_MESSAGE;
   105   }
   108   }
   106 
   109 
   107   check_jingle(node, jn, &error);
   110   check_jingle(node, jn, &error);
   108   if (error != NULL) {
   111   if (error != NULL) {
   109     if (error->code == JINGLE_CHECK_ERROR) {
   112     if (error->domain == JINGLE_CHECK_ERROR) {
   110       // request malformed, we reply with a bad-request
   113       // request malformed, we reply with a bad-request
   111       jingle_send_iq_error(message, "cancel", "bad-request", NULL);
   114       jingle_send_iq_error(message, "cancel", "bad-request", NULL);
   112     }
   115     }
       
   116     g_clear_error(&error);
   113     return LM_HANDLER_RESULT_REMOVE_MESSAGE;
   117     return LM_HANDLER_RESULT_REMOVE_MESSAGE;
   114   }
   118   }
   115   
   119 
   116   scr_log_print(LPRINT_DEBUG, "jingle: Received a valid jingle IQ");
   120   scr_log_print(LPRINT_DEBUG, "jingle: Received a valid jingle IQ");
   117   
   121 
   118   if (jingle_action_list[jn->action].handler != NULL)
   122   if (jingle_action_list[jn->action].handler == NULL) {
   119     jingle_action_list[jn->action].handler(message, jn, &error);
       
   120   else
       
   121     jingle_send_iq_error(message, "cancel", "feature-not-implemented",
   123     jingle_send_iq_error(message, "cancel", "feature-not-implemented",
   122                          "unsupported-info");
   124                          "unsupported-info");
       
   125     return LM_HANDLER_RESULT_REMOVE_MESSAGE;
       
   126   }
       
   127 
       
   128   jingle_action_list[jn->action].handler(message, jn);
   123 
   129 
   124   return LM_HANDLER_RESULT_REMOVE_MESSAGE;
   130   return LM_HANDLER_RESULT_REMOVE_MESSAGE;
   125 }
   131 }
   126 
   132 
   127 /**
   133 /**