Browse code

core: add new param sip_parser_oneline

To log SIP headers with comma instead of \r\n.

Stefan Mititelu authored on 25/10/2021 06:08:36
Showing 7 changed files
... ...
@@ -373,6 +373,7 @@ MEMSAFETY	"mem_safety"
373 373
 MEMJOIN		"mem_join"
374 374
 MEMSTATUSMODE		"mem_status_mode"
375 375
 CORELOG		"corelog"|"core_log"
376
+SIP_PARSER_ONELINE "sip_parser_oneline"
376 377
 SIP_PARSER_LOG "sip_parser_log"
377 378
 SIP_PARSER_MODE "sip_parser_mode"
378 379
 SIP_WARNING sip_warning
... ...
@@ -835,6 +836,7 @@ IMPORTFILE      "import_file"
835 836
 <INITIAL>{MEMSAFETY}	{ count(); yylval.strval=yytext; return MEMSAFETY; }
836 837
 <INITIAL>{MEMJOIN}	{ count(); yylval.strval=yytext; return MEMJOIN; }
837 838
 <INITIAL>{MEMSTATUSMODE}	{ count(); yylval.strval=yytext; return MEMSTATUSMODE; }
839
+<INITIAL>{SIP_PARSER_ONELINE}  { count(); yylval.strval=yytext; return SIP_PARSER_ONELINE; }
838 840
 <INITIAL>{SIP_PARSER_LOG}  { count(); yylval.strval=yytext; return SIP_PARSER_LOG; }
839 841
 <INITIAL>{SIP_PARSER_MODE}  { count(); yylval.strval=yytext; return SIP_PARSER_MODE; }
840 842
 <INITIAL>{CORELOG}	{ count(); yylval.strval=yytext; return CORELOG; }
... ...
@@ -394,6 +394,7 @@ extern char *default_routename;
394 394
 %token MEMSAFETY
395 395
 %token MEMJOIN
396 396
 %token MEMSTATUSMODE
397
+%token SIP_PARSER_ONELINE
397 398
 %token SIP_PARSER_LOG
398 399
 %token SIP_PARSER_MODE
399 400
 %token CORELOG
... ...
@@ -970,6 +971,8 @@ assign_stm:
970 971
 	| MEMJOIN EQUAL error { yyerror("int value expected"); }
971 972
 	| MEMSTATUSMODE EQUAL intno { default_core_cfg.mem_status_mode=$3; }
972 973
 	| MEMSTATUSMODE EQUAL error { yyerror("int value expected"); }
974
+	| SIP_PARSER_ONELINE EQUAL intno { default_core_cfg.sip_parser_oneline=$3; }
975
+	| SIP_PARSER_ONELINE EQUAL error { yyerror("int value expected"); }
973 976
 	| SIP_PARSER_LOG EQUAL intno { default_core_cfg.sip_parser_log=$3; }
974 977
 	| SIP_PARSER_LOG EQUAL error { yyerror("int value expected"); }
975 978
 	| SIP_PARSER_MODE EQUAL intno { ksr_sip_parser_mode=$3; }
... ...
@@ -115,6 +115,7 @@ struct cfg_group_core default_core_cfg = {
115 115
 	1, /*!< mem_safety - 0 disabled; 1 enabled */
116 116
 	1, /*!< mem_join - 1 enabled */
117 117
 	0, /*!< mem_status_mode - 0 only free fragments, 1 all fragements */
118
+	0, /*!< sip msg parser on one line*/
118 119
 	L_ERR, /*!< sip msg parser error log level*/
119 120
 	L_ERR, /*!< corelog */
120 121
 	L_DBG, /*!< latency cfg log */
... ...
@@ -319,6 +320,8 @@ cfg_def_t core_cfg_def[] = {
319 320
 		"join free memory fragments"},
320 321
 	{"mem_status_mode",		CFG_VAR_INT|CFG_ATOMIC,	0, 0, 0, 0,
321 322
 		"print status for free or all memory fragments"},
323
+	{"sip_parser_oneline",		CFG_VAR_INT|CFG_ATOMIC,	0, 0, 0, 0,
324
+		"sip msg print on one line"},
322 325
 	{"sip_parser_log",		CFG_VAR_INT|CFG_ATOMIC,	0, 0, 0, 0,
323 326
 		"log level for sip msg parser error messages"},
324 327
 	{"corelog",		CFG_VAR_INT|CFG_ATOMIC,	0, 0, 0, 0,
... ...
@@ -103,6 +103,7 @@ struct cfg_group_core {
103 103
 	int mem_safety; /*!< memory safety control option */
104 104
 	int mem_join; /*!< memory free fragments join option */
105 105
 	int mem_status_mode; /*!< memory status printed for free/all fragments */
106
+	int sip_parser_oneline; /*!< sip msg on one line */
106 107
 	int sip_parser_log; /*!< sip msg parser error log level*/
107 108
 	int corelog; /*!< log level for non-critcal core error messages */
108 109
 	int latency_cfg_log; /*!< log level for printing latency of routing blocks */
... ...
@@ -743,6 +743,11 @@ int parse_msg(char* const buf, const unsigned int len, struct sip_msg* const msg
743 743
 	return 0;
744 744
 
745 745
 error:
746
+	/* the message should be logged in one line only */
747
+	if (cfg_get(core, core_cfg, sip_parser_oneline) > 0) {
748
+		msg_to_oneline(msg->buf);
749
+	}
750
+
746 751
 	/* more debugging, msg->orig is/should be null terminated*/
747 752
 	LOG(cfg_get(core, core_cfg, sip_parser_log), "ERROR: parse_msg: message=<%.*s>\n",
748 753
 			(int)msg->len, ZSW(msg->buf));
... ...
@@ -1093,6 +1098,29 @@ int msg_set_time(sip_msg_t* const msg)
1093 1098
 	return gettimeofday(&msg->tval, NULL);
1094 1099
 }
1095 1100
 
1101
+/**
1102
+ * replace \r\n with comma and space in msg->buf
1103
+ */
1104
+void msg_to_oneline(char *buf)
1105
+{
1106
+	int i = 0;
1107
+	int len = strlen(buf)+1;
1108
+
1109
+	for (i = 0; i < len; i++)
1110
+	{
1111
+		if(buf[i] == '\r')
1112
+		{
1113
+			buf[i] = ',';
1114
+		}
1115
+		else if(buf[i] == '\n')
1116
+		{
1117
+			buf[i] = ' ';
1118
+		}
1119
+	}
1120
+
1121
+	return ;
1122
+}
1123
+
1096 1124
 /**
1097 1125
  * get source ip, port and protocol in SIP URI format
1098 1126
  * - tmode - 0: short format (transport=udp is not added, being default)
... ...
@@ -521,6 +521,11 @@ int msg_set_time(sip_msg_t* const msg);
521 521
  */
522 522
 void msg_ldata_reset(sip_msg_t*);
523 523
 
524
+/**
525
+ * replace \r\n with , and space in msg->buf
526
+ */
527
+void msg_to_oneline(char*);
528
+
524 529
 /**
525 530
  * get source ip, port and protocol in SIP URI format
526 531
  */
... ...
@@ -2702,6 +2702,11 @@ nextvia:
2702 2702
 	goto parse_again;
2703 2703
 
2704 2704
 error:
2705
+	/* the message should be logged in one line only */
2706
+	if (cfg_get(core, core_cfg, sip_parser_oneline) > 0) {
2707
+		msg_to_oneline(buffer);
2708
+	}
2709
+
2705 2710
 	if(end > buffer) {
2706 2711
 		LM_ERR("parsing via on: <%.*s>\n", (int)(end - buffer), ZSW(buffer));
2707 2712
 	}