reverted HTTPCLient debug back to defaulted off

Dependencies:   CyaSSL

Fork of HTTPClient-SSL by Keith Ruenheck

Files at this revision

API Documentation at this revision

Comitter:
Vanger
Date:
Wed Dec 31 22:26:17 2014 +0000
Parent:
32:d9db238bb8a3
Child:
34:13920d48893d
Commit message:
Changed client implementation of TCPSocketConnection for interfacing with cellular class

Changed in this revision

CyaSSL.lib Show annotated file Show diff for this revision Revisions of this file
HTTPClient.cpp Show annotated file Show diff for this revision Revisions of this file
HTTPClient.h Show annotated file Show diff for this revision Revisions of this file
--- a/CyaSSL.lib	Thu Aug 28 00:07:09 2014 +0000
+++ b/CyaSSL.lib	Wed Dec 31 22:26:17 2014 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/wolfSSL/code/CyaSSL/#1239e9b70ca2
+http://mbed.org/users/wolfSSL/code/CyaSSL/#fe3788d8dd06
--- a/HTTPClient.cpp	Thu Aug 28 00:07:09 2014 +0000
+++ b/HTTPClient.cpp	Wed Dec 31 22:26:17 2014 +0000
@@ -53,9 +53,8 @@
 #include <../CyaSSL/cyassl/ssl.h>
 
 #include "HTTPClient.h"
-#include "TCPSocketConnection.h"
 
-static  TCPSocketConnection m_sock;
+static  TCPSocketConnection* m_sock;
 #define CHUNK_SIZE    256
 #define SEND_BUF_SIZE 1024
 static char send_buf[SEND_BUF_SIZE] ;
@@ -68,7 +67,7 @@
 #define RECV_RETRY 3
 
     for(i=0; i<RECV_RETRY; i++) {
-        n = m_sock.receive(buf, sz) ;
+        n = m_sock->receive(buf, sz) ;
         if(n >= 0)return n  ;
         wait(0.2) ;
     }
@@ -81,7 +80,7 @@
     int n ;
     
     wait(0.1) ;
-    n = m_sock.send(buf, sz);
+    n = m_sock->send(buf, sz);
     if(n > 0) {
         wait(0.3) ;
         return n ;
@@ -112,7 +111,7 @@
 HTTPClient::HTTPClient() :
     m_basicAuthUser(NULL), m_basicAuthPassword(NULL), m_httpResponseCode(0)
 {
-
+    m_sock = &_m_sock;
     /* CyaSSL_Debugging_ON() ; */
     
     ctx = 0 ;
@@ -206,7 +205,7 @@
   do{ \
     if(ret) { \
       cyassl_free() ;\
-      m_sock.close(); \
+      m_sock->close(); \
       ERR("Connection error (%d)", ret); \
       return HTTP_CONN; \
     } \
@@ -215,7 +214,7 @@
 #define PRTCL_ERR() \
   do{ \
     cyassl_free() ;\
-    m_sock.close(); \
+    m_sock->close(); \
     ERR("Protocol error"); \
     return HTTP_PRTCL; \
   } while(0)
@@ -235,7 +234,7 @@
 
 HTTPResult HTTPClient::connect(const char* url, HTTP_METH method, IHTTPDataOut* pDataOut, IHTTPDataIn* pDataIn, int timeout) //Execute request
 {
-    CYASSL_METHOD * SSLmethod ;
+    CYASSL_METHOD * SSLmethod = 0;
     m_httpResponseCode = 0; //Invalidate code
     m_timeout = timeout;
     redirect = 0 ;
@@ -277,11 +276,11 @@
     int retry ;
 
     for(retry=0; retry<MAX_RETRY; retry++) {
-        int ret = m_sock.connect(host, port);
+        int ret = m_sock->connect(host, port);
         if(ret == 0)break ;
     }
     if(retry == MAX_RETRY) {
-        m_sock.close();
+        m_sock->close();
         ERR("Could not connect");
         return HTTP_CONN;
     }
@@ -334,7 +333,7 @@
     snprintf(buf, sizeof(buf), "%s %s HTTP/1.1\r\nHost: %s\r\nConnection: keep-alive\r\n", meth, path, host); //Write request
     ret = send(buf);
     if(ret) {
-        m_sock.close();
+        m_sock->close();
         ERR("Could not write request");
         return HTTP_CONN;
     }
@@ -612,7 +611,7 @@
 
     }
     cyassl_free() ;
-    m_sock.close();
+    m_sock->close();
     DBG("Completed HTTP transaction");
     if(redirect)return HTTP_REDIRECT ;
     else        return HTTP_OK;
@@ -623,7 +622,7 @@
     DBG("Trying to read between %d and %d bytes", minLen, maxLen);
     size_t readLen = 0;
 
-    if(!m_sock.is_connected()) {
+    if(!m_sock->is_connected()) {
         WARN("Connection was closed by server");
         return HTTP_CLOSED; //Connection was closed by server
     }
@@ -633,7 +632,7 @@
     if(port == HTTPS_PORT) {
         DBG("Enter CyaSSL_read") ;
 
-        m_sock.set_blocking(false, m_timeout);
+        m_sock->set_blocking(false, m_timeout);
         readLen = CyaSSL_read(ssl, buf, maxLen);
         if (readLen > 0) {
             buf[readLen] = 0;
@@ -650,12 +649,12 @@
     while(readLen < maxLen) {
         if(readLen < minLen) {
             DBG("Trying to read at most %d bytes [Blocking]", minLen - readLen);
-            m_sock.set_blocking(false, m_timeout);
-            ret = m_sock.receive_all(buf + readLen, minLen - readLen);
+            m_sock->set_blocking(false, m_timeout);
+            ret = m_sock->receive_all(buf + readLen, minLen - readLen);
         } else {
             DBG("Trying to read at most %d bytes [Not blocking]", maxLen - readLen);
-            m_sock.set_blocking(false, 0);
-            ret = m_sock.receive(buf + readLen, maxLen - readLen);
+            m_sock->set_blocking(false, 0);
+            ret = m_sock->receive(buf + readLen, maxLen - readLen);
         }
 
         if( ret > 0) {
@@ -663,7 +662,7 @@
         } else if( ret == 0 ) {
             break;
         } else {
-            if(!m_sock.is_connected()) {
+            if(!m_sock->is_connected()) {
                 ERR("Connection error (recv returned %d)", ret);
                 *pReadLen = readLen;
                 return HTTP_CONN;
@@ -672,7 +671,7 @@
             }
         }
 
-        if(!m_sock.is_connected()) {
+        if(!m_sock->is_connected()) {
             break;
         }
     }
@@ -726,7 +725,7 @@
     DBG("Trying to write %d bytes:%s\n", len, buf);
     size_t writtenLen = 0;
 
-    if(!m_sock.is_connected()) {
+    if(!m_sock->is_connected()) {
         WARN("Connection was closed by server");
         return HTTP_CLOSED; //Connection was closed by server
     }
@@ -740,8 +739,8 @@
         DBG("Written %d bytes", writtenLen);
         return HTTP_OK;
     }
-    m_sock.set_blocking(false, m_timeout);
-    int ret = m_sock.send_all(buf, len);
+    m_sock->set_blocking(false, m_timeout);
+    int ret = m_sock->send_all(buf, len);
     if(ret > 0) {
         writtenLen += ret;
     } else if( ret == 0 ) {
--- a/HTTPClient.h	Thu Aug 28 00:07:09 2014 +0000
+++ b/HTTPClient.h	Wed Dec 31 22:26:17 2014 +0000
@@ -30,9 +30,11 @@
 
 #include "IHTTPData.h"
 #include "mbed.h"
+#include "TCPSocketConnection.h"
 
 ///HTTP client results
 enum HTTPResult {
+    HTTP_OK = 0, ///<Success
     HTTP_PROCESSING, ///<Processing
     HTTP_PARSE, ///<url Parse error
     HTTP_DNS, ///<Could not resolve name
@@ -44,7 +46,6 @@
     HTTP_CONN, ///<Connection error
     HTTP_CLOSED, ///<Connection was closed by remote host
     HTTP_REDIRECT, ///<HTTP 300 - 303
-    HTTP_OK = 0, ///<Success
 };
 
 /**A simple HTTP Client
@@ -145,6 +146,7 @@
     HTTPResult readHeader(void) ;
     
     //Parameters
+    TCPSocketConnection _m_sock;
 
     int m_timeout;