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

Committer:
andrewboyson
Date:
Thu Jan 11 17:38:21 2018 +0000
Revision:
61:aad055f1b0d1
Parent:
tcp/http/http.cpp@55:e64b8b47a2b6
Child:
71:736a5747ade1
Removed dependence on Mbed OS

Who changed what in which revision?

UserRevisionLine numberNew contents of line
andrewboyson 61:aad055f1b0d1 1 #include <stdbool.h>
andrewboyson 61:aad055f1b0d1 2
andrewboyson 54:84ef2b29cf7e 3 #include "http.h"
andrewboyson 54:84ef2b29cf7e 4 #include "tcpbuf.h"
andrewboyson 54:84ef2b29cf7e 5 #include "action.h"
andrewboyson 54:84ef2b29cf7e 6 #include "net.h"
andrewboyson 54:84ef2b29cf7e 7 #include "log.h"
andrewboyson 54:84ef2b29cf7e 8
andrewboyson 54:84ef2b29cf7e 9 bool HttpTrace = false;
andrewboyson 54:84ef2b29cf7e 10
andrewboyson 54:84ef2b29cf7e 11 void (*HttpReplyFunction )(int todo); //Plumb into this from your html server
andrewboyson 54:84ef2b29cf7e 12 int (*HttpRequestFunction)(char *pPath, char *pLastModified, char *pQuery); //Plumb into this from your html server
andrewboyson 54:84ef2b29cf7e 13
andrewboyson 55:e64b8b47a2b6 14 int HttpHandleRequest(int* pSize, char* pRequestStream, int positionInRequestStream, char* pReplyStream, int positionInReplyStream, uint16_t mss, int* pToDo)
andrewboyson 54:84ef2b29cf7e 15 {
andrewboyson 54:84ef2b29cf7e 16 if (HttpTrace)
andrewboyson 54:84ef2b29cf7e 17 {
andrewboyson 55:e64b8b47a2b6 18 LogF("HTTP <<< %d (%d)\r\n", *pSize, positionInRequestStream);
andrewboyson 54:84ef2b29cf7e 19 }
andrewboyson 54:84ef2b29cf7e 20 //Handle request for the first packet of data received but leave todo the same after that.
andrewboyson 54:84ef2b29cf7e 21 if (*pSize)
andrewboyson 54:84ef2b29cf7e 22 {
andrewboyson 54:84ef2b29cf7e 23 char* pMethod;
andrewboyson 54:84ef2b29cf7e 24 char* pPath;
andrewboyson 54:84ef2b29cf7e 25 char* pQuery;
andrewboyson 54:84ef2b29cf7e 26 char* pLastModified;
andrewboyson 54:84ef2b29cf7e 27 HttpReadRequest(pRequestStream, *pSize, &pMethod, &pPath, &pQuery, &pLastModified);
andrewboyson 54:84ef2b29cf7e 28 *pToDo = HttpRequestFunction(pPath, pLastModified, pQuery);
andrewboyson 54:84ef2b29cf7e 29 }
andrewboyson 54:84ef2b29cf7e 30
andrewboyson 54:84ef2b29cf7e 31 //Handle sending of any data
andrewboyson 54:84ef2b29cf7e 32 TcpBufStart(positionInReplyStream, mss, pReplyStream);
andrewboyson 54:84ef2b29cf7e 33 HttpReplyFunction(*pToDo);
andrewboyson 54:84ef2b29cf7e 34 *pSize = TcpBufLength();
andrewboyson 55:e64b8b47a2b6 35
andrewboyson 55:e64b8b47a2b6 36 if (HttpTrace)
andrewboyson 55:e64b8b47a2b6 37 {
andrewboyson 55:e64b8b47a2b6 38 LogF("HTTP >>> %d (%d)\r\n", *pSize, positionInReplyStream);
andrewboyson 55:e64b8b47a2b6 39 }
andrewboyson 55:e64b8b47a2b6 40
andrewboyson 54:84ef2b29cf7e 41
andrewboyson 54:84ef2b29cf7e 42 return UNICAST;
andrewboyson 54:84ef2b29cf7e 43 }