summaryrefslogtreecommitdiff
path: root/agni.c
diff options
context:
space:
mode:
Diffstat (limited to 'agni.c')
-rw-r--r--agni.c48
1 files changed, 38 insertions, 10 deletions
diff --git a/agni.c b/agni.c
index be07089..08259ba 100644
--- a/agni.c
+++ b/agni.c
@@ -158,6 +158,7 @@ tble_cmd_resp* cllbk_wrapper( void *(*call)(void *), tble_cmd_param *param)
return unique ID, with atomic counter should work in all cases
*/
_Atomic int _glbl_id=0;
+/*
int uniq_id()
{
int ret=-1,id;
@@ -171,6 +172,7 @@ int uniq_id()
return ret;
}
+*/
@@ -350,7 +352,7 @@ int th_start_client(void *data)
tbl_qcmd *qtbl = NULL;
//create response table
- qtbl = tbl_qcmd_c(10);
+ qtbl = tbl_qcmd_c(100);
if (qtbl == NULL)
{
PERM();
@@ -483,25 +485,48 @@ int th_start_client(void *data)
mq_cmd_param(recv_cmd, &paramPtr, &paramSz);
printf("ID:%d Recieved response [%s]%d\n",mq_cmd_id(recv_cmd), paramPtr,paramSz);
- //wrong
+ //wrong
tble_cmd_resp *match_resp = malloc(sizeof(tble_cmd_resp));
memset(match_resp, 0, sizeof(tble_cmd_resp));
if (match_resp != NULL)
{
- PNL();
+ //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();
+ //PNL();
match_resp->resp = alloc_new_str_s(paramPtr, paramSz);
- PNL();
+ //PNL();
//check if command match
int cmd_id = tbl_qcmd_resp(qtbl, match_resp);
if (cmd_id > 0)
{
- PNL();
+
PRINT("%d\n",cmd_id);
+ tble_qcmd *cmd = tbl_qcmd_match_id(qtbl, cmd_id);
+ PNL();
+ if (cmd != NULL)
+ {
+ int buf_sz = TH_CONN_BUF_SZ>128?128:TH_CONN_BUF_SZ;
+
+ PNL();
+ char *resp_user = token_new_str(cmd->tok,0);
+ char *sep = strchr(resp_user,'!');
+ resp_user[sep-resp_user] = 0x0;
+
+ PNL();
+ memset(cmd_buf, 0, buf_sz);
+ PNL();
+ //prepare response
+ int fret = snprintf(cmd_buf, buf_sz,":%s PRIVMSG %s :%s \r\n",cfg->user,resp_user,match_resp->resp);
+ PRINT("cmd_buf %s \n", cmd_buf);
+ write(conn, cmd_buf, fret);
+
+ free(resp_user);
+
+ }
+
}
tbl_cmd_resp_free(match_resp);
@@ -567,14 +592,16 @@ int th_start_client(void *data)
memset(cmd_buf,0,128);
char *uname = token_new_str(itok,0);
char *msg = token_new_str(itok,3);
+
+ PRINT("msg %s\n", msg);
char *sep = strchr(uname,'!');
uname[sep-uname] = 0x0;
//just send to test that thos commands works mate
- fret2=snprintf(cmd_buf,128,":%s PRIVMSG %s PONGER\r\n",cfg->user,uname);
- printf("FORMATED [%s]",cmd_buf);
- fret = write(conn,cmd_buf,fret2);
+ //fret2=snprintf(cmd_buf,128,":%s PRIVMSG %s PONGER\r\n",cfg->user,uname);
+ //printf("FORMATED [%s]",cmd_buf);
+ //fret = write(conn,cmd_buf,fret2);
//create cmd table command and set into table
qcmd = tbl_qcmd_cmd_c();
@@ -595,7 +622,8 @@ int th_start_client(void *data)
|TBL_PF_QCMD_TIDX);
}
-
+ PRINT("msg %s\n", msg);
+
//create command and send to mq
mq_cmd *privcmd = mq_cmd_create(qcmd->cid,"PRIVMSG",strlen("PRIVMSG"),msg,strlen(msg));
char *bufPtr;