@lazedo requested changes on this pull request.
thank you for your contribution. some required changes
+ if(faked_msg_init()<0)
+ {
+ LM_ERR("failed to init kazoo local sip msg\n");
+ return -1;
+ }
+
why was this added ?
+ sr_kemi_eng_t *keng = NULL;
+
if(kazoo_event_callback.s!=NULL && kazoo_event_callback.len>0) {
+ keng = sr_kemi_eng_get();
+ if(keng==NULL) {
+ LM_ERR("failed to find kemi engine\n");
+ return -1;
+ }
+ kazoo_route_no=-1;
+ }
+ else {
+ route_no=route_lookup(&event_rt, "kazoo:consumer-event");
+ if (route_no==-1)
+ {
+ LM_ERR("failed to find event_route[kazoo:consumer-event]\n");
+ return -1;
+ }
+ if (event_rt.rlist[route_no]==0)
+ {
+ LM_WARN("event_route[kazoo:consumer-event] is empty\n");
+ }
+ kazoo_route_no=route_no;
+ }
+
+
please use a different logic here. `kazoo:consumer-event` is not mandatory. you could set
a variable like `kz_use_kemi` that is set if `kazoo_event_callback` is set and `kemi` is
valid. then use that variable when needed
+ if (kazoo_route_no>=0) {
+ rt =
route_get(&event_rt, "kazoo:mod-init");
+ if(rt>=0 && event_rt.rlist[rt]!=NULL) {
+ LM_DBG("executing event_route[kazoo:mod-init] (%d)\n", rt);
formatting looks odd
+ if (kazoo_route_no>=0) {
sprintf(buffer, "kazoo:consumer-event-%.*s-%.*s",ev_category.len, ev_category.s,
ev_name.len, ev_name.s);
- for (p=buffer ; *p; ++p) *p = tolower(*p);
- for (p=buffer ; *p; ++p) if(*p == '_') *p = '-';
- if(kz_amqp_consumer_fire_event(buffer) != 0) {
- sprintf(buffer, "kazoo:consumer-event-%.*s",ev_category.len,
ev_category.s);
for (p=buffer ; *p; ++p) *p = tolower(*p);
for (p=buffer ; *p; ++p) if(*p == '_') *p = '-';
if(kz_amqp_consumer_fire_event(buffer) != 0) {
- sprintf(buffer, "kazoo:consumer-event-%s-%s", key, subkey);
+ sprintf(buffer, "kazoo:consumer-event-%.*s",ev_category.len,
ev_category.s);
for (p=buffer ; *p; ++p) *p = tolower(*p);
for (p=buffer ; *p; ++p) if(*p == '_') *p = '-';
if(kz_amqp_consumer_fire_event(buffer) != 0) {
- sprintf(buffer, "kazoo:consumer-event-%s", key);
+ sprintf(buffer, "kazoo:consumer-event-%s-%s", key, subkey);
for (p=buffer ; *p; ++p) *p = tolower(*p);
for (p=buffer ; *p; ++p) if(*p == '_') *p = '-';
- if(kz_amqp_consumer_fire_event(buffer) != 0) {
- sprintf(buffer, "kazoo:consumer-event");
- if(kz_amqp_consumer_fire_event(buffer) != 0) {
- LM_ERR("kazoo:consumer-event not found\n");
- }
- }
+ if(kz_amqp_consumer_fire_event(buffer) != 0) {
+ sprintf(buffer, "kazoo:consumer-event-%s", key);
+ for (p=buffer ; *p; ++p) *p = tolower(*p);
+ for (p=buffer ; *p; ++p) if(*p == '_') *p = '-';
+ if(kz_amqp_consumer_fire_event(buffer) != 0) {
+ sprintf(buffer, "kazoo:consumer-event");
+ if(kz_amqp_consumer_fire_event(buffer) != 0) {
+ LM_ERR("kazoo:consumer-event not found\n");
+ }
+ }
+ }
}
}
+ } else {
+ keng = sr_kemi_eng_get();
+ if(keng!=NULL) {
+ sip_msg_t *msg;
+ str evrtname = str_init("kazoo:consumer-event");
+
+ rtb = get_route_type();
+ msg = faked_msg_next();
+ if(sr_kemi_route(keng, msg, EVENT_ROUTE, &kazoo_event_callback,
&evrtname)<0) {
+ LM_ERR("error running event route kemi callback\n");
+ }
+ set_route_type(rtb);
+ } else {
+ LM_ERR("no event route or kemi callback found for execution\n");
+ }
}
+
split this in two different functions that are evoked depending on `kemi` being active
- rt = route_get(&event_rt,
"kazoo:mod-init");
- if(rt>=0 && event_rt.rlist[rt]!=NULL) {
- LM_DBG("executing event_route[kazoo:mod-init] (%d)\n", rt);
- if(faked_msg_init()<0)
- return -1;
- fmsg = faked_msg_next();
- rtb = get_route_type();
- set_route_type(REQUEST_ROUTE);
- init_run_actions_ctx(&ctx);
- run_top_route(event_rt.rlist[rt], fmsg, &ctx);
- if(ctx.run_flags&DROP_R_F)
- {
- LM_ERR("exit due to 'drop' in event route\n");
- return -1;
+ if (kazoo_route_no>=0) {
+ rt = route_get(&event_rt, "kazoo:mod-init");
+ if(rt>=0 && event_rt.rlist[rt]!=NULL) {
+ LM_DBG("executing event_route[kazoo:mod-init] (%d)\n", rt);
+ if(faked_msg_init()<0)
+ return -1;
+ fmsg = faked_msg_next();
+ rtb = get_route_type();
+ set_route_type(REQUEST_ROUTE);
+ init_run_actions_ctx(&ctx);
+ run_top_route(event_rt.rlist[rt], fmsg, &ctx);
+ if(ctx.run_flags&DROP_R_F)
+ {
+ LM_ERR("exit due to 'drop' in event route\n");
+ return -1;
+ }
+ set_route_type(rtb);
+ }
+ }
+ else {
+ keng = sr_kemi_eng_get();
+ if(keng!=NULL) {
+ sip_msg_t *msg;
+ str evrtname = str_init("kazoo:mod-init");
+ rtb = get_route_type();
+ msg = faked_msg_next();
+ if(sr_kemi_route(keng, msg, EVENT_ROUTE, &kazoo_event_callback,
&evrtname)<0) {
+ LM_ERR("error running event route kemi callback\n");
+ }
+ set_route_type(rtb);
+ }
+ else {
+ LM_ERR("no event route or kemi callback found for execution\n");
split this in two different function that are evoked by `fire_init_event` depending on
`kemi` being active
--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/kamailio/kamailio/pull/2324#pullrequestreview-414207173