summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFreeArtMan <dos21h@gmail.com>2017-09-05 23:57:31 +0100
committerFreeArtMan <dos21h@gmail.com>2017-09-05 23:57:31 +0100
commit2f5d66c4a5b85c32f62042dd7e9ea984d27a4363 (patch)
tree204c4f92ac6c427741c44d87049790f55dd1aab4
parentda722516cb31e523d58ebb4a2f827988e3a1782b (diff)
downloadagni-2f5d66c4a5b85c32f62042dd7e9ea984d27a4363.tar.gz
agni-2f5d66c4a5b85c32f62042dd7e9ea984d27a4363.zip
Removed mq_cmd shitz
-rw-r--r--agni.c90
-rw-r--r--extlibs/nbrpc.h1
-rw-r--r--mq_cmd.c325
-rw-r--r--mq_cmd.h49
-rw-r--r--mq_ntf.h3
5 files changed, 0 insertions, 468 deletions
diff --git a/agni.c b/agni.c
index 6830893..8b2b704 100644
--- a/agni.c
+++ b/agni.c
@@ -24,7 +24,6 @@
#include "darray.h"
#include "buf.h"
-#include "mq_cmd.h"
#include "mq_ntf.h"
#include "tbl_qcmd.h"
#include "util.h"
@@ -197,7 +196,6 @@ int th_start_client(void *data)
server_cfg *cfg = data;
mq_ntf_mdt *mq = cfg->mq;
- mq_cmd *recv_cmd = NULL; // for recieved cmd from mq
struct mq_attr out_attr, *ptr_out_attr=&out_attr;
struct mq_attr in_attr, *ptr_in_attr=&in_attr;
char *out_buf = NULL;
@@ -350,91 +348,6 @@ int th_start_client(void *data)
//recieve commands from queue
if (mq_event == 1)
{
- /*
- recv_cmd = mq_cmd_creates(in_buf, in_attr.mq_msgsize, -1);
- if (recv_cmd != NULL)
- {
- if (mq_cmd_o_cmp_cmd(recv_cmd,"QUIT") == 0)
- {
- printf("QUIT recieved lets quit main loop\n");
- break;
- } else if (mq_cmd_o_cmp_cmd(recv_cmd,"PRIVMSG:") == 0)
- {
- //PRINT("Response\n")
- char *paramPtr;
- size_t paramSz;
- mq_cmd_param(recv_cmd, &paramPtr, &paramSz);
- printf("ID:%d Recieved response [%s]%zu\n",mq_cmd_id(recv_cmd), paramPtr, paramSz);
-
- //wrong
- tble_cmd_resp *match_resp = malloc(sizeof(tble_cmd_resp));
- memset(match_resp, 0, sizeof(tble_cmd_resp));
- if (match_resp != NULL)
- {
- match_resp->qid = mq_cmd_id(recv_cmd);
- //for now any type is ok, make time consistant, for this usage
- //match_cmd->type = QCMD_NONE
- match_resp->resp = alloc_new_str_s(paramPtr, paramSz);
-
- //check if command match
- int cmd_id = tbl_qcmd_resp(qtbl, match_resp);
- if (cmd_id > 0)
- {
- tble_qcmd *cmd = tbl_qcmd_match_id(qtbl, cmd_id);
- if (cmd != NULL)
- {
-
- //PRINT("Found ID in qcmd table %d\n", cmd_id);
- char *resp_user = token_new_str(cmd->tok,0);
- char *dest_user = token_new_str(cmd->tok,2);
- char *sep = strchr(resp_user,'!');
- resp_user[sep-resp_user] = 0x0;
-
- memset(cmd_buf, 0, TH_CONN_BUF_SZ);
-
- if (dest_user[0] == '#')
- {
- //response for chan PRIVMSG
- //prepare response
- int fret = snprintf(cmd_buf, TH_CONN_BUF_SZ,":%s PRIVMSG %s :%s \r\n", cfg->user, dest_user, match_resp->resp);
- PRINT("%s\n",cmd_buf);
- write(conn.conn_fd, cmd_buf, fret);
- }
- else
- {
- //response for user PRIVMSG
-
- //prepare response
- int fret = snprintf(cmd_buf, TH_CONN_BUF_SZ,":%s PRIVMSG %s :%s \r\n", dest_user, resp_user, match_resp->resp);
- PRINT("%s\n",cmd_buf);
- write(conn.conn_fd, cmd_buf, fret);
- }
-
- FREE(dest_user);
- FREE(resp_user);
-
- //remove command by id
- //for now just remove command without checkings its state
- tbl_qcmd_del_by_id(qtbl, cmd_id); //no error check
-
- }
-
- }
-
- tbl_cmd_resp_free(match_resp);
- }
-
- //lets memleak here
-
- } else
- {
- PRINT("Unknown command\n");
- }
- }
- mq_cmd_free(recv_cmd);
- recv_cmd = NULL;
- */
-
nb_init(nb_resp);
nb_load(nb_resp, in_buf);
rpc_resp_unmarsh(nb_resp, &resp);
@@ -732,10 +645,7 @@ int th_event_manager(void *data)
int run;
int mq_event;
-
-
//read any command
- mq_cmd *recv_cmd = NULL; // for recieved cmd from mq
struct mq_attr out_attr, *ptr_out_attr=&out_attr;
struct mq_attr in_attr, *ptr_in_attr=&in_attr;
diff --git a/extlibs/nbrpc.h b/extlibs/nbrpc.h
index 3108702..6583b51 100644
--- a/extlibs/nbrpc.h
+++ b/extlibs/nbrpc.h
@@ -3,7 +3,6 @@
#include <netbytes.h>
-#include "mq_cmd.h"
#include "mq_ntf.h"
typedef struct rpc_request
diff --git a/mq_cmd.c b/mq_cmd.c
deleted file mode 100644
index bc692a4..0000000
--- a/mq_cmd.c
+++ /dev/null
@@ -1,325 +0,0 @@
-#include "mq_cmd.h"
-
-#define MQ_CMD_MSG_SIZE 1024
-//last string element should be string ;]
-mq_cmd* mq_cmd_create(int id, char *cmd, size_t cmd_sz, char *param, size_t param_sz)
-{
- mq_cmd *ret = NULL;
-
- if (cmd == NULL)
- {
- PERM();
- return NULL;
- }
- if (param == NULL)
- {
- PERM();
- return NULL;
- }
-
- ret = malloc(sizeof(mq_cmd));
- if (ret == NULL)
- {
- ENL();
- return NULL;
- }
- memset(ret, 0, sizeof(mq_cmd));
-
- ret->id = id;
- ret->sz = MQ_CMD_MSG_SIZE;
- ret->buf = malloc(MQ_CMD_MSG_SIZE);
- memset(ret->buf, 0, MQ_CMD_MSG_SIZE); //speed? who cares
- if (ret->buf == NULL)
- {
- ENL();
- free(ret);
- return NULL;
- }
- //if not null string that everything will blow up pal
- //cmd[cmd_sz-1] = 0x0;
- //param[param_sz-1] = 0x0;
- char *t_cmd = malloc(cmd_sz+1);
- memcpy(t_cmd, cmd, cmd_sz);
- t_cmd[cmd_sz]=0;
-
- char *t_param = malloc(param_sz+1);
- memcpy(t_param, param, param_sz);
- t_param[param_sz]=0;
- snprintf(ret->buf,ret->sz-1,":%d:%s: %s", id, t_cmd, t_param);
-
- free(t_cmd);
- free(t_param);
-
- return ret;
-}
-
-mq_cmd* mq_cmd_creates(char *str, size_t sz, int id)
-{
- mq_cmd *ret = NULL;
-
- //just naive belive everything is fine in string
- ret = malloc(sizeof(mq_cmd)); //can blow up
- ret->buf = malloc(sz);
- if (ret->buf == NULL)
- {
- PERM();
- free(ret);
- return NULL;
- }
- memset(ret->buf, 0, MQ_CMD_MSG_SIZE);
- ret->sz = sz;
- memcpy(ret->buf,str,sz);
- ret->id = id;
-
- return ret;
-}
-
-int mq_cmd_id(mq_cmd *cmd)
-{
- int i,j,strt,sz;
- int id_parse;
- char buf[16]; //fix this
- /*:[ID]:*/
-
- if (cmd == NULL)
- {
- PERM();
- return -1;
- }
-
- i = 0;
- while ((cmd->buf[i] != 0) && (i<cmd->sz))
- {
- if (cmd->buf[i] == ':')
- {
- i++;
- strt = i;
- sz = 0;
- while ((cmd->buf[i] != ':')&&
- (cmd->buf[i] != '\0')&&
- (i<cmd->sz))
- {
- sz++;
- i++;
- }
- for (j=0;j<(strt+sz)||j<15;j++)
- {
- buf[j] = cmd->buf[strt+j];
- }
- buf[j] = 0x0;
- id_parse = atoi(buf);
- return id_parse;
- }
- i++;
- }
- return -1;
-}
-
-//buf contains pointer to cmd
-//sz contains size of buf
-//%s formatting should work badly, writting to buf modifies cmd
-//be carefull
-int mq_cmd_cmd(mq_cmd *cmd, char **buf, size_t *sz)
-{
- int i,strt,cnt,l_c;
-
- if (cmd == NULL)
- {
- PERM();
- return -1;
- }
- if (buf == NULL)
- {
- PERM();
- return -1;
- }
- if (sz == NULL)
- {
- PERM();
- return -1;
- }
-
- i = 0;
- l_c = 0;
- while ((cmd->buf[i] != 0)&&(i<cmd->sz))
- {
- if (cmd->buf[i] == ':')
- {
- l_c += 1;
- if (l_c == 2)
- {
- i++;
- break;
-
- }
- }
- i++;
- }
- strt = i;
- cnt = 0;
- while ((cmd->buf[i] != 0)&&(i<cmd->sz))
- {
-
- if (cmd->buf[i] == ':')
- break;
- cnt++;
- i++;
- }
- *buf = cmd->buf+strt;
- *sz = cnt;
-
- return 0;
-}
-
-int mq_cmd_param(mq_cmd *cmd, char **param, size_t *sz)
-{
- int i,strt,l_c;
-
- i = 0;
- l_c = 0;
- while ((cmd->buf[i] != 0)&&(i<cmd->sz))
- {
- if (cmd->buf[i] == ':')
- {
- l_c += 1;
- if (l_c == 3)
- {
- i++;
- break;
- }
- }
- i++;
- }
-
- while ((cmd->buf[i] != 0)&&(i<cmd->sz))
- {
- if (cmd->buf[i] != ' ') break;
- i++;
- }
- strt = i;
- *param = cmd->buf+strt;
-
- //buffer allways ends with zero, no worries
- *sz = strlen(*param);
-
- return 0;
-}
-
-size_t mq_cmd_size(mq_cmd *cmd)
-{
- if (cmd == NULL)
- {
- PERM();
- return -1;
- }
- return cmd->sz;
-}
-
-char *mq_cmd_buf(mq_cmd *cmd)
-{
- if (cmd == NULL)
- {
- PERM();
- return NULL;
- }
-
- return cmd->buf;
-}
-
-void mq_cmd_free(mq_cmd *mq)
-{
- if (mq != NULL)
- {
- free(mq->buf);
- mq->buf = NULL;
- free(mq);
- mq = NULL;
- }
-}
-
-
-int mq_cmd_o_cmp_param(mq_cmd *cmd, char *str)
-{
- int str_sz; //get strsize from strlen()
- size_t buf_sz;
- char *buf = NULL;
-
- if (cmd == NULL)
- {
- return -1;
- }
-
- if (str == NULL)
- {
- return -1;
- }
-
- if (-1 == mq_cmd_param(cmd, &buf, &buf_sz))
- {
- return -1;
- }
-
- str_sz = strlen(str);
- if (strncmp(buf, str, str_sz) != 0)
- {
- return -1;
- }
-
- return 0;
-}
-
-int mq_cmd_o_cmp_cmd( mq_cmd *cmd, char *str)
-{
- int str_sz; //get strsize from strlen()
- size_t buf_sz;
- char *buf = NULL;
-
- if (cmd == NULL)
- {
- PERM();
- return -1;
- }
-
- if (str == NULL)
- {
- PERM();
- return -1;
- }
-
- if (-1 == mq_cmd_cmd(cmd, &buf, &buf_sz))
- {
- return -1;
- }
-
- str_sz = strlen(str);
- if (strncmp(buf, str, str_sz) != 0)
- {
- return -1;
- }
-
- return 0;
-}
-
-int mq_cmd_o_cmp_id( mq_cmd *cmd, int id)
-{
- int fret;
- if (cmd == NULL)
- {
- PERM();
- return -1;
- }
-
- if (id < 0)
- {
- PERM();
- return -1;
- }
-
- if ((fret = mq_cmd_id(cmd)) != id)
- {
- ENL();
- return -1;
- }
-
- return 0;
-}
diff --git a/mq_cmd.h b/mq_cmd.h
deleted file mode 100644
index 4a6f6ea..0000000
--- a/mq_cmd.h
+++ /dev/null
@@ -1,49 +0,0 @@
-#ifndef __AGNI_MQ_CMD_H
-#define __AGNI_MQ_CMD_H
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-
-#include "debug.h"
-
-typedef struct mq_cmd
-{
- int id;
- char *buf;
- size_t sz;
-} mq_cmd;
-
-/*
-BASIC oprations over structure, create,destroy,get data
-*/
-mq_cmd* mq_cmd_create(int id, char *cmd, size_t cmd_sz, char *param, size_t param_sz);
-//create new command from string, can set id, parsed id could be different
-mq_cmd* mq_cmd_creates(char *str, size_t sz, int id);
-//parse param from buffer
-int mq_cmd_id(mq_cmd *cmd);
-//parse command from buffer
-int mq_cmd_cmd(mq_cmd *cmd, char **buf, size_t *sz);
-//parse command param from buffer
-int mq_cmd_param(mq_cmd *cmd, char **param, size_t *sz);
-//return buffer size
-size_t mq_cmd_size(mq_cmd *cmd);
-char *mq_cmd_buf(mq_cmd *cmd);
-void mq_cmd_free(mq_cmd *mq);
-
-/*
-ADVANCED opeartions over data
-*/
-//compare with some values
-//0 - same, -1 not same values
-int mq_cmd_o_cmp_param(mq_cmd *cmd, char *str);
-int mq_cmd_o_cmp_cmd( mq_cmd *cmd, char *str);
-int mq_cmd_o_cmp_id( mq_cmd *cmd, int id);
-
-
-
-#define CMD_CREATE(ID,CMD,PARAM) mq_cmd_create(ID,CMD,strlen(CMD),PARAM,strlen(PARAM));
-#define CMD_FREE(CMD_T) mq_cmd_free(CMD_T);
-
-
-#endif \ No newline at end of file
diff --git a/mq_ntf.h b/mq_ntf.h
index 2a5ea9f..eeebf89 100644
--- a/mq_ntf.h
+++ b/mq_ntf.h
@@ -6,7 +6,6 @@
#include <string.h>
#include <mqueue.h>
-#include "mq_cmd.h"
#include "debug.h"
@@ -42,8 +41,6 @@ int mq_ntf_read(mq_ntf_mdt *mq, int dir, char *buf, size_t size);
int mq_ntf_write(mq_ntf_mdt *mq, int dir, const char *buf, size_t size);
int mq_ntf_count(mq_ntf_mdt *mq, int dir);
int mq_ntf_close(mq_ntf_mdt *mq);
-int mq_ntf_cmd_send(mq_ntf_mdt *mq, mq_cmd *cmd);
-int mq_ntf_cmd_recv(mq_ntf_mdt *mq, mq_cmd *cmd);
int mq_drain_q(mqd_t mqd);
int mq_ntf_drain(mq_ntf_mdt *mq);
int mq_ntf_getattr(mq_ntf_mdt *mq, int dir, struct mq_attr **attr);