diff options
| author | 2008-08-05 23:25:35 -0700 | |
|---|---|---|
| committer | 2008-08-05 23:28:10 -0700 | |
| commit | 25e85bf5362b6f4c1878665c6037fdbfdc25c155 (patch) | |
| tree | 437979cdb4b9a7958a3d891d6a39a7be2bf61d17 /src/userpref.c | |
| parent | 4b558a53f61005b0ca49665d2da92303f6e14872 (diff) | |
| download | libimobiledevice-25e85bf5362b6f4c1878665c6037fdbfdc25c155.tar.gz libimobiledevice-25e85bf5362b6f4c1878665c6037fdbfdc25c155.tar.bz2 | |
Zack's final changes to the pairing.
Diffstat (limited to 'src/userpref.c')
| -rw-r--r-- | src/userpref.c | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/src/userpref.c b/src/userpref.c index 12ff8f3..1a9ebc9 100644 --- a/src/userpref.c +++ b/src/userpref.c | |||
| @@ -23,6 +23,8 @@ | |||
| 23 | #include <stdio.h> | 23 | #include <stdio.h> |
| 24 | #include <string.h> | 24 | #include <string.h> |
| 25 | #include "userpref.h" | 25 | #include "userpref.h" |
| 26 | #include <string.h> | ||
| 27 | #include <stdio.h> | ||
| 26 | 28 | ||
| 27 | 29 | ||
| 28 | #define LIBIPHONE_CONF_DIR "libiphone" | 30 | #define LIBIPHONE_CONF_DIR "libiphone" |
| @@ -87,7 +89,7 @@ int is_device_known(char* public_key) | |||
| 87 | g_io_channel_read_to_end (keyfile, &stored_key, NULL, NULL); | 89 | g_io_channel_read_to_end (keyfile, &stored_key, NULL, NULL); |
| 88 | 90 | ||
| 89 | /* now compare to input */ | 91 | /* now compare to input */ |
| 90 | if (strcmp(public_key, stored_key) == 2) | 92 | if (strcmp(public_key, stored_key) == 2 || !strcmp(public_key, stored_key)) |
| 91 | ret = 1; | 93 | ret = 1; |
| 92 | g_free(stored_key); | 94 | g_free(stored_key); |
| 93 | g_io_channel_shutdown(keyfile, FALSE, NULL); | 95 | g_io_channel_shutdown(keyfile, FALSE, NULL); |
| @@ -118,6 +120,7 @@ int store_device_public_key(char* public_key) | |||
| 118 | gchar** devices_list = g_key_file_get_string_list (key_file, "Global", "DevicesList", NULL, NULL); | 120 | gchar** devices_list = g_key_file_get_string_list (key_file, "Global", "DevicesList", NULL, NULL); |
| 119 | 121 | ||
| 120 | guint length = 0; | 122 | guint length = 0; |
| 123 | guint wlength = 0; | ||
| 121 | if (devices_list) | 124 | if (devices_list) |
| 122 | g_strv_length(devices_list); | 125 | g_strv_length(devices_list); |
| 123 | g_strfreev(devices_list); | 126 | g_strfreev(devices_list); |
| @@ -127,8 +130,9 @@ int store_device_public_key(char* public_key) | |||
| 127 | 130 | ||
| 128 | gchar* device_file = g_build_path(G_DIR_SEPARATOR_S, g_get_user_config_dir(), LIBIPHONE_CONF_DIR, dev_file, NULL); | 131 | gchar* device_file = g_build_path(G_DIR_SEPARATOR_S, g_get_user_config_dir(), LIBIPHONE_CONF_DIR, dev_file, NULL); |
| 129 | GIOChannel* file = g_io_channel_new_file (device_file, "w", NULL); | 132 | GIOChannel* file = g_io_channel_new_file (device_file, "w", NULL); |
| 130 | g_io_channel_write_chars (file, public_key, length, NULL, NULL); | 133 | wlength = strlen(public_key); // why this wasn't discovered before... ugh |
| 131 | g_io_channel_shutdown(file, FALSE, NULL); | 134 | g_io_channel_write_chars (file, public_key, wlength, NULL, NULL); |
| 135 | g_io_channel_shutdown(file, TRUE, NULL); | ||
| 132 | 136 | ||
| 133 | /* append device to list */ | 137 | /* append device to list */ |
| 134 | gchar** new_devices_list = (gchar**)g_malloc(sizeof(gchar*)* (length + 1)); | 138 | gchar** new_devices_list = (gchar**)g_malloc(sizeof(gchar*)* (length + 1)); |
| @@ -145,7 +149,7 @@ int store_device_public_key(char* public_key) | |||
| 145 | gchar* buf = g_key_file_to_data (key_file, &length,NULL); | 149 | gchar* buf = g_key_file_to_data (key_file, &length,NULL); |
| 146 | GIOChannel* file = g_io_channel_new_file (config_file, "w", NULL); | 150 | GIOChannel* file = g_io_channel_new_file (config_file, "w", NULL); |
| 147 | g_io_channel_write_chars (file, buf, length, NULL, NULL); | 151 | g_io_channel_write_chars (file, buf, length, NULL, NULL); |
| 148 | g_io_channel_shutdown(file, FALSE, NULL); | 152 | g_io_channel_shutdown(file, TRUE, NULL); |
| 149 | g_key_file_free(key_file); | 153 | g_key_file_free(key_file); |
| 150 | } | 154 | } |
| 151 | 155 | ||
| @@ -215,6 +219,7 @@ int init_config_file(char* host_id, gnutls_datum_t* root_key, gnutls_datum_t* ho | |||
| 215 | GKeyFile* key_file = g_key_file_new (); | 219 | GKeyFile* key_file = g_key_file_new (); |
| 216 | 220 | ||
| 217 | /* store in config file */ | 221 | /* store in config file */ |
| 222 | if (debug) printf("init_config_file setting hostID to %s\n", host_id); | ||
| 218 | g_key_file_set_value (key_file, "Global", "HostID", host_id); | 223 | g_key_file_set_value (key_file, "Global", "HostID", host_id); |
| 219 | 224 | ||
| 220 | /* write config file on disk */ | 225 | /* write config file on disk */ |
| @@ -222,7 +227,7 @@ int init_config_file(char* host_id, gnutls_datum_t* root_key, gnutls_datum_t* ho | |||
| 222 | gchar* buf = g_key_file_to_data (key_file, &length,NULL); | 227 | gchar* buf = g_key_file_to_data (key_file, &length,NULL); |
| 223 | GIOChannel* file = g_io_channel_new_file (config_file, "w", NULL); | 228 | GIOChannel* file = g_io_channel_new_file (config_file, "w", NULL); |
| 224 | g_io_channel_write_chars (file, buf, length, NULL, NULL); | 229 | g_io_channel_write_chars (file, buf, length, NULL, NULL); |
| 225 | g_io_channel_shutdown(file, FALSE, NULL); | 230 | g_io_channel_shutdown(file, TRUE, NULL); |
| 226 | 231 | ||
| 227 | g_key_file_free(key_file); | 232 | g_key_file_free(key_file); |
| 228 | 233 | ||
