aboutsummaryrefslogtreecommitdiff
path: root/src/examples/http_compression.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/examples/http_compression.c')
-rw-r--r--src/examples/http_compression.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/examples/http_compression.c b/src/examples/http_compression.c
index 0f532cf0..244266ef 100644
--- a/src/examples/http_compression.c
+++ b/src/examples/http_compression.c
@@ -1,6 +1,7 @@
1/* 1/*
2 This file is part of libmicrohttpd 2 This file is part of libmicrohttpd
3 Copyright (C) 2019 Christian Grothoff (and other contributing authors) 3 Copyright (C) 2019 Christian Grothoff (and other contributing authors)
4 Copyright (C) 2019-2022 Evgeny Grin (Karlson2k)
4 5
5 This library is free software; you can redistribute it and/or 6 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public 7 modify it under the terms of the GNU Lesser General Public
@@ -20,6 +21,7 @@
20 * @file http_compression.c 21 * @file http_compression.c
21 * @brief minimal example for how to compress HTTP response 22 * @brief minimal example for how to compress HTTP response
22 * @author Silvio Clecio (silvioprog) 23 * @author Silvio Clecio (silvioprog)
24 * @author Karlson2k (Evgeny Grin)
23 */ 25 */
24 26
25#include "platform.h" 27#include "platform.h"
@@ -68,14 +70,14 @@ body_compress (void **buf,
68 uLongf cbuf_size; 70 uLongf cbuf_size;
69 int ret; 71 int ret;
70 72
71 cbuf_size = compressBound (*buf_size); 73 cbuf_size = compressBound ((uLong) * buf_size);
72 cbuf = malloc (cbuf_size); 74 cbuf = malloc (cbuf_size);
73 if (NULL == cbuf) 75 if (NULL == cbuf)
74 return MHD_NO; 76 return MHD_NO;
75 ret = compress (cbuf, 77 ret = compress (cbuf,
76 &cbuf_size, 78 &cbuf_size,
77 (const Bytef *) *buf, 79 (const Bytef *) *buf,
78 *buf_size); 80 (uLong) * buf_size);
79 if ((Z_OK != ret) || 81 if ((Z_OK != ret) ||
80 (cbuf_size >= *buf_size)) 82 (cbuf_size >= *buf_size))
81 { 83 {
@@ -165,15 +167,18 @@ int
165main (int argc, char *const *argv) 167main (int argc, char *const *argv)
166{ 168{
167 struct MHD_Daemon *d; 169 struct MHD_Daemon *d;
170 unsigned int port;
168 171
169 if (argc != 2) 172 if ( (argc != 2) ||
173 (1 != sscanf (argv[1], "%u", &port)) ||
174 (65535 < port) )
170 { 175 {
171 printf ("%s PORT\n", argv[0]); 176 printf ("%s PORT\n", argv[0]);
172 return 1; 177 return 1;
173 } 178 }
174 d = MHD_start_daemon (MHD_USE_AUTO | MHD_USE_INTERNAL_POLLING_THREAD 179 d = MHD_start_daemon (MHD_USE_AUTO | MHD_USE_INTERNAL_POLLING_THREAD
175 | MHD_USE_ERROR_LOG, 180 | MHD_USE_ERROR_LOG,
176 atoi (argv[1]), NULL, NULL, 181 (uint16_t) port, NULL, NULL,
177 &ahc_echo, NULL, 182 &ahc_echo, NULL,
178 MHD_OPTION_END); 183 MHD_OPTION_END);
179 if (NULL == d) 184 if (NULL == d)