Created configuration data processing routines; bug fix

Configuration objects can now be copied and freed.
Fixed a bug that wanted to load a module before the modules directory would be set

Signed-off-by: Gergely Polonkai (W00d5t0ck) <polesz@w00d5t0ck.info>
This commit is contained in:
Gergely Polonkai (W00d5t0ck) 2011-01-26 17:53:33 +01:00
parent 55ba26f645
commit c39c378289
2 changed files with 98 additions and 5 deletions

View File

@ -1,8 +1,22 @@
/* wXMPPd - (Trying to be) full featured XMPP daemon
* Copyright (C) 2011 Gergely Polonkai
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#if (HAVE_MMAP == 1)
# include <mman.h>
# include <unistd.h>
#endif
#include <glib.h>
#include <libxml/parser.h>
#include <libxml/xpath.h>
@ -50,7 +64,10 @@ wxmppd_processConfigfile(const char *file, int startup, wxmppd_config_t **config
return WXMPPD_CONFIG_BADFILE;
}
wxmppd_loadModule(xpathObject->nodesetval->nodeTab[i]->children->content, (config == NULL));
if (config)
{
(*config)->modules_to_load = g_slist_append((*config)->modules_to_load, g_strdup(xpathObject->nodesetval->nodeTab[i]->children->content));
}
}
}
@ -94,3 +111,57 @@ wxmppd_processConfigfile(const char *file, int startup, wxmppd_config_t **config
return WXMPPD_CONFIG_SUCCESS;
}
wxmppd_config_t *
wxmppd_copyConfig(wxmppd_config_t *src)
{
wxmppd_config_t *temp;
temp = g_new0(wxmppd_config_t, 1);
if (src->modules_dir != NULL)
{
temp->modules_dir = g_strdup(src->modules_dir);
}
if (src->modules_to_load)
{
guint i;
temp->modules_to_load = NULL;
for (i = 0; i < g_slist_length(src->modules_to_load); i++)
{
temp->modules_to_load = g_slist_append(temp->modules_to_load, g_strdup(g_slist_nth(src->modules_to_load, i)->data));
}
}
return temp;
}
static void
free_slist_data_cb(gpointer data, gpointer user_data)
{
g_free(data);
}
void
wxmppd_freeConfig(wxmppd_config_t **config)
{
if (*config)
{
if ((*config)->modules_dir)
{
g_free((*config)->modules_dir);
}
if ((*config)->modules_to_load)
{
g_slist_foreach((*config)->modules_to_load, free_slist_data_cb, NULL);
g_slist_free((*config)->modules_to_load);
}
g_free(*config);
}
*config = NULL;
}

View File

@ -1,6 +1,25 @@
/* wXMPPd - (Trying to be) full featured XMPP daemon
* Copyright (C) 2011 Gergely Polonkai
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __WXMPPD_CONFIGFILES_H
# define __WXMPPD_CONFIGFILES_H
#include <glib.h>
enum {
WXMPPD_CONFIG_SUCCESS = 0,
WXMPPD_CONFIG_BADFILE,
@ -8,9 +27,12 @@ enum {
typedef struct _wxmppd_config_t {
char *modules_dir;
GSList *modules_to_load;
} wxmppd_config_t;
int wxmppd_processConfigfile(const char *file, int startup, wxmppd_config_t **config);
wxmppd_config_t *wxmppd_copyConfig(wxmppd_config_t *src);
void wxmppd_freeConfig(wxmppd_config_t **config);
#endif /* __WXMPPD_CONFIGFILES_H */