Asterisk - The Open Source Telephony Project GIT-master-27fb039
Loading...
Searching...
No Matches
Functions | Variables
func_pjsip_aor.c File Reference

Get information about a PJSIP AOR. More...

#include "asterisk.h"
#include <pjsip.h>
#include <pjlib.h>
#include "asterisk/app.h"
#include "asterisk/pbx.h"
#include "asterisk/module.h"
#include "asterisk/sorcery.h"
#include "asterisk/res_pjsip.h"
Include dependency graph for func_pjsip_aor.c:

Go to the source code of this file.

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
static int load_module (void)
 
static int pjsip_aor_function_read (struct ast_channel *chan, const char *cmd, char *data, struct ast_str **buf, ssize_t len)
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Get information about a PJSIP AOR" , .key = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .requires = "res_pjsip", }
 
static const struct ast_module_infoast_module_info = &__mod_info
 
static struct ast_custom_function pjsip_aor_function
 

Detailed Description

Get information about a PJSIP AOR.

Author
Joshua Colp <jcolp@digium.com> 

Definition in file func_pjsip_aor.c.

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 211 of file func_pjsip_aor.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 211 of file func_pjsip_aor.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 211 of file func_pjsip_aor.c.

◆ load_module()

static int load_module ( void  )
static

Definition at line 201 of file func_pjsip_aor.c.

202{
204}
static struct ast_custom_function pjsip_aor_function
#define ast_custom_function_register(acf)
Register a custom function.
Definition pbx.h:1562

References ast_custom_function_register, and pjsip_aor_function.

◆ pjsip_aor_function_read()

static int pjsip_aor_function_read ( struct ast_channel chan,
const char *  cmd,
char *  data,
struct ast_str **  buf,
ssize_t  len 
)
static

Definition at line 92 of file func_pjsip_aor.c.

94{
95 struct ast_sorcery *pjsip_sorcery;
96 char *parsed_data = ast_strdupa(data);
97 RAII_VAR(struct ast_sip_aor *, aor_obj, NULL, ao2_cleanup);
98 int res = 0;
99
101 AST_APP_ARG(aor_name);
102 AST_APP_ARG(field_name);
103 );
104
105 /* Check for zero arguments */
106 if (ast_strlen_zero(parsed_data)) {
107 ast_log(AST_LOG_ERROR, "Cannot call %s without arguments\n", cmd);
108 return -1;
109 }
110
111 AST_STANDARD_APP_ARGS(args, parsed_data);
112
113 if (ast_strlen_zero(args.aor_name)) {
114 ast_log(AST_LOG_ERROR, "Cannot call %s without an AOR name to query\n", cmd);
115 return -1;
116 }
117
118 if (ast_strlen_zero(args.field_name)) {
119 ast_log(AST_LOG_ERROR, "Cannot call %s with an empty field name to query\n", cmd);
120 return -1;
121 }
122
123 pjsip_sorcery = ast_sip_get_sorcery();
124 if (!pjsip_sorcery) {
125 ast_log(AST_LOG_ERROR, "Unable to retrieve PJSIP configuration: sorcery object is NULL\n");
126 return -1;
127 }
128
129 aor_obj = ast_sorcery_retrieve_by_id(pjsip_sorcery, "aor", args.aor_name);
130 if (!aor_obj) {
131 ast_log(AST_LOG_WARNING, "Failed to retrieve information for AOR '%s'\n", args.aor_name);
132 return -1;
133 }
134
135 if (!strcmp(args.field_name, "contact")) {
136 /* The multiple fields handler for contact does not provide a list of contact object names, which is what we want, so we
137 * handle contact specifically to provide this.
138 */
139 RAII_VAR(struct ao2_container *, contacts, NULL, ao2_cleanup);
140 struct ao2_iterator i;
141 struct ast_sip_contact *contact;
142 int first = 1;
143
144 contacts = ast_sip_location_retrieve_aor_contacts(aor_obj);
145 if (!contacts) {
146 ast_log(LOG_WARNING, "Failed to retrieve contacts for AOR '%s'\n", args.aor_name);
147 return -1;
148 }
149
150 i = ao2_iterator_init(contacts, 0);
151 while ((contact = ao2_iterator_next(&i))) {
152 if (!first) {
153 ast_str_append(buf, len, "%s", ",");
154 }
155
157 first = 0;
158
159 ao2_ref(contact, -1);
160 }
162 } else {
163 struct ast_variable *change_set;
164 struct ast_variable *it_change_set;
165
166 change_set = ast_sorcery_objectset_create(pjsip_sorcery, aor_obj);
167 if (!change_set) {
168 ast_log(AST_LOG_WARNING, "Failed to retrieve information for AOR '%s': change set is NULL\n", args.aor_name);
169 return -1;
170 }
171
172 for (it_change_set = change_set; it_change_set; it_change_set = it_change_set->next) {
173 if (!strcmp(it_change_set->name, args.field_name)) {
174 ast_str_set(buf, len, "%s", it_change_set->value);
175 break;
176 }
177 }
178
179 if (!it_change_set) {
180 ast_log(AST_LOG_WARNING, "Unknown property '%s' for PJSIP AOR\n", args.field_name);
181 res = 1;
182 }
183
184 ast_variables_destroy(change_set);
185 }
186
187 return res;
188}
struct sla_ringing_trunk * first
Definition app_sla.c:338
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition astmm.h:298
#define ast_log
Definition astobj2.c:42
#define ao2_iterator_next(iter)
Definition astobj2.h:1911
#define ao2_cleanup(obj)
Definition astobj2.h:1934
struct ao2_iterator ao2_iterator_init(struct ao2_container *c, int flags) attribute_warn_unused_result
Create an iterator for a container.
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition astobj2.h:459
void ao2_iterator_destroy(struct ao2_iterator *iter)
Destroy a container iterator.
char buf[BUFSIZE]
Definition eagi_proxy.c:66
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
#define AST_APP_ARG(name)
Define an application argument.
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application's arguments.
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the 'standard' argument separation process for an application.
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
Definition extconf.c:1260
#define AST_LOG_WARNING
#define AST_LOG_ERROR
#define LOG_WARNING
struct ast_sorcery * ast_sip_get_sorcery(void)
Get a pointer to the SIP sorcery structure.
struct ao2_container * ast_sip_location_retrieve_aor_contacts(const struct ast_sip_aor *aor)
Retrieve all contacts currently available for an AOR.
Definition location.c:247
static struct @519 args
#define NULL
Definition resample.c:96
const char * ast_sorcery_object_get_id(const void *object)
Get the unique identifier of a sorcery object.
Definition sorcery.c:2381
#define ast_sorcery_objectset_create(sorcery, object)
Create an object set (KVP list) for an object.
Definition sorcery.h:1137
void * ast_sorcery_retrieve_by_id(const struct ast_sorcery *sorcery, const char *type, const char *id)
Retrieve an object using its unique identifier.
Definition sorcery.c:1917
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
Definition strings.h:1139
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition strings.h:65
int ast_str_set(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Set a dynamic string using variable arguments.
Definition strings.h:1113
Generic container type.
When we need to walk through a container, we use an ao2_iterator to keep track of the current positio...
Definition astobj2.h:1821
A SIP address of record.
Definition res_pjsip.h:478
Contact associated with an address of record.
Definition res_pjsip.h:390
Full structure for sorcery.
Definition sorcery.c:231
Structure for variables, used for configurations and for channel variables.
struct ast_variable * next
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition utils.h:981

References ao2_cleanup, ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_ref, args, AST_APP_ARG, AST_DECLARE_APP_ARGS, ast_log, AST_LOG_ERROR, AST_LOG_WARNING, ast_sip_get_sorcery(), ast_sip_location_retrieve_aor_contacts(), ast_sorcery_object_get_id(), ast_sorcery_objectset_create, ast_sorcery_retrieve_by_id(), AST_STANDARD_APP_ARGS, ast_str_append(), ast_str_set(), ast_strdupa, ast_strlen_zero(), ast_variables_destroy(), buf, first, len(), LOG_WARNING, ast_variable::name, ast_variable::next, NULL, RAII_VAR, and ast_variable::value.

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 196 of file func_pjsip_aor.c.

197{
199}
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.

References ast_custom_function_unregister(), and pjsip_aor_function.

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Get information about a PJSIP AOR" , .key = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .requires = "res_pjsip", }
static

Definition at line 211 of file func_pjsip_aor.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 211 of file func_pjsip_aor.c.

◆ pjsip_aor_function

struct ast_custom_function pjsip_aor_function
static
Initial value:
= {
.name = "PJSIP_AOR",
}
static int pjsip_aor_function_read(struct ast_channel *chan, const char *cmd, char *data, struct ast_str **buf, ssize_t len)

Definition at line 191 of file func_pjsip_aor.c.

191 {
192 .name = "PJSIP_AOR",
194};

Referenced by load_module(), and unload_module().