Remove globals

Clean up a bunch of places where the global namespace was being
polluted by accident.
This commit is contained in:
Robin Malley 2021-01-17 05:10:16 +00:00
parent 6cd786be1a
commit 1f5b113daa
5 changed files with 8 additions and 14 deletions

View File

@ -12,7 +12,7 @@ local util = require("util")
local ret = {}
local stmnt_cache, stmnt_insert_cache
local stmnt_cache, stmnt_insert_cache, stmnt_dirty_cache
local oldconfigure = configure
function configure(...)
@ -59,7 +59,7 @@ function ret.render(pagename,callback)
stmnt_cache:reset()
--page is not cached
elseif err == sql.ROW then
data = stmnt_cache:get_values()
local data = stmnt_cache:get_values()
stmnt_cache:reset()
return data[1]
else --sql.ERROR or sql.MISUSE
@ -84,7 +84,7 @@ function ret.dirty(url)
stmnt_dirty_cache:bind_names{
path = url
}
err = util.do_sql(stmnt_dirty_cache)
util.do_sql(stmnt_dirty_cache)
stmnt_dirty_cache:reset()
end

View File

@ -11,7 +11,7 @@ local cache = require("cache")
local config = require("config")
local session = require("session")
local stmnt_author_of, stmnt_update_raw, stmnt_update
local stmnt_author_of, stmnt_update_raw, stmnt_update, stmnt_hash
local oldconfigure = configure
function configure(...)

View File

@ -94,6 +94,7 @@ end
local function author_paste(req,ps)
--Author paste
local author, authorid = session.get(req)
local ret
if author == nil then
ret = pages.author_paste{
domain = config.domain,
@ -114,7 +115,7 @@ local function author_paste(req,ps)
assert(stmnt_paste:bind_blob(5,"") == sql.OK)
util.sqlbind(stmnt_paste,"bind",6,ps.unlisted)
util.sqlbind(stmnt_paste,"bind_blob",7,textsha3)
err = util.do_sql(stmnt_paste)
local err = util.do_sql(stmnt_paste)
stmnt_paste:reset()
if err == sql.DONE then
local rowid = stmnt_paste:last_insert_rowid()
@ -193,7 +194,6 @@ local function paste_post(req)
text = zlib.compress(text)
assert(text,"Failed to compress text")
ps.text = text
local esctitle = util.decodeentities(title)
--Always sanatize the title with the plain parser. no markup
--in the title.
ps.title = parsers.plain(title)

View File

@ -5,7 +5,7 @@ local util = require("util")
local queries = require("queries")
local oldconfigure = configure
local stmnt_get_session, stmnt_insert_session
local stmnt_get_session, stmnt_insert_session, stmnt_delete_session
function configure(...)
stmnt_get_session = assert(db.conn:prepare(queries.select_valid_sessions))
stmnt_insert_session = assert(db.conn:prepare(queries.insert_session))

View File

@ -169,13 +169,7 @@ function util.parse_tags(str)
end
local function decodeentity(capture)
local n = tonumber(capture,16)
local c = string.char(n)
if escapes[c] then
return escapes[c]
else
return c
end
return string.char(tonumber(capture,16)) --Decode base 16 and conver to character
end
function util.decodeentities(str)
return string.gsub(str,"%%(%x%x)",decodeentity)