Asterisk - The Open Source Telephony Project GIT-master-2de1a68
pbx_sw.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 <git@cfware.com>
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 <git@cfware.com>
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 */
37struct ast_sw {
38 const char *name;
39 /*! Registrar */
40 const char *registrar;
41 /*! Data load */
42 const char *data;
43 int eval;
45 char stuff[0];
46};
47
48const char *ast_get_switch_name(const struct ast_sw *sw)
49{
50 return sw ? sw->name : NULL;
51}
52
53const char *ast_get_switch_data(const struct ast_sw *sw)
54{
55 return sw ? sw->data : NULL;
56}
57
58int ast_get_switch_eval(const struct ast_sw *sw)
59{
60 return sw->eval;
61}
62
63const char *ast_get_switch_registrar(const struct ast_sw *sw)
64{
65 return sw ? sw->registrar : NULL;
66}
67
68struct 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
101void sw_free(struct ast_sw *sw)
102{
103 ast_free(sw);
104}
Prototypes for public functions only of internal interest,.
Asterisk main include file. File version handling, generic pbx functions.
#define ast_free(a)
Definition: astmm.h:180
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:202
#define AST_LIST_ENTRY(type)
Declare a forward link structure inside a list entry.
Definition: linkedlists.h:410
Core PBX routines and definitions.
static char * registrar
Definition: pbx_ael.c:78
Private include file for pbx.
const char * ast_get_switch_name(const struct ast_sw *sw)
Definition: pbx_sw.c:48
const char * ast_get_switch_data(const struct ast_sw *sw)
Definition: pbx_sw.c:53
struct ast_sw * sw_alloc(const char *value, const char *data, int eval, const char *registrar)
Definition: pbx_sw.c:68
void sw_free(struct ast_sw *sw)
Definition: pbx_sw.c:101
int ast_get_switch_eval(const struct ast_sw *sw)
Definition: pbx_sw.c:58
const char * ast_get_switch_registrar(const struct ast_sw *sw)
Definition: pbx_sw.c:63
#define NULL
Definition: resample.c:96
ast_sw: Switch statement in extensions.conf
Definition: pbx_sw.c:37
char stuff[0]
Definition: pbx_sw.c:45
int eval
Definition: pbx_sw.c:43
const char * registrar
Definition: pbx_sw.c:40
const char * data
Definition: pbx_sw.c:42
const char * name
Definition: pbx_sw.c:38
struct ast_sw::@379 list
int value
Definition: syslog.c:37