summaryrefslogtreecommitdiff
path: root/agni.c
diff options
context:
space:
mode:
Diffstat (limited to 'agni.c')
-rw-r--r--agni.c92
1 files changed, 75 insertions, 17 deletions
diff --git a/agni.c b/agni.c
index a5b0014..1ff1c1a 100644
--- a/agni.c
+++ b/agni.c
@@ -20,6 +20,7 @@
#include "config_servers.h"
#include "config_cmds.h"
+#include "config_load.h"
#include "darray.h"
#include "buf.h"
@@ -31,11 +32,38 @@
#include "irc_parse.h"
#include "mmm.h"
+#include "arg.h"
+
/*
no defence programming, no error checking, no argument checking just PoC
nothing else
*/
+/*
+Define command line arguments
+*/
+
+s_arg_val arg_config_filename =
+{
+ .ptr = "config/servers.ini",
+ .default_ptr = "config/servers.ini",
+ .result = NULL
+};
+
+def_arg agni_cmd_args[] =
+{
+ ARG_ENTRY("-c",VAL,&arg_config_filename,"ini config file"),
+ {NULL,0,NULL}
+};
+
+arg_t *cfg = NULL;
+
+/*
+configuration variables
+*/
+
+config_ini *config=NULL;
+
#define MQ_MSG_SIZE 8192
//HACK
@@ -138,7 +166,7 @@ typedef struct server_cfg
char *user;
char *password;
char *server; //should be changed to hostname?
- char **channels;
+ char *channels[SERV_CHAN_MAX_NUM];
char *port;
int ssl;
} server_cfg;
@@ -469,6 +497,7 @@ int th_start_client(void *data)
while (cfg->channels[iter]!=NULL)
{
chan_name = cfg->channels[iter];
+ printf("%s\n",chan_name);
if ((strncmp(chan_name,sep_chan,strlen(chan_name))==0)
&& (strlen(sep_chan)==strlen(chan_name)))
{
@@ -641,6 +670,8 @@ int th_event_manager(void *data)
PERM();
}
+
+
//load predefined/precompiled command list
{
single_cmd_def *single_cmd = confgi_cmd_list;
@@ -837,7 +868,7 @@ as a watch dog.
*******************************************************************************/
int main(int argc, char **argv)
{
- int i;
+ int i,j;
int cnt_servers,cnt_running;
server_cfg *cfg_list;
@@ -847,11 +878,19 @@ int main(int argc, char **argv)
/*set atomic variables to init value*/
atomic_store(&_glbl_id, 0);
+
+ /*Load configs*/
+ cfg = arg_load(argc, argv, agni_cmd_args);
+
+ config_load_ini(arg_config_filename.result->ptr, &config);
+ printf("%s\n",arg_config_filename.result->ptr);
+
/* Load configuration */
- cnt_servers = SIZEOF_SERVER_LIST;
- for (i=0;i<SIZEOF_SERVER_LIST;i++)
+ cnt_servers = config_server_num(config);
+ if (cnt_servers == 0)
{
- printf("Load config for server %s\n",server_list[i].server);
+ printf("No configured servers to load\n");
+ return 0;
}
cfg_list = malloc(sizeof(server_cfg)*cnt_servers);
@@ -859,31 +898,50 @@ int main(int argc, char **argv)
{
ENL();
}
+ memset(cfg_list, 0, sizeof(server_cfg)*cnt_servers);
+
mq_array = malloc(sizeof(mq_ntf_mdt)*cnt_servers);
if (mq_array == NULL)
{
ENL();
}
+
/* For each configuration create listener */
- for (i=0;i<SIZEOF_SERVER_LIST;i++)
+ for (i=0;i<cnt_servers;i++)
{
/*initialise server config*/
- server_cfg *srvc = cfg_list+i;
- irc_server_conf *isrvc = &server_list[i];
+ server_cfg *srvc = &cfg_list[i];
+ //irc_server_conf *isrvc = &server_list[i];
+ irc_server_conf isrvc;
+
+ memset(&isrvc, 0, sizeof(irc_server_conf));
+ config_get_irc_config(config, i, &isrvc); //well there is no free structure so you gona get memleaks here =P in isrvc
+
srvc->tid = i;
srvc->stack = malloc(STACK_SIZE); //NULL will brake everything ;)
if (srvc->stack == NULL)
{
ERROR("BLow");
}
- srvc->user = isrvc->user;
- srvc->password = isrvc->password;
- srvc->server = isrvc->server;
- srvc->channels = isrvc->channels;
- srvc->port = isrvc->port;
- srvc->ssl = isrvc->ssl;
+ srvc->user = alloc_new_str(isrvc.user);
+ //srvc->password = alloc_new_str(isrvc.password);
+ srvc->server = alloc_new_str(isrvc.server);
+ srvc->port = alloc_new_str(isrvc.port);
+ srvc->ssl = isrvc.ssl;
+ //srvc->channels = isrvc.channels;
+ for (j=0;j<SERV_CHAN_MAX_NUM;j++)
+ {
+ if (isrvc.channels[j])
+ {
+ srvc->channels[j] = alloc_new_str(isrvc.channels[j]);
+ } else
+ {
+ srvc->channels[j] = NULL;
+ }
+ }
+ free_irc_server_conf(&isrvc);
//atomic_init( &srvc->running, 1);
atomic_store(&srvc->running, 0);
@@ -904,11 +962,11 @@ int main(int argc, char **argv)
}
/* event handler thread */
- evhnd_cfg = malloc(sizeof(event_handler_cfg));
+ evhnd_cfg = malloc(sizeof(event_handler_cfg));
memset(evhnd_cfg, 0, sizeof(event_handler_cfg));
- evhnd_cfg->stack = malloc(EVENT_HND_STACK_SIZE);
+ evhnd_cfg->stack = malloc(EVENT_HND_STACK_SIZE);
atomic_store(&evhnd_cfg->running, 0);
- evhnd_cfg->mq_num = cnt_servers;
+ evhnd_cfg->mq_num = cnt_servers;
evhnd_cfg->mq_listen = mq_array;
clone(th_event_manager, evhnd_cfg->stack+EVENT_HND_STACK_SIZE, CLONE_VM|CLONE_FILES, (void *)evhnd_cfg);