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@75:603b10404183, 2018-10-30 (annotated)
- Committer:
- andrewboyson
- Date:
- Tue Oct 30 22:11:22 2018 +0000
- Revision:
- 75:603b10404183
- Parent:
- 73:43e3d7fb3d60
- Child:
- 79:f50e02fb5c94
A lot of tidying up and prevented requests other than the first packet from doing anything.
Who changed what in which revision?
User | Revision | Line number | New 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 | 75:603b10404183 | 8 | #include "led.h" |
andrewboyson | 54:84ef2b29cf7e | 9 | |
andrewboyson | 54:84ef2b29cf7e | 10 | bool HttpTrace = false; |
andrewboyson | 54:84ef2b29cf7e | 11 | |
andrewboyson | 54:84ef2b29cf7e | 12 | void (*HttpReplyFunction )(int todo); //Plumb into this from your html server |
andrewboyson | 54:84ef2b29cf7e | 13 | int (*HttpRequestFunction)(char *pPath, char *pLastModified, char *pQuery); //Plumb into this from your html server |
andrewboyson | 54:84ef2b29cf7e | 14 | |
andrewboyson | 73:43e3d7fb3d60 | 15 | void HttpHandleRequest(int size, char* pRequestStream, int positionInRequestStream, int* pToDo) |
andrewboyson | 54:84ef2b29cf7e | 16 | { |
andrewboyson | 54:84ef2b29cf7e | 17 | if (HttpTrace) |
andrewboyson | 54:84ef2b29cf7e | 18 | { |
andrewboyson | 73:43e3d7fb3d60 | 19 | LogF("HTTP <<< %d (%d)\r\n", size, positionInRequestStream); |
andrewboyson | 54:84ef2b29cf7e | 20 | } |
andrewboyson | 54:84ef2b29cf7e | 21 | //Handle request for the first packet of data received but leave todo the same after that. |
andrewboyson | 75:603b10404183 | 22 | if (size && positionInRequestStream == 0) |
andrewboyson | 54:84ef2b29cf7e | 23 | { |
andrewboyson | 54:84ef2b29cf7e | 24 | char* pMethod; |
andrewboyson | 54:84ef2b29cf7e | 25 | char* pPath; |
andrewboyson | 54:84ef2b29cf7e | 26 | char* pQuery; |
andrewboyson | 54:84ef2b29cf7e | 27 | char* pLastModified; |
andrewboyson | 73:43e3d7fb3d60 | 28 | HttpReadRequest(pRequestStream, size, &pMethod, &pPath, &pQuery, &pLastModified); |
andrewboyson | 54:84ef2b29cf7e | 29 | *pToDo = HttpRequestFunction(pPath, pLastModified, pQuery); |
andrewboyson | 54:84ef2b29cf7e | 30 | } |
andrewboyson | 54:84ef2b29cf7e | 31 | |
andrewboyson | 71:736a5747ade1 | 32 | } |
andrewboyson | 71:736a5747ade1 | 33 | void HttpSendReply(int* pSize, char* pReplyStream, int positionInReplyStream, uint16_t mss, int todo) |
andrewboyson | 71:736a5747ade1 | 34 | { |
andrewboyson | 54:84ef2b29cf7e | 35 | TcpBufStart(positionInReplyStream, mss, pReplyStream); |
andrewboyson | 71:736a5747ade1 | 36 | HttpReplyFunction(todo); |
andrewboyson | 54:84ef2b29cf7e | 37 | *pSize = TcpBufLength(); |
andrewboyson | 55:e64b8b47a2b6 | 38 | |
andrewboyson | 55:e64b8b47a2b6 | 39 | if (HttpTrace) |
andrewboyson | 55:e64b8b47a2b6 | 40 | { |
andrewboyson | 55:e64b8b47a2b6 | 41 | LogF("HTTP >>> %d (%d)\r\n", *pSize, positionInReplyStream); |
andrewboyson | 55:e64b8b47a2b6 | 42 | } |
andrewboyson | 71:736a5747ade1 | 43 | } |