summaryrefslogtreecommitdiff
path: root/main/pbx_ignorepat.c
blob: 5b21c3a1fdbdf9d29b97a6a2dcebe130e2a00a6a (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
/*
 * 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 ignorepat 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"

/*! \brief ast_ignorepat: Ignore patterns in dial plan */
struct ast_ignorepat {
	const char *registrar;
	const char pattern[0];
};

const char *ast_get_ignorepat_name(const struct ast_ignorepat *ip)
{
	return ip ? ip->pattern : NULL;
}

const char *ast_get_ignorepat_registrar(const struct ast_ignorepat *ip)
{
	return ip ? ip->registrar : NULL;
}

struct ast_ignorepat *ignorepat_alloc(const char *value, const char *registrar)
{
	struct ast_ignorepat *ignorepat;
	int length = strlen(value) + 1;
	char *pattern;

	/* allocate new include structure ... */
	ignorepat = ast_calloc(1, sizeof(*ignorepat) + length);
	if (!ignorepat) {
		return NULL;
	}

	/* The cast to char * is because we need to write the initial value.
	 * The field is not supposed to be modified otherwise.  Also, gcc 4.2
	 * sees the cast as dereferencing a type-punned pointer and warns about
	 * it.  This is the workaround (we're telling gcc, yes, that's really
	 * what we wanted to do).
	 */
	pattern = (char *) ignorepat->pattern;
	strcpy(pattern, value);
	ignorepat->registrar = registrar;

	return ignorepat;
}

void ignorepat_free(struct ast_ignorepat *ip)
{
	ast_free(ip);
}