summaryrefslogtreecommitdiff
path: root/main/pbx_include.c
blob: 1bdc39605fecfe1f9c350dc60ac96fc31dd20e60 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
 * 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"

#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);
}