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
tcp/http/httpsend.c@144:6bd5c54efc7d, 2019-05-12 (annotated)
- Committer:
- andrewboyson
- Date:
- Sun May 12 17:17:49 2019 +0000
- Revision:
- 144:6bd5c54efc7d
- Parent:
- 140:9000ea70b220
Tidied up tcp.
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| andrewboyson | 127:fcdfbfad8770 | 1 | #include <time.h> |
| andrewboyson | 54:84ef2b29cf7e | 2 | #include "tcpbuf.h" |
| andrewboyson | 54:84ef2b29cf7e | 3 | |
| andrewboyson | 144:6bd5c54efc7d | 4 | int HttpGetLength() { return TcpBufLength(); } |
| andrewboyson | 54:84ef2b29cf7e | 5 | void HttpAddChar (char c) { TcpBufAddChar(c); } |
| andrewboyson | 54:84ef2b29cf7e | 6 | void HttpFillChar (char c, int length) { TcpBufFillChar(c, length); } |
| andrewboyson | 54:84ef2b29cf7e | 7 | int HttpAddText (const char* text) { return TcpBufAddText(text); } |
| andrewboyson | 54:84ef2b29cf7e | 8 | int HttpAddV (char *fmt, va_list argptr) { return TcpBufAddV(fmt, argptr); } |
| andrewboyson | 54:84ef2b29cf7e | 9 | int HttpAddF (char *fmt, ...) |
| andrewboyson | 54:84ef2b29cf7e | 10 | { |
| andrewboyson | 54:84ef2b29cf7e | 11 | va_list argptr; |
| andrewboyson | 54:84ef2b29cf7e | 12 | va_start(argptr, fmt); |
| andrewboyson | 54:84ef2b29cf7e | 13 | int size = TcpBufAddV(fmt, argptr); |
| andrewboyson | 54:84ef2b29cf7e | 14 | va_end(argptr); |
| andrewboyson | 54:84ef2b29cf7e | 15 | return size; |
| andrewboyson | 54:84ef2b29cf7e | 16 | } |
| andrewboyson | 54:84ef2b29cf7e | 17 | void HttpAddData (const char* data, int length) { TcpBufAddData(data, length); } |
| andrewboyson | 54:84ef2b29cf7e | 18 | void HttpAddStream(void (*startFunction)(void), int (*enumerateFunction)(void)) { TcpBufAddStream(startFunction, enumerateFunction);} |
| andrewboyson | 96:43eb7a110f1a | 19 | void HttpAddNibbleAsHex(int nibble) |
| andrewboyson | 96:43eb7a110f1a | 20 | { |
| andrewboyson | 96:43eb7a110f1a | 21 | nibble &= 0x0F; |
| andrewboyson | 96:43eb7a110f1a | 22 | char c; |
| andrewboyson | 96:43eb7a110f1a | 23 | if (nibble < 0x0A) c = nibble + '0'; |
| andrewboyson | 96:43eb7a110f1a | 24 | else if (nibble < 0x10) c = nibble - 0xA + 'A'; |
| andrewboyson | 96:43eb7a110f1a | 25 | else c = '0'; |
| andrewboyson | 96:43eb7a110f1a | 26 | HttpAddChar(c); |
| andrewboyson | 96:43eb7a110f1a | 27 | } |
| andrewboyson | 140:9000ea70b220 | 28 | void HttpAddByteAsHex(int value) |
| andrewboyson | 140:9000ea70b220 | 29 | { |
| andrewboyson | 140:9000ea70b220 | 30 | HttpAddNibbleAsHex(value >> 4); |
| andrewboyson | 140:9000ea70b220 | 31 | HttpAddNibbleAsHex(value >> 0); |
| andrewboyson | 140:9000ea70b220 | 32 | } |
| andrewboyson | 96:43eb7a110f1a | 33 | void HttpAddInt12AsHex(int value) |
| andrewboyson | 96:43eb7a110f1a | 34 | { |
| andrewboyson | 96:43eb7a110f1a | 35 | HttpAddNibbleAsHex(value >> 8); |
| andrewboyson | 96:43eb7a110f1a | 36 | HttpAddNibbleAsHex(value >> 4); |
| andrewboyson | 96:43eb7a110f1a | 37 | HttpAddNibbleAsHex(value >> 0); |
| andrewboyson | 96:43eb7a110f1a | 38 | } |
| andrewboyson | 96:43eb7a110f1a | 39 | void HttpAddInt16AsHex(int value) |
| andrewboyson | 96:43eb7a110f1a | 40 | { |
| andrewboyson | 96:43eb7a110f1a | 41 | HttpAddNibbleAsHex(value >> 12); |
| andrewboyson | 96:43eb7a110f1a | 42 | HttpAddNibbleAsHex(value >> 8); |
| andrewboyson | 96:43eb7a110f1a | 43 | HttpAddNibbleAsHex(value >> 4); |
| andrewboyson | 96:43eb7a110f1a | 44 | HttpAddNibbleAsHex(value >> 0); |
| andrewboyson | 96:43eb7a110f1a | 45 | } |
| andrewboyson | 135:a7f026a09543 | 46 | void HttpAddInt32AsHex(int value) |
| andrewboyson | 135:a7f026a09543 | 47 | { |
| andrewboyson | 135:a7f026a09543 | 48 | HttpAddNibbleAsHex(value >> 28); |
| andrewboyson | 135:a7f026a09543 | 49 | HttpAddNibbleAsHex(value >> 24); |
| andrewboyson | 135:a7f026a09543 | 50 | HttpAddNibbleAsHex(value >> 20); |
| andrewboyson | 135:a7f026a09543 | 51 | HttpAddNibbleAsHex(value >> 16); |
| andrewboyson | 135:a7f026a09543 | 52 | HttpAddNibbleAsHex(value >> 12); |
| andrewboyson | 135:a7f026a09543 | 53 | HttpAddNibbleAsHex(value >> 8); |
| andrewboyson | 135:a7f026a09543 | 54 | HttpAddNibbleAsHex(value >> 4); |
| andrewboyson | 135:a7f026a09543 | 55 | HttpAddNibbleAsHex(value >> 0); |
| andrewboyson | 135:a7f026a09543 | 56 | } |
| andrewboyson | 140:9000ea70b220 | 57 | void HttpAddInt64AsHex(int64_t value) |
| andrewboyson | 140:9000ea70b220 | 58 | { |
| andrewboyson | 140:9000ea70b220 | 59 | HttpAddNibbleAsHex(value >> 60); |
| andrewboyson | 140:9000ea70b220 | 60 | HttpAddNibbleAsHex(value >> 56); |
| andrewboyson | 140:9000ea70b220 | 61 | HttpAddNibbleAsHex(value >> 52); |
| andrewboyson | 140:9000ea70b220 | 62 | HttpAddNibbleAsHex(value >> 48); |
| andrewboyson | 140:9000ea70b220 | 63 | HttpAddNibbleAsHex(value >> 44); |
| andrewboyson | 140:9000ea70b220 | 64 | HttpAddNibbleAsHex(value >> 40); |
| andrewboyson | 140:9000ea70b220 | 65 | HttpAddNibbleAsHex(value >> 36); |
| andrewboyson | 140:9000ea70b220 | 66 | HttpAddNibbleAsHex(value >> 32); |
| andrewboyson | 140:9000ea70b220 | 67 | HttpAddNibbleAsHex(value >> 28); |
| andrewboyson | 140:9000ea70b220 | 68 | HttpAddNibbleAsHex(value >> 24); |
| andrewboyson | 140:9000ea70b220 | 69 | HttpAddNibbleAsHex(value >> 20); |
| andrewboyson | 140:9000ea70b220 | 70 | HttpAddNibbleAsHex(value >> 16); |
| andrewboyson | 140:9000ea70b220 | 71 | HttpAddNibbleAsHex(value >> 12); |
| andrewboyson | 140:9000ea70b220 | 72 | HttpAddNibbleAsHex(value >> 8); |
| andrewboyson | 140:9000ea70b220 | 73 | HttpAddNibbleAsHex(value >> 4); |
| andrewboyson | 140:9000ea70b220 | 74 | HttpAddNibbleAsHex(value >> 0); |
| andrewboyson | 140:9000ea70b220 | 75 | } |
| andrewboyson | 127:fcdfbfad8770 | 76 | void HttpAddTm(struct tm* ptm) |
| andrewboyson | 127:fcdfbfad8770 | 77 | { |
| andrewboyson | 127:fcdfbfad8770 | 78 | HttpAddF("%d-%02d-%02d ", ptm->tm_year + 1900, ptm->tm_mon + 1, ptm->tm_mday); |
| andrewboyson | 127:fcdfbfad8770 | 79 | switch(ptm->tm_wday) |
| andrewboyson | 127:fcdfbfad8770 | 80 | { |
| andrewboyson | 127:fcdfbfad8770 | 81 | case 0: HttpAddText("Sun"); break; |
| andrewboyson | 127:fcdfbfad8770 | 82 | case 1: HttpAddText("Mon"); break; |
| andrewboyson | 127:fcdfbfad8770 | 83 | case 2: HttpAddText("Tue"); break; |
| andrewboyson | 127:fcdfbfad8770 | 84 | case 3: HttpAddText("Wed"); break; |
| andrewboyson | 127:fcdfbfad8770 | 85 | case 4: HttpAddText("Thu"); break; |
| andrewboyson | 127:fcdfbfad8770 | 86 | case 5: HttpAddText("Fri"); break; |
| andrewboyson | 127:fcdfbfad8770 | 87 | case 6: HttpAddText("Sat"); break; |
| andrewboyson | 127:fcdfbfad8770 | 88 | default: HttpAddText("???"); break; |
| andrewboyson | 127:fcdfbfad8770 | 89 | } |
| andrewboyson | 127:fcdfbfad8770 | 90 | HttpAddF(" %02d:%02d:%02d", ptm->tm_hour, ptm->tm_min, ptm->tm_sec); |
| andrewboyson | 127:fcdfbfad8770 | 91 | if (ptm->tm_isdst > 0) HttpAddText(" BST"); |
| andrewboyson | 127:fcdfbfad8770 | 92 | else if (ptm->tm_isdst == 0) HttpAddText(" GMT"); |
| andrewboyson | 127:fcdfbfad8770 | 93 | else HttpAddText(" UTC"); |
| andrewboyson | 127:fcdfbfad8770 | 94 | } |