Asterisk - The Open Source Telephony Project  18.5.0
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 <[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"
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 
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",
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);
86 
87  return 0;
88 }
int ast_sip_initialize_sorcery_domain_alias(void)
Initialize sorcery with domain alias support.
Asterisk main include file. File version handling, generic pbx functions.
Full structure for sorcery.
Definition: sorcery.c:230
Type for a default handler that should do nothing.
#define SIP_SORCERY_DOMAIN_ALIAS_TYPE
Definition: res_pjsip.h:254
static int domain_alias_apply(const struct ast_sorcery *sorcery, void *obj)
Apply handler for domain_alias type.
#define NULL
Definition: resample.c:96
Domain data structure.
Definition: sip.h:888
#define ast_strlen_zero(foo)
Definition: strings.h:52
#define ast_log
Definition: astobj2.c:42
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
Definition: stringfields.h:353
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:838
#define LOG_ERROR
Definition: logger.h:285
#define ast_sorcery_apply_default(sorcery, type, name, data)
Definition: sorcery.h:477
static const char name[]
Definition: cdr_mysql.c:74
#define STRFLDSET(type,...)
Convert a struct and a list of stringfield fields to an argument list of field offsets.
Support for logging to various files, console and syslog Configuration in file logger.conf.
#define ast_sorcery_object_field_register(sorcery, type, name, default_val, opt_type, flags,...)
Register a field within an object.
Definition: sorcery.h:955
static struct ast_sorcery * sorcery
const ast_string_field domain
Definition: res_pjsip.h:265
struct ast_sorcery * ast_sip_get_sorcery(void)
Get a pointer to the SIP sorcery structure.
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
Type for default option handler for stringfields.
static void * domain_alias_alloc(const char *name)
void * ast_sorcery_generic_alloc(size_t size, ao2_destructor_fn destructor)
Allocate a generic sorcery capable object.
Definition: sorcery.c:1728
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
Definition: stringfields.h:368
static void domain_alias_destroy(void *obj)
Sorcery Data Access Layer API.