something wrong with my server code - I tried hard but failed to find the reason
Can someone please tell why does the compiler complains, in the function serveRequest
that the parameter uriReqValue may be undefined?
and this only happens when the code has the lines
if(testLocalClient(currClientIP)) authenticated=true;
here is the server code
void serve() {
if (!getArg(HAS_ENET)) {
return;
}
bool authenticated=false, ajaxFound=false, dumpFound=false, faviconFound=false, httpFound=false, cnxOK,
isFullAdmin=false;
unsigned int bufPtr;
static IPAddress prevClientIP(0, 0, 0, 0);
IPAddress currClientIP;
const char ajaxPhrase[]="ajax_inputs&";
const char faviconPhrase[]="/favicon";
const char dumpPhrase[]="/Dump";
const char credPhrase[]="Authorization: Basic";
const char emptyPhrase[]="\r\n";
const char httpPhrase[]="/ HTTP/";
char fmEnet;
int param=0, value=0;
unsigned long int serverAvailableStart;
unsigned long int serverAvailableEnd;
char* strStart;
const int IS_PARAM_LEN=strlen("ARG");
const int IS_PARAM_OFFSET=strlen(ajaxPhrase);
const int PARAM_OFFSET=strlen("ajax_inputs&ARG");
const int VALUE_OFFSET=strlen("ajax_inputs&ARG00=");
byte parsedURI;
byte req=ARGS + 1;
bool uriReqValue;
const int TIME_OUT=10000; // max 10 sec idle cnx. prevent connected client with no data deadlock
const byte MAX_LINES=20;
const byte MAX_LINE_LEN=200; //characters
byte lineLen;
byte lines;
bool existCommand=false;
int idleCnxCtr=0;
serverAvailableStart=micros();
client=server.available();
serverAvailableEnd=micros();
serverAvailableDur+=serverAvailableEnd-serverAvailableStart;
if (!client) return;
report(F("server-> new client\r\n"), MI_VERB);
currClientIP=(unsigned long)client.remoteIP();
//local client is authenticated by wifi password and if in router's white list => granted 'local admin' IP
if(testLocalClient(currClientIP)) authenticated=true;
cnxOK=true;
bufPtr=0; memset(genBuf, '\0', sizeof(genBuf)); //zero buffer
lines=0; lineLen=0;
while (client.connected() && cnxOK) {
if (client.available()) {//new byte from line
idleCnxCtr=0;
fmEnet=client.read();
if (bufPtr<GEN_BUF_SIZE-1) {genBuf[bufPtr++]=fmEnet; reportChar(fmEnet, HI_VERB);}
if (fmEnet=='\n') { //----full line assembled
lineLen=0;
if (lines++>MAX_LINES) {
report(F("server-> too many lines"), LO_VERB);
if(!hackCtr) logger(__LINE__, 0, LOG_DONT_HALT); // log only if counter null
if(hackCtr<UCHAR_MAX) hackCtr++;
break;
}
//-------full line assembled
if (strstr(genBuf, credPhrase)) {//--------------------------
report(F("server-> cred phrase found\r\n"), MI_VERB);
if (strstr(genBuf, SERVER_ADMIN_CREDS)) {
report(F("server-> admin ok\r\n"), MI_VERB);
authenticated=isFullAdmin=true;
}
else report(F("server-> creds NOK\r\n"), LO_VERB);
}
else if (!strncmp(genBuf, "GET", 3)) { //-------------------------
if (strstr(genBuf, httpPhrase)) {
httpFound=true;
report(F("server-> http phrase found\r\n"), MI_VERB);
}
if ((parsedURI=parseURI())<ARGS) { //req in URI
req=parsedURI; uriReqValue=isupper(genBuf[REQ_OFFSET]);
report(F("server-> request in URI found\r\n"), MI_VERB);
}
else if ((strStart=strstr(genBuf, ajaxPhrase))) { //-----ajax can come w/o a command=>just refresh buttons
ajaxFound=true;
report(F("server-> ajax phrase found\r\n"), MI_VERB);
if (!strncmp(strStart+IS_PARAM_OFFSET, "arg", IS_PARAM_LEN)) {
existCommand=true;
param=atoi(strStart+PARAM_OFFSET); value=*(strStart+VALUE_OFFSET)-'0';
if ((param<0)||(param>=ARGS)||(((value!=0)&&(value!=1)))) { // invalid command?
report(F("server-> got strange param/value: "), MI_VERB); reportInt(param, MI_VERB); spdiv;
reportInt(value, MI_VERB); spln();
existCommand=false;
logger(__LINE__, ((param & 0xfc)<<4)+(value&0x3), LOG_DONT_HALT);
}
if (existCommand) report(F("server-> nonempty ajax req; param/value "), MI_VERB); sp(ARG_NAMES[param]); sp_; spbln(value);
}
else {
report(F("server-> empty ajax request\r\n"), MI_VERB);
existCommand=false;
}
}
else if (strstr(genBuf, dumpPhrase)) {//------------
dumpFound=true;
report(F("server-> dump phrase found\r\n"), MI_VERB);
}
else if (strstr(genBuf, faviconPhrase)) {//------------
faviconFound=true;
report(F("server-> favicon phrase found\r\n"), MI_VERB);
}
}
else if (!strcmp(genBuf, emptyPhrase)) { //--------request assembled
report(F("server-> found empty\r\n"), MI_VERB);
if (authenticated) {
report(F("server-> authenticated\r\n"), MI_VERB);
if (ajaxFound) serveAjax(client, param, (bool)value, existCommand, isFullAdmin);
else if (req<ARGS) serveRequest(req, uriReqValue, isFullAdmin);
else if (dumpFound) serveDump(client, isFullAdmin);
else if (faviconFound) serve404();
else if (httpFound) servePage(client);
else {
report(F("server-> request not understandable: (possibly) logging & closing cnx\r\n"), MI_VERB);
if(!hackCtr) logger(__LINE__, 0, LOG_DONT_HALT); // log only if counter null
if(hackCtr<UCHAR_MAX) hackCtr++;
cnxOK=false;
break;
}
}
else {
report(F("server-> not auhenticated\r\n"), MI_VERB);
serveAuthPage(client);
}
break;
}
else {
; //Nothing interesting on this line
}
bufPtr=0; memset(genBuf, '\0', sizeof(genBuf)); //sign the string with zero whatever its length
}
else {// line not fully assembled
if (lineLen++ > MAX_LINE_LEN) {
report(F("\r\nserver-> too long line\r\n"), LO_VERB);
if(!hackCtr) logger(__LINE__, 0, LOG_DONT_HALT); // log only if counter null
if(hackCtr<UCHAR_MAX) hackCtr++;
cnxOK=false;
break;
}
else {
; //this byte has no interest
}
}
}//end if client data available
else {// connected but nothing comes from enet
delay(1);
if ((idleCnxCtr++)>TIME_OUT){
if(!hackCtr) logger(__LINE__, 0, LOG_DONT_HALT); // log only if counter null
if(hackCtr<UCHAR_MAX) hackCtr++;
cnxOK=false;
}
}
}
// end client connected())
report(F("server-> client ip "), MI_VERB); spln(currClientIP);
if (!cnxOK) {
report(F("server-> misbehaviour, closing cnx\r\n"), MI_VERB);
if(currClientIP!=prevClientIP){
logger(__LINE__, currClientIP[0], LOG_DONT_HALT);
logger(__LINE__, currClientIP[1], LOG_DONT_HALT);
logger(__LINE__, currClientIP[2], LOG_DONT_HALT);
logger(__LINE__, currClientIP[3], LOG_DONT_HALT);
prevClientIP=currClientIP; // keep this offending IP to avoid relogging same offending successor
}
else{;}
}
if (!client.connected())report(F("server-> end xsaction; cnx closed by client\r\n"), MI_VERB);
else report(F("server-> end xsaction; cnx still open\r\n"), MI_VERB);
report(F("server-> sending stop cnx\r\n"), MI_VERB);
client.stop(); // close the connection
delay(1);//?
report(F("server-> stop cnx sent\r\n"), MI_VERB);
if (authenticated&&(existCommand||(req<ARGS))) {
if (getArg(PERS_HALT)) logger(__LINE__, 0, LOG_PERS_HALT);
writeNVargs();
}
spln();
}