]> git.sesse.net Git - vlc/blob - src/misc/sql.c
Plus sign must not be decoded in URI
[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 <assert.h>
35 #include "libvlc.h"
36
37 #undef sql_Create
38 sql_t *sql_Create( vlc_object_t *p_this, const char *psz_name,
39         const char* psz_host, int i_port,
40         const char* psz_user, const char* psz_pass )
41 {
42     sql_t *p_sql;
43
44     p_sql = ( sql_t * ) vlc_custom_create( p_this, sizeof( sql_t ),
45                                            VLC_OBJECT_GENERIC, "sql" );
46     if( !p_sql )
47     {
48         msg_Err( p_this, "unable to create sql object" );
49         return NULL;
50     }
51     vlc_object_attach( p_sql, p_this );
52
53     p_sql->psz_host = strdup( psz_host );
54     p_sql->psz_user = strdup( psz_user );
55     p_sql->psz_pass = strdup( psz_pass );
56     p_sql->i_port = i_port;
57
58     p_sql->p_module = module_need( p_sql, "sql", psz_name,
59                                    psz_name && *psz_name );
60     if( !p_sql->p_module )
61     {
62         free( p_sql->psz_host );
63         free( p_sql->psz_user );
64         free( p_sql->psz_pass );
65         vlc_object_release( p_sql );
66         msg_Err( p_this, "SQL provider not found" );
67         return NULL;
68     }
69
70     return p_sql;
71 }
72
73 #undef sql_Destroy
74 void sql_Destroy( vlc_object_t* obj )
75 {
76     sql_t *p_sql = (sql_t *)obj;
77     assert( p_sql );
78
79     free( p_sql->psz_host );
80     free( p_sql->psz_user );
81     free( p_sql->psz_pass );
82
83     module_unneed( p_sql, p_sql->p_module );
84
85     vlc_object_release( obj );
86 }