From 220366da25017dd4b99f2136c1a35a5efc2d3fd8 Mon Sep 17 00:00:00 2001 From: V1K1NGbg Date: Fri, 2 Aug 2024 14:47:21 +0300 Subject: new dependencies --- src/ltn12.d.tl | 45 +++++++++++++++ src/socket.d.tl | 158 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/socket/http.d.tl | 28 +++++++++ src/ssl.d.tl | 113 ++++++++++++++++++++++++++++++++++++ src/ssl/https.d.tl | 50 ++++++++++++++++ 5 files changed, 394 insertions(+) create mode 100644 src/ltn12.d.tl create mode 100644 src/socket.d.tl create mode 100644 src/socket/http.d.tl create mode 100644 src/ssl.d.tl create mode 100644 src/ssl/https.d.tl (limited to 'src') diff --git a/src/ltn12.d.tl b/src/ltn12.d.tl new file mode 100644 index 00000000..cd2375fc --- /dev/null +++ b/src/ltn12.d.tl @@ -0,0 +1,45 @@ + +local record ltn12 + type Filter = function(string): string, string + type Sink = function(string, string): boolean, string + type Source = function(): string, string + + type FancySink = function(string, string): boolean, string | FancySink + type FancySource = function(): string, string | FancySource + + -- Docs just say returns a truthy value on success + -- Since this value should really only be + -- used to check for truthiness, any seems fine here + type Pump = function(Source, Sink): any, string + + record filter + chain: function(Filter, Filter, ...: Filter): Filter + + cycle: function(string, string, any): Filter + end + record pump + all: Pump + step: Pump + end + record sink + chain: function(Filter, Sink): Sink + error: function(string): Sink + file: function(FILE, string): Sink + null: function(): Sink + simplify: function(FancySink): Sink + table: function({string}): Sink, {string} + end + record source + cat: function(Source, ...: Source): Source + chain: function(Source, Filter): Source + empty: function(): Source + error: function(string): Source + file: function(FILE): Source + file: function(FILE, string): Source + simplify: function(FancySource): Source + string: function(string): Source + table: function({string}): Source, {string} + end + end + + return ltn12 \ No newline at end of file diff --git a/src/socket.d.tl b/src/socket.d.tl new file mode 100644 index 00000000..e62e907b --- /dev/null +++ b/src/socket.d.tl @@ -0,0 +1,158 @@ +local ltn12 = require("ltn12") +local Sink = ltn12.Sink +local Source = ltn12.Source + +local record socket + record TCP + -- master methods + bind: function(TCP, string, integer) + connect: function(TCP, string, integer): integer, string + listen: function(TCP, integer): integer, string + + -- client methods + getpeername: function(TCP): string, integer + + enum TCPReceivePattern + "*l" + "*a" + end + enum TCPReceiveError + "closed" + "timeout" + end + receive: function(TCP, TCPReceivePattern|integer, string): string, TCPReceiveError + + send: function(TCP, string, integer, integer): integer, string, integer + + enum TCPShutdownMode + "both" + "send" + "receive" + end + shutdown: function(TCP, TCPShutdownMode): integer + + -- server methods + accept: function(TCP): TCP, string + + -- client and server methods + enum TCPOption + "keepalive" + "reuseaddr" + "tcp-nodelay" + end + enum TCPLinger + "linger" + end + record TCPLingerOption + on: boolean + timeout: integer + end + setoption: function(TCP, TCPOption): integer + setoption: function(TCP, TCPLinger, TCPLingerOption): integer + + -- master, client, and server methods + close: function(TCP) + + getsockname: function(TCP): string, integer + + getstats: function(TCP): integer, integer, integer + + setstats: function(TCP, integer, integer, integer): integer + + enum TCPTimeoutMode + "b" + "t" + end + settimeout: function(TCP, integer, TCPTimeoutMode) + end + record UDP + close: function(UDP) + + getpeername: function(UDP): string, integer + + getsockname: function(UDP): string, integer + + enum UDPTimeout + "timeout" + end + receive: function(UDP, integer): string, UDPTimeout + + receivefrom: function(UDP, integer): string, string, integer, UDPTimeout + + send: function(UDP, string): integer, string + + sendto: function(UDP, string, string, integer): integer, string + + setpeername: function(UDP, string, integer): integer, string + + setsockname: function(UDP, string, integer): integer, string + + enum UDPOptions + "dontroute" + "broadcast" + end + setoption: function(UDP, UDPOptions, boolean): integer, string + + settimeout: function(UDP, integer) + end + tcp: function(): TCP, string + + udp: function(): UDP, string + + record dns + record DNSResolved + name: string + alias: {string} + ip: {string} + end + toip: function(): string + tohostname: function(string): string, DNSResolved|string + gethostname: function(string): string, DNSResolved|string + end + + bind: function(string, integer, integer): TCP + + connect: function(string, integer, string, integer): TCP + + _DEBUG: boolean + + newtry: function(function): function + + protect: function(function): function + + -- tagged records/Table Union types would be nice here, + -- as this should be {TCP|UDP} + -- but I imagine this should be fine for most uses + select: function({UDP}, {UDP}, integer): {UDP}, {UDP}, string + select: function({TCP}, {TCP}, integer): {TCP}, {TCP}, string + + enum SinkMode + "http-chunked" + "close-when-done" + "keep-open" + end + + sink: function(SinkMode, UDP): Sink + sink: function(SinkMode, TCP): Sink + + skip: function(integer, ...: any): any... + + sleep: function(integer) + + enum SourceMode + "http-chunked" + "by-length" + "until-closed" + end + + source: function(SourceMode, TCP, integer): Source + source: function(SourceMode, UDP, integer): Source + + gettime: function(): integer + + try: function(...: any): any... + + _VERSION: string +end + +return socket \ No newline at end of file diff --git a/src/socket/http.d.tl b/src/socket/http.d.tl new file mode 100644 index 00000000..2a64872e --- /dev/null +++ b/src/socket/http.d.tl @@ -0,0 +1,28 @@ +local ltn12 = require("ltn12") +local type Pump = ltn12.Pump +local type Sink = ltn12.Sink +local type Source = ltn12.Source + +local record http + request: function(string): string, integer|string, string, string + request: function(string, string): string, integer|string, string, string + record HTTPRequest + url: string + sink: Sink + method: string + headers: {string:string} + source: Source + step: Pump + proxy: string + redirect: boolean + create: function + end + request: function(HTTPRequest): string, integer|string, string, string + + PORT: integer + PROXY: string + TIMEOUT: integer + USERAGENT: string +end + +return http \ No newline at end of file diff --git a/src/ssl.d.tl b/src/ssl.d.tl new file mode 100644 index 00000000..1bd40348 --- /dev/null +++ b/src/ssl.d.tl @@ -0,0 +1,113 @@ +local socket = require("socket") +local TCP = socket.TCP + +local record ssl + record SSLCertificate + certificate: string + key: string + password: string|function + end + record SSLContext + mode: string + protocol: string + key: string + password: string|function + certificate: string + certificates: {SSLCertificate} + cafile: string + capath: string + verify: string|{string} + options: string|{string} + ciphers: string + ciphersuites: string + depth: number + dhparam: function + curve: string + curves_list: string + verifyext: string|{string} + alpn: string|function|{string} + dane: boolean + end + record X509Certificate + enum Algorithm + "sha1" + "sha256" + "sha512" + end + digest: function(X509Certificate, Algorithm): string + extensions: function(X509Certificate): {string} + issued: function(X509Certificate, X509Certificate): string + issuer: function(X509Certificate): string + notbefore: function(X509Certificate): string + notafter: function(X509Certificate): string + pem: function(X509Certificate): string + pubkey: function(X509Certificate): string + serial: function(X509Certificate): string + enum Encoding + "ai5" + "utf8" + end + setencode: function(X509Certificate, Encoding): string + subject: function(X509Certificate): string + validat: function(X509Certificate, string): boolean + end + record SSLConnection + close: function(SSLConnection) + dohandshake: function(SSLConnection): boolean, string + getalpn: function(SSLConnection): string + getfinished: function(SSLConnection): string + getpeercertificate: function(SSLConnection): X509Certificate + getpeercertificate: function(SSLConnection, number): X509Certificate + getpeerchain: function(SSLConnection): X509Certificate + getpeerverification: function(SSLConnection): string + getpeerfinished: function(SSLConnection): string + getsniname: function(SSLConnection): string + getstats: function(SSLConnection): number, number, number + info: function(SSLConnection): table + info: function(SSLConnection, string): string + enum ReceivePattern + "*a" + "*l" + end + receive: function(SSLConnection, number|ReceivePattern): string, string + receive: function(SSLConnection, number|ReceivePattern, string): string, string + send: function(SSLConnection): number, number|string, number + send: function(SSLConnection, number): number, number|string, number + send: function(SSLConnection, number, number): number, number|string, number + setdane: function(SSLConnection, string) + setstats: function(SSLConnection, number, number, number): number + enum TimeoutMode + "b" + "t" + end + settimeout: function(SSLConnection, number) + settimeout: function(SSLConnection, number, TimeoutMode) + settlsa: function(SSLConnection, number, number, number, number) + sni: function(SSLConnection, string) + sni: function(SSLConnection, {string:SSLContext}) + sni: function(SSLConnection, {string:SSLContext}, boolean) + enum Reason + "read" + "write" + "nothing" + end + want: function(SSLConnection): Reason + end + + record config + protocols: {string:boolean} + curves: {string:boolean} + capabilities: {string:boolean} + options: {string:boolean} + algorithms: {string:boolean} + end + + newcontext: function(SSLContext): SSLContext + wrap: function(TCP, SSLContext): SSLConnection + loadcertificate: function(string): X509Certificate + + _COPYRIGHT: string + _VERSION: string +end + +return ssl \ No newline at end of file diff --git a/src/ssl/https.d.tl b/src/ssl/https.d.tl new file mode 100644 index 00000000..94c38df6 --- /dev/null +++ b/src/ssl/https.d.tl @@ -0,0 +1,50 @@ +local ssl = require("ssl") +local SSLCertificate = ssl.SSLCertificate +local SSLConnection = ssl.SSLConnection + +local ltn12 = require("ltn12") +local Pump = ltn12.Pump +local Sink = ltn12.Sink +local Source = ltn12.Source + +local record https + record HTTPSRequest + -- HTTP options + url: string|{string} + sink: Sink + method: string + headers: {string:string} + source: Source + step: Pump + -- proxy: string -- not supported + -- redirect: boolean -- not supported + -- create: function -- https implements its own + + -- SSL options + mode: string + protocol: string + key: string + password: string|function + certificate: string + certificates: {SSLCertificate} + cafile: string + capath: string + verify: string|{string} + options: string|{string} + ciphers: string + ciphersuites: string + depth: number + dhparam: function + curve: string + curves_list: string + verifyext: string|{string} + alpn: string|function|{string} + dane: boolean + end + request: function(string): string, number, {string:string}, string + request: function(string, string): string, number, {string:string}, string + request: function(HTTPSRequest): string, number, {string:string}, string + tcp: function(): function(): SSLConnection +end + +return https \ No newline at end of file -- cgit v1.2.3-55-g6feb