Merge pull request #9734 from tichris0/development

Swapped strstr for strchr where applicable
This commit is contained in:
Theo Arends 2020-11-04 15:17:20 +01:00 committed by GitHub
commit 9299073e60
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 30 additions and 30 deletions

View File

@ -1242,7 +1242,7 @@ void CmndTemplate(void)
bool error = false; bool error = false;
if (strstr(XdrvMailbox.data, "{") == nullptr) { // If no JSON it must be parameter if (strchr(XdrvMailbox.data, '{') == nullptr) { // If no JSON it must be parameter
if ((XdrvMailbox.payload > 0) && (XdrvMailbox.payload <= MAXMODULE)) { if ((XdrvMailbox.payload > 0) && (XdrvMailbox.payload <= MAXMODULE)) {
XdrvMailbox.payload--; XdrvMailbox.payload--;
if (ValidTemplateModule(XdrvMailbox.payload)) { if (ValidTemplateModule(XdrvMailbox.payload)) {
@ -1550,7 +1550,7 @@ void CmndHostname(void)
{ {
if (!XdrvMailbox.grpflg && (XdrvMailbox.data_len > 0)) { if (!XdrvMailbox.grpflg && (XdrvMailbox.data_len > 0)) {
SettingsUpdateText(SET_HOSTNAME, (SC_DEFAULT == Shortcut()) ? WIFI_HOSTNAME : XdrvMailbox.data); SettingsUpdateText(SET_HOSTNAME, (SC_DEFAULT == Shortcut()) ? WIFI_HOSTNAME : XdrvMailbox.data);
if (strstr(SettingsText(SET_HOSTNAME), "%") != nullptr) { if (strchr(SettingsText(SET_HOSTNAME), '%') != nullptr) {
SettingsUpdateText(SET_HOSTNAME, WIFI_HOSTNAME); SettingsUpdateText(SET_HOSTNAME, WIFI_HOSTNAME);
} }
TasmotaGlobal.restart_flag = 2; TasmotaGlobal.restart_flag = 2;
@ -1643,7 +1643,7 @@ void CmndInterlock(void)
if (max_relays > sizeof(Settings.interlock[0]) * 8) { max_relays = sizeof(Settings.interlock[0]) * 8; } if (max_relays > sizeof(Settings.interlock[0]) * 8) { max_relays = sizeof(Settings.interlock[0]) * 8; }
if (max_relays > 1) { // Only interlock with more than 1 relay if (max_relays > 1) { // Only interlock with more than 1 relay
if (XdrvMailbox.data_len > 0) { if (XdrvMailbox.data_len > 0) {
if (strstr(XdrvMailbox.data, ",") != nullptr) { // Interlock entry if (strchr(XdrvMailbox.data, ',') != nullptr) { // Interlock entry
for (uint32_t i = 0; i < MAX_INTERLOCKS; i++) { Settings.interlock[i] = 0; } // Reset current interlocks for (uint32_t i = 0; i < MAX_INTERLOCKS; i++) { Settings.interlock[i] = 0; } // Reset current interlocks
char *group; char *group;
char *q; char *q;
@ -1801,7 +1801,7 @@ void CmndTimeStdDst(uint32_t ts)
{ {
// TimeStd 0/1, 0/1/2/3/4, 1..12, 1..7, 0..23, +/-780 // TimeStd 0/1, 0/1/2/3/4, 1..12, 1..7, 0..23, +/-780
if (XdrvMailbox.data_len > 0) { if (XdrvMailbox.data_len > 0) {
if (strstr(XdrvMailbox.data, ",") != nullptr) { // Process parameter entry if (strchr(XdrvMailbox.data, ',') != nullptr) { // Process parameter entry
uint32_t tpos = 0; // Parameter index uint32_t tpos = 0; // Parameter index
int value = 0; int value = 0;
char *p = XdrvMailbox.data; // Parameters like "1, 2,3 , 4 ,5, -120" or ",,,,,+240" char *p = XdrvMailbox.data; // Parameters like "1, 2,3 , 4 ,5, -120" or ",,,,,+240"

View File

@ -25,10 +25,10 @@ char* Format(char* output, const char* input, int size)
char *token; char *token;
uint32_t digits = 0; uint32_t digits = 0;
if (strstr(input, "%") != nullptr) { if (strchr(input, '%') != nullptr) {
strlcpy(output, input, size); strlcpy(output, input, size);
token = strtok(output, "%"); token = strtok(output, "%");
if (strstr(input, "%") == input) { if (strchr(input, '%') == input) {
output[0] = '\0'; output[0] = '\0';
} else { } else {
token = strtok(nullptr, ""); token = strtok(nullptr, "");

View File

@ -280,7 +280,7 @@ void setup(void) {
Format(TasmotaGlobal.mqtt_client, SettingsText(SET_MQTT_CLIENT), sizeof(TasmotaGlobal.mqtt_client)); Format(TasmotaGlobal.mqtt_client, SettingsText(SET_MQTT_CLIENT), sizeof(TasmotaGlobal.mqtt_client));
Format(TasmotaGlobal.mqtt_topic, SettingsText(SET_MQTT_TOPIC), sizeof(TasmotaGlobal.mqtt_topic)); Format(TasmotaGlobal.mqtt_topic, SettingsText(SET_MQTT_TOPIC), sizeof(TasmotaGlobal.mqtt_topic));
if (strstr(SettingsText(SET_HOSTNAME), "%") != nullptr) { if (strchr(SettingsText(SET_HOSTNAME), '%') != nullptr) {
SettingsUpdateText(SET_HOSTNAME, WIFI_HOSTNAME); SettingsUpdateText(SET_HOSTNAME, WIFI_HOSTNAME);
snprintf_P(TasmotaGlobal.hostname, sizeof(TasmotaGlobal.hostname)-1, SettingsText(SET_HOSTNAME), TasmotaGlobal.mqtt_topic, ESP_getChipId() & 0x1FFF); snprintf_P(TasmotaGlobal.hostname, sizeof(TasmotaGlobal.hostname)-1, SettingsText(SET_HOSTNAME), TasmotaGlobal.mqtt_topic, ESP_getChipId() & 0x1FFF);
} else { } else {

View File

@ -2185,7 +2185,7 @@ void WifiSaveSettings(void)
WebGetArg("h", tmp, sizeof(tmp)); WebGetArg("h", tmp, sizeof(tmp));
SettingsUpdateText(SET_HOSTNAME, (!strlen(tmp)) ? WIFI_HOSTNAME : tmp); SettingsUpdateText(SET_HOSTNAME, (!strlen(tmp)) ? WIFI_HOSTNAME : tmp);
if (strstr(SettingsText(SET_HOSTNAME), "%") != nullptr) { if (strchr(SettingsText(SET_HOSTNAME), '%') != nullptr) {
SettingsUpdateText(SET_HOSTNAME, WIFI_HOSTNAME); SettingsUpdateText(SET_HOSTNAME, WIFI_HOSTNAME);
} }
WebGetArg("c", tmp, sizeof(tmp)); WebGetArg("c", tmp, sizeof(tmp));
@ -3429,7 +3429,7 @@ void CmndWebSend(void)
void CmndWebColor(void) void CmndWebColor(void)
{ {
if (XdrvMailbox.data_len > 0) { if (XdrvMailbox.data_len > 0) {
if (strstr(XdrvMailbox.data, "{") == nullptr) { // If no JSON it must be parameter if (strchr(XdrvMailbox.data, '{') == nullptr) { // If no JSON it must be parameter
if ((XdrvMailbox.data_len > 3) && (XdrvMailbox.index > 0) && (XdrvMailbox.index <= COL_LAST)) { if ((XdrvMailbox.data_len > 3) && (XdrvMailbox.index > 0) && (XdrvMailbox.index <= COL_LAST)) {
WebHexCode(XdrvMailbox.index -1, XdrvMailbox.data); WebHexCode(XdrvMailbox.index -1, XdrvMailbox.data);
} }

View File

@ -2513,7 +2513,7 @@ bool LightColorEntry(char *buffer, uint32_t buffer_length)
buffer_length--; // remove all trailing '=' buffer_length--; // remove all trailing '='
memcpy(&Light.entry_color, &Light.current_color, sizeof(Light.entry_color)); memcpy(&Light.entry_color, &Light.current_color, sizeof(Light.entry_color));
} }
if (strstr(buffer, ",") != nullptr) { // Decimal entry if (strchr(buffer, ',') != nullptr) { // Decimal entry
int8_t i = 0; int8_t i = 0;
for (str = strtok_r(buffer, ",", &p); str && i < 6; str = strtok_r(nullptr, ",", &p)) { for (str = strtok_r(buffer, ",", &p); str && i < 6; str = strtok_r(nullptr, ",", &p)) {
if (i < LST_MAX) { if (i < LST_MAX) {

View File

@ -318,7 +318,7 @@ void CmndIrSend(void)
uint8_t error = IE_SYNTAX_IRSEND; uint8_t error = IE_SYNTAX_IRSEND;
if (XdrvMailbox.data_len) { if (XdrvMailbox.data_len) {
if (strstr(XdrvMailbox.data, "{") == nullptr) { if (strchr(XdrvMailbox.data, '{') == nullptr) {
error = IE_INVALID_JSON; error = IE_INVALID_JSON;
} else { } else {
error = IrRemoteCmndIrSendJson(); error = IrRemoteCmndIrSendJson();

View File

@ -805,7 +805,7 @@ void CmndIrSend(void)
uint8_t error = IE_SYNTAX_IRSEND; uint8_t error = IE_SYNTAX_IRSEND;
if (XdrvMailbox.data_len) { if (XdrvMailbox.data_len) {
if (strstr(XdrvMailbox.data, "{") == nullptr) { if (strchr(XdrvMailbox.data, '{') == nullptr) {
error = IrRemoteCmndIrSendRaw(); error = IrRemoteCmndIrSendRaw();
} else { } else {
error = IrRemoteCmndIrSendJson(); error = IrRemoteCmndIrSendJson();

View File

@ -497,7 +497,7 @@ void CmndDomoticzSend(void) {
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= 5)) { if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= 5)) {
if (XdrvMailbox.data_len > 0) { if (XdrvMailbox.data_len > 0) {
if (strstr(XdrvMailbox.data, ",") != nullptr) { // Process parameter entry if (strchr(XdrvMailbox.data, ',') != nullptr) { // Process parameter entry
char *data; char *data;
uint32_t index = strtoul(strtok_r(XdrvMailbox.data, ",", &data), nullptr, 10); uint32_t index = strtoul(strtok_r(XdrvMailbox.data, ",", &data), nullptr, 10);
if ((index > 0) && (data != nullptr)) { if ((index > 0) && (data != nullptr)) {

View File

@ -2249,7 +2249,7 @@ void CmndScale(void)
{ {
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= MAX_RULE_VARS)) { if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= MAX_RULE_VARS)) {
if (XdrvMailbox.data_len > 0) { if (XdrvMailbox.data_len > 0) {
if (strstr(XdrvMailbox.data, ",") != nullptr) { // Process parameter entry if (strchr(XdrvMailbox.data, ',') != nullptr) { // Process parameter entry
char sub_string[XdrvMailbox.data_len +1]; char sub_string[XdrvMailbox.data_len +1];
float valueIN = CharToFloat(subStr(sub_string, XdrvMailbox.data, ",", 1)); float valueIN = CharToFloat(subStr(sub_string, XdrvMailbox.data, ",", 1));

View File

@ -1120,7 +1120,7 @@ void CmndKnxEnhanced(void)
void CmndKnxPa(void) void CmndKnxPa(void)
{ {
if (XdrvMailbox.data_len) { if (XdrvMailbox.data_len) {
if (strstr(XdrvMailbox.data, ".") != nullptr) { // Process parameter entry if (strchr(XdrvMailbox.data, '.') != nullptr) { // Process parameter entry
char sub_string[XdrvMailbox.data_len]; char sub_string[XdrvMailbox.data_len];
int pa_area = atoi(subStr(sub_string, XdrvMailbox.data, ".", 1)); int pa_area = atoi(subStr(sub_string, XdrvMailbox.data, ".", 1));
@ -1148,7 +1148,7 @@ void CmndKnxGa(void)
{ {
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= MAX_KNX_GA)) { if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= MAX_KNX_GA)) {
if (XdrvMailbox.data_len) { if (XdrvMailbox.data_len) {
if (strstr(XdrvMailbox.data, ",") != nullptr) { // Process parameter entry if (strchr(XdrvMailbox.data, ',') != nullptr) { // Process parameter entry
char sub_string[XdrvMailbox.data_len]; char sub_string[XdrvMailbox.data_len];
int ga_option = atoi(subStr(sub_string, XdrvMailbox.data, ",", 1)); int ga_option = atoi(subStr(sub_string, XdrvMailbox.data, ",", 1));
@ -1199,7 +1199,7 @@ void CmndKnxCb(void)
{ {
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= MAX_KNX_CB)) { if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= MAX_KNX_CB)) {
if (XdrvMailbox.data_len) { if (XdrvMailbox.data_len) {
if (strstr(XdrvMailbox.data, ",") != nullptr) { // Process parameter entry if (strchr(XdrvMailbox.data, ',') != nullptr) { // Process parameter entry
char sub_string[XdrvMailbox.data_len]; char sub_string[XdrvMailbox.data_len];
int cb_option = atoi(subStr(sub_string, XdrvMailbox.data, ",", 1)); int cb_option = atoi(subStr(sub_string, XdrvMailbox.data, ",", 1));

View File

@ -132,7 +132,7 @@ void AdcGetSettings(uint32_t idx) {
Adc[idx].param2 = 0; Adc[idx].param2 = 0;
Adc[idx].param3 = 0; Adc[idx].param3 = 0;
Adc[idx].param4 = 0; Adc[idx].param4 = 0;
if (strstr(SettingsText(SET_ADC_PARAM1 + idx), ",") != nullptr) { if (strchr(SettingsText(SET_ADC_PARAM1 + idx), ',') != nullptr) {
Adcs.type = atoi(subStr(parameters, SettingsText(SET_ADC_PARAM1 + idx), ",", 1)); Adcs.type = atoi(subStr(parameters, SettingsText(SET_ADC_PARAM1 + idx), ",", 1));
Adc[idx].param1 = atoi(subStr(parameters, SettingsText(SET_ADC_PARAM1 + idx), ",", 2)); Adc[idx].param1 = atoi(subStr(parameters, SettingsText(SET_ADC_PARAM1 + idx), ",", 2));
Adc[idx].param2 = atoi(subStr(parameters, SettingsText(SET_ADC_PARAM1 + idx), ",", 3)); Adc[idx].param2 = atoi(subStr(parameters, SettingsText(SET_ADC_PARAM1 + idx), ",", 3));

View File

@ -205,7 +205,7 @@ bool HxCommand(void)
Response_P(S_JSON_SENSOR_INDEX_SVALUE, XSNS_34, "Reset"); Response_P(S_JSON_SENSOR_INDEX_SVALUE, XSNS_34, "Reset");
break; break;
case 2: // Calibrate case 2: // Calibrate
if (strstr(XdrvMailbox.data, ",") != nullptr) { if (strchr(XdrvMailbox.data, ',') != nullptr) {
Settings.weight_reference = strtol(subStr(sub_string, XdrvMailbox.data, ",", 2), nullptr, 10); Settings.weight_reference = strtol(subStr(sub_string, XdrvMailbox.data, ",", 2), nullptr, 10);
} }
Hx.scale = 1; Hx.scale = 1;
@ -215,26 +215,26 @@ bool HxCommand(void)
HxCalibrationStateTextJson(3); HxCalibrationStateTextJson(3);
break; break;
case 3: // WeightRef to user reference case 3: // WeightRef to user reference
if (strstr(XdrvMailbox.data, ",") != nullptr) { if (strchr(XdrvMailbox.data, ',') != nullptr) {
Settings.weight_reference = strtol(subStr(sub_string, XdrvMailbox.data, ",", 2), nullptr, 10); Settings.weight_reference = strtol(subStr(sub_string, XdrvMailbox.data, ",", 2), nullptr, 10);
} }
show_parms = true; show_parms = true;
break; break;
case 4: // WeightCal to user calculated value case 4: // WeightCal to user calculated value
if (strstr(XdrvMailbox.data, ",") != nullptr) { if (strchr(XdrvMailbox.data, ',') != nullptr) {
Settings.weight_calibration = strtol(subStr(sub_string, XdrvMailbox.data, ",", 2), nullptr, 10); Settings.weight_calibration = strtol(subStr(sub_string, XdrvMailbox.data, ",", 2), nullptr, 10);
Hx.scale = Settings.weight_calibration; Hx.scale = Settings.weight_calibration;
} }
show_parms = true; show_parms = true;
break; break;
case 5: // WeightMax case 5: // WeightMax
if (strstr(XdrvMailbox.data, ",") != nullptr) { if (strchr(XdrvMailbox.data, ',') != nullptr) {
Settings.weight_max = strtol(subStr(sub_string, XdrvMailbox.data, ",", 2), nullptr, 10) / 1000; Settings.weight_max = strtol(subStr(sub_string, XdrvMailbox.data, ",", 2), nullptr, 10) / 1000;
} }
show_parms = true; show_parms = true;
break; break;
case 6: // WeightItem case 6: // WeightItem
if (strstr(XdrvMailbox.data, ",") != nullptr) { if (strchr(XdrvMailbox.data, ',') != nullptr) {
Settings.weight_item = (unsigned long)(CharToFloat(subStr(sub_string, XdrvMailbox.data, ",", 2)) * 10); Settings.weight_item = (unsigned long)(CharToFloat(subStr(sub_string, XdrvMailbox.data, ",", 2)) * 10);
} }
show_parms = true; show_parms = true;
@ -244,13 +244,13 @@ bool HxCommand(void)
Response_P(S_JSON_SENSOR_INDEX_SVALUE, XSNS_34, D_JSON_DONE); Response_P(S_JSON_SENSOR_INDEX_SVALUE, XSNS_34, D_JSON_DONE);
break; break;
case 8: // Json on weight change case 8: // Json on weight change
if (strstr(XdrvMailbox.data, ",") != nullptr) { if (strchr(XdrvMailbox.data, ',') != nullptr) {
Settings.SensorBits1.hx711_json_weight_change = strtol(subStr(sub_string, XdrvMailbox.data, ",", 2), nullptr, 10) & 1; Settings.SensorBits1.hx711_json_weight_change = strtol(subStr(sub_string, XdrvMailbox.data, ",", 2), nullptr, 10) & 1;
} }
show_parms = true; show_parms = true;
break; break;
case 9: // WeightDelta case 9: // WeightDelta
if (strstr(XdrvMailbox.data, ",") != nullptr) { if (strchr(XdrvMailbox.data, ',') != nullptr) {
Settings.weight_change = strtol(subStr(sub_string, XdrvMailbox.data, ",", 2), nullptr, 10); Settings.weight_change = strtol(subStr(sub_string, XdrvMailbox.data, ",", 2), nullptr, 10);
SetWeightDelta(); SetWeightDelta();
} }

View File

@ -294,27 +294,27 @@ bool Xsns68Cmnd(void)
char sub_string[XdrvMailbox.data_len +1]; char sub_string[XdrvMailbox.data_len +1];
switch (XdrvMailbox.payload) { switch (XdrvMailbox.payload) {
case 1: case 1:
if (strstr(XdrvMailbox.data, ",") != nullptr) { if (strchr(XdrvMailbox.data, ',') != nullptr) {
Settings.windmeter_radius = (uint16_t)strtol(subStr(sub_string, XdrvMailbox.data, ",", 2), nullptr, 10); Settings.windmeter_radius = (uint16_t)strtol(subStr(sub_string, XdrvMailbox.data, ",", 2), nullptr, 10);
} }
break; break;
case 2: case 2:
if (strstr(XdrvMailbox.data, ",") != nullptr) { if (strchr(XdrvMailbox.data, ',') != nullptr) {
Settings.windmeter_pulses_x_rot = (uint8_t)strtol(subStr(sub_string, XdrvMailbox.data, ",", 2), nullptr, 10); Settings.windmeter_pulses_x_rot = (uint8_t)strtol(subStr(sub_string, XdrvMailbox.data, ",", 2), nullptr, 10);
} }
break; break;
case 3: case 3:
if (strstr(XdrvMailbox.data, ",") != nullptr) { if (strchr(XdrvMailbox.data, ',') != nullptr) {
Settings.windmeter_pulse_debounce = (uint16_t)strtol(subStr(sub_string, XdrvMailbox.data, ",", 2), nullptr, 10); Settings.windmeter_pulse_debounce = (uint16_t)strtol(subStr(sub_string, XdrvMailbox.data, ",", 2), nullptr, 10);
} }
break; break;
case 4: case 4:
if (strstr(XdrvMailbox.data, ",") != nullptr) { if (strchr(XdrvMailbox.data, ',') != nullptr) {
Settings.windmeter_speed_factor = (int16_t)(CharToFloat(subStr(sub_string, XdrvMailbox.data, ",", 2)) * 1000); Settings.windmeter_speed_factor = (int16_t)(CharToFloat(subStr(sub_string, XdrvMailbox.data, ",", 2)) * 1000);
} }
break; break;
case 5: case 5:
if (strstr(XdrvMailbox.data, ",") != nullptr) { if (strchr(XdrvMailbox.data, ',') != nullptr) {
Settings.windmeter_tele_pchange = (uint8_t)strtol(subStr(sub_string, XdrvMailbox.data, ",", 2), nullptr, 10); Settings.windmeter_tele_pchange = (uint8_t)strtol(subStr(sub_string, XdrvMailbox.data, ",", 2), nullptr, 10);
} }
break; break;