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 2 changed files
... ...
@@ -126,6 +126,9 @@ str sock_hdr_name = {0,0};
126 126
 
127 127
 /* where to go for event route ("usrloc:contact-expired") */
128 128
 int reg_expire_event_rt = -1; /* default disabled */
129
+str reg_event_callback = STR_NULL;
130
+
131
+sr_kemi_eng_t *keng = NULL;
129 132
 
130 133
 #define RCV_NAME "received"
131 134
 str rcv_param = str_init(RCV_NAME);
... ...
@@ -228,6 +231,7 @@ static param_export_t params[] = {
228 231
 	{"regid_mode",         INT_PARAM, &reg_regid_mode					},
229 232
 	{"flow_timer",         INT_PARAM, &reg_flow_timer					},
230 233
 	{"contact_max_size",   INT_PARAM, &contact_max_size					},
234
+	{"event_callback",     PARAM_STR, &reg_event_callback				},
231 235
 	{0, 0, 0}
232 236
 };
233 237
 
... ...
@@ -339,12 +343,19 @@ static int mod_init(void)
339 343
 		return -1;
340 344
 	}
341 345
 
342
-	if(ul.register_ulcb != NULL)
343
-	{
344
-		reg_expire_event_rt = route_lookup(&event_rt, "usrloc:contact-expired");
345
-		if (reg_expire_event_rt>=0 && event_rt.rlist[reg_expire_event_rt]==0)
346
-			reg_expire_event_rt=-1; /* disable */
347
-		if (reg_expire_event_rt>=0) {
346
+	if(ul.register_ulcb != NULL) {
347
+		if (reg_event_callback.s==NULL || reg_event_callback.len<=0 ) {
348
+			reg_expire_event_rt = route_lookup(&event_rt, "usrloc:contact-expired");
349
+			if (reg_expire_event_rt>=0 && event_rt.rlist[reg_expire_event_rt]==0)
350
+				reg_expire_event_rt=-1; /* disable */
351
+		} else {
352
+			keng = sr_kemi_eng_get();
353
+			if(keng==NULL) {
354
+				LM_DBG("event callback (%s) set, but no cfg engine\n",
355
+					reg_event_callback.s);
356
+			}
357
+		}
358
+		if (reg_expire_event_rt>=0 || (reg_event_callback.s!=NULL && keng !=NULL)) {
348 359
 			set_child_rpc_sip_mode();
349 360
 			if(ul.register_ulcb(UL_CONTACT_EXPIRE, reg_ul_expired_contact, 0)< 0)
350 361
 			{
... ...
@@ -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; }