Debian Codegraph @

res/res_pjsip/config_domain_aliases.c

raw symbols SCIP
1 /*
2 * Asterisk -- An open source telephony toolkit.
3 *
4 * Copyright (C) 2013, Digium, Inc.
5 *
6 * Joshua Colp <[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 #include "asterisk.h"
20
21 #include <pjsip.h>
22 #include <pjlib.h>
23
24 #include "asterisk/res_pjsip.h"
25 #include "include/res_pjsip_private.h"
26 #include "asterisk/logger.h"
27 #include "asterisk/sorcery.h"
28
29 static void domain_alias_destroy(void *obj)
30 {
31 struct ast_sip_domain_alias *alias = obj;
32
33 ast_string_field_free_memory(alias);
34 }
35
36 static void *domain_alias_alloc(const char *name)
37 {
38 struct ast_sip_domain_alias *alias;
39
40 alias = ast_sorcery_generic_alloc(sizeof(*alias), domain_alias_destroy);
41 if (!alias) {
42 return NULL;
43 }
44
45 if (ast_string_field_init(alias, 256)) {
46 ao2_cleanup(alias);
47 return NULL;
48 }
49
50 return alias;
51 }
52
53 /*! \brief Apply handler for domain_alias type */
54 static int domain_alias_apply(const struct ast_sorcery *sorcery, void *obj)
55 {
56 struct ast_sip_domain_alias *alias = obj;
57
58 if (ast_strlen_zero(alias->domain)) {
59 /*
60 * What is the point of defining an alias and not saying
61 * what is being aliased?
62 */
63 ast_log(LOG_ERROR, "%s '%s' missing required domain being aliased.\n",
64 SIP_SORCERY_DOMAIN_ALIAS_TYPE, ast_sorcery_object_get_id(alias));
65 return -1;
66 }
67 return 0;
68 }
69
70 /*! \brief Initialize sorcery with domain alias support */
71 int ast_sip_initialize_sorcery_domain_alias(void)
72 {
73 struct ast_sorcery *sorcery = ast_sip_get_sorcery();
74
75 ast_sorcery_apply_default(sorcery, SIP_SORCERY_DOMAIN_ALIAS_TYPE, "config", "pjsip.conf,criteria=type=domain_alias");
76
77 if (ast_sorcery_object_register(sorcery, SIP_SORCERY_DOMAIN_ALIAS_TYPE,
78 domain_alias_alloc, NULL, domain_alias_apply)) {
79 return -1;
80 }
81
82 ast_sorcery_object_field_register(sorcery, SIP_SORCERY_DOMAIN_ALIAS_TYPE, "type", "",
83 OPT_NOOP_T, 0, 0);
84 ast_sorcery_object_field_register(sorcery, SIP_SORCERY_DOMAIN_ALIAS_TYPE, "domain",
85 "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_domain_alias, domain));
86
87 return 0;
88 }