Command line option parsing, configuration parsing
Made config file parsing a bit more fool proof Config file can now contain a modules-dir element that holds the location of the DSO's Prepared module loading function to be able to dry-run Removed some unneeded header files Added command line options parsing
This commit is contained in:
@@ -10,13 +10,18 @@
|
||||
#include "modules.h"
|
||||
|
||||
int
|
||||
wxmppd_processConfigfile(const char *file, int startup)
|
||||
wxmppd_processConfigfile(const char *file, int startup, wxmppd_config_t **config)
|
||||
{
|
||||
xmlDocPtr doc;
|
||||
xmlXPathContextPtr xpathCtx;
|
||||
xmlXPathObjectPtr xpathObject;
|
||||
int i;
|
||||
|
||||
if (config)
|
||||
{
|
||||
*config = g_new0(wxmppd_config_t, 1);
|
||||
}
|
||||
|
||||
if ((doc = xmlParseFile(file)) == NULL)
|
||||
{
|
||||
printf("Config file error!\n");
|
||||
@@ -31,24 +36,60 @@ wxmppd_processConfigfile(const char *file, int startup)
|
||||
return WXMPPD_CONFIG_BADFILE;
|
||||
}
|
||||
|
||||
printf("%d nodes found.\n", xpathObject->nodesetval->nodeNr);
|
||||
for (i = 0; i < xpathObject->nodesetval->nodeNr; i++)
|
||||
if (xpathObject->nodesetval)
|
||||
{
|
||||
xmlNodePtr textNode;
|
||||
|
||||
if (xmlChildElementCount(xpathObject->nodesetval->nodeTab[i]) > 0)
|
||||
for (i = 0; i < xpathObject->nodesetval->nodeNr; i++)
|
||||
{
|
||||
printf("Config file error! modules/load elements cannot have children!\n");
|
||||
xmlXPathFreeContext(xpathCtx);
|
||||
xmlNodePtr textNode;
|
||||
|
||||
if (xmlChildElementCount(xpathObject->nodesetval->nodeTab[i]) > 0)
|
||||
{
|
||||
printf("Config file error! modules/load elements cannot have children!\n");
|
||||
xmlXPathFreeContext(xpathCtx);
|
||||
xmlXPathFreeObject(xpathObject);
|
||||
return WXMPPD_CONFIG_BADFILE;
|
||||
}
|
||||
|
||||
wxmppd_loadModule(xpathObject->nodesetval->nodeTab[i]->children->content, (config == NULL));
|
||||
}
|
||||
}
|
||||
|
||||
xmlXPathFreeObject(xpathObject);
|
||||
|
||||
if ((xpathObject = xmlXPathEvalExpression("/wxmppd/modules/module-dir", xpathCtx)) == NULL)
|
||||
{
|
||||
printf("Config file error during xpath!\n");
|
||||
xmlXPathFreeContext(xpathCtx);
|
||||
return WXMPPD_CONFIG_BADFILE;
|
||||
}
|
||||
|
||||
if (xpathObject->nodesetval)
|
||||
{
|
||||
if (xpathObject->nodesetval->nodeNr > 1)
|
||||
{
|
||||
printf("Config file cannot contain more than one module-dir definition!\n");
|
||||
xmlXPathFreeObject(xpathObject);
|
||||
xmlXPathFreeContext(xpathCtx);
|
||||
return WXMPPD_CONFIG_BADFILE;
|
||||
}
|
||||
else if (xpathObject->nodesetval->nodeNr == 1)
|
||||
{
|
||||
if (xmlChildElementCount(xpathObject->nodesetval->nodeTab[0]) > 0)
|
||||
{
|
||||
printf("Config file error! modules/load elements cannot have children!\n");
|
||||
xmlXPathFreeContext(xpathCtx);
|
||||
xmlXPathFreeObject(xpathObject);
|
||||
return WXMPPD_CONFIG_BADFILE;
|
||||
}
|
||||
|
||||
wxmppd_loadModule(xpathObject->nodesetval->nodeTab[i]->children->content);
|
||||
if (config)
|
||||
{
|
||||
(*config)->modules_dir = g_strdup(xpathObject->nodesetval->nodeTab[0]->children->content);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
xmlXPathFreeContext(xpathCtx);
|
||||
xmlXPathFreeObject(xpathObject);
|
||||
|
||||
return WXMPPD_CONFIG_SUCCESS;
|
||||
}
|
||||
|
Reference in New Issue
Block a user