[sr-dev] git:5.1:1007b74b: ldap: use core fixup function for ldap_search()

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

[sr-dev] git:5.1:1007b74b: ldap: use core fixup function for ldap_search()

Daniel-Constantin Mierla
Module: kamailio
Branch: 5.1
Commit: 1007b74b66267c31d12b60c53b231e73e74b0931
URL: https://github.com/kamailio/kamailio/commit/1007b74b66267c31d12b60c53b231e73e74b0931

Author: Daniel-Constantin Mierla <[hidden email]>
Committer: Daniel-Constantin Mierla <[hidden email]>
Date: 2017-12-04T09:25:33+01:00

ldap: use core fixup function for ldap_search()

(cherry picked from commit 209032fc134afb90e4e12b194d1368ed9fb67ee9)

---

Modified: src/modules/ldap/ldap_exp_fn.c
Modified: src/modules/ldap/ldap_exp_fn.h
Modified: src/modules/ldap/ldap_mod.c

---

Diff:  https://github.com/kamailio/kamailio/commit/1007b74b66267c31d12b60c53b231e73e74b0931.diff
Patch: https://github.com/kamailio/kamailio/commit/1007b74b66267c31d12b60c53b231e73e74b0931.patch

---

diff --git a/src/modules/ldap/ldap_exp_fn.c b/src/modules/ldap/ldap_exp_fn.c
index 77a92c2bf7..c68e00895e 100644
--- a/src/modules/ldap/ldap_exp_fn.c
+++ b/src/modules/ldap/ldap_exp_fn.c
@@ -52,31 +52,22 @@ static char esc_buf[ESC_BUF_SIZE];
 * exported functions
 */
 
-int ldap_search_impl(struct sip_msg *_msg, pv_elem_t *_ldap_url)
+int ldap_search_impl(struct sip_msg *_msg, str *ldap_url)
 {
- str ldap_url;
  int ld_result_count = 0;
 
  /*
  * do variable substitution for _ldap_url (pv_printf_s)
  */
- if(_ldap_url == NULL) {
+ if(ldap_url == NULL || ldap_url->s==NULL || ldap_url->len<=0) {
  LM_ERR("empty ldap_url\n");
  return -2;
  }
- if(_ldap_url->spec != NULL && _ldap_url->spec->getf != NULL) {
- if(pv_printf_s(_msg, _ldap_url, &ldap_url) != 0 || ldap_url.len <= 0) {
- LM_ERR("pv_printf_s failed\n");
- return -2;
- }
- } else {
- ldap_url = _ldap_url->text;
- }
 
  /*
  * perform LDAP search
  */
- if(ldap_url_search(ldap_url.s, &ld_result_count) != 0) {
+ if(ldap_url_search(ldap_url->s, &ld_result_count) != 0) {
  /* LDAP search error */
  return -2;
  }
diff --git a/src/modules/ldap/ldap_exp_fn.h b/src/modules/ldap/ldap_exp_fn.h
index 695dbc198e..20d4149de6 100644
--- a/src/modules/ldap/ldap_exp_fn.h
+++ b/src/modules/ldap/ldap_exp_fn.h
@@ -47,7 +47,7 @@ struct ldap_result_check_params
  pv_elem_p check_str_elem_p;
 };
 
-int ldap_search_impl(struct sip_msg *_msg, pv_elem_t *_ldap_url);
+int ldap_search_impl(struct sip_msg *_msg, str *ldap_url);
 
 int ldap_write_result(struct sip_msg *_msg, struct ldap_result_params *_lrp,
  struct subst_expr *_se);
diff --git a/src/modules/ldap/ldap_mod.c b/src/modules/ldap/ldap_mod.c
index f167bcadbb..2364f0a7cf 100644
--- a/src/modules/ldap/ldap_mod.c
+++ b/src/modules/ldap/ldap_mod.c
@@ -33,6 +33,7 @@
 #include "../../core/parser/hf.h"
 #include "../../core/sr_module.h"
 #include "../../core/pvar.h"
+#include "../../core/mod_fix.h"
 #include "../../core/mem/mem.h"
 
 #include "ld_session.h"
@@ -54,7 +55,6 @@ static int child_init(int rank);
 /*
 * fixup functions
 */
-static int ldap_search_fixup(void **param, int param_no);
 static int ldap_result_fixup(void **param, int param_no);
 static int ldap_filter_url_encode_fixup(void **param, int param_no);
 static int ldap_result_check_fixup(void **param, int param_no);
@@ -92,7 +92,7 @@ static dictionary *config_vals = NULL;
 /* clang-format off */
 static cmd_export_t cmds[] = {
  {"ldap_search",            (cmd_function)w_ldap_search,            1,
- ldap_search_fixup, 0,
+ fixup_spve_null, 0,
  REQUEST_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE|ONREPLY_ROUTE|LOCAL_ROUTE},
  {"ldap_result",            (cmd_function)w_ldap_result1,           1,
  ldap_result_fixup, 0,
@@ -246,7 +246,13 @@ static void destroy(void)
 
 static int w_ldap_search(struct sip_msg *msg, char *ldap_url, char *param)
 {
- return ldap_search_impl(msg, (pv_elem_t *)ldap_url);
+ str ldap_url_val = STR_NULL;
+
+ if(fixup_get_svalue(msg, (gparam_t*)ldap_url, &ldap_url_val)<0) {
+ LM_ERR("failed to get ldap url parameter\n");
+ return -1;
+ }
+ return ldap_search_impl(msg, &ldap_url_val);
 }
 
 static int w_ldap_result1(struct sip_msg *msg, char *src, char *param)
@@ -291,28 +297,6 @@ static int w_ldap_result_check_2(
 * FIXUP functions
 */
 
-static int ldap_search_fixup(void **param, int param_no)
-{
- pv_elem_t *model;
- str s;
-
- if(param_no == 1) {
- s.s = (char *)*param;
- s.len = strlen(s.s);
- if(s.len == 0) {
- LM_ERR("ldap url is empty string!\n");
- return E_CFG;
- }
- if(pv_parse_format(&s, &model) || model == NULL) {
- LM_ERR("wrong format [%s] for ldap url!\n", s.s);
- return E_CFG;
- }
- *param = (void *)model;
- }
-
- return 0;
-}
-
 static int ldap_result_fixup(void **param, int param_no)
 {
  struct ldap_result_params *lp;


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