32dcffac1de2d774bbdab8bdc1e1d5d5bf3be7bf
[multipath-tools/.git] / multipathd / cli.h
1 #ifndef _CLI_H_
2 #define _CLI_H_
3
4 #include <stdint.h>
5
6 enum {
7         __LIST,
8         __ADD,
9         __DEL,
10         __SWITCH,
11         __SUSPEND,
12         __RESUME,
13         __REINSTATE,
14         __FAIL,
15         __RESIZE,
16         __RESET,
17         __RELOAD,
18         __FORCEQ,
19         __DISABLEQ,
20         __RESTOREQ,
21         __PATHS,
22         __MAPS,
23         __PATH,
24         __MAP,
25         __GROUP,
26         __RECONFIGURE,
27         __DAEMON,
28         __STATUS,
29         __STATS,
30         __TOPOLOGY,
31         __CONFIG,
32         __BLACKLIST,
33         __DEVICES,
34         __RAW,
35         __WILDCARDS,
36         __QUIT,
37         __SHUTDOWN,
38         __GETPRSTATUS,
39         __SETPRSTATUS,
40         __UNSETPRSTATUS,
41         __FMT,
42         __JSON,
43         __GETPRKEY,
44         __SETPRKEY,
45         __UNSETPRKEY,
46         __KEY,
47         __LOCAL,
48 };
49
50 #define LIST            (1 << __LIST)
51 #define ADD             (1 << __ADD)
52 #define DEL             (1 << __DEL)
53 #define SWITCH          (1 << __SWITCH)
54 #define SUSPEND         (1 << __SUSPEND)
55 #define RESUME          (1 << __RESUME)
56 #define REINSTATE       (1 << __REINSTATE)
57 #define FAIL            (1 << __FAIL)
58 #define RESIZE          (1 << __RESIZE)
59 #define RESET           (1 << __RESET)
60 #define RELOAD          (1 << __RELOAD)
61 #define FORCEQ          (1 << __FORCEQ)
62 #define DISABLEQ        (1 << __DISABLEQ)
63 #define RESTOREQ        (1 << __RESTOREQ)
64 #define PATHS           (1 << __PATHS)
65 #define MAPS            (1 << __MAPS)
66 #define PATH            (1 << __PATH)
67 #define MAP             (1 << __MAP)
68 #define GROUP           (1 << __GROUP)
69 #define RECONFIGURE     (1 << __RECONFIGURE)
70 #define DAEMON          (1 << __DAEMON)
71 #define STATUS          (1 << __STATUS)
72 #define STATS           (1 << __STATS)
73 #define TOPOLOGY        (1 << __TOPOLOGY)
74 #define CONFIG          (1 << __CONFIG)
75 #define BLACKLIST       (1 << __BLACKLIST)
76 #define DEVICES         (1 << __DEVICES)
77 #define RAW             (1 << __RAW)
78 #define COUNT           (1 << __COUNT)
79 #define WILDCARDS       (1 << __WILDCARDS)
80 #define QUIT            (1 << __QUIT)
81 #define SHUTDOWN        (1 << __SHUTDOWN)
82 #define GETPRSTATUS     (1ULL << __GETPRSTATUS)
83 #define SETPRSTATUS     (1ULL << __SETPRSTATUS)
84 #define UNSETPRSTATUS   (1ULL << __UNSETPRSTATUS)
85 #define FMT             (1ULL << __FMT)
86 #define JSON            (1ULL << __JSON)
87 #define GETPRKEY        (1ULL << __GETPRKEY)
88 #define SETPRKEY        (1ULL << __SETPRKEY)
89 #define UNSETPRKEY      (1ULL << __UNSETPRKEY)
90 #define KEY             (1ULL << __KEY)
91 #define LOCAL           (1ULL << __LOCAL)
92
93 #define INITIAL_REPLY_LEN       1200
94
95 #define REALLOC_REPLY(r, a, m)                                  \
96         do {                                                    \
97                 if ((a)) {                                      \
98                         char *tmp = (r);                        \
99                                                                 \
100                         if (m >= MAX_REPLY_LEN) {               \
101                                 condlog(1, "Warning: max reply length exceeded"); \
102                                 free(tmp);                      \
103                                 (r) = NULL;                     \
104                         } else {                                \
105                                 (r) = REALLOC((r), (m) * 2);    \
106                                 if ((r)) {                      \
107                                         memset((r) + (m), 0, (m)); \
108                                         (m) *= 2;               \
109                                 }                               \
110                                 else                            \
111                                         free(tmp);              \
112                         }                                       \
113                 }                                               \
114         } while (0)
115
116 struct key {
117         char * str;
118         char * param;
119         uint64_t code;
120         int has_param;
121 };
122
123 struct handler {
124         uint64_t fingerprint;
125         int locked;
126         int (*fn)(void *, char **, int *, void *);
127 };
128
129 int alloc_handlers (void);
130 int add_handler (uint64_t fp, int (*fn)(void *, char **, int *, void *));
131 int set_handler_callback (uint64_t fp, int (*fn)(void *, char **, int *, void *));
132 int set_unlocked_handler_callback (uint64_t fp, int (*fn)(void *, char **, int *, void *));
133 int parse_cmd (char * cmd, char ** reply, int * len, void *, int);
134 int load_keys (void);
135 char * get_keyparam (vector v, uint64_t code);
136 void free_keys (vector vec);
137 void free_handlers (void);
138 int cli_init (void);
139 void cli_exit(void);
140 char * key_generator (const char * str, int state);
141
142 #endif /* _CLI_H_ */