Software /
code /
prosody
Annotate
net/resolvers/chain.lua @ 13011:16b47c3b44f3
mod_invites_register: Allow roles to be an ordered list, first being primary
Part of an update to mod_invites and friends to the new authz and roles.
Invites with roles in the old way will need to be migrated, but with
invites often being short lived it is probably not a long-lived problem.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Thu, 30 Mar 2023 11:05:40 +0200 |
parent | 12204:7c397a49d163 |
rev | line source |
---|---|
12204
7c397a49d163
net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
1 |
7c397a49d163
net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
2 local methods = {}; |
7c397a49d163
net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
3 local resolver_mt = { __index = methods }; |
7c397a49d163
net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
4 |
7c397a49d163
net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
5 -- Find the next target to connect to, and |
7c397a49d163
net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
6 -- pass it to cb() |
7c397a49d163
net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
7 function methods:next(cb) |
7c397a49d163
net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
8 if self.resolvers then |
7c397a49d163
net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
9 if not self.resolver then |
7c397a49d163
net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
10 if #self.resolvers == 0 then |
7c397a49d163
net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
11 cb(nil); |
7c397a49d163
net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
12 return; |
7c397a49d163
net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
13 end |
7c397a49d163
net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
14 local next_resolver = table.remove(self.resolvers, 1); |
7c397a49d163
net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
15 self.resolver = next_resolver; |
7c397a49d163
net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
16 end |
7c397a49d163
net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
17 self.resolver:next(function (...) |
7c397a49d163
net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
18 if self.resolver then |
7c397a49d163
net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
19 self.last_error = self.resolver.last_error; |
7c397a49d163
net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
20 end |
7c397a49d163
net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
21 if ... == nil then |
7c397a49d163
net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
22 self.resolver = nil; |
7c397a49d163
net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
23 self:next(cb); |
7c397a49d163
net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
24 else |
7c397a49d163
net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
25 cb(...); |
7c397a49d163
net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
26 end |
7c397a49d163
net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
27 end); |
7c397a49d163
net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
28 return; |
7c397a49d163
net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
29 end |
7c397a49d163
net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
30 end |
7c397a49d163
net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
31 |
7c397a49d163
net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
32 local function new(resolvers) |
7c397a49d163
net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
33 return setmetatable({ resolvers = resolvers }, resolver_mt); |
7c397a49d163
net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
34 end |
7c397a49d163
net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
35 |
7c397a49d163
net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
36 return { |
7c397a49d163
net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
37 new = new; |
7c397a49d163
net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
38 }; |