Re: Proposed Patches for META-DATA branch.

Alexander Malysh <[email protected]>
Newsgroups gmane.comp.mobile.kannel.devel
Message-ID <[email protected]>
Michael Zervakis schrieb:
> Dear all,
> 
>    During testing of cvs-20081021 meta-data branch we found two issues:
> 1. The meta_data_pack() always appends an "&" at the end of the 
> resulting string. As a result sms.meta_data always contains an "&" at 
> the end, which produces queries like the following:
> DEBUG:   Query: 
> sms_source=%2B999999999&sms_dest=9999&smsc-id=smsc&sms_command=test&meta_data=%3Fsmpp%3Fmessage_reference%3D192%26 

I don't see this as a issue. Why it should be a problem?

> 
> 
> 2. When using post-xml sms.meta_data is not urlencoded resulting in an 
> unreadable XML file like this <meta-data>?smpp?tag=1&</meta-data>.

You are right, but your fix is wrong because this can happens to any 
value in xml. See attached patch that should fix this issue.

> 
> Regards,
> Mike Zervakis
>
smsbox.patch.txt (text/plain, 2.2 KB)
Index: gw/smsbox.c
===================================================================
RCS file: /home/cvs/gateway/gw/smsbox.c,v
retrieving revision 1.279
diff -a -u -p -r1.279 smsbox.c
--- gw/smsbox.c	7 Oct 2008 10:55:27 -0000	1.279
+++ gw/smsbox.c	20 Nov 2008 17:36:41 -0000
@@ -1474,9 +1474,15 @@ static int obey_request(Octstr **result,
 /* XXX The first two chars are beeing eaten somewhere and
  * only sometimes - something must be ungry */
 
-#define OCTSTR_APPEND_XML(xml, tag, text)                  \
-        octstr_format_append(xml, "  \t\t<" tag ">%s</" tag ">\n", \
-            (text?octstr_get_cstr(text):""));
+#define OCTSTR_APPEND_XML(xml, tag, text) \
+        do { \
+            xmlDocPtr tmp_doc = xmlNewDoc(BAD_CAST "1.0"); \
+            xmlChar *xml_escaped = NULL; \
+            if (text != NULL) xml_escaped = xmlEncodeEntitiesReentrant(tmp_doc, BAD_CAST octstr_get_cstr(text)); \
+            octstr_format_append(xml, "  \t\t<" tag ">%s</" tag ">\n", (xml_escaped == NULL ? (char*)xml_escaped : "")); \
+            if (xml_escaped != NULL) xmlFree(xml_escaped); \
+            xmlFreeDoc(tmp_doc); \
+        } while(0)
 
 #define OCTSTR_APPEND_XML_NUMBER(xml, tag, value)          \
         octstr_format_append(xml, "  \t\t<" tag ">%ld</" tag ">\n", (long) value);
@@ -1569,7 +1575,7 @@ static int obey_request(Octstr **result,
 	if(msg->sms.compress != SMS_PARAM_UNDEFINED)
 	    OCTSTR_APPEND_XML_NUMBER(tmp, "compress", msg->sms.compress);
 	if(octstr_len(tmp))
-	    OCTSTR_APPEND_XML(xml, "dcs", tmp)
+	    OCTSTR_APPEND_XML(xml, "dcs", tmp);
 	octstr_destroy(tmp);
 
 	/* deferred (timing/delay) */
@@ -1577,7 +1583,7 @@ static int obey_request(Octstr **result,
 	if(msg->sms.deferred != SMS_PARAM_UNDEFINED)
 	    OCTSTR_APPEND_XML_NUMBER(tmp, "delay", msg->sms.deferred);
 	if(octstr_len(tmp))
-	    OCTSTR_APPEND_XML(xml, "timing", tmp)
+	    OCTSTR_APPEND_XML(xml, "timing", tmp);
 	octstr_destroy(tmp);
 
 	/* validity (vp/delay) */
@@ -1585,7 +1591,7 @@ static int obey_request(Octstr **result,
 	if(msg->sms.validity != SMS_PARAM_UNDEFINED)
 	    OCTSTR_APPEND_XML_NUMBER(tmp, "delay", msg->sms.validity);
 	if(octstr_len(tmp))
-	    OCTSTR_APPEND_XML(xml, "vp", tmp)
+	    OCTSTR_APPEND_XML(xml, "vp", tmp);
 	octstr_destroy(tmp);
 
 	/* time (at) */
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.