Software /
code /
prosody
Comparison
util/pubsub.lua @ 10411:db2a06b9ff98
Merge 0.11->trunk
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 16 Nov 2019 16:52:31 +0100 |
parent | 10356:0a2d7efca039 |
child | 10521:cbb2c3f8bb1d |
comparison
equal
deleted
inserted
replaced
10410:659b577f280c | 10411:db2a06b9ff98 |
---|---|
1 local events = require "util.events"; | 1 local events = require "util.events"; |
2 local cache = require "util.cache"; | 2 local cache = require "util.cache"; |
3 local errors = require "util.error"; | |
3 | 4 |
4 local service_mt = {}; | 5 local service_mt = {}; |
5 | 6 |
6 local default_config = { | 7 local default_config = { |
7 itemstore = function (config, _) return cache.new(config["max_items"]) end; | 8 itemstore = function (config, _) return cache.new(config["max_items"]) end; |
508 if not (node_config and required_config) then | 509 if not (node_config and required_config) then |
509 return false; | 510 return false; |
510 end | 511 end |
511 for config_field, value in pairs(required_config) do | 512 for config_field, value in pairs(required_config) do |
512 if node_config[config_field] ~= value then | 513 if node_config[config_field] ~= value then |
513 return false; | 514 return false, config_field; |
514 end | 515 end |
515 end | 516 end |
516 return true; | 517 return true; |
517 end | 518 end |
518 | 519 |
544 return ok, err; | 545 return ok, err; |
545 end | 546 end |
546 node_obj = self.nodes[node]; | 547 node_obj = self.nodes[node]; |
547 elseif requested_config and not requested_config._defaults_only then | 548 elseif requested_config and not requested_config._defaults_only then |
548 -- Check that node has the requested config before we publish | 549 -- Check that node has the requested config before we publish |
549 if not check_preconditions(node_obj.config, requested_config) then | 550 local ok, field = check_preconditions(node_obj.config, requested_config); |
550 return false, "precondition-not-met"; | 551 if not ok then |
552 local err = errors.new({ | |
553 type = "cancel", condition = "conflict", text = "Field does not match: "..field; | |
554 }); | |
555 err.pubsub_condition = "precondition-not-met"; | |
556 return false, err; | |
551 end | 557 end |
552 end | 558 end |
553 if not self.config.itemcheck(item) then | 559 if not self.config.itemcheck(item) then |
554 return nil, "invalid-item"; | 560 return nil, "invalid-item"; |
555 end | 561 end |