Compare commits

..
84 Commits
Author SHA1 Message Date
Deomid Ryabkov 6e50fe4475 Mongoose 6.10
PUBLISHED_FROM=c61fa89018f8cef4f798e094acff8d36c72869f2
2017-10-31 10:01:27 +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
Sergey Lyubka 598e96a0cc Make amalgam work on windows
PUBLISHED_FROM=92f43c7b0a705ff40c4aea07f2ee0627f8e0e4a1
2017-10-19 13:49:42 +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
Бобби 8313896a85 Unbind things from v7
PUBLISHED_FROM=d20f138ae37c99a34cc29e7bfb327d7834404d93
2017-10-18 16:05:25 +00:00
Бобби 8193302162 Initial socks5 client & server implementation
PUBLISHED_FROM=05d3cca6223c963e7ae89dde3628fa8fad46e6bd
2017-10-18 14:05:13 +00:00
Бобби 6e3e5560d0 Move mongoose docs to https://cesanta.com/docs/
PUBLISHED_FROM=ebf5568abe82952ab2751298185a10189098013f
2017-10-16 15:18:24 +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
Deomid Ryabkov 62c896a872 Merge pull request #856 from cesanta/dev
Mongoose 6.9
2017-09-13 14:57:33 +03:00
Deomid Ryabkov 2db07dfc3b Mongoose 6.9
PUBLISHED_FROM=9e9047060b688291655ed227d19b7937fa9a147d
2017-09-13 11:36:46 +00:00
Sergey Lyubka 34eb3f1e66 Merge pull request #855 from cesanta/dev
Mongoose 6.8
2017-09-13 11:48:50 +01:00
Deomid Ryabkov 9d30e892e9 Mongoose 6.8
PUBLISHED_FROM=082d0bf5e9b06b850382ce502c7f5b4d68a6a328
2017-09-13 09:21:30 +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
Deomid Ryabkov c8af7cdd27 Check for int overflow when parsing WS frames
PUBLISHED_FROM=b7325b38e881455df703b0b628c41931565ccb33
2017-09-06 17:34:37 +00:00
Deomid Ryabkov f857f6394f Access QoS field after validating topic length
PUBLISHED_FROM=6f2d9849d75ca1ec2b6dade11ccad8d0c5d4b3bd
2017-09-06 15:35:15 +00:00
Deomid Ryabkov 97d733e129 Fix MQTT broker SUBSCRIBE request parsing
Add checks on the number of subscribe requests per packet and overall per-session subscription limit.

PUBLISHED_FROM=faaf5c50af31a0694c9308a664f2e418dbb0eb18
2017-09-06 13:23:13 +00:00
Deomid Ryabkov 77e44c7c0e Harden MQTT variable length parsing
PUBLISHED_FROM=e16ee57bc30277e5b5684e53da78e69baaf9f779
2017-09-06 11:49:43 +00:00
Наше вам с кисточкой abf89d32d9 Make C ws client work with Go
PUBLISHED_FROM=263553121b992ec0f66b0275b4e10f4176281812
2017-09-01 08:35:53 +00:00
Deomid Ryabkov 177e05deb2 CC3220: AWS connection works
PUBLISHED_FROM=5831462c5be0b79afff32130a1f45784f32bc524
2017-08-31 21:52:31 +00:00
Deomid Ryabkov eb5645241c CC3220: WiFi, basic networking support
PUBLISHED_FROM=db89a45a536f0234d6d5cf740354c0dbeeff1f26
2017-08-31 15:32:50 +00:00
Deomid Ryabkov 202300952c CC3220: GPIO, sys_config and mgos_init support
```
Using port /dev/ttyACM0
[Aug 30 19:33:02.105]
[Aug 30 19:33:02.114] cc32xx_init          c_no_libs 1.0 (20170830-163205/mos8@6587ffd6+)
[Aug 30 19:33:02.123] cc32xx_init          Mongoose OS 2017083016 (20170830-163205/mos8@6587ffd6+)
[Aug 30 19:33:02.130] cc32xx_init          RAM: 253588 total, 240044 free
[Aug 30 19:33:04.430] cc32xx_start_nwp     NWP v3.4.0.0 started, host driver v2.0.1.19
[Aug 30 19:33:04.437] mgos_vfs_dev_open    slfs_container ({"prefix": "spiffs.img.0"}) -> 20005a64
[Aug 30 19:33:04.450] cc32xx_vfs_dev_slfs_ 20005a64 spiffs.img.0.0 262144 0xfffffffffffffffe
[Aug 30 19:33:04.457] mgos_vfs_mount       Mount SPIFFS @ / (dev 20005a64, opts ) -> 20005a74
[Aug 30 19:33:06.102] mgos_vfs_mount       /: size 233681, used: 4016, free: 229665
[Aug 30 19:33:06.108] mgos_vfs_mount       Mount SLFS @ /slfs (dev 0, opts ) -> 20005ed4
[Aug 30 19:33:06.114] mgos_vfs_mount       /slfs: size 0, used: 0, free: 0
[Aug 30 19:33:06.718] mgos_sys_config_init MAC: 04A316459442
[Aug 30 19:33:06.720] mgos_sys_config_init WDT: 30 seconds
[Aug 30 19:33:06.724] Hello, world!
[Aug 30 19:33:06.728] mgos_init            Init done, RAM: 253588 total, 236544 free, 235864 min free
```

PUBLISHED_FROM=7e83c9ddcc642bd324a40e125d6636ece824fb18
2017-08-30 17:49:34 +00:00
Deomid Ryabkov c7bea65ae7 CC3220 FS support
For now, we only support SPIFFS-in-a-box, same as CC3200.
On CC3200SF it should be possible to have SPIFFS on built-in flash, but that is left for later.

PUBLISHED_FROM=dee337c8cd8ed288c22abe9960eef81e6e90cc4a
2017-08-30 16:50:03 +00:00
Deomid Ryabkov d5a9000d46 Harden MQTT parser some more
PUBLISHED_FROM=5e7fcc7bf145aa8e1045e8d627b1c0731bb4341b
2017-08-30 12:49:30 +00:00
Deomid Ryabkov f62018451f Fix subscription parsing in MQTT broker
Also, do not accept PUBLISH and SUBSCRIBE before a sucessful CONNECT.

PUBLISHED_FROM=b5096cdc2ec5da1358244c428efbbb2e20be1a05
2017-08-30 08:49:35 +00:00
Deomid Ryabkov 0a93e301c9 CC3220: Exception handling, NWP init
Also make CC3200 use newer ARM compiler, generates slightly smaller code.

PUBLISHED_FROM=a0be49d7ea864a95886f7110887a59f6f11802d7
2017-08-29 21:49:53 +00:00
Dmitry Frank 6fe9cae62a Add mg_next_comma_list_entry_n()
And mgos_conf_check_access_n()

PUBLISHED_FROM=c7de937b4f5463ca463d604183a4ee831617bd6d
2017-08-27 12:49:28 +00:00
Deomid Ryabkov 38e984a008 CC3220 first steps
Achievement unlocked: CC3220 port prints a boot banner.
Then locks up.

Included in this PR is refactoring to pull out common parts to be shared with CC3200.

PUBLISHED_FROM=5fb9d9a00bb9ce7f63dde20bc1876076b76d5257
2017-08-26 17:05:00 +00:00
Our CI Bot 09e4254718 Add mqtt_over_websocket_server example
Fixed bug in websocket handshake:
now adding Sec-WebSocket-Protocol header in handshake response.

PUBLISHED_FROM=e4a71ff9dc4aeec63db40cb7f356dc5b25c1215a
2017-08-24 10:34:35 +00:00
Dmitry Frank d4b55c4ceb Separate digest auth from HTTP headers parsing
PUBLISHED_FROM=f97569ae2f31ab94ce4875eae4d0a198f719c388
2017-08-22 19:51:53 +00:00
Deomid Ryabkov 7d5479985d Enable LWIP net_if locking on ESP32 (doh!)
https://forum.mongoose-os.com/discussion/comment/4620/#Comment_4620

PUBLISHED_FROM=679dd48e078615ef4f57d1879957b734f549ef2e
2017-08-21 14:24:51 +00:00
Deomid Ryabkov 6517af3dea CC3220 blinky
Ignore all the mess, this is just the beginning...

PUBLISHED_FROM=41ab3c5af0b1d07204619dd4d8dc2e84b6a54f32
2017-08-21 07:52:09 +00:00
ruslanvaliullin 7632a5e4af Fix ignoring DhcpNameServer
PUBLISHED_FROM=73d6767e4aaa7249eeb5d76f9e7160be041292ca
2017-08-17 15:51:21 +00:00
ruslanvaliullin 7f20c41dd5 Implement rmdir & sleep func instead macros
PUBLISHED_FROM=62c73e5fb4f70e2b5b8824ce092012508640b173
2017-08-17 14:32:36 +00:00
ruslanvaliullin 66b23b11b0 Fix Nmap reset on ESP8266
PUBLISHED_FROM=7b9c85e7708721f2c6d0e2fc8ad5c32c61b48854
2017-08-16 17:40:48 +00:00
Deomid Ryabkov 448b44094a Add automated check for extern "C"
Fix headers that didn't have it

PUBLISHED_FROM=ce8140783d4b661f16278a4a5adc957b21965473
2017-07-27 11:19:56 +00:00
Sergey Lyubka 8bbb44f90c Always send MG_EV_HTTP_CHUNK
PUBLISHED_FROM=33957356e1510b73b37768496c74a6bf12630215
2017-07-21 13:34:52 +00:00
Deomid Ryabkov 0fba87c755 Make mg_url_encode public
Change the API to heap-allocate the string and get rid of a bunch of fat stack buffers.

PUBLISHED_FROM=c793dc64a9a044a9769d92ea16859f5d704a2181
2017-07-21 12:06:52 +00:00
Sergey Lyubka fea648496c Fix https://github.com/cesanta/mongoose-os/issues/318
PUBLISHED_FROM=2fc7b59b2edd0f473acd22067439471778acef8e
2017-07-20 08:05:12 +00:00
Sergey Lyubka 944a6b761c Fix https://github.com/cesanta/mongoose/pull/824
PUBLISHED_FROM=ed2c39b9e00a7374af7fed5af0c9acd6c330334a
2017-07-17 14:28:35 +00:00
Sergey Lyubka f1ae183752 Fix https://github.com/cesanta/mongoose/pull/829
PUBLISHED_FROM=6e56c250fe62010e25b6ed489c0d608163ba629c
2017-07-17 14:28:34 +00:00
Sergey Lyubka a0ece4e969 Fix links for MWS readme
PUBLISHED_FROM=c6c31d47eedcfe09b675e3f56d967da5b22809f6
2017-07-17 12:18:57 +00:00
Sergey Lyubka 0bb14abbdd Nitpick for MQTT example
PUBLISHED_FROM=a0dd26c00b41363f1cc58c28f530fbdf272ed146
2017-07-14 10:52:37 +00:00
Deomid Ryabkov 4c37e49274 Disable insecure and deprectaed SSL protocols
Also allow disabling conmpression and forcing server cipher list.

PUBLISHED_FROM=5539deec9c2382ba34597872dd7f3a5abc0cc311
2017-07-05 17:04:31 +00:00
Deomid Ryabkov 2a2bc33a89 Add mg_strstr
PUBLISHED_FROM=4306e870e2cab854febb6becc198ca2247e2e002
2017-07-05 16:20:32 +00:00
Dmitry Frank 41558bbf64 Fix formatting
PUBLISHED_FROM=4d4d49136e13ba8035d452a4f64fcaf48f15bdb3
2017-07-04 19:35:55 +00:00
Sergey Lyubka 4d0cc95ff4 Add JS net api test
PUBLISHED_FROM=f2821b104f8f2fc196ce4064b7c9f35ea152368d
2017-07-04 19:04:45 +00:00
Deomid Ryabkov cfd28a4f7a Add mg_strchr
Write unit tests for some mg_str functions.

PUBLISHED_FROM=1fc7e1d5d5ef259d4023f295aec8651caa3e7e86
2017-07-03 15:05:54 +00:00
Deomid Ryabkov 5a0b6fc35a Use SSL_CTX_{get,set}_app_data to store context
h/t @hendrikw01

Fixes https://github.com/cesanta/mongoose/issues/826
Closes https://github.com/cesanta/mongoose/pull/831

PUBLISHED_FROM=d5e1285bee9bcbb85d581ee62972a2fde7d9c0db
2017-07-03 11:04:40 +00:00
Dmitry Frank 3e59e1c465 Fix formatting
PUBLISHED_FROM=1803e726eee7bb64496d70389655083eb70257ab
2017-07-02 20:05:53 +00:00
Sergey Lyubka ae611a6e55 Clean up v7 from mongoose
PUBLISHED_FROM=efa9cc3aaf0c5ae8841e029370f882b615cebf1b
2017-07-01 08:51:09 +00:00
Sergey Lyubka a7a2e3deb1 Introduce log filter
PUBLISHED_FROM=b8f538f87e034452032284d45b78090338e87f72
2017-06-29 14:34:28 +00:00
Deomid Ryabkov cae0a1cbc0 Fix mongoose amalgamation
PUBLISHED_FROM=16ae777c949caf87e7dce428d62fa8878a30d318
2017-06-28 19:13:47 +00:00
Sergey Lyubka 244e5f67d3 Commonize pattern matching functions
PUBLISHED_FROM=e69e298a51dbe0f9c47184169ecad06eef0676fc
2017-06-28 18:35:37 +00:00
Dmitry Frank ff078882d5 Don't define fileno stub in C++
PUBLISHED_FROM=98fb6c78d20a98dfba07ba6671bd51a394bbc4ca
2017-06-27 15:19:50 +00:00
Sergey Lyubka 8d76733fad Make mg_conn_addr_to_str return len
Also amend api_net.js to use returned length.

PUBLISHED_FROM=38e15f9587edf28049c5b9e5f126b4db159910e8
2017-06-26 21:02:02 +00:00
Deomid Ryabkov fb3a5a7d90 Disable cert verification when ssl_ca_cert is '*'
PUBLISHED_FROM=578706e48a2c1fbbf5e9aaab3eba743e7d13fa61
2017-06-21 14:23:30 +00:00
Deomid Ryabkov f374ac5f9a Do not close already closed connection
PUBLISHED_FROM=9e345f2319141f20b89e28a2d29adba21ea213e1
2017-06-20 20:06:18 +00:00
Deomid Ryabkov 02707364f0 Lower conn accept message verbosity to DEBUG
Raised in previous commit by mistake

PUBLISHED_FROM=31a73fb610c34ed0c85d081bfa11a8067f216696
2017-06-20 19:14:33 +00:00
Deomid Ryabkov 104106b9cf Invoke tcp_accepted() on the listening pcb
As required by the LWIP API

PUBLISHED_FROM=7bfc6d816aa69f8fdd7592ade48b2d52e2d4991a
2017-06-20 19:14:31 +00:00
Deomid Ryabkov 474e065a30 MAX_PATH_SIZE -> MG_MAX_PATH
PUBLISHED_FROM=32bda9e86a11cad3b908d211a1f7bc9d27312874
2017-06-20 18:06:36 +00:00
Deomid Ryabkov 27094896b1 mOS filesystem refactoring: introduce VFS
With different filesystem implementations and storage drivers, like grown-ups have :)
This is not currently used to add any new functionality, we still have
only one FS and driver on ESP8266 and ESP32; CC3200 has two: SPIFFS and SLFS.
This will be used soon to implement filesystems on additional SPI flash chips and SD cards.

PUBLISHED_FROM=293960fef82952c505e9b1925aac7724c7308362
2017-06-13 15:35:38 +00:00
Dmitry Frank cd48bcfd7d Don't ignore userdata in mg_bind
PUBLISHED_FROM=0ffcd770535efa66ff1b6f9201f2caf832bd5055
2017-06-09 19:05:40 +00:00
Sergey Lyubka 5baeba53d7 Reorg docs
PUBLISHED_FROM=657a53762ada0ab3fe715a15939eb510a637e37f
2017-06-09 19:05:34 +00:00
Dmitry Frank 3a3b433849 Don't ignore userdata in mg_bind
PUBLISHED_FROM=0ffcd770535efa66ff1b6f9201f2caf832bd5055
2017-06-09 16:18:45 +03:00
ruslanvaliullin a2192ae483 Add mbuf_append result check
PUBLISHED_FROM=967a7ff3684e548ddbfe92365f7718a99e14d098
2017-06-07 18:50:24 +00:00
Deomid Ryabkov 023b55f2e5 MQTT client keep alive fixes
- Move keep alive management up to the Mongoose library
 - Only outgoing control messgaes should reset keepalive timer
 - Add unit test

https://forum.mongoose-os.com/discussion/1155/mqtt-keep-alive-compliance-issue

PUBLISHED_FROM=f86e30744ded53a6f7f96afec066b4ff3b4372c0
2017-06-04 21:50:23 +00:00
Deomid Ryabkov e4309d472b Annotate cs_log_printf with format attribute
This adds compile-time checks for format strings.

Fix issues exposed by this.

PUBLISHED_FROM=b9f820d8ad44fce9186dfdad4fe109fafa5371ce
2017-05-30 12:05:34 +00:00
Deomid Ryabkov c5452fc2ec Don't ignore non-merge commits when publishing
Merge commits are not explicitly ignored either: they're just naturally
ignored as empty commits.

PUBLISHED_FROM=12871fd4c9b1e9de4e57e13d810bffd98ddba299
2017-05-28 13:22:49 +00:00
Dmitry Frank f78ee9d42e Don't ignore non-merge commits when publishing
Merge commits are not explicitly ignored either: they're just naturally
ignored as empty commits.

PUBLISHED_FROM=2c814104eedd76ee90813488277ecaaf2baf6315
2017-05-28 13:22:48 +00:00
Deomid Ryabkov c8416cc17d NULL out name server field properly
Fixes https://github.com/cesanta/mongoose-os/issues/260

PUBLISHED_FROM=e95076915d52edb2298e3ea386281c277e42c89a
2017-05-26 14:44:11 +00:00
Deomid Ryabkov cf0a969a65 ESP8266 and ESP32 build image updates
ESP32: 2.0-r6
ESP8266: 2.0.0-1.5.0-r5

This brings updated mbedTLS with support for on-disk CA chains:
https://github.com/cesanta/mbedtls/compare/esp32_2.0-r5...esp32_2.0-r6
ESP8266 gets bigger rollup (ESP32 got those changes earlier, seems ok):
https://github.com/cesanta/mbedtls/compare/esp8266...esp8266_2.0.0-1.5.0-r5

Saves ~1.5K RAM for now, but will allow adding more roots to ca.pem without wasting RAM.

Refactored docker build for ESP8266 in the same way as was done earlier for ESP32.

PUBLISHED_FROM=db8eb0f91875d02266a8baaf1141c0d65eb59674
2017-05-25 17:20:18 +00:00
Deomid Ryabkov 06670d3401 Fix double-removal of send_mbuf data with SSL on
Other minor fixes.
Also decrease idle poll interval to 100 ms, as a workaround for some cases of incorrect next poll delay computation.

Added HW tests for SSL fetches.

Fixes cesanta/mongoose-os#262

PUBLISHED_FROM=4d19f845768b4b3b990d25959d4211972368d7fc
2017-05-19 16:20:00 +00:00
Deomid Ryabkov 7c0493071f Fix a typo
PUBLISHED_FROM=183a1bb571d0e2f5c23181107d30417f73c1eeb1
2017-04-11 11:22:42 +01:00
Alexander Alashkin c60fe0c6f6 Fix crash in multipart handling
Close cesanta/dev#6974

PUBLISHED_FROM=4d4e4a46eceba10aec8dacb7f8f58bd078c92307
2017-04-11 11:22:18 +01:00
61 changed files with 1844 additions and 918 deletions

No files matched your search

+9 -13
View File
@@ -8,7 +8,7 @@ used by vast number of open source and
commercial products - it even runs on the International Space station! commercial products - it even runs on the International Space station!
Mongoose makes embedded network programming fast, robust, and easy. Mongoose makes embedded network programming fast, robust, and easy.
- [Download Mongoose Source Code here](https://www.cesanta.com) - [Download Mongoose Source Code here](https://www.cesanta.com/download.html)
Looking for a complete IoT firmware solution? Looking for a complete IoT firmware solution?
@@ -17,9 +17,9 @@ Check out [Mongoose OS](https://mongoose-os.com) - open source embedded operatin
# Support # Support
- [Study mongoose example code](https://github.com/cesanta/mongoose/tree/master/examples) - [Study mongoose example code](https://github.com/cesanta/mongoose/tree/master/examples)
- [Read User Guide and API reference](https://docs.cesanta.com/mongoose) - [Read User Guide and API reference](https://docs.cesanta.com/mongoose)
- [Support Forum - ask your technical questions here] (http://forum.cesanta.com/index.php?p=/categories/mongoose) - [Support Forum - ask your technical questions here](https://forum.mongoose-os.com/categories/mongoose)
- [Commercial licensing and support available] (https://www.cesanta.com/services-support) - [Commercial licensing and support available](https://www.cesanta.com/licensing.html)
- [Check our latest releases] (https://github.com/cesanta/mongoose/releases) - [Check our latest releases](https://github.com/cesanta/mongoose/releases)
# Features # Features
@@ -47,7 +47,7 @@ Check out [Mongoose OS](https://mongoose-os.com) - open source embedded operatin
Mongoose is released under Commercial and [GNU GPL v.2](http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) open source licenses. Mongoose is released under Commercial and [GNU GPL v.2](http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) open source licenses.
Commercial Projects: [Contact us for commercial license.] (https://www.cesanta.com/contact) Commercial Projects: [Contact us for commercial license.](https://www.cesanta.com/contact.html)
# Dashboard Example # Dashboard Example
@@ -55,18 +55,14 @@ Mongoose is often used to implement device dashboards and real-time
data exchange over Websocket. Here is a dashboard example that illustrates data exchange over Websocket. Here is a dashboard example that illustrates
the functionality: the functionality:
![](http://www.cesanta.com/hubfs/www.cesanta.com/diagrams/dash_mongoose_diagram.png) ![](http://www.cesanta.com/images/dashboard.png)
[Developing a new product? Contact us today to discuss how Mongoose can help. [Developing a new product? Contact us today to discuss how Mongoose can help.](https://www.cesanta.com/contact.html)
](https://www.cesanta.com/contact)
# Contributions # Contributions
To submit contributions, sign To submit contributions, sign [Cesanta CLA](https://cesanta.com/cla.html)
[Cesanta CLA](https://docs.cesanta.com/contributors_la.shtml)
and send GitHub pull request. You retain the copyright on your contributions. and send GitHub pull request. You retain the copyright on your contributions.
# Looking for a pre-compiled Mongoose web server Windows or Mac binary? # Looking for a pre-compiled Mongoose web server Windows or Mac binary?
- [Download pre-compiled Mongoose web server binary.](https://www.cesanta.com/products/binary) - [Download pre-compiled Mongoose web server binary.](https://www.cesanta.com/binary.html)
[![Analytics](https://ga-beacon.appspot.com/UA-42732794-5/project-page)](https://github.com/cesanta/mongoose)
+1
View File
@@ -3,6 +3,7 @@ title: "Server API reference"
symbol_kind: "intro" symbol_kind: "intro"
decl_name: "http_server.h" decl_name: "http_server.h"
items: items:
- { name: mg_check_digest_auth.md }
- { name: mg_file_upload_handler.md } - { name: mg_file_upload_handler.md }
- { name: mg_get_http_basic_auth.md } - { name: mg_get_http_basic_auth.md }
- { name: mg_get_http_header.md } - { name: mg_get_http_header.md }
@@ -0,0 +1,17 @@
---
title: "mg_check_digest_auth()"
decl_name: "mg_check_digest_auth"
symbol_kind: "func"
signature: |
int mg_check_digest_auth(struct mg_str method, struct mg_str uri,
struct mg_str username, struct mg_str cnonce,
struct mg_str response, struct mg_str qop,
struct mg_str nc, struct mg_str nonce,
struct mg_str auth_domain, FILE *fp);
---
Authenticates given response params against an opened password file.
Returns 1 if authenticated, 0 otherwise.
It's used by mg_http_check_digest_auth().
@@ -5,6 +5,7 @@ symbol_kind: "struct"
signature: | signature: |
struct mg_mqtt_proto_data { struct mg_mqtt_proto_data {
uint16_t keep_alive; uint16_t keep_alive;
double last_control_time;
}; };
--- ---
-1
View File
@@ -11,7 +11,6 @@ items:
- { name: mg_check_ip_acl.md } - { name: mg_check_ip_acl.md }
- { name: mg_connect.md } - { name: mg_connect.md }
- { name: mg_connect_opt.md } - { name: mg_connect_opt.md }
- { name: mg_enable_javascript.md }
- { name: mg_mgr_free.md } - { name: mg_mgr_free.md }
- { name: mg_mgr_init.md } - { name: mg_mgr_init.md }
- { name: mg_mgr_init_opt.md } - { name: mg_mgr_init_opt.md }
-14
View File
@@ -1,14 +0,0 @@
---
title: "mg_enable_javascript()"
decl_name: "mg_enable_javascript"
symbol_kind: "func"
signature: |
enum v7_err mg_enable_javascript(struct mg_mgr *m, struct v7 *v7,
const char *init_js_file_name);
---
Enables server-side JavaScript scripting.
Requires a `-DMG_ENABLE_JAVASCRIPT` compilation flag and V7 engine sources.
V7 instance must not be destroyed during manager's lifetime.
Returns a V7 error.
+1 -4
View File
@@ -14,10 +14,7 @@ signature: |
void *user_data; /* User data */ void *user_data; /* User data */
int num_ifaces; int num_ifaces;
struct mg_iface **ifaces; /* network interfaces */ struct mg_iface **ifaces; /* network interfaces */
#if MG_ENABLE_JAVASCRIPT const char *nameserver; /* DNS server to use */
struct v7 *v7;
#endif
const char *nameserver; /* DNS server to use */
}; };
--- ---
+1 -2
View File
@@ -14,16 +14,15 @@ items:
- { name: mg_hexdump_connection.md } - { name: mg_hexdump_connection.md }
- { name: mg_hexdumpf.md } - { name: mg_hexdumpf.md }
- { name: mg_is_big_endian.md } - { name: mg_is_big_endian.md }
- { name: mg_match_prefix.md }
- { name: mg_mbuf_append_base64.md } - { name: mg_mbuf_append_base64.md }
- { name: mg_mbuf_append_base64_putc.md } - { name: mg_mbuf_append_base64_putc.md }
- { name: mg_next_comma_list_entry.md }
- { name: mg_open.md } - { name: mg_open.md }
- { name: mg_skip.md } - { name: mg_skip.md }
- { name: mg_sock_addr_to_str.md } - { name: mg_sock_addr_to_str.md }
- { name: mg_sock_to_str.md } - { name: mg_sock_to_str.md }
- { name: mg_start_thread.md } - { name: mg_start_thread.md }
- { name: mg_stat.md } - { name: mg_stat.md }
- { name: mg_url_encode.md }
--- ---
+4 -3
View File
@@ -3,8 +3,8 @@ title: "mg_conn_addr_to_str()"
decl_name: "mg_conn_addr_to_str" decl_name: "mg_conn_addr_to_str"
symbol_kind: "func" symbol_kind: "func"
signature: | signature: |
void mg_conn_addr_to_str(struct mg_connection *nc, char *buf, size_t len, int mg_conn_addr_to_str(struct mg_connection *c, char *buf, size_t len,
int flags); int flags);
--- ---
Converts a connection's local or remote address into string. Converts a connection's local or remote address into string.
@@ -17,5 +17,6 @@ see `MG_SOCK_STRINGIFY_*` definitions.
- MG_SOCK_STRINGIFY_REMOTE - print remote peer's IP/port, not local address - MG_SOCK_STRINGIFY_REMOTE - print remote peer's IP/port, not local address
If both port number and IP address are printed, they are separated by `:`. If both port number and IP address are printed, they are separated by `:`.
If compiled with `-DMG_ENABLE_IPV6`, IPv6 addresses are supported. If compiled with `-DMG_ENABLE_IPV6`, IPv6 addresses are supported.
Return length of the stringified address.
-14
View File
@@ -1,14 +0,0 @@
---
title: "mg_match_prefix()"
decl_name: "mg_match_prefix"
symbol_kind: "func"
signature: |
int mg_match_prefix(const char *pattern, int pattern_len, const char *str);
---
Matches 0-terminated string (mg_match_prefix) or string with given length
mg_match_prefix_n against a glob pattern.
Match is case-insensitive. Returns number of bytes matched, or -1 if no
match.
@@ -1,21 +0,0 @@
---
title: "mg_next_comma_list_entry()"
decl_name: "mg_next_comma_list_entry"
symbol_kind: "func"
signature: |
const char *mg_next_comma_list_entry(const char *list, struct mg_str *val,
struct mg_str *eq_val);
---
A helper function for traversing a comma separated list of values.
It returns a list pointer shifted to the next value or NULL if the end
of the list found.
The value is stored in a val vector. If the value has a form "x=y", then
eq_val vector is initialised to point to the "y" part, and val vector length
is adjusted to point only to "x".
If the list is just a comma separated list of entries, like "aa,bb,cc" then
`eq_val` will contain zero-length string.
The purpose of this function is to parse comma separated string without
any copying/memory allocation.
+2 -2
View File
@@ -3,8 +3,8 @@ title: "mg_sock_addr_to_str()"
decl_name: "mg_sock_addr_to_str" decl_name: "mg_sock_addr_to_str"
symbol_kind: "func" symbol_kind: "func"
signature: | signature: |
void mg_sock_addr_to_str(const union socket_address *sa, char *buf, size_t len, int mg_sock_addr_to_str(const union socket_address *sa, char *buf, size_t len,
int flags); int flags);
--- ---
Convert the socket's address into string. Convert the socket's address into string.
+13
View File
@@ -0,0 +1,13 @@
---
title: "mg_url_encode()"
decl_name: "mg_url_encode"
symbol_kind: "func"
signature: |
struct mg_str mg_url_encode(const struct mg_str src);
---
URL-escape the specified string.
All non-printable characters are escaped, plus `._-$,;~()/`.
Input need not be NUL-terminated, but the returned string is.
Returned string is heap-allocated and must be free()'d.
File renamed without changes.
-7
View File
@@ -1,7 +0,0 @@
---
title: CoAP
items:
- { name: server_example.md }
- { name: client_example.md }
- { name: ../c-api/coap.h/ }
---
File renamed without changes.
-7
View File
@@ -1,7 +0,0 @@
---
title: DNS client example
---
See https://github.com/cesanta/mongoose/blob/master/mongoose.c and search
for the `mg_resolve_async_eh()` function - that is the core of
built-in Mongoose async DNS resolver.
@@ -1,6 +1,7 @@
--- # Examples
title: DNS server example
---
## DNS server example
To create a DNS server, follow this pattern: To create a DNS server, follow this pattern:
@@ -71,3 +72,10 @@ int main(int argc, char *argv[]) {
``` ```
See full [Captive DNS server example](https://github.com/cesanta/mongoose/tree/master/examples/captive_dns_server). See full [Captive DNS server example](https://github.com/cesanta/mongoose/tree/master/examples/captive_dns_server).
## DNS client example
See https://github.com/cesanta/mongoose/blob/master/mongoose.c and search
for the `mg_resolve_async_eh()` function - that is the core of
built-in Mongoose async DNS resolver.
-8
View File
@@ -1,8 +0,0 @@
---
title: DNS
items:
- { name: server_example.md }
- { name: client_example.md }
- { name: ../c-api/dns.h/ }
- { name: ../c-api/dns_server.h/ }
---
+3 -5
View File
@@ -1,6 +1,4 @@
--- # CGI
title: CGI
---
[CGI](https://en.wikipedia.org/wiki/Common_Gateway_Interface) [CGI](https://en.wikipedia.org/wiki/Common_Gateway_Interface)
is a simple mechanism to generate dynamic content. is a simple mechanism to generate dynamic content.
@@ -16,7 +14,7 @@ CGI file must be executable. Mongoose honours the shebang line - see
http://en.wikipedia.org/wiki/Shebang_(Unix). http://en.wikipedia.org/wiki/Shebang_(Unix).
For example, if both PHP and Perl CGIs are used, then For example, if both PHP and Perl CGIs are used, then
``#!/path/to/php-cgi.exe` and ``#!/path/to/perl.exe` must be the first lines `#!/path/to/php-cgi.exe` and `#!/path/to/perl.exe` must be the first lines
of the respective CGI scripts. of the respective CGI scripts.
It is possible to hardcode the path to the CGI interpreter for all It is possible to hardcode the path to the CGI interpreter for all
@@ -32,4 +30,4 @@ Example:
NOTE: In the CGI handler we don't use explicitly a system call waitpid() for NOTE: In the CGI handler we don't use explicitly a system call waitpid() for
reaping zombie processes. Instead, we set the SIGCHLD handler to SIG_IGN. reaping zombie processes. Instead, we set the SIGCHLD handler to SIG_IGN.
It will cause zombie processes to be reaped automatically. It will cause zombie processes to be reaped automatically.
CAUTION: not all OSes (e.g. QNX) reap zombies if SIGCHLD is ignored. CAUTION: not all OSes (e.g. QNX) reap zombies if SIGCHLD is ignored.
@@ -1,6 +1,4 @@
--- # HTTP client example
title: HTTP client example
---
To create an HTTP client, follow this pattern: To create an HTTP client, follow this pattern:
@@ -1,6 +1,4 @@
--- # Digest Authentication
title: Digest Authentication
---
Mongoose has a built-in Digest (MD5) authentication support. In order to Mongoose has a built-in Digest (MD5) authentication support. In order to
enable Digest authentication, create a file `.htpasswd` in the directory enable Digest authentication, create a file `.htpasswd` in the directory
@@ -8,7 +6,7 @@ you would like to protect. That file should be in the format that Apache's
`htdigest` utility. `htdigest` utility.
You can use either Apache `htdigest` utility, or You can use either Apache `htdigest` utility, or
Mongoose pre-build binary (https://www.cesanta.com/products/binary) Mongoose pre-build binary at https://www.cesanta.com/binary.html
to add new users into that file: to add new users into that file:
``` ```
+1 -3
View File
@@ -1,6 +1,4 @@
--- #: HTTP events
title: HTTP events
---
As discussed in the overview, `mg_set_protocol_http_websocket()` function As discussed in the overview, `mg_set_protocol_http_websocket()` function
parses incoming data, treats it as HTTP or WebSocket, and triggers high-level parses incoming data, treats it as HTTP or WebSocket, and triggers high-level
+1 -3
View File
@@ -1,6 +1,4 @@
--- # Serving files
title: Serving files
---
API function `mg_serve_http()` makes it easy to serve files from a filesystem. API function `mg_serve_http()` makes it easy to serve files from a filesystem.
Generally speaking, that function is an implementation of the HTTP server Generally speaking, that function is an implementation of the HTTP server
-16
View File
@@ -1,16 +0,0 @@
---
title: HTTP
items:
- { name: server_example.md }
- { name: client_example.md }
- { name: events.md }
- { name: files.md }
- { name: cgi.md }
- { name: ssi.md }
- { name: upload.md }
- { name: ssl.md }
- { name: digest_auth.md }
- { name: ../c-api/http.h/ }
- { name: ../c-api/http_server.h/ }
- { name: ../c-api/http_client.h/ }
---
@@ -1,6 +1,4 @@
--- # HTTP server example
title: HTTP server example
---
To create an HTTP server, follow this pattern: To create an HTTP server, follow this pattern:
+1 -3
View File
@@ -1,6 +1,4 @@
--- # SSI
title: SSI
---
Server Side Includes (SSI) is a simple interpreted server-side scripting Server Side Includes (SSI) is a simple interpreted server-side scripting
language which is most commonly used to include the contents of a file language which is most commonly used to include the contents of a file
+2 -4
View File
@@ -1,6 +1,4 @@
--- # Enabling SSL (HTTPS)
title: Enabling HTTPS
---
To enable SSL on the server side, please follow these steps: To enable SSL on the server side, please follow these steps:
@@ -30,4 +28,4 @@ int main(void) {
} }
``` ```
For the full example, please see the [Simplest HTTPS server example](https://github.com/cesanta/dev/tree/master/mongoose/examples/simplest_web_server_ssl). For the full example, please see the [Simplest HTTPS server example](https://github.com/cesanta/mongoose/tree/master/examples/simplest_web_server_ssl).
+5 -7
View File
@@ -1,14 +1,12 @@
--- # Handling file uploads
title: Handling file uploads
---
In order to handle file uploads, use the following HTML snippet: In order to handle file uploads, use the following HTML snippet:
```HTML ```HTML
&lt;form method="POST" action="/upload" enctype="multipart/form-data"&gt; <form method="POST" action="/upload" enctype="multipart/form-data">
&lt;input type="file" name="file"&gt; <input type="file" name="file">
&lt;input type="submit" value="Upload"&gt; <input type="submit" value="Upload">
&lt;/form&gt; </form>
``` ```
Uploaded files will be sent to the `/upload` endpoint via the `POST` request. Uploaded files will be sent to the `/upload` endpoint via the `POST` request.
-5
View File
@@ -1,5 +0,0 @@
---
title: MQTT client example
---
See https://github.com/cesanta/mongoose/tree/master/examples/mqtt_client
+5
View File
@@ -0,0 +1,5 @@
# Examples
- [Client example](https://github.com/cesanta/mongoose/tree/master/examples/mqtt_client)
- [Server example](https://github.com/cesanta/mongoose/tree/master/examples/mqtt_broker)
-8
View File
@@ -1,8 +0,0 @@
---
title: MQTT
items:
- { name: server_example.md }
- { name: client_example.md }
- { name: ../c-api/mqtt.h/ }
- { name: ../c-api/mqtt_server.h/ }
---
-5
View File
@@ -1,5 +0,0 @@
---
title: MQTT server example
---
See https://github.com/cesanta/mongoose/tree/master/examples/mqtt_broker
+59
View File
@@ -0,0 +1,59 @@
# Build options
Mongoose source code ships in a single .c file that contains functionality
for all supported protocols (modules). Modules can be disabled at compile
time which reduces the executable's size. That can be done by setting preprocessor
flags. Also, some preprocessor flags can be used to tune internal Mongoose
parameters.
To set a preprocessor flag during compile time, use the `-D <PREPROCESSOR_FLAG>`
compiler option. For example, to disable both MQTT and CoAP,
compile the application `my_app.c` like this (assumed UNIX system):
```
$ cc my_app.c mongoose.c -D MG_DISABLE_MQTT -D MG_DISABLE_COAP
```
## Enabling flags
- `MG_ENABLE_SSL` Enable [SSL/TLS support](https://docs.cesanta.com/mongoose/master/#/http/ssl.md/) (OpenSSL API)
- `MG_ENABLE_IPV6` Enable IPv6 support
- `MG_ENABLE_MQTT` enable [MQTT client](https://docs.cesanta.com/mongoose/master/#/mqtt/client_example.md/) (on by default, set to 0 to disable)
- `MG_ENABLE_MQTT_BROKER` enable [MQTT broker](https://docs.cesanta.com/mongoose/master/#/mqtt/server_example.md/)
- `MG_ENABLE_DNS_SERVER` enable DNS server
- `MG_ENABLE_COAP` enable CoAP protocol
- `MG_ENABLE_HTTP` Enable HTTP protocol support (on by default, set to 0 to disable)
- `MG_ENABLE_HTTP_CGI` Enable [CGI](https://docs.cesanta.com/mongoose/master/#/http/cgi.md/) support
- `MG_ENABLE_HTTP_SSI` Enable [Server Side Includes](https://docs.cesanta.com/mongoose/master/#/http/ssi.md/) support
- `MG_ENABLE_HTTP_SSI_EXEC` Enable SSI `exec` operator
- `MG_ENABLE_HTTP_WEBDAV` enable WebDAV extensions to HTTP
- `MG_ENABLE_HTTP_WEBSOCKET` enable WebSocket extension to HTTP (on by default, =0 to disable)
- `MG_ENABLE_BROADCAST` enable `mg_broadcast()` API
- `MG_ENABLE_GETADDRINFO` enable `getaddrinfo()` in `mg_resolve2()`
- `MG_ENABLE_THREADS` enable `mg_start_thread()` API
## Disabling flags
- `MG_DISABLE_HTTP_DIGEST_AUTH` disable HTTP Digest (MD5) authorisation support
- `CS_DISABLE_SHA1` disable SHA1 support (used by WebSocket)
- `CS_DISABLE_MD5` disable MD5 support (used by HTTP auth)
- `MG_DISABLE_HTTP_KEEP_ALIVE` useful for embedded systems to save resources
## Platform specific
Mongoose tries to detect the target platform whenever possible, but in some cases you have
to explicitly declare some peculiarities of your target, such as:
- `MG_CC3200`: enable workarounds for the TI CC3200 target.
- `MG_ESP8266`: enable workarounds for the ESP8266 target, add `RTOS_SDK` to specify the RTOS SDK flavour.
## Tunables
- `MG_MALLOC`, `MG_CALLOC`, `MG_REALLOC`, `MG_FREE` allow you to a use custom
memory allocator, e.g. `-DMG_MALLOC=my_malloc`
- `MG_USE_READ_WRITE` when set replaces calls to `recv` with `read` and `send` with `write`,
thus enabling to add any kind of file descriptor (files, serial devices) to an event manager.
- `MG_SSL_CRYPTO_MODERN`, `MG_SSL_CRYPTO_OLD` - choose either "Modern" or "Old" ciphers
instead of the default "Intermediate" setting.
See [this article](https://wiki.mozilla.org/Security/Server_Side_TLS#Recommended_configurations) for details.
- `MG_USER_FILE_FUNCTIONS` allow you to use custom file operation, by defining you own `mg_stat`, `mg_fopen`, `mg_open`, `mg_fread` and `mg_fwrite` functions
@@ -1,8 +0,0 @@
---
title: Disabling flags
---
- `MG_DISABLE_HTTP_DIGEST_AUTH` disable HTTP Digest (MD5) authorisation support
- `CS_DISABLE_SHA1` disable SHA1 support (used by WebSocket)
- `CS_DISABLE_MD5` disable MD5 support (used by HTTP auth)
- `MG_DISABLE_HTTP_KEEP_ALIVE` useful for embedded systems to save resources
@@ -1,19 +0,0 @@
---
title: Enabling flags
---
- `MG_ENABLE_SSL` Enable [SSL/TLS support](https://docs.cesanta.com/mongoose/master/#/http/ssl.md/) (OpenSSL API)
- `MG_ENABLE_IPV6` Enable IPv6 support
- `MG_ENABLE_MQTT` enable [MQTT client](https://docs.cesanta.com/mongoose/master/#/mqtt/client_example.md/) (on by default, set to 0 to disable)
- `MG_ENABLE_MQTT_BROKER` enable [MQTT broker](https://docs.cesanta.com/mongoose/master/#/mqtt/server_example.md/)
- `MG_ENABLE_DNS_SERVER` enable DNS server
- `MG_ENABLE_COAP` enable CoAP protocol
- `MG_ENABLE_HTTP` Enable HTTP protocol support (on by default, set to 0 to disable)
- `MG_ENABLE_HTTP_CGI` Enable [CGI](https://docs.cesanta.com/mongoose/master/#/http/cgi.md/) support
- `MG_ENABLE_HTTP_SSI` Enable [Server Side Includes](https://docs.cesanta.com/mongoose/master/#/http/ssi.md/) support
- `MG_ENABLE_HTTP_SSI_EXEC` Enable SSI `exec` operator
- `MG_ENABLE_HTTP_WEBDAV` enable WebDAV extensions to HTTP
- `MG_ENABLE_HTTP_WEBSOCKET` enable WebSocket extension to HTTP (on by default, =0 to disable)
- `MG_ENABLE_BROADCAST` enable `mg_broadcast()` API
- `MG_ENABLE_GETADDRINFO` enable `getaddrinfo()` in `mg_resolve2()`
- `MG_ENABLE_THREADS` enable `mg_start_thread()` API
-22
View File
@@ -1,22 +0,0 @@
---
title: Build Options
items:
- { type: file, name: enabling-flags.md }
- { type: file, name: disabling-flags.md }
- { type: file, name: platform-spec.md }
- { type: file, name: tunables.md }
---
Mongoose source code ships in a single .c file that contains functionality
for all supported protocols (modules). Modules can be disabled at compile
time which reduces the executable's size. That can be done by setting preprocessor
flags. Also, some preprocessor flags can be used to tune internal Mongoose
parameters.
To set a preprocessor flag during compile time, use the `-D <PREPROCESSOR_FLAG>`
compiler option. For example, to disable both MQTT and CoAP,
compile the application `my_app.c` like this (assumed UNIX system):
```
$ cc my_app.c mongoose.c -D MG_DISABLE_MQTT -D MG_DISABLE_COAP
```
@@ -1,9 +0,0 @@
---
title: Platform specific
---
Mongoose tries to detect the target platform whenever possible, but in some cases you have
to explicitly declare some peculiarities of your target, such as:
- `MG_CC3200`: enable workarounds for the TI CC3200 target.
- `MG_ESP8266`: enable workarounds for the ESP8266 target, add `RTOS_SDK` to specify the RTOS SDK flavour.
-12
View File
@@ -1,12 +0,0 @@
---
title: Tunables
---
- `MG_MALLOC`, `MG_CALLOC`, `MG_REALLOC`, `MG_FREE` allow you to a use custom
memory allocator, e.g. `-DMG_MALLOC=my_malloc`
- `MG_USE_READ_WRITE` when set replaces calls to `recv` with `read` and `send` with `write`,
thus enabling to add any kind of file descriptor (files, serial devices) to an event manager.
- `MG_SSL_CRYPTO_MODERN`, `MG_SSL_CRYPTO_OLD` - choose either "Modern" or "Old" ciphers
instead of the default "Intermediate" setting.
See [this article](https://wiki.mozilla.org/Security/Server_Side_TLS#Recommended_configurations) for details.
- `MG_USER_FILE_FUNCTIONS` allow you to use custom file operation, by defining you own `mg_stat`, `mg_fopen`, `mg_open`, `mg_fread` and `mg_fwrite` functions
+1 -3
View File
@@ -1,6 +1,4 @@
--- # Design Concept
title: Design Concept
---
Mongoose has three basic data structures: Mongoose has three basic data structures:
+1 -3
View File
@@ -1,6 +1,4 @@
--- # Connection flags
title: Connection flags
---
Each connection has a `flags` bit field. Some flags are set by Mongoose, for Each connection has a `flags` bit field. Some flags are set by Mongoose, for
example if a user creates an outbound UDP connection using a `udp://1.2.3.4:5678` example if a user creates an outbound UDP connection using a `udp://1.2.3.4:5678`
+1 -3
View File
@@ -1,6 +1,4 @@
--- # Event handler function
title: Event handler function
---
Each connection has an event handler function associated with it. That function Each connection has an event handler function associated with it. That function
must be implemented by the user. Event handler is the key element of the Mongoose must be implemented by the user. Event handler is the key element of the Mongoose
+1 -3
View File
@@ -1,6 +1,4 @@
--- # Events
title: Events
---
Mongoose accepts incoming connections, reads and writes data and calls Mongoose accepts incoming connections, reads and writes data and calls
specified event handlers for each connection when appropriate. A typical event specified event handlers for each connection when appropriate. A typical event
+1 -12
View File
@@ -1,15 +1,4 @@
--- # Introduction
title: Overview
items:
# - { name: usage-example.md }
- { name: concept.md }
- { name: mbufs.md }
- { name: event-handler.md }
- { name: events.md }
- { name: conn-flags.md }
- { name: build-options }
- { name: usage-example.md }
---
Mongoose is a networking library written in C. Mongoose is a networking library written in C.
It is a swiss army knife for embedded network programming. It is a swiss army knife for embedded network programming.
+2 -4
View File
@@ -1,6 +1,4 @@
--- # Memory buffers
title: Memory buffers
---
Each connection has a send and receive buffer, `struct mg_connection::send_mbuf` Each connection has a send and receive buffer, `struct mg_connection::send_mbuf`
and `struct mg_connection::recv_mbuf` respectively. When data arrives, and `struct mg_connection::recv_mbuf` respectively. When data arrives,
@@ -11,4 +9,4 @@ When Mongoose successfully writes data to the socket, it discards data from
`struct mg_connection::send_mbuf` and sends an `MG_EV_SEND` event. When the connection `struct mg_connection::send_mbuf` and sends an `MG_EV_SEND` event. When the connection
is closed, an `MG_EV_CLOSE` event is sent. is closed, an `MG_EV_CLOSE` event is sent.
![](media/mbuf.png) ![](/docs/media/mbuf.png)
+1 -3
View File
@@ -1,6 +1,4 @@
--- # Example - TCP echo server
title: Example - TCP echo server
---
- Copy `mongoose.c` and `mongoose.h` to your build tree - Copy `mongoose.c` and `mongoose.h` to your build tree
- Write code that uses the Mongoose API, e.g. in `my_app.c` - Write code that uses the Mongoose API, e.g. in `my_app.c`
+5 -5
View File
@@ -22,7 +22,7 @@ IPATH = . ../.. $(REPO_PATH)
VPATH = ../.. VPATH = ../..
MONGOOSE_FEATURES = -DMG_ENABLE_SSL -DMG_ENABLE_HTTP_STREAMING_MULTIPART MONGOOSE_FEATURES = -DMG_ENABLE_SSL -DMG_ENABLE_HTTP_STREAMING_MULTIPART -DMG_MODULE_LINES
SDK_FLAGS = -DUSE_FREERTOS -DSL_PLATFORM_MULTI_THREADED SDK_FLAGS = -DUSE_FREERTOS -DSL_PLATFORM_MULTI_THREADED
# -DTARGET_IS_CC3200 would reduce code size by using functions in ROM # -DTARGET_IS_CC3200 would reduce code size by using functions in ROM
@@ -58,11 +58,11 @@ $(FW_DIR):
$(FW_ZIP): $(FW_ELF) $(FW_BIN) $(SLFS_FILES) $(FW_ZIP): $(FW_ELF) $(FW_BIN) $(SLFS_FILES)
@echo " Code size: $(shell ls -l $(FW_BIN) | awk '{print $$5}')" @echo " Code size: $(shell ls -l $(FW_BIN) | awk '{print $$5}')"
@echo " GEN $(FW_MANIFEST)" @echo " GEN $(FW_MANIFEST)"
@fw_meta gen_build_info \ @fw_meta.py gen_build_info \
--json_output=$(BUILD_INFO_JSON) --json_output=$(BUILD_INFO_JSON)
@cp -v $(SLFS_FILES) out/ @cp -v $(SLFS_FILES) out/
@cp $(CC3200_SP_FILE)* $(FW_DIR) @cp $(CC3200_SP_FILE)* $(FW_DIR)
@fw_meta create_manifest \ @fw_meta.py create_manifest \
--name=$(PROG) --platform=$(PLATFORM) \ --name=$(PROG) --platform=$(PLATFORM) \
--build_info=$(BUILD_INFO_JSON) \ --build_info=$(BUILD_INFO_JSON) \
--output=$(FW_MANIFEST) \ --output=$(FW_MANIFEST) \
@@ -72,14 +72,14 @@ $(FW_ZIP): $(FW_ELF) $(FW_BIN) $(SLFS_FILES)
/sys/mcuimg.bin:type=app,src=$(notdir $(FW_BIN)) \ /sys/mcuimg.bin:type=app,src=$(notdir $(FW_BIN)) \
$(foreach f,$(SLFS_FILES), $(notdir $(f)):type=slfile,src=$(notdir $(f))) $(foreach f,$(SLFS_FILES), $(notdir $(f)):type=slfile,src=$(notdir $(f)))
@echo " ZIP $@" @echo " ZIP $@"
@fw_meta create_fw \ @fw_meta.py create_fw \
--manifest=$(FW_MANIFEST) \ --manifest=$(FW_MANIFEST) \
--src_dir=$(FW_DIR) \ --src_dir=$(FW_DIR) \
--output=$@ --output=$@
FREERTOS_SRCS = timers.c list.c queue.c tasks.c port.c heap_3.c osi_freertos.c FREERTOS_SRCS = timers.c list.c queue.c tasks.c port.c heap_3.c osi_freertos.c
DRIVER_SRCS = cpu.c gpio.c gpio_if.c i2c.c i2c_if.c interrupt.c pin.c prcm.c spi.c uart.c udma.c utils.c DRIVER_SRCS = cpu.c gpio.c gpio_if.c i2c.c i2c_if.c interrupt.c pin.c prcm.c spi.c uart.c udma.c utils.c
SL_SRCS = socket.c wlan.c driver.c device.c netapp.c netcfg.c network_common.c cc_pal.c fs.c SL_SRCS = socket.c wlan.c driver.c device.c netapp.c netcfg.c network_common.c timer.c cc_pal.c fs.c
SDK_SRCS = startup_gcc.c $(FREERTOS_SRCS) $(DRIVER_SRCS) $(SL_SRCS) SDK_SRCS = startup_gcc.c $(FREERTOS_SRCS) $(DRIVER_SRCS) $(SL_SRCS)
IPATH += $(SDK_PATH) $(SDK_PATH)/inc $(SDK_PATH)/driverlib \ IPATH += $(SDK_PATH) $(SDK_PATH)/inc $(SDK_PATH)/driverlib \
$(SDK_PATH)/example/common $(SDK_PATH)/oslib \ $(SDK_PATH)/example/common $(SDK_PATH)/oslib \
+13
View File
@@ -294,3 +294,16 @@ void SimpleLinkGeneralEventHandler(SlDeviceEvent_t *e) {
LOG(LL_ERROR, ("status %d sender %d", e->EventData.deviceEvent.status, LOG(LL_ERROR, ("status %d sender %d", e->EventData.deviceEvent.status,
e->EventData.deviceEvent.sender)); e->EventData.deviceEvent.sender));
} }
#ifndef __TI_COMPILER_VERSION__
int _gettimeofday_r(struct _reent *r, struct timeval *tp, void *tz) {
#else
int gettimeofday(struct timeval *tp, void *tz) {
#endif
unsigned long sec;
unsigned short msec;
MAP_PRCMRTCGet(&sec, &msec);
tp->tv_sec = sec;
tp->tv_usec = ((unsigned long) msec) * 1000;
return 0;
}
+1 -1
View File
@@ -1 +1 @@
docker.cesanta.com/cc3200-build:1.2.0-r8 docker.cesanta.com/cc3200-build:1.3.0-r2
+3 -3
View File
@@ -21,9 +21,9 @@ ifeq ($(SSL_LIB),mbedtls)
CFLAGS += -DMG_ENABLE_SSL -DMG_SSL_IF=MG_SSL_IF_MBEDTLS -DMG_SSL_MBED_DUMMY_RANDOM -lmbedcrypto -lmbedtls -lmbedx509 CFLAGS += -DMG_ENABLE_SSL -DMG_SSL_IF=MG_SSL_IF_MBEDTLS -DMG_SSL_MBED_DUMMY_RANDOM -lmbedcrypto -lmbedtls -lmbedx509
endif endif
ifeq ($(JS), yes) ifdef ASAN
V7_PATH = ../../deps/v7 CC = clang
CFLAGS_EXTRA += -DMG_ENABLE_JAVASCRIPT -I $(V7_PATH) $(V7_PATH)/v7.c CFLAGS += -fsanitize=address
endif endif
$(PROG): $(SOURCES) $(PROG): $(SOURCES)
+1 -1
View File
@@ -1,4 +1,4 @@
PROG = mqtt_broker PROG = mqtt_broker
MODULE_CFLAGS = -DMG_ENABLE_MQTT_BROKER -DMG_ENABLE_HTTP=0 MODULE_CFLAGS = -DMG_ENABLE_MQTT_BROKER -DMG_ENABLE_HTTP=0
SSL_LIB=openssl #SSL_LIB=openssl
include ../examples.mk include ../examples.mk
+15 -6
View File
@@ -17,22 +17,31 @@
#include "../../mongoose.h" #include "../../mongoose.h"
static const char *s_listening_address = "0.0.0.0:1883";
static void ev_handler(struct mg_connection *c, int ev, void *ev_data) {
if (ev != MG_EV_POLL) printf("USER HANDLER GOT EVENT %d\n", ev);
/* Do your custom event processing here */
mg_mqtt_broker(c, ev, ev_data);
}
int main(void) { int main(void) {
struct mg_mgr mgr; struct mg_mgr mgr;
const char *address = "0.0.0.0:1883"; struct mg_connection *c;
struct mg_connection *nc;
struct mg_mqtt_broker brk; struct mg_mqtt_broker brk;
mg_mgr_init(&mgr, NULL); mg_mgr_init(&mgr, NULL);
mg_mqtt_broker_init(&brk, NULL); mg_mqtt_broker_init(&brk, NULL);
if ((nc = mg_bind(&mgr, address, mg_mqtt_broker)) == NULL) { if ((c = mg_bind(&mgr, s_listening_address, ev_handler)) == NULL) {
fprintf(stderr, "mg_bind(%s) failed\n", address); fprintf(stderr, "mg_bind(%s) failed\n", s_listening_address);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
nc->user_data = &brk; mg_mqtt_broker_init(&brk, NULL);
c->user_data = &brk;
mg_set_protocol_mqtt(c);
printf("MQTT broker started on %s\n", address); printf("MQTT broker started on %s\n", s_listening_address);
/* /*
* TODO: Add a HTTP status page that shows current sessions * TODO: Add a HTTP status page that shows current sessions
+1 -4
View File
@@ -27,10 +27,7 @@ static void ev_handler(struct mg_connection *nc, int ev, void *p) {
struct mg_mqtt_message *msg = (struct mg_mqtt_message *) p; struct mg_mqtt_message *msg = (struct mg_mqtt_message *) p;
(void) nc; (void) nc;
#if 0 if (ev != MG_EV_POLL) printf("USER HANDLER GOT EVENT %d\n", ev);
if (ev != MG_EV_POLL)
printf("USER HANDLER GOT %d\n", ev);
#endif
switch (ev) { switch (ev) {
case MG_EV_CONNECT: { case MG_EV_CONNECT: {
@@ -0,0 +1,4 @@
PROG = mqtt_over_websocket_server
MODULE_CFLAGS = -DMG_ENABLE_MQTT_BROKER=1
#SSL_LIB=mbedtls
include ../examples.mk
@@ -0,0 +1,124 @@
/*
* 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 <https://www.cesanta.com/license>.
*/
#include "mongoose.h"
static const char *s_mqtt_address = "0.0.0.0:1883";
static const char *s_http_address = "0.0.0.0:8080";
static void unproxy(struct mg_connection *c) {
struct mg_connection *pc = (struct mg_connection *) c->user_data;
if (pc != NULL) {
pc->flags |= MG_F_CLOSE_IMMEDIATELY;
pc->user_data = NULL;
c->user_data = NULL;
}
printf("Closing connection %p\n", c);
}
static void proxy_handler(struct mg_connection *c, int ev, void *ev_data) {
if (ev == MG_EV_POLL) return;
printf("%p %s EVENT %d %p\n", c, __func__, ev, ev_data);
switch (ev) {
case MG_EV_CLOSE: {
unproxy(c);
break;
}
case MG_EV_RECV: {
struct mg_connection *pc = (struct mg_connection *) c->user_data;
if (pc != NULL) {
mg_send_websocket_frame(pc, WEBSOCKET_OP_BINARY, c->recv_mbuf.buf,
c->recv_mbuf.len);
mbuf_remove(&c->recv_mbuf, c->recv_mbuf.len);
}
break;
}
}
}
static void http_handler(struct mg_connection *c, int ev, void *ev_data) {
struct mg_connection *pc = (struct mg_connection *) c->user_data;
if (ev == MG_EV_POLL) return;
printf("%p %s EVENT %d %p\n", c, __func__, ev, ev_data);
/* Do your custom event processing here */
switch (ev) {
case MG_EV_WEBSOCKET_HANDSHAKE_DONE: {
pc = mg_connect(c->mgr, s_mqtt_address, proxy_handler);
pc->user_data = c;
c->user_data = pc;
printf("Created proxy connection %p\n", pc);
break;
}
case MG_EV_WEBSOCKET_FRAME: {
struct websocket_message *wm = (struct websocket_message *) ev_data;
if (pc != NULL) {
printf("Forwarding %d bytes\n", (int) wm->size);
mg_send(pc, wm->data, wm->size);
}
break;
}
case MG_EV_CLOSE: {
unproxy(c);
break;
}
}
}
static void mqtt_handler(struct mg_connection *c, int ev, void *ev_data) {
if (ev == MG_EV_POLL) return;
printf("%p %s EVENT %d %p\n", c, __func__, ev, ev_data);
/* Do your custom event processing here */
switch (ev) {
case MG_EV_CLOSE:
printf("Closing MQTT connection %p\n", c);
break;
}
mg_mqtt_broker(c, ev, ev_data);
}
static void start_mqtt_server(struct mg_mgr *mgr, const char *addr) {
struct mg_connection *c;
static struct mg_mqtt_broker brk; // static is important - must not perish
if ((c = mg_bind(mgr, addr, mqtt_handler)) == NULL) {
fprintf(stderr, "Cannot start MQTT server on port [%s]\n", addr);
exit(EXIT_FAILURE);
}
mg_mqtt_broker_init(&brk, NULL);
c->user_data = &brk;
mg_set_protocol_mqtt(c);
printf("MQTT server started on %s\n", addr);
}
static void start_http_server(struct mg_mgr *mgr, const char *addr) {
struct mg_connection *c;
if ((c = mg_bind(mgr, addr, http_handler)) == NULL) {
fprintf(stderr, "Cannot start HTTP server on port [%s]\n", addr);
exit(EXIT_FAILURE);
}
mg_set_protocol_http_websocket(c);
printf("HTTP server started on %s\n", addr);
}
int main(void) {
struct mg_mgr mgr;
mg_mgr_init(&mgr, NULL);
start_http_server(&mgr, s_http_address);
start_mqtt_server(&mgr, s_mqtt_address);
for (;;) {
mg_mgr_poll(&mgr, 1000);
}
}
-5
View File
@@ -75,11 +75,6 @@ int main(int argc, char *argv[]) {
s_http_port = argv[++i]; s_http_port = argv[++i];
} else if (strcmp(argv[i], "-a") == 0 && i + 1 < argc) { } else if (strcmp(argv[i], "-a") == 0 && i + 1 < argc) {
s_http_server_opts.auth_domain = argv[++i]; s_http_server_opts.auth_domain = argv[++i];
#if MG_ENABLE_JAVASCRIPT
} else if (strcmp(argv[i], "-j") == 0 && i + 1 < argc) {
const char *init_file = argv[++i];
mg_enable_javascript(&mgr, v7_create(), init_file);
#endif
} else if (strcmp(argv[i], "-P") == 0 && i + 1 < argc) { } else if (strcmp(argv[i], "-P") == 0 && i + 1 < argc) {
s_http_server_opts.global_auth_file = argv[++i]; s_http_server_opts.global_auth_file = argv[++i];
} else if (strcmp(argv[i], "-A") == 0 && i + 1 < argc) { } else if (strcmp(argv[i], "-A") == 0 && i + 1 < argc) {
+5
View File
@@ -0,0 +1,5 @@
PROG = socks_server
# NOTE(lsm): -DMG_ENABLE_IPV6 won't work for the mingw build
MODULE_CFLAGS = -DMG_ENABLE_SOCKS=1 # -DMG_ENABLE_DEBUG=1
#SSL_LIB=openssl
include ../examples.mk
+32
View File
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2017 Cesanta Software Limited
* All rights reserved
*
* Use curl to test, e.g.
* curl -i --socks5 127.0.0.1:1080 www.met.ie
*/
#include "mongoose.h"
static const char *s_listening_addr = "1080";
int main(void) {
struct mg_mgr mgr;
struct mg_connection *c;
mg_mgr_init(&mgr, NULL);
if ((c = mg_bind(&mgr, s_listening_addr, NULL)) == NULL) {
fprintf(stderr, "mg_bind(%s) failed\n", s_listening_addr);
exit(EXIT_FAILURE);
}
mg_set_protocol_socks(c);
printf("Starting socks5 proxy server on %s\n", s_listening_addr);
for (;;) {
mg_mgr_poll(&mgr, 1000);
}
mg_mgr_free(&mgr);
return 0;
}
+1217 -514
View File
File diff suppressed because it is too large. Load diff
+268 -108
View File
@@ -23,7 +23,7 @@
#ifndef CS_MONGOOSE_SRC_COMMON_H_ #ifndef CS_MONGOOSE_SRC_COMMON_H_
#define CS_MONGOOSE_SRC_COMMON_H_ #define CS_MONGOOSE_SRC_COMMON_H_
#define MG_VERSION "6.7" #define MG_VERSION "6.10"
/* Local tweaks, applied before any of Mongoose's own headers. */ /* Local tweaks, applied before any of Mongoose's own headers. */
#ifdef MG_LOCALS #ifdef MG_LOCALS
@@ -46,9 +46,10 @@
#define CS_P_WINDOWS 2 #define CS_P_WINDOWS 2
#define CS_P_ESP32 15 #define CS_P_ESP32 15
#define CS_P_ESP8266 3 #define CS_P_ESP8266 3
#define CS_P_CC3200 4
#define CS_P_MSP432 5
#define CS_P_CC3100 6 #define CS_P_CC3100 6
#define CS_P_CC3200 4
#define CS_P_CC3220 17
#define CS_P_MSP432 5
#define CS_P_TM4C129 14 #define CS_P_TM4C129 14
#define CS_P_MBED 7 #define CS_P_MBED 7
#define CS_P_WINCE 8 #define CS_P_WINCE 8
@@ -58,15 +59,17 @@
#define CS_P_NRF52 10 #define CS_P_NRF52 10
#define CS_P_PIC32 11 #define CS_P_PIC32 11
#define CS_P_STM32 16 #define CS_P_STM32 16
/* Next id: 17 */ /* Next id: 18 */
/* If not specified explicitly, we guess platform by defines. */ /* If not specified explicitly, we guess platform by defines. */
#ifndef CS_PLATFORM #ifndef CS_PLATFORM
#if defined(TARGET_IS_MSP432P4XX) || defined(__MSP432P401R__) #if defined(TARGET_IS_MSP432P4XX) || defined(__MSP432P401R__)
#define CS_PLATFORM CS_P_MSP432 #define CS_PLATFORM CS_P_MSP432
#elif defined(cc3200) #elif defined(cc3200) || defined(TARGET_IS_CC3200)
#define CS_PLATFORM CS_P_CC3200 #define CS_PLATFORM CS_P_CC3200
#elif defined(cc3220) || defined(TARGET_IS_CC3220)
#define CS_PLATFORM CS_P_CC3220
#elif defined(__unix__) || defined(__APPLE__) #elif defined(__unix__) || defined(__APPLE__)
#define CS_PLATFORM CS_P_UNIX #define CS_PLATFORM CS_P_UNIX
#elif defined(WINCE) #elif defined(WINCE)
@@ -111,8 +114,9 @@
/* Amalgamated: #include "common/platforms/platform_windows.h" */ /* Amalgamated: #include "common/platforms/platform_windows.h" */
/* Amalgamated: #include "common/platforms/platform_esp32.h" */ /* Amalgamated: #include "common/platforms/platform_esp32.h" */
/* Amalgamated: #include "common/platforms/platform_esp8266.h" */ /* Amalgamated: #include "common/platforms/platform_esp8266.h" */
/* Amalgamated: #include "common/platforms/platform_cc3200.h" */
/* Amalgamated: #include "common/platforms/platform_cc3100.h" */ /* Amalgamated: #include "common/platforms/platform_cc3100.h" */
/* Amalgamated: #include "common/platforms/platform_cc3200.h" */
/* Amalgamated: #include "common/platforms/platform_cc3220.h" */
/* Amalgamated: #include "common/platforms/platform_mbed.h" */ /* Amalgamated: #include "common/platforms/platform_mbed.h" */
/* Amalgamated: #include "common/platforms/platform_nrf51.h" */ /* Amalgamated: #include "common/platforms/platform_nrf51.h" */
/* Amalgamated: #include "common/platforms/platform_nrf52.h" */ /* Amalgamated: #include "common/platforms/platform_nrf52.h" */
@@ -223,14 +227,12 @@
#endif #endif
#define snprintf _snprintf #define snprintf _snprintf
#define vsnprintf _vsnprintf #define vsnprintf _vsnprintf
#define sleep(x) Sleep((x) *1000)
#define to64(x) _atoi64(x) #define to64(x) _atoi64(x)
#if !defined(__MINGW32__) && !defined(__MINGW64__) #if !defined(__MINGW32__) && !defined(__MINGW64__)
#define popen(x, y) _popen((x), (y)) #define popen(x, y) _popen((x), (y))
#define pclose(x) _pclose(x) #define pclose(x) _pclose(x)
#define fileno _fileno #define fileno _fileno
#endif #endif
#define rmdir _rmdir
#if defined(_MSC_VER) && _MSC_VER >= 1400 #if defined(_MSC_VER) && _MSC_VER >= 1400
#define fseeko(x, y, z) _fseeki64((x), (y), (z)) #define fseeko(x, y, z) _fseeki64((x), (y), (z))
#else #else
@@ -321,6 +323,9 @@ typedef struct _stati64 cs_stat_t;
#define MG_NET_IF MG_NET_IF_SOCKET #define MG_NET_IF MG_NET_IF_SOCKET
#endif #endif
int rmdir(const char *dirname);
unsigned int sleep(unsigned int seconds);
#endif /* CS_PLATFORM == CS_P_WINDOWS */ #endif /* CS_PLATFORM == CS_P_WINDOWS */
#endif /* CS_COMMON_PLATFORMS_PLATFORM_WINDOWS_H_ */ #endif /* CS_COMMON_PLATFORMS_PLATFORM_WINDOWS_H_ */
#ifdef MG_MODULE_LINES #ifdef MG_MODULE_LINES
@@ -538,7 +543,9 @@ typedef struct stat cs_stat_t;
#define SIZE_T_FMT "u" #define SIZE_T_FMT "u"
typedef struct stat cs_stat_t; typedef struct stat cs_stat_t;
#define DIRSEP '/' #define DIRSEP '/'
#if !defined(MGOS_VFS_DEFINE_DIRENT)
#define CS_DEFINE_DIRENT #define CS_DEFINE_DIRENT
#endif
#define to64(x) strtoll(x, NULL, 10) #define to64(x) strtoll(x, NULL, 10)
#define INT64_FMT PRId64 #define INT64_FMT PRId64
@@ -546,7 +553,7 @@ typedef struct stat cs_stat_t;
#define __cdecl #define __cdecl
#define _FILE_OFFSET_BITS 32 #define _FILE_OFFSET_BITS 32
#ifndef RTOS_SDK #if !defined(RTOS_SDK) && !defined(__cplusplus)
#define fileno(x) -1 #define fileno(x) -1
#endif #endif
@@ -558,9 +565,9 @@ typedef struct stat cs_stat_t;
#ifndef MG_NET_IF #ifndef MG_NET_IF
#include <lwip/opt.h> #include <lwip/opt.h>
#if LWIP_SOCKET /* RTOS SDK has LWIP sockets */ #if LWIP_SOCKET /* RTOS SDK has LWIP sockets */
# define MG_NET_IF MG_NET_IF_SOCKET #define MG_NET_IF MG_NET_IF_SOCKET
#else #else
# define MG_NET_IF MG_NET_IF_LWIP_LOW_LEVEL #define MG_NET_IF MG_NET_IF_LWIP_LOW_LEVEL
#endif #endif
#endif #endif
@@ -601,7 +608,7 @@ typedef struct stat cs_stat_t;
#include <simplelink.h> #include <simplelink.h>
#include <netapp.h> #include <netapp.h>
#undef timeval #undef timeval
typedef int sock_t; typedef int sock_t;
#define INVALID_SOCKET (-1) #define INVALID_SOCKET (-1)
@@ -700,7 +707,7 @@ struct stat {
}; };
int _stat(const char *pathname, struct stat *st); int _stat(const char *pathname, struct stat *st);
#define stat(a, b) _stat(a, b) int stat(const char *pathname, struct stat *st);
#define __S_IFMT 0170000 #define __S_IFMT 0170000
@@ -716,8 +723,10 @@ int _stat(const char *pathname, struct stat *st);
#define S_ISDIR(mode) __S_ISTYPE((mode), __S_IFDIR) #define S_ISDIR(mode) __S_ISTYPE((mode), __S_IFDIR)
#define S_ISREG(mode) __S_ISTYPE((mode), __S_IFREG) #define S_ISREG(mode) __S_ISTYPE((mode), __S_IFREG)
/* As of 5.2.7, TI compiler does not support va_copy() yet. */ /* 5.x series compilers don't have va_copy, 16.x do. */
#if __TI_COMPILER_VERSION__ < 16000000
#define va_copy(apc, ap) ((apc) = (ap)) #define va_copy(apc, ap) ((apc) = (ap))
#endif
#endif /* __TI_COMPILER_VERSION__ */ #endif /* __TI_COMPILER_VERSION__ */
@@ -838,7 +847,8 @@ int _stat(const char *pathname, struct stat *st);
#define CS_ENABLE_STDIO 1 #define CS_ENABLE_STDIO 1
#endif #endif
#if (defined(CC3200_FS_SPIFFS) || defined(CC3200_FS_SLFS)) && !defined(MG_ENABLE_FILESYSTEM) #if (defined(CC3200_FS_SPIFFS) || defined(CC3200_FS_SLFS)) && \
!defined(MG_ENABLE_FILESYSTEM)
#define MG_ENABLE_FILESYSTEM 1 #define MG_ENABLE_FILESYSTEM 1
#endif #endif
@@ -882,15 +892,15 @@ typedef struct stat cs_stat_t;
#define __cdecl #define __cdecl
#ifndef MG_NET_IF #ifndef MG_NET_IF
# include <lwip/opt.h> #include <lwip/opt.h>
# if LWIP_SOCKET #if LWIP_SOCKET
# define MG_NET_IF MG_NET_IF_SOCKET #define MG_NET_IF MG_NET_IF_SOCKET
# else #else
# define MG_NET_IF MG_NET_IF_LWIP_LOW_LEVEL #define MG_NET_IF MG_NET_IF_LWIP_LOW_LEVEL
# endif #endif
# define MG_LWIP 1 #define MG_LWIP 1
#elif MG_NET_IF == MG_NET_IF_SIMPLELINK #elif MG_NET_IF == MG_NET_IF_SIMPLELINK
# include "common/platforms/simplelink/cs_simplelink.h" /* Amalgamated: #include "common/platforms/simplelink/cs_simplelink.h" */
#endif #endif
#ifndef CS_ENABLE_STDIO #ifndef CS_ENABLE_STDIO
@@ -1012,16 +1022,16 @@ in_addr_t inet_addr(const char *cp);
#define to64(x) strtoll(x, NULL, 10) #define to64(x) strtoll(x, NULL, 10)
#define MG_NET_IF MG_NET_IF_LWIP_LOW_LEVEL #define MG_NET_IF MG_NET_IF_LWIP_LOW_LEVEL
#define MG_LWIP 1 #define MG_LWIP 1
#define MG_ENABLE_IPV6 1 #define MG_ENABLE_IPV6 1
/* /*
* For ARM C Compiler, make lwip to export `struct timeval`; for other * For ARM C Compiler, make lwip to export `struct timeval`; for other
* compilers, suppress it. * compilers, suppress it.
*/ */
#if !defined(__ARMCC_VERSION) #if !defined(__ARMCC_VERSION)
# define LWIP_TIMEVAL_PRIVATE 0 #define LWIP_TIMEVAL_PRIVATE 0
#else #else
struct timeval; struct timeval;
int gettimeofday(struct timeval *tp, void *tzp); int gettimeofday(struct timeval *tp, void *tzp);
@@ -1058,12 +1068,12 @@ int gettimeofday(struct timeval *tp, void *tzp);
#define to64(x) strtoll(x, NULL, 10) #define to64(x) strtoll(x, NULL, 10)
#define MG_NET_IF MG_NET_IF_LWIP_LOW_LEVEL #define MG_NET_IF MG_NET_IF_LWIP_LOW_LEVEL
#define MG_LWIP 1 #define MG_LWIP 1
#define MG_ENABLE_IPV6 1 #define MG_ENABLE_IPV6 1
#if !defined(ENOSPC) #if !defined(ENOSPC)
# define ENOSPC 28 /* No space left on device */ #define ENOSPC 28 /* No space left on device */
#endif #endif
/* /*
@@ -1071,7 +1081,7 @@ int gettimeofday(struct timeval *tp, void *tzp);
* compilers, suppress it. * compilers, suppress it.
*/ */
#if !defined(__ARMCC_VERSION) #if !defined(__ARMCC_VERSION)
# define LWIP_TIMEVAL_PRIVATE 0 #define LWIP_TIMEVAL_PRIVATE 0
#endif #endif
#define INT64_FMT PRId64 #define INT64_FMT PRId64
@@ -1095,9 +1105,10 @@ int gettimeofday(struct timeval *tp, void *tzp);
#ifndef CS_COMMON_PLATFORMS_SIMPLELINK_CS_SIMPLELINK_H_ #ifndef CS_COMMON_PLATFORMS_SIMPLELINK_CS_SIMPLELINK_H_
#define CS_COMMON_PLATFORMS_SIMPLELINK_CS_SIMPLELINK_H_ #define CS_COMMON_PLATFORMS_SIMPLELINK_CS_SIMPLELINK_H_
#if defined(MG_NET_IF) && MG_NET_IF == MG_NET_IF_SIMPLELINK
/* If simplelink.h is already included, all bets are off. */ /* If simplelink.h is already included, all bets are off. */
#if defined(MG_NET_IF) && MG_NET_IF == MG_NET_IF_SIMPLELINK && \ #if !defined(__SIMPLELINK_H__)
!defined(__SIMPLELINK_H__)
#include <stdbool.h> #include <stdbool.h>
@@ -1111,6 +1122,12 @@ int gettimeofday(struct timeval *tp, void *tzp);
#undef fd_set #undef fd_set
#endif #endif
#if CS_PLATFORM == CS_P_CC3220
#include <ti/drivers/net/wifi/porting/user.h>
#include <ti/drivers/net/wifi/simplelink.h>
#include <ti/drivers/net/wifi/sl_socket.h>
#include <ti/drivers/net/wifi/netapp.h>
#else
/* We want to disable SL_INC_STD_BSD_API_NAMING, so we include user.h ourselves /* We want to disable SL_INC_STD_BSD_API_NAMING, so we include user.h ourselves
* and undef it. */ * and undef it. */
#define PROVISIONING_API_H_ #define PROVISIONING_API_H_
@@ -1120,6 +1137,7 @@ int gettimeofday(struct timeval *tp, void *tzp);
#include <simplelink/include/simplelink.h> #include <simplelink/include/simplelink.h>
#include <simplelink/include/netapp.h> #include <simplelink/include/netapp.h>
#endif /* CS_PLATFORM == CS_P_CC3220 */
/* Now define only the subset of the BSD API that we use. /* Now define only the subset of the BSD API that we use.
* Notably, close(), read() and write() are not defined. */ * Notably, close(), read() and write() are not defined. */
@@ -1182,13 +1200,65 @@ int sl_fs_init(void);
void sl_restart_cb(struct mg_mgr *mgr); void sl_restart_cb(struct mg_mgr *mgr);
int sl_set_ssl_opts(struct mg_connection *nc); int sl_set_ssl_opts(int sock, struct mg_connection *nc);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif /* MG_NET_IF == MG_NET_IF_SIMPLELINK && !defined(__SIMPLELINK_H__) */ #endif /* !defined(__SIMPLELINK_H__) */
/* Compatibility with older versions of SimpleLink */
#if SL_MAJOR_VERSION_NUM < 2
#define SL_ERROR_BSD_EAGAIN SL_EAGAIN
#define SL_ERROR_BSD_EALREADY SL_EALREADY
#define SL_ERROR_BSD_ENOPROTOOPT SL_ENOPROTOOPT
#define SL_ERROR_BSD_ESECDATEERROR SL_ESECDATEERROR
#define SL_ERROR_BSD_ESECSNOVERIFY SL_ESECSNOVERIFY
#define SL_ERROR_FS_FAILED_TO_ALLOCATE_MEM SL_FS_ERR_FAILED_TO_ALLOCATE_MEM
#define SL_ERROR_FS_FILE_HAS_NOT_BEEN_CLOSE_CORRECTLY \
SL_FS_FILE_HAS_NOT_BEEN_CLOSE_CORRECTLY
#define SL_ERROR_FS_FILE_NAME_EXIST SL_FS_FILE_NAME_EXIST
#define SL_ERROR_FS_FILE_NOT_EXISTS SL_FS_ERR_FILE_NOT_EXISTS
#define SL_ERROR_FS_NO_AVAILABLE_NV_INDEX SL_FS_ERR_NO_AVAILABLE_NV_INDEX
#define SL_ERROR_FS_NOT_ENOUGH_STORAGE_SPACE SL_FS_ERR_NO_AVAILABLE_BLOCKS
#define SL_ERROR_FS_NOT_SUPPORTED SL_FS_ERR_NOT_SUPPORTED
#define SL_ERROR_FS_WRONG_FILE_NAME SL_FS_WRONG_FILE_NAME
#define SL_ERROR_FS_INVALID_HANDLE SL_FS_ERR_INVALID_HANDLE
#define SL_NETCFG_MAC_ADDRESS_GET SL_MAC_ADDRESS_GET
#define SL_SOCKET_FD_ZERO SL_FD_ZERO
#define SL_SOCKET_FD_SET SL_FD_SET
#define SL_SOCKET_FD_ISSET SL_FD_ISSET
#define SL_SO_SECURE_DOMAIN_NAME_VERIFICATION SO_SECURE_DOMAIN_NAME_VERIFICATION
#define SL_FS_READ FS_MODE_OPEN_READ
#define SL_FS_WRITE FS_MODE_OPEN_WRITE
#define SL_FI_FILE_SIZE(fi) ((fi).FileLen)
#define SL_FI_FILE_MAX_SIZE(fi) ((fi).AllocatedLen)
#define SlDeviceVersion_t SlVersionFull
#define sl_DeviceGet sl_DevGet
#define SL_DEVICE_GENERAL SL_DEVICE_GENERAL_CONFIGURATION
#define SL_LEN_TYPE _u8
#define SL_OPT_TYPE _u8
#else /* SL_MAJOR_VERSION_NUM >= 2 */
#define FS_MODE_OPEN_CREATE(max_size, flag) \
(SL_FS_CREATE | SL_FS_CREATE_MAX_SIZE(max_size))
#define SL_FI_FILE_SIZE(fi) ((fi).Len)
#define SL_FI_FILE_MAX_SIZE(fi) ((fi).MaxSize)
#define SL_LEN_TYPE _u16
#define SL_OPT_TYPE _u16
#endif /* SL_MAJOR_VERSION_NUM < 2 */
int slfs_open(const unsigned char *fname, uint32_t flags);
#endif /* MG_NET_IF == MG_NET_IF_SIMPLELINK */
#endif /* CS_COMMON_PLATFORMS_SIMPLELINK_CS_SIMPLELINK_H_ */ #endif /* CS_COMMON_PLATFORMS_SIMPLELINK_CS_SIMPLELINK_H_ */
#ifdef MG_MODULE_LINES #ifdef MG_MODULE_LINES
@@ -1375,18 +1445,18 @@ typedef struct _stati64 {
#endif #endif
#ifndef _UINTPTR_T_DEFINED #ifndef _UINTPTR_T_DEFINED
typedef unsigned int* uintptr_t; typedef unsigned int *uintptr_t;
#endif #endif
#define _S_IFREG 2 #define _S_IFREG 2
#define _S_IFDIR 4 #define _S_IFDIR 4
#ifndef S_ISDIR #ifndef S_ISDIR
#define S_ISDIR(x) (((x) & _S_IFDIR) != 0) #define S_ISDIR(x) (((x) &_S_IFDIR) != 0)
#endif #endif
#ifndef S_ISREG #ifndef S_ISREG
#define S_ISREG(x) (((x) & _S_IFREG) != 0) #define S_ISREG(x) (((x) &_S_IFREG) != 0)
#endif #endif
int open(const char *filename, int oflag, int pmode); int open(const char *filename, int oflag, int pmode);
@@ -1423,7 +1493,8 @@ typedef struct stat cs_stat_t;
#define MG_NET_IF MG_NET_IF_LWIP_LOW_LEVEL #define MG_NET_IF MG_NET_IF_LWIP_LOW_LEVEL
/* /*
* LPCXpress comes with 3 C library implementations: Newlib, NewlibNano and Redlib. * LPCXpress comes with 3 C library implementations: Newlib, NewlibNano and
*Redlib.
* See https://community.nxp.com/message/630860 for more details. * See https://community.nxp.com/message/630860 for more details.
* *
* Redlib is the default and lacks certain things, so we provide them. * Redlib is the default and lacks certain things, so we provide them.
@@ -1519,7 +1590,7 @@ typedef TCP_SOCKET sock_t;
#define CS_ENABLE_STDIO 1 #define CS_ENABLE_STDIO 1
#endif #endif
char* inet_ntoa(struct in_addr in); char *inet_ntoa(struct in_addr in);
#endif /* CS_PLATFORM == CS_P_PIC32 */ #endif /* CS_PLATFORM == CS_P_PIC32 */
@@ -1726,6 +1797,8 @@ void cs_hmac_sha1(const unsigned char *key, size_t key_len,
#ifndef CS_COMMON_CS_TIME_H_ #ifndef CS_COMMON_CS_TIME_H_
#define CS_COMMON_CS_TIME_H_ #define CS_COMMON_CS_TIME_H_
#include <time.h>
/* Amalgamated: #include "common/platform.h" */ /* Amalgamated: #include "common/platform.h" */
#ifdef __cplusplus #ifdef __cplusplus
@@ -1735,6 +1808,12 @@ extern "C" {
/* Sub-second granularity time(). */ /* Sub-second granularity time(). */
double cs_time(void); double cs_time(void);
/*
* Similar to (non-standard) timegm, converts broken-down time into the number
* of seconds since Unix Epoch.
*/
double cs_timegm(const struct tm *tm);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif /* __cplusplus */ #endif /* __cplusplus */
@@ -1757,7 +1836,7 @@ double cs_time(void);
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif /* __cplusplus */ #endif
/* Describes chunk of memory */ /* Describes chunk of memory */
struct mg_str { struct mg_str {
@@ -1799,12 +1878,19 @@ struct mg_str mg_strdup(const struct mg_str s);
*/ */
struct mg_str mg_strdup_nul(const struct mg_str s); struct mg_str mg_strdup_nul(const struct mg_str s);
/*
* Locates character in a string.
*/
const char *mg_strchr(const struct mg_str s, int c);
int mg_strcmp(const struct mg_str str1, const struct mg_str str2); int mg_strcmp(const struct mg_str str1, const struct mg_str str2);
int mg_strncmp(const struct mg_str str1, const struct mg_str str2, size_t n); int mg_strncmp(const struct mg_str str1, const struct mg_str str2, size_t n);
const char *mg_strstr(const struct mg_str haystack, const struct mg_str needle);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif /* __cplusplus */ #endif
#endif /* CS_COMMON_MG_STR_H_ */ #endif /* CS_COMMON_MG_STR_H_ */
#ifdef MG_MODULE_LINES #ifdef MG_MODULE_LINES
@@ -1953,6 +2039,7 @@ int cs_base64_decode(const unsigned char *s, int len, char *dst, int *dec_len);
#include <stdlib.h> #include <stdlib.h>
/* Amalgamated: #include "common/platform.h" */ /* Amalgamated: #include "common/platform.h" */
/* Amalgamated: #include "common/mg_str.h" */
#ifndef CS_ENABLE_STRDUP #ifndef CS_ENABLE_STRDUP
#define CS_ENABLE_STRDUP 0 #define CS_ENABLE_STRDUP 0
@@ -2047,6 +2134,34 @@ int mg_asprintf(char **buf, size_t size, const char *fmt, ...);
/* Same as mg_asprintf, but takes varargs list. */ /* Same as mg_asprintf, but takes varargs list. */
int mg_avprintf(char **buf, size_t size, const char *fmt, va_list ap); int mg_avprintf(char **buf, size_t size, const char *fmt, va_list ap);
/*
* A helper function for traversing a comma separated list of values.
* It returns a list pointer shifted to the next value or NULL if the end
* of the list found.
* The value is stored in a val vector. If the value has a form "x=y", then
* eq_val vector is initialised to point to the "y" part, and val vector length
* is adjusted to point only to "x".
* If the list is just a comma separated list of entries, like "aa,bb,cc" then
* `eq_val` will contain zero-length string.
*
* The purpose of this function is to parse comma separated string without
* any copying/memory allocation.
*/
const char *mg_next_comma_list_entry(const char *list, struct mg_str *val,
struct mg_str *eq_val);
struct mg_str mg_next_comma_list_entry_n(struct mg_str list, struct mg_str *val,
struct mg_str *eq_val);
/*
* Matches 0-terminated string (mg_match_prefix) or string with given length
* mg_match_prefix_n against a glob pattern.
*
* Match is case-insensitive. Returns number of bytes matched, or -1 if no
* match.
*/
int mg_match_prefix(const char *pattern, int pattern_len, const char *str);
int mg_match_prefix_n(const struct mg_str pattern, const struct mg_str str);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
@@ -2910,14 +3025,14 @@ struct { \
#define MG_ENABLE_IPV6 0 #define MG_ENABLE_IPV6 0
#endif #endif
#ifndef MG_ENABLE_JAVASCRIPT
#define MG_ENABLE_JAVASCRIPT 0
#endif
#ifndef MG_ENABLE_MQTT #ifndef MG_ENABLE_MQTT
#define MG_ENABLE_MQTT 1 #define MG_ENABLE_MQTT 1
#endif #endif
#ifndef MG_ENABLE_SOCKS
#define MG_ENABLE_SOCKS 0
#endif
#ifndef MG_ENABLE_MQTT_BROKER #ifndef MG_ENABLE_MQTT_BROKER
#define MG_ENABLE_MQTT_BROKER 0 #define MG_ENABLE_MQTT_BROKER 0
#endif #endif
@@ -3214,11 +3329,6 @@ int mg_ssl_if_write(struct mg_connection *nc, const void *data, size_t len);
#ifndef CS_MONGOOSE_SRC_NET_H_ #ifndef CS_MONGOOSE_SRC_NET_H_
#define CS_MONGOOSE_SRC_NET_H_ #define CS_MONGOOSE_SRC_NET_H_
#if MG_ENABLE_JAVASCRIPT
#define EXCLUDE_COMMON
#include <v7.h>
#endif
/* Amalgamated: #include "mongoose/src/common.h" */ /* Amalgamated: #include "mongoose/src/common.h" */
/* Amalgamated: #include "mongoose/src/net_if.h" */ /* Amalgamated: #include "mongoose/src/net_if.h" */
/* Amalgamated: #include "common/mbuf.h" */ /* Amalgamated: #include "common/mbuf.h" */
@@ -3281,10 +3391,7 @@ struct mg_mgr {
void *user_data; /* User data */ void *user_data; /* User data */
int num_ifaces; int num_ifaces;
struct mg_iface **ifaces; /* network interfaces */ struct mg_iface **ifaces; /* network interfaces */
#if MG_ENABLE_JAVASCRIPT const char *nameserver; /* DNS server to use */
struct v7 *v7;
#endif
const char *nameserver; /* DNS server to use */
}; };
/* /*
@@ -3748,17 +3855,6 @@ int mg_resolve(const char *domain_name, char *ip_addr_buf, size_t buf_len);
*/ */
int mg_check_ip_acl(const char *acl, uint32_t remote_ip); int mg_check_ip_acl(const char *acl, uint32_t remote_ip);
#if MG_ENABLE_JAVASCRIPT
/*
* Enables server-side JavaScript scripting.
* Requires a `-DMG_ENABLE_JAVASCRIPT` compilation flag and V7 engine sources.
* V7 instance must not be destroyed during manager's lifetime.
* Returns a V7 error.
*/
enum v7_err mg_enable_javascript(struct mg_mgr *m, struct v7 *v7,
const char *init_js_file_name);
#endif
/* /*
* Schedules an MG_EV_TIMER event to be delivered at `timestamp` time. * Schedules an MG_EV_TIMER event to be delivered at `timestamp` time.
* `timestamp` is UNIX time (the number of seconds since Epoch). It is * `timestamp` is UNIX time (the number of seconds since Epoch). It is
@@ -3889,8 +3985,12 @@ int mg_normalize_uri_path(const struct mg_str *in, struct mg_str *out);
extern "C" { extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
#ifndef MAX_PATH_SIZE #ifndef MG_MAX_PATH
#define MAX_PATH_SIZE 500 #ifdef PATH_MAX
#define MG_MAX_PATH PATH_MAX
#else
#define MG_MAX_PATH 256
#endif
#endif #endif
/* /*
@@ -3995,9 +4095,10 @@ void mg_set_close_on_exec(sock_t);
* *
* If both port number and IP address are printed, they are separated by `:`. * If both port number and IP address are printed, they are separated by `:`.
* If compiled with `-DMG_ENABLE_IPV6`, IPv6 addresses are supported. * If compiled with `-DMG_ENABLE_IPV6`, IPv6 addresses are supported.
* Return length of the stringified address.
*/ */
void mg_conn_addr_to_str(struct mg_connection *nc, char *buf, size_t len, int mg_conn_addr_to_str(struct mg_connection *c, char *buf, size_t len,
int flags); int flags);
#if MG_NET_IF == MG_NET_IF_SOCKET #if MG_NET_IF == MG_NET_IF_SOCKET
/* Legacy interface. */ /* Legacy interface. */
void mg_sock_to_str(sock_t sock, char *buf, size_t len, int flags); void mg_sock_to_str(sock_t sock, char *buf, size_t len, int flags);
@@ -4008,8 +4109,8 @@ void mg_sock_to_str(sock_t sock, char *buf, size_t len, int flags);
* *
* `flags` is MG_SOCK_STRINGIFY_IP and/or MG_SOCK_STRINGIFY_PORT. * `flags` is MG_SOCK_STRINGIFY_IP and/or MG_SOCK_STRINGIFY_PORT.
*/ */
void mg_sock_addr_to_str(const union socket_address *sa, char *buf, size_t len, int mg_sock_addr_to_str(const union socket_address *sa, char *buf, size_t len,
int flags); int flags);
#if MG_ENABLE_HEXDUMP #if MG_ENABLE_HEXDUMP
/* /*
@@ -4041,32 +4142,6 @@ void mg_hexdump_connection(struct mg_connection *nc, const char *path,
*/ */
int mg_is_big_endian(void); int mg_is_big_endian(void);
/*
* A helper function for traversing a comma separated list of values.
* It returns a list pointer shifted to the next value or NULL if the end
* of the list found.
* The value is stored in a val vector. If the value has a form "x=y", then
* eq_val vector is initialised to point to the "y" part, and val vector length
* is adjusted to point only to "x".
* If the list is just a comma separated list of entries, like "aa,bb,cc" then
* `eq_val` will contain zero-length string.
*
* The purpose of this function is to parse comma separated string without
* any copying/memory allocation.
*/
const char *mg_next_comma_list_entry(const char *list, struct mg_str *val,
struct mg_str *eq_val);
/*
* Matches 0-terminated string (mg_match_prefix) or string with given length
* mg_match_prefix_n against a glob pattern.
*
* Match is case-insensitive. Returns number of bytes matched, or -1 if no
* match.
*/
int mg_match_prefix(const char *pattern, int pattern_len, const char *str);
int mg_match_prefix_n(const struct mg_str pattern, const struct mg_str str);
/* /*
* Use with cs_base64_init/update/finish in order to write out base64 in chunks. * Use with cs_base64_init/update/finish in order to write out base64 in chunks.
*/ */
@@ -4085,6 +4160,14 @@ void mg_mbuf_append_base64(struct mbuf *mbuf, const void *data, size_t len);
void mg_basic_auth_header(const struct mg_str user, const struct mg_str pass, void mg_basic_auth_header(const struct mg_str user, const struct mg_str pass,
struct mbuf *buf); struct mbuf *buf);
/*
* URL-escape the specified string.
* All non-printable characters are escaped, plus `._-$,;~()/`.
* Input need not be NUL-terminated, but the returned string is.
* Returned string is heap-allocated and must be free()'d.
*/
struct mg_str mg_url_encode(const struct mg_str src);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif /* __cplusplus */ #endif /* __cplusplus */
@@ -4121,14 +4204,6 @@ extern "C" {
#define MG_MAX_HTTP_REQUEST_SIZE 1024 #define MG_MAX_HTTP_REQUEST_SIZE 1024
#endif #endif
#ifndef MG_MAX_PATH
#ifdef PATH_MAX
#define MG_MAX_PATH PATH_MAX
#else
#define MG_MAX_PATH 256
#endif
#endif
#ifndef MG_MAX_HTTP_SEND_MBUF #ifndef MG_MAX_HTTP_SEND_MBUF
#define MG_MAX_HTTP_SEND_MBUF 1024 #define MG_MAX_HTTP_SEND_MBUF 1024
#endif #endif
@@ -4865,6 +4940,18 @@ void mg_register_http_endpoint_opt(struct mg_connection *nc,
int mg_http_check_digest_auth(struct http_message *hm, const char *auth_domain, int mg_http_check_digest_auth(struct http_message *hm, const char *auth_domain,
FILE *fp); FILE *fp);
/*
* Authenticates given response params against an opened password file.
* Returns 1 if authenticated, 0 otherwise.
*
* It's used by mg_http_check_digest_auth().
*/
int mg_check_digest_auth(struct mg_str method, struct mg_str uri,
struct mg_str username, struct mg_str cnonce,
struct mg_str response, struct mg_str qop,
struct mg_str nc, struct mg_str nonce,
struct mg_str auth_domain, FILE *fp);
/* /*
* Sends buffer `buf` of size `len` to the client using chunked HTTP encoding. * Sends buffer `buf` of size `len` to the client using chunked HTTP encoding.
* This function sends the buffer size as hex number + newline first, then * This function sends the buffer size as hex number + newline first, then
@@ -5070,6 +5157,7 @@ int mg_http_create_digest_auth_header(char *buf, size_t buf_len,
struct mg_mqtt_message { struct mg_mqtt_message {
int cmd; int cmd;
int qos; int qos;
int len; /* message length in the IO buffer */
struct mg_str topic; struct mg_str topic;
struct mg_str payload; struct mg_str payload;
@@ -5105,6 +5193,7 @@ struct mg_send_mqtt_handshake_opts {
/* mg_mqtt_proto_data should be in header to allow external access to it */ /* mg_mqtt_proto_data should be in header to allow external access to it */
struct mg_mqtt_proto_data { struct mg_mqtt_proto_data {
uint16_t keep_alive; uint16_t keep_alive;
double last_control_time;
}; };
/* Message types */ /* Message types */
@@ -5303,7 +5392,9 @@ int mg_mqtt_vmatch_topic_expression(const char *exp, struct mg_str topic);
extern "C" { extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
#define MG_MQTT_MAX_SESSION_SUBSCRIPTIONS 512; #ifndef MG_MQTT_MAX_SESSION_SUBSCRIPTIONS
#define MG_MQTT_MAX_SESSION_SUBSCRIPTIONS 512
#endif
struct mg_mqtt_broker; struct mg_mqtt_broker;
@@ -5945,3 +6036,72 @@ struct mg_connection *mg_sntp_get_time(struct mg_mgr *mgr,
#endif #endif
#endif /* CS_MONGOOSE_SRC_SNTP_H_ */ #endif /* CS_MONGOOSE_SRC_SNTP_H_ */
#ifdef MG_MODULE_LINES
#line 1 "mongoose/src/socks.h"
#endif
/*
* Copyright (c) 2017 Cesanta Software Limited
* All rights reserved
*/
#ifndef CS_MONGOOSE_SRC_SOCKS_H_
#define CS_MONGOOSE_SRC_SOCKS_H_
#if MG_ENABLE_SOCKS
#define MG_SOCKS_VERSION 5
#define MG_SOCKS_HANDSHAKE_DONE MG_F_USER_1
#define MG_SOCKS_CONNECT_DONE MG_F_USER_2
/* SOCKS5 handshake methods */
enum mg_socks_handshake_method {
MG_SOCKS_HANDSHAKE_NOAUTH = 0, /* Handshake method - no authentication */
MG_SOCKS_HANDSHAKE_GSSAPI = 1, /* Handshake method - GSSAPI auth */
MG_SOCKS_HANDSHAKE_USERPASS = 2, /* Handshake method - user/password auth */
MG_SOCKS_HANDSHAKE_FAILURE = 0xff, /* Handshake method - failure */
};
/* SOCKS5 commands */
enum mg_socks_command {
MG_SOCKS_CMD_CONNECT = 1, /* Command: CONNECT */
MG_SOCKS_CMD_BIND = 2, /* Command: BIND */
MG_SOCKS_CMD_UDP_ASSOCIATE = 3, /* Command: UDP ASSOCIATE */
};
/* SOCKS5 address types */
enum mg_socks_address_type {
MG_SOCKS_ADDR_IPV4 = 1, /* Address type: IPv4 */
MG_SOCKS_ADDR_DOMAIN = 3, /* Address type: Domain name */
MG_SOCKS_ADDR_IPV6 = 4, /* Address type: IPv6 */
};
/* SOCKS5 response codes */
enum mg_socks_response {
MG_SOCKS_SUCCESS = 0, /* Response: success */
MG_SOCKS_FAILURE = 1, /* Response: failure */
MG_SOCKS_NOT_ALLOWED = 2, /* Response: connection not allowed */
MG_SOCKS_NET_UNREACHABLE = 3, /* Response: network unreachable */
MG_SOCKS_HOST_UNREACHABLE = 4, /* Response: network unreachable */
MG_SOCKS_CONN_REFUSED = 5, /* Response: network unreachable */
MG_SOCKS_TTL_EXPIRED = 6, /* Response: network unreachable */
MG_SOCKS_CMD_NOT_SUPPORTED = 7, /* Response: network unreachable */
MG_SOCKS_ADDR_NOT_SUPPORTED = 8, /* Response: network unreachable */
};
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/* Turn the connection into the SOCKS server */
void mg_set_protocol_socks(struct mg_connection *c);
/* Create socks tunnel for the client connection */
struct mg_iface *mg_socks_mk_iface(struct mg_mgr *, const char *proxy_addr);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif
#endif
+6 -2
View File
@@ -99,9 +99,9 @@ def resolve(path, parent_name):
else: else:
p = os.path.join(args.include_path, path) p = os.path.join(args.include_path, path)
if os.path.exists(p) and not args.norel: if os.path.exists(p) and not args.norel:
p = os.path.realpath(p).replace('%s/' % os.getcwd(), '') p = os.path.realpath(p).replace('%s%s' % (os.getcwd(), os.sep), '')
# print >>sys.stderr, '%s -> %s (cwd %s)' % (path, p, os.getcwd()) # print >>sys.stderr, '%s -> %s (cwd %s)' % (path, p, os.getcwd())
return p return p.replace(os.sep, '/')
def emit_line_directive(out, name, parent_name): def emit_line_directive(out, name, parent_name):
print >>out, '''#ifdef %(prefix)s_MODULE_LINES print >>out, '''#ifdef %(prefix)s_MODULE_LINES
@@ -148,6 +148,10 @@ if args.first:
# emitting # emitting
if sys.platform == "win32":
import os, msvcrt
msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
if args.public: if args.public:
print '#include "%s"' % (args.public) print '#include "%s"' % (args.public)