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
diff --git a/src/libosmo-mgcp-client/mgcp_client_vty.c b/src/libosmo-mgcp-client/mgcp_client_vty.c
index 390bacb..4f71e3d 100644
--- a/src/libosmo-mgcp-client/mgcp_client_vty.c
+++ b/src/libosmo-mgcp-client/mgcp_client_vty.c
@@ -368,36 +368,16 @@
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 @@
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)
{