From 05ce1932c60cc303e808255b43950f63012ca665 Mon Sep 17 00:00:00 2001 From: "Alfred E. Heggestad" Date: Sat, 28 Jan 2017 23:14:23 +0100 Subject: cmd: make struct commands opaque --- src/baresip.c | 6 +++--- src/cmd.c | 33 ++++++++++++++++++++++----------- 2 files changed, 25 insertions(+), 14 deletions(-) (limited to 'src') 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; } -- cgit v1.2.3