diff options
| author | 2008-07-31 21:54:16 -0700 | |
|---|---|---|
| committer | 2008-07-31 21:54:16 -0700 | |
| commit | d05ae226356cc674a055c784a4b9b75825162ba6 (patch) | |
| tree | 9cfff8c5e5f90c4d5b0d7e36a2b1ac5b78a4baf9 /src/userpref.c | |
| parent | bbd289b44c94aeb327675352d187209639e64baa (diff) | |
| download | libimobiledevice-d05ae226356cc674a055c784a4b9b75825162ba6.tar.gz libimobiledevice-d05ae226356cc674a055c784a4b9b75825162ba6.tar.bz2 | |
Added a way to load HostID from a user specific config file.
Signed-off-by: Matt Colyer <matt@colyer.name>
Diffstat (limited to 'src/userpref.c')
| -rw-r--r-- | src/userpref.c | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/userpref.c b/src/userpref.c new file mode 100644 index 0000000..b877700 --- /dev/null +++ b/src/userpref.c | |||
| @@ -0,0 +1,52 @@ | |||
| 1 | /* | ||
| 2 | * userpref.c | ||
| 3 | * contains methods to access user specific certificates IDs and more. | ||
| 4 | * | ||
| 5 | * Copyright (c) 2008 Jonathan Beck All Rights Reserved. | ||
| 6 | * | ||
| 7 | * This program is free software: you can redistribute it and/or modify | ||
| 8 | * it under the terms of the GNU General Public License as published by | ||
| 9 | * the Free Software Foundation, either version 3 of the License, or | ||
| 10 | * (at your option) any later version. | ||
| 11 | * | ||
| 12 | * This program is distributed in the hope that it will be useful, | ||
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 15 | * GNU General Public License for more details. | ||
| 16 | * | ||
| 17 | * You should have received a copy of the GNU General Public License | ||
| 18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 19 | */ | ||
| 20 | |||
| 21 | #include <glib.h> | ||
| 22 | #include "userpref.h" | ||
| 23 | |||
| 24 | #define LIBIPHONE_CONF_DIR "libiphone" | ||
| 25 | #define LIBIPHONE_CONF_FILE "libiphonerc" | ||
| 26 | |||
| 27 | extern int debug; | ||
| 28 | |||
| 29 | char* get_host_id() | ||
| 30 | { | ||
| 31 | char* host_id = NULL; | ||
| 32 | gchar* config_file = NULL; | ||
| 33 | |||
| 34 | /* first get config file */ | ||
| 35 | config_file = g_build_path(G_DIR_SEPARATOR_S, g_get_user_config_dir(), LIBIPHONE_CONF_DIR, LIBIPHONE_CONF_FILE, NULL); | ||
| 36 | if (g_file_test(config_file, (G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR))) { | ||
| 37 | |||
| 38 | /*now parse file to get the HostID*/ | ||
| 39 | GKeyFile* key_file = g_key_file_new (); | ||
| 40 | if( g_key_file_load_from_file (key_file, config_file, G_KEY_FILE_KEEP_COMMENTS, NULL) ) { | ||
| 41 | |||
| 42 | gchar* loc_host_id = g_key_file_get_value(key_file, "Global", "HostID", NULL); | ||
| 43 | if (loc_host_id) | ||
| 44 | host_id = strdup(loc_host_id); | ||
| 45 | g_free(loc_host_id); | ||
| 46 | } | ||
| 47 | g_key_file_free(key_file); | ||
| 48 | } | ||
| 49 | if (debug) printf("Using %s as HostID\n",host_id); | ||
| 50 | return host_id; | ||
| 51 | } | ||
| 52 | |||
