trunk/3rdparty/mongoose/README.md
| r243581 | r243582 | |
| 78 | 78 | |
| 79 | 79 | # Other products by Cesanta Software: simple and effective |
| 80 | 80 | |
| 81 | - [Fossa](http://github.com/cesanta/fossa) - Multi-protocol networking library |
| 81 | 82 | - [SSL Wrapper](https://github.com/cesanta/ssl_wrapper) - application to |
| 82 | 83 | secure network communications |
| 83 | 84 | - [Frozen](https://github.com/cesanta/frozen) - JSON parser and generator |
| 84 | 85 | - [SLRE](https://github.com/cesanta/slre) - Super Light Regular Expression |
| 85 | 86 | library |
| 86 | | - [Net Skeleton](https://github.com/cesanta/net_skeleton) - framework for |
| 87 | | building network applications |
| 88 | | - [SLDR](https://github.com/cesanta/sldr) - Super Light DNS Resolver |
trunk/3rdparty/mongoose/docs/SSL.md
| r243581 | r243582 | |
| 1 | 1 | # Mongoose SSL guide |
| 2 | 2 | |
| 3 | 3 | SSL is a protocol that makes web communication secure. To enable SSL |
| 4 | | in mongoose, 3 steps are required: |
| 4 | in mongoose, 2 steps are required: |
| 5 | 5 | |
| 6 | | 1. Valid certificate file must be created |
| 7 | | 2. `ssl_certificate` options must be set to contain path to the |
| 8 | | certificate file. |
| 9 | | 3. `listening_ports` option must contain a port number with letter `s` |
| 10 | | appended to it, which instructs Mongoose to use SSL for all connections |
| 11 | | made to that port. |
| 6 | 1. Create valid SSL certificate file |
| 7 | 2. Append SSL certificate file path to the `listening_ports` option |
| 12 | 8 | |
| 13 | 9 | Below is the `mongoose.conf` file snippet for typical SSL setup: |
| 14 | 10 | |
| 15 | | document_root www_root # Serve files in www_root directory |
| 16 | | listening_ports 80r,443s # Redirect all HTTP requests to HTTPS |
| 17 | | ssl_certificate ssl_cert.pem # Location of certificate file |
| 11 | document_root www_root # Serve files in www_root directory |
| 12 | listening_ports 80,443:cert.pem # Listen on ports 80 and 443 |
| 18 | 13 | |
| 19 | 14 | ## How to create SSL certificate file |
| 20 | 15 | |
trunk/3rdparty/mongoose/mongoose.c
| r243581 | r243582 | |
| 48 | 48 | #define _INTEGRAL_MAX_BITS 64 // Enable _stati64() on Windows |
| 49 | 49 | #define _CRT_SECURE_NO_WARNINGS // Disable deprecation warning in VS2005+ |
| 50 | 50 | #undef WIN32_LEAN_AND_MEAN // Let windows.h always include winsock2.h |
| 51 | | #ifdef __Linux__ |
| 51 | #if defined(__Linux__) || defined(_WIN32) |
| 52 | 52 | #define _XOPEN_SOURCE 600 // For flockfile() on Linux |
| 53 | 53 | #endif |
| 54 | 54 | #define __STDC_FORMAT_MACROS // <inttypes.h> wants this for C++ |
| r243581 | r243582 | |
| 347 | 347 | assert(io != NULL); |
| 348 | 348 | assert(io->len <= io->size); |
| 349 | 349 | |
| 350 | /* check overflow */ |
| 351 | if (len > ~(size_t)0 - (size_t)(io->buf + io->len)) { |
| 352 | return 0; |
| 353 | } |
| 354 | |
| 350 | 355 | if (len <= 0) { |
| 351 | 356 | } else if (io->len + len <= io->size) { |
| 352 | 357 | memcpy(io->buf + io->len, buf, len); |
| r243581 | r243582 | |
| 2893 | 2898 | static int deliver_websocket_frame(struct connection *conn) { |
| 2894 | 2899 | // Having buf unsigned char * is important, as it is used below in arithmetic |
| 2895 | 2900 | unsigned char *buf = (unsigned char *) conn->ns_conn->recv_iobuf.buf; |
| 2896 | | int i, len, buf_len = conn->ns_conn->recv_iobuf.len, frame_len = 0, |
| 2901 | size_t i, len, buf_len = conn->ns_conn->recv_iobuf.len, frame_len = 0, |
| 2897 | 2902 | mask_len = 0, header_len = 0, data_len = 0, buffered = 0; |
| 2898 | 2903 | |
| 2899 | 2904 | if (buf_len >= 2) { |
| r243581 | r243582 | |
| 2904 | 2909 | header_len = 2 + mask_len; |
| 2905 | 2910 | } else if (len == 126 && buf_len >= 4 + mask_len) { |
| 2906 | 2911 | header_len = 4 + mask_len; |
| 2907 | | data_len = ((((int) buf[2]) << 8) + buf[3]); |
| 2912 | data_len = ((((size_t) buf[2]) << 8) + buf[3]); |
| 2908 | 2913 | } else if (buf_len >= 10 + mask_len) { |
| 2909 | 2914 | header_len = 10 + mask_len; |
| 2910 | | data_len = (int) (((uint64_t) htonl(* (uint32_t *) &buf[2])) << 32) + |
| 2915 | data_len = (size_t) (((uint64_t) htonl(* (uint32_t *) &buf[2])) << 32) + |
| 2911 | 2916 | htonl(* (uint32_t *) &buf[6]); |
| 2912 | 2917 | } |
| 2913 | 2918 | } |
| r243581 | r243582 | |
| 2938 | 2943 | } |
| 2939 | 2944 | |
| 2940 | 2945 | size_t mg_websocket_write(struct mg_connection *conn, int opcode, |
| 2941 | | const char *data, size_t data_len) { |
| 2946 | const char *data, size_t data_len) { |
| 2942 | 2947 | unsigned char mem[4192], *copy = mem; |
| 2943 | 2948 | size_t copy_len = 0; |
| 2944 | 2949 | |
| 2950 | /* Check overflow */ |
| 2951 | if (data_len > ~(size_t)0 - (size_t)10) { |
| 2952 | return 0; |
| 2953 | } |
| 2954 | |
| 2945 | 2955 | if (data_len + 10 > sizeof(mem) && |
| 2946 | 2956 | (copy = (unsigned char *) NS_MALLOC(data_len + 10)) == NULL) { |
| 2947 | 2957 | return 0; |