summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGravatar Matt Colyer2008-08-17 09:00:10 -0700
committerGravatar Matt Colyer2008-08-17 09:00:10 -0700
commit8e82524e5506b5af6bc75fa040e101c840121eec (patch)
tree6fa5841682d3baae3697753fed53b88112d1bfa1 /src
parent495dd184490e44411f53da36f5aa02f91a9fa3bf (diff)
downloadlibimobiledevice-8e82524e5506b5af6bc75fa040e101c840121eec.tar.gz
libimobiledevice-8e82524e5506b5af6bc75fa040e101c840121eec.tar.bz2
Enhance the usability of initconf, by giving more feedback to the user.
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am3
-rw-r--r--src/initconf.c79
2 files changed, 64 insertions, 18 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 09d232f..dc32c04 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -4,4 +4,7 @@ AM_LDFLAGS = $(libxml2_LIBS) $(libusb_LIBS) $(libglib2_LIBS) $(libfuse_LIBS) $(l
bin_PROGRAMS = iphoneclient ifuse libiphone-initconf
iphoneclient_SOURCES = usbmux.c main.c iphone.c plist.c lockdown.c AFC.c userpref.c
ifuse_SOURCES = ifuse.c usbmux.c iphone.c plist.c lockdown.c AFC.c userpref.c
+
libiphone_initconf_SOURCES = initconf.c userpref.c
+libiphone_initconf_CFLAGS = $(libgthread2_CFLAGS)
+libiphone_initconf_LDFLAGS = $(libgthread2_LIBS)
diff --git a/src/initconf.c b/src/initconf.c
index b4952e7..a8d56e4 100644
--- a/src/initconf.c
+++ b/src/initconf.c
@@ -21,6 +21,7 @@
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <gnutls/gnutls.h>
#include <gnutls/x509.h>
#include <glib.h>
@@ -51,21 +52,46 @@ char *lockdownd_generate_hostid() {
return hostid;
}
-int main(int argc, char *argv[]) {
-
- printf("This program generates keys required to connect with the iPhone\n");
- printf("It only needs to be run ONCE.\n\n");
- printf("Additionally it may take several minutes to run, please be patient.\n\n");
+void generate_key(gpointer key){
+ gnutls_x509_privkey_generate(*((gnutls_x509_privkey_t*)key), GNUTLS_PK_RSA, 2048, 0);
+ g_thread_exit(0);
+}
- gnutls_global_init();
+void progress_bar(gpointer mutex){
+ const char *spinner = "|/-\\|/-\\";
+ int i = 0;
+
+ while (!g_static_mutex_trylock((GStaticMutex*)mutex)){
+ usleep(500000);
+ printf("Generating root key... %c\r", spinner[i++]);
+ fflush(stdout);
+ if (i > 8) i = 0;
+ }
+ printf("Generating key... done\n");
+ g_thread_exit(0);
+}
+int main(int argc, char *argv[]) {
+ GThread *progress_thread, *key_thread;
+ GError *err;
+ static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
char* host_id = NULL;
gnutls_x509_privkey_t root_privkey;
gnutls_x509_privkey_t host_privkey;
-
gnutls_x509_crt_t root_cert;
gnutls_x509_crt_t host_cert;
+ // Create the thread
+ if (!g_thread_supported()){
+ g_thread_init(NULL);
+ }
+ gnutls_global_init();
+
+ printf("This program generates keys required to connect with the iPhone\n");
+ printf("It only needs to be run ONCE.\n\n");
+ printf("Additionally it may take several minutes to run, please be patient.\n\n");
+
+
gnutls_x509_privkey_init(&root_privkey);
gnutls_x509_privkey_init(&host_privkey);
@@ -73,19 +99,36 @@ int main(int argc, char *argv[]) {
gnutls_x509_crt_init(&host_cert);
/* generate HostID */
- //TODO
host_id = lockdownd_generate_hostid();
- /* generate keys */
- printf("Generating root key...");
- fflush(stdout);
- gnutls_x509_privkey_generate(root_privkey, GNUTLS_PK_RSA, 2048, 0);
- printf("done\n");
+ /* generate root key */
+ g_static_mutex_lock(&mutex);
+ if((key_thread = g_thread_create((GThreadFunc)generate_key, &root_privkey, TRUE, &err)) == NULL) {
+ printf("Thread create failed: %s!!\n", err->message );
+ g_error_free(err) ;
+ }
+ if((progress_thread = g_thread_create((GThreadFunc)progress_bar, &mutex, TRUE, &err)) == NULL) {
+ printf("Thread create failed: %s!!\n", err->message );
+ g_error_free(err) ;
+ }
+ g_thread_join(key_thread);
+ g_static_mutex_unlock(&mutex);
+ g_thread_join(progress_thread);
- printf("Generating private key...");
- fflush(stdout);
- gnutls_x509_privkey_generate(host_privkey, GNUTLS_PK_RSA, 2048, 0);
- printf("done\n");
+ /* generate host key */
+ g_static_mutex_init(&mutex);
+ g_static_mutex_lock(&mutex);
+ if((key_thread = g_thread_create((GThreadFunc)generate_key, &host_privkey, TRUE, &err)) == NULL) {
+ printf("Thread create failed: %s!!\n", err->message );
+ g_error_free(err) ;
+ }
+ if((progress_thread = g_thread_create((GThreadFunc)progress_bar, &mutex, TRUE, &err)) == NULL) {
+ printf("Thread create failed: %s!!\n", err->message );
+ g_error_free(err) ;
+ }
+ g_thread_join(key_thread);
+ g_static_mutex_unlock(&mutex);
+ g_thread_join(progress_thread);
/* generate certificates */
gnutls_x509_crt_set_key(root_cert, root_privkey);
@@ -133,7 +176,7 @@ int main(int argc, char *argv[]) {
gnutls_x509_crt_export (root_cert, GNUTLS_X509_FMT_PEM, root_cert_pem.data, &root_cert_pem.size);
printf("done\n");
- printf("Generating root certificate...");
+ printf("Generating host certificate...");
gnutls_x509_crt_export (host_cert, GNUTLS_X509_FMT_PEM, host_cert_pem.data, &host_cert_pem.size);
printf("done\n");