--- a/jingle.c Tue May 25 05:52:04 2010 +0200
+++ b/jingle.c Tue May 25 15:10:00 2010 +0200
@@ -29,6 +29,7 @@
#include <mcabber/logprint.h>
#include "jingle.h"
+#include "parse.h"
static void mcjingle_init (void);
@@ -36,121 +37,84 @@
struct info_iq {
- const gchar *from, *to, *type, *id;
+ const gchar *from, *to, *type, *id;
};
-struct info_jingle {
- const gchar *xmlns, *action, *initiator, *sid;
-};
-
-
LmMessageHandler* jingle_iq_handler = NULL;
module_info_t info_jingle = {
- .branch = MCABBER_BRANCH,
- .api = MCABBER_API_VERSION,
- .version = MCABBER_VERSION,
- .description = "Main Jingle module\n"
- " required for file transport, voip...\n",
- .requires = NULL,
- .init = mcjingle_init,
- .uninit = mcjingle_uninit,
- .next = NULL,
+ .branch = MCABBER_BRANCH,
+ .api = MCABBER_API_VERSION,
+ .version = MCABBER_VERSION,
+ .description = "Main Jingle module\n"
+ " required for file transport, voip...\n",
+ .requires = NULL,
+ .init = mcjingle_init,
+ .uninit = mcjingle_uninit,
+ .next = NULL,
};
void parse_iq(LmMessageNode *iq, struct info_iq *ii)
{
- if (!strcmp(iq->name, "iq")) {
- ii->to = ii->from = ii->type = ii->id = NULL;
- return;
- }
-
- ii->from = lm_message_node_get_attribute(iq, "from");
- ii->to = lm_message_node_get_attribute(iq, "to");
- ii->type = lm_message_node_get_attribute(iq, "type");
- ii->id = lm_message_node_get_attribute(iq, "id");
-}
+ if (!strcmp(iq->name, "iq")) {
+ ii->to = ii->from = ii->type = ii->id = NULL;
+ return;
+ }
-void parse_jingle(LmMessageNode *jingle, struct info_jingle *ij)
-{
- if (!strcmp(ij->name, "jingle")) {
- ij->to = ij->from = ij->type = ij->id = NULL;
- return;
- }
-
- ii->from = lm_message_node_get_attribute(iq, "from");
- ii->to = lm_message_node_get_attribute(iq, "to");
- ii->type = lm_message_node_get_attribute(iq, "type");
- ii->id = lm_message_node_get_attribute(iq, "id");
+ ii->from = lm_message_node_get_attribute(iq, "from");
+ ii->to = lm_message_node_get_attribute(iq, "to");
+ ii->type = lm_message_node_get_attribute(iq, "type");
+ ii->id = lm_message_node_get_attribute(iq, "id");
}
LmHandlerResult jingle_iq_event_handler(LmMessageHandler *handler,
- LmConnection *connection,
- LmMessage *message,
- gpointer user_data)
+ LmConnection *connection,
+ LmMessage *message,
+ gpointer user_data)
{
- LmMessageNode *test = lm_message_get_node(message)->children;
- struct info_iq ii;
- parse_iq(lm_message_get_node(message), &ii);
-
- if (strcmp(test->name, "jingle") != 0) {
- return LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS;
- }
-
- if (!strcmp(lm_message_node_get_attribute(test, "xmlns"), NS_JINGLE)) {
- gchar* action = g_strdup(lm_message_node_get_attribute(test, "action"));
- gchar* initiator = g_strdup(lm_message_node_get_attribute(test, "initiator"));
- gchar* responder = g_strdup(lm_message_node_get_attribute(test, "responder"));
- gchar* sid = g_strdup(lm_message_node_get_attribute(test, "sid"));
- if (!strcmp(action, "content-accept")) {
- } else if (!strcmp(action, "content-add")) {
- } else if (!strcmp(action, "content-modify")) {
- } else if (!strcmp(action, "content-reject")) {
- } else if (!strcmp(action, "content-remove")) {
- } else if (!strcmp(action, "description-info")) {
- } else if (!strcmp(action, "security-info")) {
- } else if (!strcmp(action, "session-accept")) {
- } else if (!strcmp(action, "session-info")) {
- } else if (!strcmp(action, "session-initiate")) {
- LmMessageNode *child = NULL;
- gchar* disposition = NULL;
- for(child = test->children; child; child = child->next) {
- if (!strcmp((disposition = lm_message_node_get_attribute(child, "disposition")), "session"))
- break;
- if (!disposition) {
- disposition = g_strdup("session");
- break;
- }
- }
- if (strcmp(disposition, "session")) {
- //ERREUR
- }
- } else if (!strcmp(action, "session-terminate")) {
- } else if (!strcmp(action, "transport-accept")) {
- } else if (!strcmp(action, "transport-info")) {
- } else if (!strcmp(action, "transport-reject")) {
- } else if (!strcmp(action, "transport-replace")) {
- } else {
- // action inconnue => réponse XEP 0166 : 7.2
- }
- } else {
- scr_log_print(LPRINT_NORMAL, "jingle : Namespace inconnu (%s)", lm_message_node_get_attribute(test, "xmlns"));
- }
+ LmMessageNode *test = lm_message_get_node(message)->children;
+ struct info_iq ii;
+ struct info_jingle ij;
+
+ parse_iq(lm_message_get_node(message), &ii);
+
+ if (parse_jingle(test, &ij) == PARSE_ERROR_NAME)
+ return LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS;
+
+ if (strcmp(lm_message_node_get_attribute(test, "xmlns"), NS_JINGLE)) {
+ scr_log_print(LPRINT_NORMAL, "jingle : Namespace inconnu (%s)", lm_message_node_get_attribute(test, "xmlns"));
+ return LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS;
+ }
- return LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS;
+ if (!strcmp(ij.action, "content-accept")) {
+ } else if (!strcmp(ij.action, "content-add")) {
+ } else if (!strcmp(ij.action, "content-modify")) {
+ } else if (!strcmp(ij.action, "content-reject")) {
+ } else if (!strcmp(ij.action, "content-remove")) {
+ } else if (!strcmp(ij.action, "description-info")) {
+ } else if (!strcmp(ij.action, "security-info")) {
+ } else if (!strcmp(ij.action, "session-accept")) {
+ } else if (!strcmp(ij.action, "session-info")) {
+ } else if (!strcmp(ij.action, "session-initiate")) {
+ } else if (!strcmp(ij.action, "session-terminate")) {
+ } else if (!strcmp(ij.action, "transport-accept")) {
+ } else if (!strcmp(ij.action, "transport-info")) {
+ } else if (!strcmp(ij.action, "transport-reject")) {
+ } else if (!strcmp(ij.action, "transport-replace")) {
+ }
}
static void mcjingle_init(void)
{
- jingle_iq_handler = lm_message_handler_new(jingle_iq_event_handler, NULL, NULL);
- lm_connection_register_message_handler(lconnection, jingle_iq_handler, LM_MESSAGE_TYPE_IQ, LM_HANDLER_PRIORITY_FIRST);
+ jingle_iq_handler = lm_message_handler_new(jingle_iq_event_handler, NULL, NULL);
+ lm_connection_register_message_handler(lconnection, jingle_iq_handler, LM_MESSAGE_TYPE_IQ, LM_HANDLER_PRIORITY_FIRST);
}
static void mcjingle_uninit(void)
{
- lm_connection_unregister_message_handler(lconnection, jingle_iq_handler, LM_MESSAGE_TYPE_IQ);
- lm_message_handler_invalidate(lm);
- lm_message_handler_unref(lm);
+ lm_connection_unregister_message_handler(lconnection, jingle_iq_handler, LM_MESSAGE_TYPE_IQ);
+ lm_message_handler_invalidate(jingle_iq_handler);
+ lm_message_handler_unref(jingle_iq_handler);
}