diff --git a/src/modules/db_flatstore/db_flatstore.c b/src/modules/db_flatstore/db_flatstore.c index b30a77a6eb4..6e3236421d8 100644 --- a/src/modules/db_flatstore/db_flatstore.c +++ b/src/modules/db_flatstore/db_flatstore.c @@ -62,6 +62,10 @@ str flat_pid = STR_NULL; /** Enable/disable flushing after eaach write. */ int flat_flush = 1; +/** Escape delimiter using + * ""%" HEX HEX" mechanism for escaping from RFC 2396 + * */ +int encode_delimiter = 1; /** Row delimiter. * The character in this variable will be used to delimit rows. @@ -116,6 +120,7 @@ static cmd_export_t cmds[] = { /* Exported parameters */ static param_export_t params[] = { {"flush", PARAM_INT, &flat_flush}, + {"encode_delimiter", PARAM_INT, &encode_delimiter}, {"field_delimiter", PARAM_STR, &flat_delimiter}, {"record_delimiter", PARAM_STR, &flat_record_delimiter}, {"escape_char", PARAM_STR, &flat_escape}, diff --git a/src/modules/db_flatstore/doc/db_flatstore.xml b/src/modules/db_flatstore/doc/db_flatstore.xml index 5e16cdc0f12..6ead114feab 100644 --- a/src/modules/db_flatstore/doc/db_flatstore.xml +++ b/src/modules/db_flatstore/doc/db_flatstore.xml @@ -18,12 +18,22 @@ FhG FOKUS jan@iptel.org + + Julien + Chavanton + Flowroute + jchavanton@gmail.com + 2004 2005 FhG FOKUS + + 2017 + Flowroute + @@ -87,7 +97,7 @@ modparam("acc", "db_url", "flatstore:/var/log/acc") Rotating Log Files The module implements a &kamailio; management interface command called - flatstore.rotate. When &kamailio; receives the command it will + flatstore.k_rotate. When &kamailio; receives the command it will close and reopen all files used by the db_flatstore module. The rotation itself has to be done by another application (such as logrotate). Follow these steps to rotate files generated by @@ -113,7 +123,7 @@ mv acc_4.log acc_3.log.20050605 Send &kamailio; the management command to close and reopen the renamed files: -&sercmd; flatstore.rotate +&sercmd; flatstore.k_rotate This will force &kamailio; to close the renamed files and open new ones with original names, such as diff --git a/src/modules/db_flatstore/doc/db_flatstore_params.xml b/src/modules/db_flatstore/doc/db_flatstore_params.xml index d515cc60497..2f52a791af9 100644 --- a/src/modules/db_flatstore/doc/db_flatstore_params.xml +++ b/src/modules/db_flatstore/doc/db_flatstore_params.xml @@ -17,4 +17,15 @@ Default value is 1. +
+ <varname>encode_delimiter</varname> (integer) + + Enable or disable encoding tof the escaped character + using ""%" HEX HEX" mechanism for escaping from RFC 2396 + + + Default value is 1. + Default delimiter '|' is replaced with %7C if found in any string + +
diff --git a/src/modules/db_flatstore/km_flatstore.c b/src/modules/db_flatstore/km_flatstore.c index 356a97bc3d8..9bdd4d6c8a0 100644 --- a/src/modules/db_flatstore/km_flatstore.c +++ b/src/modules/db_flatstore/km_flatstore.c @@ -182,7 +182,20 @@ int flat_db_insert(const db1_con_t* h, const db_key_t* k, const db_val_t* v, break; case DB1_STR: - fprintf(f, "%.*s", VAL_STR(v + i).len, VAL_STR(v + i).s); + if (!encode_delimiter) { + fprintf(f, "%.*s", VAL_STR(v + i).len, VAL_STR(v + i).s); + } else { + s = VAL_STR(v + i).s; + l = VAL_STR(v + i).len; + while (l--) { + if (*s == *flat_delimiter.s) { + fprintf(f, "%%%02X", (*s & 0xff) ); + } else { + fprintf(f, "%c", *s); + } + ++s; + } + } break; case DB1_DATETIME: diff --git a/src/modules/db_flatstore/km_flatstore.h b/src/modules/db_flatstore/km_flatstore.h index 9d6053b5003..6461f30a10c 100644 --- a/src/modules/db_flatstore/km_flatstore.h +++ b/src/modules/db_flatstore/km_flatstore.h @@ -27,6 +27,8 @@ #include "../../lib/srdb1/db_key.h" #include "../../lib/srdb1/db_con.h" +extern str flat_delimiter; +extern int encode_delimiter; /* * Initialize database module