Asterisk - The Open Source Telephony Project GIT-master-0bf3178
chanvars.c
Go to the documentation of this file.
1/*
2 * Asterisk -- An open source telephony toolkit.
3 *
4 * Copyright (C) 1999 - 2005, Digium, Inc.
5 *
6 * Mark Spencer <markster@digium.com>
7 *
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.
13 *
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.
17 */
18
19/*! \file
20 *
21 * \brief Channel Variables
22 *
23 * \author Mark Spencer <markster@digium.com>
24 */
25
26/*** MODULEINFO
27 <support_level>core</support_level>
28 ***/
29
30#include "asterisk.h"
31
32#include "asterisk/chanvars.h"
33#include "asterisk/strings.h"
34#include "asterisk/utils.h"
35
36struct ast_var_t *_ast_var_assign(const char *name, const char *value, const char *file, int lineno, const char *function)
37{
38 struct ast_var_t *var;
39 int name_len = strlen(name) + 1;
40 int value_len = strlen(value) + 1;
41
42 var = __ast_calloc(sizeof(*var) + name_len + value_len, sizeof(char),
43 file, lineno, function);
44 if (!var) {
45 return NULL;
46 }
47
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);
51
52 return var;
53}
54
56{
58}
59
60const char *ast_var_name(const struct ast_var_t *var)
61{
62 const char *name;
63
64 if (var == NULL || (name = var->name) == NULL)
65 return NULL;
66 /* Return the name without the initial underscores */
67 if (name[0] == '_') {
68 name++;
69 if (name[0] == '_')
70 name++;
71 }
72 return name;
73}
74
75const char *ast_var_full_name(const struct ast_var_t *var)
76{
77 return (var ? var->name : NULL);
78}
79
80const char *ast_var_value(const struct ast_var_t *var)
81{
82 return (var ? var->value : NULL);
83}
84
85char *ast_var_find(const struct varshead *head, const char *name)
86{
87 struct ast_var_t *var;
88
90 if (!strcmp(name, var->name)) {
91 return var->value;
92 }
93 }
94 return NULL;
95}
96
98{
99 struct varshead *head;
100
101 head = ast_calloc(1, sizeof(*head));
102 if (!head) {
103 return NULL;
104 }
106 return head;
107}
108
110{
111 struct ast_var_t *var;
112
113 if (!head) {
114 return;
115 }
116
117 while ((var = AST_LIST_REMOVE_HEAD(head, entries))) {
119 }
120
121 ast_free(head);
122}
123
125{
126 struct varshead *clone;
127 struct ast_var_t *var, *newvar;
128
129 if (!head) {
130 return NULL;
131 }
132
133 clone = ast_var_list_create();
134 if (!clone) {
135 return NULL;
136 }
137
139 newvar = ast_var_assign(var->name, var->value);
140 if (!newvar) {
142 return NULL;
143 }
144 AST_VAR_LIST_INSERT_TAIL(clone, newvar);
145 }
146
147 return clone;
148}
#define var
Definition: ast_expr2f.c:605
Asterisk main include file. File version handling, generic pbx functions.
#define ast_free(a)
Definition: astmm.h:180
void * __ast_calloc(size_t nmemb, size_t size, const char *file, int lineno, const char *func) attribute_malloc
Definition: astmm.c:1603
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:202
void ast_var_list_destroy(struct varshead *head)
Definition: chanvars.c:109
char * ast_var_find(const struct varshead *head, const char *name)
Definition: chanvars.c:85
const char * ast_var_name(const struct ast_var_t *var)
Definition: chanvars.c:60
void ast_var_delete(struct ast_var_t *var)
Definition: chanvars.c:55
const char * ast_var_full_name(const struct ast_var_t *var)
Definition: chanvars.c:75
const char * ast_var_value(const struct ast_var_t *var)
Definition: chanvars.c:80
struct varshead * ast_var_list_clone(struct varshead *head)
Definition: chanvars.c:124
struct ast_var_t * _ast_var_assign(const char *name, const char *value, const char *file, int lineno, const char *function)
Definition: chanvars.c:36
struct varshead * ast_var_list_create(void)
Definition: chanvars.c:97
Channel Variables.
static void AST_VAR_LIST_INSERT_TAIL(struct varshead *head, struct ast_var_t *var)
Definition: chanvars.h:51
#define AST_VAR_LIST_TRAVERSE(head, var)
Definition: chanvars.h:49
#define ast_var_assign(name, value)
Definition: chanvars.h:40
static const char name[]
Definition: format_mp3.c:68
#define AST_LIST_HEAD_INIT_NOLOCK(head)
Initializes a list head structure.
Definition: linkedlists.h:681
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:491
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
Definition: linkedlists.h:833
#define NULL
Definition: resample.c:96
String manipulation functions.
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:425
struct ast_var_t::@211 entries
int value
Definition: syslog.c:37
Utility functions.