Andrew Boyson / net

Dependents:   oldheating gps motorhome heating

tcp/http/httpshim/httpshim.c

Committer:
andrewboyson
Date:
2019-09-07
Revision:
158:3adf725c0804
Parent:
157:b0bdb77e27f3

File content as of revision 158:3adf725c0804:

#include <stdbool.h>

#include "http.h"
#include "tcp.h"
#include "tcpbuf.h"
#include "tls.h"
#include "led.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 HttpShimReset(bool secure, int connection)
{
    if (secure) TlsReset(connection); //Only reset TLS if appropriate
    HttpFunctionReset(connection);    //Always reset Http
}
void HttpShimRequest(bool secure, int connection, int size, char* pRequestStream, uint32_t positionInRequestStream)
{
    if (secure) TlsRequest         (connection, size, (uint8_t*)pRequestStream, positionInRequestStream);
    else        HttpFunctionRequest(connection, size,           pRequestStream, positionInRequestStream);
}

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

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