Data update

This commit is contained in:
Ingy döt Net 2025-02-27 18:35:13 -05:00
parent 8e4e15fa56
commit 72eb4943cb
1853 changed files with 35514 additions and 9441 deletions

View file

@ -0,0 +1,64 @@
#ifdef __FB_WIN32__
#include once "win/winsock2.bi"
Declare Function fbsocket Alias "socket" (af As Long, Type As Long, protocol As Long) As SOCKET
#else
#include once "sys/socket.bi"
#include once "netinet/in.bi"
#include once "arpa/inet.bi"
#include once "netdb.bi"
Declare Function fbsocket Alias "socket" (af As Long, Type As Long, protocol As Long) As Long
#endif
Function main() As Integer
#ifdef __fb_win32__
Dim As WSADATA wsaData
WSAStartup(MAKEWORD(2, 2), @wsaData)
#endif
' Create socket
Dim As Long sock = fbsocket(AF_INET, SOCK_STREAM, 0)
' Get host info
Dim As hostent Ptr host = gethostbyname("www.example.com")
' Set up address structure
Dim As sockaddr_in addr
addr.sin_family = AF_INET
addr.sin_port = htons(443)
addr.sin_addr = *Cast(in_addr Ptr, host->h_addr)
' Connect
connect(sock, Cast(sockaddr Ptr, @addr), Sizeof(sockaddr_in))
' Send request
Dim As String request = "GET / HTTP/1.1" & Chr(13, 10) & _
"Host: www.example.com" & Chr(13, 10) & _
Chr(13, 10)
send(sock, request, Len(request), 0)
' Receive response
Dim As String response
Dim As String buffer = Space(4096)
Dim As Integer bytes
Do
bytes = recv(sock, buffer, 4096, 0)
If bytes > 0 Then response &= Left(buffer, bytes)
Loop While bytes > 0
Print response
' Cleanup
#ifdef __fb_win32__
closesocket(sock)
WSACleanup()
#Else
Close(sock)
#endif
Return 0
End Function
main()
Sleep

View file

@ -1,34 +0,0 @@
/* HTTPS_Client-authenticated.wren */
var CURLOPT_URL = 10002
var CURLOPT_SSLCERT = 10025
var CURLOPT_SSLKEY = 10087
var CURLOPT_KEYPASSWD = 10258
foreign class Curl {
construct easyInit() {}
foreign easySetOpt(opt, param)
foreign easyPerform()
foreign easyCleanup()
}
var curl = Curl.easyInit()
if (curl == 0) {
System.print("Error initializing cURL.")
return
}
curl.easySetOpt(CURLOPT_URL, "https://example.com/")
curl.easySetOpt(CURLOPT_SSLCERT, "cert.pem")
curl.easySetOpt(CURLOPT_SSLKEY, "key.pem")
curl.easySetOpt(CURLOPT_KEYPASSWD, "s3cret")
var status = curl.easyPerform()
if (status != 0) {
System.print("Failed to perform task.")
return
}
curl.easyCleanup()

View file

@ -1,117 +0,0 @@
/* gcc HTTPS_Client-authenticated.c -o HTTPS_Client-authenticated -lcurl -lwren -lm */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <curl/curl.h>
#include "wren.h"
/* C <=> Wren interface functions */
void C_curlAllocate(WrenVM* vm) {
CURL** pcurl = (CURL**)wrenSetSlotNewForeign(vm, 0, 0, sizeof(CURL*));
*pcurl = curl_easy_init();
}
void C_easyPerform(WrenVM* vm) {
CURL* curl = *(CURL**)wrenGetSlotForeign(vm, 0);
CURLcode cc = curl_easy_perform(curl);
wrenSetSlotDouble(vm, 0, (double)cc);
}
void C_easyCleanup(WrenVM* vm) {
CURL* curl = *(CURL**)wrenGetSlotForeign(vm, 0);
curl_easy_cleanup(curl);
}
void C_easySetOpt(WrenVM* vm) {
CURL* curl = *(CURL**)wrenGetSlotForeign(vm, 0);
CURLoption opt = (CURLoption)wrenGetSlotDouble(vm, 1);
const char *arg = wrenGetSlotString(vm, 2);
curl_easy_setopt(curl, opt, arg);
}
WrenForeignClassMethods bindForeignClass(WrenVM* vm, const char* module, const char* className) {
WrenForeignClassMethods methods;
methods.allocate = NULL;
methods.finalize = NULL;
if (strcmp(module, "main") == 0) {
if (strcmp(className, "Curl") == 0) {
methods.allocate = C_curlAllocate;
}
}
return methods;
}
WrenForeignMethodFn bindForeignMethod(
WrenVM* vm,
const char* module,
const char* className,
bool isStatic,
const char* signature) {
if (strcmp(module, "main") == 0) {
if (strcmp(className, "Curl") == 0) {
if (!isStatic && strcmp(signature, "easySetOpt(_,_)") == 0) return C_easySetOpt;
if (!isStatic && strcmp(signature, "easyPerform()") == 0) return C_easyPerform;
if (!isStatic && strcmp(signature, "easyCleanup()") == 0) return C_easyCleanup;
}
}
return NULL;
}
static void writeFn(WrenVM* vm, const char* text) {
printf("%s", text);
}
void errorFn(WrenVM* vm, WrenErrorType errorType, const char* module, const int line, const char* msg) {
switch (errorType) {
case WREN_ERROR_COMPILE:
printf("[%s line %d] [Error] %s\n", module, line, msg);
break;
case WREN_ERROR_STACK_TRACE:
printf("[%s line %d] in %s\n", module, line, msg);
break;
case WREN_ERROR_RUNTIME:
printf("[Runtime Error] %s\n", msg);
break;
}
}
char *readFile(const char *fileName) {
FILE *f = fopen(fileName, "r");
fseek(f, 0, SEEK_END);
long fsize = ftell(f);
rewind(f);
char *script = malloc(fsize + 1);
fread(script, 1, fsize, f);
fclose(f);
script[fsize] = 0;
return script;
}
int main(int argc, char **argv) {
WrenConfiguration config;
wrenInitConfiguration(&config);
config.writeFn = &writeFn;
config.errorFn = &errorFn;
config.bindForeignClassFn = &bindForeignClass;
config.bindForeignMethodFn = &bindForeignMethod;
WrenVM* vm = wrenNewVM(&config);
const char* module = "main";
const char* fileName = "HTTPS_Client-authenticated.wren";
char *script = readFile(fileName);
WrenInterpretResult result = wrenInterpret(vm, module, script);
switch (result) {
case WREN_RESULT_COMPILE_ERROR:
printf("Compile Error!\n");
break;
case WREN_RESULT_RUNTIME_ERROR:
printf("Runtime Error!\n");
break;
case WREN_RESULT_SUCCESS:
break;
}
wrenFreeVM(vm);
free(script);
return 0;
}

View file

@ -0,0 +1,7 @@
import "os" for Process
var certFile = "myCert.pem"
var keyFile = "myKey.pem"
var url = "www.example.com"
Process.exec("curl", ["--cert", certFile, "--key", keyFile, url])