]> git.sesse.net Git - vlc/blob - src/misc/sql.c
Use var_Inherit* instead of var_CreateGet*.
[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 #if !defined( __LIBVLC__ )
25   #error You are not libvlc or one of its plugins. You cannot include this file
26 #endif
27
28 #ifdef HAVE_CONFIG_H
29 #include "config.h"
30 #endif
31
32 #include <vlc_common.h>
33 #include <vlc_sql.h>
34 #include <vlc_modules.h>
35 #include <assert.h>
36 #include "libvlc.h"
37
38 #undef sql_Create
39 sql_t *sql_Create( vlc_object_t *p_this, const char *psz_name,
40         const char* psz_host, int i_port,
41         const char* psz_user, const char* psz_pass )
42 {
43     sql_t *p_sql;
44
45     p_sql = ( sql_t * ) vlc_custom_create( p_this, sizeof( sql_t ),
46                                            VLC_OBJECT_GENERIC, "sql" );
47     if( !p_sql )
48     {
49         msg_Err( p_this, "unable to create sql object" );
50         return NULL;
51     }
52     vlc_object_attach( p_sql, p_this );
53
54     p_sql->psz_host = strdup( psz_host );
55     p_sql->psz_user = strdup( psz_user );
56     p_sql->psz_pass = strdup( psz_pass );
57     p_sql->i_port = i_port;
58
59     p_sql->p_module = module_need( p_sql, "sql", psz_name,
60                                    psz_name && *psz_name );
61     if( !p_sql->p_module )
62     {
63         free( p_sql->psz_host );
64         free( p_sql->psz_user );
65         free( p_sql->psz_pass );
66         vlc_object_release( p_sql );
67         msg_Err( p_this, "SQL provider not found" );
68         return NULL;
69     }
70
71     return p_sql;
72 }
73
74 #undef sql_Destroy
75 void sql_Destroy( vlc_object_t* obj )
76 {
77     sql_t *p_sql = (sql_t *)obj;
78     assert( p_sql );
79
80     free( p_sql->psz_host );
81     free( p_sql->psz_user );
82     free( p_sql->psz_pass );
83
84     module_unneed( p_sql, p_sql->p_module );
85
86     vlc_object_release( obj );
87 }