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
Diff: tcp/http/http.c
- Revision:
- 61:aad055f1b0d1
- Parent:
- 55:e64b8b47a2b6
- Child:
- 71:736a5747ade1
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tcp/http/http.c Thu Jan 11 17:38:21 2018 +0000 @@ -0,0 +1,43 @@ +#include <stdbool.h> + +#include "http.h" +#include "tcpbuf.h" +#include "action.h" +#include "net.h" +#include "log.h" + +bool HttpTrace = false; + +void (*HttpReplyFunction )(int todo); //Plumb into this from your html server +int (*HttpRequestFunction)(char *pPath, char *pLastModified, char *pQuery); //Plumb into this from your html server + +int HttpHandleRequest(int* pSize, char* pRequestStream, int positionInRequestStream, char* pReplyStream, int positionInReplyStream, uint16_t mss, int* pToDo) +{ + if (HttpTrace) + { + LogF("HTTP <<< %d (%d)\r\n", *pSize, positionInRequestStream); + } + //Handle request for the first packet of data received but leave todo the same after that. + if (*pSize) + { + char* pMethod; + char* pPath; + char* pQuery; + char* pLastModified; + HttpReadRequest(pRequestStream, *pSize, &pMethod, &pPath, &pQuery, &pLastModified); + *pToDo = HttpRequestFunction(pPath, pLastModified, pQuery); + } + + //Handle sending of any data + TcpBufStart(positionInReplyStream, mss, pReplyStream); + HttpReplyFunction(*pToDo); + *pSize = TcpBufLength(); + + if (HttpTrace) + { + LogF("HTTP >>> %d (%d)\r\n", *pSize, positionInReplyStream); + } + + + return UNICAST; +} \ No newline at end of file