Module: kamailio
Branch: master
Commit: f23e256acbc10cd24238f71a70b6f1a7bf64826d
URL: 
https://github.com/kamailio/kamailio/commit/f23e256acbc10cd24238f71a70b6f1a7bf64826d

Author: Daniel-Constantin Mierla <[email protected]>
Committer: Daniel-Constantin Mierla <[email protected]>
Date: 2019-06-04T08:54:13+02:00

htable: kemi functions to get the value of an hash table item

---

Modified: src/modules/htable/htable.c

---

Diff:  
https://github.com/kamailio/kamailio/commit/f23e256acbc10cd24238f71a70b6f1a7bf64826d.diff
Patch: 
https://github.com/kamailio/kamailio/commit/f23e256acbc10cd24238f71a70b6f1a7bf64826d.patch

---

diff --git a/src/modules/htable/htable.c b/src/modules/htable/htable.c
index 1320330f35..667653639c 100644
--- a/src/modules/htable/htable.c
+++ b/src/modules/htable/htable.c
@@ -917,6 +917,83 @@ int ht_param(modparam_t type, void *val)
 
 }
 
+/**
+ *
+ */
+static sr_kemi_xval_t _sr_kemi_htable_xval = {0};
+
+/* pkg copy */
+static ht_cell_t *_htc_kemi_local=NULL;
+
+/**
+ *
+ */
+static sr_kemi_xval_t* ki_ht_get_mode(sip_msg_t *msg, str *htname, str *itname,
+               int rmode)
+{
+       ht_t *ht = NULL;
+       ht_cell_t *htc=NULL;
+
+       /* Find the htable */
+       ht = ht_get_table(htname);
+       if (!ht) {
+               LM_ERR("No such htable: %.*s\n", htname->len, htname->s);
+               sr_kemi_xval_null(&_sr_kemi_htable_xval, rmode);
+               return &_sr_kemi_htable_xval;
+       }
+
+       htc = ht_cell_pkg_copy(ht, itname, _htc_kemi_local);
+       if(_htc_kemi_local!=htc) {
+               ht_cell_pkg_free(_htc_kemi_local);
+               _htc_kemi_local=htc;
+       }
+       if(htc==NULL) {
+               if(ht->flags==PV_VAL_INT) {
+                       _sr_kemi_htable_xval.vtype = SR_KEMIP_INT;
+                       _sr_kemi_htable_xval.v.n = ht->initval.n;
+                       return &_sr_kemi_htable_xval;
+               }
+               sr_kemi_xval_null(&_sr_kemi_htable_xval, rmode);
+               return &_sr_kemi_htable_xval;
+       }
+
+       if(htc->flags&AVP_VAL_STR) {
+               _sr_kemi_htable_xval.vtype = SR_KEMIP_STR;
+               _sr_kemi_htable_xval.v.s = htc->value.s;
+               return &_sr_kemi_htable_xval;
+       }
+
+       /* integer */
+       _sr_kemi_htable_xval.vtype = SR_KEMIP_INT;
+       _sr_kemi_htable_xval.v.n = htc->value.n;
+       return &_sr_kemi_htable_xval;
+}
+
+/**
+ *
+ */
+static sr_kemi_xval_t* ki_ht_get(sip_msg_t *msg, str *htname, str *itname)
+{
+       return ki_ht_get_mode(msg, htname, itname, SR_KEMI_XVAL_NULL_NONE);
+}
+
+/**
+ *
+ */
+static sr_kemi_xval_t* ki_ht_gete(sip_msg_t *msg, str *htname, str *itname)
+{
+       return ki_ht_get_mode(msg, htname, itname, SR_KEMI_XVAL_NULL_EMPTY);
+}
+
+/**
+ *
+ */
+static sr_kemi_xval_t* ki_ht_getw(sip_msg_t *msg, str *htname, str *itname)
+{
+       return ki_ht_get_mode(msg, htname, itname, SR_KEMI_XVAL_NULL_PRINT);
+}
+
+
 /**
  *
  */
@@ -1694,6 +1771,21 @@ static sr_kemi_t sr_kemi_htable_exports[] = {
                { SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_STR,
                        SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
        },
+       { str_init("htable"), str_init("sht_get"),
+               SR_KEMIP_XVAL, ki_ht_get,
+               { SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_NONE,
+                       SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
+       },
+       { str_init("htable"), str_init("sht_gete"),
+               SR_KEMIP_XVAL, ki_ht_gete,
+               { SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_NONE,
+                       SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
+       },
+       { str_init("htable"), str_init("sht_getw"),
+               SR_KEMIP_XVAL, ki_ht_getw,
+               { SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_NONE,
+                       SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
+       },
        { str_init("htable"), str_init("sht_sets"),
                SR_KEMIP_INT, ki_ht_sets,
                { SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_STR,


_______________________________________________
Kamailio (SER) - Development Mailing List
[email protected]
https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-dev

Reply via email to