Change the way the header files are included.
authorNicolas Cornu <nicolas.cornu@ensi-bourges.fr>
Wed, 09 Jun 2010 22:16:21 +0200
changeset 18 d0ddcfd31eb8
parent 17 24aa7414bafd
child 19 60a10ab26723
Change the way the header files are included. Add a function to free a JingleNode.
jingle-filetransfert/CMakeLists.txt
jingle-filetransfert/filetransfert.c
jingle/CMakeLists.txt
jingle/action-handlers.c
jingle/check.c
jingle/check.h
jingle/jingle.c
jingle/jingle.h
jingle/register.c
jingle/register.h
--- a/jingle-filetransfert/CMakeLists.txt	Wed Jun 09 04:11:26 2010 +0200
+++ b/jingle-filetransfert/CMakeLists.txt	Wed Jun 09 22:16:21 2010 +0200
@@ -1,4 +1,4 @@
 add_library(jingle-filetransfert MODULE filetransfert.c)
 set_target_properties(jingle-filetransfert PROPERTIES COMPILE_FLAGS "-Wall")
-include_directories(${CMAKE_SOURCE_DIR}/jingle ..)
+include_directories(${CMAKE_SOURCE_DIR})
 install(TARGETS jingle-filetransfert DESTINATION lib/mcabber)
--- a/jingle-filetransfert/filetransfert.c	Wed Jun 09 04:11:26 2010 +0200
+++ b/jingle-filetransfert/filetransfert.c	Wed Jun 09 22:16:21 2010 +0200
@@ -26,7 +26,7 @@
 #include <mcabber/modules.h>
 #include <mcabber/xmpp_helper.h>
 
-#include <jingle.h>
+#include <jingle/jingle.h>
 
 #include "filetransfert.h"
 
--- a/jingle/CMakeLists.txt	Wed Jun 09 04:11:26 2010 +0200
+++ b/jingle/CMakeLists.txt	Wed Jun 09 22:16:21 2010 +0200
@@ -1,5 +1,5 @@
 add_library(jingle MODULE jingle.c check.c action-handlers.c register.c)
 set_target_properties(jingle PROPERTIES COMPILE_FLAGS "-Wall")
-include_directories(${LM_INCLUDE_DIRS} ..)
+include_directories(${LM_INCLUDE_DIRS} ${CMAKE_SOURCE_DIR})
 target_link_libraries(jingle ${LM_LIBRARIES})
 install(TARGETS jingle DESTINATION lib/mcabber)
--- a/jingle/action-handlers.c	Wed Jun 09 04:11:26 2010 +0200
+++ b/jingle/action-handlers.c	Wed Jun 09 22:16:21 2010 +0200
@@ -21,19 +21,19 @@
 
 #include <glib.h>
 
-#include "jingle.h"
-#include "check.h"
+#include <jingle/jingle.h>
+#include <jingle/check.h>
 
 
 void handle_session_initiate(LmMessage *m, JingleNode *jn)
 {
   // a session-initiate message must contains at least one <content> element
-  if (g_list_length(jn->content) < 1) {
+  if (g_slist_length(jn->content) < 1) {
     jingle_send_iq_error(m, "cancel", "bad-request", NULL);
     return;
   }
 
-  /*// if a session with the same jid already exists
+  /*// if a session with the same sid already exists
   if (session_find(jn) != NULL) {
     jingle_send_iq_error(m, "cancel", "unexpected-request", "out-of-order");
     return;
--- a/jingle/check.c	Wed Jun 09 04:11:26 2010 +0200
+++ b/jingle/check.c	Wed Jun 09 22:16:21 2010 +0200
@@ -22,11 +22,11 @@
 #include <glib.h>
 #include <loudmouth/loudmouth.h>
 
-#include "check.h"
-#include "jingle.h"
+#include <jingle/check.h>
+#include <jingle/jingle.h>
 
 
-JingleContentNode *check_content(LmMessageNode *node, GError **err);
+static JingleContentNode *check_content(LmMessageNode *node, GError **err);
 gint index_in_array(const gchar *str, const gchar **array);
 
 
@@ -49,12 +49,11 @@
  * Populate a jingle_data struct from a <jingle> element.
  * Check if the element is in compliance with the XEP.
  */
-gboolean check_jingle(LmMessageNode *node, JingleNode *jn, GError **err)
+gboolean check_jingle(LmMessage *message, LmMessageNode *node,
+                      JingleNode *jn, GError **err)
 {
   //gint nb_reason = 0;
-  LmMessageNode *child = NULL;
   const gchar *actionstr;
-  JingleContentNode *cn;
 
   actionstr     = lm_message_node_get_attribute(node, "action");
   jn->initiator = lm_message_node_get_attribute(node, "initiator");
@@ -84,22 +83,14 @@
                 "too many reason elements");
     return FALSE;
   }*/
-  
-  for (child = node->children; child; child = child->next) {
-    if (!g_strcmp0(child->name, "content")) {
-      cn = check_content(child, err);
-      if(cn == NULL) {
-        g_assert (*err != NULL);
-        return FALSE;
-	  }
-	  jn->content = g_list_append(jn->content, cn);
-    }
-  }
+
+  jn->message = lm_message_ref(message);
+  jn->node    = node;
 
   return TRUE;
 }
 
-JingleContentNode *check_content(LmMessageNode *node, GError **err)
+static JingleContentNode *check_content(LmMessageNode *node, GError **err)
 {
   JingleContentNode *cn = g_new0(JingleContentNode, 1);
   const gchar *creatorstr, *sendersstr;
@@ -141,6 +132,28 @@
   return cn;
 }
 
+/**
+ * Check <content> elements if there is any.
+ * Add them to the JingleNode struct.
+ */
+gboolean check_contents(JingleNode *jn, GError **err)
+{
+  LmMessageNode *child = NULL;
+  JingleContentNode *cn;
+
+  for (child = jn->node->children; child; child = child->next) {
+    if (!g_strcmp0(child->name, "content")) {
+      cn = check_content(child, err);
+      if(cn == NULL) {
+        g_assert (*err != NULL);
+        return FALSE;
+	  }
+	  jn->content = g_slist_append(jn->content, cn);
+    }
+  }
+  return TRUE;
+}
+
 gint index_in_array(const gchar *str, const gchar **array)
 {
   gint i;
--- a/jingle/check.h	Wed Jun 09 04:11:26 2010 +0200
+++ b/jingle/check.h	Wed Jun 09 22:16:21 2010 +0200
@@ -4,7 +4,7 @@
 #include <glib.h>
 #include <loudmouth/loudmouth.h>
 
-#include "jingle.h"
+#include <jingle/jingle.h>
 
 #define JINGLE_CHECK_ERROR jingle_check_error_quark()
 
@@ -16,7 +16,9 @@
 } JingleCheckError;
 
 
-int check_jingle(LmMessageNode* node, JingleNode *jd, GError **err);
+gboolean check_jingle(LmMessage *message, LmMessageNode *node,
+                      JingleNode *jn, GError **err);
+gboolean check_contents(JingleNode *jn, GError **err);
 GQuark jingle_check_error_quark();
 
 #endif
--- a/jingle/jingle.c	Wed Jun 09 04:11:26 2010 +0200
+++ b/jingle/jingle.c	Wed Jun 09 22:16:21 2010 +0200
@@ -31,10 +31,10 @@
 #include <mcabber/xmpp_helper.h>
 #include <mcabber/xmpp_defines.h> 
 
-#include "jingle.h"
-#include "check.h"
-#include "action-handlers.h"
-#include "register.h"
+#include <jingle/jingle.h>
+#include <jingle/check.h>
+#include <jingle/action-handlers.h>
+#include <jingle/register.h>
 
 
 static void  jingle_register_lm_handlers(void);
@@ -107,7 +107,7 @@
     return LM_HANDLER_RESULT_REMOVE_MESSAGE;
   }
 
-  check_jingle(jnode, jn, &error);
+  check_jingle(message, jnode, jn, &error);
   if (error != NULL) {
     if (error->domain == JINGLE_CHECK_ERROR) {
       // request malformed, we reply with a bad-request
@@ -146,7 +146,7 @@
 }
 
 /**
- * Reply to a Jingle IQ with an error.
+ * Create an error IQ.
  */
 LmMessage *jingle_new_iq_error(LmMessage *m, const gchar *errtype,
                                const gchar *cond, const gchar *jinglecond)
@@ -173,6 +173,9 @@
   return r;
 }
 
+/**
+ * Reply to a Jingle IQ with an error.
+ */
 void jingle_send_iq_error(LmMessage *m, const gchar *errtype,
                           const gchar *cond, const gchar *jinglecond)
 {
@@ -196,6 +199,18 @@
   return JINGLE_UNKNOWN_ACTION;
 }
 
+void jingle_free_jinglenode(JingleNode *jn)
+{
+  GSList *entry = NULL;
+  for (entry = jn->content; entry; entry = entry->next) {
+    if (entry->data != NULL)
+      g_free((JingleContentNode*) entry->data);
+  }
+  g_slist_free(jn->content);
+  lm_message_unref(jn->message);
+  g_free(jn);
+}
+
 static void jingle_unregister_lm_handlers(void)
 {
   if (lconnection) {
--- a/jingle/jingle.h	Wed Jun 09 04:11:26 2010 +0200
+++ b/jingle/jingle.h	Wed Jun 09 22:16:21 2010 +0200
@@ -40,6 +40,12 @@
 } JingleSenders;
 
 typedef struct {
+  /* pointer to the original LmMessage */
+  LmMessage *message;
+
+  /* poiter to the <jingle> element */
+  LmMessageNode *node;
+
   /* action attribute */
   JingleAction action;
 
@@ -58,7 +64,7 @@
   const gchar *sid;
 
   /* Doubly-linked list of JingleContentNode. */
-  GList *content;
+  GSList *content;
 
 } JingleNode;
 
--- a/jingle/register.c	Wed Jun 09 04:11:26 2010 +0200
+++ b/jingle/register.c	Wed Jun 09 22:16:21 2010 +0200
@@ -23,8 +23,8 @@
 
 #include <mcabber/logprint.h>
 
-#include "register.h"
-#include "jingle.h"
+#include <jingle/register.h>
+#include <jingle/jingle.h>
 
 
 typedef struct {
--- a/jingle/register.h	Wed Jun 09 04:11:26 2010 +0200
+++ b/jingle/register.h	Wed Jun 09 22:16:21 2010 +0200
@@ -1,7 +1,7 @@
 #ifndef __JINGLE_REGISTER_H__
 #define __JINGLE_REGISTER_H__
 
-#include "jingle.h"
+#include <jingle/jingle.h>
 
 
 #define NS_JINGLE_APP_PREFIX       "urn:xmpp:jingle:app:"