Browse code

kemix: exported get_srcuri() to kemi

- return source address in uri format, similar to $su

Daniel-Constantin Mierla authored on 26/02/2021 13:54:04
Showing 1 changed files
... ...
@@ -27,6 +27,7 @@
27 27
 
28 28
 #include "../../core/sr_module.h"
29 29
 #include "../../core/dprint.h"
30
+#include "../../core/pvapi.h"
30 31
 #include "../../core/kemi.h"
31 32
 #include "../../core/ppcfg.h"
32 33
 #include "../../core/parser/parse_uri.h"
... ...
@@ -1066,6 +1067,39 @@ static sr_kemi_xval_t* ki_kx_gete_cturi(sip_msg_t *msg)
1066 1067
 	return ki_kx_get_cturi_mode(msg, SR_KEMI_XVAL_NULL_EMPTY);
1067 1068
 }
1068 1069
 
1070
+/**
1071
+ *
1072
+ */
1073
+static sr_kemi_xval_t* ki_kx_get_srcuri(sip_msg_t *msg)
1074
+{
1075
+	str ssock;
1076
+
1077
+	if(msg==NULL) {
1078
+		sr_kemi_xval_null(&_sr_kemi_kx_xval, SR_KEMI_XVAL_NULL_EMPTY);
1079
+		return &_sr_kemi_kx_xval;
1080
+
1081
+	}
1082
+
1083
+	if(get_src_uri(msg, 0, &ssock)<0) {
1084
+		sr_kemi_xval_null(&_sr_kemi_kx_xval, SR_KEMI_XVAL_NULL_EMPTY);
1085
+		return &_sr_kemi_kx_xval;
1086
+	}
1087
+
1088
+	if (ssock.len + 1 >= pv_get_buffer_size()) {
1089
+		LM_ERR("local buffer size exceeded\n");
1090
+		sr_kemi_xval_null(&_sr_kemi_kx_xval, SR_KEMI_XVAL_NULL_EMPTY);
1091
+		return &_sr_kemi_kx_xval;
1092
+	}
1093
+
1094
+	_sr_kemi_kx_xval.v.s.s = pv_get_buffer();
1095
+	strncpy(_sr_kemi_kx_xval.v.s.s, ssock.s, ssock.len);
1096
+	_sr_kemi_kx_xval.v.s.len = ssock.len;
1097
+	_sr_kemi_kx_xval.v.s.s[_sr_kemi_kx_xval.v.s.len] = '\0';
1098
+
1099
+	_sr_kemi_kx_xval.vtype = SR_KEMIP_STR;
1100
+	return &_sr_kemi_kx_xval;
1101
+}
1102
+
1069 1103
 /**
1070 1104
  *
1071 1105
  */
... ...
@@ -1301,6 +1335,11 @@ static sr_kemi_t sr_kemi_kx_exports[] = {
1301 1335
 		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
1302 1336
 			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
1303 1337
 	},
1338
+	{ str_init("kx"), str_init("get_srcuri"),
1339
+		SR_KEMIP_XVAL, ki_kx_get_srcuri,
1340
+		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
1341
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
1342
+	},
1304 1343
 	{ str_init("kx"), str_init("get_ua"),
1305 1344
 		SR_KEMIP_XVAL, ki_kx_get_ua,
1306 1345
 		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
Browse code

kemix: exported KSR.kx.get_send_sock_port()

- return send socket port if set, 0 otherwise

Daniel-Constantin Mierla authored on 05/01/2021 15:57:13
Showing 1 changed files
... ...
@@ -522,6 +522,17 @@ static sr_kemi_xval_t* ki_kx_get_send_sock_name(sip_msg_t *msg)
522 522
 	return &_sr_kemi_kx_xval;
523 523
 }
524 524
 
525
+/**
526
+ *
527
+ */
528
+static int ki_kx_get_send_sock_port(sip_msg_t *msg)
529
+{
530
+	if (msg==NULL || msg->force_send_socket==0) {
531
+		return 0;
532
+	}
533
+	return (int)msg->force_send_socket->port_no;
534
+}
535
+
525 536
 /**
526 537
  *
527 538
  */
... ...
@@ -1325,6 +1336,11 @@ static sr_kemi_t sr_kemi_kx_exports[] = {
1325 1336
 		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
1326 1337
 			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
1327 1338
 	},
1339
+	{ str_init("kx"), str_init("get_send_sock_port"),
1340
+		SR_KEMIP_INT, ki_kx_get_send_sock_port,
1341
+		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
1342
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
1343
+	},
1328 1344
 	{ str_init("kx"), str_init("get_rcvip"),
1329 1345
 		SR_KEMIP_XVAL, ki_kx_get_rcvip,
1330 1346
 		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
Browse code

kemix: exported functions to get env values

Daniel-Constantin Mierla authored on 04/01/2021 09:35:42
Showing 1 changed files
... ...
@@ -1093,6 +1093,52 @@ static int ki_kx_get_defn(sip_msg_t *msg, str *dname)
1093 1093
 	return n;
1094 1094
 }
1095 1095
 
1096
+/**
1097
+ *
1098
+ */
1099
+static sr_kemi_xval_t* ki_kx_get_env(sip_msg_t *msg, str *envname)
1100
+{
1101
+	char *val;
1102
+
1103
+	memset(&_sr_kemi_kx_xval, 0, sizeof(sr_kemi_xval_t));
1104
+	if(envname==NULL || envname->s==NULL || envname->len<=0) {
1105
+		sr_kemi_xval_null(&_sr_kemi_kx_xval, SR_KEMI_XVAL_NULL_EMPTY);
1106
+		return &_sr_kemi_kx_xval;
1107
+	}
1108
+
1109
+	val = getenv(envname->s);
1110
+	if (val == NULL) {
1111
+		sr_kemi_xval_null(&_sr_kemi_kx_xval, SR_KEMI_XVAL_NULL_EMPTY);
1112
+		return &_sr_kemi_kx_xval;
1113
+	}
1114
+
1115
+	_sr_kemi_kx_xval.vtype = SR_KEMIP_STR;
1116
+	_sr_kemi_kx_xval.v.s.s = val;
1117
+	_sr_kemi_kx_xval.v.s.len = strlen(val);
1118
+	return &_sr_kemi_kx_xval;
1119
+}
1120
+
1121
+/**
1122
+ *
1123
+ */
1124
+static int ki_kx_get_envn(sip_msg_t *msg, str *envname)
1125
+{
1126
+	str val;
1127
+	int r = 0;
1128
+
1129
+	if(envname==NULL || envname->s==NULL || envname->len<=0) {
1130
+		return 0;
1131
+	}
1132
+
1133
+	val.s = getenv(envname->s);
1134
+	if (val.s) {
1135
+		val.len = strlen(val.s);
1136
+		str2sint(&val, &r);
1137
+		return r;
1138
+	}
1139
+
1140
+	return r;
1141
+}
1096 1142
 
1097 1143
 /**
1098 1144
  *
... ...
@@ -1404,6 +1450,16 @@ static sr_kemi_t sr_kemi_kx_exports[] = {
1404 1450
 		{ SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
1405 1451
 			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
1406 1452
 	},
1453
+	{ str_init("kx"), str_init("get_env"),
1454
+		SR_KEMIP_XVAL, ki_kx_get_env,
1455
+		{ SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
1456
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
1457
+	},
1458
+	{ str_init("kx"), str_init("get_envn"),
1459
+		SR_KEMIP_INT, ki_kx_get_envn,
1460
+		{ SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
1461
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
1462
+	},
1407 1463
 
1408 1464
 
1409 1465
 	{ {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } }
Browse code

kemix: exported functions to get define values

Daniel-Constantin Mierla authored on 15/12/2020 08:28:26
Showing 1 changed files
... ...
@@ -28,6 +28,7 @@
28 28
 #include "../../core/sr_module.h"
29 29
 #include "../../core/dprint.h"
30 30
 #include "../../core/kemi.h"
31
+#include "../../core/ppcfg.h"
31 32
 #include "../../core/parser/parse_uri.h"
32 33
 #include "../../core/parser/parse_from.h"
33 34
 #include "../../core/parser/parse_to.h"
... ...
@@ -1054,6 +1055,45 @@ static sr_kemi_xval_t* ki_kx_gete_cturi(sip_msg_t *msg)
1054 1055
 	return ki_kx_get_cturi_mode(msg, SR_KEMI_XVAL_NULL_EMPTY);
1055 1056
 }
1056 1057
 
1058
+/**
1059
+ *
1060
+ */
1061
+static sr_kemi_xval_t* ki_kx_get_def(sip_msg_t *msg, str *dname)
1062
+{
1063
+	str *val;
1064
+
1065
+	val = pp_define_get(dname->len, dname->s);
1066
+
1067
+	memset(&_sr_kemi_kx_xval, 0, sizeof(sr_kemi_xval_t));
1068
+	if (val==NULL) {
1069
+		sr_kemi_xval_null(&_sr_kemi_kx_xval, SR_KEMI_XVAL_NULL_EMPTY);
1070
+		return &_sr_kemi_kx_xval;
1071
+	}
1072
+
1073
+	_sr_kemi_kx_xval.vtype = SR_KEMIP_STR;
1074
+	_sr_kemi_kx_xval.v.s.s = val->s;
1075
+	_sr_kemi_kx_xval.v.s.len = val->len;
1076
+	return &_sr_kemi_kx_xval;
1077
+}
1078
+
1079
+/**
1080
+ *
1081
+ */
1082
+static int ki_kx_get_defn(sip_msg_t *msg, str *dname)
1083
+{
1084
+	str *val;
1085
+	int n = 0;
1086
+
1087
+	val = pp_define_get(dname->len, dname->s);
1088
+
1089
+	if (val != NULL) {
1090
+		str2sint(val, &n);
1091
+	}
1092
+
1093
+	return n;
1094
+}
1095
+
1096
+
1057 1097
 /**
1058 1098
  *
1059 1099
  */
... ...
@@ -1354,6 +1394,16 @@ static sr_kemi_t sr_kemi_kx_exports[] = {
1354 1394
 		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
1355 1395
 			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
1356 1396
 	},
1397
+	{ str_init("kx"), str_init("get_def"),
1398
+		SR_KEMIP_XVAL, ki_kx_get_def,
1399
+		{ SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
1400
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
1401
+	},
1402
+	{ str_init("kx"), str_init("get_defn"),
1403
+		SR_KEMIP_INT, ki_kx_get_defn,
1404
+		{ SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
1405
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
1406
+	},
1357 1407
 
1358 1408
 
1359 1409
 	{ {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } }
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,
Browse code

kemix: exported functions to get socket string and name

Daniel-Constantin Mierla authored on 23/11/2020 07:15:34
Showing 1 changed files
... ...
@@ -486,6 +486,39 @@ static sr_kemi_xval_t* ki_kx_get_srcport(sip_msg_t *msg)
486 486
 	return &_sr_kemi_kx_xval;
487 487
 }
488 488
 
489
+/**
490
+ *
491
+ */
492
+static sr_kemi_xval_t* ki_kx_get_send_sock(sip_msg_t *msg)
493
+{
494
+	memset(&_sr_kemi_kx_xval, 0, sizeof(sr_kemi_xval_t));
495
+	if (msg==NULL || msg->force_send_socket==0) {
496
+		sr_kemi_xval_null(&_sr_kemi_kx_xval, SR_KEMI_XVAL_NULL_NONE);
497
+		return &_sr_kemi_kx_xval;
498
+	}
499
+
500
+	_sr_kemi_kx_xval.vtype = SR_KEMIP_STR;
501
+	_sr_kemi_kx_xval.v.s = msg->force_send_socket->sock_str;
502
+	return &_sr_kemi_kx_xval;
503
+}
504
+
505
+/**
506
+ *
507
+ */
508
+static sr_kemi_xval_t* ki_kx_get_send_sock_name(sip_msg_t *msg)
509
+{
510
+	memset(&_sr_kemi_kx_xval, 0, sizeof(sr_kemi_xval_t));
511
+	if (msg==NULL || msg->force_send_socket==0
512
+			|| msg->force_send_socket->sockname.s==0) {
513
+		sr_kemi_xval_null(&_sr_kemi_kx_xval, SR_KEMI_XVAL_NULL_NONE);
514
+		return &_sr_kemi_kx_xval;
515
+	}
516
+
517
+	_sr_kemi_kx_xval.vtype = SR_KEMIP_STR;
518
+	_sr_kemi_kx_xval.v.s = msg->force_send_socket->sockname;
519
+	return &_sr_kemi_kx_xval;
520
+}
521
+
489 522
 /**
490 523
  *
491 524
  */
... ...
@@ -520,6 +553,23 @@ static sr_kemi_xval_t* ki_kx_get_rcvport(sip_msg_t *msg)
520 553
 	return &_sr_kemi_kx_xval;
521 554
 }
522 555
 
556
+/**
557
+ *
558
+ */
559
+static sr_kemi_xval_t* ki_kx_get_rcv_sock_name(sip_msg_t *msg)
560
+{
561
+	memset(&_sr_kemi_kx_xval, 0, sizeof(sr_kemi_xval_t));
562
+	if(msg==NULL || msg->rcv.bind_address==NULL
563
+			|| msg->rcv.bind_address->sockname.s==NULL) {
564
+		sr_kemi_xval_null(&_sr_kemi_kx_xval, SR_KEMI_XVAL_NULL_NONE);
565
+		return &_sr_kemi_kx_xval;
566
+	}
567
+
568
+	_sr_kemi_kx_xval.vtype = SR_KEMIP_STR;
569
+	_sr_kemi_kx_xval.v.s = msg->rcv.bind_address->sockname;
570
+	return &_sr_kemi_kx_xval;
571
+}
572
+
523 573
 /**
524 574
  *
525 575
  */
... ...
@@ -1107,11 +1157,26 @@ static sr_kemi_t sr_kemi_kx_exports[] = {
1107 1157
 		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
1108 1158
 			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
1109 1159
 	},
1160
+	{ str_init("kx"), str_init("get_send_sock"),
1161
+		SR_KEMIP_XVAL, ki_kx_get_send_sock,
1162
+		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
1163
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
1164
+	},
1165
+	{ str_init("kx"), str_init("get_send_sock_name"),
1166
+		SR_KEMIP_XVAL, ki_kx_get_send_sock_name,
1167
+		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
1168
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
1169
+	},
1110 1170
 	{ str_init("kx"), str_init("get_rcvip"),
1111 1171
 		SR_KEMIP_XVAL, ki_kx_get_rcvip,
1112 1172
 		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
1113 1173
 			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
1114 1174
 	},
1175
+	{ str_init("kx"), str_init("get_rcv_sock_name"),
1176
+		SR_KEMIP_XVAL, ki_kx_get_rcv_sock_name,
1177
+		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
1178
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
1179
+	},
1115 1180
 	{ str_init("kx"), str_init("get_rcvport"),
1116 1181
 		SR_KEMIP_XVAL, ki_kx_get_rcvport,
1117 1182
 		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
Browse code

kemix: exported function get_rcvadvip() and get_rcvadvport()

- return advertised address and port of the receiving socket

Daniel-Constantin Mierla authored on 20/11/2020 07:12:18
Showing 1 changed files
... ...
@@ -520,6 +520,38 @@ static sr_kemi_xval_t* ki_kx_get_rcvport(sip_msg_t *msg)
520 520
 	return &_sr_kemi_kx_xval;
521 521
 }
522 522
 
523
+/**
524
+ *
525
+ */
526
+static sr_kemi_xval_t* ki_kx_get_rcvadvip(sip_msg_t *msg)
527
+{
528
+	memset(&_sr_kemi_kx_xval, 0, sizeof(sr_kemi_xval_t));
529
+	if(msg->rcv.bind_address!=NULL
530
+			&& msg->rcv.bind_address->useinfo.address_str.len > 0) {
531
+		_sr_kemi_kx_xval.vtype = SR_KEMIP_STR;
532
+		_sr_kemi_kx_xval.v.s = msg->rcv.bind_address->useinfo.address_str;
533
+		return &_sr_kemi_kx_xval;
534
+	}
535
+
536
+	return ki_kx_get_rcvip(msg);
537
+}
538
+
539
+/**
540
+ *
541
+ */
542
+static sr_kemi_xval_t* ki_kx_get_rcvadvport(sip_msg_t *msg)
543
+{
544
+	memset(&_sr_kemi_kx_xval, 0, sizeof(sr_kemi_xval_t));
545
+	if(msg->rcv.bind_address!=NULL
546
+			&& msg->rcv.bind_address->useinfo.port_no_str.len > 0) {
547
+		_sr_kemi_kx_xval.vtype = SR_KEMIP_INT;
548
+		_sr_kemi_kx_xval.v.n = (int)msg->rcv.bind_address->useinfo.port_no;
549
+		return &_sr_kemi_kx_xval;
550
+	}
551
+
552
+	return ki_kx_get_rcvport(msg);
553
+}
554
+
523 555
 /**
524 556
  *
525 557
  */
... ...
@@ -1085,6 +1117,16 @@ static sr_kemi_t sr_kemi_kx_exports[] = {
1085 1117
 		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
1086 1118
 			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
1087 1119
 	},
1120
+	{ str_init("kx"), str_init("get_rcvadvip"),
1121
+		SR_KEMIP_XVAL, ki_kx_get_rcvadvip,
1122
+		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
1123
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
1124
+	},
1125
+	{ str_init("kx"), str_init("get_rcvadvport"),
1126
+		SR_KEMIP_XVAL, ki_kx_get_rcvadvport,
1127
+		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
1128
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
1129
+	},
1088 1130
 	{ str_init("kx"), str_init("get_proto"),
1089 1131
 		SR_KEMIP_XVAL, ki_kx_get_proto,
1090 1132
 		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
Browse code

kemix: function to get the body length

Daniel-Constantin Mierla authored on 08/06/2020 18:44:24
Showing 1 changed files
... ...
@@ -739,6 +739,30 @@ static sr_kemi_xval_t* ki_kx_getw_body(sip_msg_t *msg)
739 739
 	return ki_kx_get_body_mode(msg, SR_KEMI_XVAL_NULL_PRINT);
740 740
 }
741 741
 
742
+/**
743
+ *
744
+ */
745
+static int ki_kx_get_bodylen(sip_msg_t *msg)
746
+{
747
+	str s;
748
+	memset(&_sr_kemi_kx_xval, 0, sizeof(sr_kemi_xval_t));
749
+	if(msg==NULL) {
750
+		return 0;
751
+	}
752
+
753
+	s.s = get_body(msg);
754
+
755
+	if(s.s == NULL) {
756
+		return 0;
757
+	}
758
+	s.len = msg->buf + msg->len - s.s;
759
+	if(s.len <=0) {
760
+		return 0;
761
+	}
762
+
763
+	return s.len;
764
+}
765
+
742 766
 /**
743 767
  *
744 768
  */
... ...
@@ -1116,6 +1140,11 @@ static sr_kemi_t sr_kemi_kx_exports[] = {
1116 1140
 		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
1117 1141
 			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
1118 1142
 	},
1143
+	{ str_init("kx"), str_init("get_bodylen"),
1144
+		SR_KEMIP_INT, ki_kx_get_bodylen,
1145
+		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
1146
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
1147
+	},
1119 1148
 	{ str_init("kx"), str_init("get_timestamp"),
1120 1149
 		SR_KEMIP_INT, ki_kx_get_timestamp,
1121 1150
 		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
Browse code

kemi: exported function to get msg type

Daniel-Constantin Mierla authored on 30/05/2020 07:11:06
Showing 1 changed files
... ...
@@ -872,6 +872,25 @@ static int ki_kx_get_msglen(sip_msg_t *msg)
872 872
 	return msg->len;
873 873
 }
874 874
 
875
+/**
876
+ *
877
+ */
878
+static int ki_kx_get_msgtype(sip_msg_t *msg)
879
+{
880
+	if(msg==NULL) {
881
+		return -1;
882
+	}
883
+
884
+	if(msg->first_line.type == SIP_REQUEST) {
885
+		return 1;
886
+	} else if(msg->first_line.type == SIP_REPLY) {
887
+		return 2;
888
+	}
889
+
890
+	return 0;
891
+}
892
+
893
+
875 894
 /**
876 895
  *
877 896
  */
... ...
@@ -1122,6 +1141,11 @@ static sr_kemi_t sr_kemi_kx_exports[] = {
1122 1141
 		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
1123 1142
 			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
1124 1143
 	},
1144
+	{ str_init("kx"), str_init("get_msgtype"),
1145
+		SR_KEMIP_INT, ki_kx_get_msgtype,
1146
+		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
1147
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
1148
+	},
1125 1149
 
1126 1150
 
1127 1151
 	{ {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } }
Browse code

kemix: functions to get msg buffer and length

Daniel-Constantin Mierla authored on 29/05/2020 08:40:19
Showing 1 changed files
... ...
@@ -843,6 +843,35 @@ static int ki_kx_get_conid(sip_msg_t *msg)
843 843
 	return conid;
844 844
 }
845 845
 
846
+/**
847
+ *
848
+ */
849
+static sr_kemi_xval_t* ki_kx_get_msgbuf(sip_msg_t *msg)
850
+{
851
+	memset(&_sr_kemi_kx_xval, 0, sizeof(sr_kemi_xval_t));
852
+	if(msg==NULL) {
853
+		sr_kemi_xval_null(&_sr_kemi_kx_xval, SR_KEMI_XVAL_NULL_EMPTY);
854
+		return &_sr_kemi_kx_xval;
855
+	}
856
+
857
+	_sr_kemi_kx_xval.vtype = SR_KEMIP_STR;
858
+	_sr_kemi_kx_xval.v.s.s = msg->buf;
859
+	_sr_kemi_kx_xval.v.s.len = msg->len;
860
+	return &_sr_kemi_kx_xval;
861
+}
862
+
863
+/**
864
+ *
865
+ */
866
+static int ki_kx_get_msglen(sip_msg_t *msg)
867
+{
868
+	if(msg==NULL) {
869
+		return -1;
870
+	}
871
+
872
+	return msg->len;
873
+}
874
+
846 875
 /**
847 876
  *
848 877
  */
... ...
@@ -1083,6 +1112,17 @@ static sr_kemi_t sr_kemi_kx_exports[] = {
1083 1112
 		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
1084 1113
 			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
1085 1114
 	},
1115
+	{ str_init("kx"), str_init("get_msgbuf"),
1116
+		SR_KEMIP_XVAL, ki_kx_get_msgbuf,
1117
+		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
1118
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
1119
+	},
1120
+	{ str_init("kx"), str_init("get_msglen"),
1121
+		SR_KEMIP_INT, ki_kx_get_msglen,
1122
+		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
1123
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
1124
+	},
1125
+
1086 1126
 
1087 1127
 	{ {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } }
1088 1128
 };
Browse code

kemix: exported get_conid() function to retrieve tcp connection id

- returns -1 if not available

Daniel-Constantin Mierla authored on 24/02/2020 08:30:31
Showing 1 changed files
... ...
@@ -32,6 +32,7 @@
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/tcp_conn.h"
35 36
 
36 37
 MODULE_VERSION
37 38
 
... ...
@@ -822,6 +823,25 @@ static sr_kemi_xval_t* ki_kx_get_callid(sip_msg_t *msg)
822 823
 	return &_sr_kemi_kx_xval;
823 824
 }
824 825
 
826
+/**
827
+ *
828
+ */
829
+static int ki_kx_get_conid(sip_msg_t *msg)
830
+{
831
+	tcp_connection_t *con;
832
+	int conid;
833
+
834
+	if (msg == NULL)
835
+		return -1;
836
+
837
+	if ((con = tcpconn_get(msg->rcv.proto_reserved1, 0, 0, 0, 0)) == NULL)
838
+		return -1;
839
+
840
+	conid = con->id;
841
+	tcpconn_put(con);
842
+
843
+	return conid;
844
+}
825 845
 
826 846
 /**
827 847
  *
... ...
@@ -1058,6 +1078,11 @@ static sr_kemi_t sr_kemi_kx_exports[] = {
1058 1078
 		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
1059 1079
 			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
1060 1080
 	},
1081
+	{ str_init("kx"), str_init("get_conid"),
1082
+		SR_KEMIP_INT, ki_kx_get_conid,
1083
+		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
1084
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
1085
+	},
1061 1086
 
1062 1087
 	{ {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } }
1063 1088
 };
Browse code

kemix: exported function to get next hop uri

Daniel-Constantin Mierla authored on 17/02/2020 15:37:55
Showing 1 changed files
... ...
@@ -778,6 +778,21 @@ static sr_kemi_xval_t* ki_kx_gete_duri(sip_msg_t *msg)
778 778
 	return ki_kx_get_duri_mode(msg, SR_KEMI_XVAL_NULL_EMPTY);
779 779
 }
780 780
 
781
+/**
782
+ *
783
+ */
784
+static sr_kemi_xval_t* ki_kx_get_nhuri(sip_msg_t *msg)
785
+{
786
+	memset(&_sr_kemi_kx_xval, 0, sizeof(sr_kemi_xval_t));
787
+	if(msg->dst_uri.s==NULL || msg->dst_uri.len<=0) {
788
+		return ki_kx_get_ruri(msg);
789
+	}
790
+
791
+	_sr_kemi_kx_xval.vtype = SR_KEMIP_STR;
792
+	_sr_kemi_kx_xval.v.s = msg->dst_uri;
793
+	return &_sr_kemi_kx_xval;
794
+}
795
+
781 796
 /**
782 797
  *
783 798
  */
... ...
@@ -938,7 +953,11 @@ static sr_kemi_t sr_kemi_kx_exports[] = {
938 953
 		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
939 954
 			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
940 955
 	},
941
-
956
+	{ str_init("kx"), str_init("get_nhuri"),
957
+		SR_KEMIP_XVAL, ki_kx_get_nhuri,
958
+		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
959
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
960
+	},
942 961
 	{ str_init("kx"), str_init("get_ua"),
943 962
 		SR_KEMIP_XVAL, ki_kx_get_ua,
944 963
 		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
Browse code

kemix: exported functions to get to-uri user and host

Daniel-Constantin Mierla authored on 06/02/2020 19:49:36
Showing 1 changed files
... ...
@@ -341,6 +341,71 @@ static sr_kemi_xval_t* ki_kx_gete_fhost(sip_msg_t *msg)
341 341
 	return ki_kx_get_furi_attr(msg, 2, SR_KEMI_XVAL_NULL_EMPTY);
342 342
 }
343 343
 
344
+/**
345
+ *
346
+ */
347
+static sr_kemi_xval_t* ki_kx_get_turi_attr(sip_msg_t *msg, int iattr, int xmode)
348
+{
349
+	sip_uri_t *uri;
350
+
351
+	memset(&_sr_kemi_kx_xval, 0, sizeof(sr_kemi_xval_t));
352
+	uri=parse_to_uri(msg);
353
+	if(uri==NULL) {
354
+		sr_kemi_xval_null(&_sr_kemi_kx_xval, xmode);
355
+		return &_sr_kemi_kx_xval;
356
+	}
357
+
358
+	return ki_kx_get_xuri_attr(msg, uri, iattr, xmode);
359
+}
360
+
361
+/**
362
+ *
363
+ */
364
+static sr_kemi_xval_t* ki_kx_get_tuser(sip_msg_t *msg)
365
+{
366
+	return ki_kx_get_turi_attr(msg, 1, SR_KEMI_XVAL_NULL_NONE);
367
+}
368
+
369
+/**
370
+ *
371
+ */
372
+static sr_kemi_xval_t* ki_kx_getw_tuser(sip_msg_t *msg)
373
+{
374
+	return ki_kx_get_turi_attr(msg, 1, SR_KEMI_XVAL_NULL_PRINT);
375
+}
376
+
377
+/**
378
+ *
379
+ */
380
+static sr_kemi_xval_t* ki_kx_gete_tuser(sip_msg_t *msg)
381
+{
382
+	return ki_kx_get_turi_attr(msg, 1, SR_KEMI_XVAL_NULL_EMPTY);
383
+}
384
+
385
+/**
386
+ *
387
+ */
388
+static sr_kemi_xval_t* ki_kx_get_thost(sip_msg_t *msg)
389
+{
390
+	return ki_kx_get_turi_attr(msg, 2, SR_KEMI_XVAL_NULL_NONE);
391
+}
392
+
393
+/**
394
+ *
395
+ */
396
+static sr_kemi_xval_t* ki_kx_getw_thost(sip_msg_t *msg)
397
+{
398
+	return ki_kx_get_turi_attr(msg, 2, SR_KEMI_XVAL_NULL_PRINT);
399
+}
400
+
401
+/**
402
+ *
403
+ */
404
+static sr_kemi_xval_t* ki_kx_gete_thost(sip_msg_t *msg)
405
+{
406
+	return ki_kx_get_turi_attr(msg, 2, SR_KEMI_XVAL_NULL_EMPTY);
407
+}
408
+
344 409
 /**
345 410
  *
346 411
  */
... ...
@@ -828,6 +893,36 @@ static sr_kemi_t sr_kemi_kx_exports[] = {
828 893
 		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
829 894
 			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
830 895
 	},
896
+	{ str_init("kx"), str_init("get_tuser"),
897
+		SR_KEMIP_XVAL, ki_kx_get_tuser,
898
+		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
899
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
900
+	},
901
+	{ str_init("kx"), str_init("gete_tuser"),
902
+		SR_KEMIP_XVAL, ki_kx_gete_tuser,
903
+		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
904
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
905
+	},
906
+	{ str_init("kx"), str_init("getw_tuser"),
907
+		SR_KEMIP_XVAL, ki_kx_getw_tuser,
908
+		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
909
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
910
+	},
911
+	{ str_init("kx"), str_init("get_thost"),
912
+		SR_KEMIP_XVAL, ki_kx_get_thost,
913
+		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
914
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
915
+	},
916
+	{ str_init("kx"), str_init("gete_thost"),
917
+		SR_KEMIP_XVAL, ki_kx_gete_thost,
918
+		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
919
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
920
+	},
921
+	{ str_init("kx"), str_init("getw_thost"),
922
+		SR_KEMIP_XVAL, ki_kx_getw_thost,
923
+		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
924
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
925
+	},
831 926
 	{ str_init("kx"), str_init("get_duri"),
832 927
 		SR_KEMIP_XVAL, ki_kx_get_duri,
833 928
 		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
Browse code

kemix: exported function to get call-id

Daniel-Constantin Mierla authored on 05/02/2020 08:38:43
Showing 1 changed files
... ...
@@ -35,6 +35,7 @@
35 35
 
36 36
 MODULE_VERSION
37 37
 
38
+/* clang-format off */
38 39
 struct module_exports exports = {
39 40
 	"kemix",         /* module name */
40 41
 	DEFAULT_DLFLAGS, /* dlopen flags */
... ...
@@ -47,6 +48,7 @@ struct module_exports exports = {
47 48
 	0,               /* per-child init function */
48 49
 	0                /* module destroy function */
49 50
 };
51
+/* clang-format on */
50 52
 
51 53
 
52 54
 /**
... ...
@@ -719,6 +721,28 @@ static int ki_kx_get_timestamp(sip_msg_t *msg)
719 721
 	return (int)time(NULL);
720 722
 }
721 723
 
724
+/**
725
+ *
726
+ */
727
+static sr_kemi_xval_t* ki_kx_get_callid(sip_msg_t *msg)
728
+{
729
+	memset(&_sr_kemi_kx_xval, 0, sizeof(sr_kemi_xval_t));
730
+	if(msg==NULL) {
731
+		sr_kemi_xval_null(&_sr_kemi_kx_xval, SR_KEMI_XVAL_NULL_EMPTY);
732
+		return &_sr_kemi_kx_xval;
733
+	}
734
+	if(msg->callid==NULL && ((parse_headers(msg, HDR_CALLID_F, 0)==-1)
735
+			|| (msg->callid==NULL))) {
736
+		sr_kemi_xval_null(&_sr_kemi_kx_xval, SR_KEMI_XVAL_NULL_EMPTY);
737
+		return &_sr_kemi_kx_xval;
738
+	}
739
+
740
+	_sr_kemi_kx_xval.vtype = SR_KEMIP_STR;
741
+	_sr_kemi_kx_xval.v.s = msg->callid->body;
742
+	return &_sr_kemi_kx_xval;
743
+}
744
+
745
+
722 746
 /**
723 747
  *
724 748
  */
... ...
@@ -915,6 +939,11 @@ static sr_kemi_t sr_kemi_kx_exports[] = {
915 939
 		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
916 940
 			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
917 941
 	},
942
+	{ str_init("kx"), str_init("get_callid"),
943
+		SR_KEMIP_XVAL, ki_kx_get_callid,
944
+		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
945
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
946
+	},
918 947
 
919 948
 	{ {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } }
920 949
 };
Browse code

kemix: exported function to get timestamp

Daniel-Constantin Mierla authored on 30/01/2020 11:01:49
Showing 1 changed files
... ...
@@ -23,6 +23,7 @@
23 23
 #include <unistd.h>
24 24
 #include <stdlib.h>
25 25
 #include <string.h>
26
+#include <time.h>
26 27
 
27 28
 #include "../../core/sr_module.h"
28 29
 #include "../../core/dprint.h"
... ...
@@ -710,6 +711,14 @@ static sr_kemi_xval_t* ki_kx_gete_duri(sip_msg_t *msg)
710 711
 	return ki_kx_get_duri_mode(msg, SR_KEMI_XVAL_NULL_EMPTY);
711 712
 }
712 713
 
714
+/**
715
+ *
716
+ */
717
+static int ki_kx_get_timestamp(sip_msg_t *msg)
718
+{
719
+	return (int)time(NULL);
720
+}
721
+
713 722
 /**
714 723
  *
715 724
  */
... ...
@@ -901,7 +910,11 @@ static sr_kemi_t sr_kemi_kx_exports[] = {
901 910
 		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
902 911
 			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
903 912
 	},
904
-
913
+	{ str_init("kx"), str_init("get_timestamp"),
914
+		SR_KEMIP_INT, ki_kx_get_timestamp,
915
+		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
916
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
917
+	},
905 918
 
906 919
 	{ {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } }
907 920
 };
Browse code

kemix: exported functions to get dst-uri variants

Daniel-Constantin Mierla authored on 28/01/2020 13:35:13
Showing 1 changed files
... ...
@@ -670,6 +670,46 @@ static sr_kemi_xval_t* ki_kx_getw_body(sip_msg_t *msg)
670 670
 	return ki_kx_get_body_mode(msg, SR_KEMI_XVAL_NULL_PRINT);
671 671
 }
672 672
 
673
+/**
674
+ *
675
+ */
676
+static sr_kemi_xval_t* ki_kx_get_duri_mode(sip_msg_t *msg, int xmode)
677
+{
678
+	memset(&_sr_kemi_kx_xval, 0, sizeof(sr_kemi_xval_t));
679
+	if(msg->dst_uri.s==NULL || msg->dst_uri.len<=0) {
680
+		sr_kemi_xval_null(&_sr_kemi_kx_xval, xmode);
681
+		return &_sr_kemi_kx_xval;