From 04a5bf19c439362ffe2d275ac843c64c46a3c9a5 Mon Sep 17 00:00:00 2001 From: Victor Seva Date: Tue, 26 Mar 2024 11:35:44 +0100 Subject: [PATCH] MT#59738 cfgtutils: expose second optional str for locks Change-Id: I35410282324d7806988a69ba7b6315e3f968680e (cherry picked from commit a770a9a0638fc02a6f71d868ea1895f13ba2760c) (cherry picked from commit c3d620772e5181e63b3f6d38e5926952b38b5add) --- debian/patches/series | 2 + ...support-second-str-for-cfgutils-lock.patch | 78 +++++++ ...-optional-second-string-key-for-lock.patch | 219 ++++++++++++++++++ 3 files changed, 299 insertions(+) create mode 100644 debian/patches/sipwise/app_lua_sr-support-second-str-for-cfgutils-lock.patch create mode 100644 debian/patches/sipwise/cfgutils-expose-optional-second-string-key-for-lock.patch diff --git a/debian/patches/series b/debian/patches/series index 477754843..22cb47304 100644 --- a/debian/patches/series +++ b/debian/patches/series @@ -95,6 +95,8 @@ sipwise/dialog-support-profile_get_size-for-all-profiles.patch sipwise/rtpengine-set-mime-content-length.patch sipwise/presence_vqr.patch sipwise/dialog-dlg_get_ttag.patch +sipwise/cfgutils-expose-optional-second-string-key-for-lock.patch +sipwise/app_lua_sr-support-second-str-for-cfgutils-lock.patch ### active development # ### Don't just put stuff in any order diff --git a/debian/patches/sipwise/app_lua_sr-support-second-str-for-cfgutils-lock.patch b/debian/patches/sipwise/app_lua_sr-support-second-str-for-cfgutils-lock.patch new file mode 100644 index 000000000..882eff035 --- /dev/null +++ b/debian/patches/sipwise/app_lua_sr-support-second-str-for-cfgutils-lock.patch @@ -0,0 +1,78 @@ +From: Victor Seva +Date: Tue, 26 Mar 2024 11:54:46 +0100 +Subject: app_lua_sr: support second str for cfgutils lock + +--- + src/modules/app_lua_sr/app_lua_sr_exp.c | 30 ++++++++++++++++++++++++------ + 1 file changed, 24 insertions(+), 6 deletions(-) + +diff --git a/src/modules/app_lua_sr/app_lua_sr_exp.c b/src/modules/app_lua_sr/app_lua_sr_exp.c +index 522f0cf..80a4cb6 100644 +--- a/src/modules/app_lua_sr/app_lua_sr_exp.c ++++ b/src/modules/app_lua_sr/app_lua_sr_exp.c +@@ -2783,20 +2783,29 @@ static const luaL_Reg _sr_sanity_Map[] = { + static int lua_sr_cfgutils_lock(lua_State *L) + { + int ret; +- str lkey; ++ str lkey, lkey2; + + if(!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_CFGUTILS)) { + LM_WARN("weird: cfgutils function executed but module not " + "registered\n"); + return app_lua_return_error(L); + } +- if(lua_gettop(L) != 1) { ++ ret = lua_gettop(L); ++ if(ret < 1 || ret > 3) { + LM_WARN("invalid number of parameters from Lua\n"); + return app_lua_return_error(L); + } ++ if(ret > 1) { ++ lkey2.s = (char *)lua_tostring(L, -1); ++ lkey2.len = strlen(lkey2.s); ++ } + lkey.s = (char *)lua_tostring(L, -1); + lkey.len = strlen(lkey.s); +- ret = _lua_cfgutilsb.mlock(&lkey); ++ if(ret > 1) { ++ ret = _lua_cfgutilsb.mlock(&lkey, &lkey2); ++ } else { ++ ret = _lua_cfgutilsb.mlock(&lkey, NULL); ++ } + + return app_lua_return_int(L, ret); + } +@@ -2808,20 +2817,29 @@ static int lua_sr_cfgutils_lock(lua_State *L) + static int lua_sr_cfgutils_unlock(lua_State *L) + { + int ret; +- str lkey; ++ str lkey, lkey2; + + if(!(_sr_lua_exp_reg_mods & SR_LUA_EXP_MOD_CFGUTILS)) { + LM_WARN("weird: cfgutils function executed but module not " + "registered\n"); + return app_lua_return_error(L); + } +- if(lua_gettop(L) != 1) { ++ ret = lua_gettop(L); ++ if(ret < 1 || ret > 3) { + LM_WARN("invalid number of parameters from Lua\n"); + return app_lua_return_error(L); + } ++ if(ret > 1) { ++ lkey2.s = (char *)lua_tostring(L, -1); ++ lkey2.len = strlen(lkey2.s); ++ } + lkey.s = (char *)lua_tostring(L, -1); + lkey.len = strlen(lkey.s); +- ret = _lua_cfgutilsb.munlock(&lkey); ++ if(ret > 1) { ++ ret = _lua_cfgutilsb.munlock(&lkey, &lkey2); ++ } else { ++ ret = _lua_cfgutilsb.munlock(&lkey, NULL); ++ } + + return app_lua_return_int(L, ret); + } diff --git a/debian/patches/sipwise/cfgutils-expose-optional-second-string-key-for-lock.patch b/debian/patches/sipwise/cfgutils-expose-optional-second-string-key-for-lock.patch new file mode 100644 index 000000000..224f5ff7c --- /dev/null +++ b/debian/patches/sipwise/cfgutils-expose-optional-second-string-key-for-lock.patch @@ -0,0 +1,219 @@ +From: Victor Seva +Date: Tue, 26 Mar 2024 11:07:12 +0100 +Subject: cfgutils: expose optional second string key for hashing at locks + +--- + src/modules/cfgutils/api.h | 4 +- + src/modules/cfgutils/cfgutils.c | 103 ++++++++++++++++++++++++++++++---------- + 2 files changed, 81 insertions(+), 26 deletions(-) + +diff --git a/src/modules/cfgutils/api.h b/src/modules/cfgutils/api.h +index d82cd4b..3c91f7c 100644 +--- a/src/modules/cfgutils/api.h ++++ b/src/modules/cfgutils/api.h +@@ -26,8 +26,8 @@ + + #include "../../core/str.h" + +-typedef int (*cfgutils_lock_f)(str *lkey); +-typedef int (*cfgutils_unlock_f)(str *lkey); ++typedef int (*cfgutils_lock_f)(str *lkey, str *lkey2); ++typedef int (*cfgutils_unlock_f)(str *lkey, str *lkey2); + + /** + * @brief CFGUTILS API structure +diff --git a/src/modules/cfgutils/cfgutils.c b/src/modules/cfgutils/cfgutils.c +index f439192..6887af7 100644 +--- a/src/modules/cfgutils/cfgutils.c ++++ b/src/modules/cfgutils/cfgutils.c +@@ -145,10 +145,15 @@ static cmd_export_t cmds[] = { + ANY_ROUTE}, + {"is_gflag", (cmd_function)is_gflag, 1, fixup_gflags, 0, ANY_ROUTE}, + {"lock", (cmd_function)w_cfg_lock, 1, fixup_spve_null, 0, ANY_ROUTE}, ++ {"lock", (cmd_function)w_cfg_lock, 2, fixup_spve_spve, 0, ANY_ROUTE}, + {"unlock", (cmd_function)w_cfg_unlock, 1, fixup_spve_null, 0, + ANY_ROUTE}, ++ {"unlock", (cmd_function)w_cfg_unlock, 2, fixup_spve_spve, 0, ++ ANY_ROUTE}, + {"trylock", (cmd_function)w_cfg_trylock, 1, fixup_spve_null, 0, + ANY_ROUTE}, ++ {"trylock", (cmd_function)w_cfg_trylock, 2, fixup_spve_spve, 0, ++ ANY_ROUTE}, + {"core_hash", (cmd_function)w_core_hash, 3, fixup_core_hash, 0, + ANY_ROUTE}, + {"check_route_exists", (cmd_function)w_check_route_exists, 1, +@@ -669,19 +674,34 @@ static int ki_shm_summary(sip_msg_t *msg) + return 1; + } + +-static int cfg_lock_helper(str *lkey, int mode) ++static int cfg_lock_helper(str *lkey, str *lkey2, int mode) + { + unsigned int pos; ++ str *key2 = NULL; ++ ++ if(lkey2 && lkey2->len > 0) { ++ key2 = lkey2; ++ } + + if(_cfg_lock_set == NULL) { +- LM_ERR("lock set not initialized (attempt to do op: %d on: %.*s) -" +- " see param lock_set_size\n", +- mode, lkey->len, lkey->s); ++ if(key2) { ++ LM_ERR("lock set not initialized (attempt to do op: %d on:[%.*s " ++ "%.*s]) - see param lock_set_size\n", ++ mode, STR_FMT(lkey), STR_FMT(lkey2)); ++ } else { ++ LM_ERR("lock set not initialized (attempt to do op: %d on:[%.*s]) " ++ "- see param lock_set_size\n", ++ mode, STR_FMT(lkey)); ++ } + return -1; + } +- pos = core_case_hash(lkey, 0, _cfg_lock_size); +- +- LM_DBG("cfg_lock mode %d on %u (%.*s)\n", mode, pos, lkey->len, lkey->s); ++ pos = core_case_hash(lkey, key2, _cfg_lock_size); ++ if(key2) { ++ LM_DBG("cfg_lock mode %d on %u (%.*s %.*s)\n", mode, pos, STR_FMT(lkey), ++ STR_FMT(lkey2)); ++ } else { ++ LM_DBG("cfg_lock mode %d on %u (%.*s)\n", mode, pos, STR_FMT(lkey)); ++ } + + if(mode == 0) { + /* Lock */ +@@ -707,45 +727,65 @@ static int cfg_lock_helper(str *lkey, int mode) + + static int cfg_lock(sip_msg_t *msg, str *lkey) + { +- return cfg_lock_helper(lkey, 0); ++ return cfg_lock_helper(lkey, NULL, 0); + } + + static int cfg_unlock(sip_msg_t *msg, str *lkey) + { +- return cfg_lock_helper(lkey, 1); ++ return cfg_lock_helper(lkey, NULL, 1); + } + + static int cfg_trylock(sip_msg_t *msg, str *lkey) + { +- return cfg_lock_helper(lkey, 2); ++ return cfg_lock_helper(lkey, NULL, 2); + } + +-static int w_cfg_lock_wrapper(struct sip_msg *msg, gparam_p key, int mode) ++static int cfg_lock_key2(sip_msg_t *msg, str *lkey, str *lkey2) + { +- str s; ++ return cfg_lock_helper(lkey, lkey2, 0); ++} ++ ++static int cfg_unlock_key2(sip_msg_t *msg, str *lkey, str *lkey2) ++{ ++ return cfg_lock_helper(lkey, lkey2, 1); ++} ++ ++static int cfg_trylock_key2(sip_msg_t *msg, str *lkey, str *lkey2) ++{ ++ return cfg_lock_helper(lkey, lkey2, 2); ++} ++ ++static int w_cfg_lock_wrapper( ++ struct sip_msg *msg, gparam_p key, gparam_p key2, int mode) ++{ ++ str s1, s2; + if(key == NULL) { + return -1; + } +- if(fixup_get_svalue(msg, key, &s) != 0) { ++ if(fixup_get_svalue(msg, key, &s1) != 0) { + LM_ERR("cannot get first parameter\n"); + return -1; + } +- return cfg_lock_helper(&s, mode); ++ if(key2 != NULL && fixup_get_svalue(msg, key2, &s2) != 0) { ++ LM_ERR("cannot get second parameter\n"); ++ return -1; ++ } ++ return cfg_lock_helper(&s1, &s2, mode); + } + +-static int w_cfg_lock(struct sip_msg *msg, char *key, char *s2) ++static int w_cfg_lock(struct sip_msg *msg, char *key, char *key2) + { +- return w_cfg_lock_wrapper(msg, (gparam_p)key, 0); ++ return w_cfg_lock_wrapper(msg, (gparam_p)key, (gparam_p)key2, 0); + } + +-static int w_cfg_unlock(struct sip_msg *msg, char *key, char *s2) ++static int w_cfg_unlock(struct sip_msg *msg, char *key, char *key2) + { +- return w_cfg_lock_wrapper(msg, (gparam_p)key, 1); ++ return w_cfg_lock_wrapper(msg, (gparam_p)key, (gparam_p)key2, 1); + } + +-static int w_cfg_trylock(struct sip_msg *msg, char *key, char *s2) ++static int w_cfg_trylock(struct sip_msg *msg, char *key, char *key2) + { +- return w_cfg_lock_wrapper(msg, (gparam_p)key, 2); ++ return w_cfg_lock_wrapper(msg, (gparam_p)key, (gparam_p)key2, 2); + } + + /*! Check if a route block exists - only request routes +@@ -903,17 +943,17 @@ static void mod_destroy(void) + /** + * + */ +-int cfgutils_lock(str *lkey) ++int cfgutils_lock(str *lkey, str *lkey2) + { +- return cfg_lock_helper(lkey, 0); ++ return cfg_lock_helper(lkey, lkey2, 0); + } + + /** + * + */ +-int cfgutils_unlock(str *lkey) ++int cfgutils_unlock(str *lkey, str *lkey2) + { +- return cfg_lock_helper(lkey, 1); ++ return cfg_lock_helper(lkey, lkey2, 1); + } + + static int fixup_core_hash(void **param, int param_no) +@@ -995,16 +1035,31 @@ static sr_kemi_t sr_kemi_cfgutils_exports[] = { + { SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE, + SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE } + }, ++ { str_init("cfgutils"), str_init("lock"), ++ SR_KEMIP_INT, cfg_lock_key2, ++ { SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_NONE, ++ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE } ++ }, + { str_init("cfgutils"), str_init("unlock"), + SR_KEMIP_INT, cfg_unlock, + { SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE, + SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE } + }, ++ { str_init("cfgutils"), str_init("unlock"), ++ SR_KEMIP_INT, cfg_unlock_key2, ++ { SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_NONE, ++ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE } ++ }, + { str_init("cfgutils"), str_init("trylock"), + SR_KEMIP_INT, cfg_trylock, + { SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE, + SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE } + }, ++ { str_init("cfgutils"), str_init("trylock"), ++ SR_KEMIP_INT, cfg_trylock_key2, ++ { SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_NONE, ++ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE } ++ }, + { str_init("cfgutils"), str_init("rand_set_prob"), + SR_KEMIP_INT, ki_rand_set_prob, + { SR_KEMIP_INT, SR_KEMIP_NONE, SR_KEMIP_NONE,