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
tcp/http/http.c
- Committer:
- andrewboyson
- Date:
- 2019-01-26
- Revision:
- 117:a725e5ad4fad
- Parent:
- 108:66f17386ffd4
- Child:
- 126:62edacc9f14d
File content as of revision 117:a725e5ad4fad:
#include <stdbool.h> #include "http.h" #include "tcpbuf.h" #include "action.h" #include "net.h" #include "log.h" #include "led.h" #include "fault.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 void HttpHandleRequest(int size, char* pRequestStream, uint32_t positionInRequestStream, int* pToDo) { int lastFaultPoint = FaultPoint; FaultPoint = FAULT_POINT_HttpHandleRequest; if (HttpTrace) { LogF("HTTP <<< %d (%u)\r\n", size, positionInRequestStream); } //Handle request for the first packet of data received but leave todo the same after that. if (size && positionInRequestStream == 0) { char* pMethod; char* pPath; char* pQuery; char* pLastModified; FaultPoint = FAULT_POINT_HttpReadRequest; HttpRequestRead(pRequestStream, size, &pMethod, &pPath, &pQuery, &pLastModified); FaultPoint = FAULT_POINT_HttpRequestFunction; *pToDo = HttpRequestFunction(pPath, pLastModified, pQuery); } FaultPoint = lastFaultPoint; } void HttpSendReply(int* pSize, char* pReplyStream, uint32_t positionInReplyStream, uint16_t mss, int todo) { TcpBufStart(positionInReplyStream, mss, pReplyStream); HttpReplyFunction(todo); *pSize = TcpBufLength(); if (HttpTrace) { LogF("HTTP >>> %d (%d)\r\n", *pSize, positionInReplyStream); } }