From e8f9ca8ac1ad214bd15d91268056b2b06f8b2261 Mon Sep 17 00:00:00 2001 From: Gregg Date: Sat, 30 Mar 2024 06:03:31 -0500 Subject: [PATCH] Modified UUID check to allow for Custom short-form UUID Also truncated string Characteristics printed via 'i' CLI Command to show only first 32 characters followed by "..." if there are more than 32. --- src/HomeSpan.cpp | 6 +++--- src/HomeSpan.h | 7 +++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/HomeSpan.cpp b/src/HomeSpan.cpp index 73973fb..6b0891d 100644 --- a/src/HomeSpan.cpp +++ b/src/HomeSpan.cpp @@ -887,8 +887,8 @@ void Span::processSerialCommand(const char *c){ isBridge=false; // ...this is not a bridge device for(auto chr=(*svc)->Characteristics.begin(); chr!=(*svc)->Characteristics.end(); chr++){ - LOG0(" \u21e8 Characteristic %s(%s): IID=%d, %sUUID=\"%s\", %sPerms=", - (*chr)->hapName,(*chr)->uvPrint((*chr)->value).c_str(),(*chr)->iid,(*chr)->isCustom?"Custom-":"",(*chr)->type,(*chr)->perms!=(*chr)->hapChar->perms?"Custom-":""); + LOG0(" \u21e8 Characteristic %s(%.32s%s): IID=%d, %sUUID=\"%s\", %sPerms=", + (*chr)->hapName,(*chr)->uvPrint((*chr)->value).c_str(),strlen((*chr)->uvPrint((*chr)->value).c_str())>32?"...":"",(*chr)->iid,(*chr)->isCustom?"Custom-":"",(*chr)->type,(*chr)->perms!=(*chr)->hapChar->perms?"Custom-":""); int foundPerms=0; for(uint8_t i=0;i<7;i++){ @@ -925,7 +925,7 @@ void Span::processSerialCommand(const char *c){ if(!(*chr)->isCustom && !(*svc)->isCustom && std::find((*svc)->req.begin(),(*svc)->req.end(),(*chr)->hapChar)==(*svc)->req.end() && std::find((*svc)->opt.begin(),(*svc)->opt.end(),(*chr)->hapChar)==(*svc)->opt.end()) LOG0(" *** WARNING #%d! Service does not support this Characteristic ***\n",++nWarnings); else - if(invalidUUID((*chr)->type,(*chr)->isCustom)) + if(invalidUUID((*chr)->type)) LOG0(" *** ERROR #%d! Format of UUID is invalid ***\n",++nErrors); else if(std::find_if((*svc)->Characteristics.begin(),chr,[chr](SpanCharacteristic *c)->boolean{return(c->hapChar==(*chr)->hapChar);})!=chr) diff --git a/src/HomeSpan.h b/src/HomeSpan.h index 2938f4a..2d0fa22 100644 --- a/src/HomeSpan.h +++ b/src/HomeSpan.h @@ -287,10 +287,13 @@ class Span{ void clearNotify(int slotNum); // set ev notification flags for connection 'slotNum' to false across all characteristics void printfNotify(SpanBuf *pObj, int nObj, int conNum); // writes notification JSON to hapOut stream based on SpanBuf objects and specified connection number - static boolean invalidUUID(const char *uuid, boolean isCustom){ + static boolean invalidUUID(const char *uuid){ int x=0; + sscanf(uuid,"%*8[0-9a-fA-F]%n",&x); // check for short-form of UUID + if(strlen(uuid)==x && uuid[0]!='0') + return(false); sscanf(uuid,"%*8[0-9a-fA-F]-%*4[0-9a-fA-F]-%*4[0-9a-fA-F]-%*4[0-9a-fA-F]-%*12[0-9a-fA-F]%n",&x); - return(isCustom && (strlen(uuid)!=36 || x!=36)); + return(strlen(uuid)!=36 || x!=36); } public: