Sat Apr 12 07:12:24 2008

Asterisk developer's documentation


global_datastores.c

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- An open source telephony toolkit.
00003  *
00004  * Copyright (C) 1999 - 2007, Digium, Inc.
00005  *
00006  * Mark Michelson <mmichelson@digium.com>
00007  *
00008  * See http://www.asterisk.org for more information about
00009  * the Asterisk project. Please do not directly contact
00010  * any of the maintainers of this project for assistance;
00011  * the project provides a web site, mailing lists and IRC
00012  * channels for your use.
00013  *
00014  * This program is free software, distributed under the terms of
00015  * the GNU General Public License Version 2. See the LICENSE file
00016  * at the top of the source tree.
00017  */
00018 
00019 /*! \file
00020  *
00021  * \brief globally-accessible datastore information and callbacks
00022  *
00023  * \author Mark Michelson <mmichelson@digium.com>
00024  */
00025 
00026 #include "asterisk/global_datastores.h"
00027 #include "asterisk/linkedlists.h"
00028 
00029 static void dialed_interface_destroy(void *data)
00030 {
00031    struct ast_dialed_interface *di = NULL;
00032    AST_LIST_HEAD(, ast_dialed_interface) *dialed_interface_list = data;
00033    
00034    if (!dialed_interface_list)
00035       return;
00036 
00037    AST_LIST_LOCK(dialed_interface_list);
00038    while ((di = AST_LIST_REMOVE_HEAD(dialed_interface_list, list)))
00039       ast_free(di);
00040    AST_LIST_UNLOCK(dialed_interface_list);
00041 
00042    AST_LIST_HEAD_DESTROY(dialed_interface_list);
00043    ast_free(dialed_interface_list);
00044 }
00045 
00046 static void *dialed_interface_duplicate(void *data)
00047 {
00048    struct ast_dialed_interface *di = NULL;
00049    AST_LIST_HEAD(, ast_dialed_interface) *old_list;
00050    AST_LIST_HEAD(, ast_dialed_interface) *new_list = NULL;
00051 
00052    if(!(old_list = data))
00053       return NULL;
00054 
00055    if(!(new_list = ast_calloc(1, sizeof(*new_list))))
00056       return NULL;
00057 
00058    AST_LIST_HEAD_INIT(new_list);
00059    AST_LIST_LOCK(old_list);
00060    AST_LIST_TRAVERSE(old_list, di, list) {
00061       struct ast_dialed_interface *di2 = ast_calloc(1, sizeof(*di2) + strlen(di->interface));
00062       if(!di2) {
00063          AST_LIST_UNLOCK(old_list);
00064          dialed_interface_destroy(new_list);
00065          return NULL;
00066       }
00067       strcpy(di2->interface, di->interface);
00068       AST_LIST_INSERT_TAIL(new_list, di2, list);
00069    }
00070    AST_LIST_UNLOCK(old_list);
00071 
00072    return new_list;
00073 }
00074 
00075 const struct ast_datastore_info dialed_interface_info = {
00076    .type ="dialed-interface",
00077    .destroy = dialed_interface_destroy,
00078    .duplicate = dialed_interface_duplicate,
00079 };

Generated on Sat Apr 12 07:12:24 2008 for Asterisk - the Open Source PBX by  doxygen 1.5.5