Browse code

registrar: added function reg_from_user(ultable, uri, mode)

- return true if the message came from the user identified uri parameter
by matching agains its location records

Daniel-Constantin Mierla authored on 20/05/2022 11:17:24
Showing 1 changed files
... ...
@@ -33,6 +33,7 @@
33 33
 #include "../../core/mod_fix.h"
34 34
 #include "../../core/route.h"
35 35
 #include "../../core/action.h"
36
+#include "../../core/resolve.h"
36 37
 #include "../../core/fmsg.h"
37 38
 #include "../../core/kemi.h"
38 39
 #include "../../core/receive.h"
... ...
@@ -994,3 +995,88 @@ error:
994 995
 	}
995 996
 	return -1;
996 997
 }
998
+
999
+#define REG_FROM_USER_MPORT (1)
1000
+#define REG_FROM_USER_MPROTO (1<<1)
1001
+/**
1002
+ *
1003
+ */
1004
+int ki_reg_from_user(sip_msg_t* msg, str *utname, str* uri, int vmode)
1005
+{
1006
+	udomain_t* dt;
1007
+	urecord_t* r;
1008
+	ucontact_t* ptr;
1009
+	str aor = {0, 0};
1010
+	sip_uri_t rcvuri;
1011
+	int res = -1;
1012
+	int ret = -1;
1013
+	ip_addr_t ipb;
1014
+
1015
+	if (extract_aor(uri, &aor, NULL) < 0) {
1016
+		LM_ERR("failed to extract Address Of Record\n");
1017
+		return -1;
1018
+	}
1019
+
1020
+	if(ul.get_udomain(utname->s, &dt)<0) {
1021
+		LM_ERR("usrloc domain [%s] not found\n", utname->s);
1022
+		return -1;
1023
+	}
1024
+
1025
+	/* copy contacts */
1026
+	ul.lock_udomain(dt, &aor);
1027
+	res = ul.get_urecord(dt, &aor, &r);
1028
+	if (res > 0) {
1029
+		LM_DBG("'%.*s' not found in usrloc\n", aor.len, ZSW(aor.s));
1030
+		ul.unlock_udomain(dt, &aor);
1031
+		return -1;
1032
+	}
1033
+
1034
+	for(ptr = r->contacts; ptr; ptr = ptr->next) {
1035
+		if(ptr->received.s!=NULL) {
1036
+			if (parse_uri(ptr->received.s, ptr->received.len, &rcvuri) < 0) {
1037
+				LM_ERR("failed to parse rcv uri [%.*s]\n",
1038
+						ptr->received.len, ptr->received.s);
1039
+				goto error;
1040
+			}
1041
+		} else {
1042
+			if (parse_uri(ptr->c.s, ptr->c.len, &rcvuri) < 0) {
1043
+				LM_ERR("failed to parse contact uri [%.*s]\n",
1044
+						ptr->received.len, ptr->received.s);
1045
+				goto error;
1046
+			}
1047
+		}
1048
+		if(str2ipxbuf(&rcvuri.host, &ipb) < 0) {
1049
+			LM_WARN("failed to convert ip [%.*s] - ignoring\n",
1050
+					rcvuri.host.len, rcvuri.host.s);
1051
+			continue;
1052
+		}
1053
+		if(!ip_addr_cmp(&msg->rcv.src_ip, &ipb)) {
1054
+			continue;
1055
+		}
1056
+		if(vmode & REG_FROM_USER_MPORT) {
1057
+			if(msg->rcv.src_port!=rcvuri.port_no) {
1058
+				continue;
1059
+			}
1060
+		}
1061
+		if(vmode & REG_FROM_USER_MPROTO) {
1062
+			if(msg->rcv.proto!=rcvuri.proto) {
1063
+				continue;
1064
+			}
1065
+		}
1066
+		LM_DBG("matched contact record with source address [%.*s]\n",
1067
+				rcvuri.host.len, rcvuri.host.s);
1068
+		ret = 1;
1069
+		break;
1070
+	}
1071
+	ul.release_urecord(r);
1072
+	ul.unlock_udomain(dt, &aor);
1073
+
1074
+	return ret;
1075
+
1076
+error:
1077
+	ul.release_urecord(r);
1078
+	ul.unlock_udomain(dt, &aor);
1079
+	return -1;
1080
+
1081
+}
1082
+
Browse code

registrar: proper attribute name for contact record xavp

Daniel-Constantin Mierla authored on 12/05/2022 16:49:06
Showing 1 changed files
... ...
@@ -937,7 +937,7 @@ int ki_lookup_xavp(sip_msg_t* msg, str *utname, str* uri,
937 937
 			memset(&nxval, 0, sizeof(sr_xval_t));
938 938
 			nxval.type = SR_XTYPE_STR;
939 939
 			nxval.v.s = ptr->received;
940
-			STR_STATIC_SET(fxname, "socket");
940
+			STR_STATIC_SET(fxname, "dsturi");
941 941
 			if(xavp_add_value(&fxname, &nxval, &cxavp)==NULL) {
942 942
 				LM_ERR("failed to add xavp %.*s field\n", fxname.len, fxname.s);
943 943
 				goto error;
Browse code

registrar: added lookup_xavp("ultable", "uri", "rxname", "cxname")

- lookup of uri and store record and contact attributes in xavps

Daniel-Constantin Mierla authored on 12/05/2022 16:18:14
Showing 1 changed files
... ...
@@ -863,4 +863,134 @@ void reg_ul_expired_contact(ucontact_t* ptr, int type, void* param)
863 863
 	return;
864 864
 error:
865 865
 	regpv_free_profile(rpp);
866
-	return; }
866
+	return;
867
+}
868
+
869
+int ki_lookup_xavp(sip_msg_t* msg, str *utname, str* uri,
870
+		str* rxname, str *cxname)
871
+{
872
+	udomain_t* dt;
873
+	urecord_t* r;
874
+	ucontact_t* ptr;
875
+	str aor = {0, 0};
876
+	sr_xavp_t *rxavp=NULL;
877
+	sr_xavp_t *cxavp=NULL;
878
+	sr_xavp_t *pxavp=NULL;
879
+	sr_xval_t nxval;
880
+	str fxname = {0, 0};
881
+	int res;
882
+	int n;
883
+
884
+	if (extract_aor(uri, &aor, NULL) < 0) {
885
+		LM_ERR("failed to extract Address Of Record\n");
886
+		return -1;
887
+	}
888
+
889
+	if(ul.get_udomain(utname->s, &dt)<0) {
890
+		LM_ERR("usrloc domain [%s] not found\n", utname->s);
891
+		return -1;
892
+	}
893
+
894
+	/* add record aor field */
895
+	memset(&nxval, 0, sizeof(sr_xval_t));
896
+	nxval.type = SR_XTYPE_STR;
897
+	nxval.v.s = aor;
898
+	STR_STATIC_SET(fxname, "aor");
899
+	if(xavp_add_value(&fxname, &nxval, &rxavp)==NULL) {
900
+		LM_ERR("failed to add xavp %.*s field\n", fxname.len, fxname.s);
901
+		return -1;
902
+	}
903
+
904
+	/* copy contacts */
905
+	ul.lock_udomain(dt, &aor);
906
+	res = ul.get_urecord(dt, &aor, &r);
907
+	if (res > 0) {
908
+		LM_DBG("'%.*s' not found in usrloc\n", aor.len, ZSW(aor.s));
909
+		ul.unlock_udomain(dt, &aor);
910
+		xavp_destroy_list(&rxavp);
911
+		return -1;
912
+	}
913
+
914
+	ptr = r->contacts;
915
+	n = 0;
916
+	while(ptr) {
917
+		/* add record uri field */
918
+		memset(&nxval, 0, sizeof(sr_xval_t));
919
+		nxval.type = SR_XTYPE_STR;
920
+		nxval.v.s = ptr->c;
921
+		STR_STATIC_SET(fxname, "uri");
922
+		if(xavp_add_value(&fxname, &nxval, &cxavp)==NULL) {
923
+			LM_ERR("failed to add xavp %.*s field\n", fxname.len, fxname.s);
924
+			goto error;
925
+		}
926
+		if(ptr->sock) {
927
+			memset(&nxval, 0, sizeof(sr_xval_t));
928
+			nxval.type = SR_XTYPE_STR;
929
+			nxval.v.s = ptr->sock->sock_str;
930
+			STR_STATIC_SET(fxname, "socket");
931
+			if(xavp_add_value(&fxname, &nxval, &cxavp)==NULL) {
932
+				LM_ERR("failed to add xavp %.*s field\n", fxname.len, fxname.s);
933
+				goto error;
934
+			}
935
+		}
936
+		if(ptr->received.s!=NULL) {
937
+			memset(&nxval, 0, sizeof(sr_xval_t));
938
+			nxval.type = SR_XTYPE_STR;
939
+			nxval.v.s = ptr->received;
940
+			STR_STATIC_SET(fxname, "socket");
941
+			if(xavp_add_value(&fxname, &nxval, &cxavp)==NULL) {
942
+				LM_ERR("failed to add xavp %.*s field\n", fxname.len, fxname.s);
943
+				goto error;
944
+			}
945
+		}
946
+		/* add cxavp in root list */
947
+		memset(&nxval, 0, sizeof(sr_xval_t));
948
+		nxval.type = SR_XTYPE_XAVP;
949
+		nxval.v.xavp = cxavp;
950
+		if((pxavp = xavp_add_value_after(cxname, &nxval, pxavp))==NULL) {
951
+			LM_ERR("cannot add dst xavp to root list\n");
952
+			goto error;
953
+		}
954
+		cxavp = NULL;
955
+		n++;
956
+		ptr = ptr->next;
957
+	}
958
+	ul.release_urecord(r);
959
+	ul.unlock_udomain(dt, &aor);
960
+
961
+	/* add record count field */
962
+	memset(&nxval, 0, sizeof(sr_xval_t));
963
+	nxval.type = SR_XTYPE_INT;
964
+	nxval.v.i = n;
965
+	STR_STATIC_SET(fxname, "count");
966
+	if(xavp_add_value(&fxname, &nxval, &rxavp)==NULL) {
967
+		LM_ERR("failed to add xavp %.*s field\n", fxname.len, fxname.s);
968
+		xavp_destroy_list(&rxavp);
969
+		return -1;
970
+	}
971
+
972
+	/* add rxavp in root list */
973
+	memset(&nxval, 0, sizeof(sr_xval_t));
974
+	nxval.type = SR_XTYPE_XAVP;
975
+	nxval.v.xavp = rxavp;
976
+	if((pxavp = xavp_add_value(rxname, &nxval, NULL))==NULL) {
977
+		LM_ERR("cannot add rxavp to root list\n");
978
+		xavp_destroy_list(&rxavp);
979
+		return -1;
980
+	}
981
+
982
+	LM_DBG("fetched <%d> contacts for <%.*s> in [%.*s]\n",
983
+			n, aor.len, aor.s, cxname->len, cxname->s);
984
+	return 1;
985
+
986
+error:
987
+	ul.release_urecord(r);
988
+	ul.unlock_udomain(dt, &aor);
989
+	if(cxavp!=NULL) {
990
+		xavp_destroy_list(&cxavp);
991
+	}
992
+	if(rxavp!=NULL) {
993
+		xavp_destroy_list(&rxavp);
994
+	}
995
+	return -1;
996
+}
Browse code

registrar: kemi functions to get $ulc(...) attributes

Daniel-Constantin Mierla authored on 12/05/2022 09:21:46
Showing 1 changed files
... ...
@@ -430,6 +430,113 @@ error:
430 430
 	return -1;
431 431
 }
432 432
 
433
+/**
434
+ *
435
+ */
436
+static sr_kemi_xval_t _sr_kemi_reg_ulc_xval = {0};
437
+
438
+sr_kemi_xval_t* ki_reg_ulc_rget(sip_msg_t* msg, str* rid, str* attr)
439
+{
440
+	regpv_profile_t *rpp = NULL;
441
+
442
+	memset(&_sr_kemi_reg_ulc_xval, 0, sizeof(sr_kemi_xval_t));
443
+	if(rid==NULL || rid->s==NULL || attr==NULL || attr->s==NULL) {
444
+		LM_WARN("invalid parameters - return value 0\n");
445
+		_sr_kemi_reg_ulc_xval.vtype = SR_KEMIP_INT;
446
+		_sr_kemi_reg_ulc_xval.v.n = 0;
447
+		return &_sr_kemi_reg_ulc_xval;
448
+	}
449
+
450
+	rpp = regpv_get_profile(rid);
451
+	if(rpp==0) {
452
+		LM_WARN("result [%.*s] is not defined - return value 0\n",
453
+				rid->len, rid->s);
454
+		_sr_kemi_reg_ulc_xval.vtype = SR_KEMIP_INT;
455
+		_sr_kemi_reg_ulc_xval.v.n = 0;
456
+		return &_sr_kemi_reg_ulc_xval;
457
+	}
458
+
459
+	if(attr->len==5 && strncmp(attr->s, "count", 5)==0) {
460
+		_sr_kemi_reg_ulc_xval.vtype = SR_KEMIP_INT;
461
+		_sr_kemi_reg_ulc_xval.v.n = rpp->nrc;
462
+		return &_sr_kemi_reg_ulc_xval;
463
+	} else if(attr->len==3 && strncmp(attr->s, "aor", 3)==0) {
464
+		_sr_kemi_reg_ulc_xval.vtype = SR_KEMIP_STR;
465
+		_sr_kemi_reg_ulc_xval.v.s = rpp->aor;
466
+		return &_sr_kemi_reg_ulc_xval;
467
+	}
468
+
469
+	LM_WARN("attribute [%.*s] is not defined - return value 0\n",
470
+			attr->len, attr->s);
471
+	_sr_kemi_reg_ulc_xval.vtype = SR_KEMIP_INT;
472
+	_sr_kemi_reg_ulc_xval.v.n = 0;
473
+	return &_sr_kemi_reg_ulc_xval;
474
+}
475
+
476
+sr_kemi_xval_t* ki_reg_ulc_cget(sip_msg_t* msg, str* rid, str* attr, int idx)
477
+{
478
+	regpv_profile_t *rpp = NULL;
479
+	ucontact_t *c = NULL;
480
+	int i = 0;
481
+
482
+
483
+	memset(&_sr_kemi_reg_ulc_xval, 0, sizeof(sr_kemi_xval_t));
484
+	if(rid==NULL || rid->s==NULL || attr==NULL || attr->s==NULL) {
485
+		LM_WARN("invalid parameters - return value 0\n");
486
+		_sr_kemi_reg_ulc_xval.vtype = SR_KEMIP_INT;
487
+		_sr_kemi_reg_ulc_xval.v.n = 0;
488
+		return &_sr_kemi_reg_ulc_xval;
489
+	}
490
+
491
+	rpp = regpv_get_profile(rid);
492
+	if(rpp==0) {
493
+		LM_WARN("result [%.*s] is not defined - return value 0\n",
494
+				rid->len, rid->s);
495
+		_sr_kemi_reg_ulc_xval.vtype = SR_KEMIP_INT;
496
+		_sr_kemi_reg_ulc_xval.v.n = 0;
497
+		return &_sr_kemi_reg_ulc_xval;
498
+	}
499
+
500
+	/* work only with positive indexes by now */
501
+	if(idx<0) {
502
+		idx = 0;
503
+	}
504
+	/* get contact by index */
505
+	i = 0;
506
+	for(c = rpp->contacts; c!=NULL; c = c->next) {
507
+		if(i == idx) {
508
+			break;
509
+		}
510
+		i++;
511
+	}
512
+	if(c == NULL) {
513
+		LM_WARN("contact at index [%d] is not found - return value 0\n", idx);
514
+		_sr_kemi_reg_ulc_xval.vtype = SR_KEMIP_INT;
515
+		_sr_kemi_reg_ulc_xval.v.n = 0;
516
+		return &_sr_kemi_reg_ulc_xval;
517
+	}
518
+
519
+	if(attr->len==4 && strncmp(attr->s, "addr", 4)==0) {
520
+		_sr_kemi_reg_ulc_xval.vtype = SR_KEMIP_STR;
521
+		_sr_kemi_reg_ulc_xval.v.s = c->c;
522
+		return &_sr_kemi_reg_ulc_xval;
523
+	} else if(attr->len==6 && strncmp(attr->s, "socket", 6)==0) {
524
+		if(c->sock==NULL) {
525
+			sr_kemi_xval_null(&_sr_kemi_reg_ulc_xval, SR_KEMI_XVAL_NULL_EMPTY);
526
+			return &_sr_kemi_reg_ulc_xval;
527
+		}
528
+		_sr_kemi_reg_ulc_xval.vtype = SR_KEMIP_STR;
529
+		_sr_kemi_reg_ulc_xval.v.s = c->sock->sock_str;
530
+		return &_sr_kemi_reg_ulc_xval;
531
+	}
532
+
533
+	LM_WARN("attribute [%.*s] is not defined - return value 0\n",
534
+			attr->len, attr->s);
535
+	_sr_kemi_reg_ulc_xval.vtype = SR_KEMIP_INT;
536
+	_sr_kemi_reg_ulc_xval.v.n = 0;
537
+	return &_sr_kemi_reg_ulc_xval;
538
+}
539
+
433 540
 int pv_fetch_contacts_helper(sip_msg_t* msg, udomain_t* dt, str* uri,
434 541
 		str* profile)
435 542
 {
Browse code

registrar: clean avp/xavp created at 'usrloc:contact-expired' route_event

Victor Seva authored on 26/06/2019 10:29:22
Showing 1 changed files
... ...
@@ -35,6 +35,7 @@
35 35
 #include "../../core/action.h"
36 36
 #include "../../core/fmsg.h"
37 37
 #include "../../core/kemi.h"
38
+#include "../../core/receive.h"
38 39
 #include "../usrloc/usrloc.h"
39 40
 #include "registrar.h"
40 41
 #include "common.h"
... ...
@@ -751,7 +752,7 @@ void reg_ul_expired_contact(ucontact_t* ptr, int type, void* param)
751 752
 		}
752 753
 	}
753 754
 	set_route_type(backup_rt);
754
-
755
+	ksr_msg_env_reset();
755 756
 	return;
756 757
 error:
757 758
 	regpv_free_profile(rpp);
Browse code

registrar: use kemi wrapper to execute routing functions

Daniel-Constantin Mierla authored on 27/02/2019 08:25:25
Showing 1 changed files
... ...
@@ -744,7 +744,7 @@ void reg_ul_expired_contact(ucontact_t* ptr, int type, void* param)
744 744
 		keng = sr_kemi_eng_get();
745 745
 		if (keng!=NULL) {
746 746
 			str evname = str_init("usrloc:contact-expired");
747
-			if(keng->froute(fmsg, EVENT_ROUTE,
747
+			if(sr_kemi_route(keng, fmsg, EVENT_ROUTE,
748 748
 					&reg_event_callback, &evname)<0) {
749 749
 				LM_ERR("error running event route kemi callback\n");
750 750
 			}
Browse code

registrar: add event_callback parameter

This allows usage of the `usrloc:contact-expired` event route with
KEMI routing configurations.

Ivaylo Markov authored on 18/08/2018 14:46:00
Showing 1 changed files
... ...
@@ -34,11 +34,14 @@
34 34
 #include "../../core/route.h"
35 35
 #include "../../core/action.h"
36 36
 #include "../../core/fmsg.h"
37
+#include "../../core/kemi.h"
37 38
 #include "../usrloc/usrloc.h"
38 39
 #include "registrar.h"
39 40
 #include "common.h"
40 41
 #include "regpv.h"
41 42
 
43
+extern str reg_event_callback;
44
+
42 45
 typedef struct _regpv_profile {
43 46
 	str pname;
44 47
 	str domain;
... ...
@@ -629,8 +632,9 @@ void reg_ul_expired_contact(ucontact_t* ptr, int type, void* param)
629 632
 	int olen;
630 633
 	int ilen;
631 634
 	char *p;
635
+	sr_kemi_eng_t *keng = NULL;
632 636
 
633
-	if(reg_expire_event_rt<0)
637
+	if(reg_expire_event_rt<0 && reg_event_callback.s==NULL)
634 638
 		return;
635 639
 
636 640
 	if (faked_msg_init() < 0)
... ...
@@ -733,11 +737,22 @@ void reg_ul_expired_contact(ucontact_t* ptr, int type, void* param)
733 737
 	backup_rt = get_route_type();
734 738
 	set_route_type(REQUEST_ROUTE);
735 739
 	init_run_actions_ctx(&ctx);
736
-	run_top_route(event_rt.rlist[reg_expire_event_rt], fmsg, 0);
740
+
741
+	if (reg_expire_event_rt >= 0) {
742
+		run_top_route(event_rt.rlist[reg_expire_event_rt], fmsg, 0);
743
+	} else {
744
+		keng = sr_kemi_eng_get();
745
+		if (keng!=NULL) {
746
+			str evname = str_init("usrloc:contact-expired");
747
+			if(keng->froute(fmsg, EVENT_ROUTE,
748
+					&reg_event_callback, &evname)<0) {
749
+				LM_ERR("error running event route kemi callback\n");
750
+			}
751
+		}
752
+	}
737 753
 	set_route_type(backup_rt);
738 754
 
739 755
 	return;
740 756
 error:
741 757
 	regpv_free_profile(rpp);
742
-	return;
743
-}
758
+	return; }
Browse code

registrar: added server_id to pv attributes

Charles Chance authored on 10/11/2017 13:52:01
Showing 1 changed files
... ...
@@ -273,6 +273,9 @@ int pv_get_ulc(struct sip_msg *msg,  pv_param_t *param,
273 273
 			if (c->sock && (c->sock->proto == PROTO_TCP || c->sock->proto == PROTO_TLS || c->sock->proto == PROTO_WS || c->sock->proto == PROTO_WSS))
274 274
 				return pv_get_sintval(msg, param, res, c->tcpconn_id);
275 275
 		break;
276
+		case 22: /* server_id */
277
+			return pv_get_uintval(msg, param, res, c->server_id);
278
+		break;
276 279
 	}
277 280
 
278 281
 	return pv_get_null(msg, param, res);
... ...
@@ -400,6 +403,10 @@ int pv_parse_ulc_name(pv_spec_p sp, str *in)
400 403
 				rp->attr = 20;
401 404
 			else goto error;
402 405
 		break;
406
+		case 9:
407
+			if(strncmp(pa.s, "server_id", 9)==0)
408
+				rp->attr = 22;
409
+		break;
403 410
 		case 10:
404 411
 			if(strncmp(pa.s, "user_agent", 10)==0)
405 412
 				rp->attr = 12;
Browse code

registrar: restructured condition for clarity

Daniel-Constantin Mierla authored on 28/07/2017 08:29:33
Showing 1 changed files
... ...
@@ -538,6 +538,7 @@ int pv_fetch_contacts_helper(sip_msg_t* msg, udomain_t* dt, str* uri,
538 538
 			c0->instance.len = ptr->instance.len;
539 539
 			p += c0->instance.len;
540 540
 		}
541
+		LM_DBG("memory block between %p - %p\n", c0, p);
541 542
 		if ((ptr->sock) && (ptr->sock->proto == PROTO_TCP
542 543
 				|| ptr->sock->proto == PROTO_TLS || ptr->sock->proto == PROTO_WS
543 544
 				|| ptr->sock->proto == PROTO_WSS))
Browse code

registrar: free var in case of pv name error

Daniel-Constantin Mierla authored on 08/07/2017 07:38:13
Showing 1 changed files
... ...
@@ -288,8 +288,8 @@ int pv_parse_ulc_name(pv_spec_p sp, str *in)
288 288
 {
289 289
 	str pn;
290 290
 	str pa;
291
-	regpv_name_t *rp;
292
-	regpv_profile_t *rpp;
291
+	regpv_name_t *rp = NULL;
292
+	regpv_profile_t *rpp = NULL;
293 293
 
294 294
 	if(sp==NULL || in==NULL || in->len<=0)
295 295
 		return -1;
... ...
@@ -414,6 +414,7 @@ int pv_parse_ulc_name(pv_spec_p sp, str *in)
414 414
 	return 0;
415 415
 
416 416
 error:
417
+	if(rp) pkg_free(rp);
417 418
 	LM_ERR("unknown contact attr name in %.*s\n", in->len, in->s);
418 419
 	return -1;
419 420
 }
Browse code

registrar: fix compilation warnings

Daniel-Constantin Mierla authored on 02/05/2017 13:10:17
Showing 1 changed files
... ...
@@ -427,7 +427,6 @@ int pv_fetch_contacts_helper(sip_msg_t* msg, udomain_t* dt, str* uri,
427 427
 	ucontact_t* c0;
428 428
 	regpv_profile_t *rpp;
429 429
 	str aor = {0, 0};
430
-	str u = {0, 0};
431 430
 	int res;
432 431
 	int olen;
433 432
 	int ilen;
Browse code

registrar: more functions exported to kemi framework

Daniel-Constantin Mierla authored on 01/05/2017 06:08:28
Showing 1 changed files
... ...
@@ -418,8 +418,8 @@ error:
418 418
 	return -1;
419 419
 }
420 420
 
421
-int pv_fetch_contacts(struct sip_msg* msg, char* table, char* uri,
422
-		char* profile)
421
+int pv_fetch_contacts_helper(sip_msg_t* msg, udomain_t* dt, str* uri,
422
+		str* profile)
423 423
 {
424 424
 	urecord_t* r;
425 425
 	ucontact_t* ptr;
... ...
@@ -445,13 +445,7 @@ int pv_fetch_contacts(struct sip_msg* msg, char* table, char* uri,
445 445
 	if(rpp->flags)
446 446
 		regpv_free_profile(rpp);
447 447
 
448
-	if(fixup_get_svalue(msg, (gparam_p)uri, &u)!=0 || u.len<=0)
449
-	{
450
-		LM_ERR("invalid uri parameter\n");
451
-		return -1;
452
-	}
453
-
454
-	if (extract_aor(&u, &aor, NULL) < 0) {
448
+	if (extract_aor(uri, &aor, NULL) < 0) {
455 449
 		LM_ERR("failed to extract Address Of Record\n");
456 450
 		return -1;
457 451
 	}
... ...
@@ -465,16 +459,16 @@ int pv_fetch_contacts(struct sip_msg* msg, char* table, char* uri,
465 459
 	}
466 460
 	memcpy(rpp->aor.s, aor.s, aor.len);
467 461
 	rpp->aor.len = aor.len;
468
-	rpp->domain = *((udomain_head_t*)table)->name;
462
+	rpp->domain = *((udomain_head_t*)dt)->name;
469 463
 	rpp->flags = 1;
470 464
 
471 465
 	/* copy contacts */
472 466
 	ilen = sizeof(ucontact_t);
473
-	ul.lock_udomain((udomain_t*)table, &aor);
474
-	res = ul.get_urecord((udomain_t*)table, &aor, &r);
467
+	ul.lock_udomain(dt, &aor);
468
+	res = ul.get_urecord(dt, &aor, &r);
475 469
 	if (res > 0) {
476 470
 		LM_DBG("'%.*s' Not found in usrloc\n", aor.len, ZSW(aor.s));
477
-		ul.unlock_udomain((udomain_t*)table, &aor);
471
+		ul.unlock_udomain(dt, &aor);
478 472
 		return -1;
479 473
 	}
480 474
 
... ...
@@ -491,7 +485,7 @@ int pv_fetch_contacts(struct sip_msg* msg, char* table, char* uri,
491 485
 		{
492 486
 			LM_ERR("no more pkg\n");
493 487
 			ul.release_urecord(r);
494
-			ul.unlock_udomain((udomain_t*)table, &aor);
488
+			ul.unlock_udomain(dt, &aor);
495 489
 			goto error;
496 490
 		}
497 491
 		memcpy(c0, ptr, ilen);
... ...
@@ -544,7 +538,9 @@ int pv_fetch_contacts(struct sip_msg* msg, char* table, char* uri,
544 538
 			c0->instance.len = ptr->instance.len;
545 539
 			p += c0->instance.len;
546 540
 		}
547
-		if ((ptr->sock) && (ptr->sock->proto == PROTO_TCP || ptr->sock->proto == PROTO_TLS || ptr->sock->proto == PROTO_WS || ptr->sock->proto == PROTO_WSS))
541
+		if ((ptr->sock) && (ptr->sock->proto == PROTO_TCP
542
+				|| ptr->sock->proto == PROTO_TLS || ptr->sock->proto == PROTO_WS
543
+				|| ptr->sock->proto == PROTO_WSS))
548 544
 		{
549 545
 			c0->tcpconn_id = ptr->tcpconn_id;
550 546
 		}
... ...
@@ -561,7 +557,7 @@ int pv_fetch_contacts(struct sip_msg* msg, char* table, char* uri,
561 557
 		ptr = ptr->next;
562 558
 	}
563 559
 	ul.release_urecord(r);
564
-	ul.unlock_udomain((udomain_t*)table, &aor);
560
+	ul.unlock_udomain(dt, &aor);
565 561
 	rpp->nrc = n;
566 562
 	LM_DBG("fetched <%d> contacts for <%.*s> in [%.*s]\n",
567 563
 			n, aor.len, aor.s, rpp->pname.len, rpp->pname.s);
... ...
@@ -571,11 +567,36 @@ error:
571 567
 	regpv_free_profile(rpp);
572 568
 	return -1;
573 569
 }
574
-int pv_free_contacts(struct sip_msg* msg, char* profile, char* s2)
570
+
571
+int pv_fetch_contacts(sip_msg_t* msg, char* table, char* uri, char* profile)
572
+{
573
+	str u = STR_NULL;
574
+
575
+	if(fixup_get_svalue(msg, (gparam_t*)uri, &u)!=0 || u.len<=0)
576
+	{
577
+		LM_ERR("invalid uri parameter\n");
578
+		return -1;
579
+	}
580
+	return pv_fetch_contacts_helper(msg, (udomain_t*)table, &u, (str*)profile);
581
+}
582
+
583
+int ki_reg_fetch_contacts(sip_msg_t* msg, str* dtable, str* uri, str* profile)
584
+{
585
+	udomain_t* d;
586
+
587
+	if(ul.get_udomain(dtable->s, &d)<0) {
588
+		LM_ERR("usrloc domain [%s] not found\n", dtable->s);
589
+		return -1;
590
+	}
591
+
592
+	return pv_fetch_contacts_helper(msg, d, uri, profile);
593
+}
594
+
595
+int ki_reg_free_contacts(sip_msg_t* msg, str* profile)
575 596
 {
576 597
 	regpv_profile_t *rpp;
577 598
 
578
-	rpp = regpv_get_profile((str*)profile);
599
+	rpp = regpv_get_profile(profile);
579 600
 	if(rpp==0)
580 601
 		return -1;
581 602
 
... ...
@@ -584,6 +605,11 @@ int pv_free_contacts(struct sip_msg* msg, char* profile, char* s2)
584 605
 	return 1;
585 606
 }
586 607
 
608
+int pv_free_contacts(struct sip_msg* msg, char* profile, char* s2)
609
+{
610
+	return ki_reg_free_contacts(msg, (str*)profile);
611
+}
612
+
587 613
 void reg_ul_expired_contact(ucontact_t* ptr, int type, void* param)
588 614
 {
589 615
 	str profile = {"exp", 3};
Browse code

core, lib, modules: updated include paths for header files

Daniel-Constantin Mierla authored on 07/12/2016 11:07:22
Showing 1 changed files
... ...
@@ -28,12 +28,12 @@
28 28
 
29 29
 
30 30
 #include <string.h>
31
-#include "../../dprint.h"
32
-#include "../../mem/mem.h"
33
-#include "../../mod_fix.h"
34
-#include "../../route.h"
35
-#include "../../action.h"
36
-#include "../../fmsg.h"
31
+#include "../../core/dprint.h"
32
+#include "../../core/mem/mem.h"
33
+#include "../../core/mod_fix.h"
34
+#include "../../core/route.h"
35
+#include "../../core/action.h"
36
+#include "../../core/fmsg.h"
37 37
 #include "../usrloc/usrloc.h"
38 38
 #include "registrar.h"
39 39
 #include "common.h"
Browse code

core, lib, modules: restructured source code tree

- new folder src/ to hold the source code for main project applications
- main.c is in src/
- all core files are subfolder are in src/core/
- modules are in src/modules/
- libs are in src/lib/
- application Makefiles are in src/
- application binary is built in src/ (src/kamailio)

Daniel-Constantin Mierla authored on 07/12/2016 11:03:51
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,709 @@
1
+/*
2
+ * Export vontact attrs as PV
3
+ *
4
+ * Copyright (C) 2008 Daniel-Constantin Mierla (asipto.com)
5
+ *
6
+ * This file is part of Kamailio, a free SIP server.
7
+ *
8
+ * Kamailio is free software; you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation; either version 2 of the License, or
11
+ * (at your option) any later version
12
+ *
13
+ * Kamailio is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program; if not, write to the Free Software
20
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21
+ */
22
+
23
+/*!
24
+ * \file
25
+ * \brief SIP registrar module - export contacts as PV
26
+ * \ingroup registrar
27
+ */
28
+
29
+
30
+#include <string.h>
31
+#include "../../dprint.h"
32
+#include "../../mem/mem.h"
33
+#include "../../mod_fix.h"
34
+#include "../../route.h"
35
+#include "../../action.h"
36
+#include "../../fmsg.h"
37
+#include "../usrloc/usrloc.h"
38
+#include "registrar.h"
39
+#include "common.h"
40
+#include "regpv.h"
41
+
42
+typedef struct _regpv_profile {
43
+	str pname;
44
+	str domain;
45
+	str aor;
46
+	int flags;
47
+	unsigned int aorhash;
48
+	int nrc;
49
+	ucontact_t* contacts;
50
+	struct _regpv_profile *next;
51
+} regpv_profile_t;
52
+
53
+typedef struct _regpv_name {
54
+	regpv_profile_t *rp;
55
+	int attr;
56
+} regpv_name_t;
57
+
58
+static regpv_profile_t *_regpv_profile_list = NULL;
59
+
60
+static inline regpv_profile_t* regpv_get_profile(str *name)
61
+{
62
+	regpv_profile_t *rp;
63
+
64
+	if(name==NULL || name->len<=0)
65
+	{
66
+		LM_ERR("invalid parameters\n");
67
+		return NULL;
68
+	}
69
+
70
+	rp = _regpv_profile_list;
71
+	while(rp)
72
+	{
73
+		if(rp->pname.len == name->len
74
+				&& strncmp(rp->pname.s, name->s, name->len)==0)
75
+			return rp;
76
+		rp = rp->next;
77
+	}
78
+
79
+	rp = (regpv_profile_t*)pkg_malloc(sizeof(regpv_profile_t));
80
+	if(rp==NULL)
81
+	{
82
+		LM_ERR("no more pkg\n");
83
+		return NULL;
84
+	}
85
+	memset(rp, 0, sizeof(regpv_profile_t));
86
+	rp->pname.s = (char*)pkg_malloc((name->len+1)*sizeof(char));
87
+	if(rp->pname.s==NULL)
88
+	{
89
+		LM_ERR("no more pkg\n");
90
+		pkg_free(rp);
91
+		return NULL;
92
+	}
93
+	memcpy(rp->pname.s, name->s, name->len);
94
+	rp->pname.s[name->len] = '\0';
95
+	rp->pname.len = name->len;
96
+
97
+	rp->next = _regpv_profile_list;
98
+	_regpv_profile_list = rp;
99
+	return rp;
100
+}
101
+
102
+static void regpv_free_profile(regpv_profile_t *rpp)
103
+{
104
+	ucontact_t* ptr;
105
+	ucontact_t* ptr0;
106
+
107
+	if(rpp==NULL)
108
+		return;
109
+
110
+	ptr = rpp->contacts;
111
+	while(ptr)
112
+	{
113
+		ptr0 = ptr;
114
+		ptr = ptr->next;
115
+		pkg_free(ptr0);
116
+	}
117
+	if(rpp->domain.s!=NULL)
118
+	{
119
+		rpp->domain.s = 0;
120
+		rpp->domain.len = 0;
121
+	}
122
+	if(rpp->aor.s!=NULL)
123
+	{
124
+		pkg_free(rpp->aor.s);
125
+		rpp->aor.s = 0;
126
+		rpp->aor.len = 0;
127
+	}
128
+
129
+	rpp->flags = 0;
130
+	rpp->aorhash = 0;
131
+	rpp->nrc = 0;
132
+	rpp->contacts = 0;
133
+
134
+}
135
+
136
+void regpv_free_profiles(void)
137
+{
138
+	regpv_profile_t *rp;
139
+	regpv_profile_t *rp0;
140
+
141
+	rp = _regpv_profile_list;
142
+
143
+	while(rp)
144
+	{
145
+		if(rp->pname.s!=NULL)
146
+			pkg_free(rp->pname.s);
147
+		rp0 = rp;
148
+		regpv_free_profile(rp0);
149
+		rp = rp->next;
150
+	}
151
+	_regpv_profile_list = 0;
152
+}
153
+
154
+int pv_get_ulc(struct sip_msg *msg,  pv_param_t *param,
155
+		pv_value_t *res)
156
+{
157
+	regpv_name_t *rp;
158
+	regpv_profile_t *rpp;
159
+	ucontact_t *c;
160
+	int idx;
161
+	int i;
162
+
163
+	if(param==NULL)
164
+	{
165
+		LM_ERR("invalid params\n");
166
+		return -1;
167
+	}
168
+	rp = (regpv_name_t*)param->pvn.u.dname;
169
+	if(rp==NULL || rp->rp==NULL)
170
+	{
171
+		LM_DBG("no profile in params\n");
172
+		return pv_get_null(msg, param, res);
173
+	}
174
+	rpp = rp->rp;
175
+
176
+	if(rpp->flags==0 || rpp->contacts==NULL)
177
+	{
178
+		LM_DBG("profile not set or no contacts there\n");
179
+		return pv_get_null(msg, param, res);
180
+	}
181
+	/* get index */
182
+	if(pv_get_spec_index(msg, param, &idx, &i)!=0)
183
+	{
184
+		LM_ERR("invalid index\n");
185
+		return -1;
186
+	}
187
+
188
+	/* work only with positive indexes by now */
189
+	if(idx<0)
190
+		idx = 0;
191
+
192
+	/* get contact */
193
+	i = 0;
194
+	c = rpp->contacts;
195
+	while(c)
196
+	{
197
+		if(i == idx)
198
+			break;
199
+		i++;
200
+		c = c->next;
201
+	}
202
+	if(c==NULL)
203
+		return pv_get_null(msg, param, res);
204
+
205
+	switch(rp->attr)
206
+	{
207
+		case 0: /* aor */
208
+			return  pv_get_strval(msg, param, res, &rpp->aor);
209
+		break;
210
+		case 1: /* domain */
211
+			return  pv_get_strval(msg, param, res, &rpp->domain);
212
+		break;
213
+		case 2: /* aorhash */
214
+			return pv_get_uintval(msg, param, res, rpp->aorhash);
215
+		break;
216
+		case 3: /* addr */
217
+			return  pv_get_strval(msg, param, res, &c->c);
218
+		break;
219
+		case 4: /* path */
220
+			return  pv_get_strval(msg, param, res, &c->path);
221
+		break;
222
+		case 5: /* received */
223
+			return  pv_get_strval(msg, param, res, &c->received);
224
+		break;
225
+		case 6: /* expires */
226
+			return pv_get_uintval(msg, param, res,
227
+					(unsigned int)c->expires);
228
+		break;
229
+		case 7: /* callid */
230
+			return  pv_get_strval(msg, param, res, &c->callid);
231
+		break;
232
+		case 8: /* q */
233
+			return pv_get_sintval(msg, param, res, (int)c->q);
234
+		break;
235
+		case 9: /* cseq */
236
+			return pv_get_sintval(msg, param, res, c->cseq);
237
+		break;
238
+		case 10: /* flags */
239
+			return pv_get_uintval(msg, param, res, c->flags);
240
+		break;
241
+		case 11: /* cflags */
242
+			return pv_get_uintval(msg, param, res, c->cflags);
243
+		break;
244
+		case 12: /* user agent */
245
+			return  pv_get_strval(msg, param, res, &c->user_agent);
246
+		break;
247
+		case 14: /* socket */
248
+			if(c->sock==NULL)
249
+				return pv_get_null(msg, param, res);
250
+			return pv_get_strval(msg, param, res, &c->sock->sock_str);
251
+		break;
252
+		case 15: /* modified */
253
+			return pv_get_uintval(msg, param, res,
254
+					(unsigned int)c->last_modified);
255
+		break;
256
+		case 16: /* methods */
257
+			return pv_get_uintval(msg, param, res, c->methods);
258
+		break;
259
+		case 17: /* count */
260
+			return pv_get_sintval(msg, param, res, rpp->nrc);
261
+		break;