Review Board 1.7.16


Add aliases for Directory

Review Request #2244 - Created Dec. 12, 2012 and submitted

Tilghman Lesher
Reviewers
asterisk-dev
Asterisk
This patch adds extra strings for comparison in the Directory application.  The purpose of this is to enable nicknames that otherwise would not be compared.  For example, Bob "Bongo Boy" Berman might have an alias of "Bongo", for which he would be searchable, even though his name would not normally include it.
Deployed and working on a production machine.

Diff revision 2

This is not the most recent revision of the diff. The latest diff is revision 3. See what's changed.

1 2 3
1 2 3

  1. /trunk/apps/app_directory.c: Loading...
  2. /trunk/configs/voicemail.conf.sample: Loading...
  3. /trunk/contrib/realtime/mysql/voicemail.sql: Loading...
/trunk/apps/app_directory.c
Revision 377511 New Change
[20] 424 lines
[+20] [+] static int select_item_menu(struct ast_channel *chan, struct directory_item **items, int count, const char *dialcontext, struct ast_flags *flags, char *opts[])
425

    
   
425

   
426
	/* Nothing was selected */
426
	/* Nothing was selected */
427
	return 0;
427
	return 0;
428
}
428
}
429

    
   
429

   

    
   
430
AST_THREADSTORAGE(commonbuf);

    
   
431

   
430
static struct ast_config *realtime_directory(char *context)
432
static struct ast_config *realtime_directory(char *context)
431
{
433
{
432
	struct ast_config *cfg;
434
	struct ast_config *cfg;
433
	struct ast_config *rtdata;
435
	struct ast_config *rtdata;
434
	struct ast_category *cat;
436
	struct ast_category *cat;
435
	struct ast_variable *var;
437
	struct ast_variable *var;
436
	char *mailbox;
438
	char *mailbox;
437
	const char *fullname;
439
	const char *fullname;
438
	const char *hidefromdir, *searchcontexts = NULL;
440
	const char *hidefromdir, *searchcontexts = NULL;
439
	char tmp[100];

   
440
	struct ast_flags config_flags = { 0 };
441
	struct ast_flags config_flags = { 0 };

    
   
442
	struct ast_str *tmp = ast_str_thread_get(&commonbuf, 100);

    
   
443

   

    
   
444
	if (!tmp) {

    
   
445
		return NULL;

    
   
446
	}
441

    
   
447

   
442
	/* Load flat file config. */
448
	/* Load flat file config. */
443
	cfg = ast_config_load(VOICEMAIL_CONFIG, config_flags);
449
	cfg = ast_config_load(VOICEMAIL_CONFIG, config_flags);
444

    
   
450

   
445
	if (!cfg) {
451
	if (!cfg) {
[+20] [20] 24 lines
[+20] static struct ast_config *realtime_directory(char *context)
470
		return cfg;
476
		return cfg;
471
	}
477
	}
472

    
   
478

   
473
	mailbox = NULL;
479
	mailbox = NULL;
474
	while ( (mailbox = ast_category_browse(rtdata, mailbox)) ) {
480
	while ( (mailbox = ast_category_browse(rtdata, mailbox)) ) {

    
   
481
		struct ast_variable *alias;
475
		const char *ctx = ast_variable_retrieve(rtdata, mailbox, "context");
482
		const char *ctx = ast_variable_retrieve(rtdata, mailbox, "context");
476

    
   
483

   
477
		fullname = ast_variable_retrieve(rtdata, mailbox, "fullname");
484
		fullname = ast_variable_retrieve(rtdata, mailbox, "fullname");
478
		hidefromdir = ast_variable_retrieve(rtdata, mailbox, "hidefromdir");
485
		hidefromdir = ast_variable_retrieve(rtdata, mailbox, "hidefromdir");
479
		if (ast_true(hidefromdir)) {
486
		if (ast_true(hidefromdir)) {
480
			/* Skip hidden */
487
			/* Skip hidden */
481
			continue;
488
			continue;
482
		}
489
		}
483
		snprintf(tmp, sizeof(tmp), "no-password,%s", S_OR(fullname, ""));
490
		ast_str_set(&tmp, 0, "no-password,%s", S_OR(fullname, ""));

    
   
491
		if (ast_variable_retrieve(rtdata, mailbox, "alias")) {

    
   
492
			for (alias = ast_variable_browse(rtdata, mailbox); alias; alias = alias->next) {

    
   
493
				if (!strcasecmp(alias->name, "alias")) {

    
   
494
					ast_str_append(&tmp, 0, "|alias=%s", alias->value);

    
   
495
				}

    
   
496
			}

    
   
497
		}
484

    
   
498

   
485
		/* Does the context exist within the config file? If not, make one */
499
		/* Does the context exist within the config file? If not, make one */
486
		if (!(cat = ast_category_get(cfg, ctx))) {
500
		if (!(cat = ast_category_get(cfg, ctx))) {
487
			if (!(cat = ast_category_new(ctx, "", 99999))) {
501
			if (!(cat = ast_category_new(ctx, "", 99999))) {
488
				ast_log(LOG_WARNING, "Out of memory\n");
502
				ast_log(LOG_WARNING, "Out of memory\n");
[+20] [20] 4 lines
[+20] static struct ast_config *realtime_directory(char *context)
493
				return NULL;
507
				return NULL;
494
			}
508
			}
495
			ast_category_append(cfg, cat);
509
			ast_category_append(cfg, cat);
496
		}
510
		}
497

    
   
511

   
498
		if ((var = ast_variable_new(mailbox, tmp, ""))) {
512
		if ((var = ast_variable_new(mailbox, ast_str_buffer(tmp), ""))) {
499
			ast_variable_append(cat, var);
513
			ast_variable_append(cat, var);
500
		} else {
514
		} else {
501
			ast_log(LOG_WARNING, "Out of memory adding mailbox '%s'\n", mailbox);
515
			ast_log(LOG_WARNING, "Out of memory adding mailbox '%s'\n", mailbox);
502
		}
516
		}
503
	}
517
	}
[+20] [20] 50 lines
[+20] [+] static int check_match(struct directory_item **result, const char *item_context, const char *item_fullname, const char *item_ext, const char *pattern_ext, int use_first_name)
554
typedef AST_LIST_HEAD_NOLOCK(, directory_item) itemlist;
568
typedef AST_LIST_HEAD_NOLOCK(, directory_item) itemlist;
555

    
   
569

   
556
static int search_directory_sub(const char *context, struct ast_config *vmcfg, struct ast_config *ucfg, const char *ext, struct ast_flags flags, itemlist *alist)
570
static int search_directory_sub(const char *context, struct ast_config *vmcfg, struct ast_config *ucfg, const char *ext, struct ast_flags flags, itemlist *alist)
557
{
571
{
558
	struct ast_variable *v;
572
	struct ast_variable *v;
559
	char buf[AST_MAX_EXTENSION + 1], *pos, *bufptr, *cat;
573
	struct ast_str *buf = ast_str_thread_get(&commonbuf, 100);

    
   
574
	char *pos, *bufptr, *cat, *alias;
560
	struct directory_item *item;
575
	struct directory_item *item;
561
	int res;
576
	int res;
562

    
   
577

   

    
   
578
	if (!buf) {

    
   
579
		return -1;

    
   
580
	}

    
   
581

   
563
	ast_debug(2, "Pattern: %s\n", ext);
582
	ast_debug(2, "Pattern: %s\n", ext);
564

    
   
583

   
565
	for (v = ast_variable_browse(vmcfg, context); v; v = v->next) {
584
	for (v = ast_variable_browse(vmcfg, context); v; v = v->next) {
566

    
   
585

   
567
		/* Ignore hidden */
586
		/* Ignore hidden */
568
		if (strcasestr(v->value, "hidefromdir=yes"))
587
		if (strcasestr(v->value, "hidefromdir=yes")) {
569
			continue;
588
			continue;

    
   
589
		}
570

    
   
590

   
571
		ast_copy_string(buf, v->value, sizeof(buf));
591
		ast_str_set(&buf, 0, "%s", v->value);
572
		bufptr = buf;
592
		bufptr = ast_str_buffer(buf);
573

    
   
593

   
574
		/* password,Full Name,email,pager,options */
594
		/* password,Full Name,email,pager,options */
575
		strsep(&bufptr, ",");
595
		strsep(&bufptr, ",");
576
		pos = strsep(&bufptr, ",");
596
		pos = strsep(&bufptr, ",");
577

    
   
597

   
[+20] [20] 7 lines
[+20] static int search_directory_sub(const char *context, struct ast_config *vmcfg, struct ast_config *ucfg, const char *ext, struct ast_flags flags, itemlist *alist)
585
			res = check_match(&item, context, pos, v->name, ext, 0 /* use_first_name */);
605
			res = check_match(&item, context, pos, v->name, ext, 0 /* use_first_name */);
586
		}
606
		}
587
		if (!res && ast_test_flag(&flags, OPT_LISTBYFIRSTNAME)) {
607
		if (!res && ast_test_flag(&flags, OPT_LISTBYFIRSTNAME)) {
588
			res = check_match(&item, context, pos, v->name, ext, 1 /* use_first_name */);
608
			res = check_match(&item, context, pos, v->name, ext, 1 /* use_first_name */);
589
		}
609
		}

    
   
610
		if (!res && (alias = strcasestr(bufptr, "alias="))) {

    
   
611
			char *a;

    
   
612
			ast_debug(1, "Found alias: %s\n", alias);

    
   
613
			while ((a = strsep(&alias, "|"))) {

    
   
614
				if (!strncasecmp(a, "alias=", 6)) {

    
   
615
					if ((res = check_match(&item, context, a + 6, v->name, ext, 1))) {

    
   
616
						break;

    
   
617
					}

    
   
618
				}

    
   
619
			}

    
   
620
		}
590

    
   
621

   
591
		if (!res)
622
		if (!res) {
592
			continue;
623
			continue;
593
		else if (res < 0)
624
		} else if (res < 0) {
594
			return -1;
625
			return -1;

    
   
626
		}
595

    
   
627

   
596
		AST_LIST_INSERT_TAIL(alist, item, entry);
628
		AST_LIST_INSERT_TAIL(alist, item, entry);
597
	}
629
	}
598

    
   
630

   
599
	if (ucfg) {
631
	if (ucfg) {
600
		for (cat = ast_category_browse(ucfg, NULL); cat ; cat = ast_category_browse(ucfg, cat)) {
632
		for (cat = ast_category_browse(ucfg, NULL); cat ; cat = ast_category_browse(ucfg, cat)) {
601
			const char *position;
633
			const char *position;
602
			if (!strcasecmp(cat, "general"))
634

   

    
   
635
			if (!strcasecmp(cat, "general")) {
603
				continue;
636
				continue;
604
			if (!ast_true(ast_config_option(ucfg, cat, "hasdirectory")))
637
			}

    
   
638
			if (!ast_true(ast_config_option(ucfg, cat, "hasdirectory"))) {
605
				continue;
639
				continue;

    
   
640
			}
606

    
   
641

   
607
			/* Find all candidate extensions */
642
			/* Find all candidate extensions */
608
			position = ast_variable_retrieve(ucfg, cat, "fullname");
643
			if (!(position = ast_variable_retrieve(ucfg, cat, "fullname"))) {
609
			if (!position)

   
610
				continue;
644
				continue;

    
   
645
			}
611

    
   
646

   
612
			res = 0;
647
			res = 0;
613
			if (ast_test_flag(&flags, OPT_LISTBYLASTNAME)) {
648
			if (ast_test_flag(&flags, OPT_LISTBYLASTNAME)) {
614
				res = check_match(&item, context, position, cat, ext, 0 /* use_first_name */);
649
				res = check_match(&item, context, position, cat, ext, 0 /* use_first_name */);
615
			}
650
			}
616
			if (!res && ast_test_flag(&flags, OPT_LISTBYFIRSTNAME)) {
651
			if (!res && ast_test_flag(&flags, OPT_LISTBYFIRSTNAME)) {
617
				res = check_match(&item, context, position, cat, ext, 1 /* use_first_name */);
652
				res = check_match(&item, context, position, cat, ext, 1 /* use_first_name */);
618
			}
653
			}

    
   
654
			if (!res) {

    
   
655
				struct ast_variable *alias;

    
   
656
				for (alias = ast_variable_browse(ucfg, cat); alias; alias = alias->next) {

    
   
657
					if (!strcasecmp(v->name, "alias") && (res = check_match(&item, context, v->value, cat, ext, 1))) {

    
   
658
						break;

    
   
659
					}

    
   
660
				}

    
   
661
			}
619

    
   
662

   
620
			if (!res)
663
			if (!res) {
621
				continue;
664
				continue;
622
			else if (res < 0)
665
			} else if (res < 0) {
623
				return -1;
666
				return -1;

    
   
667
			}
624

    
   
668

   
625
			AST_LIST_INSERT_TAIL(alist, item, entry);
669
			AST_LIST_INSERT_TAIL(alist, item, entry);
626
		}
670
		}
627
	}
671
	}
628
	return 0;
672
	return 0;
[+20] [20] 265 lines
/trunk/configs/voicemail.conf.sample
Revision 377511 New Change
 
/trunk/contrib/realtime/mysql/voicemail.sql
Revision 377511 New Change
 
  1. /trunk/apps/app_directory.c: Loading...
  2. /trunk/configs/voicemail.conf.sample: Loading...
  3. /trunk/contrib/realtime/mysql/voicemail.sql: 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.