From f46b30bd36457cf349ef18ee854cce9f4dd0daaf Mon Sep 17 00:00:00 2001 From: Matthew Jordan Date: Wed, 11 Dec 2013 12:31:57 +0000 Subject: func_pjsip_endpoint: Add PJSIP_ENDPOINT function for querying endpoint details This patch adds a new function, PJSIP_ENDPOINT, which lets the dialplan query, for any endpoint, any property configured on an endpoint. This function is a companion to the CHANNEL function, which can be used to extract the endpoint name for a channel. Review: https://reviewboard.asterisk.org/r/3035 ........ Merged revisions 403616 from http://svn.asterisk.org/svn/asterisk/branches/12 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@403617 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- Makefile | 8 +-- doc/appdocsxml.dtd | 5 +- doc/appdocsxml.xslt | 128 +++++++++++++++++++++++++++++++++++ doc/snapshots.xslt | 115 ------------------------------- funcs/func_pjsip_endpoint.c | 161 ++++++++++++++++++++++++++++++++++++++++++++ main/sorcery.c | 10 +++ 6 files changed, 307 insertions(+), 120 deletions(-) create mode 100644 doc/appdocsxml.xslt delete mode 100644 doc/snapshots.xslt create mode 100644 funcs/func_pjsip_endpoint.c diff --git a/Makefile b/Makefile index e76ebf9e9..223cafb54 100644 --- a/Makefile +++ b/Makefile @@ -448,7 +448,7 @@ datafiles: _all doc/core-en_US.xml fi \ done $(INSTALL) -m 644 doc/core-en_US.xml "$(DESTDIR)$(ASTDATADIR)/static-http"; - $(INSTALL) -m 644 doc/snapshots.xslt "$(DESTDIR)$(ASTDATADIR)/static-http"; + $(INSTALL) -m 644 doc/appdocsxml.xslt "$(DESTDIR)$(ASTDATADIR)/static-http"; if [ -d doc/tex/asterisk ] ; then \ $(INSTALL) -d "$(DESTDIR)$(ASTDATADIR)/static-http/docs" ; \ for n in doc/tex/asterisk/* ; do \ @@ -471,7 +471,7 @@ doc/core-en_US.xml: makeopts .lastclean $(XML_core_en_US) @printf "Building Documentation For: " @echo "" > $@ @echo "" >> $@ - @echo "" > $@ + @echo "" > $@ @echo "" >> $@ @for x in $(MOD_SUBDIRS); do \ printf "$$x " ; \ @@ -495,7 +495,7 @@ else @printf "Building Documentation For: " @echo "" > $@ @echo "" >> $@ - @echo "" > $@ + @echo "" > $@ @echo "" >> $@ @for x in $(MOD_SUBDIRS); do \ printf "$$x " ; \ @@ -578,7 +578,7 @@ bininstall: _all installdirs $(SUBDIRS_INSTALL) main-bininstall fi $(INSTALL) -m 644 doc/core-*.xml "$(DESTDIR)$(ASTDATADIR)/documentation" - $(INSTALL) -m 644 doc/snapshots.xslt "$(DESTDIR)$(ASTDATADIR)/documentation" + $(INSTALL) -m 644 doc/appdocsxml.xslt "$(DESTDIR)$(ASTDATADIR)/documentation" $(INSTALL) -m 644 doc/appdocsxml.dtd "$(DESTDIR)$(ASTDATADIR)/documentation" $(INSTALL) -m 644 doc/asterisk.8 "$(DESTDIR)$(ASTMANDIR)/man8" $(INSTALL) -m 644 doc/astdb*.8 "$(DESTDIR)$(ASTMANDIR)/man8" diff --git a/doc/appdocsxml.dtd b/doc/appdocsxml.dtd index d56c8a860..a81b64400 100644 --- a/doc/appdocsxml.dtd +++ b/doc/appdocsxml.dtd @@ -85,6 +85,9 @@ + + + @@ -103,7 +106,7 @@ - + diff --git a/doc/appdocsxml.xslt b/doc/appdocsxml.xslt new file mode 100644 index 000000000..33ff73388 --- /dev/null +++ b/doc/appdocsxml.xslt @@ -0,0 +1,128 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + A numeric code for the channel's current state, related to + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + The type of bridge + + + + + + Technology in use by the bridge + + + + + + Number of channels in the bridge + + + diff --git a/doc/snapshots.xslt b/doc/snapshots.xslt deleted file mode 100644 index 17114cbcd..000000000 --- a/doc/snapshots.xslt +++ /dev/null @@ -1,115 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - A numeric code for the channel's current state, related to - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - The type of bridge - - - - - - Technology in use by the bridge - - - - - - Number of channels in the bridge - - - diff --git a/funcs/func_pjsip_endpoint.c b/funcs/func_pjsip_endpoint.c new file mode 100644 index 000000000..8d079ed2d --- /dev/null +++ b/funcs/func_pjsip_endpoint.c @@ -0,0 +1,161 @@ +/* + * Asterisk -- An open source telephony toolkit. + * + * Copyright (C) 2013, Digium, Inc. + * + * Matt Jordan + * + * See http://www.asterisk.org for more information about + * the Asterisk project. Please do not directly contact + * any of the maintainers of this project for assistance; + * the project provides a web site, mailing lists and IRC + * channels for your use. + * + * This program is free software, distributed under the terms of + * the GNU General Public License Version 2. See the LICENSE file + * at the top of the source tree. + */ + +/*! \file + * + * \brief Get information about a PJSIP endpoint + * + * \author \verbatim Matt Jordan \endverbatim + * + * \ingroup functions + * + */ + +/*** MODULEINFO + core + pjproject + res_pjsip + ***/ + +#include "asterisk.h" + +ASTERISK_FILE_VERSION(__FILE__, "$Revision$") + +#include +#include + +#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" + +/*** DOCUMENTATION + + + Get information about a PJSIP endpoint + + + + The name of the endpoint to query. + + + The configuration option for the endpoint to query for. + Supported options are those fields on the + endpoint object in + pjsip.conf. + + + + + + + + +***/ + +static int pjsip_endpoint_function_read(struct ast_channel *chan, + const char *cmd, char *data, struct ast_str **buf, ssize_t len) +{ + struct ast_sorcery *pjsip_sorcery; + char *parsed_data = ast_strdupa(data); + RAII_VAR(void *, endpoint_obj, NULL, ao2_cleanup); + struct ast_variable *change_set; + struct ast_variable *it_change_set; + int res; + + AST_DECLARE_APP_ARGS(args, + AST_APP_ARG(endpoint_name); + AST_APP_ARG(field_name); + ); + + /* Check for zero arguments */ + if (ast_strlen_zero(parsed_data)) { + ast_log(AST_LOG_ERROR, "Cannot call %s without arguments\n", cmd); + return -1; + } + + AST_STANDARD_APP_ARGS(args, parsed_data); + + if (ast_strlen_zero(args.endpoint_name)) { + ast_log(AST_LOG_ERROR, "Cannot call %s without an endpoint name to query\n", cmd); + return -1; + } + + if (ast_strlen_zero(args.field_name)) { + ast_log(AST_LOG_ERROR, "Cannot call %s with an empty field name to query\n", cmd); + return -1; + } + + pjsip_sorcery = ast_sip_get_sorcery(); + if (!pjsip_sorcery) { + ast_log(AST_LOG_ERROR, "Unable to retrieve PJSIP configuration: sorcery object is NULL\n"); + return -1; + } + + endpoint_obj = ast_sorcery_retrieve_by_id(pjsip_sorcery, "endpoint", args.endpoint_name); + if (!endpoint_obj) { + ast_log(AST_LOG_WARNING, "Failed to retrieve information for endpoint '%s'\n", args.endpoint_name); + return -1; + } + + change_set = ast_sorcery_objectset_create(pjsip_sorcery, endpoint_obj); + if (!change_set) { + ast_log(AST_LOG_WARNING, "Failed to retrieve information for endpoint '%s': change set is NULL\n", args.endpoint_name); + return -1; + } + + for (it_change_set = change_set; it_change_set; it_change_set = it_change_set->next) { + if (!strcmp(it_change_set->name, args.field_name)) { + if (!strcmp(it_change_set->name, "disallow")) { + ast_str_set(buf, len, "!%s", it_change_set->value); + } else { + ast_str_set(buf, len, "%s", it_change_set->value); + } + break; + } + } + + res = it_change_set ? 0 : 1; + if (res) { + ast_log(AST_LOG_WARNING, "Unknown property '%s' for PJSIP endpoint\n", args.field_name); + } + + ast_variables_destroy(change_set); + + return res; +} + + +static struct ast_custom_function pjsip_endpoint_function = { + .name = "PJSIP_ENDPOINT", + .read2 = pjsip_endpoint_function_read, +}; + +static int unload_module(void) +{ + return ast_custom_function_unregister(&pjsip_endpoint_function); +} + +static int load_module(void) +{ + return ast_custom_function_register(&pjsip_endpoint_function); +} + +AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Get information about a PJSIP endpoint"); diff --git a/main/sorcery.c b/main/sorcery.c index 2ea6d9ead..c7e1a03f3 100644 --- a/main/sorcery.c +++ b/main/sorcery.c @@ -34,6 +34,8 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #include "asterisk/logger.h" #include "asterisk/sorcery.h" #include "asterisk/astobj2.h" +#include "asterisk/format.h" +#include "asterisk/format_cap.h" #include "asterisk/strings.h" #include "asterisk/config_options.h" #include "asterisk/netsock2.h" @@ -217,11 +219,19 @@ static int chararray_handler_fn(const void *obj, const intptr_t *args, char **bu return !(*buf = ast_strdup(field)) ? -1 : 0; } +static int codec_handler_fn(const void *obj, const intptr_t *args, char **buf) +{ + char tmp_buf[256]; + struct ast_format_cap **cap = (struct ast_format_cap **)(obj + args[1]); + return !(*buf = ast_strdup(ast_getformatname_multiple(tmp_buf, sizeof(tmp_buf), *cap))); +} + static sorcery_field_handler sorcery_field_default_handler(enum aco_option_type type) { switch(type) { case OPT_BOOL_T: return bool_handler_fn; case OPT_CHAR_ARRAY_T: return chararray_handler_fn; + case OPT_CODEC_T: return codec_handler_fn; case OPT_DOUBLE_T: return double_handler_fn; case OPT_INT_T: return int_handler_fn; case OPT_SOCKADDR_T: return sockaddr_handler_fn; -- cgit v1.2.3