-
-
Notifications
You must be signed in to change notification settings - Fork 345
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move HTTP strings into flash and provide suitable functions (#1459)
* Move HTTP strings into flash and provide suitable functions http-parser - patch update * place tokens[] into flash memory and use get_token() function instead - doesn't rely on mforce32 compiler support to save RAM * Remove http_errno_name() - replaced with httpGetErrnoName() defined in HttpCommon.cpp. Note the replacement returns a String, not a const char* HttpCommon * Add httpGetErrnoName(), httpGetErrnoDescription() and httpGetStatusText() functions - saves RAM by storing text strings in flash HttpServerConnection !! Backwards Incompatible (BC) change. Impact: Low !!! * getStatus() method removed, superseded by httpGetStatusText() function. The _message_ parameter is now a const String&, instead of const char*. As the default value is nullptr, if () statement works as expected. FlashString.h * Add FSTR_TABLE macro Samples/Basic_Progmem * Add demo code for use of FSTR_TABLE
- Loading branch information
Showing
8 changed files
with
226 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/**** | ||
* Sming Framework Project - Open Source framework for high efficiency native ESP8266 development. | ||
* Created 2015 by Skurydin Alexey | ||
* http://github.com/SmingHub/Sming | ||
* All files of the Sming Core are provided under the LGPL v3 license. | ||
* | ||
* @author: 2018 - Mikee47 <[email protected]> | ||
* | ||
* httpGetErrorName(), httpGetErrorDescription() and httpGetStatusText() functions added | ||
* | ||
****/ | ||
|
||
#include "HttpCommon.h" | ||
|
||
// Define flash strings and lookup table for HTTP error names | ||
#define XX(_n, _s) static DEFINE_FSTR(hpename_##_n, "HPE_" #_n); | ||
HTTP_ERRNO_MAP(XX) | ||
#undef XX | ||
|
||
static FSTR_TABLE(hpeNames) = { | ||
#define XX(_n, _s) FSTR_PTR(hpename_##_n), | ||
HTTP_ERRNO_MAP(XX) | ||
#undef XX | ||
}; | ||
|
||
String httpGetErrorName(enum http_errno err) | ||
{ | ||
if(err > HPE_UNKNOWN) | ||
return F("HPE_#") + String(err); | ||
|
||
return *hpeNames[err]; | ||
} | ||
|
||
// Define flash strings and lookup table for HTTP error descriptions | ||
#define XX(_n, _s) static DEFINE_FSTR(hpedesc_##_n, _s); | ||
HTTP_ERRNO_MAP(XX) | ||
#undef XX | ||
|
||
static FSTR_TABLE(hpeDescriptions) = { | ||
#define XX(_n, _s) FSTR_PTR(hpedesc_##_n), | ||
HTTP_ERRNO_MAP(XX) | ||
#undef XX | ||
}; | ||
|
||
String httpGetErrorDescription(enum http_errno err) | ||
{ | ||
if(err > HPE_UNKNOWN) | ||
return F("HPE_#") + String(err); | ||
|
||
return *hpeDescriptions[err]; | ||
} | ||
|
||
// Define flash strings for HTTP status codes | ||
#define XX(_num, _name, _string) static DEFINE_FSTR(hpsText_##_num, #_string); | ||
HTTP_STATUS_MAP(XX) | ||
#undef XX | ||
|
||
String httpGetStatusText(enum http_status code) | ||
{ | ||
switch(code) { | ||
#define XX(_num, _name, _string) \ | ||
case _num: \ | ||
return hpsText_##_num; | ||
HTTP_STATUS_MAP(XX) | ||
#undef XX | ||
default: | ||
return F("<unknown_") + String(code) + '>'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters