Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: oldheating gps motorhome heating
Revision 146:0fc66d610fd6, committed 2019-05-15
- Comitter:
- andrewboyson
- Date:
- Wed May 15 15:33:15 2019 +0000
- Parent:
- 145:206bf0d073c7
- Child:
- 147:a6093b52e654
- Commit message:
- Tidied the http shim
Changed in this revision
--- a/tcp/http/http.c Tue May 14 15:09:39 2019 +0000 +++ b/tcp/http/http.c Wed May 15 15:33:15 2019 +0000 @@ -1,4 +1,8 @@ #include <stdbool.h> +#include <stdint.h> bool HttpTrace = false; -bool HttpsTrace = false; + +//Plumb into these from your html server +void (*HttpRequestFunction)(int size, char* pRequestStream, uint32_t positionInRequestStream, char* pState); +bool (*HttpReplyPollFunction)(char* pState, bool clientFinished);
--- a/tcp/http/http.h Tue May 14 15:09:39 2019 +0000 +++ b/tcp/http/http.h Wed May 15 15:33:15 2019 +0000 @@ -35,7 +35,6 @@ extern void HttpQueryUnencode (char* pValue); extern bool HttpTrace; -extern bool HttpsTrace; extern void HttpDateFromDateTime(const char* date, const char *ptime, char* ptext); extern void HttpDateFromNow(char* pText); @@ -47,9 +46,5 @@ #define HTTP_DATE_LENGTH 30 extern void (*HttpRequestFunction)(int size, char* pRequestStream, uint32_t positionInRequestStream, char* pState); -extern void HttpRequest (int size, char* pRequestStream, uint32_t positionInRequestStream, char* pState); -extern void HttpsRequest (int size, char* pRequestStream, uint32_t positionInRequestStream, char* pState); extern bool (*HttpReplyPollFunction)(char* pState, bool clientFinished); -extern bool HttpReplyPoll (char* pState, bool clientFinished); -extern bool HttpsReplyPoll (char* pState, bool clientFinished);
--- a/tcp/http/httpadd.c Tue May 14 15:09:39 2019 +0000
+++ b/tcp/http/httpadd.c Wed May 15 15:33:15 2019 +0000
@@ -2,12 +2,22 @@
#include <stdio.h>
#include "http.h"
+#include "httpshim.h"
+bool HttpBufFilled(void)
+{
+ return HttpShimBufFilled();
+}
+
+void HttpAddChar(char c)
+{
+ HttpShimAddChar(c);
+}
void HttpFillChar (char c, int length)
{
while (length > 0)
{
- HttpAddChar(c);
+ HttpShimAddChar(c);
length--;
}
}
@@ -16,7 +26,7 @@
const char* start = text;
while (*text)
{
- HttpAddChar(*text);
+ HttpShimAddChar(*text);
text++;
}
return text - start;
@@ -40,7 +50,7 @@
{
while (length > 0)
{
- HttpAddChar(*data);
+ HttpShimAddChar(*data);
data++;
length--;
}
@@ -52,7 +62,7 @@
{
int c = enumerateFunction();
if (c == EOF) break;
- HttpAddChar(c);
+ HttpShimAddChar(c);
}
}
void HttpAddNibbleAsHex(int nibble)
@@ -62,7 +72,7 @@
if (nibble < 0x0A) c = nibble + '0';
else if (nibble < 0x10) c = nibble - 0xA + 'A';
else c = '0';
- HttpAddChar(c);
+ HttpShimAddChar(c);
}
void HttpAddByteAsHex(int value)
{
--- a/tcp/http/httpshim.c Tue May 14 15:09:39 2019 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,39 +0,0 @@
-#include <stdbool.h>
-
-#include "tcp.h"
-#include "tcpbuf.h"
-#include "tls.h"
-
-//Plumb into these from your html server
-void (*HttpRequestFunction)(int size, char* pRequestStream, uint32_t positionInRequestStream, char* pState);
-bool (*HttpReplyPollFunction)(char* pState, bool clientFinished);
-
-void HttpRequest(int size, char* pRequestStream, uint32_t positionInRequestStream, char* pState)
-{
- HttpRequestFunction(size, pRequestStream, positionInRequestStream, pState);
-}
-void HttpsRequest(int size, char* pRequestStream, uint32_t positionInRequestStream, char* pState)
-{
- TlsRequest (size, pRequestStream, positionInRequestStream, pState);
-}
-bool HttpBufFilled(void)
-{
- return TcpBufFilled();
-}
-
-static bool tlsRequired;
-bool HttpReplyPoll (char* pState, bool clientFinished)
-{
- tlsRequired = false;
- return HttpReplyPollFunction(pState, clientFinished);
-}
-bool HttpsReplyPoll(char* pState, bool clientFinished)
-{
- tlsRequired = true;
- return TlsReplyPoll(pState, clientFinished);
-}
-void HttpAddChar (char c)
-{
- if (tlsRequired) TlsAddChar(c);
- else TcpBufAddChar(c);
-}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tcp/http/httpshim/httpshim.c Wed May 15 15:33:15 2019 +0000
@@ -0,0 +1,40 @@
+#include <stdbool.h>
+
+#include "http.h"
+#include "tcp.h"
+#include "tcpbuf.h"
+#include "tls.h"
+
+/*
+The shim acts as the switch between TCP, TLS and HTTP.
+It means HTTP does not need to know if it is talking directly to TCP as HTTP or via TLS in the form of HTTPS.
+It means TCP does not need to know if it is talking directly to HTTP or via TLS.
+*/
+
+void HttpShimRequest(int size, char* pRequestStream, uint32_t positionInRequestStream, char* pState, bool secure)
+{
+ if (secure) TlsRequest (size, pRequestStream, positionInRequestStream, pState);
+ else HttpRequestFunction(size, pRequestStream, positionInRequestStream, pState);
+}
+
+static bool tlsRequired;
+bool HttpShimReplyPoll (char* pState, bool clientFinished, bool secure)
+{
+ tlsRequired = secure;
+ if (secure) return TlsReplyPoll (pState, clientFinished);
+ else return HttpReplyPollFunction(pState, clientFinished);
+}
+void HttpShimAddChar (char c)
+{
+ if (tlsRequired) TlsAddChar(c);
+ else TcpBufAddChar(c);
+}
+
+bool HttpShimBufFilled()
+{
+ return TcpBufFilled();
+}
+bool HttpShimGetTrace()
+{
+ return HttpTrace;
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tcp/http/httpshim/httpshim.h Wed May 15 15:33:15 2019 +0000 @@ -0,0 +1,12 @@ +#include <stdint.h> +#include <stdbool.h> + +extern void HttpShimRequest(int size, char* pRequestStream, uint32_t positionInRequestStream, char* pState, bool secure); + +extern bool HttpShimReplyPoll(char* pState, bool clientFinished, bool secure); + +extern void HttpShimAddChar(char c); + +extern bool HttpShimBufFilled(void); + +extern bool HttpShimGetTrace(void); \ No newline at end of file
--- a/tcp/tcpbuf.c Tue May 14 15:09:39 2019 +0000 +++ b/tcp/tcpbuf.c Wed May 15 15:33:15 2019 +0000 @@ -1,7 +1,5 @@ #include <stdbool.h> -#include <stdio.h> - -#include "http.h" +#include <stdint.h> static uint32_t currentPositionInMessage; static uint32_t bufferPositionInMessage;
--- a/tcp/tcpbuf.h Tue May 14 15:09:39 2019 +0000 +++ b/tcp/tcpbuf.h Wed May 15 15:33:15 2019 +0000 @@ -1,8 +1,7 @@ -#include <stdarg.h> #include <stdint.h> #include <stdbool.h> -extern void TcpBufStart (uint32_t position, int mss, char *pData); -extern void TcpBufAddChar (char c); -extern int TcpBufLength (void); -extern bool TcpBufFilled (void); \ No newline at end of file +extern void TcpBufStart (uint32_t position, int mss, char *pData); +extern void TcpBufAddChar(char c); +extern int TcpBufLength (void); +extern bool TcpBufFilled (void); \ No newline at end of file
--- a/tcp/tcprecv.c Tue May 14 15:09:39 2019 +0000
+++ b/tcp/tcprecv.c Wed May 15 15:33:15 2019 +0000
@@ -11,7 +11,7 @@
#include "tcb.h"
#include "ip4.h"
#include "dhcp.h"
-#include "http.h"
+#include "httpshim.h"
#include "led.h"
#include "mstimer.h"
#include "restart.h"
@@ -57,9 +57,9 @@
char* pData = (char*)pPacket + TcpHdrSizeGet();
switch (pTcb->locPort)
{
- case 80: HttpRequest (dataLength, pData, position, pTcb->appData); break;
- case 443: HttpsRequest(dataLength, pData, position, pTcb->appData); break;
- default: break;
+ case 80: HttpShimRequest(dataLength, pData, position, pTcb->appData, false); break;
+ case 443: HttpShimRequest(dataLength, pData, position, pTcb->appData, true ); break;
+ default: break;
}
}
static int sendResetFromPacket(int* pSizeTx, void* pPacketTx, int ipType, int remArIndex, int locIpScope, int seqLengthRcvd)
@@ -134,7 +134,7 @@
switch (TcpHdrDstPort)
{
case 80:
- if (HttpTrace)
+ if (HttpShimGetTrace())
{
if (NetTraceNewLine) Log("\r\n");
LogTime("HTTP server request\r\n");
@@ -143,7 +143,7 @@
break;
case 443:
- if (HttpsTrace)
+ if (HttpShimGetTrace())
{
if (NetTraceNewLine) Log("\r\n");
LogTime("HTTPS server request\r\n");
--- a/tcp/tcpsend.c Tue May 14 15:09:39 2019 +0000
+++ b/tcp/tcpsend.c Wed May 15 15:33:15 2019 +0000
@@ -11,7 +11,7 @@
#include "tcb.h"
#include "ip4.h"
#include "dhcp.h"
-#include "http.h"
+#include "httpshim.h"
#include "led.h"
#include "tcpsend.h"
#include "mstimer.h"
@@ -34,15 +34,13 @@
}
}
-
static bool doTrace(uint16_t port)
{
switch (port)
{
- case 80:
- if (HttpTrace) return true;
- default:
- return false;
+ case 80:
+ case 443: return HttpShimGetTrace();
+ default: return false;
}
}
static bool addApplicationData(int *pDataLength, void* pPacket, uint16_t port, uint32_t start, int mss, char* pAppState, bool clientFinished)
@@ -52,8 +50,8 @@
bool finished = false;
switch (port)
{
- case 80: finished = HttpReplyPoll (pAppState, clientFinished); break;
- case 443: finished = HttpsReplyPoll(pAppState, clientFinished); break;
+ case 80: finished = HttpShimReplyPoll(pAppState, clientFinished, false); break;
+ case 443: finished = HttpShimReplyPoll(pAppState, clientFinished, true ); break;
}
*pDataLength = TcpBufLength();
return finished;