Main Page | Alphabetical List | Data Structures | File List | Data Fields | Globals

chanvars.c

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- A telephony toolkit for Linux.
00003  *
00004  * Channel Variables
00005  * 
00006  * Copyright (C) 2002, Mark Spencer
00007  *
00008  * Mark Spencer <markster@linux-support.net>
00009  *
00010  * This program is free software, distributed under the terms of
00011  * the GNU General Public License
00012  */
00013 
00014 #include <stdlib.h>
00015 #include <string.h>
00016 
00017 #include <asterisk/chanvars.h>
00018 #include <asterisk/logger.h>
00019 
00020 struct ast_var_t *ast_var_assign(char *name, char *value)
00021 {
00022    int i;
00023    struct ast_var_t *var;
00024    
00025    var = malloc(sizeof(struct ast_var_t));
00026 
00027    if (var == NULL)
00028    {
00029       ast_log(LOG_WARNING, "Out of memory\n");
00030       return NULL;
00031    }
00032    
00033    i = strlen(value);
00034    var->value = malloc(i + 1);
00035    if (var->value == NULL)
00036    {
00037       ast_log(LOG_WARNING, "Out of memory\n");
00038       free(var);
00039       return NULL;
00040    }
00041 
00042    strncpy(var->value, value, i);
00043    var->value[i] = '\0';
00044    
00045    i = strlen(name);
00046    var->name = malloc(i + 1);
00047    if (var->name == NULL)
00048    {
00049       ast_log(LOG_WARNING, "Out of memory\n");
00050       free(var->value);
00051       free(var);
00052       return NULL;
00053    }
00054 
00055    strncpy(var->name, name, i); 
00056    var->name[i] = '\0';
00057 
00058    return var;
00059 }  
00060    
00061 void ast_var_delete(struct ast_var_t *var)
00062 {
00063    if (var == NULL) return;
00064 
00065    if (var->name != NULL) free(var->name);
00066    if (var->value != NULL) free(var->value);
00067 
00068    free(var);
00069 }
00070 
00071 char *ast_var_name(struct ast_var_t *var)
00072 {
00073    return (var != NULL ? var->name : NULL);
00074 }
00075 
00076 char *ast_var_value(struct ast_var_t *var)
00077 {
00078    return (var != NULL ? var->value : NULL);
00079 }
00080 
00081    

Generated on Fri Feb 27 12:19:41 2004 for Asterisk by doxygen 1.3.5