ld_res.c

Go to the documentation of this file.
00001 /* 
00002  * $Id$ 
00003  *
00004  * LDAP Database Driver for SER
00005  *
00006  * Copyright (C) 2008 iptelorg GmbH
00007  *
00008  * This file is part of SER, a free SIP server.
00009  *
00010  * SER 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  * SER 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 
00033 #include <string.h>
00034 
00035 #include "ld_res.h"
00036 #include "ld_cmd.h"
00037 
00038 #include "../../mem/mem.h"
00039 #include "../../dprint.h"
00040 #include "../../lib/srdb2/db_gen.h"
00041 
00042 
00043 static void ld_res_free(db_res_t* res, struct ld_res* payload)
00044 {
00045         db_drv_free(&payload->gen);
00046         if (payload->msg) ldap_msgfree(payload->msg);
00047         payload->msg = NULL;
00048         pkg_free(payload);
00049 }
00050 
00051 
00052 int ld_res(db_res_t* res)
00053 {
00054         struct ld_res* lres;
00055 
00056         lres = (struct ld_res*)pkg_malloc(sizeof(struct ld_res));
00057         if (lres == NULL) {
00058                 ERR("ldap: No memory left\n");
00059                 return -1;
00060         }
00061         memset(lres, '\0', sizeof(struct ld_res));
00062         if (db_drv_init(&lres->gen, ld_res_free) < 0) goto error;
00063         DB_SET_PAYLOAD(res, lres);
00064         return 0;
00065         
00066  error:
00067         if (lres) {
00068                 db_drv_free(&lres->gen);
00069                 pkg_free(lres);
00070         }
00071         return -1;
00072 }
00073