Browse code

kemix: added functions to get contact header uri

Daniel-Constantin Mierla authored on 24/11/2020 12:25:43
Showing 1 changed files
... ...
@@ -32,6 +32,8 @@
32 32
 #include "../../core/parser/parse_from.h"
33 33
 #include "../../core/parser/parse_to.h"
34 34
 #include "../../core/parser/digest/digest.h"
35
+#include "../../core/parser/contact/parse_contact.h"
36
+
35 37
 #include "../../core/tcp_conn.h"
36 38
 
37 39
 MODULE_VERSION
... ...
@@ -997,6 +999,61 @@ static int ki_kx_get_msgtype(sip_msg_t *msg)
997 999
 }
998 1000
 
999 1001
 
1002
+/**
1003
+ *
1004
+ */
1005
+static sr_kemi_xval_t* ki_kx_get_cturi_mode(sip_msg_t *msg, int xmode)
1006
+{
1007
+	contact_t *c;
1008
+
1009
+	memset(&_sr_kemi_kx_xval, 0, sizeof(sr_kemi_xval_t));
1010
+
1011
+	if((parse_contact_headers(msg) < 0) || (msg->contact == NULL)
1012
+			|| (msg->contact->parsed == NULL)) {
1013
+		sr_kemi_xval_null(&_sr_kemi_kx_xval, xmode);
1014
+		return &_sr_kemi_kx_xval;
1015
+	}
1016
+
1017
+	if (((contact_body_t*)msg->contact->parsed)->star == 1) {
1018
+		sr_kemi_xval_null(&_sr_kemi_kx_xval, xmode);
1019
+		return &_sr_kemi_kx_xval;
1020
+	}
1021
+
1022
+	c = (((contact_body_t*)msg->contact->parsed)->contacts);
1023
+	if(c==NULL || c->uri.s==NULL || c->uri.len<=0) {
1024
+		sr_kemi_xval_null(&_sr_kemi_kx_xval, xmode);
1025
+		return &_sr_kemi_kx_xval;
1026
+	}
1027
+
1028
+	_sr_kemi_kx_xval.vtype = SR_KEMIP_STR;
1029
+	_sr_kemi_kx_xval.v.s = c->uri;
1030
+	return &_sr_kemi_kx_xval;
1031
+}
1032
+
1033
+/**
1034
+ *
1035
+ */
1036
+static sr_kemi_xval_t* ki_kx_get_cturi(sip_msg_t *msg)
1037
+{
1038
+	return ki_kx_get_cturi_mode(msg, SR_KEMI_XVAL_NULL_NONE);
1039
+}
1040
+
1041
+/**
1042
+ *
1043
+ */
1044
+static sr_kemi_xval_t* ki_kx_getw_cturi(sip_msg_t *msg)
1045
+{
1046
+	return ki_kx_get_cturi_mode(msg, SR_KEMI_XVAL_NULL_PRINT);
1047
+}
1048
+
1049
+/**
1050
+ *
1051
+ */
1052
+static sr_kemi_xval_t* ki_kx_gete_cturi(sip_msg_t *msg)
1053
+{
1054
+	return ki_kx_get_cturi_mode(msg, SR_KEMI_XVAL_NULL_EMPTY);
1055
+}
1056
+
1000 1057
 /**
1001 1058
  *
1002 1059
  */
... ...
@@ -1127,6 +1184,21 @@ static sr_kemi_t sr_kemi_kx_exports[] = {
1127 1184
 		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
1128 1185
 			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
1129 1186
 	},
1187
+	{ str_init("kx"), str_init("get_cturi"),
1188
+		SR_KEMIP_XVAL, ki_kx_get_cturi,
1189
+		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
1190
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
1191
+	},
1192
+	{ str_init("kx"), str_init("gete_cturi"),
1193
+		SR_KEMIP_XVAL, ki_kx_gete_cturi,
1194
+		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
1195
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
1196
+	},
1197
+	{ str_init("kx"), str_init("getw_cturi"),
1198
+		SR_KEMIP_XVAL, ki_kx_getw_cturi,
1199
+		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
1200
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
1201
+	},
1130 1202
 	{ str_init("kx"), str_init("get_nhuri"),
1131 1203
 		SR_KEMIP_XVAL, ki_kx_get_nhuri,
1132 1204
 		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,