NCBI C++ ToolKit
tls.h
Go to the documentation of this file.

Go to the SVN repository for this file.

Go to the SVN repository for this file.

Go to the SVN repository for this file.

Go to the SVN repository for this file.

Go to the SVN repository for this file.

Go to the SVN repository for this file.

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)
46 
47 # ifdef HAVE_GNUTLS
48 
49 static inline size_t
51 {
52  return gnutls_record_check_pending((gnutls_session_t) conn->tls_session);
53 }
54 
55 static inline ssize_t
56 tds_ssl_read(TDSCONNECTION *conn, unsigned char *buf, size_t buflen)
57 {
58  return gnutls_record_recv((gnutls_session_t) conn->tls_session, buf, buflen);
59 }
60 
61 static inline ssize_t
62 tds_ssl_write(TDSCONNECTION *conn, const unsigned char *buf, size_t buflen)
63 {
64  return gnutls_record_send((gnutls_session_t) conn->tls_session, buf, buflen);
65 }
66 # else
67 
68 static inline size_t
70 {
71  return SSL_pending((SSL *) conn->tls_session);
72 }
73 
74 static inline ssize_t
75 tds_ssl_read(TDSCONNECTION *conn, unsigned char *buf, size_t buflen)
76 {
77  return SSL_read((SSL *) conn->tls_session, buf, buflen);
78 }
79 
80 static inline ssize_t
81 tds_ssl_write(TDSCONNECTION *conn, const unsigned char *buf, size_t buflen)
82 {
83  return SSL_write((SSL *) conn->tls_session, buf, buflen);
84 }
85 # endif
86 #else
87 static inline TDSRET
89 {
90  return TDS_FAIL;
91 }
92 
93 static inline void
95 {
96 }
97 
98 static inline size_t
100 {
101  return 0;
102 }
103 
104 static inline ssize_t
105 tds_ssl_read(TDSCONNECTION *conn, unsigned char *buf, size_t buflen)
106 {
107  return -1;
108 }
109 
110 static inline ssize_t
111 tds_ssl_write(TDSCONNECTION *conn, const unsigned char *buf, size_t buflen)
112 {
113  return -1;
114 }
115 #endif
116 
117 #include <freetds/popvis.h>
118 
119 #endif /* _freetds_tls_h_ */
static TDSSOCKET * tds
Definition: collations.c:37
static CS_CONNECTION * conn
Definition: ct_dynamic.c:25
char * buf
int ssize_t
Definition: ncbiconf_msvc.h:92
Information for a server connection.
Definition: tds.h:1211
#define TDS_FAIL
Definition: tds.h:204
int TDSRET
Definition: tds.h:201
static void tds_ssl_deinit(TDSCONNECTION *conn)
Definition: tls.h:94
static ssize_t tds_ssl_read(TDSCONNECTION *conn, unsigned char *buf, size_t buflen)
Definition: tls.h:105
static TDSRET tds_ssl_init(TDSSOCKET *tds)
Definition: tls.h:88
static ssize_t tds_ssl_write(TDSCONNECTION *conn, const unsigned char *buf, size_t buflen)
Definition: tls.h:111
static size_t tds_ssl_pending(TDSCONNECTION *conn)
Definition: tls.h:99
Modified on Tue Apr 09 07:57:35 2024 by modify_doxy.py rev. 669887
Modified on Wed Apr 10 07:32:59 2024 by modify_doxy.py rev. 669887
Modified on Thu Apr 11 15:06:08 2024 by modify_doxy.py rev. 669887
Modified on Fri Apr 12 17:18:05 2024 by modify_doxy.py rev. 669887
Modified on Sat Apr 13 11:46:05 2024 by modify_doxy.py rev. 669887
Modified on Sun Apr 14 05:26:26 2024 by modify_doxy.py rev. 669887