Module: kamailio
Branch: master
Commit: 37e50fadb8a18bc85c0af00da153db7f0dc59e0f
URL:
https://github.com/kamailio/kamailio/commit/37e50fadb8a18bc85c0af00da153db7…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2022-02-09T08:55:41+01:00
htable: added rpc commands to set value and expire at the same time
---
Modified: src/modules/htable/htable.c
---
Diff:
https://github.com/kamailio/kamailio/commit/37e50fadb8a18bc85c0af00da153db7…
Patch:
https://github.com/kamailio/kamailio/commit/37e50fadb8a18bc85c0af00da153db7…
---
diff --git a/src/modules/htable/htable.c b/src/modules/htable/htable.c
index 6de38d57e9..f7a9cb389a 100644
--- a/src/modules/htable/htable.c
+++ b/src/modules/htable/htable.c
@@ -1487,6 +1487,14 @@ static const char* htable_setex_doc[2] = {
"Set expire in a hash table for the item referenced by key.",
0
};
+static const char* htable_setxs_doc[2] = {
+ "Set one key in a hash table to a string value and its expire value.",
+ 0
+};
+static const char* htable_setxi_doc[2] = {
+ "Set one key in a hash table to an integer value and its expire value.",
+ 0
+};
static const char* htable_list_doc[2] = {
"List all htables.",
0
@@ -1714,6 +1722,49 @@ static void htable_rpc_setex(rpc_t* rpc, void* c) {
return;
}
+/*! \brief RPC htable.setxs command to set one item to string value and its expire value
*/
+static void htable_rpc_setxs(rpc_t* rpc, void* c) {
+ str htname, keyname;
+ str sval;
+ int exval;
+
+ if (rpc->scan(c, "SS.Sd", &htname, &keyname, &sval, &exval)
< 4) {
+ rpc->fault(c, 500,
+ "Not enough parameters (htable name, key name, value and expire)");
+ return;
+ }
+
+ if(ki_ht_setxs(NULL, &htname, &keyname, &sval, exval)<0) {
+ LM_ERR("cannot set $sht(%.*s=>%.*s)\n", htname.len, htname.s,
+ keyname.len, keyname.s);
+ rpc->fault(c, 500, "Failed to set the item");
+ return;
+ }
+ rpc->rpl_printf(c, "Ok. Key set to new value.");
+ return;
+}
+
+/*! \brief RPC htable.setxi command to set one item to integer value and its expire value
*/
+static void htable_rpc_setxi(rpc_t* rpc, void* c) {
+ str htname, keyname;
+ int ival;
+ int exval;
+
+ if (rpc->scan(c, "SS.dd", &htname, &keyname, &ival, &exval)
< 4) {
+ rpc->fault(c, 500,
+ "Not enough parameters (htable name, key name, value and expire)");
+ return;
+ }
+ if(ki_ht_setxi(NULL, &htname, &keyname, ival, exval)<0) {
+ LM_ERR("cannot set $sht(%.*s=>%.*s)\n", htname.len, htname.s,
+ keyname.len, keyname.s);
+ rpc->fault(c, 500, "Failed to set the item");
+ return;
+ }
+ rpc->rpl_printf(c, "Ok. Key set to new value.");
+ return;
+}
+
/*! \brief RPC htable.dump command to print content of a hash table */
static void htable_rpc_dump(rpc_t* rpc, void* c)
{
@@ -2077,6 +2128,8 @@ rpc_export_t htable_rpc[] = {
{"htable.sets", htable_rpc_sets, htable_sets_doc, 0},
{"htable.seti", htable_rpc_seti, htable_seti_doc, 0},
{"htable.setex", htable_rpc_setex, htable_setex_doc, 0},
+ {"htable.setxs", htable_rpc_setxs, htable_setxs_doc, 0},
+ {"htable.setxi", htable_rpc_setxi, htable_setxi_doc, 0},
{"htable.listTables", htable_rpc_list, htable_list_doc, RET_ARRAY},
{"htable.reload", htable_rpc_reload, htable_reload_doc, 0},
{"htable.store", htable_rpc_store, htable_store_doc, 0},