mod_pubsub_hub/mod_pubsub_hub.lua
author Kim Alvefur <zash@zash.se>
Fri, 28 Feb 2014 15:36:06 +0100
changeset 1324 853a382c9bd6
parent 801 133ee88d19ae
child 1325 b21236b6b8d8
permissions -rw-r--r--
mod_turncredentials: Advertise the XEP-0215 feature (thanks Gryffus)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
764
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
     1
-- Copyright (C) 2011 - 2012 Kim Alvefur
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
     2
--
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
     3
-- This file is MIT/X11 licensed.
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
     4
1324
853a382c9bd6 mod_turncredentials: Advertise the XEP-0215 feature (thanks Gryffus)
Kim Alvefur <zash@zash.se>
parents: 801
diff changeset
     5
local http_request, formdecode, formencode = import("net.http", "request", "formdecode", "formencode");
764
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
     6
local uuid = require "util.uuid".generate;
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
     7
local hmac_sha1 = require "util.hmac".sha1;
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
     8
local json_encode = require "util.json".encode;
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
     9
local time = os.time;
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    10
local m_min, m_max = math.min, math.max;
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    11
local tostring = tostring;
1324
853a382c9bd6 mod_turncredentials: Advertise the XEP-0215 feature (thanks Gryffus)
Kim Alvefur <zash@zash.se>
parents: 801
diff changeset
    12
764
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    13
local xmlns_pubsub = "http://jabber.org/protocol/pubsub";
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    14
local xmlns_pubsub_event = xmlns_pubsub .. "#event";
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    15
local subs_by_topic = module:shared"subscriptions";
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    16
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    17
local max_lease, min_lease, default_lease = 86400, 600, 3600;
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    18
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    19
module:depends"pubsub";
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    20
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    21
local valid_modes = { ["subscribe"] = true, ["unsubscribe"] = true, }
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    22
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    23
local function do_subscribe(subscription)
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    24
	-- FIXME handle other states
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    25
	if subscription.state == "subscribed" then
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    26
		local ok, err = hosts[module.host].modules.pubsub.service:add_subscription(subscription.topic, true, module.host);
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    27
		module:log(ok and "debug" or "error", "add_subscription() => %s, %s", tostring(ok), tostring(err));
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    28
	end
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    29
end
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    30
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    31
local function handle_request(event)
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    32
	local request, response = event.request, event.response;
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    33
	local method, body = request.method, request.body;
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    34
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    35
	local query = request.url.query or {};
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    36
	if query and type(query) == "string" then
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    37
		query = formdecode(query);
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    38
	end
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    39
	if body and request.headers.content_type == "application/x-www-form-urlencoded" then
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    40
		body = formdecode(body);
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    41
	end
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    42
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    43
	if method == "POST" then
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    44
		-- Subscription request
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    45
		if body["hub.callback"] and body["hub.mode"] and valid_modes[body["hub.mode"]]
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    46
			and body["hub.topic"] and body["hub.verify"] then
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    47
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    48
			-- http://pubsubhubbub.googlecode.com/svn/trunk/pubsubhubbub-core-0.3.html#anchor5
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    49
			local callback = body["hub.callback"];
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    50
			local mode = body["hub.mode"];
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    51
			local topic = body["hub.topic"];
767
e5667f1da6bf mod_pubsub_hub: Enforce minimal lease time
Kim Alvefur <zash@zash.se>
parents: 766
diff changeset
    52
			local lease_seconds = m_max(min_lease, m_min(tonumber(body["hub.lease_seconds"]) or default_lease, max_lease));
764
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    53
			local secret = body["hub.secret"];
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    54
			local verify_token = body["hub.verify_token"];
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    55
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    56
			module:log("debug", "topic is "..(type(topic)=="string" and "%q" or "%s"), topic);
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    57
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    58
			if not subs_by_topic[topic] then
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    59
				subs_by_topic[topic] = {};
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    60
			end
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    61
			local subscription = subs_by_topic[topic][callback];
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    62
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    63
			local verify_modes = {};
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    64
			for i=1,#body do
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    65
				if body[i].name == "hub.verify" then
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    66
					verify_modes[body[i].value] = true;
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    67
				end
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    68
			end
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    69
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    70
			subscription = subscription or {
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    71
				id = uuid(),
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    72
				callback = callback,
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    73
				topic = topic,
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    74
				state = "unsubscribed",
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    75
				secret = secret,
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    76
				want_state = mode,
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    77
				lease_seconds = lease_seconds,
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    78
				expires = time() + lease_seconds,
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    79
			};
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    80
			subs_by_topic[topic][callback] = subscription;
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    81
			local challenge = uuid();
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    82
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    83
			local callback_url = callback .. (callback:match("%?") and "&" or "?") .. formencode{
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    84
				["hub.mode"] = mode,
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    85
				["hub.topic"] = topic,
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    86
				["hub.challenge"] = challenge,
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    87
				["hub.lease_seconds"] = tostring(lease_seconds),
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    88
				["hub.verify_token"] = verify_token,
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    89
			}
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    90
			module:log("debug", require"util.serialization".serialize(verify_modes));
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    91
			if verify_modes["async"] then
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    92
				module:log("debug", "Sending async verification request to %s for %s", tostring(callback_url), tostring(subscription));
1324
853a382c9bd6 mod_turncredentials: Advertise the XEP-0215 feature (thanks Gryffus)
Kim Alvefur <zash@zash.se>
parents: 801
diff changeset
    93
				http_request(callback_url, nil, function(body, code)
764
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    94
					if body == challenge and code > 199 and code < 300 then
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    95
						if not subscription.want_state then
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    96
							module:log("warn", "Verification of already verified request, probably");
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    97
							return;
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    98
						end
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    99
						subscription.state = subscription.want_state .. "d";
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   100
						subscription.want_state = nil;
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   101
						module:log("debug", "calling do_subscribe()");
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   102
						do_subscribe(subscription);
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   103
						subs_by_topic[topic][callback] = subscription;
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   104
					else
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   105
						module:log("warn", "status %d and body was %q", tostring(code), tostring(body));
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   106
						subs_by_topic[topic][callback] = subscription;
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   107
					end
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   108
				end)
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   109
				return 202;
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   110
			elseif verify_modes["sync"] then
1324
853a382c9bd6 mod_turncredentials: Advertise the XEP-0215 feature (thanks Gryffus)
Kim Alvefur <zash@zash.se>
parents: 801
diff changeset
   111
				http_request(callback_url, nil, function(body, code)
764
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   112
					if body == challenge and code > 199 and code < 300 then
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   113
						if not subscription.want_state then
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   114
							module:log("warn", "Verification of already verified request, probably");
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   115
							return;
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   116
						end
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   117
						if mode == "unsubscribe" then
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   118
							subs_by_topic[topic][callback] = nil;
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   119
						else
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   120
							subscription.state = subscription.want_state .. "d";
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   121
							subscription.want_state = nil;
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   122
							module:log("debug", "calling do_subscribe()");
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   123
							do_subscribe(subscription);
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   124
							subs_by_topic[topic][callback] = subscription;
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   125
						end
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   126
					else
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   127
						subs_by_topic[topic][callback] = subscription;
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   128
					end
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   129
					response.status = 204;
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   130
					response:send();
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   131
				end)
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   132
				return true;
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   133
			end
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   134
			return 400;
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   135
		else
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   136
			response.status = 400;
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   137
			response.headers.content_type = "text/html";
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   138
			return "<h1>Bad Request</h1>\n<a href='http://pubsubhubbub.googlecode.com/svn/trunk/pubsubhubbub-core-0.3.html#anchor5'>Missing required parameter(s)</a>\n"
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   139
		end
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   140
	end
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   141
end
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   142
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   143
local function periodic()
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   144
	local now = time();
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   145
	local next_check = now + max_lease;
766
1184fe8ebb21 mod_pubsub_hub: Try to choose time until the next periodic check in a sane way
Kim Alvefur <zash@zash.se>
parents: 764
diff changeset
   146
	local purge = false;
764
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   147
	for topic, callbacks in pairs(subs_by_topic) do
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   148
		for callback, subscription in pairs(callbacks) do
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   149
			if subscription.mode == "subscribed" then
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   150
				if subscription.expires < now then
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   151
					-- Subscription has expired, drop it.
766
1184fe8ebb21 mod_pubsub_hub: Try to choose time until the next periodic check in a sane way
Kim Alvefur <zash@zash.se>
parents: 764
diff changeset
   152
					purge = true;
1184fe8ebb21 mod_pubsub_hub: Try to choose time until the next periodic check in a sane way
Kim Alvefur <zash@zash.se>
parents: 764
diff changeset
   153
				elseif subscription.expires < now + min_lease  then
764
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   154
					-- Subscription set to expire soon, re-confirm it.
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   155
					local challenge = uuid();
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   156
					local callback_url = callback .. (callback:match("%?") and "&" or "?") .. formencode{
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   157
						["hub.mode"] = subscription.state,
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   158
						["hub.topic"] = topic,
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   159
						["hub.challenge"] = challenge,
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   160
						["hub.lease_seconds"] = subscription.lease_seconds,
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   161
						["hub.verify_token"] = subscription.verify_token,
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   162
					}
1324
853a382c9bd6 mod_turncredentials: Advertise the XEP-0215 feature (thanks Gryffus)
Kim Alvefur <zash@zash.se>
parents: 801
diff changeset
   163
					http_request(callback_url, nil, function(body, code)
764
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   164
						if body == challenge and code > 199 and code < 300 then
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   165
							subscription.expires = now + subscription.lease_seconds;
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   166
						end
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   167
					end);
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   168
				else
766
1184fe8ebb21 mod_pubsub_hub: Try to choose time until the next periodic check in a sane way
Kim Alvefur <zash@zash.se>
parents: 764
diff changeset
   169
					next_check = m_min(next_check, subscription.expires);
764
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   170
				end
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   171
			end
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   172
		end
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   173
		if purge then
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   174
			local new_callbacks = {};
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   175
			for callback, subscription in pairs(callbacks) do
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   176
				if (subscription.state == "subscribed" and subscription.expires < now)
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   177
					and subscription.want_state ~= "remove" then
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   178
					new_callbacks[callback] = subscription;
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   179
				end
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   180
			end
766
1184fe8ebb21 mod_pubsub_hub: Try to choose time until the next periodic check in a sane way
Kim Alvefur <zash@zash.se>
parents: 764
diff changeset
   181
			subs_by_topic[topic] = new_callbacks;
1184fe8ebb21 mod_pubsub_hub: Try to choose time until the next periodic check in a sane way
Kim Alvefur <zash@zash.se>
parents: 764
diff changeset
   182
			purge = false;
764
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   183
		end
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   184
	end
785
e781e63a49f4 mod_pubsub_hub: Fix calculating next periodic check of subscriptions.
Kim Alvefur <zash@zash.se>
parents: 767
diff changeset
   185
	return m_max((now - next_check) - min_lease, min_lease);
764
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   186
end
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   187
801
133ee88d19ae mod_pubsub_hub: Add compat wrapping of Atom content for interop with PuSH
Kim Alvefur <zash@zash.se>
parents: 785
diff changeset
   188
local xmlns_atom = "http://www.w3.org/2005/Atom";
133ee88d19ae mod_pubsub_hub: Add compat wrapping of Atom content for interop with PuSH
Kim Alvefur <zash@zash.se>
parents: 785
diff changeset
   189
local st = require "util.stanza";
133ee88d19ae mod_pubsub_hub: Add compat wrapping of Atom content for interop with PuSH
Kim Alvefur <zash@zash.se>
parents: 785
diff changeset
   190
764
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   191
local function on_notify(subscription, content)
801
133ee88d19ae mod_pubsub_hub: Add compat wrapping of Atom content for interop with PuSH
Kim Alvefur <zash@zash.se>
parents: 785
diff changeset
   192
	if content.attr and content.attr.xmlns == xmlns_atom then
133ee88d19ae mod_pubsub_hub: Add compat wrapping of Atom content for interop with PuSH
Kim Alvefur <zash@zash.se>
parents: 785
diff changeset
   193
		-- COMPAT This is required by the PubSubHubbub spec.
133ee88d19ae mod_pubsub_hub: Add compat wrapping of Atom content for interop with PuSH
Kim Alvefur <zash@zash.se>
parents: 785
diff changeset
   194
		content = st.stanza("feed", {xmlns=xmlns_atom}):add_child(content);
133ee88d19ae mod_pubsub_hub: Add compat wrapping of Atom content for interop with PuSH
Kim Alvefur <zash@zash.se>
parents: 785
diff changeset
   195
	end
764
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   196
	local body = tostring(content);
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   197
	local headers = {
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   198
		["Content-Type"] = "application/xml",
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   199
	};
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   200
	if subscription.secret then
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   201
		headers["X-Hub-Signature"] = "sha1="..hmac_sha1(subscription.secret, body, true);
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   202
	end
1324
853a382c9bd6 mod_turncredentials: Advertise the XEP-0215 feature (thanks Gryffus)
Kim Alvefur <zash@zash.se>
parents: 801
diff changeset
   203
	http_request(subscription.callback, { method = "POST", body = body, headers = headers }, function(body, code)
764
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   204
		if code >= 200 and code <= 299 then
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   205
			module:log("debug", "Delivered");
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   206
		else
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   207
			module:log("warn", "Got status code %d on delivery to %s", tonumber(code) or -1, tostring(subscription.callback));
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   208
			-- TODO Retry
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   209
			-- ... but the spec says that you should not retry, wtf?
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   210
		end
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   211
	end);
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   212
end
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   213
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   214
module:hook("message/host", function(event)
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   215
	local stanza = event.stanza;
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   216
	if stanza.attr.from ~= module.host then return end;
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   217
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   218
	for pubsub_event in stanza:childtags("event", xmlns_pubsub_event) do
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   219
		local items = pubsub_event:get_child("items");
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   220
		local node = items.attr.node;
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   221
		if items and node and subs_by_topic[node] then
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   222
			for item in items:childtags("item") do
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   223
				local content = item.tags[1];
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   224
				for callback, subscription in pairs(subs_by_topic[node]) do
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   225
					on_notify(subscription, content)
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   226
				end
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   227
			end
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   228
		end
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   229
	end
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   230
	return true;
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   231
end, 10);
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   232
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   233
module:depends"http";
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   234
module:provides("http", {
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   235
	default_path = "/hub";
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   236
	route = {
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   237
		POST = handle_request;
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   238
		GET = function()
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   239
			return json_encode(subs_by_topic);
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   240
		end;
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   241
		["GET /topic/*"] = function(event, path)
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   242
			return json_encode(subs_by_topic[path])
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   243
		end;
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   244
	};
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   245
});
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   246
d11d91ee81ed mod_pubsub_hub: New module that implements the Hub part of PubSubHubbub
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   247
module:add_timer(1, periodic);