Fixed custom headers and Basic authorization, added support for redirection, functional file download interface can be used for SW updates and more.

Dependents:   Sample_HTTPClient Sample_HTTPClient LWM2M_NanoService_Ethernet LWM2M_NanoService_Ethernet ... more

Fork of HTTPClient by Vincent Wochnik

More recent changes - added iCal processing.

Derivative of a derivative, however this one works when it comes to supplying Basic authorization to access a protected resource. Some additional changes to the debug interface to clean it up for consistency with many other components I have.

Files at this revision

API Documentation at this revision

Comitter:
WiredHome
Date:
Thu Aug 06 11:11:31 2015 +0000
Parent:
34:3556275bebf3
Child:
36:a5c13e512b78
Commit message:
Code changes based on running through a stricter compiler.

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
data/HTTPFile.cpp Show annotated file Show diff for this revision Revisions of this file
data/HTTPMap.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/HTTPClient.cpp	Sun Mar 08 17:50:52 2015 +0000
+++ b/HTTPClient.cpp	Thu Aug 06 11:11:31 2015 +0000
@@ -21,10 +21,10 @@
 //#define DEBUG "HTCL"
 #include <cstdio>
 #if (defined(DEBUG) && !defined(TARGET_LPC11U24))
-#define DBG(x, ...)  std::printf("[DBG %s %3d] "x"\r\n", DEBUG, __LINE__, ##__VA_ARGS__);
-#define WARN(x, ...) std::printf("[WRN %s %3d] "x"\r\n", DEBUG, __LINE__, ##__VA_ARGS__);
-#define ERR(x, ...)  std::printf("[ERR %s %3d] "x"\r\n", DEBUG, __LINE__, ##__VA_ARGS__);
-#define INFO(x, ...) std::printf("[INF %s %3d] "x"\r\n", DEBUG, __LINE__, ##__VA_ARGS__);
+#define DBG(x, ...)  std::printf("[DBG %s %3d] " x "\r\n", DEBUG, __LINE__, ##__VA_ARGS__);
+#define WARN(x, ...) std::printf("[WRN %s %3d] " x "\r\n", DEBUG, __LINE__, ##__VA_ARGS__);
+#define ERR(x, ...)  std::printf("[ERR %s %3d] " x "\r\n", DEBUG, __LINE__, ##__VA_ARGS__);
+#define INFO(x, ...) std::printf("[INF %s %3d] " x "\r\n", DEBUG, __LINE__, ##__VA_ARGS__);
 #else
 #define DBG(x, ...)
 #define WARN(x, ...)
@@ -157,7 +157,7 @@
     char path[MAXLEN_VALUE];
     size_t recvContentLength = 0;
     bool recvChunked = false;
-    int crlfPos = 0;
+    size_t crlfPos = 0;
     char buf[CHUNK_SIZE];
     size_t trfLen;
     int ret = 0;
@@ -549,7 +549,7 @@
     return HTTP_OK;
 }
 
-HTTPResult HTTPClient::send(char* buf, size_t len) //0 on success, err code on failure
+HTTPResult HTTPClient::send(const char* buf, size_t len) //0 on success, err code on failure
 {
     if(len == 0) {
         len = strlen(buf);
@@ -587,7 +587,7 @@
         return HTTP_PARSE; //URL is invalid
     }
 
-    if( maxSchemeLen < hostPtr - schemePtr + 1 ) { //including NULL-terminating char
+    if( (uint16_t)maxSchemeLen < hostPtr - schemePtr + 1 ) { //including NULL-terminating char
         WARN("Scheme str is too small (%d >= %d)", maxSchemeLen, hostPtr - schemePtr + 1);
         return HTTP_PARSE;
     }
@@ -653,7 +653,7 @@
     static const char base64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
     unsigned int c, c1, c2, c3;
 
-    if (len < ((((length-1)/3)+1)<<2)) return -1;
+    if ((uint16_t)len < ((((length-1)/3)+1)<<2)) return -1;
     for(unsigned int i = 0, j = 0; i<length; i+=3,j+=4) {
         c1 = ((((unsigned char)*((unsigned char *)&input[i]))));
         c2 = (length>i+1)?((((unsigned char)*((unsigned char *)&input[i+1])))):0;
--- a/HTTPClient.h	Sun Mar 08 17:50:52 2015 +0000
+++ b/HTTPClient.h	Thu Aug 06 11:11:31 2015 +0000
@@ -171,7 +171,7 @@
 
     HTTPResult connect(const char* url, HTTP_METH method, IHTTPDataOut* pDataOut, IHTTPDataIn* pDataIn, int timeout); //Execute request
     HTTPResult recv(char* buf, size_t minLen, size_t maxLen, size_t* pReadLen); //0 on success, err code on failure
-    HTTPResult send(char* buf, size_t len = 0); //0 on success, err code on failure
+    HTTPResult send(const char* buf, size_t len = 0); //0 on success, err code on failure
     HTTPResult parseURL(const char* url, char* scheme, size_t maxSchemeLen, char* host, size_t maxHostLen, uint16_t* port, char* path, size_t maxPathLen); //Parse URL
     void createauth (const char *user, const char *pwd, char *buf, int len);
     int base64enc(const char *input, unsigned int length, char *output, int len);
--- a/data/HTTPFile.cpp	Sun Mar 08 17:50:52 2015 +0000
+++ b/data/HTTPFile.cpp	Thu Aug 06 11:11:31 2015 +0000
@@ -41,7 +41,7 @@
     if (file) {
         written = fwrite(buf, 1, len, file);   
         INFO("  writ:%d, ftell: %d", written, ftell(file)); 
-        if ((!m_chunked && (ftell(file) >= m_len)) || (m_chunked && !written)) {
+        if ((!m_chunked && ((size_t)ftell(file) >= m_len)) || (m_chunked && !written)) {
             INFO("closing");
             close();
         }
--- a/data/HTTPMap.cpp	Sun Mar 08 17:50:52 2015 +0000
+++ b/data/HTTPMap.cpp	Thu Aug 06 11:11:31 2015 +0000
@@ -66,13 +66,13 @@
   //URL encode
   char* out = buf;
   const char* in = m_keys[m_pos];
-  if( (m_pos != 0) && (out - buf < len - 1) )
+  if( (m_pos != 0) && ((size_t)(out - buf) < len - 1) )
   {
     *out='&';
     out++;
   }
 
-  while( (*in != '\0') && (out - buf < len - 3) )
+  while( (*in != '\0') && ((size_t)(out - buf) < len - 3) )
   {
     if (std::isalnum(*in) || *in == '-' || *in == '_' || *in == '.' || *in == '~')
     {
@@ -97,14 +97,14 @@
     in++;
   }
 
-  if( out - buf < len - 1 )
+  if( (size_t)(out - buf) < len - 1 )
   {
     *out='=';
     out++;
   }
 
   in = m_values[m_pos];
-  while( (*in != '\0') && (out - buf < len - 3) )
+  while( (*in != '\0') && ((size_t)(out - buf) < len - 3) )
   {
     if (std::isalnum(*in) || *in == '-' || *in == '_' || *in == '.' || *in == '~')
     {