make Local channel return sensible device state values
[asterisk-bristuff.git] / chanvars.c
blobe21b3fc57c9f536d80a5601ddd3d8f788a94ad4c
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 <stdlib.h>
31 #include <string.h>
33 #include "asterisk/chanvars.h"
34 #include "asterisk/logger.h"
35 #include "asterisk/strings.h"
36 #include "asterisk/utils.h"
38 struct ast_var_t *ast_var_assign(const char *name, const char *value)
40 struct ast_var_t *var;
41 int name_len = strlen(name) + 1;
42 int value_len = strlen(value) + 1;
44 if (!(var = ast_calloc(sizeof(*var) + name_len + value_len, sizeof(char)))) {
45 return NULL;
48 ast_copy_string(var->name, name, name_len);
49 var->value = var->name + name_len;
50 ast_copy_string(var->value, value, value_len);
52 return var;
55 void ast_var_delete(struct ast_var_t *var)
57 if (var)
58 free(var);
61 const char *ast_var_name(const struct ast_var_t *var)
63 const char *name;
65 if (var == NULL || (name = var->name) == NULL)
66 return NULL;
67 /* Return the name without the initial underscores */
68 if (name[0] == '_') {
69 name++;
70 if (name[0] == '_')
71 name++;
73 return name;
76 const char *ast_var_full_name(const struct ast_var_t *var)
78 return (var ? var->name : NULL);
81 const char *ast_var_value(const struct ast_var_t *var)
83 return (var ? var->value : NULL);