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@55:e64b8b47a2b6, 2017-11-13 (annotated)
- Committer:
- andrewboyson
- Date:
- Mon Nov 13 21:46:31 2017 +0000
- Revision:
- 55:e64b8b47a2b6
- Parent:
- 54:84ef2b29cf7e
Rearranged the TCP code
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 | 55:e64b8b47a2b6 | 13 | int HttpHandleRequest(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 | 55:e64b8b47a2b6 | 17 | LogF("HTTP <<< %d (%d)\r\n", *pSize, positionInRequestStream); |
andrewboyson | 54:84ef2b29cf7e | 18 | } |
andrewboyson | 54:84ef2b29cf7e | 19 | //Handle request for the first packet of data received but leave todo the same after that. |
andrewboyson | 54:84ef2b29cf7e | 20 | if (*pSize) |
andrewboyson | 54:84ef2b29cf7e | 21 | { |
andrewboyson | 54:84ef2b29cf7e | 22 | char* pMethod; |
andrewboyson | 54:84ef2b29cf7e | 23 | char* pPath; |
andrewboyson | 54:84ef2b29cf7e | 24 | char* pQuery; |
andrewboyson | 54:84ef2b29cf7e | 25 | char* pLastModified; |
andrewboyson | 54:84ef2b29cf7e | 26 | HttpReadRequest(pRequestStream, *pSize, &pMethod, &pPath, &pQuery, &pLastModified); |
andrewboyson | 54:84ef2b29cf7e | 27 | *pToDo = HttpRequestFunction(pPath, pLastModified, pQuery); |
andrewboyson | 54:84ef2b29cf7e | 28 | } |
andrewboyson | 54:84ef2b29cf7e | 29 | |
andrewboyson | 54:84ef2b29cf7e | 30 | //Handle sending of any data |
andrewboyson | 54:84ef2b29cf7e | 31 | TcpBufStart(positionInReplyStream, mss, pReplyStream); |
andrewboyson | 54:84ef2b29cf7e | 32 | HttpReplyFunction(*pToDo); |
andrewboyson | 54:84ef2b29cf7e | 33 | *pSize = TcpBufLength(); |
andrewboyson | 55:e64b8b47a2b6 | 34 | |
andrewboyson | 55:e64b8b47a2b6 | 35 | if (HttpTrace) |
andrewboyson | 55:e64b8b47a2b6 | 36 | { |
andrewboyson | 55:e64b8b47a2b6 | 37 | LogF("HTTP >>> %d (%d)\r\n", *pSize, positionInReplyStream); |
andrewboyson | 55:e64b8b47a2b6 | 38 | } |
andrewboyson | 55:e64b8b47a2b6 | 39 | |
andrewboyson | 54:84ef2b29cf7e | 40 | |
andrewboyson | 54:84ef2b29cf7e | 41 | return UNICAST; |
andrewboyson | 54:84ef2b29cf7e | 42 | } |