summaryrefslogtreecommitdiffstats
path: root/sesman/config.c
diff options
context:
space:
mode:
authorilsimo <ilsimo>2005-10-23 21:47:17 +0000
committerilsimo <ilsimo>2005-10-23 21:47:17 +0000
commite7dbdea767e3478c9255b15c3fe6f928f253c438 (patch)
treed42b4ae832f1cdbacf0ac510b52a1065b4ee0b37 /sesman/config.c
parent4e8b16669ec451ec73d05c51defc3982267da892 (diff)
downloadxrdp-proprietary-e7dbdea767e3478c9255b15c3fe6f928f253c438.tar.gz
xrdp-proprietary-e7dbdea767e3478c9255b15c3fe6f928f253c438.zip
Adding logging functions and adding log options in config files
Diffstat (limited to 'sesman/config.c')
-rw-r--r--sesman/config.c120
1 files changed, 97 insertions, 23 deletions
diff --git a/sesman/config.c b/sesman/config.c
index a42e3d03..c58daed1 100644
--- a/sesman/config.c
+++ b/sesman/config.c
@@ -24,16 +24,26 @@
#include "sesman.h"
/******************************************************************************/
+static int text2bool(char* s)
+{
+ if (0 == g_strncasecmp(s, "1", 1) ||
+ 0 == g_strncasecmp(s, "true", 4) ||
+ 0 == g_strncasecmp(s, "yes", 3))
+ {
+ return 1;
+ }
+ return 0;
+}
+
+/******************************************************************************/
/* returns error */
int DEFAULT_CC
-config_read(struct sesman_config* cfg)
+config_read(struct config_sesman* cfg)
{
- int i;
int fd;
struct list* sec;
struct list* param_n;
struct list* param_v;
- char* buf;
fd = g_file_open(SESMAN_CFG_FILE);
if (-1 == fd)
@@ -41,7 +51,7 @@ config_read(struct sesman_config* cfg)
g_printf("sesman: error reading config: %s\n\r", SESMAN_CFG_FILE);
return 1;
}
- g_memset(cfg, 0, sizeof(struct sesman_config));
+ g_memset(cfg, 0, sizeof(struct config_sesman));
sec = list_create();
sec->auto_free = 1;
file_read_sections(fd, sec);
@@ -49,41 +59,105 @@ config_read(struct sesman_config* cfg)
param_n->auto_free = 1;
param_v = list_create();
param_v->auto_free = 1;
- file_read_section(fd, SESMAN_CFG_GLOBALS, param_n, param_v);
+
+ /* read global config */
+ config_read_globals(fd, cfg, param_n, param_v);
+
+ /* read logging config */
+ config_read_logging(fd, &(cfg->log), param_n, param_v);
+
+ /* cleanup */
+ list_delete(sec);
+ list_delete(param_v);
+ list_delete(param_n);
+ return 0;
+}
+
+int DEFAULT_CC
+config_read_globals(int file, struct config_sesman* cf, struct list* param_n, struct list* param_v)
+{
+ int i;
+ char* buf;
+
+ list_clear(param_v);
+ list_clear(param_n);
+
+ file_read_section(file, SESMAN_CFG_GLOBALS, param_n, param_v);
for (i = 0; i < param_n->count; i++)
{
buf = (char*)list_get_item(param_n, i);
if (0 == g_strncasecmp(buf, SESMAN_CFG_DEFWM, 20))
{
- g_strncpy(cfg->default_wm, (char*)list_get_item(param_v, i), 31);
+ g_strncpy(cf->default_wm, (char*)list_get_item(param_v, i), 31);
}
else if (0 == g_strncasecmp(buf, SESMAN_CFG_USERWM, 20))
{
- g_strncpy(cfg->user_wm, (char*)list_get_item(param_v, i), 31);
+ g_strncpy(cf->user_wm, (char*)list_get_item(param_v, i), 31);
}
else if (0 == g_strncasecmp(buf, SESMAN_CFG_ENABLE_USERWM, 20))
{
- buf = (char*)list_get_item(param_v, i);
- if (0 == g_strncasecmp(buf, "1", 1) ||
- 0 == g_strncasecmp(buf, "true", 4) ||
- 0 == g_strncasecmp(buf, "yes", 3))
- {
- cfg->enable_user_wm = 1;
- }
+ cf->enable_user_wm = text2bool((char*) list_get_item(param_v, i));
}
else if (0 == g_strncasecmp(buf, SESMAN_CFG_PORT, 20))
{
- g_strncpy(cfg->listen_port, (char*)list_get_item(param_v, i), 15);
+ g_strncpy(cf->listen_port, (char*)list_get_item(param_v, i), 15);
}
}
+
g_printf("sesman config:\n\r");
- g_printf("\tListenPort: %s\n\r", cfg->listen_port);
- g_printf("\tEnableUserWindowManager: %i\n\r", cfg->enable_user_wm);
- g_printf("\tUserWindowManager: %s\n\r", cfg->user_wm);
- g_printf("\tDefaultWindowManager: %s\n\r", cfg->default_wm);
- /* cleanup */
- list_delete(sec);
- list_delete(param_v);
- list_delete(param_n);
+ g_printf("\tListenPort: %s\n\r", cf->listen_port);
+ g_printf("\tEnableUserWindowManager: %i\n\r", cf->enable_user_wm);
+ g_printf("\tUserWindowManager: %s\n\r", cf->user_wm);
+ g_printf("\tDefaultWindowManager: %s\n\r", cf->default_wm);
+
+ return 0;
+}
+
+int DEFAULT_CC
+config_read_logging(int file, struct log_config* lc, struct list* param_n, struct list* param_v)
+{
+ int i;
+ char* buf;
+
+ list_clear(param_v);
+ list_clear(param_n);
+
+ /* setting defaults */
+ lc->program_name = g_strdup("sesman");
+ lc->log_file = 0;
+ lc->fd = 0;
+ lc->log_level = LOG_LEVEL_DEBUG;
+ lc->enable_syslog = 0;
+ lc->syslog_level = LOG_LEVEL_DEBUG;
+
+ file_read_section(file, SESMAN_CFG_LOGGING, param_n, param_v);
+ for (i = 0; i < param_n->count; i++)
+ {
+ buf = (char*)list_get_item(param_n, i);
+ if (0 == g_strncasecmp(buf, SESMAN_CFG_LOG_FILE, 20))
+ {
+ lc->log_file = g_strdup((char*)list_get_item(param_v, i));
+ }
+ if (0 == g_strncasecmp(buf, SESMAN_CFG_LOG_LEVEL, 20))
+ {
+ lc->log_level = log_text2level((char*)list_get_item(param_v, i));
+ }
+ if (0 == g_strncasecmp(buf, SESMAN_CFG_LOG_ENABLE_SYSLOG, 20))
+ {
+ lc->enable_syslog = text2bool((char*)list_get_item(param_v, i));
+ }
+ if (0 == g_strncasecmp(buf, SESMAN_CFG_LOG_SYSLOG_LEVEL, 20))
+ {
+ lc->syslog_level = log_text2level((char*)list_get_item(param_v, i));
+ }
+ }
+
+ g_printf("logging configuration:\n\r");
+ g_printf("\tLogFile: %s\n\r",lc->log_file);
+ g_printf("\tLogLevel: %i\n\r", lc->log_level);
+ g_printf("\tEnableSyslog: %i\n\r", lc->enable_syslog);
+ g_printf("\tSyslogLevel: %i\n\r", lc->syslog_level);
+
return 0;
}
+