00001 /* 00002 * Asterisk -- An open source telephony toolkit. 00003 * 00004 * Copyright (C) 1999 - 2005, Digium, Inc. 00005 * 00006 * Mark Spencer <markster@digium.com> 00007 * 00008 * See http://www.asterisk.org for more information about 00009 * the Asterisk project. Please do not directly contact 00010 * any of the maintainers of this project for assistance; 00011 * the project provides a web site, mailing lists and IRC 00012 * channels for your use. 00013 * 00014 * This program is free software, distributed under the terms of 00015 * the GNU General Public License Version 2. See the LICENSE file 00016 * at the top of the source tree. 00017 */ 00018 00019 /*! \file 00020 * 00021 * \brief Channel Variables 00022 * 00023 * \author Mark Spencer <markster@digium.com> 00024 */ 00025 00026 #include "asterisk.h" 00027 00028 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 40864 $") 00029 00030 #include <stdio.h> 00031 #include <stdlib.h> 00032 #include <string.h> 00033 00034 #include "asterisk/chanvars.h" 00035 #include "asterisk/logger.h" 00036 #include "asterisk/strings.h" 00037 #include "asterisk/utils.h" 00038 00039 struct ast_var_t *ast_var_assign(const char *name, const char *value) 00040 { 00041 struct ast_var_t *var; 00042 int name_len = strlen(name) + 1; 00043 int value_len = strlen(value) + 1; 00044 00045 if (!(var = ast_calloc(sizeof(*var) + name_len + value_len, sizeof(char)))) { 00046 return NULL; 00047 } 00048 00049 ast_copy_string(var->name, name, name_len); 00050 var->value = var->name + name_len; 00051 ast_copy_string(var->value, value, value_len); 00052 00053 return var; 00054 } 00055 00056 void ast_var_delete(struct ast_var_t *var) 00057 { 00058 if (var) 00059 free(var); 00060 } 00061 00062 const char *ast_var_name(const struct ast_var_t *var) 00063 { 00064 const char *name; 00065 00066 if (var == NULL || (name = var->name) == NULL) 00067 return NULL; 00068 /* Return the name without the initial underscores */ 00069 if (name[0] == '_') { 00070 name++; 00071 if (name[0] == '_') 00072 name++; 00073 } 00074 return name; 00075 } 00076 00077 const char *ast_var_full_name(const struct ast_var_t *var) 00078 { 00079 return (var ? var->name : NULL); 00080 } 00081 00082 const char *ast_var_value(const struct ast_var_t *var) 00083 { 00084 return (var ? var->value : NULL); 00085 } 00086 00087