myserver-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[myserver-commit] [SCM] GNU MyServer branch, master, updated. 0_9_2-173-


From: Giuseppe Scrivano
Subject: [myserver-commit] [SCM] GNU MyServer branch, master, updated. 0_9_2-173-g65ae115
Date: Sun, 18 Apr 2010 21:07:58 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU MyServer".

The branch, master has been updated
       via  65ae115899512a5ebde9d66bf7ebbdbcf062a956 (commit)
       via  687ff1cd87cf7d1897223a0905a5a127b4b09ca4 (commit)
      from  476a013549ad805136ebfb3d94b6aa1ed3b37312 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------


commit 65ae115899512a5ebde9d66bf7ebbdbcf062a956
Author: Giuseppe Scrivano <address@hidden>
Date:   Sun Apr 18 23:03:53 2010 +0200

    Reformat code

diff --git a/myserver/src/base/xml/xml_parser.cpp 
b/myserver/src/base/xml/xml_parser.cpp
index ba125c1..22cdc04 100644
--- a/myserver/src/base/xml/xml_parser.cpp
+++ b/myserver/src/base/xml/xml_parser.cpp
@@ -35,7 +35,7 @@
  */
 static int MemBufWriteCallback (void * context, const char * buffer, int len)
 {
-  ((MemBuf *)context)->addBuffer ((const void *)buffer, len);
+  ((MemBuf *)context)->addBuffer ((const void *) buffer, len);
   return len;
 }
 
@@ -50,7 +50,6 @@ static int MemBufCloseCallback (void *context)
   return 0;
 }
 
-
 /**
  * Initializes the libxml2 library
  * Calls xmlInitParser ()
@@ -92,34 +91,32 @@ int XmlParser::open (const char* filename, bool useXpath)
     close ();
 
   doc = xmlParseFile (filename);
-
   if (doc == NULL)
     return -1;
 
   cur = xmlDocGetRootElement (doc);
   if (!cur)
-  {
-    close ();
-    return -1;
-  }
+    {
+      close ();
+      return -1;
+    }
 
   mtime = FilesUtility::getLastModTime (filename);
-
   if (mtime == static_cast<time_t>(-1))
-  {
-    close ();
-    return -1;
-  }
-
-  if (useXpath)
-  {
-    xpathCtx = xmlXPathNewContext (doc);
-    if (xpathCtx == NULL)
     {
       close ();
       return -1;
     }
-  }
+
+  if (useXpath)
+    {
+      xpathCtx = xmlXPathNewContext (doc);
+      if (xpathCtx == NULL)
+        {
+          close ();
+          return -1;
+        }
+    }
   return 0;
 }
 
@@ -148,11 +145,9 @@ int XmlParser::openMemBuf (MemBuf & memory, bool useXpath)
   if (memory.getLength () == 0)
     return -1;
 
-  if (!doc)
-    {
-      doc = xmlParseMemory ((const char * )memory.getBuffer (),
-                            memory.getLength ());
-    }
+  if (! doc)
+    doc = xmlParseMemory ((const char * ) memory.getBuffer (),
+                          memory.getLength ());
   else
     close ();
 
@@ -160,7 +155,6 @@ int XmlParser::openMemBuf (MemBuf & memory, bool useXpath)
     return -1;
 
   cur = xmlDocGetRootElement (doc);
-
   if (!cur)
     {
       close ();
@@ -170,11 +164,11 @@ int XmlParser::openMemBuf (MemBuf & memory, bool useXpath)
   if (useXpath)
     {
       xpathCtx = xmlXPathNewContext (doc);
-    if (xpathCtx == NULL)
-      {
-      close ();
-      return -1;
-      }
+      if (xpathCtx == NULL)
+        {
+          close ();
+          return -1;
+        }
     }
   return 0;
 }
@@ -220,23 +214,23 @@ const char *XmlParser::getValue (const char* vName)
 {
   char *ret = NULL;
   xmlNodePtr lcur;
-  cur = xmlDocGetRootElement (doc);
 
+  cur = xmlDocGetRootElement (doc);
   if (!cur)
     return 0;
 
   lcur = cur->xmlChildrenNode;
 
   while (lcur)
-  {
-    if (!xmlStrcmp (lcur->name, (const xmlChar *)vName))
     {
-      lastNode = lcur;
-      return (char*)lcur->children->content;
-    }
+      if (!xmlStrcmp (lcur->name, (const xmlChar *) vName))
+        {
+          lastNode = lcur;
+          return (const char*) lcur->children->content;
+        }
 
-    lcur = lcur->next;
-  }
+      lcur = lcur->next;
+    }
 
   return ret;
 }
@@ -252,58 +246,53 @@ int XmlParser::setValue (const char* vName, const char 
*value)
 {
   xmlNodePtr lcur = cur->xmlChildrenNode;
   while (lcur)
-  {
-    if (!xmlStrcmp (lcur->name, (const xmlChar *)vName))
     {
-      lastNode = lcur;
+      if (!xmlStrcmp (lcur->name, (const xmlChar *)vName))
+        {
+          lastNode = lcur;
 
-      if (lcur->children->content)
-        xmlFree (lcur->children->content);
+          if (lcur->children->content)
+            xmlFree (lcur->children->content);
 
-      lcur->children->content = (xmlChar *)
-        checked::checkErrorNull (xmlStrdup ((const xmlChar *) value));
+          lcur->children->content = (xmlChar *)
+            checked::checkErrorNull (xmlStrdup ((const xmlChar *) value));
 
-      return 0;
-    }
+          return 0;
+        }
 
-    lcur = lcur->next;
-  }
+      lcur = lcur->next;
+    }
 
   return 1;
 }
 
-
 /**
  * Gets the attribute for the node field.
  * \param field Field
  * \param attr Attribute
  * \return
  */
-const char *XmlParser::getAttr (const char* field, const char *attr)
+const char *XmlParser::getAttr (const char *field, const char *attr)
 {
   xmlNodePtr lcur = cur->xmlChildrenNode;
 
   while (lcur)
-  {
-    if (!xmlStrcmp (lcur->name, (const xmlChar *)field))
     {
-      lastNode = lcur;
-      xmlAttr *attrs =  lcur->properties;
-
-      while (attrs)
-      {
-        if (!xmlStrcmp (attrs->name, (const xmlChar *)attr))
+      if (!xmlStrcmp (lcur->name, (const xmlChar *) field))
         {
-          return (char*)attrs->children->content;
+          lastNode = lcur;
+          xmlAttr *attrs =  lcur->properties;
+          while (attrs)
+            {
+              if (!xmlStrcmp (attrs->name, (const xmlChar *) attr))
+                return (const char *) attrs->children->content;
+
+              attrs = attrs->next;
+            }
         }
-
-        attrs = attrs->next;
-      }
+      lcur = lcur->next;
     }
 
-    lcur = lcur->next;
-  }
-
   return 0;
 }
 
@@ -313,22 +302,20 @@ const char *XmlParser::getAttr (const char* field, const 
char *attr)
  *\return NULL on errors.
  *\return The XmlXPathResult containing the result.
  */
-XmlXPathResult* XmlParser::evaluateXpath (const char* expr)
+XmlXPathResult* XmlParser::evaluateXpath (const char *expr)
 {
   xmlXPathObjectPtr xpathObj;
 
-  if (!useXpath)
+  if (! useXpath)
     return NULL;
 
-  xpathObj = xmlXPathEvalExpression ((const xmlChar*)expr, xpathCtx);
-
+  xpathObj = xmlXPathEvalExpression ((const xmlChar *) expr, xpathCtx);
   if (xpathObj == NULL)
     return NULL;
 
   return new XmlXPathResult (xpathObj);
 }
 
-
 /**
  * Frees the memory, use by the XmlParser class
  */
@@ -361,10 +348,9 @@ int XmlParser::close ()
  * \param nbytes Amount of bytes
  * \return Returns 0 on success, non 0 on failures
  */
-int XmlParser::save (const char *filename,int *nbytes)
+int XmlParser::save (const char *filename, int *nbytes)
 {
   int err = xmlSaveFile (filename,doc);
-
   if (nbytes)
     *nbytes = err;
 
@@ -380,13 +366,13 @@ int XmlParser::save (const char *filename,int *nbytes)
  * \param nbytes Amount of bytes
  * \return Returns 0 on success, non 0 on failures
  */
-int XmlParser::saveMemBuf (MemBuf & memory,int *nbytes)
+int XmlParser::saveMemBuf (MemBuf &memory, int *nbytes)
 {
   /*! Initialize the callback struct. */
   xmlOutputBufferPtr callback;
   callback = xmlOutputBufferCreateIO (MemBufWriteCallback,
                                       MemBufCloseCallback,
-                                      (void *)&memory,
+                                      (void *) &memory,
                                       NULL);
 
   /*! Clear the buffer */
@@ -394,7 +380,6 @@ int XmlParser::saveMemBuf (MemBuf & memory,int *nbytes)
 
   /*! Let libxml2 fill the MemBuf class with our interal callbacks. */
   int err = xmlSaveFileTo (callback, doc, NULL);
-
   if (nbytes)
     *nbytes = err;
 
@@ -411,8 +396,8 @@ void XmlParser::newfile (const char * root)
   if (doc != NULL)
     close ();
 
-  doc = xmlNewDoc ((const xmlChar*)"1.0");
-  cur = xmlNewDocNode (doc, NULL, (const xmlChar*)root, NULL);
+  doc = xmlNewDoc ((const xmlChar *) "1.0");
+  cur = xmlNewDocNode (doc, NULL, (const xmlChar *) root, NULL);
 
   xmlDocSetRootElement (doc, cur);
 
@@ -426,10 +411,10 @@ void XmlParser::newfile (const char * root)
  * \param name Child name
  * \param value Value of the child
  */
-void XmlParser::addChild (const char * name, const char * value)
+void XmlParser::addChild (const char *name, const char *value)
 {
-  lastNode = xmlNewTextChild (cur, NULL, (const xmlChar*)name,
-                              (const xmlChar*)value);
+  lastNode = xmlNewTextChild (cur, NULL, (const xmlChar *) name,
+                              (const xmlChar *) value);
 
   addLineFeed ();
 }
@@ -440,12 +425,12 @@ void XmlParser::addChild (const char * name, const char * 
value)
  * Only one level for now
  * \param name Name of the sub group
  */
-void XmlParser::addGroup (const char * name)
+void XmlParser::addGroup (const char *name)
 {
   if (prevCur == NULL)
     {
       prevCur = cur;
-      cur = xmlNewTextChild (cur, NULL, (const xmlChar*)name, NULL);
+      cur = xmlNewTextChild (cur, NULL, (const xmlChar *) name, NULL);
       lastNode = cur;
       addLineFeed ();
     }
@@ -459,12 +444,12 @@ void XmlParser::addGroup (const char * name)
 void XmlParser::endGroup ()
 {
   if (prevCur != NULL)
-  {
-    cur = prevCur;
-    prevCur = NULL;
-    addLineFeed ();
-    addLineFeed ();
-  }
+    {
+      cur = prevCur;
+      prevCur = NULL;
+      addLineFeed ();
+      addLineFeed ();
+    }
 }
 
 
@@ -473,12 +458,12 @@ void XmlParser::endGroup ()
  * \param name Name
  * \param value Value
  */
-void XmlParser::setAttr (const char * name, const char * value)
+void XmlParser::setAttr (const char *name, const char *value)
 {
   if (lastNode == NULL)
     return;
 
-  xmlSetProp (lastNode, (const xmlChar*)name, (const xmlChar*)value);
+  xmlSetProp (lastNode, (const xmlChar*) name, (const xmlChar*) value);
 }
 
 
@@ -488,9 +473,9 @@ void XmlParser::setAttr (const char * name, const char * 
value)
 void XmlParser::addLineFeed ()
 {
 #ifdef WIN32
-    xmlNodePtr endline = xmlNewDocText (doc, (const xmlChar *)"\r\n");
+  xmlNodePtr endline = xmlNewDocText (doc, (const xmlChar *) "\r\n");
 #else
-    xmlNodePtr endline = xmlNewDocText (doc, (const xmlChar *)"\n");
+  xmlNodePtr endline = xmlNewDocText (doc, (const xmlChar *) "\n");
 #endif
 
   xmlAddChild (cur, endline);



commit 687ff1cd87cf7d1897223a0905a5a127b4b09ca4
Author: Giuseppe Scrivano <address@hidden>
Date:   Sun Apr 18 22:33:29 2010 +0200

    Fix a segfault when the new value is longer than the previous one

diff --git a/myserver/src/base/xml/xml_parser.cpp 
b/myserver/src/base/xml/xml_parser.cpp
index 13b0b8f..ba125c1 100644
--- a/myserver/src/base/xml/xml_parser.cpp
+++ b/myserver/src/base/xml/xml_parser.cpp
@@ -21,6 +21,7 @@
 #include <include/base/xml/xml_parser.h>
 #include <include/base/utility.h>
 #include <include/base/file/files_utility.h>
+#include <include/base/exceptions/checked.h>
 
 #include <string.h>
 
@@ -257,7 +258,10 @@ int XmlParser::setValue (const char* vName, const char 
*value)
       lastNode = lcur;
 
       if (lcur->children->content)
-        strcpy ((char*)lcur->children->content, value);
+        xmlFree (lcur->children->content);
+
+      lcur->children->content = (xmlChar *)
+        checked::checkErrorNull (xmlStrdup ((const xmlChar *) value));
 
       return 0;
     }

-----------------------------------------------------------------------

Summary of changes:
 myserver/src/base/xml/xml_parser.cpp |  169 ++++++++++++++++------------------
 1 files changed, 79 insertions(+), 90 deletions(-)


hooks/post-receive
-- 
GNU MyServer




reply via email to

[Prev in Thread] Current Thread [Next in Thread]