Fri Jul 24 00:40:54 2009

Asterisk developer's documentation


datastore.c

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- An open source telephony toolkit.
00003  *
00004  * Copyright (C) 2007 - 2008, Digium, Inc.
00005  *
00006  * See http://www.asterisk.org for more information about
00007  * the Asterisk project. Please do not directly contact
00008  * any of the maintainers of this project for assistance;
00009  * the project provides a web site, mailing lists and IRC
00010  * channels for your use.
00011  *
00012  * This program is free software, distributed under the terms of
00013  * the GNU General Public License Version 2. See the LICENSE file
00014  * at the top of the source tree.
00015  */
00016 
00017 /*! \file
00018  *
00019  * \brief Asterisk datastore objects
00020  */
00021 
00022 #include "asterisk.h"
00023 
00024 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 135680 $")
00025 
00026 #include "asterisk/_private.h"
00027 
00028 #include "asterisk/datastore.h"
00029 #include "asterisk/utils.h"
00030 
00031 struct ast_datastore *ast_datastore_alloc(const struct ast_datastore_info *info, const char *uid)
00032 {
00033    struct ast_datastore *datastore = NULL;
00034 
00035    /* Make sure we at least have type so we can identify this */
00036    if (!info) {
00037       return NULL;
00038    }
00039 
00040    /* Allocate memory for datastore and clear it */
00041    datastore = ast_calloc(1, sizeof(*datastore));
00042    if (!datastore) {
00043       return NULL;
00044    }
00045 
00046    datastore->info = info;
00047 
00048    datastore->uid = ast_strdup(uid);
00049 
00050    return datastore;
00051 }
00052 
00053 int ast_datastore_free(struct ast_datastore *datastore)
00054 {
00055    int res = 0;
00056 
00057    /* Using the destroy function (if present) destroy the data */
00058    if (datastore->info->destroy != NULL && datastore->data != NULL) {
00059       datastore->info->destroy(datastore->data);
00060       datastore->data = NULL;
00061    }
00062 
00063    /* Free allocated UID memory */
00064    if (datastore->uid != NULL) {
00065       ast_free((void *) datastore->uid);
00066       datastore->uid = NULL;
00067    }
00068 
00069    /* Finally free memory used by ourselves */
00070    ast_free(datastore);
00071 
00072    return res;
00073 }

Generated on Fri Jul 24 00:40:54 2009 for Asterisk - the Open Source PBX by  doxygen 1.4.7