summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile6
-rw-r--r--agni.c99
-rw-r--r--cmd_date.c13
-rw-r--r--cmd_date.h11
-rw-r--r--cmd_ping.c13
-rw-r--r--cmd_ping.h11
-rw-r--r--cmd_uptime.c13
-rw-r--r--cmd_uptime.h11
-rw-r--r--cmd_version.c6
-rw-r--r--cmd_version.h13
-rw-r--r--config_cmds.h27
-rw-r--r--tbl_qcmd.c1
-rw-r--r--tbl_qcmd.h2
13 files changed, 148 insertions, 78 deletions
diff --git a/Makefile b/Makefile
index 6dbebee..26ac9a8 100644
--- a/Makefile
+++ b/Makefile
@@ -13,8 +13,12 @@ make:
$(CC) $(CFLAGS) sock_conn.c -c
$(CC) $(CFLAGS) irc_parse.c -c
$(CC) $(CFLAGS) mmm.c -c
+ $(CC) $(CFLAGS) cmd_date.c -c
+ $(CC) $(CFLAGS) cmd_uptime.c -c
+ $(CC) $(CFLAGS) cmd_version.c -c
+ $(CC) $(CFLAGS) cmd_ping.c -c
$(CC) $(CFLAGS) tbl_qcmd.o mq_cmd.o mq_ntf.o buf.o mmm.o darray.o util.o sock_conn.o \
- irc_parse.o mmm.c agni.c \
+ irc_parse.o mmm.c cmd_date.o cmd_uptime.o cmd_version.o cmd_ping.o agni.c \
-o $(PROJECT) -std=c11 -lrt
leak:
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);
diff --git a/cmd_date.c b/cmd_date.c
index e69de29..ac44bd5 100644
--- a/cmd_date.c
+++ b/cmd_date.c
@@ -0,0 +1,13 @@
+#include "cmd_date.h"
+
+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;
+} \ No newline at end of file
diff --git a/cmd_date.h b/cmd_date.h
index e69de29..0e1c9c5 100644
--- a/cmd_date.h
+++ b/cmd_date.h
@@ -0,0 +1,11 @@
+#ifndef __CMD_DATE_H
+#define __CMD_DATE_H
+
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "util.h"
+
+void *cmd_date(void *data);
+
+#endif \ No newline at end of file
diff --git a/cmd_ping.c b/cmd_ping.c
new file mode 100644
index 0000000..5bd6d84
--- /dev/null
+++ b/cmd_ping.c
@@ -0,0 +1,13 @@
+#include "cmd_ping.h"
+
+void *cmd_ping(void *data)
+{
+ char *param = (char *)data;
+ char *ret = NULL;
+
+ printf("PONG\n");
+
+ ret = alloc_new_str("PONG");
+
+ return ret;
+} \ No newline at end of file
diff --git a/cmd_ping.h b/cmd_ping.h
new file mode 100644
index 0000000..fef18c6
--- /dev/null
+++ b/cmd_ping.h
@@ -0,0 +1,11 @@
+#ifndef __CMD_PING_H
+#define __CMD_PING_H
+
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "util.h"
+
+void *cmd_ping(void *data);
+
+#endif \ No newline at end of file
diff --git a/cmd_uptime.c b/cmd_uptime.c
index e69de29..f745be0 100644
--- a/cmd_uptime.c
+++ b/cmd_uptime.c
@@ -0,0 +1,13 @@
+#include "cmd_uptime.h"
+
+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;
+} \ No newline at end of file
diff --git a/cmd_uptime.h b/cmd_uptime.h
index e69de29..3906cd2 100644
--- a/cmd_uptime.h
+++ b/cmd_uptime.h
@@ -0,0 +1,11 @@
+#ifndef __CMD_UPTIME_H
+#define __CMD_UPTIME_H
+
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "util.h"
+
+void *cmd_uptime(void *data);
+
+#endif \ No newline at end of file
diff --git a/cmd_version.c b/cmd_version.c
new file mode 100644
index 0000000..d449ea1
--- /dev/null
+++ b/cmd_version.c
@@ -0,0 +1,6 @@
+#include "cmd_version.h"
+
+void *cmd_version(void *data)
+{
+ return NULL;
+} \ No newline at end of file
diff --git a/cmd_version.h b/cmd_version.h
new file mode 100644
index 0000000..ede27bb
--- /dev/null
+++ b/cmd_version.h
@@ -0,0 +1,13 @@
+#ifndef __CMD_VERSION_H
+#define __CMD_VERSION_H
+
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "util.h"
+
+void *cmd_version(void *data);
+
+#endif
+
+
diff --git a/config_cmds.h b/config_cmds.h
new file mode 100644
index 0000000..2ae8574
--- /dev/null
+++ b/config_cmds.h
@@ -0,0 +1,27 @@
+#ifndef __CONFIG_CMDS_H
+#define __CONFIG_CMDS_H
+
+typedef struct single_cmd_def
+{
+ char *name;
+ void *(*callback)(void *);
+} single_cmd_def;
+
+
+//list all include files with commands
+#include "cmd_date.h"
+#include "cmd_uptime.h"
+#include "cmd_version.h"
+#include "cmd_ping.h"
+
+single_cmd_def confgi_cmd_list[] =
+{
+ {"DATE",cmd_date},
+ {"UPTIME",cmd_uptime},
+ {"VERSION",cmd_version},
+ {"PING",cmd_ping},
+ {NULL,NULL}
+};
+
+
+#endif \ No newline at end of file
diff --git a/tbl_qcmd.c b/tbl_qcmd.c
index bc609b6..5f4b0e8 100644
--- a/tbl_qcmd.c
+++ b/tbl_qcmd.c
@@ -772,6 +772,7 @@ int tbl_qcmd_destroy_table(tbl_qcmd *tbl)
return 0;
}
+//redo adding and deleteing logic, there is a bug
int tbl_qcmd_mng_states(tbl_qcmd *tbl)
{
int i;
diff --git a/tbl_qcmd.h b/tbl_qcmd.h
index bef4043..55e6d93 100644
--- a/tbl_qcmd.h
+++ b/tbl_qcmd.h
@@ -45,7 +45,7 @@ typedef struct tbl_exec
tble_exec **cmd;
} tbl_exec;
-#define QCMD_DEFAULT_TIMEOUT 10 //default amount of seconds to wait replay
+#define QCMD_DEFAULT_TIMEOUT 3 //default amount of seconds to wait replay
#define QCMD_NONE 0 //nothing happening with this command
#define QCMD_TIMEOUT 1 //command running to long without result