summaryrefslogtreecommitdiff
path: root/main/pbx_ignorepat.c
diff options
context:
space:
mode:
authorCorey Farrell <git@cfware.com>2016-07-15 03:59:48 -0400
committerCorey Farrell <git@cfware.com>2016-07-18 03:21:43 -0400
commite2e8713b8405cee26ed40be092bf1320ed9b29db (patch)
tree480d601c66ebf7bacb20acca4d6cd23f4d8d6336 /main/pbx_ignorepat.c
parentbe36bd7ca565531c09ca444e59b6d057131a9ab0 (diff)
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
Diffstat (limited to 'main/pbx_ignorepat.c')
-rw-r--r--main/pbx_ignorepat.c82
1 files changed, 82 insertions, 0 deletions
diff --git a/main/pbx_ignorepat.c b/main/pbx_ignorepat.c
new file mode 100644
index 000000000..1a2232c57
--- /dev/null
+++ b/main/pbx_ignorepat.c
@@ -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);
+}