Asterisk - The Open Source Telephony Project  18.5.0
pbx_include.c
Go to the documentation of this file.
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 2016, CFWare, LLC
5  *
6  * Corey Farrell <[email protected]>
7  *
8  * See http://www.asterisk.org for more information about
9  * the Asterisk project. Please do not directly contact
10  * any of the maintainers of this project for assistance;
11  * the project provides a web site, mailing lists and IRC
12  * channels for your use.
13  *
14  * This program is free software, distributed under the terms of
15  * the GNU General Public License Version 2. See the LICENSE file
16  * at the top of the source tree.
17  */
18 
19 /*! \file
20  *
21  * \brief Dialplan context include routines.
22  *
23  * \author Corey Farrell <[email protected]>
24  */
25 
26 /*** MODULEINFO
27  <support_level>core</support_level>
28  ***/
29 
30 #include "asterisk.h"
31 
32 #include "asterisk/_private.h"
33 #include "asterisk/pbx.h"
34 #include "pbx_private.h"
35 
36 /*! ast_include: include= support in extensions.conf */
37 struct ast_include {
38  const char *name;
39  /*! Context to include */
40  const char *rname;
41  /*! Registrar */
42  const char *registrar;
43  /*! If time construct exists */
44  int hastime;
45  /*! time construct */
47  char stuff[0];
48 };
49 
50 const char *ast_get_include_name(const struct ast_include *inc)
51 {
52  return inc ? inc->name : NULL;
53 }
54 
55 const char *include_rname(const struct ast_include *inc)
56 {
57  return inc ? inc->rname : NULL;
58 }
59 
60 const char *ast_get_include_registrar(const struct ast_include *inc)
61 {
62  return inc ? inc->registrar : NULL;
63 }
64 
65 int include_valid(const struct ast_include *inc)
66 {
67  if (!inc->hastime) {
68  return 1;
69  }
70 
71  return ast_check_timing(&(inc->timing));
72 }
73 
74 struct ast_include *include_alloc(const char *value, const char *registrar)
75 {
76  struct ast_include *new_include;
77  char *c;
78  int valuebufsz = strlen(value) + 1;
79  char *p;
80 
81  /* allocate new include structure ... */
82  new_include = ast_calloc(1, sizeof(*new_include) + (valuebufsz * 2));
83  if (!new_include) {
84  return NULL;
85  }
86 
87  /* Fill in this structure. Use 'p' for assignments, as the fields
88  * in the structure are 'const char *'
89  */
90  p = new_include->stuff;
91  new_include->name = p;
92  strcpy(p, value);
93  p += valuebufsz;
94  new_include->rname = p;
95  strcpy(p, value);
96  /* Strip off timing info, and process if it is there */
97  if ((c = strchr(p, ',')) ) {
98  *c++ = '\0';
99  new_include->hastime = ast_build_timing(&(new_include->timing), c);
100  }
101  new_include->registrar = registrar;
102 
103  return new_include;
104 }
105 
106 void include_free(struct ast_include *inc)
107 {
108  ast_destroy_timing(&(inc->timing));
109  ast_free(inc);
110 }
ast_include: include= support in extensions.conf
Definition: pbx_include.c:37
Asterisk main include file. File version handling, generic pbx functions.
Private include file for pbx.
struct ast_include * include_alloc(const char *value, const char *registrar)
Definition: pbx_include.c:74
void include_free(struct ast_include *inc)
Definition: pbx_include.c:106
const char * include_rname(const struct ast_include *inc)
Definition: pbx_include.c:55
static struct test_val c
#define NULL
Definition: resample.c:96
const char * ast_get_include_name(const struct ast_include *inc)
Definition: pbx_include.c:50
int include_valid(const struct ast_include *inc)
Definition: pbx_include.c:65
int value
Definition: syslog.c:37
char stuff[0]
Definition: pbx_include.c:47
struct ast_timing timing
Definition: pbx_include.c:46
Core PBX routines and definitions.
const char * ast_get_include_registrar(const struct ast_include *inc)
Definition: pbx_include.c:60
int ast_check_timing(const struct ast_timing *i)
Evaluate a pre-constructed bitmap as to whether the current time falls within the range specified...
Definition: extconf.c:4002
int ast_destroy_timing(struct ast_timing *i)
Deallocates memory structures associated with a timing bitmap.
Definition: pbx_timing.c:285
#define ast_free(a)
Definition: astmm.h:182
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:204
Prototypes for public functions only of internal interest,.
const char * name
Definition: pbx_include.c:38
int ast_build_timing(struct ast_timing *i, const char *info)
Construct a timing bitmap, for use in time-based conditionals.
Definition: extconf.c:3808
const char * rname
Definition: pbx_include.c:40
const char * registrar
Definition: pbx_include.c:42