/
usb_moded-config.c
148 lines (123 loc) · 3.55 KB
/
usb_moded-config.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/**
@file usb_moded-config.c
Copyright (C) 2010 Nokia Corporation. All rights reserved.
@author: Philippe De Swert <philippe.de-swert@nokia.com>
This program is free software; you can redistribute it and/or
modify it under the terms of the Lesser GNU General Public License
version 2 as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the Lesser GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <glib.h>
#include <glib/gkeyfile.h>
#include "usb_moded-config.h"
#include "usb_moded-log.h"
static int get_conf_int(const gchar *entry, const gchar *key);
static const char * get_conf_string(const gchar *entry, const gchar *key);
const char *find_mounts(void)
{
const char *ret = NULL;
ret = get_conf_string(FS_MOUNT_ENTRY, FS_MOUNT_KEY);
if(ret == NULL)
{
ret = g_strdup(FS_MOUNT_DEFAULT);
log_debug("Default mount = %s\n", ret);
}
return(ret);
}
int find_sync(void)
{
return(get_conf_int(FS_SYNC_ENTRY, FS_SYNC_KEY));
}
const char * find_alt_mount(void)
{
return(get_conf_string(ALT_MOUNT_ENTRY, ALT_MOUNT_KEY));
}
#ifdef UDEV
const char * find_udev_path(void)
{
return(get_conf_string(UDEV_PATH_ENTRY, UDEV_PATH_KEY));
}
#endif /* UDEV */
#ifdef NOKIA
const char * find_cdrom_path(void)
{
return(get_conf_string(CDROM_ENTRY, CDROM_PATH_KEY));
}
int find_cdrom_timeout(void)
{
return(get_conf_int(CDROM_ENTRY, CDROM_TIMEOUT_KEY));
}
#endif /* NOKIA */
static int get_conf_int(const gchar *entry, const gchar *key)
{
GKeyFile *settingsfile;
gboolean test = FALSE;
gchar **keys;
int ret = 0;
settingsfile = g_key_file_new();
test = g_key_file_load_from_file(settingsfile, FS_MOUNT_CONFIG_FILE, G_KEY_FILE_NONE, NULL);
if(!test)
{
log_debug("no conffile\n");
g_key_file_free(settingsfile);
return(ret);
}
keys = g_key_file_get_keys (settingsfile, entry, NULL, NULL);
if(keys == NULL)
return ret;
while (*keys != NULL)
{
if(!strcmp(*keys, key))
{
ret = g_key_file_get_integer(settingsfile, entry, *keys, NULL);
log_debug("%s key value = %d\n", key, ret);
}
keys++;
}
g_key_file_free(settingsfile);
return(ret);
}
static const char * get_conf_string(const gchar *entry, const gchar *key)
{
GKeyFile *settingsfile;
gboolean test = FALSE;
gchar **keys;
const char *ret = NULL, *tmp_char;
settingsfile = g_key_file_new();
test = g_key_file_load_from_file(settingsfile, FS_MOUNT_CONFIG_FILE, G_KEY_FILE_NONE, NULL);
if(!test)
{
log_debug("No conffile.\n");
g_key_file_free(settingsfile);
return(ret);
}
keys = g_key_file_get_keys (settingsfile, entry, NULL, NULL);
if(keys == NULL)
return ret;
while (*keys != NULL)
{
if(!strcmp(*keys, key))
{
tmp_char = g_key_file_get_string(settingsfile, entry, *keys, NULL);
if(tmp_char)
{
log_debug("key %s value = %s\n", key, tmp_char);
ret = g_strdup(tmp_char);
}
}
keys++;
}
g_key_file_free(settingsfile);
return(ret);
}