You've already forked mariadb-connector-c
mirror of
https://github.com/mariadb-corporation/mariadb-connector-c.git
synced 2025-08-08 14:02:17 +03:00
Added new API function mysql_get_info/mysql_get_infov which retrieves
global or connection dependent information: mysql_get_infov(MYSQL *mysql, enum mariadb_value value, void *arg, ...) the following value types are supported: MARIADB_CHARSET_ID (requires numeric 4th parameter) MARIADB_CHARSET_INFO (requires string 4th parameter) MARIADB_CHARSET_NAME MARIADB_CLIENT_ERRORS MARIADB_CLIENT_VERSION MARIADB_CLIENT_VERSION_ID MARIADB_CONNECTION_ASYNC_TIMEOUT MARIADB_CONNECTION_ASYNC_TIMEOUT_MS MARIADB_CONNECTION_HOST MARIADB_CONNECTION_INFO MARIADB_CONNECTION_PORT MARIADB_CONNECTION_PROTOCOL_VERSION_ID MARIADB_CONNECTION_PVIO_TYPE MARIADB_CONNECTION_SCHEMA MARIADB_CONNECTION_SERVER_TYPE MARIADB_CONNECTION_SERVER_VERSION MARIADB_CONNECTION_SERVER_VERSION_ID MARIADB_CONNECTION_SOCKET MARIADB_CONNECTION_SSL_CIPHER MARIADB_CONNECTION_SSL_VERSION MARIADB_CONNECTION_SSL_VERSION_ID MARIADB_CONNECTION_TYPE MARIADB_CONNECTION_UNIX_SOCKET MARIADB_CONNECTION_USER MARIADB_MAX_ALLOWED_PACKET MARIADB_NET_BUFFER_LENGTH MARIADB_CONNECTION prefix indicates that a valid connection handle has to be passed as first parameter.
This commit is contained in:
@@ -58,7 +58,7 @@ ENDIF()
|
||||
|
||||
FOREACH(API_TEST ${API_TESTS})
|
||||
ADD_EXECUTABLE(${API_TEST} ${API_TEST}.c)
|
||||
TARGET_LINK_LIBRARIES(${API_TEST} mytap mariadbclient)
|
||||
TARGET_LINK_LIBRARIES(${API_TEST} mytap libmariadb)
|
||||
ADD_TEST(${API_TEST} ${EXECUTABLE_OUTPUT_PATH}/${API_TEST})
|
||||
SET_TESTS_PROPERTIES(${API_TEST} PROPERTIES TIMEOUT 120)
|
||||
ENDFOREACH(API_TEST)
|
||||
|
@@ -34,7 +34,8 @@ my_bool skip_async= 0;
|
||||
|
||||
static int test_async(MYSQL *mysql)
|
||||
{
|
||||
int type= mariadb_get_connection_type(mysql);
|
||||
int type;
|
||||
mariadb_get_info(mysql, MARIADB_CONNECTION_PVIO_TYPE, &type);
|
||||
if (type > MARIADB_CONNECTION_TCP)
|
||||
{
|
||||
skip_async= 1;
|
||||
|
@@ -1021,11 +1021,74 @@ static int test_remote2(MYSQL *my)
|
||||
}
|
||||
#endif
|
||||
|
||||
static int test_get_info(MYSQL *mysql)
|
||||
{
|
||||
size_t sval;
|
||||
unsigned int ival;
|
||||
char *cval;
|
||||
int rc;
|
||||
MY_CHARSET_INFO cs;
|
||||
CHARSET_INFO *ci;
|
||||
char **errors;
|
||||
|
||||
rc= mariadb_get_infov(mysql, MARIADB_MAX_ALLOWED_PACKET, &sval);
|
||||
FAIL_IF(rc, "mysql_get_info failed");
|
||||
diag("max_allowed_packet: %d", sval);
|
||||
rc= mariadb_get_infov(mysql, MARIADB_NET_BUFFER_LENGTH, &sval);
|
||||
FAIL_IF(rc, "mysql_get_info failed");
|
||||
diag("net_buffer_length: %d", sval);
|
||||
rc= mariadb_get_infov(mysql, MARIADB_CLIENT_VERSION_ID, &sval);
|
||||
FAIL_IF(rc, "mysql_get_info failed");
|
||||
diag("client_version_id: %d", sval);
|
||||
rc= mariadb_get_infov(mysql, MARIADB_CONNECTION_SERVER_VERSION_ID, &sval);
|
||||
FAIL_IF(rc, "mysql_get_info failed");
|
||||
diag("server_version_id: %d", sval);
|
||||
rc= mariadb_get_infov(mysql, MARIADB_CHARSET_INFO, &cs);
|
||||
FAIL_IF(rc, "mysql_get_info failed");
|
||||
diag("charset name: %s", cs.csname);
|
||||
rc= mariadb_get_infov(mysql, MARIADB_CONNECTION_PVIO_TYPE, &ival);
|
||||
FAIL_IF(rc, "mysql_get_info failed");
|
||||
diag("connection type: %d", ival);
|
||||
rc= mariadb_get_infov(mysql, MARIADB_CONNECTION_PROTOCOL_VERSION_ID, &ival);
|
||||
FAIL_IF(rc, "mysql_get_info failed");
|
||||
diag("protocol_version: %d", ival);
|
||||
rc= mariadb_get_infov(mysql, MARIADB_CONNECTION_SERVER_TYPE, &cval);
|
||||
FAIL_IF(rc, "mysql_get_info failed");
|
||||
diag("server_type: %s", cval);
|
||||
rc= mariadb_get_infov(mysql, MARIADB_CONNECTION_SERVER_VERSION, &cval);
|
||||
FAIL_IF(rc, "mysql_get_info failed");
|
||||
diag("server_version: %s", cval);
|
||||
rc= mariadb_get_infov(mysql, MARIADB_CLIENT_VERSION, &cval);
|
||||
FAIL_IF(rc, "mysql_get_info failed");
|
||||
diag("client_version: %s", cval);
|
||||
rc= mariadb_get_infov(mysql, MARIADB_CHARSET_NAME, &ci, "utf8");
|
||||
FAIL_IF(rc, "mysql_get_info failed");
|
||||
diag("charset_name: %s", ci->csname);
|
||||
diag("charset_nr: %d", ci->nr);
|
||||
rc= mariadb_get_infov(mysql, MARIADB_CHARSET_ID, &ci, 63);
|
||||
FAIL_IF(rc, "mysql_get_info failed");
|
||||
diag("charset_name: %s", ci->csname);
|
||||
rc= mariadb_get_infov(mysql, MARIADB_CLIENT_ERRORS, &errors);
|
||||
FAIL_IF(rc, "mysql_get_info failed");
|
||||
diag("error[0]: %s", errors[0]);
|
||||
rc= mysql_query(mysql, "DROP TABLE IF exists t1");
|
||||
check_mysql_rc(rc, mysql);
|
||||
rc= mysql_query(mysql, "CREATE TABLE t1 (a int)");
|
||||
check_mysql_rc(rc, mysql);
|
||||
rc= mysql_query(mysql, "INSERT INTO t1 VALUES (1),(2)");
|
||||
check_mysql_rc(rc, mysql);
|
||||
rc= mariadb_get_infov(mysql, MARIADB_CONNECTION_INFO, &cval);
|
||||
FAIL_IF(rc, "mysql_get_info failed");
|
||||
diag("mariadb_info: %s", cval);
|
||||
return OK;
|
||||
}
|
||||
|
||||
struct my_tests_st my_tests[] = {
|
||||
#ifdef HAVE_REMOTEIO
|
||||
{"test_remote1", test_remote1, TEST_CONNECTION_NEW, 0, NULL, NULL},
|
||||
{"test_remote2", test_remote2, TEST_CONNECTION_NEW, 0, NULL, NULL},
|
||||
#endif
|
||||
{"test_get_info", test_get_info, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
|
||||
{"test_conc117", test_conc117, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
|
||||
{"test_conc_114", test_conc_114, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
|
||||
{"test_connect_attrs", test_connect_attrs, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
|
||||
|
@@ -51,10 +51,16 @@ static int check_cipher(MYSQL *mysql)
|
||||
char *cipher= (char *)mysql_get_ssl_cipher(mysql);
|
||||
if (!cipher)
|
||||
return 1;
|
||||
diag("cipher: %s", cipher);
|
||||
|
||||
#ifdef HAVE_GNUTLS
|
||||
return strcmp(cipher, "AES-128-GCM");
|
||||
{
|
||||
return strcmp(cipher, "AES-128-GCM");
|
||||
}
|
||||
#elif HAVE_OPENSSL
|
||||
return strcmp(cipher, "DHE-RSA-AES256-SHA");
|
||||
if (!strcmp(cipher, "DHE-RSA-AES256-SHA") ||
|
||||
!strcmp(cipher, "DHE-RSA-AES256-GCM-SHA384"))
|
||||
return 0;
|
||||
#elif HAVE_SCHANNEL
|
||||
return strcmp(cipher, "CALG_AES_256");
|
||||
#endif
|
||||
@@ -107,6 +113,14 @@ static int test_ssl(MYSQL *mysql)
|
||||
}
|
||||
mysql_free_result(res);
|
||||
|
||||
#ifdef HAVE_GNUTLS
|
||||
diag("SSL library: GNUTLS");
|
||||
#elif HAVE_OPENSSL
|
||||
diag("SSL library: OPENSSL");
|
||||
#elif HAVE_SCHANNEL
|
||||
diag("SSL library: SCHANNEL");
|
||||
#endif
|
||||
|
||||
sslhost[0]= 0;
|
||||
|
||||
if (!skip_ssl)
|
||||
@@ -129,6 +143,9 @@ static int test_ssl(MYSQL *mysql)
|
||||
static int test_ssl_cipher(MYSQL *unused)
|
||||
{
|
||||
MYSQL *my;
|
||||
MYSQL_RES *res;
|
||||
MYSQL_ROW row;
|
||||
int rc;
|
||||
|
||||
if (check_skip_ssl())
|
||||
return SKIP;
|
||||
@@ -141,6 +158,14 @@ static int test_ssl_cipher(MYSQL *unused)
|
||||
FAIL_IF(!mysql_real_connect(my, hostname, ssluser, sslpw, schema,
|
||||
port, socketname, 0), mysql_error(my));
|
||||
|
||||
rc= mysql_query(my, "SHOW session status like 'Ssl_version'");
|
||||
check_mysql_rc(rc, my);
|
||||
res= mysql_store_result(my);
|
||||
row= mysql_fetch_row(res);
|
||||
diag("%s: %s", row[0], row[1]);
|
||||
diag("cipher: %s", mysql_get_ssl_cipher(my));
|
||||
mysql_free_result(res);
|
||||
|
||||
FAIL_IF(check_cipher(my) != 0, "Invalid cipher");
|
||||
mysql_close(my);
|
||||
return OK;
|
||||
@@ -747,7 +772,33 @@ static int test_ssl_fp_list(MYSQL *unused)
|
||||
return OK;
|
||||
}
|
||||
|
||||
static int test_ssl_version(MYSQL *mysql)
|
||||
{
|
||||
unsigned int iversion;
|
||||
char *version;
|
||||
MYSQL *my;
|
||||
|
||||
if (check_skip_ssl())
|
||||
return SKIP;
|
||||
|
||||
my= mysql_init(NULL);
|
||||
FAIL_IF(!my, "mysql_init() failed");
|
||||
|
||||
mysql_ssl_set(my,0, 0, "@CMAKE_SOURCE_DIR@/unittest/libmariadb/certs/ca-cert.pem", 0, 0);
|
||||
FAIL_IF(!mysql_real_connect(my, hostname, ssluser, sslpw, schema,
|
||||
port, socketname, 0), mysql_error(my));
|
||||
|
||||
diag("cipher: %s", mysql_get_ssl_cipher(my));
|
||||
mariadb_get_infov(my, MARIADB_CONNECTION_SSL_VERSION_ID, &iversion);
|
||||
diag("protocol: %d", iversion);
|
||||
mariadb_get_infov(my, MARIADB_CONNECTION_SSL_VERSION, &version);
|
||||
diag("protocol: %s", version);
|
||||
|
||||
mysql_close(my);
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
struct my_tests_st my_tests[] = {
|
||||
{"test_ssl", test_ssl, TEST_CONNECTION_NEW, 0, NULL, NULL},
|
||||
@@ -766,6 +817,7 @@ struct my_tests_st my_tests[] = {
|
||||
{"test_ssl_cipher", test_ssl_cipher, TEST_CONNECTION_NONE, 0, NULL, NULL},
|
||||
{"test_multi_ssl_connections", test_multi_ssl_connections, TEST_CONNECTION_NONE, 0, NULL, NULL},
|
||||
{"test_conc_102", test_conc_102, TEST_CONNECTION_NEW, 0, NULL, NULL},
|
||||
{"test_ssl_version", test_ssl_version, TEST_CONNECTION_NEW, 0, NULL, NULL},
|
||||
{"test_ssl_threads", test_ssl_threads, TEST_CONNECTION_NEW, 0, NULL, NULL},
|
||||
#ifndef HAVE_SCHANNEL
|
||||
{"test_password_protected", test_password_protected, TEST_CONNECTION_NEW, 0, NULL, NULL},
|
||||
|
Reference in New Issue
Block a user