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

added kepler/lua to the build

git-svn-id: svn://svn.code.sf.net/p/axtls/code/trunk@96 9a5d90b5-6617-0410-8a86-bb477d3ed2e3
This commit is contained in:
cameronrich 2007-05-22 12:07:24 +00:00
parent c511f2986e
commit 80b24c3c41
6 changed files with 148 additions and 28 deletions

View File

@ -71,15 +71,31 @@ config CONFIG_HTTP_CGI_EXTENSIONS
This is a comma separated list - e.g. ".php,.pl" etc
config CONFIG_HTTP_LUA_LAUNCHER
string "Lua's CGI Launcher"
default "/usr/local/bin/cgi" if CONFIG_PLATFORM_LINUX
default "/usr/local/bin/cgi.exe" if CONFIG_PLATFORM_CYGWIN
config CONFIG_HTTP_ENABLE_LUA
bool "Enable Lua"
default y
depends on CONFIG_HTTP_HAS_CGI
help
Lua is a powerful, fast, light-weight, embeddable scripting language.
See http://www.lua.org for details.
config CONFIG_HTTP_LUA_PREFIX
string "Lua's Installation Prefix"
default "/usr/local"
depends on CONFIG_HTTP_ENABLE_LUA
help
Lua has a special launcher application to run kepler/lua scripts.
".lua and .lp" extensions must be defined in CONFIG_HTTP_CGI_EXTENSIONS.
The location of Lua's installation prefix. This is also necessary for
Lua's cgi launcher application.
config CONFIG_HTTP_BUILD_LUA
bool "Build Lua"
default n
depends on CONFIG_HTTP_ENABLE_LUA
help
Build Lua and install in /usr/local/bin
endmenu
config CONFIG_HTTP_DIRECTORIES

View File

@ -16,7 +16,7 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
all : web_server
all : web_server lua
include ../config/.config
include ../config/makefile.conf
@ -39,6 +39,17 @@ endif
CFLAGS += -I../ssl
ifdef CONFIG_HTTP_BUILD_LUA
lua: kepler-1.1
kepler-1.1:
@tar xvfz kepler-1.1-snapshot-20070420-1741.tar.gz
@cat kepler.patch | patch -p0
cd kepler-1.1; ./configure --prefix=$(CONFIG_HTTP_LUA_PREFIX) --launcher=cgi --lua-suffix= ; make install
else
lua:
endif
else # win32 build
TARGET=../$(STAGE)/axhttpd.exe
TARGET2=../$(STAGE)/htpasswd.exe
@ -100,4 +111,5 @@ endif # CONFIG_AXHTTPD
clean::
-@rm -f $(TARGET)*
-@rm -fr kepler-1.1

View File

@ -75,12 +75,15 @@ struct connstruct
#if defined(CONFIG_HTTP_HAS_CGI)
uint8_t is_cgi;
#ifdef CONFIG_HTTP_ENABLE_LUA
uint8_t is_lua;
#endif
int content_length;
char remote_addr[MAXREQUESTLENGTH];
char uri_request[MAXREQUESTLENGTH];
char uri_path_info[MAXREQUESTLENGTH];
char uri_query[MAXREQUESTLENGTH];
char cookie[MAXREQUESTLENGTH];
#endif
#if defined(CONFIG_HTTP_HAS_AUTHORIZATION)
char authorization[MAXREQUESTLENGTH];

Binary file not shown.

64
httpd/kepler.patch Normal file
View File

@ -0,0 +1,64 @@
diff -Naur kepler-1.1/launcher/cgi/Makefile kepler-1.1.new/launcher/cgi/Makefile
--- kepler-1.1/launcher/cgi/Makefile 2007-04-21 06:41:49.000000000 +1000
+++ kepler-1.1.new/launcher/cgi/Makefile 2007-05-16 22:13:38.750000000 +1000
@@ -16,7 +16,7 @@
$T: $(CH) $(OBJS)
- $(CC) $(CFLAGS) -o $@ $(OBJS) $(LIBS)
+ $(CC) $(CFLAGS) -o $@ $(OBJS) $(LIBS) -L../../lua-5.1.2/src -llua
build: $T
diff -Naur kepler-1.1/luafilesystem/Makefile kepler-1.1.new/luafilesystem/Makefile
--- kepler-1.1/luafilesystem/Makefile 2007-04-21 06:41:49.000000000 +1000
+++ kepler-1.1.new/luafilesystem/Makefile 2007-05-16 22:06:25.546875000 +1000
@@ -12,7 +12,7 @@
lib: src/$(LIBNAME)
src/$(LIBNAME): $(OBJS)
- export MACOSX_DEPLOYMENT_TARGET="10.3"; $(CC) $(CFLAGS) $(LIB_OPTION) -o src/$(LIBNAME) $(OBJS)
+ export MACOSX_DEPLOYMENT_TARGET="10.3"; $(CC) $(CFLAGS) $(LIB_OPTION) -o src/$(LIBNAME) $(OBJS) -L../lua-5.1.2/src -llua
install: src/$(LIBNAME)
mkdir -p $(LUA_LIBDIR)
diff -Naur kepler-1.1/luasocket-2.0.1/src/makefile kepler-1.1.new/luasocket-2.0.1/src/makefile
--- kepler-1.1/luasocket-2.0.1/src/makefile 2007-04-21 06:41:49.000000000 +1000
+++ kepler-1.1.new/luasocket-2.0.1/src/makefile 2007-05-16 22:36:37.125000000 +1000
@@ -47,10 +47,10 @@
all: $(SOCKET_SO) $(MIME_SO)
$(SOCKET_SO): $(SOCKET_OBJS)
- $(LD) $(LDFLAGS) -o $@ $(SOCKET_OBJS)
+ $(LD) $(LDFLAGS) -o $@ $(SOCKET_OBJS) -L../../lua-5.1.2/src -llua
$(MIME_SO): $(MIME_OBJS)
- $(LD) $(LDFLAGS) -o $@ $(MIME_OBJS)
+ $(LD) $(LDFLAGS) -o $@ $(MIME_OBJS) -L../../lua-5.1.2/src -llua
$(UNIX_SO): $(UNIX_OBJS)
$(LD) $(LDFLAGS) -o $@ $(UNIX_OBJS)
diff -Naur kepler-1.1/md5/Makefile kepler-1.1.new/md5/Makefile
--- kepler-1.1/md5/Makefile 2007-04-21 06:41:49.000000000 +1000
+++ kepler-1.1.new/md5/Makefile 2007-05-16 22:06:44.593750000 +1000
@@ -15,7 +15,7 @@
src/$(LIBNAME) : $(OBJS)
- export MACOSX_DEPLOYMENT_TARGET="10.3"; $(CC) $(CFLAGS) $(LIB_OPTION) -o src/$(LIBNAME) $(OBJS)
+ export MACOSX_DEPLOYMENT_TARGET="10.3"; $(CC) $(CFLAGS) $(LIB_OPTION) -o src/$(LIBNAME) $(OBJS) -L../lua-5.1.2/src -llua
$(COMPAT_DIR)/compat-5.1.o: $(COMPAT_DIR)/compat-5.1.c
$(CC) -c $(CFLAGS) -o $@ $(COMPAT_DIR)/compat-5.1.c
diff -Naur kepler-1.1/rings/Makefile kepler-1.1.new/rings/Makefile
--- kepler-1.1/rings/Makefile 2007-04-21 06:41:49.000000000 +1000
+++ kepler-1.1.new/rings/Makefile 2007-05-16 22:05:28.765625000 +1000
@@ -10,7 +10,7 @@
OBJS= src/rings.o
src/$(LIBNAME) : $(OBJS)
- export MACOSX_DEPLOYMENT_TARGET="10.3"; $(CC) $(CFLAGS) $(LIB_OPTION) -o src/$(LIBNAME) $(OBJS)
+ export MACOSX_DEPLOYMENT_TARGET="10.3"; $(CC) $(CFLAGS) $(LIB_OPTION) -o src/$(LIBNAME) $(OBJS) -L../lua-5.1.2/src -llua
install:
mkdir -p $(LUA_LIBDIR)

View File

@ -26,6 +26,8 @@
#include <string.h>
#include "axhttp.h"
#define HTTP_VERSION "HTTP/1.1"
static const char * index_file = "index.html";
static int special_read(struct connstruct *cn, void *buf, size_t count);
@ -125,6 +127,10 @@ static int procheadelem(struct connstruct *cn, char *buf)
{
sscanf(value, "%d", &cn->content_length);
}
else if (strcmp(buf, "Cookie:") == 0)
{
my_strncpy(cn->cookie, value, MAXREQUESTLENGTH);
}
#endif
return 1;
@ -138,8 +144,8 @@ static void procdirlisting(struct connstruct *cn)
if (cn->reqtype == TYPE_HEAD)
{
snprintf(buf, sizeof(buf),
"HTTP/1.1 200 OK\nContent-Type: text/html\n\n");
snprintf(buf, sizeof(buf), HTTP_VERSION
" 200 OK\nContent-Type: text/html\n\n");
write(cn->networkdesc, buf, strlen(buf));
removeconnection(cn);
return;
@ -164,7 +170,8 @@ static void procdirlisting(struct connstruct *cn)
}
#endif
snprintf(buf, sizeof(buf), "HTTP/1.1 200 OK\nContent-Type: text/html\n\n"
snprintf(buf, sizeof(buf), HTTP_VERSION
" 200 OK\nContent-Type: text/html\n\n"
"<html><body>\n<title>Directory Listing</title>\n"
"<h3>Directory listing of %s://%s%s</h3><br />\n",
cn->is_ssl ? "https" : "http", cn->server_name, cn->filereq);
@ -347,7 +354,7 @@ void procsendhead(struct connstruct *cn)
if ((stbuf.st_mode & S_IEXEC) == 0 || isdir(cn->actualfile))
{
/* A non-executable file, or directory? */
send_error(cn, 404);
send_error(cn, 403);
}
else
proccgi(cn);
@ -388,7 +395,7 @@ void procsendhead(struct connstruct *cn)
if (cn->if_modified_since != -1 && (cn->if_modified_since == 0 ||
cn->if_modified_since >= stbuf.st_mtime))
{
snprintf(buf, sizeof(buf), "HTTP/1.1 304 Not Modified\nServer: "
snprintf(buf, sizeof(buf), HTTP_VERSION" 304 Not Modified\nServer: "
"%s\nDate: %s\n", server_version, date);
special_write(cn, buf, strlen(buf));
cn->state = STATE_WANT_TO_READ_HEAD;
@ -414,7 +421,7 @@ void procsendhead(struct connstruct *cn)
return;
}
snprintf(buf, sizeof(buf), "HTTP/1.1 200 OK\nServer: %s\n"
snprintf(buf, sizeof(buf), HTTP_VERSION" 200 OK\nServer: %s\n"
"Content-Type: %s\nContent-Length: %ld\n"
"Date: %sLast-Modified: %s\n", server_version,
getmimetype(cn->actualfile), (long) stbuf.st_size,
@ -491,14 +498,15 @@ void procsendfile(struct connstruct *cn)
}
#if defined(CONFIG_HTTP_HAS_CGI)
#define CGI_ARG_SIZE 14
/* Should this be a bit more dynamic? It would mean more calls to malloc etc */
#define CGI_ARG_SIZE 16
static void proccgi(struct connstruct *cn)
{
int tpipe[2];
char *myargs[2];
char cgienv[CGI_ARG_SIZE][MAXREQUESTLENGTH];
char * cgiptr[CGI_ARG_SIZE+1];
char * cgiptr[CGI_ARG_SIZE+4];
const char *type = "HEAD";
int cgi_index = 0, i;
#ifdef WIN32
@ -506,7 +514,7 @@ static void proccgi(struct connstruct *cn)
#endif
snprintf(cgienv[0], MAXREQUESTLENGTH,
"HTTP/1.1 200 OK\nServer: %s\n%s",
HTTP_VERSION" 200 OK\nServer: %s\n%s",
server_version, (cn->reqtype == TYPE_HEAD) ? "\n" : "");
special_write(cn, cgienv[0], strlen(cgienv[0]));
@ -574,6 +582,12 @@ static void proccgi(struct connstruct *cn)
"QUERY_STRING=%s", cn->uri_query);
snprintf(cgienv[cgi_index++], MAXREQUESTLENGTH,
"REMOTE_ADDR=%s", cn->remote_addr);
snprintf(cgienv[cgi_index++], MAXREQUESTLENGTH,
"HTTP_COOKIE=%s", cn->cookie); /* note: small size */
#if defined(CONFIG_HTTP_HAS_AUTHORIZATION)
snprintf(cgienv[cgi_index++], MAXREQUESTLENGTH,
"REMOTE_USER=%s", cn->authorization);
#endif
switch (cn->reqtype)
{
@ -585,7 +599,7 @@ static void proccgi(struct connstruct *cn)
type = "POST";
sprintf(cgienv[cgi_index++],
"CONTENT_LENGTH=%d", cn->content_length);
strcpy(cgienv[cgi_index++],
strcpy(cgienv[cgi_index++], /* hard-code? */
"CONTENT_TYPE=application/x-www-form-urlencoded");
break;
}
@ -610,7 +624,11 @@ static void proccgi(struct connstruct *cn)
for (i = 0; i < cgi_index; i++)
cgiptr[i] = cgienv[i];
cgiptr[i++] = "AUTH_TYPE=Basic";
cgiptr[i++] = "GATEWAY_INTERFACE=CGI/1.1";
cgiptr[i++] = "SERVER_PROTOCOL="HTTP_VERSION;
cgiptr[i] = NULL;
execve(myargs[0], myargs, cgiptr);
printf("Content-type: text/plain\n\nshouldn't get here\n");
#endif
@ -626,13 +644,14 @@ static char * cgi_filetype_match(struct connstruct *cn, const char *fn)
if ((t = strstr(fn, tp->ext)) != NULL)
{
t += strlen(tp->ext);
if (*t == '/' || *t == '\0')
{
#ifdef CONFIG_HTTP_ENABLE_LUA
if (strcmp(tp->ext, ".lua") == 0 || strcmp(tp->ext, ".lp") == 0)
cn->is_lua = 1;
#endif
return t;
}
@ -652,7 +671,9 @@ static void decode_path_info(struct connstruct *cn, char *path_info)
char *cgi_delim;
cn->is_cgi = 0;
#ifdef CONFIG_HTTP_ENABLE_LUA
cn->is_lua = 0;
#endif
*cn->uri_request = '\0';
*cn->uri_path_info = '\0';
*cn->uri_query = '\0';
@ -739,15 +760,6 @@ static void buildactualfile(struct connstruct *cn)
{
char *cp;
#if defined(CONFIG_HTTP_HAS_CGI)
/* use the lua launcher if this file has a lua extension */
if (cn->is_lua)
{
strcpy(cn->actualfile, CONFIG_HTTP_LUA_LAUNCHER);
return;
}
#endif
#ifdef CONFIG_HTTP_USE_CHROOT
snprintf(cn->actualfile, MAXREQUESTLENGTH, "%s", cn->filereq);
#else
@ -794,6 +806,19 @@ static void buildactualfile(struct connstruct *cn)
*cp = 0;
}
#endif
#if defined(CONFIG_HTTP_ENABLE_LUA)
/*
* Use the lua launcher if this file has a lua extension. Put this at the
* end as we need the directory name.
*/
if (cn->is_lua)
#ifdef CONFIG_PLATFORM_CYGWIN
sprintf(cn->actualfile, "%s/bin/cgi.exe", CONFIG_HTTP_LUA_PREFIX);
#else
sprintf(cn->actualfile, "%s/bin/cgi", CONFIG_HTTP_LUA_PREFIX);
#endif
#endif
}
static int sanitizefile(const char *buf)
@ -851,7 +876,7 @@ static void send_authenticate(struct connstruct *cn, const char *realm)
{
char buf[1024];
snprintf(buf, sizeof(buf), "HTTP/1.1 401 Unauthorized\n"
snprintf(buf, sizeof(buf), HTTP_VERSION" 401 Unauthorized\n"
"WWW-Authenticate: Basic\n"
"realm=\"%s\"\n", realm);
special_write(cn, buf, strlen(buf));