[asterisk-commits] mjordan: branch 12 r403616 - in /branches/12: ./ doc/ funcs/ main/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Dec 11 06:30:00 CST 2013


Author: mjordan
Date: Wed Dec 11 06:29:49 2013
New Revision: 403616

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=403616
Log:
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

Added:
    branches/12/doc/appdocsxml.xslt   (with props)
    branches/12/funcs/func_pjsip_endpoint.c   (with props)
Removed:
    branches/12/doc/snapshots.xslt
Modified:
    branches/12/Makefile
    branches/12/doc/appdocsxml.dtd
    branches/12/main/sorcery.c

Modified: branches/12/Makefile
URL: http://svnview.digium.com/svn/asterisk/branches/12/Makefile?view=diff&rev=403616&r1=403615&r2=403616
==============================================================================
--- branches/12/Makefile (original)
+++ branches/12/Makefile Wed Dec 11 06:29:49 2013
@@ -448,7 +448,7 @@
 		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 @@
 	@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 @@
 	@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 @@
 	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"

Modified: branches/12/doc/appdocsxml.dtd
URL: http://svnview.digium.com/svn/asterisk/branches/12/doc/appdocsxml.dtd?view=diff&rev=403616&r1=403615&r2=403616
==============================================================================
--- branches/12/doc/appdocsxml.dtd (original)
+++ branches/12/doc/appdocsxml.dtd Wed Dec 11 06:29:49 2013
@@ -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 "">
 

Added: branches/12/doc/appdocsxml.xslt
URL: http://svnview.digium.com/svn/asterisk/branches/12/doc/appdocsxml.xslt?view=auto&rev=403616
==============================================================================
--- branches/12/doc/appdocsxml.xslt (added)
+++ branches/12/doc/appdocsxml.xslt Wed Dec 11 06:29:49 2013
@@ -1,0 +1,128 @@
+<xsl:stylesheet version="1.0"
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+    <xsl:output omit-xml-declaration="yes" indent="yes"/>
+
+    <xsl:param name="pNewType" select="'myNewType'"/>
+
+    <xsl:template match="node()|@*">
+        <xsl:copy>
+            <xsl:apply-templates select="node()|@*"/>
+        </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">
+                <xsl:value-of select="concat(@prefix,'Channel')"/>
+            </xsl:attribute>
+        </xsl:element>
+        <xsl:element name="parameter">
+            <xsl:attribute name="name">
+                <xsl:value-of select="concat(@prefix,'ChannelState')"/>
+            </xsl:attribute>
+            <para>A numeric code for the channel's current state, related to <xsl:value-of select="concat(@prefix,'ChannelStateDesc')"/></para>
+        </xsl:element>
+        <xsl:element name="parameter">
+            <xsl:attribute name="name">
+                <xsl:value-of select="concat(@prefix,'ChannelStateDesc')"/>
+            </xsl:attribute>
+            <enumlist>
+                <enum name="Down"/>
+                <enum name="Rsrvd"/>
+                <enum name="OffHook"/>
+                <enum name="Dialing"/>
+                <enum name="Ring"/>
+                <enum name="Ringing"/>
+                <enum name="Up"/>
+                <enum name="Busy"/>
+                <enum name="Dialing Offhook"/>
+                <enum name="Pre-ring"/>
+                <enum name="Unknown"/>
+            </enumlist>
+        </xsl:element>
+        <xsl:element name="parameter">
+            <xsl:attribute name="name">
+                <xsl:value-of select="concat(@prefix,'CallerIDNum')"/>
+            </xsl:attribute>
+        </xsl:element>
+        <xsl:element name="parameter">
+            <xsl:attribute name="name">
+                <xsl:value-of select="concat(@prefix,'CallerIDName')"/>
+            </xsl:attribute>
+        </xsl:element>
+        <xsl:element name="parameter">
+            <xsl:attribute name="name">
+                <xsl:value-of select="concat(@prefix,'ConnectedLineNum')"/>
+            </xsl:attribute>
+        </xsl:element>
+        <xsl:element name="parameter">
+            <xsl:attribute name="name">
+                <xsl:value-of select="concat(@prefix,'ConnectedLineName')"/>
+            </xsl:attribute>
+        </xsl:element>
+        <xsl:element name="parameter">
+            <xsl:attribute name="name">
+                <xsl:value-of select="concat(@prefix,'AccountCode')"/>
+            </xsl:attribute>
+        </xsl:element>
+        <xsl:element name="parameter">
+            <xsl:attribute name="name">
+                <xsl:value-of select="concat(@prefix,'Context')"/>
+            </xsl:attribute>
+        </xsl:element>
+        <xsl:element name="parameter">
+            <xsl:attribute name="name">
+                <xsl:value-of select="concat(@prefix,'Exten')"/>
+            </xsl:attribute>
+        </xsl:element>
+        <xsl:element name="parameter">
+            <xsl:attribute name="name">
+                <xsl:value-of select="concat(@prefix,'Priority')"/>
+            </xsl:attribute>
+        </xsl:element>
+        <xsl:element name="parameter">
+            <xsl:attribute name="name">
+                <xsl:value-of select="concat(@prefix,'Uniqueid')"/>
+            </xsl:attribute>
+        </xsl:element>
+    </xsl:template>
+
+    <xsl:template match="bridge_snapshot">
+        <xsl:element name="parameter">
+            <xsl:attribute name="name">
+                <xsl:value-of select="concat(@prefix,'BridgeUniqueid')"/>
+            </xsl:attribute>
+        </xsl:element>
+        <xsl:element name="parameter">
+            <xsl:attribute name="name">
+                <xsl:value-of select="concat(@prefix,'BridgeType')"/>
+            </xsl:attribute>
+            <para>The type of bridge</para>
+        </xsl:element>
+        <xsl:element name="parameter">
+            <xsl:attribute name="name">
+                <xsl:value-of select="concat(@prefix,'BridgeTechnology')"/>
+            </xsl:attribute>
+            <para>Technology in use by the bridge</para>
+        </xsl:element>
+        <xsl:element name="parameter">
+            <xsl:attribute name="name">
+                <xsl:value-of select="concat(@prefix,'BridgeNumChannels')"/>
+            </xsl:attribute>
+            <para>Number of channels in the bridge</para>
+        </xsl:element>
+    </xsl:template>
+</xsl:stylesheet>

Propchange: branches/12/doc/appdocsxml.xslt
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: branches/12/doc/appdocsxml.xslt
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: branches/12/doc/appdocsxml.xslt
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: branches/12/funcs/func_pjsip_endpoint.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/funcs/func_pjsip_endpoint.c?view=auto&rev=403616
==============================================================================
--- branches/12/funcs/func_pjsip_endpoint.c (added)
+++ branches/12/funcs/func_pjsip_endpoint.c Wed Dec 11 06:29:49 2013
@@ -1,0 +1,161 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2013, Digium, Inc.
+ *
+ * Matt Jordan <mjordan at 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 at 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");

Propchange: branches/12/funcs/func_pjsip_endpoint.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: branches/12/funcs/func_pjsip_endpoint.c
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: branches/12/funcs/func_pjsip_endpoint.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: branches/12/main/sorcery.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/main/sorcery.c?view=diff&rev=403616&r1=403615&r2=403616
==============================================================================
--- branches/12/main/sorcery.c (original)
+++ branches/12/main/sorcery.c Wed Dec 11 06:29:49 2013
@@ -34,6 +34,8 @@
 #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 @@
 	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;




More information about the asterisk-commits mailing list