LCOV - code coverage report
Current view: top level - include/freetds - tls.h (source / functions) Hit Total Coverage
Test: FreeTDS coverage Lines: 6 6 100.0 %
Date: 2024-03-23 08:24:27 Functions: 0 0 -

          Line data    Source code
       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       53538 :         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       22653 :         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        9328 :         return gnutls_record_send((gnutls_session_t) conn->tls_session, buf, buflen);
      66             : }
      67             : #  else
      68             : 
      69             : /* compatibility for LibreSSL 2.7  */
      70             : #ifdef LIBRESSL_VERSION_NUMBER
      71             : #define TLS_ST_OK SSL_ST_OK
      72             : #endif
      73             : 
      74             : static inline int
      75             : tds_ssl_pending(TDSCONNECTION *conn)
      76             : {
      77       21159 :         return SSL_pending((SSL *) conn->tls_session);
      78             : }
      79             : 
      80             : static inline int
      81             : tds_ssl_read(TDSCONNECTION *conn, unsigned char *buf, int buflen)
      82             : {
      83       17605 :         return SSL_read((SSL *) conn->tls_session, buf, buflen);
      84             : }
      85             : 
      86             : static inline int
      87             : tds_ssl_write(TDSCONNECTION *conn, const unsigned char *buf, int buflen)
      88             : {
      89        9003 :         return SSL_write((SSL *) conn->tls_session, buf, buflen);
      90             : }
      91             : #  endif
      92             : #else
      93             : static inline TDSRET
      94             : tds_ssl_init(TDSSOCKET *tds TDS_UNUSED)
      95             : {
      96             :         return TDS_FAIL;
      97             : }
      98             : 
      99             : static inline void
     100             : tds_ssl_deinit(TDSCONNECTION *conn TDS_UNUSED)
     101             : {
     102             : }
     103             : 
     104             : static inline int
     105             : tds_ssl_pending(TDSCONNECTION *conn TDS_UNUSED)
     106             : {
     107             :         return 0;
     108             : }
     109             : 
     110             : static inline int
     111             : tds_ssl_read(TDSCONNECTION *conn TDS_UNUSED, unsigned char *buf TDS_UNUSED, int buflen TDS_UNUSED)
     112             : {
     113             :         return -1;
     114             : }
     115             : 
     116             : static inline int
     117             : tds_ssl_write(TDSCONNECTION *conn TDS_UNUSED, const unsigned char *buf TDS_UNUSED, int buflen TDS_UNUSED)
     118             : {
     119             :         return -1;
     120             : }
     121             : #endif
     122             : 
     123             : #include <freetds/popvis.h>
     124             : 
     125             : #endif /* _freetds_tls_h_ */

Generated by: LCOV version 1.13