annotate src/gnutls.c @ 112318:deae5bb3f0f6

Give a name FLOAT_TO_STRING_BUFSIZE to the constant 350. * lisp.h (FLOAT_TO_STRING_BUFSIZE): New macro. * data.c (Fnumber_to_string): Use it. * print.c (float_to_string, print_object): Likewise.
author Paul Eggert <eggert@cs.ucla.edu>
date Sun, 09 Jan 2011 00:21:21 -0800
parents 54ea07fb88fc
children 6378d1b57038
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
1 /* GnuTLS glue for GNU Emacs.
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
2 Copyright (C) 2010 Free Software Foundation, Inc.
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
3
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
4 This file is part of GNU Emacs.
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
5
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
6 GNU Emacs is free software: you can redistribute it and/or modify
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
7 it under the terms of the GNU General Public License as published by
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
8 the Free Software Foundation, either version 3 of the License, or
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
9 (at your option) any later version.
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
10
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
11 GNU Emacs is distributed in the hope that it will be useful,
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
14 GNU General Public License for more details.
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
15
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
17 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
18
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
19 #include <config.h>
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
20 #include <errno.h>
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
21 #include <setjmp.h>
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
22
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
23 #include "lisp.h"
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
24 #include "process.h"
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
25
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
26 #ifdef HAVE_GNUTLS
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
27 #include <gnutls/gnutls.h>
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
28
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
29 Lisp_Object Qgnutls_code;
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
30 Lisp_Object Qgnutls_anon, Qgnutls_x509pki;
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
31 Lisp_Object Qgnutls_e_interrupted, Qgnutls_e_again,
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
32 Qgnutls_e_invalid_session, Qgnutls_e_not_ready_for_handshake;
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
33 int global_initialized;
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
34
110745
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
35 /* The following are for the property list of `gnutls-boot'. */
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
36 Lisp_Object Qgnutls_bootprop_priority;
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
37 Lisp_Object Qgnutls_bootprop_trustfiles;
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
38 Lisp_Object Qgnutls_bootprop_keyfiles;
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
39 Lisp_Object Qgnutls_bootprop_callbacks;
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
40 Lisp_Object Qgnutls_bootprop_loglevel;
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
41
110724
3ccf1931ae33 src/gnutls.c: Doc fixes. Make some functions static.
Juanma Barranquero <lekktu@gmail.com>
parents: 110652
diff changeset
42 static void
110649
2f0d755fa21b Do the gnutls handshake from the reader loop, instead of looping over
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110648
diff changeset
43 emacs_gnutls_handshake (struct Lisp_Process *proc)
2f0d755fa21b Do the gnutls handshake from the reader loop, instead of looping over
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110648
diff changeset
44 {
2f0d755fa21b Do the gnutls handshake from the reader loop, instead of looping over
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110648
diff changeset
45 gnutls_session_t state = proc->gnutls_state;
2f0d755fa21b Do the gnutls handshake from the reader loop, instead of looping over
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110648
diff changeset
46 int ret;
2f0d755fa21b Do the gnutls handshake from the reader loop, instead of looping over
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110648
diff changeset
47
2f0d755fa21b Do the gnutls handshake from the reader loop, instead of looping over
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110648
diff changeset
48 if (proc->gnutls_initstage < GNUTLS_STAGE_HANDSHAKE_CANDO)
2f0d755fa21b Do the gnutls handshake from the reader loop, instead of looping over
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110648
diff changeset
49 return;
2f0d755fa21b Do the gnutls handshake from the reader loop, instead of looping over
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110648
diff changeset
50
2f0d755fa21b Do the gnutls handshake from the reader loop, instead of looping over
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110648
diff changeset
51 if (proc->gnutls_initstage < GNUTLS_STAGE_TRANSPORT_POINTERS_SET)
110652
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
52 {
110745
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
53 /* This is how GnuTLS takes sockets: as file descriptors passed
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
54 in. For an Emacs process socket, infd and outfd are the
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
55 same but we use this two-argument version for clarity. */
110652
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
56 gnutls_transport_set_ptr2 (state,
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
57 (gnutls_transport_ptr_t) (long) proc->infd,
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
58 (gnutls_transport_ptr_t) (long) proc->outfd);
110649
2f0d755fa21b Do the gnutls handshake from the reader loop, instead of looping over
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110648
diff changeset
59
110652
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
60 proc->gnutls_initstage = GNUTLS_STAGE_TRANSPORT_POINTERS_SET;
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
61 }
110649
2f0d755fa21b Do the gnutls handshake from the reader loop, instead of looping over
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110648
diff changeset
62
2f0d755fa21b Do the gnutls handshake from the reader loop, instead of looping over
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110648
diff changeset
63 ret = gnutls_handshake (state);
2f0d755fa21b Do the gnutls handshake from the reader loop, instead of looping over
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110648
diff changeset
64 proc->gnutls_initstage = GNUTLS_STAGE_HANDSHAKE_TRIED;
2f0d755fa21b Do the gnutls handshake from the reader loop, instead of looping over
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110648
diff changeset
65
2f0d755fa21b Do the gnutls handshake from the reader loop, instead of looping over
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110648
diff changeset
66 if (ret == GNUTLS_E_SUCCESS)
110652
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
67 {
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
68 /* here we're finally done. */
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
69 proc->gnutls_initstage = GNUTLS_STAGE_READY;
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
70 }
110649
2f0d755fa21b Do the gnutls handshake from the reader loop, instead of looping over
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110648
diff changeset
71 }
2f0d755fa21b Do the gnutls handshake from the reader loop, instead of looping over
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110648
diff changeset
72
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
73 int
110648
256dd50b2a63 Make sure all reads/writes to gnutls streams go via the gnutls functions.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110636
diff changeset
74 emacs_gnutls_write (int fildes, struct Lisp_Process *proc, char *buf,
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
75 unsigned int nbyte)
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
76 {
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
77 register int rtnval, bytes_written;
110648
256dd50b2a63 Make sure all reads/writes to gnutls streams go via the gnutls functions.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110636
diff changeset
78 gnutls_session_t state = proc->gnutls_state;
256dd50b2a63 Make sure all reads/writes to gnutls streams go via the gnutls functions.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110636
diff changeset
79
110907
1ccdcdef34fc Fix gnutls write-before-negotiation case.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110878
diff changeset
80 if (proc->gnutls_initstage != GNUTLS_STAGE_READY) {
1ccdcdef34fc Fix gnutls write-before-negotiation case.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110878
diff changeset
81 #ifdef EWOULDBLOCK
1ccdcdef34fc Fix gnutls write-before-negotiation case.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110878
diff changeset
82 errno = EWOULDBLOCK;
1ccdcdef34fc Fix gnutls write-before-negotiation case.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110878
diff changeset
83 #endif
1ccdcdef34fc Fix gnutls write-before-negotiation case.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110878
diff changeset
84 #ifdef EAGAIN
1ccdcdef34fc Fix gnutls write-before-negotiation case.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110878
diff changeset
85 errno = EAGAIN;
1ccdcdef34fc Fix gnutls write-before-negotiation case.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110878
diff changeset
86 #endif
110652
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
87 return -1;
110907
1ccdcdef34fc Fix gnutls write-before-negotiation case.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110878
diff changeset
88 }
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
89
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
90 bytes_written = 0;
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
91
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
92 while (nbyte > 0)
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
93 {
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
94 rtnval = gnutls_write (state, buf, nbyte);
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
95
110878
39b6f8749957 (emacs_gnutls_write): Check for GNUTLS_E_AGAIN and not EINTR.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110875
diff changeset
96 if (rtnval < 0)
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
97 {
110878
39b6f8749957 (emacs_gnutls_write): Check for GNUTLS_E_AGAIN and not EINTR.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110875
diff changeset
98 if (rtnval == GNUTLS_E_AGAIN || rtnval == GNUTLS_E_INTERRUPTED)
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
99 continue;
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
100 else
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
101 return (bytes_written ? bytes_written : -1);
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
102 }
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
103
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
104 buf += rtnval;
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
105 nbyte -= rtnval;
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
106 bytes_written += rtnval;
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
107 }
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
108
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
109 return (bytes_written);
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
110 }
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
111
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
112 int
110648
256dd50b2a63 Make sure all reads/writes to gnutls streams go via the gnutls functions.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110636
diff changeset
113 emacs_gnutls_read (int fildes, struct Lisp_Process *proc, char *buf,
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
114 unsigned int nbyte)
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
115 {
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
116 register int rtnval;
110648
256dd50b2a63 Make sure all reads/writes to gnutls streams go via the gnutls functions.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110636
diff changeset
117 gnutls_session_t state = proc->gnutls_state;
256dd50b2a63 Make sure all reads/writes to gnutls streams go via the gnutls functions.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110636
diff changeset
118
110652
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
119 if (proc->gnutls_initstage != GNUTLS_STAGE_READY)
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
120 {
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
121 emacs_gnutls_handshake (proc);
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
122 return -1;
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
123 }
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
124
110608
06497cf3e920 (emacs_gnutls_read): Don't infloop while reading.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110606
diff changeset
125 rtnval = gnutls_read (state, buf, nbyte);
06497cf3e920 (emacs_gnutls_read): Don't infloop while reading.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110606
diff changeset
126 if (rtnval >= 0)
06497cf3e920 (emacs_gnutls_read): Don't infloop while reading.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110606
diff changeset
127 return rtnval;
111025
54ea07fb88fc (emacs_gnutls_read): Return 0 if we get a non-"EAGAIN"-like error to signal to Emacs that the socket should be closed.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110907
diff changeset
128 else {
54ea07fb88fc (emacs_gnutls_read): Return 0 if we get a non-"EAGAIN"-like error to signal to Emacs that the socket should be closed.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110907
diff changeset
129 if (rtnval == GNUTLS_E_AGAIN ||
54ea07fb88fc (emacs_gnutls_read): Return 0 if we get a non-"EAGAIN"-like error to signal to Emacs that the socket should be closed.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110907
diff changeset
130 rtnval == GNUTLS_E_INTERRUPTED)
54ea07fb88fc (emacs_gnutls_read): Return 0 if we get a non-"EAGAIN"-like error to signal to Emacs that the socket should be closed.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110907
diff changeset
131 return -1;
54ea07fb88fc (emacs_gnutls_read): Return 0 if we get a non-"EAGAIN"-like error to signal to Emacs that the socket should be closed.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110907
diff changeset
132 else
54ea07fb88fc (emacs_gnutls_read): Return 0 if we get a non-"EAGAIN"-like error to signal to Emacs that the socket should be closed.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110907
diff changeset
133 return 0;
54ea07fb88fc (emacs_gnutls_read): Return 0 if we get a non-"EAGAIN"-like error to signal to Emacs that the socket should be closed.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110907
diff changeset
134 }
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
135 }
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
136
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
137 /* convert an integer error to a Lisp_Object; it will be either a
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
138 known symbol like `gnutls_e_interrupted' and `gnutls_e_again' or
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
139 simply the integer value of the error. GNUTLS_E_SUCCESS is mapped
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
140 to Qt. */
110724
3ccf1931ae33 src/gnutls.c: Doc fixes. Make some functions static.
Juanma Barranquero <lekktu@gmail.com>
parents: 110652
diff changeset
141 static Lisp_Object
3ccf1931ae33 src/gnutls.c: Doc fixes. Make some functions static.
Juanma Barranquero <lekktu@gmail.com>
parents: 110652
diff changeset
142 gnutls_make_error (int error)
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
143 {
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
144 switch (error)
110652
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
145 {
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
146 case GNUTLS_E_SUCCESS:
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
147 return Qt;
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
148 case GNUTLS_E_AGAIN:
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
149 return Qgnutls_e_again;
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
150 case GNUTLS_E_INTERRUPTED:
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
151 return Qgnutls_e_interrupted;
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
152 case GNUTLS_E_INVALID_SESSION:
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
153 return Qgnutls_e_invalid_session;
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
154 }
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
155
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
156 return make_number (error);
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
157 }
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
158
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
159 DEFUN ("gnutls-get-initstage", Fgnutls_get_initstage, Sgnutls_get_initstage, 1, 1, 0,
110724
3ccf1931ae33 src/gnutls.c: Doc fixes. Make some functions static.
Juanma Barranquero <lekktu@gmail.com>
parents: 110652
diff changeset
160 doc: /* Return the GnuTLS init stage of process PROC.
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
161 See also `gnutls-boot'. */)
110724
3ccf1931ae33 src/gnutls.c: Doc fixes. Make some functions static.
Juanma Barranquero <lekktu@gmail.com>
parents: 110652
diff changeset
162 (Lisp_Object proc)
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
163 {
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
164 CHECK_PROCESS (proc);
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
165
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
166 return make_number (GNUTLS_INITSTAGE (proc));
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
167 }
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
168
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
169 DEFUN ("gnutls-errorp", Fgnutls_errorp, Sgnutls_errorp, 1, 1, 0,
110724
3ccf1931ae33 src/gnutls.c: Doc fixes. Make some functions static.
Juanma Barranquero <lekktu@gmail.com>
parents: 110652
diff changeset
170 doc: /* Return t if ERROR indicates a GnuTLS problem.
3ccf1931ae33 src/gnutls.c: Doc fixes. Make some functions static.
Juanma Barranquero <lekktu@gmail.com>
parents: 110652
diff changeset
171 ERROR is an integer or a symbol with an integer `gnutls-code' property.
3ccf1931ae33 src/gnutls.c: Doc fixes. Make some functions static.
Juanma Barranquero <lekktu@gmail.com>
parents: 110652
diff changeset
172 usage: (gnutls-errorp ERROR) */)
3ccf1931ae33 src/gnutls.c: Doc fixes. Make some functions static.
Juanma Barranquero <lekktu@gmail.com>
parents: 110652
diff changeset
173 (Lisp_Object err)
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
174 {
110724
3ccf1931ae33 src/gnutls.c: Doc fixes. Make some functions static.
Juanma Barranquero <lekktu@gmail.com>
parents: 110652
diff changeset
175 if (EQ (err, Qt)) return Qnil;
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
176
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
177 return Qt;
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
178 }
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
179
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
180 DEFUN ("gnutls-error-fatalp", Fgnutls_error_fatalp, Sgnutls_error_fatalp, 1, 1, 0,
110724
3ccf1931ae33 src/gnutls.c: Doc fixes. Make some functions static.
Juanma Barranquero <lekktu@gmail.com>
parents: 110652
diff changeset
181 doc: /* Check if ERROR is fatal.
3ccf1931ae33 src/gnutls.c: Doc fixes. Make some functions static.
Juanma Barranquero <lekktu@gmail.com>
parents: 110652
diff changeset
182 ERROR is an integer or a symbol with an integer `gnutls-code' property.
3ccf1931ae33 src/gnutls.c: Doc fixes. Make some functions static.
Juanma Barranquero <lekktu@gmail.com>
parents: 110652
diff changeset
183 usage: (gnutls-error-fatalp ERROR) */)
3ccf1931ae33 src/gnutls.c: Doc fixes. Make some functions static.
Juanma Barranquero <lekktu@gmail.com>
parents: 110652
diff changeset
184 (Lisp_Object err)
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
185 {
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
186 Lisp_Object code;
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
187
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
188 if (EQ (err, Qt)) return Qnil;
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
189
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
190 if (SYMBOLP (err))
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
191 {
110652
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
192 code = Fget (err, Qgnutls_code);
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
193 if (NUMBERP (code))
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
194 {
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
195 err = code;
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
196 }
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
197 else
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
198 {
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
199 error ("Symbol has no numeric gnutls-code property");
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
200 }
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
201 }
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
202
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
203 if (!NUMBERP (err))
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
204 error ("Not an error symbol or code");
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
205
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
206 if (0 == gnutls_error_is_fatal (XINT (err)))
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
207 return Qnil;
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
208
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
209 return Qt;
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
210 }
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
211
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
212 DEFUN ("gnutls-error-string", Fgnutls_error_string, Sgnutls_error_string, 1, 1, 0,
110724
3ccf1931ae33 src/gnutls.c: Doc fixes. Make some functions static.
Juanma Barranquero <lekktu@gmail.com>
parents: 110652
diff changeset
213 doc: /* Return a description of ERROR.
3ccf1931ae33 src/gnutls.c: Doc fixes. Make some functions static.
Juanma Barranquero <lekktu@gmail.com>
parents: 110652
diff changeset
214 ERROR is an integer or a symbol with an integer `gnutls-code' property.
3ccf1931ae33 src/gnutls.c: Doc fixes. Make some functions static.
Juanma Barranquero <lekktu@gmail.com>
parents: 110652
diff changeset
215 usage: (gnutls-error-string ERROR) */)
3ccf1931ae33 src/gnutls.c: Doc fixes. Make some functions static.
Juanma Barranquero <lekktu@gmail.com>
parents: 110652
diff changeset
216 (Lisp_Object err)
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
217 {
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
218 Lisp_Object code;
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
219
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
220 if (EQ (err, Qt)) return build_string ("Not an error");
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
221
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
222 if (SYMBOLP (err))
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
223 {
110652
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
224 code = Fget (err, Qgnutls_code);
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
225 if (NUMBERP (code))
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
226 {
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
227 err = code;
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
228 }
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
229 else
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
230 {
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
231 return build_string ("Symbol has no numeric gnutls-code property");
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
232 }
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
233 }
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
234
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
235 if (!NUMBERP (err))
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
236 return build_string ("Not an error symbol or code");
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
237
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
238 return build_string (gnutls_strerror (XINT (err)));
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
239 }
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
240
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
241 DEFUN ("gnutls-deinit", Fgnutls_deinit, Sgnutls_deinit, 1, 1, 0,
110728
ab7396ada96a src/gnutls.c: Fix typo in docstring.
Juanma Barranquero <lekktu@gmail.com>
parents: 110724
diff changeset
242 doc: /* Deallocate GnuTLS resources associated with process PROC.
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
243 See also `gnutls-init'. */)
110724
3ccf1931ae33 src/gnutls.c: Doc fixes. Make some functions static.
Juanma Barranquero <lekktu@gmail.com>
parents: 110652
diff changeset
244 (Lisp_Object proc)
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
245 {
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
246 gnutls_session_t state;
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
247
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
248 CHECK_PROCESS (proc);
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
249 state = XPROCESS (proc)->gnutls_state;
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
250
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
251 if (GNUTLS_INITSTAGE (proc) >= GNUTLS_STAGE_INIT)
110652
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
252 {
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
253 gnutls_deinit (state);
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
254 GNUTLS_INITSTAGE (proc) = GNUTLS_STAGE_INIT - 1;
110652
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
255 }
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
256
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
257 return Qt;
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
258 }
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
259
110728
ab7396ada96a src/gnutls.c: Fix typo in docstring.
Juanma Barranquero <lekktu@gmail.com>
parents: 110724
diff changeset
260 /* Initializes global GnuTLS state to defaults.
ab7396ada96a src/gnutls.c: Fix typo in docstring.
Juanma Barranquero <lekktu@gmail.com>
parents: 110724
diff changeset
261 Call `gnutls-global-deinit' when GnuTLS usage is no longer needed.
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
262 Returns zero on success. */
110724
3ccf1931ae33 src/gnutls.c: Doc fixes. Make some functions static.
Juanma Barranquero <lekktu@gmail.com>
parents: 110652
diff changeset
263 static Lisp_Object
3ccf1931ae33 src/gnutls.c: Doc fixes. Make some functions static.
Juanma Barranquero <lekktu@gmail.com>
parents: 110652
diff changeset
264 gnutls_emacs_global_init (void)
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
265 {
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
266 int ret = GNUTLS_E_SUCCESS;
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
267
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
268 if (!global_initialized)
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
269 ret = gnutls_global_init ();
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
270
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
271 global_initialized = 1;
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
272
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
273 return gnutls_make_error (ret);
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
274 }
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
275
110728
ab7396ada96a src/gnutls.c: Fix typo in docstring.
Juanma Barranquero <lekktu@gmail.com>
parents: 110724
diff changeset
276 /* Deinitializes global GnuTLS state.
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
277 See also `gnutls-global-init'. */
110724
3ccf1931ae33 src/gnutls.c: Doc fixes. Make some functions static.
Juanma Barranquero <lekktu@gmail.com>
parents: 110652
diff changeset
278 static Lisp_Object
3ccf1931ae33 src/gnutls.c: Doc fixes. Make some functions static.
Juanma Barranquero <lekktu@gmail.com>
parents: 110652
diff changeset
279 gnutls_emacs_global_deinit (void)
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
280 {
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
281 if (global_initialized)
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
282 gnutls_global_deinit ();
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
283
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
284 global_initialized = 0;
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
285
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
286 return gnutls_make_error (GNUTLS_E_SUCCESS);
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
287 }
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
288
110724
3ccf1931ae33 src/gnutls.c: Doc fixes. Make some functions static.
Juanma Barranquero <lekktu@gmail.com>
parents: 110652
diff changeset
289 static void
3ccf1931ae33 src/gnutls.c: Doc fixes. Make some functions static.
Juanma Barranquero <lekktu@gmail.com>
parents: 110652
diff changeset
290 gnutls_log_function (int level, const char* string)
110611
6c735824d0c1 Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110608
diff changeset
291 {
110724
3ccf1931ae33 src/gnutls.c: Doc fixes. Make some functions static.
Juanma Barranquero <lekktu@gmail.com>
parents: 110652
diff changeset
292 message ("gnutls.c: [%d] %s", level, string);
110606
b4f4c3e9b976 Add debugging to the gnutls library, and finish handshaking when it's done.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110584
diff changeset
293 }
b4f4c3e9b976 Add debugging to the gnutls library, and finish handshaking when it's done.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110584
diff changeset
294
110745
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
295 static void
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
296 gnutls_log_function2 (int level, const char* string, const char* extra)
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
297 {
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
298 message ("gnutls.c: [%d] %s %s", level, string, extra);
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
299 }
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
300
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
301 DEFUN ("gnutls-boot", Fgnutls_boot, Sgnutls_boot, 3, 3, 0,
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
302 doc: /* Initialize GnuTLS client for process PROC with TYPE+PROPLIST.
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
303 Currently only client mode is supported. Returns a success/failure
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
304 value you can check with `gnutls-errorp'.
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
305
110745
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
306 TYPE is a symbol, either `gnutls-anon' or `gnutls-x509pki'.
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
307 PROPLIST is a property list with the following keys:
110611
6c735824d0c1 Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110608
diff changeset
308
110745
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
309 :priority is a GnuTLS priority string, defaults to "NORMAL".
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
310 :trustfiles is a list of PEM-encoded trust files for `gnutls-x509pki'.
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
311 :keyfiles is a list of PEM-encoded key files for `gnutls-x509pki'.
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
312 :callbacks is an alist of callback functions (TODO).
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
313 :loglevel is the debug level requested from GnuTLS, try 4.
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
314
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
315 The debug level will be set for this process AND globally for GnuTLS.
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
316 So if you set it higher or lower at any point, it affects global
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
317 debugging.
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
318
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
319 Note that the priority is set on the client. The server does not use
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
320 the protocols's priority except for disabling protocols that were not
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
321 specified.
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
322
110724
3ccf1931ae33 src/gnutls.c: Doc fixes. Make some functions static.
Juanma Barranquero <lekktu@gmail.com>
parents: 110652
diff changeset
323 Processes must be initialized with this function before other GnuTLS
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
324 functions are used. This function allocates resources which can only
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
325 be deallocated by calling `gnutls-deinit' or by calling it again.
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
326
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
327 Each authentication type may need additional information in order to
110745
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
328 work. For X.509 PKI (`gnutls-x509pki'), you probably need at least
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
329 one trustfile (usually a CA bundle). */)
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
330 (Lisp_Object proc, Lisp_Object type, Lisp_Object proplist)
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
331 {
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
332 int ret = GNUTLS_E_SUCCESS;
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
333
110611
6c735824d0c1 Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110608
diff changeset
334 int max_log_level = 0;
6c735824d0c1 Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110608
diff changeset
335
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
336 /* TODO: GNUTLS_X509_FMT_DER is also an option. */
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
337 int file_format = GNUTLS_X509_FMT_PEM;
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
338
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
339 gnutls_session_t state;
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
340 gnutls_certificate_credentials_t x509_cred;
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
341 gnutls_anon_client_credentials_t anon_cred;
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
342 Lisp_Object global_init;
110745
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
343 char* priority_string_ptr = "NORMAL"; /* default priority string. */
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
344 Lisp_Object tail;
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
345
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
346 /* Placeholders for the property list elements. */
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
347 Lisp_Object priority_string;
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
348 Lisp_Object trustfiles;
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
349 Lisp_Object keyfiles;
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
350 Lisp_Object callbacks;
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
351 Lisp_Object loglevel;
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
352
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
353 CHECK_PROCESS (proc);
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
354 CHECK_SYMBOL (type);
110745
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
355 CHECK_LIST (proplist);
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
356
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
357 priority_string = Fplist_get (proplist, Qgnutls_bootprop_priority);
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
358 trustfiles = Fplist_get (proplist, Qgnutls_bootprop_trustfiles);
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
359 keyfiles = Fplist_get (proplist, Qgnutls_bootprop_keyfiles);
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
360 callbacks = Fplist_get (proplist, Qgnutls_bootprop_callbacks);
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
361 loglevel = Fplist_get (proplist, Qgnutls_bootprop_loglevel);
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
362
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
363 state = XPROCESS (proc)->gnutls_state;
110648
256dd50b2a63 Make sure all reads/writes to gnutls streams go via the gnutls functions.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110636
diff changeset
364 XPROCESS (proc)->gnutls_p = 1;
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
365
110611
6c735824d0c1 Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110608
diff changeset
366 if (NUMBERP (loglevel))
6c735824d0c1 Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110608
diff changeset
367 {
6c735824d0c1 Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110608
diff changeset
368 gnutls_global_set_log_function (gnutls_log_function);
6c735824d0c1 Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110608
diff changeset
369 gnutls_global_set_log_level (XINT (loglevel));
6c735824d0c1 Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110608
diff changeset
370 max_log_level = XINT (loglevel);
6c735824d0c1 Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110608
diff changeset
371 XPROCESS (proc)->gnutls_log_level = max_log_level;
6c735824d0c1 Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110608
diff changeset
372 }
110648
256dd50b2a63 Make sure all reads/writes to gnutls streams go via the gnutls functions.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110636
diff changeset
373
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
374 /* always initialize globals. */
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
375 global_init = gnutls_emacs_global_init ();
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
376 if (! NILP (Fgnutls_errorp (global_init)))
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
377 return global_init;
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
378
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
379 /* deinit and free resources. */
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
380 if (GNUTLS_INITSTAGE (proc) >= GNUTLS_STAGE_CRED_ALLOC)
110652
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
381 {
110611
6c735824d0c1 Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110608
diff changeset
382 GNUTLS_LOG (1, max_log_level, "deallocating credentials");
6c735824d0c1 Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110608
diff changeset
383
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
384 if (EQ (type, Qgnutls_x509pki))
110652
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
385 {
110611
6c735824d0c1 Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110608
diff changeset
386 GNUTLS_LOG (2, max_log_level, "deallocating x509 credentials");
6c735824d0c1 Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110608
diff changeset
387 x509_cred = XPROCESS (proc)->gnutls_x509_cred;
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
388 gnutls_certificate_free_credentials (x509_cred);
110652
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
389 }
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
390 else if (EQ (type, Qgnutls_anon))
110652
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
391 {
110611
6c735824d0c1 Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110608
diff changeset
392 GNUTLS_LOG (2, max_log_level, "deallocating anon credentials");
6c735824d0c1 Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110608
diff changeset
393 anon_cred = XPROCESS (proc)->gnutls_anon_cred;
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
394 gnutls_anon_free_client_credentials (anon_cred);
110652
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
395 }
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
396 else
110652
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
397 {
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
398 error ("unknown credential type");
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
399 ret = GNUTLS_EMACS_ERROR_INVALID_TYPE;
110652
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
400 }
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
401
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
402 if (GNUTLS_INITSTAGE (proc) >= GNUTLS_STAGE_INIT)
110652
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
403 {
110611
6c735824d0c1 Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110608
diff changeset
404 GNUTLS_LOG (1, max_log_level, "deallocating x509 credentials");
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
405 Fgnutls_deinit (proc);
110652
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
406 }
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
407 }
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
408
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
409 GNUTLS_INITSTAGE (proc) = GNUTLS_STAGE_EMPTY;
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
410
110611
6c735824d0c1 Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110608
diff changeset
411 GNUTLS_LOG (1, max_log_level, "allocating credentials");
6c735824d0c1 Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110608
diff changeset
412
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
413 if (EQ (type, Qgnutls_x509pki))
110652
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
414 {
110611
6c735824d0c1 Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110608
diff changeset
415 GNUTLS_LOG (2, max_log_level, "allocating x509 credentials");
6c735824d0c1 Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110608
diff changeset
416 x509_cred = XPROCESS (proc)->gnutls_x509_cred;
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
417 if (gnutls_certificate_allocate_credentials (&x509_cred) < 0)
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
418 memory_full ();
110652
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
419 }
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
420 else if (EQ (type, Qgnutls_anon))
110652
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
421 {
110611
6c735824d0c1 Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110608
diff changeset
422 GNUTLS_LOG (2, max_log_level, "allocating anon credentials");
6c735824d0c1 Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110608
diff changeset
423 anon_cred = XPROCESS (proc)->gnutls_anon_cred;
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
424 if (gnutls_anon_allocate_client_credentials (&anon_cred) < 0)
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
425 memory_full ();
110652
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
426 }
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
427 else
110652
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
428 {
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
429 error ("unknown credential type");
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
430 ret = GNUTLS_EMACS_ERROR_INVALID_TYPE;
110652
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
431 }
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
432
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
433 if (ret < GNUTLS_E_SUCCESS)
110652
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
434 return gnutls_make_error (ret);
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
435
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
436 GNUTLS_INITSTAGE (proc) = GNUTLS_STAGE_CRED_ALLOC;
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
437
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
438 if (EQ (type, Qgnutls_x509pki))
110652
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
439 {
110745
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
440 for (tail = trustfiles; !NILP (tail); tail = Fcdr (tail))
110652
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
441 {
110745
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
442 Lisp_Object trustfile = Fcar (tail);
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
443 if (STRINGP (trustfile))
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
444 {
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
445 GNUTLS_LOG2 (1, max_log_level, "setting the trustfile: ",
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
446 SDATA (trustfile));
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
447 ret = gnutls_certificate_set_x509_trust_file
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
448 (x509_cred,
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
449 SDATA (trustfile),
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
450 file_format);
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
451
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
452 if (ret < GNUTLS_E_SUCCESS)
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
453 return gnutls_make_error (ret);
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
454 }
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
455 else
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
456 {
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
457 error ("Sorry, GnuTLS can't use non-string trustfile %s",
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
458 trustfile);
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
459 }
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
460 }
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
461
110745
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
462 for (tail = keyfiles; !NILP (tail); tail = Fcdr (tail))
110652
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
463 {
110745
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
464 Lisp_Object keyfile = Fcar (tail);
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
465 if (STRINGP (keyfile))
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
466 {
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
467 GNUTLS_LOG2 (1, max_log_level, "setting the keyfile: ",
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
468 SDATA (keyfile));
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
469 ret = gnutls_certificate_set_x509_crl_file
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
470 (x509_cred,
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
471 SDATA (keyfile),
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
472 file_format);
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
473
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
474 if (ret < GNUTLS_E_SUCCESS)
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
475 return gnutls_make_error (ret);
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
476 }
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
477 else
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
478 {
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
479 error ("Sorry, GnuTLS can't use non-string keyfile %s",
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
480 keyfile);
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
481 }
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
482 }
110652
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
483 }
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
484
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
485 GNUTLS_INITSTAGE (proc) = GNUTLS_STAGE_FILES;
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
486
110611
6c735824d0c1 Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110608
diff changeset
487 GNUTLS_LOG (1, max_log_level, "gnutls_init");
6c735824d0c1 Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110608
diff changeset
488
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
489 ret = gnutls_init (&state, GNUTLS_CLIENT);
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
490
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
491 if (ret < GNUTLS_E_SUCCESS)
110652
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
492 return gnutls_make_error (ret);
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
493
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
494 XPROCESS (proc)->gnutls_state = state;
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
495
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
496 GNUTLS_INITSTAGE (proc) = GNUTLS_STAGE_INIT;
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
497
110745
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
498 if (STRINGP (priority_string))
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
499 {
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
500 priority_string_ptr = (char*) SDATA (priority_string);
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
501 GNUTLS_LOG2 (1, max_log_level, "got non-default priority string:",
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
502 priority_string_ptr);
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
503 }
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
504 else
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
505 {
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
506 GNUTLS_LOG2 (1, max_log_level, "using default priority string:",
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
507 priority_string_ptr);
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
508 }
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
509
110611
6c735824d0c1 Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110608
diff changeset
510 GNUTLS_LOG (1, max_log_level, "setting the priority string");
6c735824d0c1 Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110608
diff changeset
511
110724
3ccf1931ae33 src/gnutls.c: Doc fixes. Make some functions static.
Juanma Barranquero <lekktu@gmail.com>
parents: 110652
diff changeset
512 ret = gnutls_priority_set_direct (state,
110745
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
513 priority_string_ptr,
110724
3ccf1931ae33 src/gnutls.c: Doc fixes. Make some functions static.
Juanma Barranquero <lekktu@gmail.com>
parents: 110652
diff changeset
514 NULL);
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
515
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
516 if (ret < GNUTLS_E_SUCCESS)
110652
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
517 return gnutls_make_error (ret);
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
518
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
519 GNUTLS_INITSTAGE (proc) = GNUTLS_STAGE_PRIORITY;
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
520
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
521 if (EQ (type, Qgnutls_x509pki))
110652
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
522 {
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
523 ret = gnutls_cred_set (state, GNUTLS_CRD_CERTIFICATE, x509_cred);
110652
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
524 }
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
525 else if (EQ (type, Qgnutls_anon))
110652
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
526 {
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
527 ret = gnutls_cred_set (state, GNUTLS_CRD_ANON, anon_cred);
110652
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
528 }
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
529 else
110652
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
530 {
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
531 error ("unknown credential type");
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
532 ret = GNUTLS_EMACS_ERROR_INVALID_TYPE;
110652
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
533 }
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
534
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
535 if (ret < GNUTLS_E_SUCCESS)
110652
056ce44cedcd Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110649
diff changeset
536 return gnutls_make_error (ret);
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
537
110611
6c735824d0c1 Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110608
diff changeset
538 XPROCESS (proc)->gnutls_anon_cred = anon_cred;
6c735824d0c1 Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110608
diff changeset
539 XPROCESS (proc)->gnutls_x509_cred = x509_cred;
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
540 XPROCESS (proc)->gnutls_cred_type = type;
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
541
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
542 GNUTLS_INITSTAGE (proc) = GNUTLS_STAGE_CRED_SET;
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
543
110649
2f0d755fa21b Do the gnutls handshake from the reader loop, instead of looping over
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110648
diff changeset
544 emacs_gnutls_handshake (XPROCESS (proc));
2f0d755fa21b Do the gnutls handshake from the reader loop, instead of looping over
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110648
diff changeset
545
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
546 return gnutls_make_error (GNUTLS_E_SUCCESS);
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
547 }
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
548
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
549 DEFUN ("gnutls-bye", Fgnutls_bye,
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
550 Sgnutls_bye, 2, 2, 0,
110724
3ccf1931ae33 src/gnutls.c: Doc fixes. Make some functions static.
Juanma Barranquero <lekktu@gmail.com>
parents: 110652
diff changeset
551 doc: /* Terminate current GnuTLS connection for process PROC.
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
552 The connection should have been initiated using `gnutls-handshake'.
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
553
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
554 If CONT is not nil the TLS connection gets terminated and further
110724
3ccf1931ae33 src/gnutls.c: Doc fixes. Make some functions static.
Juanma Barranquero <lekktu@gmail.com>
parents: 110652
diff changeset
555 receives and sends will be disallowed. If the return value is zero you
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
556 may continue using the connection. If CONT is nil, GnuTLS actually
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
557 sends an alert containing a close request and waits for the peer to
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
558 reply with the same message. In order to reuse the connection you
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
559 should wait for an EOF from the peer.
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
560
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
561 This function may also return `gnutls-e-again', or
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
562 `gnutls-e-interrupted'. */)
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
563 (Lisp_Object proc, Lisp_Object cont)
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
564 {
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
565 gnutls_session_t state;
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
566 int ret;
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
567
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
568 CHECK_PROCESS (proc);
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
569
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
570 state = XPROCESS (proc)->gnutls_state;
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
571
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
572 ret = gnutls_bye (state,
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
573 NILP (cont) ? GNUTLS_SHUT_RDWR : GNUTLS_SHUT_WR);
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
574
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
575 return gnutls_make_error (ret);
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
576 }
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
577
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
578 void
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
579 syms_of_gnutls (void)
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
580 {
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
581 global_initialized = 0;
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
582
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
583 Qgnutls_code = intern_c_string ("gnutls-code");
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
584 staticpro (&Qgnutls_code);
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
585
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
586 Qgnutls_anon = intern_c_string ("gnutls-anon");
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
587 staticpro (&Qgnutls_anon);
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
588
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
589 Qgnutls_x509pki = intern_c_string ("gnutls-x509pki");
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
590 staticpro (&Qgnutls_x509pki);
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
591
110875
bb9bf961ba7b Make emacs_gnutls_read() return the expected on errors.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110745
diff changeset
592 Qgnutls_bootprop_priority = intern_c_string (":priority");
110745
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
593 staticpro (&Qgnutls_bootprop_priority);
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
594
110875
bb9bf961ba7b Make emacs_gnutls_read() return the expected on errors.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110745
diff changeset
595 Qgnutls_bootprop_trustfiles = intern_c_string (":trustfiles");
110745
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
596 staticpro (&Qgnutls_bootprop_trustfiles);
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
597
110875
bb9bf961ba7b Make emacs_gnutls_read() return the expected on errors.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110745
diff changeset
598 Qgnutls_bootprop_keyfiles = intern_c_string (":keyfiles");
110745
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
599 staticpro (&Qgnutls_bootprop_keyfiles);
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
600
110875
bb9bf961ba7b Make emacs_gnutls_read() return the expected on errors.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110745
diff changeset
601 Qgnutls_bootprop_callbacks = intern_c_string (":callbacks");
110745
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
602 staticpro (&Qgnutls_bootprop_callbacks);
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
603
110875
bb9bf961ba7b Make emacs_gnutls_read() return the expected on errors.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110745
diff changeset
604 Qgnutls_bootprop_loglevel = intern_c_string (":loglevel");
110745
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
605 staticpro (&Qgnutls_bootprop_loglevel);
af2db97ca17a Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110728
diff changeset
606
110584
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
607 Qgnutls_e_interrupted = intern_c_string ("gnutls-e-interrupted");
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
608 staticpro (&Qgnutls_e_interrupted);
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
609 Fput (Qgnutls_e_interrupted, Qgnutls_code,
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
610 make_number (GNUTLS_E_INTERRUPTED));
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
611
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
612 Qgnutls_e_again = intern_c_string ("gnutls-e-again");
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
613 staticpro (&Qgnutls_e_again);
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
614 Fput (Qgnutls_e_again, Qgnutls_code,
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
615 make_number (GNUTLS_E_AGAIN));
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
616
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
617 Qgnutls_e_invalid_session = intern_c_string ("gnutls-e-invalid-session");
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
618 staticpro (&Qgnutls_e_invalid_session);
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
619 Fput (Qgnutls_e_invalid_session, Qgnutls_code,
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
620 make_number (GNUTLS_E_INVALID_SESSION));
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
621
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
622 Qgnutls_e_not_ready_for_handshake =
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
623 intern_c_string ("gnutls-e-not-ready-for-handshake");
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
624 staticpro (&Qgnutls_e_not_ready_for_handshake);
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
625 Fput (Qgnutls_e_not_ready_for_handshake, Qgnutls_code,
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
626 make_number (GNUTLS_E_APPLICATION_ERROR_MIN));
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
627
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
628 defsubr (&Sgnutls_get_initstage);
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
629 defsubr (&Sgnutls_errorp);
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
630 defsubr (&Sgnutls_error_fatalp);
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
631 defsubr (&Sgnutls_error_string);
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
632 defsubr (&Sgnutls_boot);
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
633 defsubr (&Sgnutls_deinit);
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
634 defsubr (&Sgnutls_bye);
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
635 }
9d94d76ce611 Set up GnuTLS support.
Ted Zlatanov <tzz@lifelogs.com>
parents:
diff changeset
636 #endif