comparison mod_pubsub_feed/mod_pubsub_feed.lua @ 455:52f2188ec47d

mod_default_vcard: Sets initial vCard from data enterd on registration
author Kim Alvefur <zash@zash.se>
date Sat, 15 Oct 2011 13:43:37 +0200
parents fe4fdba21a23
children bbea8081c865
comparison
equal deleted inserted replaced
454:3f101f7a26d0 455:52f2188ec47d
36 local formdecode = http.formdecode; 36 local formdecode = http.formdecode;
37 local formencode = http.formencode; 37 local formencode = http.formencode;
38 local urldecode = http.urldecode; 38 local urldecode = http.urldecode;
39 local urlencode = http.urlencode; 39 local urlencode = http.urlencode;
40 40
41 local feed_list = {};
42 local refresh_interval;
43
44 -- Dynamicaly reloadable config.
45 local function update_config()
41 local config = module:get_option("feeds") or { 46 local config = module:get_option("feeds") or {
42 planet_jabber = "http://planet.jabber.org/atom.xml"; 47 planet_jabber = "http://planet.jabber.org/atom.xml";
43 prosody_blog = "http://blog.prosody.im/feed/atom.xml"; 48 prosody_blog = "http://blog.prosody.im/feed/atom.xml";
44 }; 49 };
45 local refresh_interval = module:get_option_number("feed_pull_interval", 15) * 60; 50 refresh_interval = module:get_option_number("feed_pull_interval", 15) * 60;
46 local use_pubsubhubub = module:get_option_boolean("use_pubsubhubub", true); -- HTTP by default or not? 51 local new_feed_list;
47 local httphost = module:get_option_string("pubsubhubub_httphost", module.host); -- If module.host IN A doesn't point to this server, use this to override.
48 local feed_list = { }
49 for node, url in pairs(config) do 52 for node, url in pairs(config) do
53 local new_feed_list[node] = true;
54 if not feed_list[node] then
50 feed_list[node] = { url = url; node = node; last_update = 0 }; 55 feed_list[node] = { url = url; node = node; last_update = 0 };
51 end 56 else
52 -- TODO module:hook("config-reloaded", above loop); 57 feed_list[node].url = url;
53 -- Also, keeping it somewhere persistent in order to avoid duplicated publishes? 58 end
59 end
60 for node in pairs(feed_list) do
61 if not new_feed_list[node] then
62 feed_list[node] = nil;
63 end
64 end
65 end
66 update_config();
67 module:hook("config-reloaded", update_config);
54 68
55 -- Used to kill the timer 69 -- Used to kill the timer
56 local module_unloaded = false; 70 local module_unloaded = false;
57 function module.unload() 71 function module.unload()
58 module_unloaded = true; 72 module_unloaded = true;
59 end 73 end
74
75 -- Config stuff that can't be reloaded, since it would need to re-bind HTTP stuff.
76
77 -- If module.host IN A doesn't point to this server, use this to override.
78 local httphost = module:get_option_string("pubsubhubub_httphost", module.host);
79 -- HTTP by default or not?
80 local use_pubsubhubub = module:get_option_boolean("use_pubsubhubub", true);
60 81
61 -- Thanks to Maranda for this 82 -- Thanks to Maranda for this
62 local port, base, ssl = 5280, "callback", false; 83 local port, base, ssl = 5280, "callback", false;
63 local ports = module:get_option("feeds_ports") or { port = port, base = base, ssl = ssl }; 84 local ports = module:get_option("feeds_ports") or { port = port, base = base, ssl = ssl };
64 -- FIXME If ports isn't a table, this will cause an error 85 -- FIXME If ports isn't a table, this will cause an error
167 end 188 end
168 end); 189 end);
169 end 190 end
170 191
171 function refresh_feeds() 192 function refresh_feeds()
193 local now = time();
172 if module_unloaded then return end 194 if module_unloaded then return end
173 --module:log("debug", "Refreshing feeds"); 195 --module:log("debug", "Refreshing feeds");
174 for node, item in pairs(feed_list) do 196 for node, item in pairs(feed_list) do
175 --FIXME Don't fetch feeds which have a subscription 197 --FIXME Don't fetch feeds which have a subscription
176 -- Otoho, what if the subscription expires or breaks? 198 -- Otoho, what if the subscription expires or breaks?
177 if item.last_update + refresh_interval < time() then 199 if item.last_update + refresh_interval < now then
178 module:log("debug", "checking %s", item.node); 200 module:log("debug", "checking %s", item.node);
179 fetch(item, update_entry); 201 fetch(item, update_entry);
180 end 202 end
181 end 203 end
182 return refresh_interval; 204 return refresh_interval;