#include "asterisk.h"
#include <sys/stat.h>
#include "asterisk/module.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/utils.h"
#include "asterisk/app.h"
Go to the source code of this file.
Functions | |
static void | __reg_module (void) |
static void | __unreg_module (void) |
static int | env_read (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len) |
static int | env_write (struct ast_channel *chan, const char *cmd, char *data, const char *value) |
static int | file_read (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len) |
static int | load_module (void) |
static int | stat_read (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len) |
static int | unload_module (void) |
Variables | |
static struct ast_module_info | __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Environment/filesystem dialplan functions" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "068e67f60f50dd9ee86464c05884a49d" , .load = load_module, .unload = unload_module, } |
static const struct ast_module_info * | ast_module_info = &__mod_info |
static struct ast_custom_function | env_function |
static struct ast_custom_function | file_function |
static struct ast_custom_function | stat_function |
Definition in file func_env.c.
static void __reg_module | ( | void | ) | [static] |
Definition at line 234 of file func_env.c.
static void __unreg_module | ( | void | ) | [static] |
Definition at line 234 of file func_env.c.
static int env_read | ( | struct ast_channel * | chan, | |
const char * | cmd, | |||
char * | data, | |||
char * | buf, | |||
size_t | len | |||
) | [static] |
Definition at line 36 of file func_env.c.
References ast_copy_string().
00038 { 00039 char *ret = NULL; 00040 00041 *buf = '\0'; 00042 00043 if (data) 00044 ret = getenv(data); 00045 00046 if (ret) 00047 ast_copy_string(buf, ret, len); 00048 00049 return 0; 00050 }
static int env_write | ( | struct ast_channel * | chan, | |
const char * | cmd, | |||
char * | data, | |||
const char * | value | |||
) | [static] |
Definition at line 52 of file func_env.c.
References ast_strlen_zero(), setenv(), and unsetenv().
00054 { 00055 if (!ast_strlen_zero(data)) { 00056 if (!ast_strlen_zero(value)) { 00057 setenv(data, value, 1); 00058 } else { 00059 unsetenv(data); 00060 } 00061 } 00062 00063 return 0; 00064 }
static int file_read | ( | struct ast_channel * | chan, | |
const char * | cmd, | |||
char * | data, | |||
char * | buf, | |||
size_t | len | |||
) | [static] |
Definition at line 109 of file func_env.c.
References AST_APP_ARG, ast_copy_string(), AST_DECLARE_APP_ARGS, ast_free, ast_log(), ast_read_textfile(), AST_STANDARD_APP_ARGS, and LOG_WARNING.
00110 { 00111 AST_DECLARE_APP_ARGS(args, 00112 AST_APP_ARG(filename); 00113 AST_APP_ARG(offset); 00114 AST_APP_ARG(length); 00115 ); 00116 int offset = 0, length, res = 0; 00117 char *contents; 00118 size_t contents_len; 00119 00120 AST_STANDARD_APP_ARGS(args, data); 00121 if (args.argc > 1) { 00122 offset = atoi(args.offset); 00123 } 00124 00125 if (args.argc > 2) { 00126 /* The +1/-1 in this code section is to accomodate for the terminating NULL. */ 00127 if ((length = atoi(args.length) + 1) > len) { 00128 ast_log(LOG_WARNING, "Length %d is greater than the max (%d). Truncating output.\n", length - 1, (int)len - 1); 00129 length = len; 00130 } 00131 } else { 00132 length = len; 00133 } 00134 00135 if (!(contents = ast_read_textfile(args.filename))) { 00136 return -1; 00137 } 00138 00139 do { 00140 contents_len = strlen(contents); 00141 if (offset > contents_len) { 00142 res = -1; 00143 break; 00144 } 00145 00146 if (offset >= 0) { 00147 if (length < 0) { 00148 if (contents_len - offset + length < 0) { 00149 /* Nothing left after trimming */ 00150 res = -1; 00151 break; 00152 } 00153 ast_copy_string(buf, &contents[offset], contents_len + length); 00154 } else { 00155 ast_copy_string(buf, &contents[offset], length); 00156 } 00157 } else { 00158 if (offset * -1 > contents_len) { 00159 ast_log(LOG_WARNING, "Offset is larger than the file size.\n"); 00160 offset = contents_len * -1; 00161 } 00162 ast_copy_string(buf, &contents[contents_len + offset], length); 00163 } 00164 } while (0); 00165 00166 ast_free(contents); 00167 00168 return res; 00169 }
static int load_module | ( | void | ) | [static] |
Definition at line 223 of file func_env.c.
References ast_custom_function_register, env_function, file_function, and stat_function.
00224 { 00225 int res = 0; 00226 00227 res |= ast_custom_function_register(&env_function); 00228 res |= ast_custom_function_register(&stat_function); 00229 res |= ast_custom_function_register(&file_function); 00230 00231 return res; 00232 }
static int stat_read | ( | struct ast_channel * | chan, | |
const char * | cmd, | |||
char * | data, | |||
char * | buf, | |||
size_t | len | |||
) | [static] |
Definition at line 66 of file func_env.c.
References ast_copy_string(), and strsep().
00068 { 00069 char *action; 00070 struct stat s; 00071 00072 ast_copy_string(buf, "0", len); 00073 00074 action = strsep(&data, ","); 00075 if (stat(data, &s)) { 00076 return 0; 00077 } else { 00078 switch (*action) { 00079 case 'e': 00080 strcpy(buf, "1"); 00081 break; 00082 case 's': 00083 snprintf(buf, len, "%d", (unsigned int) s.st_size); 00084 break; 00085 case 'f': 00086 snprintf(buf, len, "%d", S_ISREG(s.st_mode) ? 1 : 0); 00087 break; 00088 case 'd': 00089 snprintf(buf, len, "%d", S_ISDIR(s.st_mode) ? 1 : 0); 00090 break; 00091 case 'M': 00092 snprintf(buf, len, "%d", (int) s.st_mtime); 00093 break; 00094 case 'A': 00095 snprintf(buf, len, "%d", (int) s.st_mtime); 00096 break; 00097 case 'C': 00098 snprintf(buf, len, "%d", (int) s.st_ctime); 00099 break; 00100 case 'm': 00101 snprintf(buf, len, "%o", (int) s.st_mode); 00102 break; 00103 } 00104 } 00105 00106 return 0; 00107 }
static int unload_module | ( | void | ) | [static] |
Definition at line 212 of file func_env.c.
References ast_custom_function_unregister(), env_function, file_function, and stat_function.
00213 { 00214 int res = 0; 00215 00216 res |= ast_custom_function_unregister(&env_function); 00217 res |= ast_custom_function_unregister(&stat_function); 00218 res |= ast_custom_function_unregister(&file_function); 00219 00220 return res; 00221 }
struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Environment/filesystem dialplan functions" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "068e67f60f50dd9ee86464c05884a49d" , .load = load_module, .unload = unload_module, } [static] |
Definition at line 234 of file func_env.c.
const struct ast_module_info* ast_module_info = &__mod_info [static] |
Definition at line 234 of file func_env.c.
struct ast_custom_function env_function [static] |
struct ast_custom_function file_function [static] |
struct ast_custom_function stat_function [static] |