diff options
author | Matt Colyer | 2008-08-17 09:00:10 -0700 |
---|---|---|
committer | Matt Colyer | 2008-08-17 09:00:10 -0700 |
commit | 8e82524e5506b5af6bc75fa040e101c840121eec (patch) | |
tree | 6fa5841682d3baae3697753fed53b88112d1bfa1 /src/initconf.c | |
parent | 495dd184490e44411f53da36f5aa02f91a9fa3bf (diff) | |
download | libplist-8e82524e5506b5af6bc75fa040e101c840121eec.tar.gz libplist-8e82524e5506b5af6bc75fa040e101c840121eec.tar.bz2 |
Enhance the usability of initconf, by giving more feedback to the user.
Diffstat (limited to 'src/initconf.c')
-rw-r--r-- | src/initconf.c | 79 |
1 files changed, 61 insertions, 18 deletions
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"); |