Sat Sep 16 07:28:08 2006

Asterisk developer's documentation


func_env.c

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- An open source telephony toolkit.
00003  *
00004  * Copyright (C) 1999 - 2005, Digium, Inc.
00005  *
00006  * See http://www.asterisk.org for more information about
00007  * the Asterisk project. Please do not directly contact
00008  * any of the maintainers of this project for assistance;
00009  * the project provides a web site, mailing lists and IRC
00010  * channels for your use.
00011  *
00012  * This program is free software, distributed under the terms of
00013  * the GNU General Public License Version 2. See the LICENSE file
00014  * at the top of the source tree.
00015  */
00016 
00017 /*! \file
00018  *
00019  * \brief Environment related dialplan functions
00020  * 
00021  */
00022 
00023 #include <stdlib.h>
00024 #include <string.h>
00025 #include <sys/types.h>
00026 
00027 #include "asterisk.h"
00028 
00029 /* ASTERISK_FILE_VERSION(__FILE__, "$Revision: 7221 $") */
00030 
00031 #include "asterisk/channel.h"
00032 #include "asterisk/pbx.h"
00033 #include "asterisk/logger.h"
00034 #include "asterisk/utils.h"
00035 #include "asterisk/app.h"
00036 
00037 static char *builtin_function_env_read(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) 
00038 {
00039    char *ret = "";
00040 
00041    if (data) {
00042       ret = getenv(data);
00043       if (!ret)
00044          ret = "";
00045    }
00046    ast_copy_string(buf, ret, len);
00047 
00048    return buf;
00049 }
00050 
00051 static void builtin_function_env_write(struct ast_channel *chan, char *cmd, char *data, const char *value) 
00052 {
00053    if (!ast_strlen_zero(data)) {
00054       if (!ast_strlen_zero(value)) {
00055          setenv(data, value, 1);
00056       } else {
00057          unsetenv(data);
00058       }
00059    }
00060 }
00061 
00062 #ifndef BUILTIN_FUNC
00063 static
00064 #endif
00065 struct ast_custom_function env_function = {
00066    .name = "ENV",
00067    .synopsis = "Gets or sets the environment variable specified",
00068    .syntax = "ENV(<envname>)",
00069    .read = builtin_function_env_read,
00070    .write = builtin_function_env_write,
00071 };

Generated on Sat Sep 16 07:28:08 2006 for Asterisk - the Open Source PBX by  doxygen 1.4.7