From d43cf6e4704da5414c80e32da06060ad06511f62 Mon Sep 17 00:00:00 2001 From: FreeArtMan Date: Sun, 7 May 2017 23:29:37 +0100 Subject: Fixed bug with not sending correctly PONG to response to PING --- agni.c | 39 +++++++++++++++++++-------------------- tbl_qcmd.c | 4 ++-- 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/agni.c b/agni.c index e0055be..2bdba8b 100644 --- a/agni.c +++ b/agni.c @@ -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) { @@ -417,12 +426,6 @@ int th_start_client(void *data) if (token_cmp(itok,1,"NOTICE")==1) { - } - if (token_cmp(itok,1,"PING")==1) - { - int fret; - fret = write(conn,"PONG",strlen("PONG")); - printf("OUT<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 -- cgit v1.2.3