[asterisk-commits] kpfleming: branch 1.4 r51176 - /branches/1.4/apps/app_voicemail.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Tue Jan 16 18:29:13 MST 2007


Author: kpfleming
Date: Tue Jan 16 19:29:12 2007
New Revision: 51176

URL: http://svn.digium.com/view/asterisk?view=rev&rev=51176
Log:
a few more coding style cleanups and one bug fix (from AnthonyL)

Modified:
    branches/1.4/apps/app_voicemail.c

Modified: branches/1.4/apps/app_voicemail.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/apps/app_voicemail.c?view=diff&rev=51176&r1=51175&r2=51176
==============================================================================
--- branches/1.4/apps/app_voicemail.c (original)
+++ branches/1.4/apps/app_voicemail.c Tue Jan 16 19:29:12 2007
@@ -657,12 +657,11 @@
 	struct ast_variable *tmp;
 	tmp = var;
 	while (tmp) {
-		if (!strcasecmp(tmp->name, "password") || !strcasecmp(tmp->name, "secret")) {
+		if (!strcasecmp(tmp->name, "vmpassword")) {
 			ast_copy_string(retval->password, tmp->value, sizeof(retval->password));
-		} else if (!strcasecmp(tmp->name, "secret")) {
-			/* dont let secret override vmpassword */
+		} else if (!strcasecmp(tmp->name, "secret")) { /* don't overwrite vmpassword if it exists */
 			if (ast_strlen_zero(retval->password))
-				ast_copy_string(retval->password, tmp->value, sizeof(retval->password));	
+				ast_copy_string(retval->password, tmp->value, sizeof(retval->password));
 		} else if (!strcasecmp(tmp->name, "uniqueid")) {
 			ast_copy_string(retval->uniqueid, tmp->value, sizeof(retval->uniqueid));
 		} else if (!strcasecmp(tmp->name, "pager")) {
@@ -768,7 +767,6 @@
 	struct ast_category *cat=NULL;
 	char *category=NULL, *value=NULL, *new=NULL;
 	const char *tmp=NULL;
-	int len;
 					
 	if (!change_password_realtime(vmu, newpassword))
 		return;
@@ -787,14 +785,8 @@
 					ast_log(LOG_WARNING, "variable has bad format.\n");
 					break;
 				}
-				len = (strlen(value) + strlen(newpassword));
-				
-				if (!(new = ast_calloc(1,len))) {
-					ast_log(LOG_WARNING, "Memory Allocation Failed.\n");
-					break;
-				}
+				new = alloca((strlen(value)+strlen(newpassword)+1));
 				sprintf(new,"%s%s", newpassword, value);
-	
 				if (!(cat = ast_category_get(cfg, category))) {
 					ast_log(LOG_WARNING, "Failed to get category structure.\n");
 					break;
@@ -806,8 +798,6 @@
 		reset_user_pw(vmu->context, vmu->mailbox, newpassword);
 		ast_copy_string(vmu->password, newpassword, sizeof(vmu->password));
 		config_text_file_save(VOICEMAIL_CONFIG, cfg, "AppVoicemail");
-		if (new)
-			free(new);
 	}
 	category = NULL;
 	var = NULL;
@@ -825,15 +815,12 @@
 						ast_log(LOG_DEBUG, "looks like we need to make vmpassword!\n");
 					var = ast_variable_new("vmpassword", newpassword);
 				} 
-				if (!(new = ast_calloc(1,strlen(newpassword)))) {
-					if (option_debug > 3)
-						ast_log(LOG_DEBUG, "Memory Allocation Failed.\n");
-					break;
-				} 
+				new = alloca(strlen(newpassword)+1);
 				sprintf(new, "%s", newpassword);
 				if (!(cat = ast_category_get(cfg, category))) {
 					if (option_debug > 3)
 						ast_log(LOG_DEBUG, "failed to get category!\n");
+					break;
 				}
 				if (!var)		
 					ast_variable_update(cat, "vmpassword", new, NULL);
@@ -845,10 +832,7 @@
 		reset_user_pw(vmu->context, vmu->mailbox, newpassword);	
 		ast_copy_string(vmu->password, newpassword, sizeof(vmu->password));
 		config_text_file_save("users.conf", cfg, "AppVoicemail");
-		if (new) 
-			free(new);
-	}
-
+	}
 }
 
 static void vm_change_password_shell(struct ast_vm_user *vmu, char *newpassword)



More information about the asterisk-commits mailing list