Browse code

posops: init data structure for each function

Daniel-Constantin Mierla authored on 29/09/2021 07:32:50
Showing 1 changed files
... ...
@@ -149,6 +149,15 @@ static void mod_destroy(void)
149 149
 	return;
150 150
 }
151 151
 
152
+/**
153
+ *
154
+ */
155
+static void posops_data_init(void)
156
+{
157
+	memset(&_posops_data, 0, sizeof(posops_data_t));
158
+	_posops_data.ret = -1;
159
+}
160
+
152 161
 /**
153 162
  *
154 163
  */
... ...
@@ -157,6 +166,7 @@ static int ki_posops_pos_append(sip_msg_t *msg, int idx, str *val)
157 166
 	int offset;
158 167
 	sr_lump_t *anchor = NULL;
159 168
 
169
+	posops_data_init();
160 170
 	if(val==NULL || val->s==NULL || val->len<=0) {
161 171
 		LM_ERR("invalid val parameter\n");
162 172
 		return -1;
... ...
@@ -189,6 +199,7 @@ static int w_posops_pos_append(sip_msg_t* msg, char* p1idx, char* p2val)
189 199
 	int idx = 0;
190 200
 	str val = STR_NULL;
191 201
 
202
+	posops_data_init();
192 203
 	if(fixup_get_ivalue(msg, (gparam_t*)p1idx, &idx)!=0) {
193 204
 		LM_ERR("unable to get idx parameter\n");
194 205
 		return -1;
... ...
@@ -210,6 +221,7 @@ static int ki_posops_pos_insert(sip_msg_t *msg, int idx, str *val)
210 221
 	int offset;
211 222
 	sr_lump_t *anchor = NULL;
212 223
 
224
+	posops_data_init();
213 225
 	if(val==NULL || val->s==NULL || val->len<=0) {
214 226
 		LM_ERR("invalid val parameter\n");
215 227
 		return -1;
... ...
@@ -242,6 +254,7 @@ static int w_posops_pos_insert(sip_msg_t* msg, char* p1idx, char* p2val)
242 254
 	int idx = 0;
243 255
 	str val = STR_NULL;
244 256
 
257
+	posops_data_init();
245 258
 	if(fixup_get_ivalue(msg, (gparam_t*)p1idx, &idx)!=0) {
246 259
 		LM_ERR("unable to get idx parameter\n");
247 260
 		return -1;
... ...
@@ -264,6 +277,7 @@ static int ki_posops_pos_rm(sip_msg_t *msg, int idx, int len)
264 277
 	int offset;
265 278
 	sr_lump_t *anchor = NULL;
266 279
 
280
+	posops_data_init();
267 281
 	if(len<=0) {
268 282
 		LM_ERR("length invalid: %d (msg-len: %d)\n", len, msg->len);
269 283
 		return -1;
... ...
@@ -304,6 +318,7 @@ static int w_posops_pos_rm(sip_msg_t* msg, char* p1idx, char* p2len)
304 318
 	int idx = 0;
305 319
 	int len = 0;
306 320
 
321
+	posops_data_init();
307 322
 	if(fixup_get_ivalue(msg, (gparam_t*)p1idx, &idx)!=0) {
308 323
 		LM_ERR("unable to get idx parameter\n");
309 324
 		return -1;
... ...
@@ -321,7 +336,7 @@ static int w_posops_pos_rm(sip_msg_t* msg, char* p1idx, char* p2len)
321 336
  */
322 337
 static int ki_posops_pos_headers_start(sip_msg_t* msg)
323 338
 {
324
-	memset(&_posops_data, 0, sizeof(posops_data_t));
339
+	posops_data_init();
325 340
 	if (parse_headers(msg, HDR_EOH_F, 0) == -1) {
326 341
 		LM_ERR("failed to parse headers\n");
327 342
 		return -1;
... ...
@@ -346,7 +361,7 @@ static int w_posops_pos_headers_start(sip_msg_t* msg, char* p1, char* p2)
346 361
  */
347 362
 static int ki_posops_pos_headers_end(sip_msg_t* msg)
348 363
 {
349
-	memset(&_posops_data, 0, sizeof(posops_data_t));
364
+	posops_data_init();
350 365
 	if (parse_headers(msg, HDR_EOH_F, 0) == -1) {
351 366
 		LM_ERR("failed to parse headers\n");
352 367
 		return -1;
... ...
@@ -373,7 +388,7 @@ static int ki_posops_pos_body_start(sip_msg_t* msg)
373 388
 {
374 389
 	char *body = 0;
375 390
 
376
-	memset(&_posops_data, 0, sizeof(posops_data_t));
391
+	posops_data_init();
377 392
 	if (parse_headers(msg, HDR_EOH_F, 0) == -1) {
378 393
 		LM_ERR("failed to parse headers\n");
379 394
 		return -1;
... ...
@@ -404,7 +419,7 @@ static int w_posops_pos_body_start(sip_msg_t* msg, char* p1, char* p2)
404 419
  */
405 420
 static int ki_posops_pos_body_end(sip_msg_t* msg)
406 421
 {
407
-	memset(&_posops_data, 0, sizeof(posops_data_t));
422
+	posops_data_init();
408 423
 	if (parse_headers(msg, HDR_EOH_F, 0) == -1) {
409 424
 		LM_ERR("failed to parse headers\n");
410 425
 		return -1;
... ...
@@ -437,6 +452,7 @@ static int ki_posops_pos_find_str(sip_msg_t *msg, int idx, str *val)
437 452
 	char *p;
438 453
 	str text;
439 454
 
455
+	posops_data_init();
440 456
 	if(val==NULL || val->s==NULL || val->len<=0) {
441 457
 		return -1;
442 458
 	}
... ...
@@ -467,6 +483,7 @@ static int w_posops_pos_find_str(sip_msg_t* msg, char* p1idx, char* p2val)
467 483
 	int idx = 0;
468 484
 	str val = STR_NULL;
469 485
 
486
+	posops_data_init();
470 487
 	if(fixup_get_ivalue(msg, (gparam_t*)p1idx, &idx)!=0) {
471 488
 		LM_ERR("unable to get idx parameter\n");
472 489
 		return -1;
... ...
@@ -488,6 +505,7 @@ static int ki_posops_pos_findi_str(sip_msg_t *msg, int idx, str *val)
488 505
 	char *p;
489 506
 	str text;
490 507
 
508
+	posops_data_init();
491 509
 	if(val==NULL || val->s==NULL || val->len<=0) {
492 510
 		return -1;
493 511
 	}
... ...
@@ -519,6 +537,7 @@ static int w_posops_pos_findi_str(sip_msg_t* msg, char* p1idx, char* p2val)
519 537
 	int idx = 0;
520 538
 	str val = STR_NULL;
521 539
 
540
+	posops_data_init();
522 541
 	if(fixup_get_ivalue(msg, (gparam_t*)p1idx, &idx)!=0) {
523 542
 		LM_ERR("unable to get idx parameter\n");
524 543
 		return -1;
... ...
@@ -542,6 +561,7 @@ static int ki_posops_pos_rfind_str(sip_msg_t *msg, int idx, str *val)
542 561
 	char *p;
543 562
 	str text;
544 563
 
564
+	posops_data_init();
545 565
 	if(val==NULL || val->s==NULL || val->len<=0) {
546 566
 		return -1;
547 567
 	}
... ...
@@ -572,6 +592,7 @@ static int w_posops_pos_rfind_str(sip_msg_t* msg, char* p1idx, char* p2val)
572 592
 	int idx = 0;
573 593
 	str val = STR_NULL;
574 594
 
595
+	posops_data_init();
575 596
 	if(fixup_get_ivalue(msg, (gparam_t*)p1idx, &idx)!=0) {
576 597
 		LM_ERR("unable to get idx parameter\n");
577 598
 		return -1;
... ...
@@ -593,6 +614,7 @@ static int ki_posops_pos_rfindi_str(sip_msg_t *msg, int idx, str *val)
593 614
 	char *p;
594 615
 	str text;
595 616
 
617
+	posops_data_init();
596 618
 	if(val==NULL || val->s==NULL || val->len<=0) {
597 619
 		return -1;
598 620
 	}
... ...
@@ -624,6 +646,7 @@ static int w_posops_pos_rfindi_str(sip_msg_t* msg, char* p1idx, char* p2val)
624 646
 	int idx = 0;
625 647
 	str val = STR_NULL;
626 648
 
649
+	posops_data_init();
627 650
 	if(fixup_get_ivalue(msg, (gparam_t*)p1idx, &idx)!=0) {
628 651
 		LM_ERR("unable to get idx parameter\n");
629 652
 		return -1;
... ...
@@ -670,6 +693,7 @@ static int ki_posops_pos_search(sip_msg_t* msg, int idx, str* sre)
670 693
 	regex_t mre;
671 694
 	int ret;
672 695
 
696
+	posops_data_init();
673 697
 	memset(&mre, 0, sizeof(regex_t));
674 698
 	if (regcomp(&mre, sre->s, REG_EXTENDED|REG_ICASE|REG_NEWLINE)!=0) {
675 699
 		LM_ERR("failed to compile regex: %.*s\n", sre->len, sre->s);
... ...
@@ -691,6 +715,7 @@ static int w_posops_pos_search(sip_msg_t* msg, char* p1idx, char* p2re)
691 715
 	int idx = 0;
692 716
 	regex_t *re = NULL;
693 717
 
718
+	posops_data_init();
694 719
 	if(fixup_get_ivalue(msg, (gparam_t*)p1idx, &idx)!=0) {
695 720
 		LM_ERR("unable to get idx parameter\n");
696 721
 		return -1;