Mon Mar 19 11:30:26 2012

Asterisk developer's documentation


chanvars.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  * 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: 149199 $")
00029 
00030 #include "asterisk/chanvars.h"
00031 #include "asterisk/strings.h"
00032 #include "asterisk/utils.h"
00033 
00034 #ifdef MALLOC_DEBUG
00035 struct ast_var_t *_ast_var_assign(const char *name, const char *value, const char *file, int lineno, const char *function)
00036 #else
00037 struct ast_var_t *ast_var_assign(const char *name, const char *value)
00038 #endif
00039 {  
00040    struct ast_var_t *var;
00041    int name_len = strlen(name) + 1;
00042    int value_len = strlen(value) + 1;
00043 
00044 #ifdef MALLOC_DEBUG
00045    if (!(var = __ast_calloc(sizeof(*var) + name_len + value_len, sizeof(char), file, lineno, function))) {
00046 #else
00047    if (!(var = ast_calloc(sizeof(*var) + name_len + value_len, sizeof(char)))) {
00048 #endif
00049       return NULL;
00050    }
00051 
00052    ast_copy_string(var->name, name, name_len);
00053    var->value = var->name + name_len;
00054    ast_copy_string(var->value, value, value_len);
00055    
00056    return var;
00057 }  
00058    
00059 void ast_var_delete(struct ast_var_t *var)
00060 {
00061    if (var)
00062       ast_free(var);
00063 }
00064 
00065 const char *ast_var_name(const struct ast_var_t *var)
00066 {
00067    const char *name;
00068 
00069    if (var == NULL || (name = var->name) == NULL)
00070       return NULL;
00071    /* Return the name without the initial underscores */
00072    if (name[0] == '_') {
00073       name++;
00074       if (name[0] == '_')
00075          name++;
00076    }
00077    return name;
00078 }
00079 
00080 const char *ast_var_full_name(const struct ast_var_t *var)
00081 {
00082    return (var ? var->name : NULL);
00083 }
00084 
00085 const char *ast_var_value(const struct ast_var_t *var)
00086 {
00087    return (var ? var->value : NULL);
00088 }
00089 
00090 

Generated on Mon Mar 19 11:30:26 2012 for Asterisk - The Open Source Telephony Project by  doxygen 1.4.7