mgcp-client: Refactor system keeping old users not calling mgcp_client_pool_config_write() working

Move the regular writing logic to a subfunction, and raise the flag only
on one of them.
This simplifies the code paths but not marking stuff true and false over
the same code path.

Change-Id: I070798863f2bdc253df004a63262d4bcd529348f
This commit is contained in:
Pau Espin 2022-10-19 17:13:20 +02:00
parent 2172f402a5
commit 3a914e33e9
1 changed files with 24 additions and 22 deletions

View File

@ -368,36 +368,16 @@ void mgcp_client_vty_init(void *talloc_ctx, int node, struct mgcp_client_conf *c
vty_init_common(talloc_ctx, node);
}
/* Deprecated, used for backward compatibility with older users which didn't call
* mgcp_client_pool_config_write(): */
/* Mark whether user called mgcp_client_pool_config_write() and hence support new API */
static bool mgcp_client_pool_config_write_called = false;
static int config_write_pool(struct vty *vty)
{
int rc;
if (mgcp_client_pool_config_write_called)
return CMD_SUCCESS;
rc = mgcp_client_pool_config_write(vty, NULL);
/* mgcp_client_pool_config_write sets this to true, let's reset it */
mgcp_client_pool_config_write_called = false;
return rc;
}
/*! Write out MGCP client config to VTY.
* \param[in] vty VTY to which we should print.
* \param[in] indent string used for indentation (e.g. " ").
If NULL, indentation passed during mgcp_client_pool_vty_init() will be used.
* \returns CMD_SUCCESS on success, CMD_WARNING on error */
int mgcp_client_pool_config_write(struct vty *vty, const char *indent)
static int _mgcp_client_pool_config_write(struct vty *vty, const char *indent)
{
struct mgcp_client_pool *pool = global_mgcp_client_pool;
struct mgcp_client_pool_member *pool_member;
unsigned int subindent_buf_len;
char *subindent;
/* Tell internal node write function that the user supports calling proper API: */
mgcp_client_pool_config_write_called = true;
if (!indent)
indent = pool->vty_indent ? : "";
subindent_buf_len = strlen(indent) + 1 + 1;
@ -424,6 +404,28 @@ int mgcp_client_pool_config_write(struct vty *vty, const char *indent)
return CMD_SUCCESS;
}
/* Deprecated, used for backward compatibility with older users which didn't call
* mgcp_client_pool_config_write(): */
static int config_write_pool(struct vty *vty)
{
if (mgcp_client_pool_config_write_called)
return CMD_SUCCESS;
return _mgcp_client_pool_config_write(vty, NULL);
}
/*! Write out MGCP client config to VTY.
* \param[in] vty VTY to which we should print.
* \param[in] indent string used for indentation (e.g. " ").
If NULL, indentation passed during mgcp_client_pool_vty_init() will be used.
* \returns CMD_SUCCESS on success, CMD_WARNING on error */
int mgcp_client_pool_config_write(struct vty *vty, const char *indent)
{
/* Tell internal node write function that the user supports calling proper API: */
mgcp_client_pool_config_write_called = true;
return _mgcp_client_pool_config_write(vty, indent);
}
DEFUN_ATTR(cfg_mgw,
cfg_mgw_cmd, "mgw <0-255>", "Select a MGCP client config to setup\n" "reference number\n", CMD_ATTR_IMMEDIATE)
{