Mercurial > prosody-modules
comparison mod_muc_log_http/muc_log_http/mod_muc_log_http.lua @ 1268:854a3933cfcd
mod_muc_log_http: URL-encode room names. This allows special characters in room names to work. Ideally this escaping shouldn’t be done in the user visible content, but the module’s template system doesn’t currently allow that.
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Sat, 04 Jan 2014 16:50:57 -0500 |
parents | 280adf09ae12 |
children | 7dbde05b48a9 |
comparison
equal
deleted
inserted
replaced
1267:589991b148e8 | 1268:854a3933cfcd |
---|---|
60 url = url:gsub("+", " ") | 60 url = url:gsub("+", " ") |
61 url = url:gsub("%%(%x%x)", function(h) return strchar(tonumber(h,16)) end) | 61 url = url:gsub("%%(%x%x)", function(h) return strchar(tonumber(h,16)) end) |
62 url = url:gsub("\r\n", "\n") | 62 url = url:gsub("\r\n", "\n") |
63 return url | 63 return url |
64 end | 64 end |
65 local function urlencode(s) | |
66 return s and (s:gsub("[^a-zA-Z0-9.~_-]", function (c) return ("%%%02x"):format(c:byte()); end)); | |
67 end | |
65 | 68 |
66 local function generate_room_list(component) | 69 local function generate_room_list(component) |
67 local rooms = ""; | 70 local rooms = ""; |
68 local component_host = hosts[component]; | 71 local component_host = hosts[component]; |
69 if component_host and component_host.muc ~= nil then | 72 if component_host and component_host.muc ~= nil then |
70 for jid, room in pairs(component_host.muc.rooms) do | 73 for jid, room in pairs(component_host.muc.rooms) do |
71 local node = split_jid(jid); | 74 local node = split_jid(jid); |
72 if not room._data.hidden and room._data.logging and node then | 75 if not room._data.hidden and room._data.logging and node then |
73 rooms = rooms .. html.rooms.bit:gsub("###ROOM###", node):gsub("###COMPONENT###", component); | 76 rooms = rooms .. html.rooms.bit:gsub("###ROOM###", urlencode(node)):gsub("###COMPONENT###", component); |
74 end | 77 end |
75 end | 78 end |
76 return html.rooms.body:gsub("###ROOMS_STUFF###", rooms):gsub("###COMPONENT###", component), "Chatroom logs for "..component; | 79 return html.rooms.body:gsub("###ROOMS_STUFF###", rooms):gsub("###COMPONENT###", component), "Chatroom logs for "..component; |
77 end | 80 end |
78 end | 81 end |
240 end | 243 end |
241 if jid == bare_room_jid then | 244 if jid == bare_room_jid then |
242 found = 1 | 245 found = 1 |
243 end | 246 end |
244 | 247 |
245 rooms = rooms .. html.days.rooms.bit:gsub("###ROOM###", node); | 248 rooms = rooms .. html.days.rooms.bit:gsub("###ROOM###", urlencode(node)); |
246 end | 249 end |
247 end | 250 end |
248 | 251 |
249 room = component.muc.rooms[bare_room_jid]; | 252 room = component.muc.rooms[bare_room_jid]; |
250 if room._data.hidden or not room._data.logging then | 253 if room._data.hidden or not room._data.logging then |