Browse code

registrar: more functions exported to kemi framework

Daniel-Constantin Mierla authored on 01/05/2017 06:08:28
Showing 3 changed files
... ...
@@ -477,6 +477,18 @@ static int w_lookup_branches(sip_msg_t* _m, char* _d, char* _p2)
477 477
 }
478 478
 
479 479
 
480
+static int ki_lookup_branches(sip_msg_t* _m, str* _dtable)
481
+{
482
+	udomain_t* d;
483
+
484
+	if(ul.get_udomain(_dtable->s, &d)<0) {
485
+		LM_ERR("usrloc domain [%s] not found\n", _dtable->s);
486
+		return -1;
487
+	}
488
+
489
+	return lookup_branches(_m, d);
490
+}
491
+
480 492
 static int w_registered(struct sip_msg* _m, char* _d, char* _uri)
481 493
 {
482 494
 	str uri = {0};
... ...
@@ -488,6 +500,18 @@ static int w_registered(struct sip_msg* _m, char* _d, char* _uri)
488 500
 	return registered(_m, (udomain_t*)_d, (uri.len>0)?&uri:NULL);
489 501
 }
490 502
 
503
+static int ki_registered_uri(sip_msg_t* _m, str* _dtable, str* _uri)
504
+{
505
+	udomain_t* d;
506
+
507
+	if(ul.get_udomain(_dtable->s, &d)<0) {
508
+		LM_ERR("usrloc domain [%s] not found\n", _dtable->s);
509
+		return -1;
510
+	}
511
+
512
+	return registered(_m, d, (_uri && _uri->len>0)?_uri:NULL);
513
+}
514
+
491 515
 static int w_registered3(struct sip_msg* _m, char* _d, char* _uri, char* _flags)
492 516
 {
493 517
 	str uri = {0};
... ...
@@ -505,6 +529,18 @@ static int w_registered3(struct sip_msg* _m, char* _d, char* _uri, char* _flags)
505 529
 	return registered3(_m, (udomain_t*)_d, (uri.len>0)?&uri:NULL, flags);
506 530
 }
507 531
 
532
+static int ki_registered_flags(sip_msg_t* _m, str* _dtable, str* _uri, int _f)
533
+{
534
+	udomain_t* d;
535
+
536
+	if(ul.get_udomain(_dtable->s, &d)<0) {
537
+		LM_ERR("usrloc domain [%s] not found\n", _dtable->s);
538
+		return -1;
539
+	}
540
+
541
+	return registered3(_m, d, (_uri && _uri->len>0)?_uri:NULL, _f);
542
+}
543
+
508 544
 static int w_registered4(struct sip_msg* _m, char* _d, char* _uri, char* _flags, char* _actionflags)
509 545
 {
510 546
 	str uri = {0};
... ...
@@ -528,6 +564,19 @@ static int w_registered4(struct sip_msg* _m, char* _d, char* _uri, char* _flags,
528 564
 	return registered4(_m, (udomain_t*)_d, (uri.len>0)?&uri:NULL, flags, actionflags);
529 565
 }
530 566
 
567
+static int ki_registered_action(sip_msg_t* _m, str* _dtable, str* _uri,
568
+		int _f, int _aflags)
569
+{
570
+	udomain_t* d;
571
+
572
+	if(ul.get_udomain(_dtable->s, &d)<0) {
573
+		LM_ERR("usrloc domain [%s] not found\n", _dtable->s);
574
+		return -1;
575
+	}
576
+
577
+	return registered4(_m, d, (_uri && _uri->len>0)?_uri:NULL, _f, _aflags);
578
+}
579
+
531 580
 static int w_unregister(struct sip_msg* _m, char* _d, char* _uri)
532 581
 {
533 582
 	str uri = {0};
... ...
@@ -540,6 +589,22 @@ static int w_unregister(struct sip_msg* _m, char* _d, char* _uri)
540 589
 	return unregister(_m, (udomain_t*)_d, &uri, NULL);
541 590
 }
542 591
 
592
+static int ki_unregister(sip_msg_t* _m, str* _dtable, str* _uri)
593
+{
594
+	udomain_t* d;
595
+
596
+	if(_uri==NULL || _uri->len<=0) {
597
+		LM_ERR("invalid uri parameter\n");
598
+		return -1;
599
+	}
600
+	if(ul.get_udomain(_dtable->s, &d)<0) {
601
+		LM_ERR("usrloc domain [%s] not found\n", _dtable->s);
602
+		return -1;
603
+	}
604
+
605
+	return unregister(_m, d, _uri, NULL);
606
+}
607
+
543 608
 static int w_unregister2(struct sip_msg* _m, char* _d, char* _uri, char *_ruid)
544 609
 {
545 610
 	str uri = {0, 0};
... ...
@@ -555,10 +620,25 @@ static int w_unregister2(struct sip_msg* _m, char* _d, char* _uri, char *_ruid)
555 620
 		return -1;
556 621
 	}
557 622
 
558
-
559 623
 	return unregister(_m, (udomain_t*)_d, &uri, &ruid);
560 624
 }
561 625
 
626
+static int ki_unregister_ruid(sip_msg_t* _m, str* _dtable, str* _uri, str *_ruid)
627
+{
628
+	udomain_t* d;
629
+
630
+	if(_uri==NULL || _uri->len<=0) {
631
+		LM_ERR("invalid uri parameter\n");
632
+		return -1;
633
+	}
634
+	if(ul.get_udomain(_dtable->s, &d)<0) {
635
+		LM_ERR("usrloc domain [%s] not found\n", _dtable->s);
636
+		return -1;
637
+	}
638
+
639
+	return unregister(_m, d, _uri, _ruid);
640
+}
641
+
562 642
 /*! \brief
563 643
  * Convert char* parameter to udomain_t* pointer
564 644
  */
... ...
@@ -794,12 +874,61 @@ static sr_kemi_t sr_kemi_registrar_exports[] = {
794 874
 		{ SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_NONE,
795 875
 			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
796 876
 	},
877
+	{ str_init("registrar"), str_init("lookup_branches"),
878
+		SR_KEMIP_INT, ki_lookup_branches,
879
+		{ SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
880
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
881
+	},
797 882
 	{ str_init("registrar"), str_init("registered"),
798 883
 		SR_KEMIP_INT, regapi_registered,
799 884
 		{ SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
800 885
 			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
801 886
 	},
802
-
887
+	{ str_init("registrar"), str_init("registered_uri"),
888
+		SR_KEMIP_INT, ki_registered_uri,
889
+		{ SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_NONE,
890
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
891
+	},
892
+	{ str_init("registrar"), str_init("registered_flags"),
893
+		SR_KEMIP_INT, ki_registered_flags,
894
+		{ SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_INT,
895
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
896
+	},
897
+	{ str_init("registrar"), str_init("registered_action"),
898
+		SR_KEMIP_INT, ki_registered_action,
899
+		{ SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_INT,
900
+			SR_KEMIP_INT, SR_KEMIP_NONE, SR_KEMIP_NONE }
901
+	},
902
+	{ str_init("registrar"), str_init("set_q_override"),
903
+		SR_KEMIP_INT, regapi_set_q_override,
904
+		{ SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
905
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
906
+	},
907
+	{ str_init("registrar"), str_init("add_sock_hdr"),
908
+		SR_KEMIP_INT, ki_add_sock_hdr,
909
+		{ SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
910
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
911
+	},
912
+	{ str_init("registrar"), str_init("unregister"),
913
+		SR_KEMIP_INT, ki_unregister,
914
+		{ SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_NONE,
915
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
916
+	},
917
+	{ str_init("registrar"), str_init("unregister_ruid"),
918
+		SR_KEMIP_INT, ki_unregister_ruid,
919
+		{ SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_STR,
920
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
921
+	},
922
+	{ str_init("registrar"), str_init("reg_fetch_contacts"),
923
+		SR_KEMIP_INT, ki_reg_fetch_contacts,
924
+		{ SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_STR,
925
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
926
+	},
927
+	{ str_init("registrar"), str_init("reg_freee_contacts"),
928
+		SR_KEMIP_INT, ki_reg_free_contacts,
929
+		{ SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
930
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
931
+	},
803 932
 	{ {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } }
804 933
 };
805 934
 
... ...
@@ -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};
... ...
@@ -41,7 +41,9 @@ int pv_parse_ulc_name(pv_spec_p sp, str *in);
41 41
 
42 42
 int pv_fetch_contacts(struct sip_msg* msg, char* table, char* uri,
43 43
 		char* profile);
44
+int ki_reg_fetch_contacts(sip_msg_t* msg, str* dtable, str* uri, str* profile);
44 45
 int pv_free_contacts(struct sip_msg* msg, char* profile, char *s2);
46
+int ki_reg_free_contacts(sip_msg_t* msg, str* profile);
45 47
 
46 48
 void regpv_free_profiles(void);
47 49