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

Dependents:   heating gps

tcp/http/httpshim/httpshim.c

Committer:
andrewboyson
Date:
5 weeks ago
Revision:
146:0fc66d610fd6
Child:
147:a6093b52e654

File content as of revision 146:0fc66d610fd6:

#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* pState, bool secure)
{
    if (secure) TlsRequest         (size, pRequestStream, positionInRequestStream, pState);
    else        HttpRequestFunction(size, pRequestStream, positionInRequestStream, pState);
}

static bool tlsRequired;
bool HttpShimReplyPoll (char* pState, bool clientFinished, bool secure)
{
    tlsRequired = secure;
    if (secure) return TlsReplyPoll         (pState, clientFinished);
    else        return HttpReplyPollFunction(pState, clientFinished);
}
void HttpShimAddChar  (char c)
{
    if (tlsRequired) TlsAddChar(c);
    else          TcpBufAddChar(c);
}

bool HttpShimBufFilled()
{
    return TcpBufFilled();
}
bool HttpShimGetTrace()
{
    return HttpTrace;
}