comparison 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
comparison
equal deleted inserted replaced
323:433bf7dc3e7a 324:100b3ad2e10c
60 60
61 local response_codes = { 61 local response_codes = {
62 ["200"] = "OK"; 62 ["200"] = "OK";
63 ["202"] = "Accepted"; 63 ["202"] = "Accepted";
64 ["400"] = "Bad Request"; 64 ["400"] = "Bad Request";
65 ["403"] = "Forbidden";
65 ["404"] = "Not Found"; 66 ["404"] = "Not Found";
66 ["501"] = "Not Implemented"; 67 ["501"] = "Not Implemented";
67 }; 68 };
68 69
69 local function http_response(code, headers, body) 70 local function http_response(code, headers, body)
161 end 162 end
162 return refresh_interval; 163 return refresh_interval;
163 end 164 end
164 165
165 function subscribe(feed) 166 function subscribe(feed)
166 local token = uuid(); 167 feed.token = uuid();
167 local _body, body = { 168 local _body, body = {
168 ["hub.callback"] = "http://"..module.host..":5280/callback?node=" .. urlencode(feed.node); --FIXME figure out your own hostname reliably? 169 ["hub.callback"] = "http://"..module.host..":5280/callback?node=" .. urlencode(feed.node); --FIXME figure out your own hostname reliably?
169 ["hub.mode"] = "subscribe"; --TODO unsubscribe 170 ["hub.mode"] = "subscribe"; --TODO unsubscribe
170 ["hub.topic"] = feed.url; 171 ["hub.topic"] = feed.url;
171 ["hub.verify"] = "async"; 172 ["hub.verify"] = "async";
172 ["hub.verify_token"] = token; 173 ["hub.verify_token"] = feed.token;
173 --["hub.secret"] = ""; -- TODO http://pubsubhubbub.googlecode.com/svn/trunk/pubsubhubbub-core-0.3.html#authednotify 174 --["hub.secret"] = ""; -- TODO http://pubsubhubbub.googlecode.com/svn/trunk/pubsubhubbub-core-0.3.html#authednotify
174 --["hub.lease_seconds"] = ""; 175 --["hub.lease_seconds"] = "";
175 }, { }; 176 }, { };
176 for name, value in pairs(_body) do 177 for name, value in pairs(_body) do
177 t_insert(body, { name = name, value = value }); 178 t_insert(body, { name = name, value = value });
209 -- Would this work for unsubscribe? 210 -- Would this work for unsubscribe?
210 -- Also, if feed.subscription is changed here, 211 -- Also, if feed.subscription is changed here,
211 -- it would probably invalidate the subscription 212 -- it would probably invalidate the subscription
212 -- when/if the hub asks if it should be renewed 213 -- when/if the hub asks if it should be renewed
213 end 214 end
214 if query["hub.verify"] ~= feed.token then 215 if query["hub.verify_token"] ~= feed.token then
215 module:log("debug", "Invalid verify_token: %s", tostring(query["hub.verify"])) 216 module:log("debug", "Invalid verify_token: %s", tostring(query["hub.verify_token"]))
216 return http_response(401) 217 return http_response(403)
217 end 218 end
218 module:log("debug", "Confirming %s request to %s", feed.subscription, feed.url) 219 module:log("debug", "Confirming %s request to %s", feed.subscription, feed.url)
219 return http_response(200, nil, query["hub.challenge"]) 220 return http_response(200, nil, query["hub.challenge"])
220 end 221 end
221 return http_response(400); 222 return http_response(400);