diff --git a/src/HAP.cpp b/src/HAP.cpp index 82a1003..571bbcc 100644 --- a/src/HAP.cpp +++ b/src/HAP.cpp @@ -256,7 +256,7 @@ void HAPClient::processRequest(){ } if(homeSpan.webLog.isEnabled && !strncmp(body,homeSpan.webLog.statusURL.c_str(),homeSpan.webLog.statusURL.length())){ // GET STATUS - AN OPTIONAL, NON-HAP-R2 FEATURE - getStatusURL(this,NULL); + getStatusURL(this,NULL,NULL); return; } @@ -1095,7 +1095,7 @@ int HAPClient::putPrepareURL(char *json){ ////////////////////////////////////// -void HAPClient::getStatusURL(HAPClient *hapClient, void (*callBack)(const char *)){ +void HAPClient::getStatusURL(HAPClient *hapClient, void (*callBack)(const char *, void *), void *user_data){ char clocktime[33]; @@ -1119,9 +1119,9 @@ void HAPClient::getStatusURL(HAPClient *hapClient, void (*callBack)(const char * if(hapClient) LOG2("\n>>>>>>>>>> %s >>>>>>>>>>\n",hapClient->client.remoteIP().toString().c_str()); - hapOut.setHapClient(hapClient).setLogLevel(2).setCallback(callBack); + hapOut.setHapClient(hapClient).setLogLevel(2).setCallback(callBack).setCallbackUserData(user_data); - hapOut << "HTTP/1.1 200 OK\r\nContent-type: text/html; charset=utf-8\r\n\r\n"; + if(!callBack) hapOut << "HTTP/1.1 200 OK\r\nContent-type: text/html; charset=utf-8\r\n\r\n"; hapOut << "" << homeSpan.displayName << "\n"; hapOut << "\n"; hapOut << "

" << homeSpan.displayName << "

\n"; @@ -1191,7 +1191,7 @@ void HAPClient::getStatusURL(HAPClient *hapClient, void (*callBack)(const char * if(homeSpan.weblogCallback){ String usrString; - homeSpan.weblogCallback(usrString); + homeSpan.weblogCallback(usrString); // Callback to add user-defined html in top table. hapOut << usrString.c_str(); } @@ -1593,7 +1593,7 @@ void HapOut::HapStreamBuffer::flushBuffer(){ buffer[num]='\0'; // add null terminator but DO NOT increment num (we don't want terminator considered as part of buffer) if(callBack) - callBack(buffer); + callBack(buffer,callBackUserData); if(logLevel<=homeSpan.getLogLevel()){ if(enablePrettyPrint) // if pretty print needed, use formatted method @@ -1649,8 +1649,9 @@ int HapOut::HapStreamBuffer::sync(){ indent=0; if(callBack){ - callBack(NULL); + callBack(NULL,callBackUserData); callBack=NULL; + callBackUserData=NULL; } mbedtls_sha512_finish_ret(ctx,hash); // finish SHA-384 and store hash diff --git a/src/HAP.h b/src/HAP.h index 6df9859..36f6074 100644 --- a/src/HAP.h +++ b/src/HAP.h @@ -170,7 +170,7 @@ struct HAPClient { static void checkTimedWrites(); // checks for expired Timed Write PIDs, and clears any found (HAP Section 6.7.2.4) static void eventNotify(SpanBuf *pObj, int nObj, int ignoreClient=-1); // transmits EVENT Notifications for nObj SpanBuf objects, pObj, with optional flag to ignore a specific client - static void getStatusURL(HAPClient *, void (*)(const char *)); // GET / status (an optional, non-HAP feature) + static void getStatusURL(HAPClient *, void (*)(const char *, void *), void *); // GET / status (an optional, non-HAP feature) class HAPTLV : public TLV8 { // dedicated class for HAP TLV8 records public: @@ -198,7 +198,8 @@ class HapOut : public std::ostream { size_t indent=0; uint8_t *hash; mbedtls_sha512_context *ctx; - void (*callBack)(const char *)=NULL; + void (*callBack)(const char *, void *)=NULL; + void *callBackUserData = NULL; void flushBuffer(); int_type overflow(int_type c) override; @@ -220,7 +221,8 @@ class HapOut : public std::ostream { HapOut& setHapClient(HAPClient *hapClient){hapBuffer.hapClient=hapClient;return(*this);} HapOut& setLogLevel(int logLevel){hapBuffer.logLevel=logLevel;return(*this);} HapOut& prettyPrint(){hapBuffer.enablePrettyPrint=true;hapBuffer.logLevel=0;return(*this);} - HapOut& setCallback(void(*f)(const char *)){hapBuffer.callBack=f;return(*this);} + HapOut& setCallback(void(*f)(const char *, void *)){hapBuffer.callBack=f;return(*this);} + HapOut& setCallbackUserData(void *userData){hapBuffer.callBackUserData=userData;return(*this);} uint8_t *getHash(){return(hapBuffer.hash);} size_t getSize(){return(hapBuffer.getSize());} diff --git a/src/HomeSpan.cpp b/src/HomeSpan.cpp index f45dedb..84c3c65 100644 --- a/src/HomeSpan.cpp +++ b/src/HomeSpan.cpp @@ -1148,8 +1148,8 @@ void Span::processSerialCommand(const char *c){ /////////////////////////////// -void Span::getWebLog(void (*f)(const char *)){ - HAPClient::getStatusURL(NULL,f); +void Span::getWebLog(void (*f)(const char *, void *), void *user_data){ + HAPClient::getStatusURL(NULL,f,user_data); } /////////////////////////////// diff --git a/src/HomeSpan.h b/src/HomeSpan.h index 7a4d7ba..1c4262e 100644 --- a/src/HomeSpan.h +++ b/src/HomeSpan.h @@ -362,7 +362,7 @@ class Span{ Span& setWebLogCSS(const char *css){webLog.css="\n" + String(css) + "\n";return(*this);} Span& setWebLogCallback(void (*f)(String &)){weblogCallback=f;return(*this);} - void getWebLog(void (*f)(const char *)); + void getWebLog(void (*f)(const char *, void *), void *); Span& setVerboseWifiReconnect(bool verbose=true){verboseWifiReconnect=verbose;return(*this);}