1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

http: allocate memory dynamically on Windows

This commit is contained in:
joe-conigliaro 2019-08-26 04:27:12 +10:00 committed by Alexander Medvednikov
parent ec4ff6e811
commit 836cc32d78
3 changed files with 21 additions and 11 deletions

View File

@ -134,7 +134,7 @@ void vschannel_init() {
tls_ctx.creds_initialized = TRUE;
}
INT request(INT iport, CHAR *host, CHAR *req, CHAR *out)
INT request(INT iport, CHAR *host, CHAR *req, CHAR **out)
{
SecBuffer ExtraData;
SECURITY_STATUS Status;
@ -201,7 +201,6 @@ INT request(INT iport, CHAR *host, CHAR *req, CHAR *out)
return resp_length;
}
// Send a close_notify alert to the server and
// close down the connection.
if(disconnect_from_server()) {
@ -774,7 +773,7 @@ static SECURITY_STATUS client_handshake_loop(BOOL fDoInitialRead, SecBuffer *pEx
}
static SECURITY_STATUS https_make_request(CHAR *req, CHAR *out, int *length) {
static SECURITY_STATUS https_make_request(CHAR *req, CHAR **out, int *length) {
SecPkgContext_StreamSizes Sizes;
SECURITY_STATUS scRet;
SecBufferDesc Message;
@ -860,6 +859,7 @@ static SECURITY_STATUS https_make_request(CHAR *req, CHAR *out, int *length) {
}
// Read data from server until done.
INT buff_size = vsc_init_resp_buff_size;
cbIoBuffer = 0;
while(TRUE){
// Read some data.
@ -936,10 +936,20 @@ static SECURITY_STATUS https_make_request(CHAR *req, CHAR *out, int *length) {
}
}
// increase buffer size if we need
int required_length = *length+(int)pDataBuffer->cbBuffer;
if( required_length > buff_size ) {
CHAR *a = realloc(*out, required_length);
if( a == NULL ) {
scRet = SEC_E_INTERNAL_ERROR;
return scRet;
}
*out = a;
buff_size = required_length;
}
// Copy the decrypted data to our output buffer
memcpy(*out+*length, pDataBuffer->pvBuffer, (int)pDataBuffer->cbBuffer);
*length += (int)pDataBuffer->cbBuffer;
memcpy(out, pDataBuffer->pvBuffer, (int)pDataBuffer->cbBuffer);
out += (int)pDataBuffer->cbBuffer;
// Move any "extra" data to the input buffer.
if(pExtraBuffer) {

View File

@ -11,6 +11,8 @@
#include <security.h>
#include <sspi.h>
#define vsc_init_resp_buff_size 44000
#define IO_BUFFER_SIZE 0x10000
#define TLS_MAX_BUFSIZ 32768
@ -25,10 +27,10 @@ static void vschannel_init();
static void vschannel_cleanup();
static INT request(INT iport, CHAR *host, CHAR *req, CHAR *out);
static INT request(INT iport, CHAR *host, CHAR *req, CHAR **out);
static SECURITY_STATUS https_make_request(
CHAR *req, CHAR *out, int *length);
CHAR *req, CHAR **out, int *length);
static INT connect_to_server(CHAR *host, INT port_number);

View File

@ -18,12 +18,10 @@ fn init_module() {}
fn (req &Request) ssl_do(port int, method, host_name, path string) Response {
C.vschannel_init()
// TODO: joe-c
// dynamically increase in vschannel.c if needed
mut buff := malloc(44000)
mut buff := malloc(C.vsc_init_resp_buff_size)
addr := host_name
sdata := req.build_request_headers(method, host_name, path)
length := int(C.request(port, addr.str, sdata.str, buff))
length := int(C.request(port, addr.str, sdata.str, &buff))
C.vschannel_cleanup()
return parse_response(string(buff, length))