diff options
author | Daniel Willmann <daniel@totalueberwachung.de> | 2011-03-17 15:37:54 +0100 |
---|---|---|
committer | Harald Welte <laforge@gnumonks.org> | 2014-08-21 15:34:12 +0200 |
commit | 8b7a9626a20ee7de20d1e09cfa1e8491a2325d52 (patch) | |
tree | c685cc4491dabb09c81b32b7de4f479691855f6c /openbsc | |
parent | e9f5894e2c72c39e55bb9173470dff40de61a326 (diff) |
libctrl: Add ctrl_cmd_cpy() to copy a command
Diffstat (limited to 'openbsc')
-rw-r--r-- | openbsc/include/openbsc/control_cmd.h | 1 | ||||
-rw-r--r-- | openbsc/src/libctrl/control_cmd.c | 36 |
2 files changed, 37 insertions, 0 deletions
diff --git a/openbsc/include/openbsc/control_cmd.h b/openbsc/include/openbsc/control_cmd.h index c78b3dc1..c94c7b57 100644 --- a/openbsc/include/openbsc/control_cmd.h +++ b/openbsc/include/openbsc/control_cmd.h @@ -77,6 +77,7 @@ int ctrl_cmd_handle(struct ctrl_cmd *cmd, void *data); int ctrl_cmd_send(struct osmo_wqueue *queue, struct ctrl_cmd *cmd); struct ctrl_cmd *ctrl_cmd_parse(void *ctx, struct msgb *msg); struct msgb *ctrl_cmd_make(struct ctrl_cmd *cmd); +struct ctrl_cmd *ctrl_cmd_cpy(void *ctx, struct ctrl_cmd *cmd); #define CTRL_CMD_DEFINE_RANGE(cmdname, cmdstr, dtype, element, min, max) \ int get_##cmdname(struct ctrl_cmd *cmd, void *data) \ diff --git a/openbsc/src/libctrl/control_cmd.c b/openbsc/src/libctrl/control_cmd.c index 06af3b32..b5cff685 100644 --- a/openbsc/src/libctrl/control_cmd.c +++ b/openbsc/src/libctrl/control_cmd.c @@ -237,6 +237,42 @@ int ctrl_cmd_install(enum ctrl_node_type node, struct ctrl_cmd_element *cmd) return 0; } +struct ctrl_cmd *ctrl_cmd_cpy(void *ctx, struct ctrl_cmd *cmd) +{ + struct ctrl_cmd *cmd2; + + cmd2 = talloc_zero(ctx, struct ctrl_cmd); + if (!cmd2) + return NULL; + + cmd2->type = cmd->type; + if (cmd->id) { + cmd2->id = talloc_strdup(cmd2, cmd->id); + if (!cmd2->id) + goto err; + } + if (cmd->variable) { + cmd2->variable = talloc_strdup(cmd2, cmd->variable); + if (!cmd2->variable) + goto err; + } + if (cmd->value) { + cmd2->value = talloc_strdup(cmd2, cmd->value); + if (!cmd2->value) + goto err; + } + if (cmd->reply) { + cmd2->reply = talloc_strdup(cmd2, cmd->reply); + if (!cmd2->reply) + goto err; + } + + return cmd2; +err: + talloc_free(cmd2); + return NULL; +} + struct ctrl_cmd *ctrl_cmd_parse(void *ctx, struct msgb *msg) { char *str, *tmp, *saveptr = NULL; |