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
web-server-base.c@109:3e82f62c7e1f, 2019-04-29 (annotated)
- Committer:
- andrewboyson
- Date:
- Mon Apr 29 14:45:30 2019 +0000
- Revision:
- 109:3e82f62c7e1f
- Parent:
- web-base.c@108:91bfb40e7487
Tidied names from http to web
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| andrewboyson | 103:91194cc19bbb | 1 | #include "web-base.h" |
| andrewboyson | 109:3e82f62c7e1f | 2 | #include "web-server-derived.h" |
| andrewboyson | 109:3e82f62c7e1f | 3 | #include "web-server-base.h" |
| andrewboyson | 103:91194cc19bbb | 4 | #include "http.h" |
| andrewboyson | 103:91194cc19bbb | 5 | #include "fault.h" |
| andrewboyson | 103:91194cc19bbb | 6 | #include "led.h" |
| andrewboyson | 103:91194cc19bbb | 7 | |
| andrewboyson | 109:3e82f62c7e1f | 8 | #define DO_FAVICON DO_BASE + 0 |
| andrewboyson | 109:3e82f62c7e1f | 9 | #define DO_BASE_CSS DO_BASE + 1 |
| andrewboyson | 109:3e82f62c7e1f | 10 | #define DO_NAV_CSS DO_BASE + 2 |
| andrewboyson | 109:3e82f62c7e1f | 11 | #define DO_TRACE_HTML DO_BASE + 3 |
| andrewboyson | 109:3e82f62c7e1f | 12 | #define DO_TRACE_AJAX DO_BASE + 4 |
| andrewboyson | 109:3e82f62c7e1f | 13 | #define DO_TRACE_SCRIPT DO_BASE + 5 |
| andrewboyson | 109:3e82f62c7e1f | 14 | #define DO_CLOCK_HTML DO_BASE + 6 |
| andrewboyson | 109:3e82f62c7e1f | 15 | #define DO_CLOCK_AJAX DO_BASE + 7 |
| andrewboyson | 109:3e82f62c7e1f | 16 | #define DO_CLOCK_SCRIPT DO_BASE + 8 |
| andrewboyson | 109:3e82f62c7e1f | 17 | #define DO_NET_HTML DO_BASE + 9 |
| andrewboyson | 109:3e82f62c7e1f | 18 | #define DO_NET4_HTML DO_BASE + 10 |
| andrewboyson | 109:3e82f62c7e1f | 19 | #define DO_NET4_AJAX DO_BASE + 11 |
| andrewboyson | 109:3e82f62c7e1f | 20 | #define DO_NET4_SCRIPT DO_BASE + 12 |
| andrewboyson | 109:3e82f62c7e1f | 21 | #define DO_NET6_HTML DO_BASE + 13 |
| andrewboyson | 109:3e82f62c7e1f | 22 | #define DO_NET6_AJAX DO_BASE + 14 |
| andrewboyson | 109:3e82f62c7e1f | 23 | #define DO_NET6_SCRIPT DO_BASE + 15 |
| andrewboyson | 109:3e82f62c7e1f | 24 | #define DO_LOG_HTML DO_BASE + 16 |
| andrewboyson | 109:3e82f62c7e1f | 25 | #define DO_FAULT_HTML DO_BASE + 17 |
| andrewboyson | 109:3e82f62c7e1f | 26 | #define DO_FIRMWARE_HTML DO_BASE + 18 |
| andrewboyson | 109:3e82f62c7e1f | 27 | #define DO_FIRMWARE_AJAX DO_BASE + 19 |
| andrewboyson | 109:3e82f62c7e1f | 28 | #define DO_FIRMWARE_SCRIPT DO_BASE + 20 |
| andrewboyson | 103:91194cc19bbb | 29 | |
| andrewboyson | 109:3e82f62c7e1f | 30 | int WebServerBaseDecideWhatToDo(char *pPath, char* pLastModified) |
| andrewboyson | 103:91194cc19bbb | 31 | { |
| andrewboyson | 103:91194cc19bbb | 32 | if (HttpSameStr(pPath, "/login" )) return DO_LOGIN; |
| andrewboyson | 103:91194cc19bbb | 33 | if (HttpSameStr(pPath, "/clock" )) return DO_CLOCK_HTML; |
| andrewboyson | 103:91194cc19bbb | 34 | if (HttpSameStr(pPath, "/clock-ajax" )) return DO_CLOCK_AJAX; |
| andrewboyson | 103:91194cc19bbb | 35 | if (HttpSameStr(pPath, "/net" )) return DO_NET_HTML; |
| andrewboyson | 103:91194cc19bbb | 36 | if (HttpSameStr(pPath, "/net4" )) return DO_NET4_HTML; |
| andrewboyson | 103:91194cc19bbb | 37 | if (HttpSameStr(pPath, "/net4-ajax" )) return DO_NET4_AJAX; |
| andrewboyson | 103:91194cc19bbb | 38 | if (HttpSameStr(pPath, "/net6" )) return DO_NET6_HTML; |
| andrewboyson | 103:91194cc19bbb | 39 | if (HttpSameStr(pPath, "/net6-ajax" )) return DO_NET6_AJAX; |
| andrewboyson | 103:91194cc19bbb | 40 | if (HttpSameStr(pPath, "/log" )) return DO_LOG_HTML; |
| andrewboyson | 103:91194cc19bbb | 41 | if (HttpSameStr(pPath, "/trace" )) return DO_TRACE_HTML; |
| andrewboyson | 103:91194cc19bbb | 42 | if (HttpSameStr(pPath, "/trace-ajax" )) return DO_TRACE_AJAX; |
| andrewboyson | 103:91194cc19bbb | 43 | if (HttpSameStr(pPath, "/fault" )) return DO_FAULT_HTML; |
| andrewboyson | 103:91194cc19bbb | 44 | if (HttpSameStr(pPath, "/firmware" )) return DO_FIRMWARE_HTML; |
| andrewboyson | 103:91194cc19bbb | 45 | if (HttpSameStr(pPath, "/firmware-ajax")) return DO_FIRMWARE_AJAX; |
| andrewboyson | 103:91194cc19bbb | 46 | |
| andrewboyson | 103:91194cc19bbb | 47 | if (HttpSameStr(pPath, "/favicon.ico" )) return HttpSameDate(WebFaviconDate, WebFaviconTime, pLastModified) ? DO_NOT_MODIFIED : DO_FAVICON; |
| andrewboyson | 103:91194cc19bbb | 48 | if (HttpSameStr(pPath, "/base.css" )) return HttpSameDate(WebBaseCssDate, WebBaseCssTime, pLastModified) ? DO_NOT_MODIFIED : DO_BASE_CSS; |
| andrewboyson | 103:91194cc19bbb | 49 | if (HttpSameStr(pPath, "/settings.css" )) return HttpSameDate(WebNavCssDate, WebNavCssTime, pLastModified) ? DO_NOT_MODIFIED : DO_NAV_CSS; |
| andrewboyson | 103:91194cc19bbb | 50 | if (HttpSameStr(pPath, "/net4.js" )) return HttpSameDate(WebNet4ScriptDate, WebNet4ScriptTime, pLastModified) ? DO_NOT_MODIFIED : DO_NET4_SCRIPT; |
| andrewboyson | 103:91194cc19bbb | 51 | if (HttpSameStr(pPath, "/net6.js" )) return HttpSameDate(WebNet6ScriptDate, WebNet6ScriptTime, pLastModified) ? DO_NOT_MODIFIED : DO_NET6_SCRIPT; |
| andrewboyson | 103:91194cc19bbb | 52 | if (HttpSameStr(pPath, "/trace.js" )) return HttpSameDate(WebTraceScriptDate, WebTraceScriptTime, pLastModified) ? DO_NOT_MODIFIED : DO_TRACE_SCRIPT; |
| andrewboyson | 103:91194cc19bbb | 53 | if (HttpSameStr(pPath, "/clock.js" )) return HttpSameDate(WebClockScriptDate, WebClockScriptTime, pLastModified) ? DO_NOT_MODIFIED : DO_CLOCK_SCRIPT; |
| andrewboyson | 103:91194cc19bbb | 54 | if (HttpSameStr(pPath, "/firmware.js" )) return HttpSameDate(WebFirmwareScriptDate, WebFirmwareScriptTime, pLastModified) ? DO_NOT_MODIFIED : DO_FIRMWARE_SCRIPT; |
| andrewboyson | 105:43ef124233cd | 55 | |
| andrewboyson | 109:3e82f62c7e1f | 56 | return WebServerDerivedRequest(pPath, pLastModified); |
| andrewboyson | 103:91194cc19bbb | 57 | } |
| andrewboyson | 109:3e82f62c7e1f | 58 | void WebServerBaseHandleQuery(int todo, char* pQuery) |
| andrewboyson | 103:91194cc19bbb | 59 | { |
| andrewboyson | 103:91194cc19bbb | 60 | switch (todo) |
| andrewboyson | 103:91194cc19bbb | 61 | { |
| andrewboyson | 103:91194cc19bbb | 62 | case DO_LOGIN: WebLoginQuery (pQuery); return; |
| andrewboyson | 103:91194cc19bbb | 63 | case DO_TRACE_AJAX: WebTraceQuery (pQuery); return; |
| andrewboyson | 103:91194cc19bbb | 64 | case DO_CLOCK_AJAX: WebClockQuery (pQuery); return; |
| andrewboyson | 103:91194cc19bbb | 65 | case DO_CLOCK_HTML: WebClockQuery (pQuery); return; |
| andrewboyson | 103:91194cc19bbb | 66 | case DO_LOG_HTML: WebLogQuery (pQuery); return; |
| andrewboyson | 103:91194cc19bbb | 67 | case DO_FAULT_HTML: WebFaultQuery (pQuery); return; |
| andrewboyson | 103:91194cc19bbb | 68 | case DO_FIRMWARE_HTML: WebFirmwareQuery(pQuery); return; |
| andrewboyson | 103:91194cc19bbb | 69 | case DO_FIRMWARE_AJAX: WebFirmwareQuery(pQuery); return; |
| andrewboyson | 103:91194cc19bbb | 70 | } |
| andrewboyson | 109:3e82f62c7e1f | 71 | WebServerDerivedGet(todo, pQuery); |
| andrewboyson | 103:91194cc19bbb | 72 | } |
| andrewboyson | 109:3e82f62c7e1f | 73 | bool WebServerBaseHandlePost(int todo, int contentLength, int contentStart, int size, char* pRequestStream, uint32_t positionInRequestStream) |
| andrewboyson | 103:91194cc19bbb | 74 | { |
| andrewboyson | 103:91194cc19bbb | 75 | switch (todo) |
| andrewboyson | 103:91194cc19bbb | 76 | { |
| andrewboyson | 103:91194cc19bbb | 77 | case DO_FIRMWARE_AJAX: return WebFirmwarePost(contentLength, contentStart, size, pRequestStream, positionInRequestStream); |
| andrewboyson | 103:91194cc19bbb | 78 | } |
| andrewboyson | 109:3e82f62c7e1f | 79 | return WebServerDerivedPost(todo, contentLength, size, pRequestStream, positionInRequestStream); |
| andrewboyson | 103:91194cc19bbb | 80 | } |
| andrewboyson | 103:91194cc19bbb | 81 | |
| andrewboyson | 109:3e82f62c7e1f | 82 | void WebServerBaseReply(int todo) |
| andrewboyson | 103:91194cc19bbb | 83 | { |
| andrewboyson | 103:91194cc19bbb | 84 | //Try all the base modules |
| andrewboyson | 103:91194cc19bbb | 85 | switch (todo) |
| andrewboyson | 103:91194cc19bbb | 86 | { |
| andrewboyson | 109:3e82f62c7e1f | 87 | case DO_NOT_FOUND: HttpNotFound (); return; |
| andrewboyson | 109:3e82f62c7e1f | 88 | case DO_NOT_MODIFIED: HttpNotModified (); return; |
| andrewboyson | 103:91194cc19bbb | 89 | case DO_LOGIN: WebLoginHtml (); return; |
| andrewboyson | 103:91194cc19bbb | 90 | case DO_FAVICON: WebFavicon (); return; |
| andrewboyson | 103:91194cc19bbb | 91 | case DO_BASE_CSS: WebBaseCss (); return; |
| andrewboyson | 103:91194cc19bbb | 92 | case DO_NAV_CSS: WebNavCss (); return; |
| andrewboyson | 103:91194cc19bbb | 93 | case DO_TRACE_HTML: WebTraceHtml (); return; |
| andrewboyson | 103:91194cc19bbb | 94 | case DO_TRACE_AJAX: WebTraceAjax (); return; |
| andrewboyson | 103:91194cc19bbb | 95 | case DO_TRACE_SCRIPT: WebTraceScript (); return; |
| andrewboyson | 103:91194cc19bbb | 96 | case DO_CLOCK_HTML: WebClockHtml (); return; |
| andrewboyson | 103:91194cc19bbb | 97 | case DO_CLOCK_AJAX: WebClockAjax (); return; |
| andrewboyson | 103:91194cc19bbb | 98 | case DO_CLOCK_SCRIPT: WebClockScript (); return; |
| andrewboyson | 103:91194cc19bbb | 99 | case DO_NET_HTML: WebNetHtml (); return; |
| andrewboyson | 103:91194cc19bbb | 100 | case DO_NET4_HTML: WebNet4Html (); return; |
| andrewboyson | 103:91194cc19bbb | 101 | case DO_NET4_AJAX: WebNet4Ajax (); return; |
| andrewboyson | 103:91194cc19bbb | 102 | case DO_NET4_SCRIPT: WebNet4Script (); return; |
| andrewboyson | 103:91194cc19bbb | 103 | case DO_NET6_HTML: WebNet6Html (); return; |
| andrewboyson | 103:91194cc19bbb | 104 | case DO_NET6_AJAX: WebNet6Ajax (); return; |
| andrewboyson | 103:91194cc19bbb | 105 | case DO_NET6_SCRIPT: WebNet6Script (); return; |
| andrewboyson | 103:91194cc19bbb | 106 | case DO_LOG_HTML: WebLogHtml (); return; |
| andrewboyson | 103:91194cc19bbb | 107 | case DO_FAULT_HTML: WebFaultHtml (); return; |
| andrewboyson | 103:91194cc19bbb | 108 | case DO_FIRMWARE_HTML: WebFirmwareHtml (); return; |
| andrewboyson | 103:91194cc19bbb | 109 | case DO_FIRMWARE_AJAX: WebFirmwareAjax (); return; |
| andrewboyson | 103:91194cc19bbb | 110 | case DO_FIRMWARE_SCRIPT: WebFirmwareScript(); return; |
| andrewboyson | 103:91194cc19bbb | 111 | } |
| andrewboyson | 103:91194cc19bbb | 112 | |
| andrewboyson | 103:91194cc19bbb | 113 | //If not called then call the derived (child) module |
| andrewboyson | 109:3e82f62c7e1f | 114 | WebServerDerivedReply(todo); |
| andrewboyson | 103:91194cc19bbb | 115 | } |
| andrewboyson | 103:91194cc19bbb | 116 |