1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-06 05:21:22 +03:00

added lua test cases

git-svn-id: svn://svn.code.sf.net/p/axtls/code/trunk@128 9a5d90b5-6617-0410-8a86-bb477d3ed2e3
This commit is contained in:
cameronrich 2007-09-17 21:48:39 +00:00
parent 69003c01ac
commit ab7cbe8310
28 changed files with 659 additions and 34 deletions

View File

@ -28,6 +28,15 @@ extern "C" {
#endif
#include "os_port.h"
#include "config.h"
/* enable features based on a 'super-set' capbaility. */
#if defined(CONFIG_SSL_FULL_MODE)
#define CONFIG_SSL_ENABLE_CLIENT
#define CONFIG_SSL_CERT_VERIFICATION
#elif defined(CONFIG_SSL_ENABLE_CLIENT)
#define CONFIG_SSL_CERT_VERIFICATION
#endif
/**************************************************************************
* AES declarations

View File

@ -29,7 +29,13 @@
#include "crypto.h"
static const unsigned char PI_SUBST[256] =
/**
* This code is only here to enable the verification of Verisign root
* certificates. So only enable it for verification mode.
*/
#ifdef CONFIG_SSL_CERT_VERIFICATION
static const uint8_t PI_SUBST[256] =
{
0x29, 0x2E, 0x43, 0xC9, 0xA2, 0xD8, 0x7C, 0x01, 0x3D, 0x36,
0x54, 0xA1, 0xEC, 0xF0, 0x06, 0x13, 0x62, 0xA7, 0x05, 0xF3,
@ -70,7 +76,7 @@ EXP_FUNC void STDCALL MD2_Init(MD2_CTX *ctx)
static void md2_process(MD2_CTX *ctx)
{
int i, j;
unsigned char t = 0;
uint8_t t = 0;
for (i = 0; i < 16; i++)
{
@ -140,3 +146,5 @@ EXP_FUNC void STDCALL MD2_Final(uint8_t *output, MD2_CTX *ctx)
memcpy(output, ctx->state, 16);
}
#endif

View File

@ -622,7 +622,7 @@ void procsendfile(struct connstruct *cn)
#if defined(CONFIG_HTTP_HAS_CGI)
/* Should this be a bit more dynamic? It would mean more calls to malloc etc */
#define CGI_ARG_SIZE 16
#define CGI_ARG_SIZE 17
static void proccgi(struct connstruct *cn)
{
@ -771,7 +771,8 @@ static void proccgi(struct connstruct *cn)
if (cgi_index >= CGI_ARG_SIZE)
{
printf("Content-type: text/plain\n\nToo many CGI args\n");
printf("Content-type: text/plain\n\nToo many CGI args (%d, %d)\n",
cgi_index, CGI_ARG_SIZE);
_exit(1);
}

View File

@ -19,17 +19,8 @@
#ifndef BIGINT_HEADER
#define BIGINT_HEADER
#include "config.h"
/* enable features based on a 'super-set' capbaility. */
#if defined(CONFIG_SSL_FULL_MODE)
#define CONFIG_SSL_ENABLE_CLIENT
#define CONFIG_SSL_CERT_VERIFICATION
#elif defined(CONFIG_SSL_ENABLE_CLIENT)
#define CONFIG_SSL_CERT_VERIFICATION
#endif
#include "os_port.h"
#include "crypto.h"
#include "bigint_impl.h"
#ifndef CONFIG_BIGINT_CHECK_ON

View File

@ -27,6 +27,7 @@
extern "C" {
#endif
#include "crypto.h"
#include "bigint.h"
/**************************************************************************

View File

@ -27,7 +27,6 @@
#include <string.h>
#include <time.h>
#include "os_port.h"
#include "crypto.h"
#include "crypto_misc.h"
#ifdef CONFIG_SSL_CERT_VERIFICATION

File diff suppressed because one or more lines are too long

75
www/lua/download.lua Normal file
View File

@ -0,0 +1,75 @@
#!/usr/local/bin/lua
require"luasocket"
function receive (connection)
connection:settimeout(0)
local s, status = connection:receive (2^10)
if status == "timeout" then
coroutine.yield (connection)
end
return s, status
end
function download (host, file, outfile)
--local f = assert (io.open (outfile, "w"))
local c = assert (socket.connect (host, 80))
c:send ("GET "..file.." HTTP/1.0\r\n\r\n")
while true do
local s, status = receive (c)
--f:write (s)
if status == "closed" then
break
end
end
c:close()
--f:close()
end
local threads = {}
function get (host, file, outfile)
print (string.format ("Downloading %s from %s to %s", file, host, outfile))
local co = coroutine.create (function ()
return download (host, file, outfile)
end)
table.insert (threads, co)
end
function dispatcher ()
while true do
local n = table.getn (threads)
if n == 0 then
break
end
local connections = {}
for i = 1, n do
local status, res = coroutine.resume (threads[i])
if not res then
table.remove (threads, i)
break
else
table.insert (connections, res)
end
end
if table.getn (connections) == n then
socket.select (connections)
end
end
end
local url = arg[1]
if not url then
print (string.format ("usage: %s url [times]", arg[0]))
os.exit()
end
local times = arg[2] or 5
url = string.gsub (url, "^http.?://", "")
local _, _, host, file = string.find (url, "^([^/]+)(/.*)")
local _, _, fn = string.find (file, "([^/]+)$")
for i = 1, times do
get (host, file, fn..i)
end
dispatcher ()

26
www/lua/env.lua Normal file
View File

@ -0,0 +1,26 @@
-- This file should be executed before any script in this directory
-- according to the configuration (cgilua/conf.lua).
pcall (cgilua.enablesession)
local put, mkurlpath = cgilua.put, cgilua.mkurlpath
cgilua.addclosefunction (function ()
put [[
<p>
<small>
<a href="test_main.html">Main</a>]]
for _, test in {
{ "Get", "test_main.lua", {ab = "cd", ef = "gh"} },
{ "Cookies", "test_cookies.lua", },
{ "FileSystem", "test_fs.lua", },
{ "Libraries", "test_lib.lua", },
{ "Session", "test_session.lua", },
{ "Variables", "test_variables.lp", },
} do
put (string.format (' &middot; <a href="%s">%s</a>',
mkurlpath (test[2], test[3]), test[1]))
end
put [[
</small>]]
end)

64
www/lua/overview.lp Normal file
View File

@ -0,0 +1,64 @@
<?lua
-- Tries to load known libraries
for _, t in ipairs { "lxp", "luasql.postgres", "luasql.mysql", "luasql.oci8", "luasql.sqlite", "luasql.odbc", "socket", "xmlrpc", "soap", "lualdap", "logging", "md5", "zip", "stable", "copas", } do
pcall (require, t)
end
libraries = { "lxp", "luasql", "socket", "xmlrpc", "soap", "lualdap", "logging", "md5", "zip", "stable", "copas", }
local colors = { "#999999", "#CCCCCC", "#FFFFFF", }
local i = 0
function color () i = math.mod (i + 1, 3) return colors[i + 1] end
function pack_name (p) return string.gsub (p, "^([^.]+).-", "%1") end
function idx (t, f) return _G[t][f] or _G[t]["_"..f] or "" end
?>
<html>
<head><title>CGILua installation overview</title></head>
<body bgcolor="#FFFFFF">
<h1>CGILua installation overview</h1>
<table>
<tr>
<th bgcolor="#999999">Version
<th bgcolor="#999999">Copyright
<th bgcolor="#999999">Description
</tr>
<?lua
local support = {
{ "Lua", "_VERSION" },
{ "compat-5.1", "_COMPAT51" },
}
for _, l in ipairs (support) do bg = color()
?>
<tr>
<td bgcolor = "<%= bg %>"><%= tostring(_G[l[2]]) %>
<td bgcolor = "<%= bg %>">
<td bgcolor = "<%= bg %>">
</tr>
<? end ?>
<tr><td colspan="4"></tr>
<?lua
local pack = {}
for i, p in ipairs (libraries) do
local s = _G[p]
local n = pack_name(p)
if type(_G[n]) == "table" and _G[n]._VERSION then
pack[n] = true
table.insert (pack, n)
end
end
table.sort (pack)
for _, p in ipairs (pack) do bg = color() ?>
<tr>
<td bgcolor = "<%= bg %>"><%= idx(p,"VERSION") %>
<td bgcolor = "<%= bg %>"><small><%= idx(p,"COPYRIGHT") %></small>
<td bgcolor = "<%= bg %>"><small><%= idx(p,"DESCRIPTION") %></small>
</tr>
<?lua end ?>
</table>
</body>
</html>

31
www/lua/prepara_sql2.lua Normal file
View File

@ -0,0 +1,31 @@
#!/usr/local/bin/lua
MAX_ROWS = arg[1] or 10
require"postgres"
local env = assert (luasql.postgres ())
local conn = assert (env:connect ("luasql-test", "tomas"))
-- Apaga restos de outros testes.
conn:execute "drop table t2"
conn:execute "drop table t1"
-- Criando as tabelas.
assert (conn:execute [[create table t1 (
a int,
b int
)]])
assert (conn:execute [[create table t2 (
c int,
d int
)]])
-- Preenchedo as tabelas.
for i = 1, MAX_ROWS do
local ii = 2*i
assert (conn:execute (string.format ([[
insert into t1 values (%d, %d);
insert into t2 values (%d, %d);]],
ii, i, ii, i)))
end

9
www/lua/tcgi1.lua Normal file
View File

@ -0,0 +1,9 @@
io.stdout:write"Content-type: text/html\n\n"
for i,v in pairs{"QUERY_STRING", } do
io.stdout:write (string.format ("%s = %s", v, os.getenv(v) or '&nbsp;'))
end
io.stdout:write "<br>\n"
local post_data = io.stdin:read"*a"
io.stdout:write (string.format ("post_data = {%s}", post_data))

38
www/lua/test_conc.lua Normal file
View File

@ -0,0 +1,38 @@
cgilua.htmlheader()
if ap then
local pid, ppid = ap.pid ()
if not ppid then
ppid = "no parent pid"
end
cgilua.put ("pid = "..pid.." ("..ppid..")".."\n")
end
assert(type(stable.get) == "function")
assert(type(stable.set) == "function")
cgilua.put"stable.pairs = {<br>\n"
for i, v in stable.pairs () do
cgilua.put (i.." = "..tostring(v).."<br>\n")
end
cgilua.put"}<br>\n"
local counter = stable.get"counter" or 0
stable.set ("counter", counter + 1)
local f = stable.get"f"
if not f then
local d = os.date()
stable.set ("f", function () return d end)
else
cgilua.put ("f() = "..tostring (f ()))
end
cgilua.put"<br>\n"
for i = 1,800 do
cgilua.put (i)
for ii = 1,1000 do
cgilua.put ("<!>")
end
cgilua.put ("\n")
end
cgilua.put ("End")

13
www/lua/test_cookies.lp Normal file
View File

@ -0,0 +1,13 @@
<?lua
local cookies = require"cgilua.cookies"
CL_COOKIE = "cgilua_cookie"
local test = cookies.get (CL_COOKIE)
cookies.sethtml (CL_COOKIE, os.date())
?>
<h1>Testing Cookies library</h1>
<%= CL_COOKIE%> = <%= tostring(test)%><br>
Assigning current date to cookie!<br>
Reload this script to check cookie's value!

14
www/lua/test_cookies.lua Normal file
View File

@ -0,0 +1,14 @@
local cookies = require"cgilua.cookies"
CL_COOKIE = "cgilua_cookie"
local test = cookies.get (CL_COOKIE)
cookies.set (CL_COOKIE, os.date())
cgilua.htmlheader ()
cgilua.put ([[
<h1>Testing Cookies library</h1>
]]..CL_COOKIE..' = '..tostring(test)..[[<br>
Assigning current date to cookie!<br>
Reload this script to check cookie's value!
]])

4
www/lua/test_err.lua Normal file
View File

@ -0,0 +1,4 @@
cgilua.htmlheader()
cgilua.put"Oi!"
--io.write"something\n"
cgilua.errorlog ("eca", "emerg")

23
www/lua/test_fs.lua Normal file
View File

@ -0,0 +1,23 @@
function link_dir (dir, base)
local path = base.."/"..dir
local mode = lfs.attributes (path).mode
if mode == "directory" then
return string.format ('<a href="%s">%s</a>',
cgilua.mkurlpath ("test_fs.lua", { dir = path }),
dir)
else
return dir
end
end
cgilua.htmlheader ()
cgilua.put ("<h1>Testing Filesystem library</h1>\n")
cgilua.put ("<table>\n")
cgilua.put ("<tr><td colspan=2>Testing <b>dir</b></td></tr>\n")
local i = 0
local dir = cgi.dir or "."
for file in lfs.dir (dir) do
i = i+1
cgilua.put ("<tr><td>"..i.."</td><td>"..link_dir(file, dir).."</td></tr>\n")
end
cgilua.put ("</table>\n")

22
www/lua/test_htk.lua Normal file
View File

@ -0,0 +1,22 @@
require"htk"
local a_table = {}
for i = 1, 20 do
local l = {}
for j = 1, 20 do
table.insert (l, HTK.TD { "cell "..i..","..j })
end
table.insert (a_table, HTK.TR (l))
end
cgilua.htmlheader()
cgilua.put (HTK.HTML {
HTK.HEAD { HTK.TITLE { "Titulo da Pagina" } },
HTK.BODY {
bgcolor = "#FFFFFF",
HTK.H1 { "Titulo da Pagina" },
HTK.P {},
"Uma página qualquer",
HTK.TABLE (a_table),
}
})

31
www/lua/test_lib.lua Normal file
View File

@ -0,0 +1,31 @@
local function getfield (t, f)
for w in string.gfind(f, "[%w_]+") do
if not t then return nil end
t = t[w]
end
return t
end
function test_lib (libname)
local ok, err = pcall (require, libname)
if not ok then
cgilua.put ("Library <tt><b>"..libname.."</b></tt> not found<br>\n"..
err)
else
cgilua.put ("Library <tt><b>"..libname.."</b></tt><br>\n")
local t = getfield (_G, libname)
if type(t) ~= "table" then
cgilua.put (tostring(t))
else
for i, v in pairs (t) do
cgilua.put ("&nbsp;&nbsp;"..tostring(i).." = "..tostring(v).."<br>\n")
end
end
end
cgilua.put ("\n<p>\n")
end
cgilua.htmlheader ()
for _, lib in ipairs { "lfs", "socket", "luasql.postgres", "luasql", "lxp", "lxp.lom", "lualdap", "htk", "xmlrpc", "xmlrpc.http" } do
test_lib (lib)
end

127
www/lua/test_main.html Normal file
View File

@ -0,0 +1,127 @@
<html>
<head><title>Test Page</title></head>
<table border>
<tr>
<th colspan="4"> GET: </td>
</tr>
<tr>
<td>Lua script</td>
<td><a href="test_main.lua?field1=ab&field2=cd&field1=ef">module</a></td>
</tr>
<tr>
<td>HTML template</td>
<td><a href="test_main.lp?field1=ab&field2=cd&field1=ef">module</a></td>
</tr>
<tr>
<th colspan="4"> POST: </td>
</tr>
<tr>
<td colspan="4">
<form method="POST" action="">
<table>
<tr>
<td colspan="4">
field 1: <input type="text" name="field1"><br>
field 2: <input type="text" name="field2"><br>
field 3:
<input type="checkbox" name="field3" value="op 1">op 1
<input type="checkbox" name="field3" value="op 2">op 2
<input type="checkbox" name="field3" value="op 3">op 3
</td>
</tr>
<tr>
<td>Lua script</td>
<td>
<a href="javascript:document.forms[0].action='test_main.lua';document.forms[0].submit()">module</a>
</td>
</tr>
<tr>
<td>HTML template</td>
<td>
<a href="javascript:document.forms[0].action='test_main.lp';document.forms[0].submit()">module</a>
</td>
</tr>
</table>
</form>
</td>
</tr>
<tr>
<th colspan="4"> POST (with upload): </td>
</tr>
<tr>
<td colspan="4">
<form method="POST" enctype="multipart/form-data" action="">
<table>
<tr>
<td colspan="4">
field 1: <input type="text" name="field1"><br>
file (binary!): <input type="file" name="file"><br>
</td>
</tr>
<tr>
<td>Lua script</td>
<td>
<a href="javascript:document.forms[1].action='test_main.lua';document.forms[1].submit()">module</a>
</td>
</tr>
<tr>
<td>HTML template</td>
<td>
<a href="javascript:document.forms[1].action='test_main.lp';document.forms[1].submit()">module</a>
</td>
</tr>
</table>
</form>
</td>
</tr>
<tr>
<th colspan="4"> Cookies: </td>
</tr>
<tr>
<td>Lua script</td>
<td><a href="test_cookies.lua">module</a></td>
</tr>
<tr>
<td>HTML template</td>
<td><a href="test_cookies.lp">module</a></td>
</tr>
<tr>
<th colspan="4"> Filesystem: </td>
</tr>
<tr>
<td>Lua script</td>
<td><a href="test_fs.lua">module</a></td>
</tr>
<tr>
<th colspan="4"> Session: </td>
</tr>
<tr>
<td>Lua script</td>
<td><a href="test_session.lua">module</a></td>
</tr>
<tr>
<th colspan="4"> CGI Variables: </td>
</tr>
<tr>
<td>HTML template</td>
<td><a href="test_variables.lp">module</a></td>
</tr>
<tr>
<th colspan="4"> Library Overview: </td>
</tr>
<tr>
<td>HTML template</td>
<td><a href="overview.lp">module</a></td>
</tr>
<tr>
<th colspan="4"> Concurrency </td>
</tr>
<tr>
<td>Lua script</td>
<td><a href="test_conc.lua">module</a></td>
</tr>
</table>
</html>

31
www/lua/test_main.lp Normal file
View File

@ -0,0 +1,31 @@
<html>
<head><title>Embeded Lua Test</title></head>
<body>
cgi = {
<?lua
for i,v in pairs (cgi) do
if type(v) == "table" then
local vv = "{"
for a,b in pairs(v) do
vv = string.format ("%s%s = %s<br>\n", vv, a, tostring(b))
end
v = vv.."}"
end
?>
<%= i %> = <%= tostring(v) %> <br>
<%
end
%>
}
<br>
Remote address: <%= cgilua.servervariable"REMOTE_ADDR" %>
<br>
Is persistent = <%= tostring (SAPI.Info.ispersistent) %>
<br>
ap = <?lua= tostring(ap) ?> <br>
lfcgi = <% = tostring(lfcgi) %> <br>
<%= (ap and ap.handler()) or "" %> <br>
</body>
</html>

46
www/lua/test_main.lua Normal file
View File

@ -0,0 +1,46 @@
cgilua.htmlheader()
cgilua.put[[
<html>
<head><title>Script Lua Test</title></head>
<body>
cgi = {
]]
for i,v in pairs (cgi) do
if type(v) == "table" then
local vv = "{"
for a,b in pairs(v) do
vv = string.format ("%s%s = %s<br>\n", vv, a, tostring(b))
end
v = vv.."}"
end
cgilua.put (string.format ("%s = %s<br>\n", i, tostring(v)))
end
cgilua.put "}<br>\n"
cgilua.put ("Remote address: "..cgilua.servervariable"REMOTE_ADDR")
cgilua.put "<br>\n"
cgilua.put ("Is persistent = "..tostring (SAPI.Info.ispersistent).."<br>\n")
cgilua.put ("ap="..tostring(ap).."<br>\n")
cgilua.put ("lfcgi="..tostring(lfcgi).."<br>\n")
-- Checking Virtual Environment
local my_output = cgilua.put
cgilua.put = nil
local status, err = pcall (function ()
assert (cgilua.put == nil, "cannot change cgilua.put value")
end)
cgilua.put = my_output
assert (status == true, err)
-- Checking require
local status, err = pcall (function () require"unknown_module" end)
assert (status == false, "<tt>unknown_module</tt> loaded!")
-- assert (package == nil, "Access to <tt>package</tt> table allowed!")
cgilua.put[[
<p>
</body>
</html>
]]
cgilua = nil

43
www/lua/test_session.lua Normal file
View File

@ -0,0 +1,43 @@
cgilua.enablesession ()
function pt (tab)
for i, v in pairs (tab) do
local vv = v
if type(v) == "table" then
vv = ""
for _i, _v in pairs (v) do
vv = vv..string.format ("%s = %q, ", _i, _v)
end
vv = '{'..vv..'}'
end
cgilua.put (string.format ("%s = %s<br>\n", tostring (i), tostring (vv)))
end
end
if cgi.field then
if not cgilua.session.data.field then
cgilua.session.data.field = {}
end
table.insert (cgilua.session.data.field, cgi.field)
end
cgilua.htmlheader()
if cgilua.session then
cgilua.put "cgi = {<br>\n"
pt (cgi)
cgilua.put "}<br>\n"
cgilua.put "cgilua.session.data = {<br>\n"
pt (cgilua.session.data)
cgilua.put "}<br>\n"
cgilua.put [[<form action="]]
cgilua.put (cgilua.mkurlpath"test_session.lua")
cgilua.put [[" method="POST">
field: <input type="text" name="field" value="]]
cgilua.put (cgi.field or "")
cgilua.put [["><br>
<input type="submit"><br>
</form>]]
else
cgilua.put "Sessions library is not available or not well configured"
end

13
www/lua/test_sql.lua Normal file
View File

@ -0,0 +1,13 @@
local s = require"luasql.postgres"
local env = assert (luasql.postgres ())
local conn = assert (env:connect ("luasql-test", "tomas"))
local cur = assert (conn:execute ("select count(*) from fetch_test"))
cgilua.htmlheader()
cgilua.put ("Total lines at table fetch_test is "..cur:fetch())
cgilua.put (string.format ("<br>\n%s == %s<br>\n", tostring(s), tostring(luasql)))
cur:close()
conn:close()
env:close()

24
www/lua/test_sql2.lua Normal file
View File

@ -0,0 +1,24 @@
require"postgres"
local env = assert (luasql.postgres ())
local conn = assert (env:connect ("luasql-test", "tomas"))
local cur = assert (conn:execute ("select count(*) from t1"))
local total = tonumber (cur:fetch())
cur:close()
local aleatorio = math.random(total)
local cur = assert (conn:execute ("select * from t1, t2 where b = d and a != "..2*aleatorio))
cgilua.htmlheader()
cgilua.put ("Aleatorio = "..aleatorio.."<br>\n")
local a,b,c,d = cur:fetch()
cgilua.put ("<table>\n")
while a do
-- cgilua.put ("<tr><td>",a,"<td>",b,"<td>",c,"<td>",d,"</tr>")
a,b,c,d = cur:fetch()
end
cgilua.put ("</table>\n")
cur:close()
conn:close()
env:close()

View File

@ -1,12 +0,0 @@
#!/bin/sh
echo "Content-Type: text/html"
echo
echo "<html><title>System Health</title><body>"
echo "<h1>System Health for '`/bin/hostname`'</h1>"
echo "<h2>Processes</h2><table border=\"2\">"
/bin/ps -ef | /bin/sed -e "s/\(.*\)/<tr><td>\1<\/td><\/tr>/"
echo "</table><h2>Free FileSystem Space</h2>"
echo "<table border=\"2\">"
/bin/df -h / | /bin/sed -e "s/\(.*\)/<tr><td>\1<\/td><\/tr>/"
echo "</table></body></html>"

View File

@ -1,6 +0,0 @@
#!/bin/php
<?
phpinfo();
?>