1d4afb5ceSopenharmony_ci /* 2d4afb5ceSopenharmony_ci * libwebsockets - small server side websockets and web server implementation 3d4afb5ceSopenharmony_ci * 4d4afb5ceSopenharmony_ci * Copyright (C) 2010 - 2019 Andy Green <andy@warmcat.com> 5d4afb5ceSopenharmony_ci * 6d4afb5ceSopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a copy 7d4afb5ceSopenharmony_ci * of this software and associated documentation files (the "Software"), to 8d4afb5ceSopenharmony_ci * deal in the Software without restriction, including without limitation the 9d4afb5ceSopenharmony_ci * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 10d4afb5ceSopenharmony_ci * sell copies of the Software, and to permit persons to whom the Software is 11d4afb5ceSopenharmony_ci * furnished to do so, subject to the following conditions: 12d4afb5ceSopenharmony_ci * 13d4afb5ceSopenharmony_ci * The above copyright notice and this permission notice shall be included in 14d4afb5ceSopenharmony_ci * all copies or substantial portions of the Software. 15d4afb5ceSopenharmony_ci * 16d4afb5ceSopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17d4afb5ceSopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18d4afb5ceSopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19d4afb5ceSopenharmony_ci * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20d4afb5ceSopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21d4afb5ceSopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 22d4afb5ceSopenharmony_ci * IN THE SOFTWARE. 23d4afb5ceSopenharmony_ci * 24d4afb5ceSopenharmony_ci * This is included from private-lib-core.h if LWS_WITH_HTTP_STREAM_COMPRESSION 25d4afb5ceSopenharmony_ci */ 26d4afb5ceSopenharmony_ci 27d4afb5ceSopenharmony_ci#if defined(LWS_WITH_MINIZ) 28d4afb5ceSopenharmony_ci#include <miniz.h> 29d4afb5ceSopenharmony_ci#else 30d4afb5ceSopenharmony_ci#include <zlib.h> 31d4afb5ceSopenharmony_ci#endif 32d4afb5ceSopenharmony_ci#if defined(LWS_WITH_HTTP_BROTLI) 33d4afb5ceSopenharmony_ci#include <brotli/encode.h> 34d4afb5ceSopenharmony_ci#include <brotli/decode.h> 35d4afb5ceSopenharmony_ci#endif 36d4afb5ceSopenharmony_ci 37d4afb5ceSopenharmony_ci/* 38d4afb5ceSopenharmony_ci * struct holding union of all the available compression methods' context data, 39d4afb5ceSopenharmony_ci * and state if it's compressing or decompressing 40d4afb5ceSopenharmony_ci */ 41d4afb5ceSopenharmony_ci 42d4afb5ceSopenharmony_citypedef struct lws_compression_ctx { 43d4afb5ceSopenharmony_ci union { 44d4afb5ceSopenharmony_ci 45d4afb5ceSopenharmony_ci#if defined(LWS_WITH_HTTP_BROTLI) 46d4afb5ceSopenharmony_ci BrotliEncoderState *br_en; 47d4afb5ceSopenharmony_ci BrotliDecoderState *br_de; 48d4afb5ceSopenharmony_ci#endif 49d4afb5ceSopenharmony_ci z_stream *deflate; 50d4afb5ceSopenharmony_ci void *generic_ctx_ptr; 51d4afb5ceSopenharmony_ci } u; 52d4afb5ceSopenharmony_ci 53d4afb5ceSopenharmony_ci struct lws_buflist *buflist_comp; 54d4afb5ceSopenharmony_ci 55d4afb5ceSopenharmony_ci unsigned int is_decompression:1; 56d4afb5ceSopenharmony_ci unsigned int final_on_input_side:1; 57d4afb5ceSopenharmony_ci unsigned int may_have_more:1; 58d4afb5ceSopenharmony_ci unsigned int chunking:1; 59d4afb5ceSopenharmony_ci} lws_comp_ctx_t; 60d4afb5ceSopenharmony_ci 61d4afb5ceSopenharmony_ci/* generic structure defining the interface to a compression method */ 62d4afb5ceSopenharmony_ci 63d4afb5ceSopenharmony_cistruct lws_compression_support { 64d4afb5ceSopenharmony_ci /** compression name as used by, eg, content-ecoding */ 65d4afb5ceSopenharmony_ci const char *encoding_name; 66d4afb5ceSopenharmony_ci /** create a compression context for the compression method, or NULL */ 67d4afb5ceSopenharmony_ci int (*init_compression)(lws_comp_ctx_t *ctx, int decomp); 68d4afb5ceSopenharmony_ci /** pass data into the context to be processed */ 69d4afb5ceSopenharmony_ci int (*process)(lws_comp_ctx_t *ctx, const void *in, size_t *ilen_iused, 70d4afb5ceSopenharmony_ci void *out, size_t *olen_oused); 71d4afb5ceSopenharmony_ci /** destroy the de/compression context */ 72d4afb5ceSopenharmony_ci void (*destroy)(lws_comp_ctx_t *ctx); 73d4afb5ceSopenharmony_ci}; 74d4afb5ceSopenharmony_ci 75d4afb5ceSopenharmony_ciextern struct lws_compression_support lcs_deflate; 76d4afb5ceSopenharmony_ciextern struct lws_compression_support lcs_brotli; 77d4afb5ceSopenharmony_ci 78d4afb5ceSopenharmony_ciint 79d4afb5ceSopenharmony_cilws_http_compression_validate(struct lws *wsi); 80d4afb5ceSopenharmony_ci 81d4afb5ceSopenharmony_ciint 82d4afb5ceSopenharmony_cilws_http_compression_transform(struct lws *wsi, unsigned char *buf, 83d4afb5ceSopenharmony_ci size_t len, enum lws_write_protocol *wp, 84d4afb5ceSopenharmony_ci unsigned char **outbuf, size_t *olen_oused); 85d4afb5ceSopenharmony_ci 86d4afb5ceSopenharmony_civoid 87d4afb5ceSopenharmony_cilws_http_compression_destroy(struct lws *wsi); 88