From 5007608202739ed1835ffc10a54dba02bc0f361f Mon Sep 17 00:00:00 2001 From: FreeArtMan Date: Thu, 20 Apr 2017 10:43:28 +0100 Subject: Add command executor command check --- agni.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++------- tbl_qcmd.c | 18 ++++++++++++++++++ tbl_qcmd.h | 2 +- 3 files changed, 65 insertions(+), 8 deletions(-) diff --git a/agni.c b/agni.c index 03c9f2b..dc91a93 100644 --- a/agni.c +++ b/agni.c @@ -368,8 +368,8 @@ int th_start_client(void *data) //PNL(); //PRINT("SERVER:%s PORT:%s USER:%s\n", cfg->server, cfg->port, cfg->user); - //conn = irc_connect(cfg->server, cfg->port); - conn = irc_connect("irc.freenode.net", "6667"); + conn = irc_connect(cfg->server, cfg->port); + //conn = irc_connect("irc.freenode.net", "6667"); //PNL(); if (conn < 0) { @@ -777,11 +777,6 @@ int th_event_manager(void *data) } tbl_exec_print_tbl(etbl, TBL_PF_EXEC_ALL); - etbl = tbl_exec_list_c(10); - if (etbl == NULL) - { - PERM(); - } //create command table qtbl = tbl_qcmd_c(10);//well 10 should be ok right? @@ -835,8 +830,19 @@ int th_event_manager(void *data) //PNL(); if (recv_cmd != NULL) { + + char *recv_cmd_param=NULL; + size_t recv_cmd_param_sz=-1; + PNL(); PRINT("MQ:CMD %s\n", mq_cmd_buf(recv_cmd)); + + + //get command fields + mq_cmd_param(recv_cmd, &recv_cmd_param, &recv_cmd_param_sz); + + + if (mq_cmd_o_cmp_cmd(recv_cmd,"QUIT") == 0) { printf("QUIT recieved lets quit main loop\n"); @@ -852,6 +858,7 @@ int th_event_manager(void *data) mq_cmd_free(privcmd); } else if (mq_cmd_o_cmp_cmd(recv_cmd,"PRIVMSG") == 0) { + /* printf("Some private message\n"); if (mq_cmd_o_cmp_param(recv_cmd, ":DATE") == 0) { @@ -878,10 +885,27 @@ int th_event_manager(void *data) mq_ntf_write(mq, MQ_IN, cmdBuf, strlen(cmdBuf)); cmdBuf = NULL; + mq_cmd_free(privcmd); + privcmd = NULL; + } else if (mq_cmd_o_cmp_param(recv_cmd, ":HELLO") == 0) + { + char msg[] = "PONG TO HELLO"; + mq_cmd *privcmd = mq_cmd_create(mq_cmd_id(recv_cmd),"PRIVMSG",strlen("PRIVMSG"),msg,strlen(msg)); + + PRINT("%s\n", privcmd->buf); + + int id = mq_cmd_id(recv_cmd); + PRINT("%d\n",id); + + char *cmdBuf = mq_cmd_buf(privcmd); + mq_ntf_write(mq, MQ_IN, cmdBuf, strlen(cmdBuf)); + cmdBuf = NULL; + mq_cmd_free(privcmd); privcmd = NULL; } else { + char msg[] = "PONG EVENT THREAD"; mq_cmd *privcmd = mq_cmd_create(mq_cmd_id(recv_cmd),"PRIVMSG",strlen("PRIVMSG"),msg,strlen(msg)); @@ -890,6 +914,21 @@ int th_event_manager(void *data) mq_ntf_write(mq, MQ_IN, cmdBuf, strlen(cmdBuf)); mq_cmd_free(privcmd); + + } + */ + + + //check if command callback excists + if (recv_cmd_param!=NULL) + { + if (tbl_exec_in_s(etbl, recv_cmd_param+1)>=0) //there is ':' in front of command, check if ptr not null otherwise die + { + + } else + { + PRINT("Command not found\n"); + } } } else if (mq_cmd_o_cmp_cmd(recv_cmd,"CMD2") == 0) diff --git a/tbl_qcmd.c b/tbl_qcmd.c index 4af9de8..deef61f 100644 --- a/tbl_qcmd.c +++ b/tbl_qcmd.c @@ -49,6 +49,24 @@ int tbl_exec_add(tbl_exec *tbl, tble_exec *cmd) int tbl_exec_in_s(tbl_exec *tbl, char *cmd) { + int i; + tble_exec *el=NULL; + + if ((tbl == NULL) || (cmd == NULL)) + { + PERM(); + return -1; + } + + for (i=0; isize; i++) + { + el = tbl->cmd[i]; + if (strncmp(el->cmd, cmd, strlen(el->cmd))==0) + { + return i; + } + } + return -1; } diff --git a/tbl_qcmd.h b/tbl_qcmd.h index acd3da7..5f66386 100644 --- a/tbl_qcmd.h +++ b/tbl_qcmd.h @@ -168,7 +168,7 @@ Input: tbl - table of executed commands cmd - command name to search in the list Output: - >=0 - if everything whent ok + >=0 - if everything whent ok, return position of command in array -1 - if there was some kind of mistake */ int tbl_exec_in_s(tbl_exec *tbl, char *cmd); -- cgit v1.2.3