Mon Mar 31 07:38:02 2008

Asterisk developer's documentation


func_global.c

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- An open source telephony toolkit.
00003  *
00004  * Copyright (C) 2006, Tilghman Lesher
00005  *
00006  * Tilghman Lesher <func_global__200605@the-tilghman.com>
00007  *
00008  * See http://www.asterisk.org for more information about
00009  * the Asterisk project. Please do not directly contact
00010  * any of the maintainers of this project for assistance;
00011  * the project provides a web site, mailing lists and IRC
00012  * channels for your use.
00013  *
00014  * This program is free software, distributed under the terms of
00015  * the GNU General Public License Version 2. See the LICENSE file
00016  * at the top of the source tree.
00017  */
00018 
00019 /*! \file
00020  *
00021  * \brief Global variable dialplan functions
00022  *
00023  * \author Tilghman Lesher <func_global__200605@the-tilghman.com>
00024  *
00025  * \ingroup functions
00026  */
00027 
00028 #include "asterisk.h"
00029 
00030 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
00031 
00032 #include <stdio.h>
00033 #include <stdlib.h>
00034 #include <string.h>
00035 #include <sys/types.h>
00036 #include <sys/stat.h>
00037 
00038 #include "asterisk/module.h"
00039 #include "asterisk/channel.h"
00040 #include "asterisk/pbx.h"
00041 #include "asterisk/utils.h"
00042 
00043 static int global_read(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
00044 {
00045    const char *var = pbx_builtin_getvar_helper(NULL, data);
00046 
00047    *buf = '\0';
00048 
00049    if (var)
00050       ast_copy_string(buf, var, len);
00051 
00052    return 0;
00053 }
00054 
00055 static int global_write(struct ast_channel *chan, char *cmd, char *data, const char *value)
00056 {
00057    pbx_builtin_setvar_helper(NULL, data, value);
00058 
00059    return 0;
00060 }
00061 
00062 static struct ast_custom_function global_function = {
00063    .name = "GLOBAL",
00064    .synopsis = "Gets or sets the global variable specified",
00065    .syntax = "GLOBAL(<varname>)",
00066    .read = global_read,
00067    .write = global_write,
00068 };
00069 
00070 static int unload_module(void)
00071 {
00072    int res = 0;
00073 
00074    res |= ast_custom_function_unregister(&global_function);
00075 
00076    return res;
00077 }
00078 
00079 static int load_module(void)
00080 {
00081    int res = 0;
00082 
00083    res |= ast_custom_function_register(&global_function);
00084 
00085    return res;
00086 }
00087 
00088 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Global variable dialplan functions");

Generated on Mon Mar 31 07:38:02 2008 for Asterisk - the Open Source PBX by  doxygen 1.5.1