12 #define CTRL_CMD_ERROR -1 13 #define CTRL_CMD_HANDLED 0 14 #define CTRL_CMD_REPLY 1 15 #define CTRL_CMD_TRAP_ID "0" 85 #define ctrl_cmd_reply_printf(cmd, fmt, args ...) \ 86 osmo_talloc_asprintf(cmd, cmd->reply, fmt, ## args) 140 #define CTRL_CMD_DEFINE_STRUCT(cmdname, cmdstr, verify_name) \ 141 static struct ctrl_cmd_element cmd_##cmdname = { \ 143 .get = &get_##cmdname, \ 144 .set = &set_##cmdname, \ 145 .verify = verify_name, \ 152 #define CTRL_HELPER_GET_INT(cmdname, dtype, element) \ 153 static int get_##cmdname(struct ctrl_cmd *cmd, void *_data) \ 155 dtype *node = cmd->node; \ 156 cmd->reply = talloc_asprintf(cmd, "%i", node->element); \ 158 cmd->reply = "OOM"; \ 159 return CTRL_CMD_ERROR; \ 161 return CTRL_CMD_REPLY; \ 168 #define CTRL_HELPER_SET_INT(cmdname, dtype, element) \ 169 static int set_##cmdname(struct ctrl_cmd *cmd, void *_data) \ 171 dtype *node = cmd->node; \ 172 int tmp = atoi(cmd->value); \ 173 node->element = tmp; \ 174 return get_##cmdname(cmd, _data); \ 181 #define CTRL_HELPER_VERIFY_RANGE(cmdname, min, max) \ 182 static int verify_##cmdname(struct ctrl_cmd *cmd, const char *value, void *_data) \ 184 int tmp = atoi(value); \ 185 if ((tmp >= min)&&(tmp <= max)) { \ 188 cmd->reply = "Input not within the range"; \ 199 #define CTRL_CMD_DEFINE_RANGE(cmdname, cmdstr, dtype, element, min, max) \ 200 CTRL_HELPER_GET_INT(cmdname, dtype, element) \ 201 CTRL_HELPER_SET_INT(cmdname, dtype, element) \ 202 CTRL_HELPER_VERIFY_RANGE(cmdname, min, max) \ 203 CTRL_CMD_DEFINE_STRUCT(cmdname, cmdstr, verify_##cmdname) 209 #define CTRL_HELPER_GET_STRING(cmdname, dtype, element) \ 210 static int get_##cmdname(struct ctrl_cmd *cmd, void *_data) \ 212 dtype *data = cmd->node; \ 213 cmd->reply = talloc_asprintf(cmd, "%s", data->element); \ 215 cmd->reply = "OOM"; \ 216 return CTRL_CMD_ERROR; \ 218 return CTRL_CMD_REPLY; \ 225 #define CTRL_HELPER_SET_STRING(cmdname, dtype, element) \ 226 static int set_##cmdname(struct ctrl_cmd *cmd, void *_data) \ 228 dtype *data = cmd->node; \ 229 osmo_talloc_replace_string(cmd->node, &data->element, cmd->value); \ 230 return get_##cmdname(cmd, _data); \ 240 #define CTRL_CMD_DEFINE_STRING(cmdname, cmdstr, dtype, element) \ 241 CTRL_HELPER_GET_STRING(cmdname, dtype, element) \ 242 CTRL_HELPER_SET_STRING(cmdname, dtype, element) \ 243 CTRL_CMD_DEFINE_STRUCT(cmdname, cmdstr, NULL) 248 #define CTRL_CMD_DEFINE(cmdname, cmdstr) \ 249 static int get_##cmdname(struct ctrl_cmd *cmd, void *data); \ 250 static int set_##cmdname(struct ctrl_cmd *cmd, void *data); \ 251 static int verify_##cmdname(struct ctrl_cmd *cmd, const char *value, void *data); \ 252 CTRL_CMD_DEFINE_STRUCT(cmdname, cmdstr, verify_##cmdname) 257 #define CTRL_CMD_DEFINE_RO(cmdname, cmdstr) \ 258 static int get_##cmdname(struct ctrl_cmd *cmd, void *data); \ 259 static int set_##cmdname(struct ctrl_cmd *cmd, void *data) \ 261 cmd->reply = "Read Only attribute"; \ 262 return CTRL_CMD_ERROR; \ 264 static int verify_##cmdname(struct ctrl_cmd *cmd, const char *value, void *data) \ 266 cmd->reply = "Read Only attribute"; \ 269 CTRL_CMD_DEFINE_STRUCT(cmdname, cmdstr, verify_##cmdname) 274 #define CTRL_CMD_DEFINE_WO(cmdname, cmdstr) \ 275 static int set_##cmdname(struct ctrl_cmd *cmd, void *data); \ 276 static int get_##cmdname(struct ctrl_cmd *cmd, void *data) \ 278 cmd->reply = "Write Only attribute"; \ 279 return CTRL_CMD_ERROR; \ 281 static int verify_##cmdname(struct ctrl_cmd *cmd, const char *val, void *data); \ 282 CTRL_CMD_DEFINE_STRUCT(cmdname, cmdstr, verify_##cmdname) 287 #define CTRL_CMD_DEFINE_WO_NOVRF(cmdname, cmdstr) \ 288 static int set_##cmdname(struct ctrl_cmd *cmd, void *data); \ 289 static int get_##cmdname(struct ctrl_cmd *cmd, void *data) \ 291 cmd->reply = "Write Only attribute"; \ 292 return CTRL_CMD_ERROR; \ 294 static int verify_##cmdname(struct ctrl_cmd *cmd, const char *val, void *data) \ 298 CTRL_CMD_DEFINE_STRUCT(cmdname, cmdstr, verify_##cmdname) Represents a single ctrl connection.
Definition: control_cmd.h:45
Definition: control_cmd.h:27
Definition: control_cmd.h:35
ctrl_node_type
The class of node at which a ctrl command is registered to.
Definition: control_cmd.h:20
Definition: control_cmd.h:23
char * variable
name of the variable
Definition: control_cmd.h:76
Definition: control_cmd.h:25
void(* closed_cb)(struct ctrl_connection *conn)
Callback if the connection was closed.
Definition: control_cmd.h:55
struct llist_head list_entry
Definition: control_cmd.h:46
ctrl_type
Ctrl command types (GET, SET, ...)
Definition: control_cmd.h:31
struct ctrl_connection * ccon
connection through which the command was received
Definition: control_cmd.h:69
Definition: control_cmd.h:21
Definition: control_cmd.h:113
Definition: control_cmd.h:32
struct ctrl_cmd * ctrl_cmd_create(void *ctx, enum ctrl_type)
Allocate a control command of given type.
Definition: control_cmd.c:238
Definition: control_cmd.h:107
struct ctrl_cmd * ctrl_cmd_cpy(void *ctx, struct ctrl_cmd *cmd)
Perform a deepl copy of the given cmd, allocating memory from ctx.
Definition: control_cmd.c:254
struct ctrl_cmd_def * ctrl_cmd_def_make(const void *ctx, struct ctrl_cmd *cmd, void *data, unsigned int secs)
Build a deferred control command state and keep it the per-connection list of deferred commands...
Definition: control_cmd.c:586
void * data
Definition: control_cmd.h:116
char * value
value of the specified CTRL variable
Definition: control_cmd.h:78
struct msgb * ctrl_cmd_make(struct ctrl_cmd *cmd)
Encode a given CTRL command from its parsed form into a message buffer.
Definition: control_cmd.c:517
int ctrl_cmd_install(enum ctrl_node_type node, struct ctrl_cmd_element *cmd)
Install a given command definition at a given CTRL node.
Definition: control_cmd.c:213
void * node
node of the specified variable
Definition: control_cmd.h:74
struct ctrl_cmd * ctrl_cmd_parse2(void *ctx, struct msgb *msg)
Parse/Decode CTRL from Message buffers into command struct.
Definition: control_cmd.c:322
char * reply
respnse message string
Definition: control_cmd.h:80
struct msgb * pending_msg
Buffer for partial input data.
Definition: control_cmd.h:52
int ctrl_cmd_send_to_all(struct ctrl_handle *ctrl, struct ctrl_cmd *cmd)
Send a CTRL command to all connections.
Definition: control_if.c:104
Definition: control_cmd.h:34
char * cmd
Definition: control_cmd.h:108
struct ctrl_cmd * ctrl_cmd_parse(void *ctx, struct msgb *msg)
Parse/Decode CTRL from Message buffers into command struct.
Definition: control_cmd.c:295
char * id
Definition: control_cmd.h:72
int ctrl_cmd_def_send(struct ctrl_cmd_def *cd)
Send the response to a deferred ctrl command.
Definition: control_cmd.c:625
struct ctrl_cmd * ctrl_cmd_parse3(void *ctx, struct msgb *msg, bool *parse_failed)
Parse/Decode CTRL from Message buffers into command struct.
Definition: control_cmd.c:336
Definition: control_cmd.h:38
int ctrl_cmd_send(struct osmo_wqueue *queue, struct ctrl_cmd *cmd)
Encode a CTRL command and append it to the given write queue.
Definition: control_if.c:122
int nr_commands
Definition: control_cmd.h:89
Definition: control_cmd.h:22
Definition: control_cmd.h:33
int ctrl_cmd_def_is_zombie(struct ctrl_cmd_def *cd)
Determine if the given deferred control command is still alive or a zombie.
Definition: control_cmd.c:608
const char * name
textual name/id of the CTRL command
Definition: control_cmd.h:97
char ** command
Definition: control_cmd.h:90
Definition: control_cmd.h:24
Definition: control_if.h:14
struct llist_head def_cmds
Pending deferred command responses for this connection.
Definition: control_cmd.h:61
int ctrl_cmd_exec(vector vline, struct ctrl_cmd *command, vector node, void *data)
Execute a given received command.
Definition: control_cmd.c:98
Definition: control_cmd.h:26
struct llist_head cmds
Pending commands for this connection.
Definition: control_cmd.h:58
Represents a single ctrl command after parsing.
Definition: control_cmd.h:67
const struct value_string ctrl_type_vals[]
human-readable string names for ctrl_type
Definition: control_cmd.c:47
Definition: control_cmd.h:36
Definition: control_cmd.h:88
struct ctrl_cmd * cmd
Definition: control_cmd.h:115
struct ctrl_cmd * ctrl_cmd_trap(struct ctrl_cmd *cmd)
Copy given cmd and convert copy to CTRL_TYPE_TRAP.
Definition: control_if.c:168
struct ctrl_cmd_def * defer
state representing deferred (async) response, if any
Definition: control_cmd.h:82
Definition: control_cmd.h:37
struct osmo_wqueue write_queue
The queue for sending data back.
Definition: control_cmd.h:49
Implementation of a given CTRL command.
Definition: control_cmd.h:95