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:
Wed May 15 15:33:15 2019 +0000
Revision:
146:0fc66d610fd6
Child:
147:a6093b52e654
Tidied the http shim

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 146:0fc66d610fd6 14 void HttpShimRequest(int size, char* pRequestStream, uint32_t positionInRequestStream, char* pState, bool secure)
andrewboyson 146:0fc66d610fd6 15 {
andrewboyson 146:0fc66d610fd6 16 if (secure) TlsRequest (size, pRequestStream, positionInRequestStream, pState);
andrewboyson 146:0fc66d610fd6 17 else HttpRequestFunction(size, pRequestStream, positionInRequestStream, pState);
andrewboyson 146:0fc66d610fd6 18 }
andrewboyson 146:0fc66d610fd6 19
andrewboyson 146:0fc66d610fd6 20 static bool tlsRequired;
andrewboyson 146:0fc66d610fd6 21 bool HttpShimReplyPoll (char* pState, bool clientFinished, bool secure)
andrewboyson 146:0fc66d610fd6 22 {
andrewboyson 146:0fc66d610fd6 23 tlsRequired = secure;
andrewboyson 146:0fc66d610fd6 24 if (secure) return TlsReplyPoll (pState, clientFinished);
andrewboyson 146:0fc66d610fd6 25 else return HttpReplyPollFunction(pState, clientFinished);
andrewboyson 146:0fc66d610fd6 26 }
andrewboyson 146:0fc66d610fd6 27 void HttpShimAddChar (char c)
andrewboyson 146:0fc66d610fd6 28 {
andrewboyson 146:0fc66d610fd6 29 if (tlsRequired) TlsAddChar(c);
andrewboyson 146:0fc66d610fd6 30 else TcpBufAddChar(c);
andrewboyson 146:0fc66d610fd6 31 }
andrewboyson 146:0fc66d610fd6 32
andrewboyson 146:0fc66d610fd6 33 bool HttpShimBufFilled()
andrewboyson 146:0fc66d610fd6 34 {
andrewboyson 146:0fc66d610fd6 35 return TcpBufFilled();
andrewboyson 146:0fc66d610fd6 36 }
andrewboyson 146:0fc66d610fd6 37 bool HttpShimGetTrace()
andrewboyson 146:0fc66d610fd6 38 {
andrewboyson 146:0fc66d610fd6 39 return HttpTrace;
andrewboyson 146:0fc66d610fd6 40 }