Mercurial > emacs
annotate src/gnutls.c @ 111002:62243368de05
shr.el (shr-insert): Remove space inserted before or after a breakable character or at the beginning or the end of a line.
shr.el (shr-find-fill-point): Do kinsoku; find the second best point or give it up if there's no breakable point.
author | Katsumi Yamaoka <yamaoka@jpl.org> |
---|---|
date | Fri, 15 Oct 2010 08:10:56 +0000 |
parents | 1ccdcdef34fc |
children | 54ea07fb88fc |
rev | line source |
---|---|
110584 | 1 /* GnuTLS glue for GNU Emacs. |
2 Copyright (C) 2010 Free Software Foundation, Inc. | |
3 | |
4 This file is part of GNU Emacs. | |
5 | |
6 GNU Emacs is free software: you can redistribute it and/or modify | |
7 it under the terms of the GNU General Public License as published by | |
8 the Free Software Foundation, either version 3 of the License, or | |
9 (at your option) any later version. | |
10 | |
11 GNU Emacs is distributed in the hope that it will be useful, | |
12 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 GNU General Public License for more details. | |
15 | |
16 You should have received a copy of the GNU General Public License | |
17 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |
18 | |
19 #include <config.h> | |
20 #include <errno.h> | |
21 #include <setjmp.h> | |
22 | |
23 #include "lisp.h" | |
24 #include "process.h" | |
25 | |
26 #ifdef HAVE_GNUTLS | |
27 #include <gnutls/gnutls.h> | |
28 | |
29 Lisp_Object Qgnutls_code; | |
30 Lisp_Object Qgnutls_anon, Qgnutls_x509pki; | |
31 Lisp_Object Qgnutls_e_interrupted, Qgnutls_e_again, | |
32 Qgnutls_e_invalid_session, Qgnutls_e_not_ready_for_handshake; | |
33 int global_initialized; | |
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 | 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 | 75 unsigned int nbyte) |
76 { | |
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 | 89 |
90 bytes_written = 0; | |
91 | |
92 while (nbyte > 0) | |
93 { | |
94 rtnval = gnutls_write (state, buf, nbyte); | |
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 | 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 | 99 continue; |
100 else | |
101 return (bytes_written ? bytes_written : -1); | |
102 } | |
103 | |
104 buf += rtnval; | |
105 nbyte -= rtnval; | |
106 bytes_written += rtnval; | |
107 } | |
108 | |
109 return (bytes_written); | |
110 } | |
111 | |
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 | 114 unsigned int nbyte) |
115 { | |
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 | 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; |
06497cf3e920
(emacs_gnutls_read): Don't infloop while reading.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110606
diff
changeset
|
128 else |
110875
bb9bf961ba7b
Make emacs_gnutls_read() return the expected on errors.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110745
diff
changeset
|
129 return -1; |
110584 | 130 } |
131 | |
132 /* convert an integer error to a Lisp_Object; it will be either a | |
133 known symbol like `gnutls_e_interrupted' and `gnutls_e_again' or | |
134 simply the integer value of the error. GNUTLS_E_SUCCESS is mapped | |
135 to Qt. */ | |
110724
3ccf1931ae33
src/gnutls.c: Doc fixes. Make some functions static.
Juanma Barranquero <lekktu@gmail.com>
parents:
110652
diff
changeset
|
136 static Lisp_Object |
3ccf1931ae33
src/gnutls.c: Doc fixes. Make some functions static.
Juanma Barranquero <lekktu@gmail.com>
parents:
110652
diff
changeset
|
137 gnutls_make_error (int error) |
110584 | 138 { |
139 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
|
140 { |
056ce44cedcd
Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110649
diff
changeset
|
141 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
|
142 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
|
143 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
|
144 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
|
145 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
|
146 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
|
147 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
|
148 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
|
149 } |
110584 | 150 |
151 return make_number (error); | |
152 } | |
153 | |
154 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
|
155 doc: /* Return the GnuTLS init stage of process PROC. |
110584 | 156 See also `gnutls-boot'. */) |
110724
3ccf1931ae33
src/gnutls.c: Doc fixes. Make some functions static.
Juanma Barranquero <lekktu@gmail.com>
parents:
110652
diff
changeset
|
157 (Lisp_Object proc) |
110584 | 158 { |
159 CHECK_PROCESS (proc); | |
160 | |
161 return make_number (GNUTLS_INITSTAGE (proc)); | |
162 } | |
163 | |
164 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
|
165 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
|
166 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
|
167 usage: (gnutls-errorp ERROR) */) |
3ccf1931ae33
src/gnutls.c: Doc fixes. Make some functions static.
Juanma Barranquero <lekktu@gmail.com>
parents:
110652
diff
changeset
|
168 (Lisp_Object err) |
110584 | 169 { |
110724
3ccf1931ae33
src/gnutls.c: Doc fixes. Make some functions static.
Juanma Barranquero <lekktu@gmail.com>
parents:
110652
diff
changeset
|
170 if (EQ (err, Qt)) return Qnil; |
110584 | 171 |
172 return Qt; | |
173 } | |
174 | |
175 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
|
176 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
|
177 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
|
178 usage: (gnutls-error-fatalp ERROR) */) |
3ccf1931ae33
src/gnutls.c: Doc fixes. Make some functions static.
Juanma Barranquero <lekktu@gmail.com>
parents:
110652
diff
changeset
|
179 (Lisp_Object err) |
110584 | 180 { |
181 Lisp_Object code; | |
182 | |
183 if (EQ (err, Qt)) return Qnil; | |
184 | |
185 if (SYMBOLP (err)) | |
186 { | |
110652
056ce44cedcd
Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110649
diff
changeset
|
187 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
|
188 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
|
189 { |
056ce44cedcd
Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110649
diff
changeset
|
190 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
|
191 } |
056ce44cedcd
Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110649
diff
changeset
|
192 else |
056ce44cedcd
Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110649
diff
changeset
|
193 { |
056ce44cedcd
Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110649
diff
changeset
|
194 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
|
195 } |
110584 | 196 } |
197 | |
198 if (!NUMBERP (err)) | |
199 error ("Not an error symbol or code"); | |
200 | |
201 if (0 == gnutls_error_is_fatal (XINT (err))) | |
202 return Qnil; | |
203 | |
204 return Qt; | |
205 } | |
206 | |
207 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
|
208 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
|
209 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
|
210 usage: (gnutls-error-string ERROR) */) |
3ccf1931ae33
src/gnutls.c: Doc fixes. Make some functions static.
Juanma Barranquero <lekktu@gmail.com>
parents:
110652
diff
changeset
|
211 (Lisp_Object err) |
110584 | 212 { |
213 Lisp_Object code; | |
214 | |
215 if (EQ (err, Qt)) return build_string ("Not an error"); | |
216 | |
217 if (SYMBOLP (err)) | |
218 { | |
110652
056ce44cedcd
Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110649
diff
changeset
|
219 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
|
220 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
|
221 { |
056ce44cedcd
Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110649
diff
changeset
|
222 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
|
223 } |
056ce44cedcd
Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110649
diff
changeset
|
224 else |
056ce44cedcd
Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110649
diff
changeset
|
225 { |
056ce44cedcd
Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110649
diff
changeset
|
226 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
|
227 } |
110584 | 228 } |
229 | |
230 if (!NUMBERP (err)) | |
231 return build_string ("Not an error symbol or code"); | |
232 | |
233 return build_string (gnutls_strerror (XINT (err))); | |
234 } | |
235 | |
236 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
|
237 doc: /* Deallocate GnuTLS resources associated with process PROC. |
110584 | 238 See also `gnutls-init'. */) |
110724
3ccf1931ae33
src/gnutls.c: Doc fixes. Make some functions static.
Juanma Barranquero <lekktu@gmail.com>
parents:
110652
diff
changeset
|
239 (Lisp_Object proc) |
110584 | 240 { |
241 gnutls_session_t state; | |
242 | |
243 CHECK_PROCESS (proc); | |
244 state = XPROCESS (proc)->gnutls_state; | |
245 | |
246 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
|
247 { |
110584 | 248 gnutls_deinit (state); |
249 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
|
250 } |
110584 | 251 |
252 return Qt; | |
253 } | |
254 | |
110728
ab7396ada96a
src/gnutls.c: Fix typo in docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
110724
diff
changeset
|
255 /* Initializes global GnuTLS state to defaults. |
ab7396ada96a
src/gnutls.c: Fix typo in docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
110724
diff
changeset
|
256 Call `gnutls-global-deinit' when GnuTLS usage is no longer needed. |
110584 | 257 Returns zero on success. */ |
110724
3ccf1931ae33
src/gnutls.c: Doc fixes. Make some functions static.
Juanma Barranquero <lekktu@gmail.com>
parents:
110652
diff
changeset
|
258 static Lisp_Object |
3ccf1931ae33
src/gnutls.c: Doc fixes. Make some functions static.
Juanma Barranquero <lekktu@gmail.com>
parents:
110652
diff
changeset
|
259 gnutls_emacs_global_init (void) |
110584 | 260 { |
261 int ret = GNUTLS_E_SUCCESS; | |
262 | |
263 if (!global_initialized) | |
264 ret = gnutls_global_init (); | |
265 | |
266 global_initialized = 1; | |
267 | |
268 return gnutls_make_error (ret); | |
269 } | |
270 | |
110728
ab7396ada96a
src/gnutls.c: Fix typo in docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
110724
diff
changeset
|
271 /* Deinitializes global GnuTLS state. |
110584 | 272 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
|
273 static Lisp_Object |
3ccf1931ae33
src/gnutls.c: Doc fixes. Make some functions static.
Juanma Barranquero <lekktu@gmail.com>
parents:
110652
diff
changeset
|
274 gnutls_emacs_global_deinit (void) |
110584 | 275 { |
276 if (global_initialized) | |
277 gnutls_global_deinit (); | |
278 | |
279 global_initialized = 0; | |
280 | |
281 return gnutls_make_error (GNUTLS_E_SUCCESS); | |
282 } | |
283 | |
110724
3ccf1931ae33
src/gnutls.c: Doc fixes. Make some functions static.
Juanma Barranquero <lekktu@gmail.com>
parents:
110652
diff
changeset
|
284 static void |
3ccf1931ae33
src/gnutls.c: Doc fixes. Make some functions static.
Juanma Barranquero <lekktu@gmail.com>
parents:
110652
diff
changeset
|
285 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
|
286 { |
110724
3ccf1931ae33
src/gnutls.c: Doc fixes. Make some functions static.
Juanma Barranquero <lekktu@gmail.com>
parents:
110652
diff
changeset
|
287 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
|
288 } |
b4f4c3e9b976
Add debugging to the gnutls library, and finish handshaking when it's done.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110584
diff
changeset
|
289 |
110745
af2db97ca17a
Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110728
diff
changeset
|
290 static void |
af2db97ca17a
Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110728
diff
changeset
|
291 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
|
292 { |
af2db97ca17a
Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110728
diff
changeset
|
293 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
|
294 } |
af2db97ca17a
Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110728
diff
changeset
|
295 |
af2db97ca17a
Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110728
diff
changeset
|
296 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
|
297 doc: /* Initialize GnuTLS client for process PROC with TYPE+PROPLIST. |
110584 | 298 Currently only client mode is supported. Returns a success/failure |
299 value you can check with `gnutls-errorp'. | |
300 | |
110745
af2db97ca17a
Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110728
diff
changeset
|
301 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
|
302 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
|
303 |
110745
af2db97ca17a
Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110728
diff
changeset
|
304 :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
|
305 :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
|
306 :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
|
307 :callbacks is an alist of callback functions (TODO). |
af2db97ca17a
Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110728
diff
changeset
|
308 :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
|
309 |
af2db97ca17a
Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110728
diff
changeset
|
310 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
|
311 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
|
312 debugging. |
110584 | 313 |
314 Note that the priority is set on the client. The server does not use | |
315 the protocols's priority except for disabling protocols that were not | |
316 specified. | |
317 | |
110724
3ccf1931ae33
src/gnutls.c: Doc fixes. Make some functions static.
Juanma Barranquero <lekktu@gmail.com>
parents:
110652
diff
changeset
|
318 Processes must be initialized with this function before other GnuTLS |
110584 | 319 functions are used. This function allocates resources which can only |
320 be deallocated by calling `gnutls-deinit' or by calling it again. | |
321 | |
322 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
|
323 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
|
324 one trustfile (usually a CA bundle). */) |
af2db97ca17a
Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110728
diff
changeset
|
325 (Lisp_Object proc, Lisp_Object type, Lisp_Object proplist) |
110584 | 326 { |
327 int ret = GNUTLS_E_SUCCESS; | |
328 | |
110611
6c735824d0c1
Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110608
diff
changeset
|
329 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
|
330 |
110584 | 331 /* TODO: GNUTLS_X509_FMT_DER is also an option. */ |
332 int file_format = GNUTLS_X509_FMT_PEM; | |
333 | |
334 gnutls_session_t state; | |
335 gnutls_certificate_credentials_t x509_cred; | |
336 gnutls_anon_client_credentials_t anon_cred; | |
337 Lisp_Object global_init; | |
110745
af2db97ca17a
Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110728
diff
changeset
|
338 char* priority_string_ptr = "NORMAL"; /* default priority string. */ |
af2db97ca17a
Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110728
diff
changeset
|
339 Lisp_Object tail; |
af2db97ca17a
Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110728
diff
changeset
|
340 |
af2db97ca17a
Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110728
diff
changeset
|
341 /* Placeholders for the property list elements. */ |
af2db97ca17a
Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110728
diff
changeset
|
342 Lisp_Object priority_string; |
af2db97ca17a
Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110728
diff
changeset
|
343 Lisp_Object trustfiles; |
af2db97ca17a
Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110728
diff
changeset
|
344 Lisp_Object keyfiles; |
af2db97ca17a
Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110728
diff
changeset
|
345 Lisp_Object callbacks; |
af2db97ca17a
Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110728
diff
changeset
|
346 Lisp_Object loglevel; |
110584 | 347 |
348 CHECK_PROCESS (proc); | |
349 CHECK_SYMBOL (type); | |
110745
af2db97ca17a
Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110728
diff
changeset
|
350 CHECK_LIST (proplist); |
af2db97ca17a
Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110728
diff
changeset
|
351 |
af2db97ca17a
Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110728
diff
changeset
|
352 priority_string = Fplist_get (proplist, Qgnutls_bootprop_priority); |
af2db97ca17a
Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110728
diff
changeset
|
353 trustfiles = Fplist_get (proplist, Qgnutls_bootprop_trustfiles); |
af2db97ca17a
Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110728
diff
changeset
|
354 keyfiles = Fplist_get (proplist, Qgnutls_bootprop_keyfiles); |
af2db97ca17a
Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110728
diff
changeset
|
355 callbacks = Fplist_get (proplist, Qgnutls_bootprop_callbacks); |
af2db97ca17a
Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110728
diff
changeset
|
356 loglevel = Fplist_get (proplist, Qgnutls_bootprop_loglevel); |
110584 | 357 |
358 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
|
359 XPROCESS (proc)->gnutls_p = 1; |
110584 | 360 |
110611
6c735824d0c1
Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110608
diff
changeset
|
361 if (NUMBERP (loglevel)) |
6c735824d0c1
Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110608
diff
changeset
|
362 { |
6c735824d0c1
Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110608
diff
changeset
|
363 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
|
364 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
|
365 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
|
366 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
|
367 } |
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
|
368 |
110584 | 369 /* always initialize globals. */ |
370 global_init = gnutls_emacs_global_init (); | |
371 if (! NILP (Fgnutls_errorp (global_init))) | |
372 return global_init; | |
373 | |
374 /* deinit and free resources. */ | |
375 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
|
376 { |
110611
6c735824d0c1
Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110608
diff
changeset
|
377 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
|
378 |
110584 | 379 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
|
380 { |
110611
6c735824d0c1
Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110608
diff
changeset
|
381 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
|
382 x509_cred = XPROCESS (proc)->gnutls_x509_cred; |
110584 | 383 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
|
384 } |
110584 | 385 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
|
386 { |
110611
6c735824d0c1
Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110608
diff
changeset
|
387 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
|
388 anon_cred = XPROCESS (proc)->gnutls_anon_cred; |
110584 | 389 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
|
390 } |
110584 | 391 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
|
392 { |
110584 | 393 error ("unknown credential type"); |
394 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
|
395 } |
110584 | 396 |
397 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
|
398 { |
110611
6c735824d0c1
Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110608
diff
changeset
|
399 GNUTLS_LOG (1, max_log_level, "deallocating x509 credentials"); |
110584 | 400 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
|
401 } |
056ce44cedcd
Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110649
diff
changeset
|
402 } |
110584 | 403 |
404 GNUTLS_INITSTAGE (proc) = GNUTLS_STAGE_EMPTY; | |
405 | |
110611
6c735824d0c1
Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110608
diff
changeset
|
406 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
|
407 |
110584 | 408 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
|
409 { |
110611
6c735824d0c1
Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110608
diff
changeset
|
410 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
|
411 x509_cred = XPROCESS (proc)->gnutls_x509_cred; |
110584 | 412 if (gnutls_certificate_allocate_credentials (&x509_cred) < 0) |
413 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
|
414 } |
110584 | 415 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
|
416 { |
110611
6c735824d0c1
Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110608
diff
changeset
|
417 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
|
418 anon_cred = XPROCESS (proc)->gnutls_anon_cred; |
110584 | 419 if (gnutls_anon_allocate_client_credentials (&anon_cred) < 0) |
420 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
|
421 } |
110584 | 422 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
|
423 { |
110584 | 424 error ("unknown credential type"); |
425 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
|
426 } |
110584 | 427 |
428 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
|
429 return gnutls_make_error (ret); |
110584 | 430 |
431 GNUTLS_INITSTAGE (proc) = GNUTLS_STAGE_CRED_ALLOC; | |
432 | |
433 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
|
434 { |
110745
af2db97ca17a
Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110728
diff
changeset
|
435 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
|
436 { |
110745
af2db97ca17a
Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110728
diff
changeset
|
437 Lisp_Object trustfile = Fcar (tail); |
af2db97ca17a
Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110728
diff
changeset
|
438 if (STRINGP (trustfile)) |
af2db97ca17a
Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110728
diff
changeset
|
439 { |
af2db97ca17a
Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110728
diff
changeset
|
440 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
|
441 SDATA (trustfile)); |
af2db97ca17a
Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110728
diff
changeset
|
442 ret = gnutls_certificate_set_x509_trust_file |
af2db97ca17a
Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110728
diff
changeset
|
443 (x509_cred, |
af2db97ca17a
Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110728
diff
changeset
|
444 SDATA (trustfile), |
af2db97ca17a
Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110728
diff
changeset
|
445 file_format); |
af2db97ca17a
Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110728
diff
changeset
|
446 |
af2db97ca17a
Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110728
diff
changeset
|
447 if (ret < GNUTLS_E_SUCCESS) |
af2db97ca17a
Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110728
diff
changeset
|
448 return gnutls_make_error (ret); |
af2db97ca17a
Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110728
diff
changeset
|
449 } |
af2db97ca17a
Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110728
diff
changeset
|
450 else |
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 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
|
453 trustfile); |
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 } |
110584 | 456 |
110745
af2db97ca17a
Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110728
diff
changeset
|
457 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
|
458 { |
110745
af2db97ca17a
Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110728
diff
changeset
|
459 Lisp_Object keyfile = Fcar (tail); |
af2db97ca17a
Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110728
diff
changeset
|
460 if (STRINGP (keyfile)) |
af2db97ca17a
Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110728
diff
changeset
|
461 { |
af2db97ca17a
Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110728
diff
changeset
|
462 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
|
463 SDATA (keyfile)); |
af2db97ca17a
Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110728
diff
changeset
|
464 ret = gnutls_certificate_set_x509_crl_file |
af2db97ca17a
Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110728
diff
changeset
|
465 (x509_cred, |
af2db97ca17a
Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110728
diff
changeset
|
466 SDATA (keyfile), |
af2db97ca17a
Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110728
diff
changeset
|
467 file_format); |
af2db97ca17a
Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110728
diff
changeset
|
468 |
af2db97ca17a
Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110728
diff
changeset
|
469 if (ret < GNUTLS_E_SUCCESS) |
af2db97ca17a
Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110728
diff
changeset
|
470 return gnutls_make_error (ret); |
af2db97ca17a
Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110728
diff
changeset
|
471 } |
af2db97ca17a
Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110728
diff
changeset
|
472 else |
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 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
|
475 keyfile); |
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 } |
110652
056ce44cedcd
Clean up gnutls.c coding style to conform with the Emacs style.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110649
diff
changeset
|
478 } |
110584 | 479 |
480 GNUTLS_INITSTAGE (proc) = GNUTLS_STAGE_FILES; | |
481 | |
110611
6c735824d0c1
Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110608
diff
changeset
|
482 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
|
483 |
110584 | 484 ret = gnutls_init (&state, GNUTLS_CLIENT); |
485 | |
486 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
|
487 return gnutls_make_error (ret); |
110584 | 488 |
489 XPROCESS (proc)->gnutls_state = state; | |
490 | |
491 GNUTLS_INITSTAGE (proc) = GNUTLS_STAGE_INIT; | |
492 | |
110745
af2db97ca17a
Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110728
diff
changeset
|
493 if (STRINGP (priority_string)) |
af2db97ca17a
Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110728
diff
changeset
|
494 { |
af2db97ca17a
Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110728
diff
changeset
|
495 priority_string_ptr = (char*) SDATA (priority_string); |
af2db97ca17a
Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110728
diff
changeset
|
496 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
|
497 priority_string_ptr); |
af2db97ca17a
Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110728
diff
changeset
|
498 } |
af2db97ca17a
Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110728
diff
changeset
|
499 else |
af2db97ca17a
Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110728
diff
changeset
|
500 { |
af2db97ca17a
Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110728
diff
changeset
|
501 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
|
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 |
110611
6c735824d0c1
Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110608
diff
changeset
|
505 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
|
506 |
110724
3ccf1931ae33
src/gnutls.c: Doc fixes. Make some functions static.
Juanma Barranquero <lekktu@gmail.com>
parents:
110652
diff
changeset
|
507 ret = gnutls_priority_set_direct (state, |
110745
af2db97ca17a
Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110728
diff
changeset
|
508 priority_string_ptr, |
110724
3ccf1931ae33
src/gnutls.c: Doc fixes. Make some functions static.
Juanma Barranquero <lekktu@gmail.com>
parents:
110652
diff
changeset
|
509 NULL); |
110584 | 510 |
511 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
|
512 return gnutls_make_error (ret); |
110584 | 513 |
514 GNUTLS_INITSTAGE (proc) = GNUTLS_STAGE_PRIORITY; | |
515 | |
516 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
|
517 { |
110584 | 518 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
|
519 } |
110584 | 520 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
|
521 { |
110584 | 522 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
|
523 } |
110584 | 524 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
|
525 { |
110584 | 526 error ("unknown credential type"); |
527 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
|
528 } |
110584 | 529 |
530 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
|
531 return gnutls_make_error (ret); |
110584 | 532 |
110611
6c735824d0c1
Add gnutls logging and clean up various gnutls bits.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110608
diff
changeset
|
533 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
|
534 XPROCESS (proc)->gnutls_x509_cred = x509_cred; |
110584 | 535 XPROCESS (proc)->gnutls_cred_type = type; |
536 | |
537 GNUTLS_INITSTAGE (proc) = GNUTLS_STAGE_CRED_SET; | |
538 | |
110649
2f0d755fa21b
Do the gnutls handshake from the reader loop, instead of looping over
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110648
diff
changeset
|
539 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
|
540 |
110584 | 541 return gnutls_make_error (GNUTLS_E_SUCCESS); |
542 } | |
543 | |
544 DEFUN ("gnutls-bye", Fgnutls_bye, | |
545 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
|
546 doc: /* Terminate current GnuTLS connection for process PROC. |
110584 | 547 The connection should have been initiated using `gnutls-handshake'. |
548 | |
549 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
|
550 receives and sends will be disallowed. If the return value is zero you |
110584 | 551 may continue using the connection. If CONT is nil, GnuTLS actually |
552 sends an alert containing a close request and waits for the peer to | |
553 reply with the same message. In order to reuse the connection you | |
554 should wait for an EOF from the peer. | |
555 | |
556 This function may also return `gnutls-e-again', or | |
557 `gnutls-e-interrupted'. */) | |
558 (Lisp_Object proc, Lisp_Object cont) | |
559 { | |
560 gnutls_session_t state; | |
561 int ret; | |
562 | |
563 CHECK_PROCESS (proc); | |
564 | |
565 state = XPROCESS (proc)->gnutls_state; | |
566 | |
567 ret = gnutls_bye (state, | |
568 NILP (cont) ? GNUTLS_SHUT_RDWR : GNUTLS_SHUT_WR); | |
569 | |
570 return gnutls_make_error (ret); | |
571 } | |
572 | |
573 void | |
574 syms_of_gnutls (void) | |
575 { | |
576 global_initialized = 0; | |
577 | |
578 Qgnutls_code = intern_c_string ("gnutls-code"); | |
579 staticpro (&Qgnutls_code); | |
580 | |
581 Qgnutls_anon = intern_c_string ("gnutls-anon"); | |
582 staticpro (&Qgnutls_anon); | |
583 | |
584 Qgnutls_x509pki = intern_c_string ("gnutls-x509pki"); | |
585 staticpro (&Qgnutls_x509pki); | |
586 | |
110875
bb9bf961ba7b
Make emacs_gnutls_read() return the expected on errors.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110745
diff
changeset
|
587 Qgnutls_bootprop_priority = intern_c_string (":priority"); |
110745
af2db97ca17a
Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110728
diff
changeset
|
588 staticpro (&Qgnutls_bootprop_priority); |
af2db97ca17a
Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110728
diff
changeset
|
589 |
110875
bb9bf961ba7b
Make emacs_gnutls_read() return the expected on errors.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110745
diff
changeset
|
590 Qgnutls_bootprop_trustfiles = intern_c_string (":trustfiles"); |
110745
af2db97ca17a
Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110728
diff
changeset
|
591 staticpro (&Qgnutls_bootprop_trustfiles); |
af2db97ca17a
Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110728
diff
changeset
|
592 |
110875
bb9bf961ba7b
Make emacs_gnutls_read() return the expected on errors.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110745
diff
changeset
|
593 Qgnutls_bootprop_keyfiles = intern_c_string (":keyfiles"); |
110745
af2db97ca17a
Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110728
diff
changeset
|
594 staticpro (&Qgnutls_bootprop_keyfiles); |
af2db97ca17a
Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110728
diff
changeset
|
595 |
110875
bb9bf961ba7b
Make emacs_gnutls_read() return the expected on errors.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110745
diff
changeset
|
596 Qgnutls_bootprop_callbacks = intern_c_string (":callbacks"); |
110745
af2db97ca17a
Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110728
diff
changeset
|
597 staticpro (&Qgnutls_bootprop_callbacks); |
af2db97ca17a
Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110728
diff
changeset
|
598 |
110875
bb9bf961ba7b
Make emacs_gnutls_read() return the expected on errors.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110745
diff
changeset
|
599 Qgnutls_bootprop_loglevel = intern_c_string (":loglevel"); |
110745
af2db97ca17a
Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110728
diff
changeset
|
600 staticpro (&Qgnutls_bootprop_loglevel); |
af2db97ca17a
Rework the gnutls boot interface.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
110728
diff
changeset
|
601 |
110584 | 602 Qgnutls_e_interrupted = intern_c_string ("gnutls-e-interrupted"); |
603 staticpro (&Qgnutls_e_interrupted); | |
604 Fput (Qgnutls_e_interrupted, Qgnutls_code, | |
605 make_number (GNUTLS_E_INTERRUPTED)); | |
606 | |
607 Qgnutls_e_again = intern_c_string ("gnutls-e-again"); | |
608 staticpro (&Qgnutls_e_again); | |
609 Fput (Qgnutls_e_again, Qgnutls_code, | |
610 make_number (GNUTLS_E_AGAIN)); | |
611 | |
612 Qgnutls_e_invalid_session = intern_c_string ("gnutls-e-invalid-session"); | |
613 staticpro (&Qgnutls_e_invalid_session); | |
614 Fput (Qgnutls_e_invalid_session, Qgnutls_code, | |
615 make_number (GNUTLS_E_INVALID_SESSION)); | |
616 | |
617 Qgnutls_e_not_ready_for_handshake = | |
618 intern_c_string ("gnutls-e-not-ready-for-handshake"); | |
619 staticpro (&Qgnutls_e_not_ready_for_handshake); | |
620 Fput (Qgnutls_e_not_ready_for_handshake, Qgnutls_code, | |
621 make_number (GNUTLS_E_APPLICATION_ERROR_MIN)); | |
622 | |
623 defsubr (&Sgnutls_get_initstage); | |
624 defsubr (&Sgnutls_errorp); | |
625 defsubr (&Sgnutls_error_fatalp); | |
626 defsubr (&Sgnutls_error_string); | |
627 defsubr (&Sgnutls_boot); | |
628 defsubr (&Sgnutls_deinit); | |
629 defsubr (&Sgnutls_bye); | |
630 } | |
631 #endif |