Browse code

core: parse to compare header names

Daniel-Constantin Mierla authored on 31/07/2021 10:03:32
Showing 1 changed files
... ...
@@ -25,6 +25,7 @@
25 25
 
26 26
 #include "parser/parse_uri.h"
27 27
 #include "parser/parse_param.h"
28
+#include "parser/parse_hname2.h"
28 29
 
29 30
 #include "dprint.h"
30 31
 #include "ut.h"
... ...
@@ -455,22 +456,61 @@ int cmpi_str(str *s1, str *s2)
455 456
 int cmp_hdrname_str(str *s1, str *s2)
456 457
 {
457 458
 	str n1, n2;
459
+	hdr_field_t hf1, hf2;
460
+
458 461
 	n1 = *s1;
459 462
 	n2 = *s2;
460 463
 	trim_trailing(&n1);
461 464
 	trim_trailing(&n2);
462
-	/* todo: parse hdr name and compare with short/long alternative */
465
+
466
+	parse_hname2_str(&n1, &hf1);
467
+	parse_hname2_str(&n2, &hf2);
468
+	if(hf1.type==HDR_ERROR_T || hf2.type==HDR_ERROR_T) {
469
+		LM_ERR("error parsing header names [%.*s] [%.*s]\n", n1.len, n1.s,
470
+				n2.len, n2.s);
471
+		return -4;
472
+	}
473
+
474
+	if(hf1.type!=HDR_OTHER_T) {
475
+		if(hf1.type==hf2.type) {
476
+			return 0;
477
+		} else {
478
+			return 2;
479
+		}
480
+	} else if(hf1.type!=HDR_OTHER_T) {
481
+		return 2;
482
+	}
463 483
 	return cmpi_str(&n1, &n2);
464 484
 }
465 485
 
466 486
 int cmp_hdrname_strzn(str *s1, char *s2, size_t len)
467 487
 {
468 488
 	str n1, n2;
489
+	hdr_field_t hf1, hf2;
490
+
469 491
 	n1 = *s1;
470 492
 	n2.s = s2;
471 493
 	n2.len = len;
472 494
 	trim_trailing(&n1);
473 495
 	trim_trailing(&n2);
496
+
497
+	parse_hname2_str(&n1, &hf1);
498
+	parse_hname2_str(&n2, &hf2);
499
+	if(hf1.type==HDR_ERROR_T || hf2.type==HDR_ERROR_T) {
500
+		LM_ERR("error parsing header names [%.*s] [%.*s]\n", n1.len, n1.s,
501
+				n2.len, n2.s);
502
+		return -4;
503
+	}
504
+
505
+	if(hf1.type!=HDR_OTHER_T) {
506
+		if(hf1.type==hf2.type) {
507
+			return 0;
508
+		} else {
509
+			return 2;
510
+		}
511
+	} else if(hf1.type!=HDR_OTHER_T) {
512
+		return 2;
513
+	}
474 514
 	return cmpi_str(&n1, &n2);
475 515
 }
476 516