pv: new transformation {s.stripto,c}
authorDaniel-Constantin Mierla <miconda@gmail.com>
Wed, 26 Sep 2012 07:17:00 +0000 (09:17 +0200)
committerDaniel-Constantin Mierla <miconda@gmail.com>
Wed, 26 Sep 2012 07:17:00 +0000 (09:17 +0200)
- remove the prefix until meeting 'c'
- "abcdef"{s.stripto,d} => "def"
- the char can be given in a pv

modules_k/pv/pv_trans.c
modules_k/pv/pv_trans.h

index d127e76..995d25a 100644 (file)
@@ -487,6 +487,47 @@ int tr_eval_string(struct sip_msg *msg, tr_param_t *tp, int subtype,
                        val->rs.len -= i;
                        break;
 
+
+               case TR_S_STRIPTO:
+                       if(tp==NULL)
+                       {
+                               LM_ERR("stripto invalid parameters\n");
+                               return -1;
+                       }
+                       if(!(val->flags&PV_VAL_STR))
+                               val->rs.s = int2str(val->ri, &val->rs.len);
+
+                       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("stripto cannot get p1\n");
+                                       return -1;
+                               }
+                               st = v.rs;
+                       }
+
+                       val->flags = PV_VAL_STR;
+                       val->ri = 0;
+                       for(i=0; i<val->rs.len; i++)
+                       {
+                               if(val->rs.s[i] == st.s[0])
+                                       break;
+                       }
+                       if(i>=val->rs.len)
+                       {
+                               _tr_buffer[0] = '\0';
+                               val->rs.s = _tr_buffer;
+                               val->rs.len = 0;
+                               break;
+                       }
+                       val->rs.s += i;
+                       val->rs.len -= i;
+                       break;
+
                case TR_S_PREFIXES:
                case TR_S_PREFIXES_QUOT:
                        if(!(val->flags&PV_VAL_STR))
@@ -1874,6 +1915,26 @@ char* tr_parse_string(str* in, trans_t *t)
                        goto error;
                }
                goto done;
+       } else if(name.len==7 && strncasecmp(name.s, "stripto", 7)==0) {
+               t->subtype = TR_S_STRIPTO;
+               if(*p!=TR_PARAM_MARKER)
+               {
+                       LM_ERR("invalid stripto 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 strip transformation: %.*s!!\n",
+                               in->len, in->s);
+                       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)
index c660102..a34eca2 100644 (file)
@@ -40,7 +40,7 @@ enum _tr_s_subtype {
        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,
-       TR_S_TIMEFORMAT, TR_S_TRIM, TR_S_RTRIM, TR_S_LTRIM, TR_S_RM
+       TR_S_TIMEFORMAT, TR_S_TRIM, TR_S_RTRIM, TR_S_LTRIM, TR_S_RM, TR_S_STRIPTO
 };
 enum _tr_uri_subtype {
        TR_URI_NONE=0, TR_URI_USER, TR_URI_HOST, TR_URI_PASSWD, TR_URI_PORT,