Browse code

kemix: exported functions to get common URI values via KSR.kx

Daniel-Constantin Mierla authored on 27/05/2019 09:56:52
Showing 1 changed files
... ...
@@ -28,6 +28,8 @@
28 28
 #include "../../core/dprint.h"
29 29
 #include "../../core/kemi.h"
30 30
 #include "../../core/parser/parse_uri.h"
31
+#include "../../core/parser/parse_from.h"
32
+#include "../../core/parser/parse_to.h"
31 33
 
32 34
 MODULE_VERSION
33 35
 
... ...
@@ -83,6 +85,95 @@ static sr_kemi_xval_t* ki_kx_get_ruri(sip_msg_t *msg)
83 85
 	return &_sr_kemi_kx_xval;
84 86
 }
85 87
 
88
+/**
89
+ *
90
+ */
91
+static sr_kemi_xval_t* ki_kx_get_ouri(sip_msg_t *msg)
92
+{
93
+	memset(&_sr_kemi_kx_xval, 0, sizeof(sr_kemi_xval_t));
94
+
95
+	if(msg==NULL) {
96
+		sr_kemi_xval_null(&_sr_kemi_kx_xval, 0);
97
+		return &_sr_kemi_kx_xval;
98
+	}
99
+
100
+	if(msg->first_line.type == SIP_REPLY) {
101
+		/* REPLY doesnt have a ruri */
102
+		sr_kemi_xval_null(&_sr_kemi_kx_xval, 0);
103
+		return &_sr_kemi_kx_xval;
104
+	}
105
+
106
+	if(msg->parsed_uri_ok==0 /* R-URI not parsed*/ && parse_sip_msg_uri(msg)<0) {
107
+		LM_ERR("failed to parse the R-URI\n");
108
+		sr_kemi_xval_null(&_sr_kemi_kx_xval, 0);
109
+		return &_sr_kemi_kx_xval;
110
+	}
111
+
112
+	_sr_kemi_kx_xval.vtype = SR_KEMIP_STR;
113
+	_sr_kemi_kx_xval.v.s = msg->first_line.u.request.uri;
114
+	return &_sr_kemi_kx_xval;
115
+}
116
+
117
+/**
118
+ *
119
+ */
120
+static sr_kemi_xval_t* ki_kx_get_furi(sip_msg_t *msg)
121
+{
122
+	to_body_t *xto = NULL;
123
+
124
+	memset(&_sr_kemi_kx_xval, 0, sizeof(sr_kemi_xval_t));
125
+
126
+	if(msg==NULL) {
127
+		sr_kemi_xval_null(&_sr_kemi_kx_xval, 0);
128
+		return &_sr_kemi_kx_xval;
129
+	}
130
+	if(parse_from_header(msg)<0) {
131
+		LM_ERR("cannot parse From header\n");
132
+		sr_kemi_xval_null(&_sr_kemi_kx_xval, 0);
133
+		return &_sr_kemi_kx_xval;
134
+	}
135
+	if(msg->from==NULL || get_from(msg)==NULL) {
136
+		LM_DBG("no From header\n");
137
+		sr_kemi_xval_null(&_sr_kemi_kx_xval, 0);
138
+		return &_sr_kemi_kx_xval;
139
+	}
140
+
141
+	xto = get_from(msg);
142
+	_sr_kemi_kx_xval.vtype = SR_KEMIP_STR;
143
+	_sr_kemi_kx_xval.v.s = xto->uri;
144
+	return &_sr_kemi_kx_xval;
145
+}
146
+
147
+/**
148
+ *
149
+ */
150
+static sr_kemi_xval_t* ki_kx_get_turi(sip_msg_t *msg)
151
+{
152
+	to_body_t *xto = NULL;
153
+
154
+	memset(&_sr_kemi_kx_xval, 0, sizeof(sr_kemi_xval_t));
155
+
156
+	if(msg==NULL) {
157
+		sr_kemi_xval_null(&_sr_kemi_kx_xval, 0);
158
+		return &_sr_kemi_kx_xval;
159
+	}
160
+	if(parse_to_header(msg)<0) {
161
+		LM_ERR("cannot parse To header\n");
162
+		sr_kemi_xval_null(&_sr_kemi_kx_xval, 0);
163
+		return &_sr_kemi_kx_xval;
164
+	}
165
+	if(msg->to==NULL || get_to(msg)==NULL) {
166
+		LM_DBG("no To header\n");
167
+		sr_kemi_xval_null(&_sr_kemi_kx_xval, 0);
168
+		return &_sr_kemi_kx_xval;
169
+	}
170
+
171
+	xto = get_to(msg);
172
+	_sr_kemi_kx_xval.vtype = SR_KEMIP_STR;
173
+	_sr_kemi_kx_xval.v.s = xto->uri;
174
+	return &_sr_kemi_kx_xval;
175
+}
176
+
86 177
 /**
87 178
  *
88 179
  */
... ...
@@ -93,6 +184,21 @@ static sr_kemi_t sr_kemi_kx_exports[] = {
93 184
 		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
94 185
 			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
95 186
 	},
187
+	{ str_init("kx"), str_init("get_ouri"),
188
+		SR_KEMIP_XVAL, ki_kx_get_ouri,
189
+		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
190
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
191
+	},
192
+	{ str_init("kx"), str_init("get_furi"),
193
+		SR_KEMIP_XVAL, ki_kx_get_furi,
194
+		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
195
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
196
+	},
197
+	{ str_init("kx"), str_init("get_turi"),
198
+		SR_KEMIP_XVAL, ki_kx_get_turi,
199
+		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
200
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
201
+	},
96 202
 
97 203
 	{ {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } }
98 204
 };