/* * CallWeaver -- An open source telephony toolkit. * * Copyright (C) 1999 - 2005, Digium, Inc. * * See http://www.callweaver.org for more information about * the CallWeaver 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 Environment related dialplan functions * */ #ifdef HAVE_CONFIG_H #include "confdefs.h" #endif #include #include #include #include #include "callweaver.h" CALLWEAVER_FILE_VERSION("$HeadURL$", "$Revision$") #include "callweaver/module.h" #include "callweaver/channel.h" #include "callweaver/pbx.h" #include "callweaver/logger.h" #include "callweaver/utils.h" #include "callweaver/app.h" static void *env_function; static const char *env_func_name = "ENV"; static const char *env_func_synopsis = "Gets or sets the environment variable specified"; static const char *env_func_syntax = "ENV(envname)"; static const char *env_func_desc = ""; static char *builtin_function_env_read(struct opbx_channel *chan, int argc, char **argv, char *buf, size_t len) { char *ret = ""; if (argv[0]) { ret = getenv(argv[0]); if (!ret) ret = ""; } opbx_copy_string(buf, ret, len); return buf; } static void builtin_function_env_write(struct opbx_channel *chan, int argc, char **argv, const char *value) { if (argc > 0 && argv[0][0]) { if (value && *value) { setenv(argv[0], value, 1); } else { unsetenv(argv[0]); } } } static char *tdesc = "Get or set environment variables."; int unload_module(void) { return opbx_unregister_function(env_function); } int load_module(void) { env_function = opbx_register_function(env_func_name, builtin_function_env_read, builtin_function_env_write, env_func_synopsis, env_func_syntax, env_func_desc); return 0; } char *description(void) { return tdesc; } int usecount(void) { return 0; } /* Local Variables: mode: C c-file-style: "linux" indent-tabs-mode: nil End: */