summaryrefslogtreecommitdiff
path: root/mq_cmd.c
diff options
context:
space:
mode:
Diffstat (limited to 'mq_cmd.c')
-rw-r--r--mq_cmd.c110
1 files changed, 96 insertions, 14 deletions
diff --git a/mq_cmd.c b/mq_cmd.c
index 8956bfc..e573721 100644
--- a/mq_cmd.c
+++ b/mq_cmd.c
@@ -23,11 +23,12 @@ mq_cmd* mq_cmd_create(int id, char *cmd, size_t cmd_sz, char *param, size_t para
ENL();
return NULL;
}
+ memset(ret,0, sizeof(mq_cmd));
ret->id = id;
ret->sz = MQ_CMD_MSG_SIZE;
- ret->buf = malloc(ret->sz);
- if (!ret->buf)
+ ret->buf = malloc(MQ_CMD_MSG_SIZE);
+ if (ret->buf == NULL)
{
ENL();
free(ret);
@@ -60,7 +61,7 @@ mq_cmd* mq_cmd_creates(char *str, size_t sz, int id)
return ret;
}
-int mq_cmd_id(mq_cmd *cmd, int *id)
+int mq_cmd_id(mq_cmd *cmd)
{
int i,j,strt,sz;
int ret=-1;
@@ -73,11 +74,6 @@ int mq_cmd_id(mq_cmd *cmd, int *id)
PERM();
return -1;
}
- if (id == NULL)
- {
- PERM();
- return -1;
- }
i = 0;
while ((cmd->buf[i] != 0) && (i<cmd->sz))
@@ -100,8 +96,7 @@ int mq_cmd_id(mq_cmd *cmd, int *id)
}
buf[j] = 0x0;
id_parse = atoi(buf);
- *id = id_parse;
- return 0;
+ return id_parse;
}
i++;
}
@@ -112,7 +107,7 @@ int mq_cmd_id(mq_cmd *cmd, int *id)
//sz contains size of buf
//%s formatting should work badly, writting to buf modifies cmd
//be carefull
-char* mq_cmd_cmd(mq_cmd *cmd, char **buf, size_t *sz)
+int mq_cmd_cmd(mq_cmd *cmd, char **buf, size_t *sz)
{
size_t sz_parse;
int i,j,strt,cnt,l_c;
@@ -121,17 +116,17 @@ char* mq_cmd_cmd(mq_cmd *cmd, char **buf, size_t *sz)
if (cmd == NULL)
{
PERM();
- return NULL;
+ return -1;
}
if (buf == NULL)
{
PERM();
- return NULL;
+ return -1;
}
if (sz == NULL)
{
PERM();
- return NULL;
+ return -1;
}
p = cmd->buf;
@@ -236,3 +231,90 @@ void mq_cmd_free(mq_cmd *mq)
}
+
+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;
+}