summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFreeArtMan <dos21h@gmail.com>2017-05-08 16:52:21 +0100
committerFreeArtMan <dos21h@gmail.com>2017-05-08 16:52:21 +0100
commit6a377350d63fc2dd470e9bd25008e8e827c011f2 (patch)
treed1668b7358aa3e94c6dcfeeb9eb5c3af5f7d5a6a
parent5025c0c8288a336f7986153574bce73df4bb3147 (diff)
downloadagni-6a377350d63fc2dd470e9bd25008e8e827c011f2.tar.gz
agni-6a377350d63fc2dd470e9bd25008e8e827c011f2.zip
Muli server support. Some small fixes to commands
-rw-r--r--agni.c37
-rw-r--r--cmd_botu.c6
-rw-r--r--cmd_cmd.c2
-rw-r--r--cmd_ping.c2
-rw-r--r--cmd_sha1.c2
-rw-r--r--config_cmds.h4
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_mq<cfg->mq_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}
};