Review Board 1.7.16


Voicemail check cleanup

Review Request #525 - Created Feb. 23, 2010 and submitted

Tilghman Lesher
/trunk
15654, 16448
Reviewers
asterisk-dev
Asterisk
A few cleanups to fix a few bugs.

- Urgent voicemails were not attached, because the attachment code looked in the wrong folder.
- Urgent voicemails were sometimes counted twice when displaying the count of new messages.
- Backends were inconsistent as to which voicemails each API counted.
Unit test written, tested, and included.

Changes between revision 2 and 3

1 2 3
1 2 3

  1. /trunk/apps/app_voicemail.c: Loading...
/trunk/apps/app_voicemail.c
Diff Revision 2 Diff Revision 3
[20] 11587 lines
[+20] [+] static int write_password_to_file(const char *secretfn, const char *password) {
11588
	return 0;
11588
	return 0;
11589
}
11589
}
11590

    
   
11590

   
11591
AST_TEST_DEFINE(test_voicemail_msgcount)
11591
AST_TEST_DEFINE(test_voicemail_msgcount)
11592
{
11592
{
11593
	int i, j, res = AST_TEST_PASS;
11593
	int i, j, res = AST_TEST_PASS, syserr;
11594
	struct ast_vm_user *vmu;
11594
	struct ast_vm_user *vmu;
11595
	struct vm_state vms;
11595
	struct vm_state vms;

    
   
11596
#ifdef IMAP_STORAGE

    
   
11597
	struct ast_channel *chan = NULL;

    
   
11598
#endif
11596
	struct {
11599
	struct {
11597
		char dir[256];
11600
		char dir[256];
11598
		char file[256];
11601
		char file[256];
11599
		char txtfile[256];
11602
		char txtfile[256];
11600
	} tmp[3];
11603
	} tmp[3];
[+20] [20] 24 lines
[+20] AST_TEST_DEFINE(test_voicemail_msgcount)
11625
	case TEST_EXECUTE:
11628
	case TEST_EXECUTE:
11626
		break;
11629
		break;
11627
	}
11630
	}
11628

    
   
11631

   
11629
	/* Make sure the original path was completely empty */
11632
	/* Make sure the original path was completely empty */
11630
	create_dirpath(tmp[0].dir, sizeof(tmp[0].dir), testcontext, testmailbox, "");
11633
	snprintf(syscmd, sizeof(syscmd), "rm -rf %s%s/%s", VM_SPOOL_DIR, testcontext, testmailbox);
11631
	snprintf(tmp[0].file, sizeof(tmp[0].file), "rm -rf %s", tmp[0].dir);
11634
	if ((syserr = system(syscmd))) {
11632
	i = system(tmp[0].file);
11635
		ast_test_status_update(test, "Unable to clear test directory: %s\n",

    
   
11636
			syserr > 0 ? strerror(WEXITSTATUS(syserr)) : "unable to fork()");

    
   
11637
		return AST_TEST_NOT_RUN;

    
   
11638
	}

    
   
11639

   

    
   
11640
#ifdef IMAP_STORAGE

    
   
11641
	if (!(chan = ast_dummy_channel_alloc())) {

    
   
11642
		ast_test_status_update(test, "Unable to create dummy channel\n");

    
   
11643
		return AST_TEST_NOT_RUN;

    
   
11644
	}

    
   
11645
#endif
11633

    
   
11646

   
11634
	if (!(vmu = find_user(NULL, testcontext, testmailbox)) &&
11647
	if (!(vmu = find_user(NULL, testcontext, testmailbox)) &&
11635
		!(vmu = find_or_create(testcontext, testmailbox))) {
11648
		!(vmu = find_or_create(testcontext, testmailbox))) {
11636
		ast_test_status_update(test, "Cannot create vmu structure\n");
11649
		ast_test_status_update(test, "Cannot create vmu structure\n");
11637
		return AST_TEST_NOT_RUN;
11650
		return AST_TEST_NOT_RUN;
[+20] [20] 9 lines
[+20] AST_TEST_DEFINE(test_voicemail_msgcount)
11647
		snprintf(tmp[i].txtfile, sizeof(tmp[i].txtfile), "%s.txt", tmp[i].file);
11660
		snprintf(tmp[i].txtfile, sizeof(tmp[i].txtfile), "%s.txt", tmp[i].file);
11648

    
   
11661

   
11649
		if (ast_fileexists(origweasels, "gsm", "en") > 0) {
11662
		if (ast_fileexists(origweasels, "gsm", "en") > 0) {
11650
			snprintf(syscmd, sizeof(syscmd), "cp %s/sounds/en/%s.gsm %s/%s/%s/%s/msg0000.gsm", ast_config_AST_DATA_DIR, origweasels,
11663
			snprintf(syscmd, sizeof(syscmd), "cp %s/sounds/en/%s.gsm %s/%s/%s/%s/msg0000.gsm", ast_config_AST_DATA_DIR, origweasels,
11651
				VM_SPOOL_DIR, testcontext, testmailbox, folders[i]);
11664
				VM_SPOOL_DIR, testcontext, testmailbox, folders[i]);
11652
			j = system(syscmd);
11665
			if ((syserr = system(syscmd))) {

    
   
11666
				ast_test_status_update(test, "Unable to create test voicemail: %s\n",

    
   
11667
					syserr > 0 ? strerror(WEXITSTATUS(syserr)) : "unable to fork()");

    
   
11668
				return AST_TEST_NOT_RUN;

    
   
11669
			}
11653
		}
11670
		}
11654

    
   
11671

   
11655
		if ((txt = fopen(tmp[i].txtfile, "w+"))) {
11672
		if ((txt = fopen(tmp[i].txtfile, "w+"))) {
11656
			fprintf(txt, "; just a stub\n[message]\nflag=%s\n", strcmp(folders[i], "Urgent") ? "" : "Urgent");
11673
			fprintf(txt, "; just a stub\n[message]\nflag=%s\n", strcmp(folders[i], "Urgent") ? "" : "Urgent");
11657
			fclose(txt);
11674
			fclose(txt);
11658
		} else {
11675
		} else {
11659
			ast_test_status_update(test, "Unable to write message file '%s'\n", tmp[i].txtfile);
11676
			ast_test_status_update(test, "Unable to write message file '%s'\n", tmp[i].txtfile);
11660
			res = AST_TEST_FAIL;
11677
			res = AST_TEST_FAIL;
11661
			break;
11678
			break;
11662
		}
11679
		}
11663
		open_mailbox(&vms, vmu, folder2mbox[i]);
11680
		open_mailbox(&vms, vmu, folder2mbox[i]);
11664
		STORE(tmp[i].dir, testmailbox, testcontext, 0, NULL, vmu, "gsm", 600, &vms, strcmp(folders[i], "Urgent") ? "" : "Urgent");
11681
		STORE(tmp[i].dir, testmailbox, testcontext, 0, chan, vmu, "gsm", 600, &vms, strcmp(folders[i], "Urgent") ? "" : "Urgent");
11665

    
   
11682

   
11666
		/* hasvm-old, hasvm-urgent, hasvm-new, ic-old, ic-urgent, ic-new, ic2-old, ic2-urgent, ic2-new, mc-old, mc-urgent, mc-new */
11683
		/* hasvm-old, hasvm-urgent, hasvm-new, ic-old, ic-urgent, ic-new, ic2-old, ic2-urgent, ic2-new, mc-old, mc-urgent, mc-new */
11667
		for (j = 0; j < 3; j++) {
11684
		for (j = 0; j < 3; j++) {
11668
			if (ast_app_has_voicemail(testspec, folders[j]) != expected_results[i][0 + j]) {
11685
			if (ast_app_has_voicemail(testspec, folders[j]) != expected_results[i][0 + j]) {
11669
				ast_test_status_update(test, "has_voicemail(%s, %s) returned %d and we expected %d\n",
11686
				ast_test_status_update(test, "has_voicemail(%s, %s) returned %d and we expected %d\n",
[+20] [20] 18 lines
[+20] AST_TEST_DEFINE(test_voicemail_msgcount)
11688
			res = AST_TEST_FAIL;
11705
			res = AST_TEST_FAIL;
11689
		} else if (old != expected_results[i][6 + 0] ||
11706
		} else if (old != expected_results[i][6 + 0] ||
11690
				urgent != expected_results[i][6 + 1] ||
11707
				urgent != expected_results[i][6 + 1] ||
11691
				   new != expected_results[i][6 + 2]    ) {
11708
				   new != expected_results[i][6 + 2]    ) {
11692
			ast_test_status_update(test, "inboxcount2(%s) returned old=%d (expected %d), urgent=%d (expected %d), and new=%d (expected %d)\n",
11709
			ast_test_status_update(test, "inboxcount2(%s) returned old=%d (expected %d), urgent=%d (expected %d), and new=%d (expected %d)\n",
11693
				testspec, old, expected_results[i][5 + 0], urgent, expected_results[i][5 + 1], new, expected_results[i][5 + 2]);
11710
				testspec, old, expected_results[i][6 + 0], urgent, expected_results[i][6 + 1], new, expected_results[i][6 + 2]);
11694
			res = AST_TEST_FAIL;
11711
			res = AST_TEST_FAIL;
11695
		}
11712
		}
11696

    
   
11713

   
11697
		new = old = urgent = 0;
11714
		new = old = urgent = 0;
11698
		for (j = 0; j < 3; j++) {
11715
		for (j = 0; j < 3; j++) {
11699
			if (ast_app_messagecount(testcontext, testmailbox, folders[j]) != expected_results[i][9 + j]) {
11716
			if (ast_app_messagecount(testcontext, testmailbox, folders[j]) != expected_results[i][9 + j]) {
11700
				ast_test_status_update(test, "messagecount(%s, %s) returned %d and we expected %d\n",
11717
				ast_test_status_update(test, "messagecount(%s, %s) returned %d and we expected %d\n",
11701
					testspec, folders[j], ast_app_messagecount(testcontext, testmailbox, folders[j]), expected_results[i][9 + j]);
11718
					testspec, folders[j], ast_app_messagecount(testcontext, testmailbox, folders[j]), expected_results[i][9 + j]);
11702
				res = AST_TEST_FAIL;
11719
				res = AST_TEST_FAIL;
11703
			}
11720
			}
11704
		}
11721
		}
11705
	}
11722
	}
11706

    
   
11723

   

    
   
11724
	for (i = 0; i < 3; i++) {

    
   
11725
		/* This is necessary if the voicemails are stored on an ODBC/IMAP

    
   
11726
		 * server, in which case, the rm below will not affect the

    
   
11727
		 * voicemails. */

    
   
11728
		DELETE(tmp[i].dir, 0, tmp[i].file, vmu);

    
   
11729
		DISPOSE(tmp[i].dir, 0);

    
   
11730
	}

    
   
11731

   
11707
	if (vms.deleted) {
11732
	if (vms.deleted) {
11708
		ast_free(vms.deleted);
11733
		ast_free(vms.deleted);
11709
	}
11734
	}
11710
	if (vms.heard) {
11735
	if (vms.heard) {
11711
		ast_free(vms.heard);
11736
		ast_free(vms.heard);
11712
	}
11737
	}
11713

    
   
11738

   

    
   
11739
#ifdef IMAP_STORAGE

    
   
11740
	chan = ast_channel_release(chan);

    
   
11741
#endif

    
   
11742

   

    
   
11743
	/* And remove test directory */

    
   
11744
	snprintf(syscmd, sizeof(syscmd), "rm -rf %s%s/%s", VM_SPOOL_DIR, testcontext, testmailbox);

    
   
11745
	if ((syserr = system(syscmd))) {

    
   
11746
		ast_test_status_update(test, "Unable to clear test directory: %s\n",

    
   
11747
			syserr > 0 ? strerror(WEXITSTATUS(syserr)) : "unable to fork()");

    
   
11748
	}

    
   
11749

   
11714
	return res;
11750
	return res;
11715
}
11751
}
11716

    
   
11752

   
11717
static int reload(void)
11753
static int reload(void)
11718
{
11754
{
[+20] [20] 567 lines
  1. /trunk/apps/app_voicemail.c: Loading...

https://reviewboard.asterisk.org/ runs on a server provided by Digium, Inc. and uses bandwidth donated to the open source Asterisk community by API Digital Communications in Huntsville, AL USA.
Please report problems with this site to asteriskteam@digium.com.