]> code.delx.au - gnu-emacs/blob - src/gnutls.h
Merge from origin/emacs-25
[gnu-emacs] / src / gnutls.h
1 /* GnuTLS glue for GNU Emacs.
2 Copyright (C) 2010-2016 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 (at
9 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 #ifndef EMACS_GNUTLS_DEFINED
20 #define EMACS_GNUTLS_DEFINED
21
22 #ifdef HAVE_GNUTLS
23 #include <gnutls/gnutls.h>
24 #include <gnutls/x509.h>
25
26 #include "lisp.h"
27
28 /* This limits the attempts to handshake per process (connection). It
29 should work out to about one minute in asynchronous cases. */
30 #define GNUTLS_EMACS_HANDSHAKES_LIMIT 6000
31
32 typedef enum
33 {
34 /* Initialization stages. */
35 GNUTLS_STAGE_EMPTY = 0,
36 GNUTLS_STAGE_CRED_ALLOC,
37 GNUTLS_STAGE_FILES,
38 GNUTLS_STAGE_CALLBACKS,
39 GNUTLS_STAGE_INIT,
40 GNUTLS_STAGE_PRIORITY,
41 GNUTLS_STAGE_CRED_SET,
42
43 /* Handshake stages. */
44 GNUTLS_STAGE_HANDSHAKE_CANDO = GNUTLS_STAGE_CRED_SET,
45 GNUTLS_STAGE_TRANSPORT_POINTERS_SET,
46 GNUTLS_STAGE_HANDSHAKE_TRIED,
47
48 GNUTLS_STAGE_READY
49 } gnutls_initstage_t;
50
51 #define GNUTLS_EMACS_ERROR_NOT_LOADED (GNUTLS_E_APPLICATION_ERROR_MIN + 1)
52 #define GNUTLS_EMACS_ERROR_INVALID_TYPE GNUTLS_E_APPLICATION_ERROR_MIN
53
54 #define GNUTLS_INITSTAGE(proc) (XPROCESS (proc)->gnutls_initstage)
55
56 #define GNUTLS_PROCESS_USABLE(proc) \
57 (GNUTLS_INITSTAGE (proc) >= GNUTLS_STAGE_READY)
58
59 #define GNUTLS_LOG(level, max, string) \
60 do { \
61 if ((level) <= (max)) \
62 gnutls_log_function (level, "(Emacs) " string); \
63 } while (false)
64
65 #define GNUTLS_LOG2(level, max, string, extra) \
66 do { \
67 if ((level) <= (max)) \
68 gnutls_log_function2 (level, "(Emacs) " string, extra); \
69 } while (false)
70
71 #define GNUTLS_LOG2i(level, max, string, extra) \
72 do { \
73 if ((level) <= (max)) \
74 gnutls_log_function2i (level, "(Emacs) " string, extra); \
75 } while (false)
76
77 extern ptrdiff_t
78 emacs_gnutls_write (struct Lisp_Process *proc, const char *buf, ptrdiff_t nbyte);
79 extern ptrdiff_t
80 emacs_gnutls_read (struct Lisp_Process *proc, char *buf, ptrdiff_t nbyte);
81
82 extern ptrdiff_t emacs_gnutls_record_check_pending (gnutls_session_t state);
83 #ifdef WINDOWSNT
84 extern void emacs_gnutls_transport_set_errno (gnutls_session_t state, int err);
85 #endif
86 extern Lisp_Object emacs_gnutls_deinit (Lisp_Object);
87 extern Lisp_Object emacs_gnutls_global_init (void);
88 extern int gnutls_try_handshake (struct Lisp_Process *p);
89 extern Lisp_Object gnutls_verify_boot (Lisp_Object proc, Lisp_Object proplist);
90
91 #endif
92
93 extern void syms_of_gnutls (void);
94
95 #endif