mirror of
https://github.com/weechat/weechat.git
synced 2026-07-10 03:33:12 +02:00
core: make zstd dependency optional (closes #2024)
This commit is contained in:
@@ -91,7 +91,9 @@ include_directories(${GNUTLS_INCLUDE_PATH})
|
||||
|
||||
include_directories(${CURL_INCLUDE_DIRS})
|
||||
|
||||
include_directories(${ZSTD_INCLUDE_DIRS})
|
||||
if(ENABLE_ZSTD)
|
||||
include_directories(${ZSTD_INCLUDE_DIRS})
|
||||
endif()
|
||||
|
||||
include_directories("${CMAKE_BINARY_DIR}")
|
||||
add_library(weechat_core STATIC ${LIB_CORE_SRC})
|
||||
|
||||
@@ -33,7 +33,9 @@
|
||||
#include <gcrypt.h>
|
||||
#include <curl/curl.h>
|
||||
#include <zlib.h>
|
||||
#ifdef HAVE_ZSTD
|
||||
#include <zstd.h>
|
||||
#endif
|
||||
|
||||
#include <gnutls/gnutls.h>
|
||||
|
||||
@@ -683,11 +685,13 @@ debug_libs_cb (const void *pointer, void *data,
|
||||
gui_chat_printf (NULL, " zlib: (?)");
|
||||
#endif /* ZLIB_VERSION */
|
||||
|
||||
#ifdef HAVE_ZSTD
|
||||
/* display zstd version */
|
||||
gui_chat_printf (NULL, " zstd: %d.%d.%d",
|
||||
ZSTD_VERSION_MAJOR,
|
||||
ZSTD_VERSION_MINOR,
|
||||
ZSTD_VERSION_RELEASE);
|
||||
#endif /* HAVE_ZSTD */
|
||||
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
+12
-1
@@ -45,7 +45,9 @@
|
||||
#include <dirent.h>
|
||||
#include <ftw.h>
|
||||
#include <zlib.h>
|
||||
#ifdef HAVE_ZSTD
|
||||
#include <zstd.h>
|
||||
#endif
|
||||
|
||||
#include "weechat.h"
|
||||
#include "wee-config.h"
|
||||
@@ -1135,6 +1137,7 @@ int
|
||||
dir_file_compress_zstd (const char *from, const char *to,
|
||||
int compression_level)
|
||||
{
|
||||
#ifdef HAVE_ZSTD
|
||||
FILE *source, *dest;
|
||||
void *buffer_in, *buffer_out;
|
||||
size_t buffer_in_size, buffer_out_size, num_read, remaining;
|
||||
@@ -1297,6 +1300,14 @@ end:
|
||||
fclose (dest);
|
||||
|
||||
return rc;
|
||||
#else
|
||||
/* make C compiler happy */
|
||||
(void) from;
|
||||
(void) to;
|
||||
(void) compression_level;
|
||||
|
||||
return 0;
|
||||
#endif /* HAVE_ZSTD */
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1306,7 +1317,7 @@ end:
|
||||
*
|
||||
* Supported values for parameter "compressor":
|
||||
* - "gzip": gzip compression (via zlib)
|
||||
* - "zstd": zstandard compression
|
||||
* - "zstd": zstandard compression (it must be enabled at build time)
|
||||
*
|
||||
* Parameter "compression_level" is the compression level as percentage:
|
||||
* from 1 (fast, low compression) to 100 (slow, best compression).
|
||||
|
||||
@@ -48,7 +48,10 @@ list(APPEND EXTRA_LIBS "m")
|
||||
list(APPEND EXTRA_LIBS ${CURL_LIBRARIES})
|
||||
|
||||
list(APPEND EXTRA_LIBS ${ZLIB_LIBRARY})
|
||||
list(APPEND EXTRA_LIBS ${LIBZSTD_LDFLAGS})
|
||||
|
||||
if(ENABLE_ZSTD)
|
||||
list(APPEND EXTRA_LIBS ${LIBZSTD_LDFLAGS})
|
||||
endif()
|
||||
|
||||
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
||||
# link with resolv lib on macOS
|
||||
|
||||
@@ -375,6 +375,7 @@ logger_buffer_compress_file (struct t_logger_buffer *logger_buffer)
|
||||
unlink (filename);
|
||||
}
|
||||
break;
|
||||
#ifdef HAVE_ZSTD
|
||||
case LOGGER_BUFFER_COMPRESSION_ZSTD:
|
||||
if (weechat_file_compress (filename, new_filename,
|
||||
"zstd", compression_level))
|
||||
@@ -382,6 +383,7 @@ logger_buffer_compress_file (struct t_logger_buffer *logger_buffer)
|
||||
unlink (filename);
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -477,6 +479,12 @@ logger_buffer_rotate (struct t_logger_buffer *logger_buffer)
|
||||
|
||||
compression_type = weechat_config_enum (
|
||||
logger_config_file_rotation_compression_type);
|
||||
|
||||
#ifndef HAVE_ZSTD
|
||||
if (compression_type == LOGGER_BUFFER_COMPRESSION_ZSTD)
|
||||
compression_type = LOGGER_BUFFER_COMPRESSION_NONE;
|
||||
#endif
|
||||
|
||||
ptr_extension = logger_buffer_compression_extension[compression_type];
|
||||
|
||||
/* find the highest existing extension index */
|
||||
|
||||
@@ -93,6 +93,32 @@ logger_config_change_file_option_restart_log (const void *pointer, void *data,
|
||||
logger_buffer_adjust_log_filenames ();
|
||||
}
|
||||
|
||||
/*
|
||||
* Callback for changes on compression type option.
|
||||
*/
|
||||
|
||||
void
|
||||
logger_config_change_file_rotation_comp_type (const void *pointer,
|
||||
void *data,
|
||||
struct t_config_option *option)
|
||||
{
|
||||
/* make C compiler happy */
|
||||
(void) pointer;
|
||||
(void) data;
|
||||
(void) option;
|
||||
|
||||
#ifndef HAVE_ZSTD
|
||||
if (weechat_config_enum (option) == LOGGER_BUFFER_COMPRESSION_ZSTD)
|
||||
{
|
||||
weechat_printf (NULL,
|
||||
_("%s%s: zstd compression is not available, "
|
||||
"logger files will not be compressed"),
|
||||
weechat_prefix ("error"),
|
||||
LOGGER_PLUGIN_NAME);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* Callback for changes on option "logger.file.color_lines".
|
||||
*/
|
||||
@@ -666,7 +692,9 @@ logger_config_init ()
|
||||
"new type (or decompress files), then change the option in "
|
||||
"logger.conf, then load the logger plugin"),
|
||||
"none|gzip|zstd", 0, 0, "none", NULL, 0,
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
|
||||
NULL, NULL, NULL,
|
||||
&logger_config_change_file_rotation_comp_type, NULL, NULL,
|
||||
NULL, NULL, NULL);
|
||||
logger_config_file_rotation_size_max = weechat_config_new_option (
|
||||
logger_config_file, logger_config_section_file,
|
||||
"rotation_size_max", "string",
|
||||
|
||||
@@ -50,8 +50,10 @@ list(APPEND LINK_LIBS ${GCRYPT_LDFLAGS})
|
||||
|
||||
list(APPEND LINK_LIBS ${ZLIB_LIBRARY})
|
||||
|
||||
include_directories(${ZSTD_INCLUDE_DIRS})
|
||||
list(APPEND LINK_LIBS ${LIBZSTD_LDFLAGS})
|
||||
if(ENABLE_ZSTD)
|
||||
include_directories(${ZSTD_INCLUDE_DIRS})
|
||||
list(APPEND LINK_LIBS ${LIBZSTD_LDFLAGS})
|
||||
endif()
|
||||
|
||||
target_link_libraries(relay ${LINK_LIBS} coverage_config)
|
||||
|
||||
|
||||
@@ -29,7 +29,9 @@
|
||||
#include <errno.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <zlib.h>
|
||||
#ifdef HAVE_ZSTD
|
||||
#include <zstd.h>
|
||||
#endif
|
||||
|
||||
#include "../../weechat-plugin.h"
|
||||
#include "../relay.h"
|
||||
@@ -1111,6 +1113,7 @@ int
|
||||
relay_weechat_msg_compress_zstd (struct t_relay_client *client,
|
||||
struct t_relay_weechat_msg *msg)
|
||||
{
|
||||
#ifdef HAVE_ZSTD
|
||||
char raw_message[1024];
|
||||
uint32_t size32;
|
||||
Bytef *dest;
|
||||
@@ -1169,6 +1172,13 @@ error:
|
||||
free (dest);
|
||||
|
||||
return rc;
|
||||
#else
|
||||
/* make C compiler happy */
|
||||
(void) client;
|
||||
(void) msg;
|
||||
|
||||
return 0;
|
||||
#endif /* HAVE_ZSTD */
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1190,10 +1200,12 @@ relay_weechat_msg_send (struct t_relay_client *client,
|
||||
if (relay_weechat_msg_compress_zlib (client, msg))
|
||||
return;
|
||||
break;
|
||||
#ifdef HAVE_ZSTD
|
||||
case RELAY_WEECHAT_COMPRESSION_ZSTD:
|
||||
if (relay_weechat_msg_compress_zstd (client, msg))
|
||||
return;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -40,8 +40,14 @@
|
||||
#include "../relay-raw.h"
|
||||
|
||||
|
||||
char *relay_weechat_compression_string[] = /* strings for compression */
|
||||
{ "off", "zlib", "zstd" };
|
||||
/* strings for compression */
|
||||
char *relay_weechat_compression_string[RELAY_WEECHAT_NUM_COMPRESSIONS] = {
|
||||
"off",
|
||||
"zlib",
|
||||
#ifdef HAVE_ZSTD
|
||||
"zstd",
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
|
||||
@@ -34,7 +34,9 @@ enum t_relay_weechat_compression
|
||||
{
|
||||
RELAY_WEECHAT_COMPRESSION_OFF = 0, /* no compression of binary objects */
|
||||
RELAY_WEECHAT_COMPRESSION_ZLIB, /* zlib compression */
|
||||
#ifdef HAVE_ZSTD
|
||||
RELAY_WEECHAT_COMPRESSION_ZSTD, /* Zstandard compression */
|
||||
#endif
|
||||
/* number of compressions */
|
||||
RELAY_WEECHAT_NUM_COMPRESSIONS,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user