mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2025-06-21 06:35:23 +02:00
String cleanup
This commit is contained in:
parent
1bd3fc75e6
commit
79a982bed9
@ -85,7 +85,7 @@ bool Websockets::checkConnectionString(byte clientId,byte * cmd, RingStream * ou
|
|||||||
|
|
||||||
// check contents to find Sec-WebSocket-Key: and get key up to \n
|
// check contents to find Sec-WebSocket-Key: and get key up to \n
|
||||||
if (strlen((char*)cmd)<200) return false;
|
if (strlen((char*)cmd)<200) return false;
|
||||||
auto keyPos=strstr((char*)cmd,"Sec-WebSocket-Key: ");
|
auto keyPos=strstr_P((char*)cmd,(char*)F("Sec-WebSocket-Key: "));
|
||||||
if (!keyPos) return false;
|
if (!keyPos) return false;
|
||||||
keyPos+=19; // length of Sec-Websocket-Key:
|
keyPos+=19; // length of Sec-Websocket-Key:
|
||||||
auto endkeypos=strstr(keyPos,"\r");
|
auto endkeypos=strstr(keyPos,"\r");
|
||||||
@ -97,7 +97,7 @@ bool Websockets::checkConnectionString(byte clientId,byte * cmd, RingStream * ou
|
|||||||
uint8_t sha1HashBin[21] = { 0 }; // 21 to make it base64 div 3
|
uint8_t sha1HashBin[21] = { 0 }; // 21 to make it base64 div 3
|
||||||
char replyKey[100];
|
char replyKey[100];
|
||||||
strlcpy(replyKey,keyPos, sizeof(replyKey));
|
strlcpy(replyKey,keyPos, sizeof(replyKey));
|
||||||
strlcat(replyKey,"258EAFA5-E914-47DA-95CA-C5AB0DC85B11", sizeof(replyKey));
|
strlcat_P(replyKey,(char*)F("258EAFA5-E914-47DA-95CA-C5AB0DC85B11"), sizeof(replyKey));
|
||||||
|
|
||||||
DIAG(F("websock replykey=%s"),replyKey);
|
DIAG(F("websock replykey=%s"),replyKey);
|
||||||
|
|
||||||
@ -109,14 +109,14 @@ bool Websockets::checkConnectionString(byte clientId,byte * cmd, RingStream * ou
|
|||||||
// generate the response and embed the base64 encode
|
// generate the response and embed the base64 encode
|
||||||
// of the key
|
// of the key
|
||||||
outbound->mark(clientId);
|
outbound->mark(clientId);
|
||||||
outbound->print("HTTP/1.1 101 Switching Protocols\r\n"
|
outbound->print(F("HTTP/1.1 101 Switching Protocols\r\n"
|
||||||
"Server: DCCEX-WebSocketsServer\r\n"
|
"Server: DCCEX-WebSocketsServer\r\n"
|
||||||
"Upgrade: websocket\r\n"
|
"Upgrade: websocket\r\n"
|
||||||
"Connection: Upgrade\r\n"
|
"Connection: Upgrade\r\n"
|
||||||
"Origin: null\r\n"
|
"Origin: null\r\n"
|
||||||
"Sec-WebSocket-Version: 13\r\n"
|
"Sec-WebSocket-Version: 13\r\n"
|
||||||
"Sec-WebSocket-Protocol: DCCEX\r\n"
|
"Sec-WebSocket-Protocol: DCCEX\r\n"
|
||||||
"Sec-WebSocket-Accept: ");
|
"Sec-WebSocket-Accept: "));
|
||||||
// encode and emit the reply key as base 64
|
// encode and emit the reply key as base 64
|
||||||
auto * tmp=sha1HashBin;
|
auto * tmp=sha1HashBin;
|
||||||
for (int i=0;i<7;i++) {
|
for (int i=0;i<7;i++) {
|
||||||
@ -126,7 +126,7 @@ bool Websockets::checkConnectionString(byte clientId,byte * cmd, RingStream * ou
|
|||||||
if (i<6) outbound->print(b64_table[tmp[2] & 0x3f]);
|
if (i<6) outbound->print(b64_table[tmp[2] & 0x3f]);
|
||||||
tmp+=3;
|
tmp+=3;
|
||||||
}
|
}
|
||||||
outbound->print("=\r\n\r\n"); // because we have padded 1 byte
|
outbound->print(F("=\r\n\r\n")); // because we have padded 1 byte
|
||||||
outbound->commit();
|
outbound->commit();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ A million repetitions of "a"
|
|||||||
/* #define LITTLE_ENDIAN * This should be #define'd already, if true. */
|
/* #define LITTLE_ENDIAN * This should be #define'd already, if true. */
|
||||||
/* #define SHA1HANDSOFF * Copies data before messing with it. */
|
/* #define SHA1HANDSOFF * Copies data before messing with it. */
|
||||||
|
|
||||||
#if !defined(ESP8266) && !defined(ESP32)
|
// DCC-EX removed #if !defined(ESP8266) && !defined(ESP32)
|
||||||
|
|
||||||
#define SHA1HANDSOFF
|
#define SHA1HANDSOFF
|
||||||
|
|
||||||
@ -203,4 +203,4 @@ void SHA1Final(unsigned char digest[20], SHA1_CTX* context)
|
|||||||
/* ================ end of sha1.c ================ */
|
/* ================ end of sha1.c ================ */
|
||||||
|
|
||||||
|
|
||||||
#endif
|
// DCC-EX Removed: #endif
|
||||||
|
@ -9,8 +9,9 @@ By Steve Reid <steve@edmweb.com>
|
|||||||
100% Public Domain
|
100% Public Domain
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if !defined(ESP8266) && !defined(ESP32)
|
// DCC-EX REMOVED #if !defined(ESP8266) && !defined(ESP32)
|
||||||
|
#ifndef libsha1_h
|
||||||
|
#define libsha1_h
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint32_t state[5];
|
uint32_t state[5];
|
||||||
uint32_t count[2];
|
uint32_t count[2];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user