Browse code

siptrace: removed storage of xheaders read/write flags in shared memory

- they are not changed at runtime, set at module initialization

Daniel-Constantin Mierla authored on 07/04/2020 15:46:01
Showing 2 changed files
... ...
@@ -166,8 +166,8 @@ int hep_capture_id = 1;
166 166
 int hep_vendor_id = 0;
167 167
 str hep_auth_key_str = {0, 0};
168 168
 
169
-int xheaders_write = 0;
170
-int xheaders_read = 0;
169
+int trace_xheaders_write = 0;
170
+int trace_xheaders_read = 0;
171 171
 
172 172
 str trace_send_sock_str = {0, 0};
173 173
 sip_uri_t *trace_send_sock_uri = 0;
... ...
@@ -175,9 +175,6 @@ sip_uri_t *trace_send_sock_uri = 0;
175 175
 str trace_dup_uri_str = {0, 0};
176 176
 sip_uri_t *trace_dup_uri = 0;
177 177
 
178
-int *xheaders_write_flag = NULL;
179
-int *xheaders_read_flag = NULL;
180
-
181 178
 static unsigned short traced_user_avp_type = 0;
182 179
 static int_str traced_user_avp;
183 180
 static str traced_user_avp_str = {NULL, 0};
... ...
@@ -242,8 +239,8 @@ static param_export_t params[] = {
242 239
 	{"trace_to_database", INT_PARAM, &trace_to_database},
243 240
 	{"trace_local_ip", PARAM_STR, &trace_local_ip},
244 241
 	{"trace_sl_acks", INT_PARAM, &trace_sl_acks},
245
-	{"xheaders_write", INT_PARAM, &xheaders_write},
246
-	{"xheaders_read", INT_PARAM, &xheaders_read},
242
+	{"xheaders_write", INT_PARAM, &trace_xheaders_write},
243
+	{"xheaders_read", INT_PARAM, &trace_xheaders_read},
247 244
 	{"hep_mode_on", INT_PARAM, &hep_mode_on},
248 245
 	{"force_send_sock", PARAM_STR, &trace_send_sock_str},
249 246
 	{"hep_version", INT_PARAM, &hep_version},
... ...
@@ -370,15 +367,6 @@ static int mod_init(void)
370 367
 		}
371 368
 	}
372 369
 
373
-	xheaders_write_flag = (int *)shm_malloc(sizeof(int));
374
-	xheaders_read_flag = (int *)shm_malloc(sizeof(int));
375
-	if(!(xheaders_write_flag && xheaders_read_flag)) {
376
-		LM_ERR("no more shm memory left\n");
377
-		return -1;
378
-	}
379
-	*xheaders_write_flag = xheaders_write;
380
-	*xheaders_read_flag = xheaders_read;
381
-
382 370
 	if(_siptrace_init_mode==SIPTRACE_INIT_MODE_ALL
383 371
 			|| _siptrace_init_mode==SIPTRACE_INIT_MODE_SCRIPT) {
384 372
 		if(trace_flag_param!=-1) {
... ...
@@ -36,8 +36,8 @@
36 36
 #include "siptrace_send.h"
37 37
 
38 38
 
39
-extern int *xheaders_write_flag;
40
-extern int *xheaders_read_flag;
39
+extern int trace_xheaders_write;
40
+extern int trace_xheaders_read;
41 41
 extern str trace_dup_uri_str;
42 42
 extern sip_uri_t *trace_dup_uri;
43 43
 
... ...
@@ -85,14 +85,15 @@ int sip_trace_xheaders_write(struct _siptrace_data *sto)
85 85
 	int eoh_offset = 0;
86 86
 	char *new_eoh = NULL;
87 87
 
88
-	if(xheaders_write_flag == NULL || *xheaders_write_flag == 0)
88
+	if(trace_xheaders_write == 0) {
89 89
 		return 0;
90
+	}
90 91
 
91 92
 	// Memory for the message with some additional headers.
92 93
 	// It gets free()ed in sip_trace_xheaders_free().
93 94
 	buf = pkg_malloc(sto->body.len + XHEADERS_BUFSIZE);
94 95
 	if(buf == NULL) {
95
-		LM_ERR("sip_trace_xheaders_write: out of memory\n");
96
+		LM_ERR("out of pkg memory\n");
96 97
 		return -1;
97 98
 	}
98 99
 
... ...
@@ -102,7 +103,7 @@ int sip_trace_xheaders_write(struct _siptrace_data *sto)
102 103
 	buf[sto->body.len] = '\0';
103 104
 	eoh = strstr(buf, "\r\n\r\n");
104 105
 	if(eoh == NULL) {
105
-		LM_ERR("sip_trace_xheaders_write: malformed message\n");
106
+		LM_ERR("malformed message\n");
106 107
 		goto error;
107 108
 	}
108 109
 	eoh += 2; // the first \r\n belongs to the last header => skip it
... ...
@@ -121,7 +122,7 @@ int sip_trace_xheaders_write(struct _siptrace_data *sto)
121 122
 					(unsigned long long)sto->tv.tv_usec, sto->method.len,
122 123
 					sto->method.s, sto->dir);
123 124
 	if(bytes_written >= XHEADERS_BUFSIZE) {
124
-		LM_ERR("sip_trace_xheaders_write: string too long\n");
125
+		LM_ERR("string too long\n");
125 126
 		goto error;
126 127
 	}
127 128
 
... ...
@@ -136,8 +137,9 @@ int sip_trace_xheaders_write(struct _siptrace_data *sto)
136 137
 	sto->body.len += bytes_written;
137 138
 	return 0;
138 139
 error:
139
-	if(buf != NULL)
140
+	if(buf != NULL) {
140 141
 		pkg_free(buf);
142
+	}
141 143
 	return -1;
142 144
 }
143 145
 
... ...
@@ -152,8 +154,9 @@ int sip_trace_xheaders_read(struct _siptrace_data *sto)
152 154
 	char *xheaders = NULL;
153 155
 	long long unsigned int tv_sec, tv_usec;
154 156
 
155
-	if(xheaders_read_flag == NULL || *xheaders_read_flag == 0)
157
+	if(trace_xheaders_read == 0) {
156 158
 		return 0;
159
+	}
157 160
 
158 161
 	// Find the end-of-header marker \r\n\r\n
159 162
 	searchend = sto->body.s + sto->body.len - 3;
... ...
@@ -164,7 +167,7 @@ int sip_trace_xheaders_read(struct _siptrace_data *sto)
164 167
 		eoh = memchr(eoh + 1, '\r', searchend - eoh);
165 168
 	}
166 169
 	if(eoh == NULL) {
167
-		LM_ERR("sip_trace_xheaders_read: malformed message\n");
170
+		LM_ERR("malformed message\n");
168 171
 		return -1;
169 172
 	}
170 173
 
... ...
@@ -175,7 +178,7 @@ int sip_trace_xheaders_read(struct _siptrace_data *sto)
175 178
 	*eoh = '\0';
176 179
 	xheaders = strstr(sto->body.s, "\r\nX-Siptrace-Fromip: ");
177 180
 	if(xheaders == NULL) {
178
-		LM_ERR("sip_trace_xheaders_read: message without x-headers "
181
+		LM_ERR("message without x-headers "
179 182
 			   "from %.*s, callid %.*s\n",
180 183
 				sto->fromip.len, sto->fromip.s, sto->callid.len, sto->callid.s);
181 184
 		return -1;
... ...
@@ -188,7 +191,7 @@ int sip_trace_xheaders_read(struct _siptrace_data *sto)
188 191
 	sto->method.s = pkg_malloc(51);
189 192
 	sto->dir = pkg_malloc(4);
190 193
 	if(!(sto->fromip.s && sto->toip.s && sto->method.s && sto->dir)) {
191
-		LM_ERR("sip_trace_xheaders_read: out of memory\n");
194
+		LM_ERR("out of pkg memory\n");
192 195
 		goto erroraftermalloc;
193 196
 	}
194 197
 
... ...
@@ -202,7 +205,7 @@ int sip_trace_xheaders_read(struct _siptrace_data *sto)
202 205
 			   sto->fromip.s, sto->toip.s, &tv_sec, &tv_usec, sto->method.s,
203 206
 			   sto->dir)
204 207
 			== EOF) {
205
-		LM_ERR("sip_trace_xheaders_read: malformed x-headers\n");
208
+		LM_ERR("malformed x-headers\n");
206 209
 		goto erroraftermalloc;
207 210
 	}
208 211
 	sto->fromip.len = strlen(sto->fromip.s);
... ...
@@ -221,14 +224,22 @@ int sip_trace_xheaders_read(struct _siptrace_data *sto)
221 224
 	return 0;
222 225
 
223 226
 erroraftermalloc:
224
-	if(sto->fromip.s)
227
+	if(sto->fromip.s) {
225 228
 		pkg_free(sto->fromip.s);
226
-	if(sto->toip.s)
229
+		sto->fromip.s = 0;
230
+	}
231
+	if(sto->toip.s) {
227 232
 		pkg_free(sto->toip.s);
228
-	if(sto->method.s)
233
+		sto->toip.s = 0;
234
+	}
235
+	if(sto->method.s) {
229 236
 		pkg_free(sto->method.s);
230
-	if(sto->dir)
237
+		sto->method.s = 0;
238
+	}
239
+	if(sto->dir) {
231 240
 		pkg_free(sto->dir);
241
+		sto->dir = 0;
242
+	}
232 243
 	return -1;
233 244
 }
234 245
 
... ...
@@ -237,18 +248,26 @@ erroraftermalloc:
237 248
  */
238 249
 int sip_trace_xheaders_free(struct _siptrace_data *sto)
239 250
 {
240
-	if(xheaders_write_flag != NULL && *xheaders_write_flag != 0) {
241
-		if(sto->body.s)
251
+	if(trace_xheaders_write != 0) {
252
+		if(sto->body.s) {
242 253
 			pkg_free(sto->body.s);
254
+			sto->body.s = 0;
255
+		}
243 256
 	}
244 257
 
245
-	if(xheaders_read_flag != NULL && *xheaders_read_flag != 0) {
246
-		if(sto->fromip.s)
258
+	if(trace_xheaders_read != 0) {
259
+		if(sto->fromip.s) {
247 260
 			pkg_free(sto->fromip.s);
248
-		if(sto->toip.s)
261
+			sto->fromip.s = 0;
262
+		}
263
+		if(sto->toip.s) {
249 264
 			pkg_free(sto->toip.s);
250
-		if(sto->dir)
265
+			sto->toip.s = 0;
266
+		}
267
+		if(sto->dir) {
251 268
 			pkg_free(sto->dir);
269
+			sto->dir = 0;
270
+		}
252 271
 	}
253 272
 
254 273
 	return 0;