Module: kamailio
Branch: master
Commit: 31daee1800cb301d705524a56e7466abfa62e5d9
URL:
https://github.com/kamailio/kamailio/commit/31daee1800cb301d705524a56e7466a…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2024-06-24T11:38:14+02:00
pv: new transformation {s.rmhdws}
- remove header-like duplicated whitespaces (i.e., end of line followed
by whitespaces are replaced by a single whitespace)
---
Modified: src/modules/pv/pv_trans.c
Modified: src/modules/pv/pv_trans.h
---
Diff:
https://github.com/kamailio/kamailio/commit/31daee1800cb301d705524a56e7466a…
Patch:
https://github.com/kamailio/kamailio/commit/31daee1800cb301d705524a56e7466a…
---
diff --git a/src/modules/pv/pv_trans.c b/src/modules/pv/pv_trans.c
index a3ce0f0ace3..4418234ddb5 100644
--- a/src/modules/pv/pv_trans.c
+++ b/src/modules/pv/pv_trans.c
@@ -246,6 +246,34 @@ int tr_eval_string(
val->rs.s = _tr_buffer;
val->rs.len = j;
break;
+ case TR_S_RMHDWS:
+ if(!(val->flags & PV_VAL_STR))
+ val->rs.s = int2str(val->ri, &val->rs.len);
+ if(val->rs.len >= TR_BUFFER_SIZE - 1)
+ return -1;
+ j = 0;
+ c = 0;
+ for(i = 0; i < val->rs.len; i++) {
+ if(val->rs.s[i] == '\r' || val->rs.s[i] == '\n') {
+ c = 1;
+ } else if(c != 0 && (val->rs.s[i] == ' ' || val->rs.s[i] ==
'\t')) {
+ if(c == 1) {
+ _tr_buffer[j] = ' ';
+ j++;
+ c = 2;
+ }
+ } else {
+ _tr_buffer[j] = val->rs.s[i];
+ j++;
+ c = 0;
+ }
+ }
+ _tr_buffer[j] = '\0';
+ val->flags = PV_VAL_STR;
+ val->ri = 0;
+ val->rs.s = _tr_buffer;
+ val->rs.len = j;
+ break;
case TR_S_MD5:
if(!(val->flags & PV_VAL_STR))
val->rs.s = int2str(val->ri, &val->rs.len);
@@ -2721,6 +2749,9 @@ char *tr_parse_string(str *in, trans_t *t)
} else if(name.len == 4 && strncasecmp(name.s, "rmws", 4) == 0) {
t->subtype = TR_S_RMWS;
goto done;
+ } else if(name.len == 6 && strncasecmp(name.s, "rmhdws", 6) == 0) {
+ t->subtype = TR_S_RMHDWS;
+ goto done;
} else if(name.len == 6 && strncasecmp(name.s, "sha256", 6) == 0) {
t->subtype = TR_S_SHA256;
goto done;
diff --git a/src/modules/pv/pv_trans.h b/src/modules/pv/pv_trans.h
index 662d5a2b578..9eebe1da9d1 100644
--- a/src/modules/pv/pv_trans.h
+++ b/src/modules/pv/pv_trans.h
@@ -96,6 +96,7 @@ enum _tr_s_subtype
TR_S_ENCODEBASE64URLT,
TR_S_DECODEBASE64URLT,
TR_S_RMWS,
+ TR_S_RMHDWS,
TR_S_BEFORE,
TR_S_AFTER,
TR_S_RBEFORE,