Use gchar/g_strdump instead of char/strcpy.
authorNicolas Cornu <nicolas.cornu@ensi-bourges.fr>
Tue, 25 May 2010 16:44:52 +0200
changeset 5 2155c65c7455
parent 4 0ac09410a684
child 6 a035ec60dc7f
Use gchar/g_strdump instead of char/strcpy. Add an empty config.h.in.
config.h.in
jingle.c
parse.c
parse.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/config.h.in	Tue May 25 16:44:52 2010 +0200
@@ -0,0 +1,1 @@
+//#cmakedefine USE_LIBNAME
--- a/jingle.c	Tue May 25 15:58:50 2010 +0200
+++ b/jingle.c	Tue May 25 16:44:52 2010 +0200
@@ -36,10 +36,6 @@
 static void mcjingle_uninit(void);
 
 
-struct info_iq {
-	const gchar *from, *to, *type, *id;
-};
-
 LmMessageHandler* jingle_iq_handler = NULL;
 
 
@@ -56,19 +52,6 @@
 };
 
 
-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");
-}
-
 LmHandlerResult jingle_iq_event_handler(LmMessageHandler *handler,
 		LmConnection *connection,
 		LmMessage *message,
--- a/parse.c	Tue May 25 15:58:50 2010 +0200
+++ b/parse.c	Tue May 25 16:44:52 2010 +0200
@@ -11,10 +11,10 @@
   if (!strcmp(ij->name, "jingle"))
     return PARSE_ERROR_NAME;
 
-  ij->action    = attrcpy(lm_message_node_get_attribute(node, "action"));
-  ij->initiator = attrcpy(lm_message_node_get_attribute(node, "initiator"));
-  ij->responder = attrcpy(lm_message_node_get_attribute(node, "responder"));
-  ij->sid       = attrcpy(lm_message_node_get_attribute(node, "sid"));
+  ij->action    = g_strdup(lm_message_node_get_attribute(node, "action"));
+  ij->initiator = g_strdup(lm_message_node_get_attribute(node, "initiator"));
+  ij->responder = g_strdup(lm_message_node_get_attribute(node, "responder"));
+  ij->sid       = g_strdup(lm_message_node_get_attribute(node, "sid"));
    
   // check required
   if (ij->action == NULL || ij->sid == NULL)
@@ -43,10 +43,10 @@
 
 void free_jingle(struct info_jingle *ij)
 {
-  free(ij->action);
-  free(ij->initiator);
-  free(ij->responder);
-  free(ij->sid);
+  g_free(ij->action);
+  g_free(ij->initiator);
+  g_free(ij->responder);
+  g_free(ij->sid);
 }
 
 
@@ -55,14 +55,14 @@
   if (!strcmp(ic->name, "content"))
     return PARSE_ERROR_NAME;
 
-  ic->creator     = attrcpy(lm_message_node_get_attribute(node, "creator"));
-  ic->disposition = attrcpy(lm_message_node_get_attribute(node, "disposition"));
-  ic->name        = attrcpy(lm_message_node_get_attribute(node, "name"));
-  ic->senders     = attrcpy(lm_message_node_get_attribute(node, "senders"));
+  ic->creator     = g_strdup(lm_message_node_get_attribute(node, "creator"));
+  ic->disposition = g_strdup(lm_message_node_get_attribute(node, "disposition"));
+  ic->name        = g_strdup(lm_message_node_get_attribute(node, "name"));
+  ic->senders     = g_strdup(lm_message_node_get_attribute(node, "senders"));
 
   // Put default if none
   if (ic->disposition == NULL)
-    ic->disposition = attrcpy("session");
+    ic->disposition = g_strdup("session");
 
   // check required
   if (ic->creator == NULL || ic->name == NULL)
@@ -80,14 +80,14 @@
 
 void free_content(struct info_content *ic)
 {
-  free(ic->creator);
-  free(ic->disposition);
-  free(ic->name);
-  free(ic->senders);
+  g_free(ic->creator);
+  g_free(ic->disposition);
+  g_free(ic->name);
+  g_free(ic->senders);
 }
 
 
-int check_restriction(const char* name, const char** values)
+int check_restriction(const gchar* name, const gchar** values)
 {
   const char* value;
   int found = 0;
@@ -99,14 +99,3 @@
   }
   return found;
 }
-
-
-char* attrcpy(const char* attr)
-{
-  char *tmp = NULL;
-  if (attr != NULL) {
-    tmp = (char*) malloc((strlen(attr)+1) * sizeof(char));
-    strcpy(tmp, attr);
-  }
-  return tmp;
-}
--- a/parse.h	Tue May 25 15:58:50 2010 +0200
+++ b/parse.h	Tue May 25 16:44:52 2010 +0200
@@ -1,3 +1,7 @@
+#ifndef __PARSE_H__
+#define __PARSE_H__ 1
+
+#include <glib.h>
 #include <loudmouth/loudmouth.h>
 
 #define PARSE_OK                    0
@@ -7,28 +11,28 @@
 #define PARSE_ERROR_TOO_MANY_CHILDS 4
 
 struct info_iq {
-  char* from;
-  char* id;
-  char* to;
-  char* set;
+  gchar* from;
+  gchar* id;
+  gchar* to;
+  gchar* set;
 };
 
 struct info_jingle {
-  char* action;      // required (content-accept, content-add,
+  gchar* action;      // required (content-accept, content-add,
   // content-modify, content-reject, content-remove, description-info
   // security-info, session-accept, session-info, session-initiate,
   // session-terminate, transport-accept, transport-info, transport-reject,
   // transport-replace)
-  char* initiator;   // optional
-  char* responder;   // optional
-  char* sid;         // required
+  gchar* initiator;   // optional
+  gchar* responder;   // optional
+  gchar* sid;         // required
 };
 
 struct info_content {
-  char* creator;     // required (initiator, responder)
-  char* disposition; // optional, default=session
-  char* name;        // required
-  char* senders;     // optional (both, initiator, none, responder)
+  gchar* creator;     // required (initiator, responder)
+  gchar* disposition; // optional, default=session
+  gchar* name;        // required
+  gchar* senders;     // optional (both, initiator, none, responder)
 };
 
 int parse_jingle(LmMessageNode* node, struct info_jingle* ij);
@@ -36,6 +40,6 @@
 int parse_content(LmMessageNode* node, struct info_content* ic);
 void free_content(struct info_content* ic);
 
-int check_restriction(const char* name, const char** values)
+int check_restriction(const char* name, const char** values);
 
-char* attrcpy(const char* attr);
+#endif