/***** * * Copyright (C) 2002, 2003 Pablo Belin * All Rights Reserved * * This file is part of the gprelude program. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. * *****/ #include #include #include #include #include #include #include #include "list.h" #include "gprelude-mem.h" #include "db-interface.h" gprelude_db_interface_t *gprelude_db_interface_new ( void ) { gprelude_db_interface_t *db; db = malloc ( sizeof(gprelude_db_interface_t) ); if ( !db ) { log ( LOG_ERR, "memory exhausted.\n" ); return NULL; } memset ( db, 0, sizeof(gprelude_db_interface_t) ); db->name = NULL; db->format = NULL; db->type = prelude_db_type_invalid; return db; } int gprelude_db_interface_destroy ( void *data ) { gprelude_db_interface_t *db = (gprelude_db_interface_t *)data; if ( !db ) return -1; gprelude_free ( db->name ); gprelude_free ( db->format ); switch ( db->type ) { case prelude_db_type_sql: prelude_sql_connection_data_destroy ( db->data.sql ); break; default: break; } free ( db ); return 0; } gprelude_db_interface_t *gprelude_db_interface_search_by_name ( list_t *list, const char *name ) { list_t *tmp; gprelude_db_interface_t *iface; if ( !name ) return NULL; list_foreach ( list, tmp ) { iface = list_get_data ( tmp ); if ( iface && iface->name && (strcmp ( iface->name, name ) == 0) ) return iface; } return NULL; }