Asterisk - The Open Source Telephony Project GIT-master-7921072
config_domain_aliases.c
Go to the documentation of this file.
1/*
2 * Asterisk -- An open source telephony toolkit.
3 *
4 * Copyright (C) 2013, Digium, Inc.
5 *
6 * Joshua Colp <jcolp@digium.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#include "asterisk.h"
20
21#include <pjsip.h>
22#include <pjlib.h>
23
24#include "asterisk/res_pjsip.h"
26#include "asterisk/logger.h"
27#include "asterisk/sorcery.h"
28
29static void domain_alias_destroy(void *obj)
30{
31 struct ast_sip_domain_alias *alias = obj;
32
34}
35
36static 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 */
54static 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",
65 return -1;
66 }
67 return 0;
68}
69
70/*! \brief Initialize sorcery with domain alias support */
72{
74
75 ast_sorcery_apply_default(sorcery, SIP_SORCERY_DOMAIN_ALIAS_TYPE, "config", "pjsip.conf,criteria=type=domain_alias");
76
79 return -1;
80 }
81
83 OPT_NOOP_T, 0, 0);
85 "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_domain_alias, domain));
86
87 return 0;
88}
Asterisk main include file. File version handling, generic pbx functions.
#define ast_log
Definition: astobj2.c:42
#define ao2_cleanup(obj)
Definition: astobj2.h:1934
static void domain_alias_destroy(void *obj)
static void * domain_alias_alloc(const char *name)
int ast_sip_initialize_sorcery_domain_alias(void)
Initialize sorcery with domain alias support.
static int domain_alias_apply(const struct ast_sorcery *sorcery, void *obj)
Apply handler for domain_alias type.
#define STRFLDSET(type,...)
Convert a struct and a list of stringfield fields to an argument list of field offsets.
@ OPT_NOOP_T
Type for a default handler that should do nothing.
@ OPT_STRINGFIELD_T
Type for default option handler for stringfields.
static const char name[]
Definition: format_mp3.c:68
Support for logging to various files, console and syslog Configuration in file logger....
#define LOG_ERROR
struct ast_sorcery * ast_sip_get_sorcery(void)
Get a pointer to the SIP sorcery structure.
#define SIP_SORCERY_DOMAIN_ALIAS_TYPE
Definition: res_pjsip.h:312
static struct ast_sorcery * sorcery
#define NULL
Definition: resample.c:96
Sorcery Data Access Layer API.
const char * ast_sorcery_object_get_id(const void *object)
Get the unique identifier of a sorcery object.
Definition: sorcery.c:2312
#define ast_sorcery_object_register(sorcery, type, alloc, transform, apply)
Register an object type.
Definition: sorcery.h:837
void * ast_sorcery_generic_alloc(size_t size, ao2_destructor_fn destructor)
Allocate a generic sorcery capable object.
Definition: sorcery.c:1728
#define ast_sorcery_object_field_register(sorcery, type, name, default_val, opt_type, flags,...)
Register a field within an object.
Definition: sorcery.h:955
#define ast_sorcery_apply_default(sorcery, type, name, data)
Definition: sorcery.h:476
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
Definition: stringfields.h:359
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
Definition: stringfields.h:374
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
const ast_string_field domain
Definition: res_pjsip.h:323
Full structure for sorcery.
Definition: sorcery.c:230