Browse code

kemix: exported functions to return message body

Daniel-Constantin Mierla authored on 09/08/2019 13:02:13
Showing 1 changed files
... ...
@@ -617,6 +617,59 @@ static sr_kemi_xval_t* ki_kx_gets_status(sip_msg_t *msg)
617 617
 	return &_sr_kemi_kx_xval;
618 618
 }
619 619
 
620
+/**
621
+ *
622
+ */
623
+static sr_kemi_xval_t* ki_kx_get_body_mode(sip_msg_t *msg, int rmode)
624
+{
625
+	str s;
626
+	memset(&_sr_kemi_kx_xval, 0, sizeof(sr_kemi_xval_t));
627
+	if(msg==NULL) {
628
+		sr_kemi_xval_null(&_sr_kemi_kx_xval, rmode);
629
+		return &_sr_kemi_kx_xval;
630
+	}
631
+
632
+	s.s = get_body(msg);
633
+
634
+	if(s.s == NULL) {
635
+		sr_kemi_xval_null(&_sr_kemi_kx_xval, rmode);
636
+		return &_sr_kemi_kx_xval;
637
+	}
638
+	s.len = msg->buf + msg->len - s.s;
639
+	if(s.len <=0) {
640
+		sr_kemi_xval_null(&_sr_kemi_kx_xval, rmode);
641
+		return &_sr_kemi_kx_xval;
642
+	}
643
+
644
+	_sr_kemi_kx_xval.vtype = SR_KEMIP_STR;
645
+	_sr_kemi_kx_xval.v.s = s;
646
+	return &_sr_kemi_kx_xval;
647
+}
648
+
649
+/**
650
+ *
651
+ */
652
+static sr_kemi_xval_t* ki_kx_get_body(sip_msg_t *msg)
653
+{
654
+	return ki_kx_get_body_mode(msg, SR_KEMI_XVAL_NULL_NONE);
655
+}
656
+
657
+/**
658
+ *
659
+ */
660
+static sr_kemi_xval_t* ki_kx_gete_body(sip_msg_t *msg)
661
+{
662
+	return ki_kx_get_body_mode(msg, SR_KEMI_XVAL_NULL_EMPTY);
663
+}
664
+
665
+/**
666
+ *
667
+ */
668
+static sr_kemi_xval_t* ki_kx_getw_body(sip_msg_t *msg)
669
+{
670
+	return ki_kx_get_body_mode(msg, SR_KEMI_XVAL_NULL_PRINT);
671
+}
672
+
620 673
 /**
621 674
  *
622 675
  */
... ...
@@ -777,6 +830,22 @@ static sr_kemi_t sr_kemi_kx_exports[] = {
777 830
 		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
778 831
 			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
779 832
 	},
833
+	{ str_init("kx"), str_init("get_body"),
834
+		SR_KEMIP_XVAL, ki_kx_get_body,
835
+		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
836
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
837
+	},
838
+	{ str_init("kx"), str_init("getw_body"),
839
+		SR_KEMIP_XVAL, ki_kx_getw_body,
840
+		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
841
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
842
+	},
843
+	{ str_init("kx"), str_init("gete_body"),
844
+		SR_KEMIP_XVAL, ki_kx_gete_body,
845
+		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
846
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
847
+	},
848
+
780 849
 
781 850
 	{ {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } }
782 851
 };