YAPC::EU 2018 Glasgow Update!

This commit is contained in:
Ingy döt Net 2018-08-17 15:15:24 +01:00
parent 22f33d4004
commit 4e2d22a71d
1170 changed files with 15042 additions and 3047 deletions

View file

@ -0,0 +1,69 @@
' SSL library
PRAGMA INCLUDE <openssl/ssl.h> <openssl/err.h>
PRAGMA LDFLAGS -lcrypto -lssl
' Using RAM disk as a string
OPTION MEMSTREAM TRUE
' BaCon must not choke on SSL functions
OPTION PARSE FALSE
' Request to send to remote webserver (CONST is a macro def)
CONST req$ = "GET / HTTP/1.1\r\nHost: " & TOKEN$(website$, 1, ":") & "\r\n\r\n"
' Some SSL related variables
DECLARE ctx TYPE SSL_CTX*
DECLARE meth TYPE const SSL_METHOD*
DECLARE ssl TYPE SSL*
DECLARE sbio TYPE BIO*
' Which website we need to fetch
IF AMOUNT(ARGUMENT$) = 1 THEN
website$ = "www.google.com:443"
ELSE
website$ = TOKEN$(ARGUMENT$, 2)
END IF
' Initialize SSL
SSL_library_init()
SSL_load_error_strings()
' Create SSL context object
meth = SSLv23_method()
ctx = SSL_CTX_new(meth)
ssl = SSL_new(ctx)
' Cpnnect to website creating a socket
OPEN website$ FOR NETWORK AS mynet
' Perform the SSL handshake using the socket
sbio = BIO_new_socket(mynet, BIO_NOCLOSE)
SSL_set_bio(ssl, sbio, sbio)
IF SSL_connect(ssl) <= 0 THEN
EPRINT "SSL connect error"
END 1
END IF
' Setup buffer for the data coming back
mem = MEMORY(1024)
OPEN mem FOR MEMORY AS buf$
' Send the GET request to the remote server
SSL_write(ssl, req$, LEN(req$))
REPEAT
' Fetch the response into the buffer
SSL_read(ssl, buf$, 1024)
total$ = total$ & buf$
memset((void*)mem, 0, 1024)
UNTIL ISFALSE(WAIT(mynet, 500))
' Bring down SSL
SSL_shutdown(ssl)
' Close handles and free memory
CLOSE MEMORY buf$
CLOSE NETWORK mynet
FREE mem
' Show result
PRINT total$

5
Task/HTTPS/Lua/https.lua Normal file
View file

@ -0,0 +1,5 @@
local request = require('http.request')
local headers, stream = request.new_from_uri("https://sourceforge.net/"):go()
local body = stream:get_body_as_string()
local status = headers:get(':status')
io.write(string.format('Status: %d\nBody: %s\n', status, body)

View file

@ -0,0 +1,9 @@
include builtins\libcurl.e
curl_global_init()
atom curl = curl_easy_init()
curl_easy_setopt(curl, CURLOPT_URL, "https://sourceforge.net/")
object res = curl_easy_perform_ex(curl)
curl_easy_cleanup(curl)
curl_global_cleanup()
puts(1,res)