refactored tlvRespond() to use hapOut instead of sendEncrypted()

To do:

1) update putPrepareURL() to use hapOut instead of sendEncrypted()
2) remove sendEncrypted() since it is no longer needed
3) try moving MAllocator template into separate file (memory.h?) so it can be called from any other module
4) remove #include "HomeSpan.h" from TLV8
This commit is contained in:
Gregg 2024-01-10 21:53:37 -06:00
parent fa5455d6f9
commit bddffab7ad
2 changed files with 33 additions and 23 deletions

View File

@ -334,6 +334,7 @@ int HAPClient::postPairSetupURL(uint8_t *content, size_t len){
HAPTLV subTLV;
iosTLV.unpack(content,len);
if(homeSpan.getLogLevel()>1)
iosTLV.print();
LOG2("------------ END TLVS! ------------\n");
@ -478,6 +479,7 @@ int HAPClient::postPairSetupURL(uint8_t *content, size_t len){
}
subTLV.unpack(decrypted,decrypted.len()); // unpack TLV
if(homeSpan.getLogLevel()>1)
subTLV.print(); // print decrypted TLV data
LOG2("---------- END SUB-TLVS! ----------\n");
@ -536,6 +538,7 @@ int HAPClient::postPairSetupURL(uint8_t *content, size_t len){
LOG2("------- ENCRYPTING SUB-TLVS -------\n");
if(homeSpan.getLogLevel()>1)
subTLV.print();
TempBuffer<uint8_t> subPack(subTLV.pack_size()); // create sub-TLV by packing Identifier, PublicKey and Signature TLV records together
@ -581,6 +584,7 @@ int HAPClient::postPairVerifyURL(uint8_t *content, size_t len){
HAPTLV subTLV;
iosTLV.unpack(content,len);
if(homeSpan.getLogLevel()>1)
iosTLV.print();
LOG2("------------ END TLVS! ------------\n");
@ -637,6 +641,7 @@ int HAPClient::postPairVerifyURL(uint8_t *content, size_t len){
LOG2("------- ENCRYPTING SUB-TLVS -------\n");
if(homeSpan.getLogLevel()>1)
subTLV.print();
TempBuffer<uint8_t> subPack(subTLV.pack_size()); // create sub-TLV by packing Identifier and Signature TLV records together
@ -687,6 +692,7 @@ int HAPClient::postPairVerifyURL(uint8_t *content, size_t len){
}
subTLV.unpack(decrypted,decrypted.len()); // unpack TLV
if(homeSpan.getLogLevel()>1)
subTLV.print(); // print decrypted TLV data
LOG2("---------- END SUB-TLVS! ----------\n");
@ -769,6 +775,7 @@ int HAPClient::postPairingsURL(uint8_t *content, size_t len){
HAPTLV responseTLV;
iosTLV.unpack(content,len);
if(homeSpan.getLogLevel()>1)
iosTLV.print();
LOG2("------------ END TLVS! ------------\n");
@ -1307,25 +1314,27 @@ void HAPClient::eventNotify(SpanBuf *pObj, int nObj, int ignoreClient){
void HAPClient::tlvRespond(TLV8 &tlv8){
TempBuffer<uint8_t> tBuf(tlv8.pack_size()); // create buffer to hold TLV data
tlv8.pack(tBuf); // pack TLV records into buffer
tlv8.osprint(hapOut);
size_t nBytes=hapOut.getSize();
hapOut.flush();
char *body;
asprintf(&body,"HTTP/1.1 200 OK\r\nContent-Type: application/pairing+tlv8\r\nContent-Length: %d\r\n\r\n",tBuf.len()); // create Body with Content Length = size of TLV data
asprintf(&body,"HTTP/1.1 200 OK\r\nContent-Type: application/pairing+tlv8\r\nContent-Length: %d\r\n\r\n",nBytes); // create Body with Content Length = size of TLV data
LOG2("\n>>>>>>>>>> %s >>>>>>>>>>\n",client.remoteIP().toString().c_str());
LOG2(body);
if(homeSpan.getLogLevel()>1)
tlv8.print();
if(!cPair){ // unverified, unencrypted session
client.print(body);
client.write(tBuf,tBuf.len());
LOG2("------------ SENT! --------------\n");
} else {
sendEncrypted(body,tBuf,tBuf.len());
}
hapOut.setHapClient(this);
hapOut << body;
tlv8.osprint(hapOut);
hapOut.flush();
free(body);
if(!cPair)
LOG2("------------ SENT! --------------\n");
else
LOG2("-------- SENT ENCRYPTED! --------\n");
} // tlvRespond

View File

@ -29,6 +29,7 @@
#include <sstream>
#include <forward_list>
#include <memory>
#include "HomeSpan.h"