Mercurial > prosody-modules
annotate mod_pubsub_feed/mod_pubsub_feed.lua @ 324:100b3ad2e10c
mod_pubsub_feed: Fix verify_token checking.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Mon, 31 Jan 2011 23:32:25 +0100 |
parents | 433bf7dc3e7a |
children | 4e50e591a7fc |
rev | line source |
---|---|
278
653c1826739e
mod_pubsub_feed: Fetches Atom feeds and publishes to PubSub
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
1 -- Fetches Atom feeds and publishes to PubSub nodes |
653c1826739e
mod_pubsub_feed: Fetches Atom feeds and publishes to PubSub
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
2 -- |
322
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
3 -- Depends: http://code.matthewwild.co.uk/lua-feeds |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
4 -- |
278
653c1826739e
mod_pubsub_feed: Fetches Atom feeds and publishes to PubSub
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
5 -- Config: |
653c1826739e
mod_pubsub_feed: Fetches Atom feeds and publishes to PubSub
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
6 -- Component "pubsub.example.com" "pubsub" |
653c1826739e
mod_pubsub_feed: Fetches Atom feeds and publishes to PubSub
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
7 -- modules_enabled = { |
653c1826739e
mod_pubsub_feed: Fetches Atom feeds and publishes to PubSub
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
8 -- "pubsub_feed"; |
653c1826739e
mod_pubsub_feed: Fetches Atom feeds and publishes to PubSub
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
9 -- } |
653c1826739e
mod_pubsub_feed: Fetches Atom feeds and publishes to PubSub
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
10 -- feeds = { -- node -> url |
279
aa0df3db4901
mod_pubsub_feed: Wrap entry in a item element.
Kim Alvefur <zash@zash.se>
parents:
278
diff
changeset
|
11 -- prosody_blog = "http://blog.prosody.im/feed/atom.xml"; |
278
653c1826739e
mod_pubsub_feed: Fetches Atom feeds and publishes to PubSub
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
12 -- } |
653c1826739e
mod_pubsub_feed: Fetches Atom feeds and publishes to PubSub
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
13 -- feed_pull_interval = 20 -- minutes |
322
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
14 -- |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
15 -- Reference |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
16 -- http://pubsubhubbub.googlecode.com/svn/trunk/pubsubhubbub-core-0.3.html |
278
653c1826739e
mod_pubsub_feed: Fetches Atom feeds and publishes to PubSub
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
17 |
653c1826739e
mod_pubsub_feed: Fetches Atom feeds and publishes to PubSub
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
18 local modules = hosts[module.host].modules; |
653c1826739e
mod_pubsub_feed: Fetches Atom feeds and publishes to PubSub
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
19 if not modules.pubsub then |
322
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
20 --FIXME Should this throw an error() instead? |
278
653c1826739e
mod_pubsub_feed: Fetches Atom feeds and publishes to PubSub
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
21 module:log("warn", "Pubsub needs to be loaded on this host"); |
653c1826739e
mod_pubsub_feed: Fetches Atom feeds and publishes to PubSub
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
22 end |
322
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
23 |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
24 |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
25 local t_insert = table.insert; |
278
653c1826739e
mod_pubsub_feed: Fetches Atom feeds and publishes to PubSub
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
26 local add_task = require "util.timer".add_task; |
653c1826739e
mod_pubsub_feed: Fetches Atom feeds and publishes to PubSub
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
27 local date, time = os.date, os.time; |
279
aa0df3db4901
mod_pubsub_feed: Wrap entry in a item element.
Kim Alvefur <zash@zash.se>
parents:
278
diff
changeset
|
28 local dt_parse, dt_datetime = require "util.datetime".parse, require "util.datetime".datetime; |
278
653c1826739e
mod_pubsub_feed: Fetches Atom feeds and publishes to PubSub
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
29 local http = require "net.http"; |
653c1826739e
mod_pubsub_feed: Fetches Atom feeds and publishes to PubSub
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
30 local parse_feed = require "feeds".feed_from_string; |
279
aa0df3db4901
mod_pubsub_feed: Wrap entry in a item element.
Kim Alvefur <zash@zash.se>
parents:
278
diff
changeset
|
31 local st = require "util.stanza"; |
322
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
32 local httpserver = require "net.httpserver"; |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
33 local formencode = require "net.http".formencode; |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
34 local dump = require "util.serialization".serialize; |
323
433bf7dc3e7a
mod_pubsub_feed: Stricter verification handling. Correctly echo the hubs challenge.
Kim Alvefur <zash@zash.se>
parents:
322
diff
changeset
|
35 local uuid = require "util.uuid".generate; |
322
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
36 |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
37 local urldecode = require "net.http".urldecode; |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
38 local urlencode = require "net.http".urlencode; |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
39 local urlparams = --require "net.http".getQueryParams or whatever MattJ names it, FIXME |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
40 function(s) |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
41 if not s:match("=") then return urldecode(s); end |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
42 local r = {} |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
43 s:gsub("([^=&]*)=([^&]*)", function(k,v) |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
44 r[ urldecode(k) ] = urldecode(v); |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
45 return nil |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
46 end) |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
47 return r |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
48 end; |
278
653c1826739e
mod_pubsub_feed: Fetches Atom feeds and publishes to PubSub
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
49 |
653c1826739e
mod_pubsub_feed: Fetches Atom feeds and publishes to PubSub
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
50 local config = module:get_option("feeds") or { |
653c1826739e
mod_pubsub_feed: Fetches Atom feeds and publishes to PubSub
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
51 planet_jabber = "http://planet.jabber.org/atom.xml"; |
653c1826739e
mod_pubsub_feed: Fetches Atom feeds and publishes to PubSub
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
52 prosody_blog = "http://blog.prosody.im/feed/atom.xml"; |
653c1826739e
mod_pubsub_feed: Fetches Atom feeds and publishes to PubSub
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
53 }; |
322
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
54 local refresh_interval = module:get_option_number("feed_pull_interval", 15) * 60; |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
55 local use_pubsubhubub = module:get_option_boolean("use_pubsubhubub", true); -- HTTP by default or not? |
278
653c1826739e
mod_pubsub_feed: Fetches Atom feeds and publishes to PubSub
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
56 local feed_list = { } |
653c1826739e
mod_pubsub_feed: Fetches Atom feeds and publishes to PubSub
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
57 for node, url in pairs(config) do |
322
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
58 feed_list[node] = { url = url; node = node; last_update = 0 }; |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
59 end |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
60 |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
61 local response_codes = { |
323
433bf7dc3e7a
mod_pubsub_feed: Stricter verification handling. Correctly echo the hubs challenge.
Kim Alvefur <zash@zash.se>
parents:
322
diff
changeset
|
62 ["200"] = "OK"; |
322
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
63 ["202"] = "Accepted"; |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
64 ["400"] = "Bad Request"; |
324
100b3ad2e10c
mod_pubsub_feed: Fix verify_token checking.
Kim Alvefur <zash@zash.se>
parents:
323
diff
changeset
|
65 ["403"] = "Forbidden"; |
323
433bf7dc3e7a
mod_pubsub_feed: Stricter verification handling. Correctly echo the hubs challenge.
Kim Alvefur <zash@zash.se>
parents:
322
diff
changeset
|
66 ["404"] = "Not Found"; |
322
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
67 ["501"] = "Not Implemented"; |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
68 }; |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
69 |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
70 local function http_response(code, headers, body) |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
71 return { |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
72 status = (type(code) == "number" and code .. " " .. response_codes[tostring(code)]) or code; |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
73 headers = headers or {}; |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
74 body = body or "<h1>" .. response_codes[tostring(code)] .. "</h1>\n"; |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
75 }; |
278
653c1826739e
mod_pubsub_feed: Fetches Atom feeds and publishes to PubSub
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
76 end |
653c1826739e
mod_pubsub_feed: Fetches Atom feeds and publishes to PubSub
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
77 |
322
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
78 local actor = module.host.."/"..module.name; |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
79 |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
80 function update_entry(item) |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
81 local node = item.node; |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
82 --module:log("debug", "parsing %d bytes of data in node %s", #item.data or 0, node) |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
83 local feed = parse_feed(item.data); |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
84 module:log("debug", "updating node %s", node); |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
85 for _, entry in ipairs(feed) do |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
86 entry.attr.xmlns = "http://www.w3.org/2005/Atom"; |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
87 |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
88 local e_published = entry:get_child("published"); |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
89 e_published = e_published and e_published:get_text(); |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
90 e_published = e_published and dt_parse(e_published); |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
91 local e_updated = entry:get_child("updated"); |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
92 e_updated = e_updated and e_updated:get_text(); |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
93 e_updated = e_updated and dt_parse(e_updated); |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
94 |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
95 local timestamp = e_updated or e_published or nil; |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
96 --module:log("debug", "timestamp is %s, item.last_update is %s", tostring(timestamp), tostring(item.last_update)); |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
97 if not timestamp or not item.last_update or timestamp > item.last_update then |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
98 local id = entry:get_child("id"); |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
99 id = id and id:get_text() or item.url.."#"..dt_datetime(timestamp); -- Missing id, so make one up |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
100 local xitem = st.stanza("item", { id = id }):add_child(entry); |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
101 -- TODO Put data from /feed into item/source |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
102 |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
103 module:log("debug", "publishing to %s, id %s", node, id); |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
104 local ok, err = modules.pubsub.service:publish(node, actor, id, xitem); |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
105 if not ok then |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
106 if err == "item-not-found" then -- try again |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
107 module:log("debug", "got item-not-found, creating %s and trying again", node); |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
108 local ok, err = modules.pubsub.service:create(node, actor); |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
109 if not ok then |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
110 module:log("error", "could not create node %s: %s", node, err); |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
111 return; |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
112 end |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
113 local ok, err = modules.pubsub.service:publish(node, actor, id, xitem); |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
114 if not ok then |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
115 module:log("error", "could not create or publish node %s: %s", node, err); |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
116 return |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
117 end |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
118 else |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
119 module:log("error", "publishing %s failed: %s", node, err); |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
120 end |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
121 end |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
122 end |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
123 end |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
124 |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
125 if use_pubsubhubub and not item.subscription then |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
126 module:log("debug", "check if %s has a hub", item.node); |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
127 local hub = feed.links and feed.links.hub; |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
128 if hub then |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
129 item.hub = hub; |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
130 module:log("debug", "%s has a hub: %s", item.node, item.hub); |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
131 subscribe(item); |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
132 end |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
133 end |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
134 end |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
135 |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
136 function fetch(item, callback) -- HTTP Pull |
278
653c1826739e
mod_pubsub_feed: Fetches Atom feeds and publishes to PubSub
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
137 local headers = { }; |
653c1826739e
mod_pubsub_feed: Fetches Atom feeds and publishes to PubSub
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
138 if item.data and item.last_update then |
653c1826739e
mod_pubsub_feed: Fetches Atom feeds and publishes to PubSub
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
139 headers["If-Modified-Since"] = date("!%a, %d %b %Y %T %Z", item.last_update); |
653c1826739e
mod_pubsub_feed: Fetches Atom feeds and publishes to PubSub
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
140 end |
322
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
141 http.request(item.url, { headers = headers }, function(data, code, req) |
278
653c1826739e
mod_pubsub_feed: Fetches Atom feeds and publishes to PubSub
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
142 if code == 200 then |
653c1826739e
mod_pubsub_feed: Fetches Atom feeds and publishes to PubSub
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
143 item.data = data; |
322
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
144 if callback then callback(item) end |
278
653c1826739e
mod_pubsub_feed: Fetches Atom feeds and publishes to PubSub
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
145 item.last_update = time(); |
653c1826739e
mod_pubsub_feed: Fetches Atom feeds and publishes to PubSub
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
146 end |
653c1826739e
mod_pubsub_feed: Fetches Atom feeds and publishes to PubSub
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
147 if code == 304 then |
653c1826739e
mod_pubsub_feed: Fetches Atom feeds and publishes to PubSub
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
148 item.last_update = time(); |
653c1826739e
mod_pubsub_feed: Fetches Atom feeds and publishes to PubSub
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
149 end |
653c1826739e
mod_pubsub_feed: Fetches Atom feeds and publishes to PubSub
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
150 end); |
653c1826739e
mod_pubsub_feed: Fetches Atom feeds and publishes to PubSub
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
151 end |
653c1826739e
mod_pubsub_feed: Fetches Atom feeds and publishes to PubSub
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
152 |
322
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
153 function refresh_feeds() |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
154 --module:log("debug", "Refreshing feeds"); |
278
653c1826739e
mod_pubsub_feed: Fetches Atom feeds and publishes to PubSub
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
155 for node, item in pairs(feed_list) do |
322
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
156 --FIXME Don't fetch feeds which have a subscription |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
157 -- Otoho, what if the subscription expires or breaks? |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
158 if item.last_update + refresh_interval < time() then |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
159 module:log("debug", "checking %s", item.node); |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
160 fetch(item, update_entry); |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
161 end |
278
653c1826739e
mod_pubsub_feed: Fetches Atom feeds and publishes to PubSub
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
162 end |
653c1826739e
mod_pubsub_feed: Fetches Atom feeds and publishes to PubSub
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
163 return refresh_interval; |
653c1826739e
mod_pubsub_feed: Fetches Atom feeds and publishes to PubSub
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
164 end |
653c1826739e
mod_pubsub_feed: Fetches Atom feeds and publishes to PubSub
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
165 |
323
433bf7dc3e7a
mod_pubsub_feed: Stricter verification handling. Correctly echo the hubs challenge.
Kim Alvefur <zash@zash.se>
parents:
322
diff
changeset
|
166 function subscribe(feed) |
324
100b3ad2e10c
mod_pubsub_feed: Fix verify_token checking.
Kim Alvefur <zash@zash.se>
parents:
323
diff
changeset
|
167 feed.token = uuid(); |
322
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
168 local _body, body = { |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
169 ["hub.callback"] = "http://"..module.host..":5280/callback?node=" .. urlencode(feed.node); --FIXME figure out your own hostname reliably? |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
170 ["hub.mode"] = "subscribe"; --TODO unsubscribe |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
171 ["hub.topic"] = feed.url; |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
172 ["hub.verify"] = "async"; |
324
100b3ad2e10c
mod_pubsub_feed: Fix verify_token checking.
Kim Alvefur <zash@zash.se>
parents:
323
diff
changeset
|
173 ["hub.verify_token"] = feed.token; |
323
433bf7dc3e7a
mod_pubsub_feed: Stricter verification handling. Correctly echo the hubs challenge.
Kim Alvefur <zash@zash.se>
parents:
322
diff
changeset
|
174 --["hub.secret"] = ""; -- TODO http://pubsubhubbub.googlecode.com/svn/trunk/pubsubhubbub-core-0.3.html#authednotify |
322
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
175 --["hub.lease_seconds"] = ""; |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
176 }, { }; |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
177 for name, value in pairs(_body) do |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
178 t_insert(body, { name = name, value = value }); |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
179 end --FIXME Why do I have to do this? |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
180 body = formencode(body); |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
181 |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
182 --module:log("debug", "subscription request, body: %s", body); |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
183 |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
184 --FIXME The subscription states and related stuff |
323
433bf7dc3e7a
mod_pubsub_feed: Stricter verification handling. Correctly echo the hubs challenge.
Kim Alvefur <zash@zash.se>
parents:
322
diff
changeset
|
185 feed.subscription = "subscribe"; |
322
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
186 http.request(feed.hub, { body = body }, function(data, code, req) |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
187 local code = tostring(code); |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
188 module:log("debug", "subscription to %s submitted, staus %s", feed.node, code); |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
189 end); |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
190 end |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
191 |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
192 function handle_http_request(method, body, request) |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
193 --module:log("debug", "%s request to %s%s with body %s", method, request.url.path, request.url.query and "?" .. request.url.query or "", #body > 0 and body or "empty"); |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
194 local query = request.url.query; |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
195 if query and type(query) == "string" then |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
196 query = urlparams(query); |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
197 --module:log("debug", "GET data: %s", dump(query)); |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
198 end |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
199 |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
200 if method == "GET" then |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
201 if query.node and feed_list[query.node] then |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
202 local feed = feed_list[query.node]; |
323
433bf7dc3e7a
mod_pubsub_feed: Stricter verification handling. Correctly echo the hubs challenge.
Kim Alvefur <zash@zash.se>
parents:
322
diff
changeset
|
203 if query["hub.topic"] ~= feed.url then |
433bf7dc3e7a
mod_pubsub_feed: Stricter verification handling. Correctly echo the hubs challenge.
Kim Alvefur <zash@zash.se>
parents:
322
diff
changeset
|
204 module:log("debug", "Invalid topic: %s", tostring(query["hub.topic"])) |
433bf7dc3e7a
mod_pubsub_feed: Stricter verification handling. Correctly echo the hubs challenge.
Kim Alvefur <zash@zash.se>
parents:
322
diff
changeset
|
205 return http_response(404) |
322
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
206 end |
323
433bf7dc3e7a
mod_pubsub_feed: Stricter verification handling. Correctly echo the hubs challenge.
Kim Alvefur <zash@zash.se>
parents:
322
diff
changeset
|
207 if query["hub.mode"] ~= feed.subscription then |
433bf7dc3e7a
mod_pubsub_feed: Stricter verification handling. Correctly echo the hubs challenge.
Kim Alvefur <zash@zash.se>
parents:
322
diff
changeset
|
208 module:log("debug", "Invalid mode: %s", tostring(query["hub.mode"])) |
433bf7dc3e7a
mod_pubsub_feed: Stricter verification handling. Correctly echo the hubs challenge.
Kim Alvefur <zash@zash.se>
parents:
322
diff
changeset
|
209 return http_response(400) |
433bf7dc3e7a
mod_pubsub_feed: Stricter verification handling. Correctly echo the hubs challenge.
Kim Alvefur <zash@zash.se>
parents:
322
diff
changeset
|
210 -- Would this work for unsubscribe? |
433bf7dc3e7a
mod_pubsub_feed: Stricter verification handling. Correctly echo the hubs challenge.
Kim Alvefur <zash@zash.se>
parents:
322
diff
changeset
|
211 -- Also, if feed.subscription is changed here, |
433bf7dc3e7a
mod_pubsub_feed: Stricter verification handling. Correctly echo the hubs challenge.
Kim Alvefur <zash@zash.se>
parents:
322
diff
changeset
|
212 -- it would probably invalidate the subscription |
433bf7dc3e7a
mod_pubsub_feed: Stricter verification handling. Correctly echo the hubs challenge.
Kim Alvefur <zash@zash.se>
parents:
322
diff
changeset
|
213 -- when/if the hub asks if it should be renewed |
433bf7dc3e7a
mod_pubsub_feed: Stricter verification handling. Correctly echo the hubs challenge.
Kim Alvefur <zash@zash.se>
parents:
322
diff
changeset
|
214 end |
324
100b3ad2e10c
mod_pubsub_feed: Fix verify_token checking.
Kim Alvefur <zash@zash.se>
parents:
323
diff
changeset
|
215 if query["hub.verify_token"] ~= feed.token then |
100b3ad2e10c
mod_pubsub_feed: Fix verify_token checking.
Kim Alvefur <zash@zash.se>
parents:
323
diff
changeset
|
216 module:log("debug", "Invalid verify_token: %s", tostring(query["hub.verify_token"])) |
100b3ad2e10c
mod_pubsub_feed: Fix verify_token checking.
Kim Alvefur <zash@zash.se>
parents:
323
diff
changeset
|
217 return http_response(403) |
323
433bf7dc3e7a
mod_pubsub_feed: Stricter verification handling. Correctly echo the hubs challenge.
Kim Alvefur <zash@zash.se>
parents:
322
diff
changeset
|
218 end |
433bf7dc3e7a
mod_pubsub_feed: Stricter verification handling. Correctly echo the hubs challenge.
Kim Alvefur <zash@zash.se>
parents:
322
diff
changeset
|
219 module:log("debug", "Confirming %s request to %s", feed.subscription, feed.url) |
433bf7dc3e7a
mod_pubsub_feed: Stricter verification handling. Correctly echo the hubs challenge.
Kim Alvefur <zash@zash.se>
parents:
322
diff
changeset
|
220 return http_response(200, nil, query["hub.challenge"]) |
322
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
221 end |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
222 return http_response(400); |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
223 elseif method == "POST" then |
323
433bf7dc3e7a
mod_pubsub_feed: Stricter verification handling. Correctly echo the hubs challenge.
Kim Alvefur <zash@zash.se>
parents:
322
diff
changeset
|
224 -- TODO http://pubsubhubbub.googlecode.com/svn/trunk/pubsubhubbub-core-0.3.html#authednotify |
322
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
225 if #body > 0 and feed_list[query.node] then |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
226 module:log("debug", "got %d bytes PuSHed for %s", #body, query.node); |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
227 local feed = feed_list[query.node]; |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
228 feed.data = body; |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
229 update_entry(feed); |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
230 feed.last_update = time(); |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
231 return http_response(202); |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
232 end |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
233 return http_response(400); |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
234 end |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
235 return http_response(501); |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
236 end |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
237 |
278
653c1826739e
mod_pubsub_feed: Fetches Atom feeds and publishes to PubSub
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
238 function init() |
322
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
239 module:log("debug", "initiating", module.name); |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
240 if use_pubsubhubub then |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
241 httpserver.new{ port = 5280, base = "callback", handler = handle_http_request } |
637dc0a04052
mod_pubsub_feed: Implement PubSubHubbub subscriber
Kim Alvefur <zash@zash.se>
parents:
300
diff
changeset
|
242 end |
278
653c1826739e
mod_pubsub_feed: Fetches Atom feeds and publishes to PubSub
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
243 add_task(0, refresh_feeds); |
653c1826739e
mod_pubsub_feed: Fetches Atom feeds and publishes to PubSub
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
244 end |
653c1826739e
mod_pubsub_feed: Fetches Atom feeds and publishes to PubSub
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
245 |
653c1826739e
mod_pubsub_feed: Fetches Atom feeds and publishes to PubSub
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
246 if prosody.start_time then -- already started |
653c1826739e
mod_pubsub_feed: Fetches Atom feeds and publishes to PubSub
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
247 init(); |
653c1826739e
mod_pubsub_feed: Fetches Atom feeds and publishes to PubSub
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
248 else |
653c1826739e
mod_pubsub_feed: Fetches Atom feeds and publishes to PubSub
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
249 prosody.events.add_handler("server-started", init); |
653c1826739e
mod_pubsub_feed: Fetches Atom feeds and publishes to PubSub
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
250 end |