[asterisk-commits] russell: branch group/res_config_ldap r78031 - /team/group/res_config_ldap/res/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Aug 2 21:23:32 CDT 2007


Author: russell
Date: Thu Aug  2 21:23:31 2007
New Revision: 78031

URL: http://svn.digium.com/view/asterisk?view=rev&rev=78031
Log:
* Conversions to ast_debug
* Use sizeof() instead of magic numbers
* Make the module build under dev-mode

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=78031&r1=78030&r2=78031
==============================================================================
--- team/group/res_config_ldap/res/res_config_ldap.c (original)
+++ team/group/res_config_ldap/res/res_config_ldap.c Thu Aug  2 21:23:31 2007
@@ -174,8 +174,7 @@
 	if (!var_value)
 		return 0;
 
-	if (option_debug)
-		ast_log(LOG_DEBUG, "LINE(%d) semicolon_count_var: %s\n", __LINE__, var_value->value);
+	ast_debug(1, "LINE(%d) semicolon_count_var: %s\n", __LINE__, var_value->value);
 
 	return semicolon_count_str(var_value->value);
 }
@@ -291,15 +290,13 @@
 
 			while (*v) {
 				value = *v;
-				if (option_debug > 1)
-					ast_log(LOG_DEBUG, "LINE(%d) attribute_name: %s LDAP value: %s\n", __LINE__, attribute_name, value->bv_val);
+				ast_debug(2, "LINE(%d) attribute_name: %s LDAP value: %s\n", __LINE__, attribute_name, value->bv_val);
 				if (is_realmed_password_attribute) {
 					if (!strncasecmp(value->bv_val, "{md5}", 5))
 						value->bv_val += 5;
 					else
 						value->bv_val = NULL;
-					if (option_debug > 1)
-						ast_log(LOG_DEBUG, "md5: %s\n", value->bv_val);
+					ast_debug(2, "md5: %s\n", value->bv_val);
 				}
 				if (value->bv_val) {
 					/* ok, so looping through all delimited values except the last one (not, last character is not delimited...) */
@@ -357,6 +354,13 @@
 	int tot_count=0;
 	int entry_index=0;
 	LDAPMessage *ldap_entry = NULL;
+	BerElement *ber = NULL;
+	struct ast_variable *var = NULL;
+	struct ast_variable *prev = NULL;
+	int is_delimited=0;
+	char * delim_value = NULL;
+	int delim_tot_count = 0;
+	int delim_count = 0;
 
 	/* First find the total count */
 	ldap_entry = ldap_first_entry(ldapConn, ldap_result);
@@ -377,24 +381,17 @@
 	
 	ldap_entry = ldap_first_entry(ldapConn, ldap_result);
 	
-	BerElement *ber = NULL;
-	struct ast_variable *var = NULL;
-	struct ast_variable *prev = NULL;
-	int is_delimited=0;
 	i=0;
-	char * delim_value = NULL;
-	int delim_tot_count = 0;
-	int delim_count = 0;
 
 	
 	/*For each static realtime variable we may create several entries in the \a vars array if it's delimited*/
 	for (entry_index = 0; ldap_entry; ){ 
+		int pos = 0;
 		delim_value = NULL;
 		delim_tot_count = 0;
-		delim_count=0;
-		int pos=0;
+		delim_count = 0;
 		
-		do{/* while delim_count */
+		do {/* while delim_count */
 
 			/*Starting new static var*/
 			char *ldap_attribute_name = ldap_first_attribute(ldapConn, ldap_entry, &ber);
@@ -418,8 +415,7 @@
 								value->bv_val += 5;
 							else
 								value->bv_val = NULL;
-							if (option_debug > 1)
-								ast_log(LOG_DEBUG, "md5: %s\n", value->bv_val);
+							ast_debug(2, "md5: %s\n", value->bv_val);
 						}
 						if (value->bv_val) {
 							
@@ -431,8 +427,7 @@
 								ast_copy_string(delim_value,value->bv_val,strlen(value->bv_val)+1);
 								
 								if( (delim_tot_count = semicolon_count_str(delim_value)) > 0){
-									if (option_debug > 3)
-										ast_log(LOG_DEBUG, "LINE(%d) is delimited %d times: %s\n", __LINE__, delim_tot_count, delim_value);
+									ast_debug(4, "LINE(%d) is delimited %d times: %s\n", __LINE__, delim_tot_count, delim_value);
 									is_delimited = 1;
 								}
 							}
@@ -445,13 +440,11 @@
 								
 								i=pos;
 								while ( !ast_strlen_zero(value->bv_val + i) ){
-									if (option_debug > 3)
-										ast_log(LOG_DEBUG, "LINE(%d) DELIM pos: %d i: %d\n", __LINE__, pos, i);
+									ast_debug(4, "LINE(%d) DELIM pos: %d i: %d\n", __LINE__, pos, i);
 									if (delim_value[i] == ';'){
 										delim_value[i] = '\0';
 
-										if (option_debug > 1)
-											ast_log(LOG_DEBUG, "LINE(%d) DELIM - attribute_name: %s value: %s pos: %d\n", __LINE__, attribute_name, &delim_value[pos], pos);
+										ast_debug(2, "LINE(%d) DELIM - attribute_name: %s value: %s pos: %d\n", __LINE__, attribute_name, &delim_value[pos], pos);
 							
 										if (prev) {
 											prev->next = ast_variable_new(attribute_name, &delim_value[pos]);
@@ -469,12 +462,10 @@
 									}
 									i++;
 								}
-								if(ast_strlen_zero(value->bv_val + i)){
-									if (option_debug > 3)
-										ast_log(LOG_DEBUG, "LINE(%d) DELIM pos: %d i: %d delim_count: %d\n", __LINE__, pos, i,delim_count);
+								if (ast_strlen_zero(value->bv_val + i)) {
+									ast_debug(4, "LINE(%d) DELIM pos: %d i: %d delim_count: %d\n", __LINE__, pos, i,delim_count);
 									/* Last delimited value */
-									if (option_debug > 3)
-										ast_log(LOG_DEBUG, "LINE(%d) DELIM - attribute_name: %s value: %s pos: %d\n", __LINE__, attribute_name, &delim_value[pos], pos);
+									ast_debug(4, "LINE(%d) DELIM - attribute_name: %s value: %s pos: %d\n", __LINE__, attribute_name, &delim_value[pos], pos);
 									if (prev) {
 										prev->next = ast_variable_new(attribute_name, &delim_value[pos]);
 										if (prev->next) {
@@ -490,16 +481,14 @@
 									delim_value = NULL;
 								}
 								
-								if (option_debug > 3)
-									ast_log(LOG_DEBUG, "LINE(%d) DELIM pos: %d i: %d\n", __LINE__, pos, i);
+								ast_debug(4, "LINE(%d) DELIM pos: %d i: %d\n", __LINE__, pos, i);
 							} else {
 								/* not delimited */
-								if(delim_value != NULL){
+								if (delim_value) {
 									free(delim_value);
 									delim_value = NULL;
 								}
-								if (option_debug > 1)
-									ast_log(LOG_DEBUG, "LINE(%d) attribute_name: %s value: %s\n", __LINE__, attribute_name, value->bv_val);
+								ast_debug(2, "LINE(%d) attribute_name: %s value: %s\n", __LINE__, attribute_name, value->bv_val);
 
 								if (prev) {
 									prev->next = ast_variable_new(attribute_name, value->bv_val);
@@ -520,11 +509,11 @@
 			} /*!< while (ldap_attribute_name) */
 			ber_free(ber, 0);
 			if(static_table_config == table_config){
-				if (option_debug > 2){
-					const struct ast_variable * tmpdebug = variable_named(var,"variable_name");
-					const struct ast_variable * tmpdebug2 = variable_named(var,"variable_value");
-					if(tmpdebug && tmpdebug2){
-						ast_log(LOG_DEBUG, "LINE(%d) Added to vars - %s = %s\n", __LINE__, tmpdebug->value,tmpdebug2->value);
+				if (option_debug > 2) {
+					const struct ast_variable *tmpdebug = variable_named(var, "variable_name");
+					const struct ast_variable *tmpdebug2 = variable_named(var, "variable_value");
+					if (tmpdebug && tmpdebug2) {
+						ast_debug(3, "LINE(%d) Added to vars - %s = %s\n", __LINE__, tmpdebug->value, tmpdebug2->value);
 					}
 				}
 				vars[entry_index++] = var;
@@ -534,8 +523,7 @@
 			delim_count++;
 		} while(delim_count <= delim_tot_count && static_table_config == table_config );
 		if(static_table_config != table_config){
-			if (option_debug > 2)
-				ast_log(LOG_DEBUG, "LINE(%d) Added to vars - non static\n", __LINE__ );
+			ast_debug(3, "LINE(%d) Added to vars - non static\n", __LINE__ );
 				
 			vars[entry_index++] = var;
 			prev = NULL;
@@ -569,8 +557,7 @@
 		LDAPMessage *ldap_result = NULL;
 		int tries = 0;
 
-		if (option_debug > 1)
-			ast_log(LOG_DEBUG, "ldap_loadentry dn=%s\n", dn);
+		ast_debug(2, "ldap_loadentry dn=%s\n", dn);
 
 		do {
 			result = ldap_search_ext_s(ldapConn, dn, LDAP_SCOPE_BASE,
@@ -595,19 +582,16 @@
 		if (result < 0) {
 			ast_log(LOG_WARNING,
 					"Failed to query database. Check debug for more info.\n");
-			if (option_debug > 1) {
-				ast_log(LOG_DEBUG, "dn=%s\n", dn);
-				ast_log(LOG_DEBUG, "Query Failed because: %s\n",
-					ldap_err2string(result));
-			}
+			ast_debug(2, "dn=%s\n", dn);
+			ast_debug(2, "Query Failed because: %s\n",
+				ldap_err2string(result));
 			ast_mutex_unlock(&ldap_lock);
 			return NULL;
 		} else {
 			int num_entry = 0;
 			unsigned int *entries_count_ptr=NULL; /*!< not using this*/
 			if ((num_entry = ldap_count_entries(ldapConn, ldap_result)) > 0) {
-				if (option_debug>2)
-					ast_log(LOG_DEBUG, "num_entry: %d\n", num_entry);
+				ast_debug(3, "num_entry: %d\n", num_entry);
 
 				vars = realtime_ldap_result_to_vars(table_config,ldap_result,entries_count_ptr);
 				if (num_entry > 1)
@@ -646,9 +630,8 @@
 		ret_string = ast_calloc(1, MAXRESULT);
 		pbx_substitute_variables_helper(channel, string, ret_string, MAXRESULT - 1);
 	}
-	if (option_debug > 1)
-		ast_log(LOG_DEBUG, "substituted: string: '%s' => '%s' \n",
-			string, ret_string);
+	ast_debug(2, "substituted: string: '%s' => '%s' \n",
+		string, ret_string);
 	return ret_string;
 }
 
@@ -675,8 +658,7 @@
 			p++;
 		}
 	}
-	if (option_debug > 1)
-		ast_log(LOG_DEBUG, "basedn: '%s' => '%s' \n", basedn, cbasedn);
+	ast_debug(2, "basedn: '%s' => '%s' \n", basedn, cbasedn);
 	return cbasedn;
 }
 
@@ -713,8 +695,7 @@
 	char *new_value = NULL;
 	char *like_pos = strstr(name, " LIKE");
 	
-	if (option_debug > 1)
-		ast_log(LOG_DEBUG, "name='%s' value='%s'\n", name, value);
+	ast_debug(2, "name='%s' value='%s'\n", name, value);
 
 	if (like_pos) {
 		name = new_name = ast_strdupa(like_pos + strlen(" LIKE"));
@@ -1062,12 +1043,10 @@
 		struct ast_variable *var_metric = variable_named(*p, "var_metric");
 		struct ast_variable *dn = variable_named(*p, "dn");
 			
-		if (option_debug) {
-			ast_log(LOG_DEBUG, "category: %s\n", category->value);
-			ast_log(LOG_DEBUG, "var_name: %s\n", var_name->value);
-			ast_log(LOG_DEBUG, "var_val: %s\n", var_val->value);
-			ast_log(LOG_DEBUG, "cat_metric: %s\n", cat_metric->value);
-		}
+		ast_debug(1, "category: %s\n", category->value);
+		ast_debug(1, "var_name: %s\n", var_name->value);
+		ast_debug(1, "var_val: %s\n", var_val->value);
+		ast_debug(1, "cat_metric: %s\n", cat_metric->value);
 
 		if (!category) {
 			ast_log(LOG_ERROR,
@@ -1295,12 +1274,9 @@
 	}
 	/* Ready to update */
 	if ((num_entries = ldap_count_entries(ldapConn, ldap_result)) > 0) {
-		if (option_debug>2){
-			ast_log(LOG_DEBUG, "LINE(%d) Modifying %s=%s hits: %d\n", __LINE__,attribute,lookup,num_entries);
-			for(i=0;i<mods_size-1;i++){
-				ast_log(LOG_DEBUG, "LINE(%d) %s=%s \n", __LINE__,ldap_mods[i]->mod_type,ldap_mods[i]->mod_values[0]);
-			}
-		}
+		ast_debug(3, "LINE(%d) Modifying %s=%s hits: %d\n", __LINE__,attribute,lookup,num_entries);
+		for (i = 0; option_debug > 2 && i < mods_size - 1; i++)
+			ast_debug(3, "LINE(%d) %s=%s \n", __LINE__,ldap_mods[i]->mod_type,ldap_mods[i]->mod_values[0]);
 		
 		ldap_entry = ldap_first_entry(ldapConn, ldap_result);
 
@@ -1491,8 +1467,7 @@
 	struct berval cred;
 
 	if (ldapConn) {
-		if (option_debug > 1)
-			ast_log(LOG_DEBUG, "Everything seems fine.\n");
+		ast_debug(2, "Everything seems fine.\n");
 		return 1;
 	}
 
@@ -1507,19 +1482,16 @@
 	} 
 
 	if (!ast_strlen_zero(user)) {
-		if (option_debug > 1)
-			ast_log(LOG_DEBUG, "bind to %s as %s\n", host, user);
+		ast_debug(2, "bind to %s as %s\n", host, user);
 		cred.bv_val = (char *) pass;
 		cred.bv_len = strlen(pass);
 		bind_result = ldap_sasl_bind_s(ldapConn, user, LDAP_SASL_SIMPLE, &cred, NULL, NULL, NULL);
 	} else {
-		if (option_debug > 1)
-			ast_log(LOG_DEBUG, "bind anonymously %s anonymously\n", host);
+		ast_debug(2, "bind anonymously %s anonymously\n", host);
 		bind_result = ldap_sasl_bind_s(ldapConn, NULL, LDAP_SASL_SIMPLE, NULL, NULL, NULL, NULL);
 	}
 	if (bind_result == LDAP_SUCCESS) {
-		if (option_debug > 1)
-			ast_log(LOG_DEBUG, "Successfully connected to database.\n");
+		ast_debug(2, "Successfully connected to database.\n");
 		connect_time = time(NULL);
 		return 1;
 	} else {
@@ -1538,10 +1510,10 @@
 	if (!ldapConn)
 		return RESULT_FAILURE;
 	if (host) 
-		snprintf(status, 255, "Connected to %s, port %d baseDN %s", host, port, basedn);
+		snprintf(status, sizeof(status), "Connected to %s, port %d baseDN %s", host, port, basedn);
 
 	if (user && *user)
-		snprintf(status2, 99, " with username %s", user);
+		snprintf(status2, sizeof(status2), " with username %s", user);
 
 	if (ctime > 31536000) {
 		ast_cli(fd, "%s%s for %d years, %d days, %d hours, %d minutes, %d seconds.\n",




More information about the asterisk-commits mailing list