Change buffer sizes to support GR-PEACH
Dependents: GR-PEACH_Azure_Speech
Fork of HTTPClient-SSL by
Revision 30:6fef375c94e6, committed 2014-08-27
- Comitter:
- ansond
- Date:
- Wed Aug 27 21:00:02 2014 +0000
- Parent:
- 29:2d96cc752d19
- Child:
- 31:0675a342e45c
- Commit message:
- synced with HTTPClient-BasicAuth library updates
Changed in this revision
HTTPClient.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/HTTPClient.cpp Wed Aug 27 20:30:29 2014 +0000 +++ b/HTTPClient.cpp Wed Aug 27 21:00:02 2014 +0000 @@ -134,8 +134,19 @@ #define AUTHB_SIZE 128 if((strlen(user) + strlen(password)) >= AUTHB_SIZE) return HTTP_ERROR ; - m_basicAuthUser = user; - m_basicAuthPassword = password; + + if (m_basicAuthUser) free((void *)m_basicAuthUser); + if (user != NULL) { + m_basicAuthUser = (char *)malloc(strlen(user)+1); + strcpy((char *)m_basicAuthUser, user); + } + + if (m_basicAuthPassword) free((void *)m_basicAuthPassword); + if (password != NULL) { + m_basicAuthPassword = (char *)malloc(strlen(password)+1); + strcpy((char *)m_basicAuthPassword, password); + } + return HTTP_OK ; } @@ -316,6 +327,7 @@ //Send request DBG("Sending request"); char buf[CHUNK_SIZE]; + memset(buf,0,CHUNK_SIZE); send_buf_p = send_buf ; // Reset send buffer ; const char* meth = (method==HTTP_GET)?"GET":(method==HTTP_POST)?"POST":(method==HTTP_PUT)?"PUT":(method==HTTP_DELETE)?"DELETE":""; @@ -454,7 +466,7 @@ crlfPtr = strstr(buf, "\r\n"); if(crlfPtr == NULL) { if( trfLen < CHUNK_SIZE - 1 ) { - size_t newTrfLen; + size_t newTrfLen = 0; ret = recv(buf + trfLen, 1, CHUNK_SIZE - trfLen - 1, &newTrfLen); trfLen += newTrfLen; buf[trfLen] = '\0'; @@ -477,13 +489,13 @@ buf[crlfPos] = '\0'; - char key[32]; - char value[32]; + char key[41]; + char value[41]; - key[31] = '\0'; - value[31] = '\0'; + memset(key,0,41); + memset(value,0,41); - int n = sscanf(buf, "%31[^:]: %31[^\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") ) { @@ -534,7 +546,7 @@ } if(!foundCrlf) { //Try to read more if( trfLen < CHUNK_SIZE ) { - size_t newTrfLen; + size_t newTrfLen = 0; ret = recv(buf + trfLen, 0, CHUNK_SIZE - trfLen - 1, &newTrfLen); trfLen += newTrfLen; CHECK_CONN_ERR(ret); @@ -582,7 +594,7 @@ if( recvChunked ) { if(trfLen < 2) { - size_t newTrfLen; + size_t newTrfLen = 0; //Read missing chars to find end of chunk ret = recv(buf + trfLen, 2 - trfLen, CHUNK_SIZE - trfLen - 1, &newTrfLen); CHECK_CONN_ERR(ret);