FreeTDS API

tls.h
1 /* FreeTDS - Library of routines accessing Sybase and Microsoft databases
2 * Copyright (C) 2015 Frediano Ziglio
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
18 */
19
20 #ifndef _freetds_tls_h_
21 #define _freetds_tls_h_
22
23 #ifndef _tds_h_
24 #error tds.h must be included before tls.h
25 #endif
26
27 #ifdef HAVE_GNUTLS
28 # if defined(_THREAD_SAFE) && defined(TDS_HAVE_PTHREAD_MUTEX)
29 # include <freetds/thread.h>
30 # ifndef GNUTLS_USE_NETTLE
31 # include <gcrypt.h>
32 # endif
33 # endif
34 # include <gnutls/gnutls.h>
35 # include <gnutls/x509.h>
36 #elif defined(HAVE_OPENSSL)
37 # include <openssl/ssl.h>
38 # include <openssl/x509v3.h>
39 #endif
40
41 #include <freetds/pushvis.h>
42
43 #if defined(HAVE_GNUTLS) || defined(HAVE_OPENSSL)
44 TDSRET tds_ssl_init(TDSSOCKET *tds);
45 void tds_ssl_deinit(TDSCONNECTION *conn);
46
47 # ifdef HAVE_GNUTLS
48
49 static inline int
50 tds_ssl_pending(TDSCONNECTION *conn)
51 {
52 return gnutls_record_check_pending((gnutls_session_t) conn->tls_session);
53 }
54
55 static inline int
56 tds_ssl_read(TDSCONNECTION *conn, unsigned char *buf, int buflen)
57 {
58 return gnutls_record_recv((gnutls_session_t) conn->tls_session, buf, buflen);
59 }
60
61 static inline int
62 tds_ssl_write(TDSCONNECTION *conn, const unsigned char *buf, int buflen)
63 {
64 return gnutls_record_send((gnutls_session_t) conn->tls_session, buf, buflen);
65 }
66 # else
67
68 static inline int
69 tds_ssl_pending(TDSCONNECTION *conn)
70 {
71 return SSL_pending((SSL *) conn->tls_session);
72 }
73
74 static inline int
75 tds_ssl_read(TDSCONNECTION *conn, unsigned char *buf, int buflen)
76 {
77 return SSL_read((SSL *) conn->tls_session, buf, buflen);
78 }
79
80 static inline int
81 tds_ssl_write(TDSCONNECTION *conn, const unsigned char *buf, int buflen)
82 {
83 return SSL_write((SSL *) conn->tls_session, buf, buflen);
84 }
85 # endif
86 #else
87 static inline TDSRET
88 tds_ssl_init(TDSSOCKET *tds)
89 {
90 return TDS_FAIL;
91 }
92
93 static inline void
94 tds_ssl_deinit(TDSCONNECTION *conn)
95 {
96 }
97
98 static inline int
99 tds_ssl_pending(TDSCONNECTION *conn)
100 {
101 return 0;
102 }
103
104 static inline int
105 tds_ssl_read(TDSCONNECTION *conn, unsigned char *buf, int buflen)
106 {
107 return -1;
108 }
109
110 static inline int
111 tds_ssl_write(TDSCONNECTION *conn, const unsigned char *buf, int buflen)
112 {
113 return -1;
114 }
115 #endif
116
117 #include <freetds/popvis.h>
118
119 #endif /* _freetds_tls_h_ */
tds_socket
Information for a server connection.
Definition: tds.h:1175
tds_connection
Definition: tds.h:1103