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)
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_LOAD_ORDER , .description = "Get information about a PJSIP AOR" , .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_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

static void __reg_module ( void   )  [static]

Definition at line 184 of file func_pjsip_aor.c.

static void __unreg_module ( void   )  [static]

Definition at line 184 of file func_pjsip_aor.c.

static int load_module ( void   )  [static]

Definition at line 179 of file func_pjsip_aor.c.

References ast_custom_function_register.

00180 {
00181    return ast_custom_function_register(&pjsip_aor_function);
00182 }

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 72 of file func_pjsip_aor.c.

References ao2_cleanup, ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, 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(), first, LOG_WARNING, ast_variable::name, ast_variable::next, NULL, RAII_VAR, and ast_variable::value.

00074 {
00075    struct ast_sorcery *pjsip_sorcery;
00076    char *parsed_data = ast_strdupa(data);
00077    RAII_VAR(struct ast_sip_aor *, aor_obj, NULL, ao2_cleanup);
00078    int res = 0;
00079 
00080    AST_DECLARE_APP_ARGS(args,
00081       AST_APP_ARG(aor_name);
00082       AST_APP_ARG(field_name);
00083    );
00084 
00085    /* Check for zero arguments */
00086    if (ast_strlen_zero(parsed_data)) {
00087       ast_log(AST_LOG_ERROR, "Cannot call %s without arguments\n", cmd);
00088       return -1;
00089    }
00090 
00091    AST_STANDARD_APP_ARGS(args, parsed_data);
00092 
00093    if (ast_strlen_zero(args.aor_name)) {
00094       ast_log(AST_LOG_ERROR, "Cannot call %s without an AOR name to query\n", cmd);
00095       return -1;
00096    }
00097 
00098    if (ast_strlen_zero(args.field_name)) {
00099       ast_log(AST_LOG_ERROR, "Cannot call %s with an empty field name to query\n", cmd);
00100       return -1;
00101    }
00102 
00103    pjsip_sorcery = ast_sip_get_sorcery();
00104    if (!pjsip_sorcery) {
00105       ast_log(AST_LOG_ERROR, "Unable to retrieve PJSIP configuration: sorcery object is NULL\n");
00106       return -1;
00107    }
00108 
00109    aor_obj = ast_sorcery_retrieve_by_id(pjsip_sorcery, "aor", args.aor_name);
00110    if (!aor_obj) {
00111       ast_log(AST_LOG_WARNING, "Failed to retrieve information for AOR '%s'\n", args.aor_name);
00112       return -1;
00113    }
00114 
00115    if (!strcmp(args.field_name, "contact")) {
00116       /* The multiple fields handler for contact does not provide a list of contact object names, which is what we want, so we
00117        * handle contact specifically to provide this.
00118        */
00119       RAII_VAR(struct ao2_container *, contacts, NULL, ao2_cleanup);
00120       struct ao2_iterator i;
00121       struct ast_sip_contact *contact;
00122       int first = 1;
00123 
00124       contacts = ast_sip_location_retrieve_aor_contacts(aor_obj);
00125       if (!contacts) {
00126          ast_log(LOG_WARNING, "Failed to retrieve contacts for AOR '%s'\n", args.aor_name);
00127          return -1;
00128       }
00129 
00130       i = ao2_iterator_init(contacts, 0);
00131       while ((contact = ao2_iterator_next(&i))) {
00132          if (!first) {
00133             ast_str_append(buf, len, "%s", ",");
00134          }
00135 
00136          ast_str_append(buf, len, "%s", ast_sorcery_object_get_id(contact));
00137          first = 0;
00138       }
00139       ao2_iterator_destroy(&i);
00140    } else {
00141       struct ast_variable *change_set;
00142       struct ast_variable *it_change_set;
00143 
00144       change_set = ast_sorcery_objectset_create(pjsip_sorcery, aor_obj);
00145       if (!change_set) {
00146          ast_log(AST_LOG_WARNING, "Failed to retrieve information for AOR '%s': change set is NULL\n", args.aor_name);
00147          return -1;
00148       }
00149 
00150       for (it_change_set = change_set; it_change_set; it_change_set = it_change_set->next) {
00151          if (!strcmp(it_change_set->name, args.field_name)) {
00152             ast_str_set(buf, len, "%s", it_change_set->value);
00153             break;
00154          }
00155       }
00156 
00157       if (!it_change_set) {
00158          ast_log(AST_LOG_WARNING, "Unknown property '%s' for PJSIP AOR\n", args.field_name);
00159          res = 1;
00160       }
00161 
00162       ast_variables_destroy(change_set);
00163    }
00164 
00165    return res;
00166 }

static int unload_module ( void   )  [static]

Definition at line 174 of file func_pjsip_aor.c.

References ast_custom_function_unregister().

00175 {
00176    return ast_custom_function_unregister(&pjsip_aor_function);
00177 }


Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Get information about a PJSIP AOR" , .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 184 of file func_pjsip_aor.c.

Definition at line 184 of file func_pjsip_aor.c.

Initial value:

 {
   .name = "PJSIP_AOR",
   .read2 = pjsip_aor_function_read,
}

Definition at line 169 of file func_pjsip_aor.c.


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