Let's also include aclocal.m4
[asterisk-bristuff.git] / main / chanvars.c
blob7e617c1fb946819686e30e6ae6c3665d0648abe3
1 /*
2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 1999 - 2005, Digium, Inc.
6 * Mark Spencer <markster@digium.com>
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
19 /*! \file
21 * \brief Channel Variables
23 * \author Mark Spencer <markster@digium.com>
26 #include "asterisk.h"
28 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <string.h>
34 #include "asterisk/chanvars.h"
35 #include "asterisk/logger.h"
36 #include "asterisk/strings.h"
37 #include "asterisk/utils.h"
39 struct ast_var_t *ast_var_assign(const char *name, const char *value)
41 struct ast_var_t *var;
42 int name_len = strlen(name) + 1;
43 int value_len = strlen(value) + 1;
45 if (!(var = ast_calloc(sizeof(*var) + name_len + value_len, sizeof(char)))) {
46 return NULL;
49 ast_copy_string(var->name, name, name_len);
50 var->value = var->name + name_len;
51 ast_copy_string(var->value, value, value_len);
53 return var;
56 void ast_var_delete(struct ast_var_t *var)
58 if (var)
59 free(var);
62 const char *ast_var_name(const struct ast_var_t *var)
64 const char *name;
66 if (var == NULL || (name = var->name) == NULL)
67 return NULL;
68 /* Return the name without the initial underscores */
69 if (name[0] == '_') {
70 name++;
71 if (name[0] == '_')
72 name++;
74 return name;
77 const char *ast_var_full_name(const struct ast_var_t *var)
79 return (var ? var->name : NULL);
82 const char *ast_var_value(const struct ast_var_t *var)
84 return (var ? var->value : NULL);