FreeTDS API: include/freetds/tls.h Source File

FreeTDS API

- Main Page
- Related Pages
- Modules
- Classes
- Files

- File List
- File Members

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