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:
parent
ec4ff6e811
commit
836cc32d78
20
thirdparty/vschannel/vschannel.c
vendored
20
thirdparty/vschannel/vschannel.c
vendored
@ -134,7 +134,7 @@ void vschannel_init() {
|
|||||||
tls_ctx.creds_initialized = TRUE;
|
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;
|
SecBuffer ExtraData;
|
||||||
SECURITY_STATUS Status;
|
SECURITY_STATUS Status;
|
||||||
@ -201,7 +201,6 @@ INT request(INT iport, CHAR *host, CHAR *req, CHAR *out)
|
|||||||
return resp_length;
|
return resp_length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Send a close_notify alert to the server and
|
// Send a close_notify alert to the server and
|
||||||
// close down the connection.
|
// close down the connection.
|
||||||
if(disconnect_from_server()) {
|
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;
|
SecPkgContext_StreamSizes Sizes;
|
||||||
SECURITY_STATUS scRet;
|
SECURITY_STATUS scRet;
|
||||||
SecBufferDesc Message;
|
SecBufferDesc Message;
|
||||||
@ -860,6 +859,7 @@ static SECURITY_STATUS https_make_request(CHAR *req, CHAR *out, int *length) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Read data from server until done.
|
// Read data from server until done.
|
||||||
|
INT buff_size = vsc_init_resp_buff_size;
|
||||||
cbIoBuffer = 0;
|
cbIoBuffer = 0;
|
||||||
while(TRUE){
|
while(TRUE){
|
||||||
// Read some data.
|
// 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
|
// Copy the decrypted data to our output buffer
|
||||||
|
memcpy(*out+*length, pDataBuffer->pvBuffer, (int)pDataBuffer->cbBuffer);
|
||||||
*length += (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.
|
// Move any "extra" data to the input buffer.
|
||||||
if(pExtraBuffer) {
|
if(pExtraBuffer) {
|
||||||
|
6
thirdparty/vschannel/vschannel.h
vendored
6
thirdparty/vschannel/vschannel.h
vendored
@ -11,6 +11,8 @@
|
|||||||
#include <security.h>
|
#include <security.h>
|
||||||
#include <sspi.h>
|
#include <sspi.h>
|
||||||
|
|
||||||
|
#define vsc_init_resp_buff_size 44000
|
||||||
|
|
||||||
#define IO_BUFFER_SIZE 0x10000
|
#define IO_BUFFER_SIZE 0x10000
|
||||||
|
|
||||||
#define TLS_MAX_BUFSIZ 32768
|
#define TLS_MAX_BUFSIZ 32768
|
||||||
@ -25,10 +27,10 @@ static void vschannel_init();
|
|||||||
|
|
||||||
static void vschannel_cleanup();
|
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(
|
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);
|
static INT connect_to_server(CHAR *host, INT port_number);
|
||||||
|
|
||||||
|
@ -18,12 +18,10 @@ fn init_module() {}
|
|||||||
|
|
||||||
fn (req &Request) ssl_do(port int, method, host_name, path string) Response {
|
fn (req &Request) ssl_do(port int, method, host_name, path string) Response {
|
||||||
C.vschannel_init()
|
C.vschannel_init()
|
||||||
// TODO: joe-c
|
mut buff := malloc(C.vsc_init_resp_buff_size)
|
||||||
// dynamically increase in vschannel.c if needed
|
|
||||||
mut buff := malloc(44000)
|
|
||||||
addr := host_name
|
addr := host_name
|
||||||
sdata := req.build_request_headers(method, host_name, path)
|
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()
|
C.vschannel_cleanup()
|
||||||
return parse_response(string(buff, length))
|
return parse_response(string(buff, length))
|
||||||
|
Loading…
Reference in New Issue
Block a user