fix various other problems found by gcc 4.3
[asterisk-bristuff.git] / main / global_datastores.c
blob9b87b2cb43dceaa2e61f2fd07f22add5a497684f
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;
41 AST_LIST_LOCK(dialed_interface_list);
42 while ((di = AST_LIST_REMOVE_HEAD(dialed_interface_list, list)))
43 ast_free(di);
44 AST_LIST_UNLOCK(dialed_interface_list);
46 AST_LIST_HEAD_DESTROY(dialed_interface_list);
47 ast_free(dialed_interface_list);
50 static void *dialed_interface_duplicate(void *data)
52 struct ast_dialed_interface *di = NULL;
53 AST_LIST_HEAD(, ast_dialed_interface) *old_list;
54 AST_LIST_HEAD(, ast_dialed_interface) *new_list = NULL;
56 if(!(old_list = data))
57 return NULL;
59 if(!(new_list = ast_calloc(1, sizeof(*new_list))))
60 return NULL;
62 AST_LIST_HEAD_INIT(new_list);
63 AST_LIST_LOCK(old_list);
64 AST_LIST_TRAVERSE(old_list, di, list) {
65 struct ast_dialed_interface *di2 = ast_calloc(1, sizeof(*di2) + strlen(di->interface));
66 if(!di2) {
67 AST_LIST_UNLOCK(old_list);
68 dialed_interface_destroy(new_list);
69 return NULL;
71 strcpy(di2->interface, di->interface);
72 AST_LIST_INSERT_TAIL(new_list, di2, list);
74 AST_LIST_UNLOCK(old_list);
76 return new_list;
79 const struct ast_datastore_info dialed_interface_info = {
80 .type ="dialed-interface",
81 .destroy = dialed_interface_destroy,
82 .duplicate = dialed_interface_duplicate,