Andrew Boyson / net

Dependents:   oldheating gps motorhome heating

tcp/http/httpshim/httpshim.c

Committer:
andrewboyson
Date:
2019-08-20
Revision:
155:22f249751106
Parent:
154:ba9879b19d9f
Child:
156:be12b8fd5b21

File content as of revision 155:22f249751106:

#include <stdbool.h>

#include "http.h"
#include "tcp.h"
#include "tcpbuf.h"
#include "tls.h"

/*
The shim acts as the switch between TCP, TLS and HTTP.
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.
It means TCP  does not need to know if it is talking directly to HTTP or via TLS.
*/

void HttpShimRequest(int size, char* pRequestStream, uint32_t positionInRequestStream, char* pWebState, char* pTlsState, bool secure)
{
    if (secure) TlsRequest         (pTlsState, pWebState, size, (uint8_t*)pRequestStream, positionInRequestStream);
    else        HttpRequestFunction(           pWebState, size,           pRequestStream, positionInRequestStream);
}

static bool tlsRequired;
int HttpShimPoll (bool clientFinished, char* pWebState, char* pTlsState, bool secure)
{
    tlsRequired = secure;
    if (tlsRequired) return TlsPoll         (pTlsState, pWebState, clientFinished);
    else             return HttpPollFunction(           pWebState, clientFinished);
}
void HttpShimAddChar(char c)
{
    if (tlsRequired) TlsAddChar(c);
    else          TcpBufAddChar(c);
}

bool HttpShimBufFilled()
{
    return TcpBufFilled();
}
bool HttpShimGetTrace()
{
    if (tlsRequired) return  TlsTrace;
    else             return HttpTrace;
}