Review Board 1.7.16


app_directory, support option 'p(n)' as documented with CLI online help, branches 1.6.1 to trunk.

Review Request #481 - Created Feb. 1, 2010 and submitted

Alec Davis
trunk
16751
Reviewers
asterisk-dev
Asterisk
finish off preliminary work done for initial pause before presenting directory name to caller.

Currently, 'core show application DIRECTORY' from 1.6.1 through to trunk indicates the 'p(n)' option is available, where in fact there is no code to act on it, other than to populate opts[OPT_ARG_PAUSE].
1.6.1 production server.
'p' on it own doesn't introduce delay, as expected.
'p(1000)' introduces 1 second delay after intial 3 letters are entered, then presents names individually.
'mp(1000)' introduces 1 second delay after intial 3 letters are entered, then presents names as a list.
'p(6000)' enforces a maximum of a 3 second delay.

Diff revision 3

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

1 2 3 4
1 2 3 4

  1. trunk/apps/app_directory.c: Loading...
trunk/apps/app_directory.c
Revision 244325 New Change
[20] 285 lines
[+20] [+] static int select_entry(struct ast_channel *chan, const char *dialcontext, const struct directory_item *item, struct ast_flags *flags)
286
	}
286
	}
287

    
   
287

   
288
	return 0;
288
	return 0;
289
}
289
}
290

    
   
290

   
291
static int select_item_seq(struct ast_channel *chan, struct directory_item **items, int count, const char *dialcontext, struct ast_flags *flags)
291
static int select_item_pause(struct ast_channel *chan, struct ast_flags *flags, char *opts[])

    
   
292
{

    
   
293
	int res = 0, opt_pause = 0;

    
   
294

   

    
   
295
	if (ast_test_flag(flags, OPT_PAUSE) && !ast_strlen_zero(opts[OPT_ARG_PAUSE])) {

    
   
296
		opt_pause = atoi(opts[OPT_ARG_PAUSE]);

    
   
297
		if (opt_pause > 3000) {

    
   
298
			opt_pause = 3000;

    
   
299
		}

    
   
300
		res = ast_waitfordigit(chan, opt_pause);

    
   
301
	}

    
   
302
	return res;

    
   
303
}

    
   
304

   

    
   
305
static int select_item_seq(struct ast_channel *chan, struct directory_item **items, int count, const char *dialcontext, struct ast_flags *flags, char *opts[])
292
{
306
{
293
	struct directory_item *item, **ptr;
307
	struct directory_item *item, **ptr;
294
	int i, res, loop;
308
	int i, res, loop;
295

    
   
309

   

    
   
310
	/* option p(n): cellphone pause option */

    
   
311
	/* allow early press of selection key */

    
   
312
	res = select_item_pause(chan, flags, opts);

    
   
313

   
296
	for (ptr = items, i = 0; i < count; i++, ptr++) {
314
	for (ptr = items, i = 0; i < count; i++, ptr++) {
297
		item = *ptr;
315
		item = *ptr;
298

    
   
316

   
299
		for (loop = 3 ; loop > 0; loop--) {
317
		for (loop = 3 ; loop > 0; loop--) {

    
   
318
			if (!res)
300
			res = play_mailbox_owner(chan, item->context, item->exten, item->name, flags);
319
				res = play_mailbox_owner(chan, item->context, item->exten, item->name, flags);
301

    
   

   
302
			if (!res)
320
			if (!res)
303
				res = ast_stream_and_wait(chan, "dir-instr", AST_DIGIT_ANY);
321
				res = ast_stream_and_wait(chan, "dir-instr", AST_DIGIT_ANY);
304
			if (!res)
322
			if (!res)
305
				res = ast_waitfordigit(chan, 3000);
323
				res = ast_waitfordigit(chan, 3000);
306
			ast_stopstream(chan);
324
			ast_stopstream(chan);
[+20] [20] 14 lines
[+20] static int select_item_seq(struct ast_channel *chan, struct directory_item **items, int count, const char *dialcontext, struct ast_flags *flags) static int select_item_pause(struct ast_channel *chan, struct ast_flags *flags, char *opts[])
321

    
   
339

   
322
	/* Nothing was selected */
340
	/* Nothing was selected */
323
	return 0;
341
	return 0;
324
}
342
}
325

    
   
343

   
326
static int select_item_menu(struct ast_channel *chan, struct directory_item **items, int count, const char *dialcontext, struct ast_flags *flags)
344
static int select_item_menu(struct ast_channel *chan, struct directory_item **items, int count, const char *dialcontext, struct ast_flags *flags, char *opts[])
327
{
345
{
328
	struct directory_item **block, *item;
346
	struct directory_item **block, *item;
329
	int i, limit, res = 0;
347
	int i, limit, res = 0;
330
	char buf[9];
348
	char buf[9];
331

    
   
349

   

    
   
350
	/* option p(n): cellphone pause option */

    
   
351
	select_item_pause(chan, flags, opts);

    
   
352

   
332
	for (block = items; count; block += limit, count -= limit) {
353
	for (block = items; count; block += limit, count -= limit) {
333
		limit = count;
354
		limit = count;
334
		if (limit > 8)
355
		if (limit > 8)
335
			limit = 8;
356
			limit = 8;
336

    
   
357

   
[+20] [20] 308 lines
[+20] [+] static int goto_exten(struct ast_channel *chan, const char *dialcontext, char *ext)
645
			"Not Exiting the Directory!\n", ext);
666
			"Not Exiting the Directory!\n", ext);
646
		return -1;
667
		return -1;
647
	}
668
	}
648
}
669
}
649

    
   
670

   
650
static int do_directory(struct ast_channel *chan, struct ast_config *vmcfg, struct ast_config *ucfg, char *context, char *dialcontext, char digit, int digits, struct ast_flags *flags)
671
static int do_directory(struct ast_channel *chan, struct ast_config *vmcfg, struct ast_config *ucfg, char *context, char *dialcontext, char digit, int digits, struct ast_flags *flags, char *opts[])
651
{
672
{
652
	/* Read in the first three digits..  "digit" is the first digit, already read */
673
	/* Read in the first three digits..  "digit" is the first digit, already read */
653
	int res = 0;
674
	int res = 0;
654
	itemlist alist = AST_LIST_HEAD_NOLOCK_INIT_VALUE;
675
	itemlist alist = AST_LIST_HEAD_NOLOCK_INIT_VALUE;
655
	struct directory_item *item, **ptr, **sorted = NULL;
676
	struct directory_item *item, **ptr, **sorted = NULL;
[+20] [20] 46 lines
[+20] static int do_directory(struct ast_channel *chan, struct ast_config *vmcfg, struct ast_config *ucfg, char *context, char *dialcontext, char digit, int digits, struct ast_flags *flags) [+] static int do_directory(struct ast_channel *chan, struct ast_config *vmcfg, struct ast_config *ucfg, char *context, char *dialcontext, char digit, int digits, struct ast_flags *flags, char *opts[])
702
		}
723
		}
703
	}
724
	}
704

    
   
725

   
705
	if (ast_test_flag(flags, OPT_SELECTFROMMENU)) {
726
	if (ast_test_flag(flags, OPT_SELECTFROMMENU)) {
706
		/* Offer multiple entries at the same time */
727
		/* Offer multiple entries at the same time */
707
		res = select_item_menu(chan, sorted, count, dialcontext, flags);
728
		res = select_item_menu(chan, sorted, count, dialcontext, flags, opts);
708
	} else {
729
	} else {
709
		/* Offer entries one by one */
730
		/* Offer entries one by one */
710
		res = select_item_seq(chan, sorted, count, dialcontext, flags);
731
		res = select_item_seq(chan, sorted, count, dialcontext, flags, opts);
711
	}
732
	}
712

    
   
733

   
713
	if (!res) {
734
	if (!res) {
714
		res = ast_streamfile(chan, "dir-nomore", chan->language);
735
		res = ast_streamfile(chan, "dir-nomore", chan->language);
715
	}
736
	}
[+20] [20] 108 lines
[+20] [+] static int directory_exec(struct ast_channel *chan, const char *data)
824
			res = ast_waitfordigit(chan, 5000);
845
			res = ast_waitfordigit(chan, 5000);
825

    
   
846

   
826
		if (res <= 0)
847
		if (res <= 0)
827
			break;
848
			break;
828

    
   
849

   
829
		res = do_directory(chan, cfg, ucfg, args.vmcontext, args.dialcontext, res, digit, &flags);
850
		res = do_directory(chan, cfg, ucfg, args.vmcontext, args.dialcontext, res, digit, &flags, opts);
830
		if (res)
851
		if (res)
831
			break;
852
			break;
832

    
   
853

   
833
		res = ast_waitstream(chan, AST_DIGIT_ANY);
854
		res = ast_waitstream(chan, AST_DIGIT_ANY);
834
		ast_stopstream(chan);
855
		ast_stopstream(chan);
[+20] [20] 25 lines
  1. trunk/apps/app_directory.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.