Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: ECE_4180_Lab_4 IoT_Security_WIFI ESP8266_HTTP_HelloWorld ESP8266_ws_hw ... more
Fork of HTTPClient-SSL by
Revision 50:a18a06b000f3, committed 2015-06-09
- Comitter:
- sarahmarshy
- Date:
- Tue Jun 09 16:26:02 2015 +0000
- Parent:
- 49:a564fc323921
- 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 ;
