Module: sip-router Branch: master Commit: 059bd9c5576e7e14bc69506330990a165286d9c1 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=059bd9c5...
Author: Ovidiu Sas osas@voipembedded.com Committer: Ovidiu Sas osas@voipembedded.com Date: Wed Feb 12 16:14:35 2014 -0500
htable: adding flags and expires fields to htable.get RPC command
---
modules/htable/htable.c | 23 ++++++++++++++++++++--- 1 files changed, 20 insertions(+), 3 deletions(-)
diff --git a/modules/htable/htable.c b/modules/htable/htable.c index ab2ecea..a5e110e 100644 --- a/modules/htable/htable.c +++ b/modules/htable/htable.c @@ -649,6 +649,8 @@ error: return 0; }
+#define RPC_DATE_BUF_LEN 21 + static const char* htable_dump_doc[2] = { "Dump the contents of hash table.", 0 @@ -710,6 +712,8 @@ static void htable_rpc_get(rpc_t* rpc, void* c) { ht_cell_t *htc; /*!< One HT cell */ void* th; void* vh; + struct tm *_expire_t; + char expire_buf[RPC_DATE_BUF_LEN]="NEVER";
if (rpc->scan(c, "SS", &htname, &keyname) < 2) { rpc->fault(c, 500, "Not enough parameters (htable name and key name)"); @@ -742,14 +746,27 @@ static void htable_rpc_get(rpc_t* rpc, void* c) { goto error; }
+ if (htc->expire) { + _expire_t = localtime(&htc->expire); + strftime(expire_buf, RPC_DATE_BUF_LEN - 1, + "%Y-%m-%d %H:%M:%S", _expire_t); + } + LM_NOTICE("got expire [%s]\n", expire_buf); + if(htc->flags&AVP_VAL_STR) { - if(rpc->struct_add(vh, "SS", "name", &htc->name.s, "value", &htc->value.s)<0) + if(rpc->struct_add(vh, "SSds", "name", &htc->name.s, + "value", &htc->value.s, + "flags", htc->flags, + "expire", expire_buf)<0) { rpc->fault(c, 500, "Internal error adding item"); goto error; } } else { - if(rpc->struct_add(vh, "Sd", "name", &htc->name.s, "value", (int)htc->value.n)) + if(rpc->struct_add(vh, "Sdds", "name", &htc->name.s, + "value", (int)htc->value.n, + "flags", htc->flags, + "expire", expire_buf)<0) { rpc->fault(c, 500, "Internal error adding item"); goto error; @@ -892,7 +909,7 @@ static void htable_rpc_dump(rpc_t* rpc, void* c) } else { if(rpc->struct_add(vh, "Sd", "name", &it->name.s, - "value", (int)it->value.n)) + "value", (int)it->value.n)<0) { rpc->fault(c, 500, "Internal error adding item"); goto error;
Hello Juha,
I already started to work on something else. If time permits, I will take a look. I noticed that there is delete rpc command: http://kamailio.org/docs/modules/devel/modules/htable#idp15375232 I haven't checked exactly how it works. Is this something to be enhanced? What's missing right now?
-ovidiu
On Thu, Feb 13, 2014 at 12:24 AM, Juha Heinanen jh@tutpro.com wrote:
Ovidiu Sas writes:
htable: adding flags and expires fields to htable.get RPC command
ovidiu,
once you are on it, how about adding possibility to add/delete htable array entries (entries where more than one entry can share the same key) via rpc commands?
-- juha
sr-dev mailing list sr-dev@lists.sip-router.org http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev
Ovidiu Sas writes:
I noticed that there is delete rpc command: http://kamailio.org/docs/modules/devel/modules/htable#idp15375232 I haven't checked exactly how it works. Is this something to be enhanced? What's missing right now?
value param is missing, i.e., it is not possible to delete a given key/value pair. i looked at the code, but don't have enough json knowledge to figure out all the parameters.
-- juha