Mercurial > prosody-modules
comparison mod_pubsub_feed/mod_pubsub_feed.lua @ 401:c85397063eca
mod_pubsub_feed: Try harder to figure out ones callback URL.
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Wed, 24 Aug 2011 15:03:38 +0200 |
| parents | f42fe4229f8a |
| children | c92a37a72b25 |
comparison
equal
deleted
inserted
replaced
| 400:f42fe4229f8a | 401:c85397063eca |
|---|---|
| 52 planet_jabber = "http://planet.jabber.org/atom.xml"; | 52 planet_jabber = "http://planet.jabber.org/atom.xml"; |
| 53 prosody_blog = "http://blog.prosody.im/feed/atom.xml"; | 53 prosody_blog = "http://blog.prosody.im/feed/atom.xml"; |
| 54 }; | 54 }; |
| 55 local refresh_interval = module:get_option_number("feed_pull_interval", 15) * 60; | 55 local refresh_interval = module:get_option_number("feed_pull_interval", 15) * 60; |
| 56 local use_pubsubhubub = module:get_option_boolean("use_pubsubhubub", true); -- HTTP by default or not? | 56 local use_pubsubhubub = module:get_option_boolean("use_pubsubhubub", true); -- HTTP by default or not? |
| 57 local http_hostname = module:get_option_string("pubsubhubub_httphost", module.host); | |
| 57 local feed_list = { } | 58 local feed_list = { } |
| 58 for node, url in pairs(config) do | 59 for node, url in pairs(config) do |
| 59 feed_list[node] = { url = url; node = node; last_update = 0 }; | 60 feed_list[node] = { url = url; node = node; last_update = 0 }; |
| 61 end | |
| 62 | |
| 63 local ports = module:get_option("feeds_ports") or { 5280 }; | |
| 64 if not next(ports) then | |
| 65 ports = { 5280 }; | |
| 66 end | |
| 67 local port_number, base_name, secure; | |
| 68 for _, opts in ipairs(ports) do | |
| 69 if type(opts) == "number" then | |
| 70 port_number, base_name = opts, "callback"; | |
| 71 elseif type(opts) == "table" then | |
| 72 port_number, base_name, secure = opts.port or 5280, opts.path or "callback", opts.ssl or nil; | |
| 73 elseif type(opts) == "string" then | |
| 74 base_name, port_number = opts, 5280; | |
| 75 end | |
| 60 end | 76 end |
| 61 | 77 |
| 62 local response_codes = { | 78 local response_codes = { |
| 63 ["200"] = "OK"; | 79 ["200"] = "OK"; |
| 64 ["202"] = "Accepted"; | 80 ["202"] = "Accepted"; |
| 163 end | 179 end |
| 164 end | 180 end |
| 165 return refresh_interval; | 181 return refresh_interval; |
| 166 end | 182 end |
| 167 | 183 |
| 184 local function format_url(secure, host, port, path, node) | |
| 185 return ("%s://%s:%d/%s?node=%s"):format(secure and "https" or "http", host, port, path, urlencode(node)); | |
| 186 end | |
| 187 | |
| 168 function subscribe(feed) | 188 function subscribe(feed) |
| 169 feed.token = uuid(); | 189 feed.token = uuid(); |
| 170 feed.secret = uuid(); | 190 feed.secret = uuid(); |
| 171 local _body, body = { | 191 local _body, body = { |
| 172 ["hub.callback"] = "http://"..module.host..":5280/callback?node=" .. urlencode(feed.node); --FIXME figure out your own hostname reliably? | 192 ["hub.callback"] = format_url(secure, http_hostname, port_number, base_name, feed.node); |
| 173 ["hub.mode"] = "subscribe"; --TODO unsubscribe | 193 ["hub.mode"] = "subscribe"; --TODO unsubscribe |
| 174 ["hub.topic"] = feed.url; | 194 ["hub.topic"] = feed.url; |
| 175 ["hub.verify"] = "async"; | 195 ["hub.verify"] = "async"; |
| 176 ["hub.verify_token"] = feed.token; | 196 ["hub.verify_token"] = feed.token; |
| 177 ["hub.secret"] = feed.secret; | 197 ["hub.secret"] = feed.secret; |
| 249 end | 269 end |
| 250 | 270 |
| 251 function init() | 271 function init() |
| 252 module:log("debug", "initiating", module.name); | 272 module:log("debug", "initiating", module.name); |
| 253 if use_pubsubhubub then | 273 if use_pubsubhubub then |
| 254 httpserver.new{ port = 5280, base = "callback", handler = handle_http_request } | 274 httpserver.new{ port = port_number, base = base_name, handler = handle_http_request } |
| 255 end | 275 end |
| 256 add_task(0, refresh_feeds); | 276 add_task(0, refresh_feeds); |
| 257 end | 277 end |
| 258 | 278 |
| 259 if prosody.start_time then -- already started | 279 if prosody.start_time then -- already started |
