Browse code

kemix: functions to return directly user and host from ruri

Daniel-Constantin Mierla authored on 28/05/2019 12:05:16
Showing 1 changed files
... ...
@@ -174,6 +174,88 @@ static sr_kemi_xval_t* ki_kx_get_turi(sip_msg_t *msg)
174 174
 	return &_sr_kemi_kx_xval;
175 175
 }
176 176
 
177
+/**
178
+ *
179
+ */
180
+static sr_kemi_xval_t* ki_kx_get_xuri_attr(sip_msg_t *msg, sip_uri_t *puri,
181
+		int iattr, int xmode)
182
+{
183
+	if(iattr==1) {
184
+		/* username */
185
+		if(puri->user.s==NULL || puri->user.len<=0) {
186
+			sr_kemi_xval_null(&_sr_kemi_kx_xval, xmode);
187
+			return &_sr_kemi_kx_xval;
188
+		}
189
+		_sr_kemi_kx_xval.vtype = SR_KEMIP_STR;
190
+		_sr_kemi_kx_xval.v.s = puri->user;
191
+		return &_sr_kemi_kx_xval;
192
+	} else if(iattr==2) {
193
+		/* domain */
194
+		if(puri->host.s==NULL || puri->host.len<=0) {
195
+			sr_kemi_xval_null(&_sr_kemi_kx_xval, xmode);
196
+			return &_sr_kemi_kx_xval;
197
+		}
198
+		_sr_kemi_kx_xval.vtype = SR_KEMIP_STR;
199
+		_sr_kemi_kx_xval.v.s = puri->host;
200
+		return &_sr_kemi_kx_xval;
201
+	}
202
+	LM_ERR("unknown attribute id: %d\n", iattr);
203
+	sr_kemi_xval_null(&_sr_kemi_kx_xval, xmode);
204
+	return &_sr_kemi_kx_xval;
205
+}
206
+
207
+/**
208
+ *
209
+ */
210
+static sr_kemi_xval_t* ki_kx_get_ruri_attr(sip_msg_t *msg, int iattr, int xmode)
211
+{
212
+	memset(&_sr_kemi_kx_xval, 0, sizeof(sr_kemi_xval_t));
213
+
214
+	if(msg==NULL || msg->first_line.type == SIP_REPLY) {
215
+		sr_kemi_xval_null(&_sr_kemi_kx_xval, xmode);
216
+		return &_sr_kemi_kx_xval;
217
+	}
218
+
219
+	if(msg->parsed_uri_ok==0 /* R-URI not parsed*/ && parse_sip_msg_uri(msg)<0) {
220
+		LM_ERR("failed to parse the R-URI\n");
221
+		sr_kemi_xval_null(&_sr_kemi_kx_xval, xmode);
222
+		return &_sr_kemi_kx_xval;
223
+	}
224
+	return ki_kx_get_xuri_attr(msg, &(msg->parsed_uri), iattr, xmode);
225
+}
226
+
227
+/**
228
+ *
229
+ */
230
+static sr_kemi_xval_t* ki_kx_get_ruser(sip_msg_t *msg)
231
+{
232
+	return ki_kx_get_ruri_attr(msg, 1, SR_KEMI_XVAL_NULL_NONE);
233
+}
234
+
235
+/**
236
+ *
237
+ */
238
+static sr_kemi_xval_t* ki_kx_get_ruserx(sip_msg_t *msg, int xmode)
239
+{
240
+	return ki_kx_get_ruri_attr(msg, 1, xmode);
241
+}
242
+
243
+/**
244
+ *
245
+ */
246
+static sr_kemi_xval_t* ki_kx_get_rhost(sip_msg_t *msg)
247
+{
248
+	return ki_kx_get_ruri_attr(msg, 2, SR_KEMI_XVAL_NULL_NONE);
249
+}
250
+
251
+/**
252
+ *
253
+ */
254
+static sr_kemi_xval_t* ki_kx_get_rhostx(sip_msg_t *msg, int xmode)
255
+{
256
+	return ki_kx_get_ruri_attr(msg, 2, xmode);
257
+}
258
+
177 259
 /**
178 260
  *
179 261
  */
... ...
@@ -199,6 +281,27 @@ static sr_kemi_t sr_kemi_kx_exports[] = {
199 281
 		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
200 282
 			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
201 283
 	},
284
+	{ str_init("kx"), str_init("get_ruser"),
285
+		SR_KEMIP_XVAL, ki_kx_get_ruser,
286
+		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
287
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
288
+	},
289
+	{ str_init("kx"), str_init("get_ruserx"),
290
+		SR_KEMIP_XVAL, ki_kx_get_ruserx,
291
+		{ SR_KEMIP_INT, SR_KEMIP_NONE, SR_KEMIP_NONE,
292
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
293
+	},
294
+	{ str_init("kx"), str_init("get_rhost"),
295
+		SR_KEMIP_XVAL, ki_kx_get_rhost,
296
+		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
297
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
298
+	},
299
+	{ str_init("kx"), str_init("get_rhostx"),
300
+		SR_KEMIP_XVAL, ki_kx_get_rhostx,
301
+		{ SR_KEMIP_INT, SR_KEMIP_NONE, SR_KEMIP_NONE,
302
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
303
+	},
304
+
202 305
 
203 306
 	{ {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } }
204 307
 };