From 690eff4fa2ea03c5965dcaf52b49165acff565cb Mon Sep 17 00:00:00 2001 From: Jay Date: Mon, 25 Feb 2013 22:17:46 +0800 Subject: [PATCH 1/9] Fix bugs about range request and explorer crashes 1. fix a bug that when header contains "Range: 100-", the range request support will fail 2. (windows) fix a bug that when explorer.exe crashes due to some reason, the tray icon will disappear. --- main.c | 5 +++++ mongoose.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/main.c b/main.c index 4993b82b..7f008b02 100644 --- a/main.c +++ b/main.c @@ -690,6 +690,7 @@ static LRESULT CALLBACK WindowProc(HWND hWnd, UINT msg, WPARAM wParam, char buf[200], *service_argv[] = {__argv[0], NULL}; POINT pt; HMENU hMenu; + static UINT s_uTaskbarRestart; // for taskbar creation switch (msg) { case WM_CREATE: @@ -700,6 +701,7 @@ static LRESULT CALLBACK WindowProc(HWND hWnd, UINT msg, WPARAM wParam, exit(EXIT_SUCCESS); } else { start_mongoose(__argc, __argv); + s_uTaskbarRestart = RegisterWindowMessage(TEXT("TaskbarCreated")); } break; case WM_COMMAND: @@ -757,6 +759,9 @@ static LRESULT CALLBACK WindowProc(HWND hWnd, UINT msg, WPARAM wParam, Shell_NotifyIcon(NIM_DELETE, &TrayIcon); PostQuitMessage(0); return 0; // We've just sent our own quit message, with proper hwnd. + default: + if (msg==s_uTaskbarRestart) + Shell_NotifyIcon(NIM_ADD, &TrayIcon); } return DefWindowProc(hWnd, msg, wParam, lParam); diff --git a/mongoose.c b/mongoose.c index 7399c5ca..ce4edf0c 100644 --- a/mongoose.c +++ b/mongoose.c @@ -2786,7 +2786,7 @@ static void handle_file_request(struct mg_connection *conn, const char *path, r1 = r2 = 0; hdr = mg_get_header(conn, "Range"); if (hdr != NULL && (n = parse_range_header(hdr, &r1, &r2)) > 0 && - r1 >= 0 && r2 > 0) { + r1 >= 0 && r2 >= 0) { conn->status_code = 206; cl = n == 2 ? (r2 > cl ? cl : r2) - r1 + 1: cl - r1; mg_snprintf(conn, range, sizeof(range), From eb1fdf56e6573cd4fa280b452d8982666bbb0e60 Mon Sep 17 00:00:00 2001 From: Sergey Lyubka Date: Tue, 26 Feb 2013 11:47:46 +0100 Subject: [PATCH 2/9] Updated readme --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index e868c332..b5ff7863 100644 --- a/README.md +++ b/README.md @@ -54,9 +54,9 @@ to all who already did so: T.Barmann, D.Hughes, J.C.Sloan, R.Romeo, L.E.Spencer, S.Kotay, R.M.Shorter, W.Mar, J.Wilander and 7 others. Appreciated guys, you keep my brains going! Cash is also welcome indeed. Press [](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=DGZ2FMP95TAL6) -button to donate. Donation progress: 249/1000 € +button to donate. Donation progress: 259/1000 € (thanks to O.M.Vilhunen, C.Radik, G.Woodcock, M.Szczepkowski, Eternal Lands Development Team, T.Tollet, C.Tangerino, G.Karsai, A.Bourgett, -C.Blakemore) +C.Blakemore, D.Fonaryov) -![Progress](http://chart.googleapis.com/chart?chxr=0,0,1000&chxt=x&chbh=30,0,0&chs=300x35&cht=bhs&chco=90c0f0&chd=t:24.9) +![Progress](http://chart.googleapis.com/chart?chxr=0,0,1000&chxt=x&chbh=30,0,0&chs=300x35&cht=bhs&chco=90c0f0&chd=t:25.9) From fc9a9593d2852be28eebac9f04c2f44e799e5413 Mon Sep 17 00:00:00 2001 From: Sergey Lyubka Date: Wed, 27 Feb 2013 10:44:42 +0000 Subject: [PATCH 3/9] Added sqlite to linux_lua target --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 9990aca6..4fcb4cff 100644 --- a/Makefile +++ b/Makefile @@ -76,7 +76,7 @@ all: # To build with lua, make sure you have Lua unpacked into lua-5.2.1 directory linux_lua: - $(CC) mongoose.c main.c $(LUA_SOURCES) -DUSE_LUA -I$(LUA) -o $(PROG) -ldl $(CFLAGS) + $(CC) mongoose.c main.c build/lsqlite3.c build/sqlite3.c $(LUA_SOURCES) -DUSE_LUA -DUSE_LUA_SQLITE3 -DLUA_COMPAT_ALL -I$(LUA) -o $(PROG) -ldl $(CFLAGS) # Make sure that the compiler flags come last in the compilation string. # If not so, this can break some on some Linux distros which use From a58bb71c19fcb8c533f14cf16d2f4bb25d4fcf4c Mon Sep 17 00:00:00 2001 From: Sergey Lyubka Date: Wed, 27 Feb 2013 10:44:59 +0000 Subject: [PATCH 4/9] Added Lua section to the user manual --- UserManual.md | 44 ++++++++++++++++++++++++++++++++++++++++++++ test/page.lp | 9 +++++++++ 2 files changed, 53 insertions(+) diff --git a/UserManual.md b/UserManual.md index b4c6aa4c..e2006a1e 100644 --- a/UserManual.md +++ b/UserManual.md @@ -279,6 +279,50 @@ must be for a file name only, not including directory name. Example: mongoose -hide_files_patterns secret.txt|even_more_secret.txt +# Lua Server Pages +Pre-built Windows and Mac mongoose binaries have built-in Lua Server Pages +support. That means it is possible to write PHP-like scripts with mongoose, +using Lua programming language instead of PHP. Lua is known +for it's speed and small size. Mongoose uses Lua version 5.2.1, the +documentation for it can be found at +[Lua 5.2 reference manual](http://www.lua.org/manual/5.2/). + +To create a Lua Page, make sure a file has `.lp` extension. For example, +let's say it is going to be `my_page.lp`. The contents of the file, just like +with PHP, is HTML with embedded Lua code. Lua code must be enclosed in +`` blocks, and can appear anywhere on the page. For example, to +print current weekday name, one can write: + +

+ Today is: + +

+ +Note that this example uses function `print()`, which prints data to the +web page. Using function `print()` is the way to generate web content from +inside Lua code. In addition to `print()`, all standard library functions +are accessible from the Lua code (please check reference manual for details), +and also information about the request is available in `request_info` object, +like request method, all headers, etcetera. Please refer to +`struct mg_request_info` definition in +[mongoose.h](https://github.com/valenok/mongoose/blob/master/mongoose.h) +to see what kind of information is present in `request_info` object. Also, +[page.lp](https://github.com/valenok/mongoose/blob/master/test/page.lp) +contains some example code that uses `request_info`. + + +One substantial difference of mongoose's Lua Pages and PHP is that Mongoose +expects Lua page to output HTTP headers. Therefore, **at the very beginning of +every Lua Page must be a Lua block that outputs HTTP headers**, like this: + + + + ... the rest of the web page ... + +It is easy to do things like redirects, for example: + + + # Common Problems - PHP doesn't work - getting empty page, or 'File not found' error. The reason for that is wrong paths to the interpreter. Remember that with PHP, diff --git a/test/page.lp b/test/page.lp index 5024acb7..02be3382 100644 --- a/test/page.lp +++ b/test/page.lp @@ -2,6 +2,7 @@ -- Lua server pages have full control over the output, including HTTP -- headers they send to the client. Send HTTP headers: print('HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n') + ?>

This is an example Lua server page served by @@ -10,6 +11,14 @@ Mongoose has Lua, Sqlite, and other functionality built in the binary. This example page stores the request in the Sqlite database, and shows all requests done previously.

+

Today is +

HTTP headers:
+ ') + end + ?> +

 
Date: Wed, 27 Feb 2013 10:49:31 +0000
Subject: [PATCH 5/9] Updated Lua section in user manual

---
 UserManual.md | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/UserManual.md b/UserManual.md
index e2006a1e..1d4a0038 100644
--- a/UserManual.md
+++ b/UserManual.md
@@ -323,6 +323,11 @@ It is easy to do things like redirects, for example:
 
     
 
+To serve Lua Page, mongoose creates Lua context. That context is used for
+all Lua blocks within the page. That means, all Lua blocks on the same page
+share the same context. If one block defines a variable, for example, that
+variable is visible in the block that follows.
+
 # Common Problems
 - PHP doesn't work - getting empty page, or 'File not found' error. The
   reason for that is wrong paths to the interpreter. Remember that with PHP,

From 5ce1fc3c2abc8499d51c4b327ba167a93c4b2818 Mon Sep 17 00:00:00 2001
From: Mikhail Nikalyukin 
Date: Wed, 27 Feb 2013 13:02:39 +0200
Subject: [PATCH 6/9] add lua page example with the form submitting

---
 UserManual.md                 | 10 +++++++--
 examples/lua/prime_numbers.lp | 42 +++++++++++++++++++++++++++++++++++
 2 files changed, 50 insertions(+), 2 deletions(-)
 create mode 100644 examples/lua/prime_numbers.lp

diff --git a/UserManual.md b/UserManual.md
index e2006a1e..f69398b6 100644
--- a/UserManual.md
+++ b/UserManual.md
@@ -307,8 +307,9 @@ like request method, all headers, etcetera. Please refer to
 `struct mg_request_info` definition in
 [mongoose.h](https://github.com/valenok/mongoose/blob/master/mongoose.h)
 to see what kind of information is present in `request_info` object. Also,
-[page.lp](https://github.com/valenok/mongoose/blob/master/test/page.lp)
-contains some example code that uses `request_info`.
+[page.lp](https://github.com/valenok/mongoose/blob/master/test/page.lp) and
+[prime_numbers.lp]()https://github.com/valenok/mongoose/blob/master/examples/lua/prime_numbers.lp
+contains some example code that uses `request_info` and other functions(form submitting for example).
 
 
 One substantial difference of mongoose's Lua Pages and PHP is that Mongoose
@@ -323,6 +324,11 @@ It is easy to do things like redirects, for example:
 
     
 
+To serve Lua Page, mongoose creates Lua context. That context is used for
+all Lua blocks within the page. That means, all Lua blocks on the same page
+share the same context. If one block defines a variable, for example, that
+variable is visible in the block that follows.
+
 # Common Problems
 - PHP doesn't work - getting empty page, or 'File not found' error. The
   reason for that is wrong paths to the interpreter. Remember that with PHP,
diff --git a/examples/lua/prime_numbers.lp b/examples/lua/prime_numbers.lp
new file mode 100644
index 00000000..b3edc129
--- /dev/null
+++ b/examples/lua/prime_numbers.lp
@@ -0,0 +1,42 @@
+
+
+
+  

Prime numbers from 0 to 100, calculated by Lua:

+ ' .. i .. ' ') end + end + + ?> + +

Reading POST data from Lua (click submit):

+
+ +
+   POST data: []
+   request method: []
+   IP/port: []
+   URI: []
+   HTTP version []
+   HEADERS:
+   
+
+ From cd1707034c5f741230ba492c8011df001076cbff Mon Sep 17 00:00:00 2001 From: Mikhail Nikalyukin Date: Wed, 27 Feb 2013 13:04:08 +0200 Subject: [PATCH 7/9] update README.md --- UserManual.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UserManual.md b/UserManual.md index f69398b6..666e49fe 100644 --- a/UserManual.md +++ b/UserManual.md @@ -308,7 +308,7 @@ like request method, all headers, etcetera. Please refer to [mongoose.h](https://github.com/valenok/mongoose/blob/master/mongoose.h) to see what kind of information is present in `request_info` object. Also, [page.lp](https://github.com/valenok/mongoose/blob/master/test/page.lp) and -[prime_numbers.lp]()https://github.com/valenok/mongoose/blob/master/examples/lua/prime_numbers.lp +[prime_numbers.lp](https://github.com/valenok/mongoose/blob/master/examples/lua/prime_numbers.lp) contains some example code that uses `request_info` and other functions(form submitting for example). From 27735f293ba80719ec7adef22881190d5e68ffd9 Mon Sep 17 00:00:00 2001 From: Sergey Lyubka Date: Wed, 27 Feb 2013 11:17:33 +0000 Subject: [PATCH 8/9] Updated dates --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index 5040cd43..edb19837 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2004-2010 Sergey Lyubka +Copyright (c) 2004-2013 Sergey Lyubka Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal From 69cb94f3fb64b0f79708360b47836ab069f5c6a1 Mon Sep 17 00:00:00 2001 From: Sergey Lyubka Date: Wed, 27 Feb 2013 18:06:35 +0000 Subject: [PATCH 9/9] Removed header printing from page.lp --- test/page.lp | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/test/page.lp b/test/page.lp index 02be3382..b2ebee8b 100644 --- a/test/page.lp +++ b/test/page.lp @@ -10,14 +10,7 @@ Mongoose has Lua, Sqlite, and other functionality built in the binary. This example page stores the request in the Sqlite database, and shows all requests done previously.

- -

Today is -

HTTP headers:
- ') - end - ?> +

Today is