├── test
├── .leading.dot.txt
├── hello.txt
├── ssi8.shtml
├── ssi9.shtml
├── bad2.cgi
├── dir with spaces
│ └── hello.cgi
├── hello.cgi
├── ssi3.shtml
├── ssi4.shtml
├── sh.cgi
├── ssi7.shtml
├── ssi1.shtml
├── ssi2.shtml
├── ssi5.shtml
├── ssi6.shtml
├── bad.cgi
├── passfile
├── x.php
├── timeout.cgi
├── all_build_flags.pl
├── env.cgi
├── page.lp
├── exploit.pl
└── embed.c
├── examples
├── html
│ ├── logo.png
│ ├── favicon.ico
│ ├── login.html
│ ├── index.html
│ ├── style.css
│ └── main.js
├── lua_dll.c
├── Makefile
├── lua
│ └── prime_numbers.lp
├── websocket.c
├── websocket_html_root
│ └── index.html
├── hello.c
├── upload.c
├── post.c
└── ssl_cert.pem
├── lua-5.2.1
├── doc
│ ├── logo.gif
│ ├── osi-certified-72x60.png
│ ├── manual.css
│ ├── lua.css
│ ├── lua.1
│ └── luac.1
├── README
├── src
│ ├── lua.hpp
│ ├── lapi.h
│ ├── lundump.h
│ ├── lfunc.h
│ ├── ldebug.h
│ ├── lualib.h
│ ├── ltm.h
│ ├── ltable.h
│ ├── lstring.h
│ ├── lvm.h
│ ├── ldo.h
│ ├── lzio.h
│ ├── lmem.h
│ ├── lzio.c
│ ├── linit.c
│ ├── ltm.c
│ ├── lctype.h
│ ├── llex.h
│ ├── lctype.c
│ ├── lmem.c
│ ├── lcode.h
│ ├── lopcodes.c
│ ├── lparser.h
│ ├── ldump.c
│ ├── lcorolib.c
│ ├── lfunc.c
│ ├── lbitlib.c
│ ├── lstring.c
│ ├── lgc.h
│ ├── lundump.c
│ ├── Makefile
│ ├── lmathlib.c
│ ├── lauxlib.h
│ ├── lstate.h
│ ├── llimits.h
│ ├── ltablib.c
│ ├── lstate.c
│ └── lobject.c
└── Makefile
├── LICENSE
├── README.md
└── Makefile
/test/.leading.dot.txt:
--------------------------------------------------------------------------------
1 | abc123
2 |
--------------------------------------------------------------------------------
/test/hello.txt:
--------------------------------------------------------------------------------
1 | simple text file
2 |
--------------------------------------------------------------------------------
/test/ssi8.shtml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/test/ssi9.shtml:
--------------------------------------------------------------------------------
1 | ssi_begin
2 |
3 | ssi_end
4 |
--------------------------------------------------------------------------------
/examples/html/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mimoralea/mongoose/master/examples/html/logo.png
--------------------------------------------------------------------------------
/lua-5.2.1/doc/logo.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mimoralea/mongoose/master/lua-5.2.1/doc/logo.gif
--------------------------------------------------------------------------------
/examples/html/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mimoralea/mongoose/master/examples/html/favicon.ico
--------------------------------------------------------------------------------
/test/bad2.cgi:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env perl
2 |
3 | print "Status: 123 Please pass me to the client\r\n\r\n";
4 |
--------------------------------------------------------------------------------
/test/dir with spaces/hello.cgi:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env perl
2 |
3 | print "Content-Type: text/plain\n\nhello\n";
4 |
--------------------------------------------------------------------------------
/test/hello.cgi:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | echo "Content-Type: text/plain"
4 | echo
5 |
6 | echo $QUERY_STRING
7 |
--------------------------------------------------------------------------------
/test/ssi3.shtml:
--------------------------------------------------------------------------------
1 |
2 | ssi_begin
3 |
4 | ssi_end
5 |
6 |
--------------------------------------------------------------------------------
/test/ssi4.shtml:
--------------------------------------------------------------------------------
1 |
2 | ssi_begin
3 |
4 | ssi_end
5 |
6 |
--------------------------------------------------------------------------------
/test/sh.cgi:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | echo "Content-Type: text/plain"
4 | echo
5 |
6 | echo "This is shell script CGI."
7 |
--------------------------------------------------------------------------------
/test/ssi7.shtml:
--------------------------------------------------------------------------------
1 |
2 |
3 | ssi_begin
4 |
5 | ssi_end
6 |
7 |
--------------------------------------------------------------------------------
/test/ssi1.shtml:
--------------------------------------------------------------------------------
1 |
2 | ssi_begin
3 |
4 | ssi_end
5 |
6 |
--------------------------------------------------------------------------------
/test/ssi2.shtml:
--------------------------------------------------------------------------------
1 |
2 | ssi_begin
3 |
4 | ssi_end
5 |
6 |
--------------------------------------------------------------------------------
/test/ssi5.shtml:
--------------------------------------------------------------------------------
1 |
2 | ssi_begin
3 |
4 | ssi_end
5 |
6 |
--------------------------------------------------------------------------------
/test/ssi6.shtml:
--------------------------------------------------------------------------------
1 |
2 | ssi_begin
3 |
4 | ssi_end
5 |
6 |
--------------------------------------------------------------------------------
/test/bad.cgi:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | echo "echoing bad headers: server must report status 500"
4 | exec 1>&2
5 | echo shit!!!
6 |
--------------------------------------------------------------------------------
/lua-5.2.1/doc/osi-certified-72x60.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mimoralea/mongoose/master/lua-5.2.1/doc/osi-certified-72x60.png
--------------------------------------------------------------------------------
/test/passfile:
--------------------------------------------------------------------------------
1 | guest:mydomain.com:485264dcc977a1925370b89d516a1477
2 | Administrator:mydomain.com:e32daa3028eba04dc53e2d781e6fc983
3 |
4 |
--------------------------------------------------------------------------------
/lua-5.2.1/README:
--------------------------------------------------------------------------------
1 |
2 | This is Lua 5.2.1, released on 08 Jun 2012.
3 |
4 | For installation instructions, license details, and
5 | further information about Lua, see doc/readme.html.
6 |
7 |
--------------------------------------------------------------------------------
/test/x.php:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 | echo $_POST["x"]; ?>
8 |
9 |
10 |
--------------------------------------------------------------------------------
/lua-5.2.1/src/lua.hpp:
--------------------------------------------------------------------------------
1 | // lua.hpp
2 | // Lua header files for C++
3 | // <> not supplied automatically because Lua also compiles as C++
4 |
5 | extern "C" {
6 | #include "lua.h"
7 | #include "lualib.h"
8 | #include "lauxlib.h"
9 | }
10 |
--------------------------------------------------------------------------------
/test/timeout.cgi:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env perl
2 |
3 | # Make stdout unbuffered
4 | use FileHandle;
5 | STDOUT->autoflush(1);
6 |
7 | # This script outputs some content, then sleeps for 5 seconds, then exits.
8 | # Web server should return the content immediately after it is sent,
9 | # not waiting until the script exits.
10 | print "Content-Type: text/html\r\n\r\n";
11 | print "Some data";
12 | sleep 3;
13 |
--------------------------------------------------------------------------------
/examples/lua_dll.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | #include "lua.h"
4 | #include "lauxlib.h"
5 |
6 | static int smile(lua_State *L) {
7 | (void) L; // Unused
8 | printf("%s\n", ":-)");
9 | return 0;
10 | }
11 |
12 | int LUA_API luaopen_lua_dll(lua_State *L) {
13 | static const struct luaL_Reg api[] = {
14 | {"smile", smile},
15 | {NULL, NULL},
16 | };
17 | luaL_openlib(L, "lua_dll", api, 0);
18 | return 1;
19 | }
20 |
--------------------------------------------------------------------------------
/lua-5.2.1/doc/manual.css:
--------------------------------------------------------------------------------
1 | h3 code {
2 | font-family: inherit ;
3 | font-size: inherit ;
4 | }
5 |
6 | pre, code {
7 | font-size: 12pt ;
8 | }
9 |
10 | span.apii {
11 | float: right ;
12 | font-family: inherit ;
13 | font-style: normal ;
14 | font-size: small ;
15 | color: gray ;
16 | }
17 |
18 | p+h1, ul+h1 {
19 | padding-top: 0.4em ;
20 | padding-bottom: 0.4em ;
21 | padding-left: 30px ;
22 | margin-left: -30px ;
23 | background-color: #E0E0FF ;
24 | }
25 |
--------------------------------------------------------------------------------
/lua-5.2.1/src/lapi.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** $Id: lapi.h,v 2.7 2009/11/27 15:37:59 roberto Exp $
3 | ** Auxiliary functions from Lua API
4 | ** See Copyright Notice in lua.h
5 | */
6 |
7 | #ifndef lapi_h
8 | #define lapi_h
9 |
10 |
11 | #include "llimits.h"
12 | #include "lstate.h"
13 |
14 | #define api_incr_top(L) {L->top++; api_check(L, L->top <= L->ci->top, \
15 | "stack overflow");}
16 |
17 | #define adjustresults(L,nres) \
18 | { if ((nres) == LUA_MULTRET && L->ci->top < L->top) L->ci->top = L->top; }
19 |
20 | #define api_checknelems(L,n) api_check(L, (n) < (L->top - L->ci->func), \
21 | "not enough elements in the stack")
22 |
23 |
24 | #endif
25 |
--------------------------------------------------------------------------------
/lua-5.2.1/src/lundump.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** $Id: lundump.h,v 1.39 2012/05/08 13:53:33 roberto Exp $
3 | ** load precompiled Lua chunks
4 | ** See Copyright Notice in lua.h
5 | */
6 |
7 | #ifndef lundump_h
8 | #define lundump_h
9 |
10 | #include "lobject.h"
11 | #include "lzio.h"
12 |
13 | /* load one chunk; from lundump.c */
14 | LUAI_FUNC Closure* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char* name);
15 |
16 | /* make header; from lundump.c */
17 | LUAI_FUNC void luaU_header (lu_byte* h);
18 |
19 | /* dump one chunk; from ldump.c */
20 | LUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip);
21 |
22 | /* data to catch conversion errors */
23 | #define LUAC_TAIL "\x19\x93\r\n\x1a\n"
24 |
25 | /* size in bytes of header of binary files */
26 | #define LUAC_HEADERSIZE (sizeof(LUA_SIGNATURE)-sizeof(char)+2+6+sizeof(LUAC_TAIL)-sizeof(char))
27 |
28 | #endif
29 |
--------------------------------------------------------------------------------
/test/all_build_flags.pl:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env perl
2 |
3 | @flags = ("NO_POPEN", "NO_SSL", "NDEBUG", "DEBUG", "NO_CGI");
4 | my $num_flags = @flags;
5 |
6 | sub fail {
7 | print "FAILED: @_\n";
8 | exit 1;
9 | }
10 |
11 | my $platform = $ARGV[0] || "linux";
12 |
13 | for (my $i = 0; $i < 2 ** $num_flags; $i++) {
14 | my $bitmask = sprintf("%*.*b", $num_flags, $num_flags, $i);
15 | my @combination = ();
16 | for (my $j = 0; $j < $num_flags; $j++) {
17 | push @combination, $flags[$j] if substr($bitmask, $j, 1);
18 | }
19 | my $defines = join(" ", map { "-D$_" } @combination);
20 | my $cmd = "CFLAGS=\"$defines\" make clean $platform >/dev/null";
21 | system($cmd) == 0 or fail "build failed: $_";
22 | print "Build succeeded, flags: [$defines]\n";
23 | system("perl test/test.pl basic_tests >/dev/null") == 0
24 | or fail "basic tests";
25 | print "Basic tests: OK\n";
26 | }
27 |
28 | print "PASS: All builds passed!\n";
29 |
--------------------------------------------------------------------------------
/test/env.cgi:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env perl
2 |
3 | use Cwd;
4 | use CGI;
5 |
6 | use vars '%in';
7 | CGI::ReadParse();
8 |
9 | print "Content-Type: text/html\r\n\r\n";
10 |
11 | print "\n";
12 | foreach my $key (sort keys %ENV) {
13 | print "$key=$ENV{$key}\n";
14 | }
15 |
16 | print "\n";
17 |
18 | foreach my $key (sort keys %in) {
19 | print "$key=$in{$key}\n";
20 | }
21 |
22 | print "\n";
23 |
24 | print 'CURRENT_DIR=' . getcwd() . "\n";
25 | print "\n";
26 |
27 | my $stuff = <
29 | function set_val() {
30 | }
31 |
32 |
37 |
38 |
42 | EOP
43 |
44 | #system('some shit');
45 |
46 | print $stuff;
47 |
--------------------------------------------------------------------------------
/examples/Makefile:
--------------------------------------------------------------------------------
1 | CFLAGS= -W -Wall -I.. -pthread -g
2 |
3 | all:
4 | OS=`uname`; \
5 | test "$$OS" = Linux && LIBS="-ldl" ; \
6 | $(CC) $(CFLAGS) hello.c ../mongoose.c $$LIBS $(ADD) -o hello;
7 | $(CC) $(CFLAGS) upload.c ../mongoose.c $$LIBS $(ADD) -o upload;
8 | $(CC) $(CFLAGS) post.c ../mongoose.c $$LIBS $(ADD) -o post;
9 | $(CC) $(CFLAGS) -DUSE_WEBSOCKET websocket.c ../mongoose.c $$LIBS $(ADD) -o websocket;
10 | $(CC) $(CFLAGS) chat.c ../mongoose.c $$LIBS $(ADD) -o chat
11 |
12 |
13 | MSVC = e:/vc6
14 | CL = $(MSVC)/bin/cl
15 | CLFLAGS = /MD /TC /nologo $(DBG) /W3 /DNO_SSL \
16 | /I$(MSVC)/include /I.. /Dsnprintf=_snprintf \
17 | /link /incremental:no /libpath:$(MSVC)/lib /machine:IX86
18 |
19 | windows:
20 | $(CL) upload.c ../mongoose.c $(CLFLAGS)
21 | $(CL) hello.c ../mongoose.c $(CLFLAGS)
22 | $(CL) upload.c ../mongoose.c $(CLFLAGS)
23 | $(CL) post.c ../mongoose.c $(CLFLAGS)
24 | $(CL) post.c ../mongoose.c $(CLFLAGS)
25 | $(CL) /DUSE_WEBSOCKET websocket.c ../mongoose.c $(CLFLAGS)
26 |
27 | clean:
28 | rm -rf hello upload post websocket chat *.exe *.dSYM *.obj
29 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2004-2013 Sergey Lyubka
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy
4 | of this software and associated documentation files (the "Software"), to deal
5 | in the Software without restriction, including without limitation the rights
6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 | copies of the Software, and to permit persons to whom the Software is
8 | furnished to do so, subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in
11 | all copies or substantial portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 | THE SOFTWARE.
20 |
--------------------------------------------------------------------------------
/lua-5.2.1/src/lfunc.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** $Id: lfunc.h,v 2.8 2012/05/08 13:53:33 roberto Exp $
3 | ** Auxiliary functions to manipulate prototypes and closures
4 | ** See Copyright Notice in lua.h
5 | */
6 |
7 | #ifndef lfunc_h
8 | #define lfunc_h
9 |
10 |
11 | #include "lobject.h"
12 |
13 |
14 | #define sizeCclosure(n) (cast(int, sizeof(CClosure)) + \
15 | cast(int, sizeof(TValue)*((n)-1)))
16 |
17 | #define sizeLclosure(n) (cast(int, sizeof(LClosure)) + \
18 | cast(int, sizeof(TValue *)*((n)-1)))
19 |
20 |
21 | LUAI_FUNC Proto *luaF_newproto (lua_State *L);
22 | LUAI_FUNC Closure *luaF_newCclosure (lua_State *L, int nelems);
23 | LUAI_FUNC Closure *luaF_newLclosure (lua_State *L, int nelems);
24 | LUAI_FUNC UpVal *luaF_newupval (lua_State *L);
25 | LUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level);
26 | LUAI_FUNC void luaF_close (lua_State *L, StkId level);
27 | LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f);
28 | LUAI_FUNC void luaF_freeupval (lua_State *L, UpVal *uv);
29 | LUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number,
30 | int pc);
31 |
32 |
33 | #endif
34 |
--------------------------------------------------------------------------------
/lua-5.2.1/src/ldebug.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** $Id: ldebug.h,v 2.7 2011/10/07 20:45:19 roberto Exp $
3 | ** Auxiliary functions from Debug Interface module
4 | ** See Copyright Notice in lua.h
5 | */
6 |
7 | #ifndef ldebug_h
8 | #define ldebug_h
9 |
10 |
11 | #include "lstate.h"
12 |
13 |
14 | #define pcRel(pc, p) (cast(int, (pc) - (p)->code) - 1)
15 |
16 | #define getfuncline(f,pc) (((f)->lineinfo) ? (f)->lineinfo[pc] : 0)
17 |
18 | #define resethookcount(L) (L->hookcount = L->basehookcount)
19 |
20 | /* Active Lua function (given call info) */
21 | #define ci_func(ci) (clLvalue((ci)->func))
22 |
23 |
24 | LUAI_FUNC l_noret luaG_typeerror (lua_State *L, const TValue *o,
25 | const char *opname);
26 | LUAI_FUNC l_noret luaG_concaterror (lua_State *L, StkId p1, StkId p2);
27 | LUAI_FUNC l_noret luaG_aritherror (lua_State *L, const TValue *p1,
28 | const TValue *p2);
29 | LUAI_FUNC l_noret luaG_ordererror (lua_State *L, const TValue *p1,
30 | const TValue *p2);
31 | LUAI_FUNC l_noret luaG_runerror (lua_State *L, const char *fmt, ...);
32 | LUAI_FUNC l_noret luaG_errormsg (lua_State *L);
33 |
34 | #endif
35 |
--------------------------------------------------------------------------------
/lua-5.2.1/src/lualib.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** $Id: lualib.h,v 1.43 2011/12/08 12:11:37 roberto Exp $
3 | ** Lua standard libraries
4 | ** See Copyright Notice in lua.h
5 | */
6 |
7 |
8 | #ifndef lualib_h
9 | #define lualib_h
10 |
11 | #include "lua.h"
12 |
13 |
14 |
15 | LUAMOD_API int (luaopen_base) (lua_State *L);
16 |
17 | #define LUA_COLIBNAME "coroutine"
18 | LUAMOD_API int (luaopen_coroutine) (lua_State *L);
19 |
20 | #define LUA_TABLIBNAME "table"
21 | LUAMOD_API int (luaopen_table) (lua_State *L);
22 |
23 | #define LUA_IOLIBNAME "io"
24 | LUAMOD_API int (luaopen_io) (lua_State *L);
25 |
26 | #define LUA_OSLIBNAME "os"
27 | LUAMOD_API int (luaopen_os) (lua_State *L);
28 |
29 | #define LUA_STRLIBNAME "string"
30 | LUAMOD_API int (luaopen_string) (lua_State *L);
31 |
32 | #define LUA_BITLIBNAME "bit32"
33 | LUAMOD_API int (luaopen_bit32) (lua_State *L);
34 |
35 | #define LUA_MATHLIBNAME "math"
36 | LUAMOD_API int (luaopen_math) (lua_State *L);
37 |
38 | #define LUA_DBLIBNAME "debug"
39 | LUAMOD_API int (luaopen_debug) (lua_State *L);
40 |
41 | #define LUA_LOADLIBNAME "package"
42 | LUAMOD_API int (luaopen_package) (lua_State *L);
43 |
44 |
45 | /* open all previous libraries */
46 | LUALIB_API void (luaL_openlibs) (lua_State *L);
47 |
48 |
49 |
50 | #if !defined(lua_assert)
51 | #define lua_assert(x) ((void)0)
52 | #endif
53 |
54 |
55 | #endif
56 |
--------------------------------------------------------------------------------
/lua-5.2.1/src/ltm.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** $Id: ltm.h,v 2.11 2011/02/28 17:32:10 roberto Exp $
3 | ** Tag methods
4 | ** See Copyright Notice in lua.h
5 | */
6 |
7 | #ifndef ltm_h
8 | #define ltm_h
9 |
10 |
11 | #include "lobject.h"
12 |
13 |
14 | /*
15 | * WARNING: if you change the order of this enumeration,
16 | * grep "ORDER TM"
17 | */
18 | typedef enum {
19 | TM_INDEX,
20 | TM_NEWINDEX,
21 | TM_GC,
22 | TM_MODE,
23 | TM_LEN,
24 | TM_EQ, /* last tag method with `fast' access */
25 | TM_ADD,
26 | TM_SUB,
27 | TM_MUL,
28 | TM_DIV,
29 | TM_MOD,
30 | TM_POW,
31 | TM_UNM,
32 | TM_LT,
33 | TM_LE,
34 | TM_CONCAT,
35 | TM_CALL,
36 | TM_N /* number of elements in the enum */
37 | } TMS;
38 |
39 |
40 |
41 | #define gfasttm(g,et,e) ((et) == NULL ? NULL : \
42 | ((et)->flags & (1u<<(e))) ? NULL : luaT_gettm(et, e, (g)->tmname[e]))
43 |
44 | #define fasttm(l,et,e) gfasttm(G(l), et, e)
45 |
46 | #define ttypename(x) luaT_typenames_[(x) + 1]
47 | #define objtypename(x) ttypename(ttypenv(x))
48 |
49 | LUAI_DDEC const char *const luaT_typenames_[LUA_TOTALTAGS];
50 |
51 |
52 | LUAI_FUNC const TValue *luaT_gettm (Table *events, TMS event, TString *ename);
53 | LUAI_FUNC const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o,
54 | TMS event);
55 | LUAI_FUNC void luaT_init (lua_State *L);
56 |
57 | #endif
58 |
--------------------------------------------------------------------------------
/lua-5.2.1/src/ltable.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** $Id: ltable.h,v 2.16 2011/08/17 20:26:47 roberto Exp $
3 | ** Lua tables (hash)
4 | ** See Copyright Notice in lua.h
5 | */
6 |
7 | #ifndef ltable_h
8 | #define ltable_h
9 |
10 | #include "lobject.h"
11 |
12 |
13 | #define gnode(t,i) (&(t)->node[i])
14 | #define gkey(n) (&(n)->i_key.tvk)
15 | #define gval(n) (&(n)->i_val)
16 | #define gnext(n) ((n)->i_key.nk.next)
17 |
18 | #define invalidateTMcache(t) ((t)->flags = 0)
19 |
20 |
21 | LUAI_FUNC const TValue *luaH_getint (Table *t, int key);
22 | LUAI_FUNC void luaH_setint (lua_State *L, Table *t, int key, TValue *value);
23 | LUAI_FUNC const TValue *luaH_getstr (Table *t, TString *key);
24 | LUAI_FUNC const TValue *luaH_get (Table *t, const TValue *key);
25 | LUAI_FUNC TValue *luaH_newkey (lua_State *L, Table *t, const TValue *key);
26 | LUAI_FUNC TValue *luaH_set (lua_State *L, Table *t, const TValue *key);
27 | LUAI_FUNC Table *luaH_new (lua_State *L);
28 | LUAI_FUNC void luaH_resize (lua_State *L, Table *t, int nasize, int nhsize);
29 | LUAI_FUNC void luaH_resizearray (lua_State *L, Table *t, int nasize);
30 | LUAI_FUNC void luaH_free (lua_State *L, Table *t);
31 | LUAI_FUNC int luaH_next (lua_State *L, Table *t, StkId key);
32 | LUAI_FUNC int luaH_getn (Table *t);
33 |
34 |
35 | #if defined(LUA_DEBUG)
36 | LUAI_FUNC Node *luaH_mainposition (const Table *t, const TValue *key);
37 | LUAI_FUNC int luaH_isdummy (Node *n);
38 | #endif
39 |
40 |
41 | #endif
42 |
--------------------------------------------------------------------------------
/examples/lua/prime_numbers.lp:
--------------------------------------------------------------------------------
1 | HTTP/1.0 200 OK
2 | Content-Type: text/html
3 |
4 |
5 | Prime numbers from 0 to 100, calculated by Lua:
6 |
7 | function is_prime(n)
8 | if n <= 0 then return false end
9 | if n <= 2 then return true end
10 | if (n % 2 == 0) then return false end
11 | for i = 3, n / 2, 2 do
12 | if (n % i == 0) then return false end
13 | end
14 | return true
15 | end
16 |
17 | for i = 1, 100 do
18 | if is_prime(i) then mg.write('' .. i .. ' ') end
19 | end
20 |
21 | ?>
22 |
23 | Reading POST data from Lua (click submit):
24 |
25 |
26 |
27 | POST data: [
28 | local post_data = ''
29 | if mg.request_info.request_method == 'POST' then
30 | post_data = mg.read()
31 | end
32 | mg.write(post_data)
33 | ?>]
34 | request method: [ mg.write(mg.request_info.request_method) ?>]
35 | IP/port: [ mg.write(mg.request_info.remote_ip, ':',
36 | mg.request_info.remote_port) ?>]
37 | URI: [ mg.write(mg.request_info.uri) ?>]
38 | HTTP version [ mg.write(mg.request_info.http_version) ?>]
39 | HEADERS:
40 |
41 | for name, value in pairs(mg.request_info.http_headers) do
42 | mg.write(name, ':', value, '\n')
43 | end
44 | ?>
45 |
46 |
47 |
--------------------------------------------------------------------------------
/lua-5.2.1/src/lstring.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** $Id: lstring.h,v 1.49 2012/02/01 21:57:15 roberto Exp $
3 | ** String table (keep all strings handled by Lua)
4 | ** See Copyright Notice in lua.h
5 | */
6 |
7 | #ifndef lstring_h
8 | #define lstring_h
9 |
10 | #include "lgc.h"
11 | #include "lobject.h"
12 | #include "lstate.h"
13 |
14 |
15 | #define sizestring(s) (sizeof(union TString)+((s)->len+1)*sizeof(char))
16 |
17 | #define sizeudata(u) (sizeof(union Udata)+(u)->len)
18 |
19 | #define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \
20 | (sizeof(s)/sizeof(char))-1))
21 |
22 | #define luaS_fix(s) l_setbit((s)->tsv.marked, FIXEDBIT)
23 |
24 |
25 | /*
26 | ** test whether a string is a reserved word
27 | */
28 | #define isreserved(s) ((s)->tsv.tt == LUA_TSHRSTR && (s)->tsv.extra > 0)
29 |
30 |
31 | /*
32 | ** equality for short strings, which are always internalized
33 | */
34 | #define eqshrstr(a,b) check_exp((a)->tsv.tt == LUA_TSHRSTR, (a) == (b))
35 |
36 |
37 | LUAI_FUNC unsigned int luaS_hash (const char *str, size_t l, unsigned int seed);
38 | LUAI_FUNC int luaS_eqlngstr (TString *a, TString *b);
39 | LUAI_FUNC int luaS_eqstr (TString *a, TString *b);
40 | LUAI_FUNC void luaS_resize (lua_State *L, int newsize);
41 | LUAI_FUNC Udata *luaS_newudata (lua_State *L, size_t s, Table *e);
42 | LUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l);
43 | LUAI_FUNC TString *luaS_new (lua_State *L, const char *str);
44 |
45 |
46 | #endif
47 |
--------------------------------------------------------------------------------
/examples/websocket.c:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2004-2012 Sergey Lyubka
2 | // This file is a part of mongoose project, http://github.com/valenok/mongoose
3 |
4 | #include
5 | #include
6 | #include "mongoose.h"
7 |
8 | static void websocket_ready_handler(struct mg_connection *conn) {
9 | static const char *message = "server ready";
10 | mg_websocket_write(conn, WEBSOCKET_OPCODE_TEXT, message, strlen(message));
11 | }
12 |
13 | // Arguments:
14 | // flags: first byte of websocket frame, see websocket RFC,
15 | // http://tools.ietf.org/html/rfc6455, section 5.2
16 | // data, data_len: payload data. Mask, if any, is already applied.
17 | static int websocket_data_handler(struct mg_connection *conn, int flags,
18 | char *data, size_t data_len) {
19 | (void) flags; // Unused
20 | mg_websocket_write(conn, WEBSOCKET_OPCODE_TEXT, data, data_len);
21 |
22 | // Returning zero means stoping websocket conversation.
23 | // Close the conversation if client has sent us "exit" string.
24 | return memcmp(data, "exit", 4);
25 | }
26 |
27 | int main(void) {
28 | struct mg_context *ctx;
29 | struct mg_callbacks callbacks;
30 | const char *options[] = {
31 | "listening_ports", "8080",
32 | "document_root", "websocket_html_root",
33 | NULL
34 | };
35 |
36 | memset(&callbacks, 0, sizeof(callbacks));
37 | callbacks.websocket_ready = websocket_ready_handler;
38 | callbacks.websocket_data = websocket_data_handler;
39 | ctx = mg_start(&callbacks, NULL, options);
40 | getchar(); // Wait until user hits "enter"
41 | mg_stop(ctx);
42 |
43 | return 0;
44 | }
45 |
--------------------------------------------------------------------------------
/examples/websocket_html_root/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | WebSocket Test
4 |
33 |
34 | Mongoose WebSocket Test
35 |
36 |
37 | This page code creates websocket to the URI "/foo",
38 | sends a message to it, waits for the reply, then sends an "exit" message.
39 | Server must echo all messages back, and terminate the conversation after
40 | receiving the "exit" message.
41 |
42 |
43 |
44 |