[asterisk-commits] anthonyl: branch anthonyl/usersconf-vmpassword r50986 - /team/anthonyl/usersc...

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Mon Jan 15 15:59:37 MST 2007


Author: anthonyl
Date: Mon Jan 15 16:59:36 2007
New Revision: 50986

URL: http://svn.digium.com/view/asterisk?view=rev&rev=50986
Log:
clean up part one of the mess svnmerge made of this

Modified:
    team/anthonyl/usersconf-vmpassword/apps/app_voicemail.c

Modified: team/anthonyl/usersconf-vmpassword/apps/app_voicemail.c
URL: http://svn.digium.com/view/asterisk/team/anthonyl/usersconf-vmpassword/apps/app_voicemail.c?view=diff&rev=50986&r1=50985&r2=50986
==============================================================================
--- team/anthonyl/usersconf-vmpassword/apps/app_voicemail.c (original)
+++ team/anthonyl/usersconf-vmpassword/apps/app_voicemail.c Mon Jan 15 16:59:36 2007
@@ -777,81 +777,44 @@
 	return res;
 }
 
-/* nice-er implimentation of vm_change_password */
-/* this one also supports users.conf with the vmpassword param */
-/* the current method i am trying to impliment just tries to change both */
 static void vm_change_password(struct ast_vm_user *vmu, const char *newpassword)
 {
-	struct ast_config   *cfg = NULL;
-	struct ast_variable *var;
-	struct ast_category *cat;
-	char *category = NULL, *new = NULL;
-	const char *tmp = "";
-	FILE *configin;
-	FILE *configout;
-	int linenum=0;
-	char inbuf[256];
-	char orig[256];
-	char currcontext[256] = "";
-	char tmpin[PATH_MAX];
-	char tmpout[PATH_MAX];
-
+	struct ast_config   *cfg=NULL;
+	struct ast_variable *var=NULL;
+	struct ast_category *cat=NULL;
+	char *category=NULL, *tmp=NULL, *value=NULL, *new=NULL;
+	int len;
+					
 	if (!change_password_realtime(vmu, newpassword))
 		return;
 
-	snprintf(tmpin, sizeof(tmpin), "%s/voicemail.conf", ast_config_AST_CONFIG_DIR);
-	snprintf(tmpout, sizeof(tmpout), "%s/voicemail.conf.new", ast_config_AST_CONFIG_DIR);
-	configin = fopen(tmpin,"r");
-	if (configin)
-		configout = fopen(tmpout,"w+");
-	else
-		configout = NULL;
-	if (!configin || !configout) {
-		if (configin)
-			fclose(configin);
-		else
-			ast_log(LOG_WARNING, "Warning: Unable to open '%s' for reading: %s\n", tmpin, strerror(errno));
-		if (configout)
-			fclose(configout);
-		else
-			ast_log(LOG_WARNING, "Warning: Unable to open '%s' for writing: %s\n", tmpout, strerror(errno));
-			return;
-	}
-
-	while (!feof(configin)) {
-		char *comment = NULL, *tmpctx = NULL, *tmpctxend = NULL;
-
-		/* Read in the line */
-		if (fgets(inbuf, sizeof(inbuf), configin) == NULL)
-			continue;
-		linenum++;
-
-		/* Make a backup of it */
-		ast_copy_string(orig, inbuf, sizeof(orig));
-
-		/*
-		  Read the file line by line, split each line into a comment and command section
-		  only parse the command portion of the line
-		*/
-		if (inbuf[strlen(inbuf) - 1] == '\n')
-			inbuf[strlen(inbuf) - 1] = '\0';
-
-		if ((comment = strchr(inbuf, ';')))
-			*comment++ = '\0'; /* Now inbuf is terminated just before the comment */
-
-		if (ast_strlen_zero(inbuf)) {
-			fprintf(configout, "%s", orig);
-			continue;
-		}
-
-		/* Check for a context, first '[' to first ']' */
-		if ((tmpctx = strchr(inbuf, '['))) {
-			tmpctxend = strchr(tmpctx, ']');
-			if (tmpctxend) {
-				/* Valid context */
-				ast_copy_string(currcontext, tmpctx + 1, tmpctxend - tmpctx);
-				fprintf(configout, "%s", orig);
-				continue;
+	/* check voicemail.conf */
+	if ((cfg = ast_config_load("voicemail.conf"))) {
+		while ((category = ast_category_browse(cfg, category))) {
+			if (!strcasecmp(category, vmu->context)) {
+				tmp = ast_variable_retrieve(cfg, category, vmu->mailbox);
+				if (!tmp) {
+					ast_log(LOG_WARNING, "We could not find the mailbox.\n");
+					break;
+				}
+				value = strstr(tmp,",");
+				if (!value) {
+					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;
+				}
+				sprintf(new,"%s%s", newpassword, value);
+	
+				if (!(cat = ast_category_get(cfg, category))) {
+					ast_log(LOG_WARNING, "Failed to get category structure.\n");
+					break;
+				}
+				ast_variable_update(cat, vmu->mailbox, new, NULL);
 			}
 		}
 		/* save the results */
@@ -861,8 +824,10 @@
 		if (new)
 			free(new);
 	}
+
 	category = NULL;
 	var = NULL;
+
 	/* check users.conf and update the password stored for the mailbox*/
 	/* if no vmpassword entry exists create one. */
 	if ((cfg = ast_config_load("users.conf"))) {



More information about the asterisk-commits mailing list