melunko@117
|
1 |
|
melunko@117
|
2 |
/**
|
melunko@117
|
3 |
* GMyth Library
|
melunko@117
|
4 |
*
|
melunko@117
|
5 |
* @file gmyth/gmyth_backend_info.c
|
melunko@117
|
6 |
*
|
melunko@117
|
7 |
* Copyright (C) 2006 INdT - Instituto Nokia de Tecnologia.
|
melunko@117
|
8 |
* @author Hallyson Melo <hallyson.melo@indt.org.br>
|
melunko@117
|
9 |
*
|
melunko@117
|
10 |
*//*
|
melunko@117
|
11 |
*
|
melunko@117
|
12 |
* This program is free software; you can redistribute it and/or modify
|
melunko@117
|
13 |
* it under the terms of the GNU Lesser General Public License as published by
|
melunko@117
|
14 |
* the Free Software Foundation; either version 2 of the License, or
|
melunko@117
|
15 |
* (at your option) any later version.
|
melunko@117
|
16 |
*
|
melunko@117
|
17 |
* This program is distributed in the hope that it will be useful,
|
melunko@117
|
18 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
melunko@117
|
19 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
melunko@117
|
20 |
* GNU General Public License for more details.
|
melunko@117
|
21 |
*
|
melunko@117
|
22 |
* You should have received a copy of the GNU Lesser General Public License
|
melunko@117
|
23 |
* along with this program; if not, write to the Free Software
|
melunko@117
|
24 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
melunko@117
|
25 |
*/
|
leo_sobral@213
|
26 |
|
leo_sobral@213
|
27 |
#ifdef HAVE_CONFIG_H
|
leo_sobral@213
|
28 |
#include "config.h"
|
leo_sobral@213
|
29 |
#endif
|
melunko@117
|
30 |
|
melunko@117
|
31 |
#include "gmyth_backendinfo.h"
|
rosfran@119
|
32 |
#include "gmyth_uri.h"
|
renatofilho@131
|
33 |
#include "gmyth_debug.h"
|
melunko@117
|
34 |
|
melunko@117
|
35 |
static void gmyth_backend_info_class_init (GMythBackendInfoClass *klass);
|
melunko@117
|
36 |
static void gmyth_backend_info_init (GMythBackendInfo *object);
|
melunko@117
|
37 |
|
melunko@117
|
38 |
static void gmyth_backend_info_dispose (GObject *object);
|
melunko@117
|
39 |
static void gmyth_backend_info_finalize (GObject *object);
|
melunko@117
|
40 |
|
melunko@117
|
41 |
G_DEFINE_TYPE(GMythBackendInfo, gmyth_backend_info, G_TYPE_OBJECT)
|
melunko@117
|
42 |
|
melunko@117
|
43 |
static void
|
melunko@117
|
44 |
gmyth_backend_info_class_init (GMythBackendInfoClass *klass)
|
melunko@117
|
45 |
{
|
melunko@117
|
46 |
GObjectClass *gobject_class;
|
melunko@117
|
47 |
|
melunko@117
|
48 |
gobject_class = (GObjectClass *) klass;
|
melunko@117
|
49 |
|
melunko@117
|
50 |
gobject_class->dispose = gmyth_backend_info_dispose;
|
melunko@117
|
51 |
gobject_class->finalize = gmyth_backend_info_finalize;
|
melunko@117
|
52 |
}
|
melunko@117
|
53 |
|
melunko@117
|
54 |
static void
|
melunko@117
|
55 |
gmyth_backend_info_init (GMythBackendInfo *backend_info)
|
melunko@117
|
56 |
{
|
melunko@117
|
57 |
backend_info->hostname = NULL;
|
melunko@117
|
58 |
backend_info->username = NULL;
|
rosfran@178
|
59 |
backend_info->password = NULL;
|
melunko@117
|
60 |
backend_info->db_name = NULL;
|
melunko@117
|
61 |
backend_info->port = -1;
|
melunko@117
|
62 |
}
|
melunko@117
|
63 |
|
melunko@117
|
64 |
static void
|
melunko@117
|
65 |
gmyth_backend_info_dispose (GObject *object)
|
melunko@117
|
66 |
{
|
melunko@117
|
67 |
GMythBackendInfo *backend_info = GMYTH_BACKEND_INFO (object);
|
melunko@117
|
68 |
|
melunko@117
|
69 |
g_free (backend_info->hostname);
|
melunko@117
|
70 |
g_free (backend_info->username);
|
melunko@117
|
71 |
g_free (backend_info->password);
|
melunko@117
|
72 |
g_free (backend_info->db_name);
|
melunko@117
|
73 |
|
melunko@117
|
74 |
backend_info->hostname = NULL;
|
melunko@117
|
75 |
backend_info->username = NULL;
|
melunko@117
|
76 |
backend_info->password = NULL;
|
melunko@117
|
77 |
backend_info->db_name = NULL;
|
melunko@117
|
78 |
backend_info->port = -1;
|
melunko@117
|
79 |
|
melunko@117
|
80 |
G_OBJECT_CLASS (gmyth_backend_info_parent_class)->dispose (object);
|
melunko@117
|
81 |
}
|
melunko@117
|
82 |
|
melunko@117
|
83 |
static void
|
melunko@117
|
84 |
gmyth_backend_info_finalize (GObject *object)
|
melunko@117
|
85 |
{
|
melunko@117
|
86 |
g_signal_handlers_destroy (object);
|
melunko@117
|
87 |
|
melunko@117
|
88 |
G_OBJECT_CLASS (gmyth_backend_info_parent_class)->finalize (object);
|
melunko@117
|
89 |
}
|
melunko@117
|
90 |
|
melunko@117
|
91 |
/** Creates a new instance of GMythBackendInfo.
|
melunko@117
|
92 |
*
|
melunko@117
|
93 |
* @return a new instance of GMythBackendInfo.
|
melunko@117
|
94 |
*/
|
melunko@117
|
95 |
GMythBackendInfo*
|
melunko@117
|
96 |
gmyth_backend_info_new ()
|
melunko@117
|
97 |
{
|
melunko@117
|
98 |
GMythBackendInfo *backend_info =
|
melunko@117
|
99 |
GMYTH_BACKEND_INFO (g_object_new(GMYTH_BACKEND_INFO_TYPE, NULL));
|
melunko@117
|
100 |
|
melunko@117
|
101 |
return backend_info;
|
melunko@117
|
102 |
}
|
melunko@117
|
103 |
|
melunko@117
|
104 |
GMythBackendInfo*
|
rosfran@178
|
105 |
gmyth_backend_info_new_full (const gchar *hostname, const gchar *username,
|
rosfran@178
|
106 |
const gchar *password, const gchar *db_name, gint port)
|
melunko@117
|
107 |
{
|
melunko@117
|
108 |
GMythBackendInfo *backend_info =
|
melunko@117
|
109 |
GMYTH_BACKEND_INFO (g_object_new(GMYTH_BACKEND_INFO_TYPE, NULL));
|
rosfran@242
|
110 |
|
melunko@117
|
111 |
gmyth_backend_info_set_hostname (backend_info, hostname);
|
melunko@117
|
112 |
gmyth_backend_info_set_username (backend_info, username);
|
melunko@117
|
113 |
gmyth_backend_info_set_password (backend_info, password);
|
melunko@117
|
114 |
gmyth_backend_info_set_db_name (backend_info, db_name);
|
melunko@117
|
115 |
gmyth_backend_info_set_port (backend_info, port);
|
melunko@117
|
116 |
|
melunko@117
|
117 |
return backend_info;
|
melunko@117
|
118 |
}
|
melunko@117
|
119 |
|
rosfran@119
|
120 |
GMythBackendInfo*
|
rosfran@123
|
121 |
gmyth_backend_info_new_with_uri ( const gchar *uri_str )
|
rosfran@119
|
122 |
{
|
rosfran@119
|
123 |
GMythBackendInfo *backend_info =
|
rosfran@119
|
124 |
GMYTH_BACKEND_INFO (g_object_new(GMYTH_BACKEND_INFO_TYPE, NULL));
|
rosfran@119
|
125 |
|
rosfran@140
|
126 |
GMythURI* uri = gmyth_uri_new_with_value( uri_str );
|
rosfran@119
|
127 |
|
rosfran@119
|
128 |
gmyth_backend_info_set_hostname (backend_info, gmyth_uri_get_host (uri ) );
|
rosfran@119
|
129 |
gmyth_backend_info_set_username (backend_info, gmyth_uri_get_user( uri ) );
|
rosfran@119
|
130 |
gmyth_backend_info_set_password (backend_info, gmyth_uri_get_password( uri ) );
|
rosfran@123
|
131 |
gmyth_backend_info_set_db_name (backend_info, strlen( gmyth_uri_get_fragment( uri ) ) > 0
|
rosfran@123
|
132 |
? gmyth_uri_get_fragment( uri ) : gmyth_uri_get_query( uri ) );
|
rosfran@119
|
133 |
gmyth_backend_info_set_port (backend_info, gmyth_uri_get_port( uri ) );
|
rosfran@178
|
134 |
|
rosfran@119
|
135 |
return backend_info;
|
rosfran@119
|
136 |
}
|
rosfran@119
|
137 |
|
melunko@117
|
138 |
void
|
rosfran@178
|
139 |
gmyth_backend_info_set_hostname (GMythBackendInfo *backend_info, const gchar *hostname)
|
melunko@117
|
140 |
{
|
melunko@117
|
141 |
g_return_if_fail (backend_info != NULL);
|
rosfran@242
|
142 |
|
rosfran@242
|
143 |
if ( NULL == hostname || strlen(hostname) <= 0 )
|
rosfran@242
|
144 |
{
|
melunko@248
|
145 |
gmyth_debug ( "Error trying to set a hostname equals to NULL (it doesn't using UPnP)." );
|
rosfran@242
|
146 |
} else {
|
rosfran@242
|
147 |
backend_info->hostname = g_strdup (hostname);
|
rosfran@242
|
148 |
}
|
melunko@117
|
149 |
}
|
melunko@117
|
150 |
|
melunko@117
|
151 |
void
|
rosfran@178
|
152 |
gmyth_backend_info_set_username (GMythBackendInfo *backend_info, const gchar *username)
|
melunko@117
|
153 |
{
|
melunko@117
|
154 |
g_return_if_fail (backend_info != NULL);
|
melunko@117
|
155 |
|
melunko@117
|
156 |
backend_info->username = g_strdup (username);
|
melunko@117
|
157 |
}
|
melunko@117
|
158 |
|
melunko@117
|
159 |
void
|
rosfran@178
|
160 |
gmyth_backend_info_set_password (GMythBackendInfo *backend_info, const gchar *password)
|
melunko@117
|
161 |
{
|
melunko@117
|
162 |
g_return_if_fail (backend_info != NULL);
|
melunko@117
|
163 |
|
melunko@117
|
164 |
backend_info->password = g_strdup (password);
|
melunko@117
|
165 |
}
|
melunko@117
|
166 |
|
melunko@117
|
167 |
void
|
rosfran@178
|
168 |
gmyth_backend_info_set_db_name (GMythBackendInfo *backend_info, const gchar *db_name)
|
melunko@117
|
169 |
{
|
melunko@117
|
170 |
g_return_if_fail (backend_info != NULL);
|
melunko@117
|
171 |
|
melunko@117
|
172 |
backend_info->db_name = g_strdup (db_name);
|
melunko@117
|
173 |
}
|
melunko@117
|
174 |
|
rosfran@119
|
175 |
void
|
rosfran@119
|
176 |
gmyth_backend_info_set_port (GMythBackendInfo *backend_info, const gint port )
|
rosfran@119
|
177 |
{
|
rosfran@119
|
178 |
g_return_if_fail (backend_info != NULL);
|
rosfran@119
|
179 |
|
rosfran@242
|
180 |
if ( port <= 0 )
|
rosfran@242
|
181 |
{
|
melunko@248
|
182 |
gmyth_debug ( "Error trying to set a hostname equals to NULL (it doesn't using UPnP)." );
|
rosfran@242
|
183 |
} else {
|
rosfran@242
|
184 |
backend_info->port = port;
|
rosfran@242
|
185 |
}
|
rosfran@119
|
186 |
}
|
rosfran@119
|
187 |
|
renatofilho@189
|
188 |
const gchar*
|
melunko@117
|
189 |
gmyth_backend_info_get_hostname (GMythBackendInfo *backend_info)
|
melunko@117
|
190 |
{
|
melunko@117
|
191 |
g_return_val_if_fail (backend_info != NULL, NULL);
|
melunko@117
|
192 |
|
melunko@117
|
193 |
return backend_info->hostname;
|
melunko@117
|
194 |
}
|
melunko@117
|
195 |
|
renatofilho@189
|
196 |
const gchar*
|
melunko@117
|
197 |
gmyth_backend_info_get_username (GMythBackendInfo *backend_info)
|
melunko@117
|
198 |
{
|
melunko@117
|
199 |
g_return_val_if_fail (backend_info != NULL, NULL);
|
melunko@117
|
200 |
|
melunko@117
|
201 |
return backend_info->username;
|
melunko@117
|
202 |
}
|
melunko@117
|
203 |
|
renatofilho@189
|
204 |
const gchar*
|
melunko@117
|
205 |
gmyth_backend_info_get_password (GMythBackendInfo *backend_info)
|
melunko@117
|
206 |
{
|
melunko@117
|
207 |
g_return_val_if_fail (backend_info != NULL, NULL);
|
melunko@117
|
208 |
|
melunko@117
|
209 |
return backend_info->password;
|
melunko@117
|
210 |
}
|
melunko@117
|
211 |
|
renatofilho@189
|
212 |
const gchar*
|
melunko@117
|
213 |
gmyth_backend_info_get_db_name (GMythBackendInfo *backend_info)
|
melunko@117
|
214 |
{
|
melunko@117
|
215 |
g_return_val_if_fail (backend_info != NULL, NULL);
|
melunko@117
|
216 |
|
melunko@117
|
217 |
return backend_info->db_name;
|
melunko@117
|
218 |
}
|
melunko@117
|
219 |
|
melunko@117
|
220 |
gint
|
melunko@117
|
221 |
gmyth_backend_info_get_port (GMythBackendInfo *backend_info)
|
melunko@117
|
222 |
{
|
melunko@117
|
223 |
g_return_val_if_fail (backend_info != NULL, -1);
|
melunko@117
|
224 |
|
melunko@117
|
225 |
return backend_info->port;
|
melunko@117
|
226 |
}
|
rosfran@178
|
227 |
|