my fork

Fork of HTTPClient by wolf SSL

Revision:
31:7fd621b83b60
Parent:
30:a9ecee69c6b5
Child:
32:9aadb8a34e80
--- a/HTTPClient.cpp	Fri Dec 05 07:03:47 2014 +0000
+++ b/HTTPClient.cpp	Fri Jun 26 00:39:47 2015 +0000
@@ -24,12 +24,13 @@
 #define DBG(x, ...) std::printf("[HTTPClient : DBG]"x"\r\n", ##__VA_ARGS__);
 #define WARN(x, ...) std::printf("[HTTPClient : WARN]"x"\r\n", ##__VA_ARGS__);
 #define ERR(x, ...) std::printf("[HTTPClient : ERR]"x"\r\n", ##__VA_ARGS__);
-
+#define WOLF_DEBUG_ON    wolfSSL_Debugging_ON() ;
 #else
 //Disable debug
 #define DBG(x, ...)
 #define WARN(x, ...)
 #define ERR(x, ...)
+#define WOLF_DEBUG_ON 
 
 #endif
 
@@ -43,10 +44,10 @@
 
 #include <cstring>
 
-#include  <../CyaSSL/cyassl/ctaocrypt/settings.h>
-#include <../CyaSSL/cyassl/ctaocrypt/types.h>
-#include <../CyaSSL/cyassl/internal.h>
-#include <../CyaSSL/cyassl/ssl.h>
+#include  <../wolfSSL/wolfssl/wolfcrypt/settings.h>
+#include <../wolfSSL/wolfssl/wolfcrypt/types.h>
+#include <../wolfSSL/wolfssl/internal.h>
+#include <../wolfSSL/wolfssl/ssl.h>
 
 #include "HTTPClient.h"
 #include "TCPSocketConnection.h"
@@ -57,7 +58,7 @@
 static char send_buf[SEND_BUF_SIZE] ;
 static char *send_buf_p ;
 
-static int SocketReceive(CYASSL* ssl, char *buf, int sz, void *ctx)
+static int SocketReceive(WOLFSSL* ssl, char *buf, int sz, void *ctx)
 {
     int n ;
     int i ;
@@ -72,7 +73,7 @@
     return n ;
 }
 
-static int SocketSend(CYASSL* ssl, char *buf, int sz, void *ctx)
+static int SocketSend(WOLFSSL* ssl, char *buf, int sz, void *ctx)
 {
     int n ;
 
@@ -110,7 +111,7 @@
     m_basicAuthUser(NULL), m_basicAuthPassword(NULL), m_httpResponseCode(0)
 {
 
-    /* CyaSSL_Debugging_ON() ; */
+    WOLF_DEBUG_ON ;
 
     ctx = 0 ;
     ssl = 0 ;
@@ -191,7 +192,7 @@
 #define CHECK_CONN_ERR(ret) \
   do{ \
     if(ret) { \
-      cyassl_free() ;\
+      wolfssl_free() ;\
       m_sock.close(); \
       ERR("Connection error (%d)", ret); \
       return HTTP_CONN; \
@@ -200,28 +201,28 @@
 
 #define PRTCL_ERR() \
   do{ \
-    cyassl_free() ;\
+    wolfssl_free() ;\
     m_sock.close(); \
     ERR("Protocol error"); \
     return HTTP_PRTCL; \
   } while(0)
 
-void HTTPClient::cyassl_free(void)
+void HTTPClient::wolfssl_free(void)
 {
     if(ssl) {
-        CyaSSL_free(ssl) ;
+        wolfSSL_free(ssl) ;
         ssl = NULL ;
     }
     if(ctx) {
-        CyaSSL_CTX_free(ctx) ;
+        wolfSSL_CTX_free(ctx) ;
         ctx = NULL ;
     }
-    CyaSSL_Cleanup() ;
+    wolfSSL_Cleanup() ;
 }
 
 HTTPResult HTTPClient::connect(const char* url, HTTP_METH method, IHTTPDataOut* pDataOut, IHTTPDataIn* pDataIn, int timeout) //Execute request
 {
-    CYASSL_METHOD * SSLmethod ;
+    WOLFSSL_METHOD * SSLmethod ;
     m_httpResponseCode = 0; //Invalidate code
     m_timeout = timeout;
     redirect = 0 ;
@@ -233,7 +234,7 @@
 
     char scheme[8];
     char host[32];
-    char path[80];
+    char path[160];
 
     int ret ;
 
@@ -279,41 +280,41 @@
         if(ctx == NULL) {
             switch(SSLver) {
                 case 0 :
-                    SSLmethod = CyaSSLv3_client_method() ;
+                    SSLmethod = wolfSSLv3_client_method() ;
                     break ;
                 case 1 :
-                    SSLmethod = CyaTLSv1_client_method() ;
+                    SSLmethod = wolfTLSv1_client_method() ;
                     break ;
                 case 2 :
-                    SSLmethod = CyaTLSv1_1_client_method() ;
+                    SSLmethod = wolfTLSv1_1_client_method() ;
                     break ;
                 case 3 :
-                    SSLmethod = CyaTLSv1_2_client_method() ;
+                    SSLmethod = wolfTLSv1_2_client_method() ;
                     break ;
             }
-            ctx = CyaSSL_CTX_new((CYASSL_METHOD *)SSLmethod);
+            ctx = wolfSSL_CTX_new((WOLFSSL_METHOD *)SSLmethod);
             if (ctx == NULL) {
                 ERR("unable to get ctx");
                 return HTTP_CONN;
             }
-            CyaSSL_CTX_set_verify(ctx, SSL_VERIFY_NONE, 0);
-            CyaSSL_SetIORecv(ctx, SocketReceive) ;
-            CyaSSL_SetIOSend(ctx, SocketSend) ;
+            wolfSSL_CTX_set_verify(ctx, SSL_VERIFY_NONE, 0);
+            wolfSSL_SetIORecv(ctx, SocketReceive) ;
+            wolfSSL_SetIOSend(ctx, SocketSend) ;
         }
         if (ssl == NULL) {
-            ssl = CyaSSL_new(ctx);
+            ssl = wolfSSL_new(ctx);
             if (ssl == NULL) {
                 ERR("unable to get SSL object");
-                cyassl_free() ;
+                wolfssl_free() ;
                 return HTTP_CONN;
             }
         }
 
         DBG("ctx=%x, ssl=%x, ssl->ctx->CBIORecv, CBIOSend=%x, %x\n",
             ctx, ssl, SocketReceive, SocketSend ) ;
-        if (CyaSSL_connect(ssl) != SSL_SUCCESS) {
+        if (wolfSSL_connect(ssl) != SSL_SUCCESS) {
             ERR("SSL_connect failed");
-            cyassl_free() ;
+            wolfssl_free() ;
             return HTTP_CONN;
         }
     } /* SSL connect complete */
@@ -626,7 +627,7 @@
         }
 
     }
-    cyassl_free() ;
+    wolfssl_free() ;
     m_sock.close();
     DBG("Completed HTTP transaction");
     if(redirect)return HTTP_REDIRECT ;
@@ -646,15 +647,15 @@
     int ret;
 
     if(port == HTTPS_PORT) {
-        DBG("Enter CyaSSL_read") ;
+        DBG("Enter wolfSSL_read") ;
 
         m_sock.set_blocking(false, m_timeout);
-        readLen = CyaSSL_read(ssl, buf, maxLen);
+        readLen = wolfSSL_read(ssl, buf, maxLen);
         if (readLen > 0) {
             buf[readLen] = 0;
-            DBG("CyaSSL_read:%s\n", buf);
+            DBG("wolfSSL_read:%s\n", buf);
         } else {
-            ERR("CyaSSL_read, ret = %d", readLen) ;
+            ERR("wolfSSL_read, ret = %d", readLen) ;
             return HTTP_ERROR ;
         }
         DBG("Read %d bytes", readLen);
@@ -747,8 +748,8 @@
     }
 
     if(port == HTTPS_PORT) {
-        DBG("Enter CyaSSL_write") ;
-        if (CyaSSL_write(ssl, buf, len) != len) {
+        DBG("Enter wolfSSL_write") ;
+        if (wolfSSL_write(ssl, buf, len) != len) {
             ERR("SSL_write failed");
             return HTTP_ERROR ;
         }