Module: kamailio
Branch: master
Commit: 38c85975e3b4a9f1dc548f7bda1f54726fba3d44
URL:
https://github.com/kamailio/kamailio/commit/38c85975e3b4a9f1dc548f7bda1f547…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: GitHub <noreply(a)github.com>
Date: 2017-08-17T12:46:01+02:00
Merge pull request #1218 from kamailio/corehash_trans
pv: add string corehash transform
---
Modified: src/modules/pv/pv_trans.c
Modified: src/modules/pv/pv_trans.h
---
Diff:
https://github.com/kamailio/kamailio/commit/38c85975e3b4a9f1dc548f7bda1f547…
Patch:
https://github.com/kamailio/kamailio/commit/38c85975e3b4a9f1dc548f7bda1f547…
---
diff --git a/src/modules/pv/pv_trans.c b/src/modules/pv/pv_trans.c
index eccf3b6377..603219bf4e 100644
--- a/src/modules/pv/pv_trans.c
+++ b/src/modules/pv/pv_trans.c
@@ -39,6 +39,7 @@
#include "../../core/dset.h"
#include "../../core/basex.h"
#include "../../core/action.h"
+#include "../../core/hashes.h"
#include "../../core/parser/parse_param.h"
#include "../../core/parser/parse_uri.h"
@@ -265,6 +266,7 @@ int tr_eval_string(struct sip_msg *msg, tr_param_t *tp, int subtype,
str st, st2;
pv_value_t v, w;
time_t t;
+ uint sz1, sz2;
if(val==NULL || val->flags&PV_VAL_NULL)
return -1;
@@ -1121,6 +1123,35 @@ int tr_eval_string(struct sip_msg *msg, tr_param_t *tp, int
subtype,
val->rs = st;
break;
+ case TR_S_COREHASH:
+ if(!(val->flags&PV_VAL_STR))
+ val->rs.s = int2str(val->ri, &val->rs.len);
+
+ sz1 = 0;
+ if(tp != NULL) {
+ if(tp->type==TR_PARAM_NUMBER) {
+ sz1 = (uint) tp->v.n;
+ } else {
+ if(pv_get_spec_value(msg, (pv_spec_p)tp->v.data, &v)!=0
+ || (!(v.flags&PV_VAL_INT)))
+ {
+ LM_ERR("corehash cannot get size (cfg line: %d)\n",
+ get_cfg_crt_line());
+ return -1;
+ }
+ sz1 = (uint) v.ri;
+ }
+ }
+
+ sz2 = core_hash(&val->rs, NULL, sz1);
+
+ j = sprintf(_tr_buffer, "%u", sz2);
+ val->flags = PV_VAL_STR;
+ val->ri = 0;
+ val->rs.s = _tr_buffer;
+ val->rs.len = j;
+ break;
+
default:
LM_ERR("unknown subtype %d (cfg line: %d)\n",
subtype, get_cfg_crt_line());
@@ -2395,6 +2426,23 @@ char* tr_parse_string(str* in, trans_t *t)
goto error;
}
goto done;
+ } else if(name.len==8 && strncasecmp(name.s, "corehash", 8)==0) {
+ t->subtype = TR_S_COREHASH;
+ if(*p==TR_PARAM_MARKER)
+ {
+ p++;
+ _tr_parse_nparam(p, p0, tp, spec, n, sign, in, s);
+ t->params = tp;
+ }
+ tp = 0;
+ while(*p && (*p==' ' || *p=='\t' || *p=='\n')) p++;
+ if(*p!=TR_RBRACKET)
+ {
+ LM_ERR("invalid corehash transformation: %.*s!!\n",
+ in->len, in->s);
+ goto error;
+ }
+ goto done;
} else if(name.len==4 && strncasecmp(name.s, "trim", 4)==0) {
t->subtype = TR_S_TRIM;
goto done;
diff --git a/src/modules/pv/pv_trans.h b/src/modules/pv/pv_trans.h
index 764653e5e3..aacb722b95 100644
--- a/src/modules/pv/pv_trans.h
+++ b/src/modules/pv/pv_trans.h
@@ -41,7 +41,7 @@ enum _tr_s_subtype {
TR_S_STRIP, TR_S_STRIPTAIL, TR_S_PREFIXES, TR_S_PREFIXES_QUOT, TR_S_REPLACE,
TR_S_TIMEFORMAT, TR_S_TRIM, TR_S_RTRIM, TR_S_LTRIM, TR_S_RM, TR_S_STRIPTO,
TR_S_URLENCODEPARAM, TR_S_URLDECODEPARAM, TR_S_NUMERIC, TR_S_ESCAPECSV,
- TR_S_ENCODEBASE58, TR_S_DECODEBASE58
+ TR_S_ENCODEBASE58, TR_S_DECODEBASE58, TR_S_COREHASH
};
enum _tr_uri_subtype {
TR_URI_NONE=0, TR_URI_USER, TR_URI_HOST, TR_URI_PASSWD, TR_URI_PORT,