Code

New Dutch calligraphy and interpolate tutorial
[inkscape.git] / src / dom / io / socket.cpp
index 31eeb56bad3a0a0fd8ac9e2bb9af5ad79fc3d772..e39032040c5eea6f72efc6d68ec1f749dae193a6 100644 (file)
@@ -10,7 +10,7 @@
  * Authors:
  *   Bob Jamison
  *
- * Copyright (C) 2005 Bob Jamison
+ * Copyright (C) 2005-2008 Bob Jamison
  *
  *  This library is free software; you can redistribute it and/or
  *  modify it under the terms of the GNU Lesser General Public
@@ -35,6 +35,7 @@
 #include <sys/filio.h>   // needed on Solaris 8
 #endif
 
+#include <cstdio>
 #include "socket.h"
 #include "dom/util/thread.h"
 
@@ -53,6 +54,8 @@
 #ifdef HAVE_SSL
 #include <openssl/ssl.h>
 #include <openssl/err.h>
+
+RELAYTOOL_SSL
 #endif
 
 
@@ -205,12 +208,15 @@ void TcpSocket::init()
         WSAStartup( wVersionRequested, &wsaData );
 #endif
 #ifdef HAVE_SSL
-        sslStream  = NULL;
-        sslContext = NULL;
-           CRYPTO_set_locking_callback(cryptoLockCallback);
-        CRYPTO_set_id_callback(cryptoIdCallback);
-        SSL_library_init();
-        SSL_load_error_strings();
+        if (libssl_is_present)
+            {
+            sslStream  = NULL;
+            sslContext = NULL;
+            CRYPTO_set_locking_callback(cryptoLockCallback);
+            CRYPTO_set_id_callback(cryptoIdCallback);
+            SSL_library_init();
+            SSL_load_error_strings();
+            }
 #endif
         tcp_socket_inited = true;
         }
@@ -285,6 +291,8 @@ static void infoCallback(const SSL *ssl, int where, int ret)
 bool TcpSocket::startTls()
 {
 #ifdef HAVE_SSL
+    if (libssl_is_present)
+    {
     sslStream  = NULL;
     sslContext = NULL;
 
@@ -335,6 +343,7 @@ bool TcpSocket::startTls()
         }
 
     sslEnabled = true;
+    }
 #endif /*HAVE_SSL*/
     return true;
 }
@@ -397,6 +406,8 @@ bool TcpSocket::disconnect()
     bool ret  = true;
     connected = false;
 #ifdef HAVE_SSL
+    if (libssl_is_present)
+    {
     if (sslEnabled)
         {
         if (sslStream)
@@ -419,6 +430,7 @@ bool TcpSocket::disconnect()
         }
     sslStream  = NULL;
     sslContext = NULL;
+    }
 #endif /*HAVE_SSL*/
 
 #ifdef __WIN32__
@@ -460,7 +472,10 @@ long TcpSocket::available()
     if (count<=0 && sslEnabled)
         {
 #ifdef HAVE_SSL
-        return SSL_pending(sslStream);
+        if (libssl_is_present)
+            {
+            return SSL_pending(sslStream);
+            }
 #endif
         }
     return count;
@@ -480,14 +495,17 @@ bool TcpSocket::write(int ch)
     if (sslEnabled)
         {
 #ifdef HAVE_SSL
-        int r = SSL_write(sslStream, &c, 1);
-        if (r<=0)
+        if (libssl_is_present)
             {
-            switch(SSL_get_error(sslStream, r))
+            int r = SSL_write(sslStream, &c, 1);
+            if (r<=0)
                 {
-                default:
+                switch(SSL_get_error(sslStream, r))
+                    {
+                    default:
                     printf("SSL write problem");
                     return -1;
+                    }
                 }
             }
 #endif
@@ -518,14 +536,17 @@ bool TcpSocket::write(const DOMString &strArg)
     if (sslEnabled)
         {
 #ifdef HAVE_SSL
-        int r = SSL_write(sslStream, (unsigned char *)str.c_str(), len);
-        if (r<=0)
+        if (libssl_is_present)
             {
-            switch(SSL_get_error(sslStream, r))
+           int r = SSL_write(sslStream, (unsigned char *)str.c_str(), len);
+            if (r<=0)
                 {
-                default:
-                    printf("SSL write problem");
-                    return -1;
+                switch(SSL_get_error(sslStream, r))
+                    {
+                    default:
+                        printf("SSL write problem");
+                        return -1;
+                    }
                 }
             }
 #endif
@@ -572,24 +593,27 @@ int TcpSocket::read()
     if (sslEnabled)
         {
 #ifdef HAVE_SSL
-        if (!sslStream)
-            return -1;
-        int r = SSL_read(sslStream, &ch, 1);
-        unsigned long err = SSL_get_error(sslStream, r);
-        switch (err)
+        if (libssl_is_present)
             {
-            case SSL_ERROR_NONE:
-                 break;
-            case SSL_ERROR_ZERO_RETURN:
-                return -1;
-            case SSL_ERROR_SYSCALL:
-                printf("SSL read problem(syscall) %s\n",
-                     ERR_error_string(ERR_get_error(), NULL));
-                return -1;
-            default:
-                printf("SSL read problem %s\n",
-                     ERR_error_string(ERR_get_error(), NULL));
+            if (!sslStream)
                 return -1;
+            int r = SSL_read(sslStream, &ch, 1);
+            unsigned long err = SSL_get_error(sslStream, r);
+            switch (err)
+                {
+                case SSL_ERROR_NONE:
+                     break;
+                case SSL_ERROR_ZERO_RETURN:
+                    return -1;
+                case SSL_ERROR_SYSCALL:
+                    printf("SSL read problem(syscall) %s\n",
+                         ERR_error_string(ERR_get_error(), NULL));
+                    return -1;
+                default:
+                    printf("SSL read problem %s\n",
+                         ERR_error_string(ERR_get_error(), NULL));
+                    return -1;
+                }
             }
 #endif
         }