Browse code

core: add new param sip_parser_log_oneline

To log SIP headers with . 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_LOG_ONELINE "sip_parser_log_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_LOG_ONELINE}  { count(); yylval.strval=yytext; return SIP_PARSER_LOG_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_LOG_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_LOG_ONELINE EQUAL intno { default_core_cfg.sip_parser_log_oneline=$3; }
975
+	| SIP_PARSER_LOG_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 print 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_log_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_log_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 */
... ...
@@ -745,7 +745,7 @@ int parse_msg(char* const buf, const unsigned int len, struct sip_msg* const msg
745 745
 error:
746 746
 	/* more debugging, msg->orig is/should be null terminated*/
747 747
 	LOG(cfg_get(core, core_cfg, sip_parser_log), "ERROR: parse_msg: message=<%.*s>\n",
748
-			(int)msg->len, ZSW(msg->buf));
748
+			(int)msg->len, ZSW(ksr_buf_oneline(msg->buf, (int)msg->len)));
749 749
 	return -1;
750 750
 }
751 751
 
... ...
@@ -1093,6 +1093,42 @@ int msg_set_time(sip_msg_t* const msg)
1093 1093
 	return gettimeofday(&msg->tval, NULL);
1094 1094
 }
1095 1095
 
1096
+/**
1097
+ * replace \r\n with . and space
1098
+ */
1099
+char *ksr_buf_oneline(char *inbuf, int inlen)
1100
+{
1101
+	static char outbuf[BUF_SIZE];
1102
+	int outlen;
1103
+	int i = 0;
1104
+
1105
+	if (cfg_get(core, core_cfg, sip_parser_log_oneline) == 0) {
1106
+		return inbuf;
1107
+	}
1108
+
1109
+	if (inbuf == NULL) {
1110
+		outbuf[0] = '\0';
1111
+		return outbuf;
1112
+	}
1113
+
1114
+	outlen = (inlen < BUF_SIZE) ? inlen : BUF_SIZE - 1;
1115
+	memcpy(outbuf, inbuf, outlen);
1116
+	outbuf[outlen] = '\0';
1117
+
1118
+	for (i = 0; i < outlen;  i++) {
1119
+		if (outbuf[i] == '\r')
1120
+		{
1121
+			outbuf[i] = '.';
1122
+		}
1123
+		else if (outbuf[i] == '\n')
1124
+		{
1125
+			outbuf[i] = ' ';
1126
+		}
1127
+	}
1128
+
1129
+	return outbuf;
1130
+}
1131
+
1096 1132
 /**
1097 1133
  * get source ip, port and protocol in SIP URI format
1098 1134
  * - 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
526
+ */
527
+char *ksr_buf_oneline(char *inbuf, int inlen);
528
+
524 529
 /**
525 530
  * get source ip, port and protocol in SIP URI format
526 531
  */
... ...
@@ -2703,11 +2703,11 @@ nextvia:
2703 2703
 
2704 2704
 error:
2705 2705
 	if(end > buffer) {
2706
-		LM_ERR("parsing via on: <%.*s>\n", (int)(end - buffer), ZSW(buffer));
2706
+		LM_ERR("parsing via on: <%.*s>\n", (int)(end - buffer), ZSW(ksr_buf_oneline(buffer, (int)(end - buffer))));
2707 2707
 	}
2708 2708
 	if((tmp > buffer) && (tmp < end)) {
2709 2709
 		LM_ERR("parse error, parsed so far:<%.*s>\n", (int)(tmp - buffer),
2710
-				ZSW(buffer));
2710
+				ZSW(ksr_buf_oneline(buffer, (int)(tmp - buffer))));
2711 2711
 	} else {
2712 2712
 		LM_ERR("via parse error\n");
2713 2713
 	}