Asterisk - The Open Source Telephony Project  18.5.0
Data Structures | Macros | Functions
chanvars.h File Reference

Channel Variables. More...

#include "asterisk/linkedlists.h"
Include dependency graph for chanvars.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ast_var_t
 
struct  varshead
 

Macros

#define ast_var_assign(name, value)   _ast_var_assign(name, value, __FILE__, __LINE__, __PRETTY_FUNCTION__)
 
#define AST_VAR_LIST_TRAVERSE(head, var)   AST_LIST_TRAVERSE(head, var, entries)
 

Functions

struct ast_var_t_ast_var_assign (const char *name, const char *value, const char *file, int lineno, const char *function)
 
void ast_var_delete (struct ast_var_t *var)
 
char * ast_var_find (const struct varshead *head, const char *name)
 
const char * ast_var_full_name (const struct ast_var_t *var)
 
struct varsheadast_var_list_clone (struct varshead *head)
 
struct varsheadast_var_list_create (void)
 
void ast_var_list_destroy (struct varshead *head)
 
static void AST_VAR_LIST_INSERT_HEAD (struct varshead *head, struct ast_var_t *var)
 
static void AST_VAR_LIST_INSERT_TAIL (struct varshead *head, struct ast_var_t *var)
 
const char * ast_var_name (const struct ast_var_t *var)
 
const char * ast_var_value (const struct ast_var_t *var)
 

Detailed Description

Channel Variables.

Definition in file chanvars.h.

Macro Definition Documentation

◆ ast_var_assign

#define ast_var_assign (   name,
  value 
)    _ast_var_assign(name, value, __FILE__, __LINE__, __PRETTY_FUNCTION__)

◆ AST_VAR_LIST_TRAVERSE

#define AST_VAR_LIST_TRAVERSE (   head,
  var 
)    AST_LIST_TRAVERSE(head, var, entries)

Definition at line 49 of file chanvars.h.

Referenced by ast_var_list_clone(), and fields_handler().

Function Documentation

◆ _ast_var_assign()

struct ast_var_t* _ast_var_assign ( const char *  name,
const char *  value,
const char *  file,
int  lineno,
const char *  function 
)

Definition at line 36 of file chanvars.c.

References __ast_calloc(), ast_copy_string(), ast_var_t::name, NULL, ast_var_t::value, and var.

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 }
void * __ast_calloc(size_t nmemb, size_t size, const char *file, int lineno, const char *func) attribute_malloc
Definition: astmm.c:1635
#define var
Definition: ast_expr2f.c:614
#define NULL
Definition: resample.c:96
int value
Definition: syslog.c:37
char name[0]
Definition: chanvars.h:31
char * value
Definition: chanvars.h:30
static const char name[]
Definition: cdr_mysql.c:74
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401

◆ ast_var_delete()

static void ast_var_delete ( struct ast_var_t var)

◆ ast_var_find()

char* ast_var_find ( const struct varshead head,
const char *  name 
)

Definition at line 85 of file chanvars.c.

References AST_LIST_TRAVERSE, ast_var_t::entries, ast_var_t::name, NULL, ast_var_t::value, and var.

Referenced by phoneprov_destroy(), and users_apply_handler().

86 {
87  struct ast_var_t *var;
88 
89  AST_LIST_TRAVERSE(head, var, entries) {
90  if (!strcmp(name, var->name)) {
91  return var->value;
92  }
93  }
94  return NULL;
95 }
#define var
Definition: ast_expr2f.c:614
#define NULL
Definition: resample.c:96
char name[0]
Definition: chanvars.h:31
char * value
Definition: chanvars.h:30
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:490
static const char name[]
Definition: cdr_mysql.c:74
struct ast_var_t::@249 entries

◆ ast_var_full_name()

const char* ast_var_full_name ( const struct ast_var_t var)

Definition at line 75 of file chanvars.c.

References ast_var_t::name, and NULL.

Referenced by ast_channel_inherit_variables(), ast_unreal_call_setup(), and inherit_channel_vars_from_id().

76 {
77  return (var ? var->name : NULL);
78 }
#define NULL
Definition: resample.c:96
char name[0]
Definition: chanvars.h:31

◆ ast_var_list_clone()

struct varshead* ast_var_list_clone ( struct varshead head)

Definition at line 124 of file chanvars.c.

References ast_var_assign, ast_var_list_create(), ast_var_list_destroy(), AST_VAR_LIST_INSERT_TAIL(), AST_VAR_LIST_TRAVERSE, ast_var_t::name, NULL, ast_var_t::value, and var.

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 
138  AST_VAR_LIST_TRAVERSE(head, var) {
139  newvar = ast_var_assign(var->name, var->value);
140  if (!newvar) {
141  ast_var_list_destroy(clone);
142  return NULL;
143  }
144  AST_VAR_LIST_INSERT_TAIL(clone, newvar);
145  }
146 
147  return clone;
148 }
void ast_var_list_destroy(struct varshead *head)
Definition: chanvars.c:109
#define var
Definition: ast_expr2f.c:614
#define NULL
Definition: resample.c:96
struct varshead * ast_var_list_create(void)
Definition: chanvars.c:97
char name[0]
Definition: chanvars.h:31
char * value
Definition: chanvars.h:30
#define ast_var_assign(name, value)
Definition: chanvars.h:40
#define AST_VAR_LIST_TRAVERSE(head, var)
Definition: chanvars.h:49
static void AST_VAR_LIST_INSERT_TAIL(struct varshead *head, struct ast_var_t *var)
Definition: chanvars.h:51

◆ ast_var_list_create()

struct varshead* ast_var_list_create ( void  )

Definition at line 97 of file chanvars.c.

References ast_calloc, AST_LIST_HEAD_INIT_NOLOCK, and NULL.

Referenced by ast_var_list_clone(), build_profile(), get_defaults(), handle_aor(), handle_registrations(), and phoneprov_alloc().

98 {
99  struct varshead *head;
100 
101  head = ast_calloc(1, sizeof(*head));
102  if (!head) {
103  return NULL;
104  }
106  return head;
107 }
#define NULL
Definition: resample.c:96
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:204
#define AST_LIST_HEAD_INIT_NOLOCK(head)
Initializes a list head structure.
Definition: linkedlists.h:680

◆ ast_var_list_destroy()

void ast_var_list_destroy ( struct varshead head)

Definition at line 109 of file chanvars.c.

References ast_free, AST_LIST_REMOVE_HEAD, ast_var_delete(), ast_var_t::entries, and var.

Referenced by ast_var_list_clone(), get_defaults(), handle_aor(), handle_registrations(), and phoneprov_destroy().

110 {
111  struct ast_var_t *var;
112 
113  if (!head) {
114  return;
115  }
116 
117  while ((var = AST_LIST_REMOVE_HEAD(head, entries))) {
118  ast_var_delete(var);
119  }
120 
121  ast_free(head);
122 }
#define var
Definition: ast_expr2f.c:614
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
Definition: linkedlists.h:832
#define ast_free(a)
Definition: astmm.h:182
struct ast_var_t::@249 entries
void ast_var_delete(struct ast_var_t *var)
Definition: chanvars.c:55

◆ AST_VAR_LIST_INSERT_HEAD()

static void AST_VAR_LIST_INSERT_HEAD ( struct varshead head,
struct ast_var_t var 
)
inlinestatic

Definition at line 57 of file chanvars.h.

References AST_LIST_INSERT_HEAD, and ast_var_t::entries.

57  {
58  if (var) {
59  AST_LIST_INSERT_HEAD(head, var, entries);
60  }
61 }
#define AST_LIST_INSERT_HEAD(head, elm, field)
Inserts a list entry at the head of a list.
Definition: linkedlists.h:710
struct ast_var_t::@249 entries

◆ AST_VAR_LIST_INSERT_TAIL()

static void AST_VAR_LIST_INSERT_TAIL ( struct varshead head,
struct ast_var_t var 
)
inlinestatic

Definition at line 51 of file chanvars.h.

References AST_LIST_INSERT_TAIL, and ast_var_t::entries.

Referenced by assign_and_insert(), ast_var_list_clone(), build_profile(), get_defaults(), handle_aor(), handle_registrations(), and set_timezone_variables().

51  {
52  if (var) {
53  AST_LIST_INSERT_TAIL(head, var, entries);
54  }
55 }
#define AST_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
Definition: linkedlists.h:730
struct ast_var_t::@249 entries

◆ ast_var_name()

const char* ast_var_name ( const struct ast_var_t var)

◆ ast_var_value()

const char* ast_var_value ( const struct ast_var_t var)