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 4 (Latest)

1 2 3 4
1 2 3 4

  1. trunk/apps/app_directory.c: Loading...
trunk/apps/app_directory.c
Revision 249675 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] 8 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[])
315
			if (res < 0)
333
			if (res < 0)
316
				return -1;
334
				return -1;
317

    
   
335

   
318
			res = 0;
336
			res = 0;
319
		}
337
		}

    
   
338
		res = 0;
320
	}
339
	}
321

    
   
340

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

    
   
344

   
326
static int select_item_menu(struct ast_channel *chan, struct directory_item **items, int count, const char *dialcontext, struct ast_flags *flags)
345
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
{
346
{
328
	struct directory_item **block, *item;
347
	struct directory_item **block, *item;
329
	int i, limit, res = 0;
348
	int i, limit, res = 0;
330
	char buf[9];
349
	char buf[9];
331

    
   
350

   

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

    
   
352
	select_item_pause(chan, flags, opts);

    
   
353

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

    
   
358

   
[+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);
667
			"Not Exiting the Directory!\n", ext);
646
		return -1;
668
		return -1;
647
	}
669
	}
648
}
670
}
649

    
   
671

   
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)
672
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
{
673
{
652
	/* Read in the first three digits..  "digit" is the first digit, already read */
674
	/* Read in the first three digits..  "digit" is the first digit, already read */
653
	int res = 0;
675
	int res = 0;
654
	itemlist alist = AST_LIST_HEAD_NOLOCK_INIT_VALUE;
676
	itemlist alist = AST_LIST_HEAD_NOLOCK_INIT_VALUE;
655
	struct directory_item *item, **ptr, **sorted = NULL;
677
	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
		}
724
		}
703
	}
725
	}
704

    
   
726

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

    
   
734

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

    
   
847

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

    
   
850

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

    
   
854

   
833
		res = ast_waitstream(chan, AST_DIGIT_ANY);
855
		res = ast_waitstream(chan, AST_DIGIT_ANY);
834
		ast_stopstream(chan);
856
		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.