[Cleanup] Add wrapper to web_server.arg() with flash string arg

This commit is contained in:
TD-er
2021-05-26 02:51:14 +02:00
parent e73948639d
commit 1c7cd15c9e
43 changed files with 195 additions and 111 deletions
+3 -3
View File
@@ -143,9 +143,9 @@ bool CPlugin_011(CPlugin::Function function, struct EventStruct *event, String&
}
int httpmethod = getFormItemInt(F("P011httpmethod"), choice);
String httpuri = web_server.arg(F("P011httpuri"));
String httpheader = web_server.arg(F("P011httpheader"));
String httpbody = web_server.arg(F("P011httpbody"));
String httpuri = webArg(F("P011httpuri"));
String httpheader = webArg(F("P011httpheader"));
String httpbody = webArg(F("P011httpbody"));
strlcpy(customConfig->HttpMethod, methods[httpmethod].c_str(), sizeof(customConfig->HttpMethod));
strlcpy(customConfig->HttpUri, httpuri.c_str(), sizeof(customConfig->HttpUri));
+1 -1
View File
@@ -145,7 +145,7 @@ bool CPlugin_015(CPlugin::Function function, struct EventStruct *event, String&
char thumbprint[60];
String error = F("Specify server thumbprint with exactly 59 symbols string like " CPLUGIN_015_DEFAULT_THUMBPRINT);
if (!safe_strncpy(thumbprint, web_server.arg("c015_thumbprint"), 60) || (strlen(thumbprint) != 59)) {
if (!safe_strncpy(thumbprint, webArg("c015_thumbprint"), 60) || (strlen(thumbprint) != 59)) {
addHtmlError(error);
}
SaveCustomControllerSettings(event->ControllerIndex, (byte *)&thumbprint, sizeof(thumbprint));
+4 -4
View File
@@ -706,10 +706,10 @@ bool CPlugin_018(CPlugin::Function function, struct EventStruct *event, String&
if (customConfig) {
customConfig->reset();
String deveui = web_server.arg(F("deveui"));
String devaddr = web_server.arg(F("devaddr"));
String nskey = web_server.arg(F("nskey"));
String appskey = web_server.arg(F("appskey"));
String deveui = webArg(F("deveui"));
String devaddr = webArg(F("devaddr"));
String nskey = webArg(F("nskey"));
String appskey = webArg(F("appskey"));
strlcpy(customConfig->DeviceEUI, deveui.c_str(), sizeof(customConfig->DeviceEUI));
strlcpy(customConfig->DeviceAddr, devaddr.c_str(), sizeof(customConfig->DeviceAddr));
+1 -1
View File
@@ -143,7 +143,7 @@ boolean Plugin_012(byte function, struct EventStruct *event, String& string)
for (byte varNr = 0; varNr < P12_Nlines; varNr++)
{
if (!safe_strncpy(deviceTemplate[varNr], web_server.arg(getPluginCustomArgName(varNr)), P12_Nchars)) {
if (!safe_strncpy(deviceTemplate[varNr], webArg(getPluginCustomArgName(varNr)), P12_Nchars)) {
error += getCustomTaskSettingsError(varNr);
}
}
+3 -3
View File
@@ -314,7 +314,7 @@ boolean Plugin_016(byte function, struct EventStruct *event, String &string)
strID = F("Code");
strID += (varNr + 1);
if (!safe_strncpy(strCode, web_server.arg(strID), P16_Cchars)) {
if (!safe_strncpy(strCode, webArg(strID), P16_Cchars)) {
strError += strID;
strError += ' ';
}
@@ -326,7 +326,7 @@ boolean Plugin_016(byte function, struct EventStruct *event, String &string)
iCode = 0;
strID = F("ACode");
strID += (varNr + 1);
if (!safe_strncpy(strCode, web_server.arg(strID), P16_Cchars)) {
if (!safe_strncpy(strCode, webArg(strID), P16_Cchars)) {
strError += strID;
strError += ' ';
}
@@ -337,7 +337,7 @@ boolean Plugin_016(byte function, struct EventStruct *event, String &string)
strID = F("Command");
strID += (varNr + 1);
if (!safe_strncpy(P016_data->CommandLines[varNr].Command, web_server.arg(strID), P16_Nchars)) {
if (!safe_strncpy(P016_data->CommandLines[varNr].Command, webArg(strID), P16_Nchars)) {
strError += strID;
}
+1 -1
View File
@@ -120,7 +120,7 @@ boolean Plugin_023(byte function, struct EventStruct *event, String& string)
for (byte varNr = 0; varNr < P23_Nlines; varNr++)
{
if (!safe_strncpy(deviceTemplate[varNr], web_server.arg(getPluginCustomArgName(varNr)), P23_Nchars)) {
if (!safe_strncpy(deviceTemplate[varNr], webArg(getPluginCustomArgName(varNr)), P23_Nchars)) {
error += getCustomTaskSettingsError(varNr);
}
}
+1 -1
View File
@@ -384,7 +384,7 @@ boolean Plugin_036(uint8_t function, struct EventStruct *event, String& string)
for (uint8_t varNr = 0; varNr < P36_Nlines; varNr++)
{
if (!safe_strncpy(P036_data->DisplayLinesV1[varNr].Content, web_server.arg(getPluginCustomArgName(varNr)), P36_NcharsV1)) {
if (!safe_strncpy(P036_data->DisplayLinesV1[varNr].Content, webArg(getPluginCustomArgName(varNr)), P36_NcharsV1)) {
error += getCustomTaskSettingsError(varNr);
}
P036_data->DisplayLinesV1[varNr].Content[P36_NcharsV1 - 1] = 0; // Terminate in case of uninitalized data
+1 -1
View File
@@ -86,7 +86,7 @@ boolean Plugin_037(byte function, struct EventStruct *event, String& string)
{
String argName = F("p037_template");
argName += varNr + 1;
if (!safe_strncpy(deviceTemplate[varNr], web_server.arg(argName).c_str(), sizeof(deviceTemplate[varNr]))) {
if (!safe_strncpy(deviceTemplate[varNr], webArg(argName).c_str(), sizeof(deviceTemplate[varNr]))) {
error += getCustomTaskSettingsError(varNr);
}
}
+2 -2
View File
@@ -83,12 +83,12 @@ boolean Plugin_043(byte function, struct EventStruct *event, String& string)
{
String argc = F("p043_clock");
argc += x;
String plugin1 = web_server.arg(argc);
String plugin1 = webArg(argc);
ExtraTaskSettings.TaskDevicePluginConfigLong[x] = string2TimeLong(plugin1);
argc = F("p043_state");
argc += x;
String plugin2 = web_server.arg(argc);
String plugin2 = webArg(argc);
ExtraTaskSettings.TaskDevicePluginConfig[x] = plugin2.toInt();
}
success = true;
+2 -2
View File
@@ -106,14 +106,14 @@ boolean Plugin_047(byte function, struct EventStruct *event, String& string)
case PLUGIN_WEBFORM_SAVE:
{
String plugin1 = web_server.arg(F("i2c_addr"));
String plugin1 = webArg(F("i2c_addr"));
P047_I2C_ADDR = (int)strtol(plugin1.c_str(), 0, 16);
P047_SENSOR_SLEEP = isFormItemChecked(F("p047_sleep"));
P047_CHECK_VERSION = isFormItemChecked(F("p047_version"));
String plugin4 = web_server.arg(F("p047_i2cSoilMoisture_changeAddr"));
String plugin4 = webArg(F("p047_i2cSoilMoisture_changeAddr"));
P047_NEW_ADDR = (int)strtol(plugin4.c_str(), 0, 16);
P047_CHANGE_ADDR = isFormItemChecked(F("p047_changeAddr"));
+1 -1
View File
@@ -87,7 +87,7 @@ boolean Plugin_048(byte function, struct EventStruct *event, String& string) {
}
case PLUGIN_WEBFORM_SAVE: {
String plugin1 = web_server.arg(F("i2c_addr"));
String plugin1 = webArg(F("i2c_addr"));
Plugin_048_MotorShield_address = (int)strtol(plugin1.c_str(), 0, 16);
Plugin_048_MotorStepsPerRevolution = getFormItemInt(F("p048_MotorStepsPerRevolution"));
+1 -1
View File
@@ -207,7 +207,7 @@ boolean Plugin_075(byte function, struct EventStruct *event, String& string)
String error;
for (byte varNr = 0; varNr < P75_Nlines; varNr++)
{
if (!safe_strncpy(deviceTemplate[varNr], web_server.arg(getPluginCustomArgName(varNr)), P75_Nchars)) {
if (!safe_strncpy(deviceTemplate[varNr], webArg(getPluginCustomArgName(varNr)), P75_Nchars)) {
error += getCustomTaskSettingsError(varNr);
}
}
+1 -1
View File
@@ -157,7 +157,7 @@ boolean Plugin_079(byte function, struct EventStruct *event, String& string)
}
case PLUGIN_WEBFORM_SAVE: {
String i2c_address = web_server.arg(F("i2c_addr"));
String i2c_address = webArg(F("i2c_addr"));
I2C_ADDR_PCFG_P079 = (int)strtol(i2c_address.c_str(), 0, 16);
SHIELD_VER_PCFG_P079 = getFormItemInt(F("p079_shield_type"));
+1 -1
View File
@@ -216,7 +216,7 @@ boolean Plugin_081(byte function, struct EventStruct *event, String& string)
case PLUGIN_WEBFORM_SAVE:
{
String expression = web_server.arg(F("p081_cron_exp"));
String expression = webArg(F("p081_cron_exp"));
String log;
{
char expression_c[PLUGIN_081_EXPRESSION_SIZE];
+1 -1
View File
@@ -154,7 +154,7 @@ boolean Plugin_087(byte function, struct EventStruct *event, String& string) {
if (nullptr != P087_data) {
for (byte varNr = 0; varNr < P87_Nlines; varNr++)
{
P087_data->setLine(varNr, web_server.arg(getPluginCustomArgName(varNr)));
P087_data->setLine(varNr, webArg(getPluginCustomArgName(varNr)));
}
addHtmlError(SaveCustomTaskSettings(event->TaskIndex, P087_data->_lines, P87_Nlines, 0));
+1 -1
View File
@@ -178,7 +178,7 @@ boolean Plugin_089(byte function, struct EventStruct *event, String& string)
char hostname[PLUGIN_089_HOSTNAME_SIZE];
// Reset "Fails" if settings updated
UserVar[event->BaseVarIndex] = 0;
strncpy(hostname, web_server.arg(F("p089_ping_host")).c_str() , sizeof(hostname));
strncpy(hostname, webArg(F("p089_ping_host")).c_str() , sizeof(hostname));
SaveCustomTaskSettings(event->TaskIndex, (byte*)&hostname, PLUGIN_089_HOSTNAME_SIZE);
success = true;
break;
+1 -1
View File
@@ -655,7 +655,7 @@ private:
static void dumpPacket(const uint8_t* packet, size_t length, String& result) {
for (size_t idx = 0; idx < length; ++idx) {
result += formatToHex(packet[idx], EMPTY_STRING);
result += formatToHex(packet[idx], F(""));
result += ' ';
}
}
+1 -1
View File
@@ -169,7 +169,7 @@ boolean Plugin_094(byte function, struct EventStruct *event, String& string) {
if (nullptr != P094_data) {
for (byte varNr = 0; varNr < P94_Nlines; varNr++)
{
P094_data->setLine(varNr, web_server.arg(getPluginCustomArgName(varNr)));
P094_data->setLine(varNr, webArg(getPluginCustomArgName(varNr)));
}
addHtmlError(SaveCustomTaskSettings(event->TaskIndex, P094_data->_lines, P94_Nlines, 0));
+1 -1
View File
@@ -334,7 +334,7 @@ boolean Plugin_099(byte function, struct EventStruct *event, String& string)
String error;
for (int objectNr = 0; objectNr < P099_CONFIG_OBJECTCOUNT; objectNr++) {
if (!safe_strncpy(P099_data->StoredSettings.TouchObjects[objectNr].objectname, web_server.arg(getPluginCustomArgName(objectNr)), P099_MaxObjectNameLength)) {
if (!safe_strncpy(P099_data->StoredSettings.TouchObjects[objectNr].objectname, webArg(getPluginCustomArgName(objectNr)), P099_MaxObjectNameLength)) {
error += getCustomTaskSettingsError(objectNr);
}
P099_data->StoredSettings.TouchObjects[objectNr].objectname[P099_MaxObjectNameLength - 1] = 0; // Terminate in case of uninitalized data
+2 -2
View File
@@ -192,7 +192,7 @@ boolean Plugin_101(byte function, struct EventStruct *event, String& string)
}
// Check IP Address.
if (!safe_strncpy(ipString, web_server.arg(getPluginCustomArgName(0)), IP_BUFF_SIZE_P101)) {
if (!safe_strncpy(ipString, webArg(getPluginCustomArgName(0)), IP_BUFF_SIZE_P101)) {
// msgStr = getCustomTaskSettingsError(0); // Report string too long.
// errorStr += msgStr;
// msgStr = wolStr + msgStr;
@@ -229,7 +229,7 @@ boolean Plugin_101(byte function, struct EventStruct *event, String& string)
}
// Check MAC Address.
if (!safe_strncpy(macString, web_server.arg(getPluginCustomArgName(1)), MAC_BUFF_SIZE_P101)) {
if (!safe_strncpy(macString, webArg(getPluginCustomArgName(1)), MAC_BUFF_SIZE_P101)) {
// msgStr += getCustomTaskSettingsError(1); // Report string too long.
// errorStr += msgStr;
// msgStr = wolStr + msgStr;
+2 -2
View File
@@ -317,7 +317,7 @@ boolean Plugin_103(byte function, struct EventStruct *event, String &string)
{
addLog(LOG_LEVEL_DEBUG, F("isFormItemChecked"));
String probeType(F("K,"));
probeType += web_server.arg(F("Plugin_103_ec_probe_type"));
probeType += webArg(F("Plugin_103_ec_probe_type"));
char setProbeTypeCmd[ATLAS_EZO_RETURN_ARRAY_SIZE] = {0};
_P103_send_I2C_command(I2Cchoice, probeType, setProbeTypeCmd);
}
@@ -370,7 +370,7 @@ boolean Plugin_103(byte function, struct EventStruct *event, String &string)
if (board_type == PH || board_type == EC)
{
char deviceTemperatureTemplate[40] = {0};
String tmpString = web_server.arg(F("Plugin_103_temperature_template"));
String tmpString = webArg(F("Plugin_103_temperature_template"));
safe_strncpy(deviceTemperatureTemplate, tmpString.c_str(), sizeof(deviceTemperatureTemplate) - 1);
ZERO_TERMINATE(deviceTemperatureTemplate); // be sure that our string ends with a \0
+6 -5
View File
@@ -151,7 +151,7 @@ unsigned long hexToUL(const String& input_c, size_t startpos, size_t nrHexDecima
return hexToUL(input_c.substring(startpos, startpos + nrHexDecimals), nrHexDecimals);
}
String formatToHex(unsigned long value, const String& prefix) {
String formatToHex(unsigned long value, const __FlashStringHelper * prefix) {
String result = prefix;
String hex(value, HEX);
@@ -636,11 +636,12 @@ void htmlStrongEscape(String& html)
}
else
{
char s[4];
char s[4] = {0};
sprintf_P(s, PSTR("%03d"), static_cast<int>(html[i]));
escaped += "&#";
escaped += '&';
escaped += '#';
escaped += s;
escaped += ";";
escaped += ';';
}
}
html = escaped;
@@ -964,7 +965,7 @@ void parseStandardConversions(String& s, bool useURLencode) {
SMART_CONV(F("%c_m2dh%"), minutesToDayHour(data.arg1))
SMART_CONV(F("%c_m2dhm%"), minutesToDayHourMinute(data.arg1))
SMART_CONV(F("%c_s2dhms%"), secondsToDayHourMinuteSecond(data.arg1))
SMART_CONV(F("%c_2hex%"), formatToHex(data.arg1, EMPTY_STRING))
SMART_CONV(F("%c_2hex%"), formatToHex(data.arg1, F("")))
#undef SMART_CONV
// Conversions with 2 parameters
+2 -2
View File
@@ -62,7 +62,7 @@ unsigned long hexToUL(const String& input_c,
size_t nrHexDecimals);
String formatToHex(unsigned long value,
const String& prefix);
const __FlashStringHelper * prefix);
String formatToHex(unsigned long value);
@@ -131,7 +131,7 @@ String wrapIfContains(const String& value,
\*********************************************************************************************/
String to_json_object_value(const __FlashStringHelper * object,
const __FlashStringHelper * value);
String to_json_object_value(const __FlashStringHelper * object,
const String& value);
+8 -8
View File
@@ -111,8 +111,8 @@ void addControllerEnabledForm(controllerIndex_t controllerindex) {
ControllerSettingsStruct::VarType varType = ControllerSettingsStruct::CONTROLLER_ENABLED;
bool isAlternativeDisplayName = false;
String displayName = getControllerParameterDisplayName(ProtocolIndex, varType, isAlternativeDisplayName);
String internalName = getControllerParameterInternalName(ProtocolIndex, varType);
const String displayName = getControllerParameterDisplayName(ProtocolIndex, varType, isAlternativeDisplayName);
const String internalName = getControllerParameterInternalName(ProtocolIndex, varType);
addFormCheckBox(displayName, internalName, Settings.ControllerEnabled[controllerindex]);
}
@@ -123,8 +123,8 @@ void addControllerParameterForm(const ControllerSettingsStruct& ControllerSettin
}
bool isAlternativeDisplayName = false;
String displayName = getControllerParameterDisplayName(ProtocolIndex, varType, isAlternativeDisplayName);
String internalName = getControllerParameterInternalName(ProtocolIndex, varType);
const String displayName = getControllerParameterDisplayName(ProtocolIndex, varType, isAlternativeDisplayName);
const String internalName = getControllerParameterInternalName(ProtocolIndex, varType);
switch (varType) {
case ControllerSettingsStruct::CONTROLLER_USE_DNS:
@@ -153,7 +153,7 @@ void addControllerParameterForm(const ControllerSettingsStruct& ControllerSettin
}
case ControllerSettingsStruct::CONTROLLER_USER:
{
size_t fieldMaxLength =
const size_t fieldMaxLength =
ControllerSettings.useExtendedCredentials() ? EXT_SECURITY_MAX_USER_LENGTH : sizeof(SecuritySettings.ControllerUser[0]) - 1;
addFormTextBox(displayName,
internalName,
@@ -163,7 +163,7 @@ void addControllerParameterForm(const ControllerSettingsStruct& ControllerSettin
}
case ControllerSettingsStruct::CONTROLLER_PASS:
{
size_t fieldMaxLength = ControllerSettings.useExtendedCredentials() ? EXT_SECURITY_MAX_PASS_LENGTH : sizeof(SecuritySettings.ControllerPassword[0]) - 1;
const size_t fieldMaxLength = ControllerSettings.useExtendedCredentials() ? EXT_SECURITY_MAX_PASS_LENGTH : sizeof(SecuritySettings.ControllerPassword[0]) - 1;
if (isAlternativeDisplayName) {
// It is not a regular password, thus use normal text field.
addFormTextBox(displayName, internalName,
@@ -295,7 +295,7 @@ void saveControllerParameterForm(ControllerSettingsStruct & ControllerSet
if (!ControllerSettings.UseDNS)
{
String controllerip = web_server.arg(internalName);
String controllerip = webArg(internalName);
str2ip(controllerip, ControllerSettings.IP);
}
break;
@@ -303,7 +303,7 @@ void saveControllerParameterForm(ControllerSettingsStruct & ControllerSet
ControllerSettings.Port = getFormItemInt(internalName, ControllerSettings.Port);
break;
case ControllerSettingsStruct::CONTROLLER_USER:
setControllerUser(controllerindex, ControllerSettings, web_server.arg(internalName));
setControllerUser(controllerindex, ControllerSettings, webArg(internalName));
break;
case ControllerSettingsStruct::CONTROLLER_PASS:
{
+1 -1
View File
@@ -47,7 +47,7 @@ void handleNotFound() {
message += F(" NAME:");
message += web_server.argName(i);
message += F("\n VALUE:");
message += web_server.arg(i);
message += webArg(i);
message += '\n';
}
web_server.send(404, F("text/plain"), message);
+2 -2
View File
@@ -35,10 +35,10 @@ void handle_advanced() {
TXBuffer.startStream();
sendHeadandTail_stdtemplate();
if (web_server.arg(F("edit")).length() != 0)
if (webArg(F("edit")).length() != 0)
{
// Settings.MessageDelay_unused = getFormItemInt(F("messagedelay"));
Settings.IP_Octet = web_server.arg(F("ip")).toInt();
Settings.IP_Octet = webArg(F("ip")).toInt();
strncpy_webserver_arg(Settings.NTPHost, F("ntphost"));
Settings.TimeZone = getFormItemInt(F("timezone"));
TimeChangeRule dst_start(getFormItemInt(F("dststartweek")), getFormItemInt(F("dststartdow")), getFormItemInt(F("dststartmonth")), getFormItemInt(F("dststarthour")), Settings.TimeZone);
+2 -2
View File
@@ -38,7 +38,7 @@ void handle_config() {
if (web_server.args() != 0)
{
String name = web_server.arg(F("name"));
String name = webArg(F("name"));
name.trim();
Settings.Delay = getFormItemInt(F("delay"), Settings.Delay);
@@ -66,7 +66,7 @@ void handle_config() {
copyFormPassword(F("password"), SecuritySettings.Password, sizeof(SecuritySettings.Password));
// SSID 1
safe_strncpy(SecuritySettings.WifiSSID, web_server.arg(F("ssid")).c_str(), sizeof(SecuritySettings.WifiSSID));
safe_strncpy(SecuritySettings.WifiSSID, webArg(F("ssid")).c_str(), sizeof(SecuritySettings.WifiSSID));
copyFormPassword(F("key"), SecuritySettings.WifiKey, sizeof(SecuritySettings.WifiKey));
// SSID 2
+1 -1
View File
@@ -18,7 +18,7 @@ void handle_control() {
checkRAM(F("handle_control"));
# endif // ifndef BUILD_NO_RAM_TRACKER
String webrequest = web_server.arg(F("cmd"));
String webrequest = webArg(F("cmd"));
HandledWebCommand_result res = handle_command_from_web(EventValueSource::Enum::VALUE_SOURCE_HTTP, webrequest);
switch (res) {
+1 -1
View File
@@ -136,7 +136,7 @@ boolean handle_custom(String path) {
}
// handle commands from a custom page
String webrequest = web_server.arg(F("cmd"));
String webrequest = webArg(F("cmd"));
if (webrequest.length() > 0) {
ExecuteCommand_all_config(EventValueSource::Enum::VALUE_SOURCE_HTTP, webrequest.c_str());
+16 -16
View File
@@ -43,7 +43,7 @@ void handle_devices() {
// char tmpString[41];
// String taskindex = web_server.arg(F("index"));
// String taskindex = webArg(F("index"));
pluginID_t taskdevicenumber;
@@ -56,20 +56,20 @@ void handle_devices() {
// String taskdeviceid[CONTROLLER_MAX];
// String taskdevicepin1 = web_server.arg(F("taskdevicepin1")); // "taskdevicepin*" should not be changed because it is uses by plugins
// String taskdevicepin1 = webArg(F("taskdevicepin1")); // "taskdevicepin*" should not be changed because it is uses by plugins
// and expected to be saved by this code
// String taskdevicepin2 = web_server.arg(F("taskdevicepin2"));
// String taskdevicepin3 = web_server.arg(F("taskdevicepin3"));
// String taskdevicepin1pullup = web_server.arg(F("TDPPU"));
// String taskdevicepin1inversed = web_server.arg(F("TDPI"));
// String taskdevicename = web_server.arg(F("TDN"));
// String taskdeviceport = web_server.arg(F("TDP"));
// String taskdevicepin2 = webArg(F("taskdevicepin2"));
// String taskdevicepin3 = webArg(F("taskdevicepin3"));
// String taskdevicepin1pullup = webArg(F("TDPPU"));
// String taskdevicepin1inversed = webArg(F("TDPI"));
// String taskdevicename = webArg(F("TDN"));
// String taskdeviceport = webArg(F("TDP"));
// String taskdeviceformula[VARS_PER_TASK];
// String taskdevicevaluename[VARS_PER_TASK];
// String taskdevicevaluedecimals[VARS_PER_TASK];
// String taskdevicesenddata[CONTROLLER_MAX];
// String taskdeviceglobalsync = web_server.arg(F("TDGS"));
// String taskdeviceenabled = web_server.arg(F("TDE"));
// String taskdeviceglobalsync = webArg(F("TDGS"));
// String taskdeviceenabled = webArg(F("TDE"));
// for (byte varNr = 0; varNr < VARS_PER_TASK; varNr++)
// {
@@ -77,17 +77,17 @@ void handle_devices() {
// String arg = F("TDF");
// arg += varNr + 1;
// arg.toCharArray(argc, 25);
// taskdeviceformula[varNr] = web_server.arg(argc);
// taskdeviceformula[varNr] = webArg(argc);
//
// arg = F("TDVN");
// arg += varNr + 1;
// arg.toCharArray(argc, 25);
// taskdevicevaluename[varNr] = web_server.arg(argc);
// taskdevicevaluename[varNr] = webArg(argc);
//
// arg = F("TDVD");
// arg += varNr + 1;
// arg.toCharArray(argc, 25);
// taskdevicevaluedecimals[varNr] = web_server.arg(argc);
// taskdevicevaluedecimals[varNr] = webArg(argc);
// }
// for (controllerIndex_t controllerNr = 0; controllerNr < CONTROLLER_MAX; controllerNr++)
@@ -96,12 +96,12 @@ void handle_devices() {
// String arg = F("TDID");
// arg += controllerNr + 1;
// arg.toCharArray(argc, 25);
// taskdeviceid[controllerNr] = web_server.arg(argc);
// taskdeviceid[controllerNr] = webArg(argc);
//
// arg = F("TDSD");
// arg += controllerNr + 1;
// arg.toCharArray(argc, 25);
// taskdevicesenddata[controllerNr] = web_server.arg(argc);
// taskdevicesenddata[controllerNr] = webArg(argc);
// }
byte page = getFormItemInt(F("page"), 0);
@@ -333,7 +333,7 @@ void handle_devices_CopySubmittedSettings(taskIndex_t taskIndex, pluginID_t task
update_whenset_FormItemInt(F("taskdevicepin2"), pin2);
update_whenset_FormItemInt(F("taskdevicepin3"), pin3);
setBasicTaskValues(taskIndex, taskdevicetimer,
isFormItemChecked(F("TDE")), web_server.arg(F("TDN")),
isFormItemChecked(F("TDE")), webArg(F("TDN")),
pin1, pin2, pin3);
Settings.TaskDevicePort[taskIndex] = getFormItemInt(F("TDP"), 0);
update_whenset_FormItemInt(F("remoteFeed"), Settings.TaskDeviceDataFeed[taskIndex]);
+7 -7
View File
@@ -32,7 +32,7 @@ void handle_filelist_json() {
navMenuIndex = MENU_INDEX_TOOLS;
TXBuffer.startJsonStream();
String fdelete = web_server.arg(F("delete"));
String fdelete = webArg(F("delete"));
if (tryDeleteFile(fdelete)) {
# if defined(ESP32)
@@ -47,7 +47,7 @@ void handle_filelist_json() {
const int pageSize = 25;
int startIdx = 0;
String fstart = web_server.arg(F("start"));
String fstart = webArg(F("start"));
if (fstart.length() > 0)
{
@@ -141,7 +141,7 @@ void handle_filelist() {
TXBuffer.startStream();
sendHeadandTail_stdtemplate();
String fdelete = web_server.arg(F("delete"));
String fdelete = webArg(F("delete"));
if (tryDeleteFile(fdelete))
{
@@ -161,7 +161,7 @@ void handle_filelist() {
# endif // ifdef USES_C016
const int pageSize = 25;
int startIdx = 0;
String fstart = web_server.arg(F("start"));
String fstart = webArg(F("start"));
if (fstart.length() > 0)
{
@@ -337,17 +337,17 @@ void handle_SDfilelist() {
for (uint8_t i = 0; i < web_server.args(); i++) {
if (web_server.argName(i) == F("delete"))
{
fdelete = web_server.arg(i);
fdelete = webArg(i);
}
if (web_server.argName(i) == F("deletedir"))
{
ddelete = web_server.arg(i);
ddelete = webArg(i);
}
if (web_server.argName(i) == F("chgto"))
{
change_to_dir = web_server.arg(i);
change_to_dir = webArg(i);
}
}
+1 -1
View File
@@ -117,7 +117,7 @@ void handle_json()
bool showTaskDetails = true;
bool showNodes = true;
{
String view = web_server.arg("view");
String view = webArg("view");
if (view.length() != 0) {
if (view == F("sensorupdate")) {
+1 -1
View File
@@ -49,7 +49,7 @@ void handle_log_JSON() {
if (!isLoggedIn()) { return; }
#ifdef WEBSERVER_LOG
TXBuffer.startJsonStream();
String webrequest = web_server.arg(F("view"));
String webrequest = webArg(F("view"));
addHtml(F("{\"Log\": {"));
if (webrequest == F("legend")) {
+28 -6
View File
@@ -93,6 +93,11 @@ void addFormNumericBox(LabelType::Enum label, int value, int min, int max)
addFormNumericBox(getLabel(label), getInternalLabel(label), value, min, max);
}
void addFormNumericBox(const __FlashStringHelper * label, const __FlashStringHelper * id, int value, int min, int max)
{
addFormNumericBox(String(label), String(id), value, min, max);
}
void addFormNumericBox(const String& label, const String& id, int value, int min, int max)
{
addRowLabel_tr_id(label, id);
@@ -121,6 +126,18 @@ void addTaskSelectBox(const String& label, const String& id, taskIndex_t choice)
// ********************************************************************************
// Add a Text Box form
// ********************************************************************************
void addFormTextBox(const __FlashStringHelper * label,
const __FlashStringHelper * id,
const String& value,
int maxlength,
bool readonly,
bool required,
const String& pattern)
{
addRowLabel_tr_id(label, id);
addTextBox(id, value, maxlength, readonly, required, pattern);
}
void addFormTextBox(const String& label,
const String& id,
const String& value,
@@ -165,7 +182,7 @@ void addFormPasswordBox(const String& label, const String& id, const String& pas
bool getFormPassword(const String& id, String& password)
{
password = web_server.arg(id);
password = webArg(id);
return !password.equals(F("*****"));
}
@@ -200,7 +217,7 @@ void addFormIPaccessControlSelect(const String& label, const String& id, int cho
// Add a selector form
// ********************************************************************************
void addFormPinSelect(const String& label, const String& id, int choice)
void addFormPinSelect(const String& label, const __FlashStringHelper * id, int choice)
{
addRowLabel_tr_id(label, id);
addPinSelect(false, id, choice);
@@ -229,6 +246,11 @@ void addFormSelectorI2C(const String& id, int addressCount, const int addresses[
addSelector_Foot();
}
void addFormSelector(const __FlashStringHelper * label, const __FlashStringHelper * id, int optionCount, const __FlashStringHelper * options[], const int indices[], int selectedIndex)
{
addFormSelector(String(label), String(id), optionCount, options, indices, NULL, selectedIndex, false);
}
void addFormSelector(const String& label, const String& id, int optionCount, const __FlashStringHelper * options[], const int indices[], int selectedIndex)
{
addFormSelector(label, id, optionCount, options, indices, NULL, selectedIndex, false);
@@ -381,7 +403,7 @@ int getFormItemInt(const String& key, int defaultValue) {
}
bool getCheckWebserverArg_int(const String& key, int& value) {
const String valueStr = web_server.arg(key);
const String valueStr = webArg(key);
if (valueStr.length() == 0) return false;
return validIntFromString(valueStr, value);
}
@@ -415,7 +437,7 @@ bool isFormItemChecked(const __FlashStringHelper * id)
bool isFormItemChecked(const String& id)
{
return web_server.arg(id) == F("on");
return webArg(id) == F("on");
}
bool isFormItemChecked(const LabelType::Enum& id)
@@ -445,7 +467,7 @@ float getFormItemFloat(const __FlashStringHelper * id)
float getFormItemFloat(const String& id)
{
const String val = web_server.arg(id);
const String val = webArg(id);
float res = 0.0;
if (val.length() > 0) {
validFloatFromString(val, res);
@@ -460,7 +482,7 @@ float getFormItemFloat(const LabelType::Enum& id)
bool isFormItem(const String& id)
{
return web_server.arg(id).length() != 0;
return webArg(id).length() != 0;
}
void copyFormPassword(const String& id, char *pPassword, int maxlength)
+12 -1
View File
@@ -37,6 +37,7 @@ void addFormCheckBox_disabled(LabelType::Enum label, boolean checked);
// Add a Numeric Box form
// ********************************************************************************
void addFormNumericBox(LabelType::Enum label, int value, int min = INT_MIN, int max = INT_MAX);
void addFormNumericBox(const __FlashStringHelper * label, const __FlashStringHelper * id, int value, int min = INT_MIN, int max = INT_MAX);
void addFormNumericBox(const String& label, const String& id, int value, int min = INT_MIN, int max = INT_MAX);
void addFormFloatNumberBox(LabelType::Enum label, float value, float min, float max, byte nrDecimals = 6, float stepsize = 0.0f);
@@ -50,6 +51,14 @@ void addTaskSelectBox(const String& label, const String& id, taskIndex_t choice)
// ********************************************************************************
// Add a Text Box form
// ********************************************************************************
void addFormTextBox(const __FlashStringHelper * label,
const __FlashStringHelper * id,
const String& value,
int maxlength,
bool readonly = false,
bool required = false,
const String& pattern = "");
void addFormTextBox(const String& label,
const String& id,
const String& value,
@@ -91,12 +100,14 @@ void addFormIPaccessControlSelect(const String& label, const String& id, int cho
// Add a selector form
// ********************************************************************************
void addFormPinSelect(const String& label, const String& id, int choice);
void addFormPinSelect(const String& label, const __FlashStringHelper * id, int choice);
void addFormPinSelectI2C(const String& label, const String& id, int choice);
void addFormSelectorI2C(const String& id, int addressCount, const int addresses[], int selectedIndex);
void addFormSelector(const __FlashStringHelper * label, const __FlashStringHelper * id, int optionCount, const __FlashStringHelper * options[], const int indices[], int selectedIndex);
void addFormSelector(const String& label, const String& id, int optionCount, const __FlashStringHelper * options[], const int indices[], int selectedIndex);
void addFormSelector(const String& label, const String& id, int optionCount, const String options[], const int indices[], int selectedIndex);
+1 -1
View File
@@ -95,7 +95,7 @@ void handle_root() {
String sCommand;
boolean rebootCmd = false;
sCommand = web_server.arg(F("cmd"));
sCommand = webArg(F("cmd"));
rebootCmd = strcasecmp_P(sCommand.c_str(), PSTR("reboot")) == 0;
sendHeadandTail_stdtemplate(_HEAD, rebootCmd);
{
+7 -7
View File
@@ -138,7 +138,7 @@ void handle_rules_new() {
const int rulesListPageSize = 25;
int startIdx = 0;
const String fstart = web_server.arg(F("start"));
const String fstart = webArg(F("start"));
if (fstart.length() > 0)
{
@@ -280,8 +280,8 @@ void handle_rules_backup() {
# ifndef BUILD_NO_RAM_TRACKER
checkRAM(F("handle_rules_backup"));
# endif // ifndef BUILD_NO_RAM_TRACKER
String directory = web_server.arg(F("directory"));
String fileName = web_server.arg(F("fileName"));
String directory = webArg(F("directory"));
String fileName = webArg(F("fileName"));
String error;
if (directory.length() > 0)
@@ -339,7 +339,7 @@ void handle_rules_delete() {
# ifndef BUILD_NO_RAM_TRACKER
checkRAM(F("handle_rules_delete"));
# endif // ifndef BUILD_NO_RAM_TRACKER
String fileName = web_server.arg(F("fileName"));
String fileName = webArg(F("fileName"));
fileName = fileName.substring(0, fileName.length() - 4);
bool removed = false;
# ifdef WEBSERVER_RULES_DEBUG
@@ -411,7 +411,7 @@ bool handle_rules_edit(String originalUri, bool isAddNew) {
if (isAddNew)
{
eventName = web_server.arg(F("eventName"));
eventName = webArg(F("eventName"));
fileName += EventToFileName(eventName);
}
else
@@ -433,8 +433,8 @@ bool handle_rules_edit(String originalUri, bool isAddNew) {
if (web_server.args() > 0)
{
const String& rules = web_server.arg(F("rules"));
isNew = web_server.arg(F("IsNew")) == F("yes");
const String& rules = webArg(F("rules"));
isNew = webArg(F("IsNew")) == F("yes");
// Overwrite verification
if (isEdit && isNew) {
+6 -6
View File
@@ -52,9 +52,9 @@ void handle_settingsarchive() {
if (web_server.hasArg(F("download"))) {
// Try downloading files.
String url = web_server.arg(F("url"));
String user = web_server.arg(F("user"));
String pass = web_server.arg(F("pass"));
String url = webArg(F("url"));
String user = webArg(F("user"));
String pass = webArg(F("pass"));
addTableSeparator(F("Download result"), 2, 3);
bool somethingDownloaded = false;
@@ -106,10 +106,10 @@ void handle_settingsarchive() {
addTableSeparator(F("Archive Location"), 2, 3);
addFormTextBox(F("URL with settings"), F("url"), web_server.arg(F("url")), 256);
addFormTextBox(F("URL with settings"), F("url"), webArg(F("url")), 256);
addFormNote(F("Only HTTP supported. Do not include filename"));
addFormTextBox(F("User"), F("user"), web_server.arg(F("user")), 64);
addFormPasswordBox(F("Pass"), F("pass"), web_server.arg(F("pass")), 64);
addFormTextBox(F("User"), F("user"), webArg(F("user")), 64);
addFormPasswordBox(F("Pass"), F("pass"), webArg(F("pass")), 64);
addFormNote(F("URL, user and pass will not be stored"));
addRowLabel(F("Try download files"));
+2 -2
View File
@@ -79,8 +79,8 @@ void handle_setup() {
static byte status = HANDLE_SETUP_SCAN_STAGE;
static byte refreshCount = 0;
String ssid = web_server.arg(F("ssid"));
String other = web_server.arg(F("other"));
String ssid = webArg(F("ssid"));
String other = webArg(F("other"));
String password;
bool passwordGiven = getFormPassword(F("pass"), password);
if (passwordGiven) {
+1 -1
View File
@@ -25,7 +25,7 @@ void handle_tools() {
TXBuffer.startStream();
sendHeadandTail_stdtemplate(_HEAD);
String webrequest = web_server.arg(F("cmd"));
String webrequest = webArg(F("cmd"));
handle_command_from_web(EventValueSource::Enum::VALUE_SOURCE_WEB_FRONTEND, webrequest);
printToWeb = false;
+39 -6
View File
@@ -106,7 +106,7 @@
void safe_strncpy_webserver_arg(char *dest, const String& arg, size_t max_size) {
if (web_server.hasArg(arg)) {
safe_strncpy(dest, web_server.arg(arg).c_str(), max_size);
safe_strncpy(dest, webArg(arg).c_str(), max_size);
}
}
@@ -218,7 +218,7 @@ void sendHeadandTail_stdtemplate(boolean Tail, boolean rebooting) {
log += F(": '");
log += web_server.argName(i);
log += F("' length: ");
log += web_server.arg(i).length();
log += webArg(i).length();
}
addLog(LOG_LEVEL_INFO, log);
}
@@ -1015,7 +1015,7 @@ void addSVG_param(const String& key, const String& value) {
addHtml(html);
}
void createSvgRect_noStroke(const String& classname, unsigned int fillColor, float xoffset, float yoffset, float width, float height, float rx, float ry) {
void createSvgRect_noStroke(const __FlashStringHelper * classname, unsigned int fillColor, float xoffset, float yoffset, float width, float height, float rx, float ry) {
createSvgRect(classname, fillColor, fillColor, xoffset, yoffset, width, height, 0, rx, ry);
}
@@ -1136,9 +1136,8 @@ void getWiFi_RSSI_icon(int rssi, int width_pixels)
for (int i = 0; i < nbars; ++i) {
unsigned int color = i < nbars_filled ? 0x0 : 0xa1a1a1; // Black/Grey
String classname = i < nbars_filled ? F("bar_highlight") : F("bar_dimmed");
int barHeight = (i + 1) * bar_height_step;
createSvgRect_noStroke(classname, color, i * (barWidth + white_between_bar) * scale, 100 - barHeight, barWidth, barHeight, 0, 0);
createSvgRect_noStroke(i < nbars_filled ? F("bar_highlight") : F("bar_dimmed"), color, i * (barWidth + white_between_bar) * scale, 100 - barHeight, barWidth, barHeight, 0, 0);
}
addHtml(F("</svg>\n"));
}
@@ -1298,5 +1297,39 @@ void getPartitionTableSVG(byte pType, unsigned int partitionColor) {
#endif // ifdef ESP32
bool webArg2ip(const String& arg, byte *IP) {
return str2ip(web_server.arg(arg), IP);
return str2ip(webArg(arg), IP);
}
#ifdef ESP8266
const String& webArg(const __FlashStringHelper * arg)
{
return web_server.arg(String(arg));
}
const String& webArg(const String& arg)
{
return web_server.arg(arg);
}
const String& webArg(int i)
{
return web_server.arg(i);
}
#endif
#ifdef ESP32
String webArg(const __FlashStringHelper * arg)
{
return web_server.arg(String(arg));
}
String webArg(const String& arg)
{
return web_server.arg(arg);
}
String webArg(int i)
{
return web_server.arg(i);
}
#endif
+18 -1
View File
@@ -147,7 +147,7 @@ void addSVG_param(const String& key,
void addSVG_param(const String& key,
const String& value);
void createSvgRect_noStroke(const String& classname,
void createSvgRect_noStroke(const __FlashStringHelper * classname,
unsigned int fillColor,
float xoffset,
float yoffset,
@@ -211,4 +211,21 @@ void getPartitionTableSVG(byte pType,
bool webArg2ip(const String& arg,
byte *IP);
// Separate wrapper to get web_server.arg()
// 1) To allow to have a __FlashStringHelper call -> reduce build size
// 2) ESP32 does not return a const String &, but a temporary copy, thus we _must_ copy before using it.
#ifdef ESP8266
const String& webArg(const __FlashStringHelper * arg);
const String& webArg(const String& arg);
const String& webArg(int i);
#endif
#ifdef ESP32
String webArg(const __FlashStringHelper * arg);
String webArg(const String& arg);
String webArg(int i);
#endif
#endif // ifndef WEBSERVER_WEBSERVER_H
+1 -1
View File
@@ -27,7 +27,7 @@ void handle_login() {
TXBuffer.startStream();
sendHeadandTail_stdtemplate(_HEAD);
String webrequest = web_server.arg(F("password"));
String webrequest = webArg(F("password"));
addHtml(F("<form method='post'>"));
html_table_class_normal();
addHtml(F("<TR><TD>Password<TD>"));