aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/curl/lib/content_encoding.c
diff options
context:
space:
mode:
authorthegeorg <thegeorg@yandex-team.ru>2022-02-10 16:45:12 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:45:12 +0300
commit49116032d905455a7b1c994e4a696afc885c1e71 (patch)
treebe835aa92c6248212e705f25388ebafcf84bc7a1 /contrib/libs/curl/lib/content_encoding.c
parent4e839db24a3bbc9f1c610c43d6faaaa99824dcca (diff)
downloadydb-49116032d905455a7b1c994e4a696afc885c1e71.tar.gz
Restoring authorship annotation for <thegeorg@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'contrib/libs/curl/lib/content_encoding.c')
-rw-r--r--contrib/libs/curl/lib/content_encoding.c326
1 files changed, 163 insertions, 163 deletions
diff --git a/contrib/libs/curl/lib/content_encoding.c b/contrib/libs/curl/lib/content_encoding.c
index 7550ce25a0..68da3fa1cf 100644
--- a/contrib/libs/curl/lib/content_encoding.c
+++ b/contrib/libs/curl/lib/content_encoding.c
@@ -5,11 +5,11 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
- * are also available at https://curl.se/docs/copyright.html.
+ * are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
@@ -34,10 +34,10 @@
#error #include <brotli/decode.h>
#endif
-#ifdef HAVE_ZSTD
-#error #include <zstd.h>
-#endif
-
+#ifdef HAVE_ZSTD
+#error #include <zstd.h>
+#endif
+
#include "sendf.h"
#include "http.h"
#include "content_encoding.h"
@@ -81,11 +81,11 @@ typedef enum {
} zlibInitState;
/* Writer parameters. */
-struct zlib_params {
+struct zlib_params {
zlibInitState zlib_init; /* zlib init state */
uInt trailerlen; /* Remaining trailer byte count. */
z_stream z; /* State structure for zlib. */
-};
+};
static voidpf
@@ -133,8 +133,8 @@ exit_zlib(struct connectdata *conn,
return result;
}
-static CURLcode process_trailer(struct connectdata *conn,
- struct zlib_params *zp)
+static CURLcode process_trailer(struct connectdata *conn,
+ struct zlib_params *zp)
{
z_stream *z = &zp->z;
CURLcode result = CURLE_OK;
@@ -158,10 +158,10 @@ static CURLcode process_trailer(struct connectdata *conn,
}
static CURLcode inflate_stream(struct connectdata *conn,
- struct contenc_writer *writer,
- zlibInitState started)
+ struct contenc_writer *writer,
+ zlibInitState started)
{
- struct zlib_params *zp = (struct zlib_params *) &writer->params;
+ struct zlib_params *zp = (struct zlib_params *) &writer->params;
z_stream *z = &zp->z; /* zlib state structure */
uInt nread = z->avail_in;
Bytef *orig_in = z->next_in;
@@ -261,9 +261,9 @@ static CURLcode inflate_stream(struct connectdata *conn,
/* Deflate handler. */
static CURLcode deflate_init_writer(struct connectdata *conn,
- struct contenc_writer *writer)
+ struct contenc_writer *writer)
{
- struct zlib_params *zp = (struct zlib_params *) &writer->params;
+ struct zlib_params *zp = (struct zlib_params *) &writer->params;
z_stream *z = &zp->z; /* zlib state structure */
if(!writer->downstream)
@@ -280,10 +280,10 @@ static CURLcode deflate_init_writer(struct connectdata *conn,
}
static CURLcode deflate_unencode_write(struct connectdata *conn,
- struct contenc_writer *writer,
+ struct contenc_writer *writer,
const char *buf, size_t nbytes)
{
- struct zlib_params *zp = (struct zlib_params *) &writer->params;
+ struct zlib_params *zp = (struct zlib_params *) &writer->params;
z_stream *z = &zp->z; /* zlib state structure */
/* Set the compressed input when this function is called */
@@ -298,29 +298,29 @@ static CURLcode deflate_unencode_write(struct connectdata *conn,
}
static void deflate_close_writer(struct connectdata *conn,
- struct contenc_writer *writer)
+ struct contenc_writer *writer)
{
- struct zlib_params *zp = (struct zlib_params *) &writer->params;
+ struct zlib_params *zp = (struct zlib_params *) &writer->params;
z_stream *z = &zp->z; /* zlib state structure */
exit_zlib(conn, z, &zp->zlib_init, CURLE_OK);
}
-static const struct content_encoding deflate_encoding = {
+static const struct content_encoding deflate_encoding = {
"deflate",
NULL,
deflate_init_writer,
deflate_unencode_write,
deflate_close_writer,
- sizeof(struct zlib_params)
+ sizeof(struct zlib_params)
};
/* Gzip handler. */
static CURLcode gzip_init_writer(struct connectdata *conn,
- struct contenc_writer *writer)
+ struct contenc_writer *writer)
{
- struct zlib_params *zp = (struct zlib_params *) &writer->params;
+ struct zlib_params *zp = (struct zlib_params *) &writer->params;
z_stream *z = &zp->z; /* zlib state structure */
if(!writer->downstream)
@@ -434,10 +434,10 @@ static enum {
#endif
static CURLcode gzip_unencode_write(struct connectdata *conn,
- struct contenc_writer *writer,
+ struct contenc_writer *writer,
const char *buf, size_t nbytes)
{
- struct zlib_params *zp = (struct zlib_params *) &writer->params;
+ struct zlib_params *zp = (struct zlib_params *) &writer->params;
z_stream *z = &zp->z; /* zlib state structure */
if(zp->zlib_init == ZLIB_INIT_GZIP) {
@@ -562,21 +562,21 @@ static CURLcode gzip_unencode_write(struct connectdata *conn,
}
static void gzip_close_writer(struct connectdata *conn,
- struct contenc_writer *writer)
+ struct contenc_writer *writer)
{
- struct zlib_params *zp = (struct zlib_params *) &writer->params;
+ struct zlib_params *zp = (struct zlib_params *) &writer->params;
z_stream *z = &zp->z; /* zlib state structure */
exit_zlib(conn, z, &zp->zlib_init, CURLE_OK);
}
-static const struct content_encoding gzip_encoding = {
+static const struct content_encoding gzip_encoding = {
"gzip",
"x-gzip",
gzip_init_writer,
gzip_unencode_write,
gzip_close_writer,
- sizeof(struct zlib_params)
+ sizeof(struct zlib_params)
};
#endif /* HAVE_LIBZ */
@@ -584,9 +584,9 @@ static const struct content_encoding gzip_encoding = {
#ifdef HAVE_BROTLI
/* Writer parameters. */
-struct brotli_params {
+struct brotli_params {
BrotliDecoderState *br; /* State structure for brotli. */
-};
+};
static CURLcode brotli_map_error(BrotliDecoderErrorCode be)
{
@@ -627,9 +627,9 @@ static CURLcode brotli_map_error(BrotliDecoderErrorCode be)
}
static CURLcode brotli_init_writer(struct connectdata *conn,
- struct contenc_writer *writer)
+ struct contenc_writer *writer)
{
- struct brotli_params *bp = (struct brotli_params *) &writer->params;
+ struct brotli_params *bp = (struct brotli_params *) &writer->params;
(void) conn;
if(!writer->downstream)
@@ -640,10 +640,10 @@ static CURLcode brotli_init_writer(struct connectdata *conn,
}
static CURLcode brotli_unencode_write(struct connectdata *conn,
- struct contenc_writer *writer,
+ struct contenc_writer *writer,
const char *buf, size_t nbytes)
{
- struct brotli_params *bp = (struct brotli_params *) &writer->params;
+ struct brotli_params *bp = (struct brotli_params *) &writer->params;
const uint8_t *src = (const uint8_t *) buf;
char *decomp;
uint8_t *dst;
@@ -688,9 +688,9 @@ static CURLcode brotli_unencode_write(struct connectdata *conn,
}
static void brotli_close_writer(struct connectdata *conn,
- struct contenc_writer *writer)
+ struct contenc_writer *writer)
{
- struct brotli_params *bp = (struct brotli_params *) &writer->params;
+ struct brotli_params *bp = (struct brotli_params *) &writer->params;
(void) conn;
if(bp->br) {
@@ -699,129 +699,129 @@ static void brotli_close_writer(struct connectdata *conn,
}
}
-static const struct content_encoding brotli_encoding = {
+static const struct content_encoding brotli_encoding = {
"br",
NULL,
brotli_init_writer,
brotli_unencode_write,
brotli_close_writer,
- sizeof(struct brotli_params)
+ sizeof(struct brotli_params)
+};
+#endif
+
+
+#ifdef HAVE_ZSTD
+/* Writer parameters. */
+struct zstd_params {
+ ZSTD_DStream *zds; /* State structure for zstd. */
+ void *decomp;
+};
+
+static CURLcode zstd_init_writer(struct connectdata *conn,
+ struct contenc_writer *writer)
+{
+ struct zstd_params *zp = (struct zstd_params *)&writer->params;
+ (void)conn;
+
+ if(!writer->downstream)
+ return CURLE_WRITE_ERROR;
+
+ zp->zds = ZSTD_createDStream();
+ zp->decomp = NULL;
+ return zp->zds ? CURLE_OK : CURLE_OUT_OF_MEMORY;
+}
+
+static CURLcode zstd_unencode_write(struct connectdata *conn,
+ struct contenc_writer *writer,
+ const char *buf, size_t nbytes)
+{
+ CURLcode result = CURLE_OK;
+ struct zstd_params *zp = (struct zstd_params *)&writer->params;
+ ZSTD_inBuffer in;
+ ZSTD_outBuffer out;
+ size_t errorCode;
+
+ if(!zp->decomp) {
+ zp->decomp = malloc(DSIZ);
+ if(!zp->decomp)
+ return CURLE_OUT_OF_MEMORY;
+ }
+ in.pos = 0;
+ in.src = buf;
+ in.size = nbytes;
+
+ for(;;) {
+ out.pos = 0;
+ out.dst = zp->decomp;
+ out.size = DSIZ;
+
+ errorCode = ZSTD_decompressStream(zp->zds, &out, &in);
+ if(ZSTD_isError(errorCode)) {
+ return CURLE_BAD_CONTENT_ENCODING;
+ }
+ if(out.pos > 0) {
+ result = Curl_unencode_write(conn, writer->downstream,
+ zp->decomp, out.pos);
+ if(result)
+ break;
+ }
+ if((in.pos == nbytes) && (out.pos < out.size))
+ break;
+ }
+
+ return result;
+}
+
+static void zstd_close_writer(struct connectdata *conn,
+ struct contenc_writer *writer)
+{
+ struct zstd_params *zp = (struct zstd_params *)&writer->params;
+ (void)conn;
+
+ if(zp->decomp) {
+ free(zp->decomp);
+ zp->decomp = NULL;
+ }
+ if(zp->zds) {
+ ZSTD_freeDStream(zp->zds);
+ zp->zds = NULL;
+ }
+}
+
+static const struct content_encoding zstd_encoding = {
+ "zstd",
+ NULL,
+ zstd_init_writer,
+ zstd_unencode_write,
+ zstd_close_writer,
+ sizeof(struct zstd_params)
};
#endif
-#ifdef HAVE_ZSTD
-/* Writer parameters. */
-struct zstd_params {
- ZSTD_DStream *zds; /* State structure for zstd. */
- void *decomp;
-};
-
-static CURLcode zstd_init_writer(struct connectdata *conn,
- struct contenc_writer *writer)
-{
- struct zstd_params *zp = (struct zstd_params *)&writer->params;
- (void)conn;
-
- if(!writer->downstream)
- return CURLE_WRITE_ERROR;
-
- zp->zds = ZSTD_createDStream();
- zp->decomp = NULL;
- return zp->zds ? CURLE_OK : CURLE_OUT_OF_MEMORY;
-}
-
-static CURLcode zstd_unencode_write(struct connectdata *conn,
- struct contenc_writer *writer,
- const char *buf, size_t nbytes)
-{
- CURLcode result = CURLE_OK;
- struct zstd_params *zp = (struct zstd_params *)&writer->params;
- ZSTD_inBuffer in;
- ZSTD_outBuffer out;
- size_t errorCode;
-
- if(!zp->decomp) {
- zp->decomp = malloc(DSIZ);
- if(!zp->decomp)
- return CURLE_OUT_OF_MEMORY;
- }
- in.pos = 0;
- in.src = buf;
- in.size = nbytes;
-
- for(;;) {
- out.pos = 0;
- out.dst = zp->decomp;
- out.size = DSIZ;
-
- errorCode = ZSTD_decompressStream(zp->zds, &out, &in);
- if(ZSTD_isError(errorCode)) {
- return CURLE_BAD_CONTENT_ENCODING;
- }
- if(out.pos > 0) {
- result = Curl_unencode_write(conn, writer->downstream,
- zp->decomp, out.pos);
- if(result)
- break;
- }
- if((in.pos == nbytes) && (out.pos < out.size))
- break;
- }
-
- return result;
-}
-
-static void zstd_close_writer(struct connectdata *conn,
- struct contenc_writer *writer)
-{
- struct zstd_params *zp = (struct zstd_params *)&writer->params;
- (void)conn;
-
- if(zp->decomp) {
- free(zp->decomp);
- zp->decomp = NULL;
- }
- if(zp->zds) {
- ZSTD_freeDStream(zp->zds);
- zp->zds = NULL;
- }
-}
-
-static const struct content_encoding zstd_encoding = {
- "zstd",
- NULL,
- zstd_init_writer,
- zstd_unencode_write,
- zstd_close_writer,
- sizeof(struct zstd_params)
-};
-#endif
-
-
/* Identity handler. */
static CURLcode identity_init_writer(struct connectdata *conn,
- struct contenc_writer *writer)
+ struct contenc_writer *writer)
{
(void) conn;
return writer->downstream? CURLE_OK: CURLE_WRITE_ERROR;
}
static CURLcode identity_unencode_write(struct connectdata *conn,
- struct contenc_writer *writer,
+ struct contenc_writer *writer,
const char *buf, size_t nbytes)
{
return Curl_unencode_write(conn, writer->downstream, buf, nbytes);
}
static void identity_close_writer(struct connectdata *conn,
- struct contenc_writer *writer)
+ struct contenc_writer *writer)
{
(void) conn;
(void) writer;
}
-static const struct content_encoding identity_encoding = {
+static const struct content_encoding identity_encoding = {
"identity",
"none",
identity_init_writer,
@@ -832,7 +832,7 @@ static const struct content_encoding identity_encoding = {
/* supported content encodings table. */
-static const struct content_encoding * const encodings[] = {
+static const struct content_encoding * const encodings[] = {
&identity_encoding,
#ifdef HAVE_LIBZ
&deflate_encoding,
@@ -841,9 +841,9 @@ static const struct content_encoding * const encodings[] = {
#ifdef HAVE_BROTLI
&brotli_encoding,
#endif
-#ifdef HAVE_ZSTD
- &zstd_encoding,
-#endif
+#ifdef HAVE_ZSTD
+ &zstd_encoding,
+#endif
NULL
};
@@ -852,8 +852,8 @@ static const struct content_encoding * const encodings[] = {
char *Curl_all_content_encodings(void)
{
size_t len = 0;
- const struct content_encoding * const *cep;
- const struct content_encoding *ce;
+ const struct content_encoding * const *cep;
+ const struct content_encoding *ce;
char *ace;
for(cep = encodings; *cep; cep++) {
@@ -886,14 +886,14 @@ char *Curl_all_content_encodings(void)
/* Real client writer: no downstream. */
static CURLcode client_init_writer(struct connectdata *conn,
- struct contenc_writer *writer)
+ struct contenc_writer *writer)
{
(void) conn;
return writer->downstream? CURLE_WRITE_ERROR: CURLE_OK;
}
static CURLcode client_unencode_write(struct connectdata *conn,
- struct contenc_writer *writer,
+ struct contenc_writer *writer,
const char *buf, size_t nbytes)
{
struct Curl_easy *data = conn->data;
@@ -908,13 +908,13 @@ static CURLcode client_unencode_write(struct connectdata *conn,
}
static void client_close_writer(struct connectdata *conn,
- struct contenc_writer *writer)
+ struct contenc_writer *writer)
{
(void) conn;
(void) writer;
}
-static const struct content_encoding client_encoding = {
+static const struct content_encoding client_encoding = {
NULL,
NULL,
client_init_writer,
@@ -926,14 +926,14 @@ static const struct content_encoding client_encoding = {
/* Deferred error dummy writer. */
static CURLcode error_init_writer(struct connectdata *conn,
- struct contenc_writer *writer)
+ struct contenc_writer *writer)
{
(void) conn;
return writer->downstream? CURLE_OK: CURLE_WRITE_ERROR;
}
static CURLcode error_unencode_write(struct connectdata *conn,
- struct contenc_writer *writer,
+ struct contenc_writer *writer,
const char *buf, size_t nbytes)
{
char *all = Curl_all_content_encodings();
@@ -951,13 +951,13 @@ static CURLcode error_unencode_write(struct connectdata *conn,
}
static void error_close_writer(struct connectdata *conn,
- struct contenc_writer *writer)
+ struct contenc_writer *writer)
{
(void) conn;
(void) writer;
}
-static const struct content_encoding error_encoding = {
+static const struct content_encoding error_encoding = {
NULL,
NULL,
error_init_writer,
@@ -967,13 +967,13 @@ static const struct content_encoding error_encoding = {
};
/* Create an unencoding writer stage using the given handler. */
-static struct contenc_writer *
-new_unencoding_writer(struct connectdata *conn,
- const struct content_encoding *handler,
- struct contenc_writer *downstream)
+static struct contenc_writer *
+new_unencoding_writer(struct connectdata *conn,
+ const struct content_encoding *handler,
+ struct contenc_writer *downstream)
{
- size_t sz = offsetof(struct contenc_writer, params) + handler->paramsize;
- struct contenc_writer *writer = (struct contenc_writer *)calloc(1, sz);
+ size_t sz = offsetof(struct contenc_writer, params) + handler->paramsize;
+ struct contenc_writer *writer = (struct contenc_writer *)calloc(1, sz);
if(writer) {
writer->handler = handler;
@@ -988,8 +988,8 @@ new_unencoding_writer(struct connectdata *conn,
}
/* Write data using an unencoding writer stack. */
-CURLcode Curl_unencode_write(struct connectdata *conn,
- struct contenc_writer *writer,
+CURLcode Curl_unencode_write(struct connectdata *conn,
+ struct contenc_writer *writer,
const char *buf, size_t nbytes)
{
if(!nbytes)
@@ -1002,7 +1002,7 @@ void Curl_unencode_cleanup(struct connectdata *conn)
{
struct Curl_easy *data = conn->data;
struct SingleRequest *k = &data->req;
- struct contenc_writer *writer = k->writer_stack;
+ struct contenc_writer *writer = k->writer_stack;
while(writer) {
k->writer_stack = writer->downstream;
@@ -1013,13 +1013,13 @@ void Curl_unencode_cleanup(struct connectdata *conn)
}
/* Find the content encoding by name. */
-static const struct content_encoding *find_encoding(const char *name,
- size_t len)
+static const struct content_encoding *find_encoding(const char *name,
+ size_t len)
{
- const struct content_encoding * const *cep;
+ const struct content_encoding * const *cep;
for(cep = encodings; *cep; cep++) {
- const struct content_encoding *ce = *cep;
+ const struct content_encoding *ce = *cep;
if((strncasecompare(name, ce->name, len) && !ce->name[len]) ||
(ce->alias && strncasecompare(name, ce->alias, len) && !ce->alias[len]))
return ce;
@@ -1055,8 +1055,8 @@ CURLcode Curl_build_unencoding_stack(struct connectdata *conn,
Curl_httpchunk_init(conn); /* init our chunky engine. */
}
else if(namelen) {
- const struct content_encoding *encoding = find_encoding(name, namelen);
- struct contenc_writer *writer;
+ const struct content_encoding *encoding = find_encoding(name, namelen);
+ struct contenc_writer *writer;
if(!k->writer_stack) {
k->writer_stack = new_unencoding_writer(conn, &client_encoding, NULL);
@@ -1090,8 +1090,8 @@ CURLcode Curl_build_unencoding_stack(struct connectdata *conn,
return CURLE_NOT_BUILT_IN;
}
-CURLcode Curl_unencode_write(struct connectdata *conn,
- struct contenc_writer *writer,
+CURLcode Curl_unencode_write(struct connectdata *conn,
+ struct contenc_writer *writer,
const char *buf, size_t nbytes)
{
(void) conn;