Module: sip-router Branch: master Commit: 29318c4636b01fbaa0d119d9bdd2926adc3817de URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=29318c46...
Author: Alex Hermann alex@speakup.nl Committer: Alex Hermann alex@speakup.nl Date: Fri Mar 11 16:52:18 2011 +0100
modules_k/pv: Add s.ftime transformation. Will format the epoch in the pv by the format in the parameter. Uses standard strftime formatting.
example: $(TS{s.ftime,%Y-%m-%d %H:%M:%S})
---
modules_k/pv/pv_trans.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++ modules_k/pv/pv_trans.h | 2 +- 2 files changed, 59 insertions(+), 1 deletions(-)
diff --git a/modules_k/pv/pv_trans.c b/modules_k/pv/pv_trans.c index 476b5c0..4842a06 100644 --- a/modules_k/pv/pv_trans.c +++ b/modules_k/pv/pv_trans.c @@ -496,6 +496,43 @@ int tr_eval_string(struct sip_msg *msg, tr_param_t *tp, int subtype, val->rs.len = j-1; break;
+ case TR_S_TIMEFORMAT: + if(tp==NULL) + { + LM_ERR("timeformat invalid parameters\n"); + return -1; + } + if(!(val->flags&PV_VAL_INT) && (str2int(&val->rs, (unsigned int*) &val->ri)!=0)) + { + LM_ERR("value is not numeric\n"); + return -1; + } + if(tp->type==TR_PARAM_STRING) + { + st = tp->v.s; + } else { + if(pv_get_spec_value(msg, (pv_spec_p)tp->v.data, &v)!=0 + || (!(v.flags&PV_VAL_STR)) || v.rs.len<=0) + { + LM_ERR("timeformat cannot get p1\n"); + return -1; + } + st = v.rs; + } + s = pkg_malloc(st.len + 1); + if (s==NULL) + { + LM_ERR("no more pkg memory\n"); + return -1; + } + memcpy(s, st.s, st.len); + s[st.len] = '\0'; + val->rs.len = strftime(_tr_buffer, TR_BUFFER_SIZE-1, s, localtime((time_t*) &val->ri)); + pkg_free(s); + val->flags = PV_VAL_STR; + val->rs.s = _tr_buffer; + break; + default: LM_ERR("unknown subtype %d\n", subtype); @@ -1212,6 +1249,7 @@ char* tr_parse_string(str* in, trans_t *t) { char *p; char *p0; + char *ps; str name; str s; pv_spec_t *spec = NULL; @@ -1425,6 +1463,26 @@ char* tr_parse_string(str* in, trans_t *t) goto error; } goto done; + } else if(name.len==5 && strncasecmp(name.s, "ftime", 5)==0) { + t->subtype = TR_S_TIMEFORMAT; + if(*p!=TR_PARAM_MARKER) + { + LM_ERR("invalid ftime transformation: %.*s!\n", + in->len, in->s); + goto error; + } + p++; + _tr_parse_sparam(p, p0, tp, spec, ps, in, s); + t->params = tp; + tp = 0; + while(*p && (*p==' ' || *p=='\t' || *p=='\n')) p++; + if(*p!=TR_RBRACKET) + { + LM_ERR("invalid ftime transformation: %.*s!!\n", + in->len, in->s); + goto error; + } + goto done; }
LM_ERR("unknown transformation: %.*s/%.*s/%d!\n", in->len, in->s, diff --git a/modules_k/pv/pv_trans.h b/modules_k/pv/pv_trans.h index 1e601d8..222c09e 100644 --- a/modules_k/pv/pv_trans.h +++ b/modules_k/pv/pv_trans.h @@ -39,7 +39,7 @@ enum _tr_s_subtype { TR_S_SELECT, TR_S_ENCODEHEXA, TR_S_DECODEHEXA, 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_STRIP, TR_S_STRIPTAIL, TR_S_PREFIXES, TR_S_PREFIXES_QUOT, TR_S_TIMEFORMAT }; enum _tr_uri_subtype { TR_URI_NONE=0, TR_URI_USER, TR_URI_HOST, TR_URI_PASSWD, TR_URI_PORT,