[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[myserver-commit] [2757] Static size buffers were replaced with std:: st
From: |
Giuseppe Scrivano |
Subject: |
[myserver-commit] [2757] Static size buffers were replaced with std:: string and some memory leaks were fixed |
Date: |
Thu, 21 Aug 2008 19:55:52 +0000 |
Revision: 2757
http://svn.sv.gnu.org/viewvc/?view=rev&root=myserver&revision=2757
Author: gscrivano
Date: 2008-08-21 19:55:52 +0000 (Thu, 21 Aug 2008)
Log Message:
-----------
Static size buffers were replaced with std::string and some memory leaks were
fixed
Modified Paths:
--------------
trunk/myserver/include/xml_parser.h
trunk/myserver/src/security.cpp
Modified: trunk/myserver/include/xml_parser.h
===================================================================
--- trunk/myserver/include/xml_parser.h 2008-08-17 12:08:47 UTC (rev 2756)
+++ trunk/myserver/include/xml_parser.h 2008-08-21 19:55:52 UTC (rev 2757)
@@ -92,6 +92,7 @@
void addLineFeed();
time_t getLastModTime();
+ XmlXPathResult* evaluateXpath(string & path){return
evaluateXpath(path.c_str());}
XmlXPathResult* evaluateXpath(const char*);
bool isXpathEnabled(){return useXpath;}
private:
Modified: trunk/myserver/src/security.cpp
===================================================================
--- trunk/myserver/src/security.cpp 2008-08-17 12:08:47 UTC (rev 2756)
+++ trunk/myserver/src/security.cpp 2008-08-21 19:55:52 UTC (rev 2757)
@@ -27,6 +27,7 @@
#include <string>
#include <sstream>
+#include <memory>
using namespace std;
@@ -66,33 +67,32 @@
string &out,
XmlParser* parser)
{
- char evalString[64];
+ string evalString;
XmlXPathResult* xpathRes;
xmlNodeSetPtr nodes;
+ int ret;
-
out.assign("");
if(parser == NULL || !parser->isXpathEnabled())
return -1;
- sprintf(evalString, "/SECURITY/address@hidden'%d\']/@FILE", error);
+ evalString = "/SECURITY/address@hidden'";
+ evalString += error;
+ evalString += "']/@FILE";
+
xpathRes = parser->evaluateXpath(evalString);
nodes = xpathRes->getNodeSet();
if(nodes && nodes->nodeNr)
out.assign((const char*)nodes->nodeTab[0]->children->content);
- if(xpathRes)
- delete xpathRes;
-
-
/* Return 1 if both it was found and well configured. */
- if(nodes && nodes->nodeNr && out.length())
- return 1;
-
- return 0;
+ ret = nodes && nodes->nodeNr && out.length() ? 1 : 0;
+ delete xpathRes;
+ return ret;
+
}
@@ -105,43 +105,57 @@
*/
int SecurityManager::getPermissionMask(SecurityToken *st, XmlParser* parser)
{
- XmlXPathResult* xpathRes;
xmlNodeSetPtr nodes;
xmlAttr* attr;
- char evalString[256];
+ string evalString;
int permissions = 0;
const char* requiredPassword;
bool rightPassword = false;
+ auto_ptr<XmlXPathResult> itemRes;
+ auto_ptr<XmlXPathResult> userRes;
if(parser == NULL || !parser->isXpathEnabled())
return -1;
- strcpy(evalString, "/SECURITY/AUTH/@TYPE");
+ evalString = "/SECURITY/AUTH/@TYPE";
- xpathRes = parser->evaluateXpath(evalString);
- nodes = xpathRes->getNodeSet();
+ auto_ptr<XmlXPathResult>authRes(parser->evaluateXpath(evalString));
+ nodes = authRes.get()->getNodeSet();
if(nodes && nodes->nodeNr)
strncpy(st->authType,(const char*)nodes->nodeTab[0]->children->content,
st->authTypeLen);
+ evalString = "/SECURITY/address@hidden'";
+ evalString += st->filename;
+ evalString += "\']/address@hidden'";
+ evalString += st->user;
+ evalString += "\']/.";
- sprintf(evalString, "/SECURITY/address@hidden'%s\']/address@hidden'%s\']/.",
st->filename, st->user);
- xpathRes = parser->evaluateXpath(evalString);
- nodes = xpathRes->getNodeSet();
+ auto_ptr<XmlXPathResult> itemUserRes(parser->evaluateXpath(evalString));
+ nodes = itemUserRes.get()->getNodeSet();
+
if(!nodes || !nodes->nodeNr)
{
- sprintf(evalString, "/SECURITY/address@hidden'%s\']/.", st->filename);
- xpathRes = parser->evaluateXpath(evalString);
- nodes = xpathRes->getNodeSet();
+ evalString = "/SECURITY/address@hidden'";
+ evalString += st->filename;
+ evalString += "\']/.";
+ itemRes.reset(parser->evaluateXpath(evalString));
+
+ nodes = itemRes.get()->getNodeSet();
+
if(!nodes || !nodes->nodeNr)
{
- sprintf(evalString, "/SECURITY/address@hidden'%s\']/.", st->user);
- xpathRes = parser->evaluateXpath(evalString);
- nodes = xpathRes->getNodeSet();
+ evalString = "/SECURITY/address@hidden'";
+ evalString += st->user;
+ evalString += "\']/.";
+
+ userRes.reset(parser->evaluateXpath(evalString));
+
+ nodes = userRes.get()->getNodeSet();
}
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [myserver-commit] [2757] Static size buffers were replaced with std:: string and some memory leaks were fixed,
Giuseppe Scrivano <=