]> git.sesse.net Git - vlc/blob - src/misc/sql.c
8d4e412b803937f3d0cec01aaf3cd36ef33b3f04
[vlc] / src / misc / sql.c
1 /*****************************************************************************
2  * sql.c: SQL Connection: Creators and destructors
3  *****************************************************************************
4  * Copyright (C) 2008-2009 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Srikanth Raju <srikiraju at gmail dot com>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 #ifdef HAVE_CONFIG_H
25 #include "config.h"
26 #endif
27
28 #include <vlc_common.h>
29 #include <vlc_sql.h>
30 #include <vlc_modules.h>
31 #include <assert.h>
32 #include "libvlc.h"
33
34 #undef sql_Create
35 sql_t *sql_Create( vlc_object_t *p_this, const char *psz_name,
36         const char* psz_host, int i_port,
37         const char* psz_user, const char* psz_pass )
38 {
39     sql_t *p_sql;
40
41     p_sql = ( sql_t * ) vlc_custom_create( p_this, sizeof( sql_t ), "sql" );
42     if( !p_sql )
43     {
44         msg_Err( p_this, "unable to create sql object" );
45         return NULL;
46     }
47
48     p_sql->psz_host = strdup( psz_host );
49     p_sql->psz_user = strdup( psz_user );
50     p_sql->psz_pass = strdup( psz_pass );
51     p_sql->i_port = i_port;
52
53     p_sql->p_module = module_need( p_sql, "sql", psz_name,
54                                    psz_name && *psz_name );
55     if( !p_sql->p_module )
56     {
57         free( p_sql->psz_host );
58         free( p_sql->psz_user );
59         free( p_sql->psz_pass );
60         vlc_object_release( p_sql );
61         msg_Err( p_this, "SQL provider not found" );
62         return NULL;
63     }
64
65     return p_sql;
66 }
67
68 #undef sql_Destroy
69 void sql_Destroy( vlc_object_t* obj )
70 {
71     sql_t *p_sql = (sql_t *)obj;
72     assert( p_sql );
73
74     free( p_sql->psz_host );
75     free( p_sql->psz_user );
76     free( p_sql->psz_pass );
77
78     module_unneed( p_sql, p_sql->p_module );
79
80     vlc_object_release( obj );
81 }