Software /
code /
prosody
Comparison
util/openssl.lua @ 7022:3252c107c91a
util.openssl: Rename variables for readability
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 23 Dec 2015 08:46:54 +0100 |
parent | 7021:f436446661ca |
child | 7023:c2ccbfe30113 |
comparison
equal
deleted
inserted
replaced
7021:f436446661ca | 7022:3252c107c91a |
---|---|
145 do -- Lua to shell calls. | 145 do -- Lua to shell calls. |
146 local function shell_escape(s) | 146 local function shell_escape(s) |
147 return "'" .. tostring(s):gsub("'",[['\'']]) .. "'"; | 147 return "'" .. tostring(s):gsub("'",[['\'']]) .. "'"; |
148 end | 148 end |
149 | 149 |
150 local function serialize(f,o) | 150 local function serialize(command, args) |
151 local r = {"openssl", f}; | 151 local commandline = { "openssl", command }; |
152 for k,v in pairs(o) do | 152 for k, v in pairs(args) do |
153 if type(k) == "string" then | 153 if type(k) == "string" then |
154 t_insert(r, ("-%s"):format(k)); | 154 t_insert(commandline, ("-%s"):format(k)); |
155 if v ~= true then | 155 if v ~= true then |
156 t_insert(r, shell_escape(v)); | 156 t_insert(commandline, shell_escape(v)); |
157 end | 157 end |
158 end | 158 end |
159 end | 159 end |
160 for _,v in ipairs(o) do | 160 for _, v in ipairs(args) do |
161 t_insert(r, shell_escape(v)); | 161 t_insert(commandline, shell_escape(v)); |
162 end | 162 end |
163 return t_concat(r, " "); | 163 return t_concat(commandline, " "); |
164 end | 164 end |
165 | 165 |
166 local os_execute = os.execute; | 166 local os_execute = os.execute; |
167 setmetatable(_M, { | 167 setmetatable(_M, { |
168 __index=function(_,f) | 168 __index=function(_,f) |
169 return function(opts) | 169 return function(opts) |
170 return 0 == os_execute(serialize(f, type(opts) == "table" and opts or {})); | 170 return 0 == os_execute(serialize(command, type(opts) == "table" and opts or {})); |
171 end; | 171 end; |
172 end; | 172 end; |
173 }); | 173 }); |
174 end | 174 end |
175 | 175 |