Signed-off-by: Hans Leidekker hans@codeweavers.com --- dlls/winhttp/request.c | 54 +++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 29 deletions(-)
diff --git a/dlls/winhttp/request.c b/dlls/winhttp/request.c index f2cb24d4486..85b6db6c8e0 100644 --- a/dlls/winhttp/request.c +++ b/dlls/winhttp/request.c @@ -3132,11 +3132,11 @@ HINTERNET WINAPI WinHttpWebSocketCompleteUpgrade( HINTERNET hrequest, DWORD_PTR return hsocket; }
-static DWORD send_bytes( struct netconn *netconn, char *bytes, int len ) +static DWORD send_bytes( struct socket *socket, char *bytes, int len ) { int count; DWORD err; - if ((err = netconn_send( netconn, bytes, len, &count ))) return err; + if ((err = netconn_send( socket->request->netconn, bytes, len, &count ))) return err; return (count == len) ? ERROR_SUCCESS : ERROR_INTERNAL_ERROR; }
@@ -3145,7 +3145,7 @@ static DWORD send_bytes( struct netconn *netconn, char *bytes, int len ) #define RESERVED_BIT (7 << 4) #define CONTROL_BIT (1 << 3)
-static DWORD send_frame( struct netconn *netconn, enum socket_opcode opcode, USHORT status, const char *buf, +static DWORD send_frame( struct socket *socket, enum socket_opcode opcode, USHORT status, const char *buf, DWORD buflen, BOOL final ) { DWORD i = 0, j, ret, offset = 2, len = buflen; @@ -3177,27 +3177,27 @@ static DWORD send_frame( struct netconn *netconn, enum socket_opcode opcode, USH offset += 8; }
- if ((ret = send_bytes( netconn, hdr, offset ))) return ret; + if ((ret = send_bytes( socket, hdr, offset ))) return ret; if (len) { mask = &hdr[offset]; RtlGenRandom( mask, 4 ); - if ((ret = send_bytes( netconn, mask, 4 ))) return ret; + if ((ret = send_bytes( socket, mask, 4 ))) return ret; }
if (opcode == SOCKET_OPCODE_CLOSE) /* prepend status code */ { byte = (status >> 8) ^ mask[i++ % 4]; - if ((ret = send_bytes( netconn, &byte, 1 ))) return ret; + if ((ret = send_bytes( socket, &byte, 1 ))) return ret;
byte = (status & 0xff) ^ mask[i++ % 4]; - if ((ret = send_bytes( netconn, &byte, 1 ))) return ret; + if ((ret = send_bytes( socket, &byte, 1 ))) return ret; }
for (j = 0; j < buflen; j++) { byte = buf[j] ^ mask[i++ % 4]; - if ((ret = send_bytes( netconn, &byte, 1 ))) return ret; + if ((ret = send_bytes( socket, &byte, 1 ))) return ret; }
return ERROR_SUCCESS; @@ -3222,7 +3222,7 @@ static DWORD socket_send( struct socket *socket, WINHTTP_WEB_SOCKET_BUFFER_TYPE enum socket_opcode opcode = map_buffer_type( type ); DWORD ret;
- ret = send_frame( socket->request->netconn, opcode, 0, buf, len, TRUE ); + ret = send_frame( socket, opcode, 0, buf, len, TRUE ); if (async) { if (!ret) @@ -3304,10 +3304,10 @@ DWORD WINAPI WinHttpWebSocketSend( HINTERNET hsocket, WINHTTP_WEB_SOCKET_BUFFER_ return ret; }
-static DWORD receive_bytes( struct netconn *netconn, char *buf, DWORD len, DWORD *ret_len ) +static DWORD receive_bytes( struct socket *socket, char *buf, DWORD len, DWORD *ret_len ) { DWORD err; - if ((err = netconn_recv( netconn, buf, len, 0, (int *)ret_len ))) return err; + if ((err = netconn_recv( socket->request->netconn, buf, len, 0, (int *)ret_len ))) return err; if (*ret_len != len) return ERROR_WINHTTP_INVALID_SERVER_RESPONSE; return ERROR_SUCCESS; } @@ -3328,12 +3328,12 @@ static BOOL is_supported_opcode( enum socket_opcode opcode ) } }
-static DWORD receive_frame( struct netconn *netconn, DWORD *ret_len, enum socket_opcode *opcode ) +static DWORD receive_frame( struct socket *socket, DWORD *ret_len, enum socket_opcode *opcode ) { DWORD ret, len, count; char hdr[2];
- if ((ret = receive_bytes( netconn, hdr, sizeof(hdr), &count ))) return ret; + if ((ret = receive_bytes( socket, hdr, sizeof(hdr), &count ))) return ret; if ((hdr[0] & RESERVED_BIT) || (hdr[1] & MASK_BIT) || !is_supported_opcode( hdr[0] & 0xf )) { return ERROR_WINHTTP_INVALID_SERVER_RESPONSE; @@ -3345,13 +3345,13 @@ static DWORD receive_frame( struct netconn *netconn, DWORD *ret_len, enum socket if (len == 126) { USHORT len16; - if ((ret = receive_bytes( netconn, (char *)&len16, sizeof(len16), &count ))) return ret; + if ((ret = receive_bytes( socket, (char *)&len16, sizeof(len16), &count ))) return ret; len = RtlUshortByteSwap( len16 ); } else if (len == 127) { ULONGLONG len64; - if ((ret = receive_bytes( netconn, (char *)&len64, sizeof(len64), &count ))) return ret; + if ((ret = receive_bytes( socket, (char *)&len64, sizeof(len64), &count ))) return ret; if ((len64 = RtlUlonglongByteSwap( len64 )) > ~0u) return ERROR_NOT_SUPPORTED; len = len64; } @@ -3365,7 +3365,7 @@ static void CALLBACK task_socket_send_pong( TP_CALLBACK_INSTANCE *instance, void struct socket_send *s = ctx;
TRACE("running %p\n", work); - send_frame( s->socket->request->netconn, SOCKET_OPCODE_PONG, 0, NULL, 0, TRUE ); + send_frame( s->socket, SOCKET_OPCODE_PONG, 0, NULL, 0, TRUE );
release_object( &s->socket->hdr ); free( s ); @@ -3389,18 +3389,17 @@ static DWORD socket_send_pong( struct socket *socket ) } return ret; } - return send_frame( socket->request->netconn, SOCKET_OPCODE_PONG, 0, NULL, 0, TRUE ); + return send_frame( socket, SOCKET_OPCODE_PONG, 0, NULL, 0, TRUE ); }
static DWORD socket_drain( struct socket *socket ) { - struct netconn *netconn = socket->request->netconn; DWORD ret, count;
while (socket->read_size) { char buf[1024]; - if ((ret = receive_bytes( netconn, buf, min(socket->read_size, sizeof(buf)), &count ))) return ret; + if ((ret = receive_bytes( socket, buf, min(socket->read_size, sizeof(buf)), &count ))) return ret; socket->read_size -= count; } return ERROR_SUCCESS; @@ -3448,14 +3447,13 @@ static WINHTTP_WEB_SOCKET_BUFFER_TYPE map_opcode( enum socket_opcode opcode, BOO static DWORD socket_receive( struct socket *socket, void *buf, DWORD len, DWORD *ret_len, WINHTTP_WEB_SOCKET_BUFFER_TYPE *ret_type, BOOL async ) { - struct netconn *netconn = socket->request->netconn; DWORD count, ret = ERROR_SUCCESS;
if (!socket->read_size) { for (;;) { - if (!(ret = receive_frame( netconn, &socket->read_size, &socket->opcode ))) + if (!(ret = receive_frame( socket, &socket->read_size, &socket->opcode ))) { if (!(socket->opcode & CONTROL_BIT) || (ret = handle_control_frame( socket ))) break; } @@ -3463,7 +3461,7 @@ static DWORD socket_receive( struct socket *socket, void *buf, DWORD len, DWORD if (ret) break; } } - if (!ret) ret = receive_bytes( netconn, buf, min(len, socket->read_size), &count ); + if (!ret) ret = receive_bytes( socket, buf, min(len, socket->read_size), &count ); if (!ret) { socket->read_size -= count; @@ -3551,11 +3549,10 @@ DWORD WINAPI WinHttpWebSocketReceive( HINTERNET hsocket, void *buf, DWORD len, D
static DWORD socket_shutdown( struct socket *socket, USHORT status, const void *reason, DWORD len, BOOL async ) { - struct netconn *netconn = socket->request->netconn; DWORD ret;
stop_queue( &socket->send_q ); - if (!(ret = send_frame( netconn, SOCKET_OPCODE_CLOSE, status, reason, len, TRUE ))) + if (!(ret = send_frame( socket, SOCKET_OPCODE_CLOSE, status, reason, len, TRUE ))) { socket->state = SOCKET_STATE_SHUTDOWN; } @@ -3631,7 +3628,6 @@ DWORD WINAPI WinHttpWebSocketShutdown( HINTERNET hsocket, USHORT status, void *r
static DWORD socket_close( struct socket *socket, USHORT status, const void *reason, DWORD len, BOOL async ) { - struct netconn *netconn = socket->request->netconn; DWORD ret, count;
if ((ret = socket_drain( socket ))) goto done; @@ -3639,11 +3635,11 @@ static DWORD socket_close( struct socket *socket, USHORT status, const void *rea if (socket->state < SOCKET_STATE_SHUTDOWN) { stop_queue( &socket->send_q ); - if ((ret = send_frame( netconn, SOCKET_OPCODE_CLOSE, status, reason, len, TRUE ))) goto done; + if ((ret = send_frame( socket, SOCKET_OPCODE_CLOSE, status, reason, len, TRUE ))) goto done; socket->state = SOCKET_STATE_SHUTDOWN; }
- if ((ret = receive_frame( netconn, &count, &socket->opcode ))) goto done; + if ((ret = receive_frame( socket, &count, &socket->opcode ))) goto done; if (socket->opcode != SOCKET_OPCODE_CLOSE || (count && (count < sizeof(socket->status) || count > sizeof(socket->status) + sizeof(socket->reason)))) { @@ -3654,9 +3650,9 @@ static DWORD socket_close( struct socket *socket, USHORT status, const void *rea if (count) { DWORD reason_len = count - sizeof(socket->status); - if ((ret = receive_bytes( netconn, (char *)&socket->status, sizeof(socket->status), &count ))) goto done; + if ((ret = receive_bytes( socket, (char *)&socket->status, sizeof(socket->status), &count ))) goto done; socket->status = RtlUshortByteSwap( socket->status ); - if ((ret = receive_bytes( netconn, socket->reason, reason_len, &socket->reason_len ))) goto done; + if ((ret = receive_bytes( socket, socket->reason, reason_len, &socket->reason_len ))) goto done; } socket->state = SOCKET_STATE_CLOSED;