fixed XML parsing of TNCCS 1.1 ReasonString message
authorAndreas Steffen <andreas.steffen@strongswan.org>
Thu, 16 Jun 2011 09:30:38 +0000 (11:30 +0200)
committerAndreas Steffen <andreas.steffen@strongswan.org>
Thu, 16 Jun 2011 09:30:38 +0000 (11:30 +0200)
src/libcharon/plugins/tnccs_11/messages/tnccs_reason_strings_msg.c

index a3476de..2486a51 100644 (file)
@@ -14,6 +14,7 @@
  */
 
 #include "tnccs_reason_strings_msg.h"
+#include "tnccs_error_msg.h"
 
 #include <debug.h>
 
@@ -85,6 +86,10 @@ tnccs_msg_t *tnccs_reason_strings_msg_create_from_node(xmlNodePtr node,
                                                                                                           linked_list_t *errors)
 {
        private_tnccs_reason_strings_msg_t *this;
+       char *error_msg, *lang_string, *reason_string;
+       tnccs_error_type_t error_type = TNCCS_ERROR_MALFORMED_BATCH;
+       tnccs_msg_t *msg;
+       xmlNodePtr child;
 
        INIT(this,
                .public = {
@@ -99,7 +104,45 @@ tnccs_msg_t *tnccs_reason_strings_msg_create_from_node(xmlNodePtr node,
                .node = node,
        );
 
+       if (xmlStrcmp(node->name, (const xmlChar*)"TNCCS-ReasonStrings"))
+       {
+               error_msg = "TNCCS-ReasonStrings tag in expected";
+               goto fatal;
+       }
+
+       child = node->xmlChildrenNode;
+       while (child)
+       {
+               if (xmlIsBlankNode(child))
+               {
+                       child = child->next;
+                       continue;
+               }
+               if (xmlStrcmp(child->name, (const xmlChar*)"ReasonString"))
+               {
+                       error_msg = "ReasonString tag in expected";
+                       goto fatal;
+               }
+               break;
+       }
+
+       lang_string = (char*)xmlGetProp(child, (const xmlChar*)"lang");
+       if (!lang_string)
+       {
+               lang_string = "";
+       }
+       this->language = chunk_create(strdup(lang_string), strlen(lang_string));
+
+       reason_string = (char*)xmlNodeGetContent(child);
+       this->reason = chunk_create(strdup(reason_string), strlen(reason_string));
+
        return &this->public.tnccs_msg_interface;
+
+fatal:
+       msg = tnccs_error_msg_create(error_type, error_msg);
+       errors->insert_last(errors, msg);
+       _destroy(this);
+       return NULL;
 }
 
 /**
@@ -145,7 +188,7 @@ tnccs_msg_t *tnccs_reason_strings_msg_create(chunk_t reason, chunk_t language)
        xmlNewProp(n3, BAD_CAST "xml:lang", BAD_CAST this->language.ptr);
        xmlNodeSetContent(n3, BAD_CAST this->reason.ptr);
        xmlAddChild(n2, n3);
-    xmlAddChild(n, n2);
+       xmlAddChild(n, n2);
 
        return &this->public.tnccs_msg_interface;
 }