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 # include <openssl/err.h>
40 #endif
41 
42 #include <freetds/pushvis.h>
43 
44 #if defined(HAVE_GNUTLS) || defined(HAVE_OPENSSL)
45 TDSRET tds_ssl_init(TDSSOCKET *tds);
46 void tds_ssl_deinit(TDSCONNECTION *conn);
47 
48 # ifdef HAVE_GNUTLS
49 
50 static inline int
51 tds_ssl_pending(TDSCONNECTION *conn)
52 {
53  return gnutls_record_check_pending((gnutls_session_t) conn->tls_session);
54 }
55 
56 static inline int
57 tds_ssl_read(TDSCONNECTION *conn, unsigned char *buf, int buflen)
58 {
59  return gnutls_record_recv((gnutls_session_t) conn->tls_session, buf, buflen);
60 }
61 
62 static inline int
63 tds_ssl_write(TDSCONNECTION *conn, const unsigned char *buf, int buflen)
64 {
65  return gnutls_record_send((gnutls_session_t) conn->tls_session, buf, buflen);
66 }
67 # else
68 
69 static inline int
70 tds_ssl_pending(TDSCONNECTION *conn)
71 {
72  return SSL_pending((SSL *) conn->tls_session);
73 }
74 
75 static inline int
76 tds_ssl_read(TDSCONNECTION *conn, unsigned char *buf, int buflen)
77 {
78  return SSL_read((SSL *) conn->tls_session, buf, buflen);
79 }
80 
81 static inline int
82 tds_ssl_write(TDSCONNECTION *conn, const unsigned char *buf, int buflen)
83 {
84  return SSL_write((SSL *) conn->tls_session, buf, buflen);
85 }
86 # endif
87 #else
88 static inline TDSRET
89 tds_ssl_init(TDSSOCKET *tds)
90 {
91  return TDS_FAIL;
92 }
93 
94 static inline void
95 tds_ssl_deinit(TDSCONNECTION *conn)
96 {
97 }
98 
99 static inline int
100 tds_ssl_pending(TDSCONNECTION *conn)
101 {
102  return 0;
103 }
104 
105 static inline int
106 tds_ssl_read(TDSCONNECTION *conn, unsigned char *buf, int buflen)
107 {
108  return -1;
109 }
110 
111 static inline int
112 tds_ssl_write(TDSCONNECTION *conn, const unsigned char *buf, int buflen)
113 {
114  return -1;
115 }
116 #endif
117 
118 #include <freetds/popvis.h>
119 
120 #endif /* _freetds_tls_h_ */
Information for a server connection.
Definition: tds.h:1135
Definition: tds.h:1063