00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "asterisk.h"
00023
00024 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 192354 $")
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 const char *file, int line, const char *function)
00033 {
00034 struct ast_datastore *datastore = NULL;
00035
00036
00037 if (!info) {
00038 return NULL;
00039 }
00040
00041 #if defined(__AST_DEBUG_MALLOC)
00042 if (!(datastore = __ast_calloc(1, sizeof(*datastore), file, line, function))) {
00043 return NULL;
00044 }
00045 #else
00046 if (!(datastore = ast_calloc(1, sizeof(*datastore)))) {
00047 return NULL;
00048 }
00049 #endif
00050
00051 datastore->info = info;
00052
00053 datastore->uid = ast_strdup(uid);
00054
00055 return datastore;
00056 }
00057
00058 int ast_datastore_free(struct ast_datastore *datastore)
00059 {
00060 int res = 0;
00061
00062
00063 if (datastore->info->destroy != NULL && datastore->data != NULL) {
00064 datastore->info->destroy(datastore->data);
00065 datastore->data = NULL;
00066 }
00067
00068
00069 if (datastore->uid != NULL) {
00070 ast_free((void *) datastore->uid);
00071 datastore->uid = NULL;
00072 }
00073
00074
00075 ast_free(datastore);
00076
00077 return res;
00078 }
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089 #undef ast_datastore_alloc
00090 struct ast_datastore *ast_datastore_alloc(const struct ast_datastore_info *info, const char *uid);
00091 struct ast_datastore *ast_datastore_alloc(const struct ast_datastore_info *info, const char *uid)
00092 {
00093 return __ast_datastore_alloc(info, uid, __FILE__, __LINE__, __FUNCTION__);
00094 }