[sr-dev] git:master:5a5bc72a: uac_redirect: exported get_redirects() variants to kemi framework

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[sr-dev] git:master:5a5bc72a: uac_redirect: exported get_redirects() variants to kemi framework

Daniel-Constantin Mierla
Module: kamailio
Branch: master
Commit: 5a5bc72a66d2129aae8a8e200c905ff326e9f659
URL: https://github.com/kamailio/kamailio/commit/5a5bc72a66d2129aae8a8e200c905ff326e9f659

Author: Daniel-Constantin Mierla <[hidden email]>
Committer: Daniel-Constantin Mierla <[hidden email]>
Date: 2017-12-06T21:11:44+01:00

uac_redirect: exported get_redirects() variants to kemi framework

---

Modified: src/modules/uac_redirect/uac_redirect.c

---

Diff:  https://github.com/kamailio/kamailio/commit/5a5bc72a66d2129aae8a8e200c905ff326e9f659.diff
Patch: https://github.com/kamailio/kamailio/commit/5a5bc72a66d2129aae8a8e200c905ff326e9f659.patch

---

diff --git a/src/modules/uac_redirect/uac_redirect.c b/src/modules/uac_redirect/uac_redirect.c
index 77da46672e..788829ae6d 100644
--- a/src/modules/uac_redirect/uac_redirect.c
+++ b/src/modules/uac_redirect/uac_redirect.c
@@ -28,6 +28,7 @@
 #include "../../core/mem/mem.h"
 #include "../../lib/srutils/sruid.h"
 #include "../../modules/tm/tm_load.h"
+#include "../../core/kemi.h"
 #include "rd_funcs.h"
 #include "rd_filter.h"
 
@@ -258,6 +259,7 @@ static int redirect_init(void)
 {
  regex_t *filter;
  void *p;
+ cmd_function fct;
 
  /* load the TM API */
  if (load_tm_api(&rd_tmb)!=0) {
@@ -304,6 +306,21 @@ static int redirect_init(void)
  if(sruid_init(&_redirect_sruid, '-', "rdir", SRUID_INC)<0)
  return -1;
 
+ if(rd_acc_fct == 0) {
+ /* import the acc stuff */
+ if(acc_fct_s != 0 && acc_fct_s[0] == '\0') {
+ fct = find_export(acc_fct_s, 2, REQUEST_ROUTE);
+ if(fct == 0)
+ fct = find_export(acc_fct_s, 1, REQUEST_ROUTE);
+ if(fct == 0) {
+ LM_ERR("cannot import %s function; is acc loaded and"
+ " configured\n", acc_fct_s);
+ return E_UNSPEC;
+ }
+ rd_acc_fct = fct;
+ }
+ }
+
  return 0;
 error:
  return -1;
@@ -374,3 +391,83 @@ static int w_get_redirect1(struct sip_msg* msg, char *max_c, char *foo)
  return w_get_redirect2(msg, max_c, 0);
 }
 
+static int ki_get_redirects_acc(sip_msg_t* msg, int max_c, int max_b,
+ str *reason)
+{
+ int n;
+ acc_param_t accp;
+
+ if(reason && reason->len>0) {
+ memset(&accp, 0, sizeof(acc_param_t));
+ accp.reason.s = reason->s;
+ accp.reason.len = reason->len;
+ }
+ msg_tracer(msg, 0);
+ /* get the contacts */
+ n = get_redirect(msg, max_c, max_b, (reason && reason->len>0)?&accp:NULL,
+ bflags);
+ reset_filters();
+ /* reset the tracer */
+ msg_tracer(msg, 1);
+
+ return n;
+}
+
+static int ki_get_redirects(sip_msg_t* msg, int max_c, int max_b)
+{
+ int n;
+
+ msg_tracer(msg, 0);
+ /* get the contacts */
+ n = get_redirect(msg, max_c, max_b, NULL, bflags);
+ reset_filters();
+ /* reset the tracer */
+ msg_tracer(msg, 1);
+
+ return n;
+}
+
+static int ki_get_redirects_all(sip_msg_t* msg)
+{
+ int n;
+
+ msg_tracer(msg, 0);
+ /* get the contacts */
+ n = get_redirect(msg, 0, 0, NULL, bflags);
+ reset_filters();
+ /* reset the tracer */
+ msg_tracer(msg, 1);
+
+ return n;
+}
+
+/**
+ *
+ */
+/* clang-format off */
+static sr_kemi_t sr_kemi_uac_redirect_exports[] = {
+ { str_init("uac_redirect"), str_init("get_redirects_all"),
+ SR_KEMIP_INT, ki_get_redirects_all,
+ { SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
+ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
+ },
+ { str_init("uac_redirect"), str_init("get_redirects"),
+ SR_KEMIP_INT, ki_get_redirects,
+ { SR_KEMIP_INT, SR_KEMIP_INT, SR_KEMIP_NONE,
+ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
+ },
+ { str_init("uac_redirect"), str_init("get_redirects_acc"),
+ SR_KEMIP_INT, ki_get_redirects_acc,
+ { SR_KEMIP_INT, SR_KEMIP_INT, 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_uac_redirect_exports);
+ return 0;
+}
\ No newline at end of file


_______________________________________________
Kamailio (SER) - Development Mailing List
[hidden email]
https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-dev