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

Get information about a PJSIP endpoint. More...

#include "asterisk.h"
#include <pjsip.h>
#include <pjlib.h>
#include "asterisk/app.h"
#include "asterisk/pbx.h"
#include "asterisk/module.h"
#include "asterisk/channel.h"
#include "asterisk/sorcery.h"
#include "asterisk/res_pjsip.h"
Include dependency graph for func_pjsip_endpoint.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_endpoint_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 endpoint" , .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_endpoint_function
 

Detailed Description

Get information about a PJSIP endpoint.

Author
Matt Jordan <mjordan@digium.com> 

Definition in file func_pjsip_endpoint.c.

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 167 of file func_pjsip_endpoint.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 167 of file func_pjsip_endpoint.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 167 of file func_pjsip_endpoint.c.

◆ load_module()

static int load_module ( void  )
static

Definition at line 157 of file func_pjsip_endpoint.c.

158{
160}
static struct ast_custom_function pjsip_endpoint_function
#define ast_custom_function_register(acf)
Register a custom function.
Definition pbx.h:1562

References ast_custom_function_register, and pjsip_endpoint_function.

◆ pjsip_endpoint_function_read()

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

Definition at line 74 of file func_pjsip_endpoint.c.

76{
77 struct ast_sorcery *pjsip_sorcery;
78 char *parsed_data = ast_strdupa(data);
79 RAII_VAR(void *, endpoint_obj, NULL, ao2_cleanup);
80 struct ast_variable *change_set;
81 struct ast_variable *it_change_set;
82 int res;
83
85 AST_APP_ARG(endpoint_name);
86 AST_APP_ARG(field_name);
87 );
88
89 /* Check for zero arguments */
90 if (ast_strlen_zero(parsed_data)) {
91 ast_log(AST_LOG_ERROR, "Cannot call %s without arguments\n", cmd);
92 return -1;
93 }
94
95 AST_STANDARD_APP_ARGS(args, parsed_data);
96
97 if (ast_strlen_zero(args.endpoint_name)) {
98 ast_log(AST_LOG_ERROR, "Cannot call %s without an endpoint name to query\n", cmd);
99 return -1;
100 }
101
102 if (ast_strlen_zero(args.field_name)) {
103 ast_log(AST_LOG_ERROR, "Cannot call %s with an empty field name to query\n", cmd);
104 return -1;
105 }
106
107 pjsip_sorcery = ast_sip_get_sorcery();
108 if (!pjsip_sorcery) {
109 ast_log(AST_LOG_ERROR, "Unable to retrieve PJSIP configuration: sorcery object is NULL\n");
110 return -1;
111 }
112
113 endpoint_obj = ast_sorcery_retrieve_by_id(pjsip_sorcery, "endpoint", args.endpoint_name);
114 if (!endpoint_obj) {
115 ast_log(AST_LOG_WARNING, "Failed to retrieve information for endpoint '%s'\n", args.endpoint_name);
116 return -1;
117 }
118
119 change_set = ast_sorcery_objectset_create(pjsip_sorcery, endpoint_obj);
120 if (!change_set) {
121 ast_log(AST_LOG_WARNING, "Failed to retrieve information for endpoint '%s': change set is NULL\n", args.endpoint_name);
122 return -1;
123 }
124
125 for (it_change_set = change_set; it_change_set; it_change_set = it_change_set->next) {
126 if (!strcmp(it_change_set->name, args.field_name)) {
127 if (!strcmp(it_change_set->name, "disallow")) {
128 ast_str_set(buf, len, "!%s", it_change_set->value);
129 } else {
130 ast_str_set(buf, len, "%s", it_change_set->value);
131 }
132 break;
133 }
134 }
135
136 res = it_change_set ? 0 : 1;
137 if (res) {
138 ast_log(AST_LOG_WARNING, "Unknown property '%s' for PJSIP endpoint\n", args.field_name);
139 }
140
141 ast_variables_destroy(change_set);
142
143 return res;
144}
#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_cleanup(obj)
Definition astobj2.h:1934
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
struct ast_sorcery * ast_sip_get_sorcery(void)
Get a pointer to the SIP sorcery structure.
static struct @519 args
#define NULL
Definition resample.c:96
#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
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
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:978

References ao2_cleanup, args, AST_APP_ARG, AST_DECLARE_APP_ARGS, ast_log, AST_LOG_ERROR, AST_LOG_WARNING, ast_sip_get_sorcery(), ast_sorcery_objectset_create, ast_sorcery_retrieve_by_id(), AST_STANDARD_APP_ARGS, ast_str_set(), ast_strdupa, ast_strlen_zero(), ast_variables_destroy(), buf, len(), ast_variable::name, ast_variable::next, NULL, RAII_VAR, and ast_variable::value.

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 152 of file func_pjsip_endpoint.c.

153{
155}
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.

References ast_custom_function_unregister(), and pjsip_endpoint_function.

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Get information about a PJSIP endpoint" , .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 167 of file func_pjsip_endpoint.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 167 of file func_pjsip_endpoint.c.

◆ pjsip_endpoint_function

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

Definition at line 147 of file func_pjsip_endpoint.c.

147 {
148 .name = "PJSIP_ENDPOINT",
150};

Referenced by load_module(), and unload_module().