[svn-commits] russell: branch group/res_config_ldap r64679 -
/team/group/res_config_ldap/res/
svn-commits at lists.digium.com
svn-commits at lists.digium.com
Wed May 16 13:42:38 MST 2007
Author: russell
Date: Wed May 16 15:42:38 2007
New Revision: 64679
URL: http://svn.digium.com/view/asterisk?view=rev&rev=64679
Log:
some more code cleanup ...
Modified:
team/group/res_config_ldap/res/res_config_ldap.c
Modified: team/group/res_config_ldap/res/res_config_ldap.c
URL: http://svn.digium.com/view/asterisk/team/group/res_config_ldap/res/res_config_ldap.c?view=diff&rev=64679&r1=64678&r2=64679
==============================================================================
--- team/group/res_config_ldap/res/res_config_ldap.c (original)
+++ team/group/res_config_ldap/res/res_config_ldap.c Wed May 16 15:42:38 2007
@@ -95,7 +95,6 @@
char *table_name; /*!< table name */
char *additional_filter; /*!< additional filter */
struct ast_variable *attributes; /*!< attribute names conversion */
- struct ast_variable *escapes; /*!< characters to escape(i.e., * - the ldap wildchar) */
struct ast_variable *delimiters; /*!< the current delimiter is semicolon, so we are not using this variable */
AST_LIST_ENTRY(ldap_table_config) entry;
};
@@ -179,64 +178,6 @@
ast_log(LOG_DEBUG, "LINE(%d) semicolon_count_var: %s\n", __LINE__, var_value->value);
return semicolon_count_str(var_value->value);
-}
-
-/*! \brief add escape characters to the table config (e.g., the * character)
- */
-static void ldap_table_config_add_escape(struct ldap_table_config *table_config,
- const char *escape_string)
-{
- char *string;
- char *start;
- char *p;
- char *value;
- struct ast_variable *var;
-
- if (ast_strlen_zero(escape_string))
- return;
-
- start = string = ast_strdupa(escape_string);
-
- if (!(p = strstr(start, "=>"))) {
- ast_log(LOG_WARNING, "LDAP RealTime: Missing '=>' in escape: %s in %s\n",
- escape_string, table_config->table_name);
- return;
- }
-
- value = p + 2; /* skip => */
-
- /* trim ! */
-
- start = ast_skip_blanks(start);
- p--;
- while (p >= start && isspace(*p)) {
- *p = '\0';
- p--;
- }
-
- value = ast_skip_blanks(value);
- p = value + strlen(value) - 1;
- while (p >= value && isspace(*p)) {
- *p = '\0';
- p--;
- }
-
- if (ast_strlen_zero(start)) {
- ast_log(LOG_WARNING, "LDAP RealTime: Empty variable name in escape: %s in %s\n",
- escape_string, table_config->table_name);
- return;
- }
-
- if (ast_strlen_zero(value)) {
- ast_log(LOG_WARNING, "LDAP RealTime: Empty ldap escape name in escape: %s in %s\n",
- escape_string, table_config->table_name);
- return;
- }
-
- var = ast_variable_new(start, value);
- if (table_config->escapes)
- var->next = table_config->escapes;
- table_config->escapes = var;
}
/*! \brief add attribute to table config - Should be locked before using it */
@@ -269,8 +210,6 @@
free(c->additional_filter);
if (c->attributes)
ast_variables_destroy(c->attributes);
- if (c->escapes)
- ast_variables_destroy(c->escapes);
free(c);
}
@@ -325,12 +264,10 @@
}
/*! \brief Get variables from ldap entry attributes - Should be locked before using it
- *
- *
* \return a linked list of ast_variable variables.
**/
static struct ast_variable *realtime_ldap_entry_to_var(struct ldap_table_config *table_config,
- LDAPMessage *ldap_entry)
+ LDAPMessage *ldap_entry)
{
BerElement *ber = NULL;
struct ast_variable *var = NULL;
@@ -366,10 +303,10 @@
}
if (value->bv_val) {
/* ok, so looping through all delimited values except the last one (not, last character is not delimited...) */
- if( is_delimited != 0){
- i=0;
- pos=0;
- while ( !ast_strlen_zero(value->bv_val + i) ){
+ if (is_delimited) {
+ i = 0;
+ pos = 0;
+ while (!ast_strlen_zero(value->bv_val + i)) {
if (value->bv_val[i] == ';'){
value->bv_val[i] = '\0';
if (prev) {
@@ -397,7 +334,6 @@
}
v++;
}
-// ldap_value_free(values);
ber_bvecfree(values);
}
ldap_attribute_name = ldap_next_attribute(ldapConn, ldap_entry, ber);
@@ -414,7 +350,7 @@
* \return \a vars - an array of ast_variable variables terminated with a null.
**/
static struct ast_variable **realtime_ldap_result_to_vars(struct ldap_table_config *table_config,
- LDAPMessage * ldap_result, unsigned int *entries_count_ptr)
+ LDAPMessage * ldap_result, unsigned int *entries_count_ptr)
{
struct ast_variable ** vars;
int i=0;
@@ -422,7 +358,6 @@
int entry_index=0;
LDAPMessage *ldap_entry = NULL;
-
/* First find the total count */
ldap_entry = ldap_first_entry(ldapConn, ldap_result);
@@ -776,46 +711,21 @@
{
char *new_name = NULL;
char *new_value = NULL;
- char *wsPos = strstr(name, " LIKE");
- int foundEscape = 0;
- struct ast_variable *nextEscape = table_config->escapes;
- char *esc_value = NULL;
- char esc_tmp[2];
-
- for(nextEscape = table_config->escapes; nextEscape ; nextEscape = nextEscape->next ){
- if(strcmp(name,nextEscape->name) == 0){
- foundEscape = 1;
- break;
- }
- }
-
- if (foundEscape == 1){
- esc_value = strdup(value);
- strcpy(esc_tmp, "\\");
- strcat(esc_tmp, nextEscape->value);
- replace_string_in_string(esc_value, nextEscape->value, esc_tmp);
- value = esc_value;
- }
- /* The remaining filter mods */
-
+ char *like_pos = strstr(name, " LIKE");
+
if (option_debug > 1)
ast_log(LOG_DEBUG, "name='%s' value='%s'\n", name, value);
- if (wsPos) {
- new_name = strndup(name, wsPos - name);
- name = new_name;
- new_value = strdup(value);
+
+ if (like_pos) {
+ name = new_name = ast_strdupa(like_pos + strlen(" LIKE"));
+ value = new_value = ast_strdupa(value);
replace_string_in_string(new_value, "\\_", "_");
replace_string_in_string(new_value, "%", "*");
- value = new_value;
- }
+ }
+
name = convert_attribute_name_to_ldap(table_config, name);
ast_str_append(filter, 0, "(%s=%s)", name, value);
-
- if (new_name)
- free(new_name);
- if (new_value)
- free(new_value);
}
/*! \brief LDAP base function
@@ -1561,9 +1471,7 @@
static_table_config = table_config;
}
for (; var; var = var->next) {
- if (!strcasecmp(var->name, "escape"))
- ldap_table_config_add_escape(table_config, var->value);
- else if (!strcasecmp(var->name, "additionalFilter"))
+ if (!strcasecmp(var->name, "additionalFilter"))
table_config->additional_filter = strdup(var->value);
else
ldap_table_config_add_attribute(table_config, var->name, var->value);
More information about the svn-commits
mailing list