@@ -161,15 +161,14 @@ uint8_t WebSockets::createHeader(uint8_t * headerPtr, WSopcode_t opcode, size_t
161161 * @param client WSclient_t * ptr to the client struct
162162 * @param opcode WSopcode_t
163163 * @param length size_t length of the payload
164- * @param mask bool add dummy mask to the frame (needed for web browser)
165164 * @param fin bool can be used to send data in more then one frame (set fin on the last frame)
166165 * @return true if ok
167166 */
168- bool WebSockets::sendFrameHeader (WSclient_t * client, WSopcode_t opcode, size_t length, bool mask, bool fin) {
167+ bool WebSockets::sendFrameHeader (WSclient_t * client, WSopcode_t opcode, size_t length, bool fin) {
169168 uint8_t maskKey[4 ] = { 0x00 , 0x00 , 0x00 , 0x00 };
170169 uint8_t buffer[WEBSOCKETS_MAX_HEADER_SIZE] = { 0 };
171170
172- uint8_t headerSize = createHeader (&buffer[0 ], opcode, length, mask , maskKey, fin);
171+ uint8_t headerSize = createHeader (&buffer[0 ], opcode, length, client-> cIsClient , maskKey, fin);
173172
174173 if (write (client, &buffer[0 ], headerSize) != headerSize) {
175174 return false ;
@@ -186,12 +185,11 @@ bool WebSockets::sendFrameHeader(WSclient_t * client, WSopcode_t opcode, size_t
186185 * @param opcode WSopcode_t
187186 * @param payload uint8_t * ptr to the payload
188187 * @param length size_t length of the payload
189- * @param mask bool add dummy mask to the frame (needed for web browser)
190188 * @param fin bool can be used to send data in more then one frame (set fin on the last frame)
191189 * @param headerToPayload bool set true if the payload has reserved 14 Byte at the beginning to dynamically add the Header (payload neet to be in RAM!)
192190 * @return true if ok
193191 */
194- bool WebSockets::sendFrame (WSclient_t * client, WSopcode_t opcode, uint8_t * payload, size_t length, bool mask, bool fin, bool headerToPayload) {
192+ bool WebSockets::sendFrame (WSclient_t * client, WSopcode_t opcode, uint8_t * payload, size_t length, bool fin, bool headerToPayload) {
195193
196194 if (client->tcp && !client->tcp ->connected ()) {
197195 DEBUG_WEBSOCKETS (" [WS][%d][sendFrame] not Connected!?\n " , client->num );
@@ -204,7 +202,7 @@ bool WebSockets::sendFrame(WSclient_t * client, WSopcode_t opcode, uint8_t * pay
204202 }
205203
206204 DEBUG_WEBSOCKETS (" [WS][%d][sendFrame] ------- send message frame -------\n " , client->num );
207- DEBUG_WEBSOCKETS (" [WS][%d][sendFrame] fin: %u opCode: %u mask: %u length: %u headerToPayload: %u\n " , client->num , fin, opcode, mask , length, headerToPayload);
205+ DEBUG_WEBSOCKETS (" [WS][%d][sendFrame] fin: %u opCode: %u mask: %u length: %u headerToPayload: %u\n " , client->num , fin, opcode, client-> cIsClient , length, headerToPayload);
208206
209207 if (opcode == WSop_text) {
210208 DEBUG_WEBSOCKETS (" [WS][%d][sendFrame] text: %s\n " , client->num , (payload + (headerToPayload ? 14 : 0 )));
@@ -228,7 +226,7 @@ bool WebSockets::sendFrame(WSclient_t * client, WSopcode_t opcode, uint8_t * pay
228226 headerSize = 10 ;
229227 }
230228
231- if (mask ) {
229+ if (client-> cIsClient ) {
232230 headerSize += 4 ;
233231 }
234232
@@ -255,27 +253,27 @@ bool WebSockets::sendFrame(WSclient_t * client, WSopcode_t opcode, uint8_t * pay
255253 headerPtr = &buffer[0 ];
256254 }
257255
258- createHeader (headerPtr, opcode, length, mask, maskKey, fin);
256+ if (client->cIsClient && useInternBuffer) {
257+ // if we use a Intern Buffer we can modify the data
258+ // by this fact its possible the do the masking
259+ for (uint8_t x = 0 ; x < sizeof (maskKey); x++) {
260+ maskKey[x] = random (0xFF );
261+ }
262+ }
259263
260- if (mask) {
261- if (useInternBuffer) {
262- // if we use a Intern Buffer we can modify the data
263- // by this fact its possible the do the masking
264- for (uint8_t x = 0 ; x < sizeof (maskKey); x++) {
265- maskKey[x] = random (0xFF );
266- }
264+ createHeader (headerPtr, opcode, length, client->cIsClient , maskKey, fin);
267265
268- uint8_t * dataMaskPtr;
266+ if (client->cIsClient && useInternBuffer) {
267+ uint8_t * dataMaskPtr;
269268
270- if (headerToPayload) {
271- dataMaskPtr = (payloadPtr + WEBSOCKETS_MAX_HEADER_SIZE);
272- } else {
273- dataMaskPtr = payloadPtr;
274- }
269+ if (headerToPayload) {
270+ dataMaskPtr = (payloadPtr + WEBSOCKETS_MAX_HEADER_SIZE);
271+ } else {
272+ dataMaskPtr = payloadPtr;
273+ }
275274
276- for (size_t x = 0 ; x < length; x++) {
277- dataMaskPtr[x] = (dataMaskPtr[x] ^ maskKey[x % 4 ]);
278- }
275+ for (size_t x = 0 ; x < length; x++) {
276+ dataMaskPtr[x] = (dataMaskPtr[x] ^ maskKey[x % 4 ]);
279277 }
280278 }
281279
@@ -485,17 +483,18 @@ void WebSockets::handleWebsocketPayloadCb(WSclient_t * client, bool ok, uint8_t
485483 break ;
486484 case WSop_ping:
487485 // send pong back
488- sendFrame (client, WSop_pong, payload, header->payloadLen , true );
486+ sendFrame (client, WSop_pong, payload, header->payloadLen );
489487 break ;
490488 case WSop_pong:
491489 DEBUG_WEBSOCKETS (" [WS][%d][handleWebsocket] get pong (%s)\n " , client->num , payload ? (const char *)payload : " " );
492490 break ;
493491 case WSop_close: {
494- uint16_t reasonCode = 1000 ;
495- if (header->payloadLen >= 2 ) {
496- reasonCode = payload[0 ] << 8 | payload[1 ];
497- }
498-
492+ #ifndef NODEBUG_WEBSOCKETS
493+ uint16_t reasonCode = 1000 ;
494+ if (header->payloadLen >= 2 ) {
495+ reasonCode = payload[0 ] << 8 | payload[1 ];
496+ }
497+ #endif
499498 DEBUG_WEBSOCKETS (" [WS][%d][handleWebsocket] get ask for close. Code: %d" , client->num , reasonCode);
500499 if (header->payloadLen > 2 ) {
501500 DEBUG_WEBSOCKETS (" (%s)\n " , (payload + 2 ));
0 commit comments