| 970 | ////////////////////////////////////// |
| 971 | |
| 972 | int HAPClient::putCharacteristicsURL(char *json){ |
| 973 | |
| 974 | if(!cPair){ // unverified, unencrypted session |
| 975 | unauthorizedError(); |
| 976 | return(0); |
| 977 | } |
| 978 | |
| 979 | LOG1("In Put Characteristics #%d (%s)...\n",clientNumber,client.remoteIP().toString().c_str()); |
| 980 | |
| 981 | SpanBufVec pVec; |
| 982 | |
| 983 | if(!homeSpan.updateCharacteristics(json, pVec)) // perform update and check for success |
| 984 | return(0); // return if failed to update (error message will have been printed in update) |
| 985 | |
| 986 | boolean multiCast=false; |
| 987 | for(auto it=pVec.begin();it!=pVec.end() && !multiCast;it++) // for each characteristic, check if any status is either NOT OKAY, or if WRITE-RESPONSE is requested |
| 988 | if((*it).status!=StatusCode::OK || (*it).wr) // if so, must use multicast response |
| 989 | multiCast=true; |
| 990 | |
| 991 | LOG2("\n>>>>>>>>>> %s >>>>>>>>>>\n",client.remoteIP().toString().c_str()); |
| 992 | |
| 993 | if(!multiCast){ // JSON object has no content |
| 994 | |
| 995 | hapOut.setLogLevel(2).setHapClient(this); |
| 996 | hapOut << "HTTP/1.1 204 No Content\r\n\r\n"; |
| 997 | hapOut.flush(); |
| 998 | |
| 999 | } else { // multicast response is required |
| 1000 | |
| 1001 | homeSpan.printfAttributes(pVec); |
| 1002 | size_t nBytes=hapOut.getSize(); |
| 1003 | hapOut.flush(); |
| 1004 | |
| 1005 | hapOut.setLogLevel(2).setHapClient(this); |
| 1006 | hapOut << "HTTP/1.1 207 Multi-Status\r\nContent-Type: application/hap+json\r\nContent-Length: " << nBytes << "\r\n\r\n"; |
| 1007 | homeSpan.printfAttributes(pVec); |
| 1008 | hapOut.flush(); |
| 1009 | } |
| 1010 | |
| 1011 | LOG2("\n-------- SENT ENCRYPTED! --------\n"); |
| 1012 | |
| 1013 | // Create and send Event Notifications if needed |
| 1014 | |
| 1015 | eventNotify(pVec,this); // transmit EVENT Notification for objects, except DO NOT notify client making request |
| 1016 | |
| 1017 | return(1); |
| 1018 | } |
| 1019 | |
| 1020 | ////////////////////////////////////// |
| 1021 |
nothing calls this directly
no test coverage detected