Wed Jan 8 2020 09:49:46

Asterisk developer's documentation


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 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 369001 $")
33 
34 #include "asterisk/chanvars.h"
35 #include "asterisk/strings.h"
36 #include "asterisk/utils.h"
37 
38 #ifdef MALLOC_DEBUG
39 struct ast_var_t *_ast_var_assign(const char *name, const char *value, const char *file, int lineno, const char *function)
40 #else
41 struct ast_var_t *ast_var_assign(const char *name, const char *value)
42 #endif
43 {
44  struct ast_var_t *var;
45  int name_len = strlen(name) + 1;
46  int value_len = strlen(value) + 1;
47 
48 #ifdef MALLOC_DEBUG
49  if (!(var = __ast_calloc(sizeof(*var) + name_len + value_len, sizeof(char), file, lineno, function))) {
50 #else
51  if (!(var = ast_calloc(sizeof(*var) + name_len + value_len, sizeof(char)))) {
52 #endif
53  return NULL;
54  }
55 
56  ast_copy_string(var->name, name, name_len);
57  var->value = var->name + name_len;
58  ast_copy_string(var->value, value, value_len);
59 
60  return var;
61 }
62 
63 void ast_var_delete(struct ast_var_t *var)
64 {
65  if (var)
66  ast_free(var);
67 }
68 
69 const char *ast_var_name(const struct ast_var_t *var)
70 {
71  const char *name;
72 
73  if (var == NULL || (name = var->name) == NULL)
74  return NULL;
75  /* Return the name without the initial underscores */
76  if (name[0] == '_') {
77  name++;
78  if (name[0] == '_')
79  name++;
80  }
81  return name;
82 }
83 
84 const char *ast_var_full_name(const struct ast_var_t *var)
85 {
86  return (var ? var->name : NULL);
87 }
88 
89 const char *ast_var_value(const struct ast_var_t *var)
90 {
91  return (var ? var->value : NULL);
92 }
93 
94 
Asterisk main include file. File version handling, generic pbx functions.
String manipulation functions.
const char * ast_var_value(const struct ast_var_t *var)
Definition: chanvars.c:89
struct ast_var_t * ast_var_assign(const char *name, const char *value)
Definition: chanvars.c:41
const char * ast_var_name(const struct ast_var_t *var)
Definition: chanvars.c:69
#define var
Definition: ast_expr2f.c:606
void * __ast_calloc(size_t nmemb, size_t size, const char *file, int lineno, const char *func)
int value
Definition: syslog.c:39
void ast_var_delete(struct ast_var_t *var)
Definition: chanvars.c:63
Utility functions.
char * value
Definition: chanvars.h:30
char name[0]
Definition: chanvars.h:31
const char * ast_var_full_name(const struct ast_var_t *var)
Definition: chanvars.c:84
static const char name[]
#define ast_free(a)
Definition: astmm.h:97
#define ast_calloc(a, b)
Definition: astmm.h:82
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:223
#define ASTERISK_FILE_VERSION(file, version)
Register/unregister a source code file with the core.
Definition: asterisk.h:180