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.cpp@54:84ef2b29cf7e, 2017-11-13 (annotated)
- Committer:
- andrewboyson
- Date:
- Mon Nov 13 08:06:55 2017 +0000
- Revision:
- 54:84ef2b29cf7e
- Child:
- 55:e64b8b47a2b6
Tidied HTTP files
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
andrewboyson | 54:84ef2b29cf7e | 1 | #include "mbed.h" |
andrewboyson | 54:84ef2b29cf7e | 2 | #include "http.h" |
andrewboyson | 54:84ef2b29cf7e | 3 | #include "tcpbuf.h" |
andrewboyson | 54:84ef2b29cf7e | 4 | #include "action.h" |
andrewboyson | 54:84ef2b29cf7e | 5 | #include "net.h" |
andrewboyson | 54:84ef2b29cf7e | 6 | #include "log.h" |
andrewboyson | 54:84ef2b29cf7e | 7 | |
andrewboyson | 54:84ef2b29cf7e | 8 | bool HttpTrace = false; |
andrewboyson | 54:84ef2b29cf7e | 9 | |
andrewboyson | 54:84ef2b29cf7e | 10 | void (*HttpReplyFunction )(int todo); //Plumb into this from your html server |
andrewboyson | 54:84ef2b29cf7e | 11 | int (*HttpRequestFunction)(char *pPath, char *pLastModified, char *pQuery); //Plumb into this from your html server |
andrewboyson | 54:84ef2b29cf7e | 12 | |
andrewboyson | 54:84ef2b29cf7e | 13 | int HttpHandleRequest(void (*traceback)(void), int* pSize, char* pRequestStream, int positionInRequestStream, char* pReplyStream, int positionInReplyStream, uint16_t mss, int* pToDo) |
andrewboyson | 54:84ef2b29cf7e | 14 | { |
andrewboyson | 54:84ef2b29cf7e | 15 | if (HttpTrace) |
andrewboyson | 54:84ef2b29cf7e | 16 | { |
andrewboyson | 54:84ef2b29cf7e | 17 | if (NetTraceNewLine) Log("\r\n"); |
andrewboyson | 54:84ef2b29cf7e | 18 | LogTimeF("HTTP packet received starting at %d length %d bytes\r\n", positionInRequestStream, *pSize); |
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 | 54:84ef2b29cf7e | 35 | |
andrewboyson | 54:84ef2b29cf7e | 36 | return UNICAST; |
andrewboyson | 54:84ef2b29cf7e | 37 | } |