summaryrefslogtreecommitdiffstats
path: root/server/parser
diff options
context:
space:
mode:
Diffstat (limited to 'server/parser')
-rw-r--r--server/parser/configparser.c16
-rw-r--r--server/parser/configparser.h2
-rw-r--r--server/parser/rteval_parserd.c16
3 files changed, 25 insertions, 9 deletions
diff --git a/server/parser/configparser.c b/server/parser/configparser.c
index 88c7ae3..6d5e84a 100644
--- a/server/parser/configparser.c
+++ b/server/parser/configparser.c
@@ -106,8 +106,8 @@ static inline eurephiaVALUES *parse_config_line(LogContext *log, const char *lin
}
-static inline eurephiaVALUES *default_cfg_values(LogContext *log) {
- eurephiaVALUES *cfg = NULL;
+static inline eurephiaVALUES *default_cfg_values(LogContext *log, eurephiaVALUES *prgargs) {
+ eurephiaVALUES *cfg = NULL, *ptr = NULL;
cfg = eCreate_value_space(log, 20);
eAdd_value(cfg, "datadir", "/var/lib/rteval");
@@ -119,6 +119,11 @@ static inline eurephiaVALUES *default_cfg_values(LogContext *log) {
eAdd_value(cfg, "db_password", "rtevaldb_parser");
eAdd_value(cfg, "reportdir", "/var/lib/rteval/reports");
+ // Copy over the arguments to the config, update existing settings
+ for( ptr = prgargs; ptr; ptr = ptr->next ) {
+ eUpdate_value(cfg, ptr->key, ptr->val, 1);
+ }
+
return cfg;
}
@@ -131,13 +136,14 @@ static inline eurephiaVALUES *default_cfg_values(LogContext *log) {
* @return Returns a pointer to an eurephiaVALUES stack containing the configuration on success,
* otherwise NULL.
*/
-eurephiaVALUES *read_config(LogContext *log, const char *cfgname, const char *section) {
+eurephiaVALUES *read_config(LogContext *log, eurephiaVALUES *prgargs, const char *section) {
FILE *fp = NULL;
- char *buf = NULL, *sectmatch = NULL;
+ char *buf = NULL, *sectmatch = NULL, *cfgname = NULL;
int sectfound = 0;
eurephiaVALUES *cfg = NULL;
struct stat fi;
+ cfgname = eGet_value(prgargs, "configfile");
if( stat(cfgname, &fi) == -1 ) {
writelog(log, LOG_EMERG, "Could not open the config file: %s", cfgname);
return NULL;
@@ -152,7 +158,7 @@ eurephiaVALUES *read_config(LogContext *log, const char *cfgname, const char *se
sectmatch = (char *) malloc_nullsafe(log, strlen_nullsafe(section)+4);
sprintf(sectmatch, "[%s]", section);
- cfg = default_cfg_values(log);
+ cfg = default_cfg_values(log, prgargs);
writelog(log, LOG_DEBUG, "Reading config file: %s", cfgname);
while( fgets(buf, fi.st_size, fp) != NULL ) {
if( strncmp(buf, "[", 1) == 0 ) {
diff --git a/server/parser/configparser.h b/server/parser/configparser.h
index a047d83..54a904b 100644
--- a/server/parser/configparser.h
+++ b/server/parser/configparser.h
@@ -33,6 +33,6 @@
#ifndef _CONFIGPARSER_H
#define _CONFIGPARSER_H
-eurephiaVALUES *read_config(LogContext *log, const char *cfgname, const char *section);
+eurephiaVALUES *read_config(LogContext *log, eurephiaVALUES *prgargs, const char *section);
#endif
diff --git a/server/parser/rteval_parserd.c b/server/parser/rteval_parserd.c
index 6821d34..fa73458 100644
--- a/server/parser/rteval_parserd.c
+++ b/server/parser/rteval_parserd.c
@@ -37,6 +37,7 @@
#include <pgsql.h>
#include <threadinfo.h>
#include <parsethread.h>
+#include <argparser.h>
#define DEFAULT_MSG_MAX 5 /**< Default size of the message queue */
#define XMLPARSER_XSL "xmlparser.xsl" /**< rteval report parser XSLT, parses XML into database friendly data*/
@@ -179,7 +180,7 @@ int process_submission_queue(dbconn *dbc, mqd_t msgq) {
* @return Returns the result of the process_submission_queue() function.
*/
int main(int argc, char **argv) {
- eurephiaVALUES *config = NULL;
+ eurephiaVALUES *config = NULL, *prgargs = NULL;
char xsltfile[2050], *reportdir = NULL;
xsltStylesheet *xslt = NULL;
dbconn *dbc = NULL;
@@ -195,16 +196,25 @@ int main(int argc, char **argv) {
xsltInit();
xmlInitParser();
+ prgargs = parse_arguments(argc, argv);
+ if( prgargs == NULL ) {
+ fprintf(stderr, "** ERROR ** Failed to parse program arguments\n");
+ rc = 2;
+ goto exit;
+ }
+
// Setup a log context
- logctx = init_log(NULL, LOG_NOTICE);
+ logctx = init_log(eGet_value(prgargs, "log"), eGet_value(prgargs, "loglevel"));
if( !logctx ) {
fprintf(stderr, "** ERROR ** Could not setup a log context\n");
+ eFree_values(prgargs);
rc = 2;
goto exit;
}
// Fetch configuration
- config = read_config(logctx, "/etc/rteval.conf", "xmlrpc_parser");
+ config = read_config(logctx, prgargs, "xmlrpc_parser");
+ eFree_values(prgargs); // read_config() copies prgargs into config, we don't need prgargs anymore
// Parse XSLT template
snprintf(xsltfile, 512, "%s/%s", eGet_value(config, "xsltpath"), XMLPARSER_XSL);