From 4137c5a09299012a3c3ae2e6085c140790f4403d Mon Sep 17 00:00:00 2001 From: Vlad Patrascu Date: Tue, 2 Apr 2019 13:24:17 +0300 Subject: [PATCH] ldap: port script functions to new param interface --- modules/ldap/api.h | 2 +- modules/ldap/ldap_api_fn.c | 28 +++- modules/ldap/ldap_api_fn.h | 2 +- modules/ldap/ldap_exp_fn.c | 128 ++++----------- modules/ldap/ldap_exp_fn.h | 35 +--- modules/ldap/ldap_mod.c | 329 ++++++++----------------------------- 6 files changed, 133 insertions(+), 391 deletions(-) diff --git a/modules/ldap/api.h b/modules/ldap/api.h index 97e9b9c5422..0d5aaa1160f 100644 --- a/modules/ldap/api.h +++ b/modules/ldap/api.h @@ -96,7 +96,7 @@ static inline int load_ldap_api(ldap_api_t *api) { load_ldap_t load_ldap; - if (!(load_ldap = (load_ldap_t) find_export("load_ldap", 0, 0))) + if (!(load_ldap = (load_ldap_t) find_export("load_ldap", 0))) { LM_ERR("can't import load_ldap\n"); return -1; diff --git a/modules/ldap/ldap_api_fn.c b/modules/ldap/ldap_api_fn.c index 57bdea59a94..d41708c04ec 100644 --- a/modules/ldap/ldap_api_fn.c +++ b/modules/ldap/ldap_api_fn.c @@ -377,7 +377,7 @@ int ldap_params_search( int ldap_url_search_async( - char* _ldap_url, + str* _ldap_url, int* _msgidp, struct ld_session **ldsp, struct ld_conn** conn, @@ -385,19 +385,25 @@ int ldap_url_search_async( { LDAPURLDesc *ludp; int rc; + str ldap_url_nt; - if (ldap_url_parse(_ldap_url, &ludp) != 0) { - LM_ERR("invalid LDAP URL [%s]\n", ZSW(_ldap_url)); + if (pkg_nt_str_dup(&ldap_url_nt, _ldap_url) < 0) { + LM_ERR("no more pkg memory\n"); + return -2; + } + + if (ldap_url_parse(ldap_url_nt.s, &ludp) != 0) { + LM_ERR("invalid LDAP URL [%s]\n", ldap_url_nt.s); if (ludp != NULL) { ldap_free_urldesc(ludp); } - return -2; + goto error; } if (ludp->lud_host == NULL) { LM_ERR( "no ldap session name found in ldap URL [%s]\n", - ZSW(_ldap_url)); - return -2; + ldap_url_nt.s); + goto error; } @@ -418,6 +424,7 @@ int ldap_url_search_async( if ((rc == 0 && *_msgidp >= 0) || rc == 1) { if (get_connected_ldap_session(ludp->lud_host, ldsp)) { LM_ERR("[%s]: couldn't get ldap session\n", ludp->lud_host); + pkg_free(ldap_url_nt.s); return -1; } } @@ -427,13 +434,18 @@ int ldap_url_search_async( *ld_result_count = ldap_count_entries((*ldsp)->conn_s.handle, last_ldap_result); if (*ld_result_count < 0) { LM_ERR("[%s]: ldap_count_entries for sync call failed\n", (*ldsp)->name); + pkg_free(ldap_url_nt.s); return -1; } } ldap_free_urldesc(ludp); + pkg_free(ldap_url_nt.s); return rc; +error: + pkg_free(ldap_url_nt.s); + return -2; } @@ -446,7 +458,7 @@ int ldap_url_search( int rc; if (ldap_url_parse(_ldap_url, &ludp) != 0) { - LM_ERR("invalid LDAP URL [%s]\n", ZSW(_ldap_url)); + LM_ERR("invalid LDAP URL [%s]\n", _ldap_url); if (ludp != NULL) { ldap_free_urldesc(ludp); } @@ -455,7 +467,7 @@ int ldap_url_search( if (ludp->lud_host == NULL) { LM_ERR( "no ldap session name found in ldap URL [%s]\n", - ZSW(_ldap_url)); + _ldap_url); return -2; } diff --git a/modules/ldap/ldap_api_fn.h b/modules/ldap/ldap_api_fn.h index 9ec0b8302eb..761dcb6f731 100644 --- a/modules/ldap/ldap_api_fn.h +++ b/modules/ldap/ldap_api_fn.h @@ -68,7 +68,7 @@ int ldap_params_search( ...); int ldap_url_search_async( - char* _ldap_url, + str* _ldap_url, int* _msgidp, struct ld_session **ldsp, struct ld_conn** conn, diff --git a/modules/ldap/ldap_exp_fn.c b/modules/ldap/ldap_exp_fn.c index 6a491fc7bd6..8eac12b7c0a 100644 --- a/modules/ldap/ldap_exp_fn.c +++ b/modules/ldap/ldap_exp_fn.c @@ -65,6 +65,7 @@ int resume_ldap_search(int fd, struct sip_msg *msg, void *param) switch (rc) { case -1: /* error */ + pkg_free(as_params->ldap_url.s); pkg_free(as_params); return -1; case 0: @@ -73,6 +74,7 @@ int resume_ldap_search(int fd, struct sip_msg *msg, void *param) return 1; case 1: /* successfull */ + pkg_free(as_params->ldap_url.s); pkg_free(as_params); async_status = ASYNC_DONE; @@ -95,9 +97,8 @@ int resume_ldap_search(int fd, struct sip_msg *msg, void *param) int ldap_search_impl_async( struct sip_msg* _msg, async_ctx *ctx, - pv_elem_t* _ldap_url) + str* ldap_url) { - str ldap_url; int msgid; int sockfd; int rc=-1; @@ -106,26 +107,10 @@ int ldap_search_impl_async( struct ld_session *lds; struct ld_conn* conn; - /* - * do variable substitution for _ldap_url (pv_printf_s) - */ - if (_ldap_url==NULL) { - LM_ERR("empty ldap_url\n"); - return -2; - } - if ( _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 ((rc=ldap_url_search_async(ldap_url.s, &msgid, &lds, &conn, &ld_result_count)) < 0) + if ((rc=ldap_url_search_async(ldap_url, &msgid, &lds, &conn, &ld_result_count)) < 0) { /* LDAP search error */ rc = -2; @@ -160,9 +145,12 @@ int ldap_search_impl_async( } as_params->msgid = msgid; - as_params->ldap_url = ldap_url; as_params->lds = lds; as_params->conn = conn; + if (pkg_nt_str_dup(&as_params->ldap_url, ldap_url) < 0) { + LM_ERR("no more pkg mem\n"); + goto error; + } ctx->resume_param = as_params; ctx->resume_f = resume_ldap_search;/* resume function */ @@ -178,35 +166,28 @@ int ldap_search_impl_async( int ldap_search_impl( struct sip_msg* _msg, - pv_elem_t* _ldap_url) + str* ldap_url) { - str ldap_url; int ld_result_count = 0; + str ldap_url_nt; - /* - * do variable substitution for _ldap_url (pv_printf_s) - */ - if (_ldap_url==NULL) { - LM_ERR("empty ldap_url\n"); + if (pkg_nt_str_dup(&ldap_url_nt, ldap_url) < 0) { + LM_ERR("no more pkg memory\n"); return -2; } - if ( _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_nt.s, &ld_result_count) != 0) { /* LDAP search error */ + pkg_free(ldap_url_nt.s); return -2; } + + pkg_free(ldap_url_nt.s); + if (ld_result_count < 1) { /* no LDAP entry found */ @@ -216,10 +197,8 @@ int ldap_search_impl( return ld_result_count; } -int ldap_write_result( - struct sip_msg* _msg, - struct ldap_result_params* _lrp, - struct subst_expr* _se) +int ldap_write_result( struct sip_msg* _msg, str *attr_name, pv_spec_t *dst_avp, + int avp_type, struct subst_expr* _se) { int dst_avp_name; int_str dst_avp_val; @@ -234,7 +213,7 @@ int ldap_write_result( */ if (pv_get_avp_name( _msg, - &(_lrp->dst_avp_spec.pvp), + &dst_avp->pvp, &dst_avp_name, &dst_avp_type) != 0) @@ -246,7 +225,7 @@ int ldap_write_result( /* * get LDAP attr values */ - if ((rc = ldap_get_attr_vals(&_lrp->ldap_attr_name, &attr_vals)) != 0) + if ((rc = ldap_get_attr_vals(attr_name, &attr_vals)) != 0) { if (rc > 0) { return -1; @@ -276,7 +255,7 @@ int ldap_write_result( avp_val_str = *subst_result; } - if (_lrp->dst_avp_val_type == 1) + if (avp_type == 1) { /* try to convert ldap value to integer */ if (!str2sint(&avp_val_str, &avp_val_int)) @@ -338,40 +317,19 @@ int ldap_result_next(void) } } -int ldap_result_check( - struct sip_msg* _msg, - struct ldap_result_check_params* _lrp, - struct subst_expr* _se) +int ldap_result_check(struct sip_msg* _msg, str* attr_name, str *check_str, + struct subst_expr *_se) { - str check_str, *subst_result = NULL; + str *subst_result = NULL; int rc, i, nmatches; - char *attr_val; + str attr_val; struct berval **attr_vals; - /* - * do variable substitution for check_str - */ - - if (_lrp->check_str_elem_p) - { - if (pv_printf_s(_msg, _lrp->check_str_elem_p, &check_str) != 0) - { - LM_ERR("pv_printf_s failed\n"); - return -2; - } - } else - { - LM_ERR("empty check string\n"); - return -2; - } - - LM_DBG("check_str [%s]\n", check_str.s); - /* * get LDAP attr values */ - if ((rc = ldap_get_attr_vals(&_lrp->ldap_attr_name, &attr_vals)) != 0) + if ((rc = ldap_get_attr_vals(attr_name, &attr_vals)) != 0) { if (rc > 0) { return -1; @@ -388,7 +346,8 @@ int ldap_result_check( { if (_se == NULL) { - attr_val = attr_vals[i]->bv_val; + attr_val.s = attr_vals[i]->bv_val; + attr_val.len = strlen(attr_val.s); } else { subst_result = subst_str(attr_vals[i]->bv_val, _msg, _se, @@ -397,11 +356,11 @@ int ldap_result_check( { continue; } - attr_val = subst_result->s; + attr_val = *subst_result; } - LM_DBG("attr_val [%s]\n", attr_val); - rc = strncmp(check_str.s, attr_val, check_str.len); + LM_DBG("attr_val [%.*s]\n", attr_val.len, attr_val.s); + rc = str_strcmp(check_str, &attr_val); if (_se != NULL) { pkg_free(subst_result->s); @@ -417,28 +376,13 @@ int ldap_result_check( return -1; } -int ldap_filter_url_encode( - struct sip_msg* _msg, - pv_elem_t* _filter_component, - pv_spec_t* _dst_avp_spec) +int ldap_filter_url_encode(struct sip_msg* _msg, str *filter_component, + pv_spec_t* _dst_avp_spec) { - str filter_component_str, esc_str; + str esc_str; int dst_avp_name; unsigned short dst_avp_type; - /* - * variable substitution for _filter_component - */ - if (_filter_component) { - if (pv_printf_s(_msg, _filter_component, &filter_component_str) != 0) { - LM_ERR("pv_printf_s failed\n"); - return -1; - } - } else { - LM_ERR("empty first argument\n"); - return -1; - } - /* * get dst AVP name (dst_avp_name) */ @@ -454,7 +398,7 @@ int ldap_filter_url_encode( */ esc_str.s = esc_buf; esc_str.len = ESC_BUF_SIZE; - if (ldap_rfc4515_escape(&filter_component_str, &esc_str, 1) != 0) + if (ldap_rfc4515_escape(filter_component, &esc_str, 1) != 0) { LM_ERR("ldap_rfc4515_escape() failed\n"); return -1; diff --git a/modules/ldap/ldap_exp_fn.h b/modules/ldap/ldap_exp_fn.h index adaf69ff23a..3f172ae23a0 100644 --- a/modules/ldap/ldap_exp_fn.h +++ b/modules/ldap/ldap_exp_fn.h @@ -38,19 +38,6 @@ #include "../../re.h" #include "ld_session.h" -struct ldap_result_params -{ - str ldap_attr_name; - int dst_avp_val_type; /* 0: str, 1: int */ - pv_spec_t dst_avp_spec; -}; - -struct ldap_result_check_params -{ - str ldap_attr_name; - pv_elem_p check_str_elem_p; -}; - struct ldap_async_params { int msgid; str ldap_url; @@ -61,32 +48,26 @@ struct ldap_async_params { int ldap_search_impl_async( struct sip_msg* _msg, async_ctx *ctx, - pv_elem_t* _ldap_url); + str* _ldap_url); int ldap_search_impl( struct sip_msg* _msg, - pv_elem_t* _ldap_url); + str* _ldap_url); -int ldap_write_result( - struct sip_msg* _msg, - struct ldap_result_params* _lrp, - struct subst_expr* _se); +int ldap_write_result( struct sip_msg* _msg, str *attr_name, pv_spec_t *dst_avp, + int avp_type, struct subst_expr* _se); int ldap_result_next(); -int ldap_filter_url_encode( - struct sip_msg* _msg, - pv_elem_t* _filter_component, - pv_spec_t* _dst_avp_spec); +int ldap_filter_url_encode(struct sip_msg* _msg, str *filter_component, + pv_spec_t* _dst_avp_spec); int rfc2254_escape( struct sip_msg* _msg, char* _value, char* _avp_name); -int ldap_result_check( - struct sip_msg* _msg, - struct ldap_result_check_params* _lrp, - struct subst_expr* _se); +int ldap_result_check(struct sip_msg* _msg, str* attr_name, str *check_str, + struct subst_expr *_se); #endif /* LDAP_EXP_FN_H */ diff --git a/modules/ldap/ldap_mod.c b/modules/ldap/ldap_mod.c index d64cf02112f..8202ff94f6b 100644 --- a/modules/ldap/ldap_mod.c +++ b/modules/ldap/ldap_mod.c @@ -57,27 +57,22 @@ 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); +static int fixup_result_avp_type(void **param); +static int fixup_substre(void** param); /* * exported functions */ -static int w_ldap_search_async(struct sip_msg* msg, async_ctx *ctx, - char* ldap_url, char* param); -static int w_ldap_search(struct sip_msg* msg, char* ldap_url, char* param); -static int w_ldap_result1(struct sip_msg* msg, char* src, char* param); -static int w_ldap_result2(struct sip_msg* msg, char* src, char* subst); -static int w_ldap_result_next(struct sip_msg* msg, char* foo, char *bar); +static int w_ldap_search_async(struct sip_msg* msg, async_ctx *ctx, str* ldap_url); +static int w_ldap_search(struct sip_msg* msg, str* ldap_url); +static int w_ldap_result(struct sip_msg* msg, str *attr_name, + pv_spec_t *dst_avp, void *avp_type, struct subst_expr *subst); +static int w_ldap_result_next(struct sip_msg* msg); static int w_ldap_filter_url_encode(struct sip_msg* msg, - char* filter_component, char* dst_avp_name); -static int w_ldap_result_check_1(struct sip_msg* msg, - char* attr_name_check_str, char* param); -static int w_ldap_result_check_2(struct sip_msg* msg, - char* attr_name_check_str, char* attr_val_re); + str* filter_component, pv_spec_t* dst_avp_name); +static int w_ldap_result_check(struct sip_msg* msg, str* attr_name, + str *check_str, struct subst_expr *subst); /* @@ -93,38 +88,39 @@ str ldap_config = str_init(DEF_LDAP_CONFIG); static dictionary* config_vals = NULL; static acmd_export_t acmds[] = { - {"ldap_search", (acmd_function) w_ldap_search_async, 1, ldap_search_fixup}, - {0, 0, 0, 0} + {"ldap_search", (acmd_function)w_ldap_search_async, { + {CMD_PARAM_STR, 0, 0}, {0,0,0}}}, + {0,0,{{0,0,0}}} }; -/* -* Exported functions -*/ + static cmd_export_t cmds[] = { - {"ldap_search", (cmd_function)w_ldap_search, 1, - ldap_search_fixup, 0, REQUEST_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE| - ONREPLY_ROUTE|LOCAL_ROUTE|STARTUP_ROUTE|TIMER_ROUTE|EVENT_ROUTE}, - {"ldap_result", (cmd_function)w_ldap_result1, 1, - ldap_result_fixup, 0, REQUEST_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE| + {"ldap_search", (cmd_function)w_ldap_search, { + {CMD_PARAM_STR, 0, 0}, {0,0,0}}, + REQUEST_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE| ONREPLY_ROUTE|LOCAL_ROUTE|STARTUP_ROUTE|TIMER_ROUTE|EVENT_ROUTE}, - {"ldap_result", (cmd_function)w_ldap_result2, 2, - ldap_result_fixup, 0, REQUEST_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE| + {"ldap_result", (cmd_function)w_ldap_result, { + {CMD_PARAM_STR, 0, 0}, + {CMD_PARAM_VAR, 0, 0}, + {CMD_PARAM_STR | CMD_PARAM_OPT, fixup_result_avp_type, 0}, + {CMD_PARAM_STR | CMD_PARAM_OPT, fixup_substre, 0}, {0,0,0}}, + REQUEST_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE| ONREPLY_ROUTE|LOCAL_ROUTE|STARTUP_ROUTE|TIMER_ROUTE|EVENT_ROUTE}, - {"ldap_result_next", (cmd_function)w_ldap_result_next, 0, - 0, 0, REQUEST_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE|ONREPLY_ROUTE| + {"ldap_result_next", (cmd_function)w_ldap_result_next, {{0,0,0}}, + REQUEST_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE|ONREPLY_ROUTE| LOCAL_ROUTE|STARTUP_ROUTE|TIMER_ROUTE|EVENT_ROUTE}, - {"ldap_result_check", (cmd_function)w_ldap_result_check_1, 1, - ldap_result_check_fixup, 0, REQUEST_ROUTE|FAILURE_ROUTE| + {"ldap_result_check", (cmd_function)w_ldap_result_check, { + {CMD_PARAM_STR, 0, 0}, + {CMD_PARAM_STR, 0, 0}, + {CMD_PARAM_STR | CMD_PARAM_OPT, fixup_substre, 0}, {0,0,0}}, + REQUEST_ROUTE|FAILURE_ROUTE| BRANCH_ROUTE|ONREPLY_ROUTE|LOCAL_ROUTE|STARTUP_ROUTE|TIMER_ROUTE|EVENT_ROUTE}, - {"ldap_result_check", (cmd_function)w_ldap_result_check_2, 2, - ldap_result_check_fixup, 0, REQUEST_ROUTE|FAILURE_ROUTE| + {"ldap_filter_url_encode", (cmd_function)w_ldap_filter_url_encode, { + {CMD_PARAM_STR, 0, 0}, + {CMD_PARAM_VAR, 0, 0}, {0,0,0}}, + REQUEST_ROUTE|FAILURE_ROUTE| BRANCH_ROUTE|ONREPLY_ROUTE|LOCAL_ROUTE|STARTUP_ROUTE|TIMER_ROUTE|EVENT_ROUTE}, - {"ldap_filter_url_encode", (cmd_function)w_ldap_filter_url_encode, 2, - ldap_filter_url_encode_fixup, 0, REQUEST_ROUTE|FAILURE_ROUTE| - BRANCH_ROUTE|ONREPLY_ROUTE|LOCAL_ROUTE|STARTUP_ROUTE|TIMER_ROUTE|EVENT_ROUTE}, - {"load_ldap", (cmd_function)load_ldap, 0, - 0, 0, - 0}, - {0, 0, 0, 0, 0, 0} + {"load_ldap", (cmd_function)load_ldap, {{0,0,0}}, 0}, + {0,0,{{0,0,0}},0} }; @@ -275,265 +271,74 @@ static void destroy(void) * EXPORTED functions */ -static int w_ldap_search_async(struct sip_msg* msg, async_ctx *ctx, - char* ldap_url, char* param) -{ - return ldap_search_impl_async(msg, ctx, (pv_elem_t*)ldap_url); -} - -static int w_ldap_search(struct sip_msg* msg, char* ldap_url, char* param) +static int w_ldap_search_async(struct sip_msg* msg, async_ctx *ctx, str* ldap_url) { - return ldap_search_impl(msg, (pv_elem_t*)ldap_url); + return ldap_search_impl_async(msg, ctx, ldap_url); } -static int w_ldap_result1(struct sip_msg* msg, char* src, char* param) +static int w_ldap_search(struct sip_msg* msg, str* ldap_url) { - return ldap_write_result(msg, (struct ldap_result_params*)src, NULL); + return ldap_search_impl(msg, ldap_url); } -static int w_ldap_result2(struct sip_msg* msg, char* src, char* subst) +static int w_ldap_result(struct sip_msg* msg, str *attr_name, + pv_spec_t *dst_avp, void *avp_type, struct subst_expr *subst) { - return ldap_write_result(msg, (struct ldap_result_params*)src, - (struct subst_expr*)subst); + return ldap_write_result(msg, attr_name, dst_avp, (int)avp_type, subst); } -static int w_ldap_result_next(struct sip_msg* msg, char* foo, char *bar) +static int w_ldap_result_next(struct sip_msg* msg) { return ldap_result_next(); } static int w_ldap_filter_url_encode(struct sip_msg* msg, - char* filter_component, char* dst_avp_name) -{ - return ldap_filter_url_encode(msg, (pv_elem_t*)filter_component, - (pv_spec_t*)dst_avp_name); -} - -static int w_ldap_result_check_1(struct sip_msg* msg, - char* attr_name_check_str, char* param) + str* filter_component, pv_spec_t* dst_avp_name) { - return ldap_result_check(msg, - (struct ldap_result_check_params*)attr_name_check_str, NULL); + return ldap_filter_url_encode(msg, filter_component, dst_avp_name); } -static int w_ldap_result_check_2(struct sip_msg* msg, - char* attr_name_check_str, char* attr_val_re) +static int w_ldap_result_check(struct sip_msg* msg, str* attr_name, + str *check_str, struct subst_expr *subst) { - return ldap_result_check( msg, - (struct ldap_result_check_params*)attr_name_check_str, - (struct subst_expr*)attr_val_re); + return ldap_result_check(msg, attr_name, check_str, subst); } /* * 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) +static int fixup_result_avp_type(void **param) { - struct ldap_result_params* lp; - struct subst_expr* se; - str subst; - char *arg_str, *dst_avp_str, *dst_avp_val_type_str; - char *p; - str s; + static str ints = str_init("int"); + static str strs = str_init("str"); int dst_avp_val_type = 0; - if (param_no == 1) { - arg_str = (char*)*param; - if ((dst_avp_str = strchr(arg_str, '/')) == 0) - { - /* no / found in arg_str */ - LM_ERR("invalid first argument [%s]\n", arg_str); - return E_UNSPEC; - } - *(dst_avp_str++) = 0; - - if ((dst_avp_val_type_str = strchr(dst_avp_str, '/'))) - { - *(dst_avp_val_type_str++) = 0; - if (!strcmp(dst_avp_val_type_str, "int")) - { - dst_avp_val_type = 1; - } - else if (strcmp(dst_avp_val_type_str, "str")) - { - LM_ERR( "invalid avp_type [%s]\n", - dst_avp_val_type_str); - return E_UNSPEC; - } - } - - lp = (struct ldap_result_params*)pkg_malloc(sizeof(struct ldap_result_params)); - if (lp == NULL) { - LM_ERR("no memory\n"); - return E_OUT_OF_MEM; - } - memset(lp, 0, sizeof(struct ldap_result_params)); - - lp->ldap_attr_name.s = arg_str; - lp->ldap_attr_name.len = strlen(arg_str); - - lp->dst_avp_val_type = dst_avp_val_type; - s.s = dst_avp_str; s.len = strlen(s.s); - p = pv_parse_spec(&s, &lp->dst_avp_spec); - if (p == 0) { - pkg_free(lp); - LM_ERR("parse error for [%s]\n", - dst_avp_str); - return E_UNSPEC; - } - if (lp->dst_avp_spec.type != PVT_AVP) { - pkg_free(lp); - LM_ERR( "bad attribute name [%s]\n", - dst_avp_str); - return E_UNSPEC; - } - *param = (void*)lp; - - } else if (param_no == 2) { - subst.s = *param; - subst.len = strlen(*param); - se = subst_parser(&subst); - if (se == 0) { - LM_ERR("bad subst re [%s]\n", - (char*)*param); - return E_BAD_RE; - } - *param = (void*)se; - } - - return 0; -} - -static int ldap_result_check_fixup(void** param, int param_no) -{ - struct ldap_result_check_params *lp; - struct subst_expr *se; - str subst; - str s; - char *arg_str, *check_str; - int arg_str_len; - - if (param_no == 1) + if (!str_strcmp((str*)*param, &ints)) { - arg_str = (char*)*param; - arg_str_len = strlen(arg_str); - if ((check_str = strchr(arg_str, '/')) == 0) - { - /* no / found in arg_str */ - LM_ERR( "invalid first argument [%s] (no '/' found)\n", - arg_str); - return E_UNSPEC; - } - *(check_str++) = 0; - - lp = (struct ldap_result_check_params*)pkg_malloc(sizeof(struct ldap_result_check_params)); - if (lp == NULL) { - LM_ERR("no memory\n"); - return E_OUT_OF_MEM; - } - memset(lp, 0, sizeof(struct ldap_result_check_params)); - - lp->ldap_attr_name.s = arg_str; - lp->ldap_attr_name.len = strlen(arg_str); - - if (lp->ldap_attr_name.len + 1 == arg_str_len) - { - /* empty check_str */ - lp->check_str_elem_p = 0; - } - else - { - s.s = check_str; s.len = strlen(s.s); - if (pv_parse_format(&s, &(lp->check_str_elem_p)) < 0) - { - LM_ERR("pv_parse_format failed\n"); - return E_OUT_OF_MEM; - } - } - *param = (void*)lp; + dst_avp_val_type = 1; } - else if (param_no == 2) + else if (str_strcmp((str*)*param, &strs)) { - subst.s = *param; - subst.len = strlen(*param); - se = subst_parser(&subst); - if (se == 0) { - LM_ERR( "bad subst re [%s]\n", - (char*)*param); - return E_BAD_RE; - } - *param = (void*)se; + LM_ERR( "invalid avp_type [%.*s]\n", + ((str*)*param)->len, ((str*)*param)->s); + return E_UNSPEC; } + *param = (void*)(long)dst_avp_val_type; return 0; } -static int ldap_filter_url_encode_fixup(void** param, int param_no) +static int fixup_substre(void** param) { - pv_elem_t *elem_p; - pv_spec_t *spec_p; - str s; - - if (param_no == 1) { - s.s = (char*)*param; - if (s.s==0 || s.s[0]==0) { - elem_p = 0; - } else { - s.len = strlen(s.s); - if (pv_parse_format(&s, &elem_p) < 0) { - LM_ERR("pv_parse_format failed\n"); - return E_OUT_OF_MEM; - } - } - *param = (void*)elem_p; - } - else if (param_no == 2) - { - spec_p = (pv_spec_t*)pkg_malloc(sizeof(pv_spec_t)); - if (spec_p == NULL) { - LM_ERR("no memory\n"); - return E_OUT_OF_MEM; - } - s.s = (char*)*param; s.len = strlen(s.s); - if (pv_parse_spec(&s, spec_p) - == 0) - { - pkg_free(spec_p); - LM_ERR("parse error for [%s]\n", - (char*)*param); - return E_UNSPEC; - } - if (spec_p->type != PVT_AVP) { - pkg_free(spec_p); - LM_ERR("bad attribute name" - " [%s]\n", (char*)*param); - return E_UNSPEC; - } - *param = (void*)spec_p; + struct subst_expr* se; + + se=subst_parser((str*)*param); + if (se==0){ + LM_ERR("bad subst re [%.*s]\n", ((str*)*param)->len, ((str*)*param)->s); + return E_BAD_RE; } + *param=se; return 0; }