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.

Files at this revision

API Documentation at this revision

Comitter:
sarahmarshy
Date:
Tue Jun 09 16:26:02 2015 +0000
Parent:
49:a564fc323921
Child:
51:3bdf57f7fd60
Commit message:
Changed global variable to global pointer

Changed in this revision

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/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);
--- a/HTTPClient.h	Fri Jun 05 22:10:21 2015 +0000
+++ b/HTTPClient.h	Tue Jun 09 16:26:02 2015 +0000
@@ -30,6 +30,7 @@
 
 #include "IHTTPData.h"
 #include "mbed.h"
+#include "TCPSocketConnection.h"
 
 ///HTTP client results
 enum HTTPResult {
@@ -58,6 +59,8 @@
     ///Instantiate the HTTP client
     HTTPClient();
     ~HTTPClient();
+    
+    
 
     /**
     Provides a OAUTH2 authentification feature 
@@ -155,12 +158,13 @@
     //Parameters
 
     int m_timeout;
-
     const char* m_basicAuthUser;
     const char* m_basicAuthPassword;
     const char* m_oauthToken;
     int m_httpResponseCode;
 
+    TCPSocketConnection m_sock;
+    
     const char * header ;
     char * redirect_url ;
     int    redirect_url_size ;