[svn-commits] branch oej/test-this-branch r12372 - in /team/oej/test-this-branch: ./ funcs/...

svn-commits at lists.digium.com svn-commits at lists.digium.com
Tue Mar 7 12:38:06 MST 2006


Author: oej
Date: Tue Mar  7 13:38:02 2006
New Revision: 12372

URL: http://svn.digium.com/view/asterisk?rev=12372&view=rev
Log:
Adding IFMODULE dialplan function to check whether module is loaded in Asterisk
or not. 

Added:
    team/oej/test-this-branch/funcs/func_module.c   (with props)
Modified:
    team/oej/test-this-branch/README.test-this-branch
    team/oej/test-this-branch/include/asterisk/module.h
    team/oej/test-this-branch/loader.c

Modified: team/oej/test-this-branch/README.test-this-branch
URL: http://svn.digium.com/view/asterisk/team/oej/test-this-branch/README.test-this-branch?rev=12372&r1=12371&r2=12372&view=diff
==============================================================================
--- team/oej/test-this-branch/README.test-this-branch (original)
+++ team/oej/test-this-branch/README.test-this-branch Tue Mar  7 13:38:02 2006
@@ -31,13 +31,14 @@
 
 And the following stand-alone patches
 - New CLI commands for global variables (oej, #6506)
-- Additional options for the CHANNEL dialplan function (oej)
+- Additional options for the CHANNEL dialplan function (oej, #6670)
 - Manager sendtext event (ZX81, #6131)
 - Carrier ENUM support (otmar, #5526)
 - HDLC mode support for ZAP channels (crich, #6251)
 - Show manager CLI commands (junky, #5240)
 - Support SIP_CODEC for early media (oej, #6576)
 - Show threads CLI command (rizzo, #6053)
+- IFMODULE dialplan function (oej, #6671)
 
 Coming here soon:
 - siptransfer: Improved SIP transfer support

Added: team/oej/test-this-branch/funcs/func_module.c
URL: http://svn.digium.com/view/asterisk/team/oej/test-this-branch/funcs/func_module.c?rev=12372&view=auto
==============================================================================
--- team/oej/test-this-branch/funcs/func_module.c (added)
+++ team/oej/test-this-branch/funcs/func_module.c Tue Mar  7 13:38:02 2006
@@ -1,0 +1,93 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 1999 - 2006, Digium, Inc.
+ *
+ * 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 Simple module check function
+ * \author Olle E. Johansson, Edvina.net
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include "asterisk.h"
+
+ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+
+#include "asterisk/module.h"
+#include "asterisk/channel.h"
+#include "asterisk/pbx.h"
+#include "asterisk/logger.h"
+#include "asterisk/utils.h"
+#include "asterisk/app.h"
+#include "asterisk/module.h"
+
+static int ifmodule_read(struct ast_channel *chan, char *cmd, char *data,
+		    char *buf, size_t len)
+{
+	char *ret = NULL;
+
+	*buf = '\0';
+
+	if (data)
+		if (ast_module_check(data))
+			ret = "1";
+
+	if (ret)
+		ast_copy_string(buf, ret, len);
+
+	return 0;
+}
+
+static struct ast_custom_function ifmodule_function = {
+	.name = "IFMODULE",
+	.synopsis = "Checks if an Asterisk module is loaded in memory",
+	.syntax = "IFMODULE(<modulename.so>)",
+	.read = ifmodule_read,
+	.desc = "Checks if a module is loaded. Use the full module name\n"
+		"as shown by the list in \"show modules\". \n"
+		"Returns \"1\" if module exists in memory, otherwise nothing.\n",
+};
+
+static char *tdesc = "Checks if Asterisk module is loaded in memory";
+
+int unload_module(void)
+{
+	return ast_custom_function_unregister(&ifmodule_function);
+}
+
+int load_module(void)
+{
+	return ast_custom_function_register(&ifmodule_function);
+}
+
+char *description(void)
+{
+	return tdesc;
+}
+
+int usecount(void)
+{
+	return 0;
+}
+
+char *key()
+{
+	return ASTERISK_GPL_KEY;
+}

Propchange: team/oej/test-this-branch/funcs/func_module.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/oej/test-this-branch/funcs/func_module.c
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: team/oej/test-this-branch/funcs/func_module.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: team/oej/test-this-branch/include/asterisk/module.h
URL: http://svn.digium.com/view/asterisk/team/oej/test-this-branch/include/asterisk/module.h?rev=12372&r1=12371&r2=12372&view=diff
==============================================================================
--- team/oej/test-this-branch/include/asterisk/module.h (original)
+++ team/oej/test-this-branch/include/asterisk/module.h Tue Mar  7 13:38:02 2006
@@ -188,6 +188,13 @@
  */
 int ast_update_module_list(int (*modentry)(const char *module, const char *description, int usecnt, const char *like),
 			   const char *like);
+
+/*!
+ * \brief Check if module with the name given is loaded
+ * \param name Module name, like "chan_sip.so"
+ * \return 0 if false, 1 if true 
+ */
+int ast_module_check(char *name);
 
 /*! 
  * \brief Add a procedure to be run when modules have been updated.

Modified: team/oej/test-this-branch/loader.c
URL: http://svn.digium.com/view/asterisk/team/oej/test-this-branch/loader.c?rev=12372&r1=12371&r2=12372&view=diff
==============================================================================
--- team/oej/test-this-branch/loader.c (original)
+++ team/oej/test-this-branch/loader.c Tue Mar  7 13:38:02 2006
@@ -577,6 +577,25 @@
 	return total_mod_loaded;
 }
 
+int ast_module_check(char *name)
+{
+	struct module *cur;
+	int unlock = -1;
+	int res = 0;
+
+	if (ast_strlen_zero(name))
+		return 0;	/* FALSE */
+
+	if (ast_mutex_trylock(&module_list.lock))
+		unlock = 0;
+	AST_LIST_TRAVERSE(&module_list, cur, next)
+		if (!res && !strcasecmp(name, cur->resource))
+			res = 1;
+	if (unlock)
+		AST_LIST_UNLOCK(&module_list);
+	return res;
+}
+
 int ast_loader_register(int (*v)(void)) 
 {
 	/* XXX Should be more flexible here, taking > 1 verboser XXX */



More information about the svn-commits mailing list