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)
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_LOAD_ORDER , .description = "Get information about a PJSIP endpoint" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
static 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

static void __reg_module ( void   )  [static]

Definition at line 161 of file func_pjsip_endpoint.c.

static void __unreg_module ( void   )  [static]

Definition at line 161 of file func_pjsip_endpoint.c.

static int load_module ( void   )  [static]

Definition at line 156 of file func_pjsip_endpoint.c.

References ast_custom_function_register.

00157 {
00158    return ast_custom_function_register(&pjsip_endpoint_function);
00159 }

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 73 of file func_pjsip_endpoint.c.

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(), ast_variable::name, ast_variable::next, NULL, RAII_VAR, and ast_variable::value.

00075 {
00076    struct ast_sorcery *pjsip_sorcery;
00077    char *parsed_data = ast_strdupa(data);
00078    RAII_VAR(void *, endpoint_obj, NULL, ao2_cleanup);
00079    struct ast_variable *change_set;
00080    struct ast_variable *it_change_set;
00081    int res;
00082 
00083    AST_DECLARE_APP_ARGS(args,
00084       AST_APP_ARG(endpoint_name);
00085       AST_APP_ARG(field_name);
00086    );
00087 
00088    /* Check for zero arguments */
00089    if (ast_strlen_zero(parsed_data)) {
00090       ast_log(AST_LOG_ERROR, "Cannot call %s without arguments\n", cmd);
00091       return -1;
00092    }
00093 
00094    AST_STANDARD_APP_ARGS(args, parsed_data);
00095 
00096    if (ast_strlen_zero(args.endpoint_name)) {
00097       ast_log(AST_LOG_ERROR, "Cannot call %s without an endpoint name to query\n", cmd);
00098       return -1;
00099    }
00100 
00101    if (ast_strlen_zero(args.field_name)) {
00102       ast_log(AST_LOG_ERROR, "Cannot call %s with an empty field name to query\n", cmd);
00103       return -1;
00104    }
00105 
00106    pjsip_sorcery = ast_sip_get_sorcery();
00107    if (!pjsip_sorcery) {
00108       ast_log(AST_LOG_ERROR, "Unable to retrieve PJSIP configuration: sorcery object is NULL\n");
00109       return -1;
00110    }
00111 
00112    endpoint_obj = ast_sorcery_retrieve_by_id(pjsip_sorcery, "endpoint", args.endpoint_name);
00113    if (!endpoint_obj) {
00114       ast_log(AST_LOG_WARNING, "Failed to retrieve information for endpoint '%s'\n", args.endpoint_name);
00115       return -1;
00116    }
00117 
00118    change_set = ast_sorcery_objectset_create(pjsip_sorcery, endpoint_obj);
00119    if (!change_set) {
00120       ast_log(AST_LOG_WARNING, "Failed to retrieve information for endpoint '%s': change set is NULL\n", args.endpoint_name);
00121       return -1;
00122    }
00123 
00124    for (it_change_set = change_set; it_change_set; it_change_set = it_change_set->next) {
00125       if (!strcmp(it_change_set->name, args.field_name)) {
00126          if (!strcmp(it_change_set->name, "disallow")) {
00127             ast_str_set(buf, len, "!%s", it_change_set->value);
00128          } else {
00129             ast_str_set(buf, len, "%s", it_change_set->value);
00130          }
00131          break;
00132       }
00133    }
00134 
00135    res = it_change_set ? 0 : 1;
00136    if (res) {
00137       ast_log(AST_LOG_WARNING, "Unknown property '%s' for PJSIP endpoint\n", args.field_name);
00138    }
00139 
00140    ast_variables_destroy(change_set);
00141 
00142    return res;
00143 }

static int unload_module ( void   )  [static]

Definition at line 151 of file func_pjsip_endpoint.c.

References ast_custom_function_unregister().


Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Get information about a PJSIP endpoint" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, } [static]

Definition at line 161 of file func_pjsip_endpoint.c.

Definition at line 161 of file func_pjsip_endpoint.c.

Initial value:

 {
   .name = "PJSIP_ENDPOINT",
   .read2 = pjsip_endpoint_function_read,
}

Definition at line 146 of file func_pjsip_endpoint.c.


Generated on Thu Apr 16 06:31:22 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6