Browse code

kemix: functions to get src/rcv ip and port

Daniel-Constantin Mierla authored on 14/06/2019 07:01:08
Showing 1 changed files
... ...
@@ -317,6 +317,74 @@ static sr_kemi_xval_t* ki_kx_getw_ua(sip_msg_t *msg)
317 317
 	return ki_kx_get_ua_mode(msg, SR_KEMI_XVAL_NULL_PRINT);
318 318
 }
319 319
 
320
+/**
321
+ *
322
+ */
323
+static sr_kemi_xval_t* ki_kx_get_srcip(sip_msg_t *msg)
324
+{
325
+	memset(&_sr_kemi_kx_xval, 0, sizeof(sr_kemi_xval_t));
326
+	if(msg==NULL) {
327
+		sr_kemi_xval_null(&_sr_kemi_kx_xval, SR_KEMI_XVAL_NULL_NONE);
328
+		return &_sr_kemi_kx_xval;
329
+	}
330
+
331
+	_sr_kemi_kx_xval.vtype = SR_KEMIP_STR;
332
+	_sr_kemi_kx_xval.v.s.s = ip_addr2a(&msg->rcv.src_ip);
333
+	_sr_kemi_kx_xval.v.s.len = strlen(_sr_kemi_kx_xval.v.s.s);
334
+	return &_sr_kemi_kx_xval;
335
+}
336
+
337
+/**
338
+ *
339
+ */
340
+static sr_kemi_xval_t* ki_kx_get_srcport(sip_msg_t *msg)
341
+{
342
+	memset(&_sr_kemi_kx_xval, 0, sizeof(sr_kemi_xval_t));
343
+	if(msg==NULL) {
344
+		_sr_kemi_kx_xval.vtype = SR_KEMIP_INT;
345
+		_sr_kemi_kx_xval.v.n = 0;
346
+		return &_sr_kemi_kx_xval;
347
+	}
348
+
349
+	_sr_kemi_kx_xval.vtype = SR_KEMIP_INT;
350
+	_sr_kemi_kx_xval.v.n = (int)msg->rcv.src_port;
351
+	return &_sr_kemi_kx_xval;
352
+}
353
+
354
+/**
355
+ *
356
+ */
357
+static sr_kemi_xval_t* ki_kx_get_rcvip(sip_msg_t *msg)
358
+{
359
+	memset(&_sr_kemi_kx_xval, 0, sizeof(sr_kemi_xval_t));
360
+	if(msg==NULL || msg->rcv.bind_address==NULL
361
+			|| msg->rcv.bind_address->address_str.s==NULL) {
362
+		sr_kemi_xval_null(&_sr_kemi_kx_xval, SR_KEMI_XVAL_NULL_NONE);
363
+		return &_sr_kemi_kx_xval;
364
+	}
365
+
366
+	_sr_kemi_kx_xval.vtype = SR_KEMIP_STR;
367
+	_sr_kemi_kx_xval.v.s = msg->rcv.bind_address->address_str;
368
+	return &_sr_kemi_kx_xval;
369
+}
370
+
371
+/**
372
+ *
373
+ */
374
+static sr_kemi_xval_t* ki_kx_get_rcvport(sip_msg_t *msg)
375
+{
376
+	memset(&_sr_kemi_kx_xval, 0, sizeof(sr_kemi_xval_t));
377
+	if(msg==NULL || msg->rcv.bind_address==NULL) {
378
+		_sr_kemi_kx_xval.vtype = SR_KEMIP_INT;
379
+		_sr_kemi_kx_xval.v.n = 0;
380
+		return &_sr_kemi_kx_xval;
381
+	}
382
+
383
+	_sr_kemi_kx_xval.vtype = SR_KEMIP_INT;
384
+	_sr_kemi_kx_xval.v.n = (int)msg->rcv.bind_address->port_no;
385
+	return &_sr_kemi_kx_xval;
386
+}
387
+
320 388
 /**
321 389
  *
322 390
  */
... ...
@@ -387,6 +455,26 @@ static sr_kemi_t sr_kemi_kx_exports[] = {
387 455
 		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
388 456
 			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
389 457
 	},
458
+	{ str_init("kx"), str_init("get_srcip"),
459
+		SR_KEMIP_XVAL, ki_kx_get_srcip,
460
+		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
461
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
462
+	},
463
+	{ str_init("kx"), str_init("get_srcport"),
464
+		SR_KEMIP_XVAL, ki_kx_get_srcport,
465
+		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
466
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
467
+	},
468
+	{ str_init("kx"), str_init("get_rcvip"),
469
+		SR_KEMIP_XVAL, ki_kx_get_rcvip,
470
+		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
471
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
472
+	},
473
+	{ str_init("kx"), str_init("get_rcvport"),
474
+		SR_KEMIP_XVAL, ki_kx_get_rcvport,
475
+		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
476
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
477
+	},
390 478
 
391 479
 	{ {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } }
392 480
 };