Wed Jan 8 2020 09:49:48

Asterisk developer's documentation


global_datastores.c
Go to the documentation of this file.
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 1999 - 2007, Digium, Inc.
5  *
6  * Mark Michelson <mmichelson@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 globally-accessible datastore information and callbacks
22  *
23  * \author Mark Michelson <mmichelson@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/global_datastores.h"
35 #include "asterisk/linkedlists.h"
36 
37 static void dialed_interface_destroy(void *data)
38 {
39  struct ast_dialed_interface *di = NULL;
40  AST_LIST_HEAD(, ast_dialed_interface) *dialed_interface_list = data;
41 
42  if (!dialed_interface_list) {
43  return;
44  }
45 
46  AST_LIST_LOCK(dialed_interface_list);
47  while ((di = AST_LIST_REMOVE_HEAD(dialed_interface_list, list)))
48  ast_free(di);
49  AST_LIST_UNLOCK(dialed_interface_list);
50 
51  AST_LIST_HEAD_DESTROY(dialed_interface_list);
52  ast_free(dialed_interface_list);
53 }
54 
55 static void *dialed_interface_duplicate(void *data)
56 {
57  struct ast_dialed_interface *di = NULL;
59  AST_LIST_HEAD(, ast_dialed_interface) *new_list = NULL;
60 
61  if(!(old_list = data)) {
62  return NULL;
63  }
64 
65  if(!(new_list = ast_calloc(1, sizeof(*new_list)))) {
66  return NULL;
67  }
68 
69  AST_LIST_HEAD_INIT(new_list);
70  AST_LIST_LOCK(old_list);
71  AST_LIST_TRAVERSE(old_list, di, list) {
72  struct ast_dialed_interface *di2 = ast_calloc(1, sizeof(*di2) + strlen(di->interface));
73  if(!di2) {
74  AST_LIST_UNLOCK(old_list);
75  dialed_interface_destroy(new_list);
76  return NULL;
77  }
78  strcpy(di2->interface, di->interface);
79  AST_LIST_INSERT_TAIL(new_list, di2, list);
80  }
81  AST_LIST_UNLOCK(old_list);
82 
83  return new_list;
84 }
85 
87  .type = "dialed-interface",
88  .destroy = dialed_interface_destroy,
89  .duplicate = dialed_interface_duplicate,
90 };
91 
92 static void secure_call_store_destroy(void *data)
93 {
94  struct ast_secure_call_store *store = data;
95 
96  ast_free(store);
97 }
98 
99 static void *secure_call_store_duplicate(void *data)
100 {
101  struct ast_secure_call_store *old = data;
102  struct ast_secure_call_store *new;
103 
104  if (!(new = ast_calloc(1, sizeof(*new)))) {
105  return NULL;
106  }
107  new->signaling = old->signaling;
108  new->media = old->media;
109 
110  return new;
111 }
113  .type = "encrypt-call",
114  .destroy = secure_call_store_destroy,
115  .duplicate = secure_call_store_duplicate,
116 };
const char * type
Definition: datastore.h:32
#define AST_LIST_LOCK(head)
Locks a list.
Definition: linkedlists.h:39
Asterisk main include file. File version handling, generic pbx functions.
#define AST_LIST_HEAD(name, type)
Defines a structure to be used to hold a list of specified type.
Definition: linkedlists.h:172
static void * dialed_interface_duplicate(void *data)
#define AST_LIST_UNLOCK(head)
Attempts to unlock a list.
Definition: linkedlists.h:139
Structure for a data store type.
Definition: datastore.h:31
#define AST_LIST_HEAD_DESTROY(head)
Destroys a list head structure.
Definition: linkedlists.h:638
struct ast_datastore_info dialed_interface_info
A set of macros to manage forward-linked lists.
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
Definition: linkedlists.h:818
static void secure_call_store_destroy(void *data)
struct ast_datastore_info secure_call_info
#define AST_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
Definition: linkedlists.h:716
static float di[4]
Definition: tdd.c:59
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:490
struct ast_dialed_interface::@174 list
static void * secure_call_store_duplicate(void *data)
#define AST_LIST_HEAD_INIT(head)
Initializes a list head structure.
Definition: linkedlists.h:611
#define ast_free(a)
Definition: astmm.h:97
#define ast_calloc(a, b)
Definition: astmm.h:82
#define ASTERISK_FILE_VERSION(file, version)
Register/unregister a source code file with the core.
Definition: asterisk.h:180
static void dialed_interface_destroy(void *data)