소스 검색

Merge pull request #1262 from jchavanton/db_flatstore_delimiter

db_flatstore: encode delimiter param
Daniel-Constantin Mierla 8 년 전
부모
커밋
c203af8d97

+ 5 - 0
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},

+ 12 - 2
src/modules/db_flatstore/doc/db_flatstore.xml

@@ -18,12 +18,22 @@
 		<affiliation><orgname>FhG FOKUS</orgname></affiliation>
 		<email>[email protected]</email>
 	    </author>
+	    <author>
+		<firstname>Julien</firstname>
+		<surname>Chavanton</surname>
+		<affiliation><orgname>Flowroute</orgname></affiliation>
+		<email>[email protected]</email>
+	    </author>
 	</authorgroup>
 	<copyright>
 	    <year>2004</year>
 	    <year>2005</year>
 	    <holder>FhG FOKUS</holder>
 	</copyright>
+	<copyright>
+	    <year>2017</year>
+	    <holder>Flowroute</holder>
+	</copyright>
     </bookinfo>
 
     <chapter>
@@ -87,7 +97,7 @@ modparam("acc", "db_url", "flatstore:/var/log/acc")
 	    <title>Rotating Log Files</title>
 	    <para>
 		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:
 			<screen>
-&sercmd; flatstore.rotate
+&sercmd; flatstore.k_rotate
 			</screen>
 			This will force &kamailio; to close the renamed files and open
 			new ones with original names, such as

+ 11 - 0
src/modules/db_flatstore/doc/db_flatstore_params.xml

@@ -17,4 +17,15 @@
 	    Default value is 1.
 	</para>
     </section>
+    <section id="encode_delimiter">
+	<title><varname>encode_delimiter</varname> (integer)</title>
+	<para>
+	    Enable or disable encoding tof the escaped character
+	    using  ""%" HEX HEX" mechanism for escaping from RFC 2396
+	</para>
+	<para>
+	    Default value is 1.
+	    Default delimiter '|' is replaced with %7C if found in any string
+	</para>
+    </section>
 </section>

+ 14 - 1
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:

+ 2 - 0
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