1 /* -*- Mode: C ; c-basic-offset: 2 -*- */
2 /*****************************************************************************
4 * $Id: conf.c,v 1.2 2004/05/21 23:42:49 nedko Exp $
7 * Mediadatabase configuration file handling.
10 * Nedko Arnaudov <nedko@users.sourceforge.net>
13 * GNU GENERAL PUBLIC LICENSE version 2
15 *****************************************************************************/
21 #include "../result.h"
27 #define CONF_FILE ".mediadatabase"
28 #define CFL_SECTION_GLOBAL NULL
29 #define CFL_SECTION_CUI "cui"
30 #define CFL_SECTION_MYSQL "MySQL"
31 #define CFL_SECTION_SQLITE "SQLite"
32 #define CFL_VALUE_MYSQL_HOST "host"
33 #define CFL_VALUE_MYSQL_USER "user"
34 #define CFL_VALUE_MYSQL_PASS "pass"
35 #define CFL_VALUE_MYSQL_DB "db"
36 #define CFL_VALUE_MOUNT "mount"
37 #define CFL_VALUE_UNMOUNT "unmount"
38 #define CFL_VALUE_MOUNTDIR "mountdir"
39 #define CFL_VALUE_SQLITE_DB "dbfile"
40 #define CFL_VALUE_BACKEND "backend"
53 cfl_value_type_t CFLValueType
;
55 pszHOME
= getenv("HOME");
62 mediadb_error_callback(
63 MEDIADB_ERROR_CRITICAL
,
64 "HOME environment variable not set.");
69 s
= strlen(pszHOME
) + 1 + strlen(CONF_FILE
) + 1;
71 pszConf
= (char *)malloc(s
);
74 mediadb_error_callback(
75 MEDIADB_ERROR_CRITICAL
,
81 sprintf(pszConf
, "%s/%s", pszHOME
, CONF_FILE
);
83 hFile
= fopen(pszConf
, "r");
87 MEDIADB_ERROR_CRITICAL
,
88 "Cannot open configuration file \"%s\".",
97 mediadb_error_callback(
98 MEDIADB_ERROR_CRITICAL
,
104 nRet
= cfl_init_from_file(
107 CFL_FILE_TYPE_DEFAULT
);
110 mediadb_error_printf(
111 MEDIADB_ERROR_CRITICAL
,
112 "cfl_init_from_file() failed. (%s)",
113 cfl_errcode_to_message(nRet
));
117 pszCFLValue
= cfl_value_get_by_name(
123 if (pszCFLValue
!= NULL
&&
124 CFLValueType
== CFL_TYPE_STRING
)
126 r
= disk_set_mount_command(pszCFLValue
);
127 if (MEDIADB_IS_ERROR(r
))
133 pszCFLValue
= cfl_value_get_by_name(
139 if (pszCFLValue
!= NULL
&&
140 CFLValueType
== CFL_TYPE_STRING
)
142 r
= disk_set_unmount_command(pszCFLValue
);
143 if (MEDIADB_IS_ERROR(r
))
149 pszCFLValue
= cfl_value_get_by_name(
155 if (pszCFLValue
!= NULL
&&
156 CFLValueType
== CFL_TYPE_STRING
)
158 r
= disk_set_path(pszCFLValue
);
159 if (MEDIADB_IS_ERROR(r
))
165 pszCFLValue
= cfl_value_get_by_name(
168 CFL_VALUE_MYSQL_HOST
,
171 if (pszCFLValue
!= NULL
&&
172 CFLValueType
== CFL_TYPE_STRING
)
174 r
= db_set_mysql_host(pszCFLValue
);
175 if (MEDIADB_IS_ERROR(r
))
181 pszCFLValue
= cfl_value_get_by_name(
187 if (pszCFLValue
!= NULL
&&
188 CFLValueType
== CFL_TYPE_STRING
)
190 r
= db_set_mysql_database(pszCFLValue
);
191 if (MEDIADB_IS_ERROR(r
))
197 pszCFLValue
= cfl_value_get_by_name(
200 CFL_VALUE_MYSQL_USER
,
203 if (pszCFLValue
!= NULL
&&
204 CFLValueType
== CFL_TYPE_STRING
)
206 r
= db_set_mysql_user(pszCFLValue
);
207 if (MEDIADB_IS_ERROR(r
))
213 pszCFLValue
= cfl_value_get_by_name(
216 CFL_VALUE_MYSQL_PASS
,
219 if (pszCFLValue
!= NULL
&&
220 CFLValueType
== CFL_TYPE_STRING
)
222 r
= db_set_mysql_pass(pszCFLValue
);
223 if (MEDIADB_IS_ERROR(r
))
229 pszCFLValue
= cfl_value_get_by_name(
235 if (pszCFLValue
!= NULL
&&
236 CFLValueType
== CFL_TYPE_STRING
)
238 r
= db_set_sqlite_database(pszCFLValue
);
239 if (MEDIADB_IS_ERROR(r
))
245 pszCFLValue
= cfl_value_get_by_name(
251 if (pszCFLValue
!= NULL
&&
252 CFLValueType
== CFL_TYPE_STRING
)
254 if (strcmp(pszCFLValue
, CFL_SECTION_SQLITE
) == 0)
258 else if (strcmp(pszCFLValue
, CFL_SECTION_MYSQL
) == 0)
285 /*****************************************************************************
289 * !!! WARNING !!! Following lines are automatically updated by the CVS system.
292 * Revision 1.2 2004/05/21 23:42:49 nedko
293 * mediadb_error_callback() now tells if error is critical.
295 * Revision 1.1 2004/05/16 19:01:17 nedko
296 * libfrontend holds code common to frontends but not in libdb.
298 *****************************************************************************/