44 #include "asterisk/res_pjsip.h"
75 static int contact_function_get_permanent(
void *obj,
void *arg,
int flags)
86 static int pjsip_contact_function_read(
struct ast_channel *chan,
87 const char *cmd,
char *data,
struct ast_str **buf, ssize_t len)
102 if (ast_strlen_zero(parsed_data)) {
103 ast_log(AST_LOG_ERROR,
"Cannot call %s without arguments\n", cmd);
109 if (ast_strlen_zero(args.contact_name)) {
110 ast_log(AST_LOG_ERROR,
"Cannot call %s without a contact name to query\n", cmd);
114 if (ast_strlen_zero(args.field_name)) {
115 ast_log(AST_LOG_ERROR,
"Cannot call %s with an empty field name to query\n", cmd);
119 pjsip_sorcery = ast_sip_get_sorcery();
120 if (!pjsip_sorcery) {
121 ast_log(AST_LOG_ERROR,
"Unable to retrieve PJSIP configuration: sorcery object is NULL\n");
126 if ((contact_name = strstr(args.contact_name,
"@@"))) {
127 size_t aor_name_len = contact_name - args.contact_name;
128 char aor_name[aor_name_len + 1];
132 strncpy(aor_name, args.contact_name, aor_name_len);
133 aor_name[aor_name_len] =
'\0';
137 ast_log(AST_LOG_WARNING,
"Failed to retrieve information for contact '%s'\n", args.contact_name);
141 contact_obj =
ao2_callback(aor_obj->permanent_contacts, 0, contact_function_get_permanent, args.contact_name);
147 ast_log(AST_LOG_WARNING,
"Failed to retrieve information for contact '%s'\n", args.contact_name);
151 contact_status = ast_sip_get_contact_status(contact_obj);
153 if (!strcmp(args.field_name,
"status")) {
154 ast_str_set(buf, len,
"%s", ast_sip_get_contact_status_label(contact_status ? contact_status->status : UNKNOWN));
155 }
else if (!strcmp(args.field_name,
"rtt")) {
156 if (!contact_status || contact_status->status != AVAILABLE) {
159 ast_str_set(buf, len,
"%" PRId64, contact_status->rtt);
168 ast_log(AST_LOG_WARNING,
"Failed to retrieve information for contact '%s': change set is NULL\n", args.contact_name);
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)) {
179 if (!it_change_set) {
180 ast_log(AST_LOG_WARNING,
"Unknown property '%s' for PJSIP contact\n", args.field_name);
193 .
name =
"PJSIP_CONTACT",
194 .read2 = pjsip_contact_function_read,
197 static int unload_module(
void)
202 static int load_module(
void)
207 AST_MODULE_INFO(
ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT,
"Get information about a PJSIP contact",
208 .support_level = AST_MODULE_SUPPORT_CORE,
210 .unload = unload_module,
211 .requires =
"res_pjsip",
struct ast_variable * next
Main Channel structure associated with a channel.
Asterisk main include file. File version handling, generic pbx functions.
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the 'standard' argument separation process for an application.
#define ao2_callback(c, flags, cb_fn, arg)
ao2_callback() is a generic function that applies cb_fn() to all objects in a container, as described below.
Structure for variables, used for configurations and for channel variables.
Full structure for sorcery.
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.
void * ast_sorcery_retrieve_by_id(const struct ast_sorcery *sorcery, const char *type, const char *id)
Retrieve an object using its unique identifier.
int ast_str_set(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Set a dynamic string using variable arguments.
#define ast_strdupa(s)
duplicate a string in memory from the stack
Data structure associated with a custom dialplan function.
const char * ast_sorcery_object_get_id(const void *object)
Get the unique identifier of a sorcery object.
Core PBX routines and definitions.
Support for dynamic strings.
#define ast_sorcery_objectset_create(sorcery, object)
Create an object set (KVP list) for an object.
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application's arguments.
Application convenience functions, designed to give consistent look and feel to Asterisk apps...
#define ast_custom_function_register(acf)
Register a custom function.
Sorcery Data Access Layer API.
#define AST_APP_ARG(name)
Define an application argument.