bdb_fld.c

Go to the documentation of this file.
00001 /*
00002  * $Id$
00003  *
00004  * BDB Database Driver for SIP-router
00005  *
00006  * Copyright (C) 2008 iptelorg GmbH
00007  *
00008  * This file is part of SIP-router, a free SIP server.
00009  *
00010  * SIP-router is free software; you can redistribute it and/or modify it under the
00011  * terms of the GNU General Public License as published by the Free Software
00012  * Foundation; either version 2 of the License, or (at your option) any later
00013  * version.
00014  *
00015  * SIP-router is distributed in the hope that it will be useful, but WITHOUT ANY
00016  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00017  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
00018  * details.
00019  *
00020  * You should have received a copy of the GNU General Public License along
00021  * with this program; if not, write to the Free Software Foundation, Inc.,
00022  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
00023  */
00024 
00035 #include <stdlib.h>
00036 #include <stdio.h>
00037 #include <strings.h>
00038 #include <stdint.h>
00039 #include <string.h>
00040 #include <time.h>   /* strptime, XOPEN issue must be >= 4 */
00041 
00042 #include "../../lib/srdb2/db_drv.h"
00043 #include "../../mem/mem.h"
00044 #include "../../dprint.h"
00045 #include "../../ut.h"
00046 
00047 #include "bdb_fld.h"
00048 
00049 static void bdb_fld_free(db_fld_t* fld, bdb_fld_t* payload)
00050 {
00051         db_drv_free(&payload->gen);
00052         if (payload->buf.s) pkg_free(payload->buf.s);
00053         if (payload->name) pkg_free(payload->name);
00054         pkg_free(payload);
00055 }
00056 
00057 
00058 int bdb_fld(db_fld_t* fld, char* table)
00059 {
00060         bdb_fld_t *res;
00061 
00062         res = (bdb_fld_t*)pkg_malloc(sizeof(bdb_fld_t));
00063         if (res == NULL) {
00064                 ERR("oracle: No memory left\n");
00065                 return -1;
00066         }
00067         memset(res, '\0', sizeof(bdb_fld_t));
00068         res->col_pos = -1;
00069         if (db_drv_init(&res->gen, bdb_fld_free) < 0) goto error;
00070 
00071         DB_SET_PAYLOAD(fld, res);
00072         return 0;
00073 
00074 error:
00075         if (res) pkg_free(res);
00076         return -1;
00077 }
00078 
00079