Asterisk.org: Developer Documentation (28 Oct 2009)

Wed Oct 28 15:47:53 2009

## Asterisk developer's documentation

- Main Page
- Related Pages
- Modules
- Data Structures
- Files
- Directories

# 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  */
    00024
    00025 #include <stdlib.h>
    00026 #include <string.h>
    00027
    00028 #include "asterisk.h"
    00029
    00030 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 7221 $")
    00031
    00032 #include "asterisk/chanvars.h"
    00033 #include "asterisk/logger.h"
    00034 #include "asterisk/strings.h"
    00035
    00036 struct ast_var_t *ast_var_assign(const char *name, const char *value)
    00037 {
    00038    int i;
    00039    struct ast_var_t *var;
    00040
    00041    var = calloc(sizeof(struct ast_var_t) + strlen(name) + 1 + strlen(value) + 1, sizeof(char));
    00042
    00043    if (var == NULL) {
    00044       ast_log(LOG_WARNING, "Out of memory\n");
    00045       return NULL;
    00046    }
    00047
    00048    i = strlen(name) + 1;
    00049    ast_copy_string(var->name, name, i);
    00050    var->value = var->name + i;
    00051    ast_copy_string(var->value, value, strlen(value) + 1);
    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 char *ast_var_name(struct ast_var_t *var)
    00063 {
    00064    char *name;
    00065
    00066    if (var == NULL)
    00067       return NULL;
    00068    if (var->name == NULL)
    00069       return NULL;
    00070    /* Return the name without the initial underscores */
    00071    if (var->name[0] == '_') {
    00072       if (var->name[1] == '_')
    00073          name = (char*)&(var->name[2]);
    00074       else
    00075          name = (char*)&(var->name[1]);
    00076    } else
    00077       name = var->name;
    00078    return name;
    00079 }
    00080
    00081 char *ast_var_full_name(struct ast_var_t *var)
    00082 {
    00083    return (var ? var->name : NULL);
    00084 }
    00085
    00086 char *ast_var_value(struct ast_var_t *var)
    00087 {
    00088    return (var ? var->value : NULL);
    00089 }
    00090
    00091