Remove stricmp for strcasecmp

This commit is contained in:
Dave Davenport 2022-01-04 23:59:05 +01:00
parent e4a4d21619
commit cfbcbcdb6a
6 changed files with 36 additions and 48 deletions

View File

@ -112,12 +112,12 @@ void handleMQTTcallback(char* topic, byte* payload, unsigned int length) {
char msgPayload[50];
int msglen = min((int)(length)+1, (int)sizeof(msgPayload));
strlcpy(msgPayload, (char *)payload, msglen);
if (stricmp(topic, "homeassistant/status") == 0) {
if (strcasecmp(topic, "homeassistant/status") == 0) {
//incoming message on status, detect going down
if (stricmp(msgPayload, "offline") == 0){
if (strcasecmp(msgPayload, "offline") == 0){
//home assistant went down
DebugTln(F("Home Assistant went offline!"));
} else if (stricmp(msgPayload, "online") == 0){
} else if (strcasecmp(msgPayload, "online") == 0){
DebugTln(F("Home Assistant went online!"));
//restart stuff, to make sure it works correctly again
startMQTT(); // fixing some issues with hanging HA AutoDiscovery in some scenario's?
@ -133,22 +133,22 @@ void handleMQTTcallback(char* topic, byte* payload, unsigned int length) {
token = strtok(topic, "/");
MQTTDebugT("Parsing topic: ");
MQTTDebugf("%s/", token);
if (stricmp(token, CSTR(settingMQTTtopTopic)) == 0) {
if (strcasecmp(token, CSTR(settingMQTTtopTopic)) == 0) {
token = strtok(NULL, "/");
MQTTDebugf("%s/", token);
if (stricmp(token, "set") == 0) {
if (strcasecmp(token, "set") == 0) {
token = strtok(NULL, "/");
MQTTDebugf("%s/", token);
if (stricmp(token, CSTR(NodeId)) == 0) {
if (strcasecmp(token, CSTR(NodeId)) == 0) {
token = strtok(NULL, "/");
MQTTDebugf("%s", token);
if (token != NULL){
//loop thru command list
int i;
for (i=0; i<nrcmds; i++){
if (stricmp(token, setcmds[i].setcmd) == 0){
if (strcasecmp(token, setcmds[i].setcmd) == 0){
//found a match
if (stricmp(setcmds[i].ottype, "raw") == 0){
if (strcasecmp(setcmds[i].ottype, "raw") == 0){
//raw command
snprintf(otgwcmd, sizeof(otgwcmd), "%s", msgPayload);
MQTTDebugf(" found command, sending payload [%s]\r\n", otgwcmd);

View File

@ -1699,11 +1699,11 @@ void handleOTGW()
sWrite[bytes_write] = 0;
OTGWDebugTf("Net2Ser: Sending to OTGW: [%s] (%d)\r\n", sWrite, bytes_write);
//check for reset command
if (stricmp(sWrite, "GW=R")==0){
if (strcasecmp(sWrite, "GW=R")==0){
//detected [GW=R], then reset the gateway the gpio way
OTGWDebugTln(F("Detected: GW=R. Reset gateway command executed."));
resetOTGW();
} else if (stricmp(sWrite, "PS=1")==0) {
} else if (strcasecmp(sWrite, "PS=1")==0) {
//detected [PS=1], then PrintSummary mode = true --> From this point on you need to ask for summary.
bPrintSummarymode = true;
//reset all msglastupdated in webui
@ -1711,7 +1711,7 @@ void handleOTGW()
msglastupdated[i] = 0; //clear epoch values
}
sMessage = "PS=1 mode; No UI updates.";
} else if (stricmp(sWrite, "PS=0")==0) {
} else if (strcasecmp(sWrite, "PS=0")==0) {
//detected [PS=0], then PrintSummary mode = OFF --> Raw mode is turned on again.
bPrintSummarymode = false;
sMessage = "";

View File

@ -54,7 +54,7 @@ void setLed(int8_t, uint8_t);
#define CBOOLEAN(x) (x?"true":"false")
#define CONOFF(x) (x?"On":"Off")
#define CBINARY(x) (x?"1":"0")
#define EVALBOOLEAN(x) (stricmp(x,"true")==0||stricmp(x,"on")==0||stricmp(x,"1")==0)
#define EVALBOOLEAN(x) (strcasecmp(x,"true")==0||strcasecmp(x,"on")==0||strcasecmp(x,"1")==0)
//prototype

View File

@ -84,18 +84,6 @@ uint8_t splitString(String inStrng, char delimiter, String wOut[], uint8_t maxWo
} // splitString()
//===========================================================================================
int stricmp(const char *a, const char *b)
{
for (;; a++, b++) {
int d = tolower((unsigned char)*a) - tolower((unsigned char)*b);
if (d != 0 || !*a)
return d;
}
} // stricmp()
//===========================================================================================
float formatFloat(float v, int dec)
{
@ -375,7 +363,7 @@ bool checklittlefshash(){
}
}
DebugTf("Check githash = [%s]\r\n", CSTR(_githash));
return (stricmp(CSTR(_githash), _VERSION_GITHASH)==0);
return (strcasecmp(CSTR(_githash), _VERSION_GITHASH)==0);
}
return false;
}

View File

@ -181,7 +181,7 @@ void sendOTGWlabel(const char *msglabel){
uint_fast8_t msgid;
for (msgid = 0; msgid<= OT_MSGID_MAX; msgid++){
PROGMEM_readAnything (&OTmap[msgid], OTlookupitem);
if (stricmp(OTlookupitem.label, msglabel)==0) break;
if (strcasecmp(OTlookupitem.label, msglabel)==0) break;
}
if (msgid > OT_MSGID_MAX){
root["error"] = "message id: reserved for future use";

View File

@ -162,7 +162,7 @@ void updateSetting(const char *field, const char *newValue)
{ //do not just trust the caller to do the right thing, server side validation is here!
DebugTf("-> field[%s], newValue[%s]\r\n", field, newValue);
if (stricmp(field, "hostname")==0)
if (strcasecmp(field, "hostname")==0)
{ //make sure we have a valid hostname here...
settingHostname = String(newValue);
if (settingHostname.length()==0) settingHostname=_HOSTNAME;
@ -181,70 +181,70 @@ void updateSetting(const char *field, const char *newValue)
Debugln();
DebugTf("Need reboot before new %s.local will be available!\r\n\n", CSTR(settingHostname));
}
if (stricmp(field, "MQTTenable")==0) settingMQTTenable = EVALBOOLEAN(newValue);
if (stricmp(field, "MQTTbroker")==0) settingMQTTbroker = String(newValue);
if (stricmp(field, "MQTTbrokerPort")==0) settingMQTTbrokerPort = atoi(newValue);
if (stricmp(field, "MQTTuser")==0) settingMQTTuser = String(newValue);
if (stricmp(field, "MQTTpasswd")==0) settingMQTTpasswd = String(newValue);
if (stricmp(field, "MQTTtoptopic")==0) {
if (strcasecmp(field, "MQTTenable")==0) settingMQTTenable = EVALBOOLEAN(newValue);
if (strcasecmp(field, "MQTTbroker")==0) settingMQTTbroker = String(newValue);
if (strcasecmp(field, "MQTTbrokerPort")==0) settingMQTTbrokerPort = atoi(newValue);
if (strcasecmp(field, "MQTTuser")==0) settingMQTTuser = String(newValue);
if (strcasecmp(field, "MQTTpasswd")==0) settingMQTTpasswd = String(newValue);
if (strcasecmp(field, "MQTTtoptopic")==0) {
settingMQTTtopTopic = String(newValue);
if (settingMQTTtopTopic.length()==0) {
settingMQTTtopTopic = _HOSTNAME;
settingMQTTtopTopic.toLowerCase();
}
}
if (stricmp(field, "MQTThaprefix")==0) {
if (strcasecmp(field, "MQTThaprefix")==0) {
settingMQTThaprefix = String(newValue);
if (settingMQTThaprefix.length()==0) settingMQTThaprefix = HOME_ASSISTANT_DISCOVERY_PREFIX;
}
if (stricmp(field, "MQTTuniqueid") == 0) {
if (strcasecmp(field, "MQTTuniqueid") == 0) {
settingMQTTuniqueid = String(newValue);
if (settingMQTTuniqueid.length() == 0) settingMQTTuniqueid = getUniqueId();
}
if (stricmp(field, "MQTTOTmessage")==0) settingMQTTOTmessage = EVALBOOLEAN(newValue);
if (strcasecmp(field, "MQTTOTmessage")==0) settingMQTTOTmessage = EVALBOOLEAN(newValue);
if (strstr(field, "mqtt") != NULL) startMQTT();//restart MQTT on change of any setting
if (stricmp(field, "NTPenable")==0) settingNTPenable = EVALBOOLEAN(newValue);
if (stricmp(field, "NTPhostname")==0) {
if (strcasecmp(field, "NTPenable")==0) settingNTPenable = EVALBOOLEAN(newValue);
if (strcasecmp(field, "NTPhostname")==0) {
settingNTPhostname = String(newValue);
startNTP();
}
if (stricmp(field, "NTPtimezone")==0) {
if (strcasecmp(field, "NTPtimezone")==0) {
settingNTPtimezone = String(newValue);
startNTP(); // update timezone if changed
}
if (stricmp(field, "LEDblink")==0) settingLEDblink = EVALBOOLEAN(newValue);
if (stricmp(field, "GPIOSENSORSenabled") == 0)
if (strcasecmp(field, "LEDblink")==0) settingLEDblink = EVALBOOLEAN(newValue);
if (strcasecmp(field, "GPIOSENSORSenabled") == 0)
{
settingGPIOSENSORSenabled = EVALBOOLEAN(newValue);
Debugln();
DebugTf("Need reboot before GPIO SENSORS will search for sensors on pin GPIO%d!\r\n\n", settingGPIOSENSORSpin);
}
if (stricmp(field, "GPIOSENSORSpin") == 0)
if (strcasecmp(field, "GPIOSENSORSpin") == 0)
{
settingGPIOSENSORSpin = atoi(newValue);
Debugln();
DebugTf("Need reboot before GPIO SENSORS will use new pin GPIO%d!\r\n\n", settingGPIOSENSORSpin);
}
if (stricmp(field, "GPIOSENSORSinterval") == 0) {
if (strcasecmp(field, "GPIOSENSORSinterval") == 0) {
settingGPIOSENSORSinterval = atoi(newValue);
CHANGE_INTERVAL_SEC(timerpollsensor, settingGPIOSENSORSinterval, CATCH_UP_MISSED_TICKS);
}
if (stricmp(field, "OTGWcommandenable")==0) settingOTGWcommandenable = EVALBOOLEAN(newValue);
if (stricmp(field, "OTGWcommands")==0) settingOTGWcommands = String(newValue);
if (stricmp(field, "GPIOOUTPUTSenabled") == 0)
if (strcasecmp(field, "OTGWcommandenable")==0) settingOTGWcommandenable = EVALBOOLEAN(newValue);
if (strcasecmp(field, "OTGWcommands")==0) settingOTGWcommands = String(newValue);
if (strcasecmp(field, "GPIOOUTPUTSenabled") == 0)
{
settingGPIOOUTPUTSenabled = EVALBOOLEAN(newValue);
Debugln();
DebugTf("Need reboot before GPIO OUTPUTS will be enabled on pin GPIO%d!\r\n\n", settingGPIOOUTPUTSenabled);
}
if (stricmp(field, "GPIOOUTPUTSpin") == 0)
if (strcasecmp(field, "GPIOOUTPUTSpin") == 0)
{
settingGPIOOUTPUTSpin = atoi(newValue);
Debugln();
DebugTf("Need reboot before GPIO OUTPUTS will use new pin GPIO%d!\r\n\n", settingGPIOOUTPUTSpin);
}
if (stricmp(field, "GPIOOUTPUTStriggerBit") == 0)
if (strcasecmp(field, "GPIOOUTPUTStriggerBit") == 0)
{
settingGPIOOUTPUTStriggerBit = atoi(newValue);
Debugln();