mirror of
https://github.com/cesanta/mongoose.git
synced 2026-10-26 12:14:56 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
23141c2fef | ||
|
|
c8ba652f1c | ||
|
|
6ac2fa2ae6 | ||
|
|
0322ec5647 | ||
|
|
a5223a9850 | ||
|
|
016968ada1 | ||
|
|
710b888122 | ||
|
|
cf53959f34 | ||
|
|
30d29fb77f | ||
|
|
c05b51bbfc | ||
|
|
1ab704ac92 | ||
|
|
2bc77e065c | ||
|
|
790daabf7d | ||
|
|
a6598a1278 | ||
|
|
0af5502b74 | ||
|
|
f059e41cac | ||
|
|
2cce91de9a | ||
|
|
0ff5b5b044 | ||
|
|
0c5d9a98c2 | ||
|
|
c9fbdfc1b5 | ||
|
|
6193b5171c | ||
|
|
911115ccc0 | ||
|
|
2f3ddeccc5 | ||
|
|
ca3f5a3257 | ||
|
|
df206bc05a | ||
|
|
531fec34fd | ||
|
|
4c10d1f356 | ||
|
|
94dccdd6f4 | ||
|
|
544352b7d3 | ||
|
|
29c2ae4886 | ||
|
|
1a2e2ec2fd | ||
|
|
3e780d21fc | ||
|
|
63fcea0159 | ||
|
|
e5d21225be | ||
|
|
0c9caf3120 | ||
|
|
54ba36c1c9 | ||
|
|
5077350589 | ||
|
|
2d880c4f5c | ||
|
|
4ca4c862a5 | ||
|
|
0918df1566 | ||
|
|
aa2583cc26 | ||
|
|
e1b1d39635 | ||
|
|
3bf82dd541 | ||
|
|
2896965c97 | ||
|
|
53b784b143 | ||
|
|
8e91e3a305 | ||
|
|
dbc07c8b00 | ||
|
|
ce953575e2 | ||
|
|
80db048578 | ||
|
|
382d165574 | ||
|
|
0fb2f38cb7 | ||
|
|
aa007f1285 | ||
|
|
8752910330 | ||
|
|
2a5a8eec49 | ||
|
|
ceca52de30 | ||
|
|
8a3691055c | ||
|
|
56d12c89da | ||
|
|
2cfce4d8b2 | ||
|
|
f372faf614 | ||
|
|
882f3b3ac3 | ||
|
|
fac0e9b0ac | ||
|
|
a3cf67c380 | ||
|
|
2987cbdb5c | ||
|
|
6083b9c5c5 | ||
|
|
83237a02d9 | ||
|
|
965188bac9 | ||
|
|
66da41d401 | ||
|
|
cfd334ac6c | ||
|
|
b5f6254c1e | ||
|
|
dcbd1cbbd1 | ||
|
|
a3b568f460 | ||
|
|
75770aec80 | ||
|
|
3a8ae7ac17 | ||
|
|
b116b2fa82 | ||
|
|
7806609773 | ||
|
|
72f45aa7e2 | ||
|
|
5e3e6a6dce | ||
|
|
1388bb1db4 | ||
|
|
3cc0d16f65 | ||
|
|
b50095fa61 | ||
|
|
7ad85219d8 | ||
|
|
347a249d10 | ||
|
|
07d982129a | ||
|
|
73f2602ba0 | ||
|
|
44561d163a | ||
|
|
c941a1a39a | ||
|
|
bee22312bc | ||
|
|
bdb16c624c | ||
|
|
e389e70d05 | ||
|
|
695559f691 | ||
|
|
13be74b4c6 | ||
|
|
02a1032fd4 | ||
|
|
788f35b19c | ||
|
|
3721efe1e9 | ||
|
|
e0822ffb78 | ||
|
|
ae7d5a8f94 | ||
|
|
ced7a2e0b5 | ||
|
|
5ed6708468 | ||
|
|
9fe53f307b | ||
|
|
c64d30e1f6 | ||
|
|
b4c25fc7ba | ||
|
|
b67b618811 | ||
|
|
5a19438f70 | ||
|
|
860addf1e3 | ||
|
|
03d571a119 | ||
|
|
0d9ecffc53 | ||
|
|
d4c8384b85 | ||
|
|
bd40145301 | ||
|
|
9b42494316 | ||
|
|
2daff6959f | ||
|
|
e9c434a6a1 | ||
|
|
d6fba7e45d | ||
|
|
0a0130b90c | ||
|
|
facf2af66e | ||
|
|
cc54195f59 | ||
|
|
e2fb707d9f | ||
|
|
7dfff935d6 | ||
|
|
5727a5c0ed | ||
|
|
268d2e9cbe | ||
|
|
1e7da874a4 | ||
|
|
7875a8c2bd | ||
|
|
b0355d45ae | ||
|
|
91136d7731 | ||
|
|
01a058d29b | ||
|
|
e6eca1738f | ||
|
|
2108ec5a0c | ||
|
|
bc4e47630a | ||
|
|
f41c9a2a1f | ||
|
|
6c77208236 | ||
|
|
386d2e5cd4 | ||
|
|
b738fdbffa | ||
|
|
b5704850db | ||
|
|
9c67e8960e | ||
|
|
d3dff4e1d5 | ||
|
|
82872e86fd | ||
|
|
ac229b6606 | ||
|
|
a6bf2bcbf4 | ||
|
|
b0cf8304cb | ||
|
|
0d9fe39dbb | ||
|
|
708af6d9c5 | ||
|
|
e4c71425c9 | ||
|
|
6e07215c1c | ||
|
|
ca9603301e | ||
|
|
d6c388042c | ||
|
|
6f66d794e8 | ||
|
|
1389eec784 | ||
|
|
6ef795e082 | ||
|
|
1e5d258e9e | ||
|
|
70eb4c4bbc | ||
|
|
a639e10a4d | ||
|
|
48750e67f6 | ||
|
|
ce60379af6 | ||
|
|
e0b9e4abfd | ||
|
|
665f205527 | ||
|
|
030daaf5d5 | ||
|
|
760511ec49 | ||
|
|
203688a34b | ||
|
|
29f4703e4f | ||
|
|
3cec6f6745 | ||
|
|
abcea07641 | ||
|
|
6a54704b29 | ||
|
|
8a2fbac4c0 | ||
|
|
96ce6bac69 | ||
|
|
50c0b958ff | ||
|
|
44416902d6 | ||
|
|
25e646c1a1 | ||
|
|
bd723bdc38 | ||
|
|
5e57031724 | ||
|
|
c583913290 | ||
|
|
870ca615de | ||
|
|
64b51699f8 | ||
|
|
50a889dac0 | ||
|
|
0ff0788458 | ||
|
|
fec6009edb | ||
|
|
c4f172a120 | ||
|
|
464c77314d | ||
|
|
f51ca8d5d1 | ||
|
|
7b37e0cb8b | ||
|
|
c7925353e7 | ||
|
|
bd23ec4323 | ||
|
|
3671b2632d | ||
|
|
25115a694c | ||
|
|
2436f9d6c3 | ||
|
|
2238951c18 | ||
|
|
f266dd2c94 | ||
|
|
b03358cb03 | ||
|
|
1bede7e28b | ||
|
|
3536670b82 | ||
|
|
3235c05fd6 | ||
|
|
63db54e7b5 | ||
|
|
1db51eb788 | ||
|
|
0e640ae885 | ||
|
|
1bff6df2a7 | ||
|
|
d0e66de225 | ||
|
|
f537670ce2 | ||
|
|
4cb3341a15 | ||
|
|
d52d9a4a6f | ||
|
|
4a076c7ea4 | ||
|
|
db6e883c22 | ||
|
|
804da054b5 | ||
|
|
fb4e701545 | ||
|
|
ccff4abf13 | ||
|
|
24a7936907 | ||
|
|
0993994139 | ||
|
|
8b740536de | ||
|
|
e851aac853 | ||
|
|
a39861b7bf | ||
|
|
63490249ba | ||
|
|
704f057384 | ||
|
|
40968bc496 | ||
|
|
6873f3c5f6 | ||
|
|
ba5cd7267a | ||
|
|
1bb98e5e8e | ||
|
|
a7774d0f1a | ||
|
|
f52c756fbb | ||
|
|
cc586c6ba2 | ||
|
|
606eab7f4f | ||
|
|
872b85b5f2 | ||
|
|
35bd2b6032 | ||
|
|
c5287b9044 | ||
|
|
223f6d960e | ||
|
|
464b895116 | ||
|
|
05d7b7c8bc | ||
|
|
d8b4db37a0 | ||
|
|
6bb49c780c | ||
|
|
3a60c5764d | ||
|
|
a8b38e4ab9 | ||
|
|
8750f8af1f | ||
|
|
e94a02dc12 | ||
|
|
5680b0fcc5 | ||
|
|
33c56b0edc | ||
|
|
e62e48397d | ||
|
|
8be30350be | ||
|
|
2609a2ab72 | ||
|
|
5a04ab2c56 | ||
|
|
4739de6c28 | ||
|
|
639d7a2fd8 | ||
|
|
8115ce1d82 | ||
|
|
3558b587b7 | ||
|
|
e21ec58ea8 | ||
|
|
74135bca7d | ||
|
|
d369f31608 | ||
|
|
d4b14ca3c1 | ||
|
|
f0994896d5 | ||
|
|
cfdd430b98 | ||
|
|
a6c05a9e83 | ||
|
|
94f63787bb | ||
|
|
367f5df328 | ||
|
|
f096138d6e | ||
|
|
0d00cd51e6 | ||
|
|
b216210a13 | ||
|
|
166833f330 | ||
|
|
4d6bedfd4e | ||
|
|
ace8c1736c | ||
|
|
c658a54d18 | ||
|
|
781a1dc25e | ||
|
|
3ea3b8dfa4 | ||
|
|
a514e143ff | ||
|
|
e1486a79e3 | ||
|
|
ee615248e3 | ||
|
|
687e0e2ee8 | ||
|
|
19aefcb7dd | ||
|
|
6a46244a21 | ||
|
|
60674c11c9 | ||
|
|
91c9ab807b | ||
|
|
9231c7346c | ||
|
|
20cb3a823a | ||
|
|
cbd8d69e6d | ||
|
|
f7fcfa6a42 | ||
|
|
293c5e5852 | ||
|
|
ceb866b4ee | ||
|
|
2f9166e96e | ||
|
|
fe0e0e69e5 | ||
|
|
db96641c10 | ||
|
|
fe83928ca4 | ||
|
|
014414f17f | ||
|
|
6ffe2d7f7a | ||
|
|
30c82d7efe | ||
|
|
999c4ad26c | ||
|
|
30a7965135 | ||
|
|
a8a017a048 | ||
|
|
eac8ffabc4 | ||
|
|
a7a17711ec | ||
|
|
18e28ef879 | ||
|
|
ce7515fca9 | ||
|
|
d5a78fb664 | ||
|
|
1b3a1b74ac | ||
|
|
8dd76e6ef4 | ||
|
|
976b5f37c1 | ||
|
|
31489ab7b1 | ||
|
|
1eb59940a4 | ||
|
|
576d769b56 | ||
|
|
afaba7ee17 | ||
|
|
40f257ef2b | ||
|
|
5840dc8153 | ||
|
|
5ed3dafb56 | ||
|
|
b99bf306ec | ||
|
|
89fae72aa7 | ||
|
|
ab147e8f19 | ||
|
|
81a78f9c8b | ||
|
|
370aeefdde | ||
|
|
c5407a75f4 | ||
|
|
7217aa22f1 | ||
|
|
69bd5f7aa2 | ||
|
|
41b3c1b23e | ||
|
|
f639409533 | ||
|
|
67c44799c8 | ||
|
|
4646e2ad55 | ||
|
|
b77532ea3f | ||
|
|
ed8168e8a1 | ||
|
|
39e2d2ad55 | ||
|
|
27c6656398 | ||
|
|
ffe83051fe | ||
|
|
93cd77ffad | ||
|
|
279c06c64c | ||
|
|
570c8213b6 | ||
|
|
f521999ea6 | ||
|
|
e41df3cf9c | ||
|
|
65f484291f | ||
|
|
77db89961b | ||
|
|
ad50310bb6 | ||
|
|
66ec3d1f1e | ||
|
|
a9da86d05c | ||
|
|
5f25a88821 | ||
|
|
fd7dc33645 | ||
|
|
9c22771a43 | ||
|
|
11640cc3c6 | ||
|
|
2264520a2f | ||
|
|
2f0b411ddd | ||
|
|
e0aceb4f3a | ||
|
|
ea9a60a59a | ||
|
|
458320cffb | ||
|
|
e0214af422 | ||
|
|
df5e997ea7 | ||
|
|
0a3cb63c73 | ||
|
|
37f7f3fb12 | ||
|
|
2ac970fa16 | ||
|
|
de35a353d4 | ||
|
|
dbbda02f70 | ||
|
|
725c30446c | ||
|
|
60473ae41a | ||
|
|
951d20f904 | ||
|
|
85a6abd58b | ||
|
|
2fbe09ad7c | ||
|
|
23325efab2 | ||
|
|
107902bae4 | ||
|
|
9bbf4c8384 | ||
|
|
c39a712540 | ||
|
|
e9f6111ba1 | ||
|
|
ba267a32fd | ||
|
|
f64ebbe0b1 | ||
|
|
8865dd5e84 | ||
|
|
ce57f47de0 | ||
|
|
48be2dbc2a | ||
|
|
8905522a94 | ||
|
|
eea1680cf9 | ||
|
|
d5004cb7eb | ||
|
|
1d1a05bf39 | ||
|
|
2009069037 | ||
|
|
8f7703c2a9 | ||
|
|
8e87c4f013 | ||
|
|
639a6dc2a8 | ||
|
|
cead9a04ca | ||
|
|
e528093027 | ||
|
|
c432b783fb | ||
|
|
e06976836f | ||
|
|
c9f7407573 | ||
|
|
a40e59dbe6 | ||
|
|
61ee3d36d0 | ||
|
|
94dbf21ffb | ||
|
|
998425b14b | ||
|
|
6900dd733a | ||
|
|
9e4cd054c8 | ||
|
|
5dc317fcb0 | ||
|
|
fbd5d77ce8 | ||
|
|
6f8751b479 | ||
|
|
877c4dc698 | ||
|
|
2dfc79129a | ||
|
|
416f4bf10f | ||
|
|
f9a99530ff | ||
|
|
940b65e4db | ||
|
|
b22f7d3a49 | ||
|
|
eaa0e26a85 | ||
|
|
a3a63f7e56 | ||
|
|
c9036f3ac0 | ||
|
|
60858d7fe5 | ||
|
|
1c914bde1d | ||
|
|
a487332aa0 | ||
|
|
3987d4d560 | ||
|
|
8d3181e0bf | ||
|
|
0f1a59aeb4 | ||
|
|
2cdf259940 | ||
|
|
0187fe943a | ||
|
|
a34d1ec00a | ||
|
|
e70d98b7b0 | ||
|
|
bea012a3c1 | ||
|
|
eb2d470f65 | ||
|
|
652c352394 | ||
|
|
f1b37b3101 | ||
|
|
81b9876af8 | ||
|
|
7010addadb | ||
|
|
9e118c8a31 | ||
|
|
2fc654ac35 | ||
|
|
45861c7890 | ||
|
|
1957879e10 | ||
|
|
ddbe690698 | ||
|
|
9ba1596c46 | ||
|
|
de509ae952 | ||
|
|
77817cd019 | ||
|
|
7083bea56b | ||
|
|
3dffd7604a | ||
|
|
5a67af0c73 | ||
|
|
14526a2109 | ||
|
|
a6cfbd2536 | ||
|
|
0d28f99275 | ||
|
|
a281e99661 | ||
|
|
170df7b676 | ||
|
|
3fa5c69f98 | ||
|
|
e31f3058fa | ||
|
|
83a9a726d3 | ||
|
|
8ae0400b0d | ||
|
|
037fdbcccb | ||
|
|
5d2ac4e0a6 | ||
|
|
f977757a9d | ||
|
|
1db13aeed5 | ||
|
|
956788d7de | ||
|
|
45f6612096 | ||
|
|
2392156fd4 | ||
|
|
cf1811f8c3 | ||
|
|
93c5335d80 | ||
|
|
192205b10b | ||
|
|
0377eea9c5 | ||
|
|
ad89868564 | ||
|
|
976f286134 | ||
|
|
503a1a749d | ||
|
|
45a4266172 | ||
|
|
2ea17e8c6d | ||
|
|
67b7d79710 | ||
|
|
2e35e25935 | ||
|
|
d86d409d3c | ||
|
|
1109d3aa3c | ||
|
|
8208d9e250 | ||
|
|
fdd086b11c | ||
|
|
5825e3ea74 | ||
|
|
061ba99124 | ||
|
|
ead098f726 | ||
|
|
7a129c17ba | ||
|
|
400084ea8a | ||
|
|
82ad9a073a | ||
|
|
22aea8acac | ||
|
|
40e5c744da | ||
|
|
e648681f1d | ||
|
|
02f19fc05a | ||
|
|
7690f9e34b | ||
|
|
65c1278975 | ||
|
|
05e1135940 | ||
|
|
7b6e8fb93c | ||
|
|
9f1679e900 | ||
|
|
c0af018e20 | ||
|
|
d553ae992a | ||
|
|
89ef8f2f30 | ||
|
|
9115a99f47 | ||
|
|
bbc65c7987 | ||
|
|
bac0f75dd6 | ||
|
|
6440c358c1 | ||
|
|
6f84c8bbfb | ||
|
|
0adbfcba96 | ||
|
|
136c3e8200 | ||
|
|
7d699ea73c | ||
|
|
fc37b08139 | ||
|
|
3aaf47d4e4 | ||
|
|
346179d1f1 | ||
|
|
0148bc804a | ||
|
|
472e198d4a | ||
|
|
bf6fc3262f | ||
|
|
53311e8d6b | ||
|
|
cc636197bc | ||
|
|
6b4f7e785d | ||
|
|
73ed83c5e3 | ||
|
|
56f128514e | ||
|
|
f0571f9fd6 | ||
|
|
a3663da90e | ||
|
|
f74a1e1dc2 | ||
|
|
74511b42f5 | ||
|
|
04862eec85 | ||
|
|
4d105386ca | ||
|
|
44a35bb5bf | ||
|
|
022c9f0d47 | ||
|
|
e38061970e | ||
|
|
a4e8dc3069 | ||
|
|
fa4179ee53 | ||
|
|
a8c8cfb665 | ||
|
|
e0b6109214 | ||
|
|
d29f849602 | ||
|
|
848c5d753e | ||
|
|
4eef5b14fb | ||
|
|
283af71bbf | ||
|
|
ff85b802c3 | ||
|
|
e2b42e4117 | ||
|
|
63909b59c5 | ||
|
|
7380c65265 | ||
|
|
e9316a4feb | ||
|
|
2ac231cb7e | ||
|
|
a741d53028 | ||
|
|
9ea7b6f8ae | ||
|
|
580d3da3c7 | ||
|
|
aa59dda966 | ||
|
|
47b92e4145 | ||
|
|
fa351959a0 | ||
|
|
1414e2a236 | ||
|
|
5fb275e146 | ||
|
|
9390c66b48 | ||
|
|
2f69ca37d3 | ||
|
|
4cd11de400 | ||
|
|
15a2639355 | ||
|
|
c20f26dbb9 | ||
|
|
cae797cf04 | ||
|
|
0d885add0e | ||
|
|
842231cc5c | ||
|
|
dc55a3ae40 | ||
|
|
4d85cc6c76 | ||
|
|
8ac1b40c11 | ||
|
|
238b43af84 | ||
|
|
12c8e99bd5 | ||
|
|
5f2f359bd6 | ||
|
|
ccf0ce4a1f | ||
|
|
134a5b7b9e | ||
|
|
d39daab29e | ||
|
|
a798b1a937 | ||
|
|
04de3bb2f9 | ||
|
|
86da250e2c | ||
|
|
347a8c2f70 | ||
|
|
9624200663 | ||
|
|
18b1e95350 | ||
|
|
407877a4d5 | ||
|
|
7541c6339a | ||
|
|
31f1efd4f5 | ||
|
|
2477f80a43 | ||
|
|
cf94fb3642 | ||
|
|
2210043b87 | ||
|
|
10872b3227 | ||
|
|
cb324cfb9a | ||
|
|
4ee5849a04 | ||
|
|
fa216849e5 | ||
|
|
df6e35e330 | ||
|
|
96bb9aac36 | ||
|
|
7cec2fe280 | ||
|
|
02937f8852 | ||
|
|
51f0cc2b67 | ||
|
|
253927008c | ||
|
|
9778a4ccfc | ||
|
|
d0e2741832 | ||
|
|
3a5e2fba88 | ||
|
|
85940c8045 | ||
|
|
a0b599b308 | ||
|
|
d43ccda9a7 | ||
|
|
675b83a3ef | ||
|
|
dfdfcc060d | ||
|
|
143fb4f423 | ||
|
|
b7eb12017c | ||
|
|
bd1c6c1506 | ||
|
|
efb7f4f05d | ||
|
|
5475fe661d | ||
|
|
8f62822a33 | ||
|
|
0aa1a9e324 | ||
|
|
7a77bb1c4a | ||
|
|
4576b69e30 | ||
|
|
4fd6eb597d | ||
|
|
257dacd7bb | ||
|
|
c88b7b19b3 | ||
|
|
4fbfb5d0d0 | ||
|
|
67c678270e | ||
|
|
049db9015b | ||
|
|
9dde225b5e | ||
|
|
3a0a22f4cc | ||
|
|
b4a4b15835 | ||
|
|
dca2eab152 | ||
|
|
f9f212442c | ||
|
|
83793aadde | ||
|
|
f7a705c40a | ||
|
|
f5f6edcf5a | ||
|
|
9cb1048c66 | ||
|
|
522a7eb554 | ||
|
|
072833acd5 | ||
|
|
a5aa08e408 | ||
|
|
12d98a1732 | ||
|
|
a6c2c2a10b | ||
|
|
fbe1914226 | ||
|
|
64a744055f | ||
|
|
0007e47c07 | ||
|
|
4708cce8bd | ||
|
|
3eb9156e60 | ||
|
|
2990f9328a | ||
|
|
a0befd65a0 | ||
|
|
872ad8badf | ||
|
|
0970e080d9 | ||
|
|
52fe1461d5 | ||
|
|
d5b33adb88 | ||
|
|
ec84a148f0 | ||
|
|
77d5d4c921 | ||
|
|
58dab48156 | ||
|
|
7abb406d0f | ||
|
|
b941dcd5c5 | ||
|
|
b7adf9b52a | ||
|
|
28f7d83a74 | ||
|
|
34ee1ef3d6 | ||
|
|
e518517456 | ||
|
|
7d0662f1bc | ||
|
|
e3751d29d5 | ||
|
|
04b9ccca22 | ||
|
|
1a17165227 | ||
|
|
b6d968f00c | ||
|
|
a69987a711 | ||
|
|
492328474d | ||
|
|
673a2c581f | ||
|
|
9ef42621e0 | ||
|
|
f5865886b2 | ||
|
|
473e2a1cb2 | ||
|
|
146cf1d1c0 | ||
|
|
ab73055ef3 | ||
|
|
3b83543592 | ||
|
|
d4ac96c24d | ||
|
|
0612129a88 | ||
|
|
9bd5903f1d | ||
|
|
d4eae0e251 | ||
|
|
4d7ea04dd8 | ||
|
|
653fab6b41 | ||
|
|
f4c30b746e | ||
|
|
923e5004e8 | ||
|
|
b14a1e25f0 | ||
|
|
5a3b1123f6 | ||
|
|
6a9494b683 | ||
|
|
63c5658a2b | ||
|
|
fe087cdce9 | ||
|
|
af7efd980c | ||
|
|
2cb325c981 | ||
|
|
66435a7158 | ||
|
|
48417ba911 | ||
|
|
f39c4c8909 | ||
|
|
2a7e720f12 | ||
|
|
ec22250d9b | ||
|
|
a7889756a9 | ||
|
|
9ac67770eb | ||
|
|
3330bca4be | ||
|
|
31f0409bf9 | ||
|
|
ebf9ee089b | ||
|
|
88cf329490 | ||
|
|
bba29d32ce | ||
|
|
2f1f408882 | ||
|
|
46a9e42b8f | ||
|
|
58d3abe165 | ||
|
|
03e737829a | ||
|
|
95d8881454 | ||
|
|
a50a52ca91 | ||
|
|
50371ef309 | ||
|
|
6192d1b53a | ||
|
|
daa9175139 | ||
|
|
8a65611a8c | ||
|
|
6c8a0aa768 | ||
|
|
787b15551d | ||
|
|
2c896e7e5c | ||
|
|
0e49214c7e | ||
|
|
914606a046 | ||
|
|
b30417e908 | ||
|
|
5b8d4cdf68 | ||
|
|
ba06d135c3 | ||
|
|
f0d3d7e81d | ||
|
|
d1bd15291e | ||
|
|
d00b7f4300 | ||
|
|
ebc909b61b | ||
|
|
537fb39b21 | ||
|
|
e106151072 | ||
|
|
257de0709f | ||
|
|
774a819e76 | ||
|
|
ff1412f29d | ||
|
|
c6606c714f | ||
|
|
de3d4e3019 | ||
|
|
2f49e63d5b | ||
|
|
988b40f70d | ||
|
|
b5fdd48d76 | ||
|
|
f4f73a8dfa | ||
|
|
74711c686f | ||
|
|
78c994f7cc | ||
|
|
2d5d668863 | ||
|
|
87279f3518 | ||
|
|
bd10a03da0 | ||
|
|
d138119d24 | ||
|
|
73019665fa | ||
|
|
66824e7757 | ||
|
|
7fe6b29218 | ||
|
|
ebdf973af9 | ||
|
|
71dd7a96c7 | ||
|
|
886dcb3f5d | ||
|
|
37751a2875 | ||
|
|
45347bd44c | ||
|
|
8c4521af03 | ||
|
|
0d2a8db626 | ||
|
|
e791a795b4 | ||
|
|
03d846529d | ||
|
|
607651a3ff | ||
|
|
0714e0dd8f | ||
|
|
224d18589f | ||
|
|
2fd7191836 | ||
|
|
853d162b55 | ||
|
|
762a68a0cf | ||
|
|
1da098671e | ||
|
|
f852a4db0f | ||
|
|
ddea940690 | ||
|
|
292e43b41b | ||
|
|
915e923e35 | ||
|
|
e6ac3af454 | ||
|
|
3adaf8dba9 | ||
|
|
1777cc6e86 | ||
|
|
f9f623bd60 | ||
|
|
fe95707b4e | ||
|
|
a631ee1e1e | ||
|
|
493666dac6 | ||
|
|
46ef4e33c8 | ||
|
|
cafaecfc56 | ||
|
|
47606a71ee | ||
|
|
eedfedd13b | ||
|
|
87d841d81b | ||
|
|
5153eebc9b | ||
|
|
70154f6c23 | ||
|
|
d3577b7877 | ||
|
|
199e0a330f | ||
|
|
a8da1b3334 | ||
|
|
63c19b4631 | ||
|
|
1f471e1cf3 | ||
|
|
ef28c37529 | ||
|
|
cd7e1b9eb7 | ||
|
|
226d476856 | ||
|
|
21965e0e03 | ||
|
|
40ab4a8d3d | ||
|
|
e84d0574fa | ||
|
|
1a64d37fc7 | ||
|
|
9cca843a9b | ||
|
|
ecbf79135f | ||
|
|
96eb48902b | ||
|
|
079c99c47f | ||
|
|
6d2a76b609 | ||
|
|
24e0950ca2 | ||
|
|
98214ce1a4 | ||
|
|
7eed7eab36 | ||
|
|
f0fb5c01a2 | ||
|
|
a92aa3bf49 | ||
|
|
b12cc9fd49 | ||
|
|
a61c3a2636 | ||
|
|
9fd435059f | ||
|
|
3156ac9791 | ||
|
|
b946f33189 | ||
|
|
1e0b7054e6 | ||
|
|
46e04e857c | ||
|
|
4abdeaddbf | ||
|
|
029af1c376 | ||
|
|
c02f2ff4bb | ||
|
|
f74fec8a7e | ||
|
|
50f8e8891b | ||
|
|
d67b1dbd53 | ||
|
|
b0eeb7d67b | ||
|
|
2c6c75cbad | ||
|
|
241388b8a0 | ||
|
|
820b497f42 | ||
|
|
88d8435a02 | ||
|
|
f3f177f3ed | ||
|
|
bfa171cd97 | ||
|
|
19c94ce218 | ||
|
|
5e5033a0f3 | ||
|
|
411a269991 | ||
|
|
bca6aab5a5 | ||
|
|
330e2ff74e | ||
|
|
eb5848478c | ||
|
|
5bb361b1d2 | ||
|
|
0d40364089 | ||
|
|
16c4fe1f37 | ||
|
|
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 |
No files matched your search
+20
@@ -0,0 +1,20 @@
|
|||||||
|
language: cpp
|
||||||
|
|
||||||
|
env:
|
||||||
|
matrix:
|
||||||
|
- MONGOOSE_NO_SOCKETPAIR
|
||||||
|
- MONGOOSE_NO_FILESYSTEM
|
||||||
|
- MONGOOSE_NO_AUTH
|
||||||
|
- MONGOOSE_NO_DAV
|
||||||
|
- MONGOOSE_NO_DIRECTORY_LISTING
|
||||||
|
- MONGOOSE_NO_LOGGING
|
||||||
|
- MONGOOSE_NO_SSI
|
||||||
|
- MONGOOSE_NO_DL
|
||||||
|
- MONGOOSE_NO_WEBSOCKET
|
||||||
|
|
||||||
|
compiler:
|
||||||
|
- gcc
|
||||||
|
- clang
|
||||||
|
|
||||||
|
script:
|
||||||
|
- cd test && make
|
||||||
@@ -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
|
This code is dual-licensed: you can redistribute it and/or modify
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
it under the terms of the GNU General Public License version 2 as
|
||||||
in the Software without restriction, including without limitation the rights
|
published by the Free Software Foundation. For the terms of this
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
license, see <http://www.gnu.org/licenses>.
|
||||||
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
|
You are free to use this code under the terms of the GNU General
|
||||||
all copies or substantial portions of the Software.
|
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
|
Alternatively, you can license this code under a commercial
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
license, as set out in <http://cesanta.com/>.
|
||||||
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.
|
|
||||||
@@ -1,163 +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|cygwin)"
|
|
||||||
|
|
||||||
# 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)
|
|
||||||
# -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)
|
|
||||||
|
|
||||||
|
|
||||||
##########################################################################
|
|
||||||
### UNIX build: linux, bsd, mac, rtems
|
|
||||||
##########################################################################
|
|
||||||
|
|
||||||
# To build with Lua, download and unzip Lua 5.2.1 source code into the
|
|
||||||
# mongoose directory, and then add $(LUA_FLAGS) to CFLAGS below
|
|
||||||
LUA = lua-5.2.1/src
|
|
||||||
LUA_FLAGS = -DUSE_LUA -I$(LUA) -L$(LUA) -llua -lm
|
|
||||||
|
|
||||||
GCC_WARNS = -W -Wall -pedantic
|
|
||||||
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 /DUSE_LUA /I$(LUA)
|
|
||||||
GUILIB= user32.lib shell32.lib
|
|
||||||
LINK = /link /incremental:no /libpath:$(MSVC)/lib /machine:IX86 \
|
|
||||||
/subsystem:windows ws2_32.lib advapi32.lib cyassl.lib lua.lib
|
|
||||||
CYAFL = /c /I $(CYA)/include -I $(CYA)/include/openssl /I$(MSVC)/INCLUDE \
|
|
||||||
/I $(CYA)/ctaocrypt/include /D _LIB /D OPENSSL_EXTRA
|
|
||||||
|
|
||||||
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_OBJECTS = $(LUA_SOURCES:%.c=%.o)
|
|
||||||
|
|
||||||
CYA_SOURCES = $(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) /Fo$(CYA)/ $(CYA_SOURCES) $(CYAFL) $(DEF)
|
|
||||||
$(MSVC)/bin/lib $(CYA)/*.obj /out:$@
|
|
||||||
|
|
||||||
lua.lib:
|
|
||||||
$(CL) /c /Fo$(LUA)/ $(LUA_SOURCES)
|
|
||||||
$(MSVC)/bin/lib $(LUA_SOURCES:%.c=%.obj) /out:$@
|
|
||||||
|
|
||||||
windows: cyassl.lib lua.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
|
|
||||||
|
|
||||||
# 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 ./win32/res.rc ./win32/res.o
|
|
||||||
$(CC) $(CYGWINOPT) mongoose.c -lws2_32 \
|
|
||||||
-shared -Wl,--out-implib=$(PROG).lib -o $(PROG).dll
|
|
||||||
$(CC) $(CYGWINOPT) -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 win32/res.o
|
|
||||||
@@ -1,35 +1,86 @@
|
|||||||
Overview
|
# <img src="http://cesanta.com/images/mongoose_logo.png" width="64" height="64"> Mongoose Web Server
|
||||||
--------
|
|
||||||
|
|
||||||
Mongoose is easy to use web server. It also can be used as embedded web server library to provide web interface to applications.
|
Mongoose is the most easy to use web server on the planet. A web server of choice for Web developers (PHP, Ruby, Python, etc) and Web designers.
|
||||||
|
|
||||||
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, that can be done via command line flags or configuration file, which should be created in the same directory where mongoose itself lives. This makes Mongoose perfect for all sorts of demos, quick tests, file sharing, and Web programming.
|
Mongoose is built on top of Libmongoose embedded library, which can turn
|
||||||
|
anything into a web server in 5 minutes worth of effort and few lines of code.
|
||||||
|
Libmongoose is used to serve Web GUI on embedded devices, implement RESTful
|
||||||
|
services, RPC frameworks (e.g. JSON-RPC), handle telemetry data exchange, and
|
||||||
|
perform many other tasks in various different industries including aerospace,
|
||||||
|
manufacturing, finance, research, automotive, gaming, IT.
|
||||||
|
|
||||||
|
|
||||||
Features
|
* [Mailing list](http://groups.google.com/group/mongoose-users)
|
||||||
--------
|
* [Downloads](http://cesanta.com/mongoose.shtml)
|
||||||
|
* [Documentation](http://cesanta.com/docs.shtml)
|
||||||
|
|
||||||
- Crossplatform - works on Windows, MacOS and most flavors of UNIX
|
# Features
|
||||||
- CGI, SSL, SSI, Digest (MD5) authorization, Websocket, WEbDAV support
|
|
||||||
- Lua server pages (like PHP, but using Lua as a language instead of PHP)
|
|
||||||
- Resumed download, URL rewrite, IP-based ACL, Windows service
|
|
||||||
- Excluding files from serving by URI pattern (file blacklist)
|
|
||||||
- Download speed limit based on client subnet or URI pattern
|
|
||||||
- Small footprint: executable size is 50 kB on Linux 2.6 i386 system
|
|
||||||
- 130 kilobytes Windows executable with all of the above compiled in, and no dependencies
|
|
||||||
- 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)
|
|
||||||
- Super-liberal MIT license, great for commercial users!
|
|
||||||
|
|
||||||
|
- Works on Windows, Mac, UNIX/Linux, iPhone, Android eCos, QNX
|
||||||
|
and many other platforms
|
||||||
|
- CGI, SSI, SSL, Digest auth, Websocket, WEbDAV, Resumed download,
|
||||||
|
URL rewrite, file blacklist
|
||||||
|
- Custom error pages, Virtual hosts, IP-based ACL, Windows service,
|
||||||
|
HTTP/HTTPS client
|
||||||
|
- Simple and clean
|
||||||
|
[embedding API](https://github.com/cesanta/mongoose/blob/master/mongoose.h).
|
||||||
|
The source is in single
|
||||||
|
[mongoose.c](https://github.com/cesanta/mongoose/blob/master/mongoose.c) file
|
||||||
|
to make embedding easy
|
||||||
|
- Extremely lightweight, has a core of under 40kB and tiny runtime footprint
|
||||||
|
- Asynchronous, non-blocking core supporting single- or multi-threaded usage
|
||||||
|
- On the market since 2004 with over 1 million cumulative downloads
|
||||||
|
- Stable, mature and tested, has several man-years invested
|
||||||
|
in continuous improvement and refinement
|
||||||
|
|
||||||
Mailing list
|
# Screenshots
|
||||||
------------
|
|
||||||
|
|
||||||
You can read it online, subscribe to, or send a message at [mongoose-users](http://groups.google.com/group/mongoose-users).
|
Download, double-click to start, run browser -- that's all!
|
||||||
|
|
||||||
|

|
||||||
|

|
||||||
|
|
||||||
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!
|
# Acknowledgements
|
||||||
Many thanks to all who already did so: T.Barmann, D.Hughes, J.C.Sloan and 4 others. Appreciated, guys, you keep my brains going!
|
|
||||||
|
Mongoose made better thanks to the contribution of following people:
|
||||||
|
|
||||||
|
Arnout Vandecappelle, Benoît Amiaux, Boris Pek, Cody Hanson, Colin Leitner,
|
||||||
|
Daniel Oaks, Eric Bakan, Erik Oomen, Filipp Kovalev, Ger Hobbelt,
|
||||||
|
Hendrik Polczynski, Igor Okulist, Jay, Joe Mucchiello, John Safranek,
|
||||||
|
José Miguel Gonçalves, Shueng Chuan, Katerina Blinova, Konstantin Sorokin,
|
||||||
|
Marin Atanasov, Matt Healy, Mitch Hendrickson, Nigel Stewart, Pavel Khlebovich,
|
||||||
|
Sebastian Reinhard, Stefan Doehla, abadc0de, nullable.type,
|
||||||
|
T.Barmann, D.Hughes, J.C.Sloan, R.Romeo, L.E.Spencer, S.Kotay, R.M.Shorter,
|
||||||
|
W.Mar, J.Wilander, Santa from Memphis, S.Davies, C.Beck,
|
||||||
|
O.M.Vilhunen, C.Radik, G.Woodcock, M.Szczepkowski,
|
||||||
|
Eternal Lands Dev Team, T.Tollet, C.Tangerino, G.Karsai, A.Bourgett,
|
||||||
|
C.Blakemore, D.Fonaryov, T.Andrle, O.IJsselmuiden, R.Womack, M.Tomlinson,
|
||||||
|
A.Slåttå, L.Farrell, J.D.P.Ballestero, V.Albaev, B.Harker, T.Scheffel, H.Klein,
|
||||||
|
R.Merit, T.Bennett, H.Solis, A.Zincenko, M.S., S.Krul, K.Cooke, S.McCallum,
|
||||||
|
F.Morenius, and 10 others.
|
||||||
|
|
||||||
|
# Licensing
|
||||||
|
|
||||||
|
Mongoose is released under commercial and
|
||||||
|
[GNU GPL v.2](http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) open
|
||||||
|
source licenses. The GPLv2 open source License does not generally permit
|
||||||
|
incorporating this software into non-open source programs.
|
||||||
|
For those customers who do not wish to comply with the GPLv2 open
|
||||||
|
source license requirements,
|
||||||
|
[Cesanta Software](http://cesanta.com) offers a full,
|
||||||
|
royalty-free commercial license and professional support
|
||||||
|
without any of the GPL restrictions.
|
||||||
|
|
||||||
|
# Other products by Cesanta Software: simple and effective
|
||||||
|
|
||||||
|
- [SSL Wrapper](https://github.com/cesanta/ssl_wrapper) - application to
|
||||||
|
secure network communications
|
||||||
|
- [Frozen](https://github.com/cesanta/frozen) - JSON parser and generator
|
||||||
|
- [SLRE](https://github.com/cesanta/slre) - Super Light Regular Expression
|
||||||
|
library
|
||||||
|
- [Net Skeleton](https://github.com/cesanta/net_skeleton) - framework for
|
||||||
|
building network applications
|
||||||
|
- [SLDR](https://github.com/cesanta/sldr) - Super Light DNS Resolver
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
LOCAL_PATH := $(call my-dir)/../..
|
||||||
|
include $(CLEAR_VARS)
|
||||||
|
|
||||||
|
# To build with lua support, uncomment two lines below:
|
||||||
|
#LUA_SOURCES := build/lua_5.2.1.c build/sqlite3.c build/lsqlite3.c
|
||||||
|
#LUA_FLAGS := -I$(LOCAL_PATH)/build -DTHREADSAFE=1 -DSQLITE_ENABLE_FTS3 -DSQLITE_ENABLE_FTS3_PARENTHESIS -DUSE_LUA -DUSE_LUA_SQLITE3 -DLUA_COMPAT_ALL -D"getlocaledecpoint() ='.'"
|
||||||
|
|
||||||
|
LOCAL_CFLAGS := -std=c99 -O2 -W -Wall -pthread -pipe $(LUA_FLAGS) $(COPT)
|
||||||
|
LOCAL_MODULE := mongoose
|
||||||
|
LOCAL_SRC_FILES := examples/server.c mongoose.c $(LUA_SOURCES)
|
||||||
|
|
||||||
|
include $(BUILD_EXECUTABLE)
|
||||||
@@ -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.write('HTTP/1.0 200 OK\r\n')
|
|
||||||
conn.write('Content-Type: text/plain\r\n\r\n')
|
|
||||||
return True
|
|
||||||
elif event == mongoose.NEW_REQUEST and info.uri == '/show':
|
|
||||||
conn.write('HTTP/1.0 200 OK\r\n')
|
|
||||||
conn.write('Content-Type: text/plain\r\n\r\n')
|
|
||||||
conn.write('[%s] [%s] [%s]\n' % (info.request_method, info.uri,
|
|
||||||
info.query_string))
|
|
||||||
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.write('my_var: %s\n' % (my_var or '<not set>'))
|
|
||||||
conn.write('HEADERS: \n')
|
|
||||||
for header in info.http_headers[:info.num_headers]:
|
|
||||||
conn.write(' %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,166 +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
|
|
||||||
OPEN_FILE = 9
|
|
||||||
INIT_LUA = 10
|
|
||||||
|
|
||||||
|
|
||||||
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),
|
|
||||||
('user_data', ctypes.c_void_p),
|
|
||||||
('ev_data', ctypes.c_void_p),
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
||||||
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)
|
|
||||||
+246
@@ -0,0 +1,246 @@
|
|||||||
|
# Mongoose API Reference
|
||||||
|
|
||||||
|
struct mg_server *mg_create_server(void *server_param);
|
||||||
|
|
||||||
|
Creates web server instance. Returns opaque instance pointer, or NULL if
|
||||||
|
there is not enough memory. `server_param`: Could be any pointer, or NULL.
|
||||||
|
This pointer will be passed
|
||||||
|
to the callback functions as `struct mg_connection::server_param` field.
|
||||||
|
A common use case is to pass `this` pointer of the C++ wrapper class
|
||||||
|
as `user_param`, to let the callback get the pointer to the C++ object.
|
||||||
|
|
||||||
|
Note that this function doesn't make the
|
||||||
|
server instance to serve. Serving is done by `mg_poll_server()` function.
|
||||||
|
Mongoose has single-threaded, event-driven, asynchronous, non-blocking core.
|
||||||
|
When server instance is created, it contains an information about
|
||||||
|
the configuration and the state of each connection.
|
||||||
|
Server instance is capable on listening on only one port. After creation,
|
||||||
|
`struct mg_server` has a list
|
||||||
|
of active connections and configuration parameters.
|
||||||
|
|
||||||
|
Side-effect: on UNIX, `mg_create_server()` ignores SIGPIPE signals. If custom
|
||||||
|
processing is required SIGPIPE, signal handler must be set up after
|
||||||
|
calling `mg_create_server()`.
|
||||||
|
|
||||||
|
Important: Mongoose does not install `SIGCHLD` handler. If CGI is used,
|
||||||
|
`SIGCHLD` handler must be set up to reap CGI zombie processes.
|
||||||
|
|
||||||
|
|
||||||
|
void mg_destroy_server(struct mg_server **server);
|
||||||
|
|
||||||
|
Deallocates web server instance, closes all pending connections, and makes
|
||||||
|
server pointer a NULL pointer.
|
||||||
|
|
||||||
|
const char mg_set_option(struct mg_server *server, const char *name,
|
||||||
|
const char *value);
|
||||||
|
|
||||||
|
Sets a particular server option. Note that at least one option,
|
||||||
|
`listening_port`, must be specified. To serve static files, `document_root`
|
||||||
|
must be specified too. If `document_root` option is left unset, Mongoose
|
||||||
|
will not access filesystem at all. `mg_set_option()` returns NULL if option was
|
||||||
|
set successfully, otherwise it returns human-readable error string. It is
|
||||||
|
allowed to call `mg_set_option()` by the same thread that does
|
||||||
|
`mg_poll_server()` (Mongoose thread) and change server configuration while it
|
||||||
|
is serving, in between `mg_poll_server()` calls.
|
||||||
|
|
||||||
|
int mg_poll_server(struct mg_server *server, int milliseconds);
|
||||||
|
|
||||||
|
Performs one iteration of IO loop by iterating over all
|
||||||
|
active connections, performing `select()` syscall on all sockets with a timeout
|
||||||
|
of `milliseconds`. When `select()` returns, Mongoose
|
||||||
|
does an IO for each socket that has data to be sent or received. Application
|
||||||
|
code must call `mg_poll_server()` in a loop. It is an error to have more then
|
||||||
|
one thread calling `mg_poll_server()`, `mg_set_option()` or any other function
|
||||||
|
that take `struct mg_server *` parameter. Mongoose does not
|
||||||
|
mutex-protect `struct mg_server *`, therefore only single thread
|
||||||
|
(Mongoose thread) should make Mongoose calls.
|
||||||
|
|
||||||
|
`mg_poll_server()` calls user-specified event handler when certain events
|
||||||
|
occur. Sequence of events for the accepted connection is this:
|
||||||
|
|
||||||
|
* `MG_AUTH` - Mongoose asks whether this connection is authorized. If event
|
||||||
|
handler returns `MG_FALSE`, then Mongoose does not serve the request but
|
||||||
|
sends authorization request to the client. If `MG_TRUE` is returned,
|
||||||
|
then Mongoose continues on with the request.
|
||||||
|
* `MG_REQUEST` - Mongoose asks event handler to serve the request. If
|
||||||
|
event handler serves the request by sending a reply,
|
||||||
|
it should return `MG_TRUE`. Otherwise,
|
||||||
|
it should return `MG_FALSE` which tells Mongoose that request is not
|
||||||
|
served and Mongoose should serve it. For example, event handler might
|
||||||
|
choose to serve only RESTful API requests with URIs that start with
|
||||||
|
certain prefix, and let Mongoose serve all static files.
|
||||||
|
If event handler decides to serve the request, but doesn't have
|
||||||
|
all the data at the moment, it should return `MG_MORE`. That tells
|
||||||
|
Mongoose to keep the connection open after callback returns.
|
||||||
|
|
||||||
|
`mg_connection::connection_param` pointer is a placeholder to keep
|
||||||
|
user-specific data. For example, handler could decide to open a DB
|
||||||
|
connection and store DB connection handle in `connection_param`.
|
||||||
|
* `MG_POLL` is sent to every connection on every iteration of
|
||||||
|
`mg_poll_server()`. Event handler should return `MG_FALSE` to ignore
|
||||||
|
this event. If event handler returns `MG_TRUE`, then Mongoose assumes
|
||||||
|
that event handler has finished sending data, and Mongoose will
|
||||||
|
close the connection.
|
||||||
|
* `MG_HTTP_ERROR` sent when Mongoose is about to send HTTP error back
|
||||||
|
to the client. Event handler can choose to send a reply itself, in which
|
||||||
|
case event handler must return `MG_TRUE`. Otherwise, event handler must
|
||||||
|
return `MG_FALSE`.
|
||||||
|
* `MG_CLOSE` is sent when the connection is closed. This event is used
|
||||||
|
to cleanup per-connection state stored in `connection_param`
|
||||||
|
if it was allocated. Event handler return value is ignored.
|
||||||
|
|
||||||
|
Sequence of events for the client connection is this:
|
||||||
|
|
||||||
|
* `MG_CONNECT` sent when Mongoose has connected to the remote host.
|
||||||
|
This event is sent to the connection initiated by `mg_connect()` call.
|
||||||
|
Connection status is held in `mg_connection::status_code`: if zero,
|
||||||
|
then connection was successful, otherwise connection was not established.
|
||||||
|
User should send a request upon successful connection.
|
||||||
|
Event handler should return `MG_TRUE` if connection was successful and
|
||||||
|
HTTP request has been sent. Otherwise, it should send `MG_FALSE`.
|
||||||
|
* `MG_REPLY` is sent when response has been received from the remote host.
|
||||||
|
If event handler sends another request, then it should return `MG_TRUE`.
|
||||||
|
Otherwise it should return `MG_FALSE` and Mongoose will close the connection.
|
||||||
|
* `MG_CLOSE` same as for the accepted connection.
|
||||||
|
|
||||||
|
|
||||||
|
When mongoose buffers in HTTP request and successfully parses it, it sends
|
||||||
|
`MG_REQUEST` event for GET requests immediately. For POST requests,
|
||||||
|
Mongoose delays the call until the whole POST request is buffered in memory.
|
||||||
|
POST data is available to the callback as `struct mg_connection::content`,
|
||||||
|
and POST data length is in `struct mg_connection::content_len`.
|
||||||
|
|
||||||
|
Note that websocket connections are treated the same way. Mongoose buffers
|
||||||
|
websocket frame in memory, and calls event handler when frame is fully
|
||||||
|
buffered. Frame data is available `struct mg_connection::content`, and
|
||||||
|
data length is in `struct mg_connection::content_len`, i.e. very similar to
|
||||||
|
the POST request. `struct mg_connection::is_websocket` flag indicates
|
||||||
|
whether the request is websocket or not. Also, for websocket requests,
|
||||||
|
there is `struct mg_connection::wsbits` field which contains first byte
|
||||||
|
of the websocket frame which URI handler can examine. Note that to
|
||||||
|
reply to the websocket client, `mg_websocket_write()` should be used.
|
||||||
|
To reply to the plain HTTP client, `mg_write_data()` should be used.
|
||||||
|
|
||||||
|
Return value: number of active connections.
|
||||||
|
|
||||||
|
|
||||||
|
const char **mg_get_valid_option_names(void);
|
||||||
|
|
||||||
|
Returns a NULL-terminated array of option names and their default values.
|
||||||
|
There are two entries per option in an array: an option name followed by a
|
||||||
|
default value. A default value could be NULL. A NULL name indicates an end
|
||||||
|
of the array.
|
||||||
|
|
||||||
|
const char *mg_get_option(const struct mg_server *server, const char *name);
|
||||||
|
|
||||||
|
Returns the value of particular configuration parameter. If
|
||||||
|
given parameter name is not valid, NULL is returned. For valid names, return
|
||||||
|
value is guaranteed to be non-NULL. If parameter is not set, zero-length string
|
||||||
|
is returned.
|
||||||
|
|
||||||
|
void mg_wakeup_server_ex(struct mg_server *, mg_handler_t func,
|
||||||
|
const char *fmt, ...);
|
||||||
|
|
||||||
|
Sends string message to a server. Function `func` is called for every active
|
||||||
|
connection. String message is passed in `struct mg_connection::callback_param`.
|
||||||
|
This function is designed to push data to the connected clients, and
|
||||||
|
can be called from any thread. There is a limitation on the length of
|
||||||
|
the message, currently at 8 kilobytes.
|
||||||
|
|
||||||
|
void mg_send_status(struct mg_connection *, int status_code);
|
||||||
|
void mg_send_header(struct mg_connection *, const char *name,
|
||||||
|
const char *value);
|
||||||
|
void mg_send_data(struct mg_connection *, const void *data, int data_len);
|
||||||
|
void mg_printf_data(struct mg_connection *, const char *format, ...);
|
||||||
|
|
||||||
|
These functions are used to construct a response to the client. HTTP response
|
||||||
|
consists of three parts: a status line, zero or more HTTP headers,
|
||||||
|
a response body. Mongoose provides functions for all three parts:
|
||||||
|
* `mg_send_status()` is used to create status line. This function can be
|
||||||
|
called zero or once. If `mg_send_status()` is not called, then Mongoose
|
||||||
|
will send status 200 (success) implicitly.
|
||||||
|
* `mg_send_header()` adds HTTP header to the response. This function could
|
||||||
|
be called zero or more times.
|
||||||
|
* `mg_send_data()` and `mg_printf_data()` are used to send data to the
|
||||||
|
client. Note that Mongoose adds `Transfer-Encoding: chunked` header
|
||||||
|
implicitly, and sends data in chunks. Therefore, it is not necessary to
|
||||||
|
set `Content-Length` header. Note that `mg_send_data()` and
|
||||||
|
`mg_printf_data()` do not send data immediately. Instead, they spool
|
||||||
|
data in memory, and Mongoose sends that data later after URI handler
|
||||||
|
returns. If data to be sent is huge, an URI handler might
|
||||||
|
send data in pieces by saving state in
|
||||||
|
`struct mg_connection::connection_param` variable and returning `0`. Then
|
||||||
|
Mongoose will call a handler repeatedly after each socket write.
|
||||||
|
|
||||||
|
<!-- -->
|
||||||
|
|
||||||
|
void mg_send_file(struct mg_connection *, const char *path);
|
||||||
|
|
||||||
|
Tells Mongoose to serve given file. Mongoose handles file according to
|
||||||
|
it's extensions, i.e. Mongoose will invoke CGI script if `path` has CGI
|
||||||
|
extension, it'll render SSI file if `path` has SSI extension, etc. If `path`
|
||||||
|
points to a directory, Mongoose will show directory listing. If this function
|
||||||
|
is used, no calls to `mg_send*` or `mg_printf*` functions must be made, and
|
||||||
|
event handler must return `MG_MORE`.
|
||||||
|
|
||||||
|
int mg_websocket_write(struct mg_connection* conn, int opcode,
|
||||||
|
const char *data, size_t data_len);
|
||||||
|
|
||||||
|
Similar to `mg_write()`, but wraps the data into a websocket frame with a
|
||||||
|
given websocket `opcode`.
|
||||||
|
|
||||||
|
const char *mg_get_header(const struct mg_connection *, const char *name);
|
||||||
|
|
||||||
|
Get the value of particular HTTP header. This is a helper function.
|
||||||
|
It traverses http_headers array, and if the header is present in the array,
|
||||||
|
returns its value. If it is not present, NULL is returned.
|
||||||
|
|
||||||
|
|
||||||
|
int mg_get_var(const struct mg_connection *conn, const char *var_name,
|
||||||
|
char *buf, size_t buf_len);
|
||||||
|
|
||||||
|
Gets HTTP form variable. Both POST buffer and query string are inspected.
|
||||||
|
Form variable is url-decoded and written to the buffer. On success, this
|
||||||
|
function returns the length of decoded variable. On error, -1 is returned if
|
||||||
|
variable not found, and -2 is returned if destination buffer is too small
|
||||||
|
to hold the variable. Destination buffer is guaranteed to be
|
||||||
|
'\0' - terminated if it is not NULL or zero length.
|
||||||
|
|
||||||
|
int mg_parse_header(const char *hdr, const char *var_name, char *buf,
|
||||||
|
size_t buf_size);
|
||||||
|
|
||||||
|
This function parses HTTP header and fetches given variable's value in a buffer.
|
||||||
|
A header should be like `x=123, y=345, z="other value"`. This function is
|
||||||
|
designed to parse Cookie headers, Authorization headers, and similar. Returns
|
||||||
|
the length of the fetched value, or 0 if variable not found.
|
||||||
|
|
||||||
|
int mg_modify_passwords_file(const char *passwords_file_name,
|
||||||
|
const char *domain,
|
||||||
|
const char *user,
|
||||||
|
const char *password);
|
||||||
|
|
||||||
|
Add, edit or delete the entry in the passwords file.
|
||||||
|
This function allows an application to manipulate .htpasswd files on the
|
||||||
|
fly by adding, deleting and changing user records. This is one of the
|
||||||
|
several ways of implementing authentication on the server side.
|
||||||
|
If password is not NULL, entry is added (or modified if already exists).
|
||||||
|
If password is NULL, entry is deleted.
|
||||||
|
Return: 1 on success, 0 on error.
|
||||||
|
|
||||||
|
|
||||||
|
int mg_parse_multipart(const char *buf, int buf_len,
|
||||||
|
char *var_name, int var_name_len,
|
||||||
|
char *file_name, int file_name_len,
|
||||||
|
const char **data, int *data_len);
|
||||||
|
|
||||||
|
Parses a buffer that contains multipart form data. Stores chunk name
|
||||||
|
in a `var_name` buffer. If chunk is an uploaded file, then `file_name`
|
||||||
|
will have a file name. `data` and `data_len` will point to the chunk data.
|
||||||
|
Returns number of bytes to skip to the next chunk.
|
||||||
|
|
||||||
|
struct mg_connection *mg_connect(struct mg_server *server,
|
||||||
|
const char *host, int port, int use_ssl);
|
||||||
|
|
||||||
|
Create connection to the remote host. Returns `NULL` on error, non-null
|
||||||
|
if the connection has been scheduled for connection. Upon a connection,
|
||||||
|
Mongoose will send `MG_CONNECT` event to the event handler.
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
# Mongoose 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.
|
||||||
|
|
||||||
|
- Clone Mongoose Git repo
|
||||||
|
- 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/examples`
|
||||||
|
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.
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
How To Create Basic Website With Mongoose
|
||||||
|
===========================================
|
||||||
|
|
||||||
|
## 1. Create a directory which will contain your website files. For example, on drive `C:\`, create a directory called `my_website`:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## 2. Inside `my_website` directory, create a new file called "index". This will be the default web page shown when the website is visited.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## 3. Open index file with your favorite editor (for example, Notepad) and enter some HTML code:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## 4. Save this file as `index.html`:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
|
||||||
|
## 5. Download Mongoose executable from http://cesanta.com/mongoose.shtml and copy the executable inside `my_website` directory:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## 6. Double-click mongoose executable. An icon will appear on a system tray in the bottom right corner of the desktop:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## 7. Click on the mongoose icon and choose "Go to my address" menu:
|
||||||
|

|
||||||
|
|
||||||
|
## 8. A browser will popup displaying `index.html` file. Now, you can expand your website by adding more content.
|
||||||
|
|
||||||
|

|
||||||
+171
@@ -0,0 +1,171 @@
|
|||||||
|
# Mongoose Embedding Guide
|
||||||
|
|
||||||
|
Embedding Mongoose is done in two steps:
|
||||||
|
|
||||||
|
1. Copy
|
||||||
|
[mongoose.c](https://raw.github.com/cesanta/mongoose/master/mongoose.c) and
|
||||||
|
[mongoose.h](https://raw.github.com/cesanta/mongoose/master/mongoose.h)
|
||||||
|
to your application's source tree and include them in the build.
|
||||||
|
2. Somewhere in the application code, call `mg_create_server()` to create
|
||||||
|
a server, configure it with `mg_set_option()` and loop with
|
||||||
|
`mg_poll_server()` until done. Call `mg_destroy_server()` to cleanup.
|
||||||
|
|
||||||
|
Here's a minimal application `app.c` that embeds mongoose:
|
||||||
|
|
||||||
|
#include "mongoose.h"
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
struct mg_server *server = mg_create_server(NULL, NULL);
|
||||||
|
mg_set_option(server, "document_root", "."); // Serve current directory
|
||||||
|
mg_set_option(server, "listening_port", "8080"); // Open port 8080
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
|
mg_poll_server(server, 1000); // Infinite loop, Ctrl-C to stop
|
||||||
|
}
|
||||||
|
mg_destroy_server(&server);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
To compile it, put `mongoose.c`, `mongoose.h` and `app.c` into one
|
||||||
|
folder, start terminal on UNIX or Visual Studio command line prompt on Windows,
|
||||||
|
and run the following command:
|
||||||
|
|
||||||
|
cc app.c mongoose.c -pthread -o app # on Unix
|
||||||
|
cl.exe app.c mongoose.c /TC /MD # on Windows
|
||||||
|
|
||||||
|
When run, this simple application opens port 8080 and serves static files,
|
||||||
|
CGI files and lists directory content in the current working directory.
|
||||||
|
|
||||||
|
It is possible to generate HTML page content. Mongoose can call user-defined
|
||||||
|
function when certain events occur.
|
||||||
|
That function is called _an event handler_, and it is the second parameter
|
||||||
|
to `mg_create_server()` function. Here is the example event handler function:
|
||||||
|
|
||||||
|
int event_handler(struct mg_connection *conn, enum mg_event ev) {
|
||||||
|
switch (ev) {
|
||||||
|
case MG_AUTH: return MG_TRUE;
|
||||||
|
default: return MG_FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Event handler is called by Mongoose with `struct mg_connection *`
|
||||||
|
pointer and an event number. `struct mg_connection *conn`
|
||||||
|
has all information about the request: HTTP headers, POST or websocket
|
||||||
|
data buffer, etcetera. `enum mg_event ev` tells which exactly event is sent.
|
||||||
|
For each event, an event handler returns a value which tells Mongoose how
|
||||||
|
to behave.
|
||||||
|
|
||||||
|
The sequence of events for every connection is this:
|
||||||
|
|
||||||
|
* `MG_AUTH` - Mongoose asks whether this connection is authorized. If event
|
||||||
|
handler returns `MG_FALSE`, then Mongoose does not serve the request but
|
||||||
|
sends authorization request to the client. If `MG_TRUE` is returned,
|
||||||
|
then Mongoose continues on with the request.
|
||||||
|
* `MG_REQUEST` - Mongoose asks event handler to serve the request. If
|
||||||
|
event handler serves the request by sending a reply,
|
||||||
|
it should return `MG_TRUE`. Otherwise,
|
||||||
|
it should return `MG_FALSE` which tells Mongoose that request is not
|
||||||
|
served and Mongoose should serve it. For example, event handler might
|
||||||
|
choose to serve only RESTful API requests with URIs that start with
|
||||||
|
certain prefix, and let Mongoose serve all static files.
|
||||||
|
If event handler decides to serve the request, but doesn't have
|
||||||
|
all the data at the moment, it should return `MG_MORE`. That tells
|
||||||
|
Mongoose to keep the connection open after callback returns.
|
||||||
|
|
||||||
|
`mg_connection::connection_param` pointer is a placeholder to keep
|
||||||
|
user-specific data. For example, handler could decide to open a DB
|
||||||
|
connection and store DB connection handle in `connection_param`.
|
||||||
|
* `MG_POLL` is sent to every connection on every iteration of
|
||||||
|
`mg_poll_server()`. Event handler should return `MG_FALSE` to ignore
|
||||||
|
this event. If event handler returns `MG_TRUE`, then Mongoose assumes
|
||||||
|
that event handler has finished sending data, and Mongoose will
|
||||||
|
close the connection.
|
||||||
|
* `MG_HTTP_ERROR` sent when Mongoose is about to send HTTP error back
|
||||||
|
to the client. Event handler can choose to send a reply itself, in which
|
||||||
|
case event handler must return `MG_TRUE`. Otherwise, event handler must
|
||||||
|
return `MG_FALSE`
|
||||||
|
* `MG_CLOSE` is sent when the connection is closed. This event is used
|
||||||
|
to cleanup per-connection state stored in `connection_param`
|
||||||
|
if it was allocated.
|
||||||
|
|
||||||
|
Let's extend our minimal application example and
|
||||||
|
create an URI that will be served by user's C code. The app will handle
|
||||||
|
`/hello` URI by showing a hello message. So, when app is run,
|
||||||
|
http://127.0.0.1:8080/hello will say hello, and here's the code:
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include "mongoose.h"
|
||||||
|
|
||||||
|
static int event_handler(struct mg_connection *conn, enum mg_event ev) {
|
||||||
|
if (ev == MG_AUTH) {
|
||||||
|
return MG_TRUE; // Authorize all requests
|
||||||
|
} else if (ev == MG_REQUEST && !strcmp(conn->uri, "/hello")) {
|
||||||
|
mg_printf_data(conn, "%s", "Hello world");
|
||||||
|
return MG_TRUE; // Mark as processed
|
||||||
|
} else {
|
||||||
|
return MG_FALSE; // Rest of the events are not processed
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
struct mg_server *server = mg_create_server(NULL, event_handler);
|
||||||
|
mg_set_option(server, "document_root", ".");
|
||||||
|
mg_set_option(server, "listening_port", "8080");
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
|
mg_poll_server(server, 1000); // Infinite loop, Ctrl-C to stop
|
||||||
|
}
|
||||||
|
mg_destroy_server(&server);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
## Example code
|
||||||
|
|
||||||
|
Mongoose source code contains number of examples, located in the
|
||||||
|
[examples](https://github.com/cesanta/mongoose/blob/master/examples/) directory.
|
||||||
|
To build any example, go to the respective directory and run `make`.
|
||||||
|
|
||||||
|
## Compilation flags
|
||||||
|
|
||||||
|
Below is the list of compilation flags that enable or disable certain
|
||||||
|
features. By default, some features are enabled, and could be disabled
|
||||||
|
by setting appropriate `NO_*` flag. Features that are disabled by default
|
||||||
|
could be enabled by setting appropriate `USE_*` flag. Bare bones Mongoose
|
||||||
|
is quite small, about 30 kilobytes of compiled x86 code. Each feature adds
|
||||||
|
a couple of kilobytes to the executable size, and also has some runtime penalty.
|
||||||
|
|
||||||
|
Note that some flags start with `NS_` prefix. This is because Mongoose uses
|
||||||
|
[Net Skeleton](http://github.com/cesanta/net_skeleton) as a low-level
|
||||||
|
networking engine. If user code has `#include <net_skeleton.h>`, then
|
||||||
|
all Net Skeleton functions will be available too.
|
||||||
|
|
||||||
|
|
||||||
|
-DMONGOOSE_NO_AUTH Disable MD5 authorization support
|
||||||
|
-DMONGOOSE_NO_CGI Disable CGI support
|
||||||
|
-DMONGOOSE_NO_DAV Disable WebDAV support
|
||||||
|
(PUT, DELETE, MKCOL, PROPFIND methods)
|
||||||
|
-DMONGOOSE_NO_DIRECTORY_LISTING Disable directory listing
|
||||||
|
-DMONGOOSE_NO_FILESYSTEM Disables all file IO, serving from memory only
|
||||||
|
-DMONGOOSE_NO_LOGGING Disable access/error logging
|
||||||
|
-DMONGOOSE_NO_THREADS
|
||||||
|
-DMONGOOSE_NO_WEBSOCKET Disable WebSocket support
|
||||||
|
|
||||||
|
-DMONGOOSE_USE_IDLE_TIMEOUT_SECONDS=X Idle connection timeout, default is 30
|
||||||
|
-DMONGOOSE_USE_LUA Enable Lua scripting
|
||||||
|
-DMONGOOSE_USE_LUA_SQLITE3 Enable sqlite3 binding for Lua
|
||||||
|
-DMONGOOSE_USE_POST_SIZE_LIMIT=X POST requests larger than X will be
|
||||||
|
rejected, not set by default
|
||||||
|
-DMONGOOSE_USE_EXTRA_HTTP_HEADERS=X Append X to the HTTP headers
|
||||||
|
for static files, empty by default
|
||||||
|
|
||||||
|
-DNS_ENABLE_DEBUG Enables debug messages on stdout, very noisy
|
||||||
|
-DNS_ENABLE_SSL Enable SSL
|
||||||
|
-DNS_ENABLE_IPV6 Enable IPv6 support
|
||||||
|
-DNS_ENABLE_HEXDUMP Enables hexdump of sent and received traffic
|
||||||
|
-DNS_STACK_SIZE=X Sets stack size to X for ns_start_thread()
|
||||||
|
-DNS_DISABLE_THREADS Disable threads support
|
||||||
|
-DNS_DISABLE_SOCKETPAIR For systems without loopback interface
|
||||||
|
-DMONGOOSE_SEND_NS_EVENTS Send Net Skeleton events to the event handler
|
||||||
|
in addition to the Mongoose events
|
||||||
+45
@@ -0,0 +1,45 @@
|
|||||||
|
# Mongoose FAQ
|
||||||
|
|
||||||
|
## My Antivirus Software reports Mongoose as a security threat
|
||||||
|
|
||||||
|
Mongoose doesn't contain any malicious logic. Antivirus reports a
|
||||||
|
[false positive](http://en.wikipedia.org/wiki/Type_I_and_type_II_errors#False_positive_error).
|
||||||
|
This is when certain byte sequence in Mongoose accidentally matches
|
||||||
|
virus signature in the Antivirus database.
|
||||||
|
|
||||||
|
## Download page doesn't work
|
||||||
|
|
||||||
|
Please make sure Javascript is enabled in your browser, and that the
|
||||||
|
antivirus software is not blocking the download.
|
||||||
|
|
||||||
|
|
||||||
|
## MacOS message: "Mongoose.app is damaged and can’t be opened. You should move it to the Trash"
|
||||||
|
|
||||||
|
This happens on newer MacOS systems. The reason for the message
|
||||||
|
is the fact Mongoose.app is not digitally signed.
|
||||||
|
Mongoose download procedure changes the app on the fly by injecting
|
||||||
|
user information in the binary, making any prior digital signature void.
|
||||||
|
Open "System Preferences" -> "Security" and set "Allow apps downloaded from"
|
||||||
|
to "Anywhere". Revert the settings once Mongoose is installed.
|
||||||
|
|
||||||
|
## 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 to the Visual Studio project settings.
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
How To Share Files With Mongoose
|
||||||
|
===========================================
|
||||||
|
|
||||||
|
## 1. Download Mongoose executable from http://cesanta.com/mongoose.shtml and copy the executable inside the directory you want to share:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## 2. Double-click mongoose executable. A browser will start automatically, an icon will appear on a system tray in the bottom right corner of the desktop:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## 3. Click on the mongoose icon
|
||||||
|

|
||||||
|
|
||||||
|
|
||||||
|
## 4. Click on "Go to my address" to launch a browser locally. Or, to access a folder from another machine, launch a browser and type in the URL:
|
||||||
|
|
||||||
|

|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
# Mongoose Internals
|
||||||
|
|
||||||
|
Mongoose has single-threaded, event-driven, asynchronous, non-blocking core.
|
||||||
|
`mg_create_server()` creates a web server instance. An instance is a container
|
||||||
|
for the config options and list of active connections. To do the actual
|
||||||
|
serving, user must call `mg_poll_server()`, which iterates over all
|
||||||
|
active connections, performing `select()` syscall on all sockets with a
|
||||||
|
timeout of specified number of milliseconds. When `select()` returns, Mongoose
|
||||||
|
does an IO for each socket that has data to be sent or received. Application
|
||||||
|
code must call `mg_poll_server()` in a loop.
|
||||||
|
|
||||||
|
Mongoose server instance is designed to be used by a single thread.
|
||||||
|
It is an error to have more then
|
||||||
|
one thread calling `mg_poll_server()`, `mg_set_option()` or any other function
|
||||||
|
that take `struct mg_server *` parameter. Mongoose does not
|
||||||
|
mutex-protect `struct mg_server *`, therefore the best practice is
|
||||||
|
to call server management functions from the same thread (an IO thread).
|
||||||
|
On a multi-core systems, many server instances can be created, sharing the
|
||||||
|
same listening socket and managed by separate threads (see [multi_threaded.c](https://github.com/cesanta/mongoose/blob/master/examples/multi_threaded.c))
|
||||||
|
example.
|
||||||
|
|
||||||
|
It is an error to pass and store `struct mg_connection *` pointers for
|
||||||
|
later use to send data. The reason is that they can be invalidated by the
|
||||||
|
next `mg_poll_server()` call. For such a task,
|
||||||
|
there is `mg_iterate_over_connections()` API
|
||||||
|
exists, which sends a callback function to the IO thread, then IO thread
|
||||||
|
calls specified function for all active connection.
|
||||||
|
|
||||||
|
When mongoose buffers in HTTP request and successfully parses it, it calls
|
||||||
|
appropriate URI handler immediately for GET requests. For POST requests,
|
||||||
|
Mongoose delays the call until the whole POST request is buffered in memory.
|
||||||
|
POST data is available to the callback as `struct mg_connection::content`,
|
||||||
|
and POST data length is in `struct mg_connection::content_len`.
|
||||||
|
|
||||||
|
Note that websocket connections are treated the same way. Mongoose buffers
|
||||||
|
websocket frame in memory, and calls URI handler when frame is fully
|
||||||
|
buffered. Frame data is available `struct mg_connection::content`, and
|
||||||
|
data length is in `struct mg_connection::content_len`, i.e. very similar to
|
||||||
|
the POST request. `struct mg_connection::is_websocket` flag indicates
|
||||||
|
whether the request is websocket or not. Also, for websocket requests,
|
||||||
|
there is `struct mg_connection::wsbits` field which contains first byte
|
||||||
|
of the websocket frame which URI handler can examine. Note that to
|
||||||
|
reply to the websocket client, `mg_websocket_write()` should be used.
|
||||||
|
To reply to the plain HTTP client, `mg_write()` should be used.
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
# Mongoose Lua Server Pages
|
||||||
|
|
||||||
|
Pre-built Windows and Mac mongoose binaries support Lua Server Pages
|
||||||
|
functionality.
|
||||||
|
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.3, 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 a file that is called `ANY_NAME.lp`. For example,
|
||||||
|
`my_page.lp`. It is important to have a file
|
||||||
|
name that ends up with `.lp`, cause this is the way mongoose recognises
|
||||||
|
Lua Page file. The contents of the file, just like
|
||||||
|
with PHP, is HTML with embedded Lua code. Lua code must be enclosed within
|
||||||
|
`<? ?>` blocks, and can appear anywhere on the page.
|
||||||
|
|
||||||
|
Mongoose does not send HTTP headers for Lua pages. Therefore,
|
||||||
|
every Lua Page must begin with HTTP status line and headers, like this:
|
||||||
|
|
||||||
|
<? mg.write('HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n') ?>
|
||||||
|
<html><body>
|
||||||
|
<span>Today is:</span> <? mg.write(os.date("%A")) ?>
|
||||||
|
</body></html>
|
||||||
|
|
||||||
|
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).
|
||||||
|
Information about the request is available via the `mg.request_info` object.
|
||||||
|
I contains request method, all headers, etcetera. Please refer to
|
||||||
|
`struct mg_request_info` definition in
|
||||||
|
[mongoose.h](https://github.com/cesanta/mongoose/blob/master/mongoose.h)
|
||||||
|
to see what is available via the `mg.request_info` object.
|
||||||
|
Check out [prime_numbers.lp](https://github.com/cesanta/mongoose/blob/master/examples/lua/prime_numbers.lp) for some example.
|
||||||
|
|
||||||
|
Mongoose exports the following to the Lua Server Page:
|
||||||
|
|
||||||
|
mg.write(str) -- writes string to the client
|
||||||
|
mg.onerror(msg) -- error handler, can be overridden
|
||||||
|
mg.request_info -- a table with request information
|
||||||
|
|
||||||
|
Using Lua scripting it is easy to emulate SSI functionality. For example,
|
||||||
|
to include the content of another file, one can write:
|
||||||
|
|
||||||
|
<? mg.write(io.open('MY_FILE.TXT'):read('*all')) ?>
|
||||||
|
|
||||||
|
To serve a 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 all following blocks.
|
||||||
+154
@@ -0,0 +1,154 @@
|
|||||||
|
# Mongoose Configuration Options
|
||||||
|
|
||||||
|
### 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. Example: `$ mongoose -access_control_list -0.0.0.0/0,+192.168/16` to deny all acccesses except those from `192.168/16` subnet. Note that if the option is set, then all accesses are forbidden
|
||||||
|
by default. Thus in a previous example, `-0.0.0.0` part is not necessary.
|
||||||
|
For example, `$mongoose access_control_list +10.0.0.0/8`
|
||||||
|
means disallow all, allow subnet 10/8 only.
|
||||||
|
|
||||||
|
To learn more about subnet masks, see the
|
||||||
|
[Wikipedia page on Subnetwork](http://en.wikipedia.org/wiki/Subnetwork)
|
||||||
|
|
||||||
|
Default: not set, all accesses are allowed.
|
||||||
|
|
||||||
|
### access\_log\_file
|
||||||
|
Path to a file for access logs. Either full path, or relative to the
|
||||||
|
mongoose executable. Default: not set, no query logging is done.
|
||||||
|
|
||||||
|
### auth_domain
|
||||||
|
Authorization realm used in `.htpasswd` authorization. Default: `mydomain.com`
|
||||||
|
|
||||||
|
### cgi_interpreter
|
||||||
|
Path to an executable to be used use as an interpreter for __all__ CGI scripts
|
||||||
|
regardless script extension. Default: not set, Mongoose looks at
|
||||||
|
[shebang line](http://en.wikipedia.org/wiki/Shebang_(Unix\).
|
||||||
|
|
||||||
|
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 directory where mongoose executable is located.
|
||||||
|
|
||||||
|
If all CGIs use the same interpreter, for example they are all PHP, then
|
||||||
|
`cgi_interpreter` option can be set to the path to `php-cgi.exe` executable and
|
||||||
|
shebang line in the CGI scripts can be omitted.
|
||||||
|
**Note**: PHP scripts must use `php-cgi.exe`, not `php.exe`.
|
||||||
|
|
||||||
|
### cgi_pattern
|
||||||
|
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 a pattern. Note that **full file path** is
|
||||||
|
matched against the pattern, not the URI.
|
||||||
|
|
||||||
|
When Mongoose starts CGI program, it creates new environment for it (in
|
||||||
|
contrast, usually child program inherits the environment from parent). Several
|
||||||
|
environment variables however are inherited from Mongoose's environment,
|
||||||
|
they are: `PATH`, `TMP`, `TEMP`, `TMPDIR`, `PERLLIB`, `MONGOOSE_CGI`. On UNIX
|
||||||
|
it is also `LD_LIBRARY_PATH`. On Windows it is also `COMSPEC`, `SYSTEMROOT`,
|
||||||
|
`SystemDrive`, `ProgramFiles`, `ProgramFiles(x86)`, `CommonProgramFiles(x86)`.
|
||||||
|
|
||||||
|
Default: `**.cgi$|**.pl$|**.php$`
|
||||||
|
|
||||||
|
### dav\_auth\_file
|
||||||
|
Authentication file for WebDAV mutation requests: `PUT`, `DELETE`, `MKCOL`.
|
||||||
|
The format of that file is the same as for the `.htpasswd` file
|
||||||
|
used for digest authentication. It can be created and managed by
|
||||||
|
`mongoose -A` command. Default: not set, WebDAV mutations are disallowed.
|
||||||
|
|
||||||
|
### document_root
|
||||||
|
A directory to serve. Default: current working directory.
|
||||||
|
|
||||||
|
### enable\_directory\_listing
|
||||||
|
Enable directory listing, either `yes` or `no`. Default: `yes`.
|
||||||
|
|
||||||
|
### enable\_proxy
|
||||||
|
Enable proxy functionality, either `yes` or `no`. If set to `yes`, then
|
||||||
|
browsers can be configured to use Mongoose as a proxy. Default: `no`.
|
||||||
|
|
||||||
|
|
||||||
|
### extra\_mime\_types
|
||||||
|
Extra mime types to recognize, in form `extension1=type1,extension2=type2,...`.
|
||||||
|
Extension must include dot. Example:
|
||||||
|
`mongoose -extra_mime_types .cpp=plain/text,.java=plain/text`. Default: not set.
|
||||||
|
|
||||||
|
|
||||||
|
### global\_auth\_file
|
||||||
|
Path to a global passwords file, either full path or relative to the mongoose
|
||||||
|
executable. If set, per-directory `.htpasswd` files are ignored,
|
||||||
|
and all requests are authorised against that file. Use `mongoose -A` to
|
||||||
|
manage passwords, or third party utilities like
|
||||||
|
[htpasswd-generator](http://www.askapache.com/online-tools/htpasswd-generator).
|
||||||
|
Default: not set, per-directory `.htpasswd` files are respected.
|
||||||
|
|
||||||
|
### 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, e.g.
|
||||||
|
`mongoose -hide_files_patterns secret.txt|even_more_secret.txt`. Default:
|
||||||
|
not set.
|
||||||
|
|
||||||
|
### index_files
|
||||||
|
Comma-separated list of files to be treated as directory index
|
||||||
|
files. Default: `index.html,index.htm,index.cgi,index.shtml,index.php`
|
||||||
|
|
||||||
|
### listening_port
|
||||||
|
Port to listen on. Port could be prepended by the specific IP address to bind
|
||||||
|
to, e.g. `mongoose -listening_port 127.0.0.1:8080`. Otherwise Mongoose
|
||||||
|
will bind to all addresses. To enable SSL, build Mongoose with
|
||||||
|
`-DNS_ENABLE_SSL` compilation option, and specify `listening_port` as
|
||||||
|
`ssl://PORT:SSL_CERTIFICATE.PEM`. Example SSL listener:
|
||||||
|
`mongoose -listening_port ssl://8043:ssl_cert.pem`. Note that PEM file should
|
||||||
|
be in PEM format, and must have both certificate and private key in it,
|
||||||
|
concatenated together. More than one listening port can be specified,
|
||||||
|
separated by comma,
|
||||||
|
for example `mongoose -listening_port 8080,8000`. Default: 8080.
|
||||||
|
|
||||||
|
### run\_as\_user
|
||||||
|
Switch to given user credentials after startup. UNIX-only. This option is
|
||||||
|
required when mongoose needs to bind on privileged port on UNIX, e.g.
|
||||||
|
|
||||||
|
$ sudo mongoose -listening_port 80 -run_as_user nobody
|
||||||
|
|
||||||
|
Default: not set.
|
||||||
|
|
||||||
|
### url\_rewrites
|
||||||
|
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. Instead,
|
||||||
|
`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. If `uri_pattern`
|
||||||
|
is a number, then it is treated as HTTP error code, and `file_or_directory_path`
|
||||||
|
should be an URI to redirect to. Mongoose will issue `302` temporary redirect
|
||||||
|
to the specified URI with following parameters:
|
||||||
|
`?code=HTTP_ERROR_CODE&orig_uri=ORIGINAL_URI&query_string=QUERY_STRING`.
|
||||||
|
|
||||||
|
If `uri_pattern` starts with `@` symbol, then Mongoose compares
|
||||||
|
it with the `HOST` header of the request. If they are equal, Mongoose sets
|
||||||
|
document root to `file_or_directory_path`, implementing virtual hosts support.
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
|
||||||
|
# Redirect all accesses to `.doc` files to a special script
|
||||||
|
mongoose -url_rewrites **.doc$=/path/to/cgi-bin/handle_doc.cgi
|
||||||
|
|
||||||
|
# Implement user home directories support
|
||||||
|
mongoose -url_rewrites /~joe/=/home/joe/,/~bill=/home/bill/
|
||||||
|
|
||||||
|
# Redirect 404 errors to a specific error page
|
||||||
|
mongoose -url_rewrites 404=/cgi-bin/error.cgi
|
||||||
|
|
||||||
|
# Virtual hosts example: serve foo.com domain from different directory
|
||||||
|
mongoose -url_rewrites @foo.com=/var/www/foo.com
|
||||||
|
|
||||||
|
Default: not set.
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
How To Create A PHP Website With Mongoose
|
||||||
|
===========================================
|
||||||
|
|
||||||
|
## 1. Create a directory which will contain your website files. For example, on drive `C:\`, create a directory called `my_website`:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## 2. Inside `my_website` directory, create a new file called "index". This will be the default web page shown when the website is visited.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## 3. Open index file with your favorite editor (for example, Notepad) and enter some HTML / PHP code:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## 4. Save this file as `index.php`:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
|
||||||
|
## 5. Download Mongoose executable from http://cesanta.com/mongoose.shtml and copy the executable inside `my_website` directory:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## 6. Double-click mongoose executable. An icon will appear on a system tray in the bottom right corner of the desktop:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## 7. Download PHP 5.3 zip (do NOT download PHP 5.5 cause you might have missing DLLs problem) from http://windows.php.net/download and extract it to `C:\php5` directory:
|
||||||
|

|
||||||
|
|
||||||
|
## 8. Click on the mongoose icon and choose "Edit Settings" menu.:
|
||||||
|

|
||||||
|
|
||||||
|
## 9. A settings dialog will appear. Click on `cgi_interpreter` button:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## 10. Choose `C:\php5\php-cgi.exe` and click "Save Settings":
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## 11. Click on the mongoose icon and choose "Go to my address" menu:
|
||||||
|

|
||||||
|
|
||||||
|
|
||||||
|
## 12. A browser will popup displaying `index.php`.
|
||||||
|
|
||||||
|

|
||||||
@@ -0,0 +1,193 @@
|
|||||||
|
# Mongoose Release Notes
|
||||||
|
|
||||||
|
## Release 5.5, October 28 2014
|
||||||
|
|
||||||
|
Changes in Libmongoose library:
|
||||||
|
|
||||||
|
- Added new API function: `mg_forward()` for proxying functionality
|
||||||
|
- Added new API function: `mg_send_file_data()` for sending file data
|
||||||
|
- Added new utility API functions: `mg_mmap() and mg_munpap()`
|
||||||
|
- Changed the way SSL settings are handled: removed `ssl_certificate` and
|
||||||
|
`ssl_ca_certificate` options, and instead made `listening_port` accept
|
||||||
|
`ssl://PORT:SSL_CERT:CA_CERT` notation
|
||||||
|
- Added ability to listen on multiple ports, see `listening_port` documentation
|
||||||
|
- Added `enable_proxy` option
|
||||||
|
- Added [cookie_authentication](https://github.com/cesanta/mongoose/tree/master/examples/cookie_authentication) example
|
||||||
|
- Added [websocket\_ssl\_proxy](https://github.com/cesanta/mongoose/tree/master/examples/websocket_ssl_proxy) example
|
||||||
|
- Added [http_client](https://github.com/cesanta/mongoose/tree/master/examples/http_client) example
|
||||||
|
- Increased default 'idle connection' timeout from 30 to 300 seconds
|
||||||
|
- Fixed MinGW build
|
||||||
|
- Refactored all examples, put each in it's own directory with dedicated build
|
||||||
|
- Many smaller bugfixed, including SSL, CGI, API, proxy, etc
|
||||||
|
|
||||||
|
Changes in pre-compiled binaries:
|
||||||
|
|
||||||
|
- Support for multiple listening ports
|
||||||
|
- Fixed CGI handling for scripts that specify interpreter in the hashbang line
|
||||||
|
|
||||||
|
## Release 5.4, July 28 2014
|
||||||
|
|
||||||
|
Changes in Libmongoose library:
|
||||||
|
|
||||||
|
- Added `hexdump_file` option for low-level request/reply debugging
|
||||||
|
- Added `mg_template()` API function for generating HTML pages from
|
||||||
|
templates with expansions
|
||||||
|
- Fixed `struct mg_connection::local_ip` handling, `mg_set_option()`
|
||||||
|
behavior with NULL values
|
||||||
|
- Added `mg_send_file()` call to send arbitrary file to the client
|
||||||
|
- Added `mg_terminate_ssl()` for SSL termination functionality
|
||||||
|
- Added HTTP proxy support, `enable_proxy` config option
|
||||||
|
- Added `mg_next()` for iterating over existing active connections
|
||||||
|
- Added client-side SSL auth, `ssl_ca_certificate` option
|
||||||
|
- Added `mg_wakeup_server_ex()` for pushing messages to existing connections
|
||||||
|
- Added `MG_WS_HANDSHAKE` and `MG_WS_CONNECT` events that are sent on
|
||||||
|
Websocket handshake is connection establishment, respectively
|
||||||
|
- Removed server-side Lua support
|
||||||
|
- Filesystem access, reading from socket/SSL performance improvements
|
||||||
|
- DAV PROPFIND memory leak fixed
|
||||||
|
- Added `big_upload.c` and enhanced `upload.c` example
|
||||||
|
- Added `proxy.c` example that demonstrates proxy functionality and SSE pushes
|
||||||
|
- Added `websocket2.c` example that shows simple web chat implementation
|
||||||
|
over websockets
|
||||||
|
- Various minor fixes
|
||||||
|
|
||||||
|
|
||||||
|
Changes in pre-compiled binaries:
|
||||||
|
|
||||||
|
- Created HTML administration console
|
||||||
|
- When server is started, browser is started automatically
|
||||||
|
- Fixed directory listing bug when directory contains `#` character
|
||||||
|
- Removed built-in Lua Server Pages in the binary, and instead
|
||||||
|
added Mongoose + Lua developer bundle which has Lua Server Pages support.
|
||||||
|
That also solves external Lua modules loading problem.
|
||||||
|
|
||||||
|
|
||||||
|
## Release 5.3, March 10 2014
|
||||||
|
|
||||||
|
Changes in Libmongoose library:
|
||||||
|
|
||||||
|
* Moved to the evented API. Updated API documentation is at
|
||||||
|
http://cesanta.com/docs/Embed.shtml
|
||||||
|
http://cesanta.com/docs/API.shtml
|
||||||
|
* Added `MG_LUA` event for exporting custom variables to the Lua environment
|
||||||
|
* Added virtual hosts capability, see `url_rewrites` option description at
|
||||||
|
http://cesanta.com/docs/Options.shtml
|
||||||
|
* Added mjpg serving example
|
||||||
|
* Cleaned up and documented HTTP client API, with unit tests
|
||||||
|
* Added `mg_wakeup_server()` to awaken `mg_poll_server()`
|
||||||
|
from another thread
|
||||||
|
* Moved Mongoose IO core to [https://github.com/cesanta/net_skeleton](Net Skeleton)
|
||||||
|
* Added connection hexdump functionality for developers
|
||||||
|
* Bug fixes
|
||||||
|
|
||||||
|
Changes in pre-compiled binaries:
|
||||||
|
|
||||||
|
* New awesome Mongoose logos buy our designer Katrin - thanks Katrin!
|
||||||
|
Check them out at http://cesanta.com/products.shtml
|
||||||
|
* Added Lua Server Pages support to the free version, quick intro is at
|
||||||
|
http://cesanta.com/docs/Lua.shtml
|
||||||
|
* Added quick "Set shared directory" menu item to set `document_root`
|
||||||
|
* Added SSI support to the Pro version
|
||||||
|
* Removed SSL support from the Pro version
|
||||||
|
|
||||||
|
## Release 5.2, Feb 1 2014
|
||||||
|
|
||||||
|
* Windows binary made fully UNICODE aware. In previous versions,
|
||||||
|
the presence of non-ASCII chars in document root, CGI script name,
|
||||||
|
or directory name might have broken Mongoose as stand-alone
|
||||||
|
or as Windows service. Now Mongoose works with non-ASCII paths properly.
|
||||||
|
Internally, Mongoose uses UTF8 encoding. When making WinAPI calls,
|
||||||
|
mongoose converts UTF8 strings to wide chars and calls UNICODE API.
|
||||||
|
* Enhanced authorization API by providing `mg_set_auth_handler()` and
|
||||||
|
`mg_authorize_digest()`
|
||||||
|
* Removed `mg_add_uri_handler()`, added `mg_set_request_handler()`.
|
||||||
|
There is only oneURI handler that handles all requests, just like in 4.x.
|
||||||
|
The reason for this change is to provide an ability to catch all URIs,
|
||||||
|
and at the same time signal Mongoose to continue handling specific URIs.
|
||||||
|
* Added `mg_parse_multipart()` API for file uploads.
|
||||||
|
Note that the restriction on uploading huge files still exists,
|
||||||
|
and will be eliminated in the next release.
|
||||||
|
* Allowing mongoose to bind to port 0, in which case it'll bind to any
|
||||||
|
random unused port.
|
||||||
|
* Moved `idle_timeout_ms` run-time option to compile-time flag
|
||||||
|
* Added asynchronous HTTP client, not documented yet. Documentation and
|
||||||
|
examples are coming in the next couple of weeks. Async Websocket client
|
||||||
|
is scheduled for the next release. See usage examples at `unit_test.c`
|
||||||
|
* Windows and MacOS pre-built binaries are now split to free and paid ones,
|
||||||
|
paid binaries include CGI, SSL, Lua, Sqlite, support and updates.
|
||||||
|
Linux pre-built binary includes all functionality and is free, and will
|
||||||
|
continue to be free. Source code for Windows and MacOS GUI is closed.
|
||||||
|
Disclaimer: source code for the command line stand-alone server,
|
||||||
|
as well as Mongoose library itself, will never be closed.
|
||||||
|
* Multiple bug fixes and minor enhancements
|
||||||
|
|
||||||
|
## Release 5.1, Jan 10 2014
|
||||||
|
|
||||||
|
* CGI-related bugs where fixed, primarily for Windows platform
|
||||||
|
* Bugs on Windows related to UNICODE support were fixed
|
||||||
|
* Added a feature to support "error pages" through redirect.
|
||||||
|
Done using `-url_redirects` option, details are on
|
||||||
|
http://cesanta.com/docs/Options.shtml
|
||||||
|
|
||||||
|
## Release 5.0, Jan 6 2014
|
||||||
|
|
||||||
|
* Internal core has been changed from blocking, thread-per-connection to
|
||||||
|
non-blocking, asynchronous, one thread for all.
|
||||||
|
* API modification for server creation and response creation. That allowed
|
||||||
|
keep-alive support for dynamic requests, boosting the embedded performance
|
||||||
|
to 100+ thousands requests per second on a single core
|
||||||
|
(as measured on my development MacBook laptop)
|
||||||
|
* Unified handling of POST requests and Websocket requests by putting a
|
||||||
|
payload into `conn->content`, `conn->content_len` attributes.
|
||||||
|
That simplified user code and eliminated the need of `mg_read()`,
|
||||||
|
since mongoose buffers all data prior to calling the callback
|
||||||
|
* keep-alive support is the default
|
||||||
|
* Dropped SSI support and throttling support
|
||||||
|
* Several configuraition parameters are gone:
|
||||||
|
* `cgi_environment` (replaced with MONGOOSE_CGI),
|
||||||
|
* `protect_uri` (not useful)
|
||||||
|
* `ssi_pattern` (SSI support is gone)
|
||||||
|
* `throttle` (throttling support is gone)
|
||||||
|
* `error_log_file` (not used)
|
||||||
|
* `enable_keep_alive` (enabled by default)
|
||||||
|
* `listening_ports` (renamed to listening_port)
|
||||||
|
* `num_threads` (core has changed to single thread)
|
||||||
|
* `put_delete_auth_file` (renamed to dav_auth_file)
|
||||||
|
* `authentication_domain` (renamed to auth_domain)
|
||||||
|
* Due to the async, non-blocking nature of the core, few restrictions
|
||||||
|
are now in place:
|
||||||
|
* user callbacks must not block
|
||||||
|
* POST and Websocket data are now buffered, and cannot be huge
|
||||||
|
* mongoose is now capable on listening on only one port
|
||||||
|
|
||||||
|
## Release 4.1, Oct 2013
|
||||||
|
## Release 4.0, Oct 2013
|
||||||
|
## Release 3.8, Sep 2013
|
||||||
|
|
||||||
|
## Release 3.7, Feb 2 2013
|
||||||
|
|
||||||
|
* Added "redirect to SSL port" functionality, e.g. if you specify
|
||||||
|
`-listening_ports 8080r,8043s`
|
||||||
|
then all requests to HTTP port 8080 will be redirected to HTTPS port 8043
|
||||||
|
* Added `mg_download()` API, an HTTP client interface!
|
||||||
|
* Lua server pages now must output HTTP headers -- full control for Lua
|
||||||
|
* Added pre-built binary for MacOS, with initial GUI support
|
||||||
|
* API change: got rid of events, moved to struct `mg_callbacks`
|
||||||
|
* Bugfixes, thanks to contributors
|
||||||
|
|
||||||
|
|
||||||
|
## Release 3.7, Jan 18 2013
|
||||||
|
* Fixed source code archive (main.c was missing)
|
||||||
|
* Extended Windows GUI functionality:
|
||||||
|
* Added "Start browser" systray popup menu item
|
||||||
|
* Enhanced configuration editor
|
||||||
|
* Renamed config options:
|
||||||
|
* `put_delete_passwords_file` -> `put_delete_auth_file`
|
||||||
|
* `global_passwords_file` -> `global_auth_file`
|
||||||
|
* `select()` changed to `poll()`, to avoid big file descriptor
|
||||||
|
`FD_SET` problem on UNIX
|
||||||
|
* Couple of bugfixes, thanks to contributors
|
||||||
|
|
||||||
|
|
||||||
|
Eearlier release notes could be found by searching
|
||||||
|
[Mongoose mailing list](https://groups.google.com/forum/#!forum/mongoose-users)
|
||||||
+75
@@ -0,0 +1,75 @@
|
|||||||
|
# Mongoose SSL guide
|
||||||
|
|
||||||
|
SSL is a protocol that makes web communication secure. To enable SSL
|
||||||
|
in mongoose, 3 steps are required:
|
||||||
|
|
||||||
|
1. Valid certificate file must be created
|
||||||
|
2. `ssl_certificate` options must be set to contain path to the
|
||||||
|
certificate file.
|
||||||
|
3. `listening_ports` option must contain a port number with letter `s`
|
||||||
|
appended to it, which instructs Mongoose to use SSL for all connections
|
||||||
|
made to that port.
|
||||||
|
|
||||||
|
Below is the `mongoose.conf` file snippet for typical SSL setup:
|
||||||
|
|
||||||
|
document_root www_root # Serve files in www_root directory
|
||||||
|
listening_ports 80r,443s # Redirect all HTTP requests to HTTPS
|
||||||
|
ssl_certificate ssl_cert.pem # Location of certificate file
|
||||||
|
|
||||||
|
## How to create SSL certificate file
|
||||||
|
|
||||||
|
SSL certificate file is a text file that must contain at least two
|
||||||
|
sections:
|
||||||
|
|
||||||
|
1. A private key
|
||||||
|
2. A certificate
|
||||||
|
|
||||||
|
Both sections should be chunks of text in PEM format. When PEM file is
|
||||||
|
opened in a text editor, it looks like this:
|
||||||
|
|
||||||
|
-----BEGIN RSA PRIVATE KEY-----
|
||||||
|
MIIEogIBAAKCAQEAwONaLOP7EdegqjRuQKSDXzvHmFMZfBufjhELhNjo5KsL4ieH
|
||||||
|
hYN0Zii2yTb63jGxKY6gH1R/r9dL8kXaJmcZrfSa3AgywnteJWg=
|
||||||
|
-----END RSA PRIVATE KEY-----
|
||||||
|
-----BEGIN CERTIFICATE-----
|
||||||
|
MIIDBjCCAe4CCQCX05m0b053QzANBgkqhkiG9w0BAQQFADBFMQswCQYDVQQGEwJB
|
||||||
|
SEGI4JSxV56lYg==
|
||||||
|
-----END CERTIFICATE-----
|
||||||
|
|
||||||
|
Two aforementioned sections are clearly seen. Typically, those section
|
||||||
|
are bigger then in the example shown. The text between the `BEGIN` and
|
||||||
|
`END` is the text representation of binary data, a private key and a
|
||||||
|
certificate. Therefore, in order to create a certificate file,
|
||||||
|
|
||||||
|
* private key must be converted to PEM format
|
||||||
|
* certificate must be converted to PEM format
|
||||||
|
* those two should be concatenated into a single file
|
||||||
|
|
||||||
|
If the certificate chain in used, a chain file also needs to be
|
||||||
|
converted into PEM format and appended to the certificate file.
|
||||||
|
|
||||||
|
## How SSL works
|
||||||
|
|
||||||
|
SSL is a protocol that can encrypt communication between two parties. If third
|
||||||
|
party observes all messages passed by, it would be very
|
||||||
|
hard for the third party (though not impossible) to decrypt the communication.
|
||||||
|
|
||||||
|
The idea is based on so-called public key encryption. Communicating parties
|
||||||
|
have two keys: a public key and a private key. A public key is advertised
|
||||||
|
to everybody, and it is contained in a certificate. A private key is kept
|
||||||
|
secret. Security algorithm works in a way that anybody can encrypt
|
||||||
|
a message using public key, and only private key can decrypt it.
|
||||||
|
|
||||||
|
This is why web server needs both private key and certificate: private key
|
||||||
|
is used to decrypt incoming messages, and certificate is used to tell the
|
||||||
|
public key to the other party. When communication starts, parties exchange
|
||||||
|
their public keys, and keep private keys to themselves. Man-in-the-middle
|
||||||
|
who observes the communication is unable to decrypt the messages cause
|
||||||
|
private keys are required for decryption.
|
||||||
|
|
||||||
|
Encryption algorithms are built on top of hard mathematical problem, which
|
||||||
|
makes it very expensive for man-in-the-middle to compute private keys.
|
||||||
|
For example, RSA algorithm is based on a mathematical problem of factorization.
|
||||||
|
It is easy to generate two very large prime numbers `P` and `Q` and make
|
||||||
|
a product `P * Q`. But given a product, it is very hard to recover these
|
||||||
|
two prime numbers - this is called factorization.
|
||||||
@@ -0,0 +1,86 @@
|
|||||||
|
# Mongoose User Guide
|
||||||
|
|
||||||
|
Mongoose is small and easy to use web server built on top of
|
||||||
|
mongoose library. It is designed with maximum simplicity in mind. For example,
|
||||||
|
to share any directory, just drop mongoose executable in that directory,
|
||||||
|
double-click it (on UNIX, run it from shell) 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 Windows and Mac, Mongoose iconifies itself to the system tray when started.
|
||||||
|
Right-click on the icon to pop up a menu, where it is possible to stop
|
||||||
|
mongoose, or configure it.
|
||||||
|
|
||||||
|
On UNIX, `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 -document_root /var/www # Running mongoose with cmdline options
|
||||||
|
$ mongoose /etc/my_config.txt # Running mongoose with config file
|
||||||
|
$ mongoose # Running with no parameters. This will
|
||||||
|
# serve current directory on port 8080
|
||||||
|
|
||||||
|
Mongoose does not detach from terminal. Pressing `Ctrl-C` keys
|
||||||
|
stops the server.
|
||||||
|
|
||||||
|
When started, mongoose first searches for the configuration file.
|
||||||
|
If configuration file is specified explicitly in the command line, 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:
|
||||||
|
|
||||||
|
# This is a comment
|
||||||
|
document_root C:\www
|
||||||
|
listening_port 80
|
||||||
|
ssl_certificate C:\mongoose\ssl_cert.pem
|
||||||
|
|
||||||
|
Command line arguments are highest priority and can override
|
||||||
|
configuration file settings. 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 used as
|
||||||
|
document root.
|
||||||
|
|
||||||
|
Note that configuration options on the command line must start with `-`,
|
||||||
|
and their names are the same as in the config file. Exampli gratia,
|
||||||
|
the following two setups are equivalent:
|
||||||
|
|
||||||
|
$ mongoose -listening_port 1234 -document_root /var/www
|
||||||
|
|
||||||
|
$ cat > mongoose.conf
|
||||||
|
listening_ports 1234
|
||||||
|
document_root /var/www
|
||||||
|
^D
|
||||||
|
$ mongoose
|
||||||
|
|
||||||
|
Mongoose can also be used to modify `.htpasswd` passwords file:
|
||||||
|
|
||||||
|
$ mongoose -A .htpasswd mydomain.com user_name user_password
|
||||||
|
|
||||||
|
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:
|
||||||
|
|
||||||
|
# Pattern Meaning
|
||||||
|
**.cgi$ Any string that ends with .cgi
|
||||||
|
/foo Any string that begins with /foo
|
||||||
|
**a$|**b$ Any string that ends with a or b
|
||||||
|
|
||||||
|
To restrict CGI files only to `/cgi-bin/` directory, use this setting:
|
||||||
|
|
||||||
|
$ mongoose -cgi_pattern /cgi-bin/*.cgi # Emulate /cgi-bin/ restriction
|
||||||
+9
-22
@@ -1,28 +1,15 @@
|
|||||||
CFLAGS= -W -Wall -I.. -pthread -g
|
# Copyright (c) 2014 Cesanta Software
|
||||||
|
# All rights reserved
|
||||||
|
|
||||||
all:
|
SUBDIRS = $(sort $(filter-out csharp/, $(dir $(wildcard */))))
|
||||||
OS=`uname`; \
|
X = $(SUBDIRS)
|
||||||
test "$$OS" = Linux && LIBS="-ldl" ; \
|
|
||||||
$(CC) $(CFLAGS) hello.c ../mongoose.c $$LIBS $(ADD) -o hello;
|
|
||||||
$(CC) $(CFLAGS) upload.c ../mongoose.c $$LIBS $(ADD) -o upload;
|
|
||||||
$(CC) $(CFLAGS) post.c ../mongoose.c $$LIBS $(ADD) -o post;
|
|
||||||
$(CC) $(CFLAGS) -DUSE_WEBSOCKET websocket.c ../mongoose.c $$LIBS $(ADD) -o websocket;
|
|
||||||
$(CC) $(CFLAGS) chat.c ../mongoose.c $$LIBS $(ADD) -o chat
|
|
||||||
|
|
||||||
|
.PHONY: $(SUBDIRS)
|
||||||
|
|
||||||
MSVC = e:/vc6
|
all: $(SUBDIRS)
|
||||||
CL = $(MSVC)/bin/cl
|
|
||||||
CLFLAGS = /MD /TC /nologo $(DBG) /W3 /DNO_SSL \
|
|
||||||
/I$(MSVC)/include /I.. /Dsnprintf=_snprintf \
|
|
||||||
/link /incremental:no /libpath:$(MSVC)/lib /machine:IX86
|
|
||||||
|
|
||||||
windows:
|
$(SUBDIRS):
|
||||||
$(CL) upload.c ../mongoose.c $(CLFLAGS)
|
@$(MAKE) -C $@
|
||||||
$(CL) hello.c ../mongoose.c $(CLFLAGS)
|
|
||||||
$(CL) upload.c ../mongoose.c $(CLFLAGS)
|
|
||||||
$(CL) post.c ../mongoose.c $(CLFLAGS)
|
|
||||||
$(CL) post.c ../mongoose.c $(CLFLAGS)
|
|
||||||
$(CL) /DUSE_WEBSOCKET websocket.c ../mongoose.c $(CLFLAGS)
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rf hello hello.exe upload upload.exe post post.exe websocket websocket.exe chat chat.exe *.dSYM *.obj
|
for d in $(SUBDIRS) ; do $(MAKE) -C $$d clean ; done
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
# Copyright (c) 2014 Cesanta Software
|
||||||
|
# All rights reserved
|
||||||
|
|
||||||
|
PROG = big_upload
|
||||||
|
CFLAGS = -W -Wall -pthread -I../.. -g -O0 $(CFLAGS_EXTRA)
|
||||||
|
SOURCES = $(PROG).c ../../mongoose.c
|
||||||
|
|
||||||
|
$(PROG): $(SOURCES)
|
||||||
|
$(CC) -o $(PROG) $(SOURCES) $(CFLAGS)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -rf $(PROG) *.exe *.dSYM *.obj *.exp .*o *.lib
|
||||||
@@ -0,0 +1,84 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include "mongoose.h"
|
||||||
|
|
||||||
|
static int handle_request(struct mg_connection *conn) {
|
||||||
|
if (strcmp(conn->uri, "/upload") == 0) {
|
||||||
|
FILE *fp = (FILE *) conn->connection_param;
|
||||||
|
if (fp != NULL) {
|
||||||
|
fwrite(conn->content, 1, conn->content_len, fp); // Write last bits
|
||||||
|
mg_printf(conn, "HTTP/1.1 200 OK\r\n"
|
||||||
|
"Content-Type: text/plain\r\n"
|
||||||
|
"Connection: close\r\n\r\n"
|
||||||
|
"Written %ld of POST data to a temp file:\n\n",
|
||||||
|
(long) ftell(fp));
|
||||||
|
|
||||||
|
// Temp file will be destroyed after fclose(), do something with the
|
||||||
|
// data here -- for example, parse it and extract uploaded files.
|
||||||
|
// As an example, we just echo the whole POST buffer back to the client.
|
||||||
|
rewind(fp);
|
||||||
|
mg_send_file_data(conn, fileno(fp));
|
||||||
|
return MG_MORE; // Tell Mongoose reply is not completed yet
|
||||||
|
} else {
|
||||||
|
mg_printf_data(conn, "%s", "Had no data to write...");
|
||||||
|
return MG_TRUE; // Tell Mongoose we're done with this request
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
mg_printf_data(conn, "%s",
|
||||||
|
"<html><body>Upload example."
|
||||||
|
"<form method=\"POST\" action=\"/upload\" "
|
||||||
|
" enctype=\"multipart/form-data\">"
|
||||||
|
"<input type=\"file\" name=\"file\" /> <br/>"
|
||||||
|
"<input type=\"submit\" value=\"Upload\" />"
|
||||||
|
"</form></body></html>");
|
||||||
|
return MG_TRUE; // Tell mongoose to close this connection
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mongoose sends MG_RECV for every received POST chunk.
|
||||||
|
// When last POST chunk is received, Mongoose sends MG_REQUEST, then MG_CLOSE.
|
||||||
|
static int handle_recv(struct mg_connection *conn) {
|
||||||
|
FILE *fp = (FILE *) conn->connection_param;
|
||||||
|
|
||||||
|
// Open temporary file where we going to write data
|
||||||
|
if (fp == NULL && ((conn->connection_param = fp = tmpfile())) == NULL) {
|
||||||
|
return -1; // Close connection on error
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return number of bytes written to a temporary file: that is how many
|
||||||
|
// bytes we want to discard from the receive buffer
|
||||||
|
return fwrite(conn->content, 1, conn->content_len, fp);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make sure we free all allocated resources
|
||||||
|
static int handle_close(struct mg_connection *conn) {
|
||||||
|
if (conn->connection_param != NULL) {
|
||||||
|
fclose((FILE *) conn->connection_param);
|
||||||
|
conn->connection_param = NULL;
|
||||||
|
}
|
||||||
|
return MG_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int ev_handler(struct mg_connection *conn, enum mg_event ev) {
|
||||||
|
switch (ev) {
|
||||||
|
case MG_AUTH: return MG_TRUE;
|
||||||
|
case MG_REQUEST: return handle_request(conn);
|
||||||
|
case MG_RECV: return handle_recv(conn);
|
||||||
|
case MG_CLOSE: return handle_close(conn);
|
||||||
|
default: return MG_FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
struct mg_server *server = mg_create_server(NULL, ev_handler);
|
||||||
|
mg_set_option(server, "listening_port", "8080");
|
||||||
|
printf("Starting on port %s\n", mg_get_option(server, "listening_port"));
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
|
mg_poll_server(server, 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
mg_destroy_server(&server);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
-390
@@ -1,390 +0,0 @@
|
|||||||
// This file is part of the Mongoose project, http://code.google.com/p/mongoose
|
|
||||||
// It implements an online chat server. For more details,
|
|
||||||
// see the documentation on the project web site.
|
|
||||||
// To test the application,
|
|
||||||
// 1. type "make" in the directory where this file lives
|
|
||||||
// 2. point your browser to http://127.0.0.1:8081
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <assert.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <time.h>
|
|
||||||
#include <stdarg.h>
|
|
||||||
#include <pthread.h>
|
|
||||||
|
|
||||||
#include "mongoose.h"
|
|
||||||
|
|
||||||
#define MAX_USER_LEN 20
|
|
||||||
#define MAX_MESSAGE_LEN 100
|
|
||||||
#define MAX_MESSAGES 5
|
|
||||||
#define MAX_SESSIONS 2
|
|
||||||
#define SESSION_TTL 120
|
|
||||||
|
|
||||||
static const char *authorize_url = "/authorize";
|
|
||||||
static const char *login_url = "/login.html";
|
|
||||||
static const char *ajax_reply_start =
|
|
||||||
"HTTP/1.1 200 OK\r\n"
|
|
||||||
"Cache: no-cache\r\n"
|
|
||||||
"Content-Type: application/x-javascript\r\n"
|
|
||||||
"\r\n";
|
|
||||||
|
|
||||||
// Describes single message sent to a chat. If user is empty (0 length),
|
|
||||||
// the message is then originated from the server itself.
|
|
||||||
struct message {
|
|
||||||
long id; // Message ID
|
|
||||||
char user[MAX_USER_LEN]; // User that have sent the message
|
|
||||||
char text[MAX_MESSAGE_LEN]; // Message text
|
|
||||||
time_t timestamp; // Message timestamp, UTC
|
|
||||||
};
|
|
||||||
|
|
||||||
// Describes web session.
|
|
||||||
struct session {
|
|
||||||
char session_id[33]; // Session ID, must be unique
|
|
||||||
char random[20]; // Random data used for extra user validation
|
|
||||||
char user[MAX_USER_LEN]; // Authenticated user
|
|
||||||
time_t expire; // Expiration timestamp, UTC
|
|
||||||
};
|
|
||||||
|
|
||||||
static struct message messages[MAX_MESSAGES]; // Ringbuffer for messages
|
|
||||||
static struct session sessions[MAX_SESSIONS]; // Current sessions
|
|
||||||
static long last_message_id;
|
|
||||||
|
|
||||||
// Protects messages, sessions, last_message_id
|
|
||||||
static pthread_rwlock_t rwlock = PTHREAD_RWLOCK_INITIALIZER;
|
|
||||||
|
|
||||||
// Get session object for the connection. Caller must hold the lock.
|
|
||||||
static struct session *get_session(const struct mg_connection *conn) {
|
|
||||||
int i;
|
|
||||||
char session_id[33];
|
|
||||||
time_t now = time(NULL);
|
|
||||||
mg_get_cookie(conn, "session", session_id, sizeof(session_id));
|
|
||||||
for (i = 0; i < MAX_SESSIONS; i++) {
|
|
||||||
if (sessions[i].expire != 0 &&
|
|
||||||
sessions[i].expire > now &&
|
|
||||||
strcmp(sessions[i].session_id, session_id) == 0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return i == MAX_SESSIONS ? NULL : &sessions[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
static void get_qsvar(const struct mg_request_info *request_info,
|
|
||||||
const char *name, char *dst, size_t dst_len) {
|
|
||||||
const char *qs = request_info->query_string;
|
|
||||||
mg_get_var(qs, strlen(qs == NULL ? "" : qs), name, dst, dst_len);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get a get of messages with IDs greater than last_id and transform them
|
|
||||||
// into a JSON string. Return that string to the caller. The string is
|
|
||||||
// dynamically allocated, caller must free it. If there are no messages,
|
|
||||||
// NULL is returned.
|
|
||||||
static char *messages_to_json(long last_id) {
|
|
||||||
const struct message *message;
|
|
||||||
int max_msgs, len;
|
|
||||||
char buf[sizeof(messages)]; // Large enough to hold all messages
|
|
||||||
|
|
||||||
// Read-lock the ringbuffer. Loop over all messages, making a JSON string.
|
|
||||||
pthread_rwlock_rdlock(&rwlock);
|
|
||||||
len = 0;
|
|
||||||
max_msgs = sizeof(messages) / sizeof(messages[0]);
|
|
||||||
// If client is too far behind, return all messages.
|
|
||||||
if (last_message_id - last_id > max_msgs) {
|
|
||||||
last_id = last_message_id - max_msgs;
|
|
||||||
}
|
|
||||||
for (; last_id < last_message_id; last_id++) {
|
|
||||||
message = &messages[last_id % max_msgs];
|
|
||||||
if (message->timestamp == 0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
// buf is allocated on stack and hopefully is large enough to hold all
|
|
||||||
// messages (it may be too small if the ringbuffer is full and all
|
|
||||||
// messages are large. in this case asserts will trigger).
|
|
||||||
len += snprintf(buf + len, sizeof(buf) - len,
|
|
||||||
"{user: '%s', text: '%s', timestamp: %lu, id: %lu},",
|
|
||||||
message->user, message->text, message->timestamp, message->id);
|
|
||||||
assert(len > 0);
|
|
||||||
assert((size_t) len < sizeof(buf));
|
|
||||||
}
|
|
||||||
pthread_rwlock_unlock(&rwlock);
|
|
||||||
|
|
||||||
return len == 0 ? NULL : strdup(buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
// If "callback" param is present in query string, this is JSONP call.
|
|
||||||
// Return 1 in this case, or 0 if "callback" is not specified.
|
|
||||||
// Wrap an output in Javascript function call.
|
|
||||||
static int handle_jsonp(struct mg_connection *conn,
|
|
||||||
const struct mg_request_info *request_info) {
|
|
||||||
char cb[64];
|
|
||||||
|
|
||||||
get_qsvar(request_info, "callback", cb, sizeof(cb));
|
|
||||||
if (cb[0] != '\0') {
|
|
||||||
mg_printf(conn, "%s(", cb);
|
|
||||||
}
|
|
||||||
|
|
||||||
return cb[0] == '\0' ? 0 : 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// A handler for the /ajax/get_messages endpoint.
|
|
||||||
// Return a list of messages with ID greater than requested.
|
|
||||||
static void ajax_get_messages(struct mg_connection *conn,
|
|
||||||
const struct mg_request_info *request_info) {
|
|
||||||
char last_id[32], *json;
|
|
||||||
int is_jsonp;
|
|
||||||
|
|
||||||
mg_printf(conn, "%s", ajax_reply_start);
|
|
||||||
is_jsonp = handle_jsonp(conn, request_info);
|
|
||||||
|
|
||||||
get_qsvar(request_info, "last_id", last_id, sizeof(last_id));
|
|
||||||
if ((json = messages_to_json(strtoul(last_id, NULL, 10))) != NULL) {
|
|
||||||
mg_printf(conn, "[%s]", json);
|
|
||||||
free(json);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_jsonp) {
|
|
||||||
mg_printf(conn, "%s", ")");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Allocate new message. Caller must hold the lock.
|
|
||||||
static struct message *new_message(void) {
|
|
||||||
static int size = sizeof(messages) / sizeof(messages[0]);
|
|
||||||
struct message *message = &messages[last_message_id % size];
|
|
||||||
message->id = last_message_id++;
|
|
||||||
message->timestamp = time(0);
|
|
||||||
return message;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void my_strlcpy(char *dst, const char *src, size_t len) {
|
|
||||||
strncpy(dst, src, len);
|
|
||||||
dst[len - 1] = '\0';
|
|
||||||
}
|
|
||||||
|
|
||||||
// A handler for the /ajax/send_message endpoint.
|
|
||||||
static void ajax_send_message(struct mg_connection *conn,
|
|
||||||
const struct mg_request_info *request_info) {
|
|
||||||
struct message *message;
|
|
||||||
struct session *session;
|
|
||||||
char text[sizeof(message->text) - 1];
|
|
||||||
int is_jsonp;
|
|
||||||
|
|
||||||
mg_printf(conn, "%s", ajax_reply_start);
|
|
||||||
is_jsonp = handle_jsonp(conn, request_info);
|
|
||||||
|
|
||||||
get_qsvar(request_info, "text", text, sizeof(text));
|
|
||||||
if (text[0] != '\0') {
|
|
||||||
// We have a message to store. Write-lock the ringbuffer,
|
|
||||||
// grab the next message and copy data into it.
|
|
||||||
pthread_rwlock_wrlock(&rwlock);
|
|
||||||
message = new_message();
|
|
||||||
// TODO(lsm): JSON-encode all text strings
|
|
||||||
session = get_session(conn);
|
|
||||||
assert(session != NULL);
|
|
||||||
my_strlcpy(message->text, text, sizeof(text));
|
|
||||||
my_strlcpy(message->user, session->user, sizeof(message->user));
|
|
||||||
pthread_rwlock_unlock(&rwlock);
|
|
||||||
}
|
|
||||||
|
|
||||||
mg_printf(conn, "%s", text[0] == '\0' ? "false" : "true");
|
|
||||||
|
|
||||||
if (is_jsonp) {
|
|
||||||
mg_printf(conn, "%s", ")");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Redirect user to the login form. In the cookie, store the original URL
|
|
||||||
// we came from, so that after the authorization we could redirect back.
|
|
||||||
static void redirect_to_login(struct mg_connection *conn,
|
|
||||||
const struct mg_request_info *request_info) {
|
|
||||||
mg_printf(conn, "HTTP/1.1 302 Found\r\n"
|
|
||||||
"Set-Cookie: original_url=%s\r\n"
|
|
||||||
"Location: %s\r\n\r\n",
|
|
||||||
request_info->uri, login_url);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return 1 if username/password is allowed, 0 otherwise.
|
|
||||||
static int check_password(const char *user, const char *password) {
|
|
||||||
// In production environment we should ask an authentication system
|
|
||||||
// to authenticate the user.
|
|
||||||
// Here however we do trivial check that user and password are not empty
|
|
||||||
return (user[0] && password[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Allocate new session object
|
|
||||||
static struct session *new_session(void) {
|
|
||||||
int i;
|
|
||||||
time_t now = time(NULL);
|
|
||||||
pthread_rwlock_wrlock(&rwlock);
|
|
||||||
for (i = 0; i < MAX_SESSIONS; i++) {
|
|
||||||
if (sessions[i].expire == 0 || sessions[i].expire < now) {
|
|
||||||
sessions[i].expire = time(0) + SESSION_TTL;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pthread_rwlock_unlock(&rwlock);
|
|
||||||
return i == MAX_SESSIONS ? NULL : &sessions[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Generate session ID. buf must be 33 bytes in size.
|
|
||||||
// Note that it is easy to steal session cookies by sniffing traffic.
|
|
||||||
// This is why all communication must be SSL-ed.
|
|
||||||
static void generate_session_id(char *buf, const char *random,
|
|
||||||
const char *user) {
|
|
||||||
mg_md5(buf, random, user, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void send_server_message(const char *fmt, ...) {
|
|
||||||
va_list ap;
|
|
||||||
struct message *message;
|
|
||||||
|
|
||||||
pthread_rwlock_wrlock(&rwlock);
|
|
||||||
message = new_message();
|
|
||||||
message->user[0] = '\0'; // Empty user indicates server message
|
|
||||||
va_start(ap, fmt);
|
|
||||||
vsnprintf(message->text, sizeof(message->text), fmt, ap);
|
|
||||||
va_end(ap);
|
|
||||||
|
|
||||||
pthread_rwlock_unlock(&rwlock);
|
|
||||||
}
|
|
||||||
|
|
||||||
// A handler for the /authorize endpoint.
|
|
||||||
// Login page form sends user name and password to this endpoint.
|
|
||||||
static void authorize(struct mg_connection *conn,
|
|
||||||
const struct mg_request_info *request_info) {
|
|
||||||
char user[MAX_USER_LEN], password[MAX_USER_LEN];
|
|
||||||
struct session *session;
|
|
||||||
|
|
||||||
// Fetch user name and password.
|
|
||||||
get_qsvar(request_info, "user", user, sizeof(user));
|
|
||||||
get_qsvar(request_info, "password", password, sizeof(password));
|
|
||||||
|
|
||||||
if (check_password(user, password) && (session = new_session()) != NULL) {
|
|
||||||
// Authentication success:
|
|
||||||
// 1. create new session
|
|
||||||
// 2. set session ID token in the cookie
|
|
||||||
// 3. remove original_url from the cookie - not needed anymore
|
|
||||||
// 4. redirect client back to the original URL
|
|
||||||
//
|
|
||||||
// The most secure way is to stay HTTPS all the time. However, just to
|
|
||||||
// show the technique, we redirect to HTTP after the successful
|
|
||||||
// authentication. The danger of doing this is that session cookie can
|
|
||||||
// be stolen and an attacker may impersonate the user.
|
|
||||||
// Secure application must use HTTPS all the time.
|
|
||||||
my_strlcpy(session->user, user, sizeof(session->user));
|
|
||||||
snprintf(session->random, sizeof(session->random), "%d", rand());
|
|
||||||
generate_session_id(session->session_id, session->random, session->user);
|
|
||||||
send_server_message("<%s> joined", session->user);
|
|
||||||
mg_printf(conn, "HTTP/1.1 302 Found\r\n"
|
|
||||||
"Set-Cookie: session=%s; max-age=3600; http-only\r\n" // Session ID
|
|
||||||
"Set-Cookie: user=%s\r\n" // Set user, needed by Javascript code
|
|
||||||
"Set-Cookie: original_url=/; max-age=0\r\n" // Delete original_url
|
|
||||||
"Location: /\r\n\r\n",
|
|
||||||
session->session_id, session->user);
|
|
||||||
} else {
|
|
||||||
// Authentication failure, redirect to login.
|
|
||||||
redirect_to_login(conn, request_info);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return 1 if request is authorized, 0 otherwise.
|
|
||||||
static int is_authorized(const struct mg_connection *conn,
|
|
||||||
const struct mg_request_info *request_info) {
|
|
||||||
struct session *session;
|
|
||||||
char valid_id[33];
|
|
||||||
int authorized = 0;
|
|
||||||
|
|
||||||
// Always authorize accesses to login page and to authorize URI
|
|
||||||
if (!strcmp(request_info->uri, login_url) ||
|
|
||||||
!strcmp(request_info->uri, authorize_url)) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
pthread_rwlock_rdlock(&rwlock);
|
|
||||||
if ((session = get_session(conn)) != NULL) {
|
|
||||||
generate_session_id(valid_id, session->random, session->user);
|
|
||||||
if (strcmp(valid_id, session->session_id) == 0) {
|
|
||||||
session->expire = time(0) + SESSION_TTL;
|
|
||||||
authorized = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pthread_rwlock_unlock(&rwlock);
|
|
||||||
|
|
||||||
return authorized;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void redirect_to_ssl(struct mg_connection *conn,
|
|
||||||
const struct mg_request_info *request_info) {
|
|
||||||
const char *p, *host = mg_get_header(conn, "Host");
|
|
||||||
if (host != NULL && (p = strchr(host, ':')) != NULL) {
|
|
||||||
mg_printf(conn, "HTTP/1.1 302 Found\r\n"
|
|
||||||
"Location: https://%.*s:8082/%s:8082\r\n\r\n",
|
|
||||||
(int) (p - host), host, request_info->uri);
|
|
||||||
} else {
|
|
||||||
mg_printf(conn, "%s", "HTTP/1.1 500 Error\r\n\r\nHost: header is not set");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void *event_handler(enum mg_event event,
|
|
||||||
struct mg_connection *conn) {
|
|
||||||
const struct mg_request_info *request_info = mg_get_request_info(conn);
|
|
||||||
void *processed = "yes";
|
|
||||||
|
|
||||||
if (event == MG_NEW_REQUEST) {
|
|
||||||
if (!request_info->is_ssl) {
|
|
||||||
redirect_to_ssl(conn, request_info);
|
|
||||||
} else if (!is_authorized(conn, request_info)) {
|
|
||||||
redirect_to_login(conn, request_info);
|
|
||||||
} else if (strcmp(request_info->uri, authorize_url) == 0) {
|
|
||||||
authorize(conn, request_info);
|
|
||||||
} else if (strcmp(request_info->uri, "/ajax/get_messages") == 0) {
|
|
||||||
ajax_get_messages(conn, request_info);
|
|
||||||
} else if (strcmp(request_info->uri, "/ajax/send_message") == 0) {
|
|
||||||
ajax_send_message(conn, request_info);
|
|
||||||
} else {
|
|
||||||
// No suitable handler found, mark as not processed. Mongoose will
|
|
||||||
// try to serve the request.
|
|
||||||
processed = NULL;
|
|
||||||
}
|
|
||||||
} else if (event == MG_EVENT_LOG) {
|
|
||||||
printf("%s\n", (const char *) mg_get_request_info(conn)->ev_data);
|
|
||||||
processed = NULL;
|
|
||||||
} else {
|
|
||||||
processed = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return processed;
|
|
||||||
}
|
|
||||||
|
|
||||||
static const char *options[] = {
|
|
||||||
"document_root", "html",
|
|
||||||
"listening_ports", "8081,8082s",
|
|
||||||
"ssl_certificate", "ssl_cert.pem",
|
|
||||||
"num_threads", "5",
|
|
||||||
NULL
|
|
||||||
};
|
|
||||||
|
|
||||||
int main(void) {
|
|
||||||
struct mg_context *ctx;
|
|
||||||
|
|
||||||
// Initialize random number generator. It will be used later on for
|
|
||||||
// the session identifier creation.
|
|
||||||
srand((unsigned) time(0));
|
|
||||||
|
|
||||||
// Setup and start Mongoose
|
|
||||||
if ((ctx = mg_start(&event_handler, NULL, options)) == NULL) {
|
|
||||||
printf("%s\n", "Cannot start chat server, fatal exit");
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Wait until enter is pressed, then exit
|
|
||||||
printf("Chat server started on ports %s, press enter to quit.\n",
|
|
||||||
mg_get_option(ctx, "listening_ports"));
|
|
||||||
getchar();
|
|
||||||
mg_stop(ctx);
|
|
||||||
printf("%s\n", "Chat server stopped.");
|
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
// vim:ts=2:sw=2:et
|
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
# Copyright (c) 2014 Cesanta Software
|
||||||
|
# All rights reserved
|
||||||
|
|
||||||
|
PROG = cookie_auth
|
||||||
|
CFLAGS = -W -Wall -I../.. -pthread -g -O0 $(CFLAGS_EXTRA)
|
||||||
|
SOURCES = $(PROG).c ../../mongoose.c
|
||||||
|
|
||||||
|
$(PROG): $(SOURCES)
|
||||||
|
$(CC) -o $(PROG) $(SOURCES) $(CFLAGS)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -rf $(PROG) *.exe *.dSYM *.obj *.exp .*o *.lib
|
||||||
@@ -0,0 +1,96 @@
|
|||||||
|
// Copyright (c) 2014 Cesanta Software
|
||||||
|
// All rights reserved
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include "mongoose.h"
|
||||||
|
|
||||||
|
static const char *s_login_uri = "/login.html";
|
||||||
|
static const char *s_secret = ":-)"; // Must be known only to server
|
||||||
|
|
||||||
|
static void generate_ssid(const char *user_name, const char *expiration_date,
|
||||||
|
char *ssid, size_t ssid_size) {
|
||||||
|
char hash[33];
|
||||||
|
mg_md5(hash, user_name, ":", expiration_date, ":", s_secret, NULL);
|
||||||
|
snprintf(ssid, ssid_size, "%s|%s|%s", user_name, expiration_date, hash);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int check_auth(struct mg_connection *conn) {
|
||||||
|
char ssid[100], calculated_ssid[100], name[100], expire[100];
|
||||||
|
|
||||||
|
// Always authenticate requests to login page
|
||||||
|
if (strcmp(conn->uri, s_login_uri) == 0) {
|
||||||
|
return MG_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Look for session ID in the Cookie.
|
||||||
|
// That session ID can be validated against the database that stores
|
||||||
|
// current active sessions.
|
||||||
|
mg_parse_header(mg_get_header(conn, "Cookie"), "ssid", ssid, sizeof(ssid));
|
||||||
|
if (sscanf(ssid, "%[^|]|%[^|]|", name, expire) == 2) {
|
||||||
|
generate_ssid(name, expire, calculated_ssid, sizeof(calculated_ssid));
|
||||||
|
if (strcmp(ssid, calculated_ssid) == 0) {
|
||||||
|
return MG_TRUE; // Authenticate
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Auth failed, do NOT authenticate, redirect to login page
|
||||||
|
mg_printf(conn, "HTTP/1.1 302 Moved\r\nLocation: %s\r\n\r\n", s_login_uri);
|
||||||
|
return MG_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int check_login_form_submission(struct mg_connection *conn) {
|
||||||
|
char name[100], password[100], ssid[100], expire[100], expire_epoch[100];
|
||||||
|
|
||||||
|
mg_get_var(conn, "name", name, sizeof(name));
|
||||||
|
mg_get_var(conn, "password", password, sizeof(password));
|
||||||
|
|
||||||
|
// A real authentication mechanism should be employed here.
|
||||||
|
// Also, the whole site should be served through HTTPS.
|
||||||
|
if (strcmp(name, "Joe") == 0 && strcmp(password, "Doe") == 0) {
|
||||||
|
// Generate expiry date
|
||||||
|
time_t t = time(NULL) + 3600; // Valid for 1 hour
|
||||||
|
snprintf(expire_epoch, sizeof(expire_epoch), "%lu", (unsigned long) t);
|
||||||
|
strftime(expire, sizeof(expire), "%a, %d %b %Y %H:%M:%S GMT", gmtime(&t));
|
||||||
|
generate_ssid(name, expire_epoch, ssid, sizeof(ssid));
|
||||||
|
// Set "session id" cookie, there could be some data encoded in it.
|
||||||
|
mg_printf(conn,
|
||||||
|
"HTTP/1.1 302 Moved\r\n"
|
||||||
|
"Set-Cookie: ssid=%s; expire=\"%s\"; http-only; HttpOnly;\r\n"
|
||||||
|
"Location: /\r\n\r\n",
|
||||||
|
ssid, expire);
|
||||||
|
return MG_TRUE;
|
||||||
|
}
|
||||||
|
return MG_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int serve_request(struct mg_connection *conn) {
|
||||||
|
if (strcmp(conn->uri, s_login_uri) == 0 &&
|
||||||
|
strcmp(conn->request_method, "POST") == 0) {
|
||||||
|
return check_login_form_submission(conn);
|
||||||
|
}
|
||||||
|
return MG_FALSE; // Serve files in the document_root
|
||||||
|
}
|
||||||
|
|
||||||
|
static int ev_handler(struct mg_connection *conn, enum mg_event ev) {
|
||||||
|
switch (ev) {
|
||||||
|
case MG_AUTH: return check_auth(conn);
|
||||||
|
case MG_REQUEST: return serve_request(conn);
|
||||||
|
default: return MG_FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
struct mg_server *server = mg_create_server(NULL, ev_handler);
|
||||||
|
mg_set_option(server, "listening_port", "8080");
|
||||||
|
mg_set_option(server, "document_root", ".");
|
||||||
|
|
||||||
|
printf("Starting on port %s\n", mg_get_option(server, "listening_port"));
|
||||||
|
for (;;) {
|
||||||
|
mg_poll_server(server, 1000);
|
||||||
|
}
|
||||||
|
mg_destroy_server(&server);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<title>WebSocket Test</title>
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
|
<style type="text/css">
|
||||||
|
body {
|
||||||
|
background-color: #cde; margin: 0;
|
||||||
|
padding: 0; font: 14px Helvetica, Arial, sans-serif;
|
||||||
|
}
|
||||||
|
* { outline: none; }
|
||||||
|
div.content {
|
||||||
|
width: 800px; margin: 2em auto; padding: 20px 50px;
|
||||||
|
background-color: #fff; border-radius: 1em;
|
||||||
|
}
|
||||||
|
label { display: inline-block; min-width: 7em; }
|
||||||
|
input { border: 1px solid #ccc; padding: 0.4em; margin: 0 0 10px 0; }
|
||||||
|
a:link, a:visited { color: #69c; text-decoration: none; }
|
||||||
|
@media (max-width: 700px) {
|
||||||
|
body { background-color: #fff; }
|
||||||
|
div.content {
|
||||||
|
width: auto; margin: 0 auto; border-radius: 0; padding: 1em;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<div class="content">
|
||||||
|
<h1>Mongoose Cookie Base Authentication</h1>
|
||||||
|
<p>This is an index page. Authentication succeeded.</p>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<title>WebSocket Test</title>
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
|
<style type="text/css">
|
||||||
|
body {
|
||||||
|
background-color: #cde; margin: 0;
|
||||||
|
padding: 0; font: 14px Helvetica, Arial, sans-serif;
|
||||||
|
}
|
||||||
|
* { outline: none; }
|
||||||
|
div.content {
|
||||||
|
width: 800px; margin: 2em auto; padding: 20px 50px;
|
||||||
|
background-color: #fff; border-radius: 1em;
|
||||||
|
}
|
||||||
|
label { display: inline-block; min-width: 7em; }
|
||||||
|
input { border: 1px solid #ccc; padding: 0.4em; margin: 0 0 10px 0; }
|
||||||
|
a:link, a:visited { color: #69c; text-decoration: none; }
|
||||||
|
@media (max-width: 700px) {
|
||||||
|
body { background-color: #fff; }
|
||||||
|
div.content {
|
||||||
|
width: auto; margin: 0 auto; border-radius: 0; padding: 1em;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<div class="content">
|
||||||
|
<h1>Mongoose Cookie Based Authentication</h1>
|
||||||
|
<p>Use name "Joe", password "Doe" to login.</p>
|
||||||
|
<form method="POST">
|
||||||
|
<div>
|
||||||
|
<label>Name:</label>
|
||||||
|
<input type="text" name="name"/>
|
||||||
|
</div><div>
|
||||||
|
<label>Password:</label>
|
||||||
|
<input type="password" name="password"/>
|
||||||
|
</div><div>
|
||||||
|
<input type="submit" value="Login"/>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
// This file is part of mongoose web server project,
|
||||||
|
// https://github.com/cesanta/mongoose
|
||||||
|
|
||||||
|
using System;
|
||||||
|
|
||||||
|
public class Program {
|
||||||
|
static private int EventHandler(IntPtr conn_ptr, int ev) {
|
||||||
|
MongooseConnection conn = (MongooseConnection)
|
||||||
|
System.Runtime.InteropServices.Marshal.PtrToStructure(
|
||||||
|
conn_ptr , typeof(MongooseConnection));
|
||||||
|
|
||||||
|
if (ev == 102) {
|
||||||
|
// MG_AUTH
|
||||||
|
return 1;
|
||||||
|
} else if (ev == 103) {
|
||||||
|
// MG_REQUEST
|
||||||
|
Mongoose.send_data(conn_ptr, "Hello from C#!\n");
|
||||||
|
Mongoose.send_data(conn_ptr, "URI: " + conn.uri + "\n");
|
||||||
|
Mongoose.send_data(conn_ptr, "HTTP Headers:\n");
|
||||||
|
|
||||||
|
for (int i = 0; i < conn.num_headers; i++) {
|
||||||
|
IntPtr name = conn.http_headers[i].name;
|
||||||
|
IntPtr val = conn.http_headers[i].value;
|
||||||
|
System.Runtime.InteropServices.Marshal.PtrToStringAnsi(name);
|
||||||
|
Mongoose.send_data(conn_ptr, " " +
|
||||||
|
System.Runtime.InteropServices.Marshal.PtrToStringAnsi(name) + ": " +
|
||||||
|
System.Runtime.InteropServices.Marshal.PtrToStringAnsi(val) + "\n");
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void Main() {
|
||||||
|
Mongoose web_server = new Mongoose(".", "9001",
|
||||||
|
new MongooseEventHandler(EventHandler));
|
||||||
|
|
||||||
|
Console.WriteLine("Mongoose started, press Ctrl-C to exit.");
|
||||||
|
for (;;) {
|
||||||
|
web_server.poll(1000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
// This file is part of mongoose web server project,
|
||||||
|
// https://github.com/cesanta/mongoose
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
[StructLayout(LayoutKind.Sequential)] public struct MongooseHeader {
|
||||||
|
[MarshalAs(UnmanagedType.LPTStr)] public IntPtr name;
|
||||||
|
[MarshalAs(UnmanagedType.LPTStr)] public IntPtr value;
|
||||||
|
};
|
||||||
|
|
||||||
|
// mongoose.h :: struct mg_connection
|
||||||
|
[StructLayout(LayoutKind.Sequential)] public struct MongooseConnection {
|
||||||
|
[MarshalAs(UnmanagedType.LPTStr)] public string request_method;
|
||||||
|
[MarshalAs(UnmanagedType.LPTStr)] public string uri;
|
||||||
|
[MarshalAs(UnmanagedType.LPTStr)] public string http_version;
|
||||||
|
[MarshalAs(UnmanagedType.LPTStr)] public string query_string;
|
||||||
|
|
||||||
|
[MarshalAs(UnmanagedType.ByValArray,SizeConst=48)] public char[] remote_ip;
|
||||||
|
[MarshalAs(UnmanagedType.LPTStr)] public string local_ip;
|
||||||
|
[MarshalAs(UnmanagedType.U2)] public short remote_port;
|
||||||
|
[MarshalAs(UnmanagedType.U2)] public short local_port;
|
||||||
|
|
||||||
|
[MarshalAs(UnmanagedType.SysInt)] public int num_headers;
|
||||||
|
[MarshalAs(UnmanagedType.ByValArray,SizeConst=30)]
|
||||||
|
public MongooseHeader[] http_headers;
|
||||||
|
|
||||||
|
[MarshalAs(UnmanagedType.LPTStr)] public IntPtr content;
|
||||||
|
[MarshalAs(UnmanagedType.SysInt)] public int content_len;
|
||||||
|
|
||||||
|
[MarshalAs(UnmanagedType.SysInt)] public int is_websocket;
|
||||||
|
[MarshalAs(UnmanagedType.SysInt)] public int status_code;
|
||||||
|
[MarshalAs(UnmanagedType.SysInt)] public int wsbits;
|
||||||
|
};
|
||||||
|
|
||||||
|
public delegate int MongooseEventHandler(IntPtr c, int ev);
|
||||||
|
|
||||||
|
public class Mongoose {
|
||||||
|
public const string dll_ = "mongoose";
|
||||||
|
private IntPtr server_;
|
||||||
|
|
||||||
|
[DllImport(dll_)] private static extern IntPtr
|
||||||
|
mg_create_server(IntPtr user_data, MongooseEventHandler eh);
|
||||||
|
[DllImport(dll_)] private static extern int
|
||||||
|
mg_poll_server(IntPtr server, int milli);
|
||||||
|
[DllImport(dll_)] private static extern IntPtr
|
||||||
|
mg_set_option(IntPtr server, string name, string value);
|
||||||
|
[DllImport(dll_)] public static extern int
|
||||||
|
mg_send_data(IntPtr conn, string data, int length);
|
||||||
|
|
||||||
|
public Mongoose(string document_root,
|
||||||
|
string listening_port,
|
||||||
|
MongooseEventHandler event_handler) {
|
||||||
|
server_ = mg_create_server(IntPtr.Zero, event_handler);
|
||||||
|
mg_set_option(server_, "document_root", document_root);
|
||||||
|
mg_set_option(server_, "listening_port", listening_port);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int send_data(IntPtr conn, string data) {
|
||||||
|
return mg_send_data(conn, data, data.Length);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void poll(int milli) {
|
||||||
|
mg_poll_server(server_, milli);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: add destructor and call mg_destroy_server()
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
# Copyright (c) 2014 Cesanta Software
|
||||||
|
# All rights reserved
|
||||||
|
|
||||||
|
PROG = digest_auth
|
||||||
|
CFLAGS = -W -Wall -I../.. -pthread -g -O0 $(CFLAGS_EXTRA)
|
||||||
|
SOURCES = $(PROG).c ../../mongoose.c
|
||||||
|
|
||||||
|
$(PROG): $(SOURCES)
|
||||||
|
$(CC) -o $(PROG) $(SOURCES) $(CFLAGS)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -rf $(PROG) *.exe *.dSYM *.obj *.exp .*o *.lib
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include "mongoose.h"
|
||||||
|
|
||||||
|
static int ev_handler(struct mg_connection *conn, enum mg_event ev) {
|
||||||
|
|
||||||
|
if (ev == MG_AUTH) {
|
||||||
|
int result = MG_FALSE; // Not authorized
|
||||||
|
FILE *fp;
|
||||||
|
|
||||||
|
// To populate passwords file, do
|
||||||
|
// mongoose -A my_passwords.txt mydomain.com admin admin
|
||||||
|
if ((fp = fopen("my_passwords.txt", "r")) != NULL) {
|
||||||
|
result = mg_authorize_digest(conn, fp);
|
||||||
|
fclose(fp);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
return MG_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
struct mg_server *server = mg_create_server(NULL, ev_handler);
|
||||||
|
mg_set_option(server, "listening_port", "8080");
|
||||||
|
mg_set_option(server, "document_root", ".");
|
||||||
|
|
||||||
|
printf("Starting on port %s\n", mg_get_option(server, "listening_port"));
|
||||||
|
for (;;) {
|
||||||
|
mg_poll_server(server, 1000);
|
||||||
|
}
|
||||||
|
mg_destroy_server(&server);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
# Copyright (c) 2014 Cesanta Software
|
||||||
|
# All rights reserved
|
||||||
|
|
||||||
|
PROG = file_upload
|
||||||
|
CFLAGS = -W -Wall -I../.. -pthread -g -O0 $(CFLAGS_EXTRA)
|
||||||
|
SOURCES = $(PROG).c ../../mongoose.c
|
||||||
|
|
||||||
|
all: $(PROG)
|
||||||
|
|
||||||
|
run: $(PROG)
|
||||||
|
./$(PROG)
|
||||||
|
|
||||||
|
$(PROG): $(SOURCES) Makefile
|
||||||
|
$(CC) -o $(PROG) $(SOURCES) $(CFLAGS)
|
||||||
|
|
||||||
|
win:
|
||||||
|
wine cl $(SOURCES) /MD /nologo /DNDEBUG /O1 /I../.. /Fe$(PROG).exe
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -rf $(PROG) *.exe *.dSYM *.obj *.exp .*o *.lib *.gc*
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
// Copyright (c) 2004-2012 Sergey Lyubka
|
||||||
|
// This file is a part of mongoose project, http://github.com/valenok/mongoose
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include "mongoose.h"
|
||||||
|
|
||||||
|
static int send_index_page(struct mg_connection *conn) {
|
||||||
|
const char *data;
|
||||||
|
int data_len, ofs = 0;
|
||||||
|
char var_name[100], file_name[100];
|
||||||
|
|
||||||
|
mg_printf_data(conn, "%s",
|
||||||
|
"<html><body>Upload example."
|
||||||
|
"<form method=\"POST\" action=\"/handle_post_request\" "
|
||||||
|
" enctype=\"multipart/form-data\">"
|
||||||
|
"<input type=\"file\" name=\"file\" /> <br/>"
|
||||||
|
"<input type=\"submit\" value=\"Upload\" />"
|
||||||
|
"</form>");
|
||||||
|
|
||||||
|
while ((ofs = mg_parse_multipart(conn->content + ofs, conn->content_len - ofs,
|
||||||
|
var_name, sizeof(var_name),
|
||||||
|
file_name, sizeof(file_name),
|
||||||
|
&data, &data_len)) > 0) {
|
||||||
|
mg_printf_data(conn, "var: %s, file_name: %s, size: %d bytes<br>",
|
||||||
|
var_name, file_name, data_len);
|
||||||
|
}
|
||||||
|
|
||||||
|
mg_printf_data(conn, "%s", "</body></html>");
|
||||||
|
|
||||||
|
return MG_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int ev_handler(struct mg_connection *conn, enum mg_event ev) {
|
||||||
|
switch (ev) {
|
||||||
|
case MG_AUTH: return MG_TRUE;
|
||||||
|
case MG_REQUEST: return send_index_page(conn);
|
||||||
|
default: return MG_FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
struct mg_server *server;
|
||||||
|
|
||||||
|
// Create and configure the server
|
||||||
|
server = mg_create_server(NULL, ev_handler);
|
||||||
|
mg_set_option(server, "listening_port", "8080");
|
||||||
|
|
||||||
|
// Serve request. Hit Ctrl-C to terminate the program
|
||||||
|
printf("Starting on port %s\n", mg_get_option(server, "listening_port"));
|
||||||
|
for (;;) {
|
||||||
|
mg_poll_server(server, 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cleanup, and free server instance
|
||||||
|
mg_destroy_server(&server);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
# Copyright (c) 2014 Cesanta Software
|
||||||
|
# All rights reserved
|
||||||
|
|
||||||
|
PROG = form_submit
|
||||||
|
CFLAGS = -W -Wall -I../.. -pthread -g -O0 $(CFLAGS_EXTRA)
|
||||||
|
SOURCES = $(PROG).c ../../mongoose.c
|
||||||
|
|
||||||
|
$(PROG): $(SOURCES)
|
||||||
|
$(CC) -o $(PROG) $(SOURCES) $(CFLAGS)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -rf $(PROG) *.exe *.dSYM *.obj *.exp .*o *.lib
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include "mongoose.h"
|
||||||
|
|
||||||
|
static const char *html_form =
|
||||||
|
"<html><body>POST example."
|
||||||
|
"<form method=\"POST\" action=\"/handle_post_request\">"
|
||||||
|
"Input 1: <input type=\"text\" name=\"input_1\" /> <br/>"
|
||||||
|
"Input 2: <input type=\"text\" name=\"input_2\" /> <br/>"
|
||||||
|
"<input type=\"submit\" />"
|
||||||
|
"</form></body></html>";
|
||||||
|
|
||||||
|
static void send_reply(struct mg_connection *conn) {
|
||||||
|
char var1[500], var2[500];
|
||||||
|
|
||||||
|
if (strcmp(conn->uri, "/handle_post_request") == 0) {
|
||||||
|
// User has submitted a form, show submitted data and a variable value
|
||||||
|
// Parse form data. var1 and var2 are guaranteed to be NUL-terminated
|
||||||
|
mg_get_var(conn, "input_1", var1, sizeof(var1));
|
||||||
|
mg_get_var(conn, "input_2", var2, sizeof(var2));
|
||||||
|
|
||||||
|
// Send reply to the client, showing submitted form values.
|
||||||
|
// POST data is in conn->content, data length is in conn->content_len
|
||||||
|
mg_send_header(conn, "Content-Type", "text/plain");
|
||||||
|
mg_printf_data(conn,
|
||||||
|
"Submitted data: [%.*s]\n"
|
||||||
|
"Submitted data length: %d bytes\n"
|
||||||
|
"input_1: [%s]\n"
|
||||||
|
"input_2: [%s]\n",
|
||||||
|
conn->content_len, conn->content,
|
||||||
|
conn->content_len, var1, var2);
|
||||||
|
} else {
|
||||||
|
// Show HTML form.
|
||||||
|
mg_send_data(conn, html_form, strlen(html_form));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static int ev_handler(struct mg_connection *conn, enum mg_event ev) {
|
||||||
|
if (ev == MG_REQUEST) {
|
||||||
|
send_reply(conn);
|
||||||
|
return MG_TRUE;
|
||||||
|
} else if (ev == MG_AUTH) {
|
||||||
|
return MG_TRUE;
|
||||||
|
} else {
|
||||||
|
return MG_FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
struct mg_server *server = mg_create_server(NULL, ev_handler);
|
||||||
|
|
||||||
|
mg_set_option(server, "listening_port", "8080");
|
||||||
|
|
||||||
|
printf("Starting on port %s\n", mg_get_option(server, "listening_port"));
|
||||||
|
for (;;) {
|
||||||
|
mg_poll_server(server, 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
mg_destroy_server(&server);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include "mongoose.h"
|
|
||||||
|
|
||||||
static void *callback(enum mg_event event,
|
|
||||||
struct mg_connection *conn) {
|
|
||||||
const struct mg_request_info *request_info = mg_get_request_info(conn);
|
|
||||||
|
|
||||||
if (event == MG_NEW_REQUEST) {
|
|
||||||
char content[1024];
|
|
||||||
int content_length = snprintf(content, sizeof(content),
|
|
||||||
"Hello from mongoose! Remote port: %d",
|
|
||||||
request_info->remote_port);
|
|
||||||
mg_printf(conn,
|
|
||||||
"HTTP/1.1 200 OK\r\n"
|
|
||||||
"Content-Type: text/plain\r\n"
|
|
||||||
"Content-Length: %d\r\n" // Always set Content-Length
|
|
||||||
"\r\n"
|
|
||||||
"%s",
|
|
||||||
content_length, content);
|
|
||||||
// Mark as processed
|
|
||||||
return "";
|
|
||||||
} else {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(void) {
|
|
||||||
struct mg_context *ctx;
|
|
||||||
const char *options[] = {"listening_ports", "8080", NULL};
|
|
||||||
|
|
||||||
ctx = mg_start(&callback, NULL, options);
|
|
||||||
getchar(); // Wait until user hits "enter"
|
|
||||||
mg_stop(ctx);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
# Copyright (c) 2014 Cesanta Software
|
||||||
|
# All rights reserved
|
||||||
|
|
||||||
|
PROG = hello_world
|
||||||
|
CFLAGS = -W -Wall -I../.. -pthread -g -O0 $(CFLAGS_EXTRA)
|
||||||
|
SOURCES = $(PROG).c ../../mongoose.c
|
||||||
|
|
||||||
|
all: $(PROG)
|
||||||
|
|
||||||
|
run: $(PROG)
|
||||||
|
./$(PROG)
|
||||||
|
|
||||||
|
$(PROG): $(SOURCES) Makefile
|
||||||
|
$(CC) -o $(PROG) $(SOURCES) $(CFLAGS)
|
||||||
|
|
||||||
|
win:
|
||||||
|
wine cl $(SOURCES) /MD /nologo /DNDEBUG /O1 /I../.. /Fe$(PROG).exe
|
||||||
|
wine $(PROG).exe
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -rf $(PROG) *.exe *.dSYM *.obj *.exp .*o *.lib *.gc*
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
// Copyright (c) 2014 Cesanta Software
|
||||||
|
// All rights reserved
|
||||||
|
//
|
||||||
|
// This example demostrates basic use of Mongoose embedded web server.
|
||||||
|
// $Date: 2014-09-09 22:20:23 UTC $
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include "mongoose.h"
|
||||||
|
|
||||||
|
static int ev_handler(struct mg_connection *conn, enum mg_event ev) {
|
||||||
|
switch (ev) {
|
||||||
|
case MG_AUTH: return MG_TRUE;
|
||||||
|
case MG_REQUEST:
|
||||||
|
mg_printf_data(conn, "Hello! Requested URI is [%s]", conn->uri);
|
||||||
|
return MG_TRUE;
|
||||||
|
default: return MG_FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
struct mg_server *server;
|
||||||
|
|
||||||
|
// Create and configure the server
|
||||||
|
server = mg_create_server(NULL, ev_handler);
|
||||||
|
mg_set_option(server, "listening_port", "8080");
|
||||||
|
|
||||||
|
// Serve request. Hit Ctrl-C to terminate the program
|
||||||
|
printf("Starting on port %s\n", mg_get_option(server, "listening_port"));
|
||||||
|
for (;;) {
|
||||||
|
mg_poll_server(server, 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cleanup, and free server instance
|
||||||
|
mg_destroy_server(&server);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 1.4 KiB |
@@ -1,73 +0,0 @@
|
|||||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
|
||||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
||||||
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" dir="ltr">
|
|
||||||
<!-- This file is part of the Mongoose project,
|
|
||||||
http://code.google.com/p/mongoose -->
|
|
||||||
<head>
|
|
||||||
<title>Mongoose chat server</title>
|
|
||||||
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
|
|
||||||
<link type="text/css" rel="stylesheet" href="style.css"/>
|
|
||||||
<script src="jquery.js"></script>
|
|
||||||
<script src="main.js"></script>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div id="header">
|
|
||||||
<div id="logo"></div>
|
|
||||||
<div class="rounded infobox help-message" id="motd">
|
|
||||||
Chat room implemented using
|
|
||||||
<a href="http://code.google.com/p/mongoose" target="_blank">Mongoose</a>
|
|
||||||
embeddable web server.
|
|
||||||
This application was written for educational purposes demonstrating
|
|
||||||
how web interface could be decoupled from the business logic. Not a
|
|
||||||
single line of HTML is generated by the server, instead, server
|
|
||||||
gives data to the client in JSON format.
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
|
|
||||||
<div id="middle">
|
|
||||||
<div><center><span id="error" class="rounded"></span><center></div>
|
|
||||||
|
|
||||||
<div id="menu">
|
|
||||||
<div class="menu-item left-rounded menu-item-selected"
|
|
||||||
name="chat">Chat</div>
|
|
||||||
<div class="menu-item left-rounded" name="settings">Settings</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="content" class="rounded">
|
|
||||||
|
|
||||||
<div id="chat" class="main">
|
|
||||||
<div class="chat-window">
|
|
||||||
<span class="top-rounded chat-title">Main room</span>
|
|
||||||
<div class="bottom-rounded chat-content">
|
|
||||||
<div class="message-list" id="mml">
|
|
||||||
</div>
|
|
||||||
<input type="text" size="40" class="message-input"></input>
|
|
||||||
<span class="help-message">
|
|
||||||
Type your message here and press enter</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="settings" class="hidden main">
|
|
||||||
<div>
|
|
||||||
<span class="top-rounded chat-title">Settings</span>
|
|
||||||
<div class="bottom-rounded chat-content">
|
|
||||||
<table>
|
|
||||||
<tr><td>Max messages to display:</td><td>blah blah</td></tr>
|
|
||||||
<tr><td>Text color:</td><td>blah blah</td></tr>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="footer">
|
|
||||||
Copyright © 2004-2010 by Sergey Lyubka
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
Vendored
-154
@@ -1,154 +0,0 @@
|
|||||||
/*!
|
|
||||||
* jQuery JavaScript Library v1.4.2
|
|
||||||
* http://jquery.com/
|
|
||||||
*
|
|
||||||
* Copyright 2010, John Resig
|
|
||||||
* Dual licensed under the MIT or GPL Version 2 licenses.
|
|
||||||
* http://jquery.org/license
|
|
||||||
*
|
|
||||||
* Includes Sizzle.js
|
|
||||||
* http://sizzlejs.com/
|
|
||||||
* Copyright 2010, The Dojo Foundation
|
|
||||||
* Released under the MIT, BSD, and GPL Licenses.
|
|
||||||
*
|
|
||||||
* Date: Sat Feb 13 22:33:48 2010 -0500
|
|
||||||
*/
|
|
||||||
(function(A,w){function ma(){if(!c.isReady){try{s.documentElement.doScroll("left")}catch(a){setTimeout(ma,1);return}c.ready()}}function Qa(a,b){b.src?c.ajax({url:b.src,async:false,dataType:"script"}):c.globalEval(b.text||b.textContent||b.innerHTML||"");b.parentNode&&b.parentNode.removeChild(b)}function X(a,b,d,f,e,j){var i=a.length;if(typeof b==="object"){for(var o in b)X(a,o,b[o],f,e,d);return a}if(d!==w){f=!j&&f&&c.isFunction(d);for(o=0;o<i;o++)e(a[o],b,f?d.call(a[o],o,e(a[o],b)):d,j);return a}return i?
|
|
||||||
e(a[0],b):w}function J(){return(new Date).getTime()}function Y(){return false}function Z(){return true}function na(a,b,d){d[0].type=a;return c.event.handle.apply(b,d)}function oa(a){var b,d=[],f=[],e=arguments,j,i,o,k,n,r;i=c.data(this,"events");if(!(a.liveFired===this||!i||!i.live||a.button&&a.type==="click")){a.liveFired=this;var u=i.live.slice(0);for(k=0;k<u.length;k++){i=u[k];i.origType.replace(O,"")===a.type?f.push(i.selector):u.splice(k--,1)}j=c(a.target).closest(f,a.currentTarget);n=0;for(r=
|
|
||||||
j.length;n<r;n++)for(k=0;k<u.length;k++){i=u[k];if(j[n].selector===i.selector){o=j[n].elem;f=null;if(i.preType==="mouseenter"||i.preType==="mouseleave")f=c(a.relatedTarget).closest(i.selector)[0];if(!f||f!==o)d.push({elem:o,handleObj:i})}}n=0;for(r=d.length;n<r;n++){j=d[n];a.currentTarget=j.elem;a.data=j.handleObj.data;a.handleObj=j.handleObj;if(j.handleObj.origHandler.apply(j.elem,e)===false){b=false;break}}return b}}function pa(a,b){return"live."+(a&&a!=="*"?a+".":"")+b.replace(/\./g,"`").replace(/ /g,
|
|
||||||
"&")}function qa(a){return!a||!a.parentNode||a.parentNode.nodeType===11}function ra(a,b){var d=0;b.each(function(){if(this.nodeName===(a[d]&&a[d].nodeName)){var f=c.data(a[d++]),e=c.data(this,f);if(f=f&&f.events){delete e.handle;e.events={};for(var j in f)for(var i in f[j])c.event.add(this,j,f[j][i],f[j][i].data)}}})}function sa(a,b,d){var f,e,j;b=b&&b[0]?b[0].ownerDocument||b[0]:s;if(a.length===1&&typeof a[0]==="string"&&a[0].length<512&&b===s&&!ta.test(a[0])&&(c.support.checkClone||!ua.test(a[0]))){e=
|
|
||||||
true;if(j=c.fragments[a[0]])if(j!==1)f=j}if(!f){f=b.createDocumentFragment();c.clean(a,b,f,d)}if(e)c.fragments[a[0]]=j?f:1;return{fragment:f,cacheable:e}}function K(a,b){var d={};c.each(va.concat.apply([],va.slice(0,b)),function(){d[this]=a});return d}function wa(a){return"scrollTo"in a&&a.document?a:a.nodeType===9?a.defaultView||a.parentWindow:false}var c=function(a,b){return new c.fn.init(a,b)},Ra=A.jQuery,Sa=A.$,s=A.document,T,Ta=/^[^<]*(<[\w\W]+>)[^>]*$|^#([\w-]+)$/,Ua=/^.[^:#\[\.,]*$/,Va=/\S/,
|
|
||||||
Wa=/^(\s|\u00A0)+|(\s|\u00A0)+$/g,Xa=/^<(\w+)\s*\/?>(?:<\/\1>)?$/,P=navigator.userAgent,xa=false,Q=[],L,$=Object.prototype.toString,aa=Object.prototype.hasOwnProperty,ba=Array.prototype.push,R=Array.prototype.slice,ya=Array.prototype.indexOf;c.fn=c.prototype={init:function(a,b){var d,f;if(!a)return this;if(a.nodeType){this.context=this[0]=a;this.length=1;return this}if(a==="body"&&!b){this.context=s;this[0]=s.body;this.selector="body";this.length=1;return this}if(typeof a==="string")if((d=Ta.exec(a))&&
|
|
||||||
(d[1]||!b))if(d[1]){f=b?b.ownerDocument||b:s;if(a=Xa.exec(a))if(c.isPlainObject(b)){a=[s.createElement(a[1])];c.fn.attr.call(a,b,true)}else a=[f.createElement(a[1])];else{a=sa([d[1]],[f]);a=(a.cacheable?a.fragment.cloneNode(true):a.fragment).childNodes}return c.merge(this,a)}else{if(b=s.getElementById(d[2])){if(b.id!==d[2])return T.find(a);this.length=1;this[0]=b}this.context=s;this.selector=a;return this}else if(!b&&/^\w+$/.test(a)){this.selector=a;this.context=s;a=s.getElementsByTagName(a);return c.merge(this,
|
|
||||||
a)}else return!b||b.jquery?(b||T).find(a):c(b).find(a);else if(c.isFunction(a))return T.ready(a);if(a.selector!==w){this.selector=a.selector;this.context=a.context}return c.makeArray(a,this)},selector:"",jquery:"1.4.2",length:0,size:function(){return this.length},toArray:function(){return R.call(this,0)},get:function(a){return a==null?this.toArray():a<0?this.slice(a)[0]:this[a]},pushStack:function(a,b,d){var f=c();c.isArray(a)?ba.apply(f,a):c.merge(f,a);f.prevObject=this;f.context=this.context;if(b===
|
|
||||||
"find")f.selector=this.selector+(this.selector?" ":"")+d;else if(b)f.selector=this.selector+"."+b+"("+d+")";return f},each:function(a,b){return c.each(this,a,b)},ready:function(a){c.bindReady();if(c.isReady)a.call(s,c);else Q&&Q.push(a);return this},eq:function(a){return a===-1?this.slice(a):this.slice(a,+a+1)},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},slice:function(){return this.pushStack(R.apply(this,arguments),"slice",R.call(arguments).join(","))},map:function(a){return this.pushStack(c.map(this,
|
|
||||||
function(b,d){return a.call(b,d,b)}))},end:function(){return this.prevObject||c(null)},push:ba,sort:[].sort,splice:[].splice};c.fn.init.prototype=c.fn;c.extend=c.fn.extend=function(){var a=arguments[0]||{},b=1,d=arguments.length,f=false,e,j,i,o;if(typeof a==="boolean"){f=a;a=arguments[1]||{};b=2}if(typeof a!=="object"&&!c.isFunction(a))a={};if(d===b){a=this;--b}for(;b<d;b++)if((e=arguments[b])!=null)for(j in e){i=a[j];o=e[j];if(a!==o)if(f&&o&&(c.isPlainObject(o)||c.isArray(o))){i=i&&(c.isPlainObject(i)||
|
|
||||||
c.isArray(i))?i:c.isArray(o)?[]:{};a[j]=c.extend(f,i,o)}else if(o!==w)a[j]=o}return a};c.extend({noConflict:function(a){A.$=Sa;if(a)A.jQuery=Ra;return c},isReady:false,ready:function(){if(!c.isReady){if(!s.body)return setTimeout(c.ready,13);c.isReady=true;if(Q){for(var a,b=0;a=Q[b++];)a.call(s,c);Q=null}c.fn.triggerHandler&&c(s).triggerHandler("ready")}},bindReady:function(){if(!xa){xa=true;if(s.readyState==="complete")return c.ready();if(s.addEventListener){s.addEventListener("DOMContentLoaded",
|
|
||||||
L,false);A.addEventListener("load",c.ready,false)}else if(s.attachEvent){s.attachEvent("onreadystatechange",L);A.attachEvent("onload",c.ready);var a=false;try{a=A.frameElement==null}catch(b){}s.documentElement.doScroll&&a&&ma()}}},isFunction:function(a){return $.call(a)==="[object Function]"},isArray:function(a){return $.call(a)==="[object Array]"},isPlainObject:function(a){if(!a||$.call(a)!=="[object Object]"||a.nodeType||a.setInterval)return false;if(a.constructor&&!aa.call(a,"constructor")&&!aa.call(a.constructor.prototype,
|
|
||||||
"isPrototypeOf"))return false;var b;for(b in a);return b===w||aa.call(a,b)},isEmptyObject:function(a){for(var b in a)return false;return true},error:function(a){throw a;},parseJSON:function(a){if(typeof a!=="string"||!a)return null;a=c.trim(a);if(/^[\],:{}\s]*$/.test(a.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,"@").replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,"]").replace(/(?:^|:|,)(?:\s*\[)+/g,"")))return A.JSON&&A.JSON.parse?A.JSON.parse(a):(new Function("return "+
|
|
||||||
a))();else c.error("Invalid JSON: "+a)},noop:function(){},globalEval:function(a){if(a&&Va.test(a)){var b=s.getElementsByTagName("head")[0]||s.documentElement,d=s.createElement("script");d.type="text/javascript";if(c.support.scriptEval)d.appendChild(s.createTextNode(a));else d.text=a;b.insertBefore(d,b.firstChild);b.removeChild(d)}},nodeName:function(a,b){return a.nodeName&&a.nodeName.toUpperCase()===b.toUpperCase()},each:function(a,b,d){var f,e=0,j=a.length,i=j===w||c.isFunction(a);if(d)if(i)for(f in a){if(b.apply(a[f],
|
|
||||||
d)===false)break}else for(;e<j;){if(b.apply(a[e++],d)===false)break}else if(i)for(f in a){if(b.call(a[f],f,a[f])===false)break}else for(d=a[0];e<j&&b.call(d,e,d)!==false;d=a[++e]);return a},trim:function(a){return(a||"").replace(Wa,"")},makeArray:function(a,b){b=b||[];if(a!=null)a.length==null||typeof a==="string"||c.isFunction(a)||typeof a!=="function"&&a.setInterval?ba.call(b,a):c.merge(b,a);return b},inArray:function(a,b){if(b.indexOf)return b.indexOf(a);for(var d=0,f=b.length;d<f;d++)if(b[d]===
|
|
||||||
a)return d;return-1},merge:function(a,b){var d=a.length,f=0;if(typeof b.length==="number")for(var e=b.length;f<e;f++)a[d++]=b[f];else for(;b[f]!==w;)a[d++]=b[f++];a.length=d;return a},grep:function(a,b,d){for(var f=[],e=0,j=a.length;e<j;e++)!d!==!b(a[e],e)&&f.push(a[e]);return f},map:function(a,b,d){for(var f=[],e,j=0,i=a.length;j<i;j++){e=b(a[j],j,d);if(e!=null)f[f.length]=e}return f.concat.apply([],f)},guid:1,proxy:function(a,b,d){if(arguments.length===2)if(typeof b==="string"){d=a;a=d[b];b=w}else if(b&&
|
|
||||||
!c.isFunction(b)){d=b;b=w}if(!b&&a)b=function(){return a.apply(d||this,arguments)};if(a)b.guid=a.guid=a.guid||b.guid||c.guid++;return b},uaMatch:function(a){a=a.toLowerCase();a=/(webkit)[ \/]([\w.]+)/.exec(a)||/(opera)(?:.*version)?[ \/]([\w.]+)/.exec(a)||/(msie) ([\w.]+)/.exec(a)||!/compatible/.test(a)&&/(mozilla)(?:.*? rv:([\w.]+))?/.exec(a)||[];return{browser:a[1]||"",version:a[2]||"0"}},browser:{}});P=c.uaMatch(P);if(P.browser){c.browser[P.browser]=true;c.browser.version=P.version}if(c.browser.webkit)c.browser.safari=
|
|
||||||
true;if(ya)c.inArray=function(a,b){return ya.call(b,a)};T=c(s);if(s.addEventListener)L=function(){s.removeEventListener("DOMContentLoaded",L,false);c.ready()};else if(s.attachEvent)L=function(){if(s.readyState==="complete"){s.detachEvent("onreadystatechange",L);c.ready()}};(function(){c.support={};var a=s.documentElement,b=s.createElement("script"),d=s.createElement("div"),f="script"+J();d.style.display="none";d.innerHTML=" <link/><table></table><a href='/a' style='color:red;float:left;opacity:.55;'>a</a><input type='checkbox'/>";
|
|
||||||
var e=d.getElementsByTagName("*"),j=d.getElementsByTagName("a")[0];if(!(!e||!e.length||!j)){c.support={leadingWhitespace:d.firstChild.nodeType===3,tbody:!d.getElementsByTagName("tbody").length,htmlSerialize:!!d.getElementsByTagName("link").length,style:/red/.test(j.getAttribute("style")),hrefNormalized:j.getAttribute("href")==="/a",opacity:/^0.55$/.test(j.style.opacity),cssFloat:!!j.style.cssFloat,checkOn:d.getElementsByTagName("input")[0].value==="on",optSelected:s.createElement("select").appendChild(s.createElement("option")).selected,
|
|
||||||
parentNode:d.removeChild(d.appendChild(s.createElement("div"))).parentNode===null,deleteExpando:true,checkClone:false,scriptEval:false,noCloneEvent:true,boxModel:null};b.type="text/javascript";try{b.appendChild(s.createTextNode("window."+f+"=1;"))}catch(i){}a.insertBefore(b,a.firstChild);if(A[f]){c.support.scriptEval=true;delete A[f]}try{delete b.test}catch(o){c.support.deleteExpando=false}a.removeChild(b);if(d.attachEvent&&d.fireEvent){d.attachEvent("onclick",function k(){c.support.noCloneEvent=
|
|
||||||
false;d.detachEvent("onclick",k)});d.cloneNode(true).fireEvent("onclick")}d=s.createElement("div");d.innerHTML="<input type='radio' name='radiotest' checked='checked'/>";a=s.createDocumentFragment();a.appendChild(d.firstChild);c.support.checkClone=a.cloneNode(true).cloneNode(true).lastChild.checked;c(function(){var k=s.createElement("div");k.style.width=k.style.paddingLeft="1px";s.body.appendChild(k);c.boxModel=c.support.boxModel=k.offsetWidth===2;s.body.removeChild(k).style.display="none"});a=function(k){var n=
|
|
||||||
s.createElement("div");k="on"+k;var r=k in n;if(!r){n.setAttribute(k,"return;");r=typeof n[k]==="function"}return r};c.support.submitBubbles=a("submit");c.support.changeBubbles=a("change");a=b=d=e=j=null}})();c.props={"for":"htmlFor","class":"className",readonly:"readOnly",maxlength:"maxLength",cellspacing:"cellSpacing",rowspan:"rowSpan",colspan:"colSpan",tabindex:"tabIndex",usemap:"useMap",frameborder:"frameBorder"};var G="jQuery"+J(),Ya=0,za={};c.extend({cache:{},expando:G,noData:{embed:true,object:true,
|
|
||||||
applet:true},data:function(a,b,d){if(!(a.nodeName&&c.noData[a.nodeName.toLowerCase()])){a=a==A?za:a;var f=a[G],e=c.cache;if(!f&&typeof b==="string"&&d===w)return null;f||(f=++Ya);if(typeof b==="object"){a[G]=f;e[f]=c.extend(true,{},b)}else if(!e[f]){a[G]=f;e[f]={}}a=e[f];if(d!==w)a[b]=d;return typeof b==="string"?a[b]:a}},removeData:function(a,b){if(!(a.nodeName&&c.noData[a.nodeName.toLowerCase()])){a=a==A?za:a;var d=a[G],f=c.cache,e=f[d];if(b){if(e){delete e[b];c.isEmptyObject(e)&&c.removeData(a)}}else{if(c.support.deleteExpando)delete a[c.expando];
|
|
||||||
else a.removeAttribute&&a.removeAttribute(c.expando);delete f[d]}}}});c.fn.extend({data:function(a,b){if(typeof a==="undefined"&&this.length)return c.data(this[0]);else if(typeof a==="object")return this.each(function(){c.data(this,a)});var d=a.split(".");d[1]=d[1]?"."+d[1]:"";if(b===w){var f=this.triggerHandler("getData"+d[1]+"!",[d[0]]);if(f===w&&this.length)f=c.data(this[0],a);return f===w&&d[1]?this.data(d[0]):f}else return this.trigger("setData"+d[1]+"!",[d[0],b]).each(function(){c.data(this,
|
|
||||||
a,b)})},removeData:function(a){return this.each(function(){c.removeData(this,a)})}});c.extend({queue:function(a,b,d){if(a){b=(b||"fx")+"queue";var f=c.data(a,b);if(!d)return f||[];if(!f||c.isArray(d))f=c.data(a,b,c.makeArray(d));else f.push(d);return f}},dequeue:function(a,b){b=b||"fx";var d=c.queue(a,b),f=d.shift();if(f==="inprogress")f=d.shift();if(f){b==="fx"&&d.unshift("inprogress");f.call(a,function(){c.dequeue(a,b)})}}});c.fn.extend({queue:function(a,b){if(typeof a!=="string"){b=a;a="fx"}if(b===
|
|
||||||
w)return c.queue(this[0],a);return this.each(function(){var d=c.queue(this,a,b);a==="fx"&&d[0]!=="inprogress"&&c.dequeue(this,a)})},dequeue:function(a){return this.each(function(){c.dequeue(this,a)})},delay:function(a,b){a=c.fx?c.fx.speeds[a]||a:a;b=b||"fx";return this.queue(b,function(){var d=this;setTimeout(function(){c.dequeue(d,b)},a)})},clearQueue:function(a){return this.queue(a||"fx",[])}});var Aa=/[\n\t]/g,ca=/\s+/,Za=/\r/g,$a=/href|src|style/,ab=/(button|input)/i,bb=/(button|input|object|select|textarea)/i,
|
|
||||||
cb=/^(a|area)$/i,Ba=/radio|checkbox/;c.fn.extend({attr:function(a,b){return X(this,a,b,true,c.attr)},removeAttr:function(a){return this.each(function(){c.attr(this,a,"");this.nodeType===1&&this.removeAttribute(a)})},addClass:function(a){if(c.isFunction(a))return this.each(function(n){var r=c(this);r.addClass(a.call(this,n,r.attr("class")))});if(a&&typeof a==="string")for(var b=(a||"").split(ca),d=0,f=this.length;d<f;d++){var e=this[d];if(e.nodeType===1)if(e.className){for(var j=" "+e.className+" ",
|
|
||||||
i=e.className,o=0,k=b.length;o<k;o++)if(j.indexOf(" "+b[o]+" ")<0)i+=" "+b[o];e.className=c.trim(i)}else e.className=a}return this},removeClass:function(a){if(c.isFunction(a))return this.each(function(k){var n=c(this);n.removeClass(a.call(this,k,n.attr("class")))});if(a&&typeof a==="string"||a===w)for(var b=(a||"").split(ca),d=0,f=this.length;d<f;d++){var e=this[d];if(e.nodeType===1&&e.className)if(a){for(var j=(" "+e.className+" ").replace(Aa," "),i=0,o=b.length;i<o;i++)j=j.replace(" "+b[i]+" ",
|
|
||||||
" ");e.className=c.trim(j)}else e.className=""}return this},toggleClass:function(a,b){var d=typeof a,f=typeof b==="boolean";if(c.isFunction(a))return this.each(function(e){var j=c(this);j.toggleClass(a.call(this,e,j.attr("class"),b),b)});return this.each(function(){if(d==="string")for(var e,j=0,i=c(this),o=b,k=a.split(ca);e=k[j++];){o=f?o:!i.hasClass(e);i[o?"addClass":"removeClass"](e)}else if(d==="undefined"||d==="boolean"){this.className&&c.data(this,"__className__",this.className);this.className=
|
|
||||||
this.className||a===false?"":c.data(this,"__className__")||""}})},hasClass:function(a){a=" "+a+" ";for(var b=0,d=this.length;b<d;b++)if((" "+this[b].className+" ").replace(Aa," ").indexOf(a)>-1)return true;return false},val:function(a){if(a===w){var b=this[0];if(b){if(c.nodeName(b,"option"))return(b.attributes.value||{}).specified?b.value:b.text;if(c.nodeName(b,"select")){var d=b.selectedIndex,f=[],e=b.options;b=b.type==="select-one";if(d<0)return null;var j=b?d:0;for(d=b?d+1:e.length;j<d;j++){var i=
|
|
||||||
e[j];if(i.selected){a=c(i).val();if(b)return a;f.push(a)}}return f}if(Ba.test(b.type)&&!c.support.checkOn)return b.getAttribute("value")===null?"on":b.value;return(b.value||"").replace(Za,"")}return w}var o=c.isFunction(a);return this.each(function(k){var n=c(this),r=a;if(this.nodeType===1){if(o)r=a.call(this,k,n.val());if(typeof r==="number")r+="";if(c.isArray(r)&&Ba.test(this.type))this.checked=c.inArray(n.val(),r)>=0;else if(c.nodeName(this,"select")){var u=c.makeArray(r);c("option",this).each(function(){this.selected=
|
|
||||||
c.inArray(c(this).val(),u)>=0});if(!u.length)this.selectedIndex=-1}else this.value=r}})}});c.extend({attrFn:{val:true,css:true,html:true,text:true,data:true,width:true,height:true,offset:true},attr:function(a,b,d,f){if(!a||a.nodeType===3||a.nodeType===8)return w;if(f&&b in c.attrFn)return c(a)[b](d);f=a.nodeType!==1||!c.isXMLDoc(a);var e=d!==w;b=f&&c.props[b]||b;if(a.nodeType===1){var j=$a.test(b);if(b in a&&f&&!j){if(e){b==="type"&&ab.test(a.nodeName)&&a.parentNode&&c.error("type property can't be changed");
|
|
||||||
a[b]=d}if(c.nodeName(a,"form")&&a.getAttributeNode(b))return a.getAttributeNode(b).nodeValue;if(b==="tabIndex")return(b=a.getAttributeNode("tabIndex"))&&b.specified?b.value:bb.test(a.nodeName)||cb.test(a.nodeName)&&a.href?0:w;return a[b]}if(!c.support.style&&f&&b==="style"){if(e)a.style.cssText=""+d;return a.style.cssText}e&&a.setAttribute(b,""+d);a=!c.support.hrefNormalized&&f&&j?a.getAttribute(b,2):a.getAttribute(b);return a===null?w:a}return c.style(a,b,d)}});var O=/\.(.*)$/,db=function(a){return a.replace(/[^\w\s\.\|`]/g,
|
|
||||||
function(b){return"\\"+b})};c.event={add:function(a,b,d,f){if(!(a.nodeType===3||a.nodeType===8)){if(a.setInterval&&a!==A&&!a.frameElement)a=A;var e,j;if(d.handler){e=d;d=e.handler}if(!d.guid)d.guid=c.guid++;if(j=c.data(a)){var i=j.events=j.events||{},o=j.handle;if(!o)j.handle=o=function(){return typeof c!=="undefined"&&!c.event.triggered?c.event.handle.apply(o.elem,arguments):w};o.elem=a;b=b.split(" ");for(var k,n=0,r;k=b[n++];){j=e?c.extend({},e):{handler:d,data:f};if(k.indexOf(".")>-1){r=k.split(".");
|
|
||||||
k=r.shift();j.namespace=r.slice(0).sort().join(".")}else{r=[];j.namespace=""}j.type=k;j.guid=d.guid;var u=i[k],z=c.event.special[k]||{};if(!u){u=i[k]=[];if(!z.setup||z.setup.call(a,f,r,o)===false)if(a.addEventListener)a.addEventListener(k,o,false);else a.attachEvent&&a.attachEvent("on"+k,o)}if(z.add){z.add.call(a,j);if(!j.handler.guid)j.handler.guid=d.guid}u.push(j);c.event.global[k]=true}a=null}}},global:{},remove:function(a,b,d,f){if(!(a.nodeType===3||a.nodeType===8)){var e,j=0,i,o,k,n,r,u,z=c.data(a),
|
|
||||||
C=z&&z.events;if(z&&C){if(b&&b.type){d=b.handler;b=b.type}if(!b||typeof b==="string"&&b.charAt(0)==="."){b=b||"";for(e in C)c.event.remove(a,e+b)}else{for(b=b.split(" ");e=b[j++];){n=e;i=e.indexOf(".")<0;o=[];if(!i){o=e.split(".");e=o.shift();k=new RegExp("(^|\\.)"+c.map(o.slice(0).sort(),db).join("\\.(?:.*\\.)?")+"(\\.|$)")}if(r=C[e])if(d){n=c.event.special[e]||{};for(B=f||0;B<r.length;B++){u=r[B];if(d.guid===u.guid){if(i||k.test(u.namespace)){f==null&&r.splice(B--,1);n.remove&&n.remove.call(a,u)}if(f!=
|
|
||||||
null)break}}if(r.length===0||f!=null&&r.length===1){if(!n.teardown||n.teardown.call(a,o)===false)Ca(a,e,z.handle);delete C[e]}}else for(var B=0;B<r.length;B++){u=r[B];if(i||k.test(u.namespace)){c.event.remove(a,n,u.handler,B);r.splice(B--,1)}}}if(c.isEmptyObject(C)){if(b=z.handle)b.elem=null;delete z.events;delete z.handle;c.isEmptyObject(z)&&c.removeData(a)}}}}},trigger:function(a,b,d,f){var e=a.type||a;if(!f){a=typeof a==="object"?a[G]?a:c.extend(c.Event(e),a):c.Event(e);if(e.indexOf("!")>=0){a.type=
|
|
||||||
e=e.slice(0,-1);a.exclusive=true}if(!d){a.stopPropagation();c.event.global[e]&&c.each(c.cache,function(){this.events&&this.events[e]&&c.event.trigger(a,b,this.handle.elem)})}if(!d||d.nodeType===3||d.nodeType===8)return w;a.result=w;a.target=d;b=c.makeArray(b);b.unshift(a)}a.currentTarget=d;(f=c.data(d,"handle"))&&f.apply(d,b);f=d.parentNode||d.ownerDocument;try{if(!(d&&d.nodeName&&c.noData[d.nodeName.toLowerCase()]))if(d["on"+e]&&d["on"+e].apply(d,b)===false)a.result=false}catch(j){}if(!a.isPropagationStopped()&&
|
|
||||||
f)c.event.trigger(a,b,f,true);else if(!a.isDefaultPrevented()){f=a.target;var i,o=c.nodeName(f,"a")&&e==="click",k=c.event.special[e]||{};if((!k._default||k._default.call(d,a)===false)&&!o&&!(f&&f.nodeName&&c.noData[f.nodeName.toLowerCase()])){try{if(f[e]){if(i=f["on"+e])f["on"+e]=null;c.event.triggered=true;f[e]()}}catch(n){}if(i)f["on"+e]=i;c.event.triggered=false}}},handle:function(a){var b,d,f,e;a=arguments[0]=c.event.fix(a||A.event);a.currentTarget=this;b=a.type.indexOf(".")<0&&!a.exclusive;
|
|
||||||
if(!b){d=a.type.split(".");a.type=d.shift();f=new RegExp("(^|\\.)"+d.slice(0).sort().join("\\.(?:.*\\.)?")+"(\\.|$)")}e=c.data(this,"events");d=e[a.type];if(e&&d){d=d.slice(0);e=0;for(var j=d.length;e<j;e++){var i=d[e];if(b||f.test(i.namespace)){a.handler=i.handler;a.data=i.data;a.handleObj=i;i=i.handler.apply(this,arguments);if(i!==w){a.result=i;if(i===false){a.preventDefault();a.stopPropagation()}}if(a.isImmediatePropagationStopped())break}}}return a.result},props:"altKey attrChange attrName bubbles button cancelable charCode clientX clientY ctrlKey currentTarget data detail eventPhase fromElement handler keyCode layerX layerY metaKey newValue offsetX offsetY originalTarget pageX pageY prevValue relatedNode relatedTarget screenX screenY shiftKey srcElement target toElement view wheelDelta which".split(" "),
|
|
||||||
fix:function(a){if(a[G])return a;var b=a;a=c.Event(b);for(var d=this.props.length,f;d;){f=this.props[--d];a[f]=b[f]}if(!a.target)a.target=a.srcElement||s;if(a.target.nodeType===3)a.target=a.target.parentNode;if(!a.relatedTarget&&a.fromElement)a.relatedTarget=a.fromElement===a.target?a.toElement:a.fromElement;if(a.pageX==null&&a.clientX!=null){b=s.documentElement;d=s.body;a.pageX=a.clientX+(b&&b.scrollLeft||d&&d.scrollLeft||0)-(b&&b.clientLeft||d&&d.clientLeft||0);a.pageY=a.clientY+(b&&b.scrollTop||
|
|
||||||
d&&d.scrollTop||0)-(b&&b.clientTop||d&&d.clientTop||0)}if(!a.which&&(a.charCode||a.charCode===0?a.charCode:a.keyCode))a.which=a.charCode||a.keyCode;if(!a.metaKey&&a.ctrlKey)a.metaKey=a.ctrlKey;if(!a.which&&a.button!==w)a.which=a.button&1?1:a.button&2?3:a.button&4?2:0;return a},guid:1E8,proxy:c.proxy,special:{ready:{setup:c.bindReady,teardown:c.noop},live:{add:function(a){c.event.add(this,a.origType,c.extend({},a,{handler:oa}))},remove:function(a){var b=true,d=a.origType.replace(O,"");c.each(c.data(this,
|
|
||||||
"events").live||[],function(){if(d===this.origType.replace(O,""))return b=false});b&&c.event.remove(this,a.origType,oa)}},beforeunload:{setup:function(a,b,d){if(this.setInterval)this.onbeforeunload=d;return false},teardown:function(a,b){if(this.onbeforeunload===b)this.onbeforeunload=null}}}};var Ca=s.removeEventListener?function(a,b,d){a.removeEventListener(b,d,false)}:function(a,b,d){a.detachEvent("on"+b,d)};c.Event=function(a){if(!this.preventDefault)return new c.Event(a);if(a&&a.type){this.originalEvent=
|
|
||||||
a;this.type=a.type}else this.type=a;this.timeStamp=J();this[G]=true};c.Event.prototype={preventDefault:function(){this.isDefaultPrevented=Z;var a=this.originalEvent;if(a){a.preventDefault&&a.preventDefault();a.returnValue=false}},stopPropagation:function(){this.isPropagationStopped=Z;var a=this.originalEvent;if(a){a.stopPropagation&&a.stopPropagation();a.cancelBubble=true}},stopImmediatePropagation:function(){this.isImmediatePropagationStopped=Z;this.stopPropagation()},isDefaultPrevented:Y,isPropagationStopped:Y,
|
|
||||||
isImmediatePropagationStopped:Y};var Da=function(a){var b=a.relatedTarget;try{for(;b&&b!==this;)b=b.parentNode;if(b!==this){a.type=a.data;c.event.handle.apply(this,arguments)}}catch(d){}},Ea=function(a){a.type=a.data;c.event.handle.apply(this,arguments)};c.each({mouseenter:"mouseover",mouseleave:"mouseout"},function(a,b){c.event.special[a]={setup:function(d){c.event.add(this,b,d&&d.selector?Ea:Da,a)},teardown:function(d){c.event.remove(this,b,d&&d.selector?Ea:Da)}}});if(!c.support.submitBubbles)c.event.special.submit=
|
|
||||||
{setup:function(){if(this.nodeName.toLowerCase()!=="form"){c.event.add(this,"click.specialSubmit",function(a){var b=a.target,d=b.type;if((d==="submit"||d==="image")&&c(b).closest("form").length)return na("submit",this,arguments)});c.event.add(this,"keypress.specialSubmit",function(a){var b=a.target,d=b.type;if((d==="text"||d==="password")&&c(b).closest("form").length&&a.keyCode===13)return na("submit",this,arguments)})}else return false},teardown:function(){c.event.remove(this,".specialSubmit")}};
|
|
||||||
if(!c.support.changeBubbles){var da=/textarea|input|select/i,ea,Fa=function(a){var b=a.type,d=a.value;if(b==="radio"||b==="checkbox")d=a.checked;else if(b==="select-multiple")d=a.selectedIndex>-1?c.map(a.options,function(f){return f.selected}).join("-"):"";else if(a.nodeName.toLowerCase()==="select")d=a.selectedIndex;return d},fa=function(a,b){var d=a.target,f,e;if(!(!da.test(d.nodeName)||d.readOnly)){f=c.data(d,"_change_data");e=Fa(d);if(a.type!=="focusout"||d.type!=="radio")c.data(d,"_change_data",
|
|
||||||
e);if(!(f===w||e===f))if(f!=null||e){a.type="change";return c.event.trigger(a,b,d)}}};c.event.special.change={filters:{focusout:fa,click:function(a){var b=a.target,d=b.type;if(d==="radio"||d==="checkbox"||b.nodeName.toLowerCase()==="select")return fa.call(this,a)},keydown:function(a){var b=a.target,d=b.type;if(a.keyCode===13&&b.nodeName.toLowerCase()!=="textarea"||a.keyCode===32&&(d==="checkbox"||d==="radio")||d==="select-multiple")return fa.call(this,a)},beforeactivate:function(a){a=a.target;c.data(a,
|
|
||||||
"_change_data",Fa(a))}},setup:function(){if(this.type==="file")return false;for(var a in ea)c.event.add(this,a+".specialChange",ea[a]);return da.test(this.nodeName)},teardown:function(){c.event.remove(this,".specialChange");return da.test(this.nodeName)}};ea=c.event.special.change.filters}s.addEventListener&&c.each({focus:"focusin",blur:"focusout"},function(a,b){function d(f){f=c.event.fix(f);f.type=b;return c.event.handle.call(this,f)}c.event.special[b]={setup:function(){this.addEventListener(a,
|
|
||||||
d,true)},teardown:function(){this.removeEventListener(a,d,true)}}});c.each(["bind","one"],function(a,b){c.fn[b]=function(d,f,e){if(typeof d==="object"){for(var j in d)this[b](j,f,d[j],e);return this}if(c.isFunction(f)){e=f;f=w}var i=b==="one"?c.proxy(e,function(k){c(this).unbind(k,i);return e.apply(this,arguments)}):e;if(d==="unload"&&b!=="one")this.one(d,f,e);else{j=0;for(var o=this.length;j<o;j++)c.event.add(this[j],d,i,f)}return this}});c.fn.extend({unbind:function(a,b){if(typeof a==="object"&&
|
|
||||||
!a.preventDefault)for(var d in a)this.unbind(d,a[d]);else{d=0;for(var f=this.length;d<f;d++)c.event.remove(this[d],a,b)}return this},delegate:function(a,b,d,f){return this.live(b,d,f,a)},undelegate:function(a,b,d){return arguments.length===0?this.unbind("live"):this.die(b,null,d,a)},trigger:function(a,b){return this.each(function(){c.event.trigger(a,b,this)})},triggerHandler:function(a,b){if(this[0]){a=c.Event(a);a.preventDefault();a.stopPropagation();c.event.trigger(a,b,this[0]);return a.result}},
|
|
||||||
toggle:function(a){for(var b=arguments,d=1;d<b.length;)c.proxy(a,b[d++]);return this.click(c.proxy(a,function(f){var e=(c.data(this,"lastToggle"+a.guid)||0)%d;c.data(this,"lastToggle"+a.guid,e+1);f.preventDefault();return b[e].apply(this,arguments)||false}))},hover:function(a,b){return this.mouseenter(a).mouseleave(b||a)}});var Ga={focus:"focusin",blur:"focusout",mouseenter:"mouseover",mouseleave:"mouseout"};c.each(["live","die"],function(a,b){c.fn[b]=function(d,f,e,j){var i,o=0,k,n,r=j||this.selector,
|
|
||||||
u=j?this:c(this.context);if(c.isFunction(f)){e=f;f=w}for(d=(d||"").split(" ");(i=d[o++])!=null;){j=O.exec(i);k="";if(j){k=j[0];i=i.replace(O,"")}if(i==="hover")d.push("mouseenter"+k,"mouseleave"+k);else{n=i;if(i==="focus"||i==="blur"){d.push(Ga[i]+k);i+=k}else i=(Ga[i]||i)+k;b==="live"?u.each(function(){c.event.add(this,pa(i,r),{data:f,selector:r,handler:e,origType:i,origHandler:e,preType:n})}):u.unbind(pa(i,r),e)}}return this}});c.each("blur focus focusin focusout load resize scroll unload click dblclick mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave change select submit keydown keypress keyup error".split(" "),
|
|
||||||
function(a,b){c.fn[b]=function(d){return d?this.bind(b,d):this.trigger(b)};if(c.attrFn)c.attrFn[b]=true});A.attachEvent&&!A.addEventListener&&A.attachEvent("onunload",function(){for(var a in c.cache)if(c.cache[a].handle)try{c.event.remove(c.cache[a].handle.elem)}catch(b){}});(function(){function a(g){for(var h="",l,m=0;g[m];m++){l=g[m];if(l.nodeType===3||l.nodeType===4)h+=l.nodeValue;else if(l.nodeType!==8)h+=a(l.childNodes)}return h}function b(g,h,l,m,q,p){q=0;for(var v=m.length;q<v;q++){var t=m[q];
|
|
||||||
if(t){t=t[g];for(var y=false;t;){if(t.sizcache===l){y=m[t.sizset];break}if(t.nodeType===1&&!p){t.sizcache=l;t.sizset=q}if(t.nodeName.toLowerCase()===h){y=t;break}t=t[g]}m[q]=y}}}function d(g,h,l,m,q,p){q=0;for(var v=m.length;q<v;q++){var t=m[q];if(t){t=t[g];for(var y=false;t;){if(t.sizcache===l){y=m[t.sizset];break}if(t.nodeType===1){if(!p){t.sizcache=l;t.sizset=q}if(typeof h!=="string"){if(t===h){y=true;break}}else if(k.filter(h,[t]).length>0){y=t;break}}t=t[g]}m[q]=y}}}var f=/((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^[\]]*\]|['"][^'"]*['"]|[^[\]'"]+)+\]|\\.|[^ >+~,(\[\\]+)+|[>+~])(\s*,\s*)?((?:.|\r|\n)*)/g,
|
|
||||||
e=0,j=Object.prototype.toString,i=false,o=true;[0,0].sort(function(){o=false;return 0});var k=function(g,h,l,m){l=l||[];var q=h=h||s;if(h.nodeType!==1&&h.nodeType!==9)return[];if(!g||typeof g!=="string")return l;for(var p=[],v,t,y,S,H=true,M=x(h),I=g;(f.exec(""),v=f.exec(I))!==null;){I=v[3];p.push(v[1]);if(v[2]){S=v[3];break}}if(p.length>1&&r.exec(g))if(p.length===2&&n.relative[p[0]])t=ga(p[0]+p[1],h);else for(t=n.relative[p[0]]?[h]:k(p.shift(),h);p.length;){g=p.shift();if(n.relative[g])g+=p.shift();
|
|
||||||
t=ga(g,t)}else{if(!m&&p.length>1&&h.nodeType===9&&!M&&n.match.ID.test(p[0])&&!n.match.ID.test(p[p.length-1])){v=k.find(p.shift(),h,M);h=v.expr?k.filter(v.expr,v.set)[0]:v.set[0]}if(h){v=m?{expr:p.pop(),set:z(m)}:k.find(p.pop(),p.length===1&&(p[0]==="~"||p[0]==="+")&&h.parentNode?h.parentNode:h,M);t=v.expr?k.filter(v.expr,v.set):v.set;if(p.length>0)y=z(t);else H=false;for(;p.length;){var D=p.pop();v=D;if(n.relative[D])v=p.pop();else D="";if(v==null)v=h;n.relative[D](y,v,M)}}else y=[]}y||(y=t);y||k.error(D||
|
|
||||||
g);if(j.call(y)==="[object Array]")if(H)if(h&&h.nodeType===1)for(g=0;y[g]!=null;g++){if(y[g]&&(y[g]===true||y[g].nodeType===1&&E(h,y[g])))l.push(t[g])}else for(g=0;y[g]!=null;g++)y[g]&&y[g].nodeType===1&&l.push(t[g]);else l.push.apply(l,y);else z(y,l);if(S){k(S,q,l,m);k.uniqueSort(l)}return l};k.uniqueSort=function(g){if(B){i=o;g.sort(B);if(i)for(var h=1;h<g.length;h++)g[h]===g[h-1]&&g.splice(h--,1)}return g};k.matches=function(g,h){return k(g,null,null,h)};k.find=function(g,h,l){var m,q;if(!g)return[];
|
|
||||||
for(var p=0,v=n.order.length;p<v;p++){var t=n.order[p];if(q=n.leftMatch[t].exec(g)){var y=q[1];q.splice(1,1);if(y.substr(y.length-1)!=="\\"){q[1]=(q[1]||"").replace(/\\/g,"");m=n.find[t](q,h,l);if(m!=null){g=g.replace(n.match[t],"");break}}}}m||(m=h.getElementsByTagName("*"));return{set:m,expr:g}};k.filter=function(g,h,l,m){for(var q=g,p=[],v=h,t,y,S=h&&h[0]&&x(h[0]);g&&h.length;){for(var H in n.filter)if((t=n.leftMatch[H].exec(g))!=null&&t[2]){var M=n.filter[H],I,D;D=t[1];y=false;t.splice(1,1);if(D.substr(D.length-
|
|
||||||
1)!=="\\"){if(v===p)p=[];if(n.preFilter[H])if(t=n.preFilter[H](t,v,l,p,m,S)){if(t===true)continue}else y=I=true;if(t)for(var U=0;(D=v[U])!=null;U++)if(D){I=M(D,t,U,v);var Ha=m^!!I;if(l&&I!=null)if(Ha)y=true;else v[U]=false;else if(Ha){p.push(D);y=true}}if(I!==w){l||(v=p);g=g.replace(n.match[H],"");if(!y)return[];break}}}if(g===q)if(y==null)k.error(g);else break;q=g}return v};k.error=function(g){throw"Syntax error, unrecognized expression: "+g;};var n=k.selectors={order:["ID","NAME","TAG"],match:{ID:/#((?:[\w\u00c0-\uFFFF-]|\\.)+)/,
|
|
||||||
CLASS:/\.((?:[\w\u00c0-\uFFFF-]|\\.)+)/,NAME:/\[name=['"]*((?:[\w\u00c0-\uFFFF-]|\\.)+)['"]*\]/,ATTR:/\[\s*((?:[\w\u00c0-\uFFFF-]|\\.)+)\s*(?:(\S?=)\s*(['"]*)(.*?)\3|)\s*\]/,TAG:/^((?:[\w\u00c0-\uFFFF\*-]|\\.)+)/,CHILD:/:(only|nth|last|first)-child(?:\((even|odd|[\dn+-]*)\))?/,POS:/:(nth|eq|gt|lt|first|last|even|odd)(?:\((\d*)\))?(?=[^-]|$)/,PSEUDO:/:((?:[\w\u00c0-\uFFFF-]|\\.)+)(?:\((['"]?)((?:\([^\)]+\)|[^\(\)]*)+)\2\))?/},leftMatch:{},attrMap:{"class":"className","for":"htmlFor"},attrHandle:{href:function(g){return g.getAttribute("href")}},
|
|
||||||
relative:{"+":function(g,h){var l=typeof h==="string",m=l&&!/\W/.test(h);l=l&&!m;if(m)h=h.toLowerCase();m=0;for(var q=g.length,p;m<q;m++)if(p=g[m]){for(;(p=p.previousSibling)&&p.nodeType!==1;);g[m]=l||p&&p.nodeName.toLowerCase()===h?p||false:p===h}l&&k.filter(h,g,true)},">":function(g,h){var l=typeof h==="string";if(l&&!/\W/.test(h)){h=h.toLowerCase();for(var m=0,q=g.length;m<q;m++){var p=g[m];if(p){l=p.parentNode;g[m]=l.nodeName.toLowerCase()===h?l:false}}}else{m=0;for(q=g.length;m<q;m++)if(p=g[m])g[m]=
|
|
||||||
l?p.parentNode:p.parentNode===h;l&&k.filter(h,g,true)}},"":function(g,h,l){var m=e++,q=d;if(typeof h==="string"&&!/\W/.test(h)){var p=h=h.toLowerCase();q=b}q("parentNode",h,m,g,p,l)},"~":function(g,h,l){var m=e++,q=d;if(typeof h==="string"&&!/\W/.test(h)){var p=h=h.toLowerCase();q=b}q("previousSibling",h,m,g,p,l)}},find:{ID:function(g,h,l){if(typeof h.getElementById!=="undefined"&&!l)return(g=h.getElementById(g[1]))?[g]:[]},NAME:function(g,h){if(typeof h.getElementsByName!=="undefined"){var l=[];
|
|
||||||
h=h.getElementsByName(g[1]);for(var m=0,q=h.length;m<q;m++)h[m].getAttribute("name")===g[1]&&l.push(h[m]);return l.length===0?null:l}},TAG:function(g,h){return h.getElementsByTagName(g[1])}},preFilter:{CLASS:function(g,h,l,m,q,p){g=" "+g[1].replace(/\\/g,"")+" ";if(p)return g;p=0;for(var v;(v=h[p])!=null;p++)if(v)if(q^(v.className&&(" "+v.className+" ").replace(/[\t\n]/g," ").indexOf(g)>=0))l||m.push(v);else if(l)h[p]=false;return false},ID:function(g){return g[1].replace(/\\/g,"")},TAG:function(g){return g[1].toLowerCase()},
|
|
||||||
CHILD:function(g){if(g[1]==="nth"){var h=/(-?)(\d*)n((?:\+|-)?\d*)/.exec(g[2]==="even"&&"2n"||g[2]==="odd"&&"2n+1"||!/\D/.test(g[2])&&"0n+"+g[2]||g[2]);g[2]=h[1]+(h[2]||1)-0;g[3]=h[3]-0}g[0]=e++;return g},ATTR:function(g,h,l,m,q,p){h=g[1].replace(/\\/g,"");if(!p&&n.attrMap[h])g[1]=n.attrMap[h];if(g[2]==="~=")g[4]=" "+g[4]+" ";return g},PSEUDO:function(g,h,l,m,q){if(g[1]==="not")if((f.exec(g[3])||"").length>1||/^\w/.test(g[3]))g[3]=k(g[3],null,null,h);else{g=k.filter(g[3],h,l,true^q);l||m.push.apply(m,
|
|
||||||
g);return false}else if(n.match.POS.test(g[0])||n.match.CHILD.test(g[0]))return true;return g},POS:function(g){g.unshift(true);return g}},filters:{enabled:function(g){return g.disabled===false&&g.type!=="hidden"},disabled:function(g){return g.disabled===true},checked:function(g){return g.checked===true},selected:function(g){return g.selected===true},parent:function(g){return!!g.firstChild},empty:function(g){return!g.firstChild},has:function(g,h,l){return!!k(l[3],g).length},header:function(g){return/h\d/i.test(g.nodeName)},
|
|
||||||
text:function(g){return"text"===g.type},radio:function(g){return"radio"===g.type},checkbox:function(g){return"checkbox"===g.type},file:function(g){return"file"===g.type},password:function(g){return"password"===g.type},submit:function(g){return"submit"===g.type},image:function(g){return"image"===g.type},reset:function(g){return"reset"===g.type},button:function(g){return"button"===g.type||g.nodeName.toLowerCase()==="button"},input:function(g){return/input|select|textarea|button/i.test(g.nodeName)}},
|
|
||||||
setFilters:{first:function(g,h){return h===0},last:function(g,h,l,m){return h===m.length-1},even:function(g,h){return h%2===0},odd:function(g,h){return h%2===1},lt:function(g,h,l){return h<l[3]-0},gt:function(g,h,l){return h>l[3]-0},nth:function(g,h,l){return l[3]-0===h},eq:function(g,h,l){return l[3]-0===h}},filter:{PSEUDO:function(g,h,l,m){var q=h[1],p=n.filters[q];if(p)return p(g,l,h,m);else if(q==="contains")return(g.textContent||g.innerText||a([g])||"").indexOf(h[3])>=0;else if(q==="not"){h=
|
|
||||||
h[3];l=0;for(m=h.length;l<m;l++)if(h[l]===g)return false;return true}else k.error("Syntax error, unrecognized expression: "+q)},CHILD:function(g,h){var l=h[1],m=g;switch(l){case "only":case "first":for(;m=m.previousSibling;)if(m.nodeType===1)return false;if(l==="first")return true;m=g;case "last":for(;m=m.nextSibling;)if(m.nodeType===1)return false;return true;case "nth":l=h[2];var q=h[3];if(l===1&&q===0)return true;h=h[0];var p=g.parentNode;if(p&&(p.sizcache!==h||!g.nodeIndex)){var v=0;for(m=p.firstChild;m;m=
|
|
||||||
m.nextSibling)if(m.nodeType===1)m.nodeIndex=++v;p.sizcache=h}g=g.nodeIndex-q;return l===0?g===0:g%l===0&&g/l>=0}},ID:function(g,h){return g.nodeType===1&&g.getAttribute("id")===h},TAG:function(g,h){return h==="*"&&g.nodeType===1||g.nodeName.toLowerCase()===h},CLASS:function(g,h){return(" "+(g.className||g.getAttribute("class"))+" ").indexOf(h)>-1},ATTR:function(g,h){var l=h[1];g=n.attrHandle[l]?n.attrHandle[l](g):g[l]!=null?g[l]:g.getAttribute(l);l=g+"";var m=h[2];h=h[4];return g==null?m==="!=":m===
|
|
||||||
"="?l===h:m==="*="?l.indexOf(h)>=0:m==="~="?(" "+l+" ").indexOf(h)>=0:!h?l&&g!==false:m==="!="?l!==h:m==="^="?l.indexOf(h)===0:m==="$="?l.substr(l.length-h.length)===h:m==="|="?l===h||l.substr(0,h.length+1)===h+"-":false},POS:function(g,h,l,m){var q=n.setFilters[h[2]];if(q)return q(g,l,h,m)}}},r=n.match.POS;for(var u in n.match){n.match[u]=new RegExp(n.match[u].source+/(?![^\[]*\])(?![^\(]*\))/.source);n.leftMatch[u]=new RegExp(/(^(?:.|\r|\n)*?)/.source+n.match[u].source.replace(/\\(\d+)/g,function(g,
|
|
||||||
h){return"\\"+(h-0+1)}))}var z=function(g,h){g=Array.prototype.slice.call(g,0);if(h){h.push.apply(h,g);return h}return g};try{Array.prototype.slice.call(s.documentElement.childNodes,0)}catch(C){z=function(g,h){h=h||[];if(j.call(g)==="[object Array]")Array.prototype.push.apply(h,g);else if(typeof g.length==="number")for(var l=0,m=g.length;l<m;l++)h.push(g[l]);else for(l=0;g[l];l++)h.push(g[l]);return h}}var B;if(s.documentElement.compareDocumentPosition)B=function(g,h){if(!g.compareDocumentPosition||
|
|
||||||
!h.compareDocumentPosition){if(g==h)i=true;return g.compareDocumentPosition?-1:1}g=g.compareDocumentPosition(h)&4?-1:g===h?0:1;if(g===0)i=true;return g};else if("sourceIndex"in s.documentElement)B=function(g,h){if(!g.sourceIndex||!h.sourceIndex){if(g==h)i=true;return g.sourceIndex?-1:1}g=g.sourceIndex-h.sourceIndex;if(g===0)i=true;return g};else if(s.createRange)B=function(g,h){if(!g.ownerDocument||!h.ownerDocument){if(g==h)i=true;return g.ownerDocument?-1:1}var l=g.ownerDocument.createRange(),m=
|
|
||||||
h.ownerDocument.createRange();l.setStart(g,0);l.setEnd(g,0);m.setStart(h,0);m.setEnd(h,0);g=l.compareBoundaryPoints(Range.START_TO_END,m);if(g===0)i=true;return g};(function(){var g=s.createElement("div"),h="script"+(new Date).getTime();g.innerHTML="<a name='"+h+"'/>";var l=s.documentElement;l.insertBefore(g,l.firstChild);if(s.getElementById(h)){n.find.ID=function(m,q,p){if(typeof q.getElementById!=="undefined"&&!p)return(q=q.getElementById(m[1]))?q.id===m[1]||typeof q.getAttributeNode!=="undefined"&&
|
|
||||||
q.getAttributeNode("id").nodeValue===m[1]?[q]:w:[]};n.filter.ID=function(m,q){var p=typeof m.getAttributeNode!=="undefined"&&m.getAttributeNode("id");return m.nodeType===1&&p&&p.nodeValue===q}}l.removeChild(g);l=g=null})();(function(){var g=s.createElement("div");g.appendChild(s.createComment(""));if(g.getElementsByTagName("*").length>0)n.find.TAG=function(h,l){l=l.getElementsByTagName(h[1]);if(h[1]==="*"){h=[];for(var m=0;l[m];m++)l[m].nodeType===1&&h.push(l[m]);l=h}return l};g.innerHTML="<a href='#'></a>";
|
|
||||||
if(g.firstChild&&typeof g.firstChild.getAttribute!=="undefined"&&g.firstChild.getAttribute("href")!=="#")n.attrHandle.href=function(h){return h.getAttribute("href",2)};g=null})();s.querySelectorAll&&function(){var g=k,h=s.createElement("div");h.innerHTML="<p class='TEST'></p>";if(!(h.querySelectorAll&&h.querySelectorAll(".TEST").length===0)){k=function(m,q,p,v){q=q||s;if(!v&&q.nodeType===9&&!x(q))try{return z(q.querySelectorAll(m),p)}catch(t){}return g(m,q,p,v)};for(var l in g)k[l]=g[l];h=null}}();
|
|
||||||
(function(){var g=s.createElement("div");g.innerHTML="<div class='test e'></div><div class='test'></div>";if(!(!g.getElementsByClassName||g.getElementsByClassName("e").length===0)){g.lastChild.className="e";if(g.getElementsByClassName("e").length!==1){n.order.splice(1,0,"CLASS");n.find.CLASS=function(h,l,m){if(typeof l.getElementsByClassName!=="undefined"&&!m)return l.getElementsByClassName(h[1])};g=null}}})();var E=s.compareDocumentPosition?function(g,h){return!!(g.compareDocumentPosition(h)&16)}:
|
|
||||||
function(g,h){return g!==h&&(g.contains?g.contains(h):true)},x=function(g){return(g=(g?g.ownerDocument||g:0).documentElement)?g.nodeName!=="HTML":false},ga=function(g,h){var l=[],m="",q;for(h=h.nodeType?[h]:h;q=n.match.PSEUDO.exec(g);){m+=q[0];g=g.replace(n.match.PSEUDO,"")}g=n.relative[g]?g+"*":g;q=0;for(var p=h.length;q<p;q++)k(g,h[q],l);return k.filter(m,l)};c.find=k;c.expr=k.selectors;c.expr[":"]=c.expr.filters;c.unique=k.uniqueSort;c.text=a;c.isXMLDoc=x;c.contains=E})();var eb=/Until$/,fb=/^(?:parents|prevUntil|prevAll)/,
|
|
||||||
gb=/,/;R=Array.prototype.slice;var Ia=function(a,b,d){if(c.isFunction(b))return c.grep(a,function(e,j){return!!b.call(e,j,e)===d});else if(b.nodeType)return c.grep(a,function(e){return e===b===d});else if(typeof b==="string"){var f=c.grep(a,function(e){return e.nodeType===1});if(Ua.test(b))return c.filter(b,f,!d);else b=c.filter(b,f)}return c.grep(a,function(e){return c.inArray(e,b)>=0===d})};c.fn.extend({find:function(a){for(var b=this.pushStack("","find",a),d=0,f=0,e=this.length;f<e;f++){d=b.length;
|
|
||||||
c.find(a,this[f],b);if(f>0)for(var j=d;j<b.length;j++)for(var i=0;i<d;i++)if(b[i]===b[j]){b.splice(j--,1);break}}return b},has:function(a){var b=c(a);return this.filter(function(){for(var d=0,f=b.length;d<f;d++)if(c.contains(this,b[d]))return true})},not:function(a){return this.pushStack(Ia(this,a,false),"not",a)},filter:function(a){return this.pushStack(Ia(this,a,true),"filter",a)},is:function(a){return!!a&&c.filter(a,this).length>0},closest:function(a,b){if(c.isArray(a)){var d=[],f=this[0],e,j=
|
|
||||||
{},i;if(f&&a.length){e=0;for(var o=a.length;e<o;e++){i=a[e];j[i]||(j[i]=c.expr.match.POS.test(i)?c(i,b||this.context):i)}for(;f&&f.ownerDocument&&f!==b;){for(i in j){e=j[i];if(e.jquery?e.index(f)>-1:c(f).is(e)){d.push({selector:i,elem:f});delete j[i]}}f=f.parentNode}}return d}var k=c.expr.match.POS.test(a)?c(a,b||this.context):null;return this.map(function(n,r){for(;r&&r.ownerDocument&&r!==b;){if(k?k.index(r)>-1:c(r).is(a))return r;r=r.parentNode}return null})},index:function(a){if(!a||typeof a===
|
|
||||||
"string")return c.inArray(this[0],a?c(a):this.parent().children());return c.inArray(a.jquery?a[0]:a,this)},add:function(a,b){a=typeof a==="string"?c(a,b||this.context):c.makeArray(a);b=c.merge(this.get(),a);return this.pushStack(qa(a[0])||qa(b[0])?b:c.unique(b))},andSelf:function(){return this.add(this.prevObject)}});c.each({parent:function(a){return(a=a.parentNode)&&a.nodeType!==11?a:null},parents:function(a){return c.dir(a,"parentNode")},parentsUntil:function(a,b,d){return c.dir(a,"parentNode",
|
|
||||||
d)},next:function(a){return c.nth(a,2,"nextSibling")},prev:function(a){return c.nth(a,2,"previousSibling")},nextAll:function(a){return c.dir(a,"nextSibling")},prevAll:function(a){return c.dir(a,"previousSibling")},nextUntil:function(a,b,d){return c.dir(a,"nextSibling",d)},prevUntil:function(a,b,d){return c.dir(a,"previousSibling",d)},siblings:function(a){return c.sibling(a.parentNode.firstChild,a)},children:function(a){return c.sibling(a.firstChild)},contents:function(a){return c.nodeName(a,"iframe")?
|
|
||||||
a.contentDocument||a.contentWindow.document:c.makeArray(a.childNodes)}},function(a,b){c.fn[a]=function(d,f){var e=c.map(this,b,d);eb.test(a)||(f=d);if(f&&typeof f==="string")e=c.filter(f,e);e=this.length>1?c.unique(e):e;if((this.length>1||gb.test(f))&&fb.test(a))e=e.reverse();return this.pushStack(e,a,R.call(arguments).join(","))}});c.extend({filter:function(a,b,d){if(d)a=":not("+a+")";return c.find.matches(a,b)},dir:function(a,b,d){var f=[];for(a=a[b];a&&a.nodeType!==9&&(d===w||a.nodeType!==1||!c(a).is(d));){a.nodeType===
|
|
||||||
1&&f.push(a);a=a[b]}return f},nth:function(a,b,d){b=b||1;for(var f=0;a;a=a[d])if(a.nodeType===1&&++f===b)break;return a},sibling:function(a,b){for(var d=[];a;a=a.nextSibling)a.nodeType===1&&a!==b&&d.push(a);return d}});var Ja=/ jQuery\d+="(?:\d+|null)"/g,V=/^\s+/,Ka=/(<([\w:]+)[^>]*?)\/>/g,hb=/^(?:area|br|col|embed|hr|img|input|link|meta|param)$/i,La=/<([\w:]+)/,ib=/<tbody/i,jb=/<|&#?\w+;/,ta=/<script|<object|<embed|<option|<style/i,ua=/checked\s*(?:[^=]|=\s*.checked.)/i,Ma=function(a,b,d){return hb.test(d)?
|
|
||||||
a:b+"></"+d+">"},F={option:[1,"<select multiple='multiple'>","</select>"],legend:[1,"<fieldset>","</fieldset>"],thead:[1,"<table>","</table>"],tr:[2,"<table><tbody>","</tbody></table>"],td:[3,"<table><tbody><tr>","</tr></tbody></table>"],col:[2,"<table><tbody></tbody><colgroup>","</colgroup></table>"],area:[1,"<map>","</map>"],_default:[0,"",""]};F.optgroup=F.option;F.tbody=F.tfoot=F.colgroup=F.caption=F.thead;F.th=F.td;if(!c.support.htmlSerialize)F._default=[1,"div<div>","</div>"];c.fn.extend({text:function(a){if(c.isFunction(a))return this.each(function(b){var d=
|
|
||||||
c(this);d.text(a.call(this,b,d.text()))});if(typeof a!=="object"&&a!==w)return this.empty().append((this[0]&&this[0].ownerDocument||s).createTextNode(a));return c.text(this)},wrapAll:function(a){if(c.isFunction(a))return this.each(function(d){c(this).wrapAll(a.call(this,d))});if(this[0]){var b=c(a,this[0].ownerDocument).eq(0).clone(true);this[0].parentNode&&b.insertBefore(this[0]);b.map(function(){for(var d=this;d.firstChild&&d.firstChild.nodeType===1;)d=d.firstChild;return d}).append(this)}return this},
|
|
||||||
wrapInner:function(a){if(c.isFunction(a))return this.each(function(b){c(this).wrapInner(a.call(this,b))});return this.each(function(){var b=c(this),d=b.contents();d.length?d.wrapAll(a):b.append(a)})},wrap:function(a){return this.each(function(){c(this).wrapAll(a)})},unwrap:function(){return this.parent().each(function(){c.nodeName(this,"body")||c(this).replaceWith(this.childNodes)}).end()},append:function(){return this.domManip(arguments,true,function(a){this.nodeType===1&&this.appendChild(a)})},
|
|
||||||
prepend:function(){return this.domManip(arguments,true,function(a){this.nodeType===1&&this.insertBefore(a,this.firstChild)})},before:function(){if(this[0]&&this[0].parentNode)return this.domManip(arguments,false,function(b){this.parentNode.insertBefore(b,this)});else if(arguments.length){var a=c(arguments[0]);a.push.apply(a,this.toArray());return this.pushStack(a,"before",arguments)}},after:function(){if(this[0]&&this[0].parentNode)return this.domManip(arguments,false,function(b){this.parentNode.insertBefore(b,
|
|
||||||
this.nextSibling)});else if(arguments.length){var a=this.pushStack(this,"after",arguments);a.push.apply(a,c(arguments[0]).toArray());return a}},remove:function(a,b){for(var d=0,f;(f=this[d])!=null;d++)if(!a||c.filter(a,[f]).length){if(!b&&f.nodeType===1){c.cleanData(f.getElementsByTagName("*"));c.cleanData([f])}f.parentNode&&f.parentNode.removeChild(f)}return this},empty:function(){for(var a=0,b;(b=this[a])!=null;a++)for(b.nodeType===1&&c.cleanData(b.getElementsByTagName("*"));b.firstChild;)b.removeChild(b.firstChild);
|
|
||||||
return this},clone:function(a){var b=this.map(function(){if(!c.support.noCloneEvent&&!c.isXMLDoc(this)){var d=this.outerHTML,f=this.ownerDocument;if(!d){d=f.createElement("div");d.appendChild(this.cloneNode(true));d=d.innerHTML}return c.clean([d.replace(Ja,"").replace(/=([^="'>\s]+\/)>/g,'="$1">').replace(V,"")],f)[0]}else return this.cloneNode(true)});if(a===true){ra(this,b);ra(this.find("*"),b.find("*"))}return b},html:function(a){if(a===w)return this[0]&&this[0].nodeType===1?this[0].innerHTML.replace(Ja,
|
|
||||||
""):null;else if(typeof a==="string"&&!ta.test(a)&&(c.support.leadingWhitespace||!V.test(a))&&!F[(La.exec(a)||["",""])[1].toLowerCase()]){a=a.replace(Ka,Ma);try{for(var b=0,d=this.length;b<d;b++)if(this[b].nodeType===1){c.cleanData(this[b].getElementsByTagName("*"));this[b].innerHTML=a}}catch(f){this.empty().append(a)}}else c.isFunction(a)?this.each(function(e){var j=c(this),i=j.html();j.empty().append(function(){return a.call(this,e,i)})}):this.empty().append(a);return this},replaceWith:function(a){if(this[0]&&
|
|
||||||
this[0].parentNode){if(c.isFunction(a))return this.each(function(b){var d=c(this),f=d.html();d.replaceWith(a.call(this,b,f))});if(typeof a!=="string")a=c(a).detach();return this.each(function(){var b=this.nextSibling,d=this.parentNode;c(this).remove();b?c(b).before(a):c(d).append(a)})}else return this.pushStack(c(c.isFunction(a)?a():a),"replaceWith",a)},detach:function(a){return this.remove(a,true)},domManip:function(a,b,d){function f(u){return c.nodeName(u,"table")?u.getElementsByTagName("tbody")[0]||
|
|
||||||
u.appendChild(u.ownerDocument.createElement("tbody")):u}var e,j,i=a[0],o=[],k;if(!c.support.checkClone&&arguments.length===3&&typeof i==="string"&&ua.test(i))return this.each(function(){c(this).domManip(a,b,d,true)});if(c.isFunction(i))return this.each(function(u){var z=c(this);a[0]=i.call(this,u,b?z.html():w);z.domManip(a,b,d)});if(this[0]){e=i&&i.parentNode;e=c.support.parentNode&&e&&e.nodeType===11&&e.childNodes.length===this.length?{fragment:e}:sa(a,this,o);k=e.fragment;if(j=k.childNodes.length===
|
|
||||||
1?(k=k.firstChild):k.firstChild){b=b&&c.nodeName(j,"tr");for(var n=0,r=this.length;n<r;n++)d.call(b?f(this[n],j):this[n],n>0||e.cacheable||this.length>1?k.cloneNode(true):k)}o.length&&c.each(o,Qa)}return this}});c.fragments={};c.each({appendTo:"append",prependTo:"prepend",insertBefore:"before",insertAfter:"after",replaceAll:"replaceWith"},function(a,b){c.fn[a]=function(d){var f=[];d=c(d);var e=this.length===1&&this[0].parentNode;if(e&&e.nodeType===11&&e.childNodes.length===1&&d.length===1){d[b](this[0]);
|
|
||||||
return this}else{e=0;for(var j=d.length;e<j;e++){var i=(e>0?this.clone(true):this).get();c.fn[b].apply(c(d[e]),i);f=f.concat(i)}return this.pushStack(f,a,d.selector)}}});c.extend({clean:function(a,b,d,f){b=b||s;if(typeof b.createElement==="undefined")b=b.ownerDocument||b[0]&&b[0].ownerDocument||s;for(var e=[],j=0,i;(i=a[j])!=null;j++){if(typeof i==="number")i+="";if(i){if(typeof i==="string"&&!jb.test(i))i=b.createTextNode(i);else if(typeof i==="string"){i=i.replace(Ka,Ma);var o=(La.exec(i)||["",
|
|
||||||
""])[1].toLowerCase(),k=F[o]||F._default,n=k[0],r=b.createElement("div");for(r.innerHTML=k[1]+i+k[2];n--;)r=r.lastChild;if(!c.support.tbody){n=ib.test(i);o=o==="table"&&!n?r.firstChild&&r.firstChild.childNodes:k[1]==="<table>"&&!n?r.childNodes:[];for(k=o.length-1;k>=0;--k)c.nodeName(o[k],"tbody")&&!o[k].childNodes.length&&o[k].parentNode.removeChild(o[k])}!c.support.leadingWhitespace&&V.test(i)&&r.insertBefore(b.createTextNode(V.exec(i)[0]),r.firstChild);i=r.childNodes}if(i.nodeType)e.push(i);else e=
|
|
||||||
c.merge(e,i)}}if(d)for(j=0;e[j];j++)if(f&&c.nodeName(e[j],"script")&&(!e[j].type||e[j].type.toLowerCase()==="text/javascript"))f.push(e[j].parentNode?e[j].parentNode.removeChild(e[j]):e[j]);else{e[j].nodeType===1&&e.splice.apply(e,[j+1,0].concat(c.makeArray(e[j].getElementsByTagName("script"))));d.appendChild(e[j])}return e},cleanData:function(a){for(var b,d,f=c.cache,e=c.event.special,j=c.support.deleteExpando,i=0,o;(o=a[i])!=null;i++)if(d=o[c.expando]){b=f[d];if(b.events)for(var k in b.events)e[k]?
|
|
||||||
c.event.remove(o,k):Ca(o,k,b.handle);if(j)delete o[c.expando];else o.removeAttribute&&o.removeAttribute(c.expando);delete f[d]}}});var kb=/z-?index|font-?weight|opacity|zoom|line-?height/i,Na=/alpha\([^)]*\)/,Oa=/opacity=([^)]*)/,ha=/float/i,ia=/-([a-z])/ig,lb=/([A-Z])/g,mb=/^-?\d+(?:px)?$/i,nb=/^-?\d/,ob={position:"absolute",visibility:"hidden",display:"block"},pb=["Left","Right"],qb=["Top","Bottom"],rb=s.defaultView&&s.defaultView.getComputedStyle,Pa=c.support.cssFloat?"cssFloat":"styleFloat",ja=
|
|
||||||
function(a,b){return b.toUpperCase()};c.fn.css=function(a,b){return X(this,a,b,true,function(d,f,e){if(e===w)return c.curCSS(d,f);if(typeof e==="number"&&!kb.test(f))e+="px";c.style(d,f,e)})};c.extend({style:function(a,b,d){if(!a||a.nodeType===3||a.nodeType===8)return w;if((b==="width"||b==="height")&&parseFloat(d)<0)d=w;var f=a.style||a,e=d!==w;if(!c.support.opacity&&b==="opacity"){if(e){f.zoom=1;b=parseInt(d,10)+""==="NaN"?"":"alpha(opacity="+d*100+")";a=f.filter||c.curCSS(a,"filter")||"";f.filter=
|
|
||||||
Na.test(a)?a.replace(Na,b):b}return f.filter&&f.filter.indexOf("opacity=")>=0?parseFloat(Oa.exec(f.filter)[1])/100+"":""}if(ha.test(b))b=Pa;b=b.replace(ia,ja);if(e)f[b]=d;return f[b]},css:function(a,b,d,f){if(b==="width"||b==="height"){var e,j=b==="width"?pb:qb;function i(){e=b==="width"?a.offsetWidth:a.offsetHeight;f!=="border"&&c.each(j,function(){f||(e-=parseFloat(c.curCSS(a,"padding"+this,true))||0);if(f==="margin")e+=parseFloat(c.curCSS(a,"margin"+this,true))||0;else e-=parseFloat(c.curCSS(a,
|
|
||||||
"border"+this+"Width",true))||0})}a.offsetWidth!==0?i():c.swap(a,ob,i);return Math.max(0,Math.round(e))}return c.curCSS(a,b,d)},curCSS:function(a,b,d){var f,e=a.style;if(!c.support.opacity&&b==="opacity"&&a.currentStyle){f=Oa.test(a.currentStyle.filter||"")?parseFloat(RegExp.$1)/100+"":"";return f===""?"1":f}if(ha.test(b))b=Pa;if(!d&&e&&e[b])f=e[b];else if(rb){if(ha.test(b))b="float";b=b.replace(lb,"-$1").toLowerCase();e=a.ownerDocument.defaultView;if(!e)return null;if(a=e.getComputedStyle(a,null))f=
|
|
||||||
a.getPropertyValue(b);if(b==="opacity"&&f==="")f="1"}else if(a.currentStyle){d=b.replace(ia,ja);f=a.currentStyle[b]||a.currentStyle[d];if(!mb.test(f)&&nb.test(f)){b=e.left;var j=a.runtimeStyle.left;a.runtimeStyle.left=a.currentStyle.left;e.left=d==="fontSize"?"1em":f||0;f=e.pixelLeft+"px";e.left=b;a.runtimeStyle.left=j}}return f},swap:function(a,b,d){var f={};for(var e in b){f[e]=a.style[e];a.style[e]=b[e]}d.call(a);for(e in b)a.style[e]=f[e]}});if(c.expr&&c.expr.filters){c.expr.filters.hidden=function(a){var b=
|
|
||||||
a.offsetWidth,d=a.offsetHeight,f=a.nodeName.toLowerCase()==="tr";return b===0&&d===0&&!f?true:b>0&&d>0&&!f?false:c.curCSS(a,"display")==="none"};c.expr.filters.visible=function(a){return!c.expr.filters.hidden(a)}}var sb=J(),tb=/<script(.|\s)*?\/script>/gi,ub=/select|textarea/i,vb=/color|date|datetime|email|hidden|month|number|password|range|search|tel|text|time|url|week/i,N=/=\?(&|$)/,ka=/\?/,wb=/(\?|&)_=.*?(&|$)/,xb=/^(\w+:)?\/\/([^\/?#]+)/,yb=/%20/g,zb=c.fn.load;c.fn.extend({load:function(a,b,d){if(typeof a!==
|
|
||||||
"string")return zb.call(this,a);else if(!this.length)return this;var f=a.indexOf(" ");if(f>=0){var e=a.slice(f,a.length);a=a.slice(0,f)}f="GET";if(b)if(c.isFunction(b)){d=b;b=null}else if(typeof b==="object"){b=c.param(b,c.ajaxSettings.traditional);f="POST"}var j=this;c.ajax({url:a,type:f,dataType:"html",data:b,complete:function(i,o){if(o==="success"||o==="notmodified")j.html(e?c("<div />").append(i.responseText.replace(tb,"")).find(e):i.responseText);d&&j.each(d,[i.responseText,o,i])}});return this},
|
|
||||||
serialize:function(){return c.param(this.serializeArray())},serializeArray:function(){return this.map(function(){return this.elements?c.makeArray(this.elements):this}).filter(function(){return this.name&&!this.disabled&&(this.checked||ub.test(this.nodeName)||vb.test(this.type))}).map(function(a,b){a=c(this).val();return a==null?null:c.isArray(a)?c.map(a,function(d){return{name:b.name,value:d}}):{name:b.name,value:a}}).get()}});c.each("ajaxStart ajaxStop ajaxComplete ajaxError ajaxSuccess ajaxSend".split(" "),
|
|
||||||
function(a,b){c.fn[b]=function(d){return this.bind(b,d)}});c.extend({get:function(a,b,d,f){if(c.isFunction(b)){f=f||d;d=b;b=null}return c.ajax({type:"GET",url:a,data:b,success:d,dataType:f})},getScript:function(a,b){return c.get(a,null,b,"script")},getJSON:function(a,b,d){return c.get(a,b,d,"json")},post:function(a,b,d,f){if(c.isFunction(b)){f=f||d;d=b;b={}}return c.ajax({type:"POST",url:a,data:b,success:d,dataType:f})},ajaxSetup:function(a){c.extend(c.ajaxSettings,a)},ajaxSettings:{url:location.href,
|
|
||||||
global:true,type:"GET",contentType:"application/x-www-form-urlencoded",processData:true,async:true,xhr:A.XMLHttpRequest&&(A.location.protocol!=="file:"||!A.ActiveXObject)?function(){return new A.XMLHttpRequest}:function(){try{return new A.ActiveXObject("Microsoft.XMLHTTP")}catch(a){}},accepts:{xml:"application/xml, text/xml",html:"text/html",script:"text/javascript, application/javascript",json:"application/json, text/javascript",text:"text/plain",_default:"*/*"}},lastModified:{},etag:{},ajax:function(a){function b(){e.success&&
|
|
||||||
e.success.call(k,o,i,x);e.global&&f("ajaxSuccess",[x,e])}function d(){e.complete&&e.complete.call(k,x,i);e.global&&f("ajaxComplete",[x,e]);e.global&&!--c.active&&c.event.trigger("ajaxStop")}function f(q,p){(e.context?c(e.context):c.event).trigger(q,p)}var e=c.extend(true,{},c.ajaxSettings,a),j,i,o,k=a&&a.context||e,n=e.type.toUpperCase();if(e.data&&e.processData&&typeof e.data!=="string")e.data=c.param(e.data,e.traditional);if(e.dataType==="jsonp"){if(n==="GET")N.test(e.url)||(e.url+=(ka.test(e.url)?
|
|
||||||
"&":"?")+(e.jsonp||"callback")+"=?");else if(!e.data||!N.test(e.data))e.data=(e.data?e.data+"&":"")+(e.jsonp||"callback")+"=?";e.dataType="json"}if(e.dataType==="json"&&(e.data&&N.test(e.data)||N.test(e.url))){j=e.jsonpCallback||"jsonp"+sb++;if(e.data)e.data=(e.data+"").replace(N,"="+j+"$1");e.url=e.url.replace(N,"="+j+"$1");e.dataType="script";A[j]=A[j]||function(q){o=q;b();d();A[j]=w;try{delete A[j]}catch(p){}z&&z.removeChild(C)}}if(e.dataType==="script"&&e.cache===null)e.cache=false;if(e.cache===
|
|
||||||
false&&n==="GET"){var r=J(),u=e.url.replace(wb,"$1_="+r+"$2");e.url=u+(u===e.url?(ka.test(e.url)?"&":"?")+"_="+r:"")}if(e.data&&n==="GET")e.url+=(ka.test(e.url)?"&":"?")+e.data;e.global&&!c.active++&&c.event.trigger("ajaxStart");r=(r=xb.exec(e.url))&&(r[1]&&r[1]!==location.protocol||r[2]!==location.host);if(e.dataType==="script"&&n==="GET"&&r){var z=s.getElementsByTagName("head")[0]||s.documentElement,C=s.createElement("script");C.src=e.url;if(e.scriptCharset)C.charset=e.scriptCharset;if(!j){var B=
|
|
||||||
false;C.onload=C.onreadystatechange=function(){if(!B&&(!this.readyState||this.readyState==="loaded"||this.readyState==="complete")){B=true;b();d();C.onload=C.onreadystatechange=null;z&&C.parentNode&&z.removeChild(C)}}}z.insertBefore(C,z.firstChild);return w}var E=false,x=e.xhr();if(x){e.username?x.open(n,e.url,e.async,e.username,e.password):x.open(n,e.url,e.async);try{if(e.data||a&&a.contentType)x.setRequestHeader("Content-Type",e.contentType);if(e.ifModified){c.lastModified[e.url]&&x.setRequestHeader("If-Modified-Since",
|
|
||||||
c.lastModified[e.url]);c.etag[e.url]&&x.setRequestHeader("If-None-Match",c.etag[e.url])}r||x.setRequestHeader("X-Requested-With","XMLHttpRequest");x.setRequestHeader("Accept",e.dataType&&e.accepts[e.dataType]?e.accepts[e.dataType]+", */*":e.accepts._default)}catch(ga){}if(e.beforeSend&&e.beforeSend.call(k,x,e)===false){e.global&&!--c.active&&c.event.trigger("ajaxStop");x.abort();return false}e.global&&f("ajaxSend",[x,e]);var g=x.onreadystatechange=function(q){if(!x||x.readyState===0||q==="abort"){E||
|
|
||||||
d();E=true;if(x)x.onreadystatechange=c.noop}else if(!E&&x&&(x.readyState===4||q==="timeout")){E=true;x.onreadystatechange=c.noop;i=q==="timeout"?"timeout":!c.httpSuccess(x)?"error":e.ifModified&&c.httpNotModified(x,e.url)?"notmodified":"success";var p;if(i==="success")try{o=c.httpData(x,e.dataType,e)}catch(v){i="parsererror";p=v}if(i==="success"||i==="notmodified")j||b();else c.handleError(e,x,i,p);d();q==="timeout"&&x.abort();if(e.async)x=null}};try{var h=x.abort;x.abort=function(){x&&h.call(x);
|
|
||||||
g("abort")}}catch(l){}e.async&&e.timeout>0&&setTimeout(function(){x&&!E&&g("timeout")},e.timeout);try{x.send(n==="POST"||n==="PUT"||n==="DELETE"?e.data:null)}catch(m){c.handleError(e,x,null,m);d()}e.async||g();return x}},handleError:function(a,b,d,f){if(a.error)a.error.call(a.context||a,b,d,f);if(a.global)(a.context?c(a.context):c.event).trigger("ajaxError",[b,a,f])},active:0,httpSuccess:function(a){try{return!a.status&&location.protocol==="file:"||a.status>=200&&a.status<300||a.status===304||a.status===
|
|
||||||
1223||a.status===0}catch(b){}return false},httpNotModified:function(a,b){var d=a.getResponseHeader("Last-Modified"),f=a.getResponseHeader("Etag");if(d)c.lastModified[b]=d;if(f)c.etag[b]=f;return a.status===304||a.status===0},httpData:function(a,b,d){var f=a.getResponseHeader("content-type")||"",e=b==="xml"||!b&&f.indexOf("xml")>=0;a=e?a.responseXML:a.responseText;e&&a.documentElement.nodeName==="parsererror"&&c.error("parsererror");if(d&&d.dataFilter)a=d.dataFilter(a,b);if(typeof a==="string")if(b===
|
|
||||||
"json"||!b&&f.indexOf("json")>=0)a=c.parseJSON(a);else if(b==="script"||!b&&f.indexOf("javascript")>=0)c.globalEval(a);return a},param:function(a,b){function d(i,o){if(c.isArray(o))c.each(o,function(k,n){b||/\[\]$/.test(i)?f(i,n):d(i+"["+(typeof n==="object"||c.isArray(n)?k:"")+"]",n)});else!b&&o!=null&&typeof o==="object"?c.each(o,function(k,n){d(i+"["+k+"]",n)}):f(i,o)}function f(i,o){o=c.isFunction(o)?o():o;e[e.length]=encodeURIComponent(i)+"="+encodeURIComponent(o)}var e=[];if(b===w)b=c.ajaxSettings.traditional;
|
|
||||||
if(c.isArray(a)||a.jquery)c.each(a,function(){f(this.name,this.value)});else for(var j in a)d(j,a[j]);return e.join("&").replace(yb,"+")}});var la={},Ab=/toggle|show|hide/,Bb=/^([+-]=)?([\d+-.]+)(.*)$/,W,va=[["height","marginTop","marginBottom","paddingTop","paddingBottom"],["width","marginLeft","marginRight","paddingLeft","paddingRight"],["opacity"]];c.fn.extend({show:function(a,b){if(a||a===0)return this.animate(K("show",3),a,b);else{a=0;for(b=this.length;a<b;a++){var d=c.data(this[a],"olddisplay");
|
|
||||||
this[a].style.display=d||"";if(c.css(this[a],"display")==="none"){d=this[a].nodeName;var f;if(la[d])f=la[d];else{var e=c("<"+d+" />").appendTo("body");f=e.css("display");if(f==="none")f="block";e.remove();la[d]=f}c.data(this[a],"olddisplay",f)}}a=0;for(b=this.length;a<b;a++)this[a].style.display=c.data(this[a],"olddisplay")||"";return this}},hide:function(a,b){if(a||a===0)return this.animate(K("hide",3),a,b);else{a=0;for(b=this.length;a<b;a++){var d=c.data(this[a],"olddisplay");!d&&d!=="none"&&c.data(this[a],
|
|
||||||
"olddisplay",c.css(this[a],"display"))}a=0;for(b=this.length;a<b;a++)this[a].style.display="none";return this}},_toggle:c.fn.toggle,toggle:function(a,b){var d=typeof a==="boolean";if(c.isFunction(a)&&c.isFunction(b))this._toggle.apply(this,arguments);else a==null||d?this.each(function(){var f=d?a:c(this).is(":hidden");c(this)[f?"show":"hide"]()}):this.animate(K("toggle",3),a,b);return this},fadeTo:function(a,b,d){return this.filter(":hidden").css("opacity",0).show().end().animate({opacity:b},a,d)},
|
|
||||||
animate:function(a,b,d,f){var e=c.speed(b,d,f);if(c.isEmptyObject(a))return this.each(e.complete);return this[e.queue===false?"each":"queue"](function(){var j=c.extend({},e),i,o=this.nodeType===1&&c(this).is(":hidden"),k=this;for(i in a){var n=i.replace(ia,ja);if(i!==n){a[n]=a[i];delete a[i];i=n}if(a[i]==="hide"&&o||a[i]==="show"&&!o)return j.complete.call(this);if((i==="height"||i==="width")&&this.style){j.display=c.css(this,"display");j.overflow=this.style.overflow}if(c.isArray(a[i])){(j.specialEasing=
|
|
||||||
j.specialEasing||{})[i]=a[i][1];a[i]=a[i][0]}}if(j.overflow!=null)this.style.overflow="hidden";j.curAnim=c.extend({},a);c.each(a,function(r,u){var z=new c.fx(k,j,r);if(Ab.test(u))z[u==="toggle"?o?"show":"hide":u](a);else{var C=Bb.exec(u),B=z.cur(true)||0;if(C){u=parseFloat(C[2]);var E=C[3]||"px";if(E!=="px"){k.style[r]=(u||1)+E;B=(u||1)/z.cur(true)*B;k.style[r]=B+E}if(C[1])u=(C[1]==="-="?-1:1)*u+B;z.custom(B,u,E)}else z.custom(B,u,"")}});return true})},stop:function(a,b){var d=c.timers;a&&this.queue([]);
|
|
||||||
this.each(function(){for(var f=d.length-1;f>=0;f--)if(d[f].elem===this){b&&d[f](true);d.splice(f,1)}});b||this.dequeue();return this}});c.each({slideDown:K("show",1),slideUp:K("hide",1),slideToggle:K("toggle",1),fadeIn:{opacity:"show"},fadeOut:{opacity:"hide"}},function(a,b){c.fn[a]=function(d,f){return this.animate(b,d,f)}});c.extend({speed:function(a,b,d){var f=a&&typeof a==="object"?a:{complete:d||!d&&b||c.isFunction(a)&&a,duration:a,easing:d&&b||b&&!c.isFunction(b)&&b};f.duration=c.fx.off?0:typeof f.duration===
|
|
||||||
"number"?f.duration:c.fx.speeds[f.duration]||c.fx.speeds._default;f.old=f.complete;f.complete=function(){f.queue!==false&&c(this).dequeue();c.isFunction(f.old)&&f.old.call(this)};return f},easing:{linear:function(a,b,d,f){return d+f*a},swing:function(a,b,d,f){return(-Math.cos(a*Math.PI)/2+0.5)*f+d}},timers:[],fx:function(a,b,d){this.options=b;this.elem=a;this.prop=d;if(!b.orig)b.orig={}}});c.fx.prototype={update:function(){this.options.step&&this.options.step.call(this.elem,this.now,this);(c.fx.step[this.prop]||
|
|
||||||
c.fx.step._default)(this);if((this.prop==="height"||this.prop==="width")&&this.elem.style)this.elem.style.display="block"},cur:function(a){if(this.elem[this.prop]!=null&&(!this.elem.style||this.elem.style[this.prop]==null))return this.elem[this.prop];return(a=parseFloat(c.css(this.elem,this.prop,a)))&&a>-10000?a:parseFloat(c.curCSS(this.elem,this.prop))||0},custom:function(a,b,d){function f(j){return e.step(j)}this.startTime=J();this.start=a;this.end=b;this.unit=d||this.unit||"px";this.now=this.start;
|
|
||||||
this.pos=this.state=0;var e=this;f.elem=this.elem;if(f()&&c.timers.push(f)&&!W)W=setInterval(c.fx.tick,13)},show:function(){this.options.orig[this.prop]=c.style(this.elem,this.prop);this.options.show=true;this.custom(this.prop==="width"||this.prop==="height"?1:0,this.cur());c(this.elem).show()},hide:function(){this.options.orig[this.prop]=c.style(this.elem,this.prop);this.options.hide=true;this.custom(this.cur(),0)},step:function(a){var b=J(),d=true;if(a||b>=this.options.duration+this.startTime){this.now=
|
|
||||||
this.end;this.pos=this.state=1;this.update();this.options.curAnim[this.prop]=true;for(var f in this.options.curAnim)if(this.options.curAnim[f]!==true)d=false;if(d){if(this.options.display!=null){this.elem.style.overflow=this.options.overflow;a=c.data(this.elem,"olddisplay");this.elem.style.display=a?a:this.options.display;if(c.css(this.elem,"display")==="none")this.elem.style.display="block"}this.options.hide&&c(this.elem).hide();if(this.options.hide||this.options.show)for(var e in this.options.curAnim)c.style(this.elem,
|
|
||||||
e,this.options.orig[e]);this.options.complete.call(this.elem)}return false}else{e=b-this.startTime;this.state=e/this.options.duration;a=this.options.easing||(c.easing.swing?"swing":"linear");this.pos=c.easing[this.options.specialEasing&&this.options.specialEasing[this.prop]||a](this.state,e,0,1,this.options.duration);this.now=this.start+(this.end-this.start)*this.pos;this.update()}return true}};c.extend(c.fx,{tick:function(){for(var a=c.timers,b=0;b<a.length;b++)a[b]()||a.splice(b--,1);a.length||
|
|
||||||
c.fx.stop()},stop:function(){clearInterval(W);W=null},speeds:{slow:600,fast:200,_default:400},step:{opacity:function(a){c.style(a.elem,"opacity",a.now)},_default:function(a){if(a.elem.style&&a.elem.style[a.prop]!=null)a.elem.style[a.prop]=(a.prop==="width"||a.prop==="height"?Math.max(0,a.now):a.now)+a.unit;else a.elem[a.prop]=a.now}}});if(c.expr&&c.expr.filters)c.expr.filters.animated=function(a){return c.grep(c.timers,function(b){return a===b.elem}).length};c.fn.offset="getBoundingClientRect"in s.documentElement?
|
|
||||||
function(a){var b=this[0];if(a)return this.each(function(e){c.offset.setOffset(this,a,e)});if(!b||!b.ownerDocument)return null;if(b===b.ownerDocument.body)return c.offset.bodyOffset(b);var d=b.getBoundingClientRect(),f=b.ownerDocument;b=f.body;f=f.documentElement;return{top:d.top+(self.pageYOffset||c.support.boxModel&&f.scrollTop||b.scrollTop)-(f.clientTop||b.clientTop||0),left:d.left+(self.pageXOffset||c.support.boxModel&&f.scrollLeft||b.scrollLeft)-(f.clientLeft||b.clientLeft||0)}}:function(a){var b=
|
|
||||||
this[0];if(a)return this.each(function(r){c.offset.setOffset(this,a,r)});if(!b||!b.ownerDocument)return null;if(b===b.ownerDocument.body)return c.offset.bodyOffset(b);c.offset.initialize();var d=b.offsetParent,f=b,e=b.ownerDocument,j,i=e.documentElement,o=e.body;f=(e=e.defaultView)?e.getComputedStyle(b,null):b.currentStyle;for(var k=b.offsetTop,n=b.offsetLeft;(b=b.parentNode)&&b!==o&&b!==i;){if(c.offset.supportsFixedPosition&&f.position==="fixed")break;j=e?e.getComputedStyle(b,null):b.currentStyle;
|
|
||||||
k-=b.scrollTop;n-=b.scrollLeft;if(b===d){k+=b.offsetTop;n+=b.offsetLeft;if(c.offset.doesNotAddBorder&&!(c.offset.doesAddBorderForTableAndCells&&/^t(able|d|h)$/i.test(b.nodeName))){k+=parseFloat(j.borderTopWidth)||0;n+=parseFloat(j.borderLeftWidth)||0}f=d;d=b.offsetParent}if(c.offset.subtractsBorderForOverflowNotVisible&&j.overflow!=="visible"){k+=parseFloat(j.borderTopWidth)||0;n+=parseFloat(j.borderLeftWidth)||0}f=j}if(f.position==="relative"||f.position==="static"){k+=o.offsetTop;n+=o.offsetLeft}if(c.offset.supportsFixedPosition&&
|
|
||||||
f.position==="fixed"){k+=Math.max(i.scrollTop,o.scrollTop);n+=Math.max(i.scrollLeft,o.scrollLeft)}return{top:k,left:n}};c.offset={initialize:function(){var a=s.body,b=s.createElement("div"),d,f,e,j=parseFloat(c.curCSS(a,"marginTop",true))||0;c.extend(b.style,{position:"absolute",top:0,left:0,margin:0,border:0,width:"1px",height:"1px",visibility:"hidden"});b.innerHTML="<div style='position:absolute;top:0;left:0;margin:0;border:5px solid #000;padding:0;width:1px;height:1px;'><div></div></div><table style='position:absolute;top:0;left:0;margin:0;border:5px solid #000;padding:0;width:1px;height:1px;' cellpadding='0' cellspacing='0'><tr><td></td></tr></table>";
|
|
||||||
a.insertBefore(b,a.firstChild);d=b.firstChild;f=d.firstChild;e=d.nextSibling.firstChild.firstChild;this.doesNotAddBorder=f.offsetTop!==5;this.doesAddBorderForTableAndCells=e.offsetTop===5;f.style.position="fixed";f.style.top="20px";this.supportsFixedPosition=f.offsetTop===20||f.offsetTop===15;f.style.position=f.style.top="";d.style.overflow="hidden";d.style.position="relative";this.subtractsBorderForOverflowNotVisible=f.offsetTop===-5;this.doesNotIncludeMarginInBodyOffset=a.offsetTop!==j;a.removeChild(b);
|
|
||||||
c.offset.initialize=c.noop},bodyOffset:function(a){var b=a.offsetTop,d=a.offsetLeft;c.offset.initialize();if(c.offset.doesNotIncludeMarginInBodyOffset){b+=parseFloat(c.curCSS(a,"marginTop",true))||0;d+=parseFloat(c.curCSS(a,"marginLeft",true))||0}return{top:b,left:d}},setOffset:function(a,b,d){if(/static/.test(c.curCSS(a,"position")))a.style.position="relative";var f=c(a),e=f.offset(),j=parseInt(c.curCSS(a,"top",true),10)||0,i=parseInt(c.curCSS(a,"left",true),10)||0;if(c.isFunction(b))b=b.call(a,
|
|
||||||
d,e);d={top:b.top-e.top+j,left:b.left-e.left+i};"using"in b?b.using.call(a,d):f.css(d)}};c.fn.extend({position:function(){if(!this[0])return null;var a=this[0],b=this.offsetParent(),d=this.offset(),f=/^body|html$/i.test(b[0].nodeName)?{top:0,left:0}:b.offset();d.top-=parseFloat(c.curCSS(a,"marginTop",true))||0;d.left-=parseFloat(c.curCSS(a,"marginLeft",true))||0;f.top+=parseFloat(c.curCSS(b[0],"borderTopWidth",true))||0;f.left+=parseFloat(c.curCSS(b[0],"borderLeftWidth",true))||0;return{top:d.top-
|
|
||||||
f.top,left:d.left-f.left}},offsetParent:function(){return this.map(function(){for(var a=this.offsetParent||s.body;a&&!/^body|html$/i.test(a.nodeName)&&c.css(a,"position")==="static";)a=a.offsetParent;return a})}});c.each(["Left","Top"],function(a,b){var d="scroll"+b;c.fn[d]=function(f){var e=this[0],j;if(!e)return null;if(f!==w)return this.each(function(){if(j=wa(this))j.scrollTo(!a?f:c(j).scrollLeft(),a?f:c(j).scrollTop());else this[d]=f});else return(j=wa(e))?"pageXOffset"in j?j[a?"pageYOffset":
|
|
||||||
"pageXOffset"]:c.support.boxModel&&j.document.documentElement[d]||j.document.body[d]:e[d]}});c.each(["Height","Width"],function(a,b){var d=b.toLowerCase();c.fn["inner"+b]=function(){return this[0]?c.css(this[0],d,false,"padding"):null};c.fn["outer"+b]=function(f){return this[0]?c.css(this[0],d,false,f?"margin":"border"):null};c.fn[d]=function(f){var e=this[0];if(!e)return f==null?null:this;if(c.isFunction(f))return this.each(function(j){var i=c(this);i[d](f.call(this,j,i[d]()))});return"scrollTo"in
|
|
||||||
e&&e.document?e.document.compatMode==="CSS1Compat"&&e.document.documentElement["client"+b]||e.document.body["client"+b]:e.nodeType===9?Math.max(e.documentElement["client"+b],e.body["scroll"+b],e.documentElement["scroll"+b],e.body["offset"+b],e.documentElement["offset"+b]):f===w?c.css(e,d):this.css(d,typeof f==="string"?f:f+"px")}});A.jQuery=A.$=c})(window);
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
|
||||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
||||||
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" dir="ltr">
|
|
||||||
<!-- This file is part of the Mongoose project,
|
|
||||||
http://code.google.com/p/mongoose -->
|
|
||||||
<head>
|
|
||||||
<title>Mongoose chat: login</title>
|
|
||||||
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
|
|
||||||
<!--
|
|
||||||
Note that this page is self-sufficient, it does not load any other
|
|
||||||
CSS or Javascript file. This is done so because only this page is
|
|
||||||
allowed for non-authorized users. If we want to load other files
|
|
||||||
from the frontend, we need to change backend code to allow those
|
|
||||||
for non-authorized users. See chat.c :: must_authorize() function.
|
|
||||||
-->
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
window.onload = function() {
|
|
||||||
// Set correct action for the login form. We assume that the SSL port
|
|
||||||
// is the next one to insecure one.
|
|
||||||
var httpsPort = location.protocol.match(/https/) ? location.port :
|
|
||||||
parseInt(location.port) + 1;
|
|
||||||
document.forms[0].action = 'https://' + location.hostname + ':' +
|
|
||||||
httpsPort + '/authorize';
|
|
||||||
};
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<center>
|
|
||||||
<h2>Mongoose chat server login</h2>
|
|
||||||
<div style="max-width: 30em;">
|
|
||||||
Username and password can be any non-empty strings.
|
|
||||||
</div>
|
|
||||||
<br/>
|
|
||||||
<form>
|
|
||||||
<input type="text" name="user"></input><br/>
|
|
||||||
<input type="text" name="password"></input><br/>
|
|
||||||
<input type="submit" value="Login"></input>
|
|
||||||
</form>
|
|
||||||
</center>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 1.6 KiB |
@@ -1,106 +0,0 @@
|
|||||||
// This file is part of Mongoose project, http://code.google.com/p/mongoose
|
|
||||||
|
|
||||||
var chat = {
|
|
||||||
// Backend URL, string.
|
|
||||||
// 'http://backend.address.com' or '' if backend is the same as frontend
|
|
||||||
backendUrl: '',
|
|
||||||
maxVisibleMessages: 10,
|
|
||||||
errorMessageFadeOutTimeoutMs: 2000,
|
|
||||||
errorMessageFadeOutTimer: null,
|
|
||||||
lastMessageId: 0,
|
|
||||||
getMessagesIntervalMs: 1000,
|
|
||||||
};
|
|
||||||
|
|
||||||
chat.normalizeText = function(text) {
|
|
||||||
return text.replace('<', '<').replace('>', '>');
|
|
||||||
};
|
|
||||||
|
|
||||||
chat.refresh = function(data) {
|
|
||||||
|
|
||||||
if (data === undefined) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$.each(data, function(index, entry) {
|
|
||||||
var row = $('<div>').addClass('message-row').appendTo('#mml');
|
|
||||||
var timestamp = (new Date(entry.timestamp * 1000)).toLocaleTimeString();
|
|
||||||
$('<span>')
|
|
||||||
.addClass('message-timestamp')
|
|
||||||
.html('[' + timestamp + ']')
|
|
||||||
.prependTo(row);
|
|
||||||
$('<span>')
|
|
||||||
.addClass('message-user')
|
|
||||||
.addClass(entry.user ? '' : 'message-user-server')
|
|
||||||
.html(chat.normalizeText((entry.user || '[server]') + ':'))
|
|
||||||
.appendTo(row);
|
|
||||||
$('<span>')
|
|
||||||
.addClass('message-text')
|
|
||||||
.addClass(entry.user ? '' : 'message-text-server')
|
|
||||||
.html(chat.normalizeText(entry.text))
|
|
||||||
.appendTo(row);
|
|
||||||
chat.lastMessageId = Math.max(chat.lastMessageId, entry.id) + 1;
|
|
||||||
});
|
|
||||||
|
|
||||||
// Keep only chat.maxVisibleMessages, delete older ones.
|
|
||||||
while ($('#mml').children().length > chat.maxVisibleMessages) {
|
|
||||||
$('#mml div:first-child').remove();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
chat.getMessages = function(enter_loop) {
|
|
||||||
$.ajax({
|
|
||||||
dataType: 'jsonp',
|
|
||||||
url: chat.backendUrl + '/ajax/get_messages',
|
|
||||||
data: {last_id: chat.lastMessageId},
|
|
||||||
success: chat.refresh,
|
|
||||||
error: function() {
|
|
||||||
},
|
|
||||||
});
|
|
||||||
if (enter_loop) {
|
|
||||||
window.setTimeout('chat.getMessages(true)', chat.getMessagesIntervalMs);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
chat.handleMenuItemClick = function(ev) {
|
|
||||||
$('.menu-item').removeClass('menu-item-selected'); // Deselect menu buttons
|
|
||||||
$(this).addClass('menu-item-selected'); // Select clicked button
|
|
||||||
$('.main').addClass('hidden'); // Hide all main windows
|
|
||||||
$('#' + $(this).attr('name')).removeClass('hidden'); // Show main window
|
|
||||||
};
|
|
||||||
|
|
||||||
chat.showError = function(message) {
|
|
||||||
$('#error').html(message).fadeIn('fast');
|
|
||||||
window.clearTimeout(chat.errorMessageFadeOutTimer);
|
|
||||||
chat.errorMessageFadeOutTimer = window.setTimeout(function() {
|
|
||||||
$('#error').fadeOut('slow');
|
|
||||||
}, chat.errorMessageFadeOutTimeoutMs);
|
|
||||||
};
|
|
||||||
|
|
||||||
chat.handleMessageInput = function(ev) {
|
|
||||||
var input = ev.target;
|
|
||||||
if (ev.keyCode != 13 || !input.value)
|
|
||||||
return;
|
|
||||||
//input.disabled = true;
|
|
||||||
$.ajax({
|
|
||||||
dataType: 'jsonp',
|
|
||||||
url: chat.backendUrl + '/ajax/send_message',
|
|
||||||
data: {text: input.value},
|
|
||||||
success: function(ev) {
|
|
||||||
input.value = '';
|
|
||||||
input.disabled = false;
|
|
||||||
chat.getMessages(false);
|
|
||||||
},
|
|
||||||
error: function(ev) {
|
|
||||||
chat.showError('Error sending message');
|
|
||||||
input.disabled = false;
|
|
||||||
},
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
$(document).ready(function() {
|
|
||||||
$('.menu-item').click(chat.handleMenuItemClick);
|
|
||||||
$('.message-input').keypress(chat.handleMessageInput);
|
|
||||||
chat.getMessages(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
// vim:ts=2:sw=2:et
|
|
||||||
@@ -1,154 +0,0 @@
|
|||||||
/*
|
|
||||||
* vim:ts=2:sw=2:et:ai
|
|
||||||
*/
|
|
||||||
|
|
||||||
body {
|
|
||||||
font: 13px Arial; margin: 0.5em 1em;
|
|
||||||
}
|
|
||||||
|
|
||||||
#logo {
|
|
||||||
background: url('logo.png') no-repeat ;
|
|
||||||
width: 160px;
|
|
||||||
height: 40px;
|
|
||||||
float: left;
|
|
||||||
}
|
|
||||||
|
|
||||||
td {
|
|
||||||
text-align: left;
|
|
||||||
}
|
|
||||||
|
|
||||||
#motd {
|
|
||||||
margin-left: 170px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.infobox {
|
|
||||||
background: #eed;
|
|
||||||
padding: 1px 1em;
|
|
||||||
}
|
|
||||||
|
|
||||||
.help-message {
|
|
||||||
color: #aaa;
|
|
||||||
}
|
|
||||||
|
|
||||||
#middle {
|
|
||||||
margin: 0.5em 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
#error {
|
|
||||||
background: #c44;
|
|
||||||
color: white;
|
|
||||||
font-weight: bold;
|
|
||||||
}
|
|
||||||
|
|
||||||
#content, .menu-item-selected, .chat-title, .chat-content {
|
|
||||||
background: #c3d9ff;
|
|
||||||
}
|
|
||||||
|
|
||||||
#content {
|
|
||||||
overflow: hidden;
|
|
||||||
min-height: 7em;
|
|
||||||
padding: 1em;
|
|
||||||
}
|
|
||||||
|
|
||||||
.chat-title {
|
|
||||||
padding: 1px 1ex;
|
|
||||||
}
|
|
||||||
|
|
||||||
.chat-content {
|
|
||||||
padding: 1ex;
|
|
||||||
}
|
|
||||||
|
|
||||||
.chat-window {
|
|
||||||
}
|
|
||||||
|
|
||||||
.message-row {
|
|
||||||
margin: 2px;
|
|
||||||
border-bottom: 1px solid #bbb;
|
|
||||||
}
|
|
||||||
|
|
||||||
.message-timestamp {
|
|
||||||
color: #484;
|
|
||||||
}
|
|
||||||
|
|
||||||
.message-user {
|
|
||||||
margin-left: 0.5em;
|
|
||||||
font-weight: bold;
|
|
||||||
}
|
|
||||||
|
|
||||||
.message-text {
|
|
||||||
margin-left: 0.5em;
|
|
||||||
}
|
|
||||||
|
|
||||||
.message-user-server {
|
|
||||||
color: purple;
|
|
||||||
}
|
|
||||||
|
|
||||||
.message-text-server {
|
|
||||||
font-style: italic;
|
|
||||||
}
|
|
||||||
|
|
||||||
.main {
|
|
||||||
padding: 0.5em;
|
|
||||||
background: #f0fcff;
|
|
||||||
}
|
|
||||||
|
|
||||||
#menu {
|
|
||||||
margin-top: 1em;
|
|
||||||
min-width: 7em;
|
|
||||||
float: left;
|
|
||||||
}
|
|
||||||
|
|
||||||
#footer {
|
|
||||||
position: fixed;
|
|
||||||
bottom: 0;
|
|
||||||
right: 0;
|
|
||||||
color: #ccc;
|
|
||||||
padding: 0.5em;
|
|
||||||
}
|
|
||||||
|
|
||||||
.section {
|
|
||||||
clear: both;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hidden {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.menu-item {
|
|
||||||
cursor: pointer;
|
|
||||||
padding: 0.1em 0.5em;
|
|
||||||
}
|
|
||||||
|
|
||||||
.menu-item-selected {
|
|
||||||
font-weight: bold;
|
|
||||||
}
|
|
||||||
|
|
||||||
.message-list {
|
|
||||||
min-height: 1em;
|
|
||||||
background: white;
|
|
||||||
margin: 0.5em 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.rounded {
|
|
||||||
border-radius: 6px;
|
|
||||||
-moz-border-radius: 6px;
|
|
||||||
-webkit-border-radius: 6px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.left-rounded {
|
|
||||||
border-radius: 6px 0 0 6px;
|
|
||||||
-moz-border-radius: 6px 0 0 6px;
|
|
||||||
-webkit-border-radius: 6px 0 0 6px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.bottom-rounded {
|
|
||||||
border-radius: 0 0 6px 6px;
|
|
||||||
-moz-border-radius: 0 0 6px 6px;
|
|
||||||
-webkit-border-radius: 0 0 6px 6px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.top-rounded {
|
|
||||||
border-radius: 6px 6px 0 0;
|
|
||||||
-moz-border-radius: 6px 6px 0 0;
|
|
||||||
-webkit-border-radius: 6px 6px 0 0;
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
# Copyright (c) 2014 Cesanta Software
|
||||||
|
# All rights reserved
|
||||||
|
|
||||||
|
PROG = http_client
|
||||||
|
CFLAGS = -W -Wall -I../.. -pthread -g -O0 $(CFLAGS_EXTRA)
|
||||||
|
SOURCES = $(PROG).c ../../mongoose.c
|
||||||
|
|
||||||
|
unix: $(SOURCES)
|
||||||
|
$(CC) -o $(PROG) $(SOURCES) $(CFLAGS)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -rf $(PROG) *.exe *.dSYM *.obj *.exp .*o *.lib
|
||||||
@@ -0,0 +1,82 @@
|
|||||||
|
// Copyright (c) 2014 Cesanta Software
|
||||||
|
// All rights reserved
|
||||||
|
//
|
||||||
|
// This example demostrates how to connect to the remote Web server,
|
||||||
|
// download data, process it and send back a reply.
|
||||||
|
|
||||||
|
#include <signal.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "mongoose.h"
|
||||||
|
|
||||||
|
static int s_received_signal = 0;
|
||||||
|
static struct mg_server *s_server = NULL;
|
||||||
|
static const char *s_remote_addr = "glosbe.com:80";
|
||||||
|
|
||||||
|
static void signal_handler(int sig_num) {
|
||||||
|
signal(sig_num, signal_handler);
|
||||||
|
s_received_signal = sig_num;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int ev_handler(struct mg_connection *conn, enum mg_event ev) {
|
||||||
|
struct mg_connection *client, *orig;
|
||||||
|
|
||||||
|
switch (ev) {
|
||||||
|
case MG_AUTH:
|
||||||
|
return MG_TRUE;
|
||||||
|
|
||||||
|
case MG_CONNECT:
|
||||||
|
// Send request to the remote host.
|
||||||
|
// TODO(lsm): handle connect error here.
|
||||||
|
mg_printf(conn, "GET %s HTTP/1.0\r\nHost: %s\r\n\r\n",
|
||||||
|
"/gapi/translate?from=eng&dest=fra&format=json&phrase=cat",
|
||||||
|
s_remote_addr);
|
||||||
|
return MG_TRUE;
|
||||||
|
|
||||||
|
case MG_REPLY:
|
||||||
|
// Send reply to the original connection
|
||||||
|
orig = (struct mg_connection *) conn->connection_param;
|
||||||
|
mg_send_status(orig, conn->status_code);
|
||||||
|
mg_send_header(orig, "Content-Type", "text/plain");
|
||||||
|
mg_send_data(orig, conn->content, conn->content_len);
|
||||||
|
mg_send_data(orig, "", 0); // Last chunk: mark the end of reply
|
||||||
|
|
||||||
|
// Disconnect connections
|
||||||
|
orig->connection_param = NULL;
|
||||||
|
conn->connection_param = NULL;
|
||||||
|
return MG_TRUE;
|
||||||
|
|
||||||
|
case MG_REQUEST:
|
||||||
|
if ((client = mg_connect(s_server, s_remote_addr)) != NULL) {
|
||||||
|
// Interconnect requests
|
||||||
|
client->connection_param = conn;
|
||||||
|
conn->connection_param = client;
|
||||||
|
return MG_MORE;
|
||||||
|
} else {
|
||||||
|
mg_printf_data(conn, "%s", "cannot send API request");
|
||||||
|
return MG_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
return MG_FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
s_server = mg_create_server(NULL, ev_handler);
|
||||||
|
|
||||||
|
mg_set_option(s_server, "listening_port", "8080");
|
||||||
|
|
||||||
|
// Setup signal handlers
|
||||||
|
signal(SIGTERM, signal_handler);
|
||||||
|
signal(SIGINT, signal_handler);
|
||||||
|
|
||||||
|
printf("Listening on port %s\n", mg_get_option(s_server, "listening_port"));
|
||||||
|
while (s_received_signal == 0) {
|
||||||
|
mg_poll_server(s_server, 1000);
|
||||||
|
}
|
||||||
|
mg_destroy_server(&s_server);
|
||||||
|
printf("Existing on signal %d\n", s_received_signal);
|
||||||
|
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
# Copyright (c) 2014 Cesanta Software
|
||||||
|
# All rights reserved
|
||||||
|
|
||||||
|
PROG = mjpg_streamer
|
||||||
|
CFLAGS = -W -Wall -I../.. -pthread -g -O0 $(CFLAGS_EXTRA)
|
||||||
|
SOURCES = $(PROG).c ../../mongoose.c
|
||||||
|
|
||||||
|
$(PROG): $(SOURCES)
|
||||||
|
$(CC) -o $(PROG) $(SOURCES) $(CFLAGS)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -rf $(PROG) *.exe *.dSYM *.obj *.exp .*o *.lib
|
||||||
@@ -0,0 +1,105 @@
|
|||||||
|
#include <sys/stat.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include "mongoose.h"
|
||||||
|
|
||||||
|
static void send_file(struct mg_connection *conn, const char *path) {
|
||||||
|
char buf[1024];
|
||||||
|
struct stat st;
|
||||||
|
int n;
|
||||||
|
FILE *fp;
|
||||||
|
|
||||||
|
if (stat(path, &st) == 0 && (fp = fopen(path, "rb")) != NULL) {
|
||||||
|
mg_printf(conn, "--w00t\r\nContent-Type: image/jpeg\r\n"
|
||||||
|
"Content-Length: %lu\r\n\r\n", (unsigned long) st.st_size);
|
||||||
|
while ((n = fread(buf, 1, sizeof(buf), fp)) > 0) {
|
||||||
|
mg_write(conn, buf, n);
|
||||||
|
}
|
||||||
|
fclose(fp);
|
||||||
|
mg_write(conn, "\r\n", 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct conn_state {
|
||||||
|
int file_index;
|
||||||
|
time_t last_poll;
|
||||||
|
};
|
||||||
|
|
||||||
|
static int ev_handler(struct mg_connection *conn, enum mg_event ev) {
|
||||||
|
const char **file_names = (const char **) conn->server_param;
|
||||||
|
struct conn_state *state;
|
||||||
|
time_t now = time(NULL);
|
||||||
|
|
||||||
|
switch (ev) {
|
||||||
|
|
||||||
|
case MG_AUTH:
|
||||||
|
return MG_TRUE;
|
||||||
|
|
||||||
|
case MG_REQUEST:
|
||||||
|
if (strcmp(conn->uri, "/stream") != 0) {
|
||||||
|
mg_send_header(conn, "Content-Type", "text/html");
|
||||||
|
mg_printf_data(conn, "%s",
|
||||||
|
"Go to <a href=/stream>/stream</a> for MJPG stream");
|
||||||
|
return MG_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
mg_printf(conn, "%s",
|
||||||
|
"HTTP/1.0 200 OK\r\n" "Cache-Control: no-cache\r\n"
|
||||||
|
"Pragma: no-cache\r\nExpires: Thu, 01 Dec 1994 16:00:00 GMT\r\n"
|
||||||
|
"Connection: close\r\nContent-Type: multipart/x-mixed-replace; "
|
||||||
|
"boundary=--w00t\r\n\r\n");
|
||||||
|
|
||||||
|
send_file(conn, file_names[0]);
|
||||||
|
|
||||||
|
state = (struct conn_state *) malloc(sizeof(*state));
|
||||||
|
conn->connection_param = state;
|
||||||
|
state->file_index = 1; // First file is already sent
|
||||||
|
state->last_poll = time(NULL);
|
||||||
|
return MG_MORE;
|
||||||
|
|
||||||
|
case MG_POLL:
|
||||||
|
state = (struct conn_state *) conn->connection_param;
|
||||||
|
|
||||||
|
if (state != NULL && now > state->last_poll) {
|
||||||
|
if (file_names[state->file_index] != NULL) {
|
||||||
|
send_file(conn, file_names[state->file_index]);
|
||||||
|
state->file_index++;
|
||||||
|
if (file_names[state->file_index] == NULL) {
|
||||||
|
return MG_TRUE; // No more images, close connection
|
||||||
|
}
|
||||||
|
}
|
||||||
|
state->last_poll = now;
|
||||||
|
}
|
||||||
|
return MG_FALSE;
|
||||||
|
|
||||||
|
case MG_CLOSE:
|
||||||
|
free(conn->connection_param);
|
||||||
|
conn->connection_param = NULL;
|
||||||
|
return MG_FALSE;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return MG_FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[]) {
|
||||||
|
struct mg_server *server;
|
||||||
|
|
||||||
|
if (argc < 3) {
|
||||||
|
printf("Usage: %s image1.jpg image2.jpg ...\n", argv[0]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
server = mg_create_server(&argv[1], ev_handler);
|
||||||
|
mg_set_option(server, "listening_port", "8080");
|
||||||
|
|
||||||
|
printf("Starting on port %s\n", mg_get_option(server, "listening_port"));
|
||||||
|
for (;;) {
|
||||||
|
mg_poll_server(server, 1000);
|
||||||
|
}
|
||||||
|
mg_destroy_server(&server);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
# Copyright (c) 2014 Cesanta Software
|
||||||
|
# All rights reserved
|
||||||
|
|
||||||
|
PROG = multi_threaded_server
|
||||||
|
CFLAGS = -W -Wall -I../.. -pthread -g -O0 $(CFLAGS_EXTRA)
|
||||||
|
SOURCES = $(PROG).c ../../mongoose.c
|
||||||
|
|
||||||
|
$(PROG): $(SOURCES)
|
||||||
|
$(CC) -o $(PROG) $(SOURCES) $(CFLAGS)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -rf $(PROG) *.exe *.dSYM *.obj *.exp .*o *.lib
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
#include "mongoose.h"
|
||||||
|
|
||||||
|
// Start a browser and hit refresh couple of times. The replies will
|
||||||
|
// come from both server instances.
|
||||||
|
static int ev_handler(struct mg_connection *conn, enum mg_event ev) {
|
||||||
|
if (ev == MG_REQUEST) {
|
||||||
|
mg_send_header(conn, "Content-Type", "text/plain");
|
||||||
|
mg_printf_data(conn, "This is a reply from server instance # %s",
|
||||||
|
(char *) conn->server_param);
|
||||||
|
return MG_TRUE;
|
||||||
|
} else if (ev == MG_AUTH) {
|
||||||
|
return MG_TRUE;
|
||||||
|
} else {
|
||||||
|
return MG_FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void *serve(void *server) {
|
||||||
|
for (;;) mg_poll_server((struct mg_server *) server, 1000);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
struct mg_server *server1, *server2;
|
||||||
|
|
||||||
|
server1 = mg_create_server((void *) "1", ev_handler);
|
||||||
|
server2 = mg_create_server((void *) "2", ev_handler);
|
||||||
|
|
||||||
|
// Make both server1 and server2 listen on the same sockets
|
||||||
|
mg_set_option(server1, "listening_port", "8080");
|
||||||
|
mg_copy_listeners(server1, server2);
|
||||||
|
|
||||||
|
// server1 goes to separate thread, server 2 runs in main thread.
|
||||||
|
// IMPORTANT: NEVER LET DIFFERENT THREADS HANDLE THE SAME SERVER.
|
||||||
|
mg_start_thread(serve, server1);
|
||||||
|
mg_start_thread(serve, server2);
|
||||||
|
getchar();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -1,61 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include "mongoose.h"
|
|
||||||
|
|
||||||
static const char *html_form =
|
|
||||||
"<html><body>POST example."
|
|
||||||
"<form method=\"POST\" action=\"/handle_post_request\">"
|
|
||||||
"Input 1: <input type=\"text\" name=\"input_1\" /> <br/>"
|
|
||||||
"Input 2: <input type=\"text\" name=\"input_2\" /> <br/>"
|
|
||||||
"<input type=\"submit\" />"
|
|
||||||
"</form></body></html>";
|
|
||||||
|
|
||||||
static void *callback(enum mg_event event,
|
|
||||||
struct mg_connection *conn) {
|
|
||||||
const struct mg_request_info *ri = mg_get_request_info(conn);
|
|
||||||
|
|
||||||
if (event == MG_NEW_REQUEST) {
|
|
||||||
if (!strcmp(ri->uri, "/handle_post_request")) {
|
|
||||||
// User has submitted a form, show submitted data and a variable value
|
|
||||||
char post_data[1024],
|
|
||||||
input1[sizeof(post_data)], input2[sizeof(post_data)];
|
|
||||||
int post_data_len;
|
|
||||||
|
|
||||||
// Read POST data
|
|
||||||
post_data_len = mg_read(conn, post_data, sizeof(post_data));
|
|
||||||
|
|
||||||
// Parse form data. input1 and input2 are guaranteed to be NUL-terminated
|
|
||||||
mg_get_var(post_data, post_data_len, "input_1", input1, sizeof(input1));
|
|
||||||
mg_get_var(post_data, post_data_len, "input_2", input2, sizeof(input2));
|
|
||||||
|
|
||||||
mg_printf(conn, "HTTP/1.0 200 OK\r\n"
|
|
||||||
"Content-Type: text/plain\r\n\r\n"
|
|
||||||
"Submitted data: [%.*s]\n"
|
|
||||||
"Submitted data length: %d bytes\n"
|
|
||||||
"input_1: [%s]\n"
|
|
||||||
"input_2: [%s]\n",
|
|
||||||
post_data_len, post_data, post_data_len, input1, input2);
|
|
||||||
} else {
|
|
||||||
// Show HTML form.
|
|
||||||
mg_printf(conn, "HTTP/1.0 200 OK\r\n"
|
|
||||||
"Content-Length: %d\r\n"
|
|
||||||
"Content-Type: text/html\r\n\r\n%s",
|
|
||||||
(int) strlen(html_form), html_form);
|
|
||||||
}
|
|
||||||
// Mark as processed
|
|
||||||
return "";
|
|
||||||
} else {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(void) {
|
|
||||||
struct mg_context *ctx;
|
|
||||||
const char *options[] = {"listening_ports", "8080", NULL};
|
|
||||||
|
|
||||||
ctx = mg_start(&callback, NULL, options);
|
|
||||||
getchar(); // Wait until user hits "enter"
|
|
||||||
mg_stop(ctx);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
# Copyright (c) 2014 Cesanta Software
|
||||||
|
# All rights reserved
|
||||||
|
|
||||||
|
PROG = proxy_server
|
||||||
|
FLAGS = -I../.. -DNS_ENABLE_SSL
|
||||||
|
CFLAGS = -W -Wall -g -O0 -pthread -lssl $(FLAGS) $(CFLAGS_EXTRA)
|
||||||
|
SOURCES = $(PROG).c ../../mongoose.c
|
||||||
|
|
||||||
|
unix: $(SOURCES)
|
||||||
|
$(CC) -o $(PROG) $(SOURCES) $(CFLAGS)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -rf $(PROG) *.exe *.dSYM *.obj *.exp .*o *.lib
|
||||||
@@ -0,0 +1,212 @@
|
|||||||
|
// Copyright (c) 2014 Cesanta Software Limited
|
||||||
|
// All rights reserved
|
||||||
|
//
|
||||||
|
// To build and run this example:
|
||||||
|
// git clone https://github.com/cesanta/net_skeleton.git
|
||||||
|
// git clone https://github.com/cesanta/mongoose.git
|
||||||
|
// cd mongoose/examples
|
||||||
|
// make proxy
|
||||||
|
// ./proxy
|
||||||
|
//
|
||||||
|
// Configure your browser to use localhost:2014 as a proxy for all protocols
|
||||||
|
// Then, navigate to https://cesanta.com
|
||||||
|
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <signal.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#define sleep(x) Sleep((x) * 1000)
|
||||||
|
#else
|
||||||
|
#include <unistd.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "mongoose.h"
|
||||||
|
|
||||||
|
static int s_received_signal = 0;
|
||||||
|
static struct mg_server *s_server = NULL;
|
||||||
|
|
||||||
|
#define SSE_CONNECTION ((void *) 1)
|
||||||
|
|
||||||
|
static void elog(int do_exit, const char *fmt, ...) {
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, fmt);
|
||||||
|
vfprintf(stderr, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
fputc('\n', stderr);
|
||||||
|
if (do_exit) exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void signal_handler(int sig_num) {
|
||||||
|
signal(sig_num, signal_handler);
|
||||||
|
s_received_signal = sig_num;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int sse_push(struct mg_connection *conn, enum mg_event ev) {
|
||||||
|
if (ev == MG_POLL && conn->connection_param == SSE_CONNECTION) {
|
||||||
|
mg_printf(conn, "data: %s\r\n\r\n", (const char *) conn->callback_param);
|
||||||
|
}
|
||||||
|
return MG_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void *sse_pusher_thread_func(void *param) {
|
||||||
|
while (s_received_signal == 0) {
|
||||||
|
mg_wakeup_server_ex(s_server, sse_push, "%lu %s",
|
||||||
|
(unsigned long) time(NULL), (const char *) param);
|
||||||
|
sleep(1);
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return: 1 if regular file, 2 if directory, 0 if not found
|
||||||
|
static int exists(const char *path) {
|
||||||
|
struct stat st;
|
||||||
|
return stat(path, &st) != 0 ? 0 : S_ISDIR(st.st_mode) == 0 ? 1 : 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return: 1 if regular file, 2 if directory, 0 if not found
|
||||||
|
static int is_local_file(const char *uri, char *path, size_t path_len) {
|
||||||
|
snprintf(path, path_len, "%s/%s",
|
||||||
|
mg_get_option(s_server, "document_root"), uri);
|
||||||
|
return exists(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int try_to_serve_locally(struct mg_connection *conn) {
|
||||||
|
char path[500], buf[2000];
|
||||||
|
int n, res;
|
||||||
|
FILE *fp = NULL;
|
||||||
|
|
||||||
|
if ((res = is_local_file(conn->uri, path, sizeof(path))) == 2) {
|
||||||
|
strncat(path, "/index.html", sizeof(path) - strlen(path) - 1);
|
||||||
|
res = exists(path);
|
||||||
|
printf("PATH: [%s]\n", path);
|
||||||
|
}
|
||||||
|
if (res == 0) return MG_FALSE;
|
||||||
|
|
||||||
|
if ((fp = fopen(path, "rb")) != NULL) {
|
||||||
|
printf("Serving [%s] locally \n", path);
|
||||||
|
mg_send_header(conn, "Connection", "close");
|
||||||
|
mg_send_header(conn, "Content-Type", mg_get_mime_type(path, "text/plain"));
|
||||||
|
while ((n = fread(buf, 1, sizeof(buf), fp)) > 0) {
|
||||||
|
mg_send_data(conn, buf, n);
|
||||||
|
}
|
||||||
|
mg_send_data(conn, "", 0);
|
||||||
|
fclose(fp);
|
||||||
|
}
|
||||||
|
return fp == NULL ? MG_FALSE : MG_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int is_resource_present_locally(const char *uri) {
|
||||||
|
char path[500];
|
||||||
|
return is_local_file(uri, path, sizeof(path)) || strcmp(uri, "/api/sse") == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int proxy_event_handler(struct mg_connection *conn, enum mg_event ev) {
|
||||||
|
static const char target_url[] = "http://cesanta.com";
|
||||||
|
static int target_url_size = sizeof(target_url) - 1;
|
||||||
|
const char *host;
|
||||||
|
|
||||||
|
switch (ev) {
|
||||||
|
case MG_REQUEST:
|
||||||
|
host = mg_get_header(conn, "Host");
|
||||||
|
printf("[%s] [%s] [%s]\n", conn->request_method, conn->uri,
|
||||||
|
host == NULL ? "" : host);
|
||||||
|
if (strstr(conn->uri, "/qqq") != NULL) s_received_signal = SIGTERM;
|
||||||
|
|
||||||
|
// Proxied HTTPS requests use "CONNECT foo.com:443"
|
||||||
|
// Proxied HTTP requests use "GET http://..... "
|
||||||
|
// Serve requests for target_url from the local FS.
|
||||||
|
if (memcmp(conn->uri, target_url, target_url_size) == 0 &&
|
||||||
|
is_resource_present_locally(conn->uri + target_url_size)) {
|
||||||
|
conn->uri += target_url_size; // Leave only path in the URI
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strcmp(conn->uri, "/api/sse") == 0) {
|
||||||
|
conn->connection_param = SSE_CONNECTION;
|
||||||
|
mg_printf(conn, "%s", "HTTP/1.0 200 OK\r\n"
|
||||||
|
"Content-Type: text/event-stream\r\n"
|
||||||
|
"Cache-Control: no-cache\r\n\r\n");
|
||||||
|
return MG_MORE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (host != NULL && strstr(host, "cesanta") != NULL) {
|
||||||
|
return try_to_serve_locally(conn);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Enable man-in-the-middle SSL mode for oracle.com
|
||||||
|
if (!strcmp(conn->request_method, "CONNECT") &&
|
||||||
|
!strcmp(host, "oracle.com")) {
|
||||||
|
mg_terminate_ssl(conn, "ssl_cert.pem"); // MUST return MG_MORE after
|
||||||
|
return MG_MORE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return MG_FALSE;
|
||||||
|
case MG_AUTH:
|
||||||
|
return MG_TRUE;
|
||||||
|
default:
|
||||||
|
return MG_FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void setopt(struct mg_server *s, const char *opt, const char *val) {
|
||||||
|
const char *err_msg = mg_set_option(s, opt, val);
|
||||||
|
if (err_msg != NULL) {
|
||||||
|
elog(1, "Error setting [%s]: [%s]", opt, err_msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[]) {
|
||||||
|
const char *cert = NULL, *ca_cert = NULL, *port = "2014";
|
||||||
|
const char *mitm = NULL, *dump = NULL, *root = "proxy_web_root";
|
||||||
|
int i;
|
||||||
|
|
||||||
|
// Parse command line options
|
||||||
|
for (i = 1; i < argc; i++) {
|
||||||
|
if (strcmp(argv[i], "-ca_cert") == 0 && i + 1 < argc) {
|
||||||
|
ca_cert = argv[++i];
|
||||||
|
} else if (strcmp(argv[i], "-cert") == 0 && i + 1 < argc) {
|
||||||
|
cert = argv[++i];
|
||||||
|
} else if (strcmp(argv[i], "-port") == 0 && i + 1 < argc) {
|
||||||
|
port = argv[++i];
|
||||||
|
} else if (strcmp(argv[i], "-mitm") == 0 && i + 1 < argc) {
|
||||||
|
mitm = argv[++i];
|
||||||
|
} else if (strcmp(argv[i], "-root") == 0 && i + 1 < argc) {
|
||||||
|
root = argv[++i];
|
||||||
|
} else if (strcmp(argv[i], "-dump") == 0 && i + 1 < argc) {
|
||||||
|
dump = argv[++i];
|
||||||
|
} else {
|
||||||
|
elog(1, "Usage: %s [-cert FILE] [-ca_cert FILE] [-port PORT]", argv[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
signal(SIGTERM, signal_handler);
|
||||||
|
signal(SIGINT, signal_handler);
|
||||||
|
|
||||||
|
// Create and configure proxy server
|
||||||
|
s_server = mg_create_server(NULL, &proxy_event_handler);
|
||||||
|
setopt(s_server, "enable_proxy", "yes");
|
||||||
|
setopt(s_server, "document_root", root);
|
||||||
|
setopt(s_server, "listening_port", port);
|
||||||
|
setopt(s_server, "ssl_certificate", cert);
|
||||||
|
setopt(s_server, "ssl_ca_certificate", ca_cert);
|
||||||
|
setopt(s_server, "hexdump_file", dump);
|
||||||
|
setopt(s_server, "ssl_mitm_certs", mitm);
|
||||||
|
|
||||||
|
// Start two SSE pushing threads
|
||||||
|
mg_start_thread(sse_pusher_thread_func, (void *) "sse_pusher_thread_1");
|
||||||
|
mg_start_thread(sse_pusher_thread_func, (void *) "sse_pusher_thread_2");
|
||||||
|
|
||||||
|
// Start serving in the main thread
|
||||||
|
printf("Starting on port %s\n", mg_get_option(s_server, "listening_port"));
|
||||||
|
while (s_received_signal == 0) {
|
||||||
|
mg_poll_server(s_server, 1000);
|
||||||
|
}
|
||||||
|
printf("Existing on signal %d\n", s_received_signal);
|
||||||
|
mg_destroy_server(&s_server);
|
||||||
|
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>App1 Index</title>
|
||||||
|
<style>
|
||||||
|
img { height: 40px; }
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<h1>App1 index page. Served locally from the the proxy server filesystem</h1>
|
||||||
|
|
||||||
|
<p>image that references non-existent local resource. Forwarded to
|
||||||
|
the 'real' proxy target:</p>
|
||||||
|
<img src="http://cesanta.com/images/logo.png" />
|
||||||
|
|
||||||
|
<p>Google logo via HTTPS (external resource, served by remote host):</p>
|
||||||
|
<img src="https://www.google.ie/images/srpr/logo11w.png" />
|
||||||
|
|
||||||
|
<p>Same image via HTTP:</p>
|
||||||
|
<img src="http://www.google.ie/images/srpr/logo11w.png" />
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>App2 Index</title>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<script>
|
||||||
|
window.onload = function() {
|
||||||
|
// Using secure websocket connection, wss://
|
||||||
|
var ws = new WebSocket('wss://echo.websocket.org');
|
||||||
|
var div = document.getElementById('events');
|
||||||
|
ws.onmessage = function(ev) {
|
||||||
|
var el = document.createElement('div');
|
||||||
|
el.innerHTML = 'websocket message: ' + ev.data;
|
||||||
|
div.appendChild(el);
|
||||||
|
// Keep only last 5 messages in the list
|
||||||
|
while (div.childNodes.length > 5) div.removeChild(div.firstChild);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Send random stuff to the websocket connection periodically.
|
||||||
|
// websocket server much echo that stuff back.
|
||||||
|
window.setInterval(function() {
|
||||||
|
var d = new Date();
|
||||||
|
ws.send(d.toString());
|
||||||
|
}, 1000);
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>App2 index page. Served locally from the
|
||||||
|
the proxy's filesystem.</h1>
|
||||||
|
<p>
|
||||||
|
Following div shows proxy forwarding of websocket connection, served by
|
||||||
|
ws://echo.websocket.org:
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div id="events"></div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title> proxy index </title>
|
||||||
|
<script type="text/javascript">
|
||||||
|
window.onload = function() {
|
||||||
|
var es = new EventSource("/api/sse");
|
||||||
|
var div = document.getElementById('events');
|
||||||
|
es.onmessage = function(ev) {
|
||||||
|
var el = document.createElement('div');
|
||||||
|
el.innerHTML = 'sse message: ' + ev.data;
|
||||||
|
div.appendChild(el);
|
||||||
|
// Keep only last 5 messages in the list
|
||||||
|
while (div.childNodes.length > 5) div.removeChild(div.firstChild);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1> proxy index page.</h1>
|
||||||
|
<ul>
|
||||||
|
<li><a href="app1">App1</a> - App1 root</li>
|
||||||
|
<li><a href="app2">App2</a> - App2 root</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<h2>SSE pushes, done by separate threads at random times:</h2>
|
||||||
|
<div id="events"></div>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
File renamed without changes.
@@ -0,0 +1,12 @@
|
|||||||
|
# Copyright (c) 2014 Cesanta Software
|
||||||
|
# All rights reserved
|
||||||
|
|
||||||
|
PROG = restful_api
|
||||||
|
CFLAGS = -W -Wall -I../.. -pthread -g -O0 $(CFLAGS_EXTRA)
|
||||||
|
SOURCES = $(PROG).c ../../mongoose.c
|
||||||
|
|
||||||
|
$(PROG): $(SOURCES)
|
||||||
|
$(CC) -o $(PROG) $(SOURCES) $(CFLAGS)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -rf $(PROG) *.exe *.dSYM *.obj *.exp .*o *.lib
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<title>RESTful API demo</title>
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
|
<style type="text/css">
|
||||||
|
* { outline: none; font: 16px/1.4 Helvetica, Arial, sans-serif; }
|
||||||
|
body {
|
||||||
|
background-color: #cde; margin: 0;
|
||||||
|
padding: 0; font: 16px/1.4 Helvetica, Arial, sans-serif;
|
||||||
|
}
|
||||||
|
div.content {
|
||||||
|
width: 800px; margin: 2em auto; padding: 20px 50px;
|
||||||
|
background-color: #fff; border-radius: 1em;
|
||||||
|
}
|
||||||
|
label { display: inline-block; min-width: 7em; }
|
||||||
|
input { border: 1px solid #ccc; padding: 0.2em; }
|
||||||
|
a:link, a:visited { color: #69c; text-decoration: none; }
|
||||||
|
@media (max-width: 700px) {
|
||||||
|
body { background-color: #fff; }
|
||||||
|
div.content { width: auto; margin: 0 auto; padding: 1em; }
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
|
||||||
|
<script language="javascript" type="text/javascript">
|
||||||
|
jQuery(function() {
|
||||||
|
|
||||||
|
$(document).on('keyup', '#n1, #n2', function() {
|
||||||
|
$.ajax({
|
||||||
|
url: '/api/sum',
|
||||||
|
method: 'POST',
|
||||||
|
dataType: 'json',
|
||||||
|
data: { n1: $('#n1').val(), n2: $('#n2').val() },
|
||||||
|
success: function(json) {
|
||||||
|
$('#result').html(json.result);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="content">
|
||||||
|
<h1>RESTful API demo.</h1>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
This page demonstrates how Mongoose web server could be used to implement
|
||||||
|
RESTful APIs. Enter numbers below, and press Submit. Browser will send
|
||||||
|
two numbers to <tt>/api/sum</tt> URI, Mongoose calclulates the sum of
|
||||||
|
two and returns the result.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label>Number 1:</label> <input type="text" id="n1" />
|
||||||
|
</div><div>
|
||||||
|
<label>Number 2:</label> <input type="text" id="n2" />
|
||||||
|
</div><div>
|
||||||
|
<label>Result:</label> <span id="result"> </span>
|
||||||
|
</div><div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include "mongoose.h"
|
||||||
|
|
||||||
|
static const char *s_no_cache_header =
|
||||||
|
"Cache-Control: max-age=0, post-check=0, "
|
||||||
|
"pre-check=0, no-store, no-cache, must-revalidate\r\n";
|
||||||
|
|
||||||
|
static void handle_restful_call(struct mg_connection *conn) {
|
||||||
|
char n1[100], n2[100];
|
||||||
|
|
||||||
|
// Get form variables
|
||||||
|
mg_get_var(conn, "n1", n1, sizeof(n1));
|
||||||
|
mg_get_var(conn, "n2", n2, sizeof(n2));
|
||||||
|
|
||||||
|
mg_printf_data(conn, "{ \"result\": %lf }", strtod(n1, NULL) + strtod(n2, NULL));
|
||||||
|
}
|
||||||
|
|
||||||
|
static int ev_handler(struct mg_connection *conn, enum mg_event ev) {
|
||||||
|
switch (ev) {
|
||||||
|
case MG_AUTH: return MG_TRUE;
|
||||||
|
case MG_REQUEST:
|
||||||
|
if (!strcmp(conn->uri, "/api/sum")) {
|
||||||
|
handle_restful_call(conn);
|
||||||
|
return MG_TRUE;
|
||||||
|
}
|
||||||
|
mg_send_file(conn, "index.html", s_no_cache_header);
|
||||||
|
return MG_MORE;
|
||||||
|
default: return MG_FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
struct mg_server *server;
|
||||||
|
|
||||||
|
// Create and configure the server
|
||||||
|
server = mg_create_server(NULL, ev_handler);
|
||||||
|
mg_set_option(server, "listening_port", "8000");
|
||||||
|
|
||||||
|
// Serve request. Hit Ctrl-C to terminate the program
|
||||||
|
printf("Starting on port %s\n", mg_get_option(server, "listening_port"));
|
||||||
|
for (;;) {
|
||||||
|
mg_poll_server(server, 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cleanup, and free server instance
|
||||||
|
mg_destroy_server(&server);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
# Copyright (c) 2014 Cesanta Software
|
||||||
|
# All rights reserved
|
||||||
|
|
||||||
|
PROG = send_file
|
||||||
|
CFLAGS = -W -Wall -I../.. -pthread -g -O0 $(CFLAGS_EXTRA)
|
||||||
|
SOURCES = $(PROG).c ../../mongoose.c
|
||||||
|
|
||||||
|
all: $(PROG)
|
||||||
|
|
||||||
|
run: $(PROG)
|
||||||
|
./$(PROG)
|
||||||
|
|
||||||
|
$(PROG): $(SOURCES) Makefile
|
||||||
|
$(CC) -o $(PROG) $(SOURCES) $(CFLAGS)
|
||||||
|
|
||||||
|
win:
|
||||||
|
wine cl $(SOURCES) /MD /nologo /DNDEBUG /O1 /I../.. /Fe$(PROG).exe
|
||||||
|
wine $(PROG).exe
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -rf $(PROG) *.exe *.dSYM *.obj *.exp .*o *.lib *.gc*
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
// Copyright (c) 2014 Cesanta Software
|
||||||
|
// All rights reserved
|
||||||
|
//
|
||||||
|
// This example demostrates how to send arbitrary files to the client.
|
||||||
|
|
||||||
|
#include "mongoose.h"
|
||||||
|
|
||||||
|
static int ev_handler(struct mg_connection *conn, enum mg_event ev) {
|
||||||
|
switch (ev) {
|
||||||
|
case MG_REQUEST:
|
||||||
|
mg_send_file(conn, "send_file.c", NULL); // Also could be a dir, or CGI
|
||||||
|
return MG_MORE; // It is important to return MG_MORE after mg_send_file!
|
||||||
|
case MG_AUTH: return MG_TRUE;
|
||||||
|
default: return MG_FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
struct mg_server *server = mg_create_server(NULL, ev_handler);
|
||||||
|
mg_set_option(server, "listening_port", "8080");
|
||||||
|
|
||||||
|
printf("Starting on port %s\n", mg_get_option(server, "listening_port"));
|
||||||
|
for (;;) mg_poll_server(server, 1000);
|
||||||
|
mg_destroy_server(&server);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -1,59 +0,0 @@
|
|||||||
// Copyright (c) 2004-2012 Sergey Lyubka
|
|
||||||
// This file is a part of mongoose project, http://github.com/valenok/mongoose
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#ifdef _WIN32
|
|
||||||
#include <windows.h>
|
|
||||||
#include <io.h>
|
|
||||||
#define strtoll strtol
|
|
||||||
typedef __int64 int64_t;
|
|
||||||
#else
|
|
||||||
#include <inttypes.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#endif // !_WIN32
|
|
||||||
|
|
||||||
#include "mongoose.h"
|
|
||||||
|
|
||||||
static void *callback(enum mg_event event, struct mg_connection *conn) {
|
|
||||||
if (event == MG_NEW_REQUEST) {
|
|
||||||
if (!strcmp(mg_get_request_info(conn)->uri, "/handle_post_request")) {
|
|
||||||
mg_printf(conn, "%s", "HTTP/1.0 200 OK\r\n\r\n");
|
|
||||||
mg_upload(conn, "/tmp");
|
|
||||||
} else {
|
|
||||||
// Show HTML form. Make sure it has enctype="multipart/form-data" attr.
|
|
||||||
static const char *html_form =
|
|
||||||
"<html><body>Upload example."
|
|
||||||
"<form method=\"POST\" action=\"/handle_post_request\" "
|
|
||||||
" enctype=\"multipart/form-data\">"
|
|
||||||
"<input type=\"file\" name=\"file\" /> <br/>"
|
|
||||||
"<input type=\"submit\" value=\"Upload\" />"
|
|
||||||
"</form></body></html>";
|
|
||||||
|
|
||||||
mg_printf(conn, "HTTP/1.0 200 OK\r\n"
|
|
||||||
"Content-Length: %d\r\n"
|
|
||||||
"Content-Type: text/html\r\n\r\n%s",
|
|
||||||
(int) strlen(html_form), html_form);
|
|
||||||
}
|
|
||||||
// Mark as processed
|
|
||||||
return "";
|
|
||||||
} else if (event == MG_UPLOAD) {
|
|
||||||
mg_printf(conn, "Saved [%s]", mg_get_request_info(conn)->ev_data);
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(void) {
|
|
||||||
struct mg_context *ctx;
|
|
||||||
const char *options[] = {"listening_ports", "8080", NULL};
|
|
||||||
|
|
||||||
ctx = mg_start(&callback, NULL, options);
|
|
||||||
getchar(); // Wait until user hits "enter"
|
|
||||||
pause();
|
|
||||||
mg_stop(ctx);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
# Copyright (c) 2014 Cesanta Software
|
||||||
|
# All rights reserved
|
||||||
|
|
||||||
|
PROG = web_server
|
||||||
|
CFLAGS = -W -Wall -I../.. -pthread -g -O0 $(CFLAGS_EXTRA)
|
||||||
|
SOURCES = $(PROG).c ../../mongoose.c
|
||||||
|
|
||||||
|
$(PROG): $(SOURCES)
|
||||||
|
$(CC) -o $(PROG) $(SOURCES) $(CFLAGS)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -rf $(PROG) *.exe *.dSYM *.obj *.exp .*o *.lib
|
||||||
@@ -0,0 +1,491 @@
|
|||||||
|
// Copyright (c) 2004-2013 Sergey Lyubka
|
||||||
|
// Copyright (c) 2013-2014 Cesanta Software Limited
|
||||||
|
|
||||||
|
#undef UNICODE // Use ANSI WinAPI functions
|
||||||
|
#undef _UNICODE // Use multibyte encoding on Windows
|
||||||
|
#define _MBCS // Use multibyte encoding on Windows
|
||||||
|
#define _WIN32_WINNT 0x500 // Enable MIIM_BITMAP
|
||||||
|
#define _CRT_SECURE_NO_WARNINGS // Disable deprecation warning in VS2005
|
||||||
|
#define _XOPEN_SOURCE 600 // For PATH_MAX on linux
|
||||||
|
#undef WIN32_LEAN_AND_MEAN // Let windows.h always include winsock2.h
|
||||||
|
|
||||||
|
#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 <time.h>
|
||||||
|
|
||||||
|
#include "mongoose.h"
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#include <windows.h>
|
||||||
|
#include <direct.h> // For chdir()
|
||||||
|
#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 abs_path(rel, abs, abs_size) _fullpath((abs), (rel), (abs_size))
|
||||||
|
#define SIGCHLD 0
|
||||||
|
typedef struct _stat file_stat_t;
|
||||||
|
#define stat(x, y) _stat((x), (y))
|
||||||
|
#else
|
||||||
|
typedef struct stat file_stat_t;
|
||||||
|
#include <sys/wait.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#ifdef IOS
|
||||||
|
#include <ifaddrs.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define DIRSEP '/'
|
||||||
|
#define __cdecl
|
||||||
|
#define abs_path(rel, abs, abs_size) realpath((rel), (abs))
|
||||||
|
#endif // _WIN32
|
||||||
|
|
||||||
|
#define MAX_OPTIONS 100
|
||||||
|
#define MAX_CONF_FILE_LINE_SIZE (8 * 1024)
|
||||||
|
|
||||||
|
#ifndef MVER
|
||||||
|
#define MVER MONGOOSE_VERSION
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static int exit_flag;
|
||||||
|
static char server_name[50]; // Set by init_server_name()
|
||||||
|
static char s_config_file[PATH_MAX]; // Set by process_command_line_arguments
|
||||||
|
static struct mg_server *server; // Set by start_mongoose()
|
||||||
|
static const char *s_default_document_root = ".";
|
||||||
|
static const char *s_default_listening_port = "8080";
|
||||||
|
static char **s_argv = { NULL };
|
||||||
|
|
||||||
|
static void set_options(char *argv[]);
|
||||||
|
|
||||||
|
#if !defined(CONFIG_FILE)
|
||||||
|
#define CONFIG_FILE "mongoose.conf"
|
||||||
|
#endif /* !CONFIG_FILE */
|
||||||
|
|
||||||
|
static void __cdecl signal_handler(int sig_num) {
|
||||||
|
// Reinstantiate signal handler
|
||||||
|
signal(sig_num, signal_handler);
|
||||||
|
|
||||||
|
#ifndef _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 vnotify(const char *fmt, va_list ap, int must_exit) {
|
||||||
|
char msg[200];
|
||||||
|
|
||||||
|
vsnprintf(msg, sizeof(msg), fmt, ap);
|
||||||
|
fprintf(stderr, "%s\n", msg);
|
||||||
|
|
||||||
|
if (must_exit) {
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void notify(const char *fmt, ...) {
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, fmt);
|
||||||
|
vnotify(fmt, ap, 0);
|
||||||
|
va_end(ap);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void die(const char *fmt, ...) {
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, fmt);
|
||||||
|
vnotify(fmt, ap, 1);
|
||||||
|
va_end(ap);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void show_usage_and_exit(void) {
|
||||||
|
const char **names;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
fprintf(stderr, "Mongoose version %s (c) Sergey Lyubka, built on %s\n",
|
||||||
|
MVER, __DATE__);
|
||||||
|
fprintf(stderr, "Usage:\n");
|
||||||
|
#if !defined(MONGOOSE_NO_AUTH) && !defined(MONGOOSE_NO_FILESYSTEM)
|
||||||
|
fprintf(stderr, " mongoose -A <htpasswd_file> <realm> <user> <passwd>\n");
|
||||||
|
#endif
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
#define EV_HANDLER NULL
|
||||||
|
|
||||||
|
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, cpath[PATH_MAX];
|
||||||
|
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(cpath, sizeof(cpath), "%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(cpath, sizeof(cpath), "%s", CONFIG_FILE);
|
||||||
|
} else {
|
||||||
|
snprintf(cpath, sizeof(cpath), "%.*s%c%s",
|
||||||
|
(int) (p - argv[0]), argv[0], DIRSEP, CONFIG_FILE);
|
||||||
|
}
|
||||||
|
abs_path(cpath, s_config_file, sizeof(s_config_file));
|
||||||
|
|
||||||
|
fp = fopen(s_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", s_config_file, strerror(errno));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load config file settings first
|
||||||
|
if (fp != NULL) {
|
||||||
|
fprintf(stderr, "Loading config file %s\n", s_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",
|
||||||
|
s_config_file, (int) line_no, line);
|
||||||
|
} else {
|
||||||
|
set_option(options, opt, val);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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) {
|
||||||
|
const char *descr = "";
|
||||||
|
snprintf(server_name, sizeof(server_name), "Mongoose web server v.%s%s",
|
||||||
|
MVER, descr);
|
||||||
|
}
|
||||||
|
|
||||||
|
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 *serving_thread_func(void *param) {
|
||||||
|
struct mg_server *srv = (struct mg_server *) param;
|
||||||
|
while (exit_flag == 0) {
|
||||||
|
mg_poll_server(srv, 1000);
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int path_exists(const char *path, int is_dir) {
|
||||||
|
file_stat_t st;
|
||||||
|
return path == NULL || (stat(path, &st) == 0 &&
|
||||||
|
((S_ISDIR(st.st_mode) ? 1 : 0) == is_dir));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void verify_existence(char **options, const char *name, int is_dir) {
|
||||||
|
const char *path = get_option(options, name);
|
||||||
|
if (!path_exists(path, is_dir)) {
|
||||||
|
notify("Invalid path for %s: [%s]: (%s). Make sure that path is either "
|
||||||
|
"absolute, or it is relative to mongoose executable.",
|
||||||
|
name, path, strerror(errno));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void set_absolute_path(char *options[], const char *option_name) {
|
||||||
|
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(s_config_file, DIRSEP)) == NULL) {
|
||||||
|
getcwd(path, sizeof(path));
|
||||||
|
} else {
|
||||||
|
snprintf(path, sizeof(path), "%.*s", (int) (p - s_config_file),
|
||||||
|
s_config_file);
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !defined(MONGOOSE_NO_AUTH) && !defined(MONGOOSE_NO_FILESYSTEM)
|
||||||
|
int modify_passwords_file(const char *fname, const char *domain,
|
||||||
|
const char *user, const char *pass) {
|
||||||
|
int found;
|
||||||
|
char line[512], u[512], d[512], ha1[33], tmp[PATH_MAX];
|
||||||
|
FILE *fp, *fp2;
|
||||||
|
|
||||||
|
found = 0;
|
||||||
|
fp = fp2 = NULL;
|
||||||
|
|
||||||
|
// Regard empty password as no password - remove user record.
|
||||||
|
if (pass != NULL && pass[0] == '\0') {
|
||||||
|
pass = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
(void) snprintf(tmp, sizeof(tmp), "%s.tmp", fname);
|
||||||
|
|
||||||
|
// Create the file if does not exist
|
||||||
|
if ((fp = fopen(fname, "a+")) != NULL) {
|
||||||
|
fclose(fp);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Open the given file and temporary file
|
||||||
|
if ((fp = fopen(fname, "r")) == NULL) {
|
||||||
|
return 0;
|
||||||
|
} else if ((fp2 = fopen(tmp, "w+")) == NULL) {
|
||||||
|
fclose(fp);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copy the stuff to temporary file
|
||||||
|
while (fgets(line, sizeof(line), fp) != NULL) {
|
||||||
|
if (sscanf(line, "%[^:]:%[^:]:%*s", u, d) != 2) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!strcmp(u, user) && !strcmp(d, domain)) {
|
||||||
|
found++;
|
||||||
|
if (pass != NULL) {
|
||||||
|
mg_md5(ha1, user, ":", domain, ":", pass, NULL);
|
||||||
|
fprintf(fp2, "%s:%s:%s\n", user, domain, ha1);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
fprintf(fp2, "%s", line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If new user, just add it
|
||||||
|
if (!found && pass != NULL) {
|
||||||
|
mg_md5(ha1, user, ":", domain, ":", pass, NULL);
|
||||||
|
fprintf(fp2, "%s:%s:%s\n", user, domain, ha1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close files
|
||||||
|
fclose(fp);
|
||||||
|
fclose(fp2);
|
||||||
|
|
||||||
|
// Put the temp file in place of real file
|
||||||
|
remove(fname);
|
||||||
|
rename(tmp, fname);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static void start_mongoose(int argc, char *argv[]) {
|
||||||
|
s_argv = argv;
|
||||||
|
if ((server = mg_create_server(NULL, EV_HANDLER)) == NULL) {
|
||||||
|
die("%s", "Failed to start Mongoose.");
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !defined(MONGOOSE_NO_AUTH) && !defined(MONGOOSE_NO_FILESYSTEM)
|
||||||
|
// Edit passwords file if -A option is specified
|
||||||
|
if (argc > 1 && !strcmp(argv[1], "-A")) {
|
||||||
|
if (argc != 6) {
|
||||||
|
show_usage_and_exit();
|
||||||
|
}
|
||||||
|
exit(modify_passwords_file(argv[2], argv[3], argv[4], argv[5]) ?
|
||||||
|
EXIT_SUCCESS : EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Show usage if -h or --help options are specified
|
||||||
|
if (argc == 2 && (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help"))) {
|
||||||
|
show_usage_and_exit();
|
||||||
|
}
|
||||||
|
set_options(argv);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void set_options(char *argv[]) {
|
||||||
|
char *options[MAX_OPTIONS];
|
||||||
|
int i;
|
||||||
|
|
||||||
|
options[0] = NULL;
|
||||||
|
set_option(options, "document_root", s_default_document_root);
|
||||||
|
set_option(options, "listening_port", s_default_listening_port);
|
||||||
|
|
||||||
|
// 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");
|
||||||
|
set_absolute_path(options, "dav_auth_file");
|
||||||
|
set_absolute_path(options, "cgi_interpreter");
|
||||||
|
set_absolute_path(options, "access_log_file");
|
||||||
|
set_absolute_path(options, "global_auth_file");
|
||||||
|
set_absolute_path(options, "ssl_certificate");
|
||||||
|
|
||||||
|
if (!path_exists(get_option(options, "document_root"), 1)) {
|
||||||
|
set_option(options, "document_root", s_default_document_root);
|
||||||
|
set_absolute_path(options, "document_root");
|
||||||
|
notify("Setting document_root to [%s]",
|
||||||
|
mg_get_option(server, "document_root"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make extra verification for certain options
|
||||||
|
verify_existence(options, "document_root", 1);
|
||||||
|
verify_existence(options, "cgi_interpreter", 0);
|
||||||
|
verify_existence(options, "ssl_certificate", 0);
|
||||||
|
|
||||||
|
for (i = 0; options[i] != NULL; i += 2) {
|
||||||
|
const char *msg = mg_set_option(server, options[i], options[i + 1]);
|
||||||
|
if (msg != NULL) {
|
||||||
|
notify("Failed to set option [%s] to [%s]: %s",
|
||||||
|
options[i], options[i + 1], msg);
|
||||||
|
if (!strcmp(options[i], "listening_port")) {
|
||||||
|
mg_set_option(server, "listening_port", s_default_listening_port);
|
||||||
|
notify("Setting %s to [%s]", options[i], s_default_listening_port);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
free(options[i]);
|
||||||
|
free(options[i + 1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Change current working directory to document root. This way,
|
||||||
|
// scripts can use relative paths.
|
||||||
|
chdir(mg_get_option(server, "document_root"));
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
// Add an ability to pass listening socket to mongoose
|
||||||
|
{
|
||||||
|
const char *env = getenv("MONGOOSE_LISTENING_SOCKET");
|
||||||
|
if (env != NULL && atoi(env) > 0 ) {
|
||||||
|
mg_set_listening_socket(server, atoi(env));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Setup signal handler: quit on Ctrl-C
|
||||||
|
signal(SIGTERM, signal_handler);
|
||||||
|
signal(SIGINT, signal_handler);
|
||||||
|
#ifndef _WIN32
|
||||||
|
signal(SIGCHLD, signal_handler);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[]) {
|
||||||
|
init_server_name();
|
||||||
|
start_mongoose(argc, argv);
|
||||||
|
printf("%s serving [%s] on port %s\n",
|
||||||
|
server_name, mg_get_option(server, "document_root"),
|
||||||
|
mg_get_option(server, "listening_port"));
|
||||||
|
fflush(stdout); // Needed, Windows terminals might not be line-buffered
|
||||||
|
serving_thread_func(server);
|
||||||
|
printf("Exiting on signal %d ...", exit_flag);
|
||||||
|
fflush(stdout);
|
||||||
|
mg_destroy_server(&server);
|
||||||
|
printf("%s\n", " done.");
|
||||||
|
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
||||||
@@ -1,75 +0,0 @@
|
|||||||
// Copyright (c) 2004-2012 Sergey Lyubka
|
|
||||||
// This file is a part of mongoose project, http://github.com/valenok/mongoose
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include "mongoose.h"
|
|
||||||
|
|
||||||
static void *callback(enum mg_event event, struct mg_connection *conn) {
|
|
||||||
if (event == MG_WEBSOCKET_READY) {
|
|
||||||
unsigned char buf[40];
|
|
||||||
buf[0] = 0x81;
|
|
||||||
buf[1] = snprintf((char *) buf + 2, sizeof(buf) - 2, "%s", "server ready");
|
|
||||||
mg_write(conn, buf, 2 + buf[1]);
|
|
||||||
return ""; // MG_WEBSOCKET_READY return value is ignored
|
|
||||||
} else if (event == MG_WEBSOCKET_MESSAGE) {
|
|
||||||
unsigned char buf[200], reply[200];
|
|
||||||
int n, i, mask_len, xor, msg_len, len;
|
|
||||||
|
|
||||||
// Read message from the client.
|
|
||||||
// Accept only small (<126 bytes) messages.
|
|
||||||
len = 0;
|
|
||||||
msg_len = mask_len = 0;
|
|
||||||
for (;;) {
|
|
||||||
if ((n = mg_read(conn, buf + len, sizeof(buf) - len)) <= 0) {
|
|
||||||
return ""; // Read error, close websocket
|
|
||||||
}
|
|
||||||
len += n;
|
|
||||||
if (len >= 2) {
|
|
||||||
msg_len = buf[1] & 127;
|
|
||||||
mask_len = (buf[1] & 128) ? 4 : 0;
|
|
||||||
if (msg_len > 125) {
|
|
||||||
return ""; // Message is too long, close websocket
|
|
||||||
}
|
|
||||||
// If we've buffered the whole message, exit the loop
|
|
||||||
if (len >= 2 + mask_len + msg_len) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Prepare frame
|
|
||||||
reply[0] = 0x81; // text, FIN set
|
|
||||||
reply[1] = msg_len;
|
|
||||||
|
|
||||||
// Copy message from request to reply, applying the mask if required.
|
|
||||||
for (i = 0; i < msg_len; i++) {
|
|
||||||
xor = mask_len == 0 ? 0 : buf[2 + (i % 4)];
|
|
||||||
reply[i + 2] = buf[i + 2 + mask_len] ^ xor;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Echo the message back to the client
|
|
||||||
mg_write(conn, reply, 2 + msg_len);
|
|
||||||
|
|
||||||
// Return non-NULL means stoping websocket conversation.
|
|
||||||
// Close the conversation if client has sent us "exit" string.
|
|
||||||
return memcmp(reply + 2, "exit", 4) == 0 ? "" : NULL;
|
|
||||||
} else {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(void) {
|
|
||||||
struct mg_context *ctx;
|
|
||||||
const char *options[] = {
|
|
||||||
"listening_ports", "8080",
|
|
||||||
"document_root", "websocket_html_root",
|
|
||||||
NULL
|
|
||||||
};
|
|
||||||
|
|
||||||
ctx = mg_start(&callback, NULL, options);
|
|
||||||
getchar(); // Wait until user hits "enter"
|
|
||||||
mg_stop(ctx);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
# Copyright (c) 2014 Cesanta Software
|
||||||
|
# All rights reserved
|
||||||
|
|
||||||
|
PROG = websocket_chat
|
||||||
|
CFLAGS = -W -Wall -I../.. -pthread -g -O0 $(CFLAGS_EXTRA)
|
||||||
|
SOURCES = $(PROG).c ../../mongoose.c
|
||||||
|
|
||||||
|
$(PROG): $(SOURCES)
|
||||||
|
$(CC) -o $(PROG) $(SOURCES) $(CFLAGS)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -rf $(PROG) *.exe *.dSYM *.obj *.exp .*o *.lib
|
||||||
@@ -0,0 +1,98 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<title>WebSocket Test</title>
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
|
<style type="text/css">
|
||||||
|
body {
|
||||||
|
background-color: #cde; margin: 0;
|
||||||
|
padding: 0; font: 14px Helvetica, Arial, sans-serif;
|
||||||
|
}
|
||||||
|
div.content {
|
||||||
|
width: 800px; margin: 2em auto; padding: 20px 50px;
|
||||||
|
background-color: #fff; border-radius: 1em;
|
||||||
|
}
|
||||||
|
#messages {
|
||||||
|
border: 2px solid #fec; border-radius: 1em;
|
||||||
|
height: 10em; overflow: scroll; padding: 0.5em 1em;
|
||||||
|
}
|
||||||
|
a:link, a:visited { color: #69c; text-decoration: none; }
|
||||||
|
@media (max-width: 700px) {
|
||||||
|
body { background-color: #fff; }
|
||||||
|
div.content {
|
||||||
|
width: auto; margin: 0 auto; border-radius: 0;
|
||||||
|
padding: 1em;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<script language="javascript" type="text/javascript">
|
||||||
|
|
||||||
|
var rooms = [];
|
||||||
|
var ws = new WebSocket('ws://' + location.host + '/ws');
|
||||||
|
|
||||||
|
if (!window.console) { window.console = { log: function() {} } };
|
||||||
|
|
||||||
|
ws.onopen = function(ev) { console.log(ev); };
|
||||||
|
ws.onerror = function(ev) { console.log(ev); };
|
||||||
|
ws.onclose = function(ev) { console.log(ev); };
|
||||||
|
ws.onmessage = function(ev) {
|
||||||
|
console.log(ev);
|
||||||
|
var m = (ev.data || '').match(/^(\S+) (.+)/);
|
||||||
|
if (m[1] == 'id') {
|
||||||
|
document.getElementById('my_id').innerText = m[2];
|
||||||
|
} else if (m[1] == 'msg') {
|
||||||
|
var div = document.createElement('div');
|
||||||
|
div.innerHTML = m[2];
|
||||||
|
document.getElementById('messages').appendChild(div);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
window.onload = function() {
|
||||||
|
document.getElementById('send_button').onclick = function(ev) {
|
||||||
|
var msg = document.getElementById('send_input').value;
|
||||||
|
ws.send('msg ' + msg);
|
||||||
|
};
|
||||||
|
document.getElementById('room_sel').onchange = function(ev) {
|
||||||
|
var roomName = this.value || '?';
|
||||||
|
ws.send('join ' + roomName);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="content">
|
||||||
|
<h1>Websocket PubSub Demonstration</h1>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
This page demonstrates how Mongoose web server could be used to implement
|
||||||
|
<a href="http://en.wikipedia.org/wiki/Publish%E2%80%93subscribe_pattern">
|
||||||
|
publish–subscribe pattern</a>. Open this page in several browser
|
||||||
|
windows. Each window initiates persistent
|
||||||
|
<a href="http://en.wikipedia.org/wiki/WebSocket">WebSocket</a>
|
||||||
|
connection with Mongoose, making each browser window a websocket client.
|
||||||
|
Join a room, send messages, and see messages sent by other clients.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
My ID: <b><span id="my_id"></b></span>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
Join room: <select id="room_sel">
|
||||||
|
<option value="">-- select room -- </option>
|
||||||
|
<option>A</option>
|
||||||
|
<option>B</option>
|
||||||
|
</select>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div id="messages">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<input type="text" id="send_input" />
|
||||||
|
<button id="send_button">Send Message</button>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,83 @@
|
|||||||
|
// Copyright (c) 2013-2014 Cesanta Software Limited
|
||||||
|
// $Date: 2014-09-09 17:07:55 UTC $
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <signal.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include "mongoose.h"
|
||||||
|
|
||||||
|
static int s_signal_received = 0;
|
||||||
|
static struct mg_server *s_server = NULL;
|
||||||
|
|
||||||
|
// Data associated with each websocket connection
|
||||||
|
struct conn_data {
|
||||||
|
int room;
|
||||||
|
};
|
||||||
|
|
||||||
|
static void signal_handler(int sig_num) {
|
||||||
|
signal(sig_num, signal_handler); // Reinstantiate signal handler
|
||||||
|
s_signal_received = sig_num;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void handle_websocket_message(struct mg_connection *conn) {
|
||||||
|
struct conn_data *d = (struct conn_data *) conn->connection_param;
|
||||||
|
struct mg_connection *c;
|
||||||
|
|
||||||
|
printf("[%.*s]\n", (int) conn->content_len, conn->content);
|
||||||
|
if (conn->content_len > 5 && !memcmp(conn->content, "join ", 5)) {
|
||||||
|
// Client joined new room
|
||||||
|
d->room = conn->content[5];
|
||||||
|
} else if (conn->content_len > 4 && !memcmp(conn->content, "msg ", 4) &&
|
||||||
|
d->room != 0 && d->room != '?') {
|
||||||
|
// Client has sent a message. Push this message to all clients
|
||||||
|
// that are subscribed to the same room as client
|
||||||
|
for (c = mg_next(s_server, NULL); c != NULL; c = mg_next(s_server, c)) {
|
||||||
|
struct conn_data *d2 = (struct conn_data *) c->connection_param;
|
||||||
|
if (!c->is_websocket || d2->room != d->room) continue;
|
||||||
|
mg_websocket_printf(c, WEBSOCKET_OPCODE_TEXT, "msg %c %p %.*s",
|
||||||
|
(char) d->room, conn,
|
||||||
|
conn->content_len - 4, conn->content + 4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static int ev_handler(struct mg_connection *conn, enum mg_event ev) {
|
||||||
|
switch (ev) {
|
||||||
|
case MG_REQUEST:
|
||||||
|
if (conn->is_websocket) {
|
||||||
|
handle_websocket_message(conn);
|
||||||
|
return MG_TRUE;
|
||||||
|
} else {
|
||||||
|
mg_send_file(conn, "index.html", NULL); // Return MG_MORE after!
|
||||||
|
return MG_MORE;
|
||||||
|
}
|
||||||
|
case MG_WS_CONNECT:
|
||||||
|
// New websocket connection. Send connection ID back to the client.
|
||||||
|
conn->connection_param = calloc(1, sizeof(struct conn_data));
|
||||||
|
mg_websocket_printf(conn, WEBSOCKET_OPCODE_TEXT, "id %p", conn);
|
||||||
|
return MG_FALSE;
|
||||||
|
case MG_CLOSE:
|
||||||
|
free(conn->connection_param);
|
||||||
|
return MG_TRUE;
|
||||||
|
case MG_AUTH:
|
||||||
|
return MG_TRUE;
|
||||||
|
default:
|
||||||
|
return MG_FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
s_server = mg_create_server(NULL, ev_handler);
|
||||||
|
mg_set_option(s_server, "listening_port", "8080");
|
||||||
|
|
||||||
|
signal(SIGTERM, signal_handler);
|
||||||
|
signal(SIGINT, signal_handler);
|
||||||
|
|
||||||
|
printf("Started on port %s\n", mg_get_option(s_server, "listening_port"));
|
||||||
|
while (s_signal_received == 0) {
|
||||||
|
mg_poll_server(s_server, 100);
|
||||||
|
}
|
||||||
|
mg_destroy_server(&s_server);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
# Copyright (c) 2014 Cesanta Software
|
||||||
|
# All rights reserved
|
||||||
|
|
||||||
|
PROG = websocket_echo_server
|
||||||
|
CFLAGS = -W -Wall -I../.. -pthread -g -O0 $(CFLAGS_EXTRA)
|
||||||
|
SOURCES = $(PROG).c ../../mongoose.c
|
||||||
|
|
||||||
|
$(PROG): $(SOURCES)
|
||||||
|
$(CC) -o $(PROG) $(SOURCES) $(CFLAGS)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -rf $(PROG) *.exe *.dSYM *.obj *.exp .*o *.lib
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<title>WebSocket Test</title>
|
||||||
|
<script language="javascript" type="text/javascript">
|
||||||
|
|
||||||
|
var out = function(message) {
|
||||||
|
var div = document.createElement('div');
|
||||||
|
div.innerHTML = message;
|
||||||
|
document.getElementById('output').appendChild(div);
|
||||||
|
};
|
||||||
|
|
||||||
|
window.onload = function() {
|
||||||
|
var url = 'ws://' + location.host + '/ws';
|
||||||
|
var num_messages = 0;
|
||||||
|
|
||||||
|
websocket = new WebSocket(url);
|
||||||
|
websocket.onopen = function(ev) {
|
||||||
|
out('CONNECTED');
|
||||||
|
var msg = 'Не всё подчиняется разуму. Но всё подчиняется упорству. ';
|
||||||
|
out('SENT: ' + msg);
|
||||||
|
websocket.send(msg);
|
||||||
|
};
|
||||||
|
websocket.onclose = function(ev) {
|
||||||
|
out('DISCONNECTED');
|
||||||
|
};
|
||||||
|
websocket.onmessage = function(ev) {
|
||||||
|
if (!ev.data) {
|
||||||
|
out('<span style="color: blue;">PING... </span>');
|
||||||
|
} else {
|
||||||
|
out('<span style="color: blue;">RESPONSE: ' + ev.data + ' </span>');
|
||||||
|
num_messages++;
|
||||||
|
}
|
||||||
|
if (num_messages > 3) {
|
||||||
|
websocket.send('exit');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
websocket.onerror = function(ev) {
|
||||||
|
out('<span style="color: red; ">ERROR: </span> ' + ev.data);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
<style> div {font: small Verdana; } </style>
|
||||||
|
<h2>Mongoose WebSocket Test</h2>
|
||||||
|
|
||||||
|
<div id="output"></div>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
// Copyright (c) 2013-2014 Cesanta Software Limited
|
||||||
|
// $Date: 2014-09-09 17:07:55 UTC $
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include "mongoose.h"
|
||||||
|
|
||||||
|
static void push_message(struct mg_server *server, time_t current_time) {
|
||||||
|
struct mg_connection *c;
|
||||||
|
char buf[20];
|
||||||
|
int len = sprintf(buf, "%lu", (unsigned long) current_time);
|
||||||
|
|
||||||
|
// Iterate over all connections, and push current time message to websocket ones.
|
||||||
|
for (c = mg_next(server, NULL); c != NULL; c = mg_next(server, c)) {
|
||||||
|
if (c->is_websocket) {
|
||||||
|
mg_websocket_write(c, 1, buf, len);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static int send_reply(struct mg_connection *conn) {
|
||||||
|
if (conn->is_websocket) {
|
||||||
|
// This handler is called for each incoming websocket frame, one or more
|
||||||
|
// times for connection lifetime.
|
||||||
|
// Echo websocket data back to the client.
|
||||||
|
mg_websocket_write(conn, 1, conn->content, conn->content_len);
|
||||||
|
return conn->content_len == 4 && !memcmp(conn->content, "exit", 4) ?
|
||||||
|
MG_FALSE : MG_TRUE;
|
||||||
|
} else {
|
||||||
|
mg_send_file(conn, "index.html", NULL);
|
||||||
|
return MG_MORE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static int ev_handler(struct mg_connection *conn, enum mg_event ev) {
|
||||||
|
switch (ev) {
|
||||||
|
case MG_AUTH: return MG_TRUE;
|
||||||
|
case MG_REQUEST: return send_reply(conn);
|
||||||
|
default: return MG_FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
struct mg_server *server = mg_create_server(NULL, ev_handler);
|
||||||
|
time_t current_timer = 0, last_timer = time(NULL);
|
||||||
|
|
||||||
|
mg_set_option(server, "listening_port", "8080");
|
||||||
|
|
||||||
|
printf("Started on port %s\n", mg_get_option(server, "listening_port"));
|
||||||
|
for (;;) {
|
||||||
|
mg_poll_server(server, 100);
|
||||||
|
current_timer = time(NULL);
|
||||||
|
if (current_timer - last_timer > 0) {
|
||||||
|
last_timer = current_timer;
|
||||||
|
push_message(server, current_timer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mg_destroy_server(&server);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<meta charset="utf-8" />
|
|
||||||
<title>WebSocket Test</title>
|
|
||||||
<script language="javascript" type="text/javascript">
|
|
||||||
|
|
||||||
var writeToScreen = function(message) {
|
|
||||||
var div = document.createElement('div');
|
|
||||||
div.innerHTML = message;
|
|
||||||
document.getElementById('output').appendChild(div);
|
|
||||||
};
|
|
||||||
window.onload = function() {
|
|
||||||
var url = 'ws://' + window.location.host + '/foo';
|
|
||||||
websocket = new WebSocket(url);
|
|
||||||
websocket.onopen = function(ev) {
|
|
||||||
writeToScreen('CONNECTED');
|
|
||||||
var message = 'Не всё подчиняется разуму. Но всё подчиняется упорству. ';
|
|
||||||
writeToScreen('SENT: ' + message);
|
|
||||||
websocket.send(message);
|
|
||||||
};
|
|
||||||
websocket.onclose = function(ev) {
|
|
||||||
writeToScreen('DISCONNECTED');
|
|
||||||
};
|
|
||||||
websocket.onmessage = function(ev) {
|
|
||||||
writeToScreen('<span style="color: blue;">RESPONSE: ' + ev.data +
|
|
||||||
' </span>');
|
|
||||||
websocket.send('exit');
|
|
||||||
};
|
|
||||||
websocket.onerror = function(ev) {
|
|
||||||
writeToScreen('<span style="color: red; ">ERROR: </span> ' + ev.data);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
</script>
|
|
||||||
<style> div {font: small Verdana; } </style>
|
|
||||||
<h2>Mongoose WebSocket Test</h2>
|
|
||||||
|
|
||||||
<div style="width: 400px; color: #aaa; padding: 1em; ">
|
|
||||||
This page code creates websocket to the URI "/foo",
|
|
||||||
sends a message to it, waits for the reply, then sends an "exit" message.
|
|
||||||
Server must echo all messages back, and terminate the conversation after
|
|
||||||
receiving the "exit" message.
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="output"></div>
|
|
||||||
</html>
|
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
# Copyright (c) 2014 Cesanta Software
|
||||||
|
# All rights reserved
|
||||||
|
|
||||||
|
PROG = ws_ssl
|
||||||
|
CFLAGS = -W -Wall -I../.. -I. -pthread -g -O0 $(CFLAGS_EXTRA)
|
||||||
|
SOURCES = ws_ssl.c ../../mongoose.c ssl_wrapper.c
|
||||||
|
|
||||||
|
all: $(PROG)
|
||||||
|
|
||||||
|
$(PROG): $(SOURCES)
|
||||||
|
$(CC) -o $(PROG) $(SOURCES) \
|
||||||
|
-DNS_ENABLE_SSL -DSSL_WRAPPER_USE_AS_LIBRARY -lssl $(CFLAGS)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -rf $(PROG) *.exe *.dSYM *.obj *.exp .*o *.lib
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
-----BEGIN RSA PRIVATE KEY-----
|
||||||
|
MIIEowIBAAKCAQEAwizPnrCx+/kPSdEeSJFLDXrBH+cSQsSLrCm99G1hCjzqSlIk
|
||||||
|
1BhkZMEHxBaiVLky4+M/nwhjwwRHI10h6U2Or3tbPLv7z94cPf+uCx1aF7TE3Fm3
|
||||||
|
6YnDk+CjrYVFN5GRPGOPPdFxGoc+vFvQJyAAimvchnS1ZoEQFvermwzOnKspA6gc
|
||||||
|
Px+7wnOeju9TyJuDr5ngtDXFnkcpkBNPxz3En4MJY4xJiaueafh9pIES2vSl7uP0
|
||||||
|
J/qot9v2rdiL7nt1H1vwseeEkZhQ+NLB5e2z4psyktJcwDX7wQ6j7JnKfHeP+ixO
|
||||||
|
TUORgV4foBMVOqo//Guo92Q5HoLNK77V0y4+ZQIDAQABAoIBAGEsx+LlDs3JQQty
|
||||||
|
KjOq8uKWElyC6bKcZkIMydGvg6b6AU6ceW3jnyqFJ/vMUAUSghNmQQq3yiVo2Kks
|
||||||
|
DLKTa9sKYwisE0NeJsgoUtOhJttCTlrwU4f+t/AjtgY68f7zTLnqIV+Ql4ftM0pU
|
||||||
|
sIFEFMExZbWsZrQb1w+Hd0wrRqNEbSOfSjHeigvuw1T3GH2tSBUTGTpcoewCzy7U
|
||||||
|
PKS5pkYyiKySQQNqZTac3NHPjxdK6xxzwURZp1irKdiPdt04KHLVLX8KXelt/J0k
|
||||||
|
AeYkVbpFIeQ9rNBerMEp6uRBt+nE5mvP+xx1XPqKRxuxbMyTnBXeOM2zS/a/dBiz
|
||||||
|
fwokwcECgYEA9RSsv9AQ/AR8tt+aPEQvjhJ5pn/YbCb1DA9IDXpaq3tzacGd8JHj
|
||||||
|
3kUtb79nosu85LvSkAYmtzgfJs6xZyUkscra6q+xlsJ12QRxLzqfxcp9Y0wsdqM4
|
||||||
|
AcOwuiPKrjkWxOQpyWPWRwbmAefLfRMekHt4Y/QY0CwhslpnsOsj3O0CgYEAytOE
|
||||||
|
8I4GBfSQfSjXwfrso++Oi75VSsl5ZeiMGihfEhYFTE8/3rEZf7nf9iFSkN3TT+7f
|
||||||
|
pFqQzddzPBZXlpVM6k1jcEjdpJizbeR8DmICpABFrZvKz1o8pQ2Yw+FYI86ih0x4
|
||||||
|
806snMNgg/RgcVijXKFrC5joJOI+DVgwWoQyMFkCgYBxt4MkiV2oIkjf7ca6GgVa
|
||||||
|
zbXGjOGV5Umkq96J6nDxyplVw/IN8xOhScX4aP6kahaep4vfKguCzjaeIh/stS5e
|
||||||
|
lLqZVKZ5Roe6B7ag7HnAI+GkVm73KWrOXse8xui/iFvJRfkhqgJ9+HR3A9/GjD2N
|
||||||
|
Ws0Uy+lLhn6oLAya6bA9TQKBgAVfZP4aRP6TY+Bs3Io+41XUWqpI+GlqvNR+PHfU
|
||||||
|
6e/ItYs37jEv78T6X3xdlZpQxfAwG6x22a8aLetBjEBo5Aiw1Bl9VKGvidE3ZDHd
|
||||||
|
VsSRXUckAVNMyJ52pb1KktMf/h4nYGzRgLEGW+Ai8QsPlgQ2ImfEPSH8/DfORjmf
|
||||||
|
ltTBAoGBAMxIZ52DrJvuxogSOfA1MoCD6a90trkXCquvi+A/fXojZ8BHmMQshvhK
|
||||||
|
rAO7SDIV1i1Nh3jQ/oFWE8KOprqrOLO6jNTyF65vh+zk7ztGsEME9FkDhHasUiXf
|
||||||
|
t5PE9KeTChHRvIa4FGCl9We9GftE5Ii77LWMOIq22pyxYbvHQFEf
|
||||||
|
-----END RSA PRIVATE KEY-----
|
||||||
|
-----BEGIN CERTIFICATE-----
|
||||||
|
MIIDlDCCAnygAwIBAgIJAIOoO+AapJ5WMA0GCSqGSIb3DQEBBQUAMDoxDDAKBgNV
|
||||||
|
BAMTA3dzMTEMMAoGA1UEChMDd3MxMQswCQYDVQQGEwJJRTEPMA0GA1UEBxMGRHVi
|
||||||
|
bGluMB4XDTE0MDgwMzA5MTU0NVoXDTI0MDczMTA5MTU0NVowOjEMMAoGA1UEAxMD
|
||||||
|
d3MxMQwwCgYDVQQKEwN3czExCzAJBgNVBAYTAklFMQ8wDQYDVQQHEwZEdWJsaW4w
|
||||||
|
ggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDCLM+esLH7+Q9J0R5IkUsN
|
||||||
|
esEf5xJCxIusKb30bWEKPOpKUiTUGGRkwQfEFqJUuTLj4z+fCGPDBEcjXSHpTY6v
|
||||||
|
e1s8u/vP3hw9/64LHVoXtMTcWbfpicOT4KOthUU3kZE8Y4890XEahz68W9AnIACK
|
||||||
|
a9yGdLVmgRAW96ubDM6cqykDqBw/H7vCc56O71PIm4OvmeC0NcWeRymQE0/HPcSf
|
||||||
|
gwljjEmJq55p+H2kgRLa9KXu4/Qn+qi32/at2Ivue3UfW/Cx54SRmFD40sHl7bPi
|
||||||
|
mzKS0lzANfvBDqPsmcp8d4/6LE5NQ5GBXh+gExU6qj/8a6j3ZDkegs0rvtXTLj5l
|
||||||
|
AgMBAAGjgZwwgZkwHQYDVR0OBBYEFL54xAgtJTW6US4Mbr4QG0yKzvaxMGoGA1Ud
|
||||||
|
IwRjMGGAFL54xAgtJTW6US4Mbr4QG0yKzvaxoT6kPDA6MQwwCgYDVQQDEwN3czEx
|
||||||
|
DDAKBgNVBAoTA3dzMTELMAkGA1UEBhMCSUUxDzANBgNVBAcTBkR1YmxpboIJAIOo
|
||||||
|
O+AapJ5WMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEFBQADggEBAJz/RzMa9Wa2
|
||||||
|
eEXed7ijH1gcWtgVsVT1xZo0ksFl+QJ5Be1AJpOIe8nKdzYjxPWUkofIoaGHdMLL
|
||||||
|
Uc/udRzsXncup+0mD+Yos6Cqyo9yHq7L1HbXfKYZtBXIjWHdF2+RP8j9tHfITXYI
|
||||||
|
Pb2zsQ+A6PYpp5OLGZTDAnI2qffqsmwXFNhPfFhOANrGlOjsvy1P7JDzvymj/90m
|
||||||
|
NomlO3vjxLHOf6MvedTgCB0dRcAoUWPgbxPWifjBmGBjQjA4ukMQ58wbBQgvIoCW
|
||||||
|
obrXmLCNZIkpWTw4gMRYquY880IYK/OuFNJH/dawxx/WzuVr7IdLmbFY15zf5TUb
|
||||||
|
ZpIpwqRCysg=
|
||||||
|
-----END CERTIFICATE-----
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
-----BEGIN RSA PRIVATE KEY-----
|
||||||
|
MIIEpQIBAAKCAQEAwOp1RS9RnE8L5TszDPIOmpf/1pqb+ki99l/sGhqB/KZBKCuq
|
||||||
|
uoCc2VPK3PCByBE15/xJ7t691FnJfForI9DO5p2R0FPD6o357hqRsh0dJNBm0VgG
|
||||||
|
iNtLQ8lyYoE72HJbkgCAUZW4N0OBibOmvp/s3Fmr7rEjW5LmZxOtX+iULKIUZ0w6
|
||||||
|
gJlM8G5QA1SuqndN0PbPx+RZKSXZCoJj+Nboqw03nyJUexzs+lynR9ITMziUaaVM
|
||||||
|
4rzG+P6joQAnUkDNydxo/d4tj4xaioZdKxWLYEbj2BUtOlJJydotWo2wcG85ONrT
|
||||||
|
Gw0ltR1vku1hidMm2QL30uGIL5SeqyE8TqWk4QIDAQABAoIBAQCxHtKauc45MA4g
|
||||||
|
4hCGAzvLTmETnRI2YlEfAoTYlpvf5pkOE8GFyI25r4gjACJ4GO0gWG9dBF7Pt7wZ
|
||||||
|
EwRmttEvxV3aIv5OvRnKNdSs7rQSV9D+xc4CGy1oSG1f6X2TxbMzQoiN32OqQa2O
|
||||||
|
S0Z94IFs8lu8JCDtc9tcqiFVXEmnC3RvJZOShWpsCsbmh5ue1Xed0MQQ47vt7Zt7
|
||||||
|
I0cutvwSFJMsZkZUJp5+KjVNYo9TEJxVD3m2NJNJxBfBoRVHXNii3hUEHcTIdIAz
|
||||||
|
omtRwBU8AKgJirGIRo1h2ZFyubI8ScGOJWIiWMQvQqTHKiOaz3yUar1NSG+kFn0U
|
||||||
|
cj7s3FhdAoGBAOQbx8Jwhtp4iOkP6aW1nVTgiaTj4LMlyJZioFwgPFRIcA3oRHt9
|
||||||
|
5SRetmgFZNvcuNw1udfeaObKmlzxwUruprwOpihgAQWJFTtOjQNrt2gsYuX4l3W6
|
||||||
|
T46dO2W1pV+mW4A5gt0aqhLv7pCS4lpreNAqyHSPqcQWcCeiTzmp/LfDAoGBANiB
|
||||||
|
FQOTyMElR9OzKwmcGfIvnhUfJQwi5qNE3R+xXiP5x36a9HQBey5ri2lnBle0Ksr/
|
||||||
|
G+RKoflmk1eFXVHN0w35yw0dVco//WE4vOknldNEnIT85k02ld8lDTa2Q/EJZtPH
|
||||||
|
un6zeU0Q2/4SZ/GXPssEZPlpPM7WtQzztlH3+sqLAoGBAKnhppvAgi4ippQsLa4j
|
||||||
|
29BiiSAsNiQ1d3XIbfUubL+4UvuIh7gQwp6biu1dVwgHEgWuXYHPOgDn0p51zaao
|
||||||
|
pbRYlJZtKVWeChnpHkv15NnIdL8grGwZHTbxElNlPIxHsM2GB1fzi8YeumUhf0In
|
||||||
|
2AnwUum8NIq8yzo5PxeK6ZNRAoGBAIEA2Q6ankJH/nZsCbbeJq+iI+Wd+ysyGI8s
|
||||||
|
Vz2tJ9Tz3iTYG9SLlWRhfF4/nw3fMqhmPa5Xsg+zSRQbSTGXHKz1LEISOq4aVtX5
|
||||||
|
QscCaUnLVh//uRJE9iRSJX92NyGGYpjKJ5ubQSnkY9EOEpVnc2jwo2HhjPQKBzNC
|
||||||
|
fF53Dh5lAoGALwTN5uxrBZLPu4DtZkOosKkv4l+kzFoOjLJR4vA7ONBx2CSe9G7F
|
||||||
|
tSsH7lZS3b0mxBWjO90WhaSvtMWWrfqq8vrqmoTE795fYxNoLfCLK13W31aTDUsI
|
||||||
|
pQRJIL30MPvASbcFHN2MD2dXz2nQzY8C9lvtvap/krYiDKDU2L7+iP8=
|
||||||
|
-----END RSA PRIVATE KEY-----
|
||||||
|
-----BEGIN CERTIFICATE-----
|
||||||
|
MIIC7DCCAdQCBRQHBXNHMA0GCSqGSIb3DQEBBQUAMDoxDDAKBgNVBAMTA3dzMTEM
|
||||||
|
MAoGA1UEChMDd3MxMQswCQYDVQQGEwJJRTEPMA0GA1UEBxMGRHVibGluMB4XDTE0
|
||||||
|
MDgwMzA5MTU0NVoXDTI0MDczMTA5MTU0NVowOjEMMAoGA1UEAxMDd3MxMQwwCgYD
|
||||||
|
VQQKEwN3czExCzAJBgNVBAYTAklFMQ8wDQYDVQQHEwZHYWx3YXkwggEiMA0GCSqG
|
||||||
|
SIb3DQEBAQUAA4IBDwAwggEKAoIBAQDA6nVFL1GcTwvlOzMM8g6al//Wmpv6SL32
|
||||||
|
X+waGoH8pkEoK6q6gJzZU8rc8IHIETXn/Enu3r3UWcl8Wisj0M7mnZHQU8Pqjfnu
|
||||||
|
GpGyHR0k0GbRWAaI20tDyXJigTvYcluSAIBRlbg3Q4GJs6a+n+zcWavusSNbkuZn
|
||||||
|
E61f6JQsohRnTDqAmUzwblADVK6qd03Q9s/H5FkpJdkKgmP41uirDTefIlR7HOz6
|
||||||
|
XKdH0hMzOJRppUzivMb4/qOhACdSQM3J3Gj93i2PjFqKhl0rFYtgRuPYFS06UknJ
|
||||||
|
2i1ajbBwbzk42tMbDSW1HW+S7WGJ0ybZAvfS4YgvlJ6rITxOpaThAgMBAAEwDQYJ
|
||||||
|
KoZIhvcNAQEFBQADggEBABPLmq6zKOMY0WRjtBoSymq6f+vXeEwtWCfVejdG6RlG
|
||||||
|
/PTdCKNvp3OL7FDnmQQ+r5rMs4+Os4fX/g315QFKXu01rqxmFb2XVNhhaECdUWtK
|
||||||
|
QP6ZoVZviUiDjhK6a+05aerPCJpkGy/lz0W6gmj4qhuAQbobxb6UbzqTRYY+ZwGk
|
||||||
|
+SI3TAVCdmXFlxN/M9b0DbmkseRG8GGFmyRYyRb84vbV6zemFI++5ROUT9zXT7ey
|
||||||
|
nYfFJvAAk5jJhY5UP2aMlVWYYa4jUZrrPLoiBLUuRrp67EKGebCH9mgCIf8ztNJF
|
||||||
|
fpuvcz++LUeRyTlAGDefe+FyHGIwFzIfZn39D7CaRvM=
|
||||||
|
-----END CERTIFICATE-----
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
-----BEGIN RSA PRIVATE KEY-----
|
||||||
|
MIIEpAIBAAKCAQEAyal0BZKRYd+Wpxv4MB8LjjgXv/MxSN5oSAKThlCZ/AWG0FEP
|
||||||
|
d4nrBACT2xUxwo+xbYl3joiwL/eCPAp6QNKRGhvXVOnSIFVSjKZWbdX+toqK9pDS
|
||||||
|
QMDTL4ZJvK6pLZXknyHjEr0PxZh22F7iS1+C8HxBPj0Xgg/u5/+jPhFPPZ1d5elv
|
||||||
|
4cm/z+xy6RjFlA80aIeK7dcWssOsOIPjUNFfmoYgR63ScZIlUZj6j8VX9oX7fJID
|
||||||
|
jumGajDxgD2nBWFbHcGKin6bz/wZ+OIhXOCDdY7oKuMW4JiBwbfBtedkQuQYS11s
|
||||||
|
PRFFYDLoZH59Ivcu0c4F2tomE86qM8THsI910wIDAQABAoIBAG55FAQRfO8/C0rU
|
||||||
|
eavy9eOdOvV+hltC66G3N5X3BcQYSvhHz89OkJ6KqnT0MWRCT5KQIhzFKK++SWwW
|
||||||
|
2U41jCPfaKEtzlzEIQrH/MUC3Byn3OSiBWxPteFtEWv5ytgcKzg52iljxQYcNc7m
|
||||||
|
e9WKpzKS/zLXSM+JZvlVA9p2pRA88kUZ/EE5H+FW3kHj5eGNqX+cxUVpL0VKTiLv
|
||||||
|
aXWjYotpmDJW/Rn9wRQethm6Gdx3bvo+LEVlJRELNq8NM5H/tZIVRzudJOgzsw5v
|
||||||
|
3OQGhfKB6Eg/vqSFoZxX6ApXDxmtaSO83B0kK550bDVv4sBnOExGjKCzybt04tet
|
||||||
|
KtLPPoECgYEA5WUD+mFL99sCX6pzIyUVlxp9eUhVy5nvhoF6u3mvhay2XsZUY0wy
|
||||||
|
+/qVqYSZTvuvJ6JSXc4iVIX8u/gj7914805AwujepIF/8E0AaXLBMndzDE4ze5S5
|
||||||
|
2RHI7Cy4/3AWOcQ9wFFmUdSs7/6oAkcQtvzP40hGg3J2jAEhIdCqmbMCgYEA4Q0G
|
||||||
|
BYP9XeTdh0C+BcP9B5VUEC0jerYS8VqVqriB+9JfT3InI7K08sOG2DiQQBhAHuzL
|
||||||
|
RhCECU2a9j0+u5F5JNeY5m3IhU73Lw+lOlUkMaAO6x7JJEzhXhonE7Kv8fWygr/0
|
||||||
|
OB7yzqz+YsWdQ2VOPZ88ntlAYE65vzcaVswZY2ECgYEAr7Gt2VA6Ei0A5Wq0Yr+d
|
||||||
|
iKz2WzUG2TkelqOG8B4kTDrbNz2qFp+fERV9GWgAz9i+75lIgqZF7vzsdL96LtYv
|
||||||
|
NBLEUURwegjhh5hCb4E/7bpFOLCQh9+CdHpFrHYYfzRHIZlnPmxZ9OTyS6J85bmu
|
||||||
|
WKjLRKXvs++wUkzvJmoesDcCgYEAkTOB6xUZ5/a+J4HSGI43NylVr4owFgBbgHVd
|
||||||
|
k2SwGPXGoM+aCSJINUmKOv9jsrbyyAEntfD5/7aegLlLPGHDs82WzTWP5tLoEOkb
|
||||||
|
ReOhEpOejHy0ckNYNQrSo5bqhkZsAogu3fa52jcrejbeHJnEPWX8CtFJA9pHZeP7
|
||||||
|
jnzo9IECgYBefHg0dymSj2xxN0XmC+S5cvQu2K/NYUpatoWvHnPiQ87wIM0AWz0O
|
||||||
|
D0ghEI+Ze57NbtSrrcTE7hY/LHrAqXGAB9XNIM5g9Pp/lM+XjzKVr1FMf4xpuHf1
|
||||||
|
VJJRHrOU14CvMvKbgbPrL6B0d5yrYmeex7GxNw0ZVvtjCa502Eck+w==
|
||||||
|
-----END RSA PRIVATE KEY-----
|
||||||
|
-----BEGIN CERTIFICATE-----
|
||||||
|
MIIC7DCCAdQCBRQHBXNGMA0GCSqGSIb3DQEBBQUAMDoxDDAKBgNVBAMTA3dzMTEM
|
||||||
|
MAoGA1UEChMDd3MxMQswCQYDVQQGEwJJRTEPMA0GA1UEBxMGRHVibGluMB4XDTE0
|
||||||
|
MDgwMzA5MTU0NVoXDTI0MDczMTA5MTU0NVowOjEMMAoGA1UEAxMDd3MxMQwwCgYD
|
||||||
|
VQQKEwN3czExCzAJBgNVBAYTAklFMQ8wDQYDVQQHEwZHYWx3YXkwggEiMA0GCSqG
|
||||||
|
SIb3DQEBAQUAA4IBDwAwggEKAoIBAQDJqXQFkpFh35anG/gwHwuOOBe/8zFI3mhI
|
||||||
|
ApOGUJn8BYbQUQ93iesEAJPbFTHCj7FtiXeOiLAv94I8CnpA0pEaG9dU6dIgVVKM
|
||||||
|
plZt1f62ior2kNJAwNMvhkm8rqktleSfIeMSvQ/FmHbYXuJLX4LwfEE+PReCD+7n
|
||||||
|
/6M+EU89nV3l6W/hyb/P7HLpGMWUDzRoh4rt1xayw6w4g+NQ0V+ahiBHrdJxkiVR
|
||||||
|
mPqPxVf2hft8kgOO6YZqMPGAPacFYVsdwYqKfpvP/Bn44iFc4IN1jugq4xbgmIHB
|
||||||
|
t8G152RC5BhLXWw9EUVgMuhkfn0i9y7RzgXa2iYTzqozxMewj3XTAgMBAAEwDQYJ
|
||||||
|
KoZIhvcNAQEFBQADggEBAE20gAykuuaCoP49GnZ/Z6ZItFry4Fl6iCWBDdEsWI9R
|
||||||
|
wRNYumeaeejdFPXfSJdTT7UlrVK1WWGLQLq+ixHRDX+V9T67ou85F92H/OxbUoPr
|
||||||
|
iz/TZAEBTC1GvTJl49lsfPl1dTWH8T4Ej2hxCUvIJrkCkI2Ov4Wwef6A26USrwBt
|
||||||
|
S/CPInjCe6qkE5E8xfTDl8k5IIgMadTPhi5sbV2piBJoN4floJPqR0hdDKbgUymn
|
||||||
|
5WNSiRkuI6UIDZwQEp+A8TmFBHbSwfTGt2Sz5iI27P8J6pFvR5eRA1k57dRUWNXC
|
||||||
|
WAU1nqteP3QAjj9L3o8IO0T62scaiJX8x01gTmVVe2I=
|
||||||
|
-----END CERTIFICATE-----
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
-----BEGIN RSA PRIVATE KEY-----
|
||||||
|
MIIEowIBAAKCAQEAwXIMpHuTNsro2pxe6y1mu27md2Olhvfx26rO3maO0/stIC2z
|
||||||
|
G/xQatFDLIWzfKFYOT0iSEj252ENFDCw6aDRKpiaUFtXcMAWkNkkKntEyoEgE45k
|
||||||
|
rTrvpay0v0B+ojwjA1Jz/9v35cgvDwTs3vNFno5HhI0m2YF4ocTmeHJ6u0xRL/qy
|
||||||
|
atfKsfuVq5s5CXOYCXp3Ux6kJ1c22J0EdZMvS75SVjAZgRkqQpqt9L3e2ZBCEgUr
|
||||||
|
w0KwlERvpeJF+sJJOshXjfrDzvwL8IpPnGZLJNINFbSJMk5MFGcMyq/28pSZLB9E
|
||||||
|
Dh8vk5D5gUnxM60ONUy2nYPcYr5p1PLDiC8hfQIDAQABAoIBAB0Twpi6xn8W8vdh
|
||||||
|
R9c75NRJsDTD8q6d+GnXe+7sJY3xlG/gzqpnO8NCn0FC+57BNdystsl8xjgzW17s
|
||||||
|
jrsfZDFt7MwlXrhg90NgkFIeY1G5JRQrdDChykHx+t1AmYhTV8P5EdykuNd+RqyQ
|
||||||
|
RfahRJa3tkJTYUKSdoqCaU4zjwU2CSxltuJx24V+WoZE12EwewJ8HPg2XTnbsGE7
|
||||||
|
Fnx5s29O4ItM70CC0536AY/OgfuPix5z573VQiilqqfOQkVkKa1fHd6tGpWU+3kH
|
||||||
|
X9FnhEBf9cN9tVgmaB0sCSVVrfgqSXg1EwKHqe/+FCumuesA68Q35+/K3b+QrNiR
|
||||||
|
ka2yliECgYEA+V/4pbgG/lPYvTwWhKxGXXdJmrSPgZC0mwE+fRuYkeptbIkS0pwt
|
||||||
|
/UDTXk9nttj1f1ZJ3NgQbT/1w8jpXfsCJ8VeGzL9+ADhRKWVFRlu/nyFCMXawLEV
|
||||||
|
rot7SEr8BW/m8moHgY5lYipM3dXJPk0F+KLrN60U/aNmFUtPGW802BkCgYEAxpWy
|
||||||
|
FGL2sEQ0QaRDTcqqF5faVqw+5rVGvN+EX5o26E0QWWnoo3L2c2/5X93iBl+Fqtnm
|
||||||
|
9jSIQUC3rYOawKnZ/HcIE2ergFit/p6JaV9NiLDRtDUmSzlffEGVCj0neYFsnWp5
|
||||||
|
zcmkUyZ6fr19EmKQWfdteNBlXue32TjVlFbfUQUCgYAfMbgi0sBdNBPaqBeRBRPQ
|
||||||
|
QUm9xnRlGrrc4Oz2LWuKZS7G8uad3deK5H8MPxaUMtOS2DJpI8X6RJPzp8A5d1qv
|
||||||
|
quq4sEpAqauEMMpTV1khEGZ70HQqwnwZ12zWgDrCW1siW80QkcVw4CW5YjLITk4+
|
||||||
|
6fJOhqInkDcG1uLQJa8QkQKBgQCfs8l4DbJ4RRGFbLXXvNGXkb68j18yqLxPrq3F
|
||||||
|
OL9JiJhKYBsAP7clVPrG9ykLmQxlP0I35D1jxMkymLD+mlo9Z/itqmTJHggnyZWW
|
||||||
|
kVdIQ3MSKuA2BNjek9tpVY8Gb2hLHFMChVRKrpo6jOclvvB5+bsnOukbLtyyq7tP
|
||||||
|
xaFohQKBgByCmlltjOBWZLFLeA1x8j3inm9zM/FAJuANbHUOZ1RwrRcNFbDv/FXm
|
||||||
|
rLPnPCaH5AwAWhVRJcNHo37Ee0s/xqe+Q4dG4xL943k+6KlopAw1SXhuXF6PnBfF
|
||||||
|
y+ArVlh9d2oWN5cBEzRddnWnKJuMi70kMzYf6dIW9s/dHbq/gFDy
|
||||||
|
-----END RSA PRIVATE KEY-----
|
||||||
|
-----BEGIN CERTIFICATE-----
|
||||||
|
MIIDlDCCAnygAwIBAgIJAJDtcXU2wiJIMA0GCSqGSIb3DQEBBQUAMDoxDDAKBgNV
|
||||||
|
BAMTA3dzMjEMMAoGA1UEChMDd3MyMQswCQYDVQQGEwJJRTEPMA0GA1UEBxMGRHVi
|
||||||
|
bGluMB4XDTE0MDgwMzA5MTU0OFoXDTI0MDczMTA5MTU0OFowOjEMMAoGA1UEAxMD
|
||||||
|
d3MyMQwwCgYDVQQKEwN3czIxCzAJBgNVBAYTAklFMQ8wDQYDVQQHEwZEdWJsaW4w
|
||||||
|
ggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDBcgyke5M2yujanF7rLWa7
|
||||||
|
buZ3Y6WG9/Hbqs7eZo7T+y0gLbMb/FBq0UMshbN8oVg5PSJISPbnYQ0UMLDpoNEq
|
||||||
|
mJpQW1dwwBaQ2SQqe0TKgSATjmStOu+lrLS/QH6iPCMDUnP/2/flyC8PBOze80We
|
||||||
|
jkeEjSbZgXihxOZ4cnq7TFEv+rJq18qx+5WrmzkJc5gJendTHqQnVzbYnQR1ky9L
|
||||||
|
vlJWMBmBGSpCmq30vd7ZkEISBSvDQrCURG+l4kX6wkk6yFeN+sPO/Avwik+cZksk
|
||||||
|
0g0VtIkyTkwUZwzKr/bylJksH0QOHy+TkPmBSfEzrQ41TLadg9xivmnU8sOILyF9
|
||||||
|
AgMBAAGjgZwwgZkwHQYDVR0OBBYEFLK4flD5QD/mRufsPx63xlEKM8pwMGoGA1Ud
|
||||||
|
IwRjMGGAFLK4flD5QD/mRufsPx63xlEKM8pwoT6kPDA6MQwwCgYDVQQDEwN3czIx
|
||||||
|
DDAKBgNVBAoTA3dzMjELMAkGA1UEBhMCSUUxDzANBgNVBAcTBkR1YmxpboIJAJDt
|
||||||
|
cXU2wiJIMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEFBQADggEBAEYD+CReikYr
|
||||||
|
Rzvk+/Vdi/7IcaH9CFknIdtineSIw1y98nxnbnNJqxwfNaRblbYvg6OFdUI3POuI
|
||||||
|
+rdYLCFl8z3tWqRHLkGqHSJA9xcng3jLJxz0+ctiVcekJvXaB3O6eSZjhGbmmI/s
|
||||||
|
CQhdy2zpEIVOeUq50DrSJp9CknyGu/IkaGx5GOZtkiHMrpig50CRjX1lS6qrMNYp
|
||||||
|
vB8gfuqpjsL4Ar3vg+lgMSwNWXBNHrIRPHB5VEzBEdmLFZlvueR0ooEMCklpwX/a
|
||||||
|
lFImVc6JcY1pBEkHTiTLGMpGAHG3I1aVUaWb3L+V+2ym/KNRNL5C2+1eiqql5u8m
|
||||||
|
HUaOcNC90ew=
|
||||||
|
-----END CERTIFICATE-----
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
-----BEGIN RSA PRIVATE KEY-----
|
||||||
|
MIIEpAIBAAKCAQEA0ucemqFwBFziVOgTgx4mZII4WnGDpA/rWAGHvUZOqy2dQ3Pz
|
||||||
|
woGKxBaVPAl5kxEosROVGa7dTuq5yFZ4XIGvwCKxF30vCmdGCytqq6MMp904jG32
|
||||||
|
KikkmjCApIMGxMO4eoBHZZxiyVvKTbg9M2CRXErwnYWhFH/qGdPnuo0CEaHJA4VK
|
||||||
|
A9incT9dpeEhU30R6ajAe/je9rCj2OMLMFSMfd51L/VYfO60zDwUNY7YVIghQZgJ
|
||||||
|
e44EVGsp1pXaqaD6o3PvGY3ohw2aZjJzlJ7MJHbKV9lft98R3pklbpBzMH849cEy
|
||||||
|
Q/51L/rlfTUgCpTy7wEZpWHQNtHfu/1rhJjpNQIDAQABAoIBAQCUNIHXG/dBuZv7
|
||||||
|
GpMLotZL7w520Co30lAJqhmfMpb5x7YpvoPffXTsUwpQBECAzqAPv7kZMT6nxF8F
|
||||||
|
n245Y5EDrd1QqlGyN9yK4Nm2/39XPygL1wITopHsIIVmFgVdpEQxIZAKoZjx8yT4
|
||||||
|
9K1dO1Eq0CbCKzOE2lbCC51eBNUdWZIMxwC6O/j/KoIkZ/HwlG2hpUuXg8x/XawA
|
||||||
|
ZJDCoTcWHCjYP10FxKVN3vAyWM2IM44o9IbsAGEOswR4gUwRsgq6Ehc1U59XUHi+
|
||||||
|
x30oda55I1/8xD+SfP/zk2dDPHkv/hq5+258GU/THsw2+AAexocvSIS/g9EppTEg
|
||||||
|
biFaDKzJAoGBAPqey10JeyiOlHbBjoSSa7lJYUjocQANFQ4ayOAgfNX72iyabrKF
|
||||||
|
p9sVAeO/nM00+DPrm2wWws03ScsPeh+9BDJMPRBUHfSNp7+F+oyj7PWHBEFHbyO9
|
||||||
|
5HnYZP+1vhdG2dYPIY2gRSFXpiGn3j0M1D0w9c7Ilm8ee3krdR4E/mw3AoGBANdu
|
||||||
|
EfS1dK3+m7sEgc2+3U32z83GpuCHeUIKGPYMLI0fIb1CPpboHU9YjOFJZH9iIIdl
|
||||||
|
00JC963O3+pqLe0XbMOmBVt9QjZfhfB+AY+JHtbPgoQVLtq9X/WvW7h3xn6S971r
|
||||||
|
Crkhqay3Cs4BzsgYDYraQCTw3oq4twR9Nuy4etfzAoGAXOsG5wWe3diO/sCggFJx
|
||||||
|
Eg88vHVBgA1ZoxMXKtGgtw1bRHI1XIblRvqw6qmeDw72fvl5dEe0DbXT7C9ezemc
|
||||||
|
ZrGRaj5lpMfoS7/2trIIJrfaQgGkGRJMZUhvmcbeJW8lUJHnlMS5HLWMaKn+YZAi
|
||||||
|
GFXQrMv9ylD44mHUWD7tvV0CgYBNctPfvvCQsQ05ofgsiKa1Jbs1hmpuJCYy2MB6
|
||||||
|
jIvjvEJ78PnhdNc8tGAJikIoDZYWN0RI+RxkDxCvDLcwGpDOkbwxVQnd1F+pwxM6
|
||||||
|
kBhXL8kDRT5QA28hO4bk/aKN1LZeEcKMJg8C+ddXkozNoOAVgDs5TKMlCh057u41
|
||||||
|
EmmPgwKBgQDOlYi7fPYOCy0yjHMxSrp2SZOS06AMWGbbCoGkjRtvuP+FmKSNB+LZ
|
||||||
|
pOSEPJgzjsRutKjneww4LpV6dViAyTcP5JoeQpokHf7UVo7yq2QH/iwF3zJwsC/S
|
||||||
|
OuVLkqpZzWuye/QCH5NOTfw27ye8jG8VcQW2QPbcbkLXLM7zg2yX7g==
|
||||||
|
-----END RSA PRIVATE KEY-----
|
||||||
|
-----BEGIN CERTIFICATE-----
|
||||||
|
MIIC7DCCAdQCBRQHBXNJMA0GCSqGSIb3DQEBBQUAMDoxDDAKBgNVBAMTA3dzMjEM
|
||||||
|
MAoGA1UEChMDd3MyMQswCQYDVQQGEwJJRTEPMA0GA1UEBxMGRHVibGluMB4XDTE0
|
||||||
|
MDgwMzA5MTU0OFoXDTI0MDczMTA5MTU0OFowOjEMMAoGA1UEAxMDd3MyMQwwCgYD
|
||||||
|
VQQKEwN3czIxCzAJBgNVBAYTAklFMQ8wDQYDVQQHEwZHYWx3YXkwggEiMA0GCSqG
|
||||||
|
SIb3DQEBAQUAA4IBDwAwggEKAoIBAQDS5x6aoXAEXOJU6BODHiZkgjhacYOkD+tY
|
||||||
|
AYe9Rk6rLZ1Dc/PCgYrEFpU8CXmTESixE5UZrt1O6rnIVnhcga/AIrEXfS8KZ0YL
|
||||||
|
K2qrowyn3TiMbfYqKSSaMICkgwbEw7h6gEdlnGLJW8pNuD0zYJFcSvCdhaEUf+oZ
|
||||||
|
0+e6jQIRockDhUoD2KdxP12l4SFTfRHpqMB7+N72sKPY4wswVIx93nUv9Vh87rTM
|
||||||
|
PBQ1jthUiCFBmAl7jgRUaynWldqpoPqjc+8ZjeiHDZpmMnOUnswkdspX2V+33xHe
|
||||||
|
mSVukHMwfzj1wTJD/nUv+uV9NSAKlPLvARmlYdA20d+7/WuEmOk1AgMBAAEwDQYJ
|
||||||
|
KoZIhvcNAQEFBQADggEBACCCAJypO9DFU6GeOH+FwE0JCLTypHoIwERWxNL7xfjg
|
||||||
|
rwVqIxwAEo+fJjL+QY7JbAb/eqKaXIBYkAF2lFc4iEmecXX/A3Aqw95AYi78o7HD
|
||||||
|
MwRPqJha9mxLcCWwjX8XK8pT152BvYFPNhi+6jd++rDRxKDfmNvgdUQ2/YW6a5Wv
|
||||||
|
zEmLDPUWRIuMQIEmOa2/JhlllDviMExTw51nbqYgCghycRvDACyQAuu8re7P6gcg
|
||||||
|
bXObNlfxcU/8Ph6MFI+2S9ODtQ4BHyuKd4kRNsYn8vV42a0h3bCYSGPk3kSIgxd7
|
||||||
|
XijwHT/o8E9ddH2BvDv+6Nhno9C6/MbezEOIs4nlhRk=
|
||||||
|
-----END CERTIFICATE-----
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
-----BEGIN RSA PRIVATE KEY-----
|
||||||
|
MIIEpQIBAAKCAQEA29iFnMf4pjty6knOt4wT0joPUlU2dGCFWxQ5Eg77Yx3Lou2a
|
||||||
|
FOzNGp7zLYH8gauOK+mgY+B9cBv8PvVtUQQKB0SKTTV8ZNKVyP3O5F2gRSJ+tHtT
|
||||||
|
FqaPfG0WPOn/f02YbOpAe6Rk+NnlJoeuBxG4uapUSq7r0mTGJQe+52y1LcMs23ID
|
||||||
|
ENBfDoUMVt5vCnF+cYK5ndeFVLyPO3JjohDH1zv3a9ECG28rtjKHLpNYFDsPJaD7
|
||||||
|
UPuyyk3hIvfPCZoJOUlEVfpLT/lM+9oCPnq9PwIp5NqYofkuc3eKooCo7N4r4IlP
|
||||||
|
Ajktaao6b0ScNwNQB3leOIdEUFSIYy8N1JszVwIDAQABAoIBAFlIvjrGG/2m9yyf
|
||||||
|
fQyeHw6p9b8CTHNHH+G1fNgQrZe7ahBpXsJQyZueIjTBLcOb4MmEwFbPvSHiu7b2
|
||||||
|
Bcd5VHlPJLvmlPZ9b8eJDJVCUOzC7aJu03fHfU6THwzuG42f/d9942JTiY5nL+FO
|
||||||
|
CSdl0xfUTRdnou53buFrG+TxCUPj13HP1HY6DAVzEIq1H4TZwIZo7KRRTIYpTB3P
|
||||||
|
6yvr9xsISLlnmfQ4tp2pApl5o+bHJEhr1VO6SAT/pSyShi79KmMMqYtyTmOMz7w6
|
||||||
|
VJkre5ybnXBDN6tfMHWqdobJ4gRWK9rqf+LIZig5XQnyzkue8k+I7aPgO4xNFh56
|
||||||
|
dkejQcECgYEA9MDCWViqpfvof+epiKzccqnIRnz1EfHdRQjiKsKGRe39+K+pyaqJ
|
||||||
|
FOOPFy3aOw6M4cFWwcdMYzKTItvzyLVhDqMzT5eup/NVqo5tPoy93XPf2qRYiTl4
|
||||||
|
2j5wvm0RVkYEONd3pk2lbfbUmn7XQXj0+AG60SvsqErF/UhIBGec/xsCgYEA5fLC
|
||||||
|
EdiiC98kr4sVaE8G854WI+aAkStqO5YXyrnsMzRsqk8KVVYE1yCC9rYyymDBYmlx
|
||||||
|
uEW+vbWqLc8PO3v4ty3o5ff303lPMWIrvKiUldjqMjS6ncWxsQjU0bygGVgOgHO7
|
||||||
|
c8rjiDH5M0JgWSREYUVFT5mW/5+Y1LVT8mYNlHUCgYEAhMSX6N23XGkFW3Twu2qB
|
||||||
|
/1Vohgw86OoaDNvfzDBPpFmQ3rlz0ijHSeSTd5BxBH5FICXACUgygNErjcphOSxj
|
||||||
|
JQyUxgVTQlo2y1mNm1O/nwS/lxx1xqK9ky4x/Kqvr+w1WBxSFI2kQr2V4OUTobma
|
||||||
|
sXpGvDcmnrhJJLd0EaefO6cCgYEA3Xw/S9tC8nZjqqYn34nHI16Q6tF54tpTf8Np
|
||||||
|
dT4x8Xw8cqqhRGMPVHsfSi1irKYXfwgbnienuqlBmtAHVv9pKF+TJfb7gXkmO2XY
|
||||||
|
xOYIAHGn2uYJHjCun9vmyYKLHv4/MaDH3Jd/I88mviXgEdyp9Js5UJua4utB1Rg3
|
||||||
|
HJMJ34UCgYEAr0PpHEBMbZXZBybNU96+jRTgkrNeJpzlnMy7et2IsRAtLjZ0mpbn
|
||||||
|
NaX8i8eO+ubweqFdhOvbh7Hd0zr7BzrYcUG1e3njhtxJE1MgWL5plnLVUbIyDAm3
|
||||||
|
iBpIHIBASNCN3sqeq+VqXvavRmeZh5O0vyLP46/kxZx0rzR/NCi9xxU=
|
||||||
|
-----END RSA PRIVATE KEY-----
|
||||||
|
-----BEGIN CERTIFICATE-----
|
||||||
|
MIIC7DCCAdQCBRQHBXNIMA0GCSqGSIb3DQEBBQUAMDoxDDAKBgNVBAMTA3dzMjEM
|
||||||
|
MAoGA1UEChMDd3MyMQswCQYDVQQGEwJJRTEPMA0GA1UEBxMGRHVibGluMB4XDTE0
|
||||||
|
MDgwMzA5MTU0OFoXDTI0MDczMTA5MTU0OFowOjEMMAoGA1UEAxMDd3MyMQwwCgYD
|
||||||
|
VQQKEwN3czIxCzAJBgNVBAYTAklFMQ8wDQYDVQQHEwZHYWx3YXkwggEiMA0GCSqG
|
||||||
|
SIb3DQEBAQUAA4IBDwAwggEKAoIBAQDb2IWcx/imO3LqSc63jBPSOg9SVTZ0YIVb
|
||||||
|
FDkSDvtjHcui7ZoU7M0anvMtgfyBq44r6aBj4H1wG/w+9W1RBAoHRIpNNXxk0pXI
|
||||||
|
/c7kXaBFIn60e1MWpo98bRY86f9/TZhs6kB7pGT42eUmh64HEbi5qlRKruvSZMYl
|
||||||
|
B77nbLUtwyzbcgMQ0F8OhQxW3m8KcX5xgrmd14VUvI87cmOiEMfXO/dr0QIbbyu2
|
||||||
|
Mocuk1gUOw8loPtQ+7LKTeEi988Jmgk5SURV+ktP+Uz72gI+er0/Aink2pih+S5z
|
||||||
|
d4qigKjs3ivgiU8COS1pqjpvRJw3A1AHeV44h0RQVIhjLw3UmzNXAgMBAAEwDQYJ
|
||||||
|
KoZIhvcNAQEFBQADggEBALi/RmqeXGazT/WRj9+ZqdcnbcHwK5wwr2/YkpFPJ0Hf
|
||||||
|
ZDm+2vgjDdTT6cJS6fau0M5nliYdz89aQQo1j9RSRZnzlc/2YCFXyRLCOJYaINbj
|
||||||
|
1MEUAvNDGL7xTpepK9hVkXASRkbyNXERXRKFI1N+vpKu6UorT6/osEV/qM+MFJ3s
|
||||||
|
24xE8/J3J4MirVQVt6eY6Jb+tkliOPMIugr6YQlLsqJygEWATP8Qsr81XSfcZhVq
|
||||||
|
rXzVt7QV8dO0nStMjKK5omrtEAhVnASk7w1tFHkpBF1rqXGoo9ML40RnFZ+E5zqi
|
||||||
|
iZtzp+NzzLnEnWMNs+fJpPJ96P0kbq2bQzuSBcUynq0=
|
||||||
|
-----END CERTIFICATE-----
|
||||||
@@ -0,0 +1,253 @@
|
|||||||
|
// Copyright (c) 2014 Cesanta Software Limited
|
||||||
|
// All rights reserved
|
||||||
|
//
|
||||||
|
// This software 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/>.
|
||||||
|
//
|
||||||
|
// You are free to use this software 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.
|
||||||
|
//
|
||||||
|
// Alternatively, you can license this software under a commercial
|
||||||
|
// license, as set out in <http://cesanta.com/>.
|
||||||
|
//
|
||||||
|
// $Date: 2014-09-28 05:04:41 UTC $
|
||||||
|
|
||||||
|
#ifndef NS_SKELETON_HEADER_INCLUDED
|
||||||
|
#define NS_SKELETON_HEADER_INCLUDED
|
||||||
|
|
||||||
|
#define NS_SKELETON_VERSION "2.1.0"
|
||||||
|
|
||||||
|
#undef UNICODE // Use ANSI WinAPI functions
|
||||||
|
#undef _UNICODE // Use multibyte encoding on Windows
|
||||||
|
#define _MBCS // Use multibyte encoding on Windows
|
||||||
|
#define _INTEGRAL_MAX_BITS 64 // Enable _stati64() on Windows
|
||||||
|
#define _CRT_SECURE_NO_WARNINGS // Disable deprecation warning in VS2005+
|
||||||
|
#undef WIN32_LEAN_AND_MEAN // Let windows.h always include winsock2.h
|
||||||
|
#define _XOPEN_SOURCE 600 // For flockfile() on Linux
|
||||||
|
#define __STDC_FORMAT_MACROS // <inttypes.h> wants this for C++
|
||||||
|
#define __STDC_LIMIT_MACROS // C++ wants that for INT64_MAX
|
||||||
|
#ifndef _LARGEFILE_SOURCE
|
||||||
|
#define _LARGEFILE_SOURCE // Enable fseeko() and ftello() functions
|
||||||
|
#endif
|
||||||
|
#define _FILE_OFFSET_BITS 64 // Enable 64-bit file offsets
|
||||||
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
#pragma warning (disable : 4127) // FD_SET() emits warning, disable it
|
||||||
|
#pragma warning (disable : 4204) // missing c99 support
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <assert.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <signal.h>
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
#pragma comment(lib, "ws2_32.lib") // Linking with winsock library
|
||||||
|
#endif
|
||||||
|
#include <windows.h>
|
||||||
|
#include <process.h>
|
||||||
|
#ifndef EINPROGRESS
|
||||||
|
#define EINPROGRESS WSAEINPROGRESS
|
||||||
|
#endif
|
||||||
|
#ifndef EWOULDBLOCK
|
||||||
|
#define EWOULDBLOCK WSAEWOULDBLOCK
|
||||||
|
#endif
|
||||||
|
#ifndef __func__
|
||||||
|
#define STRX(x) #x
|
||||||
|
#define STR(x) STRX(x)
|
||||||
|
#define __func__ __FILE__ ":" STR(__LINE__)
|
||||||
|
#endif
|
||||||
|
#ifndef va_copy
|
||||||
|
#define va_copy(x,y) x = y
|
||||||
|
#endif // MINGW #defines va_copy
|
||||||
|
#define snprintf _snprintf
|
||||||
|
#define vsnprintf _vsnprintf
|
||||||
|
#define sleep(x) Sleep((x) * 1000)
|
||||||
|
#define to64(x) _atoi64(x)
|
||||||
|
typedef int socklen_t;
|
||||||
|
typedef unsigned char uint8_t;
|
||||||
|
typedef unsigned int uint32_t;
|
||||||
|
typedef unsigned short uint16_t;
|
||||||
|
typedef unsigned __int64 uint64_t;
|
||||||
|
typedef __int64 int64_t;
|
||||||
|
typedef SOCKET sock_t;
|
||||||
|
typedef struct _stati64 ns_stat_t;
|
||||||
|
#ifndef S_ISDIR
|
||||||
|
#define S_ISDIR(x) ((x) & _S_IFDIR)
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#include <errno.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <netdb.h>
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <arpa/inet.h> // For inet_pton() when NS_ENABLE_IPV6 is defined
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <sys/select.h>
|
||||||
|
#define closesocket(x) close(x)
|
||||||
|
#define __cdecl
|
||||||
|
#define INVALID_SOCKET (-1)
|
||||||
|
#define to64(x) strtoll(x, NULL, 10)
|
||||||
|
typedef int sock_t;
|
||||||
|
typedef struct stat ns_stat_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef NS_ENABLE_DEBUG
|
||||||
|
#define DBG(x) do { printf("%-20s ", __func__); printf x; putchar('\n'); \
|
||||||
|
fflush(stdout); } while(0)
|
||||||
|
#else
|
||||||
|
#define DBG(x)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef ARRAY_SIZE
|
||||||
|
#define ARRAY_SIZE(array) (sizeof(array) / sizeof(array[0]))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef NS_ENABLE_SSL
|
||||||
|
#ifdef __APPLE__
|
||||||
|
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||||
|
#endif
|
||||||
|
#include <openssl/ssl.h>
|
||||||
|
#else
|
||||||
|
typedef void *SSL;
|
||||||
|
typedef void *SSL_CTX;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif // __cplusplus
|
||||||
|
|
||||||
|
union socket_address {
|
||||||
|
struct sockaddr sa;
|
||||||
|
struct sockaddr_in sin;
|
||||||
|
#ifdef NS_ENABLE_IPV6
|
||||||
|
struct sockaddr_in6 sin6;
|
||||||
|
#else
|
||||||
|
struct sockaddr sin6;
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
// Describes chunk of memory
|
||||||
|
struct ns_str {
|
||||||
|
const char *p;
|
||||||
|
size_t len;
|
||||||
|
};
|
||||||
|
|
||||||
|
// IO buffers interface
|
||||||
|
struct iobuf {
|
||||||
|
char *buf;
|
||||||
|
size_t len;
|
||||||
|
size_t size;
|
||||||
|
};
|
||||||
|
|
||||||
|
void iobuf_init(struct iobuf *, size_t initial_size);
|
||||||
|
void iobuf_free(struct iobuf *);
|
||||||
|
size_t iobuf_append(struct iobuf *, const void *data, size_t data_size);
|
||||||
|
void iobuf_remove(struct iobuf *, size_t data_size);
|
||||||
|
void iobuf_resize(struct iobuf *, size_t new_size);
|
||||||
|
|
||||||
|
// Callback function (event handler) prototype, must be defined by user.
|
||||||
|
// Net skeleton will call event handler, passing events defined above.
|
||||||
|
struct ns_connection;
|
||||||
|
typedef void (*ns_callback_t)(struct ns_connection *, int event_num, void *evp);
|
||||||
|
|
||||||
|
// Events. Meaning of event parameter (evp) is given in the comment.
|
||||||
|
#define NS_POLL 0 // Sent to each connection on each call to ns_mgr_poll()
|
||||||
|
#define NS_ACCEPT 1 // New connection accept()-ed. union socket_address *addr
|
||||||
|
#define NS_CONNECT 2 // connect() succeeded or failed. int *success_status
|
||||||
|
#define NS_RECV 3 // Data has benn received. int *num_bytes
|
||||||
|
#define NS_SEND 4 // Data has been written to a socket. int *num_bytes
|
||||||
|
#define NS_CLOSE 5 // Connection is closed. NULL
|
||||||
|
|
||||||
|
|
||||||
|
struct ns_mgr {
|
||||||
|
struct ns_connection *active_connections;
|
||||||
|
const char *hexdump_file; // Debug hexdump file path
|
||||||
|
sock_t ctl[2]; // Socketpair for mg_wakeup()
|
||||||
|
void *user_data; // User data
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
struct ns_connection {
|
||||||
|
struct ns_connection *next, *prev; // ns_mgr::active_connections linkage
|
||||||
|
struct ns_connection *listener; // Set only for accept()-ed connections
|
||||||
|
struct ns_mgr *mgr;
|
||||||
|
|
||||||
|
sock_t sock; // Socket
|
||||||
|
union socket_address sa; // Peer address
|
||||||
|
struct iobuf recv_iobuf; // Received data
|
||||||
|
struct iobuf send_iobuf; // Data scheduled for sending
|
||||||
|
SSL *ssl;
|
||||||
|
SSL_CTX *ssl_ctx;
|
||||||
|
void *user_data; // User-specific data
|
||||||
|
void *proto_data; // Application protocol-specific data
|
||||||
|
time_t last_io_time; // Timestamp of the last socket IO
|
||||||
|
ns_callback_t callback; // Event handler function
|
||||||
|
|
||||||
|
unsigned int flags;
|
||||||
|
#define NSF_FINISHED_SENDING_DATA (1 << 0)
|
||||||
|
#define NSF_BUFFER_BUT_DONT_SEND (1 << 1)
|
||||||
|
#define NSF_SSL_HANDSHAKE_DONE (1 << 2)
|
||||||
|
#define NSF_CONNECTING (1 << 3)
|
||||||
|
#define NSF_CLOSE_IMMEDIATELY (1 << 4)
|
||||||
|
#define NSF_WANT_READ (1 << 5)
|
||||||
|
#define NSF_WANT_WRITE (1 << 6)
|
||||||
|
#define NSF_LISTENING (1 << 7)
|
||||||
|
#define NSF_UDP (1 << 8)
|
||||||
|
|
||||||
|
#define NSF_USER_1 (1 << 20)
|
||||||
|
#define NSF_USER_2 (1 << 21)
|
||||||
|
#define NSF_USER_3 (1 << 22)
|
||||||
|
#define NSF_USER_4 (1 << 23)
|
||||||
|
#define NSF_USER_5 (1 << 24)
|
||||||
|
#define NSF_USER_6 (1 << 25)
|
||||||
|
};
|
||||||
|
|
||||||
|
void ns_mgr_init(struct ns_mgr *, void *user_data);
|
||||||
|
void ns_mgr_free(struct ns_mgr *);
|
||||||
|
time_t ns_mgr_poll(struct ns_mgr *, int milli);
|
||||||
|
void ns_broadcast(struct ns_mgr *, ns_callback_t, void *, size_t);
|
||||||
|
|
||||||
|
struct ns_connection *ns_next(struct ns_mgr *, struct ns_connection *);
|
||||||
|
struct ns_connection *ns_add_sock(struct ns_mgr *, sock_t,
|
||||||
|
ns_callback_t, void *);
|
||||||
|
struct ns_connection *ns_bind(struct ns_mgr *, const char *,
|
||||||
|
ns_callback_t, void *);
|
||||||
|
struct ns_connection *ns_connect(struct ns_mgr *, const char *,
|
||||||
|
ns_callback_t, void *);
|
||||||
|
|
||||||
|
int ns_send(struct ns_connection *, const void *buf, int len);
|
||||||
|
int ns_printf(struct ns_connection *, const char *fmt, ...);
|
||||||
|
int ns_vprintf(struct ns_connection *, const char *fmt, va_list ap);
|
||||||
|
|
||||||
|
// Utility functions
|
||||||
|
void *ns_start_thread(void *(*f)(void *), void *p);
|
||||||
|
int ns_socketpair(sock_t [2]);
|
||||||
|
int ns_socketpair2(sock_t [2], int sock_type); // SOCK_STREAM or SOCK_DGRAM
|
||||||
|
void ns_set_close_on_exec(sock_t);
|
||||||
|
void ns_sock_to_str(sock_t sock, char *buf, size_t len, int flags);
|
||||||
|
int ns_hexdump(const void *buf, int len, char *dst, int dst_len);
|
||||||
|
int ns_avprintf(char **buf, size_t size, const char *fmt, va_list ap);
|
||||||
|
int ns_resolve(const char *domain_name, char *ip_addr_buf, size_t buf_len);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif // __cplusplus
|
||||||
|
|
||||||
|
#endif // NS_SKELETON_HEADER_INCLUDED
|
||||||
@@ -0,0 +1,123 @@
|
|||||||
|
// Copyright (c) 2014 Cesanta Software Limited
|
||||||
|
// All rights reserved
|
||||||
|
//
|
||||||
|
// This software 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/>.
|
||||||
|
//
|
||||||
|
// You are free to use this software 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.
|
||||||
|
//
|
||||||
|
// Alternatively, you can license this software under a commercial
|
||||||
|
// license, as set out in <http://cesanta.com/products.html>.
|
||||||
|
//
|
||||||
|
// $Date$
|
||||||
|
|
||||||
|
#include "net_skeleton.h"
|
||||||
|
#include "ssl_wrapper.h"
|
||||||
|
|
||||||
|
static void ev_handler(struct ns_connection *nc, int ev, void *p) {
|
||||||
|
const char *target_addr = (const char *) nc->mgr->user_data;
|
||||||
|
struct ns_connection *pc = (struct ns_connection *) nc->user_data;
|
||||||
|
struct iobuf *io = &nc->recv_iobuf;
|
||||||
|
|
||||||
|
(void) p;
|
||||||
|
switch (ev) {
|
||||||
|
case NS_ACCEPT:
|
||||||
|
// Create a connection to the target, and interlink both connections
|
||||||
|
nc->user_data = ns_connect(nc->mgr, target_addr, ev_handler, nc);
|
||||||
|
if (nc->user_data == NULL) {
|
||||||
|
nc->flags |= NSF_CLOSE_IMMEDIATELY;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case NS_CLOSE:
|
||||||
|
// If either connection closes, unlink them and shedule closing
|
||||||
|
if (pc != NULL) {
|
||||||
|
pc->flags |= NSF_FINISHED_SENDING_DATA;
|
||||||
|
pc->user_data = NULL;
|
||||||
|
}
|
||||||
|
nc->user_data = NULL;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case NS_RECV:
|
||||||
|
// Forward arrived data to the other connection, and discard from buffer
|
||||||
|
if (pc != NULL) {
|
||||||
|
ns_send(pc, io->buf, io->len);
|
||||||
|
iobuf_remove(io, io->len);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void *ssl_wrapper_init(const char *local_addr, const char *target_addr,
|
||||||
|
const char **err_msg) {
|
||||||
|
struct ns_mgr *mgr = (struct ns_mgr *) calloc(1, sizeof(mgr[0]));
|
||||||
|
*err_msg = NULL;
|
||||||
|
|
||||||
|
if (mgr == NULL) {
|
||||||
|
*err_msg = "malloc failed";
|
||||||
|
} else {
|
||||||
|
ns_mgr_init(mgr, (void *) target_addr);
|
||||||
|
if (ns_bind(mgr, local_addr, ev_handler, NULL) == NULL) {
|
||||||
|
*err_msg = "ns_bind() failed: bad listening_port";
|
||||||
|
ns_mgr_free(mgr);
|
||||||
|
free(mgr);
|
||||||
|
mgr = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return mgr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ssl_wrapper_serve(void *param, volatile int *quit) {
|
||||||
|
struct ns_mgr *mgr = (struct ns_mgr *) param;
|
||||||
|
|
||||||
|
while (*quit == 0) {
|
||||||
|
ns_mgr_poll(mgr, 1000);
|
||||||
|
}
|
||||||
|
ns_mgr_free(mgr);
|
||||||
|
free(mgr);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef SSL_WRAPPER_USE_AS_LIBRARY
|
||||||
|
static int s_received_signal = 0;
|
||||||
|
|
||||||
|
static void signal_handler(int sig_num) {
|
||||||
|
signal(sig_num, signal_handler);
|
||||||
|
s_received_signal = sig_num;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void show_usage_and_exit(const char *prog) {
|
||||||
|
fprintf(stderr, "Usage: %s <listening_address> <target_address>\n", prog);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[]) {
|
||||||
|
void *wrapper;
|
||||||
|
const char *err_msg;
|
||||||
|
|
||||||
|
if (argc != 3) {
|
||||||
|
show_usage_and_exit(argv[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Setup signal handlers
|
||||||
|
signal(SIGTERM, signal_handler);
|
||||||
|
signal(SIGINT, signal_handler);
|
||||||
|
signal(SIGPIPE, SIG_IGN);
|
||||||
|
|
||||||
|
if ((wrapper = ssl_wrapper_init(argv[1], argv[2], &err_msg)) == NULL) {
|
||||||
|
fprintf(stderr, "Error: %s\n", err_msg);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
ssl_wrapper_serve(wrapper, &s_received_signal);
|
||||||
|
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
||||||
|
#endif // SSL_WRAPPER_USE_AS_LIBRARY
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
// Copyright (c) 2014 Cesanta Software Limited
|
||||||
|
// All rights reserved
|
||||||
|
//
|
||||||
|
// This software 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/>.
|
||||||
|
//
|
||||||
|
// You are free to use this software 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.
|
||||||
|
//
|
||||||
|
// Alternatively, you can license this software under a commercial
|
||||||
|
// license, as set out in <http://cesanta.com/products.html>.
|
||||||
|
//
|
||||||
|
// $Date$
|
||||||
|
|
||||||
|
#ifndef SSL_WRAPPER_HEADER_INCLUDED
|
||||||
|
#define SSL_WRAPPER_HEADER_INCLUDED
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif // __cplusplus
|
||||||
|
|
||||||
|
void *ssl_wrapper_init(const char *listen_addr, const char *target_addr,
|
||||||
|
const char **err_msg);
|
||||||
|
void ssl_wrapper_serve(void *, volatile int *stop_marker);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif // __cplusplus
|
||||||
|
|
||||||
|
#endif // SSL_WRAPPER_HEADER_INCLUDED
|
||||||
@@ -0,0 +1,182 @@
|
|||||||
|
// Copyright (c) 2014 Cesanta Software
|
||||||
|
// All rights reserved
|
||||||
|
//
|
||||||
|
// This example demostrates proxying of WebSocket traffic, regardless of the
|
||||||
|
// protocol (ws:// or wss://).
|
||||||
|
// To use this example:
|
||||||
|
// 1. configure your browser to use a proxy on port 2014
|
||||||
|
// 2. import certs/ws1_ca.pem and certs/ws2_ca.pem into the trusted
|
||||||
|
// certificates list on your browser
|
||||||
|
// 3. make && ./ws_ssl
|
||||||
|
// 4. Point your browser to http://ws_ssl.com
|
||||||
|
// A page with 4 sections should appear, showing websocket echoes
|
||||||
|
|
||||||
|
#include "net_skeleton.h"
|
||||||
|
#include "mongoose.h"
|
||||||
|
#include "ssl_wrapper.h"
|
||||||
|
|
||||||
|
#define S1_PEM "certs/ws1_server.pem"
|
||||||
|
#define C1_PEM "certs/ws1_client.pem"
|
||||||
|
#define CA1_PEM "certs/ws1_ca.pem"
|
||||||
|
#define S2_PEM "certs/ws2_server.pem"
|
||||||
|
#define C2_PEM "certs/ws2_client.pem"
|
||||||
|
#define CA2_PEM "certs/ws2_ca.pem"
|
||||||
|
|
||||||
|
struct config {
|
||||||
|
const char *uri;
|
||||||
|
const char *wrapper_server_addr;
|
||||||
|
const char *wrapper_client_addr;
|
||||||
|
const char *target_addr;
|
||||||
|
};
|
||||||
|
|
||||||
|
static struct config s_wrappers[] = {
|
||||||
|
{
|
||||||
|
"ws1:80",
|
||||||
|
"tcp://127.0.0.1:7001",
|
||||||
|
"tcp://127.0.0.1:7001",
|
||||||
|
"tcp://127.0.0.1:9001"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ws1:443",
|
||||||
|
"ssl://127.0.0.1:7002:" S1_PEM,
|
||||||
|
"tcp://127.0.0.1:7002",
|
||||||
|
"tcp://127.0.0.1:9001"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ws2:80",
|
||||||
|
"tcp://127.0.0.1:7003",
|
||||||
|
"tcp://127.0.0.1:7003",
|
||||||
|
"ssl://127.0.0.1:9002:" C2_PEM ":" CA2_PEM
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ws2:443",
|
||||||
|
"ssl://127.0.0.1:7004:" S2_PEM,
|
||||||
|
"tcp://127.0.0.1:7004",
|
||||||
|
"ssl://127.0.0.1:9002:" C2_PEM ":" CA2_PEM
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
static int s_received_signal = 0;
|
||||||
|
|
||||||
|
static void signal_handler(int sig_num) {
|
||||||
|
signal(sig_num, signal_handler);
|
||||||
|
s_received_signal = sig_num;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int ev_handler(struct mg_connection *conn, enum mg_event ev) {
|
||||||
|
int i;
|
||||||
|
|
||||||
|
switch (ev) {
|
||||||
|
case MG_AUTH:
|
||||||
|
return MG_TRUE;
|
||||||
|
|
||||||
|
case MG_REQUEST:
|
||||||
|
printf("==> [%s] [%s]\n", conn->request_method, conn->uri);
|
||||||
|
|
||||||
|
if (strcmp(conn->request_method, "CONNECT") == 0) {
|
||||||
|
// Iterate over configured wrappers, see if we can use one of them
|
||||||
|
for (i = 0; i < (int) ARRAY_SIZE(s_wrappers); i++) {
|
||||||
|
if (strcmp(conn->uri, s_wrappers[i].uri) == 0) {
|
||||||
|
mg_forward(conn, s_wrappers[i].wrapper_client_addr);
|
||||||
|
return MG_MORE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// No suitable wrappers found. Disallow that CONNECT request.
|
||||||
|
mg_send_status(conn, 405);
|
||||||
|
return MG_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Not a CONNECT request, serve HTML file.
|
||||||
|
mg_send_file(conn, "ws_ssl.html", NULL);
|
||||||
|
return MG_MORE;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return MG_FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static int ws_handler(struct mg_connection *conn, enum mg_event ev) {
|
||||||
|
switch (ev) {
|
||||||
|
case MG_AUTH:
|
||||||
|
return MG_TRUE;
|
||||||
|
case MG_REQUEST:
|
||||||
|
if (conn->is_websocket) {
|
||||||
|
// Simple websocket echo server
|
||||||
|
mg_websocket_write(conn, WEBSOCKET_OPCODE_TEXT,
|
||||||
|
conn->content, conn->content_len);
|
||||||
|
} else {
|
||||||
|
mg_printf_data(conn, "%s", "websocket connection expected");
|
||||||
|
}
|
||||||
|
return MG_TRUE;
|
||||||
|
default:
|
||||||
|
return MG_FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void *serve_thread_func(void *param) {
|
||||||
|
struct mg_server *server = (struct mg_server *) param;
|
||||||
|
printf("Listening on port %s\n", mg_get_option(server, "listening_port"));
|
||||||
|
while (s_received_signal == 0) {
|
||||||
|
mg_poll_server(server, 1000);
|
||||||
|
}
|
||||||
|
mg_destroy_server(&server);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void *wrapper_thread_func(void *param) {
|
||||||
|
struct config *c = (struct config *) param;
|
||||||
|
const char *err_msg;
|
||||||
|
void *wrapper;
|
||||||
|
|
||||||
|
wrapper = ssl_wrapper_init(c->wrapper_server_addr, c->target_addr, &err_msg);
|
||||||
|
if (wrapper == NULL) {
|
||||||
|
fprintf(stderr, "Error: %s\n", err_msg);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
//((struct ns_mgr *) wrapper)->hexdump_file = "/dev/stderr";
|
||||||
|
ssl_wrapper_serve(wrapper, &s_received_signal);
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
struct mg_server *proxy_server = mg_create_server(NULL, ev_handler);
|
||||||
|
struct mg_server *ws1_server = mg_create_server(NULL, ws_handler);
|
||||||
|
struct mg_server *ws2_server = mg_create_server(NULL, ws_handler);
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
((struct ns_mgr *) proxy_server)->hexdump_file = "/dev/stderr";
|
||||||
|
|
||||||
|
// Configure proxy server to listen on port 2014
|
||||||
|
mg_set_option(proxy_server, "listening_port", "2014");
|
||||||
|
//mg_set_option(proxy_server, "enable_proxy", "yes");
|
||||||
|
|
||||||
|
// Configure two websocket echo servers:
|
||||||
|
// ws1 is WS, listening on 9001
|
||||||
|
// ws2 is WSS, listening on 9002
|
||||||
|
// Note that HTML page thinks that ws1 is WSS, and ws2 is WS,
|
||||||
|
// where in reality it is vice versa and proxy server makes the decision.
|
||||||
|
mg_set_option(ws1_server, "listening_port", "tcp://127.0.0.1:9001");
|
||||||
|
mg_set_option(ws2_server, "listening_port",
|
||||||
|
"ssl://127.0.0.1:9002:" S2_PEM ":" CA2_PEM);
|
||||||
|
|
||||||
|
// Setup signal handlers
|
||||||
|
signal(SIGTERM, signal_handler);
|
||||||
|
signal(SIGINT, signal_handler);
|
||||||
|
|
||||||
|
// Start SSL wrappers, each in it's own thread
|
||||||
|
for (i = 0; i < ARRAY_SIZE(s_wrappers); i++) {
|
||||||
|
ns_start_thread(wrapper_thread_func, &s_wrappers[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start websocket servers in separate threads
|
||||||
|
mg_start_thread(serve_thread_func, ws1_server);
|
||||||
|
mg_start_thread(serve_thread_func, ws2_server);
|
||||||
|
|
||||||
|
// Finally, start proxy server in this thread: this call blocks
|
||||||
|
serve_thread_func(proxy_server);
|
||||||
|
|
||||||
|
printf("Existing on signal %d\n", s_received_signal);
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Websocket Proxy SSL Test</title>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<script>
|
||||||
|
window.onload = function() {
|
||||||
|
var protocols = ['ws://', 'wss://'];
|
||||||
|
var websocketServers = ['ws1', 'ws2'];
|
||||||
|
//protocols = ['wss://'];
|
||||||
|
//websocketServers = ['ws1']
|
||||||
|
|
||||||
|
var createWebsocketConnection = function(proto, server) {
|
||||||
|
var conn = new WebSocket(proto + server);
|
||||||
|
|
||||||
|
var div = document.createElement('div');
|
||||||
|
var h2 = document.createElement('h2');
|
||||||
|
h2.innerHTML = 'Connection to ' + proto + server;
|
||||||
|
document.body.appendChild(h2);
|
||||||
|
document.body.appendChild(div);
|
||||||
|
|
||||||
|
conn.onmessage = function(ev) {
|
||||||
|
var el = document.createElement('div');
|
||||||
|
el.innerHTML = 'websocket message: ' + ev.data;
|
||||||
|
div.appendChild(el);
|
||||||
|
// Keep only last 5 messages in the list
|
||||||
|
while (div.childNodes.length > 5) div.removeChild(div.firstChild);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Send some string to the websocket connection periodically.
|
||||||
|
// websocket server much echo it back.
|
||||||
|
window.setInterval(function() { conn.send(Math.random()); }, 1000);
|
||||||
|
};
|
||||||
|
|
||||||
|
for (var i = 0; i < protocols.length; i++) {
|
||||||
|
for (var j = 0; j < websocketServers.length; j++) {
|
||||||
|
createWebsocketConnection(protocols[i], websocketServers[j]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
<style>
|
||||||
|
body > div {
|
||||||
|
border: 1px solid #ccc; background: #f0f0f0; padding: 0 1em;
|
||||||
|
margin: 0 2em; min-height: 4em; max-width: 40em;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -1,511 +0,0 @@
|
|||||||
// Copyright (c) 2004-2011 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>
|
|
||||||
#define PATH_MAX MAX_PATH
|
|
||||||
#define S_ISDIR(x) ((x) & _S_IFDIR)
|
|
||||||
#define DIRSEP '\\'
|
|
||||||
#define snprintf _snprintf
|
|
||||||
#define vsnprintf _vsnprintf
|
|
||||||
#define sleep(x) Sleep((x) * 1000)
|
|
||||||
#define WINCDECL __cdecl
|
|
||||||
#else
|
|
||||||
#include <sys/wait.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#define DIRSEP '/'
|
|
||||||
#define WINCDECL
|
|
||||||
#endif // _WIN32
|
|
||||||
|
|
||||||
#define MAX_OPTIONS 40
|
|
||||||
#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) {
|
|
||||||
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 %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 += 3) {
|
|
||||||
fprintf(stderr, " -%s %s (default: \"%s\")\n",
|
|
||||||
names[i], names[i + 1], names[i + 2] == NULL ? "" : names[i + 2]);
|
|
||||||
}
|
|
||||||
fprintf(stderr, "\nSee http://code.google.com/p/mongoose/wiki/MongooseManual"
|
|
||||||
" for more details.\n");
|
|
||||||
fprintf(stderr, "Example:\n mongoose -s cert.pem -p 80,443s -d no\n");
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void verify_document_root(const char *root) {
|
|
||||||
const char *p, *path;
|
|
||||||
char buf[PATH_MAX];
|
|
||||||
struct stat st;
|
|
||||||
|
|
||||||
path = root;
|
|
||||||
if ((p = strchr(root, ',')) != NULL && (size_t) (p - root) < sizeof(buf)) {
|
|
||||||
memcpy(buf, root, p - root);
|
|
||||||
buf[p - root] = '\0';
|
|
||||||
path = buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (stat(path, &st) != 0 || !S_ISDIR(st.st_mode)) {
|
|
||||||
die("Invalid root directory: [%s]: %s", root, strerror(errno));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
if (!strcmp(name, "document_root") || !(strcmp(name, "r"))) {
|
|
||||||
verify_document_root(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
options[0] = NULL;
|
|
||||||
|
|
||||||
// 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) {
|
|
||||||
die("%s: line %d is invalid", config_file, (int) line_no);
|
|
||||||
}
|
|
||||||
set_option(options, opt, val);
|
|
||||||
}
|
|
||||||
|
|
||||||
(void) fclose(fp);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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 void *mongoose_callback(enum mg_event ev, struct mg_connection *conn) {
|
|
||||||
if (ev == MG_EVENT_LOG) {
|
|
||||||
printf("%s\n", (const char *) mg_get_request_info(conn)->ev_data);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returning NULL marks request as not handled, signalling mongoose to
|
|
||||||
// proceed with handling it.
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void start_mongoose(int argc, char *argv[]) {
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Update config based on command line arguments */
|
|
||||||
process_command_line_arguments(argv, options);
|
|
||||||
|
|
||||||
/* Setup signal handler: quit on Ctrl-C */
|
|
||||||
signal(SIGTERM, signal_handler);
|
|
||||||
signal(SIGINT, signal_handler);
|
|
||||||
|
|
||||||
/* Start Mongoose */
|
|
||||||
ctx = mg_start(&mongoose_callback, 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
|
|
||||||
static SERVICE_STATUS ss;
|
|
||||||
static SERVICE_STATUS_HANDLE hStatus;
|
|
||||||
static const char *service_magic_argument = "--";
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
#define ID_TRAYICON 100
|
|
||||||
#define ID_QUIT 101
|
|
||||||
#define ID_EDIT_CONFIG 102
|
|
||||||
#define ID_SEPARATOR 103
|
|
||||||
#define ID_INSTALL_SERVICE 104
|
|
||||||
#define ID_REMOVE_SERVICE 105
|
|
||||||
#define ID_ICON 200
|
|
||||||
static NOTIFYICONDATA TrayIcon;
|
|
||||||
|
|
||||||
static void edit_config_file(void) {
|
|
||||||
const char **names, *value;
|
|
||||||
FILE *fp;
|
|
||||||
int i;
|
|
||||||
char cmd[200];
|
|
||||||
|
|
||||||
// Create config file if it is not present yet
|
|
||||||
if ((fp = fopen(config_file, "r")) != NULL) {
|
|
||||||
fclose(fp);
|
|
||||||
} else if ((fp = fopen(config_file, "a+")) != NULL) {
|
|
||||||
fprintf(fp,
|
|
||||||
"# Mongoose web server configuration file.\n"
|
|
||||||
"# Lines starting with '#' and empty lines are ignored.\n"
|
|
||||||
"# For detailed description of every option, visit\n"
|
|
||||||
"# http://code.google.com/p/mongoose/wiki/MongooseManual\n\n");
|
|
||||||
names = mg_get_valid_option_names();
|
|
||||||
for (i = 0; names[i] != NULL; i += 3) {
|
|
||||||
value = mg_get_option(ctx, names[i]);
|
|
||||||
fprintf(fp, "# %s %s\n", names[i + 1], *value ? value : "<value>");
|
|
||||||
}
|
|
||||||
fclose(fp);
|
|
||||||
}
|
|
||||||
|
|
||||||
snprintf(cmd, sizeof(cmd), "notepad.exe %s", config_file);
|
|
||||||
WinExec(cmd, SW_SHOW);
|
|
||||||
}
|
|
||||||
|
|
||||||
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 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;
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case WM_COMMAND:
|
|
||||||
switch (LOWORD(wParam)) {
|
|
||||||
case ID_QUIT:
|
|
||||||
mg_stop(ctx);
|
|
||||||
Shell_NotifyIcon(NIM_DELETE, &TrayIcon);
|
|
||||||
PostQuitMessage(0);
|
|
||||||
break;
|
|
||||||
case ID_EDIT_CONFIG:
|
|
||||||
edit_config_file();
|
|
||||||
break;
|
|
||||||
case ID_INSTALL_SERVICE:
|
|
||||||
case ID_REMOVE_SERVICE:
|
|
||||||
manage_service(LOWORD(wParam));
|
|
||||||
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_EDIT_CONFIG, "Edit config file");
|
|
||||||
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.
|
|
||||||
}
|
|
||||||
|
|
||||||
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_TRAYICON;
|
|
||||||
TrayIcon.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
|
|
||||||
TrayIcon.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;
|
|
||||||
}
|
|
||||||
#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 */
|
|
||||||
-184
@@ -1,184 +0,0 @@
|
|||||||
.\" Process this file with
|
|
||||||
.\" groff -man -Tascii mongoose.1
|
|
||||||
.\" $Id: mongoose.1,v 1.12 2008/11/29 15:32:42 drozd Exp $
|
|
||||||
.Dd Sep 23, 2012
|
|
||||||
.Dt mongoose 1
|
|
||||||
.Sh NAME
|
|
||||||
.Nm mongoose
|
|
||||||
.Nd lightweight web server
|
|
||||||
.Sh SYNOPSIS
|
|
||||||
.Nm
|
|
||||||
.Op Ar config_file
|
|
||||||
.Op Ar OPTIONS
|
|
||||||
.Nm
|
|
||||||
.Fl A Ar htpasswd_file domain_name user_name password
|
|
||||||
.Sh DESCRIPTION
|
|
||||||
.Nm
|
|
||||||
is small, fast and easy to use web server with CGI, SSL, MD5 authorization,
|
|
||||||
and basic SSI support.
|
|
||||||
.Pp
|
|
||||||
.Nm
|
|
||||||
does not detach from terminal, and uses current working directory
|
|
||||||
as the web root, unless
|
|
||||||
.Fl r
|
|
||||||
option is specified.
|
|
||||||
It is possible to specify multiple ports to listen on. For example, to make
|
|
||||||
mongoose listen on HTTP port 80 and HTTPS port 443, one should start it as:
|
|
||||||
.Nm
|
|
||||||
.Fl s Ar cert.pem Fl p Ar 80,443s
|
|
||||||
.Pp
|
|
||||||
Unlike other web servers,
|
|
||||||
.Nm
|
|
||||||
does not require CGI scripts be put in a special directory. CGI scripts can
|
|
||||||
be anywhere. CGI (and SSI) files are recognized by the file name pattern.
|
|
||||||
.Nm
|
|
||||||
uses shell-like glob patterns with the following syntax:
|
|
||||||
.Bl -tag -compact -width indent
|
|
||||||
.It **
|
|
||||||
Matches everything
|
|
||||||
.It *
|
|
||||||
Matches everything but slash character, '/'
|
|
||||||
.It ?
|
|
||||||
Matches any character
|
|
||||||
.It $
|
|
||||||
Matches the end of the string
|
|
||||||
.It |
|
|
||||||
Matches if pattern on the left side or the right side matches. Pattern on the
|
|
||||||
left side is matched first
|
|
||||||
.El
|
|
||||||
All other characters in the pattern match themselves.
|
|
||||||
.Pp
|
|
||||||
If no arguments are given,
|
|
||||||
.Nm
|
|
||||||
searches for a configuration file called "mongoose.conf" in the same directory
|
|
||||||
where mongoose binary is located. Alternatively, a file name could be
|
|
||||||
specified in the command line. Format of the configuration file is the same
|
|
||||||
as for the command line options except that each option must be specified
|
|
||||||
on a separate line, leading dashes for option names must be omitted.
|
|
||||||
Lines beginning with '#' and empty lines are ignored.
|
|
||||||
.Pp
|
|
||||||
.Sh OPTIONS
|
|
||||||
.Bl -tag -width indent
|
|
||||||
.It Fl A Ar htpasswd_file domain_name user_name password
|
|
||||||
Add/edit user's password in the passwords file. Deleting users can be done
|
|
||||||
with any text editor. Functionality is similar to Apache's
|
|
||||||
.Ic htdigest
|
|
||||||
utility.
|
|
||||||
.It Fl C Ar cgi_pattern
|
|
||||||
All files that fully match cgi_pattern are treated as CGI.
|
|
||||||
Default pattern allows CGI files be
|
|
||||||
anywhere. To restrict CGIs to certain directory, use e.g. "-C /cgi-bin/**.cgi".
|
|
||||||
Default: "**.cgi$|**.pl$|**.php$"
|
|
||||||
.It Fl E Ar 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 X=Y pairs, like this:
|
|
||||||
"VARIABLE1=VALUE1,VARIABLE2=VALUE2". Default: ""
|
|
||||||
.It Fl G Ar put_delete_passwords_file
|
|
||||||
PUT and DELETE passwords file. This must be specified if PUT or
|
|
||||||
DELETE methods are used. Default: ""
|
|
||||||
.It Fl I Ar cgi_interpreter
|
|
||||||
Use
|
|
||||||
.Ar cgi_interpreter
|
|
||||||
as a CGI interpreter for all CGI scripts regardless script extension.
|
|
||||||
Mongoose decides which interpreter to use by looking at
|
|
||||||
the first line of a CGI script. Default: "".
|
|
||||||
.It Fl P Ar protect_uri
|
|
||||||
Comma separated list of URI=PATH pairs, specifying that given URIs
|
|
||||||
must be protected with respected password files. Default: ""
|
|
||||||
.It Fl R Ar authentication_domain
|
|
||||||
Authorization realm. Default: "mydomain.com"
|
|
||||||
.It Fl S Ar ssi_pattern
|
|
||||||
All files that fully match ssi_pattern are treated as SSI.
|
|
||||||
Unknown SSI directives are silently ignored. Currently, two SSI directives
|
|
||||||
are supported, "include" and "exec". Default: "**.shtml$|**.shtm$"
|
|
||||||
.It Fl T Ar throttle
|
|
||||||
Limit download speed for clients.
|
|
||||||
.Ar throttle
|
|
||||||
is a comma-separated list of key=value pairs, where
|
|
||||||
key could be a '*' character (limit for all connections), a subnet in form
|
|
||||||
x.x.x.x/mask (limit for a given subnet, for example 10.0.0.0/8), or an
|
|
||||||
URI prefix pattern (limit for the set of URIs, for example /foo/**). 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. For example,
|
|
||||||
"*=1k,10.0.0.0/8" means limit everybody to 1 kilobyte per second, but give
|
|
||||||
people from 10/8 subnet unlimited speed. Default: ""
|
|
||||||
.It Fl a Ar access_log_file
|
|
||||||
Access log file. Default: "", no logging is done.
|
|
||||||
.It Fl d Ar enable_directory_listing
|
|
||||||
Enable/disable directory listing. Default: "yes"
|
|
||||||
.It Fl e Ar error_log_file
|
|
||||||
Error log file. Default: "", no errors are logged.
|
|
||||||
.It Fl g Ar global_passwords_file
|
|
||||||
Location of a global passwords file. If set, per-directory .htpasswd files are
|
|
||||||
ignored, and all requests must be authorised against that file. Default: ""
|
|
||||||
.It Fl i Ar index_files
|
|
||||||
Comma-separated list of files to be treated as directory index files.
|
|
||||||
Default: "index.html,index.htm,index.cgi"
|
|
||||||
.It Fl l Ar access_control_list
|
|
||||||
Specify access control list (ACL). ACL is a comma separated list
|
|
||||||
of IP subnets, each subnet is prepended by '-' or '+' sign. Plus means allow,
|
|
||||||
minus means deny. If subnet mask is
|
|
||||||
omitted, like "-1.2.3.4", then it means single IP address. Mask may vary
|
|
||||||
from 0 to 32 inclusive. On each request, full list is traversed, and
|
|
||||||
last match wins. Default setting is to allow all. For example, to allow only
|
|
||||||
192.168/16 subnet to connect, run "mongoose -0.0.0.0/0,+192.168/16".
|
|
||||||
Default: ""
|
|
||||||
.It Fl m Ar extra_mime_types
|
|
||||||
Extra mime types to recognize, in form
|
|
||||||
"extension1=type1,extension2=type2,...". Extension must include dot.
|
|
||||||
Example: "mongoose -m .cpp=plain/text,.java=plain/text". Default: ""
|
|
||||||
.It Fl p Ar listening_ports
|
|
||||||
Comma-separated list of ports to listen on. If the port is SSL, a letter 's'
|
|
||||||
must be appeneded, for example, "-p 80,443s" will open port 80 and port 443,
|
|
||||||
and connections on port 443 will be SSL-ed. 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
|
|
||||||
"mongoose -p 127.0.0.1:80,443s". Default: "8080"
|
|
||||||
.It Fl r Ar document_root
|
|
||||||
Location of the WWW root directory. Default: "."
|
|
||||||
.It Fl s Ar ssl_certificate
|
|
||||||
Location of SSL certificate file. Default: ""
|
|
||||||
.It Fl t Ar num_threads
|
|
||||||
Number of worker threads to start. Default: "10"
|
|
||||||
.It Fl u Ar run_as_user
|
|
||||||
Switch to given user's credentials after startup. Default: ""
|
|
||||||
.It Fl w Ar url_rewrite_patterns
|
|
||||||
Comma-separated list of URL rewrites in the form of
|
|
||||||
"pattern=substitution,..." If the "pattern" matches some prefix
|
|
||||||
of the requested URL, then matched prefix gets substituted with "substitution".
|
|
||||||
For example, "-w /config=/etc,**.doc|**.rtf=/path/to/cgi-bin/handle_doc.cgi"
|
|
||||||
will serve all URLs that start with "/config" from the "/etc" directory, and
|
|
||||||
call handle_doc.cgi script for .doc and .rtf file requests. If some pattern
|
|
||||||
matches, no further matching/substitution is performed
|
|
||||||
(first matching pattern wins). Use full paths in substitutions. Default: ""
|
|
||||||
.It Fl x Ar hide_files_patterns
|
|
||||||
A prefix 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. Default: ""
|
|
||||||
.El
|
|
||||||
.Pp
|
|
||||||
.Sh EMBEDDING
|
|
||||||
.Nm
|
|
||||||
was designed to be embeddable into C/C++ applications. Since the
|
|
||||||
source code is contained in single C file, it is fairly easy to embed it
|
|
||||||
and follow the updates. Please refer to http://code.google.com/p/mongoose
|
|
||||||
for details.
|
|
||||||
.Pp
|
|
||||||
.Sh EXAMPLES
|
|
||||||
.Bl -tag -width indent
|
|
||||||
.It Nm Fl r Ar /var/www Fl s Ar /etc/cert.pem Fl p Ar 8080,8043s
|
|
||||||
Start serving files from /var/www. Listen on port 8080 for HTTP, and 8043
|
|
||||||
for HTTPS connections. Use /etc/cert.pem as SSL certificate file.
|
|
||||||
.It Nm Fl l Ar -0.0.0.0/0,+10.0.0.0/8,+1.2.3.4
|
|
||||||
Deny connections from everywhere, allow only IP address 1.2.3.4 and
|
|
||||||
all IP addresses from 10.0.0.0/8 subnet to connect.
|
|
||||||
.It Nm Fl w Ar **=/usr/bin/script.cgi
|
|
||||||
Invoke /usr/bin/script.cgi for every incoming request, regardless of the URL.
|
|
||||||
.El
|
|
||||||
.Pp
|
|
||||||
.Sh COPYRIGHT
|
|
||||||
.Nm
|
|
||||||
is licensed under the terms of the MIT license.
|
|
||||||
.Sh AUTHOR
|
|
||||||
.An Sergey Lyubka Aq valenok@gmail.com .
|
|
||||||
+5250
-5177
File diff suppressed because it is too large.
Load diff
+153
-378
@@ -1,378 +1,153 @@
|
|||||||
// Copyright (c) 2004-2012 Sergey Lyubka
|
// Copyright (c) 2004-2013 Sergey Lyubka <valenok@gmail.com>
|
||||||
//
|
// Copyright (c) 2013-2014 Cesanta Software Limited
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// All rights reserved
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
//
|
||||||
// in the Software without restriction, including without limitation the rights
|
// This library is dual-licensed: you can redistribute it and/or modify
|
||||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
// it under the terms of the GNU General Public License version 2 as
|
||||||
// copies of the Software, and to permit persons to whom the Software is
|
// published by the Free Software Foundation. For the terms of this
|
||||||
// furnished to do so, subject to the following conditions:
|
// license, see <http://www.gnu.org/licenses/>.
|
||||||
//
|
//
|
||||||
// The above copyright notice and this permission notice shall be included in
|
// You are free to use this library under the terms of the GNU General
|
||||||
// all copies or substantial portions of the Software.
|
// Public License, but WITHOUT ANY WARRANTY; without even the implied
|
||||||
//
|
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// See the GNU General Public License for more details.
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
//
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
// Alternatively, you can license this library under a commercial
|
||||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
// license, as set out in <http://cesanta.com/>.
|
||||||
// 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
|
// $Date: 2014-09-09 17:07:55 UTC $
|
||||||
// THE SOFTWARE.
|
|
||||||
|
#ifndef MONGOOSE_HEADER_INCLUDED
|
||||||
#ifndef MONGOOSE_HEADER_INCLUDED
|
#define MONGOOSE_HEADER_INCLUDED
|
||||||
#define MONGOOSE_HEADER_INCLUDED
|
|
||||||
|
#define MONGOOSE_VERSION "5.5"
|
||||||
#include <stdio.h>
|
|
||||||
#include <stddef.h>
|
#include <stdio.h> // required for FILE
|
||||||
|
#include <stddef.h> // required for size_t
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
#ifdef __cplusplus
|
||||||
#endif // __cplusplus
|
extern "C" {
|
||||||
|
#endif // __cplusplus
|
||||||
struct mg_context; // Handle for the HTTP service itself
|
|
||||||
struct mg_connection; // Handle for the individual connection
|
// This structure contains information about HTTP request.
|
||||||
|
struct mg_connection {
|
||||||
|
const char *request_method; // "GET", "POST", etc
|
||||||
// This structure contains information about the HTTP request.
|
const char *uri; // URL-decoded URI
|
||||||
struct mg_request_info {
|
const char *http_version; // E.g. "1.0", "1.1"
|
||||||
const char *request_method; // "GET", "POST", etc
|
const char *query_string; // URL part after '?', not including '?', or NULL
|
||||||
const char *uri; // URL-decoded URI
|
|
||||||
const char *http_version; // E.g. "1.0", "1.1"
|
char remote_ip[48]; // Max IPv6 string length is 45 characters
|
||||||
const char *query_string; // URL part after '?', not including '?', or NULL
|
char local_ip[48]; // Local IP address
|
||||||
const char *remote_user; // Authenticated user, or NULL if no auth used
|
unsigned short remote_port; // Client's port
|
||||||
long remote_ip; // Client's IP address
|
unsigned short local_port; // Local port number
|
||||||
int remote_port; // Client's port
|
|
||||||
int is_ssl; // 1 if SSL-ed, 0 if not
|
int num_headers; // Number of HTTP headers
|
||||||
int num_headers; // Number of headers
|
struct mg_header {
|
||||||
struct mg_header {
|
const char *name; // HTTP header name
|
||||||
const char *name; // HTTP header name
|
const char *value; // HTTP header value
|
||||||
const char *value; // HTTP header value
|
} http_headers[30];
|
||||||
} http_headers[64]; // Maximum 64 headers
|
|
||||||
void *user_data; // User data pointer passed to the mg_start()
|
char *content; // POST (or websocket message) data, or NULL
|
||||||
void *ev_data; // Event-specific data pointer
|
size_t content_len; // Data length
|
||||||
};
|
|
||||||
|
int is_websocket; // Connection is a websocket connection
|
||||||
|
int status_code; // HTTP status code for HTTP error handler
|
||||||
// Various events on which user-defined callback function is called by Mongoose.
|
int wsbits; // First byte of the websocket frame
|
||||||
enum mg_event {
|
void *server_param; // Parameter passed to mg_add_uri_handler()
|
||||||
// New HTTP request has arrived from the client.
|
void *connection_param; // Placeholder for connection-specific data
|
||||||
// If callback returns non-NULL, Mongoose stops handling current request.
|
void *callback_param;
|
||||||
// ev_data contains NULL.
|
};
|
||||||
MG_NEW_REQUEST,
|
|
||||||
|
struct mg_server; // Opaque structure describing server instance
|
||||||
// Mongoose has finished handling the request.
|
enum mg_result { MG_FALSE, MG_TRUE, MG_MORE };
|
||||||
// Callback return value is ignored.
|
enum mg_event {
|
||||||
// ev_data contains NULL.
|
MG_POLL = 100, // Callback return value is ignored
|
||||||
MG_REQUEST_COMPLETE,
|
MG_CONNECT, // If callback returns MG_FALSE, connect fails
|
||||||
|
MG_AUTH, // If callback returns MG_FALSE, authentication fails
|
||||||
// HTTP error must be returned to the client.
|
MG_REQUEST, // If callback returns MG_FALSE, Mongoose continues with req
|
||||||
// If callback returns non-NULL, Mongoose stops handling error.
|
MG_REPLY, // If callback returns MG_FALSE, Mongoose closes connection
|
||||||
// ev_data contains HTTP error code:
|
MG_RECV, // Mongoose has received POST data chunk.
|
||||||
// int http_reply_status_code = (long) request_info->ev_data;
|
// Callback should return a number of bytes to discard from
|
||||||
MG_HTTP_ERROR,
|
// the receive buffer, or -1 to close the connection.
|
||||||
|
MG_CLOSE, // Connection is closed, callback return value is ignored
|
||||||
// Mongoose logs a message.
|
MG_WS_HANDSHAKE, // New websocket connection, handshake request
|
||||||
// If callback returns non-NULL, Mongoose stops handling that event.
|
MG_WS_CONNECT, // New websocket connection established
|
||||||
// ev_data contains a message to be logged:
|
MG_HTTP_ERROR // If callback returns MG_FALSE, Mongoose continues with err
|
||||||
// const char *log_message = request_info->ev_data;
|
};
|
||||||
MG_EVENT_LOG,
|
typedef int (*mg_handler_t)(struct mg_connection *, enum mg_event);
|
||||||
|
|
||||||
// SSL initialization, sent before certificate setup.
|
// Websocket opcodes, from http://tools.ietf.org/html/rfc6455
|
||||||
// If callback returns non-NULL, Mongoose does not set up certificates.
|
enum {
|
||||||
// ev_data contains server's OpenSSL context:
|
WEBSOCKET_OPCODE_CONTINUATION = 0x0,
|
||||||
// SSL_CTX *ssl_context = request_info->ev_data;
|
WEBSOCKET_OPCODE_TEXT = 0x1,
|
||||||
MG_INIT_SSL,
|
WEBSOCKET_OPCODE_BINARY = 0x2,
|
||||||
|
WEBSOCKET_OPCODE_CONNECTION_CLOSE = 0x8,
|
||||||
// Sent on HTTP connect, before websocket handshake.
|
WEBSOCKET_OPCODE_PING = 0x9,
|
||||||
// If user callback returns NULL, then mongoose proceeds
|
WEBSOCKET_OPCODE_PONG = 0xa
|
||||||
// with handshake, otherwise it closes the connection.
|
};
|
||||||
// ev_data contains NULL.
|
|
||||||
MG_WEBSOCKET_CONNECT,
|
// Server management functions
|
||||||
|
struct mg_server *mg_create_server(void *server_param, mg_handler_t handler);
|
||||||
// Handshake has been successfully completed.
|
void mg_destroy_server(struct mg_server **);
|
||||||
// Callback's return value is ignored.
|
const char *mg_set_option(struct mg_server *, const char *opt, const char *val);
|
||||||
// ev_data contains NULL.
|
int mg_poll_server(struct mg_server *, int milliseconds);
|
||||||
MG_WEBSOCKET_READY,
|
const char **mg_get_valid_option_names(void);
|
||||||
|
const char *mg_get_option(const struct mg_server *server, const char *name);
|
||||||
// Incoming message from the client, data could be read with mg_read().
|
void mg_copy_listeners(struct mg_server *from, struct mg_server *to);
|
||||||
// If user callback returns non-NULL, mongoose closes the websocket.
|
struct mg_connection *mg_next(struct mg_server *, struct mg_connection *);
|
||||||
// ev_data contains NULL.
|
void mg_wakeup_server(struct mg_server *);
|
||||||
MG_WEBSOCKET_MESSAGE,
|
void mg_wakeup_server_ex(struct mg_server *, mg_handler_t, const char *, ...);
|
||||||
|
struct mg_connection *mg_connect(struct mg_server *, const char *);
|
||||||
// Client has closed the connection.
|
|
||||||
// Callback's return value is ignored.
|
// Connection management functions
|
||||||
// ev_data contains NULL.
|
void mg_send_status(struct mg_connection *, int status_code);
|
||||||
MG_WEBSOCKET_CLOSE,
|
void mg_send_header(struct mg_connection *, const char *name, const char *val);
|
||||||
|
size_t mg_send_data(struct mg_connection *, const void *data, int data_len);
|
||||||
// Mongoose tries to open file.
|
size_t mg_printf_data(struct mg_connection *, const char *format, ...);
|
||||||
// If callback returns non-NULL, Mongoose will not try to open it, but
|
size_t mg_write(struct mg_connection *, const void *buf, int len);
|
||||||
// will use the returned value as a pointer to the file data. This allows
|
size_t mg_printf(struct mg_connection *conn, const char *fmt, ...);
|
||||||
// for example to serve files from memory.
|
|
||||||
// ev_data contains file path, including document root path.
|
size_t mg_websocket_write(struct mg_connection *, int opcode,
|
||||||
// Upon return, ev_data should return file size, which should be a long int.
|
const char *data, size_t data_len);
|
||||||
//
|
size_t mg_websocket_printf(struct mg_connection* conn, int opcode,
|
||||||
// const char *file_name = request_info->ev_data;
|
const char *fmt, ...);
|
||||||
// if (strcmp(file_name, "foo.txt") == 0) {
|
|
||||||
// request_info->ev_data = (void *) (long) 4;
|
void mg_send_file(struct mg_connection *, const char *path, const char *);
|
||||||
// return "data";
|
void mg_send_file_data(struct mg_connection *, int fd);
|
||||||
// }
|
|
||||||
// return NULL;
|
const char *mg_get_header(const struct mg_connection *, const char *name);
|
||||||
//
|
const char *mg_get_mime_type(const char *name, const char *default_mime_type);
|
||||||
// Note that this even is sent multiple times during one request. Each
|
int mg_get_var(const struct mg_connection *conn, const char *var_name,
|
||||||
// time mongoose tries to open or stat the file, this event is sent, e.g.
|
char *buf, size_t buf_len);
|
||||||
// for opening .htpasswd file, stat-ting requested file, opening requested
|
int mg_parse_header(const char *hdr, const char *var_name, char *buf, size_t);
|
||||||
// file, etc.
|
int mg_parse_multipart(const char *buf, int buf_len,
|
||||||
MG_OPEN_FILE,
|
char *var_name, int var_name_len,
|
||||||
|
char *file_name, int file_name_len,
|
||||||
// Mongoose initializes Lua server page. Sent only if Lua support is enabled.
|
const char **data, int *data_len);
|
||||||
// Callback's return value is ignored.
|
|
||||||
// ev_data contains lua_State pointer.
|
|
||||||
MG_INIT_LUA,
|
// Utility functions
|
||||||
|
void *mg_start_thread(void *(*func)(void *), void *param);
|
||||||
// Mongoose has uploaded file to a temporary directory.
|
char *mg_md5(char buf[33], ...);
|
||||||
// Callback's return value is ignored.
|
int mg_authorize_digest(struct mg_connection *c, FILE *fp);
|
||||||
// ev_data contains NUL-terminated file name.
|
int mg_url_encode(const char *src, size_t s_len, char *dst, size_t dst_len);
|
||||||
MG_UPLOAD,
|
int mg_url_decode(const char *src, int src_len, char *dst, int dst_len, int);
|
||||||
};
|
int mg_terminate_ssl(struct mg_connection *c, const char *cert);
|
||||||
|
int mg_forward(struct mg_connection *c, const char *addr);
|
||||||
|
void *mg_mmap(FILE *fp, size_t size);
|
||||||
// Prototype for the user-defined function. Mongoose calls this function
|
void mg_munmap(void *p, size_t size);
|
||||||
// on every MG_* event.
|
|
||||||
//
|
|
||||||
// Parameters:
|
// Templates support
|
||||||
// event: which event has been triggered.
|
struct mg_expansion {
|
||||||
// conn: opaque connection handler. Could be used to read, write data to the
|
const char *keyword;
|
||||||
// client, etc. See functions below that have "mg_connection *" arg.
|
void (*handler)(struct mg_connection *);
|
||||||
//
|
};
|
||||||
// Return:
|
void mg_template(struct mg_connection *, const char *text,
|
||||||
// If handler returns non-NULL, that means that handler has processed the
|
struct mg_expansion *expansions);
|
||||||
// request by sending appropriate HTTP reply to the client. Mongoose treats
|
|
||||||
// the request as served.
|
#ifdef __cplusplus
|
||||||
// If handler returns NULL, that means that handler has not processed
|
}
|
||||||
// the request. Handler must not send any data to the client in this case.
|
#endif // __cplusplus
|
||||||
// Mongoose proceeds with request handling as if nothing happened.
|
|
||||||
typedef void *(*mg_callback_t)(enum mg_event event, struct mg_connection *conn);
|
#endif // MONGOOSE_HEADER_INCLUDED
|
||||||
|
|
||||||
|
|
||||||
// Start web server.
|
|
||||||
//
|
|
||||||
// Parameters:
|
|
||||||
// callback: user defined event handling function or NULL.
|
|
||||||
// options: NULL terminated list of option_name, option_value pairs that
|
|
||||||
// specify Mongoose configuration parameters.
|
|
||||||
//
|
|
||||||
// Side-effects: on UNIX, ignores SIGCHLD and SIGPIPE signals. If custom
|
|
||||||
// processing is required for these, signal handlers must be set up
|
|
||||||
// after calling mg_start().
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// Example:
|
|
||||||
// const char *options[] = {
|
|
||||||
// "document_root", "/var/www",
|
|
||||||
// "listening_ports", "80,443s",
|
|
||||||
// NULL
|
|
||||||
// };
|
|
||||||
// struct mg_context *ctx = mg_start(&my_func, NULL, options);
|
|
||||||
//
|
|
||||||
// Please refer to http://code.google.com/p/mongoose/wiki/MongooseManual
|
|
||||||
// for the list of valid option and their possible values.
|
|
||||||
//
|
|
||||||
// Return:
|
|
||||||
// web server context, or NULL on error.
|
|
||||||
struct mg_context *mg_start(mg_callback_t callback, void *user_data,
|
|
||||||
const char **options);
|
|
||||||
|
|
||||||
|
|
||||||
// Stop the web server.
|
|
||||||
//
|
|
||||||
// Must be called last, when an application wants to stop the web server and
|
|
||||||
// release all associated resources. This function blocks until all Mongoose
|
|
||||||
// threads are stopped. Context pointer becomes invalid.
|
|
||||||
void mg_stop(struct mg_context *);
|
|
||||||
|
|
||||||
|
|
||||||
// Get the value of particular configuration parameter.
|
|
||||||
// The value returned is read-only. Mongoose does not allow changing
|
|
||||||
// configuration at run time.
|
|
||||||
// If given parameter name is not valid, NULL is returned. For valid
|
|
||||||
// names, return value is guaranteed to be non-NULL. If parameter is not
|
|
||||||
// set, zero-length string is returned.
|
|
||||||
const char *mg_get_option(const struct mg_context *ctx, const char *name);
|
|
||||||
|
|
||||||
|
|
||||||
// Return array of strings that represent valid configuration options.
|
|
||||||
// For each option, a short name, long name, and default value is returned.
|
|
||||||
// Array is NULL terminated.
|
|
||||||
const char **mg_get_valid_option_names(void);
|
|
||||||
|
|
||||||
|
|
||||||
// Add, edit or delete the entry in the passwords file.
|
|
||||||
//
|
|
||||||
// This function allows an application to manipulate .htpasswd files on the
|
|
||||||
// fly by adding, deleting and changing user records. This is one of the
|
|
||||||
// several ways of implementing authentication on the server side. For another,
|
|
||||||
// cookie-based way please refer to the examples/chat.c in the source tree.
|
|
||||||
//
|
|
||||||
// If password is not NULL, entry is added (or modified if already exists).
|
|
||||||
// If password is NULL, entry is deleted.
|
|
||||||
//
|
|
||||||
// Return:
|
|
||||||
// 1 on success, 0 on error.
|
|
||||||
int mg_modify_passwords_file(const char *passwords_file_name,
|
|
||||||
const char *domain,
|
|
||||||
const char *user,
|
|
||||||
const char *password);
|
|
||||||
|
|
||||||
|
|
||||||
// Return information associated with the request.
|
|
||||||
struct mg_request_info *mg_get_request_info(struct mg_connection *);
|
|
||||||
|
|
||||||
|
|
||||||
// Send data to the client.
|
|
||||||
// Return:
|
|
||||||
// 0 when the connection has been closed
|
|
||||||
// -1 on error
|
|
||||||
// number of bytes written on success
|
|
||||||
int mg_write(struct mg_connection *, const void *buf, size_t len);
|
|
||||||
|
|
||||||
|
|
||||||
// Send data to the browser using printf() semantics.
|
|
||||||
//
|
|
||||||
// Works exactly like mg_write(), but allows to do message formatting.
|
|
||||||
// Below are the macros for enabling compiler-specific checks for
|
|
||||||
// printf-like arguments.
|
|
||||||
|
|
||||||
#undef PRINTF_FORMAT_STRING
|
|
||||||
#if _MSC_VER >= 1400
|
|
||||||
#include <sal.h>
|
|
||||||
#if _MSC_VER > 1400
|
|
||||||
#define PRINTF_FORMAT_STRING(s) _Printf_format_string_ s
|
|
||||||
#else
|
|
||||||
#define PRINTF_FORMAT_STRING(s) __format_string s
|
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
#define PRINTF_FORMAT_STRING(s) s
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __GNUC__
|
|
||||||
#define PRINTF_ARGS(x, y) __attribute__((format(printf, x, y)))
|
|
||||||
#else
|
|
||||||
#define PRINTF_ARGS(x, y)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
int mg_printf(struct mg_connection *,
|
|
||||||
PRINTF_FORMAT_STRING(const char *fmt), ...) PRINTF_ARGS(2, 3);
|
|
||||||
|
|
||||||
|
|
||||||
// Send contents of the entire file together with HTTP headers.
|
|
||||||
void mg_send_file(struct mg_connection *conn, const char *path);
|
|
||||||
|
|
||||||
|
|
||||||
// Read data from the remote end, return number of bytes read.
|
|
||||||
int mg_read(struct mg_connection *, void *buf, size_t len);
|
|
||||||
|
|
||||||
|
|
||||||
// Get the value of particular HTTP header.
|
|
||||||
//
|
|
||||||
// This is a helper function. It traverses request_info->http_headers array,
|
|
||||||
// and if the header is present in the array, returns its value. If it is
|
|
||||||
// not present, NULL is returned.
|
|
||||||
const char *mg_get_header(const struct mg_connection *, const char *name);
|
|
||||||
|
|
||||||
|
|
||||||
// Get a value of particular form variable.
|
|
||||||
//
|
|
||||||
// Parameters:
|
|
||||||
// data: pointer to form-uri-encoded buffer. This could be either POST data,
|
|
||||||
// or request_info.query_string.
|
|
||||||
// data_len: length of the encoded data.
|
|
||||||
// var_name: variable name to decode from the buffer
|
|
||||||
// dst: destination buffer for the decoded variable
|
|
||||||
// dst_len: length of the destination buffer
|
|
||||||
//
|
|
||||||
// Return:
|
|
||||||
// On success, length of the decoded variable.
|
|
||||||
// On error:
|
|
||||||
// -1 (variable not found).
|
|
||||||
// -2 (destination buffer is NULL, zero length or too small to hold the decoded variable).
|
|
||||||
//
|
|
||||||
// Destination buffer is guaranteed to be '\0' - terminated if it is not
|
|
||||||
// NULL or zero length.
|
|
||||||
int mg_get_var(const char *data, size_t data_len,
|
|
||||||
const char *var_name, char *dst, size_t dst_len);
|
|
||||||
|
|
||||||
// Fetch value of certain cookie variable into the destination buffer.
|
|
||||||
//
|
|
||||||
// Destination buffer is guaranteed to be '\0' - terminated. In case of
|
|
||||||
// failure, dst[0] == '\0'. Note that RFC allows many occurrences of the same
|
|
||||||
// parameter. This function returns only first occurrence.
|
|
||||||
//
|
|
||||||
// Return:
|
|
||||||
// On success, value length.
|
|
||||||
// On error:
|
|
||||||
// -1 (either "Cookie:" header is not present at all or the requested parameter is not found).
|
|
||||||
// -2 (destination buffer is NULL, zero length or too small to hold the value).
|
|
||||||
int mg_get_cookie(const struct mg_connection *,
|
|
||||||
const char *cookie_name, char *buf, size_t buf_len);
|
|
||||||
|
|
||||||
|
|
||||||
// Connect to the remote web server.
|
|
||||||
// Return:
|
|
||||||
// On success, valid pointer to the new connection
|
|
||||||
// On error, NULL
|
|
||||||
struct mg_connection *mg_connect(struct mg_context *ctx,
|
|
||||||
const char *host, int port, int use_ssl);
|
|
||||||
|
|
||||||
|
|
||||||
// Close the connection opened by mg_connect().
|
|
||||||
void mg_close_connection(struct mg_connection *conn);
|
|
||||||
|
|
||||||
|
|
||||||
// Download given URL to a given file.
|
|
||||||
// url: URL to download
|
|
||||||
// path: file name where to save the data
|
|
||||||
// request_info: pointer to a structure that will hold parsed reply headers
|
|
||||||
// buf, bul_len: a buffer for the reply headers
|
|
||||||
// Return:
|
|
||||||
// On error, NULL
|
|
||||||
// On success, opened file stream to the downloaded contents. The stream
|
|
||||||
// is positioned to the end of the file. It is the user's responsibility
|
|
||||||
// to fclose() the opened file stream.
|
|
||||||
FILE *mg_fetch(struct mg_context *ctx, const char *url, const char *path,
|
|
||||||
char *buf, size_t buf_len, struct mg_request_info *request_info);
|
|
||||||
|
|
||||||
|
|
||||||
// File upload functionality. Each uploaded file gets saved into a temporary
|
|
||||||
// file and MG_UPLOAD event is sent.
|
|
||||||
// Return number of uploaded files.
|
|
||||||
int mg_upload(struct mg_connection *conn, const char *destination_dir);
|
|
||||||
|
|
||||||
|
|
||||||
// Convenience function -- create detached thread.
|
|
||||||
// Return: 0 on success, non-0 on error.
|
|
||||||
typedef void * (*mg_thread_func_t)(void *);
|
|
||||||
int mg_start_thread(mg_thread_func_t f, void *p);
|
|
||||||
|
|
||||||
|
|
||||||
// Return builtin mime type for the given file name.
|
|
||||||
// For unrecognized extensions, "text/plain" is returned.
|
|
||||||
const char *mg_get_builtin_mime_type(const char *file_name);
|
|
||||||
|
|
||||||
|
|
||||||
// Return Mongoose version.
|
|
||||||
const char *mg_version(void);
|
|
||||||
|
|
||||||
|
|
||||||
// MD5 hash given strings.
|
|
||||||
// Buffer 'buf' must be 33 bytes long. Varargs is a NULL terminated list of
|
|
||||||
// ASCIIz strings. When function returns, buf will contain human-readable
|
|
||||||
// MD5 hash. Example:
|
|
||||||
// char buf[33];
|
|
||||||
// mg_md5(buf, "aa", "bb", NULL);
|
|
||||||
void mg_md5(char buf[33], ...);
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif // __cplusplus
|
|
||||||
|
|
||||||
#endif // MONGOOSE_HEADER_INCLUDED
|
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
# This program is used to embed arbitrary data into a C binary. It takes
|
||||||
|
# a list of files as an input, and produces a .c data file that contains
|
||||||
|
# contents of all these files as collection of char arrays.
|
||||||
|
#
|
||||||
|
# Usage: perl <this_file> <file1> [file2, ...] > embedded_data.c
|
||||||
|
|
||||||
|
foreach my $i (0 .. $#ARGV) {
|
||||||
|
open FD, '<:raw', $ARGV[$i] or die "Cannot open $ARGV[$i]: $!\n";
|
||||||
|
printf("static const unsigned char v%d[] = {", $i);
|
||||||
|
my $byte;
|
||||||
|
my $j = 0;
|
||||||
|
while (read(FD, $byte, 1)) {
|
||||||
|
if (($j % 12) == 0) {
|
||||||
|
print "\n";
|
||||||
|
}
|
||||||
|
printf ' %#04x,', ord($byte);
|
||||||
|
$j++;
|
||||||
|
}
|
||||||
|
print " 0x00\n};\n";
|
||||||
|
close FD;
|
||||||
|
}
|
||||||
|
|
||||||
|
print <<EOS;
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
static const struct embedded_file {
|
||||||
|
const char *name;
|
||||||
|
const unsigned char *data;
|
||||||
|
size_t size;
|
||||||
|
} embedded_files[] = {
|
||||||
|
EOS
|
||||||
|
|
||||||
|
foreach my $i (0 .. $#ARGV) {
|
||||||
|
print " {\"$ARGV[$i]\", v$i, sizeof(v$i) - 1},\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
print <<EOS;
|
||||||
|
{NULL, NULL, 0}
|
||||||
|
};
|
||||||
|
|
||||||
|
const char *find_embedded_file(const char *name, size_t *size) {
|
||||||
|
const struct embedded_file *p;
|
||||||
|
for (p = embedded_files; p->name != NULL; p++) {
|
||||||
|
if (!strcmp(p->name, name)) {
|
||||||
|
if (size != NULL) { *size = p->size; }
|
||||||
|
return (const char *) p->data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
EOS
|
||||||
@@ -1 +0,0 @@
|
|||||||
abc123
|
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
# Copyright (c) 2014 Cesanta Software
|
||||||
|
# All rights reserved
|
||||||
|
|
||||||
|
PROG = unit_test
|
||||||
|
PROF_FLAGS = -fprofile-arcs -ftest-coverage -g -O0 -DGUI
|
||||||
|
CFLAGS = -W -Wall -pthread -I.. $(PROF_FLAGS) $(CFLAGS_EXTRA)
|
||||||
|
SOURCES = $(PROG).c
|
||||||
|
|
||||||
|
all: $(PROG)
|
||||||
|
./$(PROG)
|
||||||
|
gcov -b $(PROG).c | egrep '^(File|Lines)'
|
||||||
|
|
||||||
|
$(PROG): $(SOURCES) Makefile ../mongoose.c clean
|
||||||
|
$(CC) -o $(PROG) $(SOURCES) $(CFLAGS) -ldl -lssl
|
||||||
|
|
||||||
|
win:
|
||||||
|
wine cl $(SOURCES) /MD /nologo /DNDEBUG /O1 /Fe$(PROG).exe
|
||||||
|
wine $(PROG).exe
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -rf $(PROG) *.exe *.dSYM *.obj *.exp .*o *.lib *.gc*
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
#!/usr/bin/env perl
|
|
||||||
|
|
||||||
@flags = ("NO_POPEN", "NO_SSL", "NDEBUG", "DEBUG", "NO_CGI");
|
|
||||||
my $num_flags = @flags;
|
|
||||||
|
|
||||||
sub fail {
|
|
||||||
print "FAILED: @_\n";
|
|
||||||
exit 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
my $platform = $ARGV[0] || "linux";
|
|
||||||
|
|
||||||
for (my $i = 0; $i < 2 ** $num_flags; $i++) {
|
|
||||||
my $bitmask = sprintf("%*.*b", $num_flags, $num_flags, $i);
|
|
||||||
my @combination = ();
|
|
||||||
for (my $j = 0; $j < $num_flags; $j++) {
|
|
||||||
push @combination, $flags[$j] if substr($bitmask, $j, 1);
|
|
||||||
}
|
|
||||||
my $defines = join(" ", map { "-D$_" } @combination);
|
|
||||||
my $cmd = "CFLAGS=\"$defines\" make clean $platform >/dev/null";
|
|
||||||
system($cmd) == 0 or fail "build failed: $_";
|
|
||||||
print "Build succeeded, flags: [$defines]\n";
|
|
||||||
system("perl test/test.pl basic_tests >/dev/null") == 0
|
|
||||||
or fail "basic tests";
|
|
||||||
print "Basic tests: OK\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
print "PASS: All builds passed!\n";
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
echo "echoing bad headers: server must report status 500"
|
|
||||||
exec 1>&2
|
|
||||||
echo shit!!!
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
#!/usr/bin/env perl
|
|
||||||
|
|
||||||
print "Status: 123 Please pass me to the client\r\n\r\n";
|
|
||||||
-182
@@ -1,182 +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.
|
|
||||||
//
|
|
||||||
// Unit test for the mongoose web server. Tests embedded API.
|
|
||||||
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#ifndef _WIN32
|
|
||||||
#include <unistd.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "mongoose.h"
|
|
||||||
|
|
||||||
#if !defined(LISTENING_PORT)
|
|
||||||
#define LISTENING_PORT "23456"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static const char *standard_reply = "HTTP/1.1 200 OK\r\n"
|
|
||||||
"Content-Type: text/plain\r\n"
|
|
||||||
"Connection: close\r\n\r\n";
|
|
||||||
|
|
||||||
static void test_get_var(struct mg_connection *conn,
|
|
||||||
const struct mg_request_info *ri) {
|
|
||||||
char *var, *buf;
|
|
||||||
size_t buf_len;
|
|
||||||
const char *cl;
|
|
||||||
int var_len;
|
|
||||||
|
|
||||||
mg_printf(conn, "%s", standard_reply);
|
|
||||||
|
|
||||||
buf_len = 0;
|
|
||||||
var = buf = NULL;
|
|
||||||
cl = mg_get_header(conn, "Content-Length");
|
|
||||||
mg_printf(conn, "cl: %p\n", cl);
|
|
||||||
if ((!strcmp(ri->request_method, "POST") ||
|
|
||||||
!strcmp(ri->request_method, "PUT"))
|
|
||||||
&& cl != NULL) {
|
|
||||||
buf_len = atoi(cl);
|
|
||||||
buf = malloc(buf_len);
|
|
||||||
/* Read in two pieces, to test continuation */
|
|
||||||
if (buf_len > 2) {
|
|
||||||
mg_read(conn, buf, 2);
|
|
||||||
mg_read(conn, buf + 2, buf_len - 2);
|
|
||||||
} else {
|
|
||||||
mg_read(conn, buf, buf_len);
|
|
||||||
}
|
|
||||||
} else if (ri->query_string != NULL) {
|
|
||||||
buf_len = strlen(ri->query_string);
|
|
||||||
buf = malloc(buf_len + 1);
|
|
||||||
strcpy(buf, ri->query_string);
|
|
||||||
}
|
|
||||||
var = malloc(buf_len + 1);
|
|
||||||
var_len = mg_get_var(buf, buf_len, "my_var", var, buf_len + 1);
|
|
||||||
mg_printf(conn, "Value: [%s]\n", var);
|
|
||||||
mg_printf(conn, "Value size: [%d]\n", var_len);
|
|
||||||
free(buf);
|
|
||||||
free(var);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void test_get_header(struct mg_connection *conn,
|
|
||||||
const struct mg_request_info *ri) {
|
|
||||||
const char *value;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
mg_printf(conn, "%s", standard_reply);
|
|
||||||
printf("HTTP headers: %d\n", ri->num_headers);
|
|
||||||
for (i = 0; i < ri->num_headers; i++) {
|
|
||||||
printf("[%s]: [%s]\n", ri->http_headers[i].name, ri->http_headers[i].value);
|
|
||||||
}
|
|
||||||
|
|
||||||
value = mg_get_header(conn, "Host");
|
|
||||||
if (value != NULL) {
|
|
||||||
mg_printf(conn, "Value: [%s]", value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void test_get_request_info(struct mg_connection *conn,
|
|
||||||
const struct mg_request_info *ri) {
|
|
||||||
int i;
|
|
||||||
|
|
||||||
mg_printf(conn, "%s", standard_reply);
|
|
||||||
|
|
||||||
mg_printf(conn, "Method: [%s]\n", ri->request_method);
|
|
||||||
mg_printf(conn, "URI: [%s]\n", ri->uri);
|
|
||||||
mg_printf(conn, "HTTP version: [%s]\n", ri->http_version);
|
|
||||||
|
|
||||||
for (i = 0; i < ri->num_headers; i++) {
|
|
||||||
mg_printf(conn, "HTTP header [%s]: [%s]\n",
|
|
||||||
ri->http_headers[i].name,
|
|
||||||
ri->http_headers[i].value);
|
|
||||||
}
|
|
||||||
|
|
||||||
mg_printf(conn, "Query string: [%s]\n",
|
|
||||||
ri->query_string ? ri->query_string: "");
|
|
||||||
mg_printf(conn, "Remote IP: [%lu]\n", ri->remote_ip);
|
|
||||||
mg_printf(conn, "Remote port: [%d]\n", ri->remote_port);
|
|
||||||
mg_printf(conn, "Remote user: [%s]\n",
|
|
||||||
ri->remote_user ? ri->remote_user : "");
|
|
||||||
}
|
|
||||||
|
|
||||||
static void test_error(struct mg_connection *conn,
|
|
||||||
const struct mg_request_info *ri) {
|
|
||||||
int status = (int) ri->ev_data;
|
|
||||||
mg_printf(conn, "HTTP/1.1 %d XX\r\n"
|
|
||||||
"Conntection: close\r\n\r\n", status);
|
|
||||||
mg_printf(conn, "Error: [%d]", status);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void test_post(struct mg_connection *conn,
|
|
||||||
const struct mg_request_info *ri) {
|
|
||||||
const char *cl;
|
|
||||||
char *buf;
|
|
||||||
int len;
|
|
||||||
|
|
||||||
mg_printf(conn, "%s", standard_reply);
|
|
||||||
if (strcmp(ri->request_method, "POST") == 0 &&
|
|
||||||
(cl = mg_get_header(conn, "Content-Length")) != NULL) {
|
|
||||||
len = atoi(cl);
|
|
||||||
if ((buf = malloc(len)) != NULL) {
|
|
||||||
mg_write(conn, buf, len);
|
|
||||||
free(buf);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static const struct test_config {
|
|
||||||
enum mg_event event;
|
|
||||||
const char *uri;
|
|
||||||
void (*func)(struct mg_connection *, const struct mg_request_info *);
|
|
||||||
} test_config[] = {
|
|
||||||
{MG_NEW_REQUEST, "/test_get_header", &test_get_header},
|
|
||||||
{MG_NEW_REQUEST, "/test_get_var", &test_get_var},
|
|
||||||
{MG_NEW_REQUEST, "/test_get_request_info", &test_get_request_info},
|
|
||||||
{MG_NEW_REQUEST, "/test_post", &test_post},
|
|
||||||
{MG_HTTP_ERROR, "", &test_error},
|
|
||||||
{0, NULL, NULL}
|
|
||||||
};
|
|
||||||
|
|
||||||
static void *callback(enum mg_event event,
|
|
||||||
struct mg_connection *conn) {
|
|
||||||
const struct mg_request_info *request_info = mg_get_request_info(conn);
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i = 0; test_config[i].uri != NULL; i++) {
|
|
||||||
if (event == test_config[i].event &&
|
|
||||||
(event == MG_HTTP_ERROR ||
|
|
||||||
!strcmp(request_info->uri, test_config[i].uri))) {
|
|
||||||
test_config[i].func(conn, request_info);
|
|
||||||
return "processed";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(void) {
|
|
||||||
struct mg_context *ctx;
|
|
||||||
const char *options[] = {"listening_ports", LISTENING_PORT, NULL};
|
|
||||||
|
|
||||||
ctx = mg_start(callback, NULL, options);
|
|
||||||
pause();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
Loaded 100 of 124 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user