diff options
Diffstat (limited to 'agni.c')
-rw-r--r-- | agni.c | 39 |
1 files changed, 19 insertions, 20 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 |