mirror of
				https://github.com/asterisk/asterisk.git
				synced 2025-11-04 05:15:22 +00:00 
			
		
		
		
	Merged revisions 140422 via svnmerge from
https://origsvn.digium.com/svn/asterisk/trunk ................ r140422 | mmichelson | 2008-08-29 11:06:09 -0500 (Fri, 29 Aug 2008) | 20 lines Merged revisions 140421 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r140421 | mmichelson | 2008-08-29 11:01:07 -0500 (Fri, 29 Aug 2008) | 12 lines Add context checking when retrieving a vm_state. This was causing a problem for people who had identically named mailboxes in separate voicemail contexts. This commit affects IMAP storage only. (closes issue #13194) Reported by: moliveras Patches: 13194.patch uploaded by putnopvut (license 60) Tested by: putnopvut, moliveras ........ ................ git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.6.1@140425 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
		@@ -144,7 +144,7 @@ static char *get_header_by_tag(char *header, char *tag, char *buf, size_t len);
 | 
				
			|||||||
static void vm_imap_delete(int msgnum, struct ast_vm_user *vmu);
 | 
					static void vm_imap_delete(int msgnum, struct ast_vm_user *vmu);
 | 
				
			||||||
static char *get_user_by_mailbox(char *mailbox, char *buf, size_t len);
 | 
					static char *get_user_by_mailbox(char *mailbox, char *buf, size_t len);
 | 
				
			||||||
static struct vm_state *get_vm_state_by_imapuser(char *user, int interactive);
 | 
					static struct vm_state *get_vm_state_by_imapuser(char *user, int interactive);
 | 
				
			||||||
static struct vm_state *get_vm_state_by_mailbox(const char *mailbox, int interactive);
 | 
					static struct vm_state *get_vm_state_by_mailbox(const char *mailbox, const char *context, int interactive);
 | 
				
			||||||
static struct vm_state *create_vm_state_from_user(struct ast_vm_user *vmu);
 | 
					static struct vm_state *create_vm_state_from_user(struct ast_vm_user *vmu);
 | 
				
			||||||
static void vmstate_insert(struct vm_state *vms);
 | 
					static void vmstate_insert(struct vm_state *vms);
 | 
				
			||||||
static void vmstate_delete(struct vm_state *vms);
 | 
					static void vmstate_delete(struct vm_state *vms);
 | 
				
			||||||
@@ -415,6 +415,7 @@ struct vm_zone {
 | 
				
			|||||||
struct vm_state {
 | 
					struct vm_state {
 | 
				
			||||||
	char curbox[80];
 | 
						char curbox[80];
 | 
				
			||||||
	char username[80];
 | 
						char username[80];
 | 
				
			||||||
 | 
						char context[80];
 | 
				
			||||||
	char curdir[PATH_MAX];
 | 
						char curdir[PATH_MAX];
 | 
				
			||||||
	char vmbox[PATH_MAX];
 | 
						char vmbox[PATH_MAX];
 | 
				
			||||||
	char fn[PATH_MAX];
 | 
						char fn[PATH_MAX];
 | 
				
			||||||
@@ -1335,7 +1336,7 @@ static void vm_imap_delete(int msgnum, struct ast_vm_user *vmu)
 | 
				
			|||||||
		return;
 | 
							return;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (!(vms = get_vm_state_by_mailbox(vmu->mailbox, 1)) && !(vms = get_vm_state_by_mailbox(vmu->mailbox, 0))) {
 | 
						if (!(vms = get_vm_state_by_mailbox(vmu->mailbox, vmu->context, 1)) && !(vms = get_vm_state_by_mailbox(vmu->mailbox, vmu->context, 0))) {
 | 
				
			||||||
		ast_log(LOG_WARNING, "Couldn't find a vm_state for mailbox %s. Unable to set \\DELETED flag for message %d\n", vmu->mailbox, msgnum);
 | 
							ast_log(LOG_WARNING, "Couldn't find a vm_state for mailbox %s. Unable to set \\DELETED flag for message %d\n", vmu->mailbox, msgnum);
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -1378,7 +1379,7 @@ static int imap_retrieve_greeting (const char *dir, const int msgnum, struct ast
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* check if someone is accessing this box right now... */
 | 
						/* check if someone is accessing this box right now... */
 | 
				
			||||||
	if (!(vms_p = get_vm_state_by_mailbox(vmu->mailbox, 1)) ||!(vms_p = get_vm_state_by_mailbox(vmu->mailbox, 0))) {
 | 
						if (!(vms_p = get_vm_state_by_mailbox(vmu->mailbox, vmu->context, 1)) ||!(vms_p = get_vm_state_by_mailbox(vmu->mailbox, vmu->context, 0))) {
 | 
				
			||||||
		ast_log(AST_LOG_ERROR, "Voicemail state not found!\n");
 | 
							ast_log(AST_LOG_ERROR, "Voicemail state not found!\n");
 | 
				
			||||||
		return -1;
 | 
							return -1;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -1444,7 +1445,7 @@ static int imap_retrieve_file(const char *dir, const int msgnum, const char *mai
 | 
				
			|||||||
	/* Before anything can happen, we need a vm_state so that we can
 | 
						/* Before anything can happen, we need a vm_state so that we can
 | 
				
			||||||
	 * actually access the imap server through the vms->mailstream
 | 
						 * actually access the imap server through the vms->mailstream
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	if (!(vms = get_vm_state_by_mailbox(vmu->mailbox, 1)) && !(vms = get_vm_state_by_mailbox(vmu->mailbox, 0))) {
 | 
						if (!(vms = get_vm_state_by_mailbox(vmu->mailbox, vmu->context, 1)) && !(vms = get_vm_state_by_mailbox(vmu->mailbox, vmu->context, 0))) {
 | 
				
			||||||
		/* This should not happen. If it does, then I guess we'd
 | 
							/* This should not happen. If it does, then I guess we'd
 | 
				
			||||||
		 * need to create the vm_state, extract which mailbox to
 | 
							 * need to create the vm_state, extract which mailbox to
 | 
				
			||||||
		 * open, and then set up the msgArray so that the correct
 | 
							 * open, and then set up the msgArray so that the correct
 | 
				
			||||||
@@ -1615,7 +1616,7 @@ static int messagecount(const char *context, const char *mailbox, const char *fo
 | 
				
			|||||||
	/* check if someone is accessing this box right now... */
 | 
						/* check if someone is accessing this box right now... */
 | 
				
			||||||
	vms_p = get_vm_state_by_imapuser(vmu->imapuser,1);
 | 
						vms_p = get_vm_state_by_imapuser(vmu->imapuser,1);
 | 
				
			||||||
	if (!vms_p) {
 | 
						if (!vms_p) {
 | 
				
			||||||
		vms_p = get_vm_state_by_mailbox(mailbox,1);
 | 
							vms_p = get_vm_state_by_mailbox(mailbox, context, 1);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if (vms_p) {
 | 
						if (vms_p) {
 | 
				
			||||||
		ast_debug(3, "Returning before search - user is logged in\n");
 | 
							ast_debug(3, "Returning before search - user is logged in\n");
 | 
				
			||||||
@@ -1633,7 +1634,7 @@ static int messagecount(const char *context, const char *mailbox, const char *fo
 | 
				
			|||||||
	/* add one if not there... */
 | 
						/* add one if not there... */
 | 
				
			||||||
	vms_p = get_vm_state_by_imapuser(vmu->imapuser,0);
 | 
						vms_p = get_vm_state_by_imapuser(vmu->imapuser,0);
 | 
				
			||||||
	if (!vms_p) {
 | 
						if (!vms_p) {
 | 
				
			||||||
		vms_p = get_vm_state_by_mailbox(mailbox,0);
 | 
							vms_p = get_vm_state_by_mailbox(mailbox, context, 0);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* If URGENT, then look at INBOX */
 | 
						/* If URGENT, then look at INBOX */
 | 
				
			||||||
@@ -2428,6 +2429,7 @@ static struct vm_state *create_vm_state_from_user(struct ast_vm_user *vmu)
 | 
				
			|||||||
		return NULL;
 | 
							return NULL;
 | 
				
			||||||
	ast_copy_string(vms_p->imapuser, vmu->imapuser, sizeof(vms_p->imapuser));
 | 
						ast_copy_string(vms_p->imapuser, vmu->imapuser, sizeof(vms_p->imapuser));
 | 
				
			||||||
	ast_copy_string(vms_p->username, vmu->mailbox, sizeof(vms_p->username)); /* save for access from interactive entry point */
 | 
						ast_copy_string(vms_p->username, vmu->mailbox, sizeof(vms_p->username)); /* save for access from interactive entry point */
 | 
				
			||||||
 | 
						ast_copy_string(vms_p->context, vmu->context, sizeof(vms_p->context));
 | 
				
			||||||
	vms_p->mailstream = NIL; /* save for access from interactive entry point */
 | 
						vms_p->mailstream = NIL; /* save for access from interactive entry point */
 | 
				
			||||||
	if (option_debug > 4)
 | 
						if (option_debug > 4)
 | 
				
			||||||
		ast_log(AST_LOG_DEBUG,"Copied %s to %s\n",vmu->imapuser,vms_p->imapuser);
 | 
							ast_log(AST_LOG_DEBUG,"Copied %s to %s\n",vmu->imapuser,vms_p->imapuser);
 | 
				
			||||||
@@ -2466,10 +2468,11 @@ static struct vm_state *get_vm_state_by_imapuser(char *user, int interactive)
 | 
				
			|||||||
	return NULL;
 | 
						return NULL;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static struct vm_state *get_vm_state_by_mailbox(const char *mailbox, int interactive)
 | 
					static struct vm_state *get_vm_state_by_mailbox(const char *mailbox, const char *context, int interactive)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	struct vmstate *vlist = NULL;
 | 
						struct vmstate *vlist = NULL;
 | 
				
			||||||
 | 
						const char *local_context = S_OR(context, "default");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	AST_LIST_LOCK(&vmstates);
 | 
						AST_LIST_LOCK(&vmstates);
 | 
				
			||||||
	AST_LIST_TRAVERSE(&vmstates, vlist, list) {
 | 
						AST_LIST_TRAVERSE(&vmstates, vlist, list) {
 | 
				
			||||||
@@ -2477,14 +2480,14 @@ static struct vm_state *get_vm_state_by_mailbox(const char *mailbox, int interac
 | 
				
			|||||||
			ast_debug(3, "error: vms is NULL for %s\n", mailbox);
 | 
								ast_debug(3, "error: vms is NULL for %s\n", mailbox);
 | 
				
			||||||
			continue;
 | 
								continue;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if (!vlist->vms->username) {
 | 
							if (!vlist->vms->username || !vlist->vms->context) {
 | 
				
			||||||
			ast_debug(3, "error: username is NULL for %s\n", mailbox);
 | 
								ast_debug(3, "error: username is NULL for %s\n", mailbox);
 | 
				
			||||||
			continue;
 | 
								continue;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		ast_debug(3, "comparing mailbox %s (i=%d) to vmstate mailbox %s (i=%d)\n", mailbox, interactive, vlist->vms->username, vlist->vms->interactive);
 | 
							ast_debug(3, "comparing mailbox %s@%s (i=%d) to vmstate mailbox %s@%s (i=%d)\n", mailbox, local_context, interactive, vlist->vms->username, vlist->vms->context, vlist->vms->interactive);
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		if (!strcmp(vlist->vms->username,mailbox) && vlist->vms->interactive == interactive) {
 | 
							if (!strcmp(vlist->vms->username,mailbox) && !strcmp(vlist->vms->context, local_context) && vlist->vms->interactive == interactive) {
 | 
				
			||||||
			ast_debug(3, "Found it!\n");
 | 
								ast_debug(3, "Found it!\n");
 | 
				
			||||||
			AST_LIST_UNLOCK(&vmstates);
 | 
								AST_LIST_UNLOCK(&vmstates);
 | 
				
			||||||
			return vlist->vms;
 | 
								return vlist->vms;
 | 
				
			||||||
@@ -2506,7 +2509,7 @@ static void vmstate_insert(struct vm_state *vms)
 | 
				
			|||||||
	   use the one we already have since it is more up to date.
 | 
						   use the one we already have since it is more up to date.
 | 
				
			||||||
	   We can compare the username to find the duplicate */
 | 
						   We can compare the username to find the duplicate */
 | 
				
			||||||
	if (vms->interactive == 1) {
 | 
						if (vms->interactive == 1) {
 | 
				
			||||||
		altvms = get_vm_state_by_mailbox(vms->username,0);
 | 
							altvms = get_vm_state_by_mailbox(vms->username, vms->context, 0);
 | 
				
			||||||
		if (altvms) {	
 | 
							if (altvms) {	
 | 
				
			||||||
			ast_debug(3, "Duplicate mailbox %s, copying message info...\n",vms->username);
 | 
								ast_debug(3, "Duplicate mailbox %s, copying message info...\n",vms->username);
 | 
				
			||||||
			vms->newmessages = altvms->newmessages;
 | 
								vms->newmessages = altvms->newmessages;
 | 
				
			||||||
@@ -4852,7 +4855,7 @@ static int leave_voicemail(struct ast_channel *chan, char *ext, struct leave_vm_
 | 
				
			|||||||
			ast_log(AST_LOG_NOTICE, "Can not leave voicemail, unable to count messages\n");
 | 
								ast_log(AST_LOG_NOTICE, "Can not leave voicemail, unable to count messages\n");
 | 
				
			||||||
			return -1;
 | 
								return -1;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if (!(vms = get_vm_state_by_mailbox(ext,0))) {
 | 
							if (!(vms = get_vm_state_by_mailbox(ext, context, 0))) {
 | 
				
			||||||
		/* It is possible under certain circumstances that inboxcount did not
 | 
							/* It is possible under certain circumstances that inboxcount did not
 | 
				
			||||||
		 * create a vm_state when it was needed. This is a catchall which will
 | 
							 * create a vm_state when it was needed. This is a catchall which will
 | 
				
			||||||
		 * rarely be used.
 | 
							 * rarely be used.
 | 
				
			||||||
@@ -6155,7 +6158,7 @@ static int forward_message(struct ast_channel *chan, char *context, struct vm_st
 | 
				
			|||||||
				char *myserveremail = serveremail;
 | 
									char *myserveremail = serveremail;
 | 
				
			||||||
				
 | 
									
 | 
				
			||||||
				/* get destination mailbox */
 | 
									/* get destination mailbox */
 | 
				
			||||||
				dstvms = get_vm_state_by_mailbox(vmtmp->mailbox,0);
 | 
									dstvms = get_vm_state_by_mailbox(vmtmp->mailbox, vmtmp->context, 0);
 | 
				
			||||||
				if (!dstvms) {
 | 
									if (!dstvms) {
 | 
				
			||||||
					dstvms = create_vm_state_from_user(vmtmp);
 | 
										dstvms = create_vm_state_from_user(vmtmp);
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user