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@117:a725e5ad4fad, 2019-01-26 (annotated)
- Committer:
- andrewboyson
- Date:
- Sat Jan 26 15:44:59 2019 +0000
- Revision:
- 117:a725e5ad4fad
- Parent:
- 108:66f17386ffd4
- Child:
- 126:62edacc9f14d
Found bug in function which retrieves the 'If-Last-Modified' line: the lastModified pointer is not initialised so could point anywhere if no line. Although checked for NULL it is not checked for other random values. Initialised to NULL.
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 | 98:b977424ec7f7 | 9 | #include "fault.h" |
andrewboyson | 54:84ef2b29cf7e | 10 | |
andrewboyson | 54:84ef2b29cf7e | 11 | bool HttpTrace = false; |
andrewboyson | 54:84ef2b29cf7e | 12 | |
andrewboyson | 54:84ef2b29cf7e | 13 | void (*HttpReplyFunction )(int todo); //Plumb into this from your html server |
andrewboyson | 54:84ef2b29cf7e | 14 | int (*HttpRequestFunction)(char *pPath, char *pLastModified, char *pQuery); //Plumb into this from your html server |
andrewboyson | 54:84ef2b29cf7e | 15 | |
andrewboyson | 79:f50e02fb5c94 | 16 | void HttpHandleRequest(int size, char* pRequestStream, uint32_t positionInRequestStream, int* pToDo) |
andrewboyson | 54:84ef2b29cf7e | 17 | { |
andrewboyson | 98:b977424ec7f7 | 18 | int lastFaultPoint = FaultPoint; |
andrewboyson | 98:b977424ec7f7 | 19 | FaultPoint = FAULT_POINT_HttpHandleRequest; |
andrewboyson | 98:b977424ec7f7 | 20 | |
andrewboyson | 54:84ef2b29cf7e | 21 | if (HttpTrace) |
andrewboyson | 54:84ef2b29cf7e | 22 | { |
andrewboyson | 79:f50e02fb5c94 | 23 | LogF("HTTP <<< %d (%u)\r\n", size, positionInRequestStream); |
andrewboyson | 54:84ef2b29cf7e | 24 | } |
andrewboyson | 54:84ef2b29cf7e | 25 | //Handle request for the first packet of data received but leave todo the same after that. |
andrewboyson | 75:603b10404183 | 26 | if (size && positionInRequestStream == 0) |
andrewboyson | 54:84ef2b29cf7e | 27 | { |
andrewboyson | 54:84ef2b29cf7e | 28 | char* pMethod; |
andrewboyson | 54:84ef2b29cf7e | 29 | char* pPath; |
andrewboyson | 54:84ef2b29cf7e | 30 | char* pQuery; |
andrewboyson | 54:84ef2b29cf7e | 31 | char* pLastModified; |
andrewboyson | 108:66f17386ffd4 | 32 | FaultPoint = FAULT_POINT_HttpReadRequest; |
andrewboyson | 117:a725e5ad4fad | 33 | HttpRequestRead(pRequestStream, size, &pMethod, &pPath, &pQuery, &pLastModified); |
andrewboyson | 108:66f17386ffd4 | 34 | FaultPoint = FAULT_POINT_HttpRequestFunction; |
andrewboyson | 54:84ef2b29cf7e | 35 | *pToDo = HttpRequestFunction(pPath, pLastModified, pQuery); |
andrewboyson | 54:84ef2b29cf7e | 36 | } |
andrewboyson | 98:b977424ec7f7 | 37 | FaultPoint = lastFaultPoint; |
andrewboyson | 71:736a5747ade1 | 38 | } |
andrewboyson | 79:f50e02fb5c94 | 39 | void HttpSendReply(int* pSize, char* pReplyStream, uint32_t positionInReplyStream, uint16_t mss, int todo) |
andrewboyson | 71:736a5747ade1 | 40 | { |
andrewboyson | 54:84ef2b29cf7e | 41 | TcpBufStart(positionInReplyStream, mss, pReplyStream); |
andrewboyson | 71:736a5747ade1 | 42 | HttpReplyFunction(todo); |
andrewboyson | 54:84ef2b29cf7e | 43 | *pSize = TcpBufLength(); |
andrewboyson | 55:e64b8b47a2b6 | 44 | |
andrewboyson | 55:e64b8b47a2b6 | 45 | if (HttpTrace) |
andrewboyson | 55:e64b8b47a2b6 | 46 | { |
andrewboyson | 55:e64b8b47a2b6 | 47 | LogF("HTTP >>> %d (%d)\r\n", *pSize, positionInReplyStream); |
andrewboyson | 55:e64b8b47a2b6 | 48 | } |
andrewboyson | 71:736a5747ade1 | 49 | } |