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: Car_Bon_car_module
Fork of HTTPClient by
Revision 23:96a9385ceeb6, committed 2014-03-14
- Comitter:
- ansond
- Date:
- Fri Mar 14 21:25:55 2014 +0000
- Parent:
- 22:f6a3fcf48751
- Child:
- 24:07dc6a23ca28
- Commit message:
- updates
Changed in this revision
| HTTPClient.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/HTTPClient.cpp Fri Mar 14 20:03:23 2014 +0000
+++ b/HTTPClient.cpp Fri Mar 14 21:25:55 2014 +0000
@@ -58,19 +58,17 @@
void HTTPClient::basicAuth(const char* user, const char* password) //Basic Authentification
{
- #if 1
- if (m_basicAuthUser)
- free(m_basicAuthUser);
- m_basicAuthUser = (char *)malloc(strlen(user)+1);
- strcpy(m_basicAuthUser, user);
- if (m_basicAuthPassword)
- free(m_basicAuthPassword);
- m_basicAuthPassword = (char *)malloc(strlen(password)+1);
- strcpy(m_basicAuthPassword, password);
- #else
- m_basicAuthUser = user;
- m_basicAuthPassword = password;
- #endif
+ if (m_basicAuthUser) free(m_basicAuthUser);
+ if (user != NULL) {
+ m_basicAuthUser = (char *)malloc(strlen(user)+1);
+ strcpy(m_basicAuthUser, user);
+ }
+
+ if (m_basicAuthPassword) free(m_basicAuthPassword);
+ if (password != NULL) {
+ m_basicAuthPassword = (char *)malloc(strlen(password)+1);
+ strcpy(m_basicAuthPassword, password);
+ }
}
void HTTPClient::customHeaders(const char **headers, size_t pairs)
@@ -133,7 +131,9 @@
m_httpResponseCode = 0; //Invalidate code
m_timeout = timeout;
- pDataIn->writeReset();
+ if (pDataIn) {
+ pDataIn->writeReset();
+ }
if( pDataOut ) {
pDataOut->readReset();
}
@@ -169,7 +169,8 @@
//Send request
DBG("Sending request");
- char buf[CHUNK_SIZE+1];
+ char buf[CHUNK_SIZE];
+ memset(buf,0,CHUNK_SIZE);
const char* meth = (method==HTTP_GET)?"GET":(method==HTTP_POST)?"POST":(method==HTTP_PUT)?"PUT":(method==HTTP_DELETE)?"DELETE":"";
snprintf(buf, sizeof(buf), "%s %s HTTP/1.1\r\nHost: %s:%d\r\nConnection: keep-alive\r\n", meth, path, host, port); //Write request
ret = send(buf);
@@ -336,13 +337,13 @@
buf[crlfPos] = '\0';
- char key[40];
- char value[40];
+ char key[41];
+ char value[41];
+
+ memset(key,0,41);
+ memset(value,0,41);
- key[31] = '\0';
- value[31] = '\0';
-
- int n = sscanf(buf, "%35[^:]: %35[^\r\n]", key, value);
+ int n = sscanf(buf, "%40[^:]: %40[^\r\n]", key, value);
if ( n == 2 ) {
DBG("Read header : %s: %s\n", key, value);
if( !strcmp(key, "Content-Length") ) {
