Initial version

This commit is contained in:
Gergely Polonkai (W00d5t0ck)
2011-01-25 15:51:07 +01:00
commit 5cc379461a
16 changed files with 1218 additions and 0 deletions

3
src/Makefile.am Normal file
View File

@@ -0,0 +1,3 @@
bin_PROGRAMS = wxmppd
wxmppd_SOURCES = wxmppd.c configfiles.c modules.c
AM_CPPFLAGS = -DSYSCONFDIR='"$(sysconfdir)"' -DLIBDIR='"$(libdir)"'

55
src/configfiles.c Normal file
View File

@@ -0,0 +1,55 @@
#include <stdio.h>
#if (HAVE_MMAP == 1)
# include <mman.h>
# include <unistd.h>
#endif
#include <libxml/parser.h>
#include <libxml/xpath.h>
#include "configfiles.h"
#include "modules.h"
int
wxmppd_processConfigfile(const char *file, int startup)
{
xmlDocPtr doc;
xmlXPathContextPtr xpathCtx;
xmlXPathObjectPtr xpathObject;
int i;
if ((doc = xmlParseFile(file)) == NULL)
{
printf("Config file error!\n");
return WXMPPD_CONFIG_BADFILE;
}
xpathCtx = xmlXPathNewContext(doc);
if ((xpathObject = xmlXPathEvalExpression("/wxmppd/modules/load", xpathCtx)) == NULL)
{
printf("Config file error during xpath!\n");
xmlXPathFreeContext(xpathCtx);
return WXMPPD_CONFIG_BADFILE;
}
printf("%d nodes found.\n", xpathObject->nodesetval->nodeNr);
for (i = 0; i < xpathObject->nodesetval->nodeNr; i++)
{
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);
}
xmlXPathFreeContext(xpathCtx);
xmlXPathFreeObject(xpathObject);
return WXMPPD_CONFIG_SUCCESS;
}

12
src/configfiles.h Normal file
View File

@@ -0,0 +1,12 @@
#ifndef __WXMPPD_CONFIGFILES_H
# define __WXMPPD_CONFIGFILES_H
enum {
WXMPPD_CONFIG_SUCCESS = 0,
WXMPPD_CONFIG_BADFILE,
};
int wxmppd_processConfigfile(const char *file, int startup);
#endif /* __WXMPPD_CONFIGFILES_H */

10
src/modules.c Normal file
View File

@@ -0,0 +1,10 @@
#include <stdio.h>
#include "modules.h"
int
wxmppd_loadModule(char *moduleName)
{
printf("Will load module %s\n", moduleName);
}

1
src/modules.h Normal file
View File

@@ -0,0 +1 @@
int wxmppd_loadModule(char *moduleName);

27
src/wxmppd.c Normal file
View File

@@ -0,0 +1,27 @@
#define CONFIG_DIR "/home/polesz/Projektek/wxmppd/data"
#include <stdio.h>
#include <sys/types.h>
#include <dirent.h>
#include <errno.h>
#include <libxml/parser.h>
#include "configfiles.h"
char *config_dir = NULL;
int
main(int argc, char **argv)
{
xmlInitParser();
LIBXML_TEST_VERSION;
printf("%s\n", SYSCONFDIR);
wxmppd_processConfigfile(CONFIG_DIR "/wxmppd.xml", 1);
xmlCleanupParser();
return 0;
}