Fork of the working HTTPClient adaptation using CyaSSL. This version adds a derivation of HTTPText called HTTPJson to emit JSON text properly. Additionally, the URL parser has defines that permit longer URLs to be utilized.

Dependencies:   mbedTLSLibrary

Dependents:   SalesforceInterface df-2014-heroku-thermostat-k64f SalesforceInterface

Fork of HTTPClient by wolf SSL

This is a fork of the working HTTPS/SSL library that contains two extensions:

- HTTPJson - a derivation of HTTPText for emitting JSON strings specifically. No JSON parsing/checking is accomplished - HTTPJson simply sets the right Content-Type for HTTP(S).

- Expanded internal buffers for longer URLs. This is set in HTTPClient.cpp and is tunable.

Revision:
50:a18a06b000f3
Parent:
49:a564fc323921
Child:
51:3bdf57f7fd60
--- a/HTTPClient.cpp	Fri Jun 05 22:10:21 2015 +0000
+++ b/HTTPClient.cpp	Tue Jun 09 16:26:02 2015 +0000
@@ -52,9 +52,8 @@
 #include <../CyaSSL/cyassl/ssl.h>
 
 #include "HTTPClient.h"
-#include "TCPSocketConnection.h"
 
-static  TCPSocketConnection m_sock;
+
 
 // ************ should be a better way to adjust for platform limitations 
 
@@ -85,34 +84,7 @@
 
 static char send_buf[SEND_BUF_SIZE] ;
 static char *send_buf_p = NULL;
-
-static int SocketReceive(CYASSL* ssl, char *buf, int sz, void *ctx)
-{
-    int n ;
-    int i ;
-#define RECV_RETRY 3
-
-    for(i=0; i<RECV_RETRY; i++) {
-        n = m_sock.receive(buf, sz) ;
-        if(n >= 0)return n  ;
-        Thread::wait(200) ;
-    }
-    ERR("SocketReceive:%d/%d\n", n, sz)  ;
-    return n ;
-}
-
-static int SocketSend(CYASSL* ssl, char *buf, int sz, void *ctx)
-{
-    int n ;
-    
-    Thread::wait(100) ;
-    n = m_sock.send(buf, sz);
-    if(n > 0) {
-        Thread::wait(300) ;
-        return n ;
-    } else  ERR("SocketSend:%d/%d\n", n, sz);
-    return n ;
-}
+static TCPSocketConnection* m_sock_p = NULL;
 
 static void base64enc(char *out, const char *in) {
     const char code[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=" ;
@@ -133,13 +105,38 @@
     }
     out[i] = '\0' ;
 }
+int SocketReceive(CYASSL* ssl, char *buf, int sz, void *ctx)
+{
+    int n ;
+    int i ;
+#define RECV_RETRY 3
+
+    for(i=0; i<RECV_RETRY; i++) {
+        n =  m_sock_p->receive(buf, sz) ;
+        if(n >= 0)return n  ;
+        Thread::wait(200) ;
+    }
+    ERR("SocketReceive:%d/%d\n", n, sz)  ;
+    return n ;
+}
+int SocketSend(CYASSL* ssl, char *buf, int sz, void *ctx)
+{
+    int n ;
+    
+    Thread::wait(100) ;
+    n =  m_sock_p->send(buf, sz);
+    if(n > 0) {
+        Thread::wait(300) ;
+        return n ;
+    } else  ERR("SocketSend:%d/%d\n", n, sz);
+    return n ;
+}
 
 HTTPClient::HTTPClient() :
     m_basicAuthUser(NULL), m_basicAuthPassword(NULL), m_httpResponseCode(0), m_oauthToken(NULL)
 {
     // To DEBUG the underlying SSL - uncomment this...
     //CyaSSL_Debugging_ON();
-    
     ctx = 0 ;
     ssl = 0 ;
     SSLver = 3 ; 
@@ -150,6 +147,7 @@
     redirect_url = NULL ;
     redirect = 0 ;
     header = NULL ;
+    m_sock_p = &m_sock;
 }
 
 HTTPClient::~HTTPClient()
@@ -157,6 +155,7 @@
 
 }
 
+
 HTTPResult HTTPClient::oauthToken(const char *token) { // OAUTH2 Authentication
     // reset if called
     if (m_oauthToken != NULL) free((void *)m_oauthToken);