Commit Graph

1737 Commits

Author SHA1 Message Date
cpq
12c32d09fb Pass mg_http_message to MG_EV_WS_OPEN 2021-01-17 11:16:19 +00:00
cpq
ae6fd6aa35 Add extra headers param to mg_ws_upgrade() 2021-01-16 22:48:43 +00:00
cpq
72d3a49352 Restore SO_EXCLUSIVEADDRUSE 2021-01-13 03:47:11 +00:00
cpq
6c93446a1f Better reuseaddr handling on Win32 2021-01-13 03:08:11 +00:00
cpq
b7a79a556a Add extra headers param to mg_http_serve_file 2021-01-07 12:48:20 +00:00
Hakaba Hitoyo
1689a0d56b Update mongoose.c. 2021-01-05 12:35:28 +09:00
cpq
117aeaa15d Fix fd leak for cached static files 2021-01-03 09:39:46 +00:00
cpq
c7e09bd7b4 Add SSI include file=, include virtual= 2021-01-02 17:57:51 +00:00
cpq
86824795a0 Pass opts structure to mg_http_serve_dir() 2021-01-02 12:30:09 +00:00
cpq
1b0636c2d2 More checks in mg_ws_send 2021-01-02 12:20:08 +00:00
cpq
bdef3d6afd Fix win98 test 2020-12-28 06:32:55 +00:00
cpq
a882aab30e Add captive dns server example 2020-12-28 05:25:29 +00:00
cpq
71a22adc06 Add ESP8266 example 2020-12-27 01:29:42 +00:00
cpq
55f5f74658 Add mingw gcc and g++ tests 2020-12-25 19:24:51 +00:00
cpq
49b8480bfb Add http-reverse-proxy example 2020-12-25 04:32:56 +00:00
cpq
b2ab484883 Fix #954 2020-12-24 19:10:54 +00:00
cpq
4c3b97be7d Squash -DMG_ENABLE_FS=0 build warning 2020-12-24 18:48:28 +00:00
cpq
60e1b64455 Fix https://github.com/cesanta/mongoose/issues/1030 2020-12-24 17:01:49 +00:00
cpq
6bcd02bb1c Enhance HTTP client example 2020-12-24 16:52:58 +00:00
cpq
c8826e8f9c Refactor mg_ntoa and mg_straddr 2020-12-24 08:05:54 +00:00
cpq
25bc13ef1e Squash some warnings under mingw crosscompiler 2020-12-24 07:26:50 +00:00
cpq
4d123a15f9 Drop deprecated register keyword 2020-12-23 21:20:48 +00:00
cpq
abfd81cb9d Fix WS frame length encoding for len 0xffff 2020-12-23 16:18:49 +00:00
cpq
3895678bee Use MG_EV_WS_CTL for WS control messages 2020-12-23 11:58:08 +00:00
cpq
e0a1feafe0 Fix localhost resolution 2020-12-23 10:15:09 +00:00
cpq
c3aae185df Add ipv6 server test 2020-12-22 10:16:31 +00:00
cpq
2e87783246 Add IPv6 client test 2020-12-22 09:44:59 +00:00
cpq
b93456f512 Do not create socket until resolved 2020-12-21 12:26:44 +00:00
cpq
1052ee0766 Fix openssl build, and add openssl test 2020-12-20 21:45:58 +00:00
cpq
29534218d7 IPv6 related refactoring 2020-12-20 16:55:33 +00:00
cpq
d7abd53062 Always send MG_EV_CONNECT on TCP connect 2020-12-18 15:13:19 +00:00
cpq
aede72fa37 Refactor HTTP client 2020-12-18 14:29:30 +00:00
cpq
d3ebcaf5d2 Remove unneeded defines that break vc2015 build 2020-12-18 09:48:28 +00:00
cpq
04450ec659 Update http server example to showcase SSL 2020-12-18 09:01:14 +00:00
cpq
82a378e519 Add extra param to http_reply() 2020-12-17 22:47:55 +00:00
cpq
29d31ba919 More boundary checks for mg_dns_parse() 2020-12-17 19:14:17 +00:00
cpq
4519ea568d Add conditional for SSL_use_certificate_chain_file() 2020-12-17 12:12:46 +00:00
cpq
d9551c75b1 Refactor MQTT parsing 2020-12-16 10:14:00 +00:00
cpq
8d45cf6972 Add mqtt-server example 2020-12-15 20:29:47 +00:00
cpq
f176e1ae59 Handle more mime types 2020-12-15 11:58:30 +00:00
cpq
88ada54045 More tests 2020-12-12 20:38:09 +00:00
cpq
c5b1c08d05 Use MSG_NONBLOCKING for recv/send 2020-12-12 16:48:47 +00:00
cpq
d806ed5d5f Better coverage 2020-12-11 22:58:50 +00:00
cpq
37e9a2ee95 Fix C++ build error 2020-12-11 18:26:54 +00:00
cpq
90686ee5c9 Add ws examples 2020-12-11 17:35:58 +00:00
cpq
85c5577955 mg_dns_parse_name() recursion protection 2020-12-11 14:02:52 +00:00
cpq
30d4a1ad0f Fix mg_sntp_parse() 2020-12-11 13:16:51 +00:00
cpq
1b551741b8 Fix mg_url_decode fuzz 2020-12-11 09:35:50 +00:00
cpq
369f44adfa Add version.h 2020-12-10 17:46:26 +00:00
cpq
42d7865e14 Pre-built desktop server 2020-12-10 17:39:40 +00:00
cpq
94d2e86b60 More docs 2020-12-08 16:26:17 +00:00
cpq
d1b8f9e01f Fuzz-test mg_http_var and base64 2020-12-07 18:52:40 +00:00
cpq
228acefa36 Fix native socketpair call 2020-12-07 10:55:50 +00:00
cpq
d1d8a77bf6 Use socketpair syscall when available 2020-12-07 10:25:28 +00:00
cpq
7ea3293aba More tests 2020-12-07 08:54:58 +00:00
cpq
866c987409 Tuning test 2020-12-07 05:46:47 +00:00
cpq
136a37ef73 Tuning test 2020-12-07 05:18:07 +00:00
cpq
bcc62c96c8 Tuning test 2020-12-07 04:56:50 +00:00
cpq
15d6cb3065 Tuning test 2020-12-07 04:44:23 +00:00
cpq
d7a02d13e4 Add test++ linx++ 2020-12-07 03:47:37 +00:00
cpq
f2fba1d200 7.0 refactor 2020-12-05 11:26:32 +00:00
Deomid Ryabkov
be64f81eee Add mg_next_query_string_entry_n() and mg_url_decode_n()
Move to mg_util.h so encode and decode are next ot each other.

Pull out mg_next_list_entry_n() for advanced use cases.

Add unit tests.
2020-10-24 22:53:50 +01:00
Deomid Ryabkov
a4b6d58b24 Add cs_log_{lock,unlock}
In implementatiosn that have preemptive scheduelrs these can be implemented
to ensure logging from different threads is properly serialized.
2020-08-28 20:29:13 +01:00
Sergey Lyubka
86f391c701
Merge pull request #1139 from rojer/warns
Fix warnings and sync line numbers of unamalgamated sources
2020-08-20 00:45:02 +01:00
Deomid Ryabkov
a308872c88 Fix warnings and sync line numbers of unamalgamated sources 2020-08-19 22:02:50 +01:00
Deomid Ryabkov
a369160296 Add missing range check in mg_get_http_header()
h/t BushraAloraini

Fixes https://github.com/cesanta/mongoose/issues/1135
2020-08-19 21:48:45 +01:00
Deomid Ryabkov
b0a1cd7b0d Sync src with amalgamated versions
Now src contains exactly what's embedded in mongoose.c and .h, nothing more.

Added `tools/amalgam.sh` to aamlgamate both files at once.

There are no functional changes to mongoose.c, .h in this PR, only slight filename changes.
2020-07-08 02:08:49 +01:00
Sergey Lyubka
d22ff2fce7 Really revert 4880069 2020-06-11 19:08:55 +01:00
Sergey Lyubka
d6693ed360 Revert 4880069 2020-06-11 19:04:24 +01:00
Sergey Lyubka
f778d22eac Make it possible to override default FS update algorithm
PUBLISHED_FROM=774a111548da97bd9d195e177b5fb66b0fd66135
2020-06-11 18:27:48 +01:00
Sergey Lyubka
3aa76dcaec Subst CREDPARAMS
PUBLISHED_FROM=545e8dff4ea0bef061c893252c613e3429f56184
2020-06-11 18:27:46 +01:00
Deomid "rojer" Ryabkov
4680573a6b Fixes for -pedantic build mode
PUBLISHED_FROM=d0a15356cf047e579c74869ce3e8fe813752e8c7
2020-05-23 15:55:27 +00:00
Deomid "rojer" Ryabkov
95fcb261eb Fix processing of keep-alive requests when chunks are consumed
PUBLISHED_FROM=136ce2ed4f143d7ee246e5fd1078c431e205bb3a
2020-05-22 23:07:38 +00:00
Sergey Lyubka
3d53ed17fb Allow OpenSSL session reuse on 2-way SSL, integrate https://github.com/cesanta/mongoose/pull/877
PUBLISHED_FROM=6e2568b963869d062dd51b590f8e536d043c4ca2
2020-05-21 16:17:14 +01:00
Sergey Lyubka
ca11f5ab49 Fix OpenSSL error issue
PUBLISHED_FROM=a3bcdb68f48a4de4a4f55b4399792fdd5211c88d
2020-05-02 11:19:29 +00:00
Sergey Lyubka
ef92f2e9c5 Integrate cesanta/dev#1062 - Fix dereferencing in mg_http_free_proto_data_endpoints
PUBLISHED_FROM=47fd1a4de07d2c53c994d29c88ac1d3a7f61c1a0
2020-02-21 14:30:21 +00:00
Sergey Lyubka
b015e33ea5 Integrate https://github.com/cesanta/mongoose/pull/1096 - dir listing nits
PUBLISHED_FROM=a343bd61f98cbcc0f8cab02a62b912e494c27601
2020-02-14 08:30:56 +00:00
Sergey Lyubka
734c13cdf5 Squash win32 warnings
PUBLISHED_FROM=3819e74efb9ac8ff84a68105107afcacaeeab92a
2020-02-11 11:52:07 +00:00
Deomid "rojer" Ryabkov
1bf3ad2426 MQTT ping fixes
* Actually drop the connection when no response to ping arrives within the next interval.
 * Avoid sending immediate ping when wall time is adjusted, it's usually spurious.

PUBLISHED_FROM=8049280b58edfb94dd0fcb6a1e89ffefe69bcea1
2020-02-11 08:04:02 +00:00
Deomid "rojer" Ryabkov
884b9a4813 Add Content-Encoding: gzip when serving .gz files
If file ends with .gz and has known "secondary extnesion", i.e. test.html.gz,
its content type is determined by the secondary extension and content-encoding is set to gzip.

PUBLISHED_FROM=a238763b4424bafabec2e58ccae4522cacdd7c78
2020-02-01 08:33:49 +00:00
Deomid "rojer" Ryabkov
c2b5e4f3b8 Fix a leak when CA certificate file is invalid
Also free up some RAM by not allocating ca_cert when `MBEDTLS_X509_CA_CHAIN_ON_DISK` is enabled.

PUBLISHED_FROM=5e5f4103707de98c929973d2aed0aaedf0bb60da
2020-01-22 10:03:30 +00:00
Deomid "rojer" Ryabkov
bc15e9ce9a Fix value of MG_MQTT_DUP
PUBLISHED_FROM=de1772bd6ea01f3dc467ceebb3b2af5cbe8eb240
2020-01-20 09:33:25 +00:00
Deomid Ryabkov
70dc6d8dc9 Add mg_strcasecmp()
CL: Add mg_strcasecmp()

PUBLISHED_FROM=cd2a26fa12473bfa0f5e7a0a1d34fb86562ee082
2019-12-29 19:39:45 +00:00
Deomid Ryabkov
10b11b03a8 Add mg_dns_encode_name_s for non-NUL terminated strings
PUBLISHED_FROM=012e2939021d1b275a39632fd2982891d2c98c4e
2019-12-29 19:33:41 +00:00
Sergey Lyubka
cb602f178c Fix int overflow in parse_mqtt()
PUBLISHED_FROM=f9106d2f746c67ae004aeab12685eaf9cd558cd8
2019-12-23 11:13:41 +00:00
Sergey Lyubka
464113c5ae Sync mongoose changes
PUBLISHED_FROM=8b6ebf46728aca40f916dde88e372b4540ed6ea4
2019-12-19 11:12:57 +00:00
Deomid Ryabkov
c34f6c54e7 Fix ota-shadow logic
PUBLISHED_FROM=68a57c967f8864946244893c71a397ab4e27d75d
2019-12-07 09:03:26 +00:00
Sergey Lyubka
8fb58ebbca Lsm
PUBLISHED_FROM=5f465d245bb9ada5202cdd23ddc5b9856df26951
2019-11-04 13:48:28 +00:00
Sergey Lyubka
1a38e91042 Next
PUBLISHED_FROM=6fa0be81ce429b8db9e3ed572cb4a876b6fb2693
2019-07-12 09:33:26 +00:00
Sergey Lyubka
b6196371bb Lsm
PUBLISHED_FROM=18d9d1e6411db84788c527d1c34ad2adc846df00
2019-06-26 10:33:24 +00:00
Sergey Lyubka
b3e0f780c3 Fix heap-based overflow in parse_mqtt
PUBLISHED_FROM=3306592896298597fff5269634df0c1a1555113b
2019-06-13 08:18:14 +00:00
Sergey Lyubka
2bdbfc27f6 Integrate https://github.com/cesanta/mongoose/issues/1008
PUBLISHED_FROM=1b7bf2d7318568851e6c8f07451cd3982d9498b6
2019-06-13 07:48:28 +00:00
Sergey Lyubka
3fc61a3edc Fix mg_resolve2()
PUBLISHED_FROM=b0df728a75073c6ea9fc1984bb6a6b463f539347
2019-05-24 12:33:25 +00:00
Deomid Ryabkov
1fb9f922b0 Fix mgos compile check
CL: none

PUBLISHED_FROM=a1320658181aa19cd1a269d7ae62e11b3439ef84
2019-05-03 16:36:08 +00:00
Deomid Ryabkov
b4fbaf7c13 Fix locking in lwip net_if
Was not being enabled when it should have been.

CL: Fix locking in lwip net_if

PUBLISHED_FROM=4810e73417c7599f0ea08a09812ed320d02f7cae
2019-04-23 20:03:44 +00:00
Deomid Ryabkov
9884241df8 mg_net_if_lwip: Fix invoking callbacks on tcpip thread
tcpip_callback doesn't wait for the callback to run (as was previosuly assumed).

CL: mg_net_if_lwip: Fix invoking callbacks on tcpip thread

PUBLISHED_FROM=930c45f1346f9c3b024e5e684f4a452c762db92b
2019-04-15 16:33:40 +00:00
Deomid Ryabkov
e5910da300 Deliver EV_CLOSE to the last endpoint handler
CL: mg: Deliver EV_CLOSE to the last endpoint handler

PUBLISHED_FROM=02ee2c6627ed9ee1d35022244f71dfe1877ce2c0
2019-03-19 13:15:41 +00:00
Sergey Lyubka
23533b83a4 Allow NULL handler for mg_bind and mg_connect
CL:  Allow NULL handler for mg_bind and mg_connect

PUBLISHED_FROM=4963d5c022c2c57dd03101d9c7e72ca910c3bb61
2019-03-06 12:33:24 +00:00
Deomid Ryabkov
1e9fabe1ca Fix handling of WS handshake error response
Check response code, make sure it's 101.
Pass http_message to the client to keep it appraised.
This represents a slight change in the API -
in case of an error MG_EV_WEBSOCKET_HANDSHAKE_DONE will now be delivered where previosuly connection would just hang.
Clients that do not examine the argument may for a moment think handshake has succeeded but in fact connection will be closed immediately.

CL: mg: Fix handling of WS handshake error response

PUBLISHED_FROM=645a43d9e5bee216e54411f85827c9b974e9a7d1
2019-02-14 21:19:34 +00:00
Deomid Ryabkov
95a36b1759 Log file:line instead of function; add cs_log_set_file_level()
cs_log_set_filter() is removed in favor of cs_log_set_file_level() which
allows setting log verbosity of individual files and/or lines.

E.g.: `mg_=1,mjs=1,=4` - level for for everything except mjs and mongoose.

We use the fact that we are usually pretty careful with our file names and use prefixes consistently.

In mos, `debug.file_level` sets the option on boot and `Sys.SetDebug` is updated to parse `file_level` option to change it at runtime.

CL: Log file:line instead of function; add cs_log_set_file_level()

PUBLISHED_FROM=49f18d4d0d3dd224865129a4f8fe6cccd1d9bc12
2019-01-30 12:57:19 +00:00
Deomid Ryabkov
86ffa3a3ea Properly support MQTT wildcards when matching topics
CL: mg: Properly support MQTT wildcards when matching topics

PUBLISHED_FROM=aa60a71d488f4b56dff0951886c8a9a4066fd4f2
2019-01-22 12:19:04 +00:00
Deomid Ryabkov
69e2b2985d Add mg_strfree()
CL: Add mg_strfree()

PUBLISHED_FROM=b80566218986e0607a9d2758bf776a1031b27212
2019-01-16 22:48:59 +00:00
Бобби
c431904b56 Send extra options with OPTIONS
CL: Send extra options with OPTIONS. Integrate https://github.com/cesanta/mongoose/pull/657

PUBLISHED_FROM=6ee609a92febd8d908f7713f94fb73657443a09a
2019-01-16 11:33:57 +00:00
Sergey Lyubka
22e602debb Check for NULL in tcp_recved_tcpip()
CL: Check for NULL in tcp_recved_tcpip()

PUBLISHED_FROM=3f5bbc2e35b79d363eac4b99a1f0d17c9b81d4ec
2018-12-21 13:03:48 +00:00
Deomid Ryabkov
455cec67a5 CC3220: Enterprise auth support
CL: wifi: CC3220: Enterprise auth support

PUBLISHED_FROM=ce445eb5b740073c9a3f9811f1acd404ce134f2e
2018-12-18 18:19:21 +00:00
Deomid Ryabkov
e2dfac946d Ensure that user sees all the data before connection is closed
If user throttles receive by setting recv_mbuf_limit,
after the net interface reports connection as closed we must wait
for data to trickle through before disposing of it.
There can still b data in the buffers (e.g. SSL).

CL: mg: Ensure that user sees all the data before connection is closed

PUBLISHED_FROM=22be0fa368950a9fdb03cfb00febc7c0a1674b01
2018-12-10 21:04:49 +00:00
Бобби
c198d2e5f1 Make MG_CTL_MSG_MESSAGE_SIZE overridable
CL: Make MG_CTL_MSG_MESSAGE_SIZE overridable

Fix https://github.com/cesanta/mongoose/pull/987

PUBLISHED_FROM=b0a7c67297b98f616c9eadcd3c34b8747939c918
2018-12-07 10:04:00 +00:00
Deomid Ryabkov
9a70abef24 Add mbuf_append_and_free() and mbuf_move()
CL: Add mbuf_append_and_free() and mbuf_move()

PUBLISHED_FROM=bdf73906dd93b2ebeace160596508e15480b54b4
2018-12-05 21:49:01 +00:00
Deomid Ryabkov
53e1c469a2 Add ability for multipart data handler to provide pushback
It can specify how much data was actually processed and the rest will be re-delivered on next poll.

CL: mg: Add ability for multipart data handler to provide pushback

PUBLISHED_FROM=e0168c5064c3a32921c9209bc09f4da2079cd616
2018-12-05 16:02:56 +00:00
Deomid Ryabkov
15b361fbac Add mbuf_clear()
PUBLISHED_FROM=754b98b3000b24ad3b3d9cc0b4c480ca005a1c3f
2018-11-23 15:50:55 +00:00
Deomid Ryabkov
3130e59244 Stop reading if connection is closing
CL: none

PUBLISHED_FROM=3b74ca02e2960bbbf130f6d95aef679f2917e824
2018-11-02 18:12:34 +00:00
Deomid Ryabkov
93286836f9 Read all available data during recv poll
CL: mg: Read all available data during recv poll

PUBLISHED_FROM=b081025b9fb392c988924c7097b5333c38053f6f
2018-11-02 14:50:32 +00:00
Deomid Ryabkov
91b57aa9a8 Add MG_MK_STR_N() and mg_str_starts_with()
CL: Add MG_MK_STR_N() and mg_str_starts_with()

PUBLISHED_FROM=f01003efc6aa6ff45fa99c7ad6e5319f5002f22d
2018-10-29 15:50:31 +00:00
Deomid Ryabkov
220231e647 Fix digest auth result comparison
Should use length of the exected response, not the response sent by the user.

CL: mg: Fix digest auth result comparison

PUBLISHED_FROM=23375133b8babac0b276b51395917ad975e1bd3c
2018-10-15 16:47:18 +00:00
Deomid Ryabkov
c438bb0bc5 Make mg_rpc more easily portable
CL: none

PUBLISHED_FROM=2e77d72cdf82454349a7fe29cc77bd0b90ac4369
2018-10-09 12:04:12 +00:00
Deomid Ryabkov
1ffccdb7b2 Remove a spammy log line
PUBLISHED_FROM=b3ec2b3b43a464700a6e6d75b7336f823549cce3
2018-10-04 15:48:48 +00:00
Deomid Ryabkov
e79fe4b8f0 Update mbedTLS to 2.13.1
CL: Update mbedTLS to 2.13.1

PUBLISHED_FROM=bd1216f727605a901f062a044c0c0ca762f4a6d1
2018-10-04 10:06:35 +00:00
Deomid Ryabkov
aaf1fc3a4a Schedule a poll when LwIP reports TCP data sent
PUBLISHED_FROM=0cf3029d9a9b851882325e2298b878bc83fc2d33
2018-09-28 11:03:47 +00:00
Deomid Ryabkov
8b42353039 Check HTTP chunk size, ensure it's reasonable
CL: mg: Check HTTP chunk size, ensure it's reasonable

PUBLISHED_FROM=d9f6babd314c092b42ce9e7fe31d6b30a38366a2
2018-09-27 12:51:21 +00:00
Deomid Ryabkov
05c687e251 Fix handling of keepalive HTTP requests/responses
Clean the HTTP connection state when ia request/response has been fully
buffered and handler invoked.

Fixes https://github.com/cesanta/mongoose/issues/971

CL: mg: Fix handling of keepalive HTTP requests/responses

PUBLISHED_FROM=70c854aa306aacb9161f6ee48841f38dc0312e6b
2018-09-27 12:51:18 +00:00
Deomid Ryabkov
b99a94a652 Fix build w/o logging
PUBLISHED_FROM=694346bd6562c55e5ab00886df47f7cbfb0a3720
2018-09-25 11:34:05 +00:00
Deomid Ryabkov
98f6c8aa4f Trim recv_mbuf when we know the size of the data
CL: none

PUBLISHED_FROM=e354b67ab6f8246af50c601f5f70d36c029601ea
2018-09-17 16:04:00 +00:00
Deomid Ryabkov
f63d833a33 Update STM32 build image
* Update CubeL4 to 1.13.0
 * Rebuild OurTLS with `-DMBEDTLS_X509_CA_CHAIN_ON_DISK`
 * Add `-Wextra` and fix build issues

CL: Update STM32 build image

PUBLISHED_FROM=a7eacff7580bab6c6e40bdaf6164df575a717c55
2018-09-11 11:49:08 +00:00
Deomid Ryabkov
ab035901f8 ISM43XXX networking support (TCP, UDP client)
Listeners still TODO

CL: ISM43XXX networking support (TCP, UDP client)

PUBLISHED_FROM=b58ba88b9e6bd7b55ccb607d0b69cea98cb52fa5
2018-09-11 06:34:08 +00:00
Deomid Ryabkov
563c31303e Add net_if_null, a no-op net interface
Can be used for cases where device has no networking but mongoose is still needed for its event loop.

CL: mg: Add net_if_null, a no-op net interface

PUBLISHED_FROM=e79b4a8667508bbde1437dda9dad77ce3a3aa630
2018-09-06 08:34:17 +00:00
Deomid Ryabkov
421e099f2b Refactor mg polling
* Change return type of mg_mgr_poll to return number of events
 * Add mg_mgr_min_timer
 * Refactor main poll loop to remove LwIP-specific stuff

CL: Refactor mg polling

PUBLISHED_FROM=dc94618b32fa3c84a2f053bd04d134297780ec82
2018-09-06 06:34:18 +00:00
Бобби
955d4a3129 Fix file upload on windows
CL: Fix https://github.com/cesanta/mongoose/issues/962 - file upload on windows

PUBLISHED_FROM=85688eee147a1df468cca92f4ac61526ce9c02bf
2018-08-21 15:06:40 +00:00
Deomid Ryabkov
c2d83a9db0 Don't touch send_mbuf when sending MQTT messages
h/t @M4GNV5

Fixes https://github.com/cesanta/mongoose/issues/943
Closes https://github.com/cesanta/mongoose/issues/944

CL: mg: Don't touch send_mbuf when sending MQTT messages

PUBLISHED_FROM=da7b4f8acec2e403caa4addd5739d036a6a74c76
2018-08-13 14:04:49 +00:00
Deomid Ryabkov
f33d3a4e02 Fix body length calculation in mg_handle_cgi
Fixes https://nvd.nist.gov/vuln/detail/CVE-2018-10945

CL: mg: Fix body length calculation in mg_handle_cgi

PUBLISHED_FROM=0c30cf36fdb67c75f6148468701e23d6ee72d953
2018-08-13 13:05:22 +00:00
Deomid Ryabkov
86b8a56b05 Add host name verification for OpenSSL
Closes https://github.com/cesanta/mongoose/pull/955

CL: mg: Add host name verification for OpenSSL

PUBLISHED_FROM=e35dd636ba7ce63116f0a38031074d22f6cd5dac
2018-08-13 13:05:21 +00:00
Deomid Ryabkov
31632c6361 Fix build with CS_ENABLE_STDIO=0
Closes https://github.com/cesanta/mongoose/pull/945

CL: Fix build with CS_ENABLE_STDIO=0

PUBLISHED_FROM=7d15f17fc42241facdba5b1004b5b7f3dda599dc
2018-07-12 20:42:45 +00:00
Deomid Ryabkov
98c99279c3 Fix warnings on newer versions of GCC
PUBLISHED_FROM=f1d25145446057fed9e8d634ca637364ca43a5e8
2018-07-09 08:34:29 +00:00
Deomid Ryabkov
cdb8d7b692 Add mg_strstrip: trims whitespace at the ends of s
CL: Add mg_strstrip: trims whitespace at the ends of s

PUBLISHED_FROM=a7e10054ac25fa2b3a878876da93a6b30d9507b3
2018-07-07 14:04:42 +00:00
Deomid Ryabkov
6a51af9efe Fix a bug in mg_mgr_init_opt with opts.num_ifaces
h/t @YankunLi

Closes https://github.com/cesanta/mongoose/pull/939

CL: mg: Fix a bug in mg_mgr_init_opt with opts.num_ifaces

PUBLISHED_FROM=a87518b3505429a3cf9cd6d84b3b781e7dbdcfd5
2018-06-27 08:50:07 +00:00
Deomid Ryabkov
1c8449cea6 Fix pipelining issue with multipart upload
Do not clear buffer at the end of multipart request to allow following request to proceed.

Closes https://github.com/cesanta/mongoose/pull/940

CL: mg: Fix pipelining issue with multipart upload

PUBLISHED_FROM=cc7d38b126eaa863553ee4e124cfafcd72030fcf
2018-06-26 12:05:04 +00:00
Deomid Ryabkov
339bbee0df mg_file_upload_handler: Support multiple files
curl -F file1 -F file2 ...

Add a unit test and fix a minor memory leak when returning an error.

CL: mg_file_upload_handler: Support multiple files

PUBLISHED_FROM=5c4bf2be676346fb782e80f50f79df6a6721ac88
2018-06-20 13:35:31 +00:00
Deomid Ryabkov
9ba6eb716d mg_lwip: Fix race during clean conenction teardown
Set CLOSE_IMMEDIATELY flag when destroying conn.
This avoid some races in LWIP adapter.

CL: mg_lwip: Fix race during clean conenction teardown

PUBLISHED_FROM=5c67982390dfaf83527e85d1291f64c6050aa932
2018-06-18 16:35:04 +00:00
Deomid Ryabkov
1299d6118f Add MG_HIDE_SERVER_INFO
Closes https://github.com/cesanta/mos-libs/pull/2

CL: Add MG_HIDE_SERVER_INFO

PUBLISHED_FROM=ed8a5b65f1c8238df414cd1c1f8bb1f579082f55
2018-05-17 16:20:44 +00:00
Deomid Ryabkov
1614e7ba8d Restore FFI-ability of struct mg_str
mgos_dlsym needs to include mg_str for ffi_exports to be able to use it

PUBLISHED_FROM=a2dd167c8e8f9e9b7316a856f19a4603080c3632
2018-04-13 17:12:07 +00:00
Deomid Ryabkov
43b5a4e735 Add a special attribute to printf-like funcs
Enables extra compile-time checks

CL: none

PUBLISHED_FROM=9f7d658fbda5c721cf40293bf29967bb056d0437
2018-04-13 17:12:06 +00:00
Deomid Ryabkov
e89be2e944 Add mg_url_encode_opt()
CL: Add `mg_url_encode_opt()` - a parametrized version of `mg_url_encode()`

PUBLISHED_FROM=17fa57a7a5325b51b6e3aef3855eac4e82c35782
2018-04-10 11:04:31 +00:00
Deomid Ryabkov
c2fbff6d0e Fix mg_http_parse_header
Per standard, cookies are delimited by `; `.

CL: Fix mg_http_parse_header: treat ";" as a delimiter.

PUBLISHED_FROM=039243c30f5fabf4a4700a43506f841b3268306a
2018-04-10 10:19:36 +00:00
Deomid Ryabkov
b8eca17c55 Reamalgam mongoose.{c,h}
PUBLISHED_FROM=8828792097bd19774472b8a2e61420565684d174
2018-04-03 16:08:21 +00:00
Deomid Ryabkov
3e33e57707 Mongoose net_if and ssl_if refactoring
A major cleanup, disentangling net_if and ssl_if.
Pulled a lot of common logic into the core and reduced size of net_if implementations.

CL: Mongoose net_if and ssl_if refactoring

PUBLISHED_FROM=29bd4dcb264a1fd96b3dd164e2d880e1c2c0921e
2018-03-30 23:19:49 +00:00
Deomid Ryabkov
c80f4c5313 Fix an edge case in multipart HTTP upload parsing
Consume buffer as soon as we know there is no boundary there, no need to delay until next chunk arrives.
This prevents stall where buffer fills up in one go and next chunk never arrives.

CL: Fix an edge case in multipart HTTP upload parsing

PUBLISHED_FROM=025f9001d272df2a75ece22b199b1944d5db9840
2018-03-30 19:35:20 +00:00
Deomid Ryabkov
0a90cab44a Improve mbuf allocation behavior
* Limit total amount of headroom, in absolute terms (`MBUF_SIZE_MAX_HEADROOM`).
 * If unable to allocate with headroom, fall back to allocating the required minimum.
 * For mOS, set default `MBUF_SIZE_MULTIPLIER` to 2 to avoid floating point operations.
   Since max headroom size is now capped to 128 bytes, this will not result in much of a bloat.

PUBLISHED_FROM=11d4fc65a46a805bb7c8960f89a3d0b753c58bb8
2018-03-22 07:49:57 +00:00
Serge A. Zaitsev
d16dbc197f mongoose: fix http pipeline
mongoose: fix formatting

mongoose: fix formatting

mongoose: remove debugging messages

PUBLISHED_FROM=1194e018001cc5f2b598096593d7aac4ec8dc04d
2018-03-20 16:41:56 +00:00
Serge A. Zaitsev
0ae2b82b60 freshen: early attempts to make ota and config work
freshen: implement ota rollback

freshen: api for rpc

freshen: implement rpc api (without transport)

PUBLISHED_FROM=9f935f676161c81464a0dc53d5d8d085b2437ffb
2018-02-27 14:19:33 +00:00
Бобби
780077d118 Fix mg_socketpair for lwip + UDP
CL: Fix mg_socketpair for lwip + UDP

PUBLISHED_FROM=6dd09136b3837016026523fb34acb5cc893cadbe
2018-02-18 16:49:38 +00:00
Deomid Ryabkov
ad8f1d88d4 Fix buffer size passed to inet_ntop()
Fixes https://github.com/cesanta/mongoose-os/issues/394

CL: Fix buffer size passed to inet_ntop()

PUBLISHED_FROM=4a6702527627ccbb780f45200274b09a28be69ee
2018-02-13 12:49:53 +00:00
Dmitry Frank
b9b20c6494 Implement mg_http_parse_header2()
Which is a replacement of (deprecated) `mg_http_parse_header`, but,
similarly to `asprintf`, allocates a new buffer if the client-provided
one is not large enough.

Also use it throughout mongoose code, and thus some header-related
limitations are removed; in particular,
https://github.com/cesanta/mongoose/issues/813 is fixed.

CL: Mongoose Web Server: Deprecate `mg_http_parse_header()` and implement `mg_http_parse_header2()` instead, which allocates a new buffer if the client-provided one is not large enough (similarly to `asprintf`).
CL: Mongoose Web Server: Fix limitations of header value lengths, e.g. when parsing authentication headers such as nonce, etc.

PUBLISHED_FROM=c75b1bbbbdb294ea85075ce69b1368f115fdd1ef
2018-02-07 23:04:29 +00:00
Dmitry Frank
c3d9d17e34 Remove "mongoose" prefix from includes
In certain files it was necessary to make tests work from public
mongoose repo, so this commit makes things consistent.

PUBLISHED_FROM=694454d0ff007229c65d524a2a2beaf126420f15
2018-02-05 20:20:05 +00:00
Dmitry Frank
7bf5144e62 Make tests work on public repo as well
PUBLISHED_FROM=78acb18d597b6f47f31da13087fa6685f21ce445
2018-02-05 14:35:37 +00:00
Deomid Ryabkov
ab000c684a Fix includes
Even though it makes no prectical difference due to the way amalgamation works

CL: none

PUBLISHED_FROM=6977833f2b469e5b969385ad9ae21a28af76746f
2018-02-03 01:20:47 +02:00
Dmitry Frank
aba60dadec Add mg_ prefix to mongoose sources
CL: none

PUBLISHED_FROM=d6ebe5fa88c61ae3b8569897d9b09d54610bec73
2018-02-03 01:20:47 +02:00
Dmitry Frank
f29457e967 Remove tunneling from mongoose
CL: Mongoose Web Server: Remove tunneling functionality which was used by nobody

PUBLISHED_FROM=38b9e8ae7b0a5a1dbba5cff4074843dc681267d3
2018-02-02 21:50:13 +00:00
Dmitry Frank
0ab1c7ef76 Fail if passed a NULL handler
Before it resulted in an endless recursion.

Resolves https://github.com/cesanta/mongoose/issues/871

CL: Mongoose Web Server: Fail if passed a NULL handler to `mg_bind` or `mg_bind_opt`.

PUBLISHED_FROM=376e5d330a643fa530f6a27a422a1500f986c721
2018-02-02 06:35:12 +00:00
Dmitry Frank
47abc641f1 Fix nonce in digest authentication
CL: Mongoose Web Server: Digest authentication: Fix nonce validity check (expired nonce or nonce from the future did not cause the the check to fail)
CL: Mongoose Web Server: Digest authentication: Fix nonce request value; it worked before because nonce validity check was broken as well
CL: Mongoose Web Server: Digest authentication: Add `nonce` argument to `mg_http_create_digest_auth_header()`: clients should use the value received from the server's authentication request.

Resolves https://github.com/cesanta/mongoose/issues/809

PUBLISHED_FROM=5e59f90ed6b2a4311ed6763159da81c2aaf6af4c
2018-02-01 22:05:43 +00:00
Dmitry Frank
7519b2ef3a Improve websocket implementation
CL: Mongoose Web Server: Websocket: Respond to Ping with Pong
CL: Mongoose Web Server: Websocket: Properly close a connection with Close frame (in response to a client's close and when protocol failure is detected)
CL: Mongoose Web Server: Websocket: Fix support of fragmented messages
CL: Mongoose Web Server: Websocket: Add support for control frames interjected in the middle of a fragmented message

PUBLISHED_FROM=e2b3794aaacc64633540c493194cccc62afa2077
2018-02-01 13:20:19 +00:00
Dmitry Frank
ce8657f12f Fix corner case in preparing cgi env
`path_info` was dereferenced without checking for NULL, and a few lines
below, it was checked for NULL.

CL: none

PUBLISHED_FROM=9f14dc68c152b9b1119b276f047686d831bace38
2018-01-30 20:39:54 +00:00
Dmitry Frank
8e366916d5 Ensure that the name buffer is null-terminated
CL: none

PUBLISHED_FROM=f165b556582f712c2c1c752e01c41d22fe593397
2018-01-30 20:39:53 +00:00
Dmitry Frank
33f53ab000 Don't ignore setsockopt return value
PUBLISHED_FROM=f3c1fcf015f6f72eca2eb3d5dad469cd66a837a9
2018-01-30 20:39:52 +00:00
Julien Ammous
7d7bb3b388 Don't use user_data in mqtt server
Integrates https://github.com/cesanta/mongoose/pull/884
Closes https://github.com/cesanta/mongoose/issues/883

CL: Mongoose Web Server: Don't use user_data in mqtt server

PUBLISHED_FROM=7785784a766e0ba7514bbba604cde14e7bad3f73
2018-01-30 19:39:05 +00:00
Dmitry Frank
0b4bf13335 Fix mg_parse_multipart in case of malformed req
CL: Mongoose Web Server: Fix mg_parse_multipart in case of malformed request

PUBLISHED_FROM=9b33b03e9ab2ca204ad2f8d061df169246644072
2018-01-30 19:39:03 +00:00
Dmitry Frank
228984a3fc Fix a corner case in receiving UDP data
CL: none

PUBLISHED_FROM=9c13882517374644c6d799976f1048f04ae446d7
2018-01-30 14:35:15 +00:00
Dmitry Frank
255da78bed Fix socket leak when there are too many open fds
CL: Mongoose Web Server: Fix socket leak when there are too many open file descriptors

Fixes https://github.com/cesanta/mongoose/issues/870

PUBLISHED_FROM=c802b6834a54eca37821d46efde192c527e0a6b7
2018-01-30 13:37:42 +00:00
Бобби
961fb96bb7 Fix OOB access in mg_match_prefix_n()
CL: Fix OOB access in mg_match_prefix_n().
    Made mg_match_prefix_n() return non-negative result.

PUBLISHED_FROM=611454df6a6c55bfa7ddf05e7d268a86fa0457a8
2018-01-27 13:50:13 +00:00
Deomid Ryabkov
d6475fcd19 Fix TCP RX path regression in SSL mode
CL: Fix TCP RX path regression in SSL mode

PUBLISHED_FROM=2cfdb33e5f711bbc4b98e2d24ba3377de0f1d3c5
2018-01-18 11:04:45 +00:00
Dmitry Frank
ac538f755f Close undrained and stuck http connections
CL: - Mongoose Web Server: close undrained and stuck http connections

PUBLISHED_FROM=a11656b195dbe2ef8473455a171a583e37cedb2c
2018-01-16 15:20:47 +00:00
Deomid Ryabkov
5b2eb4f0e1 Enable building with CS_ENABLE_STDIO=0
h/t @kzyapkov

PUBLISHED_FROM=d15a5a0057f69f2f755af6436e676b1b179d069d
2018-01-15 20:20:36 +00:00
Dmitry Frank
80f4133bbf Get rid of magic numbers in parse_mqtt
PUBLISHED_FROM=63cc7ed8c3378bebf209d3620efb09d73675370c
2018-01-02 10:50:38 +00:00
Dmitry Frank
d10fb9451c Move the recv limit check to mqtt
PUBLISHED_FROM=028d6f56ec1cc15484c995335f00d087b590faef
2017-12-29 17:35:29 +00:00
Dmitry Frank
88ae2ecadb Drain rx_chain before closing the connection
PUBLISHED_FROM=08eee4052dd9bbc364875a577409cb78665dee30
2017-12-29 07:50:43 +00:00
Dmitry Frank
85d19dad47 Respect recv_mbuf_limit in lwip
PUBLISHED_FROM=470ff0f484bff3e4478651f0b64cc160bba8ebfc
2017-12-28 12:49:54 +00:00
Dmitry Frank
17703fe3e8 Improve docs for logging
PUBLISHED_FROM=72f0892ecfba5b1c3c2a70f0ecd5715578d7ffce
2017-12-16 17:55:53 +00:00
Бобби
4e11d5cdbf Move shadow to event API
PUBLISHED_FROM=cd059adee921dd10fd89100b0e2500ff8d7743eb
2017-12-14 13:32:11 +00:00
Sergey Lyubka
987bc1d580 Use 8k iobuf limit for aws
PUBLISHED_FROM=971951e1eeb82078b986cd6e25e52cfc1ccef286
2017-12-02 21:26:35 +00:00
Dmitry Frank
ddd35c0cba Fail if authn file is configured but doesn't exist
PUBLISHED_FROM=2c176091ffb6c7c5cfe8ea4f05b6109e00b33383
2017-11-28 19:35:22 +00:00
Sergey Lyubka
c97b615785 Fix mg_parse_uri()
PUBLISHED_FROM=e5b829d93ecf946e5bdbbf33132be7068ffe0dd2
2017-11-28 16:45:52 +00:00
Dmitry Frank
9ab6d084df Expose digest auth checking functions
PUBLISHED_FROM=1bfc6e332f56b68eb6155bb729a97a0d8d5a316c
2017-11-28 10:05:36 +00:00
Deomid Ryabkov
cf8d0a25aa Rename base64.{c,h} to cs_base64.{c,h}
To avoid name clashes.

PUBLISHED_FROM=e6ae32ec48f9b599eace7a9214a1863cdc185fd9
2017-11-24 11:36:12 +00:00
Deomid Ryabkov
90716417c9 Compatibility with LwIP 2.0
2.0 redefined LWIP_VERSION in a way that is no longer compatible with use by preprocessor (boo).
also, tcp_pcb.acked is gone, but we only use it for debug, so it doesn't matter.

PUBLISHED_FROM=776f90a08bd5024fa8a61dae257af6c60ec6710d
2017-11-23 10:05:43 +00:00
Deomid Ryabkov
101afbc9b8 Use weaker but faster cipher suites
ECDHE is way too slow on ESP8266 w/o cryptochip, this sometimes results in WiFi STA deauths.
Disable DHE completely because it's just hopelessly slow.

PUBLISHED_FROM=d9c8e95b7d5c992f9e127726c569f187b1e0b453
2017-11-21 15:33:00 +00:00
Бобби
a197646867 Integrate cesanta/mongoose-os/pull/370
PUBLISHED_FROM=5bee629477514370f9b670771e786c4f4ddae934
2017-11-09 09:49:28 +00:00
Бобби
00d1d2c0e7 Make mjs & frozen vc98 & vc2017 friendly
PUBLISHED_FROM=7cde8b374d5e318b5cdd69fc5b4de86b2a9552f5
2017-11-08 16:04:08 +00:00
Deomid Ryabkov
7942803a75 Fix MQTT SUBSCRIBE parsing
Make sure topic is properly NUL-terminated.
Ignore SUBSCRIBE requests with no topic expressions.

PUBLISHED_FROM=a00f39dda44fe63299e971a91a98f8ee57dd2a64
2017-10-30 15:34:22 +00:00
Deomid Ryabkov
a8b74a9021 Fix bug when network conn is closed before CGI
NULL out cgi_nc->user_data so it doesn't touch nc anymore.

PUBLISHED_FROM=de2f76981c377d8951fb8e18e8b3d41dbfcf38b1
2017-10-30 14:20:27 +00:00
Deomid Ryabkov
27a9a62843 Fix SimpleLink listener for SSL
Must set SSL parameters before invoking sl_Listen

PUBLISHED_FROM=9147e7aa945f75e73d5c7cd7987cb5749025a86b
2017-10-24 07:19:45 +00:00
Deomid Ryabkov
9b268b6c77 Fix timer handling
ev_timer_time may remain the same for legit reason, so to prevent looping, instead, reset it before invoking the handler.
To let user know what the initial setting was, pass it as the argument instead of current time (which is kind of pointless).

PUBLISHED_FROM=fa328009f097f9b49b5b0dd13a38ee6d6e6518de
2017-10-21 09:19:42 +00:00
Sergey Lyubka
3b3ac48edd Fix potential leak in socks client
PUBLISHED_FROM=2cb4449d2f36d59db2b0dc37c46b35de6a461810
2017-10-19 13:49:43 +00:00
Бобби
b5dd0e8093 Use verbose flags in both socks client and server
PUBLISHED_FROM=d17e96a97e1621e9788844bcd627c3143d37315c
2017-10-19 13:24:30 +00:00
Deomid Ryabkov
9b24fdfd1d Reformat mongoose
PUBLISHED_FROM=5202fa46a6a834bde35168ba566d3dce7c48f453
2017-10-19 13:24:26 +00:00
Бобби
8193302162 Initial socks5 client & server implementation
PUBLISHED_FROM=05d3cca6223c963e7ae89dde3628fa8fad46e6bd
2017-10-18 14:05:13 +00:00
Dmitry Frank
f0c6630a16 BREAKING: Sys config API change
Now apps should use getters and setters instead of accessing struct
fields directly, e.g. instead of `get_cfg()->update.timeout` it should
be `mgos_sys_config_get_update_timeout()` to get the current value, and
`mgos_sys_config_set_update_timeout(123)` to update the value.

For now, the config structs are public, but they will be made private
soon, so use accessors to keep your code working.

PUBLISHED_FROM=f7d582421a8d7e4d1ed50a280f2670d8b62f8d45
2017-10-11 11:15:48 +00:00
Deomid Ryabkov
1db747da29 Do not double-count recved bytes
Mongoose would report consumed bytes twice if mg_call is invoked recursively (e.g. proto_handler uses mg_call to invoke user's handler).
Reporting twice as much recved as was delivered effectively disables LwIP's TCP throttling and causes buffers to grow too big.

PUBLISHED_FROM=4ad5cd5db4dd54623bd6de2d50d32ddcc9e2b08a
2017-09-14 13:51:03 +00:00
Deomid Ryabkov
8065439f96 Acquire lock when manipulating rx in SSL recv path
PUBLISHED_FROM=a34cfa3ebc12daf75d7f24c8d3f3707dcc33d9a2
2017-09-14 11:06:24 +00:00
Dmitry Frank
0aaba7a461 Add cs_timegm
Which is a slightly modified version from
https://stackoverflow.com/questions/283166/easy-way-to-convert-a-struct-tm-expressed-in-utc-to-time-t-type

PUBLISHED_FROM=b73f920ca42c45473c23337782e815306bdf69f1
2017-09-12 16:20:16 +00:00
Deomid Ryabkov
3d6b568c6e Prefer ECDHE with CBC over DHE ciphersuites
PUBLISHED_FROM=4ddfc25af77247fac7e7d04cc0e56d6f3800f87b
2017-09-07 11:04:38 +00:00
Deomid Ryabkov
2b2816cfe4 Store reassembled WS frame length in proto_data
PUBLISHED_FROM=7bbe7dd20dca8435c786dca30200a4973ae0827d
2017-09-06 19:05:00 +00:00
Deomid Ryabkov
2fa18b47db Fix DNS name uncompression
PUBLISHED_FROM=07e820f539fa5feca2ad1cf81faca8404b773a65
2017-09-06 18:05:29 +00:00