aboutsummaryrefslogtreecommitdiffstats
path: root/agni.c
diff options
context:
space:
mode:
authorFreeArtMan <dos21h@gmail.com>2017-05-02 22:30:10 +0100
committerFreeArtMan <dos21h@gmail.com>2017-05-02 22:30:10 +0100
commitc6f5689838de263b8129b7c612cde030617ce780 (patch)
treec533fd036ebf6441bf98694367f2f378f1d399ef /agni.c
parent5f5d5837c9d662ce00c2fdad5b963eff6551d21c (diff)
downloadagni-c6f5689838de263b8129b7c612cde030617ce780.tar.gz
agni-c6f5689838de263b8129b7c612cde030617ce780.zip
Move commands to seperate files
Diffstat (limited to 'agni.c')
-rw-r--r--agni.c99
1 files changed, 23 insertions, 76 deletions
diff --git a/agni.c b/agni.c
index 1bf6799..9d3b37d 100644
--- a/agni.c
+++ b/agni.c
@@ -18,6 +18,7 @@
#include <mqueue.h>
#include "config_servers.h"
+#include "config_cmds.h"
#include "darray.h"
#include "buf.h"
@@ -39,44 +40,6 @@ nothing else
//HACK
extern int __irc_buf_drain_io(irc_buf *ib);
-void *cmd_pong(void *data)
-{
- char *param = (char *)data;
- char *ret = NULL;
-
- printf("PONG\n");
-
- ret = alloc_new_str("PONG");
-
- return ret;
-}
-
-void *cmd_uptime(void *data)
-{
- char *param = (char *)data;
- char *ret = NULL;
-
- printf("UPTIME\n");
-
- ret = alloc_new_str("UpTime is infinite\n");
-
- return ret;
-}
-
-void *cmd_date(void *data)
-{
- char *param = (char *)data;
- char *ret = NULL;
-
- printf("DATE\n");
-
- ret = alloc_new_str("I dont whant to date with you\n");
-
- return ret;
-}
-
-
-
/*
Wrap call back, to manage how going be executed callback.
Manage input and output params for callback.
@@ -401,6 +364,7 @@ int th_start_client(void *data)
//for now just remove command without checkings its state
tbl_qcmd_del_by_id(qtbl, cmd_id); //no error check
+ //NOT BEST PLACE WHERE TO CALL THIS FUNCTION
//should be added proper command state check and so on
tbl_qcmd_mng_states(qtbl); // This should be runed regulary
}
@@ -602,7 +566,7 @@ int th_event_manager(void *data)
struct mq_attr out_attr, *ptr_out_attr=&out_attr;
//execution and command table generation
- tble_exec *ecmd = NULL;
+ //tble_exec *ecmd = NULL;
tbl_exec *etbl = NULL;
tble_qcmd *qcmd = NULL;
tbl_qcmd *qtbl = NULL;
@@ -614,49 +578,32 @@ int th_event_manager(void *data)
PERM();
}
- ecmd = tbl_exec_c();
- if (ecmd == NULL)
+ //load predefined/precompiled command list
{
- PERM();
- }
- ecmd->id = uniq_id();
- ecmd->name = alloc_new_str("local-executor");
- ecmd->cmd = alloc_new_str("PING");
- ecmd->callback = cmd_pong;
+ single_cmd_def *single_cmd = confgi_cmd_list;
- if (-1 == tbl_exec_add(etbl, ecmd))
- {
- PERM();
- }
+ while ((single_cmd!=NULL)&&(single_cmd->name!=NULL))
+ {
+ tble_exec *ecmd = NULL;
- ecmd = tbl_exec_c();
- if (ecmd == NULL)
- {
- PERM();
- }
- ecmd->id = uniq_id();
- ecmd->name = alloc_new_str("local-executor");
- ecmd->cmd = alloc_new_str("DATE");
- ecmd->callback = cmd_date;
+ ecmd = tbl_exec_c();
+ if (ecmd == NULL)
+ {
+ PERM();
+ }
- if (-1 == tbl_exec_add(etbl, ecmd))
- {
- PERM();
- }
+ ecmd->id = uniq_id();
+ ecmd->name = alloc_new_str("local-executor");
+ ecmd->cmd = alloc_new_str(single_cmd->name);
+ ecmd->callback = single_cmd->callback;
- ecmd = tbl_exec_c();
- if (ecmd == NULL)
- {
- PERM();
- }
- ecmd->id = uniq_id();
- ecmd->name = alloc_new_str("local-executor");
- ecmd->cmd = alloc_new_str("UPTIME");
- ecmd->callback = cmd_uptime;
+ if (-1 == tbl_exec_add(etbl, ecmd))
+ {
+ PERM();
+ }
- if (-1 == tbl_exec_add(etbl, ecmd))
- {
- PERM();
+ single_cmd++;
+ }
}
tbl_exec_print_tbl(etbl, TBL_PF_EXEC_ALL);