diff --git a/include/ma_common.h b/include/ma_common.h index b88ef8a9..74c9584c 100644 --- a/include/ma_common.h +++ b/include/ma_common.h @@ -89,6 +89,7 @@ struct st_mysql_options_extension { void *status_data; my_bool tls_allow_invalid_server_cert; int (*tls_verification_callback)(MARIADB_TLS *ctls, unsigned int flags); + unsigned char zstd_compression_level; }; typedef struct st_connection_handler diff --git a/include/mysql.h b/include/mysql.h index fdf6d1ba..efad78a5 100644 --- a/include/mysql.h +++ b/include/mysql.h @@ -224,6 +224,7 @@ extern const char *SQLSTATE_UNKNOWN; MYSQL_OPT_MAX_ALLOWED_PACKET, MYSQL_OPT_NET_BUFFER_LENGTH, MYSQL_OPT_TLS_VERSION, + MYSQL_OPT_ZSTD_COMPRESSION_LEVEL, /* MariaDB specific */ MYSQL_PROGRESS_CALLBACK=5999, diff --git a/libmariadb/mariadb_lib.c b/libmariadb/mariadb_lib.c index 68af6485..9d35ff78 100644 --- a/libmariadb/mariadb_lib.c +++ b/libmariadb/mariadb_lib.c @@ -711,6 +711,7 @@ struct st_default_options mariadb_defaults[] = {{MYSQL_OPT_SSL_ENFORCE}, MARIADB_OPTION_BOOL, "tls-enforce"}, {{MYSQL_OPT_SSL_VERIFY_SERVER_CERT}, MARIADB_OPTION_BOOL,"tls-verify-peer"}, {{MARIADB_OPT_RESTRICTED_AUTH}, MARIADB_OPTION_STR, "restricted-auth"}, + {{MYSQL_OPT_ZSTD_COMPRESSION_LEVEL}, MARIADB_OPTION_INT, "zstd-compression-level"}, {{0}, 0, NULL} }; @@ -3872,6 +3873,9 @@ mysql_optionsv(MYSQL *mysql,enum mysql_option option, ...) OPT_SET_EXTENDED_VALUE(&mysql->options, tls_verification_callback, arg1); } break; + case MYSQL_OPT_ZSTD_COMPRESSION_LEVEL: + OPT_SET_EXTENDED_VALUE(&mysql->options, zstd_compression_level, *((unsigned char *)arg1)); + break; default: va_end(ap); SET_CLIENT_ERROR(mysql, CR_NOT_IMPLEMENTED, SQLSTATE_UNKNOWN, 0); @@ -3898,6 +3902,9 @@ mysql_get_optionv(MYSQL *mysql, enum mysql_option option, void *arg, ...) case MYSQL_OPT_COMPRESS: *((my_bool *)arg)= mysql->options.compress; break; + case MYSQL_OPT_ZSTD_COMPRESSION_LEVEL: + *((unsigned char *)arg)= mysql->options.extension->zstd_compression_level; + break; case MYSQL_OPT_NAMED_PIPE: *((my_bool *)arg)= mysql->options.named_pipe; break; diff --git a/plugins/auth/my_auth.c b/plugins/auth/my_auth.c index 545ff303..6339f0dd 100644 --- a/plugins/auth/my_auth.c +++ b/plugins/auth/my_auth.c @@ -508,7 +508,14 @@ static int send_client_reply_packet(MCPVIO_EXT *mpvio, */ if (mysql->client_flag & CLIENT_ZSTD_COMPRESSION) { - *end++= 3; + uchar compression_level= 3; + if (mysql->options.extension && + mysql->options.extension->zstd_compression_level >= 1 && + mysql->options.extension->zstd_compression_level <= 20) + { + compression_level= mysql->options.extension->zstd_compression_level; + } + *end++= compression_level; } /* Write authentication package */ diff --git a/unittest/libmariadb/misc.c b/unittest/libmariadb/misc.c index cf13f94d..5a947dc2 100644 --- a/unittest/libmariadb/misc.c +++ b/unittest/libmariadb/misc.c @@ -1705,8 +1705,24 @@ static int test_null_handles(MYSQL *mysql __attribute__((unused))) } +static int test_comp_level(MYSQL *my __attribute__((unused))) +{ + unsigned char clevel= 5; + unsigned char clevel1= 0; + MYSQL *mysql= mysql_init(NULL); + + mysql_optionsv(mysql, MYSQL_OPT_ZSTD_COMPRESSION_LEVEL, &clevel); + mysql_get_optionv(mysql, MYSQL_OPT_ZSTD_COMPRESSION_LEVEL, &clevel1); + + FAIL_IF(clevel != clevel1, "Different compression levels"); + mysql_close(mysql); + + return OK; +} + struct my_tests_st my_tests[] = { {"test_disable_tls1_0", test_disable_tls1_0, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_comp_level", test_comp_level, TEST_CONNECTION_NONE, 0, NULL, NULL}, {"test_ext_field_attr", test_ext_field_attr, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, {"test_conc533", test_conc533, TEST_CONNECTION_NEW, 0, NULL, NULL}, {"test_conc163", test_conc163, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},