summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFreeArtMan <dos21h@gmail.com>2017-03-16 23:12:46 +0000
committerFreeArtMan <dos21h@gmail.com>2017-03-16 23:12:46 +0000
commitb04419c4c7e485f164d6481470b2e6b0087dcac1 (patch)
tree94e07b978e28c46d4df0bb791ba9c24f5f09d5ca
parentfbba9957124bde600e89e3720377f9c3ab78e3a0 (diff)
downloadagni-b04419c4c7e485f164d6481470b2e6b0087dcac1.tar.gz
agni-b04419c4c7e485f164d6481470b2e6b0087dcac1.zip
Add token to qcmd. Added needed functions to manage that
-rw-r--r--irc_parse.c34
-rw-r--r--irc_parse.h2
-rw-r--r--tbl_qcmd.c27
-rw-r--r--tbl_qcmd.h20
4 files changed, 81 insertions, 2 deletions
diff --git a/irc_parse.c b/irc_parse.c
index 29a98dc..d7ccd03 100644
--- a/irc_parse.c
+++ b/irc_parse.c
@@ -126,6 +126,38 @@ int token_len(irc_token *tk)
return ret;
}
+irc_token* token_cpy_new(irc_token *tk)
+{
+ int i = 0;
+ irc_token *ret=NULL;
+
+ if (tk == NULL)
+ {
+ return NULL;
+ }
+
+ ret = token_create();
+ if (ret == NULL)
+ {
+ return NULL;
+ }
+
+ ret->size = tk->size;
+ ret->max_size = tk->max_size;
+ for (i=0;i<tk->size;i++)
+ {
+ irc_token_el *te = NULL;
+ te = malloc(sizeof(irc_token_el));
+ te->type = tk->tk_list[i]->type;
+ te->size = tk->tk_list[i]->size;
+ te->token = alloc_new_str_s(tk->tk_list[i]->token, tk->tk_list[i]->size);
+ ret->tk_list[i] = te;
+ te = NULL;
+ }
+
+ return ret;
+}
+
void token_destroy(irc_token *tk)
{
@@ -284,7 +316,7 @@ irc_token* irc_parse(char *str, int sz)
//*(tok[j].e+1)=0x0;
//write(0,"]\n",2);
}
- if (tok_cnt < 2 )
+ if (tok_cnt < 2 )
{
printf("Not enought tokens\n");
};
diff --git a/irc_parse.h b/irc_parse.h
index 4933f43..6366064 100644
--- a/irc_parse.h
+++ b/irc_parse.h
@@ -41,6 +41,8 @@ int token_cmp(irc_token *tk, int idx, char *str);
char* token_new_str(irc_token *tk, int idx);
//number of tokens
int token_len(irc_token *tk);
+//create new instance of token structure
+irc_token* token_cpy_new(irc_token *tk);
//clean all tokens
void token_destroy(irc_token *tk);
diff --git a/tbl_qcmd.c b/tbl_qcmd.c
index 6d7360d..e7d74ac 100644
--- a/tbl_qcmd.c
+++ b/tbl_qcmd.c
@@ -334,6 +334,26 @@ int tbl_qcmd_del(tbl_qcmd *tbl, int idx)
return ret;
}
+int tbl_qcmd_add_tok(tble_qcmd *tbl, irc_token *tk)
+{
+ if (tbl == NULL)
+ {
+ PERM();
+ return -1;
+ }
+
+ if (tk == NULL)
+ {
+ PERM();
+ return -1;
+ }
+
+ //just copy inside new token
+ tbl->tok = token_cpy_new(tk);
+
+ return 0;
+}
+
int tbl_qcmd_resp(tbl_qcmd *tbl, tble_cmd_resp *resp)
{
int ret = -1;
@@ -349,7 +369,9 @@ int tbl_qcmd_resp(tbl_qcmd *tbl, tble_cmd_resp *resp)
for (i=0;i<tbl->size;i++)
{
single_cmd = tbl->cmd[i];
- if ((single_cmd->id == resp->id))
+
+ //check this for particular checks
+ if ((single_cmd->cid == resp->qid))
{
return i;
}
@@ -558,6 +580,9 @@ int tbl_qcmd_destroy_cmd(tble_qcmd *tble)
return -1;
}
+ //?
+ //Free token list TODO
+
free(tble->cmd);
tble->cmd = NULL;
diff --git a/tbl_qcmd.h b/tbl_qcmd.h
index a872a72..d28644e 100644
--- a/tbl_qcmd.h
+++ b/tbl_qcmd.h
@@ -9,6 +9,8 @@
#include "debug.h"
#include "util.h"
+#include "irc_parse.h"
+
#define EXEC_CURRENT 0 //executes in current thread
#define EXEC_SEPERATE 1 //executes in seperate thread
@@ -67,6 +69,7 @@ typedef struct tble_qcmd
mqd_t in_q; //UNUSED
int tid; //table id
int tidx; //table unique id of executor, check if still there ;]
+ irc_token *tok; //parsed irc command, needed only by irc consumer thread
} tble_qcmd;
//list of print fields
@@ -171,6 +174,20 @@ Output:
int tbl_exec_in_s(tbl_exec *tbl, char *cmd);
/*
+add parsed token to command list
+Input:
+ tbl - executed command
+ tk - token, its going to be copies, so fill free to FREE
+Output:
+ 0 - if everything whent ok
+ -1 - if there was some kind of mistake
+*/
+int tbl_qcmd_add_tok(tble_qcmd *tbl, irc_token *tk);
+
+
+
+
+/*
if command is found then return pointer to it
if you passs pointer further then if its will be freed
or deleted from the list your programm will segfault
@@ -258,6 +275,9 @@ Output:
int tbl_qcmd_del(tbl_qcmd *tbl, int idx);
+
+
+
/*
if there is response then try to match response and return code to
executed command requester