Module: kamailio
Branch: master
Commit: 34db0b1f5b0d57e938a7a74ce9787b9c1e63bf46
URL:
https://github.com/kamailio/kamailio/commit/34db0b1f5b0d57e938a7a74ce9787b9…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2017-07-12T13:10:36+02:00
pv: added transformations for base58
- {s.encode.base58}
- {s.decode.base58}
---
Modified: src/modules/pv/pv_trans.c
Modified: src/modules/pv/pv_trans.h
---
Diff:
https://github.com/kamailio/kamailio/commit/34db0b1f5b0d57e938a7a74ce9787b9…
Patch:
https://github.com/kamailio/kamailio/commit/34db0b1f5b0d57e938a7a74ce9787b9…
---
diff --git a/src/modules/pv/pv_trans.c b/src/modules/pv/pv_trans.c
index ef88423838..3012126ff6 100644
--- a/src/modules/pv/pv_trans.c
+++ b/src/modules/pv/pv_trans.c
@@ -413,6 +413,30 @@ int tr_eval_string(struct sip_msg *msg, tr_param_t *tp, int subtype,
val->rs.s = _tr_buffer;
val->rs.len = i;
break;
+ case TR_S_ENCODEBASE58:
+ if(!(val->flags&PV_VAL_STR))
+ val->rs.s = int2str(val->ri, &val->rs.len);
+ st.len = TR_BUFFER_SIZE-1;
+ st.s = b58_encode(_tr_buffer, &st.len, val->rs.s, val->rs.len);
+ if (st.s==NULL)
+ return -1;
+ memset(val, 0, sizeof(pv_value_t));
+ val->flags = PV_VAL_STR;
+ val->rs.s = st.s;
+ val->rs.len = st.len;
+ break;
+ case TR_S_DECODEBASE58:
+ if(!(val->flags&PV_VAL_STR))
+ val->rs.s = int2str(val->ri, &val->rs.len);
+ st.len = TR_BUFFER_SIZE-1;
+ st.s = b58_decode(_tr_buffer, &st.len, val->rs.s, val->rs.len);
+ if (st.s==NULL)
+ return -1;
+ memset(val, 0, sizeof(pv_value_t));
+ val->flags = PV_VAL_STR;
+ val->rs.s = st.s;
+ val->rs.len = st.len;
+ break;
case TR_S_ENCODEBASE64:
if(!(val->flags&PV_VAL_STR))
val->rs.s = int2str(val->ri, &val->rs.len);
@@ -2111,6 +2135,12 @@ char* tr_parse_string(str* in, trans_t *t)
} else if(name.len==11 && strncasecmp(name.s, "decode.7bit", 11)==0)
{
t->subtype = TR_S_DECODE7BIT;
goto done;
+ } else if(name.len==13 && strncasecmp(name.s, "encode.base58", 13)==0)
{
+ t->subtype = TR_S_ENCODEBASE58;
+ goto done;
+ } else if(name.len==13 && strncasecmp(name.s, "decode.base58", 13)==0)
{
+ t->subtype = TR_S_DECODEBASE58;
+ goto done;
} else if(name.len==13 && strncasecmp(name.s, "encode.base64", 13)==0)
{
t->subtype = TR_S_ENCODEBASE64;
goto done;
diff --git a/src/modules/pv/pv_trans.h b/src/modules/pv/pv_trans.h
index ec6bb7fb37..7b7b15fb03 100644
--- a/src/modules/pv/pv_trans.h
+++ b/src/modules/pv/pv_trans.h
@@ -32,7 +32,7 @@
enum _tr_type { TR_NONE=0, TR_STRING, TR_URI, TR_PARAMLIST, TR_NAMEADDR,
TR_TOBODY, TR_LINE };
-enum _tr_s_subtype {
+enum _tr_s_subtype {
TR_S_NONE=0, TR_S_LEN, TR_S_INT, TR_S_MD5, TR_S_SHA256, TR_S_SHA384,
TR_S_SHA512, TR_S_SUBSTR, TR_S_SELECT, TR_S_ENCODEHEXA, TR_S_DECODEHEXA,
TR_S_ENCODE7BIT, TR_S_DECODE7BIT, TR_S_ENCODEBASE64, TR_S_DECODEBASE64,
@@ -40,7 +40,8 @@ enum _tr_s_subtype {
TR_S_ESCAPEPARAM, TR_S_UNESCAPEPARAM, TR_S_TOLOWER, TR_S_TOUPPER,
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_URLENCODEPARAM, TR_S_URLDECODEPARAM, TR_S_NUMERIC, TR_S_ESCAPECSV,
+ TR_S_ENCODEBASE58, TR_S_DECODEBASE58
};
enum _tr_uri_subtype {
TR_URI_NONE=0, TR_URI_USER, TR_URI_HOST, TR_URI_PASSWD, TR_URI_PORT,