Mercurial > prosody-modules
comparison mod_pubsub_feed/mod_pubsub_feed.lua @ 461:bbea8081c865
Revert various changes accidentally included in previous commit
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Sat, 29 Oct 2011 13:34:15 +0200 |
| parents | 52f2188ec47d |
| children | db5702bb9e41 |
comparison
equal
deleted
inserted
replaced
| 460:9bb9343f3c7a | 461:bbea8081c865 |
|---|---|
| 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() | |
| 46 local config = module:get_option("feeds") or { | 41 local config = module:get_option("feeds") or { |
| 47 planet_jabber = "http://planet.jabber.org/atom.xml"; | 42 planet_jabber = "http://planet.jabber.org/atom.xml"; |
| 48 prosody_blog = "http://blog.prosody.im/feed/atom.xml"; | 43 prosody_blog = "http://blog.prosody.im/feed/atom.xml"; |
| 49 }; | 44 }; |
| 50 refresh_interval = module:get_option_number("feed_pull_interval", 15) * 60; | 45 local refresh_interval = module:get_option_number("feed_pull_interval", 15) * 60; |
| 51 local new_feed_list; | 46 local use_pubsubhubub = module:get_option_boolean("use_pubsubhubub", true); -- HTTP by default or not? |
| 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 = { } | |
| 52 for node, url in pairs(config) do | 49 for node, url in pairs(config) do |
| 53 local new_feed_list[node] = true; | |
| 54 if not feed_list[node] then | |
| 55 feed_list[node] = { url = url; node = node; last_update = 0 }; | 50 feed_list[node] = { url = url; node = node; last_update = 0 }; |
| 56 else | 51 end |
| 57 feed_list[node].url = url; | 52 -- TODO module:hook("config-reloaded", above loop); |
| 58 end | 53 -- Also, keeping it somewhere persistent in order to avoid duplicated publishes? |
| 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); | |
| 68 | 54 |
| 69 -- Used to kill the timer | 55 -- Used to kill the timer |
| 70 local module_unloaded = false; | 56 local module_unloaded = false; |
| 71 function module.unload() | 57 function module.unload() |
| 72 module_unloaded = true; | 58 module_unloaded = true; |
| 73 end | 59 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); | |
| 81 | 60 |
| 82 -- Thanks to Maranda for this | 61 -- Thanks to Maranda for this |
| 83 local port, base, ssl = 5280, "callback", false; | 62 local port, base, ssl = 5280, "callback", false; |
| 84 local ports = module:get_option("feeds_ports") or { port = port, base = base, ssl = ssl }; | 63 local ports = module:get_option("feeds_ports") or { port = port, base = base, ssl = ssl }; |
| 85 -- FIXME If ports isn't a table, this will cause an error | 64 -- FIXME If ports isn't a table, this will cause an error |
| 188 end | 167 end |
| 189 end); | 168 end); |
| 190 end | 169 end |
| 191 | 170 |
| 192 function refresh_feeds() | 171 function refresh_feeds() |
| 193 local now = time(); | |
| 194 if module_unloaded then return end | 172 if module_unloaded then return end |
| 195 --module:log("debug", "Refreshing feeds"); | 173 --module:log("debug", "Refreshing feeds"); |
| 196 for node, item in pairs(feed_list) do | 174 for node, item in pairs(feed_list) do |
| 197 --FIXME Don't fetch feeds which have a subscription | 175 --FIXME Don't fetch feeds which have a subscription |
| 198 -- Otoho, what if the subscription expires or breaks? | 176 -- Otoho, what if the subscription expires or breaks? |
| 199 if item.last_update + refresh_interval < now then | 177 if item.last_update + refresh_interval < time() then |
| 200 module:log("debug", "checking %s", item.node); | 178 module:log("debug", "checking %s", item.node); |
| 201 fetch(item, update_entry); | 179 fetch(item, update_entry); |
| 202 end | 180 end |
| 203 end | 181 end |
| 204 return refresh_interval; | 182 return refresh_interval; |
