From 73b9d6dd6f3ed6db9873c3f66732534c722b1564 Mon Sep 17 00:00:00 2001 From: Guillem Jover Date: Tue, 28 Jun 2022 00:08:27 +0200 Subject: [PATCH] TT#181513 dialog: Add a new RCP command to get all dialog profiles The 'dlg.profile_get_size' is specified to return a single value, so we cannot return a list, otherwise on the XMLRPC interface it gets serialized into a concatenated list of structs, instead of an actual array of structs. Instead we remove the previous overloaded semantics and add a new command that returns a list, and has a more explicit plural name following the existing naming convention. Fixes: commit 7168dd66dbd1250d93f920ec7cbe5bf33b66f3fa Change-Id: Ib4a620ed680fac340bf4926dc0f1529195c9818c --- ...rt-profile_get_size-for-all-profiles.patch | 165 +++++++++--------- 1 file changed, 86 insertions(+), 79 deletions(-) diff --git a/debian/patches/sipwise/dialog-support-profile_get_size-for-all-profiles.patch b/debian/patches/sipwise/dialog-support-profile_get_size-for-all-profiles.patch index bbe979932..edf8840e5 100644 --- a/debian/patches/sipwise/dialog-support-profile_get_size-for-all-profiles.patch +++ b/debian/patches/sipwise/dialog-support-profile_get_size-for-all-profiles.patch @@ -3,77 +3,80 @@ Date: Mon, 27 Jun 2022 21:04:29 +0200 Subject: dialog: support profile_get_size for all profiles --- - src/modules/dialog/dialog.c | 38 +++++++++++++++++++++++---------- - src/modules/dialog/dlg_profile.c | 8 +++++++ - src/modules/dialog/dlg_profile.h | 5 +++++ - src/modules/dialog/doc/dialog_admin.xml | 7 +++++- - 4 files changed, 46 insertions(+), 12 deletions(-) + src/modules/dialog/dialog.c | 35 ++++++++++++++++++++++++++++++++ + src/modules/dialog/dlg_profile.c | 8 +++++++ + src/modules/dialog/dlg_profile.h | 5 ++++ + src/modules/dialog/doc/dialog_admin.xml | 22 ++++++++++++++++++++ + 4 files changed, 70 insertions(+) -diff --git a/src/modules/dialog/dialog.c b/src/modules/dialog/dialog.c -index 2082a41..8ab4f13 100644 --- a/src/modules/dialog/dialog.c +++ b/src/modules/dialog/dialog.c -@@ -2739,19 +2739,34 @@ static void internal_rpc_print_single_dlg(rpc_t *rpc, void *c, int with_context) - * \param profile_name the given profile - * \param value the given profile value - */ --static void internal_rpc_profile_get_size(rpc_t *rpc, void *c, str *profile_name, -- str *value) { -+static void internal_rpc_profile_get_size( -+ rpc_t *rpc, void *c, str *profile_name, str *value) +@@ -2756,6 +2756,33 @@ static void internal_rpc_profile_get_siz + } + + /*! ++ * \brief Helper function that outputs the sizes of all profiles via the RPC interface ++ * \see rpc_profile_get_sizes ++ * \see rpc_profile_w_value_get_sizes ++ * \param rpc RPC node that should be filled ++ * \param c RPC void pointer ++ */ ++static void internal_rpc_profile_get_sizes(rpc_t *rpc, void *c) +{ + void *h; - unsigned int size; - dlg_profile_table_t *profile; - -- profile = search_dlg_profile( profile_name ); -- if (!profile) { -- rpc->fault(c, 404, "Profile not found: %.*s", -- profile_name->len, profile_name->s); -- return; -+ if(profile_name == NULL) { -+ profile = get_first_dlg_profile(); -+ for(; profile; profile = profile->next) { -+ size = get_profile_size(profile, NULL); -+ rpc->add(c, "{", &h); -+ if(rpc->struct_add(h, "Sd", "name", &profile->name, "size", size) -+ < 0) { -+ rpc->fault(c, 500, "Server failure"); -+ return; -+ } -+ } -+ } else { -+ profile = search_dlg_profile(profile_name); -+ if(!profile) { -+ rpc->fault(c, 404, "Profile not found: %.*s", profile_name->len, -+ profile_name->s); ++ unsigned int size; ++ dlg_profile_table_t *profile; ++ ++ profile = get_first_dlg_profile(); ++ for (; profile; profile = profile->next) { ++ size = get_profile_size(profile, NULL); ++ rpc->add(c, "{", &h); ++ if (rpc->struct_add(h, "Sd", ++ "name", &profile->name, ++ "size", size) < 0) { ++ rpc->fault(c, 500, "Server failure"); + return; + } -+ size = get_profile_size(profile, value); -+ rpc->add(c, "d", size); ++ } ++ return; ++} ++ ++/*! + * \brief Helper function that outputs the dialogs belonging to a given profile via the RPC interface + * \see rpc_profile_print_dlgs + * \see rpc_profile_w_value_print_dlgs +@@ -2847,6 +2874,9 @@ static const char *rpc_dlg_set_state_doc + static const char *rpc_profile_get_size_doc[2] = { + "Returns the number of dialogs belonging to a profile", 0 + }; ++static const char *rpc_profile_get_sizes_doc[2] = { ++ "Returns the number of dialogs belonging to all profiles", 0 ++}; + static const char *rpc_profile_print_dlgs_doc[2] = { + "Lists all the dialogs belonging to a profile", 0 + }; +@@ -3052,6 +3082,10 @@ static void rpc_profile_get_size(rpc_t * } -- size = get_profile_size(profile, value); -- rpc->add(c, "d", size); return; } - -@@ -3044,8 +3059,9 @@ static void rpc_profile_get_size(rpc_t *rpc, void *c) { ++static void rpc_profile_get_sizes(rpc_t *rpc, void *c) { ++ internal_rpc_profile_get_sizes(rpc, c); ++ return; ++} + static void rpc_profile_print_dlgs(rpc_t *rpc, void *c) { str profile_name = {NULL,0}; str value = {NULL,0}; - -- if (rpc->scan(c, ".S", &profile_name) < 1) return; -- if (rpc->scan(c, "*.S", &value) > 0) { -+ if (rpc->scan(c, ".S", &profile_name) < 1){ -+ internal_rpc_profile_get_size(rpc, c, NULL, NULL); -+ } else if (rpc->scan(c, "*.S", &value) > 0) { - internal_rpc_profile_get_size(rpc, c, &profile_name, &value); - } else { - internal_rpc_profile_get_size(rpc, c, &profile_name, NULL); -diff --git a/src/modules/dialog/dlg_profile.c b/src/modules/dialog/dlg_profile.c -index f9ad20f..0d3e62f 100644 +@@ -3469,6 +3503,7 @@ static rpc_export_t rpc_methods[] = { + {"dlg.dlg_list_ctx", rpc_print_dlg_ctx, rpc_print_dlg_ctx_doc, 0}, + {"dlg.end_dlg", rpc_end_dlg_entry_id, rpc_end_dlg_entry_id_doc, 0}, + {"dlg.profile_get_size", rpc_profile_get_size, rpc_profile_get_size_doc, 0}, ++ {"dlg.profile_get_sizes", rpc_profile_get_sizes, rpc_profile_get_sizes_doc, RET_ARRAY}, + {"dlg.profile_list", rpc_profile_print_dlgs, rpc_profile_print_dlgs_doc, RET_ARRAY}, + {"dlg.bridge_dlg", rpc_dlg_bridge, rpc_dlg_bridge_doc, 0}, + {"dlg.terminate_dlg", rpc_dlg_terminate_dlg, rpc_dlg_terminate_dlg_doc, 0}, --- a/src/modules/dialog/dlg_profile.c +++ b/src/modules/dialog/dlg_profile.c -@@ -126,6 +126,14 @@ int add_profile_definitions( char* profiles, unsigned int has_value) +@@ -126,6 +126,14 @@ int add_profile_definitions( char* profi return 0; } @@ -88,11 +91,9 @@ index f9ad20f..0d3e62f 100644 /*! * \brief Search a dialog profile in the global list -diff --git a/src/modules/dialog/dlg_profile.h b/src/modules/dialog/dlg_profile.h -index 3dc7be8..7a4f8b0 100644 --- a/src/modules/dialog/dlg_profile.h +++ b/src/modules/dialog/dlg_profile.h -@@ -108,6 +108,11 @@ int add_profile_definitions( char* profiles, unsigned int has_value); +@@ -108,6 +108,11 @@ int add_profile_definitions( char* profi */ void destroy_dlg_profiles(void); @@ -104,28 +105,34 @@ index 3dc7be8..7a4f8b0 100644 /*! * \brief Search a dialog profile in the global list -diff --git a/src/modules/dialog/doc/dialog_admin.xml b/src/modules/dialog/doc/dialog_admin.xml -index 6fcaaf7..aca75f5 100644 --- a/src/modules/dialog/doc/dialog_admin.xml +++ b/src/modules/dialog/doc/dialog_admin.xml -@@ -2829,7 +2829,8 @@ dlg_reset_property("timeout-noreset"); -
- dlg.profile_get_size - -- Returns the number of dialogs belonging to a profile. If the profile -+ Returns the number of dialogs belonging to a profile. If no profile is -+ passed, all possible profiles are returned with their size. If the profile - supports values, the check can be reinforced to take into account a - specific value - how many dialogs were inserted into the profile with - a specific value. If no value is passed, only the simply belonging of -@@ -2839,6 +2840,10 @@ dlg_reset_property("timeout-noreset"); - Name: dlg.profile_get_size - Parameters: - +@@ -2856,6 +2856,28 @@ dlg_reset_property("timeout-noreset"); + +
+ ++
++ dlg.profile_get_sizes ++ ++ Returns a list if structs with the profile name and number of dialogs ++ belonging to that profile. ++ ++ Name: dlg.profile_get_sizes ++ Parameters: ++ + + NULL - returns a list of the profiles with + their size. + - - profile - name of the profile to get the - value for. ++ ++ RPC Command Format: ++ ++... ++&kamcmd; dlg.dlg.profile_get_sizes ++... ++ ++
++ +
+ dlg.profile_list +