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 #include "asterisk.h"
00027
00028 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 40722 $")
00029
00030 #include <stdio.h>
00031 #include <stdlib.h>
00032 #include <string.h>
00033 #include <sys/types.h>
00034 #include <sys/stat.h>
00035
00036 #include "asterisk/module.h"
00037 #include "asterisk/channel.h"
00038 #include "asterisk/pbx.h"
00039 #include "asterisk/utils.h"
00040
00041 static int global_read(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
00042 {
00043 const char *var = pbx_builtin_getvar_helper(NULL, data);
00044
00045 *buf = '\0';
00046
00047 if (var)
00048 ast_copy_string(buf, var, len);
00049
00050 return 0;
00051 }
00052
00053 static int global_write(struct ast_channel *chan, char *cmd, char *data, const char *value)
00054 {
00055 pbx_builtin_setvar_helper(NULL, data, value);
00056
00057 return 0;
00058 }
00059
00060 static struct ast_custom_function global_function = {
00061 .name = "GLOBAL",
00062 .synopsis = "Gets or sets the global variable specified",
00063 .syntax = "GLOBAL(<varname>)",
00064 .read = global_read,
00065 .write = global_write,
00066 };
00067
00068 static int unload_module(void)
00069 {
00070 int res = 0;
00071
00072 res |= ast_custom_function_unregister(&global_function);
00073
00074 return res;
00075 }
00076
00077 static int load_module(void)
00078 {
00079 int res = 0;
00080
00081 res |= ast_custom_function_register(&global_function);
00082
00083 return res;
00084 }
00085
00086 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Global variable dialplan functions");