#include "asterisk.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "asterisk/module.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/logger.h"
#include "asterisk/utils.h"
#include "asterisk/app.h"
Go to the source code of this file.
Functions | |
AST_MODULE_INFO_STANDARD (ASTERISK_GPL_KEY,"Environment/filesystem dialplan functions") | |
static int | env_read (struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) |
static int | env_write (struct ast_channel *chan, char *cmd, char *data, const char *value) |
static int | load_module (void) |
static int | stat_read (struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) |
static int | unload_module (void) |
Variables | |
static struct ast_custom_function | env_function |
static struct ast_custom_function | stat_function |
Definition in file func_env.c.
AST_MODULE_INFO_STANDARD | ( | ASTERISK_GPL_KEY | , | |
"Environment/filesystem dialplan functions" | ||||
) |
static int env_read | ( | struct ast_channel * | chan, | |
char * | cmd, | |||
char * | data, | |||
char * | buf, | |||
size_t | len | |||
) | [static] |
Definition at line 40 of file func_env.c.
00042 { 00043 char *ret = NULL; 00044 00045 *buf = '\0'; 00046 00047 if (data) 00048 ret = getenv(data); 00049 00050 if (ret) 00051 ast_copy_string(buf, ret, len); 00052 00053 return 0; 00054 }
static int env_write | ( | struct ast_channel * | chan, | |
char * | cmd, | |||
char * | data, | |||
const char * | value | |||
) | [static] |
Definition at line 56 of file func_env.c.
References ast_strlen_zero(), setenv(), and unsetenv().
00058 { 00059 if (!ast_strlen_zero(data)) { 00060 if (!ast_strlen_zero(value)) { 00061 setenv(data, value, 1); 00062 } else { 00063 unsetenv(data); 00064 } 00065 } 00066 00067 return 0; 00068 }
static int load_module | ( | void | ) | [static] |
Definition at line 148 of file func_env.c.
References ast_custom_function_register().
00149 { 00150 int res = 0; 00151 00152 res |= ast_custom_function_register(&env_function); 00153 res |= ast_custom_function_register(&stat_function); 00154 00155 return res; 00156 }
static int stat_read | ( | struct ast_channel * | chan, | |
char * | cmd, | |||
char * | data, | |||
char * | buf, | |||
size_t | len | |||
) | [static] |
Definition at line 70 of file func_env.c.
References strsep().
00072 { 00073 char *action; 00074 struct stat s; 00075 00076 ast_copy_string(buf, "0", len); 00077 00078 action = strsep(&data, "|"); 00079 if (stat(data, &s)) { 00080 return 0; 00081 } else { 00082 switch (*action) { 00083 case 'e': 00084 strcpy(buf, "1"); 00085 break; 00086 case 's': 00087 snprintf(buf, len, "%d", (unsigned int) s.st_size); 00088 break; 00089 case 'f': 00090 snprintf(buf, len, "%d", S_ISREG(s.st_mode) ? 1 : 0); 00091 break; 00092 case 'd': 00093 snprintf(buf, len, "%d", S_ISDIR(s.st_mode) ? 1 : 0); 00094 break; 00095 case 'M': 00096 snprintf(buf, len, "%d", (int) s.st_mtime); 00097 break; 00098 case 'A': 00099 snprintf(buf, len, "%d", (int) s.st_mtime); 00100 break; 00101 case 'C': 00102 snprintf(buf, len, "%d", (int) s.st_ctime); 00103 break; 00104 case 'm': 00105 snprintf(buf, len, "%o", (int) s.st_mode); 00106 break; 00107 } 00108 } 00109 00110 return 0; 00111 }
static int unload_module | ( | void | ) | [static] |
Definition at line 138 of file func_env.c.
References ast_custom_function_unregister().
00139 { 00140 int res = 0; 00141 00142 res |= ast_custom_function_unregister(&env_function); 00143 res |= ast_custom_function_unregister(&stat_function); 00144 00145 return res; 00146 }
struct ast_custom_function env_function [static] |
Definition at line 113 of file func_env.c.
struct ast_custom_function stat_function [static] |
Definition at line 121 of file func_env.c.