Mon May 14 04:48:11 2007

Asterisk developer's documentation


func_env.c File Reference

Environment related dialplan functions. More...

#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"

Include dependency graph for func_env.c:

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


Detailed Description

Environment related dialplan functions.

Definition in file func_env.c.


Function Documentation

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 41 of file func_env.c.

00043 {
00044    char *ret = NULL;
00045 
00046    *buf = '\0';
00047 
00048    if (data)
00049       ret = getenv(data);
00050 
00051    if (ret)
00052       ast_copy_string(buf, ret, len);
00053 
00054    return 0;
00055 }

static int env_write ( struct ast_channel chan,
char *  cmd,
char *  data,
const char *  value 
) [static]

Definition at line 57 of file func_env.c.

References ast_strlen_zero(), setenv(), and unsetenv().

00059 {
00060    if (!ast_strlen_zero(data)) {
00061       if (!ast_strlen_zero(value)) {
00062          setenv(data, value, 1);
00063       } else {
00064          unsetenv(data);
00065       }
00066    }
00067 
00068    return 0;
00069 }

static int load_module ( void   )  [static]

Definition at line 149 of file func_env.c.

References ast_custom_function_register(), env_function, and stat_function.

00150 {
00151    int res = 0;
00152 
00153    res |= ast_custom_function_register(&env_function);
00154    res |= ast_custom_function_register(&stat_function);
00155 
00156    return res;
00157 }

static int stat_read ( struct ast_channel chan,
char *  cmd,
char *  data,
char *  buf,
size_t  len 
) [static]

Definition at line 71 of file func_env.c.

References strsep().

00073 {
00074    char *action;
00075    struct stat s;
00076 
00077    *buf = '\0';
00078 
00079    action = strsep(&data, "|");
00080    if (stat(data, &s)) {
00081       return -1;
00082    } else {
00083       switch (*action) {
00084       case 'e':
00085          strcpy(buf, "1");
00086          break;
00087       case 's':
00088          snprintf(buf, len, "%d", (unsigned int) s.st_size);
00089          break;
00090       case 'f':
00091          snprintf(buf, len, "%d", S_ISREG(s.st_mode) ? 1 : 0);
00092          break;
00093       case 'd':
00094          snprintf(buf, len, "%d", S_ISDIR(s.st_mode) ? 1 : 0);
00095          break;
00096       case 'M':
00097          snprintf(buf, len, "%d", (int) s.st_mtime);
00098          break;
00099       case 'A':
00100          snprintf(buf, len, "%d", (int) s.st_mtime);
00101          break;
00102       case 'C':
00103          snprintf(buf, len, "%d", (int) s.st_ctime);
00104          break;
00105       case 'm':
00106          snprintf(buf, len, "%o", (int) s.st_mode);
00107          break;
00108       }
00109    }
00110 
00111    return 0;
00112 }

static int unload_module ( void   )  [static]

Definition at line 139 of file func_env.c.

References ast_custom_function_unregister(), env_function, and stat_function.

00140 {
00141    int res = 0;
00142 
00143    res |= ast_custom_function_unregister(&env_function);
00144    res |= ast_custom_function_unregister(&stat_function);
00145 
00146    return res;
00147 }


Variable Documentation

struct ast_custom_function env_function [static]

Definition at line 114 of file func_env.c.

Referenced by load_module(), and unload_module().

struct ast_custom_function stat_function [static]

Definition at line 122 of file func_env.c.

Referenced by load_module(), and unload_module().


Generated on Mon May 14 04:48:12 2007 for Asterisk - the Open Source PBX by  doxygen 1.5.1