summaryrefslogtreecommitdiff
path: root/mq_cmd.h
blob: e83cf3e4596afb601a8ec3aa8e0571934611982d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#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