[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[myserver-commit] [2750] Use XPath to look for the specified error file
From: |
Giuseppe Scrivano |
Subject: |
[myserver-commit] [2750] Use XPath to look for the specified error file |
Date: |
Thu, 14 Aug 2008 19:52:44 +0000 |
Revision: 2750
http://svn.sv.gnu.org/viewvc/?view=rev&root=myserver&revision=2750
Author: gscrivano
Date: 2008-08-14 19:52:43 +0000 (Thu, 14 Aug 2008)
Log Message:
-----------
Use XPath to look for the specified error file
Modified Paths:
--------------
trunk/myserver/include/xml_parser.h
trunk/myserver/src/security.cpp
trunk/myserver/src/security_cache.cpp
Modified: trunk/myserver/include/xml_parser.h
===================================================================
--- trunk/myserver/include/xml_parser.h 2008-08-14 16:28:58 UTC (rev 2749)
+++ trunk/myserver/include/xml_parser.h 2008-08-14 19:52:43 UTC (rev 2750)
@@ -93,6 +93,7 @@
time_t getLastModTime();
XmlXPathResult* evaluateXpath(const char*);
+ bool isXpathEnabled(){return useXpath;}
private:
xmlXPathContextPtr xpathCtx;
bool useXpath;
Modified: trunk/myserver/src/security.cpp
===================================================================
--- trunk/myserver/src/security.cpp 2008-08-14 16:28:58 UTC (rev 2749)
+++ trunk/myserver/src/security.cpp 2008-08-14 19:52:43 UTC (rev 2750)
@@ -60,14 +60,19 @@
*Return -1 on errors.
*Return other valus on success.
*/
-int SecurityManager::getErrorFileName(const char* sysDir,int error,
- string &out, XmlParser* parser)
+int SecurityManager::getErrorFileName(const char* sysDir,
+ int error,
+ string &out,
+ XmlParser* parser)
{
- xmlNode *node;
ostringstream permissionsFile;
XmlParser localParser;
- xmlDocPtr doc;
- bool found = 0;
+
+ char evalString[64];
+ XmlXPathResult* xpathRes;
+ xmlNodeSetPtr nodes;
+
+
out.assign("");
if(parser == 0)
{
@@ -76,68 +81,30 @@
{
return 0;
}
- if(localParser.open(permissionsFile.str().c_str()) == -1 )
+ if(localParser.open(permissionsFile.str().c_str(), true) == -1 )
return -1;
- doc=localParser.getDoc();
}
else
{
- doc=parser->getDoc();
+ if(!parser->isXpathEnabled())
+ return 0;
}
- if(doc == 0)
- {
- if(parser == 0)
- localParser.close();
- return 0;
- }
- node = doc->children->children;
+ sprintf(evalString, "/SECURITY/address@hidden'%d\']/@FILE", error);
+ xpathRes = parser->evaluateXpath(evalString);
+ nodes = xpathRes->getNodeSet();
- if(node == 0)
- {
- if(parser == 0)
- localParser.close();
- return 0;
- }
+ if(nodes && nodes->nodeNr)
+ out.assign((const char*)nodes->nodeTab[0]->content);
- while(node)
- {
- if(!xmlStrcmp(node->name, (const xmlChar *)"ERROR"))
- {
- xmlAttr *attr = node->properties;
- char *fileName = 0;
- while(attr)
- {
- if(!xmlStrcmp(attr->name, (const xmlChar *)"FILE"))
- {
- fileName = (char*)attr->children->content;
- }
- else if(!xmlStrcmp(attr->name, (const xmlChar *)"ID"))
- {
- int errorId;
- errorId = atoi((const char*)attr->children->content);
- if(errorId == error)
- found = true;
- else
- break;
- }
- attr = attr->next;
- }
+ if(xpathRes)
+ delete xpathRes;
- /* The error ID is correct. */
- if(found)
- {
- out.assign(fileName);
- break;
- }
- }
- node = node->next;
- }
if(parser == 0)
localParser.close();
/* Return 1 if both it was found and well configured. */
- if(found && out.length())
+ if(nodes && nodes->nodeNr && out.length())
return 1;
return 0;
@@ -222,7 +189,7 @@
}
else
{
- if(localParser.open(permissionsFile.str().c_str()) == -1)
+ if(localParser.open(permissionsFile.str().c_str(), true) == -1)
{
return -1;
}
Modified: trunk/myserver/src/security_cache.cpp
===================================================================
--- trunk/myserver/src/security_cache.cpp 2008-08-14 16:28:58 UTC (rev
2749)
+++ trunk/myserver/src/security_cache.cpp 2008-08-14 19:52:43 UTC (rev
2750)
@@ -185,7 +185,7 @@
(parser->getLastModTime() != fileModTime))
{
parser->close();
- if(parser->open(permissionFile.c_str()) == -1)
+ if(parser->open(permissionFile.c_str(), true) == -1)
{
dictionary.remove(permissionFile.c_str());
return -1;
@@ -213,7 +213,7 @@
delete toremove;
}
- if(parser->open(permissionFile.c_str()) == -1)
+ if(parser->open(permissionFile.c_str(), true) == -1)
return -1;
old = dictionary.put(permissionFile, parser);
@@ -256,7 +256,7 @@
(parser->getLastModTime() != fileModTime))
{
parser->close();
- if(parser->open(permissionFile.c_str()) == -1)
+ if(parser->open(permissionFile.c_str(), true) == -1)
{
dictionary.remove(permissionFile.c_str());
return -1;
@@ -284,7 +284,7 @@
delete toremove;
}
- if(parser->open(permissionFile.c_str()) == -1)
+ if(parser->open(permissionFile.c_str(), true) == -1)
return -1;
old = dictionary.put(permissionFile, parser);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [myserver-commit] [2750] Use XPath to look for the specified error file,
Giuseppe Scrivano <=