Browse code

sipt: use helper function to check for valid ISUP/IAM

Henning Westerholt authored on 14/09/2021 15:32:50
Showing 1 changed files
... ...
@@ -246,23 +246,34 @@ struct module_exports exports = {
246 246
 	mod_destroy      /* destroy function */
247 247
 };
248 248
 
249
-static int sipt_get_hop_counter(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
249
+static inline int sipt_check_IAM(struct sip_msg *msg, str *body)
250 250
 {
251
-	str body;
252
-	body.s = get_body_part(msg, TYPE_APPLICATION,SUBTYPE_ISUP,&body.len);
251
+	body->s = get_body_part(msg, TYPE_APPLICATION,SUBTYPE_ISUP, &body->len);
253 252
 
254
-	if(body.s == NULL)
253
+	if(body->s == NULL)
255 254
 	{
256 255
 		LM_INFO("No ISUP Message Found");
257 256
 		return -1;
258 257
 	}
259 258
 
260
-	if(body.s[0] != ISUP_IAM)
259
+	if(body->s[0] != ISUP_IAM)
261 260
 	{
262 261
 		LM_DBG("message not an IAM\n");
263 262
 		return -1;
264 263
 	}
265
-	
264
+	return 1;
265
+}
266
+
267
+static int sipt_get_hop_counter(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
268
+{
269
+	str body;
270
+
271
+	if(sipt_check_IAM(msg, &body) != 1)
272
+	{
273
+		LM_INFO("could not check IAM\n");
274
+		return -1;
275
+	}
276
+
266 277
 	pv_get_sintval(msg, param, res, isup_get_hop_counter((unsigned char*)body.s, body.len));
267 278
 	return 0;
268 279
 }
... ...
@@ -291,17 +302,10 @@ static int sipt_get_event_info(struct sip_msg *msg, pv_param_t *param, pv_value_
291 302
 static int sipt_get_cpc(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
292 303
 {
293 304
 	str body;
294
-	body.s = get_body_part(msg, TYPE_APPLICATION,SUBTYPE_ISUP,&body.len);
295 305
 
296
-	if(body.s == NULL)
306
+	if(sipt_check_IAM(msg, &body) != 1)
297 307
 	{
298
-		LM_INFO("No ISUP Message Found");
299
-		return -1;
300
-	}
301
-
302
-	if(body.s[0] != ISUP_IAM)
303
-	{
304
-		LM_DBG("message not an IAM\n");
308
+		LM_INFO("could not check IAM\n");
305 309
 		return -1;
306 310
 	}
307 311
 	
... ...
@@ -312,17 +316,10 @@ static int sipt_get_cpc(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
312 316
 static int sipt_get_calling_party_nai(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
313 317
 {
314 318
 	str body;
315
-	body.s = get_body_part(msg, TYPE_APPLICATION,SUBTYPE_ISUP,&body.len);
316
-
317
-	if(body.s == NULL)
318
-	{
319
-		LM_INFO("No ISUP Message Found");
320
-		return -1;
321
-	}
322 319
 
323
-	if(body.s[0] != ISUP_IAM)
320
+	if(sipt_check_IAM(msg, &body) != 1)
324 321
 	{
325
-		LM_DBG("message not an IAM\n");
322
+		LM_INFO("could not check IAM\n");
326 323
 		return -1;
327 324
 	}
328 325
 	
... ...
@@ -334,18 +331,11 @@ static int sipt_get_calling_party(struct sip_msg *msg, pv_param_t *param, pv_val
334 331
 {
335 332
 	static char sb_s_buf[26];
336 333
 	str body;
337
-	body.s = get_body_part(msg, TYPE_APPLICATION,SUBTYPE_ISUP,&body.len);
338
-
339 334
 	memset(sb_s_buf, 0, 26);
340
-	if(body.s == NULL)
341
-	{
342
-		LM_INFO("No ISUP Message Found");
343
-		return -1;
344
-	}
345 335
 
346
-	if((body.s[0] != ISUP_IAM))
336
+	if(sipt_check_IAM(msg, &body) != 1)
347 337
 	{
348
-		LM_DBG("message not an IAM\n");
338
+		LM_INFO("could not check IAM\n");
349 339
 		return -1;
350 340
 	}
351 341
 
... ...
@@ -435,17 +425,10 @@ static int sipt_get_redirection_number(struct sip_msg *msg, pv_param_t *param, p
435 425
 static int sipt_get_redirection_reason(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
436 426
 {
437 427
 	str body;
438
-	body.s = get_body_part(msg, TYPE_APPLICATION,SUBTYPE_ISUP,&body.len);
439 428
 
440
-	if(body.s == NULL)
429
+	if(sipt_check_IAM(msg, &body) != 1)
441 430
 	{
442
-		LM_INFO("No ISUP Message Found");
443
-		return -1;
444
-	}
445
-
446
-	if((body.s[0] != ISUP_IAM))
447
-	{
448
-		LM_DBG("message not an IAM\n");
431
+		LM_INFO("could not check IAM\n");
449 432
 		return -1;
450 433
 	}
451 434
 
... ...
@@ -456,17 +439,10 @@ static int sipt_get_redirection_reason(struct sip_msg *msg, pv_param_t *param, p
456 439
 static int sipt_get_original_redirection_reason(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
457 440
 {
458 441
 	str body;
459
-	body.s = get_body_part(msg, TYPE_APPLICATION,SUBTYPE_ISUP,&body.len);
460 442
 
461
-	if(body.s == NULL)
443
+	if(sipt_check_IAM(msg, &body) != 1)
462 444
 	{
463
-		LM_INFO("No ISUP Message Found");
464
-		return -1;
465
-	}
466
-
467
-	if((body.s[0] != ISUP_IAM))
468
-	{
469
-		LM_DBG("message not an IAM\n");
445
+		LM_INFO("could not check IAM\n");
470 446
 		return -1;
471 447
 	}
472 448
 
... ...
@@ -477,17 +453,10 @@ static int sipt_get_original_redirection_reason(struct sip_msg *msg, pv_param_t
477 453
 static int sipt_get_redirecting_number_nai(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
478 454
 {
479 455
 	str body;
480
-	body.s = get_body_part(msg, TYPE_APPLICATION,SUBTYPE_ISUP,&body.len);
481
-
482
-	if(body.s == NULL)
483
-	{
484
-		LM_INFO("No ISUP Message Found");
485
-		return -1;
486
-	}
487 456
 
488
-	if((body.s[0] != ISUP_IAM))
457
+	if(sipt_check_IAM(msg, &body) != 1)
489 458
 	{
490
-		LM_DBG("message not an IAM\n");
459
+		LM_INFO("could not check IAM\n");
491 460
 		return -1;
492 461
 	}
493 462
 	
... ...
@@ -499,18 +468,11 @@ static int sipt_get_redirecting_number(struct sip_msg *msg, pv_param_t *param, p
499 468
 {
500 469
 	static char sb_s_buf[26];
501 470
 	str body;
502
-	body.s = get_body_part(msg, TYPE_APPLICATION,SUBTYPE_ISUP,&body.len);
503
-
504 471
 	memset(sb_s_buf, 0, 26);
505
-	if(body.s == NULL)
506
-	{
507
-		LM_INFO("No ISUP Message Found");
508
-		return -1;
509
-	}
510 472
 
511
-	if((body.s[0] != ISUP_IAM))
473
+	if(sipt_check_IAM(msg, &body) != 1)
512 474
 	{
513
-		LM_DBG("message not an IAM\n");
475
+		LM_INFO("could not check IAM\n");
514 476
 		return -1;
515 477
 	}
516 478
 
... ...
@@ -528,17 +490,10 @@ static int sipt_get_redirecting_number(struct sip_msg *msg, pv_param_t *param, p
528 490
 static int sipt_get_original_called_number_nai(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
529 491
 {
530 492
 	str body;
531
-	body.s = get_body_part(msg, TYPE_APPLICATION,SUBTYPE_ISUP,&body.len);
532
-
533
-	if(body.s == NULL)
534
-	{
535
-		LM_INFO("No ISUP Message Found");
536
-		return -1;
537
-	}
538 493
 
539
-	if((body.s[0] != ISUP_IAM))
494
+	if(sipt_check_IAM(msg, &body) != 1)
540 495
 	{
541
-		LM_DBG("message not an IAM\n");
496
+		LM_INFO("could not check IAM\n");
542 497
 		return -1;
543 498
 	}
544 499
 
... ...
@@ -550,18 +505,11 @@ static int sipt_get_original_called_number(struct sip_msg *msg, pv_param_t *para
550 505
 {
551 506
 	static char sb_s_buf[26];
552 507
 	str body;
553
-	body.s = get_body_part(msg, TYPE_APPLICATION,SUBTYPE_ISUP,&body.len);
554
-
555 508
 	memset(sb_s_buf, 0, 26);
556
-	if(body.s == NULL)
557
-	{
558
-		LM_INFO("No ISUP Message Found");
559
-		return -1;
560
-	}
561 509
 
562
-	if((body.s[0] != ISUP_IAM))
510
+	if(sipt_check_IAM(msg, &body) != 1)
563 511
 	{
564
-		LM_DBG("message not an IAM\n");
512
+		LM_INFO("could not check IAM\n");
565 513
 		return -1;
566 514
 	}
567 515
 
... ...
@@ -579,17 +527,10 @@ static int sipt_get_original_called_number(struct sip_msg *msg, pv_param_t *para
579 527
 static int sipt_get_generic_number_nai(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
580 528
 {
581 529
 	str body;
582
-	body.s = get_body_part(msg, TYPE_APPLICATION,SUBTYPE_ISUP,&body.len);
583 530
 
584
-	if(body.s == NULL)
531
+	if(sipt_check_IAM(msg, &body) != 1)
585 532
 	{
586
-		LM_INFO("No ISUP Message Found");
587
-		return -1;
588
-	}
589
-
590
-	if((body.s[0] != ISUP_IAM))
591
-	{
592
-		LM_DBG("message not an IAM\n");
533
+		LM_INFO("could not check IAM\n");
593 534
 		return -1;
594 535
 	}
595 536
 
... ...
@@ -601,21 +542,12 @@ static int sipt_get_generic_number(struct sip_msg *msg, pv_param_t *param, pv_va
601 542
 {
602 543
 	static char sb_s_buf[26];
603 544
 	str body;
604
-	body.s = get_body_part(msg, TYPE_APPLICATION,SUBTYPE_ISUP,&body.len);
605
-
606 545
 	memset(sb_s_buf, 0, 26);
607
-	if(body.s == NULL)
546
+	if(sipt_check_IAM(msg, &body) != 1)
608 547
 	{
609
-		LM_INFO("No ISUP Message Found");
548
+		LM_INFO("could not check IAM\n");
610 549
 		return -1;
611 550
 	}
612
-
613
-	if((body.s[0] != ISUP_IAM))
614
-	{
615
-		LM_DBG("message not an IAM\n");
616
-		return -1;
617
-	}
618
-
619 551
 	isup_get_generic_number((unsigned char*)body.s, body.len, sb_s_buf);
620 552
 
621 553
 	if (strlen(sb_s_buf) > 0)
... ...
@@ -630,17 +562,9 @@ static int sipt_get_generic_number(struct sip_msg *msg, pv_param_t *param, pv_va
630 562
 static int sipt_get_presentation(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
631 563
 {
632 564
 	str body;
633
-	body.s = get_body_part(msg, TYPE_APPLICATION,SUBTYPE_ISUP,&body.len);
634
-
635
-	if(body.s == NULL)
565
+	if(sipt_check_IAM(msg, &body) != 1)
636 566
 	{
637
-		LM_INFO("No ISUP Message Found");
638
-		return -1;
639
-	}
640
-
641
-	if(body.s[0] != ISUP_IAM)
642
-	{
643
-		LM_DBG("message not an IAM\n");
567
+		LM_INFO("could not check IAM\n");
644 568
 		return -1;
645 569
 	}
646 570
 	
... ...
@@ -651,19 +575,12 @@ static int sipt_get_presentation(struct sip_msg *msg, pv_param_t *param, pv_valu
651 575
 static int sipt_get_screening(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
652 576
 {
653 577
 	str body;
654
-	body.s = get_body_part(msg, TYPE_APPLICATION,SUBTYPE_ISUP,&body.len);
655
-
656
-	if(body.s == NULL)
578
+	if(sipt_check_IAM(msg, &body) != 1)
657 579
 	{
658
-		LM_INFO("No ISUP Message Found");
580
+		LM_INFO("could not check IAM\n");
659 581
 		return -1;
660 582
 	}
661 583
 
662
-	if(body.s[0] != ISUP_IAM)
663
-	{
664
-		LM_DBG("message not an IAM\n");
665
-		return -1;
666
-	}
667 584
 	LM_DBG("about to get screening\n");
668 585
 	
669 586
 	pv_get_sintval(msg, param, res, isup_get_screening((unsigned char*)body.s, body.len));
... ...
@@ -695,17 +612,9 @@ static int sipt_get_charge_indicator(struct sip_msg *msg, pv_param_t *param, pv_
695 612
 static int sipt_get_called_party_nai(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
696 613
 {
697 614
 	str body;
698
-	body.s = get_body_part(msg, TYPE_APPLICATION,SUBTYPE_ISUP,&body.len);
699
-
700
-	if(body.s == NULL)
615
+	if(sipt_check_IAM(msg, &body) != 1)
701 616
 	{
702
-		LM_INFO("No ISUP Message Found");
703
-		return -1;
704
-	}
705
-
706
-	if(body.s[0] != ISUP_IAM)
707
-	{
708
-		LM_DBG("message not an IAM\n");
617
+		LM_INFO("could not check IAM\n");
709 618
 		return -1;
710 619
 	}
711 620
 	
... ...
@@ -717,18 +626,10 @@ static int sipt_get_called_party(struct sip_msg *msg, pv_param_t *param, pv_valu
717 626
 {
718 627
 	static char sb_s_buf[26];
719 628
 	str body;
720
-	body.s = get_body_part(msg, TYPE_APPLICATION,SUBTYPE_ISUP,&body.len);
721
-
722 629
 	memset(sb_s_buf, 0, 26);
723
-	if(body.s == NULL)
630
+	if(sipt_check_IAM(msg, &body) != 1)
724 631
 	{
725
-		LM_INFO("No ISUP Message Found");
726
-		return -1;
727
-	}
728
-
729
-	if((body.s[0] != ISUP_IAM))
730
-	{
731
-		LM_DBG("message not an IAM\n");
632
+		LM_INFO("could not check IAM\n");
732 633
 		return -1;
733 634
 	}
734 635