diff options
| author | Lars Magne Ingebrigtsen | 2010-09-29 16:30:45 +0200 |
|---|---|---|
| committer | Lars Magne Ingebrigtsen | 2010-09-29 16:30:45 +0200 |
| commit | e6059fa2447b7d7b147fbb97ec67bf3ec09622fc (patch) | |
| tree | 5725b17e52b91aae237d89584074236b4952a819 /src/gnutls.c | |
| parent | 252b4f5cf6a2d98643fb3ad8b23fb0ae6f942f5e (diff) | |
| download | emacs-e6059fa2447b7d7b147fbb97ec67bf3ec09622fc.tar.gz emacs-e6059fa2447b7d7b147fbb97ec67bf3ec09622fc.zip | |
Clean up gnutls.c coding style to conform with the Emacs style.
Remove some debugging messages.
Cast some parameters to avoid compilation warnings.
Diffstat (limited to 'src/gnutls.c')
| -rw-r--r-- | src/gnutls.c | 162 |
1 files changed, 78 insertions, 84 deletions
diff --git a/src/gnutls.c b/src/gnutls.c index 4be28016eac..37b4341d184 100644 --- a/src/gnutls.c +++ b/src/gnutls.c | |||
| @@ -42,22 +42,22 @@ emacs_gnutls_handshake (struct Lisp_Process *proc) | |||
| 42 | return; | 42 | return; |
| 43 | 43 | ||
| 44 | if (proc->gnutls_initstage < GNUTLS_STAGE_TRANSPORT_POINTERS_SET) | 44 | if (proc->gnutls_initstage < GNUTLS_STAGE_TRANSPORT_POINTERS_SET) |
| 45 | { | 45 | { |
| 46 | /* FIXME: This can't be right: infd and outfd are integers (file handles) | 46 | gnutls_transport_set_ptr2 (state, |
| 47 | whereas the function expects args of type gnutls_transport_ptr_t. */ | 47 | (gnutls_transport_ptr_t) (long) proc->infd, |
| 48 | gnutls_transport_set_ptr2 (state, proc->infd, proc->outfd); | 48 | (gnutls_transport_ptr_t) (long) proc->outfd); |
| 49 | 49 | ||
| 50 | proc->gnutls_initstage = GNUTLS_STAGE_TRANSPORT_POINTERS_SET; | 50 | proc->gnutls_initstage = GNUTLS_STAGE_TRANSPORT_POINTERS_SET; |
| 51 | } | 51 | } |
| 52 | 52 | ||
| 53 | ret = gnutls_handshake (state); | 53 | ret = gnutls_handshake (state); |
| 54 | proc->gnutls_initstage = GNUTLS_STAGE_HANDSHAKE_TRIED; | 54 | proc->gnutls_initstage = GNUTLS_STAGE_HANDSHAKE_TRIED; |
| 55 | 55 | ||
| 56 | if (ret == GNUTLS_E_SUCCESS) | 56 | if (ret == GNUTLS_E_SUCCESS) |
| 57 | { | 57 | { |
| 58 | /* here we're finally done. */ | 58 | /* here we're finally done. */ |
| 59 | proc->gnutls_initstage = GNUTLS_STAGE_READY; | 59 | proc->gnutls_initstage = GNUTLS_STAGE_READY; |
| 60 | } | 60 | } |
| 61 | } | 61 | } |
| 62 | 62 | ||
| 63 | int | 63 | int |
| @@ -68,7 +68,7 @@ emacs_gnutls_write (int fildes, struct Lisp_Process *proc, char *buf, | |||
| 68 | gnutls_session_t state = proc->gnutls_state; | 68 | gnutls_session_t state = proc->gnutls_state; |
| 69 | 69 | ||
| 70 | if (proc->gnutls_initstage != GNUTLS_STAGE_READY) | 70 | if (proc->gnutls_initstage != GNUTLS_STAGE_READY) |
| 71 | return 0; | 71 | return -1; |
| 72 | 72 | ||
| 73 | bytes_written = 0; | 73 | bytes_written = 0; |
| 74 | 74 | ||
| @@ -100,10 +100,11 @@ emacs_gnutls_read (int fildes, struct Lisp_Process *proc, char *buf, | |||
| 100 | register int rtnval; | 100 | register int rtnval; |
| 101 | gnutls_session_t state = proc->gnutls_state; | 101 | gnutls_session_t state = proc->gnutls_state; |
| 102 | 102 | ||
| 103 | if (proc->gnutls_initstage != GNUTLS_STAGE_READY) { | 103 | if (proc->gnutls_initstage != GNUTLS_STAGE_READY) |
| 104 | emacs_gnutls_handshake (proc); | 104 | { |
| 105 | return -1; | 105 | emacs_gnutls_handshake (proc); |
| 106 | } | 106 | return -1; |
| 107 | } | ||
| 107 | 108 | ||
| 108 | rtnval = gnutls_read (state, buf, nbyte); | 109 | rtnval = gnutls_read (state, buf, nbyte); |
| 109 | if (rtnval >= 0) | 110 | if (rtnval >= 0) |
| @@ -119,16 +120,16 @@ emacs_gnutls_read (int fildes, struct Lisp_Process *proc, char *buf, | |||
| 119 | Lisp_Object gnutls_make_error (int error) | 120 | Lisp_Object gnutls_make_error (int error) |
| 120 | { | 121 | { |
| 121 | switch (error) | 122 | switch (error) |
| 122 | { | 123 | { |
| 123 | case GNUTLS_E_SUCCESS: | 124 | case GNUTLS_E_SUCCESS: |
| 124 | return Qt; | 125 | return Qt; |
| 125 | case GNUTLS_E_AGAIN: | 126 | case GNUTLS_E_AGAIN: |
| 126 | return Qgnutls_e_again; | 127 | return Qgnutls_e_again; |
| 127 | case GNUTLS_E_INTERRUPTED: | 128 | case GNUTLS_E_INTERRUPTED: |
| 128 | return Qgnutls_e_interrupted; | 129 | return Qgnutls_e_interrupted; |
| 129 | case GNUTLS_E_INVALID_SESSION: | 130 | case GNUTLS_E_INVALID_SESSION: |
| 130 | return Qgnutls_e_invalid_session; | 131 | return Qgnutls_e_invalid_session; |
| 131 | } | 132 | } |
| 132 | 133 | ||
| 133 | return make_number (error); | 134 | return make_number (error); |
| 134 | } | 135 | } |
| @@ -163,17 +164,17 @@ ERROR is an integer or a symbol with an integer `gnutls-code' property. */) | |||
| 163 | if (EQ (err, Qt)) return Qnil; | 164 | if (EQ (err, Qt)) return Qnil; |
| 164 | 165 | ||
| 165 | if (SYMBOLP (err)) | 166 | if (SYMBOLP (err)) |
| 166 | { | ||
| 167 | code = Fget (err, Qgnutls_code); | ||
| 168 | if (NUMBERP (code)) | ||
| 169 | { | 167 | { |
| 170 | err = code; | 168 | code = Fget (err, Qgnutls_code); |
| 171 | } | 169 | if (NUMBERP (code)) |
| 172 | else | 170 | { |
| 173 | { | 171 | err = code; |
| 174 | error ("Symbol has no numeric gnutls-code property"); | 172 | } |
| 173 | else | ||
| 174 | { | ||
| 175 | error ("Symbol has no numeric gnutls-code property"); | ||
| 176 | } | ||
| 175 | } | 177 | } |
| 176 | } | ||
| 177 | 178 | ||
| 178 | if (!NUMBERP (err)) | 179 | if (!NUMBERP (err)) |
| 179 | error ("Not an error symbol or code"); | 180 | error ("Not an error symbol or code"); |
| @@ -194,17 +195,17 @@ ERROR is an integer or a symbol with an integer `gnutls-code' property. */) | |||
| 194 | if (EQ (err, Qt)) return build_string ("Not an error"); | 195 | if (EQ (err, Qt)) return build_string ("Not an error"); |
| 195 | 196 | ||
| 196 | if (SYMBOLP (err)) | 197 | if (SYMBOLP (err)) |
| 197 | { | ||
| 198 | code = Fget (err, Qgnutls_code); | ||
| 199 | if (NUMBERP (code)) | ||
| 200 | { | 198 | { |
| 201 | err = code; | 199 | code = Fget (err, Qgnutls_code); |
| 202 | } | 200 | if (NUMBERP (code)) |
| 203 | else | 201 | { |
| 204 | { | 202 | err = code; |
| 205 | return build_string ("Symbol has no numeric gnutls-code property"); | 203 | } |
| 204 | else | ||
| 205 | { | ||
| 206 | return build_string ("Symbol has no numeric gnutls-code property"); | ||
| 207 | } | ||
| 206 | } | 208 | } |
| 207 | } | ||
| 208 | 209 | ||
| 209 | if (!NUMBERP (err)) | 210 | if (!NUMBERP (err)) |
| 210 | return build_string ("Not an error symbol or code"); | 211 | return build_string ("Not an error symbol or code"); |
| @@ -223,10 +224,10 @@ See also `gnutls-init'. */) | |||
| 223 | state = XPROCESS (proc)->gnutls_state; | 224 | state = XPROCESS (proc)->gnutls_state; |
| 224 | 225 | ||
| 225 | if (GNUTLS_INITSTAGE (proc) >= GNUTLS_STAGE_INIT) | 226 | if (GNUTLS_INITSTAGE (proc) >= GNUTLS_STAGE_INIT) |
| 226 | { | 227 | { |
| 227 | gnutls_deinit (state); | 228 | gnutls_deinit (state); |
| 228 | GNUTLS_INITSTAGE (proc) = GNUTLS_STAGE_INIT - 1; | 229 | GNUTLS_INITSTAGE (proc) = GNUTLS_STAGE_INIT - 1; |
| 229 | } | 230 | } |
| 230 | 231 | ||
| 231 | return Qt; | 232 | return Qt; |
| 232 | } | 233 | } |
| @@ -314,7 +315,6 @@ KEYFILE and optionally CALLBACK. */) | |||
| 314 | 315 | ||
| 315 | if (NUMBERP (loglevel)) | 316 | if (NUMBERP (loglevel)) |
| 316 | { | 317 | { |
| 317 | message ("setting up log level %d", XINT (loglevel)); | ||
| 318 | gnutls_global_set_log_function (gnutls_log_function); | 318 | gnutls_global_set_log_function (gnutls_log_function); |
| 319 | gnutls_global_set_log_level (XINT (loglevel)); | 319 | gnutls_global_set_log_level (XINT (loglevel)); |
| 320 | max_log_level = XINT (loglevel); | 320 | max_log_level = XINT (loglevel); |
| @@ -328,67 +328,67 @@ KEYFILE and optionally CALLBACK. */) | |||
| 328 | 328 | ||
| 329 | /* deinit and free resources. */ | 329 | /* deinit and free resources. */ |
| 330 | if (GNUTLS_INITSTAGE (proc) >= GNUTLS_STAGE_CRED_ALLOC) | 330 | if (GNUTLS_INITSTAGE (proc) >= GNUTLS_STAGE_CRED_ALLOC) |
| 331 | { | 331 | { |
| 332 | GNUTLS_LOG (1, max_log_level, "deallocating credentials"); | 332 | GNUTLS_LOG (1, max_log_level, "deallocating credentials"); |
| 333 | 333 | ||
| 334 | if (EQ (type, Qgnutls_x509pki)) | 334 | if (EQ (type, Qgnutls_x509pki)) |
| 335 | { | 335 | { |
| 336 | GNUTLS_LOG (2, max_log_level, "deallocating x509 credentials"); | 336 | GNUTLS_LOG (2, max_log_level, "deallocating x509 credentials"); |
| 337 | x509_cred = XPROCESS (proc)->gnutls_x509_cred; | 337 | x509_cred = XPROCESS (proc)->gnutls_x509_cred; |
| 338 | gnutls_certificate_free_credentials (x509_cred); | 338 | gnutls_certificate_free_credentials (x509_cred); |
| 339 | } | 339 | } |
| 340 | else if (EQ (type, Qgnutls_anon)) | 340 | else if (EQ (type, Qgnutls_anon)) |
| 341 | { | 341 | { |
| 342 | GNUTLS_LOG (2, max_log_level, "deallocating anon credentials"); | 342 | GNUTLS_LOG (2, max_log_level, "deallocating anon credentials"); |
| 343 | anon_cred = XPROCESS (proc)->gnutls_anon_cred; | 343 | anon_cred = XPROCESS (proc)->gnutls_anon_cred; |
| 344 | gnutls_anon_free_client_credentials (anon_cred); | 344 | gnutls_anon_free_client_credentials (anon_cred); |
| 345 | } | 345 | } |
| 346 | else | 346 | else |
| 347 | { | 347 | { |
| 348 | error ("unknown credential type"); | 348 | error ("unknown credential type"); |
| 349 | ret = GNUTLS_EMACS_ERROR_INVALID_TYPE; | 349 | ret = GNUTLS_EMACS_ERROR_INVALID_TYPE; |
| 350 | } | 350 | } |
| 351 | 351 | ||
| 352 | if (GNUTLS_INITSTAGE (proc) >= GNUTLS_STAGE_INIT) | 352 | if (GNUTLS_INITSTAGE (proc) >= GNUTLS_STAGE_INIT) |
| 353 | { | 353 | { |
| 354 | GNUTLS_LOG (1, max_log_level, "deallocating x509 credentials"); | 354 | GNUTLS_LOG (1, max_log_level, "deallocating x509 credentials"); |
| 355 | Fgnutls_deinit (proc); | 355 | Fgnutls_deinit (proc); |
| 356 | } | 356 | } |
| 357 | } | 357 | } |
| 358 | 358 | ||
| 359 | GNUTLS_INITSTAGE (proc) = GNUTLS_STAGE_EMPTY; | 359 | GNUTLS_INITSTAGE (proc) = GNUTLS_STAGE_EMPTY; |
| 360 | 360 | ||
| 361 | GNUTLS_LOG (1, max_log_level, "allocating credentials"); | 361 | GNUTLS_LOG (1, max_log_level, "allocating credentials"); |
| 362 | 362 | ||
| 363 | if (EQ (type, Qgnutls_x509pki)) | 363 | if (EQ (type, Qgnutls_x509pki)) |
| 364 | { | 364 | { |
| 365 | GNUTLS_LOG (2, max_log_level, "allocating x509 credentials"); | 365 | GNUTLS_LOG (2, max_log_level, "allocating x509 credentials"); |
| 366 | x509_cred = XPROCESS (proc)->gnutls_x509_cred; | 366 | x509_cred = XPROCESS (proc)->gnutls_x509_cred; |
| 367 | if (gnutls_certificate_allocate_credentials (&x509_cred) < 0) | 367 | if (gnutls_certificate_allocate_credentials (&x509_cred) < 0) |
| 368 | memory_full (); | 368 | memory_full (); |
| 369 | } | 369 | } |
| 370 | else if (EQ (type, Qgnutls_anon)) | 370 | else if (EQ (type, Qgnutls_anon)) |
| 371 | { | 371 | { |
| 372 | GNUTLS_LOG (2, max_log_level, "allocating anon credentials"); | 372 | GNUTLS_LOG (2, max_log_level, "allocating anon credentials"); |
| 373 | anon_cred = XPROCESS (proc)->gnutls_anon_cred; | 373 | anon_cred = XPROCESS (proc)->gnutls_anon_cred; |
| 374 | if (gnutls_anon_allocate_client_credentials (&anon_cred) < 0) | 374 | if (gnutls_anon_allocate_client_credentials (&anon_cred) < 0) |
| 375 | memory_full (); | 375 | memory_full (); |
| 376 | } | 376 | } |
| 377 | else | 377 | else |
| 378 | { | 378 | { |
| 379 | error ("unknown credential type"); | 379 | error ("unknown credential type"); |
| 380 | ret = GNUTLS_EMACS_ERROR_INVALID_TYPE; | 380 | ret = GNUTLS_EMACS_ERROR_INVALID_TYPE; |
| 381 | } | 381 | } |
| 382 | 382 | ||
| 383 | if (ret < GNUTLS_E_SUCCESS) | 383 | if (ret < GNUTLS_E_SUCCESS) |
| 384 | return gnutls_make_error (ret); | 384 | return gnutls_make_error (ret); |
| 385 | 385 | ||
| 386 | GNUTLS_INITSTAGE (proc) = GNUTLS_STAGE_CRED_ALLOC; | 386 | GNUTLS_INITSTAGE (proc) = GNUTLS_STAGE_CRED_ALLOC; |
| 387 | 387 | ||
| 388 | if (EQ (type, Qgnutls_x509pki)) | 388 | if (EQ (type, Qgnutls_x509pki)) |
| 389 | { | 389 | { |
| 390 | if (STRINGP (trustfile)) | 390 | if (STRINGP (trustfile)) |
| 391 | { | 391 | { |
| 392 | GNUTLS_LOG (1, max_log_level, "setting the trustfile"); | 392 | GNUTLS_LOG (1, max_log_level, "setting the trustfile"); |
| 393 | ret = gnutls_certificate_set_x509_trust_file | 393 | ret = gnutls_certificate_set_x509_trust_file |
| 394 | (x509_cred, | 394 | (x509_cred, |
| @@ -397,10 +397,10 @@ KEYFILE and optionally CALLBACK. */) | |||
| 397 | 397 | ||
| 398 | if (ret < GNUTLS_E_SUCCESS) | 398 | if (ret < GNUTLS_E_SUCCESS) |
| 399 | return gnutls_make_error (ret); | 399 | return gnutls_make_error (ret); |
| 400 | } | 400 | } |
| 401 | 401 | ||
| 402 | if (STRINGP (keyfile)) | 402 | if (STRINGP (keyfile)) |
| 403 | { | 403 | { |
| 404 | GNUTLS_LOG (1, max_log_level, "setting the keyfile"); | 404 | GNUTLS_LOG (1, max_log_level, "setting the keyfile"); |
| 405 | ret = gnutls_certificate_set_x509_crl_file | 405 | ret = gnutls_certificate_set_x509_crl_file |
| 406 | (x509_cred, | 406 | (x509_cred, |
| @@ -409,8 +409,8 @@ KEYFILE and optionally CALLBACK. */) | |||
| 409 | 409 | ||
| 410 | if (ret < GNUTLS_E_SUCCESS) | 410 | if (ret < GNUTLS_E_SUCCESS) |
| 411 | return gnutls_make_error (ret); | 411 | return gnutls_make_error (ret); |
| 412 | } | 412 | } |
| 413 | } | 413 | } |
| 414 | 414 | ||
| 415 | GNUTLS_INITSTAGE (proc) = GNUTLS_STAGE_FILES; | 415 | GNUTLS_INITSTAGE (proc) = GNUTLS_STAGE_FILES; |
| 416 | 416 | ||
| @@ -419,7 +419,7 @@ KEYFILE and optionally CALLBACK. */) | |||
| 419 | ret = gnutls_init (&state, GNUTLS_CLIENT); | 419 | ret = gnutls_init (&state, GNUTLS_CLIENT); |
| 420 | 420 | ||
| 421 | if (ret < GNUTLS_E_SUCCESS) | 421 | if (ret < GNUTLS_E_SUCCESS) |
| 422 | return gnutls_make_error (ret); | 422 | return gnutls_make_error (ret); |
| 423 | 423 | ||
| 424 | XPROCESS (proc)->gnutls_state = state; | 424 | XPROCESS (proc)->gnutls_state = state; |
| 425 | 425 | ||
| @@ -432,32 +432,26 @@ KEYFILE and optionally CALLBACK. */) | |||
| 432 | NULL); | 432 | NULL); |
| 433 | 433 | ||
| 434 | if (ret < GNUTLS_E_SUCCESS) | 434 | if (ret < GNUTLS_E_SUCCESS) |
| 435 | return gnutls_make_error (ret); | 435 | return gnutls_make_error (ret); |
| 436 | 436 | ||
| 437 | GNUTLS_INITSTAGE (proc) = GNUTLS_STAGE_PRIORITY; | 437 | GNUTLS_INITSTAGE (proc) = GNUTLS_STAGE_PRIORITY; |
| 438 | 438 | ||
| 439 | message ("gnutls: setting the credentials"); | ||
| 440 | |||
| 441 | if (EQ (type, Qgnutls_x509pki)) | 439 | if (EQ (type, Qgnutls_x509pki)) |
| 442 | { | 440 | { |
| 443 | message ("gnutls: setting the x509 credentials"); | ||
| 444 | |||
| 445 | ret = gnutls_cred_set (state, GNUTLS_CRD_CERTIFICATE, x509_cred); | 441 | ret = gnutls_cred_set (state, GNUTLS_CRD_CERTIFICATE, x509_cred); |
| 446 | } | 442 | } |
| 447 | else if (EQ (type, Qgnutls_anon)) | 443 | else if (EQ (type, Qgnutls_anon)) |
| 448 | { | 444 | { |
| 449 | message ("gnutls: setting the anon credentials"); | ||
| 450 | |||
| 451 | ret = gnutls_cred_set (state, GNUTLS_CRD_ANON, anon_cred); | 445 | ret = gnutls_cred_set (state, GNUTLS_CRD_ANON, anon_cred); |
| 452 | } | 446 | } |
| 453 | else | 447 | else |
| 454 | { | 448 | { |
| 455 | error ("unknown credential type"); | 449 | error ("unknown credential type"); |
| 456 | ret = GNUTLS_EMACS_ERROR_INVALID_TYPE; | 450 | ret = GNUTLS_EMACS_ERROR_INVALID_TYPE; |
| 457 | } | 451 | } |
| 458 | 452 | ||
| 459 | if (ret < GNUTLS_E_SUCCESS) | 453 | if (ret < GNUTLS_E_SUCCESS) |
| 460 | return gnutls_make_error (ret); | 454 | return gnutls_make_error (ret); |
| 461 | 455 | ||
| 462 | XPROCESS (proc)->gnutls_anon_cred = anon_cred; | 456 | XPROCESS (proc)->gnutls_anon_cred = anon_cred; |
| 463 | XPROCESS (proc)->gnutls_x509_cred = x509_cred; | 457 | XPROCESS (proc)->gnutls_x509_cred = x509_cred; |