summaryrefslogtreecommitdiff
path: root/main/pbx_include.c
diff options
context:
space:
mode:
authorCorey Farrell <git@cfware.com>2016-07-14 14:51:42 -0400
committerCorey Farrell <git@cfware.com>2016-07-15 05:34:29 -0400
commitbe36bd7ca565531c09ca444e59b6d057131a9ab0 (patch)
tree85595a26df4bbfcfc39a78c5c2474984c8c894ce /main/pbx_include.c
parent273052f40498378d3f2d3548347a243df68ee9a4 (diff)
pbx: Create pbx_include.c for management of 'struct ast_include'.
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
Diffstat (limited to 'main/pbx_include.c')
-rw-r--r--main/pbx_include.c112
1 files changed, 112 insertions, 0 deletions
diff --git a/main/pbx_include.c b/main/pbx_include.c
new file mode 100644
index 000000000..46a41fb20
--- /dev/null
+++ b/main/pbx_include.c
@@ -0,0 +1,112 @@
+/*
+ * 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);
+}