aboutsummaryrefslogtreecommitdiffstats
path: root/teal-src/util
diff options
context:
space:
mode:
Diffstat (limited to 'teal-src/util')
-rw-r--r--teal-src/util/compat.d.tl4
-rw-r--r--teal-src/util/crand.d.tl6
-rw-r--r--teal-src/util/dataforms.d.tl52
-rw-r--r--teal-src/util/datetime.d.tl11
-rw-r--r--teal-src/util/encodings.d.tl27
-rw-r--r--teal-src/util/error.d.tl78
-rw-r--r--teal-src/util/format.d.tl4
-rw-r--r--teal-src/util/hashes.d.tl21
-rw-r--r--teal-src/util/hex.d.tl6
-rw-r--r--teal-src/util/http.d.tl9
-rw-r--r--teal-src/util/human/units.d.tl5
-rw-r--r--teal-src/util/id.d.tl9
-rw-r--r--teal-src/util/interpolation.d.tl6
-rw-r--r--teal-src/util/jid.d.tl15
-rw-r--r--teal-src/util/json.d.tl5
-rw-r--r--teal-src/util/net.d.tl13
-rw-r--r--teal-src/util/poll.d.tl24
-rw-r--r--teal-src/util/pposix.d.tl106
-rw-r--r--teal-src/util/random.d.tl4
-rw-r--r--teal-src/util/stanza.d.tl61
-rw-r--r--teal-src/util/strbitop.d.tl6
-rw-r--r--teal-src/util/table.d.tl6
-rw-r--r--teal-src/util/time.d.tl6
-rw-r--r--teal-src/util/uuid.d.tl5
24 files changed, 489 insertions, 0 deletions
diff --git a/teal-src/util/compat.d.tl b/teal-src/util/compat.d.tl
new file mode 100644
index 00000000..da9c6083
--- /dev/null
+++ b/teal-src/util/compat.d.tl
@@ -0,0 +1,4 @@
+local record lib
+ xpcall : function (function, function, ...:any):boolean, any
+end
+return lib
diff --git a/teal-src/util/crand.d.tl b/teal-src/util/crand.d.tl
new file mode 100644
index 00000000..80564025
--- /dev/null
+++ b/teal-src/util/crand.d.tl
@@ -0,0 +1,6 @@
+local record lib
+ bytes : function (n : number) : string
+ enum sourceid "OpenSSL" "arc4random()" "Linux" end
+ _source : sourceid
+end
+return lib
diff --git a/teal-src/util/dataforms.d.tl b/teal-src/util/dataforms.d.tl
new file mode 100644
index 00000000..9e4170fa
--- /dev/null
+++ b/teal-src/util/dataforms.d.tl
@@ -0,0 +1,52 @@
+local stanza_t = require "util.stanza".stanza_t
+
+local enum form_type
+ "form"
+ "submit"
+ "cancel"
+ "result"
+end
+
+local enum field_type
+ "boolean"
+ "fixed"
+ "hidden"
+ "jid-multi"
+ "jid-single"
+ "list-multi"
+ "list-single"
+ "text-multi"
+ "text-private"
+ "text-single"
+end
+
+local record form_field
+
+ type : field_type
+ var : string -- protocol name
+ name : string -- internal name
+
+ label : string
+ desc : string
+
+ datatype : string
+ range_min : number
+ range_max : number
+
+ value : any -- depends on field_type
+ options : table
+end
+
+local record dataform
+ title : string
+ instructions : string
+ { form_field } -- XXX https://github.com/teal-language/tl/pull/415
+
+ form : function ( dataform, table, form_type ) : stanza_t
+end
+
+local record lib
+ new : function ( dataform ) : dataform
+end
+
+return lib
diff --git a/teal-src/util/datetime.d.tl b/teal-src/util/datetime.d.tl
new file mode 100644
index 00000000..530b4eb7
--- /dev/null
+++ b/teal-src/util/datetime.d.tl
@@ -0,0 +1,11 @@
+-- TODO s/number/integer/ once Teal gets support for that
+
+local record lib
+ date : function (t : number) : string
+ datetime : function (t : number) : string
+ time : function (t : number) : string
+ legacy : function (t : number) : string
+ parse : function (t : string) : number
+end
+
+return lib
diff --git a/teal-src/util/encodings.d.tl b/teal-src/util/encodings.d.tl
new file mode 100644
index 00000000..f029f9cf
--- /dev/null
+++ b/teal-src/util/encodings.d.tl
@@ -0,0 +1,27 @@
+-- TODO many actually return Maybe(String)
+local record lib
+ record base64
+ encode : function (s : string) : string
+ decode : function (s : string) : string
+ end
+ record stringprep
+ nameprep : function (s : string, strict : boolean) : string
+ nodeprep : function (s : string, strict : boolean) : string
+ resourceprep : function (s : string, strict : boolean) : string
+ saslprep : function (s : string, strict : boolean) : string
+ end
+ record idna
+ to_ascii : function (s : string) : string
+ to_unicode : function (s : string) : string
+ end
+ record utf8
+ valid : function (s : string) : boolean
+ length : function (s : string) : number
+ end
+ record confusable
+ skeleteon : function (s : string) : string
+ end
+ version : string
+end
+return lib
+
diff --git a/teal-src/util/error.d.tl b/teal-src/util/error.d.tl
new file mode 100644
index 00000000..2dc72f0e
--- /dev/null
+++ b/teal-src/util/error.d.tl
@@ -0,0 +1,78 @@
+local enum error_type
+ "auth"
+ "cancel"
+ "continue"
+ "modify"
+ "wait"
+end
+
+local enum error_condition
+ "bad-request"
+ "conflict"
+ "feature-not-implemented"
+ "forbidden"
+ "gone"
+ "internal-server-error"
+ "item-not-found"
+ "jid-malformed"
+ "not-acceptable"
+ "not-allowed"
+ "not-authorized"
+ "policy-violation"
+ "recipient-unavailable"
+ "redirect"
+ "registration-required"
+ "remote-server-not-found"
+ "remote-server-timeout"
+ "resource-constraint"
+ "service-unavailable"
+ "subscription-required"
+ "undefined-condition"
+ "unexpected-request"
+end
+
+local record protoerror
+ type : error_type
+ condition : error_condition
+ text : string
+ code : number
+end
+
+local record error
+ type : error_type
+ condition : error_condition
+ text : string
+ code : number
+ context : { any : any }
+ source : string
+end
+
+local type compact_registry_item = { string, string, string, string }
+local type compact_registry = { compact_registry_item }
+local type registry = { string : protoerror }
+local type context = { string : any }
+
+local record error_registry_wrapper
+ source : string
+ registry : registry
+ new : function (string, context) : error
+ coerce : function (any, string) : any, error
+ wrap : function (error) : error
+ wrap : function (string, context) : error
+ is_error : function (any) : boolean
+end
+
+local record lib
+ record configure_opt
+ auto_inject_traceback : boolean
+ end
+ new : function (protoerror, context, { string : protoerror }, string) : error
+ init : function (string, string, registry | compact_registry) : error_registry_wrapper
+ init : function (string, registry | compact_registry) : error_registry_wrapper
+ is_error : function (any) : boolean
+ coerce : function (any, string) : any, error
+ from_stanza : function (table, context, string) : error
+ configure : function
+end
+
+return lib
diff --git a/teal-src/util/format.d.tl b/teal-src/util/format.d.tl
new file mode 100644
index 00000000..1ff77c97
--- /dev/null
+++ b/teal-src/util/format.d.tl
@@ -0,0 +1,4 @@
+local record lib
+ format : function (string, ... : any) : string
+end
+return lib
diff --git a/teal-src/util/hashes.d.tl b/teal-src/util/hashes.d.tl
new file mode 100644
index 00000000..70b1d91e
--- /dev/null
+++ b/teal-src/util/hashes.d.tl
@@ -0,0 +1,21 @@
+local type hash = function (msg : string, hex : boolean) : string
+local type hmac = function (key : string, msg : string, hex : boolean) : string
+local type kdf = function (pass : string, salt : string, i : number) : string
+
+local record lib
+ sha1 : hash
+ sha256 : hash
+ sha224 : hash
+ sha384 : hash
+ sha512 : hash
+ md5 : hash
+ hmac_sha1 : hmac
+ hmac_sha256 : hmac
+ hmac_sha512 : hmac
+ hmac_md5 : hmac
+ scram_Hi_sha1 : kdf
+ pbkdf2_hmac_sha1 : kdf
+ pbkdf2_hmac_sha256 : kdf
+ version : string
+end
+return lib
diff --git a/teal-src/util/hex.d.tl b/teal-src/util/hex.d.tl
new file mode 100644
index 00000000..3b216a88
--- /dev/null
+++ b/teal-src/util/hex.d.tl
@@ -0,0 +1,6 @@
+local type s2s = function (s : string) : string
+local record lib
+ to : s2s
+ from : s2s
+end
+return lib
diff --git a/teal-src/util/http.d.tl b/teal-src/util/http.d.tl
new file mode 100644
index 00000000..ecbe35c3
--- /dev/null
+++ b/teal-src/util/http.d.tl
@@ -0,0 +1,9 @@
+local record lib
+ urlencode : function (s : string) : string
+ urldecode : function (s : string) : string
+ formencode : function (f : { string : string }) : string
+ formdecode : function (s : string) : { string : string }
+ contains_token : function (field : string, token : string) : boolean
+ normalize_path : function (path : string) : string
+end
+return lib
diff --git a/teal-src/util/human/units.d.tl b/teal-src/util/human/units.d.tl
new file mode 100644
index 00000000..f6568d90
--- /dev/null
+++ b/teal-src/util/human/units.d.tl
@@ -0,0 +1,5 @@
+local lib = record
+ adjust : function (number, string) : number, string
+ format : function (number, string, string) : string
+end
+return lib
diff --git a/teal-src/util/id.d.tl b/teal-src/util/id.d.tl
new file mode 100644
index 00000000..0f7aeafc
--- /dev/null
+++ b/teal-src/util/id.d.tl
@@ -0,0 +1,9 @@
+local record lib
+ short : function () : string
+ medium : function () : string
+ long : function () : string
+ custom : function (number) : function () : string
+
+end
+return lib
+
diff --git a/teal-src/util/interpolation.d.tl b/teal-src/util/interpolation.d.tl
new file mode 100644
index 00000000..fb653edf
--- /dev/null
+++ b/teal-src/util/interpolation.d.tl
@@ -0,0 +1,6 @@
+local type renderer = function (string, { string : any }) : string
+local type filter = function (string, any) : string
+local record lib
+ new : function (string, string, funcs : { string : filter }) : renderer
+end
+return lib
diff --git a/teal-src/util/jid.d.tl b/teal-src/util/jid.d.tl
new file mode 100644
index 00000000..897318d9
--- /dev/null
+++ b/teal-src/util/jid.d.tl
@@ -0,0 +1,15 @@
+local record lib
+ split : function (string) : string, string, string
+ bare : function (string) : string
+ prepped_split : function (string, boolean) : string, string, string
+ join : function (string, string, string) : string
+ prep : function (string, boolean) : string
+ compare : function (string, string) : boolean
+ node : function (string) : string
+ host : function (string) : string
+ resource : function (string) : string
+ escape : function (string) : string
+ unescape : function (string) : string
+end
+
+return lib
diff --git a/teal-src/util/json.d.tl b/teal-src/util/json.d.tl
new file mode 100644
index 00000000..86a1495e
--- /dev/null
+++ b/teal-src/util/json.d.tl
@@ -0,0 +1,5 @@
+local record lib
+ encode : function (any) : string
+ decode : function (string) : any, string
+end
+return lib
diff --git a/teal-src/util/net.d.tl b/teal-src/util/net.d.tl
new file mode 100644
index 00000000..3fd69748
--- /dev/null
+++ b/teal-src/util/net.d.tl
@@ -0,0 +1,13 @@
+
+local enum type_strings
+ "both"
+ "ipv4"
+ "ipv6"
+end
+
+local record lib
+ local_addresses : function (type_strings, boolean)
+ pton : function (string):string
+ ntop : function (string):string
+end
+return lib
diff --git a/teal-src/util/poll.d.tl b/teal-src/util/poll.d.tl
new file mode 100644
index 00000000..6fce771e
--- /dev/null
+++ b/teal-src/util/poll.d.tl
@@ -0,0 +1,24 @@
+local record state
+ enum waiterr
+ "timeout"
+ "signal"
+ end
+ add : function (state, number, boolean, boolean) : boolean
+ add : function (state, number, boolean, boolean) : nil, string, number
+ set : function (state, number, boolean, boolean) : boolean
+ set : function (state, number, boolean, boolean) : nil, string, number
+ del : function (state, number) : boolean
+ del : function (state, number) : nil, string, number
+ wait : function (state, number) : number, boolean, boolean
+ wait : function (state, number) : nil, string, number
+ wait : function (state, number) : nil, waiterr
+ getfd : function (state) : number
+end
+
+local record lib
+ new : function () : state
+ ENOENT : number
+ EEXIST : number
+end
+
+return lib
diff --git a/teal-src/util/pposix.d.tl b/teal-src/util/pposix.d.tl
new file mode 100644
index 00000000..12091aa6
--- /dev/null
+++ b/teal-src/util/pposix.d.tl
@@ -0,0 +1,106 @@
+local record pposix
+ enum syslog_facility
+ "auth"
+ "authpriv"
+ "cron"
+ "daemon"
+ "ftp"
+ "kern"
+ "local0"
+ "local1"
+ "local2"
+ "local3"
+ "local4"
+ "local5"
+ "local6"
+ "local7"
+ "lpr"
+ "mail"
+ "syslog"
+ "user"
+ "uucp"
+ end
+
+ enum syslog_level
+ "debug"
+ "info"
+ "notice"
+ "warn"
+ "error"
+ end
+
+ enum ulimit_resource
+ "CORE"
+ "CPU"
+ "DATA"
+ "FSIZE"
+ "NOFILE"
+ "STACK"
+ "MEMLOCK"
+ "NPROC"
+ "RSS"
+ "NICE"
+ end
+
+ enum ulimit_unlimited
+ "unlimited"
+ end
+
+ type ulimit_limit = number | ulimit_unlimited
+
+ record utsname
+ sysname : string
+ nodename : string
+ release : string
+ version : string
+ machine : string
+ domainname : string
+ end
+
+ record memoryinfo
+ allocated : number
+ allocated_mmap : number
+ used : number
+ unused : number
+ returnable : number
+ end
+
+ abort : function ()
+
+ daemonize : function () : boolean, string
+
+ syslog_open : function (ident : string, facility : syslog_facility)
+ syslog_close : function ()
+ syslog_log : function (level : syslog_level, src : string, msg : string)
+ syslog_setminlevel : function (level : syslog_level)
+
+ getpid : function () : number
+ getuid : function () : number
+ getgid : function () : number
+
+ setuid : function (uid : string) : boolean, string -- string|number
+ setgid : function (uid : string) : boolean, string
+ initgroups : function (user : string, gid : number) : boolean, string
+
+ umask : function (umask : string) : string
+
+ mkdir : function (dir : string) : boolean, string
+
+ setrlimit : function (resource : ulimit_resource, soft : ulimit_limit, hard : ulimit_limit) : boolean, string
+ getrlimit : function (resource : ulimit_resource) : boolean, ulimit_limit, ulimit_limit
+ getrlimit : function (resource : ulimit_resource) : boolean, string
+
+ uname : function () : utsname
+
+ setenv : function (key : string, value : string) : boolean
+
+ meminfo : function () : memoryinfo
+
+ atomic_append : function (f : FILE, s : string) : boolean, string, number
+
+ ENOENT : number
+ _NAME : string
+ _VESRION : string
+end
+
+return pposix
diff --git a/teal-src/util/random.d.tl b/teal-src/util/random.d.tl
new file mode 100644
index 00000000..6f64f2e5
--- /dev/null
+++ b/teal-src/util/random.d.tl
@@ -0,0 +1,4 @@
+local record lib
+ bytes : function (n:number):string
+end
+return lib
diff --git a/teal-src/util/stanza.d.tl b/teal-src/util/stanza.d.tl
new file mode 100644
index 00000000..8a077087
--- /dev/null
+++ b/teal-src/util/stanza.d.tl
@@ -0,0 +1,61 @@
+local record lib
+
+ type children_iter = function ( stanza_t ) : stanza_t
+ type childtags_iter = function () : stanza_t
+ type maptags_cb = function ( stanza_t ) : stanza_t
+
+ record stanza_t
+ name : string
+ attr : { string : string }
+ { stanza_t | string }
+ tags : { stanza_t }
+
+ query : function ( stanza_t, string ) : stanza_t
+ body : function ( stanza_t, string, { string : string } ) : stanza_t
+ text_tag : function ( stanza_t, string, string, { string : string } ) : stanza_t
+ tag : function ( stanza_t, string, { string : string } ) : stanza_t
+ text : function ( stanza_t, string ) : stanza_t
+ up : function ( stanza_t ) : stanza_t
+ reset : function ( stanza_t ) : stanza_t
+ add_direct_child : function ( stanza_t, stanza_t )
+ add_child : function ( stanza_t, stanza_t )
+ remove_children : function ( stanza_t, string, string ) : stanza_t
+
+ get_child : function ( stanza_t, string, string ) : stanza_t
+ get_text : function ( stanza_t ) : string
+ get_child_text : function ( stanza_t, string, string ) : string
+ child_with_name : function ( stanza_t, string, string ) : stanza_t
+ child_with_ns : function ( stanza_t, string, string ) : stanza_t
+ children : function ( stanza_t ) : children_iter, stanza_t, number
+ childtags : function ( stanza_t, string, string ) : childtags_iter
+ maptags : function ( stanza_t, maptags_cb ) : stanza_t
+ find : function ( stanza_t, string ) : stanza_t | string
+
+ top_tag : function ( stanza_t ) : string
+ pretty_print : function ( stanza_t ) : string
+ pretty_top_tag : function ( stanza_t ) : string
+
+ get_error : function ( stanza_t ) : string, string, string, stanza_t
+ indent : function ( stanza_t, number, string ) : stanza_t
+ end
+
+ record serialized_stanza_t
+ name : string
+ attr : { string : string }
+ { serialized_stanza_t | string }
+ end
+
+ stanza : function ( string, { string : string } ) : stanza_t
+ is_stanza : function ( any ) : boolean
+ preserialize : function ( stanza_t ) : serialized_stanza_t
+ deserialize : function ( serialized_stanza_t ) : stanza_t
+ clone : function ( stanza_t, boolean ) : stanza_t
+ message : function ( { string : string }, string ) : stanza_t
+ iq : function ( { string : string } ) : stanza_t
+ reply : function ( stanza_t ) : stanza_t
+ error_reply : function ( stanza_t, string, string, string, string )
+ presence : function ( { string : string } ) : stanza_t
+ xml_escape : function ( string ) : string
+end
+
+return lib
diff --git a/teal-src/util/strbitop.d.tl b/teal-src/util/strbitop.d.tl
new file mode 100644
index 00000000..010efdb8
--- /dev/null
+++ b/teal-src/util/strbitop.d.tl
@@ -0,0 +1,6 @@
+local record mod
+ sand : function (string, string) : string
+ sor : function (string, string) : string
+ sxor : function (string, string) : string
+end
+return mod
diff --git a/teal-src/util/table.d.tl b/teal-src/util/table.d.tl
new file mode 100644
index 00000000..6f8c7e4a
--- /dev/null
+++ b/teal-src/util/table.d.tl
@@ -0,0 +1,6 @@
+local record lib
+ create : function (narr:number, nrec:number):table
+ pack : function (...:any):{any}
+end
+return lib
+
diff --git a/teal-src/util/time.d.tl b/teal-src/util/time.d.tl
new file mode 100644
index 00000000..e159706b
--- /dev/null
+++ b/teal-src/util/time.d.tl
@@ -0,0 +1,6 @@
+
+local record lib
+ now : function () : number
+ monotonic : function () : number
+end
+return lib
diff --git a/teal-src/util/uuid.d.tl b/teal-src/util/uuid.d.tl
new file mode 100644
index 00000000..17bb0590
--- /dev/null
+++ b/teal-src/util/uuid.d.tl
@@ -0,0 +1,5 @@
+local record lib
+ generate : function (number) : string
+end
+return lib
+