summaryrefslogtreecommitdiff
path: root/agni.c
diff options
context:
space:
mode:
Diffstat (limited to 'agni.c')
-rw-r--r--agni.c73
1 files changed, 67 insertions, 6 deletions
diff --git a/agni.c b/agni.c
index bb9dd40..e2ba337 100644
--- a/agni.c
+++ b/agni.c
@@ -345,6 +345,19 @@ int th_start_client(void *data)
irc_token *itok = NULL;
char *irc_line = NULL;
+ //table to match response/request
+ tble_qcmd *qcmd = NULL;
+ tbl_qcmd *qtbl = NULL;
+
+ //create response table
+ qtbl = tbl_qcmd_c(10);
+ if (qtbl == NULL)
+ {
+ PERM();
+ }
+
+
+
@@ -468,7 +481,33 @@ int th_start_client(void *data)
char *paramPtr;
size_t paramSz;
mq_cmd_param(recv_cmd, &paramPtr, &paramSz);
- printf("Recieved response [%s]%d\n",paramPtr,paramSz);
+ printf("ID:%d Recieved response [%s]%d\n",mq_cmd_id(recv_cmd), paramPtr,paramSz);
+
+ //wrong
+ tble_cmd_resp *match_resp = malloc(sizeof(tble_cmd_resp));
+ if (match_resp != NULL)
+ {
+ PNL();
+ match_resp->qid = mq_cmd_id(recv_cmd);
+ //for now any type is ok, make time consistant, for this usage
+ //match_cmd->type = QCMD_NONE
+ PNL();
+ match_resp->resp = alloc_new_str_s(paramPtr, paramSz);
+
+ PNL();
+ //check if command match
+ //int cmd_id = tbl_qcmd_resp(qtbl, match_resp);
+ //if (cmd_id > 0)
+ {
+ PNL();
+ // PRINT("%d\n",cmd_id);
+ }
+
+ tbl_cmd_param_free(match_resp);
+ }
+
+ //lets memleak here
+
} else
{
PRINT("Unknown command\n");
@@ -536,13 +575,35 @@ int th_start_client(void *data)
printf("FORMATED [%s]",cmd_buf);
fret = write(conn,cmd_buf,fret2);
+ //create cmd table command and set into table
+ qcmd = tbl_qcmd_cmd_c();
+ if (qcmd != NULL)
+ {
+ qcmd->cid = uniq_id();
+ qcmd->state = QCMD_NONE;
+ qcmd->cmd = alloc_new_str("PRIVMSG");
+ qcmd->param = alloc_new_str(msg);
+ tbl_qcmd_add(qtbl, qcmd);
+ tbl_qcmd_print_tbl(qtbl,TBL_PF_QCMD_ID
+ |TBL_PF_QCMD_CID
+ |TBL_PF_QCMD_STATE
+ |TBL_PF_QCMD_CMD
+ |TBL_PF_QCMD_PARAM
+ |TBL_PF_QCMD_TID
+ |TBL_PF_QCMD_TIDX);
+ }
+
+
//create command and send to mq
- mq_cmd *privcmd = mq_cmd_create(1,"PRIVMSG",strlen("PRIVMSG"),msg,strlen(msg));
+ mq_cmd *privcmd = mq_cmd_create(qcmd->cid,"PRIVMSG",strlen("PRIVMSG"),msg,strlen(msg));
char *bufPtr;
bufPtr = mq_cmd_buf(privcmd);
mq_ntf_write(mq, MQ_OUT, bufPtr, strlen(bufPtr));
mq_cmd_free(privcmd);
+ //for safety make null, as no one should use it anymore
+ qcmd = NULL;
+
free(msg);
free(uname);
@@ -740,7 +801,7 @@ int th_event_manager(void *data)
//create command and send to mq
char msg[] = "PONG";
- mq_cmd *privcmd = mq_cmd_create(1,"PRIVMSG",strlen("PRIVMSG"),msg,strlen(msg));
+ mq_cmd *privcmd = mq_cmd_create(mq_cmd_id(recv_cmd),"PRIVMSG",strlen("PRIVMSG"),msg,strlen(msg));
mq_cmd_free(privcmd);
} else if (mq_cmd_o_cmp_cmd(recv_cmd,"PRIVMSG") == 0)
@@ -749,7 +810,7 @@ int th_event_manager(void *data)
if (mq_cmd_o_cmp_param(recv_cmd, ":DATE") == 0)
{
char msg[] = "No date";
- mq_cmd *privcmd = mq_cmd_create(1,"PRIVMSG",strlen("PRIVMSG"),msg,strlen(msg));
+ mq_cmd *privcmd = mq_cmd_create(mq_cmd_id(recv_cmd),"PRIVMSG",strlen("PRIVMSG"),msg,strlen(msg));
char *cmdBuf = mq_cmd_buf(privcmd);
mq_ntf_write(mq, MQ_IN, cmdBuf, strlen(cmdBuf));
@@ -760,7 +821,7 @@ int th_event_manager(void *data)
} else if (mq_cmd_o_cmp_param(recv_cmd, ":UPTIME") == 0)
{
char msg[] = "Forever";
- mq_cmd *privcmd = mq_cmd_create(1,"PRIVMSG",strlen("PRIVMSG"),msg,strlen(msg));
+ mq_cmd *privcmd = mq_cmd_create(mq_cmd_id(recv_cmd),"PRIVMSG",strlen("PRIVMSG"),msg,strlen(msg));
char *cmdBuf = mq_cmd_buf(privcmd);
mq_ntf_write(mq, MQ_IN, cmdBuf, strlen(cmdBuf));
@@ -772,7 +833,7 @@ int th_event_manager(void *data)
{
char msg[] = "PONG EVENT THREAD";
- mq_cmd *privcmd = mq_cmd_create(1,"PRIVMSG",strlen("PRIVMSG"),msg,strlen(msg));
+ mq_cmd *privcmd = mq_cmd_create(mq_cmd_id(recv_cmd),"PRIVMSG",strlen("PRIVMSG"),msg,strlen(msg));
char *cmdBuf = mq_cmd_buf(privcmd);
mq_ntf_write(mq, MQ_IN, cmdBuf, strlen(cmdBuf));