00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
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");