diff --git a/Makefile b/Makefile index e76ebf9e9e4d56393e095c809c070f4f4d4abe76..223cafb543cd45210c00e87aaa5aa37238441792 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 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" > $@ @echo "<!DOCTYPE docs SYSTEM \"appdocsxml.dtd\">" >> $@ - @echo "<?xml-stylesheet type=\"text/xsl\" href=\"snapshots.xslt\"?>" > $@ + @echo "<?xml-stylesheet type=\"text/xsl\" href=\"appdocsxml.xslt\"?>" > $@ @echo "<docs xmlns:xi=\"http://www.w3.org/2001/XInclude\">" >> $@ @for x in $(MOD_SUBDIRS); do \ printf "$$x " ; \ @@ -495,7 +495,7 @@ else @printf "Building Documentation For: " @echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" > $@ @echo "<!DOCTYPE docs SYSTEM \"appdocsxml.dtd\">" >> $@ - @echo "<?xml-stylesheet type=\"text/xsl\" href=\"snapshots.xslt\"?>" > $@ + @echo "<?xml-stylesheet type=\"text/xsl\" href=\"appdocsxml.xslt\"?>" > $@ @echo "<docs xmlns:xi=\"http://www.w3.org/2001/XInclude\">" >> $@ @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 d56c8a860753ebe2a44b5b50d59351253e9f865b..a81b64400b45f74de54e03b98b5addb3430f729b 100644 --- a/doc/appdocsxml.dtd +++ b/doc/appdocsxml.dtd @@ -85,6 +85,9 @@ <!ELEMENT bridge_snapshot (#PCDATA)> <!ATTLIST bridge_snapshot prefix CDATA ""> + <!ELEMENT configOptionToEnum (configOption|xi:include)*> + <!ATTLIST configOptionToEnum prefix CDATA ""> + <!ELEMENT description (para|note|warning|variablelist|enumlist|info|xi:include)*> <!ELEMENT parameter (optionlist|enumlist|argument|para|note|warning|parameter|info|xi:include)*> @@ -103,7 +106,7 @@ <!ATTLIST option implies CDATA ""> <!ATTLIST option hasparams CDATA ""> - <!ELEMENT enumlist (enum+)> + <!ELEMENT enumlist (configOptionToEnum|enum+)> <!ELEMENT enum (para|note|warning|parameter|enumlist|info|xi:include)*> <!ATTLIST enum name CDATA ""> diff --git a/doc/snapshots.xslt b/doc/appdocsxml.xslt similarity index 90% rename from doc/snapshots.xslt rename to doc/appdocsxml.xslt index 17114cbcd72dfa092c3dee60d461ed8c93ba3de4..33ff7338808fcad06e5cffa35b903c0ab752a91e 100644 --- a/doc/snapshots.xslt +++ b/doc/appdocsxml.xslt @@ -1,4 +1,4 @@ -<xsl:stylesheet version="1.0" +<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output omit-xml-declaration="yes" indent="yes"/> @@ -10,6 +10,19 @@ </xsl:copy> </xsl:template> + <xsl:template match="configOptionToEnum"> + <xsl:for-each select="configOption"> + <xsl:element name="enum"> + <xsl:attribute name="name"> + <xsl:value-of select="@name"/> + </xsl:attribute> + <xsl:element name="para"> + <xsl:value-of select="synopsis"/> + </xsl:element> + </xsl:element> + </xsl:for-each> + </xsl:template> + <xsl:template match="channel_snapshot"> <xsl:element name="parameter"> <xsl:attribute name="name"> diff --git a/funcs/func_pjsip_endpoint.c b/funcs/func_pjsip_endpoint.c new file mode 100644 index 0000000000000000000000000000000000000000..8d079ed2deb9ba608e7459e49dabbe49afe2d0de --- /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 <mjordan@digium.com> + * + * 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 <mjordan@digium.com> \endverbatim + * + * \ingroup functions + * + */ + +/*** MODULEINFO + <support_level>core</support_level> + <depend>pjproject</depend> + <depend>res_pjsip</depend> + ***/ + +#include "asterisk.h" + +ASTERISK_FILE_VERSION(__FILE__, "$Revision$") + +#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" + +/*** DOCUMENTATION + <function name="PJSIP_ENDPOINT" language="en_US"> + <synopsis> + Get information about a PJSIP endpoint + </synopsis> + <syntax> + <parameter name="name" required="true"> + <para>The name of the endpoint to query.</para> + </parameter> + <parameter name="field" required="true"> + <para>The configuration option for the endpoint to query for. + Supported options are those fields on the + <replaceable>endpoint</replaceable> object in + <filename>pjsip.conf</filename>.</para> + <enumlist> + <configOptionToEnum> + <xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption)"/> + </configOptionToEnum> + </enumlist> + </parameter> + </syntax> + </function> +***/ + +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 2ea6d9eade01ff03ec20fc31ba71c173f0e3b460..c7e1a03f36f5bd152bb2b3c66cc699beadfcea9f 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;