Debian Codegraph @

main/pbx_ignorepat.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 context ignorepat 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_ignorepat: Ignore patterns in dial plan */
37 struct ast_ignorepat {
38 const char *registrar;
39 const char pattern[0];
40 };
41
42 const char *ast_get_ignorepat_name(const struct ast_ignorepat *ip)
43 {
44 return ip ? ip->pattern : NULL;
45 }
46
47 const char *ast_get_ignorepat_registrar(const struct ast_ignorepat *ip)
48 {
49 return ip ? ip->registrar : NULL;
50 }
51
52 struct ast_ignorepat *ignorepat_alloc(const char *value, const char *registrar)
53 {
54 struct ast_ignorepat *ignorepat;
55 int length = strlen(value) + 1;
56 char *pattern;
57
58 /* allocate new include structure ... */
59 ignorepat = ast_calloc(1, sizeof(*ignorepat) + length);
60 if (!ignorepat) {
61 return NULL;
62 }
63
64 /* The cast to char * is because we need to write the initial value.
65 * The field is not supposed to be modified otherwise. Also, gcc 4.2
66 * sees the cast as dereferencing a type-punned pointer and warns about
67 * it. This is the workaround (we're telling gcc, yes, that's really
68 * what we wanted to do).
69 */
70 pattern = (char *) ignorepat->pattern;
71 strcpy(pattern, value);
72 ignorepat->registrar = registrar;
73
74 return ignorepat;
75 }
76
77 void ignorepat_free(struct ast_ignorepat *ip)
78 {
79 ast_free(ip);
80 }