summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlfred E. Heggestad <alfred.heggestad@gmail.com>2017-01-28 23:14:23 +0100
committerAlfred E. Heggestad <alfred.heggestad@gmail.com>2017-01-28 23:14:23 +0100
commit05ce1932c60cc303e808255b43950f63012ca665 (patch)
tree88602e09542e3aa0947edf75872a5493d6e86a48 /src
parent903ce9869c933e4f13995cd9f10c1498665cfd58 (diff)
cmd: make struct commands opaque
Diffstat (limited to 'src')
-rw-r--r--src/baresip.c6
-rw-r--r--src/cmd.c33
2 files changed, 25 insertions, 14 deletions
diff --git a/src/baresip.c b/src/baresip.c
index 3ef745e..07dfbca 100644
--- a/src/baresip.c
+++ b/src/baresip.c
@@ -15,7 +15,7 @@
static struct baresip {
struct network *net;
struct contacts contacts;
- struct commands commands;
+ struct commands *commands;
struct player *player;
struct list mnatl;
struct list mencl;
@@ -61,7 +61,7 @@ int baresip_init(struct config *cfg, bool prefer_ipv6)
void baresip_close(void)
{
baresip.player = mem_deref(baresip.player);
- cmd_close(&baresip.commands);
+ baresip.commands = mem_deref(baresip.commands);
contact_close(&baresip.contacts);
baresip.net = mem_deref(baresip.net);
@@ -82,7 +82,7 @@ struct contacts *baresip_contacts(void)
struct commands *baresip_commands(void)
{
- return &baresip.commands;
+ return baresip.commands;
}
diff --git a/src/cmd.c b/src/cmd.c
index 14b0ee1..78c3522 100644
--- a/src/cmd.c
+++ b/src/cmd.c
@@ -28,6 +28,10 @@ struct cmd_ctx {
bool is_long;
};
+struct commands {
+ struct list cmdl; /**< List of command blocks (struct cmds) */
+};
+
static int cmd_print_all(struct re_printf *pf,
const struct commands *commands,
@@ -51,6 +55,14 @@ static void ctx_destructor(void *arg)
}
+static void commands_destructor(void *data)
+{
+ struct commands *commands = data;
+
+ list_flush(&commands->cmdl);
+}
+
+
static int ctx_alloc(struct cmd_ctx **ctxp, const struct cmd *cmd)
{
struct cmd_ctx *ctx;
@@ -703,21 +715,20 @@ int cmd_print(struct re_printf *pf, const struct commands *commands)
}
-int cmd_init(struct commands *commands)
+int cmd_init(struct commands **commandsp)
{
- if (!commands)
- return EINVAL;
+ struct commands *commands;
- list_init(&commands->cmdl);
+ if (!commandsp)
+ return EINVAL;
- return 0;
-}
+ commands = mem_zalloc(sizeof(*commands), commands_destructor);
+ if (!commands)
+ return ENOMEM;
+ list_init(&commands->cmdl);
-void cmd_close(struct commands *commands)
-{
- if (!commands)
- return;
+ *commandsp = commands;
- list_flush(&commands->cmdl);
+ return 0;
}