<p>N A has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/15892">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">func_min and func_max: Two new dialplan functions<br><br>Introduces two new dialplan functions, MIN and MAX,<br>which can be used to calculate the minimum or<br>maximum of up to two integers.<br><br>ASTERISK-29431<br><br>Change-Id: I2bda9269d18f9d54833c85e48e41fce0e0ce4d8d<br>---<br>A doc/CHANGES-staging/func_min_max.txt<br>A funcs/func_max.c<br>A funcs/func_min.c<br>3 files changed, 200 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/92/15892/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/doc/CHANGES-staging/func_min_max.txt b/doc/CHANGES-staging/func_min_max.txt</span><br><span>new file mode 100644</span><br><span>index 0000000..cc4e6e0</span><br><span>--- /dev/null</span><br><span>+++ b/doc/CHANGES-staging/func_min_max.txt</span><br><span>@@ -0,0 +1,4 @@</span><br><span style="color: hsl(120, 100%, 40%);">+Subject: func_min and func_max</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+Introduce two new functions, MIN and MAX, which can be used to</span><br><span style="color: hsl(120, 100%, 40%);">+obtain the minimum or maximum of up to two integers.</span><br><span>diff --git a/funcs/func_max.c b/funcs/func_max.c</span><br><span>new file mode 100644</span><br><span>index 0000000..ab717ae</span><br><span>--- /dev/null</span><br><span>+++ b/funcs/func_max.c</span><br><span>@@ -0,0 +1,98 @@</span><br><span style="color: hsl(120, 100%, 40%);">+/*
</span><br><span style="color: hsl(120, 100%, 40%);">+ * Asterisk -- An open source telephony toolkit.
</span><br><span style="color: hsl(120, 100%, 40%);">+ *
</span><br><span style="color: hsl(120, 100%, 40%);">+ * Copyright (C) 2021, Digium, Inc.
</span><br><span style="color: hsl(120, 100%, 40%);">+ *
</span><br><span style="color: hsl(120, 100%, 40%);">+ * Naveen Albert <asterisk@phreaknet.org>
</span><br><span style="color: hsl(120, 100%, 40%);">+ *
</span><br><span style="color: hsl(120, 100%, 40%);">+ * See http://www.asterisk.org for more information about
</span><br><span style="color: hsl(120, 100%, 40%);">+ * the Asterisk project. Please do not directly contact
</span><br><span style="color: hsl(120, 100%, 40%);">+ * any of the maintainers of this project for assistance;
</span><br><span style="color: hsl(120, 100%, 40%);">+ * the project provides a web site, mailing lists and IRC
</span><br><span style="color: hsl(120, 100%, 40%);">+ * channels for your use.
</span><br><span style="color: hsl(120, 100%, 40%);">+ *
</span><br><span style="color: hsl(120, 100%, 40%);">+ * This program is free software, distributed under the terms of
</span><br><span style="color: hsl(120, 100%, 40%);">+ * the GNU General Public License Version 2. See the LICENSE file
</span><br><span style="color: hsl(120, 100%, 40%);">+ * at the top of the source tree.
</span><br><span style="color: hsl(120, 100%, 40%);">+ */
</span><br><span style="color: hsl(120, 100%, 40%);">+
</span><br><span style="color: hsl(120, 100%, 40%);">+/*! \file
</span><br><span style="color: hsl(120, 100%, 40%);">+ *
</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Maximum number
</span><br><span style="color: hsl(120, 100%, 40%);">+ *
</span><br><span style="color: hsl(120, 100%, 40%);">+ * \author Naveen Albert <asterisk@phreaknet.org>
</span><br><span style="color: hsl(120, 100%, 40%);">+ *
</span><br><span style="color: hsl(120, 100%, 40%);">+ * \ingroup functions
</span><br><span style="color: hsl(120, 100%, 40%);">+ */
</span><br><span style="color: hsl(120, 100%, 40%);">+
</span><br><span style="color: hsl(120, 100%, 40%);">+/*** MODULEINFO
</span><br><span style="color: hsl(120, 100%, 40%);">+ <support_level>core</support_level>
</span><br><span style="color: hsl(120, 100%, 40%);">+ ***/
</span><br><span style="color: hsl(120, 100%, 40%);">+
</span><br><span style="color: hsl(120, 100%, 40%);">+#include "asterisk.h"
</span><br><span style="color: hsl(120, 100%, 40%);">+
</span><br><span style="color: hsl(120, 100%, 40%);">+#include "asterisk/module.h"
</span><br><span style="color: hsl(120, 100%, 40%);">+#include "asterisk/channel.h"
</span><br><span style="color: hsl(120, 100%, 40%);">+#include "asterisk/pbx.h"
</span><br><span style="color: hsl(120, 100%, 40%);">+#include "asterisk/utils.h"
</span><br><span style="color: hsl(120, 100%, 40%);">+#include "asterisk/app.h"
</span><br><span style="color: hsl(120, 100%, 40%);">+
</span><br><span style="color: hsl(120, 100%, 40%);">+/*** DOCUMENTATION
</span><br><span style="color: hsl(120, 100%, 40%);">+ <function name="MAX" language="en_US">
</span><br><span style="color: hsl(120, 100%, 40%);">+ <synopsis>
</span><br><span style="color: hsl(120, 100%, 40%);">+ Returns the maximum of two integers.
</span><br><span style="color: hsl(120, 100%, 40%);">+ </synopsis>
</span><br><span style="color: hsl(120, 100%, 40%);">+ <syntax>
</span><br><span style="color: hsl(120, 100%, 40%);">+ <parameter name="num1" />
</span><br><span style="color: hsl(120, 100%, 40%);">+ <parameter name="num2" />
</span><br><span style="color: hsl(120, 100%, 40%);">+ </syntax>
</span><br><span style="color: hsl(120, 100%, 40%);">+ <description>
</span><br><span style="color: hsl(120, 100%, 40%);">+ <para>Returns the maximum of two integers <replaceable>num1</replaceable> and <replaceable>num2</replaceable>.</para>
</span><br><span style="color: hsl(120, 100%, 40%);">+ <para>Example: Set(max=${MAX(4,7)});
</span><br><span style="color: hsl(120, 100%, 40%);">+ Sets the max variable equal to 7.</para>
</span><br><span style="color: hsl(120, 100%, 40%);">+ </description>
</span><br><span style="color: hsl(120, 100%, 40%);">+ </function>
</span><br><span style="color: hsl(120, 100%, 40%);">+ ***/
</span><br><span style="color: hsl(120, 100%, 40%);">+static int acf_max_exec(struct ast_channel *chan, const char *cmd,
</span><br><span style="color: hsl(120, 100%, 40%);">+ char *parse, char *buffer, size_t buflen)
</span><br><span style="color: hsl(120, 100%, 40%);">+{
</span><br><span style="color: hsl(120, 100%, 40%);">+ int int1, response_int, int2;
</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_DECLARE_APP_ARGS(args,
</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_APP_ARG(num1);
</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_APP_ARG(num2);
</span><br><span style="color: hsl(120, 100%, 40%);">+ );
</span><br><span style="color: hsl(120, 100%, 40%);">+
</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_STANDARD_APP_ARGS(args, parse);
</span><br><span style="color: hsl(120, 100%, 40%);">+
</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_strlen_zero(args.num1) || sscanf(args.num1, "%30d", &int1) != 1)
</span><br><span style="color: hsl(120, 100%, 40%);">+ int1 = 0;
</span><br><span style="color: hsl(120, 100%, 40%);">+
</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_strlen_zero(args.num2) || sscanf(args.num2, "%30d", &int2) != 1)
</span><br><span style="color: hsl(120, 100%, 40%);">+ int2 = int1;
</span><br><span style="color: hsl(120, 100%, 40%);">+ </span><br><span style="color: hsl(120, 100%, 40%);">+ response_int = (int1 < int2) ? int2 : int1;
</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_debug(1, "%d is the maximum of [%d,%d]\n", response_int, int1, int2);
</span><br><span style="color: hsl(120, 100%, 40%);">+ snprintf(buffer, buflen, "%d", response_int);
</span><br><span style="color: hsl(120, 100%, 40%);">+
</span><br><span style="color: hsl(120, 100%, 40%);">+ return 0;
</span><br><span style="color: hsl(120, 100%, 40%);">+}
</span><br><span style="color: hsl(120, 100%, 40%);">+
</span><br><span style="color: hsl(120, 100%, 40%);">+static struct ast_custom_function acf_max = {
</span><br><span style="color: hsl(120, 100%, 40%);">+ .name = "MAX",
</span><br><span style="color: hsl(120, 100%, 40%);">+ .read = acf_max_exec,
</span><br><span style="color: hsl(120, 100%, 40%);">+ .read_max = 12,
</span><br><span style="color: hsl(120, 100%, 40%);">+};
</span><br><span style="color: hsl(120, 100%, 40%);">+
</span><br><span style="color: hsl(120, 100%, 40%);">+static int unload_module(void)
</span><br><span style="color: hsl(120, 100%, 40%);">+{
</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_custom_function_unregister(&acf_max);
</span><br><span style="color: hsl(120, 100%, 40%);">+
</span><br><span style="color: hsl(120, 100%, 40%);">+ return 0;
</span><br><span style="color: hsl(120, 100%, 40%);">+}
</span><br><span style="color: hsl(120, 100%, 40%);">+
</span><br><span style="color: hsl(120, 100%, 40%);">+static int load_module(void)
</span><br><span style="color: hsl(120, 100%, 40%);">+{
</span><br><span style="color: hsl(120, 100%, 40%);">+ return ast_custom_function_register(&acf_max);
</span><br><span style="color: hsl(120, 100%, 40%);">+}
</span><br><span style="color: hsl(120, 100%, 40%);">+
</span><br><span style="color: hsl(120, 100%, 40%);">+AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Maximum number dialplan function");</span><br><span>\ No newline at end of file</span><br><span>diff --git a/funcs/func_min.c b/funcs/func_min.c</span><br><span>new file mode 100644</span><br><span>index 0000000..e0714f7</span><br><span>--- /dev/null</span><br><span>+++ b/funcs/func_min.c</span><br><span>@@ -0,0 +1,98 @@</span><br><span style="color: hsl(120, 100%, 40%);">+/*</span><br><span style="color: hsl(120, 100%, 40%);">+ * Asterisk -- An open source telephony toolkit.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * Copyright (C) 2021, Digium, Inc.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * Naveen Albert <asterisk@phreaknet.org></span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * See http://www.asterisk.org for more information about</span><br><span style="color: hsl(120, 100%, 40%);">+ * the Asterisk project. Please do not directly contact</span><br><span style="color: hsl(120, 100%, 40%);">+ * any of the maintainers of this project for assistance;</span><br><span style="color: hsl(120, 100%, 40%);">+ * the project provides a web site, mailing lists and IRC</span><br><span style="color: hsl(120, 100%, 40%);">+ * channels for your use.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * This program is free software, distributed under the terms of</span><br><span style="color: hsl(120, 100%, 40%);">+ * the GNU General Public License Version 2. See the LICENSE file</span><br><span style="color: hsl(120, 100%, 40%);">+ * at the top of the source tree.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*! \file</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Minimum number</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \author Naveen Albert <asterisk@phreaknet.org></span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \ingroup functions</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*** MODULEINFO</span><br><span style="color: hsl(120, 100%, 40%);">+ <support_level>core</support_level></span><br><span style="color: hsl(120, 100%, 40%);">+ ***/</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#include "asterisk.h"</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#include "asterisk/module.h"</span><br><span style="color: hsl(120, 100%, 40%);">+#include "asterisk/channel.h"</span><br><span style="color: hsl(120, 100%, 40%);">+#include "asterisk/pbx.h"</span><br><span style="color: hsl(120, 100%, 40%);">+#include "asterisk/utils.h"</span><br><span style="color: hsl(120, 100%, 40%);">+#include "asterisk/app.h"</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*** DOCUMENTATION</span><br><span style="color: hsl(120, 100%, 40%);">+ <function name="MIN" language="en_US"></span><br><span style="color: hsl(120, 100%, 40%);">+ <synopsis></span><br><span style="color: hsl(120, 100%, 40%);">+ Returns the minimum of two integers.</span><br><span style="color: hsl(120, 100%, 40%);">+ </synopsis></span><br><span style="color: hsl(120, 100%, 40%);">+ <syntax></span><br><span style="color: hsl(120, 100%, 40%);">+ <parameter name="num1" /></span><br><span style="color: hsl(120, 100%, 40%);">+ <parameter name="num2" /></span><br><span style="color: hsl(120, 100%, 40%);">+ </syntax></span><br><span style="color: hsl(120, 100%, 40%);">+ <description></span><br><span style="color: hsl(120, 100%, 40%);">+ <para>Returns the minimum of two integers <replaceable>num1</replaceable> and <replaceable>num2</replaceable>.</para></span><br><span style="color: hsl(120, 100%, 40%);">+ <para>Example: Set(min=${MIN(7,4)});</span><br><span style="color: hsl(120, 100%, 40%);">+ Sets the min variable equal to 4.</para></span><br><span style="color: hsl(120, 100%, 40%);">+ </description></span><br><span style="color: hsl(120, 100%, 40%);">+ </function></span><br><span style="color: hsl(120, 100%, 40%);">+ ***/</span><br><span style="color: hsl(120, 100%, 40%);">+static int acf_min_exec(struct ast_channel *chan, const char *cmd,</span><br><span style="color: hsl(120, 100%, 40%);">+ char *parse, char *buffer, size_t buflen)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ int int1, response_int, int2;</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_DECLARE_APP_ARGS(args,</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_APP_ARG(num1);</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_APP_ARG(num2);</span><br><span style="color: hsl(120, 100%, 40%);">+ );</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_STANDARD_APP_ARGS(args, parse);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_strlen_zero(args.num1) || sscanf(args.num1, "%30d", &int1) != 1)</span><br><span style="color: hsl(120, 100%, 40%);">+ int1 = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_strlen_zero(args.num2) || sscanf(args.num2, "%30d", &int2) != 1)</span><br><span style="color: hsl(120, 100%, 40%);">+ int2 = int1;</span><br><span style="color: hsl(120, 100%, 40%);">+ </span><br><span style="color: hsl(120, 100%, 40%);">+ response_int = (int1 > int2) ? int2 : int1;</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_debug(1, "%d is the minimum of [%d,%d]\n", response_int, int1, int2);</span><br><span style="color: hsl(120, 100%, 40%);">+ snprintf(buffer, buflen, "%d", response_int);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+static struct ast_custom_function acf_min = {</span><br><span style="color: hsl(120, 100%, 40%);">+ .name = "MIN",</span><br><span style="color: hsl(120, 100%, 40%);">+ .read = acf_min_exec,</span><br><span style="color: hsl(120, 100%, 40%);">+ .read_max = 12,</span><br><span style="color: hsl(120, 100%, 40%);">+};</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+static int unload_module(void)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_custom_function_unregister(&acf_min);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+static int load_module(void)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ return ast_custom_function_register(&acf_min);</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Minimum number dialplan function");</span><br><span>\ No newline at end of file</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/15892">change 15892</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/asterisk/+/15892"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: I2bda9269d18f9d54833c85e48e41fce0e0ce4d8d </div>
<div style="display:none"> Gerrit-Change-Number: 15892 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: N A <mail@interlinked.x10host.com> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>