summaryrefslogtreecommitdiffstats
path: root/src/initconf.c
diff options
context:
space:
mode:
authorGravatar Matt Colyer2008-09-01 15:04:31 -0700
committerGravatar Matt Colyer2008-09-01 15:04:31 -0700
commit2b05e48cb4a90dfc94ff584124f08e431398bb1a (patch)
treee0c8255e2cd5592a31295ac8ce89d8846feb7043 /src/initconf.c
parent7ac3d681889a6a8f9987837ace5465f2967cfff9 (diff)
downloadlibimobiledevice-2b05e48cb4a90dfc94ff584124f08e431398bb1a.tar.gz
libimobiledevice-2b05e48cb4a90dfc94ff584124f08e431398bb1a.tar.bz2
Enforce a modified kr style.
Use "make indent" from now on before committing.
Diffstat (limited to 'src/initconf.c')
-rw-r--r--src/initconf.c72
1 files changed, 38 insertions, 34 deletions
diff --git a/src/initconf.c b/src/initconf.c
index b900f7f..412dd70 100644
--- a/src/initconf.c
+++ b/src/initconf.c
@@ -36,38 +36,43 @@ int debug = 1;
36 * 36 *
37 * @param key The pointer to the desired location of the new key. 37 * @param key The pointer to the desired location of the new key.
38 */ 38 */
39void generate_key(gpointer key){ 39void generate_key(gpointer key)
40 gnutls_x509_privkey_generate(*((gnutls_x509_privkey_t*)key), GNUTLS_PK_RSA, 2048, 0); 40{
41 gnutls_x509_privkey_generate(*((gnutls_x509_privkey_t *) key), GNUTLS_PK_RSA, 2048, 0);
41 g_thread_exit(0); 42 g_thread_exit(0);
42} 43}
44
43/** Simple function that generates a spinner until the mutex is released. 45/** Simple function that generates a spinner until the mutex is released.
44 */ 46 */
45void progress_bar(gpointer mutex){ 47void progress_bar(gpointer mutex)
48{
46 const char *spinner = "|/-\\|/-\\"; 49 const char *spinner = "|/-\\|/-\\";
47 int i = 0; 50 int i = 0;
48 51
49 while (!g_static_mutex_trylock((GStaticMutex*)mutex)){ 52 while (!g_static_mutex_trylock((GStaticMutex *) mutex)) {
50 usleep(500000); 53 usleep(500000);
51 printf("Generating key... %c\r", spinner[i++]); 54 printf("Generating key... %c\r", spinner[i++]);
52 fflush(stdout); 55 fflush(stdout);
53 if (i > 8) i = 0; 56 if (i > 8)
57 i = 0;
54 } 58 }
55 printf("Generating key... done\n"); 59 printf("Generating key... done\n");
56 g_thread_exit(0); 60 g_thread_exit(0);
57} 61}
58 62
59int main(int argc, char *argv[]) { 63int main(int argc, char *argv[])
64{
60 GThread *progress_thread, *key_thread; 65 GThread *progress_thread, *key_thread;
61 GError *err; 66 GError *err;
62 static GStaticMutex mutex = G_STATIC_MUTEX_INIT; 67 static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
63 char* host_id = NULL; 68 char *host_id = NULL;
64 gnutls_x509_privkey_t root_privkey; 69 gnutls_x509_privkey_t root_privkey;
65 gnutls_x509_privkey_t host_privkey; 70 gnutls_x509_privkey_t host_privkey;
66 gnutls_x509_crt_t root_cert; 71 gnutls_x509_crt_t root_cert;
67 gnutls_x509_crt_t host_cert; 72 gnutls_x509_crt_t host_cert;
68 73
69 // Create the thread 74 // Create the thread
70 if (!g_thread_supported()){ 75 if (!g_thread_supported()) {
71 g_thread_init(NULL); 76 g_thread_init(NULL);
72 } 77 }
73 gnutls_global_init(); 78 gnutls_global_init();
@@ -88,28 +93,28 @@ int main(int argc, char *argv[]) {
88 93
89 /* generate root key */ 94 /* generate root key */
90 g_static_mutex_lock(&mutex); 95 g_static_mutex_lock(&mutex);
91 if((key_thread = g_thread_create((GThreadFunc)generate_key, &root_privkey, TRUE, &err)) == NULL) { 96 if ((key_thread = g_thread_create((GThreadFunc) generate_key, &root_privkey, TRUE, &err)) == NULL) {
92 printf("Thread create failed: %s!!\n", err->message ); 97 printf("Thread create failed: %s!!\n", err->message);
93 g_error_free(err) ; 98 g_error_free(err);
94 } 99 }
95 if((progress_thread = g_thread_create((GThreadFunc)progress_bar, &mutex, TRUE, &err)) == NULL) { 100 if ((progress_thread = g_thread_create((GThreadFunc) progress_bar, &mutex, TRUE, &err)) == NULL) {
96 printf("Thread create failed: %s!!\n", err->message ); 101 printf("Thread create failed: %s!!\n", err->message);
97 g_error_free(err) ; 102 g_error_free(err);
98 } 103 }
99 g_thread_join(key_thread); 104 g_thread_join(key_thread);
100 g_static_mutex_unlock(&mutex); 105 g_static_mutex_unlock(&mutex);
101 g_thread_join(progress_thread); 106 g_thread_join(progress_thread);
102 107
103 /* generate host key */ 108 /* generate host key */
104 g_static_mutex_init(&mutex); 109 g_static_mutex_init(&mutex);
105 g_static_mutex_lock(&mutex); 110 g_static_mutex_lock(&mutex);
106 if((key_thread = g_thread_create((GThreadFunc)generate_key, &host_privkey, TRUE, &err)) == NULL) { 111 if ((key_thread = g_thread_create((GThreadFunc) generate_key, &host_privkey, TRUE, &err)) == NULL) {
107 printf("Thread create failed: %s!!\n", err->message ); 112 printf("Thread create failed: %s!!\n", err->message);
108 g_error_free(err) ; 113 g_error_free(err);
109 } 114 }
110 if((progress_thread = g_thread_create((GThreadFunc)progress_bar, &mutex, TRUE, &err)) == NULL) { 115 if ((progress_thread = g_thread_create((GThreadFunc) progress_bar, &mutex, TRUE, &err)) == NULL) {
111 printf("Thread create failed: %s!!\n", err->message ); 116 printf("Thread create failed: %s!!\n", err->message);
112 g_error_free(err) ; 117 g_error_free(err);
113 } 118 }
114 g_thread_join(key_thread); 119 g_thread_join(key_thread);
115 g_static_mutex_unlock(&mutex); 120 g_static_mutex_unlock(&mutex);
@@ -136,33 +141,33 @@ int main(int argc, char *argv[]) {
136 141
137 142
138 /* export to PEM format */ 143 /* export to PEM format */
139 gnutls_datum_t root_key_pem = {NULL, 0}; 144 gnutls_datum_t root_key_pem = { NULL, 0 };
140 gnutls_datum_t host_key_pem = {NULL, 0}; 145 gnutls_datum_t host_key_pem = { NULL, 0 };
141 146
142 gnutls_x509_privkey_export (root_privkey, GNUTLS_X509_FMT_PEM, NULL, &root_key_pem.size); 147 gnutls_x509_privkey_export(root_privkey, GNUTLS_X509_FMT_PEM, NULL, &root_key_pem.size);
143 gnutls_x509_privkey_export (host_privkey, GNUTLS_X509_FMT_PEM, NULL, &host_key_pem.size); 148 gnutls_x509_privkey_export(host_privkey, GNUTLS_X509_FMT_PEM, NULL, &host_key_pem.size);
144 149
145 root_key_pem.data = gnutls_malloc(root_key_pem.size); 150 root_key_pem.data = gnutls_malloc(root_key_pem.size);
146 host_key_pem.data = gnutls_malloc(host_key_pem.size); 151 host_key_pem.data = gnutls_malloc(host_key_pem.size);
147 152
148 gnutls_x509_privkey_export (root_privkey, GNUTLS_X509_FMT_PEM, root_key_pem.data, &root_key_pem.size); 153 gnutls_x509_privkey_export(root_privkey, GNUTLS_X509_FMT_PEM, root_key_pem.data, &root_key_pem.size);
149 gnutls_x509_privkey_export (host_privkey, GNUTLS_X509_FMT_PEM, host_key_pem.data, &host_key_pem.size); 154 gnutls_x509_privkey_export(host_privkey, GNUTLS_X509_FMT_PEM, host_key_pem.data, &host_key_pem.size);
150 155
151 gnutls_datum_t root_cert_pem = {NULL, 0}; 156 gnutls_datum_t root_cert_pem = { NULL, 0 };
152 gnutls_datum_t host_cert_pem = {NULL, 0}; 157 gnutls_datum_t host_cert_pem = { NULL, 0 };
153 158
154 gnutls_x509_crt_export (root_cert, GNUTLS_X509_FMT_PEM, NULL, &root_cert_pem.size); 159 gnutls_x509_crt_export(root_cert, GNUTLS_X509_FMT_PEM, NULL, &root_cert_pem.size);
155 gnutls_x509_crt_export (host_cert, GNUTLS_X509_FMT_PEM, NULL, &host_cert_pem.size); 160 gnutls_x509_crt_export(host_cert, GNUTLS_X509_FMT_PEM, NULL, &host_cert_pem.size);
156 161
157 root_cert_pem.data = gnutls_malloc(root_cert_pem.size); 162 root_cert_pem.data = gnutls_malloc(root_cert_pem.size);
158 host_cert_pem.data = gnutls_malloc(host_cert_pem.size); 163 host_cert_pem.data = gnutls_malloc(host_cert_pem.size);
159 164
160 printf("Generating root certificate..."); 165 printf("Generating root certificate...");
161 gnutls_x509_crt_export (root_cert, GNUTLS_X509_FMT_PEM, root_cert_pem.data, &root_cert_pem.size); 166 gnutls_x509_crt_export(root_cert, GNUTLS_X509_FMT_PEM, root_cert_pem.data, &root_cert_pem.size);
162 printf("done\n"); 167 printf("done\n");
163 168
164 printf("Generating host certificate..."); 169 printf("Generating host certificate...");
165 gnutls_x509_crt_export (host_cert, GNUTLS_X509_FMT_PEM, host_cert_pem.data, &host_cert_pem.size); 170 gnutls_x509_crt_export(host_cert, GNUTLS_X509_FMT_PEM, host_cert_pem.data, &host_cert_pem.size);
166 printf("done\n"); 171 printf("done\n");
167 172
168 173
@@ -176,4 +181,3 @@ int main(int argc, char *argv[]) {
176 181
177 return 0; 182 return 0;
178} 183}
179