From 6a377350d63fc2dd470e9bd25008e8e827c011f2 Mon Sep 17 00:00:00 2001 From: FreeArtMan Date: Mon, 8 May 2017 16:52:21 +0100 Subject: Muli server support. Some small fixes to commands --- agni.c | 37 ++++++++++++++++++++++++++++++------- cmd_botu.c | 6 +++++- cmd_cmd.c | 2 +- cmd_ping.c | 2 +- cmd_sha1.c | 2 +- config_cmds.h | 4 ++-- 6 files changed, 40 insertions(+), 13 deletions(-) diff --git a/agni.c b/agni.c index 968ea45..9ad547c 100644 --- a/agni.c +++ b/agni.c @@ -447,13 +447,11 @@ int th_start_client(void *data) //if (token_cmp(itok,3,":join") == 1) if (strncmp(":join",msg,5)==0) { - //PNL(); //lets check if one more argument is there - { char *chan_name=NULL; int iter=0; - char *sep_chan = strchr(msg,' ')+1; + char *sep_chan = strchr(msg,' ')+1; //small hack //check if channel in allowed list, if yes then continue iter=0; @@ -466,11 +464,9 @@ int th_start_client(void *data) //lets join channel memset(cmd_buf, 0, TH_CONN_BUF_SZ); int fret = snprintf(cmd_buf, TH_CONN_BUF_SZ, ":%s JOIN %s\r\n", dest_name, sep_chan); - PRINT("cmd_buf %s\n", cmd_buf); write(conn, cmd_buf, fret); break; } - PNL(); iter++; if (cfg->channels[iter]==NULL) { @@ -583,7 +579,8 @@ int th_event_manager(void *data) { event_handler_cfg *cfg = data; atomic_fetch_add(&cfg->running,1); - mq_ntf_mdt *mq=NULL; + mq_ntf_mdt *mq=NULL,*mq_cur=NULL; + int i_mq=0; //to iter trought mqueue char *out_buf = NULL; int run; int mq_event; @@ -656,6 +653,7 @@ int th_event_manager(void *data) while(run) { //check if there is some message and save it to buffer + /* run += 1; mq_event = mq_ntf_select(mq, MQ_OUT); switch(mq_event) @@ -678,6 +676,31 @@ int th_event_manager(void *data) default: printf("Unknown event type\n"); } + */ + run += 1; + + for (i_mq=0;i_mqmq_num;i_mq++) + { + mq = cfg->mq_listen; + mq_event = mq_ntf_select(&mq[i_mq], MQ_OUT); + mq_cur = &mq[i_mq]; + if (mq_event == 1) + { + PRINT("MQ_EVENT OUT\n"); + memset(out_buf, 0, out_attr.mq_msgsize); + //will fail if some of queue have different buffer size param + if (mq_ntf_read(&mq[i_mq], MQ_OUT, out_buf, out_attr.mq_msgsize) == -1) + { + printf("Cant read output message\n"); + } else + { + out_buf[out_attr.mq_msgsize-1] = 0x0; + printf("Recieve %s\n", out_buf); + } + break; + } + } //mq_cur have currently queue where message comes from, need to make some buffer that gona pass/save this info + //if QUIT then quit the thread if (mq_event == 1) @@ -722,7 +745,7 @@ int th_event_manager(void *data) ); char *cmdBuf = mq_cmd_buf(privcmd); - mq_ntf_write(mq, MQ_IN, cmdBuf, strlen(cmdBuf)); + mq_ntf_write(mq_cur, MQ_IN, cmdBuf, strlen(cmdBuf)); mq_cmd_free(privcmd); } diff --git a/cmd_botu.c b/cmd_botu.c index 312509d..f284ba9 100644 --- a/cmd_botu.c +++ b/cmd_botu.c @@ -35,7 +35,11 @@ void *cmd_botu(void *data) proc_sec = start.tv_sec - file_stat.st_ctim.tv_sec; - snprintf(buf, buf_size, "%llusec\n", proc_sec); + snprintf(buf, buf_size, "%llud %lluh %llum %llus\n", + (proc_sec/(3600*24)), + (proc_sec/(3600))%24, + (proc_sec/60)%60, + proc_sec%60); ret = alloc_new_str(buf); return ret; diff --git a/cmd_cmd.c b/cmd_cmd.c index d5983cf..e893687 100644 --- a/cmd_cmd.c +++ b/cmd_cmd.c @@ -10,7 +10,7 @@ void *cmd_cmd(void *data) printf("CMD\n"); - snprintf(buf, buf_size, "%s", data); + snprintf(buf, buf_size, "%s\n", data); diff --git a/cmd_ping.c b/cmd_ping.c index 469c616..5bc0c31 100644 --- a/cmd_ping.c +++ b/cmd_ping.c @@ -7,7 +7,7 @@ void *cmd_ping(void *data) printf("PONG\n"); - ret = alloc_new_str("ping "); + ret = alloc_new_str("pong "); return ret; } \ No newline at end of file diff --git a/cmd_sha1.c b/cmd_sha1.c index 08b2527..4472ed1 100644 --- a/cmd_sha1.c +++ b/cmd_sha1.c @@ -33,7 +33,7 @@ void *cmd_sha1(void *data) hex_result[40]=0x0; - snprintf(buf, buf_size, "SHA1 %s\n",hex_result); + snprintf(buf, buf_size, "sha1 %s\n",hex_result); ret = alloc_new_str(buf); diff --git a/config_cmds.h b/config_cmds.h index a3e503e..cda9d4f 100644 --- a/config_cmds.h +++ b/config_cmds.h @@ -25,7 +25,7 @@ typedef struct single_cmd_def single_cmd_def confgi_cmd_list[] = { {"DATE",cmd_date}, - {"UPTIME",cmd_uptime}, {"!uptime",cmd_uptime}, + {"UPTIME",cmd_uptime}, {"VERSION",cmd_version}, {"!version",cmd_version}, {"PING",cmd_ping}, {"!ping",cmd_ping}, {"LOADAVG",cmd_loadavg}, @@ -33,7 +33,7 @@ single_cmd_def confgi_cmd_list[] = {"CMD",cmd_cmd}, {"!echo",cmd_cmd}, {"SHA1",cmd_sha1}, {"COOKIE",cmd_cookie}, - {"BOTU",cmd_botu}, + {"BOTU",cmd_botu}, {"!uptime",cmd_botu}, {NULL,NULL} }; -- cgit v1.2.3