A stack which works with or without an Mbed os library. Provides IPv4 or IPv6 with a full 1500 byte buffer.

Dependents:   oldheating gps motorhome heating

Committer:
andrewboyson
Date:
Fri May 17 15:01:32 2019 +0000
Revision:
147:a6093b52e654
Parent:
146:0fc66d610fd6
Child:
154:ba9879b19d9f
Split HttpPollReply into HttpPoll and HttpReply to allow TSL to work

Who changed what in which revision?

UserRevisionLine numberNew contents of line
andrewboyson 146:0fc66d610fd6 1 #include <stdbool.h>
andrewboyson 146:0fc66d610fd6 2
andrewboyson 146:0fc66d610fd6 3 #include "http.h"
andrewboyson 146:0fc66d610fd6 4 #include "tcp.h"
andrewboyson 146:0fc66d610fd6 5 #include "tcpbuf.h"
andrewboyson 146:0fc66d610fd6 6 #include "tls.h"
andrewboyson 146:0fc66d610fd6 7
andrewboyson 146:0fc66d610fd6 8 /*
andrewboyson 146:0fc66d610fd6 9 The shim acts as the switch between TCP, TLS and HTTP.
andrewboyson 146:0fc66d610fd6 10 It means HTTP does not need to know if it is talking directly to TCP as HTTP or via TLS in the form of HTTPS.
andrewboyson 146:0fc66d610fd6 11 It means TCP does not need to know if it is talking directly to HTTP or via TLS.
andrewboyson 146:0fc66d610fd6 12 */
andrewboyson 146:0fc66d610fd6 13
andrewboyson 147:a6093b52e654 14 void HttpShimRequest(int size, char* pRequestStream, uint32_t positionInRequestStream, char* pWebState, char* pTlsState, bool secure)
andrewboyson 146:0fc66d610fd6 15 {
andrewboyson 147:a6093b52e654 16 if (secure) TlsRequest (pTlsState, pWebState, size, pRequestStream, positionInRequestStream);
andrewboyson 147:a6093b52e654 17 else HttpRequestFunction( pWebState, size, pRequestStream, positionInRequestStream);
andrewboyson 146:0fc66d610fd6 18 }
andrewboyson 146:0fc66d610fd6 19
andrewboyson 146:0fc66d610fd6 20 static bool tlsRequired;
andrewboyson 147:a6093b52e654 21 int HttpShimPoll (bool clientFinished, char* pWebState, char* pTlsState, bool secure)
andrewboyson 146:0fc66d610fd6 22 {
andrewboyson 146:0fc66d610fd6 23 tlsRequired = secure;
andrewboyson 147:a6093b52e654 24 if (tlsRequired) return TlsPoll (pTlsState, pWebState, clientFinished);
andrewboyson 147:a6093b52e654 25 else return HttpPollFunction( pWebState, clientFinished);
andrewboyson 147:a6093b52e654 26 }
andrewboyson 147:a6093b52e654 27 bool HttpShimReply(char* pWebState, char* pTlsState)
andrewboyson 147:a6093b52e654 28 {
andrewboyson 147:a6093b52e654 29 if (tlsRequired) return TlsReply (pTlsState, pWebState);
andrewboyson 147:a6093b52e654 30 else return HttpReplyFunction( pWebState);
andrewboyson 146:0fc66d610fd6 31 }
andrewboyson 146:0fc66d610fd6 32 void HttpShimAddChar (char c)
andrewboyson 146:0fc66d610fd6 33 {
andrewboyson 146:0fc66d610fd6 34 if (tlsRequired) TlsAddChar(c);
andrewboyson 146:0fc66d610fd6 35 else TcpBufAddChar(c);
andrewboyson 146:0fc66d610fd6 36 }
andrewboyson 146:0fc66d610fd6 37
andrewboyson 146:0fc66d610fd6 38 bool HttpShimBufFilled()
andrewboyson 146:0fc66d610fd6 39 {
andrewboyson 146:0fc66d610fd6 40 return TcpBufFilled();
andrewboyson 146:0fc66d610fd6 41 }
andrewboyson 146:0fc66d610fd6 42 bool HttpShimGetTrace()
andrewboyson 146:0fc66d610fd6 43 {
andrewboyson 146:0fc66d610fd6 44 return HttpTrace;
andrewboyson 146:0fc66d610fd6 45 }