Module: kamailio
Branch: master
Commit: 6992c9eedeabd931fc255e5c1e992b0cfb01dbca
URL:
https://github.com/kamailio/kamailio/commit/6992c9eedeabd931fc255e5c1e992b0…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2024-04-03T18:48:29+02:00
core: helper functions to escape/unescape cr lf
---
Modified: src/core/strutils.c
Modified: src/core/strutils.h
---
Diff:
https://github.com/kamailio/kamailio/commit/6992c9eedeabd931fc255e5c1e992b0…
Patch:
https://github.com/kamailio/kamailio/commit/6992c9eedeabd931fc255e5c1e992b0…
---
diff --git a/src/core/strutils.c b/src/core/strutils.c
index 73e713cb451..475150dc0f7 100644
--- a/src/core/strutils.c
+++ b/src/core/strutils.c
@@ -109,6 +109,68 @@ int unescape_common(char *dst, char *src, int src_len)
return j;
}
+/*! \brief
+ * add backslashes for CR LF
+ */
+int escape_crlf(str *sin, str *sout)
+{
+ int i, j;
+
+ if(sout == 0 || sin == 0 || sin->len <= 0)
+ return -1;
+ j = 0;
+ for(i = 0; i < sin->len; i++) {
+ switch(sin->s[i]) {
+ case '\n':
+ sout->s[j++] = '\\';
+ sout->s[j++] = 'n';
+ break;
+ case '\r':
+ sout->s[j++] = '\\';
+ sout->s[j++] = 'r';
+ break;
+ default:
+ sout->s[j++] = sin->s[i];
+ }
+ }
+ sout->len = j;
+ return 0;
+}
+
+/*! \brief
+ * remove backslashes for CR LF
+ */
+int unescape_crlf(str *sin, str *sout)
+{
+ int i, j;
+
+ if(sout == 0 || sin == 0 || sin->len <= 0)
+ return -1;
+ j = 0;
+ i = 0;
+ while(i < sin->len) {
+ if(sin->s[i] == '\\' && i + 1 < sin->len) {
+ switch(sin->s[i + 1]) {
+ case 'n':
+ sout->s[j++] = '\n';
+ i++;
+ break;
+ case 'r':
+ sout->s[j++] = '\r';
+ i++;
+ break;
+ default:
+ sout->s[j++] = sin->s[i];
+ }
+ } else {
+ sout->s[j++] = sin->s[i];
+ }
+ i++;
+ }
+ sout->len = j;
+ return 0;
+}
+
/*! \brief Unscape all printable ASCII characters */
int unescape_user(str *sin, str *sout)
{
diff --git a/src/core/strutils.h b/src/core/strutils.h
index b32e610512c..5781943dacb 100644
--- a/src/core/strutils.h
+++ b/src/core/strutils.h
@@ -56,6 +56,8 @@ int escape_common(char *dst, char *src, int src_len);
/* remove backslashes to special characters */
int unescape_common(char *dst, char *src, int src_len);
+int escape_crlf(str *sin, str *sout);
+int unescape_crlf(str *sin, str *sout);
int escape_user(str *sin, str *sout);
int unescape_user(str *sin, str *sout);
int escape_param(str *sin, str *sout);