Adding userData to getweblogs callback.
Allows user-specific data to be available in the callback that returns weblog HTML data.
This commit is contained in:
parent
27addd274e
commit
996e94cd5a
13
src/HAP.cpp
13
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
|
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;
|
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];
|
char clocktime[33];
|
||||||
|
|
||||||
|
|
@ -1119,7 +1119,7 @@ void HAPClient::getStatusURL(HAPClient *hapClient, void (*callBack)(const char *
|
||||||
if(hapClient)
|
if(hapClient)
|
||||||
LOG2("\n>>>>>>>>>> %s >>>>>>>>>>\n",hapClient->client.remoteIP().toString().c_str());
|
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";
|
hapOut << "HTTP/1.1 200 OK\r\nContent-type: text/html; charset=utf-8\r\n\r\n";
|
||||||
hapOut << "<html><head><title>" << homeSpan.displayName << "</title>\n";
|
hapOut << "<html><head><title>" << homeSpan.displayName << "</title>\n";
|
||||||
|
|
@ -1191,7 +1191,7 @@ void HAPClient::getStatusURL(HAPClient *hapClient, void (*callBack)(const char *
|
||||||
|
|
||||||
if(homeSpan.weblogCallback){
|
if(homeSpan.weblogCallback){
|
||||||
String usrString;
|
String usrString;
|
||||||
homeSpan.weblogCallback(usrString);
|
homeSpan.weblogCallback(usrString); // Callback to add user-defined html in top table.
|
||||||
hapOut << usrString.c_str();
|
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)
|
buffer[num]='\0'; // add null terminator but DO NOT increment num (we don't want terminator considered as part of buffer)
|
||||||
|
|
||||||
if(callBack)
|
if(callBack)
|
||||||
callBack(buffer);
|
callBack(buffer,callBackUserData);
|
||||||
|
|
||||||
if(logLevel<=homeSpan.getLogLevel()){
|
if(logLevel<=homeSpan.getLogLevel()){
|
||||||
if(enablePrettyPrint) // if pretty print needed, use formatted method
|
if(enablePrettyPrint) // if pretty print needed, use formatted method
|
||||||
|
|
@ -1649,8 +1649,9 @@ int HapOut::HapStreamBuffer::sync(){
|
||||||
indent=0;
|
indent=0;
|
||||||
|
|
||||||
if(callBack){
|
if(callBack){
|
||||||
callBack(NULL);
|
callBack(NULL,callBackUserData);
|
||||||
callBack=NULL;
|
callBack=NULL;
|
||||||
|
callBackUserData=NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
mbedtls_sha512_finish_ret(ctx,hash); // finish SHA-384 and store hash
|
mbedtls_sha512_finish_ret(ctx,hash); // finish SHA-384 and store hash
|
||||||
|
|
|
||||||
|
|
@ -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 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 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
|
class HAPTLV : public TLV8 { // dedicated class for HAP TLV8 records
|
||||||
public:
|
public:
|
||||||
|
|
@ -198,7 +198,8 @@ class HapOut : public std::ostream {
|
||||||
size_t indent=0;
|
size_t indent=0;
|
||||||
uint8_t *hash;
|
uint8_t *hash;
|
||||||
mbedtls_sha512_context *ctx;
|
mbedtls_sha512_context *ctx;
|
||||||
void (*callBack)(const char *)=NULL;
|
void (*callBack)(const char *, void *)=NULL;
|
||||||
|
void *callBackUserData = NULL;
|
||||||
|
|
||||||
void flushBuffer();
|
void flushBuffer();
|
||||||
int_type overflow(int_type c) override;
|
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& setHapClient(HAPClient *hapClient){hapBuffer.hapClient=hapClient;return(*this);}
|
||||||
HapOut& setLogLevel(int logLevel){hapBuffer.logLevel=logLevel;return(*this);}
|
HapOut& setLogLevel(int logLevel){hapBuffer.logLevel=logLevel;return(*this);}
|
||||||
HapOut& prettyPrint(){hapBuffer.enablePrettyPrint=true;hapBuffer.logLevel=0;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);}
|
uint8_t *getHash(){return(hapBuffer.hash);}
|
||||||
size_t getSize(){return(hapBuffer.getSize());}
|
size_t getSize(){return(hapBuffer.getSize());}
|
||||||
|
|
|
||||||
|
|
@ -1147,8 +1147,8 @@ void Span::processSerialCommand(const char *c){
|
||||||
|
|
||||||
///////////////////////////////
|
///////////////////////////////
|
||||||
|
|
||||||
void Span::getWebLog(void (*f)(const char *)){
|
void Span::getWebLog(void (*f)(const char *, void *), void *user_data){
|
||||||
HAPClient::getStatusURL(NULL,f);
|
HAPClient::getStatusURL(NULL,f,user_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////
|
///////////////////////////////
|
||||||
|
|
|
||||||
|
|
@ -358,7 +358,7 @@ class Span{
|
||||||
|
|
||||||
Span& setWebLogCSS(const char *css){webLog.css="\n" + String(css) + "\n";return(*this);}
|
Span& setWebLogCSS(const char *css){webLog.css="\n" + String(css) + "\n";return(*this);}
|
||||||
Span& setWebLogCallback(void (*f)(String &)){weblogCallback=f;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);}
|
Span& setVerboseWifiReconnect(bool verbose=true){verboseWifiReconnect=verbose;return(*this);}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue