Annotate

plugins/mod_turn_external.lua @ 11640:51598e46e136

util.stanza: Simplify and make pretty-printing look nicer I've had this color theme in a local debug module for some time and I quite like it. The colors are from the XMPP logo. Removes extra XML serialization implementation in favor of the standard one. Also removes recursive str=str..more string building. The new two-level gsub has the accumulator in C space so shouldn't be too bad. The inner gsub calls use no callback, so should be fast and not create all that much garbage. No serious benchmarking has been done, but who cares if it looks nice?
author Kim Alvefur <zash@zash.se>
date Sat, 07 Nov 2020 22:09:46 +0100
parent 11599:ed405b6357a8
child 12282:fe5a87b5972f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11599
ed405b6357a8 mod_turn_external: Simple module to offer TURN(+STUN) via mod_external_services
Kim Alvefur <zash@zash.se>
parents:
diff changeset
1 local secret = module:get_option_string("turn_external_secret");
ed405b6357a8 mod_turn_external: Simple module to offer TURN(+STUN) via mod_external_services
Kim Alvefur <zash@zash.se>
parents:
diff changeset
2 local host = module:get_option_string("turn_external_host", module.host);
ed405b6357a8 mod_turn_external: Simple module to offer TURN(+STUN) via mod_external_services
Kim Alvefur <zash@zash.se>
parents:
diff changeset
3 local user = module:get_option_string("turn_external_user");
ed405b6357a8 mod_turn_external: Simple module to offer TURN(+STUN) via mod_external_services
Kim Alvefur <zash@zash.se>
parents:
diff changeset
4 local port = module:get_option_number("turn_external_port", 3478);
ed405b6357a8 mod_turn_external: Simple module to offer TURN(+STUN) via mod_external_services
Kim Alvefur <zash@zash.se>
parents:
diff changeset
5 local ttl = module:get_option_number("turn_external_ttl", 86400);
ed405b6357a8 mod_turn_external: Simple module to offer TURN(+STUN) via mod_external_services
Kim Alvefur <zash@zash.se>
parents:
diff changeset
6
ed405b6357a8 mod_turn_external: Simple module to offer TURN(+STUN) via mod_external_services
Kim Alvefur <zash@zash.se>
parents:
diff changeset
7 local services = module:get_option_set("turn_external_services", {"stun-udp"; "turn-udp"});
ed405b6357a8 mod_turn_external: Simple module to offer TURN(+STUN) via mod_external_services
Kim Alvefur <zash@zash.se>
parents:
diff changeset
8
ed405b6357a8 mod_turn_external: Simple module to offer TURN(+STUN) via mod_external_services
Kim Alvefur <zash@zash.se>
parents:
diff changeset
9 if not secret then error("mod_" .. module.name .. " requires that 'turn_external_secret' be set") end
ed405b6357a8 mod_turn_external: Simple module to offer TURN(+STUN) via mod_external_services
Kim Alvefur <zash@zash.se>
parents:
diff changeset
10
ed405b6357a8 mod_turn_external: Simple module to offer TURN(+STUN) via mod_external_services
Kim Alvefur <zash@zash.se>
parents:
diff changeset
11 module:depends "external_services";
ed405b6357a8 mod_turn_external: Simple module to offer TURN(+STUN) via mod_external_services
Kim Alvefur <zash@zash.se>
parents:
diff changeset
12
ed405b6357a8 mod_turn_external: Simple module to offer TURN(+STUN) via mod_external_services
Kim Alvefur <zash@zash.se>
parents:
diff changeset
13 for _, type in ipairs({"stun"; "turn"}) do
ed405b6357a8 mod_turn_external: Simple module to offer TURN(+STUN) via mod_external_services
Kim Alvefur <zash@zash.se>
parents:
diff changeset
14 for _, transport in ipairs({"udp"; "tcp"}) do
ed405b6357a8 mod_turn_external: Simple module to offer TURN(+STUN) via mod_external_services
Kim Alvefur <zash@zash.se>
parents:
diff changeset
15 if services:contains(type .. "-" .. transport) then
ed405b6357a8 mod_turn_external: Simple module to offer TURN(+STUN) via mod_external_services
Kim Alvefur <zash@zash.se>
parents:
diff changeset
16 module:add_item("external_service", {
ed405b6357a8 mod_turn_external: Simple module to offer TURN(+STUN) via mod_external_services
Kim Alvefur <zash@zash.se>
parents:
diff changeset
17 type = type;
ed405b6357a8 mod_turn_external: Simple module to offer TURN(+STUN) via mod_external_services
Kim Alvefur <zash@zash.se>
parents:
diff changeset
18 transport = transport;
ed405b6357a8 mod_turn_external: Simple module to offer TURN(+STUN) via mod_external_services
Kim Alvefur <zash@zash.se>
parents:
diff changeset
19 host = host;
ed405b6357a8 mod_turn_external: Simple module to offer TURN(+STUN) via mod_external_services
Kim Alvefur <zash@zash.se>
parents:
diff changeset
20 port = port;
ed405b6357a8 mod_turn_external: Simple module to offer TURN(+STUN) via mod_external_services
Kim Alvefur <zash@zash.se>
parents:
diff changeset
21
ed405b6357a8 mod_turn_external: Simple module to offer TURN(+STUN) via mod_external_services
Kim Alvefur <zash@zash.se>
parents:
diff changeset
22 username = type == "turn" and user or nil;
ed405b6357a8 mod_turn_external: Simple module to offer TURN(+STUN) via mod_external_services
Kim Alvefur <zash@zash.se>
parents:
diff changeset
23 secret = type == "turn" and secret or nil;
ed405b6357a8 mod_turn_external: Simple module to offer TURN(+STUN) via mod_external_services
Kim Alvefur <zash@zash.se>
parents:
diff changeset
24 ttl = type == "turn" and ttl or nil;
ed405b6357a8 mod_turn_external: Simple module to offer TURN(+STUN) via mod_external_services
Kim Alvefur <zash@zash.se>
parents:
diff changeset
25 })
ed405b6357a8 mod_turn_external: Simple module to offer TURN(+STUN) via mod_external_services
Kim Alvefur <zash@zash.se>
parents:
diff changeset
26 end
ed405b6357a8 mod_turn_external: Simple module to offer TURN(+STUN) via mod_external_services
Kim Alvefur <zash@zash.se>
parents:
diff changeset
27 end
ed405b6357a8 mod_turn_external: Simple module to offer TURN(+STUN) via mod_external_services
Kim Alvefur <zash@zash.se>
parents:
diff changeset
28 end