From 254406c8024def664984cdf977dc031841852a0f Mon Sep 17 00:00:00 2001 From: Gregg Date: Wed, 28 Oct 2020 07:31:58 -0500 Subject: [PATCH] Added more error-checking to SpanCharacteristic Checks to ensure that: (A) Characteristic is allowable (i.e. either required or optional) for the defined Service, and (B) Characteristic has not already been instantiated for the defined Service. --- src/HomeSpan.cpp | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/HomeSpan.cpp b/src/HomeSpan.cpp index cb95b83..6f1ba84 100644 --- a/src/HomeSpan.cpp +++ b/src/HomeSpan.cpp @@ -103,7 +103,8 @@ void Span::poll() { Serial.print(displayName); Serial.print(" is READY!\n\n"); isInitialized=true; - } + + } // isInitialized if(strlen(network.wifiData.ssid)>0 && WiFi.status()!=WL_CONNECTED){ initWifi(); @@ -1109,6 +1110,29 @@ SpanCharacteristic::SpanCharacteristic(char *type, uint8_t perms, char *hapName) return; } + char valid=false; + + for(int i=0; !valid && iServices.back()->req.size(); i++) + valid=!strcmp(type,homeSpan.Accessories.back()->Services.back()->req[i]->id); + + for(int i=0; !valid && iServices.back()->opt.size(); i++) + valid=!strcmp(type,homeSpan.Accessories.back()->Services.back()->opt[i]->id); + + if(!valid){ + homeSpan.configLog+=" *** ERROR! Service does not support this Characteristic. ***"; + homeSpan.nFatalErrors++; + } + + valid=true; + + for(int i=0; valid && iServices.back()->Characteristics.size(); i++) + valid=strcmp(type,homeSpan.Accessories.back()->Services.back()->Characteristics[i]->type); + + if(!valid){ + homeSpan.configLog+=" *** ERROR! Characteristic already defined for this Service. ***"; + homeSpan.nFatalErrors++; + } + homeSpan.configLog+="\n"; homeSpan.Accessories.back()->Services.back()->Characteristics.push_back(this); iid=++(homeSpan.Accessories.back()->iidCount);