Debian Codegraph @

main/pbx_sw.c

raw symbols SCIP
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 switch 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 /*! \brief ast_sw: Switch statement in extensions.conf */
37 struct ast_sw {
38 const char *name;
39 /*! Registrar */
40 const char *registrar;
41 /*! Data load */
42 const char *data;
43 int eval;
44 AST_LIST_ENTRY(ast_sw) list;
45 char stuff[0];
46 };
47
48 const char *ast_get_switch_name(const struct ast_sw *sw)
49 {
50 return sw ? sw->name : NULL;
51 }
52
53 const char *ast_get_switch_data(const struct ast_sw *sw)
54 {
55 return sw ? sw->data : NULL;
56 }
57
58 int ast_get_switch_eval(const struct ast_sw *sw)
59 {
60 return sw->eval;
61 }
62
63 const char *ast_get_switch_registrar(const struct ast_sw *sw)
64 {
65 return sw ? sw->registrar : NULL;
66 }
67
68 struct ast_sw *sw_alloc(const char *value, const char *data, int eval, const char *registrar)
69 {
70 struct ast_sw *new_sw;
71 int length;
72 char *p;
73
74 if (!data) {
75 data = "";
76 }
77 length = sizeof(struct ast_sw);
78 length += strlen(value) + 1;
79 length += strlen(data) + 1;
80
81 /* allocate new sw structure ... */
82 if (!(new_sw = ast_calloc(1, length))) {
83 return NULL;
84 }
85
86 /* ... fill in this structure ... */
87 p = new_sw->stuff;
88 new_sw->name = p;
89 strcpy(p, value);
90
91 p += strlen(value) + 1;
92 new_sw->data = p;
93 strcpy(p, data);
94
95 new_sw->eval = eval;
96 new_sw->registrar = registrar;
97
98 return new_sw;
99 }
100
101 void sw_free(struct ast_sw *sw)
102 {
103 ast_free(sw);
104 }