1 /* 2 * libwebsockets - small server side websockets and web server implementation 3 * 4 * Copyright (C) 2010 - 2019 Andy Green <andy@warmcat.com> 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a copy 7 * of this software and associated documentation files (the "Software"), to 8 * deal in the Software without restriction, including without limitation the 9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 10 * sell copies of the Software, and to permit persons to whom the Software is 11 * furnished to do so, subject to the following conditions: 12 * 13 * The above copyright notice and this permission notice shall be included in 14 * all copies or substantial portions of the Software. 15 * 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 22 * IN THE SOFTWARE. 23 */ 24 25 #if defined(LWS_WITH_MINIZ) 26 #include <miniz.h> 27 #else 28 #include <zlib.h> 29 #endif 30 31 #define DEFLATE_FRAME_COMPRESSION_LEVEL_SERVER 1 32 #define DEFLATE_FRAME_COMPRESSION_LEVEL_CLIENT Z_DEFAULT_COMPRESSION 33 34 enum arg_indexes { 35 PMD_SERVER_NO_CONTEXT_TAKEOVER, 36 PMD_CLIENT_NO_CONTEXT_TAKEOVER, 37 PMD_SERVER_MAX_WINDOW_BITS, 38 PMD_CLIENT_MAX_WINDOW_BITS, 39 PMD_RX_BUF_PWR2, 40 PMD_TX_BUF_PWR2, 41 PMD_COMP_LEVEL, 42 PMD_MEM_LEVEL, 43 44 PMD_ARG_COUNT 45 }; 46 47 struct lws_ext_pm_deflate_priv { 48 z_stream rx; 49 z_stream tx; 50 51 unsigned char *buf_rx_inflated; /* RX inflated output buffer */ 52 unsigned char *buf_tx_deflated; /* TX deflated output buffer */ 53 54 unsigned char *buf_tx_holding; 55 56 size_t count_rx_between_fin; 57 size_t count_tx_between_fin; 58 59 size_t len_tx_holding; 60 61 unsigned char args[PMD_ARG_COUNT]; 62 63 unsigned char tx_first_frame_type; 64 65 unsigned char tx_init:1; 66 unsigned char rx_init:1; 67 unsigned char compressed_out:1; 68 }; 69 70