diff options
author | FreeArtMan <dos21h@gmail.com> | 2017-05-07 23:29:37 +0100 |
---|---|---|
committer | FreeArtMan <dos21h@gmail.com> | 2017-05-07 23:29:37 +0100 |
commit | d43cf6e4704da5414c80e32da06060ad06511f62 (patch) | |
tree | a186407e73525c66a29ffa4f8c734cae7a5db385 | |
parent | 67664bcf54a128bd9cfb76f4fc047131e740cbc2 (diff) | |
download | agni-d43cf6e4704da5414c80e32da06060ad06511f62.tar.gz agni-d43cf6e4704da5414c80e32da06060ad06511f62.zip |
Fixed bug with not sending correctly PONG to response to PING
-rw-r--r-- | agni.c | 39 | ||||
-rw-r--r-- | tbl_qcmd.c | 4 |
2 files changed, 21 insertions, 22 deletions
@@ -389,22 +389,31 @@ int th_start_client(void *data) //recieve irc commands and pass to MQ, save command to table //fix this by allowing drain just chunks, not whole buffer - //memset(conn_buf, 0, TH_CONN_BUF_SZ); + memset(conn_buf, 0, TH_CONN_BUF_SZ); if((cret = read(conn,conn_buf, 256))>0) { irc_buf_puts(ib, conn_buf, cret); while (irc_buf_ready(ib) == 1) { + irc_line = irc_buf_line(ib); if (irc_line) { - printf("PARSE>>%s\n",irc_line); + printf("PARSE>>%s<<\n",irc_line); + + if (memcmp(irc_line,"PING",4)==0) { - write(conn,"PONG",strlen("PONG")); - printf("OUT>>PONG\n"); + int fret; + const int pong_buf_sz = 128; + char pong_buf[pong_buf_sz]; + snprintf(pong_buf,pong_buf_sz,"PONG %s\n",cfg->user); + PRINT("%s",pong_buf) + fret = write(conn,pong_buf,strlen(pong_buf)); + printf("OUT>>PONG %d\n",fret); } + itok = irc_parse(irc_line,strlen(irc_line)); if (itok != NULL) { @@ -418,12 +427,6 @@ int th_start_client(void *data) { } - if (token_cmp(itok,1,"PING")==1) - { - int fret; - fret = write(conn,"PONG",strlen("PONG")); - printf("OUT<<Send %d\n", fret); - } //something is sended to cbot if (token_cmp(itok,1,"PRIVMSG") == 1) { @@ -508,7 +511,12 @@ int th_start_client(void *data) token_destroy(itok); itok = NULL; } - FREE(irc_line); + if (irc_line!=NULL) + { + memset(irc_line,0,strlen(irc_line)); + free(irc_line); + irc_line = NULL; + } __irc_buf_drain_io(ib); } @@ -672,15 +680,6 @@ int th_event_manager(void *data) { printf("QUIT recieved lets quit main loop\n"); break; - } else if (mq_cmd_o_cmp_cmd(recv_cmd,"PING") == 0) - { - printf("Its fine im working\n"); - - //create command and send to mq - char msg[] = "PONG"; - 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) { //check if command callback excists @@ -100,7 +100,7 @@ int tbl_exec_run(tbl_exec *tbl, char *cmd, void **resp) for (i=0;i<tbl->size;i++) { el = tbl->cmd[i]; - PRINT("CALLBACK CMD %s\n",cmd); + //PRINT("CALLBACK CMD %s\n",cmd); if (strncmp(el->cmd, cmd, strlen(el->cmd))==0) { void *ret_resp=NULL; @@ -134,7 +134,7 @@ int tbl_exec_run(tbl_exec *tbl, char *cmd, void **resp) } } - PRINT("CALLBACK PARAMS %s\n", clbk_data); + //PRINT("CALLBACK PARAMS %s\n", clbk_data); ret_resp = el->callback(clbk_data); //no params for now |