mirror of
https://github.com/cesanta/mongoose.git
synced 2026-10-26 12:14:56 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3070e8572d | ||
|
|
baf4d8af27 | ||
|
|
d5acf2e2a7 | ||
|
|
22f8cb14d5 | ||
|
|
e28b3ca91d | ||
|
|
73d2b395d1 | ||
|
|
e556a487e0 | ||
|
|
5728fa1cea | ||
|
|
b461edabd9 | ||
|
|
c9e666babc | ||
|
|
18e64397fc | ||
|
|
3c8418d324 | ||
|
|
784a1580ce | ||
|
|
6a0ac69761 | ||
|
|
7c06279a8c | ||
|
|
aec6f85f55 | ||
|
|
52e3be5c58 | ||
|
|
01a664ad06 | ||
|
|
94933047a7 | ||
|
|
cd6005c86f | ||
|
|
6d14ed3a18 | ||
|
|
0fb5db59d3 | ||
|
|
20b274bb2b | ||
|
|
00b289a0f4 | ||
|
|
9818f9849b | ||
|
|
df1c23222e | ||
|
|
f18ac3e094 | ||
|
|
d8596fae27 | ||
|
|
85209ac4fa | ||
|
|
a58e82b301 | ||
|
|
35f485558b | ||
|
|
93365fcbd2 | ||
|
|
e40a44ba70 | ||
|
|
1eed770238 | ||
|
|
511ef4137f | ||
|
|
479164129b | ||
|
|
08746115e2 | ||
|
|
587aad75c1 | ||
|
|
218428662e | ||
|
|
04fc209644 | ||
|
|
53bedd1eb5 | ||
|
|
a0b43ae8e0 | ||
|
|
866a7e2823 | ||
|
|
2055d41a9f | ||
|
|
1ef29c1b3b | ||
|
|
e95dbb90a7 | ||
|
|
cf18c932a4 | ||
|
|
a730afc44d | ||
|
|
94296c9697 | ||
|
|
667707df50 | ||
|
|
90b6fab3bb | ||
|
|
e47dbcbdc5 | ||
|
|
2a15f8d567 | ||
|
|
b5d397c74f | ||
|
|
3d6b373c8f | ||
|
|
ed236dddeb | ||
|
|
596fb1e88a | ||
|
|
ca0cd5040d | ||
|
|
5b84acbc14 | ||
|
|
c12838e2c3 | ||
|
|
fa3e6ce271 | ||
|
|
743f48b8e0 | ||
|
|
421c16b2bb | ||
|
|
3054a7f09e | ||
|
|
2de96bd54e | ||
|
|
f815c315e7 | ||
|
|
e59ee00154 | ||
|
|
b07745ab50 | ||
|
|
2468a8fb38 | ||
|
|
ed38a4102e | ||
|
|
b1c66f6544 | ||
|
|
8f79a0564f | ||
|
|
2e93cde929 | ||
|
|
e53d05637a | ||
|
|
9d75d35365 | ||
|
|
2ea8d85cff | ||
|
|
ea81a22529 | ||
|
|
526f3aa31c | ||
|
|
62d66201c9 | ||
|
|
f32e14478f | ||
|
|
ca019799b9 | ||
|
|
c6fb9ac3d0 | ||
|
|
c80a88a407 | ||
|
|
f2e19ca3ff | ||
|
|
16c463d2e9 | ||
|
|
6a99518048 | ||
|
|
3b242ec68b | ||
|
|
7409166409 | ||
|
|
ca66b84f7d | ||
|
|
dc1c732f11 | ||
|
|
61148f1323 | ||
|
|
136e3e353d | ||
|
|
c70b80e4e1 | ||
|
|
cba4c9d85d | ||
|
|
3e588065dc | ||
|
|
35cb27dbe6 | ||
|
|
d6b9f76e9c | ||
|
|
a9d51c0e87 | ||
|
|
4b163232e3 | ||
|
|
e003236a03 | ||
|
|
de7745370c | ||
|
|
21786eec8e | ||
|
|
036b213b2b | ||
|
|
61f5f0b725 | ||
|
|
d864d72470 | ||
|
|
7ca5962d2d | ||
|
|
8ce1562f0d | ||
|
|
49d9016275 | ||
|
|
cdc7380d00 | ||
|
|
e645b33b6c | ||
|
|
30f71a8bc4 | ||
|
|
faa030385c | ||
|
|
feb3b5db96 | ||
|
|
508b67d6f5 | ||
|
|
133aec777d | ||
|
|
389ed4e099 | ||
|
|
bc40aa5442 | ||
|
|
5fb9aca2e1 | ||
|
|
c68df310b8 | ||
|
|
70ce6c5ad3 | ||
|
|
460738f11b | ||
|
|
a09ec8988e | ||
|
|
c46aa050ae | ||
|
|
348db16245 | ||
|
|
c0ca6a53be | ||
|
|
e58d622d5f | ||
|
|
bcb294620f | ||
|
|
15937a9c5c | ||
|
|
fa160cb9a3 | ||
|
|
137d6484e2 | ||
|
|
e7c34c26cb | ||
|
|
dfb7d928c2 | ||
|
|
4bb9faaf50 | ||
|
|
a856971b6d | ||
|
|
4a88ad5ca9 | ||
|
|
17ecb0a459 | ||
|
|
afd39abc6f | ||
|
|
4babcff8de | ||
|
|
17d48b1d04 | ||
|
|
6ab20ed9a3 | ||
|
|
a0e5494569 | ||
|
|
f62c733990 | ||
|
|
d283e3167f | ||
|
|
94050d44e4 | ||
|
|
dee97cbf22 | ||
|
|
be01471968 | ||
|
|
a74c44c463 | ||
|
|
81e53d8375 | ||
|
|
ca626abcac | ||
|
|
b5e7730ac7 | ||
|
|
33b920ed2c | ||
|
|
b5b234fab2 | ||
|
|
af89d2446b | ||
|
|
791ad49651 | ||
|
|
063b26fece | ||
|
|
add079a949 | ||
|
|
6e59ad8a0d | ||
|
|
f4862b646d | ||
|
|
91fa767efb | ||
|
|
5e78711467 | ||
|
|
b4a622cfd6 | ||
|
|
8c118bf4cc | ||
|
|
728ebdaafa | ||
|
|
3a186976d7 | ||
|
|
2e232b3304 | ||
|
|
d72645bf91 | ||
|
|
7d5bcec92d | ||
|
|
215ea28db0 | ||
|
|
9b76d60b38 | ||
|
|
63ccf8199f | ||
|
|
6bc6022aa9 | ||
|
|
b68db66e97 | ||
|
|
94e1c5a41b | ||
|
|
ab16220861 | ||
|
|
c0eb3e56b4 | ||
|
|
5591aa5a0d | ||
|
|
6f946f5eea | ||
|
|
39cd5b8323 | ||
|
|
ca96db714a | ||
|
|
a7f97bf2f2 | ||
|
|
e579355b01 | ||
|
|
cfbaf7f1ae | ||
|
|
ce26234ace | ||
|
|
c28dc45d4c | ||
|
|
98b6c5e16a | ||
|
|
1d9d1111e1 | ||
|
|
2a0b55b30b | ||
|
|
1e3b167208 | ||
|
|
f7821b757c | ||
|
|
c352486abb | ||
|
|
4120b9bcc0 | ||
|
|
f7725f2eeb | ||
|
|
be06c3620c | ||
|
|
272644e39f | ||
|
|
55ef3afea4 | ||
|
|
9e07c742ff | ||
|
|
cd2e50c2c4 | ||
|
|
fdef2b8643 | ||
|
|
ce55924a02 | ||
|
|
fbca54bcaf | ||
|
|
41c25d60d6 | ||
|
|
a9b5bb351f | ||
|
|
51ed3efcd1 | ||
|
|
67cffc8db5 | ||
|
|
72abaa043b | ||
|
|
b3a511f9c5 | ||
|
|
8d1f6377c4 | ||
|
|
22dddc2eeb | ||
|
|
daab527743 | ||
|
|
dd49c0791f | ||
|
|
4b539d4b95 | ||
|
|
5eabfe5da2 | ||
|
|
36b7c8d60d | ||
|
|
aa37b728ad | ||
|
|
62085e5215 | ||
|
|
d036f8a3f0 | ||
|
|
fb5e2b8c2f | ||
|
|
4505b00733 | ||
|
|
c485b8264e | ||
|
|
8edd710c00 | ||
|
|
3984e9f5cc | ||
|
|
d4fa794c83 | ||
|
|
3892e0199e | ||
|
|
67f5de624e | ||
|
|
10234b07c4 | ||
|
|
36a83e1452 | ||
|
|
34df4ec1fd | ||
|
|
69cb94f3fb | ||
|
|
7204d71136 | ||
|
|
283f590349 | ||
|
|
27735f293b | ||
|
|
a560334fbb | ||
|
|
cd1707034c | ||
|
|
5ce1fc3c2a | ||
|
|
c78fe425a0 | ||
|
|
a58bb71c19 | ||
|
|
fc9a9593d2 | ||
|
|
eb1fdf56e6 | ||
|
|
ab960df8a9 | ||
|
|
08048bd5bb | ||
|
|
800517ac16 | ||
|
|
690eff4fa2 | ||
|
|
e47b5b775a | ||
|
|
c15e2af897 | ||
|
|
d8536b011c | ||
|
|
a2239c2b4b | ||
|
|
d3c02331d4 | ||
|
|
d707841166 | ||
|
|
affd82a885 | ||
|
|
8322c82790 | ||
|
|
08708435a7 | ||
|
|
1c6036c3ac | ||
|
|
6c3cb6f3eb | ||
|
|
a123874ac5 | ||
|
|
7931929a42 | ||
|
|
cc4a4fb2ab | ||
|
|
3d211d89c5 | ||
|
|
fbf1ccee45 | ||
|
|
0bd43bcae3 | ||
|
|
b809665cad | ||
|
|
463b49f1bd | ||
|
|
a881aad5c6 | ||
|
|
aae0995cd2 | ||
|
|
26b3f227d9 | ||
|
|
665770d602 | ||
|
|
fcafaa73d6 | ||
|
|
079b9ec2c1 | ||
|
|
7bd9a85897 | ||
|
|
2efc5d9fce | ||
|
|
1cb094e059 | ||
|
|
27fe9c8f01 | ||
|
|
9178fbd153 | ||
|
|
b2b43ab0cd | ||
|
|
1415d187eb | ||
|
|
a65078b858 | ||
|
|
7107afae5c | ||
|
|
f6a807c5a4 | ||
|
|
47b11dd19e | ||
|
|
61cdc93405 | ||
|
|
7a52bd643c | ||
|
|
63e8052e4b | ||
|
|
782d0cda46 | ||
|
|
72803eb7f8 | ||
|
|
c7fd221ab7 | ||
|
|
492185e35f | ||
|
|
845d7b08e1 | ||
|
|
49bac31d2d | ||
|
|
9baf2d4ba4 | ||
|
|
1becd26a8f | ||
|
|
ffa983552f | ||
|
|
13d0b67c00 | ||
|
|
bda8e90733 | ||
|
|
fed2057a33 | ||
|
|
a27f62f89f | ||
|
|
d53902844c | ||
|
|
9870b80c65 | ||
|
|
cde25a8b82 | ||
|
|
1b7f036199 | ||
|
|
b80157b7ea | ||
|
|
f9311f0b30 | ||
|
|
bdd933f597 | ||
|
|
ee55d38b55 | ||
|
|
62162ff3e4 | ||
|
|
98f66c8867 | ||
|
|
c132191cad | ||
|
|
d73aa1ad09 | ||
|
|
d5bc58c38d | ||
|
|
51a80e4844 | ||
|
|
54f15a8fe3 | ||
|
|
ce0826e285 | ||
|
|
b21a8b2193 | ||
|
|
8bb49642da | ||
|
|
3f78df86ac | ||
|
|
c30f7a5258 | ||
|
|
7ed94d1918 | ||
|
|
dc513a9a15 | ||
|
|
8ce6cf61b7 | ||
|
|
e63f7fe33a | ||
|
|
b589e0cdf4 | ||
|
|
2b87f909ce | ||
|
|
ec7d0b1abd | ||
|
|
5bb3ede46d | ||
|
|
5105717f78 | ||
|
|
9d1e356709 | ||
|
|
3d7192d9fa | ||
|
|
1b3cbb17c1 | ||
|
|
f1f03e4378 | ||
|
|
625a2a3652 | ||
|
|
33a31d9308 | ||
|
|
5e9bd1f05e | ||
|
|
75d9a6c844 | ||
|
|
179761fd99 | ||
|
|
b783813e54 | ||
|
|
4b29689a42 | ||
|
|
9c4853471c | ||
|
|
81e21a3a0b | ||
|
|
bec6ea00ea | ||
|
|
ed32e3be0f | ||
|
|
83fae879bf | ||
|
|
2169e6d77f | ||
|
|
850e0a5922 | ||
|
|
322ed3cc6f | ||
|
|
6d4d53c247 | ||
|
|
e6f8d40942 | ||
|
|
7e051206ad | ||
|
|
76d913796c | ||
|
|
4c2609df2c | ||
|
|
f79bd71fd4 | ||
|
|
5d4f5b6000 | ||
|
|
fe7c245a6b | ||
|
|
f24bebaca8 | ||
|
|
08afdfa8b6 | ||
|
|
05f7d65fc9 | ||
|
|
a194e07545 | ||
|
|
dbb8a5bbf4 | ||
|
|
d3005df019 | ||
|
|
ef9b103a00 | ||
|
|
f0a2924a7c | ||
|
|
f109030cd0 | ||
|
|
eebdd06532 | ||
|
|
ca2fc71a01 | ||
|
|
e61e371c16 | ||
|
|
d5f07f5b9b | ||
|
|
0a8d5dde51 | ||
|
|
5646caa572 | ||
|
|
c7e5573d08 | ||
|
|
b9a226d109 | ||
|
|
fcf8b86288 | ||
|
|
a8b08c6784 | ||
|
|
1fb6f391a1 | ||
|
|
fcbc36ecde | ||
|
|
70771f29ce | ||
|
|
121391504f | ||
|
|
8455742440 | ||
|
|
5b786a5089 | ||
|
|
a6e74e7707 | ||
|
|
acf72a6109 | ||
|
|
2b76f5fc2a | ||
|
|
c0150606f0 | ||
|
|
cdb6588973 | ||
|
|
eecf24b20c | ||
|
|
0470e813a9 | ||
|
|
52c2b6a407 | ||
|
|
d0ce4b9d81 | ||
|
|
f08af96294 | ||
|
|
315ab663df | ||
|
|
fbd46f9b1c | ||
|
|
74c099fe63 | ||
|
|
2acfab62f0 | ||
|
|
0f9a6266e2 | ||
|
|
ca447d9a23 | ||
|
|
444dbe1cec | ||
|
|
20ce55eb3a | ||
|
|
3956aba429 | ||
|
|
6a37f5e4d6 | ||
|
|
f71bfd5e28 | ||
|
|
38cc14a1af | ||
|
|
bde9a63390 | ||
|
|
8eb816c314 | ||
|
|
50c05c4eed | ||
|
|
4eb5cfab7b | ||
|
|
df6fe7a379 | ||
|
|
78eec961a2 | ||
|
|
adff33c889 | ||
|
|
372fcd722c | ||
|
|
0982863e2d | ||
|
|
9b58a951f0 | ||
|
|
ba04f3fd5d | ||
|
|
ff52367c1c | ||
|
|
a0a017d54d | ||
|
|
6cad2c6f28 | ||
|
|
cec98ee9e2 | ||
|
|
dbef400762 | ||
|
|
1bd85de19a | ||
|
|
0b206129ac | ||
|
|
5e491801da | ||
|
|
eed09600f7 | ||
|
|
8d6634ff7e | ||
|
|
6c9ed3ca53 | ||
|
|
ede1befffa | ||
|
|
2cd4852321 | ||
|
|
1eb719f2d9 | ||
|
|
bf633082ac | ||
|
|
075a152779 | ||
|
|
c079a13b24 | ||
|
|
113c9d5a02 | ||
|
|
05fa677382 | ||
|
|
ab3c070e1c | ||
|
|
2e6a01b931 | ||
|
|
9fa66bf237 | ||
|
|
98c382e7af | ||
|
|
94c7a3862a | ||
|
|
6869b64b31 | ||
|
|
8faf6f7b72 | ||
|
|
99ddb2f12a | ||
|
|
ca9212c3ca | ||
|
|
c9183f3851 | ||
|
|
0912a7f473 | ||
|
|
38421657b3 | ||
|
|
64cfe1d389 | ||
|
|
69b0b58d46 | ||
|
|
0d442058e5 | ||
|
|
1ef31461bc | ||
|
|
0b09df97ac | ||
|
|
0263e39584 | ||
|
|
d8424726bb | ||
|
|
080cb2dd4b | ||
|
|
786caaecb2 | ||
|
|
eb92b5f1b3 | ||
|
|
c5ba6016aa | ||
|
|
73a845a327 | ||
|
|
6eec552ea4 | ||
|
|
cb62203cf3 | ||
|
|
4fcb64fe90 | ||
|
|
8966f47c7a | ||
|
|
e251375c0c | ||
|
|
672e1ec8c6 | ||
|
|
f8713ede2d | ||
|
|
0b5f854bf0 | ||
|
|
3770020b74 | ||
|
|
9f9a1638f7 | ||
|
|
fb07a937e7 | ||
|
|
025cd283c4 | ||
|
|
b39426dbf7 | ||
|
|
5157bd0960 | ||
|
|
2aaedef4af | ||
|
|
a0b037d288 | ||
|
|
011bdc22b2 | ||
|
|
b437d56736 | ||
|
|
6205e69ab2 | ||
|
|
038f8823f1 | ||
|
|
03dd8367bf | ||
|
|
b597da34da | ||
|
|
bf387f9544 | ||
|
|
365b5e8f8a | ||
|
|
47651766fb | ||
|
|
043ea54a2a | ||
|
|
55c8c82c4b | ||
|
|
557d1f4c49 | ||
|
|
2539a473fe | ||
|
|
6bd35a4c18 | ||
|
|
fb8f0ed4d6 | ||
|
|
3ffdf5459a | ||
|
|
02098b1903 | ||
|
|
c189553c8b | ||
|
|
d970705596 | ||
|
|
5c9ab40601 | ||
|
|
451d077170 | ||
|
|
30d1573346 | ||
|
|
0adef2db5b | ||
|
|
8c1866a4af | ||
|
|
2a7a594b49 | ||
|
|
78ea04556f | ||
|
|
7fe2944477 | ||
|
|
93131417e6 | ||
|
|
6ef5eb0665 | ||
|
|
24103ff5df | ||
|
|
2118de37c3 |
No files matched your search
@@ -1,19 +1,16 @@
|
||||
Copyright (c) 2004-2010 Sergey Lyubka
|
||||
Copyright (c) 2004-2013 Sergey Lyubka <valenok@gmail.com>
|
||||
Copyright (c) 2013 Cesanta Software Limited
|
||||
All rights reserved
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
This code is dual-licensed: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License version 2 as
|
||||
published by the Free Software Foundation. For the terms of this
|
||||
license, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
You are free to use this code under the terms of the GNU General
|
||||
Public License, but WITHOUT ANY WARRANTY; without even the implied
|
||||
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
See the GNU General Public License for more details.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
Alternatively, you can license this code under a commercial
|
||||
license, as set out in <http://cesanta.com/products.html>.
|
||||
@@ -1,147 +0,0 @@
|
||||
# This file is part of Mongoose project, http://code.google.com/p/mongoose
|
||||
# $Id: Makefile 473 2009-09-02 11:20:06Z valenok $
|
||||
|
||||
PROG= mongoose
|
||||
|
||||
all:
|
||||
@echo "make (linux|bsd|solaris|mac|windows|mingw)"
|
||||
|
||||
# Possible COPT values: (in brackets are rough numbers for 'gcc -O2' on i386)
|
||||
# -DHAVE_MD5 - use system md5 library (-2kb)
|
||||
# -DNDEBUG - strip off all debug code (-5kb)
|
||||
# -DDEBUG - build debug version (very noisy) (+7kb)
|
||||
# -DNO_CGI - disable CGI support (-5kb)
|
||||
# -DNO_SSL - disable SSL functionality (-2kb)
|
||||
# -DCONFIG_FILE=\"file\" - use `file' as the default config file
|
||||
# -DHAVE_STRTOUI64 - use system strtoui64() function for strtoull()
|
||||
# -DSSL_LIB=\"libssl.so.<version>\" - use system versioned SSL shared object
|
||||
# -DCRYPTO_LIB=\"libcrypto.so.<version>\" - use system versioned CRYPTO so
|
||||
|
||||
|
||||
##########################################################################
|
||||
### UNIX build: linux, bsd, mac, rtems
|
||||
##########################################################################
|
||||
|
||||
GCC_WARNS = -W -Wall -pedantic
|
||||
# -Wno-missing-field-initializers -Wno-unused-parameter -Wno-format-zero-length -Wno-missing-braces
|
||||
CFLAGS = -std=c99 -O2 $(GCC_WARNS) $(COPT)
|
||||
MAC_SHARED = -flat_namespace -bundle -undefined suppress
|
||||
LINFLAGS = -ldl -pthread $(CFLAGS)
|
||||
LIB = lib$(PROG).so$(MONGOOSE_LIB_SUFFIX)
|
||||
|
||||
# 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
|
||||
# "-Wl,--as-needed" turned on by default in cc command.
|
||||
# Also, this is turned in many other distros in static linkage builds.
|
||||
linux:
|
||||
$(CC) mongoose.c -shared -fPIC -fpic -o $(LIB) -Wl,-soname,$(LIB) $(LINFLAGS)
|
||||
$(CC) mongoose.c main.c -o $(PROG) $(LINFLAGS)
|
||||
|
||||
bsd:
|
||||
$(CC) mongoose.c -shared -pthread -fpic -fPIC -o $(LIB) $(CFLAGS)
|
||||
$(CC) mongoose.c main.c -pthread -o $(PROG) $(CFLAGS)
|
||||
|
||||
mac:
|
||||
$(CC) mongoose.c -pthread -o $(LIB) $(MAC_SHARED) $(CFLAGS)
|
||||
$(CC) mongoose.c main.c -pthread -o $(PROG) $(CFLAGS)
|
||||
|
||||
solaris:
|
||||
$(CC) mongoose.c -pthread -lnsl \
|
||||
-lsocket -fpic -fPIC -shared -o $(LIB) $(CFLAGS)
|
||||
$(CC) mongoose.c main.c -pthread -lnsl -lsocket -o $(PROG) $(CFLAGS)
|
||||
|
||||
|
||||
##########################################################################
|
||||
### WINDOWS build: Using Visual Studio or Mingw
|
||||
##########################################################################
|
||||
|
||||
# Using Visual Studio 6.0. To build Mongoose:
|
||||
# o Set MSVC variable below to where VS 6.0 is installed on your system
|
||||
# o Run "PATH_TO_VC6\bin\nmake windows"
|
||||
|
||||
MSVC = e:/vc6
|
||||
CYA = e:/cyassl-2.0.0rc2
|
||||
#DBG = /Zi /DDEBUG /Od
|
||||
DBG = /DNDEBUG /O1
|
||||
CL = $(MSVC)/bin/cl /MD /TC /nologo $(DBG) /Gz /W3 /DNO_SSL_DL \
|
||||
/I$(MSVC)/include
|
||||
GUILIB= user32.lib shell32.lib
|
||||
LINK = /link /incremental:no /libpath:$(MSVC)/lib /machine:IX86 \
|
||||
/subsystem:windows ws2_32.lib advapi32.lib cyassl.lib
|
||||
CYAFL = /c /I $(CYA)/include -I $(CYA)/include/openssl /I$(MSVC)/INCLUDE \
|
||||
/I $(CYA)/ctaocrypt/include /D _LIB /D OPENSSL_EXTRA
|
||||
|
||||
CYASRC= \
|
||||
$(CYA)/src/cyassl_int.c \
|
||||
$(CYA)/src/cyassl_io.c \
|
||||
$(CYA)/src/keys.c \
|
||||
$(CYA)/src/tls.c \
|
||||
$(CYA)/src/ssl.c \
|
||||
$(CYA)/ctaocrypt/src/aes.c \
|
||||
$(CYA)/ctaocrypt/src/arc4.c \
|
||||
$(CYA)/ctaocrypt/src/asn.c \
|
||||
$(CYA)/ctaocrypt/src/coding.c \
|
||||
$(CYA)/ctaocrypt/src/ctc_asm.c \
|
||||
$(CYA)/ctaocrypt/src/ctc_misc.c \
|
||||
$(CYA)/ctaocrypt/src/cyassl_memory.c \
|
||||
$(CYA)/ctaocrypt/src/des3.c \
|
||||
$(CYA)/ctaocrypt/src/dh.c \
|
||||
$(CYA)/ctaocrypt/src/dsa.c \
|
||||
$(CYA)/ctaocrypt/src/ecc.c \
|
||||
$(CYA)/ctaocrypt/src/hc128.c \
|
||||
$(CYA)/ctaocrypt/src/hmac.c \
|
||||
$(CYA)/ctaocrypt/src/integer.c \
|
||||
$(CYA)/ctaocrypt/src/md4.c \
|
||||
$(CYA)/ctaocrypt/src/md5.c \
|
||||
$(CYA)/ctaocrypt/src/pwdbased.c \
|
||||
$(CYA)/ctaocrypt/src/rabbit.c \
|
||||
$(CYA)/ctaocrypt/src/random.c \
|
||||
$(CYA)/ctaocrypt/src/ripemd.c \
|
||||
$(CYA)/ctaocrypt/src/rsa.c \
|
||||
$(CYA)/ctaocrypt/src/sha.c \
|
||||
$(CYA)/ctaocrypt/src/sha256.c \
|
||||
$(CYA)/ctaocrypt/src/sha512.c \
|
||||
$(CYA)/ctaocrypt/src/tfm.c
|
||||
|
||||
cyassl.lib:
|
||||
$(CL) $(CYASRC) $(CYAFL) $(DEF)
|
||||
$(MSVC)/bin/lib *.obj /out:$@
|
||||
|
||||
windows: cyassl.lib
|
||||
$(MSVC)/bin/rc win32\res.rc
|
||||
$(CL) /I win32 main.c mongoose.c /GA $(LINK) win32\res.res \
|
||||
$(GUILIB) /out:$(PROG).exe
|
||||
$(CL) mongoose.c /GD $(LINK) /DLL /DEF:win32\dll.def /out:$(PROG).dll
|
||||
|
||||
# Build for Windows under MinGW
|
||||
#MINGWDBG= -DDEBUG -O0 -ggdb
|
||||
MINGWDBG= -DNDEBUG -Os
|
||||
MINGWOPT= -W -Wall -mthreads -Wl,--subsystem,console $(MINGWDBG) -DHAVE_STDINT $(GCC_WARNINGS) $(COPT)
|
||||
#MINGWOPT= -W -Wall -mthreads -Wl,--subsystem,windows $(MINGWDBG) -DHAVE_STDINT $(GCC_WARNINGS) $(COPT)
|
||||
mingw:
|
||||
windres win32\res.rc win32\res.o
|
||||
$(CC) $(MINGWOPT) mongoose.c -lws2_32 \
|
||||
-shared -Wl,--out-implib=$(PROG).lib -o $(PROG).dll
|
||||
$(CC) $(MINGWOPT) -Iwin32 mongoose.c main.c win32\res.o -lws2_32 -ladvapi32 \
|
||||
-o $(PROG).exe
|
||||
|
||||
|
||||
##########################################################################
|
||||
### Manuals, cleanup, test, release
|
||||
##########################################################################
|
||||
|
||||
man:
|
||||
groff -man -T ascii mongoose.1 | col -b > mongoose.txt
|
||||
groff -man -T ascii mongoose.1 | less
|
||||
|
||||
# "TEST=unit make test" - perform unit test only
|
||||
# "TEST=embedded" - test embedded API by building and testing test/embed.c
|
||||
# "TEST=basic_tests" - perform basic tests only (no CGI, SSI..)
|
||||
tests:
|
||||
perl test/test.pl $(TEST)
|
||||
|
||||
release: clean
|
||||
F=mongoose-`perl -lne '/define\s+MONGOOSE_VERSION\s+"(\S+)"/ and print $$1' mongoose.c`.tgz ; cd .. && tar -czf x mongoose/{LICENSE,Makefile,bindings,examples,test,win32,mongoose.c,mongoose.h,mongoose.1,main.c} && mv x mongoose/$$F
|
||||
|
||||
clean:
|
||||
rm -rf *.o *.core $(PROG) *.obj *.so $(PROG).txt *.dSYM *.tgz $(PROG).exe *.dll *.lib
|
||||
@@ -1,31 +1,57 @@
|
||||
Overview
|
||||
--------
|
||||
# Project Mission
|
||||
|
||||
Mongoose is easy to use web server. It also can be used as embedded web server library to provide web interface to applications.
|
||||
Project mission is to provide easy to use, powerful, embeddable web server.
|
||||
|
||||
Mongoose executable does not depend on any external library or configuration. If it is copied to any directory and launched from there, it starts to serve that directory on port 8080 (so to access files, go to http://localhost:8080). If some additional config is required - for example, different listening port or IP-based access control, then a mongoose.conf file with respective options can be created in the same directory where executable lives. This makes Mongoose perfect for all sorts of demos, quick tests, file sharing, and Web programming.
|
||||
# Downloads
|
||||
|
||||
Sources, binaries and bundles are available for download at
|
||||
[mongoose downloads](http://cesanta.com/downloads.html).
|
||||
|
||||
# Overview
|
||||
|
||||
Mongoose keeps the balance between functionality and
|
||||
simplicity by carefully selected list of features:
|
||||
|
||||
- Works on Windows, Mac, UNIX, iPhone, Android, and many other platforms
|
||||
- Scripting and database support (Lua Server Pages + Sqlite, see
|
||||
[page.lp](https://github.com/valenok/mongoose/blob/master/test/page.lp) ),
|
||||
which provides ready to go, powerful web development platform in
|
||||
one single-click executable with **no dependencies**: forget LAMP!
|
||||
- Support for CGI, SSL, SSI, Digest (MD5) authorization, Websocket, WEbDAV
|
||||
- Resumed download, URL rewrite, file blacklist, IP-based ACL, Windows service
|
||||
- Download speed limit based on client subnet or URI pattern
|
||||
- Simple and clean embedding API,
|
||||
[mongoose.h](https://github.com/valenok/mongoose/blob/master/mongoose.h).
|
||||
The source is in single
|
||||
[mongoose.c](https://github.com/valenok/mongoose/blob/master/mongoose.c) file
|
||||
to make things easy. Embedding examples:
|
||||
[hello.c](https://github.com/valenok/mongoose/blob/master/examples/hello.c),
|
||||
[post.c](https://github.com/valenok/mongoose/blob/master/examples/post.c),
|
||||
[upload.c](https://github.com/valenok/mongoose/blob/master/examples/upload.c),
|
||||
[websocket.c](https://github.com/valenok/mongoose/blob/master/examples/websocket.c)
|
||||
- HTTP client capable of sending arbitrary HTTP/HTTPS requests
|
||||
- [User Manual](https://github.com/valenok/mongoose/blob/master/UserManual.md)
|
||||
|
||||
Note that Windows and MacOS binaries have following 3rd party software
|
||||
compiled in:
|
||||
<a href="http://wolfssl.com">WolfSSL lightweight SSL library</a>,
|
||||
<a href="http://sqlite.org">SQLite embedded database</a>,
|
||||
<a href="http://lua.org">Lua embedded scripting engine</a>.
|
||||
|
||||
Questions can be asked at
|
||||
[mongoose-users@googlegroups.com](http://groups.google.com/group/mongoose-users)
|
||||
mailing list.
|
||||
|
||||
[](http://githalytics.com/valenok/mongoose)
|
||||
|
||||
|
||||
Features
|
||||
--------
|
||||
# License
|
||||
|
||||
- Crossplatform - works on Windows, MacOS and most flavors of UNIX
|
||||
- CGI, SSL, SSI, Digest (MD5) authorization, Websocket, WEbDAV support
|
||||
- Resumed download, URL rewrite support
|
||||
- IP-based ACL, Windows service, GET, POST, HEAD, PUT, DELETE methods
|
||||
- Small footprint: executable size is 40 kB on Linux 2.6 i386 system
|
||||
- Embeddable with simple and clean API ([mongoose.h](https://github.com/valenok/mongoose/blob/master/mongoose.h)). The source is in single [mongoose.c](https://github.com/valenok/mongoose/blob/master/mongoose.c) file to make things easy.
|
||||
- Embedding examples: [hello.c](https://github.com/valenok/mongoose/blob/master/examples/hello.c), [post.c](https://github.com/valenok/mongoose/blob/master/examples/post.c), [upload.c](https://github.com/valenok/mongoose/blob/master/examples/upload.c), [websocket.c](https://github.com/valenok/mongoose/blob/master/examples/websocket.c)
|
||||
- Python and C# bindings
|
||||
Mongoose is dual-licensed. It is available under the terms of
|
||||
[GNU GPL v.2](http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) license
|
||||
license for free, or under the terms of standard commercial license provided
|
||||
by [Cesanta Software](http://cesanta.com).
|
||||
|
||||
|
||||
Mailing list
|
||||
------------
|
||||
|
||||
You can read it online, subscribe to, or send a message at [mongoose-users](http://groups.google.com/group/mongoose-users).
|
||||
|
||||
|
||||
Keep Sergey happy
|
||||
-----------------
|
||||
|
||||
I have a [books wishlist](http://amzn.com/w/1OC2ZCPTQYIEP?sort=priority) on Amazon. If you feel brave, you can buy me a book!
|
||||
[Super Light Regular Expression library](https://github.com/cesanta/slre) is
|
||||
another project by Cesanta Software, developed with the same philosophy
|
||||
of functionality and simplicity.
|
||||
+547
@@ -0,0 +1,547 @@
|
||||
# Overview
|
||||
|
||||
Mongoose is small and easy to use web server. It is self-contained, and does
|
||||
not require any external software to run.
|
||||
|
||||
On Windows, mongoose iconifies itself to the system tray icon when started.
|
||||
Right-click on the icon pops up a menu, where it is possible to stop
|
||||
mongoose, or configure it, or install it as Windows service. The easiest way
|
||||
to share a folder on Windows is to copy `mongoose.exe` to a folder,
|
||||
double-click the exe, and launch a browser at
|
||||
[http://localhost:8080](http://localhost:8080). Note that 'localhost' should
|
||||
be changed to a machine's name if a folder is accessed from other computer.
|
||||
|
||||
On UNIX and Mac, mongoose is a command line utility. Running `mongoose` in
|
||||
terminal, optionally followed by configuration parameters
|
||||
(`mongoose [OPTIONS]`) or configuration file name
|
||||
(`mongoose [config_file_name]`) starts the
|
||||
web server. Mongoose does not detach from terminal. Pressing `Ctrl-C` keys
|
||||
would stop the server.
|
||||
|
||||
When started, mongoose first searches for the configuration file.
|
||||
If configuration file is specified explicitly in the command line, i.e.
|
||||
`mongoose path_to_config_file`, then specified configuration file is used.
|
||||
Otherwise, mongoose would search for file `mongoose.conf` in the same directory
|
||||
where binary is located, and use it. Configuration file can be absent.
|
||||
|
||||
|
||||
Configuration file is a sequence of lines, each line containing
|
||||
command line argument name and it's value. Empty lines, and lines beginning
|
||||
with `#`, are ignored. Here is the example of `mongoose.conf` file:
|
||||
|
||||
document_root c:\www
|
||||
listening_ports 8080,8043s
|
||||
ssl_certificate c:\mongoose\ssl_cert.pem
|
||||
|
||||
When configuration file is processed, mongoose process command line arguments,
|
||||
if they are specified. Command line arguments therefore can override
|
||||
configuration file settings. Command line arguments must start with `-`.
|
||||
For example, if `mongoose.conf` has line
|
||||
`document_root /var/www`, and mongoose has been started as
|
||||
`mongoose -document_root /etc`, then `/etc` directory will be served as
|
||||
document root, because command line options take priority over
|
||||
configuration file. Configuration options section below provide a good
|
||||
overview of Mongoose features.
|
||||
|
||||
Note that configuration options on the command line must start with `-`,
|
||||
but their names are the same as in the config file. All option names are
|
||||
listed in the next section. Thus, the following two setups are equivalent:
|
||||
|
||||
# Using command line arguments
|
||||
$ mongoose -listening_ports 1234 -document_root /var/www
|
||||
|
||||
# Using config file
|
||||
$ cat mongoose.conf
|
||||
listening_ports 1234
|
||||
document_root /var/www
|
||||
$ mongoose
|
||||
|
||||
Mongoose can also be used to modify `.htpasswd` passwords file:
|
||||
|
||||
mongoose -A <htpasswd_file> <realm> <user> <passwd>
|
||||
|
||||
Unlike other web servers, mongoose does not require CGI scripts be located in
|
||||
a special directory. CGI scripts can be anywhere. CGI (and SSI) files are
|
||||
recognized by the file name pattern. Mongoose uses shell-like glob
|
||||
patterns. Pattern match starts at the beginning of the string, so essentially
|
||||
patterns are prefix patterns. Syntax is as follows:
|
||||
|
||||
** Matches everything
|
||||
* Matches everything but slash character, '/'
|
||||
? Matches any character
|
||||
$ Matches the end of the string
|
||||
| Matches if pattern on the left side or the right side matches.
|
||||
|
||||
All other characters in the pattern match themselves. Examples:
|
||||
|
||||
**.cgi$ Any string that ends with .cgi
|
||||
/foo Any string that begins with /foo
|
||||
**a$|**b$ Any string that ends with a or b
|
||||
|
||||
# Configuration Options
|
||||
|
||||
Below is a list of configuration options Mongoose understands. Every option
|
||||
is followed by it's default value. If default value is not present, then
|
||||
it is empty.
|
||||
|
||||
### cgi_pattern `**.cgi$|**.pl$|**.php$`
|
||||
All files that match `cgi_pattern` are treated as CGI files. Default pattern
|
||||
allows CGI files be anywhere. To restrict CGIs to a certain directory,
|
||||
use `/path/to/cgi-bin/**.cgi` as pattern. Note that full file path is
|
||||
matched against the pattern, not the URI.
|
||||
|
||||
### cgi_environment
|
||||
Extra environment variables to be passed to the CGI script in
|
||||
addition to standard ones. The list must be comma-separated list
|
||||
of name=value pairs, like this: `VARIABLE1=VALUE1,VARIABLE2=VALUE2`.
|
||||
|
||||
### put\_delete\_auth\_file
|
||||
Passwords file for PUT and DELETE requests. Without it, PUT and DELETE requests
|
||||
will fail.
|
||||
|
||||
### cgi_interpreter
|
||||
Path to an executable to use as CGI interpreter for __all__ CGI scripts
|
||||
regardless script extension. If this option is not set (which is a default),
|
||||
Mongoose looks at first line of a CGI script,
|
||||
[shebang line](http://en.wikipedia.org/wiki/Shebang_(Unix\)), for an interpreter.
|
||||
|
||||
For example, if both PHP and perl CGIs are used, then
|
||||
`#!/path/to/php-cgi.exe` and `#!/path/to/perl.exe` must be first lines of the
|
||||
respective CGI scripts. Note that paths should be either full file paths,
|
||||
or file paths relative to the current working directory of mongoose server.
|
||||
If mongoose is started by mouse double-click on Windows, current working
|
||||
directory is a directory where mongoose executable is located.
|
||||
|
||||
If all CGIs use the same interpreter, for example they are all PHP, then
|
||||
`cgi_interpreter` can be set to the path to `php-cgi.exe` executable and
|
||||
shebang line in the CGI scripts can be omitted.
|
||||
Note that PHP scripts must use `php-cgi.exe` executable, not `php.exe`.
|
||||
|
||||
### protect_uri
|
||||
Comma separated list of URI=PATH pairs, specifying that given
|
||||
URIs must be protected with respected password files. Paths must be full
|
||||
file paths.
|
||||
|
||||
### authentication_domain `mydomain.com`
|
||||
Authorization realm used in `.htpasswd` authorization.
|
||||
|
||||
### ssi_pattern `**.shtml$|**.shtm$`
|
||||
All files that match `ssi_pattern` are treated as SSI.
|
||||
|
||||
Server Side Includes (SSI) is a simple interpreted server-side scripting
|
||||
language which is most commonly used to include the contents of a file into
|
||||
a web page. It can be useful when it is desirable to include a common piece
|
||||
of code throughout a website, for example, headers and footers.
|
||||
|
||||
In order for a webpage to recognize an SSI-enabled HTML file, the filename
|
||||
should end with a special extension, by default the extension should be
|
||||
either `.shtml` or `.shtm`.
|
||||
|
||||
Unknown SSI directives are silently ignored by mongoose. Currently, two SSI
|
||||
directives are supported, `<!--#include ...>` and
|
||||
`<!--#exec "command">`. Note that `<!--#include ...>` directive supports
|
||||
three path specifications:
|
||||
|
||||
<!--#include virtual="path"> Path is relative to web server root
|
||||
<!--#include abspath="path"> Path is absolute or relative to
|
||||
web server working dir
|
||||
<!--#include file="path">, Path is relative to current document
|
||||
<!--#include "path">
|
||||
|
||||
The `include` directive may be used to include the contents of a file or the
|
||||
result of running a CGI script. The `exec` directive is used to execute a
|
||||
command on a server, and show command's output. Example:
|
||||
|
||||
<!--#exec "ls -l" -->
|
||||
|
||||
For more information on Server Side Includes, take a look at the Wikipedia:
|
||||
[Server Side Includes](http://en.wikipedia.org/wiki/Server_Side_Includes)
|
||||
|
||||
### throttle
|
||||
Limit download speed for clients. `throttle` is a comma-separated
|
||||
list of key=value pairs, where key could be:
|
||||
|
||||
* limit speed for all connections
|
||||
x.x.x.x/mask limit speed for specified subnet
|
||||
uri_prefix_pattern limit speed for given URIs
|
||||
|
||||
The value is a floating-point number of bytes per second, optionally
|
||||
followed by a `k` or `m` character, meaning kilobytes and
|
||||
megabytes respectively. A limit of 0 means unlimited rate. The
|
||||
last matching rule wins. Examples:
|
||||
|
||||
*=1k,10.0.0.0/8=0 limit all accesses to 1 kilobyte per second,
|
||||
but give connections from 10.0.0.0/8 subnet
|
||||
unlimited speed
|
||||
|
||||
/downloads/=5k limit accesses to all URIs in `/downloads/` to
|
||||
5 kilobytes per secods. All other accesses are unlimited
|
||||
|
||||
### access\_log\_file
|
||||
Path to a file for access logs. Either full path, or relative to current
|
||||
working directory. If absent (default), then accesses are not logged.
|
||||
|
||||
### error\_log\_file
|
||||
Path to a file for error logs. Either full path, or relative to current
|
||||
working directory. If absent (default), then errors are not logged.
|
||||
|
||||
### enable\_directory\_listing `yes`
|
||||
Enable directory listing, either `yes` or `no`.
|
||||
|
||||
### enable\_keep\_alive `no`
|
||||
Enable connection keep alive, either `yes` or `no`.
|
||||
|
||||
Experimental feature. Allows clients to reuse TCP connection for
|
||||
subsequent HTTP requests, which improves performance.
|
||||
For this to work when using request handlers it's important to add the correct
|
||||
Content-Length HTTP header for each request. If this is forgotten the client
|
||||
will time out.
|
||||
|
||||
|
||||
### global\_auth\_file
|
||||
Path to a global passwords file, either full path or relative to the current
|
||||
working directory. If set, per-directory `.htpasswd` files are ignored,
|
||||
and all requests are authorised against that file.
|
||||
|
||||
The file has to include the realm set through `authentication_domain` and the password in digest format:
|
||||
|
||||
user:realm:digest
|
||||
test:test.com:ce0220efc2dd2fad6185e1f1af5a4327
|
||||
|
||||
(e.g. use [this generator](http://www.askapache.com/online-tools/htpasswd-generator))
|
||||
|
||||
### index_files `index.html,index.htm,index.cgi,index.shtml,index.php`
|
||||
Comma-separated list of files to be treated as directory index
|
||||
files.
|
||||
|
||||
### access\_control\_list
|
||||
An Access Control List (ACL) allows restrictions to be put on the list of IP
|
||||
addresses which have access to the web server. In the case of the Mongoose
|
||||
web server, the ACL is a comma separated list of IP subnets, where each
|
||||
subnet is prepended by either a `-` or a `+` sign. A plus sign means allow,
|
||||
where a minus sign means deny. If a subnet mask is omitted, such as `-1.2.3.4`,
|
||||
this means to deny only that single IP address.
|
||||
|
||||
Subnet masks may vary from 0 to 32, inclusive. The default setting is to allow
|
||||
all accesses. On each request the full list is traversed, and
|
||||
the last match wins. Examples:
|
||||
|
||||
-0.0.0.0/0,+192.168/16 deny all acccesses, only allow 192.168/16 subnet
|
||||
|
||||
To learn more about subnet masks, see the
|
||||
[Wikipedia page on Subnetwork](http://en.wikipedia.org/wiki/Subnetwork)
|
||||
|
||||
### extra\_mime\_types
|
||||
Extra mime types to recognize, in form `extension1=type1,exten-
|
||||
sion2=type2,...`. Extension must include dot. Example:
|
||||
`.cpp=plain/text,.java=plain/text`
|
||||
|
||||
### listening_ports `8080`
|
||||
Comma-separated list of ports to listen on. If the port is SSL, a
|
||||
letter `s` must be appeneded, for example, `80,443s` will open
|
||||
port 80 and port 443, and connections on port 443 will be SSL-ed.
|
||||
For non-SSL ports, it is allowed to append letter `r`, meaning 'redirect'.
|
||||
Redirect ports will redirect all their traffic to the first configured
|
||||
SSL port. For example, if `listening_ports` is `80r,443s`, then all
|
||||
HTTP traffic coming at port 80 will be redirected to HTTPS port 443.
|
||||
|
||||
It is possible to specify an IP address to bind to. In this case,
|
||||
an IP address and a colon must be prepended to the port number.
|
||||
For example, to bind to a loopback interface on port 80 and to
|
||||
all interfaces on HTTPS port 443, use `127.0.0.1:80,443s`.
|
||||
|
||||
### document_root `.`
|
||||
A directory to serve. By default, currect directory is served. Current
|
||||
directory is commonly referenced as dot (`.`).
|
||||
|
||||
### ssl_certificate
|
||||
Path to SSL certificate file. This option is only required when at least one
|
||||
of the `listening_ports` is SSL. The file must be in PEM format,
|
||||
and it must have both private key and certificate, see for example
|
||||
[ssl_cert.pem](https://github.com/valenok/mongoose/blob/master/build/ssl_cert.pem)
|
||||
|
||||
### num_threads `50`
|
||||
Number of worker threads. Mongoose handles each incoming connection in a
|
||||
separate thread. Therefore, the value of this option is effectively a number
|
||||
of concurrent HTTP connections Mongoose can handle.
|
||||
|
||||
### run\_as\_user
|
||||
Switch to given user credentials after startup. Usually, this option is
|
||||
required when mongoose needs to bind on privileged port on UNIX. To do
|
||||
that, mongoose needs to be started as root. But running as root is a bad idea,
|
||||
therefore this option can be used to drop privileges. Example:
|
||||
|
||||
mongoose -listening_ports 80 -run_as_user nobody
|
||||
|
||||
### request\_timeout\_ms `30000`
|
||||
Timeout for network read and network write operations, in milliseconds.
|
||||
If client intends to keep long-running connection, either increase this value
|
||||
or use keep-alive messages.
|
||||
|
||||
|
||||
### url\_rewrite\_patterns
|
||||
Comma-separated list of URL rewrites in the form of
|
||||
`uri_pattern=file_or_directory_path`. When Mongoose receives the request,
|
||||
it constructs the file name to show by combining `document_root` and the URI.
|
||||
However, if the rewrite option is used and `uri_pattern` matches the
|
||||
requested URI, then `document_root` is ignored. Insted,
|
||||
`file_or_directory_path` is used, which should be a full path name or
|
||||
a path relative to the web server's current working directory. Note that
|
||||
`uri_pattern`, as all mongoose patterns, is a prefix pattern.
|
||||
|
||||
This makes it possible to serve many directories outside from `document_root`,
|
||||
redirect all requests to scripts, and do other tricky things. For example,
|
||||
to redirect all accesses to `.doc` files to a special script, do:
|
||||
|
||||
mongoose -url_rewrite_patterns **.doc$=/path/to/cgi-bin/handle_doc.cgi
|
||||
|
||||
Or, to imitate user home directories support, do:
|
||||
|
||||
mongoose -url_rewrite_patterns /~joe/=/home/joe/,/~bill=/home/bill/
|
||||
|
||||
### hide\_files\_patterns
|
||||
A pattern for the files to hide. Files that match the pattern will not
|
||||
show up in directory listing and return `404 Not Found` if requested. Pattern
|
||||
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:
|
||||
|
||||
<p>
|
||||
<span>Today is:</span>
|
||||
<? mg.write(os.date("%A")) ?>
|
||||
</p>
|
||||
|
||||
Note that this example uses function `mg.write()`, which prints data to the
|
||||
web page. Using function `mg.write()` is the way to generate web content from
|
||||
inside Lua code. In addition to `mg.write()`, 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 `mg.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 `mg.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)
|
||||
contains some example code that uses `request_info` and other functions(form submitting for example).
|
||||
|
||||
Mongoose exports the following to the Lua server page:
|
||||
|
||||
mg.read() -- reads a chunk from POST data, returns it as a string
|
||||
mg.write(str) -- writes string to the client
|
||||
mg.include(path) -- sources another Lua file
|
||||
mg.redirect(uri) -- internal redirect to a given URI
|
||||
mg.onerror(msg) -- error handler, can be overridden
|
||||
mg.version -- a string that holds Mongoose version
|
||||
mg.request_info -- a table with request information
|
||||
|
||||
-- Connect to the remote TCP server. This function is an implementation
|
||||
-- of simple socket interface. It returns a socket object with three
|
||||
-- methods: send, recv, close, which are synchronous (blocking).
|
||||
-- connect() throws an exception on connection error.
|
||||
connect(host, port, use_ssl)
|
||||
|
||||
-- Example of using connect() interface:
|
||||
local host = 'code.google.com' -- IP address or domain name
|
||||
local ok, sock = pcall(connect, host, 80, 1)
|
||||
if ok then
|
||||
sock:send('GET /p/mongoose/ HTTP/1.0\r\n' ..
|
||||
'Host: ' .. host .. '\r\n\r\n')
|
||||
local reply = sock:recv()
|
||||
sock:close()
|
||||
-- reply now contains the web page https://code.google.com/p/mongoose
|
||||
end
|
||||
|
||||
|
||||
**IMPORTANT: Mongoose does not send HTTP headers for Lua pages. Therefore,
|
||||
every Lua Page must begin with HTTP reply line and headers**, like this:
|
||||
|
||||
<? print('HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n') ?>
|
||||
<html><body>
|
||||
... the rest of the web page ...
|
||||
|
||||
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,
|
||||
correct interpreter is `php-cgi.exe` (`php-cgi` on UNIX). Solution: specify
|
||||
full path to the PHP interpreter, e.g.:
|
||||
`mongoose -cgi_interpreter /full/path/to/php-cgi`
|
||||
|
||||
- Mongoose fails to start. If Mongoose exits immediately when run, this
|
||||
usually indicates a syntax error in the configuration file
|
||||
(named `mongoose.conf` by default) or the command-line arguments.
|
||||
Syntax checking is omitted from Mongoose to keep its size low. However,
|
||||
the Manual should be of help. Note: the syntax changes from time to time,
|
||||
so updating the config file might be necessary after executable update.
|
||||
|
||||
- Embedding with OpenSSL on Windows might fail because of calling convention.
|
||||
To force Mongoose to use `__stdcall` convention, add `/Gz` compilation
|
||||
flag in Visual Studio compiler.
|
||||
|
||||
# Embedding
|
||||
Embedding Mongoose is easy. Copy
|
||||
[mongoose.c](https://github.com/valenok/mongoose/blob/master/mongoose.c) and
|
||||
[mongoose.h](https://github.com/valenok/mongoose/blob/master/mongoose.h)
|
||||
to your application's source tree and include them in the build. For
|
||||
example, your application's code lives in C file `my_app.c`, then on UNIX
|
||||
this command embeds Mongoose:
|
||||
|
||||
$ ls
|
||||
my_app.c mongoose.c mongoose.h
|
||||
$ gcc my_app.c mongoose.c -o my_app -ldl -pthread
|
||||
|
||||
Somewhere in the application code, call `mg_start()` to start the server.
|
||||
Pass configuration options and event handlers to `mg_start()`.
|
||||
Mongoose then calls handlers when certain events happen.
|
||||
For example, when new request arrives, Mongoose calls `begin_request`
|
||||
handler function to let user handle the request. In the handler, user code
|
||||
can get all information about the request -- parsed headers, etcetera.
|
||||
|
||||
Mongoose API is logically divided in three categories: server setup/shutdown
|
||||
functions, functions to be used by user-written event handlers, and
|
||||
convenience utility functions.
|
||||
|
||||
### Starting and stopping embedded web server
|
||||
To start the embedded web server, call `mg_start()`. To stop it, call
|
||||
`mg_stop()`.
|
||||
|
||||
// This structure needs to be passed to mg_start(), to let mongoose know
|
||||
// which callbacks to invoke. For detailed description, see
|
||||
// https://github.com/valenok/mongoose/blob/master/UserManual.md
|
||||
struct mg_callbacks {
|
||||
int (*begin_request)(struct mg_connection *);
|
||||
void (*end_request)(const struct mg_connection *, int reply_status_code);
|
||||
int (*log_message)(const struct mg_connection *, const char *message);
|
||||
int (*init_ssl)(void *ssl_context);
|
||||
int (*websocket_connect)(const struct mg_connection *);
|
||||
void (*websocket_ready)(struct mg_connection *);
|
||||
int (*websocket_data)(struct mg_connection *);
|
||||
const char * (*open_file)(const struct mg_connection *,
|
||||
const char *path, size_t *data_len);
|
||||
void (*init_lua)(struct mg_connection *, void *lua_context);
|
||||
void (*upload)(struct mg_connection *, const char *file_name);
|
||||
int (*http_error)(struct mg_connection *, int status);
|
||||
};
|
||||
|
||||
[hello.c](https://github.com/valenok/mongoose/blob/master/examples/hello.c)
|
||||
provides a minimalistic example.
|
||||
|
||||
Common pattern is to implement `begin_request` callback, and serve static files
|
||||
from memory, and/or construct dynamic replies on the fly. Here is
|
||||
my [embed.c](https://gist.github.com/valenok/4714740) gist
|
||||
that shows how to easily any data can be embedded
|
||||
directly into the executable. If such data needs to be encrypted, then
|
||||
encrypted database or encryption dongles would be a better choice.
|
||||
|
||||
# Build on Android
|
||||
|
||||
This is a small guide to help you run mongoose on Android. Currently it is
|
||||
tested on the HTC Wildfire. If you have managed to run it on other devices
|
||||
as well, please comment or drop an email in the mailing list.
|
||||
Note : You dont need root access to run mongoose on Android.
|
||||
|
||||
- Download the source from the Downloads page.
|
||||
- Download the Android NDK from [http://developer.android.com/tools/sdk/ndk/index.html](http://developer.android.com/tools/sdk/ndk/index.html)
|
||||
- Run `/path-to-ndk/ndk-build -C /path-to-mongoose/build`
|
||||
That should generate mongoose/lib/armeabi/mongoose
|
||||
- Using the adb tool (you need to have Android SDK installed for that),
|
||||
push the generated mongoose binary to `/data/local` folder on device.
|
||||
- From adb shell, navigate to `/data/local` and execute `./mongoose`.
|
||||
- To test if the server is running fine, visit your web-browser and
|
||||
navigate to `http://127.0.0.1:8080` You should see the `Index of /` page.
|
||||
|
||||

|
||||
|
||||
|
||||
Notes:
|
||||
|
||||
- `jni` stands for Java Native Interface. Read up on Android NDK if you want
|
||||
to know how to interact with the native C functions of mongoose in Android
|
||||
Java applications.
|
||||
- TODO: A Java application that interacts with the native binary or a
|
||||
shared library.
|
||||
|
||||
# Mongoose internals
|
||||
|
||||
Mongoose is multithreaded web server. `mg_start()` function allocates
|
||||
web server context (`struct mg_context`), which holds all information
|
||||
about web server instance:
|
||||
|
||||
- configuration options. Note that mongoose makes internal copies of
|
||||
passed options.
|
||||
- SSL context, if any
|
||||
- user-defined callbacks
|
||||
- opened listening sockets
|
||||
- a queue for accepted sockets
|
||||
- mutexes and condition variables for inter-thread synchronization
|
||||
|
||||
When `mg_start()` returns, all initialization is quaranteed to be complete
|
||||
(e.g. listening ports are opened, SSL is initialized, etc). `mg_start()` starts
|
||||
two threads: a master thread, that accepts new connections, and several
|
||||
worker threads, that process accepted connections. The number of worker threads
|
||||
is configurable via `num_threads` configuration option. That number puts a
|
||||
limit on number of simultaneous requests that can be handled by mongoose.
|
||||
|
||||
When master thread accepts new connection, a new accepted socket (described by
|
||||
`struct socket`) it placed into the accepted sockets queue,
|
||||
which has size of 20 (see [code](https://github.com/valenok/mongoose/blob/3892e0199e6ca9613b160535d9d107ede09daa43/mongoose.c#L486)). Any idle worker thread
|
||||
can grab accepted sockets from that queue. If all worker threads are busy,
|
||||
master thread can accept and queue up to 20 more TCP connections,
|
||||
filling up the queue.
|
||||
In the attempt to queue next accepted connection, master thread blocks
|
||||
until there is space in a queue. When master thread is blocked on a
|
||||
full queue, TCP layer in OS can also queue incoming connection.
|
||||
The number is limited by the `listen()` call parameter on listening socket,
|
||||
which is `SOMAXCONN` in case of Mongoose, and depends on a platform.
|
||||
|
||||
Worker threads are running in an infinite loop, which in simplified form
|
||||
looks something like this:
|
||||
|
||||
static void *worker_thread() {
|
||||
while (consume_socket()) {
|
||||
process_new_connection();
|
||||
}
|
||||
}
|
||||
|
||||
Function `consume_socket()` gets new accepted socket from the mongoose socket
|
||||
queue, atomically removing it from the queue. If the queue is empty,
|
||||
`consume_socket()` blocks and waits until new sockets are placed in a queue
|
||||
by the master thread. `process_new_connection()` actually processes the
|
||||
connection, i.e. reads the request, parses it, and performs appropriate action
|
||||
depending on a parsed request.
|
||||
|
||||
Master thread uses `poll()` and `accept()` to accept new connections on
|
||||
listening sockets. `poll()` is used to avoid `FD_SETSIZE` limitation of
|
||||
`select()`. Since there are only a few listening sockets, there is no reason
|
||||
to use hi-performance alternatives like `epoll()` or `kqueue()`. Worker
|
||||
threads use blocking IO on accepted sockets for reading and writing data.
|
||||
All accepted sockets have `SO_RCVTIMEO` and `SO_SNDTIMEO` socket options set
|
||||
(controlled by `request_timeout_ms` mongoose option, 30 seconds default) which
|
||||
specify read/write timeout on client connection.
|
||||
|
||||
# Other Resources
|
||||
- Presentation made by Arnout Vandecappelle at FOSDEM 2011 on 2011-02-06
|
||||
in Brussels, Belgium, called
|
||||
"Creating secure web based user interfaces for Embedded Devices"
|
||||
([pdf](http://mind.be/content/110206_Web-ui.pdf) |
|
||||
[odp](http://mind.be/content/110206_Web-ui.odp))
|
||||
- Linux Journal article by Michel J.Hammel, 2010-04-01, called
|
||||
[Mongoose: an Embeddable Web Server in C](http://www.linuxjournal.com/article/10680)
|
||||
@@ -1,52 +0,0 @@
|
||||
// This is C# example on how to use Mongoose embeddable web server,
|
||||
// http://code.google.com/p/mongoose
|
||||
//
|
||||
// Before using the mongoose module, make sure that Mongoose shared library is
|
||||
// built and present in the current (or system library) directory
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
public class Program {
|
||||
|
||||
// This function is called when user types in his browser http://127.0.0.1:8080/foo
|
||||
static private void UriHandler(MongooseConnection conn, MongooseRequestInfo ri) {
|
||||
conn.write("HTTP/1.1 200 OK\r\n\r\n");
|
||||
conn.write("Hello from C#!\n");
|
||||
conn.write("Your user-agent is: " + conn.get_header("User-Agent") + "\n");
|
||||
}
|
||||
|
||||
static private void UriDumpInfo(MongooseConnection conn, MongooseRequestInfo ri)
|
||||
{
|
||||
conn.write("HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n");
|
||||
conn.write("<html><body><head>Calling Info</head>");
|
||||
conn.write("<p>Request: " + ri.request_method + "</p>");
|
||||
conn.write("<p>URI: " + ri.uri + "</p>");
|
||||
conn.write("<p>Query: " + ri.query_string + "</p>");
|
||||
if (ri.post_data_len > 0) conn.write("<p>Post(" + ri.post_data_len + ")[@" + ri.post_data + "]: '" + Marshal.PtrToStringAnsi(ri.post_data) + "'</p>");
|
||||
conn.write("<p>User:" + ri.remote_user + "</p>");
|
||||
conn.write("<p>IP: " + ri.remote_ip + "</p>");
|
||||
conn.write("<p>HTTP: " + ri.http_version + "</p>");
|
||||
conn.write("<p>Port: " + ri.remote_port + "</p>");
|
||||
conn.write("<p>NUM Headers: " + ri.num_headers + "</p>");
|
||||
for (int i = 0; i < Math.Min(64, ri.num_headers); i++)
|
||||
{
|
||||
conn.write("<p>" + i + ":" + Marshal.PtrToStringAnsi(ri.http_headers[i].name)
|
||||
+ ":" + Marshal.PtrToStringAnsi(ri.http_headers[i].value) + "</p>");
|
||||
}
|
||||
conn.write("</body></html>");
|
||||
}
|
||||
|
||||
static void Main() {
|
||||
Mongoose web_server = new Mongoose();
|
||||
|
||||
// Set options and /foo URI handler
|
||||
web_server.set_option("ports", "8080");
|
||||
web_server.set_option("root", "c:\\");
|
||||
web_server.set_uri_callback("/foo", new MongooseCallback(UriHandler));
|
||||
web_server.set_uri_callback("/dumpinfo", new MongooseCallback(UriDumpInfo));
|
||||
|
||||
// Serve requests until user presses "enter" on a keyboard
|
||||
Console.ReadLine();
|
||||
}
|
||||
}
|
||||
@@ -1,134 +0,0 @@
|
||||
// Copyright (c) 2004-2009 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
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
//
|
||||
// $Id: mongoose.cs 472 2009-08-30 22:40:29Z spsone1 $
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)] public struct MongooseHeader {
|
||||
public IntPtr name; // Using IntPtr here because if we use strings here,
|
||||
public IntPtr value; // it won't be properly marshalled.
|
||||
};
|
||||
|
||||
// This is "struct mg_request_info" from mongoose.h header file
|
||||
[StructLayout(LayoutKind.Sequential)] public struct MongooseRequestInfo {
|
||||
public string request_method;
|
||||
public string uri;
|
||||
public string http_version;
|
||||
public string query_string;
|
||||
public IntPtr post_data;
|
||||
public string remote_user;
|
||||
public int remote_ip; //int to match the 32bit declaration in c
|
||||
public int remote_port;
|
||||
public int post_data_len;
|
||||
public int status_code;
|
||||
public int num_headers;
|
||||
[MarshalAs(UnmanagedType.ByValArray,SizeConst=64)] public MongooseHeader[] http_headers;
|
||||
};
|
||||
|
||||
// This is a delegate for mg_callback_t from mongoose.h header file
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
public delegate void MongooseCallback2(IntPtr conn, ref MongooseRequestInfo ri, IntPtr user_data);
|
||||
|
||||
// This is a delegate to be used by the application
|
||||
public delegate void MongooseCallback(MongooseConnection conn, MongooseRequestInfo ri);
|
||||
|
||||
public class Mongoose {
|
||||
public string version;
|
||||
private IntPtr ctx;
|
||||
//These two events are here to store a ref to the callbacks while they are over in unmanaged code.
|
||||
private event MongooseCallback2 delegates2;
|
||||
private event MongooseCallback delegates1;
|
||||
|
||||
[DllImport("_mongoose",CallingConvention=CallingConvention.Cdecl)] private static extern IntPtr mg_start();
|
||||
[DllImport("_mongoose",CallingConvention=CallingConvention.Cdecl)] private static extern void mg_stop(IntPtr ctx);
|
||||
[DllImport("_mongoose",CallingConvention=CallingConvention.Cdecl)] private static extern string mg_version();
|
||||
[DllImport("_mongoose",CallingConvention=CallingConvention.Cdecl)] private static extern int mg_set_option(IntPtr ctx, string name, string value);
|
||||
[DllImport("_mongoose",CallingConvention=CallingConvention.Cdecl)] private static extern string mg_get_option(IntPtr ctx, string name);
|
||||
[DllImport("_mongoose",CallingConvention=CallingConvention.Cdecl)] private static extern void mg_set_uri_callback(IntPtr ctx, string uri_regex, MulticastDelegate func, IntPtr data);
|
||||
[DllImport("_mongoose",CallingConvention=CallingConvention.Cdecl)] private static extern void mg_set_log_callback(IntPtr ctx, MulticastDelegate func);
|
||||
|
||||
public Mongoose() {
|
||||
ctx = mg_start();
|
||||
version = mg_version();
|
||||
}
|
||||
|
||||
~Mongoose() {
|
||||
mg_stop(this.ctx);
|
||||
this.ctx = IntPtr.Zero;
|
||||
}
|
||||
|
||||
public int set_option(string option_name, string option_value) {
|
||||
return mg_set_option(this.ctx, option_name, option_value);
|
||||
}
|
||||
|
||||
public string get_option(string option_name) {
|
||||
return mg_get_option(this.ctx, option_name);
|
||||
}
|
||||
|
||||
public void set_uri_callback(string uri_regex, MongooseCallback func) {
|
||||
// Build a closure around user function. Initialize connection object there which wraps
|
||||
// mg_write() and other useful methods, and then call user specified handler.
|
||||
MongooseCallback2 callback = delegate(IntPtr conn, ref MongooseRequestInfo ri, IntPtr user_data) {
|
||||
MongooseConnection connection = new MongooseConnection(conn, this);
|
||||
func(connection, ri);
|
||||
};
|
||||
// store a reference to the callback so it won't be GC'ed while its over in unmanged code
|
||||
delegates2 += callback;
|
||||
mg_set_uri_callback(this.ctx, uri_regex, callback, IntPtr.Zero);
|
||||
}
|
||||
|
||||
public void set_log_callback(MongooseCallback func) {
|
||||
delegates1 += func;
|
||||
mg_set_log_callback(this.ctx, func);
|
||||
}
|
||||
}
|
||||
|
||||
public class MongooseConnection {
|
||||
public Mongoose mongoose;
|
||||
private IntPtr conn;
|
||||
|
||||
[DllImport("_mongoose",CallingConvention=CallingConvention.Cdecl)] private static extern string mg_get_header(IntPtr ctx, string name);
|
||||
[DllImport("_mongoose",CallingConvention=CallingConvention.Cdecl)] private static extern string mg_get_var(IntPtr ctx, string name);
|
||||
[DllImport("_mongoose",CallingConvention=CallingConvention.Cdecl)] private static extern void mg_free(IntPtr ptr);
|
||||
[DllImport("_mongoose",CallingConvention=CallingConvention.Cdecl)] public static extern int mg_write(IntPtr conn, string data, int length);
|
||||
|
||||
public MongooseConnection(IntPtr conn_, Mongoose mongoose_) {
|
||||
mongoose = mongoose_;
|
||||
conn = conn_;
|
||||
}
|
||||
|
||||
public string get_header(string header_name) {
|
||||
return mg_get_header(this.conn, header_name);
|
||||
}
|
||||
|
||||
public string get_var(string header_name) {
|
||||
string s = mg_get_var(this.conn, header_name);
|
||||
string copy = "" + s;
|
||||
mg_free(Marshal.StringToHGlobalAnsi(s));
|
||||
return copy;
|
||||
}
|
||||
|
||||
public int write(string data) {
|
||||
return mg_write(this.conn, data, data.Length);
|
||||
}
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
# This is Python example on how to use Mongoose embeddable web server,
|
||||
# http://code.google.com/p/mongoose
|
||||
#
|
||||
# Before using the mongoose module, make sure that Mongoose shared library is
|
||||
# built and present in the current (or system library) directory
|
||||
|
||||
import mongoose
|
||||
import sys
|
||||
|
||||
# Handle /show and /form URIs.
|
||||
def EventHandler(event, conn):
|
||||
info = conn.info
|
||||
if event == mongoose.HTTP_ERROR:
|
||||
conn.printf('%s', 'HTTP/1.0 200 OK\r\n')
|
||||
conn.printf('%s', 'Content-Type: text/plain\r\n\r\n')
|
||||
conn.printf('HTTP error: %d\n', conn.reply_status_code)
|
||||
return True
|
||||
elif event == mongoose.NEW_REQUEST and info.uri == '/show':
|
||||
conn.printf('%s', 'HTTP/1.0 200 OK\r\n')
|
||||
conn.printf('%s', 'Content-Type: text/plain\r\n\r\n')
|
||||
conn.printf('%s %s\n', info.request_method, info.uri)
|
||||
if info.request_method == 'POST':
|
||||
content_len = conn.get_header('Content-Length')
|
||||
post_data = conn.read(int(content_len))
|
||||
my_var = conn.get_var(post_data, 'my_var')
|
||||
else:
|
||||
my_var = conn.get_var(info.query_string, 'my_var')
|
||||
conn.printf('my_var: %s\n', my_var or '<not set>')
|
||||
conn.printf('HEADERS: \n')
|
||||
for header in info.http_headers[:info.num_headers]:
|
||||
conn.printf(' %s: %s\n', header.name, header.value)
|
||||
return True
|
||||
elif event == mongoose.NEW_REQUEST and info.uri == '/form':
|
||||
conn.write('HTTP/1.0 200 OK\r\n'
|
||||
'Content-Type: text/html\r\n\r\n'
|
||||
'Use GET: <a href="/show?my_var=hello">link</a>'
|
||||
'<form action="/show" method="POST">'
|
||||
'Use POST: type text and submit: '
|
||||
'<input type="text" name="my_var"/>'
|
||||
'<input type="submit"/>'
|
||||
'</form>')
|
||||
return True
|
||||
elif event == mongoose.NEW_REQUEST and info.uri == '/secret':
|
||||
conn.send_file('/etc/passwd')
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
# Create mongoose object, and register '/foo' URI handler
|
||||
# List of options may be specified in the contructor
|
||||
server = mongoose.Mongoose(EventHandler,
|
||||
document_root='/tmp',
|
||||
listening_ports='8080')
|
||||
|
||||
print ('Mongoose started on port %s, press enter to quit'
|
||||
% server.get_option('listening_ports'))
|
||||
|
||||
sys.stdin.read(1)
|
||||
|
||||
# Deleting server object stops all serving threads
|
||||
print 'Stopping server.'
|
||||
del server
|
||||
@@ -1,170 +0,0 @@
|
||||
# Copyright (c) 2004-2009 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
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in
|
||||
# all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
# THE SOFTWARE.
|
||||
#
|
||||
# $Id: mongoose.py 471 2009-08-30 14:30:21Z valenok $
|
||||
|
||||
"""
|
||||
This module provides python binding for the Mongoose web server.
|
||||
|
||||
There are two classes defined:
|
||||
|
||||
Connection: - wraps all functions that accept struct mg_connection pointer
|
||||
as first argument.
|
||||
|
||||
Mongoose: wraps all functions that accept struct mg_context pointer as
|
||||
first argument.
|
||||
|
||||
Creating Mongoose object automatically starts server, deleting object
|
||||
automatically stops it. There is no need to call mg_start() or mg_stop().
|
||||
"""
|
||||
|
||||
|
||||
import ctypes
|
||||
import os
|
||||
|
||||
|
||||
NEW_REQUEST = 0
|
||||
REQUEST_COMPLETE = 1
|
||||
HTTP_ERROR = 2
|
||||
EVENT_LOG = 3
|
||||
INIT_SSL = 4
|
||||
WEBSOCKET_CONNECT = 5
|
||||
WEBSOCKET_READY = 6
|
||||
WEBSOCKET_MESSAGE = 7
|
||||
WEBSOCKET_CLOSE = 8
|
||||
|
||||
|
||||
class mg_header(ctypes.Structure):
|
||||
"""A wrapper for struct mg_header."""
|
||||
_fields_ = [
|
||||
('name', ctypes.c_char_p),
|
||||
('value', ctypes.c_char_p),
|
||||
]
|
||||
|
||||
|
||||
class mg_request_info(ctypes.Structure):
|
||||
"""A wrapper for struct mg_request_info."""
|
||||
_fields_ = [
|
||||
('request_method', ctypes.c_char_p),
|
||||
('uri', ctypes.c_char_p),
|
||||
('http_version', ctypes.c_char_p),
|
||||
('query_string', ctypes.c_char_p),
|
||||
('remote_user', ctypes.c_char_p),
|
||||
('remote_ip', ctypes.c_long),
|
||||
('remote_port', ctypes.c_int),
|
||||
('is_ssl', ctypes.c_int),
|
||||
('num_headers', ctypes.c_int),
|
||||
('http_headers', mg_header * 64),
|
||||
]
|
||||
|
||||
|
||||
mg_callback_t = ctypes.CFUNCTYPE(ctypes.c_void_p, ctypes.c_int, ctypes.c_void_p)
|
||||
|
||||
|
||||
class Connection(object):
|
||||
"""A wrapper class for all functions that take
|
||||
struct mg_connection * as the first argument."""
|
||||
|
||||
def __init__(self, mongoose, connection):
|
||||
self.m = mongoose
|
||||
self.conn = ctypes.c_void_p(connection)
|
||||
self.info = self.m.dll.mg_get_request_info(self.conn).contents
|
||||
self.user_data = self.m.dll.mg_get_user_data(self.conn)
|
||||
self.log_message = self.m.dll.mg_get_log_message(self.conn)
|
||||
self.reply_status_code = self.m.dll.mg_get_reply_status_code(self.conn)
|
||||
self.ssl_context = self.m.dll.mg_get_ssl_context(self.conn)
|
||||
|
||||
def get_header(self, name):
|
||||
val = self.m.dll.mg_get_header(self.conn, name)
|
||||
return ctypes.c_char_p(val).value
|
||||
|
||||
def get_var(self, data, name):
|
||||
size = data and len(data) or 0
|
||||
buf = ctypes.create_string_buffer(size)
|
||||
n = self.m.dll.mg_get_var(data, size, name, buf, size)
|
||||
return n >= 0 and buf or None
|
||||
|
||||
def printf(self, fmt, *args):
|
||||
val = self.m.dll.mg_printf(self.conn, fmt, *args)
|
||||
return ctypes.c_int(val).value
|
||||
|
||||
def write(self, data):
|
||||
val = self.m.dll.mg_write(self.conn, data, len(data))
|
||||
return ctypes.c_int(val).value
|
||||
|
||||
def read(self, size):
|
||||
buf = ctypes.create_string_buffer(size)
|
||||
n = self.m.dll.mg_read(self.conn, buf, size)
|
||||
return n <= 0 and None or buf[:n]
|
||||
|
||||
def send_file(self, path):
|
||||
self.m.dll.mg_send_file(self.conn, path)
|
||||
|
||||
|
||||
class Mongoose(object):
|
||||
"""A wrapper class for Mongoose shared library."""
|
||||
|
||||
def __init__(self, callback, **kwargs):
|
||||
if os.name == 'nt':
|
||||
self.dll = ctypes.WinDLL('mongoose.dll')
|
||||
else:
|
||||
self.dll = ctypes.CDLL('libmongoose.so')
|
||||
|
||||
self.dll.mg_start.restype = ctypes.c_void_p
|
||||
self.dll.mg_modify_passwords_file.restype = ctypes.c_int
|
||||
self.dll.mg_read.restype = ctypes.c_int
|
||||
self.dll.mg_write.restype = ctypes.c_int
|
||||
self.dll.mg_printf.restype = ctypes.c_int
|
||||
self.dll.mg_get_header.restype = ctypes.c_char_p
|
||||
self.dll.mg_get_var.restype = ctypes.c_int
|
||||
self.dll.mg_get_cookie.restype = ctypes.c_int
|
||||
self.dll.mg_get_option.restype = ctypes.c_char_p
|
||||
self.dll.mg_get_request_info.restype = ctypes.POINTER(mg_request_info)
|
||||
self.dll.mg_get_user_data.restype = ctypes.c_void_p
|
||||
self.dll.mg_get_reply_status_code.restype = ctypes.c_int
|
||||
self.dll.mg_get_log_message.restype = ctypes.c_char_p
|
||||
self.dll.mg_get_ssl_context.restype = ctypes.c_void_p
|
||||
|
||||
if callback:
|
||||
# Create a closure that will be called by the shared library.
|
||||
def func(event, connection):
|
||||
# Wrap connection pointer into the connection
|
||||
# object and call Python callback
|
||||
conn = Connection(self, connection)
|
||||
return callback(event, conn) and 1 or 0
|
||||
|
||||
# Convert the closure into C callable object
|
||||
self.callback = mg_callback_t(func)
|
||||
self.callback.restype = ctypes.c_char_p
|
||||
else:
|
||||
self.callback = ctypes.c_void_p(0)
|
||||
|
||||
args = [y for x in kwargs.items() for y in x] + [None]
|
||||
options = (ctypes.c_char_p * len(args))(*args)
|
||||
|
||||
ret = self.dll.mg_start(self.callback, 0, options)
|
||||
self.ctx = ctypes.c_void_p(ret)
|
||||
|
||||
def __del__(self):
|
||||
"""Destructor, stop Mongoose instance."""
|
||||
self.dll.mg_stop(self.ctx)
|
||||
|
||||
def get_option(self, name):
|
||||
return self.dll.mg_get_option(self.ctx, name)
|
||||
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleExecutable</key> <string>Mongoose</string>
|
||||
<key>CFBundlePackageType</key> <string>APPL</string>
|
||||
<key>CFBundleTypeRole</key> <string>None</string>
|
||||
<key>CFBundleIconFiles</key> <array>
|
||||
<string>mongoose_16x16.png</string>
|
||||
<string>mongoose_22x22.png</string>
|
||||
<string>mongoose_32x32.png</string>
|
||||
<string>mongoose_64x64.png</string>
|
||||
</array>
|
||||
<key>LSUIElement</key> <true/>
|
||||
<key>RunAtLoad</key> <true/>
|
||||
<key>Label</key> <string>com.kolkin.mongoose</string>
|
||||
<key>ProgramArguments</key> <array> </array>
|
||||
<key>KeepAlive</key> <true/>
|
||||
</dict>
|
||||
</plist>
|
||||
+218
@@ -0,0 +1,218 @@
|
||||
# This Makefile is part of Mongoose web server project,
|
||||
# https://github.com/valenok/mongoose
|
||||
#
|
||||
# This Makefile is GNU make compatible. You can get GNU Make from
|
||||
# http://gnuwin32.sourceforge.net/packages/make.htm
|
||||
#
|
||||
# Example custom build:
|
||||
# COPT="-g -O0 -DNO_SSL_DL -DUSE_LUA -llua -lcrypto -lssl" make linux
|
||||
#
|
||||
# Flags are:
|
||||
# -DHAVE_MD5 - use system md5 library (-2kb)
|
||||
# -DNDEBUG - strip off all debug code (-5kb)
|
||||
# -DDEBUG - build debug version (very noisy) (+7kb)
|
||||
# -DNO_CGI - disable CGI support (-5kb)
|
||||
# -DNO_SSL - disable SSL functionality (-2kb)
|
||||
# -DNO_SSL_DL - link against system libssl library (-1kb)
|
||||
# -DCONFIG_FILE=\"file\" - use `file' as the default config file
|
||||
# -DSSL_LIB=\"libssl.so.<version>\" - use system versioned SSL shared object
|
||||
# -DCRYPTO_LIB=\"libcrypto.so.<version>\" - use system versioned CRYPTO so
|
||||
# -DUSE_LUA - embed Lua in Mongoose (+100kb)
|
||||
|
||||
PROG = mongoose
|
||||
CFLAGS = -std=c99 -O2 -W -Wall -pedantic -pthread -pipe -I.. $(COPT)
|
||||
|
||||
# To build with Lua, download and unzip Lua 5.2.1 source code into the
|
||||
# mongoose directory, and then add $(LUA_SOURCES) to CFLAGS
|
||||
LUA = ../lua-5.2.1/src
|
||||
LUA_FLAGS = -DLUA_COMPAT_ALL
|
||||
LUA_SOURCES = $(LUA)/lapi.c $(LUA)/lcode.c $(LUA)/lctype.c \
|
||||
$(LUA)/ldebug.c $(LUA)/ldo.c $(LUA)/ldump.c \
|
||||
$(LUA)/lfunc.c $(LUA)/lgc.c $(LUA)/llex.c \
|
||||
$(LUA)/lmem.c $(LUA)/lobject.c $(LUA)/lopcodes.c \
|
||||
$(LUA)/lparser.c $(LUA)/lstate.c $(LUA)/lstring.c \
|
||||
$(LUA)/ltable.c $(LUA)/ltm.c $(LUA)/lundump.c \
|
||||
$(LUA)/lvm.c $(LUA)/lzio.c $(LUA)/lauxlib.c \
|
||||
$(LUA)/lbaselib.c $(LUA)/lbitlib.c $(LUA)/lcorolib.c \
|
||||
$(LUA)/ldblib.c $(LUA)/liolib.c $(LUA)/lmathlib.c \
|
||||
$(LUA)/loslib.c $(LUA)/lstrlib.c $(LUA)/ltablib.c \
|
||||
$(LUA)/loadlib.c $(LUA)/linit.c
|
||||
LUA_HEADERS = $(LUA)/llimits.h $(LUA)/lobject.h $(LUA)/lapi.h $(LUA)/lzio.h \
|
||||
$(LUA)/ldo.h $(LUA)/ltm.h $(LUA)/lstate.h $(LUA)/lgc.h \
|
||||
$(LUA)/lvm.h $(LUA)/ltable.h $(LUA)/lstring.h $(LUA)/lfunc.h \
|
||||
$(LUA)/lundump.h $(LUA)/ldebug.h $(LUA)/lopcodes.h $(LUA)/llex.h \
|
||||
$(LUA)/lparser.h $(LUA)/lcode.h $(LUA)/lmem.h $(LUA)/lctype.h
|
||||
LUA_WINOBJS = $(LUA_SOURCES:%.c=%.obj)
|
||||
|
||||
ifneq ($(OS), Windows_NT)
|
||||
LUA_FLAGS += -DLUA_USE_DLOPEN
|
||||
endif
|
||||
|
||||
lua_5.2.1.c: lua_5.2.1.h
|
||||
(echo '#define LUA_CORE' ; \
|
||||
echo '#define LUA_LIB' ; \
|
||||
echo '#define lobject_c' ; \
|
||||
echo '#define lua_c' ; \
|
||||
echo '#define ltable_c' ; \
|
||||
echo '#include "lua_5.2.1.h"' ; \
|
||||
cat $(LUA_HEADERS) $(LUA_SOURCES) | sed '/^#include "/d') > $@
|
||||
|
||||
lua_5.2.1.h:
|
||||
cat $(LUA)/luaconf.h $(LUA)/lua.h $(LUA)/lauxlib.h $(LUA)/lualib.h | \
|
||||
sed '/^#include "/d' > $@
|
||||
|
||||
# Stock windows binary builds with Lua and YASSL library.
|
||||
YASSL = ../../cyassl-2.4.6
|
||||
YASSL_FLAGS = -I $(YASSL) -I $(YASSL)/cyassl \
|
||||
-D _LIB -D OPENSSL_EXTRA -D HAVE_ERRNO_H \
|
||||
-D HAVE_GETHOSTBYNAME -D HAVE_INET_NTOA -D HAVE_LIMITS_H \
|
||||
-D HAVE_MEMSET -D HAVE_SOCKET -D HAVE_STDDEF_H -D HAVE_STDLIB_H \
|
||||
-D HAVE_STRING_H -D HAVE_SYS_STAT_H -D HAVE_SYS_TYPES_H
|
||||
YASSL_SOURCES = \
|
||||
$(YASSL)/src/internal.c $(YASSL)/src/io.c $(YASSL)/src/keys.c \
|
||||
$(YASSL)/src/ssl.c $(YASSL)/src/tls.c $(YASSL)/ctaocrypt/src/hmac.c \
|
||||
$(YASSL)/ctaocrypt/src/random.c $(YASSL)/ctaocrypt/src/sha.c \
|
||||
$(YASSL)/ctaocrypt/src/sha256.c $(YASSL)/ctaocrypt/src/logging.c \
|
||||
$(YASSL)/ctaocrypt/src/error.c $(YASSL)/ctaocrypt/src/rsa.c \
|
||||
$(YASSL)/ctaocrypt/src/des3.c $(YASSL)/ctaocrypt/src/asn.c \
|
||||
$(YASSL)/ctaocrypt/src/coding.c $(YASSL)/ctaocrypt/src/arc4.c \
|
||||
$(YASSL)/ctaocrypt/src/md4.c $(YASSL)/ctaocrypt/src/md5.c \
|
||||
$(YASSL)/ctaocrypt/src/dh.c $(YASSL)/ctaocrypt/src/dsa.c \
|
||||
$(YASSL)/ctaocrypt/src/pwdbased.c $(YASSL)/ctaocrypt/src/aes.c \
|
||||
$(YASSL)/ctaocrypt/src/md2.c $(YASSL)/ctaocrypt/src/ripemd.c \
|
||||
$(YASSL)/ctaocrypt/src/sha512.c $(YASSL)/src/sniffer.c \
|
||||
$(YASSL)/ctaocrypt/src/rabbit.c $(YASSL)/ctaocrypt/src/misc.c \
|
||||
$(YASSL)/ctaocrypt/src/tfm.c $(YASSL)/ctaocrypt/src/integer.c \
|
||||
$(YASSL)/ctaocrypt/src/ecc.c $(YASSL)/src/ocsp.c $(YASSL)/src/crl.c \
|
||||
$(YASSL)/ctaocrypt/src/hc128.c $(YASSL)/ctaocrypt/src/memory.c
|
||||
|
||||
ALL_SOURCES = ../mongoose.c main.c sqlite3.c lsqlite3.c lua_5.2.1.c \
|
||||
$(YASSL_SOURCES)
|
||||
ALL_OBJECTS = $(ALL_SOURCES:%.c=%.o)
|
||||
ALL_WINOBJS = $(ALL_SOURCES:%.c=%.obj)
|
||||
|
||||
SQLITE_FLAGS = -DTHREADSAFE=1 -DSQLITE_ENABLE_FTS3 -DSQLITE_ENABLE_FTS3_PARENTHESIS
|
||||
MONGOOSE_FLAGS = -DNO_SSL_DL -DUSE_LUA -DUSE_LUA_SQLITE3 -I.. $(COPT)
|
||||
|
||||
FLAGS = $(MONGOOSE_FLAGS) $(SQLITE_FLAGS) $(YASSL_FLAGS) $(LUA_FLAGS)
|
||||
|
||||
# Using Visual Studio 6.0. To build Mongoose:
|
||||
# Set MSVC variable below to where VS 6.0 is installed on your system
|
||||
# Run "PATH_TO_VC6\bin\nmake windows"
|
||||
MSVC = ../../vc6
|
||||
#DBG = /Zi /Od
|
||||
DBG = /DNDEBUG /O1
|
||||
CL = $(MSVC)/bin/cl /MD /TC /nologo $(DBG) /W3 /GA /I$(MSVC)/include
|
||||
LINK_FLAGS = /incremental:no /libpath:$(MSVC)/lib /machine:IX86 \
|
||||
user32.lib shell32.lib comdlg32.lib ws2_32.lib advapi32.lib
|
||||
LINK = $(MSVC)/bin/link $(LINK_FLAGS)
|
||||
|
||||
all:
|
||||
@echo "make (linux|bsd|solaris|mac|windows|mingw|cygwin)"
|
||||
|
||||
%.obj: %.c
|
||||
$(CL) /c $(FLAGS) /Fo$@ $<
|
||||
|
||||
%.o: %.c
|
||||
$(CC) -o $@ $< -c $(FLAGS) $(CFLAGS)
|
||||
|
||||
# Lua library for Windows
|
||||
lua.lib: $(LUA_WINOBJS)
|
||||
$(MSVC)/bin/lib /out:$@ $(LUA_WINOBJS)
|
||||
|
||||
# To build with lua, make sure you have Lua unpacked into lua-5.2.1 directory
|
||||
linux_lua: $(ALL_OBJECTS)
|
||||
$(CC) $(ALL_OBJECTS) -o $(PROG) -ldl
|
||||
|
||||
mongoose.o: mod_lua.c
|
||||
|
||||
# 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
|
||||
# "-Wl,--as-needed" turned on by default in cc command.
|
||||
# Also, this is turned in many other distros in static linkage builds.
|
||||
linux:
|
||||
$(CC) ../mongoose.c main.c -o $(PROG) -ldl $(CFLAGS)
|
||||
|
||||
mac: bsd
|
||||
bsd:
|
||||
$(CC) ../mongoose.c main.c -o $(PROG) $(CFLAGS)
|
||||
|
||||
bsd_lua: $(ALL_OBJECTS)
|
||||
$(CC) $(ALL_OBJECTS) -o $@
|
||||
|
||||
solaris:
|
||||
$(CC) ../mongoose.c main.c -lnsl -lsocket -o $(PROG) $(CFLAGS)
|
||||
|
||||
lib$(PROG).a: $(ALL_OBJECTS)
|
||||
ar cr $@ $(ALL_OBJECTS)
|
||||
|
||||
$(PROG).lib: $(ALL_WINOBJS)
|
||||
$(MSVC)/bin/lib /out:$@ $(ALL_WINOBJS)
|
||||
|
||||
# For codesign to work in non-interactive mode, unlock login keychain:
|
||||
# security unlock ~/Library/Keychains/login.keychain
|
||||
# See e.g. http://lists.apple.com/archives/apple-cdsa/2008/Jan/msg00027.html
|
||||
Mongoose: ../mongoose.c main.c
|
||||
$(CC) $(ALL_SOURCES) \
|
||||
-DUSE_COCOA $(CFLAGS) $(FLAGS) -mmacosx-version-min=10.4 \
|
||||
-framework Cocoa -ObjC -arch i386 -arch x86_64 -o Mongoose
|
||||
|
||||
cocoa: Mongoose
|
||||
V=`perl -lne '/define\s+MONGOOSE_VERSION\s+"(\S+)"/ and print $$1' ../mongoose.c`; DIR=dmg/Mongoose.app && rm -rf $$DIR && mkdir -p $$DIR/Contents/{MacOS,Resources} && install -m 644 mongoose_*.png $$DIR/Contents/Resources/ && install -m 644 Info.plist $$DIR/Contents/ && install -m 755 Mongoose $$DIR/Contents/MacOS/ && ln -fs /Applications dmg/ ; hdiutil create Mongoose-$$V.dmg -volname "Mongoose $$V" -srcfolder dmg -ov #; rm -rf dmg
|
||||
|
||||
un:
|
||||
$(CC) ../test/unit_test.c -o unit_test lua_5.2.1.c $(CFLAGS) -g -O0
|
||||
./unit_test
|
||||
|
||||
wi:
|
||||
$(CL) test/unit_test.c $(LUA_SOURCES) $(LUA_FLAGS) \
|
||||
$(YASSL_SOURCES) $(YASSL_FLAGS) /I. /DNO_SSL_DL \
|
||||
/link /libpath:$(MSVC)/lib advapi32.lib /out:unit_test.exe
|
||||
./unit_test.exe
|
||||
|
||||
windows: $(ALL_WINOBJS)
|
||||
$(MSVC)/bin/rc res.rc
|
||||
$(LINK) /nologo $(ALL_WINOBJS) res.res /out:$(PROG).exe
|
||||
|
||||
windows_tiny: $(ALL_SOURCES)
|
||||
$(MSVC)/bin/rc res.rc
|
||||
$(CL) /nologo ../mongoose.c main.c /I.. \
|
||||
/link $(LINK_FLAGS) res.res /out:$(PROG)-tiny.exe
|
||||
|
||||
# Build for Windows under MinGW
|
||||
#MINGWDBG= -DDEBUG -O0 -ggdb
|
||||
MINGWDBG= -DNDEBUG -Os
|
||||
MINGWOPT= -W -Wall -mthreads -Wl,--subsystem,console $(MINGWDBG) -DHAVE_STDINT $(GCC_WARNINGS) $(COPT)
|
||||
mingw:
|
||||
windres res.rc res.o
|
||||
$(CC) $(MINGWOPT) ../mongoose.c -lws2_32 \
|
||||
-shared -Wl,--out-implib=$(PROG).lib -o $(PROG).dll
|
||||
$(CC) $(MINGWOPT) ../mongoose.c main.c res.o \
|
||||
-lws2_32 -ladvapi32 -lcomdlg32 -o $(PROG).exe
|
||||
|
||||
# Build for Windows under Cygwin
|
||||
#CYGWINDBG= -DDEBUG -O0 -ggdb
|
||||
CYGWINDBG= -DNDEBUG -Os
|
||||
CYGWINOPT= -W -Wall -mthreads -Wl,--subsystem,console $(CYGWINDBG) -DHAVE_STDINT $(GCC_WARNINGS) $(COPT)
|
||||
cygwin:
|
||||
windres res.rc res.o
|
||||
$(CC) $(CYGWINOPT) ../mongoose.c -lws2_32 \
|
||||
-shared -Wl,--out-implib=$(PROG).lib -o $(PROG).dll
|
||||
$(CC) $(CYGWINOPT) -I.. ../mongoose.c main.c res.o \
|
||||
-lws2_32 -ladvapi32 -o $(PROG).exe
|
||||
|
||||
tests:
|
||||
perl ../test/test.pl $(TEST)
|
||||
|
||||
tarball: clean
|
||||
F=mongoose-`perl -lne '/define\s+MONGOOSE_VERSION\s+"(\S+)"/ and print $$1' ../mongoose.c`.tgz ; cd ../.. && tar -czf x mongoose/{LICENSE,*.[ch]} && mv x mongoose/build/$$F
|
||||
|
||||
release: tarball cocoa
|
||||
wine make windows windows_tiny
|
||||
V=`perl -lne '/define\s+MONGOOSE_VERSION\s+"(\S+)"/ and print $$1' ../mongoose.c`; upx mongoose.exe; upx mongoose-tiny.exe ; cp mongoose.exe mongoose-$$V.exe; cp mongoose-tiny.exe mongoose-tiny-$$V.exe; cp mongoose.exe mongoose_php_bundle/; zip -r mongoose-php-$$V.zip mongoose_php_bundle/
|
||||
|
||||
clean:
|
||||
cd ../examples && $(MAKE) clean
|
||||
rm -rf *.o *.core $(PROG) *.obj *.so $(PROG).txt *.dSYM *.tgz \
|
||||
$(PROG).exe *.dll *.lib res.o res.RES *.dSYM *.zip *.pdb \
|
||||
*.exe *dmg* $(ALL_OBJECTS) $(ALL_WINOBJS)
|
||||
File renamed without changes.
@@ -0,0 +1,6 @@
|
||||
LOCAL_PATH := $(call my-dir)/../..
|
||||
include $(CLEAR_VARS)
|
||||
LOCAL_CFLAGS := -std=c99 -O2 -W -Wall -pthread -pipe $(COPT)
|
||||
LOCAL_MODULE := mongoose
|
||||
LOCAL_SRC_FILES := main.c mongoose.c
|
||||
include $(BUILD_EXECUTABLE)
|
||||
+1883
File diff suppressed because it is too large.
Load diff
+17698
File diff suppressed because it is too large.
Load diff
+1247
File diff suppressed because it is too large.
Load diff
+985
@@ -0,0 +1,985 @@
|
||||
// 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
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
#if defined(_WIN32)
|
||||
#define _CRT_SECURE_NO_WARNINGS // Disable deprecation warning in VS2005
|
||||
#else
|
||||
#define _XOPEN_SOURCE 600 // For PATH_MAX on linux
|
||||
#endif
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <signal.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <stddef.h>
|
||||
#include <stdarg.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include "mongoose.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#include <winsvc.h>
|
||||
#include <shlobj.h>
|
||||
|
||||
#ifndef PATH_MAX
|
||||
#define PATH_MAX MAX_PATH
|
||||
#endif
|
||||
|
||||
#ifndef S_ISDIR
|
||||
#define S_ISDIR(x) ((x) & _S_IFDIR)
|
||||
#endif
|
||||
|
||||
#define DIRSEP '\\'
|
||||
#define snprintf _snprintf
|
||||
#define vsnprintf _vsnprintf
|
||||
#define sleep(x) Sleep((x) * 1000)
|
||||
#define WINCDECL __cdecl
|
||||
#define abs_path(rel, abs, abs_size) _fullpath((abs), (rel), (abs_size))
|
||||
#else
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
#define DIRSEP '/'
|
||||
#define WINCDECL
|
||||
#define abs_path(rel, abs, abs_size) realpath((rel), (abs))
|
||||
#endif // _WIN32
|
||||
|
||||
#define MAX_OPTIONS 100
|
||||
#define MAX_CONF_FILE_LINE_SIZE (8 * 1024)
|
||||
|
||||
static int exit_flag;
|
||||
static char server_name[40]; // Set by init_server_name()
|
||||
static char config_file[PATH_MAX]; // Set by process_command_line_arguments()
|
||||
static struct mg_context *ctx; // Set by start_mongoose()
|
||||
|
||||
#if !defined(CONFIG_FILE)
|
||||
#define CONFIG_FILE "mongoose.conf"
|
||||
#endif /* !CONFIG_FILE */
|
||||
|
||||
static void WINCDECL signal_handler(int sig_num) {
|
||||
#if !defined(_WIN32)
|
||||
// Do not do the trick with ignoring SIGCHLD, cause not all OSes (e.g. QNX)
|
||||
// reap zombies if SIGCHLD is ignored. On QNX, for example, waitpid()
|
||||
// fails if SIGCHLD is ignored, making system() non-functional.
|
||||
if (sig_num == SIGCHLD) {
|
||||
do {} while (waitpid(-1, &sig_num, WNOHANG) > 0);
|
||||
} else
|
||||
#endif
|
||||
{ exit_flag = sig_num; }
|
||||
}
|
||||
|
||||
static void die(const char *fmt, ...) {
|
||||
va_list ap;
|
||||
char msg[200];
|
||||
|
||||
va_start(ap, fmt);
|
||||
vsnprintf(msg, sizeof(msg), fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
#if defined(_WIN32)
|
||||
MessageBox(NULL, msg, "Error", MB_OK);
|
||||
#else
|
||||
fprintf(stderr, "%s\n", msg);
|
||||
#endif
|
||||
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
static void show_usage_and_exit(void) {
|
||||
const char **names;
|
||||
int i;
|
||||
|
||||
fprintf(stderr, "Mongoose version %s (c) Sergey Lyubka, built on %s\n",
|
||||
mg_version(), __DATE__);
|
||||
fprintf(stderr, "Usage:\n");
|
||||
fprintf(stderr, " mongoose -A <htpasswd_file> <realm> <user> <passwd>\n");
|
||||
fprintf(stderr, " mongoose [config_file]\n");
|
||||
fprintf(stderr, " mongoose [-option value ...]\n");
|
||||
fprintf(stderr, "\nOPTIONS:\n");
|
||||
|
||||
names = mg_get_valid_option_names();
|
||||
for (i = 0; names[i] != NULL; i += 2) {
|
||||
fprintf(stderr, " -%s %s\n",
|
||||
names[i], names[i + 1] == NULL ? "<empty>" : names[i + 1]);
|
||||
}
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
#if defined(_WIN32) || defined(USE_COCOA)
|
||||
static const char *config_file_top_comment =
|
||||
"# Mongoose web server configuration file.\n"
|
||||
"# For detailed description of every option, visit\n"
|
||||
"# https://github.com/valenok/mongoose/blob/master/UserManual.md\n"
|
||||
"# Lines starting with '#' and empty lines are ignored.\n"
|
||||
"# To make a change, remove leading '#', modify option's value,\n"
|
||||
"# save this file and then restart Mongoose.\n\n";
|
||||
|
||||
static const char *get_url_to_first_open_port(const struct mg_context *ctx) {
|
||||
static char url[100];
|
||||
const char *open_ports = mg_get_option(ctx, "listening_ports");
|
||||
int a, b, c, d, port, n;
|
||||
|
||||
if (sscanf(open_ports, "%d.%d.%d.%d:%d%n", &a, &b, &c, &d, &port, &n) == 5) {
|
||||
snprintf(url, sizeof(url), "%s://%d.%d.%d.%d:%d",
|
||||
open_ports[n] == 's' ? "https" : "http", a, b, c, d, port);
|
||||
} else if (sscanf(open_ports, "%d%n", &port, &n) == 1) {
|
||||
snprintf(url, sizeof(url), "%s://localhost:%d",
|
||||
open_ports[n] == 's' ? "https" : "http", port);
|
||||
} else {
|
||||
snprintf(url, sizeof(url), "%s", "http://localhost:8080");
|
||||
}
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
static void create_config_file(const char *path) {
|
||||
const char **names, *value;
|
||||
FILE *fp;
|
||||
int i;
|
||||
|
||||
// Create config file if it is not present yet
|
||||
if ((fp = fopen(path, "r")) != NULL) {
|
||||
fclose(fp);
|
||||
} else if ((fp = fopen(path, "a+")) != NULL) {
|
||||
fprintf(fp, "%s", config_file_top_comment);
|
||||
names = mg_get_valid_option_names();
|
||||
for (i = 0; names[i * 2] != NULL; i++) {
|
||||
value = mg_get_option(ctx, names[i * 2]);
|
||||
fprintf(fp, "# %s %s\n", names[i * 2], value ? value : "<value>");
|
||||
}
|
||||
fclose(fp);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static char *sdup(const char *str) {
|
||||
char *p;
|
||||
if ((p = (char *) malloc(strlen(str) + 1)) != NULL) {
|
||||
strcpy(p, str);
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
static void set_option(char **options, const char *name, const char *value) {
|
||||
int i;
|
||||
|
||||
for (i = 0; i < MAX_OPTIONS - 3; i++) {
|
||||
if (options[i] == NULL) {
|
||||
options[i] = sdup(name);
|
||||
options[i + 1] = sdup(value);
|
||||
options[i + 2] = NULL;
|
||||
break;
|
||||
} else if (!strcmp(options[i], name)) {
|
||||
free(options[i + 1]);
|
||||
options[i + 1] = sdup(value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (i == MAX_OPTIONS - 3) {
|
||||
die("%s", "Too many options specified");
|
||||
}
|
||||
}
|
||||
|
||||
static void process_command_line_arguments(char *argv[], char **options) {
|
||||
char line[MAX_CONF_FILE_LINE_SIZE], opt[sizeof(line)], val[sizeof(line)], *p;
|
||||
FILE *fp = NULL;
|
||||
size_t i, cmd_line_opts_start = 1, line_no = 0;
|
||||
|
||||
// Should we use a config file ?
|
||||
if (argv[1] != NULL && argv[1][0] != '-') {
|
||||
snprintf(config_file, sizeof(config_file), "%s", argv[1]);
|
||||
cmd_line_opts_start = 2;
|
||||
} else if ((p = strrchr(argv[0], DIRSEP)) == NULL) {
|
||||
// No command line flags specified. Look where binary lives
|
||||
snprintf(config_file, sizeof(config_file), "%s", CONFIG_FILE);
|
||||
} else {
|
||||
snprintf(config_file, sizeof(config_file), "%.*s%c%s",
|
||||
(int) (p - argv[0]), argv[0], DIRSEP, CONFIG_FILE);
|
||||
}
|
||||
|
||||
fp = fopen(config_file, "r");
|
||||
|
||||
// If config file was set in command line and open failed, die
|
||||
if (cmd_line_opts_start == 2 && fp == NULL) {
|
||||
die("Cannot open config file %s: %s", config_file, strerror(errno));
|
||||
}
|
||||
|
||||
// Load config file settings first
|
||||
if (fp != NULL) {
|
||||
fprintf(stderr, "Loading config file %s\n", config_file);
|
||||
|
||||
// Loop over the lines in config file
|
||||
while (fgets(line, sizeof(line), fp) != NULL) {
|
||||
line_no++;
|
||||
|
||||
// Ignore empty lines and comments
|
||||
for (i = 0; isspace(* (unsigned char *) &line[i]); ) i++;
|
||||
if (line[i] == '#' || line[i] == '\0') {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (sscanf(line, "%s %[^\r\n#]", opt, val) != 2) {
|
||||
printf("%s: line %d is invalid, ignoring it:\n %s",
|
||||
config_file, (int) line_no, line);
|
||||
} else {
|
||||
set_option(options, opt, val);
|
||||
}
|
||||
}
|
||||
|
||||
(void) fclose(fp);
|
||||
}
|
||||
|
||||
// If we're under MacOS and started by launchd, then the second
|
||||
// argument is process serial number, -psn_.....
|
||||
// In this case, don't process arguments at all.
|
||||
if (argv[1] == NULL || memcmp(argv[1], "-psn_", 5) != 0) {
|
||||
// Handle command line flags.
|
||||
// They override config file and default settings.
|
||||
for (i = cmd_line_opts_start; argv[i] != NULL; i += 2) {
|
||||
if (argv[i][0] != '-' || argv[i + 1] == NULL) {
|
||||
show_usage_and_exit();
|
||||
}
|
||||
set_option(options, &argv[i][1], argv[i + 1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void init_server_name(void) {
|
||||
snprintf(server_name, sizeof(server_name), "Mongoose web server v.%s",
|
||||
mg_version());
|
||||
}
|
||||
|
||||
static int log_message(const struct mg_connection *conn, const char *message) {
|
||||
(void) conn;
|
||||
printf("%s\n", message);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int is_path_absolute(const char *path) {
|
||||
#ifdef _WIN32
|
||||
return path != NULL &&
|
||||
((path[0] == '\\' && path[1] == '\\') || // UNC path, e.g. \\server\dir
|
||||
(isalpha(path[0]) && path[1] == ':' && path[2] == '\\')); // E.g. X:\dir
|
||||
#else
|
||||
return path != NULL && path[0] == '/';
|
||||
#endif
|
||||
}
|
||||
|
||||
static char *get_option(char **options, const char *option_name) {
|
||||
int i;
|
||||
|
||||
for (i = 0; options[i] != NULL; i++)
|
||||
if (!strcmp(options[i], option_name))
|
||||
return options[i + 1];
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void verify_existence(char **options, const char *option_name,
|
||||
int must_be_dir) {
|
||||
struct stat st;
|
||||
const char *path = get_option(options, option_name);
|
||||
|
||||
if (path != NULL && (stat(path, &st) != 0 ||
|
||||
((S_ISDIR(st.st_mode) ? 1 : 0) != must_be_dir))) {
|
||||
die("Invalid path for %s: [%s]: (%s). Make sure that path is either "
|
||||
"absolute, or it is relative to mongoose executable.",
|
||||
option_name, path, strerror(errno));
|
||||
}
|
||||
}
|
||||
|
||||
static void set_absolute_path(char *options[], const char *option_name,
|
||||
const char *path_to_mongoose_exe) {
|
||||
char path[PATH_MAX], abs[PATH_MAX], *option_value;
|
||||
const char *p;
|
||||
|
||||
// Check whether option is already set
|
||||
option_value = get_option(options, option_name);
|
||||
|
||||
// If option is already set and it is an absolute path,
|
||||
// leave it as it is -- it's already absolute.
|
||||
if (option_value != NULL && !is_path_absolute(option_value)) {
|
||||
// Not absolute. Use the directory where mongoose executable lives
|
||||
// be the relative directory for everything.
|
||||
// Extract mongoose executable directory into path.
|
||||
if ((p = strrchr(path_to_mongoose_exe, DIRSEP)) == NULL) {
|
||||
getcwd(path, sizeof(path));
|
||||
} else {
|
||||
snprintf(path, sizeof(path), "%.*s", (int) (p - path_to_mongoose_exe),
|
||||
path_to_mongoose_exe);
|
||||
}
|
||||
|
||||
strncat(path, "/", sizeof(path) - 1);
|
||||
strncat(path, option_value, sizeof(path) - 1);
|
||||
|
||||
// Absolutize the path, and set the option
|
||||
abs_path(path, abs, sizeof(abs));
|
||||
set_option(options, option_name, abs);
|
||||
}
|
||||
}
|
||||
|
||||
static void start_mongoose(int argc, char *argv[]) {
|
||||
struct mg_callbacks callbacks;
|
||||
char *options[MAX_OPTIONS];
|
||||
int i;
|
||||
|
||||
// Edit passwords file if -A option is specified
|
||||
if (argc > 1 && !strcmp(argv[1], "-A")) {
|
||||
if (argc != 6) {
|
||||
show_usage_and_exit();
|
||||
}
|
||||
exit(mg_modify_passwords_file(argv[2], argv[3], argv[4], argv[5]) ?
|
||||
EXIT_SUCCESS : EXIT_FAILURE);
|
||||
}
|
||||
|
||||
// Show usage if -h or --help options are specified
|
||||
if (argc == 2 && (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help"))) {
|
||||
show_usage_and_exit();
|
||||
}
|
||||
|
||||
options[0] = NULL;
|
||||
set_option(options, "document_root", ".");
|
||||
|
||||
// Update config based on command line arguments
|
||||
process_command_line_arguments(argv, options);
|
||||
|
||||
// Make sure we have absolute paths for files and directories
|
||||
// https://github.com/valenok/mongoose/issues/181
|
||||
set_absolute_path(options, "document_root", argv[0]);
|
||||
set_absolute_path(options, "put_delete_auth_file", argv[0]);
|
||||
set_absolute_path(options, "cgi_interpreter", argv[0]);
|
||||
set_absolute_path(options, "access_log_file", argv[0]);
|
||||
set_absolute_path(options, "error_log_file", argv[0]);
|
||||
set_absolute_path(options, "global_auth_file", argv[0]);
|
||||
set_absolute_path(options, "ssl_certificate", argv[0]);
|
||||
|
||||
// Make extra verification for certain options
|
||||
verify_existence(options, "document_root", 1);
|
||||
verify_existence(options, "cgi_interpreter", 0);
|
||||
verify_existence(options, "ssl_certificate", 0);
|
||||
|
||||
// Setup signal handler: quit on Ctrl-C
|
||||
signal(SIGTERM, signal_handler);
|
||||
signal(SIGINT, signal_handler);
|
||||
|
||||
// Start Mongoose
|
||||
memset(&callbacks, 0, sizeof(callbacks));
|
||||
callbacks.log_message = &log_message;
|
||||
ctx = mg_start(&callbacks, NULL, (const char **) options);
|
||||
for (i = 0; options[i] != NULL; i++) {
|
||||
free(options[i]);
|
||||
}
|
||||
|
||||
if (ctx == NULL) {
|
||||
die("%s", "Failed to start Mongoose.");
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
enum {
|
||||
ID_ICON = 100, ID_QUIT, ID_SETTINGS, ID_SEPARATOR, ID_INSTALL_SERVICE,
|
||||
ID_REMOVE_SERVICE, ID_STATIC, ID_GROUP, ID_SAVE, ID_RESET_DEFAULTS,
|
||||
ID_STATUS, ID_CONNECT,
|
||||
|
||||
// All dynamically created text boxes for options have IDs starting from
|
||||
// ID_CONTROLS, incremented by one.
|
||||
ID_CONTROLS = 200,
|
||||
|
||||
// Text boxes for files have "..." buttons to open file browser. These
|
||||
// buttons have IDs that are ID_FILE_BUTTONS_DELTA higher than associated
|
||||
// text box ID.
|
||||
ID_FILE_BUTTONS_DELTA = 1000
|
||||
};
|
||||
static HICON hIcon;
|
||||
static SERVICE_STATUS ss;
|
||||
static SERVICE_STATUS_HANDLE hStatus;
|
||||
static const char *service_magic_argument = "--";
|
||||
static NOTIFYICONDATA TrayIcon;
|
||||
|
||||
static void WINAPI ControlHandler(DWORD code) {
|
||||
if (code == SERVICE_CONTROL_STOP || code == SERVICE_CONTROL_SHUTDOWN) {
|
||||
ss.dwWin32ExitCode = 0;
|
||||
ss.dwCurrentState = SERVICE_STOPPED;
|
||||
}
|
||||
SetServiceStatus(hStatus, &ss);
|
||||
}
|
||||
|
||||
static void WINAPI ServiceMain(void) {
|
||||
ss.dwServiceType = SERVICE_WIN32;
|
||||
ss.dwCurrentState = SERVICE_RUNNING;
|
||||
ss.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN;
|
||||
|
||||
hStatus = RegisterServiceCtrlHandler(server_name, ControlHandler);
|
||||
SetServiceStatus(hStatus, &ss);
|
||||
|
||||
while (ss.dwCurrentState == SERVICE_RUNNING) {
|
||||
Sleep(1000);
|
||||
}
|
||||
mg_stop(ctx);
|
||||
|
||||
ss.dwCurrentState = SERVICE_STOPPED;
|
||||
ss.dwWin32ExitCode = (DWORD) -1;
|
||||
SetServiceStatus(hStatus, &ss);
|
||||
}
|
||||
|
||||
|
||||
static void show_error(void) {
|
||||
char buf[256];
|
||||
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||
NULL, GetLastError(),
|
||||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||
buf, sizeof(buf), NULL);
|
||||
MessageBox(NULL, buf, "Error", MB_OK);
|
||||
}
|
||||
|
||||
static void *align(void *ptr, DWORD alig) {
|
||||
ULONG ul = (ULONG) ptr;
|
||||
ul += alig;
|
||||
ul &= ~alig;
|
||||
return ((void *) ul);
|
||||
}
|
||||
|
||||
static int is_boolean_option(const char *option_name) {
|
||||
return !strcmp(option_name, "enable_directory_listing") ||
|
||||
!strcmp(option_name, "enable_keep_alive");
|
||||
}
|
||||
|
||||
static int is_filename_option(const char *option_name) {
|
||||
return !strcmp(option_name, "cgi_interpreter") ||
|
||||
!strcmp(option_name, "global_auth_file") ||
|
||||
!strcmp(option_name, "put_delete_auth_file") ||
|
||||
!strcmp(option_name, "access_log_file") ||
|
||||
!strcmp(option_name, "error_log_file") ||
|
||||
!strcmp(option_name, "ssl_certificate");
|
||||
}
|
||||
|
||||
static int is_directory_option(const char *option_name) {
|
||||
return !strcmp(option_name, "document_root");
|
||||
}
|
||||
|
||||
static int is_numeric_options(const char *option_name) {
|
||||
return !strcmp(option_name, "num_threads");
|
||||
}
|
||||
|
||||
static void save_config(HWND hDlg, FILE *fp) {
|
||||
char value[2000];
|
||||
const char **options, *name, *default_value;
|
||||
int i, id;
|
||||
|
||||
fprintf(fp, "%s", config_file_top_comment);
|
||||
options = mg_get_valid_option_names();
|
||||
for (i = 0; options[i * 2] != NULL; i++) {
|
||||
name = options[i * 2];
|
||||
id = ID_CONTROLS + i;
|
||||
if (is_boolean_option(name)) {
|
||||
snprintf(value, sizeof(value), "%s",
|
||||
IsDlgButtonChecked(hDlg, id) ? "yes" : "no");
|
||||
} else {
|
||||
GetDlgItemText(hDlg, id, value, sizeof(value));
|
||||
}
|
||||
default_value = options[i * 2 + 1] == NULL ? "" : options[i * 2 + 1];
|
||||
// If value is the same as default, skip it
|
||||
if (strcmp(value, default_value) != 0) {
|
||||
fprintf(fp, "%s %s\n", name, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static BOOL CALLBACK DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lP) {
|
||||
FILE *fp;
|
||||
int i;
|
||||
const char *name, *value, **options = mg_get_valid_option_names();
|
||||
|
||||
switch (msg) {
|
||||
case WM_CLOSE:
|
||||
DestroyWindow(hDlg);
|
||||
break;
|
||||
|
||||
case WM_COMMAND:
|
||||
switch (LOWORD(wParam)) {
|
||||
case ID_SAVE:
|
||||
EnableWindow(GetDlgItem(hDlg, ID_SAVE), FALSE);
|
||||
if ((fp = fopen(config_file, "w+")) != NULL) {
|
||||
save_config(hDlg, fp);
|
||||
fclose(fp);
|
||||
mg_stop(ctx);
|
||||
start_mongoose(__argc, __argv);
|
||||
}
|
||||
EnableWindow(GetDlgItem(hDlg, ID_SAVE), TRUE);
|
||||
break;
|
||||
case ID_RESET_DEFAULTS:
|
||||
for (i = 0; options[i * 2] != NULL; i++) {
|
||||
name = options[i * 2];
|
||||
value = options[i * 2 + 1] == NULL ? "" : options[i * 2 + 1];
|
||||
if (is_boolean_option(name)) {
|
||||
CheckDlgButton(hDlg, ID_CONTROLS + i, !strcmp(value, "yes") ?
|
||||
BST_CHECKED : BST_UNCHECKED);
|
||||
} else {
|
||||
SetWindowText(GetDlgItem(hDlg, ID_CONTROLS + i), value);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
for (i = 0; options[i * 2] != NULL; i++) {
|
||||
name = options[i * 2];
|
||||
if ((is_filename_option(name) || is_directory_option(name)) &&
|
||||
LOWORD(wParam) == ID_CONTROLS + i + ID_FILE_BUTTONS_DELTA) {
|
||||
OPENFILENAME of;
|
||||
BROWSEINFO bi;
|
||||
char path[PATH_MAX] = "";
|
||||
|
||||
memset(&of, 0, sizeof(of));
|
||||
of.lStructSize = sizeof(of);
|
||||
of.hwndOwner = (HWND) hDlg;
|
||||
of.lpstrFile = path;
|
||||
of.nMaxFile = sizeof(path);
|
||||
of.lpstrInitialDir = mg_get_option(ctx, "document_root");
|
||||
of.Flags = OFN_CREATEPROMPT | OFN_NOCHANGEDIR;
|
||||
|
||||
memset(&bi, 0, sizeof(bi));
|
||||
bi.hwndOwner = (HWND) hDlg;
|
||||
bi.lpszTitle = "Choose WWW root directory:";
|
||||
bi.ulFlags = BIF_RETURNONLYFSDIRS;
|
||||
|
||||
if (is_directory_option(name)) {
|
||||
SHGetPathFromIDList(SHBrowseForFolder(&bi), path);
|
||||
} else {
|
||||
GetOpenFileName(&of);
|
||||
}
|
||||
|
||||
if (path[0] != '\0') {
|
||||
SetWindowText(GetDlgItem(hDlg, ID_CONTROLS + i), path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case WM_INITDIALOG:
|
||||
SendMessage(hDlg, WM_SETICON,(WPARAM) ICON_SMALL, (LPARAM) hIcon);
|
||||
SendMessage(hDlg, WM_SETICON,(WPARAM) ICON_BIG, (LPARAM) hIcon);
|
||||
SetWindowText(hDlg, "Mongoose settings");
|
||||
SetFocus(GetDlgItem(hDlg, ID_SAVE));
|
||||
for (i = 0; options[i * 2] != NULL; i++) {
|
||||
name = options[i * 2];
|
||||
value = mg_get_option(ctx, name);
|
||||
if (is_boolean_option(name)) {
|
||||
CheckDlgButton(hDlg, ID_CONTROLS + i, !strcmp(value, "yes") ?
|
||||
BST_CHECKED : BST_UNCHECKED);
|
||||
} else {
|
||||
SetDlgItemText(hDlg, ID_CONTROLS + i, value == NULL ? "" : value);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void add_control(unsigned char **mem, DLGTEMPLATE *dia, WORD type,
|
||||
DWORD id, DWORD style, WORD x, WORD y,
|
||||
WORD cx, WORD cy, const char *caption) {
|
||||
DLGITEMTEMPLATE *tp;
|
||||
LPWORD p;
|
||||
|
||||
dia->cdit++;
|
||||
|
||||
*mem = align(*mem, 3);
|
||||
tp = (DLGITEMTEMPLATE *) *mem;
|
||||
|
||||
tp->id = (WORD)id;
|
||||
tp->style = style;
|
||||
tp->dwExtendedStyle = 0;
|
||||
tp->x = x;
|
||||
tp->y = y;
|
||||
tp->cx = cx;
|
||||
tp->cy = cy;
|
||||
|
||||
p = align(*mem + sizeof(*tp), 1);
|
||||
*p++ = 0xffff;
|
||||
*p++ = type;
|
||||
|
||||
while (*caption != '\0') {
|
||||
*p++ = (WCHAR) *caption++;
|
||||
}
|
||||
*p++ = 0;
|
||||
p = align(p, 1);
|
||||
|
||||
*p++ = 0;
|
||||
*mem = (unsigned char *) p;
|
||||
}
|
||||
|
||||
static void show_settings_dialog() {
|
||||
#define HEIGHT 15
|
||||
#define WIDTH 400
|
||||
#define LABEL_WIDTH 80
|
||||
|
||||
unsigned char mem[4096], *p;
|
||||
const char **option_names, *long_option_name;
|
||||
DWORD style;
|
||||
DLGTEMPLATE *dia = (DLGTEMPLATE *) mem;
|
||||
WORD i, cl, x, y, width, nelems = 0;
|
||||
static int guard;
|
||||
|
||||
static struct {
|
||||
DLGTEMPLATE template; // 18 bytes
|
||||
WORD menu, class;
|
||||
wchar_t caption[1];
|
||||
WORD fontsiz;
|
||||
wchar_t fontface[7];
|
||||
} dialog_header = {{WS_CAPTION | WS_POPUP | WS_SYSMENU | WS_VISIBLE |
|
||||
DS_SETFONT | WS_DLGFRAME, WS_EX_TOOLWINDOW, 0, 200, 200, WIDTH, 0},
|
||||
0, 0, L"", 8, L"Tahoma"};
|
||||
|
||||
if (guard == 0) {
|
||||
guard++;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
(void) memset(mem, 0, sizeof(mem));
|
||||
(void) memcpy(mem, &dialog_header, sizeof(dialog_header));
|
||||
p = mem + sizeof(dialog_header);
|
||||
|
||||
option_names = mg_get_valid_option_names();
|
||||
for (i = 0; option_names[i * 2] != NULL; i++) {
|
||||
long_option_name = option_names[i * 2];
|
||||
style = WS_CHILD | WS_VISIBLE | WS_TABSTOP;
|
||||
x = 10 + (WIDTH / 2) * (nelems % 2);
|
||||
y = (nelems/2 + 1) * HEIGHT + 5;
|
||||
width = WIDTH / 2 - 20 - LABEL_WIDTH;
|
||||
if (is_numeric_options(long_option_name)) {
|
||||
style |= ES_NUMBER;
|
||||
cl = 0x81;
|
||||
style |= WS_BORDER | ES_AUTOHSCROLL;
|
||||
} else if (is_boolean_option(long_option_name)) {
|
||||
cl = 0x80;
|
||||
style |= BS_AUTOCHECKBOX;
|
||||
} else if (is_filename_option(long_option_name) ||
|
||||
is_directory_option(long_option_name)) {
|
||||
style |= WS_BORDER | ES_AUTOHSCROLL;
|
||||
width -= 20;
|
||||
cl = 0x81;
|
||||
add_control(&p, dia, 0x80,
|
||||
ID_CONTROLS + i + ID_FILE_BUTTONS_DELTA,
|
||||
WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON,
|
||||
(WORD) (x + width + LABEL_WIDTH + 5),
|
||||
y, 15, 12, "...");
|
||||
} else {
|
||||
cl = 0x81;
|
||||
style |= WS_BORDER | ES_AUTOHSCROLL;
|
||||
}
|
||||
add_control(&p, dia, 0x82, ID_STATIC, WS_VISIBLE | WS_CHILD,
|
||||
x, y, LABEL_WIDTH, HEIGHT, long_option_name);
|
||||
add_control(&p, dia, cl, ID_CONTROLS + i, style,
|
||||
(WORD) (x + LABEL_WIDTH), y, width, 12, "");
|
||||
nelems++;
|
||||
}
|
||||
|
||||
y = (WORD) (((nelems + 1) / 2 + 1) * HEIGHT + 5);
|
||||
add_control(&p, dia, 0x80, ID_GROUP, WS_CHILD | WS_VISIBLE |
|
||||
BS_GROUPBOX, 5, 5, WIDTH - 10, y, " Settings ");
|
||||
y += 10;
|
||||
add_control(&p, dia, 0x80, ID_SAVE,
|
||||
WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | WS_TABSTOP,
|
||||
WIDTH - 70, y, 65, 12, "Save Settings");
|
||||
add_control(&p, dia, 0x80, ID_RESET_DEFAULTS,
|
||||
WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | WS_TABSTOP,
|
||||
WIDTH - 140, y, 65, 12, "Reset to defaults");
|
||||
add_control(&p, dia, 0x82, ID_STATIC,
|
||||
WS_CHILD | WS_VISIBLE | WS_DISABLED,
|
||||
5, y, 180, 12, server_name);
|
||||
|
||||
dia->cy = ((nelems + 1) / 2 + 1) * HEIGHT + 30;
|
||||
DialogBoxIndirectParam(NULL, dia, NULL, DlgProc, (LPARAM) NULL);
|
||||
guard--;
|
||||
}
|
||||
|
||||
static int manage_service(int action) {
|
||||
static const char *service_name = "Mongoose";
|
||||
SC_HANDLE hSCM = NULL, hService = NULL;
|
||||
SERVICE_DESCRIPTION descr = {server_name};
|
||||
char path[PATH_MAX + 20]; // Path to executable plus magic argument
|
||||
int success = 1;
|
||||
|
||||
if ((hSCM = OpenSCManager(NULL, NULL, action == ID_INSTALL_SERVICE ?
|
||||
GENERIC_WRITE : GENERIC_READ)) == NULL) {
|
||||
success = 0;
|
||||
show_error();
|
||||
} else if (action == ID_INSTALL_SERVICE) {
|
||||
GetModuleFileName(NULL, path, sizeof(path));
|
||||
strncat(path, " ", sizeof(path));
|
||||
strncat(path, service_magic_argument, sizeof(path));
|
||||
hService = CreateService(hSCM, service_name, service_name,
|
||||
SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS,
|
||||
SERVICE_AUTO_START, SERVICE_ERROR_NORMAL,
|
||||
path, NULL, NULL, NULL, NULL, NULL);
|
||||
if (hService) {
|
||||
ChangeServiceConfig2(hService, SERVICE_CONFIG_DESCRIPTION, &descr);
|
||||
} else {
|
||||
show_error();
|
||||
}
|
||||
} else if (action == ID_REMOVE_SERVICE) {
|
||||
if ((hService = OpenService(hSCM, service_name, DELETE)) == NULL ||
|
||||
!DeleteService(hService)) {
|
||||
show_error();
|
||||
}
|
||||
} else if ((hService = OpenService(hSCM, service_name,
|
||||
SERVICE_QUERY_STATUS)) == NULL) {
|
||||
success = 0;
|
||||
}
|
||||
|
||||
CloseServiceHandle(hService);
|
||||
CloseServiceHandle(hSCM);
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
static LRESULT CALLBACK WindowProc(HWND hWnd, UINT msg, WPARAM wParam,
|
||||
LPARAM lParam) {
|
||||
static SERVICE_TABLE_ENTRY service_table[] = {
|
||||
{server_name, (LPSERVICE_MAIN_FUNCTION) ServiceMain},
|
||||
{NULL, NULL}
|
||||
};
|
||||
int service_installed;
|
||||
char buf[200], *service_argv[] = {__argv[0], NULL};
|
||||
POINT pt;
|
||||
HMENU hMenu;
|
||||
static UINT s_uTaskbarRestart; // for taskbar creation
|
||||
|
||||
switch (msg) {
|
||||
case WM_CREATE:
|
||||
if (__argv[1] != NULL &&
|
||||
!strcmp(__argv[1], service_magic_argument)) {
|
||||
start_mongoose(1, service_argv);
|
||||
StartServiceCtrlDispatcher(service_table);
|
||||
exit(EXIT_SUCCESS);
|
||||
} else {
|
||||
start_mongoose(__argc, __argv);
|
||||
s_uTaskbarRestart = RegisterWindowMessage(TEXT("TaskbarCreated"));
|
||||
}
|
||||
break;
|
||||
case WM_COMMAND:
|
||||
switch (LOWORD(wParam)) {
|
||||
case ID_QUIT:
|
||||
mg_stop(ctx);
|
||||
Shell_NotifyIcon(NIM_DELETE, &TrayIcon);
|
||||
PostQuitMessage(0);
|
||||
return 0;
|
||||
case ID_SETTINGS:
|
||||
show_settings_dialog();
|
||||
break;
|
||||
case ID_INSTALL_SERVICE:
|
||||
case ID_REMOVE_SERVICE:
|
||||
manage_service(LOWORD(wParam));
|
||||
break;
|
||||
case ID_CONNECT:
|
||||
printf("[%s]\n", get_url_to_first_open_port(ctx));
|
||||
ShellExecute(NULL, "open", get_url_to_first_open_port(ctx),
|
||||
NULL, NULL, SW_SHOW);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case WM_USER:
|
||||
switch (lParam) {
|
||||
case WM_RBUTTONUP:
|
||||
case WM_LBUTTONUP:
|
||||
case WM_LBUTTONDBLCLK:
|
||||
hMenu = CreatePopupMenu();
|
||||
AppendMenu(hMenu, MF_STRING | MF_GRAYED, ID_SEPARATOR, server_name);
|
||||
AppendMenu(hMenu, MF_SEPARATOR, ID_SEPARATOR, "");
|
||||
service_installed = manage_service(0);
|
||||
snprintf(buf, sizeof(buf), "NT service: %s installed",
|
||||
service_installed ? "" : "not");
|
||||
AppendMenu(hMenu, MF_STRING | MF_GRAYED, ID_SEPARATOR, buf);
|
||||
AppendMenu(hMenu, MF_STRING | (service_installed ? MF_GRAYED : 0),
|
||||
ID_INSTALL_SERVICE, "Install service");
|
||||
AppendMenu(hMenu, MF_STRING | (!service_installed ? MF_GRAYED : 0),
|
||||
ID_REMOVE_SERVICE, "Deinstall service");
|
||||
AppendMenu(hMenu, MF_SEPARATOR, ID_SEPARATOR, "");
|
||||
AppendMenu(hMenu, MF_STRING, ID_CONNECT, "Start browser");
|
||||
AppendMenu(hMenu, MF_STRING, ID_SETTINGS, "Edit Settings");
|
||||
AppendMenu(hMenu, MF_SEPARATOR, ID_SEPARATOR, "");
|
||||
AppendMenu(hMenu, MF_STRING, ID_QUIT, "Exit");
|
||||
GetCursorPos(&pt);
|
||||
SetForegroundWindow(hWnd);
|
||||
TrackPopupMenu(hMenu, 0, pt.x, pt.y, 0, hWnd, NULL);
|
||||
PostMessage(hWnd, WM_NULL, 0, 0);
|
||||
DestroyMenu(hMenu);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case WM_CLOSE:
|
||||
mg_stop(ctx);
|
||||
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);
|
||||
}
|
||||
|
||||
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR cmdline, int show) {
|
||||
WNDCLASS cls;
|
||||
HWND hWnd;
|
||||
MSG msg;
|
||||
|
||||
init_server_name();
|
||||
memset(&cls, 0, sizeof(cls));
|
||||
cls.lpfnWndProc = (WNDPROC) WindowProc;
|
||||
cls.hIcon = LoadIcon(NULL, IDI_APPLICATION);
|
||||
cls.lpszClassName = server_name;
|
||||
|
||||
RegisterClass(&cls);
|
||||
hWnd = CreateWindow(cls.lpszClassName, server_name, WS_OVERLAPPEDWINDOW,
|
||||
0, 0, 0, 0, NULL, NULL, NULL, NULL);
|
||||
ShowWindow(hWnd, SW_HIDE);
|
||||
|
||||
TrayIcon.cbSize = sizeof(TrayIcon);
|
||||
TrayIcon.uID = ID_ICON;
|
||||
TrayIcon.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
|
||||
TrayIcon.hIcon = hIcon = LoadImage(GetModuleHandle(NULL),
|
||||
MAKEINTRESOURCE(ID_ICON),
|
||||
IMAGE_ICON, 16, 16, 0);
|
||||
TrayIcon.hWnd = hWnd;
|
||||
snprintf(TrayIcon.szTip, sizeof(TrayIcon.szTip), "%s", server_name);
|
||||
TrayIcon.uCallbackMessage = WM_USER;
|
||||
Shell_NotifyIcon(NIM_ADD, &TrayIcon);
|
||||
|
||||
while (GetMessage(&msg, hWnd, 0, 0) > 0) {
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
}
|
||||
|
||||
// Return the WM_QUIT value.
|
||||
return msg.wParam;
|
||||
}
|
||||
#elif defined(USE_COCOA)
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
@interface Mongoose : NSObject<NSApplicationDelegate>
|
||||
- (void) openBrowser;
|
||||
- (void) shutDown;
|
||||
@end
|
||||
|
||||
@implementation Mongoose
|
||||
- (void) openBrowser {
|
||||
[[NSWorkspace sharedWorkspace]
|
||||
openURL:[NSURL URLWithString:
|
||||
[NSString stringWithUTF8String:get_url_to_first_open_port(ctx)]]];
|
||||
}
|
||||
- (void) editConfig {
|
||||
create_config_file(config_file);
|
||||
[[NSWorkspace sharedWorkspace]
|
||||
openFile:[NSString stringWithUTF8String:config_file]
|
||||
withApplication:@"TextEdit"];
|
||||
}
|
||||
- (void)shutDown{
|
||||
[NSApp terminate:nil];
|
||||
}
|
||||
@end
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
init_server_name();
|
||||
start_mongoose(argc, argv);
|
||||
|
||||
[NSAutoreleasePool new];
|
||||
[NSApplication sharedApplication];
|
||||
|
||||
// Add delegate to process menu item actions
|
||||
Mongoose *myDelegate = [[Mongoose alloc] autorelease];
|
||||
[NSApp setDelegate: myDelegate];
|
||||
|
||||
// Run this app as agent
|
||||
ProcessSerialNumber psn = { 0, kCurrentProcess };
|
||||
TransformProcessType(&psn, kProcessTransformToBackgroundApplication);
|
||||
SetFrontProcess(&psn);
|
||||
|
||||
// Add status bar menu
|
||||
id menu = [[NSMenu new] autorelease];
|
||||
|
||||
// Add version menu item
|
||||
[menu addItem:[[[NSMenuItem alloc]
|
||||
//initWithTitle:[NSString stringWithFormat:@"%s", server_name]
|
||||
initWithTitle:[NSString stringWithUTF8String:server_name]
|
||||
action:@selector(noexist) keyEquivalent:@""] autorelease]];
|
||||
|
||||
// Add configuration menu item
|
||||
[menu addItem:[[[NSMenuItem alloc]
|
||||
initWithTitle:@"Edit configuration"
|
||||
action:@selector(editConfig) keyEquivalent:@""] autorelease]];
|
||||
|
||||
// Add connect menu item
|
||||
[menu addItem:[[[NSMenuItem alloc]
|
||||
initWithTitle:@"Open web root in a browser"
|
||||
action:@selector(openBrowser) keyEquivalent:@""] autorelease]];
|
||||
|
||||
// Separator
|
||||
[menu addItem:[NSMenuItem separatorItem]];
|
||||
|
||||
// Add quit menu item
|
||||
[menu addItem:[[[NSMenuItem alloc]
|
||||
initWithTitle:@"Quit"
|
||||
action:@selector(shutDown) keyEquivalent:@"q"] autorelease]];
|
||||
|
||||
// Attach menu to the status bar
|
||||
id item = [[[NSStatusBar systemStatusBar]
|
||||
statusItemWithLength:NSVariableStatusItemLength] retain];
|
||||
[item setHighlightMode:YES];
|
||||
[item setImage:[NSImage imageNamed:@"mongoose_22x22.png"]];
|
||||
[item setMenu:menu];
|
||||
|
||||
// Run the app
|
||||
[NSApp activateIgnoringOtherApps:YES];
|
||||
[NSApp run];
|
||||
|
||||
mg_stop(ctx);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
#else
|
||||
int main(int argc, char *argv[]) {
|
||||
init_server_name();
|
||||
start_mongoose(argc, argv);
|
||||
printf("%s started on port(s) %s with web root [%s]\n",
|
||||
server_name, mg_get_option(ctx, "listening_ports"),
|
||||
mg_get_option(ctx, "document_root"));
|
||||
while (exit_flag == 0) {
|
||||
sleep(1);
|
||||
}
|
||||
printf("Exiting on signal %d, waiting for all threads to finish...",
|
||||
exit_flag);
|
||||
fflush(stdout);
|
||||
mg_stop(ctx);
|
||||
printf("%s", " done.\n");
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
#endif /* _WIN32 */
|
||||
+393
@@ -0,0 +1,393 @@
|
||||
#include "lua_5.2.1.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
static void *mmap(void *addr, int64_t len, int prot, int flags, int fd,
|
||||
int offset) {
|
||||
HANDLE fh = (HANDLE) _get_osfhandle(fd);
|
||||
HANDLE mh = CreateFileMapping(fh, 0, PAGE_READONLY, 0, 0, 0);
|
||||
void *p = MapViewOfFile(mh, FILE_MAP_READ, 0, 0, (size_t) len);
|
||||
CloseHandle(mh);
|
||||
return p;
|
||||
}
|
||||
#define munmap(x, y) UnmapViewOfFile(x)
|
||||
#define MAP_FAILED NULL
|
||||
#define MAP_PRIVATE 0
|
||||
#define PROT_READ 0
|
||||
#else
|
||||
#include <sys/mman.h>
|
||||
#endif
|
||||
|
||||
static const char *LUASOCKET = "luasocket";
|
||||
|
||||
// Forward declarations
|
||||
static void handle_request(struct mg_connection *);
|
||||
static int handle_lsp_request(struct mg_connection *, const char *,
|
||||
struct file *, struct lua_State *);
|
||||
|
||||
static void reg_string(struct lua_State *L, const char *name, const char *val) {
|
||||
lua_pushstring(L, name);
|
||||
lua_pushstring(L, val);
|
||||
lua_rawset(L, -3);
|
||||
}
|
||||
|
||||
static void reg_int(struct lua_State *L, const char *name, int val) {
|
||||
lua_pushstring(L, name);
|
||||
lua_pushinteger(L, val);
|
||||
lua_rawset(L, -3);
|
||||
}
|
||||
|
||||
static void reg_function(struct lua_State *L, const char *name,
|
||||
lua_CFunction func, struct mg_connection *conn) {
|
||||
lua_pushstring(L, name);
|
||||
lua_pushlightuserdata(L, conn);
|
||||
lua_pushcclosure(L, func, 1);
|
||||
lua_rawset(L, -3);
|
||||
}
|
||||
|
||||
static int lsp_sock_close(lua_State *L) {
|
||||
if (lua_gettop(L) > 0 && lua_istable(L, -1)) {
|
||||
lua_getfield(L, -1, "sock");
|
||||
closesocket((SOCKET) lua_tonumber(L, -1));
|
||||
} else {
|
||||
return luaL_error(L, "invalid :close() call");
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int lsp_sock_recv(lua_State *L) {
|
||||
char buf[2000];
|
||||
int n;
|
||||
|
||||
if (lua_gettop(L) > 0 && lua_istable(L, -1)) {
|
||||
lua_getfield(L, -1, "sock");
|
||||
n = recv((SOCKET) lua_tonumber(L, -1), buf, sizeof(buf), 0);
|
||||
if (n <= 0) {
|
||||
lua_pushnil(L);
|
||||
} else {
|
||||
lua_pushlstring(L, buf, n);
|
||||
}
|
||||
} else {
|
||||
return luaL_error(L, "invalid :close() call");
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int lsp_sock_send(lua_State *L) {
|
||||
const char *buf;
|
||||
size_t len, sent = 0;
|
||||
int n, sock;
|
||||
|
||||
if (lua_gettop(L) > 1 && lua_istable(L, -2) && lua_isstring(L, -1)) {
|
||||
buf = lua_tolstring(L, -1, &len);
|
||||
lua_getfield(L, -2, "sock");
|
||||
sock = (int) lua_tonumber(L, -1);
|
||||
while (sent < len) {
|
||||
if ((n = send(sock, buf + sent, len - sent, 0)) <= 0) {
|
||||
break;
|
||||
}
|
||||
sent += n;
|
||||
}
|
||||
lua_pushnumber(L, n);
|
||||
} else {
|
||||
return luaL_error(L, "invalid :close() call");
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const struct luaL_Reg luasocket_methods[] = {
|
||||
{"close", lsp_sock_close},
|
||||
{"send", lsp_sock_send},
|
||||
{"recv", lsp_sock_recv},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
static int lsp_connect(lua_State *L) {
|
||||
char ebuf[100];
|
||||
SOCKET sock;
|
||||
|
||||
if (lua_isstring(L, -3) && lua_isnumber(L, -2) && lua_isnumber(L, -1)) {
|
||||
sock = conn2(lua_tostring(L, -3), (int) lua_tonumber(L, -2),
|
||||
(int) lua_tonumber(L, -1), ebuf, sizeof(ebuf));
|
||||
if (sock == INVALID_SOCKET) {
|
||||
return luaL_error(L, ebuf);
|
||||
} else {
|
||||
lua_newtable(L);
|
||||
reg_int(L, "sock", sock);
|
||||
reg_string(L, "host", lua_tostring(L, -4));
|
||||
luaL_getmetatable(L, LUASOCKET);
|
||||
lua_setmetatable(L, -2);
|
||||
}
|
||||
} else {
|
||||
return luaL_error(L, "connect(host,port,is_ssl): invalid parameter given.");
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int lsp_error(lua_State *L) {
|
||||
lua_getglobal(L, "mg");
|
||||
lua_getfield(L, -1, "onerror");
|
||||
lua_pushvalue(L, -3);
|
||||
lua_pcall(L, 1, 0, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Silently stop processing chunks.
|
||||
static void lsp_abort(lua_State *L) {
|
||||
int top = lua_gettop(L);
|
||||
lua_getglobal(L, "mg");
|
||||
lua_pushnil(L);
|
||||
lua_setfield(L, -2, "onerror");
|
||||
lua_settop(L, top);
|
||||
lua_pushstring(L, "aborting");
|
||||
lua_error(L);
|
||||
}
|
||||
|
||||
static int lsp(struct mg_connection *conn, const char *path,
|
||||
const char *p, int64_t len, lua_State *L) {
|
||||
int i, j, pos = 0, lines = 1, lualines = 0;
|
||||
char chunkname[MG_BUF_LEN];
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
if (p[i] == '\n') lines++;
|
||||
if (p[i] == '<' && p[i + 1] == '?') {
|
||||
for (j = i + 1; j < len ; j++) {
|
||||
if (p[j] == '\n') lualines++;
|
||||
if (p[j] == '?' && p[j + 1] == '>') {
|
||||
mg_write(conn, p + pos, i - pos);
|
||||
|
||||
snprintf(chunkname, sizeof(chunkname), "@%s+%i", path, lines);
|
||||
lua_pushlightuserdata(L, conn);
|
||||
lua_pushcclosure(L, lsp_error, 1);
|
||||
if (luaL_loadbuffer(L, p + (i + 2), j - (i + 2), chunkname)) {
|
||||
// Syntax error or OOM. Error message is pushed on stack.
|
||||
lua_pcall(L, 1, 0, 0);
|
||||
} else {
|
||||
// Success loading chunk. Call it.
|
||||
lua_pcall(L, 0, 0, 1);
|
||||
}
|
||||
|
||||
pos = j + 2;
|
||||
i = pos - 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (lualines > 0) {
|
||||
lines += lualines;
|
||||
lualines = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (i > pos) {
|
||||
mg_write(conn, p + pos, i - pos);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int lsp_write(lua_State *L) {
|
||||
int i, num_args;
|
||||
const char *str;
|
||||
size_t size;
|
||||
struct mg_connection *conn = lua_touserdata(L, lua_upvalueindex(1));
|
||||
|
||||
num_args = lua_gettop(L);
|
||||
for (i = 1; i <= num_args; i++) {
|
||||
if (lua_isstring(L, i)) {
|
||||
str = lua_tolstring(L, i, &size);
|
||||
mg_write(conn, str, size);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int lsp_read(lua_State *L) {
|
||||
struct mg_connection *conn = lua_touserdata(L, lua_upvalueindex(1));
|
||||
char buf[1024];
|
||||
int len = mg_read(conn, buf, sizeof(buf));
|
||||
|
||||
if (len <= 0) return 0;
|
||||
lua_pushlstring(L, buf, len);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
// mg.include: Include another .lp file
|
||||
static int lsp_include(lua_State *L) {
|
||||
struct mg_connection *conn = lua_touserdata(L, lua_upvalueindex(1));
|
||||
struct file file = STRUCT_FILE_INITIALIZER;
|
||||
if (handle_lsp_request(conn, lua_tostring(L, -1), &file, L)) {
|
||||
// handle_lsp_request returned an error code, meaning an error occured in
|
||||
// the included page and mg.onerror returned non-zero. Stop processing.
|
||||
lsp_abort(L);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// mg.cry: Log an error. Default value for mg.onerror.
|
||||
static int lsp_cry(lua_State *L){
|
||||
struct mg_connection *conn = lua_touserdata(L, lua_upvalueindex(1));
|
||||
cry(conn, "%s", lua_tostring(L, -1));
|
||||
return 0;
|
||||
}
|
||||
|
||||
// mg.redirect: Redirect the request (internally).
|
||||
static int lsp_redirect(lua_State *L) {
|
||||
struct mg_connection *conn = lua_touserdata(L, lua_upvalueindex(1));
|
||||
conn->request_info.uri = lua_tostring(L, -1);
|
||||
handle_request(conn);
|
||||
lsp_abort(L);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void prepare_lua_environment(struct mg_connection *conn, lua_State *L) {
|
||||
const struct mg_request_info *ri = mg_get_request_info(conn);
|
||||
extern void luaL_openlibs(lua_State *);
|
||||
int i;
|
||||
|
||||
luaL_openlibs(L);
|
||||
#ifdef USE_LUA_SQLITE3
|
||||
{ extern int luaopen_lsqlite3(lua_State *); luaopen_lsqlite3(L); }
|
||||
#endif
|
||||
|
||||
luaL_newmetatable(L, LUASOCKET);
|
||||
lua_pushliteral(L, "__index");
|
||||
luaL_newlib(L, luasocket_methods);
|
||||
lua_rawset(L, -3);
|
||||
lua_pop(L, 1);
|
||||
lua_register(L, "connect", lsp_connect);
|
||||
|
||||
if (conn == NULL) return;
|
||||
|
||||
// Register mg module
|
||||
lua_newtable(L);
|
||||
|
||||
reg_function(L, "read", lsp_read, conn);
|
||||
reg_function(L, "write", lsp_write, conn);
|
||||
reg_function(L, "cry", lsp_cry, conn);
|
||||
reg_function(L, "include", lsp_include, conn);
|
||||
reg_function(L, "redirect", lsp_redirect, conn);
|
||||
reg_string(L, "version", MONGOOSE_VERSION);
|
||||
|
||||
// Export request_info
|
||||
lua_pushstring(L, "request_info");
|
||||
lua_newtable(L);
|
||||
reg_string(L, "request_method", ri->request_method);
|
||||
reg_string(L, "uri", ri->uri);
|
||||
reg_string(L, "http_version", ri->http_version);
|
||||
reg_string(L, "query_string", ri->query_string);
|
||||
reg_int(L, "remote_ip", ri->remote_ip);
|
||||
reg_int(L, "remote_port", ri->remote_port);
|
||||
reg_int(L, "num_headers", ri->num_headers);
|
||||
lua_pushstring(L, "http_headers");
|
||||
lua_newtable(L);
|
||||
for (i = 0; i < ri->num_headers; i++) {
|
||||
reg_string(L, ri->http_headers[i].name, ri->http_headers[i].value);
|
||||
}
|
||||
lua_rawset(L, -3);
|
||||
lua_rawset(L, -3);
|
||||
|
||||
lua_setglobal(L, "mg");
|
||||
|
||||
// Register default mg.onerror function
|
||||
luaL_dostring(L, "mg.onerror = function(e) mg.write('\\nLua error:\\n', "
|
||||
"debug.traceback(e, 1)) end");
|
||||
}
|
||||
|
||||
static int lua_error_handler(lua_State *L) {
|
||||
const char *error_msg = lua_isstring(L, -1) ? lua_tostring(L, -1) : "?\n";
|
||||
|
||||
lua_getglobal(L, "mg");
|
||||
if (!lua_isnil(L, -1)) {
|
||||
lua_getfield(L, -1, "write"); // call mg.write()
|
||||
lua_pushstring(L, error_msg);
|
||||
lua_pushliteral(L, "\n");
|
||||
lua_call(L, 2, 0);
|
||||
luaL_dostring(L, "mg.write(debug.traceback(), '\\n')");
|
||||
} else {
|
||||
printf("Lua error: [%s]\n", error_msg);
|
||||
luaL_dostring(L, "print(debug.traceback(), '\\n')");
|
||||
}
|
||||
// TODO(lsm): leave the stack balanced
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void mg_exec_lua_script(struct mg_connection *conn, const char *path,
|
||||
const void **exports) {
|
||||
int i;
|
||||
lua_State *L;
|
||||
|
||||
if (path != NULL && (L = luaL_newstate()) != NULL) {
|
||||
prepare_lua_environment(conn, L);
|
||||
lua_pushcclosure(L, &lua_error_handler, 0);
|
||||
|
||||
lua_pushglobaltable(L);
|
||||
if (exports != NULL) {
|
||||
for (i = 0; exports[i] != NULL && exports[i + 1] != NULL; i += 2) {
|
||||
lua_pushstring(L, exports[i]);
|
||||
lua_pushcclosure(L, (lua_CFunction) exports[i + 1], 0);
|
||||
lua_rawset(L, -3);
|
||||
}
|
||||
}
|
||||
|
||||
if (luaL_loadfile(L, path) != 0) {
|
||||
lua_error_handler(L);
|
||||
}
|
||||
lua_pcall(L, 0, 0, -2);
|
||||
lua_close(L);
|
||||
}
|
||||
}
|
||||
|
||||
static void lsp_send_err(struct mg_connection *conn, struct lua_State *L,
|
||||
const char *fmt, ...) {
|
||||
char buf[MG_BUF_LEN];
|
||||
va_list ap;
|
||||
int len;
|
||||
|
||||
va_start(ap, fmt);
|
||||
len = vsnprintf(buf, sizeof(buf), fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
if (L == NULL) {
|
||||
send_http_error(conn, 500, http_500_error, "%s", buf);
|
||||
} else {
|
||||
lua_pushstring(L, buf);
|
||||
lua_error(L);
|
||||
}
|
||||
}
|
||||
|
||||
static int handle_lsp_request(struct mg_connection *conn, const char *path,
|
||||
struct file *filep, struct lua_State *ls) {
|
||||
void *p = NULL;
|
||||
lua_State *L = NULL;
|
||||
int error = 1;
|
||||
|
||||
// We need both mg_stat to get file size, and mg_fopen to get fd
|
||||
if (!mg_stat(conn, path, filep) || !mg_fopen(conn, path, "r", filep)) {
|
||||
lsp_send_err(conn, ls, "File [%s] not found", path);
|
||||
} else if (filep->membuf == NULL &&
|
||||
(p = mmap(NULL, (size_t) filep->size, PROT_READ, MAP_PRIVATE,
|
||||
fileno(filep->fp), 0)) == MAP_FAILED) {
|
||||
lsp_send_err(conn, ls, "mmap(%s, %zu, %d): %s", path, (size_t) filep->size,
|
||||
fileno(filep->fp), strerror(errno));
|
||||
} else if ((L = ls != NULL ? ls : luaL_newstate()) == NULL) {
|
||||
send_http_error(conn, 500, http_500_error, "%s", "luaL_newstate failed");
|
||||
} else {
|
||||
// We're not sending HTTP headers here, Lua page must do it.
|
||||
if (ls == NULL) {
|
||||
prepare_lua_environment(conn, L);
|
||||
if (conn->ctx->callbacks.init_lua != NULL) {
|
||||
conn->ctx->callbacks.init_lua(conn, L);
|
||||
}
|
||||
}
|
||||
error = lsp(conn, path, filep->membuf == NULL ? p : filep->membuf,
|
||||
filep->size, L);
|
||||
}
|
||||
|
||||
if (L != NULL && ls == NULL) lua_close(L);
|
||||
if (p != NULL) munmap(p, filep->size);
|
||||
mg_fclose(filep);
|
||||
return error;
|
||||
}
|
||||
@@ -0,0 +1,589 @@
|
||||
%PDF-1.5␍%âãÏÓ
|
||||
1 0 obj␍<</Metadata 2 0 R/OCProperties<</D<</ON[5 0 R]/Order 6 0 R/RBGroups[]>>/OCGs[5 0 R]>>/Pages 3 0 R/Type/Catalog>>␍endobj␍2 0 obj␍<</Length 16195/Subtype/XML/Type/Metadata>>stream
|
||||
<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>
|
||||
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Adobe XMP Core 5.3-c011 66.145661, 2012/02/06-14:56:27 ">
|
||||
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
|
||||
<rdf:Description rdf:about=""
|
||||
xmlns:xmp="http://ns.adobe.com/xap/1.0/"
|
||||
xmlns:xmpGImg="http://ns.adobe.com/xap/1.0/g/img/">
|
||||
<xmp:CreatorTool>Adobe Illustrator CS6 (Windows)</xmp:CreatorTool>
|
||||
<xmp:CreateDate>2013-01-02T17:27:47+01:00</xmp:CreateDate>
|
||||
<xmp:ModifyDate>2013-01-02T17:27:47Z</xmp:ModifyDate>
|
||||
<xmp:MetadataDate>2013-01-02T17:27:47Z</xmp:MetadataDate>
|
||||
<xmp:Thumbnails>
|
||||
<rdf:Alt>
|
||||
<rdf:li rdf:parseType="Resource">
|
||||
<xmpGImg:width>256</xmpGImg:width>
|
||||
<xmpGImg:height>228</xmpGImg:height>
|
||||
<xmpGImg:format>JPEG</xmpGImg:format>
|
||||
<xmpGImg:image>/9j/4AAQSkZJRgABAgEASABIAAD/7QAsUGhvdG9zaG9wIDMuMAA4QklNA+0AAAAAABAASAAAAAEA
AQBIAAAAAQAB/+4ADkFkb2JlAGTAAAAAAf/bAIQABgQEBAUEBgUFBgkGBQYJCwgGBggLDAoKCwoK
DBAMDAwMDAwQDA4PEA8ODBMTFBQTExwbGxscHx8fHx8fHx8fHwEHBwcNDA0YEBAYGhURFRofHx8f
Hx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8f/8AAEQgA5AEAAwER
AAIRAQMRAf/EAaIAAAAHAQEBAQEAAAAAAAAAAAQFAwIGAQAHCAkKCwEAAgIDAQEBAQEAAAAAAAAA
AQACAwQFBgcICQoLEAACAQMDAgQCBgcDBAIGAnMBAgMRBAAFIRIxQVEGE2EicYEUMpGhBxWxQiPB
UtHhMxZi8CRygvElQzRTkqKyY3PCNUQnk6OzNhdUZHTD0uIIJoMJChgZhJRFRqS0VtNVKBry4/PE
1OT0ZXWFlaW1xdXl9WZ2hpamtsbW5vY3R1dnd4eXp7fH1+f3OEhYaHiImKi4yNjo+Ck5SVlpeYmZ
qbnJ2en5KjpKWmp6ipqqusra6voRAAICAQIDBQUEBQYECAMDbQEAAhEDBCESMUEFURNhIgZxgZEy
obHwFMHR4SNCFVJicvEzJDRDghaSUyWiY7LCB3PSNeJEgxdUkwgJChgZJjZFGidkdFU38qOzwygp
0+PzhJSktMTU5PRldYWVpbXF1eX1RlZmdoaWprbG1ub2R1dnd4eXp7fH1+f3OEhYaHiImKi4yNjo
+DlJWWl5iZmpucnZ6fkqOkpaanqKmqq6ytrq+v/aAAwDAQACEQMRAD8A9U4q7FXYq7FXYq7FXYq7
FXYq7FXYq7FXYq7FXYq7FXYq7FXYq7FXYq7FXYq7FVsssUUbSyuscSAs7sQqqo3JJPQDFWOL+ZXk
Rrj6uNat/UrTkSQn/Iwjh+OR4wx4wyG3ube4iEtvKk0TfZkjYMp+RFRkmSpirsVYj+ZvnFfLPl2R
4XA1O8rDYr3BI+KT5IPxpkJyoMJyoI38vbs3fknRZmbkwtY4yx3NYh6f/GuGPJMeTIckydirsVdi
rsVdirsVdirsVdirsVdirsVdirsVdirsVdirsVdirsVdirsVdirsVeG/nX55mutQby3YSlbO1I+v
lD/eTdfTNP2Y+4/m+WUZJdGnJLoiX/Lfybo/5fxavr31prq4SCWS4t6c4WnA4osbHgVUt8Vdz2pj
wgCyvAAN3nd9aW1gzXGiayLmDvx9S1uFB2AaNqBuv7DNkGs+SyHzf5sh/utavkFa0W5mA29uWPEV
4ijI/wAxfPMYIXW7o1/mfl/xKuHjKeMpbrfmLW9cnjn1a7e7liT042eg4rWuwUAfTgJJQSS9/wDy
ZufW/L+xStTBJPEf+RrOPwfL8fJvx8mb5Nm7FXYq7FXYq7FXYq7FXYq7FXYq7FXYq7FXYq7FXYq7
FXYq7FXYq7FXYq7FUr8063Hofl6/1V6H6rEWjU9GkPwxqf8AWdgMEjQRI0Hy9pdhqHmHX4LRGMt7
qM/xyHclnPJ5G+QqxzF5uMBZer/n3fww6bpek290EKsXmsFO5jVQsbt7KQQK9foy3IejblLxbKml
2KuxV2KvWvyR8721lI3lq9pGl1KZbGc7fvWAUxN/rcRx99u4y3HLo245dHtuXNzsVdirsVdirsVd
irsVdirsVdirsVdirsVdirsVdirsVdirsVdirsVdirsVeffnjfRQeSGt2I53lxFGi9/gJkJ/4TK8
h2a8h2Yl+TWn6RpNrdebNauYrSM8rawaZgtQN5XUHdidlFPfIY6G5Y4xW5YP5+vtM1DzZf32m3cl
7aXL+ok0oYEEihQc6HitKL7ZCXNhI7sewMUw0bQNZ1q5a30u0e6lQcnCUAVfFmYhVHzOICQCUZfe
SPNVlA9xNp0j28ZIkngKXEakdeTwmRRT3ONJMCEjxYqlupaZaMU4/EXHUBRyJHuAMVfR35U+cbjz
L5ff63ve2DiCaQmpkUrVHbp8RGx9xmRCVhyISsM1ybN2KuxV2KuxV2KuxV2KuxV2KuxV2KuxV2Ku
xV2KuxV2KuxV2KuxV2KuxV87/nF5wi13zAtlZvz0/S+USOD8LzMf3jj2FAo+Ve+Y+SVlx8krLAmd
2ChmJCiigmtBWtBkGC3FXYqyifzCLv8AK++8qaYq2GryTJK8wf0xexcqvG0jEBWApsTxYCnU0MMt
mFDm5OCYB3Tb/nHLyP590bzNdahqNpPpujPbFJYriqCeRipj4xk78dzzp7d8r0eKYlZ2DlZZAhEf
nXp3ly18wRzaXNEL2YN+kbOL9hxTi54/CrPXcde/fMrIBezgZALedxuyOrrsykEfRkGt67+QV2qa
nq1on93cwxzotfsmFirD/ksPwy3EW3E9oy5udirsVdirsVdirsVdirsVdirsVdirsVdirsVdirsV
dirsVdirsVdiryD80PzahWGbQ/LsweVwY7zUIzVVU7FIWHUnuw6dt9xVOfQNU59A8XylpdirsVdi
rsVTy287+bbXTf0Zb6rcRWQHFYlehVT+yrfaUewOHiLLiKSMxYlmJLE1JPUnAxZ9+UXkjSvM2o3s
mqgyWlgkZ+rKxTm8palWUhuICHofDJwjZbMcbet6f+XuheX9QXVtAhktpkHCe2EjyRywtTmtJC7c
h9pd+op0y3grcNoiByZbk2TsVdirsVdirsVdirsVdirsVdirsVdirsVdirH9Z8/eT9HLJfapCsq7
NDGTNID4FIw5H05EyAYmQDDtR/P7y9CzLYafc3ZHRpCkKk+3941PmMgcoYHKEof/AJyFuix4aGgX
sDcEn7/TGDxUeK0v/OQt3yHLRIytdwLgg0+fpnHxV8VHW3/OQmntT6zo00Xj6Uyyf8SWPD4qfFTQ
fnx5ONs0noXgmUfDA0aVY+HIOVw+KE+IHm3nL82PMXmNHtYyNO0xtjawsSzjwlk2LfIAD2yuUyWu
UyWEZBg7FXYq7FXYq7FV8cMktfTXkR+yOv0DqfoxV0kMsRAkRkJFQGBFR9OKsl/LzzbeeWdeF3FC
9zayr6d7boKkx1ryX/KU7j7u+GMqLKEqL3fR/P2m69epZaNDcSOV9S5nliaKOGMdal/tOTsoAP3D
LxO+TeJWyjJsnYq7FXYq7FXYq7FXYq7FXYq7FXYqoXt9ZWNs91ezx21vGKvLKwRR9JxtbeZeZvz3
0q1LwaBbG/lG31qascHzVdnf/hcqOXuajk7nl2v/AJgebddLLfajJ6Df8esJ9KKngVSnL/ZVysyJ
azIljuRYuxV2KuxV2KuxV2KuxV2KuxV2KuxV2KuxVWt3uSwhh5OZCAIQOYZjsPg3BP0Yq9G8r/k1
5l1f059bkOl2H2hAQPXI/wAmIfDH/st/bLI4yebYMZPN7H5Z8paH5as2tdKg9ISEGaViWkkZdgXY
/PoNsuEQG4RATjCl2KuxV2KuxV2KuxV2KuxV2KuxVgvnv819I8t87K0Av9YGxgU/u4j/AMWsO/8A
kjfxpkJTphKdPCfMXmrXfMN39Z1W6aYgn0oR8MUYPZEGw+fU98oMiWgyJSjAh2KuxV2KuxV2KuxV
2KuxV2KuxV2KuxV2KuxV2KvS/wAh9LW581XN861WxtjwPhJKwUH/AIDllmIbtmMbvfMvb3Yq7FXY
q7FXYq7FXYq7FXYq7FXYq8p/Nb803055NB0KUfXaFb68U1MNdjGh/wB+eJ/Z+fSqc+gapz6B4ezM
zFmJZmNSTuSTlLS1irsVdirsVdirsVdirsVdirsVdirsVdirsVdirsVdir3D/nH2y4aPq17T+/uI
4a/8YU5f8zsuxN2J6vlra7FXYq7FXYq7FXYq7FXYq7FXYqwX81fPv+GtJFpZOP0zfKRB3MUfRpSP
Hsvv8shOVMJyp85szOxdyWZjVmO5JPUk5juO1irsVdirsVdirsVdirsVdirsVdirsVdirsVdirsV
dirsVfTH5TaQ+meRdPWReMt2Gu3H/GY1T/knxzIgKDkQFBl+TZuxV2KuxV2KuxV2KuxV2KuxVC6p
qVppenXOoXb8La1jaSVvZR0HuegwE0gmnyt5m8wXnmDW7rVbs/HO3wR9QkY2RB/qrmMTZcYmyleB
DsVdirsVdirsVdirsVdirsVdirsVdirsVdirsVdirsVT7yR5Zm8x+Y7TTUB9At6l24/ZgQ1c/T9k
e5wxFllEWX1PHGkcaxxqFjQBUUbAACgAzKcldirsVdirsVdirsVdirsVdirsVeO/nz5pIFt5bt32
YC5vqHtX91Gfu5Ef6uU5ZdGnLLo8aypqdirsVdirsVdirsVdirsVdirsVdirsVdirsVdirsVdirs
VfR35T+Sf8OaF9Zu4+OragFkuARvHH1SL2IrVvf5ZkQjQciEaDOcmzdirsVdirsVdirsVdirsVdi
qld3UFpazXVwwSC3RpZXPRUQFmP0AYq+TvMOsz61rd7qs/8AeXcrSBf5V6Iv+xUAZik2XFJspdgQ
7FXYq7FXYq7FXYq7FXYq7FXYq7FXYq7FXYq7FXYq7FXqH5M+Qjqd6PMOoR/7j7N/9DjYbSzr+1v1
WP8A4l8jlmON7tmON7vd8vb3YLine truncated
|
||||
</rdf:li>
|
||||
</rdf:Alt>
|
||||
</xmp:Thumbnails>
|
||||
</rdf:Description>
|
||||
<rdf:Description rdf:about=""
|
||||
xmlns:xmpTPg="http://ns.adobe.com/xap/1.0/t/pg/"
|
||||
xmlns:stDim="http://ns.adobe.com/xap/1.0/sType/Dimensions#"
|
||||
xmlns:xmpG="http://ns.adobe.com/xap/1.0/g/">
|
||||
<xmpTPg:NPages>1</xmpTPg:NPages>
|
||||
<xmpTPg:HasVisibleTransparency>False</xmpTPg:HasVisibleTransparency>
|
||||
<xmpTPg:HasVisibleOverprint>False</xmpTPg:HasVisibleOverprint>
|
||||
<xmpTPg:MaxPageSize rdf:parseType="Resource">
|
||||
<stDim:w>64.000000</stDim:w>
|
||||
<stDim:h>64.000000</stDim:h>
|
||||
<stDim:unit>Points</stDim:unit>
|
||||
</xmpTPg:MaxPageSize>
|
||||
<xmpTPg:PlateNames>
|
||||
<rdf:Seq>
|
||||
<rdf:li>Cyan</rdf:li>
|
||||
<rdf:li>Magenta</rdf:li>
|
||||
<rdf:li>Yellow</rdf:li>
|
||||
<rdf:li>Black</rdf:li>
|
||||
</rdf:Seq>
|
||||
</xmpTPg:PlateNames>
|
||||
<xmpTPg:SwatchGroups>
|
||||
<rdf:Seq>
|
||||
<rdf:li rdf:parseType="Resource">
|
||||
<xmpG:groupName>Default Swatch Group</xmpG:groupName>
|
||||
<xmpG:groupType>0</xmpG:groupType>
|
||||
</rdf:li>
|
||||
</rdf:Seq>
|
||||
</xmpTPg:SwatchGroups>
|
||||
</rdf:Description>
|
||||
<rdf:Description rdf:about=""
|
||||
xmlns:illustrator="http://ns.adobe.com/illustrator/1.0/">
|
||||
<illustrator:Type>Document</illustrator:Type>
|
||||
</rdf:Description>
|
||||
<rdf:Description rdf:about=""
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/">
|
||||
<dc:format>application/pdf</dc:format>
|
||||
<dc:title>
|
||||
<rdf:Alt>
|
||||
<rdf:li xml:lang="x-default">Mongoo 3 smooth green</rdf:li>
|
||||
</rdf:Alt>
|
||||
</dc:title>
|
||||
</rdf:Description>
|
||||
<rdf:Description rdf:about=""
|
||||
xmlns:xmpMM="http://ns.adobe.com/xap/1.0/mm/">
|
||||
<xmpMM:RenditionClass>proof:pdf</xmpMM:RenditionClass>
|
||||
<xmpMM:DocumentID>uuid:a2f6b830-2598-49b9-8770-4f9fa14f1be3</xmpMM:DocumentID>
|
||||
<xmpMM:InstanceID>uuid:42245d04-b042-4038-b450-94c7cfb8ee6f</xmpMM:InstanceID>
|
||||
</rdf:Description>
|
||||
<rdf:Description rdf:about=""
|
||||
xmlns:pdf="http://ns.adobe.com/pdf/1.3/">
|
||||
<pdf:Producer>Adobe PDF library 10.01</pdf:Producer>
|
||||
</rdf:Description>
|
||||
</rdf:RDF>
|
||||
</x:xmpmeta>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<?xpacket end="w"?>
|
||||
endstream␍endobj␍3 0 obj␍<</Count 1/Kids[7 0 R]/Type/Pages>>␍endobj␍7 0 obj␍<</ArtBox[0.643066 4.46875 63.2324 59.6494]/BleedBox[0.0 0.0 64.0 64.0]/Contents 8 0 R/LastModified(D:20130102172747+01'00')/MediaBox[0.0 0.0 64.0 64.0]/Parent 3 0 R/PieceInfo<</Illustrator 9 0 R>>/Resources<</ExtGState<</GS0 10 0 R>>/Properties<</MC0 5 0 R>>>>/Thumb 11 0 R/TrimBox[0.0 0.0 64.0 64.0]/Type/Page>>␍endobj␍8 0 obj␍<</Filter/FlateDecode/Length 1251>>stream
|
||||
H‰t–KŽ•7…çÿ*¼�kì²]¶§!#Y@+�A "±û|§Ü}i"E4}»ü¨Ç©SÇ÷Õ¯¯Ó«·¯Kúéç×éú|•ä]?7þùãú=ýu•Ül¤’»u~7éˇëÕ›÷%}øûúœj*ü«©ö<gÉfÞ{zøtiãÓu«yøL–K[øÍ¥®ÄRK_ÙÂoÌb5ÝêÊ}Xº�\pp«5ouµ§‡ëÖòžø°�}�ÔKøºÕ�7Oß.㪱P
|
||||
Õ¼†‡Ûʹ¯—åÞ,üY›ªhN,Ï«,,ëºjyt#V˶å»äéÆîZ-vw_©åÚ”é¬ÅÙ™{ìŽ<¨¥äíÖÄ/‡ÌG˜»ê°NùЏըÙ#�Îåª"
|
||||
Þw\¨»§ÇËH;ʹ�•¬e¯Ç¡¨qùýþC€Pq¸ù°D,OrµžW·€Ö÷ÔiúÑçk¢EÓmåmç|9Φ%eÒ´Õ,"�CºÍ<F�¬¦ºÛÆÒ�ä¶:Y)žÍ¥;Í6•¨¤h#‘¢À8âɆæŽ>Ò»\µ¢(JØ\›^v@_ÈŸ=,ñ<•Ûf€³pÒÈÐOǽˆ!,L÷XèKå²ÐK‹nP.6mj~X±ì,¬ÚO»è. 6oDh:�œw:ĉ G‡a÷Ȃh½žŠ`ÖhJ˃,¿ÊÁò㱪€1³G›j 'ž6ì„55WÌ`mu��¢¼E*âdžpƒyé\„—¤×-C*�ß›s�ÐД'ÜÁ"=E‚N’ÕÓS¹¥B€à¤êÇ«“ÇàôŽšî64nSxq~Žž åÄŸî×%›D£†³SMSqXcXÕöV¹␍Ö[¶&Žê–è)øÜ¼˜ì…~¨␍H–8Â]@ôVí">vñ°„Ikw»,ãP0QºIl†§k[jHž ñªaµc¸èg-¢2*u]Ù | ||||