1#ifndef MPDSERVER_H
2#define MPDSERVER_H
3
4#include <stdbool.h>
5
6#include <sys/types.h>
7
8typedef enum {
9 MPD_VAL_INT,
10 MPD_VAL_UINT,
11 MPD_VAL_STR,
12 MPD_VAL_FLOAT,
13 MPD_VAL_BOOL,
14 MPD_VAL_RANGE,
15 MPD_VAL_EXPR,
16 MPD_VAL_CMD,
17
18 MPD_VAL_EXPR_STR, /* only used internally */
19} mpd_val_t;
20
21typedef enum {
22 MPD_OP_NONE, /* base, modified-since, AND and NOT */
23 MPD_OP_EQUAL, /* == */
24 MPD_OP_NEQUAL, /* != */
25 MPD_OP_CONTAINS, /* contains (tag only) */
26 MPD_OP_MATCH, /* =~ */
27 MPD_OP_NMATCH, /* !~ (tag only) */
28} mpd_operation_t;
29
30typedef struct _mpd_argument_t mpd_argument_t;
31
32typedef struct {
33 char *name;
34 size_t argc;
35 mpd_argument_t **argv;
36} mpd_command_t;
37
38typedef struct _mpd_expression_t mpd_expression_t;
39
40/* This data structure is a bit clumsy and might change in the future */
41struct _mpd_expression_t {
42 char *name;
43 mpd_operation_t op;
44
45 union {
46 char *str;
47 mpd_expression_t *expr;
48 } o1;
49 mpd_expression_t *next; /* only used by AND */
50};
51
52typedef struct {
53 size_t start;
54 ssize_t end; /* -1 if end is omitted */
55} mpd_range_t;
56
57struct _mpd_argument_t {
58 mpd_val_t type;
59 union {
60 int ival;
61 unsigned int uval;
62 char *sval;
63 float fval;
64 bool bval;
65 mpd_range_t rval;
66 mpd_expression_t *eval;
67 mpd_command_t *cmdval;
68 } v;
69};
70
71/* When reading mpd_parse() input from a stream it is insufficient to
72 * simply read a single line since lists are mulitline commands. */
73
74mpd_command_t *mpd_parse(char *);
75void mpd_free_command(mpd_command_t *);
76
77#endif