mirror of
				https://github.com/asterisk/asterisk.git
				synced 2025-11-03 20:38:59 +00:00 
			
		
		
		
	This changes context includes from a linked list to a vector, makes 'struct ast_include' opaque to pbx.c. Although ast_walk_context_includes is maintained the procedure is no longer efficient except for the first call (inc==NULL). This functionality is replaced by two new functions implemented by vector macros. * ast_context_includes_count (AST_VECTOR_SIZE) * ast_context_includes_get (AST_VECTOR_GET) As with ast_walk_context_includes callers of these functions are expected to have locked contexts. Only a few places in Asterisk walked the includes, they have been converted to use the new functions. const have been applied where possible to parameters for ast_include functions. Change-Id: Ib5c882e27cf96fb2aec67a39c18b4c71c9c83b60
		
			
				
	
	
		
			113 lines
		
	
	
		
			2.4 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			113 lines
		
	
	
		
			2.4 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
/*
 | 
						|
 * Asterisk -- An open source telephony toolkit.
 | 
						|
 *
 | 
						|
 * Copyright (C) 2016, CFWare, LLC
 | 
						|
 *
 | 
						|
 * Corey Farrell <git@cfware.com>
 | 
						|
 *
 | 
						|
 * See http://www.asterisk.org for more information about
 | 
						|
 * the Asterisk project. Please do not directly contact
 | 
						|
 * any of the maintainers of this project for assistance;
 | 
						|
 * the project provides a web site, mailing lists and IRC
 | 
						|
 * channels for your use.
 | 
						|
 *
 | 
						|
 * This program is free software, distributed under the terms of
 | 
						|
 * the GNU General Public License Version 2. See the LICENSE file
 | 
						|
 * at the top of the source tree.
 | 
						|
 */
 | 
						|
 | 
						|
/*! \file
 | 
						|
 *
 | 
						|
 * \brief Dialplan context include routines.
 | 
						|
 *
 | 
						|
 * \author Corey Farrell <git@cfware.com>
 | 
						|
 */
 | 
						|
 | 
						|
/*** MODULEINFO
 | 
						|
	<support_level>core</support_level>
 | 
						|
 ***/
 | 
						|
 | 
						|
#include "asterisk.h"
 | 
						|
 | 
						|
ASTERISK_REGISTER_FILE()
 | 
						|
 | 
						|
#include "asterisk/_private.h"
 | 
						|
#include "asterisk/pbx.h"
 | 
						|
#include "pbx_private.h"
 | 
						|
 | 
						|
/*! ast_include: include= support in extensions.conf */
 | 
						|
struct ast_include {
 | 
						|
	const char *name;
 | 
						|
	/*! Context to include */
 | 
						|
	const char *rname;
 | 
						|
	/*! Registrar */
 | 
						|
	const char *registrar;
 | 
						|
	/*! If time construct exists */
 | 
						|
	int hastime;
 | 
						|
	/*! time construct */
 | 
						|
	struct ast_timing timing;
 | 
						|
	char stuff[0];
 | 
						|
};
 | 
						|
 | 
						|
const char *ast_get_include_name(const struct ast_include *inc)
 | 
						|
{
 | 
						|
	return inc ? inc->name : NULL;
 | 
						|
}
 | 
						|
 | 
						|
const char *include_rname(const struct ast_include *inc)
 | 
						|
{
 | 
						|
	return inc ? inc->rname : NULL;
 | 
						|
}
 | 
						|
 | 
						|
const char *ast_get_include_registrar(const struct ast_include *inc)
 | 
						|
{
 | 
						|
	return inc ? inc->registrar : NULL;
 | 
						|
}
 | 
						|
 | 
						|
int include_valid(const struct ast_include *inc)
 | 
						|
{
 | 
						|
	if (!inc->hastime) {
 | 
						|
		return 1;
 | 
						|
	}
 | 
						|
 | 
						|
	return ast_check_timing(&(inc->timing));
 | 
						|
}
 | 
						|
 | 
						|
struct ast_include *include_alloc(const char *value, const char *registrar)
 | 
						|
{
 | 
						|
	struct ast_include *new_include;
 | 
						|
	char *c;
 | 
						|
	int valuebufsz = strlen(value) + 1;
 | 
						|
	char *p;
 | 
						|
 | 
						|
	/* allocate new include structure ... */
 | 
						|
	new_include = ast_calloc(1, sizeof(*new_include) + (valuebufsz * 2));
 | 
						|
	if (!new_include) {
 | 
						|
		return NULL;
 | 
						|
	}
 | 
						|
 | 
						|
	/* Fill in this structure. Use 'p' for assignments, as the fields
 | 
						|
	 * in the structure are 'const char *'
 | 
						|
	 */
 | 
						|
	p = new_include->stuff;
 | 
						|
	new_include->name = p;
 | 
						|
	strcpy(p, value);
 | 
						|
	p += valuebufsz;
 | 
						|
	new_include->rname = p;
 | 
						|
	strcpy(p, value);
 | 
						|
	/* Strip off timing info, and process if it is there */
 | 
						|
	if ((c = strchr(p, ',')) ) {
 | 
						|
		*c++ = '\0';
 | 
						|
		new_include->hastime = ast_build_timing(&(new_include->timing), c);
 | 
						|
	}
 | 
						|
	new_include->registrar = registrar;
 | 
						|
 | 
						|
	return new_include;
 | 
						|
}
 | 
						|
 | 
						|
void include_free(struct ast_include *inc)
 | 
						|
{
 | 
						|
	ast_destroy_timing(&(inc->timing));
 | 
						|
	ast_free(inc);
 | 
						|
}
 |