mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-04 03:50:31 +00:00
pbx: Create pbx_ignorepat.c for management of 'struct ast_ignorepat'.
This changes context ignore patterns from a linked list to a vector, makes 'struct ast_ignorepat' opaque to pbx.c. Although ast_walk_context_ignorepats 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_ignorepats_count (AST_VECTOR_SIZE) * ast_context_ignorepats_get (AST_VECTOR_GET) As with ast_walk_context_ignorepats callers of these functions are expected to have locked contexts. Only a few places in Asterisk walked the ignorepats, they have been converted to use the new functions. Change-Id: I78f2157d275ef1b7d624b4ff7d770d38e5d7f20a
This commit is contained in:
82
main/pbx_ignorepat.c
Normal file
82
main/pbx_ignorepat.c
Normal file
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* 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 ignorepat 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"
|
||||
|
||||
/*! \brief ast_ignorepat: Ignore patterns in dial plan */
|
||||
struct ast_ignorepat {
|
||||
const char *registrar;
|
||||
const char pattern[0];
|
||||
};
|
||||
|
||||
const char *ast_get_ignorepat_name(const struct ast_ignorepat *ip)
|
||||
{
|
||||
return ip ? ip->pattern : NULL;
|
||||
}
|
||||
|
||||
const char *ast_get_ignorepat_registrar(const struct ast_ignorepat *ip)
|
||||
{
|
||||
return ip ? ip->registrar : NULL;
|
||||
}
|
||||
|
||||
struct ast_ignorepat *ignorepat_alloc(const char *value, const char *registrar)
|
||||
{
|
||||
struct ast_ignorepat *ignorepat;
|
||||
int length = strlen(value) + 1;
|
||||
char *pattern;
|
||||
|
||||
/* allocate new include structure ... */
|
||||
ignorepat = ast_calloc(1, sizeof(*ignorepat) + length);
|
||||
if (!ignorepat) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* The cast to char * is because we need to write the initial value.
|
||||
* The field is not supposed to be modified otherwise. Also, gcc 4.2
|
||||
* sees the cast as dereferencing a type-punned pointer and warns about
|
||||
* it. This is the workaround (we're telling gcc, yes, that's really
|
||||
* what we wanted to do).
|
||||
*/
|
||||
pattern = (char *) ignorepat->pattern;
|
||||
strcpy(pattern, value);
|
||||
ignorepat->registrar = registrar;
|
||||
|
||||
return ignorepat;
|
||||
}
|
||||
|
||||
void ignorepat_free(struct ast_ignorepat *ip)
|
||||
{
|
||||
ast_free(ip);
|
||||
}
|
Reference in New Issue
Block a user