Browse Source

Merge remote-tracking branch 'upstream/master'

master
Luna 2 years ago
parent
commit
5686194dbc
  1. 3
      .gitignore
  2. 3
      thirdparty/stb_image/stb_image.h
  3. 20
      thirdparty/vschannel/vschannel.c
  4. 6
      thirdparty/vschannel/vschannel.h
  5. 6
      vlib/http/backend_win.v
  6. 11
      vlib/time/time.v

3
.gitignore

@ -11,10 +11,11 @@
*.exe
*.o
.*.c
*.tmp.c
*.obj
*.pdb
*.tmp.c
fns.txt
vc_bootstrap

3
thirdparty/stb_image/stb_image.h

@ -315,6 +315,9 @@ RECENT REVISION HISTORY:
// want the zlib decoder to be available, #define STBI_SUPPORT_ZLIB
//
#ifdef __TINYC__
#define STBI_NO_SIMD
#endif
#ifndef STBI_NO_STDIO
#include <stdio.h>

20
thirdparty/vschannel/vschannel.c

@ -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) {

6
thirdparty/vschannel/vschannel.h

@ -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);

6
vlib/http/backend_win.v

@ -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))

11
vlib/time/time.v

@ -366,9 +366,14 @@ pub fn (t Time) relative() string {
}
pub fn day_of_week(y, m, d int) int {
// TODO please no
//# return (d += m < 3 ? y-- : y - 2, 23*m/9 + d + 4 + y/4- y/100 + y/400)%7;
return 0
// Sakomotho's algorithm is explained here:
// https://stackoverflow.com/a/6385934
t := [0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4]
mut sy := y
if (m < 3) {
sy = sy - 1
}
return ( sy + sy/4 - sy/100 + sy/400 + t[m-1] + d - 1) % 7 + 1
}
pub fn (t Time) day_of_week() int {

Loading…
Cancel
Save