mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
vlib: fix warnings due to the vfmt change
This commit is contained in:
parent
8d88b73512
commit
aad122334b
@ -26,7 +26,7 @@ pub fn validate(data byteptr, len int) bool {
|
|||||||
return !state.failed && state.subindex <= 0
|
return !state.failed && state.subindex <= 0
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (mut s Utf8State) seq(r0, r1, is_tail bool) bool {
|
fn (mut s Utf8State) seq(r0 bool, r1 bool, is_tail bool) bool {
|
||||||
if s.subindex == 0 || (s.index > 1 && s.subindex == 1) || (s.index >= 6 && s.subindex == 2) {
|
if s.subindex == 0 || (s.index > 1 && s.subindex == 1) || (s.index >= 6 && s.subindex == 2) {
|
||||||
if (s.subindex == 0 && r0) || (s.subindex == 1 && r1) || (s.subindex == 2 && is_tail) {
|
if (s.subindex == 0 && r0) || (s.subindex == 1 && r1) || (s.subindex == 2 && is_tail) {
|
||||||
s.subindex++
|
s.subindex++
|
||||||
|
@ -31,20 +31,16 @@ fn (mut ws Client) handshake() ? {
|
|||||||
}
|
}
|
||||||
handshake_bytes := handshake.bytes()
|
handshake_bytes := handshake.bytes()
|
||||||
ws.debug_log('sending handshake: $handshake')
|
ws.debug_log('sending handshake: $handshake')
|
||||||
ws.socket_write(handshake_bytes)?
|
ws.socket_write(handshake_bytes) ?
|
||||||
ws.read_handshake(seckey)?
|
ws.read_handshake(seckey) ?
|
||||||
unsafe {
|
unsafe {handshake_bytes.free()}
|
||||||
handshake_bytes.free()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// handshake manage the handshake part of connecting
|
// handshake manage the handshake part of connecting
|
||||||
fn (mut s Server) handle_server_handshake(mut c Client) ?(string, &ServerClient) {
|
fn (mut s Server) handle_server_handshake(mut c Client) ?(string, &ServerClient) {
|
||||||
msg := c.read_handshake_str()?
|
msg := c.read_handshake_str() ?
|
||||||
handshake_response, client := s.parse_client_handshake(msg, mut c)?
|
handshake_response, client := s.parse_client_handshake(msg, mut c) ?
|
||||||
unsafe {
|
unsafe {msg.free()}
|
||||||
msg.free()
|
|
||||||
}
|
|
||||||
return handshake_response, client
|
return handshake_response, client
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,7 +76,7 @@ fn (mut s Server) parse_client_handshake(client_handshake string, mut c Client)
|
|||||||
'Sec-WebSocket-Key', 'sec-websocket-key' {
|
'Sec-WebSocket-Key', 'sec-websocket-key' {
|
||||||
key = keys[1].trim_space()
|
key = keys[1].trim_space()
|
||||||
s.logger.debug('server-> got key: $key')
|
s.logger.debug('server-> got key: $key')
|
||||||
seckey = create_key_challenge_response(key)?
|
seckey = create_key_challenge_response(key) ?
|
||||||
s.logger.debug('server-> challenge: $seckey, response: ${keys[1]}')
|
s.logger.debug('server-> challenge: $seckey, response: ${keys[1]}')
|
||||||
flags << .has_accept
|
flags << .has_accept
|
||||||
}
|
}
|
||||||
@ -88,9 +84,7 @@ fn (mut s Server) parse_client_handshake(client_handshake string, mut c Client)
|
|||||||
// We ignore other headers like protocol for now
|
// We ignore other headers like protocol for now
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
unsafe {
|
unsafe {keys.free()}
|
||||||
keys.free()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if flags.len < 3 {
|
if flags.len < 3 {
|
||||||
return error('invalid client handshake, $client_handshake')
|
return error('invalid client handshake, $client_handshake')
|
||||||
@ -117,7 +111,7 @@ fn (mut ws Client) read_handshake_str() ?string {
|
|||||||
mut msg := [1024]byte{}
|
mut msg := [1024]byte{}
|
||||||
mut buffer := [1]byte{}
|
mut buffer := [1]byte{}
|
||||||
for total_bytes_read < 1024 {
|
for total_bytes_read < 1024 {
|
||||||
bytes_read := ws.socket_read_into_ptr(byteptr(&buffer), 1)?
|
bytes_read := ws.socket_read_into_ptr(byteptr(&buffer), 1) ?
|
||||||
if bytes_read == 0 {
|
if bytes_read == 0 {
|
||||||
return error('unexpected no response from handshake')
|
return error('unexpected no response from handshake')
|
||||||
}
|
}
|
||||||
@ -134,14 +128,12 @@ fn (mut ws Client) read_handshake_str() ?string {
|
|||||||
|
|
||||||
// read_handshake reads the handshake and check if valid
|
// read_handshake reads the handshake and check if valid
|
||||||
fn (mut ws Client) read_handshake(seckey string) ? {
|
fn (mut ws Client) read_handshake(seckey string) ? {
|
||||||
mut msg := ws.read_handshake_str()?
|
mut msg := ws.read_handshake_str() ?
|
||||||
ws.check_handshake_response(msg, seckey)?
|
ws.check_handshake_response(msg, seckey) ?
|
||||||
unsafe {
|
unsafe {msg.free()}
|
||||||
msg.free()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (mut ws Client) check_handshake_response(handshake_response, seckey string) ? {
|
fn (mut ws Client) check_handshake_response(handshake_response string, seckey string) ? {
|
||||||
ws.debug_log('handshake response:\n$handshake_response')
|
ws.debug_log('handshake response:\n$handshake_response')
|
||||||
lines := handshake_response.split_into_lines()
|
lines := handshake_response.split_into_lines()
|
||||||
header := lines[0]
|
header := lines[0]
|
||||||
@ -162,27 +154,21 @@ fn (mut ws Client) check_handshake_response(handshake_response, seckey string) ?
|
|||||||
}
|
}
|
||||||
'Sec-WebSocket-Accept', 'sec-websocket-accept' {
|
'Sec-WebSocket-Accept', 'sec-websocket-accept' {
|
||||||
ws.debug_log('seckey: $seckey')
|
ws.debug_log('seckey: $seckey')
|
||||||
challenge := create_key_challenge_response(seckey)?
|
challenge := create_key_challenge_response(seckey) ?
|
||||||
ws.debug_log('challenge: $challenge, response: ${keys[1]}')
|
ws.debug_log('challenge: $challenge, response: ${keys[1]}')
|
||||||
if keys[1].trim_space() != challenge {
|
if keys[1].trim_space() != challenge {
|
||||||
return error('handshake_handler: Sec-WebSocket-Accept header does not match computed sha1/base64 response.')
|
return error('handshake_handler: Sec-WebSocket-Accept header does not match computed sha1/base64 response.')
|
||||||
}
|
}
|
||||||
ws.flags << .has_accept
|
ws.flags << .has_accept
|
||||||
unsafe {
|
unsafe {challenge.free()}
|
||||||
challenge.free()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {}
|
else {}
|
||||||
}
|
}
|
||||||
unsafe {
|
unsafe {keys.free()}
|
||||||
keys.free()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
unsafe {
|
|
||||||
lines.free()
|
|
||||||
}
|
}
|
||||||
|
unsafe {lines.free()}
|
||||||
if ws.flags.len < 3 {
|
if ws.flags.len < 3 {
|
||||||
ws.close(1002, 'invalid websocket HTTP headers')?
|
ws.close(1002, 'invalid websocket HTTP headers') ?
|
||||||
return error('invalid websocket HTTP headers')
|
return error('invalid websocket HTTP headers')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user