Module: sip-router
Branch: master
Commit: 12f441f4b75f15ab25fc42889bfce65940d0c0d0
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=12f441f…
Author: Richard Fuchs <rfuchs(a)sipwise.com>
Committer: Richard Fuchs <rfuchs(a)sipwise.com>
Date: Tue Apr 9 16:38:22 2013 -0400
pv: implement pv transformation {en,de}code.base64
---
modules/pv/pv_trans.c | 33 +++++++++++++++++++++++++++++++++
modules/pv/pv_trans.h | 1 +
2 files changed, 34 insertions(+), 0 deletions(-)
diff --git a/modules/pv/pv_trans.c b/modules/pv/pv_trans.c
index fc9597b..1e553f1 100644
--- a/modules/pv/pv_trans.c
+++ b/modules/pv/pv_trans.c
@@ -39,6 +39,7 @@
#include "../../trim.h"
#include "../../pvapi.h"
#include "../../dset.h"
+#include "../../basex.h"
#include "../../parser/parse_param.h"
#include "../../parser/parse_uri.h"
@@ -195,6 +196,32 @@ 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_ENCODEBASE64:
+ if(!(val->flags&PV_VAL_STR))
+ val->rs.s = int2str(val->ri, &val->rs.len);
+ i = base64_enc((unsigned char *) val->rs.s, val->rs.len,
+ (unsigned char *) _tr_buffer, TR_BUFFER_SIZE-1);
+ if (i < 0)
+ return -1;
+ _tr_buffer[i] = '\0';
+ memset(val, 0, sizeof(pv_value_t));
+ val->flags = PV_VAL_STR;
+ val->rs.s = _tr_buffer;
+ val->rs.len = i;
+ break;
+ case TR_S_DECODEBASE64:
+ if(!(val->flags&PV_VAL_STR))
+ val->rs.s = int2str(val->ri, &val->rs.len);
+ i = base64_dec((unsigned char *) val->rs.s, val->rs.len,
+ (unsigned char *) _tr_buffer, TR_BUFFER_SIZE-1);
+ if (i < 0 || (i == 0 && val->rs.len > 0))
+ return -1;
+ _tr_buffer[i] = '\0';
+ memset(val, 0, sizeof(pv_value_t));
+ val->flags = PV_VAL_STR;
+ val->rs.s = _tr_buffer;
+ val->rs.len = i;
+ break;
case TR_S_ESCAPECOMMON:
if(!(val->flags&PV_VAL_STR))
val->rs.s = int2str(val->ri, &val->rs.len);
@@ -1749,6 +1776,12 @@ char* tr_parse_string(str* in, trans_t *t)
} else if(name.len==11 && strncasecmp(name.s, "decode.hexa", 11)==0)
{
t->subtype = TR_S_DECODEHEXA;
goto done;
+ } else if(name.len==13 && strncasecmp(name.s, "encode.base64", 13)==0)
{
+ t->subtype = TR_S_ENCODEBASE64;
+ goto done;
+ } else if(name.len==13 && strncasecmp(name.s, "decode.base64", 13)==0)
{
+ t->subtype = TR_S_DECODEBASE64;
+ goto done;
} else if(name.len==13 && strncasecmp(name.s, "escape.common", 13)==0)
{
t->subtype = TR_S_ESCAPECOMMON;
goto done;
diff --git a/modules/pv/pv_trans.h b/modules/pv/pv_trans.h
index a34eca2..e2aa494 100644
--- a/modules/pv/pv_trans.h
+++ b/modules/pv/pv_trans.h
@@ -37,6 +37,7 @@ enum _tr_type { TR_NONE=0, TR_STRING, TR_URI, TR_PARAMLIST,
TR_NAMEADDR,
enum _tr_s_subtype {
TR_S_NONE=0, TR_S_LEN, TR_S_INT, TR_S_MD5, TR_S_SUBSTR,
TR_S_SELECT, TR_S_ENCODEHEXA, TR_S_DECODEHEXA,
+ TR_S_ENCODEBASE64, TR_S_DECODEBASE64,
TR_S_ESCAPECOMMON, TR_S_UNESCAPECOMMON, TR_S_ESCAPEUSER, TR_S_UNESCAPEUSER,
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,