Comparison

mod_pubsub_feeds/mod_pubsub_feeds.lua @ 1454:480c6f0576b1

mod_pubsub_feeds: Update to 0.4 version of PubSubHubbub
author Kim Alvefur <zash@zash.se>
date Thu, 26 Jun 2014 18:29:01 +0200
parent 1453:7b53cfc6ba8d
child 1455:13e359c48b5b
comparison
equal deleted inserted replaced
1453:7b53cfc6ba8d 1454:480c6f0576b1
11 -- prosody_blog = "http://blog.prosody.im/feed/atom.xml"; 11 -- prosody_blog = "http://blog.prosody.im/feed/atom.xml";
12 -- } 12 -- }
13 -- feed_pull_interval = 20 -- minutes 13 -- feed_pull_interval = 20 -- minutes
14 -- 14 --
15 -- Reference 15 -- Reference
16 -- http://pubsubhubbub.googlecode.com/svn/trunk/pubsubhubbub-core-0.3.html 16 -- http://pubsubhubbub.googlecode.com/svn/trunk/pubsubhubbub-core-0.4.html
17 17
18 local pubsub = module:depends"pubsub"; 18 local pubsub = module:depends"pubsub";
19 19
20 local date, time = os.date, os.time; 20 local date, time = os.date, os.time;
21 local dt_parse, dt_datetime = require "util.datetime".parse, require "util.datetime".datetime; 21 local dt_parse, dt_datetime = require "util.datetime".parse, require "util.datetime".datetime;
141 end 141 end
142 142
143 function refresh_feeds(now) 143 function refresh_feeds(now)
144 --module:log("debug", "Refreshing feeds"); 144 --module:log("debug", "Refreshing feeds");
145 for node, item in pairs(feed_list) do 145 for node, item in pairs(feed_list) do
146 --FIXME Don't fetch feeds which have a subscription
147 -- Otoho, what if the subscription expires or breaks?
148 if item.subscription ~= "subscribe" and item.last_update + refresh_interval < now then 146 if item.subscription ~= "subscribe" and item.last_update + refresh_interval < now then
149 --module:log("debug", "checking %s", item.node); 147 --module:log("debug", "checking %s", item.node);
150 fetch(item, update_entry); 148 fetch(item, update_entry);
151 end 149 end
152 end 150 end
157 return module:http_url(nil, "/callback") .. "?node=" .. urlencode(node); 155 return module:http_url(nil, "/callback") .. "?node=" .. urlencode(node);
158 end 156 end
159 157
160 function subscribe(feed, want) 158 function subscribe(feed, want)
161 want = want or "subscribe"; 159 want = want or "subscribe";
162 feed.token = uuid();
163 feed.secret = feed.secret or uuid(); 160 feed.secret = feed.secret or uuid();
164 local body = formencode{ 161 local body = formencode{
165 ["hub.callback"] = format_url(feed.node); 162 ["hub.callback"] = format_url(feed.node);
166 ["hub.mode"] = want; 163 ["hub.mode"] = want;
167 ["hub.topic"] = feed.url; 164 ["hub.topic"] = feed.url;
168 ["hub.verify"] = "async"; 165 ["hub.verify"] = "async"; -- COMPAT this is REQUIRED in the 0.3 draft but removed in 0.4
169 ["hub.verify_token"] = feed.token;
170 ["hub.secret"] = feed.secret; 166 ["hub.secret"] = feed.secret;
171 --["hub.lease_seconds"] = ""; 167 --["hub.lease_seconds"] = "";
172 }; 168 };
173 169
174 --module:log("debug", "subscription request, body: %s", body); 170 --module:log("debug", "subscription request, body: %s", body);
214 -- Would this work for unsubscribe? 210 -- Would this work for unsubscribe?
215 -- Also, if feed.subscription is changed here, 211 -- Also, if feed.subscription is changed here,
216 -- it would probably invalidate the subscription 212 -- it would probably invalidate the subscription
217 -- when/if the hub asks if it should be renewed 213 -- when/if the hub asks if it should be renewed
218 end 214 end
219 if query["hub.verify_token"] ~= feed.token then 215 local lease_seconds = tonumber(query["hub.lease_seconds"]);
220 module:log("debug", "Invalid verify_token: %s", tostring(query["hub.verify_token"])) 216 if lease_seconds then
221 return 401; 217 feed.lease_expires = time() + lease_seconds - refresh_interval * 2;
222 end 218 end
223 module:log("debug", "Confirming %s request to %s", feed.subscription, feed.url)
224 return query["hub.challenge"]; 219 return query["hub.challenge"];
225 end 220 end
226 return 400; 221 return 400;
227 elseif method == "POST" then 222 elseif method == "POST" then
228 if #body > 0 then 223 if #body > 0 then