my fork
Fork of HTTPClient by
Diff: HTTPClient.cpp
- Revision:
- 34:76aa4f4021c1
- Parent:
- 33:77082c88748a
- Child:
- 35:4e7a9a98be37
diff -r 77082c88748a -r 76aa4f4021c1 HTTPClient.cpp --- a/HTTPClient.cpp Tue Jul 21 01:07:25 2015 +0000 +++ b/HTTPClient.cpp Thu Apr 28 00:55:27 2016 +0000 @@ -17,6 +17,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +#include "settings.h" //Debug is disabled by default #if 0 //Enable debug @@ -58,28 +59,29 @@ static char send_buf[SEND_BUF_SIZE] ; static char *send_buf_p ; -static int SocketReceive(WOLFSSL* ssl, char *buf, int sz, void *ctx) +static int SocketReceive(WOLFSSL* ssl, char *buf, int sz, void *sock) { int n ; int i ; + #define RECV_RETRY 3 - for(i=0; i<RECV_RETRY; i++) { - n = m_sock.receive(buf, sz) ; + n = ((TCPSocketConnection *)sock)->receive(buf, sz) ; if(n >= 0)return n ; - WARN("Retrt Recv") ; + WARN("Retry Recv") ; wait(0.2) ; } ERR("SocketReceive:%d/%d\n", n, sz) ; return n ; + } -static int SocketSend(WOLFSSL* ssl, char *buf, int sz, void *ctx) +static int SocketSend(WOLFSSL* ssl, char *buf, int sz, void *sock) { int n ; wait(0.1) ; - n = m_sock.send(buf, sz); + n = ((TCPSocketConnection *)sock)->send(buf, sz); if(n > 0) { wait(0.3) ; return n ; @@ -195,13 +197,23 @@ HTTPResult HTTPClient::setSSLversion(int minorV) { - if((minorV>=0) && (minorV<=3)) - SSLver = minorV ; - else return HTTP_ERROR ; + switch(minorV) { + #if defined(WOLFSSL_ALLOW_SSLV3) && !defined(NO_OLD_TLS) + case 0 : break ; + #endif + #if !defined(NO_OLD_TLS) + case 1 : break ; + case 2 : break ; + #endif + case 3 : break ; + default: + ERR("Invalid SSL version"); + return HTTP_CONN; + } + SSLver = minorV ; return HTTP_OK ; } - #define CHECK_CONN_ERR(ret) \ do{ \ if(ret) { \ @@ -297,18 +309,25 @@ DBG("SSLver=%d", SSLver) ; if(ctx == NULL) { switch(SSLver) { + #if defined(WOLFSSL_ALLOW_SSLV3) && !defined(NO_OLD_TLS) case 0 : SSLmethod = wolfSSLv3_client_method() ; break ; + #endif + #if !defined(NO_OLD_TLS) case 1 : SSLmethod = wolfTLSv1_client_method() ; break ; case 2 : SSLmethod = wolfTLSv1_1_client_method() ; break ; + #endif case 3 : SSLmethod = wolfTLSv1_2_client_method() ; break ; + default: + ERR("Invalid SSL version"); + return HTTP_CONN; } ctx = wolfSSL_CTX_new((WOLFSSL_METHOD *)SSLmethod); if (ctx == NULL) { @@ -327,7 +346,8 @@ return HTTP_CONN; } } - + wolfSSL_SetIOReadCtx (ssl, (void *)&m_sock) ; + wolfSSL_SetIOWriteCtx(ssl, (void *)&m_sock) ; DBG("ctx=%x, ssl=%x, ssl->ctx->CBIORecv, CBIOSend=%x, %x\n", ctx, ssl, SocketReceive, SocketSend ) ; if (wolfSSL_connect(ssl) != SSL_SUCCESS) {