diff options
author | FreeArtMan <dos21h@gmail.com> | 2017-05-04 22:21:39 +0100 |
---|---|---|
committer | FreeArtMan <dos21h@gmail.com> | 2017-05-04 22:21:39 +0100 |
commit | 417edbce2abde566e94d8986b487293d55e173c0 (patch) | |
tree | 133db23e0c58704f06447a77e8a1e964bf98be2c /agni.c | |
parent | 0a24537719de7cab1b4df46e7d6a22564f66ec6a (diff) | |
download | agni-417edbce2abde566e94d8986b487293d55e173c0.tar.gz agni-417edbce2abde566e94d8986b487293d55e173c0.zip |
Added new commands CMD,SHA1. Added support of params for commands. Fixed some bugs with uninitialised buffers
Diffstat (limited to 'agni.c')
-rw-r--r-- | agni.c | 36 |
1 files changed, 17 insertions, 19 deletions
@@ -278,7 +278,8 @@ int th_start_client(void *data) //PRINT("EVENT 0\n"); break; case 1: - PRINT("MQ_EVENT IN\n"); + //PRINT("MQ_EVENT IN\n"); + //memset(in_buf, 0, in_attr.mq_msgsize); if ((byte_num = mq_ntf_read(mq, MQ_IN, in_buf, in_attr.mq_msgsize)) == -1) { printf("Cant read input message \n"); @@ -297,7 +298,6 @@ int th_start_client(void *data) //recieve commands from queue if (mq_event == 1) { - //PNL(); recv_cmd = mq_cmd_creates(in_buf, in_attr.mq_msgsize, -1); if (recv_cmd != NULL) { @@ -307,7 +307,7 @@ int th_start_client(void *data) break; } else if (mq_cmd_o_cmp_cmd(recv_cmd,"PRIVMSG:") == 0) { - PRINT("Response\n") + //PRINT("Response\n") char *paramPtr; size_t paramSz; mq_cmd_param(recv_cmd, ¶mPtr, ¶mSz); @@ -331,7 +331,7 @@ int th_start_client(void *data) if (cmd != NULL) { - PRINT("Found ID in qcmd table %d\n", cmd_id); + //PRINT("Found ID in qcmd table %d\n", cmd_id); char *resp_user = token_new_str(cmd->tok,0); char *dest_user = token_new_str(cmd->tok,2); char *sep = strchr(resp_user,'!'); @@ -364,9 +364,6 @@ 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 } } @@ -385,6 +382,9 @@ int th_start_client(void *data) recv_cmd = NULL; } + + //should be added proper command state check and so on + tbl_qcmd_mng_states(qtbl); // This should be runed regulary //recieve irc commands and pass to MQ, save command to table @@ -430,7 +430,7 @@ int th_start_client(void *data) int fret,fret2; //char send_back[128]; - PNL(); + //PNL(); memset(cmd_buf,0,128); char *uname = token_new_str(itok,0); @@ -444,11 +444,11 @@ int th_start_client(void *data) //if (token_cmp(itok,3,":join") == 1) if (strncmp(":join",msg,5)==0) { - PNL(); + //PNL(); //lets check if one more argument is there { - PNL(); + //PNL(); char *sep_chan = strchr(msg,' '); //lets join channel @@ -487,10 +487,12 @@ int th_start_client(void *data) } //create command and send to mq + PRINT("MSG %s\n",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)); + PRINT("%s\n",bufPtr); + PRINT("write %d bytes\n",mq_ntf_write(mq, MQ_OUT, bufPtr, strlen(bufPtr))); mq_cmd_free(privcmd); //for safety make null, as no one should use it anymore @@ -638,6 +640,7 @@ int th_event_manager(void *data) break; case 1: PRINT("MQ_EVENT OUT\n"); + memset(out_buf, 0, out_attr.mq_msgsize); if (mq_ntf_read(mq, MQ_OUT, out_buf, out_attr.mq_msgsize) == -1) { printf("Cant read output message\n"); @@ -654,8 +657,6 @@ int th_event_manager(void *data) //if QUIT then quit the thread if (mq_event == 1) { - PNL(); - recv_cmd = mq_cmd_creates(out_buf, out_attr.mq_msgsize, 1); //PNL(); if (recv_cmd != NULL) @@ -664,14 +665,8 @@ int th_event_manager(void *data) 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) { @@ -689,16 +684,19 @@ int th_event_manager(void *data) } else if (mq_cmd_o_cmp_cmd(recv_cmd,"PRIVMSG") == 0) { //check if command callback excists + PRINT("recv_cmd_param %s\n", recv_cmd_param); 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 { void *ret_msg = NULL; + PRINT("CMD [%s]\n",recv_cmd_param); if (tbl_exec_run(etbl, recv_cmd_param+1, &ret_msg)>=0) { if (ret_msg!=NULL) { + //prepare response message and send it it back mq_cmd *privcmd = mq_cmd_create( mq_cmd_id(recv_cmd), "PRIVMSG", |