Software /
code /
prosody
Changeset
13872:76582d10bc09 default tip
Merge 13.0->trunk
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Mon, 05 May 2025 17:30:06 +0200 |
parents | 13866:7f6916088278 (diff) 13871:9eee04a95a25 (current diff) |
children | |
files | teal-src/prosody/util/jsonschema.tl util/jsonschema.lua |
diffstat | 10 files changed, 83 insertions(+), 81 deletions(-) [+] |
line wrap: on
line diff
--- a/teal-src/prosody/util/array.d.tl Mon May 05 16:32:45 2025 +0200 +++ b/teal-src/prosody/util/array.d.tl Mon May 05 17:30:06 2025 +0200 @@ -1,9 +1,10 @@ -local record array_t<T> - { T } +local record array_t<T> is { T } + -- TODO methods end local record lib metamethod __call : function () : array_t + -- TODO library functions end return lib
--- a/teal-src/prosody/util/crypto.d.tl Mon May 05 16:32:45 2025 +0200 +++ b/teal-src/prosody/util/crypto.d.tl Mon May 05 17:30:06 2025 +0200 @@ -2,7 +2,9 @@ record key private_pem : function (key) : string public_pem : function (key) : string + public_raw : function (key) : string get_type : function (key) : string + derive : function (key, key) : string end type base_evp_sign = function (key, message : string) : string @@ -44,9 +46,11 @@ aes_256_ctr_decrypt : Levp_decrypt generate_ed25519_keypair : function () : key + generate_p256_keypair : function () : key import_private_pem : function (string) : key import_public_pem : function (string) : key + import_public_ec_raw : function (string, string) : key parse_ecdsa_signature : function (string, integer) : string, string build_ecdsa_signature : function (r : string, s : string) : string
--- a/teal-src/prosody/util/dataforms.d.tl Mon May 05 16:32:45 2025 +0200 +++ b/teal-src/prosody/util/dataforms.d.tl Mon May 05 17:30:06 2025 +0200 @@ -5,7 +5,7 @@ title : string instructions : string - record form_field + record form_field is { form_field } enum field_type "boolean" @@ -35,7 +35,6 @@ options : table end - { form_field } enum form_type "form"
--- a/teal-src/prosody/util/jsonschema.tl Mon May 05 16:32:45 2025 +0200 +++ b/teal-src/prosody/util/jsonschema.tl Mon May 05 17:30:06 2025 +0200 @@ -10,12 +10,8 @@ if not math.type then require "prosody.util.mathcompat" end - -local utf8_enc = rawget(_G, "utf8") or require"prosody.util.encodings".utf8; -local utf8_len = utf8_enc.len or function(s : string) : integer - local _, count = s:gsub("[%z\001-\127\194-\253][\128-\191]*", ""); - return count; -end; +-- XXX util.encodings seems to count differently from the Lua builtin +local utf8_len = rawget(_G, "utf8") and utf8.len or require"prosody.util.encodings".utf8.length; local json = require "prosody.util.json" local null = json.null; @@ -166,7 +162,7 @@ end local type errors = { validation_error } local function mkerr(sloc:string,iloc:string,err:string) : validation_error - return { schemaLocation = sloc; instanceLocation = iloc; error = err }; + return { schemaLocation = sloc; instanceLocation = iloc; error = err } end local function validate (schema : schema_t, data : any, root : json_schema_object, sloc : string, iloc : string, errs:errors) : boolean, errors @@ -186,14 +182,14 @@ if referenced ~= nil and referenced ~= root and referenced ~= schema then if not validate(referenced, data, root, schema["$ref"], iloc, errs) then table.insert(errs, mkerr(sloc.."/$ref", iloc, "Subschema failed validation")) - return false, errs; + return false, errs end end end if not simple_validate(schema.type, data) then table.insert(errs, mkerr(sloc.."/type", iloc, "unexpected type")); - return false, errs; + return false, errs end if schema.type == "object" then @@ -202,7 +198,7 @@ for k in pairs(data) do if not k is string then table.insert(errs, mkerr(sloc.."/type", iloc, "'object' had non-string keys")); - return false, errs; + return false, errs end end end @@ -214,7 +210,7 @@ for i in pairs(data) do if not i is integer then table.insert(errs, mkerr(sloc.."/type", iloc, "'array' had non-integer keys")); - return false, errs; + return false, errs end end end @@ -231,7 +227,7 @@ end if not match then table.insert(errs, mkerr(sloc.."/enum", iloc, "not one of the enumerated values")); - return false, errs; + return false, errs end end @@ -240,42 +236,42 @@ if data is string then if schema.maxLength and utf8_len(data) > schema.maxLength then table.insert(errs, mkerr(sloc.."/maxLength", iloc, "string too long")) - return false, errs; + return false, errs end if schema.minLength and utf8_len(data) < schema.minLength then table.insert(errs, mkerr(sloc.."/maxLength", iloc, "string too short")) - return false, errs; + return false, errs end if schema.luaPattern and not data:match(schema.luaPattern) then table.insert(errs, mkerr(sloc.."/luaPattern", iloc, "string does not match pattern")) - return false, errs; + return false, errs end end if data is number then if schema.multipleOf and (data == 0 or data % schema.multipleOf ~= 0) then table.insert(errs, mkerr(sloc.."/luaPattern", iloc, "not a multiple")) - return false, errs; + return false, errs end if schema.maximum and not ( data <= schema.maximum ) then table.insert(errs, mkerr(sloc.."/maximum", iloc, "number exceeds maximum")) - return false, errs; + return false, errs end if schema.exclusiveMaximum and not ( data < schema.exclusiveMaximum ) then table.insert(errs, mkerr(sloc.."/exclusiveMaximum", iloc, "number exceeds exclusive maximum")) - return false, errs; + return false, errs end if schema.minimum and not ( data >= schema.minimum ) then table.insert(errs, mkerr(sloc.."/minimum", iloc, "number below minimum")) - return false, errs; + return false, errs end if schema.exclusiveMinimum and not ( data > schema.exclusiveMinimum ) then table.insert(errs, mkerr(sloc.."/exclusiveMinimum", iloc, "number below exclusive minimum")) - return false, errs; + return false, errs end end @@ -283,7 +279,7 @@ for i, sub in ipairs(schema.allOf) do if not validate(sub, data, root, sloc.."/allOf/"..i, iloc, errs) then table.insert(errs, mkerr(sloc.."/allOf", iloc, "did not match all subschemas")) - return false, errs; + return false, errs end end end @@ -297,7 +293,7 @@ end if valid ~= 1 then table.insert(errs, mkerr(sloc.."/oneOf", iloc, "did not match exactly one subschema")) - return false, errs; + return false, errs end end @@ -311,14 +307,14 @@ end if not match then table.insert(errs, mkerr(sloc.."/anyOf", iloc, "did not match any subschema")) - return false, errs; + return false, errs end end if schema["not"] ~= nil then if validate(schema["not"], data, root, sloc.."/not", iloc, errs) then table.insert(errs, mkerr(sloc.."/not", iloc, "did match subschema")) - return false, errs; + return false, errs end end @@ -327,14 +323,14 @@ if schema["then"] ~= nil then if not validate(schema["then"], data, root, sloc.."/then", iloc, errs) then table.insert(errs, mkerr(sloc.."/then", iloc, "did not match subschema")) - return false, errs; + return false, errs end end else if schema["else"] ~= nil then if not validate(schema["else"], data, root, sloc.."/else", iloc, errs) then table.insert(errs, mkerr(sloc.."/else", iloc, "did not match subschema")) - return false, errs; + return false, errs end end end @@ -342,7 +338,7 @@ if schema.const ~= nil and schema.const ~= data then table.insert(errs, mkerr(sloc.."/const", iloc, "did not match constant value")) - return false, errs; + return false, errs end if data is table then @@ -352,19 +348,19 @@ if schema.maxItems and #(data as {any}) > schema.maxItems then table.insert(errs, mkerr(sloc.."/maxItems", iloc, "too many items")) - return false, errs; + return false, errs end if schema.minItems and #(data as {any}) < schema.minItems then table.insert(errs, mkerr(sloc.."/minItems", iloc, "too few items")) - return false, errs; + return false, errs end if schema.required then for _, k in ipairs(schema.required) do if data[k] == nil then table.insert(errs, mkerr(sloc.."/required", iloc.."/"..tostring(k), "missing required property")) - return false, errs; + return false, errs end end end @@ -375,7 +371,7 @@ for _, req in ipairs(reqs) do if data[req] == nil then table.insert(errs, mkerr(sloc.."/dependentRequired", iloc, "missing dependent required property")) - return false, errs; + return false, errs end end end @@ -387,7 +383,7 @@ for k in pairs(data) do if not validate(schema.propertyNames, k, root, sloc.."/propertyNames", iloc.."/"..tostring(k), errs) then table.insert(errs, mkerr(sloc.."/propertyNames", iloc.."/"..tostring(k), "a property name did not match subschema")) - return false, errs; + return false, errs end end end @@ -401,7 +397,7 @@ for k, sub in pairs(schema.properties) do if data[k] ~= nil and not validate(sub, data[k], root, sloc.."/"..tostring(k), iloc.."/"..tostring(k), errs) then table.insert(errs, mkerr(sloc.."/"..tostring(k), iloc.."/"..tostring(k), "a property did not match subschema")) - return false, errs; + return false, errs end seen_properties[k] = true end @@ -414,7 +410,7 @@ if k is string and k:match(pattern) then if not validate(sub, data[k], root, sloc.."/luaPatternProperties", iloc, errs) then table.insert(errs, mkerr(sloc.."/luaPatternProperties/"..pattern, iloc.."/"..tostring(k), "a property did not match subschema")) - return false, errs; + return false, errs end seen_properties[k] = true end @@ -427,7 +423,7 @@ if not seen_properties[k as string] then if not validate(schema.additionalProperties, v, root, sloc.."/additionalProperties", iloc.."/"..tostring(k), errs) then table.insert(errs, mkerr(sloc.."/additionalProperties", iloc.."/"..tostring(k), "additional property did not match subschema")) - return false, errs; + return false, errs end end end @@ -437,7 +433,7 @@ for k, sub in pairs(schema.dependentSchemas) do if data[k] ~= nil and not validate(sub, data, root, sloc.."/dependentSchemas/"..k, iloc, errs) then table.insert(errs, mkerr(sloc.."/dependentSchemas", iloc.."/"..tostring(k), "did not match dependent subschema")) - return false, errs; + return false, errs end end end @@ -448,7 +444,7 @@ for _, v in pairs(data) do if values[v] then table.insert(errs, mkerr(sloc.."/uniqueItems", iloc, "had duplicate items")) - return false, errs; + return false, errs end values[v] = true end @@ -463,7 +459,7 @@ p = i else table.insert(errs, mkerr(sloc.."/prefixItems/"..i, iloc.."/"..tostring(i), "did not match subschema")) - return false, errs; + return false, errs end end end @@ -472,7 +468,7 @@ for i = p+1, #(data as {any}) do if not validate(schema.items, data[i], root, sloc, iloc.."/"..i, errs) then table.insert(errs, mkerr(sloc.."/prefixItems/"..i, iloc.."/"..i, "did not match subschema")) - return false, errs; + return false, errs end end end @@ -488,18 +484,18 @@ end if found < (schema.minContains or 1) then table.insert(errs, mkerr(sloc.."/minContains", iloc, "too few matches")) - return false, errs; + return false, errs elseif found > (schema.maxContains or math.huge) then table.insert(errs, mkerr(sloc.."/maxContains", iloc, "too many matches")) - return false, errs; + return false, errs end end end - return true; + return true end json_schema_object.validate = validate; -return json_schema_object; +return json_schema_object
--- a/teal-src/prosody/util/pposix.d.tl Mon May 05 16:32:45 2025 +0200 +++ b/teal-src/prosody/util/pposix.d.tl Mon May 05 17:30:06 2025 +0200 @@ -86,6 +86,14 @@ mkdir : function (dir : string) : boolean, string + enum pipe_flag_names + "cloexec" + "direct" + "nonblock" + end + pipe : function (... : pipe_flag_names) : integer, integer + fdopen : function (integer, string) : FILE, 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 @@ -103,7 +111,7 @@ ENOENT : integer _NAME : string - _VESRION : string + _VERSION : string end return pposix
--- a/teal-src/prosody/util/set.d.tl Mon May 05 16:32:45 2025 +0200 +++ b/teal-src/prosody/util/set.d.tl Mon May 05 17:30:06 2025 +0200 @@ -1,22 +1,22 @@ local record lib record Set<T> - add : function<T> (Set<T>, T) - contains : function<T> (Set<T>, T) : boolean - contains_set : function<T> (Set<T>, Set<T>) : boolean - items : function<T> (Set<T>) : function<T> (Set<T>, T) : T - remove : function<T> (Set<T>, T) - add_list : function<T> (Set<T>, { T }) - include : function<T> (Set<T>, Set<T>) - exclude : function<T> (Set<T>, Set<T>) - empty : function<T> (Set<T>) : boolean + add : function (Set, T) + contains : function (Set, T) : boolean + contains_set : function (Set, Set) : boolean + items : function (Set) : function (Set, T) : T + remove : function (Set, T) + add_list : function (Set, { T }) + include : function (Set, Set) + exclude : function (Set, Set) + empty : function (Set) : boolean end new : function<T> ({ T }) : Set<T> is_set : function (any) : boolean - union : function<T> (Set<T>, Set<T>) : Set <T> - difference : function<T> (Set<T>, Set<T>) : Set <T> - intersection : function<T> (Set<T>, Set<T>) : Set <T> - xor : function<T> (Set<T>, Set<T>) : Set <T> + union : function (Set, Set) : Set + difference : function (Set, Set) : Set + intersection : function (Set, Set) : Set + xor : function (Set, Set) : Set end return lib
--- a/teal-src/prosody/util/signal.d.tl Mon May 05 16:32:45 2025 +0200 +++ b/teal-src/prosody/util/signal.d.tl Mon May 05 17:30:06 2025 +0200 @@ -36,6 +36,7 @@ signal : function (integer | Signal, function, boolean) : boolean raise : function (integer | Signal) kill : function (integer, integer | Signal) + signalfd : function (integer) : FILE -- enum : integer end return lib
--- a/teal-src/prosody/util/smqueue.tl Mon May 05 16:32:45 2025 +0200 +++ b/teal-src/prosody/util/smqueue.tl Mon May 05 17:30:06 2025 +0200 @@ -12,12 +12,11 @@ "head" "pop" end - push : function (smqueue, T) - ack : function (smqueue, integer) : { T }, ack_errors + push : function (smqueue<T>, T) + ack : function (smqueue<T>, integer) : { T }, ack_errors resumable : function (smqueue<T>) : boolean resume : function (smqueue<T>) : queue.queue.iterator, any, integer - type consume_iter = function (smqueue<T>) : T - consume : function (smqueue<T>) : consume_iter + consume : function (smqueue<T>) : function() : T table : function (smqueue<T>) : { T } end @@ -26,13 +25,13 @@ local type smqueue = lib.smqueue; -function smqueue:push(v) +function smqueue:push(v : T) self._head = self._head + 1; -- Wraps instead of errors assert(self._queue:push(v)); end -function smqueue:ack(h : integer) : { any }, smqueue.ack_errors +function smqueue:ack(h : integer) : { T }, smqueue.ack_errors if h < self._tail then return nil, "tail"; elseif h > self._head then @@ -66,13 +65,13 @@ return self._queue:items(); end -function smqueue:consume() : queue.queue.consume_iter - return self._queue:consume() +function smqueue:consume() : (function() : T) + return self._queue:consume() as (function() : T) end -- Compatibility layer, plain ol' table -function smqueue:table() : { any } - local t : { any } = {}; +function smqueue:table() : { T } + local t : { T } = {}; for i, v in self:resume() do t[i] = v; end @@ -91,7 +90,7 @@ __freeze = freeze; } -function lib.new<T>(size : integer) : queue.queue<T> +function lib.new<T>(size : integer) : smqueue<T> assert(size>0); return setmetatable({ _head = 0; _tail = 0; _queue = queue.new(size, true) }, queue_mt); end
--- a/teal-src/prosody/util/stanza.d.tl Mon May 05 16:32:45 2025 +0200 +++ b/teal-src/prosody/util/stanza.d.tl Mon May 05 17:30:06 2025 +0200 @@ -37,10 +37,9 @@ "unexpected-request" end - record stanza_t + record stanza_t is { stanza_t | string } name : string attr : { string : string } - { stanza_t | string } tags : { stanza_t } query : function ( stanza_t, string ) : stanza_t @@ -77,10 +76,9 @@ indent : function ( stanza_t, integer, string ) : stanza_t end - record serialized_stanza_t + record serialized_stanza_t is { serialized_stanza_t | string } name : string attr : { string : string } - { serialized_stanza_t | string } end record message_attr
--- a/util/jsonschema.lua Mon May 05 16:32:45 2025 +0200 +++ b/util/jsonschema.lua Mon May 05 17:30:06 2025 +0200 @@ -4,11 +4,7 @@ require("prosody.util.mathcompat") end -local utf8_enc = rawget(_G, "utf8") or require("prosody.util.encodings").utf8; -local utf8_len = utf8_enc.len or function(s) - local _, count = s:gsub("[%z\001-\127\194-\253][\128-\191]*", ""); - return count -end; +local utf8_len = rawget(_G, "utf8") and utf8.len or require("prosody.util.encodings").utf8.length; local json = require("prosody.util.json") local null = json.null;