Module: kamailio
Branch: master
Commit: 1e3f1886cef43fcbf6cdd6f1cefb5b72e5151abc
URL:
https://github.com/kamailio/kamailio/commit/1e3f1886cef43fcbf6cdd6f1cefb5b7…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2022-09-30T11:35:53+02:00
carrierroute: exported cr_user_carrier() to kemi
---
Modified: src/modules/carrierroute/carrierroute.c
Modified: src/modules/carrierroute/cr_func.c
Modified: src/modules/carrierroute/cr_func.h
---
Diff:
https://github.com/kamailio/kamailio/commit/1e3f1886cef43fcbf6cdd6f1cefb5b7…
Patch:
https://github.com/kamailio/kamailio/commit/1e3f1886cef43fcbf6cdd6f1cefb5b7…
---
diff --git a/src/modules/carrierroute/carrierroute.c
b/src/modules/carrierroute/carrierroute.c
index b1d6b986bd..68fa793971 100644
--- a/src/modules/carrierroute/carrierroute.c
+++ b/src/modules/carrierroute/carrierroute.c
@@ -39,6 +39,7 @@
#include "../../core/str.h"
#include "../../core/mem/mem.h"
#include "../../core/ut.h" /* for user2uid() */
+#include "../../core/kemi.h"
#include "carrierroute.h"
#include "cr_fixup.h"
#include "cr_map.h"
@@ -270,3 +271,28 @@ static void mod_destroy(void) {
}
destroy_route_data();
}
+
+
+/**
+ *
+ */
+/* clang-format off */
+static sr_kemi_t sr_kemi_carrierroute_exports[] = {
+ { str_init("carrierroute"), str_init("cr_user_carrier"),
+ SR_KEMIP_INT, ki_cr_load_user_carrier,
+ { SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_STR,
+ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
+ },
+
+ { {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } }
+};
+/* clang-format on */
+
+/**
+ *
+ */
+int mod_register(char *path, int *dlflags, void *p1, void *p2)
+{
+ sr_kemi_modules_add(sr_kemi_carrierroute_exports);
+ return 0;
+}
diff --git a/src/modules/carrierroute/cr_func.c b/src/modules/carrierroute/cr_func.c
index e4e7fc1c41..90875a8df0 100644
--- a/src/modules/carrierroute/cr_func.c
+++ b/src/modules/carrierroute/cr_func.c
@@ -722,6 +722,48 @@ int cr_do_route(struct sip_msg * _msg, gparam_t *_carrier,
}
+/**
+ *
+ */
+int ki_cr_load_user_carrier_helper(struct sip_msg *_msg,
+ str *user, str *domain, pv_spec_t *dvar) {
+ pv_value_t val = {0};
+
+ /* get carrier id */
+ if ((val.ri = load_user_carrier(user, domain)) < 0) {
+ LM_ERR("error in load user carrier");
+ return -1;
+ } else {
+ /* set var */
+ val.flags = PV_VAL_INT|PV_TYPE_INT;
+ if(dvar->setf(_msg, &dvar->pvp, (int)EQ_T, &val)<0) {
+ LM_ERR("failed setting dst var\n");
+ return -1;
+ }
+ }
+ return 1;
+}
+
+/**
+ *
+ */
+int ki_cr_load_user_carrier(struct sip_msg *_msg,
+ str *user, str *domain, str *dstvar) {
+ pv_spec_t *dst;
+
+ dst = pv_cache_get(dstvar);
+ if(dst==NULL) {
+ LM_ERR("failed to get pv spec for: %.*s\n", dstvar->len, dstvar->s);
+ return -1;
+ }
+ if(dst->setf==NULL) {
+ LM_ERR("target pv is not writable: %.*s\n", dstvar->len, dstvar->s);
+ return -1;
+ }
+
+ return ki_cr_load_user_carrier_helper(_msg, user, domain, dst);
+}
+
/**
* Loads user carrier from subscriber table and stores it in an AVP.
*
@@ -735,8 +777,6 @@ int cr_do_route(struct sip_msg * _msg, gparam_t *_carrier,
int cr_load_user_carrier(struct sip_msg * _msg,
char *_user, char *_domain, char *_dstvar) {
str user, domain;
- pv_spec_t *dst;
- pv_value_t val = {0};
if (fixup_get_svalue(_msg, (gparam_t*)_user, &user)<0) {
LM_ERR("cannot print the user\n");
@@ -747,22 +787,10 @@ int cr_load_user_carrier(struct sip_msg * _msg,
LM_ERR("cannot print the domain\n");
return -1;
}
- /* get carrier id */
- if ((val.ri = load_user_carrier(&user, &domain)) < 0) {
- LM_ERR("error in load user carrier");
- return -1;
- } else {
- /* set var */
- dst = (pv_spec_t *)_dstvar;
- val.flags = PV_VAL_INT|PV_TYPE_INT;
- if(dst->setf(_msg, &dst->pvp, (int)EQ_T, &val)<0) {
- LM_ERR("failed setting dst var\n");
- return -1;
- }
- }
- return 1;
-}
+ return ki_cr_load_user_carrier_helper(_msg, &user, &domain,
+ (pv_spec_t*)_dstvar);
+}
/**
* rewrites the request URI of msg after determining the
diff --git a/src/modules/carrierroute/cr_func.h b/src/modules/carrierroute/cr_func.h
index 1fc7343611..b2e861ac76 100644
--- a/src/modules/carrierroute/cr_func.h
+++ b/src/modules/carrierroute/cr_func.h
@@ -49,6 +49,9 @@ int cr_load_user_carrier(struct sip_msg * _msg, char *_user,
char *_domain, char *_dstavp);
+int ki_cr_load_user_carrier(struct sip_msg *_msg,
+ str *user, str *domain, str *dstvar);
+
/**
* rewrites the request URI of msg after determining the
* new destination URI