use tzafrir's patch to fix this problem properly... i made the previous set of change...
[asterisk-bristuff.git] / main / global_datastores.c
blobca04a0fe93c24b5ab2834a9fa9baa4b85baff23b
1 /*
2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 1999 - 2007, Digium, Inc.
6 * Mark Michelson <mmichelson@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 globally-accessible datastore information and callbacks
23 * \author Mark Michelson <mmichelson@digium.com>
26 #include "asterisk.h"
28 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
30 #include "asterisk/global_datastores.h"
31 #include "asterisk/linkedlists.h"
33 static void dialed_interface_destroy(void *data)
35 struct ast_dialed_interface *di = NULL;
36 AST_LIST_HEAD(, ast_dialed_interface) *dialed_interface_list = data;
38 if (!dialed_interface_list) {
39 return;
42 AST_LIST_LOCK(dialed_interface_list);
43 while ((di = AST_LIST_REMOVE_HEAD(dialed_interface_list, list)))
44 ast_free(di);
45 AST_LIST_UNLOCK(dialed_interface_list);
47 AST_LIST_HEAD_DESTROY(dialed_interface_list);
48 ast_free(dialed_interface_list);
51 static void *dialed_interface_duplicate(void *data)
53 struct ast_dialed_interface *di = NULL;
54 AST_LIST_HEAD(, ast_dialed_interface) *old_list;
55 AST_LIST_HEAD(, ast_dialed_interface) *new_list = NULL;
57 if(!(old_list = data)) {
58 return NULL;
61 if(!(new_list = ast_calloc(1, sizeof(*new_list)))) {
62 return NULL;
65 AST_LIST_HEAD_INIT(new_list);
66 AST_LIST_LOCK(old_list);
67 AST_LIST_TRAVERSE(old_list, di, list) {
68 struct ast_dialed_interface *di2 = ast_calloc(1, sizeof(*di2) + strlen(di->interface));
69 if(!di2) {
70 AST_LIST_UNLOCK(old_list);
71 dialed_interface_destroy(new_list);
72 return NULL;
74 strcpy(di2->interface, di->interface);
75 AST_LIST_INSERT_TAIL(new_list, di2, list);
77 AST_LIST_UNLOCK(old_list);
79 return new_list;
83 static void *dial_features_duplicate(void *data)
85 struct ast_dial_features *df = data, *df_copy;
87 if (!(df_copy = ast_calloc(1, sizeof(*df)))) {
88 return NULL;
91 memcpy(df_copy, df, sizeof(*df));
93 return df_copy;
96 static void dial_features_destroy(void *data) {
97 struct ast_dial_features *df = data;
98 if (df) {
99 ast_free(df);
103 const struct ast_datastore_info dialed_interface_info = {
104 .type = "dialed-interface",
105 .destroy = dialed_interface_destroy,
106 .duplicate = dialed_interface_duplicate,
109 const struct ast_datastore_info dial_features_info = {
110 .type = "dial-features",
111 .destroy = dial_features_destroy,
112 .duplicate = dial_features_duplicate,