From b4bf96ce4bddbd824cbab26041ae4257011157f1 Mon Sep 17 00:00:00 2001 From: Sandu Liviu Catalin Date: Tue, 21 Sep 2021 20:59:01 +0300 Subject: [PATCH] Add MariaDB Connector/C as a built-in alternative (v3.2.3). --- CMakeLists.txt | 2 + module/CMakeLists.txt | 9 +- vendor/CMakeLists.txt | 8 + vendor/MDBC/CMakeLists.txt | 517 ++ vendor/MDBC/COPYING.LIB | 502 ++ vendor/MDBC/README | 15 + vendor/MDBC/appveyor-download.bat | 16 + vendor/MDBC/appveyor.yml | 41 + vendor/MDBC/client/CMakeLists.txt | 17 + vendor/MDBC/client/ma_plugin_info.c | 211 + vendor/MDBC/cmake/COPYING-CMAKE-SCRIPTS | 22 + vendor/MDBC/cmake/CheckFunctions.cmake | 30 + vendor/MDBC/cmake/CheckIncludeFiles.cmake | 58 + vendor/MDBC/cmake/CheckTypes.cmake | 62 + vendor/MDBC/cmake/ConnectorName.cmake | 34 + vendor/MDBC/cmake/FindGSSAPI.cmake | 110 + vendor/MDBC/cmake/FindIconv.cmake | 82 + vendor/MDBC/cmake/SearchLibrary.cmake | 29 + vendor/MDBC/cmake/WindowsCache.cmake | 392 ++ vendor/MDBC/cmake/export.cmake | 30 + vendor/MDBC/cmake/install.cmake | 160 + vendor/MDBC/cmake/install_plugins.cmake | 20 + vendor/MDBC/cmake/libressl_version.c | 7 + vendor/MDBC/cmake/linux_x86_toolchain.cmake | 18 + vendor/MDBC/cmake/misc.cmake | 13 + vendor/MDBC/cmake/plugins.cmake | 94 + vendor/MDBC/cmake/sign.cmake | 20 + vendor/MDBC/cmake/symlink.cmake | 35 + vendor/MDBC/cmake/version_info.cmake | 44 + vendor/MDBC/include/CMakeLists.txt | 41 + vendor/MDBC/include/errmsg.h | 107 + vendor/MDBC/include/ma_common.h | 122 + vendor/MDBC/include/ma_config.h.in | 145 + vendor/MDBC/include/ma_context.h | 236 + vendor/MDBC/include/ma_crypt.h | 166 + vendor/MDBC/include/ma_global.h | 1094 ++++ vendor/MDBC/include/ma_hashtbl.h | 70 + vendor/MDBC/include/ma_list.h | 47 + vendor/MDBC/include/ma_priv.h | 60 + vendor/MDBC/include/ma_pthread.h | 34 + vendor/MDBC/include/ma_pvio.h | 139 + vendor/MDBC/include/ma_server_error.h | 2 + vendor/MDBC/include/ma_sha1.h | 42 + vendor/MDBC/include/ma_string.h | 55 + vendor/MDBC/include/ma_sys.h | 542 ++ vendor/MDBC/include/ma_tls.h | 161 + vendor/MDBC/include/mariadb/ma_io.h | 55 + vendor/MDBC/include/mariadb_async.h | 37 + vendor/MDBC/include/mariadb_com.h | 469 ++ vendor/MDBC/include/mariadb_ctype.h | 76 + vendor/MDBC/include/mariadb_dyncol.h | 259 + vendor/MDBC/include/mariadb_rpl.h | 305 + vendor/MDBC/include/mariadb_stmt.h | 298 + vendor/MDBC/include/mariadb_version.h.in | 44 + vendor/MDBC/include/mysql.h | 893 +++ vendor/MDBC/include/mysql/client_plugin.h | 244 + vendor/MDBC/include/mysql/plugin_auth.h | 107 + .../MDBC/include/mysql/plugin_auth_common.h | 110 + vendor/MDBC/include/mysqld_error.h | 1225 ++++ vendor/MDBC/libmariadb/CMakeLists.txt | 470 ++ vendor/MDBC/libmariadb/bmove_upp.c | 33 + vendor/MDBC/libmariadb/get_password.c | 172 + vendor/MDBC/libmariadb/ma_alloc.c | 193 + vendor/MDBC/libmariadb/ma_array.c | 172 + vendor/MDBC/libmariadb/ma_charset.c | 1482 +++++ vendor/MDBC/libmariadb/ma_client_plugin.c.in | 508 ++ vendor/MDBC/libmariadb/ma_compress.c | 90 + vendor/MDBC/libmariadb/ma_context.c | 726 +++ vendor/MDBC/libmariadb/ma_default.c | 370 ++ vendor/MDBC/libmariadb/ma_dtoa.c | 1924 ++++++ vendor/MDBC/libmariadb/ma_errmsg.c | 116 + vendor/MDBC/libmariadb/ma_hashtbl.c | 580 ++ vendor/MDBC/libmariadb/ma_init.c | 87 + vendor/MDBC/libmariadb/ma_io.c | 224 + vendor/MDBC/libmariadb/ma_list.c | 114 + vendor/MDBC/libmariadb/ma_ll2str.c | 70 + vendor/MDBC/libmariadb/ma_loaddata.c | 265 + vendor/MDBC/libmariadb/ma_net.c | 591 ++ vendor/MDBC/libmariadb/ma_password.c | 162 + vendor/MDBC/libmariadb/ma_pvio.c | 594 ++ vendor/MDBC/libmariadb/ma_sha1.c | 326 + vendor/MDBC/libmariadb/ma_stmt_codec.c | 1362 ++++ vendor/MDBC/libmariadb/ma_string.c | 163 + vendor/MDBC/libmariadb/ma_time.c | 65 + vendor/MDBC/libmariadb/ma_tls.c | 232 + vendor/MDBC/libmariadb/mariadb_async.c | 1946 ++++++ vendor/MDBC/libmariadb/mariadb_charset.c | 74 + vendor/MDBC/libmariadb/mariadb_dyncol.c | 4368 +++++++++++++ vendor/MDBC/libmariadb/mariadb_lib.c | 4522 ++++++++++++++ vendor/MDBC/libmariadb/mariadb_rpl.c | 513 ++ vendor/MDBC/libmariadb/mariadb_stmt.c | 2515 ++++++++ vendor/MDBC/libmariadb/secure/gnutls.c | 1463 +++++ vendor/MDBC/libmariadb/secure/gnutls_crypt.c | 77 + vendor/MDBC/libmariadb/secure/ma_schannel.c | 637 ++ vendor/MDBC/libmariadb/secure/ma_schannel.h | 87 + vendor/MDBC/libmariadb/secure/openssl.c | 797 +++ vendor/MDBC/libmariadb/secure/openssl_crypt.c | 88 + vendor/MDBC/libmariadb/secure/schannel.c | 562 ++ .../MDBC/libmariadb/secure/schannel_certs.c | 854 +++ .../MDBC/libmariadb/secure/schannel_certs.h | 53 + vendor/MDBC/libmariadb/secure/win_crypt.c | 103 + vendor/MDBC/libmariadb/win32_errmsg.c | 137 + vendor/MDBC/libmariadb/win32_errmsg.h | 2 + vendor/MDBC/man/CMakeLists.txt | 123 + vendor/MDBC/man/mariadb_cancel.3 | 36 + vendor/MDBC/man/mariadb_connection.3 | 29 + vendor/MDBC/man/mariadb_dyncol_check.3 | 32 + .../man/mariadb_dyncol_column_cmp_named.3 | 31 + vendor/MDBC/man/mariadb_dyncol_column_count.3 | 36 + .../man/mariadb_dyncol_create_many_named.3 | 51 + .../MDBC/man/mariadb_dyncol_create_many_num.3 | 51 + vendor/MDBC/man/mariadb_dyncol_exists_named.3 | 33 + vendor/MDBC/man/mariadb_dyncol_exists_num.3 | 33 + vendor/MDBC/man/mariadb_dyncol_free.3 | 30 + vendor/MDBC/man/mariadb_dyncol_list_named.3 | 43 + vendor/MDBC/man/mariadb_dyncol_list_num.3 | 43 + vendor/MDBC/man/mariadb_dyncol_unpack.3 | 50 + .../man/mariadb_dyncol_update_many_named.3 | 47 + .../MDBC/man/mariadb_dyncol_update_many_num.3 | 47 + vendor/MDBC/man/mariadb_get_infov.3 | 325 + vendor/MDBC/man/mariadb_reconnect.3 | 36 + vendor/MDBC/man/mariadb_rpl_close.3 | 31 + vendor/MDBC/man/mariadb_rpl_fetch.3 | 42 + vendor/MDBC/man/mariadb_rpl_get_optionsv.3 | 74 + vendor/MDBC/man/mariadb_rpl_open.3 | 29 + vendor/MDBC/man/mariadb_rpl_optionsv.3 | 75 + vendor/MDBC/man/mariadb_stmt_execute_direct.3 | 81 + vendor/MDBC/man/mariadb_stmt_fetch_fields.3 | 36 + vendor/MDBC/man/mysql_affected_rows.3 | 46 + vendor/MDBC/man/mysql_autocommit.3 | 82 + vendor/MDBC/man/mysql_change_user.3 | 62 + vendor/MDBC/man/mysql_close.3 | 28 + vendor/MDBC/man/mysql_commit.3 | 33 + vendor/MDBC/man/mysql_data_seek.3 | 39 + vendor/MDBC/man/mysql_errno.3 | 37 + vendor/MDBC/man/mysql_error.3 | 41 + vendor/MDBC/man/mysql_fetch_field.3 | 49 + vendor/MDBC/man/mysql_fetch_field_direct.3 | 36 + vendor/MDBC/man/mysql_fetch_fields.3 | 41 + vendor/MDBC/man/mysql_fetch_lengths.3 | 41 + vendor/MDBC/man/mysql_fetch_row.3 | 44 + vendor/MDBC/man/mysql_field_count.3 | 43 + vendor/MDBC/man/mysql_field_seek.3 | 43 + vendor/MDBC/man/mysql_field_tell.3 | 32 + vendor/MDBC/man/mysql_free_result.3 | 36 + .../MDBC/man/mysql_get_character_set_info.3 | 39 + vendor/MDBC/man/mysql_get_client_info.3 | 31 + vendor/MDBC/man/mysql_get_client_version.3 | 32 + vendor/MDBC/man/mysql_get_host_info.3 | 32 + vendor/MDBC/man/mysql_get_proto_info.3 | 33 + vendor/MDBC/man/mysql_get_server_info.3 | 37 + vendor/MDBC/man/mysql_get_server_version.3 | 34 + vendor/MDBC/man/mysql_get_socket.3 | 33 + vendor/MDBC/man/mysql_get_ssl_cipher.3 | 47 + vendor/MDBC/man/mysql_hex_string.3 | 41 + vendor/MDBC/man/mysql_info.3 | 76 + vendor/MDBC/man/mysql_init.3 | 39 + vendor/MDBC/man/mysql_kill.3 | 51 + vendor/MDBC/man/mysql_more_results.3 | 47 + vendor/MDBC/man/mysql_next_result.3 | 45 + vendor/MDBC/man/mysql_num_fields.3 | 31 + vendor/MDBC/man/mysql_num_rows.3 | 35 + vendor/MDBC/man/mysql_options.3 | 37 + vendor/MDBC/man/mysql_options4.3 | 38 + vendor/MDBC/man/mysql_optionsv.3 | 390 ++ vendor/MDBC/man/mysql_ping.3 | 44 + vendor/MDBC/man/mysql_query.3 | 56 + vendor/MDBC/man/mysql_read_query_result.3 | 39 + vendor/MDBC/man/mysql_real_connect.3 | 145 + vendor/MDBC/man/mysql_real_escape_string.3 | 49 + vendor/MDBC/man/mysql_real_query.3 | 50 + vendor/MDBC/man/mysql_refresh.3 | 92 + vendor/MDBC/man/mysql_reset_connection.3 | 48 + vendor/MDBC/man/mysql_rollback.3 | 34 + vendor/MDBC/man/mysql_row_seek.3 | 41 + vendor/MDBC/man/mysql_row_tell.3 | 34 + vendor/MDBC/man/mysql_select_db.3 | 84 + vendor/MDBC/man/mysql_send_query.3 | 52 + vendor/MDBC/man/mysql_server_end.3 | 33 + vendor/MDBC/man/mysql_server_init.3 | 38 + .../MDBC/man/mysql_session_track_get_first.3 | 74 + .../MDBC/man/mysql_session_track_get_next.3 | 62 + vendor/MDBC/man/mysql_set_character_set.3 | 251 + vendor/MDBC/man/mysql_set_server_option.3 | 56 + vendor/MDBC/man/mysql_shutdown.3 | 38 + vendor/MDBC/man/mysql_sqlstate.3 | 37 + vendor/MDBC/man/mysql_ssl_set.3 | 57 + vendor/MDBC/man/mysql_stat.3 | 35 + vendor/MDBC/man/mysql_stmt_affected_rows.3 | 42 + vendor/MDBC/man/mysql_stmt_attr_get.3 | 97 + vendor/MDBC/man/mysql_stmt_attr_set.3 | 131 + vendor/MDBC/man/mysql_stmt_bind_param.3 | 50 + vendor/MDBC/man/mysql_stmt_bind_result.3 | 45 + vendor/MDBC/man/mysql_stmt_close.3 | 39 + vendor/MDBC/man/mysql_stmt_data_seek.3 | 43 + vendor/MDBC/man/mysql_stmt_errno.3 | 38 + vendor/MDBC/man/mysql_stmt_error.3 | 40 + vendor/MDBC/man/mysql_stmt_execute.3 | 43 + vendor/MDBC/man/mysql_stmt_fetch.3 | 48 + vendor/MDBC/man/mysql_stmt_fetch_column.3 | 44 + vendor/MDBC/man/mysql_stmt_field_count.3 | 38 + vendor/MDBC/man/mysql_stmt_free_result.3 | 30 + vendor/MDBC/man/mysql_stmt_init.3 | 43 + vendor/MDBC/man/mysql_stmt_insert_id.3 | 36 + vendor/MDBC/man/mysql_stmt_more_results.3 | 39 + vendor/MDBC/man/mysql_stmt_next_result.3 | 42 + vendor/MDBC/man/mysql_stmt_num_rows.3 | 37 + vendor/MDBC/man/mysql_stmt_param_count.3 | 37 + vendor/MDBC/man/mysql_stmt_param_metadata.3 | 27 + vendor/MDBC/man/mysql_stmt_prepare.3 | 58 + vendor/MDBC/man/mysql_stmt_reset.3 | 44 + vendor/MDBC/man/mysql_stmt_result_metadata.3 | 50 + vendor/MDBC/man/mysql_stmt_row_seek.3 | 40 + vendor/MDBC/man/mysql_stmt_row_tell.3 | 37 + vendor/MDBC/man/mysql_stmt_send_long_data.3 | 51 + vendor/MDBC/man/mysql_stmt_sqlstate.3 | 36 + vendor/MDBC/man/mysql_stmt_store_result.3 | 38 + vendor/MDBC/man/mysql_stmt_warning_count.3 | 38 + vendor/MDBC/man/mysql_store_result.3 | 39 + vendor/MDBC/man/mysql_thread_end.3 | 36 + vendor/MDBC/man/mysql_thread_id.3 | 39 + vendor/MDBC/man/mysql_thread_init.3 | 41 + vendor/MDBC/man/mysql_use_result.3 | 46 + vendor/MDBC/man/mysql_warning_count.3 | 41 + vendor/MDBC/mariadb_config/CMakeLists.txt | 67 + vendor/MDBC/mariadb_config/libmariadb.pc.in | 20 + .../MDBC/mariadb_config/mariadb_config.c.in | 299 + vendor/MDBC/plugins/CMakeLists.txt | 9 + vendor/MDBC/plugins/auth/CMakeLists.txt | 132 + vendor/MDBC/plugins/auth/auth_gssapi_client.c | 121 + vendor/MDBC/plugins/auth/caching_sha2_pw.c | 486 ++ vendor/MDBC/plugins/auth/common.h | 4 + vendor/MDBC/plugins/auth/dialog.c | 222 + vendor/MDBC/plugins/auth/ed25519.c | 145 + vendor/MDBC/plugins/auth/gssapi_client.c | 131 + vendor/MDBC/plugins/auth/gssapi_errmsg.c | 79 + vendor/MDBC/plugins/auth/gssapi_errmsg.h | 29 + vendor/MDBC/plugins/auth/mariadb_cleartext.c | 76 + vendor/MDBC/plugins/auth/my_auth.c | 685 ++ vendor/MDBC/plugins/auth/old_password.c | 117 + vendor/MDBC/plugins/auth/ref10/api.h | 3 + vendor/MDBC/plugins/auth/ref10/base.h | 1344 ++++ vendor/MDBC/plugins/auth/ref10/base2.h | 40 + vendor/MDBC/plugins/auth/ref10/common.h | 23 + .../plugins/auth/ref10/crypto_hash_sha512.h | 7 + vendor/MDBC/plugins/auth/ref10/crypto_int32.h | 5 + vendor/MDBC/plugins/auth/ref10/crypto_int64.h | 5 + vendor/MDBC/plugins/auth/ref10/crypto_sign.h | 13 + .../MDBC/plugins/auth/ref10/crypto_uint32.h | 5 + .../MDBC/plugins/auth/ref10/crypto_uint64.h | 5 + .../MDBC/plugins/auth/ref10/crypto_verify.h | 1 + .../plugins/auth/ref10/crypto_verify_32.h | 2 + vendor/MDBC/plugins/auth/ref10/d.h | 1 + vendor/MDBC/plugins/auth/ref10/d2.h | 1 + vendor/MDBC/plugins/auth/ref10/fe.h | 56 + vendor/MDBC/plugins/auth/ref10/fe_0.c | 19 + vendor/MDBC/plugins/auth/ref10/fe_1.c | 19 + vendor/MDBC/plugins/auth/ref10/fe_add.c | 57 + vendor/MDBC/plugins/auth/ref10/fe_cmov.c | 63 + vendor/MDBC/plugins/auth/ref10/fe_copy.c | 29 + vendor/MDBC/plugins/auth/ref10/fe_frombytes.c | 73 + vendor/MDBC/plugins/auth/ref10/fe_invert.c | 14 + .../MDBC/plugins/auth/ref10/fe_isnegative.c | 16 + vendor/MDBC/plugins/auth/ref10/fe_isnonzero.c | 19 + vendor/MDBC/plugins/auth/ref10/fe_mul.c | 253 + vendor/MDBC/plugins/auth/ref10/fe_neg.c | 45 + vendor/MDBC/plugins/auth/ref10/fe_pow22523.c | 13 + vendor/MDBC/plugins/auth/ref10/fe_sq.c | 149 + vendor/MDBC/plugins/auth/ref10/fe_sq2.c | 160 + vendor/MDBC/plugins/auth/ref10/fe_sub.c | 57 + vendor/MDBC/plugins/auth/ref10/fe_tobytes.c | 119 + vendor/MDBC/plugins/auth/ref10/ge.h | 95 + vendor/MDBC/plugins/auth/ref10/ge_add.c | 11 + vendor/MDBC/plugins/auth/ref10/ge_add.h | 97 + .../plugins/auth/ref10/ge_double_scalarmult.c | 96 + vendor/MDBC/plugins/auth/ref10/ge_frombytes.c | 50 + vendor/MDBC/plugins/auth/ref10/ge_madd.c | 11 + vendor/MDBC/plugins/auth/ref10/ge_madd.h | 88 + vendor/MDBC/plugins/auth/ref10/ge_msub.c | 11 + vendor/MDBC/plugins/auth/ref10/ge_msub.h | 88 + .../MDBC/plugins/auth/ref10/ge_p1p1_to_p2.c | 12 + .../MDBC/plugins/auth/ref10/ge_p1p1_to_p3.c | 13 + vendor/MDBC/plugins/auth/ref10/ge_p2_0.c | 8 + vendor/MDBC/plugins/auth/ref10/ge_p2_dbl.c | 11 + vendor/MDBC/plugins/auth/ref10/ge_p2_dbl.h | 73 + vendor/MDBC/plugins/auth/ref10/ge_p3_0.c | 9 + vendor/MDBC/plugins/auth/ref10/ge_p3_dbl.c | 12 + .../MDBC/plugins/auth/ref10/ge_p3_to_cached.c | 17 + vendor/MDBC/plugins/auth/ref10/ge_p3_to_p2.c | 12 + .../MDBC/plugins/auth/ref10/ge_p3_tobytes.c | 14 + vendor/MDBC/plugins/auth/ref10/ge_precomp_0.c | 8 + .../plugins/auth/ref10/ge_scalarmult_base.c | 105 + vendor/MDBC/plugins/auth/ref10/ge_sub.c | 11 + vendor/MDBC/plugins/auth/ref10/ge_sub.h | 97 + vendor/MDBC/plugins/auth/ref10/ge_tobytes.c | 14 + vendor/MDBC/plugins/auth/ref10/keypair.c | 23 + vendor/MDBC/plugins/auth/ref10/open.c | 36 + vendor/MDBC/plugins/auth/ref10/pow22523.h | 168 + vendor/MDBC/plugins/auth/ref10/pow225521.h | 166 + vendor/MDBC/plugins/auth/ref10/sc.h | 15 + vendor/MDBC/plugins/auth/ref10/sc_muladd.c | 368 ++ vendor/MDBC/plugins/auth/ref10/sc_reduce.c | 275 + vendor/MDBC/plugins/auth/ref10/sign.c | 39 + vendor/MDBC/plugins/auth/ref10/sqrtm1.h | 1 + vendor/MDBC/plugins/auth/ref10/verify.c | 40 + vendor/MDBC/plugins/auth/server_plugin.h | 51 + vendor/MDBC/plugins/auth/sha256_pw.c | 358 ++ vendor/MDBC/plugins/auth/sspi_client.c | 184 + vendor/MDBC/plugins/auth/sspi_common.h | 38 + vendor/MDBC/plugins/auth/sspi_errmsg.c | 169 + vendor/MDBC/plugins/connection/CMakeLists.txt | 13 + vendor/MDBC/plugins/connection/replication.c | 357 ++ vendor/MDBC/plugins/io/CMakeLists.txt | 15 + vendor/MDBC/plugins/io/remote_io.c | 453 ++ vendor/MDBC/plugins/plugin.def | 2 + vendor/MDBC/plugins/pvio/CMakeLists.txt | 27 + vendor/MDBC/plugins/pvio/pvio_npipe.c | 359 ++ vendor/MDBC/plugins/pvio/pvio_plugin.def | 2 + vendor/MDBC/plugins/pvio/pvio_shmem.c | 469 ++ vendor/MDBC/plugins/pvio/pvio_socket.c | 1128 ++++ vendor/MDBC/plugins/trace/trace_example.c | 458 ++ vendor/MDBC/scripts/create_man | 54 + vendor/MDBC/travis.sh | 93 + .../MDBC/unittest/libmariadb/CMakeLists.txt | 67 + vendor/MDBC/unittest/libmariadb/async.c | 271 + vendor/MDBC/unittest/libmariadb/basic-t.c | 843 +++ vendor/MDBC/unittest/libmariadb/bulk1.c | 1100 ++++ vendor/MDBC/unittest/libmariadb/charset.c | 846 +++ vendor/MDBC/unittest/libmariadb/conc336.c | 53 + vendor/MDBC/unittest/libmariadb/connection.c | 1972 ++++++ vendor/MDBC/unittest/libmariadb/cursor.c | 1841 ++++++ vendor/MDBC/unittest/libmariadb/data.csv | 100 + vendor/MDBC/unittest/libmariadb/dyncol.c | 323 + vendor/MDBC/unittest/libmariadb/errors.c | 290 + .../MDBC/unittest/libmariadb/features-10_2.c | 249 + vendor/MDBC/unittest/libmariadb/fetch.c | 1003 +++ .../unittest/libmariadb/fingerprint.list.in | 4 + vendor/MDBC/unittest/libmariadb/getopt.c | 742 +++ vendor/MDBC/unittest/libmariadb/logs.c | 217 + vendor/MDBC/unittest/libmariadb/ma_getopt.c | 741 +++ vendor/MDBC/unittest/libmariadb/ma_getopt.h | 135 + vendor/MDBC/unittest/libmariadb/misc.c | 1666 +++++ vendor/MDBC/unittest/libmariadb/my_test.h | 711 +++ vendor/MDBC/unittest/libmariadb/performance.c | 76 + vendor/MDBC/unittest/libmariadb/ps.c | 5208 ++++++++++++++++ vendor/MDBC/unittest/libmariadb/ps_bugs.c | 5484 +++++++++++++++++ vendor/MDBC/unittest/libmariadb/ps_new.c | 511 ++ vendor/MDBC/unittest/libmariadb/result.c | 1102 ++++ vendor/MDBC/unittest/libmariadb/rpl_api.c | 74 + vendor/MDBC/unittest/libmariadb/sp.c | 91 + vendor/MDBC/unittest/libmariadb/ssl.c | 1424 +++++ vendor/MDBC/unittest/libmariadb/t_aurora.c | 164 + vendor/MDBC/unittest/libmariadb/t_conc173.c | 72 + vendor/MDBC/unittest/libmariadb/thread.c | 180 + vendor/MDBC/unittest/libmariadb/view.c | 697 +++ vendor/MDBC/unittest/mytap/CMakeLists.txt | 19 + vendor/MDBC/unittest/mytap/Doxyfile | 1156 ++++ vendor/MDBC/unittest/mytap/t/basic-t.c | 33 + vendor/MDBC/unittest/mytap/tap.c | 600 ++ vendor/MDBC/unittest/mytap/tap.h | 305 + vendor/MDBC/win-iconv/iconv.h | 14 + vendor/MDBC/win-iconv/mlang.h | 54 + vendor/MDBC/win-iconv/win_iconv.c | 2051 ++++++ vendor/MDBC/win/packaging/CMakeLists.txt | 105 + vendor/MDBC/win/packaging/WixUIBannerBmp.jpg | Bin 0 -> 7401 bytes vendor/MDBC/win/packaging/WixUIDialogBmp.jpg | Bin 0 -> 221242 bytes vendor/MDBC/win/packaging/license.rtf | 464 ++ .../win/packaging/mariadb-connector-c.xml.in | 79 + vendor/MDBC/win/resource.rc.in | 34 + vendor/POCO/CMakeLists.txt | 12 +- vendor/POCO/Data/CMakeLists.txt | 2 +- vendor/POCO/Data/MySQL/CMakeLists.txt | 14 +- 372 files changed, 90819 insertions(+), 11 deletions(-) create mode 100644 vendor/MDBC/CMakeLists.txt create mode 100644 vendor/MDBC/COPYING.LIB create mode 100644 vendor/MDBC/README create mode 100644 vendor/MDBC/appveyor-download.bat create mode 100644 vendor/MDBC/appveyor.yml create mode 100644 vendor/MDBC/client/CMakeLists.txt create mode 100644 vendor/MDBC/client/ma_plugin_info.c create mode 100644 vendor/MDBC/cmake/COPYING-CMAKE-SCRIPTS create mode 100644 vendor/MDBC/cmake/CheckFunctions.cmake create mode 100644 vendor/MDBC/cmake/CheckIncludeFiles.cmake create mode 100644 vendor/MDBC/cmake/CheckTypes.cmake create mode 100644 vendor/MDBC/cmake/ConnectorName.cmake create mode 100644 vendor/MDBC/cmake/FindGSSAPI.cmake create mode 100644 vendor/MDBC/cmake/FindIconv.cmake create mode 100644 vendor/MDBC/cmake/SearchLibrary.cmake create mode 100644 vendor/MDBC/cmake/WindowsCache.cmake create mode 100644 vendor/MDBC/cmake/export.cmake create mode 100644 vendor/MDBC/cmake/install.cmake create mode 100644 vendor/MDBC/cmake/install_plugins.cmake create mode 100644 vendor/MDBC/cmake/libressl_version.c create mode 100644 vendor/MDBC/cmake/linux_x86_toolchain.cmake create mode 100644 vendor/MDBC/cmake/misc.cmake create mode 100644 vendor/MDBC/cmake/plugins.cmake create mode 100644 vendor/MDBC/cmake/sign.cmake create mode 100644 vendor/MDBC/cmake/symlink.cmake create mode 100644 vendor/MDBC/cmake/version_info.cmake create mode 100644 vendor/MDBC/include/CMakeLists.txt create mode 100644 vendor/MDBC/include/errmsg.h create mode 100644 vendor/MDBC/include/ma_common.h create mode 100644 vendor/MDBC/include/ma_config.h.in create mode 100644 vendor/MDBC/include/ma_context.h create mode 100644 vendor/MDBC/include/ma_crypt.h create mode 100644 vendor/MDBC/include/ma_global.h create mode 100644 vendor/MDBC/include/ma_hashtbl.h create mode 100644 vendor/MDBC/include/ma_list.h create mode 100644 vendor/MDBC/include/ma_priv.h create mode 100644 vendor/MDBC/include/ma_pthread.h create mode 100644 vendor/MDBC/include/ma_pvio.h create mode 100644 vendor/MDBC/include/ma_server_error.h create mode 100644 vendor/MDBC/include/ma_sha1.h create mode 100644 vendor/MDBC/include/ma_string.h create mode 100644 vendor/MDBC/include/ma_sys.h create mode 100644 vendor/MDBC/include/ma_tls.h create mode 100644 vendor/MDBC/include/mariadb/ma_io.h create mode 100644 vendor/MDBC/include/mariadb_async.h create mode 100644 vendor/MDBC/include/mariadb_com.h create mode 100644 vendor/MDBC/include/mariadb_ctype.h create mode 100644 vendor/MDBC/include/mariadb_dyncol.h create mode 100644 vendor/MDBC/include/mariadb_rpl.h create mode 100644 vendor/MDBC/include/mariadb_stmt.h create mode 100644 vendor/MDBC/include/mariadb_version.h.in create mode 100644 vendor/MDBC/include/mysql.h create mode 100644 vendor/MDBC/include/mysql/client_plugin.h create mode 100644 vendor/MDBC/include/mysql/plugin_auth.h create mode 100644 vendor/MDBC/include/mysql/plugin_auth_common.h create mode 100644 vendor/MDBC/include/mysqld_error.h create mode 100644 vendor/MDBC/libmariadb/CMakeLists.txt create mode 100644 vendor/MDBC/libmariadb/bmove_upp.c create mode 100644 vendor/MDBC/libmariadb/get_password.c create mode 100644 vendor/MDBC/libmariadb/ma_alloc.c create mode 100644 vendor/MDBC/libmariadb/ma_array.c create mode 100644 vendor/MDBC/libmariadb/ma_charset.c create mode 100644 vendor/MDBC/libmariadb/ma_client_plugin.c.in create mode 100644 vendor/MDBC/libmariadb/ma_compress.c create mode 100644 vendor/MDBC/libmariadb/ma_context.c create mode 100644 vendor/MDBC/libmariadb/ma_default.c create mode 100644 vendor/MDBC/libmariadb/ma_dtoa.c create mode 100644 vendor/MDBC/libmariadb/ma_errmsg.c create mode 100644 vendor/MDBC/libmariadb/ma_hashtbl.c create mode 100644 vendor/MDBC/libmariadb/ma_init.c create mode 100644 vendor/MDBC/libmariadb/ma_io.c create mode 100644 vendor/MDBC/libmariadb/ma_list.c create mode 100644 vendor/MDBC/libmariadb/ma_ll2str.c create mode 100644 vendor/MDBC/libmariadb/ma_loaddata.c create mode 100644 vendor/MDBC/libmariadb/ma_net.c create mode 100644 vendor/MDBC/libmariadb/ma_password.c create mode 100644 vendor/MDBC/libmariadb/ma_pvio.c create mode 100644 vendor/MDBC/libmariadb/ma_sha1.c create mode 100644 vendor/MDBC/libmariadb/ma_stmt_codec.c create mode 100644 vendor/MDBC/libmariadb/ma_string.c create mode 100644 vendor/MDBC/libmariadb/ma_time.c create mode 100644 vendor/MDBC/libmariadb/ma_tls.c create mode 100644 vendor/MDBC/libmariadb/mariadb_async.c create mode 100644 vendor/MDBC/libmariadb/mariadb_charset.c create mode 100644 vendor/MDBC/libmariadb/mariadb_dyncol.c create mode 100644 vendor/MDBC/libmariadb/mariadb_lib.c create mode 100644 vendor/MDBC/libmariadb/mariadb_rpl.c create mode 100644 vendor/MDBC/libmariadb/mariadb_stmt.c create mode 100644 vendor/MDBC/libmariadb/secure/gnutls.c create mode 100644 vendor/MDBC/libmariadb/secure/gnutls_crypt.c create mode 100644 vendor/MDBC/libmariadb/secure/ma_schannel.c create mode 100644 vendor/MDBC/libmariadb/secure/ma_schannel.h create mode 100644 vendor/MDBC/libmariadb/secure/openssl.c create mode 100644 vendor/MDBC/libmariadb/secure/openssl_crypt.c create mode 100644 vendor/MDBC/libmariadb/secure/schannel.c create mode 100644 vendor/MDBC/libmariadb/secure/schannel_certs.c create mode 100644 vendor/MDBC/libmariadb/secure/schannel_certs.h create mode 100644 vendor/MDBC/libmariadb/secure/win_crypt.c create mode 100644 vendor/MDBC/libmariadb/win32_errmsg.c create mode 100644 vendor/MDBC/libmariadb/win32_errmsg.h create mode 100644 vendor/MDBC/man/CMakeLists.txt create mode 100644 vendor/MDBC/man/mariadb_cancel.3 create mode 100644 vendor/MDBC/man/mariadb_connection.3 create mode 100644 vendor/MDBC/man/mariadb_dyncol_check.3 create mode 100644 vendor/MDBC/man/mariadb_dyncol_column_cmp_named.3 create mode 100644 vendor/MDBC/man/mariadb_dyncol_column_count.3 create mode 100644 vendor/MDBC/man/mariadb_dyncol_create_many_named.3 create mode 100644 vendor/MDBC/man/mariadb_dyncol_create_many_num.3 create mode 100644 vendor/MDBC/man/mariadb_dyncol_exists_named.3 create mode 100644 vendor/MDBC/man/mariadb_dyncol_exists_num.3 create mode 100644 vendor/MDBC/man/mariadb_dyncol_free.3 create mode 100644 vendor/MDBC/man/mariadb_dyncol_list_named.3 create mode 100644 vendor/MDBC/man/mariadb_dyncol_list_num.3 create mode 100644 vendor/MDBC/man/mariadb_dyncol_unpack.3 create mode 100644 vendor/MDBC/man/mariadb_dyncol_update_many_named.3 create mode 100644 vendor/MDBC/man/mariadb_dyncol_update_many_num.3 create mode 100644 vendor/MDBC/man/mariadb_get_infov.3 create mode 100644 vendor/MDBC/man/mariadb_reconnect.3 create mode 100644 vendor/MDBC/man/mariadb_rpl_close.3 create mode 100644 vendor/MDBC/man/mariadb_rpl_fetch.3 create mode 100644 vendor/MDBC/man/mariadb_rpl_get_optionsv.3 create mode 100644 vendor/MDBC/man/mariadb_rpl_open.3 create mode 100644 vendor/MDBC/man/mariadb_rpl_optionsv.3 create mode 100644 vendor/MDBC/man/mariadb_stmt_execute_direct.3 create mode 100644 vendor/MDBC/man/mariadb_stmt_fetch_fields.3 create mode 100644 vendor/MDBC/man/mysql_affected_rows.3 create mode 100644 vendor/MDBC/man/mysql_autocommit.3 create mode 100644 vendor/MDBC/man/mysql_change_user.3 create mode 100644 vendor/MDBC/man/mysql_close.3 create mode 100644 vendor/MDBC/man/mysql_commit.3 create mode 100644 vendor/MDBC/man/mysql_data_seek.3 create mode 100644 vendor/MDBC/man/mysql_errno.3 create mode 100644 vendor/MDBC/man/mysql_error.3 create mode 100644 vendor/MDBC/man/mysql_fetch_field.3 create mode 100644 vendor/MDBC/man/mysql_fetch_field_direct.3 create mode 100644 vendor/MDBC/man/mysql_fetch_fields.3 create mode 100644 vendor/MDBC/man/mysql_fetch_lengths.3 create mode 100644 vendor/MDBC/man/mysql_fetch_row.3 create mode 100644 vendor/MDBC/man/mysql_field_count.3 create mode 100644 vendor/MDBC/man/mysql_field_seek.3 create mode 100644 vendor/MDBC/man/mysql_field_tell.3 create mode 100644 vendor/MDBC/man/mysql_free_result.3 create mode 100644 vendor/MDBC/man/mysql_get_character_set_info.3 create mode 100644 vendor/MDBC/man/mysql_get_client_info.3 create mode 100644 vendor/MDBC/man/mysql_get_client_version.3 create mode 100644 vendor/MDBC/man/mysql_get_host_info.3 create mode 100644 vendor/MDBC/man/mysql_get_proto_info.3 create mode 100644 vendor/MDBC/man/mysql_get_server_info.3 create mode 100644 vendor/MDBC/man/mysql_get_server_version.3 create mode 100644 vendor/MDBC/man/mysql_get_socket.3 create mode 100644 vendor/MDBC/man/mysql_get_ssl_cipher.3 create mode 100644 vendor/MDBC/man/mysql_hex_string.3 create mode 100644 vendor/MDBC/man/mysql_info.3 create mode 100644 vendor/MDBC/man/mysql_init.3 create mode 100644 vendor/MDBC/man/mysql_kill.3 create mode 100644 vendor/MDBC/man/mysql_more_results.3 create mode 100644 vendor/MDBC/man/mysql_next_result.3 create mode 100644 vendor/MDBC/man/mysql_num_fields.3 create mode 100644 vendor/MDBC/man/mysql_num_rows.3 create mode 100644 vendor/MDBC/man/mysql_options.3 create mode 100644 vendor/MDBC/man/mysql_options4.3 create mode 100644 vendor/MDBC/man/mysql_optionsv.3 create mode 100644 vendor/MDBC/man/mysql_ping.3 create mode 100644 vendor/MDBC/man/mysql_query.3 create mode 100644 vendor/MDBC/man/mysql_read_query_result.3 create mode 100644 vendor/MDBC/man/mysql_real_connect.3 create mode 100644 vendor/MDBC/man/mysql_real_escape_string.3 create mode 100644 vendor/MDBC/man/mysql_real_query.3 create mode 100644 vendor/MDBC/man/mysql_refresh.3 create mode 100644 vendor/MDBC/man/mysql_reset_connection.3 create mode 100644 vendor/MDBC/man/mysql_rollback.3 create mode 100644 vendor/MDBC/man/mysql_row_seek.3 create mode 100644 vendor/MDBC/man/mysql_row_tell.3 create mode 100644 vendor/MDBC/man/mysql_select_db.3 create mode 100644 vendor/MDBC/man/mysql_send_query.3 create mode 100644 vendor/MDBC/man/mysql_server_end.3 create mode 100644 vendor/MDBC/man/mysql_server_init.3 create mode 100644 vendor/MDBC/man/mysql_session_track_get_first.3 create mode 100644 vendor/MDBC/man/mysql_session_track_get_next.3 create mode 100644 vendor/MDBC/man/mysql_set_character_set.3 create mode 100644 vendor/MDBC/man/mysql_set_server_option.3 create mode 100644 vendor/MDBC/man/mysql_shutdown.3 create mode 100644 vendor/MDBC/man/mysql_sqlstate.3 create mode 100644 vendor/MDBC/man/mysql_ssl_set.3 create mode 100644 vendor/MDBC/man/mysql_stat.3 create mode 100644 vendor/MDBC/man/mysql_stmt_affected_rows.3 create mode 100644 vendor/MDBC/man/mysql_stmt_attr_get.3 create mode 100644 vendor/MDBC/man/mysql_stmt_attr_set.3 create mode 100644 vendor/MDBC/man/mysql_stmt_bind_param.3 create mode 100644 vendor/MDBC/man/mysql_stmt_bind_result.3 create mode 100644 vendor/MDBC/man/mysql_stmt_close.3 create mode 100644 vendor/MDBC/man/mysql_stmt_data_seek.3 create mode 100644 vendor/MDBC/man/mysql_stmt_errno.3 create mode 100644 vendor/MDBC/man/mysql_stmt_error.3 create mode 100644 vendor/MDBC/man/mysql_stmt_execute.3 create mode 100644 vendor/MDBC/man/mysql_stmt_fetch.3 create mode 100644 vendor/MDBC/man/mysql_stmt_fetch_column.3 create mode 100644 vendor/MDBC/man/mysql_stmt_field_count.3 create mode 100644 vendor/MDBC/man/mysql_stmt_free_result.3 create mode 100644 vendor/MDBC/man/mysql_stmt_init.3 create mode 100644 vendor/MDBC/man/mysql_stmt_insert_id.3 create mode 100644 vendor/MDBC/man/mysql_stmt_more_results.3 create mode 100644 vendor/MDBC/man/mysql_stmt_next_result.3 create mode 100644 vendor/MDBC/man/mysql_stmt_num_rows.3 create mode 100644 vendor/MDBC/man/mysql_stmt_param_count.3 create mode 100644 vendor/MDBC/man/mysql_stmt_param_metadata.3 create mode 100644 vendor/MDBC/man/mysql_stmt_prepare.3 create mode 100644 vendor/MDBC/man/mysql_stmt_reset.3 create mode 100644 vendor/MDBC/man/mysql_stmt_result_metadata.3 create mode 100644 vendor/MDBC/man/mysql_stmt_row_seek.3 create mode 100644 vendor/MDBC/man/mysql_stmt_row_tell.3 create mode 100644 vendor/MDBC/man/mysql_stmt_send_long_data.3 create mode 100644 vendor/MDBC/man/mysql_stmt_sqlstate.3 create mode 100644 vendor/MDBC/man/mysql_stmt_store_result.3 create mode 100644 vendor/MDBC/man/mysql_stmt_warning_count.3 create mode 100644 vendor/MDBC/man/mysql_store_result.3 create mode 100644 vendor/MDBC/man/mysql_thread_end.3 create mode 100644 vendor/MDBC/man/mysql_thread_id.3 create mode 100644 vendor/MDBC/man/mysql_thread_init.3 create mode 100644 vendor/MDBC/man/mysql_use_result.3 create mode 100644 vendor/MDBC/man/mysql_warning_count.3 create mode 100644 vendor/MDBC/mariadb_config/CMakeLists.txt create mode 100644 vendor/MDBC/mariadb_config/libmariadb.pc.in create mode 100644 vendor/MDBC/mariadb_config/mariadb_config.c.in create mode 100644 vendor/MDBC/plugins/CMakeLists.txt create mode 100644 vendor/MDBC/plugins/auth/CMakeLists.txt create mode 100644 vendor/MDBC/plugins/auth/auth_gssapi_client.c create mode 100644 vendor/MDBC/plugins/auth/caching_sha2_pw.c create mode 100644 vendor/MDBC/plugins/auth/common.h create mode 100644 vendor/MDBC/plugins/auth/dialog.c create mode 100644 vendor/MDBC/plugins/auth/ed25519.c create mode 100644 vendor/MDBC/plugins/auth/gssapi_client.c create mode 100644 vendor/MDBC/plugins/auth/gssapi_errmsg.c create mode 100644 vendor/MDBC/plugins/auth/gssapi_errmsg.h create mode 100644 vendor/MDBC/plugins/auth/mariadb_cleartext.c create mode 100644 vendor/MDBC/plugins/auth/my_auth.c create mode 100644 vendor/MDBC/plugins/auth/old_password.c create mode 100644 vendor/MDBC/plugins/auth/ref10/api.h create mode 100644 vendor/MDBC/plugins/auth/ref10/base.h create mode 100644 vendor/MDBC/plugins/auth/ref10/base2.h create mode 100644 vendor/MDBC/plugins/auth/ref10/common.h create mode 100644 vendor/MDBC/plugins/auth/ref10/crypto_hash_sha512.h create mode 100644 vendor/MDBC/plugins/auth/ref10/crypto_int32.h create mode 100644 vendor/MDBC/plugins/auth/ref10/crypto_int64.h create mode 100644 vendor/MDBC/plugins/auth/ref10/crypto_sign.h create mode 100644 vendor/MDBC/plugins/auth/ref10/crypto_uint32.h create mode 100644 vendor/MDBC/plugins/auth/ref10/crypto_uint64.h create mode 100644 vendor/MDBC/plugins/auth/ref10/crypto_verify.h create mode 100644 vendor/MDBC/plugins/auth/ref10/crypto_verify_32.h create mode 100644 vendor/MDBC/plugins/auth/ref10/d.h create mode 100644 vendor/MDBC/plugins/auth/ref10/d2.h create mode 100644 vendor/MDBC/plugins/auth/ref10/fe.h create mode 100644 vendor/MDBC/plugins/auth/ref10/fe_0.c create mode 100644 vendor/MDBC/plugins/auth/ref10/fe_1.c create mode 100644 vendor/MDBC/plugins/auth/ref10/fe_add.c create mode 100644 vendor/MDBC/plugins/auth/ref10/fe_cmov.c create mode 100644 vendor/MDBC/plugins/auth/ref10/fe_copy.c create mode 100644 vendor/MDBC/plugins/auth/ref10/fe_frombytes.c create mode 100644 vendor/MDBC/plugins/auth/ref10/fe_invert.c create mode 100644 vendor/MDBC/plugins/auth/ref10/fe_isnegative.c create mode 100644 vendor/MDBC/plugins/auth/ref10/fe_isnonzero.c create mode 100644 vendor/MDBC/plugins/auth/ref10/fe_mul.c create mode 100644 vendor/MDBC/plugins/auth/ref10/fe_neg.c create mode 100644 vendor/MDBC/plugins/auth/ref10/fe_pow22523.c create mode 100644 vendor/MDBC/plugins/auth/ref10/fe_sq.c create mode 100644 vendor/MDBC/plugins/auth/ref10/fe_sq2.c create mode 100644 vendor/MDBC/plugins/auth/ref10/fe_sub.c create mode 100644 vendor/MDBC/plugins/auth/ref10/fe_tobytes.c create mode 100644 vendor/MDBC/plugins/auth/ref10/ge.h create mode 100644 vendor/MDBC/plugins/auth/ref10/ge_add.c create mode 100644 vendor/MDBC/plugins/auth/ref10/ge_add.h create mode 100644 vendor/MDBC/plugins/auth/ref10/ge_double_scalarmult.c create mode 100644 vendor/MDBC/plugins/auth/ref10/ge_frombytes.c create mode 100644 vendor/MDBC/plugins/auth/ref10/ge_madd.c create mode 100644 vendor/MDBC/plugins/auth/ref10/ge_madd.h create mode 100644 vendor/MDBC/plugins/auth/ref10/ge_msub.c create mode 100644 vendor/MDBC/plugins/auth/ref10/ge_msub.h create mode 100644 vendor/MDBC/plugins/auth/ref10/ge_p1p1_to_p2.c create mode 100644 vendor/MDBC/plugins/auth/ref10/ge_p1p1_to_p3.c create mode 100644 vendor/MDBC/plugins/auth/ref10/ge_p2_0.c create mode 100644 vendor/MDBC/plugins/auth/ref10/ge_p2_dbl.c create mode 100644 vendor/MDBC/plugins/auth/ref10/ge_p2_dbl.h create mode 100644 vendor/MDBC/plugins/auth/ref10/ge_p3_0.c create mode 100644 vendor/MDBC/plugins/auth/ref10/ge_p3_dbl.c create mode 100644 vendor/MDBC/plugins/auth/ref10/ge_p3_to_cached.c create mode 100644 vendor/MDBC/plugins/auth/ref10/ge_p3_to_p2.c create mode 100644 vendor/MDBC/plugins/auth/ref10/ge_p3_tobytes.c create mode 100644 vendor/MDBC/plugins/auth/ref10/ge_precomp_0.c create mode 100644 vendor/MDBC/plugins/auth/ref10/ge_scalarmult_base.c create mode 100644 vendor/MDBC/plugins/auth/ref10/ge_sub.c create mode 100644 vendor/MDBC/plugins/auth/ref10/ge_sub.h create mode 100644 vendor/MDBC/plugins/auth/ref10/ge_tobytes.c create mode 100644 vendor/MDBC/plugins/auth/ref10/keypair.c create mode 100644 vendor/MDBC/plugins/auth/ref10/open.c create mode 100644 vendor/MDBC/plugins/auth/ref10/pow22523.h create mode 100644 vendor/MDBC/plugins/auth/ref10/pow225521.h create mode 100644 vendor/MDBC/plugins/auth/ref10/sc.h create mode 100644 vendor/MDBC/plugins/auth/ref10/sc_muladd.c create mode 100644 vendor/MDBC/plugins/auth/ref10/sc_reduce.c create mode 100644 vendor/MDBC/plugins/auth/ref10/sign.c create mode 100644 vendor/MDBC/plugins/auth/ref10/sqrtm1.h create mode 100644 vendor/MDBC/plugins/auth/ref10/verify.c create mode 100644 vendor/MDBC/plugins/auth/server_plugin.h create mode 100644 vendor/MDBC/plugins/auth/sha256_pw.c create mode 100644 vendor/MDBC/plugins/auth/sspi_client.c create mode 100644 vendor/MDBC/plugins/auth/sspi_common.h create mode 100644 vendor/MDBC/plugins/auth/sspi_errmsg.c create mode 100644 vendor/MDBC/plugins/connection/CMakeLists.txt create mode 100644 vendor/MDBC/plugins/connection/replication.c create mode 100644 vendor/MDBC/plugins/io/CMakeLists.txt create mode 100644 vendor/MDBC/plugins/io/remote_io.c create mode 100644 vendor/MDBC/plugins/plugin.def create mode 100644 vendor/MDBC/plugins/pvio/CMakeLists.txt create mode 100644 vendor/MDBC/plugins/pvio/pvio_npipe.c create mode 100644 vendor/MDBC/plugins/pvio/pvio_plugin.def create mode 100644 vendor/MDBC/plugins/pvio/pvio_shmem.c create mode 100644 vendor/MDBC/plugins/pvio/pvio_socket.c create mode 100644 vendor/MDBC/plugins/trace/trace_example.c create mode 100644 vendor/MDBC/scripts/create_man create mode 100644 vendor/MDBC/travis.sh create mode 100644 vendor/MDBC/unittest/libmariadb/CMakeLists.txt create mode 100644 vendor/MDBC/unittest/libmariadb/async.c create mode 100644 vendor/MDBC/unittest/libmariadb/basic-t.c create mode 100644 vendor/MDBC/unittest/libmariadb/bulk1.c create mode 100644 vendor/MDBC/unittest/libmariadb/charset.c create mode 100644 vendor/MDBC/unittest/libmariadb/conc336.c create mode 100644 vendor/MDBC/unittest/libmariadb/connection.c create mode 100644 vendor/MDBC/unittest/libmariadb/cursor.c create mode 100644 vendor/MDBC/unittest/libmariadb/data.csv create mode 100644 vendor/MDBC/unittest/libmariadb/dyncol.c create mode 100644 vendor/MDBC/unittest/libmariadb/errors.c create mode 100644 vendor/MDBC/unittest/libmariadb/features-10_2.c create mode 100644 vendor/MDBC/unittest/libmariadb/fetch.c create mode 100644 vendor/MDBC/unittest/libmariadb/fingerprint.list.in create mode 100644 vendor/MDBC/unittest/libmariadb/getopt.c create mode 100644 vendor/MDBC/unittest/libmariadb/logs.c create mode 100644 vendor/MDBC/unittest/libmariadb/ma_getopt.c create mode 100644 vendor/MDBC/unittest/libmariadb/ma_getopt.h create mode 100644 vendor/MDBC/unittest/libmariadb/misc.c create mode 100644 vendor/MDBC/unittest/libmariadb/my_test.h create mode 100644 vendor/MDBC/unittest/libmariadb/performance.c create mode 100644 vendor/MDBC/unittest/libmariadb/ps.c create mode 100644 vendor/MDBC/unittest/libmariadb/ps_bugs.c create mode 100644 vendor/MDBC/unittest/libmariadb/ps_new.c create mode 100644 vendor/MDBC/unittest/libmariadb/result.c create mode 100644 vendor/MDBC/unittest/libmariadb/rpl_api.c create mode 100644 vendor/MDBC/unittest/libmariadb/sp.c create mode 100644 vendor/MDBC/unittest/libmariadb/ssl.c create mode 100644 vendor/MDBC/unittest/libmariadb/t_aurora.c create mode 100644 vendor/MDBC/unittest/libmariadb/t_conc173.c create mode 100644 vendor/MDBC/unittest/libmariadb/thread.c create mode 100644 vendor/MDBC/unittest/libmariadb/view.c create mode 100644 vendor/MDBC/unittest/mytap/CMakeLists.txt create mode 100644 vendor/MDBC/unittest/mytap/Doxyfile create mode 100644 vendor/MDBC/unittest/mytap/t/basic-t.c create mode 100644 vendor/MDBC/unittest/mytap/tap.c create mode 100644 vendor/MDBC/unittest/mytap/tap.h create mode 100644 vendor/MDBC/win-iconv/iconv.h create mode 100644 vendor/MDBC/win-iconv/mlang.h create mode 100644 vendor/MDBC/win-iconv/win_iconv.c create mode 100644 vendor/MDBC/win/packaging/CMakeLists.txt create mode 100644 vendor/MDBC/win/packaging/WixUIBannerBmp.jpg create mode 100644 vendor/MDBC/win/packaging/WixUIDialogBmp.jpg create mode 100644 vendor/MDBC/win/packaging/license.rtf create mode 100644 vendor/MDBC/win/packaging/mariadb-connector-c.xml.in create mode 100644 vendor/MDBC/win/resource.rc.in diff --git a/CMakeLists.txt b/CMakeLists.txt index e4e2141e..f0f99bfc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,6 +15,8 @@ option(ENABLE_API21 "Build for 2.1 API." OFF) option(ENABLE_DISCORD "Enable built-in Discord support" ON) option(ENABLE_DISCORD_VOICE "Enable voice support in Discord library" OFF) option(ENABLE_OFFICIAL "Enable compatibility with official legacy plug-in" ON) +# As a fall-back for certain situations (mainly some docker ubuntu containers) +option(ENABLE_BUILTIN_MYSQL_C "Enable built-in MySQL connector library" ON) #option(FORCE_32BIT_BIN "Create a 32-bit executable binary if the compiler defaults to 64-bit." OFF) # This option should only be available in certain conditions if(WIN32 AND MINGW) diff --git a/module/CMakeLists.txt b/module/CMakeLists.txt index 4dd508b9..3768c9e8 100644 --- a/module/CMakeLists.txt +++ b/module/CMakeLists.txt @@ -155,7 +155,7 @@ if(ENABLE_DISCORD) ) endif() # Link to POCO libraries -target_link_libraries(SqModule Poco::Foundation Poco::Crypto Poco::Data Poco::Net Poco::JSON Poco::XML) +target_link_libraries(SqModule Poco::Foundation Poco::Crypto Poco::Data Poco::Net) # Does POCO have SQLite support? if(ENABLE_DATA_SQLITE) if(NOT POCO_UNBUNDLED) @@ -170,9 +170,12 @@ if(ENABLE_DATA_SQLITE) # Include legacy implementation sources target_sources(SqModule PRIVATE Library/SQLite.hpp Library/SQLite.cpp) endif() +# Do we have built-in MYSQL enabled? +if (NOT ENABLE_BUILTIN_MYSQL_C) + find_package(MySQL) +endif() # Does POCO have MySLQ support? -find_package(MySQL) -if(MYSQL_FOUND) +if(ENABLE_BUILTIN_MYSQL_C OR MYSQL_FOUND) message(STATUS "MySQL was enabled") # Link the libraries target_link_libraries(SqModule Poco::DataMySQL) diff --git a/vendor/CMakeLists.txt b/vendor/CMakeLists.txt index 372fbf60..4a3d0817 100644 --- a/vendor/CMakeLists.txt +++ b/vendor/CMakeLists.txt @@ -9,6 +9,14 @@ add_subdirectory(CPR) add_subdirectory(UTF8) add_subdirectory(PUGIXML) add_subdirectory(CivetWeb) +if (ENABLE_BUILTIN_MYSQL_C) + set(WITH_MSI OFF CACHE INTERNAL "" FORCE) + set(WITH_UNIT_TESTS OFF CACHE INTERNAL "" FORCE) + set(WITH_EXTERNAL_ZLIB ON CACHE INTERNAL "" FORCE) + set(WITH_CURL ON CACHE INTERNAL "" FORCE) + set(WITH_SSL ON CACHE INTERNAL "" FORCE) + add_subdirectory(MDBC) +endif() set(BUILD_TESTING OFF CACHE INTERNAL "" FORCE) set(BUILD_SHARED_LIBS OFF CACHE INTERNAL "" FORCE) add_subdirectory(MaxmindDB) diff --git a/vendor/MDBC/CMakeLists.txt b/vendor/MDBC/CMakeLists.txt new file mode 100644 index 00000000..05beff92 --- /dev/null +++ b/vendor/MDBC/CMakeLists.txt @@ -0,0 +1,517 @@ +# CMakeLists.txt + +# This is the LGPL libmariadb project. + +CMAKE_MINIMUM_REQUIRED(VERSION 2.8.12 FATAL_ERROR) +INCLUDE(CheckFunctionExists) +IF(COMMAND CMAKE_POLICY) + SET(NEW_POLICIES CMP0003 CMP0022 CMP0023 CMP0077 CMP0069 CMP0075) + FOREACH(TYPE OLD NEW) + FOREACH(P ${${TYPE}_POLICIES}) + IF(POLICY ${P}) + CMAKE_POLICY(SET ${P} ${TYPE}) + ENDIF() + ENDFOREACH() + ENDFOREACH() +ENDIF() + + +PROJECT(mariadb-connector-c C) + +# Is C/C built as subproject? +get_directory_property(IS_SUBPROJECT PARENT_DIRECTORY) + +# do not inherit include directories from the parent project +SET_PROPERTY(DIRECTORY PROPERTY INCLUDE_DIRECTORIES) +FOREACH(V WITH_MYSQLCOMPAT WITH_MSI WITH_SIGNCODE WITH_RTC WITH_UNIT_TESTS + WITH_DYNCOL WITH_EXTERNAL_ZLIB WITH_CURL WITH_SQLITE WITH_SSL WITH_ICONV + DEFAULT_CHARSET INSTALL_LAYOUT WITH_TEST_SRCPKG) + SET(${V} ${${OPT}${V}}) +ENDFOREACH() + +#SET(PACKAGE_STATUS_SUFFIX "rc") + +SET(CC_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) +SET(CC_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) + +SET(CPACK_PACKAGE_VERSION_MAJOR 3) +SET(CPACK_PACKAGE_VERSION_MINOR 2) +SET(CPACK_PACKAGE_VERSION_PATCH 3) +SET(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}") +MATH(EXPR MARIADB_PACKAGE_VERSION_ID "${CPACK_PACKAGE_VERSION_MAJOR} * 10000 + + ${CPACK_PACKAGE_VERSION_MINOR} * 100 + + ${CPACK_PACKAGE_VERSION_PATCH}") + +MACRO(ADD_OPTION _name _text _default) + IF(NOT DEFINED ${_name}) + OPTION(${OPT}${_name} "${_text}" "${_default}") + ELSE() + OPTION(${OPT}${_name} "${_text}" "${${_name}}") + ENDIF() +ENDMACRO() + +### Options ### +IF(NOT WIN32) + ADD_OPTION(WITH_MYSQLCOMPAT "creates libmysql* symbolic links" OFF) +ELSE() + ADD_OPTION(WITH_MSI "Build MSI installation package" OFF) + ADD_OPTION(WITH_SIGNCODE "digitally sign files" OFF) + ADD_OPTION(WITH_RTC "enables run time checks for debug builds" OFF) + ADD_OPTION(WITH_ICONV "enables character set conversion" OFF) +ENDIF() + +ADD_OPTION(WITH_UNIT_TESTS "build test suite" ON) +ADD_OPTION(WITH_DYNCOL "Enables support of dynamic columns" ON) +ADD_OPTION(WITH_EXTERNAL_ZLIB "Enables use of external zlib" OFF) +ADD_OPTION(WITH_CURL "Enables use of curl" ON) +ADD_OPTION(WITH_SSL "Enables use of TLS/SSL library" ON) +############### + +INCLUDE(${CC_SOURCE_DIR}/cmake/misc.cmake) +INCLUDE(FindCURL) + +IF(WITH_SIGNCODE) + IF(WIN32 AND NOT SIGN_OPTIONS) + SET(SIGN_OPTIONS /a /t http://timestamp.verisign.com/scripts/timstamp.dll) + ELSE() + SEPARATE_ARGUMENTS(SIGN_OPTIONS) + ENDIF() + MARK_AS_ADVANCED(SIGN_OPTIONS) +ENDIF() + +SET(MARIADB_CONNECTOR_C_COPYRIGHT "2013-2017 MariaDB Corporation Ab") + +IF(WITH_RTC) + SET(RTC_OPTIONS "/RTC1 /RTCc") +ENDIF() + +INCLUDE(${CC_SOURCE_DIR}/cmake/plugins.cmake) + + +IF(WIN32) + FILE(REMOVE ${CC_BINARY_DIR}/win/packaging/plugin.conf) + INCLUDE(${CC_SOURCE_DIR}/cmake/version_info.cmake) +ENDIF() + +IF(NOT IS_SUBPROJECT) +IF(MSVC) + # Speedup system tests + INCLUDE(${CC_SOURCE_DIR}/cmake/WindowsCache.cmake) + ADD_DEFINITIONS(-DWIN32_LEAN_AND_MEAN) + IF (MSVC) + SET(CONFIG_TYPES "DEBUG" "RELEASE" "RELWITHDEBINFO") + FOREACH(BUILD_TYPE ${CONFIG_TYPES}) + FOREACH(COMPILER CXX C) + SET(COMPILER_FLAGS "${CMAKE_${COMPILER}_FLAGS_${BUILD_TYPE}}") + IF (NOT COMPILER_FLAGS STREQUAL "") + IF(NOT WITH_ASAN) + STRING(REPLACE "/MD" "/MT" COMPILER_FLAGS ${COMPILER_FLAGS}) + IF (BUILD_TYPE STREQUAL "DEBUG") + SET(COMPILER_FLAGS "${COMPILER_FLAGS} ${RTC_OPTIONS}") + ENDIF() + ENDIF() + STRING(REPLACE "/Zi" "/Z7" COMPILER_FLAGS ${COMPILER_FLAGS}) + MESSAGE (STATUS "CMAKE_${COMPILER}_FLAGS_${BUILD_TYPE}= ${COMPILER_FLAGS}") + SET(CMAKE_${COMPILER}_FLAGS_${BUILD_TYPE} ${COMPILER_FLAGS}) + ENDIF() + ENDFOREACH() + ENDFOREACH() + ENDIF() +ENDIF() +ENDIF(NOT IS_SUBPROJECT) + +# Disable dbug information for release builds +SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -DDBUG_OFF") +SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DDBUG_OFF") +SET(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -DDBUG_OFF") +SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -DDBUG_OFF") + +IF(CMAKE_COMPILER_IS_GNUCC) + INCLUDE(CheckCCompilerFlag) + #SET(GCC_FLAGS -Wunused -Wlogical-op -Wno-uninitialized -Wall -Wextra -Wformat-security -Wno-init-self -Wwrite-strings -Wshift-count-overflow -Wdeclaration-after-statement -Wno-undef -Wno-unknown-pragmas) + FOREACH(GCC_FLAG ${GCC_FLAGS}) + CHECK_C_COMPILER_FLAG("${GCC_FLAG}" HAS_${GCC_FLAG}_FLAG) + IF(${HAS_${GCC_FLAG}_FLAG}) + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${GCC_FLAG}") + ENDIF() + ENDFOREACH() +ENDIF() + +# If the build type isn't specified, set to Relwithdebinfo as default. +IF(NOT CMAKE_BUILD_TYPE) + SET(CMAKE_BUILD_TYPE "RelWithDebInfo") +ENDIF() + +# various defines for generating include/mysql_version.h +INCLUDE(FindGit) +IF(GIT_EXECUTABLE AND EXISTS ${CC_SOURCE_DIR}/.git) + EXECUTE_PROCESS( + COMMAND ${GIT_EXECUTABLE} rev-parse HEAD + WORKING_DIRECTORY ${CC_SOURCE_DIR} + OUTPUT_VARIABLE OUT RESULT_VARIABLE RES) + IF(RES EQUAL 0) + STRING(REGEX REPLACE "\n$" "" CC_SOURCE_REVISION "${OUT}") + ENDIF() +ENDIF() +SET(PROTOCOL_VERSION 10) # we adapted new password option from PHP's mysqlnd ! + +# if C/C is build as subproject inside MariaDB server tree we will +# use the version defined by server +IF(MAJOR_VERSION) + SET(MARIADB_CLIENT_VERSION_MAJOR ${MAJOR_VERSION}) + SET(MARIADB_CLIENT_VERSION_MINOR ${MINOR_VERSION}) + SET(MARIADB_CLIENT_VERSION_PATCH ${PATCH_VERSION}) + SET(MARIADB_CLIENT_VERSION_EXTRA ${EXTRA_VERSION}) +ELSE() + SET(MARIADB_CLIENT_VERSION_MAJOR "10") + SET(MARIADB_CLIENT_VERSION_MINOR "5") + SET(MARIADB_CLIENT_VERSION_PATCH "5") + SET(MARIADB_CLIENT_VERSION_EXTRA "") +ENDIF() +SET(MARIADB_CLIENT_VERSION "${MARIADB_CLIENT_VERSION_MAJOR}.${MARIADB_CLIENT_VERSION_MINOR}.${MARIADB_CLIENT_VERSION_PATCH}${MARIADB_CLIENT_VERSION_EXTRA}") +SET(MARIADB_BASE_VERSION "mariadb-${MARIADB_CLIENT_VERSION_MAJOR}.${MARIADB_CLIENT_VERSION_MINOR}") +MATH(EXPR MARIADB_VERSION_ID "${MARIADB_CLIENT_VERSION_MAJOR} * 10000 + + ${MARIADB_CLIENT_VERSION_MINOR} * 100 + + ${MARIADB_CLIENT_VERSION_PATCH}") + +IF (NOT MARIADB_PORT) + SET(MARIADB_PORT 3306) +ENDIF () +IF(NOT MARIADB_UNIX_ADDR) + SET(MARIADB_UNIX_ADDR "/tmp/mysql.sock") +ENDIF() + +INCLUDE("${CC_SOURCE_DIR}/cmake/install.cmake") +IF(NOT PLUGINDIR) + SET(PLUGINDIR "${CMAKE_INSTALL_PREFIX}/${INSTALL_PLUGINDIR}") +ENDIF() + +# todo: we don't character sets in share - all is compiled in +SET(SHAREDIR "share") +SET(DEFAULT_CHARSET_HOME "${CMAKE_INSTALL_PREFIX}") + +INCLUDE(${CC_SOURCE_DIR}/cmake/SearchLibrary.cmake) + +IF(WITH_EXTERNAL_ZLIB) + IF(NOT ZLIB_FOUND) + FIND_PACKAGE(ZLIB REQUIRED) + INCLUDE_DIRECTORIES(${ZLIB_INCLUDE_DIR}) + SET(LIBZ ${ZLIB_LIBRARY}) + ELSE() + # ZLIB was already specified by another (parent) project + SET(INTERNAL_ZLIB_LIBRARY ${ZLIB_LIBRARY}) + ENDIF() +ENDIF() + +IF(NOT WIN32) + INCLUDE(TestBigEndian) + TEST_BIG_ENDIAN(HAVE_BIGENDIAN) +ENDIF() + +# check for various include files +INCLUDE(${CC_SOURCE_DIR}/cmake/CheckIncludeFiles.cmake) +# check for various functions +INCLUDE(${CC_SOURCE_DIR}/cmake/CheckFunctions.cmake) +# check for various types +INCLUDE(${CC_SOURCE_DIR}/cmake/CheckTypes.cmake) + +IF(UNIX) + SEARCH_LIBRARY(LIBM floor m) + SEARCH_LIBRARY(LIBPTHREAD pthread_getspecific "pthread;pthreads") + SEARCH_LIBRARY(LIBNSL gethostbyname_r "nsl_r;nsl") + SEARCH_LIBRARY(LIBSOCKET setsockopt socket) + FIND_PACKAGE(Threads) + SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${LIBNSL} ${LIBBIND} ${LIBICONV} ${LIBZ} + ${LIBSOCKET} ${CMAKE_DL_LIBS} ${LIBM} ${LIBPTHREAD}) + SET(SYSTEM_LIBS ${SYSTEM_LIBS} ${LIBNSL} ${LIBBIND} ${LIBICONV} ${LIBZ} + ${LIBSOCKET} ${CMAKE_DL_LIBS} ${LIBM} ${LIBPTHREAD}) + #remove possible dups from required libraries + LIST(LENGTH CMAKE_REQUIRED_LIBRARIES rllength) + IF(${rllength} GREATER 0) + LIST(REMOVE_DUPLICATES CMAKE_REQUIRED_LIBRARIES) + ENDIF() +ENDIF() + + +IF(CMAKE_HAVE_PTHREAD_H) + SET(CMAKE_REQUIRED_INCLUDES pthread.h) +ENDIF() + +IF(DBUG_OFF) + ADD_DEFINITIONS(-DDBUG_OFF=1) +ENDIF() + +ADD_DEFINITIONS(-DMARIADB_SYSTEM_TYPE="${CMAKE_SYSTEM_NAME}") +ADD_DEFINITIONS(-DMARIADB_MACHINE_TYPE="${CMAKE_SYSTEM_PROCESSOR}") + +IF(WIN32) + SET(HAVE_THREADS 1) + ADD_DEFINITIONS(-DHAVE_DLOPEN) + ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS) + IF(MSVC) + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4996" ) + ENDIF() +ELSEIF() + SET(HAVE_THREADS ${CMAKE_USE_PTHREADS}) +ENDIF() + +IF(NOT DEFAULT_CHARSET) + SET(DEFAULT_CHARSET "utf8mb4") +ENDIF() + + +# convert SSL options to uppercase +IF(WITH_SSL) + STRING(TOUPPER ${WITH_SSL} WITH_SSL) +ENDIF() +IF(WITH_SSL STREQUAL "ON") + IF(WIN32) + SET(WITH_SSL "SCHANNEL") + ELSE() + SET(WITH_SSL "OPENSSL") + ENDIF() +ENDIF() + +IF(NOT WITH_SSL STREQUAL "OFF") + IF(WITH_SSL STREQUAL "OPENSSL") + IF (NOT OPENSSL_FOUND) + FIND_PACKAGE(OpenSSL) + ENDIF() + IF(OPENSSL_FOUND) + ADD_DEFINITIONS(-DHAVE_OPENSSL -DHAVE_TLS) + SET(SSL_SOURCES "${CC_SOURCE_DIR}/libmariadb/secure/openssl.c") + SET(SSL_LIBRARIES ${OPENSSL_SSL_LIBRARY} ${OPENSSL_CRYPTO_LIBRARY}) + IF(WIN32) + CHECK_INCLUDE_FILES (${OPENSSL_INCLUDE_DIR}/openssl/applink.c HAVE_OPENSSL_APPLINK_C) + ENDIF() + INCLUDE_DIRECTORIES(BEFORE ${OPENSSL_INCLUDE_DIR}) + + + TRY_RUN(LIBRESSL_RESULT HAVE_LIBRESSL + ${CMAKE_BINARY_DIR} + ${CC_SOURCE_DIR}/cmake/libressl_version.c + COMPILE_DEFINITIONS "-I${OPENSSL_INCLUDE_DIR}" + RUN_OUTPUT_VARIABLE LIBRESSL_VERSION) + IF(HAVE_LIBRESSL) + ADD_DEFINITIONS(-DHAVE_LIBRESSL) + SET(TLS_LIBRARY_VERSION ${LIBRESSL_VERSION}) + ELSE() + SET(TLS_LIBRARY_VERSION "OpenSSL ${OPENSSL_VERSION}") + ENDIF() + ELSE() + MESSAGE1(TLS_LIBRARY_VERSION "OpenSSL/LibreSSL not found") + ENDIF() + ENDIF() + IF(WITH_SSL STREQUAL "GNUTLS") + FIND_PACKAGE(GnuTLS "3.3.24" REQUIRED) + IF(GNUTLS_FOUND) + ADD_DEFINITIONS(-DHAVE_GNUTLS -DHAVE_TLS) + SET(SSL_SOURCES "${CC_SOURCE_DIR}/libmariadb/secure/gnutls.c") + SET(SSL_LIBRARIES ${GNUTLS_LIBRARY}) + SET(TLS_LIBRARY_VERSION "GnuTLS ${GNUTLS_VERSION_STRING}") + INCLUDE_DIRECTORIES(${GNUTLS_INCLUDE_DIR}) + ELSE() + MESSAGE(FATAL_ERROR "GnuTLS not found") + ENDIF() + ENDIF() + IF(WIN32) + IF(WITH_SSL STREQUAL "SCHANNEL") + ADD_DEFINITIONS(-DHAVE_SCHANNEL -DHAVE_TLS) + SET(SSL_SOURCES "${CC_SOURCE_DIR}/libmariadb/secure/schannel.c" + "${CC_SOURCE_DIR}/libmariadb/secure/ma_schannel.c" + "${CC_SOURCE_DIR}/libmariadb/secure/schannel_certs.c") + INCLUDE_DIRECTORIES("${CC_SOURCE_DIR}/plugins/pvio/") + SET(SSL_LIBRARIES secur32) + SET(TLS_LIBRARY_VERSION "Schannel ${CMAKE_SYSTEM_VERSION}") + ENDIF() + ENDIF() + MESSAGE1(TLS_LIBRARY_VERSION "TLS library/version: ${TLS_LIBRARY_VERSION}") + + MARK_AS_ADVANCED(SSL_SOURCES) +ENDIF() + +SET(ENABLED_LOCAL_INFILE "AUTO" CACHE STRING "If we should should enable LOAD DATA LOCAL by default (OFF/ON/AUTO)") +MARK_AS_ADVANCED(ENABLED_LOCAL_INFILE) +IF (ENABLED_LOCAL_INFILE MATCHES "^(0|FALSE)$") + SET(ENABLED_LOCAL_INFILE OFF) +ELSEIF(ENABLED_LOCAL_INFILE MATCHES "^(1|TRUE)$") + SET(ENABLED_LOCAL_INFILE ON) +ELSEIF (NOT ENABLED_LOCAL_INFILE MATCHES "^(ON|OFF|AUTO)$") + MESSAGE(FATAL_ERROR "ENABLED_LOCAL_INFILE must be one of OFF, ON, AUTO") +ENDIF() + +IF(WITH_ICONV) + IF(NOT WIN32) + INCLUDE(${CC_SOURCE_DIR}/cmake/FindIconv.cmake) + ENDIF() +ENDIF() + +CONFIGURE_FILE(${CC_SOURCE_DIR}/include/ma_config.h.in + ${CC_BINARY_DIR}/include/ma_config.h) +CONFIGURE_FILE(${CC_SOURCE_DIR}/include/ma_config.h.in + ${CC_BINARY_DIR}/include/config.h) +CONFIGURE_FILE(${CC_SOURCE_DIR}/include/mariadb_version.h.in + ${CC_BINARY_DIR}/include/mariadb_version.h) + +INCLUDE_DIRECTORIES(${CC_BINARY_DIR}/include) + +IF(WIN32) + SET(SYSTEM_LIBS ws2_32 advapi32 kernel32 shlwapi crypt32 ${LIBZ}) +ELSE() + SET(SYSTEM_LIBS ${SYSTEM_LIBS} ${LIBPTHREAD} ${CMAKE_DL_LIBS} ${LIBM}) + IF(ICONV_EXTERNAL) + SET(SYSTEM_LIBS ${SYSTEM_LIBS} ${ICONV_LIBRARIES}) + ENDIF() +ENDIF() +IF(WITH_SSL) + SET(SYSTEM_LIBS ${SYSTEM_LIBS} ${SSL_LIBRARIES}) +ENDIF() +MESSAGE1(SYSTEM_LIBS "SYSTEM_LIBS ${SYSTEM_LIBS}") +MARK_AS_ADVANCED(SYSTEM_LIBS) + +IF(NOT REMOTEIO_PLUGIN_TYPE MATCHES "OFF") + IF(CURL_FOUND) + INCLUDE_DIRECTORIES(${CURL_INCLUDE_DIRS}) + IF(REMOTEIO_PLUGIN_TYPE MATCHES "STATIC") + SET(SYSTEM_LIBS ${SYSTEM_LIBS} ${CURL_LIBRARIES}) + ENDIF() + ADD_DEFINITIONS("-DHAVE_REMOTEIO=1") + ENDIF() +ENDIF() +IF(NOT WIN32) + IF(NOT AUTH_GSSAPI_PLUGIN_TYPE MATCHES "OFF") + INCLUDE(${CC_SOURCE_DIR}/cmake/FindGSSAPI.cmake) + IF(GSSAPI_FOUND) + INCLUDE_DIRECTORIES(${GSSAPI_INCS}) + IF(AUTH_GSSAPI_PLUGIN_TYPE MATCHES "STATIC") + SET(SYSTEM_LIBS ${SYSTEM_LIBS} ${GSSAPI_LIBS}) + ENDIF() + ENDIF() + ENDIF() +ENDIF() +INCLUDE(${CC_SOURCE_DIR}/plugins/CMakeLists.txt) +ADD_SUBDIRECTORY(include) +ADD_SUBDIRECTORY(libmariadb) +IF(NOT WIN32) + ADD_SUBDIRECTORY(mariadb_config) +ENDIF() + +IF(IS_DIRECTORY ${CC_SOURCE_DIR}/unittest) + IF(WITH_UNIT_TESTS) + ADD_SUBDIRECTORY(unittest/mytap) + ADD_SUBDIRECTORY(unittest/libmariadb) + ENDIF() +ENDIF() + +IF(CLIENT_DOCS) + INSTALL(DIRECTORY ${CLIENT_DOCS} + DESTINATION ${DOCS_INSTALL_DIR_${INSTALL_LAYOUT}} + COMPONENT SharedLibraries) +ENDIF() + +IF(UNIX) + ADD_SUBDIRECTORY(man) +ENDIF() + +IF(WIN32 AND WITH_MSI AND CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo") + ADD_SUBDIRECTORY(win/packaging) +ENDIF() +MESSAGE1(SYSTEM_PROCESSOR "SYSTEM processor: ${CMAKE_SYSTEM_PROCESSOR}") +SET(CPACK_PACKAGE_VENDOR "MariaDB Corporation Ab") +SET(CPACK_PACKAGE_DESCRIPTION "MariaDB Connector/C. A library for connecting to MariaDB and MySQL servers") +SET(CPACK_PACKAGE_NAME "mariadb_connector_c") +STRING(TOLOWER ${CMAKE_SYSTEM_NAME} system_name) +SET(CPACK_RESOURCE_FILE_LICENSE "${CC_SOURCE_DIR}/COPYING.LIB") +SET(CPACK_PACKAGE_DESCRIPTION_FILE "${CC_SOURCE_DIR}/README") +INCLUDE(cmake/ConnectorName.cmake) +IF(NOT PACKAGE_STATUS_SUFFIX) + SET(CPACK_SOURCE_PACKAGE_FILE_NAME "mariadb-connector-c-${CPACK_PACKAGE_VERSION}-src") + IF(PACKAGE_PLATFORM_SUFFIX) + SET(CPACK_PACKAGE_FILE_NAME "mariadb-connector-c-${CPACK_PACKAGE_VERSION}-${PACKAGE_PLATFORM_SUFFIX}") + ELSE() + SET(CPACK_PACKAGE_FILE_NAME "mariadb-connector-c-${CPACK_PACKAGE_VERSION}-${system_name}-${CMAKE_SYSTEM_PROCESSOR}") + ENDIF() +ELSE() + SET(CPACK_SOURCE_PACKAGE_FILE_NAME "mariadb-connector-c-${CPACK_PACKAGE_VERSION}-${PACKAGE_STATUS_SUFFIX}-src") + IF(PACKAGE_PLATFORM_SUFFIX) + SET(CPACK_PACKAGE_FILE_NAME "mariadb-connector-c-${CPACK_PACKAGE_VERSION}-${PACKAGE_STATUS_SUFFIX}-${PACKAGE_PLATFORM_SUFFIX}") + ELSE() + SET(CPACK_PACKAGE_FILE_NAME "mariadb-connector-c-${CPACK_PACKAGE_VERSION}-${PACKAGE_STATUS_SUFFIX}-${system_name}-${CMAKE_SYSTEM_PROCESSOR}") + ENDIF() +ENDIF() +# Build source packages +IF(GIT_BUILD_SRCPKG) + # get branch name + EXECUTE_PROCESS(COMMAND ${GIT_EXECUTABLE} show-branch OUTPUT_VARIABLE git_branch) + STRING(REGEX MATCH "\\[([^]]+)\\]" git_branch ${git_branch}) + STRING(REGEX REPLACE "\\[|\\]" "" GIT_BRANCH ${git_branch}) + MESSAGE1(GIT_BRANCH "${GIT_BRANCH}") + IF(WIN32) + EXECUTE_PROCESS(COMMAND ${GIT_EXECUTABLE} archive ${GIT_BRANCH} --format=zip --prefix=${CPACK_SOURCE_PACKAGE_FILE_NAME}/ --output=${CPACK_SOURCE_PACKAGE_FILE_NAME}.zip) + ELSE() + EXECUTE_PROCESS(COMMAND ${GIT_EXECUTABLE} archive ${GIT_BRANCH} --format=zip --prefix=${CPACK_SOURCE_PACKAGE_FILE_NAME}/ --output=${CPACK_SOURCE_PACKAGE_FILE_NAME}.zip) + EXECUTE_PROCESS(COMMAND ${GIT_EXECUTABLE} archive ${GIT_BRANCH} --format=tar --prefix=${CPACK_SOURCE_PACKAGE_FILE_NAME}/ --output=${CPACK_SOURCE_PACKAGE_FILE_NAME}.tar) + EXECUTE_PROCESS(COMMAND gzip -9 -f ${CPACK_SOURCE_PACKAGE_FILE_NAME}.tar) + ENDIF() +ENDIF() + +SET(CPACK_SOURCE_IGNORE_FILES +\\\\.git/ +\\\\.gitignore +\\\\.gitattributes +CMakeCache\\\\.txt +cmake_dist\\\\.cmake +CPackConfig\\\\.cmake +mariadb_config\\\\.c$ +\\\\.build/ +html/ +unittest +/cmake_install.cmake +/CTestTestfile.cmake +/CPackSourceConfig.cmake +/CMakeFiles/ +/version_resources/ +/_CPack_Packages/ +\\\\.gz$ +\\\\.zip$ +mariadb_config/mariadb_config$ +/CMakeFiles/ +/version_resources/ +/_CPack_Packages/ +Makefile$ +include/my_config\\\\.h$ +) + +IF(WITH_TEST_SRCPKG) + SET(PACKAGE_FILE ${CC_SOURCE_DIR}/package.name) + FILE(REMOVE ${PACKAGE_FILE}) + FILE(WRITE ${PACKAGE_FILE} ${CPACK_SOURCE_PACKAGE_FILE_NAME}) +ENDIF() + +IF(WIN32) + SET(CPACK_GENERATOR "ZIP") + SET(CPACK_SOURCE_GENERATOR "ZIP") +ELSE() + SET(CPACK_GENERATOR "TGZ") + SET(CPACK_SOURCE_GENERATOR "TGZ") +ENDIF() +INCLUDE(CPack) + +IF(WITH_EXTERNAL_ZLIB) + SET(zlib_status ${WITH_EXTERNAL_ZLIB}) +ELSE() + SET(zlib_status "yes (using bundled zlib)") +ENDIF() + +MESSAGE1(STATUS "MariaDB Connector/c configuration: +-- Static PLUGINS ${PLUGINS_STATIC} +-- Dynamic PLUGINS ${PLUGINS_DYNAMIC} +-- CPack generation: ${CPACK_GENERATOR} +-- SSL support: ${WITH_SSL} Libs: ${SSL_LIBRARIES} +-- Zlib support: ${zlib_status} +-- Installation layout: ${INSTALL_LAYOUT} +-- Include files will be installed in ${INSTALL_INCLUDEDIR} +-- Libraries will be installed in ${INSTALL_LIBDIR} +-- Binaries will be installed in ${INSTALL_BINDIR} +-- Documentation included from ${CLIENT_DOCS} +-- Required: ${CMAKE_REQUIRED_LIBRARIES}") diff --git a/vendor/MDBC/COPYING.LIB b/vendor/MDBC/COPYING.LIB new file mode 100644 index 00000000..4362b491 --- /dev/null +++ b/vendor/MDBC/COPYING.LIB @@ -0,0 +1,502 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/vendor/MDBC/README b/vendor/MDBC/README new file mode 100644 index 00000000..a6af0fc7 --- /dev/null +++ b/vendor/MDBC/README @@ -0,0 +1,15 @@ +This is LGPL MariaDB client library that can be used to connect to MySQL +or MariaDB. + +This code is based on the LGPL libmysql client library from MySQL 3.23 +and PHP's mysqlnd extension. + +This product includes PHP software, freely available from + + +If you want to be part of this development effort, you can discuss this at +maria-developers@lists.launchpad.org. + +To report a bug you'll need to signup for an account at https://jira.mariadb.org + +The MariaDB team diff --git a/vendor/MDBC/appveyor-download.bat b/vendor/MDBC/appveyor-download.bat new file mode 100644 index 00000000..5cc2dbbb --- /dev/null +++ b/vendor/MDBC/appveyor-download.bat @@ -0,0 +1,16 @@ +@echo off +set archive=http://ftp.hosteurope.de/mirror/archive.mariadb.org//mariadb-%DB%/winx64-packages/mariadb-%DB%-winx64.msi +set last=http://mirror.i3d.net/pub/mariadb//mariadb-%DB%/winx64-packages/mariadb-%DB%-winx64.msi + +curl -fLsS -o server.msi %archive% + +if %ERRORLEVEL% == 0 goto end + +curl -fLsS -o server.msi %last% +if %ERRORLEVEL% == 0 goto end + +echo Failure Reason Given is %errorlevel% +exit /b %errorlevel% + +:end +echo "File found". diff --git a/vendor/MDBC/appveyor.yml b/vendor/MDBC/appveyor.yml new file mode 100644 index 00000000..9088b993 --- /dev/null +++ b/vendor/MDBC/appveyor.yml @@ -0,0 +1,41 @@ +version: 3.0.8;{build} +branches: + only: + - 3.1 +environment: + matrix: + - DB: '10.2.38' + APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 + CMAKE_PARAM: 'Visual Studio 15 2017 Win64' + - DB: '10.3.29' + APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 + CMAKE_PARAM: 'Visual Studio 15 2017 Win64' + - DB: '10.4.19' + APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 + CMAKE_PARAM: 'Visual Studio 15 2017 Win64' + - DB: '10.5.10' + APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 + CMAKE_PARAM: 'Visual Studio 15 2017 Win64' + + +configuration: RelWithDebInfo +clone_folder: c:\projects\mariadb-connector-c +before_build: + - cmd: appveyor-download.bat + - cmd: msiexec /i server.msi INSTALLDIR=c:\projects\server SERVICENAME=mariadb ALLOWREMOTEROOTACCESS=true /qn + - cmd: "\"c:\\projects\\server\\bin\\mysql.exe\" -e \"create database testc\" --user=root" + - cmd: set MARIADB_CC_TEST=1 + - cmd: set MYSQL_TEST_USER=root + - cmd: set MYSQL_TEST_HOST=127.0.0.1 + - cmd: set MYSQL_TEST_PASSWD= + - cmd: set MYSQL_TEST_PORT=3306 + - cmd: set MYSQL_TEST_DB=testc + - cmd: cmake -G "%CMAKE_PARAM%" -DCMAKE_BUILD_TYPE=RelWithDebInfo +build: + project: mariadb-connector-c.sln + parallel: true + verbosity: minimal +test_script: + - cmd: cd c:\projects\mariadb-connector-c\unittest\libmariadb + - cmd: set MARIADB_PLUGIN_DIR=cd c:\projects\mariadb-connector-c\plugins\lib\RelWithDebInfo + - cmd: ctest -V diff --git a/vendor/MDBC/client/CMakeLists.txt b/vendor/MDBC/client/CMakeLists.txt new file mode 100644 index 00000000..9a610847 --- /dev/null +++ b/vendor/MDBC/client/CMakeLists.txt @@ -0,0 +1,17 @@ +INCLUDE_DIRECTORIES(${CC_SOURCE_DIR}/include) + +IF(WIN32) + SET_VERSION_INFO("TARGET:mariadb_client_plugin_info" + "FILE_TYPE:VFT_APP" + "SOURCE_FILE:client/ma_plugin_info.c" + "ORIGINAL_FILE_NAME:mariadb_client_plugin_info.exe" + "FILE_DESCRIPTION:Client plugin viewer") +ENDIF() + +ADD_EXECUTABLE(mariadb_client_plugin_info ${mariadb_client_plugin_info_RC} ma_plugin_info.c) +TARGET_LINK_LIBRARIES(mariadb_client_plugin_info mariadbclient) + +INSTALL(TARGETS mariadb_client_plugin_info + DESTINATION ${INSTALL_BINDIR} + COMPONENT SharedLibraries) +SIGN_TARGET(mariadb_client_plugin_info) diff --git a/vendor/MDBC/client/ma_plugin_info.c b/vendor/MDBC/client/ma_plugin_info.c new file mode 100644 index 00000000..15951318 --- /dev/null +++ b/vendor/MDBC/client/ma_plugin_info.c @@ -0,0 +1,211 @@ + +#include +#include +#include +#include +#include +#include +#include +#include + +#define CLIENT_PLUGIN_INFO_VERSION "1.0.0" + +static struct option long_options[]= +{ + {"all", no_argument, 0, 'a'}, + {"builtin", no_argument, 0, 'b'}, + {"dynamic", no_argument, 0, 'd'}, + {"directory", 1, 0, 'p'}, + {"plugin_name", 1, 0, 'n'}, + {"version", no_argument, 0, 'v'}, + {"help", no_argument, 0, '?'}, + {NULL, 0, 0, 0} +}; + +static char *values[] = +{ + "show information for all plugins", + "show information for builtin plugins", + "show information for dynamic plugins", + "show information for dynamic plugins in specified directory", + "show information for specified plugin", + "show version information", + "display this help and exit", + NULL +}; + +struct st_plugin_type +{ + int type; + char *typename; +}; + +#ifndef _WIN32 +int my_errno=0; +#endif + +static struct st_plugin_type plugin_types[]= +{ + {MYSQL_CLIENT_AUTHENTICATION_PLUGIN, "authentication"}, + {MARIADB_CLIENT_PVIO_PLUGIN, "virtual IO"}, + {MARIADB_CLIENT_TRACE_PLUGIN, "trace"}, + {MARIADB_CLIENT_REMOTEIO_PLUGIN, "remote file access"}, + {MARIADB_CLIENT_CONNECTION_PLUGIN, "connection handler"}, + {0, "unknown"} +}; + +static void version() +{ + printf("%s Version %s\n", ma_progname, CLIENT_PLUGIN_INFO_VERSION); +} + +static void usage(void) +{ + int i=0; + printf("%s Version %s\n", ma_progname, CLIENT_PLUGIN_INFO_VERSION); + puts("Copyright 2015 MariaDB Corporation AB"); + puts("Show client plugin information for MariaDB Connector/C."); + printf("Usage: %s [OPTIONS] [plugin_name]\n", ma_progname); + while (long_options[i].name) + { + printf(" --%-12s -%s\n", long_options[i].name, values[i]); + i++; + } +} + +static char *ma_get_type_name(int type) +{ + int i=0; + while (plugin_types[i].type) + { + if (type== plugin_types[i].type) + return plugin_types[i].typename; + i++; + } + return plugin_types[i].typename; +} + +static void show_plugin_info(struct st_mysql_client_plugin *plugin, my_bool builtin) +{ + printf("Name: %s\n", plugin->name); + printf("Type: %s\n", ma_get_type_name(plugin->type)); + printf("Desc: %s\n", plugin->desc); + printf("Author: %s\n", plugin->author); + printf("License: %s\n", plugin->license); + printf("Version: %d.%d.%d\n", plugin->version[0], plugin->version[1], plugin->version[2]); + printf("API Version: 0x%04X\n", plugin->interface_version); + printf("Build type: %s\n", builtin ? "builtin" : "dynamic"); + printf("\n"); +} + +static void show_builtin() +{ + struct st_mysql_client_plugin **builtin; + + for (builtin= mysql_client_builtins; *builtin; builtin++) + show_plugin_info(*builtin, TRUE); +} + +static void show_file(char *filename) +{ + char dlpath[FN_REFLEN+1]; + void *sym, *dlhandle; + struct st_mysql_client_plugin *plugin; + char *env_plugin_dir= getenv("MARIADB_PLUGIN_DIR"); + char *has_so_ext= strstr(filename, SO_EXT); + + if (!strchr(filename, FN_LIBCHAR)) + snprintf(dlpath, sizeof(dlpath) - 1, "%s/%s%s", + (env_plugin_dir) ? env_plugin_dir : PLUGINDIR, + filename, + has_so_ext ? "" : SO_EXT); + else + strcpy(dlpath, filename); + if ((dlhandle= dlopen((const char *)dlpath, RTLD_NOW))) + { + if (sym= dlsym(dlhandle, plugin_declarations_sym)) + { + plugin= (struct st_mysql_client_plugin *)sym; + show_plugin_info(plugin, 0); + } + dlclose(dlhandle); + } +} + +static void show_dynamic(const char *directory) +{ + MY_DIR *dir= NULL; + unsigned int i; + char *plugin_dir= directory ? (char *)directory : getenv("MARIADB_PLUGIN_DIR"); + + if (!plugin_dir) + plugin_dir= PLUGINDIR; + + printf("plugin_dir %s\n", plugin_dir); + + dir= my_dir(plugin_dir, 0); + + if (!dir || !dir->number_off_files) + { + printf("No plugins found in %s\n", plugin_dir); + goto end; + } + + for (i=0; i < dir->number_off_files; i++) + { + char *p= strstr(dir->dir_entry[i].name, SO_EXT); + if (p) + show_file(dir->dir_entry[i].name); + } +end: + if (dir) + my_dirend(dir); +} + +int main(int argc, char *argv[]) +{ + int option_index= 0; + int c; + ma_progname= argv[0]; + + mysql_server_init(0, NULL, NULL); + + if (argc <= 1) + { + usage(); + exit(1); + } + + c= getopt_long(argc, argv, "bdapnvh?", long_options, &option_index); + + switch(c) { + case 'a': /* all */ + show_builtin(); + show_dynamic(NULL); + break; + case 'b': /* builtin */ + show_builtin(); + break; + case 'd': /* dynamic */ + show_dynamic(NULL); + break; + case 'v': + version(); + break; + case 'n': + if (argc > 2) + show_file(argv[2]); + break; + case 'p': + if (argc > 2) + show_dynamic(argv[2]); + break; + case '?': + usage(); + break; + default: + printf("unrecocognized option: %s", argv[1]); + exit(1); + } + exit(0); +} diff --git a/vendor/MDBC/cmake/COPYING-CMAKE-SCRIPTS b/vendor/MDBC/cmake/COPYING-CMAKE-SCRIPTS new file mode 100644 index 00000000..4b417765 --- /dev/null +++ b/vendor/MDBC/cmake/COPYING-CMAKE-SCRIPTS @@ -0,0 +1,22 @@ +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + +1. Redistributions of source code must retain the copyright + notice, this list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. +3. The name of the author may not be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/vendor/MDBC/cmake/CheckFunctions.cmake b/vendor/MDBC/cmake/CheckFunctions.cmake new file mode 100644 index 00000000..5ea949eb --- /dev/null +++ b/vendor/MDBC/cmake/CheckFunctions.cmake @@ -0,0 +1,30 @@ +# +# Copyright (C) 2013-2016 MariaDB Corporation AB +# +# Redistribution and use is allowed according to the terms of the New +# BSD license. +# For details see the COPYING-CMAKE-SCRIPTS file. +# + +# This file is included by CMakeLists.txt and +# checks for various functions. +# You will find the appropriate defines in +# include/my_config.h.in + +INCLUDE(CheckFunctionExists) + +CHECK_FUNCTION_EXISTS (alloca HAVE_ALLOCA) +CHECK_FUNCTION_EXISTS (dlerror HAVE_DLERROR) +CHECK_FUNCTION_EXISTS (dlopen HAVE_DLOPEN) +CHECK_FUNCTION_EXISTS (fcntl HAVE_FCNTL) +CHECK_FUNCTION_EXISTS (memcpy HAVE_MEMCPY) +CHECK_FUNCTION_EXISTS (nl_langinfo HAVE_NL_LANGINFO) +CHECK_FUNCTION_EXISTS (setlocale HAVE_SETLOCALE) +CHECK_FUNCTION_EXISTS (poll HAVE_POLL) +CHECK_FUNCTION_EXISTS (getpwuid HAVE_GETPWUID) + +IF(HAVE_FILE_UCONTEXT_H) + CHECK_FUNCTION_EXISTS (makecontext HAVE_UCONTEXT_H) +ENDIF() + +CHECK_FUNCTION_EXISTS (cuserid HAVE_CUSERID) \ No newline at end of file diff --git a/vendor/MDBC/cmake/CheckIncludeFiles.cmake b/vendor/MDBC/cmake/CheckIncludeFiles.cmake new file mode 100644 index 00000000..8151dde5 --- /dev/null +++ b/vendor/MDBC/cmake/CheckIncludeFiles.cmake @@ -0,0 +1,58 @@ +# +# Copyright (C) 2013-2016 MariaDB Corporation AB +# +# Redistribution and use is allowed according to the terms of the New +# BSD license. +# For details see the COPYING-CMAKE-SCRIPTS file. +# +# This file is included by CMakeLists.txt and +# checks for various header files. +# You will find the appropriate defines in +# include/my_config.h.in + +INCLUDE(CheckIncludeFiles) + +CHECK_INCLUDE_FILES (alloca.h HAVE_ALLOCA_H) +CHECK_INCLUDE_FILES (arpa/inet.h HAVE_ARPA_INET_H) +CHECK_INCLUDE_FILES (dlfcn.h HAVE_DLFCN_H) +CHECK_INCLUDE_FILES (fcntl.h HAVE_FCNTL_H) +CHECK_INCLUDE_FILES (float.h HAVE_FLOAT_H) +CHECK_INCLUDE_FILES (limits.h HAVE_LIMITS_H) +CHECK_INCLUDE_FILES (linux/limits.h HAVE_LINUX_LIMITS_H) +CHECK_INCLUDE_FILES (pwd.h HAVE_PWD_H) +CHECK_INCLUDE_FILES (sched.h HAVE_SCHED_H) +CHECK_INCLUDE_FILES (select.h HAVE_SELECT_H) + +CHECK_INCLUDE_FILES (signal.h INCLUDE_SIGNAL) +IF(INCLUDE_SIGNAL) + SET(HAVE_SIGNAL 1) + SET(CMAKE_EXTRA_INCLUDE_FILES signal.h) +ENDIF(INCLUDE_SIGNAL) + +CHECK_INCLUDE_FILES (stddef.h HAVE_STDDEF_H) + +CHECK_INCLUDE_FILES (stdint.h HAVE_STDINT_H) +IF(HAVE_STDINT_H) + SET(CMAKE_EXTRA_INCLUDE_FILES stdint.h) +ENDIF(HAVE_STDINT_H) + +CHECK_INCLUDE_FILES (stdlib.h HAVE_STDLIB_H) +CHECK_INCLUDE_FILES (string.h HAVE_STRING_H) +CHECK_INCLUDE_FILES (strings.h HAVE_STRINGS_H) + +CHECK_INCLUDE_FILES (sys/ioctl.h HAVE_SYS_IOCTL_H) +CHECK_INCLUDE_FILES (sys/select.h HAVE_SYS_SELECT_H) +CHECK_INCLUDE_FILES (sys/socket.h HAVE_SYS_SOCKET_H) +CHECK_INCLUDE_FILES (sys/types.h HAVE_SYS_TYPES_H) +CHECK_INCLUDE_FILES (sys/stat.h HAVE_SYS_STAT_H) +CHECK_INCLUDE_FILES (sys/un.h HAVE_SYS_UN_H) +CHECK_INCLUDE_FILES (unistd.h HAVE_UNISTD_H) +CHECK_INCLUDE_FILES (utime.h HAVE_UTIME_H) + +IF(APPLE) + SET(CMAKE_REQUIRED_DEFINITIONS -D_XOPEN_SOURCE=600) +ENDIF() +CHECK_INCLUDE_FILES (ucontext.h HAVE_FILE_UCONTEXT_H) +IF(NOT HAVE_FILE_UCONTEXT_H) + CHECK_INCLUDE_FILES (sys/ucontext.h HAVE_FILE_UCONTEXT_H) +ENDIF() diff --git a/vendor/MDBC/cmake/CheckTypes.cmake b/vendor/MDBC/cmake/CheckTypes.cmake new file mode 100644 index 00000000..2a47cc0c --- /dev/null +++ b/vendor/MDBC/cmake/CheckTypes.cmake @@ -0,0 +1,62 @@ +# +# Copyright (C) 2013-2016 MariaDB Corporation AB +# +# Redistribution and use is allowed according to the terms of the New +# BSD license. +# For details see the COPYING-CMAKE-SCRIPTS file. +# +# This file is included by CMakeLists.txt and +# checks for type sizes. +# You will find the appropriate defines in +# include/my_config.h.in +INCLUDE (CheckTypeSize) + +SET(CMAKE_EXTRA_INCLUDE_FILES signal.h) + +CHECK_TYPE_SIZE("char *" SIZEOF_CHARP) +CHECK_TYPE_SIZE(int SIZEOF_INT) +CHECK_TYPE_SIZE(long SIZEOF_LONG) +CHECK_TYPE_SIZE("long long" SIZEOF_LONG_LONG) +SET(CMAKE_EXTRA_INCLUDE_FILES stdio.h) +CHECK_TYPE_SIZE(size_t SIZEOF_SIZE_T) +SET(CMAKE_EXTRA_INCLUDE_FILES sys/types.h) +CHECK_TYPE_SIZE(uchar SIZEOF_UCHAR) +CHECK_TYPE_SIZE(uint SIZEOF_UINT) +CHECK_TYPE_SIZE(ulong SIZEOF_ULONG) +CHECK_TYPE_SIZE(int8 SIZEOF_INT8) +CHECK_TYPE_SIZE(uint8 SIZEOF_UINT8) +CHECK_TYPE_SIZE(int16 SIZEOF_INT16) +CHECK_TYPE_SIZE(uint16 SIZEOF_UINT16) +CHECK_TYPE_SIZE(int32 SIZEOF_INT32) +CHECK_TYPE_SIZE(uint32 SIZEOF_UINT32) +CHECK_TYPE_SIZE(int64 SIZEOF_INT64) +CHECK_TYPE_SIZE(uint64 SIZEOF_UINT64) +CHECK_TYPE_SIZE(socklen_t SIZEOF_SOCKLEN_T) + +# +# Compile testing +# +INCLUDE (CheckCSourceCompiles) + +# +# SOCKET_SIZE +# +IF(WIN32) + SET(SOCKET_SIZE_TYPE int) +ELSE(WIN32) + FOREACH(CHECK_TYPE "socklen_t" "size_t" "int") + IF (NOT SOCKET_SIZE_TYPE) + CHECK_C_SOURCE_COMPILES(" + #include + int main(int argc, char **argv) + { + getsockname(0, 0, (${CHECK_TYPE} *)0); + return 0; + }" + SOCKET_SIZE_FOUND_${CHECK_TYPE}) + IF(SOCKET_SIZE_FOUND_${CHECK_TYPE}) + SET(SOCKET_SIZE_TYPE ${CHECK_TYPE}) + ENDIF(SOCKET_SIZE_FOUND_${CHECK_TYPE}) + ENDIF (NOT SOCKET_SIZE_TYPE) + ENDFOREACH() +ENDIF(WIN32) diff --git a/vendor/MDBC/cmake/ConnectorName.cmake b/vendor/MDBC/cmake/ConnectorName.cmake new file mode 100644 index 00000000..3044aeec --- /dev/null +++ b/vendor/MDBC/cmake/ConnectorName.cmake @@ -0,0 +1,34 @@ +# +# Copyright (C) 2013-2016 MariaDB Corporation AB +# +# Redistribution and use is allowed according to the terms of the New +# BSD license. +# For details see the COPYING-CMAKE-SCRIPTS file. +# +MACRO(GET_CONNECTOR_PACKAGE_NAME name) +# check if we have 64bit +IF(SIZEOF_VOIDP EQUAL 8) + SET(IS64 1) +ENDIF() + +SET (PLAFORM_NAME CMAKE_SYSTEM_NAME) +SET (MACHINE_NAME CMAKE_SYSTEM_PROCESSOR) +SET (CONCAT_SIGN "-") + +IF(CMAKE_SYSTEM_NAME MATCHES "Windows") + SET(PLATFORM_NAME "win") + SET(CONCAT_SIGN "") + IF(IS64) + IF(CMAKE_C_COMPILER_ARCHITECTURE_ID) + STRING(TOLOWER "${CMAKE_C_COMPILER_ARCHITECTURE_ID}" MACHINE_NAME) + ELSE() + SET(MACHINE_NAME x64) + ENDIF() + ELSE() + SET(MACHINE_NAME "32") + ENDIF() +ENDIF() + +SET(product_name "mysql-connector-c-${CPACK_PACKAGE_VERSION}-${PLATFORM_NAME}${CONCAT_SIGN}${MACHINE_NAME}") +STRING(TOLOWER ${product_name} ${name}) +ENDMACRO() diff --git a/vendor/MDBC/cmake/FindGSSAPI.cmake b/vendor/MDBC/cmake/FindGSSAPI.cmake new file mode 100644 index 00000000..7941c20e --- /dev/null +++ b/vendor/MDBC/cmake/FindGSSAPI.cmake @@ -0,0 +1,110 @@ +# +# Copyright (C) 2013-2016 MariaDB Corporation AB +# +# Redistribution and use is allowed according to the terms of the New +# BSD license. +# For details see the COPYING-CMAKE-SCRIPTS file. +# +# - Try to detect the GSSAPI support +# Once done this will define +# +# GSSAPI_FOUND - system supports GSSAPI +# GSSAPI_INCS - the GSSAPI include directory +# GSSAPI_LIBS - the libraries needed to use GSSAPI +# GSSAPI_FLAVOR - the type of API - MIT or HEIMDAL + +# Copyright (c) 2006, Pino Toscano, +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# 3. The name of the author may not be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +if(GSSAPI_LIBS AND GSSAPI_FLAVOR) + + # in cache already + set(GSSAPI_FOUND TRUE) + +else(GSSAPI_LIBS AND GSSAPI_FLAVOR) + + find_program(KRB5_CONFIG NAMES krb5-config PATHS + /opt/local/bin + /usr/lib/mit/bin/ + ONLY_CMAKE_FIND_ROOT_PATH # this is required when cross compiling with cmake 2.6 and ignored with cmake 2.4, Alex + ) + mark_as_advanced(KRB5_CONFIG) + + #reset vars + set(GSSAPI_INCS) + set(GSSAPI_LIBS) + set(GSSAPI_FLAVOR) + + if(KRB5_CONFIG) + + set(HAVE_KRB5_GSSAPI TRUE) + exec_program(${KRB5_CONFIG} ARGS --libs gssapi RETURN_VALUE _return_VALUE OUTPUT_VARIABLE GSSAPI_LIBS) + if(_return_VALUE) + message(STATUS "GSSAPI configure check failed.") + set(HAVE_KRB5_GSSAPI FALSE) + endif(_return_VALUE) + IF(CMAKE_SYSTEM_NAME MATCHES AIX) + string(REGEX REPLACE "-Wl[A-Za-z0-9_/,:-]*[ $]?" "" GSSAPI_LIBS "${GSSAPI_LIBS}") + string(REGEX REPLACE "-L[A-Za-z0-9_/,:-]*[ $]?" "" GSSAPI_LIBS "${GSSAPI_LIBS}") + ENDIF() + + exec_program(${KRB5_CONFIG} ARGS --cflags gssapi RETURN_VALUE _return_VALUE OUTPUT_VARIABLE GSSAPI_INCS) + string(REGEX REPLACE "(\r?\n)+$" "" GSSAPI_INCS "${GSSAPI_INCS}") + string(REGEX REPLACE " *-I" ";" GSSAPI_INCS "${GSSAPI_INCS}") + + exec_program(${KRB5_CONFIG} ARGS --vendor RETURN_VALUE _return_VALUE OUTPUT_VARIABLE gssapi_flavor_tmp) + set(GSSAPI_FLAVOR_MIT) + if(gssapi_flavor_tmp MATCHES ".*Massachusetts.*") + set(GSSAPI_FLAVOR "MIT") + else(gssapi_flavor_tmp MATCHES ".*Massachusetts.*") + set(GSSAPI_FLAVOR "HEIMDAL") + endif(gssapi_flavor_tmp MATCHES ".*Massachusetts.*") + + if(NOT HAVE_KRB5_GSSAPI) + if (gssapi_flavor_tmp MATCHES "Sun Microsystems.*") + message(STATUS "Solaris Kerberos does not have GSSAPI; this is normal.") + set(GSSAPI_LIBS) + set(GSSAPI_INCS) + else(gssapi_flavor_tmp MATCHES "Sun Microsystems.*") + message(WARNING "${KRB5_CONFIG} failed unexpectedly.") + endif(gssapi_flavor_tmp MATCHES "Sun Microsystems.*") + endif(NOT HAVE_KRB5_GSSAPI) + + if(GSSAPI_LIBS) # GSSAPI_INCS can be also empty, so don't rely on that + set(GSSAPI_FOUND TRUE CACHE STRING "") + message(STATUS "Found GSSAPI: ${GSSAPI_LIBS}") + + set(GSSAPI_INCS ${GSSAPI_INCS} CACHE STRING "") + set(GSSAPI_LIBS ${GSSAPI_LIBS} CACHE STRING "") + set(GSSAPI_FLAVOR ${GSSAPI_FLAVOR} CACHE STRING "") + + mark_as_advanced(GSSAPI_INCS GSSAPI_LIBS GSSAPI_FLAVOR) + + endif(GSSAPI_LIBS) + + endif(KRB5_CONFIG) + +endif(GSSAPI_LIBS AND GSSAPI_FLAVOR) diff --git a/vendor/MDBC/cmake/FindIconv.cmake b/vendor/MDBC/cmake/FindIconv.cmake new file mode 100644 index 00000000..dbc7369b --- /dev/null +++ b/vendor/MDBC/cmake/FindIconv.cmake @@ -0,0 +1,82 @@ +# +# Copyright (C) 2010 Michael Bell +# 2015-2016 MariaDB Corporation AB +# +# Redistribution and use is allowed according to the terms of the New +# BSD license. +# For details see the COPYING-CMAKE-SCRIPTS file. +# +# ICONV_EXTERNAL - Iconv is an external library (not libc) +# ICONV_FOUND - system has Iconv +# ICONV_INCLUDE_DIR - the Iconv include directory +# ICONV_LIBRARIES - Link these to use Iconv +# ICONV_SECOND_ARGUMENT_IS_CONST - the second argument for iconv() is const +# ICONV_VERSION - Iconv version string + +if (ICONV_INCLUDE_DIR AND ICONV_LIBRARIES) + # Already in cache, be silent + set(ICONV_FIND_QUIETLY TRUE) +endif (ICONV_INCLUDE_DIR AND ICONV_LIBRARIES) + +find_path(ICONV_INCLUDE_DIR iconv.h) + +IF(CMAKE_SYSTEM_NAME MATCHES "SunOS") + # There is some libiconv.so in /usr/local that must + # be avoided, iconv routines are in libc +ELSEIF(APPLE) + find_library(ICONV_LIBRARIES NAMES iconv libiconv PATHS + /usr/lib/ + NO_CMAKE_SYSTEM_PATH) + SET(ICONV_EXTERNAL TRUE) +ELSE() + find_library(ICONV_LIBRARIES NAMES iconv libiconv libiconv-2) + IF(ICONV_LIBRARIES) + SET(ICONV_EXTERNAL TRUE) + ENDIF() +ENDIF() + +if (ICONV_INCLUDE_DIR AND ICONV_LIBRARIES) + set (ICONV_FOUND TRUE) +endif (ICONV_INCLUDE_DIR AND ICONV_LIBRARIES) + +set(CMAKE_REQUIRED_INCLUDES ${ICONV_INCLUDE_DIR}) +IF(ICONV_EXTERNAL) + set(CMAKE_REQUIRED_LIBRARIES ${ICONV_LIBRARIES}) +ENDIF() + +if (ICONV_FOUND) + include(CheckCSourceCompiles) + CHECK_C_SOURCE_COMPILES(" + #include + int main(){ + iconv_t conv = 0; + const char* in = 0; + size_t ilen = 0; + char* out = 0; + size_t olen = 0; + iconv(conv, &in, &ilen, &out, &olen); + return 0; + } +" ICONV_SECOND_ARGUMENT_IS_CONST ) + ADD_DEFINITIONS(-DHAVE_ICONV) +endif (ICONV_FOUND) + +set (CMAKE_REQUIRED_INCLUDES) +set (CMAKE_REQUIRED_LIBRARIES) + +if (ICONV_FOUND) + if (NOT ICONV_FIND_QUIETLY) + message (STATUS "Found Iconv: ${ICONV_LIBRARIES}") + endif (NOT ICONV_FIND_QUIETLY) +else (ICONV_FOUND) + if (Iconv_FIND_REQUIRED) + message (FATAL_ERROR "Could not find Iconv") + endif (Iconv_FIND_REQUIRED) +endif (ICONV_FOUND) + +MARK_AS_ADVANCED( + ICONV_INCLUDE_DIR + ICONV_LIBRARIES + ICONV_EXTERNAL + ICONV_SECOND_ARGUMENT_IS_CONST +) diff --git a/vendor/MDBC/cmake/SearchLibrary.cmake b/vendor/MDBC/cmake/SearchLibrary.cmake new file mode 100644 index 00000000..aa3a240e --- /dev/null +++ b/vendor/MDBC/cmake/SearchLibrary.cmake @@ -0,0 +1,29 @@ +# +# Copyright (C) 2013-2016 MariaDB Corporation AB +# +# Redistribution and use is allowed according to the terms of the New +# BSD license. +# For details see the COPYING-CMAKE-SCRIPTS file. +# +INCLUDE(CheckFunctionExists) +INCLUDE(CheckLibraryExists) + +FUNCTION(SEARCH_LIBRARY library_name function liblist) + IF(${${library_name}}) + RETURN() + ENDIF() + CHECK_FUNCTION_EXISTS(${function} IS_${function}_LIBC_FUNC) + IF(IS_${function}_LIBC_FUNC) + SET(${library_name} "" PARENT_SCOPE) + RETURN() + ENDIF() + FOREACH(lib ${liblist}) + CHECK_LIBRARY_EXISTS(${lib} ${function} "" HAVE_${function}_IN_${lib}) + IF(HAVE_${function}_IN_${lib}) + SET(${library_name} ${lib} PARENT_SCOPE) + SET(HAVE_${library_name} 1 PARENT_SCOPE) + RETURN() + ENDIF() + ENDFOREACH() +ENDFUNCTION() + diff --git a/vendor/MDBC/cmake/WindowsCache.cmake b/vendor/MDBC/cmake/WindowsCache.cmake new file mode 100644 index 00000000..5323f78a --- /dev/null +++ b/vendor/MDBC/cmake/WindowsCache.cmake @@ -0,0 +1,392 @@ +# +# Copyright (C) 2013-2016 MariaDB Corporation AB +# +# Redistribution and use is allowed according to the terms of the New +# BSD license. +# For details see the COPYING-CMAKE-SCRIPTS file. +# +IF(MSVC) +SET(BFD_H_EXISTS 0 CACHE INTERNAL "") +SET(HAVE_ACCESS 1 CACHE INTERNAL "") +SET(HAVE_AIO_H CACHE INTERNAL "") +SET(HAVE_AIO_READ CACHE INTERNAL "") +SET(HAVE_ALARM CACHE INTERNAL "") +SET(HAVE_ALLOCA_H CACHE INTERNAL "") +SET(HAVE_ARPA_INET_H CACHE INTERNAL "") +SET(HAVE_ASM_MSR_H CACHE INTERNAL "") +SET(HAVE_BACKTRACE CACHE INTERNAL "") +SET(HAVE_BACKTRACE_SYMBOLS CACHE INTERNAL "") +SET(HAVE_BACKTRACE_SYMBOLS_FD CACHE INTERNAL "") +SET(HAVE_BFILL CACHE INTERNAL "") +SET(HAVE_BMOVE CACHE INTERNAL "") +SET(HAVE_BSD_SIGNALS CACHE INTERNAL "") +SET(HAVE_BSEARCH 1 CACHE INTERNAL "") +SET(HAVE_BSS_START CACHE INTERNAL "") +SET(HAVE_BZERO CACHE INTERNAL "") +SET(HAVE_CHOWN CACHE INTERNAL "") +SET(HAVE_CLOCK_GETTIME CACHE INTERNAL "") +SET(HAVE_COMPRESS CACHE INTERNAL "") +SET(HAVE_CRYPT CACHE INTERNAL "") +SET(HAVE_CRYPT_H CACHE INTERNAL "") +SET(HAVE_CUSERID CACHE INTERNAL "") +SET(HAVE_CXX_NEW 1 CACHE INTERNAL "") +SET(HAVE_DECL_MADVISE CACHE INTERNAL "") +SET(HAVE_DIRECTIO CACHE INTERNAL "") +SET(HAVE_DIRENT_H CACHE INTERNAL "") +SET(HAVE_DLERROR CACHE INTERNAL "") +SET(HAVE_DLFCN_H CACHE INTERNAL "") +SET(HAVE_DLOPEN CACHE INTERNAL "") +SET(HAVE_DOPRNT CACHE INTERNAL "") +SET(HAVE_EXECINFO_H CACHE INTERNAL "") +SET(HAVE_FCHMOD CACHE INTERNAL "") +SET(HAVE_FCNTL CACHE INTERNAL "") +SET(HAVE_FCNTL_H 1 CACHE INTERNAL "") +SET(HAVE_FCNTL_NONBLOCK CACHE INTERNAL "") +SET(HAVE_FCONVERT CACHE INTERNAL "") +SET(HAVE_FDATASYNC CACHE INTERNAL "") +SET(HAVE_DECL_FDATASYNC CACHE INTERNAL "") +SET(HAVE_FEDISABLEEXCEPT CACHE INTERNAL "") +SET(HAVE_FENV_H CACHE INTERNAL "") +SET(HAVE_FESETROUND CACHE INTERNAL "") +SET(HAVE_FGETLN CACHE INTERNAL "") +SET(HAVE_FINITE CACHE INTERNAL "") +SET(HAVE_FINITE_IN_MATH_H CACHE INTERNAL "") +SET(HAVE_FLOATINGPOINT_H CACHE INTERNAL "") +SET(HAVE_FLOAT_H 1 CACHE INTERNAL "") +SET(HAVE_FLOCKFILE CACHE INTERNAL "") +SET(HAVE_FNMATCH_H CACHE INTERNAL "") +SET(HAVE_FPSETMASK CACHE INTERNAL "") +SET(HAVE_FPU_CONTROL_H CACHE INTERNAL "") +SET(HAVE_FSEEKO CACHE INTERNAL "") +SET(HAVE_FSYNC CACHE INTERNAL "") +SET(HAVE_FTIME 1 CACHE INTERNAL "") +SET(HAVE_FTRUNCATE CACHE INTERNAL "") +SET(HAVE_GETADDRINFO 1 CACHE INTERNAL "") +SET(HAVE_GETCWD 1 CACHE INTERNAL "") +SET(HAVE_GETHOSTBYADDR_R CACHE INTERNAL "") +SET(HAVE_GETHRTIME CACHE INTERNAL "") +SET(HAVE_GETLINE CACHE INTERNAL "") +SET(HAVE_GETNAMEINFO CACHE INTERNAL "") +SET(HAVE_GETPAGESIZE CACHE INTERNAL "") +SET(HAVE_GETPASS CACHE INTERNAL "") +SET(HAVE_GETPASSPHRASE CACHE INTERNAL "") +SET(HAVE_GETPWNAM CACHE INTERNAL "") +SET(HAVE_GETPWUID CACHE INTERNAL "") +SET(HAVE_GETRLIMIT CACHE INTERNAL "") +SET(HAVE_GETRUSAGE CACHE INTERNAL "") +SET(HAVE_GETTIMEOFDAY CACHE INTERNAL "") +SET(HAVE_GETWD CACHE INTERNAL "") +SET(HAVE_GRP_H CACHE INTERNAL "") +SET(HAVE_IA64INTRIN_H CACHE INTERNAL "") +SET(HAVE_IEEEFP_H CACHE INTERNAL "") +SET(HAVE_INDEX CACHE INTERNAL "") +SET(HAVE_INITGROUPS CACHE INTERNAL "") +SET(HAVE_INTTYPES_H CACHE INTERNAL "") +SET(HAVE_IPPROTO_IPV6 CACHE INTERNAL "") +SET(HAVE_IPV6 TRUE CACHE INTERNAL "") +SET(HAVE_IPV6_V6ONLY 1 CACHE INTERNAL "") +SET(HAVE_ISINF CACHE INTERNAL "") +SET(HAVE_ISSETUGID CACHE INTERNAL "") +SET(HAVE_GETUID CACHE INTERNAL "") +SET(HAVE_GETEUID CACHE INTERNAL "") +SET(HAVE_GETGID CACHE INTERNAL "") +SET(HAVE_GETEGID CACHE INTERNAL "") +SET(HAVE_LANGINFO_H CACHE INTERNAL "") +SET(HAVE_LDIV 1 CACHE INTERNAL "") +SET(HAVE_LIMITS_H 1 CACHE INTERNAL "") +SET(HAVE_LOCALE_H 1 CACHE INTERNAL "") +SET(HAVE_LOG2 CACHE INTERNAL "") +SET(HAVE_LONGJMP 1 CACHE INTERNAL "") +SET(HAVE_LRAND48 CACHE INTERNAL "") +SET(HAVE_LSTAT CACHE INTERNAL "") +SET(HAVE_MADVISE CACHE INTERNAL "") +SET(HAVE_MALLINFO CACHE INTERNAL "") +SET(HAVE_MALLOC_H 1 CACHE INTERNAL "") +SET(HAVE_MEMALIGN CACHE INTERNAL "") +SET(HAVE_MEMCPY 1 CACHE INTERNAL "") +SET(HAVE_MEMMOVE 1 CACHE INTERNAL "") +SET(HAVE_MEMORY_H 1 CACHE INTERNAL "") +SET(HAVE_MKSTEMP CACHE INTERNAL "") +SET(HAVE_MLOCK CACHE INTERNAL "") +SET(HAVE_MLOCKALL CACHE INTERNAL "") +SET(HAVE_MMAP CACHE INTERNAL "") +SET(HAVE_MMAP64 CACHE INTERNAL "") +SET(HAVE_NETDB_H CACHE INTERNAL "") +SET(HAVE_NETINET_IN6_H CACHE INTERNAL "") +SET(HAVE_NETINET_IN_H CACHE INTERNAL "") +SET(HAVE_NL_LANGINFO CACHE INTERNAL "") +SET(HAVE_PASE_ENVIRONMENT CACHE INTERNAL "") +SET(HAVE_PATHS_H CACHE INTERNAL "") +SET(HAVE_PCLOSE CACHE INTERNAL "") +SET(HAVE_PERROR 1 CACHE INTERNAL "") +SET(HAVE_PEERCRED CACHE INTERNAL "") +SET(HAVE_PAM_APPL_H CACHE INTERNAL "") +SET(HAVE_POLL_H CACHE INTERNAL "") +SET(HAVE_POPEN CACHE INTERNAL "") +SET(HAVE_POLL CACHE INTERNAL "") +SET(HAVE_PORT_CREATE CACHE INTERNAL "") +SET(HAVE_PORT_H CACHE INTERNAL "") +SET(HAVE_POSIX_FALLOCATE CACHE INTERNAL "") +SET(HAVE_POSIX_SIGNALS CACHE INTERNAL "") +SET(HAVE_PREAD CACHE INTERNAL "") +SET(HAVE_PRINTSTACK CACHE INTERNAL "") +SET(HAVE_PTHREAD_ATTR_CREATE CACHE INTERNAL "") +SET(HAVE_PTHREAD_ATTR_GETSTACKSIZE CACHE INTERNAL "") +SET(HAVE_PTHREAD_ATTR_SETSCOPE CACHE INTERNAL "") +SET(HAVE_PTHREAD_ATTR_SETSTACKSIZE CACHE INTERNAL "") +SET(HAVE_PTHREAD_CONDATTR_CREATE CACHE INTERNAL "") +SET(HAVE_PTHREAD_CONDATTR_SETCLOCK CACHE INTERNAL "") +SET(HAVE_PTHREAD_INIT CACHE INTERNAL "") +SET(HAVE_PTHREAD_KEY_DELETE CACHE INTERNAL "") +SET(HAVE_PTHREAD_RWLOCK_RDLOCK CACHE INTERNAL "") +SET(HAVE_PTHREAD_SIGMASK CACHE INTERNAL "") +SET(HAVE_PTHREAD_THREADMASK CACHE INTERNAL "") +SET(HAVE_PTHREAD_YIELD_NP CACHE INTERNAL "") +SET(HAVE_PTHREAD_YIELD_ZERO_ARG CACHE INTERNAL "") +SET(HAVE_PUTENV 1 CACHE INTERNAL "") +SET(HAVE_PWD_H CACHE INTERNAL "") +SET(HAVE_RDTSCLL CACHE INTERNAL "") +SET(HAVE_READDIR_R CACHE INTERNAL "") +SET(HAVE_READLINK CACHE INTERNAL "") +SET(HAVE_READ_REAL_TIME CACHE INTERNAL "") +SET(HAVE_REALPATH CACHE INTERNAL "") +SET(HAVE_REGCOMP CACHE INTERNAL "") +SET(HAVE_RENAME 1 CACHE INTERNAL "") +SET(HAVE_RE_COMP CACHE INTERNAL "") +SET(HAVE_RINT CACHE INTERNAL "") +SET(HAVE_RWLOCK_INIT CACHE INTERNAL "") +SET(HAVE_SCHED_H CACHE INTERNAL "") +SET(HAVE_SCHED_YIELD CACHE INTERNAL "") +SET(HAVE_SELECT 1 CACHE INTERNAL "") +SET(HAVE_SELECT_H CACHE INTERNAL "") +SET(HAVE_SEMAPHORE_H CACHE INTERNAL "") +SET(HAVE_SETENV CACHE INTERNAL "") +SET(HAVE_SETFD CACHE INTERNAL "") +SET(HAVE_SETLOCALE 1 CACHE INTERNAL "") +SET(HAVE_SHMAT CACHE INTERNAL "") +SET(HAVE_SHMCTL CACHE INTERNAL "") +SET(HAVE_SHMDT CACHE INTERNAL "") +SET(HAVE_SHMGET CACHE INTERNAL "") +SET(HAVE_SIGACTION CACHE INTERNAL "") +SET(HAVE_SIGADDSET CACHE INTERNAL "") +SET(HAVE_SIGEMPTYSET CACHE INTERNAL "") +SET(HAVE_SIGHOLD CACHE INTERNAL "") +SET(HAVE_SIGINT 1 CACHE INTERNAL "") +SET(HAVE_SIGPIPE CACHE INTERNAL "") +SET(HAVE_SIGQUIT CACHE INTERNAL "") +SET(HAVE_SIGSET CACHE INTERNAL "") +SET(HAVE_SIGTERM 1 CACHE INTERNAL "") +SET(HAVE_SIGTHREADMASK CACHE INTERNAL "") +SET(HAVE_SIGWAIT CACHE INTERNAL "") +SET(HAVE_SIZEOF_BOOL FALSE CACHE INTERNAL "") +SET(HAVE_SIZEOF_CHAR TRUE CACHE INTERNAL "") +SET(SIZEOF_CHAR 1 CACHE INTERNAL "") +SET(HAVE_SIZEOF_CHARP TRUE CACHE INTERNAL "") +SET(SIZEOF_CHARP ${CMAKE_SIZEOF_VOID_P} CACHE INTERNAL "") +SET(HAVE_SIZEOF_IN6_ADDR TRUE CACHE INTERNAL "") +SET(HAVE_SIZEOF_INT TRUE CACHE INTERNAL "") +SET(SIZEOF_INT 4 CACHE INTERNAL "") +SET(HAVE_SIZEOF_INT16 FALSE CACHE INTERNAL "") +SET(HAVE_SIZEOF_INT32 FALSE CACHE INTERNAL "") +SET(HAVE_SIZEOF_INT64 FALSE CACHE INTERNAL "") +SET(HAVE_SIZEOF_INT8 FALSE CACHE INTERNAL "") +SET(HAVE_SIZEOF_LONG TRUE CACHE INTERNAL "") +SET(SIZEOF_LONG 4 CACHE INTERNAL "") +SET(HAVE_SIZEOF_LONG_LONG TRUE CACHE INTERNAL "") +SET(SIZEOF_LONG_LONG 8 CACHE INTERNAL "") +SET(HAVE_SIZEOF_MODE_T FALSE CACHE INTERNAL "") +SET(HAVE_SIZEOF_OFF_T TRUE CACHE INTERNAL "") +SET(SIZEOF_OFF_T 4 CACHE INTERNAL "") +SET(HAVE_SIZEOF_SHORT TRUE CACHE INTERNAL "") +SET(SIZEOF_SHORT 2 CACHE INTERNAL "") +SET(HAVE_SIZEOF_SIGSET_T FALSE CACHE INTERNAL "") +SET(HAVE_SIZEOF_SIZE_T TRUE CACHE INTERNAL "") +SET(SIZEOF_SIZE_T ${CMAKE_SIZEOF_VOID_P} CACHE INTERNAL "") +SET(HAVE_SIZEOF_SOCKADDR_IN6 TRUE CACHE INTERNAL "") +SET(HAVE_SIZEOF_SOCKLEN_T FALSE CACHE INTERNAL "") +SET(HAVE_SIZEOF_UCHAR FALSE CACHE INTERNAL "") +SET(HAVE_SIZEOF_UINT FALSE CACHE INTERNAL "") +SET(HAVE_SIZEOF_UINT16 FALSE CACHE INTERNAL "") +SET(HAVE_SIZEOF_UINT32 FALSE CACHE INTERNAL "") +SET(HAVE_SIZEOF_UINT64 FALSE CACHE INTERNAL "") +SET(HAVE_SIZEOF_UINT8 FALSE CACHE INTERNAL "") +SET(HAVE_SIZEOF_ULONG FALSE CACHE INTERNAL "") +SET(HAVE_SIZEOF_U_INT32_T FALSE CACHE INTERNAL "") +SET(HAVE_SIZE_OF_SSIZE_T FALSE CACHE INTERNAL "") +SET(HAVE_SLEEP CACHE INTERNAL "") +SET(HAVE_SOCKADDR_STORAGE_SS_FAMILY 1 CACHE INTERNAL "") +SET(HAVE_SOLARIS_STYLE_GETHOST CACHE INTERNAL "") +SET(STACK_DIRECTION -1 CACHE INTERNAL "") +SET(HAVE_STDARG_H 1 CACHE INTERNAL "") +SET(HAVE_STDDEF_H 1 CACHE INTERNAL "") +SET(HAVE_STDINT_H CACHE INTERNAL "") +SET(HAVE_STDLIB_H 1 CACHE INTERNAL "") +SET(HAVE_STPCPY CACHE INTERNAL "") +SET(HAVE_STRCASECMP CACHE INTERNAL "") +SET(HAVE_STRCOLL 1 CACHE INTERNAL "") +SET(HAVE_STRDUP 1 CACHE INTERNAL "") +SET(HAVE_STRERROR 1 CACHE INTERNAL "") +SET(HAVE_STRINGS_H CACHE INTERNAL "") +SET(HAVE_STRING_H 1 CACHE INTERNAL "") +SET(HAVE_STRLCAT CACHE INTERNAL "") +SET(HAVE_STRLCPY CACHE INTERNAL "") +SET(HAVE_STRNCASECMP CACHE INTERNAL "") +SET(HAVE_STRNDUP CACHE INTERNAL "") +IF(MSVC_VERSION GREATER 1310) +SET(HAVE_STRNLEN 1 CACHE INTERNAL "") +ENDIF() +SET(HAVE_STRPBRK 1 CACHE INTERNAL "") +SET(HAVE_STRSEP CACHE INTERNAL "") +SET(HAVE_STRSIGNAL CACHE INTERNAL "") +SET(HAVE_STRSTR 1 CACHE INTERNAL "") +SET(HAVE_STRTOK_R CACHE INTERNAL "") +SET(HAVE_STRTOL 1 CACHE INTERNAL "") +SET(HAVE_STRTOLL CACHE INTERNAL "") +SET(HAVE_STRTOUL 1 CACHE INTERNAL "") +SET(HAVE_STRTOULL CACHE INTERNAL "") +SET(HAVE_SVR3_SIGNALS CACHE INTERNAL "") +SET(HAVE_SYNCH_H CACHE INTERNAL "") +SET(HAVE_SYSENT_H CACHE INTERNAL "") +SET(HAVE_SYS_CDEFS_H CACHE INTERNAL "") +SET(HAVE_SYS_DIR_H CACHE INTERNAL "") +SET(HAVE_SYS_ERRLIST CACHE INTERNAL "") +SET(HAVE_SYS_FILE_H CACHE INTERNAL "") +SET(HAVE_SYS_FPU_H CACHE INTERNAL "") +SET(HAVE_SYS_IOCTL_H CACHE INTERNAL "") +SET(HAVE_SYS_IPC_H CACHE INTERNAL "") +SET(HAVE_SYS_MALLOC_H CACHE INTERNAL "") +SET(HAVE_SYS_MMAN_H CACHE INTERNAL "") +SET(HAVE_SYS_PARAM_H CACHE INTERNAL "") +SET(HAVE_SYS_PRCTL_H CACHE INTERNAL "") +SET(HAVE_SYS_PTEM_H CACHE INTERNAL "") +SET(HAVE_SYS_PTE_H CACHE INTERNAL "") +SET(HAVE_SYS_RESOURCE_H CACHE INTERNAL "") +SET(HAVE_SYS_SELECT_H CACHE INTERNAL "") +SET(HAVE_SYS_SHM_H CACHE INTERNAL "") +SET(HAVE_SYS_SOCKIO_H CACHE INTERNAL "") +SET(HAVE_SYS_SOCKET_H CACHE INTERNAL "") +SET(HAVE_SYS_STAT_H 1 CACHE INTERNAL "") +SET(HAVE_SYS_STREAM_H CACHE INTERNAL "") +SET(HAVE_SYS_TERMCAP_H CACHE INTERNAL "") +SET(HAVE_SYS_TIMEB_H 1 CACHE INTERNAL "") +SET(HAVE_SYS_TIMES_H CACHE INTERNAL "") +SET(HAVE_SYS_TIME_H CACHE INTERNAL "") +SET(HAVE_SYS_TYPES_H 1 CACHE INTERNAL "") +SET(HAVE_SYS_UN_H CACHE INTERNAL "") +SET(HAVE_SYS_UTIME_H 1 CACHE INTERNAL "") +SET(HAVE_SYS_VADVISE_H CACHE INTERNAL "") +SET(HAVE_SYS_WAIT_H CACHE INTERNAL "") +SET(HAVE_TCGETATTR CACHE INTERNAL "") +SET(HAVE_TELL 1 CACHE INTERNAL "") +SET(HAVE_TEMPNAM 1 CACHE INTERNAL "") +SET(HAVE_TERMCAP_H CACHE INTERNAL "") +SET(HAVE_TERMIOS_H CACHE INTERNAL "") +SET(HAVE_TERMIO_H CACHE INTERNAL "") +SET(HAVE_TERM_H CACHE INTERNAL "") +SET(HAVE_THR_SETCONCURRENCY CACHE INTERNAL "") +SET(HAVE_THR_YIELD CACHE INTERNAL "") +SET(HAVE_TIME 1 CACHE INTERNAL "") +SET(HAVE_TIMES CACHE INTERNAL "") +SET(HAVE_TIMESPEC_TS_SEC CACHE INTERNAL "") +SET(HAVE_TIME_H 1 CACHE INTERNAL "") +SET(HAVE_TZNAME 1 CACHE INTERNAL "") +SET(HAVE_UNISTD_H CACHE INTERNAL "") +SET(HAVE_UTIME_H CACHE INTERNAL "") +SET(HAVE_VALLOC CACHE INTERNAL "") +SET(HAVE_VARARGS_H 1 CACHE INTERNAL "") +SET(HAVE_VASPRINTF CACHE INTERNAL "") +SET(HAVE_VPRINTF 1 CACHE INTERNAL "") +IF(MSVC_VERSION GREATER 1310) +SET(HAVE_VSNPRINTF 1 CACHE INTERNAL "") +ENDIF() +SET(HAVE_WEAK_SYMBOL CACHE INTERNAL "") +SET(HAVE_WORDS_BIGENDIAN TRUE CACHE INTERNAL "") +SET(WORDS_BIGENDIAN CACHE INTERNAL "") +SET(HAVE__S_IFIFO 1 CACHE INTERNAL "") +SET(HAVE__S_IREAD 1 CACHE INTERNAL "") +SET(HAVE__finite 1 CACHE INTERNAL "") +SET(HAVE__pclose 1 CACHE INTERNAL "") +SET(HAVE__popen 1 CACHE INTERNAL "") +SET(HAVE__stricmp 1 CACHE INTERNAL "") +SET(HAVE__strnicmp 1 CACHE INTERNAL "") +SET(HAVE__strtoi64 1 CACHE INTERNAL "") +SET(HAVE__strtoui64 1 CACHE INTERNAL "") +IF(MSVC_VERSION GREATER 1310) + SET(HAVE_strtok_s 1 CACHE INTERNAL "") +ENDIF() +SET(STDC_HEADERS CACHE 1 INTERNAL "") +SET(STRUCT_DIRENT_HAS_D_INO CACHE INTERNAL "") +SET(STRUCT_DIRENT_HAS_D_INO CACHE INTERNAL "") +SET(STRUCT_DIRENT_HAS_D_NAMLEN CACHE INTERNAL "") +SET(TIME_WITH_SYS_TIME CACHE INTERNAL "") +SET(TIME_T_UNSIGNED 1 CACHE INTERNAL "") +SET(TIOCSTAT_IN_SYS_IOCTL CACHE INTERNAL "") +SET(HAVE_S_IROTH CACHE INTERNAL "") +SET(HAVE_S_IFIFO CACHE INTERNAL "") +SET(QSORT_TYPE_IS_VOID 1 CACHE INTERNAL "") +SET(SIGNAL_RETURN_TYPE_IS_VOID 1 CACHE INTERNAL "") +SET(C_HAS_inline CACHE INTERNAL "") +SET(C_HAS___inline 1 CACHE INTERNAL "") +SET(FIONREAD_IN_SYS_IOCTL CACHE INTERNAL "") +SET(FIONREAD_IN_SYS_FILIO CACHE INTERNAL "") +SET(GWINSZ_IN_SYS_IOCTL CACHE INTERNAL "") +SET(HAVE_CXXABI_H CACHE INTERNAL "") +SET(HAVE_NDIR_H CACHE INTERNAL "") +SET(HAVE_SYS_NDIR_H CACHE INTERNAL "") +SET(HAVE_SYS_NDIR_H CACHE INTERNAL "") +SET(HAVE_ASM_TERMBITS_H CACHE INTERNAL "") +SET(HAVE_TERMBITS_H CACHE INTERNAL "") +SET(HAVE_VIS_H CACHE INTERNAL "") +SET(HAVE_WCHAR_H 1 CACHE INTERNAL "") +SET(HAVE_WCTYPE_H 1 CACHE INTERNAL "") +SET(HAVE_PTHREAD_RWLOCKATTR_SETKIND_NP CACHE INTERNAL "") +SET(HAVE_SOCKADDR_IN_SIN_LEN CACHE INTERNAL "") +SET(HAVE_SOCKADDR_IN6_SIN6_LEN CACHE INTERNAL "") +SET(HAVE_VALGRIND CACHE INTERNAL "") +SET(HAVE_EVENT_H CACHE INTERNAL "") +SET(HAVE_LINUX_UNISTD_H CACHE INTERNAL "") +SET(HAVE_SYS_UTSNAME_H CACHE INTERNAL "") +SET(HAVE_PTHREAD_ATTR_GETGUARDSIZE CACHE INTERNAL "") +SET(FIONREAD_IN_SYS_FILIO CACHE INTERNAL "") +SET(FIONREAD_IN_SYS_IOCTL CACHE INTERNAL "") +SET(GWINSZ_IN_SYS_IOCTL CACHE INTERNAL "") +SET(HAVE_ACCESS 1 CACHE INTERNAL "") +SET(HAVE_AIOWAIT CACHE INTERNAL "") +SET(HAVE_AIO_H CACHE INTERNAL "") +SET(HAVE_AIO_READ CACHE INTERNAL "") +SET(HAVE_ALARM CACHE INTERNAL "") +SET(HAVE_ALLOCA CACHE INTERNAL "") +SET(HAVE_ALLOCA_H CACHE INTERNAL "") +SET(HAVE_ARPA_INET_H CACHE INTERNAL "") +SET(HAVE_ASM_MSR_H CACHE INTERNAL "") +SET(HAVE_ASM_TERMBITS_H CACHE INTERNAL "") +SET(HAVE_BACKTRACE CACHE INTERNAL "") +SET(HAVE_BACKTRACE_SYMBOLS CACHE INTERNAL "") +SET(HAVE_BACKTRACE_SYMBOLS_FD CACHE INTERNAL "") +SET(HAVE_BCMP CACHE INTERNAL "") +SET(HAVE_BFILL CACHE INTERNAL "") +SET(HAVE_BMOVE CACHE INTERNAL "") +SET(HAVE_BSD_SIGNALS CACHE INTERNAL "") +SET(HAVE_BSEARCH CACHE INTERNAL "") +SET(HAVE_BSS_START CACHE INTERNAL "") +SET(HAVE_BZERO CACHE INTERNAL "") +SET(HAVE_CHOWN CACHE INTERNAL "") +SET(HAVE_CLOCK_GETTIME CACHE INTERNAL "") +SET(HAVE_COMPRESS CACHE INTERNAL "") +SET(HAVE_CRYPT CACHE INTERNAL "") +SET(HAVE_CRYPT_H CACHE INTERNAL "") +SET(HAVE_CUSERID CACHE INTERNAL "") +SET(HAVE_CXXABI_H CACHE INTERNAL "") +SET(HAVE_DECL_FDATASYNC CACHE INTERNAL "") +SET(HAVE_SIGNAL_H 1 CACHE INTERNAL "") +SET(HAVE_GETHOSTBYNAME_R CACHE INTERNAL "") +SET(HAVE_PTHREAD_ATTR_SETPRIO CACHE INTERNAL "") +SET(HAVE_PTHREAD_ATTR_SETSCHEDPARAM CACHE INTERNAL "") +SET(HAVE_PTHREAD_KILL CACHE INTERNAL "") +SET(HAVE_PTHREAD_SETPRIO_NP CACHE INTERNAL "") +SET(HAVE_PTHREAD_SETSCHEDPARAM CACHE INTERNAL "") +SET(HAVE_SETFILEPOINTER CACHE INTERNAL "") +SET(SIZEOF_U_INT32_T CACHE INTERNAL "") +SET(IS_VOID_SIGNAL 1 CACHE INTERNAL "") +SET(IS_VOID_QSORT 1 CACHE INTERNAL "") +ENDIF() diff --git a/vendor/MDBC/cmake/export.cmake b/vendor/MDBC/cmake/export.cmake new file mode 100644 index 00000000..5ae2b74f --- /dev/null +++ b/vendor/MDBC/cmake/export.cmake @@ -0,0 +1,30 @@ +# +# Copyright (C) 2013-2016 MariaDB Corporation AB +# +# Redistribution and use is allowed according to the terms of the New +# BSD license. +# For details see the COPYING-CMAKE-SCRIPTS file. +# +MACRO(CREATE_EXPORT_FILE op outfile version symbols alias_version) + IF(WIN32) + SET(EXPORT_CONTENT "EXPORTS\n") + FOREACH(exp_symbol ${symbols}) + SET(EXPORT_CONTENT ${EXPORT_CONTENT} "${exp_symbol}\n") + ENDFOREACH() + ELSE() + SET(EXPORT_CONTENT "VERSION {\n${version} {\nglobal:\n") + FOREACH(exp_symbol ${symbols}) + SET(EXPORT_CONTENT "${EXPORT_CONTENT} ${exp_symbol}\\;\n") + ENDFOREACH() + SET(EXPORT_CONTENT "${EXPORT_CONTENT}local:\n *\\;\n}\\;\n") + IF ("${alias_version}" STRGREATER "") + SET(EXPORT_CONTENT "${EXPORT_CONTENT}${alias_version} {\n}\\;\n}\\;\n") + FOREACH(exp_symbol ${symbols}) + SET(EXPORT_CONTENT "${EXPORT_CONTENT}\"${exp_symbol}@${alias_version}\" = ${exp_symbol}\\;\n") + ENDFOREACH() + ELSE() + SET(EXPORT_CONTENT "${EXPORT_CONTENT}}\\;\n") + ENDIF() + ENDIF() + FILE(${op} ${CMAKE_CURRENT_BINARY_DIR}/${outfile} ${EXPORT_CONTENT}) +ENDMACRO() diff --git a/vendor/MDBC/cmake/install.cmake b/vendor/MDBC/cmake/install.cmake new file mode 100644 index 00000000..90bae8b5 --- /dev/null +++ b/vendor/MDBC/cmake/install.cmake @@ -0,0 +1,160 @@ +# +# Copyright (C) 2013-2016 MariaDB Corporation AB +# +# Redistribution and use is allowed according to the terms of the New +# BSD license. +# For details see the COPYING-CMAKE-SCRIPTS file. +# + +# +# This file contains settings for the following layouts: +# +# - RPM +# Built with default prefix=/usr +# +# +# The following va+riables are used and can be overwritten +# +# INSTALL_LAYOUT installation layout (DEFAULT = standard for tar.gz and zip packages +# RPM packages +# +# INSTALL_BINDIR location of binaries (mariadb_config) +# INSTALL_LIBDIR location of libraries +# INSTALL_PLUGINDIR location of plugins +# INSTALL_MANDIR location of manpages + +IF(NOT INSTALL_LAYOUT) + SET(INSTALL_LAYOUT "DEFAULT") +ENDIF() + +SET(INSTALL_LAYOUT ${INSTALL_LAYOUT} CACHE + STRING "Installation layout. Currently supported options are DEFAULT (tar.gz and zip), RPM and DEB") + +# On Windows we only provide zip and .msi. Latter one uses a different packager. +IF(UNIX) + IF(INSTALL_LAYOUT MATCHES "RPM") + SET(libmariadb_prefix "/usr") + ELSEIF(INSTALL_LAYOUT MATCHES "DEFAULT|DEB") + SET(libmariadb_prefix ${CMAKE_INSTALL_PREFIX}) + ENDIF() +ENDIF() + +IF(CMAKE_DEFAULT_PREFIX_INITIALIZED_BY_DEFAULT) + SET(CMAKE_DEFAULT_PREFIX ${libmariadb_prefix} CACHE PATH "Installation prefix" FORCE) +ENDIF() + +# check if the specified installation layout is valid +SET(VALID_INSTALL_LAYOUTS "DEFAULT" "RPM" "DEB") +LIST(FIND VALID_INSTALL_LAYOUTS "${INSTALL_LAYOUT}" layout_no) +IF(layout_no EQUAL -1) + MESSAGE(FATAL_ERROR "Invalid installation layout ${INSTALL_LAYOUT}. Please specify one of the following layouts: ${VALID_INSTALL_LAYOUTS}") +ENDIF() + + + +# +# Todo: We don't generate man pages yet, will fix it +# later (webhelp to man transformation) +# + +# +# DEFAULT layout +# + +SET(INSTALL_BINDIR_DEFAULT "bin") +SET(INSTALL_LIBDIR_DEFAULT "lib/mariadb") +SET(INSTALL_PCDIR_DEFAULT "lib/pkgconfig") +SET(INSTALL_INCLUDEDIR_DEFAULT "include/mariadb") +SET(INSTALL_DOCDIR_DEFAULT "docs") +SET(INSTALL_MANDIR_DEFAULT "man") +IF(NOT IS_SUBPROJECT) + SET(INSTALL_PLUGINDIR_DEFAULT "lib/mariadb/plugin") +ELSE() +ENDIF() +SET(LIBMARIADB_STATIC_DEFAULT "mariadbclient") +# +# RPM layout +# +SET(INSTALL_BINDIR_RPM "bin") +IF((CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64" OR CMAKE_SYSTEM_PROCESSOR MATCHES "ppc64" OR CMAKE_SYSTEM_PROCESSOR MATCHES "ppc64le" OR CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64" OR CMAKE_SYSTEM_PROCESSOR MATCHES "s390x") AND CMAKE_SIZEOF_VOID_P EQUAL 8) + SET(INSTALL_LIBDIR_RPM "lib64/mariadb") + SET(INSTALL_PCDIR_RPM "lib64/pkgconfig") + SET(INSTALL_PLUGINDIR_RPM "lib64/mariadb/plugin") +ELSE() + SET(INSTALL_LIBDIR_RPM "lib/mariadb") + SET(INSTALL_PCDIR_RPM "lib/pkgconfig") + SET(INSTALL_PLUGINDIR_RPM "lib/mariadb/plugin") +ENDIF() +SET(INSTALL_INCLUDEDIR_RPM "include") +SET(INSTALL_DOCDIR_RPM "docs") +SET(INSTALL_MANDIR_RPM "share/man") +SET(LIBMARIADB_STATIC_RPM "mariadbclient") + +# +# DEB layout +# +SET(INSTALL_BINDIR_DEB "bin") +SET(INSTALL_LIBDIR_DEB "lib/${CMAKE_LIBRARY_ARCHITECTURE}") +SET(INSTALL_PCDIR_DEB "lib/${CMAKE_LIBRARY_ARCHITECTURE}/pkgconfig") +SET(INSTALL_PLUGINDIR_DEB "${INSTALL_LIBDIR_DEB}/libmariadb${CPACK_PACKAGE_VERSION_MAJOR}/plugin") +SET(INSTALL_INCLUDEDIR_DEB "include/mariadb") +SET(INSTALL_MANDIR_DEB "share/man") +SET(LIBMARIADB_STATIC_DEB "mariadb") + +IF(INSTALL_LAYOUT MATCHES "DEB") + SET(INSTALL_PLUGINDIR_CLIENT ${INSTALL_PLUGINDIR_DEB}) +ENDIF() + + +# +# Overwrite defaults +# +IF(INSTALL_LIBDIR) + SET(INSTALL_LIBDIR_${INSTALL_LAYOUT} ${INSTALL_LIBDIR}) +ENDIF() + +IF(INSTALL_PCDIR) + SET(INSTALL_PCDIR_${INSTALL_LAYOUT} ${INSTALL_PCDIR}) +ENDIF() + +IF(INSTALL_PLUGINDIR) + SET(INSTALL_PLUGINDIR_${INSTALL_LAYOUT} ${INSTALL_PLUGINDIR}) +ENDIF() + +# Extra INSTALL_PLUGINDIR_CLIENT that overrides any INSTALL_PLUGINDIR override +IF(INSTALL_PLUGINDIR_CLIENT) + SET(INSTALL_PLUGINDIR_${INSTALL_LAYOUT} ${INSTALL_PLUGINDIR_CLIENT}) +ENDIF() + +IF(INSTALL_INCLUDEDIR) + SET(INSTALL_INCLUDEDIR_${INSTALL_LAYOUT} ${INSTALL_INCLUDEDIR}) +ENDIF() + +IF(INSTALL_BINDIR) + SET(INSTALL_BINDIR_${INSTALL_LAYOUT} ${INSTALL_BINDIR}) +ENDIF() + +IF(INSTALL_MANDIR) + SET(INSTALL_MANDIR_${INSTALL_LAYOUT} ${INSTALL_MANDIR}) +ENDIF() + +IF(NOT INSTALL_PREFIXDIR) + SET(INSTALL_PREFIXDIR_${INSTALL_LAYOUT} ${libmariadb_prefix}) +ELSE() + SET(INSTALL_PREFIXDIR_${INSTALL_LAYOUT} ${INSTALL_PREFIXDIR}) +ENDIF() + +IF(DEFINED INSTALL_SUFFIXDIR) + SET(INSTALL_SUFFIXDIR_${INSTALL_LAYOUT} ${INSTALL_SUFFIXDIR}) +ENDIF() + +FOREACH(dir "BIN" "LIB" "PC" "INCLUDE" "DOCS" "PLUGIN" "MAN") + SET(INSTALL_${dir}DIR ${INSTALL_${dir}DIR_${INSTALL_LAYOUT}}) + MARK_AS_ADVANCED(INSTALL_${dir}DIR) + MESSAGE1(INSTALL_${dir}DIR "MariaDB Connector C: INSTALL_${dir}DIR=${INSTALL_${dir}DIR}") +ENDFOREACH() + +SET(LIBMARIADB_STATIC_NAME ${LIBMARIADB_STATIC_${INSTALL_LAYOUT}}) +MARK_AS_ADVANCED(LIBMARIADB_STATIC_NAME) + +MESSAGE1(LIBMARIADB_STATIC_NAME "MariaDB Connector C: LIBMARIADB_STATIC_NAME ${LIBMARIADB_STATIC_NAME}") diff --git a/vendor/MDBC/cmake/install_plugins.cmake b/vendor/MDBC/cmake/install_plugins.cmake new file mode 100644 index 00000000..1ba9822b --- /dev/null +++ b/vendor/MDBC/cmake/install_plugins.cmake @@ -0,0 +1,20 @@ +# +# Copyright (C) 2013-2016 MariaDB Corporation AB +# +# Redistribution and use is allowed according to the terms of the New +# BSD license. +# For details see the COPYING-CMAKE-SCRIPTS file. +# +# plugin installation + +MACRO(INSTALL_PLUGIN name binary_dir) + #INSTALL(TARGETS ${name} COMPONENT ClientPlugins DESTINATION ${INSTALL_PLUGINDIR}) + IF(MSVC) + INSTALL(FILES $ COMPONENT Debuginfo + DESTINATION symbols CONFIGURATIONS Debug RelWithDebInfo) + ENDIF() + IF(WIN32) + FILE(APPEND ${CC_BINARY_DIR}/win/packaging/plugin.conf "\n") + FILE(APPEND ${CC_BINARY_DIR}/win/packaging/plugin.conf "\n") + ENDIF() +ENDMACRO() diff --git a/vendor/MDBC/cmake/libressl_version.c b/vendor/MDBC/cmake/libressl_version.c new file mode 100644 index 00000000..cceac8c3 --- /dev/null +++ b/vendor/MDBC/cmake/libressl_version.c @@ -0,0 +1,7 @@ +#include +#include + +int main() +{ + printf("%s", LIBRESSL_VERSION_TEXT); +} diff --git a/vendor/MDBC/cmake/linux_x86_toolchain.cmake b/vendor/MDBC/cmake/linux_x86_toolchain.cmake new file mode 100644 index 00000000..13e0b994 --- /dev/null +++ b/vendor/MDBC/cmake/linux_x86_toolchain.cmake @@ -0,0 +1,18 @@ +# +# Copyright (C) 2013-2016 MariaDB Corporation AB +# +# Redistribution and use is allowed according to the terms of the New +# BSD license. +# For details see the COPYING-CMAKE-SCRIPTS file. +# +# toolchain file for building a 32bit version on a 64bit host + +# Usage: +# cmake -DCMAKE_TOOLCHAIN_FILE=linux_86.toolchain.cmake + +set(CMAKE_SYSTEM_NAME Linux) +set(CMAKE_SYSTEM_VERSION 1) +set(CMAKE_SYSTEM_PROCESSOR "i686") + +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32" CACHE STRING "c++ flags") +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32" CACHE STRING "c flags") diff --git a/vendor/MDBC/cmake/misc.cmake b/vendor/MDBC/cmake/misc.cmake new file mode 100644 index 00000000..0b7149b2 --- /dev/null +++ b/vendor/MDBC/cmake/misc.cmake @@ -0,0 +1,13 @@ +IF ("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_LESS "2.8.7") + FUNCTION(MESSAGE1 id out) + MESSAGE(STATUS "${out}") + ENDFUNCTION() +ELSE() + FUNCTION(MESSAGE1 id out) + STRING(MD5 hash "${out}") + IF(NOT __msg1_${id} STREQUAL "${hash}") + MESSAGE(STATUS "${out}") + ENDIF() + SET(__msg1_${id} ${hash} CACHE INTERNAL "") + ENDFUNCTION() +ENDIF() diff --git a/vendor/MDBC/cmake/plugins.cmake b/vendor/MDBC/cmake/plugins.cmake new file mode 100644 index 00000000..1f321b14 --- /dev/null +++ b/vendor/MDBC/cmake/plugins.cmake @@ -0,0 +1,94 @@ +# +# Copyright (C) 2013-2018 MariaDB Corporation AB +# +# Redistribution and use is allowed according to the terms of the New +# BSD license. +# For details see the COPYING-CMAKE-SCRIPTS file. +# +# plugin configuration + +include(${CC_SOURCE_DIR}/cmake/install_plugins.cmake) +include(${CC_SOURCE_DIR}/cmake/sign.cmake) + +FUNCTION(REGISTER_PLUGIN) + + SET(one_value_keywords TARGET DEFAULT TYPE) + SET(multi_value_keywords CONFIGURATIONS SOURCES LIBRARIES INCLUDES COMPILE_OPTIONS) + + cmake_parse_arguments(CC_PLUGIN + "${options}" + "${one_value_keywords}" + "${multi_value_keywords}" + ${ARGN}) + + # overwrite default if it was specified with cmake option + string(TOUPPER ${CC_PLUGIN_TARGET} cc_plugin) + if(NOT "${CLIENT_PLUGIN_${cc_plugin}}" STREQUAL "") + SET(CC_PLUGIN_DEFAULT ${CLIENT_PLUGIN_${cc_plugin}}) + endif() + + # use uppercase + string(TOUPPER ${CC_PLUGIN_TARGET} target_name) + string(TOUPPER "${CC_PLUGIN_CONFIGURATIONS}" CC_PLUGIN_CONFIGURATIONS) + + if(NOT ${PLUGIN_${target_name}} STREQUAL "") + string(TOUPPER ${PLUGIN_${target_name}} PLUGIN_${target_name}) + set(CC_PLUGIN_DEFAULT ${PLUGIN_${target_name}}) + endif() + +# check if default value is valid + string(TOUPPER ${CC_PLUGIN_DEFAULT} CC_PLUGIN_DEFAULT) + list(FIND CC_PLUGIN_CONFIGURATIONS ${CC_PLUGIN_DEFAULT} configuration_found) + if(${configuration_found} EQUAL -1) + message(FATAL_ERROR "Invalid plugin type ${CC_PLUGIN_DEFAULT}. Allowed plugin types are ${CC_PLUGIN_CONFIGURATIONS}") + endif() + + if(NOT ${CC_PLUGIN_DEFAULT} STREQUAL "OFF") + set(PLUGIN_${CC_PLUGIN_TARGET}_TYPE ${CC_PLUGIN_TYPE}) + + if(${CC_PLUGIN_DEFAULT} STREQUAL "DYNAMIC") + + set(PLUGINS_DYNAMIC ${PLUGINS_DYNAMIC} ${CC_PLUGIN_TARGET} PARENT_SCOPE) + if(WIN32) + set(target ${CC_PLUGIN_TARGET}) + set(FILE_TYPE "VFT_DLL") + set(FILE_DESCRIPTION "MariaDB client plugin") + set(FILE_VERSION ${CPACK_PACKAGE_VERSION}) + set(ORIGINAL_FILE_NAME "${target}.dll") + configure_file(${CC_SOURCE_DIR}/win/resource.rc.in + ${CC_BINARY_DIR}/win/${target}.rc + @ONLY) + set(CC_PLUGIN_SOURCES ${CC_PLUGIN_SOURCES} ${CC_BINARY_DIR}/win/${target}.rc ${CC_SOURCE_DIR}/plugins/plugin.def) + endif() + add_library(${CC_PLUGIN_TARGET} MODULE ${CC_PLUGIN_SOURCES}) + target_link_libraries(${CC_PLUGIN_TARGET} ${CC_PLUGIN_LIBRARIES}) + set_target_properties(${CC_PLUGIN_TARGET} PROPERTIES PREFIX "") + set_target_properties(${CC_PLUGIN_TARGET} + PROPERTIES COMPILE_FLAGS + "-DPLUGIN_DYNAMIC=1 ${CC_PLUGIN_COMPILE_OPTIONS}") + if (NOT "${CC_PLUGIN_INCLUDES}" STREQUAL "") + if(CMAKE_VERSION VERSION_LESS 2.8.11) + include_directories(${CC_PLUGIN_INCLUDES}) + else() + target_include_directories(${CC_PLUGIN_TARGET} PRIVATE ${CC_PLUGIN_INCLUDES}) + endif() + endif() + if (${CC_TARGET_COMPILE_OPTIONS}) + target_compile_options(${CC_PLUGIN_TARGET} ${CC_TARGET_COMPILE_OPTIONS}) + endif() + + if(WIN32) + SIGN_TARGET(${target}) + endif() + INSTALL_PLUGIN(${CC_PLUGIN_TARGET} ${CMAKE_CURRENT_BINARY_DIR}) + elseif(${CC_PLUGIN_DEFAULT} STREQUAL "STATIC") + set(PLUGINS_STATIC ${PLUGINS_STATIC} ${CC_PLUGIN_TARGET} PARENT_SCOPE) + set(LIBMARIADB_PLUGIN_CFLAGS ${LIBMARIADB_PLUGIN_CFLAGS} ${CC_PLUGIN_COMPILE_OPTIONS} PARENT_SCOPE) + set(LIBMARIADB_PLUGIN_INCLUDES ${LIBMARIADB_PLUGIN_INCLUDES} ${CC_PLUGIN_INCLUDES} PARENT_SCOPE) + set(LIBMARIADB_PLUGIN_SOURCES ${LIBMARIADB_PLUGIN_SOURCES} ${CC_PLUGIN_SOURCES} PARENT_SCOPE) + set(LIBMARIADB_PLUGIN_LIBS ${LIBMARIADB_PLUGIN_LIBS} ${CC_PLUGIN_LIBRARIES} PARENT_SCOPE) + endif() + else() + set(PLUGINS_OFF ${PLUGINS_OFF} ${CC_PLUGIN_TARGET}) + endif() +endfunction() diff --git a/vendor/MDBC/cmake/sign.cmake b/vendor/MDBC/cmake/sign.cmake new file mode 100644 index 00000000..7d694118 --- /dev/null +++ b/vendor/MDBC/cmake/sign.cmake @@ -0,0 +1,20 @@ +# +# Copyright (C) 2013-2016 MariaDB Corporation AB +# +# Redistribution and use is allowed according to the terms of the New +# BSD license. +# For details see the COPYING-CMAKE-SCRIPTS file. +# +IF(COMMAND SIGN_TARGET) + # Do not override server's SIGN_TARGET macro + RETURN() +ENDIF() + +MACRO(SIGN_TARGET target) + IF(WITH_SIGNCODE) + IF(WIN32) + SET(target_file $) + ADD_CUSTOM_COMMAND(TARGET ${target} COMMAND signtool ARGS sign ${SIGN_OPTIONS} ${target_file}) + ENDIF() + ENDIF() +ENDMACRO() diff --git a/vendor/MDBC/cmake/symlink.cmake b/vendor/MDBC/cmake/symlink.cmake new file mode 100644 index 00000000..c1c883d1 --- /dev/null +++ b/vendor/MDBC/cmake/symlink.cmake @@ -0,0 +1,35 @@ +# +# Copyright (C) 2013-2016 MariaDB Corporation AB +# +# Redistribution and use is allowed according to the terms of the New +# BSD license. +# For details see the COPYING-CMAKE-SCRIPTS file. +# +MACRO(create_symlink symlink_name target install_path) +# According to cmake documentation symlinks work on unix systems only +IF(UNIX) + # Get target components + ADD_CUSTOM_COMMAND( + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${symlink_name} + COMMAND ${CMAKE_COMMAND} ARGS -E remove -f ${symlink_name} + COMMAND ${CMAKE_COMMAND} ARGS -E create_symlink $ ${symlink_name} + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + DEPENDS ${target} + ) + + ADD_CUSTOM_TARGET(SYM_${symlink_name} + ALL + DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${symlink_name}) + SET_TARGET_PROPERTIES(SYM_${symlink_name} PROPERTIES CLEAN_DIRECT_OUTPUT 1) + + IF(CMAKE_GENERATOR MATCHES "Xcode") + # For Xcode, replace project config with install config + STRING(REPLACE "${CMAKE_CFG_INTDIR}" + "\${CMAKE_INSTALL_CONFIG_NAME}" output ${CMAKE_CURRENT_BINARY_DIR}/${symlink_name}) + ENDIF() + + # presumably this will be used for libmysql*.so symlinks + INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${symlink_name} DESTINATION ${install_path} + COMPONENT Development) +ENDIF() +ENDMACRO() diff --git a/vendor/MDBC/cmake/version_info.cmake b/vendor/MDBC/cmake/version_info.cmake new file mode 100644 index 00000000..ca0716da --- /dev/null +++ b/vendor/MDBC/cmake/version_info.cmake @@ -0,0 +1,44 @@ +# +# Copyright (C) 2013-2016 MariaDB Corporation AB +# +# Redistribution and use is allowed according to the terms of the New +# BSD license. +# For details see the COPYING-CMAKE-SCRIPTS file. +# +FUNCTION(GET_FILE_VERSION FILE_NAME FILE_VERSION) + + # if we build from a git repository, we calculate the file version: + # Patch number is number of commits for given file + IF(GIT_EXECUTABLE AND EXISTS ${CC_SOURCE_DIR}/.git) + EXECUTE_PROCESS(COMMAND ${GIT_EXECUTABLE} --git-dir=${CC_SOURCE_DIR}/.git --work-tree=${CC_SOURCE_DIR} rev-list HEAD --count -- ${FILE_NAME} + OUTPUT_VARIABLE FV) + STRING(REPLACE "\n" "" FV ${FV}) + SET(${FILE_VERSION} ${FV} PARENT_SCOPE) + ELSE() + SET(${FILE_VERSION} 0) + ENDIF() +ENDFUNCTION() + +MACRO(SET_VERSION_INFO) + SET(FILE_VERSION "0") + FOREACH(PROPERTY ${ARGN}) + IF(${PROPERTY} MATCHES "TARGET:") + STRING(REGEX REPLACE "^[TARGET:\\s]" "" TARGET ${PROPERTY}) + ELSEIF(${PROPERTY} MATCHES "FILE_TYPE:") + STRING(REGEX REPLACE "^[FILE_TYPE:\\s]" "" FILE_TYPE ${PROPERTY}) + ELSEIF(${PROPERTY} MATCHES "ORIGINAL_FILE_NAME:") + STRING(REGEX REPLACE "^[ORIGINAL_FILE_NAME:\\s]" "" ORIGINAL_FILE_NAME ${PROPERTY}) + ELSEIF(${PROPERTY} MATCHES "SOURCE_FILE:") + STRING(REGEX REPLACE "^[SOURCE_FILE:\\s]" "" SOURCE ${PROPERTY}) + GET_FILE_VERSION(${SOURCE} FILE_VERSION) + ELSEIF(${PROPERTY} MATCHES "FILE_DESCRIPTION:") + STRING(REPLACE "FILE_DESCRIPTION:" "" FILE_DESCRIPTION ${PROPERTY}) + ENDIF() + ENDFOREACH() + CONFIGURE_FILE(${CC_SOURCE_DIR}/win/resource.rc.in + ${CC_BINARY_DIR}/win/${TARGET}.rc) + SET(${TARGET}_RC ${CC_BINARY_DIR}/win/${TARGET}.rc) +ENDMACRO() + + + diff --git a/vendor/MDBC/include/CMakeLists.txt b/vendor/MDBC/include/CMakeLists.txt new file mode 100644 index 00000000..b9eed535 --- /dev/null +++ b/vendor/MDBC/include/CMakeLists.txt @@ -0,0 +1,41 @@ +SET(MARIADB_CLIENT_INCLUDES ${CC_SOURCE_DIR}/include/mariadb_com.h + ${CC_SOURCE_DIR}/include/mysql.h + ${CC_SOURCE_DIR}/include/mariadb_stmt.h + ${CC_SOURCE_DIR}/include/ma_pvio.h + ${CC_SOURCE_DIR}/include/ma_tls.h + ${CC_BINARY_DIR}/include/mariadb_version.h + ${CC_SOURCE_DIR}/include/ma_list.h + ${CC_SOURCE_DIR}/include/errmsg.h + ${CC_SOURCE_DIR}/include/mariadb_dyncol.h + ${CC_SOURCE_DIR}/include/mariadb_ctype.h + ${CC_SOURCE_DIR}/include/mariadb_rpl.h + ) +IF(NOT IS_SUBPROJECT) + SET(MARIADB_CLIENT_INCLUDES ${MARIADB_CLIENT_INCLUDES} + ${CC_SOURCE_DIR}/include/mysqld_error.h + ) +ENDIF() +SET(MYSQL_ADDITIONAL_INCLUDES + ${CC_SOURCE_DIR}/include/mysql/client_plugin.h + ${CC_SOURCE_DIR}/include/mysql/plugin_auth_common.h + ${CC_SOURCE_DIR}/include/mysql/plugin_auth.h + ) +SET(MARIADB_ADDITIONAL_INCLUDES + ${CC_SOURCE_DIR}/include/mariadb/ma_io.h + ) +IF(WIN32) + SET(WIX_INCLUDES ${MARIADB_CLIENT_INCLUDES} ${MARIADB_ADDITIONAL_INCLUDES} ${MYSQL_ADDITIONAL_INCLUDES} PARENT_SCOPE) +ENDIF() + +INSTALL(FILES + ${MARIADB_CLIENT_INCLUDES} + DESTINATION ${INSTALL_INCLUDEDIR} + COMPONENT Development) +INSTALL(FILES + ${MYSQL_ADDITIONAL_INCLUDES} + DESTINATION ${INSTALL_INCLUDEDIR}/mysql + COMPONENT Development) +INSTALL(FILES + ${MARIADB_ADDITIONAL_INCLUDES} + DESTINATION ${INSTALL_INCLUDEDIR}/mariadb + COMPONENT Development) diff --git a/vendor/MDBC/include/errmsg.h b/vendor/MDBC/include/errmsg.h new file mode 100644 index 00000000..7ca3238a --- /dev/null +++ b/vendor/MDBC/include/errmsg.h @@ -0,0 +1,107 @@ +/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB + 2012-2016 SkySQL AB, MariaDB Corporation AB + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + MA 02111-1301, USA */ + +/* Error messages for mysql clients */ +/* error messages for the demon is in share/language/errmsg.sys */ +#ifndef _errmsg_h_ +#define _errmsg_h_ + +#ifdef __cplusplus +extern "C" { +#endif +void init_client_errs(void); +extern const char *client_errors[]; /* Error messages */ +extern const char *mariadb_client_errors[]; /* Error messages */ +#ifdef __cplusplus +} +#endif + + + +#define CR_MIN_ERROR 2000 /* For easier client code */ +#define CR_MAX_ERROR 2999 +#define CER_MIN_ERROR 5000 +#define CER_MAX_ERROR 5999 +#define CER(X) mariadb_client_errors[(X)-CER_MIN_ERROR] +#define ER(X) client_errors[(X)-CR_MIN_ERROR] +#define CLIENT_ERRMAP 2 /* Errormap used by ma_error() */ + +#define CR_UNKNOWN_ERROR 2000 +#define CR_SOCKET_CREATE_ERROR 2001 +#define CR_CONNECTION_ERROR 2002 +#define CR_CONN_HOST_ERROR 2003 /* never sent to a client, message only */ +#define CR_IPSOCK_ERROR 2004 +#define CR_UNKNOWN_HOST 2005 +#define CR_SERVER_GONE_ERROR 2006 /* disappeared _between_ queries */ +#define CR_VERSION_ERROR 2007 +#define CR_OUT_OF_MEMORY 2008 +#define CR_WRONG_HOST_INFO 2009 +#define CR_LOCALHOST_CONNECTION 2010 +#define CR_TCP_CONNECTION 2011 +#define CR_SERVER_HANDSHAKE_ERR 2012 +#define CR_SERVER_LOST 2013 /* disappeared _during_ a query */ +#define CR_COMMANDS_OUT_OF_SYNC 2014 +#define CR_NAMEDPIPE_CONNECTION 2015 +#define CR_NAMEDPIPEWAIT_ERROR 2016 +#define CR_NAMEDPIPEOPEN_ERROR 2017 +#define CR_NAMEDPIPESETSTATE_ERROR 2018 +#define CR_CANT_READ_CHARSET 2019 +#define CR_NET_PACKET_TOO_LARGE 2020 +#define CR_SSL_CONNECTION_ERROR 2026 +#define CR_MALFORMED_PACKET 2027 +#define CR_NO_PREPARE_STMT 2030 +#define CR_PARAMS_NOT_BOUND 2031 +#define CR_INVALID_PARAMETER_NO 2034 +#define CR_INVALID_BUFFER_USE 2035 +#define CR_UNSUPPORTED_PARAM_TYPE 2036 + +#define CR_SHARED_MEMORY_CONNECTION 2037 +#define CR_SHARED_MEMORY_CONNECT_ERROR 2038 + +#define CR_CONN_UNKNOWN_PROTOCOL 2047 +#define CR_SECURE_AUTH 2049 +#define CR_NO_DATA 2051 +#define CR_NO_STMT_METADATA 2052 +#define CR_NOT_IMPLEMENTED 2054 +#define CR_SERVER_LOST_EXTENDED 2055 /* never sent to a client, message only */ +#define CR_STMT_CLOSED 2056 +#define CR_NEW_STMT_METADATA 2057 +#define CR_ALREADY_CONNECTED 2058 +#define CR_AUTH_PLUGIN_CANNOT_LOAD 2059 +#define CR_DUPLICATE_CONNECTION_ATTR 2060 +#define CR_AUTH_PLUGIN_ERR 2061 +/* Always last, if you add new error codes please update the + value for CR_MYSQL_LAST_ERROR */ +#define CR_MYSQL_LAST_ERROR CR_AUTH_PLUGIN_ERR + +/* + * MariaDB Connector/C errors: + */ +#define CR_EVENT_CREATE_FAILED 5000 +#define CR_BIND_ADDR_FAILED 5001 +#define CR_ASYNC_NOT_SUPPORTED 5002 +#define CR_FUNCTION_NOT_SUPPORTED 5003 +#define CR_FILE_NOT_FOUND 5004 +#define CR_FILE_READ 5005 +#define CR_BULK_WITHOUT_PARAMETERS 5006 +#define CR_INVALID_STMT 5007 +#define CR_VERSION_MISMATCH 5008 +/* Always last, if you add new error codes please update the + value for CR_MARIADB_LAST_ERROR */ +#define CR_MARIADB_LAST_ERROR CR_VERSION_MISMATCH +#endif diff --git a/vendor/MDBC/include/ma_common.h b/vendor/MDBC/include/ma_common.h new file mode 100644 index 00000000..5bfdb7ad --- /dev/null +++ b/vendor/MDBC/include/ma_common.h @@ -0,0 +1,122 @@ +/* Copyright (C) 2013 by MontyProgram AB + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + MA 02111-1301, USA */ + +/* defines for the libmariadb library */ + +#ifndef _ma_common_h +#define _ma_common_h + +#include +#include + +enum enum_multi_status { + COM_MULTI_OFF= 0, + COM_MULTI_CANCEL, + COM_MULTI_ENABLED, + COM_MULTI_DISABLED, + COM_MULTI_END +}; + + +typedef enum { + ALWAYS_ACCEPT, /* heuristics is disabled, use CLIENT_LOCAL_FILES */ + WAIT_FOR_QUERY, /* heuristics is enabled, not sending files */ + ACCEPT_FILE_REQUEST /* heuristics is enabled, ready to send a file */ +} auto_local_infile_state; + +typedef struct st_mariadb_db_driver +{ + struct st_mariadb_client_plugin_DB *plugin; + char *name; + void *buffer; +} MARIADB_DB_DRIVER; + +struct mysql_async_context; + +struct st_mysql_options_extension { + char *plugin_dir; + char *default_auth; + char *ssl_crl; + char *ssl_crlpath; + char *server_public_key_path; + struct mysql_async_context *async_context; + MA_HASHTBL connect_attrs; + size_t connect_attrs_len; + void (*report_progress)(const MYSQL *mysql, + unsigned int stage, + unsigned int max_stage, + double progress, + const char *proc_info, + unsigned int proc_info_length); + MARIADB_DB_DRIVER *db_driver; + char *tls_fp; /* finger print of server certificate */ + char *tls_fp_list; /* white list of finger prints */ + char *tls_pw; /* password for encrypted certificates */ + my_bool multi_command; /* indicates if client wants to send multiple + commands in one packet */ + char *url; /* for connection handler we need to save URL for reconnect */ + unsigned int tls_cipher_strength; + char *tls_version; + my_bool read_only; + char *connection_handler; + my_bool (*set_option)(MYSQL *mysql, const char *config_option, const char *config_value); + MA_HASHTBL userdata; + char *server_public_key; + char *proxy_header; + size_t proxy_header_len; + int (*io_wait)(my_socket handle, my_bool is_read, int timeout); + my_bool skip_read_response; +}; + +typedef struct st_connection_handler +{ + struct st_ma_connection_plugin *plugin; + void *data; + my_bool active; + my_bool free_data; +} MA_CONNECTION_HANDLER; + +struct st_mariadb_net_extension { + enum enum_multi_status multi_status; + int extended_errno; +}; + +struct st_mariadb_session_state +{ + LIST *list, + *current; +}; + +struct st_mariadb_extension { + MA_CONNECTION_HANDLER *conn_hdlr; + struct st_mariadb_session_state session_state[SESSION_TRACK_TYPES]; + unsigned long mariadb_client_flag; /* MariaDB specific client flags */ + unsigned long mariadb_server_capabilities; /* MariaDB specific server capabilities */ + my_bool auto_local_infile; +}; + +#define OPT_EXT_VAL(a,key) \ + (((a)->options.extension && (a)->options.extension->key) ?\ + (a)->options.extension->key : 0) + +#endif + + +typedef struct st_mariadb_field_extension +{ + MARIADB_CONST_STRING metadata[MARIADB_FIELD_ATTR_LAST+1]; /* 10.5 */ +} MA_FIELD_EXTENSION; diff --git a/vendor/MDBC/include/ma_config.h.in b/vendor/MDBC/include/ma_config.h.in new file mode 100644 index 00000000..d5ef4f66 --- /dev/null +++ b/vendor/MDBC/include/ma_config.h.in @@ -0,0 +1,145 @@ + +/* + * Include file constants (processed in LibmysqlIncludeFiles.txt 1 + */ +#cmakedefine HAVE_OPENSSL_APPLINK_C 1 +#cmakedefine HAVE_ALLOCA_H 1 +#cmakedefine HAVE_BIGENDIAN 1 +#cmakedefine HAVE_SETLOCALE 1 +#cmakedefine HAVE_NL_LANGINFO 1 +#cmakedefine HAVE_DLFCN_H 1 +#cmakedefine HAVE_FCNTL_H 1 +#cmakedefine HAVE_FLOAT_H 1 +#cmakedefine HAVE_LIMITS_H 1 +#cmakedefine HAVE_LINUX_LIMITS_H 1 +#cmakedefine HAVE_PWD_H 1 +#cmakedefine HAVE_SELECT_H 1 +#cmakedefine HAVE_STDDEF_H 1 +#cmakedefine HAVE_STDINT_H 1 +#cmakedefine HAVE_STDLIB_H 1 +#cmakedefine HAVE_STRING_H 1 +#cmakedefine HAVE_SYS_IOCTL_H 1 +#cmakedefine HAVE_SYS_SELECT_H 1 +#cmakedefine HAVE_SYS_SOCKET_H 1 +#cmakedefine HAVE_SYS_STREAM_H 1 +#cmakedefine HAVE_SYS_STAT_H 1 +#cmakedefine HAVE_SYS_SYSCTL_H 1 +#cmakedefine HAVE_SYS_TYPES_H 1 +#cmakedefine HAVE_SYS_UN_H 1 +#cmakedefine HAVE_UNISTD_H 1 +#cmakedefine HAVE_UCONTEXT_H 1 + +/* + * function definitions - processed in LibmysqlFunctions.txt + */ + +#cmakedefine HAVE_DLERROR 1 +#cmakedefine HAVE_DLOPEN 1 +#cmakedefine HAVE_GETPWUID 1 +#cmakedefine HAVE_MEMCPY 1 +#cmakedefine HAVE_POLL 1 +#cmakedefine HAVE_STRTOK_R 1 +#cmakedefine HAVE_STRTOL 1 +#cmakedefine HAVE_STRTOLL 1 +#cmakedefine HAVE_STRTOUL 1 +#cmakedefine HAVE_STRTOULL 1 +#cmakedefine HAVE_TELL 1 +#cmakedefine HAVE_THR_SETCONCURRENCY 1 +#cmakedefine HAVE_THR_YIELD 1 +#cmakedefine HAVE_VASPRINTF 1 +#cmakedefine HAVE_VSNPRINTF 1 +#cmakedefine HAVE_CUSERID 1 + +/* + * types and sizes + */ + + +#cmakedefine SIZEOF_CHARP @SIZEOF_CHARP@ +#if defined(SIZEOF_CHARP) +# define HAVE_CHARP 1 +#endif + + +#cmakedefine SIZEOF_INT @SIZEOF_INT@ +#if defined(SIZEOF_INT) +# define HAVE_INT 1 +#endif + +#cmakedefine SIZEOF_LONG @SIZEOF_LONG@ +#if defined(SIZEOF_LONG) +# define HAVE_LONG 1 +#endif + +#cmakedefine SIZEOF_LONG_LONG @SIZEOF_LONG_LONG@ +#if defined(SIZEOF_LONG_LONG) +# define HAVE_LONG_LONG 1 +#endif + + +#cmakedefine SIZEOF_SIZE_T @SIZEOF_SIZE_T@ +#if defined(SIZEOF_SIZE_T) +# define HAVE_SIZE_T 1 +#endif + + +#cmakedefine SIZEOF_UINT @SIZEOF_UINT@ +#if defined(SIZEOF_UINT) +# define HAVE_UINT 1 +#endif + +#cmakedefine SIZEOF_ULONG @SIZEOF_ULONG@ +#if defined(SIZEOF_ULONG) +# define HAVE_ULONG 1 +#endif + +#cmakedefine SIZEOF_INT8 @SIZEOF_INT8@ +#if defined(SIZEOF_INT8) +# define HAVE_INT8 1 +#endif +#cmakedefine SIZEOF_UINT8 @SIZEOF_UINT8@ +#if defined(SIZEOF_UINT8) +# define HAVE_UINT8 1 +#endif + +#cmakedefine SIZEOF_INT16 @SIZEOF_INT16@ +#if defined(SIZEOF_INT16) +# define HAVE_INT16 1 +#endif +#cmakedefine SIZEOF_UINT16 @SIZEOF_UINT16@ +#if defined(SIZEOF_UINT16) +# define HAVE_UINT16 1 +#endif + +#cmakedefine SIZEOF_INT32 @SIZEOF_INT32@ +#if defined(SIZEOF_INT32) +# define HAVE_INT32 1 +#endif +#cmakedefine SIZEOF_UINT32 @SIZEOF_UINT32@ +#if defined(SIZEOF_UINT32) +# define HAVE_UINT32 1 +#endif + +#cmakedefine SIZEOF_INT64 @SIZEOF_INT64@ +#if defined(SIZEOF_INT64) +# define HAVE_INT64 1 +#endif +#cmakedefine SIZEOF_UINT64 @SIZEOF_UINT64@ +#if defined(SIZEOF_UINT64) +# define HAVE_UINT64 1 +#endif + +#cmakedefine SIZEOF_SOCKLEN_T @SIZEOF_SOCKLEN_T@ +#if defined(SIZEOF_SOCKLEN_T) +# define HAVE_SOCKLEN_T 1 +#endif + +#cmakedefine SOCKET_SIZE_TYPE @SOCKET_SIZE_TYPE@ + +#define LOCAL_INFILE_MODE_OFF 0 +#define LOCAL_INFILE_MODE_ON 1 +#define LOCAL_INFILE_MODE_AUTO 2 +#define ENABLED_LOCAL_INFILE LOCAL_INFILE_MODE_@ENABLED_LOCAL_INFILE@ + +#define MARIADB_DEFAULT_CHARSET "@DEFAULT_CHARSET@" + diff --git a/vendor/MDBC/include/ma_context.h b/vendor/MDBC/include/ma_context.h new file mode 100644 index 00000000..3a4eb01e --- /dev/null +++ b/vendor/MDBC/include/ma_context.h @@ -0,0 +1,236 @@ +/* + Copyright 2011 Kristian Nielsen and Monty Program Ab + + This file is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this. If not, see . +*/ + +/* + Simple API for spawning a co-routine, to be used for async libmysqlclient. + + Idea is that by implementing this interface using whatever facilities are + available for given platform, we can use the same code for the generic + libmysqlclient-async code. + + (This particular implementation uses Posix ucontext swapcontext().) +*/ + +#ifdef _WIN32 +#define MY_CONTEXT_USE_WIN32_FIBERS 1 +#elif defined(__GNUC__) && __GNUC__ >= 3 && defined(__x86_64__) && !defined(__ILP32__) +#define MY_CONTEXT_USE_X86_64_GCC_ASM +#elif defined(__GNUC__) && __GNUC__ >= 3 && defined(__i386__) +#define MY_CONTEXT_USE_I386_GCC_ASM +#elif defined(HAVE_UCONTEXT_H) +#define MY_CONTEXT_USE_UCONTEXT +#else +#define MY_CONTEXT_DISABLE +#endif + +#ifdef MY_CONTEXT_USE_WIN32_FIBERS +struct my_context { + void (*user_func)(void *); + void *user_arg; + void *app_fiber; + void *lib_fiber; + int return_value; +#ifndef DBUG_OFF + void *dbug_state; +#endif +}; +#endif + + +#ifdef MY_CONTEXT_USE_UCONTEXT +#if defined(__APPLE__) && !defined(_XOPEN_SOURCE) +#define _XOPEN_SOURCE 600 +#endif +#include + +struct my_context { + void (*user_func)(void *); + void *user_data; + void *stack; + size_t stack_size; + ucontext_t base_context; + ucontext_t spawned_context; + int active; +#ifdef HAVE_VALGRIND + unsigned int valgrind_stack_id; +#endif +#ifndef DBUG_OFF + void *dbug_state; +#endif +}; +#endif + + +#ifdef MY_CONTEXT_USE_X86_64_GCC_ASM +#include + +struct my_context { + uint64_t save[9]; + void *stack_top; + void *stack_bot; +#ifdef HAVE_VALGRIND + unsigned int valgrind_stack_id; +#endif +#ifndef DBUG_OFF + void *dbug_state; +#endif +}; +#endif + + +#ifdef MY_CONTEXT_USE_I386_GCC_ASM +#include + +struct my_context { + uint64_t save[7]; + void *stack_top; + void *stack_bot; +#ifdef HAVE_VALGRIND + unsigned int valgrind_stack_id; +#endif +#ifndef DBUG_OFF + void *dbug_state; +#endif +}; +#endif + + +#ifdef MY_CONTEXT_DISABLE +struct my_context { + int dummy; +}; +#endif + +/* + Initialize an asynchroneous context object. + Returns 0 on success, non-zero on failure. +*/ +extern int my_context_init(struct my_context *c, size_t stack_size); + +/* Free an asynchroneous context object, deallocating any resources used. */ +extern void my_context_destroy(struct my_context *c); + +/* + Spawn an asynchroneous context. The context will run the supplied user + function, passing the supplied user data pointer. + + The context must have been initialised with my_context_init() prior to + this call. + + The user function may call my_context_yield(), which will cause this + function to return 1. Then later my_context_continue() may be called, which + will resume the asynchroneous context by returning from the previous + my_context_yield() call. + + When the user function returns, this function returns 0. + + In case of error, -1 is returned. +*/ +extern int my_context_spawn(struct my_context *c, void (*f)(void *), void *d); + +/* + Suspend an asynchroneous context started with my_context_spawn. + + When my_context_yield() is called, execution immediately returns from the + last my_context_spawn() or my_context_continue() call. Then when later + my_context_continue() is called, execution resumes by returning from this + my_context_yield() call. + + Returns 0 if ok, -1 in case of error. +*/ +extern int my_context_yield(struct my_context *c); + +/* + Resume an asynchroneous context. The context was spawned by + my_context_spawn(), and later suspended inside my_context_yield(). + + The asynchroneous context may be repeatedly suspended with + my_context_yield() and resumed with my_context_continue(). + + Each time it is suspended, this function returns 1. When the originally + spawned user function returns, this function returns 0. + + In case of error, -1 is returned. +*/ +extern int my_context_continue(struct my_context *c); + +struct st_ma_pvio; + +struct mysql_async_context { + /* + This is set to the value that should be returned from foo_start() or + foo_cont() when a call is suspended. + */ + unsigned int events_to_wait_for; + /* + It is also set to the event(s) that triggered when a suspended call is + resumed, eg. whether we woke up due to connection completed or timeout + in mysql_real_connect_cont(). + */ + unsigned int events_occured; + /* + This is set to the result of the whole asynchronous operation when it + completes. It uses a union, as different calls have different return + types. + */ + union { + void *r_ptr; + const void *r_const_ptr; + int r_int; + my_bool r_my_bool; + } ret_result; + /* + The timeout value (in millisecods), for suspended calls that need to wake + up on a timeout (eg. mysql_real_connect_start(). + */ + unsigned int timeout_value; + /* + This flag is set when we are executing inside some asynchronous call + foo_start() or foo_cont(). It is used to decide whether to use the + synchronous or asynchronous version of calls that may block such as + recv(). + + Note that this flag is not set when a call is suspended, eg. after + returning from foo_start() and before re-entering foo_cont(). + */ + my_bool active; + /* + This flag is set when an asynchronous operation is in progress, but + suspended. Ie. it is set when foo_start() or foo_cont() returns because + the operation needs to block, suspending the operation. + + It is used to give an error (rather than crash) if the application + attempts to call some foo_cont() method when no suspended operation foo is + in progress. + */ + my_bool suspended; + /* + If non-NULL, this is a pointer to a callback hook that will be invoked with + the user data argument just before the context is suspended, and just after + it is resumed. + */ + struct st_ma_pvio *pvio; + void (*suspend_resume_hook)(my_bool suspend, void *user_data); + void *suspend_resume_hook_user_data; + /* + This is used to save the execution contexts so that we can suspend an + operation and switch back to the application context, to resume the + suspended context later when the application re-invokes us with + foo_cont(). + */ + struct my_context async_context; +}; diff --git a/vendor/MDBC/include/ma_crypt.h b/vendor/MDBC/include/ma_crypt.h new file mode 100644 index 00000000..cf73359e --- /dev/null +++ b/vendor/MDBC/include/ma_crypt.h @@ -0,0 +1,166 @@ +/* + Copyright (C) 2018 MariaDB Corporation AB + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not see + or write to the Free Software Foundation, Inc., + 51 Franklin St., Fifth Floor, Boston, MA 02110, USA +*/ + +#ifndef _ma_hash_h_ +#define _ma_hash_h_ + +#include +#include + +/*! Hash algorithms */ +#define MA_HASH_MD5 1 +#define MA_HASH_SHA1 2 +#define MA_HASH_SHA224 3 +#define MA_HASH_SHA256 4 +#define MA_HASH_SHA384 5 +#define MA_HASH_SHA512 6 +#define MA_HASH_RIPEMD160 7 + +/*! Hash digest sizes */ +#define MA_MD5_HASH_SIZE 16 +#define MA_SHA1_HASH_SIZE 20 +#define MA_SHA224_HASH_SIZE 28 +#define MA_SHA256_HASH_SIZE 32 +#define MA_SHA384_HASH_SIZE 48 +#define MA_SHA512_HASH_SIZE 64 +#define MA_RIPEMD160_HASH_SIZE 20 + +#define MA_MAX_HASH_SIZE 64 +/** \typedef MRL hash context */ + +#if defined(_WIN32) +#include +#include +typedef struct { + char free_me; + BCRYPT_ALG_HANDLE hAlg; + BCRYPT_HASH_HANDLE hHash; + PBYTE hashObject; + DWORD digest_len; +} MA_HASH_CTX; +#elif defined(HAVE_OPENSSL) +typedef void MA_HASH_CTX; +#elif defined(HAVE_GNUTLS) +typedef struct { + void *ctx; + const struct nettle_hash *hash; +} MA_HASH_CTX; +#endif + +/** + @brief acquire and initialize new hash context + + @param[in] algorithm hash algorithm + @param[in] ctx pointer to a crypto context + + @return hash context on success, NULL on error +*/ +MA_HASH_CTX *ma_hash_new(unsigned int algorithm, MA_HASH_CTX *ctx); + +/** + @brief release and deinitializes a hash context + + @param[in] hash context + + @return void +*/ +void ma_hash_free(MA_HASH_CTX *ctx); + +/** + @brief hashes len bytes of data into the hash context. + This function can be called several times on same context to + hash additional data. + + @param[in] ctx hash context + @param[in] buffer data buffer + @param[in] len size of buffer + + @return void +*/ +void ma_hash_input(MA_HASH_CTX *ctx, + const unsigned char *buffer, + size_t len); + +/** + @brief retrieves the hash value from hash context + + @param[in] ctx hash context + @param[out] digest digest containing hash value + + @return void + */ +void ma_hash_result(MA_HASH_CTX *ctx, unsigned char *digest); + + +/** + @brief returns digest size for a given hash algorithm + + @param[in] hash algorithm + + @returns digest size or 0 on error +*/ +static inline size_t ma_hash_digest_size(unsigned int hash_alg) +{ + switch(hash_alg) { + case MA_HASH_MD5: + return MA_MD5_HASH_SIZE; + case MA_HASH_SHA1: + return MA_SHA1_HASH_SIZE; + case MA_HASH_SHA224: + return MA_SHA224_HASH_SIZE; + case MA_HASH_SHA256: + return MA_SHA256_HASH_SIZE; + case MA_HASH_SHA384: + return MA_SHA384_HASH_SIZE; + case MA_HASH_SHA512: + return MA_SHA512_HASH_SIZE; + case MA_HASH_RIPEMD160: + return MA_RIPEMD160_HASH_SIZE; + default: + return 0; + } +} + +/** + @brief function to compute hash from buffer. + + @param[in] hash_alg hash algorithm + @param[in] buffer buffer + @param[in] buffer_leng length of buffer + @param[out] digest computed hash digest + + @return void +*/ +static inline void ma_hash(unsigned int algorithm, + const unsigned char *buffer, + size_t buffer_length, + unsigned char *digest) +{ + MA_HASH_CTX *ctx= NULL; +#ifdef _WIN32 + MA_HASH_CTX dctx; + ctx= &dctx; +#endif + ctx= ma_hash_new(algorithm, ctx); + ma_hash_input(ctx, buffer, buffer_length); + ma_hash_result(ctx, digest); + ma_hash_free(ctx); +} + +#endif /* _ma_hash_h_ */ diff --git a/vendor/MDBC/include/ma_global.h b/vendor/MDBC/include/ma_global.h new file mode 100644 index 00000000..e8ca7df3 --- /dev/null +++ b/vendor/MDBC/include/ma_global.h @@ -0,0 +1,1094 @@ +/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + MA 02111-1301, USA */ + +/* This is the main include file that should included 'first' in every + C file. */ + +#ifndef _global_h +#define _global_h + +#ifdef _WIN32 +#include +#include +#include +#define strcasecmp _stricmp +#define sleep(x) Sleep(1000*(x)) +#ifdef _MSC_VER +#define inline __inline +#if _MSC_VER < 1900 +#define snprintf _snprintf +#endif +#endif +#define STDCALL __stdcall +#endif + +#include +#include +#ifndef __GNUC__ +#define __attribute(A) +#endif + +/* Fix problem with S_ISLNK() on Linux */ +#if defined(HAVE_LINUXTHREADS) +#undef _GNU_SOURCE +#define _GNU_SOURCE 1 +#endif + +/* The client defines this to avoid all thread code */ +#if defined(UNDEF_THREADS_HACK) +#undef THREAD +#undef HAVE_mit_thread +#undef HAVE_LINUXTHREADS +#undef HAVE_UNIXWARE7_THREADS +#endif + +#ifdef HAVE_THREADS_WITHOUT_SOCKETS +/* MIT pthreads does not work with unix sockets */ +#undef HAVE_SYS_UN_H +#endif + +#define __EXTENSIONS__ 1 /* We want some extension */ +#ifndef __STDC_EXT__ +#define __STDC_EXT__ 1 /* To get large file support on hpux */ +#endif + +#if defined(THREAD) && !defined(_WIN32) +#ifndef _POSIX_PTHREAD_SEMANTICS +#define _POSIX_PTHREAD_SEMANTICS /* We want posix threads */ +#endif +/* was #if defined(HAVE_LINUXTHREADS) || defined(HAVE_DEC_THREADS) || defined(HPUX) */ +#if !defined(SCO) +#define _REENTRANT 1 /* Some thread libraries require this */ +#endif +#if !defined(_THREAD_SAFE) && !defined(_AIX) +#define _THREAD_SAFE /* Required for OSF1 */ +#endif +#ifndef HAVE_mit_thread +#ifdef HAVE_UNIXWARE7_THREADS +#include +#else +#include /* AIX must have this included first */ +#endif /* HAVE_UNIXWARE7_THREADS */ +#endif /* HAVE_mit_thread */ +#if !defined(SCO) && !defined(_REENTRANT) +#define _REENTRANT 1 /* Threads requires reentrant code */ +#endif +#endif /* THREAD */ + +/* Go around some bugs in different OS and compilers */ +#ifdef HAVE_BROKEN_SNPRINTF /* HPUX 10.20 don't have this defined */ +#undef HAVE_SNPRINTF +#endif +#if defined(HAVE_BROKEN_INLINE) && !defined(__cplusplus) +#undef inline +#define inline +#endif + +#ifdef UNDEF_HAVE_GETHOSTBYNAME_R /* For OSF4.x */ +#undef HAVE_GETHOSTBYNAME_R +#endif +#ifdef UNDEF_HAVE_INITGROUPS /* For AIX 4.3 */ +#undef HAVE_INITGROUPS +#endif + +/* Fix a bug in gcc 2.8.0 on IRIX 6.2 */ +#if SIZEOF_LONG == 4 && defined(__LONG_MAX__) +#undef __LONG_MAX__ /* Is a longlong value in gcc 2.8.0 ??? */ +#define __LONG_MAX__ 2147483647 +#endif + +/* Fix problem when linking c++ programs with gcc 3.x */ +#ifdef DEFINE_CXA_PURE_VIRTUAL +#define FIX_GCC_LINKING_PROBLEM extern "C" { int __cxa_pure_virtual() {return 0;} } +#else +#define FIX_GCC_LINKING_PROBLEM +#endif + +/* egcs 1.1.2 has a problem with memcpy on Alpha */ +#if defined(__GNUC__) && defined(__alpha__) && ! (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95)) +#define BAD_MEMCPY +#endif + +/* In Linux-alpha we have atomic.h if we are using gcc */ +#if defined(HAVE_LINUXTHREADS) && defined(__GNUC__) && defined(__alpha__) && (__GNUC__ > 2 || ( __GNUC__ == 2 && __GNUC_MINOR__ >= 95)) && !defined(HAVE_ATOMIC_ADD) +#define HAVE_ATOMIC_ADD +#define HAVE_ATOMIC_SUB +#endif + +/* In Linux-ia64 including atomic.h will give us an error */ +#if (defined(HAVE_LINUXTHREADS) && defined(__GNUC__) && (defined(__ia64__) || defined(__powerpc64__))) || !defined(THREAD) +#undef HAVE_ATOMIC_ADD +#undef HAVE_ATOMIC_SUB +#endif + +#if defined(_lint) && !defined(lint) +#define lint +#endif +#if SIZEOF_LONG_LONG > 4 && !defined(_LONG_LONG) +#define _LONG_LONG 1 /* For AIX string library */ +#endif + +#ifndef stdin +#include +#endif +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_STDDEF_H +#include +#endif + +#include +#ifdef HAVE_LIMITS_H +#include +#endif +#ifdef HAVE_FLOAT_H +#include +#endif + +#ifdef HAVE_SYS_TYPES_H +#include +#endif +#ifdef HAVE_FCNTL_H +#include +#endif +#if defined(TIME_WITH_SYS_TIME) +# include +# include +#else +# if defined(HAVE_SYS_TIME_H) +# include +# else +# include +# endif +#endif /* TIME_WITH_SYS_TIME */ +#ifdef HAVE_UNISTD_H +#include +#endif +#if defined(__cplusplus) && defined(NO_CPLUSPLUS_ALLOCA) +#undef HAVE_ALLOCA +#undef HAVE_ALLOCA_H +#endif +#ifdef HAVE_ALLOCA_H +#include +#endif +#ifdef HAVE_ATOMIC_ADD +#define __SMP__ +#define CONFIG_SMP +#include +#endif +#include /* Recommended by debian */ +#include + +/* Go around some bugs in different OS and compilers */ +#if defined(_HPUX_SOURCE) && defined(HAVE_SYS_STREAM_H) +#include /* HPUX 10.20 defines ulong here. UGLY !!! */ +#define HAVE_ULONG +#endif +#ifdef DONT_USE_FINITE /* HPUX 11.x has is_finite() */ +#undef HAVE_FINITE +#endif +#if defined(HPUX) && defined(_LARGEFILE64_SOURCE) && defined(THREAD) +/* Fix bug in setrlimit */ +#undef setrlimit +#define setrlimit cma_setrlimit64 +#endif + +/* We can not live without these */ + +#define USE_MYFUNC 1 /* Must use syscall indirection */ +#define MASTER 1 /* Compile without unireg */ +#define ENGLISH 1 /* Messages in English */ +#define POSIX_MISTAKE 1 /* regexp: Fix stupid spec error */ +#define USE_REGEX 1 /* We want the use the regex library */ +/* Do not define for ultra sparcs */ +#define USE_BMOVE512 1 /* Use this unless the system bmove is faster */ + +/* Paranoid settings. Define I_AM_PARANOID if you are paranoid */ +#ifdef I_AM_PARANOID +#define DONT_ALLOW_USER_CHANGE 1 +#define DONT_USE_MYSQL_PWD 1 +#endif + +/* #define USE_some_charset 1 was deprecated by changes to configure */ +/* my_ctype my_to_upper, my_to_lower, my_sort_order gain theit right value */ +/* automagically during configuration */ + +/* Does the system remember a signal handler after a signal ? */ +#ifndef HAVE_BSD_SIGNALS +#define DONT_REMEMBER_SIGNAL +#endif + + +#if defined(_lint) || defined(FORCE_INIT_OF_VARS) +#define LINT_INIT(var) do{var=0;}while(0) /* No uninitialize-warning */ +#define LINT_INIT_STRUCT(var) memset(&var, 0, sizeof(var)) /* No uninitialize-warning */ +#else +#define LINT_INIT(var) +#define LINT_INIT_STRUCT(var) +#endif + +/* Define some useful general macros */ +#if defined(__cplusplus) && defined(__GNUC__) +#define max(a, b) ((a) >? (b)) +#define min(a, b) ((a) (b) ? (a) : (b)) +#define min(a, b) ((a) < (b) ? (a) : (b)) +#endif + +#if defined(__EMX__) || !defined(HAVE_UINT) +typedef unsigned int uint; +typedef unsigned short ushort; +#endif + +#define sgn(a) (((a) < 0) ? -1 : ((a) > 0) ? 1 : 0) +#define swap(t,a,b) do{register t dummy; dummy = a; a = b; b = dummy;}while(0) +#define test(a) ((a) ? 1 : 0) +#define set_if_bigger(a,b) do{ if ((a) < (b)) (a)=(b); }while(0) +#define set_if_smaller(a,b) do{ if ((a) > (b)) (a)=(b); }while(0) +#define test_all_bits(a,b) (((a) & (b)) == (b)) +#define set_bits(type, bit_count) (sizeof(type)*8 <= (bit_count) ? ~(type) 0 : ((((type) 1) << (bit_count)) - (type) 1)) +#define array_elements(A) ((uint) (sizeof(A)/sizeof(A[0]))) +#ifndef HAVE_RINT +#define rint(A) floor((A)+0.5) +#endif + +/* Define some general constants */ +#ifndef TRUE +#define TRUE (1) /* Logical true */ +#define FALSE (0) /* Logical false */ +#endif + +#if defined(__GNUC__) +#define function_volatile volatile +#ifndef my_reinterpret_cast +#define my_reinterpret_cast(A) reinterpret_cast +#endif +#define my_const_cast(A) const_cast +#elif !defined(my_reinterpret_cast) +#define my_reinterpret_cast(A) (A) +#define my_const_cast(A) (A) +#endif +#if !defined(__GNUC__) && !defined(__clang__) +#define __attribute__(A) +#endif + +/* From old s-system.h */ + +/* + Support macros for non ansi & other old compilers. Since such + things are no longer supported we do nothing. We keep then since + some of our code may still be needed to upgrade old customers. +*/ +#define _VARARGS(X) X +#define _STATIC_VARARGS(X) X + +#if defined(DBUG_ON) && defined(DBUG_OFF) +#undef DBUG_OFF +#endif + +#if defined(_lint) && !defined(DBUG_OFF) +#define DBUG_OFF +#endif + +#define MIN_ARRAY_SIZE 0 /* Zero or One. Gcc allows zero*/ +#define ASCII_BITS_USED 8 /* Bit char used */ +#define NEAR_F /* No near function handling */ + +/* Some types that is different between systems */ + +typedef int File; /* File descriptor */ +#ifndef my_socket_defined +#define my_socket_defined +#if defined(_WIN64) +#define my_socket unsigned long long +#elif defined(_WIN32) +#define my_socket unsigned int +#else +typedef int my_socket; +#endif +#define my_socket_defined +#endif +#ifndef INVALID_SOCKET +#define INVALID_SOCKET -1 +#endif + +#if defined(__GNUC__) && !defined(_lint) +typedef char pchar; /* Mixed prototypes can take char */ +typedef char puchar; /* Mixed prototypes can take char */ +typedef char pbool; /* Mixed prototypes can take char */ +typedef short pshort; /* Mixed prototypes can take short int */ +typedef float pfloat; /* Mixed prototypes can take float */ +#else +typedef int pchar; /* Mixed prototypes can't take char */ +typedef uint puchar; /* Mixed prototypes can't take char */ +typedef int pbool; /* Mixed prototypes can't take char */ +typedef int pshort; /* Mixed prototypes can't take short int */ +typedef double pfloat; /* Mixed prototypes can't take float */ +#endif +typedef int (*qsort_cmp)(const void *,const void *); +#ifdef HAVE_mit_thread +#define qsort_t void +#undef QSORT_TYPE_IS_VOID +#define QSORT_TYPE_IS_VOID +#else +#define qsort_t RETQSORTTYPE /* Broken GCC can't handle typedef !!!! */ +#endif + +#ifdef HAVE_SYS_SOCKET_H +#include +#endif +typedef SOCKET_SIZE_TYPE size_socket; + +#ifndef SOCKOPT_OPTLEN_TYPE +#define SOCKOPT_OPTLEN_TYPE size_socket +#endif + +/* file create flags */ + +#ifndef O_SHARE +#define O_SHARE 0 /* Flag to my_open for shared files */ +#ifndef O_BINARY +#define O_BINARY 0 /* Flag to my_open for binary files */ +#endif +#define FILE_BINARY 0 /* Flag to my_fopen for binary streams */ +#ifdef HAVE_FCNTL +#define HAVE_FCNTL_LOCK +#define F_TO_EOF 0L /* Param to lockf() to lock rest of file */ +#endif +#endif /* O_SHARE */ +#ifndef O_TEMPORARY +#define O_TEMPORARY 0 +#endif +#ifndef O_SHORT_LIVED +#define O_SHORT_LIVED 0 +#endif + +/* #define USE_RECORD_LOCK */ + + /* Unsigned types supported by the compiler */ +#define UNSINT8 /* unsigned int8 (char) */ +#define UNSINT16 /* unsigned int16 */ +#define UNSINT32 /* unsigned int32 */ + + /* General constants */ +#define SC_MAXWIDTH 256 /* Max width of screen (for error messages) */ +#define FN_LEN 256 /* Max file name len */ +#define FN_HEADLEN 253 /* Max length of filepart of file name */ +#define FN_EXTLEN 20 /* Max length of extension (part of FN_LEN) */ +#define FN_REFLEN 512 /* Max length of full path-name */ +#define FN_EXTCHAR '.' +#define FN_HOMELIB '~' /* ~/ is used as abbrev for home dir */ +#define FN_CURLIB '.' /* ./ is used as abbrev for current dir */ +#define FN_PARENTDIR ".." /* Parentdirectory; Must be a string */ +#define FN_DEVCHAR ':' + +#ifndef FN_LIBCHAR +#ifdef _WIN32 +#define FN_LIBCHAR '\\' +#define FN_ROOTDIR "\\" +#else +#define FN_LIBCHAR '/' +#define FN_ROOTDIR "/" +#endif +#define MY_NFILE 1024 /* This is only used to save filenames */ +#endif + +/* #define EXT_IN_LIBNAME */ +/* #define FN_NO_CASE_SENCE */ +/* #define FN_UPPER_CASE TRUE */ + +/* + Io buffer size; Must be a power of 2 and a multiple of 512. May be + smaller what the disk page size. This influences the speed of the + isam btree library. eg to big to slow. +*/ +#define IO_SIZE 4096 +/* + How much overhead does malloc have. The code often allocates + something like 1024-MALLOC_OVERHEAD bytes +*/ +#define MALLOC_OVERHEAD 8 + /* get memory in huncs */ +#define ONCE_ALLOC_INIT ((uint) (4096-MALLOC_OVERHEAD)) + /* Typical record cash */ +#define RECORD_CACHE_SIZE ((uint) (64*1024-MALLOC_OVERHEAD)) + /* Typical key cash */ +#define KEY_CACHE_SIZE ((uint) (8*1024*1024-MALLOC_OVERHEAD)) + + /* Some things that this system doesn't have */ + +#define ONLY_OWN_DATABASES /* We are using only databases by monty */ +#define NO_PISAM /* Not needed anymore */ +#define NO_MISAM /* Not needed anymore */ +#define NO_HASH /* Not needed anymore */ +#ifdef _WIN32 +#define NO_DIR_LIBRARY /* Not standard dir-library */ +#define USE_MY_STAT_STRUCT /* For my_lib */ +#ifdef _MSC_VER +typedef SSIZE_T ssize_t; +#endif +#endif + +/* Some things that this system does have */ + +#ifndef HAVE_ITOA +#define USE_MY_ITOA /* There is no itoa */ +#endif + +/* Some defines of functions for portability */ + +#ifndef HAVE_ATOD +#define atod atof +#endif +#ifdef USE_MY_ATOF +#define atof my_atof +extern void init_my_atof(void); +extern double my_atof(const char*); +#endif +#undef remove /* Crashes MySQL on SCO 5.0.0 */ +#ifndef _WIN32 +#define closesocket(A) close(A) +#endif +#ifndef ulonglong2double +#define ulonglong2double(A) ((double) (A)) +#define my_off_t2double(A) ((double) (A)) +#endif + + +#ifndef offsetof +#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) +#endif +#define ulong_to_double(X) ((double) (ulong) (X)) +#define SET_STACK_SIZE(X) /* Not needed on real machines */ + + +#ifdef HAVE_LINUXTHREADS +/* #define pthread_sigmask(A,B,C) sigprocmask((A),(B),(C)) */ +/* #define sigset(A,B) signal((A),(B)) */ +#endif + +#if defined(_lint) || defined(FORCE_INIT_OF_VARS) || \ + defined(__cplusplus) || !defined(__GNUC__) +#define UNINIT_VAR(x) x= 0 +#else +/* GCC specific self-initialization which inhibits the warning. */ +#define UNINIT_VAR(x) x= x +#endif + + +/* This is from the old m-machine.h file */ + +#if SIZEOF_LONG_LONG > 4 +#define HAVE_LONG_LONG 1 +#endif + +#if defined(HAVE_LONG_LONG) && !defined(LONGLONG_MIN) +#define LONGLONG_MIN ((long long) 0x8000000000000000LL) +#define LONGLONG_MAX ((long long) 0x7FFFFFFFFFFFFFFFLL) +#endif + + +#define INT_MIN64 (~0x7FFFFFFFFFFFFFFFLL) +#define INT_MAX64 0x7FFFFFFFFFFFFFFFLL +#define INT_MIN32 (~0x7FFFFFFFL) +#define INT_MAX32 0x7FFFFFFFL +#define UINT_MAX32 0xFFFFFFFFL +#define INT_MIN24 (~0x007FFFFF) +#define INT_MAX24 0x007FFFFF +#define UINT_MAX24 0x00FFFFFF +#define INT_MIN16 (~0x7FFF) +#define INT_MAX16 0x7FFF +#define UINT_MAX16 0xFFFF +#define INT_MIN8 (~0x7F) +#define INT_MAX8 0x7F +#define UINT_MAX8 0xFF + +#ifndef ULL +#ifdef HAVE_LONG_LONG +#define ULL(A) A ## ULL +#else +#define ULL(A) A ## UL +#endif +#endif + +#if defined(HAVE_LONG_LONG) && !defined(ULONGLONG_MAX) +/* First check for ANSI C99 definition: */ +#ifdef ULLONG_MAX +#define ULONGLONG_MAX ULLONG_MAX +#else +#define ULONGLONG_MAX ((unsigned long long)(~0ULL)) +#endif +#endif /* defined (HAVE_LONG_LONG) && !defined(ULONGLONG_MAX)*/ + +/* From limits.h instead */ +#ifndef DBL_MIN +#define DBL_MIN 4.94065645841246544e-324 +#define FLT_MIN ((float)1.40129846432481707e-45) +#endif +#ifndef DBL_MAX +#define DBL_MAX 1.79769313486231470e+308 +#define FLT_MAX ((float)3.40282346638528860e+38) +#endif + +/* + Max size that must be added to a so that we know Size to make + addressable obj. +*/ +typedef long my_ptrdiff_t; +#define MY_ALIGN(A,L) (((A) + (L) - 1) & ~((L) - 1)) +#define ALIGN_SIZE(A) MY_ALIGN((A),sizeof(double)) +/* Size to make addressable obj. */ +#define ALIGN_PTR(A, t) ((t*) MY_ALIGN((A),sizeof(t))) + /* Offset of filed f in structure t */ +#define OFFSET(t, f) ((size_t)(char *)&((t *)0)->f) +#define ADD_TO_PTR(ptr,size,type) (type) ((unsigned char*) (ptr)+size) +#define PTR_BYTE_DIFF(A,B) (my_ptrdiff_t) ((unsigned char*) (A) - (unsigned char*) (B)) + +#define NullS (char *) 0 +/* Nowadays we do not support MessyDos */ +#ifndef NEAR +#define NEAR /* Who needs segments ? */ +#define FAR /* On a good machine */ +#ifndef HUGE_PTR +#define HUGE_PTR +#endif +#endif +#if defined(__IBMC__) || defined(__IBMCPP__) +#define STDCALL _System _Export +#elif !defined( STDCALL) +#define STDCALL +#endif + +/* Typdefs for easyier portability */ + +#if defined(VOIDTYPE) +typedef void *gptr; /* Generic pointer */ +#else +typedef char *gptr; /* Generic pointer */ +#endif +#ifndef HAVE_INT_8_16_32 +typedef signed char int8; /* Signed integer >= 8 bits */ +typedef signed short int16; /* Signed integer >= 16 bits */ +#endif +#ifndef HAVE_UCHAR +typedef unsigned char uchar; /* Short for unsigned char */ +#endif +typedef unsigned char uint8; /* Short for unsigned integer >= 8 bits */ +typedef unsigned short uint16; /* Short for unsigned integer >= 16 bits */ + +#if SIZEOF_INT == 4 +#ifndef HAVE_INT_8_16_32 +typedef int int32; +#endif +typedef unsigned int uint32; /* Short for unsigned integer >= 32 bits */ +#elif SIZEOF_LONG == 4 +#ifndef HAVE_INT_8_16_32 +typedef long int32; +#endif +typedef unsigned long uint32; /* Short for unsigned integer >= 32 bits */ +#else +#error "Neither int or long is of 4 bytes width" +#endif + +#if !defined(HAVE_ULONG) && !defined(HAVE_LINUXTHREADS) && !defined(__USE_MISC) +typedef unsigned long ulong; /* Short for unsigned long */ +#endif +#ifndef longlong_defined +#if defined(HAVE_LONG_LONG) && SIZEOF_LONG != 8 +typedef unsigned long long int ulonglong; /* ulong or unsigned long long */ +typedef long long int longlong; +#else +typedef unsigned long ulonglong; /* ulong or unsigned long long */ +typedef long longlong; +#endif +#define longlong_defined +#endif + +#ifndef HAVE_INT64 +typedef longlong int64; +#endif +#ifndef HAVE_UINT64 +typedef ulonglong uint64; +#endif + +#ifndef MIN +#define MIN(a,b) (((a) < (b)) ? (a) : (b)) +#endif +#ifndef MAX +#define MAX(a,b) (((a) > (b)) ? (a) : (b)) +#endif +#define CMP_NUM(a,b) (((a) < (b)) ? -1 : ((a) == (b)) ? 0 : 1) +#ifdef USE_RAID +/* + The following is done with a if to not get problems with pre-processors + with late define evaluation +*/ +#if defined(SIZEOF_OFF_T) && SIZEOF_OFF_T == 4 +#define SYSTEM_SIZEOF_OFF_T 4 +#else +#define SYSTEM_SIZEOF_OFF_T 8 +#endif +#undef SIZEOF_OFF_T +#define SIZEOF_OFF_T 8 +#else +#define SYSTEM_SIZEOF_OFF_T SIZEOF_OFF_T +#endif /* USE_RAID */ + +#if defined(SIZEOF_OFF_T) && SIZEOF_OFF_T > 4 +typedef ulonglong my_off_t; +#else +typedef unsigned long my_off_t; +#endif +#define MY_FILEPOS_ERROR (~(my_off_t) 0) +#ifndef _WIN32 +typedef off_t os_off_t; +#endif + +#if defined(_WIN32) +#define socket_errno WSAGetLastError() +#define SOCKET_EINTR WSAEINTR +#define SOCKET_EAGAIN WSAEWOULDBLOCK +#define SOCKET_ENFILE ENFILE +#define SOCKET_EMFILE EMFILE +#define SOCKET_EWOULDBLOCK WSAEWOULDBLOCK +#else /* Unix */ +#define socket_errno errno +#define closesocket(A) close(A) +#define SOCKET_EINTR EINTR +#define SOCKET_EAGAIN EAGAIN +#define SOCKET_EWOULDBLOCK EWOULDBLOCK +#define SOCKET_ENFILE ENFILE +#define SOCKET_EMFILE EMFILE +#endif + +typedef uint8 int7; /* Most effective integer 0 <= x <= 127 */ +typedef short int15; /* Most effective integer 0 <= x <= 32767 */ +typedef char *my_string; /* String of characters */ +typedef unsigned long size_s; /* Size of strings (In string-funcs) */ +typedef int myf; /* Type of MyFlags in my_funcs */ +typedef char my_bool; /* Small bool */ +typedef unsigned long long my_ulonglong; +#if !defined(bool) && !defined(bool_defined) && (!defined(HAVE_BOOL) || !defined(__cplusplus)) +typedef char bool; /* Ordinary boolean values 0 1 */ +#endif + /* Macros for converting *constants* to the right type */ +#define INT8(v) (int8) (v) +#define INT16(v) (int16) (v) +#define INT32(v) (int32) (v) +#define MYF(v) (myf) (v) + +/* + Defines to make it possible to prioritize register assignments. No + longer that important with modern compilers. +*/ +#ifndef USING_X +#define reg1 register +#define reg2 register +#define reg3 register +#define reg4 register +#define reg5 register +#define reg6 register +#define reg7 register +#define reg8 register +#define reg9 register +#define reg10 register +#define reg11 register +#define reg12 register +#define reg13 register +#define reg14 register +#define reg15 register +#define reg16 register +#endif + +/* Defines for time function */ +#define SCALE_SEC 100 +#define SCALE_USEC 10000 +#define MY_HOW_OFTEN_TO_ALARM 2 /* How often we want info on screen */ +#define MY_HOW_OFTEN_TO_WRITE 1000 /* How often we want info on screen */ + +#define NOT_FIXED_DEC 31 + +#if defined(_WIN32) && defined(_MSVC) +#define MYSQLND_LLU_SPEC "%I64u" +#define MYSQLND_LL_SPEC "%I64d" +#ifndef L64 +#define L64(x) x##i64 +#endif +#else +#define MYSQLND_LLU_SPEC "%llu" +#define MYSQLND_LL_SPEC "%lld" +#ifndef L64 +#define L64(x) x##LL +#endif /* L64 */ +#endif /* _WIN32 */ +/* +** Define-funktions for reading and storing in machine independent format +** (low byte first) +*/ + +/* Optimized store functions for Intel x86 */ +#define int1store(T,A) *((int8*) (T)) = (A) +#define uint1korr(A) (*(((uint8*)(A)))) +#if defined(__i386__) || defined(_WIN32) +#define sint2korr(A) (*((int16 *) (A))) +#define sint3korr(A) ((int32) ((((uchar) (A)[2]) & 128) ? \ + (((uint32) 255L << 24) | \ + (((uint32) (uchar) (A)[2]) << 16) |\ + (((uint32) (uchar) (A)[1]) << 8) | \ + ((uint32) (uchar) (A)[0])) : \ + (((uint32) (uchar) (A)[2]) << 16) |\ + (((uint32) (uchar) (A)[1]) << 8) | \ + ((uint32) (uchar) (A)[0]))) +#define sint4korr(A) (*((long *) (A))) +#define uint2korr(A) (*((uint16 *) (A))) +#if defined(HAVE_purify) && !defined(_WIN32) +#define uint3korr(A) (uint32) (((uint32) ((uchar) (A)[0])) +\ + (((uint32) ((uchar) (A)[1])) << 8) +\ + (((uint32) ((uchar) (A)[2])) << 16)) +#else +/* + ATTENTION ! + + Please, note, uint3korr reads 4 bytes (not 3) ! + It means, that you have to provide enough allocated space ! +*/ +#define uint3korr(A) (long) (*((unsigned int *) (A)) & 0xFFFFFF) +#endif /* HAVE_purify && !_WIN32 */ +#define uint4korr(A) (*((uint32 *) (A))) +#define uint5korr(A) ((ulonglong)(((uint32) ((uchar) (A)[0])) +\ + (((uint32) ((uchar) (A)[1])) << 8) +\ + (((uint32) ((uchar) (A)[2])) << 16) +\ + (((uint32) ((uchar) (A)[3])) << 24)) +\ + (((ulonglong) ((uchar) (A)[4])) << 32)) +#define uint6korr(A) ((ulonglong)(((uint32) ((uchar) (A)[0])) + \ + (((uint32) ((uchar) (A)[1])) << 8) + \ + (((uint32) ((uchar) (A)[2])) << 16) + \ + (((uint32) ((uchar) (A)[3])) << 24)) + \ + (((ulonglong) ((uchar) (A)[4])) << 32) + \ + (((ulonglong) ((uchar) (A)[5])) << 40)) +#define uint8korr(A) (*((ulonglong *) (A))) +#define sint8korr(A) (*((longlong *) (A))) +#define int2store(T,A) *((uint16*) (T))= (uint16) (A) +#define int3store(T,A) do { *(T)= (uchar) ((A));\ + *(T+1)=(uchar) (((uint) (A) >> 8));\ + *(T+2)=(uchar) (((A) >> 16)); } while (0) +#define int4store(T,A) *((long *) (T))= (long) (A) +#define int5store(T,A) do { *(T)= (uchar)((A));\ + *((T)+1)=(uchar) (((A) >> 8));\ + *((T)+2)=(uchar) (((A) >> 16));\ + *((T)+3)=(uchar) (((A) >> 24)); \ + *((T)+4)=(uchar) (((A) >> 32)); } while(0) +#define int6store(T,A) do { *(T)= (uchar)((A)); \ + *((T)+1)=(uchar) (((A) >> 8)); \ + *((T)+2)=(uchar) (((A) >> 16)); \ + *((T)+3)=(uchar) (((A) >> 24)); \ + *((T)+4)=(uchar) (((A) >> 32)); \ + *((T)+5)=(uchar) (((A) >> 40)); } while(0) +#define int8store(T,A) do {*((ulonglong *) (T))= (ulonglong) (A);} while(0) + +typedef union { + double v; + long m[2]; +} doubleget_union; +#define doubleget(V,M) \ +do { doubleget_union _tmp; \ + _tmp.m[0] = *((long*)(M)); \ + _tmp.m[1] = *(((long*) (M))+1); \ + (V) = _tmp.v; } while(0) +#define doublestore(T,V) do { *((long *) T) = ((doubleget_union *)&V)->m[0]; \ + *(((long *) T)+1) = ((doubleget_union *)&V)->m[1]; \ + } while (0) +#define float4get(V,M) do { *((float *) &(V)) = *((float*) (M)); } while(0) +#define float8get(V,M) doubleget((V),(M)) +#define float4store(V,M) memcpy((uchar*) V,(uchar*) (&M),sizeof(float)) +#define floatstore(T,V) memcpy((uchar*)(T), (uchar*)(&V),sizeof(float)) +#define floatget(V,M) memcpy((uchar*) &V,(uchar*) (M),sizeof(float)) +#define float8store(V,M) doublestore((V),(M)) +#else + +/* + We're here if it's not a IA-32 architecture (Win32 and UNIX IA-32 defines + were done before) +*/ +#define sint2korr(A) (int16) (((int16) ((uchar) (A)[0])) +\ + ((int16) ((int16) (A)[1]) << 8)) +#define sint3korr(A) ((int32) ((((uchar) (A)[2]) & 128) ? \ + (((uint32) 255L << 24) | \ + (((uint32) (uchar) (A)[2]) << 16) |\ + (((uint32) (uchar) (A)[1]) << 8) | \ + ((uint32) (uchar) (A)[0])) : \ + (((uint32) (uchar) (A)[2]) << 16) |\ + (((uint32) (uchar) (A)[1]) << 8) | \ + ((uint32) (uchar) (A)[0]))) +#define sint4korr(A) (int32) (((int32) ((uchar) (A)[0])) +\ + (((int32) ((uchar) (A)[1]) << 8)) +\ + (((int32) ((uchar) (A)[2]) << 16)) +\ + (((int32) ((int16) (A)[3]) << 24))) +#define sint8korr(A) (longlong) uint8korr(A) +#define uint2korr(A) (uint16) (((uint16) ((uchar) (A)[0])) +\ + ((uint16) ((uchar) (A)[1]) << 8)) +#define uint3korr(A) (uint32) (((uint32) ((uchar) (A)[0])) +\ + (((uint32) ((uchar) (A)[1])) << 8) +\ + (((uint32) ((uchar) (A)[2])) << 16)) +#define uint4korr(A) (uint32) (((uint32) ((uchar) (A)[0])) +\ + (((uint32) ((uchar) (A)[1])) << 8) +\ + (((uint32) ((uchar) (A)[2])) << 16) +\ + (((uint32) ((uchar) (A)[3])) << 24)) +#define uint5korr(A) ((ulonglong)(((uint32) ((uchar) (A)[0])) +\ + (((uint32) ((uchar) (A)[1])) << 8) +\ + (((uint32) ((uchar) (A)[2])) << 16) +\ + (((uint32) ((uchar) (A)[3])) << 24)) +\ + (((ulonglong) ((uchar) (A)[4])) << 32)) +#define uint6korr(A) ((ulonglong)(((uint32) ((uchar) (A)[0])) + \ + (((uint32) ((uchar) (A)[1])) << 8) + \ + (((uint32) ((uchar) (A)[2])) << 16) + \ + (((uint32) ((uchar) (A)[3])) << 24)) + \ + (((ulonglong) ((uchar) (A)[4])) << 32) + \ + (((ulonglong) ((uchar) (A)[5])) << 40)) +#define uint8korr(A) ((ulonglong)(((uint32) ((uchar) (A)[0])) +\ + (((uint32) ((uchar) (A)[1])) << 8) +\ + (((uint32) ((uchar) (A)[2])) << 16) +\ + (((uint32) ((uchar) (A)[3])) << 24)) +\ + (((ulonglong) (((uint32) ((uchar) (A)[4])) +\ + (((uint32) ((uchar) (A)[5])) << 8) +\ + (((uint32) ((uchar) (A)[6])) << 16) +\ + (((uint32) ((uchar) (A)[7])) << 24))) <<\ + 32)) +#define int2store(T,A) do { uint def_temp= (uint) (A) ;\ + *((uchar*) (T))= (uchar)(def_temp); \ + *((uchar*) (T)+1)=(uchar)((def_temp >> 8)); \ + } while(0) +#define int3store(T,A) do { /*lint -save -e734 */\ + *((uchar*)(T))=(uchar) ((A));\ + *((uchar*) (T)+1)=(uchar) (((A) >> 8));\ + *((uchar*)(T)+2)=(uchar) (((A) >> 16)); \ + /*lint -restore */} while(0) +#define int4store(T,A) do { *((char *)(T))=(char) ((A));\ + *(((char *)(T))+1)=(char) (((A) >> 8));\ + *(((char *)(T))+2)=(char) (((A) >> 16));\ + *(((char *)(T))+3)=(char) (((A) >> 24)); } while(0) +#define int5store(T,A) do { *((char *)(T))= (char)((A)); \ + *(((char *)(T))+1)= (char)(((A) >> 8)); \ + *(((char *)(T))+2)= (char)(((A) >> 16)); \ + *(((char *)(T))+3)= (char)(((A) >> 24)); \ + *(((char *)(T))+4)= (char)(((A) >> 32)); \ + } while(0) +#define int6store(T,A) do { *((char *)(T))= (char)((A)); \ + *(((char *)(T))+1)= (char)(((A) >> 8)); \ + *(((char *)(T))+2)= (char)(((A) >> 16)); \ + *(((char *)(T))+3)= (char)(((A) >> 24)); \ + *(((char *)(T))+4)= (char)(((A) >> 32)); \ + *(((char *)(T))+5)= (char)(((A) >> 40)); \ + } while(0) +#define int8store(T,A) do { uint def_temp= (uint) (A), def_temp2= (uint) ((A) >> 32); \ + int4store((T),def_temp); \ + int4store((T+4),def_temp2); } while(0) +#ifdef HAVE_BIGENDIAN +#define float4store(T,A) do { *(T)= ((uchar *) &A)[3];\ + *((T)+1)=(char) ((uchar *) &A)[2];\ + *((T)+2)=(char) ((uchar *) &A)[1];\ + *((T)+3)=(char) ((uchar *) &A)[0]; } while(0) + +#define float4get(V,M) do { float def_temp;\ + ((uchar*) &def_temp)[0]=(M)[3];\ + ((uchar*) &def_temp)[1]=(M)[2];\ + ((uchar*) &def_temp)[2]=(M)[1];\ + ((uchar*) &def_temp)[3]=(M)[0];\ + (V)=def_temp; } while(0) +#define float8store(T,V) do { *(T)= ((uchar *) &V)[7];\ + *((T)+1)=(char) ((uchar *) &V)[6];\ + *((T)+2)=(char) ((uchar *) &V)[5];\ + *((T)+3)=(char) ((uchar *) &V)[4];\ + *((T)+4)=(char) ((uchar *) &V)[3];\ + *((T)+5)=(char) ((uchar *) &V)[2];\ + *((T)+6)=(char) ((uchar *) &V)[1];\ + *((T)+7)=(char) ((uchar *) &V)[0]; } while(0) + +#define float8get(V,M) do { double def_temp;\ + ((uchar*) &def_temp)[0]=(M)[7];\ + ((uchar*) &def_temp)[1]=(M)[6];\ + ((uchar*) &def_temp)[2]=(M)[5];\ + ((uchar*) &def_temp)[3]=(M)[4];\ + ((uchar*) &def_temp)[4]=(M)[3];\ + ((uchar*) &def_temp)[5]=(M)[2];\ + ((uchar*) &def_temp)[6]=(M)[1];\ + ((uchar*) &def_temp)[7]=(M)[0];\ + (V) = def_temp; } while(0) +#else +#define float4get(V,M) memcpy(&V, (M), sizeof(float)) +#define float4store(V,M) memcpy(V, (&M), sizeof(float)) + +#if defined(__FLOAT_WORD_ORDER) && (__FLOAT_WORD_ORDER == __BIG_ENDIAN) +#define doublestore(T,V) do { *(((char*)T)+0)=(char) ((uchar *) &V)[4];\ + *(((char*)T)+1)=(char) ((uchar *) &V)[5];\ + *(((char*)T)+2)=(char) ((uchar *) &V)[6];\ + *(((char*)T)+3)=(char) ((uchar *) &V)[7];\ + *(((char*)T)+4)=(char) ((uchar *) &V)[0];\ + *(((char*)T)+5)=(char) ((uchar *) &V)[1];\ + *(((char*)T)+6)=(char) ((uchar *) &V)[2];\ + *(((char*)T)+7)=(char) ((uchar *) &V)[3]; }\ + while(0) +#define doubleget(V,M) do { double def_temp;\ + ((uchar*) &def_temp)[0]=(M)[4];\ + ((uchar*) &def_temp)[1]=(M)[5];\ + ((uchar*) &def_temp)[2]=(M)[6];\ + ((uchar*) &def_temp)[3]=(M)[7];\ + ((uchar*) &def_temp)[4]=(M)[0];\ + ((uchar*) &def_temp)[5]=(M)[1];\ + ((uchar*) &def_temp)[6]=(M)[2];\ + ((uchar*) &def_temp)[7]=(M)[3];\ + (V) = def_temp; } while(0) +#endif /* __FLOAT_WORD_ORDER */ + +#define float8get(V,M) doubleget((V),(M)) +#define float8store(V,M) doublestore((V),(M)) +#endif /* WORDS_BIGENDIAN */ + +#endif /* __i386__ OR _WIN32 */ + +/* + Macro for reading 32-bit integer from network byte order (big-endian) + from unaligned memory location. +*/ +#define int4net(A) (int32) (((uint32) ((uchar) (A)[3])) |\ + (((uint32) ((uchar) (A)[2])) << 8) |\ + (((uint32) ((uchar) (A)[1])) << 16) |\ + (((uint32) ((uchar) (A)[0])) << 24)) +/* + Define-funktions for reading and storing in machine format from/to + short/long to/from some place in memory V should be a (not + register) variable, M is a pointer to byte +*/ + +#ifdef HAVE_BIGENDIAN + +#define ushortget(V,M) do { V = (uint16) (((uint16) ((uchar) (M)[1]))+\ + ((uint16) ((uint16) (M)[0]) << 8)); } while(0) +#define shortget(V,M) do { V = (short) (((short) ((uchar) (M)[1]))+\ + ((short) ((short) (M)[0]) << 8)); } while(0) +#define longget(V,M) do { int32 def_temp;\ + ((uchar*) &def_temp)[0]=(M)[0];\ + ((uchar*) &def_temp)[1]=(M)[1];\ + ((uchar*) &def_temp)[2]=(M)[2];\ + ((uchar*) &def_temp)[3]=(M)[3];\ + (V)=def_temp; } while(0) +#define ulongget(V,M) do { uint32 def_temp;\ + ((uchar*) &def_temp)[0]=(M)[0];\ + ((uchar*) &def_temp)[1]=(M)[1];\ + ((uchar*) &def_temp)[2]=(M)[2];\ + ((uchar*) &def_temp)[3]=(M)[3];\ + (V)=def_temp; } while(0) +#define shortstore(T,A) do { uint def_temp=(uint) (A) ;\ + *(((char*)T)+1)=(char)(def_temp); \ + *(((char*)T)+0)=(char)(def_temp >> 8); } while(0) +#define longstore(T,A) do { *(((char*)T)+3)=((A));\ + *(((char*)T)+2)=(((A) >> 8));\ + *(((char*)T)+1)=(((A) >> 16));\ + *(((char*)T)+0)=(((A) >> 24)); } while(0) + +#define floatget(V,M) memcpy(&V, (M), sizeof(float)) +#define floatstore(T,V) memcpy((T), (void*) (&V), sizeof(float)) +#define doubleget(V,M) memcpy(&V, (M), sizeof(double)) +#define doublestore(T,V) memcpy((T), (void *) &V, sizeof(double)) +#define longlongget(V,M) memcpy(&V, (M), sizeof(ulonglong)) +#define longlongstore(T,V) memcpy((T), &V, sizeof(ulonglong)) + +#else + +#define ushortget(V,M) do { V = uint2korr(M); } while(0) +#define shortget(V,M) do { V = sint2korr(M); } while(0) +#define longget(V,M) do { V = sint4korr(M); } while(0) +#define ulongget(V,M) do { V = uint4korr(M); } while(0) +#define shortstore(T,V) int2store(T,V) +#define longstore(T,V) int4store(T,V) +#ifndef floatstore +#define floatstore(T,V) memcpy((T), (void *) (&V), sizeof(float)) +#define floatget(V,M) memcpy(&V, (M), sizeof(float)) +#endif +#ifndef doubleget +#define doubleget(V,M) memcpy(&V, (M), sizeof(double)) +#define doublestore(T,V) memcpy((T), (void *) &V, sizeof(double)) +#endif /* doubleget */ +#define longlongget(V,M) memcpy(&V, (M), sizeof(ulonglong)) +#define longlongstore(T,V) memcpy((T), &V, sizeof(ulonglong)) + +#endif /* WORDS_BIGENDIAN */ + +#ifndef THREAD +#define thread_safe_increment(V,L) ((V)++) +#define thread_safe_add(V,C,L) ((V)+=(C)) +#define thread_safe_sub(V,C,L) ((V)-=(C)) +#define statistic_increment(V,L) ((V)++) +#define statistic_add(V,C,L) ((V)+=(C)) +#endif + +#ifdef _WIN32 +#define SO_EXT ".dll" +#else +#define SO_EXT ".so" +#endif + +#ifndef DBUG_OFF +#define dbug_assert(A) assert(A) +#define DBUG_ASSERT(A) assert(A) +#else +#define dbug_assert(A) +#define DBUG_ASSERT(A) +#endif + +#ifdef HAVE_DLOPEN +#ifdef _WIN32 +#define dlsym(lib, name) GetProcAddress((HMODULE)(lib), name) +#define dlopen(libname, unused) LoadLibraryEx(libname, NULL, 0) +#define dlclose(lib) FreeLibrary((HMODULE)(lib)) +#elif defined(HAVE_DLFCN_H) +#include +#endif +#ifndef HAVE_DLERROR +#define dlerror() "" +#endif +#endif + +#if SIZEOF_CHARP == SIZEOF_INT +typedef unsigned int intptr; +#elif SIZEOF_CHARP == SIZEOF_LONG +typedef unsigned long intptr; +#elif SIZEOF_CHARP == SIZEOF_LONG_LONG +typedef unsigned long long intptr; +#else +#error sizeof(void *) is not sizeof(int, long or long long) +#endif + +#ifdef _WIN32 +#define IF_WIN(A,B) A +#else +#define IF_WIN(A,B) B +#endif + +#if defined(SOLARIS) || defined(__sun) +#define IF_SOLARIS(A,B) A +#else +#define IF_SOLARIS(A,B) B +#endif + +#ifndef RTLD_NOW +#define RTLD_NOW 1 +#endif + +#endif /* _global_h */ diff --git a/vendor/MDBC/include/ma_hashtbl.h b/vendor/MDBC/include/ma_hashtbl.h new file mode 100644 index 00000000..d0954022 --- /dev/null +++ b/vendor/MDBC/include/ma_hashtbl.h @@ -0,0 +1,70 @@ +/************************************************************************************ + Copyright (C) 2000, 2012 MySQL AB & MySQL Finland AB & TCX DataKonsult AB, + Monty Program AB + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not see + or write to the Free Software Foundation, Inc., + 51 Franklin St., Fifth Floor, Boston, MA 02110, USA + + Part of this code includes code from the PHP project which + is freely available from http://www.php.net +*************************************************************************************/ + +#ifndef _ma_hashtbl_h +#define _ma_hashtbl_h +#ifdef __cplusplus +extern "C" { +#endif + +typedef uchar *(*hash_get_key)(const uchar *,uint*,my_bool); +typedef void (*hash_free_key)(void *); + + /* flags for hash_init */ +#define MA_HASHTBL_CASE_INSENSITIVE 1 + +typedef struct st_hash_info { + uint next; /* index to next key */ + uchar *data; /* data for current entry */ +} MA_HASHTBL_LINK; + +typedef struct st_hash { + uint key_offset,key_length; /* Length of key if const length */ + uint records,blength,current_record; + uint flags; + DYNAMIC_ARRAY array; /* Place for hash_keys */ + hash_get_key get_key; + void (*free)(void *); + uint (*calc_hashnr)(const uchar *key,uint length); +} MA_HASHTBL; + +#define ma_hashtbl_init(A,B,C,D,E,F,G) _ma_hashtbl_init(A,B,C,D,E,F,G CALLER_INFO) +my_bool _ma_hashtbl_init(MA_HASHTBL *hash,uint default_array_elements, uint key_offset, + uint key_length, hash_get_key get_key, + void (*free_element)(void*), uint flags CALLER_INFO_PROTO); +void ma_hashtbl_free(MA_HASHTBL *tree); +uchar *ma_hashtbl_element(MA_HASHTBL *hash,uint idx); +void * ma_hashtbl_search(MA_HASHTBL *info,const uchar *key,uint length); +void * ma_hashtbl_next(MA_HASHTBL *info,const uchar *key,uint length); +my_bool ma_hashtbl_insert(MA_HASHTBL *info,const uchar *data); +my_bool ma_hashtbl_delete(MA_HASHTBL *hash,uchar *record); +my_bool ma_hashtbl_update(MA_HASHTBL *hash,uchar *record,uchar *old_key,uint old_key_length); +my_bool ma_hashtbl_check(MA_HASHTBL *hash); /* Only in debug library */ + +#define ma_hashtbl_clear(H) memset((char*) (H), 0,sizeof(*(H))) +#define ma_hashtbl_inited(H) ((H)->array.buffer != 0) + +#ifdef __cplusplus +} +#endif +#endif diff --git a/vendor/MDBC/include/ma_list.h b/vendor/MDBC/include/ma_list.h new file mode 100644 index 00000000..ccd2bbd8 --- /dev/null +++ b/vendor/MDBC/include/ma_list.h @@ -0,0 +1,47 @@ +/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + MA 02111-1301, USA */ + +#ifndef _list_h_ +#define _list_h_ + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct st_list { + struct st_list *prev,*next; + void *data; +} LIST; + +typedef int (*list_walk_action)(void *,void *); + +extern LIST *list_add(LIST *root,LIST *element); +extern LIST *list_delete(LIST *root,LIST *element); +extern LIST *list_cons(void *data,LIST *root); +extern LIST *list_reverse(LIST *root); +extern void list_free(LIST *root,unsigned int free_data); +extern unsigned int list_length(LIST *list); +extern int list_walk(LIST *list,list_walk_action action,char * argument); + +#define list_rest(a) ((a)->next) +#define list_push(a,b) (a)=list_cons((b),(a)) +#define list_pop(A) do {LIST *old=(A); (A)=list_delete(old,old) ; ma_free((char *) old,MYF(MY_FAE)); } while(0) + +#ifdef __cplusplus +} +#endif +#endif diff --git a/vendor/MDBC/include/ma_priv.h b/vendor/MDBC/include/ma_priv.h new file mode 100644 index 00000000..13c979d5 --- /dev/null +++ b/vendor/MDBC/include/ma_priv.h @@ -0,0 +1,60 @@ +/**************************************************************************** + Copyright (C) 2020 MariaDB Corporation + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not see + or write to the Free Software Foundation, Inc., + 51 Franklin St., Fifth Floor, Boston, MA 02110, USA + + Part of this code includes code from the PHP project which + is freely available from http://www.php.net + *****************************************************************************/ +#ifndef MA_PRIV_H +#define MA_PRIV_H + +void free_rows(MYSQL_DATA *cur); +int ma_multi_command(MYSQL *mysql, enum enum_multi_status status); +MYSQL_FIELD * unpack_fields(const MYSQL *mysql, MYSQL_DATA *data, + MA_MEM_ROOT *alloc,uint fields, + my_bool default_value); + +static inline my_bool ma_has_extended_type_info(const MYSQL *mysql) +{ + return ((mysql->extension->mariadb_server_capabilities) & + (MARIADB_CLIENT_EXTENDED_METADATA >> 32)) != 0; +} + +static inline uint ma_extended_type_info_rows(const MYSQL *mysql) +{ + return ma_has_extended_type_info(mysql) ? 1 : 0; +} + +static inline my_bool ma_supports_cache_metadata(const MYSQL *mysql) +{ + return (mysql->extension->mariadb_server_capabilities & + (MARIADB_CLIENT_CACHE_METADATA >> 32)) != 0 ; +} + + +static inline uint ma_result_set_rows(const MYSQL *mysql) +{ + return ma_has_extended_type_info(mysql) ? 9 : 8; +} + +MA_FIELD_EXTENSION *ma_field_extension_deep_dup(MA_MEM_ROOT *memroot, + const MA_FIELD_EXTENSION *from); + +MYSQL_FIELD *ma_duplicate_resultset_metadata(MYSQL_FIELD *fields, size_t count, + MA_MEM_ROOT *memroot); + +#endif diff --git a/vendor/MDBC/include/ma_pthread.h b/vendor/MDBC/include/ma_pthread.h new file mode 100644 index 00000000..c01242fc --- /dev/null +++ b/vendor/MDBC/include/ma_pthread.h @@ -0,0 +1,34 @@ +/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB + 2016 MariaDB Corporation AB + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + MA 02111-1301, USA */ + +/* Defines to make different thread packages compatible */ + +#ifndef _my_pthread_h +#define _my_pthread_h + +#if defined(_WIN32) +#include +typedef CRITICAL_SECTION pthread_mutex_t; +#define pthread_mutex_init(A,B) InitializeCriticalSection(A) +#define pthread_mutex_lock(A) (EnterCriticalSection(A),0) +#define pthread_mutex_unlock(A) LeaveCriticalSection(A) +#define pthread_mutex_destroy(A) DeleteCriticalSection(A) +#define pthread_self() GetCurrentThreadId() +#endif /* defined(_WIN32) */ + +#endif /* _my_ptread_h */ diff --git a/vendor/MDBC/include/ma_pvio.h b/vendor/MDBC/include/ma_pvio.h new file mode 100644 index 00000000..05a0748f --- /dev/null +++ b/vendor/MDBC/include/ma_pvio.h @@ -0,0 +1,139 @@ +#ifndef _ma_pvio_h_ +#define _ma_pvio_h_ +#define cio_defined + +#ifdef HAVE_TLS +#include +#else +#define MARIADB_TLS void +#endif + +/* CONC-492: Allow to buuld plugins outside of MariaDB Connector/C + source tree wnen ma_global.h was not included. */ +#if !defined(_global_h) && !defined(MY_GLOBAL_INCLUDED) +typedef unsigned char uchar; +#endif + +#define PVIO_SET_ERROR if (pvio->set_error) \ + pvio->set_error + +#define PVIO_READ_AHEAD_CACHE_SIZE 16384 +#define PVIO_READ_AHEAD_CACHE_MIN_SIZE 2048 +#define PVIO_EINTR_TRIES 2 + +struct st_ma_pvio_methods; +typedef struct st_ma_pvio_methods PVIO_METHODS; + +#define IS_PVIO_ASYNC(a) \ + ((a)->mysql && (a)->mysql->options.extension && (a)->mysql->options.extension->async_context) + +#define IS_PVIO_ASYNC_ACTIVE(a) \ + (IS_PVIO_ASYNC(a)&& (a)->mysql->options.extension->async_context->active) + +#define IS_MYSQL_ASYNC(a) \ + ((a)->options.extension && (a)->options.extension->async_context) + +#define IS_MYSQL_ASYNC_ACTIVE(a) \ + (IS_MYSQL_ASYNC(a)&& (a)->options.extension->async_context->active) + +enum enum_pvio_timeout { + PVIO_CONNECT_TIMEOUT= 0, + PVIO_READ_TIMEOUT, + PVIO_WRITE_TIMEOUT +}; + +enum enum_pvio_io_event +{ + VIO_IO_EVENT_READ, + VIO_IO_EVENT_WRITE, + VIO_IO_EVENT_CONNECT +}; + +enum enum_pvio_type { + PVIO_TYPE_UNIXSOCKET= 0, + PVIO_TYPE_SOCKET, + PVIO_TYPE_NAMEDPIPE, + PVIO_TYPE_SHAREDMEM, +}; + +enum enum_pvio_operation { + PVIO_READ= 0, + PVIO_WRITE=1 +}; + +#define SHM_DEFAULT_NAME "MYSQL" + +struct st_pvio_callback; + +typedef struct st_pvio_callback { + void (*callback)(MYSQL *mysql, uchar *buffer, size_t size); + struct st_pvio_callback *next; +} PVIO_CALLBACK; + +struct st_ma_pvio { + void *data; + /* read ahead cache */ + uchar *cache; + uchar *cache_pos; + size_t cache_size; + enum enum_pvio_type type; + int timeout[3]; + int ssl_type; /* todo: change to enum (ssl plugins) */ + MARIADB_TLS *ctls; + MYSQL *mysql; + PVIO_METHODS *methods; + void (*set_error)(MYSQL *mysql, unsigned int error_nr, const char *sqlstate, const char *format, ...); + void (*callback)(MARIADB_PVIO *pvio, my_bool is_read, const uchar *buffer, size_t length); +}; + +typedef struct st_ma_pvio_cinfo +{ + const char *host; + const char *unix_socket; + int port; + enum enum_pvio_type type; + MYSQL *mysql; +} MA_PVIO_CINFO; + +struct st_ma_pvio_methods +{ + my_bool (*set_timeout)(MARIADB_PVIO *pvio, enum enum_pvio_timeout type, int timeout); + int (*get_timeout)(MARIADB_PVIO *pvio, enum enum_pvio_timeout type); + ssize_t (*read)(MARIADB_PVIO *pvio, uchar *buffer, size_t length); + ssize_t (*async_read)(MARIADB_PVIO *pvio, uchar *buffer, size_t length); + ssize_t (*write)(MARIADB_PVIO *pvio, const uchar *buffer, size_t length); + ssize_t (*async_write)(MARIADB_PVIO *pvio, const uchar *buffer, size_t length); + int (*wait_io_or_timeout)(MARIADB_PVIO *pvio, my_bool is_read, int timeout); + int (*blocking)(MARIADB_PVIO *pvio, my_bool value, my_bool *old_value); + my_bool (*connect)(MARIADB_PVIO *pvio, MA_PVIO_CINFO *cinfo); + my_bool (*close)(MARIADB_PVIO *pvio); + int (*fast_send)(MARIADB_PVIO *pvio); + int (*keepalive)(MARIADB_PVIO *pvio); + my_bool (*get_handle)(MARIADB_PVIO *pvio, void *handle); + my_bool (*is_blocking)(MARIADB_PVIO *pvio); + my_bool (*is_alive)(MARIADB_PVIO *pvio); + my_bool (*has_data)(MARIADB_PVIO *pvio, ssize_t *data_len); + int(*shutdown)(MARIADB_PVIO *pvio); +}; + +/* Function prototypes */ +MARIADB_PVIO *ma_pvio_init(MA_PVIO_CINFO *cinfo); +void ma_pvio_close(MARIADB_PVIO *pvio); +ssize_t ma_pvio_cache_read(MARIADB_PVIO *pvio, uchar *buffer, size_t length); +ssize_t ma_pvio_read(MARIADB_PVIO *pvio, uchar *buffer, size_t length); +ssize_t ma_pvio_write(MARIADB_PVIO *pvio, const uchar *buffer, size_t length); +int ma_pvio_get_timeout(MARIADB_PVIO *pvio, enum enum_pvio_timeout type); +my_bool ma_pvio_set_timeout(MARIADB_PVIO *pvio, enum enum_pvio_timeout type, int timeout); +int ma_pvio_fast_send(MARIADB_PVIO *pvio); +int ma_pvio_keepalive(MARIADB_PVIO *pvio); +my_socket ma_pvio_get_socket(MARIADB_PVIO *pvio); +my_bool ma_pvio_is_blocking(MARIADB_PVIO *pvio); +my_bool ma_pvio_blocking(MARIADB_PVIO *pvio, my_bool block, my_bool *previous_mode); +my_bool ma_pvio_is_blocking(MARIADB_PVIO *pvio); +int ma_pvio_wait_io_or_timeout(MARIADB_PVIO *pvio, my_bool is_read, int timeout); +my_bool ma_pvio_connect(MARIADB_PVIO *pvio, MA_PVIO_CINFO *cinfo); +my_bool ma_pvio_is_alive(MARIADB_PVIO *pvio); +my_bool ma_pvio_get_handle(MARIADB_PVIO *pvio, void *handle); +my_bool ma_pvio_has_data(MARIADB_PVIO *pvio, ssize_t *length); + +#endif /* _ma_pvio_h_ */ diff --git a/vendor/MDBC/include/ma_server_error.h b/vendor/MDBC/include/ma_server_error.h new file mode 100644 index 00000000..6e776630 --- /dev/null +++ b/vendor/MDBC/include/ma_server_error.h @@ -0,0 +1,2 @@ +/* This file exists for compatibility only */ +#include "mysqld_error.h" diff --git a/vendor/MDBC/include/ma_sha1.h b/vendor/MDBC/include/ma_sha1.h new file mode 100644 index 00000000..2748f114 --- /dev/null +++ b/vendor/MDBC/include/ma_sha1.h @@ -0,0 +1,42 @@ +/**************************************************************************** + Copyright (C) 2012 Monty Program AB + 2016 MariaDB Corporation AB + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not see + or write to the Free Software Foundation, Inc., + 51 Franklin St., Fifth Floor, Boston, MA 02110, USA +*****************************************************************************/ + +/* This code came from the PHP project, initially written by + Stefan Esser */ + +#ifndef SHA1_H +#define SHA1_H + +#define SHA1_MAX_LENGTH 20 +#define SCRAMBLE_LENGTH 20 +#define SCRAMBLE_LENGTH_323 8 + +/* SHA1 context. */ +typedef struct { + uint32 state[5]; /* state (ABCD) */ + uint32 count[2]; /* number of bits, modulo 2^64 (lsb first) */ + unsigned char buffer[64]; /* input buffer */ +} _MA_SHA1_CTX; + +void ma_SHA1Init(_MA_SHA1_CTX *); +void ma_SHA1Update(_MA_SHA1_CTX *, const unsigned char *, size_t); +void ma_SHA1Final(unsigned char[20], _MA_SHA1_CTX *); + +#endif diff --git a/vendor/MDBC/include/ma_string.h b/vendor/MDBC/include/ma_string.h new file mode 100644 index 00000000..10325387 --- /dev/null +++ b/vendor/MDBC/include/ma_string.h @@ -0,0 +1,55 @@ +/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB + 2012 by MontyProgram AB + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + MA 02111-1301, USA */ + +/* defines for the libmariadb library */ + +#ifndef _ma_string_h_ +#define _ma_string_h_ + +#include + +typedef enum { + MY_GCVT_ARG_FLOAT, + MY_GCVT_ARG_DOUBLE +} my_gcvt_arg_type; + +size_t ma_fcvt(double x, int precision, char *to, my_bool *error); +size_t ma_gcvt(double x, my_gcvt_arg_type type, int width, char *to, + my_bool *error); +char *ma_ll2str(long long val,char *dst, int radix); + +#define MAX_ENV_SIZE 1024 + +static inline my_bool ma_check_env_str(const char *env) +{ + unsigned int i; + + if (!env) + return 1; + + for (i=0; i < MAX_ENV_SIZE; i++) + { + if (env[i] == 0) + break; + } + if (i >= MAX_ENV_SIZE) + return 1; + return 0; +} + +#endif diff --git a/vendor/MDBC/include/ma_sys.h b/vendor/MDBC/include/ma_sys.h new file mode 100644 index 00000000..cadffe8a --- /dev/null +++ b/vendor/MDBC/include/ma_sys.h @@ -0,0 +1,542 @@ +/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + MA 02111-1301, USA */ + +#ifndef _my_sys_h +#define _my_sys_h +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef HAVE_AIOWAIT +#include /* Used by record-cache */ +typedef struct my_aio_result { + aio_result_t result; + int pending; +} my_aio_result; +#endif + +#ifndef _mariadb_ctype_h +#include /* for MARIADB_CHARSET_INFO */ +#endif + +#include + +#define MYSYS_PROGRAM_USES_CURSES() \ +do {\ + ma_error_handler_hook = ma_message_curses;\ + mysys_uses_curses=1;\ +} while(0) +#define MYSYS_PROGRAM_DONT_USE_CURSES() \ +do {\ + ma_error_handler_hook = ma_message_no_curses; \ + mysys_uses_curses=0; \ +} while(0) +#define MY_INIT(name) \ +do {\ + ma_progname= name;\ + ma_init();\ +} while(0) + +#define MAXMAPS (4) /* Number of error message maps */ +#define ERRMOD (1000) /* Max number of errors in a map */ +#define ERRMSGSIZE (SC_MAXWIDTH) /* Max length of a error message */ +#define NRERRBUFFS (2) /* Buffers for parameters */ +#define MY_FILE_ERROR ((uint) ~0) + + /* General bitmaps for my_func's */ +#define MY_FFNF 1 /* Fatal if file not found */ +#define MY_FNABP 2 /* Fatal if not all bytes read/written */ +#define MY_NABP 4 /* Error if not all bytes read/written */ +#define MY_FAE 8 /* Fatal if any error */ +#define MY_WME 16 /* Write message on error */ +#define MY_WAIT_IF_FULL 32 /* Wait and try again if disk full error */ +#define MY_RAID 64 /* Support for RAID (not the "Johnson&Johnson"-s one ;) */ +#define MY_DONT_CHECK_FILESIZE 128 /* Option to init_io_cache() */ +#define MY_LINK_WARNING 32 /* my_redel() gives warning if links */ +#define MY_COPYTIME 64 /* my_redel() copies time */ +#define MY_DELETE_OLD 256 /* my_create_with_symlink() */ +#define MY_RESOLVE_LINK 128 /* my_realpath(); Only resolve links */ +#define MY_HOLD_ORIGINAL_MODES 128 /* my_copy() holds to file modes */ +#define MY_REDEL_MAKE_BACKUP 256 +#define MY_SEEK_NOT_DONE 32 /* my_lock may have to do a seek */ +#define MY_DONT_WAIT 64 /* my_lock() don't wait if can't lock */ +#define MY_ZEROFILL 32 /* ma_malloc(), fill array with zero */ +#define MY_ALLOW_ZERO_PTR 64 /* ma_realloc() ; zero ptr -> malloc */ +#define MY_FREE_ON_ERROR 128 /* ma_realloc() ; Free old ptr on error */ +#define MY_HOLD_ON_ERROR 256 /* ma_realloc() ; Return old ptr on error */ +#define MY_THREADSAFE 128 /* pread/pwrite: Don't allow interrupts */ +#define MY_DONT_OVERWRITE_FILE 1024 /* my_copy; Don't overwrite file */ + +#define MY_CHECK_ERROR 1 /* Params to ma_end; Check open-close */ +#define MY_GIVE_INFO 2 /* Give time info about process*/ + +#define ME_HIGHBYTE 8 /* Shift for colours */ +#define ME_NOCUR 1 /* Don't use curses message */ +#define ME_OLDWIN 2 /* Use old window */ +#define ME_BELL 4 /* Ring bell then printing message */ +#define ME_HOLDTANG 8 /* Don't delete last keys */ +#define ME_WAITTOT 16 /* Wait for errtime secs of for a action */ +#define ME_WAITTANG 32 /* Wait for a user action */ +#define ME_NOREFRESH 64 /* Don't refresh screen */ +#define ME_NOINPUT 128 /* Don't use the input library */ +#define ME_COLOUR1 ((1 << ME_HIGHBYTE)) /* Possibly error-colours */ +#define ME_COLOUR2 ((2 << ME_HIGHBYTE)) +#define ME_COLOUR3 ((3 << ME_HIGHBYTE)) + + /* My seek flags */ +#define MY_SEEK_SET 0 +#define MY_SEEK_CUR 1 +#define MY_SEEK_END 2 + + /* My charsets_list flags */ +#define MY_NO_SETS 0 +#define MY_COMPILED_SETS 1 /* show compiled-in sets */ +#define MY_CONFIG_SETS 2 /* sets that have a *.conf file */ +#define MY_INDEX_SETS 4 /* all sets listed in the Index file */ +#define MY_LOADED_SETS 8 /* the sets that are currently loaded */ + + /* Some constants */ +#define MY_WAIT_FOR_USER_TO_FIX_PANIC 60 /* in seconds */ +#define MY_WAIT_GIVE_USER_A_MESSAGE 10 /* Every 10 times of prev */ +#define MIN_COMPRESS_LENGTH 50 /* Don't compress small bl. */ +#define KEYCACHE_BLOCK_SIZE 1024 + + /* root_alloc flags */ +#define MY_KEEP_PREALLOC 1 + + /* defines when allocating data */ + +#define my_checkmalloc() (0) +#undef TERMINATE +#define TERMINATE(A) {} +#define QUICK_SAFEMALLOC +#define NORMAL_SAFEMALLOC +#define ma_malloc_ci(SZ,FLAG) ma_malloc( SZ, FLAG ) +#define CALLER_INFO_PROTO /* nothing */ +#define CALLER_INFO /* nothing */ +#define ORIG_CALLER_INFO /* nothing */ + +#ifdef HAVE_ALLOCA +#if defined(_AIX) && !defined(__GNUC__) +#pragma alloca +#endif /* _AIX */ +#if defined(__GNUC__) && !defined(HAVE_ALLOCA_H) +#ifndef alloca +#define alloca __builtin_alloca +#endif +#endif /* GNUC */ +#define my_alloca(SZ) alloca((size_t) (SZ)) +#define my_afree(PTR) {} +#else +#define my_alloca(SZ) ma_malloc(SZ,MYF(0)) +#define my_afree(PTR) ma_free(PTR) +#endif /* HAVE_ALLOCA */ + +#ifndef errno +#ifdef HAVE_ERRNO_AS_DEFINE +#include /* errno is a define */ +#else +extern int errno; /* declare errno */ +#endif +#endif +extern const char ** NEAR my_errmsg[]; +extern char NEAR errbuff[NRERRBUFFS][ERRMSGSIZE]; +/* tbr +extern int (*ma_error_handler_hook)(uint my_err, const char *str,myf MyFlags); +extern int (*fatal_ma_error_handler_hook)(uint my_err, const char *str, + myf MyFlags); +*/ + +/* charsets */ +/* tbr +extern uint get_charset_number(const char *cs_name); +extern const char *get_charset_name(uint cs_number); +extern my_bool set_default_charset(uint cs, myf flags); +extern my_bool set_default_charset_by_name(const char *cs_name, myf flags); +extern void free_charsets(void); +extern char *list_charsets(myf want_flags); +extern char *get_charsets_dir(char *buf); +*/ +extern MARIADB_CHARSET_INFO *get_charset(uint cs_number, myf flags); +extern MARIADB_CHARSET_INFO *get_charset_by_name(const char *cs_name); +extern MARIADB_CHARSET_INFO *get_charset_by_nr(uint cs_number); + +/* string functions */ +char *ma_strmake(register char *dst, register const char *src, size_t length); + +/* statistics */ +#ifdef TBR +extern ulong _my_cache_w_requests,_my_cache_write,_my_cache_r_requests, + _my_cache_read; +extern ulong _my_blocks_used,_my_blocks_changed; +extern ulong ma_file_opened,ma_stream_opened, ma_tmp_file_created; +extern my_bool key_cache_inited; + + /* Point to current ma_message() */ +extern void (*my_sigtstp_cleanup)(void), + /* Executed before jump to shell */ + (*my_sigtstp_restart)(void), + (*my_abort_hook)(int); + /* Executed when coming from shell */ +extern int NEAR ma_umask, /* Default creation mask */ + NEAR ma_umask_dir, + NEAR my_recived_signals, /* Signals we have got */ + NEAR my_safe_to_handle_signal, /* Set when allowed to SIGTSTP */ + NEAR ma_dont_interrupt; /* call remember_intr when set */ +extern my_bool NEAR mysys_uses_curses, ma_use_symdir; +extern size_t lCurMemory,lMaxMemory; /* from safemalloc */ + +extern ulong ma_default_record_cache_size; +extern my_bool NEAR ma_disable_locking,NEAR ma_disable_async_io, + NEAR ma_disable_flush_key_blocks, NEAR ma_disable_symlinks; +extern char wild_many,wild_one,wild_prefix; +extern const char *charsets_dir; +extern char *defaults_extra_file; +typedef struct wild_file_pack /* Struct to hold info when selecting files */ +{ + uint wilds; /* How many wildcards */ + uint not_pos; /* Start of not-theese-files */ + my_string *wild; /* Pointer to wildcards */ +} WF_PACK; + +struct my_rnd_struct { + unsigned long seed1,seed2,max_value; + double max_value_dbl; +}; + +#endif +typedef struct st_typelib { /* Different types saved here */ + uint count; /* How many types */ + const char *name; /* Name of typelib */ + const char **type_names; +} TYPELIB; + +enum cache_type {READ_CACHE,WRITE_CACHE,READ_FIFO,READ_NET,WRITE_NET}; +enum flush_type { FLUSH_KEEP, FLUSH_RELEASE, FLUSH_IGNORE_CHANGED, + FLUSH_FORCE_WRITE}; + +typedef struct st_record_cache /* Used when caching records */ +{ + File file; + int rc_seek,error,inited; + uint rc_length,read_length,reclength; + my_off_t rc_record_pos,end_of_file; + unsigned char *rc_buff,*rc_buff2,*rc_pos,*rc_end,*rc_request_pos; +#ifdef HAVE_AIOWAIT + int use_async_io; + my_aio_result aio_result; +#endif + enum cache_type type; +} RECORD_CACHE; + + +typedef struct st_dynamic_array { + char *buffer; + uint elements,max_element; + uint alloc_increment; + uint size_of_element; +} DYNAMIC_ARRAY; + +typedef struct st_dynamic_string { + char *str; + size_t length,max_length,alloc_increment; +} DYNAMIC_STRING; + + +typedef struct st_io_cache /* Used when caching files */ +{ + my_off_t pos_in_file,end_of_file; + unsigned char *rc_pos,*rc_end,*buffer,*rc_request_pos; + int (*read_function)(struct st_io_cache *,unsigned char *,uint); + char *file_name; /* if used with 'open_cached_file' */ + char *dir,*prefix; + File file; + int seek_not_done,error; + uint buffer_length,read_length; + myf myflags; /* Flags used to my_read/my_write */ + enum cache_type type; +#ifdef HAVE_AIOWAIT + uint inited; + my_off_t aio_read_pos; + my_aio_result aio_result; +#endif +} IO_CACHE; + +typedef int (*qsort2_cmp)(const void *, const void *, const void *); + + /* defines for mf_iocache */ + + /* Test if buffer is inited */ +#define my_b_clear(info) do{(info)->buffer= 0;} while (0) +#define my_b_inited(info) ((info)->buffer) +#define my_b_EOF INT_MIN + +#define my_b_read(info,Buffer,Count) \ + ((info)->rc_pos + (Count) <= (info)->rc_end ?\ + (memcpy((Buffer),(info)->rc_pos,(size_t) (Count)), \ + ((info)->rc_pos+=(Count)),0) :\ + (*(info)->read_function)((info),(Buffer),(Count))) + +#define my_b_get(info) \ + ((info)->rc_pos != (info)->rc_end ?\ + ((info)->rc_pos++, (int) (uchar) (info)->rc_pos[-1]) :\ + _my_b_get(info)) + +#define my_b_write(info,Buffer,Count) \ + ((info)->rc_pos + (Count) <= (info)->rc_end ?\ + (memcpy((info)->rc_pos,(Buffer),(size_t) (Count)), \ + ((info)->rc_pos+=(Count)),0) :\ + _my_b_write((info),(Buffer),(Count))) + + /* my_b_write_byte doesn't have any err-check */ +#define my_b_write_byte(info,chr) \ + (((info)->rc_pos < (info)->rc_end) ?\ + ((*(info)->rc_pos++)=(chr)) :\ + (_my_b_write((info),0,0) , ((*(info)->rc_pos++)=(chr)))) + +#define my_b_fill_cache(info) \ + (((info)->rc_end=(info)->rc_pos),(*(info)->read_function)((info),0,0)) + +#define my_b_tell(info) ((info)->pos_in_file + \ + ((info)->rc_pos - (info)->rc_request_pos)) + +#define my_b_bytes_in_cache(info) ((uint) ((info)->rc_end - (info)->rc_pos)) + +typedef struct st_changeable_var { + const char *name; /* Name of variable */ + long *varptr; /* Pointer to variable */ + long def_value, /* Default value */ + min_value, /* Min allowed value */ + max_value, /* Max allowed value */ + sub_size, /* Subtract this from given value */ + block_size; /* Value should be a mult. of this */ +} CHANGEABLE_VAR; + + +/* structs for ma_alloc_root */ + +#ifndef ST_MA_USED_MEM_DEFINED +#define ST_MA_USED_MEM_DEFINED +typedef struct st_ma_used_mem { /* struct for once_alloc */ + struct st_ma_used_mem *next; /* Next block in use */ + size_t left; /* memory left in block */ + size_t size; /* Size of block */ +} MA_USED_MEM; + +typedef struct st_ma_mem_root { + MA_USED_MEM *free; + MA_USED_MEM *used; + MA_USED_MEM *pre_alloc; + size_t min_malloc; + size_t block_size; + unsigned int block_num; + unsigned int first_block_usage; + void (*error_handler)(void); +} MA_MEM_ROOT; +#endif + + /* Prototypes for mysys and my_func functions */ + +extern void * _mymalloc(size_t uSize,const char *sFile, + uint uLine, myf MyFlag); +extern void * _myrealloc(void * pPtr,size_t uSize,const char *sFile, + uint uLine, myf MyFlag); +extern void *ma_multi_malloc(myf MyFlags, ...); +extern void _myfree(void * pPtr,const char *sFile,uint uLine, myf MyFlag); +extern int _sanity(const char *sFile,unsigned int uLine); +#ifndef TERMINATE +extern void TERMINATE(FILE *file); +#endif +extern void ma_init_glob_errs(void); +extern FILE *my_fopen(const char *FileName,int Flags,myf MyFlags); +extern FILE *my_fdopen(File Filedes,const char *name, int Flags,myf MyFlags); +extern int my_fclose(FILE *fd,myf MyFlags); +extern int my_chsize(File fd,my_off_t newlength,myf MyFlags); +extern int ma_error _VARARGS((int nr,myf MyFlags, ...)); +extern int ma_printf_error _VARARGS((uint my_err, const char *format, + myf MyFlags, ...) + __attribute__ ((format (printf, 2, 4)))); +extern int ma_vsnprintf( char *str, size_t n, + const char *format, va_list ap ); +extern int ma_snprintf(char* to, size_t n, const char* fmt, ...); +extern int ma_message(uint my_err, const char *str,myf MyFlags); +extern int _mariadb_stderr_out(unsigned int error, const char *errmsg, myf MyFlags); + +extern void ma_init(void); +extern void ma_end(int infoflag); +extern int my_redel(const char *from, const char *to, int MyFlags); +extern int my_copystat(const char *from, const char *to, int MyFlags); +extern my_string my_filename(File fd); + +#ifndef THREAD +extern void dont_break(void); +extern void allow_break(void); +#else +#define dont_break() +#define allow_break() +#endif + +extern void caseup(my_string str,uint length); +extern void casedn(my_string str,uint length); +extern void caseup_str(my_string str); +extern void casedn_str(my_string str); +extern void case_sort(my_string str,uint length); +extern uint ma_dirname_part(my_string to,const char *name); +extern uint ma_dirname_length(const char *name); +#define base_name(A) ((A)+dirname_length(A)) +extern int test_if_hard_path(const char *dir_name); +extern char *ma_convert_dirname(my_string name); +extern void to_unix_path(my_string name); +extern my_string ma_fn_ext(const char *name); +extern my_string fn_same(my_string toname,const char *name,int flag); +extern my_string ma_fn_format(my_string to,const char *name,const char *dsk, + const char *form,int flag); +extern size_s ma_strlength(const char *str); +extern void ma_pack_dirname(my_string to,const char *from); +extern uint unma_pack_dirname(my_string to,const char *from); +extern uint ma_cleanup_dirname(my_string to,const char *from); +extern uint ma_system_filename(my_string to,const char *from); +extern my_string ma_unpack_filename(my_string to,const char *from); +extern my_string ma_intern_filename(my_string to,const char *from); +extern my_string directory_file_name(my_string dst, const char *src); +extern int pack_filename(my_string to, const char *name, size_s max_length); +extern my_string my_path(my_string to,const char *progname, + const char *own_pathname_part); +extern my_string my_load_path(my_string to, const char *path, + const char *own_path_prefix); +extern int wild_compare(const char *str,const char *wildstr); +extern my_string my_strcasestr(const char *src,const char *suffix); +extern int my_strcasecmp(const char *s,const char *t); +extern int my_strsortcmp(const char *s,const char *t); +extern int my_casecmp(const char *s,const char *t,uint length); +extern int my_sortcmp(const char *s,const char *t,uint length); +extern int my_sortncmp(const char *s,uint s_len, const char *t,uint t_len); +#ifdef TBR +extern WF_PACK *wf_comp(my_string str); +extern int wf_test(struct wild_file_pack *wf_pack,const char *name); +extern void wf_end(struct wild_file_pack *buffer); +extern size_s strip_sp(my_string str); +extern void get_date(my_string to,int timeflag,time_t use_time); +extern void soundex(my_string out_pntr, my_string in_pntr,pbool remove_garbage); +extern int init_record_cache(RECORD_CACHE *info,uint cachesize,File file, + uint reclength,enum cache_type type, + pbool use_async_io); +extern int read_cache_record(RECORD_CACHE *info,unsigned char *to); +extern int end_record_cache(RECORD_CACHE *info); +extern int write_cache_record(RECORD_CACHE *info,my_off_t filepos, + const unsigned char *record,uint length); +extern int flush_write_cache(RECORD_CACHE *info); +extern long my_clock(void); +extern sig_handler sigtstp_handler(int signal_number); +extern void handle_recived_signals(void); +extern int init_key_cache(ulong use_mem,ulong leave_this_much_mem); +extern unsigned char *key_cache_read(File file,my_off_t filepos,unsigned char* buff,uint length, + uint block_length,int return_buffer); +extern int key_cache_write(File file,my_off_t filepos,unsigned char* buff,uint length, + uint block_length,int force_write); +extern int flush_key_blocks(int file, enum flush_type type); +extern void end_key_cache(void); +extern sig_handler my_set_alarm_variable(int signo); +extern void my_string_ptr_sort(void *base,uint items,size_s size); +extern void radixsort_for_str_ptr(uchar* base[], uint number_of_elements, + size_s size_of_element,uchar *buffer[]); +extern qsort_t qsort2(void *base_ptr, size_t total_elems, size_t size, + qsort2_cmp cmp, void *cmp_argument); +extern qsort2_cmp get_ptr_compare(uint); +extern int init_io_cache(IO_CACHE *info,File file,uint cachesize, + enum cache_type type,my_off_t seek_offset, + pbool use_async_io, myf cache_myflags); +extern my_bool reinit_io_cache(IO_CACHE *info,enum cache_type type, + my_off_t seek_offset,pbool use_async_io, + pbool clear_cache); +extern int _my_b_read(IO_CACHE *info,unsigned char *Buffer,uint Count); +extern int _my_b_net_read(IO_CACHE *info,unsigned char *Buffer,uint Count); +extern int _my_b_get(IO_CACHE *info); +extern int _my_b_async_read(IO_CACHE *info,unsigned char *Buffer,uint Count); +extern int _my_b_write(IO_CACHE *info,const unsigned char *Buffer,uint Count); +extern int my_block_write(IO_CACHE *info, const unsigned char *Buffer, + uint Count, my_off_t pos); +extern int flush_io_cache(IO_CACHE *info); +extern int end_io_cache(IO_CACHE *info); +extern uint my_b_fill(IO_CACHE *info); +extern void my_b_seek(IO_CACHE *info,my_off_t pos); +extern uint my_b_gets(IO_CACHE *info, char *to, uint max_length); +extern uint my_b_printf(IO_CACHE *info, const char* fmt, ...); +extern uint my_b_vprintf(IO_CACHE *info, const char* fmt, va_list ap); +extern my_bool open_cached_file(IO_CACHE *cache,const char *dir, + const char *prefix, uint cache_size, + myf cache_myflags); +extern my_bool real_open_cached_file(IO_CACHE *cache); +extern void close_cached_file(IO_CACHE *cache); +File create_temp_file(char *to, const char *dir, const char *pfx, + int mode, myf MyFlags); +#define ma_init_dynamic_array(A,B,C,D) init_dynamic_array(A,B,C,D CALLER_INFO) +#endif +extern my_bool ma_init_dynamic_array(DYNAMIC_ARRAY *array,uint element_size, + uint init_alloc,uint alloc_increment CALLER_INFO_PROTO); +#define ma_init_dynamic_array_ci(A,B,C,D) ma_init_dynamic_array(A,B,C,D ORIG_CALLER_INFO) +extern my_bool ma_insert_dynamic(DYNAMIC_ARRAY *array,void * element); +extern unsigned char *ma_alloc_dynamic(DYNAMIC_ARRAY *array); +extern unsigned char *ma_pop_dynamic(DYNAMIC_ARRAY*); +extern my_bool ma_set_dynamic(DYNAMIC_ARRAY *array,void * element,uint array_index); +extern void ma_get_dynamic(DYNAMIC_ARRAY *array,void * element,uint array_index); +extern void ma_delete_dynamic(DYNAMIC_ARRAY *array); +extern void ma_delete_dynamic_element(DYNAMIC_ARRAY *array, uint array_index); +extern void ma_freeze_size(DYNAMIC_ARRAY *array); +#define dynamic_array_ptr(array,array_index) ((array)->buffer+(array_index)*(array)->size_of_element) +#define dynamic_element(array,array_index,type) ((type)((array)->buffer) +(array_index)) +#define push_dynamic(A,B) ma_insert_dynamic(A,B) + +extern int ma_find_type(my_string x,TYPELIB *typelib,uint full_name); +extern void ma_make_type(my_string to,uint nr,TYPELIB *typelib); +extern const char *ma_get_type(TYPELIB *typelib,uint nr); +extern my_bool ma_init_dynamic_string(DYNAMIC_STRING *str, const char *init_str, + size_t init_alloc, size_t alloc_increment); +extern my_bool ma_dynstr_append(DYNAMIC_STRING *str, const char *append); +extern my_bool ma_dynstr_append_quoted(DYNAMIC_STRING *str, + const char *append, size_t len, + char quote); +my_bool ma_dynstr_append_mem(DYNAMIC_STRING *str, const char *append, + size_t length); +extern my_bool ma_dynstr_set(DYNAMIC_STRING *str, const char *init_str); +extern my_bool ma_dynstr_realloc(DYNAMIC_STRING *str, size_t additional_size); +extern void ma_dynstr_free(DYNAMIC_STRING *str); +void set_all_changeable_vars(CHANGEABLE_VAR *vars); +my_bool set_changeable_var(my_string str,CHANGEABLE_VAR *vars); +my_bool set_changeable_varval(const char *var, ulong val, + CHANGEABLE_VAR *vars); +#define ma_alloc_root_inited(A) ((A)->min_malloc != 0) +void ma_init_alloc_root(MA_MEM_ROOT *mem_root, size_t block_size, size_t pre_alloc_size); +void *ma_alloc_root(MA_MEM_ROOT *mem_root, size_t Size); +void ma_free_root(MA_MEM_ROOT *root, myf MyFLAGS); +char *ma_strdup_root(MA_MEM_ROOT *root,const char *str); +char *ma_memdup_root(MA_MEM_ROOT *root,const char *str, size_t len); +void ma_free_defaults(char **argv); +void ma_print_defaults(const char *conf_file, const char **groups); +my_bool _mariadb_compress(unsigned char *, size_t *, size_t *); +my_bool _mariadb_uncompress(unsigned char *, size_t *, size_t *); +unsigned char *_mariadb_compress_alloc(const unsigned char *packet, size_t *len, size_t *complen); +ulong checksum(const unsigned char *mem, uint count); + +#if defined(_MSC_VER) && !defined(_WIN32) +extern void sleep(int sec); +#endif + +#ifdef __cplusplus +} +#endif +#endif /* _my_sys_h */ diff --git a/vendor/MDBC/include/ma_tls.h b/vendor/MDBC/include/ma_tls.h new file mode 100644 index 00000000..9ce49e7c --- /dev/null +++ b/vendor/MDBC/include/ma_tls.h @@ -0,0 +1,161 @@ +#ifndef _ma_tls_h_ +#define _ma_tls_h_ + +enum enum_pvio_tls_type { + SSL_TYPE_DEFAULT=0, +#ifdef _WIN32 + SSL_TYPE_SCHANNEL, +#endif + SSL_TYPE_OPENSSL, + SSL_TYPE_GNUTLS +}; + +#define PROTOCOL_SSLV3 0 +#define PROTOCOL_TLS_1_0 1 +#define PROTOCOL_TLS_1_1 2 +#define PROTOCOL_TLS_1_2 3 +#define PROTOCOL_TLS_1_3 4 +#define PROTOCOL_UNKNOWN 5 +#define PROTOCOL_MAX PROTOCOL_TLS_1_3 + +#define TLS_VERSION_LENGTH 64 +extern char tls_library_version[TLS_VERSION_LENGTH]; + +typedef struct st_ma_pvio_tls { + void *data; + MARIADB_PVIO *pvio; + void *ssl; +} MARIADB_TLS; + +/* Function prototypes */ + +/* ma_tls_start + initializes the ssl library + Parameter: + errmsg pointer to error message buffer + errmsg_len length of error message buffer + Returns: + 0 success + 1 if an error occurred + Notes: + On success the global variable ma_tls_initialized will be set to 1 +*/ +int ma_tls_start(char *errmsg, size_t errmsg_len); + +/* ma_tls_end + unloads/deinitializes ssl library and unsets global variable + ma_tls_initialized +*/ +void ma_tls_end(void); + +/* ma_tls_init + creates a new SSL structure for a SSL connection and loads + client certificates + + Parameters: + MYSQL a mysql structure + Returns: + void * a pointer to internal SSL structure +*/ +void * ma_tls_init(MYSQL *mysql); + +/* ma_tls_connect + performs SSL handshake + Parameters: + MARIADB_TLS MariaDB SSL container + Returns: + 0 success + 1 error +*/ +my_bool ma_tls_connect(MARIADB_TLS *ctls); + +/* ma_tls_read + reads up to length bytes from socket + Parameters: + ctls MariaDB SSL container + buffer read buffer + length buffer length + Returns: + 0-n bytes read + -1 if an error occurred +*/ +ssize_t ma_tls_read(MARIADB_TLS *ctls, const uchar* buffer, size_t length); + +/* ma_tls_write + write buffer to socket + Parameters: + ctls MariaDB SSL container + buffer write buffer + length buffer length + Returns: + 0-n bytes written + -1 if an error occurred +*/ +ssize_t ma_tls_write(MARIADB_TLS *ctls, const uchar* buffer, size_t length); + +/* ma_tls_close + closes SSL connection and frees SSL structure which was previously + created by ma_tls_init call + Parameters: + MARIADB_TLS MariaDB SSL container + Returns: + 0 success + 1 error +*/ +my_bool ma_tls_close(MARIADB_TLS *ctls); + +/* ma_tls_verify_server_cert + validation check of server certificate + Parameter: + MARIADB_TLS MariaDB SSL container + Returns: + ß success + 1 error +*/ +int ma_tls_verify_server_cert(MARIADB_TLS *ctls); + +/* ma_tls_get_cipher + returns cipher for current ssl connection + Parameter: + MARIADB_TLS MariaDB SSL container + Returns: + cipher in use or + NULL on error +*/ +const char *ma_tls_get_cipher(MARIADB_TLS *ssl); + +/* ma_tls_get_finger_print + returns SHA1 finger print of server certificate + Parameter: + MARIADB_TLS MariaDB SSL container + fp buffer for fingerprint + fp_len buffer length + Returns: + actual size of finger print +*/ +unsigned int ma_tls_get_finger_print(MARIADB_TLS *ctls, char *fp, unsigned int fp_len); + +/* ma_tls_get_protocol_version + returns protocol version number in use + Parameter: + MARIADB_TLS MariaDB SSL container + Returns: + protocol number +*/ +int ma_tls_get_protocol_version(MARIADB_TLS *ctls); +const char *ma_pvio_tls_get_protocol_version(MARIADB_TLS *ctls); +int ma_pvio_tls_get_protocol_version_id(MARIADB_TLS *ctls); + +/* Function prototypes */ +MARIADB_TLS *ma_pvio_tls_init(MYSQL *mysql); +my_bool ma_pvio_tls_connect(MARIADB_TLS *ctls); +ssize_t ma_pvio_tls_read(MARIADB_TLS *ctls, const uchar *buffer, size_t length); +ssize_t ma_pvio_tls_write(MARIADB_TLS *ctls, const uchar *buffer, size_t length); +my_bool ma_pvio_tls_close(MARIADB_TLS *ctls); +int ma_pvio_tls_verify_server_cert(MARIADB_TLS *ctls); +const char *ma_pvio_tls_cipher(MARIADB_TLS *ctls); +my_bool ma_pvio_tls_check_fp(MARIADB_TLS *ctls, const char *fp, const char *fp_list); +my_bool ma_pvio_start_ssl(MARIADB_PVIO *pvio); +void ma_pvio_tls_end(); + +#endif /* _ma_tls_h_ */ diff --git a/vendor/MDBC/include/mariadb/ma_io.h b/vendor/MDBC/include/mariadb/ma_io.h new file mode 100644 index 00000000..d39fc06e --- /dev/null +++ b/vendor/MDBC/include/mariadb/ma_io.h @@ -0,0 +1,55 @@ +/* Copyright (C) 2015 MariaDB Corporation AB + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + MA 02111-1301, USA */ + +#ifndef _ma_io_h_ +#define _ma_io_h_ + + +#ifdef HAVE_REMOTEIO +#include +#endif + +enum enum_file_type { + MA_FILE_NONE=0, + MA_FILE_LOCAL=1, + MA_FILE_REMOTE=2 +}; + +typedef struct +{ + enum enum_file_type type; + void *ptr; +} MA_FILE; + +#ifdef HAVE_REMOTEIO +struct st_rio_methods { + MA_FILE *(*mopen)(const char *url, const char *mode); + int (*mclose)(MA_FILE *ptr); + int (*mfeof)(MA_FILE *file); + size_t (*mread)(void *ptr, size_t size, size_t nmemb, MA_FILE *file); + char * (*mgets)(char *ptr, size_t size, MA_FILE *file); +}; +#endif + +/* function prototypes */ +MA_FILE *ma_open(const char *location, const char *mode, MYSQL *mysql); +int ma_close(MA_FILE *file); +int ma_feof(MA_FILE *file); +size_t ma_read(void *ptr, size_t size, size_t nmemb, MA_FILE *file); +char *ma_gets(char *ptr, size_t size, MA_FILE *file); + +#endif diff --git a/vendor/MDBC/include/mariadb_async.h b/vendor/MDBC/include/mariadb_async.h new file mode 100644 index 00000000..cd5385be --- /dev/null +++ b/vendor/MDBC/include/mariadb_async.h @@ -0,0 +1,37 @@ +/* Copyright (C) 2012 MariaDB Services and Kristian Nielsen + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + MA 02111-1301, USA */ + +/* Common definitions for MariaDB non-blocking client library. */ + +#ifndef MYSQL_ASYNC_H +#define MYSQL_ASYNC_H + +extern int my_connect_async(MARIADB_PVIO *pvio, + const struct sockaddr *name, uint namelen, + int vio_timeout); +extern ssize_t my_recv_async(MARIADB_PVIO *pvio, + unsigned char *buf, size_t size, int timeout); +extern ssize_t my_send_async(MARIADB_PVIO *pvio, + const unsigned char *buf, size_t size, + int timeout); +extern my_bool my_io_wait_async(struct mysql_async_context *b, + enum enum_pvio_io_event event, int timeout); +#ifdef HAVE_TLS +extern ssize_t ma_tls_read_async(MARIADB_PVIO *pvio, const uchar *buf, size_t size); +extern ssize_t ma_tls_write_async(MARIADB_PVIO *pvio, const uchar *buf, size_t size); +#endif + +#endif /* MYSQL_ASYNC_H */ diff --git a/vendor/MDBC/include/mariadb_com.h b/vendor/MDBC/include/mariadb_com.h new file mode 100644 index 00000000..70fb28aa --- /dev/null +++ b/vendor/MDBC/include/mariadb_com.h @@ -0,0 +1,469 @@ +/************************************************************************************ + Copyright (C) 2000, 2012 MySQL AB & MySQL Finland AB & TCX DataKonsult AB, + Monty Program AB + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not see + or write to the Free Software Foundation, Inc., + 51 Franklin St., Fifth Floor, Boston, MA 02110, USA + + Part of this code includes code from the PHP project which + is freely available from http://www.php.net +*************************************************************************************/ + +/* +** Common definition between mysql server & client +*/ + +#ifndef _mysql_com_h +#define _mysql_com_h + + +#define NAME_CHAR_LEN 64 +#define NAME_LEN 256 /* Field/table name length */ +#define HOSTNAME_LENGTH 60 +#define SYSTEM_MB_MAX_CHAR_LENGTH 4 +#define USERNAME_CHAR_LENGTH 128 +#define USERNAME_LENGTH (USERNAME_CHAR_LENGTH * SYSTEM_MB_MAX_CHAR_LENGTH) +#define SERVER_VERSION_LENGTH 60 +#define SQLSTATE_LENGTH 5 +#define SCRAMBLE_LENGTH 20 +#define SCRAMBLE_LENGTH_323 8 + +#define LOCAL_HOST "localhost" +#define LOCAL_HOST_NAMEDPIPE "." + +#if defined(_WIN32) && !defined( _CUSTOMCONFIG_) +#define MARIADB_NAMEDPIPE "MySQL" +#define MYSQL_SERVICENAME "MySql" +#endif /* _WIN32 */ + +/* for use in mysql client tools only */ +#define MYSQL_AUTODETECT_CHARSET_NAME "auto" +#define BINCMP_FLAG 131072 + +enum mysql_enum_shutdown_level +{ + SHUTDOWN_DEFAULT = 0, + KILL_QUERY= 254, + KILL_CONNECTION= 255 +}; + +enum enum_server_command +{ + COM_SLEEP = 0, + COM_QUIT, + COM_INIT_DB, + COM_QUERY, + COM_FIELD_LIST, + COM_CREATE_DB, + COM_DROP_DB, + COM_REFRESH, + COM_SHUTDOWN, + COM_STATISTICS, + COM_PROCESS_INFO, + COM_CONNECT, + COM_PROCESS_KILL, + COM_DEBUG, + COM_PING, + COM_TIME = 15, + COM_DELAYED_INSERT, + COM_CHANGE_USER, + COM_BINLOG_DUMP, + COM_TABLE_DUMP, + COM_CONNECT_OUT = 20, + COM_REGISTER_SLAVE, + COM_STMT_PREPARE = 22, + COM_STMT_EXECUTE = 23, + COM_STMT_SEND_LONG_DATA = 24, + COM_STMT_CLOSE = 25, + COM_STMT_RESET = 26, + COM_SET_OPTION = 27, + COM_STMT_FETCH = 28, + COM_DAEMON= 29, + COM_UNSUPPORTED= 30, + COM_RESET_CONNECTION = 31, + COM_STMT_BULK_EXECUTE = 250, + COM_RESERVED_1 = 254, /* former COM_MULTI, now removed */ + COM_END +}; + + +#define NOT_NULL_FLAG 1 /* Field can't be NULL */ +#define PRI_KEY_FLAG 2 /* Field is part of a primary key */ +#define UNIQUE_KEY_FLAG 4 /* Field is part of a unique key */ +#define MULTIPLE_KEY_FLAG 8 /* Field is part of a key */ +#define BLOB_FLAG 16 /* Field is a blob */ +#define UNSIGNED_FLAG 32 /* Field is unsigned */ +#define ZEROFILL_FLAG 64 /* Field is zerofill */ +#define BINARY_FLAG 128 +/* The following are only sent to new clients */ +#define ENUM_FLAG 256 /* field is an enum */ +#define AUTO_INCREMENT_FLAG 512 /* field is a autoincrement field */ +#define TIMESTAMP_FLAG 1024 /* Field is a timestamp */ +#define SET_FLAG 2048 /* field is a set */ +/* new since 3.23.58 */ +#define NO_DEFAULT_VALUE_FLAG 4096 /* Field doesn't have default value */ +#define ON_UPDATE_NOW_FLAG 8192 /* Field is set to NOW on UPDATE */ +/* end new */ +#define NUM_FLAG 32768 /* Field is num (for clients) */ +#define PART_KEY_FLAG 16384 /* Intern; Part of some key */ +#define GROUP_FLAG 32768 /* Intern: Group field */ +#define UNIQUE_FLAG 65536 /* Intern: Used by sql_yacc */ + +#define REFRESH_GRANT 1 /* Refresh grant tables */ +#define REFRESH_LOG 2 /* Start on new log file */ +#define REFRESH_TABLES 4 /* close all tables */ +#define REFRESH_HOSTS 8 /* Flush host cache */ +#define REFRESH_STATUS 16 /* Flush status variables */ +#define REFRESH_THREADS 32 /* Flush thread cache */ +#define REFRESH_SLAVE 64 /* Reset master info and restart slave + thread */ +#define REFRESH_MASTER 128 /* Remove all bin logs in the index + and truncate the index */ + +/* The following can't be set with mysql_refresh() */ +#define REFRESH_READ_LOCK 16384 /* Lock tables for read */ +#define REFRESH_FAST 32768 /* Intern flag */ + +#define CLIENT_MYSQL 1 +#define CLIENT_FOUND_ROWS 2 /* Found instead of affected rows */ +#define CLIENT_LONG_FLAG 4 /* Get all column flags */ +#define CLIENT_CONNECT_WITH_DB 8 /* One can specify db on connect */ +#define CLIENT_NO_SCHEMA 16 /* Don't allow database.table.column */ +#define CLIENT_COMPRESS 32 /* Can use compression protocol */ +#define CLIENT_ODBC 64 /* Odbc client */ +#define CLIENT_LOCAL_FILES 128 /* Can use LOAD DATA LOCAL */ +#define CLIENT_IGNORE_SPACE 256 /* Ignore spaces before '(' */ +#define CLIENT_INTERACTIVE 1024 /* This is an interactive client */ +#define CLIENT_SSL 2048 /* Switch to SSL after handshake */ +#define CLIENT_IGNORE_SIGPIPE 4096 /* IGNORE sigpipes */ +#define CLIENT_TRANSACTIONS 8192 /* Client knows about transactions */ +/* added in 4.x */ +#define CLIENT_PROTOCOL_41 512 +#define CLIENT_RESERVED 16384 +#define CLIENT_SECURE_CONNECTION 32768 +#define CLIENT_MULTI_STATEMENTS (1UL << 16) +#define CLIENT_MULTI_RESULTS (1UL << 17) +#define CLIENT_PS_MULTI_RESULTS (1UL << 18) +#define CLIENT_PLUGIN_AUTH (1UL << 19) +#define CLIENT_CONNECT_ATTRS (1UL << 20) +#define CLIENT_PLUGIN_AUTH_LENENC_CLIENT_DATA (1UL << 21) +#define CLIENT_CAN_HANDLE_EXPIRED_PASSWORDS (1UL << 22) +#define CLIENT_SESSION_TRACKING (1UL << 23) +#define CLIENT_PROGRESS (1UL << 29) /* client supports progress indicator */ +#define CLIENT_PROGRESS_OBSOLETE CLIENT_PROGRESS +#define CLIENT_SSL_VERIFY_SERVER_CERT (1UL << 30) +#define CLIENT_REMEMBER_OPTIONS (1UL << 31) + +/* MariaDB specific capabilities */ +#define MARIADB_CLIENT_FLAGS 0xFFFFFFFF00000000ULL +#define MARIADB_CLIENT_PROGRESS (1ULL << 32) +#define MARIADB_CLIENT_RESERVED_1 (1ULL << 33) /* Former COM_MULTI, don't use */ +#define MARIADB_CLIENT_STMT_BULK_OPERATIONS (1ULL << 34) +/* support of extended data type/format information, since 10.5.0 */ +#define MARIADB_CLIENT_EXTENDED_METADATA (1ULL << 35) +/* Do not resend metadata for prepared statements, since 10.6*/ +#define MARIADB_CLIENT_CACHE_METADATA (1ULL << 36) + +#define IS_MARIADB_EXTENDED_SERVER(mysql)\ + (!(mysql->server_capabilities & CLIENT_MYSQL)) + +#define MARIADB_CLIENT_SUPPORTED_FLAGS (MARIADB_CLIENT_PROGRESS |\ + MARIADB_CLIENT_STMT_BULK_OPERATIONS|\ + MARIADB_CLIENT_EXTENDED_METADATA|\ + MARIADB_CLIENT_CACHE_METADATA) + +#define CLIENT_SUPPORTED_FLAGS (CLIENT_MYSQL |\ + CLIENT_FOUND_ROWS |\ + CLIENT_LONG_FLAG |\ + CLIENT_CONNECT_WITH_DB |\ + CLIENT_NO_SCHEMA |\ + CLIENT_COMPRESS |\ + CLIENT_ODBC |\ + CLIENT_LOCAL_FILES |\ + CLIENT_IGNORE_SPACE |\ + CLIENT_INTERACTIVE |\ + CLIENT_SSL |\ + CLIENT_IGNORE_SIGPIPE |\ + CLIENT_TRANSACTIONS |\ + CLIENT_PROTOCOL_41 |\ + CLIENT_RESERVED |\ + CLIENT_SECURE_CONNECTION |\ + CLIENT_MULTI_STATEMENTS |\ + CLIENT_MULTI_RESULTS |\ + CLIENT_PROGRESS |\ + CLIENT_SSL_VERIFY_SERVER_CERT |\ + CLIENT_REMEMBER_OPTIONS |\ + CLIENT_PLUGIN_AUTH |\ + CLIENT_SESSION_TRACKING |\ + CLIENT_CONNECT_ATTRS) +#define CLIENT_CAPABILITIES (CLIENT_MYSQL | \ + CLIENT_LONG_FLAG |\ + CLIENT_TRANSACTIONS |\ + CLIENT_SECURE_CONNECTION |\ + CLIENT_MULTI_RESULTS | \ + CLIENT_PS_MULTI_RESULTS |\ + CLIENT_PROTOCOL_41 |\ + CLIENT_PLUGIN_AUTH |\ + CLIENT_PLUGIN_AUTH_LENENC_CLIENT_DATA | \ + CLIENT_SESSION_TRACKING |\ + CLIENT_CONNECT_ATTRS) + +#define CLIENT_DEFAULT_FLAGS ((CLIENT_SUPPORTED_FLAGS & ~CLIENT_COMPRESS)\ + & ~CLIENT_SSL) + +#define SERVER_STATUS_IN_TRANS 1 /* Transaction has started */ +#define SERVER_STATUS_AUTOCOMMIT 2 /* Server in auto_commit mode */ +#define SERVER_MORE_RESULTS_EXIST 8 +#define SERVER_QUERY_NO_GOOD_INDEX_USED 16 +#define SERVER_QUERY_NO_INDEX_USED 32 +#define SERVER_STATUS_CURSOR_EXISTS 64 +#define SERVER_STATUS_LAST_ROW_SENT 128 +#define SERVER_STATUS_DB_DROPPED 256 +#define SERVER_STATUS_NO_BACKSLASH_ESCAPES 512 +#define SERVER_STATUS_METADATA_CHANGED 1024 +#define SERVER_QUERY_WAS_SLOW 2048 +#define SERVER_PS_OUT_PARAMS 4096 +#define SERVER_STATUS_IN_TRANS_READONLY 8192 +#define SERVER_SESSION_STATE_CHANGED 16384 +#define SERVER_STATUS_ANSI_QUOTES 32768 + +#define MYSQL_ERRMSG_SIZE 512 +#define NET_READ_TIMEOUT 30 /* Timeout on read */ +#define NET_WRITE_TIMEOUT 60 /* Timeout on write */ +#define NET_WAIT_TIMEOUT (8*60*60) /* Wait for new query */ + +/* for server integration (mysqlbinlog) */ +#define LIST_PROCESS_HOST_LEN 64 +#define MYSQL50_TABLE_NAME_PREFIX "#mysql50#" +#define MYSQL50_TABLE_NAME_PREFIX_LENGTH (sizeof(MYSQL50_TABLE_NAME_PREFIX)-1) +#define SAFE_NAME_LEN (NAME_LEN + MYSQL50_TABLE_NAME_PREFIX_LENGTH) + +struct st_ma_pvio; +typedef struct st_ma_pvio MARIADB_PVIO; + +#define MAX_CHAR_WIDTH 255 /* Max length for a CHAR column */ +#define MAX_BLOB_WIDTH 8192 /* Default width for blob */ + +/* the following defines were added for PHP's mysqli and pdo extensions: + see: CONC-56 +*/ +#define MAX_TINYINT_WIDTH 3 +#define MAX_SMALLINT_WIDTH 5 +#define MAX_MEDIUMINT_WIDTH 8 +#define MAX_INT_WIDTH 10 +#define MAX_BIGINT_WIDTH 20 + +struct st_ma_connection_plugin; + + +typedef struct st_net { + MARIADB_PVIO *pvio; + unsigned char *buff; + unsigned char *buff_end,*write_pos,*read_pos; + my_socket fd; /* For Perl DBI/dbd */ + unsigned long remain_in_buf,length; + unsigned long buf_length, where_b; + unsigned long max_packet, max_packet_size; + unsigned int pkt_nr, compress_pkt_nr; + unsigned int write_timeout, read_timeout, retry_count; + int fcntl; + unsigned int *return_status; + unsigned char reading_or_writing; + char save_char; + char unused_1; + my_bool unused_2; + my_bool compress; + my_bool unused_3; + void *unused_4; + unsigned int last_errno; + unsigned char error; + my_bool unused_5; + my_bool unused_6; + char last_error[MYSQL_ERRMSG_SIZE]; + char sqlstate[SQLSTATE_LENGTH+1]; + struct st_mariadb_net_extension *extension; +} NET; + +#define packet_error ((unsigned int) -1) + +/* used by mysql_set_server_option */ +enum enum_mysql_set_option +{ + MYSQL_OPTION_MULTI_STATEMENTS_ON, + MYSQL_OPTION_MULTI_STATEMENTS_OFF +}; + +enum enum_session_state_type +{ + SESSION_TRACK_SYSTEM_VARIABLES= 0, + SESSION_TRACK_SCHEMA, + SESSION_TRACK_STATE_CHANGE, + /* currently not supported by MariaDB Server */ + SESSION_TRACK_GTIDS, + SESSION_TRACK_TRANSACTION_CHARACTERISTICS, + SESSION_TRACK_TRANSACTION_STATE /* make sure that SESSION_TRACK_END always points + to last element of enum !! */ +}; + +#define SESSION_TRACK_BEGIN 0 +#define SESSION_TRACK_END SESSION_TRACK_TRANSACTION_STATE +#define SESSION_TRACK_TYPES (SESSION_TRACK_END + 1) + +/* SESSION_TRACK_TRANSACTION_TYPE was renamed to SESSION_TRACK_TRANSACTION_STATE + in 3e699a1738cdfb0a2c5b8eabfa8301b8d11cf711. + This is a workaround to prevent breaking of travis and buildbot tests. + TODO: Remove this after server fixes */ +#define SESSION_TRACK_TRANSACTION_TYPE SESSION_TRACK_TRANSACTION_STATE + +enum enum_field_types { MYSQL_TYPE_DECIMAL, MYSQL_TYPE_TINY, + MYSQL_TYPE_SHORT, MYSQL_TYPE_LONG, + MYSQL_TYPE_FLOAT, MYSQL_TYPE_DOUBLE, + MYSQL_TYPE_NULL, MYSQL_TYPE_TIMESTAMP, + MYSQL_TYPE_LONGLONG,MYSQL_TYPE_INT24, + MYSQL_TYPE_DATE, MYSQL_TYPE_TIME, + MYSQL_TYPE_DATETIME, MYSQL_TYPE_YEAR, + MYSQL_TYPE_NEWDATE, MYSQL_TYPE_VARCHAR, + MYSQL_TYPE_BIT, + /* + the following types are not used by client, + only for mysqlbinlog!! + */ + MYSQL_TYPE_TIMESTAMP2, + MYSQL_TYPE_DATETIME2, + MYSQL_TYPE_TIME2, + /* --------------------------------------------- */ + MYSQL_TYPE_JSON=245, + MYSQL_TYPE_NEWDECIMAL=246, + MYSQL_TYPE_ENUM=247, + MYSQL_TYPE_SET=248, + MYSQL_TYPE_TINY_BLOB=249, + MYSQL_TYPE_MEDIUM_BLOB=250, + MYSQL_TYPE_LONG_BLOB=251, + MYSQL_TYPE_BLOB=252, + MYSQL_TYPE_VAR_STRING=253, + MYSQL_TYPE_STRING=254, + MYSQL_TYPE_GEOMETRY=255, + MAX_NO_FIELD_TYPES }; + +#define FIELD_TYPE_CHAR FIELD_TYPE_TINY /* For compatibility */ +#define FIELD_TYPE_INTERVAL FIELD_TYPE_ENUM /* For compatibility */ +#define FIELD_TYPE_DECIMAL MYSQL_TYPE_DECIMAL +#define FIELD_TYPE_NEWDECIMAL MYSQL_TYPE_NEWDECIMAL +#define FIELD_TYPE_TINY MYSQL_TYPE_TINY +#define FIELD_TYPE_SHORT MYSQL_TYPE_SHORT +#define FIELD_TYPE_LONG MYSQL_TYPE_LONG +#define FIELD_TYPE_FLOAT MYSQL_TYPE_FLOAT +#define FIELD_TYPE_DOUBLE MYSQL_TYPE_DOUBLE +#define FIELD_TYPE_NULL MYSQL_TYPE_NULL +#define FIELD_TYPE_TIMESTAMP MYSQL_TYPE_TIMESTAMP +#define FIELD_TYPE_LONGLONG MYSQL_TYPE_LONGLONG +#define FIELD_TYPE_INT24 MYSQL_TYPE_INT24 +#define FIELD_TYPE_DATE MYSQL_TYPE_DATE +#define FIELD_TYPE_TIME MYSQL_TYPE_TIME +#define FIELD_TYPE_DATETIME MYSQL_TYPE_DATETIME +#define FIELD_TYPE_YEAR MYSQL_TYPE_YEAR +#define FIELD_TYPE_NEWDATE MYSQL_TYPE_NEWDATE +#define FIELD_TYPE_ENUM MYSQL_TYPE_ENUM +#define FIELD_TYPE_SET MYSQL_TYPE_SET +#define FIELD_TYPE_TINY_BLOB MYSQL_TYPE_TINY_BLOB +#define FIELD_TYPE_MEDIUM_BLOB MYSQL_TYPE_MEDIUM_BLOB +#define FIELD_TYPE_LONG_BLOB MYSQL_TYPE_LONG_BLOB +#define FIELD_TYPE_BLOB MYSQL_TYPE_BLOB +#define FIELD_TYPE_VAR_STRING MYSQL_TYPE_VAR_STRING +#define FIELD_TYPE_STRING MYSQL_TYPE_STRING +#define FIELD_TYPE_GEOMETRY MYSQL_TYPE_GEOMETRY +#define FIELD_TYPE_BIT MYSQL_TYPE_BIT + +extern unsigned long max_allowed_packet; +extern unsigned long net_buffer_length; + +#define net_new_transaction(net) ((net)->pkt_nr=0) + +int ma_net_init(NET *net, MARIADB_PVIO *pvio); +void ma_net_end(NET *net); +void ma_net_clear(NET *net); +int ma_net_flush(NET *net); +int ma_net_write(NET *net,const unsigned char *packet, size_t len); +int ma_net_write_command(NET *net,unsigned char command,const char *packet, + size_t len, my_bool disable_flush); +int ma_net_real_write(NET *net,const char *packet, size_t len); +extern unsigned long ma_net_read(NET *net); + +struct rand_struct { + unsigned long seed1,seed2,max_value; + double max_value_dbl; +}; + + /* The following is for user defined functions */ + +enum Item_result {STRING_RESULT,REAL_RESULT,INT_RESULT,ROW_RESULT,DECIMAL_RESULT}; + +typedef struct st_udf_args +{ + unsigned int arg_count; /* Number of arguments */ + enum Item_result *arg_type; /* Pointer to item_results */ + char **args; /* Pointer to argument */ + unsigned long *lengths; /* Length of string arguments */ + char *maybe_null; /* Set to 1 for all maybe_null args */ +} UDF_ARGS; + + /* This holds information about the result */ + +typedef struct st_udf_init +{ + my_bool maybe_null; /* 1 if function can return NULL */ + unsigned int decimals; /* for real functions */ + unsigned int max_length; /* For string functions */ + char *ptr; /* free pointer for function data */ + my_bool const_item; /* 0 if result is independent of arguments */ +} UDF_INIT; + +/* Connection types */ +#define MARIADB_CONNECTION_UNIXSOCKET 0 +#define MARIADB_CONNECTION_TCP 1 +#define MARIADB_CONNECTION_NAMEDPIPE 2 +#define MARIADB_CONNECTION_SHAREDMEM 3 + + /* Constants when using compression */ +#define NET_HEADER_SIZE 4 /* standard header size */ +#define COMP_HEADER_SIZE 3 /* compression header extra size */ + + /* Prototypes to password functions */ +#define native_password_plugin_name "mysql_native_password" +#define old_password_plugin_name "mysql_old_password" + +#ifdef __cplusplus +extern "C" { +#endif + +char *ma_scramble_323(char *to,const char *message,const char *password); +void ma_scramble_41(const unsigned char *buffer, const char *scramble, const char *password); +void ma_hash_password(unsigned long *result, const char *password, size_t len); +void ma_make_scrambled_password(char *to,const char *password); + +/* Some other useful functions */ + +void mariadb_load_defaults(const char *conf_file, const char **groups, + int *argc, char ***argv); +my_bool ma_thread_init(void); +void ma_thread_end(void); + +#ifdef __cplusplus +} +#endif + +#define NULL_LENGTH ((unsigned long) ~0) /* For net_store_length */ + +#endif diff --git a/vendor/MDBC/include/mariadb_ctype.h b/vendor/MDBC/include/mariadb_ctype.h new file mode 100644 index 00000000..3b218c31 --- /dev/null +++ b/vendor/MDBC/include/mariadb_ctype.h @@ -0,0 +1,76 @@ +/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + MA 02111-1301, USA */ + +/* + A better implementation of the UNIX ctype(3) library. + Notes: my_global.h should be included before ctype.h +*/ + +#ifndef _mariadb_ctype_h +#define _mariadb_ctype_h + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define CHARSET_DIR "charsets/" +#define MY_CS_NAME_SIZE 32 + +#define MADB_DEFAULT_CHARSET_NAME "latin1" +#define MADB_DEFAULT_COLLATION_NAME "latin1_swedish_ci" +#define MADB_AUTODETECT_CHARSET_NAME "auto" + +/* we use the mysqlnd implementation */ +typedef struct ma_charset_info_st +{ + unsigned int nr; /* so far only 1 byte for charset */ + unsigned int state; + const char *csname; + const char *name; + const char *dir; + unsigned int codepage; + const char *encoding; + unsigned int char_minlen; + unsigned int char_maxlen; + unsigned int (*mb_charlen)(unsigned int c); + unsigned int (*mb_valid)(const char *start, const char *end); +} MARIADB_CHARSET_INFO; + +extern const MARIADB_CHARSET_INFO mariadb_compiled_charsets[]; +extern MARIADB_CHARSET_INFO *ma_default_charset_info; +extern MARIADB_CHARSET_INFO *ma_charset_bin; +extern MARIADB_CHARSET_INFO *ma_charset_latin1; +extern MARIADB_CHARSET_INFO *ma_charset_utf8_general_ci; +extern MARIADB_CHARSET_INFO *ma_charset_utf16le_general_ci; + +MARIADB_CHARSET_INFO *find_compiled_charset(unsigned int cs_number); +MARIADB_CHARSET_INFO *find_compiled_charset_by_name(const char *name); + +size_t mysql_cset_escape_quotes(const MARIADB_CHARSET_INFO *cset, char *newstr, const char *escapestr, size_t escapestr_len); +size_t mysql_cset_escape_slashes(const MARIADB_CHARSET_INFO *cset, char *newstr, const char *escapestr, size_t escapestr_len); +const char* madb_get_os_character_set(void); +#ifdef _WIN32 +int madb_get_windows_cp(const char *charset); +#endif + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/vendor/MDBC/include/mariadb_dyncol.h b/vendor/MDBC/include/mariadb_dyncol.h new file mode 100644 index 00000000..216431a8 --- /dev/null +++ b/vendor/MDBC/include/mariadb_dyncol.h @@ -0,0 +1,259 @@ +/* Copyright (c) 2011, Monty Program Ab + Copyright (c) 2011, Oleksandr Byelkin + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must the following disclaimer in + the documentation and/or other materials provided with the + distribution. + + THIS SOFTWARE IS PROVIDED BY ``AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL OR + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + SUCH DAMAGE. +*/ + +#ifndef ma_dyncol_h +#define ma_dyncol_h + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef LIBMARIADB +#include +#include +#endif +#include + +#ifndef longlong_defined +#if defined(HAVE_LONG_LONG) && SIZEOF_LONG != 8 +typedef unsigned long long int ulonglong; /* ulong or unsigned long long */ +typedef long long int longlong; +#else +typedef unsigned long ulonglong; /* ulong or unsigned long long */ +typedef long longlong; +#endif +#define longlong_defined +#endif + + +#ifndef _my_sys_h +typedef struct st_dynamic_string +{ + char *str; + size_t length,max_length,alloc_increment; +} DYNAMIC_STRING; +#endif + +struct st_mysql_lex_string +{ + char *str; + size_t length; +}; +typedef struct st_mysql_lex_string MYSQL_LEX_STRING; +typedef struct st_mysql_lex_string LEX_STRING; +/* + Limits of implementation +*/ +#define MAX_TOTAL_NAME_LENGTH 65535 +#define MAX_NAME_LENGTH (MAX_TOTAL_NAME_LENGTH/4) + +/* NO and OK is the same used just to show semantics */ +#define ER_DYNCOL_NO ER_DYNCOL_OK + +enum enum_dyncol_func_result +{ + ER_DYNCOL_OK= 0, + ER_DYNCOL_YES= 1, /* For functions returning 0/1 */ + ER_DYNCOL_FORMAT= -1, /* Wrong format of the encoded string */ + ER_DYNCOL_LIMIT= -2, /* Some limit reached */ + ER_DYNCOL_RESOURCE= -3, /* Out of resourses */ + ER_DYNCOL_DATA= -4, /* Incorrect input data */ + ER_DYNCOL_UNKNOWN_CHARSET= -5, /* Unknown character set */ + ER_DYNCOL_TRUNCATED= 2 /* OK, but data was truncated */ +}; + +typedef DYNAMIC_STRING DYNAMIC_COLUMN; + +enum enum_dynamic_column_type +{ + DYN_COL_NULL= 0, + DYN_COL_INT, + DYN_COL_UINT, + DYN_COL_DOUBLE, + DYN_COL_STRING, + DYN_COL_DECIMAL, + DYN_COL_DATETIME, + DYN_COL_DATE, + DYN_COL_TIME, + DYN_COL_DYNCOL +}; + +typedef enum enum_dynamic_column_type DYNAMIC_COLUMN_TYPE; + +struct st_dynamic_column_value +{ + DYNAMIC_COLUMN_TYPE type; + union + { + long long long_value; + unsigned long long ulong_value; + double double_value; + struct { + MYSQL_LEX_STRING value; + MARIADB_CHARSET_INFO *charset; + } string; +#ifndef LIBMARIADB + struct { + decimal_digit_t buffer[DECIMAL_BUFF_LENGTH]; + decimal_t value; + } decimal; +#endif + MYSQL_TIME time_value; + } x; +}; + +typedef struct st_dynamic_column_value DYNAMIC_COLUMN_VALUE; + +#ifdef MADYNCOL_DEPRECATED +enum enum_dyncol_func_result +dynamic_column_create(DYNAMIC_COLUMN *str, + uint column_nr, DYNAMIC_COLUMN_VALUE *value); + +enum enum_dyncol_func_result +dynamic_column_create_many(DYNAMIC_COLUMN *str, + uint column_count, + uint *column_numbers, + DYNAMIC_COLUMN_VALUE *values); +enum enum_dyncol_func_result +dynamic_column_update(DYNAMIC_COLUMN *org, uint column_nr, + DYNAMIC_COLUMN_VALUE *value); +enum enum_dyncol_func_result +dynamic_column_update_many(DYNAMIC_COLUMN *str, + uint add_column_count, + uint *column_numbers, + DYNAMIC_COLUMN_VALUE *values); + +enum enum_dyncol_func_result +dynamic_column_exists(DYNAMIC_COLUMN *org, uint column_nr); + +enum enum_dyncol_func_result +dynamic_column_list(DYNAMIC_COLUMN *org, DYNAMIC_ARRAY *array_of_uint); + +enum enum_dyncol_func_result +dynamic_column_get(DYNAMIC_COLUMN *org, uint column_nr, + DYNAMIC_COLUMN_VALUE *store_it_here); +#endif + +/* new functions */ +enum enum_dyncol_func_result +mariadb_dyncol_create_many_num(DYNAMIC_COLUMN *str, + uint column_count, + uint *column_numbers, + DYNAMIC_COLUMN_VALUE *values, + my_bool new_string); +enum enum_dyncol_func_result +mariadb_dyncol_create_many_named(DYNAMIC_COLUMN *str, + uint column_count, + MYSQL_LEX_STRING *column_keys, + DYNAMIC_COLUMN_VALUE *values, + my_bool new_string); + + +enum enum_dyncol_func_result +mariadb_dyncol_update_many_num(DYNAMIC_COLUMN *str, + uint add_column_count, + uint *column_keys, + DYNAMIC_COLUMN_VALUE *values); +enum enum_dyncol_func_result +mariadb_dyncol_update_many_named(DYNAMIC_COLUMN *str, + uint add_column_count, + MYSQL_LEX_STRING *column_keys, + DYNAMIC_COLUMN_VALUE *values); + + +enum enum_dyncol_func_result +mariadb_dyncol_exists_num(DYNAMIC_COLUMN *org, uint column_nr); +enum enum_dyncol_func_result +mariadb_dyncol_exists_named(DYNAMIC_COLUMN *str, MYSQL_LEX_STRING *name); + +/* List of not NULL columns */ +enum enum_dyncol_func_result +mariadb_dyncol_list_num(DYNAMIC_COLUMN *str, uint *count, uint **nums); +enum enum_dyncol_func_result +mariadb_dyncol_list_named(DYNAMIC_COLUMN *str, uint *count, + MYSQL_LEX_STRING **names); + +/* + if the column do not exists it is NULL +*/ +enum enum_dyncol_func_result +mariadb_dyncol_get_num(DYNAMIC_COLUMN *org, uint column_nr, + DYNAMIC_COLUMN_VALUE *store_it_here); +enum enum_dyncol_func_result +mariadb_dyncol_get_named(DYNAMIC_COLUMN *str, MYSQL_LEX_STRING *name, + DYNAMIC_COLUMN_VALUE *store_it_here); + +my_bool mariadb_dyncol_has_names(DYNAMIC_COLUMN *str); + +enum enum_dyncol_func_result +mariadb_dyncol_check(DYNAMIC_COLUMN *str); + +enum enum_dyncol_func_result +mariadb_dyncol_json(DYNAMIC_COLUMN *str, DYNAMIC_STRING *json); + +void mariadb_dyncol_free(DYNAMIC_COLUMN *str); + +#define mariadb_dyncol_init(A) memset((A), 0, sizeof(DYNAMIC_COLUMN)) +#define dynamic_column_initialize(A) mariadb_dyncol_init((A)) +#define dynamic_column_column_free(A) mariadb_dyncol_free((A)) + +/* conversion of values to 3 base types */ +enum enum_dyncol_func_result +mariadb_dyncol_val_str(DYNAMIC_STRING *str, DYNAMIC_COLUMN_VALUE *val, + MARIADB_CHARSET_INFO *cs, char quote); +enum enum_dyncol_func_result +mariadb_dyncol_val_long(longlong *ll, DYNAMIC_COLUMN_VALUE *val); +enum enum_dyncol_func_result +mariadb_dyncol_val_double(double *dbl, DYNAMIC_COLUMN_VALUE *val); + +enum enum_dyncol_func_result +mariadb_dyncol_unpack(DYNAMIC_COLUMN *str, + uint *count, + MYSQL_LEX_STRING **names, DYNAMIC_COLUMN_VALUE **vals); + +int mariadb_dyncol_column_cmp_named(const MYSQL_LEX_STRING *s1, + const MYSQL_LEX_STRING *s2); + +enum enum_dyncol_func_result +mariadb_dyncol_column_count(DYNAMIC_COLUMN *str, uint *column_count); + +#define mariadb_dyncol_value_init(V) \ +do {\ + (V)->type= DYN_COL_NULL;\ +} while(0) + +/* + Prepare value for using as decimal +*/ +void mariadb_dyncol_prepare_decimal(DYNAMIC_COLUMN_VALUE *value); + + +#ifdef __cplusplus +} +#endif +#endif diff --git a/vendor/MDBC/include/mariadb_rpl.h b/vendor/MDBC/include/mariadb_rpl.h new file mode 100644 index 00000000..315543f7 --- /dev/null +++ b/vendor/MDBC/include/mariadb_rpl.h @@ -0,0 +1,305 @@ +/* Copyright (C) 2018 MariaDB Corporation AB + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + MA 02111-1301, USA */ +#ifndef _mariadb_rpl_h_ +#define _mariadb_rpl_h_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +#define MARIADB_RPL_VERSION 0x0001 +#define MARIADB_RPL_REQUIRED_VERSION 0x0001 + +/* Protocol flags */ +#define MARIADB_RPL_BINLOG_DUMP_NON_BLOCK 1 +#define MARIADB_RPL_BINLOG_SEND_ANNOTATE_ROWS 2 +#define MARIADB_RPL_IGNORE_HEARTBEAT (1 << 17) + +#define EVENT_HEADER_OFS 20 + +#define FL_GROUP_COMMIT_ID 2 +#define FL_STMT_END 1 + +#define LOG_EVENT_ARTIFICIAL_F 0x20 + + +/* Options */ +enum mariadb_rpl_option { + MARIADB_RPL_FILENAME, /* Filename and length */ + MARIADB_RPL_START, /* Start position */ + MARIADB_RPL_SERVER_ID, /* Server ID */ + MARIADB_RPL_FLAGS, /* Protocol flags */ + MARIADB_RPL_GTID_CALLBACK, /* GTID callback function */ + MARIADB_RPL_GTID_DATA, /* GTID data */ + MARIADB_RPL_BUFFER +}; + +/* Event types: From MariaDB Server sql/log_event.h */ +enum mariadb_rpl_event { + UNKNOWN_EVENT= 0, + START_EVENT_V3= 1, + QUERY_EVENT= 2, + STOP_EVENT= 3, + ROTATE_EVENT= 4, + INTVAR_EVENT= 5, + LOAD_EVENT= 6, + SLAVE_EVENT= 7, + CREATE_FILE_EVENT= 8, + APPEND_BLOCK_EVENT= 9, + EXEC_LOAD_EVENT= 10, + DELETE_FILE_EVENT= 11, + NEW_LOAD_EVENT= 12, + RAND_EVENT= 13, + USER_VAR_EVENT= 14, + FORMAT_DESCRIPTION_EVENT= 15, + XID_EVENT= 16, + BEGIN_LOAD_QUERY_EVENT= 17, + EXECUTE_LOAD_QUERY_EVENT= 18, + TABLE_MAP_EVENT = 19, + + PRE_GA_WRITE_ROWS_EVENT = 20, /* deprecated */ + PRE_GA_UPDATE_ROWS_EVENT = 21, /* deprecated */ + PRE_GA_DELETE_ROWS_EVENT = 22, /* deprecated */ + + WRITE_ROWS_EVENT_V1 = 23, + UPDATE_ROWS_EVENT_V1 = 24, + DELETE_ROWS_EVENT_V1 = 25, + INCIDENT_EVENT= 26, + HEARTBEAT_LOG_EVENT= 27, + IGNORABLE_LOG_EVENT= 28, + ROWS_QUERY_LOG_EVENT= 29, + WRITE_ROWS_EVENT = 30, + UPDATE_ROWS_EVENT = 31, + DELETE_ROWS_EVENT = 32, + GTID_LOG_EVENT= 33, + ANONYMOUS_GTID_LOG_EVENT= 34, + PREVIOUS_GTIDS_LOG_EVENT= 35, + TRANSACTION_CONTEXT_EVENT= 36, + VIEW_CHANGE_EVENT= 37, + XA_PREPARE_LOG_EVENT= 38, + + /* + Add new events here - right above this comment! + Existing events (except ENUM_END_EVENT) should never change their numbers + */ + + /* New MySQL/Sun events are to be added right above this comment */ + MYSQL_EVENTS_END, + + MARIA_EVENTS_BEGIN= 160, + ANNOTATE_ROWS_EVENT= 160, + BINLOG_CHECKPOINT_EVENT= 161, + GTID_EVENT= 162, + GTID_LIST_EVENT= 163, + START_ENCRYPTION_EVENT= 164, + QUERY_COMPRESSED_EVENT = 165, + WRITE_ROWS_COMPRESSED_EVENT_V1 = 166, + UPDATE_ROWS_COMPRESSED_EVENT_V1 = 167, + DELETE_ROWS_COMPRESSED_EVENT_V1 = 168, + WRITE_ROWS_COMPRESSED_EVENT = 169, + UPDATE_ROWS_COMPRESSED_EVENT = 170, + DELETE_ROWS_COMPRESSED_EVENT = 171, + + /* Add new MariaDB events here - right above this comment! */ + + ENUM_END_EVENT /* end marker */ +}; + +typedef struct { + char *str; + size_t length; +} MARIADB_STRING; + +enum mariadb_row_event_type { + WRITE_ROWS= 0, + UPDATE_ROWS= 1, + DELETE_ROWS= 2 +}; + +/* Global transaction id */ +typedef struct st_mariadb_gtid { + unsigned int domain_id; + unsigned int server_id; + unsigned long long sequence_nr; +} MARIADB_GTID; + +/* Generic replication handle */ +typedef struct st_mariadb_rpl { + unsigned int version; + MYSQL *mysql; + char *filename; + uint32_t filename_length; + unsigned char *buffer; + unsigned long buffer_size; + uint32_t server_id; + unsigned long start_position; + uint32_t flags; + uint8_t fd_header_len; /* header len from last format description event */ + uint8_t use_checksum; +} MARIADB_RPL; + +/* Event header */ +struct st_mariadb_rpl_rotate_event { + unsigned long long position; + MARIADB_STRING filename; +}; + +struct st_mariadb_rpl_query_event { + uint32_t thread_id; + uint32_t seconds; + MARIADB_STRING database; + uint32_t errornr; + MARIADB_STRING status; + MARIADB_STRING statement; +}; + +struct st_mariadb_rpl_gtid_list_event { + uint32_t gtid_cnt; + MARIADB_GTID *gtid; +}; + +struct st_mariadb_rpl_format_description_event +{ + uint16_t format; + char *server_version; + uint32_t timestamp; + uint8_t header_len; +}; + +struct st_mariadb_rpl_checkpoint_event { + MARIADB_STRING filename; +}; + +struct st_mariadb_rpl_xid_event { + uint64_t transaction_nr; +}; + +struct st_mariadb_rpl_gtid_event { + uint64_t sequence_nr; + uint32_t domain_id; + uint8_t flags; + uint64_t commit_id; +}; + +struct st_mariadb_rpl_annotate_rows_event { + MARIADB_STRING statement; +}; + +struct st_mariadb_rpl_table_map_event { + unsigned long long table_id; + MARIADB_STRING database; + MARIADB_STRING table; + unsigned int column_count; + MARIADB_STRING column_types; + MARIADB_STRING metadata; + char *null_indicator; +}; + +struct st_mariadb_rpl_rand_event { + unsigned long long first_seed; + unsigned long long second_seed; +}; + +struct st_mariadb_rpl_encryption_event { + char scheme; + unsigned int key_version; + char *nonce; +}; + +struct st_mariadb_rpl_intvar_event { + char type; + unsigned long long value; +}; + +struct st_mariadb_rpl_uservar_event { + MARIADB_STRING name; + uint8_t is_null; + uint8_t type; + uint32_t charset_nr; + MARIADB_STRING value; + uint8_t flags; +}; + +struct st_mariadb_rpl_rows_event { + enum mariadb_row_event_type type; + uint64_t table_id; + uint16_t flags; + uint32_t column_count; + char *column_bitmap; + char *column_update_bitmap; + size_t row_data_size; + void *row_data; +}; + +struct st_mariadb_rpl_heartbeat_event { + uint32_t timestamp; + uint32_t next_position; + uint8_t type; + uint16_t flags; +}; + +typedef struct st_mariadb_rpl_event +{ + /* common header */ + MA_MEM_ROOT memroot; + unsigned int checksum; + char ok; + enum mariadb_rpl_event event_type; + unsigned int timestamp; + unsigned int server_id; + unsigned int event_length; + unsigned int next_event_pos; + unsigned short flags; + /****************/ + union { + struct st_mariadb_rpl_rotate_event rotate; + struct st_mariadb_rpl_query_event query; + struct st_mariadb_rpl_format_description_event format_description; + struct st_mariadb_rpl_gtid_list_event gtid_list; + struct st_mariadb_rpl_checkpoint_event checkpoint; + struct st_mariadb_rpl_xid_event xid; + struct st_mariadb_rpl_gtid_event gtid; + struct st_mariadb_rpl_annotate_rows_event annotate_rows; + struct st_mariadb_rpl_table_map_event table_map; + struct st_mariadb_rpl_rand_event rand; + struct st_mariadb_rpl_encryption_event encryption; + struct st_mariadb_rpl_intvar_event intvar; + struct st_mariadb_rpl_uservar_event uservar; + struct st_mariadb_rpl_rows_event rows; + struct st_mariadb_rpl_heartbeat_event heartbeat; + } event; +} MARIADB_RPL_EVENT; + +#define mariadb_rpl_init(a) mariadb_rpl_init_ex((a), MARIADB_RPL_VERSION) + +/* Function prototypes */ +MARIADB_RPL * STDCALL mariadb_rpl_init_ex(MYSQL *mysql, unsigned int version); + +int mariadb_rpl_optionsv(MARIADB_RPL *rpl, enum mariadb_rpl_option, ...); +int mariadb_rpl_get_optionsv(MARIADB_RPL *rpl, enum mariadb_rpl_option, ...); + +int STDCALL mariadb_rpl_open(MARIADB_RPL *rpl); +void STDCALL mariadb_rpl_close(MARIADB_RPL *rpl); +MARIADB_RPL_EVENT * STDCALL mariadb_rpl_fetch(MARIADB_RPL *rpl, MARIADB_RPL_EVENT *event); +void STDCALL mariadb_free_rpl_event(MARIADB_RPL_EVENT *event); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/vendor/MDBC/include/mariadb_stmt.h b/vendor/MDBC/include/mariadb_stmt.h new file mode 100644 index 00000000..d07540ea --- /dev/null +++ b/vendor/MDBC/include/mariadb_stmt.h @@ -0,0 +1,298 @@ +/************************************************************************ + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + MA 02111-1301, USA + + Part of this code includes code from PHP's mysqlnd extension + (written by Andrey Hristov, Georg Richter and Ulf Wendel), freely + available from http://www.php.net/software + +*************************************************************************/ + +#define MYSQL_NO_DATA 100 +#define MYSQL_DATA_TRUNCATED 101 +#define MYSQL_DEFAULT_PREFETCH_ROWS (unsigned long) 1 + +/* Bind flags */ +#define MADB_BIND_DUMMY 1 + +#define MARIADB_STMT_BULK_SUPPORTED(stmt)\ + ((stmt)->mysql && \ + (!((stmt)->mysql->server_capabilities & CLIENT_MYSQL) &&\ + ((stmt)->mysql->extension->mariadb_server_capabilities & \ + (MARIADB_CLIENT_STMT_BULK_OPERATIONS >> 32)))) + +#define SET_CLIENT_STMT_ERROR(a, b, c, d) \ +do { \ + (a)->last_errno= (b);\ + strncpy((a)->sqlstate, (c), SQLSTATE_LENGTH);\ + (a)->sqlstate[SQLSTATE_LENGTH]= 0;\ + strncpy((a)->last_error, (d) ? (d) : ER((b)), MYSQL_ERRMSG_SIZE);\ + (a)->last_error[MYSQL_ERRMSG_SIZE - 1]= 0;\ +} while (0) + +#define CLEAR_CLIENT_STMT_ERROR(a) \ +do { \ + (a)->last_errno= 0;\ + strcpy((a)->sqlstate, "00000");\ + (a)->last_error[0]= 0;\ +} while (0) + +#define MYSQL_PS_SKIP_RESULT_W_LEN -1 +#define MYSQL_PS_SKIP_RESULT_STR -2 +#define STMT_ID_LENGTH 4 + + +typedef struct st_mysql_stmt MYSQL_STMT; + +typedef MYSQL_RES* (*mysql_stmt_use_or_store_func)(MYSQL_STMT *); + +enum enum_stmt_attr_type +{ + STMT_ATTR_UPDATE_MAX_LENGTH, + STMT_ATTR_CURSOR_TYPE, + STMT_ATTR_PREFETCH_ROWS, + + /* MariaDB only */ + STMT_ATTR_PREBIND_PARAMS=200, + STMT_ATTR_ARRAY_SIZE, + STMT_ATTR_ROW_SIZE, + STMT_ATTR_STATE, + STMT_ATTR_CB_USER_DATA, + STMT_ATTR_CB_PARAM, + STMT_ATTR_CB_RESULT +}; + +enum enum_cursor_type +{ + CURSOR_TYPE_NO_CURSOR= 0, + CURSOR_TYPE_READ_ONLY= 1, + CURSOR_TYPE_FOR_UPDATE= 2, + CURSOR_TYPE_SCROLLABLE= 4 +}; + +enum enum_indicator_type +{ + STMT_INDICATOR_NTS=-1, + STMT_INDICATOR_NONE=0, + STMT_INDICATOR_NULL=1, + STMT_INDICATOR_DEFAULT=2, + STMT_INDICATOR_IGNORE=3, + STMT_INDICATOR_IGNORE_ROW=4 +}; + +/* + bulk PS flags +*/ +#define STMT_BULK_FLAG_CLIENT_SEND_TYPES 128 +#define STMT_BULK_FLAG_INSERT_ID_REQUEST 64 + +typedef enum mysql_stmt_state +{ + MYSQL_STMT_INITTED = 0, + MYSQL_STMT_PREPARED, + MYSQL_STMT_EXECUTED, + MYSQL_STMT_WAITING_USE_OR_STORE, + MYSQL_STMT_USE_OR_STORE_CALLED, + MYSQL_STMT_USER_FETCHING, /* fetch_row_buff or fetch_row_unbuf */ + MYSQL_STMT_FETCH_DONE +} enum_mysqlnd_stmt_state; + +typedef struct st_mysql_bind +{ + unsigned long *length; /* output length pointer */ + my_bool *is_null; /* Pointer to null indicator */ + void *buffer; /* buffer to get/put data */ + /* set this if you want to track data truncations happened during fetch */ + my_bool *error; + union { + unsigned char *row_ptr; /* for the current data position */ + char *indicator; /* indicator variable */ + } u; + void (*store_param_func)(NET *net, struct st_mysql_bind *param); + void (*fetch_result)(struct st_mysql_bind *, MYSQL_FIELD *, + unsigned char **row); + void (*skip_result)(struct st_mysql_bind *, MYSQL_FIELD *, + unsigned char **row); + /* output buffer length, must be set when fetching str/binary */ + unsigned long buffer_length; + unsigned long offset; /* offset position for char/binary fetch */ + unsigned long length_value; /* Used if length is 0 */ + unsigned int flags; /* special flags, e.g. for dummy bind */ + unsigned int pack_length; /* Internal length for packed data */ + enum enum_field_types buffer_type; /* buffer type */ + my_bool error_value; /* used if error is 0 */ + my_bool is_unsigned; /* set if integer type is unsigned */ + my_bool long_data_used; /* If used with mysql_send_long_data */ + my_bool is_null_value; /* Used if is_null is 0 */ + void *extension; +} MYSQL_BIND; + +typedef struct st_mysqlnd_upsert_result +{ + unsigned int warning_count; + unsigned int server_status; + unsigned long long affected_rows; + unsigned long long last_insert_id; +} mysql_upsert_status; + +typedef struct st_mysql_cmd_buffer +{ + unsigned char *buffer; + size_t length; +} MYSQL_CMD_BUFFER; + +typedef struct st_mysql_error_info +{ + unsigned int error_no; + char error[MYSQL_ERRMSG_SIZE+1]; + char sqlstate[SQLSTATE_LENGTH + 1]; +} mysql_error_info; + + +struct st_mysqlnd_stmt_methods +{ + my_bool (*prepare)(const MYSQL_STMT * stmt, const char * const query, size_t query_len); + my_bool (*execute)(const MYSQL_STMT * stmt); + MYSQL_RES * (*use_result)(const MYSQL_STMT * stmt); + MYSQL_RES * (*store_result)(const MYSQL_STMT * stmt); + MYSQL_RES * (*get_result)(const MYSQL_STMT * stmt); + my_bool (*free_result)(const MYSQL_STMT * stmt); + my_bool (*seek_data)(const MYSQL_STMT * stmt, unsigned long long row); + my_bool (*reset)(const MYSQL_STMT * stmt); + my_bool (*close)(const MYSQL_STMT * stmt); /* private */ + my_bool (*dtor)(const MYSQL_STMT * stmt); /* use this for mysqlnd_stmt_close */ + + my_bool (*fetch)(const MYSQL_STMT * stmt, my_bool * const fetched_anything); + + my_bool (*bind_param)(const MYSQL_STMT * stmt, const MYSQL_BIND bind); + my_bool (*refresh_bind_param)(const MYSQL_STMT * stmt); + my_bool (*bind_result)(const MYSQL_STMT * stmt, const MYSQL_BIND *bind); + my_bool (*send_long_data)(const MYSQL_STMT * stmt, unsigned int param_num, + const char * const data, size_t length); + MYSQL_RES *(*get_parameter_metadata)(const MYSQL_STMT * stmt); + MYSQL_RES *(*get_result_metadata)(const MYSQL_STMT * stmt); + unsigned long long (*get_last_insert_id)(const MYSQL_STMT * stmt); + unsigned long long (*get_affected_rows)(const MYSQL_STMT * stmt); + unsigned long long (*get_num_rows)(const MYSQL_STMT * stmt); + + unsigned int (*get_param_count)(const MYSQL_STMT * stmt); + unsigned int (*get_field_count)(const MYSQL_STMT * stmt); + unsigned int (*get_warning_count)(const MYSQL_STMT * stmt); + + unsigned int (*get_error_no)(const MYSQL_STMT * stmt); + const char * (*get_error_str)(const MYSQL_STMT * stmt); + const char * (*get_sqlstate)(const MYSQL_STMT * stmt); + + my_bool (*get_attribute)(const MYSQL_STMT * stmt, enum enum_stmt_attr_type attr_type, const void * value); + my_bool (*set_attribute)(const MYSQL_STMT * stmt, enum enum_stmt_attr_type attr_type, const void * value); + void (*set_error)(MYSQL_STMT *stmt, unsigned int error_nr, const char *sqlstate, const char *format, ...); +}; + +typedef int (*mysql_stmt_fetch_row_func)(MYSQL_STMT *stmt, unsigned char **row); +typedef void (*ps_result_callback)(void *data, unsigned int column, unsigned char **row); +typedef my_bool *(*ps_param_callback)(void *data, MYSQL_BIND *bind, unsigned int row_nr); + +struct st_mysql_stmt +{ + MA_MEM_ROOT mem_root; + MYSQL *mysql; + unsigned long stmt_id; + unsigned long flags;/* cursor is set here */ + enum_mysqlnd_stmt_state state; + MYSQL_FIELD *fields; + unsigned int field_count; + unsigned int param_count; + unsigned char send_types_to_server; + MYSQL_BIND *params; + MYSQL_BIND *bind; + MYSQL_DATA result; /* we don't use mysqlnd's result set logic */ + MYSQL_ROWS *result_cursor; + my_bool bind_result_done; + my_bool bind_param_done; + + mysql_upsert_status upsert_status; + + unsigned int last_errno; + char last_error[MYSQL_ERRMSG_SIZE+1]; + char sqlstate[SQLSTATE_LENGTH + 1]; + + my_bool update_max_length; + unsigned long prefetch_rows; + LIST list; + + my_bool cursor_exists; + + void *extension; + mysql_stmt_fetch_row_func fetch_row_func; + unsigned int execute_count;/* count how many times the stmt was executed */ + mysql_stmt_use_or_store_func default_rset_handler; + struct st_mysqlnd_stmt_methods *m; + unsigned int array_size; + size_t row_size; + unsigned int prebind_params; + void *user_data; + ps_result_callback result_callback; + ps_param_callback param_callback; +}; + +typedef void (*ps_field_fetch_func)(MYSQL_BIND *r_param, const MYSQL_FIELD * field, unsigned char **row); +typedef struct st_mysql_perm_bind { + ps_field_fetch_func func; + /* should be signed int */ + int pack_len; + unsigned long max_len; +} MYSQL_PS_CONVERSION; + +extern MYSQL_PS_CONVERSION mysql_ps_fetch_functions[MYSQL_TYPE_GEOMETRY + 1]; +unsigned long ma_net_safe_read(MYSQL *mysql); +void mysql_init_ps_subsystem(void); +unsigned long net_field_length(unsigned char **packet); +int ma_simple_command(MYSQL *mysql,enum enum_server_command command, const char *arg, + size_t length, my_bool skipp_check, void *opt_arg); +/* + * function prototypes + */ +MYSQL_STMT * STDCALL mysql_stmt_init(MYSQL *mysql); +int STDCALL mysql_stmt_prepare(MYSQL_STMT *stmt, const char *query, unsigned long length); +int STDCALL mysql_stmt_execute(MYSQL_STMT *stmt); +int STDCALL mysql_stmt_fetch(MYSQL_STMT *stmt); +int STDCALL mysql_stmt_fetch_column(MYSQL_STMT *stmt, MYSQL_BIND *bind_arg, unsigned int column, unsigned long offset); +int STDCALL mysql_stmt_store_result(MYSQL_STMT *stmt); +unsigned long STDCALL mysql_stmt_param_count(MYSQL_STMT * stmt); +my_bool STDCALL mysql_stmt_attr_set(MYSQL_STMT *stmt, enum enum_stmt_attr_type attr_type, const void *attr); +my_bool STDCALL mysql_stmt_attr_get(MYSQL_STMT *stmt, enum enum_stmt_attr_type attr_type, void *attr); +my_bool STDCALL mysql_stmt_bind_param(MYSQL_STMT * stmt, MYSQL_BIND * bnd); +my_bool STDCALL mysql_stmt_bind_result(MYSQL_STMT * stmt, MYSQL_BIND * bnd); +my_bool STDCALL mysql_stmt_close(MYSQL_STMT * stmt); +my_bool STDCALL mysql_stmt_reset(MYSQL_STMT * stmt); +my_bool STDCALL mysql_stmt_free_result(MYSQL_STMT *stmt); +my_bool STDCALL mysql_stmt_send_long_data(MYSQL_STMT *stmt, unsigned int param_number, const char *data, unsigned long length); +MYSQL_RES *STDCALL mysql_stmt_result_metadata(MYSQL_STMT *stmt); +MYSQL_RES *STDCALL mysql_stmt_param_metadata(MYSQL_STMT *stmt); +unsigned int STDCALL mysql_stmt_errno(MYSQL_STMT * stmt); +const char *STDCALL mysql_stmt_error(MYSQL_STMT * stmt); +const char *STDCALL mysql_stmt_sqlstate(MYSQL_STMT * stmt); +MYSQL_ROW_OFFSET STDCALL mysql_stmt_row_seek(MYSQL_STMT *stmt, MYSQL_ROW_OFFSET offset); +MYSQL_ROW_OFFSET STDCALL mysql_stmt_row_tell(MYSQL_STMT *stmt); +void STDCALL mysql_stmt_data_seek(MYSQL_STMT *stmt, unsigned long long offset); +unsigned long long STDCALL mysql_stmt_num_rows(MYSQL_STMT *stmt); +unsigned long long STDCALL mysql_stmt_affected_rows(MYSQL_STMT *stmt); +unsigned long long STDCALL mysql_stmt_insert_id(MYSQL_STMT *stmt); +unsigned int STDCALL mysql_stmt_field_count(MYSQL_STMT *stmt); +int STDCALL mysql_stmt_next_result(MYSQL_STMT *stmt); +my_bool STDCALL mysql_stmt_more_results(MYSQL_STMT *stmt); +int STDCALL mariadb_stmt_execute_direct(MYSQL_STMT *stmt, const char *stmt_str, size_t length); +MYSQL_FIELD * STDCALL mariadb_stmt_fetch_fields(MYSQL_STMT *stmt); diff --git a/vendor/MDBC/include/mariadb_version.h.in b/vendor/MDBC/include/mariadb_version.h.in new file mode 100644 index 00000000..a82dbb71 --- /dev/null +++ b/vendor/MDBC/include/mariadb_version.h.in @@ -0,0 +1,44 @@ +/* Copyright Abandoned 1996, 1999, 2001 MySQL AB + This file is public domain and comes with NO WARRANTY of any kind */ + +/* Version numbers for protocol & mysqld */ + +#ifndef _mariadb_version_h_ +#define _mariadb_version_h_ + +#ifdef _CUSTOMCONFIG_ +#include +#else +#define PROTOCOL_VERSION @PROTOCOL_VERSION@ +#define MARIADB_CLIENT_VERSION_STR "@MARIADB_CLIENT_VERSION@" +#define MARIADB_BASE_VERSION "@MARIADB_BASE_VERSION@" +#define MARIADB_VERSION_ID @MARIADB_VERSION_ID@ +#define MARIADB_PORT @MARIADB_PORT@ +#define MARIADB_UNIX_ADDR "@MARIADB_UNIX_ADDR@" +#ifndef MYSQL_UNIX_ADDR +#define MYSQL_UNIX_ADDR MARIADB_UNIX_ADDR +#endif +#ifndef MYSQL_PORT +#define MYSQL_PORT MARIADB_PORT +#endif + +#define MYSQL_CONFIG_NAME "my" +#define MYSQL_VERSION_ID @MARIADB_VERSION_ID@ +#define MYSQL_SERVER_VERSION "@MARIADB_CLIENT_VERSION@-MariaDB" + +#define MARIADB_PACKAGE_VERSION "@CPACK_PACKAGE_VERSION@" +#define MARIADB_PACKAGE_VERSION_ID @MARIADB_PACKAGE_VERSION_ID@ +#define MARIADB_SYSTEM_TYPE "@CMAKE_SYSTEM_NAME@" +#define MARIADB_MACHINE_TYPE "@CMAKE_SYSTEM_PROCESSOR@" +#define MARIADB_PLUGINDIR "@CMAKE_INSTALL_PREFIX@/@INSTALL_PLUGINDIR@" + +/* mysqld compile time options */ +#ifndef MYSQL_CHARSET +#define MYSQL_CHARSET "@default_charset@" +#endif +#endif + +/* Source information */ +#define CC_SOURCE_REVISION "@CC_SOURCE_REVISION@" + +#endif /* _mariadb_version_h_ */ diff --git a/vendor/MDBC/include/mysql.h b/vendor/MDBC/include/mysql.h new file mode 100644 index 00000000..ccd1149c --- /dev/null +++ b/vendor/MDBC/include/mysql.h @@ -0,0 +1,893 @@ +/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB + 2012 by MontyProgram AB + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + MA 02111-1301, USA */ + +/* defines for the libmariadb library */ + +#ifndef _mysql_h +#define _mysql_h + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef LIBMARIADB +#define LIBMARIADB +#endif +#ifndef MYSQL_CLIENT +#define MYSQL_CLIENT +#endif + +#include + +#if !defined (_global_h) && !defined (MY_GLOBAL_INCLUDED) /* If not standard header */ +#include +typedef char my_bool; +typedef unsigned long long my_ulonglong; + +#if !defined(_WIN32) +#define STDCALL +#else +#define STDCALL __stdcall +#endif + +#ifndef my_socket_defined +#define my_socket_defined +#if defined(_WIN64) +#define my_socket unsigned long long +#elif defined(_WIN32) +#define my_socket unsigned int +#else +typedef int my_socket; +#endif +#endif +#endif +#include "mariadb_com.h" +#include "mariadb_version.h" +#include "ma_list.h" +#include "mariadb_ctype.h" + + +typedef struct st_ma_const_string +{ + const char *str; + size_t length; +} MARIADB_CONST_STRING; + + +#ifndef ST_MA_USED_MEM_DEFINED +#define ST_MA_USED_MEM_DEFINED + typedef struct st_ma_used_mem { /* struct for once_alloc */ + struct st_ma_used_mem *next; /* Next block in use */ + size_t left; /* memory left in block */ + size_t size; /* Size of block */ + } MA_USED_MEM; + + typedef struct st_ma_mem_root { + MA_USED_MEM *free; + MA_USED_MEM *used; + MA_USED_MEM *pre_alloc; + size_t min_malloc; + size_t block_size; + unsigned int block_num; + unsigned int first_block_usage; + void (*error_handler)(void); + } MA_MEM_ROOT; +#endif + +extern unsigned int mysql_port; +extern char *mysql_unix_port; +extern unsigned int mariadb_deinitialize_ssl; + +#define IS_PRI_KEY(n) ((n) & PRI_KEY_FLAG) +#define IS_NOT_NULL(n) ((n) & NOT_NULL_FLAG) +#define IS_BLOB(n) ((n) & BLOB_FLAG) +#define IS_NUM(t) (((t) <= MYSQL_TYPE_INT24 && (t) != MYSQL_TYPE_TIMESTAMP) || (t) == MYSQL_TYPE_YEAR || (t) == MYSQL_TYPE_NEWDECIMAL) +#define IS_NUM_FIELD(f) ((f)->flags & NUM_FLAG) +#define INTERNAL_NUM_FIELD(f) (((f)->type <= MYSQL_TYPE_INT24 && ((f)->type != MYSQL_TYPE_TIMESTAMP || (f)->length == 14 || (f)->length == 8)) || (f)->type == MYSQL_TYPE_YEAR || (f)->type == MYSQL_TYPE_NEWDECIMAL || (f)->type == MYSQL_TYPE_DECIMAL) + + typedef struct st_mysql_field { + char *name; /* Name of column */ + char *org_name; /* Name of original column (added after 3.23.58) */ + char *table; /* Table of column if column was a field */ + char *org_table; /* Name of original table (added after 3.23.58 */ + char *db; /* table schema (added after 3.23.58) */ + char *catalog; /* table catalog (added after 3.23.58) */ + char *def; /* Default value (set by mysql_list_fields) */ + unsigned long length; /* Width of column */ + unsigned long max_length; /* Max width of selected set */ + /* added after 3.23.58 */ + unsigned int name_length; + unsigned int org_name_length; + unsigned int table_length; + unsigned int org_table_length; + unsigned int db_length; + unsigned int catalog_length; + unsigned int def_length; + /***********************/ + unsigned int flags; /* Div flags */ + unsigned int decimals; /* Number of decimals in field */ + unsigned int charsetnr; /* char set number (added in 4.1) */ + enum enum_field_types type; /* Type of field. Se mysql_com.h for types */ + void *extension; /* added in 4.1 */ + } MYSQL_FIELD; + + typedef char **MYSQL_ROW; /* return data as array of strings */ + typedef unsigned int MYSQL_FIELD_OFFSET; /* offset to current field */ + +#define SET_CLIENT_ERROR(a, b, c, d) \ + do { \ + (a)->net.last_errno= (b);\ + strncpy((a)->net.sqlstate, (c), SQLSTATE_LENGTH);\ + (a)->net.sqlstate[SQLSTATE_LENGTH]= 0;\ + strncpy((a)->net.last_error, (d) ? (d) : ER((b)), MYSQL_ERRMSG_SIZE - 1);\ + (a)->net.last_error[MYSQL_ERRMSG_SIZE - 1]= 0;\ + } while(0) + +/* For mysql_async.c */ +#define set_mariadb_error(A,B,C) SET_CLIENT_ERROR((A),(B),(C),0) +extern const char *SQLSTATE_UNKNOWN; +#define unknown_sqlstate SQLSTATE_UNKNOWN + +#define CLEAR_CLIENT_ERROR(a) \ + do { \ + (a)->net.last_errno= 0;\ + strcpy((a)->net.sqlstate, "00000");\ + (a)->net.last_error[0]= '\0';\ + if ((a)->net.extension)\ + (a)->net.extension->extended_errno= 0;\ + } while (0) + +#define MYSQL_COUNT_ERROR (~(unsigned long long) 0) + + + typedef struct st_mysql_rows { + struct st_mysql_rows *next; /* list of rows */ + MYSQL_ROW data; + unsigned long length; + } MYSQL_ROWS; + + typedef MYSQL_ROWS *MYSQL_ROW_OFFSET; /* offset to current row */ + + typedef struct st_mysql_data { + MYSQL_ROWS *data; + void *embedded_info; + MA_MEM_ROOT alloc; + unsigned long long rows; + unsigned int fields; + void *extension; + } MYSQL_DATA; + + enum mysql_option + { + MYSQL_OPT_CONNECT_TIMEOUT, + MYSQL_OPT_COMPRESS, + MYSQL_OPT_NAMED_PIPE, + MYSQL_INIT_COMMAND, + MYSQL_READ_DEFAULT_FILE, + MYSQL_READ_DEFAULT_GROUP, + MYSQL_SET_CHARSET_DIR, + MYSQL_SET_CHARSET_NAME, + MYSQL_OPT_LOCAL_INFILE, + MYSQL_OPT_PROTOCOL, + MYSQL_SHARED_MEMORY_BASE_NAME, + MYSQL_OPT_READ_TIMEOUT, + MYSQL_OPT_WRITE_TIMEOUT, + MYSQL_OPT_USE_RESULT, + MYSQL_OPT_USE_REMOTE_CONNECTION, + MYSQL_OPT_USE_EMBEDDED_CONNECTION, + MYSQL_OPT_GUESS_CONNECTION, + MYSQL_SET_CLIENT_IP, + MYSQL_SECURE_AUTH, + MYSQL_REPORT_DATA_TRUNCATION, + MYSQL_OPT_RECONNECT, + MYSQL_OPT_SSL_VERIFY_SERVER_CERT, + MYSQL_PLUGIN_DIR, + MYSQL_DEFAULT_AUTH, + MYSQL_OPT_BIND, + MYSQL_OPT_SSL_KEY, + MYSQL_OPT_SSL_CERT, + MYSQL_OPT_SSL_CA, + MYSQL_OPT_SSL_CAPATH, + MYSQL_OPT_SSL_CIPHER, + MYSQL_OPT_SSL_CRL, + MYSQL_OPT_SSL_CRLPATH, + /* Connection attribute options */ + MYSQL_OPT_CONNECT_ATTR_RESET, + MYSQL_OPT_CONNECT_ATTR_ADD, + MYSQL_OPT_CONNECT_ATTR_DELETE, + MYSQL_SERVER_PUBLIC_KEY, + MYSQL_ENABLE_CLEARTEXT_PLUGIN, + MYSQL_OPT_CAN_HANDLE_EXPIRED_PASSWORDS, + MYSQL_OPT_SSL_ENFORCE, + MYSQL_OPT_MAX_ALLOWED_PACKET, + MYSQL_OPT_NET_BUFFER_LENGTH, + MYSQL_OPT_TLS_VERSION, + + /* MariaDB specific */ + MYSQL_PROGRESS_CALLBACK=5999, + MYSQL_OPT_NONBLOCK, + /* MariaDB Connector/C specific */ + MYSQL_DATABASE_DRIVER=7000, + MARIADB_OPT_SSL_FP, /* deprecated, use MARIADB_OPT_TLS_PEER_FP instead */ + MARIADB_OPT_SSL_FP_LIST, /* deprecated, use MARIADB_OPT_TLS_PEER_FP_LIST instead */ + MARIADB_OPT_TLS_PASSPHRASE, /* passphrase for encrypted certificates */ + MARIADB_OPT_TLS_CIPHER_STRENGTH, + MARIADB_OPT_TLS_VERSION, + MARIADB_OPT_TLS_PEER_FP, /* single finger print for server certificate verification */ + MARIADB_OPT_TLS_PEER_FP_LIST, /* finger print white list for server certificate verification */ + MARIADB_OPT_CONNECTION_READ_ONLY, + MYSQL_OPT_CONNECT_ATTRS, /* for mysql_get_optionv */ + MARIADB_OPT_USERDATA, + MARIADB_OPT_CONNECTION_HANDLER, + MARIADB_OPT_PORT, + MARIADB_OPT_UNIXSOCKET, + MARIADB_OPT_PASSWORD, + MARIADB_OPT_HOST, + MARIADB_OPT_USER, + MARIADB_OPT_SCHEMA, + MARIADB_OPT_DEBUG, + MARIADB_OPT_FOUND_ROWS, + MARIADB_OPT_MULTI_RESULTS, + MARIADB_OPT_MULTI_STATEMENTS, + MARIADB_OPT_INTERACTIVE, + MARIADB_OPT_PROXY_HEADER, + MARIADB_OPT_IO_WAIT, + MARIADB_OPT_SKIP_READ_RESPONSE + }; + + enum mariadb_value { + MARIADB_CHARSET_ID, + MARIADB_CHARSET_NAME, + MARIADB_CLIENT_ERRORS, + MARIADB_CLIENT_VERSION, + MARIADB_CLIENT_VERSION_ID, + MARIADB_CONNECTION_ASYNC_TIMEOUT, + MARIADB_CONNECTION_ASYNC_TIMEOUT_MS, + MARIADB_CONNECTION_MARIADB_CHARSET_INFO, + MARIADB_CONNECTION_ERROR, + MARIADB_CONNECTION_ERROR_ID, + 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_SQLSTATE, + MARIADB_CONNECTION_SSL_CIPHER, + MARIADB_TLS_LIBRARY, + MARIADB_CONNECTION_TLS_VERSION, + MARIADB_CONNECTION_TLS_VERSION_ID, + MARIADB_CONNECTION_TYPE, + MARIADB_CONNECTION_UNIX_SOCKET, + MARIADB_CONNECTION_USER, + MARIADB_MAX_ALLOWED_PACKET, + MARIADB_NET_BUFFER_LENGTH, + MARIADB_CONNECTION_SERVER_STATUS, + MARIADB_CONNECTION_SERVER_CAPABILITIES, + MARIADB_CONNECTION_EXTENDED_SERVER_CAPABILITIES, + MARIADB_CONNECTION_CLIENT_CAPABILITIES + }; + + enum mysql_status { MYSQL_STATUS_READY, + MYSQL_STATUS_GET_RESULT, + MYSQL_STATUS_USE_RESULT, + MYSQL_STATUS_QUERY_SENT, + MYSQL_STATUS_SENDING_LOAD_DATA, + MYSQL_STATUS_FETCHING_DATA, + MYSQL_STATUS_NEXT_RESULT_PENDING, + MYSQL_STATUS_QUIT_SENT, /* object is "destroyed" at this stage */ + MYSQL_STATUS_STMT_RESULT + }; + + enum mysql_protocol_type + { + MYSQL_PROTOCOL_DEFAULT, MYSQL_PROTOCOL_TCP, MYSQL_PROTOCOL_SOCKET, + MYSQL_PROTOCOL_PIPE, MYSQL_PROTOCOL_MEMORY + }; + +struct st_mysql_options { + unsigned int connect_timeout, read_timeout, write_timeout; + unsigned int port, protocol; + unsigned long client_flag; + char *host,*user,*password,*unix_socket,*db; + struct st_dynamic_array *init_command; + char *my_cnf_file,*my_cnf_group, *charset_dir, *charset_name; + char *ssl_key; /* PEM key file */ + char *ssl_cert; /* PEM cert file */ + char *ssl_ca; /* PEM CA file */ + char *ssl_capath; /* PEM directory of CA-s? */ + char *ssl_cipher; + char *shared_memory_base_name; + unsigned long max_allowed_packet; + my_bool use_ssl; /* if to use SSL or not */ + my_bool compress,named_pipe; + my_bool reconnect, unused_1, unused_2, unused_3; + enum mysql_option methods_to_use; + char *bind_address; + my_bool secure_auth; + my_bool report_data_truncation; + /* function pointers for local infile support */ + int (*local_infile_init)(void **, const char *, void *); + int (*local_infile_read)(void *, char *, unsigned int); + void (*local_infile_end)(void *); + int (*local_infile_error)(void *, char *, unsigned int); + void *local_infile_userdata; + struct st_mysql_options_extension *extension; +}; + + typedef struct st_mysql { + NET net; /* Communication parameters */ + void *unused_0; + char *host,*user,*passwd,*unix_socket,*server_version,*host_info; + char *info,*db; + const struct ma_charset_info_st *charset; /* character set */ + MYSQL_FIELD *fields; + MA_MEM_ROOT field_alloc; + unsigned long long affected_rows; + unsigned long long insert_id; /* id if insert on table with NEXTNR */ + unsigned long long extra_info; /* Used by mysqlshow */ + unsigned long thread_id; /* Id for connection in server */ + unsigned long packet_length; + unsigned int port; + unsigned long client_flag; + unsigned long server_capabilities; + unsigned int protocol_version; + unsigned int field_count; + unsigned int server_status; + unsigned int server_language; + unsigned int warning_count; /* warning count, added in 4.1 protocol */ + struct st_mysql_options options; + enum mysql_status status; + my_bool free_me; /* If free in mysql_close */ + my_bool unused_1; + char scramble_buff[20+ 1]; + /* madded after 3.23.58 */ + my_bool unused_2; + void *unused_3, *unused_4, *unused_5, *unused_6; + LIST *stmts; + const struct st_mariadb_methods *methods; + void *thd; + my_bool *unbuffered_fetch_owner; + char *info_buffer; + struct st_mariadb_extension *extension; +} MYSQL; + +typedef struct st_mysql_res { + unsigned long long row_count; + unsigned int field_count, current_field; + MYSQL_FIELD *fields; + MYSQL_DATA *data; + MYSQL_ROWS *data_cursor; + MA_MEM_ROOT field_alloc; + MYSQL_ROW row; /* If unbuffered read */ + MYSQL_ROW current_row; /* buffer to current row */ + unsigned long *lengths; /* column lengths of current row */ + MYSQL *handle; /* for unbuffered reads */ + my_bool eof; /* Used my mysql_fetch_row */ + my_bool is_ps; +} MYSQL_RES; + +typedef struct +{ + unsigned long *p_max_allowed_packet; + unsigned long *p_net_buffer_length; + void *extension; +} MYSQL_PARAMETERS; + + +enum mariadb_field_attr_t +{ + MARIADB_FIELD_ATTR_DATA_TYPE_NAME= 0, + MARIADB_FIELD_ATTR_FORMAT_NAME= 1 +}; + +#define MARIADB_FIELD_ATTR_LAST MARIADB_FIELD_ATTR_FORMAT_NAME + + +int STDCALL mariadb_field_attr(MARIADB_CONST_STRING *attr, + const MYSQL_FIELD *field, + enum mariadb_field_attr_t type); + +#ifndef _mysql_time_h_ +enum enum_mysql_timestamp_type +{ + MYSQL_TIMESTAMP_NONE= -2, MYSQL_TIMESTAMP_ERROR= -1, + MYSQL_TIMESTAMP_DATE= 0, MYSQL_TIMESTAMP_DATETIME= 1, MYSQL_TIMESTAMP_TIME= 2 +}; + +typedef struct st_mysql_time +{ + unsigned int year, month, day, hour, minute, second; + unsigned long second_part; + my_bool neg; + enum enum_mysql_timestamp_type time_type; +} MYSQL_TIME; +#define AUTO_SEC_PART_DIGITS 39 +#endif + +#define SEC_PART_DIGITS 6 +#define MARIADB_INVALID_SOCKET -1 + +/* Asynchronous API constants */ +#define MYSQL_WAIT_READ 1 +#define MYSQL_WAIT_WRITE 2 +#define MYSQL_WAIT_EXCEPT 4 +#define MYSQL_WAIT_TIMEOUT 8 + +typedef struct character_set +{ + unsigned int number; /* character set number */ + unsigned int state; /* character set state */ + const char *csname; /* character set name */ + const char *name; /* collation name */ + const char *comment; /* comment */ + const char *dir; /* character set directory */ + unsigned int mbminlen; /* min. length for multibyte strings */ + unsigned int mbmaxlen; /* max. length for multibyte strings */ +} MY_CHARSET_INFO; + +/* Local infile support functions */ +#define LOCAL_INFILE_ERROR_LEN 512 + +#include "mariadb_stmt.h" + +#ifndef MYSQL_CLIENT_PLUGIN_HEADER +#define MYSQL_CLIENT_PLUGIN_HEADER \ + int type; \ + unsigned int interface_version; \ + const char *name; \ + const char *author; \ + const char *desc; \ + unsigned int version[3]; \ + const char *license; \ + void *mysql_api; \ + int (*init)(char *, size_t, int, va_list); \ + int (*deinit)(void); \ + int (*options)(const char *option, const void *); +struct st_mysql_client_plugin +{ + MYSQL_CLIENT_PLUGIN_HEADER +}; + +struct st_mysql_client_plugin * +mysql_load_plugin(struct st_mysql *mysql, const char *name, int type, + int argc, ...); +struct st_mysql_client_plugin * STDCALL +mysql_load_plugin_v(struct st_mysql *mysql, const char *name, int type, + int argc, va_list args); +struct st_mysql_client_plugin * STDCALL +mysql_client_find_plugin(struct st_mysql *mysql, const char *name, int type); +struct st_mysql_client_plugin * STDCALL +mysql_client_register_plugin(struct st_mysql *mysql, + struct st_mysql_client_plugin *plugin); +#endif + + +void STDCALL mysql_set_local_infile_handler(MYSQL *mysql, + int (*local_infile_init)(void **, const char *, void *), + int (*local_infile_read)(void *, char *, unsigned int), + void (*local_infile_end)(void *), + int (*local_infile_error)(void *, char*, unsigned int), + void *); + +void mysql_set_local_infile_default(MYSQL *mysql); + +void my_set_error(MYSQL *mysql, unsigned int error_nr, + const char *sqlstate, const char *format, ...); +/* Functions to get information from the MYSQL and MYSQL_RES structures */ +/* Should definitely be used if one uses shared libraries */ + +my_ulonglong STDCALL mysql_num_rows(MYSQL_RES *res); +unsigned int STDCALL mysql_num_fields(MYSQL_RES *res); +my_bool STDCALL mysql_eof(MYSQL_RES *res); +MYSQL_FIELD *STDCALL mysql_fetch_field_direct(MYSQL_RES *res, + unsigned int fieldnr); +MYSQL_FIELD * STDCALL mysql_fetch_fields(MYSQL_RES *res); +MYSQL_ROWS * STDCALL mysql_row_tell(MYSQL_RES *res); +unsigned int STDCALL mysql_field_tell(MYSQL_RES *res); + +unsigned int STDCALL mysql_field_count(MYSQL *mysql); +my_bool STDCALL mysql_more_results(MYSQL *mysql); +int STDCALL mysql_next_result(MYSQL *mysql); +my_ulonglong STDCALL mysql_affected_rows(MYSQL *mysql); +my_bool STDCALL mysql_autocommit(MYSQL *mysql, my_bool mode); +my_bool STDCALL mysql_commit(MYSQL *mysql); +my_bool STDCALL mysql_rollback(MYSQL *mysql); +my_ulonglong STDCALL mysql_insert_id(MYSQL *mysql); +unsigned int STDCALL mysql_errno(MYSQL *mysql); +const char * STDCALL mysql_error(MYSQL *mysql); +const char * STDCALL mysql_info(MYSQL *mysql); +unsigned long STDCALL mysql_thread_id(MYSQL *mysql); +const char * STDCALL mysql_character_set_name(MYSQL *mysql); +void STDCALL mysql_get_character_set_info(MYSQL *mysql, MY_CHARSET_INFO *cs); +int STDCALL mysql_set_character_set(MYSQL *mysql, const char *csname); + +my_bool mariadb_get_infov(MYSQL *mysql, enum mariadb_value value, void *arg, ...); +my_bool STDCALL mariadb_get_info(MYSQL *mysql, enum mariadb_value value, void *arg); +MYSQL * STDCALL mysql_init(MYSQL *mysql); +int STDCALL mysql_ssl_set(MYSQL *mysql, const char *key, + const char *cert, const char *ca, + const char *capath, const char *cipher); +const char * STDCALL mysql_get_ssl_cipher(MYSQL *mysql); +my_bool STDCALL mysql_change_user(MYSQL *mysql, const char *user, + const char *passwd, const char *db); +MYSQL * STDCALL mysql_real_connect(MYSQL *mysql, const char *host, + const char *user, + const char *passwd, + const char *db, + unsigned int port, + const char *unix_socket, + unsigned long clientflag); +void STDCALL mysql_close(MYSQL *sock); +int STDCALL mysql_select_db(MYSQL *mysql, const char *db); +int STDCALL mysql_query(MYSQL *mysql, const char *q); +int STDCALL mysql_send_query(MYSQL *mysql, const char *q, + unsigned long length); +my_bool STDCALL mysql_read_query_result(MYSQL *mysql); +int STDCALL mysql_real_query(MYSQL *mysql, const char *q, + unsigned long length); +int STDCALL mysql_shutdown(MYSQL *mysql, enum mysql_enum_shutdown_level shutdown_level); +int STDCALL mysql_dump_debug_info(MYSQL *mysql); +int STDCALL mysql_refresh(MYSQL *mysql, + unsigned int refresh_options); +int STDCALL mysql_kill(MYSQL *mysql,unsigned long pid); +int STDCALL mysql_ping(MYSQL *mysql); +char * STDCALL mysql_stat(MYSQL *mysql); +char * STDCALL mysql_get_server_info(MYSQL *mysql); +unsigned long STDCALL mysql_get_server_version(MYSQL *mysql); +char * STDCALL mysql_get_host_info(MYSQL *mysql); +unsigned int STDCALL mysql_get_proto_info(MYSQL *mysql); +MYSQL_RES * STDCALL mysql_list_dbs(MYSQL *mysql,const char *wild); +MYSQL_RES * STDCALL mysql_list_tables(MYSQL *mysql,const char *wild); +MYSQL_RES * STDCALL mysql_list_fields(MYSQL *mysql, const char *table, + const char *wild); +MYSQL_RES * STDCALL mysql_list_processes(MYSQL *mysql); +MYSQL_RES * STDCALL mysql_store_result(MYSQL *mysql); +MYSQL_RES * STDCALL mysql_use_result(MYSQL *mysql); +int STDCALL mysql_options(MYSQL *mysql,enum mysql_option option, + const void *arg); +int STDCALL mysql_options4(MYSQL *mysql,enum mysql_option option, + const void *arg1, const void *arg2); +void STDCALL mysql_free_result(MYSQL_RES *result); +void STDCALL mysql_data_seek(MYSQL_RES *result, + unsigned long long offset); +MYSQL_ROW_OFFSET STDCALL mysql_row_seek(MYSQL_RES *result, MYSQL_ROW_OFFSET); +MYSQL_FIELD_OFFSET STDCALL mysql_field_seek(MYSQL_RES *result, + MYSQL_FIELD_OFFSET offset); +MYSQL_ROW STDCALL mysql_fetch_row(MYSQL_RES *result); +unsigned long * STDCALL mysql_fetch_lengths(MYSQL_RES *result); +MYSQL_FIELD * STDCALL mysql_fetch_field(MYSQL_RES *result); +unsigned long STDCALL mysql_escape_string(char *to,const char *from, + unsigned long from_length); +unsigned long STDCALL mysql_real_escape_string(MYSQL *mysql, + char *to,const char *from, + unsigned long length); +unsigned int STDCALL mysql_thread_safe(void); +unsigned int STDCALL mysql_warning_count(MYSQL *mysql); +const char * STDCALL mysql_sqlstate(MYSQL *mysql); +int STDCALL mysql_server_init(int argc, char **argv, char **groups); +void STDCALL mysql_server_end(void); +void STDCALL mysql_thread_end(void); +my_bool STDCALL mysql_thread_init(void); +int STDCALL mysql_set_server_option(MYSQL *mysql, + enum enum_mysql_set_option option); +const char * STDCALL mysql_get_client_info(void); +unsigned long STDCALL mysql_get_client_version(void); +my_bool STDCALL mariadb_connection(MYSQL *mysql); +const char * STDCALL mysql_get_server_name(MYSQL *mysql); +MARIADB_CHARSET_INFO * STDCALL mariadb_get_charset_by_name(const char *csname); +MARIADB_CHARSET_INFO * STDCALL mariadb_get_charset_by_nr(unsigned int csnr); +size_t STDCALL mariadb_convert_string(const char *from, size_t *from_len, MARIADB_CHARSET_INFO *from_cs, + char *to, size_t *to_len, MARIADB_CHARSET_INFO *to_cs, int *errorcode); +int mysql_optionsv(MYSQL *mysql,enum mysql_option option, ...); +int mysql_get_optionv(MYSQL *mysql, enum mysql_option option, void *arg, ...); +int STDCALL mysql_get_option(MYSQL *mysql, enum mysql_option option, void *arg); +unsigned long STDCALL mysql_hex_string(char *to, const char *from, unsigned long len); +my_socket STDCALL mysql_get_socket(MYSQL *mysql); +unsigned int STDCALL mysql_get_timeout_value(const MYSQL *mysql); +unsigned int STDCALL mysql_get_timeout_value_ms(const MYSQL *mysql); +my_bool STDCALL mariadb_reconnect(MYSQL *mysql); +int STDCALL mariadb_cancel(MYSQL *mysql); +void STDCALL mysql_debug(const char *debug); +unsigned long STDCALL mysql_net_read_packet(MYSQL *mysql); +unsigned long STDCALL mysql_net_field_length(unsigned char **packet); +my_bool STDCALL mysql_embedded(void); +MYSQL_PARAMETERS *STDCALL mysql_get_parameters(void); + +/* Async API */ +int STDCALL mysql_close_start(MYSQL *sock); +int STDCALL mysql_close_cont(MYSQL *sock, int status); +int STDCALL mysql_commit_start(my_bool *ret, MYSQL * mysql); +int STDCALL mysql_commit_cont(my_bool *ret, MYSQL * mysql, int status); +int STDCALL mysql_dump_debug_info_cont(int *ret, MYSQL *mysql, int ready_status); +int STDCALL mysql_dump_debug_info_start(int *ret, MYSQL *mysql); +int STDCALL mysql_rollback_start(my_bool *ret, MYSQL * mysql); +int STDCALL mysql_rollback_cont(my_bool *ret, MYSQL * mysql, int status); +int STDCALL mysql_autocommit_start(my_bool *ret, MYSQL * mysql, + my_bool auto_mode); +int STDCALL mysql_list_fields_cont(MYSQL_RES **ret, MYSQL *mysql, int ready_status); +int STDCALL mysql_list_fields_start(MYSQL_RES **ret, MYSQL *mysql, const char *table, + const char *wild); +int STDCALL mysql_autocommit_cont(my_bool *ret, MYSQL * mysql, int status); +int STDCALL mysql_next_result_start(int *ret, MYSQL *mysql); +int STDCALL mysql_next_result_cont(int *ret, MYSQL *mysql, int status); +int STDCALL mysql_select_db_start(int *ret, MYSQL *mysql, const char *db); +int STDCALL mysql_select_db_cont(int *ret, MYSQL *mysql, int ready_status); +int STDCALL mysql_stmt_warning_count(MYSQL_STMT *stmt); +int STDCALL mysql_stmt_next_result_start(int *ret, MYSQL_STMT *stmt); +int STDCALL mysql_stmt_next_result_cont(int *ret, MYSQL_STMT *stmt, int status); + +int STDCALL mysql_set_character_set_start(int *ret, MYSQL *mysql, + const char *csname); +int STDCALL mysql_set_character_set_cont(int *ret, MYSQL *mysql, + int status); +int STDCALL mysql_change_user_start(my_bool *ret, MYSQL *mysql, + const char *user, + const char *passwd, + const char *db); +int STDCALL mysql_change_user_cont(my_bool *ret, MYSQL *mysql, + int status); +int STDCALL mysql_real_connect_start(MYSQL **ret, MYSQL *mysql, + const char *host, + const char *user, + const char *passwd, + const char *db, + unsigned int port, + const char *unix_socket, + unsigned long clientflag); +int STDCALL mysql_real_connect_cont(MYSQL **ret, MYSQL *mysql, + int status); +int STDCALL mysql_query_start(int *ret, MYSQL *mysql, + const char *q); +int STDCALL mysql_query_cont(int *ret, MYSQL *mysql, + int status); +int STDCALL mysql_send_query_start(int *ret, MYSQL *mysql, + const char *q, + unsigned long length); +int STDCALL mysql_send_query_cont(int *ret, MYSQL *mysql, int status); +int STDCALL mysql_real_query_start(int *ret, MYSQL *mysql, + const char *q, + unsigned long length); +int STDCALL mysql_real_query_cont(int *ret, MYSQL *mysql, + int status); +int STDCALL mysql_store_result_start(MYSQL_RES **ret, MYSQL *mysql); +int STDCALL mysql_store_result_cont(MYSQL_RES **ret, MYSQL *mysql, + int status); +int STDCALL mysql_shutdown_start(int *ret, MYSQL *mysql, + enum mysql_enum_shutdown_level + shutdown_level); +int STDCALL mysql_shutdown_cont(int *ret, MYSQL *mysql, + int status); +int STDCALL mysql_refresh_start(int *ret, MYSQL *mysql, + unsigned int refresh_options); +int STDCALL mysql_refresh_cont(int *ret, MYSQL *mysql, int status); +int STDCALL mysql_kill_start(int *ret, MYSQL *mysql, + unsigned long pid); +int STDCALL mysql_kill_cont(int *ret, MYSQL *mysql, int status); +int STDCALL mysql_set_server_option_start(int *ret, MYSQL *mysql, + enum enum_mysql_set_option + option); +int STDCALL mysql_set_server_option_cont(int *ret, MYSQL *mysql, + int status); +int STDCALL mysql_ping_start(int *ret, MYSQL *mysql); +int STDCALL mysql_ping_cont(int *ret, MYSQL *mysql, int status); +int STDCALL mysql_stat_start(const char **ret, MYSQL *mysql); +int STDCALL mysql_stat_cont(const char **ret, MYSQL *mysql, + int status); +int STDCALL mysql_free_result_start(MYSQL_RES *result); +int STDCALL mysql_free_result_cont(MYSQL_RES *result, int status); +int STDCALL mysql_fetch_row_start(MYSQL_ROW *ret, + MYSQL_RES *result); +int STDCALL mysql_fetch_row_cont(MYSQL_ROW *ret, MYSQL_RES *result, + int status); +int STDCALL mysql_read_query_result_start(my_bool *ret, + MYSQL *mysql); +int STDCALL mysql_read_query_result_cont(my_bool *ret, + MYSQL *mysql, int status); +int STDCALL mysql_reset_connection_start(int *ret, MYSQL *mysql); +int STDCALL mysql_reset_connection_cont(int *ret, MYSQL *mysql, int status); +int STDCALL mysql_session_track_get_next(MYSQL *mysql, enum enum_session_state_type type, const char **data, size_t *length); +int STDCALL mysql_session_track_get_first(MYSQL *mysql, enum enum_session_state_type type, const char **data, size_t *length); +int STDCALL mysql_stmt_prepare_start(int *ret, MYSQL_STMT *stmt,const char *query, unsigned long length); +int STDCALL mysql_stmt_prepare_cont(int *ret, MYSQL_STMT *stmt, int status); +int STDCALL mysql_stmt_execute_start(int *ret, MYSQL_STMT *stmt); +int STDCALL mysql_stmt_execute_cont(int *ret, MYSQL_STMT *stmt, int status); +int STDCALL mysql_stmt_fetch_start(int *ret, MYSQL_STMT *stmt); +int STDCALL mysql_stmt_fetch_cont(int *ret, MYSQL_STMT *stmt, int status); +int STDCALL mysql_stmt_store_result_start(int *ret, MYSQL_STMT *stmt); +int STDCALL mysql_stmt_store_result_cont(int *ret, MYSQL_STMT *stmt,int status); +int STDCALL mysql_stmt_close_start(my_bool *ret, MYSQL_STMT *stmt); +int STDCALL mysql_stmt_close_cont(my_bool *ret, MYSQL_STMT * stmt, int status); +int STDCALL mysql_stmt_reset_start(my_bool *ret, MYSQL_STMT * stmt); +int STDCALL mysql_stmt_reset_cont(my_bool *ret, MYSQL_STMT *stmt, int status); +int STDCALL mysql_stmt_free_result_start(my_bool *ret, MYSQL_STMT *stmt); +int STDCALL mysql_stmt_free_result_cont(my_bool *ret, MYSQL_STMT *stmt, + int status); +int STDCALL mysql_stmt_send_long_data_start(my_bool *ret, MYSQL_STMT *stmt, + unsigned int param_number, + const char *data, + unsigned long len); +int STDCALL mysql_stmt_send_long_data_cont(my_bool *ret, MYSQL_STMT *stmt, + int status); +int STDCALL mysql_reset_connection(MYSQL *mysql); + +/* API function calls (used by dynamic plugins) */ +struct st_mariadb_api { + unsigned long long (STDCALL *mysql_num_rows)(MYSQL_RES *res); + unsigned int (STDCALL *mysql_num_fields)(MYSQL_RES *res); + my_bool (STDCALL *mysql_eof)(MYSQL_RES *res); + MYSQL_FIELD *(STDCALL *mysql_fetch_field_direct)(MYSQL_RES *res, unsigned int fieldnr); + MYSQL_FIELD * (STDCALL *mysql_fetch_fields)(MYSQL_RES *res); + MYSQL_ROWS * (STDCALL *mysql_row_tell)(MYSQL_RES *res); + unsigned int (STDCALL *mysql_field_tell)(MYSQL_RES *res); + unsigned int (STDCALL *mysql_field_count)(MYSQL *mysql); + my_bool (STDCALL *mysql_more_results)(MYSQL *mysql); + int (STDCALL *mysql_next_result)(MYSQL *mysql); + unsigned long long (STDCALL *mysql_affected_rows)(MYSQL *mysql); + my_bool (STDCALL *mysql_autocommit)(MYSQL *mysql, my_bool mode); + my_bool (STDCALL *mysql_commit)(MYSQL *mysql); + my_bool (STDCALL *mysql_rollback)(MYSQL *mysql); + unsigned long long (STDCALL *mysql_insert_id)(MYSQL *mysql); + unsigned int (STDCALL *mysql_errno)(MYSQL *mysql); + const char * (STDCALL *mysql_error)(MYSQL *mysql); + const char * (STDCALL *mysql_info)(MYSQL *mysql); + unsigned long (STDCALL *mysql_thread_id)(MYSQL *mysql); + const char * (STDCALL *mysql_character_set_name)(MYSQL *mysql); + void (STDCALL *mysql_get_character_set_info)(MYSQL *mysql, MY_CHARSET_INFO *cs); + int (STDCALL *mysql_set_character_set)(MYSQL *mysql, const char *csname); + my_bool (*mariadb_get_infov)(MYSQL *mysql, enum mariadb_value value, void *arg, ...); + my_bool (STDCALL *mariadb_get_info)(MYSQL *mysql, enum mariadb_value value, void *arg); + MYSQL * (STDCALL *mysql_init)(MYSQL *mysql); + int (STDCALL *mysql_ssl_set)(MYSQL *mysql, const char *key, const char *cert, const char *ca, const char *capath, const char *cipher); + const char * (STDCALL *mysql_get_ssl_cipher)(MYSQL *mysql); + my_bool (STDCALL *mysql_change_user)(MYSQL *mysql, const char *user, const char *passwd, const char *db); + MYSQL * (STDCALL *mysql_real_connect)(MYSQL *mysql, const char *host, const char *user, const char *passwd, const char *db, unsigned int port, const char *unix_socket, unsigned long clientflag); + void (STDCALL *mysql_close)(MYSQL *sock); + int (STDCALL *mysql_select_db)(MYSQL *mysql, const char *db); + int (STDCALL *mysql_query)(MYSQL *mysql, const char *q); + int (STDCALL *mysql_send_query)(MYSQL *mysql, const char *q, unsigned long length); + my_bool (STDCALL *mysql_read_query_result)(MYSQL *mysql); + int (STDCALL *mysql_real_query)(MYSQL *mysql, const char *q, unsigned long length); + int (STDCALL *mysql_shutdown)(MYSQL *mysql, enum mysql_enum_shutdown_level shutdown_level); + int (STDCALL *mysql_dump_debug_info)(MYSQL *mysql); + int (STDCALL *mysql_refresh)(MYSQL *mysql, unsigned int refresh_options); + int (STDCALL *mysql_kill)(MYSQL *mysql,unsigned long pid); + int (STDCALL *mysql_ping)(MYSQL *mysql); + char * (STDCALL *mysql_stat)(MYSQL *mysql); + char * (STDCALL *mysql_get_server_info)(MYSQL *mysql); + unsigned long (STDCALL *mysql_get_server_version)(MYSQL *mysql); + char * (STDCALL *mysql_get_host_info)(MYSQL *mysql); + unsigned int (STDCALL *mysql_get_proto_info)(MYSQL *mysql); + MYSQL_RES * (STDCALL *mysql_list_dbs)(MYSQL *mysql,const char *wild); + MYSQL_RES * (STDCALL *mysql_list_tables)(MYSQL *mysql,const char *wild); + MYSQL_RES * (STDCALL *mysql_list_fields)(MYSQL *mysql, const char *table, const char *wild); + MYSQL_RES * (STDCALL *mysql_list_processes)(MYSQL *mysql); + MYSQL_RES * (STDCALL *mysql_store_result)(MYSQL *mysql); + MYSQL_RES * (STDCALL *mysql_use_result)(MYSQL *mysql); + int (STDCALL *mysql_options)(MYSQL *mysql,enum mysql_option option, const void *arg); + void (STDCALL *mysql_free_result)(MYSQL_RES *result); + void (STDCALL *mysql_data_seek)(MYSQL_RES *result, unsigned long long offset); + MYSQL_ROW_OFFSET (STDCALL *mysql_row_seek)(MYSQL_RES *result, MYSQL_ROW_OFFSET); + MYSQL_FIELD_OFFSET (STDCALL *mysql_field_seek)(MYSQL_RES *result, MYSQL_FIELD_OFFSET offset); + MYSQL_ROW (STDCALL *mysql_fetch_row)(MYSQL_RES *result); + unsigned long * (STDCALL *mysql_fetch_lengths)(MYSQL_RES *result); + MYSQL_FIELD * (STDCALL *mysql_fetch_field)(MYSQL_RES *result); + unsigned long (STDCALL *mysql_escape_string)(char *to,const char *from, unsigned long from_length); + unsigned long (STDCALL *mysql_real_escape_string)(MYSQL *mysql, char *to,const char *from, unsigned long length); + unsigned int (STDCALL *mysql_thread_safe)(void); + unsigned int (STDCALL *mysql_warning_count)(MYSQL *mysql); + const char * (STDCALL *mysql_sqlstate)(MYSQL *mysql); + int (STDCALL *mysql_server_init)(int argc, char **argv, char **groups); + void (STDCALL *mysql_server_end)(void); + void (STDCALL *mysql_thread_end)(void); + my_bool (STDCALL *mysql_thread_init)(void); + int (STDCALL *mysql_set_server_option)(MYSQL *mysql, enum enum_mysql_set_option option); + const char * (STDCALL *mysql_get_client_info)(void); + unsigned long (STDCALL *mysql_get_client_version)(void); + my_bool (STDCALL *mariadb_connection)(MYSQL *mysql); + const char * (STDCALL *mysql_get_server_name)(MYSQL *mysql); + MARIADB_CHARSET_INFO * (STDCALL *mariadb_get_charset_by_name)(const char *csname); + MARIADB_CHARSET_INFO * (STDCALL *mariadb_get_charset_by_nr)(unsigned int csnr); + size_t (STDCALL *mariadb_convert_string)(const char *from, size_t *from_len, MARIADB_CHARSET_INFO *from_cs, char *to, size_t *to_len, MARIADB_CHARSET_INFO *to_cs, int *errorcode); + int (*mysql_optionsv)(MYSQL *mysql,enum mysql_option option, ...); + int (*mysql_get_optionv)(MYSQL *mysql, enum mysql_option option, void *arg, ...); + int (STDCALL *mysql_get_option)(MYSQL *mysql, enum mysql_option option, void *arg); + unsigned long (STDCALL *mysql_hex_string)(char *to, const char *from, unsigned long len); + my_socket (STDCALL *mysql_get_socket)(MYSQL *mysql); + unsigned int (STDCALL *mysql_get_timeout_value)(const MYSQL *mysql); + unsigned int (STDCALL *mysql_get_timeout_value_ms)(const MYSQL *mysql); + my_bool (STDCALL *mariadb_reconnect)(MYSQL *mysql); + MYSQL_STMT * (STDCALL *mysql_stmt_init)(MYSQL *mysql); + int (STDCALL *mysql_stmt_prepare)(MYSQL_STMT *stmt, const char *query, unsigned long length); + int (STDCALL *mysql_stmt_execute)(MYSQL_STMT *stmt); + int (STDCALL *mysql_stmt_fetch)(MYSQL_STMT *stmt); + int (STDCALL *mysql_stmt_fetch_column)(MYSQL_STMT *stmt, MYSQL_BIND *bind_arg, unsigned int column, unsigned long offset); + int (STDCALL *mysql_stmt_store_result)(MYSQL_STMT *stmt); + unsigned long (STDCALL *mysql_stmt_param_count)(MYSQL_STMT * stmt); + my_bool (STDCALL *mysql_stmt_attr_set)(MYSQL_STMT *stmt, enum enum_stmt_attr_type attr_type, const void *attr); + my_bool (STDCALL *mysql_stmt_attr_get)(MYSQL_STMT *stmt, enum enum_stmt_attr_type attr_type, void *attr); + my_bool (STDCALL *mysql_stmt_bind_param)(MYSQL_STMT * stmt, MYSQL_BIND * bnd); + my_bool (STDCALL *mysql_stmt_bind_result)(MYSQL_STMT * stmt, MYSQL_BIND * bnd); + my_bool (STDCALL *mysql_stmt_close)(MYSQL_STMT * stmt); + my_bool (STDCALL *mysql_stmt_reset)(MYSQL_STMT * stmt); + my_bool (STDCALL *mysql_stmt_free_result)(MYSQL_STMT *stmt); + my_bool (STDCALL *mysql_stmt_send_long_data)(MYSQL_STMT *stmt, unsigned int param_number, const char *data, unsigned long length); + MYSQL_RES *(STDCALL *mysql_stmt_result_metadata)(MYSQL_STMT *stmt); + MYSQL_RES *(STDCALL *mysql_stmt_param_metadata)(MYSQL_STMT *stmt); + unsigned int (STDCALL *mysql_stmt_errno)(MYSQL_STMT * stmt); + const char *(STDCALL *mysql_stmt_error)(MYSQL_STMT * stmt); + const char *(STDCALL *mysql_stmt_sqlstate)(MYSQL_STMT * stmt); + MYSQL_ROW_OFFSET (STDCALL *mysql_stmt_row_seek)(MYSQL_STMT *stmt, MYSQL_ROW_OFFSET offset); + MYSQL_ROW_OFFSET (STDCALL *mysql_stmt_row_tell)(MYSQL_STMT *stmt); + void (STDCALL *mysql_stmt_data_seek)(MYSQL_STMT *stmt, unsigned long long offset); + unsigned long long (STDCALL *mysql_stmt_num_rows)(MYSQL_STMT *stmt); + unsigned long long (STDCALL *mysql_stmt_affected_rows)(MYSQL_STMT *stmt); + unsigned long long (STDCALL *mysql_stmt_insert_id)(MYSQL_STMT *stmt); + unsigned int (STDCALL *mysql_stmt_field_count)(MYSQL_STMT *stmt); + int (STDCALL *mysql_stmt_next_result)(MYSQL_STMT *stmt); + my_bool (STDCALL *mysql_stmt_more_results)(MYSQL_STMT *stmt); + int (STDCALL *mariadb_stmt_execute_direct)(MYSQL_STMT *stmt, const char *stmtstr, size_t length); + int (STDCALL *mysql_reset_connection)(MYSQL *mysql); +}; + +/* these methods can be overwritten by db plugins */ +struct st_mariadb_methods { + MYSQL *(*db_connect)(MYSQL *mysql, const char *host, const char *user, const char *passwd, + const char *db, unsigned int port, const char *unix_socket, unsigned long clientflag); + void (*db_close)(MYSQL *mysql); + int (*db_command)(MYSQL *mysql,enum enum_server_command command, const char *arg, + size_t length, my_bool skipp_check, void *opt_arg); + void (*db_skip_result)(MYSQL *mysql); + int (*db_read_query_result)(MYSQL *mysql); + MYSQL_DATA *(*db_read_rows)(MYSQL *mysql,MYSQL_FIELD *fields, unsigned int field_count); + int (*db_read_one_row)(MYSQL *mysql,unsigned int fields,MYSQL_ROW row, unsigned long *lengths); + /* prepared statements */ + my_bool (*db_supported_buffer_type)(enum enum_field_types type); + my_bool (*db_read_prepare_response)(MYSQL_STMT *stmt); + int (*db_read_stmt_result)(MYSQL *mysql); + my_bool (*db_stmt_get_result_metadata)(MYSQL_STMT *stmt); + my_bool (*db_stmt_get_param_metadata)(MYSQL_STMT *stmt); + int (*db_stmt_read_all_rows)(MYSQL_STMT *stmt); + int (*db_stmt_fetch)(MYSQL_STMT *stmt, unsigned char **row); + int (*db_stmt_fetch_to_bind)(MYSQL_STMT *stmt, unsigned char *row); + void (*db_stmt_flush_unbuffered)(MYSQL_STMT *stmt); + void (*set_error)(MYSQL *mysql, unsigned int error_nr, const char *sqlstate, const char *format, ...); + void (*invalidate_stmts)(MYSQL *mysql, const char *function_name); + struct st_mariadb_api *api; + int (*db_read_execute_response)(MYSQL_STMT *stmt); +}; + +/* synonyms/aliases functions */ +#define mysql_reload(mysql) mysql_refresh((mysql),REFRESH_GRANT) +#define mysql_library_init mysql_server_init +#define mysql_library_end mysql_server_end + +/* new api functions */ + +#define HAVE_MYSQL_REAL_CONNECT + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/vendor/MDBC/include/mysql/client_plugin.h b/vendor/MDBC/include/mysql/client_plugin.h new file mode 100644 index 00000000..72939d24 --- /dev/null +++ b/vendor/MDBC/include/mysql/client_plugin.h @@ -0,0 +1,244 @@ +/* Copyright (C) 2010 - 2012 Sergei Golubchik and Monty Program Ab + 2014 MariaDB Corporation AB + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not see + or write to the Free Software Foundation, Inc., + 51 Franklin St., Fifth Floor, Boston, MA 02110, USA */ + +/** + @file + + MySQL Client Plugin API + + This file defines the API for plugins that work on the client side +*/ +#ifndef MYSQL_CLIENT_PLUGIN_INCLUDED +#define MYSQL_CLIENT_PLUGIN_INCLUDED + +#ifndef MYSQL_ABI_CHECK +#include +#include +#endif + + +#ifndef PLUGINDIR +#define PLUGINDIR "lib/plugin" +#endif + +#define plugin_declarations_sym "_mysql_client_plugin_declaration_" + +/* known plugin types */ +#define MYSQL_CLIENT_PLUGIN_RESERVED 0 +#define MYSQL_CLIENT_PLUGIN_RESERVED2 1 +#define MYSQL_CLIENT_AUTHENTICATION_PLUGIN 2 /* authentication */ + +#define MYSQL_CLIENT_AUTHENTICATION_PLUGIN_INTERFACE_VERSION 0x0100 +#define MYSQL_CLIENT_MAX_PLUGINS 3 + +/* Connector/C specific plugin types */ +#define MARIADB_CLIENT_REMOTEIO_PLUGIN 100 /* communication IO */ +#define MARIADB_CLIENT_PVIO_PLUGIN 101 +#define MARIADB_CLIENT_TRACE_PLUGIN 102 +#define MARIADB_CLIENT_CONNECTION_PLUGIN 103 + +#define MARIADB_CLIENT_REMOTEIO_PLUGIN_INTERFACE_VERSION 0x0100 +#define MARIADB_CLIENT_PVIO_PLUGIN_INTERFACE_VERSION 0x0100 +#define MARIADB_CLIENT_TRACE_PLUGIN_INTERFACE_VERSION 0x0100 +#define MARIADB_CLIENT_CONNECTION_PLUGIN_INTERFACE_VERSION 0x0100 + +#define MARIADB_CLIENT_MAX_PLUGINS 4 + +#define mysql_declare_client_plugin(X) \ + struct st_mysql_client_plugin_ ## X \ + _mysql_client_plugin_declaration_ = { \ + MYSQL_CLIENT_ ## X ## _PLUGIN, \ + MYSQL_CLIENT_ ## X ## _PLUGIN_INTERFACE_VERSION, +#define mysql_end_client_plugin } + +/* generic plugin header structure */ +#ifndef MYSQL_CLIENT_PLUGIN_HEADER +#define MYSQL_CLIENT_PLUGIN_HEADER \ + int type; \ + unsigned int interface_version; \ + const char *name; \ + const char *author; \ + const char *desc; \ + unsigned int version[3]; \ + const char *license; \ + void *mysql_api; \ + int (*init)(char *, size_t, int, va_list); \ + int (*deinit)(void); \ + int (*options)(const char *option, const void *); +struct st_mysql_client_plugin +{ + MYSQL_CLIENT_PLUGIN_HEADER +}; +#endif + +struct st_mysql; + +/********* connection handler plugin specific declarations **********/ + +typedef struct st_ma_connection_plugin +{ + MYSQL_CLIENT_PLUGIN_HEADER + /* functions */ + MYSQL *(*connect)(MYSQL *mysql, const char *host, + const char *user, const char *passwd, + const char *db, unsigned int port, + const char *unix_socket, unsigned long clientflag); + void (*close)(MYSQL *mysql); + int (*set_optionsv)(MYSQL *mysql, unsigned int option, ...); + int (*set_connection)(MYSQL *mysql,enum enum_server_command command, + const char *arg, + size_t length, my_bool skipp_check, void *opt_arg); + my_bool (*reconnect)(MYSQL *mysql); + int (*reset)(MYSQL *mysql); +} MARIADB_CONNECTION_PLUGIN; + +#define MARIADB_DB_DRIVER(a) ((a)->ext_db) + +/******************* Communication IO plugin *****************/ +#include + +typedef struct st_mariadb_client_plugin_PVIO +{ + MYSQL_CLIENT_PLUGIN_HEADER + struct st_ma_pvio_methods *methods; +} MARIADB_PVIO_PLUGIN; + +/******** authentication plugin specific declarations *********/ +#include + +struct st_mysql_client_plugin_AUTHENTICATION +{ + MYSQL_CLIENT_PLUGIN_HEADER + int (*authenticate_user)(MYSQL_PLUGIN_VIO *vio, struct st_mysql *mysql); +}; + +/******** trace plugin *******/ +struct st_mysql_client_plugin_TRACE +{ + MYSQL_CLIENT_PLUGIN_HEADER +}; + +/** + type of the mysql_authentication_dialog_ask function + + @param mysql mysql + @param type type of the input + 1 - ordinary string input + 2 - password string + @param prompt prompt + @param buf a buffer to store the use input + @param buf_len the length of the buffer + + @retval a pointer to the user input string. + It may be equal to 'buf' or to 'mysql->password'. + In all other cases it is assumed to be an allocated + string, and the "dialog" plugin will free() it. +*/ +typedef char *(*mysql_authentication_dialog_ask_t)(struct st_mysql *mysql, + int type, const char *prompt, char *buf, int buf_len); + +/********************** remote IO plugin **********************/ +#ifdef HAVE_REMOTEIO +#include + +/* Remote IO plugin */ +typedef struct st_mysql_client_plugin_REMOTEIO +{ + MYSQL_CLIENT_PLUGIN_HEADER + struct st_rio_methods *methods; +} MARIADB_REMOTEIO_PLUGIN; +#endif + +/******** using plugins ************/ + +/** + loads a plugin and initializes it + + @param mysql MYSQL structure. only MYSQL_PLUGIN_DIR option value is used, + and last_errno/last_error, for error reporting + @param name a name of the plugin to load + @param type type of plugin that should be loaded, -1 to disable type check + @param argc number of arguments to pass to the plugin initialization + function + @param ... arguments for the plugin initialization function + + @retval + a pointer to the loaded plugin, or NULL in case of a failure +*/ +struct st_mysql_client_plugin * +mysql_load_plugin(struct st_mysql *mysql, const char *name, int type, + int argc, ...); + +/** + loads a plugin and initializes it, taking va_list as an argument + + This is the same as mysql_load_plugin, but take va_list instead of + a list of arguments. + + @param mysql MYSQL structure. only MYSQL_PLUGIN_DIR option value is used, + and last_errno/last_error, for error reporting + @param name a name of the plugin to load + @param type type of plugin that should be loaded, -1 to disable type check + @param argc number of arguments to pass to the plugin initialization + function + @param args arguments for the plugin initialization function + + @retval + a pointer to the loaded plugin, or NULL in case of a failure +*/ +struct st_mysql_client_plugin * STDCALL +mysql_load_plugin_v(struct st_mysql *mysql, const char *name, int type, + int argc, va_list args); + +/** + finds an already loaded plugin by name, or loads it, if necessary + + @param mysql MYSQL structure. only MYSQL_PLUGIN_DIR option value is used, + and last_errno/last_error, for error reporting + @param name a name of the plugin to load + @param type type of plugin that should be loaded + + @retval + a pointer to the plugin, or NULL in case of a failure +*/ +struct st_mysql_client_plugin * STDCALL +mysql_client_find_plugin(struct st_mysql *mysql, const char *name, int type); + +/** + adds a plugin structure to the list of loaded plugins + + This is useful if an application has the necessary functionality + (for example, a special load data handler) statically linked into + the application binary. It can use this function to register the plugin + directly, avoiding the need to factor it out into a shared object. + + @param mysql MYSQL structure. It is only used for error reporting + @param plugin an st_mysql_client_plugin structure to register + + @retval + a pointer to the plugin, or NULL in case of a failure +*/ +struct st_mysql_client_plugin * STDCALL +mysql_client_register_plugin(struct st_mysql *mysql, + struct st_mysql_client_plugin *plugin); + +extern struct st_mysql_client_plugin *mysql_client_builtins[]; + +#endif + + diff --git a/vendor/MDBC/include/mysql/plugin_auth.h b/vendor/MDBC/include/mysql/plugin_auth.h new file mode 100644 index 00000000..2be64a6b --- /dev/null +++ b/vendor/MDBC/include/mysql/plugin_auth.h @@ -0,0 +1,107 @@ +#ifndef MYSQL_PLUGIN_AUTH_COMMON_INCLUDED +/* Copyright (C) 2010 Sergei Golubchik and Monty Program Ab + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + MA 02111-1301, USA */ + +/** + @file + + This file defines constants and data structures that are the same for + both client- and server-side authentication plugins. +*/ +#define MYSQL_PLUGIN_AUTH_COMMON_INCLUDED + +/** the max allowed length for a user name */ +#define MYSQL_USERNAME_LENGTH 512 + +/** + return values of the plugin authenticate_user() method. +*/ + +/** + Authentication failed. Additionally, all other CR_xxx values + (libmariadb error code) can be used too. + + The client plugin may set the error code and the error message directly + in the MYSQL structure and return CR_ERROR. If a CR_xxx specific error + code was returned, an error message in the MYSQL structure will be + overwritten. If CR_ERROR is returned without setting the error in MYSQL, + CR_UNKNOWN_ERROR will be user. +*/ +#define CR_ERROR 0 +/** + Authentication (client part) was successful. It does not mean that the + authentication as a whole was successful, usually it only means + that the client was able to send the user name and the password to the + server. If CR_OK is returned, the libmariadb reads the next packet expecting + it to be one of OK, ERROR, or CHANGE_PLUGIN packets. +*/ +#define CR_OK -1 +/** + Authentication was successful. + It means that the client has done its part successfully and also that + a plugin has read the last packet (one of OK, ERROR, CHANGE_PLUGIN). + In this case, libmariadb will not read a packet from the server, + but it will use the data at mysql->net.read_pos. + + A plugin may return this value if the number of roundtrips in the + authentication protocol is not known in advance, and the client plugin + needs to read one packet more to determine if the authentication is finished + or not. +*/ +#define CR_OK_HANDSHAKE_COMPLETE -2 + +typedef struct st_plugin_vio_info +{ + enum { MYSQL_VIO_INVALID, MYSQL_VIO_TCP, MYSQL_VIO_SOCKET, + MYSQL_VIO_PIPE, MYSQL_VIO_MEMORY } protocol; + int socket; /**< it's set, if the protocol is SOCKET or TCP */ +#ifdef _WIN32 + HANDLE handle; /**< it's set, if the protocol is PIPE or MEMORY */ +#endif +} MYSQL_PLUGIN_VIO_INFO; + +/** + Provides plugin access to communication channel +*/ +typedef struct st_plugin_vio +{ + /** + Plugin provides a pointer reference and this function sets it to the + contents of any incoming packet. Returns the packet length, or -1 if + the plugin should terminate. + */ + int (*read_packet)(struct st_plugin_vio *vio, + unsigned char **buf); + + /** + Plugin provides a buffer with data and the length and this + function sends it as a packet. Returns 0 on success, 1 on failure. + */ + int (*write_packet)(struct st_plugin_vio *vio, + const unsigned char *packet, + int packet_len); + + /** + Fills in a st_plugin_vio_info structure, providing the information + about the connection. + */ + void (*info)(struct st_plugin_vio *vio, struct st_plugin_vio_info *info); + +} MYSQL_PLUGIN_VIO; + +#endif + diff --git a/vendor/MDBC/include/mysql/plugin_auth_common.h b/vendor/MDBC/include/mysql/plugin_auth_common.h new file mode 100644 index 00000000..ee4b8b9c --- /dev/null +++ b/vendor/MDBC/include/mysql/plugin_auth_common.h @@ -0,0 +1,110 @@ +/* Copyright (C) 2010 Sergei Golubchik and Monty Program Ab + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + MA 02111-1301, USA */ + + +#ifndef MYSQL_PLUGIN_AUTH_COMMON_INCLUDED +/** + @file + + This file defines constants and data structures that are the same for + both client- and server-side authentication plugins. +*/ +#define MYSQL_PLUGIN_AUTH_COMMON_INCLUDED + +/** the max allowed length for a user name */ +#define MYSQL_USERNAME_LENGTH 512 + +/** + return values of the plugin authenticate_user() method. +*/ + +/** + Authentication failed. Additionally, all other CR_xxx values + (libmariadb error code) can be used too. + + The client plugin may set the error code and the error message directly + in the MYSQL structure and return CR_ERROR. If a CR_xxx specific error + code was returned, an error message in the MYSQL structure will be + overwritten. If CR_ERROR is returned without setting the error in MYSQL, + CR_UNKNOWN_ERROR will be user. +*/ +#define CR_ERROR 0 +/** + Authentication (client part) was successful. It does not mean that the + authentication as a whole was successful, usually it only means + that the client was able to send the user name and the password to the + server. If CR_OK is returned, the libmariadb reads the next packet expecting + it to be one of OK, ERROR, or CHANGE_PLUGIN packets. +*/ +#define CR_OK -1 +/** + Authentication was successful. + It means that the client has done its part successfully and also that + a plugin has read the last packet (one of OK, ERROR, CHANGE_PLUGIN). + In this case, libmariadb will not read a packet from the server, + but it will use the data at mysql->net.read_pos. + + A plugin may return this value if the number of roundtrips in the + authentication protocol is not known in advance, and the client plugin + needs to read one packet more to determine if the authentication is finished + or not. +*/ +#define CR_OK_HANDSHAKE_COMPLETE -2 + +typedef struct st_plugin_vio_info +{ + enum { MYSQL_VIO_INVALID, MYSQL_VIO_TCP, MYSQL_VIO_SOCKET, + MYSQL_VIO_PIPE, MYSQL_VIO_MEMORY } protocol; +#ifndef _WIN32 + int socket; /**< it's set, if the protocol is SOCKET or TCP */ +#else + SOCKET socket; /**< it's set, if the protocol is SOCKET or TCP */ + HANDLE handle; /**< it's set, if the protocol is PIPE or MEMORY */ +#endif +} MYSQL_PLUGIN_VIO_INFO; + +/** + Provides plugin access to communication channel +*/ +typedef struct st_plugin_vio +{ + /** + Plugin provides a pointer reference and this function sets it to the + contents of any incoming packet. Returns the packet length, or -1 if + the plugin should terminate. + */ + int (*read_packet)(struct st_plugin_vio *vio, + unsigned char **buf); + + /** + Plugin provides a buffer with data and the length and this + function sends it as a packet. Returns 0 on success, 1 on failure. + */ + int (*write_packet)(struct st_plugin_vio *vio, + const unsigned char *packet, + int packet_len); + + /** + Fills in a st_plugin_vio_info structure, providing the information + about the connection. + */ + void (*info)(struct st_plugin_vio *vio, struct st_plugin_vio_info *info); + +} MYSQL_PLUGIN_VIO; + +#endif + diff --git a/vendor/MDBC/include/mysqld_error.h b/vendor/MDBC/include/mysqld_error.h new file mode 100644 index 00000000..04ec2da3 --- /dev/null +++ b/vendor/MDBC/include/mysqld_error.h @@ -0,0 +1,1225 @@ +/* Autogenerated file, please don't edit */ + +#ifndef ER_ERROR_FIRST +#define ER_ERROR_FIRST 1000 +#define ER_HASHCHK 1000 +#define ER_NISAMCHK 1001 +#define ER_NO 1002 +#define ER_YES 1003 +#define ER_CANT_CREATE_FILE 1004 +#define ER_CANT_CREATE_TABLE 1005 +#define ER_CANT_CREATE_DB 1006 +#define ER_DB_CREATE_EXISTS 1007 +#define ER_DB_DROP_EXISTS 1008 +#define ER_DB_DROP_DELETE 1009 +#define ER_DB_DROP_RMDIR 1010 +#define ER_CANT_DELETE_FILE 1011 +#define ER_CANT_FIND_SYSTEM_REC 1012 +#define ER_CANT_GET_STAT 1013 +#define ER_CANT_GET_WD 1014 +#define ER_CANT_LOCK 1015 +#define ER_CANT_OPEN_FILE 1016 +#define ER_FILE_NOT_FOUND 1017 +#define ER_CANT_READ_DIR 1018 +#define ER_CANT_SET_WD 1019 +#define ER_CHECKREAD 1020 +#define ER_DISK_FULL 1021 +#define ER_DUP_KEY 1022 +#define ER_ERROR_ON_CLOSE 1023 +#define ER_ERROR_ON_READ 1024 +#define ER_ERROR_ON_RENAME 1025 +#define ER_ERROR_ON_WRITE 1026 +#define ER_FILE_USED 1027 +#define ER_FILSORT_ABORT 1028 +#define ER_FORM_NOT_FOUND 1029 +#define ER_GET_ERRNO 1030 +#define ER_ILLEGAL_HA 1031 +#define ER_KEY_NOT_FOUND 1032 +#define ER_NOT_FORM_FILE 1033 +#define ER_NOT_KEYFILE 1034 +#define ER_OLD_KEYFILE 1035 +#define ER_OPEN_AS_READONLY 1036 +#define ER_OUTOFMEMORY 1037 +#define ER_OUT_OF_SORTMEMORY 1038 +#define ER_UNEXPECTED_EOF 1039 +#define ER_CON_COUNT_ERROR 1040 +#define ER_OUT_OF_RESOURCES 1041 +#define ER_BAD_HOST_ERROR 1042 +#define ER_HANDSHAKE_ERROR 1043 +#define ER_DBACCESS_DENIED_ERROR 1044 +#define ER_ACCESS_DENIED_ERROR 1045 +#define ER_NO_DB_ERROR 1046 +#define ER_UNKNOWN_COM_ERROR 1047 +#define ER_BAD_NULL_ERROR 1048 +#define ER_BAD_DB_ERROR 1049 +#define ER_TABLE_EXISTS_ERROR 1050 +#define ER_BAD_TABLE_ERROR 1051 +#define ER_NON_UNIQ_ERROR 1052 +#define ER_SERVER_SHUTDOWN 1053 +#define ER_BAD_FIELD_ERROR 1054 +#define ER_WRONG_FIELD_WITH_GROUP 1055 +#define ER_WRONG_GROUP_FIELD 1056 +#define ER_WRONG_SUM_SELECT 1057 +#define ER_WRONG_VALUE_COUNT 1058 +#define ER_TOO_LONG_IDENT 1059 +#define ER_DUP_FIELDNAME 1060 +#define ER_DUP_KEYNAME 1061 +#define ER_DUP_ENTRY 1062 +#define ER_WRONG_FIELD_SPEC 1063 +#define ER_PARSE_ERROR 1064 +#define ER_EMPTY_QUERY 1065 +#define ER_NONUNIQ_TABLE 1066 +#define ER_INVALID_DEFAULT 1067 +#define ER_MULTIPLE_PRI_KEY 1068 +#define ER_TOO_MANY_KEYS 1069 +#define ER_TOO_MANY_KEY_PARTS 1070 +#define ER_TOO_LONG_KEY 1071 +#define ER_KEY_COLUMN_DOES_NOT_EXITS 1072 +#define ER_BLOB_USED_AS_KEY 1073 +#define ER_TOO_BIG_FIELDLENGTH 1074 +#define ER_WRONG_AUTO_KEY 1075 +#define ER_BINLOG_CANT_DELETE_GTID_DOMAIN 1076 +#define ER_NORMAL_SHUTDOWN 1077 +#define ER_GOT_SIGNAL 1078 +#define ER_SHUTDOWN_COMPLETE 1079 +#define ER_FORCING_CLOSE 1080 +#define ER_IPSOCK_ERROR 1081 +#define ER_NO_SUCH_INDEX 1082 +#define ER_WRONG_FIELD_TERMINATORS 1083 +#define ER_BLOBS_AND_NO_TERMINATED 1084 +#define ER_TEXTFILE_NOT_READABLE 1085 +#define ER_FILE_EXISTS_ERROR 1086 +#define ER_LOAD_INFO 1087 +#define ER_ALTER_INFO 1088 +#define ER_WRONG_SUB_KEY 1089 +#define ER_CANT_REMOVE_ALL_FIELDS 1090 +#define ER_CANT_DROP_FIELD_OR_KEY 1091 +#define ER_INSERT_INFO 1092 +#define ER_UPDATE_TABLE_USED 1093 +#define ER_NO_SUCH_THREAD 1094 +#define ER_KILL_DENIED_ERROR 1095 +#define ER_NO_TABLES_USED 1096 +#define ER_TOO_BIG_SET 1097 +#define ER_NO_UNIQUE_LOGFILE 1098 +#define ER_TABLE_NOT_LOCKED_FOR_WRITE 1099 +#define ER_TABLE_NOT_LOCKED 1100 +#define ER_UNUSED_17 1101 +#define ER_WRONG_DB_NAME 1102 +#define ER_WRONG_TABLE_NAME 1103 +#define ER_TOO_BIG_SELECT 1104 +#define ER_UNKNOWN_ERROR 1105 +#define ER_UNKNOWN_PROCEDURE 1106 +#define ER_WRONG_PARAMCOUNT_TO_PROCEDURE 1107 +#define ER_WRONG_PARAMETERS_TO_PROCEDURE 1108 +#define ER_UNKNOWN_TABLE 1109 +#define ER_FIELD_SPECIFIED_TWICE 1110 +#define ER_INVALID_GROUP_FUNC_USE 1111 +#define ER_UNSUPPORTED_EXTENSION 1112 +#define ER_TABLE_MUST_HAVE_COLUMNS 1113 +#define ER_RECORD_FILE_FULL 1114 +#define ER_UNKNOWN_CHARACTER_SET 1115 +#define ER_TOO_MANY_TABLES 1116 +#define ER_TOO_MANY_FIELDS 1117 +#define ER_TOO_BIG_ROWSIZE 1118 +#define ER_STACK_OVERRUN 1119 +#define ER_WRONG_OUTER_JOIN 1120 +#define ER_NULL_COLUMN_IN_INDEX 1121 +#define ER_CANT_FIND_UDF 1122 +#define ER_CANT_INITIALIZE_UDF 1123 +#define ER_UDF_NO_PATHS 1124 +#define ER_UDF_EXISTS 1125 +#define ER_CANT_OPEN_LIBRARY 1126 +#define ER_CANT_FIND_DL_ENTRY 1127 +#define ER_FUNCTION_NOT_DEFINED 1128 +#define ER_HOST_IS_BLOCKED 1129 +#define ER_HOST_NOT_PRIVILEGED 1130 +#define ER_PASSWORD_ANONYMOUS_USER 1131 +#define ER_PASSWORD_NOT_ALLOWED 1132 +#define ER_PASSWORD_NO_MATCH 1133 +#define ER_UPDATE_INFO 1134 +#define ER_CANT_CREATE_THREAD 1135 +#define ER_WRONG_VALUE_COUNT_ON_ROW 1136 +#define ER_CANT_REOPEN_TABLE 1137 +#define ER_INVALID_USE_OF_NULL 1138 +#define ER_REGEXP_ERROR 1139 +#define ER_MIX_OF_GROUP_FUNC_AND_FIELDS 1140 +#define ER_NONEXISTING_GRANT 1141 +#define ER_TABLEACCESS_DENIED_ERROR 1142 +#define ER_COLUMNACCESS_DENIED_ERROR 1143 +#define ER_ILLEGAL_GRANT_FOR_TABLE 1144 +#define ER_GRANT_WRONG_HOST_OR_USER 1145 +#define ER_NO_SUCH_TABLE 1146 +#define ER_NONEXISTING_TABLE_GRANT 1147 +#define ER_NOT_ALLOWED_COMMAND 1148 +#define ER_SYNTAX_ERROR 1149 +#define ER_DELAYED_CANT_CHANGE_LOCK 1150 +#define ER_TOO_MANY_DELAYED_THREADS 1151 +#define ER_ABORTING_CONNECTION 1152 +#define ER_NET_PACKET_TOO_LARGE 1153 +#define ER_NET_READ_ERROR_FROM_PIPE 1154 +#define ER_NET_FCNTL_ERROR 1155 +#define ER_NET_PACKETS_OUT_OF_ORDER 1156 +#define ER_NET_UNCOMPRESS_ERROR 1157 +#define ER_NET_READ_ERROR 1158 +#define ER_NET_READ_INTERRUPTED 1159 +#define ER_NET_ERROR_ON_WRITE 1160 +#define ER_NET_WRITE_INTERRUPTED 1161 +#define ER_TOO_LONG_STRING 1162 +#define ER_TABLE_CANT_HANDLE_BLOB 1163 +#define ER_TABLE_CANT_HANDLE_AUTO_INCREMENT 1164 +#define ER_DELAYED_INSERT_TABLE_LOCKED 1165 +#define ER_WRONG_COLUMN_NAME 1166 +#define ER_WRONG_KEY_COLUMN 1167 +#define ER_WRONG_MRG_TABLE 1168 +#define ER_DUP_UNIQUE 1169 +#define ER_BLOB_KEY_WITHOUT_LENGTH 1170 +#define ER_PRIMARY_CANT_HAVE_NULL 1171 +#define ER_TOO_MANY_ROWS 1172 +#define ER_REQUIRES_PRIMARY_KEY 1173 +#define ER_NO_RAID_COMPILED 1174 +#define ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE 1175 +#define ER_KEY_DOES_NOT_EXISTS 1176 +#define ER_CHECK_NO_SUCH_TABLE 1177 +#define ER_CHECK_NOT_IMPLEMENTED 1178 +#define ER_CANT_DO_THIS_DURING_AN_TRANSACTION 1179 +#define ER_ERROR_DURING_COMMIT 1180 +#define ER_ERROR_DURING_ROLLBACK 1181 +#define ER_ERROR_DURING_FLUSH_LOGS 1182 +#define ER_ERROR_DURING_CHECKPOINT 1183 +#define ER_NEW_ABORTING_CONNECTION 1184 +#define ER_UNUSED_10 1185 +#define ER_FLUSH_MASTER_BINLOG_CLOSED 1186 +#define ER_INDEX_REBUILD 1187 +#define ER_MASTER 1188 +#define ER_MASTER_NET_READ 1189 +#define ER_MASTER_NET_WRITE 1190 +#define ER_FT_MATCHING_KEY_NOT_FOUND 1191 +#define ER_LOCK_OR_ACTIVE_TRANSACTION 1192 +#define ER_UNKNOWN_SYSTEM_VARIABLE 1193 +#define ER_CRASHED_ON_USAGE 1194 +#define ER_CRASHED_ON_REPAIR 1195 +#define ER_WARNING_NOT_COMPLETE_ROLLBACK 1196 +#define ER_TRANS_CACHE_FULL 1197 +#define ER_SLAVE_MUST_STOP 1198 +#define ER_SLAVE_NOT_RUNNING 1199 +#define ER_BAD_SLAVE 1200 +#define ER_MASTER_INFO 1201 +#define ER_SLAVE_THREAD 1202 +#define ER_TOO_MANY_USER_CONNECTIONS 1203 +#define ER_SET_CONSTANTS_ONLY 1204 +#define ER_LOCK_WAIT_TIMEOUT 1205 +#define ER_LOCK_TABLE_FULL 1206 +#define ER_READ_ONLY_TRANSACTION 1207 +#define ER_DROP_DB_WITH_READ_LOCK 1208 +#define ER_CREATE_DB_WITH_READ_LOCK 1209 +#define ER_WRONG_ARGUMENTS 1210 +#define ER_NO_PERMISSION_TO_CREATE_USER 1211 +#define ER_UNION_TABLES_IN_DIFFERENT_DIR 1212 +#define ER_LOCK_DEADLOCK 1213 +#define ER_TABLE_CANT_HANDLE_FT 1214 +#define ER_CANNOT_ADD_FOREIGN 1215 +#define ER_NO_REFERENCED_ROW 1216 +#define ER_ROW_IS_REFERENCED 1217 +#define ER_CONNECT_TO_MASTER 1218 +#define ER_QUERY_ON_MASTER 1219 +#define ER_ERROR_WHEN_EXECUTING_COMMAND 1220 +#define ER_WRONG_USAGE 1221 +#define ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT 1222 +#define ER_CANT_UPDATE_WITH_READLOCK 1223 +#define ER_MIXING_NOT_ALLOWED 1224 +#define ER_DUP_ARGUMENT 1225 +#define ER_USER_LIMIT_REACHED 1226 +#define ER_SPECIFIC_ACCESS_DENIED_ERROR 1227 +#define ER_LOCAL_VARIABLE 1228 +#define ER_GLOBAL_VARIABLE 1229 +#define ER_NO_DEFAULT 1230 +#define ER_WRONG_VALUE_FOR_VAR 1231 +#define ER_WRONG_TYPE_FOR_VAR 1232 +#define ER_VAR_CANT_BE_READ 1233 +#define ER_CANT_USE_OPTION_HERE 1234 +#define ER_NOT_SUPPORTED_YET 1235 +#define ER_MASTER_FATAL_ERROR_READING_BINLOG 1236 +#define ER_SLAVE_IGNORED_TABLE 1237 +#define ER_INCORRECT_GLOBAL_LOCAL_VAR 1238 +#define ER_WRONG_FK_DEF 1239 +#define ER_KEY_REF_DO_NOT_MATCH_TABLE_REF 1240 +#define ER_OPERAND_COLUMNS 1241 +#define ER_SUBQUERY_NO_1_ROW 1242 +#define ER_UNKNOWN_STMT_HANDLER 1243 +#define ER_CORRUPT_HELP_DB 1244 +#define ER_CYCLIC_REFERENCE 1245 +#define ER_AUTO_CONVERT 1246 +#define ER_ILLEGAL_REFERENCE 1247 +#define ER_DERIVED_MUST_HAVE_ALIAS 1248 +#define ER_SELECT_REDUCED 1249 +#define ER_TABLENAME_NOT_ALLOWED_HERE 1250 +#define ER_NOT_SUPPORTED_AUTH_MODE 1251 +#define ER_SPATIAL_CANT_HAVE_NULL 1252 +#define ER_COLLATION_CHARSET_MISMATCH 1253 +#define ER_SLAVE_WAS_RUNNING 1254 +#define ER_SLAVE_WAS_NOT_RUNNING 1255 +#define ER_TOO_BIG_FOR_UNCOMPRESS 1256 +#define ER_ZLIB_Z_MEM_ERROR 1257 +#define ER_ZLIB_Z_BUF_ERROR 1258 +#define ER_ZLIB_Z_DATA_ERROR 1259 +#define ER_CUT_VALUE_GROUP_CONCAT 1260 +#define ER_WARN_TOO_FEW_RECORDS 1261 +#define ER_WARN_TOO_MANY_RECORDS 1262 +#define ER_WARN_NULL_TO_NOTNULL 1263 +#define ER_WARN_DATA_OUT_OF_RANGE 1264 +#define WARN_DATA_TRUNCATED 1265 +#define ER_WARN_USING_OTHER_HANDLER 1266 +#define ER_CANT_AGGREGATE_2COLLATIONS 1267 +#define ER_DROP_USER 1268 +#define ER_REVOKE_GRANTS 1269 +#define ER_CANT_AGGREGATE_3COLLATIONS 1270 +#define ER_CANT_AGGREGATE_NCOLLATIONS 1271 +#define ER_VARIABLE_IS_NOT_STRUCT 1272 +#define ER_UNKNOWN_COLLATION 1273 +#define ER_SLAVE_IGNORED_SSL_PARAMS 1274 +#define ER_SERVER_IS_IN_SECURE_AUTH_MODE 1275 +#define ER_WARN_FIELD_RESOLVED 1276 +#define ER_BAD_SLAVE_UNTIL_COND 1277 +#define ER_MISSING_SKIP_SLAVE 1278 +#define ER_UNTIL_COND_IGNORED 1279 +#define ER_WRONG_NAME_FOR_INDEX 1280 +#define ER_WRONG_NAME_FOR_CATALOG 1281 +#define ER_WARN_QC_RESIZE 1282 +#define ER_BAD_FT_COLUMN 1283 +#define ER_UNKNOWN_KEY_CACHE 1284 +#define ER_WARN_HOSTNAME_WONT_WORK 1285 +#define ER_UNKNOWN_STORAGE_ENGINE 1286 +#define ER_WARN_DEPRECATED_SYNTAX 1287 +#define ER_NON_UPDATABLE_TABLE 1288 +#define ER_FEATURE_DISABLED 1289 +#define ER_OPTION_PREVENTS_STATEMENT 1290 +#define ER_DUPLICATED_VALUE_IN_TYPE 1291 +#define ER_TRUNCATED_WRONG_VALUE 1292 +#define ER_TOO_MUCH_AUTO_TIMESTAMP_COLS 1293 +#define ER_INVALID_ON_UPDATE 1294 +#define ER_UNSUPPORTED_PS 1295 +#define ER_GET_ERRMSG 1296 +#define ER_GET_TEMPORARY_ERRMSG 1297 +#define ER_UNKNOWN_TIME_ZONE 1298 +#define ER_WARN_INVALID_TIMESTAMP 1299 +#define ER_INVALID_CHARACTER_STRING 1300 +#define ER_WARN_ALLOWED_PACKET_OVERFLOWED 1301 +#define ER_CONFLICTING_DECLARATIONS 1302 +#define ER_SP_NO_RECURSIVE_CREATE 1303 +#define ER_SP_ALREADY_EXISTS 1304 +#define ER_SP_DOES_NOT_EXIST 1305 +#define ER_SP_DROP_FAILED 1306 +#define ER_SP_STORE_FAILED 1307 +#define ER_SP_LILABEL_MISMATCH 1308 +#define ER_SP_LABEL_REDEFINE 1309 +#define ER_SP_LABEL_MISMATCH 1310 +#define ER_SP_UNINIT_VAR 1311 +#define ER_SP_BADSELECT 1312 +#define ER_SP_BADRETURN 1313 +#define ER_SP_BADSTATEMENT 1314 +#define ER_UPDATE_LOG_DEPRECATED_IGNORED 1315 +#define ER_UPDATE_LOG_DEPRECATED_TRANSLATED 1316 +#define ER_QUERY_INTERRUPTED 1317 +#define ER_SP_WRONG_NO_OF_ARGS 1318 +#define ER_SP_COND_MISMATCH 1319 +#define ER_SP_NORETURN 1320 +#define ER_SP_NORETURNEND 1321 +#define ER_SP_BAD_CURSOR_QUERY 1322 +#define ER_SP_BAD_CURSOR_SELECT 1323 +#define ER_SP_CURSOR_MISMATCH 1324 +#define ER_SP_CURSOR_ALREADY_OPEN 1325 +#define ER_SP_CURSOR_NOT_OPEN 1326 +#define ER_SP_UNDECLARED_VAR 1327 +#define ER_SP_WRONG_NO_OF_FETCH_ARGS 1328 +#define ER_SP_FETCH_NO_DATA 1329 +#define ER_SP_DUP_PARAM 1330 +#define ER_SP_DUP_VAR 1331 +#define ER_SP_DUP_COND 1332 +#define ER_SP_DUP_CURS 1333 +#define ER_SP_CANT_ALTER 1334 +#define ER_SP_SUBSELECT_NYI 1335 +#define ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG 1336 +#define ER_SP_VARCOND_AFTER_CURSHNDLR 1337 +#define ER_SP_CURSOR_AFTER_HANDLER 1338 +#define ER_SP_CASE_NOT_FOUND 1339 +#define ER_FPARSER_TOO_BIG_FILE 1340 +#define ER_FPARSER_BAD_HEADER 1341 +#define ER_FPARSER_EOF_IN_COMMENT 1342 +#define ER_FPARSER_ERROR_IN_PARAMETER 1343 +#define ER_FPARSER_EOF_IN_UNKNOWN_PARAMETER 1344 +#define ER_VIEW_NO_EXPLAIN 1345 +#define ER_FRM_UNKNOWN_TYPE 1346 +#define ER_WRONG_OBJECT 1347 +#define ER_NONUPDATEABLE_COLUMN 1348 +#define ER_VIEW_SELECT_DERIVED 1349 +#define ER_VIEW_SELECT_CLAUSE 1350 +#define ER_VIEW_SELECT_VARIABLE 1351 +#define ER_VIEW_SELECT_TMPTABLE 1352 +#define ER_VIEW_WRONG_LIST 1353 +#define ER_WARN_VIEW_MERGE 1354 +#define ER_WARN_VIEW_WITHOUT_KEY 1355 +#define ER_VIEW_INVALID 1356 +#define ER_SP_NO_DROP_SP 1357 +#define ER_SP_GOTO_IN_HNDLR 1358 +#define ER_TRG_ALREADY_EXISTS 1359 +#define ER_TRG_DOES_NOT_EXIST 1360 +#define ER_TRG_ON_VIEW_OR_TEMP_TABLE 1361 +#define ER_TRG_CANT_CHANGE_ROW 1362 +#define ER_TRG_NO_SUCH_ROW_IN_TRG 1363 +#define ER_NO_DEFAULT_FOR_FIELD 1364 +#define ER_DIVISION_BY_ZERO 1365 +#define ER_TRUNCATED_WRONG_VALUE_FOR_FIELD 1366 +#define ER_ILLEGAL_VALUE_FOR_TYPE 1367 +#define ER_VIEW_NONUPD_CHECK 1368 +#define ER_VIEW_CHECK_FAILED 1369 +#define ER_PROCACCESS_DENIED_ERROR 1370 +#define ER_RELAY_LOG_FAIL 1371 +#define ER_PASSWD_LENGTH 1372 +#define ER_UNKNOWN_TARGET_BINLOG 1373 +#define ER_IO_ERR_LOG_INDEX_READ 1374 +#define ER_BINLOG_PURGE_PROHIBITED 1375 +#define ER_FSEEK_FAIL 1376 +#define ER_BINLOG_PURGE_FATAL_ERR 1377 +#define ER_LOG_IN_USE 1378 +#define ER_LOG_PURGE_UNKNOWN_ERR 1379 +#define ER_RELAY_LOG_INIT 1380 +#define ER_NO_BINARY_LOGGING 1381 +#define ER_RESERVED_SYNTAX 1382 +#define ER_WSAS_FAILED 1383 +#define ER_DIFF_GROUPS_PROC 1384 +#define ER_NO_GROUP_FOR_PROC 1385 +#define ER_ORDER_WITH_PROC 1386 +#define ER_LOGGING_PROHIBIT_CHANGING_OF 1387 +#define ER_NO_FILE_MAPPING 1388 +#define ER_WRONG_MAGIC 1389 +#define ER_PS_MANY_PARAM 1390 +#define ER_KEY_PART_0 1391 +#define ER_VIEW_CHECKSUM 1392 +#define ER_VIEW_MULTIUPDATE 1393 +#define ER_VIEW_NO_INSERT_FIELD_LIST 1394 +#define ER_VIEW_DELETE_MERGE_VIEW 1395 +#define ER_CANNOT_USER 1396 +#define ER_XAER_NOTA 1397 +#define ER_XAER_INVAL 1398 +#define ER_XAER_RMFAIL 1399 +#define ER_XAER_OUTSIDE 1400 +#define ER_XAER_RMERR 1401 +#define ER_XA_RBROLLBACK 1402 +#define ER_NONEXISTING_PROC_GRANT 1403 +#define ER_PROC_AUTO_GRANT_FAIL 1404 +#define ER_PROC_AUTO_REVOKE_FAIL 1405 +#define ER_DATA_TOO_LONG 1406 +#define ER_SP_BAD_SQLSTATE 1407 +#define ER_STARTUP 1408 +#define ER_LOAD_FROM_FIXED_SIZE_ROWS_TO_VAR 1409 +#define ER_CANT_CREATE_USER_WITH_GRANT 1410 +#define ER_WRONG_VALUE_FOR_TYPE 1411 +#define ER_TABLE_DEF_CHANGED 1412 +#define ER_SP_DUP_HANDLER 1413 +#define ER_SP_NOT_VAR_ARG 1414 +#define ER_SP_NO_RETSET 1415 +#define ER_CANT_CREATE_GEOMETRY_OBJECT 1416 +#define ER_FAILED_ROUTINE_BREAK_BINLOG 1417 +#define ER_BINLOG_UNSAFE_ROUTINE 1418 +#define ER_BINLOG_CREATE_ROUTINE_NEED_SUPER 1419 +#define ER_EXEC_STMT_WITH_OPEN_CURSOR 1420 +#define ER_STMT_HAS_NO_OPEN_CURSOR 1421 +#define ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG 1422 +#define ER_NO_DEFAULT_FOR_VIEW_FIELD 1423 +#define ER_SP_NO_RECURSION 1424 +#define ER_TOO_BIG_SCALE 1425 +#define ER_TOO_BIG_PRECISION 1426 +#define ER_M_BIGGER_THAN_D 1427 +#define ER_WRONG_LOCK_OF_SYSTEM_TABLE 1428 +#define ER_CONNECT_TO_FOREIGN_DATA_SOURCE 1429 +#define ER_QUERY_ON_FOREIGN_DATA_SOURCE 1430 +#define ER_FOREIGN_DATA_SOURCE_DOESNT_EXIST 1431 +#define ER_FOREIGN_DATA_STRING_INVALID_CANT_CREATE 1432 +#define ER_FOREIGN_DATA_STRING_INVALID 1433 +#define ER_CANT_CREATE_FEDERATED_TABLE 1434 +#define ER_TRG_IN_WRONG_SCHEMA 1435 +#define ER_STACK_OVERRUN_NEED_MORE 1436 +#define ER_TOO_LONG_BODY 1437 +#define ER_WARN_CANT_DROP_DEFAULT_KEYCACHE 1438 +#define ER_TOO_BIG_DISPLAYWIDTH 1439 +#define ER_XAER_DUPID 1440 +#define ER_DATETIME_FUNCTION_OVERFLOW 1441 +#define ER_CANT_UPDATE_USED_TABLE_IN_SF_OR_TRG 1442 +#define ER_VIEW_PREVENT_UPDATE 1443 +#define ER_PS_NO_RECURSION 1444 +#define ER_SP_CANT_SET_AUTOCOMMIT 1445 +#define ER_MALFORMED_DEFINER 1446 +#define ER_VIEW_FRM_NO_USER 1447 +#define ER_VIEW_OTHER_USER 1448 +#define ER_NO_SUCH_USER 1449 +#define ER_FORBID_SCHEMA_CHANGE 1450 +#define ER_ROW_IS_REFERENCED_2 1451 +#define ER_NO_REFERENCED_ROW_2 1452 +#define ER_SP_BAD_VAR_SHADOW 1453 +#define ER_TRG_NO_DEFINER 1454 +#define ER_OLD_FILE_FORMAT 1455 +#define ER_SP_RECURSION_LIMIT 1456 +#define ER_SP_PROC_TABLE_CORRUPT 1457 +#define ER_SP_WRONG_NAME 1458 +#define ER_TABLE_NEEDS_UPGRADE 1459 +#define ER_SP_NO_AGGREGATE 1460 +#define ER_MAX_PREPARED_STMT_COUNT_REACHED 1461 +#define ER_VIEW_RECURSIVE 1462 +#define ER_NON_GROUPING_FIELD_USED 1463 +#define ER_TABLE_CANT_HANDLE_SPKEYS 1464 +#define ER_NO_TRIGGERS_ON_SYSTEM_SCHEMA 1465 +#define ER_REMOVED_SPACES 1466 +#define ER_AUTOINC_READ_FAILED 1467 +#define ER_USERNAME 1468 +#define ER_HOSTNAME 1469 +#define ER_WRONG_STRING_LENGTH 1470 +#define ER_NON_INSERTABLE_TABLE 1471 +#define ER_ADMIN_WRONG_MRG_TABLE 1472 +#define ER_TOO_HIGH_LEVEL_OF_NESTING_FOR_SELECT 1473 +#define ER_NAME_BECOMES_EMPTY 1474 +#define ER_AMBIGUOUS_FIELD_TERM 1475 +#define ER_FOREIGN_SERVER_EXISTS 1476 +#define ER_FOREIGN_SERVER_DOESNT_EXIST 1477 +#define ER_ILLEGAL_HA_CREATE_OPTION 1478 +#define ER_PARTITION_REQUIRES_VALUES_ERROR 1479 +#define ER_PARTITION_WRONG_VALUES_ERROR 1480 +#define ER_PARTITION_MAXVALUE_ERROR 1481 +#define ER_PARTITION_SUBPARTITION_ERROR 1482 +#define ER_PARTITION_SUBPART_MIX_ERROR 1483 +#define ER_PARTITION_WRONG_NO_PART_ERROR 1484 +#define ER_PARTITION_WRONG_NO_SUBPART_ERROR 1485 +#define ER_WRONG_EXPR_IN_PARTITION_FUNC_ERROR 1486 +#define ER_NOT_CONSTANT_EXPRESSION 1487 +#define ER_FIELD_NOT_FOUND_PART_ERROR 1488 +#define ER_LIST_OF_FIELDS_ONLY_IN_HASH_ERROR 1489 +#define ER_INCONSISTENT_PARTITION_INFO_ERROR 1490 +#define ER_PARTITION_FUNC_NOT_ALLOWED_ERROR 1491 +#define ER_PARTITIONS_MUST_BE_DEFINED_ERROR 1492 +#define ER_RANGE_NOT_INCREASING_ERROR 1493 +#define ER_INCONSISTENT_TYPE_OF_FUNCTIONS_ERROR 1494 +#define ER_MULTIPLE_DEF_CONST_IN_LIST_PART_ERROR 1495 +#define ER_PARTITION_ENTRY_ERROR 1496 +#define ER_MIX_HANDLER_ERROR 1497 +#define ER_PARTITION_NOT_DEFINED_ERROR 1498 +#define ER_TOO_MANY_PARTITIONS_ERROR 1499 +#define ER_SUBPARTITION_ERROR 1500 +#define ER_CANT_CREATE_HANDLER_FILE 1501 +#define ER_BLOB_FIELD_IN_PART_FUNC_ERROR 1502 +#define ER_UNIQUE_KEY_NEED_ALL_FIELDS_IN_PF 1503 +#define ER_NO_PARTS_ERROR 1504 +#define ER_PARTITION_MGMT_ON_NONPARTITIONED 1505 +#define ER_FEATURE_NOT_SUPPORTED_WITH_PARTITIONING 1506 +#define ER_DROP_PARTITION_NON_EXISTENT 1507 +#define ER_DROP_LAST_PARTITION 1508 +#define ER_COALESCE_ONLY_ON_HASH_PARTITION 1509 +#define ER_REORG_HASH_ONLY_ON_SAME_NO 1510 +#define ER_REORG_NO_PARAM_ERROR 1511 +#define ER_ONLY_ON_RANGE_LIST_PARTITION 1512 +#define ER_ADD_PARTITION_SUBPART_ERROR 1513 +#define ER_ADD_PARTITION_NO_NEW_PARTITION 1514 +#define ER_COALESCE_PARTITION_NO_PARTITION 1515 +#define ER_REORG_PARTITION_NOT_EXIST 1516 +#define ER_SAME_NAME_PARTITION 1517 +#define ER_NO_BINLOG_ERROR 1518 +#define ER_CONSECUTIVE_REORG_PARTITIONS 1519 +#define ER_REORG_OUTSIDE_RANGE 1520 +#define ER_PARTITION_FUNCTION_FAILURE 1521 +#define ER_PART_STATE_ERROR 1522 +#define ER_LIMITED_PART_RANGE 1523 +#define ER_PLUGIN_IS_NOT_LOADED 1524 +#define ER_WRONG_VALUE 1525 +#define ER_NO_PARTITION_FOR_GIVEN_VALUE 1526 +#define ER_FILEGROUP_OPTION_ONLY_ONCE 1527 +#define ER_CREATE_FILEGROUP_FAILED 1528 +#define ER_DROP_FILEGROUP_FAILED 1529 +#define ER_TABLESPACE_AUTO_EXTEND_ERROR 1530 +#define ER_WRONG_SIZE_NUMBER 1531 +#define ER_SIZE_OVERFLOW_ERROR 1532 +#define ER_ALTER_FILEGROUP_FAILED 1533 +#define ER_BINLOG_ROW_LOGGING_FAILED 1534 +#define ER_BINLOG_ROW_WRONG_TABLE_DEF 1535 +#define ER_BINLOG_ROW_RBR_TO_SBR 1536 +#define ER_EVENT_ALREADY_EXISTS 1537 +#define ER_EVENT_STORE_FAILED 1538 +#define ER_EVENT_DOES_NOT_EXIST 1539 +#define ER_EVENT_CANT_ALTER 1540 +#define ER_EVENT_DROP_FAILED 1541 +#define ER_EVENT_INTERVAL_NOT_POSITIVE_OR_TOO_BIG 1542 +#define ER_EVENT_ENDS_BEFORE_STARTS 1543 +#define ER_EVENT_EXEC_TIME_IN_THE_PAST 1544 +#define ER_EVENT_OPEN_TABLE_FAILED 1545 +#define ER_EVENT_NEITHER_M_EXPR_NOR_M_AT 1546 +#define ER_UNUSED_2 1547 +#define ER_UNUSED_3 1548 +#define ER_EVENT_CANNOT_DELETE 1549 +#define ER_EVENT_COMPILE_ERROR 1550 +#define ER_EVENT_SAME_NAME 1551 +#define ER_EVENT_DATA_TOO_LONG 1552 +#define ER_DROP_INDEX_FK 1553 +#define ER_WARN_DEPRECATED_SYNTAX_WITH_VER 1554 +#define ER_CANT_WRITE_LOCK_LOG_TABLE 1555 +#define ER_CANT_LOCK_LOG_TABLE 1556 +#define ER_UNUSED_4 1557 +#define ER_COL_COUNT_DOESNT_MATCH_PLEASE_UPDATE 1558 +#define ER_TEMP_TABLE_PREVENTS_SWITCH_OUT_OF_RBR 1559 +#define ER_STORED_FUNCTION_PREVENTS_SWITCH_BINLOG_FORMAT 1560 +#define ER_UNUSED_13 1561 +#define ER_PARTITION_NO_TEMPORARY 1562 +#define ER_PARTITION_CONST_DOMAIN_ERROR 1563 +#define ER_PARTITION_FUNCTION_IS_NOT_ALLOWED 1564 +#define ER_DDL_LOG_ERROR 1565 +#define ER_NULL_IN_VALUES_LESS_THAN 1566 +#define ER_WRONG_PARTITION_NAME 1567 +#define ER_CANT_CHANGE_TX_CHARACTERISTICS 1568 +#define ER_DUP_ENTRY_AUTOINCREMENT_CASE 1569 +#define ER_EVENT_MODIFY_QUEUE_ERROR 1570 +#define ER_EVENT_SET_VAR_ERROR 1571 +#define ER_PARTITION_MERGE_ERROR 1572 +#define ER_CANT_ACTIVATE_LOG 1573 +#define ER_RBR_NOT_AVAILABLE 1574 +#define ER_BASE64_DECODE_ERROR 1575 +#define ER_EVENT_RECURSION_FORBIDDEN 1576 +#define ER_EVENTS_DB_ERROR 1577 +#define ER_ONLY_INTEGERS_ALLOWED 1578 +#define ER_UNSUPORTED_LOG_ENGINE 1579 +#define ER_BAD_LOG_STATEMENT 1580 +#define ER_CANT_RENAME_LOG_TABLE 1581 +#define ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT 1582 +#define ER_WRONG_PARAMETERS_TO_NATIVE_FCT 1583 +#define ER_WRONG_PARAMETERS_TO_STORED_FCT 1584 +#define ER_NATIVE_FCT_NAME_COLLISION 1585 +#define ER_DUP_ENTRY_WITH_KEY_NAME 1586 +#define ER_BINLOG_PURGE_EMFILE 1587 +#define ER_EVENT_CANNOT_CREATE_IN_THE_PAST 1588 +#define ER_EVENT_CANNOT_ALTER_IN_THE_PAST 1589 +#define ER_SLAVE_INCIDENT 1590 +#define ER_NO_PARTITION_FOR_GIVEN_VALUE_SILENT 1591 +#define ER_BINLOG_UNSAFE_STATEMENT 1592 +#define ER_SLAVE_FATAL_ERROR 1593 +#define ER_SLAVE_RELAY_LOG_READ_FAILURE 1594 +#define ER_SLAVE_RELAY_LOG_WRITE_FAILURE 1595 +#define ER_SLAVE_CREATE_EVENT_FAILURE 1596 +#define ER_SLAVE_MASTER_COM_FAILURE 1597 +#define ER_BINLOG_LOGGING_IMPOSSIBLE 1598 +#define ER_VIEW_NO_CREATION_CTX 1599 +#define ER_VIEW_INVALID_CREATION_CTX 1600 +#define ER_SR_INVALID_CREATION_CTX 1601 +#define ER_TRG_CORRUPTED_FILE 1602 +#define ER_TRG_NO_CREATION_CTX 1603 +#define ER_TRG_INVALID_CREATION_CTX 1604 +#define ER_EVENT_INVALID_CREATION_CTX 1605 +#define ER_TRG_CANT_OPEN_TABLE 1606 +#define ER_CANT_CREATE_SROUTINE 1607 +#define ER_UNUSED_11 1608 +#define ER_NO_FORMAT_DESCRIPTION_EVENT_BEFORE_BINLOG_STATEMENT 1609 +#define ER_SLAVE_CORRUPT_EVENT 1610 +#define ER_LOAD_DATA_INVALID_COLUMN 1611 +#define ER_LOG_PURGE_NO_FILE 1612 +#define ER_XA_RBTIMEOUT 1613 +#define ER_XA_RBDEADLOCK 1614 +#define ER_NEED_REPREPARE 1615 +#define ER_DELAYED_NOT_SUPPORTED 1616 +#define WARN_NO_MASTER_INFO 1617 +#define WARN_OPTION_IGNORED 1618 +#define ER_PLUGIN_DELETE_BUILTIN 1619 +#define WARN_PLUGIN_BUSY 1620 +#define ER_VARIABLE_IS_READONLY 1621 +#define ER_WARN_ENGINE_TRANSACTION_ROLLBACK 1622 +#define ER_SLAVE_HEARTBEAT_FAILURE 1623 +#define ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE 1624 +#define ER_UNUSED_14 1625 +#define ER_CONFLICT_FN_PARSE_ERROR 1626 +#define ER_EXCEPTIONS_WRITE_ERROR 1627 +#define ER_TOO_LONG_TABLE_COMMENT 1628 +#define ER_TOO_LONG_FIELD_COMMENT 1629 +#define ER_FUNC_INEXISTENT_NAME_COLLISION 1630 +#define ER_DATABASE_NAME 1631 +#define ER_TABLE_NAME 1632 +#define ER_PARTITION_NAME 1633 +#define ER_SUBPARTITION_NAME 1634 +#define ER_TEMPORARY_NAME 1635 +#define ER_RENAMED_NAME 1636 +#define ER_TOO_MANY_CONCURRENT_TRXS 1637 +#define WARN_NON_ASCII_SEPARATOR_NOT_IMPLEMENTED 1638 +#define ER_DEBUG_SYNC_TIMEOUT 1639 +#define ER_DEBUG_SYNC_HIT_LIMIT 1640 +#define ER_DUP_SIGNAL_SET 1641 +#define ER_SIGNAL_WARN 1642 +#define ER_SIGNAL_NOT_FOUND 1643 +#define ER_SIGNAL_EXCEPTION 1644 +#define ER_RESIGNAL_WITHOUT_ACTIVE_HANDLER 1645 +#define ER_SIGNAL_BAD_CONDITION_TYPE 1646 +#define WARN_COND_ITEM_TRUNCATED 1647 +#define ER_COND_ITEM_TOO_LONG 1648 +#define ER_UNKNOWN_LOCALE 1649 +#define ER_SLAVE_IGNORE_SERVER_IDS 1650 +#define ER_QUERY_CACHE_DISABLED 1651 +#define ER_SAME_NAME_PARTITION_FIELD 1652 +#define ER_PARTITION_COLUMN_LIST_ERROR 1653 +#define ER_WRONG_TYPE_COLUMN_VALUE_ERROR 1654 +#define ER_TOO_MANY_PARTITION_FUNC_FIELDS_ERROR 1655 +#define ER_MAXVALUE_IN_VALUES_IN 1656 +#define ER_TOO_MANY_VALUES_ERROR 1657 +#define ER_ROW_SINGLE_PARTITION_FIELD_ERROR 1658 +#define ER_FIELD_TYPE_NOT_ALLOWED_AS_PARTITION_FIELD 1659 +#define ER_PARTITION_FIELDS_TOO_LONG 1660 +#define ER_BINLOG_ROW_ENGINE_AND_STMT_ENGINE 1661 +#define ER_BINLOG_ROW_MODE_AND_STMT_ENGINE 1662 +#define ER_BINLOG_UNSAFE_AND_STMT_ENGINE 1663 +#define ER_BINLOG_ROW_INJECTION_AND_STMT_ENGINE 1664 +#define ER_BINLOG_STMT_MODE_AND_ROW_ENGINE 1665 +#define ER_BINLOG_ROW_INJECTION_AND_STMT_MODE 1666 +#define ER_BINLOG_MULTIPLE_ENGINES_AND_SELF_LOGGING_ENGINE 1667 +#define ER_BINLOG_UNSAFE_LIMIT 1668 +#define ER_BINLOG_UNSAFE_INSERT_DELAYED 1669 +#define ER_BINLOG_UNSAFE_SYSTEM_TABLE 1670 +#define ER_BINLOG_UNSAFE_AUTOINC_COLUMNS 1671 +#define ER_BINLOG_UNSAFE_UDF 1672 +#define ER_BINLOG_UNSAFE_SYSTEM_VARIABLE 1673 +#define ER_BINLOG_UNSAFE_SYSTEM_FUNCTION 1674 +#define ER_BINLOG_UNSAFE_NONTRANS_AFTER_TRANS 1675 +#define ER_MESSAGE_AND_STATEMENT 1676 +#define ER_SLAVE_CONVERSION_FAILED 1677 +#define ER_SLAVE_CANT_CREATE_CONVERSION 1678 +#define ER_INSIDE_TRANSACTION_PREVENTS_SWITCH_BINLOG_FORMAT 1679 +#define ER_PATH_LENGTH 1680 +#define ER_WARN_DEPRECATED_SYNTAX_NO_REPLACEMENT 1681 +#define ER_WRONG_NATIVE_TABLE_STRUCTURE 1682 +#define ER_WRONG_PERFSCHEMA_USAGE 1683 +#define ER_WARN_I_S_SKIPPED_TABLE 1684 +#define ER_INSIDE_TRANSACTION_PREVENTS_SWITCH_BINLOG_DIRECT 1685 +#define ER_STORED_FUNCTION_PREVENTS_SWITCH_BINLOG_DIRECT 1686 +#define ER_SPATIAL_MUST_HAVE_GEOM_COL 1687 +#define ER_TOO_LONG_INDEX_COMMENT 1688 +#define ER_LOCK_ABORTED 1689 +#define ER_DATA_OUT_OF_RANGE 1690 +#define ER_WRONG_SPVAR_TYPE_IN_LIMIT 1691 +#define ER_BINLOG_UNSAFE_MULTIPLE_ENGINES_AND_SELF_LOGGING_ENGINE 1692 +#define ER_BINLOG_UNSAFE_MIXED_STATEMENT 1693 +#define ER_INSIDE_TRANSACTION_PREVENTS_SWITCH_SQL_LOG_BIN 1694 +#define ER_STORED_FUNCTION_PREVENTS_SWITCH_SQL_LOG_BIN 1695 +#define ER_FAILED_READ_FROM_PAR_FILE 1696 +#define ER_VALUES_IS_NOT_INT_TYPE_ERROR 1697 +#define ER_ACCESS_DENIED_NO_PASSWORD_ERROR 1698 +#define ER_SET_PASSWORD_AUTH_PLUGIN 1699 +#define ER_GRANT_PLUGIN_USER_EXISTS 1700 +#define ER_TRUNCATE_ILLEGAL_FK 1701 +#define ER_PLUGIN_IS_PERMANENT 1702 +#define ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE_MIN 1703 +#define ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE_MAX 1704 +#define ER_STMT_CACHE_FULL 1705 +#define ER_MULTI_UPDATE_KEY_CONFLICT 1706 +#define ER_TABLE_NEEDS_REBUILD 1707 +#define WARN_OPTION_BELOW_LIMIT 1708 +#define ER_INDEX_COLUMN_TOO_LONG 1709 +#define ER_ERROR_IN_TRIGGER_BODY 1710 +#define ER_ERROR_IN_UNKNOWN_TRIGGER_BODY 1711 +#define ER_INDEX_CORRUPT 1712 +#define ER_UNDO_RECORD_TOO_BIG 1713 +#define ER_BINLOG_UNSAFE_INSERT_IGNORE_SELECT 1714 +#define ER_BINLOG_UNSAFE_INSERT_SELECT_UPDATE 1715 +#define ER_BINLOG_UNSAFE_REPLACE_SELECT 1716 +#define ER_BINLOG_UNSAFE_CREATE_IGNORE_SELECT 1717 +#define ER_BINLOG_UNSAFE_CREATE_REPLACE_SELECT 1718 +#define ER_BINLOG_UNSAFE_UPDATE_IGNORE 1719 +#define ER_UNUSED_15 1720 +#define ER_UNUSED_16 1721 +#define ER_BINLOG_UNSAFE_WRITE_AUTOINC_SELECT 1722 +#define ER_BINLOG_UNSAFE_CREATE_SELECT_AUTOINC 1723 +#define ER_BINLOG_UNSAFE_INSERT_TWO_KEYS 1724 +#define ER_TABLE_IN_FK_CHECK 1725 +#define ER_UNUSED_1 1726 +#define ER_BINLOG_UNSAFE_AUTOINC_NOT_FIRST 1727 +#define ER_CANNOT_LOAD_FROM_TABLE_V2 1728 +#define ER_MASTER_DELAY_VALUE_OUT_OF_RANGE 1729 +#define ER_ONLY_FD_AND_RBR_EVENTS_ALLOWED_IN_BINLOG_STATEMENT 1730 +#define ER_PARTITION_EXCHANGE_DIFFERENT_OPTION 1731 +#define ER_PARTITION_EXCHANGE_PART_TABLE 1732 +#define ER_PARTITION_EXCHANGE_TEMP_TABLE 1733 +#define ER_PARTITION_INSTEAD_OF_SUBPARTITION 1734 +#define ER_UNKNOWN_PARTITION 1735 +#define ER_TABLES_DIFFERENT_METADATA 1736 +#define ER_ROW_DOES_NOT_MATCH_PARTITION 1737 +#define ER_BINLOG_CACHE_SIZE_GREATER_THAN_MAX 1738 +#define ER_WARN_INDEX_NOT_APPLICABLE 1739 +#define ER_PARTITION_EXCHANGE_FOREIGN_KEY 1740 +#define ER_NO_SUCH_KEY_VALUE 1741 +#define ER_VALUE_TOO_LONG 1742 +#define ER_NETWORK_READ_EVENT_CHECKSUM_FAILURE 1743 +#define ER_BINLOG_READ_EVENT_CHECKSUM_FAILURE 1744 +#define ER_BINLOG_STMT_CACHE_SIZE_GREATER_THAN_MAX 1745 +#define ER_CANT_UPDATE_TABLE_IN_CREATE_TABLE_SELECT 1746 +#define ER_PARTITION_CLAUSE_ON_NONPARTITIONED 1747 +#define ER_ROW_DOES_NOT_MATCH_GIVEN_PARTITION_SET 1748 +#define ER_UNUSED_5 1749 +#define ER_CHANGE_RPL_INFO_REPOSITORY_FAILURE 1750 +#define ER_WARNING_NOT_COMPLETE_ROLLBACK_WITH_CREATED_TEMP_TABLE 1751 +#define ER_WARNING_NOT_COMPLETE_ROLLBACK_WITH_DROPPED_TEMP_TABLE 1752 +#define ER_MTS_FEATURE_IS_NOT_SUPPORTED 1753 +#define ER_MTS_UPDATED_DBS_GREATER_MAX 1754 +#define ER_MTS_CANT_PARALLEL 1755 +#define ER_MTS_INCONSISTENT_DATA 1756 +#define ER_FULLTEXT_NOT_SUPPORTED_WITH_PARTITIONING 1757 +#define ER_DA_INVALID_CONDITION_NUMBER 1758 +#define ER_INSECURE_PLAIN_TEXT 1759 +#define ER_INSECURE_CHANGE_MASTER 1760 +#define ER_FOREIGN_DUPLICATE_KEY_WITH_CHILD_INFO 1761 +#define ER_FOREIGN_DUPLICATE_KEY_WITHOUT_CHILD_INFO 1762 +#define ER_SQLTHREAD_WITH_SECURE_SLAVE 1763 +#define ER_TABLE_HAS_NO_FT 1764 +#define ER_VARIABLE_NOT_SETTABLE_IN_SF_OR_TRIGGER 1765 +#define ER_VARIABLE_NOT_SETTABLE_IN_TRANSACTION 1766 +#define ER_GTID_NEXT_IS_NOT_IN_GTID_NEXT_LIST 1767 +#define ER_CANT_CHANGE_GTID_NEXT_IN_TRANSACTION_WHEN_GTID_NEXT_LIST_IS_NULL 1768 +#define ER_SET_STATEMENT_CANNOT_INVOKE_FUNCTION 1769 +#define ER_GTID_NEXT_CANT_BE_AUTOMATIC_IF_GTID_NEXT_LIST_IS_NON_NULL 1770 +#define ER_SKIPPING_LOGGED_TRANSACTION 1771 +#define ER_MALFORMED_GTID_SET_SPECIFICATION 1772 +#define ER_MALFORMED_GTID_SET_ENCODING 1773 +#define ER_MALFORMED_GTID_SPECIFICATION 1774 +#define ER_GNO_EXHAUSTED 1775 +#define ER_BAD_SLAVE_AUTO_POSITION 1776 +#define ER_AUTO_POSITION_REQUIRES_GTID_MODE_ON 1777 +#define ER_CANT_DO_IMPLICIT_COMMIT_IN_TRX_WHEN_GTID_NEXT_IS_SET 1778 +#define ER_GTID_MODE_2_OR_3_REQUIRES_ENFORCE_GTID_CONSISTENCY_ON 1779 +#define ER_GTID_MODE_REQUIRES_BINLOG 1780 +#define ER_CANT_SET_GTID_NEXT_TO_GTID_WHEN_GTID_MODE_IS_OFF 1781 +#define ER_CANT_SET_GTID_NEXT_TO_ANONYMOUS_WHEN_GTID_MODE_IS_ON 1782 +#define ER_CANT_SET_GTID_NEXT_LIST_TO_NON_NULL_WHEN_GTID_MODE_IS_OFF 1783 +#define ER_FOUND_GTID_EVENT_WHEN_GTID_MODE_IS_OFF 1784 +#define ER_GTID_UNSAFE_NON_TRANSACTIONAL_TABLE 1785 +#define ER_GTID_UNSAFE_CREATE_SELECT 1786 +#define ER_GTID_UNSAFE_CREATE_DROP_TEMPORARY_TABLE_IN_TRANSACTION 1787 +#define ER_GTID_MODE_CAN_ONLY_CHANGE_ONE_STEP_AT_A_TIME 1788 +#define ER_MASTER_HAS_PURGED_REQUIRED_GTIDS 1789 +#define ER_CANT_SET_GTID_NEXT_WHEN_OWNING_GTID 1790 +#define ER_UNKNOWN_EXPLAIN_FORMAT 1791 +#define ER_CANT_EXECUTE_IN_READ_ONLY_TRANSACTION 1792 +#define ER_TOO_LONG_TABLE_PARTITION_COMMENT 1793 +#define ER_SLAVE_CONFIGURATION 1794 +#define ER_INNODB_FT_LIMIT 1795 +#define ER_INNODB_NO_FT_TEMP_TABLE 1796 +#define ER_INNODB_FT_WRONG_DOCID_COLUMN 1797 +#define ER_INNODB_FT_WRONG_DOCID_INDEX 1798 +#define ER_INNODB_ONLINE_LOG_TOO_BIG 1799 +#define ER_UNKNOWN_ALTER_ALGORITHM 1800 +#define ER_UNKNOWN_ALTER_LOCK 1801 +#define ER_MTS_CHANGE_MASTER_CANT_RUN_WITH_GAPS 1802 +#define ER_MTS_RECOVERY_FAILURE 1803 +#define ER_MTS_RESET_WORKERS 1804 +#define ER_COL_COUNT_DOESNT_MATCH_CORRUPTED_V2 1805 +#define ER_SLAVE_SILENT_RETRY_TRANSACTION 1806 +#define ER_UNUSED_22 1807 +#define ER_TABLE_SCHEMA_MISMATCH 1808 +#define ER_TABLE_IN_SYSTEM_TABLESPACE 1809 +#define ER_IO_READ_ERROR 1810 +#define ER_IO_WRITE_ERROR 1811 +#define ER_TABLESPACE_MISSING 1812 +#define ER_TABLESPACE_EXISTS 1813 +#define ER_TABLESPACE_DISCARDED 1814 +#define ER_INTERNAL_ERROR 1815 +#define ER_INNODB_IMPORT_ERROR 1816 +#define ER_INNODB_INDEX_CORRUPT 1817 +#define ER_INVALID_YEAR_COLUMN_LENGTH 1818 +#define ER_NOT_VALID_PASSWORD 1819 +#define ER_MUST_CHANGE_PASSWORD 1820 +#define ER_FK_NO_INDEX_CHILD 1821 +#define ER_FK_NO_INDEX_PARENT 1822 +#define ER_FK_FAIL_ADD_SYSTEM 1823 +#define ER_FK_CANNOT_OPEN_PARENT 1824 +#define ER_FK_INCORRECT_OPTION 1825 +#define ER_DUP_CONSTRAINT_NAME 1826 +#define ER_PASSWORD_FORMAT 1827 +#define ER_FK_COLUMN_CANNOT_DROP 1828 +#define ER_FK_COLUMN_CANNOT_DROP_CHILD 1829 +#define ER_FK_COLUMN_NOT_NULL 1830 +#define ER_DUP_INDEX 1831 +#define ER_FK_COLUMN_CANNOT_CHANGE 1832 +#define ER_FK_COLUMN_CANNOT_CHANGE_CHILD 1833 +#define ER_FK_CANNOT_DELETE_PARENT 1834 +#define ER_MALFORMED_PACKET 1835 +#define ER_READ_ONLY_MODE 1836 +#define ER_GTID_NEXT_TYPE_UNDEFINED_GROUP 1837 +#define ER_VARIABLE_NOT_SETTABLE_IN_SP 1838 +#define ER_CANT_SET_GTID_PURGED_WHEN_GTID_MODE_IS_OFF 1839 +#define ER_CANT_SET_GTID_PURGED_WHEN_GTID_EXECUTED_IS_NOT_EMPTY 1840 +#define ER_CANT_SET_GTID_PURGED_WHEN_OWNED_GTIDS_IS_NOT_EMPTY 1841 +#define ER_GTID_PURGED_WAS_CHANGED 1842 +#define ER_GTID_EXECUTED_WAS_CHANGED 1843 +#define ER_BINLOG_STMT_MODE_AND_NO_REPL_TABLES 1844 +#define ER_ALTER_OPERATION_NOT_SUPPORTED 1845 +#define ER_ALTER_OPERATION_NOT_SUPPORTED_REASON 1846 +#define ER_ALTER_OPERATION_NOT_SUPPORTED_REASON_COPY 1847 +#define ER_ALTER_OPERATION_NOT_SUPPORTED_REASON_PARTITION 1848 +#define ER_ALTER_OPERATION_NOT_SUPPORTED_REASON_FK_RENAME 1849 +#define ER_ALTER_OPERATION_NOT_SUPPORTED_REASON_COLUMN_TYPE 1850 +#define ER_ALTER_OPERATION_NOT_SUPPORTED_REASON_FK_CHECK 1851 +#define ER_ALTER_OPERATION_NOT_SUPPORTED_REASON_IGNORE 1852 +#define ER_ALTER_OPERATION_NOT_SUPPORTED_REASON_NOPK 1853 +#define ER_ALTER_OPERATION_NOT_SUPPORTED_REASON_AUTOINC 1854 +#define ER_ALTER_OPERATION_NOT_SUPPORTED_REASON_HIDDEN_FTS 1855 +#define ER_ALTER_OPERATION_NOT_SUPPORTED_REASON_CHANGE_FTS 1856 +#define ER_ALTER_OPERATION_NOT_SUPPORTED_REASON_FTS 1857 +#define ER_SQL_SLAVE_SKIP_COUNTER_NOT_SETTABLE_IN_GTID_MODE 1858 +#define ER_DUP_UNKNOWN_IN_INDEX 1859 +#define ER_IDENT_CAUSES_TOO_LONG_PATH 1860 +#define ER_ALTER_OPERATION_NOT_SUPPORTED_REASON_NOT_NULL 1861 +#define ER_MUST_CHANGE_PASSWORD_LOGIN 1862 +#define ER_ROW_IN_WRONG_PARTITION 1863 +#define ER_MTS_EVENT_BIGGER_PENDING_JOBS_SIZE_MAX 1864 +#define ER_INNODB_NO_FT_USES_PARSER 1865 +#define ER_BINLOG_LOGICAL_CORRUPTION 1866 +#define ER_WARN_PURGE_LOG_IN_USE 1867 +#define ER_WARN_PURGE_LOG_IS_ACTIVE 1868 +#define ER_AUTO_INCREMENT_CONFLICT 1869 +#define WARN_ON_BLOCKHOLE_IN_RBR 1870 +#define ER_SLAVE_MI_INIT_REPOSITORY 1871 +#define ER_SLAVE_RLI_INIT_REPOSITORY 1872 +#define ER_ACCESS_DENIED_CHANGE_USER_ERROR 1873 +#define ER_INNODB_READ_ONLY 1874 +#define ER_STOP_SLAVE_SQL_THREAD_TIMEOUT 1875 +#define ER_STOP_SLAVE_IO_THREAD_TIMEOUT 1876 +#define ER_TABLE_CORRUPT 1877 +#define ER_TEMP_FILE_WRITE_FAILURE 1878 +#define ER_INNODB_FT_AUX_NOT_HEX_ID 1879 +#define ER_LAST_MYSQL_ERROR_MESSAGE 1880 +#define ER_ERROR_LAST_SECTION_1 1880 + +/* New section */ + +#define ER_ERROR_FIRST_SECTION_2 1900 +#define ER_UNUSED_18 1900 +#define ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED 1901 +#define ER_UNUSED_19 1902 +#define ER_PRIMARY_KEY_BASED_ON_GENERATED_COLUMN 1903 +#define ER_KEY_BASED_ON_GENERATED_VIRTUAL_COLUMN 1904 +#define ER_WRONG_FK_OPTION_FOR_GENERATED_COLUMN 1905 +#define ER_WARNING_NON_DEFAULT_VALUE_FOR_GENERATED_COLUMN 1906 +#define ER_UNSUPPORTED_ACTION_ON_GENERATED_COLUMN 1907 +#define ER_UNUSED_20 1908 +#define ER_UNUSED_21 1909 +#define ER_UNSUPPORTED_ENGINE_FOR_GENERATED_COLUMNS 1910 +#define ER_UNKNOWN_OPTION 1911 +#define ER_BAD_OPTION_VALUE 1912 +#define ER_UNUSED_6 1913 +#define ER_UNUSED_7 1914 +#define ER_UNUSED_8 1915 +#define ER_DATA_OVERFLOW 1916 +#define ER_DATA_TRUNCATED 1917 +#define ER_BAD_DATA 1918 +#define ER_DYN_COL_WRONG_FORMAT 1919 +#define ER_DYN_COL_IMPLEMENTATION_LIMIT 1920 +#define ER_DYN_COL_DATA 1921 +#define ER_DYN_COL_WRONG_CHARSET 1922 +#define ER_ILLEGAL_SUBQUERY_OPTIMIZER_SWITCHES 1923 +#define ER_QUERY_CACHE_IS_DISABLED 1924 +#define ER_QUERY_CACHE_IS_GLOBALY_DISABLED 1925 +#define ER_VIEW_ORDERBY_IGNORED 1926 +#define ER_CONNECTION_KILLED 1927 +#define ER_UNUSED_12 1928 +#define ER_INSIDE_TRANSACTION_PREVENTS_SWITCH_SKIP_REPLICATION 1929 +#define ER_STORED_FUNCTION_PREVENTS_SWITCH_SKIP_REPLICATION 1930 +#define ER_QUERY_EXCEEDED_ROWS_EXAMINED_LIMIT 1931 +#define ER_NO_SUCH_TABLE_IN_ENGINE 1932 +#define ER_TARGET_NOT_EXPLAINABLE 1933 +#define ER_CONNECTION_ALREADY_EXISTS 1934 +#define ER_MASTER_LOG_PREFIX 1935 +#define ER_CANT_START_STOP_SLAVE 1936 +#define ER_SLAVE_STARTED 1937 +#define ER_SLAVE_STOPPED 1938 +#define ER_SQL_DISCOVER_ERROR 1939 +#define ER_FAILED_GTID_STATE_INIT 1940 +#define ER_INCORRECT_GTID_STATE 1941 +#define ER_CANNOT_UPDATE_GTID_STATE 1942 +#define ER_DUPLICATE_GTID_DOMAIN 1943 +#define ER_GTID_OPEN_TABLE_FAILED 1944 +#define ER_GTID_POSITION_NOT_FOUND_IN_BINLOG 1945 +#define ER_CANNOT_LOAD_SLAVE_GTID_STATE 1946 +#define ER_MASTER_GTID_POS_CONFLICTS_WITH_BINLOG 1947 +#define ER_MASTER_GTID_POS_MISSING_DOMAIN 1948 +#define ER_UNTIL_REQUIRES_USING_GTID 1949 +#define ER_GTID_STRICT_OUT_OF_ORDER 1950 +#define ER_GTID_START_FROM_BINLOG_HOLE 1951 +#define ER_SLAVE_UNEXPECTED_MASTER_SWITCH 1952 +#define ER_INSIDE_TRANSACTION_PREVENTS_SWITCH_GTID_DOMAIN_ID_SEQ_NO 1953 +#define ER_STORED_FUNCTION_PREVENTS_SWITCH_GTID_DOMAIN_ID_SEQ_NO 1954 +#define ER_GTID_POSITION_NOT_FOUND_IN_BINLOG2 1955 +#define ER_BINLOG_MUST_BE_EMPTY 1956 +#define ER_NO_SUCH_QUERY 1957 +#define ER_BAD_BASE64_DATA 1958 +#define ER_INVALID_ROLE 1959 +#define ER_INVALID_CURRENT_USER 1960 +#define ER_CANNOT_GRANT_ROLE 1961 +#define ER_CANNOT_REVOKE_ROLE 1962 +#define ER_CHANGE_SLAVE_PARALLEL_THREADS_ACTIVE 1963 +#define ER_PRIOR_COMMIT_FAILED 1964 +#define ER_IT_IS_A_VIEW 1965 +#define ER_SLAVE_SKIP_NOT_IN_GTID 1966 +#define ER_TABLE_DEFINITION_TOO_BIG 1967 +#define ER_PLUGIN_INSTALLED 1968 +#define ER_STATEMENT_TIMEOUT 1969 +#define ER_SUBQUERIES_NOT_SUPPORTED 1970 +#define ER_SET_STATEMENT_NOT_SUPPORTED 1971 +#define ER_UNUSED_9 1972 +#define ER_USER_CREATE_EXISTS 1973 +#define ER_USER_DROP_EXISTS 1974 +#define ER_ROLE_CREATE_EXISTS 1975 +#define ER_ROLE_DROP_EXISTS 1976 +#define ER_CANNOT_CONVERT_CHARACTER 1977 +#define ER_INVALID_DEFAULT_VALUE_FOR_FIELD 1978 +#define ER_KILL_QUERY_DENIED_ERROR 1979 +#define ER_NO_EIS_FOR_FIELD 1980 +#define ER_WARN_AGGFUNC_DEPENDENCE 1981 +#define WARN_INNODB_PARTITION_OPTION_IGNORED 1982 +#define ER_ERROR_LAST_SECTION_2 1982 + +/* New section */ + +#define ER_ERROR_FIRST_SECTION_3 2000 +#define ER_ERROR_LAST_SECTION_3 2000 + +/* New section */ + +#define ER_ERROR_FIRST_SECTION_4 3000 +#define ER_FILE_CORRUPT 3000 +#define ER_ERROR_ON_MASTER 3001 +#define ER_INCONSISTENT_ERROR 3002 +#define ER_STORAGE_ENGINE_NOT_LOADED 3003 +#define ER_GET_STACKED_DA_WITHOUT_ACTIVE_HANDLER 3004 +#define ER_WARN_LEGACY_SYNTAX_CONVERTED 3005 +#define ER_BINLOG_UNSAFE_FULLTEXT_PLUGIN 3006 +#define ER_CANNOT_DISCARD_TEMPORARY_TABLE 3007 +#define ER_FK_DEPTH_EXCEEDED 3008 +#define ER_COL_COUNT_DOESNT_MATCH_PLEASE_UPDATE_V2 3009 +#define ER_WARN_TRIGGER_DOESNT_HAVE_CREATED 3010 +#define ER_REFERENCED_TRG_DOES_NOT_EXIST_MYSQL 3011 +#define ER_EXPLAIN_NOT_SUPPORTED 3012 +#define ER_INVALID_FIELD_SIZE 3013 +#define ER_MISSING_HA_CREATE_OPTION 3014 +#define ER_ENGINE_OUT_OF_MEMORY 3015 +#define ER_PASSWORD_EXPIRE_ANONYMOUS_USER 3016 +#define ER_SLAVE_SQL_THREAD_MUST_STOP 3017 +#define ER_NO_FT_MATERIALIZED_SUBQUERY 3018 +#define ER_INNODB_UNDO_LOG_FULL 3019 +#define ER_INVALID_ARGUMENT_FOR_LOGARITHM 3020 +#define ER_SLAVE_CHANNEL_IO_THREAD_MUST_STOP 3021 +#define ER_WARN_OPEN_TEMP_TABLES_MUST_BE_ZERO 3022 +#define ER_WARN_ONLY_MASTER_LOG_FILE_NO_POS 3023 +#define ER_QUERY_TIMEOUT 3024 +#define ER_NON_RO_SELECT_DISABLE_TIMER 3025 +#define ER_DUP_LIST_ENTRY 3026 +#define ER_SQL_MODE_NO_EFFECT 3027 +#define ER_AGGREGATE_ORDER_FOR_UNION 3028 +#define ER_AGGREGATE_ORDER_NON_AGG_QUERY 3029 +#define ER_SLAVE_WORKER_STOPPED_PREVIOUS_THD_ERROR 3030 +#define ER_DONT_SUPPORT_SLAVE_PRESERVE_COMMIT_ORDER 3031 +#define ER_SERVER_OFFLINE_MODE 3032 +#define ER_GIS_DIFFERENT_SRIDS 3033 +#define ER_GIS_UNSUPPORTED_ARGUMENT 3034 +#define ER_GIS_UNKNOWN_ERROR 3035 +#define ER_GIS_UNKNOWN_EXCEPTION 3036 +#define ER_GIS_INVALID_DATA 3037 +#define ER_BOOST_GEOMETRY_EMPTY_INPUT_EXCEPTION 3038 +#define ER_BOOST_GEOMETRY_CENTROID_EXCEPTION 3039 +#define ER_BOOST_GEOMETRY_OVERLAY_INVALID_INPUT_EXCEPTION 3040 +#define ER_BOOST_GEOMETRY_TURN_INFO_EXCEPTION 3041 +#define ER_BOOST_GEOMETRY_SELF_INTERSECTION_POINT_EXCEPTION 3042 +#define ER_BOOST_GEOMETRY_UNKNOWN_EXCEPTION 3043 +#define ER_STD_BAD_ALLOC_ERROR 3044 +#define ER_STD_DOMAIN_ERROR 3045 +#define ER_STD_LENGTH_ERROR 3046 +#define ER_STD_INVALID_ARGUMENT 3047 +#define ER_STD_OUT_OF_RANGE_ERROR 3048 +#define ER_STD_OVERFLOW_ERROR 3049 +#define ER_STD_RANGE_ERROR 3050 +#define ER_STD_UNDERFLOW_ERROR 3051 +#define ER_STD_LOGIC_ERROR 3052 +#define ER_STD_RUNTIME_ERROR 3053 +#define ER_STD_UNKNOWN_EXCEPTION 3054 +#define ER_GIS_DATA_WRONG_ENDIANESS 3055 +#define ER_CHANGE_MASTER_PASSWORD_LENGTH 3056 +#define ER_USER_LOCK_WRONG_NAME 3057 +#define ER_USER_LOCK_DEADLOCK 3058 +#define ER_REPLACE_INACCESSIBLE_ROWS 3059 +#define ER_ALTER_OPERATION_NOT_SUPPORTED_REASON_GIS 3060 +#define ER_ERROR_LAST_SECTION_4 3060 + +/* New section */ + +#define ER_ERROR_FIRST_SECTION_5 4000 +#define ER_COMMULTI_BADCONTEXT 4000 +#define ER_BAD_COMMAND_IN_MULTI 4001 +#define ER_WITH_COL_WRONG_LIST 4002 +#define ER_TOO_MANY_DEFINITIONS_IN_WITH_CLAUSE 4003 +#define ER_DUP_QUERY_NAME 4004 +#define ER_RECURSIVE_WITHOUT_ANCHORS 4005 +#define ER_UNACCEPTABLE_MUTUAL_RECURSION 4006 +#define ER_REF_TO_RECURSIVE_WITH_TABLE_IN_DERIVED 4007 +#define ER_NOT_STANDARD_COMPLIANT_RECURSIVE 4008 +#define ER_WRONG_WINDOW_SPEC_NAME 4009 +#define ER_DUP_WINDOW_NAME 4010 +#define ER_PARTITION_LIST_IN_REFERENCING_WINDOW_SPEC 4011 +#define ER_ORDER_LIST_IN_REFERENCING_WINDOW_SPEC 4012 +#define ER_WINDOW_FRAME_IN_REFERENCED_WINDOW_SPEC 4013 +#define ER_BAD_COMBINATION_OF_WINDOW_FRAME_BOUND_SPECS 4014 +#define ER_WRONG_PLACEMENT_OF_WINDOW_FUNCTION 4015 +#define ER_WINDOW_FUNCTION_IN_WINDOW_SPEC 4016 +#define ER_NOT_ALLOWED_WINDOW_FRAME 4017 +#define ER_NO_ORDER_LIST_IN_WINDOW_SPEC 4018 +#define ER_RANGE_FRAME_NEEDS_SIMPLE_ORDERBY 4019 +#define ER_WRONG_TYPE_FOR_ROWS_FRAME 4020 +#define ER_WRONG_TYPE_FOR_RANGE_FRAME 4021 +#define ER_FRAME_EXCLUSION_NOT_SUPPORTED 4022 +#define ER_WINDOW_FUNCTION_DONT_HAVE_FRAME 4023 +#define ER_INVALID_NTILE_ARGUMENT 4024 +#define ER_CONSTRAINT_FAILED 4025 +#define ER_EXPRESSION_IS_TOO_BIG 4026 +#define ER_ERROR_EVALUATING_EXPRESSION 4027 +#define ER_CALCULATING_DEFAULT_VALUE 4028 +#define ER_EXPRESSION_REFERS_TO_UNINIT_FIELD 4029 +#define ER_PARTITION_DEFAULT_ERROR 4030 +#define ER_REFERENCED_TRG_DOES_NOT_EXIST 4031 +#define ER_INVALID_DEFAULT_PARAM 4032 +#define ER_BINLOG_NON_SUPPORTED_BULK 4033 +#define ER_BINLOG_UNCOMPRESS_ERROR 4034 +#define ER_JSON_BAD_CHR 4035 +#define ER_JSON_NOT_JSON_CHR 4036 +#define ER_JSON_EOS 4037 +#define ER_JSON_SYNTAX 4038 +#define ER_JSON_ESCAPING 4039 +#define ER_JSON_DEPTH 4040 +#define ER_JSON_PATH_EOS 4041 +#define ER_JSON_PATH_SYNTAX 4042 +#define ER_JSON_PATH_DEPTH 4043 +#define ER_JSON_PATH_NO_WILDCARD 4044 +#define ER_JSON_PATH_ARRAY 4045 +#define ER_JSON_ONE_OR_ALL 4046 +#define ER_UNSUPPORT_COMPRESSED_TEMPORARY_TABLE 4047 +#define ER_GEOJSON_INCORRECT 4048 +#define ER_GEOJSON_TOO_FEW_POINTS 4049 +#define ER_GEOJSON_NOT_CLOSED 4050 +#define ER_JSON_PATH_EMPTY 4051 +#define ER_SLAVE_SAME_ID 4052 +#define ER_FLASHBACK_NOT_SUPPORTED 4053 +#define ER_KEYS_OUT_OF_ORDER 4054 +#define ER_OVERLAPPING_KEYS 4055 +#define ER_REQUIRE_ROW_BINLOG_FORMAT 4056 +#define ER_ISOLATION_MODE_NOT_SUPPORTED 4057 +#define ER_ON_DUPLICATE_DISABLED 4058 +#define ER_UPDATES_WITH_CONSISTENT_SNAPSHOT 4059 +#define ER_ROLLBACK_ONLY 4060 +#define ER_ROLLBACK_TO_SAVEPOINT 4061 +#define ER_ISOLATION_LEVEL_WITH_CONSISTENT_SNAPSHOT 4062 +#define ER_UNSUPPORTED_COLLATION 4063 +#define ER_METADATA_INCONSISTENCY 4064 +#define ER_CF_DIFFERENT 4065 +#define ER_RDB_TTL_DURATION_FORMAT 4066 +#define ER_RDB_STATUS_GENERAL 4067 +#define ER_RDB_STATUS_MSG 4068 +#define ER_RDB_TTL_UNSUPPORTED 4069 +#define ER_RDB_TTL_COL_FORMAT 4070 +#define ER_PER_INDEX_CF_DEPRECATED 4071 +#define ER_KEY_CREATE_DURING_ALTER 4072 +#define ER_SK_POPULATE_DURING_ALTER 4073 +#define ER_SUM_FUNC_WITH_WINDOW_FUNC_AS_ARG 4074 +#define ER_NET_OK_PACKET_TOO_LARGE 4075 +#define ER_GEOJSON_EMPTY_COORDINATES 4076 +#define ER_MYROCKS_CANT_NOPAD_COLLATION 4077 +#define ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION 4078 +#define ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION 4079 +#define ER_WRONG_PARAMCOUNT_TO_CURSOR 4080 +#define ER_UNKNOWN_STRUCTURED_VARIABLE 4081 +#define ER_ROW_VARIABLE_DOES_NOT_HAVE_FIELD 4082 +#define ER_END_IDENTIFIER_DOES_NOT_MATCH 4083 +#define ER_SEQUENCE_RUN_OUT 4084 +#define ER_SEQUENCE_INVALID_DATA 4085 +#define ER_SEQUENCE_INVALID_TABLE_STRUCTURE 4086 +#define ER_SEQUENCE_ACCESS_ERROR 4087 +#define ER_SEQUENCE_BINLOG_FORMAT 4088 +#define ER_NOT_SEQUENCE 4089 +#define ER_NOT_SEQUENCE2 4090 +#define ER_UNKNOWN_SEQUENCES 4091 +#define ER_UNKNOWN_VIEW 4092 +#define ER_WRONG_INSERT_INTO_SEQUENCE 4093 +#define ER_SP_STACK_TRACE 4094 +#define ER_PACKAGE_ROUTINE_IN_SPEC_NOT_DEFINED_IN_BODY 4095 +#define ER_PACKAGE_ROUTINE_FORWARD_DECLARATION_NOT_DEFINED 4096 +#define ER_COMPRESSED_COLUMN_USED_AS_KEY 4097 +#define ER_UNKNOWN_COMPRESSION_METHOD 4098 +#define ER_WRONG_NUMBER_OF_VALUES_IN_TVC 4099 +#define ER_FIELD_REFERENCE_IN_TVC 4100 +#define ER_WRONG_TYPE_FOR_PERCENTILE_FUNC 4101 +#define ER_ARGUMENT_NOT_CONSTANT 4102 +#define ER_ARGUMENT_OUT_OF_RANGE 4103 +#define ER_WRONG_TYPE_OF_ARGUMENT 4104 +#define ER_NOT_AGGREGATE_FUNCTION 4105 +#define ER_INVALID_AGGREGATE_FUNCTION 4106 +#define ER_INVALID_VALUE_TO_LIMIT 4107 +#define ER_INVISIBLE_NOT_NULL_WITHOUT_DEFAULT 4108 +#define ER_UPDATE_INFO_WITH_SYSTEM_VERSIONING 4109 +#define ER_VERS_FIELD_WRONG_TYPE 4110 +#define ER_VERS_ENGINE_UNSUPPORTED 4111 +#define ER_UNUSED_23 4112 +#define ER_PARTITION_WRONG_TYPE 4113 +#define WARN_VERS_PART_FULL 4114 +#define WARN_VERS_PARAMETERS 4115 +#define ER_VERS_DROP_PARTITION_INTERVAL 4116 +#define ER_UNUSED_25 4117 +#define WARN_VERS_PART_NON_HISTORICAL 4118 +#define ER_VERS_ALTER_NOT_ALLOWED 4119 +#define ER_VERS_ALTER_ENGINE_PROHIBITED 4120 +#define ER_VERS_RANGE_PROHIBITED 4121 +#define ER_CONFLICTING_FOR_SYSTEM_TIME 4122 +#define ER_VERS_TABLE_MUST_HAVE_COLUMNS 4123 +#define ER_VERS_NOT_VERSIONED 4124 +#define ER_MISSING 4125 +#define ER_VERS_PERIOD_COLUMNS 4126 +#define ER_PART_WRONG_VALUE 4127 +#define ER_VERS_WRONG_PARTS 4128 +#define ER_VERS_NO_TRX_ID 4129 +#define ER_VERS_ALTER_SYSTEM_FIELD 4130 +#define ER_DROP_VERSIONING_SYSTEM_TIME_PARTITION 4131 +#define ER_VERS_DB_NOT_SUPPORTED 4132 +#define ER_VERS_TRT_IS_DISABLED 4133 +#define ER_VERS_DUPLICATE_ROW_START_END 4134 +#define ER_VERS_ALREADY_VERSIONED 4135 +#define ER_UNUSED_24 4136 +#define ER_VERS_NOT_SUPPORTED 4137 +#define ER_VERS_TRX_PART_HISTORIC_ROW_NOT_SUPPORTED 4138 +#define ER_INDEX_FILE_FULL 4139 +#define ER_UPDATED_COLUMN_ONLY_ONCE 4140 +#define ER_EMPTY_ROW_IN_TVC 4141 +#define ER_VERS_QUERY_IN_PARTITION 4142 +#define ER_KEY_DOESNT_SUPPORT 4143 +#define ER_ALTER_OPERATION_TABLE_OPTIONS_NEED_REBUILD 4144 +#define ER_BACKUP_LOCK_IS_ACTIVE 4145 +#define ER_BACKUP_NOT_RUNNING 4146 +#define ER_BACKUP_WRONG_STAGE 4147 +#define ER_BACKUP_STAGE_FAILED 4148 +#define ER_BACKUP_UNKNOWN_STAGE 4149 +#define ER_USER_IS_BLOCKED 4150 +#define ER_ACCOUNT_HAS_BEEN_LOCKED 4151 +#define ER_PERIOD_TEMPORARY_NOT_ALLOWED 4152 +#define ER_PERIOD_TYPES_MISMATCH 4153 +#define ER_MORE_THAN_ONE_PERIOD 4154 +#define ER_PERIOD_FIELD_WRONG_ATTRIBUTES 4155 +#define ER_PERIOD_NOT_FOUND 4156 +#define ER_PERIOD_COLUMNS_UPDATED 4157 +#define ER_PERIOD_CONSTRAINT_DROP 4158 +#define ER_TOO_LONG_KEYPART 4159 +#define ER_TOO_LONG_DATABASE_COMMENT 4160 +#define ER_UNKNOWN_DATA_TYPE 4161 +#define ER_UNKNOWN_OPERATOR 4162 +#define ER_WARN_HISTORY_ROW_START_TIME 4163 +#define ER_PART_STARTS_BEYOND_INTERVAL 4164 +#define ER_GALERA_REPLICATION_NOT_SUPPORTED 4165 +#define ER_LOAD_INFILE_CAPABILITY_DISABLED 4166 +#define ER_NO_SECURE_TRANSPORTS_CONFIGURED 4167 +#define ER_SLAVE_IGNORED_SHARED_TABLE 4168 +#define ER_NO_AUTOINCREMENT_WITH_UNIQUE 4169 +#define ER_KEY_CONTAINS_PERIOD_FIELDS 4170 +#define ER_KEY_CANT_HAVE_WITHOUT_OVERLAPS 4171 +#define ER_NOT_ALLOWED_IN_THIS_CONTEXT 4172 +#define ER_DATA_WAS_COMMITED_UNDER_ROLLBACK 4173 +#define ER_ERROR_LAST 4173 +#endif /* ER_ERROR_FIRST */ diff --git a/vendor/MDBC/libmariadb/CMakeLists.txt b/vendor/MDBC/libmariadb/CMakeLists.txt new file mode 100644 index 00000000..cf96b9e9 --- /dev/null +++ b/vendor/MDBC/libmariadb/CMakeLists.txt @@ -0,0 +1,470 @@ +INCLUDE_DIRECTORIES(${CC_SOURCE_DIR}/include + ${CC_SOURCE_DIR}/libmariadb) + +ADD_DEFINITIONS(-D HAVE_COMPRESS) +ADD_DEFINITIONS(-D LIBMARIADB) +ADD_DEFINITIONS(-D THREAD) + +INCLUDE(${CC_SOURCE_DIR}/cmake/sign.cmake) + +SET(MARIADB_LIB_SYMBOLS + mariadb_cancel + mariadb_connection + mariadb_convert_string + ma_pvio_register_callback + mariadb_get_charset_by_name + mariadb_stmt_execute_direct + mariadb_get_charset_by_nr + mariadb_get_info + mariadb_get_infov + mysql_get_timeout_value + mysql_get_timeout_value_ms + mysql_optionsv + mysql_ps_fetch_functions + mariadb_reconnect + mysql_stmt_warning_count + mariadb_stmt_fetch_fields + mariadb_rpl_open + mariadb_rpl_close + mariadb_rpl_fetch + mariadb_rpl_optionsv + mariadb_rpl_get_optionsv + mariadb_rpl_init_ex + mariadb_free_rpl_event + mariadb_field_attr +) +IF(WITH_SSL) + SET(MARIADB_LIB_SYMBOLS ${MARIADB_LIB_SYMBOLS} mariadb_deinitialize_ssl) +ENDIF() + +SET(MYSQL_LIB_SYMBOLS + mysql_affected_rows + mysql_autocommit + mysql_change_user + mysql_character_set_name + mysql_client_find_plugin + mysql_client_register_plugin + mysql_close + mysql_commit + mysql_data_seek + mysql_debug + mysql_dump_debug_info + mysql_embedded + mysql_eof + mysql_errno + mysql_error + mysql_escape_string + mysql_fetch_field + mysql_fetch_field_direct + mysql_fetch_fields + mysql_fetch_lengths + mysql_fetch_row + mysql_field_count + mysql_field_seek + mysql_field_tell + mysql_free_result + mysql_get_character_set_info + mysql_get_charset_by_name + mysql_get_charset_by_nr + mysql_get_client_info + mysql_get_client_version + mysql_get_host_info + mysql_get_option + mysql_get_optionv + mysql_get_parameters + mysql_get_proto_info + mysql_get_server_info + mysql_get_server_name + mysql_get_server_version + mysql_get_socket + mysql_get_ssl_cipher + mysql_hex_string + mysql_info + mysql_init + mysql_insert_id + mysql_kill + mysql_list_dbs + mysql_list_fields + mysql_list_processes + mysql_list_tables + mysql_load_plugin + mysql_load_plugin_v + mysql_more_results + mysql_net_field_length + mysql_net_read_packet + mysql_next_result + mysql_num_fields + mysql_num_rows + mysql_options + mysql_options4 + mysql_ping + mysql_query + mysql_read_query_result + mysql_real_connect + mysql_real_escape_string + mysql_real_query + mysql_refresh + mysql_reset_connection + mysql_rollback + mysql_row_seek + mysql_row_tell + mysql_select_db + mysql_send_query + mysql_server_end + mysql_server_init + mysql_session_track_get_next + mysql_session_track_get_first + mysql_set_character_set + mysql_set_local_infile_default + mysql_set_local_infile_handler + mysql_set_server_option + mysql_shutdown + mysql_sqlstate + mysql_ssl_set + mysql_stat + mysql_stmt_affected_rows + mysql_stmt_attr_get + mysql_stmt_attr_set + mysql_stmt_bind_param + mysql_stmt_bind_result + mysql_stmt_close + mysql_stmt_data_seek + mysql_stmt_errno + mysql_stmt_error + mysql_stmt_execute + mysql_stmt_fetch + mysql_stmt_fetch_column + mysql_stmt_field_count + mysql_stmt_free_result + mysql_stmt_init + mysql_stmt_insert_id + mysql_stmt_more_results + mysql_stmt_next_result + mysql_stmt_num_rows + mysql_stmt_param_count + mysql_stmt_param_metadata + mysql_stmt_prepare + mysql_stmt_reset + mysql_stmt_result_metadata + mysql_stmt_row_seek + mysql_stmt_row_tell + mysql_stmt_send_long_data + mysql_stmt_sqlstate + mysql_stmt_store_result + mysql_store_result + mysql_thread_end + mysql_thread_id + mysql_thread_init + mysql_thread_safe + mysql_use_result + mysql_warning_count) + +# some gcc versions fail to compile asm parts of my_context.c, +# if build type is "Release" (see CONC-133), so we need to add -g flag +IF(CMAKE_COMPILER_IS_GNUCC AND CMAKE_BUILD_TYPE MATCHES "Release") + SET_SOURCE_FILES_PROPERTIES(my_context.c PROPERTIES COMPILE_FLAGS -g) +ENDIF() + +SET(MARIADB_DYNCOL_SYMBOLS + mariadb_dyncol_check + mariadb_dyncol_column_cmp_named + mariadb_dyncol_column_count + mariadb_dyncol_create_many_named + mariadb_dyncol_create_many_num + mariadb_dyncol_exists_named + mariadb_dyncol_exists_num + mariadb_dyncol_free + mariadb_dyncol_get_named + mariadb_dyncol_get_num + mariadb_dyncol_has_names + mariadb_dyncol_json + mariadb_dyncol_list_named + mariadb_dyncol_list_num + mariadb_dyncol_unpack + mariadb_dyncol_update_many_named + mariadb_dyncol_update_many_num + mariadb_dyncol_val_double + mariadb_dyncol_val_long + mariadb_dyncol_val_str) + +SET(MARIADB_NONBLOCK_SYMBOLS + mysql_autocommit_cont + mysql_autocommit_start + mysql_change_user_cont + mysql_change_user_start + mysql_close_cont + mysql_close_start + mysql_commit_cont + mysql_commit_start + mysql_dump_debug_info_cont + mysql_dump_debug_info_start + mysql_fetch_row_cont + mysql_fetch_row_start + mysql_free_result_cont + mysql_free_result_start + mysql_kill_cont + mysql_kill_start + mysql_list_fields_cont + mysql_list_fields_start + mysql_next_result_cont + mysql_next_result_start + mysql_ping_cont + mysql_ping_start + mysql_reset_connection_start + mysql_reset_connection_cont + mysql_query_cont + mysql_query_start + mysql_read_query_result_cont + mysql_read_query_result_start + mysql_real_connect_cont + mysql_real_connect_start + mysql_real_query_cont + mysql_real_query_start + mysql_refresh_cont + mysql_refresh_start + mysql_rollback_cont + mysql_rollback_start + mysql_select_db_cont + mysql_select_db_start + mysql_send_query_cont + mysql_send_query_start + mysql_set_character_set_cont + mysql_set_character_set_start + mysql_set_server_option_cont + mysql_set_server_option_start + mysql_shutdown_cont + mysql_shutdown_start + mysql_stat_cont + mysql_stat_start + mysql_stmt_close_cont + mysql_stmt_close_start + mysql_stmt_execute_cont + mysql_stmt_execute_start + mysql_stmt_fetch_cont + mysql_stmt_fetch_start + mysql_stmt_free_result_cont + mysql_stmt_free_result_start + mysql_stmt_next_result_cont + mysql_stmt_next_result_start + mysql_stmt_prepare_cont + mysql_stmt_prepare_start + mysql_stmt_reset_cont + mysql_stmt_reset_start + mysql_stmt_send_long_data_cont + mysql_stmt_send_long_data_start + mysql_stmt_store_result_cont + mysql_stmt_store_result_start + mysql_store_result_cont + mysql_store_result_start +) + +# handle static plugins +SET(LIBMARIADB_SOURCES ${LIBMARIADB_PLUGIN_SOURCES}) +SET(SYSTEM_LIBS ${SYSTEM_LIBS} ${LIBMARIADB_PLUGIN_LIBS} ${INTERNAL_ZLIB_LIBRARY}) +ADD_DEFINITIONS(${LIBMARIADB_PLUGIN_DEFS}) +FOREACH(plugin ${PLUGINS_STATIC}) + SET(EXTERNAL_PLUGINS "${EXTERNAL_PLUGINS} extern struct st_mysql_client_plugin ${plugin}_client_plugin;\n") + SET(BUILTIN_PLUGINS "${BUILTIN_PLUGINS} (struct st_mysql_client_plugin *)&${plugin}_client_plugin,\n") +ENDFOREACH() +CONFIGURE_FILE(${CC_SOURCE_DIR}/libmariadb/ma_client_plugin.c.in + ${CC_BINARY_DIR}/libmariadb/ma_client_plugin.c) + +SET(LIBMARIADB_SOURCES ${LIBMARIADB_SOURCES} +${CC_SOURCE_DIR}/plugins/auth/my_auth.c +ma_array.c +ma_charset.c +ma_hashtbl.c +ma_net.c +mariadb_charset.c +ma_time.c +ma_default.c +ma_errmsg.c +mariadb_lib.c +ma_list.c +ma_pvio.c +ma_tls.c +ma_alloc.c +ma_compress.c +ma_init.c +ma_password.c +ma_ll2str.c +ma_sha1.c +mariadb_stmt.c +ma_loaddata.c +ma_stmt_codec.c +ma_string.c +ma_dtoa.c +mariadb_rpl.c +${CC_BINARY_DIR}/libmariadb/ma_client_plugin.c +ma_io.c +${SSL_SOURCES} +) + +IF(WIN32) + ADD_DEFINITIONS(-DSIZEOF_CHARP=${CMAKE_SIZEOF_VOID_P}) + INCLUDE_DIRECTORIES(${CC_SOURCE_DIR}/win-iconv) + SET(LIBMARIADB_SOURCES + ${LIBMARIADB_SOURCES} + ${CC_SOURCE_DIR}/win-iconv/win_iconv.c + win32_errmsg.c + win32_errmsg.h) +ELSE() + IF(ICONV_INCLUDE_DIR) + INCLUDE_DIRECTORIES(BEFORE ${ICONV_INCLUDE_DIR}) + ENDIF() + IF(NOT CMAKE_SYSTEM_NAME MATCHES AIX) + ADD_DEFINITIONS(-DLIBICONV_PLUG) + ENDIF() +ENDIF() + +IF(ZLIB_FOUND AND WITH_EXTERNAL_ZLIB) + INCLUDE_DIRECTORIES(${ZLIB_INCLUDE_DIR}) +ELSE() + SET(ZLIB_SOURCES + ../zlib/adler32.c + ../zlib/compress.c + ../zlib/crc32.c + ../zlib/deflate.c + ../zlib/gzclose.c + ../zlib/gzlib.c + ../zlib/gzread.c + ../zlib/gzwrite.c + ../zlib/infback.c + ../zlib/inffast.c + ../zlib/inflate.c + ../zlib/inftrees.c + ../zlib/trees.c + ../zlib/uncompr.c + ../zlib/zutil.c + ) + SET(LIBMARIADB_SOURCES ${LIBMARIADB_SOURCES} ${ZLIB_SOURCES}) + INCLUDE_DIRECTORIES(${CC_SOURCE_DIR}/zlib) +ENDIF() + +IF(WITH_DYNCOL) + MESSAGE1(WITH_DYNCOL "Dynamic column API support: ON") + SET(MARIADB_LIB_SYMBOLS ${MARIADB_LIB_SYMBOLS} ${MARIADB_DYNCOL_SYMBOLS}) + SET(LIBMARIADB_SOURCES ${LIBMARIADB_SOURCES} mariadb_dyncol.c) +ENDIF() + +SET(LIBMARIADB_SOURCES ${LIBMARIADB_SOURCES} mariadb_async.c ma_context.c) +SET(MARIADB_LIB_SYMBOLS ${MARIADB_LIB_SYMBOLS} ${MARIADB_NONBLOCK_SYMBOLS}) + +INCLUDE(${CC_SOURCE_DIR}/cmake/export.cmake) +IF(NOT WIN32) + CREATE_EXPORT_FILE(WRITE mariadbclient.def + "libmysqlclient_18" + "${MYSQL_LIB_SYMBOLS}" + "libmariadbclient_18") + CREATE_EXPORT_FILE(APPEND mariadbclient.def + "libmariadb_3" + "${MARIADB_LIB_SYMBOLS}" + "") +ELSE() + CREATE_EXPORT_FILE(WRITE mariadbclient.def + "libmariadb_3" + "${MARIADB_LIB_SYMBOLS};${MYSQL_LIB_SYMBOLS}" + "") +ENDIF() + + +IF(CMAKE_VERSION VERSION_GREATER 2.8.7) + # CREATE OBJECT LIBRARY + ADD_LIBRARY(mariadb_obj OBJECT ${LIBMARIADB_SOURCES}) + IF(UNIX) + SET_TARGET_PROPERTIES(mariadb_obj PROPERTIES COMPILE_FLAGS "${CMAKE_SHARED_LIBRARY_C_FLAGS}") + ENDIF() + SET (MARIADB_OBJECTS $) +ELSE() + SET (MARIADB_OBJECTS ${LIBMARIADB_SOURCES}) +ENDIF() + +# Xcode doesn't support targets that have only object files, +# so let's add an empty file to keep Xcode happy +IF(CMAKE_GENERATOR MATCHES Xcode) + FILE(WRITE ${CC_BINARY_DIR}/libmariadb/empty.c "") + SET(EMPTY_FILE ${CC_BINARY_DIR}/libmariadb/empty.c) +ENDIF() + +#* create file with list of functions */ +FILE(WRITE ${CC_BINARY_DIR}/manpages.list "${MARIADB_LIB_SYMBOLS};${MYSQL_LIB_SYMBOLS}") + +IF(WIN32) + SET_VERSION_INFO("TARGET:libmariadb" + "FILE_TYPE:VFT_DLL" + "SOURCE_FILE:libmariadb/libmariadb.c" + "ORIGINAL_FILE_NAME:libmariadb.dll" + "FILE_DESCRIPTION:Dynamic lib for client/server communication") +ENDIF() + + +ADD_LIBRARY(mariadbclient STATIC ${MARIADB_OBJECTS} ${EMPTY_FILE}) +TARGET_LINK_LIBRARIES(mariadbclient ${SYSTEM_LIBS}) + +IF(UNIX) + ADD_LIBRARY(libmariadb SHARED ${libmariadb_RC} ${MARIADB_OBJECTS} ${EMPTY_FILE}) + SET_TARGET_PROPERTIES(libmariadb PROPERTIES COMPILE_FLAGS "${CMAKE_SHARED_LIBRARY_C_FLAGS}") +ELSE() + ADD_LIBRARY(libmariadb SHARED ${libmariadb_RC} ${MARIADB_OBJECTS} mariadbclient.def) + SET_TARGET_PROPERTIES(libmariadb PROPERTIES LINKER_LANGUAGE C) +ENDIF() + +TARGET_LINK_LIBRARIES(libmariadb LINK_PRIVATE ${SYSTEM_LIBS}) + +SIGN_TARGET(libmariadb) + +IF(CMAKE_SYSTEM_NAME MATCHES "Linux" OR + CMAKE_SYSTEM_NAME MATCHES "kFreeBSD" OR + CMAKE_SYSTEM_NAME MATCHES "GNU") + IF (NOT WITH_ASAN AND NOT WITH_TSAN AND NOT WITH_UBSAN AND NOT WITH_MSAN) + TARGET_LINK_LIBRARIES (libmariadb LINK_PRIVATE "-Wl,--no-undefined") + ENDIF() + SET_TARGET_PROPERTIES(libmariadb PROPERTIES LINK_FLAGS "${CC_BINARY_DIR}/libmariadb/mariadbclient.def") +ENDIF() + +SET_TARGET_PROPERTIES(mariadbclient PROPERTIES IMPORTED_INTERFACE_LINK_LIBRARIES "${SYSTEM_LIBS}") +SET_TARGET_PROPERTIES(libmariadb PROPERTIES IMPORTED_INTERFACE_LINK_LIBRARIES "${SYSTEM_LIBS}") + +SET_TARGET_PROPERTIES(libmariadb PROPERTIES PREFIX "") + +# +# Installation +# +INCLUDE(${CC_SOURCE_DIR}/cmake/symlink.cmake) + +# There are still several projects which don't make use +# of the config program. To make sure these programs can +# use mariadb client library we provide libmysql symlinks + +IF(WITH_MYSQLCOMPAT) + create_symlink(libmysqlclient${CMAKE_SHARED_LIBRARY_SUFFIX} libmariadb ${INSTALL_LIBDIR}) + create_symlink(libmysqlclient_r${CMAKE_SHARED_LIBRARY_SUFFIX} libmariadb ${INSTALL_LIBDIR}) + IF(NOT CMAKE_SYSTEM_NAME MATCHES AIX) + create_symlink(libmysqlclient${CMAKE_STATIC_LIBRARY_SUFFIX} mariadbclient ${INSTALL_LIBDIR}) + create_symlink(libmysqlclient_r${CMAKE_STATIC_LIBRARY_SUFFIX} mariadbclient ${INSTALL_LIBDIR}) + ENDIF() +ENDIF() + + +SET_TARGET_PROPERTIES(libmariadb PROPERTIES VERSION + ${CPACK_PACKAGE_VERSION_MAJOR} + SOVERSION ${CPACK_PACKAGE_VERSION_MAJOR}) + +IF(NOT WIN32) + SET_TARGET_PROPERTIES(mariadbclient PROPERTIES OUTPUT_NAME "${LIBMARIADB_STATIC_NAME}") +ENDIF() + +INSTALL(TARGETS mariadbclient + COMPONENT Development + DESTINATION ${INSTALL_LIBDIR}) +INSTALL(TARGETS libmariadb + COMPONENT SharedLibraries + DESTINATION ${INSTALL_LIBDIR}) + + +IF(MSVC) + # On Windows, install PDB + INSTALL(FILES $ DESTINATION "${INSTALL_LIBDIR}" + CONFIGURATIONS Debug RelWithDebInfo + COMPONENT Development) +ENDIF() diff --git a/vendor/MDBC/libmariadb/bmove_upp.c b/vendor/MDBC/libmariadb/bmove_upp.c new file mode 100644 index 00000000..599b38be --- /dev/null +++ b/vendor/MDBC/libmariadb/bmove_upp.c @@ -0,0 +1,33 @@ +/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + MA 02111-1301, USA */ + +/* File : bmove.c + Author : Michael widenius + Updated: 1987-03-20 + Defines: bmove_upp() + + bmove_upp(dst, src, len) moves exactly "len" bytes from the source + "src-len" to the destination "dst-len" counting downwards. +*/ + +#include +#include "ma_string.h" + +void ma_bmove_upp(register char *dst, register const char *src, register size_t len) +{ + while (len-- != 0) *--dst = *--src; +} diff --git a/vendor/MDBC/libmariadb/get_password.c b/vendor/MDBC/libmariadb/get_password.c new file mode 100644 index 00000000..4a93a738 --- /dev/null +++ b/vendor/MDBC/libmariadb/get_password.c @@ -0,0 +1,172 @@ +/************************************************************************************ + Copyright (C) 2014 MariaDB Corporation AB + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not see + or write to the Free Software Foundation, Inc., + 51 Franklin St., Fifth Floor, Boston, MA 02110, USA +*************************************************************************************/ +#include +#include +#include "mysql.h" +#include +#include +#include +#include + +#ifndef _WIN32 +#include +#else +#include +#endif /* _WIN32 */ + +/* {{{ static char *get_password() */ +/* + read password from device + + SYNOPSIS + get_password + Hdl/file file handle + buffer input buffer + length buffer length + + RETURN + buffer zero terminated input buffer +*/ +#ifdef _WIN32 +static char *get_password(HANDLE Hdl, char *buffer, DWORD length) +#else +static char *get_password(FILE *file, char *buffer, int length) +#endif +{ + char inChar; + int CharsProcessed= 1; +#ifdef _WIN32 + DWORD Offset= 0; +#else + int Offset= 0; +#endif + memset(buffer, 0, length); + + do + { +#ifdef _WIN32 + if (!ReadConsole(Hdl, &inChar, 1, (DWORD *)&CharsProcessed, NULL) || + !CharsProcessed) + break; +#else + inChar= (char)fgetc(file); +#endif + + switch(inChar) { + case '\b': /* backslash */ + if (Offset) + { + /* cursor is always at the end */ + Offset--; + buffer[Offset]= 0; +#ifdef _WIN32 + _cputs("\b \b"); +#endif + } + break; + case '\n': + case '\r': + break; + default: + buffer[Offset]= inChar; + if (Offset < length - 2) + Offset++; +#ifdef _WIN32 + _cputs("*"); +#endif + break; + } + } while (CharsProcessed && inChar != '\n' && inChar != '\r'); + return buffer; +} +/* }}} */ + +/* {{{ static char* get_tty_password */ +/* + reads password from tty/console + + SYNOPSIS + get_tty_password() + buffer input buffer + length length of input buffer + + DESCRIPTION + reads a password from console (Windows) or tty without echoing + it's characters. Input buffer must be allocated by calling function. + + RETURNS + buffer pointer to input buffer +*/ +char* get_tty_password(char *prompt, char *buffer, int length) +{ +#ifdef _WIN32 + DWORD SaveState; + HANDLE Hdl; + + if (prompt) + fprintf(stderr, "%s", prompt); + + if (!(Hdl= CreateFile("CONIN$", + GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ, + NULL, + OPEN_EXISTING, 0, NULL))) + { + /* todo: provide a graphical dialog */ + return buffer; + } + /* Save ConsoleMode and set ENABLE_PROCESSED_INPUT: + CTRL+C is processed by the system and is not placed in the input buffer */ + GetConsoleMode(Hdl, &SaveState); + SetConsoleMode(Hdl, ENABLE_PROCESSED_INPUT); + + buffer= get_password(Hdl, buffer, length); + SetConsoleMode(Hdl, SaveState); + CloseHandle(Hdl); + return buffer; +#else + struct termios term_old, + term_new; + FILE *readfrom; + + if (prompt && isatty(fileno(stderr))) + fputs(prompt, stderr); + + if (!(readfrom= fopen("/dev/tty", "r"))) + readfrom= stdin; + + /* try to disable echo */ + tcgetattr(fileno(readfrom), &term_old); + term_new= term_old; + term_new.c_cc[VMIN] = 1; + term_new.c_cc[VTIME]= 0; + term_new.c_lflag&= ~(ECHO | ISIG | ICANON | ECHONL); + tcsetattr(fileno(readfrom), TCSADRAIN, &term_new); + + buffer= get_password(readfrom, buffer, length); + + if (isatty(fileno(readfrom))) + tcsetattr(fileno(readfrom), TCSADRAIN, &term_old); + + fclose(readfrom); + + return buffer; +#endif +} +/* }}} */ diff --git a/vendor/MDBC/libmariadb/ma_alloc.c b/vendor/MDBC/libmariadb/ma_alloc.c new file mode 100644 index 00000000..300a107d --- /dev/null +++ b/vendor/MDBC/libmariadb/ma_alloc.c @@ -0,0 +1,193 @@ +/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + MA 02111-1301, USA */ + +/* Routines to handle mallocing of results which will be freed the same time */ + +#include +#include +#include + +void ma_init_alloc_root(MA_MEM_ROOT *mem_root, size_t block_size, size_t pre_alloc_size) +{ + mem_root->free= mem_root->used= mem_root->pre_alloc= 0; + mem_root->min_malloc=32; + mem_root->block_size= (block_size-MALLOC_OVERHEAD-sizeof(MA_USED_MEM)+8); + mem_root->error_handler=0; + mem_root->block_num= 4; + mem_root->first_block_usage= 0; +#if !(defined(HAVE_purify) && defined(EXTRA_DEBUG)) + if (pre_alloc_size) + { + if ((mem_root->free = mem_root->pre_alloc= + (MA_USED_MEM*) malloc(pre_alloc_size+ ALIGN_SIZE(sizeof(MA_USED_MEM))))) + { + mem_root->free->size=pre_alloc_size+ALIGN_SIZE(sizeof(MA_USED_MEM)); + mem_root->free->left=pre_alloc_size; + mem_root->free->next=0; + } + } +#endif +} + +void * ma_alloc_root(MA_MEM_ROOT *mem_root, size_t Size) +{ +#if defined(HAVE_purify) && defined(EXTRA_DEBUG) + reg1 MA_USED_MEM *next; + Size+=ALIGN_SIZE(sizeof(MA_USED_MEM)); + + if (!(next = (MA_USED_MEM*) malloc(Size))) + { + if (mem_root->error_handler) + (*mem_root->error_handler)(); + return((void *) 0); /* purecov: inspected */ + } + next->next=mem_root->used; + mem_root->used=next; + return (void *) (((char*) next)+ALIGN_SIZE(sizeof(MA_USED_MEM))); +#else + size_t get_size; + void * point; + reg1 MA_USED_MEM *next= 0; + reg2 MA_USED_MEM **prev; + + Size= ALIGN_SIZE(Size); + + if ((*(prev= &mem_root->free))) + { + if ((*prev)->left < Size && + mem_root->first_block_usage++ >= 16 && + (*prev)->left < 4096) + { + next= *prev; + *prev= next->next; + next->next= mem_root->used; + mem_root->used= next; + mem_root->first_block_usage= 0; + } + for (next= *prev; next && next->left < Size; next= next->next) + prev= &next->next; + } + + if (! next) + { /* Time to alloc new block */ + get_size= MAX(Size+ALIGN_SIZE(sizeof(MA_USED_MEM)), + (mem_root->block_size & ~1) * (mem_root->block_num >> 2)); + + if (!(next = (MA_USED_MEM*) malloc(get_size))) + { + if (mem_root->error_handler) + (*mem_root->error_handler)(); + return((void *) 0); /* purecov: inspected */ + } + mem_root->block_num++; + next->next= *prev; + next->size= get_size; + next->left= get_size-ALIGN_SIZE(sizeof(MA_USED_MEM)); + *prev=next; + } + point= (void *) ((char*) next+ (next->size-next->left)); + if ((next->left-= Size) < mem_root->min_malloc) + { /* Full block */ + *prev=next->next; /* Remove block from list */ + next->next=mem_root->used; + mem_root->used=next; + mem_root->first_block_usage= 0; + } + return(point); +#endif +} + + /* deallocate everything used by alloc_root */ + +void ma_free_root(MA_MEM_ROOT *root, myf MyFlags) +{ + reg1 MA_USED_MEM *next,*old; + + if (!root) + return; /* purecov: inspected */ + if (!(MyFlags & MY_KEEP_PREALLOC)) + root->pre_alloc=0; + + for ( next=root->used; next ;) + { + old=next; next= next->next ; + if (old != root->pre_alloc) + free(old); + } + for (next= root->free ; next ; ) + { + old=next; next= next->next ; + if (old != root->pre_alloc) + free(old); + } + root->used=root->free=0; + if (root->pre_alloc) + { + root->free=root->pre_alloc; + root->free->left=root->pre_alloc->size-ALIGN_SIZE(sizeof(MA_USED_MEM)); + root->free->next=0; + } +} + + +char *ma_strdup_root(MA_MEM_ROOT *root,const char *str) +{ + size_t len= strlen(str)+1; + char *pos; + if ((pos=ma_alloc_root(root,len))) + memcpy(pos,str,len); + return pos; +} + + +char *ma_memdup_root(MA_MEM_ROOT *root, const char *str, size_t len) +{ + char *pos; + if ((pos= ma_alloc_root(root,len))) + memcpy(pos,str,len); + return pos; +} + +void *ma_multi_malloc(myf myFlags, ...) +{ + va_list args; + char **ptr,*start,*res; + size_t tot_length,length; + + va_start(args,myFlags); + tot_length=0; + while ((ptr=va_arg(args, char **))) + { + length=va_arg(args, size_t); + tot_length+=ALIGN_SIZE(length); + } + va_end(args); + + if (!(start=(char *)malloc(tot_length))) + return 0; + + va_start(args,myFlags); + res=start; + while ((ptr=va_arg(args, char **))) + { + *ptr=res; + length=va_arg(args,size_t); + res+=ALIGN_SIZE(length); + } + va_end(args); + return start; +} diff --git a/vendor/MDBC/libmariadb/ma_array.c b/vendor/MDBC/libmariadb/ma_array.c new file mode 100644 index 00000000..d067aa4a --- /dev/null +++ b/vendor/MDBC/libmariadb/ma_array.c @@ -0,0 +1,172 @@ +/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB + 2016 MariaDB Corporation AB + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + MA 02111-1301, USA */ + +/* Handling of arrays that can grow dynamically. */ + +#undef SAFEMALLOC /* Problems with threads */ + +#include +#include +#include "ma_string.h" +#include + +/* + Initiate array and alloc space for init_alloc elements. Array is usable + even if space allocation failed +*/ + +my_bool ma_init_dynamic_array(DYNAMIC_ARRAY *array, uint element_size, + uint init_alloc, uint alloc_increment CALLER_INFO_PROTO) +{ + if (!alloc_increment) + { + alloc_increment=max((8192-MALLOC_OVERHEAD)/element_size,16); + if (init_alloc > 8 && alloc_increment > init_alloc * 2) + alloc_increment=init_alloc*2; + } + + if (!init_alloc) + init_alloc=alloc_increment; + array->elements=0; + array->max_element=init_alloc; + array->alloc_increment=alloc_increment; + array->size_of_element=element_size; + if (!(array->buffer=(char*) malloc(element_size*init_alloc))) + { + array->max_element=0; + return(TRUE); + } + return(FALSE); +} + + +my_bool ma_insert_dynamic(DYNAMIC_ARRAY *array, void *element) +{ + void *buffer; + if (array->elements == array->max_element) + { /* Call only when necessary */ + if (!(buffer=ma_alloc_dynamic(array))) + return TRUE; + } + else + { + buffer=array->buffer+(array->elements * array->size_of_element); + array->elements++; + } + memcpy(buffer,element,(size_t) array->size_of_element); + return FALSE; +} + + + /* Alloc room for one element */ + +unsigned char *ma_alloc_dynamic(DYNAMIC_ARRAY *array) +{ + if (array->elements == array->max_element) + { + char *new_ptr; + if (!(new_ptr=(char*) realloc(array->buffer,(array->max_element+ + array->alloc_increment)* + array->size_of_element))) + return 0; + array->buffer=new_ptr; + array->max_element+=array->alloc_increment; + } + return (unsigned char *)array->buffer+(array->elements++ * array->size_of_element); +} + + + /* remove last element from array and return it */ + +unsigned char *ma_pop_dynamic(DYNAMIC_ARRAY *array) +{ + if (array->elements) + return (unsigned char *)array->buffer+(--array->elements * array->size_of_element); + return 0; +} + + +my_bool ma_set_dynamic(DYNAMIC_ARRAY *array, void * element, uint idx) +{ + if (idx >= array->elements) + { + if (idx >= array->max_element) + { + uint size; + char *new_ptr; + size=(idx+array->alloc_increment)/array->alloc_increment; + size*= array->alloc_increment; + if (!(new_ptr=(char*) realloc(array->buffer,size* + array->size_of_element))) + return TRUE; + array->buffer=new_ptr; + array->max_element=size; + } + memset((array->buffer+array->elements*array->size_of_element), 0, + (idx - array->elements)*array->size_of_element); + array->elements=idx+1; + } + memcpy(array->buffer+(idx * array->size_of_element),element, + (size_t) array->size_of_element); + return FALSE; +} + + +void ma_get_dynamic(DYNAMIC_ARRAY *array, void * element, uint idx) +{ + if (idx >= array->elements) + { + memset(element, 0, array->size_of_element); + return; + } + memcpy(element,array->buffer+idx*array->size_of_element, + (size_t) array->size_of_element); +} + + +void ma_delete_dynamic(DYNAMIC_ARRAY *array) +{ + if (array->buffer) + { + free(array->buffer); + array->buffer=0; + array->elements=array->max_element=0; + } +} + + +void ma_delete_dynamic_element(DYNAMIC_ARRAY *array, uint idx) +{ + char *ptr=array->buffer+array->size_of_element*idx; + array->elements--; + memmove(ptr,ptr+array->size_of_element, + (array->elements-idx)*array->size_of_element); +} + + +void ma_freeze_size(DYNAMIC_ARRAY *array) +{ + uint elements=max(array->elements,1); + + if (array->buffer && array->max_element != elements) + { + array->buffer=(char*) realloc(array->buffer, + elements*array->size_of_element); + array->max_element=elements; + } +} diff --git a/vendor/MDBC/libmariadb/ma_charset.c b/vendor/MDBC/libmariadb/ma_charset.c new file mode 100644 index 00000000..e2ae786e --- /dev/null +++ b/vendor/MDBC/libmariadb/ma_charset.c @@ -0,0 +1,1482 @@ +/**************************************************************************** + Copyright (C) 2012, 2020, MariaDB Corporation. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not see + or write to the Free Software Foundation, Inc., + 51 Franklin St., Fifth Floor, Boston, MA 02110, USA + + Part of this code includes code from the PHP project which + is freely available from http://www.php.net +*****************************************************************************/ + +/* The implementation for character set support was ported from PHP's mysqlnd + extension, written by Andrey Hristov, Georg Richter and Ulf Wendel + + Original file header: + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | Copyright (c) 2006-2011 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Authors: Georg Richter | + | Andrey Hristov | + | Ulf Wendel | + +----------------------------------------------------------------------+ +*/ + +#ifndef _WIN32 +#include +#include +#else +#include +#endif +#include +#include +#include + +#ifdef HAVE_ICONV +#ifdef _WIN32 +#include "../win-iconv/iconv.h" +#else +#include +#endif +#endif + + +#if defined(HAVE_NL_LANGINFO) && defined(HAVE_SETLOCALE) +#include +#include +#endif + +/* + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | Copyright (c) 2006-2011 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Authors: Georg Richter | + | Andrey Hristov | + | Ulf Wendel | + +----------------------------------------------------------------------+ +*/ + +/* {{{ utf8 functions */ +static unsigned int check_mb_utf8mb3_sequence(const char *start, const char *end) +{ + uchar c; + + if (start >= end) { + return 0; + } + + c = (uchar) start[0]; + + if (c < 0x80) { + return 1; /* single byte character */ + } + if (c < 0xC2) { + return 0; /* invalid mb character */ + } + if (c < 0xE0) { + if (start + 2 > end) { + return 0; /* too small */ + } + if (!(((uchar)start[1] ^ 0x80) < 0x40)) { + return 0; + } + return 2; + } + if (c < 0xF0) { + if (start + 3 > end) { + return 0; /* too small */ + } + if (!(((uchar)start[1] ^ 0x80) < 0x40 && ((uchar)start[2] ^ 0x80) < 0x40 && + (c >= 0xE1 || (uchar)start[1] >= 0xA0))) { + return 0; /* invalid utf8 character */ + } + return 3; + } + return 0; +} + + +static unsigned int check_mb_utf8_sequence(const char *start, const char *end) +{ + uchar c; + + if (start >= end) { + return 0; + } + + c = (uchar) start[0]; + + if (c < 0x80) { + return 1; /* single byte character */ + } + if (c < 0xC2) { + return 0; /* invalid mb character */ + } + if (c < 0xE0) { + if (start + 2 > end) { + return 0; /* too small */ + } + if (!(((uchar)start[1] ^ 0x80) < 0x40)) { + return 0; + } + return 2; + } + if (c < 0xF0) { + if (start + 3 > end) { + return 0; /* too small */ + } + if (!(((uchar)start[1] ^ 0x80) < 0x40 && ((uchar)start[2] ^ 0x80) < 0x40 && + (c >= 0xE1 || (uchar)start[1] >= 0xA0))) { + return 0; /* invalid utf8 character */ + } + return 3; + } + if (c < 0xF5) { + if (start + 4 > end) { /* We need 4 characters */ + return 0; /* too small */ + } + + /* + UTF-8 quick four-byte mask: + 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx + Encoding allows to encode U+00010000..U+001FFFFF + + The maximum character defined in the Unicode standard is U+0010FFFF. + Higher characters U+00110000..U+001FFFFF are not used. + + 11110000.10010000.10xxxxxx.10xxxxxx == F0.90.80.80 == U+00010000 (min) + 11110100.10001111.10111111.10111111 == F4.8F.BF.BF == U+0010FFFF (max) + + Valid codes: + [F0][90..BF][80..BF][80..BF] + [F1][80..BF][80..BF][80..BF] + [F2][80..BF][80..BF][80..BF] + [F3][80..BF][80..BF][80..BF] + [F4][80..8F][80..BF][80..BF] + */ + + if (!(((uchar)start[1] ^ 0x80) < 0x40 && + ((uchar)start[2] ^ 0x80) < 0x40 && + ((uchar)start[3] ^ 0x80) < 0x40 && + (c >= 0xf1 || (uchar)start[1] >= 0x90) && + (c <= 0xf3 || (uchar)start[1] <= 0x8F))) + { + return 0; /* invalid utf8 character */ + } + return 4; + } + return 0; +} + +static unsigned int check_mb_utf8mb3_valid(const char *start, const char *end) +{ + unsigned int len = check_mb_utf8mb3_sequence(start, end); + return (len > 1)? len:0; +} + +static unsigned int check_mb_utf8_valid(const char *start, const char *end) +{ + unsigned int len = check_mb_utf8_sequence(start, end); + return (len > 1)? len:0; +} + + +static unsigned int mysql_mbcharlen_utf8mb3(unsigned int utf8) +{ + if (utf8 < 0x80) { + return 1; /* single byte character */ + } + if (utf8 < 0xC2) { + return 0; /* invalid multibyte header */ + } + if (utf8 < 0xE0) { + return 2; /* double byte character */ + } + if (utf8 < 0xF0) { + return 3; /* triple byte character */ + } + return 0; +} + + +static unsigned int mysql_mbcharlen_utf8(unsigned int utf8) +{ + if (utf8 < 0x80) { + return 1; /* single byte character */ + } + if (utf8 < 0xC2) { + return 0; /* invalid multibyte header */ + } + if (utf8 < 0xE0) { + return 2; /* double byte character */ + } + if (utf8 < 0xF0) { + return 3; /* triple byte character */ + } + if (utf8 < 0xF8) { + return 4; /* four byte character */ + } + return 0; +} +/* }}} */ + + +/* {{{ big5 functions */ +#define valid_big5head(c) (0xA1 <= (unsigned int)(c) && (unsigned int)(c) <= 0xF9) +#define valid_big5tail(c) ((0x40 <= (unsigned int)(c) && (unsigned int)(c) <= 0x7E) || \ + (0xA1 <= (unsigned int)(c) && (unsigned int)(c) <= 0xFE)) + +#define isbig5code(c,d) (isbig5head(c) && isbig5tail(d)) + +static unsigned int check_mb_big5(const char *start, const char *end) +{ + return (valid_big5head(*((const uchar*) start)) && (end - start) > 1 && valid_big5tail(*((const uchar*) start + 1)) ? 2 : 0); +} + + +static unsigned int mysql_mbcharlen_big5(unsigned int big5) +{ + return (valid_big5head(big5)) ? 2 : 1; +} +/* }}} */ + + +/* {{{ cp932 functions */ +#define valid_cp932head(c) ((0x81 <= (c) && (c) <= 0x9F) || (0xE0 <= (c) && c <= 0xFC)) +#define valid_cp932tail(c) ((0x40 <= (c) && (c) <= 0x7E) || (0x80 <= (c) && c <= 0xFC)) + + +static unsigned int check_mb_cp932(const char *start, const char *end) +{ + return (valid_cp932head((uchar)start[0]) && (end - start > 1) && + valid_cp932tail((uchar)start[1])) ? 2 : 0; +} + + +static unsigned int mysql_mbcharlen_cp932(unsigned int cp932) +{ + return (valid_cp932head((uchar)cp932)) ? 2 : 1; +} +/* }}} */ + + +/* {{{ euckr functions */ +#define valid_euckr(c) ((0xA1 <= (uchar)(c) && (uchar)(c) <= 0xFE)) + +static unsigned int check_mb_euckr(const char *start, const char *end) +{ + if (end - start <= 1) { + return 0; /* invalid length */ + } + if (*(uchar *)start < 0x80) { + return 0; /* invalid euckr character */ + } + if (valid_euckr(start[1])) { + return 2; + } + return 0; +} + + +static unsigned int mysql_mbcharlen_euckr(unsigned int kr) +{ + return (valid_euckr(kr)) ? 2 : 1; +} +/* }}} */ + + +/* {{{ eucjpms functions */ +#define valid_eucjpms(c) (((c) & 0xFF) >= 0xA1 && ((c) & 0xFF) <= 0xFE) +#define valid_eucjpms_kata(c) (((c) & 0xFF) >= 0xA1 && ((c) & 0xFF) <= 0xDF) +#define valid_eucjpms_ss2(c) (((c) & 0xFF) == 0x8E) +#define valid_eucjpms_ss3(c) (((c) & 0xFF) == 0x8F) + +static unsigned int check_mb_eucjpms(const char *start, const char *end) +{ + if (*((uchar *)start) < 0x80) { + return 0; /* invalid eucjpms character */ + } + if (valid_eucjpms(start[0]) && (end - start) > 1 && valid_eucjpms(start[1])) { + return 2; + } + if (valid_eucjpms_ss2(start[0]) && (end - start) > 1 && valid_eucjpms_kata(start[1])) { + return 2; + } + if (valid_eucjpms_ss3(start[0]) && (end - start) > 2 && valid_eucjpms(start[1]) && + valid_eucjpms(start[2])) { + return 2; + } + return 0; +} + + +static unsigned int mysql_mbcharlen_eucjpms(unsigned int jpms) +{ + if (valid_eucjpms(jpms) || valid_eucjpms_ss2(jpms)) { + return 2; + } + if (valid_eucjpms_ss3(jpms)) { + return 3; + } + return 1; +} +/* }}} */ + + +/* {{{ gb2312 functions */ +#define valid_gb2312_head(c) (0xA1 <= (uchar)(c) && (uchar)(c) <= 0xF7) +#define valid_gb2312_tail(c) (0xA1 <= (uchar)(c) && (uchar)(c) <= 0xFE) + + +static unsigned int check_mb_gb2312(const char *start, const char *end) +{ + return (valid_gb2312_head((unsigned int)start[0]) && end - start > 1 && + valid_gb2312_tail((unsigned int)start[1])) ? 2 : 0; +} + + +static unsigned int mysql_mbcharlen_gb2312(unsigned int gb) +{ + return (valid_gb2312_head(gb)) ? 2 : 1; +} +/* }}} */ + + +/* {{{ gbk functions */ +#define valid_gbk_head(c) (0x81<=(uchar)(c) && (uchar)(c)<=0xFE) +#define valid_gbk_tail(c) ((0x40<=(uchar)(c) && (uchar)(c)<=0x7E) || (0x80<=(uchar)(c) && (uchar)(c)<=0xFE)) + +static unsigned int check_mb_gbk(const char *start, const char *end) +{ + return (valid_gbk_head(start[0]) && (end) - (start) > 1 && valid_gbk_tail(start[1])) ? 2 : 0; +} + +static unsigned int mysql_mbcharlen_gbk(unsigned int gbk) +{ + return (valid_gbk_head(gbk) ? 2 : 1); +} +/* }}} */ + + +/* {{{ sjis functions */ +#define valid_sjis_head(c) ((0x81 <= (c) && (c) <= 0x9F) || (0xE0 <= (c) && (c) <= 0xFC)) +#define valid_sjis_tail(c) ((0x40 <= (c) && (c) <= 0x7E) || (0x80 <= (c) && (c) <= 0xFC)) + + +static unsigned int check_mb_sjis(const char *start, const char *end) +{ + return (valid_sjis_head((uchar)start[0]) && (end - start) > 1 && valid_sjis_tail((uchar)start[1])) ? 2 : 0; +} + + +static unsigned int mysql_mbcharlen_sjis(unsigned int sjis) +{ + return (valid_sjis_head((uchar)sjis)) ? 2 : 1; +} +/* }}} */ + + +/* {{{ ucs2 functions */ +static unsigned int check_mb_ucs2(const char *start __attribute((unused)), const char *end __attribute((unused))) +{ + return 2; /* always 2 */ +} + +static unsigned int mysql_mbcharlen_ucs2(unsigned int ucs2 __attribute((unused))) +{ + return 2; /* always 2 */ +} +/* }}} */ + + +/* {{{ ujis functions */ +#define valid_ujis(c) ((0xA1 <= ((c)&0xFF) && ((c)&0xFF) <= 0xFE)) +#define valid_ujis_kata(c) ((0xA1 <= ((c)&0xFF) && ((c)&0xFF) <= 0xDF)) +#define valid_ujis_ss2(c) (((c)&0xFF) == 0x8E) +#define valid_ujis_ss3(c) (((c)&0xFF) == 0x8F) + +static unsigned int check_mb_ujis(const char *start, const char *end) +{ + if (*(uchar*)start < 0x80) { + return 0; /* invalid ujis character */ + } + if (valid_ujis(*(start)) && valid_ujis(*((start)+1))) { + return 2; + } + if (valid_ujis_ss2(*(start)) && valid_ujis_kata(*((start)+1))) { + return 2; + } + if (valid_ujis_ss3(*(start)) && (end-start) > 2 && valid_ujis(*((start)+1)) && valid_ujis(*((start)+2))) { + return 3; + } + return 0; +} + + +static unsigned int mysql_mbcharlen_ujis(unsigned int ujis) +{ + return (valid_ujis(ujis)? 2: valid_ujis_ss2(ujis)? 2: valid_ujis_ss3(ujis)? 3: 1); +} +/* }}} */ + + + +/* {{{ utf16 functions */ +#define UTF16_HIGH_HEAD(x) ((((uchar) (x)) & 0xFC) == 0xD8) +#define UTF16_LOW_HEAD(x) ((((uchar) (x)) & 0xFC) == 0xDC) + +static unsigned int check_mb_utf16(const char *start, const char *end) +{ + if (start + 2 > end) { + return 0; + } + + if (UTF16_HIGH_HEAD(*start)) { + return (start + 4 <= end) && UTF16_LOW_HEAD(start[2]) ? 4 : 0; + } + + if (UTF16_LOW_HEAD(*start)) { + return 0; + } + return 2; +} + + +static uint mysql_mbcharlen_utf16(unsigned int utf16) +{ + return UTF16_HIGH_HEAD(utf16) ? 4 : 2; +} +/* }}} */ + + +/* {{{ utf32 functions */ +static uint +check_mb_utf32(const char *start __attribute((unused)), const char *end __attribute((unused))) +{ + return 4; +} + + +static uint +mysql_mbcharlen_utf32(unsigned int utf32 __attribute((unused))) +{ + return 4; +} +/* }}} */ + +/* {{{ gb18030 functions */ +#define is_gb18030_odd(c) (0x81 <= (unsigned char) (c) && (unsigned char) (c) <= 0xFE) +#define is_gb18030_even_2(c) ((0x40 <= (unsigned char) (c) && (unsigned char) (c) <= 0x7E) || (0x80 <= (unsigned char) (c) && (unsigned char) (c) <= 0xFE)) +#define is_gb18030_even_4(c) (0x30 <= (unsigned char) (c) && (unsigned char) (c) <= 0x39) + + +static unsigned int mysql_mbcharlen_gb18030(unsigned int c) +{ + if (c <= 0xFF) { + return !is_gb18030_odd(c); + } + if (c > 0xFFFF || !is_gb18030_odd((c >> 8) & 0xFF)) { + return 0; + } + if (is_gb18030_even_2((c & 0xFF))) { + return 2; + } + if (is_gb18030_even_4((c & 0xFF))) { + return 4; + } + + return 0; +} + +static unsigned int check_mb_gb18030_valid(const char * start, const char * end) +{ + if (end - start <= 1 || !is_gb18030_odd(start[0])) { + return 0; + } + + if (is_gb18030_even_2(start[1])) { + return 2; + } else if (end - start > 3 && is_gb18030_even_4(start[1]) && is_gb18030_odd(start[2]) && is_gb18030_even_4(start[3])) { + return 4; + } + + return 0; +} +/* }}} */ + +/* + The server compiles sometimes the full utf-8 (the mb4) as utf8mb4, and the old as utf8, + for BC reasons. Sometimes, utf8mb4 is just utf8 but the old charsets are utf8mb3. + Change easily now, with a macro, could be made compilastion dependable. +*/ + +#define UTF8_MB4 "utf8mb4" +#define UTF8_MB3 "utf8mb3" + +/* {{{ mysql_charsets */ +const MARIADB_CHARSET_INFO mariadb_compiled_charsets[] = +{ + { 1, 1, "big5","big5_chinese_ci", "", 950, "BIG5", 1, 2, mysql_mbcharlen_big5, check_mb_big5}, + { 3, 1, "dec8", "dec8_swedish_ci", "", 0, "DEC", 1, 1, NULL, NULL}, + { 4, 1, "cp850", "cp850_general_ci", "", 850, "CP850", 1, 1, NULL, NULL}, + { 6, 1, "hp8", "hp8_english_ci", "", 0, "HP-ROMAN8", 1, 1, NULL, NULL}, + { 7, 1, "koi8r", "koi8r_general_ci", "", 20866, "KOI8R", 1, 1, NULL, NULL}, + { 8, 1, "latin1", "latin1_swedish_ci", "", 1252, "LATIN1", 1, 1, NULL, NULL}, + { 9, 1, "latin2", "latin2_general_ci", "", 852, "LATIN2", 1, 1, NULL, NULL}, + { 10, 1, "swe7", "swe7_swedish_ci", "", 20107, "", 1, 1, NULL, NULL}, + { 11, 1, "ascii", "ascii_general_ci", "", 1252, "ASCII", 1, 1, NULL, NULL}, + { 12, 1, "ujis", "ujis_japanese_ci", "", 20932, "UJIS", 1, 3, mysql_mbcharlen_ujis, check_mb_ujis}, + { 13, 1, "sjis", "sjis_japanese_ci", "", 932, "SJIS", 1, 2, mysql_mbcharlen_sjis, check_mb_sjis}, + { 16, 1, "hebrew", "hebrew_general_ci", "", 1255, "HEBREW", 1, 1, NULL, NULL}, + { 18, 1, "tis620", "tis620_thai_ci", "", 874, "TIS620", 1, 1, NULL, NULL}, + { 19, 1, "euckr", "euckr_korean_ci", "", 51949, "EUCKR", 1, 2, mysql_mbcharlen_euckr, check_mb_euckr}, + { 22, 1, "koi8u", "koi8u_general_ci", "", 21866, "KOI8U", 1, 1, NULL, NULL}, + { 24, 1, "gb2312", "gb2312_chinese_ci", "", 936, "GB2312", 1, 2, mysql_mbcharlen_gb2312, check_mb_gb2312}, + { 25, 1, "greek", "greek_general_ci", "", 28597, "GREEK", 1, 1, NULL, NULL}, + { 26, 1, "cp1250", "cp1250_general_ci", "", 1250, "CP1250", 1, 1, NULL, NULL}, + { 28, 1, "gbk", "gbk_chinese_ci", "", 936, "GBK", 1, 2, mysql_mbcharlen_gbk, check_mb_gbk}, + { 30, 1, "latin5", "latin5_turkish_ci", "", 1254, "LATIN5", 1, 1, NULL, NULL}, + { 32, 1, "armscii8", "armscii8_general_ci", "", 0, "ARMSCII-8", 1, 1, NULL, NULL}, + { 33, 1, UTF8_MB3, UTF8_MB3"_general_ci", "", 65001, "UTF-8", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid}, + { 35, 1, "ucs2", "ucs2_general_ci", "", 1200, "UCS-2BE", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2}, + { 36, 1, "cp866", "cp866_general_ci", "", 866, "CP866", 1, 1, NULL, NULL}, + { 37, 1, "keybcs2", "keybcs2_general_ci", "", 0, "", 1, 1, NULL, NULL}, + { 38, 1, "macce", "macce_general_ci", "", 10029, "CP1282", 1, 1, NULL, NULL}, + { 39, 1, "macroman", "macroman_general_ci", "", 10000, "MACINTOSH", 1, 1, NULL, NULL}, + { 40, 1, "cp852", "cp852_general_ci", "", 852, "CP852", 1, 1, NULL, NULL}, + { 41, 1, "latin7", "latin7_general_ci", "", 28603, "LATIN7", 1, 1, NULL, NULL}, + { 51, 1, "cp1251", "cp1251_general_ci", "", 1251, "CP1251", 1, 1, NULL, NULL}, + { 57, 1, "cp1256", "cp1256_general_ci", "", 1256, "CP1256", 1, 1, NULL, NULL}, + { 59, 1, "cp1257", "cp1257_general_ci", "", 1257, "CP1257", 1, 1, NULL, NULL}, + { 63, 1, "binary", "binary", "", 0, "ASCII", 1, 1, NULL, NULL}, + { 64, 1, "armscii8", "armscii8_bin", "", 0, "ARMSCII-8", 1, 1, NULL, NULL}, + { 92, 1, "geostd8", "geostd8_general_ci", "", 0, "GEORGIAN-PS", 1, 1, NULL, NULL}, + { 95, 1, "cp932", "cp932_japanese_ci", "", 932, "CP932", 1, 2, mysql_mbcharlen_cp932, check_mb_cp932}, + { 97, 1, "eucjpms", "eucjpms_japanese_ci", "", 932, "EUC-JP-MS", 1, 3, mysql_mbcharlen_eucjpms, check_mb_eucjpms}, + { 2, 1, "latin2", "latin2_czech_cs", "", 852, "LATIN2", 1, 1, NULL, NULL}, + { 5, 1, "latin1", "latin1_german1_ci", "", 1252, "LATIN1", 1, 1, NULL, NULL}, + { 14, 1, "cp1251", "cp1251_bulgarian_ci", "", 1251, "CP1251", 1, 1, NULL, NULL}, + { 15, 1, "latin1", "latin1_danish_ci", "", 1252, "LATIN1", 1, 1, NULL, NULL}, + { 17, 1, "filename", "filename", "", 0, "", 1, 5, NULL, NULL}, + { 20, 1, "latin7", "latin7_estonian_cs", "", 28603, "LATIN7", 1, 1, NULL, NULL}, + { 21, 1, "latin2", "latin2_hungarian_ci", "", 852, "LATIN2", 1, 1, NULL, NULL}, + { 23, 1, "cp1251", "cp1251_ukrainian_ci", "", 1251, "CP1251", 1, 1, NULL, NULL}, + { 27, 1, "latin2", "latin2_croatian_ci", "", 852, "LATIN2", 1, 1, NULL, NULL}, + { 29, 1, "cp1257", "cp1257_lithuanian_ci", "", 1257, "CP1257", 1, 1, NULL, NULL}, + { 31, 1, "latin1", "latin1_german2_ci", "", 1252, "LATIN1", 1, 1, NULL, NULL}, + { 34, 1, "cp1250", "cp1250_czech_cs", "", 1250, "CP1250", 1, 1, NULL, NULL}, + { 42, 1, "latin7", "latin7_general_cs", "", 28603, "LATIN7", 1, 1, NULL, NULL}, + { 43, 1, "macce", "macce_bin", "", 10029, "CP1282", 1, 1, NULL, NULL}, + { 44, 1, "cp1250", "cp1250_croatian_ci", "", 1250, "CP1250", 1, 1, NULL, NULL}, + { 45, 1, UTF8_MB4, UTF8_MB4"_general_ci", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 46, 1, UTF8_MB4, UTF8_MB4"_bin", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 47, 1, "latin1", "latin1_bin", "", 1250, "LATIN1", 1, 1, NULL, NULL}, + { 48, 1, "latin1", "latin1_general_ci", "", 1250, "LATIN1", 1, 1, NULL, NULL}, + { 49, 1, "latin1", "latin1_general_cs", "", 1250, "LATIN1", 1, 1, NULL, NULL}, + { 50, 1, "cp1251", "cp1251_bin", "", 1251, "CP1251", 1, 1, NULL, NULL}, + { 52, 1, "cp1251", "cp1251_general_cs", "", 1251, "CP1251", 1, 1, NULL, NULL}, + { 53, 1, "macroman", "macroman_bin", "", 10000, "MACINTOSH", 1, 1, NULL, NULL}, + { 54, 1, "utf16", "utf16_general_ci", "", 0, "UTF16", 2, 4, mysql_mbcharlen_utf16, check_mb_utf16}, + { 55, 1, "utf16", "utf16_bin", "", 0, "UTF16", 2, 4, mysql_mbcharlen_utf16, check_mb_utf16}, + { 56, 1, "utf16le", "utf16_general_ci", "", 1200, "UTF16LE", 2, 4, mysql_mbcharlen_utf16, check_mb_utf16}, + { 58, 1, "cp1257", "cp1257_bin", "", 1257, "CP1257", 1, 1, NULL, NULL}, +#ifdef USED_TO_BE_SO_BEFORE_MYSQL_5_5 + { 60, 1, "armascii8", "armascii8_bin", "", 0, "ARMSCII-8", 1, 1, NULL, NULL}, +#endif + { 60, 1, "utf32", "utf32_general_ci", "", 0, "UTF32", 4, 4, mysql_mbcharlen_utf32, check_mb_utf32}, + { 61, 1, "utf32", "utf32_bin", "", 0, "UTF32", 4, 4, mysql_mbcharlen_utf32, check_mb_utf32}, + { 62, 1, "utf16le", "utf16_bin", "", 1200, "UTF16LE", 2, 4, mysql_mbcharlen_utf16, check_mb_utf16}, + { 65, 1, "ascii", "ascii_bin", "", 1252, "ASCII", 1, 1, NULL, NULL}, + { 66, 1, "cp1250", "cp1250_bin", "", 1250, "CP1250", 1, 1, NULL, NULL}, + { 67, 1, "cp1256", "cp1256_bin", "", 1256, "CP1256", 1, 1, NULL, NULL}, + { 68, 1, "cp866", "cp866_bin", "", 866, "CP866", 1, 1, NULL, NULL}, + { 69, 1, "dec8", "dec8_bin", "", 0, "DEC", 1, 1, NULL, NULL}, + { 70, 1, "greek", "greek_bin", "", 28597, "GREEK", 1, 1, NULL, NULL}, + { 71, 1, "hebrew", "hebrew_bin", "", 1255, "hebrew", 1, 1, NULL, NULL}, + { 72, 1, "hp8", "hp8_bin", "", 0, "HPROMAN-8", 1, 1, NULL, NULL}, + { 73, 1, "keybcs2", "keybcs2_bin", "", 0, "", 1, 1, NULL, NULL}, + { 74, 1, "koi8r", "koi8r_bin", "", 20866, "KOI8R", 1, 1, NULL, NULL}, + { 75, 1, "koi8u", "koi8u_bin", "", 21866, "KOI8U", 1, 1, NULL, NULL}, + { 76, 1, UTF8_MB3, UTF8_MB3"_tolower_ci", "", 65001, "UTF-8", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid}, + { 77, 1, "latin2", "latin2_bin", "", 28592, "LATIN2", 1, 1, NULL, NULL}, + { 78, 1, "latin5", "latin5_bin", "", 1254, "LATIN5", 1, 1, NULL, NULL}, + { 79, 1, "latin7", "latin7_bin", "", 28603, "LATIN7", 1, 1, NULL, NULL}, + { 80, 1, "cp850", "cp850_bin", "", 850, "CP850", 1, 1, NULL, NULL}, + { 81, 1, "cp852", "cp852_bin", "", 852, "CP852", 1, 1, NULL, NULL}, + { 82, 1, "swe7", "swe7_bin", "", 0, "", 1, 1, NULL, NULL}, + { 93, 1, "geostd8", "geostd8_bin", "", 0, "GEORGIAN-PS", 1, 1, NULL, NULL}, + { 83, 1, UTF8_MB3, UTF8_MB3"_bin", "", 65001, "UTF-8", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid}, + { 84, 1, "big5", "big5_bin", "", 65000, "BIG5", 1, 2, mysql_mbcharlen_big5, check_mb_big5}, + { 85, 1, "euckr", "euckr_bin", "", 51949, "EUCKR", 1, 2, mysql_mbcharlen_euckr, check_mb_euckr}, + { 86, 1, "gb2312", "gb2312_bin", "", 936, "GB2312", 1, 2, mysql_mbcharlen_gb2312, check_mb_gb2312}, + { 87, 1, "gbk", "gbk_bin", "", 936, "GBK", 1, 2, mysql_mbcharlen_gbk, check_mb_gbk}, + { 88, 1, "sjis", "sjis_bin", "", 932, "SJIS", 1, 2, mysql_mbcharlen_sjis, check_mb_sjis}, + { 89, 1, "tis620", "tis620_bin", "", 874, "TIS620", 1, 1, NULL, NULL}, + { 90, 1, "ucs2", "ucs2_bin", "", 1200, "UCS-2BE", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2}, + { 91, 1, "ujis", "ujis_bin", "", 20932, "UJIS", 1, 3, mysql_mbcharlen_ujis, check_mb_ujis}, + { 94, 1, "latin1", "latin1_spanish_ci", "", 1252, "LATIN1", 1, 1, NULL, NULL}, + { 96, 1, "cp932", "cp932_bin", "", 932, "CP932", 1, 2, mysql_mbcharlen_cp932, check_mb_cp932}, + { 99, 1, "cp1250", "cp1250_polish_ci", "", 1250, "CP1250", 1, 1, NULL, NULL}, + { 98, 1, "eucjpms", "eucjpms_bin", "", 932, "EUCJP-MS", 1, 3, mysql_mbcharlen_eucjpms, check_mb_eucjpms}, + { 101, 1, "utf16", "utf16_unicode_ci", "", 0, "UTF16", 2, 4, mysql_mbcharlen_utf16, check_mb_utf16}, + { 102, 1, "utf16", "utf16_icelandic_ci", "", 0, "UTF16", 2, 4, mysql_mbcharlen_utf16, check_mb_utf16}, + { 103, 1, "utf16", "utf16_latvian_ci", "", 0, "UTF16", 2, 4, mysql_mbcharlen_utf16, check_mb_utf16}, + { 104, 1, "utf16", "utf16_romanian_ci", "", 0, "UTF16", 2, 4, mysql_mbcharlen_utf16, check_mb_utf16}, + { 105, 1, "utf16", "utf16_slovenian_ci", "", 0, "UTF16", 2, 4, mysql_mbcharlen_utf16, check_mb_utf16}, + { 106, 1, "utf16", "utf16_polish_ci", "", 0, "UTF16", 2, 4, mysql_mbcharlen_utf16, check_mb_utf16}, + { 107, 1, "utf16", "utf16_estonian_ci", "", 0, "UTF16", 2, 4, mysql_mbcharlen_utf16, check_mb_utf16}, + { 108, 1, "utf16", "utf16_spanish_ci", "", 0, "UTF16", 2, 4, mysql_mbcharlen_utf16, check_mb_utf16}, + { 109, 1, "utf16", "utf16_swedish_ci", "", 0, "UTF16", 2, 4, mysql_mbcharlen_utf16, check_mb_utf16}, + { 110, 1, "utf16", "utf16_turkish_ci", "", 0, "UTF16", 2, 4, mysql_mbcharlen_utf16, check_mb_utf16}, + { 111, 1, "utf16", "utf16_czech_ci", "", 0, "UTF16", 2, 4, mysql_mbcharlen_utf16, check_mb_utf16}, + { 112, 1, "utf16", "utf16_danish_ci", "", 0, "UTF16", 2, 4, mysql_mbcharlen_utf16, check_mb_utf16}, + { 113, 1, "utf16", "utf16_lithunian_ci", "", 0, "UTF16", 2, 4, mysql_mbcharlen_utf16, check_mb_utf16}, + { 114, 1, "utf16", "utf16_slovak_ci", "", 0, "UTF16", 2, 4, mysql_mbcharlen_utf16, check_mb_utf16}, + { 115, 1, "utf16", "utf16_spanish2_ci", "", 0, "UTF16", 2, 4, mysql_mbcharlen_utf16, check_mb_utf16}, + { 116, 1, "utf16", "utf16_roman_ci", "", 0, "UTF16", 2, 4, mysql_mbcharlen_utf16, check_mb_utf16}, + { 117, 1, "utf16", "utf16_persian_ci", "", 0, "UTF16", 2, 4, mysql_mbcharlen_utf16, check_mb_utf16}, + { 118, 1, "utf16", "utf16_esperanto_ci", "", 0, "UTF16", 2, 4, mysql_mbcharlen_utf16, check_mb_utf16}, + { 120, 1, "utf16", "utf16_sinhala_ci", "", 0, "UTF16", 2, 4, mysql_mbcharlen_utf16, check_mb_utf16}, + { 121, 1, "utf16", "utf16_german2_ci", "", 0, "UTF16", 2, 4, mysql_mbcharlen_utf16, check_mb_utf16}, + { 122, 1, "utf16", "utf16_croatian_mysql561_ci", "", 0, "UTF16", 2, 4, mysql_mbcharlen_utf16, check_mb_utf16}, + { 123, 1, "utf16", "utf16_unicode_520_ci", "", 0, "UTF16", 2, 4, mysql_mbcharlen_utf16, check_mb_utf16}, + { 124, 1, "utf16", "utf16_vietnamese_ci", "", 0, "UTF16", 2, 4, mysql_mbcharlen_utf16, check_mb_utf16}, + { 128, 1, "ucs2", "ucs2_unicode_ci", "", 1200, "UCS-2BE", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2}, + { 129, 1, "ucs2", "ucs2_icelandic_ci", "", 1200, "UCS-2BE", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2}, + { 130, 1, "ucs2", "ucs2_latvian_ci", "", 1200, "UCS-2BE", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2}, + { 131, 1, "ucs2", "ucs2_romanian_ci", "", 1200, "UCS2-BE", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2}, + { 132, 1, "ucs2", "ucs2_slovenian_ci", "", 1200, "UCS2-BE", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2}, + { 133, 1, "ucs2", "ucs2_polish_ci", "", 1200, "UCS2-BE", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2}, + { 134, 1, "ucs2", "ucs2_estonian_ci", "", 1200, "UCS2-BE", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2}, + { 135, 1, "ucs2", "ucs2_spanish_ci", "", 1200, "UCS2-BE", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2}, + { 136, 1, "ucs2", "ucs2_swedish_ci", "", 1200, "UCS2-BE", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2}, + { 137, 1, "ucs2", "ucs2_turkish_ci", "", 1200, "UCS2-BE", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2}, + { 138, 1, "ucs2", "ucs2_czech_ci", "", 1200, "UCS2-BE", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2}, + { 139, 1, "ucs2", "ucs2_danish_ci", "", 1200, "UCS2-BE", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2}, + { 140, 1, "ucs2", "ucs2_lithuanian_ci", "", 1200, "UCS2-BE", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2}, + { 141, 1, "ucs2", "ucs2_slovak_ci", "", 1200, "UCS2-BE", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2}, + { 142, 1, "ucs2", "ucs2_spanish2_ci", "", 1200, "UCS2-BE", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2}, + { 143, 1, "ucs2", "ucs2_roman_ci", "", 1200, "UCS2-BE", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2}, + { 144, 1, "ucs2", "ucs2_persian_ci", "", 1200, "UCS2-BE", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2}, + { 145, 1, "ucs2", "ucs2_esperanto_ci", "", 1200, "UCS2-BE", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2}, + { 146, 1, "ucs2", "ucs2_hungarian_ci", "", 1200, "UCS2-BE", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2}, + { 147, 1, "ucs2", "ucs2_sinhala_ci", "", 1200, "UCS2-BE", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2}, + { 148, 1, "ucs2", "ucs2_german2_ci", "", 1200, "UCS2-BE", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2}, + { 149, 1, "ucs2", "ucs2_croatian_ci", "", 1200, "UCS2-BE", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2}, /* MDB */ + { 150, 1, "ucs2", "ucs2_unicode_520_ci", "", 1200, "UCS2-BE", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2}, /* MDB */ + { 151, 1, "ucs2", "ucs2_vietnamese_ci", "", 1200, "UCS2-BE", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2}, /* MDB */ + { 159, 1, "ucs2", "ucs2_general_mysql500_ci", "", 1200, "UCS2-BE", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2}, /* MDB */ + { 160, 1, "utf32", "utf32_unicode_ci", "", 0, "UTF32", 4, 4, mysql_mbcharlen_utf32, check_mb_utf32}, + { 161, 1, "utf32", "utf32_icelandic_ci", "", 0, "UTF32", 4, 4, mysql_mbcharlen_utf32, check_mb_utf32}, + { 162, 1, "utf32", "utf32_latvian_ci", "", 0, "UTF32", 4, 4, mysql_mbcharlen_utf32, check_mb_utf32}, + { 163, 1, "utf32", "utf32_romanian_ci", "", 0, "UTF32", 4, 4, mysql_mbcharlen_utf32, check_mb_utf32}, + { 164, 1, "utf32", "utf32_slovenian_ci", "", 0, "UTF32", 4, 4, mysql_mbcharlen_utf32, check_mb_utf32}, + { 165, 1, "utf32", "utf32_polish_ci", "", 0, "UTF32", 4, 4, mysql_mbcharlen_utf32, check_mb_utf32}, + { 166, 1, "utf32", "utf32_estonian_ci", "", 0, "UTF32", 4, 4, mysql_mbcharlen_utf32, check_mb_utf32}, + { 167, 1, "utf32", "utf32_spanish_ci", "", 0, "UTF32", 4, 4, mysql_mbcharlen_utf32, check_mb_utf32}, + { 168, 1, "utf32", "utf32_swedish_ci", "", 0, "UTF32", 4, 4, mysql_mbcharlen_utf32, check_mb_utf32}, + { 169, 1, "utf32", "utf32_turkish_ci", "", 0, "UTF32", 4, 4, mysql_mbcharlen_utf32, check_mb_utf32}, + { 170, 1, "utf32", "utf32_czech_ci", "", 0, "UTF32", 4, 4, mysql_mbcharlen_utf32, check_mb_utf32}, + { 171, 1, "utf32", "utf32_danish_ci", "", 0, "UTF32", 4, 4, mysql_mbcharlen_utf32, check_mb_utf32}, + { 172, 1, "utf32", "utf32_lithuanian_ci", "", 0, "UTF32", 4, 4, mysql_mbcharlen_utf32, check_mb_utf32}, + { 173, 1, "utf32", "utf32_slovak_ci", "", 0, "UTF32", 4, 4, mysql_mbcharlen_utf32, check_mb_utf32}, + { 174, 1, "utf32", "utf32_spanish_ci", "", 0, "UTF32", 4, 4, mysql_mbcharlen_utf32, check_mb_utf32}, + { 175, 1, "utf32", "utf32_roman_ci", "", 0, "UTF32", 4, 4, mysql_mbcharlen_utf32, check_mb_utf32}, + { 176, 1, "utf32", "utf32_persian_ci", "", 0, "UTF32", 4, 4, mysql_mbcharlen_utf32, check_mb_utf32}, + { 177, 1, "utf32", "utf32_esperanto_ci", "", 0, "UTF32", 4, 4, mysql_mbcharlen_utf32, check_mb_utf32}, + { 178, 1, "utf32", "utf32_hungarian_ci", "", 0, "UTF32", 4, 4, mysql_mbcharlen_utf32, check_mb_utf32}, + { 179, 1, "utf32", "utf32_sinhala_ci", "", 0, "UTF32", 4, 4, mysql_mbcharlen_utf32, check_mb_utf32}, + { 180, 1, "utf32", "utf32_german2_ci", "", 0, "UTF32", 4, 4, mysql_mbcharlen_utf32, check_mb_utf32}, + { 181, 1, "utf32", "utf32_croatian_mysql561_ci", "", 0, "UTF32", 4, 4, mysql_mbcharlen_utf32, check_mb_utf32}, + { 182, 1, "utf32", "utf32_unicode_520_ci", "", 0, "UTF32", 4, 4, mysql_mbcharlen_utf32, check_mb_utf32}, + { 183, 1, "utf32", "utf32_vietnamese_ci", "", 0, "UTF32", 4, 4, mysql_mbcharlen_utf32, check_mb_utf32}, + + { 192, 1, UTF8_MB3, UTF8_MB3"_general_ci", "", 65001, "UTF-8", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid}, + { 193, 1, UTF8_MB3, UTF8_MB3"_icelandic_ci", "", 65001, "UTF-8", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid}, + { 194, 1, UTF8_MB3, UTF8_MB3"_latvian_ci", "", 65001, "UTF-8", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid}, + { 195, 1, UTF8_MB3, UTF8_MB3"_romanian_ci", "", 65001, "UTF-8", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid}, + { 196, 1, UTF8_MB3, UTF8_MB3"_slovenian_ci", "", 65001, "UTF-8", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid}, + { 197, 1, UTF8_MB3, UTF8_MB3"_polish_ci", "", 65001, "UTF-8", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid}, + { 198, 1, UTF8_MB3, UTF8_MB3"_estonian_ci", "", 65001, "UTF-8", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid}, + { 199, 1, UTF8_MB3, UTF8_MB3"_spanish_ci", "", 65001, "UTF-8", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid}, + { 119, 1, UTF8_MB3, UTF8_MB3"_spanish_ci", "", 65001, "UTF-8", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid}, + { 200, 1, UTF8_MB3, UTF8_MB3"_swedish_ci", "", 65001, "UTF-8", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid}, + { 201, 1, UTF8_MB3, UTF8_MB3"_turkish_ci", "", 65001, "UTF-8", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid}, + { 202, 1, UTF8_MB3, UTF8_MB3"_czech_ci", "", 65001, "UTF-8", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid}, + { 203, 1, UTF8_MB3, UTF8_MB3"_danish_ci", "", 65001, "UTF-8", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid }, + { 204, 1, UTF8_MB3, UTF8_MB3"_lithuanian_ci", "", 65001, "UTF-8", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid }, + { 205, 1, UTF8_MB3, UTF8_MB3"_slovak_ci", "", 65001, "UTF-8", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid}, + { 206, 1, UTF8_MB3, UTF8_MB3"_spanish2_ci", "", 65001, "UTF-8", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid}, + { 207, 1, UTF8_MB3, UTF8_MB3"_roman_ci", "", 65001, "UTF-8", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid}, + { 208, 1, UTF8_MB3, UTF8_MB3"_persian_ci", "", 65001, "UTF-8", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid}, + { 209, 1, UTF8_MB3, UTF8_MB3"_esperanto_ci", "", 65001, "UTF-8", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid}, + { 210, 1, UTF8_MB3, UTF8_MB3"_hungarian_ci", "", 65001, "UTF-8", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid}, + { 211, 1, UTF8_MB3, UTF8_MB3"_sinhala_ci", "", 65001, "UTF-8", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid}, + { 212, 1, UTF8_MB3, UTF8_MB3"_german2_ci", "", 65001, "UTF-8", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid}, + { 214, 1, UTF8_MB3, UTF8_MB3"_unicode_520_ci", "", 65001, "UTF-8", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid}, + { 215, 1, UTF8_MB3, UTF8_MB3"_vietnamese_ci", "", 65001, "UTF-8", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid}, + { 213, 1, UTF8_MB3, UTF8_MB3"_croatian_ci", "", 65001, "UTF-8", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid}, /*MDB*/ + { 223, 1, UTF8_MB3, UTF8_MB3"_general_mysql500_ci", "", 65001, "UTF-8", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid}, /*MDB*/ + + { 224, 1, UTF8_MB4, UTF8_MB4"_unicode_ci", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 225, 1, UTF8_MB4, UTF8_MB4"_icelandic_ci", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 226, 1, UTF8_MB4, UTF8_MB4"_latvian_ci", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 227, 1, UTF8_MB4, UTF8_MB4"_romanian_ci", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 228, 1, UTF8_MB4, UTF8_MB4"_slovenian_ci", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 229, 1, UTF8_MB4, UTF8_MB4"_polish_ci", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 230, 1, UTF8_MB4, UTF8_MB4"_estonian_ci", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 231, 1, UTF8_MB4, UTF8_MB4"_spanish_ci", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 232, 1, UTF8_MB4, UTF8_MB4"_swedish_ci", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 233, 1, UTF8_MB4, UTF8_MB4"_turkish_ci", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 234, 1, UTF8_MB4, UTF8_MB4"_czech_ci", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 235, 1, UTF8_MB4, UTF8_MB4"_danish_ci", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 236, 1, UTF8_MB4, UTF8_MB4"_lithuanian_ci", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 237, 1, UTF8_MB4, UTF8_MB4"_slovak_ci", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 238, 1, UTF8_MB4, UTF8_MB4"_spanish2_ci", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 239, 1, UTF8_MB4, UTF8_MB4"_roman_ci", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 240, 1, UTF8_MB4, UTF8_MB4"_persian_ci", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 241, 1, UTF8_MB4, UTF8_MB4"_esperanto_ci", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 242, 1, UTF8_MB4, UTF8_MB4"_hungarian_ci", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 243, 1, UTF8_MB4, UTF8_MB4"_sinhala_ci", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 244, 1, UTF8_MB4, UTF8_MB4"_german2_ci", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 245, 1, UTF8_MB4, UTF8_MB4"_croatian_mysql561_ci", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 246, 1, UTF8_MB4, UTF8_MB4"_unicode_520_ci", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 247, 1, UTF8_MB4, UTF8_MB4"_vietnamese_ci", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 248, 1, "gb18030", "gb18030_chinese_ci", "", 54936, "GB18030", 1, 4, mysql_mbcharlen_gb18030, check_mb_gb18030_valid}, + { 249, 1, "gb18030", "gb18030_bin", "", 54936, "GB18030", 1, 4, mysql_mbcharlen_gb18030, check_mb_gb18030_valid}, + { 250, 1, "gb18030", "gb18030_unicode_520_ci", "", 54936, "GB18030", 1, 4, mysql_mbcharlen_gb18030, check_mb_gb18030_valid}, + + + { 254, 1, UTF8_MB3, UTF8_MB3"_general_cs", "", 65001, "UTF-8", 1, 3, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + + { 255, 1, UTF8_MB4, UTF8_MB4"_0900_ai_ci", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 256, 1, UTF8_MB4, UTF8_MB4"_de_pb_0900_ai_ci", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 257, 1, UTF8_MB4, UTF8_MB4"_is_0900_ai_ci", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 258, 1, UTF8_MB4, UTF8_MB4"_lv_0900_ai_ci", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 259, 1, UTF8_MB4, UTF8_MB4"_ro_0900_ai_ci", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 260, 1, UTF8_MB4, UTF8_MB4"_sl_0900_ai_ci", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 261, 1, UTF8_MB4, UTF8_MB4"_pl_0900_ai_ci", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 262, 1, UTF8_MB4, UTF8_MB4"_et_0900_ai_ci", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 263, 1, UTF8_MB4, UTF8_MB4"_es_0900_ai_ci", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 264, 1, UTF8_MB4, UTF8_MB4"_sv_0900_ai_ci", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 265, 1, UTF8_MB4, UTF8_MB4"_tr_0900_ai_ci", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 266, 1, UTF8_MB4, UTF8_MB4"_cs_0900_ai_ci", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 267, 1, UTF8_MB4, UTF8_MB4"_da_0900_ai_ci", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 268, 1, UTF8_MB4, UTF8_MB4"_lt_0900_ai_ci", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 269, 1, UTF8_MB4, UTF8_MB4"_sk_0900_ai_ci", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 270, 1, UTF8_MB4, UTF8_MB4"_es_trad_0900_ai_ci", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 271, 1, UTF8_MB4, UTF8_MB4"_la_0900_ai_ci", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 273, 1, UTF8_MB4, UTF8_MB4"_eo_0900_ai_ci", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 274, 1, UTF8_MB4, UTF8_MB4"_hu_0900_ai_ci", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 275, 1, UTF8_MB4, UTF8_MB4"_hr_0900_ai_ci", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 277, 1, UTF8_MB4, UTF8_MB4"_vi_0900_ai_ci", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 278, 1, UTF8_MB4, UTF8_MB4"_0900_as_cs", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 279, 1, UTF8_MB4, UTF8_MB4"_de_pb__0900_as_cs", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 280, 1, UTF8_MB4, UTF8_MB4"_is_0900_as_cs", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 281, 1, UTF8_MB4, UTF8_MB4"_lv_0900_as_cs", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 282, 1, UTF8_MB4, UTF8_MB4"_ro_0900_as_cs", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 283, 1, UTF8_MB4, UTF8_MB4"_sl_0900_as_cs", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 284, 1, UTF8_MB4, UTF8_MB4"_pl_0900_as_cs", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 285, 1, UTF8_MB4, UTF8_MB4"_et_0900_as_cs", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 286, 1, UTF8_MB4, UTF8_MB4"_es_0900_as_cs", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 287, 1, UTF8_MB4, UTF8_MB4"_sv_0900_as_cs", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 288, 1, UTF8_MB4, UTF8_MB4"_tr_0900_as_cs", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 289, 1, UTF8_MB4, UTF8_MB4"_cs_0900_as_cs", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 290, 1, UTF8_MB4, UTF8_MB4"_da_0900_as_cs", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 291, 1, UTF8_MB4, UTF8_MB4"_lt_0900_as_cs", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 292, 1, UTF8_MB4, UTF8_MB4"_sk_0900_as_cs", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 293, 1, UTF8_MB4, UTF8_MB4"_es_trad_0900_as_cs", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 294, 1, UTF8_MB4, UTF8_MB4"_la_0900_as_cs", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 296, 1, UTF8_MB4, UTF8_MB4"_eo_0900_as_cs", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 297, 1, UTF8_MB4, UTF8_MB4"_hu_0900_as_cs", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 298, 1, UTF8_MB4, UTF8_MB4"_hr_0900_as_cs", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 300, 1, UTF8_MB4, UTF8_MB4"_vi_0900_as_cs", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 303, 1, UTF8_MB4, UTF8_MB4"_ja_0900_as_cs", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 304, 1, UTF8_MB4, UTF8_MB4"_ja_0900_as_cs_ks", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 305, 1, UTF8_MB4, UTF8_MB4"_0900_as_ci", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 306, 1, UTF8_MB4, UTF8_MB4"_ru_0900_as_ci", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 307, 1, UTF8_MB4, UTF8_MB4"_ru_0900_as_cs", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 576, 1, UTF8_MB3, UTF8_MB3"_croatian_ci", "", 65001, "UTF-8", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid}, /*MDB*/ + { 577, 1, UTF8_MB3, UTF8_MB3"_myanmar_ci", "", 65001, "UTF-8", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid}, /*MDB*/ + { 578, 1, UTF8_MB3, UTF8_MB3"_thai_520_w2", "", 65001, "UTF-8", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid}, /*MDB*/ + { 608, 1, UTF8_MB4, UTF8_MB4"_croatian_ci", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 609, 1, UTF8_MB4, UTF8_MB4"_myanmar_ci", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 610, 1, UTF8_MB4, UTF8_MB4"_thai_520_w2", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 640, 1, "ucs2", "ucs2_croatian_ci", "", 1200, "UCS2-BE", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2}, + { 641, 1, "ucs2", "ucs2_myanmar_ci", "", 1200, "UCS2-BE", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2}, + { 642, 1, "ucs2", "ucs2_thai_520_w2", "", 1200, "UCS2-BE", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2}, + { 672, 1, "utf16", "utf16_croatian_ci", "", 0, "UTF16", 2, 4, mysql_mbcharlen_utf16, check_mb_utf16}, + { 673, 1, "utf16", "utf16_myanmar_ci", "", 0, "UTF16", 2, 4, mysql_mbcharlen_utf16, check_mb_utf16}, + { 674, 1, "utf16", "utf16_thai_520_w2", "", 0, "UTF16", 2, 4, mysql_mbcharlen_utf16, check_mb_utf16}, + { 736, 1, "utf32", "utf32_croatian_ci", "", 0, "UTF32", 4, 4, mysql_mbcharlen_utf32, check_mb_utf32}, + { 737, 1, "utf32", "utf32_myanmar_ci", "", 0, "UTF32", 4, 4, mysql_mbcharlen_utf32, check_mb_utf32}, + { 738, 1, "utf32", "utf32_thai_520_w2", "", 0, "UTF32", 4, 4, mysql_mbcharlen_utf32, check_mb_utf32}, + {1025, 1, "big5","big5_chinese_nopad_ci", "", 950, "BIG5", 1, 2, mysql_mbcharlen_big5, check_mb_big5}, + {1027, 1, "dec8", "dec8_swedisch_nopad_ci", "", 0, "DEC", 1, 1, NULL, NULL}, + {1028, 1, "cp850", "cp850_general_nopad_ci", "", 850, "CP850", 1, 1, NULL, NULL}, + {1030, 1, "hp8", "hp8_english_nopad_ci", "", 0, "HP-ROMAN8", 1, 1, NULL, NULL}, + {1031, 1, "koi8r", "koi8r_general_nopad_ci", "", 878, "KOI8R", 1, 1, NULL, NULL}, + {1032, 1, "latin1", "latin1_swedish_nopad_ci", "", 850, "LATIN1", 1, 1, NULL, NULL}, + {1033, 1, "latin2", "latin2_general_nopad_ci", "", 852, "LATIN2", 1, 1, NULL, NULL}, + {1034, 1, "swe7", "swe7_swedish_nopad_ci", "", 20107, "", 1, 1, NULL, NULL}, + {1035, 1, "ascii", "ascii_general_nopad_ci", "", 1252, "ASCII", 1, 1, NULL, NULL}, + {1036, 1, "ujis", "ujis_japanese_nopad_ci", "", 20932, "UJIS", 1, 3, mysql_mbcharlen_ujis, check_mb_ujis}, + {1037, 1, "sjis", "sjis_japanese_nopad_ci", "", 932, "SJIS", 1, 2, mysql_mbcharlen_sjis, check_mb_sjis}, + {1040, 1, "hebrew", "hebrew_general_nopad_ci", "", 1255, "HEBREW", 1, 1, NULL, NULL}, + {1042, 1, "tis620", "tis620_thai_nopad_ci", "", 874, "TIS620", 1, 1, NULL, NULL}, + {1043, 1, "euckr", "euckr_korean_nopad_ci", "", 51949, "EUCKR", 1, 2, mysql_mbcharlen_euckr, check_mb_euckr}, + {1046, 1, "koi8u", "koi8u_general_nopad_ci", "", 20866, "KOI8U", 1, 1, NULL, NULL}, + {1048, 1, "gb2312", "gb2312_chinese_nopad_ci", "", 936, "GB2312", 1, 2, mysql_mbcharlen_gb2312, check_mb_gb2312}, + {1049, 1, "greek", "greek_general_nopad_ci", "", 28597, "GREEK", 1, 1, NULL, NULL}, + {1050, 1, "cp1250", "cp1250_general_nopad_ci", "", 1250, "CP1250", 1, 1, NULL, NULL}, + {1052, 1, "gbk", "gbk_chinese_nopad_ci", "", 936, "GBK", 1, 2, mysql_mbcharlen_gbk, check_mb_gbk}, + {1054, 1, "latin5", "latin5_turkish_nopad_ci", "", 1254, "LATIN5", 1, 1, NULL, NULL}, + {1056, 1, "armscii8", "armscii8_general_nopad_ci", "", 0, "ARMSCII-8", 1, 1, NULL, NULL}, + {1057, 1, UTF8_MB3, UTF8_MB3"_general_nopad_ci", "", 65001, "UTF-8", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid}, + {1059, 1, "ucs2", "ucs2_general_nopad_ci", "", 1200, "UCS-2BE", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2}, + {1060, 1, "cp866", "cp866_general_nopad_ci", "", 866, "CP866", 1, 1, NULL, NULL}, + {1061, 1, "keybcs2", "keybcs2_general_nopad_ci", "", 0, "", 1, 1, NULL, NULL}, + {1062, 1, "macce", "macce_general_nopad_ci", "", 10029, "CP1282", 1, 1, NULL, NULL}, + {1063, 1, "macroman", "macroman_general_nopad_ci", "", 10000, "MACINTOSH", 1, 1, NULL, NULL}, + {1064, 1, "cp852", "cp852_general_nopad_ci", "", 852, "CP852", 1, 1, NULL, NULL}, + {1065, 1, "latin7", "latin7_general_nopad_ci", "", 28603, "LATIN7", 1, 1, NULL, NULL}, + {1067, 1, "macce", "macce_nopad_bin", "", 10029, "CP1282", 1, 1, NULL, NULL}, + {1069, 1, UTF8_MB4, UTF8_MB4"_general_nopad_ci", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + {1070, 1, UTF8_MB4, UTF8_MB4"_general_nopad_bin", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + {1071, 1, "latin1", "latin1_nopad_bin", "", 850, "LATIN1", 1, 1, NULL, NULL}, + {1074, 1, "cp1251", "cp1251_nopad_bin", "", 1251, "CP1251", 1, 1, NULL, NULL}, + {1075, 1, "cp1251", "cp1251_general_nopad_ci", "", 1251, "CP1251", 1, 1, NULL, NULL}, + {1077, 1, "macroman", "macroman_nopad_bin", "", 10000, "MACINTOSH", 1, 1, NULL, NULL}, + {1078, 1, "utf16", "utf16_general_nopad_ci", "", 0, "UTF16", 2, 4, mysql_mbcharlen_utf16, check_mb_utf16}, + {1079, 1, "utf16", "utf16_nopad_bin", "", 0, "UTF16", 2, 4, mysql_mbcharlen_utf16, check_mb_utf16}, + {1080, 1, "utf16le", "utf16le_general_nopad_ci", "", 1200, "UTF16LE", 2, 4, mysql_mbcharlen_utf16, check_mb_utf16}, + {1081, 1, "cp1256", "cp1256_general_nopad_ci", "", 1256, "CP1256", 1, 1, NULL, NULL}, + {1082, 1, "cp1257", "cp1257_nopad_bin", "", 1257, "CP1257", 1, 1, NULL, NULL}, + {1083, 1, "cp1257", "cp1257_general_nopad_ci", "", 1257, "CP1257", 1, 1, NULL, NULL}, + {1084, 1, "utf32", "utf32_general_nopad_ci", "", 0, "UTF32", 4, 4, mysql_mbcharlen_utf32, check_mb_utf32}, + {1085, 1, "utf32", "utf32_nopad_bin", "", 0, "UTF32", 4, 4, mysql_mbcharlen_utf32, check_mb_utf32}, + {1086, 1, "utf16le", "utf16le_nopad_bin", "", 1200, "UTF16LE", 2, 4, mysql_mbcharlen_utf16, check_mb_utf16}, + {1088, 1, "armscii8", "armscii8_nopad_bin", "", 0, "ARMSCII-8", 1, 1, NULL, NULL}, + {1089, 1, "ascii", "ascii_nopad_bin", "", 1252, "ASCII", 1, 1, NULL, NULL}, + {1090, 1, "cp1250", "cp1250_nopad_bin", "", 1250, "CP1250", 1, 1, NULL, NULL}, + {1091, 1, "cp1256", "cp1256_nopad_bin", "", 1256, "CP1256", 1, 1, NULL, NULL}, + {1092, 1, "cp866", "cp866_nopad_bin", "", 866, "CP866", 1, 1, NULL, NULL}, + {1093, 1, "dec8", "dec8_nopad_bin", "", 0, "DEC", 1, 1, NULL, NULL}, + {1094, 1, "greek", "greek_nopad_bin", "", 28597, "GREEK", 1, 1, NULL, NULL}, + {1095, 1, "hebrew", "hebrew_nopad_bin", "", 1255, "HEBREW", 1, 1, NULL, NULL}, + {1096, 1, "hp8", "hp8_nopad_bin", "", 0, "HP-ROMAN8", 1, 1, NULL, NULL}, + {1097, 1, "keybcs2", "keybcs2_nopad_bin", "", 0, "", 1, 1, NULL, NULL}, + {1098, 1, "koi8r", "koi8r_nopad_bin", "", 878, "KOI8R", 1, 1, NULL, NULL}, + {1099, 1, "koi8u", "koi8u_nopad_bin", "", 20866, "KOI8U", 1, 1, NULL, NULL}, + {1101, 1, "latin2", "latin2_nopad_bin", "", 852, "LATIN2", 1, 1, NULL, NULL}, + {1102, 1, "latin5", "latin5_nopad_bin", "", 1254, "LATIN5", 1, 1, NULL, NULL}, + {1103, 1, "latin7", "latin7_nopad_bin", "", 28603, "LATIN7", 1, 1, NULL, NULL}, + {1104, 1, "cp850", "cp850_nopad_bin", "", 850, "CP850", 1, 1, NULL, NULL}, + {1105, 1, "cp852", "cp852_nopad_bin", "", 852, "CP852", 1, 1, NULL, NULL}, + {1106, 1, "swe7", "swe7_nopad_bin", "", 20107, "", 1, 1, NULL, NULL}, + {1107, 1, UTF8_MB3, UTF8_MB3"_nopad_bin", "", 65001, "UTF-8", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid}, + {1108, 1, "big5","big5_nopad_bin", "", 950, "BIG5", 1, 2, mysql_mbcharlen_big5, check_mb_big5}, + {1109, 1, "euckr", "euckr_nopad_bin", "", 51949, "EUCKR", 1, 2, mysql_mbcharlen_euckr, check_mb_euckr}, + {1110, 1, "gb2312", "gb2312_nopad_bin", "", 936, "GB2312", 1, 2, mysql_mbcharlen_gb2312, check_mb_gb2312}, + {1111, 1, "gbk", "gbk_nopad_bin", "", 936, "GBK", 1, 2, mysql_mbcharlen_gbk, check_mb_gbk}, + {1112, 1, "sjis", "sjis_nopad_bin", "", 932, "SJIS", 1, 2, mysql_mbcharlen_sjis, check_mb_sjis}, + {1113, 1, "tis620", "tis620_nopad_bin", "", 874, "TIS620", 1, 1, NULL, NULL}, + {1114, 1, "ucs2", "ucs2_nopad_bin", "", 1200, "UCS-2BE", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2}, + {1115, 1, "ujis", "ujis_nopad_bin", "", 20932, "UJIS", 1, 3, mysql_mbcharlen_ujis, check_mb_ujis}, + {1116, 1, "geostd8", "geostd8_general_nopad_ci", "", 0, "GEORGIAN-PS", 1, 1, NULL, NULL}, + {1117, 1, "geostd8", "geostd8_nopad_bin", "", 0, "GEORGIAN-PS", 1, 1, NULL, NULL}, + {1119, 1, "cp932", "cp932_japanese_nopad_ci", "", 932, "CP932", 1, 2, mysql_mbcharlen_cp932, check_mb_cp932}, + {1120, 1, "cp932", "cp932_nopad_bin", "", 932, "CP932", 1, 2, mysql_mbcharlen_cp932, check_mb_cp932}, + {1121, 1, "eucjpms", "eucjpms_japanese_nopad_ci", "", 932, "EUCJP-MS", 1, 3, mysql_mbcharlen_eucjpms, check_mb_eucjpms}, + {1122, 1, "eucjpms", "eucjpms_nopad_bin", "", 932, "EUCJP-MS", 1, 3, mysql_mbcharlen_eucjpms, check_mb_eucjpms}, + {1125, 1, "utf16", "utf16_unicode_nopad_ci", "", 1200, "UTF16", 2, 4, mysql_mbcharlen_utf16, check_mb_utf16}, + {1147, 1, "utf16", "utf16_unicode_520_nopad_ci", "", 1200, "UTF16", 2, 4, mysql_mbcharlen_utf16, check_mb_utf16}, + {1152, 1, "ucs2", "ucs2_unicode_nopad_ci", "", 1200, "UCS-2BE", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2}, + {1174, 1, "ucs2", "ucs2_unicode_520_nopad_ci", "", 1200, "UCS-2BE", 2, 2, mysql_mbcharlen_ucs2, check_mb_ucs2}, + {1184, 1, "utf32", "utf32_unicode_nopad_ci", "", 0, "UTF32", 4, 4, mysql_mbcharlen_utf32, check_mb_utf32}, + {1206, 1, "utf32", "utf32_unicode_520_nopad_ci", "", 0, "UTF32", 4, 4, mysql_mbcharlen_utf32, check_mb_utf32}, + {1216, 1, UTF8_MB3, UTF8_MB3"_unicode_nopad_ci", "", 65001, "UTF-8", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid}, + {1238, 1, UTF8_MB3, UTF8_MB3"_unicode_520_nopad_ci", "", 65001, "UTF-8", 1, 3, mysql_mbcharlen_utf8mb3, check_mb_utf8mb3_valid}, + {1248, 1, UTF8_MB4, UTF8_MB4"_unicode_nopad_ci", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + {1270, 1, UTF8_MB4, UTF8_MB4"_unicode_520_nopad_ci", "", 65001, "UTF-8", 1, 4, mysql_mbcharlen_utf8, check_mb_utf8_valid}, + { 0, 0, NULL, NULL, NULL, 0, NULL, 0, 0, NULL, NULL} +}; +/* }}} */ + + +/* {{{ mysql_find_charset_nr */ +const MARIADB_CHARSET_INFO * mysql_find_charset_nr(unsigned int charsetnr) +{ + const MARIADB_CHARSET_INFO * c = mariadb_compiled_charsets; + + do { + if (c->nr == charsetnr) { + return(c); + } + ++c; + } while (c[0].nr != 0); + return(NULL); +} +/* }}} */ + + +/* {{{ mysql_find_charset_name */ +MARIADB_CHARSET_INFO * mysql_find_charset_name(const char *name) +{ + MARIADB_CHARSET_INFO *c = (MARIADB_CHARSET_INFO *)mariadb_compiled_charsets; + const char *csname; + + if (!strcasecmp(name, MADB_AUTODETECT_CHARSET_NAME)) + csname= madb_get_os_character_set(); + else + csname= (char *)name; + + if (!strcasecmp("utf8",csname)) + csname= "utf8mb3"; + + do { + if (!strcasecmp(c->csname, csname)) { + return(c); + } + ++c; + } while (c[0].nr != 0); + return(NULL); +} +/* }}} */ + + +/* {{{ mysql_cset_escape_quotes */ +size_t mysql_cset_escape_quotes(const MARIADB_CHARSET_INFO *cset, char *newstr, + const char * escapestr, size_t escapestr_len ) +{ + const char *newstr_s = newstr; + const char *newstr_e = newstr + 2 * escapestr_len; + const char *end = escapestr + escapestr_len; + my_bool escape_overflow = FALSE; + + for (;escapestr < end; escapestr++) { + unsigned int len = 0; + /* check unicode characters */ + + if (cset->char_maxlen > 1 && (len = cset->mb_valid(escapestr, end))) { + + /* check possible overflow */ + if ((newstr + len) > newstr_e) { + escape_overflow = TRUE; + break; + } + /* copy mb char without escaping it */ + while (len--) { + *newstr++ = *escapestr++; + } + escapestr--; + continue; + } + if (*escapestr == '\'') { + if (newstr + 2 > newstr_e) { + escape_overflow = TRUE; + break; + } + *newstr++ = '\''; + *newstr++ = '\''; + } else { + if (newstr + 1 > newstr_e) { + escape_overflow = TRUE; + break; + } + *newstr++ = *escapestr; + } + } + *newstr = '\0'; + + if (escape_overflow) { + return((size_t)~0); + } + return((size_t)(newstr - newstr_s)); +} +/* }}} */ + + +/* {{{ mysql_cset_escape_slashes */ +size_t mysql_cset_escape_slashes(const MARIADB_CHARSET_INFO * cset, char *newstr, + const char * escapestr, size_t escapestr_len ) +{ + const char *newstr_s = newstr; + const char *newstr_e = newstr + 2 * escapestr_len; + const char *end = escapestr + escapestr_len; + my_bool escape_overflow = FALSE; + + for (;escapestr < end; escapestr++) { + char esc = '\0'; + unsigned int len = 0; + + /* check unicode characters */ + if (cset->char_maxlen > 1 && (len = cset->mb_valid(escapestr, end))) { + /* check possible overflow */ + if ((newstr + len) > newstr_e) { + escape_overflow = TRUE; + break; + } + /* copy mb char without escaping it */ + while (len--) { + *newstr++ = *escapestr++; + } + escapestr--; + continue; + } + if (cset->char_maxlen > 1 && cset->mb_charlen(*escapestr) > 1) { + esc = *escapestr; + } else { + switch (*escapestr) { + case 0: + esc = '0'; + break; + case '\n': + esc = 'n'; + break; + case '\r': + esc = 'r'; + break; + case '\\': + case '\'': + case '"': + esc = *escapestr; + break; + case '\032': + esc = 'Z'; + break; + } + } + if (esc) { + if (newstr + 2 > newstr_e) { + escape_overflow = TRUE; + break; + } + /* copy escaped character */ + *newstr++ = '\\'; + *newstr++ = esc; + } else { + if (newstr + 1 > newstr_e) { + escape_overflow = TRUE; + break; + } + /* copy non escaped character */ + *newstr++ = *escapestr; + } + } + *newstr = '\0'; + + if (escape_overflow) { + return((size_t)~0); + } + return((size_t)(newstr - newstr_s)); +} +/* }}} */ + +/* {{{ MADB_OS_CHARSET */ +struct st_madb_os_charset { + const char *identifier; + const char *description; + const char *charset; + const char *iconv_cs; + unsigned char supported; +}; + +#define MADB_CS_UNSUPPORTED 0 +#define MADB_CS_APPROX 1 +#define MADB_CS_EXACT 2 + +/* Please add new character sets at the end. */ +struct st_madb_os_charset MADB_OS_CHARSET[]= +{ +#ifdef _WIN32 + /* Windows code pages */ + {"037", "IBM EBCDIC US-Canada", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"437", "OEM United States", "cp850", NULL, MADB_CS_APPROX}, + {"500", "IBM EBCDIC International", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"708", "Arabic (ASMO 708)", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"709", "Arabic (ASMO-449+, BCON V4)", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"710", "Transparent Arabic", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"720", "Arabic (DOS)", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"737", "Greek (DOS)", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"775", "Baltic (DOS)", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"850", "Western European (DOS)", "cp850", NULL, MADB_CS_EXACT}, + {"852", "Central European (DOS)", "cp852", NULL, MADB_CS_EXACT}, + {"855", "Cyrillic (primarily Russian)", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"857", "Turkish (DOS)", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"858", "OEM Multilingual Latin 1 + Euro symbol", "cp850", NULL, MADB_CS_EXACT}, + {"860", "Portuguese (DOS)", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"861", "Icelandic (DOS)", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"862", "Hebrew (DOS)", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"863", "French Canadian (DOS)", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"864", "Arabic (864)", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"865", "Nordic (DOS)", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"866", "Cyrillic (DOS)", "cp866", NULL, MADB_CS_EXACT}, + {"869", "Greek, Modern (DOS)", "greek", NULL, MADB_CS_EXACT}, + {"870", "IBM EBCDIC Multilingual Latin 2", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"874", "Thai (Windows)", "tis620", NULL, MADB_CS_UNSUPPORTED}, + {"875", "Greek Modern", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"932", "Japanese (Shift-JIS)", "cp932", NULL, MADB_CS_EXACT}, + {"936", "Chinese Simplified (GB2312)", "gbk", NULL, MADB_CS_EXACT}, + {"949", "ANSI/OEM Korean (Unified Hangul Code)", "euckr", NULL, MADB_CS_EXACT}, + {"950", "Chinese Traditional (Big5)", "big5", NULL, MADB_CS_EXACT}, + {"1026", "EBCDIC Turkish (Latin 5)", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"1047", "EBCDIC Latin 1/Open System", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"1140", "IBM EBCDIC (US-Canada-Euro)", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"1141", "IBM EBCDIC (Germany-Euro)", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"1142", "IBM EBCDIC (Denmark-Norway-Euro)", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"1143", "IBM EBCDIC (Finland-Sweden-Euro)", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"1144", "IBM EBCDIC (Italy-Euro)", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"1145", "IBM EBCDIC (Spain-Euro)", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"1146", "IBM EBCDIC (UK-Euro)", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"1147", "IBM EBCDIC (France-Euro)", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"1148", "IBM EBCDIC (International-Euro)", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"1149", "IBM EBCDIC (Icelandic-Euro)", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"1200", "UTF-16, little endian byte order", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"1201", "UTF-16, big endian byte order", "utf16", NULL, MADB_CS_UNSUPPORTED}, + {"1250", "Central European (Windows)", "cp1250", NULL, MADB_CS_EXACT}, + {"1251", "Cyrillic (Windows)", "cp1251", NULL, MADB_CS_EXACT}, + {"1252", "Western European (Windows)", "latin1", NULL, MADB_CS_EXACT}, + {"1253", "Greek (Windows)", "greek", NULL, MADB_CS_EXACT}, + {"1254", "Turkish (Windows)", "latin5", NULL, MADB_CS_EXACT}, + {"1255", "Hebrew (Windows)", "hewbrew", NULL, MADB_CS_EXACT}, + {"1256", "Arabic (Windows)", "cp1256", NULL, MADB_CS_EXACT}, + {"1257", "Baltic (Windows)","cp1257", NULL, MADB_CS_EXACT}, + {"1258", "Vietnamese (Windows)", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"1361", "Korean (Johab)", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"10000", "Western European (Mac)", "macroman", NULL, MADB_CS_EXACT}, + {"10001", "Japanese (Mac)", "sjis", NULL, MADB_CS_EXACT}, + {"10002", "Chinese Traditional (Mac)", "big5", NULL, MADB_CS_EXACT}, + {"10003", "Korean (Mac)", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"10004", "Arabic (Mac)", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"10005", "Hebrew (Mac)", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"10006", "Greek (Mac)", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"10007", "Cyrillic (Mac)", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"10008", "Chinese Simplified (Mac)", "gb2312", NULL, MADB_CS_EXACT}, + {"10010", "Romanian (Mac)", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"10017", "Ukrainian (Mac)", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"10021", "Thai (Mac)", "tis620", NULL, MADB_CS_EXACT}, + {"10029", "Central European (Mac)", "macce", NULL, MADB_CS_EXACT}, + {"10079", "Icelandic (Mac)", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"10081", "Turkish (Mac)", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"10082", "Croatian (Mac)", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"12000", "Unicode UTF-32, little endian byte order", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"12001", "Unicode UTF-32, big endian byte order", "utf32", NULL, MADB_CS_UNSUPPORTED}, + {"20000", "Chinese Traditional (CNS)", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"20001", "TCA Taiwan", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"20002", "Chinese Traditional (Eten)", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"20003", "IBM5550 Taiwan", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"20004", "TeleText Taiwan", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"20005", "Wang Taiwan", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"20105", "Western European (IA5)", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"20106", "IA5 German (7-bit)", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"20107", "Swedish (7-bit)", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"20108", "Norwegian (7-bit)", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"20127", "US-ASCII (7-bit)", "ascii", NULL, MADB_CS_EXACT}, + {"20261", "T.61", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"20269", "Non-Spacing Accent", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"20273", "EBCDIC Germany", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"20277", "EBCDIC Denmark-Norway", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"20278", "EBCDIC Finland-Sweden", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"20280", "EBCDIC Italy", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"20284", "EBCDIC Latin America-Spain", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"20285", "EBCDIC United Kingdom", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"20290", "EBCDIC Japanese Katakana Extended", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"20297", "EBCDIC France", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"20420", "EBCDIC Arabic", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"20423", "EBCDIC Greek", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"20424", "EBCDIC Hebrew", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"20833", "EBCDIC Korean Extended", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"20838", "EBCDIC Thai", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"20866", "Cyrillic (KOI8-R)", "koi8r", NULL, MADB_CS_EXACT}, + {"20871", "EBCDIC Icelandic", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"20880", "EBCDIC Cyrillic Russian", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"20905", "EBCDIC Turkish", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"20924", "EBCDIC Latin 1/Open System (1047 + Euro symbol)", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"20932", "Japanese (JIS 0208-1990 and 0121-1990)", "ujis", NULL, MADB_CS_EXACT}, + {"20936", "Chinese Simplified (GB2312-80)", "gb2312", NULL, MADB_CS_APPROX}, + {"20949", "Korean Wansung", "euckr", NULL, MADB_CS_APPROX}, + {"21025", "EBCDIC Cyrillic Serbian-Bulgarian", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"21866", "Cyrillic (KOI8-U)", "koi8u", NULL, MADB_CS_EXACT}, + {"28591", "Western European (ISO)", "latin1", NULL, MADB_CS_APPROX}, + {"28592", "Central European (ISO)", "latin2", NULL, MADB_CS_EXACT}, + {"28593", "Latin 3", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"28594", "Baltic", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"28595", "ISO 8859-5 Cyrillic", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"28596", "ISO 8859-6 Arabic", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"28597", "ISO 8859-7 Greek", "greek", NULL, MADB_CS_EXACT}, + {"28598", "Hebrew (ISO-Visual)", "hebrew", NULL, MADB_CS_EXACT}, + {"28599", "ISO 8859-9 Turkish", "latin5", NULL, MADB_CS_EXACT}, + {"28603", "ISO 8859-13 Estonian", "latin7", NULL, MADB_CS_EXACT}, + {"28605", "8859-15 Latin 9", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"29001", "Europa 3", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"38598", "ISO 8859-8 Hebrew; Hebrew (ISO-Logical)", "hebrew", NULL, MADB_CS_EXACT}, + {"50220", "ISO 2022 Japanese with no halfwidth Katakana", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"50221", "ISO 2022 Japanese with halfwidth Katakana", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"50222", "ISO 2022 Japanese JIS X 0201-1989", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"50225", "ISO 2022 Korean", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"50227", "ISO 2022 Simplified Chinese", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"50229", "ISO 2022 Traditional Chinese", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"50930", "EBCDIC Japanese (Katakana) Extended", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"50931", "EBCDIC US-Canada and Japanese", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"50933", "EBCDIC Korean Extended and Korean", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"50935", "EBCDIC Simplified Chinese Extended and Simplified Chinese", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"50936", "EBCDIC Simplified Chinese", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"50937", "EBCDIC US-Canada and Traditional Chinese", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"50939", "EBCDIC Japanese (Latin) Extended and Japanese", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"51932", "EUC Japanese", "ujis", NULL, MADB_CS_EXACT}, + {"51936", "EUC Simplified Chinese; Chinese Simplified (EUC)", "gb2312", NULL, MADB_CS_EXACT}, + {"51949", "EUC Korean", "euckr", NULL, MADB_CS_EXACT}, + {"51950", "EUC Traditional Chinese", "big5", NULL, MADB_CS_EXACT}, + {"52936", "Chinese Simplified (HZ)", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"54936", "Chinese Simplified (GB18030)", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"57002", "ISCII Devanagari", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"57003", "ISCII Bengali", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"57004", "ISCII Tamil", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"57005", "ISCII Telugu", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"57006", "ISCII Assamese", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"57007", "ISCII Oriya", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"57008", "ISCII Kannada", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"57009", "ISCII Malayalam", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"57010", "ISCII Gujarati", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"57011", "ISCII Punjabi", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"65000", "utf-7 Unicode (UTF-7)", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"65001", "utf-8 Unicode (UTF-8)", "utf8", NULL, MADB_CS_EXACT}, + /* non Windows */ +#else + /* iconv encodings */ + {"ASCII", "US-ASCII", "ascii", "ASCII", MADB_CS_APPROX}, + {"US-ASCII", "US-ASCII", "ascii", "ASCII", MADB_CS_APPROX}, + {"Big5", "Chinese for Taiwan Multi-byte set", "big5", "BIG5", MADB_CS_EXACT}, + {"CP866", "IBM 866", "cp866", "CP866", MADB_CS_EXACT}, + {"IBM-1252", "Catalan Spain", "cp1252", "CP1252", MADB_CS_EXACT}, + {"ISCII-DEV", "Hindi", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"ISO-8859-1", "ISO-8859-1", "latin1", "ISO_8859-1", MADB_CS_APPROX}, + {"ISO8859-1", "ISO-8859-1", "latin1", "ISO_8859-1", MADB_CS_APPROX}, + {"ISO_8859-1", "ISO-8859-1", "latin1", "ISO_8859-1", MADB_CS_APPROX}, + {"ISO88591", "ISO-8859-1", "latin1", "ISO_8859-1", MADB_CS_APPROX}, + {"ISO-8859-13", "ISO-8859-13", "latin7", "ISO_8859-13", MADB_CS_EXACT}, + {"ISO8859-13", "ISO-8859-13", "latin7", "ISO_8859-13", MADB_CS_EXACT}, + {"ISO_8859-13", "ISO-8859-13", "latin7", "ISO_8859-13", MADB_CS_EXACT}, + {"ISO885913", "ISO-8859-13", "latin7", "ISO_8859-13", MADB_CS_EXACT}, + {"ISO-8859-15", "ISO-8859-15", "latin9", "ISO_8859-15", MADB_CS_UNSUPPORTED}, + {"ISO8859-15", "ISO-8859-15", "latin9", "ISO_8859-15", MADB_CS_UNSUPPORTED}, + {"ISO_8859-15", "ISO-8859-15", "latin9", "ISO_8859-15", MADB_CS_UNSUPPORTED}, + {"ISO885915", "ISO-8859-15", "latin9", "ISO_8859-15", MADB_CS_UNSUPPORTED}, + {"ISO-8859-2", "ISO-8859-2", "latin2", "ISO_8859-2", MADB_CS_EXACT}, + {"ISO8859-2", "ISO-8859-2", "latin2", "ISO_8859-2", MADB_CS_EXACT}, + {"ISO_8859-2", "ISO-8859-2", "latin2", "ISO_8859-2", MADB_CS_EXACT}, + {"ISO88592", "ISO-8859-2", "latin2", "ISO_8859-2", MADB_CS_EXACT}, + {"ISO-8859-7", "ISO-8859-7", "greek", "ISO_8859-7", MADB_CS_EXACT}, + {"ISO8859-7", "ISO-8859-7", "greek", "ISO_8859-7", MADB_CS_EXACT}, + {"ISO_8859-7", "ISO-8859-7", "greek", "ISO_8859-7", MADB_CS_EXACT}, + {"ISO88597", "ISO-8859-7", "greek", "ISO_8859-7", MADB_CS_EXACT}, + {"ISO-8859-8", "ISO-8859-8", "hebrew", "ISO_8859-8", MADB_CS_EXACT}, + {"ISO8859-8", "ISO-8859-8", "hebrew", "ISO_8859-8", MADB_CS_EXACT}, + {"ISO_8859-8", "ISO-8859-8", "hebrew", "ISO_8859-8", MADB_CS_EXACT}, + {"ISO88598", "ISO-8859-8", "hebrew", "ISO_8859-8", MADB_CS_EXACT}, + {"ISO-8859-9", "ISO-8859-9", "latin5", "ISO_8859-9", MADB_CS_EXACT}, + {"ISO8859-9", "ISO-8859-9", "latin5", "ISO_8859-9", MADB_CS_EXACT}, + {"ISO_8859-9", "ISO-8859-9", "latin5", "ISO_8859-9", MADB_CS_EXACT}, + {"ISO88599", "ISO-8859-9", "latin5", "ISO_8859-9", MADB_CS_EXACT}, + {"ISO-8859-4", "ISO-8859-4", NULL, "ISO_8859-4", MADB_CS_UNSUPPORTED}, + {"ISO8859-4", "ISO-8859-4", NULL, "ISO_8859-4", MADB_CS_UNSUPPORTED}, + {"ISO_8859-4", "ISO-8859-4", NULL, "ISO_8859-4", MADB_CS_UNSUPPORTED}, + {"ISO88594", "ISO-8859-4", NULL, "ISO_8859-4", MADB_CS_UNSUPPORTED}, + {"ISO-8859-5", "ISO-8859-5", NULL, "ISO_8859-5", MADB_CS_UNSUPPORTED}, + {"ISO8859-5", "ISO-8859-5", NULL, "ISO_8859-5", MADB_CS_UNSUPPORTED}, + {"ISO_8859-5", "ISO-8859-5", NULL, "ISO_8859-5", MADB_CS_UNSUPPORTED}, + {"ISO88595", "ISO-8859-5", NULL, "ISO_8859-5", MADB_CS_UNSUPPORTED}, + {"KOI8-R", "KOI8-R", "koi8r", "KOI8R", MADB_CS_EXACT}, + {"koi8r", "KOI8-R", "koi8r", "KOI8R", MADB_CS_EXACT}, + {"KOI8-U", "KOI8-U", "koi8u", "KOI8U", MADB_CS_EXACT}, + {"koi8u", "KOI8-U", "koi8u", "KOI8U", MADB_CS_EXACT}, + {"koi8t", "KOI8-T", NULL, "KOI8-T", MADB_CS_UNSUPPORTED}, + {"KOI8-T", "KOI8-T", NULL, "KOI8-T", MADB_CS_UNSUPPORTED}, + {"SJIS", "SHIFT_JIS", "sjis", "SJIS", MADB_CS_EXACT}, + {"Shift-JIS", "SHIFT_JIS", "sjis", "SJIS", MADB_CS_EXACT}, + {"ansi1251", "Cyrillic", "cp1251", "CP1251", MADB_CS_EXACT}, + {"cp1251", "Cyrillic", "cp1251", "CP1251", MADB_CS_EXACT}, + {"armscii8", "Armenian", "armscii8", "ASMSCII-8", MADB_CS_EXACT}, + {"armscii-8", "Armenian", "armscii8", "ASMSCII-8", MADB_CS_EXACT}, + {"big5hkscs", "Big5-HKSCS", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"cp1255", "Hebrew", "cp1255", "CP1255", MADB_CS_EXACT}, + {"eucCN", "GB-2312", "gb2312", "GB2312", MADB_CS_EXACT}, + {"eucJP", "UJIS", "ujis", "UJIS", MADB_CS_EXACT}, + {"eucKR", "EUC-KR", "euckr", "EUCKR", MADB_CS_EXACT}, + {"euctw", "EUC-TW", NULL, NULL, MADB_CS_UNSUPPORTED}, + {"gb18030", "GB 18030-2000", "gb18030", "GB18030", MADB_CS_UNSUPPORTED}, + {"gb2312", "GB2312", "gb2312", "GB2312", MADB_CS_EXACT}, + {"gbk", "GBK", "gbk", "GBK", MADB_CS_EXACT}, + {"georgianps", "Georgian", "geostd8", "GEORGIAN-PS", MADB_CS_EXACT}, + {"utf8", "UTF8", "utf8", "UTF-8", MADB_CS_EXACT}, + {"utf-8", "UTF8", "utf8", "UTF-8", MADB_CS_EXACT}, +#endif + {NULL, NULL, NULL, NULL, 0} +}; +/* }}} */ + +/* {{{ madb_get_os_character_set */ +const char *madb_get_os_character_set() +{ + unsigned int i= 0; + char *p= NULL; +#ifdef _WIN32 + char codepage[FN_REFLEN]; + snprintf(codepage, FN_REFLEN, "%u", GetConsoleCP() ? GetConsoleCP() : GetACP()); + p= codepage; +#elif defined(HAVE_NL_LANGINFO) && defined(HAVE_SETLOCALE) + if (setlocale(LC_CTYPE, "")) + p= nl_langinfo(CODESET); +#endif + if (!p) + return MADB_DEFAULT_CHARSET_NAME; + while (MADB_OS_CHARSET[i].identifier) + { + if (MADB_OS_CHARSET[i].supported > MADB_CS_UNSUPPORTED && + strcasecmp(MADB_OS_CHARSET[i].identifier, p) == 0) + return MADB_OS_CHARSET[i].charset; + i++; + } + return MADB_DEFAULT_CHARSET_NAME; +} +/* }}} */ + +/* {{{ madb_get_code_page */ +#ifdef _WIN32 +int madb_get_windows_cp(const char *charset) +{ + unsigned int i= 0; + while (MADB_OS_CHARSET[i].identifier) + { + if (MADB_OS_CHARSET[i].supported > MADB_CS_UNSUPPORTED && + strcmp(MADB_OS_CHARSET[i].charset, charset) == 0) + return atoi(MADB_OS_CHARSET[i].identifier); + i++; + } + return -1; +} +#endif +/* }}} */ + +#ifdef HAVE_ICONV +/* {{{ map_charset_name + Changing charset name into something iconv understands, if necessary. + Another purpose it to avoid BOMs in result string, adding BE if necessary + e.g.UTF16 does not work form iconv, while UTF-16 does. + */ +static void map_charset_name(const char *cs_name, my_bool target_cs, char *buffer, size_t buff_len) +{ + char digits[3], endianness[3]= "BE"; + + if (sscanf(cs_name, "UTF%2[0-9]%2[LBE]", digits, endianness)) + { + /* We should have at least digits. Endianness we write either default(BE), or what we found in the string */ + snprintf(buffer, buff_len, "UTF-%s%s", digits, endianness); + } + else + { + /* Not our client - copy as is*/ + strncpy(buffer, cs_name, buff_len - 1); + buffer[buff_len - 1]= '\0'; + } + + if (target_cs) + { + strncat(buffer, "//TRANSLIT", buff_len - strlen(buffer)); + } +} +/* }}} */ +#endif + +/* {{{ mariadb_convert_string + Converts string from one charset to another, and writes converted string to given buffer + @param[in] from + @param[in/out] from_len + @param[in] from_cs + @param[out] to + @param[in/out] to_len + @param[in] to_cs + @param[out] errorcode + + @return -1 in case of error, bytes used in the "to" buffer, otherwise + */ +size_t STDCALL mariadb_convert_string(const char *from __attribute__((unused)), + size_t *from_len __attribute__((unused)), + MARIADB_CHARSET_INFO *from_cs __attribute__((unused)), + char *to __attribute__((unused)), + size_t *to_len __attribute__((unused)), + MARIADB_CHARSET_INFO *to_cs __attribute__((unused)), int *errorcode) +{ +#ifndef HAVE_ICONV + *errorcode= ENOTSUP; + return -1; +#else + iconv_t conv= 0; + size_t rc= -1; + size_t save_len= *to_len; + char to_encoding[128], from_encoding[128]; + + *errorcode= 0; + + /* check if conversion is supported */ + if (!from_cs || !from_cs->encoding || !from_cs->encoding[0] || + !to_cs || !to_cs->encoding || !to_cs->encoding[0]) + { + *errorcode= EINVAL; + return rc; + } + + map_charset_name(to_cs->encoding, 1, to_encoding, sizeof(to_encoding)); + map_charset_name(from_cs->encoding, 0, from_encoding, sizeof(from_encoding)); + + if ((conv= iconv_open(to_encoding, from_encoding)) == (iconv_t)-1) + { + *errorcode= errno; + goto error; + } + if ((rc= iconv(conv, IF_WIN(,IF_SOLARIS(,(char **)))&from, from_len, &to, to_len)) == (size_t)-1) + { + *errorcode= errno; + goto error; + } + rc= save_len - *to_len; +error: + if (conv != (iconv_t)-1) + iconv_close(conv); + return rc; +#endif +} +/* }}} */ + diff --git a/vendor/MDBC/libmariadb/ma_client_plugin.c.in b/vendor/MDBC/libmariadb/ma_client_plugin.c.in new file mode 100644 index 00000000..b635f21d --- /dev/null +++ b/vendor/MDBC/libmariadb/ma_client_plugin.c.in @@ -0,0 +1,508 @@ +/* Copyright (C) 2010 - 2012 Sergei Golubchik and Monty Program Ab + 2015-2016 MariaDB Corporation AB + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not see + or write to the Free Software Foundation, Inc., + 51 Franklin St., Fifth Floor, Boston, MA 02110, USA */ + +/** + @file + + Support code for the client side (libmariadb) plugins + + Client plugins are somewhat different from server plugins, they are simpler. + + They do not need to be installed or in any way explicitly loaded on the + client, they are loaded automatically on demand. + One client plugin per shared object, soname *must* match the plugin name. + + There is no reference counting and no unloading either. +*/ + +/* Silence warnings about variable 'unused' being used. */ +#define FORCE_INIT_OF_VARS 1 + +#include +#include +#include +#include +#include + +#include "errmsg.h" +#include + +#ifndef WIN32 +#include +#endif + +struct st_client_plugin_int { + struct st_client_plugin_int *next; + void *dlhandle; + struct st_mysql_client_plugin *plugin; +}; + +static my_bool initialized= 0; +static MA_MEM_ROOT mem_root; + +static uint valid_plugins[][2]= { + {MYSQL_CLIENT_AUTHENTICATION_PLUGIN, MYSQL_CLIENT_AUTHENTICATION_PLUGIN_INTERFACE_VERSION}, + {MARIADB_CLIENT_PVIO_PLUGIN, MARIADB_CLIENT_PVIO_PLUGIN_INTERFACE_VERSION}, + {MARIADB_CLIENT_TRACE_PLUGIN, MARIADB_CLIENT_TRACE_PLUGIN_INTERFACE_VERSION}, + {MARIADB_CLIENT_REMOTEIO_PLUGIN, MARIADB_CLIENT_REMOTEIO_PLUGIN_INTERFACE_VERSION}, + {MARIADB_CLIENT_CONNECTION_PLUGIN, MARIADB_CLIENT_CONNECTION_PLUGIN_INTERFACE_VERSION}, + {0, 0} +}; + +/* + Loaded plugins are stored in a linked list. + The list is append-only, the elements are added to the head (like in a stack). + The elements are added under a mutex, but the list can be read and traversed + without any mutex because once an element is added to the list, it stays + there. The main purpose of a mutex is to prevent two threads from + loading the same plugin twice in parallel. +*/ + + +struct st_client_plugin_int *plugin_list[MYSQL_CLIENT_MAX_PLUGINS + MARIADB_CLIENT_MAX_PLUGINS]; +#ifdef THREAD +static pthread_mutex_t LOCK_load_client_plugin; +#endif + +@EXTERNAL_PLUGINS@ + +struct st_mysql_client_plugin *mysql_client_builtins[]= +{ + @BUILTIN_PLUGINS@ + 0 +}; + + +static int is_not_initialized(MYSQL *mysql, const char *name) +{ + if (initialized) + return 0; + + my_set_error(mysql, CR_AUTH_PLUGIN_CANNOT_LOAD, + SQLSTATE_UNKNOWN, ER(CR_AUTH_PLUGIN_CANNOT_LOAD), + name, "not initialized"); + return 1; +} + +static int get_plugin_nr(uint type) +{ + uint i= 0; + for(; valid_plugins[i][1]; i++) + if (valid_plugins[i][0] == type) + return i; + return -1; +} + +static const char *check_plugin_version(struct st_mysql_client_plugin *plugin, unsigned int version) +{ + if (plugin->interface_version < version || + (plugin->interface_version >> 8) > (version >> 8)) + return "Incompatible client plugin interface"; + return 0; +} + +/** + finds a plugin in the list + + @param name plugin name to search for + @param type plugin type + + @note this does NOT necessarily need a mutex, take care! + + @retval a pointer to a found plugin or 0 +*/ +static struct st_mysql_client_plugin *find_plugin(const char *name, int type) +{ + struct st_client_plugin_int *p; + int plugin_nr= get_plugin_nr(type); + + DBUG_ASSERT(initialized); + if (plugin_nr == -1) + return 0; + + if (!name) + return plugin_list[plugin_nr]->plugin; + + for (p= plugin_list[plugin_nr]; p; p= p->next) + { + if (strcmp(p->plugin->name, name) == 0) + return p->plugin; + } + return NULL; +} + + +/** + verifies the plugin and adds it to the list + + @param mysql MYSQL structure (for error reporting) + @param plugin plugin to install + @param dlhandle a handle to the shared object (returned by dlopen) + or 0 if the plugin was not dynamically loaded + @param argc number of arguments in the 'va_list args' + @param args arguments passed to the plugin initialization function + + @retval a pointer to an installed plugin or 0 +*/ + +static struct st_mysql_client_plugin * +add_plugin(MYSQL *mysql, struct st_mysql_client_plugin *plugin, void *dlhandle, + int argc, va_list args) +{ + const char *errmsg; + struct st_client_plugin_int plugin_int, *p; + char errbuf[1024]; + int plugin_nr; + + DBUG_ASSERT(initialized); + + plugin_int.plugin= plugin; + plugin_int.dlhandle= dlhandle; + + if ((plugin_nr= get_plugin_nr(plugin->type)) == -1) + { + errmsg= "Unknown client plugin type"; + goto err1; + } + if ((errmsg= check_plugin_version(plugin, valid_plugins[plugin_nr][1]))) + goto err1; + + /* Call the plugin initialization function, if any */ + if (plugin->init && plugin->init(errbuf, sizeof(errbuf), argc, args)) + { + errmsg= errbuf; + goto err1; + } + + p= (struct st_client_plugin_int *) + ma_memdup_root(&mem_root, (char *)&plugin_int, sizeof(plugin_int)); + + if (!p) + { + errmsg= "Out of memory"; + goto err2; + } + + + p->next= plugin_list[plugin_nr]; + plugin_list[plugin_nr]= p; + + return plugin; + +err2: + if (plugin->deinit) + plugin->deinit(); +err1: + my_set_error(mysql, CR_AUTH_PLUGIN_CANNOT_LOAD, SQLSTATE_UNKNOWN, + ER(CR_AUTH_PLUGIN_CANNOT_LOAD), plugin->name, errmsg); + if (dlhandle) + (void)dlclose(dlhandle); + return NULL; +} + + +/** + Loads plugins which are specified in the environment variable + LIBMYSQL_PLUGINS. + + Multiple plugins must be separated by semicolon. This function doesn't + return or log an error. + + The function is be called by mysql_client_plugin_init + + @todo + Support extended syntax, passing parameters to plugins, for example + LIBMYSQL_PLUGINS="plugin1(param1,param2);plugin2;..." + or + LIBMYSQL_PLUGINS="plugin1=int:param1,str:param2;plugin2;..." +*/ + +static void load_env_plugins(MYSQL *mysql) +{ + char *plugs, *free_env, *s= getenv("LIBMYSQL_PLUGINS"); + + if (ma_check_env_str(s)) + return; + + free_env= strdup(s); + plugs= s= free_env; + + do { + if ((s= strchr(plugs, ';'))) + *s= '\0'; + mysql_load_plugin(mysql, plugs, -1, 0); + plugs= s + 1; + } while (s); + + free(free_env); +} + +/********** extern functions to be used by libmariadb *********************/ + +/** + Initializes the client plugin layer. + + This function must be called before any other client plugin function. + + @retval 0 successful + @retval != 0 error occurred +*/ + +int mysql_client_plugin_init() +{ + MYSQL mysql; + struct st_mysql_client_plugin **builtin; + va_list unused; + LINT_INIT_STRUCT(unused); + + if (initialized) + return 0; + + memset(&mysql, 0, sizeof(mysql)); /* dummy mysql for set_mysql_extended_error */ + + pthread_mutex_init(&LOCK_load_client_plugin, NULL); + ma_init_alloc_root(&mem_root, 128, 128); + + memset(&plugin_list, 0, sizeof(plugin_list)); + + initialized= 1; + + pthread_mutex_lock(&LOCK_load_client_plugin); + for (builtin= mysql_client_builtins; *builtin; builtin++) + add_plugin(&mysql, *builtin, 0, 0, unused); + + pthread_mutex_unlock(&LOCK_load_client_plugin); + + load_env_plugins(&mysql); + + return 0; +} + + +/** + Deinitializes the client plugin layer. + + Unloades all client plugins and frees any associated resources. +*/ + +void mysql_client_plugin_deinit() +{ + int i; + struct st_client_plugin_int *p; + + if (!initialized) + return; + + for (i=0; i < MYSQL_CLIENT_MAX_PLUGINS; i++) + for (p= plugin_list[i]; p; p= p->next) + { + if (p->plugin->deinit) + p->plugin->deinit(); + if (p->dlhandle) + (void)dlclose(p->dlhandle); + } + + memset(&plugin_list, 0, sizeof(plugin_list)); + initialized= 0; + ma_free_root(&mem_root, MYF(0)); + pthread_mutex_destroy(&LOCK_load_client_plugin); +} + +/************* public facing functions, for client consumption *********/ + +/* see for a full description */ +struct st_mysql_client_plugin * STDCALL +mysql_client_register_plugin(MYSQL *mysql, + struct st_mysql_client_plugin *plugin) +{ + va_list unused; + LINT_INIT_STRUCT(unused); + + if (is_not_initialized(mysql, plugin->name)) + return NULL; + + pthread_mutex_lock(&LOCK_load_client_plugin); + + /* make sure the plugin wasn't loaded meanwhile */ + if (find_plugin(plugin->name, plugin->type)) + { + my_set_error(mysql, CR_AUTH_PLUGIN_CANNOT_LOAD, + SQLSTATE_UNKNOWN, ER(CR_AUTH_PLUGIN_CANNOT_LOAD), + plugin->name, "it is already loaded"); + plugin= NULL; + } + else + plugin= add_plugin(mysql, plugin, 0, 0, unused); + + pthread_mutex_unlock(&LOCK_load_client_plugin); + return plugin; +} + + +/* see for a full description */ +struct st_mysql_client_plugin * STDCALL +mysql_load_plugin_v(MYSQL *mysql, const char *name, int type, + int argc, va_list args) +{ + const char *errmsg; +#ifdef _WIN32 + char errbuf[1024]; +#endif + char dlpath[FN_REFLEN+1]; + void *sym, *dlhandle = NULL; + struct st_mysql_client_plugin *plugin; + char *env_plugin_dir= getenv("MARIADB_PLUGIN_DIR"); + + CLEAR_CLIENT_ERROR(mysql); + if (is_not_initialized(mysql, name)) + return NULL; + + pthread_mutex_lock(&LOCK_load_client_plugin); + + /* make sure the plugin wasn't loaded meanwhile */ + if (type >= 0 && find_plugin(name, type)) + { + errmsg= "it is already loaded"; + goto err; + } + + /* Compile dll path */ +#ifndef WIN32 + snprintf(dlpath, sizeof(dlpath) - 1, "%s/%s%s", + mysql->options.extension && mysql->options.extension->plugin_dir ? + mysql->options.extension->plugin_dir : (env_plugin_dir) ? env_plugin_dir : + MARIADB_PLUGINDIR, name, SO_EXT); +#else + { + char *p= (mysql->options.extension && mysql->options.extension->plugin_dir) ? + mysql->options.extension->plugin_dir : env_plugin_dir; + snprintf(dlpath, sizeof(dlpath), "%s%s%s%s", p ? p : "", p ? "\\" : "", name, SO_EXT); + } +#endif + + if (strpbrk(name, "()[]!@#$%^&/*;.,'?\\")) + { + errmsg= "invalid plugin name"; + goto err; + } + + + /* Open new dll handle */ + if (!(dlhandle= dlopen((const char *)dlpath, RTLD_NOW))) + { +#ifdef _WIN32 + char winmsg[255]; + size_t len; + winmsg[0] = 0; + FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, + NULL, + GetLastError(), + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + winmsg, 255, NULL); + len= strlen(winmsg); + while (len > 0 && (winmsg[len - 1] == '\n' || winmsg[len - 1] == '\r')) + len--; + if (len) + winmsg[len] = 0; + snprintf(errbuf, sizeof(errbuf), "%s Library path is '%s'", winmsg, dlpath); + errmsg= errbuf; +#else + errmsg= dlerror(); +#endif + goto err; + } + + + if (!(sym= dlsym(dlhandle, plugin_declarations_sym))) + { + errmsg= "not a plugin"; + (void)dlclose(dlhandle); + goto err; + } + + plugin= (struct st_mysql_client_plugin*)sym; + + if (type >=0 && type != plugin->type) + { + errmsg= "type mismatch"; + goto err; + } + + if (strcmp(name, plugin->name)) + { + errmsg= "name mismatch"; + goto err; + } + + if (type < 0 && find_plugin(name, plugin->type)) + { + errmsg= "it is already loaded"; + goto err; + } + + plugin= add_plugin(mysql, plugin, dlhandle, argc, args); + + pthread_mutex_unlock(&LOCK_load_client_plugin); + + return plugin; + +err: + if (dlhandle) + dlclose(dlhandle); + pthread_mutex_unlock(&LOCK_load_client_plugin); + my_set_error(mysql, CR_AUTH_PLUGIN_CANNOT_LOAD, SQLSTATE_UNKNOWN, + ER(CR_AUTH_PLUGIN_CANNOT_LOAD), name, errmsg); + return NULL; +} + + +/* see for a full description */ +struct st_mysql_client_plugin * STDCALL +mysql_load_plugin(MYSQL *mysql, const char *name, int type, int argc, ...) +{ + struct st_mysql_client_plugin *p; + va_list args; + va_start(args, argc); + p= mysql_load_plugin_v(mysql, name, type, argc, args); + va_end(args); + return p; +} + +/* see for a full description */ +struct st_mysql_client_plugin * STDCALL +mysql_client_find_plugin(MYSQL *mysql, const char *name, int type) +{ + struct st_mysql_client_plugin *p; + int plugin_nr= get_plugin_nr(type); + + if (is_not_initialized(mysql, name)) + return NULL; + + if (plugin_nr == -1) + { + my_set_error(mysql, CR_AUTH_PLUGIN_CANNOT_LOAD, SQLSTATE_UNKNOWN, + ER(CR_AUTH_PLUGIN_CANNOT_LOAD), name, "invalid type"); + } + + if ((p= find_plugin(name, type))) + return p; + + /* not found, load it */ + return mysql_load_plugin(mysql, name, type, 0); +} + diff --git a/vendor/MDBC/libmariadb/ma_compress.c b/vendor/MDBC/libmariadb/ma_compress.c new file mode 100644 index 00000000..55184a03 --- /dev/null +++ b/vendor/MDBC/libmariadb/ma_compress.c @@ -0,0 +1,90 @@ +/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB + 2016 MariaDB Corporation AB + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + MA 02111-1301, USA */ + +/* Written by Sinisa Milivojevic */ + +#include +#ifdef HAVE_COMPRESS +#include +#include +#include + +/* +** This replaces the packet with a compressed packet +** Returns 1 on error +** *complen is 0 if the packet wasn't compressed +*/ + +my_bool _mariadb_compress(unsigned char *packet, size_t *len, size_t *complen) +{ + if (*len < MIN_COMPRESS_LENGTH) + *complen=0; + else + { + unsigned char *compbuf=_mariadb_compress_alloc(packet,len,complen); + if (!compbuf) + return *complen ? 0 : 1; + memcpy(packet,compbuf,*len); + free(compbuf); + } + return 0; +} + + +unsigned char *_mariadb_compress_alloc(const unsigned char *packet, size_t *len, size_t *complen) +{ + unsigned char *compbuf; + *complen = *len * 120 / 100 + 12; + if (!(compbuf = (unsigned char *) malloc(*complen))) + return 0; /* Not enough memory */ + if (compress((Bytef*) compbuf,(ulong *) complen, (Bytef*) packet, + (uLong) *len ) != Z_OK) + { + free(compbuf); + return 0; + } + if (*complen >= *len) + { + *complen=0; + free(compbuf); + return 0; + } + swap(size_t,*len,*complen); /* *len is now packet length */ + return compbuf; +} + +my_bool _mariadb_uncompress (unsigned char *packet, size_t *len, size_t *complen) +{ + if (*complen) /* If compressed */ + { + unsigned char *compbuf = (unsigned char *) malloc (*complen); + if (!compbuf) + return 1; /* Not enough memory */ + if (uncompress((Bytef*) compbuf, (uLongf *)complen, (Bytef*) packet, (uLongf)*len) != Z_OK) + { /* Probably wrong packet */ + free(compbuf); + return 1; + } + *len = *complen; + memcpy(packet,compbuf,*len); + free(compbuf); + } + else *complen= *len; + return 0; +} +#endif /* HAVE_COMPRESS */ diff --git a/vendor/MDBC/libmariadb/ma_context.c b/vendor/MDBC/libmariadb/ma_context.c new file mode 100644 index 00000000..68b35606 --- /dev/null +++ b/vendor/MDBC/libmariadb/ma_context.c @@ -0,0 +1,726 @@ +/* + Copyright 2011, 2012 Kristian Nielsen and Monty Program Ab + 2016 MariaDB Corporation AB + + This file is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this. If not, see . +*/ + +/* + Implementation of async context spawning using Posix ucontext and + swapcontext(). +*/ + +#include "ma_global.h" +#include "ma_string.h" +#include "ma_context.h" + +#ifdef HAVE_VALGRIND +#include +#endif + +#ifdef MY_CONTEXT_USE_UCONTEXT +/* + The makecontext() only allows to pass integers into the created context :-( + We want to pass pointers, so we do it this kinda hackish way. + Anyway, it should work everywhere, and at least it does not break strict + aliasing. +*/ +union pass_void_ptr_as_2_int { + int a[2]; + void *p; +}; + +/* + We use old-style function definition here, as this is passed to + makecontext(). And the type of the makecontext() argument does not match + the actual type (as the actual type can differ from call to call). +*/ +static void +my_context_spawn_internal(i0, i1) +int i0, i1; +{ + int err; + struct my_context *c; + union pass_void_ptr_as_2_int u; + + u.a[0]= i0; + u.a[1]= i1; + c= (struct my_context *)u.p; + + (*c->user_func)(c->user_data); + c->active= 0; + err= setcontext(&c->base_context); + fprintf(stderr, "Aieie, setcontext() failed: %d (errno=%d)\n", err, errno); +} + + +int +my_context_continue(struct my_context *c) +{ + int err; + + if (!c->active) + return 0; + + err= swapcontext(&c->base_context, &c->spawned_context); + if (err) + { + fprintf(stderr, "Aieie, swapcontext() failed: %d (errno=%d)\n", + err, errno); + return -1; + } + + return c->active; +} + + +int +my_context_spawn(struct my_context *c, void (*f)(void *), void *d) +{ + int err; + union pass_void_ptr_as_2_int u; + + err= getcontext(&c->spawned_context); + if (err) + return -1; + c->spawned_context.uc_stack.ss_sp= c->stack; + c->spawned_context.uc_stack.ss_size= c->stack_size; + c->spawned_context.uc_link= NULL; + c->user_func= f; + c->user_data= d; + c->active= 1; + u.p= c; + makecontext(&c->spawned_context, my_context_spawn_internal, 2, + u.a[0], u.a[1]); + + return my_context_continue(c); +} + + +int +my_context_yield(struct my_context *c) +{ + int err; + + if (!c->active) + return -1; + + err= swapcontext(&c->spawned_context, &c->base_context); + if (err) + return -1; + return 0; +} + +int +my_context_init(struct my_context *c, size_t stack_size) +{ +#if SIZEOF_CHARP > SIZEOF_INT*2 +#error Error: Unable to store pointer in 2 ints on this architecture +#endif + + memset(c, 0, sizeof(*c)); + if (!(c->stack= malloc(stack_size))) + return -1; /* Out of memory */ + c->stack_size= stack_size; +#ifdef HAVE_VALGRIND + c->valgrind_stack_id= + VALGRIND_STACK_REGISTER(c->stack, ((unsigned char *)(c->stack))+stack_size); +#endif + return 0; +} + +void +my_context_destroy(struct my_context *c) +{ + if (c->stack) + { +#ifdef HAVE_VALGRIND + VALGRIND_STACK_DEREGISTER(c->valgrind_stack_id); +#endif + free(c->stack); + } +} + +#endif /* MY_CONTEXT_USE_UCONTEXT */ + + +#ifdef MY_CONTEXT_USE_X86_64_GCC_ASM +/* + GCC-amd64 implementation of my_context. + + This is slightly optimized in the common case where we never yield + (eg. fetch next row and it is already fully received in buffer). In this + case we do not need to restore registers at return (though we still need to + save them as we cannot know if we will yield or not in advance). +*/ + +#include +#include + +/* + Layout of saved registers etc. + Since this is accessed through gcc inline assembler, it is simpler to just + use numbers than to try to define nice constants or structs. + + 0 0 %rsp + 1 8 %rbp + 2 16 %rbx + 3 24 %r12 + 4 32 %r13 + 5 40 %r14 + 6 48 %r15 + 7 56 %rip for done + 8 64 %rip for yield/continue +*/ + +int +my_context_spawn(struct my_context *c, void (*f)(void *), void *d) +{ + int ret; + + /* + There are 6 callee-save registers we need to save and restore when + suspending and continuing, plus stack pointer %rsp and instruction pointer + %rip. + + However, if we never suspend, the user-supplied function will in any case + restore the 6 callee-save registers, so we can avoid restoring them in + this case. + */ + __asm__ __volatile__ + ( + "movq %%rsp, (%[save])\n\t" + "movq %[stack], %%rsp\n\t" +#if __GNUC__ >= 4 && __GNUC_MINOR__ >= 4 && !defined(__INTEL_COMPILER) + /* + This emits a DWARF DW_CFA_undefined directive to make the return address + undefined. This indicates that this is the top of the stack frame, and + helps tools that use DWARF stack unwinding to obtain stack traces. + (I use numeric constant to avoid a dependency on libdwarf includes). + */ + ".cfi_escape 0x07, 16\n\t" +#endif + "movq %%rbp, 8(%[save])\n\t" + "movq %%rbx, 16(%[save])\n\t" + "movq %%r12, 24(%[save])\n\t" + "movq %%r13, 32(%[save])\n\t" + "movq %%r14, 40(%[save])\n\t" + "movq %%r15, 48(%[save])\n\t" + "leaq 1f(%%rip), %%rax\n\t" + "leaq 2f(%%rip), %%rcx\n\t" + "movq %%rax, 56(%[save])\n\t" + "movq %%rcx, 64(%[save])\n\t" + /* + Constraint below puts the argument to the user function into %rdi, as + needed for the calling convention. + */ + "callq *%[f]\n\t" + "jmpq *56(%[save])\n" + /* + Come here when operation is done. + We do not need to restore callee-save registers, as the called function + will do this for us if needed. + */ + "1:\n\t" + "movq (%[save]), %%rsp\n\t" + "xorl %[ret], %[ret]\n\t" + "jmp 3f\n" + /* Come here when operation was suspended. */ + "2:\n\t" + "movl $1, %[ret]\n" + "3:\n" + : [ret] "=a" (ret), + [f] "+S" (f), + /* Need this in %rdi to follow calling convention. */ + [d] "+D" (d) + : [stack] "a" (c->stack_top), + /* Need this in callee-save register to preserve in function call. */ + [save] "b" (&c->save[0]) + : "rcx", "rdx", "r8", "r9", "r10", "r11", "memory", "cc" + ); + + return ret; +} + +int +my_context_continue(struct my_context *c) +{ + int ret; + + __asm__ __volatile__ + ( + "movq (%[save]), %%rax\n\t" + "movq %%rsp, (%[save])\n\t" + "movq %%rax, %%rsp\n\t" + "movq 8(%[save]), %%rax\n\t" + "movq %%rbp, 8(%[save])\n\t" + "movq %%rax, %%rbp\n\t" + "movq 24(%[save]), %%rax\n\t" + "movq %%r12, 24(%[save])\n\t" + "movq %%rax, %%r12\n\t" + "movq 32(%[save]), %%rax\n\t" + "movq %%r13, 32(%[save])\n\t" + "movq %%rax, %%r13\n\t" + "movq 40(%[save]), %%rax\n\t" + "movq %%r14, 40(%[save])\n\t" + "movq %%rax, %%r14\n\t" + "movq 48(%[save]), %%rax\n\t" + "movq %%r15, 48(%[save])\n\t" + "movq %%rax, %%r15\n\t" + + "leaq 1f(%%rip), %%rax\n\t" + "leaq 2f(%%rip), %%rcx\n\t" + "movq %%rax, 56(%[save])\n\t" + "movq 64(%[save]), %%rax\n\t" + "movq %%rcx, 64(%[save])\n\t" + + "movq 16(%[save]), %%rcx\n\t" + "movq %%rbx, 16(%[save])\n\t" + "movq %%rcx, %%rbx\n\t" + + "jmpq *%%rax\n" + /* + Come here when operation is done. + Be sure to use the same callee-save register for %[save] here and in + my_context_spawn(), so we preserve the value correctly at this point. + */ + "1:\n\t" + "movq (%[save]), %%rsp\n\t" + "movq 8(%[save]), %%rbp\n\t" + /* %rbx is preserved from my_context_spawn() in this case. */ + "movq 24(%[save]), %%r12\n\t" + "movq 32(%[save]), %%r13\n\t" + "movq 40(%[save]), %%r14\n\t" + "movq 48(%[save]), %%r15\n\t" + "xorl %[ret], %[ret]\n\t" + "jmp 3f\n" + /* Come here when operation is suspended. */ + "2:\n\t" + "movl $1, %[ret]\n" + "3:\n" + : [ret] "=a" (ret) + : /* Need this in callee-save register to preserve in function call. */ + [save] "b" (&c->save[0]) + : "rcx", "rdx", "rsi", "rdi", "r8", "r9", "r10", "r11", "memory", "cc" + ); + + return ret; +} + +int +my_context_yield(struct my_context *c) +{ + uint64_t *save= &c->save[0]; + __asm__ __volatile__ + ( + "movq (%[save]), %%rax\n\t" + "movq %%rsp, (%[save])\n\t" + "movq %%rax, %%rsp\n\t" + "movq 8(%[save]), %%rax\n\t" + "movq %%rbp, 8(%[save])\n\t" + "movq %%rax, %%rbp\n\t" + "movq 16(%[save]), %%rax\n\t" + "movq %%rbx, 16(%[save])\n\t" + "movq %%rax, %%rbx\n\t" + "movq 24(%[save]), %%rax\n\t" + "movq %%r12, 24(%[save])\n\t" + "movq %%rax, %%r12\n\t" + "movq 32(%[save]), %%rax\n\t" + "movq %%r13, 32(%[save])\n\t" + "movq %%rax, %%r13\n\t" + "movq 40(%[save]), %%rax\n\t" + "movq %%r14, 40(%[save])\n\t" + "movq %%rax, %%r14\n\t" + "movq 48(%[save]), %%rax\n\t" + "movq %%r15, 48(%[save])\n\t" + "movq %%rax, %%r15\n\t" + "movq 64(%[save]), %%rax\n\t" + "leaq 1f(%%rip), %%rcx\n\t" + "movq %%rcx, 64(%[save])\n\t" + + "jmpq *%%rax\n" + + "1:\n" + : [save] "+D" (save) + : + : "rax", "rcx", "rdx", "rsi", "r8", "r9", "r10", "r11", "memory", "cc" + ); + return 0; +} + +int +my_context_init(struct my_context *c, size_t stack_size) +{ + memset(c, 0, sizeof(*c)); + + if (!(c->stack_bot= malloc(stack_size))) + return -1; /* Out of memory */ + /* + The x86_64 ABI specifies 16-byte stack alignment. + Also put two zero words at the top of the stack. + */ + c->stack_top= (void *) + (( ((intptr)c->stack_bot + stack_size) & ~(intptr)0xf) - 16); + memset(c->stack_top, 0, 16); + +#ifdef HAVE_VALGRIND + c->valgrind_stack_id= + VALGRIND_STACK_REGISTER(c->stack_bot, c->stack_top); +#endif + return 0; +} + +void +my_context_destroy(struct my_context *c) +{ + if (c->stack_bot) + { + free(c->stack_bot); +#ifdef HAVE_VALGRIND + VALGRIND_STACK_DEREGISTER(c->valgrind_stack_id); +#endif + } +} + +#endif /* MY_CONTEXT_USE_X86_64_GCC_ASM */ + + +#ifdef MY_CONTEXT_USE_I386_GCC_ASM +/* + GCC-i386 implementation of my_context. + + This is slightly optimized in the common case where we never yield + (eg. fetch next row and it is already fully received in buffer). In this + case we do not need to restore registers at return (though we still need to + save them as we cannot know if we will yield or not in advance). +*/ + +#include +#include + +/* + Layout of saved registers etc. + Since this is accessed through gcc inline assembler, it is simpler to just + use numbers than to try to define nice constants or structs. + + 0 0 %esp + 1 4 %ebp + 2 8 %ebx + 3 12 %esi + 4 16 %edi + 5 20 %eip for done + 6 24 %eip for yield/continue +*/ + +int +my_context_spawn(struct my_context *c, void (*f)(void *), void *d) +{ + int ret; + + /* + There are 4 callee-save registers we need to save and restore when + suspending and continuing, plus stack pointer %esp and instruction pointer + %eip. + + However, if we never suspend, the user-supplied function will in any case + restore the 4 callee-save registers, so we can avoid restoring them in + this case. + */ + __asm__ __volatile__ + ( + "movl %%esp, (%[save])\n\t" + "movl %[stack], %%esp\n\t" +#if __GNUC__ >= 4 && __GNUC_MINOR__ >= 4 && !defined(__INTEL_COMPILER) + /* + This emits a DWARF DW_CFA_undefined directive to make the return address + undefined. This indicates that this is the top of the stack frame, and + helps tools that use DWARF stack unwinding to obtain stack traces. + (I use numeric constant to avoid a dependency on libdwarf includes). + */ + ".cfi_escape 0x07, 8\n\t" +#endif + /* Push the parameter on the stack. */ + "pushl %[d]\n\t" + "movl %%ebp, 4(%[save])\n\t" + "movl %%ebx, 8(%[save])\n\t" + "movl %%esi, 12(%[save])\n\t" + "movl %%edi, 16(%[save])\n\t" + /* Get label addresses in -fPIC-compatible way (no pc-relative on 32bit) */ + "call 1f\n" + "1:\n\t" + "popl %%eax\n\t" + "addl $(2f-1b), %%eax\n\t" + "movl %%eax, 20(%[save])\n\t" + "addl $(3f-2f), %%eax\n\t" + "movl %%eax, 24(%[save])\n\t" + "call *%[f]\n\t" + "jmp *20(%[save])\n" + /* + Come here when operation is done. + We do not need to restore callee-save registers, as the called function + will do this for us if needed. + */ + "2:\n\t" + "movl (%[save]), %%esp\n\t" + "xorl %[ret], %[ret]\n\t" + "jmp 4f\n" + /* Come here when operation was suspended. */ + "3:\n\t" + "movl $1, %[ret]\n" + "4:\n" + : [ret] "=a" (ret), + [f] "+c" (f), + [d] "+d" (d) + : [stack] "a" (c->stack_top), + /* Need this in callee-save register to preserve across function call. */ + [save] "D" (&c->save[0]) + : "memory", "cc" + ); + + return ret; +} + +int +my_context_continue(struct my_context *c) +{ + int ret; + + __asm__ __volatile__ + ( + "movl (%[save]), %%eax\n\t" + "movl %%esp, (%[save])\n\t" + "movl %%eax, %%esp\n\t" + "movl 4(%[save]), %%eax\n\t" + "movl %%ebp, 4(%[save])\n\t" + "movl %%eax, %%ebp\n\t" + "movl 8(%[save]), %%eax\n\t" + "movl %%ebx, 8(%[save])\n\t" + "movl %%eax, %%ebx\n\t" + "movl 12(%[save]), %%eax\n\t" + "movl %%esi, 12(%[save])\n\t" + "movl %%eax, %%esi\n\t" + + "movl 24(%[save]), %%eax\n\t" + "call 1f\n" + "1:\n\t" + "popl %%ecx\n\t" + "addl $(2f-1b), %%ecx\n\t" + "movl %%ecx, 20(%[save])\n\t" + "addl $(3f-2f), %%ecx\n\t" + "movl %%ecx, 24(%[save])\n\t" + + /* Must restore %edi last as it is also our %[save] register. */ + "movl 16(%[save]), %%ecx\n\t" + "movl %%edi, 16(%[save])\n\t" + "movl %%ecx, %%edi\n\t" + + "jmp *%%eax\n" + /* + Come here when operation is done. + Be sure to use the same callee-save register for %[save] here and in + my_context_spawn(), so we preserve the value correctly at this point. + */ + "2:\n\t" + "movl (%[save]), %%esp\n\t" + "movl 4(%[save]), %%ebp\n\t" + "movl 8(%[save]), %%ebx\n\t" + "movl 12(%[save]), %%esi\n\t" + "movl 16(%[save]), %%edi\n\t" + "xorl %[ret], %[ret]\n\t" + "jmp 4f\n" + /* Come here when operation is suspended. */ + "3:\n\t" + "movl $1, %[ret]\n" + "4:\n" + : [ret] "=a" (ret) + : /* Need this in callee-save register to preserve in function call. */ + [save] "D" (&c->save[0]) + : "ecx", "edx", "memory", "cc" + ); + + return ret; +} + +int +my_context_yield(struct my_context *c) +{ + uint64_t *save= &c->save[0]; + __asm__ __volatile__ + ( + "movl (%[save]), %%eax\n\t" + "movl %%esp, (%[save])\n\t" + "movl %%eax, %%esp\n\t" + "movl 4(%[save]), %%eax\n\t" + "movl %%ebp, 4(%[save])\n\t" + "movl %%eax, %%ebp\n\t" + "movl 8(%[save]), %%eax\n\t" + "movl %%ebx, 8(%[save])\n\t" + "movl %%eax, %%ebx\n\t" + "movl 12(%[save]), %%eax\n\t" + "movl %%esi, 12(%[save])\n\t" + "movl %%eax, %%esi\n\t" + "movl 16(%[save]), %%eax\n\t" + "movl %%edi, 16(%[save])\n\t" + "movl %%eax, %%edi\n\t" + + "movl 24(%[save]), %%eax\n\t" + "call 1f\n" + "1:\n\t" + "popl %%ecx\n\t" + "addl $(2f-1b), %%ecx\n\t" + "movl %%ecx, 24(%[save])\n\t" + + "jmp *%%eax\n" + + "2:\n" + : [save] "+d" (save) + : + : "eax", "ecx", "memory", "cc" + ); + return 0; +} + +int +my_context_init(struct my_context *c, size_t stack_size) +{ + memset(c, 0, sizeof(*c)); + if (!(c->stack_bot= malloc(stack_size))) + return -1; /* Out of memory */ + c->stack_top= (void *) + (( ((intptr)c->stack_bot + stack_size) & ~(intptr)0xf) - 16); + memset(c->stack_top, 0, 16); + +#ifdef HAVE_VALGRIND + c->valgrind_stack_id= + VALGRIND_STACK_REGISTER(c->stack_bot, c->stack_top); +#endif + return 0; +} + +void +my_context_destroy(struct my_context *c) +{ + if (c->stack_bot) + { + free(c->stack_bot); +#ifdef HAVE_VALGRIND + VALGRIND_STACK_DEREGISTER(c->valgrind_stack_id); +#endif + } +} + +#endif /* MY_CONTEXT_USE_I386_GCC_ASM */ + + +#ifdef MY_CONTEXT_USE_WIN32_FIBERS +int +my_context_yield(struct my_context *c) +{ + c->return_value= 1; + SwitchToFiber(c->app_fiber); + return 0; +} + + +static void WINAPI +my_context_trampoline(void *p) +{ + struct my_context *c= (struct my_context *)p; + /* + Reuse the Fiber by looping infinitely, each time we are scheduled we + spawn the appropriate function and switch back when it is done. + + This way we avoid the overhead of CreateFiber() for every asynchroneous + operation. + */ + for(;;) + { + (*(c->user_func))(c->user_arg); + c->return_value= 0; + SwitchToFiber(c->app_fiber); + } +} + +int +my_context_init(struct my_context *c, size_t stack_size) +{ + memset(c, 0, sizeof(*c)); + c->lib_fiber= CreateFiber(stack_size, my_context_trampoline, c); + if (c->lib_fiber) + return 0; + return -1; +} + +void +my_context_destroy(struct my_context *c) +{ + if (c->lib_fiber) + { + DeleteFiber(c->lib_fiber); + c->lib_fiber= NULL; + } +} + +int +my_context_spawn(struct my_context *c, void (*f)(void *), void *d) +{ + c->user_func= f; + c->user_arg= d; + return my_context_continue(c); +} + +int +my_context_continue(struct my_context *c) +{ + void *current_fiber= IsThreadAFiber() ? GetCurrentFiber() : ConvertThreadToFiber(c); + c->app_fiber= current_fiber; + SwitchToFiber(c->lib_fiber); + return c->return_value; +} + +#endif /* MY_CONTEXT_USE_WIN32_FIBERS */ + +#ifdef MY_CONTEXT_DISABLE +int +my_context_continue(struct my_context *c) +{ + return -1; +} + + +int +my_context_spawn(struct my_context *c, void (*f)(void *), void *d) +{ + return -1; +} + + +int +my_context_yield(struct my_context *c) +{ + return -1; +} + +int +my_context_init(struct my_context *c, size_t stack_size) +{ + return -1; /* Out of memory */ +} + +void +my_context_destroy(struct my_context *c) +{ +} + +#endif diff --git a/vendor/MDBC/libmariadb/ma_default.c b/vendor/MDBC/libmariadb/ma_default.c new file mode 100644 index 00000000..1bc8506f --- /dev/null +++ b/vendor/MDBC/libmariadb/ma_default.c @@ -0,0 +1,370 @@ +/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB + 2016 MariaDB Corporation AB + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + MA 02111-1301, USA */ + +#include +#include +#include "ma_string.h" +#include +#include "mariadb_ctype.h" +#include +#include +#include + +#ifdef _WIN32 +#include +#include "shlwapi.h" + +static const char *ini_exts[]= {"ini", "cnf", 0}; +#define R_OK 4 +#else +#include +static const char *ini_exts[]= {"cnf", 0}; +#endif + +char **configuration_dirs= NULL; +#define MAX_CONFIG_DIRS 6 + +my_bool _mariadb_read_options(MYSQL *mysql, + const char *config_dir, + const char *config_file, + const char *group, + unsigned int recursion); + +static int add_cfg_dir(char **cfg_dirs, const char *directory) +{ + int i; + + for (i = 0; i < MAX_CONFIG_DIRS && cfg_dirs[i]; i++) + if (!strcmp(cfg_dirs[i], directory)) /* already present */ + return 0; + + if (i < MAX_CONFIG_DIRS) { + cfg_dirs[i]= strdup(directory); + return 0; + } + return 1; +} + +void release_configuration_dirs() +{ + if (configuration_dirs) + { + int i= 0; + while (configuration_dirs[i]) + free(configuration_dirs[i++]); + free(configuration_dirs); + } +} + +char **get_default_configuration_dirs() +{ +#ifdef _WIN32 + char dirname[FN_REFLEN]; +#endif + char *env; + + configuration_dirs= (char **)calloc(1, (MAX_CONFIG_DIRS + 1) * sizeof(char *)); + if (!configuration_dirs) + goto end; + +#ifdef _WIN32 + /* On Windows operating systems configuration files are stored in + 1. System Windows directory + 2. System directory + 3. Windows directory + 4. C:\ + */ + + if (!GetSystemWindowsDirectory(dirname, FN_REFLEN) || + add_cfg_dir(configuration_dirs, dirname)) + goto error; + + if (!GetWindowsDirectory(dirname, FN_REFLEN) || + add_cfg_dir(configuration_dirs, dirname)) + goto error; + + if (add_cfg_dir(configuration_dirs, "C:")) + goto error; + + if (GetModuleFileName(NULL, dirname, FN_REFLEN)) + { + PathRemoveFileSpec(dirname); + if (add_cfg_dir(configuration_dirs, dirname)) + goto error; + } +#else + /* on *nix platforms configuration files are stored in + 1. SYSCONFDIR (if build happens inside server package, or + -DDEFAULT_SYSCONFDIR was specified + 2. /etc + 3. /etc/mysql + */ +#ifdef DEFAULT_SYSCONFDIR + if (add_cfg_dir(configuration_dirs, DEFAULT_SYSCONFDIR)) + goto error; +#else + if (add_cfg_dir(configuration_dirs, "/etc")) + goto error; + if (add_cfg_dir(configuration_dirs, "/etc/mysql")) + goto error; +#endif +#endif + /* CONC-537: Read configuration files from MYSQL_HOME directory only if + MARIADB_HOME was not set */ + if (!(env= getenv("MARIADB_HOME"))) + env= getenv("MYSQL_HOME"); + if (env && add_cfg_dir(configuration_dirs, env)) + goto error; +end: + return configuration_dirs; +error: + return NULL; +} + +extern my_bool _mariadb_set_conf_option(MYSQL *mysql, const char *config_option, const char *config_value); + +static my_bool is_group(char *ptr, const char **groups) +{ + while (*groups) + { + if (!strcmp(ptr, *groups)) + return 1; + groups++; + } + return 0; +} + +static my_bool _mariadb_read_options_from_file(MYSQL *mysql, + const char *config_file, + const char *group, + unsigned int recursion) +{ + uint line=0; + my_bool read_values= 0, found_group= 0, is_escaped= 0, is_quoted= 0; + char buff[4096],*ptr,*end,*value, *key= 0, *optval; + MA_FILE *file= NULL; + my_bool rc= 1; + const char *groups[5]= {"client", + "client-server", + "client-mariadb", + group, + NULL}; + my_bool (*set_option)(MYSQL *mysql, const char *config_option, const char *config_value); + + + /* if a plugin registered a hook we will call this hook, otherwise + * default (_mariadb_set_conf_option) will be called */ + if (mysql->options.extension && mysql->options.extension->set_option) + set_option= mysql->options.extension->set_option; + else + set_option= _mariadb_set_conf_option; + + if (!(file = ma_open(config_file, "r", NULL))) + goto err; + + while (ma_gets(buff,sizeof(buff)-1,file)) + { + line++; + key= 0; + /* Ignore comment and empty lines */ + for (ptr=buff ; isspace(*ptr) ; ptr++ ); + if (!is_escaped && (*ptr == '\"' || *ptr== '\'')) + { + is_quoted= !is_quoted; + continue; + } + /* CONC- 327: !includedir and !include */ + if (*ptr == '!') + { + char *val; + ptr++; + if (!(val= strchr(ptr, ' '))) + continue; + *val++= 0; + end= strchr(val, 0); + for ( ; isspace(end[-1]) ; end--) ; /* Remove end space */ + *end= 0; + if (!strcmp(ptr, "includedir")) + _mariadb_read_options(mysql, (const char *)val, NULL, group, recursion + 1); + else if (!strcmp(ptr, "include")) + _mariadb_read_options(mysql, NULL, (const char *)val, group, recursion + 1); + continue; + } + if (*ptr == '#' || *ptr == ';' || !*ptr) + continue; + is_escaped= (*ptr == '\\'); + if (*ptr == '[') /* Group name */ + { + found_group=1; + if (!(end=(char *) strchr(++ptr,']'))) + { + /* todo: set error */ + goto err; + } + for ( ; isspace(end[-1]) ; end--) ; /* Remove end space */ + end[0]=0; + read_values= is_group(ptr, groups); + continue; + } + if (!found_group) + { + /* todo: set error */ + goto err; + } + if (!read_values) + continue; + if (!(end=value=strchr(ptr,'='))) + { + end=strchr(ptr, '\0'); /* Option without argument */ + set_option(mysql, ptr, NULL); + } + if (!key) + key= ptr; + for ( ; isspace(end[-1]) ; end--) ; + *end= 0; + if (value) + { + /* Remove pre- and end space */ + char *value_end; + *value= 0; + value++; + ptr= value; + for ( ; isspace(*value); value++) ; + value_end=strchr(value, '\0'); + *value_end= 0; + optval= ptr; + for ( ; isspace(value_end[-1]) ; value_end--) ; + /* remove possible quotes */ + if (*value == '\'' || *value == '\"') + { + value++; + if (value_end[-1] == '\'' || value_end[-1] == '\"') + value_end--; + } + if (value_end < value) /* Empty string */ + value_end=value; + for ( ; value != value_end; value++) + { + if (*value == '\\' && value != value_end-1) + { + switch(*++value) { + case 'n': + *ptr++='\n'; + break; + case 't': + *ptr++= '\t'; + break; + case 'r': + *ptr++ = '\r'; + break; + case 'b': + *ptr++ = '\b'; + break; + case 's': + *ptr++= ' '; /* space */ + break; + case '\"': + *ptr++= '\"'; + break; + case '\'': + *ptr++= '\''; + break; + case '\\': + *ptr++= '\\'; + break; + default: /* Unknown; Keep '\' */ + *ptr++= '\\'; + *ptr++= *value; + break; + } + } + else + *ptr++= *value; + } + *ptr=0; + set_option(mysql, key, optval); + key= optval= 0; + } + } + rc= 0; + +err: + if (file) + ma_close(file); + return rc; +} + + +my_bool _mariadb_read_options(MYSQL *mysql, + const char *config_dir, + const char *config_file, + const char *group, + unsigned int recursion) +{ + int i= 0, + exts, + errors= 0; + char filename[FN_REFLEN + 1]; + unsigned int recursion_stop= 64; +#ifndef _WIN32 + char *env; +#endif + + if (recursion >= recursion_stop) + return 1; + + if (config_file && config_file[0]) + return _mariadb_read_options_from_file(mysql, config_file, group, recursion); + + if (config_dir && config_dir[0]) + { + for (exts= 0; ini_exts[exts]; exts++) + { + snprintf(filename, FN_REFLEN, + "%s%cmy.%s", config_dir, FN_LIBCHAR, ini_exts[exts]); + if (!access(filename, R_OK)) + errors+= _mariadb_read_options_from_file(mysql, filename, group, recursion); + } + return errors; + } + + for (i=0; i < MAX_CONFIG_DIRS && configuration_dirs[i]; i++) + { + for (exts= 0; ini_exts[exts]; exts++) + { + snprintf(filename, FN_REFLEN, + "%s%cmy.%s", configuration_dirs[i], FN_LIBCHAR, ini_exts[exts]); + if (!access(filename, R_OK)) + errors+= _mariadb_read_options_from_file(mysql, filename, group, recursion); + } + } +#ifndef _WIN32 + /* special case: .my.cnf in Home directory */ + if ((env= getenv("HOME"))) + { + for (exts= 0; ini_exts[exts]; exts++) + { + snprintf(filename, FN_REFLEN, + "%s%c.my.%s", env, FN_LIBCHAR, ini_exts[exts]); + if (!access(filename, R_OK)) + errors+= _mariadb_read_options_from_file(mysql, filename, group, recursion); + } + } +#endif + return errors; +} diff --git a/vendor/MDBC/libmariadb/ma_dtoa.c b/vendor/MDBC/libmariadb/ma_dtoa.c new file mode 100644 index 00000000..8fdff6b8 --- /dev/null +++ b/vendor/MDBC/libmariadb/ma_dtoa.c @@ -0,0 +1,1924 @@ +/* Copyright (c) 2007, 2012, Oracle and/or its affiliates. All rights reserved. + 2016,2018 MariaDB Corporation AB + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; version 2 + of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ + +/**************************************************************** + + This file incorporates work covered by the following copyright and + permission notice: + + The author of this software is David M. Gay. + + Copyright (c) 1991, 2000, 2001 by Lucent Technologies. + + Permission to use, copy, modify, and distribute this software for any + purpose without fee is hereby granted, provided that this entire notice + is included in all copies of any software which is or includes a copy + or modification of this software and in all copies of the supporting + documentation for such software. + + THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED + WARRANTY. IN PARTICULAR, NEITHER THE AUTHOR NOR LUCENT MAKES ANY + REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY + OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. + + ***************************************************************/ + +//#include "strings_def.h" +//#include /* for EOVERFLOW on Windows */ +#include +#include +#include "ma_string.h" + +/** + Appears to suffice to not call malloc() in most cases. + @todo + see if it is possible to get rid of malloc(). + this constant is sufficient to avoid malloc() on all inputs I have tried. +*/ +#define DTOA_BUFF_SIZE (460 * sizeof(void *)) + +/* Magic value returned by dtoa() to indicate overflow */ +#define DTOA_OVERFLOW 9999 + +static char *dtoa(double, int, int, int *, int *, char **, char *, size_t); +static void dtoa_free(char *, char *, size_t); + +/** + @brief + Converts a given floating point number to a zero-terminated string + representation using the 'f' format. + + @details + This function is a wrapper around dtoa() to do the same as + sprintf(to, "%-.*f", precision, x), though the conversion is usually more + precise. The only difference is in handling [-,+]infinity and nan values, + in which case we print '0\0' to the output string and indicate an overflow. + + @param x the input floating point number. + @param precision the number of digits after the decimal point. + All properties of sprintf() apply: + - if the number of significant digits after the decimal + point is less than precision, the resulting string is + right-padded with zeros + - if the precision is 0, no decimal point appears + - if a decimal point appears, at least one digit appears + before it + @param to pointer to the output buffer. The longest string which + my_fcvt() can return is FLOATING_POINT_BUFFER bytes + (including the terminating '\0'). + @param error if not NULL, points to a location where the status of + conversion is stored upon return. + FALSE successful conversion + TRUE the input number is [-,+]infinity or nan. + The output string in this case is always '0'. + @return number of written characters (excluding terminating '\0') +*/ + +size_t ma_fcvt(double x, int precision, char *to, my_bool *error) +{ + int decpt, sign, len, i; + char *res, *src, *end, *dst= to; + char buf[DTOA_BUFF_SIZE]; + DBUG_ASSERT(precision >= 0 && precision < NOT_FIXED_DEC && to != NULL); + + res= dtoa(x, 5, precision, &decpt, &sign, &end, buf, sizeof(buf)); + + if (decpt == DTOA_OVERFLOW) + { + dtoa_free(res, buf, sizeof(buf)); + *to++= '0'; + *to= '\0'; + if (error != NULL) + *error= TRUE; + return 1; + } + + src= res; + len= (int)(end - src); + + if (sign) + *dst++= '-'; + + if (decpt <= 0) + { + *dst++= '0'; + *dst++= '.'; + for (i= decpt; i < 0; i++) + *dst++= '0'; + } + + for (i= 1; i <= len; i++) + { + *dst++= *src++; + if (i == decpt && i < len) + *dst++= '.'; + } + while (i++ <= decpt) + *dst++= '0'; + + if (precision > 0) + { + if (len <= decpt) + *dst++= '.'; + + for (i= precision - MAX(0, (len - decpt)); i > 0; i--) + *dst++= '0'; + } + + *dst= '\0'; + if (error != NULL) + *error= FALSE; + + dtoa_free(res, buf, sizeof(buf)); + + return dst - to; +} + +/** + @brief + Converts a given floating point number to a zero-terminated string + representation with a given field width using the 'e' format + (aka scientific notation) or the 'f' one. + + @details + The format is chosen automatically to provide the most number of significant + digits (and thus, precision) with a given field width. In many cases, the + result is similar to that of sprintf(to, "%g", x) with a few notable + differences: + - the conversion is usually more precise than C library functions. + - there is no 'precision' argument. instead, we specify the number of + characters available for conversion (i.e. a field width). + - the result never exceeds the specified field width. If the field is too + short to contain even a rounded decimal representation, ma_gcvt() + indicates overflow and truncates the output string to the specified width. + - float-type arguments are handled differently than double ones. For a + float input number (i.e. when the 'type' argument is MY_GCVT_ARG_FLOAT) + we deliberately limit the precision of conversion by FLT_DIG digits to + avoid garbage past the significant digits. + - unlike sprintf(), in cases where the 'e' format is preferred, we don't + zero-pad the exponent to save space for significant digits. The '+' sign + for a positive exponent does not appear for the same reason. + + @param x the input floating point number. + @param type is either MY_GCVT_ARG_FLOAT or MY_GCVT_ARG_DOUBLE. + Specifies the type of the input number (see notes above). + @param width field width in characters. The minimal field width to + hold any number representation (albeit rounded) is 7 + characters ("-Ne-NNN"). + @param to pointer to the output buffer. The result is always + zero-terminated, and the longest returned string is thus + 'width + 1' bytes. + @param error if not NULL, points to a location where the status of + conversion is stored upon return. + FALSE successful conversion + TRUE the input number is [-,+]infinity or nan. + The output string in this case is always '0'. + @return number of written characters (excluding terminating '\0') + + @todo + Check if it is possible and makes sense to do our own rounding on top of + dtoa() instead of calling dtoa() twice in (rare) cases when the resulting + string representation does not fit in the specified field width and we want + to re-round the input number with fewer significant digits. Examples: + + ma_gcvt(-9e-3, ..., 4, ...); + ma_gcvt(-9e-3, ..., 2, ...); + ma_gcvt(1.87e-3, ..., 4, ...); + ma_gcvt(55, ..., 1, ...); + + We do our best to minimize such cases by: + + - passing to dtoa() the field width as the number of significant digits + + - removing the sign of the number early (and decreasing the width before + passing it to dtoa()) + + - choosing the proper format to preserve the most number of significant + digits. +*/ + +size_t ma_gcvt(double x, my_gcvt_arg_type type, int width, char *to, + my_bool *error) +{ + int decpt, sign, len, exp_len; + char *res, *src, *end, *dst= to, *dend= dst + width; + char buf[DTOA_BUFF_SIZE]; + my_bool have_space, force_e_format; + DBUG_ASSERT(width > 0 && to != NULL); + + /* We want to remove '-' from equations early */ + if (x < 0.) + width--; + + res= dtoa(x, 4, type == MY_GCVT_ARG_DOUBLE ? width : MIN(width, FLT_DIG), + &decpt, &sign, &end, buf, sizeof(buf)); + if (decpt == DTOA_OVERFLOW) + { + dtoa_free(res, buf, sizeof(buf)); + *to++= '0'; + *to= '\0'; + if (error != NULL) + *error= TRUE; + return 1; + } + + if (error != NULL) + *error= FALSE; + + src= res; + len= (int)(end - res); + + /* + Number of digits in the exponent from the 'e' conversion. + The sign of the exponent is taken into account separetely, we don't need + to count it here. + */ + exp_len= 1 + (decpt >= 101 || decpt <= -99) + (decpt >= 11 || decpt <= -9); + + /* + Do we have enough space for all digits in the 'f' format? + Let 'len' be the number of significant digits returned by dtoa, + and F be the length of the resulting decimal representation. + Consider the following cases: + 1. decpt <= 0, i.e. we have "0.NNN" => F = len - decpt + 2 + 2. 0 < decpt < len, i.e. we have "NNN.NNN" => F = len + 1 + 3. len <= decpt, i.e. we have "NNN00" => F = decpt + */ + have_space= (decpt <= 0 ? len - decpt + 2 : + decpt > 0 && decpt < len ? len + 1 : + decpt) <= width; + /* + The following is true when no significant digits can be placed with the + specified field width using the 'f' format, and the 'e' format + will not be truncated. + */ + force_e_format= (decpt <= 0 && width <= 2 - decpt && width >= 3 + exp_len); + /* + Assume that we don't have enough space to place all significant digits in + the 'f' format. We have to choose between the 'e' format and the 'f' one + to keep as many significant digits as possible. + Let E and F be the lengths of decimal representation in the 'e' and 'f' + formats, respectively. We want to use the 'f' format if, and only if F <= E. + Consider the following cases: + 1. decpt <= 0. + F = len - decpt + 2 (see above) + E = len + (len > 1) + 1 + 1 (decpt <= -99) + (decpt <= -9) + 1 + ("N.NNe-MMM") + (F <= E) <=> (len == 1 && decpt >= -1) || (len > 1 && decpt >= -2) + We also need to ensure that if the 'f' format is chosen, + the field width allows us to place at least one significant digit + (i.e. width > 2 - decpt). If not, we prefer the 'e' format. + 2. 0 < decpt < len + F = len + 1 (see above) + E = len + 1 + 1 + ... ("N.NNeMMM") + F is always less than E. + 3. len <= decpt <= width + In this case we have enough space to represent the number in the 'f' + format, so we prefer it with some exceptions. + 4. width < decpt + The number cannot be represented in the 'f' format at all, always use + the 'e' 'one. + */ + if ((have_space || + /* + Not enough space, let's see if the 'f' format provides the most number + of significant digits. + */ + ((decpt <= width && (decpt >= -1 || (decpt == -2 && + (len > 1 || !force_e_format)))) && + !force_e_format)) && + + /* + Use the 'e' format in some cases even if we have enough space for the + 'f' one. See comment for DBL_DIG. + */ + (!have_space || (decpt >= -DBL_DIG + 1 && + (decpt <= DBL_DIG || len > decpt)))) + { + /* 'f' format */ + int i; + + width-= (decpt < len) + (decpt <= 0 ? 1 - decpt : 0); + + /* Do we have to truncate any digits? */ + if (width < len) + { + if (width < decpt) + { + if (error != NULL) + *error= TRUE; + width= decpt; + } + + /* + We want to truncate (len - width) least significant digits after the + decimal point. For this we are calling dtoa with mode=5, passing the + number of significant digits = (len-decpt) - (len-width) = width-decpt + */ + dtoa_free(res, buf, sizeof(buf)); + res= dtoa(x, 5, width - decpt, &decpt, &sign, &end, buf, sizeof(buf)); + src= res; + len= (int)(end - res); + } + + if (len == 0) + { + /* Underflow. Just print '0' and exit */ + *dst++= '0'; + goto end; + } + + /* + At this point we are sure we have enough space to put all digits + returned by dtoa + */ + if (sign && dst < dend) + *dst++= '-'; + if (decpt <= 0) + { + if (dst < dend) + *dst++= '0'; + if (len > 0 && dst < dend) + *dst++= '.'; + for (; decpt < 0 && dst < dend; decpt++) + *dst++= '0'; + } + + for (i= 1; i <= len && dst < dend; i++) + { + *dst++= *src++; + if (i == decpt && i < len && dst < dend) + *dst++= '.'; + } + while (i++ <= decpt && dst < dend) + *dst++= '0'; + } + else + { + /* 'e' format */ + int decpt_sign= 0; + + if (--decpt < 0) + { + decpt= -decpt; + width--; + decpt_sign= 1; + } + width-= 1 + exp_len; /* eNNN */ + + if (len > 1) + width--; + + if (width <= 0) + { + /* Overflow */ + if (error != NULL) + *error= TRUE; + width= 0; + } + + /* Do we have to truncate any digits? */ + if (width < len) + { + /* Yes, re-convert with a smaller width */ + dtoa_free(res, buf, sizeof(buf)); + res= dtoa(x, 4, width, &decpt, &sign, &end, buf, sizeof(buf)); + src= res; + len= (int)(end - res); + if (--decpt < 0) + decpt= -decpt; + } + /* + At this point we are sure we have enough space to put all digits + returned by dtoa + */ + if (sign && dst < dend) + *dst++= '-'; + if (dst < dend) + *dst++= *src++; + if (len > 1 && dst < dend) + { + *dst++= '.'; + while (src < end && dst < dend) + *dst++= *src++; + } + if (dst < dend) + *dst++= 'e'; + if (decpt_sign && dst < dend) + *dst++= '-'; + + if (decpt >= 100 && dst < dend) + { + *dst++= decpt / 100 + '0'; + decpt%= 100; + if (dst < dend) + *dst++= decpt / 10 + '0'; + } + else if (decpt >= 10 && dst < dend) + *dst++= decpt / 10 + '0'; + if (dst < dend) + *dst++= decpt % 10 + '0'; + + } + +end: + dtoa_free(res, buf, sizeof(buf)); + *dst= '\0'; + + return dst - to; +} + +/**************************************************************** + * + * The author of this software is David M. Gay. + * + * Copyright (c) 1991, 2000, 2001 by Lucent Technologies. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose without fee is hereby granted, provided that this entire notice + * is included in all copies of any software which is or includes a copy + * or modification of this software and in all copies of the supporting + * documentation for such software. + * + * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED + * WARRANTY. IN PARTICULAR, NEITHER THE AUTHOR NOR LUCENT MAKES ANY + * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY + * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. + * + ***************************************************************/ +/* Please send bug reports to David M. Gay (dmg at acm dot org, + * with " at " changed at "@" and " dot " changed to "."). */ + +/* + Original copy of the software is located at http://www.netlib.org/fp/dtoa.c + It was adjusted to serve MySQL server needs: + * strtod() was modified to not expect a zero-terminated string. + It now honors 'se' (end of string) argument as the input parameter, + not just as the output one. + * in dtoa(), in case of overflow/underflow/NaN result string now contains "0"; + decpt is set to DTOA_OVERFLOW to indicate overflow. + * support for VAX, IBM mainframe and 16-bit hardware removed + * we always assume that 64-bit integer type is available + * support for Kernigan-Ritchie style headers (pre-ANSI compilers) + removed + * all gcc warnings ironed out + * we always assume multithreaded environment, so we had to change + memory allocation procedures to use stack in most cases; + malloc is used as the last resort. + * pow5mult rewritten to use pre-calculated pow5 list instead of + the one generated on the fly. +*/ + + +/* + On a machine with IEEE extended-precision registers, it is + necessary to specify double-precision (53-bit) rounding precision + before invoking strtod or dtoa. If the machine uses (the equivalent + of) Intel 80x87 arithmetic, the call + _control87(PC_53, MCW_PC); + does this with many compilers. Whether this or another call is + appropriate depends on the compiler; for this to work, it may be + necessary to #include "float.h" or another system-dependent header + file. +*/ + +/* + #define Honor_FLT_ROUNDS if FLT_ROUNDS can assume the values 2 or 3 + and dtoa should round accordingly. + #define Check_FLT_ROUNDS if FLT_ROUNDS can assume the values 2 or 3 + and Honor_FLT_ROUNDS is not #defined. + + TODO: check if we can get rid of the above two +*/ + +typedef int32 Long; +typedef uint32 ULong; +typedef int64 LLong; +typedef uint64 ULLong; + +typedef union { double d; ULong L[2]; } U; + +#if defined(HAVE_BIGENDIAN) || defined(WORDS_BIGENDIAN) || \ + (defined(__FLOAT_WORD_ORDER) && (__FLOAT_WORD_ORDER == __BIG_ENDIAN)) +#define word0(x) ((x)->L[0]) +#define word1(x) ((x)->L[1]) +#else +#define word0(x) ((x)->L[1]) +#define word1(x) ((x)->L[0]) +#endif + +#define dval(x) ((x)->d) + +/* #define P DBL_MANT_DIG */ +/* Ten_pmax= floor(P*log(2)/log(5)) */ +/* Bletch= (highest power of 2 < DBL_MAX_10_EXP) / 16 */ +/* Quick_max= floor((P-1)*log(FLT_RADIX)/log(10) - 1) */ +/* Int_max= floor(P*log(FLT_RADIX)/log(10) - 1) */ + +#define Exp_shift 20 +#define Exp_shift1 20 +#define Exp_msk1 0x100000 +#define Exp_mask 0x7ff00000 +#define P 53 +#define Bias 1023 +#define Emin (-1022) +#define Exp_1 0x3ff00000 +#define Exp_11 0x3ff00000 +#define Ebits 11 +#define Frac_mask 0xfffff +#define Frac_mask1 0xfffff +#define Ten_pmax 22 +#define Bletch 0x10 +#define Bndry_mask 0xfffff +#define Bndry_mask1 0xfffff +#define LSB 1 +#define Sign_bit 0x80000000 +#define Log2P 1 +#define Tiny1 1 +#define Quick_max 14 +#define Int_max 14 + +#ifndef Flt_Rounds +#ifdef FLT_ROUNDS +#define Flt_Rounds FLT_ROUNDS +#else +#define Flt_Rounds 1 +#endif +#endif /*Flt_Rounds*/ + +#ifdef Honor_FLT_ROUNDS +#define Rounding rounding +#undef Check_FLT_ROUNDS +#define Check_FLT_ROUNDS +#else +#define Rounding Flt_Rounds +#endif + +#define rounded_product(a,b) ((a)*= (b)) +#define rounded_quotient(a,b) ((a)/= (b)) + +#define Big0 (Frac_mask1 | Exp_msk1*(DBL_MAX_EXP+Bias-1)) +#define Big1 0xffffffff +#define FFFFFFFF 0xffffffffUL + +/* This is tested to be enough for dtoa */ + +#define Kmax 15 + +#define Bcopy(x,y) memcpy((char *)&(x)->sign, (char *)&(y)->sign, \ + 2*sizeof(int) + (y)->wds*sizeof(ULong)) + +/* Arbitrary-length integer */ + +typedef struct Bigint +{ + union { + ULong *x; /* points right after this Bigint object */ + struct Bigint *next; /* to maintain free lists */ + } p; + int k; /* 2^k = maxwds */ + int maxwds; /* maximum length in 32-bit words */ + int sign; /* not zero if number is negative */ + int wds; /* current length in 32-bit words */ +} Bigint; + + +/* A simple stack-memory based allocator for Bigints */ + +typedef struct Stack_alloc +{ + char *begin; + char *free; + char *end; + /* + Having list of free blocks lets us reduce maximum required amount + of memory from ~4000 bytes to < 1680 (tested on x86). + */ + Bigint *freelist[Kmax+1]; +} Stack_alloc; + + +/* + Try to allocate object on stack, and resort to malloc if all + stack memory is used. Ensure allocated objects to be aligned by the pointer + size in order to not break the alignment rules when storing a pointer to a + Bigint. +*/ + +static Bigint *Balloc(int k, Stack_alloc *alloc) +{ + Bigint *rv; + DBUG_ASSERT(k <= Kmax); + if (k <= Kmax && alloc->freelist[k]) + { + rv= alloc->freelist[k]; + alloc->freelist[k]= rv->p.next; + } + else + { + int x, len; + + x= 1 << k; + len= MY_ALIGN(sizeof(Bigint) + x * sizeof(ULong), SIZEOF_CHARP); + + if (alloc->free + len <= alloc->end) + { + rv= (Bigint*) alloc->free; + alloc->free+= len; + } + else + rv= (Bigint*) malloc(len); + + rv->k= k; + rv->maxwds= x; + } + rv->sign= rv->wds= 0; + rv->p.x= (ULong*) (rv + 1); + return rv; +} + + +/* + If object was allocated on stack, try putting it to the free + list. Otherwise call free(). +*/ + +static void Bfree(Bigint *v, Stack_alloc *alloc) +{ + char *gptr= (char*) v; /* generic pointer */ + if (gptr < alloc->begin || gptr >= alloc->end) + free(gptr); + else if (v->k <= Kmax) + { + /* + Maintain free lists only for stack objects: this way we don't + have to bother with freeing lists in the end of dtoa; + heap should not be used normally anyway. + */ + v->p.next= alloc->freelist[v->k]; + alloc->freelist[v->k]= v; + } +} + + +/* + This is to place return value of dtoa in: tries to use stack + as well, but passes by free lists management and just aligns len by + the pointer size in order to not break the alignment rules when storing a + pointer to a Bigint. +*/ + +static char *dtoa_alloc(int i, Stack_alloc *alloc) +{ + char *rv; + int aligned_size= MY_ALIGN(i, SIZEOF_CHARP); + if (alloc->free + aligned_size <= alloc->end) + { + rv= alloc->free; + alloc->free+= aligned_size; + } + else + rv= malloc(i); + return rv; +} + + +/* + dtoa_free() must be used to free values s returned by dtoa() + This is the counterpart of dtoa_alloc() +*/ + +static void dtoa_free(char *gptr, char *buf, size_t buf_size) +{ + if (gptr < buf || gptr >= buf + buf_size) + free(gptr); +} + + +/* Bigint arithmetic functions */ + +/* Multiply by m and add a */ + +static Bigint *multadd(Bigint *b, int m, int a, Stack_alloc *alloc) +{ + int i, wds; + ULong *x; + ULLong carry, y; + Bigint *b1; + + wds= b->wds; + x= b->p.x; + i= 0; + carry= a; + do + { + y= *x * (ULLong)m + carry; + carry= y >> 32; + *x++= (ULong)(y & FFFFFFFF); + } + while (++i < wds); + if (carry) + { + if (wds >= b->maxwds) + { + b1= Balloc(b->k+1, alloc); + Bcopy(b1, b); + Bfree(b, alloc); + b= b1; + } + b->p.x[wds++]= (ULong) carry; + b->wds= wds; + } + return b; +} + + +static int hi0bits(register ULong x) +{ + register int k= 0; + + if (!(x & 0xffff0000)) + { + k= 16; + x<<= 16; + } + if (!(x & 0xff000000)) + { + k+= 8; + x<<= 8; + } + if (!(x & 0xf0000000)) + { + k+= 4; + x<<= 4; + } + if (!(x & 0xc0000000)) + { + k+= 2; + x<<= 2; + } + if (!(x & 0x80000000)) + { + k++; + if (!(x & 0x40000000)) + return 32; + } + return k; +} + + +static int lo0bits(ULong *y) +{ + register int k; + register ULong x= *y; + + if (x & 7) + { + if (x & 1) + return 0; + if (x & 2) + { + *y= x >> 1; + return 1; + } + *y= x >> 2; + return 2; + } + k= 0; + if (!(x & 0xffff)) + { + k= 16; + x>>= 16; + } + if (!(x & 0xff)) + { + k+= 8; + x>>= 8; + } + if (!(x & 0xf)) + { + k+= 4; + x>>= 4; + } + if (!(x & 0x3)) + { + k+= 2; + x>>= 2; + } + if (!(x & 1)) + { + k++; + x>>= 1; + if (!x) + return 32; + } + *y= x; + return k; +} + + +/* Convert integer to Bigint number */ + +static Bigint *i2b(int i, Stack_alloc *alloc) +{ + Bigint *b; + + b= Balloc(1, alloc); + b->p.x[0]= i; + b->wds= 1; + return b; +} + + +/* Multiply two Bigint numbers */ + +static Bigint *mult(Bigint *a, Bigint *b, Stack_alloc *alloc) +{ + Bigint *c; + int k, wa, wb, wc; + ULong *x, *xa, *xae, *xb, *xbe, *xc, *xc0; + ULong y; + ULLong carry, z; + + if (a->wds < b->wds) + { + c= a; + a= b; + b= c; + } + k= a->k; + wa= a->wds; + wb= b->wds; + wc= wa + wb; + if (wc > a->maxwds) + k++; + c= Balloc(k, alloc); + for (x= c->p.x, xa= x + wc; x < xa; x++) + *x= 0; + xa= a->p.x; + xae= xa + wa; + xb= b->p.x; + xbe= xb + wb; + xc0= c->p.x; + for (; xb < xbe; xc0++) + { + if ((y= *xb++)) + { + x= xa; + xc= xc0; + carry= 0; + do + { + z= *x++ * (ULLong)y + *xc + carry; + carry= z >> 32; + *xc++= (ULong) (z & FFFFFFFF); + } + while (x < xae); + *xc= (ULong) carry; + } + } + for (xc0= c->p.x, xc= xc0 + wc; wc > 0 && !*--xc; --wc) ; + c->wds= wc; + return c; +} + + +/* + Precalculated array of powers of 5: tested to be enough for + vasting majority of dtoa_r cases. +*/ + +static ULong powers5[]= +{ + 625UL, + + 390625UL, + + 2264035265UL, 35UL, + + 2242703233UL, 762134875UL, 1262UL, + + 3211403009UL, 1849224548UL, 3668416493UL, 3913284084UL, 1593091UL, + + 781532673UL, 64985353UL, 253049085UL, 594863151UL, 3553621484UL, + 3288652808UL, 3167596762UL, 2788392729UL, 3911132675UL, 590UL, + + 2553183233UL, 3201533787UL, 3638140786UL, 303378311UL, 1809731782UL, + 3477761648UL, 3583367183UL, 649228654UL, 2915460784UL, 487929380UL, + 1011012442UL, 1677677582UL, 3428152256UL, 1710878487UL, 1438394610UL, + 2161952759UL, 4100910556UL, 1608314830UL, 349175UL +}; + + +static Bigint p5_a[]= +{ + /* { x } - k - maxwds - sign - wds */ + { { powers5 }, 1, 1, 0, 1 }, + { { powers5 + 1 }, 1, 1, 0, 1 }, + { { powers5 + 2 }, 1, 2, 0, 2 }, + { { powers5 + 4 }, 2, 3, 0, 3 }, + { { powers5 + 7 }, 3, 5, 0, 5 }, + { { powers5 + 12 }, 4, 10, 0, 10 }, + { { powers5 + 22 }, 5, 19, 0, 19 } +}; + +#define P5A_MAX (sizeof(p5_a)/sizeof(*p5_a) - 1) + +static Bigint *pow5mult(Bigint *b, int k, Stack_alloc *alloc) +{ + Bigint *b1, *p5, *p51=NULL; + int i; + static int p05[3]= { 5, 25, 125 }; + my_bool overflow= FALSE; + + if ((i= k & 3)) + b= multadd(b, p05[i-1], 0, alloc); + + if (!(k>>= 2)) + return b; + p5= p5_a; + for (;;) + { + if (k & 1) + { + b1= mult(b, p5, alloc); + Bfree(b, alloc); + b= b1; + } + if (!(k>>= 1)) + break; + /* Calculate next power of 5 */ + if (overflow) + { + p51= mult(p5, p5, alloc); + Bfree(p5, alloc); + p5= p51; + } + else if (p5 < p5_a + P5A_MAX) + ++p5; + else if (p5 == p5_a + P5A_MAX) + { + p5= mult(p5, p5, alloc); + overflow= TRUE; + } + } + if (p51) + Bfree(p51, alloc); + return b; +} + + +static Bigint *lshift(Bigint *b, int k, Stack_alloc *alloc) +{ + int i, k1, n, n1; + Bigint *b1; + ULong *x, *x1, *xe, z; + + n= k >> 5; + k1= b->k; + n1= n + b->wds + 1; + for (i= b->maxwds; n1 > i; i<<= 1) + k1++; + b1= Balloc(k1, alloc); + x1= b1->p.x; + for (i= 0; i < n; i++) + *x1++= 0; + x= b->p.x; + xe= x + b->wds; + if (k&= 0x1f) + { + k1= 32 - k; + z= 0; + do + { + *x1++= *x << k | z; + z= *x++ >> k1; + } + while (x < xe); + if ((*x1= z)) + ++n1; + } + else + do + *x1++= *x++; + while (x < xe); + b1->wds= n1 - 1; + Bfree(b, alloc); + return b1; +} + + +static int cmp(Bigint *a, Bigint *b) +{ + ULong *xa, *xa0, *xb, *xb0; + int i, j; + + i= a->wds; + j= b->wds; + if (i-= j) + return i; + xa0= a->p.x; + xa= xa0 + j; + xb0= b->p.x; + xb= xb0 + j; + for (;;) + { + if (*--xa != *--xb) + return *xa < *xb ? -1 : 1; + if (xa <= xa0) + break; + } + return 0; +} + + +static Bigint *diff(Bigint *a, Bigint *b, Stack_alloc *alloc) +{ + Bigint *c; + int i, wa, wb; + ULong *xa, *xae, *xb, *xbe, *xc; + ULLong borrow, y; + + i= cmp(a,b); + if (!i) + { + c= Balloc(0, alloc); + c->wds= 1; + c->p.x[0]= 0; + return c; + } + if (i < 0) + { + c= a; + a= b; + b= c; + i= 1; + } + else + i= 0; + c= Balloc(a->k, alloc); + c->sign= i; + wa= a->wds; + xa= a->p.x; + xae= xa + wa; + wb= b->wds; + xb= b->p.x; + xbe= xb + wb; + xc= c->p.x; + borrow= 0; + do + { + y= (ULLong)*xa++ - *xb++ - borrow; + borrow= y >> 32 & (ULong)1; + *xc++= (ULong) (y & FFFFFFFF); + } + while (xb < xbe); + while (xa < xae) + { + y= *xa++ - borrow; + borrow= y >> 32 & (ULong)1; + *xc++= (ULong) (y & FFFFFFFF); + } + while (!*--xc) + wa--; + c->wds= wa; + return c; +} + + +static Bigint *d2b(U *d, int *e, int *bits, Stack_alloc *alloc) +{ + Bigint *b; + int de, k; + ULong *x, y, z; + int i; +#define d0 word0(d) +#define d1 word1(d) + + b= Balloc(1, alloc); + x= b->p.x; + + z= d0 & Frac_mask; + d0 &= 0x7fffffff; /* clear sign bit, which we ignore */ + if ((de= (int)(d0 >> Exp_shift))) + z|= Exp_msk1; + if ((y= d1)) + { + if ((k= lo0bits(&y))) + { + x[0]= y | z << (32 - k); + z>>= (k == 32) ? (--k) : k; + } + else + x[0]= y; + i= b->wds= (x[1]= z) ? 2 : 1; + } + else + { + k= lo0bits(&z); + x[0]= z; + i= b->wds= 1; + k+= 32; + } + if (de) + { + *e= de - Bias - (P-1) + k; + *bits= P - k; + } + else + { + *e= de - Bias - (P-1) + 1 + k; + *bits= 32*i - hi0bits(x[i-1]); + } + return b; +#undef d0 +#undef d1 +} + + +static const double tens[] = +{ + 1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, + 1e10, 1e11, 1e12, 1e13, 1e14, 1e15, 1e16, 1e17, 1e18, 1e19, + 1e20, 1e21, 1e22 +}; + +static const double bigtens[]= { 1e16, 1e32, 1e64, 1e128, 1e256 }; +/* + The factor of 2^53 in tinytens[4] helps us avoid setting the underflow + flag unnecessarily. It leads to a song and dance at the end of strtod. +*/ +#define Scale_Bit 0x10 +#define n_bigtens 5 + + +static int quorem(Bigint *b, Bigint *S) +{ + int n; + ULong *bx, *bxe, q, *sx, *sxe; + ULLong borrow, carry, y, ys; + + n= S->wds; + if (b->wds < n) + return 0; + sx= S->p.x; + sxe= sx + --n; + bx= b->p.x; + bxe= bx + n; + q= *bxe / (*sxe + 1); /* ensure q <= true quotient */ + if (q) + { + borrow= 0; + carry= 0; + do + { + ys= *sx++ * (ULLong)q + carry; + carry= ys >> 32; + y= *bx - (ys & FFFFFFFF) - borrow; + borrow= y >> 32 & (ULong)1; + *bx++= (ULong) (y & FFFFFFFF); + } + while (sx <= sxe); + if (!*bxe) + { + bx= b->p.x; + while (--bxe > bx && !*bxe) + --n; + b->wds= n; + } + } + if (cmp(b, S) >= 0) + { + q++; + borrow= 0; + carry= 0; + bx= b->p.x; + sx= S->p.x; + do + { + ys= *sx++ + carry; + carry= ys >> 32; + y= *bx - (ys & FFFFFFFF) - borrow; + borrow= y >> 32 & (ULong)1; + *bx++= (ULong) (y & FFFFFFFF); + } + while (sx <= sxe); + bx= b->p.x; + bxe= bx + n; + if (!*bxe) + { + while (--bxe > bx && !*bxe) + --n; + b->wds= n; + } + } + return q; +} + + +/* + dtoa for IEEE arithmetic (dmg): convert double to ASCII string. + + Inspired by "How to Print Floating-Point Numbers Accurately" by + Guy L. Steele, Jr. and Jon L. White [Proc. ACM SIGPLAN '90, pp. 112-126]. + + Modifications: + 1. Rather than iterating, we use a simple numeric overestimate + to determine k= floor(log10(d)). We scale relevant + quantities using O(log2(k)) rather than O(k) multiplications. + 2. For some modes > 2 (corresponding to ecvt and fcvt), we don't + try to generate digits strictly left to right. Instead, we + compute with fewer bits and propagate the carry if necessary + when rounding the final digit up. This is often faster. + 3. Under the assumption that input will be rounded nearest, + mode 0 renders 1e23 as 1e23 rather than 9.999999999999999e22. + That is, we allow equality in stopping tests when the + round-nearest rule will give the same floating-point value + as would satisfaction of the stopping test with strict + inequality. + 4. We remove common factors of powers of 2 from relevant + quantities. + 5. When converting floating-point integers less than 1e16, + we use floating-point arithmetic rather than resorting + to multiple-precision integers. + 6. When asked to produce fewer than 15 digits, we first try + to get by with floating-point arithmetic; we resort to + multiple-precision integer arithmetic only if we cannot + guarantee that the floating-point calculation has given + the correctly rounded result. For k requested digits and + "uniformly" distributed input, the probability is + something like 10^(k-15) that we must resort to the Long + calculation. + */ + +static char *dtoa(double dd, int mode, int ndigits, int *decpt, int *sign, + char **rve, char *buf, size_t buf_size) +{ + /* + Arguments ndigits, decpt, sign are similar to those + of ecvt and fcvt; trailing zeros are suppressed from + the returned string. If not null, *rve is set to point + to the end of the return value. If d is +-Infinity or NaN, + then *decpt is set to DTOA_OVERFLOW. + + mode: + 0 ==> shortest string that yields d when read in + and rounded to nearest. + 1 ==> like 0, but with Steele & White stopping rule; + e.g. with IEEE P754 arithmetic , mode 0 gives + 1e23 whereas mode 1 gives 9.999999999999999e22. + 2 ==> MAX(1,ndigits) significant digits. This gives a + return value similar to that of ecvt, except + that trailing zeros are suppressed. + 3 ==> through ndigits past the decimal point. This + gives a return value similar to that from fcvt, + except that trailing zeros are suppressed, and + ndigits can be negative. + 4,5 ==> similar to 2 and 3, respectively, but (in + round-nearest mode) with the tests of mode 0 to + possibly return a shorter string that rounds to d. + With IEEE arithmetic and compilation with + -DHonor_FLT_ROUNDS, modes 4 and 5 behave the same + as modes 2 and 3 when FLT_ROUNDS != 1. + 6-9 ==> Debugging modes similar to mode - 4: don't try + fast floating-point estimate (if applicable). + + Values of mode other than 0-9 are treated as mode 0. + + Sufficient space is allocated to the return value + to hold the suppressed trailing zeros. + */ + + int bbits, b2, b5, be, dig, i, ieps, UNINIT_VAR(ilim), ilim0, + UNINIT_VAR(ilim1), j, j1, k, k0, k_check, leftright, m2, m5, s2, s5, + spec_case, try_quick; + Long L; + int denorm; + ULong x; + Bigint *b, *b1, *delta, *mlo, *mhi, *S; + U d2, eps, u; + double ds; + char *s, *s0; +#ifdef Honor_FLT_ROUNDS + int rounding; +#endif + Stack_alloc alloc; + + alloc.begin= alloc.free= buf; + alloc.end= buf + buf_size; + memset(alloc.freelist, 0, sizeof(alloc.freelist)); + + u.d= dd; + if (word0(&u) & Sign_bit) + { + /* set sign for everything, including 0's and NaNs */ + *sign= 1; + word0(&u) &= ~Sign_bit; /* clear sign bit */ + } + else + *sign= 0; + + /* If infinity, set decpt to DTOA_OVERFLOW, if 0 set it to 1 */ + /* coverity[assign_where_compare_meant] */ + if (((word0(&u) & Exp_mask) == Exp_mask && (*decpt= DTOA_OVERFLOW)) || + /* coverity[assign_where_compare_meant] */ + (!dval(&u) && (*decpt= 1))) + { + /* Infinity, NaN, 0 */ + char *res= (char*) dtoa_alloc(2, &alloc); + res[0]= '0'; + res[1]= '\0'; + if (rve) + *rve= res + 1; + return res; + } + +#ifdef Honor_FLT_ROUNDS + if ((rounding= Flt_Rounds) >= 2) + { + if (*sign) + rounding= rounding == 2 ? 0 : 2; + else + if (rounding != 2) + rounding= 0; + } +#endif + + b= d2b(&u, &be, &bbits, &alloc); + if ((i= (int)(word0(&u) >> Exp_shift1 & (Exp_mask>>Exp_shift1)))) + { + dval(&d2)= dval(&u); + word0(&d2) &= Frac_mask1; + word0(&d2) |= Exp_11; + + /* + log(x) ~=~ log(1.5) + (x-1.5)/1.5 + log10(x) = log(x) / log(10) + ~=~ log(1.5)/log(10) + (x-1.5)/(1.5*log(10)) + log10(d)= (i-Bias)*log(2)/log(10) + log10(d2) + + This suggests computing an approximation k to log10(d) by + + k= (i - Bias)*0.301029995663981 + + ( (d2-1.5)*0.289529654602168 + 0.176091259055681 ); + + We want k to be too large rather than too small. + The error in the first-order Taylor series approximation + is in our favor, so we just round up the constant enough + to compensate for any error in the multiplication of + (i - Bias) by 0.301029995663981; since |i - Bias| <= 1077, + and 1077 * 0.30103 * 2^-52 ~=~ 7.2e-14, + adding 1e-13 to the constant term more than suffices. + Hence we adjust the constant term to 0.1760912590558. + (We could get a more accurate k by invoking log10, + but this is probably not worthwhile.) + */ + + i-= Bias; + denorm= 0; + } + else + { + /* d is denormalized */ + + i= bbits + be + (Bias + (P-1) - 1); + x= i > 32 ? word0(&u) << (64 - i) | word1(&u) >> (i - 32) + : word1(&u) << (32 - i); + dval(&d2)= x; + word0(&d2)-= 31*Exp_msk1; /* adjust exponent */ + i-= (Bias + (P-1) - 1) + 1; + denorm= 1; + } + ds= (dval(&d2)-1.5)*0.289529654602168 + 0.1760912590558 + i*0.301029995663981; + k= (int)ds; + if (ds < 0. && ds != k) + k--; /* want k= floor(ds) */ + k_check= 1; + if (k >= 0 && k <= Ten_pmax) + { + if (dval(&u) < tens[k]) + k--; + k_check= 0; + } + j= bbits - i - 1; + if (j >= 0) + { + b2= 0; + s2= j; + } + else + { + b2= -j; + s2= 0; + } + if (k >= 0) + { + b5= 0; + s5= k; + s2+= k; + } + else + { + b2-= k; + b5= -k; + s5= 0; + } + if (mode < 0 || mode > 9) + mode= 0; + +#ifdef Check_FLT_ROUNDS + try_quick= Rounding == 1; +#else + try_quick= 1; +#endif + + if (mode > 5) + { + mode-= 4; + try_quick= 0; + } + leftright= 1; + switch (mode) { + case 0: + case 1: + ilim= ilim1= -1; + i= 18; + ndigits= 0; + break; + case 2: + leftright= 0; + /* fall through */ + case 4: + if (ndigits <= 0) + ndigits= 1; + ilim= ilim1= i= ndigits; + break; + case 3: + leftright= 0; + /* fall through */ + case 5: + i= ndigits + k + 1; + ilim= i; + ilim1= i - 1; + if (i <= 0) + i= 1; + } + s= s0= dtoa_alloc(i, &alloc); + +#ifdef Honor_FLT_ROUNDS + if (mode > 1 && rounding != 1) + leftright= 0; +#endif + + if (ilim >= 0 && ilim <= Quick_max && try_quick) + { + /* Try to get by with floating-point arithmetic. */ + i= 0; + dval(&d2)= dval(&u); + k0= k; + ilim0= ilim; + ieps= 2; /* conservative */ + if (k > 0) + { + ds= tens[k&0xf]; + j= k >> 4; + if (j & Bletch) + { + /* prevent overflows */ + j&= Bletch - 1; + dval(&u)/= bigtens[n_bigtens-1]; + ieps++; + } + for (; j; j>>= 1, i++) + { + if (j & 1) + { + ieps++; + ds*= bigtens[i]; + } + } + dval(&u)/= ds; + } + else if ((j1= -k)) + { + dval(&u)*= tens[j1 & 0xf]; + for (j= j1 >> 4; j; j>>= 1, i++) + { + if (j & 1) + { + ieps++; + dval(&u)*= bigtens[i]; + } + } + } + if (k_check && dval(&u) < 1. && ilim > 0) + { + if (ilim1 <= 0) + goto fast_failed; + ilim= ilim1; + k--; + dval(&u)*= 10.; + ieps++; + } + dval(&eps)= ieps*dval(&u) + 7.; + word0(&eps)-= (P-1)*Exp_msk1; + if (ilim == 0) + { + S= mhi= 0; + dval(&u)-= 5.; + if (dval(&u) > dval(&eps)) + goto one_digit; + if (dval(&u) < -dval(&eps)) + goto no_digits; + goto fast_failed; + } + if (leftright) + { + /* Use Steele & White method of only generating digits needed. */ + dval(&eps)= 0.5/tens[ilim-1] - dval(&eps); + for (i= 0;;) + { + L= (Long) dval(&u); + dval(&u)-= L; + *s++= '0' + (int)L; + if (dval(&u) < dval(&eps)) + goto ret1; + if (1. - dval(&u) < dval(&eps)) + goto bump_up; + if (++i >= ilim) + break; + dval(&eps)*= 10.; + dval(&u)*= 10.; + } + } + else + { + /* Generate ilim digits, then fix them up. */ + dval(&eps)*= tens[ilim-1]; + for (i= 1;; i++, dval(&u)*= 10.) + { + L= (Long)(dval(&u)); + if (!(dval(&u)-= L)) + ilim= i; + *s++= '0' + (int)L; + if (i == ilim) + { + if (dval(&u) > 0.5 + dval(&eps)) + goto bump_up; + else if (dval(&u) < 0.5 - dval(&eps)) + { + while (*--s == '0'); + s++; + goto ret1; + } + break; + } + } + } + fast_failed: + s= s0; + dval(&u)= dval(&d2); + k= k0; + ilim= ilim0; + } + + /* Do we have a "small" integer? */ + + if (be >= 0 && k <= Int_max) + { + /* Yes. */ + ds= tens[k]; + if (ndigits < 0 && ilim <= 0) + { + S= mhi= 0; + if (ilim < 0 || dval(&u) <= 5*ds) + goto no_digits; + goto one_digit; + } + for (i= 1;; i++, dval(&u)*= 10.) + { + L= (Long)(dval(&u) / ds); + dval(&u)-= L*ds; +#ifdef Check_FLT_ROUNDS + /* If FLT_ROUNDS == 2, L will usually be high by 1 */ + if (dval(&u) < 0) + { + L--; + dval(&u)+= ds; + } +#endif + *s++= '0' + (int)L; + if (!dval(&u)) + { + break; + } + if (i == ilim) + { +#ifdef Honor_FLT_ROUNDS + if (mode > 1) + { + switch (rounding) { + case 0: goto ret1; + case 2: goto bump_up; + } + } +#endif + dval(&u)+= dval(&u); + if (dval(&u) > ds || (dval(&u) == ds && L & 1)) + { +bump_up: + while (*--s == '9') + if (s == s0) + { + k++; + *s= '0'; + break; + } + ++*s++; + } + break; + } + } + goto ret1; + } + + m2= b2; + m5= b5; + mhi= mlo= 0; + if (leftright) + { + i = denorm ? be + (Bias + (P-1) - 1 + 1) : 1 + P - bbits; + b2+= i; + s2+= i; + mhi= i2b(1, &alloc); + } + if (m2 > 0 && s2 > 0) + { + i= m2 < s2 ? m2 : s2; + b2-= i; + m2-= i; + s2-= i; + } + if (b5 > 0) + { + if (leftright) + { + if (m5 > 0) + { + mhi= pow5mult(mhi, m5, &alloc); + b1= mult(mhi, b, &alloc); + Bfree(b, &alloc); + b= b1; + } + if ((j= b5 - m5)) + b= pow5mult(b, j, &alloc); + } + else + b= pow5mult(b, b5, &alloc); + } + S= i2b(1, &alloc); + if (s5 > 0) + S= pow5mult(S, s5, &alloc); + + /* Check for special case that d is a normalized power of 2. */ + + spec_case= 0; + if ((mode < 2 || leftright) +#ifdef Honor_FLT_ROUNDS + && rounding == 1 +#endif + ) + { + if (!word1(&u) && !(word0(&u) & Bndry_mask) && + word0(&u) & (Exp_mask & ~Exp_msk1) + ) + { + /* The special case */ + b2+= Log2P; + s2+= Log2P; + spec_case= 1; + } + } + + /* + Arrange for convenient computation of quotients: + shift left if necessary so divisor has 4 leading 0 bits. + + Perhaps we should just compute leading 28 bits of S once + a nd for all and pass them and a shift to quorem, so it + can do shifts and ors to compute the numerator for q. + */ + if ((i= ((s5 ? 32 - hi0bits(S->p.x[S->wds-1]) : 1) + s2) & 0x1f)) + i= 32 - i; + if (i > 4) + { + i-= 4; + b2+= i; + m2+= i; + s2+= i; + } + else if (i < 4) + { + i+= 28; + b2+= i; + m2+= i; + s2+= i; + } + if (b2 > 0) + b= lshift(b, b2, &alloc); + if (s2 > 0) + S= lshift(S, s2, &alloc); + if (k_check) + { + if (cmp(b,S) < 0) + { + k--; + /* we botched the k estimate */ + b= multadd(b, 10, 0, &alloc); + if (leftright) + mhi= multadd(mhi, 10, 0, &alloc); + ilim= ilim1; + } + } + if (ilim <= 0 && (mode == 3 || mode == 5)) + { + if (ilim < 0 || cmp(b,S= multadd(S,5,0, &alloc)) <= 0) + { + /* no digits, fcvt style */ +no_digits: + k= -1 - ndigits; + goto ret; + } +one_digit: + *s++= '1'; + k++; + goto ret; + } + if (leftright) + { + if (m2 > 0) + mhi= lshift(mhi, m2, &alloc); + + /* + Compute mlo -- check for special case that d is a normalized power of 2. + */ + + mlo= mhi; + if (spec_case) + { + mhi= Balloc(mhi->k, &alloc); + Bcopy(mhi, mlo); + mhi= lshift(mhi, Log2P, &alloc); + } + + for (i= 1;;i++) + { + dig= quorem(b,S) + '0'; + /* Do we yet have the shortest decimal string that will round to d? */ + j= cmp(b, mlo); + delta= diff(S, mhi, &alloc); + j1= delta->sign ? 1 : cmp(b, delta); + Bfree(delta, &alloc); + if (j1 == 0 && mode != 1 && !(word1(&u) & 1) +#ifdef Honor_FLT_ROUNDS + && rounding >= 1 +#endif + ) + { + if (dig == '9') + goto round_9_up; + if (j > 0) + dig++; + *s++= dig; + goto ret; + } + if (j < 0 || (j == 0 && mode != 1 && !(word1(&u) & 1))) + { + if (!b->p.x[0] && b->wds <= 1) + { + goto accept_dig; + } +#ifdef Honor_FLT_ROUNDS + if (mode > 1) + switch (rounding) { + case 0: goto accept_dig; + case 2: goto keep_dig; + } +#endif /*Honor_FLT_ROUNDS*/ + if (j1 > 0) + { + b= lshift(b, 1, &alloc); + j1= cmp(b, S); + if ((j1 > 0 || (j1 == 0 && dig & 1)) + && dig++ == '9') + goto round_9_up; + } +accept_dig: + *s++= dig; + goto ret; + } + if (j1 > 0) + { +#ifdef Honor_FLT_ROUNDS + if (!rounding) + goto accept_dig; +#endif + if (dig == '9') + { /* possible if i == 1 */ +round_9_up: + *s++= '9'; + goto roundoff; + } + *s++= dig + 1; + goto ret; + } +#ifdef Honor_FLT_ROUNDS +keep_dig: +#endif + *s++= dig; + if (i == ilim) + break; + b= multadd(b, 10, 0, &alloc); + if (mlo == mhi) + mlo= mhi= multadd(mhi, 10, 0, &alloc); + else + { + mlo= multadd(mlo, 10, 0, &alloc); + mhi= multadd(mhi, 10, 0, &alloc); + } + } + } + else + for (i= 1;; i++) + { + *s++= dig= quorem(b,S) + '0'; + if (!b->p.x[0] && b->wds <= 1) + { + goto ret; + } + if (i >= ilim) + break; + b= multadd(b, 10, 0, &alloc); + } + + /* Round off last digit */ + +#ifdef Honor_FLT_ROUNDS + switch (rounding) { + case 0: goto trimzeros; + case 2: goto roundoff; + } +#endif + b= lshift(b, 1, &alloc); + j= cmp(b, S); + if (j > 0 || (j == 0 && dig & 1)) + { +roundoff: + while (*--s == '9') + if (s == s0) + { + k++; + *s++= '1'; + goto ret; + } + ++*s++; + } + else + { +#ifdef Honor_FLT_ROUNDS +trimzeros: +#endif + while (*--s == '0'); + s++; + } +ret: + if (S != NULL) + Bfree(S, &alloc); + if (mhi) + { + if (mlo && mlo != mhi) + Bfree(mlo, &alloc); + Bfree(mhi, &alloc); + } +ret1: + Bfree(b, &alloc); + *s= 0; + *decpt= k + 1; + if (rve) + *rve= s; + return s0; +} diff --git a/vendor/MDBC/libmariadb/ma_errmsg.c b/vendor/MDBC/libmariadb/ma_errmsg.c new file mode 100644 index 00000000..ae247890 --- /dev/null +++ b/vendor/MDBC/libmariadb/ma_errmsg.c @@ -0,0 +1,116 @@ +/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + MA 02111-1301, USA */ + +/* Error messages for clients */ +/* error messages for the demon is in share/language/errmsg.sys */ + +#include +#include +#include "errmsg.h" +#include + +const char *SQLSTATE_UNKNOWN= "HY000"; + +const char *client_errors[]= +{ +/* 2000 */ "Unknown error", +/* 2001 */ "Can't create UNIX socket (%d)", +/* 2002 */ "Can't connect to local server through socket '%-.64s' (%d)", +/* 2003 */ "Can't connect to server on '%-.64s' (%d)", +/* 2004 */ "Can't create TCP/IP socket (%d)", +/* 2005 */ "Unknown server host '%-.100s' (%d)", +/* 2006 */ "Server has gone away", +/* 2007 */ "Protocol mismatch. Server Version = %d Client Version = %d", +/* 2008 */ "Client run out of memory", +/* 2009 */ "Wrong host info", +/* 2010 */ "Localhost via UNIX socket", +/* 2011 */ "%-.64s via TCP/IP", +/* 2012 */ "Error in server handshake", +/* 2013 */ "Lost connection to server during query", +/* 2014 */ "Commands out of sync; you can't run this command now", +/* 2015 */ "%-.64s via named pipe", +/* 2016 */ "Can't wait for named pipe to host: %-.64s pipe: %-.32s (%lu)", +/* 2017 */ "Can't open named pipe to host: %-.64s pipe: %-.32s (%lu)", +/* 2018 */ "Can't set state of named pipe to host: %-.64s pipe: %-.32s (%lu)", +/* 2019 */ "Can't initialize character set %-.64s (path: %-.64s)", +/* 2020 */ "Got packet bigger than 'max_allowed_packet'", +/* 2021 */ "", +/* 2022 */ "", +/* 2023 */ "", +/* 2024 */ "", +/* 2025 */ "", +/* 2026 */ "SSL connection error: %-.100s", +/* 2027 */ "Received malformed packet", +/* 2028 */ "", +/* 2029 */ "", +/* 2030 */ "Statement is not prepared", +/* 2031 */ "No data supplied for parameters in prepared statement", +/* 2032 */ "Data truncated", +/* 2033 */ "", +/* 2034 */ "Invalid parameter number", +/* 2035 */ "Invalid buffer type: %d (parameter: %d)", +/* 2036 */ "Buffer type is not supported", +/* 2037 */ "Shared memory: %-.64s", +/* 2038 */ "Shared memory connection failed during %s. (%lu)", +/* 2039 */ "", +/* 2040 */ "", +/* 2041 */ "", +/* 2042 */ "", +/* 2043 */ "", +/* 2044 */ "", +/* 2045 */ "", +/* 2046 */ "", +/* 2047 */ "Wrong or unknown protocol", +/* 2048 */ "", +/* 2049 */ "Connection with old authentication protocol refused.", +/* 2050 */ "", +/* 2051 */ "", +/* 2052 */ "Prepared statement contains no metadata", +/* 2053 */ "", +/* 2054 */ "This feature is not implemented or disabled", +/* 2055 */ "Lost connection to server at '%s', system error: %d", +/* 2056 */ "Server closed statement due to a prior %s function call", +/* 2057 */ "The number of parameters in bound buffers differs from number of columns in resultset", +/* 2059 */ "Can't connect twice. Already connected", +/* 2058 */ "Plugin %s could not be loaded: %s", +/* 2059 */ "An attribute with same name already exists", +/* 2060 */ "Plugin doesn't support this function", + "" +}; + +const char *mariadb_client_errors[] = +{ + /* 5000 */ "Creating an event failed (Errorcode: %d)", + /* 5001 */ "Bind to local interface '-.%64s' failed (Errorcode: %d)", + /* 5002 */ "Connection type doesn't support asynchronous IO operations", + /* 5003 */ "Server doesn't support function '%s'", + /* 5004 */ "File '%s' not found (Errcode: %d)", + /* 5005 */ "Error reading file '%s' (Errcode: %d)", + /* 5006 */ "Bulk operation without parameters is not supported", + /* 5007 */ "Invalid statement handle", + /* 5008 */ "Unsupported version %d. Supported versions are in the range %d - %d", + "" +}; + +const char ** NEAR my_errmsg[MAXMAPS]={0,0,0,0}; +char NEAR errbuff[NRERRBUFFS][ERRMSGSIZE]; + +void init_client_errs(void) +{ + my_errmsg[CLIENT_ERRMAP] = &client_errors[0]; +} + diff --git a/vendor/MDBC/libmariadb/ma_hashtbl.c b/vendor/MDBC/libmariadb/ma_hashtbl.c new file mode 100644 index 00000000..4805dee0 --- /dev/null +++ b/vendor/MDBC/libmariadb/ma_hashtbl.c @@ -0,0 +1,580 @@ +/************************************************************************************ + Copyright (C) 2000, 2012 MySQL AB & MySQL Finland AB & TCX DataKonsult AB, + Monty Program AB, 2016 MariaDB Corporation AB + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not see + or write to the Free Software Foundation, Inc., + 51 Franklin St., Fifth Floor, Boston, MA 02110, USA + + Part of this code includes code from the PHP project which + is freely available from http://www.php.net +*************************************************************************************/ + +/* The hash functions used for saving keys */ +/* One of key_length or key_length_offset must be given */ +/* Key length of 0 isn't allowed */ + +#include +#include +#include +#include +#include "ma_hashtbl.h" + +#define NO_RECORD ((uint) -1) +#define LOWFIND 1 +#define LOWUSED 2 +#define HIGHFIND 4 +#define HIGHUSED 8 + +static uint hash_mask(uint hashnr,uint buffmax,uint maxlength); +static void movelink(MA_HASHTBL_LINK *array,uint pos,uint next_link,uint newlink); +static uint calc_hashnr(const uchar *key,uint length); +static uint calc_hashnr_caseup(const uchar *key,uint length); +static int hashcmp(MA_HASHTBL *hash,MA_HASHTBL_LINK *pos,const uchar *key,uint length); + + +my_bool _ma_hashtbl_init(MA_HASHTBL *hash,uint size,uint key_offset,uint key_length, + hash_get_key get_key, + void (*free_element)(void*),uint flags CALLER_INFO_PROTO) +{ + hash->records=0; + if (ma_init_dynamic_array_ci(&hash->array,sizeof(MA_HASHTBL_LINK),size,0)) + { + hash->free=0; /* Allow call to hash_free */ + return(TRUE); + } + hash->key_offset=key_offset; + hash->key_length=key_length; + hash->blength=1; + hash->current_record= NO_RECORD; /* For the future */ + hash->get_key=get_key; + hash->free=free_element; + hash->flags=flags; + if (flags & MA_HASHTBL_CASE_INSENSITIVE) + hash->calc_hashnr=calc_hashnr_caseup; + else + hash->calc_hashnr=calc_hashnr; + return(0); +} + + +void ma_hashtbl_free(MA_HASHTBL *hash) +{ + if (hash->free) + { + uint i,records; + MA_HASHTBL_LINK *data=dynamic_element(&hash->array,0,MA_HASHTBL_LINK*); + for (i=0,records=hash->records ; i < records ; i++) + (*hash->free)(data[i].data); + hash->free=0; + } + ma_delete_dynamic(&hash->array); + hash->records=0; + return; +} + + /* some helper functions */ + +/* + This function is char* instead of uchar* as HPUX11 compiler can't + handle inline functions that are not defined as native types +*/ + +static inline char* +hash_key(MA_HASHTBL *hash,const uchar *record,uint *length,my_bool first) +{ + if (hash->get_key) + return (char *)(*hash->get_key)(record,(uint *)length,first); + *length=hash->key_length; + return (char*) record+hash->key_offset; +} + + /* Calculate pos according to keys */ + +static uint hash_mask(uint hashnr,uint buffmax,uint maxlength) +{ + if ((hashnr & (buffmax-1)) < maxlength) return (hashnr & (buffmax-1)); + return (hashnr & ((buffmax >> 1) -1)); +} + +static uint hash_rec_mask(MA_HASHTBL *hash,MA_HASHTBL_LINK *pos,uint buffmax, + uint maxlength) +{ + uint length; + uchar *key= (uchar*) hash_key(hash,pos->data,&length,0); + return hash_mask((*hash->calc_hashnr)(key,length),buffmax,maxlength); +} + +#ifndef NEW_MA_HASHTBL_FUNCTION + + /* Calc hashvalue for a key */ + +static uint calc_hashnr(const uchar *key,uint length) +{ + register uint nr=1, nr2=4; + while (length--) + { + nr^= (((nr & 63)+nr2)*((uint) (uchar) *key++))+ (nr << 8); + nr2+=3; + } + return((uint) nr); +} + + /* Calc hashvalue for a key, case independently */ + +static uint calc_hashnr_caseup(const uchar *key,uint length) +{ + register uint nr=1, nr2=4; + while (length--) + { + nr^= (((nr & 63)+nr2)*((uint) (uchar) toupper(*key++)))+ (nr << 8); + nr2+=3; + } + return((uint) nr); +} + +#else + +/* + * Fowler/Noll/Vo hash + * + * The basis of the hash algorithm was taken from an idea sent by email to the + * IEEE Posix P1003.2 mailing list from Phong Vo (kpv@research.att.com) and + * Glenn Fowler (gsf@research.att.com). Landon Curt Noll (chongo@toad.com) + * later improved on their algorithm. + * + * The magic is in the interesting relationship between the special prime + * 16777619 (2^24 + 403) and 2^32 and 2^8. + * + * This hash produces the fewest collisions of any function that we've seen so + * far, and works well on both numbers and strings. + */ + +uint calc_hashnr(const uchar *key, uint len) +{ + const uchar *end=key+len; + uint hash; + for (hash = 0; key < end; key++) + { + hash *= 16777619; + hash ^= (uint) *(uchar*) key; + } + return (hash); +} + +uint calc_hashnr_caseup(const uchar *key, uint len) +{ + const uchar *end=key+len; + uint hash; + for (hash = 0; key < end; key++) + { + hash *= 16777619; + hash ^= (uint) (uchar) toupper(*key); + } + return (hash); +} + +#endif + + +#ifndef __SUNPRO_C /* SUNPRO can't handle this */ +static inline +#endif +unsigned int rec_hashnr(MA_HASHTBL *hash,const uchar *record) +{ + uint length; + uchar *key= (uchar*) hash_key(hash,record,&length,0); + return (*hash->calc_hashnr)(key,length); +} + + + /* Search after a record based on a key */ + /* Sets info->current_ptr to found record */ + +void* ma_hashtbl_search(MA_HASHTBL *hash,const uchar *key,uint length) +{ + MA_HASHTBL_LINK *pos; + uint flag,idx; + + flag=1; + if (hash->records) + { + idx=hash_mask((*hash->calc_hashnr)(key,length ? length : + hash->key_length), + hash->blength,hash->records); + do + { + pos= dynamic_element(&hash->array,idx,MA_HASHTBL_LINK*); + if (!hashcmp(hash,pos,key,length)) + { + hash->current_record= idx; + return (pos->data); + } + if (flag) + { + flag=0; /* Reset flag */ + if (hash_rec_mask(hash,pos,hash->blength,hash->records) != idx) + break; /* Wrong link */ + } + } + while ((idx=pos->next) != NO_RECORD); + } + hash->current_record= NO_RECORD; + return(0); +} + + /* Get next record with identical key */ + /* Can only be called if previous calls was hash_search */ + +void *ma_hashtbl_next(MA_HASHTBL *hash,const uchar *key,uint length) +{ + MA_HASHTBL_LINK *pos; + uint idx; + + if (hash->current_record != NO_RECORD) + { + MA_HASHTBL_LINK *data=dynamic_element(&hash->array,0,MA_HASHTBL_LINK*); + for (idx=data[hash->current_record].next; idx != NO_RECORD ; idx=pos->next) + { + pos=data+idx; + if (!hashcmp(hash,pos,key,length)) + { + hash->current_record= idx; + return pos->data; + } + } + hash->current_record=NO_RECORD; + } + return 0; +} + + + /* Change link from pos to new_link */ + +static void movelink(MA_HASHTBL_LINK *array,uint find,uint next_link,uint newlink) +{ + MA_HASHTBL_LINK *old_link; + do + { + old_link=array+next_link; + } + while ((next_link=old_link->next) != find); + old_link->next= newlink; + return; +} + + /* Compare a key in a record to a whole key. Return 0 if identical */ + +static int hashcmp(MA_HASHTBL *hash,MA_HASHTBL_LINK *pos,const uchar *key,uint length) +{ + uint rec_keylength; + uchar *rec_key= (uchar*) hash_key(hash,pos->data,&rec_keylength,1); + return (length && length != rec_keylength) || + memcmp(rec_key,key,rec_keylength); +} + + + /* Write a hash-key to the hash-index */ + +my_bool ma_hashtbl_insert(MA_HASHTBL *info,const uchar *record) +{ + int flag; + uint halfbuff,hash_nr,first_index,idx; + uchar *ptr_to_rec= NULL,*ptr_to_rec2= NULL; + MA_HASHTBL_LINK *data,*empty,*gpos= NULL,*gpos2 = NULL,*pos; + + LINT_INIT(gpos); LINT_INIT(gpos2); + LINT_INIT(ptr_to_rec); LINT_INIT(ptr_to_rec2); + + flag=0; + if (!(empty=(MA_HASHTBL_LINK*) ma_alloc_dynamic(&info->array))) + return(TRUE); /* No more memory */ + + info->current_record= NO_RECORD; + data=dynamic_element(&info->array,0,MA_HASHTBL_LINK*); + halfbuff= info->blength >> 1; + + idx=first_index=info->records-halfbuff; + if (idx != info->records) /* If some records */ + { + do + { + pos=data+idx; + hash_nr=rec_hashnr(info,pos->data); + if (flag == 0) /* First loop; Check if ok */ + if (hash_mask(hash_nr,info->blength,info->records) != first_index) + break; + if (!(hash_nr & halfbuff)) + { /* Key will not move */ + if (!(flag & LOWFIND)) + { + if (flag & HIGHFIND) + { + flag=LOWFIND | HIGHFIND; + /* key shall be moved to the current empty position */ + gpos=empty; + ptr_to_rec=pos->data; + empty=pos; /* This place is now free */ + } + else + { + flag=LOWFIND | LOWUSED; /* key isn't changed */ + gpos=pos; + ptr_to_rec=pos->data; + } + } + else + { + if (!(flag & LOWUSED)) + { + /* Change link of previous LOW-key */ + gpos->data=ptr_to_rec; + gpos->next=(uint) (pos-data); + flag= (flag & HIGHFIND) | (LOWFIND | LOWUSED); + } + gpos=pos; + ptr_to_rec=pos->data; + } + } + else + { /* key will be moved */ + if (!(flag & HIGHFIND)) + { + flag= (flag & LOWFIND) | HIGHFIND; + /* key shall be moved to the last (empty) position */ + gpos2 = empty; empty=pos; + ptr_to_rec2=pos->data; + } + else + { + if (!(flag & HIGHUSED)) + { + /* Change link of previous hash-key and save */ + gpos2->data=ptr_to_rec2; + gpos2->next=(uint) (pos-data); + flag= (flag & LOWFIND) | (HIGHFIND | HIGHUSED); + } + gpos2=pos; + ptr_to_rec2=pos->data; + } + } + } + while ((idx=pos->next) != NO_RECORD); + + if ((flag & (LOWFIND | LOWUSED)) == LOWFIND) + { + gpos->data=ptr_to_rec; + gpos->next=NO_RECORD; + } + if ((flag & (HIGHFIND | HIGHUSED)) == HIGHFIND) + { + gpos2->data=ptr_to_rec2; + gpos2->next=NO_RECORD; + } + } + /* Check if we are at the empty position */ + + idx=hash_mask(rec_hashnr(info,record),info->blength,info->records+1); + pos=data+idx; + if (pos == empty) + { + pos->data=(uchar*) record; + pos->next=NO_RECORD; + } + else + { + /* Check if more records in same hash-nr family */ + empty[0]=pos[0]; + gpos=data+hash_rec_mask(info,pos,info->blength,info->records+1); + if (pos == gpos) + { + pos->data=(uchar*) record; + pos->next=(uint) (empty - data); + } + else + { + pos->data=(uchar*) record; + pos->next=NO_RECORD; + movelink(data,(uint) (pos-data),(uint) (gpos-data),(uint) (empty-data)); + } + } + if (++info->records == info->blength) + info->blength+= info->blength; + return(0); +} + + +/****************************************************************************** +** Remove one record from hash-table. The record with the same record +** ptr is removed. +** if there is a free-function it's called for record if found +******************************************************************************/ + +my_bool ma_hashtbl_delete(MA_HASHTBL *hash,uchar *record) +{ + uint blength,pos2,pos_hashnr,lastpos_hashnr,idx,empty_index; + MA_HASHTBL_LINK *data,*lastpos,*gpos,*pos,*pos3,*empty; + if (!hash->records) + return(1); + + blength=hash->blength; + data=dynamic_element(&hash->array,0,MA_HASHTBL_LINK*); + /* Search after record with key */ + pos=data+ hash_mask(rec_hashnr(hash,record),blength,hash->records); + gpos = 0; + + while (pos->data != record) + { + gpos=pos; + if (pos->next == NO_RECORD) + return(1); /* Key not found */ + pos=data+pos->next; + } + + if ( --(hash->records) < hash->blength >> 1) hash->blength>>=1; + hash->current_record= NO_RECORD; + lastpos=data+hash->records; + + /* Remove link to record */ + empty=pos; empty_index=(uint) (empty-data); + if (gpos) + gpos->next=pos->next; /* unlink current ptr */ + else if (pos->next != NO_RECORD) + { + empty=data+(empty_index=pos->next); + pos->data=empty->data; + pos->next=empty->next; + } + + if (empty == lastpos) /* last key at wrong pos or no next link */ + goto exit; + + /* Move the last key (lastpos) */ + lastpos_hashnr=rec_hashnr(hash,lastpos->data); + /* pos is where lastpos should be */ + pos=data+hash_mask(lastpos_hashnr,hash->blength,hash->records); + if (pos == empty) /* Move to empty position. */ + { + empty[0]=lastpos[0]; + goto exit; + } + pos_hashnr=rec_hashnr(hash,pos->data); + /* pos3 is where the pos should be */ + pos3= data+hash_mask(pos_hashnr,hash->blength,hash->records); + if (pos != pos3) + { /* pos is on wrong posit */ + empty[0]=pos[0]; /* Save it here */ + pos[0]=lastpos[0]; /* This should be here */ + movelink(data,(uint) (pos-data),(uint) (pos3-data),empty_index); + goto exit; + } + pos2= hash_mask(lastpos_hashnr,blength,hash->records+1); + if (pos2 == hash_mask(pos_hashnr,blength,hash->records+1)) + { /* Identical key-positions */ + if (pos2 != hash->records) + { + empty[0]=lastpos[0]; + movelink(data,(uint) (lastpos-data),(uint) (pos-data),empty_index); + goto exit; + } + idx= (uint) (pos-data); /* Link pos->next after lastpos */ + } + else idx= NO_RECORD; /* Different positions merge */ + + empty[0]=lastpos[0]; + movelink(data,idx,empty_index,pos->next); + pos->next=empty_index; + +exit: + ma_pop_dynamic(&hash->array); + if (hash->free) + (*hash->free)((uchar*) record); + return(0); +} + + /* + Update keys when record has changed. + This is much more efficient than using a delete & insert. + */ + +my_bool ma_hashtbl_update(MA_HASHTBL *hash,uchar *record,uchar *old_key,uint old_key_length) +{ + uint idx,new_index,new_pos_index,blength,records,empty; + MA_HASHTBL_LINK org_link,*data,*previous,*pos; + + data=dynamic_element(&hash->array,0,MA_HASHTBL_LINK*); + blength=hash->blength; records=hash->records; + + /* Search after record with key */ + + idx=hash_mask((*hash->calc_hashnr)(old_key,(old_key_length ? + old_key_length : + hash->key_length)), + blength,records); + new_index=hash_mask(rec_hashnr(hash,record),blength,records); + if (idx == new_index) + return(0); /* Nothing to do (No record check) */ + previous=0; + for (;;) + { + + if ((pos= data+idx)->data == record) + break; + previous=pos; + if ((idx=pos->next) == NO_RECORD) + return(1); /* Not found in links */ + } + hash->current_record= NO_RECORD; + org_link= *pos; + empty=idx; + + /* Relink record from current chain */ + + if (!previous) + { + if (pos->next != NO_RECORD) + { + empty=pos->next; + *pos= data[pos->next]; + } + } + else + previous->next=pos->next; /* unlink pos */ + + /* Move data to correct position */ + pos=data+new_index; + new_pos_index=hash_rec_mask(hash,pos,blength,records); + if (new_index != new_pos_index) + { /* Other record in wrong position */ + data[empty] = *pos; + movelink(data,new_index,new_pos_index,empty); + org_link.next=NO_RECORD; + data[new_index]= org_link; + } + else + { /* Link in chain at right position */ + org_link.next=data[new_index].next; + data[empty]=org_link; + data[new_index].next=empty; + } + return(0); +} + + +uchar *ma_hashtbl_element(MA_HASHTBL *hash,uint idx) +{ + if (idx < hash->records) + return dynamic_element(&hash->array,idx,MA_HASHTBL_LINK*)->data; + return 0; +} diff --git a/vendor/MDBC/libmariadb/ma_init.c b/vendor/MDBC/libmariadb/ma_init.c new file mode 100644 index 00000000..008aec54 --- /dev/null +++ b/vendor/MDBC/libmariadb/ma_init.c @@ -0,0 +1,87 @@ +/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB + 2016 MariaDB Corporation AB + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + MA 02111-1301, USA */ + +#include +#include +#include "mariadb_ctype.h" +#include +#include +#include +#ifdef _WIN32 +#ifdef _MSC_VER +#include +#include +#endif +static my_bool my_win_init(void); +#else +#define my_win_init() +#endif + +my_bool ma_init_done=0; + + + +/* Init ma_sys functions and ma_sys variabels */ + +void ma_init(void) +{ + if (ma_init_done) + return; + ma_init_done=1; + { +#ifdef _WIN32 + my_win_init(); +#endif + return; + } +} /* ma_init */ + + + +void ma_end(int infoflag __attribute__((unused))) +{ +#ifdef _WIN32 + WSACleanup( ); +#endif /* _WIN32 */ + ma_init_done=0; +} /* ma_end */ + +#ifdef _WIN32 +static my_bool my_win_init() +{ + WORD VersionRequested; + int err; + WSADATA WsaData; + const unsigned int MajorVersion=2, + MinorVersion=2; + VersionRequested= MAKEWORD(MajorVersion, MinorVersion); + /* Load WinSock library */ + if ((err= WSAStartup(VersionRequested, &WsaData))) + { + return 0; + } + /* make sure 2.2 or higher is supported */ + if ((LOBYTE(WsaData.wVersion) * 10 + HIBYTE(WsaData.wVersion)) < 22) + { + WSACleanup(); + return 1; + } + return 0; +} +#endif + diff --git a/vendor/MDBC/libmariadb/ma_io.c b/vendor/MDBC/libmariadb/ma_io.c new file mode 100644 index 00000000..178ffe9f --- /dev/null +++ b/vendor/MDBC/libmariadb/ma_io.c @@ -0,0 +1,224 @@ +/* + Copyright (C) 2015 MariaDB Corporation AB + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + MA 02111-1301, USA +*/ + +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef HAVE_REMOTEIO +struct st_mysql_client_plugin_REMOTEIO *rio_plugin= NULL; +#endif + +/* {{{ ma_open */ +MA_FILE *ma_open(const char *location, const char *mode, MYSQL *mysql) +{ + int CodePage= -1; + FILE *fp= NULL; + MA_FILE *ma_file= NULL; + + if (!location || !location[0]) + return NULL; +#ifdef HAVE_REMOTEIO + if (strstr(location, "://")) + goto remote; +#endif + +#ifdef _WIN32 + if (mysql && mysql->charset) + CodePage= madb_get_windows_cp(mysql->charset->csname); +#endif + if (CodePage == -1) + { + if (!(fp= fopen(location, mode))) + { + return NULL; + } + } +#ifdef _WIN32 + /* See CONC-44: we need to support non ascii filenames too, so we convert + current character set to wchar_t and try to open the file via _wsopen */ + else + { + wchar_t *w_filename= NULL; + wchar_t *w_mode= NULL; + int len; + DWORD Length; + + len= MultiByteToWideChar(CodePage, 0, location, (int)strlen(location), NULL, 0); + if (!len) + return NULL; + if (!(w_filename= (wchar_t *)calloc(1, (len + 1) * sizeof(wchar_t)))) + { + my_set_error(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); + return NULL; + } + Length= len; + len= MultiByteToWideChar(CodePage, 0, location, (int)strlen(location), w_filename, (int)Length); + if (!len) + { + /* todo: error handling */ + free(w_filename); + return NULL; + } + len= (int)strlen(mode); + if (!(w_mode= (wchar_t *)calloc(1, (len + 1) * sizeof(wchar_t)))) + { + my_set_error(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); + free(w_filename); + return NULL; + } + Length= len; + len= MultiByteToWideChar(CodePage, 0, mode, (int)strlen(mode), w_mode, (int)Length); + if (!len) + { + /* todo: error handling */ + free(w_filename); + free(w_mode); + return NULL; + } + fp= _wfopen(w_filename, w_mode); + free(w_filename); + free(w_mode); + } + +#endif + if (fp) + { + ma_file= (MA_FILE *)malloc(sizeof(MA_FILE)); + if (!ma_file) + { + fclose(fp); + my_set_error(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); + return NULL; + } + ma_file->type= MA_FILE_LOCAL; + ma_file->ptr= (void *)fp; + } + return ma_file; +#ifdef HAVE_REMOTEIO +remote: + /* check if plugin for remote io is available and try + * to open location */ + { + MYSQL mysql; + if (rio_plugin ||(rio_plugin= (struct st_mysql_client_plugin_REMOTEIO *) + mysql_client_find_plugin(&mysql, NULL, MARIADB_CLIENT_REMOTEIO_PLUGIN))) + return rio_plugin->methods->mopen(location, mode); + return NULL; + } +#endif +} +/* }}} */ + +/* {{{ ma_close */ +int ma_close(MA_FILE *file) +{ + int rc; + if (!file) + return -1; + + switch (file->type) { + case MA_FILE_LOCAL: + rc= fclose((FILE *)file->ptr); + free(file); + break; +#ifdef HAVE_REMOTEIO + case MA_FILE_REMOTE: + rc= rio_plugin->methods->mclose(file); + break; +#endif + default: + return -1; + } + return rc; +} +/* }}} */ + + +/* {{{ ma_feof */ +int ma_feof(MA_FILE *file) +{ + if (!file) + return -1; + + switch (file->type) { + case MA_FILE_LOCAL: + return feof((FILE *)file->ptr); + break; +#ifdef HAVE_REMOTEIO + case MA_FILE_REMOTE: + return rio_plugin->methods->mfeof(file); + break; +#endif + default: + return -1; + } +} +/* }}} */ + +/* {{{ ma_read */ +size_t ma_read(void *ptr, size_t size, size_t nmemb, MA_FILE *file) +{ + size_t s= 0; + if (!file) + return -1; + + switch (file->type) { + case MA_FILE_LOCAL: + s= fread(ptr, size, nmemb, (FILE *)file->ptr); + return s; + break; +#ifdef HAVE_REMOTEIO + case MA_FILE_REMOTE: + return rio_plugin->methods->mread(ptr, size, nmemb, file); + break; +#endif + default: + return -1; + } +} +/* }}} */ + +/* {{{ ma_gets */ +char *ma_gets(char *ptr, size_t size, MA_FILE *file) +{ + if (!file) + return NULL; + + switch (file->type) { + case MA_FILE_LOCAL: + return fgets(ptr, (int)size, (FILE *)file->ptr); + break; +#ifdef HAVE_REMOTEIO + case MA_FILE_REMOTE: + return rio_plugin->methods->mgets(ptr, size, file); + break; +#endif + default: + return NULL; + } +} +/* }}} */ + + diff --git a/vendor/MDBC/libmariadb/ma_list.c b/vendor/MDBC/libmariadb/ma_list.c new file mode 100644 index 00000000..63c526f1 --- /dev/null +++ b/vendor/MDBC/libmariadb/ma_list.c @@ -0,0 +1,114 @@ +/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB + 2016 MariaDB Corporation AB + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + MA 02111-1301, USA */ + +/* + Code for handling dubble-linked lists in C +*/ + +#include +#include +#include + + /* Add a element to start of list */ + +LIST *list_add(LIST *root, LIST *element) +{ + if (root) + { + if (root->prev) /* If add in mid of list */ + root->prev->next= element; + element->prev=root->prev; + root->prev=element; + } + else + element->prev=0; + element->next=root; + return(element); /* New root */ +} + + +LIST *list_delete(LIST *root, LIST *element) +{ + if (element->prev) + element->prev->next=element->next; + else + root=element->next; + if (element->next) + element->next->prev=element->prev; + return root; +} + + +void list_free(LIST *root, unsigned int free_data) +{ + LIST *next; + while (root) + { + next=root->next; + if (free_data) + free(root->data); + free(root); + root=next; + } +} + + +LIST *list_cons(void *data, LIST *list) +{ + LIST *new_charset=(LIST*) malloc(sizeof(LIST)); + if (!new_charset) + return 0; + new_charset->data=data; + return list_add(list,new_charset); +} + + +LIST *list_reverse(LIST *root) +{ + LIST *last; + + last=root; + while (root) + { + last=root; + root=root->next; + last->next=last->prev; + last->prev=root; + } + return last; +} + +uint list_length(LIST *list) +{ + uint count; + for (count=0 ; list ; list=list->next, count++) ; + return count; +} + + +int list_walk(LIST *list, list_walk_action action, gptr argument) +{ + int error=0; + while (list) + { + if ((error = (*action)(list->data,argument))) + return error; + list= list_rest(list); + } + return 0; +} diff --git a/vendor/MDBC/libmariadb/ma_ll2str.c b/vendor/MDBC/libmariadb/ma_ll2str.c new file mode 100644 index 00000000..6938d37f --- /dev/null +++ b/vendor/MDBC/libmariadb/ma_ll2str.c @@ -0,0 +1,70 @@ +/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB + 2016,2018 MariaDB Corporation AB + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + MA 02111-1301, USA */ + +#include +#include "ma_string.h" +#include + +static char NEAR _dig_vec[] = + "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + +char *ma_ll2str(long long val,char *dst,int radix) +{ + char buffer[65]; + register char *p; + long long_val; + + if (radix < 0) + { + if (radix < -36 || radix > -2) return (char*) 0; + if (val < 0) { + *dst++ = '-'; + val = 0ULL - val; + } + radix = -radix; + } + else + { + if (radix > 36 || radix < 2) return (char*) 0; + } + if (val == 0) + { + *dst++='0'; + *dst='\0'; + return dst; + } + p = &buffer[sizeof(buffer)-1]; + *p = '\0'; + + while ((ulonglong) val > (ulonglong) LONG_MAX) + { + ulonglong quo=(ulonglong) val/(uint) radix; + uint rem= (uint) (val- quo* (uint) radix); + *--p = _dig_vec[rem]; + val= quo; + } + long_val= (long) val; + while (long_val != 0) + { + long quo= long_val/radix; + *--p = _dig_vec[(uchar) (long_val - quo*radix)]; + long_val= quo; + } + while ((*dst++ = *p++) != 0) ; + return dst-1; +} diff --git a/vendor/MDBC/libmariadb/ma_loaddata.c b/vendor/MDBC/libmariadb/ma_loaddata.c new file mode 100644 index 00000000..c59285ec --- /dev/null +++ b/vendor/MDBC/libmariadb/ma_loaddata.c @@ -0,0 +1,265 @@ +/************************************************************************************ + Copyright (C) 2000, 2011 MySQL AB & MySQL Finland AB & TCX DataKonsult AB, + Monty Program AB + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not see + or write to the Free Software Foundation, Inc., + 51 Franklin St., Fifth Floor, Boston, MA 02110, USA + + Part of this code includes code from the PHP project which + is freely available from http://www.php.net +*************************************************************************************/ +/* + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | Copyright (c) 2006-2011 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Authors: Georg Richter | + | Andrey Hristov | + | Ulf Wendel | + +----------------------------------------------------------------------+ +*/ + +#include "ma_global.h" +#include +#include +#include "errmsg.h" +#include "mysql.h" +#include +#include +#ifdef _WIN32 +#include +#endif +#include + +typedef struct st_mysql_infile_info +{ + MA_FILE *fp; + int error_no; + char error_msg[MYSQL_ERRMSG_SIZE + 1]; + const char *filename; +} MYSQL_INFILE_INFO; + +/* {{{ mysql_local_infile_init */ +static +int mysql_local_infile_init(void **ptr, const char *filename, void *userdata) +{ + MYSQL_INFILE_INFO *info; + MYSQL *mysql= (MYSQL *)userdata; + + info = (MYSQL_INFILE_INFO *)malloc(sizeof(MYSQL_INFILE_INFO)); + if (!info) { + return(1); + } + memset(info, 0, sizeof(MYSQL_INFILE_INFO)); + *ptr = info; + + info->filename = filename; + + info->fp= ma_open(filename, "rb", mysql); + + if (!info->fp) + { + /* error handling is done via mysql_local_infile_error function, so we + need to copy error to info */ + if (mysql_errno(mysql) && !info->error_no) + { + info->error_no= mysql_errno(mysql); + ma_strmake(info->error_msg, mysql_error(mysql), MYSQL_ERRMSG_SIZE); + } + else + { + info->error_no = errno; + snprintf((char *)info->error_msg, sizeof(info->error_msg), + CER(CR_FILE_NOT_FOUND), filename, info->error_no); + } + return(1); + } + + return(0); +} +/* }}} */ + + +/* {{{ mysql_local_infile_read */ +static +int mysql_local_infile_read(void *ptr, char * buf, unsigned int buf_len) +{ + MYSQL_INFILE_INFO *info = (MYSQL_INFILE_INFO *)ptr; + size_t count; + + count= ma_read((void *)buf, 1, (size_t)buf_len, info->fp); + + if (count == (size_t)-1) + { + info->error_no = errno; + snprintf((char *)info->error_msg, sizeof(info->error_msg), + CER(CR_FILE_READ), info->filename, info->error_no); + } + return((int)count); +} +/* }}} */ + + +/* {{{ mysql_local_infile_error */ +static +int mysql_local_infile_error(void *ptr, char *error_buf, unsigned int error_buf_len) +{ + MYSQL_INFILE_INFO *info = (MYSQL_INFILE_INFO *)ptr; + + if (info) { + ma_strmake(error_buf, info->error_msg, error_buf_len); + return(info->error_no); + } + + ma_strmake(error_buf, "Unknown error", error_buf_len); + return(CR_UNKNOWN_ERROR); +} +/* }}} */ + + +/* {{{ mysql_local_infile_end */ +static +void mysql_local_infile_end(void *ptr) +{ + MYSQL_INFILE_INFO *info = (MYSQL_INFILE_INFO *)ptr; + + if (info) + { + if (info->fp) + ma_close(info->fp); + free(ptr); + } + return; +} +/* }}} */ + + +/* {{{ mysql_local_infile_default */ +void mysql_set_local_infile_default(MYSQL *conn) +{ + conn->options.local_infile_init = mysql_local_infile_init; + conn->options.local_infile_read = mysql_local_infile_read; + conn->options.local_infile_error = mysql_local_infile_error; + conn->options.local_infile_end = mysql_local_infile_end; + return; +} +/* }}} */ + +/* {{{ mysql_set_local_infile_handler */ +void STDCALL mysql_set_local_infile_handler(MYSQL *conn, + int (*local_infile_init)(void **, const char *, void *), + int (*local_infile_read)(void *, char *, uint), + void (*local_infile_end)(void *), + int (*local_infile_error)(void *, char *, uint), + void *userdata) +{ + conn->options.local_infile_init= local_infile_init; + conn->options.local_infile_read= local_infile_read; + conn->options.local_infile_end= local_infile_end; + conn->options.local_infile_error= local_infile_error; + conn->options.local_infile_userdata = userdata; + return; +} +/* }}} */ + +/* {{{ mysql_handle_local_infile */ +my_bool mysql_handle_local_infile(MYSQL *conn, const char *filename, my_bool can_local_infile) +{ + unsigned int buflen= 4096; + int bufread; + unsigned char *buf= NULL; + void *info= NULL; + my_bool result= 1; + + /* check if all callback functions exist */ + if (!conn->options.local_infile_init || !conn->options.local_infile_end || + !conn->options.local_infile_read || !conn->options.local_infile_error) + { + conn->options.local_infile_userdata= conn; + mysql_set_local_infile_default(conn); + } + + if (!(conn->options.client_flag & CLIENT_LOCAL_FILES) || + !can_local_infile) + { + my_set_error(conn, CR_UNKNOWN_ERROR, SQLSTATE_UNKNOWN, "Load data local infile forbidden"); + /* write empty packet to server */ + ma_net_write(&conn->net, (unsigned char *)"", 0); + ma_net_flush(&conn->net); + goto infile_error; + } + + /* allocate buffer for reading data */ + buf = (uchar *)malloc(buflen); + + /* init handler: allocate read buffer and open file */ + if (conn->options.local_infile_init(&info, filename, + conn->options.local_infile_userdata)) + { + char tmp_buf[MYSQL_ERRMSG_SIZE]; + int tmp_errno; + + tmp_errno= conn->options.local_infile_error(info, tmp_buf, sizeof(tmp_buf)); + my_set_error(conn, tmp_errno, SQLSTATE_UNKNOWN, tmp_buf); + ma_net_write(&conn->net, (unsigned char *)"", 0); + ma_net_flush(&conn->net); + goto infile_error; + } + + /* read data */ + while ((bufread= conn->options.local_infile_read(info, (char *)buf, buflen)) > 0) + { + if (ma_net_write(&conn->net, (unsigned char *)buf, bufread)) + { + my_set_error(conn, CR_SERVER_LOST, SQLSTATE_UNKNOWN, NULL); + goto infile_error; + } + } + + /* send empty packet for eof */ + if (ma_net_write(&conn->net, (unsigned char *)"", 0) || + ma_net_flush(&conn->net)) + { + my_set_error(conn, CR_SERVER_LOST, SQLSTATE_UNKNOWN, NULL); + goto infile_error; + } + + /* error during read occurred */ + if (bufread < 0) + { + char tmp_buf[MYSQL_ERRMSG_SIZE]; + int tmp_errno= conn->options.local_infile_error(info, tmp_buf, sizeof(tmp_buf)); + my_set_error(conn, tmp_errno, SQLSTATE_UNKNOWN, tmp_buf); + goto infile_error; + } + + result = 0; + +infile_error: + conn->options.local_infile_end(info); + free(buf); + return(result); +} +/* }}} */ + diff --git a/vendor/MDBC/libmariadb/ma_net.c b/vendor/MDBC/libmariadb/ma_net.c new file mode 100644 index 00000000..680369b3 --- /dev/null +++ b/vendor/MDBC/libmariadb/ma_net.c @@ -0,0 +1,591 @@ +/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB + 2012-2016 SkySQL AB, MariaDB Corporation AB + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + MA 02111-1301, USA */ + +/* Write and read of logical packets to/from socket + ** Writes are cached into net_buffer_length big packets. + ** Read packets are reallocated dynamically when reading big packets. + ** Each logical packet has the following pre-info: + ** 3 byte length & 1 byte package-number. + */ + + +#include +#include +#include +#include +#include +#include "mysql.h" +#include "ma_server_error.h" +#include +#include +#include +#include +#include +#ifndef _WIN32 +#include +#endif + +#define MAX_PACKET_LENGTH (256L*256L*256L-1) + +/* net_buffer_length and max_allowed_packet are defined in mysql.h + See bug conc-57 + */ +#undef net_buffer_length + +#undef max_allowed_packet +ulong max_allowed_packet=1024L * 1024L * 1024L; +ulong net_read_timeout= NET_READ_TIMEOUT; +ulong net_write_timeout= NET_WRITE_TIMEOUT; +ulong net_buffer_length= 8192; /* Default length. Enlarged if necessary */ + +#if !defined(_WIN32) +#include +#else +#undef MYSQL_SERVER /* Win32 can't handle interrupts */ +#endif +#if !defined(_WIN32) && !defined(HAVE_BROKEN_NETINET_INCLUDES) && !defined(__BEOS__) +#include +#include +#include +#if !defined(alpha_linux_port) +#include +#endif +#endif + + +/* + ** Give error if a too big packet is found + ** The server can change this with the -O switch, but because the client + ** can't normally do this the client should have a bigger max-buffer. + */ + +static int ma_net_write_buff(NET *net,const char *packet, size_t len); + + +/* Init with packet info */ + +int ma_net_init(NET *net, MARIADB_PVIO* pvio) +{ + if (!(net->buff=(uchar*) malloc(net_buffer_length))) + return 1; + if (!net->extension) + return 1; + + memset(net->buff, 0, net_buffer_length); + + net->max_packet_size= MAX(net_buffer_length, max_allowed_packet); + net->buff_end=net->buff+(net->max_packet=net_buffer_length); + net->pvio = pvio; + net->error=0; net->return_status=0; + net->read_timeout=(uint) net_read_timeout; /* Timeout for read */ + net->compress_pkt_nr= net->pkt_nr= 0; + net->write_pos=net->read_pos = net->buff; + net->last_error[0]= net->sqlstate[0] =0; + + net->compress=0; net->reading_or_writing=0; + net->where_b = net->remain_in_buf=0; + net->last_errno=0; + + if (pvio != 0) /* If real connection */ + { + ma_pvio_get_handle(pvio, &net->fd); + ma_pvio_blocking(pvio, 1, 0); + ma_pvio_fast_send(pvio); + } + return 0; +} + +void ma_net_end(NET *net) +{ + free(net->buff); + net->buff=0; +} + +/* Realloc the packet buffer */ + +static my_bool net_realloc(NET *net, size_t length) +{ + uchar *buff; + size_t pkt_length; + + if (length >= net->max_packet_size) + { + net->error=1; + net->last_errno=ER_NET_PACKET_TOO_LARGE; + return(1); + } + pkt_length = (length+IO_SIZE-1) & ~(IO_SIZE-1); + /* reallocate buffer: + size= pkt_length + NET_HEADER_SIZE + COMP_HEADER_SIZE */ + if (!(buff=(uchar*) realloc(net->buff, + pkt_length + NET_HEADER_SIZE + COMP_HEADER_SIZE))) + { + net->error=1; + return(1); + } + net->buff=net->write_pos=buff; + net->buff_end=buff+(net->max_packet=(unsigned long)pkt_length); + return(0); +} + +/* Remove unwanted characters from connection */ +void ma_net_clear(NET *net) +{ + if (net->extension->multi_status > COM_MULTI_OFF) + return; + net->compress_pkt_nr= net->pkt_nr=0; /* Ready for new command */ + net->write_pos=net->buff; + return; +} + +/* Flush write_buffer if not empty. */ +int ma_net_flush(NET *net) +{ + int error=0; + + /* don't flush if pipelined query is in progress */ + if (net->extension->multi_status > COM_MULTI_OFF) + return 0; + + if (net->buff != net->write_pos) + { + error=ma_net_real_write(net,(char*) net->buff, + (size_t) (net->write_pos - net->buff)); + net->write_pos=net->buff; + } + if (net->compress) + net->pkt_nr= net->compress_pkt_nr; + return(error); +} + +/***************************************************************************** + ** Write something to server/client buffer + *****************************************************************************/ + +/* + ** Write a logical packet with packet header + ** Format: Packet length (3 bytes), packet number(1 byte) + ** When compression is used a 3 byte compression length is added + ** NOTE: If compression is used the original package is destroyed! + */ + +int ma_net_write(NET *net, const uchar *packet, size_t len) +{ + uchar buff[NET_HEADER_SIZE]; + while (len >= MAX_PACKET_LENGTH) + { + const ulong max_len= MAX_PACKET_LENGTH; + int3store(buff,max_len); + buff[3]= (uchar)net->pkt_nr++; + if (ma_net_write_buff(net,(char*) buff,NET_HEADER_SIZE) || + ma_net_write_buff(net, (char *)packet, max_len)) + return 1; + packet+= max_len; + len-= max_len; + } + /* write last remaining packet, size can be zero */ + int3store(buff, len); + buff[3]= (uchar)net->pkt_nr++; + if (ma_net_write_buff(net,(char*) buff,NET_HEADER_SIZE) || + ma_net_write_buff(net, (char *)packet, len)) + return 1; + return 0; +} + +int ma_net_write_command(NET *net, uchar command, + const char *packet, size_t len, + my_bool disable_flush) +{ + uchar buff[NET_HEADER_SIZE+1]; + size_t buff_size= NET_HEADER_SIZE + 1; + size_t length= 1 + len; /* 1 extra byte for command */ + int rc; + + buff[NET_HEADER_SIZE]= 0; + buff[4]=command; + + if (length >= MAX_PACKET_LENGTH) + { + len= MAX_PACKET_LENGTH - 1; + do + { + int3store(buff, MAX_PACKET_LENGTH); + buff[3]= (net->compress) ? 0 : (uchar) (net->pkt_nr++); + + if (ma_net_write_buff(net, (char *)buff, buff_size) || + ma_net_write_buff(net, packet, len)) + return(1); + packet+= len; + length-= MAX_PACKET_LENGTH; + len= MAX_PACKET_LENGTH; + buff_size= NET_HEADER_SIZE; /* don't send command for further packets */ + } while (length >= MAX_PACKET_LENGTH); + len= length; + } + int3store(buff,length); + buff[3]= (net->compress) ? 0 :(uchar) (net->pkt_nr++); + rc= test (ma_net_write_buff(net,(char *)buff, buff_size) || + ma_net_write_buff(net,packet,len)); + if (!rc && !disable_flush) + return test(ma_net_flush(net)); + return rc; +} + + +static int ma_net_write_buff(NET *net,const char *packet, size_t len) +{ + size_t left_length; + + if (!len) + return 0; + + if (net->max_packet > MAX_PACKET_LENGTH && + net->compress) + left_length= (size_t)(MAX_PACKET_LENGTH - (net->write_pos - net->buff)); + else + left_length=(size_t) (net->buff_end - net->write_pos); + + if (len > left_length) + { + if (net->write_pos != net->buff) + { + memcpy((char*) net->write_pos,packet,left_length); + if (ma_net_real_write(net,(char*) net->buff, + (size_t)(net->write_pos - net->buff) + left_length)) + return 1; + packet+=left_length; + len-=left_length; + net->write_pos= net->buff; + } + if (net->compress) + { + /* uncompressed length is stored in 3 bytes,so + packet can't be > 0xFFFFFF */ + left_length= MAX_PACKET_LENGTH; + while (len > left_length) + { + if (ma_net_real_write(net, packet, left_length)) + return 1; + packet+= left_length; + len-= left_length; + } + } + if (len > net->max_packet) + return(test(ma_net_real_write(net, packet, len))); + } + memcpy((char*) net->write_pos,packet,len); + net->write_pos+=len; + return 0; +} + +unsigned char *mysql_net_store_length(unsigned char *packet, size_t length); + +/* Read and write using timeouts */ + +int ma_net_real_write(NET *net, const char *packet, size_t len) +{ + ssize_t length; + char *pos,*end; + + if (net->error == 2) + return(-1); /* socket can't be used */ + + net->reading_or_writing=2; +#ifdef HAVE_COMPRESS + if (net->compress) + { + size_t complen; + uchar *b; + uint header_length=NET_HEADER_SIZE+COMP_HEADER_SIZE; + if (!(b=(uchar*) malloc(len + NET_HEADER_SIZE + COMP_HEADER_SIZE + 1))) + { + net->last_errno=ER_OUT_OF_RESOURCES; + net->error=2; + net->reading_or_writing=0; + return(1); + } + memcpy(b+header_length,packet,len); + + if (_mariadb_compress((unsigned char*) b+header_length,&len,&complen)) + { + complen=0; + } + int3store(&b[NET_HEADER_SIZE],complen); + int3store(b,len); + b[3]=(uchar) (net->compress_pkt_nr++); + len+= header_length; + packet= (char*) b; + } +#endif /* HAVE_COMPRESS */ + + pos=(char*) packet; end=pos+len; + while (pos != end) + { + if ((length=ma_pvio_write(net->pvio,(uchar *)pos,(size_t) (end-pos))) <= 0) + { + net->error=2; /* Close socket */ + net->last_errno= ER_NET_ERROR_ON_WRITE; + net->reading_or_writing=0; +#ifdef HAVE_COMPRESS + if (net->compress) + free((char*) packet); +#endif + return(1); + } + pos+=length; + } +#ifdef HAVE_COMPRESS + if (net->compress) + free((char*) packet); +#endif + net->reading_or_writing=0; + return(((int) (pos != end))); +} + +/***************************************************************************** + ** Read something from server/clinet + *****************************************************************************/ +static ulong ma_real_read(NET *net, size_t *complen) +{ + uchar *pos; + ssize_t length; + uint i; + ulong len=packet_error; + size_t remain= (net->compress ? NET_HEADER_SIZE+COMP_HEADER_SIZE : + NET_HEADER_SIZE); + *complen = 0; + + net->reading_or_writing=1; + + pos = net->buff + net->where_b; /* net->packet -4 */ + for (i=0 ; i < 2 ; i++) + { + while (remain > 0) + { + /* First read is done with non blocking mode */ + if ((length=ma_pvio_cache_read(net->pvio, pos,remain)) <= 0L) + { + len= packet_error; + net->error=2; /* Close socket */ + goto end; + } + remain -= (ulong) length; + pos+= (ulong) length; + } + + if (i == 0) + { /* First parts is packet length */ + ulong helping; + net->pkt_nr= net->buff[net->where_b + 3]; + net->compress_pkt_nr= ++net->pkt_nr; +#ifdef HAVE_COMPRESS + if (net->compress) + { + /* complen is > 0 if package is really compressed */ + *complen=uint3korr(&(net->buff[net->where_b + NET_HEADER_SIZE])); + } +#endif + + len=uint3korr(net->buff+net->where_b); + if (!len) + goto end; + helping = max(len,(ulong)*complen) + net->where_b; + /* The necessary size of net->buff */ + if (helping >= net->max_packet) + { + if (net_realloc(net, helping)) + { + len= packet_error; /* Return error */ + goto end; + } + } + pos=net->buff + net->where_b; + remain = len; + } + } + +end: + net->reading_or_writing=0; + return(len); +} + +ulong ma_net_read(NET *net) +{ + size_t len,complen; + +#ifdef HAVE_COMPRESS + if (!net->compress) + { +#endif + len = ma_real_read (net,(size_t *)&complen); + if (len == MAX_PACKET_LENGTH) + { + /* multi packet read */ + size_t length= 0; + ulong last_pos= net->where_b; + + do + { + length+= len; + net->where_b+= (unsigned long)len; + len= ma_real_read(net, &complen); + } while (len == MAX_PACKET_LENGTH); + net->where_b= last_pos; + if (len != packet_error) + len+= length; + } + net->read_pos = net->buff + net->where_b; + if (len != packet_error) + net->read_pos[len]=0; /* Safeguard for mysql_use_result */ + return (ulong)len; +#ifdef HAVE_COMPRESS + } + else + { + /* + compressed protocol: + + -------------------------------------- + packet_length 3 + sequence_id 1 + uncompressed_length 3 + -------------------------------------- + compressed data packet_length - 7 + -------------------------------------- + + Another packet will follow if: + packet_length == MAX_PACKET_LENGTH + + Last package will be identified by + - packet_length is zero (special case) + - packet_length < MAX_PACKET_LENGTH + */ + + size_t packet_length, + buffer_length; + size_t current= 0, start= 0; + my_bool is_multi_packet= 0; + + /* check if buffer is empty */ + if (!net->remain_in_buf) + { + buffer_length= 0; + } + else + { + /* save position and restore \0 character */ + buffer_length= net->buf_length; + current= net->buf_length - net->remain_in_buf; + start= current; + net->buff[net->buf_length - net->remain_in_buf]=net->save_char; + } + for (;;) + { + if (buffer_length - current >= 4) + { + uchar *pos= net->buff + current; + packet_length= uint3korr(pos); + + /* check if we have last package (special case: zero length) */ + if (!packet_length) + { + current+= 4; /* length + sequence_id, + no more data will follow */ + break; + } + if (packet_length + 4 <= buffer_length - current) + { + if (!is_multi_packet) + { + current= current + packet_length + 4; + } + else + { + /* remove packet_header */ + memmove(net->buff + current, + net->buff + current + 4, + buffer_length - current); + buffer_length-= 4; + current+= packet_length; + } + /* do we have last packet ? */ + if (packet_length != MAX_PACKET_LENGTH) + { + is_multi_packet= 0; + break; + } + else + is_multi_packet= 1; + if (start) + { + memmove(net->buff, net->buff + start, + buffer_length - start); + /* decrease buflen*/ + buffer_length-= start; + start= 0; + } + continue; + } + } + if (start) + { + memmove(net->buff, net->buff + start, buffer_length - start); + /* decrease buflen and current */ + current -= start; + buffer_length-= start; + start= 0; + } + + net->where_b=(unsigned long)buffer_length; + + if ((packet_length = ma_real_read(net,(size_t *)&complen)) == packet_error) + return packet_error; + if (_mariadb_uncompress((unsigned char*) net->buff + net->where_b, &packet_length, &complen)) + { + net->error=2; /* caller will close socket */ + net->last_errno=ER_NET_UNCOMPRESS_ERROR; + break; + return packet_error; + } + buffer_length+= complen; + } + /* set values */ + net->buf_length= (unsigned long)buffer_length; + net->remain_in_buf= (unsigned long)(buffer_length - current); + net->read_pos= net->buff + start + 4; + len= current - start - 4; + if (is_multi_packet) + len-= 4; + net->save_char= net->read_pos[len]; /* Must be saved */ + net->read_pos[len]=0; /* Safeguard for mysql_use_result */ + } +#endif + return (ulong)len; +} + +int net_add_multi_command(NET *net, uchar command, const uchar *packet, + size_t length) +{ + if (net->extension->multi_status == COM_MULTI_OFF) + { + return(1); + } + /* don't increase packet number */ + net->compress_pkt_nr= net->pkt_nr= 0; + return ma_net_write_command(net, command, (const char *)packet, length, 1); +} + diff --git a/vendor/MDBC/libmariadb/ma_password.c b/vendor/MDBC/libmariadb/ma_password.c new file mode 100644 index 00000000..eb6fe6a8 --- /dev/null +++ b/vendor/MDBC/libmariadb/ma_password.c @@ -0,0 +1,162 @@ +/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB + 2016,2018 MariaDB Corporation AB + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + MA 02111-1301, USA */ + +/* password checking routines */ +/***************************************************************************** + The main idea is that no password are sent between client & server on + connection and that no password are saved in mysql in a decodable form. + + On connection a random string is generated and sent to the client. + The client generates a new string with a random generator inited with + the hash values from the password and the sent string. + This 'check' string is sent to the server where it is compared with + a string generated from the stored hash_value of the password and the + random string. + + The password is saved (in user.password) by using the PASSWORD() function in + mysql. + + Example: + update user set password=PASSWORD("hello") where user="test" + This saves a hashed number as a string in the password field. +*****************************************************************************/ + +#include +#include +#include +#include +#include "mysql.h" + + +void ma_randominit(struct rand_struct *rand_st,ulong seed1, ulong seed2) +{ /* For mysql 3.21.# */ +#ifdef HAVE_purify + memset((char*) rand_st, 0m sizeof(*rand_st)); /* Avoid UMC warnings */ +#endif + rand_st->max_value= 0x3FFFFFFFL; + rand_st->max_value_dbl=(double) rand_st->max_value; + rand_st->seed1=seed1%rand_st->max_value ; + rand_st->seed2=seed2%rand_st->max_value; +} + +double rnd(struct rand_struct *rand_st) +{ + rand_st->seed1=(rand_st->seed1*3+rand_st->seed2) % rand_st->max_value; + rand_st->seed2=(rand_st->seed1+rand_st->seed2+33) % rand_st->max_value; + return (((double) rand_st->seed1)/rand_st->max_value_dbl); +} + +void ma_hash_password(ulong *result, const char *password, size_t len) +{ + register ulong nr=1345345333L, add=7, nr2=0x12345671L; + ulong tmp; + const char *password_end= password + len; + for (; password < password_end; password++) + { + if (*password == ' ' || *password == '\t') + continue; /* skip space in password */ + tmp= (ulong) (uchar) *password; + nr^= (((nr & 63)+add)*tmp)+ (nr << 8); + nr2+=(nr2 << 8) ^ nr; + add+=tmp; + } + result[0]=nr & (((ulong) 1L << 31) -1L); /* Don't use sign bit (str2int) */; + result[1]=nr2 & (((ulong) 1L << 31) -1L); + return; +} + +/* + * Generate a new message based on message and password + * The same thing is done in client and server and the results are checked. + */ + +/* scramble for 4.1 servers + * Code based on php_nysqlnd_scramble function from PHP's mysqlnd extension, + * written by Andrey Hristov (andrey@php.net) + * License: PHP License 3.0 + */ +void my_crypt(unsigned char *buffer, const unsigned char *s1, const unsigned char *s2, size_t len) +{ + const unsigned char *s1_end= s1 + len; + while (s1 < s1_end) { + *buffer++= *s1++ ^ *s2++; + } +} + +void ma_scramble_41(const unsigned char *buffer, const char *scramble, const char *password) +{ + _MA_SHA1_CTX context; + unsigned char sha1[SHA1_MAX_LENGTH]; + unsigned char sha2[SHA1_MAX_LENGTH]; + + + /* Phase 1: hash password */ + ma_SHA1Init(&context); + ma_SHA1Update(&context, (unsigned char *)password, strlen((char *)password)); + ma_SHA1Final(sha1, &context); + + /* Phase 2: hash sha1 */ + ma_SHA1Init(&context); + ma_SHA1Update(&context, (unsigned char*)sha1, SHA1_MAX_LENGTH); + ma_SHA1Final(sha2, &context); + + /* Phase 3: hash scramble + sha2 */ + ma_SHA1Init(&context); + ma_SHA1Update(&context, (unsigned char *)scramble, SCRAMBLE_LENGTH); + ma_SHA1Update(&context, (unsigned char*)sha2, SHA1_MAX_LENGTH); + ma_SHA1Final((unsigned char *)buffer, &context); + + /* let's crypt buffer now */ + my_crypt((uchar *)buffer, (const unsigned char *)buffer, (const unsigned char *)sha1, SHA1_MAX_LENGTH); +} +/* }}} */ + +void ma_make_scrambled_password(char *to,const char *password) +{ + ulong hash_res[2]; + ma_hash_password(hash_res,password, strlen(password)); + sprintf(to,"%08lx%08lx",hash_res[0],hash_res[1]); +} + +/* + * Generate a new message based on message and password + * The same thing is done in client and server and the results are checked. + */ +char *ma_scramble_323(char *to, const char *message, const char *password) +{ + struct rand_struct rand_st; + ulong hash_pass[2], hash_message[2]; + + if (password && password[0]) + { + char extra, *to_start=to; + const char *end_scramble323= message + SCRAMBLE_LENGTH_323; + ma_hash_password(hash_pass,password, (uint) strlen(password)); + /* Don't use strlen, could be > SCRAMBLE_LENGTH_323 ! */ + ma_hash_password(hash_message, message, SCRAMBLE_LENGTH_323); + ma_randominit(&rand_st, hash_pass[0] ^ hash_message[0], + hash_pass[1] ^ hash_message[1]); + for (; message < end_scramble323; message++) + *to++= (char) (floor(rnd(&rand_st) * 31) + 64); + extra=(char) (floor(rnd(&rand_st) * 31)); + while (to_start != to) + *(to_start++)^= extra; + } + *to= 0; + return to; +} diff --git a/vendor/MDBC/libmariadb/ma_pvio.c b/vendor/MDBC/libmariadb/ma_pvio.c new file mode 100644 index 00000000..12569b03 --- /dev/null +++ b/vendor/MDBC/libmariadb/ma_pvio.c @@ -0,0 +1,594 @@ +/************************************************************************************ + Copyright (C) 2015 MariaDB Corporation AB, + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not see + or write to the Free Software Foundation, Inc., + 51 Franklin St., Fifth Floor, Boston, MA 02110, USA +*************************************************************************************/ + +/* MariaDB Communication IO (PVIO) interface + + PVIO is the interface for client server communication and replaces former vio + component of the client library. + + PVIO support various protcols like sockets, pipes and shared memory, which are + implemented as plugins and can be extended therefore easily. + + Interface function description: + + ma_pvio_init allocates a new PVIO object which will be used + for the current connection + + ma_pvio_close frees all resources of previously allocated PVIO object + and closes open connections + + ma_pvio_read reads data from server + + ma_pvio_write sends data to server + + ma_pvio_set_timeout sets timeout for connection, read and write + + ma_pvio_register_callback + register callback functions for read and write + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* callback functions for read/write */ +LIST *pvio_callback= NULL; + +#define IS_BLOCKING_ERROR() \ + IF_WIN(WSAGetLastError() != WSAEWOULDBLOCK, \ + (errno != EAGAIN && errno != EINTR)) + +/* {{{ MARIADB_PVIO *ma_pvio_init */ +MARIADB_PVIO *ma_pvio_init(MA_PVIO_CINFO *cinfo) +{ + /* check connection type and load the required plugin. + * Currently we support the following pvio types: + * pvio_socket + * pvio_namedpipe + * pvio_sharedmed + */ + const char *pvio_plugins[] = {"pvio_socket", "pvio_npipe", "pvio_shmem"}; + int type; + MARIADB_PVIO_PLUGIN *pvio_plugin; + MARIADB_PVIO *pvio= NULL; + + switch (cinfo->type) + { + case PVIO_TYPE_UNIXSOCKET: + case PVIO_TYPE_SOCKET: + type= 0; + break; +#ifdef _WIN32 + case PVIO_TYPE_NAMEDPIPE: + type= 1; + break; + case PVIO_TYPE_SHAREDMEM: + type= 2; + break; +#endif + default: + return NULL; + } + + if (!(pvio_plugin= (MARIADB_PVIO_PLUGIN *) + mysql_client_find_plugin(cinfo->mysql, + pvio_plugins[type], + MARIADB_CLIENT_PVIO_PLUGIN))) + { + /* error already set in mysql_client_find_plugin */ + return NULL; + } + +/* coverity[var_deref_op] */ + if (!(pvio= (MARIADB_PVIO *)calloc(1, sizeof(MARIADB_PVIO)))) + { + my_set_error(cinfo->mysql, CR_OUT_OF_MEMORY, unknown_sqlstate, 0); + return NULL; + } + + /* register error routine and methods */ + pvio->methods= pvio_plugin->methods; + pvio->set_error= my_set_error; + pvio->type= cinfo->type; + + /* set timeout to connect timeout - after successful connect we will set + * correct values for read and write */ + if (pvio->methods->set_timeout) + { + pvio->methods->set_timeout(pvio, PVIO_CONNECT_TIMEOUT, cinfo->mysql->options.connect_timeout); + pvio->methods->set_timeout(pvio, PVIO_READ_TIMEOUT, cinfo->mysql->options.connect_timeout); + pvio->methods->set_timeout(pvio, PVIO_WRITE_TIMEOUT, cinfo->mysql->options.connect_timeout); + } + + if (!(pvio->cache= calloc(1, PVIO_READ_AHEAD_CACHE_SIZE))) + { + PVIO_SET_ERROR(cinfo->mysql, CR_OUT_OF_MEMORY, unknown_sqlstate, 0); + free(pvio); + return NULL; + } + pvio->cache_size= 0; + pvio->cache_pos= pvio->cache; + + return pvio; +} +/* }}} */ + +/* {{{ my_bool ma_pvio_is_alive */ +my_bool ma_pvio_is_alive(MARIADB_PVIO *pvio) +{ + if (!pvio) + return FALSE; + if (pvio->methods->is_alive) + return pvio->methods->is_alive(pvio); + return TRUE; +} +/* }}} */ + +/* {{{ int ma_pvio_fast_send */ +int ma_pvio_fast_send(MARIADB_PVIO *pvio) +{ + if (!pvio || !pvio->methods->fast_send) + return 1; + return pvio->methods->fast_send(pvio); +} +/* }}} */ + +/* {{{ int ma_pvio_keepalive */ +int ma_pvio_keepalive(MARIADB_PVIO *pvio) +{ + if (!pvio || !pvio->methods->keepalive) + return 1; + return pvio->methods->keepalive(pvio); +} +/* }}} */ + +/* {{{ my_bool ma_pvio_set_timeout */ +my_bool ma_pvio_set_timeout(MARIADB_PVIO *pvio, + enum enum_pvio_timeout type, + int timeout) +{ + if (!pvio) + return 1; + + if (pvio->methods->set_timeout) + return pvio->methods->set_timeout(pvio, type, timeout); + return 1; +} +/* }}} */ + +/* {{{ size_t ma_pvio_read_async */ +static size_t ma_pvio_read_async(MARIADB_PVIO *pvio, uchar *buffer, size_t length) +{ + ssize_t res= 0; + struct mysql_async_context *b= pvio->mysql->options.extension->async_context; + int timeout= pvio->timeout[PVIO_READ_TIMEOUT]; + + if (!pvio->methods->async_read) + { + PVIO_SET_ERROR(pvio->mysql, CR_ASYNC_NOT_SUPPORTED, unknown_sqlstate, 0); + return -1; + } + + for (;;) + { + if (pvio->methods->async_read) + res= pvio->methods->async_read(pvio, buffer, length); + if (res >= 0 || IS_BLOCKING_ERROR()) + return res; + b->events_to_wait_for= MYSQL_WAIT_READ; + if (timeout >= 0) + { + b->events_to_wait_for|= MYSQL_WAIT_TIMEOUT; + b->timeout_value= timeout; + } + if (b->suspend_resume_hook) + (*b->suspend_resume_hook)(TRUE, b->suspend_resume_hook_user_data); + my_context_yield(&b->async_context); + if (b->suspend_resume_hook) + (*b->suspend_resume_hook)(FALSE, b->suspend_resume_hook_user_data); + if (b->events_occured & MYSQL_WAIT_TIMEOUT) + return -1; + } +} +/* }}} */ + +/* {{{ size_t ma_pvio_read */ +ssize_t ma_pvio_read(MARIADB_PVIO *pvio, uchar *buffer, size_t length) +{ + ssize_t r= -1; + if (!pvio) + return -1; + if (IS_PVIO_ASYNC_ACTIVE(pvio)) + { + r= +#if defined(HAVE_TLS) && !defined(HAVE_SCHANNEL) + (pvio->ctls) ? ma_tls_read_async(pvio, buffer, length) : +#endif + (ssize_t)ma_pvio_read_async(pvio, buffer, length); + goto end; + } + else + { + if (IS_PVIO_ASYNC(pvio)) + { + /* + If switching from non-blocking to blocking API usage, set the socket + back to blocking mode. + */ + my_bool old_mode; + ma_pvio_blocking(pvio, TRUE, &old_mode); + } + } + + /* secure connection */ +#ifdef HAVE_TLS + if (pvio->ctls) + { + r= ma_pvio_tls_read(pvio->ctls, buffer, length); + goto end; + } +#endif + if (pvio->methods->read) + r= pvio->methods->read(pvio, buffer, length); +end: + if (pvio_callback) + { + void (*callback)(int mode, MYSQL *mysql, const uchar *buffer, size_t length); + LIST *p= pvio_callback; + while (p) + { + callback= p->data; + callback(0, pvio->mysql, buffer, r); + p= p->next; + } + } + return r; +} +/* }}} */ + +/* {{{ size_t ma_pvio_cache_read */ +ssize_t ma_pvio_cache_read(MARIADB_PVIO *pvio, uchar *buffer, size_t length) +{ + ssize_t r; + + if (!pvio) + return -1; + + if (!pvio->cache) + return ma_pvio_read(pvio, buffer, length); + + if (pvio->cache + pvio->cache_size > pvio->cache_pos) + { + ssize_t remaining = pvio->cache + pvio->cache_size - pvio->cache_pos; + assert(remaining > 0); + r= MIN((ssize_t)length, remaining); + memcpy(buffer, pvio->cache_pos, r); + pvio->cache_pos+= r; + } + else if (length >= PVIO_READ_AHEAD_CACHE_MIN_SIZE) + { + r= ma_pvio_read(pvio, buffer, length); + } + else + { + r= ma_pvio_read(pvio, pvio->cache, PVIO_READ_AHEAD_CACHE_SIZE); + if (r > 0) + { + if (length < (size_t)r) + { + pvio->cache_size= r; + pvio->cache_pos= pvio->cache + length; + r= length; + } + memcpy(buffer, pvio->cache, r); + } + } + return r; +} +/* }}} */ + +/* {{{ size_t ma_pvio_write_async */ +static ssize_t ma_pvio_write_async(MARIADB_PVIO *pvio, const uchar *buffer, size_t length) +{ + ssize_t res; + struct mysql_async_context *b= pvio->mysql->options.extension->async_context; + int timeout= pvio->timeout[PVIO_WRITE_TIMEOUT]; + + for (;;) + { + res= pvio->methods->async_write(pvio, buffer, length); + if (res >= 0 || IS_BLOCKING_ERROR()) + return res; + b->events_to_wait_for= MYSQL_WAIT_WRITE; + if (timeout >= 0) + { + b->events_to_wait_for|= MYSQL_WAIT_TIMEOUT; + b->timeout_value= timeout; + } + if (b->suspend_resume_hook) + (*b->suspend_resume_hook)(TRUE, b->suspend_resume_hook_user_data); + my_context_yield(&b->async_context); + if (b->suspend_resume_hook) + (*b->suspend_resume_hook)(FALSE, b->suspend_resume_hook_user_data); + if (b->events_occured & MYSQL_WAIT_TIMEOUT) + return -1; + } +} +/* }}} */ + +/* {{{ size_t ma_pvio_write */ +ssize_t ma_pvio_write(MARIADB_PVIO *pvio, const uchar *buffer, size_t length) +{ + ssize_t r= 0; + + if (!pvio) + return -1; + + if (IS_PVIO_ASYNC_ACTIVE(pvio)) + { + r= +#if defined(HAVE_TLS) && !defined(HAVE_SCHANNEL) + (pvio->ctls) ? ma_tls_write_async(pvio, buffer, length) : +#endif + ma_pvio_write_async(pvio, buffer, length); + goto end; + } + else + { + if (IS_PVIO_ASYNC(pvio)) + { + /* + If switching from non-blocking to blocking API usage, set the socket + back to blocking mode. + */ + my_bool old_mode; + ma_pvio_blocking(pvio, TRUE, &old_mode); + } + } + /* secure connection */ +#ifdef HAVE_TLS + if (pvio->ctls) + { + r= ma_pvio_tls_write(pvio->ctls, buffer, length); + goto end; + } +#endif + + if (pvio->methods->write) + r= pvio->methods->write(pvio, buffer, length); +end: + if (pvio_callback) + { + void (*callback)(int mode, MYSQL *mysql, const uchar *buffer, size_t length); + LIST *p= pvio_callback; + while (p) + { + callback= p->data; + callback(1, pvio->mysql, buffer, r); + p= p->next; + } + } + return r; +} +/* }}} */ + +/* {{{ void ma_pvio_close */ +void ma_pvio_close(MARIADB_PVIO *pvio) +{ + /* free internal structures and close connection */ + if (pvio) + { +#ifdef HAVE_TLS + if (pvio->ctls) + { + ma_pvio_tls_close(pvio->ctls); + free(pvio->ctls); + } +#endif + if (pvio && pvio->methods->close) + pvio->methods->close(pvio); + + if (pvio->cache) + free(pvio->cache); + + free(pvio); + } +} +/* }}} */ + +/* {{{ my_bool ma_pvio_get_handle */ +my_bool ma_pvio_get_handle(MARIADB_PVIO *pvio, void *handle) +{ + if (pvio && pvio->methods->get_handle) + return pvio->methods->get_handle(pvio, handle); + return 1; +} +/* }}} */ + +/* {{{ ma_pvio_wait_async */ +static my_bool +ma_pvio_wait_async(struct mysql_async_context *b, enum enum_pvio_io_event event, + int timeout) +{ + switch (event) + { + case VIO_IO_EVENT_READ: + b->events_to_wait_for = MYSQL_WAIT_READ; + break; + case VIO_IO_EVENT_WRITE: + b->events_to_wait_for = MYSQL_WAIT_WRITE; + break; + case VIO_IO_EVENT_CONNECT: + b->events_to_wait_for = MYSQL_WAIT_WRITE | IF_WIN(0, MYSQL_WAIT_EXCEPT); + break; + } + + if (timeout >= 0) + { + b->events_to_wait_for |= MYSQL_WAIT_TIMEOUT; + b->timeout_value= timeout; + } + if (b->suspend_resume_hook) + (*b->suspend_resume_hook)(TRUE, b->suspend_resume_hook_user_data); + my_context_yield(&b->async_context); + if (b->suspend_resume_hook) + (*b->suspend_resume_hook)(FALSE, b->suspend_resume_hook_user_data); + return (b->events_occured & MYSQL_WAIT_TIMEOUT) ? 0 : 1; +} +/* }}} */ + +/* {{{ ma_pvio_wait_io_or_timeout */ +int ma_pvio_wait_io_or_timeout(MARIADB_PVIO *pvio, my_bool is_read, int timeout) +{ + if (pvio) + { + if (IS_PVIO_ASYNC_ACTIVE(pvio)) + return ma_pvio_wait_async(pvio->mysql->options.extension->async_context, + (is_read) ? VIO_IO_EVENT_READ : VIO_IO_EVENT_WRITE, + timeout); + + if (pvio && pvio->methods->wait_io_or_timeout) + return pvio->methods->wait_io_or_timeout(pvio, is_read, timeout); + } + return 1; +} +/* }}} */ + +/* {{{ my_bool ma_pvio_connect */ +my_bool ma_pvio_connect(MARIADB_PVIO *pvio, MA_PVIO_CINFO *cinfo) +{ + if (pvio && pvio->methods->connect) + return pvio->methods->connect(pvio, cinfo); + return 1; +} +/* }}} */ + +/* {{{ my_bool ma_pvio_blocking */ +my_bool ma_pvio_blocking(MARIADB_PVIO *pvio, my_bool block, my_bool *previous_mode) +{ + if (pvio && pvio->methods->blocking) + return pvio->methods->blocking(pvio, block, previous_mode) != 0; + return 1; +} +/* }}} */ + +/* {{{ my_bool ma_pvio_is_blocking */ +my_bool ma_pvio_is_blocking(MARIADB_PVIO *pvio) +{ + if (pvio && pvio->methods->is_blocking) + return pvio->methods->is_blocking(pvio); + return 1; +} +/* }}} */ + +/* {{{ ma_pvio_has_data */ +my_bool ma_pvio_has_data(MARIADB_PVIO *pvio, ssize_t *data_len) +{ + /* check if we still have unread data in cache */ + if (pvio && pvio->cache) + if (pvio->cache_pos > pvio->cache) + return test(pvio->cache_pos - pvio->cache); + if (pvio && pvio->methods->has_data) + return pvio->methods->has_data(pvio, data_len); + return 1; +} +/* }}} */ + +#ifdef HAVE_TLS +/* {{{ my_bool ma_pvio_start_ssl */ +my_bool ma_pvio_start_ssl(MARIADB_PVIO *pvio) +{ + if (!pvio || !pvio->mysql) + return 1; + CLEAR_CLIENT_ERROR(pvio->mysql); + if (!(pvio->ctls= ma_pvio_tls_init(pvio->mysql))) + { + return 1; + } + if (ma_pvio_tls_connect(pvio->ctls)) + { + free(pvio->ctls); + pvio->ctls= NULL; + return 1; + } + + /* default behaviour: + 1. peer certificate verification + 2. verify CN (requires option ssl_verify_check) + 3. verrify finger print + */ + if ((pvio->mysql->client_flag & CLIENT_SSL_VERIFY_SERVER_CERT) && + ma_pvio_tls_verify_server_cert(pvio->ctls)) + return 1; + + if (pvio->mysql->options.extension && + ((pvio->mysql->options.extension->tls_fp && pvio->mysql->options.extension->tls_fp[0]) || + (pvio->mysql->options.extension->tls_fp_list && pvio->mysql->options.extension->tls_fp_list[0]))) + { + if (ma_pvio_tls_check_fp(pvio->ctls, + pvio->mysql->options.extension->tls_fp, + pvio->mysql->options.extension->tls_fp_list)) + return 1; + } + + return 0; +} +/* }}} */ +#endif + +/* {{{ ma_pvio_register_callback */ +int ma_pvio_register_callback(my_bool register_callback, + void (*callback_function)(int mode, MYSQL *mysql, const uchar *buffer, size_t length)) +{ + LIST *list; + + if (!callback_function) + return 1; + + /* plugin will unregister in it's deinit function */ + if (register_callback) + { + list= (LIST *)malloc(sizeof(LIST)); + + list->data= (void *)callback_function; + pvio_callback= list_add(pvio_callback, list); + } + else /* unregister callback function */ + { + LIST *p= pvio_callback; + while (p) + { + if (p->data == callback_function) + { + list_delete(pvio_callback, p); + break; + } + p= p->next; + } + } + return 0; +} +/* }}} */ diff --git a/vendor/MDBC/libmariadb/ma_sha1.c b/vendor/MDBC/libmariadb/ma_sha1.c new file mode 100644 index 00000000..04c5760e --- /dev/null +++ b/vendor/MDBC/libmariadb/ma_sha1.c @@ -0,0 +1,326 @@ +/**************************************************************************** + Copyright (C) 2012 Monty Program AB + 2016 MariaDB Corporation AB + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not see + or write to the Free Software Foundation, Inc., + 51 Franklin St., Fifth Floor, Boston, MA 02110, USA + *****************************************************************************/ + +/* This code came from the PHP project, initially written by + Stefan Esser */ + + +#include "ma_global.h" +#include "string.h" + +/* This code is heavily based on the PHP md5 implementation */ + +#include "ma_sha1.h" + + +static void ma_SHA1Transform(uint32[5], const unsigned char[64]); +static void ma_SHA1Encode(unsigned char *, uint32 *, unsigned int); +static void ma_SHA1Decode(uint32 *, const unsigned char *, unsigned int); + +static unsigned char PADDING[64] = +{ + 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +}; + +/* F, G, H and I are basic SHA1 functions. +*/ +#define F(x, y, z) ((z) ^ ((x) & ((y) ^ (z)))) +#define G(x, y, z) ((x) ^ (y) ^ (z)) +#define H(x, y, z) (((x) & (y)) | ((z) & ((x) | (y)))) +#define I(x, y, z) ((x) ^ (y) ^ (z)) + +/* ROTATE_LEFT rotates x left n bits. +*/ +#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) + +/* W[i] +*/ +#define W(i) ( tmp=x[(i-3)&15]^x[(i-8)&15]^x[(i-14)&15]^x[i&15], \ + (x[i&15]=ROTATE_LEFT(tmp, 1)) ) + +/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. +*/ +#define FF(a, b, c, d, e, w) { \ + (e) += F ((b), (c), (d)) + (w) + (uint32)(0x5A827999); \ + (e) += ROTATE_LEFT ((a), 5); \ + (b) = ROTATE_LEFT((b), 30); \ +} +#define GG(a, b, c, d, e, w) { \ + (e) += G ((b), (c), (d)) + (w) + (uint32)(0x6ED9EBA1); \ + (e) += ROTATE_LEFT ((a), 5); \ + (b) = ROTATE_LEFT((b), 30); \ +} +#define HH(a, b, c, d, e, w) { \ + (e) += H ((b), (c), (d)) + (w) + (uint32)(0x8F1BBCDC); \ + (e) += ROTATE_LEFT ((a), 5); \ + (b) = ROTATE_LEFT((b), 30); \ +} +#define II(a, b, c, d, e, w) { \ + (e) += I ((b), (c), (d)) + (w) + (uint32)(0xCA62C1D6); \ + (e) += ROTATE_LEFT ((a), 5); \ + (b) = ROTATE_LEFT((b), 30); \ +} + + +/* {{{ ma_SHA1Init + * SHA1 initialization. Begins an SHA1 operation, writing a new context. + */ +void ma_SHA1Init(_MA_SHA1_CTX * context) +{ + context->count[0] = context->count[1] = 0; + /* Load magic initialization constants. + */ + context->state[0] = 0x67452301; + context->state[1] = 0xefcdab89; + context->state[2] = 0x98badcfe; + context->state[3] = 0x10325476; + context->state[4] = 0xc3d2e1f0; +} +/* }}} */ + +/* {{{ ma_SHA1Update + SHA1 block update operation. Continues an SHA1 message-digest + operation, processing another message block, and updating the + context. + */ +void ma_SHA1Update(_MA_SHA1_CTX * context, const unsigned char *input, + size_t inputLen) +{ + unsigned int i, index, partLen; + + /* Compute number of bytes mod 64 */ + index = (unsigned int) ((context->count[0] >> 3) & 0x3F); + + /* Update number of bits */ + if ((context->count[0] += ((uint32) inputLen << 3)) + < ((uint32) inputLen << 3)) + context->count[1]++; + context->count[1] += ((uint32) inputLen >> 29); + + partLen = 64 - index; + + /* Transform as many times as possible. + */ + if (inputLen >= partLen) { + memcpy + ((unsigned char*) & context->buffer[index], (unsigned char*) input, partLen); + ma_SHA1Transform(context->state, context->buffer); + + for (i = partLen; i + 63 < inputLen; i += 64) + ma_SHA1Transform(context->state, &input[i]); + + index = 0; + } else + i = 0; + + /* Buffer remaining input */ + memcpy + ((unsigned char*) & context->buffer[index], (unsigned char*) & input[i], + inputLen - i); +} +/* }}} */ + +/* {{{ ma_SHA1Final + SHA1 finalization. Ends an SHA1 message-digest operation, writing the + the message digest and zeroizing the context. + */ +void ma_SHA1Final(unsigned char digest[20], _MA_SHA1_CTX * context) +{ + unsigned char bits[8]; + unsigned int index, padLen; + + /* Save number of bits */ + bits[7] = context->count[0] & 0xFF; + bits[6] = (context->count[0] >> 8) & 0xFF; + bits[5] = (context->count[0] >> 16) & 0xFF; + bits[4] = (context->count[0] >> 24) & 0xFF; + bits[3] = context->count[1] & 0xFF; + bits[2] = (context->count[1] >> 8) & 0xFF; + bits[1] = (context->count[1] >> 16) & 0xFF; + bits[0] = (context->count[1] >> 24) & 0xFF; + + /* Pad out to 56 mod 64. + */ + index = (unsigned int) ((context->count[0] >> 3) & 0x3f); + padLen = (index < 56) ? (56 - index) : (120 - index); + ma_SHA1Update(context, PADDING, padLen); + + /* Append length (before padding) */ + ma_SHA1Update(context, bits, 8); + + /* Store state in digest */ + ma_SHA1Encode(digest, context->state, 20); + + /* Zeroize sensitive information. + */ + memset((unsigned char*) context, 0, sizeof(*context)); +} +/* }}} */ + +/* {{{ ma_SHA1Transform + * SHA1 basic transformation. Transforms state based on block. + */ +static void ma_SHA1Transform(uint32 state[5], const unsigned char block[64]) +{ + uint32 a = state[0], b = state[1], c = state[2]; + uint32 d = state[3], e = state[4], x[16], tmp; + + ma_SHA1Decode(x, block, 64); + + /* Round 1 */ + FF(a, b, c, d, e, x[0]); /* 1 */ + FF(e, a, b, c, d, x[1]); /* 2 */ + FF(d, e, a, b, c, x[2]); /* 3 */ + FF(c, d, e, a, b, x[3]); /* 4 */ + FF(b, c, d, e, a, x[4]); /* 5 */ + FF(a, b, c, d, e, x[5]); /* 6 */ + FF(e, a, b, c, d, x[6]); /* 7 */ + FF(d, e, a, b, c, x[7]); /* 8 */ + FF(c, d, e, a, b, x[8]); /* 9 */ + FF(b, c, d, e, a, x[9]); /* 10 */ + FF(a, b, c, d, e, x[10]); /* 11 */ + FF(e, a, b, c, d, x[11]); /* 12 */ + FF(d, e, a, b, c, x[12]); /* 13 */ + FF(c, d, e, a, b, x[13]); /* 14 */ + FF(b, c, d, e, a, x[14]); /* 15 */ + FF(a, b, c, d, e, x[15]); /* 16 */ + FF(e, a, b, c, d, W(16)); /* 17 */ + FF(d, e, a, b, c, W(17)); /* 18 */ + FF(c, d, e, a, b, W(18)); /* 19 */ + FF(b, c, d, e, a, W(19)); /* 20 */ + + /* Round 2 */ + GG(a, b, c, d, e, W(20)); /* 21 */ + GG(e, a, b, c, d, W(21)); /* 22 */ + GG(d, e, a, b, c, W(22)); /* 23 */ + GG(c, d, e, a, b, W(23)); /* 24 */ + GG(b, c, d, e, a, W(24)); /* 25 */ + GG(a, b, c, d, e, W(25)); /* 26 */ + GG(e, a, b, c, d, W(26)); /* 27 */ + GG(d, e, a, b, c, W(27)); /* 28 */ + GG(c, d, e, a, b, W(28)); /* 29 */ + GG(b, c, d, e, a, W(29)); /* 30 */ + GG(a, b, c, d, e, W(30)); /* 31 */ + GG(e, a, b, c, d, W(31)); /* 32 */ + GG(d, e, a, b, c, W(32)); /* 33 */ + GG(c, d, e, a, b, W(33)); /* 34 */ + GG(b, c, d, e, a, W(34)); /* 35 */ + GG(a, b, c, d, e, W(35)); /* 36 */ + GG(e, a, b, c, d, W(36)); /* 37 */ + GG(d, e, a, b, c, W(37)); /* 38 */ + GG(c, d, e, a, b, W(38)); /* 39 */ + GG(b, c, d, e, a, W(39)); /* 40 */ + + /* Round 3 */ + HH(a, b, c, d, e, W(40)); /* 41 */ + HH(e, a, b, c, d, W(41)); /* 42 */ + HH(d, e, a, b, c, W(42)); /* 43 */ + HH(c, d, e, a, b, W(43)); /* 44 */ + HH(b, c, d, e, a, W(44)); /* 45 */ + HH(a, b, c, d, e, W(45)); /* 46 */ + HH(e, a, b, c, d, W(46)); /* 47 */ + HH(d, e, a, b, c, W(47)); /* 48 */ + HH(c, d, e, a, b, W(48)); /* 49 */ + HH(b, c, d, e, a, W(49)); /* 50 */ + HH(a, b, c, d, e, W(50)); /* 51 */ + HH(e, a, b, c, d, W(51)); /* 52 */ + HH(d, e, a, b, c, W(52)); /* 53 */ + HH(c, d, e, a, b, W(53)); /* 54 */ + HH(b, c, d, e, a, W(54)); /* 55 */ + HH(a, b, c, d, e, W(55)); /* 56 */ + HH(e, a, b, c, d, W(56)); /* 57 */ + HH(d, e, a, b, c, W(57)); /* 58 */ + HH(c, d, e, a, b, W(58)); /* 59 */ + HH(b, c, d, e, a, W(59)); /* 60 */ + + /* Round 4 */ + II(a, b, c, d, e, W(60)); /* 61 */ + II(e, a, b, c, d, W(61)); /* 62 */ + II(d, e, a, b, c, W(62)); /* 63 */ + II(c, d, e, a, b, W(63)); /* 64 */ + II(b, c, d, e, a, W(64)); /* 65 */ + II(a, b, c, d, e, W(65)); /* 66 */ + II(e, a, b, c, d, W(66)); /* 67 */ + II(d, e, a, b, c, W(67)); /* 68 */ + II(c, d, e, a, b, W(68)); /* 69 */ + II(b, c, d, e, a, W(69)); /* 70 */ + II(a, b, c, d, e, W(70)); /* 71 */ + II(e, a, b, c, d, W(71)); /* 72 */ + II(d, e, a, b, c, W(72)); /* 73 */ + II(c, d, e, a, b, W(73)); /* 74 */ + II(b, c, d, e, a, W(74)); /* 75 */ + II(a, b, c, d, e, W(75)); /* 76 */ + II(e, a, b, c, d, W(76)); /* 77 */ + II(d, e, a, b, c, W(77)); /* 78 */ + II(c, d, e, a, b, W(78)); /* 79 */ + II(b, c, d, e, a, W(79)); /* 80 */ + + state[0] += a; + state[1] += b; + state[2] += c; + state[3] += d; + state[4] += e; + + /* Zeroize sensitive information. */ + memset((unsigned char*) x, 0, sizeof(x)); +} +/* }}} */ + +/* {{{ ma_SHA1Encode + Encodes input (uint32) into output (unsigned char). Assumes len is + a multiple of 4. + */ +static void ma_SHA1Encode(unsigned char *output, uint32 *input, unsigned int len) +{ + unsigned int i, j; + + for (i = 0, j = 0; j < len; i++, j += 4) { + output[j] = (unsigned char) ((input[i] >> 24) & 0xff); + output[j + 1] = (unsigned char) ((input[i] >> 16) & 0xff); + output[j + 2] = (unsigned char) ((input[i] >> 8) & 0xff); + output[j + 3] = (unsigned char) (input[i] & 0xff); + } +} +/* }}} */ + +/* {{{ ma_SHA1Decode + Decodes input (unsigned char) into output (uint32). Assumes len is + a multiple of 4. + */ +static void ma_SHA1Decode(uint32 *output, const unsigned char * input, unsigned int len) +{ + unsigned int i, j; + + for (i = 0, j = 0; j < len; i++, j += 4) + output[i] = ((uint32) input[j + 3]) | (((uint32) input[j + 2]) << 8) | + (((uint32) input[j + 1]) << 16) | (((uint32) input[j]) << 24); +} +/* }}} */ + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: sw=4 ts=4 fdm=marker + * vim<600: sw=4 ts=4 + */ diff --git a/vendor/MDBC/libmariadb/ma_stmt_codec.c b/vendor/MDBC/libmariadb/ma_stmt_codec.c new file mode 100644 index 00000000..913b6a87 --- /dev/null +++ b/vendor/MDBC/libmariadb/ma_stmt_codec.c @@ -0,0 +1,1362 @@ +/**************************************************************************** + Copyright (C) 2012 Monty Program AB + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not see + or write to the Free Software Foundation, Inc., + 51 Franklin St., Fifth Floor, Boston, MA 02110, USA + + Part of this code includes code from the PHP project which + is freely available from http://www.php.net +*****************************************************************************/ + +/* The implementation for prepared statements was ported from PHP's mysqlnd + extension, written by Andrey Hristov, Georg Richter and Ulf Wendel + + Original file header: + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | Copyright (c) 2006-2011 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Authors: Georg Richter | + | Andrey Hristov | + | Ulf Wendel | + +----------------------------------------------------------------------+ +*/ + +#include "ma_global.h" +#include +#include +#include +#include "mysql.h" +#include /* ceil() */ +#include + +#ifdef WIN32 +#include +#endif + +#define MYSQL_SILENT + +/* ranges for C-binding */ +#define UINT_MAX32 0xFFFFFFFFL +#define UINT_MAX24 0x00FFFFFF +#define UINT_MAX16 0xFFFF +#ifndef INT_MIN8 +#define INT_MIN8 (~0x7F) +#define INT_MAX8 0x7F +#endif +#define UINT_MAX8 0xFF + + #define MAX_DOUBLE_STRING_REP_LENGTH 300 +#if defined(HAVE_LONG_LONG) && !defined(LONGLONG_MIN) +#define LONGLONG_MIN ((long long) 0x8000000000000000LL) +#define LONGLONG_MAX ((long long) 0x7FFFFFFFFFFFFFFFLL) +#endif + +#define MAX_DBL_STR (3 + DBL_MANT_DIG - DBL_MIN_EXP) + +#if defined(HAVE_LONG_LONG) && !defined(ULONGLONG_MAX) +/* First check for ANSI C99 definition: */ +#ifdef ULLONG_MAX +#define ULONGLONG_MAX ULLONG_MAX +#else +#define ULONGLONG_MAX ((unsigned long long)(~0ULL)) +#endif +#endif /* defined (HAVE_LONG_LONG) && !defined(ULONGLONG_MAX)*/ + +#define YY_PART_YEAR 70 + +MYSQL_PS_CONVERSION mysql_ps_fetch_functions[MYSQL_TYPE_GEOMETRY + 1]; +my_bool mysql_ps_subsystem_initialized= 0; + + +#define NUMERIC_TRUNCATION(val,min_range, max_range)\ + ((((val) > (max_range)) || ((val) < (min_range)) ? 1 : 0)) + + +void ma_bmove_upp(register char *dst, register const char *src, register size_t len) +{ + while (len-- != 0) *--dst = *--src; +} + +/* {{{ ps_fetch_from_1_to_8_bytes */ +void ps_fetch_from_1_to_8_bytes(MYSQL_BIND *r_param, const MYSQL_FIELD * const field, + unsigned char **row, unsigned int byte_count) +{ + my_bool is_unsigned= test(field->flags & UNSIGNED_FLAG); + r_param->buffer_length= byte_count; + switch (byte_count) { + case 1: + *(uchar *)r_param->buffer= **row; + *r_param->error= is_unsigned != r_param->is_unsigned && *(uchar *)r_param->buffer > INT_MAX8; + break; + case 2: + shortstore(r_param->buffer, ((ushort) sint2korr(*row))); + *r_param->error= is_unsigned != r_param->is_unsigned && *(ushort *)r_param->buffer > INT_MAX16; + break; + case 4: + { + longstore(r_param->buffer, ((uint32)sint4korr(*row))); + *r_param->error= is_unsigned != r_param->is_unsigned && *(uint32 *)r_param->buffer > INT_MAX32; + } + break; + case 8: + { + ulonglong val= (ulonglong)sint8korr(*row); + longlongstore(r_param->buffer, val); + *r_param->error= is_unsigned != r_param->is_unsigned && val > LONGLONG_MAX ; + } + break; + default: + r_param->buffer_length= 0; + break; + } + (*row)+= byte_count; +} +/* }}} */ + +static unsigned long long my_strtoull(const char *str, size_t len, const char **end, int *err) +{ + unsigned long long val = 0; + const char *p = str; + const char *end_str = p + len; + + for (; p < end_str; p++) + { + if (*p < '0' || *p > '9') + break; + + if (val > ULONGLONG_MAX /10 || val*10 > ULONGLONG_MAX - (*p - '0')) + { + *err = ERANGE; + break; + } + val = val * 10 + *p -'0'; + } + + if (p == str) + /* Did not parse anything.*/ + *err = ERANGE; + + *end = p; + return val; +} + +static long long my_strtoll(const char *str, size_t len, const char **end, int *err) +{ + unsigned long long uval = 0; + const char *p = str; + const char *end_str = p + len; + int neg; + + while (p < end_str && isspace(*p)) + p++; + + if (p == end_str) + { + *end = p; + *err = ERANGE; + return 0; + } + + neg = *p == '-'; + if (neg) + p++; + + uval = my_strtoull(p, (end_str - p), &p, err); + *end = p; + if (*err) + return uval; + + if (!neg) + { + /* Overflow of the long long range. */ + if (uval > LONGLONG_MAX) + { + *end = p - 1; + uval = LONGLONG_MAX; + *err = ERANGE; + } + return uval; + } + + if (uval == (unsigned long long) LONGLONG_MIN) + return LONGLONG_MIN; + + if (uval > LONGLONG_MAX) + { + *end = p - 1; + uval = LONGLONG_MIN; + *err = ERANGE; + } + + return -1LL * uval; +} + + +static long long my_atoll(const char *str, const char *end_str, int *error) +{ + const char *p=str; + const char *end; + long long ret; + while (p < end_str && isspace(*p)) + p++; + + ret = my_strtoll(p, end_str - p, &end, error); + + while(end < end_str && isspace(*end)) + end++; + + if(end != end_str) + *error= 1; + + return ret; +} + + +static unsigned long long my_atoull(const char *str, const char *end_str, int *error) +{ + const char *p = str; + const char *end; + unsigned long long ret; + + while (p < end_str && isspace(*p)) + p++; + + ret = my_strtoull(p, end_str - p, &end, error); + + while(end < end_str && isspace(*end)) + end++; + + if(end != end_str) + *error= 1; + + return ret; +} + +double my_atod(const char *number, const char *end, int *error) +{ + double val= 0.0; + char buffer[MAX_DBL_STR + 1]; + int len= (int)(end - number); + + *error= errno= 0; + + if (len > MAX_DBL_STR) + { + *error= 1; + len= MAX_DBL_STR; + } + + memcpy(buffer, number, len); + buffer[len]= '\0'; + + val= strtod(buffer, NULL); + + if (errno) + *error= errno; + + return val; +} + + +/* + strtoui() version, that works for non-null terminated strings +*/ +static unsigned int my_strtoui(const char *str, size_t len, const char **end, int *err) +{ + unsigned long long ull = my_strtoull(str, len, end, err); + if (ull > UINT_MAX) + *err = ERANGE; + return (unsigned int)ull; +} + +/* + Parse time, in MySQL format. + + the input string needs is in form "hour:minute:second[.fraction]" + hour, minute and second can have leading zeroes or not, + they are not necessarily 2 chars. + + Hour must be < 838, minute < 60, second < 60 + Only 6 places of fraction are considered, the value is truncated after 6 places. +*/ +static const unsigned int frac_mul[] = { 1000000,100000,10000,1000,100,10 }; + +static int parse_time(const char *str, size_t length, const char **end_ptr, MYSQL_TIME *tm) +{ + int err= 0; + const char *p = str; + const char *end = str + length; + size_t frac_len; + int ret=1; + + tm->hour = my_strtoui(p, end-p, &p, &err); + if (err || tm->hour > 838 || p == end || *p != ':' ) + goto end; + + p++; + tm->minute = my_strtoui(p, end-p, &p, &err); + if (err || tm->minute > 59 || p == end || *p != ':') + goto end; + + p++; + tm->second = my_strtoui(p, end-p, &p, &err); + if (err || tm->second > 59) + goto end; + + ret = 0; + tm->second_part = 0; + + if (p == end) + goto end; + + /* Check for fractional part*/ + if (*p != '.') + goto end; + + p++; + frac_len = MIN(6,end-p); + + tm->second_part = my_strtoui(p, frac_len, &p, &err); + if (err) + goto end; + + if (frac_len < 6) + tm->second_part *= frac_mul[frac_len]; + + ret = 0; + + /* Consume whole fractional part, even after 6 digits.*/ + p += frac_len; + while(p < *end_ptr) + { + if (*p < '0' || *p > '9') + break; + p++; + } +end: + *end_ptr = p; + return ret; +} + + +/* + Parse date, in MySQL format. + + The input string needs is in form "year-month-day" + year, month and day can have leading zeroes or not, + they do not have fixed length. + + Year must be < 10000, month < 12, day < 32 + + Years with 2 digits, are converted to values 1970-2069 according to + usual rules: + + 00-69 is converted to 2000-2069. + 70-99 is converted to 1970-1999. +*/ +static int parse_date(const char *str, size_t length, const char **end_ptr, MYSQL_TIME *tm) +{ + int err = 0; + const char *p = str; + const char *end = str + length; + int ret = 1; + + tm->year = my_strtoui(p, end - p, &p, &err); + if (err || tm->year > 9999 || p == end || *p != '-') + goto end; + + if (p - str == 2) // 2-digit year + tm->year += (tm->year >= 70) ? 1900 : 2000; + + p++; + tm->month = my_strtoui(p,end -p, &p, &err); + if (err || tm->month > 12 || p == end || *p != '-') + goto end; + + p++; + tm->day = my_strtoui(p, end -p , &p, &err); + if (err || tm->day > 31) + goto end; + + ret = 0; + +end: + *end_ptr = p; + return ret; +} + +/* + Parse (not null terminated) string representing + TIME, DATE, or DATETIME into MYSQL_TIME structure + + The supported formats by this functions are + - TIME : [-]hours:minutes:seconds[.fraction] + - DATE : year-month-day + - DATETIME : year-month-dayhours:minutes:seconds[.fraction] + + cf https://dev.mysql.com/doc/refman/8.0/en/datetime.html + + Whitespaces are trimmed from the start and end of the string. + The function ignores junk at the end of the string. + + Parts of date of time do not have fixed length, so that parsing is compatible with server. + However server supports additional formats, e.g YYYYMMDD, HHMMSS, which this function does + not support. + +*/ +int str_to_TIME(const char *str, size_t length, MYSQL_TIME *tm) +{ + const char *p = str; + const char *end = str + length; + int is_time = 0; + + if (!p) + goto error; + + while (p < end && isspace(*p)) + p++; + while (p < end && isspace(end[-1])) + end--; + + if (end -p < 5) + goto error; + + if (*p == '-') + { + tm->neg = 1; + /* Only TIME can't be negative.*/ + is_time = 1; + p++; + } + else + { + int i; + tm->neg = 0; + /* + Date parsing (in server) accepts leading zeroes, thus position of the delimiters + is not fixed. Scan the string to find out what we need to parse. + */ + for (i = 1; p + i < end; i++) + { + if(p[i] == '-' || p [i] == ':') + { + is_time = p[i] == ':'; + break; + } + } + } + + if (is_time) + { + if (parse_time(p, end - p, &p, tm)) + goto error; + + tm->year = tm->month = tm->day = 0; + tm->time_type = MYSQL_TIMESTAMP_TIME; + return 0; + } + + if (parse_date(p, end - p, &p, tm)) + goto error; + + if (p == end || p[0] != ' ') + { + tm->hour = tm->minute = tm->second = tm->second_part = 0; + tm->time_type = MYSQL_TIMESTAMP_DATE; + return 0; + } + + /* Skip space. */ + p++; + if (parse_time(p, end - p, &p, tm)) + goto error; + + /* In DATETIME, hours must be < 24.*/ + if (tm->hour > 23) + goto error; + + tm->time_type = MYSQL_TIMESTAMP_DATETIME; + return 0; + +error: + memset(tm, 0, sizeof(*tm)); + tm->time_type = MYSQL_TIMESTAMP_ERROR; + return 1; +} + + +static void convert_froma_string(MYSQL_BIND *r_param, char *buffer, size_t len) +{ + int error= 0; + switch (r_param->buffer_type) + { + case MYSQL_TYPE_TINY: + { + longlong val= my_atoll(buffer, buffer + len, &error); + *r_param->error= error ? 1 : r_param->is_unsigned ? NUMERIC_TRUNCATION(val, 0, UINT_MAX8) : NUMERIC_TRUNCATION(val, INT_MIN8, INT_MAX8) || error > 0; + int1store(r_param->buffer, (uchar) val); + r_param->buffer_length= sizeof(uchar); + } + break; + case MYSQL_TYPE_YEAR: + case MYSQL_TYPE_SHORT: + { + longlong val= my_atoll(buffer, buffer + len, &error); + *r_param->error= error ? 1 : r_param->is_unsigned ? NUMERIC_TRUNCATION(val, 0, UINT_MAX16) : NUMERIC_TRUNCATION(val, INT_MIN16, INT_MAX16) || error > 0; + shortstore(r_param->buffer, (short)val); + r_param->buffer_length= sizeof(short); + } + break; + case MYSQL_TYPE_LONG: + { + longlong val= my_atoll(buffer, buffer + len, &error); + *r_param->error=error ? 1 : r_param->is_unsigned ? NUMERIC_TRUNCATION(val, 0, UINT_MAX32) : NUMERIC_TRUNCATION(val, INT_MIN32, INT_MAX32) || error > 0; + longstore(r_param->buffer, (int32)val); + r_param->buffer_length= sizeof(uint32); + } + break; + case MYSQL_TYPE_LONGLONG: + { + longlong val= r_param->is_unsigned ? (longlong)my_atoull(buffer, buffer + len, &error) : my_atoll(buffer, buffer + len, &error); + *r_param->error= error > 0; /* no need to check for truncation */ + longlongstore(r_param->buffer, val); + r_param->buffer_length= sizeof(longlong); + } + break; + case MYSQL_TYPE_DOUBLE: + { + double val= my_atod(buffer, buffer + len, &error); + *r_param->error= error > 0; /* no need to check for truncation */ + doublestore((uchar *)r_param->buffer, val); + r_param->buffer_length= sizeof(double); + } + break; + case MYSQL_TYPE_FLOAT: + { + float val= (float)my_atod(buffer, buffer + len, &error); + *r_param->error= error > 0; /* no need to check for truncation */ + floatstore((uchar *)r_param->buffer, val); + r_param->buffer_length= sizeof(float); + } + break; + case MYSQL_TYPE_TIME: + case MYSQL_TYPE_DATE: + case MYSQL_TYPE_DATETIME: + case MYSQL_TYPE_TIMESTAMP: + { + MYSQL_TIME *tm= (MYSQL_TIME *)r_param->buffer; + str_to_TIME(buffer, len, tm); + break; + } + break; + case MYSQL_TYPE_TINY_BLOB: + case MYSQL_TYPE_MEDIUM_BLOB: + case MYSQL_TYPE_LONG_BLOB: + case MYSQL_TYPE_BLOB: + case MYSQL_TYPE_DECIMAL: + case MYSQL_TYPE_NEWDECIMAL: + default: + { + if (len >= r_param->offset) + { + char *start= buffer + r_param->offset; /* stmt_fetch_column sets offset */ + char *end= buffer + len; + size_t copylen= 0; + + if (start < end) + { + copylen= end - start; + if (r_param->buffer_length) + memcpy(r_param->buffer, start, MIN(copylen, r_param->buffer_length)); + } + if (copylen < r_param->buffer_length) + ((char *)r_param->buffer)[copylen]= 0; + *r_param->error= (copylen > r_param->buffer_length); + + } + *r_param->length= (ulong)len; + } + break; + } +} + +static void convert_from_long(MYSQL_BIND *r_param, const MYSQL_FIELD *field, longlong val, my_bool is_unsigned) +{ + switch (r_param->buffer_type) { + case MYSQL_TYPE_TINY: + *(uchar *)r_param->buffer= (uchar)val; + *r_param->error= r_param->is_unsigned ? NUMERIC_TRUNCATION(val, 0, UINT_MAX8) : NUMERIC_TRUNCATION(val, INT_MIN8, INT_MAX8); + r_param->buffer_length= 1; + break; + case MYSQL_TYPE_SHORT: + case MYSQL_TYPE_YEAR: + shortstore(r_param->buffer, (short)val); + *r_param->error= r_param->is_unsigned ? NUMERIC_TRUNCATION(val, 0, UINT_MAX16) : NUMERIC_TRUNCATION(val, INT_MIN16, INT_MAX16); + r_param->buffer_length= 2; + break; + case MYSQL_TYPE_LONG: + longstore(r_param->buffer, (int32)val); + *r_param->error= r_param->is_unsigned ? NUMERIC_TRUNCATION(val, 0, UINT_MAX32) : NUMERIC_TRUNCATION(val, INT_MIN32, INT_MAX32); + r_param->buffer_length= 4; + break; + case MYSQL_TYPE_LONGLONG: + *r_param->error= (val < 0 && r_param->is_unsigned != is_unsigned); + longlongstore(r_param->buffer, val); + r_param->buffer_length= 8; + break; + case MYSQL_TYPE_DOUBLE: + { + volatile double dbl; + + dbl= (is_unsigned) ? ulonglong2double((ulonglong)val) : (double)val; + doublestore(r_param->buffer, dbl); + + *r_param->error = (dbl != ceil(dbl)) || + (is_unsigned ? (ulonglong )dbl != (ulonglong)val : + (longlong)dbl != (longlong)val); + + r_param->buffer_length= 8; + break; + } + case MYSQL_TYPE_FLOAT: + { + volatile float fval; + fval= is_unsigned ? (float)(ulonglong)(val) : (float)val; + floatstore((uchar *)r_param->buffer, fval); + *r_param->error= (fval != ceilf(fval)) || + (is_unsigned ? (ulonglong)fval != (ulonglong)val : + (longlong)fval != val); + r_param->buffer_length= 4; + } + break; + default: + { + char *buffer; + char *endptr; + uint len; + my_bool zf_truncated= 0; + + buffer= alloca(MAX(field->length, 22)); + endptr= ma_ll2str(val, buffer, is_unsigned ? 10 : -10); + len= (uint)(endptr - buffer); + + /* check if field flag is zerofill */ + if (field->flags & ZEROFILL_FLAG) + { + uint display_width= MAX(field->length, len); + if (display_width < r_param->buffer_length) + { + ma_bmove_upp(buffer + display_width, buffer + len, len); + /* coverity[bad_memset] */ + memset((void*) buffer, (int) '0', display_width - len); + len= display_width; + } + else + zf_truncated= 1; + } + convert_froma_string(r_param, buffer, len); + *r_param->error+= zf_truncated; + } + break; + } +} + + +/* {{{ ps_fetch_null */ +static +void ps_fetch_null(MYSQL_BIND *r_param __attribute__((unused)), + const MYSQL_FIELD * field __attribute__((unused)), + unsigned char **row __attribute__((unused))) +{ + /* do nothing */ +} +/* }}} */ + +#define GET_LVALUE_FROM_ROW(is_unsigned, data, ucast, scast)\ + (is_unsigned) ? (longlong)(ucast) *(longlong *)(data) : (longlong)(scast) *(longlong *)(data) +/* {{{ ps_fetch_int8 */ +static +void ps_fetch_int8(MYSQL_BIND *r_param, const MYSQL_FIELD * const field, + unsigned char **row) +{ + switch(r_param->buffer_type) { + case MYSQL_TYPE_TINY: + ps_fetch_from_1_to_8_bytes(r_param, field, row, 1); + break; + default: + { + uchar val= **row; + longlong lval= field->flags & UNSIGNED_FLAG ? (longlong) val : (longlong)(signed char)val; + convert_from_long(r_param, field, lval, field->flags & UNSIGNED_FLAG); + (*row) += 1; + } + break; + } +} +/* }}} */ + + +/* {{{ ps_fetch_int16 */ +static +void ps_fetch_int16(MYSQL_BIND *r_param, const MYSQL_FIELD * const field, + unsigned char **row) +{ + switch (r_param->buffer_type) { + case MYSQL_TYPE_YEAR: + case MYSQL_TYPE_SHORT: + ps_fetch_from_1_to_8_bytes(r_param, field, row, 2); + break; + default: + { + short sval= sint2korr(*row); + longlong lval= field->flags & UNSIGNED_FLAG ? (longlong)(ushort) sval : (longlong)sval; + convert_from_long(r_param, field, lval, field->flags & UNSIGNED_FLAG); + (*row) += 2; + } + break; + } +} +/* }}} */ + + +/* {{{ ps_fetch_int32 */ +static +void ps_fetch_int32(MYSQL_BIND *r_param, const MYSQL_FIELD * const field, + unsigned char **row) +{ + switch (r_param->buffer_type) { +/* case MYSQL_TYPE_TINY: + ps_fetch_from_1_to_8_bytes(r_param, field, row, 1); + break; + case MYSQL_TYPE_YEAR: + case MYSQL_TYPE_SHORT: + ps_fetch_from_1_to_8_bytes(r_param, field, row, 2); + break; */ + case MYSQL_TYPE_INT24: + case MYSQL_TYPE_LONG: + ps_fetch_from_1_to_8_bytes(r_param, field, row, 4); + break; + default: + { + int32 sval= sint4korr(*row); + longlong lval= field->flags & UNSIGNED_FLAG ? (longlong)(uint32) sval : (longlong)sval; + convert_from_long(r_param, field, lval, field->flags & UNSIGNED_FLAG); + (*row) += 4; + } + break; + } +} +/* }}} */ + + +/* {{{ ps_fetch_int64 */ +static +void ps_fetch_int64(MYSQL_BIND *r_param, const MYSQL_FIELD * const field, + unsigned char **row) +{ + switch(r_param->buffer_type) + { +/* case MYSQL_TYPE_TINY: + ps_fetch_from_1_to_8_bytes(r_param, field, row, 1); + break; + case MYSQL_TYPE_YEAR: + case MYSQL_TYPE_SHORT: + ps_fetch_from_1_to_8_bytes(r_param, field, row, 2); + break; + case MYSQL_TYPE_INT24: + case MYSQL_TYPE_LONG: + ps_fetch_from_1_to_8_bytes(r_param, field, row, 4); + break; */ + case MYSQL_TYPE_LONGLONG: + ps_fetch_from_1_to_8_bytes(r_param, field, row, 8); + break; + default: + { + longlong sval= (longlong)sint8korr(*row); + longlong lval= field->flags & UNSIGNED_FLAG ? (longlong)(ulonglong) sval : (longlong)sval; + convert_from_long(r_param, field, lval, field->flags & UNSIGNED_FLAG); + (*row) += 8; + } + break; + } +} +/* }}} */ + +static void convert_from_float(MYSQL_BIND *r_param, const MYSQL_FIELD *field, float val, int size __attribute__((unused))) +{ + double check_trunc_val= (val > 0) ? floor(val) : -floor(-val); + char *buf= (char *)r_param->buffer; + switch (r_param->buffer_type) + { + case MYSQL_TYPE_TINY: + *buf= (r_param->is_unsigned) ? (uint8)val : (int8)val; + *r_param->error= check_trunc_val != (r_param->is_unsigned ? (double)((uint8)*buf) : + (double)((int8)*buf)); + r_param->buffer_length= 1; + break; + case MYSQL_TYPE_SHORT: + case MYSQL_TYPE_YEAR: + { + if (r_param->is_unsigned) + { + ushort sval= (ushort)val; + shortstore(buf, sval); + *r_param->error= check_trunc_val != (double)sval; + } else { + short sval= (short)val; + shortstore(buf, sval); + *r_param->error= check_trunc_val != (double)sval; + } + r_param->buffer_length= 2; + } + break; + case MYSQL_TYPE_LONG: + { + if (r_param->is_unsigned) + { + uint32 lval= (uint32)val; + longstore(buf, lval); + *r_param->error= (check_trunc_val != (double)lval); + } else { + int32 lval= (int32)val; + longstore(buf, lval); + *r_param->error= (check_trunc_val != (double)lval); + } + r_param->buffer_length= 4; + } + break; + case MYSQL_TYPE_LONGLONG: + { + if (r_param->is_unsigned) + { + ulonglong llval= (ulonglong)val; + longlongstore(buf, llval); + *r_param->error= (check_trunc_val != (double)llval); + } else { + longlong llval= (longlong)val; + longlongstore(buf, llval); + *r_param->error= (check_trunc_val != (double)llval); + } + r_param->buffer_length= 8; + } + break; + case MYSQL_TYPE_DOUBLE: + { + double dval= (double)val; + memcpy(buf, &dval, sizeof(double)); + r_param->buffer_length= 8; + } + break; + default: + { + char buff[MAX_DOUBLE_STRING_REP_LENGTH]; + size_t length; + + length= MIN(MAX_DOUBLE_STRING_REP_LENGTH - 1, r_param->buffer_length); + + if (field->decimals >= NOT_FIXED_DEC) + { + length= ma_gcvt(val, MY_GCVT_ARG_FLOAT, (int)length, buff, NULL); + } + else + { + length= ma_fcvt(val, field->decimals, buff, NULL); + } + + /* check if ZEROFILL flag is active */ + if (field->flags & ZEROFILL_FLAG) + { + /* enough space available ? */ + if (field->length < length || field->length > MAX_DOUBLE_STRING_REP_LENGTH - 1) + break; + ma_bmove_upp(buff + field->length, buff + length, length); + /* coverity[bad_memset] */ + memset((void*) buff, (int) '0', field->length - length); + length= field->length; + } + + convert_froma_string(r_param, buff, length); + } + break; + } +} + +static void convert_from_double(MYSQL_BIND *r_param, const MYSQL_FIELD *field, double val, int size __attribute__((unused))) +{ + double check_trunc_val= (val > 0) ? floor(val) : -floor(-val); + char *buf= (char *)r_param->buffer; + switch (r_param->buffer_type) + { + case MYSQL_TYPE_TINY: + *buf= (r_param->is_unsigned) ? (uint8)val : (int8)val; + *r_param->error= check_trunc_val != (r_param->is_unsigned ? (double)((uint8)*buf) : + (double)((int8)*buf)); + r_param->buffer_length= 1; + break; + case MYSQL_TYPE_SHORT: + case MYSQL_TYPE_YEAR: + { + if (r_param->is_unsigned) + { + ushort sval= (ushort)val; + shortstore(buf, sval); + *r_param->error= check_trunc_val != (double)sval; + } else { + short sval= (short)val; + shortstore(buf, sval); + *r_param->error= check_trunc_val != (double)sval; + } + r_param->buffer_length= 2; + } + break; + case MYSQL_TYPE_LONG: + { + if (r_param->is_unsigned) + { + uint32 lval= (uint32)val; + longstore(buf, lval); + *r_param->error= (check_trunc_val != (double)lval); + } else { + int32 lval= (int32)val; + longstore(buf, lval); + *r_param->error= (check_trunc_val != (double)lval); + } + r_param->buffer_length= 4; + } + break; + case MYSQL_TYPE_LONGLONG: + { + if (r_param->is_unsigned) + { + ulonglong llval= (ulonglong)val; + longlongstore(buf, llval); + *r_param->error= (check_trunc_val != (double)llval); + } else { + longlong llval= (longlong)val; + longlongstore(buf, llval); + *r_param->error= (check_trunc_val != (double)llval); + } + r_param->buffer_length= 8; + } + break; + case MYSQL_TYPE_FLOAT: + { + float fval= (float)val; + memcpy(buf, &fval, sizeof(float)); + *r_param->error= (*(float*)buf != fval); + r_param->buffer_length= 4; + } + break; + default: + { + char buff[MAX_DOUBLE_STRING_REP_LENGTH]; + size_t length; + + length= MIN(MAX_DOUBLE_STRING_REP_LENGTH - 1, r_param->buffer_length); + + if (field->decimals >= NOT_FIXED_DEC) + { + length= ma_gcvt(val, MY_GCVT_ARG_DOUBLE, (int)length, buff, NULL); + } + else + { + length= ma_fcvt(val, field->decimals, buff, NULL); + } + + /* check if ZEROFILL flag is active */ + if (field->flags & ZEROFILL_FLAG) + { + /* enough space available ? */ + if (field->length < length || field->length > MAX_DOUBLE_STRING_REP_LENGTH - 1) + break; + ma_bmove_upp(buff + field->length, buff + length, length); + /* coverity [bad_memset] */ + memset((void*) buff, (int) '0', field->length - length); + length= field->length; + } + convert_froma_string(r_param, buff, length); + } + break; + } +} + + +/* {{{ ps_fetch_double */ +static +void ps_fetch_double(MYSQL_BIND *r_param, const MYSQL_FIELD * field , unsigned char **row) +{ + switch (r_param->buffer_type) + { + case MYSQL_TYPE_DOUBLE: + { + double *value= (double *)r_param->buffer; + float8get(*value, *row); + r_param->buffer_length= 8; + } + break; + default: + { + double value; + float8get(value, *row); + convert_from_double(r_param, field, value, sizeof(double)); + } + break; + } + (*row)+= 8; +} +/* }}} */ + +/* {{{ ps_fetch_float */ +static +void ps_fetch_float(MYSQL_BIND *r_param, const MYSQL_FIELD * field, unsigned char **row) +{ + switch(r_param->buffer_type) + { + case MYSQL_TYPE_FLOAT: + { + float *value= (float *)r_param->buffer; + float4get(*value, *row); + r_param->buffer_length= 4; + *r_param->error= 0; + } + break; + default: + { + float value; + memcpy(&value, *row, sizeof(float)); + float4get(value, (char *)*row); + convert_from_float(r_param, field, value, sizeof(float)); + } + break; + } + (*row)+= 4; +} +/* }}} */ + +static void convert_to_datetime(MYSQL_TIME *t, unsigned char **row, uint len, enum enum_field_types type) +{ + memset(t, 0, sizeof(MYSQL_TIME)); + + /* binary protocol for datetime: + 4-bytes: DATE + 7-bytes: DATE + TIME + >7 bytes: DATE + TIME with second_part + */ + if (len) + { + unsigned char *to= *row; + int has_date= 0; + uint offset= 7; + + if (type == MYSQL_TYPE_TIME) + { + t->neg= to[0]; + t->day= (ulong) sint4korr(to + 1); + t->time_type= MYSQL_TIMESTAMP_TIME; + offset= 8; + to++; + } else + { + t->year= (uint) sint2korr(to); + t->month= (uint) to[2]; + t->day= (uint) to[3]; + t->time_type= MYSQL_TIMESTAMP_DATE; + if (type == MYSQL_TYPE_DATE) + return; + has_date= 1; + } + + if (len > 4) + { + t->hour= (uint) to[4]; + if (type == MYSQL_TYPE_TIME) + t->hour+= t->day * 24; + t->minute= (uint) to[5]; + t->second= (uint) to[6]; + if (has_date) + t->time_type= MYSQL_TIMESTAMP_DATETIME; + } + if (len > offset) + { + t->second_part= (ulong)sint4korr(to+7); + } + } +} + + +/* {{{ ps_fetch_datetime */ +static +void ps_fetch_datetime(MYSQL_BIND *r_param, const MYSQL_FIELD * field, + unsigned char **row) +{ + MYSQL_TIME *t= (MYSQL_TIME *)r_param->buffer; + unsigned int len= net_field_length(row); + + switch (r_param->buffer_type) { + case MYSQL_TYPE_DATETIME: + case MYSQL_TYPE_TIMESTAMP: + convert_to_datetime(t, row, len, field->type); + break; + case MYSQL_TYPE_DATE: + convert_to_datetime(t, row, len, field->type); + break; + case MYSQL_TYPE_TIME: + convert_to_datetime(t, row, len, field->type); + t->year= t->day= t->month= 0; + break; + case MYSQL_TYPE_YEAR: + { + MYSQL_TIME tm; + convert_to_datetime(&tm, row, len, field->type); + shortstore(r_param->buffer, tm.year); + break; + } + default: + { + char dtbuffer[60]; + MYSQL_TIME tm; + size_t length; + convert_to_datetime(&tm, row, len, field->type); + + switch(field->type) { + case MYSQL_TYPE_DATE: + length= sprintf(dtbuffer, "%04u-%02u-%02u", tm.year, tm.month, tm.day); + break; + case MYSQL_TYPE_TIME: + length= sprintf(dtbuffer, "%s%02u:%02u:%02u", (tm.neg ? "-" : ""), tm.hour, tm.minute, tm.second); + if (field->decimals && field->decimals <= 6) + { + char ms[8]; + sprintf(ms, ".%06lu", tm.second_part); + if (field->decimals < 6) + ms[field->decimals + 1]= 0; + length+= strlen(ms); + strcat(dtbuffer, ms); + } + break; + case MYSQL_TYPE_DATETIME: + case MYSQL_TYPE_TIMESTAMP: + length= sprintf(dtbuffer, "%04u-%02u-%02u %02u:%02u:%02u", tm.year, tm.month, tm.day, tm.hour, tm.minute, tm.second); + if (field->decimals && field->decimals <= 6) + { + char ms[8]; + sprintf(ms, ".%06lu", tm.second_part); + if (field->decimals < 6) + ms[field->decimals + 1]= 0; + length+= strlen(ms); + strcat(dtbuffer, ms); + } + break; + default: + dtbuffer[0]= 0; + length= 0; + break; + } + convert_froma_string(r_param, dtbuffer, length); + break; + } + } + (*row) += len; +} +/* }}} */ + +/* {{{ ps_fetch_string */ +static +void ps_fetch_string(MYSQL_BIND *r_param, + const MYSQL_FIELD *field __attribute__((unused)), + unsigned char **row) +{ + /* C-API differs from PHP. While PHP just converts string to string, + C-API needs to convert the string to the defined type with in + the result bind buffer. + */ + ulong field_length= net_field_length(row); + + convert_froma_string(r_param, (char *)*row, field_length); + (*row) += field_length; +} +/* }}} */ + +/* {{{ ps_fetch_bin */ +static +void ps_fetch_bin(MYSQL_BIND *r_param, + const MYSQL_FIELD *field, + unsigned char **row) +{ + if (field->charsetnr == 63) + { + ulong field_length= *r_param->length= net_field_length(row); + uchar *current_pos= (*row) + r_param->offset, + *end= (*row) + field_length; + size_t copylen= 0; + + if (current_pos < end) + { + copylen= end - current_pos; + if (r_param->buffer_length) + memcpy(r_param->buffer, current_pos, MIN(copylen, r_param->buffer_length)); + } + if (copylen < r_param->buffer_length && + (r_param->buffer_type == MYSQL_TYPE_STRING || + r_param->buffer_type == MYSQL_TYPE_JSON)) + ((char *)r_param->buffer)[copylen]= 0; + *r_param->error= copylen > r_param->buffer_length; + (*row)+= field_length; + } + else + ps_fetch_string(r_param, field, row); +} +/* }}} */ + +/* {{{ _mysqlnd_init_ps_subsystem */ +void mysql_init_ps_subsystem(void) +{ + memset(mysql_ps_fetch_functions, 0, sizeof(mysql_ps_fetch_functions)); + mysql_ps_fetch_functions[MYSQL_TYPE_NULL].func= ps_fetch_null; + mysql_ps_fetch_functions[MYSQL_TYPE_NULL].pack_len = 0; + mysql_ps_fetch_functions[MYSQL_TYPE_NULL].max_len = 0; + + mysql_ps_fetch_functions[MYSQL_TYPE_TINY].func = ps_fetch_int8; + mysql_ps_fetch_functions[MYSQL_TYPE_TINY].pack_len = 1; + mysql_ps_fetch_functions[MYSQL_TYPE_TINY].max_len = 4; + + mysql_ps_fetch_functions[MYSQL_TYPE_SHORT].func = ps_fetch_int16; + mysql_ps_fetch_functions[MYSQL_TYPE_SHORT].pack_len = 2; + mysql_ps_fetch_functions[MYSQL_TYPE_SHORT].max_len = 6; + + mysql_ps_fetch_functions[MYSQL_TYPE_YEAR].func = ps_fetch_int16; + mysql_ps_fetch_functions[MYSQL_TYPE_YEAR].pack_len = 2; + mysql_ps_fetch_functions[MYSQL_TYPE_YEAR].max_len = 6; + + mysql_ps_fetch_functions[MYSQL_TYPE_INT24].func = ps_fetch_int32; + mysql_ps_fetch_functions[MYSQL_TYPE_INT24].pack_len = 4; + mysql_ps_fetch_functions[MYSQL_TYPE_INT24].max_len = 9; + + mysql_ps_fetch_functions[MYSQL_TYPE_LONG].func = ps_fetch_int32; + mysql_ps_fetch_functions[MYSQL_TYPE_LONG].pack_len = 4; + mysql_ps_fetch_functions[MYSQL_TYPE_LONG].max_len = 11; + + mysql_ps_fetch_functions[MYSQL_TYPE_LONGLONG].func = ps_fetch_int64; + mysql_ps_fetch_functions[MYSQL_TYPE_LONGLONG].pack_len= 8; + mysql_ps_fetch_functions[MYSQL_TYPE_LONGLONG].max_len = 21; + + mysql_ps_fetch_functions[MYSQL_TYPE_FLOAT].func = ps_fetch_float; + mysql_ps_fetch_functions[MYSQL_TYPE_FLOAT].pack_len = 4; + mysql_ps_fetch_functions[MYSQL_TYPE_FLOAT].max_len = MAX_DOUBLE_STRING_REP_LENGTH; + + mysql_ps_fetch_functions[MYSQL_TYPE_DOUBLE].func = ps_fetch_double; + mysql_ps_fetch_functions[MYSQL_TYPE_DOUBLE].pack_len = 8; + mysql_ps_fetch_functions[MYSQL_TYPE_DOUBLE].max_len = MAX_DOUBLE_STRING_REP_LENGTH; + + mysql_ps_fetch_functions[MYSQL_TYPE_TIME].func = ps_fetch_datetime; + mysql_ps_fetch_functions[MYSQL_TYPE_TIME].pack_len = MYSQL_PS_SKIP_RESULT_W_LEN; + mysql_ps_fetch_functions[MYSQL_TYPE_TIME].max_len = 17; + + mysql_ps_fetch_functions[MYSQL_TYPE_DATE].func = ps_fetch_datetime; + mysql_ps_fetch_functions[MYSQL_TYPE_DATE].pack_len = MYSQL_PS_SKIP_RESULT_W_LEN; + mysql_ps_fetch_functions[MYSQL_TYPE_DATE].max_len = 10; + + mysql_ps_fetch_functions[MYSQL_TYPE_NEWDATE].func = ps_fetch_string; + mysql_ps_fetch_functions[MYSQL_TYPE_NEWDATE].pack_len = MYSQL_PS_SKIP_RESULT_W_LEN; + mysql_ps_fetch_functions[MYSQL_TYPE_NEWDATE].max_len = -1; + + mysql_ps_fetch_functions[MYSQL_TYPE_DATETIME].func = ps_fetch_datetime; + mysql_ps_fetch_functions[MYSQL_TYPE_DATETIME].pack_len= MYSQL_PS_SKIP_RESULT_W_LEN; + mysql_ps_fetch_functions[MYSQL_TYPE_DATETIME].max_len = 30; + + mysql_ps_fetch_functions[MYSQL_TYPE_TIMESTAMP].func = ps_fetch_datetime; + mysql_ps_fetch_functions[MYSQL_TYPE_TIMESTAMP].pack_len= MYSQL_PS_SKIP_RESULT_W_LEN; + mysql_ps_fetch_functions[MYSQL_TYPE_TIMESTAMP].max_len = 30; + + mysql_ps_fetch_functions[MYSQL_TYPE_TINY_BLOB].func = ps_fetch_bin; + mysql_ps_fetch_functions[MYSQL_TYPE_TINY_BLOB].pack_len= MYSQL_PS_SKIP_RESULT_STR; + mysql_ps_fetch_functions[MYSQL_TYPE_TINY_BLOB].max_len = -1; + + mysql_ps_fetch_functions[MYSQL_TYPE_BLOB].func = ps_fetch_bin; + mysql_ps_fetch_functions[MYSQL_TYPE_BLOB].pack_len = MYSQL_PS_SKIP_RESULT_STR; + mysql_ps_fetch_functions[MYSQL_TYPE_BLOB].max_len = -1; + + mysql_ps_fetch_functions[MYSQL_TYPE_MEDIUM_BLOB].func = ps_fetch_bin; + mysql_ps_fetch_functions[MYSQL_TYPE_MEDIUM_BLOB].pack_len= MYSQL_PS_SKIP_RESULT_STR; + mysql_ps_fetch_functions[MYSQL_TYPE_MEDIUM_BLOB].max_len = -1; + + mysql_ps_fetch_functions[MYSQL_TYPE_LONG_BLOB].func = ps_fetch_bin; + mysql_ps_fetch_functions[MYSQL_TYPE_LONG_BLOB].pack_len = MYSQL_PS_SKIP_RESULT_STR; + mysql_ps_fetch_functions[MYSQL_TYPE_LONG_BLOB].max_len = -1; + + mysql_ps_fetch_functions[MYSQL_TYPE_BIT].func = ps_fetch_bin; + mysql_ps_fetch_functions[MYSQL_TYPE_BIT].pack_len = MYSQL_PS_SKIP_RESULT_STR; + mysql_ps_fetch_functions[MYSQL_TYPE_BIT].max_len = -1; + + mysql_ps_fetch_functions[MYSQL_TYPE_VAR_STRING].func = ps_fetch_string; + mysql_ps_fetch_functions[MYSQL_TYPE_VAR_STRING].pack_len = MYSQL_PS_SKIP_RESULT_STR; + mysql_ps_fetch_functions[MYSQL_TYPE_VAR_STRING].max_len = -1; + + mysql_ps_fetch_functions[MYSQL_TYPE_VARCHAR].func = ps_fetch_string; + mysql_ps_fetch_functions[MYSQL_TYPE_VARCHAR].pack_len = MYSQL_PS_SKIP_RESULT_STR; + mysql_ps_fetch_functions[MYSQL_TYPE_VARCHAR].max_len = -1; + + mysql_ps_fetch_functions[MYSQL_TYPE_STRING].func = ps_fetch_string; + mysql_ps_fetch_functions[MYSQL_TYPE_STRING].pack_len = MYSQL_PS_SKIP_RESULT_STR; + mysql_ps_fetch_functions[MYSQL_TYPE_STRING].max_len = -1; + + mysql_ps_fetch_functions[MYSQL_TYPE_JSON].func = ps_fetch_string; + mysql_ps_fetch_functions[MYSQL_TYPE_JSON].pack_len = MYSQL_PS_SKIP_RESULT_STR; + mysql_ps_fetch_functions[MYSQL_TYPE_JSON].max_len = -1; + + mysql_ps_fetch_functions[MYSQL_TYPE_DECIMAL].func = ps_fetch_string; + mysql_ps_fetch_functions[MYSQL_TYPE_DECIMAL].pack_len = MYSQL_PS_SKIP_RESULT_STR; + mysql_ps_fetch_functions[MYSQL_TYPE_DECIMAL].max_len = -1; + + mysql_ps_fetch_functions[MYSQL_TYPE_NEWDECIMAL].func = ps_fetch_string; + mysql_ps_fetch_functions[MYSQL_TYPE_NEWDECIMAL].pack_len = MYSQL_PS_SKIP_RESULT_STR; + mysql_ps_fetch_functions[MYSQL_TYPE_NEWDECIMAL].max_len = -1; + + mysql_ps_fetch_functions[MYSQL_TYPE_ENUM].func = ps_fetch_string; + mysql_ps_fetch_functions[MYSQL_TYPE_ENUM].pack_len = MYSQL_PS_SKIP_RESULT_STR; + mysql_ps_fetch_functions[MYSQL_TYPE_ENUM].max_len = -1; + + mysql_ps_fetch_functions[MYSQL_TYPE_SET].func = ps_fetch_string; + mysql_ps_fetch_functions[MYSQL_TYPE_SET].pack_len = MYSQL_PS_SKIP_RESULT_STR; + mysql_ps_fetch_functions[MYSQL_TYPE_SET].max_len = -1; + + mysql_ps_fetch_functions[MYSQL_TYPE_GEOMETRY].func = ps_fetch_string; + mysql_ps_fetch_functions[MYSQL_TYPE_GEOMETRY].pack_len= MYSQL_PS_SKIP_RESULT_STR; + mysql_ps_fetch_functions[MYSQL_TYPE_GEOMETRY].max_len = -1; + + mysql_ps_subsystem_initialized= 1; +} +/* }}} */ + + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noet sw=4 ts=4 fdm=marker + * vim<600: noet sw=4 ts=4 + */ + diff --git a/vendor/MDBC/libmariadb/ma_string.c b/vendor/MDBC/libmariadb/ma_string.c new file mode 100644 index 00000000..9a62e06e --- /dev/null +++ b/vendor/MDBC/libmariadb/ma_string.c @@ -0,0 +1,163 @@ +/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB + 2016 MariaDB Corporation AB + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + MA 02111-1301, USA */ + +/* + Code for handling strings which can grow dynamically. + Copyright Monty Program KB. + By monty. +*/ + +#include +#include +#include + +my_bool ma_init_dynamic_string(DYNAMIC_STRING *str, const char *init_str, + size_t init_alloc, size_t alloc_increment) +{ + uint length; + + if (!alloc_increment) + alloc_increment=128; + length=1; + if (init_str && (length= (uint) strlen(init_str)+1) < init_alloc) + init_alloc=((length+alloc_increment-1)/alloc_increment)*alloc_increment; + if (!init_alloc) + init_alloc=alloc_increment; + + if (!(str->str=(char*) malloc(init_alloc))) + return(TRUE); + str->length=length-1; + if (init_str) + memcpy(str->str,init_str,length); + str->max_length=init_alloc; + str->alloc_increment=alloc_increment; + return(FALSE); +} + +my_bool ma_dynstr_set(DYNAMIC_STRING *str, const char *init_str) +{ + uint length; + + if (init_str && (length= (uint) strlen(init_str)+1) > str->max_length) + { + str->max_length=((length+str->alloc_increment-1)/str->alloc_increment)* + str->alloc_increment; + if (!str->max_length) + str->max_length=str->alloc_increment; + if (!(str->str=(char*) realloc(str->str,str->max_length))) + return(TRUE); + } + if (init_str) + { + str->length=length-1; + memcpy(str->str,init_str,length); + } + else + str->length=0; + return(FALSE); +} + + +my_bool ma_dynstr_realloc(DYNAMIC_STRING *str, size_t additional_size) +{ + if (!additional_size) return(FALSE); + if (str->length + additional_size > str->max_length) + { + str->max_length=((str->length + additional_size+str->alloc_increment-1)/ + str->alloc_increment)*str->alloc_increment; + if (!(str->str=(char*) realloc(str->str,str->max_length))) + return(TRUE); + } + return(FALSE); +} + + +my_bool ma_dynstr_append(DYNAMIC_STRING *str, const char *append) +{ + return ma_dynstr_append_mem(str,append,strlen(append)); +} + +my_bool ma_dynstr_append_quoted(DYNAMIC_STRING *str, + const char *append, size_t len, + char quote) +{ + size_t additional= str->alloc_increment; + size_t lim= additional; + uint i; + + if (ma_dynstr_realloc(str, len + additional + 2)) + return TRUE; + str->str[str->length++]= quote; + for (i= 0; i < len; i++) + { + register char c= append[i]; + if (c == quote || c == '\\') + { + if (!lim) + { + if (ma_dynstr_realloc(str, additional)) + return TRUE; + lim= additional; + } + lim--; + str->str[str->length++]= '\\'; + } + str->str[str->length++]= c; + } + str->str[str->length++]= quote; + return FALSE; +} + +my_bool ma_dynstr_append_mem(DYNAMIC_STRING *str, const char *append, + size_t length) +{ + char *new_ptr; + if (str->length+length >= str->max_length) + { + size_t new_length=(str->length+length+str->alloc_increment)/ + str->alloc_increment; + new_length*=str->alloc_increment; + if (!(new_ptr=(char*) realloc(str->str,new_length))) + return TRUE; + str->str=new_ptr; + str->max_length=new_length; + } + memcpy(str->str + str->length,append,length); + str->length+=length; + str->str[str->length]=0; /* Safety for C programs */ + return FALSE; +} + + +void ma_dynstr_free(DYNAMIC_STRING *str) +{ + if (str->str) + { + free(str->str); + str->str=0; + } +} + +char *ma_strmake(register char *dst, register const char *src, size_t length) +{ + while (length--) + if (! (*dst++ = *src++)) + return dst-1; + *dst=0; + return dst; +} diff --git a/vendor/MDBC/libmariadb/ma_time.c b/vendor/MDBC/libmariadb/ma_time.c new file mode 100644 index 00000000..460c32d4 --- /dev/null +++ b/vendor/MDBC/libmariadb/ma_time.c @@ -0,0 +1,65 @@ +/**************************************************************************** + Copyright (C) 2013 Monty Program AB + 2016 MariaDB Corporation AB + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not see + or write to the Free Software Foundation, Inc., + 51 Franklin St., Fifth Floor, Boston, MA 02110, USA + + Part of this code includes code from the PHP project which + is freely available from http://www.php.net +*****************************************************************************/ +#include +#include +#include + + +size_t mariadb_time_to_string(const MYSQL_TIME *tm, char *time_str, size_t len, + unsigned int digits) +{ + size_t length; + + if (!time_str || !len) + return 0; + + if (digits == AUTO_SEC_PART_DIGITS) + digits= (tm->second_part) ? SEC_PART_DIGITS : 0; + + switch(tm->time_type) { + case MYSQL_TIMESTAMP_DATE: + length= snprintf(time_str, len, "%04u-%02u-%02u", tm->year, tm->month, tm->day); + digits= 0; + break; + case MYSQL_TIMESTAMP_DATETIME: + length= snprintf(time_str, len, "%04u-%02u-%02u %02u:%02u:%02u", + tm->year, tm->month, tm->day, tm->hour, tm->minute, tm->second); + break; + case MYSQL_TIMESTAMP_TIME: + length= snprintf(time_str, len, "%s%02u:%02u:%02u", + (tm->neg ? "-" : ""), tm->hour, tm->minute, tm->second); + break; + default: + time_str[0]= '\0'; + return 0; + break; + } + if (digits && (len < length)) + { + char helper[16]; + snprintf(helper, 16, ".%%0%du", digits); + length+= snprintf(time_str + length, len - length, helper, digits); + } + return length; +} + diff --git a/vendor/MDBC/libmariadb/ma_tls.c b/vendor/MDBC/libmariadb/ma_tls.c new file mode 100644 index 00000000..3090d49e --- /dev/null +++ b/vendor/MDBC/libmariadb/ma_tls.c @@ -0,0 +1,232 @@ +/************************************************************************************ + Copyright (C) 2014 MariaDB Corporation AB + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not see + or write to the Free Software Foundation, Inc., + 51 Franklin St., Fifth Floor, Boston, MA 02110, USA + + *************************************************************************************/ + +/* + * this is the abstraction layer for communication via SSL. + * The following SSL libraries/variants are currently supported: + * - openssl + * - gnutls + * - schannel (windows only) + * + * Different SSL variants are implemented as plugins + * On Windows schannel is implemented as (standard) + * built-in plugin. + */ + +#ifdef HAVE_TLS + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef HAVE_NONBLOCK +#include +#include +#endif + +/* Errors should be handled via pvio callback function */ +my_bool ma_tls_initialized= FALSE; +unsigned int mariadb_deinitialize_ssl= 1; + +const char *tls_protocol_version[]= + {"SSLv3", "TLSv1.0", "TLSv1.1", "TLSv1.2", "TLSv1.3", "Unknown"}; + +MARIADB_TLS *ma_pvio_tls_init(MYSQL *mysql) +{ + MARIADB_TLS *ctls= NULL; + + if (!ma_tls_initialized) + ma_tls_start(mysql->net.last_error, MYSQL_ERRMSG_SIZE); + + if (!(ctls= (MARIADB_TLS *)calloc(1, sizeof(MARIADB_TLS)))) + { + return NULL; + } + + /* register error routine and methods */ + ctls->pvio= mysql->net.pvio; + if (!(ctls->ssl= ma_tls_init(mysql))) + { + free(ctls); + ctls= NULL; + } + return ctls; +} + +my_bool ma_pvio_tls_connect(MARIADB_TLS *ctls) +{ + my_bool rc; + + if ((rc= ma_tls_connect(ctls))) + ma_tls_close(ctls); + return rc; +} + +ssize_t ma_pvio_tls_read(MARIADB_TLS *ctls, const uchar* buffer, size_t length) +{ + return ma_tls_read(ctls, buffer, length); +} + +ssize_t ma_pvio_tls_write(MARIADB_TLS *ctls, const uchar* buffer, size_t length) +{ + return ma_tls_write(ctls, buffer, length); +} + +my_bool ma_pvio_tls_close(MARIADB_TLS *ctls) +{ + return ma_tls_close(ctls); +} + +int ma_pvio_tls_verify_server_cert(MARIADB_TLS *ctls) +{ + return ma_tls_verify_server_cert(ctls); +} + +const char *ma_pvio_tls_cipher(MARIADB_TLS *ctls) +{ + return ma_tls_get_cipher(ctls); +} + +void ma_pvio_tls_end() +{ + ma_tls_end(); +} + +int ma_pvio_tls_get_protocol_version_id(MARIADB_TLS *ctls) +{ + return ma_tls_get_protocol_version(ctls); +} + +const char *ma_pvio_tls_get_protocol_version(MARIADB_TLS *ctls) +{ + int version; + + version= ma_tls_get_protocol_version(ctls); + if (version < 0 || version > PROTOCOL_MAX) + return tls_protocol_version[PROTOCOL_UNKNOWN]; + return tls_protocol_version[version]; +} + +static signed char ma_hex2int(char c) +{ + if (c >= '0' && c <= '9') + return c - '0'; + if (c >= 'A' && c <= 'F') + return 10 + c - 'A'; + if (c >= 'a' && c <= 'f') + return 10 + c - 'a'; + return -1; +} + +static my_bool ma_pvio_tls_compare_fp(const char *cert_fp, + unsigned int cert_fp_len, + const char *fp, unsigned int fp_len) +{ + char *p= (char *)fp, + *c; + + /* check length */ + if (cert_fp_len != 20) + return 1; + + /* We support two formats: + 2 digits hex numbers, separated by colons (length=59) + 20 * 2 digits hex numbers without separators (length = 40) + */ + if (fp_len != (strchr(fp, ':') ? 59 : 40)) + return 1; + + for(c= (char *)cert_fp; c < cert_fp + cert_fp_len; c++) + { + signed char d1, d2; + if (*p == ':') + p++; + if (p - fp > (int)fp_len -1) + return 1; + if ((d1 = ma_hex2int(*p)) == - 1 || + (d2 = ma_hex2int(*(p+1))) == -1 || + (char)(d1 * 16 + d2) != *c) + return 1; + p+= 2; + } + return 0; +} + +my_bool ma_pvio_tls_check_fp(MARIADB_TLS *ctls, const char *fp, const char *fp_list) +{ + unsigned int cert_fp_len= 64; + char *cert_fp= NULL; + my_bool rc=1; + MYSQL *mysql= ctls->pvio->mysql; + + cert_fp= (char *)malloc(cert_fp_len); + + if ((cert_fp_len= ma_tls_get_finger_print(ctls, cert_fp, cert_fp_len)) < 1) + goto end; + if (fp) + rc= ma_pvio_tls_compare_fp(cert_fp, cert_fp_len, fp, (unsigned int)strlen(fp)); + else if (fp_list) + { + MA_FILE *fp; + char buff[255]; + + if (!(fp = ma_open(fp_list, "r", mysql))) + goto end; + + while (ma_gets(buff, sizeof(buff)-1, fp)) + { + /* remove trailing new line character */ + char *pos= strchr(buff, '\r'); + if (!pos) + pos= strchr(buff, '\n'); + if (pos) + *pos= '\0'; + + if (!ma_pvio_tls_compare_fp(cert_fp, cert_fp_len, buff, (unsigned int)strlen(buff))) + { + /* finger print is valid: close file and exit */ + ma_close(fp); + rc= 0; + goto end; + } + } + + /* No finger print matched - close file and return error */ + ma_close(fp); + } + +end: + if (cert_fp) + free(cert_fp); + if (rc) + { + my_set_error(mysql, CR_SSL_CONNECTION_ERROR, SQLSTATE_UNKNOWN, + ER(CR_SSL_CONNECTION_ERROR), + "Fingerprint verification of server certificate failed"); + } + return rc; +} +#endif /* HAVE_TLS */ diff --git a/vendor/MDBC/libmariadb/mariadb_async.c b/vendor/MDBC/libmariadb/mariadb_async.c new file mode 100644 index 00000000..8e5d77b1 --- /dev/null +++ b/vendor/MDBC/libmariadb/mariadb_async.c @@ -0,0 +1,1946 @@ +/* Copyright (C) 2012 MariaDB Services and Kristian Nielsen + 2015 MariaDB Corporation + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +*/ + +/* + MySQL non-blocking client library functions. +*/ + +#include "ma_global.h" +#include "ma_sys.h" +#include "mysql.h" +#include "errmsg.h" +#ifndef LIBMARIADB +#include "sql_common.h" +#else +#include "ma_common.h" +#endif +#include "ma_context.h" +#include "ma_pvio.h" +#include "mariadb_async.h" +#include + + +#ifdef _WIN32 +/* + Windows does not support MSG_DONTWAIT for send()/recv(). So we need to ensure + that the socket is non-blocking at the start of every operation. +*/ +#define WIN_SET_NONBLOCKING(mysql) do { \ + my_bool old_mode; \ + if ((mysql)->net.pvio) ma_pvio_blocking((mysql)->net.pvio, FALSE, &old_mode); \ + } while(0); +#else +#define WIN_SET_NONBLOCKING(mysql) +#endif + +extern void mysql_close_slow_part(MYSQL *mysql); + + +void +my_context_install_suspend_resume_hook(struct mysql_async_context *b, + void (*hook)(my_bool, void *), + void *user_data) +{ + b->suspend_resume_hook= hook; + b->suspend_resume_hook_user_data= user_data; +} + + +/* Asynchronous connect(); socket must already be set non-blocking. */ +int +my_connect_async(MARIADB_PVIO *pvio, + const struct sockaddr *name, uint namelen, int vio_timeout) +{ + int res; + size_socket s_err_size; + struct mysql_async_context *b= pvio->mysql->options.extension->async_context; + my_socket sock; + + ma_pvio_get_handle(pvio, &sock); + + /* Make the socket non-blocking. */ + ma_pvio_blocking(pvio, 0, 0); + + b->events_to_wait_for= 0; + /* + Start to connect asynchronously. + If this will block, we suspend the call and return control to the + application context. The application will then resume us when the socket + polls ready for write, indicating that the connection attempt completed. + */ + res= connect(sock, name, namelen); + if (res != 0) + { +#ifdef _WIN32 + int wsa_err= WSAGetLastError(); + if (wsa_err != WSAEWOULDBLOCK) + return res; + b->events_to_wait_for|= MYSQL_WAIT_EXCEPT; +#else + int err= errno; + if (err != EINPROGRESS && err != EALREADY && err != EAGAIN) + return res; +#endif + b->events_to_wait_for|= MYSQL_WAIT_WRITE; + if (vio_timeout >= 0) + { + b->timeout_value= vio_timeout; + b->events_to_wait_for|= MYSQL_WAIT_TIMEOUT; + } + else + b->timeout_value= 0; + if (b->suspend_resume_hook) + (*b->suspend_resume_hook)(TRUE, b->suspend_resume_hook_user_data); + my_context_yield(&b->async_context); + if (b->suspend_resume_hook) + (*b->suspend_resume_hook)(FALSE, b->suspend_resume_hook_user_data); + if (b->events_occured & MYSQL_WAIT_TIMEOUT) + return -1; + + s_err_size= sizeof(res); + if (getsockopt(sock, SOL_SOCKET, SO_ERROR, (char*) &res, &s_err_size) != 0) + return -1; + if (res) + { + errno= res; + return -1; + } + } + return res; +} + +#define IS_BLOCKING_ERROR() \ + IF_WIN(WSAGetLastError() != WSAEWOULDBLOCK, \ + (errno != EAGAIN && errno != EINTR)) + +#ifdef _AIX +#ifndef MSG_DONTWAIT +#define MSG_DONTWAIT 0 +#endif +#endif + +#ifdef HAVE_TLS_FIXME +static my_bool +my_ssl_async_check_result(int res, struct mysql_async_context *b, MARIADB_SSL *cssl) +{ + int ssl_err; + b->events_to_wait_for= 0; + if (res >= 0) + return 1; + ssl_err= SSL_get_error(ssl, res); + if (ssl_err == SSL_ERROR_WANT_READ) + b->events_to_wait_for|= MYSQL_WAIT_READ; + else if (ssl_err == SSL_ERROR_WANT_WRITE) + b->events_to_wait_for|= MYSQL_WAIT_WRITE; + else + return 1; + if (b->suspend_resume_hook) + (*b->suspend_resume_hook)(TRUE, b->suspend_resume_hook_user_data); + my_context_yield(&b->async_context); + if (b->suspend_resume_hook) + (*b->suspend_resume_hook)(FALSE, b->suspend_resume_hook_user_data); + return 0; +} + +int +my_ssl_read_async(struct mysql_async_context *b, SSL *ssl, + void *buf, int size) +{ + int res; + + for (;;) + { + res= SSL_read(ssl, buf, size); + if (my_ssl_async_check_result(res, b, ssl)) + return res; + } +} + +int +my_ssl_write_async(struct mysql_async_context *b, SSL *ssl, + const void *buf, int size) +{ + int res; + + for (;;) + { + res= SSL_write(ssl, buf, size); + if (my_ssl_async_check_result(res, b, ssl)) + return res; + } +} +#endif /* HAVE_OPENSSL */ + + + + +/* + Now create non-blocking definitions for all the calls that may block. + + Each call FOO gives rise to FOO_start() that prepares the MYSQL object for + doing non-blocking calls that can suspend operation mid-way, and then starts + the call itself. And a FOO_start_internal trampoline to assist with running + the real call in a co-routine that can be suspended. And a FOO_cont() that + can continue a suspended operation. +*/ + +#define MK_ASYNC_INTERNAL_BODY(call, invoke_args, mysql_val, ret_type, ok_val)\ + struct call ## _params *parms= (struct call ## _params *)d; \ + ret_type ret; \ + struct mysql_async_context *b= \ + (mysql_val)->options.extension->async_context; \ + \ + ret= call invoke_args; \ + b->ret_result. ok_val = ret; \ + b->events_to_wait_for= 0; + +#define MK_ASYNC_START_BODY(call, mysql_val, parms_assign, err_val, ok_val, extra1) \ + int res; \ + struct mysql_async_context *b; \ + struct call ## _params parms; \ + \ + extra1 \ + b= mysql_val->options.extension->async_context; \ + parms_assign \ + \ + b->active= 1; \ + res= my_context_spawn(&b->async_context, call ## _start_internal, &parms); \ + b->active= b->suspended= 0; \ + if (res > 0) \ + { \ + /* Suspended. */ \ + b->suspended= 1; \ + return b->events_to_wait_for; \ + } \ + if (res < 0) \ + { \ + set_mariadb_error((mysql_val), CR_OUT_OF_MEMORY, unknown_sqlstate); \ + *ret= err_val; \ + } \ + else \ + *ret= b->ret_result. ok_val; \ + return 0; + +#define MK_ASYNC_CONT_BODY(mysql_val, err_val, ok_val) \ + int res; \ + struct mysql_async_context *b= \ + (mysql_val)->options.extension->async_context; \ + if (!b->suspended) \ + { \ + set_mariadb_error((mysql_val), CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate); \ + *ret= err_val; \ + return 0; \ + } \ + \ + b->active= 1; \ + b->events_occured= ready_status; \ + res= my_context_continue(&b->async_context); \ + b->active= 0; \ + if (res > 0) \ + return b->events_to_wait_for; /* (Still) suspended */ \ + b->suspended= 0; \ + if (res < 0) \ + { \ + set_mariadb_error((mysql_val), CR_OUT_OF_MEMORY, unknown_sqlstate); \ + *ret= err_val; \ + } \ + else \ + *ret= b->ret_result. ok_val; /* Finished. */ \ + return 0; + +#define MK_ASYNC_INTERNAL_BODY_VOID_RETURN(call, invoke_args, mysql_val) \ + struct call ## _params *parms= (struct call ## _params *)d; \ + struct mysql_async_context *b= \ + (mysql_val)->options.extension->async_context; \ + \ + call invoke_args; \ + b->events_to_wait_for= 0; + +#define MK_ASYNC_START_BODY_VOID_RETURN(call, mysql_val, parms_assign, extra1)\ + int res; \ + struct mysql_async_context *b; \ + struct call ## _params parms; \ + \ + extra1 \ + b= mysql_val->options.extension->async_context; \ + parms_assign \ + \ + b->active= 1; \ + res= my_context_spawn(&b->async_context, call ## _start_internal, &parms); \ + b->active= b->suspended= 0; \ + if (res > 0) \ + { \ + /* Suspended. */ \ + b->suspended= 1; \ + return b->events_to_wait_for; \ + } \ + if (res < 0) \ + set_mariadb_error((mysql_val), CR_OUT_OF_MEMORY, unknown_sqlstate); \ + return 0; + +#define MK_ASYNC_CONT_BODY_VOID_RETURN(mysql_val) \ + int res; \ + struct mysql_async_context *b= \ + (mysql_val)->options.extension->async_context; \ + if (!b->suspended) \ + { \ + set_mariadb_error((mysql_val), CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate); \ + return 0; \ + } \ + \ + b->active= 1; \ + b->events_occured= ready_status; \ + res= my_context_continue(&b->async_context); \ + b->active= 0; \ + if (res > 0) \ + return b->events_to_wait_for; /* (Still) suspended */ \ + b->suspended= 0; \ + if (res < 0) \ + set_mariadb_error((mysql_val), CR_OUT_OF_MEMORY, unknown_sqlstate); \ + return 0; + + +/* Structure used to pass parameters from mysql_real_connect_start(). */ +struct mysql_real_connect_params { + MYSQL *mysql; + const char *host; + const char *user; + const char *passwd; + const char *db; + unsigned int port; + const char *unix_socket; + unsigned long client_flags; +}; +static void +mysql_real_connect_start_internal(void *d) +{ +MK_ASYNC_INTERNAL_BODY( + mysql_real_connect, + (parms->mysql, parms->host, parms->user, parms->passwd, parms->db, + parms->port, parms->unix_socket, parms->client_flags), + parms->mysql, + MYSQL *, + r_ptr) +} +int STDCALL +mysql_real_connect_start(MYSQL **ret, MYSQL *mysql, const char *host, + const char *user, const char *passwd, const char *db, + unsigned int port, const char *unix_socket, + unsigned long client_flags) +{ +MK_ASYNC_START_BODY( + mysql_real_connect, + mysql, + { + parms.mysql= mysql; + parms.host= host; + parms.user= user; + parms.passwd= passwd; + parms.db= db; + parms.port= port; + parms.unix_socket= unix_socket; + parms.client_flags= client_flags | CLIENT_REMEMBER_OPTIONS; + }, + NULL, + r_ptr, + /* Nothing */) +} +int STDCALL +mysql_real_connect_cont(MYSQL **ret, MYSQL *mysql, int ready_status) +{ +MK_ASYNC_CONT_BODY( + mysql, + NULL, + r_ptr) +} + +/* Structure used to pass parameters from mysql_real_query_start(). */ +struct mysql_real_query_params { + MYSQL *mysql; + const char *stmt_str; + unsigned long length; +}; +static void +mysql_real_query_start_internal(void *d) +{ +MK_ASYNC_INTERNAL_BODY( + mysql_real_query, + (parms->mysql, parms->stmt_str, parms->length), + parms->mysql, + int, + r_int) +} +int STDCALL +mysql_real_query_start(int *ret, MYSQL *mysql, const char *stmt_str, unsigned long length) +{ + int res; + struct mysql_async_context *b; + struct mysql_real_query_params parms; + + b= mysql->options.extension->async_context; + { + WIN_SET_NONBLOCKING(mysql) + parms.mysql= mysql; + parms.stmt_str= stmt_str; + parms.length= length; + } + + b->active= 1; + res= my_context_spawn(&b->async_context, mysql_real_query_start_internal, &parms); + b->active= b->suspended= 0; + if (res > 0) + { + /* Suspended. */ + b->suspended= 1; + return b->events_to_wait_for; + } + if (res < 0) + { + set_mariadb_error((mysql), CR_OUT_OF_MEMORY, unknown_sqlstate); + *ret= 1; + } + else + *ret= b->ret_result.r_int; + return 0; + +} +int STDCALL +mysql_real_query_cont(int *ret, MYSQL *mysql, int ready_status) +{ +MK_ASYNC_CONT_BODY( + mysql, + 1, + r_int) +} + +/* Structure used to pass parameters from mysql_fetch_row_start(). */ +struct mysql_fetch_row_params { + MYSQL_RES *result; +}; +static void +mysql_fetch_row_start_internal(void *d) +{ +MK_ASYNC_INTERNAL_BODY( + mysql_fetch_row, + (parms->result), + parms->result->handle, + MYSQL_ROW, + r_ptr) +} +int STDCALL +mysql_fetch_row_start(MYSQL_ROW *ret, MYSQL_RES *result) +{ +MK_ASYNC_START_BODY( + mysql_fetch_row, + result->handle, + { + WIN_SET_NONBLOCKING(result->handle) + parms.result= result; + }, + NULL, + r_ptr, + /* + If we already fetched all rows from server (eg. mysql_store_result()), + then result->handle will be NULL and we cannot suspend. But that is fine, + since in this case mysql_fetch_row cannot block anyway. Just return + directly. + */ + if (!result->handle) + { + *ret= mysql_fetch_row(result); + return 0; + }) +} +int STDCALL +mysql_fetch_row_cont(MYSQL_ROW *ret, MYSQL_RES *result, int ready_status) +{ +MK_ASYNC_CONT_BODY( + result->handle, + NULL, + r_ptr) +} + +/* Structure used to pass parameters from mysql_set_character_set_start(). */ +struct mysql_set_character_set_params { + MYSQL *mysql; + const char *csname; +}; +static void +mysql_set_character_set_start_internal(void *d) +{ +MK_ASYNC_INTERNAL_BODY( + mysql_set_character_set, + (parms->mysql, parms->csname), + parms->mysql, + int, + r_int) +} +int STDCALL +mysql_set_character_set_start(int *ret, MYSQL *mysql, const char *csname) +{ +MK_ASYNC_START_BODY( + mysql_set_character_set, + mysql, + { + WIN_SET_NONBLOCKING(mysql) + parms.mysql= mysql; + parms.csname= csname; + }, + 1, + r_int, + /* Nothing */) +} +int STDCALL +mysql_set_character_set_cont(int *ret, MYSQL *mysql, int ready_status) +{ +MK_ASYNC_CONT_BODY( + mysql, + 1, + r_int) +} + +/* Structure used to pass parameters from mysql_sekect_db_start(). */ +struct mysql_select_db_params { + MYSQL *mysql; + const char *db; +}; +static void +mysql_select_db_start_internal(void *d) +{ +MK_ASYNC_INTERNAL_BODY( + mysql_select_db, + (parms->mysql, parms->db), + parms->mysql, + int, + r_int) +} +int STDCALL +mysql_select_db_start(int *ret, MYSQL *mysql, const char *db) +{ +MK_ASYNC_START_BODY( + mysql_select_db, + mysql, + { + WIN_SET_NONBLOCKING(mysql) + parms.mysql= mysql; + parms.db= db; + }, + 1, + r_int, + /* Nothing */) +} +int STDCALL +mysql_select_db_cont(int *ret, MYSQL *mysql, int ready_status) +{ +MK_ASYNC_CONT_BODY( + mysql, + 1, + r_int) +} + +/* Structure used to pass parameters from mysql_send_query_start(). */ +struct mysql_send_query_params { + MYSQL *mysql; + const char *q; + unsigned long length; +}; +static void +mysql_send_query_start_internal(void *d) +{ +MK_ASYNC_INTERNAL_BODY( + mysql_send_query, + (parms->mysql, parms->q, parms->length), + parms->mysql, + int, + r_int) +} +int STDCALL +mysql_send_query_start(int *ret, MYSQL *mysql, const char *q, unsigned long length) +{ +MK_ASYNC_START_BODY( + mysql_send_query, + mysql, + { + WIN_SET_NONBLOCKING(mysql) + parms.mysql= mysql; + parms.q= q; + parms.length= length; + }, + 1, + r_int, + /* Nothing */) +} +int STDCALL +mysql_send_query_cont(int *ret, MYSQL *mysql, int ready_status) +{ +MK_ASYNC_CONT_BODY( + mysql, + 1, + r_int) +} + +/* Structure used to pass parameters from mysql_store_result_start(). */ +struct mysql_store_result_params { + MYSQL *mysql; +}; +static void +mysql_store_result_start_internal(void *d) +{ +MK_ASYNC_INTERNAL_BODY( + mysql_store_result, + (parms->mysql), + parms->mysql, + MYSQL_RES *, + r_ptr) +} +int STDCALL +mysql_store_result_start(MYSQL_RES **ret, MYSQL *mysql) +{ +MK_ASYNC_START_BODY( + mysql_store_result, + mysql, + { + WIN_SET_NONBLOCKING(mysql) + parms.mysql= mysql; + }, + NULL, + r_ptr, + /* Nothing */) +} +int STDCALL +mysql_store_result_cont(MYSQL_RES **ret, MYSQL *mysql, int ready_status) +{ +MK_ASYNC_CONT_BODY( + mysql, + NULL, + r_ptr) +} + +/* Structure used to pass parameters from mysql_free_result_start(). */ +struct mysql_free_result_params { + MYSQL_RES *result; +}; +static void +mysql_free_result_start_internal(void *d) +{ +MK_ASYNC_INTERNAL_BODY_VOID_RETURN( + mysql_free_result, + (parms->result), + parms->result->handle) +} +int STDCALL +mysql_free_result_start(MYSQL_RES *result) +{ +MK_ASYNC_START_BODY_VOID_RETURN( + mysql_free_result, + result->handle, + { + WIN_SET_NONBLOCKING(result->handle) + parms.result= result; + }, + /* + mysql_free_result() can have NULL in result->handle (this happens when all + rows have been fetched and mysql_fetch_row() returned NULL.) + So we cannot suspend, but it does not matter, as in this case + mysql_free_result() cannot block. + It is also legitimate to have NULL result, which will do nothing. + */ + if (!result || !result->handle) + { + mysql_free_result(result); + return 0; + }) +} +int STDCALL +mysql_free_result_cont(MYSQL_RES *result, int ready_status) +{ +MK_ASYNC_CONT_BODY_VOID_RETURN(result->handle) +} + +/* Structure used to pass parameters from mysql_close_slow_part_start(). */ +struct mysql_close_slow_part_params { + MYSQL *sock; +}; +/* + We need special handling for mysql_close(), as the first part may block, + while the last part needs to free our extra library context stack. + + So we do the first part (mysql_close_slow_part()) non-blocking, but the last + part blocking. +*/ +static void +mysql_close_slow_part_start_internal(void *d) +{ +MK_ASYNC_INTERNAL_BODY_VOID_RETURN( + mysql_close_slow_part, + (parms->sock), + parms->sock) +} + +int STDCALL +mysql_close_slow_part_start(MYSQL *sock) +{ +MK_ASYNC_START_BODY_VOID_RETURN( + mysql_close_slow_part, + sock, + { + WIN_SET_NONBLOCKING(sock) + parms.sock= sock; + }, + /* Nothing */) +} +int STDCALL +mysql_close_slow_part_cont(MYSQL *sock, int ready_status) +{ +MK_ASYNC_CONT_BODY_VOID_RETURN(sock) +} +int STDCALL +mysql_close_start(MYSQL *sock) +{ + int res; + + /* It is legitimate to have NULL sock argument, which will do nothing. */ + if (sock && sock->net.pvio) + { + res= mysql_close_slow_part_start(sock); + /* If we need to block, return now and do the rest in mysql_close_cont(). */ + if (res) + return res; + } + mysql_close(sock); + return 0; +} +int STDCALL +mysql_close_cont(MYSQL *sock, int ready_status) +{ + int res; + + res= mysql_close_slow_part_cont(sock, ready_status); + if (res) + return res; + mysql_close(sock); + return 0; +} + +/* + These following are not available inside the server (neither blocking or + non-blocking). +*/ +#ifndef MYSQL_SERVER +/* Structure used to pass parameters from mysql_change_user_start(). */ +struct mysql_change_user_params { + MYSQL *mysql; + const char *user; + const char *passwd; + const char *db; +}; +static void +mysql_change_user_start_internal(void *d) +{ +MK_ASYNC_INTERNAL_BODY( + mysql_change_user, + (parms->mysql, parms->user, parms->passwd, parms->db), + parms->mysql, + my_bool, + r_my_bool) +} +int STDCALL +mysql_change_user_start(my_bool *ret, MYSQL *mysql, const char *user, const char *passwd, const char *db) +{ +MK_ASYNC_START_BODY( + mysql_change_user, + mysql, + { + WIN_SET_NONBLOCKING(mysql) + parms.mysql= mysql; + parms.user= user; + parms.passwd= passwd; + parms.db= db; + }, + TRUE, + r_my_bool, + /* Nothing */) +} +int STDCALL +mysql_change_user_cont(my_bool *ret, MYSQL *mysql, int ready_status) +{ +MK_ASYNC_CONT_BODY( + mysql, + TRUE, + r_my_bool) +} + +/* Structure used to pass parameters from mysql_query_start(). */ +struct mysql_query_params { + MYSQL *mysql; + const char *q; +}; +static void +mysql_query_start_internal(void *d) +{ +MK_ASYNC_INTERNAL_BODY( + mysql_query, + (parms->mysql, parms->q), + parms->mysql, + int, + r_int) +} +int STDCALL +mysql_query_start(int *ret, MYSQL *mysql, const char *q) +{ +MK_ASYNC_START_BODY( + mysql_query, + mysql, + { + WIN_SET_NONBLOCKING(mysql) + parms.mysql= mysql; + parms.q= q; + }, + 1, + r_int, + /* Nothing */) +} +int STDCALL +mysql_query_cont(int *ret, MYSQL *mysql, int ready_status) +{ +MK_ASYNC_CONT_BODY( + mysql, + 1, + r_int) +} + +/* Structure used to pass parameters from mysql_shutdown_start(). */ +struct mysql_shutdown_params { + MYSQL *mysql; + enum mysql_enum_shutdown_level shutdown_level; +}; +static void +mysql_shutdown_start_internal(void *d) +{ +MK_ASYNC_INTERNAL_BODY( + mysql_shutdown, + (parms->mysql, parms->shutdown_level), + parms->mysql, + int, + r_int) +} +int STDCALL +mysql_shutdown_start(int *ret, MYSQL *mysql, enum mysql_enum_shutdown_level shutdown_level) +{ +MK_ASYNC_START_BODY( + mysql_shutdown, + mysql, + { + WIN_SET_NONBLOCKING(mysql) + parms.mysql= mysql; + parms.shutdown_level= shutdown_level; + }, + 1, + r_int, + /* Nothing */) +} +int STDCALL +mysql_shutdown_cont(int *ret, MYSQL *mysql, int ready_status) +{ +MK_ASYNC_CONT_BODY( + mysql, + 1, + r_int) +} + +/* Structure used to pass parameters from mysql_dump_debug_info_start(). */ +struct mysql_dump_debug_info_params { + MYSQL *mysql; +}; +static void +mysql_dump_debug_info_start_internal(void *d) +{ +MK_ASYNC_INTERNAL_BODY( + mysql_dump_debug_info, + (parms->mysql), + parms->mysql, + int, + r_int) +} +int STDCALL +mysql_dump_debug_info_start(int *ret, MYSQL *mysql) +{ +MK_ASYNC_START_BODY( + mysql_dump_debug_info, + mysql, + { + WIN_SET_NONBLOCKING(mysql) + parms.mysql= mysql; + }, + 1, + r_int, + /* Nothing */) +} +int STDCALL +mysql_dump_debug_info_cont(int *ret, MYSQL *mysql, int ready_status) +{ +MK_ASYNC_CONT_BODY( + mysql, + 1, + r_int) +} + +/* Structure used to pass parameters from mysql_refresh_start(). */ +struct mysql_refresh_params { + MYSQL *mysql; + unsigned int refresh_options; +}; +static void +mysql_refresh_start_internal(void *d) +{ +MK_ASYNC_INTERNAL_BODY( + mysql_refresh, + (parms->mysql, parms->refresh_options), + parms->mysql, + int, + r_int) +} +int STDCALL +mysql_refresh_start(int *ret, MYSQL *mysql, unsigned int refresh_options) +{ +MK_ASYNC_START_BODY( + mysql_refresh, + mysql, + { + WIN_SET_NONBLOCKING(mysql) + parms.mysql= mysql; + parms.refresh_options= refresh_options; + }, + 1, + r_int, + /* Nothing */) +} +int STDCALL +mysql_refresh_cont(int *ret, MYSQL *mysql, int ready_status) +{ +MK_ASYNC_CONT_BODY( + mysql, + 1, + r_int) +} + +/* Structure used to pass parameters from mysql_kill_start(). */ +struct mysql_kill_params { + MYSQL *mysql; + unsigned long pid; +}; +static void +mysql_kill_start_internal(void *d) +{ +MK_ASYNC_INTERNAL_BODY( + mysql_kill, + (parms->mysql, parms->pid), + parms->mysql, + int, + r_int) +} +int STDCALL +mysql_kill_start(int *ret, MYSQL *mysql, unsigned long pid) +{ +MK_ASYNC_START_BODY( + mysql_kill, + mysql, + { + WIN_SET_NONBLOCKING(mysql) + parms.mysql= mysql; + parms.pid= pid; + }, + 1, + r_int, + /* Nothing */) +} +int STDCALL +mysql_kill_cont(int *ret, MYSQL *mysql, int ready_status) +{ +MK_ASYNC_CONT_BODY( + mysql, + 1, + r_int) +} + +/* Structure used to pass parameters from mysql_set_server_option_start(). */ +struct mysql_set_server_option_params { + MYSQL *mysql; + enum enum_mysql_set_option option; +}; +static void +mysql_set_server_option_start_internal(void *d) +{ +MK_ASYNC_INTERNAL_BODY( + mysql_set_server_option, + (parms->mysql, parms->option), + parms->mysql, + int, + r_int) +} +int STDCALL +mysql_set_server_option_start(int *ret, MYSQL *mysql, + enum enum_mysql_set_option option) +{ +MK_ASYNC_START_BODY( + mysql_set_server_option, + mysql, + { + WIN_SET_NONBLOCKING(mysql) + parms.mysql= mysql; + parms.option= option; + }, + 1, + r_int, + /* Nothing */) +} +int STDCALL +mysql_set_server_option_cont(int *ret, MYSQL *mysql, int ready_status) +{ +MK_ASYNC_CONT_BODY( + mysql, + 1, + r_int) +} + +/* Structure used to pass parameters from mysql_ping_start(). */ +struct mysql_ping_params { + MYSQL *mysql; +}; +static void +mysql_ping_start_internal(void *d) +{ +MK_ASYNC_INTERNAL_BODY( + mysql_ping, + (parms->mysql), + parms->mysql, + int, + r_int) +} +int STDCALL +mysql_ping_start(int *ret, MYSQL *mysql) +{ +MK_ASYNC_START_BODY( + mysql_ping, + mysql, + { + WIN_SET_NONBLOCKING(mysql) + parms.mysql= mysql; + }, + 1, + r_int, + /* Nothing */) +} +int STDCALL +mysql_ping_cont(int *ret, MYSQL *mysql, int ready_status) +{ +MK_ASYNC_CONT_BODY( + mysql, + 1, + r_int) +} + +/* Structure used to pass parameters from mysql_reset_connection_start(). */ +struct mysql_reset_connection_params { + MYSQL *mysql; +}; +static void +mysql_reset_connection_start_internal(void *d) +{ +MK_ASYNC_INTERNAL_BODY( + mysql_reset_connection, + (parms->mysql), + parms->mysql, + int, + r_int) +} +int STDCALL +mysql_reset_connection_start(int *ret, MYSQL *mysql) +{ +MK_ASYNC_START_BODY( + mysql_reset_connection, + mysql, + { + WIN_SET_NONBLOCKING(mysql) + parms.mysql= mysql; + }, + 1, + r_int, + /* Nothing */) +} +int STDCALL +mysql_reset_connection_cont(int *ret, MYSQL *mysql, int ready_status) +{ +MK_ASYNC_CONT_BODY( + mysql, + 1, + r_int) +} + +/* Structure used to pass parameters from mysql_stat_start(). */ +struct mysql_stat_params { + MYSQL *mysql; +}; +static void +mysql_stat_start_internal(void *d) +{ +MK_ASYNC_INTERNAL_BODY( + mysql_stat, + (parms->mysql), + parms->mysql, + const char *, + r_const_ptr) +} +int STDCALL +mysql_stat_start(const char **ret, MYSQL *mysql) +{ +MK_ASYNC_START_BODY( + mysql_stat, + mysql, + { + WIN_SET_NONBLOCKING(mysql) + parms.mysql= mysql; + }, + NULL, + r_const_ptr, + /* Nothing */) +} +int STDCALL +mysql_stat_cont(const char **ret, MYSQL *mysql, int ready_status) +{ +MK_ASYNC_CONT_BODY( + mysql, + NULL, + r_const_ptr) +} + +/* Structure used to pass parameters from mysql_list_dbs_start(). */ +struct mysql_list_dbs_params { + MYSQL *mysql; + const char *wild; +}; +static void +mysql_list_dbs_start_internal(void *d) +{ +MK_ASYNC_INTERNAL_BODY( + mysql_list_dbs, + (parms->mysql, parms->wild), + parms->mysql, + MYSQL_RES *, + r_ptr) +} +int STDCALL +mysql_list_dbs_start(MYSQL_RES **ret, MYSQL *mysql, const char *wild) +{ +MK_ASYNC_START_BODY( + mysql_list_dbs, + mysql, + { + WIN_SET_NONBLOCKING(mysql) + parms.mysql= mysql; + parms.wild= wild; + }, + NULL, + r_ptr, + /* Nothing */) +} +int STDCALL +mysql_list_dbs_cont(MYSQL_RES **ret, MYSQL *mysql, int ready_status) +{ +MK_ASYNC_CONT_BODY( + mysql, + NULL, + r_ptr) +} + +/* Structure used to pass parameters from mysql_list_tables_start(). */ +struct mysql_list_tables_params { + MYSQL *mysql; + const char *wild; +}; +static void +mysql_list_tables_start_internal(void *d) +{ +MK_ASYNC_INTERNAL_BODY( + mysql_list_tables, + (parms->mysql, parms->wild), + parms->mysql, + MYSQL_RES *, + r_ptr) +} +int STDCALL +mysql_list_tables_start(MYSQL_RES **ret, MYSQL *mysql, const char *wild) +{ +MK_ASYNC_START_BODY( + mysql_list_tables, + mysql, + { + WIN_SET_NONBLOCKING(mysql) + parms.mysql= mysql; + parms.wild= wild; + }, + NULL, + r_ptr, + /* Nothing */) +} +int STDCALL +mysql_list_tables_cont(MYSQL_RES **ret, MYSQL *mysql, int ready_status) +{ +MK_ASYNC_CONT_BODY( + mysql, + NULL, + r_ptr) +} + +/* Structure used to pass parameters from mysql_list_processes_start(). */ +struct mysql_list_processes_params { + MYSQL *mysql; +}; +static void +mysql_list_processes_start_internal(void *d) +{ +MK_ASYNC_INTERNAL_BODY( + mysql_list_processes, + (parms->mysql), + parms->mysql, + MYSQL_RES *, + r_ptr) +} +int STDCALL +mysql_list_processes_start(MYSQL_RES **ret, MYSQL *mysql) +{ +MK_ASYNC_START_BODY( + mysql_list_processes, + mysql, + { + WIN_SET_NONBLOCKING(mysql) + parms.mysql= mysql; + }, + NULL, + r_ptr, + /* Nothing */) +} +int STDCALL +mysql_list_processes_cont(MYSQL_RES **ret, MYSQL *mysql, int ready_status) +{ +MK_ASYNC_CONT_BODY( + mysql, + NULL, + r_ptr) +} + +/* Structure used to pass parameters from mysql_list_fields_start(). */ +struct mysql_list_fields_params { + MYSQL *mysql; + const char *table; + const char *wild; +}; +static void +mysql_list_fields_start_internal(void *d) +{ +MK_ASYNC_INTERNAL_BODY( + mysql_list_fields, + (parms->mysql, parms->table, parms->wild), + parms->mysql, + MYSQL_RES *, + r_ptr) +} +int STDCALL +mysql_list_fields_start(MYSQL_RES **ret, MYSQL *mysql, const char *table, + const char *wild) +{ +MK_ASYNC_START_BODY( + mysql_list_fields, + mysql, + { + WIN_SET_NONBLOCKING(mysql) + parms.mysql= mysql; + parms.table= table; + parms.wild= wild; + }, + NULL, + r_ptr, + /* Nothing */) +} +int STDCALL +mysql_list_fields_cont(MYSQL_RES **ret, MYSQL *mysql, int ready_status) +{ +MK_ASYNC_CONT_BODY( + mysql, + NULL, + r_ptr) +} + +/* Structure used to pass parameters from mysql_read_query_result_start(). */ +struct mysql_read_query_result_params { + MYSQL *mysql; +}; +static void +mysql_read_query_result_start_internal(void *d) +{ +MK_ASYNC_INTERNAL_BODY( + mysql_read_query_result, + (parms->mysql), + parms->mysql, + my_bool, + r_my_bool) +} +int STDCALL +mysql_read_query_result_start(my_bool *ret, MYSQL *mysql) +{ +MK_ASYNC_START_BODY( + mysql_read_query_result, + mysql, + { + WIN_SET_NONBLOCKING(mysql) + parms.mysql= mysql; + }, + TRUE, + r_my_bool, + /* Nothing */) +} +int STDCALL +mysql_read_query_result_cont(my_bool *ret, MYSQL *mysql, int ready_status) +{ +MK_ASYNC_CONT_BODY( + mysql, + TRUE, + r_my_bool) +} + +/* Structure used to pass parameters from mysql_stmt_prepare_start(). */ +struct mysql_stmt_prepare_params { + MYSQL_STMT *stmt; + const char *query; + unsigned long length; +}; +static void +mysql_stmt_prepare_start_internal(void *d) +{ +MK_ASYNC_INTERNAL_BODY( + mysql_stmt_prepare, + (parms->stmt, parms->query, parms->length), + parms->stmt->mysql, + int, + r_int) +} +int STDCALL +mysql_stmt_prepare_start(int *ret, MYSQL_STMT *stmt, const char *query, + unsigned long length) +{ +MK_ASYNC_START_BODY( + mysql_stmt_prepare, + stmt->mysql, + { + WIN_SET_NONBLOCKING(stmt->mysql) + parms.stmt= stmt; + parms.query= query; + parms.length= length; + }, + 1, + r_int, + /* If stmt->mysql==NULL then we will not block so can call directly. */ + if (!stmt->mysql) + { + *ret= mysql_stmt_prepare(stmt, query, length); + return 0; + }) +} +int STDCALL +mysql_stmt_prepare_cont(int *ret, MYSQL_STMT *stmt, int ready_status) +{ +MK_ASYNC_CONT_BODY( + stmt->mysql, + 1, + r_int) +} + +/* Structure used to pass parameters from mysql_stmt_execute_start(). */ +struct mysql_stmt_execute_params { + MYSQL_STMT *stmt; +}; +static void +mysql_stmt_execute_start_internal(void *d) +{ +MK_ASYNC_INTERNAL_BODY( + mysql_stmt_execute, + (parms->stmt), + parms->stmt->mysql, + int, + r_int) +} +int STDCALL +mysql_stmt_execute_start(int *ret, MYSQL_STMT *stmt) +{ +MK_ASYNC_START_BODY( + mysql_stmt_execute, + stmt->mysql, + { + WIN_SET_NONBLOCKING(stmt->mysql) + parms.stmt= stmt; + }, + 1, + r_int, + /* + If eg. mysql_change_user(), stmt->mysql will be NULL. + In this case, we cannot block. + */ + if (!stmt->mysql) + { + *ret= mysql_stmt_execute(stmt); + return 0; + }) +} +int STDCALL +mysql_stmt_execute_cont(int *ret, MYSQL_STMT *stmt, int ready_status) +{ +MK_ASYNC_CONT_BODY( + stmt->mysql, + 1, + r_int) +} + +/* Structure used to pass parameters from mysql_stmt_fetch_start(). */ +struct mysql_stmt_fetch_params { + MYSQL_STMT *stmt; +}; +static void +mysql_stmt_fetch_start_internal(void *d) +{ +MK_ASYNC_INTERNAL_BODY( + mysql_stmt_fetch, + (parms->stmt), + parms->stmt->mysql, + int, + r_int) +} +int STDCALL +mysql_stmt_fetch_start(int *ret, MYSQL_STMT *stmt) +{ +MK_ASYNC_START_BODY( + mysql_stmt_fetch, + stmt->mysql, + { + WIN_SET_NONBLOCKING(stmt->mysql) + parms.stmt= stmt; + }, + 1, + r_int, + /* If stmt->mysql==NULL then we will not block so can call directly. */ + if (!stmt->mysql) + { + *ret= mysql_stmt_fetch(stmt); + return 0; + }) +} +int STDCALL +mysql_stmt_fetch_cont(int *ret, MYSQL_STMT *stmt, int ready_status) +{ +MK_ASYNC_CONT_BODY( + stmt->mysql, + 1, + r_int) +} + +/* Structure used to pass parameters from mysql_stmt_store_result_start(). */ +struct mysql_stmt_store_result_params { + MYSQL_STMT *stmt; +}; +static void +mysql_stmt_store_result_start_internal(void *d) +{ +MK_ASYNC_INTERNAL_BODY( + mysql_stmt_store_result, + (parms->stmt), + parms->stmt->mysql, + int, + r_int) +} +int STDCALL +mysql_stmt_store_result_start(int *ret, MYSQL_STMT *stmt) +{ +MK_ASYNC_START_BODY( + mysql_stmt_store_result, + stmt->mysql, + { + WIN_SET_NONBLOCKING(stmt->mysql) + parms.stmt= stmt; + }, + 1, + r_int, + /* If stmt->mysql==NULL then we will not block so can call directly. */ + if (!stmt->mysql) + { + *ret= mysql_stmt_store_result(stmt); + return 0; + }) +} +int STDCALL +mysql_stmt_store_result_cont(int *ret, MYSQL_STMT *stmt, int ready_status) +{ +MK_ASYNC_CONT_BODY( + stmt->mysql, + 1, + r_int) +} + +/* Structure used to pass parameters from mysql_stmt_close_start(). */ +struct mysql_stmt_close_params { + MYSQL_STMT *stmt; +}; +static void +mysql_stmt_close_start_internal(void *d) +{ +MK_ASYNC_INTERNAL_BODY( + mysql_stmt_close, + (parms->stmt), + parms->stmt->mysql, + my_bool, + r_my_bool) +} +int STDCALL +mysql_stmt_close_start(my_bool *ret, MYSQL_STMT *stmt) +{ +MK_ASYNC_START_BODY( + mysql_stmt_close, + stmt->mysql, + { + WIN_SET_NONBLOCKING(stmt->mysql) + parms.stmt= stmt; + }, + TRUE, + r_my_bool, + /* If stmt->mysql==NULL then we will not block so can call directly. */ + if (!stmt->mysql) + { + *ret= mysql_stmt_close(stmt); + return 0; + }) +} +int STDCALL +mysql_stmt_close_cont(my_bool *ret, MYSQL_STMT *stmt, int ready_status) +{ +MK_ASYNC_CONT_BODY( + stmt->mysql, + TRUE, + r_my_bool) +} + +/* Structure used to pass parameters from mysql_stmt_reset_start(). */ +struct mysql_stmt_reset_params { + MYSQL_STMT *stmt; +}; +static void +mysql_stmt_reset_start_internal(void *d) +{ +MK_ASYNC_INTERNAL_BODY( + mysql_stmt_reset, + (parms->stmt), + parms->stmt->mysql, + my_bool, + r_my_bool) +} +int STDCALL +mysql_stmt_reset_start(my_bool *ret, MYSQL_STMT *stmt) +{ +MK_ASYNC_START_BODY( + mysql_stmt_reset, + stmt->mysql, + { + WIN_SET_NONBLOCKING(stmt->mysql) + parms.stmt= stmt; + }, + TRUE, + r_my_bool, + /* If stmt->mysql==NULL then we will not block so can call directly. */ + if (!stmt->mysql) + { + *ret= mysql_stmt_reset(stmt); + return 0; + }) +} +int STDCALL +mysql_stmt_reset_cont(my_bool *ret, MYSQL_STMT *stmt, int ready_status) +{ +MK_ASYNC_CONT_BODY( + stmt->mysql, + TRUE, + r_my_bool) +} + +/* Structure used to pass parameters from mysql_stmt_free_result_start(). */ +struct mysql_stmt_free_result_params { + MYSQL_STMT *stmt; +}; +static void +mysql_stmt_free_result_start_internal(void *d) +{ +MK_ASYNC_INTERNAL_BODY( + mysql_stmt_free_result, + (parms->stmt), + parms->stmt->mysql, + my_bool, + r_my_bool) +} +int STDCALL +mysql_stmt_free_result_start(my_bool *ret, MYSQL_STMT *stmt) +{ +MK_ASYNC_START_BODY( + mysql_stmt_free_result, + stmt->mysql, + { + WIN_SET_NONBLOCKING(stmt->mysql) + parms.stmt= stmt; + }, + TRUE, + r_my_bool, + /* If stmt->mysql==NULL then we will not block so can call directly. */ + if (!stmt->mysql) + { + *ret= mysql_stmt_free_result(stmt); + return 0; + }) +} +int STDCALL +mysql_stmt_free_result_cont(my_bool *ret, MYSQL_STMT *stmt, int ready_status) +{ +MK_ASYNC_CONT_BODY( + stmt->mysql, + TRUE, + r_my_bool) +} + +/* Structure used to pass parameters from mysql_stmt_send_long_data_start(). */ +struct mysql_stmt_send_long_data_params { + MYSQL_STMT *stmt; + unsigned int param_number; + const char *data; + unsigned long length; +}; +static void +mysql_stmt_send_long_data_start_internal(void *d) +{ +MK_ASYNC_INTERNAL_BODY( + mysql_stmt_send_long_data, + (parms->stmt, parms->param_number, parms->data, parms->length), + parms->stmt->mysql, + my_bool, + r_my_bool) +} +int STDCALL +mysql_stmt_send_long_data_start(my_bool *ret, MYSQL_STMT *stmt, + unsigned int param_number, + const char *data, unsigned long length) +{ +MK_ASYNC_START_BODY( + mysql_stmt_send_long_data, + stmt->mysql, + { + WIN_SET_NONBLOCKING(stmt->mysql) + parms.stmt= stmt; + parms.param_number= param_number; + parms.data= data; + parms.length= length; + }, + TRUE, + r_my_bool, + /* If stmt->mysql==NULL then we will not block so can call directly. */ + if (!stmt->mysql) + { + *ret= mysql_stmt_send_long_data(stmt, param_number, data, length); + return 0; + }) +} +int STDCALL +mysql_stmt_send_long_data_cont(my_bool *ret, MYSQL_STMT *stmt, int ready_status) +{ +MK_ASYNC_CONT_BODY( + stmt->mysql, + TRUE, + r_my_bool) +} + +/* Structure used to pass parameters from mysql_commit_start(). */ +struct mysql_commit_params { + MYSQL *mysql; +}; +static void +mysql_commit_start_internal(void *d) +{ +MK_ASYNC_INTERNAL_BODY( + mysql_commit, + (parms->mysql), + parms->mysql, + my_bool, + r_my_bool) +} +int STDCALL +mysql_commit_start(my_bool *ret, MYSQL *mysql) +{ +MK_ASYNC_START_BODY( + mysql_commit, + mysql, + { + WIN_SET_NONBLOCKING(mysql) + parms.mysql= mysql; + }, + TRUE, + r_my_bool, + /* Nothing */) +} +int STDCALL +mysql_commit_cont(my_bool *ret, MYSQL *mysql, int ready_status) +{ +MK_ASYNC_CONT_BODY( + mysql, + TRUE, + r_my_bool) +} + +/* Structure used to pass parameters from mysql_rollback_start(). */ +struct mysql_rollback_params { + MYSQL *mysql; +}; +static void +mysql_rollback_start_internal(void *d) +{ +MK_ASYNC_INTERNAL_BODY( + mysql_rollback, + (parms->mysql), + parms->mysql, + my_bool, + r_my_bool) +} +int STDCALL +mysql_rollback_start(my_bool *ret, MYSQL *mysql) +{ +MK_ASYNC_START_BODY( + mysql_rollback, + mysql, + { + WIN_SET_NONBLOCKING(mysql) + parms.mysql= mysql; + }, + TRUE, + r_my_bool, + /* Nothing */) +} +int STDCALL +mysql_rollback_cont(my_bool *ret, MYSQL *mysql, int ready_status) +{ +MK_ASYNC_CONT_BODY( + mysql, + TRUE, + r_my_bool) +} + +/* Structure used to pass parameters from mysql_autocommit_start(). */ +struct mysql_autocommit_params { + MYSQL *mysql; + my_bool auto_mode; +}; +static void +mysql_autocommit_start_internal(void *d) +{ +MK_ASYNC_INTERNAL_BODY( + mysql_autocommit, + (parms->mysql, parms->auto_mode), + parms->mysql, + my_bool, + r_my_bool) +} +int STDCALL +mysql_autocommit_start(my_bool *ret, MYSQL *mysql, my_bool auto_mode) +{ +MK_ASYNC_START_BODY( + mysql_autocommit, + mysql, + { + WIN_SET_NONBLOCKING(mysql) + parms.mysql= mysql; + parms.auto_mode= auto_mode; + }, + TRUE, + r_my_bool, + /* Nothing */) +} +int STDCALL +mysql_autocommit_cont(my_bool *ret, MYSQL *mysql, int ready_status) +{ +MK_ASYNC_CONT_BODY( + mysql, + TRUE, + r_my_bool) +} + +/* Structure used to pass parameters from mysql_next_result_start(). */ +struct mysql_next_result_params { + MYSQL *mysql; +}; +static void +mysql_next_result_start_internal(void *d) +{ +MK_ASYNC_INTERNAL_BODY( + mysql_next_result, + (parms->mysql), + parms->mysql, + int, + r_int) +} +int STDCALL +mysql_next_result_start(int *ret, MYSQL *mysql) +{ +MK_ASYNC_START_BODY( + mysql_next_result, + mysql, + { + WIN_SET_NONBLOCKING(mysql) + parms.mysql= mysql; + }, + 1, + r_int, + /* Nothing */) +} +int STDCALL +mysql_next_result_cont(int *ret, MYSQL *mysql, int ready_status) +{ +MK_ASYNC_CONT_BODY( + mysql, + 1, + r_int) +} + +/* Structure used to pass parameters from mysql_stmt_next_result_start(). */ +struct mysql_stmt_next_result_params { + MYSQL_STMT *stmt; +}; +static void +mysql_stmt_next_result_start_internal(void *d) +{ +MK_ASYNC_INTERNAL_BODY( + mysql_stmt_next_result, + (parms->stmt), + parms->stmt->mysql, + int, + r_int) +} +int STDCALL +mysql_stmt_next_result_start(int *ret, MYSQL_STMT *stmt) +{ +MK_ASYNC_START_BODY( + mysql_stmt_next_result, + stmt->mysql, + { + WIN_SET_NONBLOCKING(stmt->mysql) + parms.stmt= stmt; + }, + 1, + r_int, + /* Nothing */) +} +int STDCALL +mysql_stmt_next_result_cont(int *ret, MYSQL_STMT *stmt, int ready_status) +{ +MK_ASYNC_CONT_BODY( + stmt->mysql, + 1, + r_int) +} +#endif + + +/* + The following functions are deprecated, and so have no non-blocking version: + + mysql_connect + mysql_create_db + mysql_drop_db +*/ + +/* + The following functions can newer block, and so do not have special + non-blocking versions: + + mysql_num_rows() + mysql_num_fields() + mysql_eof() + mysql_fetch_field_direct() + mysql_fetch_fields() + mysql_row_tell() + mysql_field_tell() + mysql_field_count() + mysql_affected_rows() + mysql_insert_id() + mysql_errno() + mysql_error() + mysql_sqlstate() + mysql_warning_count() + mysql_info() + mysql_thread_id() + mysql_character_set_name() + mysql_init() + mysql_ssl_set() + mysql_get_ssl_cipher() + mysql_use_result() + mysql_get_character_set_info() + mysql_set_local_infile_handler() + mysql_set_local_infile_default() + mysql_get_server_info() + mysql_get_server_name() + mysql_get_client_info() + mysql_get_client_version() + mysql_get_host_info() + mysql_get_server_version() + mysql_get_proto_info() + mysql_options() + mysql_data_seek() + mysql_row_seek() + mysql_field_seek() + mysql_fetch_lengths() + mysql_fetch_field() + mysql_escape_string() + mysql_hex_string() + mysql_real_escape_string() + mysql_debug() + myodbc_remove_escape() + mysql_thread_safe() + mysql_embedded() + mariadb_connection() + mysql_stmt_init() + mysql_stmt_fetch_column() + mysql_stmt_param_count() + mysql_stmt_attr_set() + mysql_stmt_attr_get() + mysql_stmt_bind_param() + mysql_stmt_bind_result() + mysql_stmt_result_metadata() + mysql_stmt_param_metadata() + mysql_stmt_errno() + mysql_stmt_error() + mysql_stmt_sqlstate() + mysql_stmt_row_seek() + mysql_stmt_row_tell() + mysql_stmt_data_seek() + mysql_stmt_num_rows() + mysql_stmt_affected_rows() + mysql_stmt_insert_id() + mysql_stmt_field_count() + mysql_more_results() + mysql_get_socket() + mysql_get_timeout_value() +*/ diff --git a/vendor/MDBC/libmariadb/mariadb_charset.c b/vendor/MDBC/libmariadb/mariadb_charset.c new file mode 100644 index 00000000..a406af2f --- /dev/null +++ b/vendor/MDBC/libmariadb/mariadb_charset.c @@ -0,0 +1,74 @@ +/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB + 2016 MariaDB Corporation AB + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + MA 02111-1301, USA */ + +#include +#include +// #include "mysys_err.h" +#include +#include + +MARIADB_CHARSET_INFO *ma_default_charset_info; /* will be set in mysql_server_init */ +MARIADB_CHARSET_INFO *ma_charset_bin= (MARIADB_CHARSET_INFO *)&mariadb_compiled_charsets[32]; +MARIADB_CHARSET_INFO *ma_charset_latin1= (MARIADB_CHARSET_INFO *)&mariadb_compiled_charsets[5]; +MARIADB_CHARSET_INFO *ma_charset_utf8_general_ci= (MARIADB_CHARSET_INFO *)&mariadb_compiled_charsets[21]; +MARIADB_CHARSET_INFO *ma_charset_utf16le_general_ci= (MARIADB_CHARSET_INFO *)&mariadb_compiled_charsets[68]; + +MARIADB_CHARSET_INFO * STDCALL mysql_get_charset_by_nr(uint cs_number) +{ + int i= 0; + + while (mariadb_compiled_charsets[i].nr && cs_number != mariadb_compiled_charsets[i].nr) + i++; + + return (mariadb_compiled_charsets[i].nr) ? (MARIADB_CHARSET_INFO *)&mariadb_compiled_charsets[i] : NULL; +} + +my_bool set_default_charset(uint cs, myf flags __attribute__((unused))) +{ + MARIADB_CHARSET_INFO *new_charset; + new_charset = mysql_get_charset_by_nr(cs); + if (!new_charset) + { + return(TRUE); /* error */ + } + ma_default_charset_info = new_charset; + return(FALSE); +} + +MARIADB_CHARSET_INFO * STDCALL mysql_get_charset_by_name(const char *cs_name) +{ + int i= 0; + + while (mariadb_compiled_charsets[i].nr && strcmp(cs_name, mariadb_compiled_charsets[i].csname) != 0) + i++; + + return (mariadb_compiled_charsets[i].nr) ? (MARIADB_CHARSET_INFO *)&mariadb_compiled_charsets[i] : NULL; +} + +my_bool set_default_charset_by_name(const char *cs_name, myf flags __attribute__((unused))) +{ + MARIADB_CHARSET_INFO *new_charset; + new_charset = mysql_get_charset_by_name(cs_name); + if (!new_charset) + { + return(TRUE); /* error */ + } + + ma_default_charset_info = new_charset; + return(FALSE); +} diff --git a/vendor/MDBC/libmariadb/mariadb_dyncol.c b/vendor/MDBC/libmariadb/mariadb_dyncol.c new file mode 100644 index 00000000..775aa36f --- /dev/null +++ b/vendor/MDBC/libmariadb/mariadb_dyncol.c @@ -0,0 +1,4368 @@ +/* Copyright (c) 2011,2013 Monty Program Ab; + Copyright (c) 2011,2012 Oleksandr Byelkin + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must the following disclaimer in + the documentation and/or other materials provided with the + distribution. + + THIS SOFTWARE IS PROVIDED BY ``AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL OR + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + SUCH DAMAGE. +*/ + +/* + Numeric format: + =============== + * Fixed header part + 1 byte flags: + 0,1 bits - - 1 + 2-7 bits - 0 + 2 bytes column counter + * Columns directory sorted by column number, each entry contains of: + 2 bytes column number + bytes (1-4) combined offset from beginning of + the data segment + 3 bit type + * Data of above columns size of data and length depend on type + + Columns with names: + =================== + * Fixed header part + 1 byte flags: + 0,1 bits - - 2 + 2 bit - 1 (means format with names) + 3,4 bits - 00 (means - 2, + now 2 is the only supported size) + 5-7 bits - 0 + 2 bytes column counter + * Variable header part (now it is actually fixed part) + (2) bytes size of stored names pool + * Column directory sorted by names, each consists of + (2) bytes offset of name + bytes (2-5)bytes combined offset from beginning of + the data segment + 4 bit type + * Names stored one after another + * Data of above columns size of data and length depend on type +*/ + +#include +#include +#include +#include +//#include +#include +#include + + + +#ifndef LIBMARIADB +uint32 copy_and_convert(char *to, uint32 to_length, MARIADB_CHARSET_INFO *to_cs, + const char *from, uint32 from_length, + MARIADB_CHARSET_INFO *from_cs, uint *errors); +#else + +size_t mariadb_time_to_string(const MYSQL_TIME *tm, char *time_str, size_t len, + unsigned int digits); +size_t STDCALL mariadb_convert_string(const char *from, size_t *from_len, MARIADB_CHARSET_INFO *from_cs, + char *to, size_t *to_len, MARIADB_CHARSET_INFO *to_cs, int *errorcode); +#endif +/* + Flag byte bits + + 2 bits which determinate size of offset in the header -1 +*/ +/* mask to get above bits */ +#define DYNCOL_FLG_OFFSET (1|2) +#define DYNCOL_FLG_NAMES 4 +#define DYNCOL_FLG_NMOFFSET (8|16) +/** + All known flags mask that could be set. + + @note DYNCOL_FLG_NMOFFSET should be 0 for now. +*/ +#define DYNCOL_FLG_KNOWN (1|2|4) + +/* formats */ +enum enum_dyncol_format +{ + dyncol_fmt_num= 0, + dyncol_fmt_str= 1 +}; + +/* dynamic column size reserve */ +#define DYNCOL_SYZERESERVE 80 + +#define DYNCOL_OFFSET_ERROR 0xffffffff + +/* length of fixed string header 1 byte - flags, 2 bytes - columns counter */ +#define FIXED_HEADER_SIZE 3 +/* + length of fixed string header with names + 1 byte - flags, 2 bytes - columns counter, 2 bytes - name pool size +*/ +#define FIXED_HEADER_SIZE_NM 5 + +#define COLUMN_NUMBER_SIZE 2 +/* 2 bytes offset from the name pool */ +#define COLUMN_NAMEPTR_SIZE 2 + +#define MAX_OFFSET_LENGTH 4 +#define MAX_OFFSET_LENGTH_NM 5 + +#define DYNCOL_NUM_CHAR 6 + +my_bool mariadb_dyncol_has_names(DYNAMIC_COLUMN *str) +{ + if (str->length < 1) + return FALSE; + return test(str->str[0] & DYNCOL_FLG_NAMES); +} + +static enum enum_dyncol_func_result +dynamic_column_time_store(DYNAMIC_COLUMN *str, + MYSQL_TIME *value, enum enum_dyncol_format format); +static enum enum_dyncol_func_result +dynamic_column_date_store(DYNAMIC_COLUMN *str, + MYSQL_TIME *value); +static enum enum_dyncol_func_result +dynamic_column_time_read_internal(DYNAMIC_COLUMN_VALUE *store_it_here, + uchar *data, size_t length); +static enum enum_dyncol_func_result +dynamic_column_date_read_internal(DYNAMIC_COLUMN_VALUE *store_it_here, + uchar *data, size_t length); +static enum enum_dyncol_func_result +dynamic_column_get_internal(DYNAMIC_COLUMN *str, + DYNAMIC_COLUMN_VALUE *store_it_here, + uint num_key, LEX_STRING *str_key); +static enum enum_dyncol_func_result +dynamic_column_exists_internal(DYNAMIC_COLUMN *str, uint num_key, + LEX_STRING *str_key); +static enum enum_dyncol_func_result +dynamic_column_update_many_fmt(DYNAMIC_COLUMN *str, + uint add_column_count, + void *column_keys, + DYNAMIC_COLUMN_VALUE *values, + my_bool string_keys); +static int plan_sort_num(const void *a, const void *b); +static int plan_sort_named(const void *a, const void *b); + +/* + Structure to hold information about dynamic columns record and + iterate through it. +*/ + +struct st_dyn_header +{ + uchar *header, *nmpool, *dtpool, *data_end; + size_t offset_size; + size_t entry_size; + size_t header_size; + size_t nmpool_size; + size_t data_size; + /* dyncol_fmt_num - numeric columns, dyncol_fmt_str - column names */ + enum enum_dyncol_format format; + uint column_count; + + uchar *entry, *data, *name; + size_t offset; + size_t length; + enum enum_dynamic_column_type type; +}; + +typedef struct st_dyn_header DYN_HEADER; + +static inline my_bool read_fixed_header(DYN_HEADER *hdr, + DYNAMIC_COLUMN *str); +static void set_fixed_header(DYNAMIC_COLUMN *str, + uint offset_size, + uint column_count); + +/* + Calculate entry size (E) and header size (H) by offset size (O) and column + count (C) and fixed part of entry size (F). +*/ + +#define calc_param(E,H,F,O,C) do { \ + (*(E))= (O) + F; \ + (*(H))= (*(E)) * (C); \ +}while(0); + + +/** + Name pool size functions, for numeric format it is 0 +*/ + +static size_t name_size_num(void *keys __attribute__((unused)), + uint i __attribute__((unused))) +{ + return 0; +} + + +/** + Name pool size functions. +*/ +static size_t name_size_named(void *keys, uint i) +{ + return ((LEX_STRING *) keys)[i].length; +} + + +/** + Comparator function for references on column numbers for qsort + (numeric format) +*/ + +static int column_sort_num(const void *a, const void *b) +{ + return **((uint **)a) - **((uint **)b); +} + +/** + Comparator function for references on column numbers for qsort + (names format) +*/ + +int mariadb_dyncol_column_cmp_named(const LEX_STRING *s1, const LEX_STRING *s2) +{ + /* + We compare instead of subtraction to avoid data loss in case of huge + length difference (more then fit in int). + */ + int rc= (s1->length > s2->length ? 1 : + (s1->length < s2->length ? -1 : 0)); + if (rc == 0) + rc= memcmp((void *)s1->str, (void *)s2->str, + (size_t) s1->length); + return rc; +} + + +/** + Comparator function for references on column numbers for qsort + (names format) +*/ + +static int column_sort_named(const void *a, const void *b) +{ + return mariadb_dyncol_column_cmp_named(*((LEX_STRING **)a), + *((LEX_STRING **)b)); +} + + +/** + Check limit function (numeric format) +*/ + +static my_bool check_limit_num(const void *val) +{ + return **((uint **)val) > UINT_MAX16; +} + + +/** + Check limit function (names format) +*/ + +static my_bool check_limit_named(const void *val) +{ + return (*((LEX_STRING **)val))->length > MAX_NAME_LENGTH; +} + + +/** + Write numeric format static header part. +*/ + +static void set_fixed_header_num(DYNAMIC_COLUMN *str, DYN_HEADER *hdr) +{ + set_fixed_header(str, (uint)hdr->offset_size, hdr->column_count); + hdr->header= (uchar *)str->str + FIXED_HEADER_SIZE; + hdr->nmpool= hdr->dtpool= hdr->header + hdr->header_size; +} + + +/** + Write names format static header part. +*/ + +static void set_fixed_header_named(DYNAMIC_COLUMN *str, DYN_HEADER *hdr) +{ + DBUG_ASSERT(hdr->column_count <= 0xffff); + DBUG_ASSERT(hdr->offset_size <= MAX_OFFSET_LENGTH_NM); + /* size of data offset, named format flag, size of names offset (0 means 2) */ + str->str[0]= + (char) ((str->str[0] & ~(DYNCOL_FLG_OFFSET | DYNCOL_FLG_NMOFFSET)) | + (hdr->offset_size - 2) | DYNCOL_FLG_NAMES); + int2store(str->str + 1, hdr->column_count); /* columns number */ + int2store(str->str + 3, hdr->nmpool_size); + hdr->header= (uchar *)str->str + FIXED_HEADER_SIZE_NM; + hdr->nmpool= hdr->header + hdr->header_size; + hdr->dtpool= hdr->nmpool + hdr->nmpool_size; +} + + +/** + Store offset and type information in the given place + + @param place Beginning of the index entry + @param offset_size Size of offset field in bytes + @param type Type to be written + @param offset Offset to be written +*/ + +static my_bool type_and_offset_store_num(uchar *place, size_t offset_size, + DYNAMIC_COLUMN_TYPE type, + size_t offset) +{ + ulong val = (((ulong) offset) << 3) | (type - 1); + DBUG_ASSERT(type != DYN_COL_NULL); + DBUG_ASSERT(((type - 1) & (~7)) == 0); /* fit in 3 bits */ + DBUG_ASSERT(offset_size >= 1 && offset_size <= 4); + + /* Index entry starts with column number; jump over it */ + place+= COLUMN_NUMBER_SIZE; + + switch (offset_size) { + case 1: + if (offset >= 0x1f) /* all 1 value is reserved */ + return TRUE; + place[0]= (uchar)val; + break; + case 2: + if (offset >= 0x1fff) /* all 1 value is reserved */ + return TRUE; + int2store(place, val); + break; + case 3: + if (offset >= 0x1fffff) /* all 1 value is reserved */ + return TRUE; + int3store(place, val); + break; + case 4: + if (offset >= 0x1fffffff) /* all 1 value is reserved */ + return TRUE; + int4store(place, val); + break; + default: + return TRUE; + } + return FALSE; +} + + +static my_bool type_and_offset_store_named(uchar *place, size_t offset_size, + DYNAMIC_COLUMN_TYPE type, + size_t offset) +{ + ulonglong val = (((ulong) offset) << 4) | (type - 1); + DBUG_ASSERT(type != DYN_COL_NULL); + DBUG_ASSERT(((type - 1) & (~0xf)) == 0); /* fit in 4 bits */ + DBUG_ASSERT(offset_size >= 2 && offset_size <= 5); + + /* Index entry starts with name offset; jump over it */ + place+= COLUMN_NAMEPTR_SIZE; + switch (offset_size) { + case 2: + if (offset >= 0xfff) /* all 1 value is reserved */ + return TRUE; + int2store(place, val); + break; + case 3: + if (offset >= 0xfffff) /* all 1 value is reserved */ + return TRUE; + int3store(place, val); + break; + case 4: + if (offset >= 0xfffffff) /* all 1 value is reserved */ + return TRUE; + int4store(place, val); + break; + case 5: +#if SIZEOF_SIZE_T > 4 + if (offset >= 0xfffffffffull) /* all 1 value is reserved */ + return TRUE; +#endif + int5store(place, val); + break; + case 1: + default: + return TRUE; + } + return FALSE; +} + +/** + Write numeric format header entry + 2 bytes - column number + 1-4 bytes - data offset combined with type + + @param hdr descriptor of dynamic column record + @param column_key pointer to uint (column number) + @param value value which will be written (only type used) + @param offset offset of the data +*/ + +static my_bool put_header_entry_num(DYN_HEADER *hdr, + void *column_key, + DYNAMIC_COLUMN_VALUE *value, + size_t offset) +{ + uint *column_number= (uint *)column_key; + int2store(hdr->entry, *column_number); + DBUG_ASSERT(hdr->nmpool_size == 0); + if (type_and_offset_store_num(hdr->entry, hdr->offset_size, + value->type, + offset)) + return TRUE; + hdr->entry= hdr->entry + hdr->entry_size; + return FALSE; +} + + +/** + Write names format header entry + 1 byte - name length + 2 bytes - name offset in the name pool + 1-4 bytes - data offset combined with type + + @param hdr descriptor of dynamic column record + @param column_key pointer to LEX_STRING (column name) + @param value value which will be written (only type used) + @param offset offset of the data +*/ + +static my_bool put_header_entry_named(DYN_HEADER *hdr, + void *column_key, + DYNAMIC_COLUMN_VALUE *value, + size_t offset) +{ + LEX_STRING *column_name= (LEX_STRING *)column_key; + DBUG_ASSERT(column_name->length <= MAX_NAME_LENGTH); + DBUG_ASSERT(hdr->name - hdr->nmpool < (long) 0x10000L); + int2store(hdr->entry, hdr->name - hdr->nmpool); + memcpy(hdr->name, column_name->str, column_name->length); + DBUG_ASSERT(hdr->nmpool_size != 0 || column_name->length == 0); + if (type_and_offset_store_named(hdr->entry, hdr->offset_size, + value->type, + offset)) + return TRUE; + hdr->entry+= hdr->entry_size; + hdr->name+= column_name->length; + return FALSE; +} + + +/** + Calculate length of offset field for given data length + + @param data_length Length of the data segment + + @return number of bytes +*/ + +static size_t dynamic_column_offset_bytes_num(size_t data_length) +{ + if (data_length < 0x1f) /* all 1 value is reserved */ + return 1; + if (data_length < 0x1fff) /* all 1 value is reserved */ + return 2; + if (data_length < 0x1fffff) /* all 1 value is reserved */ + return 3; + if (data_length < 0x1fffffff) /* all 1 value is reserved */ + return 4; + return MAX_OFFSET_LENGTH + 1; /* For an error generation*/ +} + +static size_t dynamic_column_offset_bytes_named(size_t data_length) +{ + if (data_length < 0xfff) /* all 1 value is reserved */ + return 2; + if (data_length < 0xfffff) /* all 1 value is reserved */ + return 3; + if (data_length < 0xfffffff) /* all 1 value is reserved */ + return 4; +#if SIZEOF_SIZE_T > 4 + if (data_length < 0xfffffffffull) /* all 1 value is reserved */ +#endif + return 5; + return MAX_OFFSET_LENGTH_NM + 1; /* For an error generation */ +} + +/** + Read offset and type information from index entry + + @param type Where to put type info + @param offset Where to put offset info + @param place beginning of the type and offset + @param offset_size Size of offset field in bytes +*/ + +static my_bool type_and_offset_read_num(DYNAMIC_COLUMN_TYPE *type, + size_t *offset, + uchar *place, size_t offset_size) +{ + ulong UNINIT_VAR(val); + ulong UNINIT_VAR(lim); + + DBUG_ASSERT(offset_size >= 1 && offset_size <= 4); + + switch (offset_size) { + case 1: + val= (ulong)place[0]; + lim= 0x1f; + break; + case 2: + val= uint2korr(place); + lim= 0x1fff; + break; + case 3: + val= uint3korr(place); + lim= 0x1fffff; + break; + case 4: + val= uint4korr(place); + lim= 0x1fffffff; + break; + default: + DBUG_ASSERT(0); /* impossible */ + return 1; + } + *type= (val & 0x7) + 1; + *offset= val >> 3; + return (*offset >= lim); +} + +static my_bool type_and_offset_read_named(DYNAMIC_COLUMN_TYPE *type, + size_t *offset, + uchar *place, size_t offset_size) +{ + ulonglong UNINIT_VAR(val); + ulonglong UNINIT_VAR(lim); + DBUG_ASSERT(offset_size >= 2 && offset_size <= 5); + + switch (offset_size) { + case 2: + val= uint2korr(place); + lim= 0xfff; + break; + case 3: + val= uint3korr(place); + lim= 0xfffff; + break; + case 4: + val= uint4korr(place); + lim= 0xfffffff; + break; + case 5: + val= uint5korr(place); + lim= 0xfffffffffull; + break; + case 1: + default: + DBUG_ASSERT(0); /* impossible */ + return 1; + } + *type= (val & 0xf) + 1; + *offset= (size_t)(val >> 4); + return (*offset >= lim); +} + +/** + Format descriptor, contain constants and function references for + format processing +*/ + +struct st_service_funcs +{ + /* size of fixed header */ + uint fixed_hdr; + /* size of fixed part of header entry */ + uint fixed_hdr_entry; + + /*size of array element which stores keys */ + uint key_size_in_array; + + /* Maximum data offset size in bytes */ + size_t max_offset_size; + + size_t (*name_size) + (void *, uint); + int (*column_sort) + (const void *a, const void *b); + my_bool (*check_limit) + (const void *val); + void (*set_fixed_hdr) + (DYNAMIC_COLUMN *str, DYN_HEADER *hdr); + my_bool (*put_header_entry)(DYN_HEADER *hdr, + void *column_key, + DYNAMIC_COLUMN_VALUE *value, + size_t offset); + int (*plan_sort)(const void *a, const void *b); + size_t (*dynamic_column_offset_bytes)(size_t data_length); + my_bool (*type_and_offset_read)(DYNAMIC_COLUMN_TYPE *type, + size_t *offset, + uchar *place, size_t offset_size); + +}; + + +/** + Actual our 2 format descriptors +*/ + +static struct st_service_funcs fmt_data[2]= +{ + { + FIXED_HEADER_SIZE, + COLUMN_NUMBER_SIZE, + sizeof(uint), + MAX_OFFSET_LENGTH, + &name_size_num, + &column_sort_num, + &check_limit_num, + &set_fixed_header_num, + &put_header_entry_num, + &plan_sort_num, + &dynamic_column_offset_bytes_num, + &type_and_offset_read_num + }, + { + FIXED_HEADER_SIZE_NM, + COLUMN_NAMEPTR_SIZE, + sizeof(LEX_STRING), + MAX_OFFSET_LENGTH_NM, + &name_size_named, + &column_sort_named, + &check_limit_named, + &set_fixed_header_named, + &put_header_entry_named, + &plan_sort_named, + &dynamic_column_offset_bytes_named, + &type_and_offset_read_named + } +}; + + +/** + Read dynamic column record header and fill the descriptor + + @param hdr dynamic columns record descriptor to fill + @param str dynamic columns record + + @return ER_DYNCOL_* return code +*/ + +static enum enum_dyncol_func_result +init_read_hdr(DYN_HEADER *hdr, DYNAMIC_COLUMN *str) +{ + if (read_fixed_header(hdr, str)) + return ER_DYNCOL_FORMAT; + hdr->header= (uchar*)str->str + fmt_data[hdr->format].fixed_hdr; + calc_param(&hdr->entry_size, &hdr->header_size, + fmt_data[hdr->format].fixed_hdr_entry, hdr->offset_size, + hdr->column_count); + hdr->nmpool= hdr->header + hdr->header_size; + hdr->dtpool= hdr->nmpool + hdr->nmpool_size; + hdr->data_size= str->length - fmt_data[hdr->format].fixed_hdr - + hdr->header_size - hdr->nmpool_size; + hdr->data_end= (uchar*)str->str + str->length; + return ER_DYNCOL_OK; +} + + +/** + Initialize dynamic column string with (make it empty but correct format) + + @param str The string to initialize + @param size Amount of preallocated memory for the string. + + @retval FALSE OK + @retval TRUE error +*/ + +static my_bool dynamic_column_init_named(DYNAMIC_COLUMN *str, size_t size) +{ + DBUG_ASSERT(size != 0); + + /* + Make string with no fields (empty header) + - First \0 is flags + - other 2 \0 is number of fields + */ + if (ma_init_dynamic_string(str, NULL, size, DYNCOL_SYZERESERVE)) + return TRUE; + return FALSE; +} + + +/** + Calculate how many bytes needed to store val as variable length integer + where first bit indicate continuation of the sequence. + + @param val The value for which we are calculating length + + @return number of bytes +*/ + +static size_t dynamic_column_var_uint_bytes(ulonglong val) +{ + size_t len= 0; + do + { + len++; + val>>= 7; + } while (val); + return len; +} + + +/** + Stores variable length unsigned integer value to a string + + @param str The string where to append the value + @param val The value to put in the string + + @return ER_DYNCOL_* return code + + @notes + This is used to store a number together with other data in the same + object. (Like decimals, length of string etc) + (As we don't know the length of this object, we can't store 0 in 0 bytes) +*/ + +static enum enum_dyncol_func_result +dynamic_column_var_uint_store(DYNAMIC_COLUMN *str, ulonglong val) +{ + if (ma_dynstr_realloc(str, 10)) /* max what we can use */ + return ER_DYNCOL_RESOURCE; + + do + { + ulonglong rest= val >> 7; + str->str[str->length++]= ((val & 0x7f) | (rest ? 0x80 : 0x00)); + val= rest; + } while (val); + return ER_DYNCOL_OK; +} + + +/** + Reads variable length unsigned integer value from a string + + @param data The string from which the int should be read + @param data_length Max length of data + @param len Where to put length of the string read in bytes + + @return value of the unsigned integer read from the string + + In case of error, *len is set to 0 +*/ + +static ulonglong +dynamic_column_var_uint_get(uchar *data, size_t data_length, + size_t *len) +{ + ulonglong val= 0; + uint length; + uchar *end= data + data_length; + + for (length=0; data < end ; data++) + { + val+= (((ulonglong)((*data) & 0x7f)) << (length * 7)); + length++; + if (!((*data) & 0x80)) + { + /* End of data */ + *len= length; + return val; + } + } + /* Something was wrong with data */ + *len= 0; /* Mark error */ + return 0; +} + + +/** + Calculate how many bytes needed to store val as unsigned. + + @param val The value for which we are calculating length + + @return number of bytes (0-8) +*/ + +static size_t dynamic_column_uint_bytes(ulonglong val) +{ + size_t len; + + for (len= 0; val ; val>>= 8, len++) + ; + return len; +} + + +/** + Append the string with given unsigned int value. + + @param str The string where to put the value + @param val The value to put in the string + + @return ER_DYNCOL_* return code +*/ + +static enum enum_dyncol_func_result +dynamic_column_uint_store(DYNAMIC_COLUMN *str, ulonglong val) +{ + if (ma_dynstr_realloc(str, 8)) /* max what we can use */ + return ER_DYNCOL_RESOURCE; + + for (; val; val>>= 8) + str->str[str->length++]= (char) (val & 0xff); + return ER_DYNCOL_OK; +} + + +/** + Read unsigned int value of given length from the string + + @param store_it_here The structure to store the value + @param data The string which should be read + @param length The length (in bytes) of the value in nthe string + + @return ER_DYNCOL_* return code +*/ + +static enum enum_dyncol_func_result +dynamic_column_uint_read(DYNAMIC_COLUMN_VALUE *store_it_here, + uchar *data, size_t length) +{ + ulonglong value= 0; + size_t i; + + for (i= 0; i < length; i++) + value+= ((ulonglong)data[i]) << (i*8); + + store_it_here->x.ulong_value= value; + return ER_DYNCOL_OK; +} + +/** + Calculate how many bytes needed to store val as signed in following encoding: + 0 -> 0 + -1 -> 1 + 1 -> 2 + -2 -> 3 + 2 -> 4 + ... + + @param val The value for which we are calculating length + + @return number of bytes +*/ + +static size_t dynamic_column_sint_bytes(longlong val) +{ + return dynamic_column_uint_bytes((val << 1) ^ + (val < 0 ? 0xffffffffffffffffull : 0)); +} + + +/** + Append the string with given signed int value. + + @param str the string where to put the value + @param val the value to put in the string + + @return ER_DYNCOL_* return code +*/ + +static enum enum_dyncol_func_result +dynamic_column_sint_store(DYNAMIC_COLUMN *str, longlong val) +{ + return dynamic_column_uint_store(str, + (val << 1) ^ + (val < 0 ? 0xffffffffffffffffULL : 0)); +} + + +/** + Read signed int value of given length from the string + + @param store_it_here The structure to store the value + @param data The string which should be read + @param length The length (in bytes) of the value in the string + + @return ER_DYNCOL_* return code +*/ + +static enum enum_dyncol_func_result +dynamic_column_sint_read(DYNAMIC_COLUMN_VALUE *store_it_here, + uchar *data, size_t length) +{ + ulonglong val; + dynamic_column_uint_read(store_it_here, data, length); + val= store_it_here->x.ulong_value; + if (val & 1) + val= (val >> 1) ^ 0xffffffffffffffffULL; + else + val>>= 1; + store_it_here->x.long_value= (longlong) val; + return ER_DYNCOL_OK; +} + + +/** + Calculate how many bytes needed to store the value. + + @param value The value for which we are calculating length + + @return + Error: (size_t) ~0 + ok number of bytes +*/ + +static size_t +dynamic_column_value_len(DYNAMIC_COLUMN_VALUE *value, + enum enum_dyncol_format format) +{ + switch (value->type) { + case DYN_COL_NULL: + return 0; + case DYN_COL_INT: + return dynamic_column_sint_bytes(value->x.long_value); + case DYN_COL_UINT: + return dynamic_column_uint_bytes(value->x.ulong_value); + case DYN_COL_DOUBLE: + return 8; + case DYN_COL_STRING: +#ifdef LIBMARIADB + return (dynamic_column_var_uint_bytes(value->x.string.charset->nr) + + value->x.string.value.length); +#else + return (dynamic_column_var_uint_bytes(value->x.string.charset->number) + + value->x.string.value.length); +#endif +#ifndef LIBMARIADB + case DYN_COL_DECIMAL: + { + int precision= value->x.decimal.value.intg + value->x.decimal.value.frac; + int scale= value->x.decimal.value.frac; + + if (precision == 0 || decimal_is_zero(&value->x.decimal.value)) + { + /* This is here to simplify dynamic_column_decimal_store() */ + value->x.decimal.value.intg= value->x.decimal.value.frac= 0; + return 0; + } + /* + Check if legal decimal; This is needed to not get an assert in + decimal_bin_size(). However this should be impossible as all + decimals entered here should be valid and we have the special check + above to handle the unlikely but possible case that decimal.value.intg + and decimal.frac is 0. + */ + if (scale < 0 || precision <= 0) + { + DBUG_ASSERT(0); /* Impossible */ + return (size_t) ~0; + } + return (dynamic_column_var_uint_bytes(value->x.decimal.value.intg) + + dynamic_column_var_uint_bytes(value->x.decimal.value.frac) + + decimal_bin_size(precision, scale)); + } +#endif + case DYN_COL_DATETIME: + if (format == dyncol_fmt_num || value->x.time_value.second_part) + /* date+time in bits: 14 + 4 + 5 + 10 + 6 + 6 + 20 + 1 66bits ~= 9 bytes*/ + return 9; + else + return 6; + case DYN_COL_DATE: + /* date in dits: 14 + 4 + 5 = 23bits ~= 3bytes*/ + return 3; + case DYN_COL_TIME: + if (format == dyncol_fmt_num || value->x.time_value.second_part) + /* time in bits: 10 + 6 + 6 + 20 + 1 = 43bits ~= 6bytes*/ + return 6; + else + return 3; + case DYN_COL_DYNCOL: + return value->x.string.value.length; + default: + break; + } + DBUG_ASSERT(0); + return 0; +} + + +/** + Append double value to a string + + @param str the string where to put the value + @param val the value to put in the string + + @return ER_DYNCOL_* return code +*/ + +static enum enum_dyncol_func_result +dynamic_column_double_store(DYNAMIC_COLUMN *str, double val) +{ + if (ma_dynstr_realloc(str, 8)) + return ER_DYNCOL_RESOURCE; + float8store(str->str + str->length, val); + str->length+= 8; + return ER_DYNCOL_OK; +} + + +/** + Read double value of given length from the string + + @param store_it_here The structure to store the value + @param data The string which should be read + @param length The length (in bytes) of the value in nthe string + + @return ER_DYNCOL_* return code +*/ + +static enum enum_dyncol_func_result +dynamic_column_double_read(DYNAMIC_COLUMN_VALUE *store_it_here, + uchar *data, size_t length) +{ + if (length != 8) + return ER_DYNCOL_FORMAT; + float8get(store_it_here->x.double_value, data); + return ER_DYNCOL_OK; +} + + +/** + Append the string with given string value. + + @param str the string where to put the value + @param val the value to put in the string + + @return ER_DYNCOL_* return code +*/ + +static enum enum_dyncol_func_result +dynamic_column_string_store(DYNAMIC_COLUMN *str, LEX_STRING *string, + MARIADB_CHARSET_INFO *charset) +{ + enum enum_dyncol_func_result rc; +#ifdef LIBMARIADB + if ((rc= dynamic_column_var_uint_store(str, charset->nr))) +#else + if ((rc= dynamic_column_var_uint_store(str, charset->number))) +#endif + return rc; + if (ma_dynstr_append_mem(str, string->str, string->length)) + return ER_DYNCOL_RESOURCE; + return ER_DYNCOL_OK; +} + +/** + Append the string with given string value. + + @param str the string where to put the value + @param val the value to put in the string + + @return ER_DYNCOL_* return code +*/ + +static enum enum_dyncol_func_result +dynamic_column_dyncol_store(DYNAMIC_COLUMN *str, LEX_STRING *string) +{ + if (ma_dynstr_append_mem(str, string->str, string->length)) + return ER_DYNCOL_RESOURCE; + return ER_DYNCOL_OK; +} + +/** + Read string value of given length from the packed string + + @param store_it_here The structure to store the value + @param data The packed string which should be read + @param length The length (in bytes) of the value in nthe string + + @return ER_DYNCOL_* return code +*/ + +static enum enum_dyncol_func_result +dynamic_column_string_read(DYNAMIC_COLUMN_VALUE *store_it_here, + uchar *data, size_t length) +{ + size_t len; + uint charset_nr= (uint)dynamic_column_var_uint_get(data, length, &len); + if (len == 0) /* Wrong packed number */ + return ER_DYNCOL_FORMAT; +#ifndef LIBMARIADB + store_it_here->x.string.charset= get_charset_by_nr(charset_nr); +#else + store_it_here->x.string.charset= mariadb_get_charset_by_nr(charset_nr); +#endif + if (store_it_here->x.string.charset == NULL) + return ER_DYNCOL_UNKNOWN_CHARSET; + data+= len; + store_it_here->x.string.value.length= (length-= len); + store_it_here->x.string.value.str= (char*) data; + return ER_DYNCOL_OK; +} + +/** + Read Dynamic columns packet string value of given length + from the packed string + + @param store_it_here The structure to store the value + @param data The packed string which should be read + @param length The length (in bytes) of the value in nthe string + + @return ER_DYNCOL_* return code +*/ + +static enum enum_dyncol_func_result +dynamic_column_dyncol_read(DYNAMIC_COLUMN_VALUE *store_it_here, + uchar *data, size_t length) +{ + store_it_here->x.string.charset= ma_charset_bin; + store_it_here->x.string.value.length= length; + store_it_here->x.string.value.str= (char*) data; + return ER_DYNCOL_OK; +} + +/** + Append the string with given decimal value. + + @param str the string where to put the value + @param val the value to put in the string + + @return ER_DYNCOL_* return code +*/ +#ifndef LIBMARIADB +static enum enum_dyncol_func_result +dynamic_column_decimal_store(DYNAMIC_COLUMN *str, + decimal_t *value) +{ + uint bin_size; + int precision= value->intg + value->frac; + + /* Store decimal zero as empty string */ + if (precision == 0) + return ER_DYNCOL_OK; + + bin_size= decimal_bin_size(precision, value->frac); + if (ma_dynstr_realloc(str, bin_size + 20)) + return ER_DYNCOL_RESOURCE; + + /* The following can't fail as memory is already allocated */ + (void) dynamic_column_var_uint_store(str, value->intg); + (void) dynamic_column_var_uint_store(str, value->frac); + + decimal2bin(value, (uchar *) str->str + str->length, + precision, value->frac); + str->length+= bin_size; + return ER_DYNCOL_OK; +} + + +/** + Prepare the value to be used as decimal. + + @param value The value structure which should be setup. +*/ + +void mariadb_dyncol_prepare_decimal(DYNAMIC_COLUMN_VALUE *value) +{ + value->x.decimal.value.buf= value->x.decimal.buffer; + value->x.decimal.value.len= DECIMAL_BUFF_LENGTH; + /* just to be safe */ + value->type= DYN_COL_DECIMAL; + decimal_make_zero(&value->x.decimal.value); +} + +void dynamic_column_prepare_decimal(DYNAMIC_COLUMN_VALUE *value) +{ + mariadb_dyncol_prepare_decimal(value); +} + + + +/** + Read decimal value of given length from the string + + @param store_it_here The structure to store the value + @param data The string which should be read + @param length The length (in bytes) of the value in nthe string + + @return ER_DYNCOL_* return code +*/ + +static enum enum_dyncol_func_result +dynamic_column_decimal_read(DYNAMIC_COLUMN_VALUE *store_it_here, + uchar *data, size_t length) +{ + size_t intg_len, frac_len; + int intg, frac, precision, scale; + + dynamic_column_prepare_decimal(store_it_here); + /* Decimals 0.0 is stored as a zero length string */ + if (length == 0) + return ER_DYNCOL_OK; /* value contains zero */ + + intg= (int)dynamic_column_var_uint_get(data, length, &intg_len); + data+= intg_len; + frac= (int)dynamic_column_var_uint_get(data, length - intg_len, &frac_len); + data+= frac_len; + + /* Check the size of data is correct */ + precision= intg + frac; + scale= frac; + if (scale < 0 || precision <= 0 || scale > precision || + (length - intg_len - frac_len) > + (size_t) (DECIMAL_BUFF_LENGTH*sizeof(decimal_digit_t)) || + decimal_bin_size(intg + frac, frac) != + (int) (length - intg_len - frac_len)) + return ER_DYNCOL_FORMAT; + + if (bin2decimal(data, &store_it_here->x.decimal.value, precision, scale) != + E_DEC_OK) + return ER_DYNCOL_FORMAT; + return ER_DYNCOL_OK; +} +#endif + +/** + Append the string with given datetime value. + + @param str the string where to put the value + @param value the value to put in the string + + @return ER_DYNCOL_* return code +*/ + +static enum enum_dyncol_func_result +dynamic_column_date_time_store(DYNAMIC_COLUMN *str, MYSQL_TIME *value, + enum enum_dyncol_format format) +{ + enum enum_dyncol_func_result rc; + /* + 0<----year---->00000!<-hours--><---microseconds---> + 12345678901234123412345 1123456789012345612345612345678901234567890 + <123456><123456><123456><123456><123456><123456><123456><123456><123456> + */ + if ((rc= dynamic_column_date_store(str, value)) || + (rc= dynamic_column_time_store(str, value, format))) + return rc; + return ER_DYNCOL_OK; +} + + +/** + Read datetime value of given length from the packed string + + @param store_it_here The structure to store the value + @param data The packed string which should be read + @param length The length (in bytes) of the value in nthe string + + @return ER_DYNCOL_* return code +*/ + +static enum enum_dyncol_func_result +dynamic_column_date_time_read(DYNAMIC_COLUMN_VALUE *store_it_here, + uchar *data, size_t length) +{ + enum enum_dyncol_func_result rc= ER_DYNCOL_FORMAT; + /* + 0<----year---->00000!<-hours--><---microseconds---> + 12345678901234123412345 1123456789012345612345612345678901234567890 + <123456><123456><123456><123456><123456><123456><123456><123456><123456> + */ + if (length != 9 && length != 6) + goto err; + store_it_here->x.time_value.time_type= MYSQL_TIMESTAMP_DATETIME; + if ((rc= dynamic_column_date_read_internal(store_it_here, data, 3)) || + (rc= dynamic_column_time_read_internal(store_it_here, data + 3, + length - 3))) + goto err; + return ER_DYNCOL_OK; + +err: + store_it_here->x.time_value.time_type= MYSQL_TIMESTAMP_ERROR; + return rc; +} + + +/** + Append the string with given time value. + + @param str the string where to put the value + @param value the value to put in the string + + @return ER_DYNCOL_* return code +*/ + +static enum enum_dyncol_func_result +dynamic_column_time_store(DYNAMIC_COLUMN *str, MYSQL_TIME *value, + enum enum_dyncol_format format) +{ + uchar *buf; + if (ma_dynstr_realloc(str, 6)) + return ER_DYNCOL_RESOURCE; + + buf= ((uchar *)str->str) + str->length; + + if (value->time_type == MYSQL_TIMESTAMP_NONE || + value->time_type == MYSQL_TIMESTAMP_ERROR || + value->time_type == MYSQL_TIMESTAMP_DATE) + { + value->neg= 0; + value->second_part= 0; + value->hour= 0; + value->minute= 0; + value->second= 0; + } + DBUG_ASSERT(value->hour <= 838); + DBUG_ASSERT(value->minute <= 59); + DBUG_ASSERT(value->second <= 59); + DBUG_ASSERT(value->second_part <= 999999); + if (format == dyncol_fmt_num || value->second_part) + { + /* + 00000!<-hours--><---microseconds---> + 1123456789012345612345612345678901234567890 + <123456><123456><123456><123456><123456><123456> + */ + buf[0]= (value->second_part & 0xff); + buf[1]= ((value->second_part & 0xff00) >> 8); + buf[2]= (uchar)(((value->second & 0xf) << 4) | + ((value->second_part & 0xf0000) >> 16)); + buf[3]= ((value->minute << 2) | ((value->second & 0x30) >> 4)); + buf[4]= (value->hour & 0xff); + buf[5]= ((value->neg ? 0x4 : 0) | (value->hour >> 8)); + str->length+= 6; + } + else + { + /* + !<-hours--> + 11234567890123456123456 + <123456><123456><123456> + */ + buf[0]= (value->second) | ((value->minute & 0x3) << 6); + buf[1]= (value->minute >> 2) | ((value->hour & 0xf) << 4); + buf[2]= (value->hour >> 4) | (value->neg ? 0x80 : 0); + str->length+= 3; + } + + return ER_DYNCOL_OK; +} + + +/** + Read time value of given length from the packed string + + @param store_it_here The structure to store the value + @param data The packed string which should be read + @param length The length (in bytes) of the value in nthe string + + @return ER_DYNCOL_* return code +*/ + +static enum enum_dyncol_func_result +dynamic_column_time_read(DYNAMIC_COLUMN_VALUE *store_it_here, + uchar *data, size_t length) +{ + store_it_here->x.time_value.year= store_it_here->x.time_value.month= + store_it_here->x.time_value.day= 0; + store_it_here->x.time_value.time_type= MYSQL_TIMESTAMP_TIME; + return dynamic_column_time_read_internal(store_it_here, data, length); +} + +/** + Internal function for reading time part from the string. + + @param store_it_here The structure to store the value + @param data The packed string which should be read + @param length The length (in bytes) of the value in nthe string + + @return ER_DYNCOL_* return code +*/ + +static enum enum_dyncol_func_result +dynamic_column_time_read_internal(DYNAMIC_COLUMN_VALUE *store_it_here, + uchar *data, size_t length) +{ + if (length != 6 && length != 3) + goto err; + if (length == 6) + { + /* + 00000!<-hours--><---microseconds---> + 1123456789012345612345612345678901234567890 + <123456><123456><123456><123456><123456><123456> + */ + store_it_here->x.time_value.second_part= (data[0] | + (data[1] << 8) | + ((data[2] & 0xf) << 16)); + store_it_here->x.time_value.second= ((data[2] >> 4) | + ((data[3] & 0x3) << 4)); + store_it_here->x.time_value.minute= (data[3] >> 2); + store_it_here->x.time_value.hour= (((((uint)data[5]) & 0x3 ) << 8) | data[4]); + store_it_here->x.time_value.neg= ((data[5] & 0x4) ? 1 : 0); + } + else + { + /* + !<-hours--> + 11234567890123456123456 + <123456><123456><123456> + */ + store_it_here->x.time_value.second_part= 0; + store_it_here->x.time_value.second= (data[0] & 0x3f); + store_it_here->x.time_value.minute= (data[0] >> 6) | ((data[1] & 0xf) << 2); + store_it_here->x.time_value.hour= (data[1] >> 4) | ((data[2] & 0x3f) << 4); + store_it_here->x.time_value.neg= ((data[2] & 0x80) ? 1 : 0); + } + if (store_it_here->x.time_value.second > 59 || + store_it_here->x.time_value.minute > 59 || + store_it_here->x.time_value.hour > 838 || + store_it_here->x.time_value.second_part > 999999) + goto err; + return ER_DYNCOL_OK; + +err: + store_it_here->x.time_value.time_type= MYSQL_TIMESTAMP_ERROR; + return ER_DYNCOL_FORMAT; +} + + +/** + Append the string with given date value. + + @param str the string where to put the value + @param value the value to put in the string + + @return ER_DYNCOL_* return code +*/ + +static enum enum_dyncol_func_result +dynamic_column_date_store(DYNAMIC_COLUMN *str, MYSQL_TIME *value) +{ + uchar *buf; + if (ma_dynstr_realloc(str, 3)) + return ER_DYNCOL_RESOURCE; + + buf= ((uchar *)str->str) + str->length; + if (value->time_type == MYSQL_TIMESTAMP_NONE || + value->time_type == MYSQL_TIMESTAMP_ERROR || + value->time_type == MYSQL_TIMESTAMP_TIME) + value->year= value->month= value->day = 0; + DBUG_ASSERT(value->year <= 9999); + DBUG_ASSERT(value->month <= 12); + DBUG_ASSERT(value->day <= 31); + /* + 0<----year----> + 012345678901234123412345 + <123456><123456><123456> + */ + buf[0]= (value->day | + ((value->month & 0x7) << 5)); + buf[1]= ((value->month >> 3) | ((value->year & 0x7F) << 1)); + buf[2]= (value->year >> 7); + str->length+= 3; + return ER_DYNCOL_OK; +} + + + +/** + Read date value of given length from the packed string + + @param store_it_here The structure to store the value + @param data The packed string which should be read + @param length The length (in bytes) of the value in nthe string + + @return ER_DYNCOL_* return code +*/ + +static enum enum_dyncol_func_result +dynamic_column_date_read(DYNAMIC_COLUMN_VALUE *store_it_here, + uchar *data, size_t length) +{ + store_it_here->x.time_value.neg= 0; + store_it_here->x.time_value.second_part= 0; + store_it_here->x.time_value.hour= 0; + store_it_here->x.time_value.minute= 0; + store_it_here->x.time_value.second= 0; + store_it_here->x.time_value.time_type= MYSQL_TIMESTAMP_DATE; + return dynamic_column_date_read_internal(store_it_here, data, length); +} + +/** + Internal function for reading date part from the string. + + @param store_it_here The structure to store the value + @param data The packed string which should be read + @param length The length (in bytes) of the value in nthe string + + @return ER_DYNCOL_* return code +*/ + +static enum enum_dyncol_func_result +dynamic_column_date_read_internal(DYNAMIC_COLUMN_VALUE *store_it_here, + uchar *data, + size_t length) +{ + if (length != 3) + goto err; + /* + 0<----year----> + 12345678901234123412345 + <123456><123456><123456> + */ + store_it_here->x.time_value.day= (data[0] & 0x1f); + store_it_here->x.time_value.month= (((data[1] & 0x1) << 3) | + (data[0] >> 5)); + store_it_here->x.time_value.year= ((((uint)data[2]) << 7) | + (data[1] >> 1)); + if (store_it_here->x.time_value.day > 31 || + store_it_here->x.time_value.month > 12 || + store_it_here->x.time_value.year > 9999) + goto err; + return ER_DYNCOL_OK; + +err: + store_it_here->x.time_value.time_type= MYSQL_TIMESTAMP_ERROR; + return ER_DYNCOL_FORMAT; +} + + +/** + Append the string with given value. + + @param str the string where to put the value + @param value the value to put in the string + + @return ER_DYNCOL_* return code +*/ + +static enum enum_dyncol_func_result +data_store(DYNAMIC_COLUMN *str, DYNAMIC_COLUMN_VALUE *value, + enum enum_dyncol_format format) +{ + switch (value->type) { + case DYN_COL_INT: + return dynamic_column_sint_store(str, value->x.long_value); + case DYN_COL_UINT: + return dynamic_column_uint_store(str, value->x.ulong_value); + case DYN_COL_DOUBLE: + return dynamic_column_double_store(str, value->x.double_value); + case DYN_COL_STRING: + return dynamic_column_string_store(str, &value->x.string.value, + value->x.string.charset); +#ifndef LIBMARIADB + case DYN_COL_DECIMAL: + return dynamic_column_decimal_store(str, &value->x.decimal.value); +#endif + case DYN_COL_DATETIME: + /* date+time in bits: 14 + 4 + 5 + 5 + 6 + 6 40bits = 5 bytes */ + return dynamic_column_date_time_store(str, &value->x.time_value, format); + case DYN_COL_DATE: + /* date in dits: 14 + 4 + 5 = 23bits ~= 3bytes*/ + return dynamic_column_date_store(str, &value->x.time_value); + case DYN_COL_TIME: + /* time in bits: 5 + 6 + 6 = 17bits ~= 3bytes*/ + return dynamic_column_time_store(str, &value->x.time_value, format); + case DYN_COL_DYNCOL: + return dynamic_column_dyncol_store(str, &value->x.string.value); + case DYN_COL_NULL: + break; /* Impossible */ + default: + break; + } + DBUG_ASSERT(0); + return ER_DYNCOL_OK; /* Impossible */ +} + + +/** + Write information to the fixed header + + @param str String where to write the header + @param offset_size Size of offset field in bytes + @param column_count Number of columns +*/ + +static void set_fixed_header(DYNAMIC_COLUMN *str, + uint offset_size, + uint column_count) +{ + DBUG_ASSERT(column_count <= 0xffff); + DBUG_ASSERT(offset_size <= MAX_OFFSET_LENGTH); + str->str[0]= ((str->str[0] & ~DYNCOL_FLG_OFFSET) | + (offset_size - 1)); /* size of offset */ + int2store(str->str + 1, column_count); /* columns number */ + DBUG_ASSERT((str->str[0] & (~DYNCOL_FLG_KNOWN)) == 0); +} + +/** + Adds columns into the empty string + + @param str String where to write the data (the record) + @param hdr Dynamic columns record descriptor + @param column_count Number of columns in the arrays + @param column_keys Array of columns keys (uint or LEX_STRING) + @param values Array of columns values + @param new_str True if we need to allocate new string + + @return ER_DYNCOL_* return code +*/ + +static enum enum_dyncol_func_result +dynamic_new_column_store(DYNAMIC_COLUMN *str, + DYN_HEADER *hdr, + uint column_count, + void *column_keys, + DYNAMIC_COLUMN_VALUE *values, + my_bool new_str) +{ + struct st_service_funcs *fmt= fmt_data + hdr->format; + void **columns_order; + uchar *element; + uint i; + enum enum_dyncol_func_result rc= ER_DYNCOL_RESOURCE; + size_t all_headers_size; + + if (!(columns_order= malloc(sizeof(void*)*column_count))) + return ER_DYNCOL_RESOURCE; + if (new_str || str->str == 0) + { + if (column_count) + { + if (dynamic_column_init_named(str, + fmt->fixed_hdr + + hdr->header_size + + hdr->nmpool_size + + hdr->data_size + + DYNCOL_SYZERESERVE)) + goto err; + } + else + { + dynamic_column_initialize(str); + } + } + else + { + str->length= 0; + if (ma_dynstr_realloc(str, + fmt->fixed_hdr + + hdr->header_size + + hdr->nmpool_size + + hdr->data_size + + DYNCOL_SYZERESERVE)) + goto err; + } + if (!column_count) + { + free(columns_order); + return ER_DYNCOL_OK; + } + + memset(str->str, 0, fmt->fixed_hdr); + str->length= fmt->fixed_hdr; + + /* sort columns for the header */ + for (i= 0, element= (uchar *) column_keys; + i < column_count; + i++, element+= fmt->key_size_in_array) + columns_order[i]= (void *)element; + qsort(columns_order, (size_t)column_count, sizeof(void*), fmt->column_sort); + + /* + For now we don't allow creating two columns with the same number + at the time of create. This can be fixed later to just use the later + by comparing the pointers. + */ + for (i= 0; i < column_count - 1; i++) + { + if ((*fmt->check_limit)(&columns_order[i]) || + (*fmt->column_sort)(&columns_order[i], &columns_order[i + 1]) == 0) + { + rc= ER_DYNCOL_DATA; + goto err; + } + } + if ((*fmt->check_limit)(&columns_order[i])) + { + rc= ER_DYNCOL_DATA; + goto err; + } + + (*fmt->set_fixed_hdr)(str, hdr); + /* reserve place for header and name pool */ + str->length+= hdr->header_size + hdr->nmpool_size; + + hdr->entry= hdr->header; + hdr->name= hdr->nmpool; + all_headers_size= fmt->fixed_hdr + hdr->header_size + hdr->nmpool_size; + for (i= 0; i < column_count; i++) + { + uint ord= (uint)(((uchar*)columns_order[i] - (uchar*)column_keys) / + fmt->key_size_in_array); + if (values[ord].type != DYN_COL_NULL) + { + /* Store header first in the str */ + if ((*fmt->put_header_entry)(hdr, columns_order[i], values + ord, + str->length - all_headers_size)) + { + rc= ER_DYNCOL_FORMAT; + goto err; + } + + /* Store value in 'str + str->length' and increase str->length */ + if ((rc= data_store(str, values + ord, hdr->format))) + goto err; + } + } + rc= ER_DYNCOL_OK; +err: + free(columns_order); + return rc; +} + +/** + Calculate size of header, name pool and data pool + + @param hdr descriptor of dynamic column record + @param column_count number of elements in arrays + @param column_count Number of columns in the arrays + @param column_keys Array of columns keys (uint or LEX_STRING) + @param values Array of columns values + + @return ER_DYNCOL_* return code +*/ + +static enum enum_dyncol_func_result +calc_var_sizes(DYN_HEADER *hdr, + uint column_count, + void *column_keys, + DYNAMIC_COLUMN_VALUE *values) +{ + struct st_service_funcs *fmt= fmt_data + hdr->format; + uint i; + hdr->nmpool_size= hdr->data_size= 0; + hdr->column_count= 0; + for (i= 0; i < column_count; i++) + { + if (values[i].type != DYN_COL_NULL) + { + size_t tmp; + hdr->column_count++; + hdr->data_size+= (tmp= dynamic_column_value_len(values + i, + hdr->format)); + if (tmp == (size_t) ~0) + return ER_DYNCOL_DATA; + hdr->nmpool_size+= (*fmt->name_size)(column_keys, i); + } + } + /* + We can handle data up to 0x1fffffff (old format) and + 0xfffffffff (new format) bytes now. + */ + if ((hdr->offset_size= fmt->dynamic_column_offset_bytes(hdr->data_size)) >= + fmt->max_offset_size) + return ER_DYNCOL_LIMIT; + + /* header entry is column number or string pointer + offset & type */ + hdr->entry_size= fmt->fixed_hdr_entry + hdr->offset_size; + hdr->header_size= hdr->column_count * hdr->entry_size; + return ER_DYNCOL_OK; +} + +/** + Create packed string which contains given columns (internal multi format) + + @param str String where to write the data + @param column_count Number of columns in the arrays + @param column_keys Array of columns keys (format dependent) + @param values Array of columns values + @param new_str True if we need allocate new string + @param string_keys keys are strings + + @return ER_DYNCOL_* return code +*/ + +static enum enum_dyncol_func_result +dynamic_column_create_many_internal_fmt(DYNAMIC_COLUMN *str, + uint column_count, + void *column_keys, + DYNAMIC_COLUMN_VALUE *values, + my_bool new_str, + my_bool string_keys) +{ + DYN_HEADER header; + enum enum_dyncol_func_result rc; + memset(&header, 0, sizeof(header)); + header.format= (string_keys ? 1 : 0); + + if (new_str) + { + /* to make dynstr_free() working in case of errors */ + memset(str, 0, sizeof(DYNAMIC_COLUMN)); + } + + if ((rc= calc_var_sizes(&header, column_count, column_keys, values)) < 0) + return rc; + + return dynamic_new_column_store(str, &header, + column_count, + column_keys, values, + new_str); +} + + +/** + Create packed string which contains given columns + + @param str String where to write the data + @param column_count Number of columns in the arrays + @param column_numbers Array of columns numbers + @param values Array of columns values + + @return ER_DYNCOL_* return code +*/ + +enum enum_dyncol_func_result +dynamic_column_create_many(DYNAMIC_COLUMN *str, + uint column_count, + uint *column_numbers, + DYNAMIC_COLUMN_VALUE *values) +{ + return(dynamic_column_create_many_internal_fmt(str, column_count, + column_numbers, values, + TRUE, FALSE)); +} + +/** + Create packed string which contains given columns + + @param str String where to write the data + @param column_count Number of columns in the arrays + @param column_numbers Array of columns numbers + @param values Array of columns values + @param new_string True if we need allocate new string + + @return ER_DYNCOL_* return code +*/ + +enum enum_dyncol_func_result +mariadb_dyncol_create_many_num(DYNAMIC_COLUMN *str, + uint column_count, + uint *column_numbers, + DYNAMIC_COLUMN_VALUE *values, + my_bool new_string) +{ + return(dynamic_column_create_many_internal_fmt(str, column_count, + column_numbers, values, + new_string, FALSE)); +} + +/** + Create packed string which contains given columns + + @param str String where to write the data + @param column_count Number of columns in the arrays + @param column_keys Array of columns keys + @param values Array of columns value + @param new_string True if we need allocate new string + + @return ER_DYNCOL_* return code +*/ + +enum enum_dyncol_func_result +mariadb_dyncol_create_many_named(DYNAMIC_COLUMN *str, + uint column_count, + LEX_STRING *column_keys, + DYNAMIC_COLUMN_VALUE *values, + my_bool new_string) +{ + return(dynamic_column_create_many_internal_fmt(str, column_count, + column_keys, values, + new_string, TRUE)); +} + +/** + Create packed string which contains given column + + @param str String where to write the data + @param column_number Column number + @param value The columns value + + @return ER_DYNCOL_* return code +*/ + +enum enum_dyncol_func_result +dynamic_column_create(DYNAMIC_COLUMN *str, uint column_nr, + DYNAMIC_COLUMN_VALUE *value) +{ + return(dynamic_column_create_many(str, 1, &column_nr, value)); +} + + +/** + Calculate length of data between given two header entries + + @param entry Pointer to the first entry + @param entry_next Pointer to the last entry + @param header_end Pointer to the header end + @param offset_size Size of offset field in bytes + @param last_offset Size of the data segment + + @return number of bytes +*/ + +static size_t get_length_interval(uchar *entry, uchar *entry_next, + uchar *header_end, size_t offset_size, + size_t last_offset) +{ + size_t offset, offset_next; + DYNAMIC_COLUMN_TYPE type, type_next; + DBUG_ASSERT(entry < entry_next); + + if (type_and_offset_read_num(&type, &offset, entry + COLUMN_NUMBER_SIZE, + offset_size)) + return DYNCOL_OFFSET_ERROR; + if (entry_next >= header_end) + return (last_offset - offset); + if (type_and_offset_read_num(&type_next, &offset_next, + entry_next + COLUMN_NUMBER_SIZE, offset_size)) + return DYNCOL_OFFSET_ERROR; + return (offset_next - offset); +} + + +/** + Calculate length of data between given hdr->entry and next_entry + + @param hdr descriptor of dynamic column record + @param next_entry next header entry (can point just after last header + entry) + + @return number of bytes +*/ + +static size_t hdr_interval_length(DYN_HEADER *hdr, uchar *next_entry) +{ + struct st_service_funcs *fmt= fmt_data + hdr->format; + size_t next_entry_offset; + DYNAMIC_COLUMN_TYPE next_entry_type; + DBUG_ASSERT(hdr->entry < next_entry); + DBUG_ASSERT(hdr->entry >= hdr->header); + DBUG_ASSERT(next_entry <= hdr->header + hdr->header_size); + + if ((*fmt->type_and_offset_read)(&hdr->type, &hdr->offset, + hdr->entry + fmt->fixed_hdr_entry, + hdr->offset_size)) + return DYNCOL_OFFSET_ERROR; + if (next_entry == hdr->header + hdr->header_size) + return hdr->data_size - hdr->offset; + if ((*fmt->type_and_offset_read)(&next_entry_type, &next_entry_offset, + next_entry + fmt->fixed_hdr_entry, + hdr->offset_size)) + return DYNCOL_OFFSET_ERROR; + return (next_entry_offset - hdr->offset); +} + + +/** + Comparator function for references to header entries for qsort +*/ + +static int header_compar_num(const void *a, const void *b) +{ + uint va= uint2korr((uchar*)a), vb= uint2korr((uchar*)b); + return (va > vb ? 1 : (va < vb ? -1 : 0)); +} + + +/** + Find entry in the numeric format header by the column number + + @param hdr descriptor of dynamic column record + @param key number to find + + @return pointer to the entry or NULL +*/ + +static uchar *find_entry_num(DYN_HEADER *hdr, uint key) +{ + uchar header_entry[2+4]; + DBUG_ASSERT(hdr->format == dyncol_fmt_num); + int2store(header_entry, key); + return hdr->entry= bsearch(header_entry, hdr->header, + (size_t)hdr->column_count, + hdr->entry_size, &header_compar_num); +} + + +/** + Read name from header entry + + @param hdr descriptor of dynamic column record + @param entry pointer to the header entry + @param name where to put name + + @return 0 ok + @return 1 error in data +*/ + +static my_bool read_name(DYN_HEADER *hdr, uchar *entry, LEX_STRING *name) +{ + size_t nmoffset= uint2korr(entry); + uchar *next_entry= entry + hdr->entry_size; + + if (nmoffset > hdr->nmpool_size) + return 1; + + name->str= (char *)hdr->nmpool + nmoffset; + if (next_entry == hdr->header + hdr->header_size) + name->length= hdr->nmpool_size - nmoffset; + else + { + size_t next_nmoffset= uint2korr(next_entry); + if (next_nmoffset > hdr->nmpool_size) + return 1; + name->length= next_nmoffset - nmoffset; + } + return 0; +} + + +/** + Find entry in the names format header by the column number + + @param hdr descriptor of dynamic column record + @param key name to find + + @return pointer to the entry or NULL +*/ +static uchar *find_entry_named(DYN_HEADER *hdr, LEX_STRING *key) +{ + uchar *min= hdr->header; + uchar *max= hdr->header + (hdr->column_count - 1) * hdr->entry_size; + uchar *mid; + DBUG_ASSERT(hdr->format == dyncol_fmt_str); + DBUG_ASSERT(hdr->nmpool != NULL); + while (max >= min) + { + LEX_STRING name; + int cmp; + mid= hdr->header + ((min - hdr->header) + + (max - hdr->header)) / + 2 / + hdr->entry_size * hdr->entry_size; + if (read_name(hdr, mid, &name)) + return NULL; + cmp= mariadb_dyncol_column_cmp_named(&name, key); + if (cmp < 0) + min= mid + hdr->entry_size; + else if (cmp > 0) + max= mid - hdr->entry_size; + else + return mid; + } + return NULL; +} + + +/** + Write number in the buffer (backward direction - starts from the buffer end) + + @return pointer on the number beginning +*/ + +static char *backwritenum(char *chr, uint numkey) +{ + if (numkey == 0) + *(--chr)= '0'; + else + while (numkey > 0) + { + *(--chr)= '0' + numkey % 10; + numkey/= 10; + } + return chr; +} + + +/** + Find column and fill information about it + + @param hdr descriptor of dynamic column record + @param numkey Number of the column to fetch (if strkey is NULL) + @param strkey Name of the column to fetch (or NULL) + + @return 0 ok + @return 1 error in data +*/ + +static my_bool +find_column(DYN_HEADER *hdr, uint numkey, LEX_STRING *strkey) +{ + LEX_STRING nmkey; + char nmkeybuff[DYNCOL_NUM_CHAR]; /* to fit max 2 bytes number */ + DBUG_ASSERT(hdr->header != NULL); + + if (hdr->header + hdr->header_size > hdr->data_end) + return TRUE; + + /* fix key */ + if (hdr->format == dyncol_fmt_num && strkey != NULL) + { + char *end; + numkey= (uint) strtoul(strkey->str, &end, 10); + if (end != strkey->str + strkey->length) + { + /* we can't find non-numeric key among numeric ones */ + hdr->type= DYN_COL_NULL; + return 0; + } + } + else if (hdr->format == dyncol_fmt_str && strkey == NULL) + { + nmkey.str= backwritenum(nmkeybuff + sizeof(nmkeybuff), numkey); + nmkey.length= (nmkeybuff + sizeof(nmkeybuff)) - nmkey.str; + strkey= &nmkey; + } + if (hdr->format == dyncol_fmt_num) + hdr->entry= find_entry_num(hdr, numkey); + else + hdr->entry= find_entry_named(hdr, strkey); + + if (!hdr->entry) + { + /* Column not found */ + hdr->type= DYN_COL_NULL; + return 0; + } + hdr->length= hdr_interval_length(hdr, hdr->entry + hdr->entry_size); + hdr->data= hdr->dtpool + hdr->offset; + /* + Check that the found data is within the ranges. This can happen if + we get data with wrong offsets. + */ + if (hdr->length == DYNCOL_OFFSET_ERROR || + hdr->length > INT_MAX || hdr->offset > hdr->data_size) + return 1; + + return 0; +} + + +/** + Read and check the header of the dynamic string + + @param hdr descriptor of dynamic column record + @param str Dynamic string + + @retval FALSE OK + @retval TRUE error + + Note + We don't check for str->length == 0 as all code that calls this + already have handled this case. +*/ + +static inline my_bool read_fixed_header(DYN_HEADER *hdr, + DYNAMIC_COLUMN *str) +{ + DBUG_ASSERT(str != NULL && str->length != 0); + if ((str->length < 1) || + (str->str[0] & (~DYNCOL_FLG_KNOWN))) + return 1; + hdr->format= ((str->str[0] & DYNCOL_FLG_NAMES) ? + dyncol_fmt_str: + dyncol_fmt_num); + if ((str->length < fmt_data[hdr->format].fixed_hdr)) + return 1; /* Wrong header */ + hdr->offset_size= (str->str[0] & DYNCOL_FLG_OFFSET) + 1 + + (hdr->format == dyncol_fmt_str ? 1 : 0); + hdr->column_count= uint2korr(str->str + 1); + if (hdr->format == dyncol_fmt_str) + hdr->nmpool_size= uint2korr(str->str + 3); // only 2 bytes supported for now + else + hdr->nmpool_size= 0; + return 0; +} + + +/** + Get dynamic column value by column number + + @param str The packed string to extract the column + @param column_nr Number of column to fetch + @param store_it_here Where to store the extracted value + + @return ER_DYNCOL_* return code +*/ + +enum enum_dyncol_func_result +dynamic_column_get(DYNAMIC_COLUMN *str, uint column_nr, + DYNAMIC_COLUMN_VALUE *store_it_here) +{ + return dynamic_column_get_internal(str, store_it_here, column_nr, NULL); +} + +enum enum_dyncol_func_result +mariadb_dyncol_get_num(DYNAMIC_COLUMN *str, uint column_nr, + DYNAMIC_COLUMN_VALUE *store_it_here) +{ + return dynamic_column_get_internal(str, store_it_here, column_nr, NULL); +} + + +/** + Get dynamic column value by name + + @param str The packed string to extract the column + @param name Name of column to fetch + @param store_it_here Where to store the extracted value + + @return ER_DYNCOL_* return code +*/ + +enum enum_dyncol_func_result +mariadb_dyncol_get_named(DYNAMIC_COLUMN *str, LEX_STRING *name, + DYNAMIC_COLUMN_VALUE *store_it_here) +{ + DBUG_ASSERT(name != NULL); + return dynamic_column_get_internal(str, store_it_here, 0, name); +} + + +static enum enum_dyncol_func_result +dynamic_column_get_value(DYN_HEADER *hdr, DYNAMIC_COLUMN_VALUE *store_it_here) +{ + static enum enum_dyncol_func_result rc; + switch ((store_it_here->type= hdr->type)) { + case DYN_COL_INT: + rc= dynamic_column_sint_read(store_it_here, hdr->data, hdr->length); + break; + case DYN_COL_UINT: + rc= dynamic_column_uint_read(store_it_here, hdr->data, hdr->length); + break; + case DYN_COL_DOUBLE: + rc= dynamic_column_double_read(store_it_here, hdr->data, hdr->length); + break; + case DYN_COL_STRING: + rc= dynamic_column_string_read(store_it_here, hdr->data, hdr->length); + break; +#ifndef LIBMARIADB + case DYN_COL_DECIMAL: + rc= dynamic_column_decimal_read(store_it_here, hdr->data, hdr->length); + break; +#endif + case DYN_COL_DATETIME: + rc= dynamic_column_date_time_read(store_it_here, hdr->data, + hdr->length); + break; + case DYN_COL_DATE: + rc= dynamic_column_date_read(store_it_here, hdr->data, hdr->length); + break; + case DYN_COL_TIME: + rc= dynamic_column_time_read(store_it_here, hdr->data, hdr->length); + break; + case DYN_COL_NULL: + rc= ER_DYNCOL_OK; + break; + case DYN_COL_DYNCOL: + rc= dynamic_column_dyncol_read(store_it_here, hdr->data, hdr->length); + break; + default: + rc= ER_DYNCOL_FORMAT; + store_it_here->type= DYN_COL_NULL; + break; + } + return rc; +} + +/** + Get dynamic column value by number or name + + @param str The packed string to extract the column + @param store_it_here Where to store the extracted value + @param numkey Number of the column to fetch (if strkey is NULL) + @param strkey Name of the column to fetch (or NULL) + + @return ER_DYNCOL_* return code +*/ + +static enum enum_dyncol_func_result +dynamic_column_get_internal(DYNAMIC_COLUMN *str, + DYNAMIC_COLUMN_VALUE *store_it_here, + uint num_key, LEX_STRING *str_key) +{ + DYN_HEADER header; + enum enum_dyncol_func_result rc= ER_DYNCOL_FORMAT; + memset(&header, 0, sizeof(header)); + + if (str->length == 0) + goto null; + + if ((rc= init_read_hdr(&header, str)) < 0) + goto err; + + if (header.column_count == 0) + goto null; + + if (find_column(&header, num_key, str_key)) + goto err; + + rc= dynamic_column_get_value(&header, store_it_here); + return rc; + +null: + rc= ER_DYNCOL_OK; +err: + store_it_here->type= DYN_COL_NULL; + return rc; +} + + +/** + Check existence of the column in the packed string (by number) + + @param str The packed string to check the column + @param column_nr Number of column to check + + @return ER_DYNCOL_* return code +*/ + +enum enum_dyncol_func_result +mariadb_dyncol_exists_num(DYNAMIC_COLUMN *str, uint column_nr) +{ + return dynamic_column_exists_internal(str, column_nr, NULL); +} + +/** + Check existence of the column in the packed string (by name) + + @param str The packed string to check the column + @param name Name of column to check + + @return ER_DYNCOL_* return code +*/ + +enum enum_dyncol_func_result +mariadb_dyncol_exists_named(DYNAMIC_COLUMN *str, LEX_STRING *name) +{ + DBUG_ASSERT(name != NULL); + return dynamic_column_exists_internal(str, 0, name); +} + + +/** + Check existence of the column in the packed string (by name of number) + + @param str The packed string to check the column + @param num_key Number of the column to fetch (if strkey is NULL) + @param str_key Name of the column to fetch (or NULL) + + @return ER_DYNCOL_* return code +*/ + +static enum enum_dyncol_func_result +dynamic_column_exists_internal(DYNAMIC_COLUMN *str, uint num_key, + LEX_STRING *str_key) +{ + DYN_HEADER header; + enum enum_dyncol_func_result rc; + memset(&header, 0, sizeof(header)); + + if (str->length == 0) + return ER_DYNCOL_NO; /* no columns */ + + if ((rc= init_read_hdr(&header, str)) < 0) + return rc; + + if (header.column_count == 0) + return ER_DYNCOL_NO; /* no columns */ + + if (find_column(&header, num_key, str_key)) + return ER_DYNCOL_FORMAT; + + return (header.type != DYN_COL_NULL ? ER_DYNCOL_YES : ER_DYNCOL_NO); +} + + +/** + List not-null columns in the packed string (only numeric format) + + @param str The packed string + @param array_of_uint Where to put reference on created array + + @return ER_DYNCOL_* return code +*/ +enum enum_dyncol_func_result +dynamic_column_list(DYNAMIC_COLUMN *str, DYNAMIC_ARRAY *array_of_uint) +{ + DYN_HEADER header; + uchar *read; + uint i; + enum enum_dyncol_func_result rc; + + memset(array_of_uint, 0, sizeof(*array_of_uint)); /* In case of errors */ + if (str->length == 0) + return ER_DYNCOL_OK; /* no columns */ + + if ((rc= init_read_hdr(&header, str)) < 0) + return rc; + + if (header.format != dyncol_fmt_num) + return ER_DYNCOL_FORMAT; + + if (header.entry_size * header.column_count + FIXED_HEADER_SIZE > + str->length) + return ER_DYNCOL_FORMAT; + + if (ma_init_dynamic_array(array_of_uint, sizeof(uint), header.column_count, 0)) + return ER_DYNCOL_RESOURCE; + + for (i= 0, read= header.header; + i < header.column_count; + i++, read+= header.entry_size) + { + uint nm= uint2korr(read); + /* Insert can't never fail as it's pre-allocated above */ + (void) ma_insert_dynamic(array_of_uint, (uchar *)&nm); + } + return ER_DYNCOL_OK; +} + +/** + List not-null columns in the packed string (only numeric format) + + @param str The packed string + @param array_of_uint Where to put reference on created array + + @return ER_DYNCOL_* return code +*/ +enum enum_dyncol_func_result +mariadb_dyncol_list_num(DYNAMIC_COLUMN *str, uint *count, uint **nums) +{ + DYN_HEADER header; + uchar *read; + uint i; + enum enum_dyncol_func_result rc; + + (*nums)= 0; (*count)= 0; /* In case of errors */ + if (str->length == 0) + return ER_DYNCOL_OK; /* no columns */ + + if ((rc= init_read_hdr(&header, str)) < 0) + return rc; + + if (header.format != dyncol_fmt_num) + return ER_DYNCOL_FORMAT; + + if (header.entry_size * header.column_count + FIXED_HEADER_SIZE > + str->length) + return ER_DYNCOL_FORMAT; + + if (!((*nums)= (uint *)malloc(sizeof(uint) * header.column_count))) + return ER_DYNCOL_RESOURCE; + + for (i= 0, read= header.header; + i < header.column_count; + i++, read+= header.entry_size) + { + (*nums)[i]= uint2korr(read); + } + (*count)= header.column_count; + return ER_DYNCOL_OK; +} + +/** + List not-null columns in the packed string (any format) + + @param str The packed string + @param count Number of names in the list + @param names Where to put names list (should be freed) + + @return ER_DYNCOL_* return code +*/ + +enum enum_dyncol_func_result +mariadb_dyncol_list_named(DYNAMIC_COLUMN *str, uint *count, LEX_STRING **names) +{ + DYN_HEADER header; + uchar *read; + char *pool; + struct st_service_funcs *fmt; + uint i; + enum enum_dyncol_func_result rc; + + (*names)= 0; (*count)= 0; + + if (str->length == 0) + return ER_DYNCOL_OK; /* no columns */ + + if ((rc= init_read_hdr(&header, str)) < 0) + return rc; + + fmt= fmt_data + header.format; + + if (header.entry_size * header.column_count + fmt->fixed_hdr > + str->length) + return ER_DYNCOL_FORMAT; + + if (header.format == dyncol_fmt_num) + *names= (LEX_STRING *)malloc(sizeof(LEX_STRING) * header.column_count + + DYNCOL_NUM_CHAR * header.column_count); + else + *names= (LEX_STRING *)malloc(sizeof(LEX_STRING) * header.column_count + + header.nmpool_size + header.column_count); + if (!(*names)) + return ER_DYNCOL_RESOURCE; + pool= ((char *)(*names)) + sizeof(LEX_STRING) * header.column_count; + + for (i= 0, read= header.header; + i < header.column_count; + i++, read+= header.entry_size) + { + if (header.format == dyncol_fmt_num) + { + uint nm= uint2korr(read); + (*names)[i].str= pool; + pool+= DYNCOL_NUM_CHAR; + (*names)[i].length= + ma_ll2str(nm, (*names)[i].str, 10) - (*names)[i].str; + } + else + { + LEX_STRING tmp; + if (read_name(&header, read, &tmp)) + return ER_DYNCOL_FORMAT; + (*names)[i].length= tmp.length; + (*names)[i].str= pool; + pool+= tmp.length + 1; + memcpy((*names)[i].str, (const void *)tmp.str, tmp.length); + (*names)[i].str[tmp.length]= '\0'; // just for safety + } + } + (*count)= header.column_count; + return ER_DYNCOL_OK; +} + +/** + Find the place of the column in the header or place where it should be put + + @param hdr descriptor of dynamic column record + @param key Name or number of column to fetch + (depends on string_key) + @param string_key True if we gave pointer to LEX_STRING. + + @retval TRUE found + @retval FALSE pointer set to the next row +*/ + +static my_bool +find_place(DYN_HEADER *hdr, void *key, my_bool string_keys) +{ + uint mid, start, end, val; + int UNINIT_VAR(flag); + LEX_STRING str; + char buff[DYNCOL_NUM_CHAR]; + my_bool need_conversion= ((string_keys ? dyncol_fmt_str : dyncol_fmt_num) != + hdr->format); + /* new format can't be numeric if the old one is names */ + DBUG_ASSERT(string_keys || + hdr->format == dyncol_fmt_num); + + start= 0; + end= hdr->column_count -1; + mid= 1; + while (start != end) + { + uint val; + mid= (start + end) / 2; + hdr->entry= hdr->header + mid * hdr->entry_size; + if (!string_keys) + { + val= uint2korr(hdr->entry); + flag= CMP_NUM(*((uint *)key), val); + } + else + { + if (need_conversion) + { + str.str= backwritenum(buff + sizeof(buff), uint2korr(hdr->entry)); + str.length= (buff + sizeof(buff)) - str.str; + } + else + { + DBUG_ASSERT(hdr->format == dyncol_fmt_str); + if (read_name(hdr, hdr->entry, &str)) + return 0; + } + flag= mariadb_dyncol_column_cmp_named((LEX_STRING *)key, &str); + } + if (flag <= 0) + end= mid; + else + start= mid + 1; + } + hdr->entry= hdr->header + start * hdr->entry_size; + if (start != mid) + { + if (!string_keys) + { + val= uint2korr(hdr->entry); + flag= CMP_NUM(*((uint *)key), val); + } + else + { + if (need_conversion) + { + str.str= backwritenum(buff + sizeof(buff), uint2korr(hdr->entry)); + str.length= (buff + sizeof(buff)) - str.str; + } + else + { + DBUG_ASSERT(hdr->format == dyncol_fmt_str); + if (read_name(hdr, hdr->entry, &str)) + return 0; + } + flag= mariadb_dyncol_column_cmp_named((LEX_STRING *)key, &str); + } + } + if (flag > 0) + hdr->entry+= hdr->entry_size; /* Point at next bigger key */ + return flag == 0; +} + + +/* + It is internal structure which describes a plan of changing the record + of dynamic columns +*/ + +typedef enum {PLAN_REPLACE, PLAN_ADD, PLAN_DELETE, PLAN_NOP} PLAN_ACT; + +struct st_plan { + DYNAMIC_COLUMN_VALUE *val; + void *key; + uchar *place; + size_t length; + long long hdelta, ddelta, ndelta; + long long mv_offset, mv_length; + uint mv_end; + PLAN_ACT act; +}; +typedef struct st_plan PLAN; + + +/** + Sort function for plan by column number +*/ + +static int plan_sort_num(const void *a, const void *b) +{ + return *((uint *)((PLAN *)a)->key) - *((uint *)((PLAN *)b)->key); +} + + +/** + Sort function for plan by column name +*/ + +static int plan_sort_named(const void *a, const void *b) +{ + return mariadb_dyncol_column_cmp_named((LEX_STRING *)((PLAN *)a)->key, + (LEX_STRING *)((PLAN *)b)->key); +} + +#define DELTA_CHECK(S, D, C) \ + if ((S) == 0) \ + (S)= (D); \ + else if (((S) > 0 && (D) < 0) || \ + ((S) < 0 && (D) > 0)) \ + { \ + (C)= TRUE; \ + } + +/** + Update dynamic column by copying in a new record (string). + + @param str Dynamic column record to change + @param plan Plan of changing the record + @param add_column_count number of records in the plan array. + @param hdr descriptor of old dynamic column record + @param new_hdr descriptor of new dynamic column record + @param convert need conversion from numeric to names format + + @return ER_DYNCOL_* return code +*/ + +static enum enum_dyncol_func_result +dynamic_column_update_copy(DYNAMIC_COLUMN *str, PLAN *plan, + uint add_column_count, + DYN_HEADER *hdr, DYN_HEADER *new_hdr, + my_bool convert) +{ + DYNAMIC_COLUMN tmp; + struct st_service_funcs *fmt= fmt_data + hdr->format, + *new_fmt= fmt_data + new_hdr->format; + uint i, j, k; + size_t all_headers_size; + + if (dynamic_column_init_named(&tmp, + (new_fmt->fixed_hdr + new_hdr->header_size + + new_hdr->nmpool_size + + new_hdr->data_size + DYNCOL_SYZERESERVE))) + { + return ER_DYNCOL_RESOURCE; + } + memset(tmp.str, 0, new_fmt->fixed_hdr); + (*new_fmt->set_fixed_hdr)(&tmp, new_hdr); + /* Adjust tmp to contain whole the future header */ + tmp.length= new_fmt->fixed_hdr + new_hdr->header_size + new_hdr->nmpool_size; + + + /* + Copy data to the new string + i= index in array of changes + j= index in packed string header index + */ + new_hdr->entry= new_hdr->header; + new_hdr->name= new_hdr->nmpool; + all_headers_size= new_fmt->fixed_hdr + + new_hdr->header_size + new_hdr->nmpool_size; + for (i= 0, j= 0; i < add_column_count || j < hdr->column_count; i++) + { + size_t first_offset= 0; + uint start= j, end; + + /* + Search in i and j for the next column to add from i and where to + add. + */ + + while (i < add_column_count && plan[i].act == PLAN_NOP) + i++; /* skip NOP */ + + if (i == add_column_count) + j= end= hdr->column_count; + else + { + /* + old data portion. We don't need to check that j < column_count + as plan[i].place is guaranteed to have a pointer inside the + data. + */ + while (hdr->header + j * hdr->entry_size < plan[i].place) + j++; + end= j; + if ((plan[i].act == PLAN_REPLACE || plan[i].act == PLAN_DELETE)) + j++; /* data at 'j' will be removed */ + } + + /* + Adjust all headers since last loop. + We have to do this as the offset for data has moved + */ + for (k= start; k < end; k++) + { + uchar *read= hdr->header + k * hdr->entry_size; + void *key; + LEX_STRING name; + size_t offs; + uint nm; + DYNAMIC_COLUMN_TYPE tp; + char buff[DYNCOL_NUM_CHAR]; + + if (hdr->format == dyncol_fmt_num) + { + if (convert) + { + name.str= backwritenum(buff + sizeof(buff), uint2korr(read)); + name.length= (buff + sizeof(buff)) - name.str; + key= &name; + } + else + { + nm= uint2korr(read); /* Column nummber */ + key= &nm; + } + } + else + { + if (read_name(hdr, read, &name)) + goto err; + key= &name; + } + if (fmt->type_and_offset_read(&tp, &offs, + read + fmt->fixed_hdr_entry, + hdr->offset_size)) + goto err; + if (k == start) + first_offset= offs; + else if (offs < first_offset) + goto err; + + offs+= (size_t)plan[i].ddelta; + { + DYNAMIC_COLUMN_VALUE val; + val.type= tp; // only the type used in the header + if ((*new_fmt->put_header_entry)(new_hdr, key, &val, offs)) + goto err; + } + } + + /* copy first the data that was not replaced in original packed data */ + if (start < end) + { + size_t data_size; + /* Add old data last in 'tmp' */ + hdr->entry= hdr->header + start * hdr->entry_size; + data_size= + hdr_interval_length(hdr, hdr->header + end * hdr->entry_size); + if (data_size == DYNCOL_OFFSET_ERROR || + (long) data_size < 0 || + data_size > hdr->data_size - first_offset) + goto err; + + memcpy(tmp.str + tmp.length, (char *)hdr->dtpool + first_offset, + data_size); + tmp.length+= data_size; + } + + /* new data adding */ + if (i < add_column_count) + { + if( plan[i].act == PLAN_ADD || plan[i].act == PLAN_REPLACE) + { + if ((*new_fmt->put_header_entry)(new_hdr, plan[i].key, + plan[i].val, + tmp.length - all_headers_size)) + goto err; + data_store(&tmp, plan[i].val, new_hdr->format); /* Append new data */ + } + } + } + dynamic_column_column_free(str); + *str= tmp; + return ER_DYNCOL_OK; +err: + dynamic_column_column_free(&tmp); + return ER_DYNCOL_FORMAT; +} + +static enum enum_dyncol_func_result +dynamic_column_update_move_left(DYNAMIC_COLUMN *str, PLAN *plan, + size_t offset_size, + size_t entry_size, + size_t header_size, + size_t new_offset_size, + size_t new_entry_size, + size_t new_header_size, + uint column_count, + uint new_column_count, + uint add_column_count, + uchar *header_end, + size_t max_offset) +{ + uchar *write; + uchar *header_base= (uchar *)str->str + FIXED_HEADER_SIZE; + uint i, j, k; + size_t curr_offset; + + write= (uchar *)str->str + FIXED_HEADER_SIZE; + set_fixed_header(str, (uint)new_offset_size, new_column_count); + + /* + Move headers first. + i= index in array of changes + j= index in packed string header index + */ + for (curr_offset= 0, i= 0, j= 0; + i < add_column_count || j < column_count; + i++) + { + size_t UNINIT_VAR(first_offset); + uint start= j, end; + + /* + Search in i and j for the next column to add from i and where to + add. + */ + + while (i < add_column_count && plan[i].act == PLAN_NOP) + i++; /* skip NOP */ + + if (i == add_column_count) + j= end= column_count; + else + { + /* + old data portion. We don't need to check that j < column_count + as plan[i].place is guaranteed to have a pointer inside the + data. + */ + while (header_base + j * entry_size < plan[i].place) + j++; + end= j; + if ((plan[i].act == PLAN_REPLACE || plan[i].act == PLAN_DELETE)) + j++; /* data at 'j' will be removed */ + } + plan[i].mv_end= end; + + { + DYNAMIC_COLUMN_TYPE tp; + if (type_and_offset_read_num(&tp, &first_offset, + header_base + start * entry_size + + COLUMN_NUMBER_SIZE, offset_size)) + return ER_DYNCOL_FORMAT; + } + /* find data to be moved */ + if (start < end) + { + size_t data_size= + get_length_interval(header_base + start * entry_size, + header_base + end * entry_size, + header_end, offset_size, max_offset); + if (data_size == DYNCOL_OFFSET_ERROR || + (long) data_size < 0 || + data_size > max_offset - first_offset) + { + str->length= 0; // just something valid + return ER_DYNCOL_FORMAT; + } + DBUG_ASSERT(curr_offset == first_offset + plan[i].ddelta); + plan[i].mv_offset= first_offset; + plan[i].mv_length= data_size; + curr_offset+= data_size; + } + else + { + plan[i].mv_length= 0; + plan[i].mv_offset= curr_offset; + } + + if (plan[i].ddelta == 0 && offset_size == new_offset_size && + plan[i].act != PLAN_DELETE) + write+= entry_size * (end - start); + else + { + /* + Adjust all headers since last loop. + We have to do this as the offset for data has moved + */ + for (k= start; k < end; k++) + { + uchar *read= header_base + k * entry_size; + size_t offs; + uint nm; + DYNAMIC_COLUMN_TYPE tp; + + nm= uint2korr(read); /* Column nummber */ + if (type_and_offset_read_num(&tp, &offs, read + COLUMN_NUMBER_SIZE, + offset_size)) + return ER_DYNCOL_FORMAT; + + if (k > start && offs < first_offset) + { + str->length= 0; // just something valid + return ER_DYNCOL_FORMAT; + } + + offs+= (size_t)plan[i].ddelta; + int2store(write, nm); + /* write rest of data at write + COLUMN_NUMBER_SIZE */ + type_and_offset_store_num(write, new_offset_size, tp, offs); + write+= new_entry_size; + } + } + + /* new data adding */ + if (i < add_column_count) + { + if( plan[i].act == PLAN_ADD || plan[i].act == PLAN_REPLACE) + { + int2store(write, *((uint *)plan[i].key)); + type_and_offset_store_num(write, new_offset_size, + plan[i].val[0].type, + curr_offset); + write+= new_entry_size; + curr_offset+= plan[i].length; + } + } + } + + /* + Move data. + i= index in array of changes + j= index in packed string header index + */ + str->length= (FIXED_HEADER_SIZE + new_header_size); + for (i= 0, j= 0; + i < add_column_count || j < column_count; + i++) + { + uint start= j, end; + + /* + Search in i and j for the next column to add from i and where to + add. + */ + + while (i < add_column_count && plan[i].act == PLAN_NOP) + i++; /* skip NOP */ + + j= end= plan[i].mv_end; + if (i != add_column_count && + (plan[i].act == PLAN_REPLACE || plan[i].act == PLAN_DELETE)) + j++; + + /* copy first the data that was not replaced in original packed data */ + if (start < end && plan[i].mv_length) + { + memmove((header_base + new_header_size + + (size_t)plan[i].mv_offset + (size_t)plan[i].ddelta), + header_base + header_size + (size_t)plan[i].mv_offset, + (size_t)plan[i].mv_length); + } + str->length+= (size_t)plan[i].mv_length; + + /* new data adding */ + if (i < add_column_count) + { + if( plan[i].act == PLAN_ADD || plan[i].act == PLAN_REPLACE) + { + data_store(str, plan[i].val, dyncol_fmt_num);/* Append new data */ + } + } + } + return ER_DYNCOL_OK; +} + +#ifdef UNUSED +static enum enum_dyncol_func_result +dynamic_column_update_move_right(DYNAMIC_COLUMN *str, PLAN *plan, + size_t offset_size, + size_t entry_size, + size_t header_size, + size_t new_offset_size, + size_t new_entry_size, + size_t new_header_size, + uint column_count, + uint new_column_count, + uint add_column_count, + uchar *header_end, + size_t max_offset) +{ + uchar *write; + uchar *header_base= (uchar *)str->str + FIXED_HEADER_SIZE; + uint i, j, k; + size_t curr_offset; + + write= (uchar *)str->str + FIXED_HEADER_SIZE; + set_fixed_header(str, new_offset_size, new_column_count); + + /* + Move data first. + i= index in array of changes + j= index in packed string header index + */ + for (curr_offset= 0, i= 0, j= 0; + i < add_column_count || j < column_count; + i++) + { + size_t UNINIT_VAR(first_offset); + uint start= j, end; + + /* + Search in i and j for the next column to add from i and where to + add. + */ + + while (i < add_column_count && plan[i].act == PLAN_NOP) + i++; /* skip NOP */ + + if (i == add_column_count) + j= end= column_count; + else + { + /* + old data portion. We don't need to check that j < column_count + as plan[i].place is guaranteed to have a pointer inside the + data. + */ + while (header_base + j * entry_size < plan[i].place) + j++; + end= j; + if ((plan[i].act == PLAN_REPLACE || plan[i].act == PLAN_DELETE)) + j++; /* data at 'j' will be removed */ + } + plan[i].mv_end= end; + + { + DYNAMIC_COLUMN_TYPE tp; + type_and_offset_read_num(&tp, &first_offset, + header_base + + start * entry_size + COLUMN_NUMBER_SIZE, + offset_size); + } + /* find data to be moved */ + if (start < end) + { + size_t data_size= + get_length_interval(header_base + start * entry_size, + header_base + end * entry_size, + header_end, offset_size, max_offset); + if (data_size == DYNCOL_OFFSET_ERROR || + (long) data_size < 0 || + data_size > max_offset - first_offset) + { + str->length= 0; // just something valid + return ER_DYNCOL_FORMAT; + } + DBUG_ASSERT(curr_offset == first_offset + plan[i].ddelta); + plan[i].mv_offset= first_offset; + plan[i].mv_length= data_size; + curr_offset+= data_size; + } + else + { + plan[i].mv_length= 0; + plan[i].mv_offset= curr_offset; + } + + if (plan[i].ddelta == 0 && offset_size == new_offset_size && + plan[i].act != PLAN_DELETE) + write+= entry_size * (end - start); + else + { + /* + Adjust all headers since last loop. + We have to do this as the offset for data has moved + */ + for (k= start; k < end; k++) + { + uchar *read= header_base + k * entry_size; + size_t offs; + uint nm; + DYNAMIC_COLUMN_TYPE tp; + + nm= uint2korr(read); /* Column nummber */ + type_and_offset_read_num(&tp, &offs, read + COLUMN_NUMBER_SIZE, + offset_size); + if (k > start && offs < first_offset) + { + str->length= 0; // just something valid + return ER_DYNCOL_FORMAT; + } + + offs+= plan[i].ddelta; + int2store(write, nm); + /* write rest of data at write + COLUMN_NUMBER_SIZE */ + if (type_and_offset_store_num(write, new_offset_size, tp, offs)) + { + str->length= 0; // just something valid + return ER_DYNCOL_FORMAT; + } + write+= new_entry_size; + } + } + + /* new data adding */ + if (i < add_column_count) + { + if( plan[i].act == PLAN_ADD || plan[i].act == PLAN_REPLACE) + { + int2store(write, *((uint *)plan[i].key)); + if (type_and_offset_store_num(write, new_offset_size, + plan[i].val[0].type, + curr_offset)) + { + str->length= 0; // just something valid + return ER_DYNCOL_FORMAT; + } + write+= new_entry_size; + curr_offset+= plan[i].length; + } + } + } + + /* + Move headers. + i= index in array of changes + j= index in packed string header index + */ + str->length= (FIXED_HEADER_SIZE + new_header_size); + for (i= 0, j= 0; + i < add_column_count || j < column_count; + i++) + { + uint start= j, end; + + /* + Search in i and j for the next column to add from i and where to + add. + */ + + while (i < add_column_count && plan[i].act == PLAN_NOP) + i++; /* skip NOP */ + + j= end= plan[i].mv_end; + if (i != add_column_count && + (plan[i].act == PLAN_REPLACE || plan[i].act == PLAN_DELETE)) + j++; + + /* copy first the data that was not replaced in original packed data */ + if (start < end && plan[i].mv_length) + { + memmove((header_base + new_header_size + + plan[i].mv_offset + plan[i].ddelta), + header_base + header_size + plan[i].mv_offset, + plan[i].mv_length); + } + str->length+= plan[i].mv_length; + + /* new data adding */ + if (i < add_column_count) + { + if( plan[i].act == PLAN_ADD || plan[i].act == PLAN_REPLACE) + { + data_store(str, plan[i].val, dyncol_fmt_num); /* Append new data */ + } + } + } + return ER_DYNCOL_OK; +} +#endif + +/** + Update the packed string with the given columns + + @param str String where to write the data + @param add_column_count Number of columns in the arrays + @param column_numbers Array of columns numbers + @param values Array of columns values + + @return ER_DYNCOL_* return code +*/ +/* plan allocated on the stack */ +#define IN_PLACE_PLAN 4 + +enum enum_dyncol_func_result +dynamic_column_update_many(DYNAMIC_COLUMN *str, + uint add_column_count, + uint *column_numbers, + DYNAMIC_COLUMN_VALUE *values) +{ + return dynamic_column_update_many_fmt(str, add_column_count, column_numbers, + values, FALSE); +} + +enum enum_dyncol_func_result +mariadb_dyncol_update_many_num(DYNAMIC_COLUMN *str, + uint add_column_count, + uint *column_numbers, + DYNAMIC_COLUMN_VALUE *values) +{ + return dynamic_column_update_many_fmt(str, add_column_count, column_numbers, + values, FALSE); +} + +enum enum_dyncol_func_result +mariadb_dyncol_update_many_named(DYNAMIC_COLUMN *str, + uint add_column_count, + LEX_STRING *column_names, + DYNAMIC_COLUMN_VALUE *values) +{ + return dynamic_column_update_many_fmt(str, add_column_count, column_names, + values, TRUE); +} + +static uint numlen(uint val) +{ + uint res; + if (val == 0) + return 1; + res= 0; + while(val) + { + res++; + val/=10; + } + return res; +} + +static enum enum_dyncol_func_result +dynamic_column_update_many_fmt(DYNAMIC_COLUMN *str, + uint add_column_count, + void *column_keys, + DYNAMIC_COLUMN_VALUE *values, + my_bool string_keys) +{ + PLAN *plan, *alloc_plan= NULL, in_place_plan[IN_PLACE_PLAN]; + uchar *element; + DYN_HEADER header, new_header; + struct st_service_funcs *fmt, *new_fmt; + long long data_delta= 0, name_delta= 0; + uint i; + uint not_null; + long long header_delta= 0; + long long header_delta_sign, data_delta_sign; + int copy= FALSE; + enum enum_dyncol_func_result rc; + my_bool convert; + + if (add_column_count == 0) + return ER_DYNCOL_OK; + + memset(&header, 0, sizeof(header)); + memset(&new_header, 0, sizeof(new_header)); + new_header.format= (string_keys ? dyncol_fmt_str : dyncol_fmt_num); + new_fmt= fmt_data + new_header.format; + + /* + Get columns in column order. As the data in 'str' is already + in column order this allows to replace all columns in one loop. + */ + if (IN_PLACE_PLAN > add_column_count) + plan= in_place_plan; + else if (!(alloc_plan= plan= + (PLAN *)malloc(sizeof(PLAN) * (add_column_count + 1)))) + return ER_DYNCOL_RESOURCE; + + not_null= add_column_count; + for (i= 0, element= (uchar *) column_keys; + i < add_column_count; + i++, element+= new_fmt->key_size_in_array) + { + if ((*new_fmt->check_limit)(&element)) + { + rc= ER_DYNCOL_DATA; + goto end; + } + + plan[i].val= values + i; + plan[i].key= element; + if (values[i].type == DYN_COL_NULL) + not_null--; + + } + + if (str->length == 0) + { + /* + Just add new columns. If there was no columns to add we return + an empty string. + */ + goto create_new_string; + } + + /* Check that header is ok */ + if ((rc= init_read_hdr(&header, str)) < 0) + goto end; + fmt= fmt_data + header.format; + /* new format can't be numeric if the old one is names */ + DBUG_ASSERT(new_header.format == dyncol_fmt_str || + header.format == dyncol_fmt_num); + if (header.column_count == 0) + goto create_new_string; + + qsort(plan, (size_t)add_column_count, sizeof(PLAN), new_fmt->plan_sort); + + new_header.column_count= header.column_count; + new_header.nmpool_size= header.nmpool_size; + if ((convert= (new_header.format == dyncol_fmt_str && + header.format == dyncol_fmt_num))) + { + DBUG_ASSERT(new_header.nmpool_size == 0); + for(i= 0, header.entry= header.header; + i < header.column_count; + i++, header.entry+= header.entry_size) + { + new_header.nmpool_size+= numlen(uint2korr(header.entry)); + } + } + + if (fmt->fixed_hdr + header.header_size + header.nmpool_size > str->length) + { + rc= ER_DYNCOL_FORMAT; + goto end; + } + + /* + Calculate how many columns and data is added/deleted and make a 'plan' + for each of them. + */ + for (i= 0; i < add_column_count; i++) + { + /* + For now we don't allow creating two columns with the same number + at the time of create. This can be fixed later to just use the later + by comparing the pointers. + */ + if (i < add_column_count - 1 && + new_fmt->column_sort(&plan[i].key, &plan[i + 1].key) == 0) + { + rc= ER_DYNCOL_DATA; + goto end; + } + + /* Set common variables for all plans */ + plan[i].ddelta= data_delta; + plan[i].ndelta= name_delta; + /* get header delta in entries */ + plan[i].hdelta= header_delta; + plan[i].length= 0; /* Length if NULL */ + + if (find_place(&header, plan[i].key, string_keys)) + { + size_t entry_data_size, entry_name_size= 0; + + /* Data existed; We have to replace or delete it */ + + entry_data_size= hdr_interval_length(&header, header.entry + + header.entry_size); + if (entry_data_size == DYNCOL_OFFSET_ERROR || + (long) entry_data_size < 0) + { + rc= ER_DYNCOL_FORMAT; + goto end; + } + + if (new_header.format == dyncol_fmt_str) + { + if (header.format == dyncol_fmt_str) + { + LEX_STRING name; + if (read_name(&header, header.entry, &name)) + { + rc= ER_DYNCOL_FORMAT; + goto end; + } + entry_name_size= name.length; + } + else + entry_name_size= numlen(uint2korr(header.entry)); + } + + if (plan[i].val->type == DYN_COL_NULL) + { + /* Inserting a NULL means delete the old data */ + + plan[i].act= PLAN_DELETE; /* Remove old value */ + header_delta--; /* One row less in header */ + data_delta-= entry_data_size; /* Less data to store */ + name_delta-= entry_name_size; + } + else + { + /* Replace the value */ + + plan[i].act= PLAN_REPLACE; + /* get data delta in bytes */ + if ((plan[i].length= dynamic_column_value_len(plan[i].val, + new_header.format)) == + (size_t) ~0) + { + rc= ER_DYNCOL_DATA; + goto end; + } + data_delta+= plan[i].length - entry_data_size; + if (new_header.format == dyncol_fmt_str) + { + name_delta+= ((LEX_STRING *)(plan[i].key))->length - entry_name_size; + } + } + } + else + { + /* Data did not exists. Add if it it's not NULL */ + + if (plan[i].val->type == DYN_COL_NULL) + { + plan[i].act= PLAN_NOP; /* Mark entry to be skipped */ + } + else + { + /* Add new value */ + + plan[i].act= PLAN_ADD; + header_delta++; /* One more row in header */ + /* get data delta in bytes */ + if ((plan[i].length= dynamic_column_value_len(plan[i].val, + new_header.format)) == + (size_t) ~0) + { + rc= ER_DYNCOL_DATA; + goto end; + } + data_delta+= plan[i].length; + if (new_header.format == dyncol_fmt_str) + name_delta+= ((LEX_STRING *)plan[i].key)->length; + } + } + plan[i].place= header.entry; + } + plan[add_column_count].hdelta= header_delta; + plan[add_column_count].ddelta= data_delta; + plan[add_column_count].act= PLAN_NOP; + plan[add_column_count].place= header.dtpool; + + new_header.column_count= (uint)(header.column_count + header_delta); + + /* + Check if it is only "increasing" or only "decreasing" plan for (header + and data separately). + */ + new_header.data_size= header.data_size + (size_t)data_delta; + new_header.nmpool_size= new_header.nmpool_size + (size_t)name_delta; + DBUG_ASSERT(new_header.format != dyncol_fmt_num || + new_header.nmpool_size == 0); + if ((new_header.offset_size= + new_fmt->dynamic_column_offset_bytes(new_header.data_size)) >= + new_fmt->max_offset_size) + { + rc= ER_DYNCOL_LIMIT; + goto end; + } + + copy= ((header.format != new_header.format) || + (new_header.format == dyncol_fmt_str)); + /* if (new_header.offset_size!=offset_size) then we have to rewrite header */ + header_delta_sign= + ((int)new_header.offset_size + new_fmt->fixed_hdr_entry) - + ((int)header.offset_size + fmt->fixed_hdr_entry); + data_delta_sign= 0; + // plan[add_column_count] contains last deltas. + for (i= 0; i <= add_column_count && !copy; i++) + { + /* This is the check for increasing/decreasing */ + DELTA_CHECK(header_delta_sign, plan[i].hdelta, copy); + DELTA_CHECK(data_delta_sign, plan[i].ddelta, copy); + } + calc_param(&new_header.entry_size, &new_header.header_size, + new_fmt->fixed_hdr_entry, + new_header.offset_size, new_header.column_count); + + /* + Need copy because: + 1, Header/data parts moved in different directions. + 2. There is no enough allocated space in the string. + 3. Header and data moved in different directions. + */ + if (copy || /*1.*/ + str->max_length < str->length + header_delta + data_delta || /*2.*/ + ((header_delta_sign < 0 && data_delta_sign > 0) || + (header_delta_sign > 0 && data_delta_sign < 0))) /*3.*/ + rc= dynamic_column_update_copy(str, plan, add_column_count, + &header, &new_header, + convert); + else + if (header_delta_sign < 0) + rc= dynamic_column_update_move_left(str, plan, header.offset_size, + header.entry_size, + header.header_size, + new_header.offset_size, + new_header.entry_size, + new_header.header_size, + header.column_count, + new_header.column_count, + add_column_count, header.dtpool, + header.data_size); + else + /* + rc= dynamic_column_update_move_right(str, plan, offset_size, + entry_size, header_size, + new_header.offset_size, + new_header.entry_size, + new_heder.header_size, column_count, + new_header.column_count, + add_column_count, header_end, + header.data_size); + */ + rc= dynamic_column_update_copy(str, plan, add_column_count, + &header, &new_header, + convert); +end: + free(alloc_plan); + return rc; + +create_new_string: + /* There is no columns from before, so let's just add the new ones */ + rc= ER_DYNCOL_OK; + if (not_null != 0) + rc= dynamic_column_create_many_internal_fmt(str, add_column_count, + (uint*)column_keys, values, + str->str == NULL, + string_keys); + goto end; +} + + +/** + Update the packed string with the given column + + @param str String where to write the data + @param column_number Array of columns number + @param values Array of columns values + + @return ER_DYNCOL_* return code +*/ + + +int dynamic_column_update(DYNAMIC_COLUMN *str, uint column_nr, + DYNAMIC_COLUMN_VALUE *value) +{ + return dynamic_column_update_many(str, 1, &column_nr, value); +} + + +enum enum_dyncol_func_result +mariadb_dyncol_check(DYNAMIC_COLUMN *str) +{ + struct st_service_funcs *fmt; + enum enum_dyncol_func_result rc= ER_DYNCOL_FORMAT; + DYN_HEADER header; + uint i; + size_t data_offset= 0, name_offset= 0; + size_t prev_data_offset= 0, prev_name_offset= 0; + LEX_STRING name= {0,0}, prev_name= {0,0}; + uint num= 0, prev_num= 0; + void *key, *prev_key; + enum enum_dynamic_column_type type= DYN_COL_NULL, prev_type= DYN_COL_NULL; + + if (str->length == 0) + { + return(ER_DYNCOL_OK); + } + + memset(&header, 0, sizeof(header)); + + /* Check that header is OK */ + if (read_fixed_header(&header, str)) + { + goto end; + } + fmt= fmt_data + header.format; + calc_param(&header.entry_size, &header.header_size, + fmt->fixed_hdr_entry, header.offset_size, + header.column_count); + /* headers are out of string length (no space for data and part of headers) */ + if (fmt->fixed_hdr + header.header_size + header.nmpool_size > str->length) + { + goto end; + } + header.header= (uchar*)str->str + fmt->fixed_hdr; + header.nmpool= header.header + header.header_size; + header.dtpool= header.nmpool + header.nmpool_size; + header.data_size= str->length - fmt->fixed_hdr - + header.header_size - header.nmpool_size; + + /* read and check headers */ + if (header.format == dyncol_fmt_num) + { + key= # + prev_key= &prev_num; + } + else + { + key= &name; + prev_key= &prev_name; + } + for (i= 0, header.entry= header.header; + i < header.column_count; + i++, header.entry+= header.entry_size) + { + + if (header.format == dyncol_fmt_num) + { + num= uint2korr(header.entry); + } + else + { + DBUG_ASSERT(header.format == dyncol_fmt_str); + if (read_name(&header, header.entry, &name)) + { + goto end; + } + name_offset= name.str - (char *)header.nmpool; + } + if ((*fmt->type_and_offset_read)(&type, &data_offset, + header.entry + fmt->fixed_hdr_entry, + header.offset_size)) + goto end; + + DBUG_ASSERT(type != DYN_COL_NULL); + if (data_offset > header.data_size) + { + goto end; + } + if (prev_type != DYN_COL_NULL) + { + /* It is not first entry */ + if (prev_data_offset >= data_offset) + { + goto end; + } + if (prev_name_offset > name_offset) + { + goto end; + } + if ((*fmt->column_sort)(&prev_key, &key) >= 0) + { + goto end; + } + } + prev_num= num; + prev_name= name; + prev_data_offset= data_offset; + prev_name_offset= name_offset; + prev_type= type; + } + + /* check data, which we can */ + for (i= 0, header.entry= header.header; + i < header.column_count; + i++, header.entry+= header.entry_size) + { + DYNAMIC_COLUMN_VALUE store; + /* already checked by previous pass */ + (*fmt->type_and_offset_read)(&header.type, &header.offset, + header.entry + fmt->fixed_hdr_entry, + header.offset_size); + header.length= + hdr_interval_length(&header, header.entry + header.entry_size); + header.data= header.dtpool + header.offset; + switch ((header.type)) { + case DYN_COL_INT: + rc= dynamic_column_sint_read(&store, header.data, header.length); + break; + case DYN_COL_UINT: + rc= dynamic_column_uint_read(&store, header.data, header.length); + break; + case DYN_COL_DOUBLE: + rc= dynamic_column_double_read(&store, header.data, header.length); + break; + case DYN_COL_STRING: + rc= dynamic_column_string_read(&store, header.data, header.length); + break; +#ifndef LIBMARIADB + case DYN_COL_DECIMAL: + rc= dynamic_column_decimal_read(&store, header.data, header.length); + break; +#endif + case DYN_COL_DATETIME: + rc= dynamic_column_date_time_read(&store, header.data, + header.length); + break; + case DYN_COL_DATE: + rc= dynamic_column_date_read(&store, header.data, header.length); + break; + case DYN_COL_TIME: + rc= dynamic_column_time_read(&store, header.data, header.length); + break; + case DYN_COL_DYNCOL: + rc= dynamic_column_dyncol_read(&store, header.data, header.length); + break; + case DYN_COL_NULL: + default: + rc= ER_DYNCOL_FORMAT; + goto end; + } + if (rc != ER_DYNCOL_OK) + { + DBUG_ASSERT(rc < 0); + goto end; + } + } + + rc= ER_DYNCOL_OK; +end: + return(rc); +} + +enum enum_dyncol_func_result +mariadb_dyncol_val_str(DYNAMIC_STRING *str, DYNAMIC_COLUMN_VALUE *val, + MARIADB_CHARSET_INFO *cs, char quote) +{ + char buff[40]; + size_t len; + switch (val->type) { + case DYN_COL_INT: + len= snprintf(buff, sizeof(buff), "%lld", val->x.long_value); + if (ma_dynstr_append_mem(str, buff, len)) + return ER_DYNCOL_RESOURCE; + break; + case DYN_COL_UINT: + len= snprintf(buff, sizeof(buff), "%llu", val->x.ulong_value); + if (ma_dynstr_append_mem(str, buff, len)) + return ER_DYNCOL_RESOURCE; + break; + case DYN_COL_DOUBLE: + len= snprintf(buff, sizeof(buff), "%g", val->x.double_value); + if (ma_dynstr_realloc(str, len + (quote ? 2 : 0))) + return ER_DYNCOL_RESOURCE; + if (quote) + str->str[str->length++]= quote; + ma_dynstr_append_mem(str, buff, len); + if (quote) + str->str[str->length++]= quote; + break; + case DYN_COL_DYNCOL: + case DYN_COL_STRING: + { + char *alloc= NULL; + char *from= val->x.string.value.str; + ulong bufflen; + my_bool conv= ((val->x.string.charset == cs) || + !strcmp(val->x.string.charset->name, cs->name)); + my_bool rc; + len= val->x.string.value.length; + bufflen= (ulong)(len * (conv ? cs->char_maxlen : 1)); + if (ma_dynstr_realloc(str, bufflen)) + return ER_DYNCOL_RESOURCE; + + // guaranty UTF-8 string for value + if (!conv) + { +#ifndef LIBMARIADB + uint dumma_errors; +#else + int dumma_errors; +#endif + if (!quote) + { + /* convert to the destination */ + str->length+= +#ifndef LIBMARIADB + copy_and_convert_extended(str->str, bufflen, + cs, + from, (uint32)len, + val->x.string.charset, + &dumma_errors); +#else + mariadb_convert_string(from, &len, val->x.string.charset, + str->str, (size_t *)&bufflen, cs, &dumma_errors); +#endif + return ER_DYNCOL_OK; + } + if ((alloc= (char *)malloc(bufflen))) + { + len= +#ifndef LIBMARIADB + copy_and_convert_extended(alloc, bufflen, cs, + from, (uint32)len, + val->x.string.charset, + &dumma_errors); +#else + mariadb_convert_string(from, &len, val->x.string.charset, + alloc, (size_t *)&bufflen, cs, &dumma_errors); +#endif + from= alloc; + } + else + return ER_DYNCOL_RESOURCE; + } + if (quote) + rc= ma_dynstr_append_quoted(str, from, len, quote); + else + rc= ma_dynstr_append_mem(str, from, len); + if (alloc) + free(alloc); + if (rc) + return ER_DYNCOL_RESOURCE; + break; + } +#ifndef LIBMARIADB + case DYN_COL_DECIMAL: + { + int len= sizeof(buff); + decimal2string(&val->x.decimal.value, buff, &len, + 0, val->x.decimal.value.frac, + '0'); + if (ma_dynstr_append_mem(str, buff, len)) + return ER_DYNCOL_RESOURCE; + break; + } +#endif + case DYN_COL_DATETIME: + case DYN_COL_DATE: + case DYN_COL_TIME: +#ifndef LIBMARIADB + len= my_TIME_to_str(&val->x.time_value, buff, AUTO_SEC_PART_DIGITS); +#else + len= mariadb_time_to_string(&val->x.time_value, buff, 39, AUTO_SEC_PART_DIGITS); +#endif + if (ma_dynstr_realloc(str, len + (quote ? 2 : 0))) + return ER_DYNCOL_RESOURCE; + if (quote) + str->str[str->length++]= '"'; + ma_dynstr_append_mem(str, buff, len); + if (quote) + str->str[str->length++]= '"'; + break; + case DYN_COL_NULL: + if (ma_dynstr_append_mem(str, "null", 4)) + return ER_DYNCOL_RESOURCE; + break; + default: + return(ER_DYNCOL_FORMAT); + } + return(ER_DYNCOL_OK); +} + +enum enum_dyncol_func_result +mariadb_dyncol_val_long(longlong *ll, DYNAMIC_COLUMN_VALUE *val) +{ + enum enum_dyncol_func_result rc= ER_DYNCOL_OK; + *ll= 0; + switch (val->type) { + case DYN_COL_INT: + *ll= val->x.long_value; + break; + case DYN_COL_UINT: + *ll= (longlong)val->x.ulong_value; + if (*ll > (longlong)ULONGLONG_MAX) + rc= ER_DYNCOL_TRUNCATED; + break; + case DYN_COL_DOUBLE: + *ll= (longlong)val->x.double_value; + if (((double) *ll) != val->x.double_value) + rc= ER_DYNCOL_TRUNCATED; + break; + case DYN_COL_STRING: + { + char *src= val->x.string.value.str; + size_t len= val->x.string.value.length; + longlong i= 0, sign= 1; + + while (len && isspace(*src)) src++,len--; + + if (len) + { + if (*src == '-') + { + sign= -1; + src++; + } + while(len && isdigit(*src)) + { + i= i * 10 + (*src - '0'); + src++; + } + } + else + rc= ER_DYNCOL_TRUNCATED; + if (len) + rc= ER_DYNCOL_TRUNCATED; + *ll= i * sign; + break; + } +#ifndef LIBMARIADB + case DYN_COL_DECIMAL: + if (decimal2longlong(&val->x.decimal.value, ll) != E_DEC_OK) + rc= ER_DYNCOL_TRUNCATED; + break; +#endif + case DYN_COL_DATETIME: + *ll= (val->x.time_value.year * 10000000000ull + + val->x.time_value.month * 100000000L + + val->x.time_value.day * 1000000 + + val->x.time_value.hour * 10000 + + val->x.time_value.minute * 100 + + val->x.time_value.second) * + (val->x.time_value.neg ? -1 : 1); + break; + case DYN_COL_DATE: + *ll= (val->x.time_value.year * 10000 + + val->x.time_value.month * 100 + + val->x.time_value.day) * + (val->x.time_value.neg ? -1 : 1); + break; + case DYN_COL_TIME: + *ll= (val->x.time_value.hour * 10000 + + val->x.time_value.minute * 100 + + val->x.time_value.second) * + (val->x.time_value.neg ? -1 : 1); + break; + case DYN_COL_DYNCOL: + case DYN_COL_NULL: + rc= ER_DYNCOL_TRUNCATED; + break; + default: + return(ER_DYNCOL_FORMAT); + } + return(rc); +} + + +enum enum_dyncol_func_result +mariadb_dyncol_val_double(double *dbl, DYNAMIC_COLUMN_VALUE *val) +{ + enum enum_dyncol_func_result rc= ER_DYNCOL_OK; + *dbl= 0; + switch (val->type) { + case DYN_COL_INT: + *dbl= (double)val->x.long_value; + if (((longlong) *dbl) != val->x.long_value) + rc= ER_DYNCOL_TRUNCATED; + break; + case DYN_COL_UINT: + *dbl= (double)val->x.ulong_value; + if (((ulonglong) *dbl) != val->x.ulong_value) + rc= ER_DYNCOL_TRUNCATED; + break; + case DYN_COL_DOUBLE: + *dbl= val->x.double_value; + break; + case DYN_COL_STRING: + { + char *str, *end; + if (!(str= malloc(val->x.string.value.length + 1))) + return ER_DYNCOL_RESOURCE; + memcpy(str, val->x.string.value.str, val->x.string.value.length); + str[val->x.string.value.length]= '\0'; + *dbl= strtod(str, &end); + if (*end != '\0') + rc= ER_DYNCOL_TRUNCATED; + free(str); + break; + } +#ifndef LIBMARIADB + case DYN_COL_DECIMAL: + if (decimal2double(&val->x.decimal.value, dbl) != E_DEC_OK) + rc= ER_DYNCOL_TRUNCATED; + break; +#endif + case DYN_COL_DATETIME: + *dbl= (double)(val->x.time_value.year * 10000000000ull + + val->x.time_value.month * 100000000L + + val->x.time_value.day * 1000000 + + val->x.time_value.hour * 10000 + + val->x.time_value.minute * 100 + + val->x.time_value.second) * + (val->x.time_value.neg ? -1 : 1); + break; + case DYN_COL_DATE: + *dbl= (double)(val->x.time_value.year * 10000 + + val->x.time_value.month * 100 + + val->x.time_value.day) * + (val->x.time_value.neg ? -1 : 1); + break; + case DYN_COL_TIME: + *dbl= (double)(val->x.time_value.hour * 10000 + + val->x.time_value.minute * 100 + + val->x.time_value.second) * + (val->x.time_value.neg ? -1 : 1); + break; + case DYN_COL_DYNCOL: + case DYN_COL_NULL: + rc= ER_DYNCOL_TRUNCATED; + break; + default: + return(ER_DYNCOL_FORMAT); + } + return(rc); +} + + +/** + Convert to JSON + + @param str The packed string + @param json Where to put json result + + @return ER_DYNCOL_* return code +*/ + +#define JSON_STACK_PROTECTION 10 + +static enum enum_dyncol_func_result +mariadb_dyncol_json_internal(DYNAMIC_COLUMN *str, DYNAMIC_STRING *json, + uint lvl) +{ + DYN_HEADER header; + uint i; + enum enum_dyncol_func_result rc; + + if (lvl >= JSON_STACK_PROTECTION) + { + rc= ER_DYNCOL_RESOURCE; + goto err; + } + + + if (str->length == 0) + return ER_DYNCOL_OK; /* no columns */ + + if ((rc= init_read_hdr(&header, str)) < 0) + goto err; + + if (header.entry_size * header.column_count + FIXED_HEADER_SIZE > + str->length) + { + rc= ER_DYNCOL_FORMAT; + goto err; + } + + rc= ER_DYNCOL_RESOURCE; + + if (ma_dynstr_append_mem(json, "{", 1)) + goto err; + for (i= 0, header.entry= header.header; + i < header.column_count; + i++, header.entry+= header.entry_size) + { + DYNAMIC_COLUMN_VALUE val; + if (i != 0 && ma_dynstr_append_mem(json, ",", 1)) + goto err; + header.length= + hdr_interval_length(&header, header.entry + header.entry_size); + header.data= header.dtpool + header.offset; + /* + Check that the found data is within the ranges. This can happen if + we get data with wrong offsets. + */ + if (header.length == DYNCOL_OFFSET_ERROR || + header.length > INT_MAX || header.offset > header.data_size) + { + rc= ER_DYNCOL_FORMAT; + goto err; + } + if ((rc= dynamic_column_get_value(&header, &val)) < 0) + goto err; + if (header.format == dyncol_fmt_num) + { + uint nm= uint2korr(header.entry); + if (ma_dynstr_realloc(json, DYNCOL_NUM_CHAR + 3)) + goto err; + json->str[json->length++]= '"'; + json->length+= snprintf(json->str + json->length, + DYNCOL_NUM_CHAR, "%u", nm); + } + else + { + LEX_STRING name; + if (read_name(&header, header.entry, &name)) + { + rc= ER_DYNCOL_FORMAT; + goto err; + } + if (ma_dynstr_realloc(json, name.length + 3)) + goto err; + json->str[json->length++]= '"'; + memcpy(json->str + json->length, name.str, name.length); + json->length+= name.length; + } + json->str[json->length++]= '"'; + json->str[json->length++]= ':'; + if (val.type == DYN_COL_DYNCOL) + { + /* here we use it only for read so can cheat a bit */ + DYNAMIC_COLUMN dc; + memset(&dc, 0, sizeof(dc)); + dc.str= val.x.string.value.str; + dc.length= val.x.string.value.length; + if (mariadb_dyncol_json_internal(&dc, json, lvl + 1) < 0) + { + dc.str= NULL; dc.length= 0; + goto err; + } + dc.str= NULL; dc.length= 0; + } + else + { + if ((rc= mariadb_dyncol_val_str(json, &val, + ma_charset_utf8_general_ci, '"')) < 0) + goto err; + } + } + if (ma_dynstr_append_mem(json, "}", 1)) + { + rc= ER_DYNCOL_RESOURCE; + goto err; + } + return ER_DYNCOL_OK; + +err: + json->length= 0; + return rc; +} + +enum enum_dyncol_func_result +mariadb_dyncol_json(DYNAMIC_COLUMN *str, DYNAMIC_STRING *json) +{ + + if (ma_init_dynamic_string(json, NULL, str->length * 2, 100)) + return ER_DYNCOL_RESOURCE; + + return mariadb_dyncol_json_internal(str, json, 1); +} + +/** + Convert to DYNAMIC_COLUMN_VALUE values and names (LEX_STING) dynamic array + + @param str The packed string + @param count number of elements in the arrays + @param names Where to put names (should be free by user) + @param vals Where to put values (should be free by user) + + @return ER_DYNCOL_* return code +*/ + +enum enum_dyncol_func_result +mariadb_dyncol_unpack(DYNAMIC_COLUMN *str, + uint *count, + LEX_STRING **names, DYNAMIC_COLUMN_VALUE **vals) +{ + DYN_HEADER header; + char *nm; + uint i; + enum enum_dyncol_func_result rc; + + *count= 0; *names= 0; *vals= 0; + + if (str->length == 0) + return ER_DYNCOL_OK; /* no columns */ + + if ((rc= init_read_hdr(&header, str)) < 0) + return rc; + + + if (header.entry_size * header.column_count + FIXED_HEADER_SIZE > + str->length) + return ER_DYNCOL_FORMAT; + + *vals= (DYNAMIC_COLUMN_VALUE *)malloc(sizeof(DYNAMIC_COLUMN_VALUE)* header.column_count); + if (header.format == dyncol_fmt_num) + { + *names= (LEX_STRING *)malloc(sizeof(LEX_STRING) * header.column_count + + DYNCOL_NUM_CHAR * header.column_count); + nm= (char *)((*names) + header.column_count); + } + else + { + *names= (LEX_STRING *)malloc(sizeof(LEX_STRING) * header.column_count); + nm= 0; + } + if (!(*vals) || !(*names)) + { + rc= ER_DYNCOL_RESOURCE; + goto err; + } + + for (i= 0, header.entry= header.header; + i < header.column_count; + i++, header.entry+= header.entry_size) + { + header.length= + hdr_interval_length(&header, header.entry + header.entry_size); + header.data= header.dtpool + header.offset; + /* + Check that the found data is within the ranges. This can happen if + we get data with wrong offsets. + */ + if (header.length == DYNCOL_OFFSET_ERROR || + header.length > INT_MAX || header.offset > header.data_size) + { + rc= ER_DYNCOL_FORMAT; + goto err; + } + if ((rc= dynamic_column_get_value(&header, (*vals) + i)) < 0) + goto err; + + if (header.format == dyncol_fmt_num) + { + uint num= uint2korr(header.entry); + (*names)[i].str= nm; + (*names)[i].length= snprintf(nm, DYNCOL_NUM_CHAR, "%u", num); + nm+= (*names)[i].length + 1; + } + else + { + if (read_name(&header, header.entry, (*names) + i)) + { + rc= ER_DYNCOL_FORMAT; + goto err; + } + } + } + + *count= header.column_count; + return ER_DYNCOL_OK; + +err: + if (*vals) + { + free(*vals); + *vals= 0; + } + if (*names) + { + free(*names); + *names= 0; + } + return rc; +} + + +/** + Get not NULL column count + + @param str The packed string + @param column_count Where to put column count + + @return ER_DYNCOL_* return code +*/ + +enum enum_dyncol_func_result +mariadb_dyncol_column_count(DYNAMIC_COLUMN *str, uint *column_count) +{ + DYN_HEADER header; + enum enum_dyncol_func_result rc; + + (*column_count)= 0; + if (str->length == 0) + return ER_DYNCOL_OK; + + if ((rc= init_read_hdr(&header, str)) < 0) + return rc; + *column_count= header.column_count; + return rc; +} + +/** + Release dynamic column memory + + @param str dynamic column + @return void +*/ +void mariadb_dyncol_free(DYNAMIC_COLUMN *str) +{ + ma_dynstr_free(str); +} diff --git a/vendor/MDBC/libmariadb/mariadb_lib.c b/vendor/MDBC/libmariadb/mariadb_lib.c new file mode 100644 index 00000000..e4baff33 --- /dev/null +++ b/vendor/MDBC/libmariadb/mariadb_lib.c @@ -0,0 +1,4522 @@ +/************************************************************************************ + Copyright (C) 2000, 2012 MySQL AB & MySQL Finland AB & TCX DataKonsult AB, + Monty Program AB + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not see + or write to the Free Software Foundation, Inc., + 51 Franklin St., Fifth Floor, Boston, MA 02110, USA + + Part of this code includes code from the PHP project which + is freely available from http://www.php.net +*************************************************************************************/ + +#include + +#include +#include +#include +#include +#include "ma_priv.h" +#include "ma_context.h" +#include "mysql.h" +#include "mariadb_version.h" +#include "ma_server_error.h" +#include +#include "errmsg.h" +#include +#include +#include +#include + +#ifndef __has_feature +# define __has_feature(x) 0 +#endif + +#ifdef HAVE_PWD_H +#include +#endif +#if !defined(_WIN32) +#include +#include +#include +#include +#ifdef HAVE_SELECT_H +# include +#endif +#ifdef HAVE_SYS_SELECT_H +#include +#endif +#endif +#ifdef HAVE_SYS_UN_H +# include +#endif +#ifndef INADDR_NONE +#define INADDR_NONE -1 +#endif +#include +#ifndef _WIN32 +#include +#endif +#include +#ifdef HAVE_TLS +#include +#endif +#include +#ifdef _WIN32 +#include "shlwapi.h" +#define strncasecmp _strnicmp +#endif + +#define ASYNC_CONTEXT_DEFAULT_STACK_SIZE (4096*15) +#define MA_RPL_VERSION_HACK "5.5.5-" + +#define CHARSET_NAME_LEN 64 + +#undef max_allowed_packet +#undef net_buffer_length +extern ulong max_allowed_packet; /* net.c */ +extern ulong net_buffer_length; /* net.c */ + +static MYSQL_PARAMETERS mariadb_internal_parameters= {&max_allowed_packet, &net_buffer_length, 0}; +static my_bool mysql_client_init=0; +static void mysql_close_options(MYSQL *mysql); +static void ma_clear_session_state(MYSQL *mysql); +extern void release_configuration_dirs(); +extern char **get_default_configuration_dirs(); +extern my_bool ma_init_done; +extern my_bool mysql_ps_subsystem_initialized; +extern my_bool mysql_handle_local_infile(MYSQL *mysql, const char *filename, my_bool can_local_infile); +extern const MARIADB_CHARSET_INFO * mysql_find_charset_nr(uint charsetnr); +extern const MARIADB_CHARSET_INFO * mysql_find_charset_name(const char * const name); +extern my_bool set_default_charset_by_name(const char *cs_name, myf flags __attribute__((unused))); +extern int run_plugin_auth(MYSQL *mysql, char *data, uint data_len, + const char *data_plugin, const char *db); +extern int net_add_multi_command(NET *net, uchar command, const uchar *packet, + size_t length); + +extern LIST *pvio_callback; + +/* prepare statement methods from my_stmt.c */ +extern my_bool mthd_supported_buffer_type(enum enum_field_types type); +extern my_bool mthd_stmt_read_prepare_response(MYSQL_STMT *stmt); +extern my_bool mthd_stmt_get_param_metadata(MYSQL_STMT *stmt); +extern my_bool mthd_stmt_get_result_metadata(MYSQL_STMT *stmt); +extern int mthd_stmt_read_execute_response(MYSQL_STMT *stmt); +extern int mthd_stmt_fetch_row(MYSQL_STMT *stmt, unsigned char **row); +extern int mthd_stmt_fetch_to_bind(MYSQL_STMT *stmt, unsigned char *row); +extern int mthd_stmt_read_all_rows(MYSQL_STMT *stmt); +extern void mthd_stmt_flush_unbuffered(MYSQL_STMT *stmt); +extern my_bool _mariadb_read_options(MYSQL *mysql, const char *dir, const char *config_file, char *group, unsigned int recursion); +extern unsigned char *mysql_net_store_length(unsigned char *packet, size_t length); + +extern void +my_context_install_suspend_resume_hook(struct mysql_async_context *b, + void (*hook)(my_bool, void *), + void *user_data); + +uint mysql_port=0; +my_string mysql_unix_port=0; + +#define CONNECT_TIMEOUT 0 + +struct st_mariadb_methods MARIADB_DEFAULT_METHODS; + +#if defined(_WIN32) +// socket_errno is defined in ma_global.h for all platforms +#define perror(A) +#else +#include +#define SOCKET_ERROR -1 +#endif /* _WIN32 */ + +#include + +#define IS_CONNHDLR_ACTIVE(mysql)\ + ((mysql)->extension && (mysql)->extension->conn_hdlr) + +static void end_server(MYSQL *mysql); +static void mysql_close_memory(MYSQL *mysql); +void read_user_name(char *name); +my_bool STDCALL mariadb_reconnect(MYSQL *mysql); +static int cli_report_progress(MYSQL *mysql, uchar *packet, uint length); + +extern int mysql_client_plugin_init(); +extern void mysql_client_plugin_deinit(); + +/* net_get_error */ +void net_get_error(char *buf, size_t buf_len, + char *error, size_t error_len, + unsigned int *error_no, + char *sqlstate) +{ + char *p= buf; + size_t error_msg_len= 0; + + if (buf_len > 2) + { + *error_no= uint2korr(p); + p+= 2; + + /* since 4.1 sqlstate is following */ + if (*p == '#') + { + memcpy(sqlstate, ++p, SQLSTATE_LENGTH); + p+= SQLSTATE_LENGTH; + } + error_msg_len= buf_len - (p - buf); + error_msg_len= MIN(error_msg_len, error_len - 1); + memcpy(error, p, error_msg_len); + } + else + { + *error_no= CR_UNKNOWN_ERROR; + memcpy(sqlstate, SQLSTATE_UNKNOWN, SQLSTATE_LENGTH); + } +} + +/***************************************************************************** +** read a packet from server. Give error message if socket was down +** or packet is an error message +*****************************************************************************/ + +ulong +ma_net_safe_read(MYSQL *mysql) +{ + NET *net= &mysql->net; + ulong len=0; + +restart: + if (net->pvio != 0) + len=ma_net_read(net); + + if (len == packet_error || len == 0) + { + end_server(mysql); + my_set_error(mysql, net->last_errno == ER_NET_PACKET_TOO_LARGE ? + CR_NET_PACKET_TOO_LARGE: + CR_SERVER_LOST, + SQLSTATE_UNKNOWN, 0, errno); + return(packet_error); + } + if (net->read_pos[0] == 255) + { + if (len > 3) + { + char *pos=(char*) net->read_pos+1; + uint last_errno=uint2korr(pos); + pos+=2; + len-=2; + + if (last_errno== 65535 && + ((mariadb_connection(mysql) && (mysql->server_capabilities & CLIENT_PROGRESS)) || + (!(mysql->extension->mariadb_server_capabilities & MARIADB_CLIENT_PROGRESS << 32)))) + { + if (cli_report_progress(mysql, (uchar *)pos, (uint) (len-1))) + { + /* Wrong packet */ + my_set_error(mysql, CR_MALFORMED_PACKET, SQLSTATE_UNKNOWN, 0); + return (packet_error); + } + goto restart; + } + net->last_errno= last_errno; + if (pos[0]== '#') + { + ma_strmake(net->sqlstate, pos+1, SQLSTATE_LENGTH); + pos+= SQLSTATE_LENGTH + 1; + } + else + { + strncpy(net->sqlstate, SQLSTATE_UNKNOWN, SQLSTATE_LENGTH); + } + ma_strmake(net->last_error,(char*) pos, + min(len,sizeof(net->last_error)-1)); + } + else + { + my_set_error(mysql, CR_UNKNOWN_ERROR, SQLSTATE_UNKNOWN, 0); + } + + mysql->server_status&= ~SERVER_MORE_RESULTS_EXIST; + + return(packet_error); + } + return len; +} + +/* + Report progress to the client + + RETURN VALUES + 0 ok + 1 error +*/ +static int cli_report_progress(MYSQL *mysql, uchar *packet, uint length) +{ + uint stage, max_stage, proc_length; + double progress; + uchar *start= packet; + + if (length < 5) + return 1; /* Wrong packet */ + + if (!(mysql->options.extension && mysql->options.extension->report_progress)) + return 0; /* No callback, ignore packet */ + + packet++; /* Ignore number of strings */ + stage= (uint) *packet++; + max_stage= (uint) *packet++; + progress= uint3korr(packet)/1000.0; + packet+= 3; + proc_length= net_field_length(&packet); + if (packet + proc_length > start + length) + return 1; /* Wrong packet */ + (*mysql->options.extension->report_progress)(mysql, stage, max_stage, + progress, (char*) packet, + proc_length); + return 0; +} + +/* Get the length of next field. Change parameter to point at fieldstart */ +ulong +net_field_length(uchar **packet) +{ + reg1 uchar *pos= *packet; + if (*pos < 251) + { + (*packet)++; + return (ulong) *pos; + } + if (*pos == 251) + { + (*packet)++; + return NULL_LENGTH; + } + if (*pos == 252) + { + (*packet)+=3; + return (ulong) uint2korr(pos+1); + } + if (*pos == 253) + { + (*packet)+=4; + return (ulong) uint3korr(pos+1); + } + (*packet)+=9; /* Must be 254 when here */ + return (ulong) uint4korr(pos+1); +} + +/* Same as above, but returns ulonglong values */ + +static unsigned long long +net_field_length_ll(uchar **packet) +{ + reg1 uchar *pos= *packet; + if (*pos < 251) + { + (*packet)++; + return (unsigned long long) *pos; + } + if (*pos == 251) + { + (*packet)++; + return (unsigned long long) NULL_LENGTH; + } + if (*pos == 252) + { + (*packet)+=3; + return (unsigned long long) uint2korr(pos+1); + } + if (*pos == 253) + { + (*packet)+=4; + return (unsigned long long) uint3korr(pos+1); + } + (*packet)+=9; /* Must be 254 when here */ +#ifdef NO_CLIENT_LONGLONG + return (unsigned long long) uint4korr(pos+1); +#else + return (unsigned long long) uint8korr(pos+1); +#endif +} + + +void free_rows(MYSQL_DATA *cur) +{ + if (cur) + { + ma_free_root(&cur->alloc,MYF(0)); + free(cur); + } +} + +int +mthd_my_send_cmd(MYSQL *mysql,enum enum_server_command command, const char *arg, + size_t length, my_bool skipp_check, void *opt_arg) +{ + NET *net= &mysql->net; + int result= -1; + if (mysql->net.pvio == 0) + { + /* Do reconnect if possible */ + if (mariadb_reconnect(mysql)) + return(1); + } + if (mysql->status != MYSQL_STATUS_READY || + mysql->server_status & SERVER_MORE_RESULTS_EXIST) + { + SET_CLIENT_ERROR(mysql, CR_COMMANDS_OUT_OF_SYNC, SQLSTATE_UNKNOWN, 0); + goto end; + } + + if (IS_CONNHDLR_ACTIVE(mysql)) + { + result= mysql->extension->conn_hdlr->plugin->set_connection(mysql, command, arg, length, skipp_check, opt_arg); + if (result== -1) + return(result); + } + + CLEAR_CLIENT_ERROR(mysql); + + if (command == COM_QUERY || + command == COM_STMT_PREPARE) + { + if ((mysql->options.client_flag & CLIENT_LOCAL_FILES) && + mysql->options.extension && mysql->extension->auto_local_infile == WAIT_FOR_QUERY && + arg && (*arg == 'l' || *arg == 'L')) + { + if (strncasecmp(arg, "load", 4) == 0) + mysql->extension->auto_local_infile= ACCEPT_FILE_REQUEST; + } + } + + mysql->info=0; + mysql->affected_rows= ~(unsigned long long) 0; + ma_net_clear(net); /* Clear receive buffer */ + if (!arg) + arg=""; + + if (net->extension->multi_status== COM_MULTI_ENABLED) + { + return net_add_multi_command(net, command, (const uchar *)arg, length); + } + + if (ma_net_write_command(net,(uchar) command,arg, + length ? length : (ulong) strlen(arg), 0)) + { + if (net->last_errno == ER_NET_PACKET_TOO_LARGE) + { + my_set_error(mysql, CR_NET_PACKET_TOO_LARGE, SQLSTATE_UNKNOWN, 0); + goto end; + } + end_server(mysql); + if (mariadb_reconnect(mysql)) + goto end; + if (ma_net_write_command(net,(uchar) command,arg, + length ? length : (ulong) strlen(arg), 0)) + { + my_set_error(mysql, CR_SERVER_GONE_ERROR, SQLSTATE_UNKNOWN, 0); + goto end; + } + } + result=0; + + if (net->extension->multi_status > COM_MULTI_OFF) + skipp_check= 1; + + if (!skipp_check) + { + result= ((mysql->packet_length=ma_net_safe_read(mysql)) == packet_error ? + 1 : 0); + } + end: + return(result); +} + +int +ma_simple_command(MYSQL *mysql,enum enum_server_command command, const char *arg, + size_t length, my_bool skipp_check, void *opt_arg) +{ + return mysql->methods->db_command(mysql, command, arg, length, skipp_check, opt_arg); +} + +int ma_multi_command(MYSQL *mysql, enum enum_multi_status status) +{ + NET *net= &mysql->net; + + switch (status) { + case COM_MULTI_OFF: + ma_net_clear(net); + net->extension->multi_status= status; + return 0; + case COM_MULTI_ENABLED: + if (net->extension->multi_status > COM_MULTI_DISABLED) + return 1; + ma_net_clear(net); + net->extension->multi_status= status; + return 0; + case COM_MULTI_DISABLED: + /* Opposite to COM_MULTI_OFF we don't clear net buffer, + next command or com_nulti_end will flush entire buffer */ + net->extension->multi_status= status; + return 0; + case COM_MULTI_END: + { + size_t len= net->write_pos - net->buff - NET_HEADER_SIZE; + + if (len < NET_HEADER_SIZE) /* don't send empty request */ + { + ma_net_clear(net); + return 1; + } + net->extension->multi_status= COM_MULTI_OFF; + return ma_net_flush(net); + } + case COM_MULTI_CANCEL: + ma_net_clear(net); + net->extension->multi_status= COM_MULTI_OFF; + return 0; + default: + return 1; + } +} + +static void free_old_query(MYSQL *mysql) +{ + if (mysql->fields) + ma_free_root(&mysql->field_alloc,MYF(0)); + ma_init_alloc_root(&mysql->field_alloc,8192,0); /* Assume rowlength < 8192 */ + mysql->fields=0; + mysql->field_count=0; /* For API */ + mysql->info= 0; + return; +} + +#if defined(HAVE_GETPWUID) && defined(NO_GETPWUID_DECL) +struct passwd *getpwuid(uid_t); +char* getlogin(void); +#endif + +#if !defined(_WIN32) +void read_user_name(char *name) +{ + if (geteuid() == 0) + strcpy(name,"root"); /* allow use of surun */ + else + { +#ifdef HAVE_GETPWUID + struct passwd *skr; + const char *str; + if ((skr=getpwuid(geteuid())) != NULL) + { + str=skr->pw_name; + } else if ((str=getlogin()) == NULL) + { + if (!(str=getenv("USER")) && !(str=getenv("LOGNAME")) && + !(str=getenv("LOGIN"))) + str="UNKNOWN_USER"; + } + ma_strmake(name,str,USERNAME_LENGTH); +#elif defined(HAVE_CUSERID) + (void) cuserid(name); +#else + ma_strmake(name,"UNKNOWN_USER", USERNAME_LENGTH); +#endif + } + return; +} + +#else /* WIN32 */ + +void read_user_name(char *name) +{ + char *str=getenv("USERNAME"); /* ODBC will send user variable */ + ma_strmake(name,str ? str : "ODBC", USERNAME_LENGTH); +} + +#endif + + +/************************************************************************** +** Shut down connection +**************************************************************************/ + +static void +end_server(MYSQL *mysql) +{ + /* if net->error 2 and reconnect is activated, we need to inforn + connection handler */ + if (mysql->net.pvio != 0) + { + ma_pvio_close(mysql->net.pvio); + mysql->net.pvio= 0; /* Marker */ + } + ma_net_end(&mysql->net); + free_old_query(mysql); + return; +} + +void mthd_my_skip_result(MYSQL *mysql) +{ + ulong pkt_len; + + do { + pkt_len= ma_net_safe_read(mysql); + if (pkt_len == packet_error) + break; + } while (pkt_len > 8 || mysql->net.read_pos[0] != 254); + return; +} + +void STDCALL +mysql_free_result(MYSQL_RES *result) +{ + if (result) + { + if (result->handle && result->handle->status == MYSQL_STATUS_USE_RESULT) + { + result->handle->methods->db_skip_result(result->handle); + result->handle->status=MYSQL_STATUS_READY; + } + free_rows(result->data); + if (result->fields) + ma_free_root(&result->field_alloc,MYF(0)); + if (result->row) + free(result->row); + free(result); + } + return; +} + + +/**************************************************************************** +** Get options from my.cnf +****************************************************************************/ +enum enum_option_type { + MARIADB_OPTION_NONE, + MARIADB_OPTION_BOOL, + MARIADB_OPTION_INT, + MARIADB_OPTION_SIZET, + MARIADB_OPTION_STR, +}; + +struct st_default_options { + enum mysql_option option; + enum enum_option_type type; + const char *conf_key; +}; + +struct st_default_options mariadb_defaults[] = +{ + {MARIADB_OPT_PORT, MARIADB_OPTION_INT,"port"}, + {MARIADB_OPT_UNIXSOCKET, MARIADB_OPTION_STR, "socket"}, + {MYSQL_OPT_COMPRESS, MARIADB_OPTION_BOOL, "compress"}, + {MARIADB_OPT_PASSWORD, MARIADB_OPTION_STR, "password"}, + {MYSQL_OPT_NAMED_PIPE, MARIADB_OPTION_BOOL, "pipe"}, + {MYSQL_OPT_CONNECT_TIMEOUT, MARIADB_OPTION_INT, "timeout"}, + {MARIADB_OPT_USER, MARIADB_OPTION_STR, "user"}, + {MYSQL_INIT_COMMAND, MARIADB_OPTION_STR, "init-command"}, + {MARIADB_OPT_HOST, MARIADB_OPTION_STR, "host"}, + {MARIADB_OPT_SCHEMA, MARIADB_OPTION_STR, "database"}, + {MARIADB_OPT_DEBUG, MARIADB_OPTION_STR, "debug"}, + {MARIADB_OPT_FOUND_ROWS, MARIADB_OPTION_NONE, "return-found-rows"}, + {MYSQL_OPT_SSL_KEY, MARIADB_OPTION_STR, "ssl-key"}, + {MYSQL_OPT_SSL_CERT, MARIADB_OPTION_STR,"ssl-cert"}, + {MYSQL_OPT_SSL_CA, MARIADB_OPTION_STR,"ssl-ca"}, + {MYSQL_OPT_SSL_CAPATH, MARIADB_OPTION_STR,"ssl-capath"}, + {MYSQL_OPT_SSL_CRL, MARIADB_OPTION_STR,"ssl-crl"}, + {MYSQL_OPT_SSL_CRLPATH, MARIADB_OPTION_STR,"ssl-crlpath"}, + {MYSQL_OPT_SSL_VERIFY_SERVER_CERT, MARIADB_OPTION_BOOL,"ssl-verify-server-cert"}, + {MYSQL_SET_CHARSET_DIR, MARIADB_OPTION_STR, "character-sets-dir"}, + {MYSQL_SET_CHARSET_NAME, MARIADB_OPTION_STR, "default-character-set"}, + {MARIADB_OPT_INTERACTIVE, MARIADB_OPTION_NONE, "interactive-timeout"}, + {MYSQL_OPT_CONNECT_TIMEOUT, MARIADB_OPTION_INT, "connect-timeout"}, + {MYSQL_OPT_LOCAL_INFILE, MARIADB_OPTION_BOOL, "local-infile"}, + {0, 0 ,"disable-local-infile",}, + {MYSQL_OPT_SSL_CIPHER, MARIADB_OPTION_STR, "ssl-cipher"}, + {MYSQL_OPT_MAX_ALLOWED_PACKET, MARIADB_OPTION_SIZET, "max-allowed-packet"}, + {MYSQL_OPT_NET_BUFFER_LENGTH, MARIADB_OPTION_SIZET, "net-buffer-length"}, + {MYSQL_OPT_PROTOCOL, MARIADB_OPTION_INT, "protocol"}, + {MYSQL_SHARED_MEMORY_BASE_NAME, MARIADB_OPTION_STR,"shared-memory-base-name"}, + {MARIADB_OPT_MULTI_RESULTS, MARIADB_OPTION_NONE, "multi-results"}, + {MARIADB_OPT_MULTI_STATEMENTS, MARIADB_OPTION_STR, "multi-statements"}, + {MARIADB_OPT_MULTI_STATEMENTS, MARIADB_OPTION_STR, "multi-queries"}, + {MYSQL_SECURE_AUTH, MARIADB_OPTION_BOOL, "secure-auth"}, + {MYSQL_REPORT_DATA_TRUNCATION, MARIADB_OPTION_BOOL, "report-data-truncation"}, + {MYSQL_OPT_RECONNECT, MARIADB_OPTION_BOOL, "reconnect"}, + {MYSQL_PLUGIN_DIR, MARIADB_OPTION_STR, "plugin-dir"}, + {MYSQL_DEFAULT_AUTH, MARIADB_OPTION_STR, "default-auth"}, + {MARIADB_OPT_SSL_FP, MARIADB_OPTION_STR, "ssl-fp"}, + {MARIADB_OPT_SSL_FP_LIST, MARIADB_OPTION_STR, "ssl-fp-list"}, + {MARIADB_OPT_SSL_FP_LIST, MARIADB_OPTION_STR, "ssl-fplist"}, + {MARIADB_OPT_TLS_PASSPHRASE, MARIADB_OPTION_STR, "ssl-passphrase"}, + {MARIADB_OPT_TLS_VERSION, MARIADB_OPTION_STR, "tls-version"}, + {MYSQL_SERVER_PUBLIC_KEY, MARIADB_OPTION_STR, "server-public-key"}, + {MYSQL_OPT_BIND, MARIADB_OPTION_STR, "bind-address"}, + {MYSQL_OPT_SSL_ENFORCE, MARIADB_OPTION_BOOL, "ssl-enforce"}, + {0, 0, NULL} +}; + +#define CHECK_OPT_EXTENSION_SET(OPTS)\ + if (!(OPTS)->extension) \ + (OPTS)->extension= (struct st_mysql_options_extension *) \ + calloc(1, sizeof(struct st_mysql_options_extension)); + +#define OPT_SET_EXTENDED_VALUE_STR(OPTS, KEY, VAL) \ + CHECK_OPT_EXTENSION_SET(OPTS) \ + free((gptr)(OPTS)->extension->KEY); \ + if((VAL)) \ + (OPTS)->extension->KEY= strdup((char *)(VAL)); \ + else \ + (OPTS)->extension->KEY= NULL + +#define OPT_SET_EXTENDED_VALUE(OPTS, KEY, VAL) \ + CHECK_OPT_EXTENSION_SET(OPTS) \ + (OPTS)->extension->KEY= (VAL) + +#define OPT_SET_EXTENDED_VALUE_INT(A,B,C) OPT_SET_EXTENDED_VALUE(A,B,C) + +#define OPT_SET_VALUE_STR(OPTS, KEY, VAL) \ + free((OPTS)->KEY); \ + if((VAL)) \ + (OPTS)->KEY= strdup((char *)(VAL)); \ + else \ + (OPTS)->KEY= NULL + +#define OPT_SET_VALUE_INT(OPTS, KEY, VAL) \ + (OPTS)->KEY= (VAL) + +static void options_add_initcommand(struct st_mysql_options *options, + const char *init_cmd) +{ + char *insert= strdup(init_cmd); + if (!options->init_command) + { + options->init_command= (DYNAMIC_ARRAY*)malloc(sizeof(DYNAMIC_ARRAY)); + ma_init_dynamic_array(options->init_command, sizeof(char*), 5, 5); + } + + if (ma_insert_dynamic(options->init_command, (gptr)&insert)) + free(insert); +} +my_bool _mariadb_set_conf_option(MYSQL *mysql, const char *config_option, const char *config_value) +{ + if (config_option) + { + int i; + char *c; + + /* CONC-395: replace underscore "_" by dash "-" */ + while ((c= strchr(config_option, '_'))) + *c= '-'; + + for (i=0; mariadb_defaults[i].conf_key; i++) + { + if (!strcmp(mariadb_defaults[i].conf_key, config_option)) + { + my_bool val_bool; + int val_int; + size_t val_sizet; + int rc; + void *option_val= NULL; + switch (mariadb_defaults[i].type) { + case MARIADB_OPTION_BOOL: + val_bool= 0; + if (config_value) + val_bool= atoi(config_value); + option_val= &val_bool; + break; + case MARIADB_OPTION_INT: + val_int= 0; + if (config_value) + val_int= atoi(config_value); + option_val= &val_int; + break; + case MARIADB_OPTION_SIZET: + val_sizet= 0; + if (config_value) + val_sizet= strtol(config_value, NULL, 10); + option_val= &val_sizet; + break; + case MARIADB_OPTION_STR: + option_val= (void*)config_value; + break; + case MARIADB_OPTION_NONE: + break; + } + rc= mysql_optionsv(mysql, mariadb_defaults[i].option, option_val); + return(test(rc)); + } + } + } + /* unknown key */ + return 1; +} + + +static MARIADB_CONST_STRING null_const_string= {0,0}; + +/*************************************************************************** +** Allocate a string copy on memroot +***************************************************************************/ +static MARIADB_CONST_STRING ma_const_string_copy_root(MA_MEM_ROOT *memroot, + const char *str, + size_t length) +{ + MARIADB_CONST_STRING res; + if (!str || !(res.str= ma_memdup_root(memroot, str, length))) + return null_const_string; + res.length= length; + return res; +} + + +/*************************************************************************** +** Allocate and initialize MA_FIELD_EXTENSION +***************************************************************************/ +MA_FIELD_EXTENSION *new_ma_field_extension(MA_MEM_ROOT *memroot) +{ + MA_FIELD_EXTENSION *ext= ma_alloc_root(memroot, sizeof(MA_FIELD_EXTENSION)); + if (ext) + memset((void *) ext, 0, sizeof(*ext)); + return ext; +} + + +/*************************************************************************** +** Populate field extension from a type info packet +***************************************************************************/ + +static void ma_field_extension_init_type_info(MA_MEM_ROOT *memroot, + MA_FIELD_EXTENSION *ext, + const char *ptr, size_t length) +{ + const char *end= ptr + length; + for ( ; ptr < end; ) + { + uint itype= (uchar) *ptr++; + uint len= (uchar) *ptr++; + if (ptr + len > end || len > 127) + break; /*Badly encoded data*/ + if (itype <= 127 && itype <= MARIADB_FIELD_ATTR_LAST) + ext->metadata[itype]= ma_const_string_copy_root(memroot, ptr, len); + ptr+= len; + } +} + + +/*************************************************************************** +** Allocate a field extension deep copy +***************************************************************************/ + +MA_FIELD_EXTENSION *ma_field_extension_deep_dup(MA_MEM_ROOT *memroot, + const MA_FIELD_EXTENSION *from) +{ + MA_FIELD_EXTENSION *ext= new_ma_field_extension(memroot); + uint i; + if (!ext) + return NULL; + for (i= 0; i < MARIADB_FIELD_ATTR_LAST; i++) + { + if (from->metadata[i].str) + ext->metadata[i]= ma_const_string_copy_root(memroot, + from->metadata[i].str, + from->metadata[i].length); + } + return ext; +} + +/*************************************************************************** +** Change field rows to field structs +***************************************************************************/ + +static size_t rset_field_offsets[]= { + OFFSET(MYSQL_FIELD, catalog), + OFFSET(MYSQL_FIELD, catalog_length), + OFFSET(MYSQL_FIELD, db), + OFFSET(MYSQL_FIELD, db_length), + OFFSET(MYSQL_FIELD, table), + OFFSET(MYSQL_FIELD, table_length), + OFFSET(MYSQL_FIELD, org_table), + OFFSET(MYSQL_FIELD, org_table_length), + OFFSET(MYSQL_FIELD, name), + OFFSET(MYSQL_FIELD, name_length), + OFFSET(MYSQL_FIELD, org_name), + OFFSET(MYSQL_FIELD, org_name_length) +}; + +MYSQL_FIELD * +unpack_fields(const MYSQL *mysql, + MYSQL_DATA *data, MA_MEM_ROOT *alloc, uint fields, + my_bool default_value) +{ + MYSQL_ROWS *row; + MYSQL_FIELD *field,*result; + char *p; + unsigned int i, field_count= sizeof(rset_field_offsets)/sizeof(size_t)/2; + + field=result=(MYSQL_FIELD*) ma_alloc_root(alloc,sizeof(MYSQL_FIELD)*fields); + if (!result) + return(0); + + for (row=data->data; row ; row = row->next,field++) + { + if (field >= result + fields) + goto error; + + for (i=0; i < field_count; i++) + { + uint length= (uint)(row->data[i+1] - row->data[i] - 1); + if (!row->data[i] && row->data[i][length]) + goto error; + + *(char **)(((char *)field) + rset_field_offsets[i*2])= + ma_strdup_root(alloc, (char *)row->data[i]); + *(unsigned int *)(((char *)field) + rset_field_offsets[i*2+1])= length; + } + + field->extension= NULL; + if (ma_has_extended_type_info(mysql)) + { + if (row->data[i+1] - row->data[i] > 1) + { + size_t len= row->data[i+1] - row->data[i] - 1; + MA_FIELD_EXTENSION *ext= new_ma_field_extension(alloc); + if ((field->extension= ext)) + ma_field_extension_init_type_info(alloc, ext, row->data[i], len); + } + i++; + } + + p= (char *)row->data[i]; + /* filler */ + field->charsetnr= uint2korr(p); + p+= 2; + field->length= (uint) uint4korr(p); + p+= 4; + field->type= (enum enum_field_types)uint1korr(p); + p++; + field->flags= uint2korr(p); + p+= 2; + field->decimals= (uint) p[0]; + p++; + + /* filler */ + p+= 2; + + if (INTERNAL_NUM_FIELD(field)) + field->flags|= NUM_FLAG; + + i++; + /* This is used by deprecated function mysql_list_fields only, + however the reported length is not correct, so we always zero it */ + if (default_value && row->data[i]) + field->def=ma_strdup_root(alloc,(char*) row->data[i]); + else + field->def=0; + field->def_length= 0; + + field->max_length= 0; + } + if (field < result + fields) + goto error; + free_rows(data); /* Free old data */ + return(result); +error: + free_rows(data); + ma_free_root(alloc, MYF(0)); + return(0); +} + + +/* Read all rows (fields or data) from server */ + +MYSQL_DATA *mthd_my_read_rows(MYSQL *mysql,MYSQL_FIELD *mysql_fields, + uint fields) +{ + uint field; + ulong pkt_len; + ulong len; + uchar *cp; + char *to, *end_to; + MYSQL_DATA *result; + MYSQL_ROWS **prev_ptr,*cur; + NET *net = &mysql->net; + + if ((pkt_len= ma_net_safe_read(mysql)) == packet_error) + return(0); + if (!(result=(MYSQL_DATA*) calloc(1, sizeof(MYSQL_DATA)))) + { + SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); + return(0); + } + ma_init_alloc_root(&result->alloc,8192,0); /* Assume rowlength < 8192 */ + result->alloc.min_malloc=sizeof(MYSQL_ROWS); + prev_ptr= &result->data; + result->rows=0; + result->fields=fields; + + while (*(cp=net->read_pos) != 254 || pkt_len >= 8) + { + result->rows++; + if (!(cur= (MYSQL_ROWS*) ma_alloc_root(&result->alloc, + sizeof(MYSQL_ROWS))) || + !(cur->data= ((MYSQL_ROW) + ma_alloc_root(&result->alloc, + (fields+1)*sizeof(char *)+fields+pkt_len)))) + { + free_rows(result); + SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); + return(0); + } + *prev_ptr=cur; + prev_ptr= &cur->next; + to= (char*) (cur->data+fields+1); + end_to=to+fields+pkt_len-1; + for (field=0 ; field < fields ; field++) + { + if ((len=(ulong) net_field_length(&cp)) == NULL_LENGTH) + { /* null field */ + cur->data[field] = 0; + } + else + { + cur->data[field] = to; + if (len > (ulong)(end_to - to) || to > end_to) + { + free_rows(result); + SET_CLIENT_ERROR(mysql, CR_UNKNOWN_ERROR, SQLSTATE_UNKNOWN, 0); + return(0); + } + memcpy(to,(char*) cp,len); to[len]=0; + to+=len+1; + cp+=len; + if (mysql_fields) + { + if (mysql_fields[field].max_length < len) + mysql_fields[field].max_length=len; + } + } + } + cur->data[field]=to; /* End of last field */ + if ((pkt_len=ma_net_safe_read(mysql)) == packet_error) + { + free_rows(result); + return(0); + } + } + *prev_ptr=0; /* last pointer is null */ + /* save status */ + if (pkt_len > 1) + { + cp++; + mysql->warning_count= uint2korr(cp); + cp+= 2; + mysql->server_status= uint2korr(cp); + } + return(result); +} + + +/* +** Read one row. Uses packet buffer as storage for fields. +** When next packet is read, the previous field values are destroyed +*/ + + +int mthd_my_read_one_row(MYSQL *mysql,uint fields,MYSQL_ROW row, ulong *lengths) +{ + uint field; + ulong pkt_len,len; + uchar *pos,*prev_pos, *end_pos; + + if ((pkt_len=(uint) ma_net_safe_read(mysql)) == packet_error) + return -1; + + if (pkt_len <= 8 && mysql->net.read_pos[0] == 254) + { + mysql->warning_count= uint2korr(mysql->net.read_pos + 1); + mysql->server_status= uint2korr(mysql->net.read_pos + 3); + return 1; /* End of data */ + } + prev_pos= 0; /* allowed to write at packet[-1] */ + pos=mysql->net.read_pos; + end_pos=pos+pkt_len; + for (field=0 ; field < fields ; field++) + { + if ((len=(ulong) net_field_length(&pos)) == NULL_LENGTH) + { /* null field */ + row[field] = 0; + *lengths++=0; + } + else + { + if (len > (ulong) (end_pos - pos) || pos > end_pos) + { + mysql->net.last_errno=CR_UNKNOWN_ERROR; + strncpy(mysql->net.last_error,ER(mysql->net.last_errno), + MYSQL_ERRMSG_SIZE - 1); + return -1; + } + row[field] = (char*) pos; + pos+=len; + *lengths++=len; + } + if (prev_pos) + *prev_pos=0; /* Terminate prev field */ + prev_pos=pos; + } + row[field]=(char*) prev_pos+1; /* End of last field */ + *prev_pos=0; /* Terminate last field */ + return 0; +} + +/**************************************************************************** +** Init MySQL structure or allocate one +****************************************************************************/ + +MYSQL * STDCALL +mysql_init(MYSQL *mysql) +{ + if (mysql_server_init(0, NULL, NULL)) + return NULL; + if (!mysql) + { + if (!(mysql=(MYSQL*) calloc(1, sizeof(MYSQL)))) + return 0; + mysql->free_me=1; + mysql->net.pvio= 0; + mysql->net.extension= 0; + } + else + { + memset((char*) (mysql), 0, sizeof(*(mysql))); + mysql->net.pvio= 0; + mysql->free_me= 0; + mysql->net.extension= 0; + } + + if (!(mysql->net.extension= (struct st_mariadb_net_extension *) + calloc(1, sizeof(struct st_mariadb_net_extension))) || + !(mysql->extension= (struct st_mariadb_extension *) + calloc(1, sizeof(struct st_mariadb_extension)))) + goto error; + mysql->options.report_data_truncation= 1; + mysql->options.connect_timeout=CONNECT_TIMEOUT; + mysql->charset= mysql_find_charset_name(MARIADB_DEFAULT_CHARSET); + mysql->methods= &MARIADB_DEFAULT_METHODS; + strcpy(mysql->net.sqlstate, "00000"); + mysql->net.last_error[0]= mysql->net.last_errno= mysql->net.extension->extended_errno= 0; + + if (ENABLED_LOCAL_INFILE != LOCAL_INFILE_MODE_OFF) + mysql->options.client_flag|= CLIENT_LOCAL_FILES; + mysql->extension->auto_local_infile= ENABLED_LOCAL_INFILE == LOCAL_INFILE_MODE_AUTO + ? WAIT_FOR_QUERY : ALWAYS_ACCEPT; + mysql->options.reconnect= 0; + return mysql; +error: + if (mysql->free_me) + free(mysql); + return 0; +} + +int STDCALL +mysql_ssl_set(MYSQL *mysql __attribute__((unused)), + const char *key __attribute__((unused)), + const char *cert __attribute__((unused)), + const char *ca __attribute__((unused)), + const char *capath __attribute__((unused)), + const char *cipher __attribute__((unused))) +{ +#ifdef HAVE_TLS + char enable= 1; + return (mysql_optionsv(mysql, MYSQL_OPT_SSL_ENFORCE, &enable) | + mysql_optionsv(mysql, MYSQL_OPT_SSL_KEY, key) | + mysql_optionsv(mysql, MYSQL_OPT_SSL_CERT, cert) | + mysql_optionsv(mysql, MYSQL_OPT_SSL_CA, ca) | + mysql_optionsv(mysql, MYSQL_OPT_SSL_CAPATH, capath) | + mysql_optionsv(mysql, MYSQL_OPT_SSL_CIPHER, cipher)) ? 1 : 0; +#else + return 0; +#endif +} + +/************************************************************************** +**************************************************************************/ + +const char * STDCALL +mysql_get_ssl_cipher(MYSQL *mysql __attribute__((unused))) +{ +#ifdef HAVE_TLS + if (mysql->net.pvio && mysql->net.pvio->ctls) + { + return ma_pvio_tls_cipher(mysql->net.pvio->ctls); + } +#endif + return(NULL); +} + +/************************************************************************** +** Free strings in the SSL structure and clear 'use_ssl' flag. +** NB! Errors are not reported until you do mysql_real_connect. +**************************************************************************/ + +char *ma_send_connect_attr(MYSQL *mysql, unsigned char *buffer) +{ + if (mysql->server_capabilities & CLIENT_CONNECT_ATTRS) + { + buffer= (unsigned char *)mysql_net_store_length((unsigned char *)buffer, (mysql->options.extension) ? + mysql->options.extension->connect_attrs_len : 0); + if (mysql->options.extension && + ma_hashtbl_inited(&mysql->options.extension->connect_attrs)) + { + uint i; + for (i=0; i < mysql->options.extension->connect_attrs.records; i++) + { + size_t len; + uchar *p= ma_hashtbl_element(&mysql->options.extension->connect_attrs, i); + + len= strlen((char *)p); + buffer= mysql_net_store_length(buffer, len); + memcpy(buffer, p, len); + buffer+= (len); + p+= (len + 1); + len= strlen((char *)p); + buffer= mysql_net_store_length(buffer, len); + memcpy(buffer, p, len); + buffer+= len; + } + } + } + return (char *)buffer; +} + +/** set some default attributes */ +static my_bool +ma_set_connect_attrs(MYSQL *mysql, const char *host) +{ + char buffer[255]; + int rc= 0; + + rc= mysql_options(mysql, MYSQL_OPT_CONNECT_ATTR_DELETE, "_client_name") + + mysql_options(mysql, MYSQL_OPT_CONNECT_ATTR_DELETE, "_client_version") + + mysql_options(mysql, MYSQL_OPT_CONNECT_ATTR_DELETE, "_os") + + mysql_options(mysql, MYSQL_OPT_CONNECT_ATTR_DELETE, "_server_host") + +#ifdef _WIN32 + mysql_options(mysql, MYSQL_OPT_CONNECT_ATTR_DELETE, "_thread") + +#endif + mysql_options(mysql, MYSQL_OPT_CONNECT_ATTR_DELETE, "_pid") + + mysql_options(mysql, MYSQL_OPT_CONNECT_ATTR_DELETE, "_platform"); + + rc+= mysql_optionsv(mysql, MYSQL_OPT_CONNECT_ATTR_ADD, "_client_name", "libmariadb") + + mysql_optionsv(mysql, MYSQL_OPT_CONNECT_ATTR_ADD, "_client_version", MARIADB_PACKAGE_VERSION) + + mysql_optionsv(mysql, MYSQL_OPT_CONNECT_ATTR_ADD, "_os", MARIADB_SYSTEM_TYPE); + + if (host && *host) + rc+= mysql_optionsv(mysql, MYSQL_OPT_CONNECT_ATTR_ADD, "_server_host", host); + +#ifdef _WIN32 + snprintf(buffer, 255, "%lu", (ulong) GetCurrentThreadId()); + rc+= mysql_optionsv(mysql, MYSQL_OPT_CONNECT_ATTR_ADD, "_thread", buffer); + snprintf(buffer, 255, "%lu", (ulong) GetCurrentProcessId()); +#else + snprintf(buffer, 255, "%lu", (ulong) getpid()); +#endif + rc+= mysql_optionsv(mysql, MYSQL_OPT_CONNECT_ATTR_ADD, "_pid", buffer); + + rc+= mysql_optionsv(mysql, MYSQL_OPT_CONNECT_ATTR_ADD, "_platform", MARIADB_MACHINE_TYPE); + return(test(rc>0)); +} + +/* +** Note that the mysql argument must be initialized with mysql_init() +** before calling mysql_real_connect ! +*/ + +MYSQL * STDCALL +mysql_real_connect(MYSQL *mysql, const char *host, const char *user, + const char *passwd, const char *db, + uint port, const char *unix_socket,unsigned long client_flag) +{ + char *end= NULL; + char *connection_handler= (mysql->options.extension) ? + mysql->options.extension->connection_handler : 0; + + if (!mysql->methods) + mysql->methods= &MARIADB_DEFAULT_METHODS; + + if (connection_handler || + (host && (end= strstr(host, "://")))) + { + MARIADB_CONNECTION_PLUGIN *plugin; + char plugin_name[64]; + + if (!connection_handler || !connection_handler[0]) + { + memset(plugin_name, 0, 64); + ma_strmake(plugin_name, host, MIN(end - host, 63)); + end+= 3; + } + else + ma_strmake(plugin_name, connection_handler, MIN(63, strlen(connection_handler))); + + if (!(plugin= (MARIADB_CONNECTION_PLUGIN *)mysql_client_find_plugin(mysql, plugin_name, MARIADB_CLIENT_CONNECTION_PLUGIN))) + return NULL; + + if (!(mysql->extension->conn_hdlr= (MA_CONNECTION_HANDLER *)calloc(1, sizeof(MA_CONNECTION_HANDLER)))) + { + SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); + return NULL; + } + + /* save URL for reconnect */ + OPT_SET_EXTENDED_VALUE_STR(&mysql->options, url, host); + + mysql->extension->conn_hdlr->plugin= plugin; + + if (plugin && plugin->connect) + { + MYSQL *my= plugin->connect(mysql, end, user, passwd, db, port, unix_socket, client_flag); + if (!my) + { + free(mysql->extension->conn_hdlr); + mysql->extension->conn_hdlr= NULL; + } + return my; + } + } +#ifndef HAVE_SCHANNEL + return mysql->methods->db_connect(mysql, host, user, passwd, + db, port, unix_socket, client_flag); +#else +/* + With older windows versions (prior Win 10) TLS connections periodically + fail with SEC_E_INVALID_TOKEN, SEC_E_BUFFER_TOO_SMALL or SEC_E_MESSAGE_ALTERED + error (see MDEV-13492). If the connect attempt returns on of these error codes + in mysql->net.extended_errno we will try to connect again (max. 3 times) +*/ +#define MAX_SCHANNEL_CONNECT_ATTEMPTS 3 + { + int ssl_retry= (mysql->options.use_ssl) ? MAX_SCHANNEL_CONNECT_ATTEMPTS : 1; + MYSQL *my= NULL; + while (ssl_retry) + { + if ((my= mysql->methods->db_connect(mysql, host, user, passwd, + db, port, unix_socket, client_flag | CLIENT_REMEMBER_OPTIONS))) + return my; + + switch (mysql->net.extension->extended_errno) { + case SEC_E_INVALID_TOKEN: + case SEC_E_BUFFER_TOO_SMALL: + case SEC_E_MESSAGE_ALTERED: + ssl_retry--; + break; + default: + ssl_retry= 0; + break; + } + } + if (!my && !(client_flag & CLIENT_REMEMBER_OPTIONS)) + mysql_close_options(mysql); + return my; + } +#endif +} + +MYSQL *mthd_my_real_connect(MYSQL *mysql, const char *host, const char *user, + const char *passwd, const char *db, + uint port, const char *unix_socket, unsigned long client_flag) +{ + char buff[NAME_LEN+USERNAME_LENGTH+100]; + char *end, *end_pkt, *host_info; + MA_PVIO_CINFO cinfo= {NULL, NULL, 0, -1, NULL}; + MARIADB_PVIO *pvio= NULL; + char *scramble_data; + my_bool is_maria= 0; + const char *scramble_plugin; + uint pkt_length, scramble_len, pkt_scramble_len= 0; + NET *net= &mysql->net; + + if (!mysql->methods) + mysql->methods= &MARIADB_DEFAULT_METHODS; + + if (net->pvio) /* check if we are already connected */ + { + SET_CLIENT_ERROR(mysql, CR_ALREADY_CONNECTED, SQLSTATE_UNKNOWN, 0); + return(NULL); + } + + /* use default options */ + if (mysql->options.my_cnf_file || mysql->options.my_cnf_group) + { + _mariadb_read_options(mysql, NULL, + (mysql->options.my_cnf_file ? + mysql->options.my_cnf_file : NULL), + mysql->options.my_cnf_group, 0); + free(mysql->options.my_cnf_file); + free(mysql->options.my_cnf_group); + mysql->options.my_cnf_file=mysql->options.my_cnf_group=0; + } + + if (!host || !host[0]) + host = mysql->options.host; + + ma_set_connect_attrs(mysql, host); + +#ifndef WIN32 + if (mysql->options.protocol > MYSQL_PROTOCOL_SOCKET) + { + SET_CLIENT_ERROR(mysql, CR_CONN_UNKNOWN_PROTOCOL, SQLSTATE_UNKNOWN, 0); + return(NULL); + } +#endif + + /* Some empty-string-tests are done because of ODBC */ + if (!user || !user[0]) + user=mysql->options.user; + if (!passwd) + { + passwd=mysql->options.password; +#ifndef DONT_USE_MYSQL_PWD + if (!passwd) + passwd=getenv("MYSQL_PWD"); /* get it from environment (haneke) */ + if (!passwd) + passwd= ""; +#endif + } + if (!db || !db[0]) + db=mysql->options.db; + if (!port) + port=mysql->options.port; + if (!unix_socket) + unix_socket=mysql->options.unix_socket; + + mysql->server_status=SERVER_STATUS_AUTOCOMMIT; + + /* try to connect via pvio_init */ + cinfo.host= host; + cinfo.unix_socket= unix_socket; + cinfo.port= port; + cinfo.mysql= mysql; + + /* + ** Grab a socket and connect it to the server + */ +#ifndef _WIN32 +#if defined(HAVE_SYS_UN_H) + if ((!host || strcmp(host,LOCAL_HOST) == 0) && + mysql->options.protocol != MYSQL_PROTOCOL_TCP && + (unix_socket || mysql_unix_port)) + { + cinfo.host= LOCAL_HOST; + cinfo.unix_socket= (unix_socket) ? unix_socket : mysql_unix_port; + cinfo.type= PVIO_TYPE_UNIXSOCKET; + sprintf(host_info=buff,ER(CR_LOCALHOST_CONNECTION),cinfo.host); + } + else +#endif +#else + if (mysql->options.protocol == MYSQL_PROTOCOL_MEMORY) + { + cinfo.host= mysql->options.shared_memory_base_name; + cinfo.type= PVIO_TYPE_SHAREDMEM; + sprintf(host_info=buff,ER(CR_SHARED_MEMORY_CONNECTION), cinfo.host ? cinfo.host : SHM_DEFAULT_NAME); + } + /* named pipe */ + else if (mysql->options.protocol == MYSQL_PROTOCOL_PIPE || + (host && strcmp(host,LOCAL_HOST_NAMEDPIPE) == 0)) + { + cinfo.type= PVIO_TYPE_NAMEDPIPE; + sprintf(host_info=buff,ER(CR_NAMEDPIPE_CONNECTION),cinfo.host); + } + else +#endif + { + cinfo.unix_socket=0; /* This is not used */ + if (!port) + port=mysql_port; + if (!host) + host=LOCAL_HOST; + cinfo.host= host; + cinfo.port= port; + cinfo.type= PVIO_TYPE_SOCKET; + sprintf(host_info=buff,ER(CR_TCP_CONNECTION), cinfo.host); + } + /* Initialize and load pvio plugin */ + if (!(pvio= ma_pvio_init(&cinfo))) + goto error; + + /* try to connect */ + if (ma_pvio_connect(pvio, &cinfo) != 0) + { + ma_pvio_close(pvio); + goto error; + } + + if (mysql->options.extension && mysql->options.extension->proxy_header) + { + char *hdr = mysql->options.extension->proxy_header; + size_t len = mysql->options.extension->proxy_header_len; + if (ma_pvio_write(pvio, (unsigned char *)hdr, len) <= 0) + { + ma_pvio_close(pvio); + goto error; + } + } + + if (ma_net_init(net, pvio)) + goto error; + + if (mysql->options.max_allowed_packet) + net->max_packet_size= mysql->options.max_allowed_packet; + + ma_pvio_keepalive(net->pvio); + strcpy(mysql->net.sqlstate, "00000"); + + /* Get version info */ + mysql->protocol_version= PROTOCOL_VERSION; /* Assume this */ +/* + if (ma_pvio_wait_io_or_timeout(net->pvio, FALSE, 0) < 1) + { + my_set_error(mysql, CR_SERVER_LOST, SQLSTATE_UNKNOWN, + ER(CR_SERVER_LOST_EXTENDED), + "handshake: waiting for initial communication packet", + errno); + goto error; + } + */ + if ((pkt_length=ma_net_safe_read(mysql)) == packet_error) + { + if (mysql->net.last_errno == CR_SERVER_LOST) + my_set_error(mysql, CR_SERVER_LOST, SQLSTATE_UNKNOWN, + ER(CR_SERVER_LOST_EXTENDED), + "handshake: reading initial communication packet", + errno); + + goto error; + } + end= (char *)net->read_pos; + end_pkt= (char *)net->read_pos + pkt_length; + + /* Check if version of protocol matches current one */ + + mysql->protocol_version= end[0]; + end++; + + /* Check if server sends an error */ + if (mysql->protocol_version == 0XFF) + { + net_get_error(end, pkt_length - 1, net->last_error, sizeof(net->last_error), + &net->last_errno, net->sqlstate); + /* fix for bug #26426 */ + if (net->last_errno == 1040) + memcpy(net->sqlstate, "08004", SQLSTATE_LENGTH); + goto error; + } + + if (mysql->protocol_version < PROTOCOL_VERSION) + { + net->last_errno= CR_VERSION_ERROR; + sprintf(net->last_error, ER(CR_VERSION_ERROR), mysql->protocol_version, + PROTOCOL_VERSION); + goto error; + } + /* Save connection information */ + if (!user) user=""; + + if (!(mysql->host_info= strdup(host_info)) || + !(mysql->host= strdup(cinfo.host ? cinfo.host : "")) || + !(mysql->user=strdup(user)) || + !(mysql->passwd=strdup(passwd))) + { + SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); + goto error; + } + if (cinfo.unix_socket) + mysql->unix_socket= strdup(cinfo.unix_socket); + else + mysql->unix_socket=0; + mysql->port=port; + client_flag|=mysql->options.client_flag; + + if (strncmp(end, MA_RPL_VERSION_HACK, sizeof(MA_RPL_VERSION_HACK) - 1) == 0) + { + mysql->server_version= strdup(end + sizeof(MA_RPL_VERSION_HACK) - 1); + is_maria= 1; + } + else + { + if (!(mysql->server_version= strdup(end))) + { + SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); + goto error; + } + } + end+= strlen(end) + 1; + + mysql->thread_id=uint4korr(end); + end+=4; + + /* This is the first part of scramble packet. In 4.1 and later + a second package will follow later */ + scramble_data= end; + scramble_len= SCRAMBLE_LENGTH_323 + 1; + scramble_plugin= old_password_plugin_name; + end+= SCRAMBLE_LENGTH_323; + + /* 1st pad */ + end++; + + if (end + 1<= end_pkt) + { + mysql->server_capabilities=uint2korr(end); + } + + /* mysql 5.5 protocol */ + if (end + 18 <= end_pkt) + { + mysql->server_language= uint1korr(end + 2); + mysql->server_status= uint2korr(end + 3); + mysql->server_capabilities|= (unsigned int)(uint2korr(end + 5)) << 16; + pkt_scramble_len= uint1korr(end + 7); + + /* check if MariaD2B specific capabilities are available */ + if (is_maria && !(mysql->server_capabilities & CLIENT_MYSQL)) + { + mysql->extension->mariadb_server_capabilities= (ulonglong) uint4korr(end + 14); + } + } + + /* pad 2 */ + end+= 18; + + /* second scramble package */ + if (end + SCRAMBLE_LENGTH - SCRAMBLE_LENGTH_323 + 1 <= end_pkt) + { + memcpy(end - SCRAMBLE_LENGTH_323, scramble_data, SCRAMBLE_LENGTH_323); + scramble_data= end - SCRAMBLE_LENGTH_323; + if (mysql->server_capabilities & CLIENT_PLUGIN_AUTH) + { + scramble_len= pkt_scramble_len; + scramble_plugin= scramble_data + scramble_len; + if (scramble_data + scramble_len > end_pkt) + { + SET_CLIENT_ERROR(mysql, CR_MALFORMED_PACKET, SQLSTATE_UNKNOWN, 0); + goto error; + } + } else + { + scramble_len= (uint)(end_pkt - scramble_data); + scramble_plugin= native_password_plugin_name; + } + } else + { + mysql->server_capabilities&= ~CLIENT_SECURE_CONNECTION; + if (mysql->options.secure_auth) + { + SET_CLIENT_ERROR(mysql, CR_SECURE_AUTH, SQLSTATE_UNKNOWN, 0); + goto error; + } + } + + /* Set character set */ + if (mysql->options.charset_name) + mysql->charset= mysql_find_charset_name(mysql->options.charset_name); + else + mysql->charset=mysql_find_charset_name(MARIADB_DEFAULT_CHARSET); + + if (!mysql->charset) + { + net->last_errno=CR_CANT_READ_CHARSET; + sprintf(net->last_error,ER(net->last_errno), + mysql->options.charset_name ? mysql->options.charset_name : + MARIADB_DEFAULT_CHARSET, + "compiled_in"); + goto error; + } + + mysql->client_flag= client_flag; + + if (run_plugin_auth(mysql, scramble_data, scramble_len, + scramble_plugin, db)) + goto error; + + if (mysql->client_flag & CLIENT_COMPRESS) + net->compress= 1; + + /* last part: select default db */ + if (!(mysql->server_capabilities & CLIENT_CONNECT_WITH_DB) && + (db && !mysql->db)) + { + if (mysql_select_db(mysql, db)) + { + my_set_error(mysql, CR_SERVER_LOST, SQLSTATE_UNKNOWN, + ER(CR_SERVER_LOST_EXTENDED), + "Setting intital database", + errno); + goto error; + } + } + + if (mysql->options.init_command) + { + char **begin= (char **)mysql->options.init_command->buffer; + char **end= begin + mysql->options.init_command->elements; + + /* Avoid reconnect in mysql_real_connect */ + my_bool save_reconnect= mysql->options.reconnect; + mysql->options.reconnect= 0; + + for (;begin < end; begin++) + { + if (mysql_real_query(mysql, *begin, (unsigned long)strlen(*begin))) + goto error; + + /* check if query produced a result set */ + do { + MYSQL_RES *res; + if ((res= mysql_use_result(mysql))) + mysql_free_result(res); + } while (!mysql_next_result(mysql)); + } + mysql->options.reconnect= save_reconnect; + } + + strcpy(mysql->net.sqlstate, "00000"); + + /* connection established, apply timeouts */ + ma_pvio_set_timeout(mysql->net.pvio, PVIO_READ_TIMEOUT, mysql->options.read_timeout); + ma_pvio_set_timeout(mysql->net.pvio, PVIO_WRITE_TIMEOUT, mysql->options.write_timeout); + return(mysql); + +error: + /* Free allocated memory */ + end_server(mysql); + /* only free the allocated memory, user needs to call mysql_close */ + mysql_close_memory(mysql); + if (!(client_flag & CLIENT_REMEMBER_OPTIONS) && + !(IS_MYSQL_ASYNC(mysql))) + mysql_close_options(mysql); + return(0); +} + +struct my_hook_data { + MYSQL *orig_mysql; + MYSQL *new_mysql; + /* This is always NULL currently, but restoring does not hurt just in case. */ + MARIADB_PVIO *orig_pvio; +}; +/* + Callback hook to make the new VIO accessible via the old MYSQL to calling + application when suspending a non-blocking call during automatic reconnect. +*/ +static void +my_suspend_hook(my_bool suspend, void *data) +{ + struct my_hook_data *hook_data= (struct my_hook_data *)data; + if (suspend) + { + hook_data->orig_pvio= hook_data->orig_mysql->net.pvio; + hook_data->orig_mysql->net.pvio= hook_data->new_mysql->net.pvio; + } + else + hook_data->orig_mysql->net.pvio= hook_data->orig_pvio; +} + +my_bool STDCALL mariadb_reconnect(MYSQL *mysql) +{ + MYSQL tmp_mysql; + struct my_hook_data hook_data; + struct mysql_async_context *ctxt= NULL; + LIST *li_stmt= mysql->stmts; + + /* check if connection handler is active */ + if (IS_CONNHDLR_ACTIVE(mysql)) + { + if (mysql->extension->conn_hdlr->plugin && mysql->extension->conn_hdlr->plugin->reconnect) + return(mysql->extension->conn_hdlr->plugin->reconnect(mysql)); + } + + if (!mysql->options.reconnect || + (mysql->server_status & SERVER_STATUS_IN_TRANS) || !mysql->host_info) + { + /* Allow reconnect next time */ + mysql->server_status&= ~SERVER_STATUS_IN_TRANS; + my_set_error(mysql, CR_SERVER_GONE_ERROR, SQLSTATE_UNKNOWN, 0); + return(1); + } + + mysql_init(&tmp_mysql); + tmp_mysql.free_me= 0; + tmp_mysql.options=mysql->options; + if (mysql->extension->conn_hdlr) + { + tmp_mysql.extension->conn_hdlr= mysql->extension->conn_hdlr; + mysql->extension->conn_hdlr= 0; + } + + /* don't reread options from configuration files */ + tmp_mysql.options.my_cnf_group= tmp_mysql.options.my_cnf_file= NULL; + if (IS_MYSQL_ASYNC_ACTIVE(mysql)) + { + ctxt= mysql->options.extension->async_context; + hook_data.orig_mysql= mysql; + hook_data.new_mysql= &tmp_mysql; + hook_data.orig_pvio= mysql->net.pvio; + my_context_install_suspend_resume_hook(ctxt, my_suspend_hook, &hook_data); + } + + if (!mysql_real_connect(&tmp_mysql,mysql->host,mysql->user,mysql->passwd, + mysql->db, mysql->port, mysql->unix_socket, + mysql->client_flag | CLIENT_REMEMBER_OPTIONS) || + mysql_set_character_set(&tmp_mysql, mysql->charset->csname)) + { + if (ctxt) + my_context_install_suspend_resume_hook(ctxt, NULL, NULL); + /* don't free options (CONC-118) */ + memset(&tmp_mysql.options, 0, sizeof(struct st_mysql_options)); + my_set_error(mysql, tmp_mysql.net.last_errno, + tmp_mysql.net.sqlstate, + tmp_mysql.net.last_error); + mysql_close(&tmp_mysql); + return(1); + } + + for (;li_stmt;li_stmt= li_stmt->next) + { + MYSQL_STMT *stmt= (MYSQL_STMT *)li_stmt->data; + + if (stmt->state != MYSQL_STMT_INITTED) + { + stmt->state= MYSQL_STMT_INITTED; + SET_CLIENT_STMT_ERROR(stmt, CR_SERVER_LOST, SQLSTATE_UNKNOWN, 0); + } + } + + tmp_mysql.free_me= mysql->free_me; + tmp_mysql.stmts= mysql->stmts; + mysql->stmts= NULL; + + if (ctxt) + my_context_install_suspend_resume_hook(ctxt, NULL, NULL); + /* Don't free options, we moved them to tmp_mysql */ + memset(&mysql->options, 0, sizeof(mysql->options)); + mysql->free_me=0; + mysql_close(mysql); + *mysql=tmp_mysql; + mysql->net.pvio->mysql= mysql; + ma_net_clear(&mysql->net); + mysql->affected_rows= ~(unsigned long long) 0; + mysql->info= 0; + return(0); +} + +void ma_invalidate_stmts(MYSQL *mysql, const char *function_name) +{ + if (mysql->stmts) + { + LIST *li_stmt= mysql->stmts; + + for (; li_stmt; li_stmt= li_stmt->next) + { + MYSQL_STMT *stmt= (MYSQL_STMT *)li_stmt->data; + stmt->mysql= NULL; + SET_CLIENT_STMT_ERROR(stmt, CR_STMT_CLOSED, SQLSTATE_UNKNOWN, function_name); + } + mysql->stmts= NULL; + } +} + +/* + Legacy support of the MariaDB 5.5 version, where timeouts where only in + seconds resolution. Applications that use this will be asked to set a timeout + at the nearest higher whole-seconds value. +*/ +unsigned int STDCALL +mysql_get_timeout_value(const MYSQL *mysql) +{ + unsigned int timeout= 0; + + if (mysql->options.extension && mysql->options.extension->async_context) + timeout= mysql->options.extension->async_context->timeout_value; + /* Avoid overflow. */ + if (timeout > UINT_MAX - 999) + return (timeout - 1)/1000 + 1; + else + return (timeout+999)/1000; +} + + +unsigned int STDCALL +mysql_get_timeout_value_ms(const MYSQL *mysql) +{ + if (mysql->options.extension && mysql->options.extension->async_context) + return mysql->options.extension->async_context->timeout_value; + return 0; +} + +/************************************************************************** +** Change user and database +**************************************************************************/ + +my_bool STDCALL mysql_change_user(MYSQL *mysql, const char *user, + const char *passwd, const char *db) +{ + const MARIADB_CHARSET_INFO *s_cs= mysql->charset; + char *s_user= mysql->user, + *s_passwd= mysql->passwd, + *s_db= mysql->db; + int rc; + + if (mysql->options.charset_name) + mysql->charset= mysql_find_charset_name(mysql->options.charset_name); + else + mysql->charset=mysql_find_charset_name(MARIADB_DEFAULT_CHARSET); + + mysql->user= strdup(user ? user : ""); + mysql->passwd= strdup(passwd ? passwd : ""); + + /* db will be set in run_plugin_auth */ + mysql->db= 0; + rc= run_plugin_auth(mysql, 0, 0, 0, db); + + /* COM_CHANGE_USER always releases prepared statements, so we need to invalidate them */ + ma_invalidate_stmts(mysql, "mysql_change_user()"); + + if (rc==0) + { + free(s_user); + free(s_passwd); + free(s_db); + + if (!mysql->db && db && !(mysql->db= strdup(db))) + { + SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); + rc= 1; + } + } else + { + free(mysql->user); + free(mysql->passwd); + free(mysql->db); + + mysql->user= s_user; + mysql->passwd= s_passwd; + mysql->db= s_db; + mysql->charset= s_cs; + } + return(rc); +} + + +/************************************************************************** +** Set current database +**************************************************************************/ + +int STDCALL +mysql_select_db(MYSQL *mysql, const char *db) +{ + int error; + + if (!db) + return 1; + + if ((error=ma_simple_command(mysql, COM_INIT_DB, db, + (uint) strlen(db),0,0))) + return(error); + free(mysql->db); + mysql->db=strdup(db); + return(0); +} + + +/************************************************************************* +** Send a QUIT to the server and close the connection +** If handle is allocated by mysql connect free it. +*************************************************************************/ + +static void mysql_close_options(MYSQL *mysql) +{ + if (mysql->options.init_command) + { + char **begin= (char **)mysql->options.init_command->buffer; + char **end= begin + mysql->options.init_command->elements; + + for (;begin < end; begin++) + free(*begin); + ma_delete_dynamic(mysql->options.init_command); + free(mysql->options.init_command); + } + free(mysql->options.user); + free(mysql->options.host); + free(mysql->options.password); + free(mysql->options.unix_socket); + free(mysql->options.db); + free(mysql->options.my_cnf_file); + free(mysql->options.my_cnf_group); + free(mysql->options.charset_dir); + free(mysql->options.charset_name); + free(mysql->options.bind_address); + free(mysql->options.ssl_key); + free(mysql->options.ssl_cert); + free(mysql->options.ssl_ca); + free(mysql->options.ssl_capath); + free(mysql->options.ssl_cipher); + + if (mysql->options.extension) + { + struct mysql_async_context *ctxt; + if ((ctxt = mysql->options.extension->async_context)) + { + my_context_destroy(&ctxt->async_context); + free(ctxt); + mysql->options.extension->async_context= 0; + } + free(mysql->options.extension->plugin_dir); + free(mysql->options.extension->default_auth); + free(mysql->options.extension->db_driver); + free(mysql->options.extension->ssl_crl); + free(mysql->options.extension->ssl_crlpath); + free(mysql->options.extension->tls_fp); + free(mysql->options.extension->tls_fp_list); + free(mysql->options.extension->tls_pw); + free(mysql->options.extension->tls_version); + free(mysql->options.extension->url); + free(mysql->options.extension->connection_handler); + if(ma_hashtbl_inited(&mysql->options.extension->connect_attrs)) + ma_hashtbl_free(&mysql->options.extension->connect_attrs); + if (ma_hashtbl_inited(&mysql->options.extension->userdata)) + ma_hashtbl_free(&mysql->options.extension->userdata); + + } + free(mysql->options.extension); + /* clear all pointer */ + memset(&mysql->options, 0, sizeof(mysql->options)); +} + +static void mysql_close_memory(MYSQL *mysql) +{ + ma_clear_session_state(mysql); + free(mysql->host_info); + free(mysql->host); + free(mysql->user); + free(mysql->passwd); + free(mysql->db); + free(mysql->unix_socket); + free(mysql->server_version); + mysql->host_info= mysql->host= mysql->unix_socket= + mysql->server_version=mysql->user=mysql->passwd=mysql->db=0; +} + +void my_set_error(MYSQL *mysql, + unsigned int error_nr, + const char *sqlstate, + const char *format, + ...) +{ + va_list ap; + + const char *errmsg; + + if (!format) + { + if (error_nr >= CR_MIN_ERROR && error_nr <= CR_MYSQL_LAST_ERROR) + errmsg= ER(error_nr); + else if (error_nr >= CER_MIN_ERROR && error_nr <= CR_MARIADB_LAST_ERROR) + errmsg= CER(error_nr); + else + errmsg= ER(CR_UNKNOWN_ERROR); + } + + mysql->net.last_errno= error_nr; + ma_strmake(mysql->net.sqlstate, sqlstate, SQLSTATE_LENGTH); + va_start(ap, format); + vsnprintf(mysql->net.last_error, MYSQL_ERRMSG_SIZE - 1, + format ? format : errmsg, ap); + va_end(ap); + return; +} + +void mysql_close_slow_part(MYSQL *mysql) +{ + if (mysql->net.pvio) + { + free_old_query(mysql); + mysql->status=MYSQL_STATUS_READY; /* Force command */ + mysql->options.reconnect=0; + if (mysql->net.pvio && mysql->net.buff) + ma_simple_command(mysql, COM_QUIT,NullS,0,1,0); + end_server(mysql); + } +} + +static void ma_clear_session_state(MYSQL *mysql) +{ + uint i; + + if (!mysql || !mysql->extension) + return; + + for (i= SESSION_TRACK_BEGIN; i <= SESSION_TRACK_END; i++) + { + list_free(mysql->extension->session_state[i].list, 0); + } + memset(mysql->extension->session_state, 0, sizeof(struct st_mariadb_session_state) * SESSION_TRACK_TYPES); +} + +void STDCALL +mysql_close(MYSQL *mysql) +{ + if (mysql) /* Some simple safety */ + { + if (mysql->extension && mysql->extension->conn_hdlr) + { + MA_CONNECTION_HANDLER *p= mysql->extension->conn_hdlr; + if (p->plugin->close) + p->plugin->close(mysql); + free(p); + /* Fix for CONC-294: Since we already called plugin->close function + we need to prevent that mysql_close_slow_part (which sends COM_QUIT + to the server) will be handled by plugin again. */ + mysql->extension->conn_hdlr= NULL; + } + + if (mysql->methods) + mysql->methods->db_close(mysql); + + /* reset the connection in all active statements */ + ma_invalidate_stmts(mysql, "mysql_close()"); + + mysql_close_memory(mysql); + mysql_close_options(mysql); + ma_clear_session_state(mysql); + + if (mysql->net.extension) + free(mysql->net.extension); + + mysql->host_info=mysql->user=mysql->passwd=mysql->db=0; + + /* Clear pointers for better safety */ + memset((char*) &mysql->options, 0, sizeof(mysql->options)); + + if (mysql->extension) + free(mysql->extension); + + /* Clear pointers for better safety */ + mysql->net.extension = NULL; + mysql->extension = NULL; + + mysql->net.pvio= 0; + if (mysql->free_me) + free(mysql); + } + return; +} + + +/************************************************************************** +** Do a query. If query returned rows, free old rows. +** Read data by mysql_store_result or by repeating calls to mysql_fetch_row +**************************************************************************/ + +int STDCALL +mysql_query(MYSQL *mysql, const char *query) +{ + return mysql_real_query(mysql,query, (unsigned long) strlen(query)); +} + +/* + Send the query and return so we can do something else. + Needs to be followed by mysql_read_query_result() when we want to + finish processing it. +*/ + +int STDCALL +mysql_send_query(MYSQL* mysql, const char* query, unsigned long length) +{ + return ma_simple_command(mysql, COM_QUERY, query, length, 1,0); +} + +int ma_read_ok_packet(MYSQL *mysql, uchar *pos, ulong length) +{ + uchar *end= mysql->net.read_pos+length; + size_t item_len; + mysql->affected_rows= net_field_length_ll(&pos); + mysql->insert_id= net_field_length_ll(&pos); + mysql->server_status=uint2korr(pos); + pos+=2; + mysql->warning_count=uint2korr(pos); + pos+=2; + if (pos > end) + goto corrupted; + if (pos < end) + { + if ((item_len= net_field_length(&pos))) + mysql->info=(char*) pos; + if (pos + item_len > end) + goto corrupted; + + /* check if server supports session tracking */ + if (mysql->server_capabilities & CLIENT_SESSION_TRACKING) + { + ma_clear_session_state(mysql); + pos+= item_len; + + if (mysql->server_status & SERVER_SESSION_STATE_CHANGED) + { + int i; + if (pos < end) + { + LIST *session_item; + MYSQL_LEX_STRING *str= NULL; + enum enum_session_state_type si_type; + uchar *old_pos= pos; + + item_len= net_field_length(&pos); /* length for all items */ + if (pos + item_len > end) + goto corrupted; + end= pos + item_len; + + /* length was already set, so make sure that info will be zero terminated */ + if (mysql->info) + *old_pos= 0; + + while (pos < end) + { + size_t plen; + char *data; + si_type= (enum enum_session_state_type)net_field_length(&pos); + + switch(si_type) { + case SESSION_TRACK_SCHEMA: + case SESSION_TRACK_STATE_CHANGE: + case SESSION_TRACK_TRANSACTION_CHARACTERISTICS: + case SESSION_TRACK_SYSTEM_VARIABLES: + case SESSION_TRACK_TRANSACTION_STATE: + case SESSION_TRACK_GTIDS: + if (si_type != SESSION_TRACK_STATE_CHANGE) + { + net_field_length(&pos); /* ignore total length, item length will follow next */ + } + if (si_type == SESSION_TRACK_GTIDS) + { + /* skip encoding */ + net_field_length(&pos); + } + plen= net_field_length(&pos); + if (pos + plen > end) + goto corrupted; + if (!(session_item= ma_multi_malloc(0, + &session_item, sizeof(LIST), + &str, sizeof(MYSQL_LEX_STRING), + &data, plen, + NULL))) + goto oom; + str->length= plen; + str->str= data; + memcpy(str->str, (char *)pos, plen); + pos+= plen; + session_item->data= str; + mysql->extension->session_state[si_type].list= list_add(mysql->extension->session_state[si_type].list, session_item); + + /* in case schema has changed, we have to update mysql->db */ + if (si_type == SESSION_TRACK_SCHEMA) + { + free(mysql->db); + mysql->db= malloc(plen + 1); + memcpy(mysql->db, str->str, plen); + mysql->db[plen]= 0; + } + else if (si_type == SESSION_TRACK_SYSTEM_VARIABLES) + { + my_bool set_charset= 0; + /* make sure that we update charset in case it has changed */ + if (!strncmp(str->str, "character_set_client", str->length)) + set_charset= 1; + plen= net_field_length(&pos); + if (pos + plen > end) + goto corrupted; + if (!(session_item= ma_multi_malloc(0, + &session_item, sizeof(LIST), + &str, sizeof(MYSQL_LEX_STRING), + &data, plen, + NULL))) + goto oom; + str->length= plen; + str->str= data; + memcpy(str->str, (char *)pos, plen); + pos+= plen; + session_item->data= str; + mysql->extension->session_state[si_type].list= list_add(mysql->extension->session_state[si_type].list, session_item); + if (set_charset && str->length < CHARSET_NAME_LEN && + strncmp(mysql->charset->csname, str->str, str->length) != 0) + { + char cs_name[CHARSET_NAME_LEN]; + const MARIADB_CHARSET_INFO *cs_info; + memcpy(cs_name, str->str, str->length); + cs_name[str->length]= 0; + if ((cs_info = mysql_find_charset_name(cs_name))) + mysql->charset= cs_info; + } + } + break; + default: + /* not supported yet */ + plen= net_field_length(&pos); + if (pos + plen > end) + goto corrupted; + pos+= plen; + break; + } + } + } + for (i= SESSION_TRACK_BEGIN; i <= SESSION_TRACK_END; i++) + { + mysql->extension->session_state[i].list= list_reverse(mysql->extension->session_state[i].list); + mysql->extension->session_state[i].current= mysql->extension->session_state[i].list; + } + } + } + } + /* CONC-351: clear session state information */ + else if (mysql->server_capabilities & CLIENT_SESSION_TRACKING) + ma_clear_session_state(mysql); + return(0); + +oom: + ma_clear_session_state(mysql); + SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); + return -1; + +corrupted: + ma_clear_session_state(mysql); + SET_CLIENT_ERROR(mysql, CR_MALFORMED_PACKET, SQLSTATE_UNKNOWN, 0); + return -1; +} + + +static int ma_deep_copy_field(const MYSQL_FIELD *src, MYSQL_FIELD *dst, + MA_MEM_ROOT *r) +{ +#define MA_STRDUP(f) \ + do \ + { \ + if (src->f) \ + { \ + if ((dst->f= ma_strdup_root(r, src->f)) == NULL) \ + return -1; \ + } \ + else \ + { \ + dst->f= NULL; \ + } \ + } \ + while (0) + + + MA_STRDUP(catalog); + MA_STRDUP(db); + MA_STRDUP(def); + MA_STRDUP(name); + MA_STRDUP(org_name); + MA_STRDUP(org_table); + MA_STRDUP(table); +#undef MA_STRDUP + + dst->catalog_length= src->catalog_length; + dst->charsetnr= src->charsetnr; + dst->db_length= src->db_length; + dst->decimals= src->decimals; + dst->def_length= src->def_length; + dst->extension= + src->extension + ? ma_field_extension_deep_dup(r, + src->extension) + : NULL; + dst->flags= src->flags; + dst->length= src->length; + dst->max_length = src->max_length; + dst->name_length= src->name_length; + dst->org_name_length= src->org_name_length; + dst->org_table_length= src->org_table_length; + dst->table_length= src->table_length; + dst->type= src->type; + return 0; +} + + +MYSQL_FIELD *ma_duplicate_resultset_metadata(MYSQL_FIELD *fields, size_t count, + MA_MEM_ROOT *memroot) +{ + size_t i; + MYSQL_FIELD *result= + (MYSQL_FIELD *) ma_alloc_root(memroot, sizeof(MYSQL_FIELD) * count); + if (!result) + return NULL; + + for (i= 0; i < count; i++) + { + if (ma_deep_copy_field(&fields[i], &result[i], memroot)) + return NULL; + } + return result; +} + + +int mthd_my_read_query_result(MYSQL *mysql) +{ + uchar *pos; + ulong field_count; + MYSQL_DATA *fields; + ulong length; + const uchar *end; + uchar has_metadata; + + my_bool can_local_infile= (mysql->options.extension) && (mysql->extension->auto_local_infile != WAIT_FOR_QUERY); + + if (mysql->options.extension && mysql->extension->auto_local_infile == ACCEPT_FILE_REQUEST) + mysql->extension->auto_local_infile= WAIT_FOR_QUERY; + + if ((length = ma_net_safe_read(mysql)) == packet_error) + { + return(1); + } + free_old_query(mysql); /* Free old result */ +get_info: + pos=(uchar*) mysql->net.read_pos; + end= pos + length; + if ((field_count= net_field_length(&pos)) == 0) + return ma_read_ok_packet(mysql, pos, length); + if (field_count == NULL_LENGTH) /* LOAD DATA LOCAL INFILE */ + { + int error=mysql_handle_local_infile(mysql, (char *)pos, can_local_infile); + + if ((length=ma_net_safe_read(mysql)) == packet_error || error) + return(-1); + goto get_info; /* Get info packet */ + } + + has_metadata= 1; + if (ma_supports_cache_metadata(mysql)) + { + assert(mysql->fields == NULL); + if (pos < end) + { + has_metadata= *pos; + pos++; + } + } + + if (!(mysql->server_status & SERVER_STATUS_AUTOCOMMIT)) + mysql->server_status|= SERVER_STATUS_IN_TRANS; + + if (has_metadata) + { + if (!(fields= mysql->methods->db_read_rows(mysql, (MYSQL_FIELD *) 0, + ma_result_set_rows(mysql)))) + return (-1); + if (!(mysql->fields= unpack_fields(mysql, fields, &mysql->field_alloc, + (uint) field_count, 1))) + return (-1); + } + else + { + /* Read EOF, to get the status and warning count. */ + if ((length= ma_net_safe_read(mysql)) == packet_error) + { + return -1; + } + pos= (uchar *) mysql->net.read_pos; + if (length != 5 || pos[0] != 0xfe) + { + return -1; + } + mysql->warning_count= uint2korr(pos + 1); + mysql->server_status= uint2korr(pos + 3); + } + mysql->status=MYSQL_STATUS_GET_RESULT; + mysql->field_count=field_count; + return(0); +} + +int STDCALL mysql_session_track_get_next(MYSQL *mysql, enum enum_session_state_type type, + const char **data, size_t *length) +{ + MYSQL_LEX_STRING *str; + if (!mysql->extension->session_state[type].current) + return 1; + + str= (MYSQL_LEX_STRING *)mysql->extension->session_state[type].current->data; + mysql->extension->session_state[type].current= mysql->extension->session_state[type].current->next; + + *data= str->str ? str->str : NULL; + *length= str->str ? str->length : 0; + return 0; +} + +int STDCALL mysql_session_track_get_first(MYSQL *mysql, enum enum_session_state_type type, + const char **data, size_t *length) +{ + mysql->extension->session_state[type].current= mysql->extension->session_state[type].list; + return mysql_session_track_get_next(mysql, type, data, length); +} + +my_bool STDCALL +mysql_read_query_result(MYSQL *mysql) +{ + return test(mysql->methods->db_read_query_result(mysql)) ? 1 : 0; +} + +int STDCALL +mysql_real_query(MYSQL *mysql, const char *query, unsigned long length) +{ + my_bool skip_result= OPT_EXT_VAL(mysql, multi_command); + + if (length == (unsigned long)-1) + length= (unsigned long)strlen(query); + + free_old_query(mysql); + + if (ma_simple_command(mysql, COM_QUERY,query,length,1,0)) + return(-1); + if (!skip_result && !mysql->options.extension->skip_read_response) + return(mysql->methods->db_read_query_result(mysql)); + return(0); +} + +/************************************************************************** +** Alloc result struct for buffered results. All rows are read to buffer. +** mysql_data_seek may be used. +**************************************************************************/ + +MYSQL_RES * STDCALL +mysql_store_result(MYSQL *mysql) +{ + MYSQL_RES *result; + + if (!mysql->fields) + return(0); + if (mysql->status != MYSQL_STATUS_GET_RESULT) + { + SET_CLIENT_ERROR(mysql, CR_COMMANDS_OUT_OF_SYNC, SQLSTATE_UNKNOWN, 0); + return(0); + } + mysql->status=MYSQL_STATUS_READY; /* server is ready */ + if (!(result=(MYSQL_RES*) calloc(1, sizeof(MYSQL_RES)+ + sizeof(ulong)*mysql->field_count))) + { + SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); + return(0); + } + result->eof=1; /* Marker for buffered */ + result->lengths=(ulong*) (result+1); + if (!(result->data=mysql->methods->db_read_rows(mysql,mysql->fields,mysql->field_count))) + { + free(result); + return(0); + } + mysql->affected_rows= result->row_count= result->data->rows; + result->data_cursor= result->data->data; + result->fields= mysql->fields; + result->field_alloc= mysql->field_alloc; + result->field_count= mysql->field_count; + result->current_field=0; + result->current_row=0; /* Must do a fetch first */ + mysql->fields=0; /* fields is now in result */ + return(result); /* Data fetched */ +} + + +/************************************************************************** +** Alloc struct for use with unbuffered reads. Data is fetched by domand +** when calling to mysql_fetch_row. +** mysql_data_seek is a noop. +** +** No other queries may be specified with the same MYSQL handle. +** There shouldn't be much processing per row because mysql server shouldn't +** have to wait for the client (and will not wait more than 30 sec/packet). +**************************************************************************/ + +MYSQL_RES * STDCALL +mysql_use_result(MYSQL *mysql) +{ + MYSQL_RES *result; + + if (!mysql->fields) + return(0); + if (mysql->status != MYSQL_STATUS_GET_RESULT) + { + SET_CLIENT_ERROR(mysql, CR_COMMANDS_OUT_OF_SYNC, SQLSTATE_UNKNOWN, 0); + return(0); + } + if (!(result=(MYSQL_RES*) calloc(1, sizeof(*result)+ + sizeof(ulong)*mysql->field_count))) + return(0); + result->lengths=(ulong*) (result+1); + if (!(result->row=(MYSQL_ROW) + malloc(sizeof(result->row[0])*(mysql->field_count+1)))) + { /* Ptrs: to one row */ + free(result); + return(0); + } + result->fields= mysql->fields; + result->field_alloc= mysql->field_alloc; + result->field_count= mysql->field_count; + result->current_field=0; + result->handle= mysql; + result->current_row= 0; + mysql->fields=0; /* fields is now in result */ + mysql->status=MYSQL_STATUS_USE_RESULT; + return(result); /* Data is read to be fetched */ +} + +/************************************************************************** +** Return next field of the query results +**************************************************************************/ +MYSQL_FIELD * STDCALL +mysql_fetch_field(MYSQL_RES *result) +{ + if (result->current_field >= result->field_count) + return(NULL); + return &result->fields[result->current_field++]; +} + + +/************************************************************************** +** Return mysql field metadata +**************************************************************************/ +int STDCALL +mariadb_field_attr(MARIADB_CONST_STRING *attr, + const MYSQL_FIELD *field, + enum mariadb_field_attr_t type) +{ + MA_FIELD_EXTENSION *ext= (MA_FIELD_EXTENSION*) field->extension; + if (!ext || type > MARIADB_FIELD_ATTR_LAST) + { + *attr= null_const_string; + return 1; + } + *attr= ext->metadata[type]; + return 0; +} + + +/************************************************************************** +** Return next row of the query results +**************************************************************************/ +MYSQL_ROW STDCALL +mysql_fetch_row(MYSQL_RES *res) +{ + if (!res) + return 0; + if (res->handle) + { + if (res->handle->status != MYSQL_STATUS_USE_RESULT && + res->handle->status != MYSQL_STATUS_GET_RESULT) + return 0; + } + if (!res->data) + { /* Unbufferred fetch */ + if (!res->eof && res->handle) + { + if (!(res->handle->methods->db_read_one_row(res->handle,res->field_count,res->row, res->lengths))) + { + res->row_count++; + return(res->current_row=res->row); + } + res->eof=1; + res->handle->status=MYSQL_STATUS_READY; + /* Don't clear handle in mysql_free_results */ + res->handle=0; + } + return((MYSQL_ROW) NULL); + } + { + MYSQL_ROW tmp; + if (!res->data_cursor) + { + return(res->current_row=(MYSQL_ROW) NULL); + } + tmp = res->data_cursor->data; + res->data_cursor = res->data_cursor->next; + return(res->current_row=tmp); + } +} + +/************************************************************************** +** Get column lengths of the current row +** If one uses mysql_use_result, res->lengths contains the length information, +** else the lengths are calculated from the offset between pointers. +**************************************************************************/ + +ulong * STDCALL +mysql_fetch_lengths(MYSQL_RES *res) +{ + ulong *lengths,*prev_length; + char *start; + MYSQL_ROW column,end; + + if (!(column=res->current_row)) + return 0; /* Something is wrong */ + if (res->data) + { + start=0; + prev_length=0; /* Keep gcc happy */ + lengths=res->lengths; + for (end=column+res->field_count+1 ; column != end ; column++,lengths++) + { + if (!*column) + { + *lengths=0; /* Null */ + continue; + } + if (start) /* Found end of prev string */ + *prev_length= (uint) (*column-start-1); + start= *column; + prev_length=lengths; + } + } + return res->lengths; +} + +/************************************************************************** +** Move to a specific row and column +**************************************************************************/ + +void STDCALL +mysql_data_seek(MYSQL_RES *result, unsigned long long row) +{ + MYSQL_ROWS *tmp=0; + if (result->data) + for (tmp=result->data->data; row-- && tmp ; tmp = tmp->next) ; + result->current_row=0; + result->data_cursor = tmp; +} + +/************************************************************************* +** put the row or field cursor one a position one got from mysql_row_tell() +** This doesn't restore any data. The next mysql_fetch_row or +** mysql_fetch_field will return the next row or field after the last used +*************************************************************************/ + +MYSQL_ROW_OFFSET STDCALL +mysql_row_seek(MYSQL_RES *result, MYSQL_ROW_OFFSET row) +{ + MYSQL_ROW_OFFSET return_value=result->data_cursor; + result->current_row= 0; + result->data_cursor= row; + return return_value; +} + + +MYSQL_FIELD_OFFSET STDCALL +mysql_field_seek(MYSQL_RES *result, MYSQL_FIELD_OFFSET field_offset) +{ + MYSQL_FIELD_OFFSET return_value=result->current_field; + result->current_field=field_offset; + return return_value; +} + +/******************************************************** + Warning: mysql_list_dbs is deprecated and will be + removed. Use SQL statement "SHOW DATABASES" + instead + ********************************************************/ + +/***************************************************************************** +** List all databases +*****************************************************************************/ + +MYSQL_RES * STDCALL +mysql_list_dbs(MYSQL *mysql, const char *wild) +{ + char buff[255]; + snprintf(buff, 255, "SHOW DATABASES LIKE '%s'", wild ? wild : "%"); + if (mysql_query(mysql,buff)) + return(0); + return (mysql_store_result(mysql)); +} + + +/******************************************************** + Warning: mysql_list_tables is deprecated and will be + removed. Use SQL statement "SHOW TABLES" + instead + ********************************************************/ +/***************************************************************************** +** List all tables in a database +** If wild is given then only the tables matching wild are returned +*****************************************************************************/ + +MYSQL_RES * STDCALL +mysql_list_tables(MYSQL *mysql, const char *wild) +{ + char buff[255]; + + snprintf(buff, 255, "SHOW TABLES LIKE '%s'", wild ? wild : "%"); + if (mysql_query(mysql,buff)) + return(0); + return (mysql_store_result(mysql)); +} + + +/************************************************************************** +** List all fields in a table +** If wild is given then only the fields matching wild are returned +** Instead of this use query: +** show fields in 'table' like "wild" +**************************************************************************/ + +MYSQL_RES * STDCALL +mysql_list_fields(MYSQL *mysql, const char *table, const char *wild) +{ + MYSQL_RES *result; + MYSQL_DATA *query; + char buff[255]; + int length= 0; + + LINT_INIT(query); + + length= snprintf(buff, 128, "%s%c%s", table, '\0', wild ? wild : ""); + + if (ma_simple_command(mysql, COM_FIELD_LIST,buff,length,1,0) || + !(query = mysql->methods->db_read_rows(mysql,(MYSQL_FIELD*) 0, + ma_result_set_rows(mysql)))) + return(NULL); + + free_old_query(mysql); + if (!(result = (MYSQL_RES *) calloc(1, sizeof(MYSQL_RES)))) + { + free_rows(query); + return(NULL); + } + result->field_alloc=mysql->field_alloc; + mysql->fields=0; + result->eof=1; + result->field_count = (uint) query->rows; + result->fields= unpack_fields(mysql, query, &result->field_alloc, + result->field_count, 1); + if (result->fields) + return(result); + + free(result); + return(NULL); +} + +/******************************************************** + Warning: mysql_list_processes is deprecated and will be + removed. Use SQL statement "SHOW PROCESSLIST" + instead + ********************************************************/ + +/* List all running processes (threads) in server */ + +MYSQL_RES * STDCALL +mysql_list_processes(MYSQL *mysql) +{ + MYSQL_DATA *fields; + uint field_count; + uchar *pos; + + LINT_INIT(fields); + if (ma_simple_command(mysql, COM_PROCESS_INFO,0,0,0,0)) + return(NULL); + free_old_query(mysql); + pos=(uchar*) mysql->net.read_pos; + field_count=(uint) net_field_length(&pos); + if (!(fields = mysql->methods->db_read_rows(mysql,(MYSQL_FIELD*) 0,7))) + return(NULL); + if (!(mysql->fields= unpack_fields(mysql, fields, &mysql->field_alloc, + field_count, 0))) + return(NULL); + mysql->status=MYSQL_STATUS_GET_RESULT; + mysql->field_count=field_count; + return(mysql_store_result(mysql)); +} + +/* In 5.0 this version became an additional parameter shutdown_level */ +int STDCALL +mysql_shutdown(MYSQL *mysql, enum mysql_enum_shutdown_level shutdown_level) +{ + uchar s_level[2]; + s_level[0]= (uchar)shutdown_level; + return(ma_simple_command(mysql, COM_SHUTDOWN, (char *)s_level, 1, 0, 0)); +} + +int STDCALL +mysql_refresh(MYSQL *mysql,uint options) +{ + uchar bits[1]; + bits[0]= (uchar) options; + return(ma_simple_command(mysql, COM_REFRESH,(char*) bits,1,0,0)); +} + +int STDCALL +mysql_kill(MYSQL *mysql,ulong pid) +{ + char buff[12]; + int4store(buff,pid); + /* if we kill our own thread, reading the response packet will fail */ + return(ma_simple_command(mysql, COM_PROCESS_KILL,buff,4,0,0)); +} + + +int STDCALL +mysql_dump_debug_info(MYSQL *mysql) +{ + return(ma_simple_command(mysql, COM_DEBUG,0,0,0,0)); +} + +char * STDCALL +mysql_stat(MYSQL *mysql) +{ + if (ma_simple_command(mysql, COM_STATISTICS,0,0,0,0)) + return mysql->net.last_error; + mysql->net.read_pos[mysql->packet_length]=0; /* End of stat string */ + if (!mysql->net.read_pos[0]) + { + SET_CLIENT_ERROR(mysql, CR_WRONG_HOST_INFO , SQLSTATE_UNKNOWN, 0); + return mysql->net.last_error; + } + return((char*) mysql->net.read_pos); +} + +int STDCALL +mysql_ping(MYSQL *mysql) +{ + int rc; + rc= ma_simple_command(mysql, COM_PING, 0, 0, 0, 0); + if (rc && mysql->options.reconnect) + rc= ma_simple_command(mysql, COM_PING, 0, 0, 0, 0); + return rc; +} + +char * STDCALL +mysql_get_server_info(MYSQL *mysql) +{ + return((char*) mysql->server_version); +} + +static size_t mariadb_server_version_id(MYSQL *mysql) +{ + size_t major, minor, patch; + char *p; + + if (!(p = mysql->server_version)) { + return 0; + } + + major = strtol(p, &p, 10); + p += 1; /* consume the dot */ + minor = strtol(p, &p, 10); + p += 1; /* consume the dot */ + patch = strtol(p, &p, 10); + + return (major * 10000L + (unsigned long)(minor * 100L + patch)); +} + +unsigned long STDCALL mysql_get_server_version(MYSQL *mysql) +{ + return (unsigned long)mariadb_server_version_id(mysql); +} + +char * STDCALL +mysql_get_host_info(MYSQL *mysql) +{ + return(mysql->host_info); +} + +uint STDCALL +mysql_get_proto_info(MYSQL *mysql) +{ + return (mysql->protocol_version); +} + +const char * STDCALL +mysql_get_client_info(void) +{ + return (char*) MARIADB_PACKAGE_VERSION; +} + +static size_t get_store_length(size_t length) +{ + #define MAX_STORE_SIZE 9 + unsigned char buffer[MAX_STORE_SIZE], *p; + + /* We just store the length and subtract offset of our buffer + to determine the length */ + p= mysql_net_store_length(buffer, length); + return p - buffer; +} + +uchar *ma_get_hash_keyval(const uchar *hash_entry, + unsigned int *length, + my_bool not_used __attribute__((unused))) +{ + /* Hash entry has the following format: + Offset: 0 key (\0 terminated) + key_length + 1 value (\0 terminated) + */ + uchar *p= (uchar *)hash_entry; + size_t len= strlen((char *)p); + *length= (unsigned int)len; + return p; +} + +void ma_int_hash_free(void *p) +{ + free(p); +} + +int +mysql_optionsv(MYSQL *mysql,enum mysql_option option, ...) +{ + va_list ap; + void *arg1; + size_t stacksize; + struct mysql_async_context *ctxt; + + va_start(ap, option); + + arg1= va_arg(ap, void *); + + switch (option) { + case MYSQL_OPT_CONNECT_TIMEOUT: + mysql->options.connect_timeout= *(uint*) arg1; + break; + case MYSQL_OPT_COMPRESS: + mysql->options.compress= 1; /* Remember for connect */ + mysql->options.client_flag|= CLIENT_COMPRESS; + break; + case MYSQL_OPT_NAMED_PIPE: + mysql->options.named_pipe=1; /* Force named pipe */ + break; + case MYSQL_OPT_LOCAL_INFILE: /* Allow LOAD DATA LOCAL ?*/ + if (!arg1 || test(*(unsigned int*) arg1)) + mysql->options.client_flag|= CLIENT_LOCAL_FILES; + else + mysql->options.client_flag&= ~CLIENT_LOCAL_FILES; + if (arg1) { + CHECK_OPT_EXTENSION_SET(&mysql->options); + mysql->extension->auto_local_infile= *(uint*)arg1 == LOCAL_INFILE_MODE_AUTO + ? WAIT_FOR_QUERY : ALWAYS_ACCEPT; + } + break; + case MYSQL_INIT_COMMAND: + options_add_initcommand(&mysql->options, (char *)arg1); + break; + case MYSQL_READ_DEFAULT_FILE: + OPT_SET_VALUE_STR(&mysql->options, my_cnf_file, (char *)arg1); + break; + case MYSQL_READ_DEFAULT_GROUP: + OPT_SET_VALUE_STR(&mysql->options, my_cnf_group, arg1 ? (char *)arg1 : ""); + break; + case MYSQL_SET_CHARSET_DIR: + OPT_SET_VALUE_STR(&mysql->options, charset_dir, arg1); + break; + case MYSQL_SET_CHARSET_NAME: + OPT_SET_VALUE_STR(&mysql->options, charset_name, arg1); + break; + case MYSQL_OPT_RECONNECT: + mysql->options.reconnect= *(my_bool *)arg1; + break; + case MYSQL_OPT_PROTOCOL: + mysql->options.protocol= *((uint *)arg1); + break; +#ifdef _WIN32 + case MYSQL_SHARED_MEMORY_BASE_NAME: + OPT_SET_VALUE_STR(&mysql->options, shared_memory_base_name, arg1); + break; +#endif + case MYSQL_OPT_READ_TIMEOUT: + mysql->options.read_timeout= *(uint *)arg1; + break; + case MYSQL_OPT_WRITE_TIMEOUT: + mysql->options.write_timeout= *(uint *)arg1; + break; + case MYSQL_REPORT_DATA_TRUNCATION: + mysql->options.report_data_truncation= *(my_bool *)arg1; + break; + case MYSQL_PROGRESS_CALLBACK: + CHECK_OPT_EXTENSION_SET(&mysql->options); + if (mysql->options.extension) + mysql->options.extension->report_progress= + (void (*)(const MYSQL *, uint, uint, double, const char *, uint)) arg1; + break; + case MYSQL_SERVER_PUBLIC_KEY: + OPT_SET_EXTENDED_VALUE_STR(&mysql->options, server_public_key, (char *)arg1); + break; + case MYSQL_PLUGIN_DIR: + OPT_SET_EXTENDED_VALUE_STR(&mysql->options, plugin_dir, (char *)arg1); + break; + case MYSQL_DEFAULT_AUTH: + OPT_SET_EXTENDED_VALUE_STR(&mysql->options, default_auth, (char *)arg1); + break; + case MYSQL_OPT_NONBLOCK: + if (mysql->options.extension && + (ctxt = mysql->options.extension->async_context) != 0) + { + /* + We must not allow changing the stack size while a non-blocking call is + suspended (as the stack is then in use). + */ + if (ctxt->suspended) + goto end; + my_context_destroy(&ctxt->async_context); + free(ctxt); + } + if (!(ctxt= (struct mysql_async_context *) + calloc(1, sizeof(*ctxt)))) + { + SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); + goto end; + } + stacksize= 0; + if (arg1) + stacksize= *(const size_t *)arg1; + if (!stacksize) + stacksize= ASYNC_CONTEXT_DEFAULT_STACK_SIZE; + if (my_context_init(&ctxt->async_context, stacksize)) + { + free(ctxt); + goto end; + } + if (!mysql->options.extension) + if(!(mysql->options.extension= (struct st_mysql_options_extension *) + calloc(1, sizeof(struct st_mysql_options_extension)))) + { + free(ctxt); + SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); + goto end; + } + mysql->options.extension->async_context= ctxt; + break; + case MYSQL_OPT_MAX_ALLOWED_PACKET: + if (mysql) + mysql->options.max_allowed_packet= (unsigned long)(*(size_t *)arg1); + else + max_allowed_packet= (unsigned long)(*(size_t *)arg1); + break; + case MYSQL_OPT_NET_BUFFER_LENGTH: + net_buffer_length= (unsigned long)(*(size_t *)arg1); + break; + case MYSQL_OPT_CAN_HANDLE_EXPIRED_PASSWORDS: + if (*(my_bool *)arg1) + mysql->options.client_flag |= CLIENT_CAN_HANDLE_EXPIRED_PASSWORDS; + else + mysql->options.client_flag &= ~CLIENT_CAN_HANDLE_EXPIRED_PASSWORDS; + break; + case MYSQL_OPT_SSL_ENFORCE: + mysql->options.use_ssl= (*(my_bool *)arg1); + break; + case MYSQL_OPT_SSL_VERIFY_SERVER_CERT: + if (*(my_bool *)arg1) + mysql->options.client_flag |= CLIENT_SSL_VERIFY_SERVER_CERT; + else + mysql->options.client_flag &= ~CLIENT_SSL_VERIFY_SERVER_CERT; + break; + case MYSQL_OPT_SSL_KEY: + OPT_SET_VALUE_STR(&mysql->options, ssl_key, (char *)arg1); + break; + case MYSQL_OPT_SSL_CERT: + OPT_SET_VALUE_STR(&mysql->options, ssl_cert, (char *)arg1); + break; + case MYSQL_OPT_SSL_CA: + OPT_SET_VALUE_STR(&mysql->options, ssl_ca, (char *)arg1); + break; + case MYSQL_OPT_SSL_CAPATH: + OPT_SET_VALUE_STR(&mysql->options, ssl_capath, (char *)arg1); + break; + case MYSQL_OPT_SSL_CIPHER: + OPT_SET_VALUE_STR(&mysql->options, ssl_cipher, (char *)arg1); + break; + case MYSQL_OPT_SSL_CRL: + OPT_SET_EXTENDED_VALUE_STR(&mysql->options, ssl_crl, (char *)arg1); + break; + case MYSQL_OPT_SSL_CRLPATH: + OPT_SET_EXTENDED_VALUE_STR(&mysql->options, ssl_crlpath, (char *)arg1); + break; + case MYSQL_OPT_CONNECT_ATTR_DELETE: + { + uchar *h; + CHECK_OPT_EXTENSION_SET(&mysql->options); + if (ma_hashtbl_inited(&mysql->options.extension->connect_attrs) && + (h= (uchar *)ma_hashtbl_search(&mysql->options.extension->connect_attrs, (uchar *)arg1, + arg1 ? (uint)strlen((char *)arg1) : 0))) + { + uchar *p= h; + size_t key_len= strlen((char *)p); + mysql->options.extension->connect_attrs_len-= key_len + get_store_length(key_len); + p+= key_len + 1; + key_len= strlen((char *)p); + mysql->options.extension->connect_attrs_len-= key_len + get_store_length(key_len); + ma_hashtbl_delete(&mysql->options.extension->connect_attrs, h); + } + + } + break; + case MYSQL_OPT_CONNECT_ATTR_RESET: + CHECK_OPT_EXTENSION_SET(&mysql->options); + if (ma_hashtbl_inited(&mysql->options.extension->connect_attrs)) + { + ma_hashtbl_free(&mysql->options.extension->connect_attrs); + mysql->options.extension->connect_attrs_len= 0; + } + break; + case MARIADB_OPT_CONNECTION_HANDLER: + OPT_SET_EXTENDED_VALUE_STR(&mysql->options, connection_handler, (char *)arg1); + break; + case MARIADB_OPT_PORT: + OPT_SET_VALUE_INT(&mysql->options, port, *((uint *)arg1)); + break; + case MARIADB_OPT_UNIXSOCKET: + OPT_SET_VALUE_STR(&mysql->options, unix_socket, arg1); + break; + case MARIADB_OPT_USER: + OPT_SET_VALUE_STR(&mysql->options, user, arg1); + break; + case MARIADB_OPT_HOST: + OPT_SET_VALUE_STR(&mysql->options, host, arg1); + break; + case MARIADB_OPT_SCHEMA: + OPT_SET_VALUE_STR(&mysql->options, db, arg1); + break; + case MARIADB_OPT_DEBUG: + break; + case MARIADB_OPT_FOUND_ROWS: + mysql->options.client_flag|= CLIENT_FOUND_ROWS; + break; + case MARIADB_OPT_INTERACTIVE: + mysql->options.client_flag|= CLIENT_INTERACTIVE; + break; + case MARIADB_OPT_MULTI_RESULTS: + mysql->options.client_flag|= CLIENT_MULTI_RESULTS; + break; + case MARIADB_OPT_MULTI_STATEMENTS: + mysql->options.client_flag|= CLIENT_MULTI_STATEMENTS | CLIENT_MULTI_RESULTS; + break; + case MARIADB_OPT_PASSWORD: + OPT_SET_VALUE_STR(&mysql->options, password, arg1); + break; + case MARIADB_OPT_USERDATA: + { + void *data= va_arg(ap, void *); + uchar *buffer, *p; + char *key= (char *)arg1; + + if (!key || !data) + { + SET_CLIENT_ERROR(mysql, CR_INVALID_PARAMETER_NO, SQLSTATE_UNKNOWN, 0); + goto end; + } + + CHECK_OPT_EXTENSION_SET(&mysql->options); + if (!ma_hashtbl_inited(&mysql->options.extension->userdata)) + { + if (_ma_hashtbl_init(&mysql->options.extension->userdata, + 0, 0, 0, ma_get_hash_keyval, ma_int_hash_free, 0)) + { + SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); + goto end; + } + } + /* check if key is already in buffer */ + p= (uchar *)ma_hashtbl_search(&mysql->options.extension->userdata, + (uchar *)key, + (uint)strlen(key)); + if (p) + { + p+= strlen(key) + 1; + memcpy(p, &data, sizeof(void *)); + break; + } + + if (!(buffer= (uchar *)malloc(strlen(key) + 1 + sizeof(void *)))) + { + SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); + goto end; + } + + p= buffer; + strcpy((char *)p, key); + p+= strlen(key) + 1; + memcpy(p, &data, sizeof(void *)); + + if (ma_hashtbl_insert(&mysql->options.extension->userdata, buffer)) + { + free(buffer); + SET_CLIENT_ERROR(mysql, CR_INVALID_PARAMETER_NO, SQLSTATE_UNKNOWN, 0); + goto end; + } + } + break; + case MYSQL_OPT_CONNECT_ATTR_ADD: + { + uchar *buffer; + void *arg2= va_arg(ap, void *); + size_t storage_len, key_len= arg1 ? strlen((char *)arg1) : 0, + value_len= arg2 ? strlen((char *)arg2) : 0; + if (!key_len || !value_len) + { + SET_CLIENT_ERROR(mysql, CR_INVALID_PARAMETER_NO, SQLSTATE_UNKNOWN, 0); + goto end; + } + storage_len= key_len + value_len + + get_store_length(key_len) + + get_store_length(value_len); + + /* since we store terminating zero character in hash, we need + * to increase lengths */ + key_len++; + value_len++; + + CHECK_OPT_EXTENSION_SET(&mysql->options); + if (!key_len || + storage_len + mysql->options.extension->connect_attrs_len > 0xFFFF) + { + SET_CLIENT_ERROR(mysql, CR_INVALID_PARAMETER_NO, SQLSTATE_UNKNOWN, 0); + goto end; + } + + if (!ma_hashtbl_inited(&mysql->options.extension->connect_attrs)) + { + if (_ma_hashtbl_init(&mysql->options.extension->connect_attrs, + 0, 0, 0, ma_get_hash_keyval, ma_int_hash_free, 0)) + { + SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); + goto end; + } + } + if ((buffer= (uchar *)malloc(key_len + value_len))) + { + uchar *p= buffer; + strcpy((char *)p, arg1); + p+= (strlen(arg1) + 1); + if (arg2) + strcpy((char *)p, arg2); + + if (ma_hashtbl_insert(&mysql->options.extension->connect_attrs, buffer)) + { + free(buffer); + SET_CLIENT_ERROR(mysql, CR_INVALID_PARAMETER_NO, SQLSTATE_UNKNOWN, 0); + goto end; + } + mysql->options.extension->connect_attrs_len+= storage_len; + } + else + { + SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); + goto end; + } + } + break; + case MYSQL_ENABLE_CLEARTEXT_PLUGIN: + break; + case MYSQL_SECURE_AUTH: + mysql->options.secure_auth= *(my_bool *)arg1; + break; + case MYSQL_OPT_BIND: + OPT_SET_VALUE_STR(&mysql->options, bind_address, arg1); + break; + case MARIADB_OPT_TLS_CIPHER_STRENGTH: + OPT_SET_EXTENDED_VALUE_INT(&mysql->options, tls_cipher_strength, *((unsigned int *)arg1)); + break; + case MARIADB_OPT_SSL_FP: + case MARIADB_OPT_TLS_PEER_FP: + OPT_SET_EXTENDED_VALUE_STR(&mysql->options, tls_fp, (char *)arg1); + mysql->options.use_ssl= 1; + break; + case MARIADB_OPT_SSL_FP_LIST: + case MARIADB_OPT_TLS_PEER_FP_LIST: + OPT_SET_EXTENDED_VALUE_STR(&mysql->options, tls_fp_list, (char *)arg1); + mysql->options.use_ssl= 1; + break; + case MARIADB_OPT_TLS_PASSPHRASE: + OPT_SET_EXTENDED_VALUE_STR(&mysql->options, tls_pw, (char *)arg1); + break; + case MARIADB_OPT_CONNECTION_READ_ONLY: + OPT_SET_EXTENDED_VALUE_INT(&mysql->options, read_only, *(my_bool *)arg1); + break; + case MARIADB_OPT_PROXY_HEADER: + { + size_t arg2 = va_arg(ap, size_t); + OPT_SET_EXTENDED_VALUE(&mysql->options, proxy_header, (char *)arg1); + OPT_SET_EXTENDED_VALUE(&mysql->options, proxy_header_len, arg2); + } + break; + case MARIADB_OPT_TLS_VERSION: + case MYSQL_OPT_TLS_VERSION: + OPT_SET_EXTENDED_VALUE_STR(&mysql->options, tls_version, (char *)arg1); + break; + case MARIADB_OPT_IO_WAIT: + CHECK_OPT_EXTENSION_SET(&mysql->options); + mysql->options.extension->io_wait = (int(*)(my_socket, my_bool, int))arg1; + break; + case MARIADB_OPT_SKIP_READ_RESPONSE: + OPT_SET_EXTENDED_VALUE_INT(&mysql->options, skip_read_response, *(my_bool *)arg1); + break; + default: + va_end(ap); + SET_CLIENT_ERROR(mysql, CR_NOT_IMPLEMENTED, SQLSTATE_UNKNOWN, 0); + return(1); + } + va_end(ap); + return(0); +end: + va_end(ap); + return(1); +} + +int +mysql_get_optionv(MYSQL *mysql, enum mysql_option option, void *arg, ...) +{ + va_list ap; + + va_start(ap, arg); + + switch(option) { + case MYSQL_OPT_CONNECT_TIMEOUT: + *((uint *)arg)= mysql->options.connect_timeout; + break; + case MYSQL_OPT_COMPRESS: + *((my_bool *)arg)= mysql->options.compress; + break; + case MYSQL_OPT_NAMED_PIPE: + *((my_bool *)arg)= mysql->options.named_pipe; + break; + case MYSQL_OPT_LOCAL_INFILE: /* Allow LOAD DATA LOCAL ?*/ + *((uint *)arg)= test(mysql->options.client_flag & CLIENT_LOCAL_FILES); + break; + case MYSQL_INIT_COMMAND: + /* mysql_get_optionsv(mysql, MYSQL_INIT_COMMAND, commands, elements) */ + { + unsigned int *elements; + if (arg) + *((char **)arg)= mysql->options.init_command ? mysql->options.init_command->buffer : NULL; + if ((elements= va_arg(ap, unsigned int *))) + *elements= mysql->options.init_command ? mysql->options.init_command->elements : 0; + } + break; + case MYSQL_READ_DEFAULT_FILE: + *((char **)arg)= mysql->options.my_cnf_file; + break; + case MYSQL_READ_DEFAULT_GROUP: + *((char **)arg)= mysql->options.my_cnf_group; + break; + case MYSQL_SET_CHARSET_DIR: + /* not supported in this version. Since all character sets + are internally available, we don't throw an error */ + *((char **)arg)= NULL; + break; + case MYSQL_SET_CHARSET_NAME: + if (mysql->charset) + *((const char **)arg)= mysql->charset->csname; + else + *((char **)arg)= mysql->options.charset_name; + break; + case MYSQL_OPT_RECONNECT: + *((my_bool *)arg)= mysql->options.reconnect; + break; + case MYSQL_OPT_PROTOCOL: + *((uint *)arg)= mysql->options.protocol; + break; + case MYSQL_OPT_READ_TIMEOUT: + *((uint *)arg)= mysql->options.read_timeout; + break; + case MYSQL_OPT_WRITE_TIMEOUT: + *((uint *)arg)= mysql->options.write_timeout; + break; + case MYSQL_REPORT_DATA_TRUNCATION: + *((my_bool *)arg)= mysql->options.report_data_truncation; + break; + case MYSQL_PROGRESS_CALLBACK: + *((void (**)(const MYSQL *, uint, uint, double, const char *, uint))arg)= + mysql->options.extension ? mysql->options.extension->report_progress : NULL; + break; + case MYSQL_SERVER_PUBLIC_KEY: + *((char **)arg)= mysql->options.extension ? + mysql->options.extension->server_public_key : NULL; + break; + case MYSQL_PLUGIN_DIR: + *((char **)arg)= mysql->options.extension ? mysql->options.extension->plugin_dir : NULL; + break; + case MYSQL_DEFAULT_AUTH: + *((char **)arg)= mysql->options.extension ? mysql->options.extension->default_auth : NULL; + break; + case MYSQL_OPT_NONBLOCK: + *((my_bool *)arg)= test(mysql->options.extension && mysql->options.extension->async_context); + break; + case MYSQL_OPT_CAN_HANDLE_EXPIRED_PASSWORDS: + *((my_bool *)arg)= test(mysql->options.client_flag & CLIENT_CAN_HANDLE_EXPIRED_PASSWORDS); + break; + case MYSQL_OPT_SSL_ENFORCE: + *((my_bool *)arg)= mysql->options.use_ssl; + break; + case MYSQL_OPT_SSL_VERIFY_SERVER_CERT: + *((my_bool *)arg)= test(mysql->options.client_flag & CLIENT_SSL_VERIFY_SERVER_CERT); + break; + case MYSQL_OPT_SSL_KEY: + *((char **)arg)= mysql->options.ssl_key; + break; + case MYSQL_OPT_SSL_CERT: + *((char **)arg)= mysql->options.ssl_cert; + break; + case MYSQL_OPT_SSL_CA: + *((char **)arg)= mysql->options.ssl_ca; + break; + case MYSQL_OPT_SSL_CAPATH: + *((char **)arg)= mysql->options.ssl_capath; + break; + case MYSQL_OPT_SSL_CIPHER: + *((char **)arg)= mysql->options.ssl_cipher; + break; + case MYSQL_OPT_SSL_CRL: + *((char **)arg)= mysql->options.extension ? mysql->options.ssl_cipher : NULL; + break; + case MYSQL_OPT_SSL_CRLPATH: + *((char **)arg)= mysql->options.extension ? mysql->options.extension->ssl_crlpath : NULL; + break; + case MYSQL_OPT_CONNECT_ATTRS: + /* mysql_get_optionsv(mysql, MYSQL_OPT_CONNECT_ATTRS, keys, vals, elements) */ + { + unsigned int i, *elements; + char **key= NULL; + void *arg1; + char **val= NULL; + + if (arg) + key= *(char ***)arg; + + arg1= va_arg(ap, char **); + if (arg1) + val= *(char ***)arg1; + + if (!(elements= va_arg(ap, unsigned int *))) + goto error; + + *elements= 0; + + if (!mysql->options.extension || + !ma_hashtbl_inited(&mysql->options.extension->connect_attrs)) + break; + + *elements= mysql->options.extension->connect_attrs.records; + + if (val || key) + { + for (i=0; i < *elements; i++) + { + uchar *p= ma_hashtbl_element(&mysql->options.extension->connect_attrs, i); + if (key) + key[i]= (char *)p; + p+= strlen((char *)p) + 1; + if (val) + val[i]= (char *)p; + } + } + } + break; + case MYSQL_OPT_MAX_ALLOWED_PACKET: + *((unsigned long *)arg)= (mysql) ? mysql->options.max_allowed_packet : + max_allowed_packet; + break; + case MYSQL_OPT_NET_BUFFER_LENGTH: + *((unsigned long *)arg)= net_buffer_length; + break; + case MYSQL_SECURE_AUTH: + *((my_bool *)arg)= mysql->options.secure_auth; + break; + case MYSQL_OPT_BIND: + *((char **)arg)= mysql->options.bind_address; + break; + case MARIADB_OPT_TLS_CIPHER_STRENGTH: + *((unsigned int *)arg) = mysql->options.extension ? mysql->options.extension->tls_cipher_strength : 0; + break; + case MARIADB_OPT_SSL_FP: + case MARIADB_OPT_TLS_PEER_FP: + *((char **)arg)= mysql->options.extension ? mysql->options.extension->tls_fp : NULL; + break; + case MARIADB_OPT_SSL_FP_LIST: + case MARIADB_OPT_TLS_PEER_FP_LIST: + *((char **)arg)= mysql->options.extension ? mysql->options.extension->tls_fp_list : NULL; + break; + case MARIADB_OPT_TLS_PASSPHRASE: + *((char **)arg)= mysql->options.extension ? mysql->options.extension->tls_pw : NULL; + break; + case MARIADB_OPT_CONNECTION_READ_ONLY: + *((my_bool *)arg)= mysql->options.extension ? mysql->options.extension->read_only : 0; + break; + case MARIADB_OPT_USERDATA: + /* nysql_get_optionv(mysql, MARIADB_OPT_USERDATA, key, value) */ + { + uchar *p; + void *data= va_arg(ap, void *); + char *key= (char *)arg; + if (key && data && mysql->options.extension && ma_hashtbl_inited(&mysql->options.extension->userdata) && + (p= (uchar *)ma_hashtbl_search(&mysql->options.extension->userdata, (uchar *)key, + (uint)strlen((char *)key)))) + { + p+= strlen(key) + 1; + *((void **)data)= *((void **)p); + break; + } + if (data) + *((void **)data)= NULL; + } + break; + case MARIADB_OPT_CONNECTION_HANDLER: + *((char **)arg)= mysql->options.extension ? mysql->options.extension->connection_handler : NULL; + break; + case MARIADB_OPT_IO_WAIT: + *((int(**)(my_socket, my_bool, int))arg) = mysql->options.extension ? mysql->options.extension->io_wait : NULL; + break; + case MARIADB_OPT_SKIP_READ_RESPONSE: + *((my_bool*)arg)= mysql->options.extension ? mysql->options.extension->skip_read_response : 0; + break; + default: + va_end(ap); + SET_CLIENT_ERROR(mysql, CR_NOT_IMPLEMENTED, SQLSTATE_UNKNOWN, 0); + return(1); + } + va_end(ap); + return(0); +error: + va_end(ap); + return(1); +} + +int STDCALL mysql_get_option(MYSQL *mysql, enum mysql_option option, void *arg) +{ + return mysql_get_optionv(mysql, option, arg); +} + +int STDCALL +mysql_options(MYSQL *mysql,enum mysql_option option, const void *arg) +{ + return mysql_optionsv(mysql, option, arg); +} + +int STDCALL +mysql_options4(MYSQL *mysql,enum mysql_option option, const void *arg1, const void *arg2) +{ + return mysql_optionsv(mysql, option, arg1, arg2); +} +/**************************************************************************** +** Functions to get information from the MySQL structure +** These are functions to make shared libraries more usable. +****************************************************************************/ + +/* MYSQL_RES */ +my_ulonglong STDCALL mysql_num_rows(MYSQL_RES *res) +{ + return res->row_count; +} + +unsigned int STDCALL mysql_num_fields(MYSQL_RES *res) +{ + return res->field_count; +} + +/* deprecated */ +my_bool STDCALL mysql_eof(MYSQL_RES *res) +{ + return res->eof; +} + +MYSQL_FIELD * STDCALL mysql_fetch_field_direct(MYSQL_RES *res,uint fieldnr) +{ + return &(res)->fields[fieldnr]; +} + +MYSQL_FIELD * STDCALL mysql_fetch_fields(MYSQL_RES *res) +{ + return (res)->fields; +} + +MYSQL_ROWS * STDCALL mysql_row_tell(MYSQL_RES *res) +{ + return res->data_cursor; +} + +uint STDCALL mysql_field_tell(MYSQL_RES *res) +{ + return (res)->current_field; +} + +/* MYSQL */ + +unsigned int STDCALL mysql_field_count(MYSQL *mysql) +{ + return mysql->field_count; +} + +my_ulonglong STDCALL mysql_affected_rows(MYSQL *mysql) +{ + return (mysql)->affected_rows; +} + +my_bool STDCALL mysql_autocommit(MYSQL *mysql, my_bool mode) +{ + return((my_bool) mysql_real_query(mysql, (mode) ? "SET autocommit=1" : + "SET autocommit=0", 16)); +} + +my_bool STDCALL mysql_commit(MYSQL *mysql) +{ + return((my_bool)mysql_real_query(mysql, "COMMIT", (unsigned long)strlen("COMMIT"))); +} + +my_bool STDCALL mysql_rollback(MYSQL *mysql) +{ + return((my_bool)mysql_real_query(mysql, "ROLLBACK", (unsigned long)strlen("ROLLBACK"))); +} + +my_ulonglong STDCALL mysql_insert_id(MYSQL *mysql) +{ + return (mysql)->insert_id; +} + +uint STDCALL mysql_errno(MYSQL *mysql) +{ + return mysql ? mysql->net.last_errno : 0; +} + +const char * STDCALL mysql_error(MYSQL *mysql) +{ + return mysql ? (mysql)->net.last_error : (char *)""; +} + +const char *STDCALL mysql_info(MYSQL *mysql) +{ + return (mysql)->info; +} + +my_bool STDCALL mysql_more_results(MYSQL *mysql) +{ + return(test(mysql->server_status & SERVER_MORE_RESULTS_EXIST)); +} + +int STDCALL mysql_next_result(MYSQL *mysql) +{ + + /* make sure communication is not blocking */ + if (mysql->status != MYSQL_STATUS_READY) + { + SET_CLIENT_ERROR(mysql, CR_COMMANDS_OUT_OF_SYNC, SQLSTATE_UNKNOWN, 0); + return(1); + } + + /* clear error, and mysql status variables */ + CLEAR_CLIENT_ERROR(mysql); + mysql->affected_rows = (ulonglong) ~0; + + if (mysql->server_status & SERVER_MORE_RESULTS_EXIST) + { + return(mysql->methods->db_read_query_result(mysql)); + } + + return(-1); +} + +ulong STDCALL mysql_thread_id(MYSQL *mysql) +{ + return (mysql)->thread_id; +} + +const char * STDCALL mysql_character_set_name(MYSQL *mysql) +{ + return mysql->charset->csname; +} + + +uint STDCALL mysql_thread_safe(void) +{ +#ifdef THREAD + return 1; +#else + return 0; +#endif +} + +/**************************************************************************** +** Some support functions +****************************************************************************/ + +/* +** Add escape characters to a string (blob?) to make it suitable for a insert +** to should at least have place for length*2+1 chars +** Returns the length of the to string +*/ + +ulong STDCALL +mysql_escape_string(char *to,const char *from, ulong length) +{ + return (ulong)mysql_cset_escape_slashes(ma_default_charset_info, to, from, length); +} + +ulong STDCALL +mysql_real_escape_string(MYSQL *mysql, char *to,const char *from, + ulong length) +{ + if (mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES) + return (ulong)mysql_cset_escape_quotes(mysql->charset, to, from, length); + else + return (ulong)mysql_cset_escape_slashes(mysql->charset, to, from, length); +} + +static void mariadb_get_charset_info(MYSQL *mysql, MY_CHARSET_INFO *cs) +{ + if (!cs) + return; + + cs->number= mysql->charset->nr; + cs->csname= mysql->charset->csname; + cs->name= mysql->charset->name; + cs->state= 0; + cs->comment= NULL; + cs->dir= NULL; + cs->mbminlen= mysql->charset->char_minlen; + cs->mbmaxlen= mysql->charset->char_maxlen; + + return; +} + +void STDCALL mysql_get_character_set_info(MYSQL *mysql, MY_CHARSET_INFO *cs) +{ + mariadb_get_charset_info(mysql, cs); +} + +int STDCALL mysql_set_character_set(MYSQL *mysql, const char *csname) +{ + const MARIADB_CHARSET_INFO *cs; + + if (!csname) + goto error; + + if ((cs= mysql_find_charset_name(csname))) + { + char buff[64]; + + snprintf(buff, 63, "SET NAMES %s", cs->csname); + if (!mysql_real_query(mysql, buff, (unsigned long)strlen(buff))) + { + mysql->charset= cs; + return(0); + } + return(mysql->net.last_errno); + } + +error: + my_set_error(mysql, CR_CANT_READ_CHARSET, SQLSTATE_UNKNOWN, + 0, csname, "compiled_in"); + return(mysql->net.last_errno); +} + +unsigned int STDCALL mysql_warning_count(MYSQL *mysql) +{ + return mysql->warning_count; +} + +const char * STDCALL mysql_sqlstate(MYSQL *mysql) +{ + return mysql->net.sqlstate; +} + +#ifndef _WIN32 +#include +static void ignore_sigpipe() +{ + signal(SIGPIPE, SIG_IGN); +} +#else +#define ignore_sigpipe() +#endif + +#ifdef _WIN32 +static int mysql_once_init() +#else +static void mysql_once_init() +#endif +{ + ma_init(); /* Will init threads */ + init_client_errs(); + get_default_configuration_dirs(); + set_default_charset_by_name(MARIADB_DEFAULT_CHARSET, 0); + if (mysql_client_plugin_init()) + { +#ifdef _WIN32 + return 1; +#else + return; +#endif + } + if (!mysql_port) + { +#if !__has_feature(memory_sanitizer) /* work around MSAN deficiency */ + struct servent *serv_ptr; +#endif + char *env; + + mysql_port = MARIADB_PORT; +#if !__has_feature(memory_sanitizer) /* work around MSAN deficiency */ + if ((serv_ptr = getservbyname("mysql", "tcp"))) + mysql_port = (uint)ntohs((ushort)serv_ptr->s_port); +#endif + if ((env = getenv("MYSQL_TCP_PORT"))) + mysql_port =(uint)atoi(env); + } + if (!mysql_unix_port) + { + char *env; +#ifdef _WIN32 + mysql_unix_port = (char*)MARIADB_NAMEDPIPE; +#else + mysql_unix_port = (char*)MARIADB_UNIX_ADDR; +#endif + if ((env = getenv("MYSQL_UNIX_PORT")) || + (env = getenv("MARIADB_UNIX_PORT"))) + mysql_unix_port = env; + } + if (!mysql_ps_subsystem_initialized) + mysql_init_ps_subsystem(); +#ifdef HAVE_TLS + ma_tls_start(0, 0); +#endif + ignore_sigpipe(); + mysql_client_init = 1; +#ifdef _WIN32 + return 0; +#endif +} + +#ifdef _WIN32 +static INIT_ONCE init_once= INIT_ONCE_STATIC_INIT; +BOOL CALLBACK win_init_once( + PINIT_ONCE InitOnce, + PVOID Parameter, + PVOID *lpContext) +{ + return !mysql_once_init(); + return TRUE; +} +#else +static pthread_once_t init_once = PTHREAD_ONCE_INIT; +#endif + +int STDCALL mysql_server_init(int argc __attribute__((unused)), + char **argv __attribute__((unused)), + char **groups __attribute__((unused))) +{ +#ifdef _WIN32 + BOOL ret = InitOnceExecuteOnce(&init_once, win_init_once, NULL, NULL); + return ret? 0: 1; +#else + return pthread_once(&init_once, mysql_once_init); +#endif +} + +void STDCALL mysql_server_end(void) +{ + if (!mysql_client_init) + return; + + release_configuration_dirs(); + mysql_client_plugin_deinit(); + + list_free(pvio_callback, 0); + if (ma_init_done) + ma_end(0); +#ifdef HAVE_TLS + ma_pvio_tls_end(); +#endif + mysql_client_init= 0; + ma_init_done= 0; +#ifdef WIN32 + init_once = (INIT_ONCE)INIT_ONCE_STATIC_INIT; +#else + init_once = (pthread_once_t)PTHREAD_ONCE_INIT; +#endif +} + +my_bool STDCALL mysql_thread_init(void) +{ + return 0; +} + +void STDCALL mysql_thread_end(void) +{ +} + +int STDCALL mysql_set_server_option(MYSQL *mysql, + enum enum_mysql_set_option option) +{ + char buffer[2]; + int2store(buffer, (uint)option); + return(ma_simple_command(mysql, COM_SET_OPTION, buffer, sizeof(buffer), 0, 0)); +} + +ulong STDCALL mysql_get_client_version(void) +{ + return MARIADB_PACKAGE_VERSION_ID; +} + +ulong STDCALL mysql_hex_string(char *to, const char *from, unsigned long len) +{ + char *start= to; + char hexdigits[]= "0123456789ABCDEF"; + + while (len--) + { + *to++= hexdigits[((unsigned char)*from) >> 4]; + *to++= hexdigits[((unsigned char)*from) & 0x0F]; + from++; + } + *to= 0; + return (ulong)(to - start); +} + +my_bool STDCALL mariadb_connection(MYSQL *mysql) +{ + return (strstr(mysql->server_version, "MariaDB") || + strstr(mysql->server_version, "-maria-")); +} + +const char * STDCALL +mysql_get_server_name(MYSQL *mysql) +{ + if (mysql->options.extension && + mysql->options.extension->db_driver != NULL) + return mysql->options.extension->db_driver->name; + return mariadb_connection(mysql) ? "MariaDB" : "MySQL"; +} + +static my_socket mariadb_get_socket(MYSQL *mysql) +{ + my_socket sock= INVALID_SOCKET; + if (mysql->net.pvio) + { + ma_pvio_get_handle(mysql->net.pvio, &sock); + + } + /* if an asynchronous connect is in progress, we need to obtain + pvio handle from async_context until the connection was + successfully established. + */ + else if (mysql->options.extension && mysql->options.extension->async_context && + mysql->options.extension->async_context->pvio) + { + ma_pvio_get_handle(mysql->options.extension->async_context->pvio, &sock); + } + return sock; +} + +my_socket STDCALL +mysql_get_socket(MYSQL *mysql) +{ + return mariadb_get_socket(mysql); +} + +MARIADB_CHARSET_INFO * STDCALL mariadb_get_charset_by_name(const char *csname) +{ + return (MARIADB_CHARSET_INFO *)mysql_find_charset_name(csname); +} + +MARIADB_CHARSET_INFO * STDCALL mariadb_get_charset_by_nr(unsigned int csnr) +{ + return (MARIADB_CHARSET_INFO *)mysql_find_charset_nr(csnr); +} + +my_bool mariadb_get_infov(MYSQL *mysql, enum mariadb_value value, void *arg, ...) +{ + va_list ap; + + va_start(ap, arg); + + switch(value) { + case MARIADB_MAX_ALLOWED_PACKET: + *((size_t *)arg)= (size_t)max_allowed_packet; + break; + case MARIADB_NET_BUFFER_LENGTH: + *((size_t *)arg)= (size_t)net_buffer_length; + break; + case MARIADB_CONNECTION_ERROR_ID: + if (!mysql) + goto error; + *((unsigned int *)arg)= mysql->net.last_errno; + break; + case MARIADB_CONNECTION_ERROR: + if (!mysql) + goto error; + *((char **)arg)= mysql->net.last_error; + break; + case MARIADB_CONNECTION_SQLSTATE: + if (!mysql) + goto error; + *((char **)arg)= mysql->net.sqlstate; + break; + case MARIADB_CONNECTION_TLS_VERSION: + #ifdef HAVE_TLS + if (mysql && mysql->net.pvio && mysql->net.pvio->ctls) + *((char **)arg)= (char *)ma_pvio_tls_get_protocol_version(mysql->net.pvio->ctls); + else + #endif + goto error; + break; + case MARIADB_CONNECTION_TLS_VERSION_ID: + #ifdef HAVE_TLS + if (mysql && mysql->net.pvio && mysql->net.pvio->ctls) + *((unsigned int *)arg)= ma_pvio_tls_get_protocol_version_id(mysql->net.pvio->ctls); + else + #endif + goto error; + break; + case MARIADB_TLS_LIBRARY: +#ifdef HAVE_TLS + *((const char **)arg)= tls_library_version; +#else + *((const char **)arg)= "Off"; +#endif + break; + case MARIADB_CLIENT_VERSION: + *((const char **)arg)= MARIADB_CLIENT_VERSION_STR; + break; + case MARIADB_CLIENT_VERSION_ID: + *((size_t *)arg)= MARIADB_VERSION_ID; + break; + case MARIADB_CONNECTION_SERVER_VERSION: + if (mysql) + *((char **)arg)= mysql->server_version; + else + goto error; + break; + case MARIADB_CONNECTION_SERVER_TYPE: + if (mysql) + *((const char **)arg)= mariadb_connection(mysql) ? "MariaDB" : "MySQL"; + else + goto error; + break; + case MARIADB_CONNECTION_SERVER_VERSION_ID: + if (mysql) + *((size_t *)arg)= mariadb_server_version_id(mysql); + else + goto error; + break; + case MARIADB_CONNECTION_PROTOCOL_VERSION_ID: + if (mysql) + *((unsigned int *)arg)= mysql->protocol_version; + else + goto error; + break; + case MARIADB_CONNECTION_MARIADB_CHARSET_INFO: + if (mysql) + mariadb_get_charset_info(mysql, (MY_CHARSET_INFO *)arg); + else + goto error; + break; + case MARIADB_CONNECTION_SOCKET: + if (mysql) + *((my_socket *)arg)= mariadb_get_socket(mysql); + else + goto error; + break; + case MARIADB_CONNECTION_TYPE: + if (mysql && mysql->net.pvio) + *((int *)arg)= (int)mysql->net.pvio->type; + else + goto error; + break; + case MARIADB_CONNECTION_ASYNC_TIMEOUT_MS: + if (mysql && mysql->options.extension && mysql->options.extension->async_context) + *((unsigned int *)arg)= mysql->options.extension->async_context->timeout_value; + break; + case MARIADB_CONNECTION_ASYNC_TIMEOUT: + if (mysql && mysql->options.extension && mysql->options.extension->async_context) + { + unsigned int timeout= mysql->options.extension->async_context->timeout_value; + if (timeout > UINT_MAX - 999) + *((unsigned int *)arg)= (timeout - 1)/1000 + 1; + else + *((unsigned int *)arg)= (timeout+999)/1000; + } + break; + case MARIADB_CHARSET_NAME: + { + char *name; + name= va_arg(ap, char *); + if (name) + *((MARIADB_CHARSET_INFO **)arg)= (MARIADB_CHARSET_INFO *)mysql_find_charset_name(name); + else + goto error; + } + break; + case MARIADB_CHARSET_ID: + { + unsigned int nr; + nr= va_arg(ap, unsigned int); + *((MARIADB_CHARSET_INFO **)arg)= (MARIADB_CHARSET_INFO *)mysql_find_charset_nr(nr); + } + break; + case MARIADB_CONNECTION_SSL_CIPHER: + #ifdef HAVE_TLS + if (mysql && mysql->net.pvio && mysql->net.pvio->ctls) + *((char **)arg)= (char *)ma_pvio_tls_cipher(mysql->net.pvio->ctls); + else + #endif + goto error; + break; + case MARIADB_CLIENT_ERRORS: + *((char ***)arg)= (char **)client_errors; + break; + case MARIADB_CONNECTION_INFO: + if (mysql) + *((char **)arg)= (char *)mysql->info; + else + goto error; + break; + case MARIADB_CONNECTION_PVIO_TYPE: + if (mysql && mysql->net.pvio) + *((unsigned int *)arg)= (unsigned int)mysql->net.pvio->type; + else + goto error; + break; + case MARIADB_CONNECTION_SCHEMA: + if (mysql) + *((char **)arg)= mysql->db; + else + goto error; + break; + case MARIADB_CONNECTION_USER: + if (mysql) + *((char **)arg)= mysql->user; + else + goto error; + break; + case MARIADB_CONNECTION_PORT: + if (mysql) + *((unsigned int *)arg)= mysql->port; + else + goto error; + break; + case MARIADB_CONNECTION_UNIX_SOCKET: + if (mysql) + *((char **)arg)= mysql->unix_socket; + else + goto error; + break; + case MARIADB_CONNECTION_HOST: + if (mysql) + *((char **)arg)= mysql->host; + else + goto error; + break; + case MARIADB_CONNECTION_SERVER_STATUS: + if (mysql) + *((unsigned int *)arg)= mysql->server_status; + else + goto error; + break; + case MARIADB_CONNECTION_SERVER_CAPABILITIES: + if (mysql) + *((unsigned long *)arg)= mysql->server_capabilities; + else + goto error; + break; + case MARIADB_CONNECTION_EXTENDED_SERVER_CAPABILITIES: + if (mysql) + *((unsigned long *)arg)= mysql->extension->mariadb_server_capabilities; + else + goto error; + break; + case MARIADB_CONNECTION_CLIENT_CAPABILITIES: + if (mysql) + *((unsigned long *)arg)= mysql->client_flag; + else + goto error; + break; + default: + va_end(ap); + return(-1); + } + va_end(ap); + return(0); +error: + va_end(ap); + return(-1); +} + +my_bool STDCALL mariadb_get_info(MYSQL *mysql, enum mariadb_value value, void *arg) +{ + return mariadb_get_infov(mysql, value, arg); +} + +/* + Immediately aborts connection, making all subsequent read/write operations fail. + Does not invalidate memory used for mysql structure, nor closes any communication + channels - mysql_close is still needed. + Useful to break long query, in situation sending KILL is not possible. +*/ +int STDCALL mariadb_cancel(MYSQL *mysql) +{ + if (!mysql || !mysql->net.pvio || !mysql->net.pvio->methods || !mysql->net.pvio->methods->shutdown) + { + return 1; + } + else + { + MARIADB_PVIO *pvio = mysql->net.pvio; + return pvio->methods->shutdown(pvio); + } +} + +/* compatibility functions for MariaDB */ +void STDCALL +mysql_debug(const char *debug __attribute__((unused))) +{ + return; +} + +/******************************************************************** + mysql_net_ functions - low-level API to MySQL protocol +*********************************************************************/ +ulong STDCALL mysql_net_read_packet(MYSQL *mysql) +{ + return ma_net_safe_read(mysql); +} + +ulong STDCALL mysql_net_field_length(uchar **packet) +{ + return net_field_length(packet); +} + +my_bool STDCALL mysql_embedded(void) +{ +#ifdef EMBEDDED_LIBRARY + return 1; +#else + return 0; +#endif +} + +MYSQL_PARAMETERS *STDCALL +mysql_get_parameters(void) +{ + return &mariadb_internal_parameters; +} + +int STDCALL mysql_reset_connection(MYSQL *mysql) +{ + int rc; + + /* check if connection handler is active */ + if (IS_CONNHDLR_ACTIVE(mysql)) + { + if (mysql->extension->conn_hdlr->plugin && mysql->extension->conn_hdlr->plugin->reset) + return(mysql->extension->conn_hdlr->plugin->reset(mysql)); + } + + /* skip result sets */ + if (mysql->status == MYSQL_STATUS_USE_RESULT || + mysql->status == MYSQL_STATUS_GET_RESULT || + mysql->status & SERVER_MORE_RESULTS_EXIST) + { + mthd_my_skip_result(mysql); + mysql->status= MYSQL_STATUS_READY; + } + + rc= ma_simple_command(mysql, COM_RESET_CONNECTION, 0, 0, 0, 0); + if (rc && mysql->options.reconnect) + { + /* There is no big sense in resetting but we need reconnect */ + rc= ma_simple_command(mysql, COM_RESET_CONNECTION,0,0,0,0); + } + if (rc) + return 1; + + /* reset the connection in all active statements */ + ma_invalidate_stmts(mysql, "mysql_reset_connection()"); + free_old_query(mysql); + mysql->status= MYSQL_STATUS_READY; + mysql->affected_rows= ~(my_ulonglong)0; + mysql->insert_id= 0; + return 0; +} + +#undef STDCALL +/* API functions for usage in dynamic plugins */ +struct st_mariadb_api MARIADB_API= +{ + mysql_num_rows, + mysql_num_fields, + mysql_eof, + mysql_fetch_field_direct, + mysql_fetch_fields, + mysql_row_tell, + mysql_field_tell, + mysql_field_count, + mysql_more_results, + mysql_next_result, + mysql_affected_rows, + mysql_autocommit, + mysql_commit, + mysql_rollback, + mysql_insert_id, + mysql_errno, + mysql_error, + mysql_info, + mysql_thread_id, + mysql_character_set_name, + mysql_get_character_set_info, + mysql_set_character_set, + mariadb_get_infov, + mariadb_get_info, + mysql_init, + mysql_ssl_set, + mysql_get_ssl_cipher, + mysql_change_user, + mysql_real_connect, + mysql_close, + mysql_select_db, + mysql_query, + mysql_send_query, + mysql_read_query_result, + mysql_real_query, + mysql_shutdown, + mysql_dump_debug_info, + mysql_refresh, + mysql_kill, + mysql_ping, + mysql_stat, + mysql_get_server_info, + mysql_get_server_version, + mysql_get_host_info, + mysql_get_proto_info, + mysql_list_dbs, + mysql_list_tables, + mysql_list_fields, + mysql_list_processes, + mysql_store_result, + mysql_use_result, + mysql_options, + mysql_free_result, + mysql_data_seek, + mysql_row_seek, + mysql_field_seek, + mysql_fetch_row, + mysql_fetch_lengths, + mysql_fetch_field, + mysql_escape_string, + mysql_real_escape_string, + mysql_thread_safe, + mysql_warning_count, + mysql_sqlstate, + mysql_server_init, + mysql_server_end, + mysql_thread_end, + mysql_thread_init, + mysql_set_server_option, + mysql_get_client_info, + mysql_get_client_version, + mariadb_connection, + mysql_get_server_name, + mariadb_get_charset_by_name, + mariadb_get_charset_by_nr, + mariadb_convert_string, + mysql_optionsv, + mysql_get_optionv, + mysql_get_option, + mysql_hex_string, + mysql_get_socket, + mysql_get_timeout_value, + mysql_get_timeout_value_ms, + mariadb_reconnect, + mysql_stmt_init, + mysql_stmt_prepare, + mysql_stmt_execute, + mysql_stmt_fetch, + mysql_stmt_fetch_column, + mysql_stmt_store_result, + mysql_stmt_param_count, + mysql_stmt_attr_set, + mysql_stmt_attr_get, + mysql_stmt_bind_param, + mysql_stmt_bind_result, + mysql_stmt_close, + mysql_stmt_reset, + mysql_stmt_free_result, + mysql_stmt_send_long_data, + mysql_stmt_result_metadata, + mysql_stmt_param_metadata, + mysql_stmt_errno, + mysql_stmt_error, + mysql_stmt_sqlstate, + mysql_stmt_row_seek, + mysql_stmt_row_tell, + mysql_stmt_data_seek, + mysql_stmt_num_rows, + mysql_stmt_affected_rows, + mysql_stmt_insert_id, + mysql_stmt_field_count, + mysql_stmt_next_result, + mysql_stmt_more_results, + mariadb_stmt_execute_direct, + mysql_reset_connection +}; + +/* + * Default methods for a connection. These methods are + * stored in mysql->methods and can be overwritten by + * a plugin, e.g. for using another database + */ +struct st_mariadb_methods MARIADB_DEFAULT_METHODS = { + /* open a connection */ + mthd_my_real_connect, + /* close connection */ + mysql_close_slow_part, + /* send command to server */ + mthd_my_send_cmd, + /* skip result set */ + mthd_my_skip_result, + /* read response packet */ + mthd_my_read_query_result, + /* read all rows from a result set */ + mthd_my_read_rows, + /* read one/next row */ + mthd_my_read_one_row, + /* check if datatype is supported */ + mthd_supported_buffer_type, + /* read response packet from prepare */ + mthd_stmt_read_prepare_response, + /* read response from stmt execute */ + mthd_my_read_query_result, + /* get result set metadata for a prepared statement */ + mthd_stmt_get_result_metadata, + /* get param metadata for a prepared statement */ + mthd_stmt_get_param_metadata, + /* read all rows (buffered) */ + mthd_stmt_read_all_rows, + /* fetch one row (unbuffered) */ + mthd_stmt_fetch_row, + /* store values in bind buffer */ + mthd_stmt_fetch_to_bind, + /* skip unbuffered stmt result */ + mthd_stmt_flush_unbuffered, + /* set error */ + my_set_error, + /* invalidate statements */ + ma_invalidate_stmts, + /* API functions */ + &MARIADB_API, + /* read execute response */ + mthd_stmt_read_execute_response +}; diff --git a/vendor/MDBC/libmariadb/mariadb_rpl.c b/vendor/MDBC/libmariadb/mariadb_rpl.c new file mode 100644 index 00000000..9bb1916a --- /dev/null +++ b/vendor/MDBC/libmariadb/mariadb_rpl.c @@ -0,0 +1,513 @@ +/************************************************************************************ + Copyright (C) 2018 MariaDB Corpoeation AB + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not see + or write to the Free Software Foundation, Inc., + 51 Franklin St., Fifth Floor, Boston, MA 02110, USA + +*************************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static int rpl_alloc_string(MARIADB_RPL_EVENT *event, + MARIADB_STRING *s, + unsigned char *buffer, + size_t len) +{ + if (!(s->str= ma_alloc_root(&event->memroot, len))) + return 1; + memcpy(s->str, buffer, len); + s->length= len; + return 0; +} + +MARIADB_RPL * STDCALL mariadb_rpl_init_ex(MYSQL *mysql, unsigned int version) +{ + MARIADB_RPL *rpl; + + if (version < MARIADB_RPL_REQUIRED_VERSION || + version > MARIADB_RPL_VERSION) + { + my_set_error(mysql, CR_VERSION_MISMATCH, SQLSTATE_UNKNOWN, 0, version, + MARIADB_RPL_VERSION, MARIADB_RPL_REQUIRED_VERSION); + return 0; + } + + if (!mysql) + return NULL; + + if (!(rpl= (MARIADB_RPL *)calloc(1, sizeof(MARIADB_RPL)))) + { + SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); + return 0; + } + rpl->version= version; + rpl->mysql= mysql; + return rpl; +} + +void STDCALL mariadb_free_rpl_event(MARIADB_RPL_EVENT *event) +{ + if (event) + { + ma_free_root(&event->memroot, MYF(0)); + free(event); + } +} + +int STDCALL mariadb_rpl_open(MARIADB_RPL *rpl) +{ + unsigned char *ptr, *buf; + if (!rpl || !rpl->mysql) + return 1; + + /* COM_BINLOG_DUMP: + Ofs Len Data + 0 1 COM_BINLOG_DUMP + 1 4 position + 5 2 flags + 7 4 server id + 11 * filename + + * = filename length + + */ + ptr= buf= +#ifdef WIN32 + (unsigned char *)_alloca(rpl->filename_length + 11); +#else + (unsigned char *)alloca(rpl->filename_length + 11); +#endif + + int4store(ptr, (unsigned int)rpl->start_position); + ptr+= 4; + int2store(ptr, rpl->flags); + ptr+= 2; + int4store(ptr, rpl->server_id); + ptr+= 4; + memcpy(ptr, rpl->filename, rpl->filename_length); + ptr+= rpl->filename_length; + + if (ma_simple_command(rpl->mysql, COM_BINLOG_DUMP, (const char *)buf, ptr - buf, 1, 0)) + return 1; + return 0; +} + +MARIADB_RPL_EVENT * STDCALL mariadb_rpl_fetch(MARIADB_RPL *rpl, MARIADB_RPL_EVENT *event) +{ + unsigned char *ev; + size_t len; + MARIADB_RPL_EVENT *rpl_event= 0; + + if (!rpl || !rpl->mysql) + return 0; + + while (1) { + unsigned long pkt_len= ma_net_safe_read(rpl->mysql); + + if (pkt_len == packet_error) + { + rpl->buffer_size= 0; + return 0; + } + + /* EOF packet: + see https://mariadb.com/kb/en/library/eof_packet/ + Packet length must be less than 9 bytes, EOF header + is 0xFE. + */ + if (pkt_len < 9 && rpl->mysql->net.read_pos[0] == 0xFE) + { + rpl->buffer_size= 0; + return 0; + } + + /* if ignore heartbeat flag was set, we ignore this + record and continue to fetch next record. + The first byte is always status byte (0x00) + For event header description see + https://mariadb.com/kb/en/library/2-binlog-event-header/ */ + if (rpl->flags & MARIADB_RPL_IGNORE_HEARTBEAT) + { + if (rpl->mysql->net.read_pos[1 + 4] == HEARTBEAT_LOG_EVENT) + continue; + } + + rpl->buffer_size= pkt_len; + rpl->buffer= rpl->mysql->net.read_pos; + + if (event) + { + MA_MEM_ROOT memroot= event->memroot; + rpl_event= event; + ma_free_root(&memroot, MYF(MY_KEEP_PREALLOC)); + memset(rpl_event, 0, sizeof(MARIADB_RPL_EVENT)); + rpl_event->memroot= memroot; + } else { + if (!(rpl_event = (MARIADB_RPL_EVENT *)malloc(sizeof(MARIADB_RPL_EVENT)))) + goto mem_error; + memset(rpl_event, 0, sizeof(MARIADB_RPL_EVENT)); + ma_init_alloc_root(&rpl_event->memroot, 8192, 0); + } + rpl_event->checksum= uint4korr(rpl->buffer + rpl->buffer_size - 4); + + rpl_event->ok= rpl->buffer[0]; + rpl_event->timestamp= uint4korr(rpl->buffer + 1); + rpl_event->event_type= (unsigned char)*(rpl->buffer + 5); + rpl_event->server_id= uint4korr(rpl->buffer + 6); + rpl_event->event_length= uint4korr(rpl->buffer + 10); + rpl_event->next_event_pos= uint4korr(rpl->buffer + 14); + rpl_event->flags= uint2korr(rpl->buffer + 18); + + ev= rpl->buffer + EVENT_HEADER_OFS; + + if (rpl->use_checksum) + { + rpl_event->checksum= *(ev + rpl_event->event_length - 4); + rpl_event->event_length-= 4; + } + + switch(rpl_event->event_type) { + case HEARTBEAT_LOG_EVENT: + rpl_event->event.heartbeat.timestamp= uint4korr(ev); + ev+= 4; + rpl_event->event.heartbeat.next_position= uint4korr(ev); + ev+= 4; + rpl_event->event.heartbeat.type= (uint8_t)*ev; + ev+= 1; + rpl_event->event.heartbeat.flags= uint2korr(ev); + break; + case BINLOG_CHECKPOINT_EVENT: + len= uint4korr(ev); + ev+= 4; + if (rpl_alloc_string(rpl_event, &rpl_event->event.checkpoint.filename, ev, len)) + goto mem_error; + break; + case FORMAT_DESCRIPTION_EVENT: + rpl_event->event.format_description.format = uint2korr(ev); + ev+= 2; + rpl_event->event.format_description.server_version = (char *)(ev); + ev+= 50; + rpl_event->event.format_description.timestamp= uint4korr(ev); + ev+= 4; + rpl->fd_header_len= rpl_event->event.format_description.header_len= (uint8_t)*ev; + ev= rpl->buffer + rpl->buffer_size - 5; + rpl->use_checksum= *ev; + break; + case QUERY_EVENT: + { + size_t db_len, status_len; + rpl_event->event.query.thread_id= uint4korr(ev); + ev+= 4; + rpl_event->event.query.seconds= uint4korr(ev); + ev+= 4; + db_len= *ev; + ev++; + rpl_event->event.query.errornr= uint2korr(ev); + ev+= 2; + status_len= uint2korr(ev); + ev+= 2; + if (rpl_alloc_string(rpl_event, &rpl_event->event.query.status, ev, status_len)) + goto mem_error; + ev+= status_len; + + if (rpl_alloc_string(rpl_event, &rpl_event->event.query.database, ev, db_len)) + goto mem_error; + ev+= db_len + 1; /* zero terminated */ + + /* calculate statement size: buffer + buffer_size - current_ofs (ev) - crc_size */ + len= (size_t)(rpl->buffer + rpl->buffer_size - ev - (rpl->use_checksum ? 4 : 0)); + if (rpl_alloc_string(rpl_event, &rpl_event->event.query.statement, ev, len)) + goto mem_error; + break; + } + case TABLE_MAP_EVENT: + rpl_event->event.table_map.table_id= uint6korr(ev); + ev+= 8; + len= *ev; + ev++; + if (rpl_alloc_string(rpl_event, &rpl_event->event.table_map.database, ev, len)) + goto mem_error; + ev+= len + 1; + len= *ev; + ev++; + if (rpl_alloc_string(rpl_event, &rpl_event->event.table_map.table, ev, len)) + goto mem_error; + ev+= len + 1; + rpl_event->event.table_map.column_count= mysql_net_field_length(&ev); + len= rpl_event->event.table_map.column_count; + if (rpl_alloc_string(rpl_event, &rpl_event->event.table_map.column_types, ev, len)) + goto mem_error; + ev+= len; + len= mysql_net_field_length(&ev); + if (rpl_alloc_string(rpl_event, &rpl_event->event.table_map.metadata, ev, len)) + goto mem_error; + break; + case RAND_EVENT: + rpl_event->event.rand.first_seed= uint8korr(ev); + ev+= 8; + rpl_event->event.rand.second_seed= uint8korr(ev); + break; + case INTVAR_EVENT: + rpl_event->event.intvar.type= *ev; + ev++; + rpl_event->event.intvar.value= uint8korr(ev); + break; + case USER_VAR_EVENT: + len= uint4korr(ev); + ev+= 4; + if (rpl_alloc_string(rpl_event, &rpl_event->event.uservar.name, ev, len)) + goto mem_error; + ev+= len; + if (!(rpl_event->event.uservar.is_null= (uint8)*ev)) + { + ev++; + rpl_event->event.uservar.type= *ev; + ev++; + rpl_event->event.uservar.charset_nr= uint4korr(ev); + ev+= 4; + len= uint4korr(ev); + ev+= 4; + if (rpl_alloc_string(rpl_event, &rpl_event->event.uservar.value, ev, len)) + goto mem_error; + ev+= len; + if ((unsigned long)(ev - rpl->buffer) < rpl->buffer_size) + rpl_event->event.uservar.flags= *ev; + } + break; + case START_ENCRYPTION_EVENT: + rpl_event->event.encryption.scheme= *ev; + ev++; + rpl_event->event.encryption.key_version= uint4korr(ev); + ev+= 4; + rpl_event->event.encryption.nonce= (char *)ev; + break; + case ANNOTATE_ROWS_EVENT: + len= (uint32)(rpl->buffer + rpl->buffer_size - (unsigned char *)ev - (rpl->use_checksum ? 4 : 0)); + if (rpl_alloc_string(rpl_event, &rpl_event->event.annotate_rows.statement, ev, len)) + goto mem_error; + break; + case ROTATE_EVENT: + rpl_event->event.rotate.position= uint8korr(ev); + ev+= 8; + len= rpl_event->event_length - rpl->fd_header_len - 8; + if (rpl_alloc_string(rpl_event, &rpl_event->event.rotate.filename, ev, len)) + goto mem_error; + break; + case XID_EVENT: + rpl_event->event.xid.transaction_nr= uint8korr(ev); + break; + case STOP_EVENT: + /* nothing to do here */ + break; + case GTID_EVENT: + rpl_event->event.gtid.sequence_nr= uint8korr(ev); + ev+= 8; + rpl_event->event.gtid.domain_id= uint4korr(ev); + ev+= 4; + rpl_event->event.gtid.flags= *ev; + ev++; + if (rpl_event->event.gtid.flags & FL_GROUP_COMMIT_ID) + rpl_event->event.gtid.commit_id= uint8korr(ev); + break; + case GTID_LIST_EVENT: + { + uint32 i; + rpl_event->event.gtid_list.gtid_cnt= uint4korr(ev); + ev++; + if (!(rpl_event->event.gtid_list.gtid= (MARIADB_GTID *)ma_alloc_root(&rpl_event->memroot, sizeof(MARIADB_GTID) * rpl_event->event.gtid_list.gtid_cnt))) + goto mem_error; + for (i=0; i < rpl_event->event.gtid_list.gtid_cnt; i++) + { + rpl_event->event.gtid_list.gtid[i].domain_id= uint4korr(ev); + ev+= 4; + rpl_event->event.gtid_list.gtid[i].server_id= uint4korr(ev); + ev+= 4; + rpl_event->event.gtid_list.gtid[i].sequence_nr= uint8korr(ev); + ev+= 8; + } + break; + } + case WRITE_ROWS_EVENT_V1: + case UPDATE_ROWS_EVENT_V1: + case DELETE_ROWS_EVENT_V1: + rpl_event->event.rows.type= rpl_event->event_type - WRITE_ROWS_EVENT_V1; + if (rpl->fd_header_len == 6) + { + rpl_event->event.rows.table_id= uint4korr(ev); + ev+= 4; + } else { + rpl_event->event.rows.table_id= uint6korr(ev); + ev+= 6; + } + rpl_event->event.rows.flags= uint2korr(ev); + ev+= 2; + len= rpl_event->event.rows.column_count= mysql_net_field_length(&ev); + if (!len) + break; + if (!(rpl_event->event.rows.column_bitmap = + (char *)ma_alloc_root(&rpl_event->memroot, (len + 7) / 8))) + goto mem_error; + memcpy(rpl_event->event.rows.column_bitmap, ev, (len + 7) / 8); + ev+= (len + 7) / 8; + if (rpl_event->event_type == UPDATE_ROWS_EVENT_V1) + { + if (!(rpl_event->event.rows.column_update_bitmap = + (char *)ma_alloc_root(&rpl_event->memroot, (len + 7) / 8))) + goto mem_error; + memcpy(rpl_event->event.rows.column_update_bitmap, ev, (len + 7) / 8); + ev+= (len + 7) / 8; + } + len= (rpl->buffer + rpl_event->event_length + EVENT_HEADER_OFS - rpl->fd_header_len) - ev; + if ((rpl_event->event.rows.row_data_size= len)) + { + if (!(rpl_event->event.rows.row_data = + (char *)ma_alloc_root(&rpl_event->memroot, rpl_event->event.rows.row_data_size))) + goto mem_error; + memcpy(rpl_event->event.rows.row_data, ev, rpl_event->event.rows.row_data_size); + } + break; + default: + free(rpl_event); + return NULL; + break; + } + return rpl_event; + } +mem_error: + free(rpl_event); + SET_CLIENT_ERROR(rpl->mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); + return 0; +} + +void STDCALL mariadb_rpl_close(MARIADB_RPL *rpl) +{ + if (!rpl) + return; + if (rpl->filename) + free((void *)rpl->filename); + free(rpl); + return; +} + +int mariadb_rpl_optionsv(MARIADB_RPL *rpl, + enum mariadb_rpl_option option, + ...) +{ + va_list ap; + int rc= 0; + + if (!rpl) + return 1; + + va_start(ap, option); + + switch (option) { + case MARIADB_RPL_FILENAME: + { + char *arg1= va_arg(ap, char *); + rpl->filename_length= (uint32_t)va_arg(ap, size_t); + free((void *)rpl->filename); + rpl->filename= NULL; + if (rpl->filename_length) + { + rpl->filename= (char *)malloc(rpl->filename_length); + memcpy((void *)rpl->filename, arg1, rpl->filename_length); + } + else if (arg1) + { + rpl->filename= strdup((const char *)arg1); + rpl->filename_length= (uint32_t)strlen(rpl->filename); + } + break; + } + case MARIADB_RPL_SERVER_ID: + { + rpl->server_id= va_arg(ap, unsigned int); + break; + } + case MARIADB_RPL_FLAGS: + { + rpl->flags= va_arg(ap, unsigned int); + break; + } + case MARIADB_RPL_START: + { + rpl->start_position= va_arg(ap, unsigned long); + break; + } + default: + rc= -1; + goto end; + } +end: + va_end(ap); + return rc; +} + +int mariadb_rpl_get_optionsv(MARIADB_RPL *rpl, + enum mariadb_rpl_option option, + ...) +{ + va_list ap; + + if (!rpl) + return 1; + + va_start(ap, option); + + switch (option) { + case MARIADB_RPL_FILENAME: + { + const char **name= (const char **)va_arg(ap, char **); + size_t *len= (size_t*)va_arg(ap, size_t *); + + *name= rpl->filename; + *len= rpl->filename_length; + break; + } + case MARIADB_RPL_SERVER_ID: + { + unsigned int *id= va_arg(ap, unsigned int *); + *id= rpl->server_id; + break; + } + case MARIADB_RPL_FLAGS: + { + unsigned int *flags= va_arg(ap, unsigned int *); + *flags= rpl->flags; + break; + } + case MARIADB_RPL_START: + { + unsigned long *start= va_arg(ap, unsigned long *); + *start= rpl->start_position; + break; + } + default: + va_end(ap); + return 1; + break; + } + va_end(ap); + return 0; +} diff --git a/vendor/MDBC/libmariadb/mariadb_stmt.c b/vendor/MDBC/libmariadb/mariadb_stmt.c new file mode 100644 index 00000000..3808f9b2 --- /dev/null +++ b/vendor/MDBC/libmariadb/mariadb_stmt.c @@ -0,0 +1,2515 @@ +/**************************************************************************** + Copyright (C) 2012 Monty Program AB + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not see + or write to the Free Software Foundation, Inc., + 51 Franklin St., Fifth Floor, Boston, MA 02110, USA + + Part of this code includes code from the PHP project which + is freely available from http://www.php.net + *****************************************************************************/ + +/* The implementation for prepared statements was ported from PHP's mysqlnd + extension, written by Andrey Hristov, Georg Richter and Ulf Wendel + + Original file header: + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | Copyright (c) 2006-2011 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Authors: Georg Richter | + | Andrey Hristov | + | Ulf Wendel | + +----------------------------------------------------------------------+ + */ + +#include "ma_global.h" +#include +#include +#include +#include "mysql.h" +#include "errmsg.h" +#include +#include +#include +#include +#include +#include +#include "ma_priv.h" +#include + + +#define UPDATE_STMT_ERROR(stmt)\ +SET_CLIENT_STMT_ERROR((stmt), (stmt)->mysql->net.last_errno, (stmt)->mysql->net.sqlstate, (stmt)->mysql->net.last_error) + +#define STMT_NUM_OFS(type, a, r) (((type *)(a))[r]) +#define MADB_RESET_ERROR 1 +#define MADB_RESET_LONGDATA 2 +#define MADB_RESET_SERVER 4 +#define MADB_RESET_BUFFER 8 +#define MADB_RESET_STORED 16 + +#define MAX_TIME_STR_LEN 13 +#define MAX_DATE_STR_LEN 5 +#define MAX_DATETIME_STR_LEN 12 + +typedef struct +{ + MA_MEM_ROOT fields_ma_alloc_root; +} MADB_STMT_EXTENSION; + +static my_bool net_stmt_close(MYSQL_STMT *stmt, my_bool remove); + +static my_bool is_not_null= 0; +static my_bool is_null= 1; + +void stmt_set_error(MYSQL_STMT *stmt, + unsigned int error_nr, + const char *sqlstate, + const char *format, + ...) +{ + va_list ap; + const char *error= NULL; + + if (error_nr >= CR_MIN_ERROR && error_nr <= CR_MYSQL_LAST_ERROR) + error= ER(error_nr); + else if (error_nr >= CER_MIN_ERROR && error_nr <= CR_MARIADB_LAST_ERROR) + error= CER(error_nr); + + stmt->last_errno= error_nr; + ma_strmake(stmt->sqlstate, sqlstate, SQLSTATE_LENGTH); + va_start(ap, format); + vsnprintf(stmt->last_error, MYSQL_ERRMSG_SIZE, + format ? format : error ? error : "", ap); + va_end(ap); + return; +} + +my_bool mthd_supported_buffer_type(enum enum_field_types type) +{ + switch (type) { + case MYSQL_TYPE_BIT: + case MYSQL_TYPE_BLOB: + case MYSQL_TYPE_DATE: + case MYSQL_TYPE_DATETIME: + case MYSQL_TYPE_DECIMAL: + case MYSQL_TYPE_DOUBLE: + case MYSQL_TYPE_FLOAT: + case MYSQL_TYPE_GEOMETRY: + case MYSQL_TYPE_INT24: + case MYSQL_TYPE_LONG: + case MYSQL_TYPE_LONG_BLOB: + case MYSQL_TYPE_LONGLONG: + case MYSQL_TYPE_MEDIUM_BLOB: + case MYSQL_TYPE_NEWDATE: + case MYSQL_TYPE_NEWDECIMAL: + case MYSQL_TYPE_NULL: + case MYSQL_TYPE_SHORT: + case MYSQL_TYPE_STRING: + case MYSQL_TYPE_JSON: + case MYSQL_TYPE_TIME: + case MYSQL_TYPE_TIMESTAMP: + case MYSQL_TYPE_TINY: + case MYSQL_TYPE_TINY_BLOB: + case MYSQL_TYPE_VAR_STRING: + case MYSQL_TYPE_YEAR: + return 1; + break; + default: + return 0; + break; + } +} + +static my_bool madb_reset_stmt(MYSQL_STMT *stmt, unsigned int flags); +static my_bool mysql_stmt_internal_reset(MYSQL_STMT *stmt, my_bool is_close); +static int stmt_unbuffered_eof(MYSQL_STMT *stmt __attribute__((unused)), + uchar **row __attribute__((unused))) +{ + return MYSQL_NO_DATA; +} + +static int stmt_unbuffered_fetch(MYSQL_STMT *stmt, uchar **row) +{ + ulong pkt_len; + + pkt_len= ma_net_safe_read(stmt->mysql); + + if (pkt_len == packet_error) + { + stmt->fetch_row_func= stmt_unbuffered_eof; + return(1); + } + + if (stmt->mysql->net.read_pos[0] == 254) + { + *row = NULL; + stmt->fetch_row_func= stmt_unbuffered_eof; + return(MYSQL_NO_DATA); + } + else + *row = stmt->mysql->net.read_pos; + stmt->result.rows++; + return(0); +} + +static int stmt_buffered_fetch(MYSQL_STMT *stmt, uchar **row) +{ + if (!stmt->result_cursor) + { + *row= NULL; + stmt->state= MYSQL_STMT_FETCH_DONE; + return MYSQL_NO_DATA; + } + stmt->state= MYSQL_STMT_USER_FETCHING; + *row= (uchar *)stmt->result_cursor->data; + + stmt->result_cursor= stmt->result_cursor->next; + return 0; +} + +int mthd_stmt_read_all_rows(MYSQL_STMT *stmt) +{ + MYSQL_DATA *result= &stmt->result; + MYSQL_ROWS *current, **pprevious; + ulong packet_len; + unsigned char *p; + + pprevious= &result->data; + + while ((packet_len = ma_net_safe_read(stmt->mysql)) != packet_error) + { + p= stmt->mysql->net.read_pos; + if (packet_len > 7 || p[0] != 254) + { + /* allocate space for rows */ + if (!(current= (MYSQL_ROWS *)ma_alloc_root(&result->alloc, sizeof(MYSQL_ROWS) + packet_len))) + { + SET_CLIENT_STMT_ERROR(stmt, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); + return(1); + } + current->data= (MYSQL_ROW)(current + 1); + *pprevious= current; + pprevious= ¤t->next; + + /* copy binary row, we will encode it during mysql_stmt_fetch */ + memcpy((char *)current->data, (char *)p, packet_len); + + if (stmt->update_max_length) + { + uchar *null_ptr, bit_offset= 4; + uchar *cp= p; + unsigned int i; + + cp++; /* skip first byte */ + null_ptr= cp; + cp+= (stmt->field_count + 9) / 8; + + for (i=0; i < stmt->field_count; i++) + { + if (!(*null_ptr & bit_offset)) + { + if (mysql_ps_fetch_functions[stmt->fields[i].type].pack_len < 0) + { + /* We need to calculate the sizes for date and time types */ + size_t len= net_field_length(&cp); + switch(stmt->fields[i].type) { + case MYSQL_TYPE_TIME: + case MYSQL_TYPE_DATE: + case MYSQL_TYPE_DATETIME: + case MYSQL_TYPE_TIMESTAMP: + stmt->fields[i].max_length= mysql_ps_fetch_functions[stmt->fields[i].type].max_len; + break; + default: + if (len > stmt->fields[i].max_length) + stmt->fields[i].max_length= (ulong)len; + break; + } + cp+= len; + } + else + { + if (stmt->fields[i].flags & ZEROFILL_FLAG) + { + size_t len= MAX(stmt->fields[i].length, mysql_ps_fetch_functions[stmt->fields[i].type].max_len); + if (len > stmt->fields[i].max_length) + stmt->fields[i].max_length= (unsigned long)len; + } + else if (!stmt->fields[i].max_length) + { + stmt->fields[i].max_length= mysql_ps_fetch_functions[stmt->fields[i].type].max_len; + } + cp+= mysql_ps_fetch_functions[stmt->fields[i].type].pack_len; + } + } + if (!((bit_offset <<=1) & 255)) + { + bit_offset= 1; /* To next byte */ + null_ptr++; + } + } + } + current->length= packet_len; + result->rows++; + } else /* end of stream */ + { + *pprevious= 0; + /* sace status info */ + p++; + stmt->upsert_status.warning_count= stmt->mysql->warning_count= uint2korr(p); + p+=2; + stmt->upsert_status.server_status= stmt->mysql->server_status= uint2korr(p); + stmt->result_cursor= result->data; + return(0); + } + } + stmt->result_cursor= 0; + SET_CLIENT_STMT_ERROR(stmt, stmt->mysql->net.last_errno, stmt->mysql->net.sqlstate, + stmt->mysql->net.last_error); + return(1); +} + +static int stmt_cursor_fetch(MYSQL_STMT *stmt, uchar **row) +{ + uchar buf[STMT_ID_LENGTH + 4]; + MYSQL_DATA *result= &stmt->result; + + if (stmt->state < MYSQL_STMT_USE_OR_STORE_CALLED) + { + SET_CLIENT_STMT_ERROR(stmt, CR_COMMANDS_OUT_OF_SYNC, SQLSTATE_UNKNOWN, 0); + return(1); + } + + /* do we have some prefetched rows available ? */ + if (stmt->result_cursor) + return(stmt_buffered_fetch(stmt, row)); + if (stmt->upsert_status.server_status & SERVER_STATUS_LAST_ROW_SENT) + stmt->upsert_status.server_status&= ~SERVER_STATUS_LAST_ROW_SENT; + else + { + int4store(buf, stmt->stmt_id); + int4store(buf + STMT_ID_LENGTH, stmt->prefetch_rows); + + if (stmt->mysql->methods->db_command(stmt->mysql, COM_STMT_FETCH, (char *)buf, sizeof(buf), 1, stmt)) + { + UPDATE_STMT_ERROR(stmt); + return(1); + } + + /* free previously allocated buffer */ + ma_free_root(&result->alloc, MYF(MY_KEEP_PREALLOC)); + result->data= 0; + result->rows= 0; + + if (!stmt->mysql->options.extension->skip_read_response) + { + if (stmt->mysql->methods->db_stmt_read_all_rows(stmt)) + return(1); + + return(stmt_buffered_fetch(stmt, row)); + } + } + /* no more cursor data available */ + *row= NULL; + return(MYSQL_NO_DATA); +} + +/* flush one result set */ +void mthd_stmt_flush_unbuffered(MYSQL_STMT *stmt) +{ + ulong packet_len; + int in_resultset= stmt->state > MYSQL_STMT_EXECUTED && + stmt->state < MYSQL_STMT_FETCH_DONE; + while ((packet_len = ma_net_safe_read(stmt->mysql)) != packet_error) + { + uchar *pos= stmt->mysql->net.read_pos; + if (!in_resultset && *pos == 0) /* OK */ + { + pos++; + net_field_length(&pos); + net_field_length(&pos); + stmt->mysql->server_status= uint2korr(pos); + goto end; + } + if (packet_len < 8 && *pos == 254) /* EOF */ + { + if (mariadb_connection(stmt->mysql)) + { + stmt->mysql->server_status= uint2korr(pos + 3); + if (in_resultset) + goto end; + in_resultset= 1; + } + else + goto end; + } + } +end: + stmt->state= MYSQL_STMT_FETCH_DONE; +} + +int mthd_stmt_fetch_to_bind(MYSQL_STMT *stmt, unsigned char *row) +{ + uint i; + size_t truncations= 0; + unsigned char *null_ptr, bit_offset= 4; + row++; /* skip status byte */ + null_ptr= row; + row+= (stmt->field_count + 9) / 8; + + for (i=0; i < stmt->field_count; i++) + { + /* save row position for fetching values in pieces */ + if (*null_ptr & bit_offset) + { + if (stmt->result_callback) + stmt->result_callback(stmt->user_data, i, NULL); + else + { + if (!stmt->bind[i].is_null) + stmt->bind[i].is_null= &stmt->bind[i].is_null_value; + *stmt->bind[i].is_null= 1; + stmt->bind[i].u.row_ptr= NULL; + } + } else + { + stmt->bind[i].u.row_ptr= row; + if (!stmt->bind_result_done || + stmt->bind[i].flags & MADB_BIND_DUMMY) + { + unsigned long length; + + if (stmt->result_callback) + stmt->result_callback(stmt->user_data, i, &row); + else { + if (mysql_ps_fetch_functions[stmt->fields[i].type].pack_len >= 0) + length= mysql_ps_fetch_functions[stmt->fields[i].type].pack_len; + else + length= net_field_length(&row); + row+= length; + if (!stmt->bind[i].length) + stmt->bind[i].length= &stmt->bind[i].length_value; + *stmt->bind[i].length= stmt->bind[i].length_value= length; + } + } + else + { + if (!stmt->bind[i].length) + stmt->bind[i].length= &stmt->bind[i].length_value; + if (!stmt->bind[i].is_null) + stmt->bind[i].is_null= &stmt->bind[i].is_null_value; + *stmt->bind[i].is_null= 0; + mysql_ps_fetch_functions[stmt->fields[i].type].func(&stmt->bind[i], &stmt->fields[i], &row); + if (stmt->mysql->options.report_data_truncation) + truncations+= *stmt->bind[i].error; + } + } + + if (!((bit_offset <<=1) & 255)) { + bit_offset= 1; /* To next byte */ + null_ptr++; + } + } + return((truncations) ? MYSQL_DATA_TRUNCATED : 0); +} + +MYSQL_RES *_mysql_stmt_use_result(MYSQL_STMT *stmt) +{ + MYSQL *mysql= stmt->mysql; + + if (!stmt->field_count || + (!stmt->cursor_exists && mysql->status != MYSQL_STATUS_STMT_RESULT) || + (stmt->cursor_exists && mysql->status != MYSQL_STATUS_READY) || + (stmt->state != MYSQL_STMT_WAITING_USE_OR_STORE)) + { + SET_CLIENT_ERROR(mysql, CR_COMMANDS_OUT_OF_SYNC, SQLSTATE_UNKNOWN, 0); + return(NULL); + } + + CLEAR_CLIENT_STMT_ERROR(stmt); + + stmt->state = MYSQL_STMT_USE_OR_STORE_CALLED; + if (!stmt->cursor_exists) + stmt->fetch_row_func= stmt_unbuffered_fetch; //mysql_stmt_fetch_unbuffered_row; + else + stmt->fetch_row_func= stmt_cursor_fetch; + + return(NULL); +} + +unsigned char *mysql_net_store_length(unsigned char *packet, size_t length) +{ + if (length < (unsigned long long) L64(251)) { + *packet = (unsigned char) length; + return packet + 1; + } + + if (length < (unsigned long long) L64(65536)) { + *packet++ = 252; + int2store(packet,(uint) length); + return packet + 2; + } + + if (length < (unsigned long long) L64(16777216)) { + *packet++ = 253; + int3store(packet,(ulong) length); + return packet + 3; + } + *packet++ = 254; + int8store(packet, length); + return packet + 8; +} + +static long ma_get_length(MYSQL_STMT *stmt, unsigned int param_nr, unsigned long row_nr) +{ + if (!stmt->params[param_nr].length) + return 0; + if (stmt->param_callback) + return (long)*stmt->params[param_nr].length; + if (stmt->row_size) + return *(long *)((char *)stmt->params[param_nr].length + row_nr * stmt->row_size); + else + return stmt->params[param_nr].length[row_nr]; +} + +static signed char ma_get_indicator(MYSQL_STMT *stmt, unsigned int param_nr, unsigned long row_nr) +{ + if (!MARIADB_STMT_BULK_SUPPORTED(stmt) || + !stmt->array_size || + !stmt->params[param_nr].u.indicator) + return 0; + if (stmt->param_callback) + return *stmt->params[param_nr].u.indicator; + if (stmt->row_size) + return *((char *)stmt->params[param_nr].u.indicator + (row_nr * stmt->row_size)); + return stmt->params[param_nr].u.indicator[row_nr]; +} + +static void *ma_get_buffer_offset(MYSQL_STMT *stmt, enum enum_field_types type, + void *buffer, unsigned long row_nr) +{ + if (stmt->param_callback) + return buffer; + + if (stmt->array_size) + { + int len; + if (stmt->row_size) + return (void *)((char *)buffer + stmt->row_size * row_nr); + len= mysql_ps_fetch_functions[type].pack_len; + if (len > 0) + return (void *)((char *)buffer + len * row_nr); + return ((void **)buffer)[row_nr]; + } + return buffer; +} + +int store_param(MYSQL_STMT *stmt, int column, unsigned char **p, unsigned long row_nr) +{ + void *buf= ma_get_buffer_offset(stmt, stmt->params[column].buffer_type, + stmt->params[column].buffer, row_nr); + signed char indicator= ma_get_indicator(stmt, column, row_nr); + + switch (stmt->params[column].buffer_type) { + case MYSQL_TYPE_TINY: + int1store(*p, (*(uchar *)buf)); + (*p) += 1; + break; + case MYSQL_TYPE_SHORT: + case MYSQL_TYPE_YEAR: + int2store(*p, (*(short *)buf)); + (*p) += 2; + break; + case MYSQL_TYPE_FLOAT: + float4store(*p, (*(float *)buf)); + (*p) += 4; + break; + case MYSQL_TYPE_DOUBLE: + float8store(*p, (*(double *)buf)); + (*p) += 8; + break; + case MYSQL_TYPE_LONGLONG: + int8store(*p, (*(ulonglong *)buf)); + (*p) += 8; + break; + case MYSQL_TYPE_LONG: + case MYSQL_TYPE_INT24: + int4store(*p, (*(int32 *)buf)); + (*p)+= 4; + break; + case MYSQL_TYPE_TIME: + { + /* binary encoding: + Offset Length Field + 0 1 Length + 1 1 negative + 2-5 4 day + 6 1 hour + 7 1 ninute + 8 1 second; + 9-13 4 second_part + */ + MYSQL_TIME *t= (MYSQL_TIME *)ma_get_buffer_offset(stmt, stmt->params[column].buffer_type, + stmt->params[column].buffer, row_nr); + char t_buffer[MAX_TIME_STR_LEN]; + uint len= 0; + + t_buffer[1]= t->neg ? 1 : 0; + int4store(t_buffer + 2, t->day); + t_buffer[6]= (uchar) t->hour; + t_buffer[7]= (uchar) t->minute; + t_buffer[8]= (uchar) t->second; + if (t->second_part) + { + int4store(t_buffer + 9, t->second_part); + len= 12; + } + else if (t->day || t->hour || t->minute || t->second) + len= 8; + t_buffer[0]= len++; + memcpy(*p, t_buffer, len); + (*p)+= len; + break; + } + case MYSQL_TYPE_DATE: + case MYSQL_TYPE_TIMESTAMP: + case MYSQL_TYPE_DATETIME: + { + /* binary format for date, timestamp and datetime + Offset Length Field + 0 1 Length + 1-2 2 Year + 3 1 Month + 4 1 Day + 5 1 Hour + 6 1 minute + 7 1 second + 8-11 4 secondpart + */ + MYSQL_TIME *t= (MYSQL_TIME *)ma_get_buffer_offset(stmt, stmt->params[column].buffer_type, + stmt->params[column].buffer, row_nr); + char t_buffer[MAX_DATETIME_STR_LEN]; + uint len= 0; + + int2store(t_buffer + 1, t->year); + t_buffer[3]= (char) t->month; + t_buffer[4]= (char) t->day; + t_buffer[5]= (char) t->hour; + t_buffer[6]= (char) t->minute; + t_buffer[7]= (char) t->second; + if (t->second_part) + { + int4store(t_buffer + 8, t->second_part); + len= 11; + } + else if (t->hour || t->minute || t->second) + len= 7; + else if (t->year || t->month || t->day) + len= 4; + else + len=0; + t_buffer[0]= len++; + memcpy(*p, t_buffer, len); + (*p)+= len; + break; + } + case MYSQL_TYPE_TINY_BLOB: + case MYSQL_TYPE_MEDIUM_BLOB: + case MYSQL_TYPE_LONG_BLOB: + case MYSQL_TYPE_BLOB: + case MYSQL_TYPE_VARCHAR: + case MYSQL_TYPE_VAR_STRING: + case MYSQL_TYPE_STRING: + case MYSQL_TYPE_JSON: + case MYSQL_TYPE_DECIMAL: + case MYSQL_TYPE_NEWDECIMAL: + { + ulong len; + /* to is after p. The latter hasn't been moved */ + uchar *to; + + if (indicator == STMT_INDICATOR_NTS) + len= -1; + else + len= ma_get_length(stmt, column, row_nr); + + if (len == (ulong)-1) + len= (ulong)strlen((char *)buf); + + to = mysql_net_store_length(*p, len); + + if (len) + memcpy(to, buf, len); + (*p) = to + len; + break; + } + + default: + /* unsupported parameter type */ + SET_CLIENT_STMT_ERROR(stmt, CR_UNSUPPORTED_PARAM_TYPE, SQLSTATE_UNKNOWN, 0); + return 1; + } + return 0; +} + +/* {{{ mysqlnd_stmt_execute_generate_simple_request */ +unsigned char* mysql_stmt_execute_generate_simple_request(MYSQL_STMT *stmt, size_t *request_len) +{ + /* execute packet has the following format: + Offset Length Description + ----------------------------------------- + 0 4 Statement id + 4 1 Flags (cursor type) + 5 4 Iteration count + ----------------------------------------- + if (stmt->param_count): + 6 (paramcount+7)/8 null bitmap + ------------------------------------------ + if (stmt->send_types_to_server): + param_count*2 parameter types + 1st byte: parameter type + 2nd byte flag: + unsigned flag (32768) + indicator variable exists (16384) + ------------------------------------------ + n data from bind_buffer + + */ + + size_t length= 1024; + size_t free_bytes= 0; + size_t null_byte_offset= 0; + uint i; + + uchar *start= NULL, *p; + + /* preallocate length bytes */ + /* check: gr */ + if (!(start= p= (uchar *)malloc(length))) + goto mem_error; + + int4store(p, stmt->stmt_id); + p += STMT_ID_LENGTH; + + /* flags is 4 bytes, we store just 1 */ + int1store(p, (unsigned char) stmt->flags); + p++; + + int4store(p, 1); + p+= 4; + + if (stmt->param_count) + { + size_t null_count= (stmt->param_count + 7) / 8; + + free_bytes= length - (p - start); + if (null_count + 20 > free_bytes) + { + size_t offset= p - start; + length+= offset + null_count + 20; + if (!(start= (uchar *)realloc(start, length))) + goto mem_error; + p= start + offset; + } + + null_byte_offset= p - start; + memset(p, 0, null_count); + p += null_count; + + int1store(p, stmt->send_types_to_server); + p++; + + free_bytes= length - (p - start); + + /* Store type information: + 2 bytes per type + */ + if (stmt->send_types_to_server) + { + if (free_bytes < stmt->param_count * 2 + 20) + { + size_t offset= p - start; + length= offset + stmt->param_count * 2 + 20; + if (!(start= (uchar *)realloc(start, length))) + goto mem_error; + p= start + offset; + } + for (i = 0; i < stmt->param_count; i++) + { + /* this differs from mysqlnd, c api supports unsigned !! */ + uint buffer_type= stmt->params[i].buffer_type | (stmt->params[i].is_unsigned ? 32768 : 0); + /* check if parameter requires indicator variable */ + int2store(p, buffer_type); + p+= 2; + } + } + + /* calculate data size */ + for (i=0; i < stmt->param_count; i++) + { + size_t size= 0; + my_bool has_data= TRUE; + + if (stmt->params[i].long_data_used) + { + has_data= FALSE; + stmt->params[i].long_data_used= 0; + } + + if (has_data) + { + switch (stmt->params[i].buffer_type) { + case MYSQL_TYPE_NULL: + has_data= FALSE; + break; + case MYSQL_TYPE_TINY_BLOB: + case MYSQL_TYPE_MEDIUM_BLOB: + case MYSQL_TYPE_LONG_BLOB: + case MYSQL_TYPE_BLOB: + case MYSQL_TYPE_VARCHAR: + case MYSQL_TYPE_VAR_STRING: + case MYSQL_TYPE_STRING: + case MYSQL_TYPE_JSON: + case MYSQL_TYPE_DECIMAL: + case MYSQL_TYPE_NEWDECIMAL: + case MYSQL_TYPE_GEOMETRY: + case MYSQL_TYPE_NEWDATE: + case MYSQL_TYPE_ENUM: + case MYSQL_TYPE_BIT: + case MYSQL_TYPE_SET: + size+= 5; /* max 8 bytes for size */ + size+= (size_t)ma_get_length(stmt, i, 0); + break; + default: + size+= mysql_ps_fetch_functions[stmt->params[i].buffer_type].pack_len; + break; + } + } + free_bytes= length - (p - start); + if (free_bytes < size + 20) + { + size_t offset= p - start; + length= MAX(2 * length, offset + size + 20); + if (!(start= (uchar *)realloc(start, length))) + goto mem_error; + p= start + offset; + } + if (((stmt->params[i].is_null && *stmt->params[i].is_null) || + stmt->params[i].buffer_type == MYSQL_TYPE_NULL || + !stmt->params[i].buffer)) + { + has_data= FALSE; + (start + null_byte_offset)[i/8] |= (unsigned char) (1 << (i & 7)); + } + + if (has_data) + { + store_param(stmt, i, &p, 0); + } + } + } + stmt->send_types_to_server= 0; + *request_len = (size_t)(p - start); + return start; +mem_error: + SET_CLIENT_STMT_ERROR(stmt, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); + free(start); + *request_len= 0; + return NULL; +} +/* }}} */ + +/* {{{ mysql_stmt_skip_paramset */ +my_bool mysql_stmt_skip_paramset(MYSQL_STMT *stmt, uint row) +{ + uint i; + for (i=0; i < stmt->param_count; i++) + { + if (ma_get_indicator(stmt, i, row) == STMT_INDICATOR_IGNORE_ROW) + return '\1'; + } + + return '\0'; +} +/* }}} */ + +/* {{{ mysql_stmt_execute_generate_bulk_request */ +unsigned char* mysql_stmt_execute_generate_bulk_request(MYSQL_STMT *stmt, size_t *request_len) +{ + /* execute packet has the following format: + Offset Length Description + ----------------------------------------- + 0 4 Statement id + 4 2 Flags (cursor type): + STMT_BULK_FLAG_CLIENT_SEND_TYPES = 128 + STMT_BULK_FLAG_INSERT_ID_REQUEST = 64 + ----------------------------------------- + if (stmt->send_types_to_server): + for (i=0; i < param_count; i++) + 1st byte: parameter type + 2nd byte flag: + unsigned flag (32768) + ------------------------------------------ + for (i=0; i < param_count; i++) + 1 indicator variable + STMT_INDICATOR_NONE 0 + STMT_INDICATOR_NULL 1 + STMT_INDICATOR_DEFAULT 2 + STMT_INDICATOR_IGNORE 3 + STMT_INDICATOR_SKIP_SET 4 + n data from bind buffer + + */ + + size_t length= 1024; + size_t free_bytes= 0; + ushort flags= 0; + uint i, j; + + uchar *start= NULL, *p; + + if (!MARIADB_STMT_BULK_SUPPORTED(stmt)) + { + stmt_set_error(stmt, CR_FUNCTION_NOT_SUPPORTED, "IM001", + CER(CR_FUNCTION_NOT_SUPPORTED), "Bulk operation"); + return NULL; + } + + if (!stmt->param_count) + { + stmt_set_error(stmt, CR_BULK_WITHOUT_PARAMETERS, "IM001", + CER(CR_BULK_WITHOUT_PARAMETERS)); + return NULL; + } + + /* preallocate length bytes */ + if (!(start= p= (uchar *)malloc(length))) + goto mem_error; + + int4store(p, stmt->stmt_id); + p += STMT_ID_LENGTH; + + /* todo: request to return auto generated ids */ + if (stmt->send_types_to_server) + flags|= STMT_BULK_FLAG_CLIENT_SEND_TYPES; + int2store(p, flags); + p+=2; + + /* When using mariadb_stmt_execute_direct stmt->paran_count is + not knowm, so we need to assign prebind_params, which was previously + set by mysql_stmt_attr_set + */ + if (!stmt->param_count && stmt->prebind_params) + stmt->param_count= stmt->prebind_params; + + if (stmt->param_count) + { + free_bytes= length - (p - start); + + /* Store type information: + 2 bytes per type + */ + if (stmt->send_types_to_server) + { + if (free_bytes < stmt->param_count * 2 + 20) + { + size_t offset= p - start; + length= offset + stmt->param_count * 2 + 20; + if (!(start= (uchar *)realloc(start, length))) + goto mem_error; + p= start + offset; + } + for (i = 0; i < stmt->param_count; i++) + { + /* this differs from mysqlnd, c api supports unsigned !! */ + uint buffer_type= stmt->params[i].buffer_type | (stmt->params[i].is_unsigned ? 32768 : 0); + int2store(p, buffer_type); + p+= 2; + } + } + + /* calculate data size */ + for (j=0; j < stmt->array_size; j++) + { + /* If callback for parameters was specified, we need to + update bind information for new row */ + if (stmt->param_callback) + stmt->param_callback(stmt->user_data, stmt->params, j); + + if (mysql_stmt_skip_paramset(stmt, j)) + continue; + + for (i=0; i < stmt->param_count; i++) + { + size_t size= 0; + my_bool has_data= TRUE; + signed char indicator= ma_get_indicator(stmt, i, j); + /* check if we need to send data */ + if (indicator > 0) + has_data= FALSE; + size= 1; + + /* Please note that mysql_stmt_send_long_data is not supported + current when performing bulk execute */ + + if (has_data) + { + switch (stmt->params[i].buffer_type) { + case MYSQL_TYPE_NULL: + has_data= FALSE; + indicator= STMT_INDICATOR_NULL; + break; + case MYSQL_TYPE_TINY_BLOB: + case MYSQL_TYPE_MEDIUM_BLOB: + case MYSQL_TYPE_LONG_BLOB: + case MYSQL_TYPE_BLOB: + case MYSQL_TYPE_VARCHAR: + case MYSQL_TYPE_VAR_STRING: + case MYSQL_TYPE_STRING: + case MYSQL_TYPE_JSON: + case MYSQL_TYPE_DECIMAL: + case MYSQL_TYPE_NEWDECIMAL: + case MYSQL_TYPE_GEOMETRY: + case MYSQL_TYPE_NEWDATE: + case MYSQL_TYPE_ENUM: + case MYSQL_TYPE_BIT: + case MYSQL_TYPE_SET: + size+= 5; /* max 8 bytes for size */ + if (!stmt->param_callback) + { + if (indicator == STMT_INDICATOR_NTS || + (!stmt->row_size && ma_get_length(stmt,i,j) == -1)) + { + size+= strlen(ma_get_buffer_offset(stmt, + stmt->params[i].buffer_type, + stmt->params[i].buffer,j)); + } + else + size+= (size_t)ma_get_length(stmt, i, j); + } + else { + size+= stmt->params[i].buffer_length; + } + break; + default: + size+= mysql_ps_fetch_functions[stmt->params[i].buffer_type].pack_len; + break; + } + } + free_bytes= length - (p - start); + if (free_bytes < size + 20) + { + size_t offset= p - start; + length= MAX(2 * length, offset + size + 20); + if (!(start= (uchar *)realloc(start, length))) + goto mem_error; + p= start + offset; + } + + int1store(p, indicator > 0 ? indicator : 0); + p++; + if (has_data) { + store_param(stmt, i, &p, (stmt->param_callback) ? 0 : j); + } + } + } + + } + stmt->send_types_to_server= 0; + *request_len = (size_t)(p - start); + return start; +mem_error: + SET_CLIENT_STMT_ERROR(stmt, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); + free(start); + *request_len= 0; + return NULL; +} +/* }}} */ +/*! + ******************************************************************************* + + \fn unsigned long long mysql_stmt_affected_rows + \brief returns the number of affected rows from last mysql_stmt_execute + call + + \param[in] stmt The statement handle + ******************************************************************************* + */ +unsigned long long STDCALL mysql_stmt_affected_rows(MYSQL_STMT *stmt) +{ + return stmt->upsert_status.affected_rows; +} + +my_bool STDCALL mysql_stmt_attr_get(MYSQL_STMT *stmt, enum enum_stmt_attr_type attr_type, void *value) +{ + switch (attr_type) { + case STMT_ATTR_STATE: + *(enum mysql_stmt_state *)value= stmt->state; + break; + case STMT_ATTR_UPDATE_MAX_LENGTH: + *(my_bool *)value= stmt->update_max_length; + break; + case STMT_ATTR_CURSOR_TYPE: + *(unsigned long *)value= stmt->flags; + break; + case STMT_ATTR_PREFETCH_ROWS: + *(unsigned long *)value= stmt->prefetch_rows; + break; + case STMT_ATTR_PREBIND_PARAMS: + *(unsigned int *)value= stmt->prebind_params; + break; + case STMT_ATTR_ARRAY_SIZE: + *(unsigned int *)value= stmt->array_size; + break; + case STMT_ATTR_ROW_SIZE: + *(size_t *)value= stmt->row_size; + break; + case STMT_ATTR_CB_USER_DATA: + *((void **)value) = stmt->user_data; + break; + default: + return(1); + } + return(0); +} + +my_bool STDCALL mysql_stmt_attr_set(MYSQL_STMT *stmt, enum enum_stmt_attr_type attr_type, const void *value) +{ + switch (attr_type) { + case STMT_ATTR_UPDATE_MAX_LENGTH: + stmt->update_max_length= *(my_bool *)value; + break; + case STMT_ATTR_CURSOR_TYPE: + if (*(ulong *)value > (unsigned long) CURSOR_TYPE_READ_ONLY) + { + SET_CLIENT_STMT_ERROR(stmt, CR_NOT_IMPLEMENTED, SQLSTATE_UNKNOWN, 0); + return(1); + } + stmt->flags = *(ulong *)value; + break; + case STMT_ATTR_PREFETCH_ROWS: + if (*(ulong *)value == 0) + *(long *)value= MYSQL_DEFAULT_PREFETCH_ROWS; + else + stmt->prefetch_rows= *(long *)value; + break; + case STMT_ATTR_PREBIND_PARAMS: + if (stmt->state > MYSQL_STMT_INITTED) + { + mysql_stmt_internal_reset(stmt, 1); + net_stmt_close(stmt, 0); + stmt->state= MYSQL_STMT_INITTED; + stmt->params= 0; + } + stmt->prebind_params= *(unsigned int *)value; + break; + case STMT_ATTR_ARRAY_SIZE: + stmt->array_size= *(unsigned int *)value; + break; + case STMT_ATTR_ROW_SIZE: + stmt->row_size= *(size_t *)value; + break; + case STMT_ATTR_CB_RESULT: + stmt->result_callback= (ps_result_callback)value; + break; + case STMT_ATTR_CB_PARAM: + stmt->param_callback= (ps_param_callback)value; + break; + case STMT_ATTR_CB_USER_DATA: + stmt->user_data= (void *)value; + break; + default: + SET_CLIENT_STMT_ERROR(stmt, CR_NOT_IMPLEMENTED, SQLSTATE_UNKNOWN, 0); + return(1); + } + return(0); +} + +my_bool STDCALL mysql_stmt_bind_param(MYSQL_STMT *stmt, MYSQL_BIND *bind) +{ + MYSQL *mysql= stmt->mysql; + + if (!mysql) + { + SET_CLIENT_STMT_ERROR(stmt, CR_SERVER_LOST, SQLSTATE_UNKNOWN, 0); + return(1); + } + + /* If number of parameters was specified via mysql_stmt_attr_set we need to realloc + them, e.g. for mariadb_stmt_execute_direct() + */ + if ((stmt->state < MYSQL_STMT_PREPARED || stmt->state >= MYSQL_STMT_EXECUTED) && + stmt->prebind_params > 0) + { + if (!stmt->params && stmt->prebind_params) + { + if (!(stmt->params= (MYSQL_BIND *)ma_alloc_root(&stmt->mem_root, stmt->prebind_params * sizeof(MYSQL_BIND)))) + { + SET_CLIENT_STMT_ERROR(stmt, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); + return(1); + } + memset(stmt->params, '\0', stmt->prebind_params * sizeof(MYSQL_BIND)); + } + stmt->param_count= stmt->prebind_params; + } + else if (stmt->state < MYSQL_STMT_PREPARED) { + SET_CLIENT_STMT_ERROR(stmt, CR_NO_PREPARE_STMT, SQLSTATE_UNKNOWN, 0); + return(1); + } + + if (stmt->param_count && bind) + { + uint i; + + memcpy(stmt->params, bind, sizeof(MYSQL_BIND) * stmt->param_count); + stmt->send_types_to_server= 1; + + for (i=0; i < stmt->param_count; i++) + { + if (stmt->mysql->methods->db_supported_buffer_type && + !stmt->mysql->methods->db_supported_buffer_type(stmt->params[i].buffer_type)) + { + SET_CLIENT_STMT_ERROR(stmt, CR_UNSUPPORTED_PARAM_TYPE, SQLSTATE_UNKNOWN, 0); + return(1); + } + if (!stmt->params[i].is_null) + stmt->params[i].is_null= &is_not_null; + + if (stmt->params[i].long_data_used) + stmt->params[i].long_data_used= 0; + + if (!stmt->params[i].length) + stmt->params[i].length= &stmt->params[i].buffer_length; + + switch(stmt->params[i].buffer_type) { + case MYSQL_TYPE_NULL: + stmt->params[i].is_null= &is_null; + break; + case MYSQL_TYPE_TINY: + stmt->params[i].buffer_length= 1; + break; + case MYSQL_TYPE_SHORT: + case MYSQL_TYPE_YEAR: + stmt->params[i].buffer_length= 2; + break; + case MYSQL_TYPE_LONG: + case MYSQL_TYPE_FLOAT: + stmt->params[i].buffer_length= 4; + break; + case MYSQL_TYPE_LONGLONG: + case MYSQL_TYPE_DOUBLE: + stmt->params[i].buffer_length= 8; + break; + case MYSQL_TYPE_DATETIME: + case MYSQL_TYPE_TIMESTAMP: + stmt->params[i].buffer_length= 12; + break; + case MYSQL_TYPE_TIME: + stmt->params[i].buffer_length= 13; + break; + case MYSQL_TYPE_DATE: + stmt->params[i].buffer_length= 5; + break; + case MYSQL_TYPE_STRING: + case MYSQL_TYPE_JSON: + case MYSQL_TYPE_VAR_STRING: + case MYSQL_TYPE_BLOB: + case MYSQL_TYPE_TINY_BLOB: + case MYSQL_TYPE_MEDIUM_BLOB: + case MYSQL_TYPE_LONG_BLOB: + case MYSQL_TYPE_DECIMAL: + case MYSQL_TYPE_NEWDECIMAL: + break; + default: + SET_CLIENT_STMT_ERROR(stmt, CR_UNSUPPORTED_PARAM_TYPE, SQLSTATE_UNKNOWN, 0); + return(1); + break; + } + } + } + stmt->bind_param_done= stmt->send_types_to_server= 1; + + CLEAR_CLIENT_STMT_ERROR(stmt); + return(0); +} + +my_bool STDCALL mysql_stmt_bind_result(MYSQL_STMT *stmt, MYSQL_BIND *bind) +{ + uint i; + + if (stmt->state < MYSQL_STMT_PREPARED) + { + SET_CLIENT_STMT_ERROR(stmt, CR_NO_PREPARE_STMT, SQLSTATE_UNKNOWN, 0); + return(1); + } + + if (!stmt->field_count) + { + SET_CLIENT_STMT_ERROR(stmt, CR_NO_STMT_METADATA, SQLSTATE_UNKNOWN, 0); + return(1); + } + + if (!bind) + return(1); + + /* In case of a stored procedure we don't allocate memory for bind + in mysql_stmt_prepare + */ + + if (stmt->field_count && !stmt->bind) + { + MA_MEM_ROOT *fields_ma_alloc_root= + &((MADB_STMT_EXTENSION *)stmt->extension)->fields_ma_alloc_root; + if (!(stmt->bind= (MYSQL_BIND *)ma_alloc_root(fields_ma_alloc_root, stmt->field_count * sizeof(MYSQL_BIND)))) + { + SET_CLIENT_STMT_ERROR(stmt, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); + return(1); + } + } + + memcpy(stmt->bind, bind, sizeof(MYSQL_BIND) * stmt->field_count); + + for (i=0; i < stmt->field_count; i++) + { + if (stmt->mysql->methods->db_supported_buffer_type && + !stmt->mysql->methods->db_supported_buffer_type(bind[i].buffer_type)) + { + SET_CLIENT_STMT_ERROR(stmt, CR_UNSUPPORTED_PARAM_TYPE, SQLSTATE_UNKNOWN, 0); + return(1); + } + + if (!stmt->bind[i].is_null) + stmt->bind[i].is_null= &stmt->bind[i].is_null_value; + if (!stmt->bind[i].length) + stmt->bind[i].length= &stmt->bind[i].length_value; + if (!stmt->bind[i].error) + stmt->bind[i].error= &stmt->bind[i].error_value; + + /* set length values for numeric types */ + switch(bind[i].buffer_type) { + case MYSQL_TYPE_NULL: + *stmt->bind[i].length= stmt->bind[i].length_value= 0; + break; + case MYSQL_TYPE_TINY: + *stmt->bind[i].length= stmt->bind[i].length_value= 1; + break; + case MYSQL_TYPE_SHORT: + case MYSQL_TYPE_YEAR: + *stmt->bind[i].length= stmt->bind[i].length_value= 2; + break; + case MYSQL_TYPE_INT24: + case MYSQL_TYPE_LONG: + case MYSQL_TYPE_FLOAT: + *stmt->bind[i].length= stmt->bind[i].length_value= 4; + break; + case MYSQL_TYPE_LONGLONG: + case MYSQL_TYPE_DOUBLE: + *stmt->bind[i].length= stmt->bind[i].length_value= 8; + break; + case MYSQL_TYPE_TIME: + case MYSQL_TYPE_DATE: + case MYSQL_TYPE_DATETIME: + case MYSQL_TYPE_TIMESTAMP: + *stmt->bind[i].length= stmt->bind[i].length_value= sizeof(MYSQL_TIME); + break; + default: + break; + } + } + stmt->bind_result_done= 1; + CLEAR_CLIENT_STMT_ERROR(stmt); + + return(0); +} + +static my_bool net_stmt_close(MYSQL_STMT *stmt, my_bool remove) +{ + char stmt_id[STMT_ID_LENGTH]; + MA_MEM_ROOT *fields_ma_alloc_root= &((MADB_STMT_EXTENSION *)stmt->extension)->fields_ma_alloc_root; + + /* clear memory */ + ma_free_root(&stmt->result.alloc, MYF(0)); /* allocated in mysql_stmt_store_result */ + ma_free_root(&stmt->mem_root,MYF(0)); + ma_free_root(fields_ma_alloc_root, MYF(0)); + + if (stmt->mysql) + { + CLEAR_CLIENT_ERROR(stmt->mysql); + + /* remove from stmt list */ + if (remove) + stmt->mysql->stmts= list_delete(stmt->mysql->stmts, &stmt->list); + + /* check if all data are fetched */ + if (stmt->mysql->status != MYSQL_STATUS_READY) + { + do { + stmt->mysql->methods->db_stmt_flush_unbuffered(stmt); + } while(mysql_stmt_more_results(stmt)); + stmt->mysql->status= MYSQL_STATUS_READY; + } + if (stmt->state > MYSQL_STMT_INITTED) + { + int4store(stmt_id, stmt->stmt_id); + if (stmt->mysql->methods->db_command(stmt->mysql,COM_STMT_CLOSE, stmt_id, + sizeof(stmt_id), 1, stmt)) + { + UPDATE_STMT_ERROR(stmt); + return 1; + } + } + } + return 0; +} + +my_bool STDCALL mysql_stmt_close(MYSQL_STMT *stmt) +{ + my_bool rc= 1; + + if (stmt) + { + if (stmt->mysql && stmt->mysql->net.pvio) + mysql_stmt_internal_reset(stmt, 1); + + rc= net_stmt_close(stmt, 1); + + free(stmt->extension); + free(stmt); + } + return(rc); +} + +void STDCALL mysql_stmt_data_seek(MYSQL_STMT *stmt, unsigned long long offset) +{ + unsigned long long i= offset; + MYSQL_ROWS *ptr= stmt->result.data; + + while(i-- && ptr) + ptr= ptr->next; + + stmt->result_cursor= ptr; + stmt->state= MYSQL_STMT_USER_FETCHING; + + return; +} + +unsigned int STDCALL mysql_stmt_errno(MYSQL_STMT *stmt) +{ + return stmt->last_errno; +} + +const char * STDCALL mysql_stmt_error(MYSQL_STMT *stmt) +{ + return (const char *)stmt->last_error; +} + +int mthd_stmt_fetch_row(MYSQL_STMT *stmt, unsigned char **row) +{ + return stmt->fetch_row_func(stmt, row); +} + +int STDCALL mysql_stmt_fetch(MYSQL_STMT *stmt) +{ + unsigned char *row; + int rc; + + if (stmt->state <= MYSQL_STMT_EXECUTED) + { + SET_CLIENT_STMT_ERROR(stmt, CR_COMMANDS_OUT_OF_SYNC, SQLSTATE_UNKNOWN, 0); + return(1); + } + + if (stmt->state < MYSQL_STMT_WAITING_USE_OR_STORE || !stmt->field_count) + { + SET_CLIENT_STMT_ERROR(stmt, CR_COMMANDS_OUT_OF_SYNC, SQLSTATE_UNKNOWN, 0); + return(1); + } else if (stmt->state== MYSQL_STMT_WAITING_USE_OR_STORE) + { + stmt->default_rset_handler(stmt); + } + + if (stmt->state == MYSQL_STMT_FETCH_DONE) + return(MYSQL_NO_DATA); + + if ((rc= stmt->mysql->methods->db_stmt_fetch(stmt, &row))) + { + stmt->state= MYSQL_STMT_FETCH_DONE; + stmt->mysql->status= MYSQL_STATUS_READY; + /* to fetch data again, stmt must be executed again */ + return(rc); + } + + rc= stmt->mysql->methods->db_stmt_fetch_to_bind(stmt, row); + + stmt->state= MYSQL_STMT_USER_FETCHING; + CLEAR_CLIENT_ERROR(stmt->mysql); + CLEAR_CLIENT_STMT_ERROR(stmt); + return(rc); +} + +int STDCALL mysql_stmt_fetch_column(MYSQL_STMT *stmt, MYSQL_BIND *bind, unsigned int column, unsigned long offset) +{ + if (stmt->state < MYSQL_STMT_USER_FETCHING || column >= stmt->field_count || + stmt->state == MYSQL_STMT_FETCH_DONE) { + SET_CLIENT_STMT_ERROR(stmt, CR_NO_DATA, SQLSTATE_UNKNOWN, 0); + return(1); + } + + if (!stmt->bind[column].u.row_ptr) + { + /* we set row_ptr only for columns which contain data, so this must be a NULL column */ + if (bind[0].is_null) + *bind[0].is_null= 1; + } + else + { + unsigned char *save_ptr; + if (bind[0].length) + *bind[0].length= *stmt->bind[column].length; + else + bind[0].length= &stmt->bind[column].length_value; + if (bind[0].is_null) + *bind[0].is_null= 0; + else + bind[0].is_null= &bind[0].is_null_value; + if (!bind[0].error) + bind[0].error= &bind[0].error_value; + *bind[0].error= 0; + bind[0].offset= offset; + save_ptr= stmt->bind[column].u.row_ptr; + mysql_ps_fetch_functions[stmt->fields[column].type].func(&bind[0], &stmt->fields[column], &stmt->bind[column].u.row_ptr); + stmt->bind[column].u.row_ptr= save_ptr; + } + return(0); +} + +unsigned int STDCALL mysql_stmt_field_count(MYSQL_STMT *stmt) +{ + return stmt->field_count; +} + +my_bool STDCALL mysql_stmt_free_result(MYSQL_STMT *stmt) +{ + return madb_reset_stmt(stmt, MADB_RESET_LONGDATA | MADB_RESET_STORED | + MADB_RESET_BUFFER | MADB_RESET_ERROR); +} + +MYSQL_STMT * STDCALL mysql_stmt_init(MYSQL *mysql) +{ + + MYSQL_STMT *stmt= NULL; + + if (!(stmt= (MYSQL_STMT *)calloc(1, sizeof(MYSQL_STMT))) || + !(stmt->extension= (MADB_STMT_EXTENSION *)calloc(1, sizeof(MADB_STMT_EXTENSION)))) + { + free(stmt); + SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); + return(NULL); + } + + + /* fill mysql's stmt list */ + stmt->list.data= stmt; + stmt->mysql= mysql; + stmt->stmt_id= 0; + mysql->stmts= list_add(mysql->stmts, &stmt->list); + + + /* clear flags */ + strcpy(stmt->sqlstate, "00000"); + + stmt->state= MYSQL_STMT_INITTED; + + /* set default */ + stmt->prefetch_rows= 1; + + ma_init_alloc_root(&stmt->mem_root, 2048, 2048); + ma_init_alloc_root(&stmt->result.alloc, 4096, 4096); + ma_init_alloc_root(&((MADB_STMT_EXTENSION *)stmt->extension)->fields_ma_alloc_root, 2048, 2048); + + return(stmt); +} + +my_bool mthd_stmt_read_prepare_response(MYSQL_STMT *stmt) +{ + ulong packet_length; + uchar *p; + + if ((packet_length= ma_net_safe_read(stmt->mysql)) == packet_error) + return(1); + + p= (uchar *)stmt->mysql->net.read_pos; + + if (0xFF == p[0]) /* Error occurred */ + { + return(1); + } + + p++; + stmt->stmt_id= uint4korr(p); + p+= 4; + stmt->field_count= uint2korr(p); + p+= 2; + stmt->param_count= uint2korr(p); + p+= 2; + + /* filler */ + p++; + /* for backward compatibility we also update mysql->warning_count */ + stmt->mysql->warning_count= stmt->upsert_status.warning_count= uint2korr(p); + +/* metadata not supported yet */ + + if (stmt->param_count && + stmt->mysql->methods->db_stmt_get_param_metadata(stmt)) + { + return 1; + } + + /* allocated bind buffer for parameters */ + if (stmt->field_count && + stmt->mysql->methods->db_stmt_get_result_metadata(stmt)) + { + return 1; + } + if (stmt->param_count) + { + if (stmt->prebind_params) + { + if (stmt->prebind_params != stmt->param_count) + { + SET_CLIENT_STMT_ERROR(stmt, CR_INVALID_PARAMETER_NO, SQLSTATE_UNKNOWN, 0); + return 1; + } + } else { + if (!(stmt->params= (MYSQL_BIND *)ma_alloc_root(&stmt->mem_root, stmt->param_count * sizeof(MYSQL_BIND)))) + { + SET_CLIENT_STMT_ERROR(stmt, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); + return 1; + } + memset(stmt->params, '\0', stmt->param_count * sizeof(MYSQL_BIND)); + } + } + /* allocated bind buffer for result */ + if (stmt->field_count) + { + MA_MEM_ROOT *fields_ma_alloc_root= &((MADB_STMT_EXTENSION *)stmt->extension)->fields_ma_alloc_root; + if (!(stmt->bind= (MYSQL_BIND *)ma_alloc_root(fields_ma_alloc_root, stmt->field_count * sizeof(MYSQL_BIND)))) + { + SET_CLIENT_STMT_ERROR(stmt, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); + return 1; + } + memset(stmt->bind, 0, sizeof(MYSQL_BIND) * stmt->field_count); + } + stmt->state = MYSQL_STMT_PREPARED; + + return(0); +} + +my_bool mthd_stmt_get_param_metadata(MYSQL_STMT *stmt) +{ + MYSQL_DATA *result; + + if (!(result= stmt->mysql->methods->db_read_rows(stmt->mysql, (MYSQL_FIELD *)0, + 7 + ma_extended_type_info_rows(stmt->mysql)))) + return(1); + + free_rows(result); + return(0); +} + +my_bool mthd_stmt_get_result_metadata(MYSQL_STMT *stmt) +{ + MYSQL_DATA *result; + MA_MEM_ROOT *fields_ma_alloc_root= &((MADB_STMT_EXTENSION *)stmt->extension)->fields_ma_alloc_root; + + if (!(result= stmt->mysql->methods->db_read_rows(stmt->mysql, (MYSQL_FIELD *)0, + 7 + ma_extended_type_info_rows(stmt->mysql)))) + return(1); + if (!(stmt->fields= unpack_fields(stmt->mysql, result, fields_ma_alloc_root, + stmt->field_count, 0))) + return(1); + return(0); +} + +int STDCALL mysql_stmt_warning_count(MYSQL_STMT *stmt) +{ + return stmt->upsert_status.warning_count; +} + +int STDCALL mysql_stmt_prepare(MYSQL_STMT *stmt, const char *query, unsigned long length) +{ + MYSQL *mysql= stmt->mysql; + int rc= 1; + my_bool is_multi= 0; + + if (!stmt->mysql) + { + SET_CLIENT_STMT_ERROR(stmt, CR_SERVER_LOST, SQLSTATE_UNKNOWN, 0); + return(1); + } + + if (length == (unsigned long) -1) + length= (unsigned long)strlen(query); + + /* clear flags */ + CLEAR_CLIENT_STMT_ERROR(stmt); + CLEAR_CLIENT_ERROR(stmt->mysql); + stmt->upsert_status.affected_rows= mysql->affected_rows= (unsigned long long) ~0; + + /* check if we have to clear results */ + if (stmt->state > MYSQL_STMT_INITTED) + { + char stmt_id[STMT_ID_LENGTH]; + is_multi= (mysql->net.extension->multi_status > COM_MULTI_OFF); + /* We need to semi-close the prepared statement: + reset stmt and free all buffers and close the statement + on server side. Statement handle will get a new stmt_id */ + + if (!is_multi) + ma_multi_command(mysql, COM_MULTI_ENABLED); + + if (mysql_stmt_internal_reset(stmt, 1)) + goto fail; + + ma_free_root(&stmt->mem_root, MYF(MY_KEEP_PREALLOC)); + ma_free_root(&((MADB_STMT_EXTENSION *)stmt->extension)->fields_ma_alloc_root, MYF(0)); + + stmt->param_count= 0; + stmt->field_count= 0; + stmt->fields= NULL; + stmt->params= NULL; + + int4store(stmt_id, stmt->stmt_id); + if (mysql->methods->db_command(mysql, COM_STMT_CLOSE, stmt_id, + sizeof(stmt_id), 1, stmt)) + goto fail; + } + if (mysql->methods->db_command(mysql, COM_STMT_PREPARE, query, length, 1, stmt)) + goto fail; + + if (!is_multi && mysql->net.extension->multi_status == COM_MULTI_ENABLED) + ma_multi_command(mysql, COM_MULTI_END); + + if (mysql->net.extension->multi_status > COM_MULTI_OFF || + mysql->options.extension->skip_read_response) + return 0; + + if (mysql->methods->db_read_prepare_response && + mysql->methods->db_read_prepare_response(stmt)) + goto fail; + + return(0); + +fail: + stmt->state= MYSQL_STMT_INITTED; + UPDATE_STMT_ERROR(stmt); + return(rc); +} + +int STDCALL mysql_stmt_store_result(MYSQL_STMT *stmt) +{ + unsigned int last_server_status; + + if (!stmt->mysql) + { + SET_CLIENT_STMT_ERROR(stmt, CR_SERVER_LOST, SQLSTATE_UNKNOWN, 0); + return(1); + } + + if (!stmt->field_count) + return(0); + + /* test_pure_coverage requires checking of error_no */ + if (stmt->last_errno) + return(1); + + if (stmt->state < MYSQL_STMT_EXECUTED) + { + SET_CLIENT_ERROR(stmt->mysql, CR_COMMANDS_OUT_OF_SYNC, SQLSTATE_UNKNOWN, 0); + SET_CLIENT_STMT_ERROR(stmt, CR_COMMANDS_OUT_OF_SYNC, SQLSTATE_UNKNOWN, 0); + return(1); + } + + last_server_status= stmt->mysql->server_status; + + /* if stmt is a cursor, we need to tell server to send all rows */ + if (stmt->cursor_exists && stmt->mysql->status == MYSQL_STATUS_READY) + { + char buff[STMT_ID_LENGTH + 4]; + int4store(buff, stmt->stmt_id); + int4store(buff + STMT_ID_LENGTH, (int)~0); + + if (stmt->mysql->methods->db_command(stmt->mysql, COM_STMT_FETCH, + buff, sizeof(buff), 1, stmt)) + { + UPDATE_STMT_ERROR(stmt); + return(1); + } + } + else if (stmt->mysql->status != MYSQL_STATUS_STMT_RESULT) + { + SET_CLIENT_ERROR(stmt->mysql, CR_COMMANDS_OUT_OF_SYNC, SQLSTATE_UNKNOWN, 0); + SET_CLIENT_STMT_ERROR(stmt, CR_COMMANDS_OUT_OF_SYNC, SQLSTATE_UNKNOWN, 0); + return(1); + } + + if (stmt->mysql->methods->db_stmt_read_all_rows(stmt)) + { + /* error during read - reset stmt->data */ + ma_free_root(&stmt->result.alloc, 0); + stmt->result.data= NULL; + stmt->result.rows= 0; + stmt->mysql->status= MYSQL_STATUS_READY; + return(1); + } + + /* workaround for MDEV 6304: + more results not set if the resultset has + SERVER_PS_OUT_PARAMS set + */ + if (last_server_status & SERVER_PS_OUT_PARAMS && + !(stmt->mysql->server_status & SERVER_MORE_RESULTS_EXIST)) + stmt->mysql->server_status|= SERVER_MORE_RESULTS_EXIST; + + stmt->result_cursor= stmt->result.data; + stmt->fetch_row_func= stmt_buffered_fetch; + stmt->mysql->status= MYSQL_STATUS_READY; + + if (!stmt->result.rows) + stmt->state= MYSQL_STMT_FETCH_DONE; + else + stmt->state= MYSQL_STMT_USE_OR_STORE_CALLED; + + /* set affected rows: see bug 2247 */ + stmt->upsert_status.affected_rows= stmt->result.rows; + stmt->mysql->affected_rows= stmt->result.rows; + + return(0); +} + +static int madb_alloc_stmt_fields(MYSQL_STMT *stmt) +{ + MA_MEM_ROOT *fields_ma_alloc_root= &((MADB_STMT_EXTENSION *)stmt->extension)->fields_ma_alloc_root; + MYSQL *mysql= stmt->mysql; + if (!mysql->field_count) + return 0; + + stmt->field_count= mysql->field_count; + if (mysql->fields) + { + /* Column info was sent by server */ + ma_free_root(fields_ma_alloc_root, MYF(0)); + if (!(stmt->fields= ma_duplicate_resultset_metadata( + mysql->fields, mysql->field_count, + fields_ma_alloc_root))) + { + SET_CLIENT_STMT_ERROR(stmt, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); + return(1); + } + if (!(stmt->bind= (MYSQL_BIND *) ma_alloc_root( + fields_ma_alloc_root, stmt->field_count * sizeof(MYSQL_BIND)))) + { + SET_CLIENT_STMT_ERROR(stmt, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); + return (1); + } + } + memset(stmt->bind, 0, stmt->field_count * sizeof(MYSQL_BIND)); + stmt->bind_result_done= 0; + return(0); +} + +int mthd_stmt_read_execute_response(MYSQL_STMT *stmt) +{ + MYSQL *mysql= stmt->mysql; + int ret; + + if (!mysql) + return(1); + + /* if a reconnect occurred, our connection handle is invalid */ + if (!stmt->mysql) + return (1); + + ret= test((mysql->methods->db_read_stmt_result && + mysql->methods->db_read_stmt_result(mysql))); + + if (!ret && mysql->field_count && !mysql->fields) + { + /* + Column info was not sent by server, copy + from stmt->fields + */ + assert(stmt->fields); + /* + Too bad, C/C resets stmt->field_count to 0 + before reading SP output variables result sets. + */ + if(!stmt->field_count) + stmt->field_count = mysql->field_count; + else + assert(mysql->field_count == stmt->field_count); + mysql->fields= ma_duplicate_resultset_metadata( + stmt->fields, stmt->field_count, &mysql->field_alloc); + if (!mysql->fields) + { + SET_CLIENT_STMT_ERROR(stmt, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); + return (1); + } + } + + /* update affected rows, also if an error occurred */ + stmt->upsert_status.affected_rows= stmt->mysql->affected_rows; + + if (ret) + { + SET_CLIENT_STMT_ERROR(stmt, mysql->net.last_errno, mysql->net.sqlstate, + mysql->net.last_error); + stmt->state= MYSQL_STMT_PREPARED; + return(1); + } + stmt->upsert_status.last_insert_id= mysql->insert_id; + stmt->upsert_status.server_status= mysql->server_status; + stmt->upsert_status.warning_count= mysql->warning_count; + + CLEAR_CLIENT_ERROR(mysql); + CLEAR_CLIENT_STMT_ERROR(stmt); + + stmt->execute_count++; + stmt->send_types_to_server= 0; + + stmt->state= MYSQL_STMT_EXECUTED; + + if (mysql->field_count) + { + if (!stmt->field_count || + mysql->server_status & SERVER_MORE_RESULTS_EXIST) /* fix for ps_bug: test_misc */ + { + MA_MEM_ROOT *fields_ma_alloc_root= + &((MADB_STMT_EXTENSION *)stmt->extension)->fields_ma_alloc_root; + uint i; + + ma_free_root(fields_ma_alloc_root, MYF(0)); + if (!(stmt->bind= (MYSQL_BIND *)ma_alloc_root(fields_ma_alloc_root, + sizeof(MYSQL_BIND) * mysql->field_count)) || + !(stmt->fields= (MYSQL_FIELD *)ma_alloc_root(fields_ma_alloc_root, + sizeof(MYSQL_FIELD) * mysql->field_count))) + { + SET_CLIENT_STMT_ERROR(stmt, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); + return(1); + } + memset(stmt->bind, 0, sizeof(MYSQL_BIND) * mysql->field_count); + stmt->field_count= mysql->field_count; + + for (i=0; i < stmt->field_count; i++) + { + memcpy(&stmt->fields[i], &mysql->fields[i], sizeof(MYSQL_FIELD)); + + /* since all pointers will be incorrect if another statement will + be executed, so we need to allocate memory and copy the + information */ + if (mysql->fields[i].db) + stmt->fields[i].db= ma_strdup_root(fields_ma_alloc_root, mysql->fields[i].db); + if (mysql->fields[i].table) + stmt->fields[i].table= ma_strdup_root(fields_ma_alloc_root, mysql->fields[i].table); + if (mysql->fields[i].org_table) + stmt->fields[i].org_table= ma_strdup_root(fields_ma_alloc_root, mysql->fields[i].org_table); + if (mysql->fields[i].name) + stmt->fields[i].name= ma_strdup_root(fields_ma_alloc_root, mysql->fields[i].name); + if (mysql->fields[i].org_name) + stmt->fields[i].org_name= ma_strdup_root(fields_ma_alloc_root, mysql->fields[i].org_name); + if (mysql->fields[i].catalog) + stmt->fields[i].catalog= ma_strdup_root(fields_ma_alloc_root, mysql->fields[i].catalog); + if (mysql->fields[i].def) + stmt->fields[i].def= ma_strdup_root(fields_ma_alloc_root, mysql->fields[i].def); + stmt->fields[i].extension= + mysql->fields[i].extension ? + ma_field_extension_deep_dup(fields_ma_alloc_root, + mysql->fields[i].extension) : + NULL; + } + } + + if ((stmt->upsert_status.server_status & SERVER_STATUS_CURSOR_EXISTS) && + (stmt->flags & CURSOR_TYPE_READ_ONLY)) + { + stmt->cursor_exists = TRUE; + mysql->status = MYSQL_STATUS_READY; + + /* Only cursor read */ + stmt->default_rset_handler = _mysql_stmt_use_result; + + } else if (stmt->flags & CURSOR_TYPE_READ_ONLY) + { + /* + We have asked for CURSOR but got no cursor, because the condition + above is not fulfilled. Then... + This is a single-row result set, a result set with no rows, EXPLAIN, + SHOW VARIABLES, or some other command which either a) bypasses the + cursors framework in the server and writes rows directly to the + network or b) is more efficient if all (few) result set rows are + precached on client and server's resources are freed. + */ + + /* preferred is buffered read */ + if (mysql_stmt_store_result(stmt)) + return 1; + stmt->mysql->status= MYSQL_STATUS_STMT_RESULT; + } else + { + /* preferred is unbuffered read */ + stmt->default_rset_handler = _mysql_stmt_use_result; + stmt->mysql->status= MYSQL_STATUS_STMT_RESULT; + } + stmt->state= MYSQL_STMT_WAITING_USE_OR_STORE; + /* in certain cases parameter types can change: For example see bug + 4026 (SELECT ?), so we need to update field information */ + if (mysql->field_count == stmt->field_count) + { + uint i; + for (i=0; i < stmt->field_count; i++) + { + stmt->fields[i].type= mysql->fields[i].type; + stmt->fields[i].length= mysql->fields[i].length; + stmt->fields[i].flags= mysql->fields[i].flags; + stmt->fields[i].decimals= mysql->fields[i].decimals; + stmt->fields[i].charsetnr= mysql->fields[i].charsetnr; + stmt->fields[i].max_length= mysql->fields[i].max_length; + } + } else + { + /* table was altered, see test_wl4166_2 */ + SET_CLIENT_STMT_ERROR(stmt, CR_NEW_STMT_METADATA, SQLSTATE_UNKNOWN, 0); + return(1); + } + } + return(0); +} + +int STDCALL mysql_stmt_execute(MYSQL_STMT *stmt) +{ + MYSQL *mysql= stmt->mysql; + char *request; + int ret; + size_t request_len= 0; + + if (!stmt->mysql) + { + SET_CLIENT_STMT_ERROR(stmt, CR_SERVER_LOST, SQLSTATE_UNKNOWN, 0); + return(1); + } + + if (stmt->state < MYSQL_STMT_PREPARED) + { + SET_CLIENT_ERROR(mysql, CR_COMMANDS_OUT_OF_SYNC, SQLSTATE_UNKNOWN, 0); + SET_CLIENT_STMT_ERROR(stmt, CR_COMMANDS_OUT_OF_SYNC, SQLSTATE_UNKNOWN, 0); + return(1); + } + + if (stmt->param_count && !stmt->bind_param_done) + { + SET_CLIENT_STMT_ERROR(stmt, CR_PARAMS_NOT_BOUND, SQLSTATE_UNKNOWN, 0); + return(1); + } + + if (stmt->state == MYSQL_STMT_WAITING_USE_OR_STORE) + { + stmt->default_rset_handler = _mysql_stmt_use_result; + stmt->default_rset_handler(stmt); + } + if (stmt->state > MYSQL_STMT_WAITING_USE_OR_STORE && stmt->state < MYSQL_STMT_FETCH_DONE && !stmt->result.data) + { + if (!stmt->cursor_exists) + do { + stmt->mysql->methods->db_stmt_flush_unbuffered(stmt); + } while(mysql_stmt_more_results(stmt)); + stmt->state= MYSQL_STMT_PREPARED; + stmt->mysql->status= MYSQL_STATUS_READY; + } + + /* clear data, in case mysql_stmt_store_result was called */ + if (stmt->result.data) + { + ma_free_root(&stmt->result.alloc, MYF(MY_KEEP_PREALLOC)); + stmt->result_cursor= stmt->result.data= 0; + } + /* CONC-344: set row count to zero */ + stmt->result.rows= 0; + if (stmt->array_size > 0) + request= (char *)mysql_stmt_execute_generate_bulk_request(stmt, &request_len); + else + request= (char *)mysql_stmt_execute_generate_simple_request(stmt, &request_len); + + if (!request) + return 1; + + ret= stmt->mysql->methods->db_command(mysql, + stmt->array_size > 0 ? COM_STMT_BULK_EXECUTE : COM_STMT_EXECUTE, + request, request_len, 1, stmt); + if (request) + free(request); + + if (ret) + { + UPDATE_STMT_ERROR(stmt); + return(1); + } + + if (mysql->net.extension->multi_status > COM_MULTI_OFF || + mysql->options.extension->skip_read_response) + return(0); + + return(mthd_stmt_read_execute_response(stmt)); +} + +static my_bool madb_reset_stmt(MYSQL_STMT *stmt, unsigned int flags) +{ + MYSQL *mysql= stmt->mysql; + my_bool ret= 0; + + if (!stmt->mysql) + { + SET_CLIENT_STMT_ERROR(stmt, CR_SERVER_LOST, SQLSTATE_UNKNOWN, 0); + return(1); + } + + /* clear error */ + if (flags & MADB_RESET_ERROR) + { + CLEAR_CLIENT_ERROR(stmt->mysql); + CLEAR_CLIENT_STMT_ERROR(stmt); + } + + if (stmt->stmt_id) + { + /* free buffered resultset, previously allocated + * by mysql_stmt_store_result + */ + if (flags & MADB_RESET_STORED && + stmt->result_cursor) + { + ma_free_root(&stmt->result.alloc, MYF(MY_KEEP_PREALLOC)); + stmt->result.data= NULL; + stmt->result.rows= 0; + stmt->result_cursor= NULL; + stmt->mysql->status= MYSQL_STATUS_READY; + stmt->state= MYSQL_STMT_FETCH_DONE; + } + + /* if there is a pending result set, we will flush it */ + if (flags & MADB_RESET_BUFFER) + { + if (stmt->state == MYSQL_STMT_WAITING_USE_OR_STORE) + { + stmt->default_rset_handler(stmt); + stmt->state = MYSQL_STMT_USER_FETCHING; + } + + if (stmt->mysql->status!= MYSQL_STATUS_READY && stmt->field_count) + { + mysql->methods->db_stmt_flush_unbuffered(stmt); + mysql->status= MYSQL_STATUS_READY; + } + } + + if (flags & MADB_RESET_SERVER) + { + /* reset statement on server side */ + if (stmt->mysql && stmt->mysql->status == MYSQL_STATUS_READY && + stmt->mysql->net.pvio) + { + unsigned char cmd_buf[STMT_ID_LENGTH]; + int4store(cmd_buf, stmt->stmt_id); + if ((ret= stmt->mysql->methods->db_command(mysql,COM_STMT_RESET, (char *)cmd_buf, + sizeof(cmd_buf), 0, stmt))) + { + UPDATE_STMT_ERROR(stmt); + return(ret); + } + } + } + + if (flags & MADB_RESET_LONGDATA) + { + if (stmt->params) + { + ulonglong i; + for (i=0; i < stmt->param_count; i++) + if (stmt->params[i].long_data_used) + stmt->params[i].long_data_used= 0; + } + } + + } + return(ret); +} + +static my_bool mysql_stmt_internal_reset(MYSQL_STMT *stmt, my_bool is_close) +{ + MYSQL *mysql= stmt->mysql; + my_bool ret= 1; + unsigned int flags= MADB_RESET_LONGDATA | MADB_RESET_BUFFER | MADB_RESET_ERROR; + + if (!mysql) + { + /* connection could be invalid, e.g. after mysql_stmt_close or failed reconnect + attempt (see bug CONC-97) */ + SET_CLIENT_STMT_ERROR(stmt, CR_SERVER_LOST, SQLSTATE_UNKNOWN, 0); + return(1); + } + + if (stmt->state >= MYSQL_STMT_USER_FETCHING && + stmt->fetch_row_func == stmt_unbuffered_fetch) + flags|= MADB_RESET_BUFFER; + + ret= madb_reset_stmt(stmt, flags); + + if (stmt->stmt_id) + { + if ((stmt->state > MYSQL_STMT_EXECUTED && + stmt->mysql->status != MYSQL_STATUS_READY) || + stmt->mysql->server_status & SERVER_MORE_RESULTS_EXIST) + { + /* flush any pending (multiple) result sets */ + if (stmt->state == MYSQL_STMT_WAITING_USE_OR_STORE) + { + stmt->default_rset_handler(stmt); + stmt->state = MYSQL_STMT_USER_FETCHING; + } + + if (stmt->field_count) + { + while (mysql_stmt_next_result(stmt) == 0); + stmt->mysql->status= MYSQL_STATUS_READY; + } + } + if (!is_close) + ret= madb_reset_stmt(stmt, MADB_RESET_SERVER); + stmt->state= MYSQL_STMT_PREPARED; + } + else + stmt->state= MYSQL_STMT_INITTED; + + stmt->upsert_status.affected_rows= mysql->affected_rows; + stmt->upsert_status.last_insert_id= mysql->insert_id; + stmt->upsert_status.server_status= mysql->server_status; + stmt->upsert_status.warning_count= mysql->warning_count; + mysql->status= MYSQL_STATUS_READY; + + return(ret); +} + +MYSQL_RES * STDCALL mysql_stmt_result_metadata(MYSQL_STMT *stmt) +{ + MYSQL_RES *res; + + if (!stmt->field_count) + return(NULL); + + /* aloocate result set structutr and copy stmt information */ + if (!(res= (MYSQL_RES *)calloc(1, sizeof(MYSQL_RES)))) + { + SET_CLIENT_STMT_ERROR(stmt, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); + return(NULL); + } + + res->eof= 1; + res->fields= stmt->fields; + res->field_count= stmt->field_count; + return(res); +} + +my_bool STDCALL mysql_stmt_reset(MYSQL_STMT *stmt) +{ + if (stmt->stmt_id > 0 && + stmt->stmt_id != (unsigned long) -1) + return mysql_stmt_internal_reset(stmt, 0); + return 0; +} + +const char * STDCALL mysql_stmt_sqlstate(MYSQL_STMT *stmt) +{ + return stmt->sqlstate; +} + +MYSQL_ROW_OFFSET STDCALL mysql_stmt_row_tell(MYSQL_STMT *stmt) +{ + return(stmt->result_cursor); +} + +unsigned long STDCALL mysql_stmt_param_count(MYSQL_STMT *stmt) +{ + return stmt->param_count; +} + +MYSQL_ROW_OFFSET STDCALL mysql_stmt_row_seek(MYSQL_STMT *stmt, MYSQL_ROW_OFFSET new_row) +{ + MYSQL_ROW_OFFSET old_row; /* for returning old position */ + + old_row= stmt->result_cursor; + stmt->result_cursor= new_row; + + return(old_row); +} + +my_bool STDCALL mysql_stmt_send_long_data(MYSQL_STMT *stmt, uint param_number, + const char *data, unsigned long length) +{ + CLEAR_CLIENT_ERROR(stmt->mysql); + CLEAR_CLIENT_STMT_ERROR(stmt); + + if (stmt->state < MYSQL_STMT_PREPARED || !stmt->params) + { + SET_CLIENT_STMT_ERROR(stmt, CR_NO_PREPARE_STMT, SQLSTATE_UNKNOWN, 0); + return(1); + } + + if (param_number >= stmt->param_count) + { + SET_CLIENT_STMT_ERROR(stmt, CR_INVALID_PARAMETER_NO, SQLSTATE_UNKNOWN, 0); + return(1); + } + + if (length || !stmt->params[param_number].long_data_used) + { + int ret; + size_t packet_len= STMT_ID_LENGTH + 2 + length; + uchar *cmd_buff= (uchar *)calloc(1, packet_len); + int4store(cmd_buff, stmt->stmt_id); + int2store(cmd_buff + STMT_ID_LENGTH, param_number); + memcpy(cmd_buff + STMT_ID_LENGTH + 2, data, length); + stmt->params[param_number].long_data_used= 1; + ret= stmt->mysql->methods->db_command(stmt->mysql, COM_STMT_SEND_LONG_DATA, + (char *)cmd_buff, packet_len, 1, stmt); + if (ret) + UPDATE_STMT_ERROR(stmt); + free(cmd_buff); + return(ret); + } + return(0); +} + +unsigned long long STDCALL mysql_stmt_insert_id(MYSQL_STMT *stmt) +{ + return stmt->upsert_status.last_insert_id; +} + +unsigned long long STDCALL mysql_stmt_num_rows(MYSQL_STMT *stmt) +{ + return stmt->result.rows; +} + +MYSQL_RES* STDCALL mysql_stmt_param_metadata(MYSQL_STMT *stmt __attribute__((unused))) +{ + /* server doesn't deliver any information yet, + so we just return NULL + */ + return(NULL); +} + +my_bool STDCALL mysql_stmt_more_results(MYSQL_STMT *stmt) +{ + /* MDEV 4604: Server doesn't set MORE_RESULT flag for + OutParam result set, so we need to check + for SERVER_MORE_RESULTS_EXIST and for + SERVER_PS_OUT_PARAMS) + */ + return (stmt && + stmt->mysql && + ((stmt->mysql->server_status & SERVER_MORE_RESULTS_EXIST) || + (stmt->mysql->server_status & SERVER_PS_OUT_PARAMS))); +} + +int STDCALL mysql_stmt_next_result(MYSQL_STMT *stmt) +{ + int rc= 0; + + if (!stmt->mysql) + { + SET_CLIENT_STMT_ERROR(stmt, CR_SERVER_LOST, SQLSTATE_UNKNOWN, 0); + return(1); + } + + if (stmt->state < MYSQL_STMT_EXECUTED) + { + SET_CLIENT_ERROR(stmt->mysql, CR_COMMANDS_OUT_OF_SYNC, SQLSTATE_UNKNOWN, 0); + SET_CLIENT_STMT_ERROR(stmt, CR_COMMANDS_OUT_OF_SYNC, SQLSTATE_UNKNOWN, 0); + return(1); + } + + if (!mysql_stmt_more_results(stmt)) + return(-1); + + if (stmt->state > MYSQL_STMT_EXECUTED && + stmt->state < MYSQL_STMT_FETCH_DONE) + madb_reset_stmt(stmt, MADB_RESET_ERROR | MADB_RESET_BUFFER | MADB_RESET_LONGDATA); + stmt->state= MYSQL_STMT_WAITING_USE_OR_STORE; + + if (mysql_next_result(stmt->mysql)) + { + stmt->state= MYSQL_STMT_FETCH_DONE; + SET_CLIENT_STMT_ERROR(stmt, stmt->mysql->net.last_errno, stmt->mysql->net.sqlstate, + stmt->mysql->net.last_error); + return(1); + } + + if (stmt->mysql->status == MYSQL_STATUS_GET_RESULT) + stmt->mysql->status= MYSQL_STATUS_STMT_RESULT; + + if (stmt->mysql->field_count) + rc= madb_alloc_stmt_fields(stmt); + else + { + stmt->upsert_status.affected_rows= stmt->mysql->affected_rows; + stmt->upsert_status.last_insert_id= stmt->mysql->insert_id; + stmt->upsert_status.server_status= stmt->mysql->server_status; + stmt->upsert_status.warning_count= stmt->mysql->warning_count; + } + + stmt->field_count= stmt->mysql->field_count; + stmt->result.rows= 0; + + return(rc); +} + +int STDCALL mariadb_stmt_execute_direct(MYSQL_STMT *stmt, + const char *stmt_str, + size_t length) +{ + MYSQL *mysql; + my_bool emulate_cmd; + my_bool clear_result= 0; + + if (!stmt) + return 1; + + mysql= stmt->mysql; + if (!mysql) + { + SET_CLIENT_STMT_ERROR(stmt, CR_SERVER_LOST, SQLSTATE_UNKNOWN, 0); + return 1; + } + + emulate_cmd= !(!(stmt->mysql->server_capabilities & CLIENT_MYSQL) && + (stmt->mysql->extension->mariadb_server_capabilities & + (MARIADB_CLIENT_STMT_BULK_OPERATIONS >> 32))) || mysql->net.compress; + + /* Server versions < 10.2 don't support execute_direct, so we need to + emulate it */ + if (emulate_cmd) + { + int rc; + + /* avoid sending close + prepare in 2 packets */ + if ((rc= mysql_stmt_prepare(stmt, stmt_str, (unsigned long)length))) + return rc; + return mysql_stmt_execute(stmt); + } + + if (ma_multi_command(mysql, COM_MULTI_ENABLED)) + { + SET_CLIENT_STMT_ERROR(stmt, CR_COMMANDS_OUT_OF_SYNC, SQLSTATE_UNKNOWN, 0); + return 1; + } + + if (length == (size_t) -1) + length= strlen(stmt_str); + + /* clear flags */ + CLEAR_CLIENT_STMT_ERROR(stmt); + CLEAR_CLIENT_ERROR(stmt->mysql); + stmt->upsert_status.affected_rows= mysql->affected_rows= (unsigned long long) ~0; + + /* check if we have to clear results */ + if (stmt->state > MYSQL_STMT_INITTED) + { + /* We need to semi-close the prepared statement: + reset stmt and free all buffers and close the statement + on server side. Statement handle will get a new stmt_id */ + char stmt_id[STMT_ID_LENGTH]; + + if (mysql_stmt_internal_reset(stmt, 1)) + goto fail; + + ma_free_root(&stmt->mem_root, MYF(MY_KEEP_PREALLOC)); + ma_free_root(&((MADB_STMT_EXTENSION *)stmt->extension)->fields_ma_alloc_root, MYF(0)); + stmt->field_count= 0; + stmt->param_count= 0; + stmt->params= 0; + + int4store(stmt_id, stmt->stmt_id); + if (mysql->methods->db_command(mysql, COM_STMT_CLOSE, stmt_id, + sizeof(stmt_id), 1, stmt)) + goto fail; + } + stmt->stmt_id= -1; + if (mysql->methods->db_command(mysql, COM_STMT_PREPARE, stmt_str, length, 1, stmt)) + goto fail; + + /* in case prepare fails, we need to clear the result package from execute, which + is always an error packet (invalid statement id) */ + clear_result= 1; + + stmt->state= MYSQL_STMT_PREPARED; + /* Since we can't determine stmt_id here, we need to set it to -1, so server will know that the + * execute command belongs to previous prepare */ + stmt->stmt_id= -1; + if (mysql_stmt_execute(stmt)) + goto fail; + + /* flush multi buffer */ + if (ma_multi_command(mysql, COM_MULTI_END)) + goto fail; + + if (!mysql->options.extension->skip_read_response) + { + /* read prepare response */ + if (mysql->methods->db_read_prepare_response && + mysql->methods->db_read_prepare_response(stmt)) + goto fail; + + clear_result= 0; + + /* read execute response packet */ + return mthd_stmt_read_execute_response(stmt); + } +fail: + /* check if we need to set error message */ + if (!mysql_stmt_errno(stmt)) + UPDATE_STMT_ERROR(stmt); + if (clear_result) { + do { + stmt->mysql->methods->db_stmt_flush_unbuffered(stmt); + } while(mysql_stmt_more_results(stmt)); + } + stmt->state= MYSQL_STMT_INITTED; + return 1; +} + +MYSQL_FIELD * STDCALL mariadb_stmt_fetch_fields(MYSQL_STMT *stmt) +{ + if (stmt) + return stmt->fields; + return NULL; +} diff --git a/vendor/MDBC/libmariadb/secure/gnutls.c b/vendor/MDBC/libmariadb/secure/gnutls.c new file mode 100644 index 00000000..960647a2 --- /dev/null +++ b/vendor/MDBC/libmariadb/secure/gnutls.c @@ -0,0 +1,1463 @@ +/************************************************************************************ + Copyright (C) 2014 MariaDB Corporation AB + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not see + or write to the Free Software Foundation, Inc., + 51 Franklin St., Fifth Floor, Boston, MA 02110, USA + + *************************************************************************************/ +#ifdef HAVE_GNUTLS + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +pthread_mutex_t LOCK_gnutls_config; + +extern my_bool ma_tls_initialized; +extern unsigned int mariadb_deinitialize_ssl; + +enum ma_pem_type { + MA_TLS_PEM_CERT= 0, + MA_TLS_PEM_KEY, + MA_TLS_PEM_CA, + MA_TLS_PEM_CRL +}; + +static int my_verify_callback(gnutls_session_t ssl); + +char tls_library_version[TLS_VERSION_LENGTH]; + +struct st_gnutls_data { + MYSQL *mysql; + gnutls_privkey_t key; + gnutls_pcert_st cert; +}; + +struct st_cipher_map { + unsigned char sid[2]; + const char *iana_name; + const char *openssl_name; + const char *gnutls_name; +}; + +const struct st_cipher_map tls_ciphers[]= +{ + { {0x00, 0x01}, + "TLS_RSA_WITH_NULL_MD5", + NULL, + "TLS_RSA_NULL_MD5"}, + { {0x00, 0x02}, + "TLS_RSA_WITH_NULL_SHA", + NULL, + "TLS_RSA_NULL_SHA1"}, + { {0x00, 0x3B}, + "TLS_RSA_WITH_NULL_SHA256", + NULL, + "TLS_RSA_NULL_SHA256"}, + { {0x00, 0x05}, + "TLS_RSA_WITH_RC4_128_SHA", + NULL, + "TLS_RSA_ARCFOUR_128_SHA1"}, + { {0x00, 0x04}, + "TLS_RSA_WITH_RC4_128_MD5", + NULL, + "TLS_RSA_ARCFOUR_128_MD5"}, + { {0x00, 0x0A}, + "TLS_RSA_WITH_3DES_EDE_CBC_SHA", + "DES-CBC3-SHA", + "TLS_RSA_3DES_EDE_CBC_SHA1"}, + { {0x00, 0x2F}, + "TLS_RSA_WITH_AES_128_CBC_SHA", + "AES128-SHA", + "TLS_RSA_AES_128_CBC_SHA1"}, + { {0x00, 0x35}, + "TLS_RSA_WITH_AES_256_CBC_SHA", + "AES256-SHA", + "TLS_RSA_AES_256_CBC_SHA1"}, + { {0x00, 0xBA}, + "TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256", + "CAMELLIA128-SHA256", + "TLS_RSA_CAMELLIA_128_CBC_SHA256"}, + { {0x00, 0xC0}, + "TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256", + NULL, + "TLS_RSA_CAMELLIA_256_CBC_SHA256"}, + { {0x00, 0x41}, + "TLS_RSA_WITH_CAMELLIA_128_CBC_SHA", + "CAMELLIA128-SHA", + "TLS_RSA_CAMELLIA_128_CBC_SHA1"}, + { {0x00, 0x84}, + "TLS_RSA_WITH_CAMELLIA_256_CBC_SHA", + "CAMELLIA256-SHA", + "TLS_RSA_CAMELLIA_256_CBC_SHA1"}, + { {0x00, 0x3C}, + "TLS_RSA_WITH_AES_128_CBC_SHA256", + "AES128-SHA256", + "TLS_RSA_AES_128_CBC_SHA256"}, + { {0x00, 0x3D}, + "TLS_RSA_WITH_AES_256_CBC_SHA256", + "AES256-SHA256", + "TLS_RSA_AES_256_CBC_SHA256"}, + { {0x00, 0x9C}, + "TLS_RSA_WITH_AES_128_GCM_SHA256", + "AES128-GCM-SHA256", + "TLS_RSA_AES_128_GCM_SHA256"}, + { {0x00, 0x9D}, + "TLS_RSA_WITH_AES_256_GCM_SHA384", + "AES256-GCM-SHA384", + "TLS_RSA_AES_256_GCM_SHA384"}, + { {0xC0, 0x7A}, + "TLS_RSA_WITH_CAMELLIA_128_GCM_SHA256", + NULL, + "TLS_RSA_CAMELLIA_128_GCM_SHA256"}, + { {0xC0, 0x7B}, + "TLS_RSA_WITH_CAMELLIA_256_GCM_SHA384", + NULL, + "TLS_RSA_CAMELLIA_256_GCM_SHA384"}, + { {0xC0, 0x9C}, + "TLS_RSA_WITH_AES_128_CCM", + NULL, + "TLS_RSA_AES_128_CCM"}, + { {0xC0, 0x9D}, + "TLS_RSA_WITH_AES_256_CCM", + NULL, + "TLS_RSA_AES_256_CCM"}, + { {0xC0, 0xA0}, + "TLS_RSA_WITH_AES_128_CCM_8", + NULL, + "TLS_RSA_AES_128_CCM_8"}, + { {0xC0, 0xA1}, + "TLS_RSA_WITH_AES_256_CCM_8", + NULL, + "TLS_RSA_AES_256_CCM_8"}, + { {0x00, 0x66}, + "TLS_DHE_DSS_WITH_RC4_128_SHA", + NULL, + "TLS_DHE_DSS_ARCFOUR_128_SHA1"}, + { {0x00, 0x13}, + "TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA", + NULL, + "TLS_DHE_DSS_3DES_EDE_CBC_SHA1"}, + { {0x00, 0x32}, + "TLS_DHE_DSS_WITH_AES_128_CBC_SHA", + NULL, + "TLS_DHE_DSS_AES_128_CBC_SHA1"}, + { {0x00, 0x38}, + "TLS_DHE_DSS_WITH_AES_256_CBC_SHA", + NULL, + "TLS_DHE_DSS_AES_256_CBC_SHA1"}, + { {0x00, 0xBD}, + "TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA256", + NULL, + "TLS_DHE_DSS_CAMELLIA_128_CBC_SHA256"}, + { {0x00, 0xC3}, + "TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA256", + NULL, + "TLS_DHE_DSS_CAMELLIA_256_CBC_SHA256"}, + { {0x00, 0x44}, + "TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA", + NULL, + "TLS_DHE_DSS_CAMELLIA_128_CBC_SHA1"}, + { {0x00, 0x87}, + "TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA", + NULL, + "TLS_DHE_DSS_CAMELLIA_256_CBC_SHA1"}, + { {0x00, 0x40}, + "TLS_DHE_DSS_WITH_AES_128_CBC_SHA256", + NULL, + "TLS_DHE_DSS_AES_128_CBC_SHA256"}, + { {0x00, 0x6A}, + "TLS_DHE_DSS_WITH_AES_256_CBC_SHA256", + NULL, + "TLS_DHE_DSS_AES_256_CBC_SHA256"}, + { {0x00, 0xA2}, + "TLS_DHE_DSS_WITH_AES_128_GCM_SHA256", + NULL, + "TLS_DHE_DSS_AES_128_GCM_SHA256"}, + { {0x00, 0xA3}, + "TLS_DHE_DSS_WITH_AES_256_GCM_SHA384", + NULL, + "TLS_DHE_DSS_AES_256_GCM_SHA384"}, + { {0xC0, 0x80}, + "TLS_DHE_DSS_WITH_CAMELLIA_128_GCM_SHA256", + NULL, + "TLS_DHE_DSS_CAMELLIA_128_GCM_SHA256"}, + { {0xC0, 0x81}, + "TLS_DHE_DSS_WITH_CAMELLIA_256_GCM_SHA384", + NULL, + "TLS_DHE_DSS_CAMELLIA_256_GCM_SHA384"}, + { {0x00, 0x16}, + "TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA", + "EDH-RSA-DES-CBC3-SHA", + "TLS_DHE_RSA_3DES_EDE_CBC_SHA1"}, + { {0x00, 0x33}, + "TLS_DHE_RSA_WITH_AES_128_CBC_SHA", + "DHE-RSA-AES128-SHA", + "TLS_DHE_RSA_AES_128_CBC_SHA1"}, + { {0x00, 0x39}, + "TLS_DHE_RSA_WITH_AES_256_CBC_SHA", + "DHE-RSA-AES256-SHA", + "TLS_DHE_RSA_AES_256_CBC_SHA1"}, + { {0x00, 0xBE}, + "TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256", + NULL, + "TLS_DHE_RSA_CAMELLIA_128_CBC_SHA256"}, + { {0x00, 0xC4}, + "TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256", + NULL, + "TLS_DHE_RSA_CAMELLIA_256_CBC_SHA256"}, + { {0x00, 0x45}, + "TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA", + "DHE-RSA-CAMELLIA128-SHA", + "TLS_DHE_RSA_CAMELLIA_128_CBC_SHA1"}, + { {0x00, 0x88}, + "TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA", + "DHE-RSA-CAMELLIA256-SHA", + "TLS_DHE_RSA_CAMELLIA_256_CBC_SHA1"}, + { {0x00, 0x67}, + "TLS_DHE_RSA_WITH_AES_128_CBC_SHA256", + "DHE-RSA-AES128-SHA256", + "TLS_DHE_RSA_AES_128_CBC_SHA256"}, + { {0x00, 0x6B}, + "TLS_DHE_RSA_WITH_AES_256_CBC_SHA256", + "DHE-RSA-AES256-SHA256", + "TLS_DHE_RSA_AES_256_CBC_SHA256"}, + { {0x00, 0x9E}, + "TLS_DHE_RSA_WITH_AES_128_GCM_SHA256", + "DHE-RSA-AES128-GCM-SHA256", + "TLS_DHE_RSA_AES_128_GCM_SHA256"}, + { {0x00, 0x9F}, + "TLS_DHE_RSA_WITH_AES_256_GCM_SHA384", + "DHE-RSA-AES256-GCM-SHA384", + "TLS_DHE_RSA_AES_256_GCM_SHA384"}, + { {0xC0, 0x7C}, + "TLS_DHE_RSA_WITH_CAMELLIA_128_GCM_SHA256", + NULL, + "TLS_DHE_RSA_CAMELLIA_128_GCM_SHA256"}, + { {0xC0, 0x7D}, + "TLS_DHE_RSA_WITH_CAMELLIA_256_GCM_SHA384", + NULL, + "TLS_DHE_RSA_CAMELLIA_256_GCM_SHA384"}, + { {0xCC, 0xAA}, + "TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256", + "DHE-RSA-CHACHA20-POLY1305", + "TLS_DHE_RSA_CHACHA20_POLY1305"}, + { {0xC0, 0x9E}, + "TLS_DHE_RSA_WITH_AES_128_CCM", + NULL, + "TLS_DHE_RSA_AES_128_CCM"}, + { {0xC0, 0x9F}, + "TLS_DHE_RSA_WITH_AES_256_CCM", + NULL, + "TLS_DHE_RSA_AES_256_CCM"}, + { {0xC0, 0xA2}, + "TLS_DHE_RSA_WITH_AES_128_CCM_8", + NULL, + "TLS_DHE_RSA_AES_128_CCM_8"}, + { {0xC0, 0xA3}, + "TLS_DHE_RSA_WITH_AES_256_CCM_8", + NULL, + "TLS_DHE_RSA_AES_256_CCM_8"}, + { {0xC0, 0x10}, + "TLS_ECDHE_RSA_WITH_", + NULL, + "TLS_ECDHE_RSA_NULL_SHA1"}, + { {0xC0, 0x12}, + "TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA", + "ECDHE-RSA-DES-CBC3-SHA", + "TLS_ECDHE_RSA_3DES_EDE_CBC_SHA1"}, + { {0xC0, 0x13}, + "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA", + "ECDHE-RSA-AES128-SHA", + "TLS_ECDHE_RSA_AES_128_CBC_SHA1"}, + { {0xC0, 0x14}, + "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA", + "ECDHE-RSA-AES256-SHA", + "TLS_ECDHE_RSA_AES_256_CBC_SHA1"}, + { {0xC0, 0x28}, + "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384", + "ECDHE-RSA-AES256-SHA384", + "TLS_ECDHE_RSA_AES_256_CBC_SHA384"}, + { {0xC0, 0x11}, + "TLS_ECDHE_RSA_WITH_RC4_128_SHA", + NULL, + "TLS_ECDHE_RSA_ARCFOUR_128_SHA1"}, + { {0xC0, 0x76}, + "TLS_ECDHE_RSA_WITH_CAMELLIA_128_CBC_SHA256", + NULL, + "TLS_ECDHE_RSA_CAMELLIA_128_CBC_SHA256"}, + { {0xC0, 0x77}, + "TLS_ECDHE_RSA_WITH_CAMELLIA_256_CBC_SHA384", + NULL, + "TLS_ECDHE_RSA_CAMELLIA_256_CBC_SHA384"}, + { {0xC0, 0x06}, + "TLS_ECDHE_ECDSA_WITH_", + NULL, + "TLS_ECDHE_ECDSA_NULL_SHA1"}, + { {0xC0, 0x08}, + "TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA", + "ECDHE-ECDSA-DES-CBC3-SHA", + "TLS_ECDHE_ECDSA_3DES_EDE_CBC_SHA1"}, + { {0xC0, 0x09}, + "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA", + "ECDHE-ECDSA-AES128-SHA", + "TLS_ECDHE_ECDSA_AES_128_CBC_SHA1"}, + { {0xC0, 0x0A}, + "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA", + "ECDHE-ECDSA-AES256-SHA", + "TLS_ECDHE_ECDSA_AES_256_CBC_SHA1"}, + { {0xC0, 0x07}, + "TLS_ECDHE_ECDSA_WITH_RC4_128_SHA", + NULL, + "TLS_ECDHE_ECDSA_ARCFOUR_128_SHA1"}, + { {0xC0, 0x72}, + "TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_CBC_SHA256", + NULL, + "TLS_ECDHE_ECDSA_CAMELLIA_128_CBC_SHA256"}, + { {0xC0, 0x73}, + "TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_CBC_SHA384", + NULL, + "TLS_ECDHE_ECDSA_CAMELLIA_256_CBC_SHA384"}, + { {0xC0, 0x23}, + "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256", + "ECDHE-ECDSA-AES128-SHA256", + "TLS_ECDHE_ECDSA_AES_128_CBC_SHA256"}, + { {0xC0, 0x27}, + "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256", + "ECDHE-RSA-AES128-SHA256", + "TLS_ECDHE_RSA_AES_128_CBC_SHA256"}, + { {0xC0, 0x86}, + "TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_GCM_SHA256", + NULL, + "TLS_ECDHE_ECDSA_CAMELLIA_128_GCM_SHA256"}, + { {0xC0, 0x87}, + "TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_GCM_SHA384", + NULL, + "TLS_ECDHE_ECDSA_CAMELLIA_256_GCM_SHA384"}, + { {0xC0, 0x2B}, + "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256", + "ECDHE-ECDSA-AES128-GCM-SHA256", + "TLS_ECDHE_ECDSA_AES_128_GCM_SHA256"}, + { {0xC0, 0x2C}, + "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384", + "ECDHE-ECDSA-AES256-GCM-SHA384", + "TLS_ECDHE_ECDSA_AES_256_GCM_SHA384"}, + { {0xC0, 0x2F}, + "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256", + "ECDHE-RSA-AES128-GCM-SHA256", + "TLS_ECDHE_RSA_AES_128_GCM_SHA256"}, + { {0xC0, 0x30}, + "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384", + "ECDHE-RSA-AES256-GCM-SHA384", + "TLS_ECDHE_RSA_AES_256_GCM_SHA384"}, + { {0xC0, 0x24}, + "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384", + "ECDHE-ECDSA-AES256-SHA384", + "TLS_ECDHE_ECDSA_AES_256_CBC_SHA384"}, + { {0xC0, 0x8A}, + "TLS_ECDHE_RSA_WITH_CAMELLIA_128_GCM_SHA256", + NULL, + "TLS_ECDHE_RSA_CAMELLIA_128_GCM_SHA256"}, + { {0xC0, 0x8B}, + "TLS_ECDHE_RSA_WITH_CAMELLIA_256_GCM_SHA384", + NULL, + "TLS_ECDHE_RSA_CAMELLIA_256_GCM_SHA384"}, + { {0xCC, 0xA8}, + "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256", + "ECDHE-RSA-CHACHA20-POLY1305", + "TLS_ECDHE_RSA_CHACHA20_POLY1305"}, + { {0xCC, 0xA9}, + "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256", + "ECDHE-ECDSA-CHACHA20-POLY1305", + "TLS_ECDHE_ECDSA_CHACHA20_POLY1305"}, + { {0xC0, 0xAC}, + "TLS_ECDHE_ECDSA_WITH_AES_128_CCM", + NULL, + "TLS_ECDHE_ECDSA_AES_128_CCM"}, + { {0xC0, 0xAD}, + "TLS_ECDHE_ECDSA_WITH_AES_256_CCM", + NULL, + "TLS_ECDHE_ECDSA_AES_256_CCM"}, + { {0xC0, 0xAE}, + "TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8", + NULL, + "TLS_ECDHE_ECDSA_AES_128_CCM_8"}, + { {0xC0, 0xAF}, + "TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8", + NULL, + "TLS_ECDHE_ECDSA_AES_256_CCM_8"}, + { {0xC0, 0x34}, + "TLS_ECDHE_PSK_WITH_3DES_EDE_CBC_SHA", + "ECDHE-PSK-3DES-EDE-CBC-SHA", + "TLS_ECDHE_PSK_3DES_EDE_CBC_SHA1"}, + { {0xC0, 0x35}, + "TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA", + "ECDHE-PSK-AES128-CBC-SHA", + "TLS_ECDHE_PSK_AES_128_CBC_SHA1"}, + { {0xC0, 0x36}, + "TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA", + "ECDHE-PSK-AES256-CBC-SHA", + "TLS_ECDHE_PSK_AES_256_CBC_SHA1"}, + { {0xC0, 0x37}, + "TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256", + "ECDHE-PSK-AES128-CBC-SHA256", + "TLS_ECDHE_PSK_AES_128_CBC_SHA256"}, + { {0xC0, 0x38}, + "TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384", + "ECDHE-PSK-AES256-CBC-SHA384", + "TLS_ECDHE_PSK_AES_256_CBC_SHA384"}, + { {0xC0, 0x33}, + "TLS_ECDHE_PSK_WITH_RC4_128_SHA", + NULL, + "TLS_ECDHE_PSK_ARCFOUR_128_SHA1"}, + { {0xC0, 0x39}, + "TLS_ECDHE_PSK_WITH_NULL_SHA", + NULL, + "TLS_ECDHE_PSK_NULL_SHA1"}, + { {0xC0, 0x3A}, + "TLS_ECDHE_PSK_WITH_NULL_SHA256", + NULL, + "TLS_ECDHE_PSK_NULL_SHA256"}, + { {0xC0, 0x3B}, + "TLS_ECDHE_PSK_WITH_NULL_SHA384", + NULL, + "TLS_ECDHE_PSK_NULL_SHA384"}, + { {0xC0, 0x9A}, + "TLS_ECDHE_PSK_WITH_CAMELLIA_128_CBC_SHA256", + NULL, + "TLS_ECDHE_PSK_CAMELLIA_128_CBC_SHA256"}, + { {0xC0, 0x9B}, + "TLS_ECDHE_PSK_WITH_CAMELLIA_256_CBC_SHA384", + NULL, + "TLS_ECDHE_PSK_CAMELLIA_256_CBC_SHA384"}, + { {0x00, 0x8A}, + "TLS_PSK_WITH_RC4_128_SHA", + NULL, + "TLS_PSK_ARCFOUR_128_SHA1"}, + { {0x00, 0x8B}, + "TLS_PSK_WITH_3DES_EDE_CBC_SHA", + "PSK-3DES-EDE-CBC-SHA", + "TLS_PSK_3DES_EDE_CBC_SHA1"}, + { {0x00, 0x8C}, + "TLS_PSK_WITH_AES_128_CBC_SHA", + "PSK-AES128-CBC-SHA", + "TLS_PSK_AES_128_CBC_SHA1"}, + { {0x00, 0x8D}, + "TLS_PSK_WITH_AES_256_CBC_SHA", + "PSK-AES256-CBC-SHA", + "TLS_PSK_AES_256_CBC_SHA1"}, + { {0x00, 0xAE}, + "TLS_PSK_WITH_AES_128_CBC_SHA256", + "PSK-AES128-CBC-SHA256", + "TLS_PSK_AES_128_CBC_SHA256"}, + { {0x00, 0xA9}, + "TLS_PSK_WITH_AES_256_GCM_SHA384", + "PSK-AES256-GCM-SHA384", + "TLS_PSK_AES_256_GCM_SHA384"}, + { {0xC0, 0x8E}, + "TLS_PSK_WITH_CAMELLIA_128_GCM_SHA256", + NULL, + "TLS_PSK_CAMELLIA_128_GCM_SHA256"}, + { {0xC0, 0x8F}, + "TLS_PSK_WITH_CAMELLIA_256_GCM_SHA384", + NULL, + "TLS_PSK_CAMELLIA_256_GCM_SHA384"}, + { {0x00, 0xA8}, + "TLS_PSK_WITH_AES_128_GCM_SHA256", + "PSK-AES128-GCM-SHA256", + "TLS_PSK_AES_128_GCM_SHA256"}, + { {0x00, 0x2C}, + "TLS_PSK_WITH_", + NULL, + "TLS_PSK_NULL_SHA1"}, + { {0x00, 0xB0}, + "TLS_PSK_WITH_", + NULL, + "TLS_PSK_NULL_SHA256"}, + { {0xC0, 0x94}, + "TLS_PSK_WITH_CAMELLIA_128_CBC_SHA256", + NULL, + "TLS_PSK_CAMELLIA_128_CBC_SHA256"}, + { {0xC0, 0x95}, + "TLS_PSK_WITH_CAMELLIA_256_CBC_SHA384", + NULL, + "TLS_PSK_CAMELLIA_256_CBC_SHA384"}, + { {0x00, 0xAF}, + "TLS_PSK_WITH_AES_256_CBC_SHA384", + "PSK-AES256-CBC-SHA384", + "TLS_PSK_AES_256_CBC_SHA384"}, + { {0x00, 0xB1}, + "TLS_PSK_WITH_", + NULL, + "TLS_PSK_NULL_SHA384"}, + { {0x00, 0x92}, + "TLS_RSA_PSK_WITH_RC4_128_SHA", + NULL, + "TLS_RSA_PSK_ARCFOUR_128_SHA1"}, + { {0x00, 0x93}, + "TLS_RSA_PSK_WITH_3DES_EDE_CBC_SHA", + "RSA-PSK-3DES-EDE-CBC-SHA", + "TLS_RSA_PSK_3DES_EDE_CBC_SHA1"}, + { {0x00, 0x94}, + "TLS_RSA_PSK_WITH_AES_128_CBC_SHA", + "RSA-PSK-AES128-CBC-SHA", + "TLS_RSA_PSK_AES_128_CBC_SHA1"}, + { {0x00, 0x95}, + "TLS_RSA_PSK_WITH_AES_256_CBC_SHA", + "RSA-PSK-AES256-CBC-SHA", + "TLS_RSA_PSK_AES_256_CBC_SHA1"}, + { {0xC0, 0x92}, + "TLS_RSA_PSK_WITH_CAMELLIA_128_GCM_SHA256", + NULL, + "TLS_RSA_PSK_CAMELLIA_128_GCM_SHA256"}, + { {0xC0, 0x93}, + "TLS_RSA_PSK_WITH_CAMELLIA_256_GCM_SHA384", + NULL, + "TLS_RSA_PSK_CAMELLIA_256_GCM_SHA384"}, + { {0x00, 0xAC}, + "TLS_RSA_PSK_WITH_AES_128_GCM_SHA256", + "RSA-PSK-AES128-GCM-SHA256", + "TLS_RSA_PSK_AES_128_GCM_SHA256"}, + { {0x00, 0xB6}, + "TLS_RSA_PSK_WITH_AES_128_CBC_SHA256", + "RSA-PSK-AES128-CBC-SHA256", + "TLS_RSA_PSK_AES_128_CBC_SHA256"}, + { {0x00, 0x2E}, + "TLS_RSA_PSK_WITH_NULL_SHA", + NULL, + "TLS_RSA_PSK_NULL_SHA1"}, + { {0x00, 0xB8}, + "TLS_RSA_PSK_WITH_", + NULL, + "TLS_RSA_PSK_NULL_SHA256"}, + { {0x00, 0xAD}, + "TLS_RSA_PSK_WITH_AES_256_GCM_SHA384", + "RSA-PSK-AES256-GCM-SHA384", + "TLS_RSA_PSK_AES_256_GCM_SHA384"}, + { {0x00, 0xB7}, + "TLS_RSA_PSK_WITH_AES_256_CBC_SHA384", + "RSA-PSK-AES256-CBC-SHA384", + "TLS_RSA_PSK_AES_256_CBC_SHA384"}, + { {0x00, 0xB9}, + "TLS_RSA_PSK_WITH_", + NULL, + "TLS_RSA_PSK_NULL_SHA384"}, + { {0xC0, 0x98}, + "TLS_RSA_PSK_WITH_CAMELLIA_128_CBC_SHA256", + NULL, + "TLS_RSA_PSK_CAMELLIA_128_CBC_SHA256"}, + { {0xC0, 0x99}, + "TLS_RSA_PSK_WITH_CAMELLIA_256_CBC_SHA384", + NULL, + "TLS_RSA_PSK_CAMELLIA_256_CBC_SHA384"}, + { {0x00, 0x8E}, + "TLS_DHE_PSK_WITH_RC4_128_SHA", + NULL, + "TLS_DHE_PSK_ARCFOUR_128_SHA1"}, + { {0x00, 0x8F}, + "TLS_DHE_PSK_WITH_3DES_EDE_CBC_SHA", + "DHE-PSK-3DES-EDE-CBC-SHA", + "TLS_DHE_PSK_3DES_EDE_CBC_SHA1"}, + { {0x00, 0x90}, + "TLS_DHE_PSK_WITH_AES_128_CBC_SHA", + "DHE-PSK-AES128-CBC-SHA", + "TLS_DHE_PSK_AES_128_CBC_SHA1"}, + { {0x00, 0x91}, + "TLS_DHE_PSK_WITH_AES_256_CBC_SHA", + "DHE-PSK-AES256-CBC-SHA", + "TLS_DHE_PSK_AES_256_CBC_SHA1"}, + { {0x00, 0xB2}, + "TLS_DHE_PSK_WITH_AES_128_CBC_SHA256", + "DHE-PSK-AES128-CBC-SHA256", + "TLS_DHE_PSK_AES_128_CBC_SHA256"}, + { {0x00, 0xAA}, + "TLS_DHE_PSK_WITH_AES_128_GCM_SHA256", + "DHE-PSK-AES128-GCM-SHA256", + "TLS_DHE_PSK_AES_128_GCM_SHA256"}, + { {0x00, 0x2D}, + "TLS_DHE_PSK_WITH_", + NULL, + "TLS_DHE_PSK_NULL_SHA1"}, + { {0x00, 0xB4}, + "TLS_DHE_PSK_WITH_", + NULL, + "TLS_DHE_PSK_NULL_SHA256"}, + { {0x00, 0xB5}, + "TLS_DHE_PSK_WITH_", + NULL, + "TLS_DHE_PSK_NULL_SHA384"}, + { {0x00, 0xB3}, + "TLS_DHE_PSK_WITH_AES_256_CBC_SHA384", + "DHE-PSK-AES256-CBC-SHA384", + "TLS_DHE_PSK_AES_256_CBC_SHA384"}, + { {0x00, 0xAB}, + "TLS_DHE_PSK_WITH_AES_256_GCM_SHA384", + "DHE-PSK-AES256-GCM-SHA384", + "TLS_DHE_PSK_AES_256_GCM_SHA384"}, + { {0xC0, 0x96}, + "TLS_DHE_PSK_WITH_CAMELLIA_128_CBC_SHA256", + NULL, + "TLS_DHE_PSK_CAMELLIA_128_CBC_SHA256"}, + { {0xC0, 0x97}, + "TLS_DHE_PSK_WITH_CAMELLIA_256_CBC_SHA384", + NULL, + "TLS_DHE_PSK_CAMELLIA_256_CBC_SHA384"}, + { {0xC0, 0x90}, + "TLS_DHE_PSK_WITH_CAMELLIA_128_GCM_SHA256", + NULL, + "TLS_DHE_PSK_CAMELLIA_128_GCM_SHA256"}, + { {0xC0, 0x91}, + "TLS_DHE_PSK_WITH_CAMELLIA_256_GCM_SHA384", + NULL, + "TLS_DHE_PSK_CAMELLIA_256_GCM_SHA384"}, + { {0xC0, 0xA4}, + "TLS_PSK_WITH_AES_128_CCM", + NULL, + "TLS_PSK_AES_128_CCM"}, + { {0xC0, 0xA5}, + "TLS_PSK_WITH_AES_256_CCM", + NULL, + "TLS_PSK_AES_256_CCM"}, + { {0xC0, 0xA6}, + "TLS_DHE_PSK_WITH_AES_128_CCM", + NULL, + "TLS_DHE_PSK_AES_128_CCM"}, + { {0xC0, 0xA7}, + "TLS_DHE_PSK_WITH_AES_256_CCM", + NULL, + "TLS_DHE_PSK_AES_256_CCM"}, + { {0xC0, 0xA8}, + "TLS_PSK_WITH_AES_128_CCM_8", + NULL, + "TLS_PSK_AES_128_CCM_8"}, + { {0xC0, 0xA9}, + "TLS_PSK_WITH_AES_256_CCM_8", + NULL, + "TLS_PSK_AES_256_CCM_8"}, + { {0xC0, 0xAA}, + "TLS_PSK_DHE_WITH_AES_128_CCM_8", + NULL, + "TLS_DHE_PSK_AES_128_CCM_8"}, + { {0xC0, 0xAB}, + "TLS_PSK_DHE_WITH_AES_256_CCM_8", + NULL, + "TLS_DHE_PSK_AES_256_CCM_8"}, + { {0xCC, 0xAD}, + "TLS_DHE_PSK_WITH_CHACHA20_POLY1305_SHA256", + "DHE-PSK-CHACHA20-POLY1305", + "TLS_DHE_PSK_CHACHA20_POLY1305"}, + { {0xCC, 0xAC}, + "TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256", + "ECDHE-PSK-CHACHA20-POLY1305", + "TLS_ECDHE_PSK_CHACHA20_POLY1305"}, + { {0xCC, 0xAE}, + "TLS_RSA_PSK_WITH_CHACHA20_POLY1305_SHA256", + "RSA-PSK-CHACHA20-POLY1305", + "TLS_RSA_PSK_CHACHA20_POLY1305"}, + { {0xCC, 0xAB}, + "TLS_PSK_WITH_CHACHA20_POLY1305_SHA256", + "PSK-CHACHA20-POLY1305", + "TLS_PSK_CHACHA20_POLY1305"}, + { {0x00, 0x18}, + "TLS_DH_anon_WITH_RC4_128_MD5", + NULL, + "TLS_DH_ANON_ARCFOUR_128_MD5"}, + { {0x00, 0x1B}, + "TLS_DH_anon_WITH_3DES_EDE_CBC_SHA", + NULL, + "TLS_DH_ANON_3DES_EDE_CBC_SHA1"}, + { {0x00, 0x34}, + "TLS_DH_anon_WITH_AES_128_CBC_SHA", + NULL, + "TLS_DH_ANON_AES_128_CBC_SHA1"}, + { {0x00, 0x3A}, + "TLS_DH_anon_WITH_AES_256_CBC_SHA", + NULL, + "TLS_DH_ANON_AES_256_CBC_SHA1"}, + { {0x00, 0xBF}, + "TLS_DH_anon_WITH_CAMELLIA_128_CBC_SHA256", + NULL, + "TLS_DH_ANON_CAMELLIA_128_CBC_SHA256"}, + { {0x00, 0xC5}, + "TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA256", + NULL, + "TLS_DH_ANON_CAMELLIA_256_CBC_SHA256"}, + { {0x00, 0x46}, + "TLS_DH_anon_WITH_CAMELLIA_128_CBC_SHA", + NULL, + "TLS_DH_ANON_CAMELLIA_128_CBC_SHA1"}, + { {0x00, 0x89}, + "TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA", + NULL, + "TLS_DH_ANON_CAMELLIA_256_CBC_SHA1"}, + { {0x00, 0x6C}, + "TLS_DH_anon_WITH_AES_128_CBC_SHA256", + NULL, + "TLS_DH_ANON_AES_128_CBC_SHA256"}, + { {0x00, 0x6D}, + "TLS_DH_anon_WITH_AES_256_CBC_SHA256", + NULL, + "TLS_DH_ANON_AES_256_CBC_SHA256"}, + { {0x00, 0xA6}, + "TLS_DH_anon_WITH_AES_128_GCM_SHA256", + NULL, + "TLS_DH_ANON_AES_128_GCM_SHA256"}, + { {0x00, 0xA7}, + "TLS_DH_anon_WITH_AES_256_GCM_SHA384", + NULL, + "TLS_DH_ANON_AES_256_GCM_SHA384"}, + { {0xC0, 0x84}, + "TLS_DH_anon_WITH_CAMELLIA_128_GCM_SHA256", + NULL, + "TLS_DH_ANON_CAMELLIA_128_GCM_SHA256"}, + { {0xC0, 0x85}, + "TLS_DH_anon_WITH_CAMELLIA_256_GCM_SHA384", + NULL, + "TLS_DH_ANON_CAMELLIA_256_GCM_SHA384"}, + { {0xC0, 0x15}, + "TLS_ECDH_anon_WITH_", + NULL, + "TLS_ECDH_ANON_NULL_SHA1"}, + { {0xC0, 0x17}, + "TLS_ECDH_anon_WITH_3DES_EDE_CBC_SHA", + NULL, + "TLS_ECDH_ANON_3DES_EDE_CBC_SHA1"}, + { {0xC0, 0x18}, + "TLS_ECDH_anon_WITH_AES_128_CBC_SHA", + NULL, + "TLS_ECDH_ANON_AES_128_CBC_SHA1"}, + { {0xC0, 0x19}, + "TLS_ECDH_anon_WITH_AES_256_CBC_SHA", + NULL, + "TLS_ECDH_ANON_AES_256_CBC_SHA1"}, + { {0xC0, 0x16}, + "TLS_ECDH_anon_WITH_RC4_128_SHA", + NULL, + "TLS_ECDH_ANON_ARCFOUR_128_SHA1"}, + { {0xC0, 0x1A}, + "TLS_SRP_SHA_WITH_3DES_EDE_CBC_SHA", + "SRP-3DES-EDE-CBC-SHA", + "TLS_SRP_SHA_3DES_EDE_CBC_SHA1"}, + { {0xC0, 0x1D}, + "TLS_SRP_SHA_WITH_AES_128_CBC_SHA", + "SRP-AES-128-CBC-SHA", + "TLS_SRP_SHA_AES_128_CBC_SHA1"}, + { {0xC0, 0x20}, + "TLS_SRP_SHA_WITH_AES_256_CBC_SHA", + "SRP-AES-256-CBC-SHA", + "TLS_SRP_SHA_AES_256_CBC_SHA1"}, + { {0xC0, 0x1C}, + "TLS_SRP_SHA_DSS_WITH_3DES_EDE_CBC_SHA", + NULL, + "TLS_SRP_SHA_DSS_3DES_EDE_CBC_SHA1"}, + { {0xC0, 0x1B}, + "TLS_SRP_SHA_RSA_WITH_3DES_EDE_CBC_SHA", + "SRP-RSA-3DES-EDE-CBC-SHA", + "TLS_SRP_SHA_RSA_3DES_EDE_CBC_SHA1"}, + { {0xC0, 0x1F}, + "TLS_SRP_SHA_DSS_WITH_AES_128_CBC_SHA", + NULL, + "TLS_SRP_SHA_DSS_AES_128_CBC_SHA1"}, + { {0xC0, 0x1E}, + "TLS_SRP_SHA_RSA_WITH_AES_128_CBC_SHA", + "SRP-RSA-AES-128-CBC-SHA", + "TLS_SRP_SHA_RSA_AES_128_CBC_SHA1"}, + { {0xC0, 0x22}, + "TLS_SRP_SHA_DSS_WITH_AES_256_CBC_SHA", + NULL, + "TLS_SRP_SHA_DSS_AES_256_CBC_SHA1"}, + { {0xC0, 0x21}, + "TLS_SRP_SHA_RSA_WITH_AES_256_CBC_SHA", + "SRP-RSA-AES-256-CBC-SHA", + "TLS_SRP_SHA_RSA_AES_256_CBC_SHA1"}, + { {0x00, 0x00}, + NULL, + NULL, + NULL} +}; + +/* free data assigned to the connection */ +static void free_gnutls_data(struct st_gnutls_data *data) +{ + if (data) + { + if (data->key) + gnutls_privkey_deinit(data->key); + gnutls_pcert_deinit(&data->cert); + free(data); + } +} + +/* map the gnutls cipher suite (defined by key exchange algorithm, cipher + and mac algorithm) to the corresponding OpenSSL cipher name */ +static const char *openssl_cipher_name(gnutls_kx_algorithm_t kx, + gnutls_cipher_algorithm_t cipher, + gnutls_mac_algorithm_t mac) +{ + unsigned int i=0; + const char *name= 0; + unsigned char sid[2]; + gnutls_kx_algorithm_t lkx; + gnutls_cipher_algorithm_t lcipher; + gnutls_mac_algorithm_t lmac; + + while ((name= gnutls_cipher_suite_info(i++, (unsigned char *)&sid, &lkx, &lcipher, &lmac, NULL))) + { + if (lkx == kx && + lcipher == cipher && + lmac == mac) + { + i=0; + while (tls_ciphers[i].iana_name) + { + if (!memcmp(tls_ciphers[i].sid, &sid, 2)) + { + if (tls_ciphers[i].openssl_name) + return tls_ciphers[i].openssl_name; + if (tls_ciphers[i].gnutls_name) + return tls_ciphers[i].gnutls_name; + return tls_ciphers[i].iana_name; + } + i++; + } + } + } + return NULL; +} + +/* get priority string for a given openssl cipher name */ +static char *get_priority(const char *cipher_name, char *priority, size_t len) +{ + unsigned int i= 0; + while (tls_ciphers[i].iana_name) + { + if (strcmp(tls_ciphers[i].iana_name, cipher_name) == 0 || + (tls_ciphers[i].openssl_name && + strcmp(tls_ciphers[i].openssl_name, cipher_name) == 0) || + (tls_ciphers[i].gnutls_name && + strcmp(tls_ciphers[i].gnutls_name, cipher_name) == 0)) + { + const char *name; + gnutls_kx_algorithm_t kx; + gnutls_cipher_algorithm_t cipher; + gnutls_mac_algorithm_t mac; + gnutls_protocol_t min_version; + unsigned j= 0; + + if (!tls_ciphers[i].gnutls_name) + return NULL; + + while ((name= gnutls_cipher_suite_info(j++, NULL, &kx, &cipher, + &mac, &min_version))) + { + if (!strcmp(name, tls_ciphers[i].gnutls_name)) + { + snprintf(priority, len - 1, ":+%s:+%s:+%s", + gnutls_cipher_get_name(cipher), + gnutls_mac_get_name(mac), + gnutls_kx_get_name(kx)); + return priority; + } + } + return NULL; + } + i++; + } + return NULL; +} + +#define MAX_SSL_ERR_LEN 100 + +static void ma_tls_set_error(MYSQL *mysql, void *ssl, int ssl_errno) +{ + char ssl_error[MAX_SSL_ERR_LEN]; + const char *ssl_error_reason; + MARIADB_PVIO *pvio= mysql->net.pvio; + + if (!ssl_errno) + { + pvio->set_error(mysql, CR_SSL_CONNECTION_ERROR, SQLSTATE_UNKNOWN, "Unknown SSL error"); + return; + } + + /* give a more descriptive error message for alerts */ + if (ssl_errno == GNUTLS_E_FATAL_ALERT_RECEIVED) + { + gnutls_alert_description_t alert_desc; + const char *alert_name; + alert_desc= gnutls_alert_get((gnutls_session_t)ssl); + alert_name= gnutls_alert_get_name(alert_desc); + snprintf(ssl_error, MAX_SSL_ERR_LEN, "fatal alert received: %s", + alert_name); + pvio->set_error(mysql, CR_SSL_CONNECTION_ERROR, SQLSTATE_UNKNOWN, 0, + ssl_error); + return; + } + + if ((ssl_error_reason= gnutls_strerror(ssl_errno))) + { + pvio->set_error(mysql, CR_SSL_CONNECTION_ERROR, SQLSTATE_UNKNOWN, 0, + ssl_error_reason); + return; + } + snprintf(ssl_error, MAX_SSL_ERR_LEN, "SSL errno=%d", ssl_errno); + pvio->set_error(mysql, CR_SSL_CONNECTION_ERROR, SQLSTATE_UNKNOWN, + ssl_error); +} + + +static void ma_tls_get_error(char *errmsg, size_t length, int ssl_errno) +{ + const char *ssl_error_reason; + + if (!ssl_errno) + { + strncpy(errmsg, "Unknown SSL error", length); + return; + } + if ((ssl_error_reason= gnutls_strerror(ssl_errno))) + { + strncpy(errmsg, ssl_error_reason, length); + return; + } + snprintf(errmsg, length, "SSL errno=%d", ssl_errno); +} + +/* + Initializes SSL and allocate global + context SSL_context + + SYNOPSIS + my_gnutls_start + mysql connection handle + + RETURN VALUES + 0 success + 1 error +*/ +int ma_tls_start(char *errmsg, size_t errmsg_len) +{ + int rc= 0; + + if (ma_tls_initialized) + return 0; + + pthread_mutex_init(&LOCK_gnutls_config,NULL); + pthread_mutex_lock(&LOCK_gnutls_config); + + if ((rc= gnutls_global_init()) != GNUTLS_E_SUCCESS) + { + ma_tls_get_error(errmsg, errmsg_len, rc); + goto end; + } + snprintf(tls_library_version, TLS_VERSION_LENGTH - 1, "GnuTLS %s", + gnutls_check_version(NULL)); + + ma_tls_initialized= TRUE; +end: + pthread_mutex_unlock(&LOCK_gnutls_config); + return rc; +} + +/* + Release SSL and free resources + Will be automatically executed by + mysql_server_end() function + + SYNOPSIS + my_gnutls_end() + void + + RETURN VALUES + void +*/ +void ma_tls_end() +{ + if (ma_tls_initialized) + { + pthread_mutex_lock(&LOCK_gnutls_config); + if (mariadb_deinitialize_ssl) + gnutls_global_deinit(); + ma_tls_initialized= FALSE; + pthread_mutex_unlock(&LOCK_gnutls_config); + pthread_mutex_destroy(&LOCK_gnutls_config); + } + return; +} + +static size_t ma_gnutls_get_protocol_version(const char *tls_version_option, + char *priority_string, + size_t prio_len) +{ + char tls_versions[128]; + + tls_versions[0]= 0; + if (!tls_version_option || !tls_version_option[0]) + goto end; + + + if (strstr(tls_version_option, "TLSv1.0")) + strcat(tls_versions, ":+VERS-TLS1.0"); + if (strstr(tls_version_option, "TLSv1.1")) + strcat(tls_versions, ":+VERS-TLS1.1"); + if (strstr(tls_version_option, "TLSv1.2")) + strcat(tls_versions, ":+VERS-TLS1.2"); +#if GNUTLS_VERSION_NUMBER > 0x030605 + if (strstr(tls_version_option, "TLSv1.3")) + strcat(tls_versions, ":+VERS-TLS1.3"); +#endif +end: + if (tls_versions[0]) + snprintf(priority_string, prio_len - 1, "-VERS-TLS-ALL%s:NORMAL", tls_versions); + else + strncpy(priority_string, "NORMAL:+VERS-ALL", prio_len - 1); + return strlen(priority_string); +} + +static int ma_gnutls_set_ciphers(gnutls_session_t ssl, + const char *cipher_str, + const char *tls_version) +{ + const char *err; + char *token; +#define PRIO_SIZE 1024 + char prio[PRIO_SIZE]; + + ma_gnutls_get_protocol_version(tls_version, prio, PRIO_SIZE); + + if (!cipher_str) + return gnutls_priority_set_direct(ssl, prio, &err); + + token= strtok((char *)cipher_str, ":"); + + strcpy(prio, "NONE:+VERS-TLS-ALL:+SIGN-ALL:+COMP-NULL:+CURVE-ALL"); + + while (token) + { + char priority[1024]; + char *p= get_priority(token, priority, 1024); + if (p) + strncat(prio, p, PRIO_SIZE - strlen(prio)); + token = strtok(NULL, ":"); + } + return gnutls_priority_set_direct(ssl, prio , &err); +} + +static int ma_tls_set_certs(MYSQL *mysql, + gnutls_certificate_credentials_t ctx) +{ + int ssl_error= 0; + + if (mysql->options.ssl_ca) + { + + ssl_error= gnutls_certificate_set_x509_trust_file(ctx, + mysql->options.ssl_ca, + GNUTLS_X509_FMT_PEM); + if (ssl_error < 0) + goto error; + } + + if (mysql->options.ssl_capath) + { + ssl_error= gnutls_certificate_set_x509_trust_dir(ctx, + mysql->options.ssl_capath, + GNUTLS_X509_FMT_PEM); + if (ssl_error < 0) + goto error; + } + + if (mysql->options.extension && mysql->options.extension->ssl_crl) + { + ssl_error= gnutls_certificate_set_x509_crl_file(ctx, + mysql->options.extension->ssl_crl, GNUTLS_X509_FMT_PEM); + if (ssl_error < 0) + goto error; + } + + if (!mysql->options.ssl_ca && !mysql->options.ssl_capath) + { + ssl_error= gnutls_certificate_set_x509_system_trust(ctx); + if (ssl_error < 0) + goto error; + } + + gnutls_certificate_set_verify_function(ctx, + my_verify_callback); + + if (mysql->options.ssl_key || mysql->options.ssl_cert) + { + char *keyfile= mysql->options.ssl_key; + char *certfile= mysql->options.ssl_cert; + + if (!certfile) + certfile= keyfile; + else if (!keyfile) + keyfile= certfile; + + /* load cert/key into context */ + if ((ssl_error= gnutls_certificate_set_x509_key_file2(ctx, + certfile, keyfile, GNUTLS_X509_FMT_PEM, + mysql->options.extension ? mysql->options.extension->tls_pw : NULL, 0)) < 0) + goto error; + } + +error: + return ssl_error; +} + +void *ma_tls_init(MYSQL *mysql) +{ + gnutls_session_t ssl= NULL; + gnutls_certificate_credentials_t ctx; + int ssl_error= 0; + struct st_gnutls_data *data= NULL; + + pthread_mutex_lock(&LOCK_gnutls_config); + + if (gnutls_certificate_allocate_credentials(&ctx) != GNUTLS_E_SUCCESS) + goto error; + + if ((ssl_error= ma_tls_set_certs(mysql, ctx)) < 0) + goto error; + + if ((ssl_error = gnutls_init(&ssl, GNUTLS_CLIENT & GNUTLS_NONBLOCK)) < 0) + goto error; + + if (!(data= (struct st_gnutls_data *)calloc(1, sizeof(struct st_gnutls_data)))) + goto error; + + data->mysql= mysql; + gnutls_session_set_ptr(ssl, (void *)data); + + ssl_error= ma_gnutls_set_ciphers(ssl, mysql->options.ssl_cipher, mysql->options.extension ? mysql->options.extension->tls_version : NULL); + if (ssl_error < 0) + goto error; + + /* we don't load private key and cert by default - if the server requests + a client certificate we will send it via callback function */ + if ((ssl_error= gnutls_credentials_set(ssl, GNUTLS_CRD_CERTIFICATE, ctx)) < 0) + goto error; + + pthread_mutex_unlock(&LOCK_gnutls_config); + return (void *)ssl; +error: + free_gnutls_data(data); + ma_tls_set_error(mysql, ssl, ssl_error); + gnutls_certificate_free_credentials(ctx); + if (ssl) + gnutls_deinit(ssl); + pthread_mutex_unlock(&LOCK_gnutls_config); + return NULL; +} + +#ifdef GNUTLS_EXTERNAL_TRANSPORT +ssize_t ma_tls_push(gnutls_transport_ptr_t ptr, const void* data, size_t len) +{ + MARIADB_PVIO *pvio= (MARIADB_PVIO *)ptr; + ssize_t rc= pvio->methods->write(pvio, data, len); + return rc; +} + +ssize_t ma_tls_pull(gnutls_transport_ptr_t ptr, void* data, size_t len) +{ + MARIADB_PVIO *pvio= (MARIADB_PVIO *)ptr; + ssize_t rc= pvio->methods->read(pvio, data, len); + return rc; +} + +static int ma_tls_pull_timeout(gnutls_transport_ptr_t ptr, unsigned int ms) +{ + MARIADB_PVIO *pvio= (MARIADB_PVIO *)ptr; + return pvio->methods->wait_io_or_timeout(pvio, 0, ms); +} +#endif + +my_bool ma_tls_connect(MARIADB_TLS *ctls) +{ + gnutls_session_t ssl = (gnutls_session_t)ctls->ssl; + my_bool blocking; + MYSQL *mysql; + MARIADB_PVIO *pvio; + int ret; + struct st_gnutls_data *data; + data= (struct st_gnutls_data *)gnutls_session_get_ptr(ssl); + mysql= data->mysql; + + if (!mysql) + return 1; + + pvio= mysql->net.pvio; + + /* Set socket to blocking if not already set */ + if (!(blocking= pvio->methods->is_blocking(pvio))) + pvio->methods->blocking(pvio, TRUE, 0); + + +#ifdef GNUTLS_EXTERNAL_TRANSPORT + /* we don't use GnuTLS read/write functions */ + gnutls_transport_set_ptr(ssl, pvio); + gnutls_transport_set_push_function(ssl, ma_tls_push); + gnutls_transport_set_pull_function(ssl, ma_tls_pull); + gnutls_transport_set_pull_timeout_function(ssl, ma_tls_pull_timeout); + gnutls_handshake_set_timeout(ssl, pvio->timeout[PVIO_CONNECT_TIMEOUT]); +#else + gnutls_transport_set_int(ssl, mysql_get_socket(mysql)); +#endif + + do { + ret = gnutls_handshake(ssl); + } while (ret < 0 && gnutls_error_is_fatal(ret) == 0); + + if (ret < 0) + { + /* If error message was not set while calling certification callback function, + use default error message (which is not very descriptive */ + if (!mysql_errno(mysql)) + ma_tls_set_error(mysql, ssl, ret); + + ma_tls_close(ctls); + + /* restore blocking mode */ + if (!blocking) + pvio->methods->blocking(pvio, FALSE, 0); + return 1; + } + ctls->ssl= (void *)ssl; + return 0; +} + +ssize_t ma_tls_write_async(MARIADB_PVIO *pvio, const uchar *buffer, size_t length) +{ + ssize_t res; + struct mysql_async_context *b= pvio->mysql->options.extension->async_context; + MARIADB_TLS *ctls= pvio->ctls; + + for (;;) + { + b->events_to_wait_for= 0; + res= gnutls_record_send((gnutls_session_t)ctls->ssl, (void *)buffer, length); + if (res > 0) + return res; + if (res == GNUTLS_E_AGAIN) + b->events_to_wait_for|= MYSQL_WAIT_WRITE; + else + return res; + if (b->suspend_resume_hook) + (*b->suspend_resume_hook)(TRUE, b->suspend_resume_hook_user_data); + my_context_yield(&b->async_context); + if (b->suspend_resume_hook) + (*b->suspend_resume_hook)(FALSE, b->suspend_resume_hook_user_data); + } +} + + +ssize_t ma_tls_read_async(MARIADB_PVIO *pvio, const uchar *buffer, size_t length) +{ + ssize_t res; + struct mysql_async_context *b= pvio->mysql->options.extension->async_context; + MARIADB_TLS *ctls= pvio->ctls; + + for (;;) + { + b->events_to_wait_for= 0; + res= gnutls_record_recv((gnutls_session_t)ctls->ssl, (void *)buffer, length); + if (res > 0) + return res; + if (res == GNUTLS_E_AGAIN) + b->events_to_wait_for|= MYSQL_WAIT_READ; + else + return res; + if (b->suspend_resume_hook) + (*b->suspend_resume_hook)(TRUE, b->suspend_resume_hook_user_data); + my_context_yield(&b->async_context); + if (b->suspend_resume_hook) + (*b->suspend_resume_hook)(FALSE, b->suspend_resume_hook_user_data); + } +} + +ssize_t ma_tls_read(MARIADB_TLS *ctls, const uchar* buffer, size_t length) +{ + ssize_t rc; + MARIADB_PVIO *pvio= ctls->pvio; + + while ((rc= gnutls_record_recv((gnutls_session_t)ctls->ssl, (void *)buffer, length)) <= 0) + { + if (rc != GNUTLS_E_AGAIN && rc != GNUTLS_E_INTERRUPTED) + return rc; + if (pvio->methods->wait_io_or_timeout(pvio, TRUE, pvio->mysql->options.read_timeout) < 1) + return rc; + } + return rc; +} + +ssize_t ma_tls_write(MARIADB_TLS *ctls, const uchar* buffer, size_t length) +{ + ssize_t rc; + MARIADB_PVIO *pvio= ctls->pvio; + + while ((rc= gnutls_record_send((gnutls_session_t)ctls->ssl, (void *)buffer, length)) <= 0) + { + if (rc != GNUTLS_E_AGAIN && rc != GNUTLS_E_INTERRUPTED) + return rc; + if (pvio->methods->wait_io_or_timeout(pvio, TRUE, pvio->mysql->options.write_timeout) < 1) + return rc; + } + return rc; +} + +my_bool ma_tls_close(MARIADB_TLS *ctls) +{ + if (ctls->ssl) + { + gnutls_certificate_credentials_t ctx; + struct st_gnutls_data *data= + (struct st_gnutls_data *)gnutls_session_get_ptr(ctls->ssl); + /* this would be the correct way, however can't detect afterwards + if the socket is closed or not, so we don't send encrypted + finish alert. + rc= gnutls_bye((gnutls_session_t )ctls->ssl, GNUTLS_SHUT_WR); + */ + free_gnutls_data(data); + gnutls_credentials_get(ctls->ssl, GNUTLS_CRD_CERTIFICATE, (void **)&ctx); + gnutls_certificate_free_keys(ctx); + gnutls_certificate_free_cas(ctx); + gnutls_certificate_free_crls(ctx); + gnutls_certificate_free_ca_names(ctx); + gnutls_certificate_free_credentials(ctx); + gnutls_deinit((gnutls_session_t )ctls->ssl); + ctls->ssl= NULL; + } + return 0; +} + +int ma_tls_verify_server_cert(MARIADB_TLS *ctls __attribute__((unused))) +{ + /* server verification is already handled before during handshake */ + return 0; +} + +const char *ma_tls_get_cipher(MARIADB_TLS *ctls) +{ + gnutls_kx_algorithm_t kx; + gnutls_cipher_algorithm_t cipher; + gnutls_mac_algorithm_t mac; + + if (!ctls || !ctls->ssl) + return NULL; + + mac= gnutls_mac_get((gnutls_session_t)ctls->ssl); + cipher= gnutls_cipher_get((gnutls_session_t)ctls->ssl); + kx= gnutls_kx_get((gnutls_session_t)ctls->ssl); + return openssl_cipher_name(kx, cipher, mac); +} + +static int my_verify_callback(gnutls_session_t ssl) +{ + unsigned int status= 0; + struct st_gnutls_data *data= (struct st_gnutls_data *)gnutls_session_get_ptr(ssl); + MYSQL *mysql; + + mysql= data->mysql; + + CLEAR_CLIENT_ERROR(mysql); + + if ((mysql->client_flag & CLIENT_SSL_VERIFY_SERVER_CERT)) + { + const char *hostname= mysql->host; + + if (gnutls_certificate_verify_peers3 (ssl, hostname, &status) < 0) + return GNUTLS_E_CERTIFICATE_ERROR; + } else { + if (gnutls_certificate_verify_peers2 (ssl, &status) < 0) + return GNUTLS_E_CERTIFICATE_ERROR; + } + if (status & GNUTLS_CERT_INVALID) + { + gnutls_datum_t out; + int type; + /* accept self signed certificates if we don't have to verify server cert */ + if (!(mysql->client_flag & CLIENT_SSL_VERIFY_SERVER_CERT) && + (status & GNUTLS_CERT_SIGNER_NOT_FOUND)) + return 0; + + /* gnutls default error message "certificate validation failed" isn't very + descriptive, so we provide more information about the error here */ + type= gnutls_certificate_type_get(ssl); + gnutls_certificate_verification_status_print(status, type, &out, 0); + my_set_error(mysql, CR_SSL_CONNECTION_ERROR, SQLSTATE_UNKNOWN, + ER(CR_SSL_CONNECTION_ERROR), out.data); + gnutls_free(out.data); + + return GNUTLS_E_CERTIFICATE_ERROR; + } + + + return 0; +} + +unsigned int ma_tls_get_finger_print(MARIADB_TLS *ctls, char *fp, unsigned int len) +{ + MYSQL *mysql; + size_t fp_len= len; + const gnutls_datum_t *cert_list; + unsigned int cert_list_size; + struct st_gnutls_data *data; + + if (!ctls || !ctls->ssl) + return 0; + + data= (struct st_gnutls_data *)gnutls_session_get_ptr(ctls->ssl); + mysql= (MYSQL *)data->mysql; + + cert_list = gnutls_certificate_get_peers (ctls->ssl, &cert_list_size); + if (cert_list == NULL) + { + my_set_error(mysql, CR_SSL_CONNECTION_ERROR, SQLSTATE_UNKNOWN, + ER(CR_SSL_CONNECTION_ERROR), + "Unable to get server certificate"); + return 0; + } + + if (gnutls_fingerprint(GNUTLS_DIG_SHA1, &cert_list[0], fp, &fp_len) == 0) + return fp_len; + else + { + my_set_error(mysql, CR_SSL_CONNECTION_ERROR, SQLSTATE_UNKNOWN, + ER(CR_SSL_CONNECTION_ERROR), + "Finger print buffer too small"); + return 0; + } +} + +int ma_tls_get_protocol_version(MARIADB_TLS *ctls) +{ + if (!ctls || !ctls->ssl) + return 1; + + return gnutls_protocol_get_version(ctls->ssl) - 1; +} +#endif /* HAVE_GNUTLS */ diff --git a/vendor/MDBC/libmariadb/secure/gnutls_crypt.c b/vendor/MDBC/libmariadb/secure/gnutls_crypt.c new file mode 100644 index 00000000..0d3712f7 --- /dev/null +++ b/vendor/MDBC/libmariadb/secure/gnutls_crypt.c @@ -0,0 +1,77 @@ +/* + Copyright (C) 2018 MariaDB Corporation AB + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not see + or write to the Free Software Foundation, Inc., + 51 Franklin St., Fifth Floor, Boston, MA 02110, USA +*/ +#include +#include +#include + +static gnutls_digest_algorithm_t ma_hash_get_algorithm(unsigned int alg) +{ + switch(alg) + { + case MA_HASH_MD5: + return GNUTLS_DIG_MD5; + case MA_HASH_SHA1: + return GNUTLS_DIG_SHA1; + case MA_HASH_SHA256: + return GNUTLS_DIG_SHA256; + case MA_HASH_SHA384: + return GNUTLS_DIG_SHA384; + case MA_HASH_SHA512: + return GNUTLS_DIG_SHA512; + case MA_HASH_RIPEMD160: + return GNUTLS_DIG_RMD160; + default: + return GNUTLS_DIG_UNKNOWN; + } +} + +MA_HASH_CTX *ma_hash_new(unsigned int algorithm, MA_HASH_CTX *unused_ctx __attribute__((unused))) +{ + gnutls_hash_hd_t ctx= NULL; + gnutls_digest_algorithm_t hash_alg= ma_hash_get_algorithm(algorithm); + + /* unknown or unsupported hash algorithm */ + if (hash_alg == GNUTLS_DIG_UNKNOWN) + return NULL; + + if (gnutls_hash_init(&ctx, hash_alg) < 0) + return NULL; + + return (MA_HASH_CTX *)ctx; +} + +void ma_hash_free(MA_HASH_CTX *ctx) +{ + if (ctx) + gnutls_hash_deinit((gnutls_hash_hd_t)ctx, NULL); +} + +void ma_hash_input(MA_HASH_CTX *ctx, + const unsigned char *buffer, + size_t len) +{ + gnutls_hash((gnutls_hash_hd_t)ctx, (const void *)buffer, len); +} + +void ma_hash_result(MA_HASH_CTX *ctx, unsigned char *digest) +{ + gnutls_hash_output((gnutls_hash_hd_t)ctx, digest); +} + + diff --git a/vendor/MDBC/libmariadb/secure/ma_schannel.c b/vendor/MDBC/libmariadb/secure/ma_schannel.c new file mode 100644 index 00000000..e989aeaa --- /dev/null +++ b/vendor/MDBC/libmariadb/secure/ma_schannel.c @@ -0,0 +1,637 @@ +/************************************************************************************ + Copyright (C) 2014 MariaDB Corporation Ab + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not see + or write to the Free Software Foundation, Inc., + 51 Franklin St., Fifth Floor, Boston, MA 02110, USA + + Author: Georg Richter + + *************************************************************************************/ +#include "ma_schannel.h" +#include "schannel_certs.h" +#include + +#define SC_IO_BUFFER_SIZE 0x4000 +#define MAX_SSL_ERR_LEN 100 + +#define SCHANNEL_PAYLOAD(A) ((A).cbMaximumMessage + (A).cbHeader + (A).cbTrailer) +void ma_schannel_set_win_error(MARIADB_PVIO *pvio, DWORD ErrorNo); + + + + +/* {{{ void ma_schannel_set_sec_error */ +void ma_schannel_set_sec_error(MARIADB_PVIO* pvio, DWORD ErrorNo) +{ + MYSQL* mysql = pvio->mysql; + if (ErrorNo != SEC_E_OK) + mysql->net.extension->extended_errno = ErrorNo; + if (ErrorNo == SEC_E_INTERNAL_ERROR && GetLastError()) + { + ma_schannel_set_win_error(pvio, GetLastError()); + return; + } + ma_schannel_set_win_error(pvio, ErrorNo); +} +/* }}} */ + +#include "win32_errmsg.h" +/* {{{ void ma_schnnel_set_win_error */ +void ma_schannel_set_win_error(MARIADB_PVIO *pvio, DWORD ErrorNo) +{ + char buffer[256]; + ma_format_win32_error(buffer, sizeof(buffer), ErrorNo, "SSL connection error: "); + pvio->set_error(pvio->mysql, CR_SSL_CONNECTION_ERROR, SQLSTATE_UNKNOWN, buffer); + return; +} +/* }}} */ + + +/* }}} */ + +/* {{{ SECURITY_STATUS ma_schannel_handshake_loop(MARIADB_PVIO *pvio, my_bool InitialRead, SecBuffer *pExtraData) */ +/* + perform handshake loop + + SYNOPSIS + ma_schannel_handshake_loop() + pvio Pointer to an Communication/IO structure + InitialRead TRUE if it's the very first read + ExtraData Pointer to an SecBuffer which contains extra data (sent by application) + + +*/ + +SECURITY_STATUS ma_schannel_handshake_loop(MARIADB_PVIO *pvio, my_bool InitialRead, SecBuffer *pExtraData) +{ + SecBufferDesc OutBuffer, InBuffer; + SecBuffer InBuffers[2], OutBuffers; + DWORD dwSSPIFlags, dwSSPIOutFlags, cbData, cbIoBuffer; + TimeStamp tsExpiry; + SECURITY_STATUS rc; + PUCHAR IoBuffer; + BOOL fDoRead; + MARIADB_TLS *ctls= pvio->ctls; + SC_CTX *sctx= (SC_CTX *)ctls->ssl; + + + dwSSPIFlags = ISC_REQ_SEQUENCE_DETECT | + ISC_REQ_REPLAY_DETECT | + ISC_REQ_CONFIDENTIALITY | + ISC_RET_EXTENDED_ERROR | + ISC_REQ_ALLOCATE_MEMORY | + ISC_REQ_STREAM; + + + /* Allocate data buffer */ + if (!(IoBuffer = LocalAlloc(LMEM_FIXED, SC_IO_BUFFER_SIZE))) + return SEC_E_INSUFFICIENT_MEMORY; + + cbIoBuffer = 0; + fDoRead = InitialRead; + + /* handshake loop: We will leave if handshake is finished + or an error occurs */ + + rc = SEC_I_CONTINUE_NEEDED; + + while (rc == SEC_I_CONTINUE_NEEDED || + rc == SEC_E_INCOMPLETE_MESSAGE || + rc == SEC_I_INCOMPLETE_CREDENTIALS ) + { + /* Read data */ + if (rc == SEC_E_INCOMPLETE_MESSAGE || + !cbIoBuffer) + { + if(fDoRead) + { + ssize_t nbytes = pvio->methods->read(pvio, IoBuffer + cbIoBuffer, (size_t)(SC_IO_BUFFER_SIZE - cbIoBuffer)); + if (nbytes <= 0) + { + rc = SEC_E_INTERNAL_ERROR; + break; + } + cbData = (DWORD)nbytes; + cbIoBuffer += cbData; + } + else + fDoRead = TRUE; + } + + /* input buffers + First buffer stores data received from server. leftover data + will be stored in second buffer with BufferType SECBUFFER_EXTRA */ + + InBuffers[0].pvBuffer = IoBuffer; + InBuffers[0].cbBuffer = cbIoBuffer; + InBuffers[0].BufferType = SECBUFFER_TOKEN; + + InBuffers[1].pvBuffer = NULL; + InBuffers[1].cbBuffer = 0; + InBuffers[1].BufferType = SECBUFFER_EMPTY; + + InBuffer.cBuffers = 2; + InBuffer.pBuffers = InBuffers; + InBuffer.ulVersion = SECBUFFER_VERSION; + + + /* output buffer */ + OutBuffers.pvBuffer = NULL; + OutBuffers.BufferType= SECBUFFER_TOKEN; + OutBuffers.cbBuffer = 0; + + OutBuffer.cBuffers = 1; + OutBuffer.pBuffers = &OutBuffers; + OutBuffer.ulVersion = SECBUFFER_VERSION; + + + rc = InitializeSecurityContextA(&sctx->CredHdl, + &sctx->hCtxt, + NULL, + dwSSPIFlags, + 0, + SECURITY_NATIVE_DREP, + &InBuffer, + 0, + NULL, + &OutBuffer, + &dwSSPIOutFlags, + &tsExpiry ); + + + if (rc == SEC_E_OK || + rc == SEC_I_CONTINUE_NEEDED || + (FAILED(rc) && (dwSSPIOutFlags & ISC_RET_EXTENDED_ERROR))) + { + if(OutBuffers.cbBuffer && OutBuffers.pvBuffer) + { + ssize_t nbytes = pvio->methods->write(pvio, (uchar *)OutBuffers.pvBuffer, (size_t)OutBuffers.cbBuffer); + if(nbytes <= 0) + { + FreeContextBuffer(OutBuffers.pvBuffer); + DeleteSecurityContext(&sctx->hCtxt); + return SEC_E_INTERNAL_ERROR; + } + cbData= (DWORD)nbytes; + /* Free output context buffer */ + FreeContextBuffer(OutBuffers.pvBuffer); + OutBuffers.pvBuffer = NULL; + } + } + /* check if we need to read more data */ + switch (rc) { + case SEC_E_INCOMPLETE_MESSAGE: + /* we didn't receive all data, so just continue loop */ + continue; + break; + case SEC_E_OK: + /* handshake completed, but we need to check if extra + data was sent (which contains encrypted application data) */ + if (InBuffers[1].BufferType == SECBUFFER_EXTRA) + { + if (!(pExtraData->pvBuffer= LocalAlloc(0, InBuffers[1].cbBuffer))) + return SEC_E_INSUFFICIENT_MEMORY; + + MoveMemory(pExtraData->pvBuffer, IoBuffer + (cbIoBuffer - InBuffers[1].cbBuffer), InBuffers[1].cbBuffer ); + pExtraData->BufferType = SECBUFFER_TOKEN; + pExtraData->cbBuffer = InBuffers[1].cbBuffer; + } + else + { + pExtraData->BufferType= SECBUFFER_EMPTY; + pExtraData->pvBuffer= NULL; + pExtraData->cbBuffer= 0; + } + break; + + case SEC_I_INCOMPLETE_CREDENTIALS: + /* Provided credentials didn't contain a valid client certificate. + We will try to connect anonymously, using current credentials */ + fDoRead= FALSE; + rc= SEC_I_CONTINUE_NEEDED; + continue; + break; + default: + if (FAILED(rc)) + { + goto loopend; + } + break; + } + + if ( InBuffers[1].BufferType == SECBUFFER_EXTRA ) + { + MoveMemory( IoBuffer, IoBuffer + (cbIoBuffer - InBuffers[1].cbBuffer), InBuffers[1].cbBuffer ); + cbIoBuffer = InBuffers[1].cbBuffer; + } + else + cbIoBuffer = 0; + } +loopend: + if (FAILED(rc)) + { + ma_schannel_set_sec_error(pvio, rc); + DeleteSecurityContext(&sctx->hCtxt); + } + LocalFree(IoBuffer); + + return rc; +} +/* }}} */ + +/* {{{ SECURITY_STATUS ma_schannel_client_handshake(MARIADB_TLS *ctls) */ +/* + performs client side handshake + + SYNOPSIS + ma_schannel_client_handshake() + ctls Pointer to a MARIADB_TLS structure + + DESCRIPTION + initiates a client/server handshake. This function can be used + by clients only + + RETURN + SEC_E_OK on success +*/ + +SECURITY_STATUS ma_schannel_client_handshake(MARIADB_TLS *ctls) +{ + MARIADB_PVIO *pvio; + SECURITY_STATUS sRet; + DWORD OutFlags; + DWORD r; + SC_CTX *sctx; + SecBuffer ExtraData; + DWORD SFlags= ISC_REQ_SEQUENCE_DETECT | ISC_REQ_REPLAY_DETECT | + ISC_REQ_CONFIDENTIALITY | ISC_RET_EXTENDED_ERROR | + ISC_REQ_USE_SUPPLIED_CREDS | + ISC_REQ_ALLOCATE_MEMORY | ISC_REQ_STREAM; + + SecBufferDesc BufferOut; + SecBuffer BuffersOut; + + if (!ctls || !ctls->pvio) + return 1; + + pvio= ctls->pvio; + sctx= (SC_CTX *)ctls->ssl; + + /* Initialie securifty context */ + BuffersOut.BufferType= SECBUFFER_TOKEN; + BuffersOut.cbBuffer= 0; + BuffersOut.pvBuffer= NULL; + + + BufferOut.cBuffers= 1; + BufferOut.pBuffers= &BuffersOut; + BufferOut.ulVersion= SECBUFFER_VERSION; + + sRet = InitializeSecurityContext(&sctx->CredHdl, + NULL, + pvio->mysql->host, + SFlags, + 0, + SECURITY_NATIVE_DREP, + NULL, + 0, + &sctx->hCtxt, + &BufferOut, + &OutFlags, + NULL); + + if(sRet != SEC_I_CONTINUE_NEEDED) + { + ma_schannel_set_sec_error(pvio, sRet); + return sRet; + } + + /* send client hello packaet */ + if(BuffersOut.cbBuffer != 0 && BuffersOut.pvBuffer != NULL) + { + ssize_t nbytes = (DWORD)pvio->methods->write(pvio, (uchar *)BuffersOut.pvBuffer, (size_t)BuffersOut.cbBuffer); + + if (nbytes <= 0) + { + sRet= SEC_E_INTERNAL_ERROR; + goto end; + } + r = (DWORD)nbytes; + } + sRet= ma_schannel_handshake_loop(pvio, TRUE, &ExtraData); + + /* allocate IO-Buffer for write operations: After handshake + was successful, we are able now to calculate payload */ + if ((sRet = QueryContextAttributes(&sctx->hCtxt, SECPKG_ATTR_STREAM_SIZES, &sctx->Sizes ))) + goto end; + + sctx->IoBufferSize= SCHANNEL_PAYLOAD(sctx->Sizes); + if (!(sctx->IoBuffer= (PUCHAR)LocalAlloc(0, sctx->IoBufferSize))) + { + sRet= SEC_E_INSUFFICIENT_MEMORY; + goto end; + } + + return sRet; +end: + if (BuffersOut.pvBuffer) + FreeContextBuffer(BuffersOut.pvBuffer); + return sRet; +} +/* }}} */ + +/* {{{ SECURITY_STATUS ma_schannel_read_decrypt(MARIADB_PVIO *pvio, PCredHandle phCreds, CtxtHandle * phContext, + DWORD DecryptLength, uchar *ReadBuffer, DWORD ReadBufferSize) */ +/* + Reads encrypted data from a SSL stream and decrypts it. + + SYNOPSIS + ma_schannel_read + pvio pointer to Communication IO structure + phContext a context handle + DecryptLength size of decrypted buffer + ReadBuffer Buffer for decrypted data + ReadBufferSize size of ReadBuffer + + + DESCRIPTION + Reads decrypted data from a SSL stream and encrypts it. + + RETURN + SEC_E_OK on success + SEC_E_* if an error occurred +*/ + +SECURITY_STATUS ma_schannel_read_decrypt(MARIADB_PVIO *pvio, + CtxtHandle * phContext, + DWORD *DecryptLength, + uchar *ReadBuffer, + DWORD ReadBufferSize) +{ + ssize_t nbytes = 0; + DWORD dwOffset = 0; + SC_CTX *sctx; + SECURITY_STATUS sRet = 0; + SecBufferDesc Msg; + SecBuffer Buffers[4]; + int i; + + if (!pvio || !pvio->methods || !pvio->methods->read || !pvio->ctls || !DecryptLength) + return SEC_E_INTERNAL_ERROR; + + sctx = (SC_CTX *)pvio->ctls->ssl; + *DecryptLength = 0; + + if (sctx->dataBuf.cbBuffer) + { + /* Have unread decrypted data from the last time, copy. */ + nbytes = MIN(ReadBufferSize, sctx->dataBuf.cbBuffer); + memcpy(ReadBuffer, sctx->dataBuf.pvBuffer, nbytes); + sctx->dataBuf.pvBuffer = (char *)(sctx->dataBuf.pvBuffer) + nbytes; + sctx->dataBuf.cbBuffer -= (DWORD)nbytes; + *DecryptLength = (DWORD)nbytes; + return SEC_E_OK; + } + + + while (1) + { + /* Check for any encrypted data returned by last DecryptMessage() in SECBUFFER_EXTRA buffer. */ + if (sctx->extraBuf.cbBuffer) + { + memmove(sctx->IoBuffer, sctx->extraBuf.pvBuffer, sctx->extraBuf.cbBuffer); + dwOffset = sctx->extraBuf.cbBuffer; + sctx->extraBuf.cbBuffer = 0; + } + + do { + assert(sctx->IoBufferSize > dwOffset); + if (dwOffset == 0 || sRet == SEC_E_INCOMPLETE_MESSAGE) + { + nbytes = pvio->methods->read(pvio, sctx->IoBuffer + dwOffset, (size_t)(sctx->IoBufferSize - dwOffset)); + if (nbytes <= 0) + { + /* server closed connection, or an error */ + // todo: error + return SEC_E_INVALID_HANDLE; + } + dwOffset += (DWORD)nbytes; + } + ZeroMemory(Buffers, sizeof(SecBuffer) * 4); + Buffers[0].pvBuffer = sctx->IoBuffer; + Buffers[0].cbBuffer = dwOffset; + + Buffers[0].BufferType = SECBUFFER_DATA; + Buffers[1].BufferType = SECBUFFER_EMPTY; + Buffers[2].BufferType = SECBUFFER_EMPTY; + Buffers[3].BufferType = SECBUFFER_EMPTY; + + Msg.ulVersion = SECBUFFER_VERSION; // Version number + Msg.cBuffers = 4; + Msg.pBuffers = Buffers; + + sRet = DecryptMessage(phContext, &Msg, 0, NULL); + + } while (sRet == SEC_E_INCOMPLETE_MESSAGE); /* Continue reading until full message arrives */ + + + if (sRet != SEC_E_OK) + { + ma_schannel_set_sec_error(pvio, sRet); + return sRet; + } + + sctx->extraBuf.cbBuffer = 0; + sctx->dataBuf.cbBuffer = 0; + for (i = 0; i < 4; i++) + { + if (Buffers[i].BufferType == SECBUFFER_DATA) + sctx->dataBuf = Buffers[i]; + if (Buffers[i].BufferType == SECBUFFER_EXTRA) + sctx->extraBuf = Buffers[i]; + } + + + if (sctx->dataBuf.cbBuffer) + { + assert(sctx->dataBuf.pvBuffer); + /* + Copy at most ReadBufferSize bytes to output. + Store the rest (if any) to be processed next time. + */ + nbytes = MIN(sctx->dataBuf.cbBuffer, ReadBufferSize); + memcpy((char *)ReadBuffer, sctx->dataBuf.pvBuffer, nbytes); + sctx->dataBuf.cbBuffer -= (unsigned long)nbytes; + sctx->dataBuf.pvBuffer = (char *)sctx->dataBuf.pvBuffer + nbytes; + + *DecryptLength = (DWORD)nbytes; + return SEC_E_OK; + } + // No data buffer, loop + } +} +/* }}} */ +#include "win32_errmsg.h" +my_bool ma_schannel_verify_certs(MARIADB_TLS *ctls, BOOL verify_server_name) +{ + SECURITY_STATUS status; + + MARIADB_PVIO *pvio= ctls->pvio; + MYSQL *mysql= pvio->mysql; + SC_CTX *sctx = (SC_CTX *)ctls->ssl; + const char *ca_file= mysql->options.ssl_ca; + const char* ca_path = mysql->options.ssl_capath; + const char *crl_file= mysql->options.extension ? mysql->options.extension->ssl_crl : NULL; + const char* crl_path = mysql->options.extension ? mysql->options.extension->ssl_crlpath : NULL; + PCCERT_CONTEXT pServerCert= NULL; + char errmsg[256]; + HCERTSTORE store= NULL; + int ret= 0; + + status = schannel_create_store(ca_file, ca_path, crl_file, crl_path, &store, errmsg, sizeof(errmsg)); + if(status) + goto end; + + status = QueryContextAttributesA(&sctx->hCtxt, SECPKG_ATTR_REMOTE_CERT_CONTEXT, (PVOID)&pServerCert); + if (status) + { + ma_format_win32_error(errmsg, sizeof(errmsg), GetLastError(), + "QueryContextAttributes(SECPKG_ATTR_REMOTE_CERT_CONTEXT) failed."); + goto end; + } + + status = schannel_verify_server_certificate( + pServerCert, + store, + crl_file != 0 || crl_path != 0, + mysql->host, + verify_server_name, + errmsg, sizeof(errmsg)); + + if (status) + goto end; + + ret= 1; + +end: + if (!ret) + { + pvio->set_error(mysql, CR_SSL_CONNECTION_ERROR, SQLSTATE_UNKNOWN, + "SSL connection error: %s", errmsg); + } + if (pServerCert) + CertFreeCertificateContext(pServerCert); + if(store) + schannel_free_store(store); + return ret; +} + + +/* {{{ size_t ma_schannel_write_encrypt(MARIADB_PVIO *pvio, PCredHandle phCreds, CtxtHandle * phContext) */ +/* + Decrypts data and write to SSL stream + SYNOPSIS + ma_schannel_write_decrypt + pvio pointer to Communication IO structure + phContext a context handle + DecryptLength size of decrypted buffer + ReadBuffer Buffer for decrypted data + ReadBufferSize size of ReadBuffer + + DESCRIPTION + Write encrypted data to SSL stream. + + RETURN + SEC_E_OK on success + SEC_E_* if an error occurred +*/ +ssize_t ma_schannel_write_encrypt(MARIADB_PVIO *pvio, + uchar *WriteBuffer, + size_t WriteBufferSize) +{ + SECURITY_STATUS scRet; + SecBufferDesc Message; + SecBuffer Buffers[4]; + DWORD cbMessage; + PBYTE pbMessage; + SC_CTX *sctx= (SC_CTX *)pvio->ctls->ssl; + size_t payload; + ssize_t nbytes; + DWORD write_size; + + payload= MIN(WriteBufferSize, sctx->Sizes.cbMaximumMessage); + + memcpy(&sctx->IoBuffer[sctx->Sizes.cbHeader], WriteBuffer, payload); + pbMessage = sctx->IoBuffer + sctx->Sizes.cbHeader; + cbMessage = (DWORD)payload; + + Buffers[0].pvBuffer = sctx->IoBuffer; + Buffers[0].cbBuffer = sctx->Sizes.cbHeader; + Buffers[0].BufferType = SECBUFFER_STREAM_HEADER; // Type of the buffer + + Buffers[1].pvBuffer = &sctx->IoBuffer[sctx->Sizes.cbHeader]; + Buffers[1].cbBuffer = (DWORD)payload; + Buffers[1].BufferType = SECBUFFER_DATA; + + Buffers[2].pvBuffer = &sctx->IoBuffer[sctx->Sizes.cbHeader] + payload; + Buffers[2].cbBuffer = sctx->Sizes.cbTrailer; + Buffers[2].BufferType = SECBUFFER_STREAM_TRAILER; + + Buffers[3].pvBuffer = SECBUFFER_EMPTY; // Pointer to buffer 4 + Buffers[3].cbBuffer = SECBUFFER_EMPTY; // length of buffer 4 + Buffers[3].BufferType = SECBUFFER_EMPTY; // Type of the buffer 4 + + + Message.ulVersion = SECBUFFER_VERSION; + Message.cBuffers = 4; + Message.pBuffers = Buffers; + if ((scRet = EncryptMessage(&sctx->hCtxt, 0, &Message, 0))!= SEC_E_OK) + return -1; + write_size = Buffers[0].cbBuffer + Buffers[1].cbBuffer + Buffers[2].cbBuffer; + nbytes = pvio->methods->write(pvio, sctx->IoBuffer, write_size); + return nbytes == write_size ? payload : -1; +} +/* }}} */ + +extern char *ssl_protocol_version[5]; + +/* {{{ ma_tls_get_protocol_version(MARIADB_TLS *ctls) */ +int ma_tls_get_protocol_version(MARIADB_TLS *ctls) +{ + SC_CTX *sctx; + SecPkgContext_ConnectionInfo ConnectionInfo; + if (!ctls->ssl) + return 1; + + sctx= (SC_CTX *)ctls->ssl; + + if (QueryContextAttributes(&sctx->hCtxt, SECPKG_ATTR_CONNECTION_INFO, &ConnectionInfo) != SEC_E_OK) + return -1; + + switch(ConnectionInfo.dwProtocol) + { + case SP_PROT_SSL3_CLIENT: + return PROTOCOL_SSLV3; + case SP_PROT_TLS1_CLIENT: + return PROTOCOL_TLS_1_0; + case SP_PROT_TLS1_1_CLIENT: + return PROTOCOL_TLS_1_1; + case SP_PROT_TLS1_2_CLIENT: + return PROTOCOL_TLS_1_2; + default: + return -1; + } +} +/* }}} */ diff --git a/vendor/MDBC/libmariadb/secure/ma_schannel.h b/vendor/MDBC/libmariadb/secure/ma_schannel.h new file mode 100644 index 00000000..af7fc602 --- /dev/null +++ b/vendor/MDBC/libmariadb/secure/ma_schannel.h @@ -0,0 +1,87 @@ +/************************************************************************************ + Copyright (C) 2014 MariaDB Corporation Ab + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not see + or write to the Free Software Foundation, Inc., + 51 Franklin St., Fifth Floor, Boston, MA 02110, USA + + Author: Georg Richter + + *************************************************************************************/ +#ifndef _ma_schannel_h_ +#define _ma_schannel_h_ + +#define SECURITY_WIN32 +#include +#include +#include +#include +#include + + +#include +#include + + +#include + +#include +#undef SECURITY_WIN32 +#include +#include + +#define SC_IO_BUFFER_SIZE 0x4000 + + +#include + +struct st_DER { + char* der_buffer; + DWORD der_length; +}; + +struct st_schannel { + CredHandle CredHdl; + PUCHAR IoBuffer; + DWORD IoBufferSize; + SecPkgContext_StreamSizes Sizes; + CtxtHandle hCtxt; + + /* Cached data from the last read/decrypt call.*/ + SecBuffer extraBuf; /* encrypted data read from server. */ + SecBuffer dataBuf; /* decrypted but still unread data from server.*/ + +}; + +typedef struct st_schannel SC_CTX; + +extern HCERTSTORE ca_CertStore, crl_CertStore; +extern my_bool ca_Check, crl_Check; + +; +SECURITY_STATUS ma_schannel_client_handshake(MARIADB_TLS *ctls); +SECURITY_STATUS ma_schannel_handshake_loop(MARIADB_PVIO *pvio, my_bool InitialRead, SecBuffer *pExtraData); + +my_bool ma_schannel_verify_certs(MARIADB_TLS *ctls, BOOL verify_server_name); +ssize_t ma_schannel_write_encrypt(MARIADB_PVIO *pvio, + uchar *WriteBuffer, + size_t WriteBufferSize); +SECURITY_STATUS ma_schannel_read_decrypt(MARIADB_PVIO *pvio, + CtxtHandle* phContext, + DWORD *DecryptLength, + uchar *ReadBuffer, + DWORD ReadBufferSize); + + +#endif /* _ma_schannel_h_ */ diff --git a/vendor/MDBC/libmariadb/secure/openssl.c b/vendor/MDBC/libmariadb/secure/openssl.c new file mode 100644 index 00000000..264625a6 --- /dev/null +++ b/vendor/MDBC/libmariadb/secure/openssl.c @@ -0,0 +1,797 @@ +/************************************************************************************ + Copyright (C) 2012 Monty Program AB + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not see + or write to the Free Software Foundation, Inc., + 51 Franklin St., Fifth Floor, Boston, MA 02110, USA + + *************************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include /* SSL and SSL_CTX */ +#include /* error reporting */ +#include +#include + +#if defined(_WIN32) && !defined(_OPENSSL_Applink) && defined(HAVE_OPENSSL_APPLINK_C) +#include +#endif + +#if OPENSSL_VERSION_NUMBER >= 0x10002000L && !defined(LIBRESSL_VERSION_NUMBER) +#include +#define HAVE_OPENSSL_CHECK_HOST 1 +#endif + +#if OPENSSL_VERSION_NUMBER >= 0x10100000L && !defined(LIBRESSL_VERSION_NUMBER) +#define HAVE_OPENSSL_1_1_API +#endif + +#if OPENSSL_VERSION_NUMBER < 0x10000000L +#define SSL_OP_NO_TLSv1_1 0L +#define SSL_OP_NO_TLSv1_2 0L +#define CRYPTO_THREADID_set_callback CRYPTO_set_id_callback +#define CRYPTO_THREADID_get_callback CRYPTO_get_id_callback +#endif + +#if defined(OPENSSL_USE_BIOMETHOD) +#undef OPENSSL_USE_BIOMETHOD +#endif +#ifndef HAVE_OPENSSL_DEFAULT +#include +#define ma_malloc(A,B) malloc((A)) +#undef ma_free +#define ma_free(A) free((A)) +#define ma_snprintf snprintf +#define ma_vsnprintf vsnprintf +#undef SAFE_MUTEX +#endif +#include + +#include +#include + +extern my_bool ma_tls_initialized; +extern unsigned int mariadb_deinitialize_ssl; + +#define MAX_SSL_ERR_LEN 100 +char tls_library_version[TLS_VERSION_LENGTH]; + +static pthread_mutex_t LOCK_openssl_config; +#ifndef HAVE_OPENSSL_1_1_API +static pthread_mutex_t *LOCK_crypto= NULL; +#endif +#if defined(OPENSSL_USE_BIOMETHOD) +static int ma_bio_read(BIO *h, char *buf, int size); +static int ma_bio_write(BIO *h, const char *buf, int size); +static BIO_METHOD ma_BIO_method; +#endif + + +static long ma_tls_version_options(const char *version) +{ + long protocol_options, + disable_all_protocols; + + protocol_options= disable_all_protocols= + SSL_OP_NO_SSLv2 | + SSL_OP_NO_SSLv3 | + SSL_OP_NO_TLSv1 | + SSL_OP_NO_TLSv1_1 | + SSL_OP_NO_TLSv1_2 +#ifdef TLS1_3_VERSION + | SSL_OP_NO_TLSv1_3 +#endif + ; + + if (!version) + return 0; + + if (strstr(version, "TLSv1.0")) + protocol_options&= ~SSL_OP_NO_TLSv1; + if (strstr(version, "TLSv1.1")) + protocol_options&= ~SSL_OP_NO_TLSv1_1; + if (strstr(version, "TLSv1.2")) + protocol_options&= ~SSL_OP_NO_TLSv1_2; +#ifdef TLS1_3_VERSION + if (strstr(version, "TLSv1.3")) + protocol_options&= ~SSL_OP_NO_TLSv1_3; +#endif + + if (protocol_options != disable_all_protocols) + return protocol_options; + return 0; +} + +static void ma_tls_set_error(MYSQL *mysql) +{ + ulong ssl_errno= ERR_get_error(); + char ssl_error[MAX_SSL_ERR_LEN]; + const char *ssl_error_reason; + MARIADB_PVIO *pvio= mysql->net.pvio; + + if (!ssl_errno) + { + pvio->set_error(mysql, CR_SSL_CONNECTION_ERROR, SQLSTATE_UNKNOWN, "Unknown SSL error"); + return; + } + if ((ssl_error_reason= ERR_reason_error_string(ssl_errno))) + { + pvio->set_error(mysql, CR_SSL_CONNECTION_ERROR, SQLSTATE_UNKNOWN, + 0, ssl_error_reason); + return; + } + snprintf(ssl_error, MAX_SSL_ERR_LEN, "SSL errno=%lu", ssl_errno); + pvio->set_error(mysql, CR_SSL_CONNECTION_ERROR, SQLSTATE_UNKNOWN, 0, ssl_error); + return; +} + +#ifndef HAVE_OPENSSL_1_1_API +/* + thread safe callbacks for OpenSSL + Crypto call back functions will be + set during ssl_initialization + */ +#if OPENSSL_VERSION_NUMBER < 0x10000000L +static unsigned long my_cb_threadid(void) +{ + /* cast pthread_t to unsigned long */ + return (unsigned long) pthread_self(); +} +#else +static void my_cb_threadid(CRYPTO_THREADID *id) +{ + CRYPTO_THREADID_set_numeric(id, (unsigned long)pthread_self()); +} +#endif +#endif + +#ifndef HAVE_OPENSSL_1_1_API +static void my_cb_locking(int mode, int n, + const char *file __attribute__((unused)), + int line __attribute__((unused))) +{ + if (mode & CRYPTO_LOCK) + pthread_mutex_lock(&LOCK_crypto[n]); + else + pthread_mutex_unlock(&LOCK_crypto[n]); +} + +static int ssl_thread_init() +{ + if (!CRYPTO_THREADID_get_callback() +#ifndef OPENSSL_NO_DEPRECATED + && !CRYPTO_get_id_callback() +#endif + ) + { + int i, max= CRYPTO_num_locks(); + + if (LOCK_crypto == NULL) + { + if (!(LOCK_crypto= + (pthread_mutex_t *)ma_malloc(sizeof(pthread_mutex_t) * max, MYF(0)))) + return 1; + + for (i=0; i < max; i++) + pthread_mutex_init(&LOCK_crypto[i], NULL); + } + CRYPTO_set_locking_callback(my_cb_locking); + CRYPTO_THREADID_set_callback(my_cb_threadid); + } + return 0; +} +#endif + +#if defined(_WIN32) || !defined(DISABLE_SIGPIPE) +#define disable_sigpipe() +#else +#include +static void ma_sigpipe_handler() +{ +} + +static void disable_sigpipe() +{ + struct sigaction old_handler, new_handler={NULL}; + if (!sigaction (SIGPIPE, NULL, &old_handler) && + !old_handler.sa_handler) + { + new_handler.sa_handler= ma_sigpipe_handler; + new_handler.sa_flags= 0; + if (!sigemptyset(&new_handler.sa_mask)) + sigaction(SIGPIPE, &new_handler, NULL); + } +} +#endif + +/* + Initializes SSL + + SYNOPSIS + my_ssl_start + mysql connection handle + + RETURN VALUES + 0 success + 1 error +*/ +int ma_tls_start(char *errmsg __attribute__((unused)), size_t errmsg_len __attribute__((unused))) +{ + int rc= 1; + char *p; + if (ma_tls_initialized) + return 0; + + /* lock mutex to prevent multiple initialization */ + pthread_mutex_init(&LOCK_openssl_config, NULL); + pthread_mutex_lock(&LOCK_openssl_config); +#ifdef HAVE_OPENSSL_1_1_API + if (!OPENSSL_init_ssl(OPENSSL_INIT_LOAD_CONFIG, NULL)) + goto end; +#else + if (ssl_thread_init()) + { + strncpy(errmsg, "Not enough memory", errmsg_len); + goto end; + } + SSL_library_init(); +#if SSLEAY_VERSION_NUMBER >= 0x00907000L + OPENSSL_config(NULL); +#endif +#endif +#ifndef HAVE_OPENSSL_1_1_API + /* load errors */ + SSL_load_error_strings(); + /* digests and ciphers */ + OpenSSL_add_all_algorithms(); +#endif + disable_sigpipe(); +#ifdef OPENSSL_USE_BIOMETHOD + memcpy(&ma_BIO_method, BIO_s_socket(), sizeof(BIO_METHOD)); + ma_BIO_method.bread= ma_bio_read; + ma_BIO_method.bwrite= ma_bio_write; +#endif + snprintf(tls_library_version, TLS_VERSION_LENGTH - 1, "%s", +#if defined(LIBRESSL_VERSION_NUMBER) || !defined(HAVE_OPENSSL_1_1_API) + SSLeay_version(SSLEAY_VERSION)); +#else + OpenSSL_version(OPENSSL_VERSION)); +#endif + /* remove date from version */ + if ((p= strstr(tls_library_version, " "))) + *p= 0; + rc= 0; + ma_tls_initialized= TRUE; +end: + pthread_mutex_unlock(&LOCK_openssl_config); + return rc; +} + +/* + Release SSL and free resources + Will be automatically executed by + mysql_server_end() function + + SYNOPSIS + my_ssl_end() + void + + RETURN VALUES + void +*/ +void ma_tls_end() +{ + if (ma_tls_initialized) + { + pthread_mutex_lock(&LOCK_openssl_config); +#ifndef HAVE_OPENSSL_1_1_API + if (LOCK_crypto) + { + int i; + CRYPTO_set_locking_callback(NULL); + CRYPTO_THREADID_set_callback(NULL); + + for (i=0; i < CRYPTO_num_locks(); i++) + pthread_mutex_destroy(&LOCK_crypto[i]); + ma_free((gptr)LOCK_crypto); + LOCK_crypto= NULL; + } +#endif + if (mariadb_deinitialize_ssl) + { +#ifndef HAVE_OPENSSL_1_1_API + ERR_remove_thread_state(NULL); + EVP_cleanup(); + CRYPTO_cleanup_all_ex_data(); + ERR_free_strings(); + CONF_modules_free(); + CONF_modules_unload(1); +#endif + } + ma_tls_initialized= FALSE; + pthread_mutex_unlock(&LOCK_openssl_config); + pthread_mutex_destroy(&LOCK_openssl_config); + } + return; +} + +int ma_tls_get_password(char *buf, int size, + int rwflag __attribute__((unused)), + void *userdata) +{ + memset(buf, 0, size); + if (userdata) + strncpy(buf, (char *)userdata, size); + return (int)strlen(buf); +} + + +static int ma_tls_set_certs(MYSQL *mysql, SSL_CTX *ctx) +{ + char *certfile= mysql->options.ssl_cert, + *keyfile= mysql->options.ssl_key; + char *pw= (mysql->options.extension) ? + mysql->options.extension->tls_pw : NULL; + + /* add cipher */ + if ((mysql->options.ssl_cipher && + mysql->options.ssl_cipher[0] != 0)) + { + if( +#ifdef TLS1_3_VERSION + SSL_CTX_set_ciphersuites(ctx, mysql->options.ssl_cipher) == 0 && +#endif + SSL_CTX_set_cipher_list(ctx, mysql->options.ssl_cipher) == 0) + goto error; + } + + /* ca_file and ca_path */ + if (!SSL_CTX_load_verify_locations(ctx, + mysql->options.ssl_ca, + mysql->options.ssl_capath)) + { + if (mysql->options.ssl_ca || mysql->options.ssl_capath) + goto error; + if (SSL_CTX_set_default_verify_paths(ctx) == 0) + goto error; + } + + if (mysql->options.extension && + (mysql->options.extension->ssl_crl || mysql->options.extension->ssl_crlpath)) + { + X509_STORE *certstore; + + if ((certstore= SSL_CTX_get_cert_store(ctx))) + { + if (X509_STORE_load_locations(certstore, mysql->options.extension->ssl_crl, + mysql->options.extension->ssl_crlpath) == 0) + goto error; + + if (X509_STORE_set_flags(certstore, X509_V_FLAG_CRL_CHECK | X509_V_FLAG_CRL_CHECK_ALL) == 0) + goto error; + } + } + + if (keyfile && !certfile) + certfile= keyfile; + if (certfile && !keyfile) + keyfile= certfile; + + /* set cert */ + if (certfile && certfile[0] != 0) + { + if (SSL_CTX_use_certificate_chain_file(ctx, certfile) != 1) + { + goto error; + } + } + + if (keyfile && keyfile[0]) + { + FILE *fp; + if ((fp= fopen(keyfile, "rb"))) + { + EVP_PKEY *key= EVP_PKEY_new(); + PEM_read_PrivateKey(fp, &key, NULL, pw); + fclose(fp); + if (SSL_CTX_use_PrivateKey(ctx, key) != 1) + { + unsigned long err= ERR_peek_error(); + EVP_PKEY_free(key); + if (!(ERR_GET_LIB(err) == ERR_LIB_X509 && + ERR_GET_REASON(err) == X509_R_CERT_ALREADY_IN_HASH_TABLE)) + goto error; + } + EVP_PKEY_free(key); + } else { + my_set_error(mysql, CR_SSL_CONNECTION_ERROR, SQLSTATE_UNKNOWN, + CER(CR_FILE_NOT_FOUND), keyfile); + return 1; + } + } + /* verify key */ + if (certfile && SSL_CTX_check_private_key(ctx) != 1) + goto error; + + SSL_CTX_set_verify(ctx, (mysql->options.ssl_ca || mysql->options.ssl_capath) ? + SSL_VERIFY_PEER : SSL_VERIFY_NONE, NULL); + return 0; + +error: + ma_tls_set_error(mysql); + return 1; +} + +void *ma_tls_init(MYSQL *mysql) +{ + SSL *ssl= NULL; + SSL_CTX *ctx= NULL; + long default_options= SSL_OP_ALL | + SSL_OP_NO_SSLv2 | + SSL_OP_NO_SSLv3; + long options= 0; + pthread_mutex_lock(&LOCK_openssl_config); + + #if OPENSSL_VERSION_NUMBER >= 0x10100000L + if (!(ctx= SSL_CTX_new(TLS_client_method()))) +#else + if (!(ctx= SSL_CTX_new(SSLv23_client_method()))) +#endif + goto error; + if (mysql->options.extension) + options= ma_tls_version_options(mysql->options.extension->tls_version); + SSL_CTX_set_options(ctx, options ? options : default_options); + + if (ma_tls_set_certs(mysql, ctx)) + { + goto error; + } + + if (!(ssl= SSL_new(ctx))) + goto error; + + if (!SSL_set_app_data(ssl, mysql)) + goto error; + + pthread_mutex_unlock(&LOCK_openssl_config); + return (void *)ssl; +error: + pthread_mutex_unlock(&LOCK_openssl_config); + if (ctx) + SSL_CTX_free(ctx); + if (ssl) + SSL_free(ssl); + return NULL; +} + +my_bool ma_tls_connect(MARIADB_TLS *ctls) +{ + SSL *ssl = (SSL *)ctls->ssl; + my_bool blocking, try_connect= 1; + MYSQL *mysql; + MARIADB_PVIO *pvio; + int rc; +#ifdef OPENSSL_USE_BIOMETHOD + BIO_METHOD *bio_method= NULL; + BIO *bio; +#endif + + mysql= (MYSQL *)SSL_get_app_data(ssl); + pvio= mysql->net.pvio; + + /* Set socket to non blocking if not already set */ + if (!(blocking= pvio->methods->is_blocking(pvio))) + pvio->methods->blocking(pvio, FALSE, 0); + + SSL_clear(ssl); + +#ifdef OPENSSL_USE_BIOMETHOD + bio= BIO_new(&ma_BIO_method); + bio->ptr= pvio; + SSL_set_bio(ssl, bio, bio); + BIO_set_fd(bio, mysql_get_socket(mysql), BIO_NOCLOSE); +#else + SSL_set_fd(ssl, (int)mysql_get_socket(mysql)); +#endif + + while (try_connect && (rc= SSL_connect(ssl)) == -1) + { + switch((SSL_get_error(ssl, rc))) { + case SSL_ERROR_WANT_READ: + if (pvio->methods->wait_io_or_timeout(pvio, TRUE, mysql->options.connect_timeout) < 1) + try_connect= 0; + break; + case SSL_ERROR_WANT_WRITE: + if (pvio->methods->wait_io_or_timeout(pvio, TRUE, mysql->options.connect_timeout) < 1) + try_connect= 0; + break; + default: + try_connect= 0; + } + } + + /* In case handshake failed or if a root certificate (ca) was specified, + we need to check the result code of X509 verification. A detailed check + of the peer certificate (hostname checking will follow later) */ + if (rc != 1 || + (mysql->client_flag & CLIENT_SSL_VERIFY_SERVER_CERT) || + (mysql->options.ssl_ca || mysql->options.ssl_capath)) + { + long x509_err= SSL_get_verify_result(ssl); + if (x509_err != X509_V_OK) + { + my_set_error(mysql, CR_SSL_CONNECTION_ERROR, SQLSTATE_UNKNOWN, + ER(CR_SSL_CONNECTION_ERROR), X509_verify_cert_error_string(x509_err)); + /* restore blocking mode */ + if (!blocking) + pvio->methods->blocking(pvio, FALSE, 0); + + return 1; + } else if (rc != 1) { + ma_tls_set_error(mysql); + return 1; + } + } + pvio->ctls->ssl= ctls->ssl= (void *)ssl; + + return 0; +} + +static my_bool +ma_tls_async_check_result(int res, struct mysql_async_context *b, SSL *ssl) +{ + int ssl_err; + b->events_to_wait_for= 0; + if (res >= 0) + return 1; + ssl_err= SSL_get_error(ssl, res); + if (ssl_err == SSL_ERROR_WANT_READ) + b->events_to_wait_for|= MYSQL_WAIT_READ; + else if (ssl_err == SSL_ERROR_WANT_WRITE) + b->events_to_wait_for|= MYSQL_WAIT_WRITE; + else + return 1; + if (b->suspend_resume_hook) + (*b->suspend_resume_hook)(TRUE, b->suspend_resume_hook_user_data); + my_context_yield(&b->async_context); + if (b->suspend_resume_hook) + (*b->suspend_resume_hook)(FALSE, b->suspend_resume_hook_user_data); + return 0; +} + +ssize_t ma_tls_read_async(MARIADB_PVIO *pvio, + const unsigned char *buffer, + size_t length) +{ + int res; + struct mysql_async_context *b= pvio->mysql->options.extension->async_context; + MARIADB_TLS *ctls= pvio->ctls; + + for (;;) + { + res= SSL_read((SSL *)ctls->ssl, (void *)buffer, (int)length); + if (ma_tls_async_check_result(res, b, (SSL *)ctls->ssl)) + return res; + } +} + +ssize_t ma_tls_write_async(MARIADB_PVIO *pvio, + const unsigned char *buffer, + size_t length) +{ + int res; + struct mysql_async_context *b= pvio->mysql->options.extension->async_context; + MARIADB_TLS *ctls= pvio->ctls; + + for (;;) + { + res= SSL_write((SSL *)ctls->ssl, (void *)buffer, (int)length); + if (ma_tls_async_check_result(res, b, (SSL *)ctls->ssl)) + return res; + } +} + + +ssize_t ma_tls_read(MARIADB_TLS *ctls, const uchar* buffer, size_t length) +{ + int rc; + MARIADB_PVIO *pvio= ctls->pvio; + + while ((rc= SSL_read((SSL *)ctls->ssl, (void *)buffer, (int)length)) < 0) + { + int error= SSL_get_error((SSL *)ctls->ssl, rc); + if (error != SSL_ERROR_WANT_READ) + return rc; + if (pvio->methods->wait_io_or_timeout(pvio, TRUE, pvio->mysql->options.read_timeout) < 1) + return rc; + } + return rc; +} + +ssize_t ma_tls_write(MARIADB_TLS *ctls, const uchar* buffer, size_t length) +{ + int rc; + MARIADB_PVIO *pvio= ctls->pvio; + + while ((rc= SSL_write((SSL *)ctls->ssl, (void *)buffer, (int)length)) <= 0) + { + int error= SSL_get_error((SSL *)ctls->ssl, rc); + if (error != SSL_ERROR_WANT_WRITE) + return rc; + if (pvio->methods->wait_io_or_timeout(pvio, TRUE, pvio->mysql->options.write_timeout) < 1) + return rc; + } + return rc; +} + +my_bool ma_tls_close(MARIADB_TLS *ctls) +{ + int i, rc; + SSL *ssl; + SSL_CTX *ctx= NULL; + + if (!ctls || !ctls->ssl) + return 1; + ssl= (SSL *)ctls->ssl; + ctx= SSL_get_SSL_CTX(ssl); + if (ctx) + SSL_CTX_free(ctx); + + SSL_set_quiet_shutdown(ssl, 1); + /* 2 x pending + 2 * data = 4 */ + for (i=0; i < 4; i++) + if ((rc= SSL_shutdown(ssl))) + break; + + /* Since we transferred ownership of BIO to ssl, BIO will + automatically freed - no need for an explicit BIO_free_all */ + + SSL_free(ssl); + ctls->ssl= NULL; + + return rc; +} + +int ma_tls_verify_server_cert(MARIADB_TLS *ctls) +{ + X509 *cert; + MYSQL *mysql; + SSL *ssl; + MARIADB_PVIO *pvio; +#if !defined(HAVE_OPENSSL_CHECK_HOST) + X509_NAME *x509sn; + int cn_pos; + X509_NAME_ENTRY *cn_entry; + ASN1_STRING *cn_asn1; + const char *cn_str; +#endif + if (!ctls || !ctls->ssl) + return 1; + ssl= (SSL *)ctls->ssl; + + mysql= (MYSQL *)SSL_get_app_data(ssl); + pvio= mysql->net.pvio; + + if (!mysql->host) + { + pvio->set_error(mysql, CR_SSL_CONNECTION_ERROR, SQLSTATE_UNKNOWN, + ER(CR_SSL_CONNECTION_ERROR), "Invalid (empty) hostname"); + return 1; + } + + if (!(cert= SSL_get_peer_certificate(ssl))) + { + pvio->set_error(mysql, CR_SSL_CONNECTION_ERROR, SQLSTATE_UNKNOWN, + ER(CR_SSL_CONNECTION_ERROR), "Unable to get server certificate"); + return 1; + } +#ifdef HAVE_OPENSSL_CHECK_HOST + if (X509_check_host(cert, mysql->host, 0, 0, 0) != 1 + && X509_check_ip_asc(cert, mysql->host, 0) != 1) + goto error; +#else + x509sn= X509_get_subject_name(cert); + + if ((cn_pos= X509_NAME_get_index_by_NID(x509sn, NID_commonName, -1)) < 0) + goto error; + + if (!(cn_entry= X509_NAME_get_entry(x509sn, cn_pos))) + goto error; + + if (!(cn_asn1 = X509_NAME_ENTRY_get_data(cn_entry))) + goto error; + + cn_str = (char *)ASN1_STRING_data(cn_asn1); + + /* Make sure there is no embedded \0 in the CN */ + if ((size_t)ASN1_STRING_length(cn_asn1) != strlen(cn_str)) + goto error; + + if (strcmp(cn_str, mysql->host)) + goto error; +#endif + X509_free(cert); + + return 0; +error: + X509_free(cert); + + pvio->set_error(mysql, CR_SSL_CONNECTION_ERROR, SQLSTATE_UNKNOWN, + ER(CR_SSL_CONNECTION_ERROR), "Validation of SSL server certificate failed"); + return 1; +} + +const char *ma_tls_get_cipher(MARIADB_TLS *ctls) +{ + if (!ctls || !ctls->ssl) + return NULL; + return SSL_get_cipher_name(ctls->ssl); +} + +unsigned int ma_tls_get_finger_print(MARIADB_TLS *ctls, char *fp, unsigned int len) +{ + X509 *cert= NULL; + MYSQL *mysql; + unsigned int fp_len; + + if (!ctls || !ctls->ssl) + return 0; + + mysql= SSL_get_app_data(ctls->ssl); + + if (!(cert= SSL_get_peer_certificate(ctls->ssl))) + { + my_set_error(mysql, CR_SSL_CONNECTION_ERROR, SQLSTATE_UNKNOWN, + ER(CR_SSL_CONNECTION_ERROR), + "Unable to get server certificate"); + goto end; + } + + if (len < EVP_MAX_MD_SIZE) + { + my_set_error(mysql, CR_SSL_CONNECTION_ERROR, SQLSTATE_UNKNOWN, + ER(CR_SSL_CONNECTION_ERROR), + "Finger print buffer too small"); + goto end; + } + if (!X509_digest(cert, EVP_sha1(), (unsigned char *)fp, &fp_len)) + { + my_set_error(mysql, CR_SSL_CONNECTION_ERROR, SQLSTATE_UNKNOWN, + ER(CR_SSL_CONNECTION_ERROR), + "invalid finger print of server certificate"); + goto end; + } + + X509_free(cert); + return (fp_len); +end: + X509_free(cert); + return 0; +} + + +int ma_tls_get_protocol_version(MARIADB_TLS *ctls) +{ + if (!ctls || !ctls->ssl) + return -1; + + return SSL_version(ctls->ssl) & 0xFF; +} + diff --git a/vendor/MDBC/libmariadb/secure/openssl_crypt.c b/vendor/MDBC/libmariadb/secure/openssl_crypt.c new file mode 100644 index 00000000..01d41a90 --- /dev/null +++ b/vendor/MDBC/libmariadb/secure/openssl_crypt.c @@ -0,0 +1,88 @@ +/* + Copyright (C) 2018 MariaDB Corporation AB + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not see + or write to the Free Software Foundation, Inc., + 51 Franklin St., Fifth Floor, Boston, MA 02110, USA +*/ +#include +#include +#include + +static const EVP_MD *ma_hash_get_algorithm(unsigned int alg) +{ + switch(alg) + { + case MA_HASH_MD5: + return EVP_md5(); + case MA_HASH_SHA1: + return EVP_sha1(); + case MA_HASH_SHA224: + return EVP_sha224(); + case MA_HASH_SHA256: + return EVP_sha256(); + case MA_HASH_SHA384: + return EVP_sha384(); + case MA_HASH_SHA512: + return EVP_sha512(); + case MA_HASH_RIPEMD160: + return EVP_ripemd160(); + default: + return NULL; + } +} + +MA_HASH_CTX *ma_hash_new(unsigned int algorithm, MA_HASH_CTX *unused __attribute__((unused))) +{ + EVP_MD_CTX *ctx= NULL; + const EVP_MD *evp_md= ma_hash_get_algorithm(algorithm); + + /* unknown or unsupported hash algorithm */ + if (!evp_md) + return NULL; +#if OPENSSL_VERSION_NUMBER >= 0x10100000L + if (!(ctx= EVP_MD_CTX_new())) +#else + if (!(ctx= EVP_MD_CTX_create())) +#endif + return NULL; + if (!EVP_DigestInit(ctx, evp_md)) + { + ma_hash_free(ctx); + return NULL; + } + return ctx; +} + +void ma_hash_free(MA_HASH_CTX *ctx) +{ + if (ctx) +#if OPENSSL_VERSION_NUMBER >= 0x10100000L + EVP_MD_CTX_free(ctx); +#else + EVP_MD_CTX_destroy(ctx); +#endif +} + +void ma_hash_input(MA_HASH_CTX *ctx, + const unsigned char *buffer, + size_t len) +{ + EVP_DigestUpdate(ctx, buffer, len); +} + +void ma_hash_result(MA_HASH_CTX *ctx, unsigned char *digest) +{ + EVP_DigestFinal_ex(ctx, digest, NULL); +} diff --git a/vendor/MDBC/libmariadb/secure/schannel.c b/vendor/MDBC/libmariadb/secure/schannel.c new file mode 100644 index 00000000..ff1833d4 --- /dev/null +++ b/vendor/MDBC/libmariadb/secure/schannel.c @@ -0,0 +1,562 @@ +/************************************************************************************ + Copyright (C) 2014 MariaDB Corporation Ab + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not see + or write to the Free Software Foundation, Inc., + 51 Franklin St., Fifth Floor, Boston, MA 02110, USA + + *************************************************************************************/ +#include "ma_schannel.h" +#include "schannel_certs.h" +#include + +extern my_bool ma_tls_initialized; +char tls_library_version[] = "Schannel"; + +#define PROT_SSL3 1 +#define PROT_TLS1_0 2 +#define PROT_TLS1_2 4 +#define PROT_TLS1_3 8 + +static struct +{ + DWORD cipher_id; + DWORD protocol; + const char *iana_name; + const char *openssl_name; + ALG_ID algs[4]; /* exchange, encryption, hash, signature */ +} +cipher_map[] = +{ + { + 0x0002, + PROT_TLS1_0 | PROT_TLS1_2 | PROT_SSL3, + "TLS_RSA_WITH_NULL_SHA", "NULL-SHA", + { CALG_RSA_KEYX, 0, CALG_SHA1, CALG_RSA_SIGN } + }, + { + 0x0004, + PROT_TLS1_0 | PROT_TLS1_2 | PROT_SSL3, + "TLS_RSA_WITH_RC4_128_MD5", "RC4-MD5", + { CALG_RSA_KEYX, CALG_RC4, CALG_MD5, CALG_RSA_SIGN } + }, + { + 0x0005, + PROT_TLS1_0 | PROT_TLS1_2 | PROT_SSL3, + "TLS_RSA_WITH_RC4_128_SHA", "RC4-SHA", + { CALG_RSA_KEYX, CALG_RC4, CALG_SHA1, CALG_RSA_SIGN } + }, + { + 0x000A, + PROT_SSL3, + "TLS_RSA_WITH_3DES_EDE_CBC_SHA", "DES-CBC3-SHA", + {CALG_RSA_KEYX, CALG_3DES, CALG_SHA1, CALG_DSS_SIGN} + }, + { + 0x0013, + PROT_TLS1_0 | PROT_TLS1_2 | PROT_SSL3, + "TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA", "EDH-DSS-DES-CBC3-SHA", + { CALG_DH_EPHEM, CALG_3DES, CALG_SHA1, CALG_DSS_SIGN } + }, + { + 0x002F, + PROT_SSL3 | PROT_TLS1_0 | PROT_TLS1_2, + "TLS_RSA_WITH_AES_128_CBC_SHA", "AES128-SHA", + { CALG_RSA_KEYX, CALG_AES_128, CALG_SHA, CALG_RSA_SIGN} + }, + { + 0x0032, + PROT_TLS1_0 | PROT_TLS1_2, + "TLS_DHE_DSS_WITH_AES_128_CBC_SHA", "DHE-DSS-AES128-SHA", + { CALG_DH_EPHEM, CALG_AES_128, CALG_SHA1, CALG_RSA_SIGN } + }, + { + 0x0033, + PROT_TLS1_0 | PROT_TLS1_2, + "TLS_DHE_RSA_WITH_AES_128_CBC_SHA", "DHE-RSA-AES128-SHA", + { CALG_DH_EPHEM, CALG_AES_128, CALG_SHA1, CALG_RSA_SIGN } + }, + { + 0x0035, + PROT_TLS1_0 | PROT_TLS1_2, + "TLS_RSA_WITH_AES_256_CBC_SHA", "AES256-SHA", + { CALG_RSA_KEYX, CALG_AES_256, CALG_SHA1, CALG_RSA_SIGN } + }, + { + 0x0038, + PROT_TLS1_0 | PROT_TLS1_2, + "TLS_DHE_DSS_WITH_AES_256_CBC_SHA", "DHE-DSS-AES256-SHA", + { CALG_DH_EPHEM, CALG_AES_256, CALG_SHA1, CALG_DSS_SIGN } + }, + { + 0x0039, + PROT_TLS1_0 | PROT_TLS1_2, + "TLS_DHE_RSA_WITH_AES_256_CBC_SHA", "DHE-RSA-AES256-SHA", + { CALG_DH_EPHEM, CALG_AES_256, CALG_SHA1, CALG_RSA_SIGN } + }, + { + 0x003B, + PROT_TLS1_2, + "TLS_RSA_WITH_NULL_SHA256", "NULL-SHA256", + { CALG_RSA_KEYX, 0, CALG_SHA_256, CALG_RSA_SIGN } + }, + { + 0x003C, + PROT_TLS1_2, + "TLS_RSA_WITH_AES_128_CBC_SHA256", "AES128-SHA256", + { CALG_RSA_KEYX, CALG_AES_128, CALG_SHA_256, CALG_RSA_SIGN } + }, + { + 0x003D, + PROT_TLS1_2, + "TLS_RSA_WITH_AES_256_CBC_SHA256", "AES256-SHA256", + { CALG_RSA_KEYX, CALG_AES_256, CALG_SHA_256, CALG_RSA_SIGN } + }, + { + 0x0040, + PROT_TLS1_2, + "TLS_DHE_DSS_WITH_AES_128_CBC_SHA256", "DHE-DSS-AES128-SHA256", + { CALG_DH_EPHEM, CALG_AES_128, CALG_SHA_256, CALG_DSS_SIGN } + }, + { + 0x009C, + PROT_TLS1_2, + "TLS_RSA_WITH_AES_128_GCM_SHA256", "AES128-GCM-SHA256", + { CALG_RSA_KEYX, CALG_AES_128, CALG_SHA_256, CALG_RSA_SIGN } + }, + { + 0x009D, + PROT_TLS1_2, + "TLS_RSA_WITH_AES_256_GCM_SHA384", "AES256-GCM-SHA384", + { CALG_RSA_KEYX, CALG_AES_256, CALG_SHA_384, CALG_RSA_SIGN } + }, + { + 0x009E, + PROT_TLS1_2, + "TLS_DHE_RSA_WITH_AES_128_GCM_SHA256", "DHE-RSA-AES128-GCM-SHA256", + { CALG_DH_EPHEM, CALG_AES_128, CALG_SHA_256, CALG_RSA_SIGN } + }, + { + 0x009F, + PROT_TLS1_2, + "TLS_DHE_RSA_WITH_AES_256_GCM_SHA384", "DHE-RSA-AES256-GCM-SHA384", + { CALG_DH_EPHEM, CALG_AES_256, CALG_SHA_384, CALG_RSA_SIGN } + }, + { + 0xC027, + PROT_TLS1_2, + "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256", "ECDHE-RSA-AES128-SHA256", + { CALG_ECDH, CALG_AES_128, CALG_SHA_256, CALG_RSA_SIGN } + }, + { + 0xC028, + PROT_TLS1_2, + "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384", "ECDHE-RSA-AES256-SHA384", + { CALG_ECDH, CALG_AES_256, CALG_SHA_384, CALG_RSA_SIGN } + } +}; + +#define MAX_ALG_ID 50 + +extern void ma_schannel_set_sec_error(MARIADB_PVIO *pvio, DWORD ErrorNo); + +/* + Initializes SSL and allocate global + context SSL_context + + SYNOPSIS + ma_tls_start + + RETURN VALUES + 0 success + 1 error +*/ +int ma_tls_start(char *errmsg, size_t errmsg_len) +{ + ma_tls_initialized = TRUE; + return 0; +} + +/* + Release SSL and free resources + Will be automatically executed by + mysql_server_end() function + + SYNOPSIS + ma_tls_end() + void + + RETURN VALUES + void +*/ +void ma_tls_end() +{ + return; +} + +/* {{{ static int ma_tls_set_client_certs(MARIADB_TLS *ctls) */ +static int ma_tls_set_client_certs(MARIADB_TLS *ctls,const CERT_CONTEXT **cert_ctx) +{ + MYSQL *mysql= ctls->pvio->mysql; + char *certfile= mysql->options.ssl_cert, + *keyfile= mysql->options.ssl_key; + MARIADB_PVIO *pvio= ctls->pvio; + char errmsg[256]; + + if (!certfile && keyfile) + certfile= keyfile; + if (!keyfile && certfile) + keyfile= certfile; + + if (!certfile) + return 0; + + *cert_ctx = schannel_create_cert_context(certfile, keyfile, errmsg, sizeof(errmsg)); + if (!*cert_ctx) + { + pvio->set_error(pvio->mysql, CR_SSL_CONNECTION_ERROR, SQLSTATE_UNKNOWN, "SSL connection error: %s", errmsg); + return 1; + } + + return 0; +} +/* }}} */ + +/* {{{ void *ma_tls_init(MARIADB_TLS *ctls, MYSQL *mysql) */ +void *ma_tls_init(MYSQL *mysql) +{ + SC_CTX *sctx = (SC_CTX *)LocalAlloc(LMEM_ZEROINIT, sizeof(SC_CTX)); + if (sctx) + { + SecInvalidateHandle(&sctx->CredHdl); + SecInvalidateHandle(&sctx->hCtxt); + } + return sctx; +} +/* }}} */ + + +/* + Maps between openssl suite names and schannel alg_ids. + Every suite has 4 algorithms (for exchange, encryption, hash and signing). + + The input string is a set of suite names (openssl), separated + by ':' + + The output is written into the array 'arr' of size 'arr_size' + The function returns number of elements written to the 'arr'. +*/ + +static struct _tls_version { + const char *tls_version; + DWORD protocol; +} tls_version[]= { + {"TLSv1.0", PROT_TLS1_0}, + {"TLSv1.2", PROT_TLS1_2}, + {"TLSv1.3", PROT_TLS1_3}, + {"SSLv3", PROT_SSL3} +}; + +/* The following list was produced with OpenSSL 1.1.1j + by executing `openssl ciphers -V`. */ +static struct { + DWORD dwCipherSuite; + const char *openssl_name; +} openssl_ciphers[] = { + {0x002F, "AES128-SHA"}, + {0x0033, "DHE-RSA-AES128-SHA"}, + {0x0035, "AES256-SHA"}, + {0x0039, "DHE-RSA-AES256-SHA"}, + {0x003C, "AES128-SHA256"}, + {0x003D, "AES256-SHA256"}, + {0x0067, "DHE-RSA-AES128-SHA256"}, + {0x006B, "DHE-RSA-AES256-SHA256"}, + {0x008C, "PSK-AES128-CBC-SHA"}, + {0x008D, "PSK-AES256-CBC-SHA"}, + {0x0090, "DHE-PSK-AES128-CBC-SHA"}, + {0x0091, "DHE-PSK-AES256-CBC-SHA"}, + {0x0094, "RSA-PSK-AES128-CBC-SHA"}, + {0x0095, "RSA-PSK-AES256-CBC-SHA"}, + {0x009C, "AES128-GCM-SHA256"}, + {0x009D, "AES256-GCM-SHA384"}, + {0x009E, "DHE-RSA-AES128-GCM-SHA256"}, + {0x009F, "DHE-RSA-AES256-GCM-SHA384"}, + {0x00A8, "PSK-AES128-GCM-SHA256"}, + {0x00A9, "PSK-AES256-GCM-SHA384"}, + {0x00AA, "DHE-PSK-AES128-GCM-SHA256"}, + {0x00AB, "DHE-PSK-AES256-GCM-SHA384"}, + {0x00AC, "RSA-PSK-AES128-GCM-SHA256"}, + {0x00AD, "RSA-PSK-AES256-GCM-SHA384"}, + {0x00AE, "PSK-AES128-CBC-SHA256"}, + {0x00AF, "PSK-AES256-CBC-SHA384"}, + {0x00B2, "DHE-PSK-AES128-CBC-SHA256"}, + {0x00B3, "DHE-PSK-AES256-CBC-SHA384"}, + {0x00B6, "RSA-PSK-AES128-CBC-SHA256"}, + {0x00B7, "RSA-PSK-AES256-CBC-SHA384"}, + {0x1301, "TLS_AES_128_GCM_SHA256"}, + {0x1302, "TLS_AES_256_GCM_SHA384"}, + {0x1303, "TLS_CHACHA20_POLY1305_SHA256"}, + {0xC009, "ECDHE-ECDSA-AES128-SHA"}, + {0xC00A, "ECDHE-ECDSA-AES256-SHA"}, + {0xC013, "ECDHE-RSA-AES128-SHA"}, + {0xC014, "ECDHE-RSA-AES256-SHA"}, + {0xC01D, "SRP-AES-128-CBC-SHA"}, + {0xC01E, "SRP-RSA-AES-128-CBC-SHA"}, + {0xC020, "SRP-AES-256-CBC-SHA"}, + {0xC021, "SRP-RSA-AES-256-CBC-SHA"}, + {0xC023, "ECDHE-ECDSA-AES128-SHA256"}, + {0xC024, "ECDHE-ECDSA-AES256-SHA384"}, + {0xC027, "ECDHE-RSA-AES128-SHA256"}, + {0xC028, "ECDHE-RSA-AES256-SHA384"}, + {0xC02B, "ECDHE-ECDSA-AES128-GCM-SHA256"}, + {0xC02C, "ECDHE-ECDSA-AES256-GCM-SHA384"}, + {0xC02F, "ECDHE-RSA-AES128-GCM-SHA256"}, + {0xC030, "ECDHE-RSA-AES256-GCM-SHA384"}, + {0xC035, "ECDHE-PSK-AES128-CBC-SHA"}, + {0xC036, "ECDHE-PSK-AES256-CBC-SHA"}, + {0xC037, "ECDHE-PSK-AES128-CBC-SHA256"}, + {0xC038, "ECDHE-PSK-AES256-CBC-SHA384"}, + {0xCCA8, "ECDHE-RSA-CHACHA20-POLY1305"}, + {0xCCA9, "ECDHE-ECDSA-CHACHA20-POLY1305"}, + {0xCCAA, "DHE-RSA-CHACHA20-POLY1305"}, + {0xCCAB, "PSK-CHACHA20-POLY1305"}, + {0xCCAC, "ECDHE-PSK-CHACHA20-POLY1305"}, + {0xCCAD, "DHE-PSK-CHACHA20-POLY1305"}, + {0xCCAE, "RSA-PSK-CHACHA20-POLY1305"} +}; + +static size_t set_cipher(char * cipher_str, DWORD protocol, ALG_ID *arr , size_t arr_size) +{ + char *token = strtok(cipher_str, ":"); + size_t pos = 0; + + while (token) + { + size_t i; + + for(i = 0; i < sizeof(cipher_map)/sizeof(cipher_map[0]) ; i++) + { + if((pos + 4 < arr_size && strcmp(cipher_map[i].openssl_name, token) == 0) || + (cipher_map[i].protocol <= protocol)) + { + memcpy(arr + pos, cipher_map[i].algs, sizeof(ALG_ID)* 4); + pos += 4; + break; + } + } + token = strtok(NULL, ":"); + } + return pos; +} + +my_bool ma_tls_connect(MARIADB_TLS *ctls) +{ + MYSQL *mysql; + SCHANNEL_CRED Cred = {0}; + MARIADB_PVIO *pvio; + my_bool rc= 1; + SC_CTX *sctx; + SECURITY_STATUS sRet; + ALG_ID AlgId[MAX_ALG_ID]; + size_t i; + DWORD protocol = 0; + int verify_certs; + const CERT_CONTEXT* cert_context = NULL; + + if (!ctls) + return 1; + + pvio= ctls->pvio; + sctx= (SC_CTX *)ctls->ssl; + if (!pvio || !sctx) + return 1; + + mysql= pvio->mysql; + if (!mysql) + return 1; + + /* Set cipher */ + if (mysql->options.ssl_cipher) + { + + /* check if a protocol was specified as a cipher: + * In this case don't allow cipher suites which belong to newer protocols + * Please note: There are no cipher suites for TLS1.1 + */ + for (i = 0; i < sizeof(tls_version) / sizeof(tls_version[0]); i++) + { + if (!_stricmp(mysql->options.ssl_cipher, tls_version[i].tls_version)) + protocol |= tls_version[i].protocol; + } + memset(AlgId, 0, sizeof(AlgId)); + Cred.cSupportedAlgs = (DWORD)set_cipher(mysql->options.ssl_cipher, protocol, AlgId, MAX_ALG_ID); + if (Cred.cSupportedAlgs) + { + Cred.palgSupportedAlgs = AlgId; + } + else if (!protocol) + { + ma_schannel_set_sec_error(pvio, SEC_E_ALGORITHM_MISMATCH); + goto end; + } + } + + Cred.dwVersion= SCHANNEL_CRED_VERSION; + + Cred.dwFlags = SCH_CRED_NO_SERVERNAME_CHECK | SCH_CRED_NO_DEFAULT_CREDS | SCH_CRED_MANUAL_CRED_VALIDATION; + + if (mysql->options.extension && mysql->options.extension->tls_version) + { + if (strstr(mysql->options.extension->tls_version, "TLSv1.0")) + Cred.grbitEnabledProtocols|= SP_PROT_TLS1_0_CLIENT; + if (strstr(mysql->options.extension->tls_version, "TLSv1.1")) + Cred.grbitEnabledProtocols|= SP_PROT_TLS1_1_CLIENT; + if (strstr(mysql->options.extension->tls_version, "TLSv1.2")) + Cred.grbitEnabledProtocols|= SP_PROT_TLS1_2_CLIENT; + } + if (!Cred.grbitEnabledProtocols) + Cred.grbitEnabledProtocols = SP_PROT_TLS1_0_CLIENT | SP_PROT_TLS1_1_CLIENT | SP_PROT_TLS1_2_CLIENT; + + + if (ma_tls_set_client_certs(ctls, &cert_context)) + goto end; + + if (cert_context) + { + Cred.cCreds = 1; + Cred.paCred = &cert_context; + } + sRet= AcquireCredentialsHandleA(NULL, UNISP_NAME_A, SECPKG_CRED_OUTBOUND, + NULL, &Cred, NULL, NULL, &sctx->CredHdl, NULL); + if (sRet) + { + ma_schannel_set_sec_error(pvio, sRet); + goto end; + } + if (ma_schannel_client_handshake(ctls) != SEC_E_OK) + goto end; + + verify_certs = mysql->options.ssl_ca || mysql->options.ssl_capath || + (mysql->client_flag & CLIENT_SSL_VERIFY_SERVER_CERT); + + if (verify_certs) + { + if (!ma_schannel_verify_certs(ctls, (mysql->client_flag & CLIENT_SSL_VERIFY_SERVER_CERT))) + goto end; + } + + rc = 0; + +end: + if (cert_context) + schannel_free_cert_context(cert_context); + return rc; +} + +ssize_t ma_tls_read(MARIADB_TLS *ctls, const uchar* buffer, size_t length) +{ + SC_CTX *sctx= (SC_CTX *)ctls->ssl; + MARIADB_PVIO *pvio= ctls->pvio; + DWORD dlength= 0; + SECURITY_STATUS status = ma_schannel_read_decrypt(pvio, &sctx->hCtxt, &dlength, (uchar *)buffer, (DWORD)length); + if (status == SEC_I_CONTEXT_EXPIRED) + return 0; /* other side shut down the connection. */ + if (status == SEC_I_RENEGOTIATE) + return -1; /* Do not handle renegotiate yet */ + + return (status == SEC_E_OK)? (ssize_t)dlength : -1; +} + +ssize_t ma_tls_write(MARIADB_TLS *ctls, const uchar* buffer, size_t length) +{ + MARIADB_PVIO *pvio= ctls->pvio; + ssize_t rc, wlength= 0; + ssize_t remain= length; + + while (remain > 0) + { + if ((rc= ma_schannel_write_encrypt(pvio, (uchar *)buffer + wlength, remain)) <= 0) + return rc; + wlength+= rc; + remain-= rc; + } + return length; +} + +/* {{{ my_bool ma_tls_close(MARIADB_PVIO *pvio) */ +my_bool ma_tls_close(MARIADB_TLS *ctls) +{ + SC_CTX *sctx= (SC_CTX *)ctls->ssl; + + if (sctx) + { + LocalFree(sctx->IoBuffer); + + if (SecIsValidHandle(&sctx->CredHdl)) + FreeCredentialHandle(&sctx->CredHdl); + + if (SecIsValidHandle(&sctx->hCtxt)) + DeleteSecurityContext(&sctx->hCtxt); + } + LocalFree(sctx); + return 0; +} +/* }}} */ + +int ma_tls_verify_server_cert(MARIADB_TLS *ctls) +{ + /* Done elsewhere */ + return 0; +} + +static const char *cipher_name(const SecPkgContext_CipherInfo *CipherInfo) +{ + size_t i; + + for(i = 0; i < sizeof(openssl_ciphers)/sizeof(openssl_ciphers[0]) ; i++) + { + if (CipherInfo->dwCipherSuite == openssl_ciphers[i].dwCipherSuite) + return openssl_ciphers[i].openssl_name; + } + return ""; +}; + +const char *ma_tls_get_cipher(MARIADB_TLS *ctls) +{ + SecPkgContext_CipherInfo CipherInfo = { SECPKGCONTEXT_CIPHERINFO_V1 }; + SECURITY_STATUS sRet; + SC_CTX *sctx; + + if (!ctls || !ctls->ssl) + return NULL; + + sctx= (SC_CTX *)ctls->ssl; + sRet= QueryContextAttributesA(&sctx->hCtxt, SECPKG_ATTR_CIPHER_INFO, (PVOID)&CipherInfo); + + if (sRet != SEC_E_OK) + return NULL; + + return cipher_name(&CipherInfo); +} + +unsigned int ma_tls_get_finger_print(MARIADB_TLS *ctls, char *fp, unsigned int len) +{ + SC_CTX *sctx= (SC_CTX *)ctls->ssl; + PCCERT_CONTEXT pRemoteCertContext = NULL; + if (QueryContextAttributes(&sctx->hCtxt, SECPKG_ATTR_REMOTE_CERT_CONTEXT, (PVOID)&pRemoteCertContext) != SEC_E_OK) + return 0; + CertGetCertificateContextProperty(pRemoteCertContext, CERT_HASH_PROP_ID, fp, (DWORD *)&len); + CertFreeCertificateContext(pRemoteCertContext); + return len; +} diff --git a/vendor/MDBC/libmariadb/secure/schannel_certs.c b/vendor/MDBC/libmariadb/secure/schannel_certs.c new file mode 100644 index 00000000..fb0fee30 --- /dev/null +++ b/vendor/MDBC/libmariadb/secure/schannel_certs.c @@ -0,0 +1,854 @@ +/************************************************************************************ + Copyright (C) 2019 MariaDB + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not see + or write to the Free Software Foundation, Inc., + 51 Franklin St., Fifth Floor, Boston, MA 02110, USA + + *************************************************************************************/ + + /* + This module contain X509 certificate handling on Windows. + PEM parsing, loading client certificate and key, server certificate validation + */ + + /* + CERT_CHAIN_ENGINE_CONFIG has additional members in Windows 8.1 + To allow client to be work on pre-8.1 Windows, compile + with corresponding _WIN32_WINNT + */ +#ifdef _WIN32_WINNT +#undef _WIN32_WINNT +#define _WIN32_WINNT 0x0601 +#endif + +#include +#include "schannel_certs.h" +#include +#include +#include +#include +#include +#include +#include "win32_errmsg.h" + + /* + Return GetLastError(), or, if this unexpectedly gives success, + return ERROR_INTERNAL_ERROR. + + Background - in several cases in this module we return GetLastError() + after an Windows function fails. However, we do not want the function to + return success, even if GetLastError() was suddenly 0. + */ +static DWORD get_last_error() +{ + DWORD ret = GetLastError(); + if (ret) + return ret; + + // We generally expect last error to be set API fails. + // thus the debug assertion- + assert(0); + return ERROR_INTERNAL_ERROR; +} + +#define FAIL(...) \ + do{\ + status = get_last_error();\ + ma_format_win32_error(errmsg, errmsg_len, status, __VA_ARGS__);\ + goto cleanup;\ + } while (0) + +/* + Load file into memory. Add null terminator at the end, so it will be a valid C string. +*/ +static char* pem_file_to_string(const char* file, char* errmsg, size_t errmsg_len) +{ + LARGE_INTEGER file_size; + size_t file_bufsize = 0; + size_t total_bytes_read = 0; + char* file_buffer = NULL; + SECURITY_STATUS status = SEC_E_OK; + + HANDLE file_handle = CreateFile(file, GENERIC_READ, FILE_SHARE_READ, NULL, + OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + if (file_handle == INVALID_HANDLE_VALUE) + { + FAIL("failed to open file '%s'", file); + } + + if (!GetFileSizeEx(file_handle, &file_size)) + { + FAIL("GetFileSizeEx failed on '%s'", file); + } + + if (file_size.QuadPart > ULONG_MAX - 1) + { + SetLastError(SEC_E_INVALID_PARAMETER); + FAIL("file '%s' too large", file); + } + + file_bufsize = (size_t)file_size.QuadPart; + file_buffer = (char*)LocalAlloc(0,file_bufsize + 1); + if (!file_buffer) + { + FAIL("LocalAlloc(0,%zu) failed", file_bufsize + 1); + } + + while (total_bytes_read < file_bufsize) + { + DWORD bytes_to_read = (DWORD)(file_bufsize - total_bytes_read); + DWORD bytes_read = 0; + + if (!ReadFile(file_handle, file_buffer + total_bytes_read, + bytes_to_read, &bytes_read, NULL)) + { + FAIL("ReadFile() failed to read file '%s'", file); + } + if (bytes_read == 0) + { + /* Premature EOF -- adjust the bufsize to the new value */ + file_bufsize = total_bytes_read; + } + else + { + total_bytes_read += bytes_read; + } + } + + /* Null terminate the buffer */ + file_buffer[file_bufsize] = '\0'; + +cleanup: + if (file_handle != INVALID_HANDLE_VALUE) + { + CloseHandle(file_handle); + } + if (status) + { + /* Some error happened. */ + LocalFree(file_buffer); + file_buffer = NULL; + } + return file_buffer; +} + + +// Structure for parsing BEGIN/END sections inside pem. +typedef struct _pem_type_desc +{ + const char* begin_tag; + size_t begin_tag_len; + const char* end_tag; + size_t end_tag_len; +} pem_type_desc; + +#define BEGIN_TAG(x) "-----BEGIN " x "-----" +#define END_TAG(x) "\n-----END " x "-----" +#define PEM_SECTION(tag) {BEGIN_TAG(tag), sizeof(BEGIN_TAG(tag))-1, END_TAG(tag), sizeof(END_TAG(tag))-1} + +typedef enum { + PEM_TYPE_CERTIFICATE = 0, + PEM_TYPE_X509_CRL, + PEM_TYPE_RSA_PRIVATE_KEY, + PEM_TYPE_PRIVATE_KEY +} PEM_TYPE; + +static const pem_type_desc pem_sections[] = { + PEM_SECTION("CERTIFICATE"), + PEM_SECTION("X509 CRL"), + PEM_SECTION("RSA PRIVATE KEY"), + PEM_SECTION("PRIVATE KEY") +}; + +/* + Locate a substring in pem for given type, + e.g section between BEGIN CERTIFICATE and END CERTIFICATE + in PEMs base64 format, with header and footer. + + output parameters 'begin' and 'end' are set upon return. + it is possible that functions returns 'begin' != NULL but + 'end' = NULL. This is generally a format error, meaning that + the end tag was not found +*/ +void pem_locate(char* pem_str, + PEM_TYPE type, + char** begin, + char** end) +{ + *begin = NULL; + *end = NULL; + char c; + + const pem_type_desc* desc = &pem_sections[type]; + *begin = strstr(pem_str, desc->begin_tag); + if (!(*begin)) + return; + + // We expect newline after the + // begin tag, LF or CRLF + c = (*begin)[desc->begin_tag_len]; + + if (c != '\r' && c != '\n') + { + *begin = NULL; + return; + } + + *end = strstr(*begin + desc->begin_tag_len + 1, desc->end_tag); + if (!*end) + return; // error, end marker not found + + (*end) += desc->end_tag_len; + return; +} + + +/* + Add certificates, or CRLs from a PEM file to Wincrypt store +*/ +static SECURITY_STATUS add_certs_to_store( + HCERTSTORE trust_store, + const char* file, + PEM_TYPE type, + char* errmsg, + size_t errmsg_len) +{ + char* file_buffer = NULL; + char* cur = NULL; + SECURITY_STATUS status = SEC_E_OK; + CRL_CONTEXT* crl_context = NULL; + CERT_CONTEXT* cert_context = NULL; + char* begin; + char* end; + + file_buffer = pem_file_to_string(file, errmsg, errmsg_len); + if (!file_buffer) + goto cleanup; + + for (cur = file_buffer; ; cur = end) + { + pem_locate(cur, type, &begin, &end); + + if (!begin) + break; + + if (!end) + { + SetLastError(SEC_E_INVALID_PARAMETER); + FAIL("Invalid PEM file '%s', missing end marker corresponding to begin marker '%s' at offset %zu", + file, pem_sections[type].begin_tag, (size_t)(begin - file_buffer)); + } + CERT_BLOB cert_blob; + void* context = NULL; + DWORD actual_content_type = 0; + + cert_blob.pbData = (BYTE*)begin; + cert_blob.cbData = (DWORD)(end - begin); + if (!CryptQueryObject( + CERT_QUERY_OBJECT_BLOB, &cert_blob, + CERT_QUERY_CONTENT_FLAG_CERT | CERT_QUERY_CONTENT_FLAG_CRL, + CERT_QUERY_FORMAT_FLAG_ALL, 0, NULL, &actual_content_type, + NULL, NULL, NULL, (const void**)&context)) + { + FAIL("failed to extract certificate from PEM file '%s'",file); + } + + if (!context) + { + SetLastError(SEC_E_INTERNAL_ERROR); + FAIL("unexpected result from CryptQueryObject(),cert_context is NULL" + " after successful completion, file '%s'", + file); + } + + if (actual_content_type == CERT_QUERY_CONTENT_CERT) + { + CERT_CONTEXT* cert_context = (CERT_CONTEXT*)context; + if (!CertAddCertificateContextToStore( + trust_store, cert_context, + CERT_STORE_ADD_ALWAYS, NULL)) + { + FAIL("CertAddCertificateContextToStore failed"); + } + } + else if (actual_content_type == CERT_QUERY_CONTENT_CRL) + { + CRL_CONTEXT* crl_context = (CRL_CONTEXT*)context; + if (!CertAddCRLContextToStore( + trust_store, crl_context, + CERT_STORE_ADD_ALWAYS, NULL)) + { + FAIL("CertAddCRLContextToStore() failed"); + } + } + } +cleanup: + LocalFree(file_buffer); + if (cert_context) + CertFreeCertificateContext(cert_context); + if (crl_context) + CertFreeCRLContext(crl_context); + return status; +} + +/* +Add a directory to store, i.e try to load all files. +(extract certificates and add them to store) + +@return 0 on success, error only if directory is invalid. +*/ +SECURITY_STATUS add_dir_to_store(HCERTSTORE trust_store, const char* dir, + PEM_TYPE type, char* errmsg, size_t errmsg_len) +{ + WIN32_FIND_DATAA ffd; + char path[MAX_PATH]; + char pattern[MAX_PATH]; + DWORD dwAttr; + HANDLE hFind = INVALID_HANDLE_VALUE; + SECURITY_STATUS status = SEC_E_OK; + + if ((dwAttr = GetFileAttributes(dir)) == INVALID_FILE_ATTRIBUTES) + { + SetLastError(SEC_E_INVALID_PARAMETER); + FAIL("directory '%s' does not exist", dir); + } + if (!(dwAttr & FILE_ATTRIBUTE_DIRECTORY)) + { + SetLastError(SEC_E_INVALID_PARAMETER); + FAIL("'%s' is not a directory", dir); + } + sprintf_s(pattern, sizeof(pattern), "%s\\*", dir); + hFind = FindFirstFile(pattern, &ffd); + if (hFind == INVALID_HANDLE_VALUE) + { + FAIL("FindFirstFile(%s) failed",pattern); + } + do + { + if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) + continue; + sprintf_s(path, sizeof(path), "%s\\%s", dir, ffd.cFileName); + + // ignore error from add_certs_to_store(), not all file + // maybe PEM. + add_certs_to_store(trust_store, path, type, errmsg, + errmsg_len); + } while (FindNextFile(hFind, &ffd) != 0); + +cleanup: + if (hFind != INVALID_HANDLE_VALUE) + FindClose(hFind); + + return status; +} + +/* Count certificates in store. */ +static int count_certificates(HCERTSTORE store) +{ + int num_certs = 0; + PCCERT_CONTEXT c = NULL; + + while ((c = CertEnumCertificatesInStore(store, c))) + num_certs++; + + return num_certs; +} + +/** + Creates certificate store with user defined CA chain and/or CRL. + Loads PEM certificate from files or directories. + + If only CRLFile/CRLPath is defined, the "system" store is duplicated, + and new CRLs are added to it. + + If CAFile/CAPAth is defined, then new empty store is created, and CAs + (and CRLs, if defined), are added to it. + + The function throws an error, if none of the files in CAFile/CAPath have a valid certificate. + It is also an error if CRLFile does not exist. +*/ +SECURITY_STATUS schannel_create_store( + const char* CAFile, + const char* CAPath, + const char* CRLFile, + const char* CRLPath, + HCERTSTORE* out_store, + char* errmsg, + size_t errmsg_len) +{ + + HCERTSTORE store = NULL; + HCERTSTORE system_store = NULL; + int status = SEC_E_OK; + + *out_store = NULL; + if (!CAFile && !CAPath && !CRLFile && !CRLPath) + { + /* Nothing to do, caller will use default store*/ + *out_store = NULL; + return SEC_E_OK; + } + if (CAFile || CAPath) + { + /* Open the certificate store */ + store = CertOpenStore(CERT_STORE_PROV_MEMORY, 0, (HCRYPTPROV)NULL, + CERT_STORE_CREATE_NEW_FLAG, NULL); + if (!store) + { + FAIL("CertOpenStore failed for memory store"); + } + } + else if (CRLFile || CRLPath) + { + /* Only CRL was provided, copy system store, add revocation list to + * it. */ + system_store = + CertOpenStore(CERT_STORE_PROV_SYSTEM, 0, (HCRYPTPROV_LEGACY)NULL, + CERT_SYSTEM_STORE_CURRENT_USER, L"MY"); + if (!system_store) + { + FAIL("CertOpenStore failed for system store"); + } + + store = CertDuplicateStore(system_store); + if (!store) + { + FAIL("CertDuplicateStore failed"); + } + } + + if (CAFile) + { + status = add_certs_to_store(store, CAFile, + PEM_TYPE_CERTIFICATE, errmsg, errmsg_len); + if (status) + goto cleanup; + } + if (CAPath) + { + status = add_dir_to_store(store, CAPath, + PEM_TYPE_CERTIFICATE, errmsg, errmsg_len); + if (status) + goto cleanup; + } + + if ((CAFile || CAPath) && store && !count_certificates(store)) + { + SetLastError(SEC_E_INVALID_PARAMETER); + FAIL("no valid certificates were found, CAFile='%s', CAPath='%s'", + CAFile ? CAFile : "", CAPath ? CAPath : ""); + } + + if (CRLFile) + { + status = add_certs_to_store(store, CRLFile, PEM_TYPE_X509_CRL, + errmsg, errmsg_len); + } + if (CRLPath) + { + status = add_dir_to_store(store, CRLPath, PEM_TYPE_X509_CRL, + errmsg, errmsg_len); + } + +cleanup: + if (system_store) + CertCloseStore(system_store, 0); + if (status && store) + { + CertCloseStore(store, 0); + store = NULL; + } + *out_store = store; + return status; +} + +/* + The main verification logic. + Taken almost completely from Windows 2003 Platform SDK 2003 + (Samples\Security\SSPI\SSL\WebClient.c) + + The only difference here is is usage of custom store + and chain engine. +*/ +static SECURITY_STATUS VerifyServerCertificate( + PCCERT_CONTEXT pServerCert, + HCERTSTORE hStore, + LPWSTR pwszServerName, + DWORD dwRevocationCheckFlags, + DWORD dwVerifyFlags, + LPSTR errmsg, + size_t errmsg_len) +{ + SSL_EXTRA_CERT_CHAIN_POLICY_PARA polExtra; + CERT_CHAIN_POLICY_PARA PolicyPara; + CERT_CHAIN_POLICY_STATUS PolicyStatus; + CERT_CHAIN_PARA ChainPara; + HCERTCHAINENGINE hChainEngine = NULL; + PCCERT_CHAIN_CONTEXT pChainContext = NULL; + LPSTR rgszUsages[] = { szOID_PKIX_KP_SERVER_AUTH, + szOID_SERVER_GATED_CRYPTO, + szOID_SGC_NETSCAPE }; + DWORD cUsages = sizeof(rgszUsages) / sizeof(LPSTR); + SECURITY_STATUS status = SEC_E_OK; + + if (pServerCert == NULL) + { + SetLastError(SEC_E_WRONG_PRINCIPAL); + FAIL("Invalid parameter pServerCert passed to VerifyServerCertificate"); + } + + ZeroMemory(&ChainPara, sizeof(ChainPara)); + ChainPara.cbSize = sizeof(ChainPara); + ChainPara.RequestedUsage.dwType = USAGE_MATCH_TYPE_OR; + ChainPara.RequestedUsage.Usage.cUsageIdentifier = cUsages; + ChainPara.RequestedUsage.Usage.rgpszUsageIdentifier = rgszUsages; + + if (hStore) + { + CERT_CHAIN_ENGINE_CONFIG EngineConfig = { 0 }; + EngineConfig.cbSize = sizeof(EngineConfig); + EngineConfig.hExclusiveRoot = hStore; + if (!CertCreateCertificateChainEngine(&EngineConfig, &hChainEngine)) + { + FAIL("CertCreateCertificateChainEngine failed"); + } + } + + if (!CertGetCertificateChain( + hChainEngine, + pServerCert, + NULL, + pServerCert->hCertStore, + &ChainPara, + dwRevocationCheckFlags, + NULL, + &pChainContext)) + { + FAIL("CertGetCertificateChain failed"); + goto cleanup; + } + + // Validate certificate chain. + ZeroMemory(&polExtra, sizeof(SSL_EXTRA_CERT_CHAIN_POLICY_PARA)); + polExtra.cbStruct = sizeof(SSL_EXTRA_CERT_CHAIN_POLICY_PARA); + polExtra.dwAuthType = AUTHTYPE_SERVER; + polExtra.fdwChecks = dwVerifyFlags; + polExtra.pwszServerName = pwszServerName; + + memset(&PolicyPara, 0, sizeof(PolicyPara)); + PolicyPara.cbSize = sizeof(PolicyPara); + PolicyPara.pvExtraPolicyPara = &polExtra; + + memset(&PolicyStatus, 0, sizeof(PolicyStatus)); + PolicyStatus.cbSize = sizeof(PolicyStatus); + + if (!CertVerifyCertificateChainPolicy( + CERT_CHAIN_POLICY_SSL, + pChainContext, + &PolicyPara, + &PolicyStatus)) + { + FAIL("CertVerifyCertificateChainPolicy failed"); + } + + if (PolicyStatus.dwError) + { + SetLastError(PolicyStatus.dwError); + FAIL("Server certificate validation failed"); + } + +cleanup: + if (hChainEngine) + { + CertFreeCertificateChainEngine(hChainEngine); + } + if (pChainContext) + { + CertFreeCertificateChain(pChainContext); + } + return status; +} + + +void schannel_free_store(HCERTSTORE store) +{ + if (store) + CertCloseStore(store, 0); +} + + +/* +Verify server certificate against a wincrypt store +@return 0 - success, otherwise error occurred. +*/ +SECURITY_STATUS schannel_verify_server_certificate( + const CERT_CONTEXT* cert, + HCERTSTORE store, + BOOL check_revocation, + const char* server_name, + BOOL check_server_name, + char* errmsg, + size_t errmsg_len) +{ + SECURITY_STATUS status = SEC_E_OK; + wchar_t* wserver_name = NULL; + DWORD dwVerifyFlags; + DWORD dwRevocationFlags; + + if (check_server_name) + { + int cchServerName = (int)strlen(server_name) + 1; + wserver_name = (wchar_t*)LocalAlloc(0,sizeof(wchar_t) * cchServerName); + if (!wserver_name) + { + FAIL("LocalAlloc() failed"); + } + if (MultiByteToWideChar(CP_UTF8, 0, server_name, cchServerName, wserver_name, cchServerName) < 0) + { + FAIL("MultiByteToWideChar() failed"); + } + } + + dwVerifyFlags = 0; + dwRevocationFlags = 0; + if (check_revocation) + dwRevocationFlags |= CERT_CHAIN_REVOCATION_CHECK_CHAIN_EXCLUDE_ROOT | CERT_CHAIN_REVOCATION_CHECK_CACHE_ONLY; + if (!check_server_name) + dwVerifyFlags |= SECURITY_FLAG_IGNORE_CERT_CN_INVALID; + + status = VerifyServerCertificate(cert, store, wserver_name ? wserver_name : L"SERVER_NAME", + dwRevocationFlags, dwVerifyFlags, errmsg, errmsg_len); + +cleanup: + LocalFree(wserver_name); + return status; +} + + +/* Attach private key (in PEM format) to client certificate */ +static SECURITY_STATUS load_private_key(CERT_CONTEXT* cert, char* private_key_str, size_t len, char* errmsg, size_t errmsg_len) +{ + DWORD derlen = (DWORD)len; + BYTE* derbuf = NULL; + DWORD keyblob_len = 0; + BYTE* keyblob = NULL; + HCRYPTPROV hProv = 0; + HCRYPTKEY hKey = 0; + CERT_KEY_CONTEXT cert_key_context = { 0 }; + PCRYPT_PRIVATE_KEY_INFO pki = NULL; + DWORD pki_len = 0; + SECURITY_STATUS status = SEC_E_OK; + + derbuf = LocalAlloc(0, derlen); + if (!derbuf) + { + FAIL("LocalAlloc failed"); + } + + if (!CryptStringToBinaryA(private_key_str, (DWORD)len, CRYPT_STRING_BASE64HEADER, derbuf, &derlen, NULL, NULL)) + { + FAIL("Failed to convert BASE64 private key"); + } + + /* + To accommodate for both "BEGIN PRIVATE KEY" vs "BEGIN RSA PRIVATE KEY" + sections in PEM, we try to decode with PKCS_PRIVATE_KEY_INFO first, + and, if it fails, with PKCS_RSA_PRIVATE_KEY flag. + */ + if (CryptDecodeObjectEx( + X509_ASN_ENCODING, + PKCS_PRIVATE_KEY_INFO, + derbuf, derlen, + CRYPT_DECODE_ALLOC_FLAG, + NULL, &pki, &pki_len)) + { + // convert private key info to RSA private key blob + if (!CryptDecodeObjectEx( + X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, + PKCS_RSA_PRIVATE_KEY, + pki->PrivateKey.pbData, + pki->PrivateKey.cbData, + CRYPT_DECODE_ALLOC_FLAG, + NULL, &keyblob, &keyblob_len)) + { + FAIL("Failed to parse private key"); + } + } + else if (!CryptDecodeObjectEx( + X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, + PKCS_RSA_PRIVATE_KEY, + derbuf, derlen, + CRYPT_DECODE_ALLOC_FLAG, NULL, + &keyblob, &keyblob_len)) + { + FAIL("Failed to parse private key"); + } + + if (!CryptAcquireContext(&hProv, NULL, MS_ENHANCED_PROV, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) + { + FAIL("CryptAcquireContext failed"); + } + + if (!CryptImportKey(hProv, keyblob, keyblob_len, 0, 0, (HCRYPTKEY*)&hKey)) + { + FAIL("CryptImportKey failed"); + } + cert_key_context.hCryptProv = hProv; + cert_key_context.dwKeySpec = AT_KEYEXCHANGE; + cert_key_context.cbSize = sizeof(cert_key_context); + + /* assign private key to certificate context */ + if (!CertSetCertificateContextProperty(cert, CERT_KEY_CONTEXT_PROP_ID, + CERT_STORE_NO_CRYPT_RELEASE_FLAG, + &cert_key_context)) + { + FAIL("CertSetCertificateContextProperty failed"); + } + +cleanup: + LocalFree(derbuf); + LocalFree(keyblob); + LocalFree(pki); + if (hKey) + CryptDestroyKey(hKey); + if (status) + { + if (hProv) + CryptReleaseContext(hProv, 0); + } + return status; +} + +/* + Given PEM strings for certificate and private key, + create a client certificate* +*/ +static CERT_CONTEXT* create_client_certificate_mem( + char* cert_file_content, + char* key_file_content, + char* errmsg, + size_t errmsg_len) +{ + CERT_CONTEXT* ctx = NULL; + char* begin; + char* end; + CERT_BLOB cert_blob; + DWORD actual_content_type = 0; + SECURITY_STATUS status = SEC_E_OK; + + /* Parse certificate */ + pem_locate(cert_file_content, PEM_TYPE_CERTIFICATE, + &begin, &end); + + if (!begin || !end) + { + SetLastError(SEC_E_INVALID_PARAMETER); + FAIL("Client certificate not found in PEM file"); + } + + cert_blob.pbData = (BYTE*)begin; + cert_blob.cbData = (DWORD)(end - begin); + if (!CryptQueryObject( + CERT_QUERY_OBJECT_BLOB, &cert_blob, + CERT_QUERY_CONTENT_FLAG_CERT, + CERT_QUERY_FORMAT_FLAG_ALL, 0, NULL, &actual_content_type, + NULL, NULL, NULL, (const void**)&ctx)) + { + FAIL("Can't parse client certficate"); + } + + /* Parse key */ + PEM_TYPE types[] = { PEM_TYPE_RSA_PRIVATE_KEY, PEM_TYPE_PRIVATE_KEY }; + for (int i = 0; i < sizeof(types) / sizeof(types[0]); i++) + { + pem_locate(key_file_content, types[i], &begin, &end); + if (begin && end) + { + /* Assign key to certificate.*/ + status = load_private_key(ctx, begin, (end - begin), errmsg, errmsg_len); + goto cleanup; + } + } + + if (!begin || !end) + { + SetLastError(SEC_E_INVALID_PARAMETER); + FAIL("Client private key not found in PEM"); + } + +cleanup: + if (status && ctx) + { + CertFreeCertificateContext(ctx); + ctx = NULL; + } + return ctx; +} + + +/* Given cert and key, as PEM file names, create a client certificate */ +CERT_CONTEXT* schannel_create_cert_context(char* cert_file, char* key_file, char* errmsg, size_t errmsg_len) +{ + CERT_CONTEXT* ctx = NULL; + char* key_file_content = NULL; + char* cert_file_content = NULL; + + cert_file_content = pem_file_to_string(cert_file, errmsg, errmsg_len); + + if (!cert_file_content) + goto cleanup; + + if (cert_file == key_file) + { + key_file_content = cert_file_content; + } + else + { + key_file_content = pem_file_to_string(key_file, errmsg, errmsg_len); + if (!key_file_content) + goto cleanup; + } + + ctx = create_client_certificate_mem(cert_file_content, key_file_content, errmsg, errmsg_len); + +cleanup: + LocalFree(cert_file_content); + if (cert_file != key_file) + LocalFree(key_file_content); + + return ctx; +} + +/* + Free certificate, and all resources, created by schannel_create_cert_context() +*/ +void schannel_free_cert_context(const CERT_CONTEXT* cert) +{ + /* release provider handle which was acquires in load_private_key() */ + CERT_KEY_CONTEXT cert_key_context = { 0 }; + cert_key_context.cbSize = sizeof(cert_key_context); + DWORD cbData = sizeof(CERT_KEY_CONTEXT); + HCRYPTPROV hProv = 0; + + if (CertGetCertificateContextProperty(cert, CERT_KEY_CONTEXT_PROP_ID, &cert_key_context, &cbData)) + { + hProv = cert_key_context.hCryptProv; + } + CertFreeCertificateContext(cert); + if (hProv) + { + CryptReleaseContext(cert_key_context.hCryptProv, 0); + } +} diff --git a/vendor/MDBC/libmariadb/secure/schannel_certs.h b/vendor/MDBC/libmariadb/secure/schannel_certs.h new file mode 100644 index 00000000..67a8d11e --- /dev/null +++ b/vendor/MDBC/libmariadb/secure/schannel_certs.h @@ -0,0 +1,53 @@ +/************************************************************************************ + Copyright (C) 2019 MariaDB Corporation Ab + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not see + or write to the Free Software Foundation, Inc., + 51 Franklin St., Fifth Floor, Boston, MA 02110, USA + + *************************************************************************************/ + +#pragma once +#include +#include + +extern SECURITY_STATUS schannel_create_store( + const char* CAFile, + const char* CAPath, + const char* CRLFile, + const char* CRLPath, + HCERTSTORE* store, + char* errmsg, + size_t errmsg_len +); + +extern SECURITY_STATUS schannel_verify_server_certificate( + const CERT_CONTEXT* cert, + HCERTSTORE store, + BOOL check_revocation, + const char* server_name, + BOOL check_server_name, + char* errmsg, + size_t errmsg_len); + +extern void schannel_free_store(HCERTSTORE store); + +extern CERT_CONTEXT* schannel_create_cert_context( + char* cert_file, + char* key_file, + char* errmsg, + size_t errmsg_len); + +extern void schannel_free_cert_context(const CERT_CONTEXT* cert); + diff --git a/vendor/MDBC/libmariadb/secure/win_crypt.c b/vendor/MDBC/libmariadb/secure/win_crypt.c new file mode 100644 index 00000000..77194e8a --- /dev/null +++ b/vendor/MDBC/libmariadb/secure/win_crypt.c @@ -0,0 +1,103 @@ +/* + Copyright (C) 2018 MariaDB Corporation AB + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not see + or write to the Free Software Foundation, Inc., + 51 Franklin St., Fifth Floor, Boston, MA 02110, USA +*/ +#include +#include +#include +#include + +BCRYPT_ALG_HANDLE Sha256Prov= 0; +BCRYPT_ALG_HANDLE Sha512Prov= 0; +BCRYPT_ALG_HANDLE RsaProv= 0; + +static LPCWSTR ma_hash_get_algorithm(unsigned int alg, BCRYPT_ALG_HANDLE *algHdl) +{ + switch(alg) + { + case MA_HASH_SHA256: + *algHdl= Sha256Prov; + return BCRYPT_SHA256_ALGORITHM; + case MA_HASH_SHA512: + *algHdl= Sha512Prov; + return BCRYPT_SHA512_ALGORITHM; + default: + *algHdl= 0; + return NULL; + } +} + +MA_HASH_CTX *ma_hash_new(unsigned int algorithm, MA_HASH_CTX *ctx) +{ + MA_HASH_CTX *newctx= ctx; + DWORD cbObjSize, cbData; + LPCWSTR alg; + BCRYPT_ALG_HANDLE algHdl= 0; + + alg= ma_hash_get_algorithm(algorithm, &algHdl); + + if (!alg || !algHdl) + return NULL; + + if (BCryptGetProperty(algHdl, BCRYPT_OBJECT_LENGTH, + (PBYTE)&cbObjSize, sizeof(DWORD), + &cbData, 0) < 0) + goto error; + + if (!newctx) + { + newctx= (MA_HASH_CTX *)calloc(1, sizeof(MA_HASH_CTX)); + newctx->free_me= 1; + } + else + memset(newctx, 0, sizeof(MA_HASH_CTX)); + + newctx->hashObject= (PBYTE)malloc(cbObjSize); + newctx->digest_len= (DWORD)ma_hash_digest_size(algorithm); + BCryptCreateHash(algHdl, &newctx->hHash, newctx->hashObject, cbObjSize, NULL, 0, 0); + + return newctx; +error: + if (newctx && !ctx) + free(newctx); + return NULL; +} + +void ma_hash_free(MA_HASH_CTX *ctx) +{ + if (ctx) + { + if (ctx->hHash) + BCryptDestroyHash(ctx->hHash); + if (ctx->hashObject) + free(ctx->hashObject); + if (ctx->free_me) + free(ctx); + } +} + +void ma_hash_input(MA_HASH_CTX *ctx, + const unsigned char *buffer, + size_t len) +{ + BCryptHashData(ctx->hHash, (PUCHAR)buffer, (LONG)len, 0); +} + +void ma_hash_result(MA_HASH_CTX *ctx, unsigned char *digest) +{ + BCryptFinishHash(ctx->hHash, digest, ctx->digest_len, 0); +} diff --git a/vendor/MDBC/libmariadb/win32_errmsg.c b/vendor/MDBC/libmariadb/win32_errmsg.c new file mode 100644 index 00000000..eaa5872f --- /dev/null +++ b/vendor/MDBC/libmariadb/win32_errmsg.c @@ -0,0 +1,137 @@ +/************************************************************************************ + Copyright (C) 2019 MariaDB + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not see + or write to the Free Software Foundation, Inc., + 51 Franklin St., Fifth Floor, Boston, MA 02110, USA + + *************************************************************************************/ + +#include +#include +#include +#include + +/* + Format Windows error, with optional text. + + For "known" errors we also output their symbolic error constant, e.g + CERT_E_CN_NO_MATCH in addition to numeric value. + + We also try to output English text for all error messages, as not to mess up + with encodings. +*/ +void ma_format_win32_error(char* buf, size_t buflen, DWORD code, _Printf_format_string_ const char* fmt, ...) +{ + char* cur = buf; + char* end = cur + buflen; + *cur = 0; + if (fmt) + { + va_list vargs; + va_start(vargs, fmt); + cur += vsnprintf_s(cur, end - cur, _TRUNCATE, fmt, vargs); + va_end(vargs); + } + + if (code == 0) + return; + + static struct map_entry + { + DWORD code; + const char* sym; + const char* msg; + } + map[] = + { +#define ENTRY(x, y) {x,#x, y} + ENTRY(SEC_E_WRONG_PRINCIPAL, "The target principal name is incorrect"), + ENTRY(CERT_E_CN_NO_MATCH,"The certificate's CN name does not match the passed value"), + ENTRY(SEC_E_UNTRUSTED_ROOT,"The certificate chain was issued by an authority that is not trusted"), + ENTRY(TRUST_E_CERT_SIGNATURE,"The signature of the certificate cannot be verified"), + ENTRY(SEC_E_CERT_EXPIRED,"The received certificate has expired"), + ENTRY(CERT_E_EXPIRED,"A required certificate is not within its validity period when verifying against the current system clock or the timestamp in the signed file"), + ENTRY(CRYPT_E_NO_REVOCATION_CHECK, "The revocation function was unable to check revocation for the certificate"), + ENTRY(CRYPT_E_REVOCATION_OFFLINE,"The revocation function was unable to check revocation because the revocation server was offline"), + ENTRY(CRYPT_E_REVOKED,"The certificate is revoked"), + ENTRY(SEC_E_CERT_UNKNOWN,"An unknown error occurred while processing the certificate"), + ENTRY(CERT_E_ROLE," A certificate that can only be used as an end-entity is being used as a CA or vice versa"), + ENTRY(CERT_E_WRONG_USAGE,"The certificate is not valid for the requested usage"), + ENTRY(SEC_E_ILLEGAL_MESSAGE, "The message received was unexpected or badly formatted"), + ENTRY(CERT_E_VALIDITYPERIODNESTING,"The validity periods of the certification chain do not nest correctly"), + ENTRY(CERT_E_PATHLENCONST,"A path length constraint in the certification chain has been violated"), + ENTRY(CERT_E_CRITICAL,"A certificate contains an unknown extension that is marked 'critical'"), + ENTRY(CERT_E_PURPOSE,"A certificate being used for a purpose other than the ones specified by its CA"), + ENTRY(CERT_E_ISSUERCHAINING,"A parent of a given certificate in fact did not issue that child certificate"), + ENTRY(CERT_E_MALFORMED, "A certificate is missing or has an empty value for an important field, such as a subject or issuer name"), + ENTRY(CERT_E_CHAINING,"A certificate chain could not be built to a trusted root authority"), + ENTRY(TRUST_E_FAIL," Generic trust failure"), + ENTRY(CERT_E_UNTRUSTEDTESTROOT,"The certification path terminates with the test root which is not trusted with the current policy settings"), + ENTRY(CERT_E_UNTRUSTEDROOT,"A certificate chain processed, but terminated in a root certificate which is not trusted by the trust provider"), + ENTRY(CERT_E_REVOCATION_FAILURE,"The revocation process could not continue - the certificate(s) could not be checked"), + ENTRY(SEC_E_ILLEGAL_MESSAGE, "The message received was unexpected or badly formatted"), + ENTRY(SEC_E_UNTRUSTED_ROOT, "Untrusted root certificate"), + ENTRY(SEC_E_BUFFER_TOO_SMALL, "Buffer too small"), + ENTRY(SEC_E_CRYPTO_SYSTEM_INVALID, "Cipher is not supported"), + ENTRY(SEC_E_INSUFFICIENT_MEMORY, "Out of memory"), + ENTRY(SEC_E_OUT_OF_SEQUENCE, "Invalid message sequence"), + ENTRY(SEC_E_DECRYPT_FAILURE, "The specified data could not be decrypted"), + ENTRY(SEC_I_INCOMPLETE_CREDENTIALS, "Incomplete credentials"), + ENTRY(SEC_E_ENCRYPT_FAILURE, "The specified data could not be encrypted"), + ENTRY(SEC_I_CONTEXT_EXPIRED, "The context has expired and can no longer be used"), + ENTRY(SEC_E_ALGORITHM_MISMATCH, "no cipher match"), + ENTRY(SEC_E_NO_CREDENTIALS, "no credentials"), + ENTRY(SEC_E_INVALID_TOKEN, "The token supplied to function is invalid"), + ENTRY(SEC_E_UNSUPPORTED_FUNCTION,"The function requested is not supported") + }; + + struct map_entry* entry = NULL; + + if (cur > buf && cur[-1] != ' ' && cur[-1] != '.') + { + strncpy_s(cur,end-cur, ". ", _TRUNCATE); + cur += 2; + } + + for (size_t i = 0; i < sizeof(map) / sizeof(map[0]); i++) + { + if (code == map[i].code) + { + entry = &map[i]; + break; + } + } + if (cur > end - 20) + return; + if (entry) + { + sprintf_s(cur, end - cur, "%s. Error 0x%08lX(%s)", entry->msg, code, entry->sym); + } + else + { + cur += FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, code, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), + cur, (DWORD)(end - cur), NULL); + while (cur > buf && (*cur == '\0' || *cur == '\n' || *cur == '\r' || *cur == '.')) + cur--; + if (*cur) + { + cur++; + *cur = 0; + } + sprintf_s(cur, end - cur, ". Error %lu/0x%08lX", code, code); + } +} + diff --git a/vendor/MDBC/libmariadb/win32_errmsg.h b/vendor/MDBC/libmariadb/win32_errmsg.h new file mode 100644 index 00000000..865d9928 --- /dev/null +++ b/vendor/MDBC/libmariadb/win32_errmsg.h @@ -0,0 +1,2 @@ +#include +void ma_format_win32_error(char* buf, size_t buflen, DWORD code, _Printf_format_string_ const char* fmt, ...); diff --git a/vendor/MDBC/man/CMakeLists.txt b/vendor/MDBC/man/CMakeLists.txt new file mode 100644 index 00000000..227b233d --- /dev/null +++ b/vendor/MDBC/man/CMakeLists.txt @@ -0,0 +1,123 @@ +SET(CC_MAN_PAGES_3 +mariadb_cancel.3 +mariadb_connection.3 +mariadb_dyncol_check.3 +mariadb_dyncol_column_cmp_named.3 +mariadb_dyncol_column_count.3 +mariadb_dyncol_create_many_named.3 +mariadb_dyncol_create_many_num.3 +mariadb_dyncol_exists_named.3 +mariadb_dyncol_exists_num.3 +mariadb_dyncol_free.3 +mariadb_dyncol_list_named.3 +mariadb_dyncol_list_num.3 +mariadb_dyncol_unpack.3 +mariadb_dyncol_update_many_named.3 +mariadb_dyncol_update_many_num.3 +mariadb_get_infov.3 +mariadb_reconnect.3 +mariadb_rpl_close.3 +mariadb_rpl_fetch.3 +mariadb_rpl_get_optionsv.3 +mariadb_rpl_open.3 +mariadb_rpl_optionsv.3 +mariadb_stmt_execute_direct.3 +mariadb_stmt_fetch_fields.3 +mysql_affected_rows.3 +mysql_autocommit.3 +mysql_change_user.3 +mysql_close.3 +mysql_commit.3 +mysql_data_seek.3 +mysql_errno.3 +mysql_error.3 +mysql_fetch_field.3 +mysql_fetch_field_direct.3 +mysql_fetch_fields.3 +mysql_fetch_lengths.3 +mysql_fetch_row.3 +mysql_field_count.3 +mysql_field_seek.3 +mysql_field_tell.3 +mysql_free_result.3 +mysql_get_character_set_info.3 +mysql_get_client_info.3 +mysql_get_client_version.3 +mysql_get_host_info.3 +mysql_get_proto_info.3 +mysql_get_server_info.3 +mysql_get_server_version.3 +mysql_get_socket.3 +mysql_get_ssl_cipher.3 +mysql_hex_string.3 +mysql_info.3 +mysql_init.3 +mysql_kill.3 +mysql_more_results.3 +mysql_next_result.3 +mysql_num_fields.3 +mysql_num_rows.3 +mysql_options.3 +mysql_options4.3 +mysql_optionsv.3 +mysql_ping.3 +mysql_query.3 +mysql_read_query_result.3 +mysql_real_connect.3 +mysql_real_escape_string.3 +mysql_real_query.3 +mysql_refresh.3 +mysql_reset_connection.3 +mysql_rollback.3 +mysql_row_seek.3 +mysql_row_tell.3 +mysql_select_db.3 +mysql_send_query.3 +mysql_server_end.3 +mysql_server_init.3 +mysql_session_track_get_first.3 +mysql_session_track_get_next.3 +mysql_set_character_set.3 +mysql_set_server_option.3 +mysql_shutdown.3 +mysql_sqlstate.3 +mysql_ssl_set.3 +mysql_stat.3 +mysql_stmt_affected_rows.3 +mysql_stmt_attr_get.3 +mysql_stmt_attr_set.3 +mysql_stmt_bind_param.3 +mysql_stmt_bind_result.3 +mysql_stmt_close.3 +mysql_stmt_data_seek.3 +mysql_stmt_errno.3 +mysql_stmt_error.3 +mysql_stmt_execute.3 +mysql_stmt_fetch.3 +mysql_stmt_fetch_column.3 +mysql_stmt_field_count.3 +mysql_stmt_free_result.3 +mysql_stmt_init.3 +mysql_stmt_insert_id.3 +mysql_stmt_more_results.3 +mysql_stmt_next_result.3 +mysql_stmt_num_rows.3 +mysql_stmt_param_count.3 +mysql_stmt_param_metadata.3 +mysql_stmt_prepare.3 +mysql_stmt_reset.3 +mysql_stmt_result_metadata.3 +mysql_stmt_row_seek.3 +mysql_stmt_row_tell.3 +mysql_stmt_send_long_data.3 +mysql_stmt_sqlstate.3 +mysql_stmt_store_result.3 +mysql_stmt_warning_count.3 +mysql_store_result.3 +mysql_thread_end.3 +mysql_thread_id.3 +mysql_thread_init.3 +mysql_use_result.3 +mysql_warning_count.3) + +INSTALL(FILES ${CC_MAN_PAGES_3} DESTINATION ${INSTALL_MANDIR}/man3 COMPONENT ManPagesDevelopment) diff --git a/vendor/MDBC/man/mariadb_cancel.3 b/vendor/MDBC/man/mariadb_cancel.3 new file mode 100644 index 00000000..debe4a90 --- /dev/null +++ b/vendor/MDBC/man/mariadb_cancel.3 @@ -0,0 +1,36 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mariadb_cancel" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mariadb_cancel \- Immediately aborts a connection +.SS Synopsis +.IP +.nf +\f[C] +#include + +int mariadb_cancel(MYSQL * mysql); +\f[R] +.fi +.SS Description +.PP +Immediately aborts a connection by making all subsequent read/write +operations fail. +\f[C]mariadb_cancel()\f[R] does not invalidate memory used for +\f[C]mysql\f[R] structure, nor close any communication channels. +To free the memory, \f[B]mysql_close(3)\f[R] must be called. +\f[C]mariadb_cancel()\f[R] is useful to break long queries in situations +where sending KILL is not possible. +.SS Parameter +.PP +\f[C]mysql\f[R] \- mysql handle, which was previously allocated by +\f[B]mysql_init(3)\f[R] and connected by +\f[B]mysql_real_connect(3)\f[R]. +.SS Return value +.PP +Returns zero on success or a non\-zero value on error. +.SS History +.PP +\f[C]mariadb_cancel()\f[R] was added in Connector/C 3.0 diff --git a/vendor/MDBC/man/mariadb_connection.3 b/vendor/MDBC/man/mariadb_connection.3 new file mode 100644 index 00000000..958f83c6 --- /dev/null +++ b/vendor/MDBC/man/mariadb_connection.3 @@ -0,0 +1,29 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mariadb_connection" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mariadb_connection \- checks if the client is connected to a MariaDB +database server +.SS Synopsis +.IP +.nf +\f[C] +#include + +my_bool mariadb_connection(MYSQL * mysql); +\f[R] +.fi +.SS Description +.PP +Checks if the client is connected to a MariaDB or MySQL database server. +.SS Parameter +.PP +\f[C]mysql\f[R] \- mysql handle, which was previously allocated by +\f[B]mysql_init(3)\f[R] and connected by +\f[B]mysql_real_connect(3)\f[R]. +.SS Return value +.PP +Returns a non zero value if connected to a MariaDB database server, +otherwise zero. diff --git a/vendor/MDBC/man/mariadb_dyncol_check.3 b/vendor/MDBC/man/mariadb_dyncol_check.3 new file mode 100644 index 00000000..197ee145 --- /dev/null +++ b/vendor/MDBC/man/mariadb_dyncol_check.3 @@ -0,0 +1,32 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mariadb_dyncol_check" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mariadb_dyncol_check \- Checks if a dynamic column has correct format +.SS Synopsis +.IP +.nf +\f[C] +#include + +enum enum_dyncol_func_result +mariadb_dyncol_check(DYNAMIC_COLUMN *str); +\f[R] +.fi +.SS Description +.PP +The function \f[C]mariadb_dyncol_check()\f[R] checks if a dynamic column +has correct format. +This can be used e.g.\ to check if a blob contains a dynamic column. +.SS Parameter +.IP \[bu] 2 +\f[C]str\f[R]\- pointer to a \f[C]DYNAMIC_COLUMN\f[R] structure. +.SS Return value +.PP +Returns \f[C]ER_DYNCOL_OK\f[R] if the dynamic column has correct format, +otherwise \f[C]ER_DYNCOL_FORMAT\f[R]. +.SS See also +.IP \[bu] 2 +\f[B]mariadb_dyncol_count(3)\f[R] diff --git a/vendor/MDBC/man/mariadb_dyncol_column_cmp_named.3 b/vendor/MDBC/man/mariadb_dyncol_column_cmp_named.3 new file mode 100644 index 00000000..a5aedcbf --- /dev/null +++ b/vendor/MDBC/man/mariadb_dyncol_column_cmp_named.3 @@ -0,0 +1,31 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mariadb_dyncol_column_cmp_named" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mariadb_dyncol_column_cmp_named \- Compare two column names +.SS Synopsis +.IP +.nf +\f[C] +#include + +int mariadb_dyncol_column_cmp_named(const MYSQL_LEX_STRING *s1, + const MYSQL_LEX_STRING *s2); +\f[R] +.fi +.SS Description +.PP +Compares two dynamic column keys represented as a pointer to a +\f[C]MYSQL_LEX_STRING\f[R] structure. +.SS Parameter +.IP \[bu] 2 +\f[C]s1\f[R] \- First key +.IP \[bu] 2 +\f[C]s2\f[R] \- Second key +.SS Return value +.PP +Returns an integer less than, equal to, or greater than zero if the +first bytes of \f[C]s1\f[R] is found, respectively, to be less than, to +match, or be greater than the first bytes of \f[C]s2\f[R]. diff --git a/vendor/MDBC/man/mariadb_dyncol_column_count.3 b/vendor/MDBC/man/mariadb_dyncol_column_count.3 new file mode 100644 index 00000000..5469357b --- /dev/null +++ b/vendor/MDBC/man/mariadb_dyncol_column_count.3 @@ -0,0 +1,36 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mariadb_dyncol_column_count" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mariadb_dyncol_column_count \- Get number of columns in dynamic column +blob ## Synopsis +.IP +.nf +\f[C] +#include + +enum enum_dyncol_func_result +mariadb_dyncol_column_count(DYNAMIC_COLUMN *str, + unsigned int *column_count); +\f[R] +.fi +.SS Description +.PP +Gets the number of columnns in a dynamic column blob. +.SS Parameter +.IP \[bu] 2 +\f[C]*str\f[R] \- A pointer to a \f[C]DYNAMIC_COLUMN\f[R] structure +.IP \[bu] 2 +\f[C]column_count\f[R] \- An unsigned integer pointer where the number +of columns will be stored. +.SS Return value +.PP +Returns \f[C]ER_DYNCOL_OK\f[R] on success, otherwise error. +.SS Notes +.IP \[bu] 2 +\f[C]mariadb_dyncol_column_count()\f[R] doesn\[cq]t count NULL values. +.SS See also +.IP \[bu] 2 +Dynamic Column Error Codes (dyncol_typesanddefs#error-codes) diff --git a/vendor/MDBC/man/mariadb_dyncol_create_many_named.3 b/vendor/MDBC/man/mariadb_dyncol_create_many_named.3 new file mode 100644 index 00000000..915ade45 --- /dev/null +++ b/vendor/MDBC/man/mariadb_dyncol_create_many_named.3 @@ -0,0 +1,51 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mariadb_dyncol_create_many_named" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mariadb_dyncol_create_many_named \- Creates a dynamic column with named +keys +.SS Synopsis +.IP +.nf +\f[C] +#include + +enum enum_dyncol_func_result +mariadb_dyncol_create_many_named(DYNAMIC_COLUMN *str, + uint column_count, + MYSQL_LEX_STRING *column_keys, + DYNAMIC_COLUMN_VALUE *values, + my_bool new_string); +\f[R] +.fi +.SS Description +.PP +Create a dynamic column from arrays of values and names. +.SS Parameter +.IP \[bu] 2 +\f[C]*str\f[R] \- A pointer to a dynamic column structure +.IP \[bu] 2 +\f[C]column_count\f[R] \- number of columns +.IP \[bu] 2 +\f[C]*column_keys\f[R] \- an array of column keys +.IP \[bu] 2 +\f[C]*values\f[R] \- an array of values +.IP \[bu] 2 +\f[C]new_string\f[R] \- if set \f[C]str\f[R] will be reinitialized (not +freed) before usage +.SS Return value +.PP +Returns \f[C]ER_DYNCOL_OK\f[R] on success, otherwise error. +.SS Notes +.IP \[bu] 2 +To delete, update or insert new columns into an existing dynamic column +use function +.SS See also +.IP \[bu] 2 + +.IP \[bu] 2 + +.IP \[bu] 2 +Dynamic Column Error Codes (dyncol_typesanddefs#error-codes) diff --git a/vendor/MDBC/man/mariadb_dyncol_create_many_num.3 b/vendor/MDBC/man/mariadb_dyncol_create_many_num.3 new file mode 100644 index 00000000..c97078eb --- /dev/null +++ b/vendor/MDBC/man/mariadb_dyncol_create_many_num.3 @@ -0,0 +1,51 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mariadb_dyncol_create_many_num" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mariadb_dyncol_create_many_num \- Creates a dynamic column with numeric +keys +.SS Synopsis +.IP +.nf +\f[C] +#include + +enum enum_dyncol_func_result +mariadb_dyncol_create_many_num(DYNAMIC_COLUMN *str, + uint column_count, + uint *column_numbers, + DYNAMIC_COLUMN_VALUE *values, + my_bool new_string); +\f[R] +.fi +.SS Description +.PP +Create a dynamic column from arrays of values and numb\['e]rs +.SS Parameter +.IP \[bu] 2 +\f[C]*str\f[R] \- A pointer to a dynamic column structure +.IP \[bu] 2 +\f[C]column_count\f[R] \- number of columns +.IP \[bu] 2 +\f[C]*column_numbers\f[R] \- an array of column numbers +.IP \[bu] 2 +\f[C]*values\f[R] \- an array of values +.IP \[bu] 2 +\f[C]new_string\f[R] \- if set \f[C]str\f[R] will be reinitialized (not +freed) before usage +.SS Return value +.PP +Returns \f[C]ER_DYNCOL_OK\f[R] on success, otherwise error. +.SS Notes +.IP \[bu] 2 +To delete, update or insert new columns into an existing dynamic column +use function +.SS See also +.IP \[bu] 2 + +.IP \[bu] 2 + +.IP \[bu] 2 +Dynamic Column Error Codes (dyncol_typesanddefs#error-codes) diff --git a/vendor/MDBC/man/mariadb_dyncol_exists_named.3 b/vendor/MDBC/man/mariadb_dyncol_exists_named.3 new file mode 100644 index 00000000..a5f40eea --- /dev/null +++ b/vendor/MDBC/man/mariadb_dyncol_exists_named.3 @@ -0,0 +1,33 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mariadb_dyncol_exists_named" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mariadb_dyncol_exists_named \- Check if column with given name exists. +.SS Synopsis +.IP +.nf +\f[C] +enum enum_dyncol_func_result +mariadb_dyncol_exists_named(DYNAMIC_COLUMN *str, + MYSQL_LEX_STRING *column_key); +\f[R] +.fi +.SS Description +.PP +Checks if a column with the specified column key exists. +.SS Parameter +.IP \[bu] 2 +\f[C]*str\f[R] \- Dynamic column +.IP \[bu] 2 +\f[C]*column_key\f[R] \- The column key to search for +.SS Return value +.PP +Returns \f[C]ER_DYNCOL_YES\f[R] if a column with given key exists, +\f[C]ER_DYNCOL_NO\f[R] if no column exists or error. +.SS See also +.IP \[bu] 2 + +.IP \[bu] 2 +Dynamic Column Error Codes (dyncol_typesanddefs#error-codes) diff --git a/vendor/MDBC/man/mariadb_dyncol_exists_num.3 b/vendor/MDBC/man/mariadb_dyncol_exists_num.3 new file mode 100644 index 00000000..d68bf01d --- /dev/null +++ b/vendor/MDBC/man/mariadb_dyncol_exists_num.3 @@ -0,0 +1,33 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mariadb_dyncol_exists_num" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mariadb_dyncol_exists_num \- Check if column with given number exists. +.SS Synopsis +.IP +.nf +\f[C] +enum enum_dyncol_func_result +mariadb_dyncol_exists_num(DYNAMIC_COLUMN *str, + uint column_number); +\f[R] +.fi +.SS Description +.PP +Checks if a column with the specified column key exists. +.SS Parameter +.IP \[bu] 2 +\f[C]*str\f[R] \- Dynamic column +.IP \[bu] 2 +\f[C]column_number\f[R] \- The column number to search for +.SS Return value +.PP +Returns \f[C]ER_DYNCOL_YES\f[R] if a column with given number exists, +\f[C]ER_DYNCOL_NO\f[R] if no column exists or error. +.SS See also +.IP \[bu] 2 + +.IP \[bu] 2 +Dynamic Column Error Codes (dyncol_typesanddefs#error-codes) diff --git a/vendor/MDBC/man/mariadb_dyncol_free.3 b/vendor/MDBC/man/mariadb_dyncol_free.3 new file mode 100644 index 00000000..1b286b15 --- /dev/null +++ b/vendor/MDBC/man/mariadb_dyncol_free.3 @@ -0,0 +1,30 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mariadb_dyncol_free" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mariadb_dyncol_free \- Free memory inside packed blob +.SS Synopsis +.IP +.nf +\f[C] +#include + +void mariadb_dyncol_free(DYNAMIC_COLUMN *str) +\f[R] +.fi +.SS Description +.PP +Frees memory associated by the specified dynamic column +.SS Parameter +.IP \[bu] 2 +\f[C]*str\f[R] \- A pointer to a \f[C]DYNAMIC_COLUMN\f[R] structure +.SS Notes +.IP \[bu] 2 +\f[C]mariadb_dyncol_free()\f[R] doesn\[cq]t free the memory of the +passed \f[C]DYNAMIC_COLUMN\f[R] structure but all memory of stored +columns. +.SS See also +.IP \[bu] 2 +\f[B]mariadb_dyncol_init(3)\f[R] diff --git a/vendor/MDBC/man/mariadb_dyncol_list_named.3 b/vendor/MDBC/man/mariadb_dyncol_list_named.3 new file mode 100644 index 00000000..081961d6 --- /dev/null +++ b/vendor/MDBC/man/mariadb_dyncol_list_named.3 @@ -0,0 +1,43 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mariadb_dyncol_list_named" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mariadb_dyncol_list_named \- Lists column keys in dynamic column +.SS Synopsis +.IP +.nf +\f[C] +#include + +enum enum_dyncol_func_result +mariadb_dyncol_list_named(DYNAMIC_COLUMN *str, + uint *column_count, + MYSQL_LEX_STRING **column_keys); +\f[R] +.fi +.SS Description +.PP +Lists the column keys inside a dynamic column. +.SS Notes +.IP \[bu] 2 +The application program needs to free the allocated memory for +\f[C]column_count\f[R] and \f[C]column_keys\f[R] parameter. +.SS Parameter +.IP \[bu] 2 +\f[C]*str\f[R] \- Dynamic column +.IP \[bu] 2 +\f[C]*column_count\f[R] \- A pointer to an unsigned integer which stores +the number of columns +.IP \[bu] 2 +\f[C]**column_keys\f[R] \- A pointer to an array of column keys, which +stores the keys +.SS Return value +.PP +Returns \f[C]ER_DYNCOL_OK\f[R] on success, otherwise error. +.SS See also +.IP \[bu] 2 + +.IP \[bu] 2 + diff --git a/vendor/MDBC/man/mariadb_dyncol_list_num.3 b/vendor/MDBC/man/mariadb_dyncol_list_num.3 new file mode 100644 index 00000000..d556394a --- /dev/null +++ b/vendor/MDBC/man/mariadb_dyncol_list_num.3 @@ -0,0 +1,43 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mariadb_dyncol_list_num" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mariadb_dyncol_list_num \- Lists numeric column keys in dynamic column +.SS Synopsis +.IP +.nf +\f[C] +#include + +enum enum_dyncol_func_result +mariadb_dyncol_list_named(DYNAMIC_COLUMN *str, + uint *column_count, + uint **column_numbers); +\f[R] +.fi +.SS Description +.PP +Lists the column numbers inside a dynamic column. +.SS Parameter +.IP \[bu] 2 +\f[C]*str\f[R] \- Dynamic column +.IP \[bu] 2 +\f[C]*column_count\f[R] \- A pointer to an unsigned integer which stores +the number of columns +.IP \[bu] 2 +\f[C]**column_numbers\f[R] \- A pointer to an array of column numbers, +which stores the numbers +.SS Return value +.PP +Returns \f[C]ER_DYNCOL_OK\f[R] on success, otherwise error. +.SS Notes +.IP \[bu] 2 +The application program needs to free the allocated memory for +\f[C]column_count\f[R] and \f[C]column_numbers\f[R] parameter. +.SS See also +.IP \[bu] 2 + +.IP \[bu] 2 + diff --git a/vendor/MDBC/man/mariadb_dyncol_unpack.3 b/vendor/MDBC/man/mariadb_dyncol_unpack.3 new file mode 100644 index 00000000..f159dfea --- /dev/null +++ b/vendor/MDBC/man/mariadb_dyncol_unpack.3 @@ -0,0 +1,50 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mariadb_dyncol_unpack" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mariadb_dyncol_unpack \- extracts keys and values of all columns +.SS Synopsis +.IP +.nf +\f[C] +#include + +enum enum_dyncol_func_result +mariadb_dyncol_unpack(DYNAMIC_COLUMN *str, + uint *column_count, + MYSQL_LEX_STRING **column_keys, + DYNAMIC_COLUMN_VALUE **values); +\f[R] +.fi +.SS Description +.PP +The \f[C]mariadb_dyncol_unpack()\f[R] function extracts all keys and +values of a dynamic column. +.SS Parameter +.IP \[bu] 2 +\f[C]str\f[R] \- Pointer to a \f[C]DYNAMIC_COLUMN\f[R] structure +.IP \[bu] 2 +\f[C]column count\f[R] \- Pointer to an unsigned integer which will +receive the number of columns +.IP \[bu] 2 +\f[C]column_keys\f[R] \- Pointer of an array of +\f[C]MYSQL_LEX_STRING\f[R] structures, which will contain the column +keys +.IP \[bu] 2 +\f[C]values\f[R] \- Pointer of an array of +\f[C]DYNAMIC_COLUMN_VALUE\f[R] structures, which will contain the +values. +.SS Return value +.PP +Returns \f[C]ER_DYNCOL_OK\f[R] on success, otherwise an error. +.SS Notes +.IP \[bu] 2 +The \f[C]column_keys\f[R] and \f[C]values\f[R] arrays will be allocated +by \f[C]mariadb_dyncol_unpack()\f[R] and must be freed by application. +.SS See also +.IP \[bu] 2 +\f[B]mariadb_dyncol_get(3)\f[R] +.IP \[bu] 2 +\f[B]mariadb_dyncol_list(3)\f[R] diff --git a/vendor/MDBC/man/mariadb_dyncol_update_many_named.3 b/vendor/MDBC/man/mariadb_dyncol_update_many_named.3 new file mode 100644 index 00000000..b76a2da3 --- /dev/null +++ b/vendor/MDBC/man/mariadb_dyncol_update_many_named.3 @@ -0,0 +1,47 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mariadb_dyncol_update_many_named" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mariadb_dyncol_update_many_named \- Update, insert or delete values in a +dynamic column +.SS Synopsis +.IP +.nf +\f[C] +#include + +enum enum_dyncol_func_result +mariadb_dyncol_update_many_named(DYNAMIC_COLUMN *str, + uint column_count, + MYSQL_LEX_STRING *column_keys, + DYNAMIC_COLUMN_VALUE *values) +\f[R] +.fi +.SS Description +.PP +Add, delete or update columns in a dynamic column. +.SS Parameter +.IP \[bu] 2 +\f[C]*str\f[R] \- A pointer to a dynamic column structure +.IP \[bu] 2 +\f[C]column_count\f[R] \- number of columns +.IP \[bu] 2 +\f[C]*column_keys\f[R] \- an array of column keys +.IP \[bu] 2 +\f[C]*values\f[R] \- an array of values +.SS Return value +.PP +Returns \f[C]ER_DYNCOL_OK\f[R] on success, otherwise error. +.SS Notes +.IP \[bu] 2 +To delete a column, update its value to a \[lq]non\-value\[rq] of type +\f[C]DYN_COL_NULL\f[R] +.SS See also +.IP \[bu] 2 + +.IP \[bu] 2 + +.IP \[bu] 2 +Dynamic Column Error Codes (dyncol_typesanddefs#error-codes) diff --git a/vendor/MDBC/man/mariadb_dyncol_update_many_num.3 b/vendor/MDBC/man/mariadb_dyncol_update_many_num.3 new file mode 100644 index 00000000..d292b062 --- /dev/null +++ b/vendor/MDBC/man/mariadb_dyncol_update_many_num.3 @@ -0,0 +1,47 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mariadb_dyncol_update_many_num" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mariadb_dyncol_update_many_num \- Update, insert or delete values in a +dynamic column using numeric keys +.SS Synopsis +.IP +.nf +\f[C] +#include + +enum enum_dyncol_func_result +mariadb_dyncol_update_many_num(DYNAMIC_COLUMN *str, + uint column_count, + uint *column_keys, + DYNAMIC_COLUMN_VALUE *values) +\f[R] +.fi +.SS Description +.PP +Add, delete or update columns in a dynamic column with a numeric key. +.SS Parameter +.IP \[bu] 2 +\f[C]*str\f[R] \- A pointer to a dynamic column structure +.IP \[bu] 2 +\f[C]column_count\f[R] \- number of columns +.IP \[bu] 2 +\f[C]*column_keys\f[R] \- an array of column keys +.IP \[bu] 2 +\f[C]*values\f[R] \- an array of values +.SS Return value +.PP +Returns \f[C]ER_DYNCOL_OK\f[R] on success, otherwise error. +.SS Notes +.IP \[bu] 2 +To delete a column, update its value to a \[lq]non\-value\[rq] of type +\f[C]DYN_COL_NULL\f[R] +.SS See also +.IP \[bu] 2 + +.IP \[bu] 2 + +.IP \[bu] 2 +Dynamic Column Error Codes (dyncol_typesanddefs#error-codes) diff --git a/vendor/MDBC/man/mariadb_get_infov.3 b/vendor/MDBC/man/mariadb_get_infov.3 new file mode 100644 index 00000000..4de47796 --- /dev/null +++ b/vendor/MDBC/man/mariadb_get_infov.3 @@ -0,0 +1,325 @@ +.\"t +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mariadb_get_infov" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mariadb_get_infov \- retrieves generic or connection releated +information +.SS Synopsis +.IP +.nf +\f[C] +#include + +int mariadb_get_infov(MYSQL * mysql, + enum mariadb_value value, + void * arg, + ...); +\f[R] +.fi +.SH Description +.PP +Retrieves generic or connection specific information. +\f[C]arg\f[R] (and further arguments) must be a pointer to a variable of +the type appropriate for the \f[C]value\f[R] argument. +The following table shows which variable type to use for each value. +.PP +.TS +tab(@); +lw(35.0n) lw(35.0n). +T{ +Variable Type +T}@T{ +Values +T} +_ +T{ +\f[C]unsigned int\f[R] +T}@T{ +\f[C]MARIADB_CLIENT_VERSION_ID\f[R], +\f[C]MARIADB_CONNECTION_ASYNC_TIMEOUT\f[R], +\f[C]MARIADB_CONNECTION_ASYNC_TIMEOUT_MS\f[R], +\f[C]MARIADB_CONNECTION_ERROR_ID\f[R], +\f[C]MARIADB_CONNECTION_PORT\f[R], +\f[C]MARIADB_CONNECTION_PROTOCOL_VERSION_ID\f[R], +\f[C]MARIADB_CONNECTION_PVIO_TYPE\f[R], +\f[C]MARIADB_CONNECTION_SERVER_STATUS\f[R], +\f[C]MARIADB_CONNECTION_SERVER_VERSION_ID\f[R], +\f[C]MARIADB_CONNECTION_SSL_VERSION_ID\f[R] +T} +T{ +\f[C]unsigned long\f[R] +T}@T{ +\f[C]MARIADB_CONNECTION_CLIENT_CAPABILITIES\f[R], +\f[C]MARIADB_CONNECTION_EXTENDED_SERVER_CAPABILITIES\f[R], +\f[C]MARIADB_CONNECTION__SERVER_CAPABILITIES\f[R] +T} +T{ +\f[C]size_t\f[R] +T}@T{ +\f[C]MARIADB_MAX_ALLOWED_PACKET\f[R], +\f[C]MARIADB_NET_BUFFER_LENGTH\f[R] +T} +T{ +\f[C]const char *\f[R] +T}@T{ +\f[C]MARIADB_CLIENT_VERSION\f[R], \f[C]MARIADB_SSL_VERSION\f[R], +\f[C]MARIADB_CONNECTION_ERROR\f[R], \f[C]MARIADB_CONNECTION_HOST\f[R], +\f[C]MARIADB_CONNECTION_INFO\f[R], \f[C]MARIADB_CONNECTION_SCHEMA\f[R], +\f[C]MARIADB_CONNECTION_SERVER_TYPE\f[R], +\f[C]MARIADB_CONNECTION_SERVER_VERSION\f[R], +\f[C]MARIADB_CONNECTION_SQLSTATE\f[R], +\f[C]MARIADB_CONNECTION_SSL_CIPHER\f[R], +\f[C]MARIADB_CONNECTIONSSL_VERSION\f[R], +\f[C]MARIADB_CONNECTUION_UNIX_SOCKET\f[R], +\f[C]MARIADB_CONNECTION_USER\f[R], +T} +T{ +\f[C]const char **\f[R] +T}@T{ +\f[C]MARIADB_CLIENT_ERRORS\f[R] +T} +T{ +\f[C]const *MY_CHARSET_INFO\f[R] +T}@T{ +\f[C]MARIADB_CHARSET_NAME\f[R], +\f[C]MARIADB_CONNECTION_CHARSET_INFO\f[R] +T} +T{ +\f[C]my_socket\f[R] +T}@T{ +\f[C]MARIADB_CONNECTION_SOCKET\f[R] +T} +.TE +.SS Value types +.SS Generic information +.PP +For these information types parameter \f[C]mysql\f[R] needs to be set to +NULL. +.IP \[bu] 2 +\f[C]MARIADB_CHARSET_NAME\f[R] +.PD 0 +.P +.PD +Retrieves the charset information for a character set by it\[cq]s +literal representation. +.IP \[bu] 2 +\f[C]MARIADB_CLIENT_ERRORS\f[R] +.PD 0 +.P +.PD +Retrieve array of client errors. +This can be used in plugins to set global error messages (which are not +exported by MariaDB Connector/C). +.IP \[bu] 2 +\f[C]MARIADB_CLIENT_VERSION\f[R] +.PD 0 +.P +.PD +The client version in literal representation. +.IP \[bu] 2 +\f[C]MARIADB_CLIENT_VERSION_ID\f[R] +.PD 0 +.P +.PD +The client version in numeric format. +.IP \[bu] 2 +\f[C]MARIADB_MAX_ALLOWED_PACKET\f[R] +.PD 0 +.P +.PD +Retrieves value of maximum allowed packet size. +.IP \[bu] 2 +\f[C]MARIADB_NET_BUFFER_LENGTH\f[R] +.PD 0 +.P +.PD +Retrieves the length of net buffer. +.IP \[bu] 2 +\f[C]MARIADB_SSL_LIBRARY\f[R] +.PD 0 +.P +.PD +The TLS library MariaDB Connector/C is compiled against. +.SS Connection related information +.PP +For these information types parameter mysql must be represent a valid +connection handle which was allocated by \f[B]mysql_init(3)\f[R]. +.IP \[bu] 2 +\f[C]MARIADB_CONNECTION_ASYNC_TIMEOUT\f[R] +.PD 0 +.P +.PD +Retrieves the timeout for non blocking calls in seconds. +.IP \[bu] 2 +\f[C]MARIADB_CONNECTION_ASYNC_TIMEOUT_MS\f[R] +.PD 0 +.P +.PD +Retrieves the timeout for non blocking calls in milliseconds. +.IP \[bu] 2 +\f[C]MARIADB_CONNECTION_CHARSET_INFO\f[R] +.PD 0 +.P +.PD +Retrieves character set information for given connection. +.IP \[bu] 2 +\f[C]MARIADB_CONNECTION_CLIENT_CAPABILITIES\f[R] +.PD 0 +.P +.PD +Returns the handshak capability flags] of the client. +.IP \[bu] 2 +\f[C]MARIADB_CONNECTION_ERROR\f[R] +.PD 0 +.P +.PD +Retrieves error message for last used command. +.IP \[bu] 2 +\f[C]MARIADB_CONNECTION_ERROR_ID\f[R] +.PD 0 +.P +.PD +Retrieves error number for last used command. +*\f[C]MARIADB_CONNECTION_EXTENDED_SERVER_CAPABILITIES\f[R] +.PD 0 +.P +.PD +Returns the extended capability flags of the connected MariaDB server +.IP \[bu] 2 +\f[C]MARIADB_CONNECTION_HOST\f[R] +.PD 0 +.P +.PD +Returns host name of the connected MariaDB server +.IP \[bu] 2 +\f[C]MARIADB_CONNECTION_INFO\f[R] +.PD 0 +.P +.PD +Retrieves generic info for last used command. +.IP \[bu] 2 +\f[C]MARIADB_CONNECTION_PORT\f[R] +.PD 0 +.P +.PD +Retrieves the port number of server host. +.IP \[bu] 2 +\f[C]MARIADB_CONNECTION_PROTOCOL_VERSION_ID\f[R] +.PD 0 +.P +.PD +Retrieves the protocol version number. +.IP \[bu] 2 +\f[C]MARIADB_CONNECTION_PVIO_TYPE\f[R] +.PD 0 +.P +.PD +Retrieves the pvio plugin used for specified connection. +.IP \[bu] 2 +\f[C]MARIADB_CONNECTION_SCHEMA\f[R] +.PD 0 +.P +.PD +Retrieves the current schema. +.IP \[bu] 2 +\f[C]MARIADB_CONNECTION_SERVER_CAPABILITIES\f[R] +.PD 0 +.P +.PD +Retrievrs the capability flags of the connected server. +.IP \[bu] 2 +\f[C]MARIADB_CONNECTION_SERVER_STATUS\f[R] +.PD 0 +.P +.PD +Returns server status after last operation. +.IP \[bu] 2 +\f[C]MARIADB_CONNECTION_SERVER_TYPE\f[R] +.PD 0 +.P +.PD +Retrieves the type of the server. +.IP \[bu] 2 +\f[C]MARIADB_CONNECTION_SERVER_VERSION\f[R] +.PD 0 +.P +.PD +Retrieves the server version in literal format. +.IP \[bu] 2 +\f[C]MARIADB_CONNECTION_SERVER_VERSION_ID\f[R] +.PD 0 +.P +.PD +Retrieves the server version in numeric format. +.IP \[bu] 2 +\f[C]MARIADB_CONNECTION_SOCKET\f[R] +.PD 0 +.P +.PD +Retrieves the handle (socket) for given connection. +.IP \[bu] 2 +\f[C]MARIADB_CONNECTION_SQLSTATE\f[R] +.PD 0 +.P +.PD +Retrieves current sqlstate information for last used command. +.IP \[bu] 2 +\f[C]MARIADB_CONNECTION_SSL_CIPHER\f[R] +.PD 0 +.P +.PD +Retrieves the TLS/SSL cipher in use. +.IP \[bu] 2 +\f[C]MARIADB_CONNECTION_SSL_VERSION\f[R] +.PD 0 +.P +.PD +Retrieves the TLS protocol version used in literal format. +.IP \[bu] 2 +\f[C]MARIADB_CONNECTION_SSL_VERSION_ID\f[R] +.PD 0 +.P +.PD +Retrieves the TLS protocol version used in numeric format. +.IP \[bu] 2 +\f[C]MARIADB_CONNECTION_UNIX_SOCKET\f[R] +.PD 0 +.P +.PD +Retrieves the file name of the unix socket +.IP \[bu] 2 +\f[C]MARIADB_CONNECTION_USER\f[R] +.PD 0 +.P +.PD +Retrieves connection\[cq]s user name. +.SS Returns +.PP +Returns zero on success, non zero if an error occurred (e.g.\ if an +invalid option was specified), +.SS Source file +.IP +.nf +\f[C] + +## History +This function was added in MariaDB Connector/C 3.0, + +## Examples +\f[R] +.fi +.PP +/* get server port for current connection \f[I]/ unsigned int port; +mariadb_get_infov(mysql, MARIADB_CONNECTION_PORT, (void \f[R])&port); +.IP +.nf +\f[C] +\f[R] +.fi +.PP +/* get user name for current connection \f[I]/ const char \f[R]user; +mariadb_get_infov(mysql, MARIADB_CONNECTION_USER, (void \f[I])&user); +\[ga]\[ga]\[ga] ## See also \f[R] \f[B]mysql_get_optionv(3)\f[R] diff --git a/vendor/MDBC/man/mariadb_reconnect.3 b/vendor/MDBC/man/mariadb_reconnect.3 new file mode 100644 index 00000000..bb17e2c7 --- /dev/null +++ b/vendor/MDBC/man/mariadb_reconnect.3 @@ -0,0 +1,36 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mariadb_reconnect" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mariadb_reconnect \- reconnects to a server +.SS Synopsis +.IP +.nf +\f[C] +#include + +my_bool mariadb_reconnect(MYSQL * mysql) +\f[R] +.fi +.SS Description +.PP +\f[C]mariadb_reconnect()\f[R] tries to reconnect to a server in case the +connection died due to timeout or other errors. +It uses the same credentials which were specified in +\f[B]mysql_real_connect(3)\f[R]. +.SS Return value +.PP +The function will return 0 on sucess, a non zero value on error +.PP +\f[B]Note\f[R]: The function will return an error, if the option +\f[C]MYSQL_OPT_RECONNECT\f[R] wasn\[cq]t set before. +.SS History +.PP +\f[C]mariadb_reconnect()\f[R] was added in MariaDB Connector/C 3.0 +.SS See also +.IP \[bu] 2 +\f[B]mysql_real_connect(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_optionsv(3)\f[R] diff --git a/vendor/MDBC/man/mariadb_rpl_close.3 b/vendor/MDBC/man/mariadb_rpl_close.3 new file mode 100644 index 00000000..6ef0688e --- /dev/null +++ b/vendor/MDBC/man/mariadb_rpl_close.3 @@ -0,0 +1,31 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mariadb_rpl_close" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mariadb_rpl_close \- Closes replication stream +.SS Synopsis +.IP +.nf +\f[C] +#include + +void mariadb_rpl_close(MARIADB_RPL *rpl) +\f[R] +.fi +.SS Description +.PP +Closes a replication stream. +.SS Parameter +.PP +\f[C]rpl\f[R] \- A replication handle which was initialized by +\f[B]mariadb_rpl_init(3)\f[R] and connected by +\f[B]mariadb_rpl_open(3)\f[R]. +.SS Notes +.PP +To close the connection to the server, the api function +\f[B]mariadb_close(3)\f[R] must be called. +.SS History +.PP +\f[C]mariadb_rpl_close\f[R] was added in MariaDB Connector/C 3.1 diff --git a/vendor/MDBC/man/mariadb_rpl_fetch.3 b/vendor/MDBC/man/mariadb_rpl_fetch.3 new file mode 100644 index 00000000..9640feee --- /dev/null +++ b/vendor/MDBC/man/mariadb_rpl_fetch.3 @@ -0,0 +1,42 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mariadb_rpl_fetch" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mariadb_rpl_fetch \- fetches next event from replication stream +.SS Synopsis +.IP +.nf +\f[C] +#include + +MARIADB_RPL_EVENT *mariadb_rpl_fetch(MARIADB_RPL *rpl, MARIADB_RPL_EVENT *event) +\f[R] +.fi +.SS Description +.PP +Fetches one event from the replication stream +.SS Parameter +.IP \[bu] 2 +\f[C]rpl\f[R] \- A replication handle which was initialized by +\f[B]mariadb_rpl_init(3)\f[R] and connected by +\f[B]mariadb_rpl_open(3)\f[R]. +.IP \[bu] 2 +\f[C]event\f[R] \- An event which was returned by a previous call to +\f[C]mariadb_rpl_fetch\f[R]. +If this value is \f[C]NULL\f[R] the function will allocate new memory +for the event, otherwise the passed event value will be overwritten. +.SS Return value +.PP +An event handle or NULL if EOF packet was received. +.SS Notes +.PP +Event memory needs to be freed by calling +\f[B]mariadb_rpl_free_event(3)\f[R]. +.SS See also +.IP \[bu] 2 +\f[B]mariadb_rpl_free_event(3)\f[R] +.SS History +.PP +\f[C]mariadb_rpl_fetch\f[R] was added in MariaDB Connector/C 3.1.0 diff --git a/vendor/MDBC/man/mariadb_rpl_get_optionsv.3 b/vendor/MDBC/man/mariadb_rpl_get_optionsv.3 new file mode 100644 index 00000000..f4db3ec3 --- /dev/null +++ b/vendor/MDBC/man/mariadb_rpl_get_optionsv.3 @@ -0,0 +1,74 @@ +.\"t +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mariadb_rpl_get_optionsv" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mariadb_rpl_get_optionsv \- get replication option value +.SS Synopsis +.IP +.nf +\f[C] +#include + +int mariadb_rpl_get_optionsv(MARIADB_RPL *rpl, enum mariadb_rpl_option option, ...) +\f[R] +.fi +.SS Parameter +.IP \[bu] 2 +\f[C]rpl\f[R] \- a replication handle which was previously allocated by + +.IP \[bu] 2 +\f[C]option\f[R] \- The option to be set, followed by one or more values +.PP +.TS +tab(@); +lw(23.3n) lw(23.3n) lw(23.3n). +T{ +Option +T}@T{ +Type +T}@T{ +Description +T} +_ +T{ +MARIADB_RPL_FILENAME +T}@T{ +char **, size_t * +T}@T{ +The name and name length of binglog file +T} +T{ +MARIADB_RPL_START +T}@T{ +unsigned long * +T}@T{ +Start position +T} +T{ +MARIADB_RPL_SERVER_ID +T}@T{ +uint32_t * +T}@T{ +Server id +T} +T{ +MARIADB_RPL_FLAGS +T}@T{ +uint32_t * +T}@T{ +Flags +T} +.TE +.SS Return value +.PP +Returns zero on success, non zero on error. +.SS See also +.IP \[bu] 2 +\f[B]mariadb_rpl_optionsv(3)\f[R] +.SS History +.PP +\f[C]mariadb_rpl_get_optionsv\f[R] was added in MariaDB Connector/C +3.1.0 diff --git a/vendor/MDBC/man/mariadb_rpl_open.3 b/vendor/MDBC/man/mariadb_rpl_open.3 new file mode 100644 index 00000000..d90b2311 --- /dev/null +++ b/vendor/MDBC/man/mariadb_rpl_open.3 @@ -0,0 +1,29 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mariadb_rpl_open" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mariadb_rpl_open \- opens a replication stream +.SS Synopsis +.IP +.nf +\f[C] +#include + +int mariadb_rpl_open(MARIADB_RPL *rpl) +\f[R] +.fi +.SS Description +.PP +Opens a replication stream +.SS Parameter +.IP \[bu] 2 +\f[C]rpl\f[R] \- A replication handle which was previously initialized +by \f[B]mariadb_rpl_init(3)\f[R]. +.SS Return value +.PP +Zero on success, nonzero on error. +.SS History +.PP +\f[C]mariadb_rpl_open\f[R] was added in MariaDB Connector/C 3.1.0 diff --git a/vendor/MDBC/man/mariadb_rpl_optionsv.3 b/vendor/MDBC/man/mariadb_rpl_optionsv.3 new file mode 100644 index 00000000..d791fa94 --- /dev/null +++ b/vendor/MDBC/man/mariadb_rpl_optionsv.3 @@ -0,0 +1,75 @@ +.\"t +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mariadb_rpl_optionsv" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mariadb_rpl_optionsv \- sets replication options +.SS Synopsis +.IP +.nf +\f[C] +#include + +int mariadb_rpl_optionsv(MARIADB_RPL *rpl, enum mariadb_rpl_option option, ...) +\f[R] +.fi +.SS Parameter +.IP \[bu] 2 +\f[C]rpl\f[R] \- a replication handle which was previously allocated by + +.IP \[bu] 2 +\f[C]option\f[R] \- The option to be set, followed by one or more values +.PP +.TS +tab(@); +l l l. +T{ +Option +T}@T{ +Type +T}@T{ +Description +T} +_ +T{ +MARIADB_RPL_FILENAME +T}@T{ +char * +T}@T{ +The name of binglog file +T} +T{ +MARIADB_RPL_START +T}@T{ +unsigned long +T}@T{ +Start position +T} +T{ +MARIADB_RPL_SERVER_ID +T}@T{ +uint32_t +T}@T{ +Server id +T} +T{ +MARIADB_RPL_FLAGS +T}@T{ +uint32_t +T}@T{ +Flags +T} +.TE +.SS Return value +.PP +Returns zero on success, non zero on error. +.SS See also +.IP \[bu] 2 +\f[B]mariadb_rpl_get_optionsv(3)\f[R] +.IP \[bu] 2 +\f[B]mariadb_rpl_open(3)\f[R] +.SS History +.PP +\f[C]mariadb_rpl_optionsv\f[R] was added in MariaDB Connector/C 3.1.0 diff --git a/vendor/MDBC/man/mariadb_stmt_execute_direct.3 b/vendor/MDBC/man/mariadb_stmt_execute_direct.3 new file mode 100644 index 00000000..d8e0d33d --- /dev/null +++ b/vendor/MDBC/man/mariadb_stmt_execute_direct.3 @@ -0,0 +1,81 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mariadb_stmt_execute_direct" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mariadb_stmt_execute_direct \- prepares and executes a prepared +statement +.SS Synopsis +.IP +.nf +\f[C] +#include + +int mariadb_stmt_execute_direct(MYSQL_STMT * stmt, + const char *query, + size_t length); +\f[R] +.fi +.SS Description +.PP +Prepares and executes a statement which was previously allocated by +\f[B]mysql_stmt_init(3)\f[R], using the current values of the parameter +variables if any parameters exist in the statement. +.SS Parameters +.IP \[bu] 2 +\f[C]stmt\f[R] \- A statement handle, which was previously allocated by +\f[B]mysql_stmt_init(3)\f[R]. +.IP \[bu] 2 +\f[C]query\f[R] SQL statement +.IP \[bu] 2 +\f[C]length\f[R] Length of SQL statement +.SS Return value +.PP +Returns zero on success, non\-zero on failure. +.SS Notes +.IP \[bu] 2 +Since the number of parameter of the statement is unknown before +execution it is mandatory to set the number of parameters via the +\f[B]mysql_stmt_attr_set(3)\f[R] function. +.IP \[bu] 2 +If the SQL statement is a zero\-terminated string, you can also pass +\f[C]\-1\f[R] as length. +.IP \[bu] 2 +The statement handle is intended for one\-time execution. +Reusing the statement handle might lead to unexpected behavior. +.SS History +.PP +This function was added in Connector/C 3.0 and requires MariaDB 10.2 or +later versions. +.SS See Also +.IP \[bu] 2 +\f[B]mysql_stmt_attr_set(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_stmt_bind_param(3)\f[R] +.SS Example +.PP +\[ga]\[ga]\[ga]C static int execute_direct_example(MYSQL \f[I]mysql) { +MYSQL_STMT \f[R]stmt= mysql_stmt_init(mysql); MYSQL_BIND bind[2]; int +intval= 1; int param_count= 2; char *strval= +\[lq]execute_direct_example\[rq]; +.PP +/* Direct execution without parameters */ if +(mariadb_stmt_execute_direct(stmt, \[lq]CREATE TABLE execute_direct (a +int, b varchar(30))\[rq], \-1)) goto error; +.PP +memset(&bind, 0, sizeof(MYSQL_BIND) * 2); bind[0].buffer_type= +MYSQL_TYPE_SHORT; bind[0].buffer= &intval; bind[1].buffer_type= +MYSQL_TYPE_STRING; bind[1].buffer= strval; bind[1].buffer_length= +strlen(strval); +.PP +/* set number of parameters */ if (mysql_stmt_attr_set(stmt, +STMT_ATTR_PREBIND_PARAMS, ¶m_count)) goto error; +.PP +/* bind parameters */ if (mysql_stmt_bind_param(stmt, bind)) goto error; +.PP +if (mariadb_stmt_execute_direct(stmt, \[lq]INSERT INTO execute_direct +VALUES (?,?)\[rq], \-1)) goto error; +.PP +mysql_stmt_close(stmt); return 0; error: printf(\[lq]Error: %s\[rq], +mysql_stmt_error(stmt)); mysql_stmt_close(stmt); return 1; } diff --git a/vendor/MDBC/man/mariadb_stmt_fetch_fields.3 b/vendor/MDBC/man/mariadb_stmt_fetch_fields.3 new file mode 100644 index 00000000..ea3f8b31 --- /dev/null +++ b/vendor/MDBC/man/mariadb_stmt_fetch_fields.3 @@ -0,0 +1,36 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mariadb_stmt_fetch_fields" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mariadb_stmt_fetch_fields \- Returns an array of fields containing the +column definitions ## Synopsis +.IP +.nf +\f[C] +#include + +MYSQL_FIELD *mariadb_stmt_fetch_fields(MYSQL_STMT * stmt); +\f[R] +.fi +.SS Description +.PP +Returns an array of fields. +Each field contains the definition for a column of the result set. +If the statement doesn\[cq]t have a result set a NULL pointer will be +returned. +.SS Parameter +.IP \[bu] 2 +\f[C]stmt\f[R] \- A statement handle, which was previously allocated by +\f[B]mysql_stmt_init(3)\f[R]. +.SS Notes +.PP +The number of fields can be obtained by +\f[B]mysql_stmt_field_count(3)\f[R] +.SS History +.PP +This function was added in MariaDB Connector/C 3.1.0 +.SS See Also +.PP +*\f[B]mysql_stmt_field_count(3)\f[R] diff --git a/vendor/MDBC/man/mysql_affected_rows.3 b/vendor/MDBC/man/mysql_affected_rows.3 new file mode 100644 index 00000000..9f5e8489 --- /dev/null +++ b/vendor/MDBC/man/mysql_affected_rows.3 @@ -0,0 +1,46 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_affected_rows" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_affected_rows \- returns the number of rows affected by the last +operation +.SS Synopsis +.IP +.nf +\f[C] +#include + +my_ulonglong mysql_affected_rows(MYSQL * mysql); +\f[R] +.fi +.SS Description +.PP +Returns the number of affected rows by the last operation associated +with mysql, if the operation was an \[lq]upsert\[rq] (\f[C]INSERT\f[R], +\f[C]UPDATE\f[R], \f[C]DELETE\f[R] or \f[C]REPLACE\f[R]) statement, or +\-1 if the last operation failed. +.SS Parameters: +.PP +\f[C]mysql\f[R] is a connection identifier, which was previously +allocated by \f[B]mysql_init(3)\f[R] and connected by +\f[B]mysql_real_connect(3)\f[R]. +.SS Notes: +.IP \[bu] 2 +When using \f[C]UPDATE\f[R], MariaDB will not update columns where the +new value is the same as the old value. +This creates the possibility that mysql_affected_rows may not actually +equal the number of rows matched, only the number of rows that were +literally affected by the query. +.IP \[bu] 2 +The \f[C]REPLACE\f[R] statement first deletes the record with the same +primary key and then inserts the new record. +This function returns the number of deleted records in addition to the +number of inserted records. +.SH Return value +.PP +Returns the number of affected rows or \-1 on error. +.SS See also +.IP \[bu] 2 +\f[B]mysql_num_rows(3)\f[R] diff --git a/vendor/MDBC/man/mysql_autocommit.3 b/vendor/MDBC/man/mysql_autocommit.3 new file mode 100644 index 00000000..2bdbec7c --- /dev/null +++ b/vendor/MDBC/man/mysql_autocommit.3 @@ -0,0 +1,82 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_autocommit" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_autocommit \- Toggles autocommit mode +.SS Synopsis +.IP +.nf +\f[C] +#include + +my_bool mysql_autocommit(MYSQL * mysql, my_bool auto_mode); +\f[R] +.fi +.SS Description +.PP +Toggles autocommit mode on or off for the current database connection. +Autocommit mode will be set if mode=1 or unset if mode=0. +.SS Parameters: +.IP \[bu] 2 +\f[C]mysql\f[R] is a connection identifier, which was previously +allocated by \f[B]mysql_init(3)\f[R] and connected by +\f[B]mysql_real_connect(3)\f[R]. +.IP \[bu] 2 +\f[C]auto_mode\f[R] \- whether to turn autocommit on or not. +.SS Notes +.IP \[bu] 2 +Autocommit mode only affects operations on transactional table types. +To determine the current state of autocommit mode use the SQL command +\f[C]SELECT \[at]\[at]autocommit\f[R] or check the server status (see +example below). +.IP \[bu] 2 +Be aware: the [mysql_rollback()}(mysql_rollback() function will not work +if autocommit mode is switched on. +.SS Examples +.SS SQL +.IP +.nf +\f[C] +# Turn of autocmmit +SET AUTOCOMMIT=0; + +# Retrieve autocommit +SELECT \[at]\[at]autocommit; ++\-\-\-\-\-\-\-\-\-\-\-\-\-\-+ +| \[at]\[at]autocommit | ++\-\-\-\-\-\-\-\-\-\-\-\-\-\-+ +| 0 | ++\-\-\-\-\-\-\-\-\-\-\-\-\-\-+ +\f[R] +.fi +.SS MariaDB Connector/C +.IP +.nf +\f[C] +static int test_autocommit(MYSQL *mysql) +{ + int rc; + unsigned int server_status; + + /* Turn autocommit off */ + rc= mysql_autocommit(mysql, 0); + if (rc) + return rc; /* Error */ + + /* If autocommit = 0 succeeded, the last OK packet updated the server status */ + rc= mariadb_get_infov(mysql, MARIADB_CONNECTION_SERVER_STATUS, &server_status); + if (rc) + return rc; /* Error */ + + if (server_status & SERVER_STATUS_AUTOCOMMIT) + { + printf(\[dq]Error: autocommit is on\[rs]n\[dq]); + return 1; + } + printf(\[dq]OK: autocommit is off\[rs]n\[dq]); + return 0; +} +\f[R] +.fi diff --git a/vendor/MDBC/man/mysql_change_user.3 b/vendor/MDBC/man/mysql_change_user.3 new file mode 100644 index 00000000..356f61b3 --- /dev/null +++ b/vendor/MDBC/man/mysql_change_user.3 @@ -0,0 +1,62 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_change_user" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_change_user \- changes user and default database +.SS Synopsis +.IP +.nf +\f[C] +#include + +my_bool mysql_change_user(MYSQL * mysql, + const char * user, + const char * passwd, + const char * db); +\f[R] +.fi +.SS Description +.PP +Changes the user and default database of the current connection. +.PP +In order to successfully change users a valid username and password +parameters must be provided and that user must have sufficient +permissions to access the desired database. +If for any reason authorization fails, the current user authentication +will remain. +.SS Parameters +.IP \[bu] 2 +\f[C]mysql\f[R] is a connection identifier, which was previously +allocated by \f[B]mysql_init(3)\f[R] and connected by +\f[B]mysql_real_connect(3)\f[R]. +.IP \[bu] 2 +\f[C]user\f[R] \- the user name for server authentication +.IP \[bu] 2 +\f[C]passwd\f[R] \- the password for server authentication +.IP \[bu] 2 +\f[C]db\f[R] \- the default database. +If desired, the NULL value may be passed resulting in only changing the +user and not selecting a database. +To select a database in this case use the \f[B]mysql_select_db(3)\f[R] +function. +.SS Notes +.IP \[bu] 2 +mysql_change_user will always cause the current database connection to +behave as if was a completely new database connection, regardless of if +the operation was completed successfully. +This reset includes performing a rollback on any active transactions, +closing all temporary tables, and unlocking all locked tables. +.IP \[bu] 2 +To prevent denial of service and brute\-force attacks the server will +block the connection if \f[C]mysql_change_user()\f[R] failed three times +in a row +.SS Return value +.PP +Returns zero on success, nonzero if an error occurred. +.SS See also +.IP \[bu] 2 +\f[B]mysql_real_connect(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_select_db(3)\f[R] diff --git a/vendor/MDBC/man/mysql_close.3 b/vendor/MDBC/man/mysql_close.3 new file mode 100644 index 00000000..560c52dc --- /dev/null +++ b/vendor/MDBC/man/mysql_close.3 @@ -0,0 +1,28 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_close" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_close \- Closes a previously opened connection +.SS Synopsis +.IP +.nf +\f[C] +#include + +void mysql_close(MYSQL *mysql); +\f[R] +.fi +.SS Description +.PP +Closes a previously opened connection and deallocates all memory. +.SS Notes +.IP \[bu] 2 +To reuse a connection handle after \f[C]mysql_close()\f[R] the handle +must be initialized again by \f[B]mysql_init(3)\f[R]. +.SS See also +.IP \[bu] 2 +\f[B]mysql_init(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_real_connect(3)\f[R] diff --git a/vendor/MDBC/man/mysql_commit.3 b/vendor/MDBC/man/mysql_commit.3 new file mode 100644 index 00000000..3b9334d8 --- /dev/null +++ b/vendor/MDBC/man/mysql_commit.3 @@ -0,0 +1,33 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_commit" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_commit \- Commits the current transaction +.SS Synopsis +.IP +.nf +\f[C] +#include + +my_bool mysql_commit(MYSQL * mysql); +\f[R] +.fi +.SS Description +.PP +Commits the current transaction for the specified database connection. +Returns zero on success, nonzero if an error occurred. +.SS Parameters +.IP \[bu] 2 +\f[C]mysql\f[R] is a connection identifier, which was previously +allocated by \f[B]mysql_init(3)\f[R] and connected by +\f[B]mysql_real_connect(3)\f[R]. +.SS Notes +.PP +Executing mysql_commit() will not affected the behaviour of autocommit. +This means, any update or insert statements following mysql_commit() +will be rolled back when the connection gets closed. +.PP +== See also * \f[B]mysql_autocommit(3)\f[R] * +\f[B]mysql_rollback(3)\f[R] diff --git a/vendor/MDBC/man/mysql_data_seek.3 b/vendor/MDBC/man/mysql_data_seek.3 new file mode 100644 index 00000000..adfa98ae --- /dev/null +++ b/vendor/MDBC/man/mysql_data_seek.3 @@ -0,0 +1,39 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_data_seek" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_data_seek \- seeks to an offset +.SS Synopsis +.IP +.nf +\f[C] +#include + +void mysql_data_seek(MYSQL_RES * result, + my_ulonglong offset); +\f[R] +.fi +.SS Description +.PP +The mysql_data_seek() function seeks to an arbitrary function result +pointer specified by the offset in the result set. +Returns zero on success, nonzero if an error occurred. +.SS Parameters +.IP \[bu] 2 +\f[C]result\f[R] \- a result set identifier returned by +mysql_store_result(). +.IP \[bu] 2 +\f[C]offset\f[R] \- the field offset. +Must be between zero and the total number of rows minus one +(0..mysql_num_rows \- 1). +.SS Notes +.PP +This function can only be used with buffered result sets obtained from +the use of the \f[B]mysql_store_result(3)\f[R] function. +.SS See also +.IP \[bu] 2 +\f[B]mysql_num_rows(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_store_result(3)\f[R] diff --git a/vendor/MDBC/man/mysql_errno.3 b/vendor/MDBC/man/mysql_errno.3 new file mode 100644 index 00000000..2152a8d8 --- /dev/null +++ b/vendor/MDBC/man/mysql_errno.3 @@ -0,0 +1,37 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_errno" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_errno \- returns the last error code for the most recent function +call +.SS Synopsis +.IP +.nf +\f[C] +#include + +unsigned int mysql_errno(MYSQL * mysql); +\f[R] +.fi +.SS Description +.PP +Returns the last error code for the most recent function call that can +succeed or fail. +Zero means no error occurred. +.SS Parameter +.IP \[bu] 2 +\f[C]mysql\f[R] is a connection identifier, which was previously +allocated by \f[B]mysql_init(3)\f[R] and connected by +\f[B]mysql_real_connect(3)\f[R]. +.SS Notes +.IP \[bu] 2 +Client error codes are listed in \f[C]errmsg.h\f[R] header file, server +error codes are listed in \f[C]mysqld_error.h\f[R] header file of the +server source distribution. +.SS See also +.IP \[bu] 2 +\f[B]mysql_error(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_sqlstate(3)\f[R] diff --git a/vendor/MDBC/man/mysql_error.3 b/vendor/MDBC/man/mysql_error.3 new file mode 100644 index 00000000..242c6ba9 --- /dev/null +++ b/vendor/MDBC/man/mysql_error.3 @@ -0,0 +1,41 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_error" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_error \- returns the last error message for the most recent +function call +.SS Synopsis +.IP +.nf +\f[C] +#include + +const char * mysql_error(MYSQL * mysql); +\f[R] +.fi +.SS Description +.PP +Returns the last error message for the most recent function call that +can succeed or fail. +An empty string means no error occurred. +.SS Parameter +.IP \[bu] 2 +\f[C]mysql\f[R] is a connection identifier, which was previously +allocated by \f[B]mysql_init(3)\f[R] and connected by +\f[B]mysql_real_connect(3)\f[R]. +.SS Notes +.IP \[bu] 2 +Client error codes are listed in \f[C]errmsg.h\f[R] header file, server +error codes are listed in \f[C]mysqld_error.h\f[R] header file of the +server source distribution. +.IP \[bu] 2 +Client error messages can be obtained by calling +\f[B]mariadb_get_infov(3)\f[R] and passing the parameter +\f[C]MARIADB_CLIENT_ERRORS\f[R] +.SS See also +.IP \[bu] 2 +\f[B]mysql_errno(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_sqlstate(3)\f[R] diff --git a/vendor/MDBC/man/mysql_fetch_field.3 b/vendor/MDBC/man/mysql_fetch_field.3 new file mode 100644 index 00000000..3d588255 --- /dev/null +++ b/vendor/MDBC/man/mysql_fetch_field.3 @@ -0,0 +1,49 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_fetch_field" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_fetch_field \- Returns the definition of one column of a result +set +.SS Synopsis +.IP +.nf +\f[C] +#include + +MYSQL_FIELD * mysql_fetch_field(MYSQL_RES * result); +\f[R] +.fi +.SS Description +.PP +Returns the definition of one column of a result set as a pointer to a +MYSQL_FIELD structure. +Call this function repeatedly to retrieve information about all columns +in the result set. +.SS Parameters +.IP \[bu] 2 +\f[C]result\f[R] \- a result set identifier returned by +\f[B]mysql_store_result(3)\f[R] or \f[B]mysql_use_result(3)\f[R]. +.SS Notes +.IP \[bu] 2 +The field order will be reset if you execute a new SELECT query. +.IP \[bu] 2 +In case only information for a specific field is required the field can +be selected by using the \f[B]mysql_field_seek(3)\f[R] function or +obtained by \f[B]mysql_fetch_field_direct(3)\f[R] function. +.SS Return value +.PP +a pointer of a \f[C]MYSQL_FIELD\f[R] structure, or NULL if there are no +more fields. +.SS See also +.IP \[bu] 2 +\f[B]mysql_field_seek(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_field_tell(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_fetch_field_direct(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_store_result(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_use_result(3)\f[R] diff --git a/vendor/MDBC/man/mysql_fetch_field_direct.3 b/vendor/MDBC/man/mysql_fetch_field_direct.3 new file mode 100644 index 00000000..2ad3a5c6 --- /dev/null +++ b/vendor/MDBC/man/mysql_fetch_field_direct.3 @@ -0,0 +1,36 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_fetch_field_direct" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_fetch_field_direct \- Returns a pointer to a MYSQL_FIELD structure +.SS Synopsis +.IP +.nf +\f[C] +#include + +MYSQL_FIELD * mysql_fetch_field_direct(MYSQL_RES * res, + unsigned int fieldnr); +\f[R] +.fi +.SS Description +.PP +Returns a pointer to a \f[C]MYSQL_FIELD\f[R] structure which contains +field information from the specified result set. +### Parameter * \f[C]res\f[R] \- a result set identifier returned by +\f[B]mysql_store_result(3)\f[R] or \f[B]mysql_use_result(3)\f[R]. +* \f[C]fieldnr\f[R] \- the field number. +This value must be within the range from 0 to number of fields \- 1 ### +Notes * The total number of fields can be obtained by +mysql_field_count() +.SS Return value +.PP +Pointer to a \f[C]MYSQL_FIELD\f[R] structure or \f[C]NULL\f[R] if an +invalid field number was specified +.SS See also +.IP \[bu] 2 +\f[B]mysql_fetch_field(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_field_count(3)\f[R] diff --git a/vendor/MDBC/man/mysql_fetch_fields.3 b/vendor/MDBC/man/mysql_fetch_fields.3 new file mode 100644 index 00000000..1fe28648 --- /dev/null +++ b/vendor/MDBC/man/mysql_fetch_fields.3 @@ -0,0 +1,41 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_fetch_fields" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_fetch_fields \- returns an array of fields +.SS Synopsis +.IP +.nf +\f[C] +#include + +MYSQL_FIELD * mysql_fetch_fields(MYSQL_RES * res); +\f[R] +.fi +.SS Description +.PP +This function serves an identical purpose to the +\f[B]mysql_fetch_field(3)\f[R] function with the single difference that +instead of returning one field at a time for each field, the fields are +returned as an array. +Each field contains the definition for a column of the result set. +.SS Parameters +.IP \[bu] 2 +\f[C]res\f[R] \- a result set identifier returned by +\f[B]mysql_store_result(3)\f[R] or \f[B]mysql_use_result(3)\f[R]. +.SS Notes +.PP +The total number of fields can be obtained by +\f[B]mysql_field_count(3)\f[R]. +.SS Return value +.PP +an array of type \f[C]MYSQL_FIELD\f[R]. +.SS See also +.IP \[bu] 2 +\f[B]mysql_fetch_field(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_fetch_field_direct(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_field_count(3)\f[R] diff --git a/vendor/MDBC/man/mysql_fetch_lengths.3 b/vendor/MDBC/man/mysql_fetch_lengths.3 new file mode 100644 index 00000000..76f781bb --- /dev/null +++ b/vendor/MDBC/man/mysql_fetch_lengths.3 @@ -0,0 +1,41 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_fetch_lengths" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_fetch_lengths \- returns an array of length values for the current +row +.SS Synopsis +.IP +.nf +\f[C] +#include + +unsigned long * mysql_fetch_lengths(MYSQL_RES * result); +\f[R] +.fi +.SS Description +.PP +The \f[C]mysql_fetch_lengths()\f[R] function returns an array containing +the lengths of every column of the current row within the result set +(not including terminating zero character) or \f[C]NULL\f[R] if an error +occurred. +.SS Parameter +.IP \[bu] 2 +\f[C]result\f[R] \- a result set identifier returned by +\f[B]mysql_store_result(3)\f[R] or \f[B]mysql_use_result(3)\f[R]. +### Notes \f[C]mysql_fetch_lengths()\f[R] is valid only for the current +row of the result set. +It returns \f[C]NULL\f[R] if you call it before calling +\f[B]mysql_fetch_row(3)\f[R] or after retrieving all rows in the result. +.SS Return value +.PP +An array of unsigned long values . +The size of the array can be determined by the number of fields in +current result set. +.SS See also +.IP \[bu] 2 +\f[B]mysql_field_count(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_fetch_row(3)\f[R] diff --git a/vendor/MDBC/man/mysql_fetch_row.3 b/vendor/MDBC/man/mysql_fetch_row.3 new file mode 100644 index 00000000..0c52acbc --- /dev/null +++ b/vendor/MDBC/man/mysql_fetch_row.3 @@ -0,0 +1,44 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_fetch_row" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_fetch_row \- fetches row of data from result set +.SS Synopsis +.IP +.nf +\f[C] +#include + +MYSQL_ROW mysql_fetch_row(MYSQL_RES * result); +\f[R] +.fi +.SS Description +.PP +Fetches one row of data from the result set and returns it as an array +of char pointers (\f[C]MYSQL_ROW\f[R]), where each column is stored in +an offset starting from 0 (zero). +Each subsequent call to this function will return the next row within +the result set, or NULL if there are no more rows. +.SS Parameter +.IP \[bu] 2 +\f[C]result\f[R] \- a result set identifier returned by +\f[B]mysql_store_result(3)\f[R] or \f[B]mysql_use_result(3)\f[R]. +.SS Notes +.IP \[bu] 2 +If a column contains a \f[C]NULL\f[R] value the corresponding char +pointer will be set to \f[C]NULL\f[R]. +.IP \[bu] 2 +Memory associated to \f[C]MYSQL_ROW\f[R] will be freed when calling +\f[B]mysql_free_result(3)\f[R] function. +.SS Return value +.PP +A \f[C]MYSQL_ROW\f[R] structure (array of character pointers) +representing the data of the current row. +If there are no more rows available \f[C]NULL\f[R]will be returned. +.SS See also +.IP \[bu] 2 +\f[B]mysql_use_result(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_store_result(3)\f[R] diff --git a/vendor/MDBC/man/mysql_field_count.3 b/vendor/MDBC/man/mysql_field_count.3 new file mode 100644 index 00000000..aa7d1a94 --- /dev/null +++ b/vendor/MDBC/man/mysql_field_count.3 @@ -0,0 +1,43 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_field_count" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_field_count \- returns the number of columns for the most recent +statement +.SS Synopsis +.IP +.nf +\f[C] +#include + +unsigned int mysql_field_count(MYSQL * mysql); +\f[R] +.fi +.SS Description +.PP +Returns the number of columns for the most recent statement on the +connection represented by the link parameter as an unsigned integer. +This function can be useful when using the +\f[B]mysql_store_result(3)\f[R] function to determine if the query +should have produced a non\-empty result set or not without knowing the +nature of the query. +.SS Parameters +.IP \[bu] 2 +\f[C]mysql\f[R] is a connection identifier, which was previously +allocated by \f[B]mysql_init(3)\f[R] and connected by +\f[B]mysql_real_connect(3)\f[R]. +.SS Notes +.PP +The \f[C]mysql_field_count()\f[R] function should be used to determine +if there is a result set available. +.SS Return value: +.PP +The number of columns for the most recent statemet. +The value is zero, if the statemet didn\[cq]t produce a result set. +.SS See also +.IP \[bu] 2 +\f[B]mysql_store_result(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_use_result(3)\f[R] diff --git a/vendor/MDBC/man/mysql_field_seek.3 b/vendor/MDBC/man/mysql_field_seek.3 new file mode 100644 index 00000000..f0251db8 --- /dev/null +++ b/vendor/MDBC/man/mysql_field_seek.3 @@ -0,0 +1,43 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_field_seek" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_field_seek \- sets the field cursor to given offset +.SS Synopsis +.IP +.nf +\f[C] +#include + +MYSQL_FIELD_OFFSET mysql_field_seek(MYSQL_RES * result, + MYSQL_FIELD_OFFSET offset); +\f[R] +.fi +.SS Description +.PP +Sets the field cursor to the given offset. +The next call to \f[B]mysql_fetch_field(3)\f[R] will retrieve the field +definition of the column associated with that offset. +.SS Parameters +.IP \[bu] 2 +\f[C]result\f[R] \- a result set identifier returned by +\f[B]mysql_store_result(3)\f[R] or \f[B]mysql_use_result(3)\f[R]. +.IP \[bu] 2 +\f[C]offset\f[R] \- the field number. +This number must be in the range from +\f[C]0\f[R]..\f[C]number of fields \- 1\f[R]. +.SS Notes +.IP \[bu] 2 +The number of fields can be obtained from \f[B]mysql_field_count(3)\f[R] +\&. +.IP \[bu] 2 +To move the field cursor to the first field offset parameter should be +zero. +.SS Return value +.PP +Returns the previous value of the field cursor +.SS See also +.IP \[bu] 2 +\f[B]mysql_field_tell(3)\f[R] diff --git a/vendor/MDBC/man/mysql_field_tell.3 b/vendor/MDBC/man/mysql_field_tell.3 new file mode 100644 index 00000000..f6026dce --- /dev/null +++ b/vendor/MDBC/man/mysql_field_tell.3 @@ -0,0 +1,32 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_field_tell" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_field_tell \- Returns offset of the field cursor +.SS Synopsis +.IP +.nf +\f[C] +#include + +MYSQL_FIELD_OFFSET mysql_field_tell(MYSQL_RES * result); +\f[R] +.fi +.SS Description +.PP +Return the offset of the field cursor used for the last +\f[B]mysql_fetch_field(3)\f[R] call. +This value can be used as a parameter for the function +\f[B]mysql_field_seek(3)\f[R]. +.SS Parameter +.IP \[bu] 2 +\f[C]result\f[R] \- a result set identifier returned by +\f[B]mysql_store_result(3)\f[R] or \f[B]mysql_use_result(3)\f[R]. +.SS Return value +.PP +Returns the current offset of the field cursor +.SS See also +.IP \[bu] 2 +\f[B]mysql_field_seek(3)\f[R] diff --git a/vendor/MDBC/man/mysql_free_result.3 b/vendor/MDBC/man/mysql_free_result.3 new file mode 100644 index 00000000..3e9bdd10 --- /dev/null +++ b/vendor/MDBC/man/mysql_free_result.3 @@ -0,0 +1,36 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_free_result" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_free_result \- Frees result set +.SS Synopsis +.IP +.nf +\f[C] +#include + +void mysql_free_result(MYSQL_RES * result); +\f[R] +.fi +.SS Description +.PP +Frees the memory associated with a result set. +Returns void. +.SS Parameters +.IP \[bu] 2 +\f[C]result\f[R] \- a result set identifier returned by +\f[B]mysql_store_result(3)\f[R] or \f[B]mysql_use_result(3)\f[R]. +.SS Notes +.IP \[bu] 2 +You should always free your result set with mysql_free_result() as soon +it\[cq]s not needed anymore +.IP \[bu] 2 +Row values obtained by a prior \f[B]mysql_fetch_row(3)\f[R] call will +become invalid after calling mysql_free_result(). +.SS See also +.IP \[bu] 2 +\f[B]mysql_store_result(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_use_result(3)\f[R] diff --git a/vendor/MDBC/man/mysql_get_character_set_info.3 b/vendor/MDBC/man/mysql_get_character_set_info.3 new file mode 100644 index 00000000..886aa8d4 --- /dev/null +++ b/vendor/MDBC/man/mysql_get_character_set_info.3 @@ -0,0 +1,39 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_get_character_set_info" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_get_character_set_info \- returns character set information +.SS Synopsis +.IP +.nf +\f[C] +#include + +void mysql_get_character_set_info(MYSQL * mysql, + MY_CHARSET_INFO * charset); +\f[R] +.fi +.SS Description +.PP +Returns information about the current default character set for the +specified connection. +.SS Parameters +.IP \[bu] 2 +\f[C]mysql\f[R] \- a connection identifier, which was previously +allocated by \f[B]mysql_init(3)\f[R] and connected by +\f[B]mysql_real_connect(3)\f[R]. +.IP \[bu] 2 +\f[C]charset\f[R] \- a pointer to a \f[C]MY_CHARSET_INFO\f[R] structure, +in which the information will be copied. +.SS Notes +.IP \[bu] 2 +A complete list of supported character sets in the client library is +listed in the function description for +\f[B]mysql_set_character_set(3)\f[R]. +.SS See also +.IP \[bu] 2 +\f[B]mariadb_get_infov(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_set_character_set(3)\f[R] diff --git a/vendor/MDBC/man/mysql_get_client_info.3 b/vendor/MDBC/man/mysql_get_client_info.3 new file mode 100644 index 00000000..8d055632 --- /dev/null +++ b/vendor/MDBC/man/mysql_get_client_info.3 @@ -0,0 +1,31 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_get_client_info" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_get_client_info \- returns client library version as string +representation +.SS Synopsis +.IP +.nf +\f[C] +#include + +const char * mysql_get_client_info(void ); +\f[R] +.fi +.SS Description +.PP +Returns a string representing the client library version +.SS Notes +.PP +To obtain the numeric value of the client library version use +\f[B]mysql_get_client_version(3)\f[R]. +.SS See also +.IP \[bu] 2 +\f[B]mysql_get_client_version(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_get_host_info(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_get_proto_info(3)\f[R] diff --git a/vendor/MDBC/man/mysql_get_client_version.3 b/vendor/MDBC/man/mysql_get_client_version.3 new file mode 100644 index 00000000..c1b524ff --- /dev/null +++ b/vendor/MDBC/man/mysql_get_client_version.3 @@ -0,0 +1,32 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_get_client_version" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_get_client_version \- returns client version number +.SS Synopsis +.IP +.nf +\f[C] +unsigned long mysql_get_client_version(void); +\f[R] +.fi +.SS Description +.PP +Returns a number representing the client library version. +The value has the format XXYYZZ: major version * 10000 + minor version * +100 + patch version. +### Notes * To obtain a string containing the client library version use +the \f[B]mysql_get_client_info(3)\f[R] function. +* Note: Since MariaDB Server 10.2.6 and MariaDB Connector/C 3.0.1 the +client library is bundled with server package and returns the server +package version. +To obtain the client version of the connector, please use the constant +\f[C]MARIADB_PACKAGE_VERSION_ID\f[R] +.SS Return value +.PP +A long integer representing the client version +.SS See also +.IP \[bu] 2 +\f[B]mysql_get_client_info(3)\f[R] diff --git a/vendor/MDBC/man/mysql_get_host_info.3 b/vendor/MDBC/man/mysql_get_host_info.3 new file mode 100644 index 00000000..a7dbd3c2 --- /dev/null +++ b/vendor/MDBC/man/mysql_get_host_info.3 @@ -0,0 +1,32 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_get_host_info" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_get_host_info \- Returns host information +.SS Synopsis +.IP +.nf +\f[C] +#include +const char * mysql_get_host_info(MYSQL * mysql); +\f[R] +.fi +.SS Description +.PP +Describes the type of connection in use for the connection, including +the server host name. +Returns a string, or NULL if the connection is not valid. +.SS Parameter +.IP \[bu] 2 +\f[C]mysql\f[R] \- a connection identifier, which was previously +allocated by \f[B]mysql_init(3)\f[R] and connected by +\f[B]mysql_real_connect(3)\f[R]. +.SS Return value +.PP +Returns a string, describing host information or \f[C]NULL\f[R] if the +connection is not valid. +.SS See also +.IP \[bu] 2 +\f[B]mysql_get_server_version(3)\f[R] diff --git a/vendor/MDBC/man/mysql_get_proto_info.3 b/vendor/MDBC/man/mysql_get_proto_info.3 new file mode 100644 index 00000000..489eddd1 --- /dev/null +++ b/vendor/MDBC/man/mysql_get_proto_info.3 @@ -0,0 +1,33 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_get_proto_info" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_get_proto_info \- Returns protocol version number +.SS Synopsis +.IP +.nf +\f[C] +#include + +unsigned int mysql_get_proto_info(MYSQL * mysql); +\f[R] +.fi +.SS Description +.PP +Returns the protocol version number for the specified connection +.SS Parameter +.IP \[bu] 2 +\f[C]mysql\f[R] \- a connection identifier, which was previously +allocated by \f[B]mysql_init(3)\f[R] and connected by +\f[B]mysql_real_connect(3)\f[R]. +.SS Notes +.PP +MariaDB Connector/C doesn\[cq]t support protocol version 9 and prior. +.SS Return value +.PP +The protocol version number in use +.SS See also +.IP \[bu] 2 +\f[B]mysql_get_host_info(3)\f[R] diff --git a/vendor/MDBC/man/mysql_get_server_info.3 b/vendor/MDBC/man/mysql_get_server_info.3 new file mode 100644 index 00000000..0524d9b8 --- /dev/null +++ b/vendor/MDBC/man/mysql_get_server_info.3 @@ -0,0 +1,37 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_get_server_info" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_get_server_info \- Returns server version as string +.SS Synopsis +.IP +.nf +\f[C] +#include + +const char * mysql_get_server_info(MYSQL * mysql); +\f[R] +.fi +.SS Description +.PP +Returns the server version or \f[C]NULL\f[R] on failure. +.SS Parameter +.IP \[bu] 2 +\f[C]mysql\f[R] \- a connection identifier, which was previously +allocated by \f[B]mysql_init(3)\f[R] and connected by +\f[B]mysql_real_connect(3)\f[R]. +.SS Notes +.PP +To obtain the numeric server version please use +\f[B]mysql_get_server_version(3)\f[R]. +.SS Return value +.PP +Returns the server version as zero terminated string or \f[C]NULL\f[R]on +failure. +.SS See also +.IP \[bu] 2 +\f[B]mysql_get_server_info(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_get_client_info(3)\f[R] diff --git a/vendor/MDBC/man/mysql_get_server_version.3 b/vendor/MDBC/man/mysql_get_server_version.3 new file mode 100644 index 00000000..60dcdce4 --- /dev/null +++ b/vendor/MDBC/man/mysql_get_server_version.3 @@ -0,0 +1,34 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_get_server_version" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_get_server_version \- returns numeric server version +.SS Synopsis +.IP +.nf +\f[C] +#include + +unsigned long mysql_get_server_version(MYSQL * mysql); +\f[R] +.fi +.SS Description +.PP +Returns an integer representing the version of connected server. +.SS Parameter +.IP \[bu] 2 +\f[C]mysql\f[R] \- a connection identifier, which was previously +allocated by \f[B]mysql_init(3)\f[R] and connected by +\f[B]mysql_real_connect(3)\f[R]. +.SS Notes +.PP +The form of the version number is VERSION_MAJOR * 10000 + VERSION_MINOR +* 100 + VERSION_PATCH. +.SS Return value +.PP +The version number of the connected server +.SS See also +.IP \[bu] 2 +\f[B]mysql_get_server_info(3)\f[R] diff --git a/vendor/MDBC/man/mysql_get_socket.3 b/vendor/MDBC/man/mysql_get_socket.3 new file mode 100644 index 00000000..6c5b58ec --- /dev/null +++ b/vendor/MDBC/man/mysql_get_socket.3 @@ -0,0 +1,33 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_get_socket" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_get_socket \- Returns the descriptor of the socket used for the +current connection +.SS Synopsis +.IP +.nf +\f[C] +#include + +my_socket mysql_get_socket(MYSQL * mysql); +\f[R] +.fi +.SS Description +.PP +Returns the descriptor of the socket used for the current connection. +.SS Parameter +.IP \[bu] 2 +\f[C]mysql\f[R] \- a mysql handle, which was previously allocated by +\f[B]mysql_init(3)\f[R] and connected by +\f[B]mysql_real_connect(3)\f[R]. +.SS Return value +.PP +A socket handle or INVALID_SOCKET (\-1) if the socket descriptor could +not be determined, e.g.\ if the connection doesn\[cq]t use a socket +connection. +.SS See also +.IP \[bu] 2 +\f[B]mysql_real_connect(3)\f[R] diff --git a/vendor/MDBC/man/mysql_get_ssl_cipher.3 b/vendor/MDBC/man/mysql_get_ssl_cipher.3 new file mode 100644 index 00000000..bbc58f7b --- /dev/null +++ b/vendor/MDBC/man/mysql_get_ssl_cipher.3 @@ -0,0 +1,47 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_get_ssl_cipher" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_get_ssl_cipher \- returns the cipher suite in use +.SS Synopsis +.IP +.nf +\f[C] +#include + +const char *mysql_get_ssl_cipher(MYSQL *mysql) +\f[R] +.fi +.SS Description +.PP +Returns the name of the currently used cipher suite of the secure +connection, or NULL for non TLS connections. +.SS Parameter +.IP \[bu] 2 +\f[C]mysql\f[R] \- a connection identifier, which was previously +allocated by \f[B]mysql_init(3)\f[R] and connected by +\f[B]mysql_real_connect(3)\f[R]. +.SS Notes +.IP \[bu] 2 +For using \f[C]mysql_get_ssl_cipher()\f[R] MariaDB Connector/C must be +built with TLS/SSL support, otherwise the function will return NULL. +.IP \[bu] 2 +\[ga]mysql_get_ssl_cipher()\[cq] can be used to determine if the client +server connection is secure. +.IP \[bu] 2 +Depending on the TLS library in use (OpenSSL, GnuTLS or Windows +Schannel) the name of the cipher suites may differ. +For example the cipher suite 0x002F +(\f[C]TLS_RSA_WITH_AES_128_CBC_SHA\f[R]) has different names: +\f[C]AES128\-SHA\f[R] for OpenSSL and Schannel and +\f[C]TLS_RSA_AES_128_CBC_SHA1\f[R] for GnuTLS. +.SS Return value +.PP +Returns a zero terminated string containing the cipher suite used for a +secure connection, or \f[C]NULL\f[R] if connection doesn\[cq]t use +TLS/SSL. +.SS See also +.IP \[bu] 2 +\f[B]mysql_ssl_set(3)\f[R] diff --git a/vendor/MDBC/man/mysql_hex_string.3 b/vendor/MDBC/man/mysql_hex_string.3 new file mode 100644 index 00000000..d5788306 --- /dev/null +++ b/vendor/MDBC/man/mysql_hex_string.3 @@ -0,0 +1,41 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_hex_string" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_hex_string \- create a hexadecimal string +.SS Synopsis +.IP +.nf +\f[C] +#include +unsigned long mysql_hex_string(char * to, + const char * from, + unsigned long len); +\f[R] +.fi +.SS Description +.PP +This function is used to create a hexadecimal string which can be used +in SQL statements. +e.g.\ \f[C]INSERT INTO my_blob VALUES(X\[aq]A0E1CD\[aq])\f[R]. +.SS Parameter +.IP \[bu] 2 +\f[C]to\f[R] \- result buffer +.IP \[bu] 2 +\f[C]from\f[R] \- the string which will be encoded +.IP \[bu] 2 +\f[C]len\f[R] \- length of the string (from) +.SS Notes +.IP \[bu] 2 +The size of the buffer for the encoded string must be 2 * length + 1. +.IP \[bu] 2 +The encoded string does not contain a leading X\[cq]. +.SS Return value +.PP +Returns the length of the encoded string without the trailing null +character. +.SS See also +.IP \[bu] 2 +\f[B]mysql_real_escape_string(3)\f[R] diff --git a/vendor/MDBC/man/mysql_info.3 b/vendor/MDBC/man/mysql_info.3 new file mode 100644 index 00000000..f486f0c9 --- /dev/null +++ b/vendor/MDBC/man/mysql_info.3 @@ -0,0 +1,76 @@ +.\"t +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_info" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_info \- provides information about the last executed statement +.SS Synopsis +.IP +.nf +\f[C] +#include + +const char * mysql_info(MYSQL * mysql); +\f[R] +.fi +.SS Description +.PP +The \f[C]mysql_info()\f[R] function returns a string providing +information about the last statement executed. +.SS Parameter +.IP \[bu] 2 +\f[C]mysql\f[R] \- a connection identifier, which was previously +allocated by \f[B]mysql_init(3)\f[R] and connected by +\f[B]mysql_real_connect(3)\f[R]. +.SS Notes +.PP +Statements which do not fall into one of the preceding formats are not +supported (e.g.\ \f[C]SELECT\f[R]). +In these situations mysql_info() will return an empty string. +.SS Return value +.PP +Zero terminated information string. +The information depends on statement type: +.PP +.TS +tab(@); +lw(35.0n) lw(35.0n). +T{ +Query type +T}@T{ +Example result string +T} +_ +T{ +\f[C]INSERT INTO...SELECT...\f[R] +T}@T{ +Records: 100 Duplicates: 0 Warnings: 0 +T} +T{ +\f[C]INSERT INTO...VALUES (...),(...),(...)\f[R] +T}@T{ +Records: 3 Duplicates: 0 Warnings: 0 +T} +T{ +\f[C]LOAD DATA INFILE\f[R] +T}@T{ +Records: 1 Deleted: 0 Skipped: 0 Warnings: 0 +T} +T{ +\f[C]ALTER TABLE ...\f[R] +T}@T{ +Records: 3 Duplicates: 0 Warnings: 0 +T} +T{ +\f[C]UPDATE ...\f[R] +T}@T{ +Rows matched: 40 Changed: 40 Warnings: 0 +T} +.TE +.SS See also +.IP \[bu] 2 +\f[B]mysql_affected_rows(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_warning_count(3)\f[R] diff --git a/vendor/MDBC/man/mysql_init.3 b/vendor/MDBC/man/mysql_init.3 new file mode 100644 index 00000000..fb6264dc --- /dev/null +++ b/vendor/MDBC/man/mysql_init.3 @@ -0,0 +1,39 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_init" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_init \- Prepares and initializes a \f[C]MYSQL\f[R] structure +.SS Synopsis +.IP +.nf +\f[C] +#include + +MYSQL *mysql_init(MYSQL *mysql); +\f[R] +.fi +.SS Description +.PP +Prepares and initializes a \f[C]MYSQL\f[R] structure to be used with +\f[B]mysql_real_connect(3)\f[R]. +If an address of a \f[C]MYSQL\f[R] structure was passed as parameter, +the structure will be initialized, if \f[C]NULL\f[R] was passed, a new +structure will be allocated and initialized. +.PP +\f[B]Notes:\f[R] * If parameter \f[C]mysql\f[R] is not \f[C]NULL\f[R] +\f[B]mysql_close(3)\f[R] API function will not release the memory * Any +subsequent calls to any function (except \f[B]mysql_optionsv(3)\f[R] +will fail until \f[B]mysql_real_connect(3)\f[R] was called. +* Memory allocated by \f[C]mysql_init()\f[R] must be freed with +\f[B]mysql_close(3)\f[R]. +.SS Return value +.PP +The \f[C]mysql_init()\f[R] function returns an address of a +\f[C]MYSQL\f[R] structure, or NULL in case of memory allcation error. +.SS See also +.IP \[bu] 2 +\f[B]mysql_close(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_optionsv(3)\f[R] diff --git a/vendor/MDBC/man/mysql_kill.3 b/vendor/MDBC/man/mysql_kill.3 new file mode 100644 index 00000000..c3680dc1 --- /dev/null +++ b/vendor/MDBC/man/mysql_kill.3 @@ -0,0 +1,51 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_kill" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_kill \- Kills a connection +.SS Synopsis +.IP +.nf +\f[C] +#include + +int mysql_kill(MYSQL * mysql, + unsigned long); +\f[R] +.fi +.SS Description +.PP +This function is used to ask the server to kill a MariaDB thread +specified by the processid parameter. +This value must be retrieved by [show\-processlist()](SHOW +PROCESSLIST]]. +If trying to kill the own connection \f[B]mysql_thread_id(3)\f[R] should +be used. +.SS Parameter +.IP \[bu] 2 +\f[C]mysql\f[R] \- a connection identifier, which was previously +allocated by \f[B]mysql_init(3)\f[R] and connected by +\f[B]mysql_real_connect(3)\f[R]. +Returns 0 on success, otherwise nonzero. +.IP \[bu] 2 +\f[C]long\f[R] \- process id +.SS Notes +.IP \[bu] 2 +To stop a running command without killing the connection use +\f[C]KILL QUERY\f[R]. +.IP \[bu] 2 +The \f[C]mysql_kill()\f[R] function only kills a connection, it +doesn\[cq]t free any memory \- this must be done explicitly by calling +\f[B]mysql_close(3)\f[R]. +.SS Return value +.PP +Returns zero on success, non zero on error. +.SS See also +.IP \[bu] 2 +\f[B]mysql_thread_id(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_close(3)\f[R] +.IP \[bu] 2 +\f[B]mariadb_cancel(3)\f[R] diff --git a/vendor/MDBC/man/mysql_more_results.3 b/vendor/MDBC/man/mysql_more_results.3 new file mode 100644 index 00000000..bbecabf8 --- /dev/null +++ b/vendor/MDBC/man/mysql_more_results.3 @@ -0,0 +1,47 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_more_results" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_more_results \- indicates if one or more results are available +.SS Synopsis +.IP +.nf +\f[C] +#include + +my_bool mysql_more_results(MYSQL * mysql); +\f[R] +.fi +.SS Description +.PP +Indicates if one or more result sets are available from a previous call +to \f[B]mysql_real_query(3)\f[R]. +.SS Parameter +.IP \[bu] 2 +\f[C]mysql\f[R] \- a connection identifier, which was previously +allocated by \f[B]mysql_init(3)\f[R] and connected by +\f[B]mysql_real_connect(3)\f[R]. +.SS Notes +.IP \[bu] 2 +The function \f[B]mysql_set_server_option(3)\f[R] enables or disables +multi statement support. +.IP \[bu] 2 +Multiple result sets can be obtained either by calling a stored +procedure or by executing concatenated statements, +e.g.\ \f[C]SELECT a FROM t1;SELECT b, c FROM t2\f[R]. +.SS Return value +.PP +Returns 1 if more result sets are available, otherwise zero. +.SS See also +.IP \[bu] 2 +\f[B]mysql_real_query(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_use_result(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_store_result(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_next_result(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_set_server_option(3)\f[R] diff --git a/vendor/MDBC/man/mysql_next_result.3 b/vendor/MDBC/man/mysql_next_result.3 new file mode 100644 index 00000000..9e608fea --- /dev/null +++ b/vendor/MDBC/man/mysql_next_result.3 @@ -0,0 +1,45 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_next_result" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_next_result \- prepares next result set +.SS Synopsis +.IP +.nf +\f[C] +#include + +int mysql_next_result(MYSQL * mysql); +\f[R] +.fi +.SS Description +.PP +Prepares next result set from a previous call to +\f[B]mysql_real_query(3)\f[R] which can be retrieved by +\f[B]mysql_store_result(3)\f[R] or +[mysql_use_result()](()](mysql_use_result). +Returns zero on success, nonzero if an error occurred. +.SS Parameter +.IP \[bu] 2 +\f[C]mysql\f[R] \- a mysql handle, which was previously allocated by +\f[B]mysql_init(3)\f[R] and connected by +\f[B]mysql_real_connect(3)\f[R]. +.SS Notes +.IP \[bu] 2 +If a multi query contains errors the return value of +\f[B]mysql_errno(3)\f[R] and \f[B]mysql_error(3)\f[R] might change and +there will be no result set available. +.SS Return value +.PP +Returns zero on success, non zero value on error. +.SS See also +.IP \[bu] 2 +\f[B]mysql_real_query(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_store_result(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_use_result(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_more_results(3)\f[R] diff --git a/vendor/MDBC/man/mysql_num_fields.3 b/vendor/MDBC/man/mysql_num_fields.3 new file mode 100644 index 00000000..19fd2388 --- /dev/null +++ b/vendor/MDBC/man/mysql_num_fields.3 @@ -0,0 +1,31 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_num_fields" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_num_fields \- Returns number of fields in a result set +.SS Synopsis +.IP +.nf +\f[C] +#include + +unsigned int mysql_num_fields(MYSQL_RES * ); +\f[R] +.fi +.SS Description +.PP +Returns number of fields in a specified result set. +.SS Parameter +.IP \[bu] 2 +\f[C]MYSQL RES *\f[R] \- A result set identifier returned by +\f[B]mysql_store_result(3)\f[R] or \f[B]mysql_use_result(3)\f[R]. +.SS Return value +.PP +Returns number of fields. +.SS See also +.IP \[bu] 2 +\f[B]mysql_fetch_field(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_field_count(3)\f[R] diff --git a/vendor/MDBC/man/mysql_num_rows.3 b/vendor/MDBC/man/mysql_num_rows.3 new file mode 100644 index 00000000..f9d52eac --- /dev/null +++ b/vendor/MDBC/man/mysql_num_rows.3 @@ -0,0 +1,35 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_num_rows" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_num_rows \- Returns number of rows in a result set. +.SS Synopsis +.IP +.nf +\f[C] +#include + +my_ulonglong mysql_num_rows(MYSQL_RES * ); +\f[R] +.fi +.SS Description +.PP +Returns number of rows in a result set. +.SS Parameters +.IP \[bu] 2 +\f[C]MYSQL_RES\f[R] \- a result set identifier returned by +\f[B]mysql_store_result(3)\f[R] or \f[B]mysql_use_result(3)\f[R]. +### Notes The behaviour of \f[C]mysql_num_rows()\f[R] depends on whether +buffered or unbuffered result sets are being used. +For unbuffered result sets, \f[C]mysql_num_rows()\f[R] will not return +the correct number of rows until all the rows in the result have been +retrieved. +.SS See also +.IP \[bu] 2 +\f[B]mysql_affected_rows(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_use_result(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_store_result(3)\f[R] diff --git a/vendor/MDBC/man/mysql_options.3 b/vendor/MDBC/man/mysql_options.3 new file mode 100644 index 00000000..7962f596 --- /dev/null +++ b/vendor/MDBC/man/mysql_options.3 @@ -0,0 +1,37 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_options" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_options \- Used to set extra connect options and affect behavior +of a connection +.SS Synopsis +.IP +.nf +\f[C] +#include + +int mysql_options(MYSQL * mysql, + enum mysql_option, + const void * arg); +\f[R] +.fi +.SS Description +.PP +Used to set extra connect options and affect behavior for a connection. +This function may be called multiple times to set several options. +\f[C]mysql_options()\f[R] should be called after +\f[B]mysql_init(3)\f[R]. +.SS Notes +.PP +This function is deprecated, new implementations should use +\f[B]mysql_optionsv(3)\f[R] api function instead. +.SS Options +.PP +An overview of the possible options can be found in the description of +the \f[B]mysql_optionsv(3)\f[R] API function. +.SS See Also +.PP +\f[I]\f[BI]mysql_init(3)\f[I] \f[R]\f[B]mysql_optionsv(3)\f[R] +*\f[B]mysql_real_connect(3)\f[R] diff --git a/vendor/MDBC/man/mysql_options4.3 b/vendor/MDBC/man/mysql_options4.3 new file mode 100644 index 00000000..99f41969 --- /dev/null +++ b/vendor/MDBC/man/mysql_options4.3 @@ -0,0 +1,38 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_options4" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_options4 \- Used to set extra connect options and affect behavior +of a connection +.SS Synopsis +.IP +.nf +\f[C] +#include + +int mysql_options4(MYSQL * mysql, + enum mysql_option, + const void * arg1, + const void * arg2); +\f[R] +.fi +.SS Description +.PP +Used to set extra connect options and affect behavior for a connection. +This function may be called multiple times to set several options. +\f[C]mysql_options()\f[R] should be called after +\f[B]mysql_init(3)\f[R]. +.SS Notes +.PP +This function is deprecated, new implementations should use +\f[B]mysql_optionsv(3)\f[R] api function instead. +.SS Options +.PP +An overview of the possible options can be found in the description of +the \f[B]mysql_optionsv(3)\f[R] API function. +.SS See Also +.PP +\f[I]\f[BI]mysql_init(3)\f[I] \f[R]\f[B]mysql_optionsv(3)\f[R] +*\f[B]mysql_real_connect(3)\f[R] diff --git a/vendor/MDBC/man/mysql_optionsv.3 b/vendor/MDBC/man/mysql_optionsv.3 new file mode 100644 index 00000000..f9a2a00e --- /dev/null +++ b/vendor/MDBC/man/mysql_optionsv.3 @@ -0,0 +1,390 @@ +.\"t +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_optionsv" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_optionsv \- Used to set extra connect options and affect behavior +of a connection +.SS Synopsis +.IP +.nf +\f[C] +#include + +int mysql_optionsv(MYSQL * mysql, + enum mysql_option, + const void * arg, + ...); +\f[R] +.fi +.SS Description +.PP +Used to set extra connect options and affect behavior for a connection. +This function may be called multiple times to set several options. +\f[C]mysql_optionsv()\f[R] should be called after +\f[B]mysql_init(3)\f[R]. +.SS Options +.PP +The following table shows which variable type to use for each option. +.PP +.TS +tab(@); +lw(35.0n) lw(35.0n). +T{ +Variable Type +T}@T{ +Values +T} +_ +T{ +\f[C]my_bool\f[R] +T}@T{ +\f[C]MYSQL_OPT_RECONNECT\f[R], \f[C]MYSQL_OPT_LOCAL_INFILE\f[R], +\f[C]MYSQL_SECURE_AUTH\f[R], \f[C]MYSQL_REPORT_DATA_TRUNCATION\f[R], +\f[C]MYSQL_OPT_SSL_ENFORCE\f[R], +\f[C]MYSQL_OPT_SSL_VERIFY_SERVER_CERT\f[R] +T} +T{ +\f[C]unsigned int\f[R] +T}@T{ +\f[C]MYSQL_OPT_PORT\f[R], \f[C]MYSQL_OPT_CONNECT_TIMEOUT\f[R], +\f[C]MYSQL_OPT_PROTOCOL\f[R], \f[C]MYSQL_OPT_READ_TIMEOUT\f[R], +\f[C]MYSQL_OPT_WRITE_TIMEOUT\f[R] +T} +T{ +\f[C]unsigned long\f[R] +T}@T{ +\f[C]MYSQL_OPT_NET_BUFFER_LENGTH\f[R], +\f[C]MYSQL_OPT_MAX_ALLOWED_PACKET\f[R] +T} +T{ +\f[C]const char *\f[R] +T}@T{ +\f[C]MYSQL_INIT_COMMAND\f[R], \f[C]MARIADB_OPT_UNIXSOCKET\f[R], +\f[C]MARIADB_OPT_PASSWORD\f[R] , \f[C]MARIADB_OPT_USER\f[R], +\f[C]MARIADB_OPT_HOST\f[R], \f[C]MARIADB_OPT_SCHEMA\f[R], +\f[C]MYSQL_OPT_SSL_KEY\f[R], \f[C]MYSQL_OPT_SSL_CERT\f[R], +\f[C]MYSQL_OPT_SSL_CA\f[R], \f[C]MYSQL_OPT_SSL_CAPATH\f[R], +\f[C]MYSQL_SET_CHARSET_NAME\f[R], \f[C]MYSQL_SET_CHARSET_DIR\f[R], +\f[C]MYSQL_OPT_SSL_CIPHER\f[R], \f[C]MYSQL_SHARED_MEMORY_BASE_NAME\f[R], +\f[C]MYSQL_PLUGIN_DIR\f[R], \f[C]MYSQL_DEFAULT_AUTH\f[R], +\f[C]MARIADB_OPT_SSL_FP\f[R], \f[C]MARIADB_OPT_SSL_FP_LIST\f[R], +\f[C]MARIADB_OPT_TLS_PASSPHRASE\f[R], \f[C]MARIADB_OPT_TLS_VERSION\f[R], +\f[C]MYSQL_OPT_BIND\f[R], \f[C]MYSQL_OPT_CONNECT_ATTR_DELETE\f[R], +\f[C]MYSQL_OPT_CONNECT_ATTR_ADD\f[R], +\f[C]MARIADB_OPT_CONNECTION_HANDLER\f[R], +\f[C]MYSQL_SERVER_PUBLIC_KEY\f[R] +T} +T{ +\- +T}@T{ +\f[C]MYSQL_OPT_CONNECT_ATTR_RESET\f[R] +T} +.TE +.IP \[bu] 2 +\f[C]MYSQL_INIT_COMMAND\f[R] +.PD 0 +.P +.PD +Command(s) which will be executed when connecting and reconnecting to +the server. +.IP \[bu] 2 +\f[C]MYSQL_OPT_COMPRESS\f[R] +.PD 0 +.P +.PD +Use the compressed protocol for client server communication. +If the server doesn\[cq]t support compressed protocol, the default +protocol will be used. +.IP \[bu] 2 +\f[C]MYSQL_OPT_CONNECT_TIMEOUT\f[R] +.PD 0 +.P +.PD +Connect timeout in seconds. +This value will be passed as an unsigned ##int## parameter. +.IP \[bu] 2 +\f[C]MYSQL_OPT_LOCAL_INFILE\f[R] +.PD 0 +.P +.PD +Enable or disable the use of \f[C]LOAD DATA LOCAL INFILE\f[R] +.IP \[bu] 2 +\f[C]MYSQL_OPT_NAMED_PIPE\f[R] +.PD 0 +.P +.PD +For Windows operating systems only: Use named pipes for client/server +communication. +.IP \[bu] 2 +\f[C]MYSQL_PROGRESS_CALLBACK\f[R] +.PD 0 +.P +.PD +Specifies a callback function which will be able to visualize the +progress of certain long running statements +(i.e.\ \f[C]LOAD DATA LOCAL INFILE\f[R] or \f[C]ALTER TABLE\f[R]). +The callback function must be defined as followed: +.IP +.nf +\f[C] +static void report_progress(const MYSQL *mysql __attribute__((unused)), + uint stage, uint max_stage, + double progress __attribute__((unused)), + const char *proc_info __attribute__((unused)), + uint proc_info_length __attribute__((unused))) +\f[R] +.fi +.IP \[bu] 2 +\f[C]MYSQL_OPT_PROTOCOL\f[R] +.PD 0 +.P +.PD +Specify the type of client/server protocol. +Possible values are: \f[C]MYSQL_PROTOCOL_TCP\f[R], +\f[C]MYSQL_PROTOCOL_SOCKET\f[R], \f[C]MYSQL_PROTOCOL_PIPE\f[R] and +\f[C]MYSQL_PROTOCOL_MEMORY\f[R]. +.IP \[bu] 2 +\f[C]MYSQL_OPT_RECONNECT\f[R] +.PD 0 +.P +.PD +Enable or disable automatic reconnect. +.IP \[bu] 2 +\f[C]MYSQL_OPT_READ_TIMEOUT\f[R] +.PD 0 +.P +.PD +Specifies the timeout in seconds for reading packets from the server. +.IP \[bu] 2 +\f[C]MYSQL_OPT_WRITE_TIMEOUT\f[R] +.PD 0 +.P +.PD +Specifies the timeout in seconds for sending packets to the server. +.IP \[bu] 2 +\f[C]MYSQL_READ_DEFAULT_FILE\f[R] +.PD 0 +.P +.PD +Read options from named configuration file. +To read from default \f[C]my.cnf\f[R] configuration file, a NULL pointer +has to be passed with option MYSQL_READ_DEFAULT_GROUP. +\f[B]Note:\f[R] MariaDB Connector/C will not read the configuration by +default. +If \f[C]MYSQL_READ_DEFAULT_FILE\f[R] is specified the following sections +will be always processed: +.IP \[bu] 2 +[client] +.IP \[bu] 2 +[client\-server] +.IP \[bu] 2 +[client\-mariadb] +.IP \[bu] 2 +\f[C]MYSQL_READ_DEFAULT_GROUP\f[R] +.PD 0 +.P +.PD +Read options from the named group from +[[configuring\-mariadb\-with\-mycnf|my.cnf]] or the file specified with +MYSQL_READ_DEFAULT_FILE. +.IP \[bu] 2 +\f[C]MYSQL_REPORT_DATA_TRUNCATION\f[R] +.PD 0 +.P +.PD +Enable or disable reporting data truncation errors for prepared +statements. +.IP \[bu] 2 +\f[C]MYSQL_OPT_BIND\f[R] +.PD 0 +.P +.PD +Specify the network interface from which to connect to MariaDB Server. +.IP \[bu] 2 +\f[C]MYSQL_PLUGIN_DIR\f[R] +.PD 0 +.P +.PD +Specify the location of client plugins. +.IP \[bu] 2 +\f[C]MYSQL_OPT_NONBLOCK\f[R] +.PD 0 +.P +.PD +Specify stack size for non blocking operations. +The argument for MYSQL_OPT_NONBLOCK is the size of the stack used to +save the state of a non\-blocking operation while it is waiting for I/O +and the application is doing other processing. +Normally, applications will not have to change this, and it can be +passed as zero to use the default value. +.IP \[bu] 2 +\f[C]MARIADB_OPT_CONNECTION_HANDLER\f[R] +.PD 0 +.P +.PD +Specify the name of a connection handler plugin. +.IP \[bu] 2 +\f[C]MARIADB_OPT_USERDATA\f[R] +.PD 0 +.P +.PD +Bundle user data to the current connection, e.g.\ for use in connection +handler plugins. +This option requires 4 parameters: connection, option, key and value: +.IP +.nf +\f[C] +mysql_optionsv(mysql, MARIADB_OPT_USERDATA, (void *)\[dq]ssh_user\[dq], (void *)ssh_user); +\f[R] +.fi +.IP \[bu] 2 +\f[C]MARIADB_OPT_CONNECTION_READ_ONLY\f[R] +.PD 0 +.P +.PD +This option is used by connection handler plugins and indicates that the +current connection will be used for read operations only. +.IP \[bu] 2 +\f[C]MYSQL_OPT_CAN_HANDLE_EXPIRED_PASSWORDS\f[R] +.PD 0 +.P +.PD +If this option is set, the client indicates that it will be able to +handle expired passwords by setting the +\f[C]CLIENT_CAN_HANDLE_EXPIRED_PASSWORDS\f[R] capability flag. +If the password has expired and +\f[C]CLIENT_CAN_HANDLE_EXPIRED_PASSWORDS\f[R] is set, the server will +not return an error when connecting, but put the connection in sandbox +mode, where all commands will return error 1820 +(\f[C]ER_MUST_CHANGE_PASSWORD\f[R]) unless a new password was set. +This option was added in MariaDB Connector/C 3.0.4 +.SS TLS/SSL and Security options +.IP \[bu] 2 +\f[C]MYSQL_OPT_SSL_KEY\f[R] +.PD 0 +.P +.PD +Specify the name of a key for a secure connection. +If the key is protected with a passphrase, the passphrase needs to be +specified with \f[C]MARIADB_OPT_PASSPHRASE\f[R] option. +.IP \[bu] 2 +\f[C]MYSQL_OPT_SSL_CERT\f[R] +.PD 0 +.P +.PD +Specify the name of a certificate for a secure connection. +.IP \[bu] 2 +\f[C]MYSQL_OPT_SSL_CA\f[R] +.PD 0 +.P +.PD +Specify the name of a file which contains one or more trusted CAs. +.IP \[bu] 2 +\f[C]MYSQL_OPT_SSL_CAPATH\f[R] +.PD 0 +.P +.PD +Specify the path which contains trusted CAs. +.IP \[bu] 2 +\f[C]MYSQL_OPT_SSL_CIPHER\f[R] +.PD 0 +.P +.PD +Specify one or more (SSLv3, TLSv1.0 or TLSv1.2) cipher suites for TLS +encryption. +Even if Connector/C supports TLSv1.3 protocol, it is not possible yet to +specify TLSv1.3 cipher suites. +.IP \[bu] 2 +\f[C]MYSQL_OPT_SSL_CRL\f[R] +.PD 0 +.P +.PD +Specify a file with a certificate revocation list. +.IP \[bu] 2 +\f[C]MYSQL_OPT_SSL_CRLPATH\f[R] +.PD 0 +.P +.PD +Specify a directory with contains files with certificate revocation +lists. +.IP \[bu] 2 +\f[C]MARIADB_OPT_SSL_FP\f[R] +.PD 0 +.P +.PD +Specify the SHA1 fingerprint of a server certificate for validation +during the TLS handshake. +.IP \[bu] 2 +\f[C]MARIADB_OPT_SSL_FP\f[R] +.PD 0 +.P +.PD +Specify a file which contains one or more SHA1 fingerprints of server +certificates for validation during the TLS handshake. +.IP \[bu] 2 +\f[C]MARIADB_OPT_SSL_PASPHRASE\f[R] +.PD 0 +.P +.PD +Specify a passphrase for a passphrase protected client key. +.IP \[bu] 2 +\f[C]MYSQL_OPT_SSL_VERIFY_SERVER_CERT\f[R] +.PD 0 +.P +.PD +Enable (or disable) the verification of the hostname against common name +(CN) of the server\[cq]s host certificate. +.IP \[bu] 2 +\f[C]MYSQL_SERVER_PUBLIC_KEY\f[R] +.PD 0 +.P +.PD +Specifies the name of the file which contains the RSA public key of the +database server. +The format of this file must be in PEM format. +This option is used by the caching_sha2_password plugin and was added in +Connector/C 3.1.0 +.IP \[bu] 2 +\f[C]MARIADB_OPT_TLS_CIPHER_STRENGTH\f[R] +.PD 0 +.P +.PD +This option is not in use anymore. +.SS Connection Attributes +.PP +Connection attributes are stored in the \f[C]session_connect_attrs\f[R] +and \f[C]session_account_connect_attrs\f[R]Performance Schema tables. +By default, MariaDB Connector/C sends the following connection +attributes to the server: * \f[C]_client_name\f[R]: always +\[lq]libmariadb\[rq] * \f[C]_client_version\f[R]: version of MariaDB +Connector/C * \f[C]_os\f[R]: operation system * _pid: process id * +\f[C]_platform\f[R]: e.g.\ x86 or x64 * \f[C]_server_host\f[R]: the +hostname (as specified in mysql_real_connect). +This attribute was added in Connector/C 3.0.5 +.PP +\f[B]Note:\f[R] If the Performance Schema is disabled, connection +attributes will not be stored on server. +.IP \[bu] 2 +\f[C]MYSQL_OPT_CONNECT_ATTR_DELETE\f[R] +.PD 0 +.P +.PD +Deletes a connection attribute for the given key. +.IP \[bu] 2 +\f[C]MYSQL_OPT_CONNECT_ATTR_ADD\f[R] +.PD 0 +.P +.PD +Adds a key/value pair to connection attributes. +.IP \[bu] 2 +\f[C]MYSQL_OPT_CONNECT_ATTR_RESET\f[R] +.PD 0 +.P +.PD +Clears the current list of connection attributes. +.SS See Also +.PP +\f[I]\f[BI]mysql_init(3)\f[I] \f[R]\f[B]mysql_real_connect(3)\f[R] diff --git a/vendor/MDBC/man/mysql_ping.3 b/vendor/MDBC/man/mysql_ping.3 new file mode 100644 index 00000000..6dd05ad3 --- /dev/null +++ b/vendor/MDBC/man/mysql_ping.3 @@ -0,0 +1,44 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_ping" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_ping \- checks if the connection between client and server is +working +.SS Synopsis +.IP +.nf +\f[C] +#include + +int mysql_ping(MYSQL * mysql); +\f[R] +.fi +.SS Description +.PP +Checks whether the connection to the server is working. +If it has gone down, and global option reconnect is enabled an automatic +reconnection is attempted. +.PP +This function can be used by clients that remain idle for a long while, +to check whether the server has closed the connection and reconnect if +necessary. +.SS Parameters +.IP \[bu] 2 +\f[C]mysql\f[R] \- a mysql handle, which was previously allocated by +\f[B]mysql_init(3)\f[R] and connected by +\f[B]mysql_real_connect(3)\f[R]. +### Notes +.IP \[bu] 2 +If a reconnect occurred the thread_id will change. +Also resources bundled to the connection (prepared statements, locks, +temporary tables, \&...) will be released. +.SS Return value +.PP +Returns zero on success, nonzero if an error occured. +.SS See also +.IP \[bu] 2 +\f[B]mysql_optionsv(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_kill(3)\f[R] diff --git a/vendor/MDBC/man/mysql_query.3 b/vendor/MDBC/man/mysql_query.3 new file mode 100644 index 00000000..a31e73a7 --- /dev/null +++ b/vendor/MDBC/man/mysql_query.3 @@ -0,0 +1,56 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_query" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_query \- executes a null terminated statement string +.SS Synopsis +.IP +.nf +\f[C] +#include + +int mysql_query(MYSQL * mysql, + const char * query); +\f[R] +.fi +.SS Description +.PP +Performs a statement pointed to by the null terminate string query +against the database. +Contrary to \f[B]mysql_real_query(3)\f[R], mysql_query() is not binary +safe. +.SS Parameter +.IP \[bu] 2 +\f[C]mysql\f[R] \- a mysql handle, which was previously allocated by +\f[B]mysql_init(3)\f[R] and connected by +\f[B]mysql_real_connect(3)\f[R]. +.IP \[bu] 2 +\f[C]query\f[R] \-a null terminated string containing the statement to +be performed. +.SS Notes +.IP \[bu] 2 +For executing multi statements the statements within the null terminated +string statements must be separated by a semicolon. +.IP \[bu] 2 +If your statement contains binary data you should use +\f[B]mysql_real_query(3)\f[R] or escape your data with +\f[B]mysql_hex_string(3)\f[R]. +.IP \[bu] 2 +To determine if a statement returned a result set use the function +\f[B]mysql_field_count(3)\f[R]. +.SS Return value +.PP +Returns zero on success, non zero on failure. +.SS See also +.IP \[bu] 2 +\f[B]mysql_real_query(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_field_count(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_hex_string(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_use_result(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_store_result(3)\f[R] diff --git a/vendor/MDBC/man/mysql_read_query_result.3 b/vendor/MDBC/man/mysql_read_query_result.3 new file mode 100644 index 00000000..5660da1c --- /dev/null +++ b/vendor/MDBC/man/mysql_read_query_result.3 @@ -0,0 +1,39 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_read_query_result" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_read_query_result \- waits for a server result or response package +.SS Synopsis +.IP +.nf +\f[C] +#include + +my_bool mysql_read_query_result(MYSQL * mysql); +\f[R] +.fi +.SS Description +.PP +Waits for a server result set or response package from a previously +executed \f[B]mysql_send_query(3)\f[R]. +.SS Parameters +.IP \[bu] 2 +\f[C]mysql\f[R] \- a mysql handle, which was previously allocated by +\f[B]mysql_init(3)\f[R] and connected by +\f[B]mysql_real_connect(3)\f[R]. +.SS Return value +.PP +Zero on success, non zero on error. +.SS Example +.PP +For an example how to use \[cq]mysql_send_query()\[ga] in an event +driven model, please check Jan Kneschke\[cq]s Blog entry \[lq]Async +MySQL Queries with +C\-API\[rq] (https://jan.kneschke.de/projects/mysql/async-mysql-queries-with-c-api/). +.SS See also +.IP \[bu] 2 +\f[B]mysql_real_query(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_send_query(3)\f[R] diff --git a/vendor/MDBC/man/mysql_real_connect.3 b/vendor/MDBC/man/mysql_real_connect.3 new file mode 100644 index 00000000..5d7b57c4 --- /dev/null +++ b/vendor/MDBC/man/mysql_real_connect.3 @@ -0,0 +1,145 @@ +.\"t +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_real_connect" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_real_connect \- establishes a connection to a MariaDB database +server +.SS Synopsis +.IP +.nf +\f[C] +MYSQL * mysql_real_connect(MYSQL *mysql, + const char *host, + const char *user, + const char *passwd, + const char *db, + unsigned int port, + const char *unix_socket, + unsigned long flags); +\f[R] +.fi +.SS Description +.PP +Establishes a connection to a database server. +.SS Parameter +.IP \[bu] 2 +\f[C]mysql\f[R] \- a mysql handle, which was previously allocated by +\f[B]mysql_init(3)\f[R] +.IP \[bu] 2 +\f[C]host\f[R] \- can be either a host name or an IP address. +Passing the NULL value or the string \[lq]localhost\[rq] to this +parameter, the local host is assumed. +When possible, pipes will be used instead of the TCP/IP protocol. +.IP \[bu] 2 +\f[C]user\f[R] \- the user name. +.IP \[bu] 2 +\f[C]passwd\f[R] \- If provided or NULL, the server will attempt to +authenticate the user against those user records which have no password +only. +This allows one username to be used with different permissions +(depending on if a password as provided or not). +.IP \[bu] 2 +\f[C]db\f[R] \- if provided will specify the default database to be used +when performing queries. +.IP \[bu] 2 +\f[C]port\f[R] \- specifies the port number to attempt to connect to the +server. +.IP \[bu] 2 +\f[C]unix_socket\f[R] \- specifies the socket or named pipe that should +be used. +.IP \[bu] 2 +\f[C]flags\f[R] \- the flags allows various connection options to be set +.PD 0 +.P +.PD +.PP +.TS +tab(@); +lw(35.0n) lw(35.0n). +T{ +Flag +T}@T{ +Description +T} +_ +T{ +\f[C]CLIENT_FOUND_ROWS\f[R] +T}@T{ +Return the number of matched rows instead of number of changed rows. +T} +T{ +\f[C]CLIENT_NO_SCHEMA\f[R] +T}@T{ +Forbids the use of database.tablename.column syntax and forces the SQL +parser to generate an error. +T} +T{ +\f[C]CLIENT_COMPRESS\f[R] +T}@T{ +Use compression protocol +T} +T{ +\f[C]CLIENT_IGNORE_SPACE\f[R] +T}@T{ +Allows spaces after function names. +All function names will become reserved words. +T} +T{ +\f[C]CLIENT_LOCAL_FILES\f[R] +T}@T{ +Allows LOAD DATA LOCAL statements +T} +T{ +\f[C]CLIENT_MULTI_STATEMENTS\f[R] +T}@T{ +Allows the client to send multiple statements in one command. +Statements will be divided by a semicolon. +T} +T{ +\f[C]CLIENT_MULTI_RESULTS\f[R] +T}@T{ +Indicates that the client is able to handle multiple result sets from +stored procedures or multi statements. +This option will be automatically set if CLIENT_MULTI_STATEMENTS is set. +T} +T{ +\f[C]CLIENT_REMEMBER_OPTIONS\f[R] +T}@T{ +Rembers options passed to \f[B]mysql_optionsv(3)\f[R] if a connect +attempt failed. +If MYSQL_OPTIONS_RECONNECT option was set to true, options will be saved +and used for reconnection. +T} +.TE +.SS Return value +.PP +returns a connection handle (same as passed for 1st parameter) or NULL +on error. +On error, please check \f[B]mysql_errno(3)\f[R] and +\f[B]mysql_error(3)\f[R] functions for more information. +.SS Notes +.IP \[bu] 2 +The password doesn\[cq]t need to be encrypted before executing +mysql_real_connect(). +This will be handled in the client server protocol. +.IP \[bu] 2 +The connection handle can\[cq]t be reused for establishing a new +connection. +It must be closed and reinitialized before. +.IP \[bu] 2 +mysql_real_connect() must complete successfully before you can execute +any other API functions beside \f[B]mysql_optionsv(3)\f[R]. +.SS See also +.IP \[bu] 2 +\f[B]mysql_init(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_close(3)\f[R] +.IP \[bu] 2 +\f[B]mariadb_reconnect(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_error(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_errno(3)\f[R] diff --git a/vendor/MDBC/man/mysql_real_escape_string.3 b/vendor/MDBC/man/mysql_real_escape_string.3 new file mode 100644 index 00000000..f4ba4c54 --- /dev/null +++ b/vendor/MDBC/man/mysql_real_escape_string.3 @@ -0,0 +1,49 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_real_escape_string" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_real_escape_string \- escape string by taking into account +character set of connection +.SS Synopsis +.IP +.nf +\f[C] +#include + +unsigned long mysql_real_escape_string(MYSQL * mysql, + char * to, + const char * from, + unsigned long); +\f[R] +.fi +.SS Description +.PP +This function is used to create a legal SQL string that you can use in +an SQL statement. +The given string is encoded to an escaped SQL string, taking into +account the current character set of the connection. +.SS Parameter +.IP \[bu] 2 +\f[C]mysql\f[R] \- a mysql handle, which was previously allocated by +\f[B]mysql_init(3)\f[R] and connected by +\f[B]mysql_real_connect(3)\f[R]. +.IP \[bu] 2 +\f[C]to\f[R] \- buffer for the encoded string. +The size of this buffer must be length * 2 + 1 bytes: in worst case +every character of the from string needs to be escaped. +Additionally a trailing 0 character will be appended. +.IP \[bu] 2 +\f[C]from\f[R] \- a string which will be encoded by +mysql_real_escape_string(). +.IP \[bu] 2 +\f[C]long\f[R] \- the length of the \f[C]from\f[R] string. +.SS Return value +.PP +Returns the length of the encoded (to) string. +.SS See also +.IP \[bu] 2 +\f[B]mysql_escape_string(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_hex_string(3)\f[R] diff --git a/vendor/MDBC/man/mysql_real_query.3 b/vendor/MDBC/man/mysql_real_query.3 new file mode 100644 index 00000000..e92f89bc --- /dev/null +++ b/vendor/MDBC/man/mysql_real_query.3 @@ -0,0 +1,50 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_real_query" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_real_query \- execute a statement (binary safe) +.SS Synopsis +.IP +.nf +\f[C] +#include + +int mysql_real_query(MYSQL * mysql, + const char * query, + unsigned long length); +\f[R] +.fi +.SS Description +.PP +mysql_real_query() is the binary safe function for performing a +statement on the database server. +.SS Parameter +.IP \[bu] 2 +\f[C]mysql\f[R] \- a mysql handle, which was previously allocated by +\f[B]mysql_init(3)\f[R] and connected by +\f[B]mysql_real_connect(3)\f[R]. +.IP \[bu] 2 +\f[C]query\f[R] \- a string containing the statement to be performed. +.IP \[bu] 2 +\f[C]length\f[R] \- length of the string. +.SS Notes +.IP \[bu] 2 +Contrary to the \f[B]mysql_query(3)\f[R] function, mysql_real_query is +binary safe. +.IP \[bu] 2 +To determine if mysql_real_query returns a result set use the +\f[B]mysql_num_fields(3)\f[R] function. +.SS Return value +.PP +Returns zero on success, otherwise non zero. +.SS See also +.IP \[bu] 2 +\f[B]mysql_query(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_num_fields(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_use_result(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_store_result(3)\f[R] diff --git a/vendor/MDBC/man/mysql_refresh.3 b/vendor/MDBC/man/mysql_refresh.3 new file mode 100644 index 00000000..71a0035f --- /dev/null +++ b/vendor/MDBC/man/mysql_refresh.3 @@ -0,0 +1,92 @@ +.\"t +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_refresh" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_refresh \- flushes information on the server +.SS Synopsis +.IP +.nf +\f[C] +#include + +int mysql_refresh(MYSQL * mysql, unsigned int options); +\f[R] +.fi +.SS Description +.PP +Flushes different types of information stored on the server. +The bit\-masked parameter options specify which kind of information will +be flushed. +.SS Parameters +.IP \[bu] 2 +\f[C]mysql\f[R] \- a mysql handle, which was previously allocated by +\f[B]mysql_init(3)\f[R] and connected by +\f[B]mysql_real_connect(3)\f[R]. +.IP \[bu] 2 +\f[C]options\f[R] \- a bit masked composed integer. +See below. +.PP +\f[C]options\f[R] can be any combinationation of the following flags: +.PP +.TS +tab(@); +l l. +T{ +Option +T}@T{ +Description +T} +_ +T{ +\f[C]REFRESH_GRANT\f[R] +T}@T{ +Refresh grant tables. +T} +T{ +\f[C]REFRESH_LOG\f[R] +T}@T{ +Flush logs. +T} +T{ +\f[C]REFRESH_TABLES\f[R] +T}@T{ +Flush table cache. +T} +T{ +\f[C]REFRESH_HOSTS\f[R] +T}@T{ +Flush host cache. +T} +T{ +\f[C]REFRESH_STATUS\f[R] +T}@T{ +Reset status variables. +T} +T{ +\f[C]REFRESH_THREADS\f[R] +T}@T{ +Flush thread cache. +T} +T{ +\f[C]REFRESH_SLAVE\f[R] +T}@T{ +Reset master server information and restart slaves. +T} +T{ +\f[C]REFRESH_MASTER\f[R] +T}@T{ +Remove binary log files. +T} +.TE +.SS Notes +.IP \[bu] 2 +To combine different values in the options parameter use the OR operator +`|'. +.IP \[bu] 2 +\f[C]mysql_reload()\f[R] is an alias for mysql_refresh(). +.SS Return value +.PP +Returns zero on success, otherwise non zero. diff --git a/vendor/MDBC/man/mysql_reset_connection.3 b/vendor/MDBC/man/mysql_reset_connection.3 new file mode 100644 index 00000000..9ffae0a2 --- /dev/null +++ b/vendor/MDBC/man/mysql_reset_connection.3 @@ -0,0 +1,48 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_reset_connection" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_reset_connection \- Resets connection and clears session state +.SS Synopsis +.IP +.nf +\f[C] +#include + +int mysql_reset_connection(MYSQL * mysql); +\f[R] +.fi +.SS Description +.PP +Resets the current connection and clears session state. +Similar to \f[B]mysql_change_user(3)\f[R] or +\f[B]mariadb_reconnect(3)\f[R], mysql_reset_connection() resets session +status, but without disconnecting, opening, or reauthenticating. +.PP +On client side mysql_reset_connection() * clears pending or unprocessed +result sets * clears status like affected_rows, info or last_insert_id * +invalidates active prepared statements +.PP +On server side mysql_reset_connection() * drops temporary table(s) * +rollbacks active transaction * resets autocommit mode * releases table +locks * initializes session variables (and sets them to the value of +corresponding global variables) * closes active prepared statements * +clears user variables +.SS Parameter +.IP \[bu] 2 +\f[C]mysql\f[R] \- a mysql handle, which was previously allocated by +\f[B]mysql_init(3)\f[R] and connected by +\f[B]mysql_real_connect(3)\f[R]. +.SS Return value +.PP +Returns zero on success, non zero if an error occurred. +.SS History +.PP +This function was added in MariaDB Connector/C 3.0.0. +.SS See also +.IP \[bu] 2 +\f[B]mariadb_cancel(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_kill(3)\f[R] diff --git a/vendor/MDBC/man/mysql_rollback.3 b/vendor/MDBC/man/mysql_rollback.3 new file mode 100644 index 00000000..e827b8f9 --- /dev/null +++ b/vendor/MDBC/man/mysql_rollback.3 @@ -0,0 +1,34 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_rollback" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_rollback \- Rolls back the current transaction +.SS Synopsis +.IP +.nf +\f[C] +#include + +my_bool mysql_rollback(MYSQL * mysql); +\f[R] +.fi +.SS Description +.PP +Rolls back the current transaction for the database. +Returns zero on success, nonzero if an error occurred. +.SS Parameter +.IP \[bu] 2 +\f[C]mysql\f[R] \- a mysql handle, which was previously allocated by +\f[B]mysql_init(3)\f[R] and connected by +\f[B]mysql_real_connect(3)\f[R]. +.SS Notes +.IP \[bu] 2 +mysql_rollback() will not work as expected if autocommit mode was set or +the storage engine does not support transactions. +.SS See also +.IP \[bu] 2 +\f[B]mysql_commit(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_autocommit(3)\f[R] diff --git a/vendor/MDBC/man/mysql_row_seek.3 b/vendor/MDBC/man/mysql_row_seek.3 new file mode 100644 index 00000000..e88f11ec --- /dev/null +++ b/vendor/MDBC/man/mysql_row_seek.3 @@ -0,0 +1,41 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_row_seek" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_row_seek \- Positions the row cursor to an arbitrary row +.SS Synopsis +.IP +.nf +\f[C] +#include + +MYSQL_ROW_OFFSET mysql_row_seek(MYSQL_RES * result, + MYSQL_ROW_OFFSET offset); +\f[R] +.fi +.SS Description +.PP +Positions the row cursor to an arbitrary row in a result set which was +obtained by \f[B]mysql_store_result(3)\f[R]. +.SS Parameter +.IP \[bu] 2 +\f[C]result\f[R] \- a result set identifier returned by +\f[B]mysql_store_result(3)\f[R]. +.IP \[bu] 2 +\f[C]offset\f[R] \- row offset. +This value can be obtained either by mysql_row_seek() or +\f[B]mysql_row_tell(3)\f[R] +.SS Notes +.IP \[bu] 2 +This function will not work if the result set was obtained by +\f[B]mysql_use_result(3)\f[R]. +.SS Return value +.PP +Returns the previous row offset. +.SS See also +.IP \[bu] 2 +\f[B]mysql_store_result(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_row_tell(3)\f[R] diff --git a/vendor/MDBC/man/mysql_row_tell.3 b/vendor/MDBC/man/mysql_row_tell.3 new file mode 100644 index 00000000..fd09ae45 --- /dev/null +++ b/vendor/MDBC/man/mysql_row_tell.3 @@ -0,0 +1,34 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_row_tell" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_row_tell \- Returns row offset of a result cursor +.SS Synopsis +.IP +.nf +\f[C] +#include + +MYSQL_ROW_OFFSET mysql_row_tell(MYSQL_RES * res); +\f[R] +.fi +.SS Description +.PP +Returns the row offset of a result cursor. +The returned offset value can be used to reposition the result cursor by +calling \f[B]mysql_row_seek(3)\f[R]. +.SS Parameter +.IP \[bu] 2 +\f[C]res\f[R] \- a result set identifier returned by +\f[B]mysql_store_result(3)\f[R]. +.SS Notes +.IP \[bu] 2 +This function will not work if the result set was obtained by +\f[B]mysql_use_result(3)\f[R]. +.SS See also +.IP \[bu] 2 +\f[B]mysql_store_result(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_row_seek(3)\f[R] diff --git a/vendor/MDBC/man/mysql_select_db.3 b/vendor/MDBC/man/mysql_select_db.3 new file mode 100644 index 00000000..b165dd2f --- /dev/null +++ b/vendor/MDBC/man/mysql_select_db.3 @@ -0,0 +1,84 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_select_db" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_select_db \- selects a database as default +.SS Synopsis +.IP +.nf +\f[C] +#include + +int mysql_select_db(MYSQL * mysql, + const char * db); +\f[R] +.fi +.SS Description +.PP +Selects a database as default. +Returns zero on success, non\-zero on failure +.SS Parameters +.IP \[bu] 2 +\f[C]mysql\f[R] is a connection identifier, which was previously +allocated by \f[B]mysql_init(3)\f[R] and connected by +\f[B]mysql_real_connect(3)\f[R]. +.IP \[bu] 2 +\f[C]db\f[R] \- the default database name +.SS Notes +.IP \[bu] 2 +To retrieve the name of the default database either execute the SQL +command \f[C]SELECT DATABASE()\f[R] or retrieve the value via +\f[B]mariadb_get_infov(3)\f[R] API function. +.IP \[bu] 2 +The default database can also be set by the db parameter in +\f[B]mysql_real_connect(3)\f[R]. +.SS Examples +.SS SQL +.IP +.nf +\f[C] +# switch to default database test +USE test; +# check default database +SELECT DATABASE(); ++\-\-\-\-\-\-\-\-\-\-\-\-+ +| database() | ++\-\-\-\-\-\-\-\-\-\-\-\-+ +| test | ++\-\-\-\-\-\-\-\-\-\-\-\-+ +\f[R] +.fi +.SS MariadDB Connector/C +.IP +.nf +\f[C] +static int set_default_db(MYSQL *mysql) +{ + int rc; + char *default_db; + + /* change default database to test */ + rc= mysql_select_db(mysql, \[dq]test\[dq]); + if (rc) + return rc; /* Error */ + + /* get the default database */ + rc= mariadb_get_infov(mysql, MARIADB_CONNECTION_SCHEMA, &default_db); + if (rc) + return rc; /* Error */ + + if (strcmp(\[dq]test\[dq], default_db) != NULL) + { + printf(\[dq]Wrong default database\[rs]n\[dq]); + return 1; + } + printf(\[dq]Default database: %s\[dq], default_db); + return 0; +} +\f[R] +.fi +.SS See also +.PP +\f[B]mysql_real_connect(3)\f[R] diff --git a/vendor/MDBC/man/mysql_send_query.3 b/vendor/MDBC/man/mysql_send_query.3 new file mode 100644 index 00000000..a31d3629 --- /dev/null +++ b/vendor/MDBC/man/mysql_send_query.3 @@ -0,0 +1,52 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_send_query" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_send_query \- sends a SQL statement without waiting for server +reponse +.SS Synopsis +.IP +.nf +\f[C] +#include + +int mysql_send_query(MYSQL * mysql, + const char *query, + unsigned long length); +\f[R] +.fi +.SS Description +.PP +Sends a statement to the server, without waiting for the Server OK +packet and/or resultset. +.SS Parameters +.IP \[bu] 2 +\f[C]mysql\f[R] \- a mysql handle, which was previously allocated by +\f[B]mysql_init(3)\f[R] and connected by +\f[B]mysql_real_connect(3)\f[R]. +.IP \[bu] 2 +\f[C]query\f[R] \- SQL statement +.IP \[bu] 2 +\f[C]length\f[R] \- length of the SQL statement +.SS Notes +.IP \[bu] 2 +The OK and result set package need to be retrieved by +\f[B]mysql_read_query_result(3)\f[R] function +.IP \[bu] 2 +\f[C]mysql_send_query()\f[R] can be used for semi asynchronous +operation. +While the function itself is blocking, an event driven application can +do other tasks until result set is available. +.SS Example +.PP +For an example how to use \[cq]mysql_send_query()\[ga] in an event +driven model, please check Jan Kneschke\[cq]s article \[lq]Async MySQL +Queries with +C\-API\[rq] (https://jan.kneschke.de/projects/mysql/async-mysql-queries-with-c-api/). +.SS See also +.IP \[bu] 2 + +.IP \[bu] 2 + diff --git a/vendor/MDBC/man/mysql_server_end.3 b/vendor/MDBC/man/mysql_server_end.3 new file mode 100644 index 00000000..f8a0bead --- /dev/null +++ b/vendor/MDBC/man/mysql_server_end.3 @@ -0,0 +1,33 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_server_end" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_server_end \- Called when finished using MariaDB Connector/C +.SS Synopsis +.IP +.nf +\f[C] +#include + +void mysql_server_end(void) +\f[R] +.fi +.SS Description +.PP +Call when finished using the library, such as after disconnecting from +the server. +For a client program, only cleans up by performing memory management +tasks. +.SS Notes +.IP \[bu] 2 +\f[C]mysql_library_end()\f[R] is an alias for +\f[C]mysql_server_end()\f[R]. +.IP \[bu] 2 +In MySQL Connector/C versions 3.0.1 to 3.0.4 it was not possible to call +multiple times \f[B]mysql_server_init(3)\f[R] and +\f[C]mysql_server_end()\f[R]. +.SS See also +.IP \[bu] 2 +\f[B]mysql_server_init(3)\f[R] diff --git a/vendor/MDBC/man/mysql_server_init.3 b/vendor/MDBC/man/mysql_server_init.3 new file mode 100644 index 00000000..e01edc5f --- /dev/null +++ b/vendor/MDBC/man/mysql_server_init.3 @@ -0,0 +1,38 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_server_init" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_server_init \- Initializes library +.SS Synopsis +.IP +.nf +\f[C] +#include + +int mysql_library_init(int argc __attribute__((unused)), + char **argv __attribute__((unused)), + char **groups __attribute__((unused))) +\f[R] +.fi +.SS Description +.PP +Call to initialize the library before calling other functions. +.SS Parameters +.PP +All parameters are unused, they only exist for compatibility reasons. +.SS Notes +.IP \[bu] 2 +Call \f[B]mysql_server_end(3)\f[R] to clean up after completion. +.IP \[bu] 2 +If the library was not explicetly initialized by +\f[C]mysql_server_init()\f[R] any call to \f[B]mysql_init(3)\f[R] will +automatically initialize the library. +.IP \[bu] 2 +\f[C]mysql_library_init()\f[R] is an alias for +\f[C]mysql_server_init()\f[R] +.SS Return value +.PP +Returns zero for success, or nonzero if an error occurred. +## See also * \f[B]mysql_server_end(3)\f[R] diff --git a/vendor/MDBC/man/mysql_session_track_get_first.3 b/vendor/MDBC/man/mysql_session_track_get_first.3 new file mode 100644 index 00000000..9f7265f8 --- /dev/null +++ b/vendor/MDBC/man/mysql_session_track_get_first.3 @@ -0,0 +1,74 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_session_track_get_first" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_session_track_get_first \- retrieves first session status change +information +.SS Synopsis +.IP +.nf +\f[C] +#include + +int mysql_session_track_get_first(MYSQL * mysql, + enum enum_session_state_type type, + const char **data, + size_t *length ); +\f[R] +.fi +.SS Description +.PP +\f[C]mysql_session_track_get_first()\f[R] retrieves the first session +status change information received from the server. +.PP +Depending on the specified type the read only data pointer will contain +the following information: * \f[C]SESSION_TRACK_SCHEMA\f[R]: The name of +the default schema (database) * +\f[C]SESSION_TRACK_SYSTEM_VARIABLES\f[R]: If a session system variable +is changed, the first call contains the name of the changed system +variable, the second call contains the new value. +Both name and value are represented as strings. +* \f[C]SESSION_TRACK_STATE_CHANGE\f[R]: shows whether the session status +has changed. +The value is changed as string \[lq]1\[rq] (changed) or \[lq]0\[rq] +(unchanged). +.PP +Further data needs to be obtained by calling +\f[B]mysql_session_track_get_next(3)\f[R]. +.SS Parameter +.IP \[bu] 2 +\f[C]mysql\f[R] \- mysql handle, which was previously allocated by +\f[B]mysql_init(3)\f[R] and connected by +\f[B]mysql_real_connect(3)\f[R]. +.IP \[bu] 2 +\f[C]type\f[R] \- type of information. +Valid values are +.RS 2 +.IP \[bu] 2 +\f[C]SESSION_TRACK_SYSTEM_VARIABLES\f[R] +.IP \[bu] 2 +\f[C]SESSION_TRACK_SCHEMA\f[R] +.IP \[bu] 2 +\f[C]SESSION_TRACK_STATE_CHANGE\f[R] +.IP \[bu] 2 +\f[C]SESSION_TRACK_GTIDS\f[R] (unsupported) +.RE +.IP \[bu] 2 +\f[C]data\f[R] \- pointer to data, which must be declared as +\f[C]const char *\f[R] +.IP \[bu] 2 +\f[C]length\f[R] \- pointer to a \f[C]size_t\f[R] variable, which will +contain the length of data +.SS Returns +.PP +Zero for success, nonzero if no session tracking information is +available. +.SS History +.PP +\f[C]mysql_session_track_get_first()\f[R] was added in Connector/C 3.0 +and MariaDB Server 10.2. +.SS See also +.IP \[bu] 2 +\f[B]mysql_session_track_get_next(3)\f[R] diff --git a/vendor/MDBC/man/mysql_session_track_get_next.3 b/vendor/MDBC/man/mysql_session_track_get_next.3 new file mode 100644 index 00000000..420ee607 --- /dev/null +++ b/vendor/MDBC/man/mysql_session_track_get_next.3 @@ -0,0 +1,62 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_session_track_get_next" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_session_track_get_next \- Retrieves the next session status change +information +.SS Synopsis +.IP +.nf +\f[C] +#include + +int mysql_session_track_get_next(MYSQL * mysql, + enum enum_session_state_type type, + const char **data, + size_t *length ); +\f[R] +.fi +.SS Description +.PP +\f[C]mysql_session_track_get_next()\f[R] retrieves the session status +change information received from the server after a successful call to +\f[B]mysql_session_track_get_first(3)\f[R]. +.PP +\f[C]mysql_session_track_get_next()\f[R] needs to be called repeatedly +until a non zero return value indicates end of data. +.SS Parameters +.IP \[bu] 2 +\f[C]mysql\f[R] \- mysql handle, which was previously allocated by +\f[B]mysql_init(3)\f[R] and connected bys +\f[B]mysql_real_connect(3)\f[R]. +.IP \[bu] 2 +\f[C]type\f[R] \- type of information. +Valid values are +.RS 2 +.IP \[bu] 2 +\f[C]SESSION_TRACK_SYSTEM_VARIABLES\f[R] +.IP \[bu] 2 +\f[C]SESSION_TRACK_SCHEMA\f[R] +.IP \[bu] 2 +\f[C]SESSION_TRACK_STATE_CHANGE\f[R] +.IP \[bu] 2 +\f[C]SESSION_TRACK_GTIDS\f[R] (unsupported) +.RE +.IP \[bu] 2 +\f[C]data\f[R] \- pointer to data, which must be declared as +\f[C]const char *\f[R] +.IP \[bu] 2 +\f[C]length\f[R] \- pointer to a \f[C]size_t\f[R] variable, which will +contain the length of data +.SS Return value +.PP +Zero for success, nonzero if an error occurred. +.SS History +.PP +\f[C]mysql_session_track_get_next()\f[R] was added in Connector/C 3.0 +and MariaDB Server 10.2. +.SS See also +.PP +\f[B]mysql_session_track_get_first(3)\f[R] diff --git a/vendor/MDBC/man/mysql_set_character_set.3 b/vendor/MDBC/man/mysql_set_character_set.3 new file mode 100644 index 00000000..a2907590 --- /dev/null +++ b/vendor/MDBC/man/mysql_set_character_set.3 @@ -0,0 +1,251 @@ +.\"t +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_set_character_set" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_set_character_set \- Sets the default character set for connection +.SS Synopsis +.IP +.nf +\f[C] +#include + +int mysql_set_character_set(MYSQL * mysql, + const char * csname); +\f[R] +.fi +.SS Description +.PP +Sets the default +[data\-types\-character\-sets\-and\-collations()](character set]] for +the current connection. +Returns zero on success, non\-zero on failure. +.SS Parameters +.IP \[bu] 2 +\f[C]mysql\f[R] \- a mysql handle, which was previously allocated by +mysql_init() (mysql_init) or \f[B]mysql_real_connect(3)\f[R]. +.IP \[bu] 2 +\f[C]csname\f[R] \- character set name ### Notes +.IP \[bu] 2 +It\[cq]s strongly recommended to use mysql_set_character_set() instead +of \f[C]SET NAMES ...\f[R] since \f[B]mysql_real_escape_string(3)\f[R] +might fail or deliver unexpected results. +.SS Return value +.PP +Zero on success, non zero if an error occured +.SS Supported character sets +.PP +The client library supports the following character sets: +.PP +.TS +tab(@); +lw(35.0n) lw(35.0n). +T{ +Character set +T}@T{ +Description +T} +_ +T{ +armscii8 +T}@T{ +8 bit character set for Armenian +T} +T{ +ascii +T}@T{ +US ASCII character set +T} +T{ +big5 +T}@T{ +2 byte character set for traditional Chinese, Hongkong, Macau and Taiwan +T} +T{ +binary +T}@T{ +8 bit binary character set +T} +T{ +cp1250 +T}@T{ +Windows code page 1250 character set +T} +T{ +cp1251 +T}@T{ +Windows code page 1251 character set +T} +T{ +cp1256 +T}@T{ +Windows code page 1256 character set +T} +T{ +cp1257 +T}@T{ +Windows code page 1257 character set +T} +T{ +cp850 +T}@T{ +MS\-DOS Codepage 850 (Western Europe) +T} +T{ +cp852 +T}@T{ +MS\-DOS Codepage 852 (Middle Europe) +T} +T{ +cp866 +T}@T{ +MS\-DOS Codepage 866 (Russian) +T} +T{ +cp932 +T}@T{ +Microsoft Codepage 932 (Extension to sjis) +T} +T{ +dec8 +T}@T{ +DEC West European +T} +T{ +eucjpms +T}@T{ +UJIS for Windows Japanese +T} +T{ +euckr +T}@T{ +EUC KR\-Korean +T} +T{ +gb2312 +T}@T{ +GB\-2312 simplified Chinese +T} +T{ +gbk +T}@T{ +GBK simplified Chinese +T} +T{ +geostd8 +T}@T{ +GEOSTD8 Georgian +T} +T{ +greek +T}@T{ +ISO 8859\-7 Greek +T} +T{ +hebrew +T}@T{ +ISO 8859\-8 Hebrew +T} +T{ +hp8 +T}@T{ +HP West European +T} +T{ +keybcs2 +T}@T{ +DOS Kamenicky Czech\-Slovak +T} +T{ +koi8r +T}@T{ +KOI8\-R Relcom Russian +T} +T{ +koi8u +T}@T{ +KOI8\-U Ukrainian +T} +T{ +latin1 +T}@T{ +CP1252 Western European +T} +T{ +latin2 +T}@T{ +ISO 8859\-2 Central Europe +T} +T{ +latin5 +T}@T{ +ISO 8859\-9 Turkish +T} +T{ +latin7 +T}@T{ +ISO 8859\-13 Baltic +T} +T{ +macce +T}@T{ +MAC Central European +T} +T{ +macroman +T}@T{ +MAC Western European +T} +T{ +sjis +T}@T{ +SJIS for Windows Japanese +T} +T{ +swe7 +T}@T{ +7\-bit Swedish +T} +T{ +tis620 +T}@T{ +TIS620 Thai +T} +T{ +ucs2 +T}@T{ +UCS\-2 Unicode +T} +T{ +ujis +T}@T{ +EUC\-JP Japanese +T} +T{ +utf8 +T}@T{ +UTF\-8 Unicode +T} +T{ +utf16 +T}@T{ +UTF\-16 Unicode +T} +T{ +utf32 +T}@T{ +UTF\-32 Unicode +T} +T{ +utf8mb4 +T}@T{ +UTF 4\-byte Unicode +T} +.TE +.SS See also +.IP \[bu] 2 +\f[B]mysql_get_character_set_info(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_real_escape_string(3)\f[R] diff --git a/vendor/MDBC/man/mysql_set_server_option.3 b/vendor/MDBC/man/mysql_set_server_option.3 new file mode 100644 index 00000000..1b02cd77 --- /dev/null +++ b/vendor/MDBC/man/mysql_set_server_option.3 @@ -0,0 +1,56 @@ +.\"t +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_set_server_option" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_set_server_option \- Sets server option +.SS Synopsis +.IP +.nf +\f[C] +#include + +int mysql_set_server_option(MYSQL * mysql, + enum enum_mysql_set_option); +\f[R] +.fi +.SS Description +.PP +Sets server option. +.SS Parameters +.IP \[bu] 2 +\f[C]mysql\f[R] \- a mysql handle, which was previously allocated by +\f[B]mysql_init(3)\f[R] and connected by +\f[B]mysql_real_connect(3)\f[R]. +.IP \[bu] 2 +\f[C]enum_mysql_set_option\f[R] \- server option (see below) Server +option, which can be one of the following values: +.PP +.TS +tab(@); +l l. +T{ +Option +T}@T{ +Description +T} +_ +T{ +MYSQL_OPTION_MULTI_STATEMENTS_OFF +T}@T{ +Disables multi statement support +T} +T{ +MYSQL_OPTION_MULTI_STATEMENTS_ON +T}@T{ +Enable multi statement support +T} +.TE +.SS Return value +.PP +Returns zero on success, non\-zero on failure. +.SS See also +.IP \[bu] 2 +\f[B]mysql_real_connect(3)\f[R] diff --git a/vendor/MDBC/man/mysql_shutdown.3 b/vendor/MDBC/man/mysql_shutdown.3 new file mode 100644 index 00000000..1dac9e2b --- /dev/null +++ b/vendor/MDBC/man/mysql_shutdown.3 @@ -0,0 +1,38 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_shutdown" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_shutdown \- Sends shutdown message to server +.SS Synopsis +.IP +.nf +\f[C] +#include + +int mysql_shutdown(MYSQL * mysql, + enum mysql_enum_shutdown_level); +\f[R] +.fi +.SS Description +.PP +Sends a shutdown message to the server. +.SS Parameter +.IP \[bu] 2 +\f[C]mysql\f[R] \- a mysql handle, which was previously allocated by +\f[B]mysql_init(3)\f[R] and connected by +\f[B]mysql_real_connect(3)\f[R]. +.IP \[bu] 2 +\f[C]mysql_enum_shutdown_level\f[R] \- currently only one shutdown +level, \f[C]SHUTDOWN_DEFAULT\f[R] is supported. +.SS Notes +.IP \[bu] 2 +To shutdown the database server, the user for the current connection +must have SHUTDOWN privileges. +.SS Return value +.PP +Returns zero on success, non\-zero on failure. +.SS See also +.IP \[bu] 2 +\f[B]mysql_kill(3)\f[R] diff --git a/vendor/MDBC/man/mysql_sqlstate.3 b/vendor/MDBC/man/mysql_sqlstate.3 new file mode 100644 index 00000000..56031846 --- /dev/null +++ b/vendor/MDBC/man/mysql_sqlstate.3 @@ -0,0 +1,37 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_sqlstate" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_sqlstate \- returns SQLSTATE error code +.SS Synopsis +.IP +.nf +\f[C] +#include + +const char * mysql_sqlstate(MYSQL * mysql); +\f[R] +.fi +.SS Description +.PP +Returns a string containing the SQLSTATE error code for the most +recently invoked function that can succeed or fail. +The error code consists of five characters. +`00000' means no error. +The values are specified by ANSI SQL and ODBC +.SS Parameter +.SS Notes +.PP +Please note that not all client library error codes are mapped to +SQLSTATE errors. +Errors which can\[cq]t be mapped will returned as value HY000. +.SS Return value +.PP +A string containing SQLSTATE error code. +.SS See also +.IP \[bu] 2 +\f[B]mysql_error(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_errno(3)\f[R] diff --git a/vendor/MDBC/man/mysql_ssl_set.3 b/vendor/MDBC/man/mysql_ssl_set.3 new file mode 100644 index 00000000..761b9703 --- /dev/null +++ b/vendor/MDBC/man/mysql_ssl_set.3 @@ -0,0 +1,57 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_ssl_set" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_ssl_set \- Sets TLS/SSL options +.SS Synopsis +.IP +.nf +\f[C] +#include + +my_bool mysql_ssl_set(MYSQL *mysql, + const char *key, + const char *cert, + const char *ca, + const char *capath, + const char *cipher) +\f[R] +.fi +.SS Description +.PP +Used for establishing a secure TLS connection. +It must be called before attempting to use +\f[B]mysql_real_connect(3)\f[R]. +TLS support must be enabled in the client library in order for the +function to have any effect. +.PP +NULL can be used for an unused parameter. +Always returns zero. +.SS Parameter +.IP \[bu] 2 +\f[C]mysql\f[R] \- a mysql handle, which was previously allocated by +\f[B]mysql_init(3)\f[R]. +.IP \[bu] 2 +\f[C]key\f[R] \- path to the key file. +.IP \[bu] 2 +\f[C]cert\f[R] \- path to the certificate file. +.IP \[bu] 2 +\f[C]ca\f[R] \- path to the certificate authority file. +.IP \[bu] 2 +\f[C]capath\f[R] \- path to the directory containing the trusted TLS CA +certificates in PEM format. +.IP \[bu] 2 +\f[C]cipher\f[R] list of permitted (SSLv3, TLSv1.0 or TLSv1.2) cipher +suites to use for TLS encryption. +.SS Notes +.IP \[bu] 2 +\f[B]mysql_real_connect(3)\f[R] will return an error if attempting to +connect and TLS is incorrectly set up. +.IP \[bu] 2 +Even if Connector/C supports TLSv1.3 protocol, it is not possible yet to +specify TLSv1.3 cipher suites via \f[C]cipher\f[R] parameter. +.SS See also +.IP \[bu] 2 +\f[B]mysql_get_ssl_cipher(3)\f[R] diff --git a/vendor/MDBC/man/mysql_stat.3 b/vendor/MDBC/man/mysql_stat.3 new file mode 100644 index 00000000..8ae47956 --- /dev/null +++ b/vendor/MDBC/man/mysql_stat.3 @@ -0,0 +1,35 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_stat" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_stat \- Returns current server status +.SS Synopsis +.IP +.nf +\f[C] +#include + +const char * mysql_stat(MYSQL * mysql); +\f[R] +.fi +.SS Description +.PP +mysql_stat() returns a string with the current server status for uptime, +threads, queries, open tables, flush tables and queries per second. +.SS Parameter +.IP \[bu] 2 +\f[C]mysql\f[R] \- a mysql handle, which was previously allocated by +\f[B]mysql_init(3)\f[R] and connected byy +\f[B]mysql_real_connect(3)\f[R]. +.SS Notes +.PP +For a complete list of other status variables, you have to use the +[show\-status()](SHOW STATUS]] SQL command. +.SS Return value +.PP +Returns a string representing current server status. +.SS See also +.IP \[bu] 2 +mysql_get_server_info() (mysql_get_server_info) diff --git a/vendor/MDBC/man/mysql_stmt_affected_rows.3 b/vendor/MDBC/man/mysql_stmt_affected_rows.3 new file mode 100644 index 00000000..3684b8f6 --- /dev/null +++ b/vendor/MDBC/man/mysql_stmt_affected_rows.3 @@ -0,0 +1,42 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_stmt_affected_rows" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_stmt_affected_rows \- Returns the number of affected rows from +previous executed prepared statement +.SS Synopsis +.IP +.nf +\f[C] +#include + +my_ulonglong mysql_stmt_affected_rows(MYSQL_STMT * stmt); +\f[R] +.fi +.SS Description +.PP +Returns the number of affected rows by the last prepared statement +associated with mysql, if the operation was an \[lq]upsert\[rq] (INSERT, +UPDATE, DELETE or REPLACE) statement, or \-1 if the last prepared +statement failed. +.SS Parameter +.IP \[bu] 2 +\f[C]stmt\f[R] \- a statement handle, which was previously allocated by +[mysql_stmt_init()](mysql_stmt_init().]] +.SS Notes +.IP \[bu] 2 +When using \f[C]UPDATE\f[R], MariaDB will not update columns where the +new value is the same as the old value. +This creates the possibility that \f[C]mysql_stmt_affected_rows()\f[R] +may not actually equal the number of rows matched, only the number of +rows that were literally affected by the query. +.IP \[bu] 2 +The \f[C]REPLACE\f[R] statement first deletes the record with the same +primary key and then inserts the new record. +This function returns the number of deleted records in addition to the +number of inserted records. +.SS See Also +.IP \[bu] 2 +\f[B]mysql_stmt_insert_id(3)\f[R] diff --git a/vendor/MDBC/man/mysql_stmt_attr_get.3 b/vendor/MDBC/man/mysql_stmt_attr_get.3 new file mode 100644 index 00000000..37681560 --- /dev/null +++ b/vendor/MDBC/man/mysql_stmt_attr_get.3 @@ -0,0 +1,97 @@ +.\"t +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_stmt_attr_get" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_stmt_attr_get \- Gets the current value of a statement attribute +.SS Synopsis +.IP +.nf +\f[C] +#include + +my_bool mysql_stmt_attr_get(MYSQL_STMT * stmt, + enum enum_stmt_attr_type, + void * attr); +\f[R] +.fi +.SS Description +.PP +Gets the current value of a statement attribute. +Returns zero on success, non zero on failure. +.SS Parameter +.IP \[bu] 2 +\f[C]stmt\f[R] \- a statement handle, which was previously allocated by +\f[B]mysql_stmt_init(3)\f[R]. +.IP \[bu] 2 +\f[C]enum_stmt_attr_type\f[R] \- attribute. +See below. +.IP \[bu] 2 +\f[C]attr\f[R] \- pointer to a variable, which will contain the +attribute value. +.SS Attribute types +.PP +The \f[C]enum_stmt_attr_type\f[R] parameter has the following possible +values: +.PP +.TS +tab(@); +lw(23.3n) lw(23.3n) lw(23.3n). +T{ +Value +T}@T{ +Type +T}@T{ +Description +T} +_ +T{ +\f[C]STMT_ATTR_UPDATE_MAX_LENGTH\f[R] +T}@T{ +\f[C]my_bool *\f[R] +T}@T{ +Indicates if \f[B]mysql_stmt_store_result(3)\f[R] will update the +max_length value of \f[C]MYSQL_FIELD\f[R] structures. +T} +T{ +\f[C]STMT_ATTR_CURSOR_TYPE\f[R] +T}@T{ +\f[C]unsigned long *\f[R] +T}@T{ +Possible values are \f[C]CURSOR_TYPE_READ_ONLY\f[R] or default value +\f[C]CURSOR_TYPE_NO_CURSOR\f[R]. +T} +T{ +\f[C]STMT_ATTR_PREFETCH_ROWS\f[R] +T}@T{ +\f[C]unsigned long *\f[R] +T}@T{ +Number of rows which will be prefetched. +The default value is 1. +T} +T{ +\f[C]STMT_ATTR_PREBIND_PARAMS\f[R] +T}@T{ +\f[C]unsigned int *\f[R] +T}@T{ +Number of parameters used for \f[B]mariadb_stmt_execute_direct(3)\f[R] +T} +T{ +\f[C]STMT_ATTR_STATE\f[R] +T}@T{ +\f[C]enum mysql_stmt_state *\f[R] +T}@T{ +Status of prepared statement. +Possible values are defined in \f[C]enum mysql_stmt_state\f[R]. +This option was added in MariaDB Connector/C 3.1.0 +T} +.TE +.SS Notes +.IP \[bu] 2 +Setting the number of prefetched rows will work only for read only +cursors. +.SS See Also +.IP \[bu] 2 +\f[B]mysql_stmt_attr_set(3)\f[R] diff --git a/vendor/MDBC/man/mysql_stmt_attr_set.3 b/vendor/MDBC/man/mysql_stmt_attr_set.3 new file mode 100644 index 00000000..3d4d15b7 --- /dev/null +++ b/vendor/MDBC/man/mysql_stmt_attr_set.3 @@ -0,0 +1,131 @@ +.\"t +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_stmt_attr_set" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_stmt_attr_set \- Sets attribute of a statement +.SS Synopsis +.IP +.nf +\f[C] +#include + +my_bool mysql_stmt_attr_set(MYSQL_STMT * stmt, + enum enum_stmt_attr_type, + const void * attr); +\f[R] +.fi +.SS Description +.PP +Used to modify the behavior of a prepared statement. +This function may be called multiple times to set several attributes. +Returns zero on success, non\-zero on failure. +.SS Parameters +.IP \[bu] 2 +\f[C]stmt\f[R] \- a statement handle, which was previously allocated by +\f[B]mysql_stmt_init(3)\f[R]. +.IP \[bu] 2 +\f[C]enum_stmt_attr_type\f[R] \- the attribute that you want to set. +See below. +.IP \[bu] 2 +\f[C]attr\f[R] \- the value to assign to the attribute +.SS Attribute types +.PP +The \f[C]enum_stmt_attr_type\f[R] attribute can have one of the +following values: +.PP +.TS +tab(@); +lw(23.3n) lw(23.3n) lw(23.3n). +T{ +Value +T}@T{ +Type +T}@T{ +Description +T} +_ +T{ +\f[C]STMT_ATTR_UPDATE_MAX_LENGTH\f[R] +T}@T{ +\f[C]my_bool *\f[R] +T}@T{ +If set to 1, \f[B]mysql_stmt_store_result(3)\f[R] will update the +max_length value of MYSQL_FIELD structures. +T} +T{ +\f[C]STMT_ATTR_CURSOR_TYPE\f[R] +T}@T{ +\f[C]unsigned long *\f[R] +T}@T{ +cursor type when \f[B]mysql_stmt_execute(3)\f[R] is invoked. +Possible values are \f[C]CURSOR_TYPE_READ_ONLY\f[R] or default value +\f[C]CURSOR_TYPE_NO_CURSOR\f[R]. +T} +T{ +\f[C]STMT_ATTR_PREFETCH_ROWS\f[R] +T}@T{ +\f[C]unsigned long *\f[R] +T}@T{ +number of rows which will be prefetched. +The default value is 1. +T} +T{ +\f[C]STMT_ATTR_PREBIND_PARAMS\f[R] +T}@T{ +\f[C]unsigned int *\f[R] +T}@T{ +number of parameter markers when using +\f[B]mariadb_stmt_execute_direct(3)\f[R]. +If the statement handle is reused it will be reset automatically to the +state after mysql_stmt_init(). +This option was added in Connector/C 3.0 +T} +T{ +\f[C]STMT_ATTR_ARRAY_SIZE\f[R] +T}@T{ +\f[C]unsigned int *\f[R] +T}@T{ +number of array elements. +This option was added in Connector/C 3.0 and requires MariaDB 10.2 or +later +T} +T{ +\f[C]STMT_ATTR_ROW_SIZE\f[R] +T}@T{ +\f[C]size_t *\f[R] +T}@T{ +specifies size of a structure for row wise binding. +This length must include space for all of the bound parameters and any +padding of the structure or buffer to ensure that when the address of a +bound parameter is incremented with the specified length, the result +will point to the beginning of the same parameter in the next set of +parameters. +When using the sizeof operator in ANSI C, this behavior is guaranteed. +If the value is zero column\-wise binding will be used (default). +This option was added in Connector/C 3.0 and requires MariaDB 10.2 or +later +T} +.TE +.SS Notes +.IP \[bu] 2 +If you use the \f[C]MYSQL_STMT_ATTR_CURSOR_TYPE\f[R] option with +\f[C]MYSQL_CURSOR_TYPE_READ_ONLY\f[R], a cursor is opened for the +statement when you invoke \f[B]mysql_stmt_execute(3)\f[R]. +If there is already an open cursor from a previous +\f[B]mysql_stmt_execute(3)\f[R] call, it closes the cursor before +opening a new one. +\f[B]mysql_stmt_reset(3)\f[R] also closes any open cursor before +preparing the statement for re\-execution. +.IP \[bu] 2 +If you open a cursor for a prepared statement it is unnecessary to call +\f[B]mysql_stmt_store_result(3)\f[R]. +.IP \[bu] 2 +\f[B]mysql_stmt_free_result(3)\f[R] closes any open cursor. +.SS See Also +.IP \[bu] 2 +\f[B]mariadb_stmt_execute_direct(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_stmt_attr_get(3)\f[R] diff --git a/vendor/MDBC/man/mysql_stmt_bind_param.3 b/vendor/MDBC/man/mysql_stmt_bind_param.3 new file mode 100644 index 00000000..13a28412 --- /dev/null +++ b/vendor/MDBC/man/mysql_stmt_bind_param.3 @@ -0,0 +1,50 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_stmt_bind_param" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_stmt_bind_param \- Binds parameter to a prepared statement +.SS Synopsis +.IP +.nf +\f[C] +#include + +my_bool mysql_stmt_bind_param(MYSQL_STMT * stmt, + MYSQL_BIND * bind); +\f[R] +.fi +.SS Description +.PP +Binds variables for parameter markers in the prepared statement that was +passed to \f[B]mysql_stmt_prepare(3)\f[R]. +Returns zero on success, non\-zero on failure. +.SS Parameters +.IP \[bu] 2 +\f[C]stmt\f[R] \- a statement handle, which was previously allocated by +\f[B]mysql_stmt_init(3)\f[R]. +.IP \[bu] 2 +\f[C]bind\f[R] \- an array of \f[C]MYSQL_BIND\f[R] structures. +The size of this array must be equal to the number of parameters. +.SS Notes +.IP \[bu] 2 +The number of parameters can be obtained by +\f[B]mysql_stmt_param_count(3)\f[R]. +.IP \[bu] 2 +If the number of parameters is unknown, for example when using +\f[B]mariadb_stmt_execute_direct(3)\f[R], the number of parameters have +to be specified with the \f[B]mysql_stmt_attr_set(3)\f[R] function. +.SS See Also +.IP \[bu] 2 +\f[B]mariadb_stmt_execute_direct(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_stmt_prepare(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_stmt_bind_result(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_stmt_execute(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_stmt_param_count(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_stmt_send_long_data(3)\f[R] diff --git a/vendor/MDBC/man/mysql_stmt_bind_result.3 b/vendor/MDBC/man/mysql_stmt_bind_result.3 new file mode 100644 index 00000000..1cea6bed --- /dev/null +++ b/vendor/MDBC/man/mysql_stmt_bind_result.3 @@ -0,0 +1,45 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_stmt_bind_result" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_stmt_bind_result \- binds result columns to variables +.SS Synopsis +.IP +.nf +\f[C] +#include + +my_bool mysql_stmt_bind_result(MYSQL_STMT * stmt, + MYSQL_BIND * bind); +\f[R] +.fi +.SS Description +.PP +Binds columns in the result set to variables. +Returns zero on success, non\-zero on failure. +.SS Parameters +.IP \[bu] 2 +\f[C]stmt\f[R] \- a statement handle, which was previously allocated by +\f[B]mysql_stmt_init(3)\f[R]. +.IP \[bu] 2 +\f[C]bind\f[R] \- an array of [MYSQL_BIND]] structures. +The size of this array must be equal to the number of columns in result +set. +.SS Notes +.IP \[bu] 2 +To determine the number of columns in result set use +\f[B]mysql_stmt_field_count(3)\f[R]. +.IP \[bu] 2 +A column can be bound or rebound at any time, even after a result set +has been partially retrieved. +The new binding takes effect the next time \f[B]mysql_stmt_fetch(3)\f[R] +is called. +.SS See Also +.IP \[bu] 2 +\f[B]mysql_stmt_field_count(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_stmt_execute(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_stmt_fetch(3)\f[R] diff --git a/vendor/MDBC/man/mysql_stmt_close.3 b/vendor/MDBC/man/mysql_stmt_close.3 new file mode 100644 index 00000000..a5e1a109 --- /dev/null +++ b/vendor/MDBC/man/mysql_stmt_close.3 @@ -0,0 +1,39 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_stmt_close" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_stmt_close \- Closes a prepared statement +.SS Synopsis +.IP +.nf +\f[C] +#include + +my_bool mysql_stmt_close(MYSQL_STMT * stmt); +\f[R] +.fi +.SS Description +.PP +Closes a prepared statement and deallocates the statement handle. +If the current statement has pending or unread results, this function +cancels them so that the next query can be executed. +.SS Parameter +.IP \[bu] 2 +\f[C]stmt\f[R] \- a statement handle, which was previously allocated by +\f[B]mysql_stmt_init(3)\f[R]. +.SS Return value +.PP +Returns zero on success, nonzero on error (when communicating with the +server). +The statement is deallocated, regardless of the error. +.SS Notes +.IP \[bu] 2 +If you want to reuse the statement handle with a different SQL command, +use \f[B]mysql_stmt_reset(3)\f[R]. +.SS See Also +.IP \[bu] 2 +\f[B]mysql_stmt_init(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_stmt_reset(3)\f[R] diff --git a/vendor/MDBC/man/mysql_stmt_data_seek.3 b/vendor/MDBC/man/mysql_stmt_data_seek.3 new file mode 100644 index 00000000..6c7dc21a --- /dev/null +++ b/vendor/MDBC/man/mysql_stmt_data_seek.3 @@ -0,0 +1,43 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_stmt_data_seek" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_stmt_data_seek \- Seeks to an arbitrary row in statement result +set +.SS Synopsis +.IP +.nf +\f[C] +#include + +void mysql_stmt_data_seek(MYSQL_STMT * stmt, + my_ulonglong offset); +\f[R] +.fi +.SS Description +.PP +Seeks to an arbitrary row in statement result set obtained by a previous +call to \f[B]mysql_stmt_store_result(3)\f[R]. +.SS Parameter +.IP \[bu] 2 +\f[C]stmt\f[R] \- a statement handle, which was previously allocated by +\f[B]mysql_stmt_init(3)\f[R]. +.IP \[bu] 2 +\f[C]offset\f[R] \- row offset. +This value must between 0 and number of rows \- 1. +.SS Return value +.PP +Returns void +.SS Notes +.IP \[bu] 2 +The number of rows can be obtained with the function +\f[B]mysql_stmt_num_rows(3)\f[R]. +.SS See Also +.IP \[bu] 2 +\f[B]mysql_stmt_row_tell(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_stmt_store_result(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_stmt_num_rows(3)\f[R] diff --git a/vendor/MDBC/man/mysql_stmt_errno.3 b/vendor/MDBC/man/mysql_stmt_errno.3 new file mode 100644 index 00000000..08b08621 --- /dev/null +++ b/vendor/MDBC/man/mysql_stmt_errno.3 @@ -0,0 +1,38 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_stmt_errno" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_stmt_errno \- Returns error code for the last statement error +.SS Synopsis +.IP +.nf +\f[C] +#include + +unsigned int mysql_stmt_errno(MYSQL_STMT * stmt); +\f[R] +.fi +.SS Description +.PP +Returns the error code for the most recently invoked statement function +that can succeed or fail. +.SS Parameter +.IP \[bu] 2 +\f[C]stmt\f[R] \- a statement handle, which was previously allocated by +\f[B]mysql_stmt_init(3)\f[R]. +.SS Return value +.PP +Returns error code. +A zero value means that no error occurred. +.SS Notes +.IP \[bu] 2 +Client error messages are listed in \f[C]errmsg.h\f[R] header file, +server error messages are listed in \f[C]mysqld_error.h\f[R] header file +of the server source distribution. +.SS See Also +.IP \[bu] 2 +\f[B]mysql_stmt_error(3)\f[R], +.IP \[bu] 2 +\f[B]mysql_stmt_sqlstate(3)\f[R] diff --git a/vendor/MDBC/man/mysql_stmt_error.3 b/vendor/MDBC/man/mysql_stmt_error.3 new file mode 100644 index 00000000..56ad3fc8 --- /dev/null +++ b/vendor/MDBC/man/mysql_stmt_error.3 @@ -0,0 +1,40 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_stmt_error" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_stmt_error \- Returns a string description for the last statement +error +.SS Synopsis +.IP +.nf +\f[C] +#include + +const char * mysql_stmt_error(MYSQL_STMT * stmt); +\f[R] +.fi +.SS Description +.PP +Returns a string containing the error message for the most recently +invoked statement function that can succeed or fail. +The string will be empty if no error occurred. +.SS Parameter +.IP \[bu] 2 +\f[C]stmt\f[R] \- a statement handle, which was previously allocated by +\f[B]mysql_stmt_init(3)\f[R]. +.SS Return value +.IP \[bu] 2 +A string describing the last error or an empty string if no error +occured. +.SS Notes +.IP \[bu] 2 +Client error messages are listed in the \f[C]errmsg.h\f[R] header file, +server error messages are listed in the \f[C]mysqld_error.h\f[R] header +file of the server source distribution. +.SS See Also +.IP \[bu] 2 +\f[B]mysql_stmt_errno(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_stmt_sqlstate(3)\f[R] diff --git a/vendor/MDBC/man/mysql_stmt_execute.3 b/vendor/MDBC/man/mysql_stmt_execute.3 new file mode 100644 index 00000000..e0c30714 --- /dev/null +++ b/vendor/MDBC/man/mysql_stmt_execute.3 @@ -0,0 +1,43 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_stmt_execute" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_stmt_execute \- Executes a prepared statement +.SS Synopsis +.IP +.nf +\f[C] +#include + +int mysql_stmt_execute(MYSQL_STMT * stmt); +\f[R] +.fi +.SS Description +.PP +Executes a prepared statement which was previously prepared by +\f[B]mysql_stmt_prepare(3)\f[R]. +When executed any parameter markers which exist will automatically be +replaced with the appropriate data. +.SS Parameter +.IP \[bu] 2 +\f[C]stmt\f[R] \- A statement handle, which was previously allocated by +\f[B]mysql_stmt_init(3)\f[R]. +.SS Return value +.PP +Returns zero on success, non\-zero on failure. +.SS Notes +.IP \[bu] 2 +If the statement is UPDATE, REPLACE, DELETE or INSERT, the total number +of affected rows can be determined by using the +\f[B]mysql_stmt_affected_rows(3)\f[R] function. +Likewise, if the query yields a result set the +\f[B]mysql_stmt_fetch(3)\f[R] function is used. +.SS See Also +.IP \[bu] 2 +\f[B]mariadb_stmt_execute_direct(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_stmt_prepare(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_stmt_bind_param(3)\f[R] diff --git a/vendor/MDBC/man/mysql_stmt_fetch.3 b/vendor/MDBC/man/mysql_stmt_fetch.3 new file mode 100644 index 00000000..6f805cc7 --- /dev/null +++ b/vendor/MDBC/man/mysql_stmt_fetch.3 @@ -0,0 +1,48 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_stmt_fetch" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_stmt_fetch \- Fetches result set row from a prepared statement +.SS Synopsis +.IP +.nf +\f[C] +#include + +int mysql_stmt_fetch(MYSQL_STMT * stmt); +\f[R] +.fi +.SS Description +.PP +Fetch the result from a prepared statement into the buffer bound by +[mysql_stmt_bind_result()}(mysql_stmt_bind_result). +.SS Parameter +.IP \[bu] 2 +\f[C]stmt\f[R] \- a statement handle, which was previously allocated by +\f[B]mysql_stmt_init(3)\f[R]. +.SS Return value +.PP +Returns \f[C]0\f[R] for success, \f[C]MYSQL_NO_DATA\f[R] if the end of +the result set has been reached, or \f[C]MYSQL_DATA_TRUNCATION\f[R] if +one or more values are truncated. +.SS Notes +.IP \[bu] 2 +Note that all columns must be bound by the application before calling +mysql_stmt_fetch(). +.IP \[bu] 2 +Data are transferred unbuffered without calling +\f[B]mysql_stmt_store_result(3)\f[R] which can decrease performance (but +reduces memory cost). +.IP \[bu] 2 +Truncation reporting must be enabled by function +\f[B]mysql_optionsv(3)\f[R] with option +\f[C]MYSQL_REPORT_DATA_TRUNCATION\f[R] +.SS See Also +.IP \[bu] 2 +\f[B]mysql_stmt_prepare(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_stmt_bind_result(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_stmt_execute(3)\f[R] diff --git a/vendor/MDBC/man/mysql_stmt_fetch_column.3 b/vendor/MDBC/man/mysql_stmt_fetch_column.3 new file mode 100644 index 00000000..7dd1e346 --- /dev/null +++ b/vendor/MDBC/man/mysql_stmt_fetch_column.3 @@ -0,0 +1,44 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_stmt_fetch_column" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_stmt_fetch_column \- Fetches a single column into bind buffer +.SS Synopsis +.IP +.nf +\f[C] +#include + +int mysql_stmt_fetch_column(MYSQL_STMT * stmt, + MYSQL_BIND * bind_arg, + unsigned int column, + unsigned long offset); +\f[R] +.fi +.SS Description +.PP +This function can be used to fetch large data of a single column in +pieces. +.SS Parameter +.IP \[bu] 2 +\f[C]stmt\f[R] \- a statement handle, which was previously allocated by +\f[B]mysql_stmt_init(3)\f[R]. +.IP \[bu] 2 +\f[C]bind_arg\f[R] \- a pointer to a MYSQL_BIND structure. +.IP \[bu] 2 +\f[C]column\f[R] \- number of column, first column is numbered zero. +.IP \[bu] 2 +\f[C]offset\f[R] \- offset at which to begin retrieving data. +.SS Return value +.PP +Returns zero on success, non\-zero on failure. +.SS Notes +.IP \[bu] 2 +The size of the buffer is specified within MYSQL_BIND structure. +.SS See Also +.IP \[bu] 2 +\f[B]mysql_stmt_fetch(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_stmt_send_long_data(3)\f[R] diff --git a/vendor/MDBC/man/mysql_stmt_field_count.3 b/vendor/MDBC/man/mysql_stmt_field_count.3 new file mode 100644 index 00000000..1ff73e14 --- /dev/null +++ b/vendor/MDBC/man/mysql_stmt_field_count.3 @@ -0,0 +1,38 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_stmt_field_count" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_stmt_field_count \- Returns the number of fields in a result set +.SS Synopsis +.IP +.nf +\f[C] +#include + +unsigned int mysql_stmt_field_count(MYSQL_STMT * stmt); +\f[R] +.fi +.SS Description +.PP +Returns the number of fields in a result set of a prepared statement. +.SS Return value +.PP +Number of fields or zero if the prepared statement has no result set. +.SS Parameter +.IP \[bu] 2 +\f[C]stmt\f[R] \- a statement handle, which was previously allocated by +\f[B]mysql_stmt_init(3)\f[R]. +.SS Notes +.IP \[bu] 2 +The number of fields will be available after calling +\f[B]mysql_stmt_prepare(3)\f[R] +.IP \[bu] 2 +\f[C]mysql_stmt_field_count()\f[R] returns zero for statements which +don\[cq]t produce a result set. +.SS See Also +.IP \[bu] 2 +\f[B]mysql_stmt_prepare(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_stmt_param_count(3)\f[R] diff --git a/vendor/MDBC/man/mysql_stmt_free_result.3 b/vendor/MDBC/man/mysql_stmt_free_result.3 new file mode 100644 index 00000000..12ecd555 --- /dev/null +++ b/vendor/MDBC/man/mysql_stmt_free_result.3 @@ -0,0 +1,30 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_stmt_free_result" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_stmt_free_result \- Frees stored result set memory of a prepared +statement +.SS Synopsis +.IP +.nf +\f[C] +#include + +void mysql_stmt_free_result(MYSQL_STMT * stmt); +\f[R] +.fi +.SS Description +.PP +Frees stored result memory of a prepared statement. +.SS Parameter +.IP \[bu] 2 +\f[C]stmt\f[R] \- a statement handle, which was previously allocated by +\f[B]mysql_stmt_init(3)\f[R]. +.SS Return value +.PP +Returns void +.SS See Also +.IP \[bu] 2 +\f[B]mysql_stmt_store_result(3)\f[R] diff --git a/vendor/MDBC/man/mysql_stmt_init.3 b/vendor/MDBC/man/mysql_stmt_init.3 new file mode 100644 index 00000000..e1fd7334 --- /dev/null +++ b/vendor/MDBC/man/mysql_stmt_init.3 @@ -0,0 +1,43 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_stmt_init" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_stmt_init \- Initializes a prepared statement handle +.SS Synopsis +.IP +.nf +\f[C] +#include + +MYSQL_STMT * mysql_stmt_init(MYSQL * mysql); +\f[R] +.fi +.SS Description +.PP +Initializes and allocates memory for a prepared statement. +.SS Parameter +.IP \[bu] 2 +\f[C]mysql\f[R] \- a mysql handle, which was previously allocated by +\f[B]mysql_init(3)\f[R] and connected by +\f[B]mysql_real_connect(3)\f[R]. +.SS Return value +.PP +Returns a pointer to a \f[C]MYSQL_STMT\f[R] structure or \f[C]NULL\f[R] +if an error occurred. +.SS Notes +.IP \[bu] 2 +Members of the \f[C]MYSQL_STMT\f[R] structure are not intended for +application use. +.IP \[bu] 2 +A statement handle which was allocated by mysql_stmt_init() needs to be +freed with \f[B]mysql_stmt_close(3)\f[R]. +.IP \[bu] 2 +Any subsequent calls to any mysql_stmt function will fail until +\f[B]mysql_stmt_prepare(3)\f[R] was called. +.SS See Also +.IP \[bu] 2 +\f[B]mysql_stmt_close(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_stmt_prepare(3)\f[R] diff --git a/vendor/MDBC/man/mysql_stmt_insert_id.3 b/vendor/MDBC/man/mysql_stmt_insert_id.3 new file mode 100644 index 00000000..303250a8 --- /dev/null +++ b/vendor/MDBC/man/mysql_stmt_insert_id.3 @@ -0,0 +1,36 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_stmt_insert_id" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_stmt_insert_id \- Returns the auto generated id from previously +executed prepared statement. +.SS Synopsis +.IP +.nf +\f[C] +#include + +my_ulonglong mysql_stmt_insert_id(MYSQL_STMT * stmt); +\f[R] +.fi +.SS Description +.PP +The \f[C]mysql_stmt_insert_id()\f[R] function returns the ID generated +by a prepared statement on a table with a column having the +\f[C]AUTO_INCREMENT\f[R] attribute. +## Parameter * \f[C]stmt\f[R] \- a statement handle, which was +previously allocated by \f[B]mysql_stmt_init(3)\f[R]. +## Return value Returns the auto generated id from previously executed +prepared statement. +If the last query wasn\[cq]t an INSERT or UPDATE statement or if the +modified table does not have a column with the AUTO_INCREMENT attribute, +this function will return zero. +.SS Notes +.IP \[bu] 2 +When performing a multi insert prepared statement, +mysql_stmt_insert_id() will return the value of the first row. +.SS See Also +.IP \[bu] 2 +\f[B]mysql_insert_id(3)\f[R] diff --git a/vendor/MDBC/man/mysql_stmt_more_results.3 b/vendor/MDBC/man/mysql_stmt_more_results.3 new file mode 100644 index 00000000..2720716e --- /dev/null +++ b/vendor/MDBC/man/mysql_stmt_more_results.3 @@ -0,0 +1,39 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_stmt_more_results" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_stmt_more_results \- indicates if one or more results from a +previously executed prepared statement are available +.SS Synopsis +.IP +.nf +\f[C] +#include + +my_bool mysql_stmt_more_results(MYSQL_STMT * stmt); +\f[R] +.fi +.SS Description +.PP +Indicates if one or more result sets are available from a previous call +to \f[B]mysql_stmt_execute(3)\f[R]. +.SS Parameter +.IP \[bu] 2 +\f[C]stmt\f[R] \- a statement handle, which was previously allocated by +mysql_stmt_init() (mysql_init) and executed by +\f[B]mysql_stmt_execute(3)\f[R]. +.SS Notes +.IP \[bu] 2 +Multiple result sets can be obtained by calling a stored procedure. +Executing concatenated statements is not supported in prepared statement +protocol. +.SS Return value +.PP +Returns 1 if more result sets are available, otherwise zero. +.SS See also +.IP \[bu] 2 +\f[B]mysql_stmt_next_result(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_stmt_store_result(3)\f[R] diff --git a/vendor/MDBC/man/mysql_stmt_next_result.3 b/vendor/MDBC/man/mysql_stmt_next_result.3 new file mode 100644 index 00000000..52eca995 --- /dev/null +++ b/vendor/MDBC/man/mysql_stmt_next_result.3 @@ -0,0 +1,42 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_stmt_next_result" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_stmt_next_result \- prepares next result set of a prepared +statement +.SS Synopsis +.IP +.nf +\f[C] +#include + +int mysql_stmt_next_result(MYSQL_STMT * stmt); +\f[R] +.fi +.SS Description +.PP +Prepares next result set from a previous call to +\f[B]mysql_stmt_execute(3)\f[R] which can be retrieved by +\f[B]mysql_stmt_store_result(3)\f[R]. +.SS Parameter +.IP \[bu] 2 +\f[C]stmt\f[R] \- a statement handle, which was previously allocated by +[mysql_stmt_init()](mysql_stmt_init().]] +.SS Return value +.PP +Returns zero on success, nonzero if an error occurred. +.SS Notes +.IP \[bu] 2 +The function \f[B]mysql_stmt_more_results(3)\f[R] indicates if further +result sets are available. +.IP \[bu] 2 +If the execution of a stored procedure produced multiple result sets the +return value of \f[B]mysql_stmt_errno(3)\f[R]/error() might change and +there will be no result set available. +.SS See also +.IP \[bu] 2 +\f[B]mysql_stmt_execute(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_stmt_more_results(3)\f[R] diff --git a/vendor/MDBC/man/mysql_stmt_num_rows.3 b/vendor/MDBC/man/mysql_stmt_num_rows.3 new file mode 100644 index 00000000..74912791 --- /dev/null +++ b/vendor/MDBC/man/mysql_stmt_num_rows.3 @@ -0,0 +1,37 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_stmt_num_rows" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_stmt_num_rows \- Returns number of rows in a prepared statement +result set +.SS Synopsis +.IP +.nf +\f[C] +#include + +unsigned long long mysql_stmt_num_rows(MYSQL_STMT * stmt); +\f[R] +.fi +.SS Description +.PP +Returns the number of rows in the result set. +The use of mysql_stmt_num_rows() depends on whether or not you used +\f[B]mysql_stmt_store_result(3)\f[R] to buffer the entire result set in +the statement handle. +.SS Parameter +.IP \[bu] 2 +\f[C]stmt\f[R] \- a statement handle, which was previously allocated by +\f[B]mysql_stmt_init(3)\f[R]. +.SS Return value +.PP +Number of rows in the result set +.SS Notes +.IP \[bu] 2 +If you use \f[B]mysql_stmt_store_result(3)\f[R], mysql_stmt_num_rows() +may be called immediately. +.SS See Also +.IP \[bu] 2 +\f[B]mysql_stmt_store_result(3)\f[R] diff --git a/vendor/MDBC/man/mysql_stmt_param_count.3 b/vendor/MDBC/man/mysql_stmt_param_count.3 new file mode 100644 index 00000000..d8d838ca --- /dev/null +++ b/vendor/MDBC/man/mysql_stmt_param_count.3 @@ -0,0 +1,37 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_stmt_param_count" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_stmt_param_count \- Returns number of parameters +.SS Synopsis +.IP +.nf +\f[C] +#include + +unsigned long mysql_stmt_param_count(MYSQL_STMT * stmt); +\f[R] +.fi +.SS Description +.PP +Returns the number of parameter markers present in the prepared +statement. +Parameter markers are specified as \f[C]?\f[R] (question mark) +.SS Parameter +.IP \[bu] 2 +\f[C]stmt\f[R] \- a statement handle, which was previously allocated by +\f[B]mysql_stmt_init(3)\f[R]. +.SS Return value +.PP +The number of parameter markers in prepared statement. +.SS Notes +.IP \[bu] 2 +This function will not deliver a valid result until +mysql_stmt_prepare()() (mysql_stmt_prepare) was called. +.SS See Also +.IP \[bu] 2 +mysql_stmt_prepare()() (mysql_stmt_prepare) +.IP \[bu] 2 +\f[B]mysql_stmt_field_count(3)\f[R] diff --git a/vendor/MDBC/man/mysql_stmt_param_metadata.3 b/vendor/MDBC/man/mysql_stmt_param_metadata.3 new file mode 100644 index 00000000..d9d2bc1a --- /dev/null +++ b/vendor/MDBC/man/mysql_stmt_param_metadata.3 @@ -0,0 +1,27 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_stmt_param_metadata" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_stmt_param_metadata \- This function does nothing! +.SS Synopsis +.IP +.nf +\f[C] +#include + +MYSQL_RES * mysql_stmt_param_metadata(MYSQL_STMT * stmt); +\f[R] +.fi +.SS Description +.PP +This function does nothing, it\[cq]s not implemented now and reserved +for future use. +.SS Parameter +.IP \[bu] 2 +\f[C]stmt\f[R] \- a statement handle, which was previously allocated by +\f[B]mysql_stmt_init(3)\f[R]. +.SS Return value +.PP +Always returns \f[C]NULL\f[R]. diff --git a/vendor/MDBC/man/mysql_stmt_prepare.3 b/vendor/MDBC/man/mysql_stmt_prepare.3 new file mode 100644 index 00000000..a6d22477 --- /dev/null +++ b/vendor/MDBC/man/mysql_stmt_prepare.3 @@ -0,0 +1,58 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_stmt_prepare" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_stmt_prepare \- Prepares an SQL string +.SS Synopsis +.IP +.nf +\f[C] +#include + +int mysql_stmt_prepare(MYSQL_STMT * stmt, + const char * query, + unsigned long length); +\f[R] +.fi +.SS Description +.PP +Prepares the SQL query. +.SS Parameter +.IP \[bu] 2 +\f[C]stmt\f[R] \- a statement handle, which was previously allocated by +\f[B]mysql_stmt_init(3)\f[R]. +.IP \[bu] 2 +\f[C]query\f[R] \- SQL statement +.IP \[bu] 2 +\f[C]length\f[R] \- length of SQL statement +.SS Return value +.PP +Zero on success, non zero on error. +.SS Notes +.IP \[bu] 2 +The parameter markers must be bound to application variables using +\f[B]mysql_stmt_bind_param(3)\f[R]. +.IP \[bu] 2 +The maximum number of parameters is 65535 (0xFFFF). +.IP \[bu] 2 +The markers are legal only in certain places in SQL statements. +For example, they are allowed in the VALUES() list ofINSERT statement +(to specify column values for a row), or in a comparison with a column +in a [select()](WHERE]] clause to specify a comparison value. +However, they are not allowed in identifiers (such as table or column +names) in the select list that names the columns to be returned by +SELECT statement, or to specify both operands of a binary operator such +as the equal sign. +The latter restriction is necessary because it would be impossible to +determine the parameter type. +In general, parameters are legal only in Data Manipulation Language +(DML) statements, and not in Data Definition Language (DDL) statements. +.SS See Also +.IP \[bu] 2 +\f[B]mysql_stmt_init(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_stmt_param_count(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_stmt_execute(3)\f[R] diff --git a/vendor/MDBC/man/mysql_stmt_reset.3 b/vendor/MDBC/man/mysql_stmt_reset.3 new file mode 100644 index 00000000..c7fd0395 --- /dev/null +++ b/vendor/MDBC/man/mysql_stmt_reset.3 @@ -0,0 +1,44 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_stmt_reset" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_stmt_reset \- Resets a prepared statement +.SS Synopsis +.IP +.nf +\f[C] +#include + +my_bool mysql_stmt_reset(MYSQL_STMT * stmt); +\f[R] +.fi +.SS Description +.PP +Resets a prepared statement on client and server to state after prepare. +.SS Parameter +.IP \[bu] 2 +\f[C]stmt\f[R] \- a statement handle, which was previously allocated by +\f[B]mysql_stmt_init(3)\f[R]. +Returns zero on success, nonzero if an error occurred. +.SS Return value +.PP +Returns zero on succes, 1 if an error occured. +.SS Notes +.IP \[bu] 2 +\f[C]mysql_stmt_reset()\f[R] resets the statement on the server, +unbuffered result sets and errors. +Bindings and stored result sets will not be cleared. +The latter one will be cleared when re\-executing or closing the +prepared statement. +.IP \[bu] 2 +To reprepare a prepared statement with another SQL statement use +\f[B]mysql_stmt_prepare(3)\f[R]. +.SS See Also +.IP \[bu] 2 +\f[B]mysql_stmt_close(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_stmt_prepare(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_stmt_execute(3)\f[R] diff --git a/vendor/MDBC/man/mysql_stmt_result_metadata.3 b/vendor/MDBC/man/mysql_stmt_result_metadata.3 new file mode 100644 index 00000000..42f01bcd --- /dev/null +++ b/vendor/MDBC/man/mysql_stmt_result_metadata.3 @@ -0,0 +1,50 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_stmt_result_metadata" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_stmt_result_metadata \- Returns result set metadata from a +prepared statement. +.SS Synopsis +.IP +.nf +\f[C] +#include + +MYSQL_RES * mysql_stmt_result_metadata(MYSQL_STMT * stmt); +\f[R] +.fi +.SS Description +.PP +If a statement passed to \f[B]mysql_stmt_prepare(3)\f[R] is one that +produces a result set, mysql_stmt_result_metadata() returns the result +set that can be used to process the meta information such as total +number of fields and individual field information. +.SS Parameter +.IP \[bu] 2 +\f[C]stmt\f[R] \- a statement handle, which was previously allocated by +\f[B]mysql_stmt_init(3)\f[R]. +.SS Return value +.PP +Returns a result set that can be used to process metadata information. +.SS Notes +.IP \[bu] 2 +The result set returned by mysql_stmt_result_metadata() contains only +metadata. +It does not contain any row results. +The rows are obtained by \f[B]mysql_stmt_fetch(3)\f[R]. +.IP \[bu] 2 +This result set pointer can be passed as an argument to any of the +field\-based functions that process result set metadata, such as: +\f[B]mysql_num_fields(3)\f[R], \f[B]mysql_fetch_field(3)\f[R], +\f[B]mysql_fetch_field_direct(3)\f[R], \f[B]mysql_fetch_fields(3)\f[R], +\f[B]mysql_field_count(3)\f[R], \f[B]mysql_field_seek(3)\f[R], +\f[B]mysql_field_tell(3)\f[R], \f[B]mysql_free_result(3)\f[R] +.SS See Also +.IP \[bu] 2 +\f[B]mariadb_stmt_fetch_fields(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_free_result(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_stmt_prepare(3)\f[R] diff --git a/vendor/MDBC/man/mysql_stmt_row_seek.3 b/vendor/MDBC/man/mysql_stmt_row_seek.3 new file mode 100644 index 00000000..dceeb3a1 --- /dev/null +++ b/vendor/MDBC/man/mysql_stmt_row_seek.3 @@ -0,0 +1,40 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_stmt_row_seek" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_stmt_row_seek \- Positions row cursor. +.SS Synopsis +.IP +.nf +\f[C] +#include + +MYSQL_ROW_OFFSET mysql_stmt_row_seek(MYSQL_STMT * stmt, + MYSQL_ROW_OFFSET offset); +\f[R] +.fi +.SS Description +.PP +Positions the row cursor to an arbitrary row in a result set which was +obtained by \f[B]mysql_stmt_store_result(3)\f[R]. +.SS Parameter +.IP \[bu] 2 +\f[C]stmt\f[R] \- a statement handle, which was previously allocated by +\f[B]mysql_stmt_init(3)\f[R]. +.IP \[bu] 2 +\f[C]offset\f[R] \- row offset. +This value can be obtained either by mysql_stmt_row_seek() or +\f[B]mysql_stmt_row_tell(3)\f[R]. +.SS Return value +.PP +Returns the previous row offset. +.SS Notes +.PP +The result set must be obtained by \f[B]mysql_use_result(3)\f[R]. +.SS See Also +.IP \[bu] 2 +\f[B]mysql_stmt_row_tell(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_stmt_store_result(3)\f[R] diff --git a/vendor/MDBC/man/mysql_stmt_row_tell.3 b/vendor/MDBC/man/mysql_stmt_row_tell.3 new file mode 100644 index 00000000..f1116651 --- /dev/null +++ b/vendor/MDBC/man/mysql_stmt_row_tell.3 @@ -0,0 +1,37 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_stmt_row_tell" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_stmt_row_tell \- Returns position of row cursor +.SS Synopsis +.IP +.nf +\f[C] +#include + +MYSQL_ROW_OFFSET mysql_stmt_row_tell(MYSQL_STMT * stmt); +\f[R] +.fi +.SS Description +.PP +Returns the row offset of a result cursor. +The returned offset value can be used to reposition the result cursor by +calling \f[B]mysql_stmt_row_seek(3)\f[R]. +.SS Parameter +.IP \[bu] 2 +\f[C]stmt\f[R] \- a statement handle, which was previously allocated by +\f[B]mysql_stmt_init(3)\f[R]. +.SS Return value +.PP +Returns the current position of the row cursor. +.SS Notes +.IP \[bu] 2 +This function can be used for buffered result sets only, which can be +obtained by executing the \f[B]mysql_stmt_store_result(3)\f[R] function. +.SS See Also +.IP \[bu] 2 +\f[B]mysql_stmt_row_seek(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_stmt_store_result(3)\f[R] diff --git a/vendor/MDBC/man/mysql_stmt_send_long_data.3 b/vendor/MDBC/man/mysql_stmt_send_long_data.3 new file mode 100644 index 00000000..9fd9b60a --- /dev/null +++ b/vendor/MDBC/man/mysql_stmt_send_long_data.3 @@ -0,0 +1,51 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_stmt_send_long_data" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_stmt_send_long_data \- Sends data in chunks +.SS Synopsis +.IP +.nf +\f[C] +#include + +my_bool mysql_stmt_send_long_data(MYSQL_STMT * stmt, + unsigned int, + const char * data, + unsigned long); +\f[R] +.fi +.SS Description +.PP +Allows sending parameter data to the server in pieces (or chunks), +e.g.\ if the size of a blob exceeds the size of max_allowed_packet size. +This function can be called multiple times to send the parts of a +character or binary data value for a column, which must be one of the +\f[C]TEXT\f[R] or \f[C]BLOB\f[R] datatypes. +.SS Parameter +.IP \[bu] 2 +\f[C]stmt\f[R] \- a statement handle, which was previously allocated by +\f[B]mysql_stmt_init(3)\f[R]. +.IP \[bu] 2 +\f[C]param_no\f[R] \- indicates which parameter to associate the data +with. +Parameters are numbered beginning with 0. +.IP \[bu] 2 +\f[C]data\f[R] \- a buffer containing the data to send. +.IP \[bu] 2 +\f[C]long\f[R] \- size of the data buffer. +.SS Return value +.PP +Returns zero on success, nonzero if an error occurred. +.SS Notes +.IP \[bu] 2 +\f[C]mysql_stmt_send_long_data()\f[R] must be called before +\f[B]mysql_stmt_execute(3)\f[R]. +.IP \[bu] 2 +bound variables for this column will be ignored when calling +\f[B]mysql_stmt_execute(3)\f[R]. +.SS See also +.IP \[bu] 2 +\f[B]mysql_stmt_execute(3)\f[R]. diff --git a/vendor/MDBC/man/mysql_stmt_sqlstate.3 b/vendor/MDBC/man/mysql_stmt_sqlstate.3 new file mode 100644 index 00000000..3cf0c5d9 --- /dev/null +++ b/vendor/MDBC/man/mysql_stmt_sqlstate.3 @@ -0,0 +1,36 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_stmt_sqlstate" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_stmt_sqlstate \- Returns SQLSTATE error from previous statement +operation. +.SS Synopsis +.IP +.nf +\f[C] +#include + +const char * mysql_stmt_sqlstate(MYSQL_STMT * stmt); +\f[R] +.fi +.SS Description +.PP +Returns a string containing the SQLSTATE error code for the most +recently invoked prepared statement function that can succeed or fail. +## Parameter * \f[C]stmt\f[R] \- a statement handle, which was +previously allocated by \f[B]mysql_stmt_init(3)\f[R]. +## Return value Returns a 5 digit error code. +`00000' means no error. +The values are specified by ANSI SQL and ODBC. +.SS Notes +.PP +Please note that not all client library error codes are mapped to +SQLSTATE errors. +Errors which can\[cq]t be mapped will returned as value HY000. +.SS See Also +.IP \[bu] 2 +\f[B]mysql_stmt_errno(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_stmt_error(3)\f[R] diff --git a/vendor/MDBC/man/mysql_stmt_store_result.3 b/vendor/MDBC/man/mysql_stmt_store_result.3 new file mode 100644 index 00000000..63be3ac3 --- /dev/null +++ b/vendor/MDBC/man/mysql_stmt_store_result.3 @@ -0,0 +1,38 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_stmt_store_result" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_stmt_store_result \- Transfers a result set from a prepared +statement +.SS Synopsis +.IP +.nf +\f[C] +#include + +int mysql_stmt_store_result(MYSQL_STMT * stmt); +\f[R] +.fi +.SS Description +.PP +You must call mysql_stmt_store_result() for every query that +successfully produces a result set only if you want to buffer the +complete result set by the client, so that the subsequent +\f[B]mysql_stmt_fetch(3)\f[R] call returns buffered data. +.SS Parameter +.IP \[bu] 2 +\f[C]stmt\f[R] \- a statement handle, which was previously allocated by +\f[B]mysql_stmt_init(3)\f[R]. +.SS Return value +.PP +Returns zero on success, nonzero if an error occurred. +## Notes * You can detect whether the statement produced a result set by +checking the return value of \f[B]mysql_stmt_field_count(3)\f[R] +function. +.SS See Also +.IP \[bu] 2 +\f[B]mysql_stmt_field_count(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_stmt_fetch(3)\f[R] diff --git a/vendor/MDBC/man/mysql_stmt_warning_count.3 b/vendor/MDBC/man/mysql_stmt_warning_count.3 new file mode 100644 index 00000000..8dc373dd --- /dev/null +++ b/vendor/MDBC/man/mysql_stmt_warning_count.3 @@ -0,0 +1,38 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_stmt_warning_count" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_stmt_warning_count \- Returns the number of warnings from the last +executed statement. +.SS Synopsis +.IP +.nf +\f[C] +#include + +unsigned int mysql_stmt_warning_count(MYSQL_STMT * stmt); +\f[R] +.fi +.SS Description +.PP +Returns the number of warnings from the last executed statement, or zero +if there are no warnings. +## Parameter * \f[C]stmt\f[R] \- a statement handle, which was +previously allocated by \f[B]mysql_stmt_init(3)\f[R]. +.SS Return value +.PP +Returns the number of warnings. +.SS Notes +.IP \[bu] 2 +For retrieving warning messages you should use the SQL command +\f[C]SHOW WARNINGS\f[R]. +.IP \[bu] 2 +If SQL_MODE \f[C]TRADITIONAL\f[R] is enabled an error instead of warning +will be returned. +For detailed information check the server documentation. +## History This function was added in Connector/C 3.0. +.SS See Also +.IP \[bu] 2 +\f[B]mysql_warning_count(3)\f[R] diff --git a/vendor/MDBC/man/mysql_store_result.3 b/vendor/MDBC/man/mysql_store_result.3 new file mode 100644 index 00000000..e73cb3c6 --- /dev/null +++ b/vendor/MDBC/man/mysql_store_result.3 @@ -0,0 +1,39 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_store_result" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_store_result \- returns a buffered result set +.SS Synopsis +.IP +.nf +\f[C] +#include + +MYSQL_RES * mysql_store_result(MYSQL * mysql); +\f[R] +.fi +.SS Description +.PP +Returns a buffered resultset from the last executed query. +### Notes +.IP \[bu] 2 +mysql_field_count() (imysql_field_count) indicates if there will be a +result set available. +.IP \[bu] 2 +The memory allocated by mysql_store_result() needs to be released by +calling the function \f[B]mysql_free_result(3)\f[R]. +.SS Parameters +.IP \[bu] 2 +\f[C]mysql\f[R] is a connection identifier, which was previously +allocated by \f[B]mysql_init(3)\f[R] and connected by +\f[B]mysql_real_connect(3)\f[R]. +.SS Return value +.PP +Returns a buffered result set or NULL in case an error occured or if the +query didn\[cq]t return data (e.g.\ when executing an INSERT, UPDATE, +DELETE or REPLACE statement). +## See also * \f[B]mysql_free_result(3)\f[R] * +\f[B]mysql_use_result(3)\f[R] * \f[B]mysql_real_query(3)\f[R] * +\f[B]mysql_field_count(3)\f[R] diff --git a/vendor/MDBC/man/mysql_thread_end.3 b/vendor/MDBC/man/mysql_thread_end.3 new file mode 100644 index 00000000..881d4f1e --- /dev/null +++ b/vendor/MDBC/man/mysql_thread_end.3 @@ -0,0 +1,36 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_thread_end" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_thread_end \- Releases thread specific memory +.SS Synopsis +.IP +.nf +\f[C] +#include + +void mysql_thread_end(void ); +\f[R] +.fi +.SS Description +.PP +The mysql_thread_end() function needs to be called before a client +thread ends. +It will release thread specific memory, which was allocated by a +previous \f[B]mysql_thread_init(3)\f[R] call. +Returns void. +.SS Notes +.PP +Unlike \f[B]mysql_thread_init(3)\f[R] mysql_thread_end() will not be +invoked automatically if the thread ends. +To avoid memory leaks mysql_thread_end() must be called explicitly. +.SS History +.PP +This function is deprecated since MariaDB Connector/C 3.0.0. +.SS See also +.IP \[bu] 2 +\f[B]mysql_thread_init(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_thread_safe(3)\f[R] diff --git a/vendor/MDBC/man/mysql_thread_id.3 b/vendor/MDBC/man/mysql_thread_id.3 new file mode 100644 index 00000000..b04eaf56 --- /dev/null +++ b/vendor/MDBC/man/mysql_thread_id.3 @@ -0,0 +1,39 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_thread_id" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_thread_id \- Returns id of the current connection +.SS Synopsis +.IP +.nf +\f[C] +#include + +unsigned long mysql_thread_id(MYSQL * mysql); +\f[R] +.fi +.SS Description +.PP +The mysql_thread_id() function returns the thread id for the current +connection. +.SS Parameter +.IP \[bu] 2 +\f[C]mysql\f[R] \- a mysql handle, which was previously allocated by +\f[B]mysql_init(3)\f[R] and connected by +\f[B]mysql_real_connect(3)\f[R]. +### Notes +.IP \[bu] 2 +The current connection can be killed with \f[B]mysql_kill(3)\f[R]. +.IP \[bu] 2 +If reconnect option is enabled the thread id might change if the client +reconnects to the server. +.SS Return value +.PP +Returns the thread id of the current connection. +.SS See also +.IP \[bu] 2 +\f[B]mysql_kill(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_options(3)\f[R] diff --git a/vendor/MDBC/man/mysql_thread_init.3 b/vendor/MDBC/man/mysql_thread_init.3 new file mode 100644 index 00000000..d2d14034 --- /dev/null +++ b/vendor/MDBC/man/mysql_thread_init.3 @@ -0,0 +1,41 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_thread_init" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_thread_init \- initialize thread +.SS Synopsis +.IP +.nf +\f[C] +#include + +my_bool mysql_thread_init(void ); +\f[R] +.fi +.SS Description +.PP +Thread initialization for multi threaded clients. +Multi threaded clients should call mysql_thread_init() at the beginning +of the thread initialization to initialize thread specific client +library variables. +If mysql_thread_init() was not called explicitly, it will be called +automatically by \f[B]mysql_init(3)\f[R] or +\f[B]mysql_real_connect(3)\f[R]. +.SS Notes +.PP +Before a client thread ends the \f[B]mysql_thread_end(3)\f[R] function +must be called to release memory \- otherwise the client library will +report an error. +.SS Return value +.PP +Returns zero if successful or 1 if an error occurred. +.SS History +.PP +This function is deprecated since MariaDB Connector/C 3.0.0. +.SS See also +.IP \[bu] 2 +\f[B]mysql_thread_end(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_thread_safe(3)\f[R] diff --git a/vendor/MDBC/man/mysql_use_result.3 b/vendor/MDBC/man/mysql_use_result.3 new file mode 100644 index 00000000..89347af5 --- /dev/null +++ b/vendor/MDBC/man/mysql_use_result.3 @@ -0,0 +1,46 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_use_result" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_use_result \- returns an unbuffered result set +.SS Synopsis +.IP +.nf +\f[C] +#include + +MYSQL_RES * mysql_use_result(MYSQL * mysql); +\f[R] +.fi +.SS Description +.PP +Used to initiate the retrieval of a result set from the last query +executed using the mysql_real_query() function on the database +connection. +Either this or the \f[B]mysql_store_result(3)\f[R] function must be +called before the results of a query can be retrieved, and one or the +other must be called to prevent the next query on that database +connection from failing. +.SS Parameters +.IP \[bu] 2 +\f[C]mysql\f[R] is a connection identifier, which was previously +allocated by \f[B]mysql_init(3)\f[R] and connected by +\f[B]mysql_real_connect(3)\f[R]. +.SS Notes +.PP +The mysql_use_result() function does not transfer the entire result set. +Hence several functions like \f[B]mysql_num_rows(3)\f[R] or +\f[B]mysql_data_seek(3)\f[R] cannot be used. +mysql_use_result() will block the current connection until all result +sets are retrieved or result set was released by +\f[B]mysql_free_result(3)\f[R]. +.SS Return value +.PP +Returns an unbuffered result set or \f[C]NULL\f[R] if an error occurred. +.SS See also +.IP \[bu] 2 +\f[B]mysql_store_result(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_free_result(3)\f[R] diff --git a/vendor/MDBC/man/mysql_warning_count.3 b/vendor/MDBC/man/mysql_warning_count.3 new file mode 100644 index 00000000..6fce09b0 --- /dev/null +++ b/vendor/MDBC/man/mysql_warning_count.3 @@ -0,0 +1,41 @@ +.\" Automatically generated by Pandoc 2.5 +.\" +.TH "mysql_warning_count" "3" "" "Version 3.2.2" "MariaDB Connector/C" +.hy +.SS Name +.PP +mysql_warning_count \- Returns the number of warnings +.SS Synopsis +.IP +.nf +\f[C] +#include + +unsigned int mysql_warning_count(MYSQL * mysql); +\f[R] +.fi +.SS Description +.PP +Returns the number of warnings from the last executed query, or zero if +there are no warnings. +.SS Parameter +.IP \[bu] 2 +\f[C]mysql\f[R] \- a mysql handle, which was previously allocated by +\f[B]mysql_init(3)\f[R] and connected by +\f[B]mysql_real_connect(3)\f[R]. +.SS Notes +.IP \[bu] 2 +For retrieving warning messages you should use the SQL command +\f[C]SHOW WARNINGS\f[R]. +.IP \[bu] 2 +If SQL_MODE \f[C]TRADITIONAL\f[R] is enabled an error instead of warning +will be returned. +For detailed information check the server documentation. +.SS Return value +.PP +Returns the number of warnings +.SS See also +.IP \[bu] 2 +\f[B]mysql_error(3)\f[R] +.IP \[bu] 2 +\f[B]mysql_errno(3)\f[R] diff --git a/vendor/MDBC/mariadb_config/CMakeLists.txt b/vendor/MDBC/mariadb_config/CMakeLists.txt new file mode 100644 index 00000000..5bbf36b0 --- /dev/null +++ b/vendor/MDBC/mariadb_config/CMakeLists.txt @@ -0,0 +1,67 @@ +INCLUDE_DIRECTORIES(${CC_SOURCE_DIR}/include) + +# Figure out additional libraries for use with + +FUNCTION(GET_LIB_NAME LIB_NAME LIB_OUT) + IF(APPLE) + STRING(FIND ${LIB_NAME} ".dylib" IS_SO) + ELSE() + STRING(FIND ${LIB_NAME} ".so" IS_SO) + ENDIF() + IF(NOT ${IS_SO} STREQUAL "-1") + GET_FILENAME_COMPONENT(LIB_FILE ${LIB_NAME} NAME_WE) + ELSE() + SET(LIB_FILE ${LIB_NAME}) + ENDIF() + + STRING(SUBSTRING ${LIB_NAME} 0 1 LIB_PREFIX) + + IF(NOT ${LIB_PREFIX} STREQUAL "-") + SET(LIB_FILE "-l${LIB_FILE}") + STRING(REPLACE "-llib" "-l" LIB_FILE ${LIB_FILE}) + SET(${LIB_OUT} ${LIB_FILE} PARENT_SCOPE) + ELSE() + SET(${LIB_OUT} ${LIB_NAME} PARENT_SCOPE) + ENDIF() +ENDFUNCTION() + +LIST(LENGTH SYSTEM_LIBS rllength) +IF(${rllength} GREATER 0) + LIST(REMOVE_DUPLICATES SYSTEM_LIBS) +ENDIF() + +FOREACH (LIB_NAME ${SYSTEM_LIBS}) + GET_LIB_NAME(${LIB_NAME} LIB_OUT) + SET(extra_dynamic_LDFLAGS "${extra_dynamic_LDFLAGS} ${LIB_OUT}") +ENDFOREACH() +STRING(STRIP "${extra_dynamic_LDFLAGS}" extra_dynamic_LDFLAGS) +LIST(REMOVE_DUPLICATES extra_dynamic_LDFLAGS) + +IF(UNIX AND NOT APPLE) + IF(ICONV_EXTERNAL) + GET_LIB_NAME(${ICONV_LIBRARIES} LIB_OUT) + SET(extra_dynamic_LDFLAGS "${extra_dynamic_LDFLAGS} ${LIB_OUT}") + ENDIF() +ENDIF() + +CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/mariadb_config.c.in + ${CMAKE_CURRENT_BINARY_DIR}/mariadb_config.c @ONLY) + +CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/libmariadb.pc.in + ${CMAKE_CURRENT_BINARY_DIR}/libmariadb.pc @ONLY) + +ADD_EXECUTABLE(mariadb_config ${CMAKE_CURRENT_BINARY_DIR}/mariadb_config.c) + +IF(CMAKE_SYSTEM_NAME MATCHES AIX) + TARGET_LINK_LIBRARIES(mariadb_config compat-getopt) +ENDIF() + +# Installation +# +INSTALL(TARGETS mariadb_config + DESTINATION "bin" + COMPONENT Development) + +INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/libmariadb.pc + DESTINATION "${INSTALL_PCDIR}" + COMPONENT Development) diff --git a/vendor/MDBC/mariadb_config/libmariadb.pc.in b/vendor/MDBC/mariadb_config/libmariadb.pc.in new file mode 100644 index 00000000..968181a1 --- /dev/null +++ b/vendor/MDBC/mariadb_config/libmariadb.pc.in @@ -0,0 +1,20 @@ +# +# pkg_config.pc.in +# +# pkg_config configuration file +# For a detailed description of options, please visit +# Dan Nicholson’s Guide to pkg-config (http://www.freedesktop.org/wiki/Software/pkg-config/) +# + +prefix=@CMAKE_INSTALL_PREFIX@ +includedir=${prefix}/@INSTALL_INCLUDEDIR@/@SUFFIX_INSTALL_DIR@ +libdir=${prefix}/@INSTALL_LIBDIR@/@SUFFIX_INSTALL_DIR@ + +Name: libmariadb +Version: @CPACK_PACKAGE_VERSION@ +Description: MariaDB Connector/C dynamic library +Cflags: -I${includedir} +Libs: -L${libdir} -lmariadb +Libs.private: @extra_dynamic_LDFLAGS@ + + diff --git a/vendor/MDBC/mariadb_config/mariadb_config.c.in b/vendor/MDBC/mariadb_config/mariadb_config.c.in new file mode 100644 index 00000000..55749432 --- /dev/null +++ b/vendor/MDBC/mariadb_config/mariadb_config.c.in @@ -0,0 +1,299 @@ +#include +#include +#include +#include +#include +#ifdef HAVE_SYS_STAT_H +#include +#endif +#if defined(__FreeBSD__) +#include +#endif +#ifdef HAVE_SYS_TYPES_H +#include +#endif +#include +#ifdef HAVE_LINUX_LIMITS_H +#include +#endif +#include +#if defined(__APPLE__) +#include +#endif + +static char *mariadb_progname; + +#ifndef PATH_MAX +#define PATH_MAX 4096 +#endif + +#define INCLUDE "-I%s/@INSTALL_INCLUDEDIR@ -I%s/@INSTALL_INCLUDEDIR@/mysql" +#define LIBS "-L%s/@INSTALL_LIBDIR@/ -lmariadb" +#define LIBS_SYS "@extra_dynamic_LDFLAGS@" +#define CFLAGS INCLUDE +#define VERSION "@MARIADB_CLIENT_VERSION@" +#define CC_VERSION "@CPACK_PACKAGE_VERSION@" +#define PLUGIN_DIR "%s/@INSTALL_PLUGINDIR@" +#define SOCKET "@MARIADB_UNIX_ADDR@" +#define PORT "@MARIADB_PORT@" +#ifdef HAVE_TLS +#define TLS_LIBRARY_VERSION "@TLS_LIBRARY_VERSION@" +#else +#define TLS_LIBRARY_VERSION "" +#endif +#define PKG_INCLUDEDIR "%s/@INSTALL_INCLUDEDIR@" +#define PKG_PLUGINDIR "%s/@INSTALL_PLUGINDIR@" +#define PKG_LIBDIR "%s/@INSTALL_LIBDIR@" + +#if defined(SOLARIS) || defined(__sun) +#define OPT_STRING_TYPE (char *) +#else +#define OPT_STRING_TYPE +#endif +static struct option long_options[]= +{ + {OPT_STRING_TYPE "cflags", no_argument, 0, 'a'}, + {OPT_STRING_TYPE "help", no_argument, 0, 'b'}, + {OPT_STRING_TYPE "include", no_argument, 0, 'c'}, + {OPT_STRING_TYPE "libs", no_argument, 0, 'd'}, + {OPT_STRING_TYPE "libs_r", no_argument, 0, 'e'}, + {OPT_STRING_TYPE "libs_sys", no_argument, 0, 'l'}, + {OPT_STRING_TYPE "version", no_argument, 0, 'f'}, + {OPT_STRING_TYPE "cc_version", no_argument, 0, 'g'}, + {OPT_STRING_TYPE "socket", no_argument, 0, 'h'}, + {OPT_STRING_TYPE "port", no_argument, 0, 'i'}, + {OPT_STRING_TYPE "plugindir", no_argument, 0, 'j'}, + {OPT_STRING_TYPE "tlsinfo", no_argument, 0, 'k'}, + {OPT_STRING_TYPE "variable", 2, 0, 'm'}, + {NULL, 0, 0, 0} +}; + +static struct { + const char *variable; + const char *value; +} variables[] = { + {"pkgincludedir", PKG_INCLUDEDIR}, + {"pkglibdir", PKG_LIBDIR}, + {"pkgplugindir", PKG_PLUGINDIR}, + {NULL, NULL} +}; + +char installation_dir[PATH_MAX]; + +static const char *values[]= +{ + CFLAGS, + NULL, + INCLUDE, + LIBS, + LIBS, + LIBS_SYS, + VERSION, + CC_VERSION, + SOCKET, + PORT, + PLUGIN_DIR, + TLS_LIBRARY_VERSION, + "VAR VAR is one of:" +}; + +void usage(void) +{ + int i=0; + puts("Copyright 2011-2020 MariaDB Corporation AB"); + puts("Get compiler flags for using the MariaDB Connector/C."); + printf("Usage: %s [OPTIONS]\n", mariadb_progname); + printf("Compiler: @CMAKE_C_COMPILER_ID@ @CMAKE_C_COMPILER_VERSION@\n"); + while (long_options[i].name) + { + if (!long_options[i].has_arg) + { + if (values[i]) + { + printf(" --%-12s [", long_options[i].name); + printf(values[i], installation_dir, installation_dir); + printf("]\n"); + } + } else + { + printf(" --%s=%s\n", long_options[i].name, values[i]); + /* Variables */ + if (long_options[i].val == 'm') + { + int i= 0; + while (variables[i].variable) + { + printf(" %-14s [", variables[i].variable); + printf(variables[i].value, installation_dir); + printf("]\n"); + i++; + } + } + } + + i++; + } +} + +/* + mariadb_get_install_location() + Tries to find the installation location in the following order: + 1) check if MARIADB_CONFIG environment variable was set + 2) try to determine the installation directory from executable path + 3) Fallback if 1 and 2 failed: use CMAKE_SYSROOT/CMAKE_INSTALL_PREFIX +*/ +static void mariadb_get_install_location() +{ + char *p= NULL; + struct stat s; + + /* Check environment variable MARIADB_CONFIG */ + if ((p= getenv("MARIADB_CONFIG"))) + { + if (!stat(p, &s) && S_ISREG(s.st_mode)) + { + goto end; + } + } + /* Try to determine path of executable */ + if (!(p= alloca(PATH_MAX))) + goto end; + else { +#if defined(__APPLE__) + unsigned int len= PATH_MAX; + if (_NSGetExecutablePath(p, &len) != 0) + *p= 0; + else + { + p[len]= 0; + if (realpath(p, p) != 0) + *p= 0; + } +#elif defined(__sun) || defined(SOLARIS) + if (realpath(getexecname(), p) == NULL) + *p= 0; +#elif defined(__NetBSD__) + ssize_t len= readlink("/proc/curproc/exe", p, PATH_MAX); + if (len == -1 || len == PATH_MAX) + *p= 0; + else + p[len]= 0; +#elif defined(__FreeBSD__) + int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1}; + size_t cb = PATH_MAX; + if (sysctl(mib, 4, p, &cb, NULL, 0) == -1) + *p= 0; + else + p[cb]= 0; +#elif defined(__linux__) + ssize_t len= readlink("/proc/self/exe", p, PATH_MAX); + if (len == -1 || len == PATH_MAX) + *p= 0; + else + p[len]= 0; +#else + *p= 0; +#endif + } +end: + if (p && p[0]) + { + char *c, *search= alloca(6 + strlen(mariadb_progname)); + sprintf(search, "/bin/%s", mariadb_progname); + c= strstr(p, search); + if (c) + { + strncpy(installation_dir, p, c - p); + } + else + *p=0; + } + if (!p || !p[0]) + { + strncpy(installation_dir, "@CMAKE_SYSROOT@@CMAKE_INSTALL_PREFIX@", PATH_MAX - 1); + return; + } +} + +int main(int argc, char **argv) +{ + int c; + char *p = strrchr(argv[0], '/'); + mariadb_progname= p ? p + 1 : argv[0]; + + mariadb_get_install_location(); + + if (argc <= 1) + { + usage(); + exit(0); + } + + while(1) + { + int option_index= 0; + c= getopt_long(argc, argv, "abcdefghijkl", long_options, &option_index); + + switch(c) { + case 'a': /* CFLAGS and Include directories */ + printf(CFLAGS, installation_dir, installation_dir); + break; + case 'b': /* Usage */ + usage(); + break; + case 'c': /* Include directories */ + printf(INCLUDE, installation_dir, installation_dir); + break; + case 'd': /* Library directories and names */ + case 'e': + printf(LIBS, installation_dir); + break; + case 'f': /* Server version */ + printf(VERSION); + break; + case 'g': /* Connector/C version */ + printf(CC_VERSION); + break; + case 'h': /* Unix socket */ + printf(SOCKET); + break; + case 'i': /* default port */ + printf(PORT); + break; + case 'j': /* plugin directory */ + printf(PLUGIN_DIR, installation_dir); + break; + case 'k': /* TLS version */ + printf("%s", TLS_LIBRARY_VERSION); + break; + case 'l': /* System libraries */ + printf(LIBS_SYS); + break; + case 'm': /* variable */ + { + int i= 0; + while (variables[i].variable) + { + if (!strcmp(optarg, variables[i].variable)) + { + printf(variables[i].value, installation_dir); + break; + } + i++; + } + if (!variables[i].variable) + { + printf("Unknown variable '%s'\n", optarg); + exit(1); + } + break; + } + default: + exit((c != -1)); + } + printf("\n"); + } + + exit(0); +} + diff --git a/vendor/MDBC/plugins/CMakeLists.txt b/vendor/MDBC/plugins/CMakeLists.txt new file mode 100644 index 00000000..3b0e5e83 --- /dev/null +++ b/vendor/MDBC/plugins/CMakeLists.txt @@ -0,0 +1,9 @@ +SET(PLUGIN_EXTRA_FILES ${CC_SOURCE_DIR}/libmariadb/ma_errmsg.c) + + +FILE(GLOB plugin_dirs ${CC_SOURCE_DIR}/plugins/*) +FOREACH(dir ${plugin_dirs}) + IF (EXISTS ${dir}/CMakeLists.txt) + INCLUDE(${dir}/CMakeLists.txt) + ENDIF() +ENDFOREACH() diff --git a/vendor/MDBC/plugins/auth/CMakeLists.txt b/vendor/MDBC/plugins/auth/CMakeLists.txt new file mode 100644 index 00000000..0e3b5478 --- /dev/null +++ b/vendor/MDBC/plugins/auth/CMakeLists.txt @@ -0,0 +1,132 @@ +SET(AUTH_DIR ${CC_SOURCE_DIR}/plugins/auth) + +INCLUDE_DIRECTORIES(${AUTH_DIR}) +INCLUDE_DIRECTORIES(${CC_SOURCE_DIR}/include) + +SET(CRYPTO_PLUGIN 1) +IF(WIN32) + SET(CRYPT_SOURCE ${CC_SOURCE_DIR}/libmariadb/secure/win_crypt.c) + SET(CRYPT_LIBS crypt32 bcrypt) +ELSEIF(WITH_SSL STREQUAL "OPENSSL") + SET(CRYPT_SOURCE ${CC_SOURCE_DIR}/libmariadb/secure/openssl_crypt.c) + SET(CRYPT_LIBS ${SSL_LIBRARIES}) +ELSEIF(WITH_SSL STREQUAL "GNUTLS") + SET(CRYPT_SOURCE ${CC_SOURCE_DIR}/libmariadb/secure/gnutls_crypt.c) + IF (NOT SSL_LIBRARIES MATCHES "^.*\\.a$") + SET(CRYPT_LIBS ${SSL_LIBRARIES}) + ENDIF() +ELSE() + UNSET(CRYPTO_PLUGIN) +ENDIF() + +#native password +REGISTER_PLUGIN(TARGET mysql_native_password + TYPE MARIADB_CLIENT_PLUGIN_AUTH + CONFIGURATIONS STATIC + DEFAULT STATIC + SOURCES ${CC_SOURCE_DIR}/plugins/auth/my_auth.c) + +#Dialog client authentication plugin +REGISTER_PLUGIN(TARGET dialog + TYPE MARIADB_CLIENT_PLUGIN_AUTH + CONFIGURATIONS DYNAMIC STATIC OFF + DEFAULT DYNAMIC + SOURCES ${CC_SOURCE_DIR}/plugins/auth/dialog.c + ${CC_SOURCE_DIR}/libmariadb/get_password.c) + + +# Crypto plugins +IF(CRYPTO_PLUGIN) + + #ED25519 client authentication plugin + SET(REF10_DIR ${CC_SOURCE_DIR}/plugins/auth/ref10) + SET(REF10_SOURCES ${REF10_DIR}/fe_0.c ${REF10_DIR}/fe_isnegative.c ${REF10_DIR}/fe_sub.c ${REF10_DIR}/ge_p1p1_to_p2.c + ${REF10_DIR}/ge_p3_to_cached.c ${REF10_DIR}/open.c ${REF10_DIR}/fe_1.c ${REF10_DIR}/fe_isnonzero.c + ${REF10_DIR}/fe_tobytes.c ${REF10_DIR}/ge_p1p1_to_p3.c ${REF10_DIR}/ge_p3_to_p2.c ${REF10_DIR}/sc_muladd.c + ${REF10_DIR}/fe_add.c ${REF10_DIR}/fe_mul.c ${REF10_DIR}/ge_add.c ${REF10_DIR}/ge_p2_0.c ${REF10_DIR}/ge_precomp_0.c + ${REF10_DIR}/sc_reduce.c ${REF10_DIR}/fe_cmov.c ${REF10_DIR}/fe_neg.c ${REF10_DIR}/ge_double_scalarmult.c + ${REF10_DIR}/ge_p2_dbl.c ${REF10_DIR}/ge_scalarmult_base.c ${REF10_DIR}/sign.c ${REF10_DIR}/fe_copy.c + ${REF10_DIR}/fe_pow22523.c ${REF10_DIR}/ge_frombytes.c ${REF10_DIR}/ge_p3_0.c ${REF10_DIR}/ge_sub.c + ${REF10_DIR}/verify.c ${REF10_DIR}/fe_frombytes.c ${REF10_DIR}/fe_sq2.c ${REF10_DIR}/ge_madd.c + ${REF10_DIR}/ge_p3_dbl.c ${REF10_DIR}/ge_tobytes.c ${REF10_DIR}/fe_invert.c ${REF10_DIR}/fe_sq.c + ${REF10_DIR}/ge_msub.c ${REF10_DIR}/ge_p3_tobytes.c ${REF10_DIR}/keypair.c) + + REGISTER_PLUGIN(TARGET client_ed25519 + TYPE MARIADB_CLIENT_PLUGIN_AUTH + CONFIGURATIONS DYNAMIC STATIC OFF + DEFAULT DYNAMIC + SOURCES ${CC_SOURCE_DIR}/plugins/auth/ed25519.c + ${REF10_SOURCES} + ${CRYPT_SOURCE} + INCLUDES ${REF10_DIR} + LIBRARIES ${CRYPT_LIBS} + COMPILE_OPTIONS -DMYSQL_CLIENT=1) + IF(MSVC) + # Silence conversion (integer truncantion) warnings from reference code + SET_SOURCE_FILES_PROPERTIES(${REF10_SOURCES} PROPERTY COMPILE_FLAGS "-DMYSQL_CLIENT=1 /wd4244 /wd4146") + ENDIF() + + IF(CMAKE_C_COMPILER_ID MATCHES "GNU" AND CMAKE_C_COMPILER_VERSION LESS 11 + AND CMAKE_C_COMPILER_VERSION GREATER 6) + SET_SOURCE_FILES_PROPERTIES(${REF10_SOURCES} PROPERTY COMPILE_FLAGS + -fno-sanitize=shift) + ENDIF() + + # SHA256 caching plugin for MySQL 8.0 connection + REGISTER_PLUGIN(TARGET caching_sha2_password + TYPE MARIADB_CLIENT_PLUGIN_AUTH + CONFIGURATIONS DYNAMIC STATIC OFF + DEFAULT DYNAMIC + SOURCES ${CC_SOURCE_DIR}/plugins/auth/caching_sha2_pw.c + ${CRYPT_SOURCE} + LIBRARIES ${CRYPT_LIBS}) + + IF(WITH_SSL STREQUAL "GNUTLS" AND NOT WIN32) + MESSAGE1(STATUS "sha256_password not supported by GnuTLS due to missing OAEP padding") + ELSE() + REGISTER_PLUGIN(TARGET sha256_password + TYPE MARIADB_CLIENT_PLUGIN_AUTH + CONFIGURATIONS DYNAMIC STATIC OFF + DEFAULT DYNAMIC + SOURCES ${AUTH_DIR}/sha256_pw.c + LIBRARIES ${CRYPT_LIBS}) + ENDIF() +ENDIF() + +#GSSAPI client authentication plugin +IF(NOT WIN32) + INCLUDE(${CC_SOURCE_DIR}/cmake/FindGSSAPI.cmake) + IF(GSSAPI_FOUND) + SET(GSSAPI_SOURCES ${AUTH_DIR}/auth_gssapi_client.c ${AUTH_DIR}/gssapi_client.c ${AUTH_DIR}/gssapi_errmsg.c) + ENDIF() +ELSE() + SET(GSSAPI_LIBS secur32) + SET(GSSAPI_SOURCES ${AUTH_DIR}/auth_gssapi_client.c ${AUTH_DIR}/sspi_client.c ${AUTH_DIR}/sspi_errmsg.c) +ENDIF() +IF(GSSAPI_SOURCES) + REGISTER_PLUGIN(TARGET auth_gssapi_client + TYPE MARIADB_CLIENT_PLUGIN_AUTH + CONFIGURATIONS DYNAMIC STATIC OFF + DEFAULT DYNAMIC + SOURCES ${GSSAPI_SOURCES} + INCLUDES ${CC_SOURCE_DIR}/plugins/auth ${GSSAPI_INCS} + LIBRARIES ${GSSAPI_LIBS}) + IF(CMAKE_C_COMPILER_ID MATCHES "Clang") + SET_SOURCE_FILES_PROPERTIES(${GSSAPI_SOURCES} PROPERTY COMPILE_FLAGS "-Wno-deprecated-declarations") + ENDIF() +ENDIF() + +# old_password plugin +REGISTER_PLUGIN(TARGET mysql_old_password + TYPE MARIADB_CLIENT_PLUGIN_AUTH + CONFIGURATIONS STATIC DYNAMIC OFF + DEFAULT STATIC + SOURCES ${AUTH_DIR}/old_password.c) + +# Cleartext +REGISTER_PLUGIN(TARGET mysql_clear_password + TYPE MARIADB_CLIENT_PLUGIN_AUTH + CONFIGURATIONS DYNAMIC STATIC OFF + DEFAULT DYNAMIC + SOURCES ${AUTH_DIR}/mariadb_cleartext.c) + diff --git a/vendor/MDBC/plugins/auth/auth_gssapi_client.c b/vendor/MDBC/plugins/auth/auth_gssapi_client.c new file mode 100644 index 00000000..6f6c6ceb --- /dev/null +++ b/vendor/MDBC/plugins/auth/auth_gssapi_client.c @@ -0,0 +1,121 @@ +/* Copyright (c) 2015-2016, Shuang Qiu, Robbie Harwood, +Vladislav Vaintroub & MariaDB Corporation + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, +this list of conditions and the following disclaimer in the documentation +and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. +*/ + +/** + @file + + GSSAPI authentication plugin, client side +*/ +#include +#include +#include +#include +#include +#include +#include +#include +#include "common.h" + +extern int auth_client(char *principal_name, + char *mech, + MYSQL *mysql, + MYSQL_PLUGIN_VIO *vio); + +static void parse_server_packet(char *packet, size_t packet_len, char *spn, char *mech) +{ + size_t spn_len; + spn_len = strnlen(packet, packet_len); + strncpy(spn, packet, PRINCIPAL_NAME_MAX); + if (spn_len == packet_len - 1) + { + /* Mechanism not included into packet */ + *mech = 0; + } + else + { + strncpy(mech, packet + spn_len + 1, MECH_NAME_MAX); + } +} + +/** + Set client error message. + */ +void log_client_error(MYSQL *mysql, const char *format, ...) +{ + NET *net= &mysql->net; + va_list args; + + net->last_errno= ER_UNKNOWN_ERROR; + va_start(args, format); + vsnprintf(net->last_error, sizeof(net->last_error) - 1, + format, args); + va_end(args); + memcpy(net->sqlstate, "HY000", sizeof(net->sqlstate)); +} + +/** + The main client function of the GSSAPI plugin. + */ +static int gssapi_auth_client(MYSQL_PLUGIN_VIO *vio, MYSQL *mysql) +{ + int packet_len; + unsigned char *packet; + char spn[PRINCIPAL_NAME_MAX + 1]; + char mech[MECH_NAME_MAX + 1]; + + /* read from server for service principal name */ + packet_len= vio->read_packet(vio, &packet); + if (packet_len < 0) + { + return CR_ERROR; + } + parse_server_packet((char *)packet, (size_t)packet_len, spn, mech); + return auth_client(spn, mech, mysql, vio); +} + + +/* register client plugin */ +#ifndef PLUGIN_DYNAMIC +struct st_mysql_client_plugin_AUTHENTICATION auth_gssapi_client_client_plugin= +#else +struct st_mysql_client_plugin_AUTHENTICATION _mysql_client_plugin_declaration_ = +#endif +{ + MYSQL_CLIENT_AUTHENTICATION_PLUGIN, + MYSQL_CLIENT_AUTHENTICATION_PLUGIN_INTERFACE_VERSION, + "auth_gssapi_client", + "Shuang Qiu, Robbie Harwood, Vladislav Vaintroub, Georg Richter", + "GSSAPI/SSPI based authentication", + {0, 1, 0}, + "BSD", + NULL, + NULL, + NULL, + NULL, + gssapi_auth_client +}; diff --git a/vendor/MDBC/plugins/auth/caching_sha2_pw.c b/vendor/MDBC/plugins/auth/caching_sha2_pw.c new file mode 100644 index 00000000..73a92282 --- /dev/null +++ b/vendor/MDBC/plugins/auth/caching_sha2_pw.c @@ -0,0 +1,486 @@ +/************************************************************************************ + Copyright (C) 2017 MariaDB Corporation AB + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not see + or write to the Free Software Foundation, Inc., + 51 Franklin St., Fifth Floor, Boston, MA 02110, USA + *************************************************************************************/ +#ifndef _WIN32 +#define _GNU_SOURCE 1 +#endif + +#ifdef _WIN32 +#define HAVE_WINCRYPT +#undef HAVE_OPENSSL +#undef HAVE_GNUTLS +#endif + +#if defined(HAVE_OPENSSL) || defined(HAVE_WINCRYPT) || defined(HAVE_GNUTLS) + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifndef WIN32 +#include +#endif + +#if defined(HAVE_OPENSSL) +#include +#include +#include +#elif defined(HAVE_GNUTLS) +#include +#elif defined(HAVE_WINCRYPT) +#include +#include +#include + +extern BCRYPT_ALG_HANDLE RsaProv; +extern BCRYPT_ALG_HANDLE Sha256Prov; +#endif + +#include + +#define MAX_PW_LEN 1024 + +#define REQUEST_PUBLIC_KEY 2 +#define CACHED_LOGIN_SUCCEEDED 3 +#define RSA_LOGIN_REQUIRED 4 + +/* MySQL server allows requesting public key only for non secure connections. + secure connections are: + - TLS/SSL connections + - unix_socket connections +*/ +static unsigned char is_connection_secure(MYSQL *mysql) +{ + if (mysql->options.use_ssl || + mysql->net.pvio->type != PVIO_TYPE_SOCKET) + return 1; + return 0; +} + +static int ma_sha256_scramble(unsigned char *scramble, size_t scramble_len, + unsigned char *source, size_t source_len, + unsigned char *salt, size_t salt_len) +{ + unsigned char digest1[MA_SHA256_HASH_SIZE], + digest2[MA_SHA256_HASH_SIZE], + new_scramble[MA_SHA256_HASH_SIZE]; +#ifdef HAVE_WINCRYPT + MA_HASH_CTX myctx; + MA_HASH_CTX *ctx= &myctx; +#else + MA_HASH_CTX *ctx = NULL; +#endif + size_t i; + + /* check if all specified lengtht are valid */ + if (!scramble_len || !source_len || !salt_len) + return 1; + + + /* Step1: create sha256 from source */ + if (!(ctx= ma_hash_new(MA_HASH_SHA256, ctx))) + return 1; + ma_hash_input(ctx, source, source_len); + ma_hash_result(ctx, digest1); + ma_hash_free(ctx); +#ifndef HAVE_WINCRYPT + ctx = NULL; +#endif + + /* Step2: create sha256 digest from digest1 */ + if (!(ctx= ma_hash_new(MA_HASH_SHA256, ctx))) + return 1; + ma_hash_input(ctx, digest1, MA_SHA256_HASH_SIZE); + ma_hash_result(ctx, digest2); + ma_hash_free(ctx); +#ifndef HAVE_WINCRYPT + ctx = NULL; +#endif + + /* Step3: create sha256 digest from digest2 + salt */ + if (!(ctx= ma_hash_new(MA_HASH_SHA256, ctx))) + return 1; + ma_hash_input(ctx, digest2, MA_SHA256_HASH_SIZE); + ma_hash_input(ctx, salt, salt_len); + ma_hash_result(ctx, new_scramble); + ma_hash_free(ctx); + + /* Step4: xor(digest1, scramble1) */ + for (i= 0; i < scramble_len; i++) + scramble[i]= digest1[i] ^ new_scramble[i]; + return 0; +} + +/* function prototypes */ +static int auth_caching_sha2_client(MYSQL_PLUGIN_VIO *vio, MYSQL *mysql); +static int auth_caching_sha2_deinit(void); +static int auth_caching_sha2_init(char *unused1, + size_t unused2, + int unused3, + va_list); + + +#ifndef PLUGIN_DYNAMIC +struct st_mysql_client_plugin_AUTHENTICATION caching_sha2_password_client_plugin= +#else +struct st_mysql_client_plugin_AUTHENTICATION _mysql_client_plugin_declaration_ = +#endif +{ + MYSQL_CLIENT_AUTHENTICATION_PLUGIN, + MYSQL_CLIENT_AUTHENTICATION_PLUGIN_INTERFACE_VERSION, + "caching_sha2_password", + "Georg Richter", + "Caching SHA2 Authentication Plugin", + {0,1,0}, + "LGPL", + NULL, + auth_caching_sha2_init, + auth_caching_sha2_deinit, + NULL, + auth_caching_sha2_client +}; + +#ifdef HAVE_WINCRYPT +static LPBYTE ma_load_pem(const char *buffer, DWORD *buffer_len) +{ + LPBYTE der_buffer= NULL; + DWORD der_buffer_length= 0; + + if (buffer_len == NULL || *buffer_len == 0) + return NULL; + /* calculate the length of DER binary */ + if (!CryptStringToBinaryA(buffer, *buffer_len, CRYPT_STRING_BASE64HEADER, + NULL, &der_buffer_length, NULL, NULL)) + goto end; + /* allocate DER binary buffer */ + if (!(der_buffer= (LPBYTE)malloc(der_buffer_length))) + goto end; + /* convert to DER binary */ + if (!CryptStringToBinaryA(buffer, *buffer_len, CRYPT_STRING_BASE64HEADER, + der_buffer, &der_buffer_length, NULL, NULL)) + goto end; + + *buffer_len= der_buffer_length; + + return der_buffer; + +end: + if (der_buffer) + free(der_buffer); + *buffer_len= 0; + return NULL; +} +#endif + +#ifndef HAVE_GNUTLS +static char *load_pub_key_file(const char *filename, int *pub_key_size) +{ + FILE *fp= NULL; + char *buffer= NULL; + unsigned char error= 1; + + if (!pub_key_size) + return NULL; + + if (!(fp= fopen(filename, "r"))) + goto end; + + if (fseek(fp, 0, SEEK_END)) + goto end; + + if ((*pub_key_size= ftell(fp)) < 0) + goto end; + + rewind(fp); + + if (!(buffer= malloc(*pub_key_size + 1))) + goto end; + + if (fread(buffer, *pub_key_size, 1, fp) != (size_t)*pub_key_size) + goto end; + + error= 0; + +end: + if (fp) + fclose(fp); + if (error && buffer) + { + free(buffer); + buffer= NULL; + } + return buffer; +} +#endif + +static int auth_caching_sha2_client(MYSQL_PLUGIN_VIO *vio, MYSQL *mysql) +{ + unsigned char *packet; + int packet_length; + int rc= CR_ERROR; +#if !defined(HAVE_GNUTLS) + char passwd[MAX_PW_LEN]; +#ifdef HAVE_OPENSSL + unsigned char *rsa_enc_pw= NULL; + size_t rsa_size; +#else + unsigned char rsa_enc_pw[MAX_PW_LEN]; + ULONG rsa_size; +#endif + unsigned int pwlen, i; + char *filebuffer= NULL; +#endif + unsigned char buf[MA_SHA256_HASH_SIZE]; + +#if defined(HAVE_OPENSSL) + EVP_PKEY *pubkey= NULL; + EVP_PKEY_CTX *ctx= NULL; + BIO *bio; + size_t outlen; +#elif defined(HAVE_WINCRYPT) + BCRYPT_KEY_HANDLE pubkey= 0; + BCRYPT_OAEP_PADDING_INFO paddingInfo; + LPBYTE der_buffer= NULL; + DWORD der_buffer_len= 0; + CERT_PUBLIC_KEY_INFO *publicKeyInfo= NULL; + DWORD publicKeyInfoLen; +#endif + + /* read error */ + if ((packet_length= vio->read_packet(vio, &packet)) < 0) + return CR_ERROR; + + if (packet_length != SCRAMBLE_LENGTH + 1) + return CR_SERVER_HANDSHAKE_ERR; + + memmove(mysql->scramble_buff, packet, SCRAMBLE_LENGTH); + mysql->scramble_buff[SCRAMBLE_LENGTH]= 0; + + /* send empty packet if no password was provided */ + if (!mysql->passwd || !mysql->passwd[0]) + { + if (vio->write_packet(vio, 0, 0)) + return CR_ERROR; + return CR_OK; + } + + /* This is the normal authentication, if the host/user key is already in server + cache. In case authentication will fail, we will not return an error but will + try to connect via RSA encryption. + */ + if (ma_sha256_scramble(buf, MA_SHA256_HASH_SIZE, + (unsigned char *)mysql->passwd, strlen(mysql->passwd), + (unsigned char *)mysql->scramble_buff, SCRAMBLE_LENGTH)) + return CR_ERROR; + + if (vio->write_packet(vio, buf, MA_SHA256_HASH_SIZE)) + return CR_ERROR; + if ((packet_length=vio->read_packet(vio, &packet)) == -1) + return CR_ERROR; + if (packet_length == 1) + { + switch (*packet) { + case CACHED_LOGIN_SUCCEEDED: + return CR_OK; + case RSA_LOGIN_REQUIRED: + break; + default: + return CR_ERROR; + } + } + + if (!is_connection_secure(mysql)) + { +#if defined(HAVE_GNUTLS) + mysql->methods->set_error(mysql, CR_AUTH_PLUGIN_ERR, "HY000", + "RSA Encryption not supported - caching_sha2_password plugin was built with GnuTLS support"); + return CR_ERROR; +#else + /* read public key file (if specified) */ + if (mysql->options.extension && + mysql->options.extension->server_public_key) + { + filebuffer= load_pub_key_file(mysql->options.extension->server_public_key, + &packet_length); + } + + /* if no public key file was specified or if we couldn't read the file, + we ask server to send public key */ + if (!filebuffer) + { + unsigned char request= REQUEST_PUBLIC_KEY; + if (vio->write_packet(vio, &request, 1) || + (packet_length=vio->read_packet(vio, &packet)) == -1) + { + mysql->methods->set_error(mysql, CR_AUTH_PLUGIN_ERR, "HY000", "Couldn't read RSA public key from server"); + return CR_ERROR; + } + } +#if defined(HAVE_OPENSSL) + bio= BIO_new_mem_buf(filebuffer ? (unsigned char *)filebuffer : packet, + packet_length); + if ((pubkey= PEM_read_bio_PUBKEY(bio, NULL, NULL, NULL))) + { + if (!(ctx= EVP_PKEY_CTX_new(pubkey, NULL))) + goto error; + if (EVP_PKEY_encrypt_init(ctx) <= 0) + goto error; + if (EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_OAEP_PADDING) <= 0) + goto error; + rsa_size= EVP_PKEY_size(pubkey); + } + BIO_free(bio); + bio= NULL; + ERR_clear_error(); +#elif defined(HAVE_WINCRYPT) + der_buffer_len= packet_length; + /* Load pem and convert it to binary object. New length will be returned + in der_buffer_len */ + if (!(der_buffer= ma_load_pem(filebuffer ? filebuffer : (char *)packet, &der_buffer_len))) + goto error; + + /* Create context and load public key */ + if (!CryptDecodeObjectEx(X509_ASN_ENCODING, X509_PUBLIC_KEY_INFO, + der_buffer, der_buffer_len, + CRYPT_DECODE_ALLOC_FLAG, NULL, + &publicKeyInfo, &publicKeyInfoLen)) + goto error; + free(der_buffer); + + /* Import public key as cng key */ + if (!CryptImportPublicKeyInfoEx2(X509_ASN_ENCODING, publicKeyInfo, + CRYPT_OID_INFO_PUBKEY_ENCRYPT_KEY_FLAG, + NULL, &pubkey)) + goto error; + +#endif + if (!pubkey) + return CR_ERROR; + + pwlen= (unsigned int)strlen(mysql->passwd) + 1; /* include terminating zero */ + if (pwlen > MAX_PW_LEN) + goto error; + memcpy(passwd, mysql->passwd, pwlen); + + /* xor password with scramble */ + for (i=0; i < pwlen; i++) + passwd[i]^= *(mysql->scramble_buff + i % SCRAMBLE_LENGTH); + + /* encrypt scrambled password */ +#if defined(HAVE_OPENSSL) + if (EVP_PKEY_encrypt(ctx, NULL, &outlen, (unsigned char *)passwd, pwlen) <= 0) + goto error; + if (!(rsa_enc_pw= malloc(outlen))) + goto error; + if (EVP_PKEY_encrypt(ctx, rsa_enc_pw, &outlen, (unsigned char *)passwd, pwlen) <= 0) + goto error; +#elif defined(HAVE_WINCRYPT) + ZeroMemory(&paddingInfo, sizeof(paddingInfo)); + paddingInfo.pszAlgId = BCRYPT_SHA1_ALGORITHM; + if ((rc= BCryptEncrypt(pubkey, (PUCHAR)passwd, pwlen, &paddingInfo, NULL, 0, rsa_enc_pw, + MAX_PW_LEN, &rsa_size, BCRYPT_PAD_OAEP))) + goto error; + +#endif + if (vio->write_packet(vio, rsa_enc_pw, rsa_size)) + goto error; + + rc= CR_OK; +#endif + } + else + { + if (vio->write_packet(vio, (unsigned char *)mysql->passwd, (int)strlen(mysql->passwd) + 1)) + return CR_ERROR; + return CR_OK; + } +#if !defined(HAVE_GNUTLS) +error: +#if defined(HAVE_OPENSSL) + if (pubkey) + EVP_PKEY_free(pubkey); + if (rsa_enc_pw) + free(rsa_enc_pw); + if (bio) + BIO_free(bio); + if (ctx) + EVP_PKEY_CTX_free(ctx); +#elif defined(HAVE_WINCRYPT) + if (pubkey) + BCryptDestroyKey(pubkey); + if (publicKeyInfo) + LocalFree(publicKeyInfo); +#endif + free(filebuffer); +#endif + return rc; +} +/* }}} */ + +/* {{{ static int auth_caching_sha2_init */ +/* + Initialization routine + + SYNOPSIS + auth_sha256_init + unused1 + unused2 + unused3 + unused4 + + DESCRIPTION + Init function checks if the caller provides own dialog function. + The function name must be mariadb_auth_dialog or + mysql_authentication_dialog_ask. If the function cannot be found, + we will use owr own simple command line input. + + RETURN + 0 success + */ +static int auth_caching_sha2_init(char *unused1 __attribute__((unused)), + size_t unused2 __attribute__((unused)), + int unused3 __attribute__((unused)), + va_list unused4 __attribute__((unused))) +{ +#if defined(HAVE_WINCRYPT) + BCryptOpenAlgorithmProvider(&Sha256Prov, BCRYPT_SHA256_ALGORITHM, NULL, 0); + BCryptOpenAlgorithmProvider(&RsaProv, BCRYPT_RSA_ALGORITHM, NULL, 0); +#endif + return 0; +} +/* }}} */ + +/* {{{ auth_caching_sha2_deinit */ +static int auth_caching_sha2_deinit(void) +{ +#if defined(HAVE_WINCRYPT) + BCryptCloseAlgorithmProvider(Sha256Prov, 0); + BCryptCloseAlgorithmProvider(RsaProv, 0); +#endif + return 0; +} +/* }}} */ + +#endif /* defined(HAVE_OPENSSL) || defined(HAVE_WINCRYPT) || defined(HAVE_GNUTLS)*/ + diff --git a/vendor/MDBC/plugins/auth/common.h b/vendor/MDBC/plugins/auth/common.h new file mode 100644 index 00000000..c04241ac --- /dev/null +++ b/vendor/MDBC/plugins/auth/common.h @@ -0,0 +1,4 @@ +/** Maximal length of the target name */ +#define PRINCIPAL_NAME_MAX 256 +/** Maximal length of the mech string */ +#define MECH_NAME_MAX 30 diff --git a/vendor/MDBC/plugins/auth/dialog.c b/vendor/MDBC/plugins/auth/dialog.c new file mode 100644 index 00000000..31d7b7d8 --- /dev/null +++ b/vendor/MDBC/plugins/auth/dialog.c @@ -0,0 +1,222 @@ +/************************************************************************************ + Copyright (C) 2014-2018 MariaDB Corporation AB + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not see + or write to the Free Software Foundation, Inc., + 51 Franklin St., Fifth Floor, Boston, MA 02110, USA +*************************************************************************************/ +#ifndef _WIN32 +#define _GNU_SOURCE 1 +#endif + +#include +#include +#include +#include +#include + +#ifndef WIN32 +#include +#endif + + +/* function prototypes */ +extern char *get_tty_password(char *opt_message, char *buff, int bufflen); +static int auth_dialog_open(MYSQL_PLUGIN_VIO *vio, MYSQL *mysql); +static int auth_dialog_init(char *unused1, + size_t unused2, + int unused3, + va_list); + +mysql_authentication_dialog_ask_t auth_dialog_func; + +#ifndef PLUGIN_DYNAMIC +struct st_mysql_client_plugin_AUTHENTICATION dialog_client_plugin= +#else +struct st_mysql_client_plugin_AUTHENTICATION _mysql_client_plugin_declaration_ = +#endif +{ + MYSQL_CLIENT_AUTHENTICATION_PLUGIN, + MYSQL_CLIENT_AUTHENTICATION_PLUGIN_INTERFACE_VERSION, + "dialog", + "Sergei Golubchik, Georg Richter", + "Dialog Client Authentication Plugin", + {0,1,0}, + "LGPL", + NULL, + auth_dialog_init, + NULL, + NULL, + auth_dialog_open +}; + + +/* {{{ static char *auth_dialog_native_prompt */ +/* + Native dialog prompt via stdin + + SYNOPSIS + auth_dialog_native_prompt + mysql connection handle + type input type + prompt prompt + buffer Input buffer + buffer_len Input buffer length + + DESCRIPTION + + RETURNS + Input buffer +*/ +static char *auth_dialog_native_prompt(MYSQL *mysql __attribute__((unused)), + int type, + const char *prompt, + char *buffer, + int buffer_len) +{ + /* display prompt */ + fprintf(stdout, "%s", prompt); + + memset(buffer, 0, buffer_len); + + /* for type 2 (password) don't display input */ + if (type != 2) + { + if (fgets(buffer, buffer_len - 1, stdin)) + { + /* remove trailing line break */ + size_t length= strlen(buffer); + if (length && buffer[length - 1] == '\n') + buffer[length - 1]= 0; + } + } + else + { + get_tty_password((char *)"", buffer, buffer_len - 1); + } + return buffer; +} +/* }}} */ + +/* {{{ static int auth_dialog_open */ +/* + opens dialog + + SYNOPSIS + vio Vio + mysql connection handle + + DESCRIPTION + reads prompt from server, waits for input and sends + input to server. + Note that first byte of prompt indicates if we have a + password which should not be echoed to stdout. + + RETURN + CR_ERROR if an error occurs + CR_OK + CR_OK_HANDSHAKE_COMPLETE +*/ +static int auth_dialog_open(MYSQL_PLUGIN_VIO *vio, MYSQL *mysql) +{ + uchar *packet; + uchar type= 0; + char dialog_buffer[1024]; + char *response; + int packet_length; + my_bool first_loop= TRUE; + + do { + if ((packet_length= vio->read_packet(vio, &packet)) == -1) + /* read error */ + return CR_ERROR; + + if (packet_length > 0) + { + type= *packet; + packet++; + + /* check for protocol packet */ + if (!type || type == 254) + return CR_OK_HANDSHAKE_COMPLETE; + + if ((type >> 1) == 2 && + first_loop && + mysql->passwd && mysql->passwd[0]) + response= mysql->passwd; + else + response= auth_dialog_func(mysql, type >> 1, + (const char *)packet, + dialog_buffer, 1024); + } + else + { + /* in case mysql_change_user was called the client needs + to send packet first */ + response= mysql->passwd; + } + if (!response || + vio->write_packet(vio, (uchar *)response, (int)strlen(response) + 1)) + return CR_ERROR; + + first_loop= FALSE; + + } while((type & 1) != 1); + return CR_OK; +} +/* }}} */ + +/* {{{ static int auth_dialog_init */ +/* + Initialization routine + + SYNOPSIS + auth_dialog_init + unused1 + unused2 + unused3 + unused4 + + DESCRIPTION + Init function checks if the caller provides own dialog function. + The function name must be mariadb_auth_dialog or + mysql_authentication_dialog_ask. If the function cannot be found, + we will use owr own simple command line input. + + RETURN + 0 success +*/ +static int auth_dialog_init(char *unused1 __attribute__((unused)), + size_t unused2 __attribute__((unused)), + int unused3 __attribute__((unused)), + va_list unused4 __attribute__((unused))) +{ + void *func; +#ifdef WIN32 + if (!(func= GetProcAddress(GetModuleHandle(NULL), "mariadb_auth_dialog"))) + /* for MySQL users */ + func= GetProcAddress(GetModuleHandle(NULL), "mysql_authentication_dialog_ask"); +#else + if (!(func= dlsym(RTLD_DEFAULT, "mariadb_auth_dialog"))) + /* for MySQL users */ + func= dlsym(RTLD_DEFAULT, "mysql_authentication_dialog_ask"); +#endif + if (func) + auth_dialog_func= (mysql_authentication_dialog_ask_t)func; + else + auth_dialog_func= auth_dialog_native_prompt; + + return 0; +} +/* }}} */ diff --git a/vendor/MDBC/plugins/auth/ed25519.c b/vendor/MDBC/plugins/auth/ed25519.c new file mode 100644 index 00000000..918b8bad --- /dev/null +++ b/vendor/MDBC/plugins/auth/ed25519.c @@ -0,0 +1,145 @@ +/************************************************************************************ + Copyright (C) 2017-2019 MariaDB Corporation AB + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not see + or write to the Free Software Foundation, Inc., + 51 Franklin St., Fifth Floor, Boston, MA 02110, USA + *************************************************************************************/ +#ifndef _WIN32 +#define _GNU_SOURCE 1 +#endif + +#ifdef _WIN32 +#define HAVE_WINCRYPT +#undef HAVE_OPENSSL +#undef HAVE_GNUTLS +#endif + +#if defined(HAVE_OPENSSL) || defined(HAVE_WINCRYPT) || defined(HAVE_GNUTLS) + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifndef WIN32 +#include +#endif + +#if defined(HAVE_WINCRYPT) +#include +#include +#include +extern BCRYPT_ALG_HANDLE Sha512Prov; +#elif defined(HAVE_OPENSSL) +#include +#include +#include +#elif defined(HAVE_GNUTLS) +#include +#endif + +#include +#include +#include + +/* function prototypes */ +static int auth_ed25519_client(MYSQL_PLUGIN_VIO *vio, MYSQL *mysql); +static int auth_ed25519_deinit(void); +static int auth_ed25519_init(char *unused1, + size_t unused2, + int unused3, + va_list); + + +#ifndef PLUGIN_DYNAMIC +struct st_mysql_client_plugin_AUTHENTICATION client_ed25519_client_plugin= +#else +struct st_mysql_client_plugin_AUTHENTICATION _mysql_client_plugin_declaration_ = +#endif +{ + MYSQL_CLIENT_AUTHENTICATION_PLUGIN, + MYSQL_CLIENT_AUTHENTICATION_PLUGIN_INTERFACE_VERSION, + "client_ed25519", + "Sergei Golubchik, Georg Richter", + "Ed25519 Authentication Plugin", + {0,1,0}, + "LGPL", + NULL, + auth_ed25519_init, + auth_ed25519_deinit, + NULL, + auth_ed25519_client +}; + + +static int auth_ed25519_client(MYSQL_PLUGIN_VIO *vio, MYSQL *mysql) +{ + unsigned char *packet, + signature[CRYPTO_BYTES + NONCE_BYTES]; + int pkt_len; + + /* + Step 1: Server sends nonce + Step 2: check that packet length is equal to NONCE_BYTES (=32) + Step 3: Sign the nonce with password + Steo 4: Send the signature back to server + */ + + /* read and check nonce */ + pkt_len= vio->read_packet(vio, &packet); + if (pkt_len != NONCE_BYTES) + return CR_SERVER_HANDSHAKE_ERR; + + /* Sign nonce: the crypto_sign function is part of ref10 */ + ma_crypto_sign(signature, packet, NONCE_BYTES, (unsigned char*)mysql->passwd, strlen(mysql->passwd)); + + /* send signature to server */ + if (vio->write_packet(vio, signature, CRYPTO_BYTES)) + return CR_ERROR; + + return CR_OK; +} +/* }}} */ + +/* {{{ static int auth_ed25519_init */ +static int auth_ed25519_init(char *unused1 __attribute__((unused)), + size_t unused2 __attribute__((unused)), + int unused3 __attribute__((unused)), + va_list unused4 __attribute__((unused))) +{ +#if defined(HAVE_WINCRYPT) + BCryptOpenAlgorithmProvider(&Sha512Prov, BCRYPT_SHA512_ALGORITHM, NULL, 0); +#endif + return 0; +} +/* }}} */ + +/* {{{ auth_ed25519_deinit */ +static int auth_ed25519_deinit(void) +{ +#if defined(HAVE_WINCRYPT) + BCryptCloseAlgorithmProvider(Sha512Prov, 0); +#endif + return 0; +} +/* }}} */ + +#endif /* defined(HAVE_OPENSSL) || defined(HAVE_WINCRYPT) || defined(HAVE_GNUTLS)*/ + diff --git a/vendor/MDBC/plugins/auth/gssapi_client.c b/vendor/MDBC/plugins/auth/gssapi_client.c new file mode 100644 index 00000000..b4e3e89d --- /dev/null +++ b/vendor/MDBC/plugins/auth/gssapi_client.c @@ -0,0 +1,131 @@ +/* Copyright (c) 2015, Shuang Qiu, Robbie Harwood, +Vladislav Vaintroub & MariaDB Corporation + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, +this list of conditions and the following disclaimer in the documentation +and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. +*/ + +#if defined(__FreeBSD__) || defined(SOLARIS) || defined(__sun) +#include +#else +#include +#endif +#include +#include +#include +#include +#include +#include "gssapi_errmsg.h" + +extern void log_client_error(MYSQL *mysql,const char *fmt,...); + + +/* This sends the error to the client */ +static void log_error(MYSQL *mysql, OM_uint32 major, OM_uint32 minor, const char *msg) +{ + if (GSS_ERROR(major)) + { + char sysmsg[1024]; + gssapi_errmsg(major, minor, sysmsg, sizeof(sysmsg)); + log_client_error(mysql, + "Client GSSAPI error (major %u, minor %u) : %s - %s", + major, minor, msg, sysmsg); + } + else + { + log_client_error(mysql, "Client GSSAPI error : %s", msg); + } +} + +int auth_client(char *principal_name, char *mech __attribute__((unused)), + MYSQL *mysql, MYSQL_PLUGIN_VIO *vio) +{ + gss_buffer_desc input= {0,0}; + int ret= CR_ERROR; + OM_uint32 major= 0, minor= 0; + gss_ctx_id_t ctxt= GSS_C_NO_CONTEXT; + gss_name_t service_name= GSS_C_NO_NAME; + + if (principal_name && principal_name[0]) + { + /* import principal from plain text */ + gss_buffer_desc principal_name_buf; + principal_name_buf.length= strlen(principal_name); + principal_name_buf.value= (void *) principal_name; + major= gss_import_name(&minor, &principal_name_buf, GSS_C_NT_USER_NAME, &service_name); + if (GSS_ERROR(major)) + { + log_error(mysql, major, minor, "gss_import_name"); + return CR_ERROR; + } + } + + do + { + gss_buffer_desc output= {0,0}; + major= gss_init_sec_context(&minor, GSS_C_NO_CREDENTIAL, &ctxt, service_name, + GSS_C_NO_OID, 0, 0, GSS_C_NO_CHANNEL_BINDINGS, + &input, NULL, &output, NULL, NULL); + if (output.length) + { + /* send credential */ + if(vio->write_packet(vio, (unsigned char *)output.value, output.length)) + { + /* Server error packet contains detailed message. */ + ret= CR_OK_HANDSHAKE_COMPLETE; + gss_release_buffer (&minor, &output); + goto cleanup; + } + } + gss_release_buffer (&minor, &output); + + if (GSS_ERROR(major)) + { + log_error(mysql, major, minor,"gss_init_sec_context"); + goto cleanup; + } + + if (major & GSS_S_CONTINUE_NEEDED) + { + int len= vio->read_packet(vio, (unsigned char **) &input.value); + if (len <= 0) + { + /* Server error packet contains detailed message. */ + ret= CR_OK_HANDSHAKE_COMPLETE; + goto cleanup; + } + input.length= len; + } + } while (major & GSS_S_CONTINUE_NEEDED); + + ret= CR_OK; + +cleanup: + if (service_name != GSS_C_NO_NAME) + gss_release_name(&minor, &service_name); + if (ctxt != GSS_C_NO_CONTEXT) + gss_delete_sec_context(&minor, &ctxt, GSS_C_NO_BUFFER); + + return ret; +} diff --git a/vendor/MDBC/plugins/auth/gssapi_errmsg.c b/vendor/MDBC/plugins/auth/gssapi_errmsg.c new file mode 100644 index 00000000..eb914404 --- /dev/null +++ b/vendor/MDBC/plugins/auth/gssapi_errmsg.c @@ -0,0 +1,79 @@ +/* Copyright (c) 2015, Shuang Qiu, Robbie Harwood, +Vladislav Vaintroub & MariaDB Corporation + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, +this list of conditions and the following disclaimer in the documentation +and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. +*/ + +#if defined(__FreeBSD__) || defined(SOLARIS) || defined(__sun) +#include +#else +#include +#endif +#include +void gssapi_errmsg(OM_uint32 major, OM_uint32 minor, char *buf, size_t size) +{ + OM_uint32 message_context; + OM_uint32 status_code; + OM_uint32 maj_status; + OM_uint32 min_status; + gss_buffer_desc status_string; + char *p= buf; + char *end= buf + size - 1; + int types[] = {GSS_C_GSS_CODE,GSS_C_MECH_CODE}; + int i; + for(i= 0; i < 2;i++) + { + message_context= 0; + status_code= types[i] == GSS_C_GSS_CODE?major:minor; + + if(!status_code) + continue; + do + { + maj_status = gss_display_status( + &min_status, + status_code, + types[i], + GSS_C_NO_OID, + &message_context, + &status_string); + + if(maj_status) + break; + + if(p + status_string.length + 2 < end) + { + memcpy(p,status_string.value, status_string.length); + p += status_string.length; + *p++ = '.'; + *p++ = ' '; + } + + gss_release_buffer(&min_status, &status_string); + } + while (message_context != 0); + } + *p= 0; +} diff --git a/vendor/MDBC/plugins/auth/gssapi_errmsg.h b/vendor/MDBC/plugins/auth/gssapi_errmsg.h new file mode 100644 index 00000000..26db8439 --- /dev/null +++ b/vendor/MDBC/plugins/auth/gssapi_errmsg.h @@ -0,0 +1,29 @@ +/* Copyright (c) 2015, Shuang Qiu, Robbie Harwood, +Vladislav Vaintroub & MariaDB Corporation + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, +this list of conditions and the following disclaimer in the documentation +and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. +*/ + +extern void gssapi_errmsg(OM_uint32 major, OM_uint32 minor, char *buf, size_t size); diff --git a/vendor/MDBC/plugins/auth/mariadb_cleartext.c b/vendor/MDBC/plugins/auth/mariadb_cleartext.c new file mode 100644 index 00000000..b63c1d3b --- /dev/null +++ b/vendor/MDBC/plugins/auth/mariadb_cleartext.c @@ -0,0 +1,76 @@ +/************************************************************************************ + Copyright (C) 2014-2018 MariaDB Corporation AB + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not see + or write to the Free Software Foundation, Inc., + 51 Franklin St., Fifth Floor, Boston, MA 02110, USA +*************************************************************************************/ +#include +#include +#include +#include + +/* clear text plugin submits the password without opening a dialog. + This will be the case if pam-use-cleartext-plugin option is + enabled on server side */ + +/* {{{ auth_send_plain_password() */ +/* + sends an unencrypted password to server + + SYNOPSIS + auth_send_plain_password() + vio pointer to vio structure + mysql connection handle + + DESCRIPTION + sends an unencrypted password (which was specified either in + mysql_real_connect or mysql_change_user) to server. + + RETURN + CR_OK + CR_ERROR if an error occurred +*/ +static int clear_password_auth_client(MYSQL_PLUGIN_VIO *vio, MYSQL *mysql) +{ + if (!vio || !mysql || !mysql->passwd) + return CR_ERROR; + + /* write password including terminating zero character */ + return vio->write_packet(vio, (const unsigned char *) mysql->passwd, (int)strlen(mysql->passwd) + 1) ? + CR_ERROR : CR_OK; +} +/* }}} */ + +#ifndef PLUGIN_DYNAMIC +struct st_mysql_client_plugin_AUTHENTICATION mysql_clear_password_client_plugin= +#else +struct st_mysql_client_plugin_AUTHENTICATION _mysql_client_plugin_declaration_ = +#endif +{ + MYSQL_CLIENT_AUTHENTICATION_PLUGIN, + MYSQL_CLIENT_AUTHENTICATION_PLUGIN_INTERFACE_VERSION, + "mysql_clear_password", + "Georg Richter", + "MariaDB clear password authentication plugin", + {0,1,0}, + "LGPL", + NULL, + NULL, + NULL, + NULL, + clear_password_auth_client +}; + + diff --git a/vendor/MDBC/plugins/auth/my_auth.c b/vendor/MDBC/plugins/auth/my_auth.c new file mode 100644 index 00000000..2fd1ba12 --- /dev/null +++ b/vendor/MDBC/plugins/auth/my_auth.c @@ -0,0 +1,685 @@ +#include +#include +#include +#include +#include +#include + +typedef struct st_mysql_client_plugin_AUTHENTICATION auth_plugin_t; +static int client_mpvio_write_packet(struct st_plugin_vio*, const uchar*, size_t); +static int native_password_auth_client(MYSQL_PLUGIN_VIO *vio, MYSQL *mysql); +static int dummy_fallback_auth_client(MYSQL_PLUGIN_VIO *vio, MYSQL *mysql __attribute__((unused))); +extern void read_user_name(char *name); +extern char *ma_send_connect_attr(MYSQL *mysql, unsigned char *buffer); +extern int ma_read_ok_packet(MYSQL *mysql, uchar *pos, ulong length); +extern unsigned char *mysql_net_store_length(unsigned char *packet, size_t length); + +typedef struct { + int (*read_packet)(struct st_plugin_vio *vio, uchar **buf); + int (*write_packet)(struct st_plugin_vio *vio, const uchar *pkt, size_t pkt_len); + void (*info)(struct st_plugin_vio *vio, struct st_plugin_vio_info *info); + /* -= end of MYSQL_PLUGIN_VIO =- */ + MYSQL *mysql; + auth_plugin_t *plugin; /**< what plugin we're under */ + const char *db; + struct { + uchar *pkt; /**< pointer into NET::buff */ + uint pkt_len; + } cached_server_reply; + uint packets_read, packets_written; /**< counters for send/received packets */ + my_bool mysql_change_user; /**< if it's mysql_change_user() */ + int last_read_packet_len; /**< the length of the last *read* packet */ +} MCPVIO_EXT; +/* +#define compile_time_assert(A) \ +do {\ + typedef char constraint[(A) ? 1 : -1];\ +} while (0); +*/ + +auth_plugin_t mysql_native_password_client_plugin= +{ + MYSQL_CLIENT_AUTHENTICATION_PLUGIN, + MYSQL_CLIENT_AUTHENTICATION_PLUGIN_INTERFACE_VERSION, + native_password_plugin_name, + "R.J.Silk, Sergei Golubchik", + "Native MySQL authentication", + {1, 0, 0}, + "LGPL", + NULL, + NULL, + NULL, + NULL, + native_password_auth_client +}; + + +static int native_password_auth_client(MYSQL_PLUGIN_VIO *vio, MYSQL *mysql) +{ + int pkt_len; + uchar *pkt; + + if (((MCPVIO_EXT *)vio)->mysql_change_user) + { + /* + in mysql_change_user() the client sends the first packet. + we use the old scramble. + */ + pkt= (uchar*)mysql->scramble_buff; + pkt_len= SCRAMBLE_LENGTH + 1; + } + else + { + /* read the scramble */ + if ((pkt_len= vio->read_packet(vio, &pkt)) < 0) + return CR_ERROR; + + if (pkt_len != SCRAMBLE_LENGTH + 1) + return CR_SERVER_HANDSHAKE_ERR; + + /* save it in MYSQL */ + memmove(mysql->scramble_buff, pkt, SCRAMBLE_LENGTH); + mysql->scramble_buff[SCRAMBLE_LENGTH] = 0; + } + + if (mysql && mysql->passwd[0]) + { + char scrambled[SCRAMBLE_LENGTH + 1]; + ma_scramble_41((uchar *)scrambled, (char*)pkt, mysql->passwd); + if (vio->write_packet(vio, (uchar*)scrambled, SCRAMBLE_LENGTH)) + return CR_ERROR; + } + else + if (vio->write_packet(vio, 0, 0)) /* no password */ + return CR_ERROR; + + return CR_OK; +} + +auth_plugin_t dummy_fallback_client_plugin= +{ + MYSQL_CLIENT_AUTHENTICATION_PLUGIN, + MYSQL_CLIENT_AUTHENTICATION_PLUGIN_INTERFACE_VERSION, + "dummy_fallback_auth", + "Sergei Golubchik", + "Dummy fallback plugin", + {1, 0, 0}, + "LGPL", + NULL, + NULL, + NULL, + NULL, + dummy_fallback_auth_client +}; + + +static int dummy_fallback_auth_client(MYSQL_PLUGIN_VIO *vio, MYSQL *mysql __attribute__((unused))) +{ + char last_error[MYSQL_ERRMSG_SIZE]; + unsigned int i, last_errno= ((MCPVIO_EXT *)vio)->mysql->net.last_errno; + if (last_errno) + { + strncpy(last_error, ((MCPVIO_EXT *)vio)->mysql->net.last_error, + sizeof(last_error) - 1); + last_error[sizeof(last_error) - 1]= 0; + } + + /* safety-wise we only do 10 round-trips */ + for (i=0; i < 10; i++) + { + uchar *pkt; + if (vio->read_packet(vio, &pkt) < 0) + break; + if (vio->write_packet(vio, 0, 0)) + break; + } + if (last_errno) + { + MYSQL *mysql= ((MCPVIO_EXT *)vio)->mysql; + strncpy(mysql->net.last_error, last_error, + sizeof(mysql->net.last_error) - 1); + mysql->net.last_error[sizeof(mysql->net.last_error) - 1]= 0; + } + return CR_ERROR; +} + +static int send_change_user_packet(MCPVIO_EXT *mpvio, + const uchar *data, int data_len) +{ + MYSQL *mysql= mpvio->mysql; + char *buff, *end; + int res= 1; + size_t conn_attr_len= (mysql->options.extension) ? + mysql->options.extension->connect_attrs_len : 0; + + buff= malloc(USERNAME_LENGTH+1 + data_len+1 + NAME_LEN+1 + 2 + NAME_LEN+1 + 9 + conn_attr_len); + + end= ma_strmake(buff, mysql->user, USERNAME_LENGTH) + 1; + + if (!data_len) + *end++= 0; + else + { + if (mysql->client_flag & CLIENT_SECURE_CONNECTION) + { + DBUG_ASSERT(data_len <= 255); + if (data_len > 255) + { + my_set_error(mysql, CR_MALFORMED_PACKET, SQLSTATE_UNKNOWN, 0); + goto error; + } + *end++= data_len; + } + else + { + DBUG_ASSERT(data_len == SCRAMBLE_LENGTH_323 + 1); + DBUG_ASSERT(data[SCRAMBLE_LENGTH_323] == 0); + } + memcpy(end, data, data_len); + end+= data_len; + } + end= ma_strmake(end, mpvio->db ? mpvio->db : "", NAME_LEN) + 1; + + if (mysql->server_capabilities & CLIENT_PROTOCOL_41) + { + int2store(end, (ushort) mysql->charset->nr); + end+= 2; + } + + if (mysql->server_capabilities & CLIENT_PLUGIN_AUTH) + end= ma_strmake(end, mpvio->plugin->name, NAME_LEN) + 1; + + end= ma_send_connect_attr(mysql, (unsigned char *)end); + + res= ma_simple_command(mysql, COM_CHANGE_USER, + buff, (ulong)(end-buff), 1, NULL); + +error: + free(buff); + return res; +} + + + +static int send_client_reply_packet(MCPVIO_EXT *mpvio, + const uchar *data, int data_len) +{ + MYSQL *mysql= mpvio->mysql; + NET *net= &mysql->net; + char *buff, *end; + size_t conn_attr_len= (mysql->options.extension) ? + mysql->options.extension->connect_attrs_len : 0; + + /* see end= buff+32 below, fixed size of the packet is 32 bytes */ + buff= malloc(33 + USERNAME_LENGTH + data_len + NAME_LEN + NAME_LEN + conn_attr_len + 9); + end= buff; + + mysql->client_flag|= mysql->options.client_flag; + mysql->client_flag|= CLIENT_CAPABILITIES; + + if (mysql->client_flag & CLIENT_MULTI_STATEMENTS) + mysql->client_flag|= CLIENT_MULTI_RESULTS; + +#if defined(HAVE_TLS) && !defined(EMBEDDED_LIBRARY) + if (mysql->options.ssl_key || mysql->options.ssl_cert || + mysql->options.ssl_ca || mysql->options.ssl_capath || + mysql->options.ssl_cipher || mysql->options.use_ssl || + (mysql->options.client_flag & CLIENT_SSL_VERIFY_SERVER_CERT)) + mysql->options.use_ssl= 1; + if (mysql->options.use_ssl) + mysql->client_flag|= CLIENT_SSL; +#endif /* HAVE_TLS && !EMBEDDED_LIBRARY*/ + if (mpvio->db) + mysql->client_flag|= CLIENT_CONNECT_WITH_DB; + else + /* See CONC-490: If no database was specified, we need + to unset CLIENT_CONNECT_WITH_DB flag */ + mysql->client_flag&= ~CLIENT_CONNECT_WITH_DB; + + /* if server doesn't support SSL and verification of server certificate + was set to mandatory, we need to return an error */ + if (mysql->options.use_ssl && !(mysql->server_capabilities & CLIENT_SSL)) + { + if ((mysql->client_flag & CLIENT_SSL_VERIFY_SERVER_CERT) || + (mysql->options.extension && (mysql->options.extension->tls_fp || + mysql->options.extension->tls_fp_list))) + { + my_set_error(mysql, CR_SSL_CONNECTION_ERROR, SQLSTATE_UNKNOWN, + ER(CR_SSL_CONNECTION_ERROR), + "SSL is required, but the server does not support it"); + goto error; + } + } + + + /* Remove options that server doesn't support */ + mysql->client_flag= mysql->client_flag & + (~(CLIENT_COMPRESS | CLIENT_SSL | CLIENT_PROTOCOL_41) + | mysql->server_capabilities); + +#ifndef HAVE_COMPRESS + mysql->client_flag&= ~CLIENT_COMPRESS; +#endif + + if (mysql->client_flag & CLIENT_PROTOCOL_41) + { + /* 4.1 server and 4.1 client has a 32 byte option flag */ + if (!(mysql->server_capabilities & CLIENT_MYSQL)) + mysql->client_flag&= ~CLIENT_MYSQL; + int4store(buff,mysql->client_flag); + int4store(buff+4, net->max_packet_size); + buff[8]= (char) mysql->charset->nr; + memset(buff + 9, 0, 32-9); + if (!(mysql->server_capabilities & CLIENT_MYSQL)) + { + uint server_extended_cap= mysql->extension->mariadb_server_capabilities; + uint client_extended_cap= (uint)(MARIADB_CLIENT_SUPPORTED_FLAGS >> 32); + mysql->extension->mariadb_client_flag= + server_extended_cap & client_extended_cap; + int4store(buff + 28, mysql->extension->mariadb_client_flag); + } + end= buff+32; + } + else + { + int2store(buff, mysql->client_flag); + int3store(buff+2, net->max_packet_size); + end= buff+5; + } +#ifdef HAVE_TLS + if (mysql->options.ssl_key || + mysql->options.ssl_cert || + mysql->options.ssl_ca || + mysql->options.ssl_capath || + mysql->options.ssl_cipher +#ifdef CRL_IMPLEMENTED + || (mysql->options.extension && + (mysql->options.extension->ssl_crl || + mysql->options.extension->ssl_crlpath)) +#endif + ) + mysql->options.use_ssl= 1; + if (mysql->options.use_ssl && + (mysql->client_flag & CLIENT_SSL)) + { + /* + Send mysql->client_flag, max_packet_size - unencrypted otherwise + the server does not know we want to do SSL + */ + if (ma_net_write(net, (unsigned char *)buff, (size_t) (end-buff)) || ma_net_flush(net)) + { + my_set_error(mysql, CR_SERVER_LOST, SQLSTATE_UNKNOWN, + ER(CR_SERVER_LOST_EXTENDED), + "sending connection information to server", + errno); + goto error; + } + if (ma_pvio_start_ssl(mysql->net.pvio)) + goto error; + } +#endif /* HAVE_TLS */ + + /* This needs to be changed as it's not useful with big packets */ + if (mysql->user && mysql->user[0]) + ma_strmake(end, mysql->user, USERNAME_LENGTH); + else + read_user_name(end); + + /* We have to handle different version of handshake here */ + end+= strlen(end) + 1; + if (data_len) + { + if (mysql->server_capabilities & CLIENT_SECURE_CONNECTION) + { + if (mysql->server_capabilities & CLIENT_PLUGIN_AUTH_LENENC_CLIENT_DATA) + { + end= (char *)mysql_net_store_length((uchar *)end, data_len); + } + else { + /* Without CLIENT_PLUGIN_AUTH_LENENC_CLIENT_DATA capability password + length is limited up to 255 chars */ + if (data_len > 0xFF) + goto error; + *end++= data_len; + } + memcpy(end, data, data_len); + end+= data_len; + } + else + { + DBUG_ASSERT(data_len == SCRAMBLE_LENGTH_323 + 1); /* incl. \0 at the end */ + memcpy(end, data, data_len); + end+= data_len; + } + } + else + *end++= 0; + + /* Add database if needed */ + if (mpvio->db && (mysql->server_capabilities & CLIENT_CONNECT_WITH_DB)) + { + end= ma_strmake(end, mpvio->db, NAME_LEN) + 1; + mysql->db= strdup(mpvio->db); + } + + if (mysql->server_capabilities & CLIENT_PLUGIN_AUTH) + end= ma_strmake(end, mpvio->plugin->name, NAME_LEN) + 1; + + end= ma_send_connect_attr(mysql, (unsigned char *)end); + + /* Write authentication package */ + if (ma_net_write(net, (unsigned char *)buff, (size_t) (end-buff)) || ma_net_flush(net)) + { + my_set_error(mysql, CR_SERVER_LOST, SQLSTATE_UNKNOWN, + ER(CR_SERVER_LOST_EXTENDED), + "sending authentication information", + errno); + goto error; + } + free(buff); + return 0; + +error: + free(buff); + return 1; +} + +/** + vio->read_packet() callback method for client authentication plugins + + This function is called by a client authentication plugin, when it wants + to read data from the server. +*/ + +static int client_mpvio_read_packet(struct st_plugin_vio *mpv, uchar **buf) +{ + MCPVIO_EXT *mpvio= (MCPVIO_EXT*)mpv; + MYSQL *mysql= mpvio->mysql; + ulong pkt_len; + + /* there are cached data left, feed it to a plugin */ + if (mpvio->cached_server_reply.pkt) + { + *buf= mpvio->cached_server_reply.pkt; + mpvio->cached_server_reply.pkt= 0; + mpvio->packets_read++; + return mpvio->cached_server_reply.pkt_len; + } + + if (mpvio->packets_read == 0) + { + /* + the server handshake packet came from the wrong plugin, + or it's mysql_change_user(). Either way, there is no data + for a plugin to read. send a dummy packet to the server + to initiate a dialog. + */ + if (client_mpvio_write_packet(mpv, 0, 0)) + return (int)packet_error; + } + + /* otherwise read the data */ + if ((pkt_len= ma_net_safe_read(mysql)) == packet_error) + return (int)packet_error; + + mpvio->last_read_packet_len= pkt_len; + *buf= mysql->net.read_pos; + + /* was it a request to change plugins ? */ + if (pkt_len && **buf == 254) + return (int)packet_error; /* if yes, this plugin shan't continue */ + + /* + the server sends \1\255 or \1\254 instead of just \255 or \254 - + for us to not confuse it with an error or "change plugin" packets. + We remove this escaping \1 here. + + See also server_mpvio_write_packet() where the escaping is done. + */ + if (pkt_len && **buf == 1) + { + (*buf)++; + pkt_len--; + } + mpvio->packets_read++; + return pkt_len; +} + +/** + vio->write_packet() callback method for client authentication plugins + + This function is called by a client authentication plugin, when it wants + to send data to the server. + + It transparently wraps the data into a change user or authentication + handshake packet, if necessary. +*/ + +static int client_mpvio_write_packet(struct st_plugin_vio *mpv, + const uchar *pkt, size_t pkt_len) +{ + int res; + MCPVIO_EXT *mpvio= (MCPVIO_EXT*)mpv; + + if (mpvio->packets_written == 0) + { + if (mpvio->mysql_change_user) + res= send_change_user_packet(mpvio, pkt, (int)pkt_len); + else + res= send_client_reply_packet(mpvio, pkt, (int)pkt_len); + } + else + { + NET *net= &mpvio->mysql->net; + if (mpvio->mysql->thd) + res= 1; /* no chit-chat in embedded */ + else + res= ma_net_write(net, (unsigned char *)pkt, pkt_len) || ma_net_flush(net); + } + + if (res) + { + /* don't overwrite errors */ + if (!mysql_errno(mpvio->mysql)) + my_set_error(mpvio->mysql, CR_SERVER_LOST, SQLSTATE_UNKNOWN, + ER(CR_SERVER_LOST_EXTENDED), + "sending authentication information", + errno); + } + mpvio->packets_written++; + return res; +} + +/** + fills MYSQL_PLUGIN_VIO_INFO structure with the information about the + connection +*/ + +void mpvio_info(MARIADB_PVIO *pvio, MYSQL_PLUGIN_VIO_INFO *info) +{ + memset(info, 0, sizeof(*info)); + switch (pvio->type) { + case PVIO_TYPE_SOCKET: + info->protocol= MYSQL_VIO_TCP; + ma_pvio_get_handle(pvio, &info->socket); + return; + case PVIO_TYPE_UNIXSOCKET: + info->protocol= MYSQL_VIO_SOCKET; + ma_pvio_get_handle(pvio, &info->socket); + return; + /* + case VIO_TYPE_SSL: + { + struct sockaddr addr; + SOCKET_SIZE_TYPE addrlen= sizeof(addr); + if (getsockname(vio->sd, &addr, &addrlen)) + return; + info->protocol= addr.sa_family == AF_UNIX ? + MYSQL_VIO_SOCKET : MYSQL_VIO_TCP; + info->socket= vio->sd; + return; + } + */ +#ifdef _WIN32 + /* + case VIO_TYPE_NAMEDPIPE: + info->protocol= MYSQL_VIO_PIPE; + info->handle= vio->hPipe; + return; + */ +/* not supported yet + case VIO_TYPE_SHARED_MEMORY: + info->protocol= MYSQL_VIO_MEMORY; + info->handle= vio->handle_file_map; + return; +*/ +#endif + default: DBUG_ASSERT(0); + } +} + +static void client_mpvio_info(MYSQL_PLUGIN_VIO *vio, + MYSQL_PLUGIN_VIO_INFO *info) +{ + MCPVIO_EXT *mpvio= (MCPVIO_EXT*)vio; + mpvio_info(mpvio->mysql->net.pvio, info); +} + +/** + Client side of the plugin driver authentication. + + @note this is used by both the mysql_real_connect and mysql_change_user + + @param mysql mysql + @param data pointer to the plugin auth data (scramble) in the + handshake packet + @param data_len the length of the data + @param data_plugin a plugin that data were prepared for + or 0 if it's mysql_change_user() + @param db initial db to use, can be 0 + + @retval 0 ok + @retval 1 error +*/ + +int run_plugin_auth(MYSQL *mysql, char *data, uint data_len, + const char *data_plugin, const char *db) +{ + const char *auth_plugin_name= NULL; + auth_plugin_t *auth_plugin; + MCPVIO_EXT mpvio; + ulong pkt_length; + int res; + + /* determine the default/initial plugin to use */ + if (mysql->server_capabilities & CLIENT_PLUGIN_AUTH) + { + if (mysql->options.extension && mysql->options.extension->default_auth) + auth_plugin_name= mysql->options.extension->default_auth; + else if (data_plugin) + auth_plugin_name= data_plugin; + } + if (!auth_plugin_name) + { + if (mysql->server_capabilities & CLIENT_PROTOCOL_41) + auth_plugin_name= native_password_plugin_name; + else + auth_plugin_name= "mysql_old_password"; + } + if (!(auth_plugin= (auth_plugin_t*) mysql_client_find_plugin(mysql, + auth_plugin_name, MYSQL_CLIENT_AUTHENTICATION_PLUGIN))) + auth_plugin= &dummy_fallback_client_plugin; + + mysql->net.last_errno= 0; /* just in case */ + + if (data_plugin && strcmp(data_plugin, auth_plugin_name)) + { + /* data was prepared for a different plugin, so we don't + send any data */ + data= 0; + data_len= 0; + } + + mpvio.mysql_change_user= data_plugin == 0; + mpvio.cached_server_reply.pkt= (uchar*)data; + mpvio.cached_server_reply.pkt_len= data_len; + mpvio.read_packet= client_mpvio_read_packet; + mpvio.write_packet= client_mpvio_write_packet; + mpvio.info= client_mpvio_info; + mpvio.mysql= mysql; + mpvio.packets_read= mpvio.packets_written= 0; + mpvio.db= db; + +retry: + mpvio.plugin= auth_plugin; + + mysql->net.read_pos[0]= 0; + res= auth_plugin->authenticate_user((struct st_plugin_vio *)&mpvio, mysql); + + if ((res == CR_ERROR && !mysql->net.buff) || + (res > CR_OK && mysql->net.read_pos[0] != 254)) + { + /* + the plugin returned an error. write it down in mysql, + unless the error code is CR_ERROR and mysql->net.last_errno + is already set (the plugin has done it) + */ + if (res > CR_ERROR) + my_set_error(mysql, res, SQLSTATE_UNKNOWN, 0); + else + if (!mysql->net.last_errno) { + my_set_error(mysql, CR_UNKNOWN_ERROR, SQLSTATE_UNKNOWN, 0); + } + return 1; + } + + /* read the OK packet (or use the cached value in mysql->net.read_pos */ + if (res == CR_OK) + pkt_length= ma_net_safe_read(mysql); + else /* res == CR_OK_HANDSHAKE_COMPLETE or an error */ + pkt_length= mpvio.last_read_packet_len; + + if (pkt_length == packet_error) + { + if (mysql->net.last_errno == CR_SERVER_LOST) + my_set_error(mysql, CR_SERVER_LOST, SQLSTATE_UNKNOWN, + ER(CR_SERVER_LOST_EXTENDED), + "reading authorization packet", + errno); + return 1; + } + if (mysql->net.read_pos[0] == 254) + { + /* The server asked to use a different authentication plugin */ + if (pkt_length == 1) + { + /* old "use short scramble" packet */ + auth_plugin_name= old_password_plugin_name; + mpvio.cached_server_reply.pkt= (uchar*)mysql->scramble_buff; + mpvio.cached_server_reply.pkt_len= SCRAMBLE_LENGTH + 1; + } + else + { + /* new "use different plugin" packet */ + uint len; + auth_plugin_name= (char*)mysql->net.read_pos + 1; + len= (uint)strlen(auth_plugin_name); /* safe as ma_net_read always appends \0 */ + mpvio.cached_server_reply.pkt_len= pkt_length - len - 2; + mpvio.cached_server_reply.pkt= mysql->net.read_pos + len + 2; + } + if (!(auth_plugin= (auth_plugin_t *) mysql_client_find_plugin(mysql, + auth_plugin_name, MYSQL_CLIENT_AUTHENTICATION_PLUGIN))) + auth_plugin= &dummy_fallback_client_plugin; + + goto retry; + + } + /* + net->read_pos[0] should always be 0 here if the server implements + the protocol correctly + */ + if (mysql->net.read_pos[0] == 0) + return ma_read_ok_packet(mysql, mysql->net.read_pos + 1, pkt_length); + return 1; +} + diff --git a/vendor/MDBC/plugins/auth/old_password.c b/vendor/MDBC/plugins/auth/old_password.c new file mode 100644 index 00000000..07756e92 --- /dev/null +++ b/vendor/MDBC/plugins/auth/old_password.c @@ -0,0 +1,117 @@ +/************************************************************************************ + Copyright (C) 2014,2015,2018 MariaDB Corporation AB + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not see + or write to the Free Software Foundation, Inc., + 51 Franklin St., Fifth Floor, Boston, MA 02110, USA +*************************************************************************************/ +#include +#include +#include +#include +#include +#include + + +/* function prototypes */ +static int auth_old_password(MYSQL_PLUGIN_VIO *vio, MYSQL *mysql); + +typedef struct st_mysql_client_plugin_AUTHENTICATION auth_plugin_t; + +typedef struct { + int (*read_packet)(struct st_plugin_vio *vio, uchar **buf); + int (*write_packet)(struct st_plugin_vio *vio, const uchar *pkt, size_t pkt_len); + void (*info)(struct st_plugin_vio *vio, struct st_plugin_vio_info *info); + /* -= end of MYSQL_PLUGIN_VIO =- */ + MYSQL *mysql; + auth_plugin_t *plugin; /**< what plugin we're under */ + const char *db; + struct { + uchar *pkt; /**< pointer into NET::buff */ + uint pkt_len; + } cached_server_reply; + uint packets_read, packets_written; /**< counters for send/received packets */ + my_bool mysql_change_user; /**< if it's mysql_change_user() */ + int last_read_packet_len; /**< the length of the last *read* packet */ +} MCPVIO_EXT; + +#ifndef PLUGIN_DYNAMIC +struct st_mysql_client_plugin_AUTHENTICATION mysql_old_password_client_plugin= +#else +struct st_mysql_client_plugin_AUTHENTICATION _mysql_client_plugin_declaration_ = +#endif +{ + MYSQL_CLIENT_AUTHENTICATION_PLUGIN, + MYSQL_CLIENT_AUTHENTICATION_PLUGIN_INTERFACE_VERSION, + "mysql_old_password", + "Sergei Golubchik, R.J. Silk, Georg Richter", + "Old (pre 4.1) authentication plugin", + {1,0,0}, + "LGPL", + NULL, + NULL, + NULL, + NULL, + auth_old_password +}; + +/** + client authentication plugin that does old MySQL authentication + using an 8-byte (4.0-) scramble +*/ + +static int auth_old_password(MYSQL_PLUGIN_VIO *vio, MYSQL *mysql) +{ + uchar *pkt; + int pkt_len; + + if (((MCPVIO_EXT *)vio)->mysql_change_user) + { + /* + in mysql_change_user() the client sends the first packet. + we use the old scramble. + */ + pkt= (uchar*)mysql->scramble_buff; + } + else + { + /* read the scramble */ + if ((pkt_len= vio->read_packet(vio, &pkt)) < 0) + return CR_ERROR; + + if (pkt_len != SCRAMBLE_LENGTH_323 + 1 && + pkt_len != SCRAMBLE_LENGTH + 1) + return CR_SERVER_HANDSHAKE_ERR; + + /* save it in MYSQL */ + memmove(mysql->scramble_buff, pkt, pkt_len - 1); + mysql->scramble_buff[pkt_len - 1] = 0; + } + + if (mysql && mysql->passwd[0]) + { + char scrambled[SCRAMBLE_LENGTH_323 + 1]; + ma_scramble_323(scrambled, (char*)pkt, mysql->passwd); + if (vio->write_packet(vio, (uchar*)scrambled, SCRAMBLE_LENGTH_323 + 1)) + return CR_ERROR; + } + else + if (vio->write_packet(vio, 0, 0)) /* no password */ + return CR_ERROR; + + return CR_OK; +} + + + diff --git a/vendor/MDBC/plugins/auth/ref10/api.h b/vendor/MDBC/plugins/auth/ref10/api.h new file mode 100644 index 00000000..9f1db7e5 --- /dev/null +++ b/vendor/MDBC/plugins/auth/ref10/api.h @@ -0,0 +1,3 @@ +#define CRYPTO_PUBLICKEYBYTES 32 +#define CRYPTO_BYTES 64 +#define CRYPTO_DETERMINISTIC 1 diff --git a/vendor/MDBC/plugins/auth/ref10/base.h b/vendor/MDBC/plugins/auth/ref10/base.h new file mode 100644 index 00000000..573bd8a0 --- /dev/null +++ b/vendor/MDBC/plugins/auth/ref10/base.h @@ -0,0 +1,1344 @@ +{ + { + { 25967493,-14356035,29566456,3660896,-12694345,4014787,27544626,-11754271,-6079156,2047605 }, + { -12545711,934262,-2722910,3049990,-727428,9406986,12720692,5043384,19500929,-15469378 }, + { -8738181,4489570,9688441,-14785194,10184609,-12363380,29287919,11864899,-24514362,-4438546 }, + }, + { + { -12815894,-12976347,-21581243,11784320,-25355658,-2750717,-11717903,-3814571,-358445,-10211303 }, + { -21703237,6903825,27185491,6451973,-29577724,-9554005,-15616551,11189268,-26829678,-5319081 }, + { 26966642,11152617,32442495,15396054,14353839,-12752335,-3128826,-9541118,-15472047,-4166697 }, + }, + { + { 15636291,-9688557,24204773,-7912398,616977,-16685262,27787600,-14772189,28944400,-1550024 }, + { 16568933,4717097,-11556148,-1102322,15682896,-11807043,16354577,-11775962,7689662,11199574 }, + { 30464156,-5976125,-11779434,-15670865,23220365,15915852,7512774,10017326,-17749093,-9920357 }, + }, + { + { -17036878,13921892,10945806,-6033431,27105052,-16084379,-28926210,15006023,3284568,-6276540 }, + { 23599295,-8306047,-11193664,-7687416,13236774,10506355,7464579,9656445,13059162,10374397 }, + { 7798556,16710257,3033922,2874086,28997861,2835604,32406664,-3839045,-641708,-101325 }, + }, + { + { 10861363,11473154,27284546,1981175,-30064349,12577861,32867885,14515107,-15438304,10819380 }, + { 4708026,6336745,20377586,9066809,-11272109,6594696,-25653668,12483688,-12668491,5581306 }, + { 19563160,16186464,-29386857,4097519,10237984,-4348115,28542350,13850243,-23678021,-15815942 }, + }, + { + { -15371964,-12862754,32573250,4720197,-26436522,5875511,-19188627,-15224819,-9818940,-12085777 }, + { -8549212,109983,15149363,2178705,22900618,4543417,3044240,-15689887,1762328,14866737 }, + { -18199695,-15951423,-10473290,1707278,-17185920,3916101,-28236412,3959421,27914454,4383652 }, + }, + { + { 5153746,9909285,1723747,-2777874,30523605,5516873,19480852,5230134,-23952439,-15175766 }, + { -30269007,-3463509,7665486,10083793,28475525,1649722,20654025,16520125,30598449,7715701 }, + { 28881845,14381568,9657904,3680757,-20181635,7843316,-31400660,1370708,29794553,-1409300 }, + }, + { + { 14499471,-2729599,-33191113,-4254652,28494862,14271267,30290735,10876454,-33154098,2381726 }, + { -7195431,-2655363,-14730155,462251,-27724326,3941372,-6236617,3696005,-32300832,15351955 }, + { 27431194,8222322,16448760,-3907995,-18707002,11938355,-32961401,-2970515,29551813,10109425 }, + }, +}, +{ + { + { -13657040,-13155431,-31283750,11777098,21447386,6519384,-2378284,-1627556,10092783,-4764171 }, + { 27939166,14210322,4677035,16277044,-22964462,-12398139,-32508754,12005538,-17810127,12803510 }, + { 17228999,-15661624,-1233527,300140,-1224870,-11714777,30364213,-9038194,18016357,4397660 }, + }, + { + { -10958843,-7690207,4776341,-14954238,27850028,-15602212,-26619106,14544525,-17477504,982639 }, + { 29253598,15796703,-2863982,-9908884,10057023,3163536,7332899,-4120128,-21047696,9934963 }, + { 5793303,16271923,-24131614,-10116404,29188560,1206517,-14747930,4559895,-30123922,-10897950 }, + }, + { + { -27643952,-11493006,16282657,-11036493,28414021,-15012264,24191034,4541697,-13338309,5500568 }, + { 12650548,-1497113,9052871,11355358,-17680037,-8400164,-17430592,12264343,10874051,13524335 }, + { 25556948,-3045990,714651,2510400,23394682,-10415330,33119038,5080568,-22528059,5376628 }, + }, + { + { -26088264,-4011052,-17013699,-3537628,-6726793,1920897,-22321305,-9447443,4535768,1569007 }, + { -2255422,14606630,-21692440,-8039818,28430649,8775819,-30494562,3044290,31848280,12543772 }, + { -22028579,2943893,-31857513,6777306,13784462,-4292203,-27377195,-2062731,7718482,14474653 }, + }, + { + { 2385315,2454213,-22631320,46603,-4437935,-15680415,656965,-7236665,24316168,-5253567 }, + { 13741529,10911568,-33233417,-8603737,-20177830,-1033297,33040651,-13424532,-20729456,8321686 }, + { 21060490,-2212744,15712757,-4336099,1639040,10656336,23845965,-11874838,-9984458,608372 }, + }, + { + { -13672732,-15087586,-10889693,-7557059,-6036909,11305547,1123968,-6780577,27229399,23887 }, + { -23244140,-294205,-11744728,14712571,-29465699,-2029617,12797024,-6440308,-1633405,16678954 }, + { -29500620,4770662,-16054387,14001338,7830047,9564805,-1508144,-4795045,-17169265,4904953 }, + }, + { + { 24059557,14617003,19037157,-15039908,19766093,-14906429,5169211,16191880,2128236,-4326833 }, + { -16981152,4124966,-8540610,-10653797,30336522,-14105247,-29806336,916033,-6882542,-2986532 }, + { -22630907,12419372,-7134229,-7473371,-16478904,16739175,285431,2763829,15736322,4143876 }, + }, + { + { 2379352,11839345,-4110402,-5988665,11274298,794957,212801,-14594663,23527084,-16458268 }, + { 33431127,-11130478,-17838966,-15626900,8909499,8376530,-32625340,4087881,-15188911,-14416214 }, + { 1767683,7197987,-13205226,-2022635,-13091350,448826,5799055,4357868,-4774191,-16323038 }, + }, +}, +{ + { + { 6721966,13833823,-23523388,-1551314,26354293,-11863321,23365147,-3949732,7390890,2759800 }, + { 4409041,2052381,23373853,10530217,7676779,-12885954,21302353,-4264057,1244380,-12919645 }, + { -4421239,7169619,4982368,-2957590,30256825,-2777540,14086413,9208236,15886429,16489664 }, + }, + { + { 1996075,10375649,14346367,13311202,-6874135,-16438411,-13693198,398369,-30606455,-712933 }, + { -25307465,9795880,-2777414,14878809,-33531835,14780363,13348553,12076947,-30836462,5113182 }, + { -17770784,11797796,31950843,13929123,-25888302,12288344,-30341101,-7336386,13847711,5387222 }, + }, + { + { -18582163,-3416217,17824843,-2340966,22744343,-10442611,8763061,3617786,-19600662,10370991 }, + { 20246567,-14369378,22358229,-543712,18507283,-10413996,14554437,-8746092,32232924,16763880 }, + { 9648505,10094563,26416693,14745928,-30374318,-6472621,11094161,15689506,3140038,-16510092 }, + }, + { + { -16160072,5472695,31895588,4744994,8823515,10365685,-27224800,9448613,-28774454,366295 }, + { 19153450,11523972,-11096490,-6503142,-24647631,5420647,28344573,8041113,719605,11671788 }, + { 8678025,2694440,-6808014,2517372,4964326,11152271,-15432916,-15266516,27000813,-10195553 }, + }, + { + { -15157904,7134312,8639287,-2814877,-7235688,10421742,564065,5336097,6750977,-14521026 }, + { 11836410,-3979488,26297894,16080799,23455045,15735944,1695823,-8819122,8169720,16220347 }, + { -18115838,8653647,17578566,-6092619,-8025777,-16012763,-11144307,-2627664,-5990708,-14166033 }, + }, + { + { -23308498,-10968312,15213228,-10081214,-30853605,-11050004,27884329,2847284,2655861,1738395 }, + { -27537433,-14253021,-25336301,-8002780,-9370762,8129821,21651608,-3239336,-19087449,-11005278 }, + { 1533110,3437855,23735889,459276,29970501,11335377,26030092,5821408,10478196,8544890 }, + }, + { + { 32173121,-16129311,24896207,3921497,22579056,-3410854,19270449,12217473,17789017,-3395995 }, + { -30552961,-2228401,-15578829,-10147201,13243889,517024,15479401,-3853233,30460520,1052596 }, + { -11614875,13323618,32618793,8175907,-15230173,12596687,27491595,-4612359,3179268,-9478891 }, + }, + { + { 31947069,-14366651,-4640583,-15339921,-15125977,-6039709,-14756777,-16411740,19072640,-9511060 }, + { 11685058,11822410,3158003,-13952594,33402194,-4165066,5977896,-5215017,473099,5040608 }, + { -20290863,8198642,-27410132,11602123,1290375,-2799760,28326862,1721092,-19558642,-3131606 }, + }, +}, +{ + { + { 7881532,10687937,7578723,7738378,-18951012,-2553952,21820786,8076149,-27868496,11538389 }, + { -19935666,3899861,18283497,-6801568,-15728660,-11249211,8754525,7446702,-5676054,5797016 }, + { -11295600,-3793569,-15782110,-7964573,12708869,-8456199,2014099,-9050574,-2369172,-5877341 }, + }, + { + { -22472376,-11568741,-27682020,1146375,18956691,16640559,1192730,-3714199,15123619,10811505 }, + { 14352098,-3419715,-18942044,10822655,32750596,4699007,-70363,15776356,-28886779,-11974553 }, + { -28241164,-8072475,-4978962,-5315317,29416931,1847569,-20654173,-16484855,4714547,-9600655 }, + }, + { + { 15200332,8368572,19679101,15970074,-31872674,1959451,24611599,-4543832,-11745876,12340220 }, + { 12876937,-10480056,33134381,6590940,-6307776,14872440,9613953,8241152,15370987,9608631 }, + { -4143277,-12014408,8446281,-391603,4407738,13629032,-7724868,15866074,-28210621,-8814099 }, + }, + { + { 26660628,-15677655,8393734,358047,-7401291,992988,-23904233,858697,20571223,8420556 }, + { 14620715,13067227,-15447274,8264467,14106269,15080814,33531827,12516406,-21574435,-12476749 }, + { 236881,10476226,57258,-14677024,6472998,2466984,17258519,7256740,8791136,15069930 }, + }, + { + { 1276410,-9371918,22949635,-16322807,-23493039,-5702186,14711875,4874229,-30663140,-2331391 }, + { 5855666,4990204,-13711848,7294284,-7804282,1924647,-1423175,-7912378,-33069337,9234253 }, + { 20590503,-9018988,31529744,-7352666,-2706834,10650548,31559055,-11609587,18979186,13396066 }, + }, + { + { 24474287,4968103,22267082,4407354,24063882,-8325180,-18816887,13594782,33514650,7021958 }, + { -11566906,-6565505,-21365085,15928892,-26158305,4315421,-25948728,-3916677,-21480480,12868082 }, + { -28635013,13504661,19988037,-2132761,21078225,6443208,-21446107,2244500,-12455797,-8089383 }, + }, + { + { -30595528,13793479,-5852820,319136,-25723172,-6263899,33086546,8957937,-15233648,5540521 }, + { -11630176,-11503902,-8119500,-7643073,2620056,1022908,-23710744,-1568984,-16128528,-14962807 }, + { 23152971,775386,27395463,14006635,-9701118,4649512,1689819,892185,-11513277,-15205948 }, + }, + { + { 9770129,9586738,26496094,4324120,1556511,-3550024,27453819,4763127,-19179614,5867134 }, + { -32765025,1927590,31726409,-4753295,23962434,-16019500,27846559,5931263,-29749703,-16108455 }, + { 27461885,-2977536,22380810,1815854,-23033753,-3031938,7283490,-15148073,-19526700,7734629 }, + }, +}, +{ + { + { -8010264,-9590817,-11120403,6196038,29344158,-13430885,7585295,-3176626,18549497,15302069 }, + { -32658337,-6171222,-7672793,-11051681,6258878,13504381,10458790,-6418461,-8872242,8424746 }, + { 24687205,8613276,-30667046,-3233545,1863892,-1830544,19206234,7134917,-11284482,-828919 }, + }, + { + { 11334899,-9218022,8025293,12707519,17523892,-10476071,10243738,-14685461,-5066034,16498837 }, + { 8911542,6887158,-9584260,-6958590,11145641,-9543680,17303925,-14124238,6536641,10543906 }, + { -28946384,15479763,-17466835,568876,-1497683,11223454,-2669190,-16625574,-27235709,8876771 }, + }, + { + { -25742899,-12566864,-15649966,-846607,-33026686,-796288,-33481822,15824474,-604426,-9039817 }, + { 10330056,70051,7957388,-9002667,9764902,15609756,27698697,-4890037,1657394,3084098 }, + { 10477963,-7470260,12119566,-13250805,29016247,-5365589,31280319,14396151,-30233575,15272409 }, + }, + { + { -12288309,3169463,28813183,16658753,25116432,-5630466,-25173957,-12636138,-25014757,1950504 }, + { -26180358,9489187,11053416,-14746161,-31053720,5825630,-8384306,-8767532,15341279,8373727 }, + { 28685821,7759505,-14378516,-12002860,-31971820,4079242,298136,-10232602,-2878207,15190420 }, + }, + { + { -32932876,13806336,-14337485,-15794431,-24004620,10940928,8669718,2742393,-26033313,-6875003 }, + { -1580388,-11729417,-25979658,-11445023,-17411874,-10912854,9291594,-16247779,-12154742,6048605 }, + { -30305315,14843444,1539301,11864366,20201677,1900163,13934231,5128323,11213262,9168384 }, + }, + { + { -26280513,11007847,19408960,-940758,-18592965,-4328580,-5088060,-11105150,20470157,-16398701 }, + { -23136053,9282192,14855179,-15390078,-7362815,-14408560,-22783952,14461608,14042978,5230683 }, + { 29969567,-2741594,-16711867,-8552442,9175486,-2468974,21556951,3506042,-5933891,-12449708 }, + }, + { + { -3144746,8744661,19704003,4581278,-20430686,6830683,-21284170,8971513,-28539189,15326563 }, + { -19464629,10110288,-17262528,-3503892,-23500387,1355669,-15523050,15300988,-20514118,9168260 }, + { -5353335,4488613,-23803248,16314347,7780487,-15638939,-28948358,9601605,33087103,-9011387 }, + }, + { + { -19443170,-15512900,-20797467,-12445323,-29824447,10229461,-27444329,-15000531,-5996870,15664672 }, + { 23294591,-16632613,-22650781,-8470978,27844204,11461195,13099750,-2460356,18151676,13417686 }, + { -24722913,-4176517,-31150679,5988919,-26858785,6685065,1661597,-12551441,15271676,-15452665 }, + }, +}, +{ + { + { 11433042,-13228665,8239631,-5279517,-1985436,-725718,-18698764,2167544,-6921301,-13440182 }, + { -31436171,15575146,30436815,12192228,-22463353,9395379,-9917708,-8638997,12215110,12028277 }, + { 14098400,6555944,23007258,5757252,-15427832,-12950502,30123440,4617780,-16900089,-655628 }, + }, + { + { -4026201,-15240835,11893168,13718664,-14809462,1847385,-15819999,10154009,23973261,-12684474 }, + { -26531820,-3695990,-1908898,2534301,-31870557,-16550355,18341390,-11419951,32013174,-10103539 }, + { -25479301,10876443,-11771086,-14625140,-12369567,1838104,21911214,6354752,4425632,-837822 }, + }, + { + { -10433389,-14612966,22229858,-3091047,-13191166,776729,-17415375,-12020462,4725005,14044970 }, + { 19268650,-7304421,1555349,8692754,-21474059,-9910664,6347390,-1411784,-19522291,-16109756 }, + { -24864089,12986008,-10898878,-5558584,-11312371,-148526,19541418,8180106,9282262,10282508 }, + }, + { + { -26205082,4428547,-8661196,-13194263,4098402,-14165257,15522535,8372215,5542595,-10702683 }, + { -10562541,14895633,26814552,-16673850,-17480754,-2489360,-2781891,6993761,-18093885,10114655 }, + { -20107055,-929418,31422704,10427861,-7110749,6150669,-29091755,-11529146,25953725,-106158 }, + }, + { + { -4234397,-8039292,-9119125,3046000,2101609,-12607294,19390020,6094296,-3315279,12831125 }, + { -15998678,7578152,5310217,14408357,-33548620,-224739,31575954,6326196,7381791,-2421839 }, + { -20902779,3296811,24736065,-16328389,18374254,7318640,6295303,8082724,-15362489,12339664 }, + }, + { + { 27724736,2291157,6088201,-14184798,1792727,5857634,13848414,15768922,25091167,14856294 }, + { -18866652,8331043,24373479,8541013,-701998,-9269457,12927300,-12695493,-22182473,-9012899 }, + { -11423429,-5421590,11632845,3405020,30536730,-11674039,-27260765,13866390,30146206,9142070 }, + }, + { + { 3924129,-15307516,-13817122,-10054960,12291820,-668366,-27702774,9326384,-8237858,4171294 }, + { -15921940,16037937,6713787,16606682,-21612135,2790944,26396185,3731949,345228,-5462949 }, + { -21327538,13448259,25284571,1143661,20614966,-8849387,2031539,-12391231,-16253183,-13582083 }, + }, + { + { 31016211,-16722429,26371392,-14451233,-5027349,14854137,17477601,3842657,28012650,-16405420 }, + { -5075835,9368966,-8562079,-4600902,-15249953,6970560,-9189873,16292057,-8867157,3507940 }, + { 29439664,3537914,23333589,6997794,-17555561,-11018068,-15209202,-15051267,-9164929,6580396 }, + }, +}, +{ + { + { -12185861,-7679788,16438269,10826160,-8696817,-6235611,17860444,-9273846,-2095802,9304567 }, + { 20714564,-4336911,29088195,7406487,11426967,-5095705,14792667,-14608617,5289421,-477127 }, + { -16665533,-10650790,-6160345,-13305760,9192020,-1802462,17271490,12349094,26939669,-3752294 }, + }, + { + { -12889898,9373458,31595848,16374215,21471720,13221525,-27283495,-12348559,-3698806,117887 }, + { 22263325,-6560050,3984570,-11174646,-15114008,-566785,28311253,5358056,-23319780,541964 }, + { 16259219,3261970,2309254,-15534474,-16885711,-4581916,24134070,-16705829,-13337066,-13552195 }, + }, + { + { 9378160,-13140186,-22845982,-12745264,28198281,-7244098,-2399684,-717351,690426,14876244 }, + { 24977353,-314384,-8223969,-13465086,28432343,-1176353,-13068804,-12297348,-22380984,6618999 }, + { -1538174,11685646,12944378,13682314,-24389511,-14413193,8044829,-13817328,32239829,-5652762 }, + }, + { + { -18603066,4762990,-926250,8885304,-28412480,-3187315,9781647,-10350059,32779359,5095274 }, + { -33008130,-5214506,-32264887,-3685216,9460461,-9327423,-24601656,14506724,21639561,-2630236 }, + { -16400943,-13112215,25239338,15531969,3987758,-4499318,-1289502,-6863535,17874574,558605 }, + }, + { + { -13600129,10240081,9171883,16131053,-20869254,9599700,33499487,5080151,2085892,5119761 }, + { -22205145,-2519528,-16381601,414691,-25019550,2170430,30634760,-8363614,-31999993,-5759884 }, + { -6845704,15791202,8550074,-1312654,29928809,-12092256,27534430,-7192145,-22351378,12961482 }, + }, + { + { -24492060,-9570771,10368194,11582341,-23397293,-2245287,16533930,8206996,-30194652,-5159638 }, + { -11121496,-3382234,2307366,6362031,-135455,8868177,-16835630,7031275,7589640,8945490 }, + { -32152748,8917967,6661220,-11677616,-1192060,-15793393,7251489,-11182180,24099109,-14456170 }, + }, + { + { 5019558,-7907470,4244127,-14714356,-26933272,6453165,-19118182,-13289025,-6231896,-10280736 }, + { 10853594,10721687,26480089,5861829,-22995819,1972175,-1866647,-10557898,-3363451,-6441124 }, + { -17002408,5906790,221599,-6563147,7828208,-13248918,24362661,-2008168,-13866408,7421392 }, + }, + { + { 8139927,-6546497,32257646,-5890546,30375719,1886181,-21175108,15441252,28826358,-4123029 }, + { 6267086,9695052,7709135,-16603597,-32869068,-1886135,14795160,-7840124,13746021,-1742048 }, + { 28584902,7787108,-6732942,-15050729,22846041,-7571236,-3181936,-363524,4771362,-8419958 }, + }, +}, +{ + { + { 24949256,6376279,-27466481,-8174608,-18646154,-9930606,33543569,-12141695,3569627,11342593 }, + { 26514989,4740088,27912651,3697550,19331575,-11472339,6809886,4608608,7325975,-14801071 }, + { -11618399,-14554430,-24321212,7655128,-1369274,5214312,-27400540,10258390,-17646694,-8186692 }, + }, + { + { 11431204,15823007,26570245,14329124,18029990,4796082,-31446179,15580664,9280358,-3973687 }, + { -160783,-10326257,-22855316,-4304997,-20861367,-13621002,-32810901,-11181622,-15545091,4387441 }, + { -20799378,12194512,3937617,-5805892,-27154820,9340370,-24513992,8548137,20617071,-7482001 }, + }, + { + { -938825,-3930586,-8714311,16124718,24603125,-6225393,-13775352,-11875822,24345683,10325460 }, + { -19855277,-1568885,-22202708,8714034,14007766,6928528,16318175,-1010689,4766743,3552007 }, + { -21751364,-16730916,1351763,-803421,-4009670,3950935,3217514,14481909,10988822,-3994762 }, + }, + { + { 15564307,-14311570,3101243,5684148,30446780,-8051356,12677127,-6505343,-8295852,13296005 }, + { -9442290,6624296,-30298964,-11913677,-4670981,-2057379,31521204,9614054,-30000824,12074674 }, + { 4771191,-135239,14290749,-13089852,27992298,14998318,-1413936,-1556716,29832613,-16391035 }, + }, + { + { 7064884,-7541174,-19161962,-5067537,-18891269,-2912736,25825242,5293297,-27122660,13101590 }, + { -2298563,2439670,-7466610,1719965,-27267541,-16328445,32512469,-5317593,-30356070,-4190957 }, + { -30006540,10162316,-33180176,3981723,-16482138,-13070044,14413974,9515896,19568978,9628812 }, + }, + { + { 33053803,199357,15894591,1583059,27380243,-4580435,-17838894,-6106839,-6291786,3437740 }, + { -18978877,3884493,19469877,12726490,15913552,13614290,-22961733,70104,7463304,4176122 }, + { -27124001,10659917,11482427,-16070381,12771467,-6635117,-32719404,-5322751,24216882,5944158 }, + }, + { + { 8894125,7450974,-2664149,-9765752,-28080517,-12389115,19345746,14680796,11632993,5847885 }, + { 26942781,-2315317,9129564,-4906607,26024105,11769399,-11518837,6367194,-9727230,4782140 }, + { 19916461,-4828410,-22910704,-11414391,25606324,-5972441,33253853,8220911,6358847,-1873857 }, + }, + { + { 801428,-2081702,16569428,11065167,29875704,96627,7908388,-4480480,-13538503,1387155 }, + { 19646058,5720633,-11416706,12814209,11607948,12749789,14147075,15156355,-21866831,11835260 }, + { 19299512,1155910,28703737,14890794,2925026,7269399,26121523,15467869,-26560550,5052483 }, + }, +}, +{ + { + { -3017432,10058206,1980837,3964243,22160966,12322533,-6431123,-12618185,12228557,-7003677 }, + { 32944382,14922211,-22844894,5188528,21913450,-8719943,4001465,13238564,-6114803,8653815 }, + { 22865569,-4652735,27603668,-12545395,14348958,8234005,24808405,5719875,28483275,2841751 }, + }, + { + { -16420968,-1113305,-327719,-12107856,21886282,-15552774,-1887966,-315658,19932058,-12739203 }, + { -11656086,10087521,-8864888,-5536143,-19278573,-3055912,3999228,13239134,-4777469,-13910208 }, + { 1382174,-11694719,17266790,9194690,-13324356,9720081,20403944,11284705,-14013818,3093230 }, + }, + { + { 16650921,-11037932,-1064178,1570629,-8329746,7352753,-302424,16271225,-24049421,-6691850 }, + { -21911077,-5927941,-4611316,-5560156,-31744103,-10785293,24123614,15193618,-21652117,-16739389 }, + { -9935934,-4289447,-25279823,4372842,2087473,10399484,31870908,14690798,17361620,11864968 }, + }, + { + { -11307610,6210372,13206574,5806320,-29017692,-13967200,-12331205,-7486601,-25578460,-16240689 }, + { 14668462,-12270235,26039039,15305210,25515617,4542480,10453892,6577524,9145645,-6443880 }, + { 5974874,3053895,-9433049,-10385191,-31865124,3225009,-7972642,3936128,-5652273,-3050304 }, + }, + { + { 30625386,-4729400,-25555961,-12792866,-20484575,7695099,17097188,-16303496,-27999779,1803632 }, + { -3553091,9865099,-5228566,4272701,-5673832,-16689700,14911344,12196514,-21405489,7047412 }, + { 20093277,9920966,-11138194,-5343857,13161587,12044805,-32856851,4124601,-32343828,-10257566 }, + }, + { + { -20788824,14084654,-13531713,7842147,19119038,-13822605,4752377,-8714640,-21679658,2288038 }, + { -26819236,-3283715,29965059,3039786,-14473765,2540457,29457502,14625692,-24819617,12570232 }, + { -1063558,-11551823,16920318,12494842,1278292,-5869109,-21159943,-3498680,-11974704,4724943 }, + }, + { + { 17960970,-11775534,-4140968,-9702530,-8876562,-1410617,-12907383,-8659932,-29576300,1903856 }, + { 23134274,-14279132,-10681997,-1611936,20684485,15770816,-12989750,3190296,26955097,14109738 }, + { 15308788,5320727,-30113809,-14318877,22902008,7767164,29425325,-11277562,31960942,11934971 }, + }, + { + { -27395711,8435796,4109644,12222639,-24627868,14818669,20638173,4875028,10491392,1379718 }, + { -13159415,9197841,3875503,-8936108,-1383712,-5879801,33518459,16176658,21432314,12180697 }, + { -11787308,11500838,13787581,-13832590,-22430679,10140205,1465425,12689540,-10301319,-13872883 }, + }, +}, +{ + { + { 5414091,-15386041,-21007664,9643570,12834970,1186149,-2622916,-1342231,26128231,6032912 }, + { -26337395,-13766162,32496025,-13653919,17847801,-12669156,3604025,8316894,-25875034,-10437358 }, + { 3296484,6223048,24680646,-12246460,-23052020,5903205,-8862297,-4639164,12376617,3188849 }, + }, + { + { 29190488,-14659046,27549113,-1183516,3520066,-10697301,32049515,-7309113,-16109234,-9852307 }, + { -14744486,-9309156,735818,-598978,-20407687,-5057904,25246078,-15795669,18640741,-960977 }, + { -6928835,-16430795,10361374,5642961,4910474,12345252,-31638386,-494430,10530747,1053335 }, + }, + { + { -29265967,-14186805,-13538216,-12117373,-19457059,-10655384,-31462369,-2948985,24018831,15026644 }, + { -22592535,-3145277,-2289276,5953843,-13440189,9425631,25310643,13003497,-2314791,-15145616 }, + { -27419985,-603321,-8043984,-1669117,-26092265,13987819,-27297622,187899,-23166419,-2531735 }, + }, + { + { -21744398,-13810475,1844840,5021428,-10434399,-15911473,9716667,16266922,-5070217,726099 }, + { 29370922,-6053998,7334071,-15342259,9385287,2247707,-13661962,-4839461,30007388,-15823341 }, + { -936379,16086691,23751945,-543318,-1167538,-5189036,9137109,730663,9835848,4555336 }, + }, + { + { -23376435,1410446,-22253753,-12899614,30867635,15826977,17693930,544696,-11985298,12422646 }, + { 31117226,-12215734,-13502838,6561947,-9876867,-12757670,-5118685,-4096706,29120153,13924425 }, + { -17400879,-14233209,19675799,-2734756,-11006962,-5858820,-9383939,-11317700,7240931,-237388 }, + }, + { + { -31361739,-11346780,-15007447,-5856218,-22453340,-12152771,1222336,4389483,3293637,-15551743 }, + { -16684801,-14444245,11038544,11054958,-13801175,-3338533,-24319580,7733547,12796905,-6335822 }, + { -8759414,-10817836,-25418864,10783769,-30615557,-9746811,-28253339,3647836,3222231,-11160462 }, + }, + { + { 18606113,1693100,-25448386,-15170272,4112353,10045021,23603893,-2048234,-7550776,2484985 }, + { 9255317,-3131197,-12156162,-1004256,13098013,-9214866,16377220,-2102812,-19802075,-3034702 }, + { -22729289,7496160,-5742199,11329249,19991973,-3347502,-31718148,9936966,-30097688,-10618797 }, + }, + { + { 21878590,-5001297,4338336,13643897,-3036865,13160960,19708896,5415497,-7360503,-4109293 }, + { 27736861,10103576,12500508,8502413,-3413016,-9633558,10436918,-1550276,-23659143,-8132100 }, + { 19492550,-12104365,-29681976,-852630,-3208171,12403437,30066266,8367329,13243957,8709688 }, + }, +}, +{ + { + { 12015105,2801261,28198131,10151021,24818120,-4743133,-11194191,-5645734,5150968,7274186 }, + { 2831366,-12492146,1478975,6122054,23825128,-12733586,31097299,6083058,31021603,-9793610 }, + { -2529932,-2229646,445613,10720828,-13849527,-11505937,-23507731,16354465,15067285,-14147707 }, + }, + { + { 7840942,14037873,-33364863,15934016,-728213,-3642706,21403988,1057586,-19379462,-12403220 }, + { 915865,-16469274,15608285,-8789130,-24357026,6060030,-17371319,8410997,-7220461,16527025 }, + { 32922597,-556987,20336074,-16184568,10903705,-5384487,16957574,52992,23834301,6588044 }, + }, + { + { 32752030,11232950,3381995,-8714866,22652988,-10744103,17159699,16689107,-20314580,-1305992 }, + { -4689649,9166776,-25710296,-10847306,11576752,12733943,7924251,-2752281,1976123,-7249027 }, + { 21251222,16309901,-2983015,-6783122,30810597,12967303,156041,-3371252,12331345,-8237197 }, + }, + { + { 8651614,-4477032,-16085636,-4996994,13002507,2950805,29054427,-5106970,10008136,-4667901 }, + { 31486080,15114593,-14261250,12951354,14369431,-7387845,16347321,-13662089,8684155,-10532952 }, + { 19443825,11385320,24468943,-9659068,-23919258,2187569,-26263207,-6086921,31316348,14219878 }, + }, + { + { -28594490,1193785,32245219,11392485,31092169,15722801,27146014,6992409,29126555,9207390 }, + { 32382935,1110093,18477781,11028262,-27411763,-7548111,-4980517,10843782,-7957600,-14435730 }, + { 2814918,7836403,27519878,-7868156,-20894015,-11553689,-21494559,8550130,28346258,1994730 }, + }, + { + { -19578299,8085545,-14000519,-3948622,2785838,-16231307,-19516951,7174894,22628102,8115180 }, + { -30405132,955511,-11133838,-15078069,-32447087,-13278079,-25651578,3317160,-9943017,930272 }, + { -15303681,-6833769,28856490,1357446,23421993,1057177,24091212,-1388970,-22765376,-10650715 }, + }, + { + { -22751231,-5303997,-12907607,-12768866,-15811511,-7797053,-14839018,-16554220,-1867018,8398970 }, + { -31969310,2106403,-4736360,1362501,12813763,16200670,22981545,-6291273,18009408,-15772772 }, + { -17220923,-9545221,-27784654,14166835,29815394,7444469,29551787,-3727419,19288549,1325865 }, + }, + { + { 15100157,-15835752,-23923978,-1005098,-26450192,15509408,12376730,-3479146,33166107,-8042750 }, + { 20909231,13023121,-9209752,16251778,-5778415,-8094914,12412151,10018715,2213263,-13878373 }, + { 32529814,-11074689,30361439,-16689753,-9135940,1513226,22922121,6382134,-5766928,8371348 }, + }, +}, +{ + { + { 9923462,11271500,12616794,3544722,-29998368,-1721626,12891687,-8193132,-26442943,10486144 }, + { -22597207,-7012665,8587003,-8257861,4084309,-12970062,361726,2610596,-23921530,-11455195 }, + { 5408411,-1136691,-4969122,10561668,24145918,14240566,31319731,-4235541,19985175,-3436086 }, + }, + { + { -13994457,16616821,14549246,3341099,32155958,13648976,-17577068,8849297,65030,8370684 }, + { -8320926,-12049626,31204563,5839400,-20627288,-1057277,-19442942,6922164,12743482,-9800518 }, + { -2361371,12678785,28815050,4759974,-23893047,4884717,23783145,11038569,18800704,255233 }, + }, + { + { -5269658,-1773886,13957886,7990715,23132995,728773,13393847,9066957,19258688,-14753793 }, + { -2936654,-10827535,-10432089,14516793,-3640786,4372541,-31934921,2209390,-1524053,2055794 }, + { 580882,16705327,5468415,-2683018,-30926419,-14696000,-7203346,-8994389,-30021019,7394435 }, + }, + { + { 23838809,1822728,-15738443,15242727,8318092,-3733104,-21672180,-3492205,-4821741,14799921 }, + { 13345610,9759151,3371034,-16137791,16353039,8577942,31129804,13496856,-9056018,7402518 }, + { 2286874,-4435931,-20042458,-2008336,-13696227,5038122,11006906,-15760352,8205061,1607563 }, + }, + { + { 14414086,-8002132,3331830,-3208217,22249151,-5594188,18364661,-2906958,30019587,-9029278 }, + { -27688051,1585953,-10775053,931069,-29120221,-11002319,-14410829,12029093,9944378,8024 }, + { 4368715,-3709630,29874200,-15022983,-20230386,-11410704,-16114594,-999085,-8142388,5640030 }, + }, + { + { 10299610,13746483,11661824,16234854,7630238,5998374,9809887,-16694564,15219798,-14327783 }, + { 27425505,-5719081,3055006,10660664,23458024,595578,-15398605,-1173195,-18342183,9742717 }, + { 6744077,2427284,26042789,2720740,-847906,1118974,32324614,7406442,12420155,1994844 }, + }, + { + { 14012521,-5024720,-18384453,-9578469,-26485342,-3936439,-13033478,-10909803,24319929,-6446333 }, + { 16412690,-4507367,10772641,15929391,-17068788,-4658621,10555945,-10484049,-30102368,-4739048 }, + { 22397382,-7767684,-9293161,-12792868,17166287,-9755136,-27333065,6199366,21880021,-12250760 }, + }, + { + { -4283307,5368523,-31117018,8163389,-30323063,3209128,16557151,8890729,8840445,4957760 }, + { -15447727,709327,-6919446,-10870178,-29777922,6522332,-21720181,12130072,-14796503,5005757 }, + { -2114751,-14308128,23019042,15765735,-25269683,6002752,10183197,-13239326,-16395286,-2176112 }, + }, +}, +{ + { + { -19025756,1632005,13466291,-7995100,-23640451,16573537,-32013908,-3057104,22208662,2000468 }, + { 3065073,-1412761,-25598674,-361432,-17683065,-5703415,-8164212,11248527,-3691214,-7414184 }, + { 10379208,-6045554,8877319,1473647,-29291284,-12507580,16690915,2553332,-3132688,16400289 }, + }, + { + { 15716668,1254266,-18472690,7446274,-8448918,6344164,-22097271,-7285580,26894937,9132066 }, + { 24158887,12938817,11085297,-8177598,-28063478,-4457083,-30576463,64452,-6817084,-2692882 }, + { 13488534,7794716,22236231,5989356,25426474,-12578208,2350710,-3418511,-4688006,2364226 }, + }, + { + { 16335052,9132434,25640582,6678888,1725628,8517937,-11807024,-11697457,15445875,-7798101 }, + { 29004207,-7867081,28661402,-640412,-12794003,-7943086,31863255,-4135540,-278050,-15759279 }, + { -6122061,-14866665,-28614905,14569919,-10857999,-3591829,10343412,-6976290,-29828287,-10815811 }, + }, + { + { 27081650,3463984,14099042,-4517604,1616303,-6205604,29542636,15372179,17293797,960709 }, + { 20263915,11434237,-5765435,11236810,13505955,-10857102,-16111345,6493122,-19384511,7639714 }, + { -2830798,-14839232,25403038,-8215196,-8317012,-16173699,18006287,-16043750,29994677,-15808121 }, + }, + { + { 9769828,5202651,-24157398,-13631392,-28051003,-11561624,-24613141,-13860782,-31184575,709464 }, + { 12286395,13076066,-21775189,-1176622,-25003198,4057652,-32018128,-8890874,16102007,13205847 }, + { 13733362,5599946,10557076,3195751,-5557991,8536970,-25540170,8525972,10151379,10394400 }, + }, + { + { 4024660,-16137551,22436262,12276534,-9099015,-2686099,19698229,11743039,-33302334,8934414 }, + { -15879800,-4525240,-8580747,-2934061,14634845,-698278,-9449077,3137094,-11536886,11721158 }, + { 17555939,-5013938,8268606,2331751,-22738815,9761013,9319229,8835153,-9205489,-1280045 }, + }, + { + { -461409,-7830014,20614118,16688288,-7514766,-4807119,22300304,505429,6108462,-6183415 }, + { -5070281,12367917,-30663534,3234473,32617080,-8422642,29880583,-13483331,-26898490,-7867459 }, + { -31975283,5726539,26934134,10237677,-3173717,-605053,24199304,3795095,7592688,-14992079 }, + }, + { + { 21594432,-14964228,17466408,-4077222,32537084,2739898,6407723,12018833,-28256052,4298412 }, + { -20650503,-11961496,-27236275,570498,3767144,-1717540,13891942,-1569194,13717174,10805743 }, + { -14676630,-15644296,15287174,11927123,24177847,-8175568,-796431,14860609,-26938930,-5863836 }, + }, +}, +{ + { + { 12962541,5311799,-10060768,11658280,18855286,-7954201,13286263,-12808704,-4381056,9882022 }, + { 18512079,11319350,-20123124,15090309,18818594,5271736,-22727904,3666879,-23967430,-3299429 }, + { -6789020,-3146043,16192429,13241070,15898607,-14206114,-10084880,-6661110,-2403099,5276065 }, + }, + { + { 30169808,-5317648,26306206,-11750859,27814964,7069267,7152851,3684982,1449224,13082861 }, + { 10342826,3098505,2119311,193222,25702612,12233820,23697382,15056736,-21016438,-8202000 }, + { -33150110,3261608,22745853,7948688,19370557,-15177665,-26171976,6482814,-10300080,-11060101 }, + }, + { + { 32869458,-5408545,25609743,15678670,-10687769,-15471071,26112421,2521008,-22664288,6904815 }, + { 29506923,4457497,3377935,-9796444,-30510046,12935080,1561737,3841096,-29003639,-6657642 }, + { 10340844,-6630377,-18656632,-2278430,12621151,-13339055,30878497,-11824370,-25584551,5181966 }, + }, + { + { 25940115,-12658025,17324188,-10307374,-8671468,15029094,24396252,-16450922,-2322852,-12388574 }, + { -21765684,9916823,-1300409,4079498,-1028346,11909559,1782390,12641087,20603771,-6561742 }, + { -18882287,-11673380,24849422,11501709,13161720,-4768874,1925523,11914390,4662781,7820689 }, + }, + { + { 12241050,-425982,8132691,9393934,32846760,-1599620,29749456,12172924,16136752,15264020 }, + { -10349955,-14680563,-8211979,2330220,-17662549,-14545780,10658213,6671822,19012087,3772772 }, + { 3753511,-3421066,10617074,2028709,14841030,-6721664,28718732,-15762884,20527771,12988982 }, + }, + { + { -14822485,-5797269,-3707987,12689773,-898983,-10914866,-24183046,-10564943,3299665,-12424953 }, + { -16777703,-15253301,-9642417,4978983,3308785,8755439,6943197,6461331,-25583147,8991218 }, + { -17226263,1816362,-1673288,-6086439,31783888,-8175991,-32948145,7417950,-30242287,1507265 }, + }, + { + { 29692663,6829891,-10498800,4334896,20945975,-11906496,-28887608,8209391,14606362,-10647073 }, + { -3481570,8707081,32188102,5672294,22096700,1711240,-33020695,9761487,4170404,-2085325 }, + { -11587470,14855945,-4127778,-1531857,-26649089,15084046,22186522,16002000,-14276837,-8400798 }, + }, + { + { -4811456,13761029,-31703877,-2483919,-3312471,7869047,-7113572,-9620092,13240845,10965870 }, + { -7742563,-8256762,-14768334,-13656260,-23232383,12387166,4498947,14147411,29514390,4302863 }, + { -13413405,-12407859,20757302,-13801832,14785143,8976368,-5061276,-2144373,17846988,-13971927 }, + }, +}, +{ + { + { -2244452,-754728,-4597030,-1066309,-6247172,1455299,-21647728,-9214789,-5222701,12650267 }, + { -9906797,-16070310,21134160,12198166,-27064575,708126,387813,13770293,-19134326,10958663 }, + { 22470984,12369526,23446014,-5441109,-21520802,-9698723,-11772496,-11574455,-25083830,4271862 }, + }, + { + { -25169565,-10053642,-19909332,15361595,-5984358,2159192,75375,-4278529,-32526221,8469673 }, + { 15854970,4148314,-8893890,7259002,11666551,13824734,-30531198,2697372,24154791,-9460943 }, + { 15446137,-15806644,29759747,14019369,30811221,-9610191,-31582008,12840104,24913809,9815020 }, + }, + { + { -4709286,-5614269,-31841498,-12288893,-14443537,10799414,-9103676,13438769,18735128,9466238 }, + { 11933045,9281483,5081055,-5183824,-2628162,-4905629,-7727821,-10896103,-22728655,16199064 }, + { 14576810,379472,-26786533,-8317236,-29426508,-10812974,-102766,1876699,30801119,2164795 }, + }, + { + { 15995086,3199873,13672555,13712240,-19378835,-4647646,-13081610,-15496269,-13492807,1268052 }, + { -10290614,-3659039,-3286592,10948818,23037027,3794475,-3470338,-12600221,-17055369,3565904 }, + { 29210088,-9419337,-5919792,-4952785,10834811,-13327726,-16512102,-10820713,-27162222,-14030531 }, + }, + { + { -13161890,15508588,16663704,-8156150,-28349942,9019123,-29183421,-3769423,2244111,-14001979 }, + { -5152875,-3800936,-9306475,-6071583,16243069,14684434,-25673088,-16180800,13491506,4641841 }, + { 10813417,643330,-19188515,-728916,30292062,-16600078,27548447,-7721242,14476989,-12767431 }, + }, + { + { 10292079,9984945,6481436,8279905,-7251514,7032743,27282937,-1644259,-27912810,12651324 }, + { -31185513,-813383,22271204,11835308,10201545,15351028,17099662,3988035,21721536,-3148940 }, + { 10202177,-6545839,-31373232,-9574638,-32150642,-8119683,-12906320,3852694,13216206,14842320 }, + }, + { + { -15815640,-10601066,-6538952,-7258995,-6984659,-6581778,-31500847,13765824,-27434397,9900184 }, + { 14465505,-13833331,-32133984,-14738873,-27443187,12990492,33046193,15796406,-7051866,-8040114 }, + { 30924417,-8279620,6359016,-12816335,16508377,9071735,-25488601,15413635,9524356,-7018878 }, + }, + { + { 12274201,-13175547,32627641,-1785326,6736625,13267305,5237659,-5109483,15663516,4035784 }, + { -2951309,8903985,17349946,601635,-16432815,-4612556,-13732739,-15889334,-22258478,4659091 }, + { -16916263,-4952973,-30393711,-15158821,20774812,15897498,5736189,15026997,-2178256,-13455585 }, + }, +}, +{ + { + { -8858980,-2219056,28571666,-10155518,-474467,-10105698,-3801496,278095,23440562,-290208 }, + { 10226241,-5928702,15139956,120818,-14867693,5218603,32937275,11551483,-16571960,-7442864 }, + { 17932739,-12437276,-24039557,10749060,11316803,7535897,22503767,5561594,-3646624,3898661 }, + }, + { + { 7749907,-969567,-16339731,-16464,-25018111,15122143,-1573531,7152530,21831162,1245233 }, + { 26958459,-14658026,4314586,8346991,-5677764,11960072,-32589295,-620035,-30402091,-16716212 }, + { -12165896,9166947,33491384,13673479,29787085,13096535,6280834,14587357,-22338025,13987525 }, + }, + { + { -24349909,7778775,21116000,15572597,-4833266,-5357778,-4300898,-5124639,-7469781,-2858068 }, + { 9681908,-6737123,-31951644,13591838,-6883821,386950,31622781,6439245,-14581012,4091397 }, + { -8426427,1470727,-28109679,-1596990,3978627,-5123623,-19622683,12092163,29077877,-14741988 }, + }, + { + { 5269168,-6859726,-13230211,-8020715,25932563,1763552,-5606110,-5505881,-20017847,2357889 }, + { 32264008,-15407652,-5387735,-1160093,-2091322,-3946900,23104804,-12869908,5727338,189038 }, + { 14609123,-8954470,-6000566,-16622781,-14577387,-7743898,-26745169,10942115,-25888931,-14884697 }, + }, + { + { 20513500,5557931,-15604613,7829531,26413943,-2019404,-21378968,7471781,13913677,-5137875 }, + { -25574376,11967826,29233242,12948236,-6754465,4713227,-8940970,14059180,12878652,8511905 }, + { -25656801,3393631,-2955415,-7075526,-2250709,9366908,-30223418,6812974,5568676,-3127656 }, + }, + { + { 11630004,12144454,2116339,13606037,27378885,15676917,-17408753,-13504373,-14395196,8070818 }, + { 27117696,-10007378,-31282771,-5570088,1127282,12772488,-29845906,10483306,-11552749,-1028714 }, + { 10637467,-5688064,5674781,1072708,-26343588,-6982302,-1683975,9177853,-27493162,15431203 }, + }, + { + { 20525145,10892566,-12742472,12779443,-29493034,16150075,-28240519,14943142,-15056790,-7935931 }, + { -30024462,5626926,-551567,-9981087,753598,11981191,25244767,-3239766,-3356550,9594024 }, + { -23752644,2636870,-5163910,-10103818,585134,7877383,11345683,-6492290,13352335,-10977084 }, + }, + { + { -1931799,-5407458,3304649,-12884869,17015806,-4877091,-29783850,-7752482,-13215537,-319204 }, + { 20239939,6607058,6203985,3483793,-18386976,-779229,-20723742,15077870,-22750759,14523817 }, + { 27406042,-6041657,27423596,-4497394,4996214,10002360,-28842031,-4545494,-30172742,-4805667 }, + }, +}, +{ + { + { 11374242,12660715,17861383,-12540833,10935568,1099227,-13886076,-9091740,-27727044,11358504 }, + { -12730809,10311867,1510375,10778093,-2119455,-9145702,32676003,11149336,-26123651,4985768 }, + { -19096303,341147,-6197485,-239033,15756973,-8796662,-983043,13794114,-19414307,-15621255 }, + }, + { + { 6490081,11940286,25495923,-7726360,8668373,-8751316,3367603,6970005,-1691065,-9004790 }, + { 1656497,13457317,15370807,6364910,13605745,8362338,-19174622,-5475723,-16796596,-5031438 }, + { -22273315,-13524424,-64685,-4334223,-18605636,-10921968,-20571065,-7007978,-99853,-10237333 }, + }, + { + { 17747465,10039260,19368299,-4050591,-20630635,-16041286,31992683,-15857976,-29260363,-5511971 }, + { 31932027,-4986141,-19612382,16366580,22023614,88450,11371999,-3744247,4882242,-10626905 }, + { 29796507,37186,19818052,10115756,-11829032,3352736,18551198,3272828,-5190932,-4162409 }, + }, + { + { 12501286,4044383,-8612957,-13392385,-32430052,5136599,-19230378,-3529697,330070,-3659409 }, + { 6384877,2899513,17807477,7663917,-2358888,12363165,25366522,-8573892,-271295,12071499 }, + { -8365515,-4042521,25133448,-4517355,-6211027,2265927,-32769618,1936675,-5159697,3829363 }, + }, + { + { 28425966,-5835433,-577090,-4697198,-14217555,6870930,7921550,-6567787,26333140,14267664 }, + { -11067219,11871231,27385719,-10559544,-4585914,-11189312,10004786,-8709488,-21761224,8930324 }, + { -21197785,-16396035,25654216,-1725397,12282012,11008919,1541940,4757911,-26491501,-16408940 }, + }, + { + { 13537262,-7759490,-20604840,10961927,-5922820,-13218065,-13156584,6217254,-15943699,13814990 }, + { -17422573,15157790,18705543,29619,24409717,-260476,27361681,9257833,-1956526,-1776914 }, + { -25045300,-10191966,15366585,15166509,-13105086,8423556,-29171540,12361135,-18685978,4578290 }, + }, + { + { 24579768,3711570,1342322,-11180126,-27005135,14124956,-22544529,14074919,21964432,8235257 }, + { -6528613,-2411497,9442966,-5925588,12025640,-1487420,-2981514,-1669206,13006806,2355433 }, + { -16304899,-13605259,-6632427,-5142349,16974359,-10911083,27202044,1719366,1141648,-12796236 }, + }, + { + { -12863944,-13219986,-8318266,-11018091,-6810145,-4843894,13475066,-3133972,32674895,13715045 }, + { 11423335,-5468059,32344216,8962751,24989809,9241752,-13265253,16086212,-28740881,-15642093 }, + { -1409668,12530728,-6368726,10847387,19531186,-14132160,-11709148,7791794,-27245943,4383347 }, + }, +}, +{ + { + { -28970898,5271447,-1266009,-9736989,-12455236,16732599,-4862407,-4906449,27193557,6245191 }, + { -15193956,5362278,-1783893,2695834,4960227,12840725,23061898,3260492,22510453,8577507 }, + { -12632451,11257346,-32692994,13548177,-721004,10879011,31168030,13952092,-29571492,-3635906 }, + }, + { + { 3877321,-9572739,32416692,5405324,-11004407,-13656635,3759769,11935320,5611860,8164018 }, + { -16275802,14667797,15906460,12155291,-22111149,-9039718,32003002,-8832289,5773085,-8422109 }, + { -23788118,-8254300,1950875,8937633,18686727,16459170,-905725,12376320,31632953,190926 }, + }, + { + { -24593607,-16138885,-8423991,13378746,14162407,6901328,-8288749,4508564,-25341555,-3627528 }, + { 8884438,-5884009,6023974,10104341,-6881569,-4941533,18722941,-14786005,-1672488,827625 }, + { -32720583,-16289296,-32503547,7101210,13354605,2659080,-1800575,-14108036,-24878478,1541286 }, + }, + { + { 2901347,-1117687,3880376,-10059388,-17620940,-3612781,-21802117,-3567481,20456845,-1885033 }, + { 27019610,12299467,-13658288,-1603234,-12861660,-4861471,-19540150,-5016058,29439641,15138866 }, + { 21536104,-6626420,-32447818,-10690208,-22408077,5175814,-5420040,-16361163,7779328,109896 }, + }, + { + { 30279744,14648750,-8044871,6425558,13639621,-743509,28698390,12180118,23177719,-554075 }, + { 26572847,3405927,-31701700,12890905,-19265668,5335866,-6493768,2378492,4439158,-13279347 }, + { -22716706,3489070,-9225266,-332753,18875722,-1140095,14819434,-12731527,-17717757,-5461437 }, + }, + { + { -5056483,16566551,15953661,3767752,-10436499,15627060,-820954,2177225,8550082,-15114165 }, + { -18473302,16596775,-381660,15663611,22860960,15585581,-27844109,-3582739,-23260460,-8428588 }, + { -32480551,15707275,-8205912,-5652081,29464558,2713815,-22725137,15860482,-21902570,1494193 }, + }, + { + { -19562091,-14087393,-25583872,-9299552,13127842,759709,21923482,16529112,8742704,12967017 }, + { -28464899,1553205,32536856,-10473729,-24691605,-406174,-8914625,-2933896,-29903758,15553883 }, + { 21877909,3230008,9881174,10539357,-4797115,2841332,11543572,14513274,19375923,-12647961 }, + }, + { + { 8832269,-14495485,13253511,5137575,5037871,4078777,24880818,-6222716,2862653,9455043 }, + { 29306751,5123106,20245049,-14149889,9592566,8447059,-2077124,-2990080,15511449,4789663 }, + { -20679756,7004547,8824831,-9434977,-4045704,-3750736,-5754762,108893,23513200,16652362 }, + }, +}, +{ + { + { -33256173,4144782,-4476029,-6579123,10770039,-7155542,-6650416,-12936300,-18319198,10212860 }, + { 2756081,8598110,7383731,-6859892,22312759,-1105012,21179801,2600940,-9988298,-12506466 }, + { -24645692,13317462,-30449259,-15653928,21365574,-10869657,11344424,864440,-2499677,-16710063 }, + }, + { + { -26432803,6148329,-17184412,-14474154,18782929,-275997,-22561534,211300,2719757,4940997 }, + { -1323882,3911313,-6948744,14759765,-30027150,7851207,21690126,8518463,26699843,5276295 }, + { -13149873,-6429067,9396249,365013,24703301,-10488939,1321586,149635,-15452774,7159369 }, + }, + { + { 9987780,-3404759,17507962,9505530,9731535,-2165514,22356009,8312176,22477218,-8403385 }, + { 18155857,-16504990,19744716,9006923,15154154,-10538976,24256460,-4864995,-22548173,9334109 }, + { 2986088,-4911893,10776628,-3473844,10620590,-7083203,-21413845,14253545,-22587149,536906 }, + }, + { + { 4377756,8115836,24567078,15495314,11625074,13064599,7390551,10589625,10838060,-15420424 }, + { -19342404,867880,9277171,-3218459,-14431572,-1986443,19295826,-15796950,6378260,699185 }, + { 7895026,4057113,-7081772,-13077756,-17886831,-323126,-716039,15693155,-5045064,-13373962 }, + }, + { + { -7737563,-5869402,-14566319,-7406919,11385654,13201616,31730678,-10962840,-3918636,-9669325 }, + { 10188286,-15770834,-7336361,13427543,22223443,14896287,30743455,7116568,-21786507,5427593 }, + { 696102,13206899,27047647,-10632082,15285305,-9853179,10798490,-4578720,19236243,12477404 }, + }, + { + { -11229439,11243796,-17054270,-8040865,-788228,-8167967,-3897669,11180504,-23169516,7733644 }, + { 17800790,-14036179,-27000429,-11766671,23887827,3149671,23466177,-10538171,10322027,15313801 }, + { 26246234,11968874,32263343,-5468728,6830755,-13323031,-15794704,-101982,-24449242,10890804 }, + }, + { + { -31365647,10271363,-12660625,-6267268,16690207,-13062544,-14982212,16484931,25180797,-5334884 }, + { -586574,10376444,-32586414,-11286356,19801893,10997610,2276632,9482883,316878,13820577 }, + { -9882808,-4510367,-2115506,16457136,-11100081,11674996,30756178,-7515054,30696930,-3712849 }, + }, + { + { 32988917,-9603412,12499366,7910787,-10617257,-11931514,-7342816,-9985397,-32349517,7392473 }, + { -8855661,15927861,9866406,-3649411,-2396914,-16655781,-30409476,-9134995,25112947,-2926644 }, + { -2504044,-436966,25621774,-5678772,15085042,-5479877,-24884878,-13526194,5537438,-13914319 }, + }, +}, +{ + { + { -11225584,2320285,-9584280,10149187,-33444663,5808648,-14876251,-1729667,31234590,6090599 }, + { -9633316,116426,26083934,2897444,-6364437,-2688086,609721,15878753,-6970405,-9034768 }, + { -27757857,247744,-15194774,-9002551,23288161,-10011936,-23869595,6503646,20650474,1804084 }, + }, + { + { -27589786,15456424,8972517,8469608,15640622,4439847,3121995,-10329713,27842616,-202328 }, + { -15306973,2839644,22530074,10026331,4602058,5048462,28248656,5031932,-11375082,12714369 }, + { 20807691,-7270825,29286141,11421711,-27876523,-13868230,-21227475,1035546,-19733229,12796920 }, + }, + { + { 12076899,-14301286,-8785001,-11848922,-25012791,16400684,-17591495,-12899438,3480665,-15182815 }, + { -32361549,5457597,28548107,7833186,7303070,-11953545,-24363064,-15921875,-33374054,2771025 }, + { -21389266,421932,26597266,6860826,22486084,-6737172,-17137485,-4210226,-24552282,15673397 }, + }, + { + { -20184622,2338216,19788685,-9620956,-4001265,-8740893,-20271184,4733254,3727144,-12934448 }, + { 6120119,814863,-11794402,-622716,6812205,-15747771,2019594,7975683,31123697,-10958981 }, + { 30069250,-11435332,30434654,2958439,18399564,-976289,12296869,9204260,-16432438,9648165 }, + }, + { + { 32705432,-1550977,30705658,7451065,-11805606,9631813,3305266,5248604,-26008332,-11377501 }, + { 17219865,2375039,-31570947,-5575615,-19459679,9219903,294711,15298639,2662509,-16297073 }, + { -1172927,-7558695,-4366770,-4287744,-21346413,-8434326,32087529,-1222777,32247248,-14389861 }, + }, + { + { 14312628,1221556,17395390,-8700143,-4945741,-8684635,-28197744,-9637817,-16027623,-13378845 }, + { -1428825,-9678990,-9235681,6549687,-7383069,-468664,23046502,9803137,17597934,2346211 }, + { 18510800,15337574,26171504,981392,-22241552,7827556,-23491134,-11323352,3059833,-11782870 }, + }, + { + { 10141598,6082907,17829293,-1947643,9830092,13613136,-25556636,-5544586,-33502212,3592096 }, + { 33114168,-15889352,-26525686,-13343397,33076705,8716171,1151462,1521897,-982665,-6837803 }, + { -32939165,-4255815,23947181,-324178,-33072974,-12305637,-16637686,3891704,26353178,693168 }, + }, + { + { 30374239,1595580,-16884039,13186931,4600344,406904,9585294,-400668,31375464,14369965 }, + { -14370654,-7772529,1510301,6434173,-18784789,-6262728,32732230,-13108839,17901441,16011505 }, + { 18171223,-11934626,-12500402,15197122,-11038147,-15230035,-19172240,-16046376,8764035,12309598 }, + }, +}, +{ + { + { 5975908,-5243188,-19459362,-9681747,-11541277,14015782,-23665757,1228319,17544096,-10593782 }, + { 5811932,-1715293,3442887,-2269310,-18367348,-8359541,-18044043,-15410127,-5565381,12348900 }, + { -31399660,11407555,25755363,6891399,-3256938,14872274,-24849353,8141295,-10632534,-585479 }, + }, + { + { -12675304,694026,-5076145,13300344,14015258,-14451394,-9698672,-11329050,30944593,1130208 }, + { 8247766,-6710942,-26562381,-7709309,-14401939,-14648910,4652152,2488540,23550156,-271232 }, + { 17294316,-3788438,7026748,15626851,22990044,113481,2267737,-5908146,-408818,-137719 }, + }, + { + { 16091085,-16253926,18599252,7340678,2137637,-1221657,-3364161,14550936,3260525,-7166271 }, + { -4910104,-13332887,18550887,10864893,-16459325,-7291596,-23028869,-13204905,-12748722,2701326 }, + { -8574695,16099415,4629974,-16340524,-20786213,-6005432,-10018363,9276971,11329923,1862132 }, + }, + { + { 14763076,-15903608,-30918270,3689867,3511892,10313526,-21951088,12219231,-9037963,-940300 }, + { 8894987,-3446094,6150753,3013931,301220,15693451,-31981216,-2909717,-15438168,11595570 }, + { 15214962,3537601,-26238722,-14058872,4418657,-15230761,13947276,10730794,-13489462,-4363670 }, + }, + { + { -2538306,7682793,32759013,263109,-29984731,-7955452,-22332124,-10188635,977108,699994 }, + { -12466472,4195084,-9211532,550904,-15565337,12917920,19118110,-439841,-30534533,-14337913 }, + { 31788461,-14507657,4799989,7372237,8808585,-14747943,9408237,-10051775,12493932,-5409317 }, + }, + { + { -25680606,5260744,-19235809,-6284470,-3695942,16566087,27218280,2607121,29375955,6024730 }, + { 842132,-2794693,-4763381,-8722815,26332018,-12405641,11831880,6985184,-9940361,2854096 }, + { -4847262,-7969331,2516242,-5847713,9695691,-7221186,16512645,960770,12121869,16648078 }, + }, + { + { -15218652,14667096,-13336229,2013717,30598287,-464137,-31504922,-7882064,20237806,2838411 }, + { -19288047,4453152,15298546,-16178388,22115043,-15972604,12544294,-13470457,1068881,-12499905 }, + { -9558883,-16518835,33238498,13506958,30505848,-1114596,-8486907,-2630053,12521378,4845654 }, + }, + { + { -28198521,10744108,-2958380,10199664,7759311,-13088600,3409348,-873400,-6482306,-12885870 }, + { -23561822,6230156,-20382013,10655314,-24040585,-11621172,10477734,-1240216,-3113227,13974498 }, + { 12966261,15550616,-32038948,-1615346,21025980,-629444,5642325,7188737,18895762,12629579 }, + }, +}, +{ + { + { 14741879,-14946887,22177208,-11721237,1279741,8058600,11758140,789443,32195181,3895677 }, + { 10758205,15755439,-4509950,9243698,-4879422,6879879,-2204575,-3566119,-8982069,4429647 }, + { -2453894,15725973,-20436342,-10410672,-5803908,-11040220,-7135870,-11642895,18047436,-15281743 }, + }, + { + { -25173001,-11307165,29759956,11776784,-22262383,-15820455,10993114,-12850837,-17620701,-9408468 }, + { 21987233,700364,-24505048,14972008,-7774265,-5718395,32155026,2581431,-29958985,8773375 }, + { -25568350,454463,-13211935,16126715,25240068,8594567,20656846,12017935,-7874389,-13920155 }, + }, + { + { 6028182,6263078,-31011806,-11301710,-818919,2461772,-31841174,-5468042,-1721788,-2776725 }, + { -12278994,16624277,987579,-5922598,32908203,1248608,7719845,-4166698,28408820,6816612 }, + { -10358094,-8237829,19549651,-12169222,22082623,16147817,20613181,13982702,-10339570,5067943 }, + }, + { + { -30505967,-3821767,12074681,13582412,-19877972,2443951,-19719286,12746132,5331210,-10105944 }, + { 30528811,3601899,-1957090,4619785,-27361822,-15436388,24180793,-12570394,27679908,-1648928 }, + { 9402404,-13957065,32834043,10838634,-26580150,-13237195,26653274,-8685565,22611444,-12715406 }, + }, + { + { 22190590,1118029,22736441,15130463,-30460692,-5991321,19189625,-4648942,4854859,6622139 }, + { -8310738,-2953450,-8262579,-3388049,-10401731,-271929,13424426,-3567227,26404409,13001963 }, + { -31241838,-15415700,-2994250,8939346,11562230,-12840670,-26064365,-11621720,-15405155,11020693 }, + }, + { + { 1866042,-7949489,-7898649,-10301010,12483315,13477547,3175636,-12424163,28761762,1406734 }, + { -448555,-1777666,13018551,3194501,-9580420,-11161737,24760585,-4347088,25577411,-13378680 }, + { -24290378,4759345,-690653,-1852816,2066747,10693769,-29595790,9884936,-9368926,4745410 }, + }, + { + { -9141284,6049714,-19531061,-4341411,-31260798,9944276,-15462008,-11311852,10931924,-11931931 }, + { -16561513,14112680,-8012645,4817318,-8040464,-11414606,-22853429,10856641,-20470770,13434654 }, + { 22759489,-10073434,-16766264,-1871422,13637442,-10168091,1765144,-12654326,28445307,-5364710 }, + }, + { + { 29875063,12493613,2795536,-3786330,1710620,15181182,-10195717,-8788675,9074234,1167180 }, + { -26205683,11014233,-9842651,-2635485,-26908120,7532294,-18716888,-9535498,3843903,9367684 }, + { -10969595,-6403711,9591134,9582310,11349256,108879,16235123,8601684,-139197,4242895 }, + }, +}, +{ + { + { 22092954,-13191123,-2042793,-11968512,32186753,-11517388,-6574341,2470660,-27417366,16625501 }, + { -11057722,3042016,13770083,-9257922,584236,-544855,-7770857,2602725,-27351616,14247413 }, + { 6314175,-10264892,-32772502,15957557,-10157730,168750,-8618807,14290061,27108877,-1180880 }, + }, + { + { -8586597,-7170966,13241782,10960156,-32991015,-13794596,33547976,-11058889,-27148451,981874 }, + { 22833440,9293594,-32649448,-13618667,-9136966,14756819,-22928859,-13970780,-10479804,-16197962 }, + { -7768587,3326786,-28111797,10783824,19178761,14905060,22680049,13906969,-15933690,3797899 }, + }, + { + { 21721356,-4212746,-12206123,9310182,-3882239,-13653110,23740224,-2709232,20491983,-8042152 }, + { 9209270,-15135055,-13256557,-6167798,-731016,15289673,25947805,15286587,30997318,-6703063 }, + { 7392032,16618386,23946583,-8039892,-13265164,-1533858,-14197445,-2321576,17649998,-250080 }, + }, + { + { -9301088,-14193827,30609526,-3049543,-25175069,-1283752,-15241566,-9525724,-2233253,7662146 }, + { -17558673,1763594,-33114336,15908610,-30040870,-12174295,7335080,-8472199,-3174674,3440183 }, + { -19889700,-5977008,-24111293,-9688870,10799743,-16571957,40450,-4431835,4862400,1133 }, + }, + { + { -32856209,-7873957,-5422389,14860950,-16319031,7956142,7258061,311861,-30594991,-7379421 }, + { -3773428,-1565936,28985340,7499440,24445838,9325937,29727763,16527196,18278453,15405622 }, + { -4381906,8508652,-19898366,-3674424,-5984453,15149970,-13313598,843523,-21875062,13626197 }, + }, + { + { 2281448,-13487055,-10915418,-2609910,1879358,16164207,-10783882,3953792,13340839,15928663 }, + { 31727126,-7179855,-18437503,-8283652,2875793,-16390330,-25269894,-7014826,-23452306,5964753 }, + { 4100420,-5959452,-17179337,6017714,-18705837,12227141,-26684835,11344144,2538215,-7570755 }, + }, + { + { -9433605,6123113,11159803,-2156608,30016280,14966241,-20474983,1485421,-629256,-15958862 }, + { -26804558,4260919,11851389,9658551,-32017107,16367492,-20205425,-13191288,11659922,-11115118 }, + { 26180396,10015009,-30844224,-8581293,5418197,9480663,2231568,-10170080,33100372,-1306171 }, + }, + { + { 15121113,-5201871,-10389905,15427821,-27509937,-15992507,21670947,4486675,-5931810,-14466380 }, + { 16166486,-9483733,-11104130,6023908,-31926798,-1364923,2340060,-16254968,-10735770,-10039824 }, + { 28042865,-3557089,-12126526,12259706,-3717498,-6945899,6766453,-8689599,18036436,5803270 }, + }, +}, +{ + { + { -817581,6763912,11803561,1585585,10958447,-2671165,23855391,4598332,-6159431,-14117438 }, + { -31031306,-14256194,17332029,-2383520,31312682,-5967183,696309,50292,-20095739,11763584 }, + { -594563,-2514283,-32234153,12643980,12650761,14811489,665117,-12613632,-19773211,-10713562 }, + }, + { + { 30464590,-11262872,-4127476,-12734478,19835327,-7105613,-24396175,2075773,-17020157,992471 }, + { 18357185,-6994433,7766382,16342475,-29324918,411174,14578841,8080033,-11574335,-10601610 }, + { 19598397,10334610,12555054,2555664,18821899,-10339780,21873263,16014234,26224780,16452269 }, + }, + { + { -30223925,5145196,5944548,16385966,3976735,2009897,-11377804,-7618186,-20533829,3698650 }, + { 14187449,3448569,-10636236,-10810935,-22663880,-3433596,7268410,-10890444,27394301,12015369 }, + { 19695761,16087646,28032085,12999827,6817792,11427614,20244189,-1312777,-13259127,-3402461 }, + }, + { + { 30860103,12735208,-1888245,-4699734,-16974906,2256940,-8166013,12298312,-8550524,-10393462 }, + { -5719826,-11245325,-1910649,15569035,26642876,-7587760,-5789354,-15118654,-4976164,12651793 }, + { -2848395,9953421,11531313,-5282879,26895123,-12697089,-13118820,-16517902,9768698,-2533218 }, + }, + { + { -24719459,1894651,-287698,-4704085,15348719,-8156530,32767513,12765450,4940095,10678226 }, + { 18860224,15980149,-18987240,-1562570,-26233012,-11071856,-7843882,13944024,-24372348,16582019 }, + { -15504260,4970268,-29893044,4175593,-20993212,-2199756,-11704054,15444560,-11003761,7989037 }, + }, + { + { 31490452,5568061,-2412803,2182383,-32336847,4531686,-32078269,6200206,-19686113,-14800171 }, + { -17308668,-15879940,-31522777,-2831,-32887382,16375549,8680158,-16371713,28550068,-6857132 }, + { -28126887,-5688091,16837845,-1820458,-6850681,12700016,-30039981,4364038,1155602,5988841 }, + }, + { + { 21890435,-13272907,-12624011,12154349,-7831873,15300496,23148983,-4470481,24618407,8283181 }, + { -33136107,-10512751,9975416,6841041,-31559793,16356536,3070187,-7025928,1466169,10740210 }, + { -1509399,-15488185,-13503385,-10655916,32799044,909394,-13938903,-5779719,-32164649,-15327040 }, + }, + { + { 3960823,-14267803,-28026090,-15918051,-19404858,13146868,15567327,951507,-3260321,-573935 }, + { 24740841,5052253,-30094131,8961361,25877428,6165135,-24368180,14397372,-7380369,-6144105 }, + { -28888365,3510803,-28103278,-1158478,-11238128,-10631454,-15441463,-14453128,-1625486,-6494814 }, + }, +}, +{ + { + { 793299,-9230478,8836302,-6235707,-27360908,-2369593,33152843,-4885251,-9906200,-621852 }, + { 5666233,525582,20782575,-8038419,-24538499,14657740,16099374,1468826,-6171428,-15186581 }, + { -4859255,-3779343,-2917758,-6748019,7778750,11688288,-30404353,-9871238,-1558923,-9863646 }, + }, + { + { 10896332,-7719704,824275,472601,-19460308,3009587,25248958,14783338,-30581476,-15757844 }, + { 10566929,12612572,-31944212,11118703,-12633376,12362879,21752402,8822496,24003793,14264025 }, + { 27713862,-7355973,-11008240,9227530,27050101,2504721,23886875,-13117525,13958495,-5732453 }, + }, + { + { -23481610,4867226,-27247128,3900521,29838369,-8212291,-31889399,-10041781,7340521,-15410068 }, + { 4646514,-8011124,-22766023,-11532654,23184553,8566613,31366726,-1381061,-15066784,-10375192 }, + { -17270517,12723032,-16993061,14878794,21619651,-6197576,27584817,3093888,-8843694,3849921 }, + }, + { + { -9064912,2103172,25561640,-15125738,-5239824,9582958,32477045,-9017955,5002294,-15550259 }, + { -12057553,-11177906,21115585,-13365155,8808712,-12030708,16489530,13378448,-25845716,12741426 }, + { -5946367,10645103,-30911586,15390284,-3286982,-7118677,24306472,15852464,28834118,-7646072 }, + }, + { + { -17335748,-9107057,-24531279,9434953,-8472084,-583362,-13090771,455841,20461858,5491305 }, + { 13669248,-16095482,-12481974,-10203039,-14569770,-11893198,-24995986,11293807,-28588204,-9421832 }, + { 28497928,6272777,-33022994,14470570,8906179,-1225630,18504674,-14165166,29867745,-8795943 }, + }, + { + { -16207023,13517196,-27799630,-13697798,24009064,-6373891,-6367600,-13175392,22853429,-4012011 }, + { 24191378,16712145,-13931797,15217831,14542237,1646131,18603514,-11037887,12876623,-2112447 }, + { 17902668,4518229,-411702,-2829247,26878217,5258055,-12860753,608397,16031844,3723494 }, + }, + { + { -28632773,12763728,-20446446,7577504,33001348,-13017745,17558842,-7872890,23896954,-4314245 }, + { -20005381,-12011952,31520464,605201,2543521,5991821,-2945064,7229064,-9919646,-8826859 }, + { 28816045,298879,-28165016,-15920938,19000928,-1665890,-12680833,-2949325,-18051778,-2082915 }, + }, + { + { 16000882,-344896,3493092,-11447198,-29504595,-13159789,12577740,16041268,-19715240,7847707 }, + { 10151868,10572098,27312476,7922682,14825339,4723128,-32855931,-6519018,-10020567,3852848 }, + { -11430470,15697596,-21121557,-4420647,5386314,15063598,16514493,-15932110,29330899,-15076224 }, + }, +}, +{ + { + { -25499735,-4378794,-15222908,-6901211,16615731,2051784,3303702,15490,-27548796,12314391 }, + { 15683520,-6003043,18109120,-9980648,15337968,-5997823,-16717435,15921866,16103996,-3731215 }, + { -23169824,-10781249,13588192,-1628807,-3798557,-1074929,-19273607,5402699,-29815713,-9841101 }, + }, + { + { 23190676,2384583,-32714340,3462154,-29903655,-1529132,-11266856,8911517,-25205859,2739713 }, + { 21374101,-3554250,-33524649,9874411,15377179,11831242,-33529904,6134907,4931255,11987849 }, + { -7732,-2978858,-16223486,7277597,105524,-322051,-31480539,13861388,-30076310,10117930 }, + }, + { + { -29501170,-10744872,-26163768,13051539,-25625564,5089643,-6325503,6704079,12890019,15728940 }, + { -21972360,-11771379,-951059,-4418840,14704840,2695116,903376,-10428139,12885167,8311031 }, + { -17516482,5352194,10384213,-13811658,7506451,13453191,26423267,4384730,1888765,-5435404 }, + }, + { + { -25817338,-3107312,-13494599,-3182506,30896459,-13921729,-32251644,-12707869,-19464434,-3340243 }, + { -23607977,-2665774,-526091,4651136,5765089,4618330,6092245,14845197,17151279,-9854116 }, + { -24830458,-12733720,-15165978,10367250,-29530908,-265356,22825805,-7087279,-16866484,16176525 }, + }, + { + { -23583256,6564961,20063689,3798228,-4740178,7359225,2006182,-10363426,-28746253,-10197509 }, + { -10626600,-4486402,-13320562,-5125317,3432136,-6393229,23632037,-1940610,32808310,1099883 }, + { 15030977,5768825,-27451236,-2887299,-6427378,-15361371,-15277896,-6809350,2051441,-15225865 }, + }, + { + { -3362323,-7239372,7517890,9824992,23555850,295369,5148398,-14154188,-22686354,16633660 }, + { 4577086,-16752288,13249841,-15304328,19958763,-14537274,18559670,-10759549,8402478,-9864273 }, + { -28406330,-1051581,-26790155,-907698,-17212414,-11030789,9453451,-14980072,17983010,9967138 }, + }, + { + { -25762494,6524722,26585488,9969270,24709298,1220360,-1677990,7806337,17507396,3651560 }, + { -10420457,-4118111,14584639,15971087,-15768321,8861010,26556809,-5574557,-18553322,-11357135 }, + { 2839101,14284142,4029895,3472686,14402957,12689363,-26642121,8459447,-5605463,-7621941 }, + }, + { + { -4839289,-3535444,9744961,2871048,25113978,3187018,-25110813,-849066,17258084,-7977739 }, + { 18164541,-10595176,-17154882,-1542417,19237078,-9745295,23357533,-15217008,26908270,12150756 }, + { -30264870,-7647865,5112249,-7036672,-1499807,-6974257,43168,-5537701,-32302074,16215819 }, + }, +}, +{ + { + { -6898905,9824394,-12304779,-4401089,-31397141,-6276835,32574489,12532905,-7503072,-8675347 }, + { -27343522,-16515468,-27151524,-10722951,946346,16291093,254968,7168080,21676107,-1943028 }, + { 21260961,-8424752,-16831886,-11920822,-23677961,3968121,-3651949,-6215466,-3556191,-7913075 }, + }, + { + { 16544754,13250366,-16804428,15546242,-4583003,12757258,-2462308,-8680336,-18907032,-9662799 }, + { -2415239,-15577728,18312303,4964443,-15272530,-12653564,26820651,16690659,25459437,-4564609 }, + { -25144690,11425020,28423002,-11020557,-6144921,-15826224,9142795,-2391602,-6432418,-1644817 }, + }, + { + { -23104652,6253476,16964147,-3768872,-25113972,-12296437,-27457225,-16344658,6335692,7249989 }, + { -30333227,13979675,7503222,-12368314,-11956721,-4621693,-30272269,2682242,25993170,-12478523 }, + { 4364628,5930691,32304656,-10044554,-8054781,15091131,22857016,-10598955,31820368,15075278 }, + }, + { + { 31879134,-8918693,17258761,90626,-8041836,-4917709,24162788,-9650886,-17970238,12833045 }, + { 19073683,14851414,-24403169,-11860168,7625278,11091125,-19619190,2074449,-9413939,14905377 }, + { 24483667,-11935567,-2518866,-11547418,-1553130,15355506,-25282080,9253129,27628530,-7555480 }, + }, + { + { 17597607,8340603,19355617,552187,26198470,-3176583,4593324,-9157582,-14110875,15297016 }, + { 510886,14337390,-31785257,16638632,6328095,2713355,-20217417,-11864220,8683221,2921426 }, + { 18606791,11874196,27155355,-5281482,-24031742,6265446,-25178240,-1278924,4674690,13890525 }, + }, + { + { 13609624,13069022,-27372361,-13055908,24360586,9592974,14977157,9835105,4389687,288396 }, + { 9922506,-519394,13613107,5883594,-18758345,-434263,-12304062,8317628,23388070,16052080 }, + { 12720016,11937594,-31970060,-5028689,26900120,8561328,-20155687,-11632979,-14754271,-10812892 }, + }, + { + { 15961858,14150409,26716931,-665832,-22794328,13603569,11829573,7467844,-28822128,929275 }, + { 11038231,-11582396,-27310482,-7316562,-10498527,-16307831,-23479533,-9371869,-21393143,2465074 }, + { 20017163,-4323226,27915242,1529148,12396362,15675764,13817261,-9658066,2463391,-4622140 }, + }, + { + { -16358878,-12663911,-12065183,4996454,-1256422,1073572,9583558,12851107,4003896,12673717 }, + { -1731589,-15155870,-3262930,16143082,19294135,13385325,14741514,-9103726,7903886,2348101 }, + { 24536016,-16515207,12715592,-3862155,1511293,10047386,-3842346,-7129159,-28377538,10048127 }, + }, +}, +{ + { + { -12622226,-6204820,30718825,2591312,-10617028,12192840,18873298,-7297090,-32297756,15221632 }, + { -26478122,-11103864,11546244,-1852483,9180880,7656409,-21343950,2095755,29769758,6593415 }, + { -31994208,-2907461,4176912,3264766,12538965,-868111,26312345,-6118678,30958054,8292160 }, + }, + { + { 31429822,-13959116,29173532,15632448,12174511,-2760094,32808831,3977186,26143136,-3148876 }, + { 22648901,1402143,-22799984,13746059,7936347,365344,-8668633,-1674433,-3758243,-2304625 }, + { -15491917,8012313,-2514730,-12702462,-23965846,-10254029,-1612713,-1535569,-16664475,8194478 }, + }, + { + { 27338066,-7507420,-7414224,10140405,-19026427,-6589889,27277191,8855376,28572286,3005164 }, + { 26287124,4821776,25476601,-4145903,-3764513,-15788984,-18008582,1182479,-26094821,-13079595 }, + { -7171154,3178080,23970071,6201893,-17195577,-4489192,-21876275,-13982627,32208683,-1198248 }, + }, + { + { -16657702,2817643,-10286362,14811298,6024667,13349505,-27315504,-10497842,-27672585,-11539858 }, + { 15941029,-9405932,-21367050,8062055,31876073,-238629,-15278393,-1444429,15397331,-4130193 }, + { 8934485,-13485467,-23286397,-13423241,-32446090,14047986,31170398,-1441021,-27505566,15087184 }, + }, + { + { -18357243,-2156491,24524913,-16677868,15520427,-6360776,-15502406,11461896,16788528,-5868942 }, + { -1947386,16013773,21750665,3714552,-17401782,-16055433,-3770287,-10323320,31322514,-11615635 }, + { 21426655,-5650218,-13648287,-5347537,-28812189,-4920970,-18275391,-14621414,13040862,-12112948 }, + }, + { + { 11293895,12478086,-27136401,15083750,-29307421,14748872,14555558,-13417103,1613711,4896935 }, + { -25894883,15323294,-8489791,-8057900,25967126,-13425460,2825960,-4897045,-23971776,-11267415 }, + { -15924766,-5229880,-17443532,6410664,3622847,10243618,20615400,12405433,-23753030,-8436416 }, + }, + { + { -7091295,12556208,-20191352,9025187,-17072479,4333801,4378436,2432030,23097949,-566018 }, + { 4565804,-16025654,20084412,-7842817,1724999,189254,24767264,10103221,-18512313,2424778 }, + { 366633,-11976806,8173090,-6890119,30788634,5745705,-7168678,1344109,-3642553,12412659 }, + }, + { + { -24001791,7690286,14929416,-168257,-32210835,-13412986,24162697,-15326504,-3141501,11179385 }, + { 18289522,-14724954,8056945,16430056,-21729724,7842514,-6001441,-1486897,-18684645,-11443503 }, + { 476239,6601091,-6152790,-9723375,17503545,-4863900,27672959,13403813,11052904,5219329 }, + }, +}, +{ + { + { 20678546,-8375738,-32671898,8849123,-5009758,14574752,31186971,-3973730,9014762,-8579056 }, + { -13644050,-10350239,-15962508,5075808,-1514661,-11534600,-33102500,9160280,8473550,-3256838 }, + { 24900749,14435722,17209120,-15292541,-22592275,9878983,-7689309,-16335821,-24568481,11788948 }, + }, + { + { -3118155,-11395194,-13802089,14797441,9652448,-6845904,-20037437,10410733,-24568470,-1458691 }, + { -15659161,16736706,-22467150,10215878,-9097177,7563911,11871841,-12505194,-18513325,8464118 }, + { -23400612,8348507,-14585951,-861714,-3950205,-6373419,14325289,8628612,33313881,-8370517 }, + }, + { + { -20186973,-4967935,22367356,5271547,-1097117,-4788838,-24805667,-10236854,-8940735,-5818269 }, + { -6948785,-1795212,-32625683,-16021179,32635414,-7374245,15989197,-12838188,28358192,-4253904 }, + { -23561781,-2799059,-32351682,-1661963,-9147719,10429267,-16637684,4072016,-5351664,5596589 }, + }, + { + { -28236598,-3390048,12312896,6213178,3117142,16078565,29266239,2557221,1768301,15373193 }, + { -7243358,-3246960,-4593467,-7553353,-127927,-912245,-1090902,-4504991,-24660491,3442910 }, + { -30210571,5124043,14181784,8197961,18964734,-11939093,22597931,7176455,-18585478,13365930 }, + }, + { + { -7877390,-1499958,8324673,4690079,6261860,890446,24538107,-8570186,-9689599,-3031667 }, + { 25008904,-10771599,-4305031,-9638010,16265036,15721635,683793,-11823784,15723479,-15163481 }, + { -9660625,12374379,-27006999,-7026148,-7724114,-12314514,11879682,5400171,519526,-1235876 }, + }, + { + { 22258397,-16332233,-7869817,14613016,-22520255,-2950923,-20353881,7315967,16648397,7605640 }, + { -8081308,-8464597,-8223311,9719710,19259459,-15348212,23994942,-5281555,-9468848,4763278 }, + { -21699244,9220969,-15730624,1084137,-25476107,-2852390,31088447,-7764523,-11356529,728112 }, + }, + { + { 26047220,-11751471,-6900323,-16521798,24092068,9158119,-4273545,-12555558,-29365436,-5498272 }, + { 17510331,-322857,5854289,8403524,17133918,-3112612,-28111007,12327945,10750447,10014012 }, + { -10312768,3936952,9156313,-8897683,16498692,-994647,-27481051,-666732,3424691,7540221 }, + }, + { + { 30322361,-6964110,11361005,-4143317,7433304,4989748,-7071422,-16317219,-9244265,15258046 }, + { 13054562,-2779497,19155474,469045,-12482797,4566042,5631406,2711395,1062915,-5136345 }, + { -19240248,-11254599,-29509029,-7499965,-5835763,13005411,-6066489,12194497,32960380,1459310 }, + }, +}, +{ + { + { 19852034,7027924,23669353,10020366,8586503,-6657907,394197,-6101885,18638003,-11174937 }, + { 31395534,15098109,26581030,8030562,-16527914,-5007134,9012486,-7584354,-6643087,-5442636 }, + { -9192165,-2347377,-1997099,4529534,25766844,607986,-13222,9677543,-32294889,-6456008 }, + }, + { + { -2444496,-149937,29348902,8186665,1873760,12489863,-30934579,-7839692,-7852844,-8138429 }, + { -15236356,-15433509,7766470,746860,26346930,-10221762,-27333451,10754588,-9431476,5203576 }, + { 31834314,14135496,-770007,5159118,20917671,-16768096,-7467973,-7337524,31809243,7347066 }, + }, + { + { -9606723,-11874240,20414459,13033986,13716524,-11691881,19797970,-12211255,15192876,-2087490 }, + { -12663563,-2181719,1168162,-3804809,26747877,-14138091,10609330,12694420,33473243,-13382104 }, + { 33184999,11180355,15832085,-11385430,-1633671,225884,15089336,-11023903,-6135662,14480053 }, + }, + { + { 31308717,-5619998,31030840,-1897099,15674547,-6582883,5496208,13685227,27595050,8737275 }, + { -20318852,-15150239,10933843,-16178022,8335352,-7546022,-31008351,-12610604,26498114,66511 }, + { 22644454,-8761729,-16671776,4884562,-3105614,-13559366,30540766,-4286747,-13327787,-7515095 }, + }, + { + { -28017847,9834845,18617207,-2681312,-3401956,-13307506,8205540,13585437,-17127465,15115439 }, + { 23711543,-672915,31206561,-8362711,6164647,-9709987,-33535882,-1426096,8236921,16492939 }, + { -23910559,-13515526,-26299483,-4503841,25005590,-7687270,19574902,10071562,6708380,-6222424 }, + }, + { + { 2101391,-4930054,19702731,2367575,-15427167,1047675,5301017,9328700,29955601,-11678310 }, + { 3096359,9271816,-21620864,-15521844,-14847996,-7592937,-25892142,-12635595,-9917575,6216608 }, + { -32615849,338663,-25195611,2510422,-29213566,-13820213,24822830,-6146567,-26767480,7525079 }, + }, + { + { -23066649,-13985623,16133487,-7896178,-3389565,778788,-910336,-2782495,-19386633,11994101 }, + { 21691500,-13624626,-641331,-14367021,3285881,-3483596,-25064666,9718258,-7477437,13381418 }, + { 18445390,-4202236,14979846,11622458,-1727110,-3582980,23111648,-6375247,28535282,15779576 }, + }, + { + { 30098053,3089662,-9234387,16662135,-21306940,11308411,-14068454,12021730,9955285,-16303356 }, + { 9734894,-14576830,-7473633,-9138735,2060392,11313496,-18426029,9924399,20194861,13380996 }, + { -26378102,-7965207,-22167821,15789297,-18055342,-6168792,-1984914,15707771,26342023,10146099 }, + }, +}, +{ + { + { -26016874,-219943,21339191,-41388,19745256,-2878700,-29637280,2227040,21612326,-545728 }, + { -13077387,1184228,23562814,-5970442,-20351244,-6348714,25764461,12243797,-20856566,11649658 }, + { -10031494,11262626,27384172,2271902,26947504,-15997771,39944,6114064,33514190,2333242 }, + }, + { + { -21433588,-12421821,8119782,7219913,-21830522,-9016134,-6679750,-12670638,24350578,-13450001 }, + { -4116307,-11271533,-23886186,4843615,-30088339,690623,-31536088,-10406836,8317860,12352766 }, + { 18200138,-14475911,-33087759,-2696619,-23702521,-9102511,-23552096,-2287550,20712163,6719373 }, + }, + { + { 26656208,6075253,-7858556,1886072,-28344043,4262326,11117530,-3763210,26224235,-3297458 }, + { -17168938,-14854097,-3395676,-16369877,-19954045,14050420,21728352,9493610,18620611,-16428628 }, + { -13323321,13325349,11432106,5964811,18609221,6062965,-5269471,-9725556,-30701573,-16479657 }, + }, + { + { -23860538,-11233159,26961357,1640861,-32413112,-16737940,12248509,-5240639,13735342,1934062 }, + { 25089769,6742589,17081145,-13406266,21909293,-16067981,-15136294,-3765346,-21277997,5473616 }, + { 31883677,-7961101,1083432,-11572403,22828471,13290673,-7125085,12469656,29111212,-5451014 }, + }, + { + { 24244947,-15050407,-26262976,2791540,-14997599,16666678,24367466,6388839,-10295587,452383 }, + { -25640782,-3417841,5217916,16224624,19987036,-4082269,-24236251,-5915248,15766062,8407814 }, + { -20406999,13990231,15495425,16395525,5377168,15166495,-8917023,-4388953,-8067909,2276718 }, + }, + { + { 30157918,12924066,-17712050,9245753,19895028,3368142,-23827587,5096219,22740376,-7303417 }, + { 2041139,-14256350,7783687,13876377,-25946985,-13352459,24051124,13742383,-15637599,13295222 }, + { 33338237,-8505733,12532113,7977527,9106186,-1715251,-17720195,-4612972,-4451357,-14669444 }, + }, + { + { -20045281,5454097,-14346548,6447146,28862071,1883651,-2469266,-4141880,7770569,9620597 }, + { 23208068,7979712,33071466,8149229,1758231,-10834995,30945528,-1694323,-33502340,-14767970 }, + { 1439958,-16270480,-1079989,-793782,4625402,10647766,-5043801,1220118,30494170,-11440799 }, + }, + { + { -5037580,-13028295,-2970559,-3061767,15640974,-6701666,-26739026,926050,-1684339,-13333647 }, + { 13908495,-3549272,30919928,-6273825,-21521863,7989039,9021034,9078865,3353509,4033511 }, + { -29663431,-15113610,32259991,-344482,24295849,-12912123,23161163,8839127,27485041,7356032 }, + }, +}, +{ + { + { 9661027,705443,11980065,-5370154,-1628543,14661173,-6346142,2625015,28431036,-16771834 }, + { -23839233,-8311415,-25945511,7480958,-17681669,-8354183,-22545972,14150565,15970762,4099461 }, + { 29262576,16756590,26350592,-8793563,8529671,-11208050,13617293,-9937143,11465739,8317062 }, + }, + { + { -25493081,-6962928,32500200,-9419051,-23038724,-2302222,14898637,3848455,20969334,-5157516 }, + { -20384450,-14347713,-18336405,13884722,-33039454,2842114,-21610826,-3649888,11177095,14989547 }, + { -24496721,-11716016,16959896,2278463,12066309,10137771,13515641,2581286,-28487508,9930240 }, + }, + { + { -17751622,-2097826,16544300,-13009300,-15914807,-14949081,18345767,-13403753,16291481,-5314038 }, + { -33229194,2553288,32678213,9875984,8534129,6889387,-9676774,6957617,4368891,9788741 }, + { 16660756,7281060,-10830758,12911820,20108584,-8101676,-21722536,-8613148,16250552,-11111103 }, + }, + { + { -19765507,2390526,-16551031,14161980,1905286,6414907,4689584,10604807,-30190403,4782747 }, + { -1354539,14736941,-7367442,-13292886,7710542,-14155590,-9981571,4383045,22546403,437323 }, + { 31665577,-12180464,-16186830,1491339,-18368625,3294682,27343084,2786261,-30633590,-14097016 }, + }, + { + { -14467279,-683715,-33374107,7448552,19294360,14334329,-19690631,2355319,-19284671,-6114373 }, + { 15121312,-15796162,6377020,-6031361,-10798111,-12957845,18952177,15496498,-29380133,11754228 }, + { -2637277,-13483075,8488727,-14303896,12728761,-1622493,7141596,11724556,22761615,-10134141 }, + }, + { + { 16918416,11729663,-18083579,3022987,-31015732,-13339659,-28741185,-12227393,32851222,11717399 }, + { 11166634,7338049,-6722523,4531520,-29468672,-7302055,31474879,3483633,-1193175,-4030831 }, + { -185635,9921305,31456609,-13536438,-12013818,13348923,33142652,6546660,-19985279,-3948376 }, + }, + { + { -32460596,11266712,-11197107,-7899103,31703694,3855903,-8537131,-12833048,-30772034,-15486313 }, + { -18006477,12709068,3991746,-6479188,-21491523,-10550425,-31135347,-16049879,10928917,3011958 }, + { -6957757,-15594337,31696059,334240,29576716,14796075,-30831056,-12805180,18008031,10258577 }, + }, + { + { -22448644,15655569,7018479,-4410003,-30314266,-1201591,-1853465,1367120,25127874,6671743 }, + { 29701166,-14373934,-10878120,9279288,-17568,13127210,21382910,11042292,25838796,4642684 }, + { -20430234,14955537,-24126347,8124619,-5369288,-5990470,30468147,-13900640,18423289,4177476 }, + }, +}, diff --git a/vendor/MDBC/plugins/auth/ref10/base2.h b/vendor/MDBC/plugins/auth/ref10/base2.h new file mode 100644 index 00000000..8c538440 --- /dev/null +++ b/vendor/MDBC/plugins/auth/ref10/base2.h @@ -0,0 +1,40 @@ + { + { 25967493,-14356035,29566456,3660896,-12694345,4014787,27544626,-11754271,-6079156,2047605 }, + { -12545711,934262,-2722910,3049990,-727428,9406986,12720692,5043384,19500929,-15469378 }, + { -8738181,4489570,9688441,-14785194,10184609,-12363380,29287919,11864899,-24514362,-4438546 }, + }, + { + { 15636291,-9688557,24204773,-7912398,616977,-16685262,27787600,-14772189,28944400,-1550024 }, + { 16568933,4717097,-11556148,-1102322,15682896,-11807043,16354577,-11775962,7689662,11199574 }, + { 30464156,-5976125,-11779434,-15670865,23220365,15915852,7512774,10017326,-17749093,-9920357 }, + }, + { + { 10861363,11473154,27284546,1981175,-30064349,12577861,32867885,14515107,-15438304,10819380 }, + { 4708026,6336745,20377586,9066809,-11272109,6594696,-25653668,12483688,-12668491,5581306 }, + { 19563160,16186464,-29386857,4097519,10237984,-4348115,28542350,13850243,-23678021,-15815942 }, + }, + { + { 5153746,9909285,1723747,-2777874,30523605,5516873,19480852,5230134,-23952439,-15175766 }, + { -30269007,-3463509,7665486,10083793,28475525,1649722,20654025,16520125,30598449,7715701 }, + { 28881845,14381568,9657904,3680757,-20181635,7843316,-31400660,1370708,29794553,-1409300 }, + }, + { + { -22518993,-6692182,14201702,-8745502,-23510406,8844726,18474211,-1361450,-13062696,13821877 }, + { -6455177,-7839871,3374702,-4740862,-27098617,-10571707,31655028,-7212327,18853322,-14220951 }, + { 4566830,-12963868,-28974889,-12240689,-7602672,-2830569,-8514358,-10431137,2207753,-3209784 }, + }, + { + { -25154831,-4185821,29681144,7868801,-6854661,-9423865,-12437364,-663000,-31111463,-16132436 }, + { 25576264,-2703214,7349804,-11814844,16472782,9300885,3844789,15725684,171356,6466918 }, + { 23103977,13316479,9739013,-16149481,817875,-15038942,8965339,-14088058,-30714912,16193877 }, + }, + { + { -33521811,3180713,-2394130,14003687,-16903474,-16270840,17238398,4729455,-18074513,9256800 }, + { -25182317,-4174131,32336398,5036987,-21236817,11360617,22616405,9761698,-19827198,630305 }, + { -13720693,2639453,-24237460,-7406481,9494427,-5774029,-6554551,-15960994,-2449256,-14291300 }, + }, + { + { -3151181,-5046075,9282714,6866145,-31907062,-863023,-18940575,15033784,25105118,-7894876 }, + { -24326370,15950226,-31801215,-14592823,-11662737,-5090925,1573892,-2625887,2198790,-15804619 }, + { -3099351,10324967,-2241613,7453183,-5446979,-2735503,-13812022,-16236442,-32461234,-12290683 }, + }, diff --git a/vendor/MDBC/plugins/auth/ref10/common.h b/vendor/MDBC/plugins/auth/ref10/common.h new file mode 100644 index 00000000..4a52f774 --- /dev/null +++ b/vendor/MDBC/plugins/auth/ref10/common.h @@ -0,0 +1,23 @@ +/* + Copyright (c) 2017, MariaDB + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA */ + +#include +#include + +#include "ref10/api.h" +#include "crypto_sign.h" + +#define NONCE_BYTES 32 diff --git a/vendor/MDBC/plugins/auth/ref10/crypto_hash_sha512.h b/vendor/MDBC/plugins/auth/ref10/crypto_hash_sha512.h new file mode 100644 index 00000000..c023f30f --- /dev/null +++ b/vendor/MDBC/plugins/auth/ref10/crypto_hash_sha512.h @@ -0,0 +1,7 @@ +#if defined(MYSQL_CLIENT) || defined(LIBMARIADB) +#include +#define crypto_hash_sha512(DST,SRC,SLEN) ma_hash(MA_HASH_SHA512, SRC, SLEN, DST) +#else +#include +#define crypto_hash_sha512(DST,SRC,SLEN) my_sha512(DST,(char*)(SRC),SLEN) +#endif diff --git a/vendor/MDBC/plugins/auth/ref10/crypto_int32.h b/vendor/MDBC/plugins/auth/ref10/crypto_int32.h new file mode 100644 index 00000000..642fca05 --- /dev/null +++ b/vendor/MDBC/plugins/auth/ref10/crypto_int32.h @@ -0,0 +1,5 @@ +#include +#include +typedef int32_t crypto_int32; + +#define select ed25519_select diff --git a/vendor/MDBC/plugins/auth/ref10/crypto_int64.h b/vendor/MDBC/plugins/auth/ref10/crypto_int64.h new file mode 100644 index 00000000..a308e406 --- /dev/null +++ b/vendor/MDBC/plugins/auth/ref10/crypto_int64.h @@ -0,0 +1,5 @@ +#include +#include +typedef int64_t crypto_int64; + +#define select ed25519_select diff --git a/vendor/MDBC/plugins/auth/ref10/crypto_sign.h b/vendor/MDBC/plugins/auth/ref10/crypto_sign.h new file mode 100644 index 00000000..5f9b3437 --- /dev/null +++ b/vendor/MDBC/plugins/auth/ref10/crypto_sign.h @@ -0,0 +1,13 @@ +int crypto_sign_keypair( + unsigned char *pk, + unsigned char *pw, unsigned long long pwlen +); +int ma_crypto_sign( + unsigned char *sm, + const unsigned char *m, unsigned long long mlen, + const unsigned char *pw, unsigned long long pwlen +); +int crypto_sign_open( + unsigned char *sm, unsigned long long smlen, + const unsigned char *pk +); diff --git a/vendor/MDBC/plugins/auth/ref10/crypto_uint32.h b/vendor/MDBC/plugins/auth/ref10/crypto_uint32.h new file mode 100644 index 00000000..ab2977ca --- /dev/null +++ b/vendor/MDBC/plugins/auth/ref10/crypto_uint32.h @@ -0,0 +1,5 @@ +#include +#include +typedef uint32_t crypto_uint32; + +#define select ed25519_select diff --git a/vendor/MDBC/plugins/auth/ref10/crypto_uint64.h b/vendor/MDBC/plugins/auth/ref10/crypto_uint64.h new file mode 100644 index 00000000..029c6819 --- /dev/null +++ b/vendor/MDBC/plugins/auth/ref10/crypto_uint64.h @@ -0,0 +1,5 @@ +#include +#include +typedef uint64_t crypto_uint64; + +#define select ed25519_select diff --git a/vendor/MDBC/plugins/auth/ref10/crypto_verify.h b/vendor/MDBC/plugins/auth/ref10/crypto_verify.h new file mode 100644 index 00000000..33e11b1e --- /dev/null +++ b/vendor/MDBC/plugins/auth/ref10/crypto_verify.h @@ -0,0 +1 @@ +int crypto_verify(const unsigned char *x,const unsigned char *y); diff --git a/vendor/MDBC/plugins/auth/ref10/crypto_verify_32.h b/vendor/MDBC/plugins/auth/ref10/crypto_verify_32.h new file mode 100644 index 00000000..d8235b75 --- /dev/null +++ b/vendor/MDBC/plugins/auth/ref10/crypto_verify_32.h @@ -0,0 +1,2 @@ +#define crypto_verify_32 crypto_verify +int crypto_verify(const unsigned char *x,const unsigned char *y); diff --git a/vendor/MDBC/plugins/auth/ref10/d.h b/vendor/MDBC/plugins/auth/ref10/d.h new file mode 100644 index 00000000..e25f5783 --- /dev/null +++ b/vendor/MDBC/plugins/auth/ref10/d.h @@ -0,0 +1 @@ +-10913610,13857413,-15372611,6949391,114729,-8787816,-6275908,-3247719,-18696448,-12055116 diff --git a/vendor/MDBC/plugins/auth/ref10/d2.h b/vendor/MDBC/plugins/auth/ref10/d2.h new file mode 100644 index 00000000..01aaec75 --- /dev/null +++ b/vendor/MDBC/plugins/auth/ref10/d2.h @@ -0,0 +1 @@ +-21827239,-5839606,-30745221,13898782,229458,15978800,-12551817,-6495438,29715968,9444199 diff --git a/vendor/MDBC/plugins/auth/ref10/fe.h b/vendor/MDBC/plugins/auth/ref10/fe.h new file mode 100644 index 00000000..60c308ba --- /dev/null +++ b/vendor/MDBC/plugins/auth/ref10/fe.h @@ -0,0 +1,56 @@ +#ifndef FE_H +#define FE_H + +#include "crypto_int32.h" + +typedef crypto_int32 fe[10]; + +/* +fe means field element. +Here the field is \Z/(2^255-19). +An element t, entries t[0]...t[9], represents the integer +t[0]+2^26 t[1]+2^51 t[2]+2^77 t[3]+2^102 t[4]+...+2^230 t[9]. +Bounds on each t[i] vary depending on context. +*/ + +#define fe_frombytes crypto_sign_ed25519_ref10_fe_frombytes +#define fe_tobytes crypto_sign_ed25519_ref10_fe_tobytes +#define fe_copy crypto_sign_ed25519_ref10_fe_copy +#define fe_isnonzero crypto_sign_ed25519_ref10_fe_isnonzero +#define fe_isnegative crypto_sign_ed25519_ref10_fe_isnegative +#define fe_0 crypto_sign_ed25519_ref10_fe_0 +#define fe_1 crypto_sign_ed25519_ref10_fe_1 +#define fe_cswap crypto_sign_ed25519_ref10_fe_cswap +#define fe_cmov crypto_sign_ed25519_ref10_fe_cmov +#define fe_add crypto_sign_ed25519_ref10_fe_add +#define fe_sub crypto_sign_ed25519_ref10_fe_sub +#define fe_neg crypto_sign_ed25519_ref10_fe_neg +#define fe_mul crypto_sign_ed25519_ref10_fe_mul +#define fe_sq crypto_sign_ed25519_ref10_fe_sq +#define fe_sq2 crypto_sign_ed25519_ref10_fe_sq2 +#define fe_mul121666 crypto_sign_ed25519_ref10_fe_mul121666 +#define fe_invert crypto_sign_ed25519_ref10_fe_invert +#define fe_pow22523 crypto_sign_ed25519_ref10_fe_pow22523 + +extern void fe_frombytes(fe,const unsigned char *); +extern void fe_tobytes(unsigned char *,const fe); + +extern void fe_copy(fe,const fe); +extern int fe_isnonzero(const fe); +extern int fe_isnegative(const fe); +extern void fe_0(fe); +extern void fe_1(fe); +extern void fe_cswap(fe,fe,unsigned int); +extern void fe_cmov(fe,const fe,unsigned int); + +extern void fe_add(fe,const fe,const fe); +extern void fe_sub(fe,const fe,const fe); +extern void fe_neg(fe,const fe); +extern void fe_mul(fe,const fe,const fe); +extern void fe_sq(fe,const fe); +extern void fe_sq2(fe,const fe); +extern void fe_mul121666(fe,const fe); +extern void fe_invert(fe,const fe); +extern void fe_pow22523(fe,const fe); + +#endif diff --git a/vendor/MDBC/plugins/auth/ref10/fe_0.c b/vendor/MDBC/plugins/auth/ref10/fe_0.c new file mode 100644 index 00000000..ec879d73 --- /dev/null +++ b/vendor/MDBC/plugins/auth/ref10/fe_0.c @@ -0,0 +1,19 @@ +#include "fe.h" + +/* +h = 0 +*/ + +void fe_0(fe h) +{ + h[0] = 0; + h[1] = 0; + h[2] = 0; + h[3] = 0; + h[4] = 0; + h[5] = 0; + h[6] = 0; + h[7] = 0; + h[8] = 0; + h[9] = 0; +} diff --git a/vendor/MDBC/plugins/auth/ref10/fe_1.c b/vendor/MDBC/plugins/auth/ref10/fe_1.c new file mode 100644 index 00000000..8cf77848 --- /dev/null +++ b/vendor/MDBC/plugins/auth/ref10/fe_1.c @@ -0,0 +1,19 @@ +#include "fe.h" + +/* +h = 1 +*/ + +void fe_1(fe h) +{ + h[0] = 1; + h[1] = 0; + h[2] = 0; + h[3] = 0; + h[4] = 0; + h[5] = 0; + h[6] = 0; + h[7] = 0; + h[8] = 0; + h[9] = 0; +} diff --git a/vendor/MDBC/plugins/auth/ref10/fe_add.c b/vendor/MDBC/plugins/auth/ref10/fe_add.c new file mode 100644 index 00000000..e6a81da2 --- /dev/null +++ b/vendor/MDBC/plugins/auth/ref10/fe_add.c @@ -0,0 +1,57 @@ +#include "fe.h" + +/* +h = f + g +Can overlap h with f or g. + +Preconditions: + |f| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc. + |g| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc. + +Postconditions: + |h| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc. +*/ + +void fe_add(fe h,const fe f,const fe g) +{ + crypto_int32 f0 = f[0]; + crypto_int32 f1 = f[1]; + crypto_int32 f2 = f[2]; + crypto_int32 f3 = f[3]; + crypto_int32 f4 = f[4]; + crypto_int32 f5 = f[5]; + crypto_int32 f6 = f[6]; + crypto_int32 f7 = f[7]; + crypto_int32 f8 = f[8]; + crypto_int32 f9 = f[9]; + crypto_int32 g0 = g[0]; + crypto_int32 g1 = g[1]; + crypto_int32 g2 = g[2]; + crypto_int32 g3 = g[3]; + crypto_int32 g4 = g[4]; + crypto_int32 g5 = g[5]; + crypto_int32 g6 = g[6]; + crypto_int32 g7 = g[7]; + crypto_int32 g8 = g[8]; + crypto_int32 g9 = g[9]; + crypto_int32 h0 = f0 + g0; + crypto_int32 h1 = f1 + g1; + crypto_int32 h2 = f2 + g2; + crypto_int32 h3 = f3 + g3; + crypto_int32 h4 = f4 + g4; + crypto_int32 h5 = f5 + g5; + crypto_int32 h6 = f6 + g6; + crypto_int32 h7 = f7 + g7; + crypto_int32 h8 = f8 + g8; + crypto_int32 h9 = f9 + g9; + h[0] = h0; + h[1] = h1; + h[2] = h2; + h[3] = h3; + h[4] = h4; + h[5] = h5; + h[6] = h6; + h[7] = h7; + h[8] = h8; + h[9] = h9; +} diff --git a/vendor/MDBC/plugins/auth/ref10/fe_cmov.c b/vendor/MDBC/plugins/auth/ref10/fe_cmov.c new file mode 100644 index 00000000..8ca584fb --- /dev/null +++ b/vendor/MDBC/plugins/auth/ref10/fe_cmov.c @@ -0,0 +1,63 @@ +#include "fe.h" + +/* +Replace (f,g) with (g,g) if b == 1; +replace (f,g) with (f,g) if b == 0. + +Preconditions: b in {0,1}. +*/ + +void fe_cmov(fe f,const fe g,unsigned int b) +{ + crypto_int32 f0 = f[0]; + crypto_int32 f1 = f[1]; + crypto_int32 f2 = f[2]; + crypto_int32 f3 = f[3]; + crypto_int32 f4 = f[4]; + crypto_int32 f5 = f[5]; + crypto_int32 f6 = f[6]; + crypto_int32 f7 = f[7]; + crypto_int32 f8 = f[8]; + crypto_int32 f9 = f[9]; + crypto_int32 g0 = g[0]; + crypto_int32 g1 = g[1]; + crypto_int32 g2 = g[2]; + crypto_int32 g3 = g[3]; + crypto_int32 g4 = g[4]; + crypto_int32 g5 = g[5]; + crypto_int32 g6 = g[6]; + crypto_int32 g7 = g[7]; + crypto_int32 g8 = g[8]; + crypto_int32 g9 = g[9]; + crypto_int32 x0 = f0 ^ g0; + crypto_int32 x1 = f1 ^ g1; + crypto_int32 x2 = f2 ^ g2; + crypto_int32 x3 = f3 ^ g3; + crypto_int32 x4 = f4 ^ g4; + crypto_int32 x5 = f5 ^ g5; + crypto_int32 x6 = f6 ^ g6; + crypto_int32 x7 = f7 ^ g7; + crypto_int32 x8 = f8 ^ g8; + crypto_int32 x9 = f9 ^ g9; + b = -b; + x0 &= b; + x1 &= b; + x2 &= b; + x3 &= b; + x4 &= b; + x5 &= b; + x6 &= b; + x7 &= b; + x8 &= b; + x9 &= b; + f[0] = f0 ^ x0; + f[1] = f1 ^ x1; + f[2] = f2 ^ x2; + f[3] = f3 ^ x3; + f[4] = f4 ^ x4; + f[5] = f5 ^ x5; + f[6] = f6 ^ x6; + f[7] = f7 ^ x7; + f[8] = f8 ^ x8; + f[9] = f9 ^ x9; +} diff --git a/vendor/MDBC/plugins/auth/ref10/fe_copy.c b/vendor/MDBC/plugins/auth/ref10/fe_copy.c new file mode 100644 index 00000000..9c5bf865 --- /dev/null +++ b/vendor/MDBC/plugins/auth/ref10/fe_copy.c @@ -0,0 +1,29 @@ +#include "fe.h" + +/* +h = f +*/ + +void fe_copy(fe h,const fe f) +{ + crypto_int32 f0 = f[0]; + crypto_int32 f1 = f[1]; + crypto_int32 f2 = f[2]; + crypto_int32 f3 = f[3]; + crypto_int32 f4 = f[4]; + crypto_int32 f5 = f[5]; + crypto_int32 f6 = f[6]; + crypto_int32 f7 = f[7]; + crypto_int32 f8 = f[8]; + crypto_int32 f9 = f[9]; + h[0] = f0; + h[1] = f1; + h[2] = f2; + h[3] = f3; + h[4] = f4; + h[5] = f5; + h[6] = f6; + h[7] = f7; + h[8] = f8; + h[9] = f9; +} diff --git a/vendor/MDBC/plugins/auth/ref10/fe_frombytes.c b/vendor/MDBC/plugins/auth/ref10/fe_frombytes.c new file mode 100644 index 00000000..5c179174 --- /dev/null +++ b/vendor/MDBC/plugins/auth/ref10/fe_frombytes.c @@ -0,0 +1,73 @@ +#include "fe.h" +#include "crypto_int64.h" +#include "crypto_uint64.h" + +static crypto_uint64 load_3(const unsigned char *in) +{ + crypto_uint64 result; + result = (crypto_uint64) in[0]; + result |= ((crypto_uint64) in[1]) << 8; + result |= ((crypto_uint64) in[2]) << 16; + return result; +} + +static crypto_uint64 load_4(const unsigned char *in) +{ + crypto_uint64 result; + result = (crypto_uint64) in[0]; + result |= ((crypto_uint64) in[1]) << 8; + result |= ((crypto_uint64) in[2]) << 16; + result |= ((crypto_uint64) in[3]) << 24; + return result; +} + +/* +Ignores top bit of h. +*/ + +void fe_frombytes(fe h,const unsigned char *s) +{ + crypto_int64 h0 = load_4(s); + crypto_int64 h1 = load_3(s + 4) << 6; + crypto_int64 h2 = load_3(s + 7) << 5; + crypto_int64 h3 = load_3(s + 10) << 3; + crypto_int64 h4 = load_3(s + 13) << 2; + crypto_int64 h5 = load_4(s + 16); + crypto_int64 h6 = load_3(s + 20) << 7; + crypto_int64 h7 = load_3(s + 23) << 5; + crypto_int64 h8 = load_3(s + 26) << 4; + crypto_int64 h9 = (load_3(s + 29) & 8388607) << 2; + crypto_int64 carry0; + crypto_int64 carry1; + crypto_int64 carry2; + crypto_int64 carry3; + crypto_int64 carry4; + crypto_int64 carry5; + crypto_int64 carry6; + crypto_int64 carry7; + crypto_int64 carry8; + crypto_int64 carry9; + + carry9 = (h9 + (crypto_int64) (1<<24)) >> 25; h0 += carry9 * 19; h9 -= carry9 << 25; + carry1 = (h1 + (crypto_int64) (1<<24)) >> 25; h2 += carry1; h1 -= carry1 << 25; + carry3 = (h3 + (crypto_int64) (1<<24)) >> 25; h4 += carry3; h3 -= carry3 << 25; + carry5 = (h5 + (crypto_int64) (1<<24)) >> 25; h6 += carry5; h5 -= carry5 << 25; + carry7 = (h7 + (crypto_int64) (1<<24)) >> 25; h8 += carry7; h7 -= carry7 << 25; + + carry0 = (h0 + (crypto_int64) (1<<25)) >> 26; h1 += carry0; h0 -= carry0 << 26; + carry2 = (h2 + (crypto_int64) (1<<25)) >> 26; h3 += carry2; h2 -= carry2 << 26; + carry4 = (h4 + (crypto_int64) (1<<25)) >> 26; h5 += carry4; h4 -= carry4 << 26; + carry6 = (h6 + (crypto_int64) (1<<25)) >> 26; h7 += carry6; h6 -= carry6 << 26; + carry8 = (h8 + (crypto_int64) (1<<25)) >> 26; h9 += carry8; h8 -= carry8 << 26; + + h[0] = h0; + h[1] = h1; + h[2] = h2; + h[3] = h3; + h[4] = h4; + h[5] = h5; + h[6] = h6; + h[7] = h7; + h[8] = h8; + h[9] = h9; +} diff --git a/vendor/MDBC/plugins/auth/ref10/fe_invert.c b/vendor/MDBC/plugins/auth/ref10/fe_invert.c new file mode 100644 index 00000000..bcfdb8ff --- /dev/null +++ b/vendor/MDBC/plugins/auth/ref10/fe_invert.c @@ -0,0 +1,14 @@ +#include "fe.h" + +void fe_invert(fe out,const fe z) +{ + fe t0; + fe t1; + fe t2; + fe t3; + int i; + +#include "pow225521.h" + + return; +} diff --git a/vendor/MDBC/plugins/auth/ref10/fe_isnegative.c b/vendor/MDBC/plugins/auth/ref10/fe_isnegative.c new file mode 100644 index 00000000..3b2c8b8d --- /dev/null +++ b/vendor/MDBC/plugins/auth/ref10/fe_isnegative.c @@ -0,0 +1,16 @@ +#include "fe.h" + +/* +return 1 if f is in {1,3,5,...,q-2} +return 0 if f is in {0,2,4,...,q-1} + +Preconditions: + |f| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc. +*/ + +int fe_isnegative(const fe f) +{ + unsigned char s[32]; + fe_tobytes(s,f); + return s[0] & 1; +} diff --git a/vendor/MDBC/plugins/auth/ref10/fe_isnonzero.c b/vendor/MDBC/plugins/auth/ref10/fe_isnonzero.c new file mode 100644 index 00000000..47568001 --- /dev/null +++ b/vendor/MDBC/plugins/auth/ref10/fe_isnonzero.c @@ -0,0 +1,19 @@ +#include "fe.h" +#include "crypto_verify_32.h" + +/* +return 1 if f == 0 +return 0 if f != 0 + +Preconditions: + |f| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc. +*/ + +static const unsigned char zero[32]; + +int fe_isnonzero(const fe f) +{ + unsigned char s[32]; + fe_tobytes(s,f); + return crypto_verify_32(s,zero); +} diff --git a/vendor/MDBC/plugins/auth/ref10/fe_mul.c b/vendor/MDBC/plugins/auth/ref10/fe_mul.c new file mode 100644 index 00000000..26ca8b36 --- /dev/null +++ b/vendor/MDBC/plugins/auth/ref10/fe_mul.c @@ -0,0 +1,253 @@ +#include "fe.h" +#include "crypto_int64.h" + +/* +h = f * g +Can overlap h with f or g. + +Preconditions: + |f| bounded by 1.65*2^26,1.65*2^25,1.65*2^26,1.65*2^25,etc. + |g| bounded by 1.65*2^26,1.65*2^25,1.65*2^26,1.65*2^25,etc. + +Postconditions: + |h| bounded by 1.01*2^25,1.01*2^24,1.01*2^25,1.01*2^24,etc. +*/ + +/* +Notes on implementation strategy: + +Using schoolbook multiplication. +Karatsuba would save a little in some cost models. + +Most multiplications by 2 and 19 are 32-bit precomputations; +cheaper than 64-bit postcomputations. + +There is one remaining multiplication by 19 in the carry chain; +one *19 precomputation can be merged into this, +but the resulting data flow is considerably less clean. + +There are 12 carries below. +10 of them are 2-way parallelizable and vectorizable. +Can get away with 11 carries, but then data flow is much deeper. + +With tighter constraints on inputs can squeeze carries into int32. +*/ + +void fe_mul(fe h,const fe f,const fe g) +{ + crypto_int32 f0 = f[0]; + crypto_int32 f1 = f[1]; + crypto_int32 f2 = f[2]; + crypto_int32 f3 = f[3]; + crypto_int32 f4 = f[4]; + crypto_int32 f5 = f[5]; + crypto_int32 f6 = f[6]; + crypto_int32 f7 = f[7]; + crypto_int32 f8 = f[8]; + crypto_int32 f9 = f[9]; + crypto_int32 g0 = g[0]; + crypto_int32 g1 = g[1]; + crypto_int32 g2 = g[2]; + crypto_int32 g3 = g[3]; + crypto_int32 g4 = g[4]; + crypto_int32 g5 = g[5]; + crypto_int32 g6 = g[6]; + crypto_int32 g7 = g[7]; + crypto_int32 g8 = g[8]; + crypto_int32 g9 = g[9]; + crypto_int32 g1_19 = 19 * g1; /* 1.959375*2^29 */ + crypto_int32 g2_19 = 19 * g2; /* 1.959375*2^30; still ok */ + crypto_int32 g3_19 = 19 * g3; + crypto_int32 g4_19 = 19 * g4; + crypto_int32 g5_19 = 19 * g5; + crypto_int32 g6_19 = 19 * g6; + crypto_int32 g7_19 = 19 * g7; + crypto_int32 g8_19 = 19 * g8; + crypto_int32 g9_19 = 19 * g9; + crypto_int32 f1_2 = 2 * f1; + crypto_int32 f3_2 = 2 * f3; + crypto_int32 f5_2 = 2 * f5; + crypto_int32 f7_2 = 2 * f7; + crypto_int32 f9_2 = 2 * f9; + crypto_int64 f0g0 = f0 * (crypto_int64) g0; + crypto_int64 f0g1 = f0 * (crypto_int64) g1; + crypto_int64 f0g2 = f0 * (crypto_int64) g2; + crypto_int64 f0g3 = f0 * (crypto_int64) g3; + crypto_int64 f0g4 = f0 * (crypto_int64) g4; + crypto_int64 f0g5 = f0 * (crypto_int64) g5; + crypto_int64 f0g6 = f0 * (crypto_int64) g6; + crypto_int64 f0g7 = f0 * (crypto_int64) g7; + crypto_int64 f0g8 = f0 * (crypto_int64) g8; + crypto_int64 f0g9 = f0 * (crypto_int64) g9; + crypto_int64 f1g0 = f1 * (crypto_int64) g0; + crypto_int64 f1g1_2 = f1_2 * (crypto_int64) g1; + crypto_int64 f1g2 = f1 * (crypto_int64) g2; + crypto_int64 f1g3_2 = f1_2 * (crypto_int64) g3; + crypto_int64 f1g4 = f1 * (crypto_int64) g4; + crypto_int64 f1g5_2 = f1_2 * (crypto_int64) g5; + crypto_int64 f1g6 = f1 * (crypto_int64) g6; + crypto_int64 f1g7_2 = f1_2 * (crypto_int64) g7; + crypto_int64 f1g8 = f1 * (crypto_int64) g8; + crypto_int64 f1g9_38 = f1_2 * (crypto_int64) g9_19; + crypto_int64 f2g0 = f2 * (crypto_int64) g0; + crypto_int64 f2g1 = f2 * (crypto_int64) g1; + crypto_int64 f2g2 = f2 * (crypto_int64) g2; + crypto_int64 f2g3 = f2 * (crypto_int64) g3; + crypto_int64 f2g4 = f2 * (crypto_int64) g4; + crypto_int64 f2g5 = f2 * (crypto_int64) g5; + crypto_int64 f2g6 = f2 * (crypto_int64) g6; + crypto_int64 f2g7 = f2 * (crypto_int64) g7; + crypto_int64 f2g8_19 = f2 * (crypto_int64) g8_19; + crypto_int64 f2g9_19 = f2 * (crypto_int64) g9_19; + crypto_int64 f3g0 = f3 * (crypto_int64) g0; + crypto_int64 f3g1_2 = f3_2 * (crypto_int64) g1; + crypto_int64 f3g2 = f3 * (crypto_int64) g2; + crypto_int64 f3g3_2 = f3_2 * (crypto_int64) g3; + crypto_int64 f3g4 = f3 * (crypto_int64) g4; + crypto_int64 f3g5_2 = f3_2 * (crypto_int64) g5; + crypto_int64 f3g6 = f3 * (crypto_int64) g6; + crypto_int64 f3g7_38 = f3_2 * (crypto_int64) g7_19; + crypto_int64 f3g8_19 = f3 * (crypto_int64) g8_19; + crypto_int64 f3g9_38 = f3_2 * (crypto_int64) g9_19; + crypto_int64 f4g0 = f4 * (crypto_int64) g0; + crypto_int64 f4g1 = f4 * (crypto_int64) g1; + crypto_int64 f4g2 = f4 * (crypto_int64) g2; + crypto_int64 f4g3 = f4 * (crypto_int64) g3; + crypto_int64 f4g4 = f4 * (crypto_int64) g4; + crypto_int64 f4g5 = f4 * (crypto_int64) g5; + crypto_int64 f4g6_19 = f4 * (crypto_int64) g6_19; + crypto_int64 f4g7_19 = f4 * (crypto_int64) g7_19; + crypto_int64 f4g8_19 = f4 * (crypto_int64) g8_19; + crypto_int64 f4g9_19 = f4 * (crypto_int64) g9_19; + crypto_int64 f5g0 = f5 * (crypto_int64) g0; + crypto_int64 f5g1_2 = f5_2 * (crypto_int64) g1; + crypto_int64 f5g2 = f5 * (crypto_int64) g2; + crypto_int64 f5g3_2 = f5_2 * (crypto_int64) g3; + crypto_int64 f5g4 = f5 * (crypto_int64) g4; + crypto_int64 f5g5_38 = f5_2 * (crypto_int64) g5_19; + crypto_int64 f5g6_19 = f5 * (crypto_int64) g6_19; + crypto_int64 f5g7_38 = f5_2 * (crypto_int64) g7_19; + crypto_int64 f5g8_19 = f5 * (crypto_int64) g8_19; + crypto_int64 f5g9_38 = f5_2 * (crypto_int64) g9_19; + crypto_int64 f6g0 = f6 * (crypto_int64) g0; + crypto_int64 f6g1 = f6 * (crypto_int64) g1; + crypto_int64 f6g2 = f6 * (crypto_int64) g2; + crypto_int64 f6g3 = f6 * (crypto_int64) g3; + crypto_int64 f6g4_19 = f6 * (crypto_int64) g4_19; + crypto_int64 f6g5_19 = f6 * (crypto_int64) g5_19; + crypto_int64 f6g6_19 = f6 * (crypto_int64) g6_19; + crypto_int64 f6g7_19 = f6 * (crypto_int64) g7_19; + crypto_int64 f6g8_19 = f6 * (crypto_int64) g8_19; + crypto_int64 f6g9_19 = f6 * (crypto_int64) g9_19; + crypto_int64 f7g0 = f7 * (crypto_int64) g0; + crypto_int64 f7g1_2 = f7_2 * (crypto_int64) g1; + crypto_int64 f7g2 = f7 * (crypto_int64) g2; + crypto_int64 f7g3_38 = f7_2 * (crypto_int64) g3_19; + crypto_int64 f7g4_19 = f7 * (crypto_int64) g4_19; + crypto_int64 f7g5_38 = f7_2 * (crypto_int64) g5_19; + crypto_int64 f7g6_19 = f7 * (crypto_int64) g6_19; + crypto_int64 f7g7_38 = f7_2 * (crypto_int64) g7_19; + crypto_int64 f7g8_19 = f7 * (crypto_int64) g8_19; + crypto_int64 f7g9_38 = f7_2 * (crypto_int64) g9_19; + crypto_int64 f8g0 = f8 * (crypto_int64) g0; + crypto_int64 f8g1 = f8 * (crypto_int64) g1; + crypto_int64 f8g2_19 = f8 * (crypto_int64) g2_19; + crypto_int64 f8g3_19 = f8 * (crypto_int64) g3_19; + crypto_int64 f8g4_19 = f8 * (crypto_int64) g4_19; + crypto_int64 f8g5_19 = f8 * (crypto_int64) g5_19; + crypto_int64 f8g6_19 = f8 * (crypto_int64) g6_19; + crypto_int64 f8g7_19 = f8 * (crypto_int64) g7_19; + crypto_int64 f8g8_19 = f8 * (crypto_int64) g8_19; + crypto_int64 f8g9_19 = f8 * (crypto_int64) g9_19; + crypto_int64 f9g0 = f9 * (crypto_int64) g0; + crypto_int64 f9g1_38 = f9_2 * (crypto_int64) g1_19; + crypto_int64 f9g2_19 = f9 * (crypto_int64) g2_19; + crypto_int64 f9g3_38 = f9_2 * (crypto_int64) g3_19; + crypto_int64 f9g4_19 = f9 * (crypto_int64) g4_19; + crypto_int64 f9g5_38 = f9_2 * (crypto_int64) g5_19; + crypto_int64 f9g6_19 = f9 * (crypto_int64) g6_19; + crypto_int64 f9g7_38 = f9_2 * (crypto_int64) g7_19; + crypto_int64 f9g8_19 = f9 * (crypto_int64) g8_19; + crypto_int64 f9g9_38 = f9_2 * (crypto_int64) g9_19; + crypto_int64 h0 = f0g0+f1g9_38+f2g8_19+f3g7_38+f4g6_19+f5g5_38+f6g4_19+f7g3_38+f8g2_19+f9g1_38; + crypto_int64 h1 = f0g1+f1g0 +f2g9_19+f3g8_19+f4g7_19+f5g6_19+f6g5_19+f7g4_19+f8g3_19+f9g2_19; + crypto_int64 h2 = f0g2+f1g1_2 +f2g0 +f3g9_38+f4g8_19+f5g7_38+f6g6_19+f7g5_38+f8g4_19+f9g3_38; + crypto_int64 h3 = f0g3+f1g2 +f2g1 +f3g0 +f4g9_19+f5g8_19+f6g7_19+f7g6_19+f8g5_19+f9g4_19; + crypto_int64 h4 = f0g4+f1g3_2 +f2g2 +f3g1_2 +f4g0 +f5g9_38+f6g8_19+f7g7_38+f8g6_19+f9g5_38; + crypto_int64 h5 = f0g5+f1g4 +f2g3 +f3g2 +f4g1 +f5g0 +f6g9_19+f7g8_19+f8g7_19+f9g6_19; + crypto_int64 h6 = f0g6+f1g5_2 +f2g4 +f3g3_2 +f4g2 +f5g1_2 +f6g0 +f7g9_38+f8g8_19+f9g7_38; + crypto_int64 h7 = f0g7+f1g6 +f2g5 +f3g4 +f4g3 +f5g2 +f6g1 +f7g0 +f8g9_19+f9g8_19; + crypto_int64 h8 = f0g8+f1g7_2 +f2g6 +f3g5_2 +f4g4 +f5g3_2 +f6g2 +f7g1_2 +f8g0 +f9g9_38; + crypto_int64 h9 = f0g9+f1g8 +f2g7 +f3g6 +f4g5 +f5g4 +f6g3 +f7g2 +f8g1 +f9g0 ; + crypto_int64 carry0; + crypto_int64 carry1; + crypto_int64 carry2; + crypto_int64 carry3; + crypto_int64 carry4; + crypto_int64 carry5; + crypto_int64 carry6; + crypto_int64 carry7; + crypto_int64 carry8; + crypto_int64 carry9; + + /* + |h0| <= (1.65*1.65*2^52*(1+19+19+19+19)+1.65*1.65*2^50*(38+38+38+38+38)) + i.e. |h0| <= 1.4*2^60; narrower ranges for h2, h4, h6, h8 + |h1| <= (1.65*1.65*2^51*(1+1+19+19+19+19+19+19+19+19)) + i.e. |h1| <= 1.7*2^59; narrower ranges for h3, h5, h7, h9 + */ + + carry0 = (h0 + (crypto_int64) (1<<25)) >> 26; h1 += carry0; h0 -= carry0 << 26; + carry4 = (h4 + (crypto_int64) (1<<25)) >> 26; h5 += carry4; h4 -= carry4 << 26; + /* |h0| <= 2^25 */ + /* |h4| <= 2^25 */ + /* |h1| <= 1.71*2^59 */ + /* |h5| <= 1.71*2^59 */ + + carry1 = (h1 + (crypto_int64) (1<<24)) >> 25; h2 += carry1; h1 -= carry1 << 25; + carry5 = (h5 + (crypto_int64) (1<<24)) >> 25; h6 += carry5; h5 -= carry5 << 25; + /* |h1| <= 2^24; from now on fits into int32 */ + /* |h5| <= 2^24; from now on fits into int32 */ + /* |h2| <= 1.41*2^60 */ + /* |h6| <= 1.41*2^60 */ + + carry2 = (h2 + (crypto_int64) (1<<25)) >> 26; h3 += carry2; h2 -= carry2 << 26; + carry6 = (h6 + (crypto_int64) (1<<25)) >> 26; h7 += carry6; h6 -= carry6 << 26; + /* |h2| <= 2^25; from now on fits into int32 unchanged */ + /* |h6| <= 2^25; from now on fits into int32 unchanged */ + /* |h3| <= 1.71*2^59 */ + /* |h7| <= 1.71*2^59 */ + + carry3 = (h3 + (crypto_int64) (1<<24)) >> 25; h4 += carry3; h3 -= carry3 << 25; + carry7 = (h7 + (crypto_int64) (1<<24)) >> 25; h8 += carry7; h7 -= carry7 << 25; + /* |h3| <= 2^24; from now on fits into int32 unchanged */ + /* |h7| <= 2^24; from now on fits into int32 unchanged */ + /* |h4| <= 1.72*2^34 */ + /* |h8| <= 1.41*2^60 */ + + carry4 = (h4 + (crypto_int64) (1<<25)) >> 26; h5 += carry4; h4 -= carry4 << 26; + carry8 = (h8 + (crypto_int64) (1<<25)) >> 26; h9 += carry8; h8 -= carry8 << 26; + /* |h4| <= 2^25; from now on fits into int32 unchanged */ + /* |h8| <= 2^25; from now on fits into int32 unchanged */ + /* |h5| <= 1.01*2^24 */ + /* |h9| <= 1.71*2^59 */ + + carry9 = (h9 + (crypto_int64) (1<<24)) >> 25; h0 += carry9 * 19; h9 -= carry9 << 25; + /* |h9| <= 2^24; from now on fits into int32 unchanged */ + /* |h0| <= 1.1*2^39 */ + + carry0 = (h0 + (crypto_int64) (1<<25)) >> 26; h1 += carry0; h0 -= carry0 << 26; + /* |h0| <= 2^25; from now on fits into int32 unchanged */ + /* |h1| <= 1.01*2^24 */ + + h[0] = h0; + h[1] = h1; + h[2] = h2; + h[3] = h3; + h[4] = h4; + h[5] = h5; + h[6] = h6; + h[7] = h7; + h[8] = h8; + h[9] = h9; +} diff --git a/vendor/MDBC/plugins/auth/ref10/fe_neg.c b/vendor/MDBC/plugins/auth/ref10/fe_neg.c new file mode 100644 index 00000000..2078ce52 --- /dev/null +++ b/vendor/MDBC/plugins/auth/ref10/fe_neg.c @@ -0,0 +1,45 @@ +#include "fe.h" + +/* +h = -f + +Preconditions: + |f| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc. + +Postconditions: + |h| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc. +*/ + +void fe_neg(fe h,const fe f) +{ + crypto_int32 f0 = f[0]; + crypto_int32 f1 = f[1]; + crypto_int32 f2 = f[2]; + crypto_int32 f3 = f[3]; + crypto_int32 f4 = f[4]; + crypto_int32 f5 = f[5]; + crypto_int32 f6 = f[6]; + crypto_int32 f7 = f[7]; + crypto_int32 f8 = f[8]; + crypto_int32 f9 = f[9]; + crypto_int32 h0 = -f0; + crypto_int32 h1 = -f1; + crypto_int32 h2 = -f2; + crypto_int32 h3 = -f3; + crypto_int32 h4 = -f4; + crypto_int32 h5 = -f5; + crypto_int32 h6 = -f6; + crypto_int32 h7 = -f7; + crypto_int32 h8 = -f8; + crypto_int32 h9 = -f9; + h[0] = h0; + h[1] = h1; + h[2] = h2; + h[3] = h3; + h[4] = h4; + h[5] = h5; + h[6] = h6; + h[7] = h7; + h[8] = h8; + h[9] = h9; +} diff --git a/vendor/MDBC/plugins/auth/ref10/fe_pow22523.c b/vendor/MDBC/plugins/auth/ref10/fe_pow22523.c new file mode 100644 index 00000000..56675a59 --- /dev/null +++ b/vendor/MDBC/plugins/auth/ref10/fe_pow22523.c @@ -0,0 +1,13 @@ +#include "fe.h" + +void fe_pow22523(fe out,const fe z) +{ + fe t0; + fe t1; + fe t2; + int i; + +#include "pow22523.h" + + return; +} diff --git a/vendor/MDBC/plugins/auth/ref10/fe_sq.c b/vendor/MDBC/plugins/auth/ref10/fe_sq.c new file mode 100644 index 00000000..8dd11984 --- /dev/null +++ b/vendor/MDBC/plugins/auth/ref10/fe_sq.c @@ -0,0 +1,149 @@ +#include "fe.h" +#include "crypto_int64.h" + +/* +h = f * f +Can overlap h with f. + +Preconditions: + |f| bounded by 1.65*2^26,1.65*2^25,1.65*2^26,1.65*2^25,etc. + +Postconditions: + |h| bounded by 1.01*2^25,1.01*2^24,1.01*2^25,1.01*2^24,etc. +*/ + +/* +See fe_mul.c for discussion of implementation strategy. +*/ + +void fe_sq(fe h,const fe f) +{ + crypto_int32 f0 = f[0]; + crypto_int32 f1 = f[1]; + crypto_int32 f2 = f[2]; + crypto_int32 f3 = f[3]; + crypto_int32 f4 = f[4]; + crypto_int32 f5 = f[5]; + crypto_int32 f6 = f[6]; + crypto_int32 f7 = f[7]; + crypto_int32 f8 = f[8]; + crypto_int32 f9 = f[9]; + crypto_int32 f0_2 = 2 * f0; + crypto_int32 f1_2 = 2 * f1; + crypto_int32 f2_2 = 2 * f2; + crypto_int32 f3_2 = 2 * f3; + crypto_int32 f4_2 = 2 * f4; + crypto_int32 f5_2 = 2 * f5; + crypto_int32 f6_2 = 2 * f6; + crypto_int32 f7_2 = 2 * f7; + crypto_int32 f5_38 = 38 * f5; /* 1.959375*2^30 */ + crypto_int32 f6_19 = 19 * f6; /* 1.959375*2^30 */ + crypto_int32 f7_38 = 38 * f7; /* 1.959375*2^30 */ + crypto_int32 f8_19 = 19 * f8; /* 1.959375*2^30 */ + crypto_int32 f9_38 = 38 * f9; /* 1.959375*2^30 */ + crypto_int64 f0f0 = f0 * (crypto_int64) f0; + crypto_int64 f0f1_2 = f0_2 * (crypto_int64) f1; + crypto_int64 f0f2_2 = f0_2 * (crypto_int64) f2; + crypto_int64 f0f3_2 = f0_2 * (crypto_int64) f3; + crypto_int64 f0f4_2 = f0_2 * (crypto_int64) f4; + crypto_int64 f0f5_2 = f0_2 * (crypto_int64) f5; + crypto_int64 f0f6_2 = f0_2 * (crypto_int64) f6; + crypto_int64 f0f7_2 = f0_2 * (crypto_int64) f7; + crypto_int64 f0f8_2 = f0_2 * (crypto_int64) f8; + crypto_int64 f0f9_2 = f0_2 * (crypto_int64) f9; + crypto_int64 f1f1_2 = f1_2 * (crypto_int64) f1; + crypto_int64 f1f2_2 = f1_2 * (crypto_int64) f2; + crypto_int64 f1f3_4 = f1_2 * (crypto_int64) f3_2; + crypto_int64 f1f4_2 = f1_2 * (crypto_int64) f4; + crypto_int64 f1f5_4 = f1_2 * (crypto_int64) f5_2; + crypto_int64 f1f6_2 = f1_2 * (crypto_int64) f6; + crypto_int64 f1f7_4 = f1_2 * (crypto_int64) f7_2; + crypto_int64 f1f8_2 = f1_2 * (crypto_int64) f8; + crypto_int64 f1f9_76 = f1_2 * (crypto_int64) f9_38; + crypto_int64 f2f2 = f2 * (crypto_int64) f2; + crypto_int64 f2f3_2 = f2_2 * (crypto_int64) f3; + crypto_int64 f2f4_2 = f2_2 * (crypto_int64) f4; + crypto_int64 f2f5_2 = f2_2 * (crypto_int64) f5; + crypto_int64 f2f6_2 = f2_2 * (crypto_int64) f6; + crypto_int64 f2f7_2 = f2_2 * (crypto_int64) f7; + crypto_int64 f2f8_38 = f2_2 * (crypto_int64) f8_19; + crypto_int64 f2f9_38 = f2 * (crypto_int64) f9_38; + crypto_int64 f3f3_2 = f3_2 * (crypto_int64) f3; + crypto_int64 f3f4_2 = f3_2 * (crypto_int64) f4; + crypto_int64 f3f5_4 = f3_2 * (crypto_int64) f5_2; + crypto_int64 f3f6_2 = f3_2 * (crypto_int64) f6; + crypto_int64 f3f7_76 = f3_2 * (crypto_int64) f7_38; + crypto_int64 f3f8_38 = f3_2 * (crypto_int64) f8_19; + crypto_int64 f3f9_76 = f3_2 * (crypto_int64) f9_38; + crypto_int64 f4f4 = f4 * (crypto_int64) f4; + crypto_int64 f4f5_2 = f4_2 * (crypto_int64) f5; + crypto_int64 f4f6_38 = f4_2 * (crypto_int64) f6_19; + crypto_int64 f4f7_38 = f4 * (crypto_int64) f7_38; + crypto_int64 f4f8_38 = f4_2 * (crypto_int64) f8_19; + crypto_int64 f4f9_38 = f4 * (crypto_int64) f9_38; + crypto_int64 f5f5_38 = f5 * (crypto_int64) f5_38; + crypto_int64 f5f6_38 = f5_2 * (crypto_int64) f6_19; + crypto_int64 f5f7_76 = f5_2 * (crypto_int64) f7_38; + crypto_int64 f5f8_38 = f5_2 * (crypto_int64) f8_19; + crypto_int64 f5f9_76 = f5_2 * (crypto_int64) f9_38; + crypto_int64 f6f6_19 = f6 * (crypto_int64) f6_19; + crypto_int64 f6f7_38 = f6 * (crypto_int64) f7_38; + crypto_int64 f6f8_38 = f6_2 * (crypto_int64) f8_19; + crypto_int64 f6f9_38 = f6 * (crypto_int64) f9_38; + crypto_int64 f7f7_38 = f7 * (crypto_int64) f7_38; + crypto_int64 f7f8_38 = f7_2 * (crypto_int64) f8_19; + crypto_int64 f7f9_76 = f7_2 * (crypto_int64) f9_38; + crypto_int64 f8f8_19 = f8 * (crypto_int64) f8_19; + crypto_int64 f8f9_38 = f8 * (crypto_int64) f9_38; + crypto_int64 f9f9_38 = f9 * (crypto_int64) f9_38; + crypto_int64 h0 = f0f0 +f1f9_76+f2f8_38+f3f7_76+f4f6_38+f5f5_38; + crypto_int64 h1 = f0f1_2+f2f9_38+f3f8_38+f4f7_38+f5f6_38; + crypto_int64 h2 = f0f2_2+f1f1_2 +f3f9_76+f4f8_38+f5f7_76+f6f6_19; + crypto_int64 h3 = f0f3_2+f1f2_2 +f4f9_38+f5f8_38+f6f7_38; + crypto_int64 h4 = f0f4_2+f1f3_4 +f2f2 +f5f9_76+f6f8_38+f7f7_38; + crypto_int64 h5 = f0f5_2+f1f4_2 +f2f3_2 +f6f9_38+f7f8_38; + crypto_int64 h6 = f0f6_2+f1f5_4 +f2f4_2 +f3f3_2 +f7f9_76+f8f8_19; + crypto_int64 h7 = f0f7_2+f1f6_2 +f2f5_2 +f3f4_2 +f8f9_38; + crypto_int64 h8 = f0f8_2+f1f7_4 +f2f6_2 +f3f5_4 +f4f4 +f9f9_38; + crypto_int64 h9 = f0f9_2+f1f8_2 +f2f7_2 +f3f6_2 +f4f5_2; + crypto_int64 carry0; + crypto_int64 carry1; + crypto_int64 carry2; + crypto_int64 carry3; + crypto_int64 carry4; + crypto_int64 carry5; + crypto_int64 carry6; + crypto_int64 carry7; + crypto_int64 carry8; + crypto_int64 carry9; + + carry0 = (h0 + (crypto_int64) (1<<25)) >> 26; h1 += carry0; h0 -= carry0 << 26; + carry4 = (h4 + (crypto_int64) (1<<25)) >> 26; h5 += carry4; h4 -= carry4 << 26; + + carry1 = (h1 + (crypto_int64) (1<<24)) >> 25; h2 += carry1; h1 -= carry1 << 25; + carry5 = (h5 + (crypto_int64) (1<<24)) >> 25; h6 += carry5; h5 -= carry5 << 25; + + carry2 = (h2 + (crypto_int64) (1<<25)) >> 26; h3 += carry2; h2 -= carry2 << 26; + carry6 = (h6 + (crypto_int64) (1<<25)) >> 26; h7 += carry6; h6 -= carry6 << 26; + + carry3 = (h3 + (crypto_int64) (1<<24)) >> 25; h4 += carry3; h3 -= carry3 << 25; + carry7 = (h7 + (crypto_int64) (1<<24)) >> 25; h8 += carry7; h7 -= carry7 << 25; + + carry4 = (h4 + (crypto_int64) (1<<25)) >> 26; h5 += carry4; h4 -= carry4 << 26; + carry8 = (h8 + (crypto_int64) (1<<25)) >> 26; h9 += carry8; h8 -= carry8 << 26; + + carry9 = (h9 + (crypto_int64) (1<<24)) >> 25; h0 += carry9 * 19; h9 -= carry9 << 25; + + carry0 = (h0 + (crypto_int64) (1<<25)) >> 26; h1 += carry0; h0 -= carry0 << 26; + + h[0] = h0; + h[1] = h1; + h[2] = h2; + h[3] = h3; + h[4] = h4; + h[5] = h5; + h[6] = h6; + h[7] = h7; + h[8] = h8; + h[9] = h9; +} diff --git a/vendor/MDBC/plugins/auth/ref10/fe_sq2.c b/vendor/MDBC/plugins/auth/ref10/fe_sq2.c new file mode 100644 index 00000000..026ed3aa --- /dev/null +++ b/vendor/MDBC/plugins/auth/ref10/fe_sq2.c @@ -0,0 +1,160 @@ +#include "fe.h" +#include "crypto_int64.h" + +/* +h = 2 * f * f +Can overlap h with f. + +Preconditions: + |f| bounded by 1.65*2^26,1.65*2^25,1.65*2^26,1.65*2^25,etc. + +Postconditions: + |h| bounded by 1.01*2^25,1.01*2^24,1.01*2^25,1.01*2^24,etc. +*/ + +/* +See fe_mul.c for discussion of implementation strategy. +*/ + +void fe_sq2(fe h,const fe f) +{ + crypto_int32 f0 = f[0]; + crypto_int32 f1 = f[1]; + crypto_int32 f2 = f[2]; + crypto_int32 f3 = f[3]; + crypto_int32 f4 = f[4]; + crypto_int32 f5 = f[5]; + crypto_int32 f6 = f[6]; + crypto_int32 f7 = f[7]; + crypto_int32 f8 = f[8]; + crypto_int32 f9 = f[9]; + crypto_int32 f0_2 = 2 * f0; + crypto_int32 f1_2 = 2 * f1; + crypto_int32 f2_2 = 2 * f2; + crypto_int32 f3_2 = 2 * f3; + crypto_int32 f4_2 = 2 * f4; + crypto_int32 f5_2 = 2 * f5; + crypto_int32 f6_2 = 2 * f6; + crypto_int32 f7_2 = 2 * f7; + crypto_int32 f5_38 = 38 * f5; /* 1.959375*2^30 */ + crypto_int32 f6_19 = 19 * f6; /* 1.959375*2^30 */ + crypto_int32 f7_38 = 38 * f7; /* 1.959375*2^30 */ + crypto_int32 f8_19 = 19 * f8; /* 1.959375*2^30 */ + crypto_int32 f9_38 = 38 * f9; /* 1.959375*2^30 */ + crypto_int64 f0f0 = f0 * (crypto_int64) f0; + crypto_int64 f0f1_2 = f0_2 * (crypto_int64) f1; + crypto_int64 f0f2_2 = f0_2 * (crypto_int64) f2; + crypto_int64 f0f3_2 = f0_2 * (crypto_int64) f3; + crypto_int64 f0f4_2 = f0_2 * (crypto_int64) f4; + crypto_int64 f0f5_2 = f0_2 * (crypto_int64) f5; + crypto_int64 f0f6_2 = f0_2 * (crypto_int64) f6; + crypto_int64 f0f7_2 = f0_2 * (crypto_int64) f7; + crypto_int64 f0f8_2 = f0_2 * (crypto_int64) f8; + crypto_int64 f0f9_2 = f0_2 * (crypto_int64) f9; + crypto_int64 f1f1_2 = f1_2 * (crypto_int64) f1; + crypto_int64 f1f2_2 = f1_2 * (crypto_int64) f2; + crypto_int64 f1f3_4 = f1_2 * (crypto_int64) f3_2; + crypto_int64 f1f4_2 = f1_2 * (crypto_int64) f4; + crypto_int64 f1f5_4 = f1_2 * (crypto_int64) f5_2; + crypto_int64 f1f6_2 = f1_2 * (crypto_int64) f6; + crypto_int64 f1f7_4 = f1_2 * (crypto_int64) f7_2; + crypto_int64 f1f8_2 = f1_2 * (crypto_int64) f8; + crypto_int64 f1f9_76 = f1_2 * (crypto_int64) f9_38; + crypto_int64 f2f2 = f2 * (crypto_int64) f2; + crypto_int64 f2f3_2 = f2_2 * (crypto_int64) f3; + crypto_int64 f2f4_2 = f2_2 * (crypto_int64) f4; + crypto_int64 f2f5_2 = f2_2 * (crypto_int64) f5; + crypto_int64 f2f6_2 = f2_2 * (crypto_int64) f6; + crypto_int64 f2f7_2 = f2_2 * (crypto_int64) f7; + crypto_int64 f2f8_38 = f2_2 * (crypto_int64) f8_19; + crypto_int64 f2f9_38 = f2 * (crypto_int64) f9_38; + crypto_int64 f3f3_2 = f3_2 * (crypto_int64) f3; + crypto_int64 f3f4_2 = f3_2 * (crypto_int64) f4; + crypto_int64 f3f5_4 = f3_2 * (crypto_int64) f5_2; + crypto_int64 f3f6_2 = f3_2 * (crypto_int64) f6; + crypto_int64 f3f7_76 = f3_2 * (crypto_int64) f7_38; + crypto_int64 f3f8_38 = f3_2 * (crypto_int64) f8_19; + crypto_int64 f3f9_76 = f3_2 * (crypto_int64) f9_38; + crypto_int64 f4f4 = f4 * (crypto_int64) f4; + crypto_int64 f4f5_2 = f4_2 * (crypto_int64) f5; + crypto_int64 f4f6_38 = f4_2 * (crypto_int64) f6_19; + crypto_int64 f4f7_38 = f4 * (crypto_int64) f7_38; + crypto_int64 f4f8_38 = f4_2 * (crypto_int64) f8_19; + crypto_int64 f4f9_38 = f4 * (crypto_int64) f9_38; + crypto_int64 f5f5_38 = f5 * (crypto_int64) f5_38; + crypto_int64 f5f6_38 = f5_2 * (crypto_int64) f6_19; + crypto_int64 f5f7_76 = f5_2 * (crypto_int64) f7_38; + crypto_int64 f5f8_38 = f5_2 * (crypto_int64) f8_19; + crypto_int64 f5f9_76 = f5_2 * (crypto_int64) f9_38; + crypto_int64 f6f6_19 = f6 * (crypto_int64) f6_19; + crypto_int64 f6f7_38 = f6 * (crypto_int64) f7_38; + crypto_int64 f6f8_38 = f6_2 * (crypto_int64) f8_19; + crypto_int64 f6f9_38 = f6 * (crypto_int64) f9_38; + crypto_int64 f7f7_38 = f7 * (crypto_int64) f7_38; + crypto_int64 f7f8_38 = f7_2 * (crypto_int64) f8_19; + crypto_int64 f7f9_76 = f7_2 * (crypto_int64) f9_38; + crypto_int64 f8f8_19 = f8 * (crypto_int64) f8_19; + crypto_int64 f8f9_38 = f8 * (crypto_int64) f9_38; + crypto_int64 f9f9_38 = f9 * (crypto_int64) f9_38; + crypto_int64 h0 = f0f0 +f1f9_76+f2f8_38+f3f7_76+f4f6_38+f5f5_38; + crypto_int64 h1 = f0f1_2+f2f9_38+f3f8_38+f4f7_38+f5f6_38; + crypto_int64 h2 = f0f2_2+f1f1_2 +f3f9_76+f4f8_38+f5f7_76+f6f6_19; + crypto_int64 h3 = f0f3_2+f1f2_2 +f4f9_38+f5f8_38+f6f7_38; + crypto_int64 h4 = f0f4_2+f1f3_4 +f2f2 +f5f9_76+f6f8_38+f7f7_38; + crypto_int64 h5 = f0f5_2+f1f4_2 +f2f3_2 +f6f9_38+f7f8_38; + crypto_int64 h6 = f0f6_2+f1f5_4 +f2f4_2 +f3f3_2 +f7f9_76+f8f8_19; + crypto_int64 h7 = f0f7_2+f1f6_2 +f2f5_2 +f3f4_2 +f8f9_38; + crypto_int64 h8 = f0f8_2+f1f7_4 +f2f6_2 +f3f5_4 +f4f4 +f9f9_38; + crypto_int64 h9 = f0f9_2+f1f8_2 +f2f7_2 +f3f6_2 +f4f5_2; + crypto_int64 carry0; + crypto_int64 carry1; + crypto_int64 carry2; + crypto_int64 carry3; + crypto_int64 carry4; + crypto_int64 carry5; + crypto_int64 carry6; + crypto_int64 carry7; + crypto_int64 carry8; + crypto_int64 carry9; + + h0 += h0; + h1 += h1; + h2 += h2; + h3 += h3; + h4 += h4; + h5 += h5; + h6 += h6; + h7 += h7; + h8 += h8; + h9 += h9; + + carry0 = (h0 + (crypto_int64) (1<<25)) >> 26; h1 += carry0; h0 -= carry0 << 26; + carry4 = (h4 + (crypto_int64) (1<<25)) >> 26; h5 += carry4; h4 -= carry4 << 26; + + carry1 = (h1 + (crypto_int64) (1<<24)) >> 25; h2 += carry1; h1 -= carry1 << 25; + carry5 = (h5 + (crypto_int64) (1<<24)) >> 25; h6 += carry5; h5 -= carry5 << 25; + + carry2 = (h2 + (crypto_int64) (1<<25)) >> 26; h3 += carry2; h2 -= carry2 << 26; + carry6 = (h6 + (crypto_int64) (1<<25)) >> 26; h7 += carry6; h6 -= carry6 << 26; + + carry3 = (h3 + (crypto_int64) (1<<24)) >> 25; h4 += carry3; h3 -= carry3 << 25; + carry7 = (h7 + (crypto_int64) (1<<24)) >> 25; h8 += carry7; h7 -= carry7 << 25; + + carry4 = (h4 + (crypto_int64) (1<<25)) >> 26; h5 += carry4; h4 -= carry4 << 26; + carry8 = (h8 + (crypto_int64) (1<<25)) >> 26; h9 += carry8; h8 -= carry8 << 26; + + carry9 = (h9 + (crypto_int64) (1<<24)) >> 25; h0 += carry9 * 19; h9 -= carry9 << 25; + + carry0 = (h0 + (crypto_int64) (1<<25)) >> 26; h1 += carry0; h0 -= carry0 << 26; + + h[0] = h0; + h[1] = h1; + h[2] = h2; + h[3] = h3; + h[4] = h4; + h[5] = h5; + h[6] = h6; + h[7] = h7; + h[8] = h8; + h[9] = h9; +} diff --git a/vendor/MDBC/plugins/auth/ref10/fe_sub.c b/vendor/MDBC/plugins/auth/ref10/fe_sub.c new file mode 100644 index 00000000..6e26b7df --- /dev/null +++ b/vendor/MDBC/plugins/auth/ref10/fe_sub.c @@ -0,0 +1,57 @@ +#include "fe.h" + +/* +h = f - g +Can overlap h with f or g. + +Preconditions: + |f| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc. + |g| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc. + +Postconditions: + |h| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc. +*/ + +void fe_sub(fe h,const fe f,const fe g) +{ + crypto_int32 f0 = f[0]; + crypto_int32 f1 = f[1]; + crypto_int32 f2 = f[2]; + crypto_int32 f3 = f[3]; + crypto_int32 f4 = f[4]; + crypto_int32 f5 = f[5]; + crypto_int32 f6 = f[6]; + crypto_int32 f7 = f[7]; + crypto_int32 f8 = f[8]; + crypto_int32 f9 = f[9]; + crypto_int32 g0 = g[0]; + crypto_int32 g1 = g[1]; + crypto_int32 g2 = g[2]; + crypto_int32 g3 = g[3]; + crypto_int32 g4 = g[4]; + crypto_int32 g5 = g[5]; + crypto_int32 g6 = g[6]; + crypto_int32 g7 = g[7]; + crypto_int32 g8 = g[8]; + crypto_int32 g9 = g[9]; + crypto_int32 h0 = f0 - g0; + crypto_int32 h1 = f1 - g1; + crypto_int32 h2 = f2 - g2; + crypto_int32 h3 = f3 - g3; + crypto_int32 h4 = f4 - g4; + crypto_int32 h5 = f5 - g5; + crypto_int32 h6 = f6 - g6; + crypto_int32 h7 = f7 - g7; + crypto_int32 h8 = f8 - g8; + crypto_int32 h9 = f9 - g9; + h[0] = h0; + h[1] = h1; + h[2] = h2; + h[3] = h3; + h[4] = h4; + h[5] = h5; + h[6] = h6; + h[7] = h7; + h[8] = h8; + h[9] = h9; +} diff --git a/vendor/MDBC/plugins/auth/ref10/fe_tobytes.c b/vendor/MDBC/plugins/auth/ref10/fe_tobytes.c new file mode 100644 index 00000000..0a63baf9 --- /dev/null +++ b/vendor/MDBC/plugins/auth/ref10/fe_tobytes.c @@ -0,0 +1,119 @@ +#include "fe.h" + +/* +Preconditions: + |h| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc. + +Write p=2^255-19; q=floor(h/p). +Basic claim: q = floor(2^(-255)(h + 19 2^(-25)h9 + 2^(-1))). + +Proof: + Have |h|<=p so |q|<=1 so |19^2 2^(-255) q|<1/4. + Also have |h-2^230 h9|<2^231 so |19 2^(-255)(h-2^230 h9)|<1/4. + + Write y=2^(-1)-19^2 2^(-255)q-19 2^(-255)(h-2^230 h9). + Then 0> 25; + q = (h0 + q) >> 26; + q = (h1 + q) >> 25; + q = (h2 + q) >> 26; + q = (h3 + q) >> 25; + q = (h4 + q) >> 26; + q = (h5 + q) >> 25; + q = (h6 + q) >> 26; + q = (h7 + q) >> 25; + q = (h8 + q) >> 26; + q = (h9 + q) >> 25; + + /* Goal: Output h-(2^255-19)q, which is between 0 and 2^255-20. */ + h0 += 19 * q; + /* Goal: Output h-2^255 q, which is between 0 and 2^255-20. */ + + carry0 = h0 >> 26; h1 += carry0; h0 -= carry0 << 26; + carry1 = h1 >> 25; h2 += carry1; h1 -= carry1 << 25; + carry2 = h2 >> 26; h3 += carry2; h2 -= carry2 << 26; + carry3 = h3 >> 25; h4 += carry3; h3 -= carry3 << 25; + carry4 = h4 >> 26; h5 += carry4; h4 -= carry4 << 26; + carry5 = h5 >> 25; h6 += carry5; h5 -= carry5 << 25; + carry6 = h6 >> 26; h7 += carry6; h6 -= carry6 << 26; + carry7 = h7 >> 25; h8 += carry7; h7 -= carry7 << 25; + carry8 = h8 >> 26; h9 += carry8; h8 -= carry8 << 26; + carry9 = h9 >> 25; h9 -= carry9 << 25; + /* h10 = carry9 */ + + /* + Goal: Output h0+...+2^255 h10-2^255 q, which is between 0 and 2^255-20. + Have h0+...+2^230 h9 between 0 and 2^255-1; + evidently 2^255 h10-2^255 q = 0. + Goal: Output h0+...+2^230 h9. + */ + + s[0] = h0 >> 0; + s[1] = h0 >> 8; + s[2] = h0 >> 16; + s[3] = (h0 >> 24) | (h1 << 2); + s[4] = h1 >> 6; + s[5] = h1 >> 14; + s[6] = (h1 >> 22) | (h2 << 3); + s[7] = h2 >> 5; + s[8] = h2 >> 13; + s[9] = (h2 >> 21) | (h3 << 5); + s[10] = h3 >> 3; + s[11] = h3 >> 11; + s[12] = (h3 >> 19) | (h4 << 6); + s[13] = h4 >> 2; + s[14] = h4 >> 10; + s[15] = h4 >> 18; + s[16] = h5 >> 0; + s[17] = h5 >> 8; + s[18] = h5 >> 16; + s[19] = (h5 >> 24) | (h6 << 1); + s[20] = h6 >> 7; + s[21] = h6 >> 15; + s[22] = (h6 >> 23) | (h7 << 3); + s[23] = h7 >> 5; + s[24] = h7 >> 13; + s[25] = (h7 >> 21) | (h8 << 4); + s[26] = h8 >> 4; + s[27] = h8 >> 12; + s[28] = (h8 >> 20) | (h9 << 6); + s[29] = h9 >> 2; + s[30] = h9 >> 10; + s[31] = h9 >> 18; +} diff --git a/vendor/MDBC/plugins/auth/ref10/ge.h b/vendor/MDBC/plugins/auth/ref10/ge.h new file mode 100644 index 00000000..55e95f95 --- /dev/null +++ b/vendor/MDBC/plugins/auth/ref10/ge.h @@ -0,0 +1,95 @@ +#ifndef GE_H +#define GE_H + +/* +ge means group element. + +Here the group is the set of pairs (x,y) of field elements (see fe.h) +satisfying -x^2 + y^2 = 1 + d x^2y^2 +where d = -121665/121666. + +Representations: + ge_p2 (projective): (X:Y:Z) satisfying x=X/Z, y=Y/Z + ge_p3 (extended): (X:Y:Z:T) satisfying x=X/Z, y=Y/Z, XY=ZT + ge_p1p1 (completed): ((X:Z),(Y:T)) satisfying x=X/Z, y=Y/T + ge_precomp (Duif): (y+x,y-x,2dxy) +*/ + +#include "fe.h" + +typedef struct { + fe X; + fe Y; + fe Z; +} ge_p2; + +typedef struct { + fe X; + fe Y; + fe Z; + fe T; +} ge_p3; + +typedef struct { + fe X; + fe Y; + fe Z; + fe T; +} ge_p1p1; + +typedef struct { + fe yplusx; + fe yminusx; + fe xy2d; +} ge_precomp; + +typedef struct { + fe YplusX; + fe YminusX; + fe Z; + fe T2d; +} ge_cached; + +#define ge_frombytes_negate_vartime crypto_sign_ed25519_ref10_ge_frombytes_negate_vartime +#define ge_tobytes crypto_sign_ed25519_ref10_ge_tobytes +#define ge_p3_tobytes crypto_sign_ed25519_ref10_ge_p3_tobytes + +#define ge_p2_0 crypto_sign_ed25519_ref10_ge_p2_0 +#define ge_p3_0 crypto_sign_ed25519_ref10_ge_p3_0 +#define ge_precomp_0 crypto_sign_ed25519_ref10_ge_precomp_0 +#define ge_p3_to_p2 crypto_sign_ed25519_ref10_ge_p3_to_p2 +#define ge_p3_to_cached crypto_sign_ed25519_ref10_ge_p3_to_cached +#define ge_p1p1_to_p2 crypto_sign_ed25519_ref10_ge_p1p1_to_p2 +#define ge_p1p1_to_p3 crypto_sign_ed25519_ref10_ge_p1p1_to_p3 +#define ge_p2_dbl crypto_sign_ed25519_ref10_ge_p2_dbl +#define ge_p3_dbl crypto_sign_ed25519_ref10_ge_p3_dbl + +#define ge_madd crypto_sign_ed25519_ref10_ge_madd +#define ge_msub crypto_sign_ed25519_ref10_ge_msub +#define ge_add crypto_sign_ed25519_ref10_ge_add +#define ge_sub crypto_sign_ed25519_ref10_ge_sub +#define ge_scalarmult_base crypto_sign_ed25519_ref10_ge_scalarmult_base +#define ge_double_scalarmult_vartime crypto_sign_ed25519_ref10_ge_double_scalarmult_vartime + +extern void ge_tobytes(unsigned char *,const ge_p2 *); +extern void ge_p3_tobytes(unsigned char *,const ge_p3 *); +extern int ge_frombytes_negate_vartime(ge_p3 *,const unsigned char *); + +extern void ge_p2_0(ge_p2 *); +extern void ge_p3_0(ge_p3 *); +extern void ge_precomp_0(ge_precomp *); +extern void ge_p3_to_p2(ge_p2 *,const ge_p3 *); +extern void ge_p3_to_cached(ge_cached *,const ge_p3 *); +extern void ge_p1p1_to_p2(ge_p2 *,const ge_p1p1 *); +extern void ge_p1p1_to_p3(ge_p3 *,const ge_p1p1 *); +extern void ge_p2_dbl(ge_p1p1 *,const ge_p2 *); +extern void ge_p3_dbl(ge_p1p1 *,const ge_p3 *); + +extern void ge_madd(ge_p1p1 *,const ge_p3 *,const ge_precomp *); +extern void ge_msub(ge_p1p1 *,const ge_p3 *,const ge_precomp *); +extern void ge_add(ge_p1p1 *,const ge_p3 *,const ge_cached *); +extern void ge_sub(ge_p1p1 *,const ge_p3 *,const ge_cached *); +extern void ge_scalarmult_base(ge_p3 *,const unsigned char *); +extern void ge_double_scalarmult_vartime(ge_p2 *,const unsigned char *,const ge_p3 *,const unsigned char *); + +#endif diff --git a/vendor/MDBC/plugins/auth/ref10/ge_add.c b/vendor/MDBC/plugins/auth/ref10/ge_add.c new file mode 100644 index 00000000..da7ff5d2 --- /dev/null +++ b/vendor/MDBC/plugins/auth/ref10/ge_add.c @@ -0,0 +1,11 @@ +#include "ge.h" + +/* +r = p + q +*/ + +void ge_add(ge_p1p1 *r,const ge_p3 *p,const ge_cached *q) +{ + fe t0; +#include "ge_add.h" +} diff --git a/vendor/MDBC/plugins/auth/ref10/ge_add.h b/vendor/MDBC/plugins/auth/ref10/ge_add.h new file mode 100644 index 00000000..7481f8ff --- /dev/null +++ b/vendor/MDBC/plugins/auth/ref10/ge_add.h @@ -0,0 +1,97 @@ + +/* qhasm: enter ge_add */ + +/* qhasm: fe X1 */ + +/* qhasm: fe Y1 */ + +/* qhasm: fe Z1 */ + +/* qhasm: fe Z2 */ + +/* qhasm: fe T1 */ + +/* qhasm: fe ZZ */ + +/* qhasm: fe YpX2 */ + +/* qhasm: fe YmX2 */ + +/* qhasm: fe T2d2 */ + +/* qhasm: fe X3 */ + +/* qhasm: fe Y3 */ + +/* qhasm: fe Z3 */ + +/* qhasm: fe T3 */ + +/* qhasm: fe YpX1 */ + +/* qhasm: fe YmX1 */ + +/* qhasm: fe A */ + +/* qhasm: fe B */ + +/* qhasm: fe C */ + +/* qhasm: fe D */ + +/* qhasm: YpX1 = Y1+X1 */ +/* asm 1: fe_add(>YpX1=fe#1,YpX1=r->X,Y,X); */ +fe_add(r->X,p->Y,p->X); + +/* qhasm: YmX1 = Y1-X1 */ +/* asm 1: fe_sub(>YmX1=fe#2,YmX1=r->Y,Y,X); */ +fe_sub(r->Y,p->Y,p->X); + +/* qhasm: A = YpX1*YpX2 */ +/* asm 1: fe_mul(>A=fe#3,A=r->Z,X,YplusX); */ +fe_mul(r->Z,r->X,q->YplusX); + +/* qhasm: B = YmX1*YmX2 */ +/* asm 1: fe_mul(>B=fe#2,B=r->Y,Y,YminusX); */ +fe_mul(r->Y,r->Y,q->YminusX); + +/* qhasm: C = T2d2*T1 */ +/* asm 1: fe_mul(>C=fe#4,C=r->T,T2d,T); */ +fe_mul(r->T,q->T2d,p->T); + +/* qhasm: ZZ = Z1*Z2 */ +/* asm 1: fe_mul(>ZZ=fe#1,ZZ=r->X,Z,Z); */ +fe_mul(r->X,p->Z,q->Z); + +/* qhasm: D = 2*ZZ */ +/* asm 1: fe_add(>D=fe#5,D=t0,X,X); */ +fe_add(t0,r->X,r->X); + +/* qhasm: X3 = A-B */ +/* asm 1: fe_sub(>X3=fe#1,X3=r->X,Z,Y); */ +fe_sub(r->X,r->Z,r->Y); + +/* qhasm: Y3 = A+B */ +/* asm 1: fe_add(>Y3=fe#2,Y3=r->Y,Z,Y); */ +fe_add(r->Y,r->Z,r->Y); + +/* qhasm: Z3 = D+C */ +/* asm 1: fe_add(>Z3=fe#3,Z3=r->Z,T); */ +fe_add(r->Z,t0,r->T); + +/* qhasm: T3 = D-C */ +/* asm 1: fe_sub(>T3=fe#4,T3=r->T,T); */ +fe_sub(r->T,t0,r->T); + +/* qhasm: return */ diff --git a/vendor/MDBC/plugins/auth/ref10/ge_double_scalarmult.c b/vendor/MDBC/plugins/auth/ref10/ge_double_scalarmult.c new file mode 100644 index 00000000..f8bf4bf7 --- /dev/null +++ b/vendor/MDBC/plugins/auth/ref10/ge_double_scalarmult.c @@ -0,0 +1,96 @@ +#include "ge.h" + +static void slide(signed char *r,const unsigned char *a) +{ + int i; + int b; + int k; + + for (i = 0;i < 256;++i) + r[i] = 1 & (a[i >> 3] >> (i & 7)); + + for (i = 0;i < 256;++i) + if (r[i]) { + for (b = 1;b <= 6 && i + b < 256;++b) { + if (r[i + b]) { + if (r[i] + (r[i + b] << b) <= 15) { + r[i] += r[i + b] << b; r[i + b] = 0; + } else if (r[i] - (r[i + b] << b) >= -15) { + r[i] -= r[i + b] << b; + for (k = i + b;k < 256;++k) { + if (!r[k]) { + r[k] = 1; + break; + } + r[k] = 0; + } + } else + break; + } + } + } + +} + +static ge_precomp Bi[8] = { +#include "base2.h" +} ; + +/* +r = a * A + b * B +where a = a[0]+256*a[1]+...+256^31 a[31]. +and b = b[0]+256*b[1]+...+256^31 b[31]. +B is the Ed25519 base point (x,4/5) with x positive. +*/ + +void ge_double_scalarmult_vartime(ge_p2 *r,const unsigned char *a,const ge_p3 *A,const unsigned char *b) +{ + signed char aslide[256]; + signed char bslide[256]; + ge_cached Ai[8]; /* A,3A,5A,7A,9A,11A,13A,15A */ + ge_p1p1 t; + ge_p3 u; + ge_p3 A2; + int i; + + slide(aslide,a); + slide(bslide,b); + + ge_p3_to_cached(&Ai[0],A); + ge_p3_dbl(&t,A); ge_p1p1_to_p3(&A2,&t); + ge_add(&t,&A2,&Ai[0]); ge_p1p1_to_p3(&u,&t); ge_p3_to_cached(&Ai[1],&u); + ge_add(&t,&A2,&Ai[1]); ge_p1p1_to_p3(&u,&t); ge_p3_to_cached(&Ai[2],&u); + ge_add(&t,&A2,&Ai[2]); ge_p1p1_to_p3(&u,&t); ge_p3_to_cached(&Ai[3],&u); + ge_add(&t,&A2,&Ai[3]); ge_p1p1_to_p3(&u,&t); ge_p3_to_cached(&Ai[4],&u); + ge_add(&t,&A2,&Ai[4]); ge_p1p1_to_p3(&u,&t); ge_p3_to_cached(&Ai[5],&u); + ge_add(&t,&A2,&Ai[5]); ge_p1p1_to_p3(&u,&t); ge_p3_to_cached(&Ai[6],&u); + ge_add(&t,&A2,&Ai[6]); ge_p1p1_to_p3(&u,&t); ge_p3_to_cached(&Ai[7],&u); + + ge_p2_0(r); + + for (i = 255;i >= 0;--i) { + if (aslide[i] || bslide[i]) break; + } + + for (;i >= 0;--i) { + ge_p2_dbl(&t,r); + + if (aslide[i] > 0) { + ge_p1p1_to_p3(&u,&t); + ge_add(&t,&u,&Ai[aslide[i]/2]); + } else if (aslide[i] < 0) { + ge_p1p1_to_p3(&u,&t); + ge_sub(&t,&u,&Ai[(-aslide[i])/2]); + } + + if (bslide[i] > 0) { + ge_p1p1_to_p3(&u,&t); + ge_madd(&t,&u,&Bi[bslide[i]/2]); + } else if (bslide[i] < 0) { + ge_p1p1_to_p3(&u,&t); + ge_msub(&t,&u,&Bi[(-bslide[i])/2]); + } + + ge_p1p1_to_p2(r,&t); + } +} diff --git a/vendor/MDBC/plugins/auth/ref10/ge_frombytes.c b/vendor/MDBC/plugins/auth/ref10/ge_frombytes.c new file mode 100644 index 00000000..1a059ee9 --- /dev/null +++ b/vendor/MDBC/plugins/auth/ref10/ge_frombytes.c @@ -0,0 +1,50 @@ +#include "ge.h" + +static const fe d = { +#include "d.h" +} ; + +static const fe sqrtm1 = { +#include "sqrtm1.h" +} ; + +int ge_frombytes_negate_vartime(ge_p3 *h,const unsigned char *s) +{ + fe u; + fe v; + fe v3; + fe vxx; + fe check; + + fe_frombytes(h->Y,s); + fe_1(h->Z); + fe_sq(u,h->Y); + fe_mul(v,u,d); + fe_sub(u,u,h->Z); /* u = y^2-1 */ + fe_add(v,v,h->Z); /* v = dy^2+1 */ + + fe_sq(v3,v); + fe_mul(v3,v3,v); /* v3 = v^3 */ + fe_sq(h->X,v3); + fe_mul(h->X,h->X,v); + fe_mul(h->X,h->X,u); /* x = uv^7 */ + + fe_pow22523(h->X,h->X); /* x = (uv^7)^((q-5)/8) */ + fe_mul(h->X,h->X,v3); + fe_mul(h->X,h->X,u); /* x = uv^3(uv^7)^((q-5)/8) */ + + fe_sq(vxx,h->X); + fe_mul(vxx,vxx,v); + fe_sub(check,vxx,u); /* vx^2-u */ + if (fe_isnonzero(check)) { + fe_add(check,vxx,u); /* vx^2+u */ + if (fe_isnonzero(check)) return -1; + fe_mul(h->X,h->X,sqrtm1); + } + + if (fe_isnegative(h->X) == (s[31] >> 7)) + fe_neg(h->X,h->X); + + fe_mul(h->T,h->X,h->Y); + return 0; +} diff --git a/vendor/MDBC/plugins/auth/ref10/ge_madd.c b/vendor/MDBC/plugins/auth/ref10/ge_madd.c new file mode 100644 index 00000000..62257177 --- /dev/null +++ b/vendor/MDBC/plugins/auth/ref10/ge_madd.c @@ -0,0 +1,11 @@ +#include "ge.h" + +/* +r = p + q +*/ + +void ge_madd(ge_p1p1 *r,const ge_p3 *p,const ge_precomp *q) +{ + fe t0; +#include "ge_madd.h" +} diff --git a/vendor/MDBC/plugins/auth/ref10/ge_madd.h b/vendor/MDBC/plugins/auth/ref10/ge_madd.h new file mode 100644 index 00000000..ecae8495 --- /dev/null +++ b/vendor/MDBC/plugins/auth/ref10/ge_madd.h @@ -0,0 +1,88 @@ + +/* qhasm: enter ge_madd */ + +/* qhasm: fe X1 */ + +/* qhasm: fe Y1 */ + +/* qhasm: fe Z1 */ + +/* qhasm: fe T1 */ + +/* qhasm: fe ypx2 */ + +/* qhasm: fe ymx2 */ + +/* qhasm: fe xy2d2 */ + +/* qhasm: fe X3 */ + +/* qhasm: fe Y3 */ + +/* qhasm: fe Z3 */ + +/* qhasm: fe T3 */ + +/* qhasm: fe YpX1 */ + +/* qhasm: fe YmX1 */ + +/* qhasm: fe A */ + +/* qhasm: fe B */ + +/* qhasm: fe C */ + +/* qhasm: fe D */ + +/* qhasm: YpX1 = Y1+X1 */ +/* asm 1: fe_add(>YpX1=fe#1,YpX1=r->X,Y,X); */ +fe_add(r->X,p->Y,p->X); + +/* qhasm: YmX1 = Y1-X1 */ +/* asm 1: fe_sub(>YmX1=fe#2,YmX1=r->Y,Y,X); */ +fe_sub(r->Y,p->Y,p->X); + +/* qhasm: A = YpX1*ypx2 */ +/* asm 1: fe_mul(>A=fe#3,A=r->Z,X,yplusx); */ +fe_mul(r->Z,r->X,q->yplusx); + +/* qhasm: B = YmX1*ymx2 */ +/* asm 1: fe_mul(>B=fe#2,B=r->Y,Y,yminusx); */ +fe_mul(r->Y,r->Y,q->yminusx); + +/* qhasm: C = xy2d2*T1 */ +/* asm 1: fe_mul(>C=fe#4,C=r->T,xy2d,T); */ +fe_mul(r->T,q->xy2d,p->T); + +/* qhasm: D = 2*Z1 */ +/* asm 1: fe_add(>D=fe#5,D=t0,Z,Z); */ +fe_add(t0,p->Z,p->Z); + +/* qhasm: X3 = A-B */ +/* asm 1: fe_sub(>X3=fe#1,X3=r->X,Z,Y); */ +fe_sub(r->X,r->Z,r->Y); + +/* qhasm: Y3 = A+B */ +/* asm 1: fe_add(>Y3=fe#2,Y3=r->Y,Z,Y); */ +fe_add(r->Y,r->Z,r->Y); + +/* qhasm: Z3 = D+C */ +/* asm 1: fe_add(>Z3=fe#3,Z3=r->Z,T); */ +fe_add(r->Z,t0,r->T); + +/* qhasm: T3 = D-C */ +/* asm 1: fe_sub(>T3=fe#4,T3=r->T,T); */ +fe_sub(r->T,t0,r->T); + +/* qhasm: return */ diff --git a/vendor/MDBC/plugins/auth/ref10/ge_msub.c b/vendor/MDBC/plugins/auth/ref10/ge_msub.c new file mode 100644 index 00000000..741ecbf1 --- /dev/null +++ b/vendor/MDBC/plugins/auth/ref10/ge_msub.c @@ -0,0 +1,11 @@ +#include "ge.h" + +/* +r = p - q +*/ + +void ge_msub(ge_p1p1 *r,const ge_p3 *p,const ge_precomp *q) +{ + fe t0; +#include "ge_msub.h" +} diff --git a/vendor/MDBC/plugins/auth/ref10/ge_msub.h b/vendor/MDBC/plugins/auth/ref10/ge_msub.h new file mode 100644 index 00000000..500f986b --- /dev/null +++ b/vendor/MDBC/plugins/auth/ref10/ge_msub.h @@ -0,0 +1,88 @@ + +/* qhasm: enter ge_msub */ + +/* qhasm: fe X1 */ + +/* qhasm: fe Y1 */ + +/* qhasm: fe Z1 */ + +/* qhasm: fe T1 */ + +/* qhasm: fe ypx2 */ + +/* qhasm: fe ymx2 */ + +/* qhasm: fe xy2d2 */ + +/* qhasm: fe X3 */ + +/* qhasm: fe Y3 */ + +/* qhasm: fe Z3 */ + +/* qhasm: fe T3 */ + +/* qhasm: fe YpX1 */ + +/* qhasm: fe YmX1 */ + +/* qhasm: fe A */ + +/* qhasm: fe B */ + +/* qhasm: fe C */ + +/* qhasm: fe D */ + +/* qhasm: YpX1 = Y1+X1 */ +/* asm 1: fe_add(>YpX1=fe#1,YpX1=r->X,Y,X); */ +fe_add(r->X,p->Y,p->X); + +/* qhasm: YmX1 = Y1-X1 */ +/* asm 1: fe_sub(>YmX1=fe#2,YmX1=r->Y,Y,X); */ +fe_sub(r->Y,p->Y,p->X); + +/* qhasm: A = YpX1*ymx2 */ +/* asm 1: fe_mul(>A=fe#3,A=r->Z,X,yminusx); */ +fe_mul(r->Z,r->X,q->yminusx); + +/* qhasm: B = YmX1*ypx2 */ +/* asm 1: fe_mul(>B=fe#2,B=r->Y,Y,yplusx); */ +fe_mul(r->Y,r->Y,q->yplusx); + +/* qhasm: C = xy2d2*T1 */ +/* asm 1: fe_mul(>C=fe#4,C=r->T,xy2d,T); */ +fe_mul(r->T,q->xy2d,p->T); + +/* qhasm: D = 2*Z1 */ +/* asm 1: fe_add(>D=fe#5,D=t0,Z,Z); */ +fe_add(t0,p->Z,p->Z); + +/* qhasm: X3 = A-B */ +/* asm 1: fe_sub(>X3=fe#1,X3=r->X,Z,Y); */ +fe_sub(r->X,r->Z,r->Y); + +/* qhasm: Y3 = A+B */ +/* asm 1: fe_add(>Y3=fe#2,Y3=r->Y,Z,Y); */ +fe_add(r->Y,r->Z,r->Y); + +/* qhasm: Z3 = D-C */ +/* asm 1: fe_sub(>Z3=fe#3,Z3=r->Z,T); */ +fe_sub(r->Z,t0,r->T); + +/* qhasm: T3 = D+C */ +/* asm 1: fe_add(>T3=fe#4,T3=r->T,T); */ +fe_add(r->T,t0,r->T); + +/* qhasm: return */ diff --git a/vendor/MDBC/plugins/auth/ref10/ge_p1p1_to_p2.c b/vendor/MDBC/plugins/auth/ref10/ge_p1p1_to_p2.c new file mode 100644 index 00000000..9bb5013d --- /dev/null +++ b/vendor/MDBC/plugins/auth/ref10/ge_p1p1_to_p2.c @@ -0,0 +1,12 @@ +#include "ge.h" + +/* +r = p +*/ + +extern void ge_p1p1_to_p2(ge_p2 *r,const ge_p1p1 *p) +{ + fe_mul(r->X,p->X,p->T); + fe_mul(r->Y,p->Y,p->Z); + fe_mul(r->Z,p->Z,p->T); +} diff --git a/vendor/MDBC/plugins/auth/ref10/ge_p1p1_to_p3.c b/vendor/MDBC/plugins/auth/ref10/ge_p1p1_to_p3.c new file mode 100644 index 00000000..2f57b109 --- /dev/null +++ b/vendor/MDBC/plugins/auth/ref10/ge_p1p1_to_p3.c @@ -0,0 +1,13 @@ +#include "ge.h" + +/* +r = p +*/ + +extern void ge_p1p1_to_p3(ge_p3 *r,const ge_p1p1 *p) +{ + fe_mul(r->X,p->X,p->T); + fe_mul(r->Y,p->Y,p->Z); + fe_mul(r->Z,p->Z,p->T); + fe_mul(r->T,p->X,p->Y); +} diff --git a/vendor/MDBC/plugins/auth/ref10/ge_p2_0.c b/vendor/MDBC/plugins/auth/ref10/ge_p2_0.c new file mode 100644 index 00000000..6191d1e6 --- /dev/null +++ b/vendor/MDBC/plugins/auth/ref10/ge_p2_0.c @@ -0,0 +1,8 @@ +#include "ge.h" + +void ge_p2_0(ge_p2 *h) +{ + fe_0(h->X); + fe_1(h->Y); + fe_1(h->Z); +} diff --git a/vendor/MDBC/plugins/auth/ref10/ge_p2_dbl.c b/vendor/MDBC/plugins/auth/ref10/ge_p2_dbl.c new file mode 100644 index 00000000..2e332b5c --- /dev/null +++ b/vendor/MDBC/plugins/auth/ref10/ge_p2_dbl.c @@ -0,0 +1,11 @@ +#include "ge.h" + +/* +r = 2 * p +*/ + +void ge_p2_dbl(ge_p1p1 *r,const ge_p2 *p) +{ + fe t0; +#include "ge_p2_dbl.h" +} diff --git a/vendor/MDBC/plugins/auth/ref10/ge_p2_dbl.h b/vendor/MDBC/plugins/auth/ref10/ge_p2_dbl.h new file mode 100644 index 00000000..128efed9 --- /dev/null +++ b/vendor/MDBC/plugins/auth/ref10/ge_p2_dbl.h @@ -0,0 +1,73 @@ + +/* qhasm: enter ge_p2_dbl */ + +/* qhasm: fe X1 */ + +/* qhasm: fe Y1 */ + +/* qhasm: fe Z1 */ + +/* qhasm: fe A */ + +/* qhasm: fe AA */ + +/* qhasm: fe XX */ + +/* qhasm: fe YY */ + +/* qhasm: fe B */ + +/* qhasm: fe X3 */ + +/* qhasm: fe Y3 */ + +/* qhasm: fe Z3 */ + +/* qhasm: fe T3 */ + +/* qhasm: XX=X1^2 */ +/* asm 1: fe_sq(>XX=fe#1,XX=r->X,X); */ +fe_sq(r->X,p->X); + +/* qhasm: YY=Y1^2 */ +/* asm 1: fe_sq(>YY=fe#3,YY=r->Z,Y); */ +fe_sq(r->Z,p->Y); + +/* qhasm: B=2*Z1^2 */ +/* asm 1: fe_sq2(>B=fe#4,B=r->T,Z); */ +fe_sq2(r->T,p->Z); + +/* qhasm: A=X1+Y1 */ +/* asm 1: fe_add(>A=fe#2,A=r->Y,X,Y); */ +fe_add(r->Y,p->X,p->Y); + +/* qhasm: AA=A^2 */ +/* asm 1: fe_sq(>AA=fe#5,AA=t0,Y); */ +fe_sq(t0,r->Y); + +/* qhasm: Y3=YY+XX */ +/* asm 1: fe_add(>Y3=fe#2,Y3=r->Y,Z,X); */ +fe_add(r->Y,r->Z,r->X); + +/* qhasm: Z3=YY-XX */ +/* asm 1: fe_sub(>Z3=fe#3,Z3=r->Z,Z,X); */ +fe_sub(r->Z,r->Z,r->X); + +/* qhasm: X3=AA-Y3 */ +/* asm 1: fe_sub(>X3=fe#1,X3=r->X,Y); */ +fe_sub(r->X,t0,r->Y); + +/* qhasm: T3=B-Z3 */ +/* asm 1: fe_sub(>T3=fe#4,T3=r->T,T,Z); */ +fe_sub(r->T,r->T,r->Z); + +/* qhasm: return */ diff --git a/vendor/MDBC/plugins/auth/ref10/ge_p3_0.c b/vendor/MDBC/plugins/auth/ref10/ge_p3_0.c new file mode 100644 index 00000000..401b2935 --- /dev/null +++ b/vendor/MDBC/plugins/auth/ref10/ge_p3_0.c @@ -0,0 +1,9 @@ +#include "ge.h" + +void ge_p3_0(ge_p3 *h) +{ + fe_0(h->X); + fe_1(h->Y); + fe_1(h->Z); + fe_0(h->T); +} diff --git a/vendor/MDBC/plugins/auth/ref10/ge_p3_dbl.c b/vendor/MDBC/plugins/auth/ref10/ge_p3_dbl.c new file mode 100644 index 00000000..0d8a0591 --- /dev/null +++ b/vendor/MDBC/plugins/auth/ref10/ge_p3_dbl.c @@ -0,0 +1,12 @@ +#include "ge.h" + +/* +r = 2 * p +*/ + +void ge_p3_dbl(ge_p1p1 *r,const ge_p3 *p) +{ + ge_p2 q; + ge_p3_to_p2(&q,p); + ge_p2_dbl(r,&q); +} diff --git a/vendor/MDBC/plugins/auth/ref10/ge_p3_to_cached.c b/vendor/MDBC/plugins/auth/ref10/ge_p3_to_cached.c new file mode 100644 index 00000000..bde64228 --- /dev/null +++ b/vendor/MDBC/plugins/auth/ref10/ge_p3_to_cached.c @@ -0,0 +1,17 @@ +#include "ge.h" + +/* +r = p +*/ + +static const fe d2 = { +#include "d2.h" +} ; + +extern void ge_p3_to_cached(ge_cached *r,const ge_p3 *p) +{ + fe_add(r->YplusX,p->Y,p->X); + fe_sub(r->YminusX,p->Y,p->X); + fe_copy(r->Z,p->Z); + fe_mul(r->T2d,p->T,d2); +} diff --git a/vendor/MDBC/plugins/auth/ref10/ge_p3_to_p2.c b/vendor/MDBC/plugins/auth/ref10/ge_p3_to_p2.c new file mode 100644 index 00000000..e532a9e4 --- /dev/null +++ b/vendor/MDBC/plugins/auth/ref10/ge_p3_to_p2.c @@ -0,0 +1,12 @@ +#include "ge.h" + +/* +r = p +*/ + +extern void ge_p3_to_p2(ge_p2 *r,const ge_p3 *p) +{ + fe_copy(r->X,p->X); + fe_copy(r->Y,p->Y); + fe_copy(r->Z,p->Z); +} diff --git a/vendor/MDBC/plugins/auth/ref10/ge_p3_tobytes.c b/vendor/MDBC/plugins/auth/ref10/ge_p3_tobytes.c new file mode 100644 index 00000000..21cb2fc6 --- /dev/null +++ b/vendor/MDBC/plugins/auth/ref10/ge_p3_tobytes.c @@ -0,0 +1,14 @@ +#include "ge.h" + +void ge_p3_tobytes(unsigned char *s,const ge_p3 *h) +{ + fe recip; + fe x; + fe y; + + fe_invert(recip,h->Z); + fe_mul(x,h->X,recip); + fe_mul(y,h->Y,recip); + fe_tobytes(s,y); + s[31] ^= fe_isnegative(x) << 7; +} diff --git a/vendor/MDBC/plugins/auth/ref10/ge_precomp_0.c b/vendor/MDBC/plugins/auth/ref10/ge_precomp_0.c new file mode 100644 index 00000000..2e218861 --- /dev/null +++ b/vendor/MDBC/plugins/auth/ref10/ge_precomp_0.c @@ -0,0 +1,8 @@ +#include "ge.h" + +void ge_precomp_0(ge_precomp *h) +{ + fe_1(h->yplusx); + fe_1(h->yminusx); + fe_0(h->xy2d); +} diff --git a/vendor/MDBC/plugins/auth/ref10/ge_scalarmult_base.c b/vendor/MDBC/plugins/auth/ref10/ge_scalarmult_base.c new file mode 100644 index 00000000..421e4fa0 --- /dev/null +++ b/vendor/MDBC/plugins/auth/ref10/ge_scalarmult_base.c @@ -0,0 +1,105 @@ +#include "ge.h" +#include "crypto_uint32.h" + +static unsigned char equal(signed char b,signed char c) +{ + unsigned char ub = b; + unsigned char uc = c; + unsigned char x = ub ^ uc; /* 0: yes; 1..255: no */ + crypto_uint32 y = x; /* 0: yes; 1..255: no */ + y -= 1; /* 4294967295: yes; 0..254: no */ + y >>= 31; /* 1: yes; 0: no */ + return y; +} + +static unsigned char negative(signed char b) +{ + unsigned long long x = b; /* 18446744073709551361..18446744073709551615: yes; 0..255: no */ + x >>= 63; /* 1: yes; 0: no */ + return x; +} + +static void cmov(ge_precomp *t,ge_precomp *u,unsigned char b) +{ + fe_cmov(t->yplusx,u->yplusx,b); + fe_cmov(t->yminusx,u->yminusx,b); + fe_cmov(t->xy2d,u->xy2d,b); +} + +/* base[i][j] = (j+1)*256^i*B */ +static ge_precomp base[32][8] = { +#include "base.h" +} ; + +static void select(ge_precomp *t,int pos,signed char b) +{ + ge_precomp minust; + unsigned char bnegative = negative(b); + unsigned char babs = b - (((-bnegative) & b) << 1); + + ge_precomp_0(t); + cmov(t,&base[pos][0],equal(babs,1)); + cmov(t,&base[pos][1],equal(babs,2)); + cmov(t,&base[pos][2],equal(babs,3)); + cmov(t,&base[pos][3],equal(babs,4)); + cmov(t,&base[pos][4],equal(babs,5)); + cmov(t,&base[pos][5],equal(babs,6)); + cmov(t,&base[pos][6],equal(babs,7)); + cmov(t,&base[pos][7],equal(babs,8)); + fe_copy(minust.yplusx,t->yminusx); + fe_copy(minust.yminusx,t->yplusx); + fe_neg(minust.xy2d,t->xy2d); + cmov(t,&minust,bnegative); +} + +/* +h = a * B +where a = a[0]+256*a[1]+...+256^31 a[31] +B is the Ed25519 base point (x,4/5) with x positive. + +Preconditions: + a[31] <= 127 +*/ + +void ge_scalarmult_base(ge_p3 *h,const unsigned char *a) +{ + signed char e[64]; + signed char carry; + ge_p1p1 r; + ge_p2 s; + ge_precomp t; + int i; + + for (i = 0;i < 32;++i) { + e[2 * i + 0] = (a[i] >> 0) & 15; + e[2 * i + 1] = (a[i] >> 4) & 15; + } + /* each e[i] is between 0 and 15 */ + /* e[63] is between 0 and 7 */ + + carry = 0; + for (i = 0;i < 63;++i) { + e[i] += carry; + carry = e[i] + 8; + carry >>= 4; + e[i] -= carry << 4; + } + e[63] += carry; + /* each e[i] is between -8 and 8 */ + + ge_p3_0(h); + for (i = 1;i < 64;i += 2) { + select(&t,i / 2,e[i]); + ge_madd(&r,h,&t); ge_p1p1_to_p3(h,&r); + } + + ge_p3_dbl(&r,h); ge_p1p1_to_p2(&s,&r); + ge_p2_dbl(&r,&s); ge_p1p1_to_p2(&s,&r); + ge_p2_dbl(&r,&s); ge_p1p1_to_p2(&s,&r); + ge_p2_dbl(&r,&s); ge_p1p1_to_p3(h,&r); + + for (i = 0;i < 64;i += 2) { + select(&t,i / 2,e[i]); + ge_madd(&r,h,&t); ge_p1p1_to_p3(h,&r); + } +} diff --git a/vendor/MDBC/plugins/auth/ref10/ge_sub.c b/vendor/MDBC/plugins/auth/ref10/ge_sub.c new file mode 100644 index 00000000..69f3d540 --- /dev/null +++ b/vendor/MDBC/plugins/auth/ref10/ge_sub.c @@ -0,0 +1,11 @@ +#include "ge.h" + +/* +r = p - q +*/ + +void ge_sub(ge_p1p1 *r,const ge_p3 *p,const ge_cached *q) +{ + fe t0; +#include "ge_sub.h" +} diff --git a/vendor/MDBC/plugins/auth/ref10/ge_sub.h b/vendor/MDBC/plugins/auth/ref10/ge_sub.h new file mode 100644 index 00000000..b4ef1f5d --- /dev/null +++ b/vendor/MDBC/plugins/auth/ref10/ge_sub.h @@ -0,0 +1,97 @@ + +/* qhasm: enter ge_sub */ + +/* qhasm: fe X1 */ + +/* qhasm: fe Y1 */ + +/* qhasm: fe Z1 */ + +/* qhasm: fe Z2 */ + +/* qhasm: fe T1 */ + +/* qhasm: fe ZZ */ + +/* qhasm: fe YpX2 */ + +/* qhasm: fe YmX2 */ + +/* qhasm: fe T2d2 */ + +/* qhasm: fe X3 */ + +/* qhasm: fe Y3 */ + +/* qhasm: fe Z3 */ + +/* qhasm: fe T3 */ + +/* qhasm: fe YpX1 */ + +/* qhasm: fe YmX1 */ + +/* qhasm: fe A */ + +/* qhasm: fe B */ + +/* qhasm: fe C */ + +/* qhasm: fe D */ + +/* qhasm: YpX1 = Y1+X1 */ +/* asm 1: fe_add(>YpX1=fe#1,YpX1=r->X,Y,X); */ +fe_add(r->X,p->Y,p->X); + +/* qhasm: YmX1 = Y1-X1 */ +/* asm 1: fe_sub(>YmX1=fe#2,YmX1=r->Y,Y,X); */ +fe_sub(r->Y,p->Y,p->X); + +/* qhasm: A = YpX1*YmX2 */ +/* asm 1: fe_mul(>A=fe#3,A=r->Z,X,YminusX); */ +fe_mul(r->Z,r->X,q->YminusX); + +/* qhasm: B = YmX1*YpX2 */ +/* asm 1: fe_mul(>B=fe#2,B=r->Y,Y,YplusX); */ +fe_mul(r->Y,r->Y,q->YplusX); + +/* qhasm: C = T2d2*T1 */ +/* asm 1: fe_mul(>C=fe#4,C=r->T,T2d,T); */ +fe_mul(r->T,q->T2d,p->T); + +/* qhasm: ZZ = Z1*Z2 */ +/* asm 1: fe_mul(>ZZ=fe#1,ZZ=r->X,Z,Z); */ +fe_mul(r->X,p->Z,q->Z); + +/* qhasm: D = 2*ZZ */ +/* asm 1: fe_add(>D=fe#5,D=t0,X,X); */ +fe_add(t0,r->X,r->X); + +/* qhasm: X3 = A-B */ +/* asm 1: fe_sub(>X3=fe#1,X3=r->X,Z,Y); */ +fe_sub(r->X,r->Z,r->Y); + +/* qhasm: Y3 = A+B */ +/* asm 1: fe_add(>Y3=fe#2,Y3=r->Y,Z,Y); */ +fe_add(r->Y,r->Z,r->Y); + +/* qhasm: Z3 = D-C */ +/* asm 1: fe_sub(>Z3=fe#3,Z3=r->Z,T); */ +fe_sub(r->Z,t0,r->T); + +/* qhasm: T3 = D+C */ +/* asm 1: fe_add(>T3=fe#4,T3=r->T,T); */ +fe_add(r->T,t0,r->T); + +/* qhasm: return */ diff --git a/vendor/MDBC/plugins/auth/ref10/ge_tobytes.c b/vendor/MDBC/plugins/auth/ref10/ge_tobytes.c new file mode 100644 index 00000000..31b3d33e --- /dev/null +++ b/vendor/MDBC/plugins/auth/ref10/ge_tobytes.c @@ -0,0 +1,14 @@ +#include "ge.h" + +void ge_tobytes(unsigned char *s,const ge_p2 *h) +{ + fe recip; + fe x; + fe y; + + fe_invert(recip,h->Z); + fe_mul(x,h->X,recip); + fe_mul(y,h->Y,recip); + fe_tobytes(s,y); + s[31] ^= fe_isnegative(x) << 7; +} diff --git a/vendor/MDBC/plugins/auth/ref10/keypair.c b/vendor/MDBC/plugins/auth/ref10/keypair.c new file mode 100644 index 00000000..64000838 --- /dev/null +++ b/vendor/MDBC/plugins/auth/ref10/keypair.c @@ -0,0 +1,23 @@ +#include +#include "crypto_sign.h" +#include "crypto_hash_sha512.h" +#include "ge.h" + +int crypto_sign_keypair( + unsigned char *pk, + unsigned char *pw, unsigned long long pwlen +) +{ + unsigned char az[64]; + ge_p3 A; + + crypto_hash_sha512(az,pw,pwlen); + az[0] &= 248; + az[31] &= 63; + az[31] |= 64; + + ge_scalarmult_base(&A,az); + ge_p3_tobytes(pk,&A); + + return 0; +} diff --git a/vendor/MDBC/plugins/auth/ref10/open.c b/vendor/MDBC/plugins/auth/ref10/open.c new file mode 100644 index 00000000..7362b681 --- /dev/null +++ b/vendor/MDBC/plugins/auth/ref10/open.c @@ -0,0 +1,36 @@ +#include +#include "crypto_sign.h" +#include "crypto_hash_sha512.h" +#include "crypto_verify_32.h" +#include "ge.h" +#include "sc.h" + +int crypto_sign_open( + unsigned char *sm, unsigned long long smlen, + const unsigned char *pk +) +{ + unsigned char scopy[32]; + unsigned char h[64]; + unsigned char rcheck[32]; + ge_p3 A; + ge_p2 R; + + if (smlen < 64) goto badsig; + if (sm[63] & 224) goto badsig; + if (ge_frombytes_negate_vartime(&A,pk) != 0) goto badsig; + + memmove(scopy,sm + 32,32); + + memmove(sm + 32,pk,32); + crypto_hash_sha512(h,sm,smlen); + sc_reduce(h); + + ge_double_scalarmult_vartime(&R,h,&A,scopy); + ge_tobytes(rcheck,&R); + if (crypto_verify_32(rcheck,sm) == 0) + return 0; + +badsig: + return -1; +} diff --git a/vendor/MDBC/plugins/auth/ref10/pow22523.h b/vendor/MDBC/plugins/auth/ref10/pow22523.h new file mode 100644 index 00000000..d476ed14 --- /dev/null +++ b/vendor/MDBC/plugins/auth/ref10/pow22523.h @@ -0,0 +1,168 @@ + +/* qhasm: fe z1 */ + +/* qhasm: fe z2 */ + +/* qhasm: fe z8 */ + +/* qhasm: fe z9 */ + +/* qhasm: fe z11 */ + +/* qhasm: fe z22 */ + +/* qhasm: fe z_5_0 */ + +/* qhasm: fe z_10_5 */ + +/* qhasm: fe z_10_0 */ + +/* qhasm: fe z_20_10 */ + +/* qhasm: fe z_20_0 */ + +/* qhasm: fe z_40_20 */ + +/* qhasm: fe z_40_0 */ + +/* qhasm: fe z_50_10 */ + +/* qhasm: fe z_50_0 */ + +/* qhasm: fe z_100_50 */ + +/* qhasm: fe z_100_0 */ + +/* qhasm: fe z_200_100 */ + +/* qhasm: fe z_200_0 */ + +/* qhasm: fe z_250_50 */ + +/* qhasm: fe z_250_0 */ + +/* qhasm: fe z_252_2 */ + +/* qhasm: fe z_252_3 */ + +/* qhasm: enter pow22523 */ + +/* qhasm: z2 = z1^2^1 */ +/* asm 1: fe_sq(>z2=fe#1,z2=fe#1,>z2=fe#1); */ +/* asm 2: fe_sq(>z2=t0,z2=t0,>z2=t0); */ +fe_sq(t0,z); + +/* covscan CWE-561 dead code: variable i can't be < 1 +for (i = 1;i < 1;++i) fe_sq(t0,t0); +*/ + +/* qhasm: z8 = z2^2^2 */ +/* asm 1: fe_sq(>z8=fe#2,z8=fe#2,>z8=fe#2); */ +/* asm 2: fe_sq(>z8=t1,z8=t1,>z8=t1); */ +fe_sq(t1,t0); for (i = 1;i < 2;++i) fe_sq(t1,t1); + +/* qhasm: z9 = z1*z8 */ +/* asm 1: fe_mul(>z9=fe#2,z9=t1,z11=fe#1,z11=t0,z22=fe#1,z22=fe#1,>z22=fe#1); */ +/* asm 2: fe_sq(>z22=t0,z22=t0,>z22=t0); */ +fe_sq(t0,t0); + +/* covscan CWE-561 dead code: variable i can't be < 1 +for (i = 1;i < 1;++i) fe_sq(t0,t0); +*/ + +/* qhasm: z_5_0 = z9*z22 */ +/* asm 1: fe_mul(>z_5_0=fe#1,z_5_0=t0,z_10_5=fe#2,z_10_5=fe#2,>z_10_5=fe#2); */ +/* asm 2: fe_sq(>z_10_5=t1,z_10_5=t1,>z_10_5=t1); */ +fe_sq(t1,t0); for (i = 1;i < 5;++i) fe_sq(t1,t1); + +/* qhasm: z_10_0 = z_10_5*z_5_0 */ +/* asm 1: fe_mul(>z_10_0=fe#1,z_10_0=t0,z_20_10=fe#2,z_20_10=fe#2,>z_20_10=fe#2); */ +/* asm 2: fe_sq(>z_20_10=t1,z_20_10=t1,>z_20_10=t1); */ +fe_sq(t1,t0); for (i = 1;i < 10;++i) fe_sq(t1,t1); + +/* qhasm: z_20_0 = z_20_10*z_10_0 */ +/* asm 1: fe_mul(>z_20_0=fe#2,z_20_0=t1,z_40_20=fe#3,z_40_20=fe#3,>z_40_20=fe#3); */ +/* asm 2: fe_sq(>z_40_20=t2,z_40_20=t2,>z_40_20=t2); */ +fe_sq(t2,t1); for (i = 1;i < 20;++i) fe_sq(t2,t2); + +/* qhasm: z_40_0 = z_40_20*z_20_0 */ +/* asm 1: fe_mul(>z_40_0=fe#2,z_40_0=t1,z_50_10=fe#2,z_50_10=fe#2,>z_50_10=fe#2); */ +/* asm 2: fe_sq(>z_50_10=t1,z_50_10=t1,>z_50_10=t1); */ +fe_sq(t1,t1); for (i = 1;i < 10;++i) fe_sq(t1,t1); + +/* qhasm: z_50_0 = z_50_10*z_10_0 */ +/* asm 1: fe_mul(>z_50_0=fe#1,z_50_0=t0,z_100_50=fe#2,z_100_50=fe#2,>z_100_50=fe#2); */ +/* asm 2: fe_sq(>z_100_50=t1,z_100_50=t1,>z_100_50=t1); */ +fe_sq(t1,t0); for (i = 1;i < 50;++i) fe_sq(t1,t1); + +/* qhasm: z_100_0 = z_100_50*z_50_0 */ +/* asm 1: fe_mul(>z_100_0=fe#2,z_100_0=t1,z_200_100=fe#3,z_200_100=fe#3,>z_200_100=fe#3); */ +/* asm 2: fe_sq(>z_200_100=t2,z_200_100=t2,>z_200_100=t2); */ +fe_sq(t2,t1); for (i = 1;i < 100;++i) fe_sq(t2,t2); + +/* qhasm: z_200_0 = z_200_100*z_100_0 */ +/* asm 1: fe_mul(>z_200_0=fe#2,z_200_0=t1,z_250_50=fe#2,z_250_50=fe#2,>z_250_50=fe#2); */ +/* asm 2: fe_sq(>z_250_50=t1,z_250_50=t1,>z_250_50=t1); */ +fe_sq(t1,t1); for (i = 1;i < 50;++i) fe_sq(t1,t1); + +/* qhasm: z_250_0 = z_250_50*z_50_0 */ +/* asm 1: fe_mul(>z_250_0=fe#1,z_250_0=t0,z_252_2=fe#1,z_252_2=fe#1,>z_252_2=fe#1); */ +/* asm 2: fe_sq(>z_252_2=t0,z_252_2=t0,>z_252_2=t0); */ +fe_sq(t0,t0); for (i = 1;i < 2;++i) fe_sq(t0,t0); + +/* qhasm: z_252_3 = z_252_2*z1 */ +/* asm 1: fe_mul(>z_252_3=fe#12,z_252_3=out,z2=fe#1,z2=fe#1,>z2=fe#1); */ +/* asm 2: fe_sq(>z2=t0,z2=t0,>z2=t0); */ +fe_sq(t0,z); +/* covscan CWE-561 dead code: variable i can't be < 1 +for (i = 1;i < 1;++i) fe_sq(t0,t0); +*/ + +/* qhasm: z8 = z2^2^2 */ +/* asm 1: fe_sq(>z8=fe#2,z8=fe#2,>z8=fe#2); */ +/* asm 2: fe_sq(>z8=t1,z8=t1,>z8=t1); */ +fe_sq(t1,t0); for (i = 1;i < 2;++i) fe_sq(t1,t1); + +/* qhasm: z9 = z1*z8 */ +/* asm 1: fe_mul(>z9=fe#2,z9=t1,z11=fe#1,z11=t0,z22=fe#3,z22=fe#3,>z22=fe#3); */ +/* asm 2: fe_sq(>z22=t2,z22=t2,>z22=t2); */ +fe_sq(t2,t0); +/* covscan CWE-561 dead code: variable i can't be < 1 +for (i = 1;i < 1;++i) fe_sq(t2,t2); +*/ + +/* qhasm: z_5_0 = z9*z22 */ +/* asm 1: fe_mul(>z_5_0=fe#2,z_5_0=t1,z_10_5=fe#3,z_10_5=fe#3,>z_10_5=fe#3); */ +/* asm 2: fe_sq(>z_10_5=t2,z_10_5=t2,>z_10_5=t2); */ +fe_sq(t2,t1); for (i = 1;i < 5;++i) fe_sq(t2,t2); + +/* qhasm: z_10_0 = z_10_5*z_5_0 */ +/* asm 1: fe_mul(>z_10_0=fe#2,z_10_0=t1,z_20_10=fe#3,z_20_10=fe#3,>z_20_10=fe#3); */ +/* asm 2: fe_sq(>z_20_10=t2,z_20_10=t2,>z_20_10=t2); */ +fe_sq(t2,t1); for (i = 1;i < 10;++i) fe_sq(t2,t2); + +/* qhasm: z_20_0 = z_20_10*z_10_0 */ +/* asm 1: fe_mul(>z_20_0=fe#3,z_20_0=t2,z_40_20=fe#4,z_40_20=fe#4,>z_40_20=fe#4); */ +/* asm 2: fe_sq(>z_40_20=t3,z_40_20=t3,>z_40_20=t3); */ +fe_sq(t3,t2); for (i = 1;i < 20;++i) fe_sq(t3,t3); + +/* qhasm: z_40_0 = z_40_20*z_20_0 */ +/* asm 1: fe_mul(>z_40_0=fe#3,z_40_0=t2,z_50_10=fe#3,z_50_10=fe#3,>z_50_10=fe#3); */ +/* asm 2: fe_sq(>z_50_10=t2,z_50_10=t2,>z_50_10=t2); */ +fe_sq(t2,t2); for (i = 1;i < 10;++i) fe_sq(t2,t2); + +/* qhasm: z_50_0 = z_50_10*z_10_0 */ +/* asm 1: fe_mul(>z_50_0=fe#2,z_50_0=t1,z_100_50=fe#3,z_100_50=fe#3,>z_100_50=fe#3); */ +/* asm 2: fe_sq(>z_100_50=t2,z_100_50=t2,>z_100_50=t2); */ +fe_sq(t2,t1); for (i = 1;i < 50;++i) fe_sq(t2,t2); + +/* qhasm: z_100_0 = z_100_50*z_50_0 */ +/* asm 1: fe_mul(>z_100_0=fe#3,z_100_0=t2,z_200_100=fe#4,z_200_100=fe#4,>z_200_100=fe#4); */ +/* asm 2: fe_sq(>z_200_100=t3,z_200_100=t3,>z_200_100=t3); */ +fe_sq(t3,t2); for (i = 1;i < 100;++i) fe_sq(t3,t3); + +/* qhasm: z_200_0 = z_200_100*z_100_0 */ +/* asm 1: fe_mul(>z_200_0=fe#3,z_200_0=t2,z_250_50=fe#3,z_250_50=fe#3,>z_250_50=fe#3); */ +/* asm 2: fe_sq(>z_250_50=t2,z_250_50=t2,>z_250_50=t2); */ +fe_sq(t2,t2); for (i = 1;i < 50;++i) fe_sq(t2,t2); + +/* qhasm: z_250_0 = z_250_50*z_50_0 */ +/* asm 1: fe_mul(>z_250_0=fe#2,z_250_0=t1,z_255_5=fe#2,z_255_5=fe#2,>z_255_5=fe#2); */ +/* asm 2: fe_sq(>z_255_5=t1,z_255_5=t1,>z_255_5=t1); */ +fe_sq(t1,t1); for (i = 1;i < 5;++i) fe_sq(t1,t1); + +/* qhasm: z_255_21 = z_255_5*z11 */ +/* asm 1: fe_mul(>z_255_21=fe#12,z_255_21=out,> 5); + crypto_int64 a2 = 2097151 & (load_3(a + 5) >> 2); + crypto_int64 a3 = 2097151 & (load_4(a + 7) >> 7); + crypto_int64 a4 = 2097151 & (load_4(a + 10) >> 4); + crypto_int64 a5 = 2097151 & (load_3(a + 13) >> 1); + crypto_int64 a6 = 2097151 & (load_4(a + 15) >> 6); + crypto_int64 a7 = 2097151 & (load_3(a + 18) >> 3); + crypto_int64 a8 = 2097151 & load_3(a + 21); + crypto_int64 a9 = 2097151 & (load_4(a + 23) >> 5); + crypto_int64 a10 = 2097151 & (load_3(a + 26) >> 2); + crypto_int64 a11 = (load_4(a + 28) >> 7); + crypto_int64 b0 = 2097151 & load_3(b); + crypto_int64 b1 = 2097151 & (load_4(b + 2) >> 5); + crypto_int64 b2 = 2097151 & (load_3(b + 5) >> 2); + crypto_int64 b3 = 2097151 & (load_4(b + 7) >> 7); + crypto_int64 b4 = 2097151 & (load_4(b + 10) >> 4); + crypto_int64 b5 = 2097151 & (load_3(b + 13) >> 1); + crypto_int64 b6 = 2097151 & (load_4(b + 15) >> 6); + crypto_int64 b7 = 2097151 & (load_3(b + 18) >> 3); + crypto_int64 b8 = 2097151 & load_3(b + 21); + crypto_int64 b9 = 2097151 & (load_4(b + 23) >> 5); + crypto_int64 b10 = 2097151 & (load_3(b + 26) >> 2); + crypto_int64 b11 = (load_4(b + 28) >> 7); + crypto_int64 c0 = 2097151 & load_3(c); + crypto_int64 c1 = 2097151 & (load_4(c + 2) >> 5); + crypto_int64 c2 = 2097151 & (load_3(c + 5) >> 2); + crypto_int64 c3 = 2097151 & (load_4(c + 7) >> 7); + crypto_int64 c4 = 2097151 & (load_4(c + 10) >> 4); + crypto_int64 c5 = 2097151 & (load_3(c + 13) >> 1); + crypto_int64 c6 = 2097151 & (load_4(c + 15) >> 6); + crypto_int64 c7 = 2097151 & (load_3(c + 18) >> 3); + crypto_int64 c8 = 2097151 & load_3(c + 21); + crypto_int64 c9 = 2097151 & (load_4(c + 23) >> 5); + crypto_int64 c10 = 2097151 & (load_3(c + 26) >> 2); + crypto_int64 c11 = (load_4(c + 28) >> 7); + crypto_int64 s0; + crypto_int64 s1; + crypto_int64 s2; + crypto_int64 s3; + crypto_int64 s4; + crypto_int64 s5; + crypto_int64 s6; + crypto_int64 s7; + crypto_int64 s8; + crypto_int64 s9; + crypto_int64 s10; + crypto_int64 s11; + crypto_int64 s12; + crypto_int64 s13; + crypto_int64 s14; + crypto_int64 s15; + crypto_int64 s16; + crypto_int64 s17; + crypto_int64 s18; + crypto_int64 s19; + crypto_int64 s20; + crypto_int64 s21; + crypto_int64 s22; + crypto_int64 s23; + crypto_int64 carry0; + crypto_int64 carry1; + crypto_int64 carry2; + crypto_int64 carry3; + crypto_int64 carry4; + crypto_int64 carry5; + crypto_int64 carry6; + crypto_int64 carry7; + crypto_int64 carry8; + crypto_int64 carry9; + crypto_int64 carry10; + crypto_int64 carry11; + crypto_int64 carry12; + crypto_int64 carry13; + crypto_int64 carry14; + crypto_int64 carry15; + crypto_int64 carry16; + crypto_int64 carry17; + crypto_int64 carry18; + crypto_int64 carry19; + crypto_int64 carry20; + crypto_int64 carry21; + crypto_int64 carry22; + + s0 = c0 + a0*b0; + s1 = c1 + a0*b1 + a1*b0; + s2 = c2 + a0*b2 + a1*b1 + a2*b0; + s3 = c3 + a0*b3 + a1*b2 + a2*b1 + a3*b0; + s4 = c4 + a0*b4 + a1*b3 + a2*b2 + a3*b1 + a4*b0; + s5 = c5 + a0*b5 + a1*b4 + a2*b3 + a3*b2 + a4*b1 + a5*b0; + s6 = c6 + a0*b6 + a1*b5 + a2*b4 + a3*b3 + a4*b2 + a5*b1 + a6*b0; + s7 = c7 + a0*b7 + a1*b6 + a2*b5 + a3*b4 + a4*b3 + a5*b2 + a6*b1 + a7*b0; + s8 = c8 + a0*b8 + a1*b7 + a2*b6 + a3*b5 + a4*b4 + a5*b3 + a6*b2 + a7*b1 + a8*b0; + s9 = c9 + a0*b9 + a1*b8 + a2*b7 + a3*b6 + a4*b5 + a5*b4 + a6*b3 + a7*b2 + a8*b1 + a9*b0; + s10 = c10 + a0*b10 + a1*b9 + a2*b8 + a3*b7 + a4*b6 + a5*b5 + a6*b4 + a7*b3 + a8*b2 + a9*b1 + a10*b0; + s11 = c11 + a0*b11 + a1*b10 + a2*b9 + a3*b8 + a4*b7 + a5*b6 + a6*b5 + a7*b4 + a8*b3 + a9*b2 + a10*b1 + a11*b0; + s12 = a1*b11 + a2*b10 + a3*b9 + a4*b8 + a5*b7 + a6*b6 + a7*b5 + a8*b4 + a9*b3 + a10*b2 + a11*b1; + s13 = a2*b11 + a3*b10 + a4*b9 + a5*b8 + a6*b7 + a7*b6 + a8*b5 + a9*b4 + a10*b3 + a11*b2; + s14 = a3*b11 + a4*b10 + a5*b9 + a6*b8 + a7*b7 + a8*b6 + a9*b5 + a10*b4 + a11*b3; + s15 = a4*b11 + a5*b10 + a6*b9 + a7*b8 + a8*b7 + a9*b6 + a10*b5 + a11*b4; + s16 = a5*b11 + a6*b10 + a7*b9 + a8*b8 + a9*b7 + a10*b6 + a11*b5; + s17 = a6*b11 + a7*b10 + a8*b9 + a9*b8 + a10*b7 + a11*b6; + s18 = a7*b11 + a8*b10 + a9*b9 + a10*b8 + a11*b7; + s19 = a8*b11 + a9*b10 + a10*b9 + a11*b8; + s20 = a9*b11 + a10*b10 + a11*b9; + s21 = a10*b11 + a11*b10; + s22 = a11*b11; + s23 = 0; + + carry0 = (s0 + (1<<20)) >> 21; s1 += carry0; s0 -= carry0 << 21; + carry2 = (s2 + (1<<20)) >> 21; s3 += carry2; s2 -= carry2 << 21; + carry4 = (s4 + (1<<20)) >> 21; s5 += carry4; s4 -= carry4 << 21; + carry6 = (s6 + (1<<20)) >> 21; s7 += carry6; s6 -= carry6 << 21; + carry8 = (s8 + (1<<20)) >> 21; s9 += carry8; s8 -= carry8 << 21; + carry10 = (s10 + (1<<20)) >> 21; s11 += carry10; s10 -= carry10 << 21; + carry12 = (s12 + (1<<20)) >> 21; s13 += carry12; s12 -= carry12 << 21; + carry14 = (s14 + (1<<20)) >> 21; s15 += carry14; s14 -= carry14 << 21; + carry16 = (s16 + (1<<20)) >> 21; s17 += carry16; s16 -= carry16 << 21; + carry18 = (s18 + (1<<20)) >> 21; s19 += carry18; s18 -= carry18 << 21; + carry20 = (s20 + (1<<20)) >> 21; s21 += carry20; s20 -= carry20 << 21; + carry22 = (s22 + (1<<20)) >> 21; s23 += carry22; s22 -= carry22 << 21; + + carry1 = (s1 + (1<<20)) >> 21; s2 += carry1; s1 -= carry1 << 21; + carry3 = (s3 + (1<<20)) >> 21; s4 += carry3; s3 -= carry3 << 21; + carry5 = (s5 + (1<<20)) >> 21; s6 += carry5; s5 -= carry5 << 21; + carry7 = (s7 + (1<<20)) >> 21; s8 += carry7; s7 -= carry7 << 21; + carry9 = (s9 + (1<<20)) >> 21; s10 += carry9; s9 -= carry9 << 21; + carry11 = (s11 + (1<<20)) >> 21; s12 += carry11; s11 -= carry11 << 21; + carry13 = (s13 + (1<<20)) >> 21; s14 += carry13; s13 -= carry13 << 21; + carry15 = (s15 + (1<<20)) >> 21; s16 += carry15; s15 -= carry15 << 21; + carry17 = (s17 + (1<<20)) >> 21; s18 += carry17; s17 -= carry17 << 21; + carry19 = (s19 + (1<<20)) >> 21; s20 += carry19; s19 -= carry19 << 21; + carry21 = (s21 + (1<<20)) >> 21; s22 += carry21; s21 -= carry21 << 21; + + s11 += s23 * 666643; + s12 += s23 * 470296; + s13 += s23 * 654183; + s14 -= s23 * 997805; + s15 += s23 * 136657; + s16 -= s23 * 683901; + s23 = 0; + + s10 += s22 * 666643; + s11 += s22 * 470296; + s12 += s22 * 654183; + s13 -= s22 * 997805; + s14 += s22 * 136657; + s15 -= s22 * 683901; + s22 = 0; + + s9 += s21 * 666643; + s10 += s21 * 470296; + s11 += s21 * 654183; + s12 -= s21 * 997805; + s13 += s21 * 136657; + s14 -= s21 * 683901; + s21 = 0; + + s8 += s20 * 666643; + s9 += s20 * 470296; + s10 += s20 * 654183; + s11 -= s20 * 997805; + s12 += s20 * 136657; + s13 -= s20 * 683901; + s20 = 0; + + s7 += s19 * 666643; + s8 += s19 * 470296; + s9 += s19 * 654183; + s10 -= s19 * 997805; + s11 += s19 * 136657; + s12 -= s19 * 683901; + s19 = 0; + + s6 += s18 * 666643; + s7 += s18 * 470296; + s8 += s18 * 654183; + s9 -= s18 * 997805; + s10 += s18 * 136657; + s11 -= s18 * 683901; + s18 = 0; + + carry6 = (s6 + (1<<20)) >> 21; s7 += carry6; s6 -= carry6 << 21; + carry8 = (s8 + (1<<20)) >> 21; s9 += carry8; s8 -= carry8 << 21; + carry10 = (s10 + (1<<20)) >> 21; s11 += carry10; s10 -= carry10 << 21; + carry12 = (s12 + (1<<20)) >> 21; s13 += carry12; s12 -= carry12 << 21; + carry14 = (s14 + (1<<20)) >> 21; s15 += carry14; s14 -= carry14 << 21; + carry16 = (s16 + (1<<20)) >> 21; s17 += carry16; s16 -= carry16 << 21; + + carry7 = (s7 + (1<<20)) >> 21; s8 += carry7; s7 -= carry7 << 21; + carry9 = (s9 + (1<<20)) >> 21; s10 += carry9; s9 -= carry9 << 21; + carry11 = (s11 + (1<<20)) >> 21; s12 += carry11; s11 -= carry11 << 21; + carry13 = (s13 + (1<<20)) >> 21; s14 += carry13; s13 -= carry13 << 21; + carry15 = (s15 + (1<<20)) >> 21; s16 += carry15; s15 -= carry15 << 21; + + s5 += s17 * 666643; + s6 += s17 * 470296; + s7 += s17 * 654183; + s8 -= s17 * 997805; + s9 += s17 * 136657; + s10 -= s17 * 683901; + s17 = 0; + + s4 += s16 * 666643; + s5 += s16 * 470296; + s6 += s16 * 654183; + s7 -= s16 * 997805; + s8 += s16 * 136657; + s9 -= s16 * 683901; + s16 = 0; + + s3 += s15 * 666643; + s4 += s15 * 470296; + s5 += s15 * 654183; + s6 -= s15 * 997805; + s7 += s15 * 136657; + s8 -= s15 * 683901; + s15 = 0; + + s2 += s14 * 666643; + s3 += s14 * 470296; + s4 += s14 * 654183; + s5 -= s14 * 997805; + s6 += s14 * 136657; + s7 -= s14 * 683901; + s14 = 0; + + s1 += s13 * 666643; + s2 += s13 * 470296; + s3 += s13 * 654183; + s4 -= s13 * 997805; + s5 += s13 * 136657; + s6 -= s13 * 683901; + s13 = 0; + + s0 += s12 * 666643; + s1 += s12 * 470296; + s2 += s12 * 654183; + s3 -= s12 * 997805; + s4 += s12 * 136657; + s5 -= s12 * 683901; + s12 = 0; + + carry0 = (s0 + (1<<20)) >> 21; s1 += carry0; s0 -= carry0 << 21; + carry2 = (s2 + (1<<20)) >> 21; s3 += carry2; s2 -= carry2 << 21; + carry4 = (s4 + (1<<20)) >> 21; s5 += carry4; s4 -= carry4 << 21; + carry6 = (s6 + (1<<20)) >> 21; s7 += carry6; s6 -= carry6 << 21; + carry8 = (s8 + (1<<20)) >> 21; s9 += carry8; s8 -= carry8 << 21; + carry10 = (s10 + (1<<20)) >> 21; s11 += carry10; s10 -= carry10 << 21; + + carry1 = (s1 + (1<<20)) >> 21; s2 += carry1; s1 -= carry1 << 21; + carry3 = (s3 + (1<<20)) >> 21; s4 += carry3; s3 -= carry3 << 21; + carry5 = (s5 + (1<<20)) >> 21; s6 += carry5; s5 -= carry5 << 21; + carry7 = (s7 + (1<<20)) >> 21; s8 += carry7; s7 -= carry7 << 21; + carry9 = (s9 + (1<<20)) >> 21; s10 += carry9; s9 -= carry9 << 21; + carry11 = (s11 + (1<<20)) >> 21; s12 += carry11; s11 -= carry11 << 21; + + s0 += s12 * 666643; + s1 += s12 * 470296; + s2 += s12 * 654183; + s3 -= s12 * 997805; + s4 += s12 * 136657; + s5 -= s12 * 683901; + s12 = 0; + + carry0 = s0 >> 21; s1 += carry0; s0 -= carry0 << 21; + carry1 = s1 >> 21; s2 += carry1; s1 -= carry1 << 21; + carry2 = s2 >> 21; s3 += carry2; s2 -= carry2 << 21; + carry3 = s3 >> 21; s4 += carry3; s3 -= carry3 << 21; + carry4 = s4 >> 21; s5 += carry4; s4 -= carry4 << 21; + carry5 = s5 >> 21; s6 += carry5; s5 -= carry5 << 21; + carry6 = s6 >> 21; s7 += carry6; s6 -= carry6 << 21; + carry7 = s7 >> 21; s8 += carry7; s7 -= carry7 << 21; + carry8 = s8 >> 21; s9 += carry8; s8 -= carry8 << 21; + carry9 = s9 >> 21; s10 += carry9; s9 -= carry9 << 21; + carry10 = s10 >> 21; s11 += carry10; s10 -= carry10 << 21; + carry11 = s11 >> 21; s12 += carry11; s11 -= carry11 << 21; + + s0 += s12 * 666643; + s1 += s12 * 470296; + s2 += s12 * 654183; + s3 -= s12 * 997805; + s4 += s12 * 136657; + s5 -= s12 * 683901; + s12 = 0; + + carry0 = s0 >> 21; s1 += carry0; s0 -= carry0 << 21; + carry1 = s1 >> 21; s2 += carry1; s1 -= carry1 << 21; + carry2 = s2 >> 21; s3 += carry2; s2 -= carry2 << 21; + carry3 = s3 >> 21; s4 += carry3; s3 -= carry3 << 21; + carry4 = s4 >> 21; s5 += carry4; s4 -= carry4 << 21; + carry5 = s5 >> 21; s6 += carry5; s5 -= carry5 << 21; + carry6 = s6 >> 21; s7 += carry6; s6 -= carry6 << 21; + carry7 = s7 >> 21; s8 += carry7; s7 -= carry7 << 21; + carry8 = s8 >> 21; s9 += carry8; s8 -= carry8 << 21; + carry9 = s9 >> 21; s10 += carry9; s9 -= carry9 << 21; + carry10 = s10 >> 21; s11 += carry10; s10 -= carry10 << 21; + + s[0] = s0 >> 0; + s[1] = s0 >> 8; + s[2] = (s0 >> 16) | (s1 << 5); + s[3] = s1 >> 3; + s[4] = s1 >> 11; + s[5] = (s1 >> 19) | (s2 << 2); + s[6] = s2 >> 6; + s[7] = (s2 >> 14) | (s3 << 7); + s[8] = s3 >> 1; + s[9] = s3 >> 9; + s[10] = (s3 >> 17) | (s4 << 4); + s[11] = s4 >> 4; + s[12] = s4 >> 12; + s[13] = (s4 >> 20) | (s5 << 1); + s[14] = s5 >> 7; + s[15] = (s5 >> 15) | (s6 << 6); + s[16] = s6 >> 2; + s[17] = s6 >> 10; + s[18] = (s6 >> 18) | (s7 << 3); + s[19] = s7 >> 5; + s[20] = s7 >> 13; + s[21] = s8 >> 0; + s[22] = s8 >> 8; + s[23] = (s8 >> 16) | (s9 << 5); + s[24] = s9 >> 3; + s[25] = s9 >> 11; + s[26] = (s9 >> 19) | (s10 << 2); + s[27] = s10 >> 6; + s[28] = (s10 >> 14) | (s11 << 7); + s[29] = s11 >> 1; + s[30] = s11 >> 9; + s[31] = s11 >> 17; +} diff --git a/vendor/MDBC/plugins/auth/ref10/sc_reduce.c b/vendor/MDBC/plugins/auth/ref10/sc_reduce.c new file mode 100644 index 00000000..d01f5a57 --- /dev/null +++ b/vendor/MDBC/plugins/auth/ref10/sc_reduce.c @@ -0,0 +1,275 @@ +#include "sc.h" +#include "crypto_int64.h" +#include "crypto_uint32.h" +#include "crypto_uint64.h" + +static crypto_uint64 load_3(const unsigned char *in) +{ + crypto_uint64 result; + result = (crypto_uint64) in[0]; + result |= ((crypto_uint64) in[1]) << 8; + result |= ((crypto_uint64) in[2]) << 16; + return result; +} + +static crypto_uint64 load_4(const unsigned char *in) +{ + crypto_uint64 result; + result = (crypto_uint64) in[0]; + result |= ((crypto_uint64) in[1]) << 8; + result |= ((crypto_uint64) in[2]) << 16; + result |= ((crypto_uint64) in[3]) << 24; + return result; +} + +/* +Input: + s[0]+256*s[1]+...+256^63*s[63] = s + +Output: + s[0]+256*s[1]+...+256^31*s[31] = s mod l + where l = 2^252 + 27742317777372353535851937790883648493. + Overwrites s in place. +*/ + +void sc_reduce(unsigned char *s) +{ + crypto_int64 s0 = 2097151 & load_3(s); + crypto_int64 s1 = 2097151 & (load_4(s + 2) >> 5); + crypto_int64 s2 = 2097151 & (load_3(s + 5) >> 2); + crypto_int64 s3 = 2097151 & (load_4(s + 7) >> 7); + crypto_int64 s4 = 2097151 & (load_4(s + 10) >> 4); + crypto_int64 s5 = 2097151 & (load_3(s + 13) >> 1); + crypto_int64 s6 = 2097151 & (load_4(s + 15) >> 6); + crypto_int64 s7 = 2097151 & (load_3(s + 18) >> 3); + crypto_int64 s8 = 2097151 & load_3(s + 21); + crypto_int64 s9 = 2097151 & (load_4(s + 23) >> 5); + crypto_int64 s10 = 2097151 & (load_3(s + 26) >> 2); + crypto_int64 s11 = 2097151 & (load_4(s + 28) >> 7); + crypto_int64 s12 = 2097151 & (load_4(s + 31) >> 4); + crypto_int64 s13 = 2097151 & (load_3(s + 34) >> 1); + crypto_int64 s14 = 2097151 & (load_4(s + 36) >> 6); + crypto_int64 s15 = 2097151 & (load_3(s + 39) >> 3); + crypto_int64 s16 = 2097151 & load_3(s + 42); + crypto_int64 s17 = 2097151 & (load_4(s + 44) >> 5); + crypto_int64 s18 = 2097151 & (load_3(s + 47) >> 2); + crypto_int64 s19 = 2097151 & (load_4(s + 49) >> 7); + crypto_int64 s20 = 2097151 & (load_4(s + 52) >> 4); + crypto_int64 s21 = 2097151 & (load_3(s + 55) >> 1); + crypto_int64 s22 = 2097151 & (load_4(s + 57) >> 6); + crypto_int64 s23 = (load_4(s + 60) >> 3); + crypto_int64 carry0; + crypto_int64 carry1; + crypto_int64 carry2; + crypto_int64 carry3; + crypto_int64 carry4; + crypto_int64 carry5; + crypto_int64 carry6; + crypto_int64 carry7; + crypto_int64 carry8; + crypto_int64 carry9; + crypto_int64 carry10; + crypto_int64 carry11; + crypto_int64 carry12; + crypto_int64 carry13; + crypto_int64 carry14; + crypto_int64 carry15; + crypto_int64 carry16; + + s11 += s23 * 666643; + s12 += s23 * 470296; + s13 += s23 * 654183; + s14 -= s23 * 997805; + s15 += s23 * 136657; + s16 -= s23 * 683901; + s23 = 0; + + s10 += s22 * 666643; + s11 += s22 * 470296; + s12 += s22 * 654183; + s13 -= s22 * 997805; + s14 += s22 * 136657; + s15 -= s22 * 683901; + s22 = 0; + + s9 += s21 * 666643; + s10 += s21 * 470296; + s11 += s21 * 654183; + s12 -= s21 * 997805; + s13 += s21 * 136657; + s14 -= s21 * 683901; + s21 = 0; + + s8 += s20 * 666643; + s9 += s20 * 470296; + s10 += s20 * 654183; + s11 -= s20 * 997805; + s12 += s20 * 136657; + s13 -= s20 * 683901; + s20 = 0; + + s7 += s19 * 666643; + s8 += s19 * 470296; + s9 += s19 * 654183; + s10 -= s19 * 997805; + s11 += s19 * 136657; + s12 -= s19 * 683901; + s19 = 0; + + s6 += s18 * 666643; + s7 += s18 * 470296; + s8 += s18 * 654183; + s9 -= s18 * 997805; + s10 += s18 * 136657; + s11 -= s18 * 683901; + s18 = 0; + + carry6 = (s6 + (1<<20)) >> 21; s7 += carry6; s6 -= carry6 << 21; + carry8 = (s8 + (1<<20)) >> 21; s9 += carry8; s8 -= carry8 << 21; + carry10 = (s10 + (1<<20)) >> 21; s11 += carry10; s10 -= carry10 << 21; + carry12 = (s12 + (1<<20)) >> 21; s13 += carry12; s12 -= carry12 << 21; + carry14 = (s14 + (1<<20)) >> 21; s15 += carry14; s14 -= carry14 << 21; + carry16 = (s16 + (1<<20)) >> 21; s17 += carry16; s16 -= carry16 << 21; + + carry7 = (s7 + (1<<20)) >> 21; s8 += carry7; s7 -= carry7 << 21; + carry9 = (s9 + (1<<20)) >> 21; s10 += carry9; s9 -= carry9 << 21; + carry11 = (s11 + (1<<20)) >> 21; s12 += carry11; s11 -= carry11 << 21; + carry13 = (s13 + (1<<20)) >> 21; s14 += carry13; s13 -= carry13 << 21; + carry15 = (s15 + (1<<20)) >> 21; s16 += carry15; s15 -= carry15 << 21; + + s5 += s17 * 666643; + s6 += s17 * 470296; + s7 += s17 * 654183; + s8 -= s17 * 997805; + s9 += s17 * 136657; + s10 -= s17 * 683901; + s17 = 0; + + s4 += s16 * 666643; + s5 += s16 * 470296; + s6 += s16 * 654183; + s7 -= s16 * 997805; + s8 += s16 * 136657; + s9 -= s16 * 683901; + s16 = 0; + + s3 += s15 * 666643; + s4 += s15 * 470296; + s5 += s15 * 654183; + s6 -= s15 * 997805; + s7 += s15 * 136657; + s8 -= s15 * 683901; + s15 = 0; + + s2 += s14 * 666643; + s3 += s14 * 470296; + s4 += s14 * 654183; + s5 -= s14 * 997805; + s6 += s14 * 136657; + s7 -= s14 * 683901; + s14 = 0; + + s1 += s13 * 666643; + s2 += s13 * 470296; + s3 += s13 * 654183; + s4 -= s13 * 997805; + s5 += s13 * 136657; + s6 -= s13 * 683901; + s13 = 0; + + s0 += s12 * 666643; + s1 += s12 * 470296; + s2 += s12 * 654183; + s3 -= s12 * 997805; + s4 += s12 * 136657; + s5 -= s12 * 683901; + s12 = 0; + + carry0 = (s0 + (1<<20)) >> 21; s1 += carry0; s0 -= carry0 << 21; + carry2 = (s2 + (1<<20)) >> 21; s3 += carry2; s2 -= carry2 << 21; + carry4 = (s4 + (1<<20)) >> 21; s5 += carry4; s4 -= carry4 << 21; + carry6 = (s6 + (1<<20)) >> 21; s7 += carry6; s6 -= carry6 << 21; + carry8 = (s8 + (1<<20)) >> 21; s9 += carry8; s8 -= carry8 << 21; + carry10 = (s10 + (1<<20)) >> 21; s11 += carry10; s10 -= carry10 << 21; + + carry1 = (s1 + (1<<20)) >> 21; s2 += carry1; s1 -= carry1 << 21; + carry3 = (s3 + (1<<20)) >> 21; s4 += carry3; s3 -= carry3 << 21; + carry5 = (s5 + (1<<20)) >> 21; s6 += carry5; s5 -= carry5 << 21; + carry7 = (s7 + (1<<20)) >> 21; s8 += carry7; s7 -= carry7 << 21; + carry9 = (s9 + (1<<20)) >> 21; s10 += carry9; s9 -= carry9 << 21; + carry11 = (s11 + (1<<20)) >> 21; s12 += carry11; s11 -= carry11 << 21; + + s0 += s12 * 666643; + s1 += s12 * 470296; + s2 += s12 * 654183; + s3 -= s12 * 997805; + s4 += s12 * 136657; + s5 -= s12 * 683901; + s12 = 0; + + carry0 = s0 >> 21; s1 += carry0; s0 -= carry0 << 21; + carry1 = s1 >> 21; s2 += carry1; s1 -= carry1 << 21; + carry2 = s2 >> 21; s3 += carry2; s2 -= carry2 << 21; + carry3 = s3 >> 21; s4 += carry3; s3 -= carry3 << 21; + carry4 = s4 >> 21; s5 += carry4; s4 -= carry4 << 21; + carry5 = s5 >> 21; s6 += carry5; s5 -= carry5 << 21; + carry6 = s6 >> 21; s7 += carry6; s6 -= carry6 << 21; + carry7 = s7 >> 21; s8 += carry7; s7 -= carry7 << 21; + carry8 = s8 >> 21; s9 += carry8; s8 -= carry8 << 21; + carry9 = s9 >> 21; s10 += carry9; s9 -= carry9 << 21; + carry10 = s10 >> 21; s11 += carry10; s10 -= carry10 << 21; + carry11 = s11 >> 21; s12 += carry11; s11 -= carry11 << 21; + + s0 += s12 * 666643; + s1 += s12 * 470296; + s2 += s12 * 654183; + s3 -= s12 * 997805; + s4 += s12 * 136657; + s5 -= s12 * 683901; + s12 = 0; + + carry0 = s0 >> 21; s1 += carry0; s0 -= carry0 << 21; + carry1 = s1 >> 21; s2 += carry1; s1 -= carry1 << 21; + carry2 = s2 >> 21; s3 += carry2; s2 -= carry2 << 21; + carry3 = s3 >> 21; s4 += carry3; s3 -= carry3 << 21; + carry4 = s4 >> 21; s5 += carry4; s4 -= carry4 << 21; + carry5 = s5 >> 21; s6 += carry5; s5 -= carry5 << 21; + carry6 = s6 >> 21; s7 += carry6; s6 -= carry6 << 21; + carry7 = s7 >> 21; s8 += carry7; s7 -= carry7 << 21; + carry8 = s8 >> 21; s9 += carry8; s8 -= carry8 << 21; + carry9 = s9 >> 21; s10 += carry9; s9 -= carry9 << 21; + carry10 = s10 >> 21; s11 += carry10; s10 -= carry10 << 21; + + s[0] = s0 >> 0; + s[1] = s0 >> 8; + s[2] = (s0 >> 16) | (s1 << 5); + s[3] = s1 >> 3; + s[4] = s1 >> 11; + s[5] = (s1 >> 19) | (s2 << 2); + s[6] = s2 >> 6; + s[7] = (s2 >> 14) | (s3 << 7); + s[8] = s3 >> 1; + s[9] = s3 >> 9; + s[10] = (s3 >> 17) | (s4 << 4); + s[11] = s4 >> 4; + s[12] = s4 >> 12; + s[13] = (s4 >> 20) | (s5 << 1); + s[14] = s5 >> 7; + s[15] = (s5 >> 15) | (s6 << 6); + s[16] = s6 >> 2; + s[17] = s6 >> 10; + s[18] = (s6 >> 18) | (s7 << 3); + s[19] = s7 >> 5; + s[20] = s7 >> 13; + s[21] = s8 >> 0; + s[22] = s8 >> 8; + s[23] = (s8 >> 16) | (s9 << 5); + s[24] = s9 >> 3; + s[25] = s9 >> 11; + s[26] = (s9 >> 19) | (s10 << 2); + s[27] = s10 >> 6; + s[28] = (s10 >> 14) | (s11 << 7); + s[29] = s11 >> 1; + s[30] = s11 >> 9; + s[31] = s11 >> 17; +} diff --git a/vendor/MDBC/plugins/auth/ref10/sign.c b/vendor/MDBC/plugins/auth/ref10/sign.c new file mode 100644 index 00000000..b4153201 --- /dev/null +++ b/vendor/MDBC/plugins/auth/ref10/sign.c @@ -0,0 +1,39 @@ +#include +#include "crypto_sign.h" +#include "crypto_hash_sha512.h" +#include "ge.h" +#include "sc.h" + +int ma_crypto_sign( + unsigned char *sm, + const unsigned char *m,unsigned long long mlen, + const unsigned char *pw,unsigned long long pwlen +) +{ + unsigned char az[64]; + unsigned char nonce[64]; + unsigned char hram[64]; + ge_p3 A, R; + + crypto_hash_sha512(az,pw,pwlen); + az[0] &= 248; + az[31] &= 63; + az[31] |= 64; + + memmove(sm + 64,m,mlen); + memmove(sm + 32,az + 32,32); + crypto_hash_sha512(nonce,sm + 32,mlen + 32); + + ge_scalarmult_base(&A,az); + ge_p3_tobytes(sm + 32,&A); + + sc_reduce(nonce); + ge_scalarmult_base(&R,nonce); + ge_p3_tobytes(sm,&R); + + crypto_hash_sha512(hram,sm,mlen + 64); + sc_reduce(hram); + sc_muladd(sm + 32,hram,az,nonce); + + return 0; +} diff --git a/vendor/MDBC/plugins/auth/ref10/sqrtm1.h b/vendor/MDBC/plugins/auth/ref10/sqrtm1.h new file mode 100644 index 00000000..d8caa23b --- /dev/null +++ b/vendor/MDBC/plugins/auth/ref10/sqrtm1.h @@ -0,0 +1 @@ +-32595792,-7943725,9377950,3500415,12389472,-272473,-25146209,-2005654,326686,11406482 diff --git a/vendor/MDBC/plugins/auth/ref10/verify.c b/vendor/MDBC/plugins/auth/ref10/verify.c new file mode 100644 index 00000000..a0e23afe --- /dev/null +++ b/vendor/MDBC/plugins/auth/ref10/verify.c @@ -0,0 +1,40 @@ +#include "crypto_verify.h" + +int crypto_verify(const unsigned char *x,const unsigned char *y) +{ + unsigned int differentbits = 0; +#define F(i) differentbits |= x[i] ^ y[i]; + F(0) + F(1) + F(2) + F(3) + F(4) + F(5) + F(6) + F(7) + F(8) + F(9) + F(10) + F(11) + F(12) + F(13) + F(14) + F(15) + F(16) + F(17) + F(18) + F(19) + F(20) + F(21) + F(22) + F(23) + F(24) + F(25) + F(26) + F(27) + F(28) + F(29) + F(30) + F(31) + return (1 & ((differentbits - 1) >> 8)) - 1; +} diff --git a/vendor/MDBC/plugins/auth/server_plugin.h b/vendor/MDBC/plugins/auth/server_plugin.h new file mode 100644 index 00000000..1348835e --- /dev/null +++ b/vendor/MDBC/plugins/auth/server_plugin.h @@ -0,0 +1,51 @@ +/* Copyright (c) 2015, Shuang Qiu, Robbie Harwood, +Vladislav Vaintroub & MariaDB Corporation + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, +this list of conditions and the following disclaimer in the documentation +and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. +*/ + +/* Plugin variables*/ +#include +typedef enum +{ + PLUGIN_MECH_KERBEROS = 0, + PLUGIN_MECH_SPNEGO = 1, + PLUGIN_MECH_DEFAULT = 2 +}PLUGIN_MECH; + +extern unsigned long srv_mech; +extern char *srv_principal_name; +extern char *srv_mech_name; +extern char *srv_keytab_path; +/* + Check, with GSSAPI/SSPI username of logged on user. + + Depending on use_full_name parameter, compare either full name + (principal name like user@real), or local name (first component) +*/ +int plugin_init(); +int plugin_deinit(); + +int auth_server(MYSQL_PLUGIN_VIO *vio, const char *username, size_t username_len, int use_full_name); diff --git a/vendor/MDBC/plugins/auth/sha256_pw.c b/vendor/MDBC/plugins/auth/sha256_pw.c new file mode 100644 index 00000000..fbe5a2bd --- /dev/null +++ b/vendor/MDBC/plugins/auth/sha256_pw.c @@ -0,0 +1,358 @@ +/************************************************************************************ + Copyright (C) 2017 MariaDB Corporation AB + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not see + or write to the Free Software Foundation, Inc., + 51 Franklin St., Fifth Floor, Boston, MA 02110, USA + *************************************************************************************/ +#ifndef _WIN32 +#define _GNU_SOURCE 1 +#endif + +#ifdef _WIN32 +#undef HAVE_GNUTLS +#undef HAVE_OPENSSL +#define HAVE_WINCRYPT +#endif + +#if defined(HAVE_OPENSSL) || defined(HAVE_WINCRYPT) + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifndef WIN32 +#include +#endif + +#if defined(WIN32) +#include +#elif defined(HAVE_OPENSSL) +#include +#include +#include +#endif + +#define MAX_PW_LEN 1024 + +/* function prototypes */ +static int auth_sha256_client(MYSQL_PLUGIN_VIO *vio, MYSQL *mysql); +static int auth_sha256_init(char *unused1, + size_t unused2, + int unused3, + va_list); + + +#ifndef PLUGIN_DYNAMIC +struct st_mysql_client_plugin_AUTHENTICATION sha256_password_client_plugin= +#else +struct st_mysql_client_plugin_AUTHENTICATION _mysql_client_plugin_declaration_ = +#endif +{ + MYSQL_CLIENT_AUTHENTICATION_PLUGIN, + MYSQL_CLIENT_AUTHENTICATION_PLUGIN_INTERFACE_VERSION, + "sha256_password", + "Georg Richter", + "SHA256 Authentication Plugin", + {0,1,0}, + "LGPL", + NULL, + auth_sha256_init, + NULL, + NULL, + auth_sha256_client +}; + +#ifdef HAVE_WINCRYPT +static LPBYTE ma_load_pem(const char *buffer, DWORD *buffer_len) +{ + LPBYTE der_buffer= NULL; + DWORD der_buffer_length= 0; + + if (buffer_len == NULL || *buffer_len == 0) + return NULL; + /* calculate the length of DER binary */ + if (!CryptStringToBinaryA(buffer, *buffer_len, CRYPT_STRING_BASE64HEADER, + NULL, &der_buffer_length, NULL, NULL)) + goto end; + /* allocate DER binary buffer */ + if (!(der_buffer= (LPBYTE)LocalAlloc(0, der_buffer_length))) + goto end; + /* convert to DER binary */ + if (!CryptStringToBinaryA(buffer, *buffer_len, CRYPT_STRING_BASE64HEADER, + der_buffer, &der_buffer_length, NULL, NULL)) + goto end; + + *buffer_len= der_buffer_length; + + return der_buffer; + +end: + if (der_buffer) + LocalFree(der_buffer); + *buffer_len= 0; + return NULL; +} +#endif + +static char *load_pub_key_file(const char *filename, int *pub_key_size) +{ + FILE *fp= NULL; + char *buffer= NULL; + unsigned char error= 1; + size_t bytes_read= 0; + long fsize= 0; + + if (!pub_key_size) + return NULL; + + if (!(fp= fopen(filename, "r"))) + goto end; + + if (fseek(fp, 0, SEEK_END)) + goto end; + + fsize= ftell(fp); + if (fsize < 0) + goto end; + + rewind(fp); + + if (!(buffer= malloc(fsize + 1))) + goto end; + + bytes_read= fread(buffer, 1, (size_t)fsize, fp); + if (bytes_read < (size_t)fsize) + goto end; + + *pub_key_size= (int)bytes_read; + + error= 0; + +end: + if (fp) + fclose(fp); + if (error && buffer) + { + free(buffer); + buffer= NULL; + } + return buffer; +} + + +static int auth_sha256_client(MYSQL_PLUGIN_VIO *vio, MYSQL *mysql) +{ + unsigned char *packet; + int packet_length; + int rc= CR_ERROR; + char passwd[MAX_PW_LEN]; + unsigned int rsa_size; + unsigned int pwlen, i; + +#if defined(HAVE_OPENSSL) + EVP_PKEY *pubkey= NULL; + EVP_PKEY_CTX *ctx= NULL; + size_t outlen= 0; + unsigned char *rsa_enc_pw= NULL; + BIO *bio; +#elif defined(HAVE_WINCRYPT) + unsigned char rsa_enc_pw[MAX_PW_LEN]; + HCRYPTKEY pubkey= 0; + HCRYPTPROV hProv= 0; + LPBYTE der_buffer= NULL; + DWORD der_buffer_len= 0; + CERT_PUBLIC_KEY_INFO *publicKeyInfo= NULL; + DWORD ParamSize= sizeof(DWORD); + int publicKeyInfoLen= 0; +#endif + char *filebuffer= NULL; + + /* read error */ + if ((packet_length= vio->read_packet(vio, &packet)) < 0) + return CR_ERROR; + + if (packet_length != SCRAMBLE_LENGTH + 1) + return CR_SERVER_HANDSHAKE_ERR; + + memmove(mysql->scramble_buff, packet, SCRAMBLE_LENGTH); + mysql->scramble_buff[SCRAMBLE_LENGTH]= 0; + + /* if a tls session is active we need to send plain password */ + if (mysql->client_flag & CLIENT_SSL) + { + if (vio->write_packet(vio, (unsigned char *)mysql->passwd, (int)strlen(mysql->passwd) + 1)) + return CR_ERROR; + return CR_OK; + } + + /* send empty packet if no password was provided */ + if (!mysql->passwd || !mysql->passwd[0]) + { + if (vio->write_packet(vio, 0, 0)) + return CR_ERROR; + return CR_OK; + } + + /* read public key file (if specified) */ + if (mysql->options.extension && + mysql->options.extension->server_public_key) + { + filebuffer= load_pub_key_file(mysql->options.extension->server_public_key, + &packet_length); + } + + /* if no public key file was specified or if we couldn't read the file, + we ask server to send public key */ + if (!filebuffer) + { + unsigned char buf= 1; + if (vio->write_packet(vio, &buf, 1)) + return CR_ERROR; + if ((packet_length=vio->read_packet(vio, &packet)) == -1) + return CR_ERROR; + } +#if defined(HAVE_OPENSSL) + bio= BIO_new_mem_buf(filebuffer ? (unsigned char *)filebuffer : packet, + packet_length); + if ((pubkey= PEM_read_bio_PUBKEY(bio, NULL, NULL, NULL))) + { + if (!(ctx= EVP_PKEY_CTX_new(pubkey, NULL))) + goto error; + if (EVP_PKEY_encrypt_init(ctx) <= 0) + goto error; + if (EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_OAEP_PADDING) <= 0) + goto error; + rsa_size= EVP_PKEY_size(pubkey); + } + BIO_free(bio); + bio= NULL; + ERR_clear_error(); +#elif defined(HAVE_WINCRYPT) + der_buffer_len= packet_length; + /* Load pem and convert it to binary object. New length will be returned + in der_buffer_len */ + if (!(der_buffer= ma_load_pem(filebuffer ? filebuffer : (char *)packet, &der_buffer_len))) + goto error; + + /* Create context and load public key */ + if (!CryptDecodeObjectEx(X509_ASN_ENCODING, X509_PUBLIC_KEY_INFO, + der_buffer, der_buffer_len, + CRYPT_DECODE_ALLOC_FLAG, NULL, + &publicKeyInfo, (DWORD *)&publicKeyInfoLen)) + goto error; + LocalFree(der_buffer); + + if (!CryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_FULL, + CRYPT_VERIFYCONTEXT)) + goto error; + if (!CryptImportPublicKeyInfo(hProv, X509_ASN_ENCODING, + publicKeyInfo, &pubkey)) + goto error; + + /* Get rsa_size */ + CryptGetKeyParam(pubkey, KP_KEYLEN, (BYTE *)&rsa_size, &ParamSize, 0); + rsa_size /= 8; +#endif + if (!pubkey) + return CR_ERROR; + + pwlen= (unsigned int)strlen(mysql->passwd) + 1; /* include terminating zero */ + if (pwlen > MAX_PW_LEN) + goto error; + memcpy(passwd, mysql->passwd, pwlen); + + /* xor password with scramble */ + for (i=0; i < pwlen; i++) + passwd[i]^= *(mysql->scramble_buff + i % SCRAMBLE_LENGTH); + + /* encrypt scrambled password */ +#if defined(HAVE_OPENSSL) + if (EVP_PKEY_encrypt(ctx, NULL, &outlen, (unsigned char *)passwd, pwlen) <= 0) + goto error; + if (!(rsa_enc_pw= malloc(outlen))) + goto error; + if (EVP_PKEY_encrypt(ctx, rsa_enc_pw, &outlen, (unsigned char *)passwd, pwlen) <= 0) + goto error; +#elif defined(HAVE_WINCRYPT) + if (!CryptEncrypt(pubkey, 0, TRUE, CRYPT_OAEP, (BYTE *)passwd, (DWORD *)&pwlen, MAX_PW_LEN)) + goto error; + /* Windows encrypts as little-endian, while server (openssl) expects + big-endian, so we have to revert the string */ + for (i= 0; i < rsa_size / 2; i++) + { + rsa_enc_pw[i]= passwd[rsa_size - 1 - i]; + rsa_enc_pw[rsa_size - 1 - i]= passwd[i]; + } +#endif + if (vio->write_packet(vio, rsa_enc_pw, rsa_size)) + goto error; + + rc= CR_OK; +error: +#if defined(HAVE_OPENSSL) + if (pubkey) + EVP_PKEY_free(pubkey); + if (bio) + BIO_free(bio); + if (ctx) + EVP_PKEY_CTX_free(ctx); + if (rsa_enc_pw) + free(rsa_enc_pw); +#elif defined(HAVE_WINCRYPT) + CryptReleaseContext(hProv, 0); + if (publicKeyInfo) + LocalFree(publicKeyInfo); +#endif + free(filebuffer); + return rc; +} +/* }}} */ + +/* {{{ static int auth_sha256_init */ +/* + Initialization routine + + SYNOPSIS + auth_sha256_init + unused1 + unused2 + unused3 + unused4 + + DESCRIPTION + Init function checks if the caller provides own dialog function. + The function name must be mariadb_auth_dialog or + mysql_authentication_dialog_ask. If the function cannot be found, + we will use owr own simple command line input. + + RETURN + 0 success + */ +static int auth_sha256_init(char *unused1 __attribute__((unused)), + size_t unused2 __attribute__((unused)), + int unused3 __attribute__((unused)), + va_list unused4 __attribute__((unused))) +{ + return 0; +} +/* }}} */ + +#endif /* defined(HAVE_OPENSSL) || defined(HAVE_WINCRYPT) */ diff --git a/vendor/MDBC/plugins/auth/sspi_client.c b/vendor/MDBC/plugins/auth/sspi_client.c new file mode 100644 index 00000000..e257cd9d --- /dev/null +++ b/vendor/MDBC/plugins/auth/sspi_client.c @@ -0,0 +1,184 @@ +/* Copyright (c) 2015, Shuang Qiu, Robbie Harwood, +Vladislav Vaintroub & MariaDB Corporation + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, +this list of conditions and the following disclaimer in the documentation +and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. +*/ + +#define SECURITY_WIN32 +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "sspi_common.h" + +extern void log_client_error(MYSQL *mysql, const char *fmt, ...); +static void log_error(MYSQL *mysql, SECURITY_STATUS err, const char *msg) +{ + if (err) + { + char buf[1024]; + sspi_errmsg(err, buf, sizeof(buf)); + log_client_error(mysql, "SSPI client error 0x%x - %s - %s", err, msg, buf); + } + else + { + log_client_error(mysql, "SSPI client error %s", msg); + } +} + + +/** Client side authentication*/ +int auth_client(char *principal_name, char *mech, MYSQL *mysql, MYSQL_PLUGIN_VIO *vio) +{ + + int ret; + CredHandle cred; + CtxtHandle ctxt; + ULONG attribs = 0; + TimeStamp lifetime; + SECURITY_STATUS sspi_err; + + SecBufferDesc inbuf_desc; + SecBuffer inbuf; + SecBufferDesc outbuf_desc; + SecBuffer outbuf; + PBYTE out = NULL; + + ret= CR_ERROR; + SecInvalidateHandle(&ctxt); + SecInvalidateHandle(&cred); + + if (!mech || strcmp(mech, "Negotiate") != 0) + { + mech= (char *)"Kerberos"; + } + + sspi_err = AcquireCredentialsHandle( + NULL, + mech, + SECPKG_CRED_OUTBOUND, + NULL, + NULL, + NULL, + NULL, + &cred, + &lifetime); + + if (SEC_ERROR(sspi_err)) + { + log_error(mysql, sspi_err, "AcquireCredentialsHandle"); + return CR_ERROR; + } + + out = (PBYTE)malloc(SSPI_MAX_TOKEN_SIZE); + if (!out) + { + log_error(mysql, SEC_E_OK, "memory allocation error"); + goto cleanup; + } + + /* Prepare buffers */ + inbuf_desc.ulVersion = SECBUFFER_VERSION; + inbuf_desc.cBuffers = 1; + inbuf_desc.pBuffers = &inbuf; + inbuf.BufferType = SECBUFFER_TOKEN; + inbuf.cbBuffer = 0; + inbuf.pvBuffer = NULL; + + outbuf_desc.ulVersion = SECBUFFER_VERSION; + outbuf_desc.cBuffers = 1; + outbuf_desc.pBuffers = &outbuf; + outbuf.BufferType = SECBUFFER_TOKEN; + outbuf.pvBuffer = out; + + do + { + outbuf.cbBuffer= SSPI_MAX_TOKEN_SIZE; + sspi_err= InitializeSecurityContext( + &cred, + SecIsValidHandle(&ctxt) ? &ctxt : NULL, + principal_name, + 0, + 0, + SECURITY_NATIVE_DREP, + inbuf.cbBuffer ? &inbuf_desc : NULL, + 0, + &ctxt, + &outbuf_desc, + &attribs, + &lifetime); + if (SEC_ERROR(sspi_err)) + { + log_error(mysql, sspi_err, "InitializeSecurityContext"); + goto cleanup; + } + if (sspi_err != SEC_E_OK && sspi_err != SEC_I_CONTINUE_NEEDED) + { + log_error(mysql, sspi_err, "Unexpected response from InitializeSecurityContext"); + goto cleanup; + } + + if (outbuf.cbBuffer) + { + /* send credential to server */ + if (vio->write_packet(vio, (unsigned char *)outbuf.pvBuffer, outbuf.cbBuffer)) + { + /* Server error packet contains detailed message. */ + ret= CR_OK_HANDSHAKE_COMPLETE; + goto cleanup; + } + } + + if (sspi_err == SEC_I_CONTINUE_NEEDED) + { + int len= vio->read_packet(vio, (unsigned char **)&inbuf.pvBuffer); + if (len <= 0) + { + /* Server side error is in the last server packet. */ + ret= CR_OK_HANDSHAKE_COMPLETE; + goto cleanup; + } + inbuf.cbBuffer= len; + } + } while (sspi_err == SEC_I_CONTINUE_NEEDED); + + ret= CR_OK; + +cleanup: + + if (SecIsValidHandle(&ctxt)) + DeleteSecurityContext(&ctxt); + if (SecIsValidHandle(&cred)) + FreeCredentialsHandle(&cred); + free(out); + return ret; +} diff --git a/vendor/MDBC/plugins/auth/sspi_common.h b/vendor/MDBC/plugins/auth/sspi_common.h new file mode 100644 index 00000000..da9159eb --- /dev/null +++ b/vendor/MDBC/plugins/auth/sspi_common.h @@ -0,0 +1,38 @@ +/* Copyright (c) 2015, Shuang Qiu, Robbie Harwood, +Vladislav Vaintroub & MariaDB Corporation + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, +this list of conditions and the following disclaimer in the documentation +and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. +*/ + +#define SECURITY_WIN32 +#include +#include +#include +#include +#include + +#define SSPI_MAX_TOKEN_SIZE 50000 +#define SEC_ERROR(err) ((err) < 0) +extern void sspi_errmsg(int err, char *buf, size_t size); diff --git a/vendor/MDBC/plugins/auth/sspi_errmsg.c b/vendor/MDBC/plugins/auth/sspi_errmsg.c new file mode 100644 index 00000000..15cb2582 --- /dev/null +++ b/vendor/MDBC/plugins/auth/sspi_errmsg.c @@ -0,0 +1,169 @@ +/* Copyright (c) 2015, Shuang Qiu, Robbie Harwood, +Vladislav Vaintroub & MariaDB Corporation + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, +this list of conditions and the following disclaimer in the documentation +and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. +*/ + +#include +#include + +#ifndef SEC_E_INVALID_PARAMETER +#define SEC_E_INVALID_PARAMETER _HRESULT_TYPEDEF_(0x8009035D) +#endif +#ifndef SEC_E_DELEGATION_POLICY +#define SEC_E_DELEGATION_POLICY _HRESULT_TYPEDEF_(0x8009035E) +#endif +#ifndef SEC_E_POLICY_NLTM_ONLY +#define SEC_E_POLICY_NLTM_ONLY _HRESULT_TYPEDEF_(0x8009035F) +#endif +#ifndef SEC_E_NO_CONTEXT +#define SEC_E_NO_CONTEXT _HRESULT_TYPEDEF_(0x80090361) +#endif +#ifndef SEC_E_PKU2U_CERT_FAILURE +#define SEC_E_PKU2U_CERT_FAILURE _HRESULT_TYPEDEF_(0x80090362) +#endif +#ifndef SEC_E_MUTUAL_AUTH_FAILED +#define SEC_E_MUTUAL_AUTH_FAILED _HRESULT_TYPEDEF_(0x80090363) +#endif + +#define ERRSYM(x) {x, #x} +static struct { + int error; + const char *sym; +} error_symbols[] = +{ + ERRSYM(SEC_E_OK), + ERRSYM(SEC_E_INSUFFICIENT_MEMORY), + ERRSYM(SEC_E_INVALID_HANDLE), + ERRSYM(SEC_E_UNSUPPORTED_FUNCTION), + ERRSYM(SEC_E_TARGET_UNKNOWN), + ERRSYM(SEC_E_INTERNAL_ERROR), + ERRSYM(SEC_E_SECPKG_NOT_FOUND), + ERRSYM(SEC_E_NOT_OWNER), + ERRSYM(SEC_E_CANNOT_INSTALL), + ERRSYM(SEC_E_INVALID_TOKEN), + ERRSYM(SEC_E_CANNOT_PACK), + ERRSYM(SEC_E_QOP_NOT_SUPPORTED), + ERRSYM(SEC_E_NO_IMPERSONATION), + ERRSYM(SEC_E_LOGON_DENIED), + ERRSYM(SEC_E_UNKNOWN_CREDENTIALS), + ERRSYM(SEC_E_NO_CREDENTIALS), + ERRSYM(SEC_E_MESSAGE_ALTERED), + ERRSYM(SEC_E_OUT_OF_SEQUENCE), + ERRSYM(SEC_E_NO_AUTHENTICATING_AUTHORITY), + ERRSYM(SEC_E_BAD_PKGID), + ERRSYM(SEC_E_CONTEXT_EXPIRED), + ERRSYM(SEC_E_INCOMPLETE_MESSAGE), + ERRSYM(SEC_E_INCOMPLETE_CREDENTIALS), + ERRSYM(SEC_E_BUFFER_TOO_SMALL), + ERRSYM(SEC_E_WRONG_PRINCIPAL), + ERRSYM(SEC_E_TIME_SKEW), + ERRSYM(SEC_E_UNTRUSTED_ROOT), + ERRSYM(SEC_E_ILLEGAL_MESSAGE), + ERRSYM(SEC_E_CERT_UNKNOWN), + ERRSYM(SEC_E_CERT_EXPIRED), + ERRSYM(SEC_E_ENCRYPT_FAILURE), + ERRSYM(SEC_E_DECRYPT_FAILURE), + ERRSYM(SEC_E_ALGORITHM_MISMATCH), + ERRSYM(SEC_E_SECURITY_QOS_FAILED), + ERRSYM(SEC_E_UNFINISHED_CONTEXT_DELETED), + ERRSYM(SEC_E_NO_TGT_REPLY), + ERRSYM(SEC_E_NO_IP_ADDRESSES), + ERRSYM(SEC_E_WRONG_CREDENTIAL_HANDLE), + ERRSYM(SEC_E_CRYPTO_SYSTEM_INVALID), + ERRSYM(SEC_E_MAX_REFERRALS_EXCEEDED), + ERRSYM(SEC_E_MUST_BE_KDC), + ERRSYM(SEC_E_STRONG_CRYPTO_NOT_SUPPORTED), + ERRSYM(SEC_E_TOO_MANY_PRINCIPALS), + ERRSYM(SEC_E_NO_PA_DATA), + ERRSYM(SEC_E_PKINIT_NAME_MISMATCH), + ERRSYM(SEC_E_SMARTCARD_LOGON_REQUIRED), + ERRSYM(SEC_E_SHUTDOWN_IN_PROGRESS), + ERRSYM(SEC_E_KDC_INVALID_REQUEST), + ERRSYM(SEC_E_KDC_UNABLE_TO_REFER), + ERRSYM(SEC_E_KDC_UNKNOWN_ETYPE), + ERRSYM(SEC_E_UNSUPPORTED_PREAUTH), + ERRSYM(SEC_E_DELEGATION_REQUIRED), + ERRSYM(SEC_E_BAD_BINDINGS), + ERRSYM(SEC_E_MULTIPLE_ACCOUNTS), + ERRSYM(SEC_E_NO_KERB_KEY), + ERRSYM(SEC_E_CERT_WRONG_USAGE), + ERRSYM(SEC_E_DOWNGRADE_DETECTED), + ERRSYM(SEC_E_SMARTCARD_CERT_REVOKED), + ERRSYM(SEC_E_ISSUING_CA_UNTRUSTED), + ERRSYM(SEC_E_REVOCATION_OFFLINE_C), + ERRSYM(SEC_E_PKINIT_CLIENT_FAILURE), + ERRSYM(SEC_E_SMARTCARD_CERT_EXPIRED), + ERRSYM(SEC_E_NO_S4U_PROT_SUPPORT), + ERRSYM(SEC_E_CROSSREALM_DELEGATION_FAILURE), + ERRSYM(SEC_E_REVOCATION_OFFLINE_KDC), + ERRSYM(SEC_E_ISSUING_CA_UNTRUSTED_KDC), + ERRSYM(SEC_E_KDC_CERT_EXPIRED), + ERRSYM(SEC_E_KDC_CERT_REVOKED), + ERRSYM(SEC_E_INVALID_PARAMETER), + ERRSYM(SEC_E_DELEGATION_POLICY), + ERRSYM(SEC_E_POLICY_NLTM_ONLY), + ERRSYM(SEC_E_NO_CONTEXT), + ERRSYM(SEC_E_PKU2U_CERT_FAILURE), + ERRSYM(SEC_E_MUTUAL_AUTH_FAILED), + ERRSYM(SEC_E_NO_SPM), + ERRSYM(SEC_E_NOT_SUPPORTED), + {0,0} +}; + +void sspi_errmsg(int err, char *buf, size_t size) +{ + size_t len,i; + + buf[size - 1] = 0; + for (i= 0; error_symbols[i].sym; i++) + { + if (error_symbols[i].error == err) + { + size_t len= strlen(error_symbols[i].sym); + if (len + 2 < size) + { + memcpy(buf, error_symbols[i].sym, len); + buf[len]= ' '; + buf += len + 1; + size-= len + 1; + } + break; + } + } + + len = FormatMessageA( + FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, + err, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), + buf, (DWORD)size, NULL); + + if(len > 0) + { + /* Trim trailing \n\r*/ + char *p; + for(p= buf + len;p > buf && (*p == '\n' || *p=='\r' || *p == 0);p--) + *p= 0; + } +} diff --git a/vendor/MDBC/plugins/connection/CMakeLists.txt b/vendor/MDBC/plugins/connection/CMakeLists.txt new file mode 100644 index 00000000..cbfd4633 --- /dev/null +++ b/vendor/MDBC/plugins/connection/CMakeLists.txt @@ -0,0 +1,13 @@ +# Aurora +REGISTER_PLUGIN(TARGET aurora + TYPE MARIADB_CLIENT_PLUGIN_CONNECTION + CONFIGURATIONS STATIC DYNAMIC OFF + DEFAULT OFF + SOURCES ${CC_SOURCE_DIR}/plugins/connection/aurora.c) + +# Replication +REGISTER_PLUGIN(TARGET replication + TYPE MARIADB_CLIENT_PLUGIN_CONNECTION + CONFIGURATIONS STATIC DYNAMIC OFF + DEFAULT OFF + SOURCES ${CC_SOURCE_DIR}/plugins/connection/replication.c) diff --git a/vendor/MDBC/plugins/connection/replication.c b/vendor/MDBC/plugins/connection/replication.c new file mode 100644 index 00000000..0e7a18b7 --- /dev/null +++ b/vendor/MDBC/plugins/connection/replication.c @@ -0,0 +1,357 @@ +/************************************************************************************ + Copyright (C) 2015-2018 MariaDB Corporation AB + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not see + or write to the Free Software Foundation, Inc., + 51 Franklin St., Fifth Floor, Boston, MA 02110, USA + + Part of this code includes code from the PHP project which + is freely available from http://www.php.net +*************************************************************************************/ + +/* MariaDB Connection plugin for load balancing */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#ifndef WIN32 +#include +#endif + +/* function prototypes */ +MYSQL *repl_connect(MYSQL *mysql, const char *host, const char *user, const char *passwd, + const char *db, unsigned int port, const char *unix_socket, unsigned long clientflag); +void repl_close(MYSQL *mysql); +int repl_command(MYSQL *mysql,enum enum_server_command command, const char *arg, + size_t length, my_bool skipp_check, void *opt_arg); +int repl_set_optionsv(MYSQL *mysql, unsigned int option, ...); + +#define MARIADB_MASTER 0 +#define MARIADB_SLAVE 1 + +static struct st_mariadb_api *libmariadb_api= NULL; + +#ifndef PLUGIN_DYNAMIC +MARIADB_CONNECTION_PLUGIN replication_client_plugin = +#else +MARIADB_CONNECTION_PLUGIN _mysql_client_plugin_declaration_ = +#endif +{ + MARIADB_CLIENT_CONNECTION_PLUGIN, + MARIADB_CLIENT_CONNECTION_PLUGIN_INTERFACE_VERSION, + "replication", + "Georg Richter", + "MariaDB connection plugin for load balancing", + {1, 0, 0}, + "LGPL", + NULL, + NULL, + NULL, + NULL, + repl_connect, + repl_close, + repl_set_optionsv, + repl_command, + NULL, + NULL +}; + +typedef struct st_conn_repl { + MARIADB_PVIO *pvio[2]; + MYSQL *slave_mysql; + my_bool read_only; + my_bool round_robin; + char *url; + char *host[2]; + unsigned int port[2]; + unsigned int current_type; +} REPL_DATA; + +#define SET_SLAVE(mysql, data)\ +do {\ + mysql->net.pvio= data->pvio[MARIADB_SLAVE]; \ + data->current_type= MARIADB_SLAVE;\ +} while(0) + +#define SET_MASTER(mysql, data)\ +do {\ + mysql->net.pvio= data->pvio[MARIADB_MASTER];\ + data->current_type= MARIADB_MASTER;\ +} while(0) + + +/* parse url + * Url has the following format: + * master[:port],slave1[:port],slave2[:port],..,slaven[:port] + * + */ + +my_bool repl_parse_url(const char *url, REPL_DATA *data) +{ + char *p; + char *slaves[64]; + int port[64], i,num_slaves= 0; + + if (!url || url[0] == 0) + return 1; + + memset(slaves, 0, 64 * sizeof(char *)); + memset(&port, 0, 64 * sizeof(int)); + + memset(data->host, 0, 2 * sizeof(char *)); + memset(data->port, 0, 2 * sizeof(int)); + + if (!data->url) + data->url= strdup(url); + data->host[MARIADB_MASTER]= p= data->url; + + /* get slaves */ + while((p && (p= strchr(p, ',')))) + { + *p= '\0'; + p++; + if (*p) + { + slaves[num_slaves]= p; + num_slaves++; + } + } + + if (!num_slaves) + return 0; + if (num_slaves == 1) + data->host[MARIADB_SLAVE]= slaves[0]; + else + { + int random_nr; +#ifndef WIN32 + struct timeval tp; + gettimeofday(&tp,NULL); + srand(tp.tv_usec / 1000 + tp.tv_sec * 1000); +#else + srand(GetTickCount()); +#endif + + random_nr= rand() % num_slaves; + data->host[MARIADB_SLAVE]= slaves[random_nr]; + } + + /* check ports */ + for (i=0; i < 2 && data->host[i]; i++) + { + /* We need to be aware of IPv6 addresses: According to RFC3986 sect. 3.2.2 + hostnames have to be enclosed in square brackets if a port is given */ + if (data->host[i][0]== '[' && strchr(data->host[i], ':') && (p= strchr(data->host[i],']'))) + { + /* ignore first square bracket */ + memmove(data->host[i], data->host[i]+1, strlen(data->host[i]) - 1); + p= strchr(data->host[i],']'); + *p= 0; + p++; + } + else + p= data->host[i]; + if (p && (p= strchr(p, ':'))) + { + *p= '\0'; + p++; + data->port[i]= atoi(p); + } + } + + return 0; +} + +MYSQL *repl_connect(MYSQL *mysql, const char *host, const char *user, const char *passwd, + const char *db, unsigned int port, const char *unix_socket, unsigned long clientflag) +{ + REPL_DATA *data= NULL; + MA_CONNECTION_HANDLER *hdlr= mysql->extension->conn_hdlr; + + if (!libmariadb_api) + libmariadb_api= mysql->methods->api; + + if ((data= (REPL_DATA *)hdlr->data)) + { + data->pvio[MARIADB_MASTER]->methods->close(data->pvio[MARIADB_MASTER]); + data->pvio[MARIADB_MASTER]= 0; + repl_close(mysql); + } + + if (!(data= calloc(1, sizeof(REPL_DATA)))) + { + mysql->methods->set_error(mysql, CR_OUT_OF_MEMORY, "HY000", 0); + return NULL; + } + memset(data->pvio, 0, 2 * sizeof(MARIADB_PVIO *)); + + if (repl_parse_url(host, data)) + goto error; + + /* try to connect to master */ + if (!(libmariadb_api->mysql_real_connect(mysql, data->host[MARIADB_MASTER], user, passwd, db, + data->port[MARIADB_MASTER] ? data->port[MARIADB_MASTER] : port, unix_socket, clientflag))) + goto error; + + data->pvio[MARIADB_MASTER]= mysql->net.pvio; + hdlr->data= data; + SET_MASTER(mysql, data); + + /* to allow immediate access without connection delay, we will start + * connecting to slave(s) in background */ + + /* if slave connection will fail, we will not return error but use master instead */ + if (!(data->slave_mysql= libmariadb_api->mysql_init(NULL)) || + !(mysql->methods->db_connect(data->slave_mysql, data->host[MARIADB_SLAVE], user, passwd, db, + data->port[MARIADB_SLAVE] ? data->port[MARIADB_SLAVE] : port, unix_socket, clientflag))) + { + if (data->slave_mysql) + libmariadb_api->mysql_close(data->slave_mysql); + data->pvio[MARIADB_SLAVE]= NULL; + } + else + { + data->pvio[MARIADB_SLAVE]= data->slave_mysql->net.pvio; + data->slave_mysql->net.pvio->mysql= mysql; + } + return mysql; +error: + if (data) + { + if (data->url) + free(data->url); + free(data); + } + return NULL; +} + +void repl_close(MYSQL *mysql) +{ + MA_CONNECTION_HANDLER *hdlr= mysql->extension->conn_hdlr; + REPL_DATA *data= (REPL_DATA *)hdlr->data; + + /* restore master */ + SET_MASTER(mysql, data); + + /* free slave information and close connection */ + if (data->pvio[MARIADB_SLAVE]) + { + /* restore mysql */ + data->pvio[MARIADB_SLAVE]->mysql= data->slave_mysql; + libmariadb_api->mysql_close(data->slave_mysql); + data->pvio[MARIADB_SLAVE]= NULL; + data->slave_mysql= NULL; + } + + /* free masrwe information and close connection */ + free(data->url); + free(data); + mysql->extension->conn_hdlr->data= NULL; +} + +static my_bool is_slave_command(const char *buffer, size_t buffer_len) +{ + const char *buffer_end= buffer + buffer_len; + + for (; buffer < buffer_end; ++buffer) + { + char c; + if (isalpha(c=*buffer)) + { + if (tolower(c) == 's') + return 1; + return 0; + } + } + return 0; +} + +static my_bool is_slave_stmt(MYSQL *mysql, const char *buffer) +{ + unsigned long stmt_id= uint4korr(buffer); + LIST *stmt_list= mysql->stmts; + + for (; stmt_list; stmt_list= stmt_list->next) + { + MYSQL_STMT *stmt= (MYSQL_STMT *)stmt_list->data; + if (stmt->stmt_id == stmt_id) + return 1; + } + return 0; +} + + +int repl_command(MYSQL *mysql,enum enum_server_command command, const char *arg, + size_t length, + my_bool skipp_check __attribute__((unused)), + void *opt_arg __attribute__((unused))) +{ + REPL_DATA *data= (REPL_DATA *)mysql->extension->conn_hdlr->data; + + /* if we don't have slave or slave became unavailable root traffic to master */ + if (!data->pvio[MARIADB_SLAVE] || !data->read_only) + { + SET_MASTER(mysql, data); + return 0; + } + switch(command) { + case COM_QUERY: + case COM_STMT_PREPARE: + if (is_slave_command(arg, length)) + SET_SLAVE(mysql, data) + else + SET_MASTER(mysql,data) + break; + case COM_STMT_EXECUTE: + case COM_STMT_FETCH: + if (data->pvio[MARIADB_SLAVE]->mysql->stmts && is_slave_stmt(data->pvio[MARIADB_SLAVE]->mysql, arg)) + SET_SLAVE(mysql, data) + else + SET_MASTER(mysql,data) + break; + + default: + SET_MASTER(mysql,data) + break; + } + return 0; +} + +int repl_set_optionsv(MYSQL *mysql, unsigned int option, ...) +{ + REPL_DATA *data= (REPL_DATA *)mysql->extension->conn_hdlr->data; + va_list ap; + void *arg1; + int rc= 0; + + va_start(ap, option); + arg1= va_arg(ap, void *); + + switch(option) { + case MARIADB_OPT_CONNECTION_READ_ONLY: + data->read_only= *(my_bool *)arg1; + break; + default: + rc= -1; + break; + } + va_end(ap); + return(rc); +} diff --git a/vendor/MDBC/plugins/io/CMakeLists.txt b/vendor/MDBC/plugins/io/CMakeLists.txt new file mode 100644 index 00000000..8c304c99 --- /dev/null +++ b/vendor/MDBC/plugins/io/CMakeLists.txt @@ -0,0 +1,15 @@ +IF (WITH_CURL) + INCLUDE(FindCURL) + IF(CURL_FOUND) + + ADD_DEFINITIONS(-DHAVE_REMOTEIO=1) + #remote io plugin + REGISTER_PLUGIN(TARGET remote_io + TYPE MARIADB_CLIENT_PLUGIN_IO + CONFIGURATIONS DYNAMIC STATIC OFF + DEFAULT DYNAMIC + SOURCES ${CC_SOURCE_DIR}/plugins/io/remote_io.c + INCLUDES ${CURL_INCLUDE_DIR} + LIBRARIES ${CURL_LIBRARIES}) + ENDIF() +ENDIF() diff --git a/vendor/MDBC/plugins/io/remote_io.c b/vendor/MDBC/plugins/io/remote_io.c new file mode 100644 index 00000000..c06ecacd --- /dev/null +++ b/vendor/MDBC/plugins/io/remote_io.c @@ -0,0 +1,453 @@ +/************************************************************************************ + * Copyright (C) 2015 - 2018 MariaDB Corporation AB + * Copyright (c) 2003 Simtec Electronics + * + * Re-implemented by Vincent Sanders with extensive + * reference to original curl example code + * + * Rewritten for MariaDB Connector/C by Georg Richter + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *************************************************************************************/ + +/* + This is a plugin for remote file access via libcurl. + + The following URL types are supported: + + http:// + https:// + ftp:// + sftp:// + ldap:// + smb:// +*/ + +#include +#include +#include +#include +#include +#include + +#include +#include +#ifndef WIN32 +#include +#else +#pragma comment(lib, "Ws2_32.lib") +#endif +#include +#include +#include + +/* Internal file structure */ + +MA_FILE *ma_rio_open(const char *url,const char *operation); +int ma_rio_close(MA_FILE *file); +int ma_rio_feof(MA_FILE *file); +size_t ma_rio_read(void *ptr, size_t size, size_t nmemb, MA_FILE *file); +char * ma_rio_gets(char *ptr, size_t size, MA_FILE *file); + +int ma_rio_init(char *, size_t, int, va_list); +int ma_rio_deinit(void); + +struct st_rio_methods ma_rio_methods= { + ma_rio_open, + ma_rio_close, + ma_rio_feof, + ma_rio_read, + ma_rio_gets +}; + +typedef struct +{ + CURL *curl; + size_t length, + offset; + uchar *buffer; + int in_progress; +} MA_REMOTE_FILE; + +CURLM *multi_handle= NULL; + +#ifndef PLUGIN_DYNAMIC +MARIADB_REMOTEIO_PLUGIN remote_io_client_plugin= +#else +MARIADB_REMOTEIO_PLUGIN _mysql_client_plugin_declaration_ = +#endif +{ + MARIADB_CLIENT_REMOTEIO_PLUGIN, + MARIADB_CLIENT_REMOTEIO_PLUGIN_INTERFACE_VERSION, + "remote_io", + "Georg Richter", + "Remote IO plugin", + {0,1,0}, + "LGPL", + NULL, + ma_rio_init, + ma_rio_deinit, + NULL, + &ma_rio_methods +mysql_end_client_plugin; + +/* {{{ ma_rio_init - Plugin initialization */ +int ma_rio_init(char *unused1 __attribute__((unused)), + size_t unused2 __attribute__((unused)), + int unused3 __attribute__((unused)), + va_list unused4 __attribute__((unused))) +{ + curl_global_init(CURL_GLOBAL_ALL); + if (!multi_handle) + multi_handle = curl_multi_init(); + return 0; +} +/* }}} */ + +/* {{{ ma_rio_deinit - Plugin deinitialization */ +int ma_rio_deinit(void) +{ + if (multi_handle) + { + curl_multi_cleanup(multi_handle); + multi_handle= NULL; + } + curl_global_cleanup(); + return 0; +} +/* }}} */ + +/* {{{ curl_write_callback */ +static size_t rio_write_callback(char *buffer, + size_t size, + size_t nitems, + void *ptr) +{ + size_t free_bytes; + char *tmp; + + MA_FILE *file= (MA_FILE *)ptr; + MA_REMOTE_FILE *curl_file = (MA_REMOTE_FILE *)file->ptr; + size *= nitems; + + free_bytes= curl_file->length - curl_file->offset; + + /* check if we need to allocate more memory */ + if (size > free_bytes) { + tmp= (char *)realloc((gptr)curl_file->buffer, curl_file->length + (size - free_bytes)); + if (!tmp) + size= free_bytes; + else { + curl_file->length+= size - free_bytes; + curl_file->buffer= (unsigned char *)tmp; + } + } + + /* copy buffer into MA_FILE structure */ + memcpy((char *)curl_file->buffer + curl_file->offset, buffer, size); + curl_file->offset+= size; + + return size; +} +/* }}} */ + +/* use to attempt to fill the read buffer up to requested number of bytes */ +static int fill_buffer(MA_FILE *file, size_t want) +{ + fd_set fdread; + fd_set fdwrite; + fd_set fdexcep; + struct timeval timeout; + int rc; + CURLMcode mc; /* curl_multi_fdset() return code */ + MA_REMOTE_FILE *rf= (MA_REMOTE_FILE *)file->ptr; + + /* only attempt to fill buffer if transactions still running and buffer + doesn't exceed required size already */ + if (!rf->in_progress || (rf->offset > want)) + return 0; + + /* try to fill buffer */ + do { + int maxfd = -1; + long curl_timeo = -1; + + FD_ZERO(&fdread); + FD_ZERO(&fdwrite); + FD_ZERO(&fdexcep); + + /* set a suitable timeout to fail on */ + timeout.tv_sec = 20; /* 20 seconds */ + timeout.tv_usec = 0; + + curl_multi_timeout(multi_handle, &curl_timeo); + if(curl_timeo >= 0) { + timeout.tv_sec = curl_timeo / 1000; + if(timeout.tv_sec > 1) + timeout.tv_sec = 1; + else + timeout.tv_usec = (curl_timeo % 1000) * 1000; + } + + /* get file descriptors from the transfers */ + mc = curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd); + + if(mc != CURLM_OK) + { + /* todo: error handling */ + break; + } + + /* On success the value of maxfd is guaranteed to be >= -1. We call + select(maxfd + 1, ...); specially in case of (maxfd == -1) there are + no fds ready yet so we call select(0, ...) */ + + if(maxfd == -1) { + struct timeval wait = { 0, 100 * 1000 }; /* 100ms */ + rc = select(0, NULL, NULL, NULL, &wait); + } + else { + rc = select(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout); + } + + switch(rc) { + case -1: + /* select error */ + break; + + case 0: + default: + /* timeout or readable/writable sockets */ + curl_multi_perform(multi_handle, &rf->in_progress); + break; + } + } while(rf->in_progress && (rf->offset < want)); + return 1; +} + +/* use to remove want bytes from the front of a files buffer */ +static int use_buffer(MA_FILE *file,int want) +{ + MA_REMOTE_FILE *rf= (MA_REMOTE_FILE *)file->ptr; + /* sort out buffer */ + if((rf->offset - want) <=0) { + /* ditch buffer - write will recreate */ + if (rf->buffer) + free(rf->buffer); + + rf->buffer=NULL; + rf->offset=0; + rf->length=0; + } + else { + /* move rest down make it available for later */ + memmove(rf->buffer, + &rf->buffer[want], + (rf->offset - want)); + + rf->offset -= want; + } + return 0; +} + +MA_FILE *ma_rio_open(const char *url,const char *operation) +{ + /* this code could check for URLs or types in the 'url' and + basically use the real fopen() for standard files */ + + MA_FILE *file; + MA_REMOTE_FILE *rf; + (void)operation; + + if (!(file = (MA_FILE *)calloc(sizeof(MA_FILE), 1))) + return NULL; + + file->type= MA_FILE_REMOTE; + if (!(file->ptr= rf= (MA_REMOTE_FILE *)calloc(sizeof(MA_REMOTE_FILE), 1))) + { + free(file); + return NULL; + } + rf->curl = curl_easy_init(); + + if (curl_easy_setopt(rf->curl, CURLOPT_URL, url) || + curl_easy_setopt(rf->curl, CURLOPT_WRITEDATA, file) || + curl_easy_setopt(rf->curl, CURLOPT_VERBOSE, 0L) || + curl_easy_setopt(rf->curl, CURLOPT_WRITEFUNCTION, rio_write_callback)) + { + free(file); + free(rf); + return NULL; + } + + curl_multi_add_handle(multi_handle, rf->curl); + + /* lets start the fetch */ + curl_multi_perform(multi_handle, &rf->in_progress); + + if((rf->offset == 0) && (!rf->in_progress)) { + /* if in_progress is 0 now, we should return NULL */ + + /* make sure the easy handle is not in the multi handle anymore */ + curl_multi_remove_handle(multi_handle, rf->curl); + + /* cleanup */ + curl_easy_cleanup(rf->curl); + + free(file); + + file = NULL; + } + return file; +} + +int ma_rio_close(MA_FILE *file) +{ + int ret=0;/* default is good return */ + MA_REMOTE_FILE *rf= (MA_REMOTE_FILE *)file->ptr; + + switch(file->type) { + case MA_FILE_REMOTE: + curl_multi_remove_handle(multi_handle, rf->curl); + + /* cleanup */ + curl_easy_cleanup(rf->curl); + break; + + default: /* unknown or supported type - oh dear */ + ret=EOF; + errno=EBADF; + break; + } + + if(rf->buffer) + free(rf->buffer);/* free any allocated buffer space */ + + free(rf); + free(file); + + return ret; +} + +int ma_rio_feof(MA_FILE *file) +{ + int ret=0; + MA_REMOTE_FILE *rf= (MA_REMOTE_FILE *)file->ptr; + + switch(file->type) { + case MA_FILE_REMOTE: + if((rf->offset == 0) && (!rf->in_progress)) + ret = 1; + break; + + default: /* unknown or supported type - oh dear */ + ret=-1; + errno=EBADF; + break; + } + return ret; +} + +size_t ma_rio_read(void *ptr, size_t size, size_t nmemb, MA_FILE *file) +{ + size_t want; + MA_REMOTE_FILE *rf= (MA_REMOTE_FILE *)file->ptr; + + switch(file->type) { + case MA_FILE_REMOTE: + want = nmemb * size; + + fill_buffer(file,want); + + /* check if there's data in the buffer - if not fill_buffer() + * either errored or EOF */ + if(!rf->offset) + return 0; + + /* ensure only available data is considered */ + if(rf->offset < want) + want = rf->offset; + + /* xfer data to caller */ + memcpy(ptr, rf->buffer, want); + + use_buffer(file,want); + + want = want / size; /* number of items */ + break; + + default: /* unknown or supported type - oh dear */ + want=0; + errno=EBADF; + break; + + } + return want; +} + +char *ma_rio_gets(char *ptr, size_t size, MA_FILE *file) +{ + size_t want = size - 1;/* always need to leave room for zero termination */ + size_t loop; + + switch(file->type) { + case MA_FILE_REMOTE: + { + MA_REMOTE_FILE *rf= (MA_REMOTE_FILE *)file->ptr; + fill_buffer(file,want); + + /* check if there's data in the buffer - if not fill either errored or + * EOF */ + if(!rf->offset) + return NULL; + + /* ensure only available data is considered */ + if(rf->offset < want) + want = rf->offset; + + /*buffer contains data */ + /* look for newline or eof */ + for(loop=0;loop < want;loop++) { + if(rf->buffer[loop] == '\n') { + want=loop+1;/* include newline */ + break; + } + } + + /* xfer data to caller */ + memcpy(ptr, rf->buffer, want); + ptr[want]=0;/* always null terminate */ + + use_buffer(file,want); + + break; + } + + default: /* unknown or supported type - oh dear */ + ptr=NULL; + errno=EBADF; + break; + } + + return ptr;/*success */ +} diff --git a/vendor/MDBC/plugins/plugin.def b/vendor/MDBC/plugins/plugin.def new file mode 100644 index 00000000..70af9256 --- /dev/null +++ b/vendor/MDBC/plugins/plugin.def @@ -0,0 +1,2 @@ +EXPORTS + _mysql_client_plugin_declaration_ DATA diff --git a/vendor/MDBC/plugins/pvio/CMakeLists.txt b/vendor/MDBC/plugins/pvio/CMakeLists.txt new file mode 100644 index 00000000..76eb3ef0 --- /dev/null +++ b/vendor/MDBC/plugins/pvio/CMakeLists.txt @@ -0,0 +1,27 @@ +SET(PVIO_DIR ${CC_SOURCE_DIR}/plugins/pvio) + +INCLUDE_DIRECTORIES(${PVIO_DIR}) +INCLUDE_DIRECTORIES(${CC_SOURCE_DIR}/include) + +#native password +REGISTER_PLUGIN(TARGET pvio_socket + TYPE MARIADB_CLIENT_PLUGIN_PVIO + CONFIGURATIONS STATIC DYNAMIC DEFAULT + DEFAULT STATIC + SOURCES ${CC_SOURCE_DIR}/plugins/pvio/pvio_socket.c) + +IF(WIN32) + # named pipe + REGISTER_PLUGIN(TARGET pvio_npipe + TYPE MARIADB_CLIENT_PLUGIN_PVIO + CONFIGURATIONS STATIC DYNAMIC DEFAULT + DEFAULT DYNAMIC + SOURCES ${CC_SOURCE_DIR}/plugins/pvio/pvio_npipe.c) + + # shared memory + REGISTER_PLUGIN(TARGET pvio_shmem + TYPE MARIADB_CLIENT_PLUGIN_PVIO + CONFIGURATIONS STATIC DYNAMIC DEFAULT + DEFAULT DYNAMIC + SOURCES ${CC_SOURCE_DIR}/plugins/pvio/pvio_shmem.c) +ENDIF() diff --git a/vendor/MDBC/plugins/pvio/pvio_npipe.c b/vendor/MDBC/plugins/pvio/pvio_npipe.c new file mode 100644 index 00000000..17c59cef --- /dev/null +++ b/vendor/MDBC/plugins/pvio/pvio_npipe.c @@ -0,0 +1,359 @@ +/************************************************************************************ + Copyright (C) 2015 Georg Richter and MariaDB Corporation AB + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not see + or write to the Free Software Foundation, Inc., + 51 Franklin St., Fifth Floor, Boston, MA 02110, USA + +*************************************************************************************/ + +/* MariaDB virtual IO plugin for Windows named pipe communication */ + +#ifdef _WIN32 + +#include +#include +#include +#include +#include +#include +#include + +/* Function prototypes */ +my_bool pvio_npipe_set_timeout(MARIADB_PVIO *pvio, enum enum_pvio_timeout type, int timeout); +int pvio_npipe_get_timeout(MARIADB_PVIO *pvio, enum enum_pvio_timeout type); +ssize_t pvio_npipe_read(MARIADB_PVIO *pvio, uchar *buffer, size_t length); +ssize_t pvio_npipe_write(MARIADB_PVIO *pvio, const uchar *buffer, size_t length); + +my_bool pvio_npipe_connect(MARIADB_PVIO *pvio, MA_PVIO_CINFO *cinfo); +my_bool pvio_npipe_close(MARIADB_PVIO *pvio); +int pvio_npipe_fast_send(MARIADB_PVIO *pvio); +int pvio_npipe_keepalive(MARIADB_PVIO *pvio); +my_bool pvio_npipe_get_handle(MARIADB_PVIO *pvio, void *handle); +my_bool pvio_npipe_is_blocking(MARIADB_PVIO *pvio); +int pvio_npipe_shutdown(MARIADB_PVIO *pvio); +my_bool pvio_npipe_is_alive(MARIADB_PVIO *pvio); + +struct st_ma_pvio_methods pvio_npipe_methods= { + pvio_npipe_set_timeout, + pvio_npipe_get_timeout, + pvio_npipe_read, + NULL, + pvio_npipe_write, + NULL, + NULL, + NULL, + pvio_npipe_connect, + pvio_npipe_close, + pvio_npipe_fast_send, + pvio_npipe_keepalive, + pvio_npipe_get_handle, + pvio_npipe_is_blocking, + pvio_npipe_is_alive, + NULL, + pvio_npipe_shutdown +}; + +#ifndef PLUGIN_DYNAMIC +MARIADB_PVIO_PLUGIN pvio_npipe_client_plugin = +#else +MARIADB_PVIO_PLUGIN _mysql_client_plugin_declaration_ = +#endif +{ + MARIADB_CLIENT_PVIO_PLUGIN, + MARIADB_CLIENT_PVIO_PLUGIN_INTERFACE_VERSION, + "pvio_npipe", + "Georg Richter", + "MariaDB virtual IO plugin for named pipe connection", + {1, 0, 0}, + "LGPL", + NULL, + NULL, + NULL, + NULL, + &pvio_npipe_methods +}; + +struct st_pvio_npipe { + HANDLE pipe; + OVERLAPPED overlapped; + MYSQL *mysql; +}; + +my_bool pvio_npipe_set_timeout(MARIADB_PVIO *pvio, enum enum_pvio_timeout type, int timeout) +{ + int timeout_ms; + + if (!pvio) + return 1; + if (timeout > INT_MAX/1000) + timeout_ms= -1; + else if (timeout <=0) + timeout_ms= -1; + else + timeout_ms = timeout*1000; + + pvio->timeout[type]= timeout_ms; + return 0; +} + +int pvio_npipe_get_timeout(MARIADB_PVIO *pvio, enum enum_pvio_timeout type) +{ + if (!pvio) + return -1; + return pvio->timeout[type] / 1000; +} + +static BOOL complete_io(HANDLE file, OVERLAPPED *ov, BOOL ret, DWORD timeout, DWORD *size) +{ + if (ret) + timeout = 0; /* IO completed successfully, do not WaitForSingleObject */ + else + { + assert(timeout); + if (GetLastError() != ERROR_IO_PENDING) + return FALSE; + } + + if (timeout) + { + HANDLE wait_handle= ov->hEvent; + assert(wait_handle && (wait_handle != INVALID_HANDLE_VALUE)); + + DWORD wait_ret= WaitForSingleObject(wait_handle, timeout); + switch (wait_ret) + { + case WAIT_OBJECT_0: + break; + case WAIT_TIMEOUT: + CancelIoEx(file, ov); + SetLastError(ERROR_TIMEOUT); + return FALSE; + default: + /* WAIT_ABANDONED or WAIT_FAILED unexpected. */ + assert(0); + return FALSE; + } + } + + return GetOverlappedResult(file, ov, size, FALSE); +} + +ssize_t pvio_npipe_read(MARIADB_PVIO *pvio, uchar *buffer, size_t length) +{ + BOOL ret; + ssize_t r= -1; + struct st_pvio_npipe *cpipe= NULL; + DWORD size; + + if (!pvio || !pvio->data) + return -1; + + cpipe= (struct st_pvio_npipe *)pvio->data; + + ret= ReadFile(cpipe->pipe, buffer, (DWORD)length, NULL, &cpipe->overlapped); + ret= complete_io(cpipe->pipe, &cpipe->overlapped, ret, pvio->timeout[PVIO_READ_TIMEOUT], &size); + r= ret? (ssize_t) size:-1; + + return r; +} + +ssize_t pvio_npipe_write(MARIADB_PVIO *pvio, const uchar *buffer, size_t length) +{ + ssize_t r= -1; + struct st_pvio_npipe *cpipe= NULL; + BOOL ret; + DWORD size; + + if (!pvio || !pvio->data) + return -1; + + cpipe= (struct st_pvio_npipe *)pvio->data; + + ret= WriteFile(cpipe->pipe, buffer, (DWORD)length, NULL , &cpipe->overlapped); + ret= complete_io(cpipe->pipe, &cpipe->overlapped, ret, pvio->timeout[PVIO_WRITE_TIMEOUT], &size); + r= ret ? (ssize_t)size : -1; + return r; +} + + +int pvio_npipe_keepalive(MARIADB_PVIO *pvio) +{ + /* keep alive is used for TCP/IP connections only */ + return 0; +} + +int pvio_npipe_fast_send(MARIADB_PVIO *pvio) +{ + /* not supported */ + return 0; +} +my_bool pvio_npipe_connect(MARIADB_PVIO *pvio, MA_PVIO_CINFO *cinfo) +{ + struct st_pvio_npipe *cpipe= NULL; + + if (!pvio || !cinfo) + return 1; + + /* if connect timeout is set, we will overwrite read/write timeout */ + if (pvio->timeout[PVIO_CONNECT_TIMEOUT]) + { + pvio->timeout[PVIO_READ_TIMEOUT]= pvio->timeout[PVIO_WRITE_TIMEOUT]= pvio->timeout[PVIO_CONNECT_TIMEOUT]; + } + + if (!(cpipe= (struct st_pvio_npipe *)LocalAlloc(LMEM_ZEROINIT, sizeof(struct st_pvio_npipe)))) + { + PVIO_SET_ERROR(cinfo->mysql, CR_OUT_OF_MEMORY, "HY000", 0, ""); + return 1; + } + pvio->data= (void *)cpipe; + cpipe->pipe= INVALID_HANDLE_VALUE; + pvio->mysql= cinfo->mysql; + pvio->type= cinfo->type; + + if (cinfo->type == PVIO_TYPE_NAMEDPIPE) + { + char szPipeName[MAX_PATH]; + ULONGLONG deadline; + LONGLONG wait_ms; + DWORD backoff= 0; /* Avoid busy wait if ERROR_PIPE_BUSY.*/ + if ( ! cinfo->unix_socket || (cinfo->unix_socket)[0] == 0x00) + cinfo->unix_socket = MARIADB_NAMEDPIPE; + if (!cinfo->host || !strcmp(cinfo->host,LOCAL_HOST)) + cinfo->host=LOCAL_HOST_NAMEDPIPE; + + szPipeName[MAX_PATH - 1]= 0; + snprintf(szPipeName, MAX_PATH - 1, "\\\\%s\\pipe\\%s", cinfo->host, cinfo->unix_socket); + + if (pvio->timeout[PVIO_CONNECT_TIMEOUT] > 0) + deadline = GetTickCount64() + pvio->timeout[PVIO_CONNECT_TIMEOUT]; + else + deadline = INFINITE; + + while (1) + { + if ((cpipe->pipe = CreateFile(szPipeName, + GENERIC_READ | + GENERIC_WRITE, + 0, /* no sharing */ + NULL, /* default security attributes */ + OPEN_EXISTING, + FILE_FLAG_OVERLAPPED, + NULL)) != INVALID_HANDLE_VALUE) + break; + + if (GetLastError() != ERROR_PIPE_BUSY) + { + pvio->set_error(pvio->mysql, CR_NAMEDPIPEOPEN_ERROR, "HY000", 0, + cinfo->host, cinfo->unix_socket, GetLastError()); + goto end; + } + + Sleep(backoff); + if (!backoff) + backoff = 1; + + wait_ms = deadline - GetTickCount64(); + if (wait_ms > INFINITE) + wait_ms = INFINITE; + + if ((wait_ms <= 0) || !WaitNamedPipe(szPipeName, (DWORD)wait_ms)) + { + pvio->set_error(pvio->mysql, CR_NAMEDPIPEWAIT_ERROR, "HY000", 0, + cinfo->host, cinfo->unix_socket, ERROR_TIMEOUT); + goto end; + } + } + + + if (!(cpipe->overlapped.hEvent= CreateEvent(NULL, FALSE, FALSE, NULL))) + { + pvio->set_error(pvio->mysql, CR_EVENT_CREATE_FAILED, "HY000", 0, + GetLastError()); + goto end; + } + return 0; + } +end: + if (cpipe) + { + if (cpipe->pipe != INVALID_HANDLE_VALUE) + CloseHandle(cpipe->pipe); + LocalFree(cpipe); + pvio->data= NULL; + } + return 1; +} + +my_bool pvio_npipe_close(MARIADB_PVIO *pvio) +{ + struct st_pvio_npipe *cpipe= NULL; + int r= 0; + + if (!pvio) + return 1; + + if (pvio->data) + { + cpipe= (struct st_pvio_npipe *)pvio->data; + CloseHandle(cpipe->overlapped.hEvent); + if (cpipe->pipe != INVALID_HANDLE_VALUE) + { + CloseHandle(cpipe->pipe); + cpipe->pipe= INVALID_HANDLE_VALUE; + } + LocalFree(pvio->data); + pvio->data= NULL; + } + return r; +} + +my_bool pvio_npipe_get_handle(MARIADB_PVIO *pvio, void *handle) +{ + if (pvio && pvio->data) + { + *(HANDLE *)handle= ((struct st_pvio_npipe *)pvio->data)->pipe; + return 0; + } + return 1; +} + +my_bool pvio_npipe_is_blocking(MARIADB_PVIO *pvio) +{ + return 1; +} + +int pvio_npipe_shutdown(MARIADB_PVIO *pvio) +{ + HANDLE h; + if (pvio_npipe_get_handle(pvio, &h) == 0) + { + return(CancelIoEx(h, NULL) ? 0 : 1); + } + return 1; +} + +my_bool pvio_npipe_is_alive(MARIADB_PVIO *pvio) +{ + HANDLE handle; + if (!pvio || !pvio->data) + return FALSE; + + handle= ((struct st_pvio_npipe *)pvio->data)->pipe; + /* Copy data from named pipe without removing it */ + if (PeekNamedPipe(handle, NULL, 0, NULL, NULL, NULL)) + return TRUE; + return test(GetLastError() != ERROR_BROKEN_PIPE); +} +#endif diff --git a/vendor/MDBC/plugins/pvio/pvio_plugin.def b/vendor/MDBC/plugins/pvio/pvio_plugin.def new file mode 100644 index 00000000..70af9256 --- /dev/null +++ b/vendor/MDBC/plugins/pvio/pvio_plugin.def @@ -0,0 +1,2 @@ +EXPORTS + _mysql_client_plugin_declaration_ DATA diff --git a/vendor/MDBC/plugins/pvio/pvio_shmem.c b/vendor/MDBC/plugins/pvio/pvio_shmem.c new file mode 100644 index 00000000..f412393b --- /dev/null +++ b/vendor/MDBC/plugins/pvio/pvio_shmem.c @@ -0,0 +1,469 @@ +/************************************************************************************ + Copyright (C) 2015 Georg Richter and MariaDB Corporation AB + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not see + or write to the Free Software Foundation, Inc., + 51 Franklin St., Fifth Floor, Boston, MA 02110, USA + +*************************************************************************************/ +/* MariaDB virtual IO plugin for Windows shared memory communication */ + +#ifdef _WIN32 + +#include +#include +#include +#include +#include +#include +#include + +#define PVIO_SHM_BUFFER_SIZE (16000 + 4) + +my_bool pvio_shm_set_timeout(MARIADB_PVIO *pvio, enum enum_pvio_timeout type, int timeout); +int pvio_shm_get_timeout(MARIADB_PVIO *pvio, enum enum_pvio_timeout type); +ssize_t pvio_shm_read(MARIADB_PVIO *pvio, uchar *buffer, size_t length); +ssize_t pvio_shm_write(MARIADB_PVIO *pvio, const uchar *buffer, size_t length); +int pvio_shm_wait_io_or_timeout(MARIADB_PVIO *pvio, my_bool is_read, int timeout); +int pvio_shm_blocking(MARIADB_PVIO *pvio, my_bool value, my_bool *old_value); +my_bool pvio_shm_connect(MARIADB_PVIO *pvio, MA_PVIO_CINFO *cinfo); +my_bool pvio_shm_close(MARIADB_PVIO *pvio); +int pvio_shm_shutdown(MARIADB_PVIO *pvio); +my_bool pvio_shm_is_alive(MARIADB_PVIO *pvio); +my_bool pvio_shm_get_handle(MARIADB_PVIO *pvio, void *handle); + +struct st_ma_pvio_methods pvio_shm_methods= { + pvio_shm_set_timeout, + pvio_shm_get_timeout, + pvio_shm_read, + NULL, + pvio_shm_write, + NULL, + pvio_shm_wait_io_or_timeout, + pvio_shm_blocking, + pvio_shm_connect, + pvio_shm_close, + NULL, + NULL, + pvio_shm_get_handle, + NULL, + pvio_shm_is_alive, + NULL, + pvio_shm_shutdown +}; + +#ifndef PLUGIN_DYNAMIC +MARIADB_PVIO_PLUGIN pvio_shmem_client_plugin= +#else +MARIADB_PVIO_PLUGIN _mysql_client_plugin_declaration_= +#endif +{ + MARIADB_CLIENT_PVIO_PLUGIN, + MARIADB_CLIENT_PVIO_PLUGIN_INTERFACE_VERSION, + "pvio_shmem", + "Georg Richter", + "MariaDB virtual IO plugin for Windows shared memory communication", + {1, 0, 0}, + "LGPPL", + NULL, + NULL, + NULL, + NULL, + &pvio_shm_methods, + +}; + +enum enum_shm_events +{ + PVIO_SHM_SERVER_WROTE= 0, + PVIO_SHM_SERVER_READ, + PVIO_SHM_CLIENT_WROTE, + PVIO_SHM_CLIENT_READ, + PVIO_SHM_CONNECTION_CLOSED +}; + +typedef struct { + HANDLE event[5]; + HANDLE file_map; + LPVOID *map; + char *read_pos; + size_t buffer_size; +} PVIO_SHM; + +const char *StrEvent[]= {"SERVER_WROTE", "SERVER_READ", "CLIENT_WROTE", "CLIENT_READ", "CONNECTION_CLOSED"}; + +struct st_pvio_shm { + char *shm_name; +}; + +my_bool pvio_shm_set_timeout(MARIADB_PVIO *pvio, enum enum_pvio_timeout type, int timeout) +{ + if (!pvio) + return 1; + pvio->timeout[type]= (timeout > 0) ? timeout * 1000 : INFINITE; + return 0; +} + +int pvio_shm_get_timeout(MARIADB_PVIO *pvio, enum enum_pvio_timeout type) +{ + if (!pvio) + return -1; + return pvio->timeout[type] / 1000; +} + +ssize_t pvio_shm_read(MARIADB_PVIO *pvio, uchar *buffer, size_t length) +{ + PVIO_SHM *pvio_shm= (PVIO_SHM *)pvio->data; + size_t copy_size= length; + HANDLE events[2]; + + if (!pvio_shm) + return -1; + + /* we need to wait for write and close events */ + if (!pvio_shm->buffer_size) + { + events[0]= pvio_shm->event[PVIO_SHM_CONNECTION_CLOSED]; + events[1]= pvio_shm->event[PVIO_SHM_SERVER_WROTE]; + + switch(WaitForMultipleObjects(2, events, 0, pvio->timeout[PVIO_READ_TIMEOUT])) + { + case WAIT_OBJECT_0: /* server closed connection */ + SetLastError(ERROR_GRACEFUL_DISCONNECT); + return -1; + case WAIT_OBJECT_0 +1: /* server_wrote event */ + break; + case WAIT_TIMEOUT: + SetLastError(ETIMEDOUT); + default: + return -1; + } + /* server sent data */ + pvio_shm->read_pos= (char *)pvio_shm->map; + pvio_shm->buffer_size= uint4korr(pvio_shm->read_pos); + pvio_shm->read_pos+= 4; + } + + if (pvio_shm->buffer_size < copy_size) + copy_size= pvio_shm->buffer_size; + + if (copy_size) + { + memcpy(buffer, (uchar *)pvio_shm->read_pos, pvio_shm->buffer_size); + pvio_shm->read_pos+= copy_size; + pvio_shm->buffer_size-= copy_size; + } + + /* we need to read again */ + if (!pvio_shm->buffer_size) + if (!SetEvent(pvio_shm->event[PVIO_SHM_CLIENT_READ])) + return -1; + + return (ssize_t)copy_size; +} + +ssize_t pvio_shm_write(MARIADB_PVIO *pvio, const uchar *buffer, size_t length) +{ + HANDLE events[2]; + PVIO_SHM *pvio_shm= (PVIO_SHM *)pvio->data; + size_t bytes_to_write= length; + uchar *buffer_pos= (uchar *)buffer; + + if (!pvio_shm) + return -1; + + events[0]= pvio_shm->event[PVIO_SHM_CONNECTION_CLOSED]; + events[1]= pvio_shm->event[PVIO_SHM_SERVER_READ]; + + while (bytes_to_write) + { + size_t pkt_length; + switch (WaitForMultipleObjects(2, events, 0, pvio->timeout[PVIO_WRITE_TIMEOUT])) { + case WAIT_OBJECT_0: /* connection closed */ + SetLastError(ERROR_GRACEFUL_DISCONNECT); + return -1; + case WAIT_OBJECT_0 + 1: /* server_read */ + break; + case WAIT_TIMEOUT: + SetLastError(ETIMEDOUT); + default: + return -1; + } + pkt_length= MIN(PVIO_SHM_BUFFER_SIZE, length); + int4store(pvio_shm->map, pkt_length); + memcpy((uchar *)pvio_shm->map + 4, buffer_pos, length); + buffer_pos+= length; + bytes_to_write-= length; + + if (!SetEvent(pvio_shm->event[PVIO_SHM_CLIENT_WROTE])) + return -1; + } + return (ssize_t)length; +} + + +int pvio_shm_wait_io_or_timeout(MARIADB_PVIO *pvio, my_bool is_read, int timeout) +{ + return 0; +} + +int pvio_shm_blocking(MARIADB_PVIO *pvio, my_bool block, my_bool *previous_mode) +{ + /* not supported */ + return 0; +} + +int pvio_shm_keepalive(MARIADB_PVIO *pvio) +{ + /* not supported */ + return 0; +} + +int pvio_shm_fast_send(MARIADB_PVIO *pvio) +{ + /* not supported */ + return 0; +} + +my_bool pvio_shm_connect(MARIADB_PVIO *pvio, MA_PVIO_CINFO *cinfo) +{ + const char *base_memory_name; + char *prefixes[]= {"", "Global\\", NULL}; + char *shm_name, *shm_suffix, *shm_prefix; + uchar i= 0; + int len; + int cid; + DWORD dwDesiredAccess= EVENT_MODIFY_STATE | SYNCHRONIZE; + HANDLE hdlConnectRequest= NULL, + hdlConnectRequestAnswer= NULL, + file_map= NULL; + LPVOID map= NULL; + PVIO_SHM *pvio_shm= (PVIO_SHM*)LocalAlloc(LMEM_ZEROINIT, sizeof(PVIO_SHM)); + + if (!pvio_shm) + { + PVIO_SET_ERROR(cinfo->mysql, CR_OUT_OF_MEMORY, "HY000", 0, ""); + return 0; + } + + /* MariaDB server constructs the event name as follows: + "Global\\base_memory_name" or + "\\base_memory_name" + */ + + + base_memory_name= (cinfo->host) ? cinfo->host : SHM_DEFAULT_NAME; + + if (!(shm_name= (char *)LocalAlloc(LMEM_ZEROINIT, strlen(base_memory_name) + 40))) + { + PVIO_SET_ERROR(cinfo->mysql, CR_OUT_OF_MEMORY, "HY000", 0, ""); + goto error; + } + + /* iterate through prefixes */ + while (prefixes[i]) + { + len= sprintf(shm_name, "%s%s_", prefixes[i], base_memory_name); + shm_suffix= shm_name + len; + strcpy(shm_suffix, "CONNECT_REQUEST"); + if ((hdlConnectRequest= OpenEvent(dwDesiredAccess, 0, shm_name))) + { + /* save prefix to prevent further loop */ + shm_prefix= prefixes[i]; + break; + } + i++; + } + if (!hdlConnectRequest) + { + PVIO_SET_ERROR(cinfo->mysql, CR_SHARED_MEMORY_CONNECT_ERROR, "HY000", 0, "Opening CONNECT_REQUEST event failed", GetLastError()); + goto error; + } + + strcpy(shm_suffix, "CONNECT_ANSWER"); + if (!(hdlConnectRequestAnswer= OpenEvent(dwDesiredAccess, 0, shm_name))) + { + PVIO_SET_ERROR(cinfo->mysql, CR_SHARED_MEMORY_CONNECT_ERROR, "HY000", 0, "Opening CONNECT_ANSWER event failed", GetLastError()); + goto error; + } + + /* get connection id, so we can build the filename used for connection */ + strcpy(shm_suffix, "CONNECT_DATA"); + if (!(file_map= OpenFileMapping(FILE_MAP_WRITE, 0, shm_name))) + { + PVIO_SET_ERROR(cinfo->mysql, CR_SHARED_MEMORY_CONNECT_ERROR, "HY000", 0, "OpenFileMapping failed", GetLastError()); + goto error; + } + + /* try to get first 4 bytes, which represents connection_id */ + if (!(map= MapViewOfFile(file_map, FILE_MAP_WRITE, 0, 0, sizeof(cid)))) + { + PVIO_SET_ERROR(cinfo->mysql, CR_SHARED_MEMORY_CONNECT_ERROR, "HY000", 0, "Reading connection_id failed", GetLastError()); + goto error; + } + + /* notify server */ + if (!SetEvent(hdlConnectRequest)) + { + PVIO_SET_ERROR(cinfo->mysql, CR_SHARED_MEMORY_CONNECT_ERROR, "HY000", 0, "Failed sending connection request", GetLastError()); + goto error; + } + + /* Wait for server answer */ + switch(WaitForSingleObject(hdlConnectRequestAnswer, pvio->timeout[PVIO_CONNECT_TIMEOUT])) { + case WAIT_ABANDONED: + PVIO_SET_ERROR(cinfo->mysql, CR_SHARED_MEMORY_CONNECT_ERROR, "HY000", 0, "Mutex was not released in time", GetLastError()); + goto error; + break; + case WAIT_FAILED: + PVIO_SET_ERROR(cinfo->mysql, CR_SHARED_MEMORY_CONNECT_ERROR, "HY000", 0, "Operation wait failed", GetLastError()); + goto error; + break; + case WAIT_TIMEOUT: + PVIO_SET_ERROR(cinfo->mysql, CR_SHARED_MEMORY_CONNECT_ERROR, "HY000", 0, "Operation timed out", GetLastError()); + goto error; + break; + case WAIT_OBJECT_0: + break; + default: + PVIO_SET_ERROR(cinfo->mysql, CR_SHARED_MEMORY_CONNECT_ERROR, "HY000", 0, "Wait for server failed", GetLastError()); + break; + } + + cid= uint4korr(map); + + len= sprintf(shm_name, "%s%s_%d_", shm_prefix, base_memory_name, cid); + shm_suffix= shm_name + len; + + strcpy(shm_suffix, "DATA"); + pvio_shm->file_map= OpenFileMapping(FILE_MAP_WRITE, 0, shm_name); + if (pvio_shm->file_map == NULL) + { + PVIO_SET_ERROR(cinfo->mysql, CR_SHARED_MEMORY_CONNECT_ERROR, "HY000", 0, "OpenFileMapping failed", GetLastError()); + goto error; + } + if (!(pvio_shm->map= MapViewOfFile(pvio_shm->file_map, FILE_MAP_WRITE, 0, 0, PVIO_SHM_BUFFER_SIZE))) + { + PVIO_SET_ERROR(cinfo->mysql, CR_SHARED_MEMORY_CONNECT_ERROR, "HY000", 0, "MapViewOfFile failed", GetLastError()); + goto error; + } + + for (i=0; i < 5; i++) + { + strcpy(shm_suffix, StrEvent[i]); + if (!(pvio_shm->event[i]= OpenEvent(dwDesiredAccess, 0, shm_name))) + { + PVIO_SET_ERROR(cinfo->mysql, CR_SHARED_MEMORY_CONNECT_ERROR, "HY000", 0, "Couldn't create event", GetLastError()); + goto error; + } + } + /* we will first read from server */ + SetEvent(pvio_shm->event[PVIO_SHM_SERVER_READ]); + +error: + if (hdlConnectRequest) + CloseHandle(hdlConnectRequest); + if (hdlConnectRequestAnswer) + CloseHandle(hdlConnectRequestAnswer); + if (shm_name) + LocalFree(shm_name); + if (map) + UnmapViewOfFile(map); + if (file_map) + CloseHandle(file_map); + if (pvio_shm) + { + /* check if all events are set */ + if (pvio_shm->event[4]) + { + pvio->data= (void *)pvio_shm; + pvio->mysql= cinfo->mysql; + pvio->type= cinfo->type; + pvio_shm->read_pos= (char *)pvio_shm->map; + pvio->mysql->net.pvio= pvio; + return 0; + } + for (i=0;i < 5; i++) + if (pvio_shm->event[i]) + CloseHandle(pvio_shm->event[i]); + if (pvio_shm->map) + UnmapViewOfFile(pvio_shm->map); + if (pvio_shm->file_map) + CloseHandle(pvio_shm->file_map); + LocalFree(pvio_shm); + } + return 1; + +} + +my_bool pvio_shm_close(MARIADB_PVIO *pvio) +{ + PVIO_SHM *pvio_shm= (PVIO_SHM *)pvio->data; + int i; + + if (!pvio_shm) + return 1; + + /* notify server */ + SetEvent(pvio_shm->event[PVIO_SHM_CONNECTION_CLOSED]); + + UnmapViewOfFile(pvio_shm->map); + CloseHandle(pvio_shm->file_map); + + for (i=0; i < 5; i++) + CloseHandle(pvio_shm->event[i]); + + LocalFree(pvio_shm); + pvio->data= NULL; + return 0; +} + +my_bool pvio_shm_get_socket(MARIADB_PVIO *pvio, void *handle) +{ + return 1; +} + +my_bool pvio_shm_is_blocking(MARIADB_PVIO *pvio) +{ + return 1; +} + +int pvio_shm_shutdown(MARIADB_PVIO *pvio) +{ + PVIO_SHM *pvio_shm= (PVIO_SHM *)pvio->data; + if (pvio_shm) + return (SetEvent(pvio_shm->event[PVIO_SHM_CONNECTION_CLOSED]) ? 0 : 1); + return 1; +} + +my_bool pvio_shm_is_alive(MARIADB_PVIO *pvio) +{ + PVIO_SHM *pvio_shm; + if (!pvio || !pvio->data) + return FALSE; + pvio_shm= (PVIO_SHM *)pvio->data; + return WaitForSingleObject(pvio_shm->event[PVIO_SHM_CONNECTION_CLOSED], 0)!=WAIT_OBJECT_0; +} + +my_bool pvio_shm_get_handle(MARIADB_PVIO *pvio, void *handle) +{ + + *(HANDLE **)handle= 0; + if (!pvio || !pvio->data) + return FALSE; + *(HANDLE **)handle= ((PVIO_SHM*)pvio->data)->event; + return TRUE; +} +#endif + diff --git a/vendor/MDBC/plugins/pvio/pvio_socket.c b/vendor/MDBC/plugins/pvio/pvio_socket.c new file mode 100644 index 00000000..225f3bea --- /dev/null +++ b/vendor/MDBC/plugins/pvio/pvio_socket.c @@ -0,0 +1,1128 @@ +/************************************************************************************ + Copyright (C) 2015,2016 MariaDB Corporation AB, + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not see + or write to the Free Software Foundation, Inc., + 51 Franklin St., Fifth Floor, Boston, MA 02110, USA +*************************************************************************************/ + +/* + MariaDB virtual IO plugin for socket communication: + + The plugin handles connections via unix and network sockets. it is enabled by + default and compiled into Connector/C. +*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#ifndef _WIN32 +#ifdef HAVE_SYS_UN_H +#include +#endif +#ifdef HAVE_POLL +#include +#endif +#ifdef HAVE_SYS_IOCTL_H +#include +#endif +#ifdef HAVE_FCNTL_H +#include +#endif +#include +#include +#include +#include +#include +#define IS_SOCKET_EINTR(err) ((err) == SOCKET_EINTR) +#else +#include +#define O_NONBLOCK 1 +#define MSG_DONTWAIT 0 +#define IS_SOCKET_EINTR(err) 0 +#endif + +#ifndef SOCKET_ERROR +#define SOCKET_ERROR -1 +#endif + +#ifndef INVALID_SOCKET +#define INVALID_SOCKET -1 +#endif + +#define DNS_TIMEOUT 30 + +#ifndef O_NONBLOCK +#if defined(O_NDELAY) +#define O_NONBLOCK O_NODELAY +#elif defined (O_FNDELAY) +#define O_NONBLOCK O_FNDELAY +#else +#error socket blocking is not supported on this platform +#endif +#endif + +#if SOCKET_EAGAIN != SOCKET_EWOULDBLOCK +#define HAVE_SOCKET_EWOULDBLOCK 1 +#endif + +#ifdef _AIX +#ifndef MSG_DONTWAIT +#define MSG_DONTWAIT 0 +#endif +#endif + +/* Function prototypes */ +my_bool pvio_socket_set_timeout(MARIADB_PVIO *pvio, enum enum_pvio_timeout type, int timeout); +int pvio_socket_get_timeout(MARIADB_PVIO *pvio, enum enum_pvio_timeout type); +ssize_t pvio_socket_read(MARIADB_PVIO *pvio, uchar *buffer, size_t length); +ssize_t pvio_socket_async_read(MARIADB_PVIO *pvio, uchar *buffer, size_t length); +ssize_t pvio_socket_async_write(MARIADB_PVIO *pvio, const uchar *buffer, size_t length); +ssize_t pvio_socket_write(MARIADB_PVIO *pvio, const uchar *buffer, size_t length); +int pvio_socket_wait_io_or_timeout(MARIADB_PVIO *pvio, my_bool is_read, int timeout); +int pvio_socket_blocking(MARIADB_PVIO *pvio, my_bool value, my_bool *old_value); +my_bool pvio_socket_connect(MARIADB_PVIO *pvio, MA_PVIO_CINFO *cinfo); +my_bool pvio_socket_close(MARIADB_PVIO *pvio); +int pvio_socket_fast_send(MARIADB_PVIO *pvio); +int pvio_socket_keepalive(MARIADB_PVIO *pvio); +my_bool pvio_socket_get_handle(MARIADB_PVIO *pvio, void *handle); +my_bool pvio_socket_is_blocking(MARIADB_PVIO *pvio); +my_bool pvio_socket_is_alive(MARIADB_PVIO *pvio); +my_bool pvio_socket_has_data(MARIADB_PVIO *pvio, ssize_t *data_len); +int pvio_socket_shutdown(MARIADB_PVIO *pvio); + +static int pvio_socket_init(char *unused1, + size_t unused2, + int unused3, + va_list); +static int pvio_socket_end(void); +static ssize_t ma_send(my_socket socket, const uchar *buffer, size_t length, int flags); +static ssize_t ma_recv(my_socket socket, uchar *buffer, size_t length, int flags); + +struct st_ma_pvio_methods pvio_socket_methods= { + pvio_socket_set_timeout, + pvio_socket_get_timeout, + pvio_socket_read, + pvio_socket_async_read, + pvio_socket_write, + pvio_socket_async_write, + pvio_socket_wait_io_or_timeout, + pvio_socket_blocking, + pvio_socket_connect, + pvio_socket_close, + pvio_socket_fast_send, + pvio_socket_keepalive, + pvio_socket_get_handle, + pvio_socket_is_blocking, + pvio_socket_is_alive, + pvio_socket_has_data, + pvio_socket_shutdown +}; + +#ifndef PLUGIN_DYNAMIC +MARIADB_PVIO_PLUGIN pvio_socket_client_plugin= +#else +MARIADB_PVIO_PLUGIN _mysql_client_plugin_declaration_ +#endif +{ + MARIADB_CLIENT_PVIO_PLUGIN, + MARIADB_CLIENT_PVIO_PLUGIN_INTERFACE_VERSION, + "pvio_socket", + "Georg Richter", + "MariaDB virtual IO plugin for socket communication", + {1, 0, 0}, + "LGPL", + NULL, + &pvio_socket_init, + &pvio_socket_end, + NULL, + &pvio_socket_methods +}; + +struct st_pvio_socket { + my_socket socket; + int fcntl_mode; + MYSQL *mysql; +}; + +static my_bool pvio_socket_initialized= FALSE; + +static int pvio_socket_init(char *errmsg __attribute__((unused)), + size_t errmsg_length __attribute__((unused)), + int unused __attribute__((unused)), + va_list va __attribute__((unused))) +{ + pvio_socket_initialized= TRUE; + return 0; +} + +static int pvio_socket_end(void) +{ + if (!pvio_socket_initialized) + return 1; + return 0; +} + +my_bool pvio_socket_change_timeout(MARIADB_PVIO *pvio, enum enum_pvio_timeout type, int timeout) +{ + struct timeval tm; + int rc= 0; + struct st_pvio_socket *csock= NULL; + if (!pvio) + return 1; + if (!(csock= (struct st_pvio_socket *)pvio->data)) + return 1; + tm.tv_sec= timeout / 1000; + tm.tv_usec= (timeout % 1000) * 1000; + switch(type) + { + case PVIO_WRITE_TIMEOUT: +#ifndef _WIN32 + rc= setsockopt(csock->socket, SOL_SOCKET, SO_SNDTIMEO, (const char *)&tm, sizeof(tm)); +#else + rc= setsockopt(csock->socket, SOL_SOCKET, SO_SNDTIMEO, (const char *)&timeout, sizeof(int)); +#endif + break; + case PVIO_READ_TIMEOUT: +#ifndef _WIN32 + rc= setsockopt(csock->socket, SOL_SOCKET, SO_RCVTIMEO, (const char *)&tm, sizeof(tm)); +#else + rc= setsockopt(csock->socket, SOL_SOCKET, SO_RCVTIMEO, (const char *)&timeout, sizeof(int)); +#endif + break; + default: + break; + } + return rc; +} + +/* {{{ pvio_socket_set_timeout */ +/* + set timeout value + + SYNOPSIS + pvio_socket_set_timeout + pvio PVIO + type timeout type (connect, read, write) + timeout timeout in seconds + + DESCRIPTION + Sets timeout values for connection-, read or write time out. + PVIO internally stores all timeout values in milliseconds, but + accepts and returns all time values in seconds (like api does). + + RETURNS + 0 Success + 1 Error +*/ +my_bool pvio_socket_set_timeout(MARIADB_PVIO *pvio, enum enum_pvio_timeout type, int timeout) +{ + struct st_pvio_socket *csock= NULL; + if (!pvio) + return 1; + csock= (struct st_pvio_socket *)pvio->data; + pvio->timeout[type]= (timeout > 0) ? timeout * 1000 : -1; + if (csock) + return pvio_socket_change_timeout(pvio, type, timeout * 1000); + return 0; +} +/* }}} */ + +/* {{{ pvio_socket_get_timeout */ +/* + get timeout value + + SYNOPSIS + pvio_socket_get_timeout + pvio PVIO + type timeout type (connect, read, write) + + DESCRIPTION + Returns timeout values for connection-, read or write time out. + PVIO internally stores all timeout values in milliseconds, but + accepts and returns all time values in seconds (like api does). + + RETURNS + 0...n time out value + -1 error +*/ +int pvio_socket_get_timeout(MARIADB_PVIO *pvio, enum enum_pvio_timeout type) +{ + if (!pvio) + return -1; + return pvio->timeout[type] / 1000; +} +/* }}} */ + +/* {{{ pvio_socket_read */ +/* + read from socket + + SYNOPSIS + pvio_socket_read() + pvio PVIO + buffer read buffer + length buffer length + + DESCRIPTION + reads up to length bytes into specified buffer. In the event of an + error erno is set to indicate it. + + RETURNS + 1..n number of bytes read + 0 peer has performed shutdown + -1 on error + +*/ +ssize_t pvio_socket_read(MARIADB_PVIO *pvio, uchar *buffer, size_t length) +{ + ssize_t r; + int read_flags= MSG_DONTWAIT; + struct st_pvio_socket *csock; + int timeout; + + if (!pvio || !pvio->data) + return -1; + + csock= (struct st_pvio_socket *)pvio->data; + timeout = pvio->timeout[PVIO_READ_TIMEOUT]; + + while ((r = ma_recv(csock->socket, (void *)buffer, length, read_flags)) == -1) + { + int err = socket_errno; + if ((err != SOCKET_EAGAIN +#ifdef HAVE_SOCKET_EWOULDBLOCK + && err != SOCKET_EWOULDBLOCK +#endif + ) || timeout == 0) + return r; + + if (pvio_socket_wait_io_or_timeout(pvio, TRUE, timeout) < 1) + return -1; + } + return r; +} +/* }}} */ + +/* {{{ pvio_socket_async_read */ +/* + read from socket + + SYNOPSIS + pvio_socket_async_read() + pvio PVIO + buffer read buffer + length buffer length + + DESCRIPTION + reads up to length bytes into specified buffer. In the event of an + error erno is set to indicate it. + + RETURNS + 1..n number of bytes read + 0 peer has performed shutdown + -1 on error + +*/ +ssize_t pvio_socket_async_read(MARIADB_PVIO *pvio, uchar *buffer, size_t length) +{ + ssize_t r= -1; +#ifndef _WIN32 + int read_flags= MSG_DONTWAIT; +#endif + struct st_pvio_socket *csock= NULL; + + if (!pvio || !pvio->data) + return -1; + + csock= (struct st_pvio_socket *)pvio->data; + +#ifndef _WIN32 + r= recv(csock->socket,(void *)buffer, length, read_flags); +#else + /* Windows doesn't support MSG_DONTWAIT, so we need to set + socket to non blocking */ + pvio_socket_blocking(pvio, 0, 0); + r= recv(csock->socket, (char *)buffer, (int)length, 0); +#endif + return r; +} +/* }}} */ + +static ssize_t ma_send(my_socket socket, const uchar *buffer, size_t length, int flags) +{ + ssize_t r; +#if !defined(MSG_NOSIGNAL) && !defined(SO_NOSIGPIPE) && !defined(_WIN32) + struct sigaction act, oldact; + act.sa_handler= SIG_IGN; + sigaction(SIGPIPE, &act, &oldact); +#endif + do { + r = send(socket, (const char *)buffer, IF_WIN((int)length,length), flags); + } + while (r == -1 && IS_SOCKET_EINTR(socket_errno)); +#if !defined(MSG_NOSIGNAL) && !defined(SO_NOSIGPIPE) && !defined(_WIN32) + sigaction(SIGPIPE, &oldact, NULL); +#endif + return r; +} + +static ssize_t ma_recv(my_socket socket, uchar *buffer, size_t length, int flags) +{ + ssize_t r; + do { + r = recv(socket, (char*) buffer, IF_WIN((int)length, length), flags); + } + while (r == -1 && IS_SOCKET_EINTR(socket_errno)); + return r; +} + +/* {{{ pvio_socket_async_write */ +/* + write to socket + + SYNOPSIS + pvio_socket_async_write() + pvio PVIO + buffer read buffer + length buffer length + + DESCRIPTION + writes up to length bytes to socket. In the event of an + error erno is set to indicate it. + + RETURNS + 1..n number of bytes read + 0 peer has performed shutdown + -1 on error + +*/ +ssize_t pvio_socket_async_write(MARIADB_PVIO *pvio, const uchar *buffer, size_t length) +{ + ssize_t r= -1; + struct st_pvio_socket *csock= NULL; +#ifndef _WIN32 + int write_flags= MSG_DONTWAIT; +#ifdef MSG_NOSIGNAL + write_flags|= MSG_NOSIGNAL; +#endif +#endif + + if (!pvio || !pvio->data) + return -1; + + csock= (struct st_pvio_socket *)pvio->data; + +#ifndef WIN32 + r= ma_send(csock->socket, buffer, length, write_flags); +#else + /* Windows doesn't support MSG_DONTWAIT, so we need to set + socket to non blocking */ + pvio_socket_blocking(pvio, 0, 0); + r= send(csock->socket, (const char *)buffer, (int)length, 0); +#endif + + return r; +} +/* }}} */ + +/* {{{ pvio_socket_write */ +/* + write to socket + + SYNOPSIS + pvio_socket_write() + pvio PVIO + buffer read buffer + length buffer length + + DESCRIPTION + writes up to length bytes to socket. In the event of an + error erno is set to indicate it. + + RETURNS + 1..n number of bytes read + 0 peer has performed shutdown + -1 on error + +*/ +ssize_t pvio_socket_write(MARIADB_PVIO *pvio, const uchar *buffer, size_t length) +{ + ssize_t r; + struct st_pvio_socket *csock; + int timeout; + int send_flags= MSG_DONTWAIT; +#ifdef MSG_NOSIGNAL + send_flags|= MSG_NOSIGNAL; +#endif + if (!pvio || !pvio->data) + return -1; + + csock= (struct st_pvio_socket *)pvio->data; + timeout = pvio->timeout[PVIO_WRITE_TIMEOUT]; + + while ((r = ma_send(csock->socket, (void *)buffer, length,send_flags)) == -1) + { + int err = socket_errno; + if ((err != SOCKET_EAGAIN +#ifdef HAVE_SOCKET_EWOULDBLOCK + && err != SOCKET_EWOULDBLOCK +#endif + )|| timeout == 0) + return r; + if (pvio_socket_wait_io_or_timeout(pvio, FALSE, timeout) < 1) + return -1; + } + return r; +} +/* }}} */ + +int pvio_socket_wait_io_or_timeout(MARIADB_PVIO *pvio, my_bool is_read, int timeout) +{ + int rc; + struct st_pvio_socket *csock= NULL; + +#ifndef _WIN32 + struct pollfd p_fd; +#else + struct timeval tv= {0,0}; + fd_set fds, exc_fds; +#endif + + if (!pvio || !pvio->data) + return 0; + + if (pvio->mysql->options.extension && + pvio->mysql->options.extension->io_wait != NULL) { + my_socket handle; + if (pvio_socket_get_handle(pvio, &handle)) + return 0; + return pvio->mysql->options.extension->io_wait(handle, is_read, timeout); + } + + csock= (struct st_pvio_socket *)pvio->data; + { +#ifndef _WIN32 + memset(&p_fd, 0, sizeof(p_fd)); + p_fd.fd= csock->socket; + p_fd.events= (is_read) ? POLLIN : POLLOUT; + + if (!timeout) + timeout= -1; + + do { + rc= poll(&p_fd, 1, timeout); + } while (rc == -1 && errno == EINTR); + + if (rc == 0) + errno= ETIMEDOUT; +#else + FD_ZERO(&fds); + FD_ZERO(&exc_fds); + + FD_SET(csock->socket, &fds); + FD_SET(csock->socket, &exc_fds); + + if (timeout >= 0) + { + tv.tv_sec= timeout / 1000; + tv.tv_usec= (timeout % 1000) * 1000; + } + + rc= select(0, (is_read) ? &fds : NULL, + (is_read) ? NULL : &fds, + &exc_fds, + (timeout >= 0) ? &tv : NULL); + + if (rc == SOCKET_ERROR) + { + errno= WSAGetLastError(); + } + else if (rc == 0) + { + rc= SOCKET_ERROR; + WSASetLastError(WSAETIMEDOUT); + errno= ETIMEDOUT; + } + else if (FD_ISSET(csock->socket, &exc_fds)) + { + int err; + int len = sizeof(int); + if (getsockopt(csock->socket, SOL_SOCKET, SO_ERROR, (char *)&err, &len) != SOCKET_ERROR) + { + WSASetLastError(err); + errno= err; + } + rc= SOCKET_ERROR; + } + +#endif + } + return rc; +} + +int pvio_socket_blocking(MARIADB_PVIO *pvio, my_bool block, my_bool *previous_mode) +{ + my_bool is_blocking; + struct st_pvio_socket *csock; + int new_fcntl_mode; + + if (!pvio || !pvio->data) + return 1; + + csock = (struct st_pvio_socket *)pvio->data; + + is_blocking = !(csock->fcntl_mode & O_NONBLOCK); + if (previous_mode) + *previous_mode = is_blocking; + + if (is_blocking == block) + return 0; + + if (block) + new_fcntl_mode = csock->fcntl_mode & ~O_NONBLOCK; + else + new_fcntl_mode = csock->fcntl_mode | O_NONBLOCK; + +#ifdef _WIN32 + { + ulong arg = block ? 0 : 1; + if (ioctlsocket(csock->socket, FIONBIO, (void *)&arg)) + { + return(WSAGetLastError()); + } + } +#else + if (fcntl(csock->socket, F_SETFL, new_fcntl_mode) == -1) + { + return errno; + } +#endif + csock->fcntl_mode = new_fcntl_mode; + return 0; +} + +static int pvio_socket_internal_connect(MARIADB_PVIO *pvio, + const struct sockaddr *name, + size_t namelen) +{ + int rc= 0; + struct st_pvio_socket *csock= NULL; + int timeout; + + if (!pvio || !pvio->data) + return 1; + + csock= (struct st_pvio_socket *)pvio->data; + timeout= pvio->timeout[PVIO_CONNECT_TIMEOUT]; + + /* set non blocking */ + pvio_socket_blocking(pvio, 0, 0); + +#ifndef _WIN32 + do { + rc= connect(csock->socket, (struct sockaddr*) name, (int)namelen); + } while (rc == -1 && (errno == EINTR || errno == EAGAIN)); + /* in case a timeout values was set we need to check error values + EINPROGRESS */ + if (timeout != 0 && rc == -1 && errno == EINPROGRESS) + { + rc= pvio_socket_wait_io_or_timeout(pvio, FALSE, timeout); + if (rc < 1) + return -1; + { + int error; + socklen_t error_len= sizeof(error); + if ((rc = getsockopt(csock->socket, SOL_SOCKET, SO_ERROR, + (char *)&error, &error_len)) < 0) + return errno; + else if (error) + return error; + } + } +#ifdef __APPLE__ + if (csock->socket) + { + int val= 1; + setsockopt(csock->socket, SOL_SOCKET, SO_NOSIGPIPE, (void *)&val, sizeof(int)); + } +#endif +#else + rc= connect(csock->socket, (struct sockaddr*) name, (int)namelen); + if (rc == SOCKET_ERROR) + { + if (WSAGetLastError() == WSAEWOULDBLOCK) + { + if (pvio_socket_wait_io_or_timeout(pvio, FALSE, timeout) < 0) + return -1; + rc= 0; + } + } +#endif + return rc; +} + +int pvio_socket_keepalive(MARIADB_PVIO *pvio) +{ + int opt= 1; + struct st_pvio_socket *csock= NULL; + + if (!pvio || !pvio->data) + return 1; + + csock= (struct st_pvio_socket *)pvio->data; + + return setsockopt(csock->socket, SOL_SOCKET, SO_KEEPALIVE, +#ifndef _WIN32 + (const void *)&opt, sizeof(opt)); +#else + (char *)&opt, (int)sizeof(opt)); +#endif +} + +int pvio_socket_fast_send(MARIADB_PVIO *pvio) +{ + int r= 0; + struct st_pvio_socket *csock= NULL; + + if (!pvio || !pvio->data) + return 1; + + csock= (struct st_pvio_socket *)pvio->data; + +/* Setting IP_TOS is not recommended on Windows. See + http://msdn.microsoft.com/en-us/library/windows/desktop/ms738586(v=vs.85).aspx +*/ +#if !defined(_WIN32) && defined(IPTOS_THROUGHPUT) + { + int tos = IPTOS_THROUGHPUT; + r= setsockopt(csock->socket, IPPROTO_IP, IP_TOS, + (const void *)&tos, sizeof(tos)); + } +#endif /* !_WIN32 && IPTOS_THROUGHPUT */ + if (!r) + { + int opt = 1; + /* turn off nagle algorithm */ + r= setsockopt(csock->socket, IPPROTO_TCP, TCP_NODELAY, +#ifdef _WIN32 + (const char *)&opt, (int)sizeof(opt)); +#else + (const void *)&opt, sizeof(opt)); +#endif + } + return r; +} + +static int +pvio_socket_connect_sync_or_async(MARIADB_PVIO *pvio, + const struct sockaddr *name, uint namelen) +{ + MYSQL *mysql= pvio->mysql; + if (mysql->options.extension && mysql->options.extension->async_context && + mysql->options.extension->async_context->active) + { + /* even if we are not connected yet, application needs to check socket + * via mysql_get_socket api call, so we need to assign pvio */ + mysql->options.extension->async_context->pvio= pvio; + pvio_socket_blocking(pvio, 0, 0); + return my_connect_async(pvio, name, namelen, pvio->timeout[PVIO_CONNECT_TIMEOUT]); + } + + return pvio_socket_internal_connect(pvio, name, namelen); +} + +my_bool pvio_socket_connect(MARIADB_PVIO *pvio, MA_PVIO_CINFO *cinfo) +{ + struct st_pvio_socket *csock= NULL; + MYSQL *mysql; + + if (!pvio || !cinfo) + return 1; + + if (!(csock= (struct st_pvio_socket *)calloc(1, sizeof(struct st_pvio_socket)))) + { + PVIO_SET_ERROR(cinfo->mysql, CR_OUT_OF_MEMORY, unknown_sqlstate, 0, ""); + return 1; + } + pvio->data= (void *)csock; + csock->socket= INVALID_SOCKET; + mysql= pvio->mysql= cinfo->mysql; + pvio->type= cinfo->type; + + if (cinfo->type == PVIO_TYPE_UNIXSOCKET) + { +#ifndef _WIN32 +#ifdef HAVE_SYS_UN_H + size_t port_length; + struct sockaddr_un UNIXaddr; + if ((csock->socket = socket(AF_UNIX,SOCK_STREAM,0)) == INVALID_SOCKET || + (port_length=strlen(cinfo->unix_socket)) >= (sizeof(UNIXaddr.sun_path))) + { + PVIO_SET_ERROR(cinfo->mysql, CR_SOCKET_CREATE_ERROR, unknown_sqlstate, 0, errno); + goto error; + } + memset((char*) &UNIXaddr, 0, sizeof(UNIXaddr)); + UNIXaddr.sun_family = AF_UNIX; +#if defined(__linux__) + /* Abstract socket */ + if (cinfo->unix_socket[0] == '@') + { + strncpy(UNIXaddr.sun_path + 1, cinfo->unix_socket + 1, 106); + port_length+= offsetof(struct sockaddr_un, sun_path); + } + else +#endif + { + size_t sun_path_size = sizeof(UNIXaddr.sun_path); + strncpy(UNIXaddr.sun_path, cinfo->unix_socket, sun_path_size - 1); + if (sun_path_size == strlen(UNIXaddr.sun_path) + 1 && UNIXaddr.sun_path[sun_path_size - 1] != '\0') + { + /* Making the string null-terminated */ + UNIXaddr.sun_path[sun_path_size - 1] = '\0'; + } + port_length= sizeof(UNIXaddr); + } + if (pvio_socket_connect_sync_or_async(pvio, (struct sockaddr *) &UNIXaddr, port_length)) + { + PVIO_SET_ERROR(cinfo->mysql, CR_CONNECTION_ERROR, SQLSTATE_UNKNOWN, + ER(CR_CONNECTION_ERROR), cinfo->unix_socket, socket_errno); + goto error; + } + if (pvio_socket_blocking(pvio, 1, 0) == SOCKET_ERROR) + { + goto error; + } +#else +/* todo: error, not supported */ +#endif +#endif + } else if (cinfo->type == PVIO_TYPE_SOCKET) + { + struct addrinfo hints, *save_res= 0, *bind_res= 0, *res= 0, *bres= 0; + char server_port[NI_MAXSERV]; + int gai_rc; + int rc= 0; + time_t start_t= time(NULL); +#ifdef _WIN32 + DWORD wait_gai; +#else + unsigned int wait_gai; +#endif + + memset(&server_port, 0, NI_MAXSERV); + snprintf(server_port, NI_MAXSERV, "%d", cinfo->port); + + /* set hints for getaddrinfo */ + memset(&hints, 0, sizeof(hints)); + hints.ai_protocol= IPPROTO_TCP; /* TCP connections only */ + hints.ai_family= AF_UNSPEC; /* includes: IPv4, IPv6 or hostname */ + hints.ai_socktype= SOCK_STREAM; + + /* if client has multiple interfaces, we will bind socket to given + * bind_address */ + if (cinfo->mysql->options.bind_address) + { + wait_gai= 1; + while ((gai_rc= getaddrinfo(cinfo->mysql->options.bind_address, 0, + &hints, &bind_res)) == EAI_AGAIN) + { + unsigned int timeout= mysql->options.connect_timeout ? + mysql->options.connect_timeout : DNS_TIMEOUT; + if (time(NULL) - start_t > (time_t)timeout) + break; +#ifndef _WIN32 + usleep(wait_gai); +#else + Sleep(wait_gai); +#endif + wait_gai*= 2; + } + if (gai_rc != 0 || !bind_res) + { + PVIO_SET_ERROR(cinfo->mysql, CR_BIND_ADDR_FAILED, SQLSTATE_UNKNOWN, + CER(CR_BIND_ADDR_FAILED), cinfo->mysql->options.bind_address, gai_rc); + goto error; + } + } + /* Get the address information for the server using getaddrinfo() */ + wait_gai= 1; + while ((gai_rc= getaddrinfo(cinfo->host, server_port, + &hints, &res)) == EAI_AGAIN) + { + unsigned int timeout= mysql->options.connect_timeout ? + mysql->options.connect_timeout : DNS_TIMEOUT; + if (time(NULL) - start_t > (time_t)timeout) + break; +#ifndef _WIN32 + usleep(wait_gai); +#else + Sleep(wait_gai); +#endif + wait_gai*= 2; + } + if (gai_rc != 0 || !res) + { + PVIO_SET_ERROR(cinfo->mysql, CR_UNKNOWN_HOST, SQLSTATE_UNKNOWN, + ER(CR_UNKNOWN_HOST), cinfo->host, gai_rc); + if (bind_res) + freeaddrinfo(bind_res); + goto error; + } + + /* res is a linked list of addresses for the given hostname. We loop until + we are able to connect to one address or all connect attempts failed */ + for (save_res= res; save_res; save_res= save_res->ai_next) + { + /* CONC-364: Avoid leak of open sockets */ + if (csock->socket != INVALID_SOCKET) + closesocket(csock->socket); + csock->socket= socket(save_res->ai_family, save_res->ai_socktype, + save_res->ai_protocol); + if (csock->socket == INVALID_SOCKET) + /* Errors will be handled after loop finished */ + continue; + + if (bind_res) + { + for (bres= bind_res; bres; bres= bres->ai_next) + { + if (!(rc= bind(csock->socket, bres->ai_addr, (int)bres->ai_addrlen))) + break; + } + if (rc) + { + closesocket(csock->socket); + csock->socket= INVALID_SOCKET; + continue; + } + } + + rc= pvio_socket_connect_sync_or_async(pvio, save_res->ai_addr, (uint)save_res->ai_addrlen); + if (!rc) + { + MYSQL *mysql= pvio->mysql; + if (mysql->options.extension && mysql->options.extension->async_context && + mysql->options.extension->async_context->active) + break; + if (pvio_socket_blocking(pvio, 0, 0) == SOCKET_ERROR) + { + closesocket(csock->socket); + csock->socket= INVALID_SOCKET; + continue; + } + break; /* success! */ + } + } + + freeaddrinfo(res); + if (bind_res) + freeaddrinfo(bind_res); + + if (csock->socket == INVALID_SOCKET) + { + PVIO_SET_ERROR(cinfo->mysql, CR_IPSOCK_ERROR, SQLSTATE_UNKNOWN, ER(CR_IPSOCK_ERROR), + socket_errno); + goto error; + } + + /* last call to connect 2 failed */ + if (rc) + { + PVIO_SET_ERROR(cinfo->mysql, CR_CONNECTION_ERROR, SQLSTATE_UNKNOWN, + ER(CR_CONN_HOST_ERROR), cinfo->host, +#ifdef _WIN32 + errno); +#else + socket_errno); +#endif + goto error; + } + if (pvio_socket_blocking(pvio, 1, 0) == SOCKET_ERROR) + goto error; + } + /* apply timeouts */ + if (pvio->timeout[PVIO_CONNECT_TIMEOUT] > 0) + { + if (pvio_socket_change_timeout(pvio, PVIO_READ_TIMEOUT, pvio->timeout[PVIO_CONNECT_TIMEOUT]) || + pvio_socket_change_timeout(pvio, PVIO_WRITE_TIMEOUT, pvio->timeout[PVIO_CONNECT_TIMEOUT])) + goto error; + } + else + { + if (pvio->timeout[PVIO_WRITE_TIMEOUT] > 0) + if (pvio_socket_change_timeout(pvio, PVIO_WRITE_TIMEOUT, pvio->timeout[PVIO_WRITE_TIMEOUT])) + goto error; + if (pvio->timeout[PVIO_READ_TIMEOUT] > 0) + if (pvio_socket_change_timeout(pvio, PVIO_READ_TIMEOUT, pvio->timeout[PVIO_READ_TIMEOUT])) + goto error; + } + return 0; +error: + /* close socket: MDEV-10891 */ + if (csock->socket != INVALID_SOCKET) + { + closesocket(csock->socket); + csock->socket= INVALID_SOCKET; + } + if (pvio->data) + { + free((gptr)pvio->data); + pvio->data= NULL; + } + return 1; +} + +/* {{{ my_bool pvio_socket_close() */ +my_bool pvio_socket_close(MARIADB_PVIO *pvio) +{ + struct st_pvio_socket *csock= NULL; + int r= 0; + + if (!pvio) + return 1; + + if (pvio->data) + { + csock= (struct st_pvio_socket *)pvio->data; + if (csock && csock->socket != INVALID_SOCKET) + { + r= closesocket(csock->socket); + csock->socket= INVALID_SOCKET; + } + free((gptr)pvio->data); + pvio->data= NULL; + } + return r; +} +/* }}} */ + +/* {{{ my_socket pvio_socket_get_handle */ +my_bool pvio_socket_get_handle(MARIADB_PVIO *pvio, void *handle) +{ + if (pvio && pvio->data && handle) + { + *(my_socket *)handle= ((struct st_pvio_socket *)pvio->data)->socket; + return 0; + } + return 1; +} +/* }}} */ + +/* {{{ my_bool pvio_socket_is_blocking(MARIADB_PVIO *pvio) */ +my_bool pvio_socket_is_blocking(MARIADB_PVIO *pvio) +{ + struct st_pvio_socket *csock= NULL; + my_bool r; + + if (!pvio || !pvio->data) + return 0; + + csock= (struct st_pvio_socket *)pvio->data; + r = !(csock->fcntl_mode & O_NONBLOCK); + return r; +} +/* }}} */ + +/* {{{ my_bool pvio_socket_is_alive(MARIADB_PVIO *pvio) */ +my_bool pvio_socket_is_alive(MARIADB_PVIO *pvio) +{ + struct st_pvio_socket *csock= NULL; + #ifndef _WIN32 + struct pollfd poll_fd; +#else + FD_SET sfds; + struct timeval tv= {0,0}; +#endif + int res; + + if (!pvio || !pvio->data) + return 0; + + csock= (struct st_pvio_socket *)pvio->data; +#ifndef _WIN32 + memset(&poll_fd, 0, sizeof(struct pollfd)); + poll_fd.events= POLLPRI | POLLIN; + poll_fd.fd= csock->socket; + + res= poll(&poll_fd, 1, 0); + if (res <= 0) /* timeout or error */ + return FALSE; + if (!(poll_fd.revents & (POLLIN | POLLPRI))) + return FALSE; + return TRUE; +#else + /* We can't use the WSAPoll function, it's broken :-( + (see Windows 8 Bugs 309411 - WSAPoll does not report failed connections) + Instead we need to use select function: + If TIMEVAL is initialized to {0, 0}, select will return immediately; + this is used to poll the state of the selected sockets. + */ + FD_ZERO(&sfds); + FD_SET(csock->socket, &sfds); + + res= select((int)csock->socket + 1, &sfds, NULL, NULL, &tv); + if (res > 0 && FD_ISSET(csock->socket, &sfds)) + return TRUE; + return FALSE; +#endif +} +/* }}} */ + +/* {{{ my_boool pvio_socket_has_data */ +my_bool pvio_socket_has_data(MARIADB_PVIO *pvio, ssize_t *data_len) +{ + struct st_pvio_socket *csock= NULL; + char tmp_buf; + ssize_t len; + my_bool mode; + + if (!pvio || !pvio->data) + return 0; + + csock= (struct st_pvio_socket *)pvio->data; + /* MSG_PEEK: Peeks at the incoming data. The data is copied into the buffer, + but is not removed from the input queue. + */ + pvio_socket_blocking(pvio, 0, &mode); + len= recv(csock->socket, &tmp_buf, sizeof(tmp_buf), MSG_PEEK); + pvio_socket_blocking(pvio, mode, 0); + if (len < 0) + return 1; + *data_len= len; + return 0; +} +/* }}} */ + +int pvio_socket_shutdown(MARIADB_PVIO *pvio) +{ + if (pvio && pvio->data) + { + my_socket s = ((struct st_pvio_socket *)pvio->data)->socket; +#ifdef _WIN32 + shutdown(s, SD_BOTH); + CancelIoEx((HANDLE)s, NULL); +#else + shutdown(s, SHUT_RDWR); +#endif + } + return -1; +} diff --git a/vendor/MDBC/plugins/trace/trace_example.c b/vendor/MDBC/plugins/trace/trace_example.c new file mode 100644 index 00000000..1060542c --- /dev/null +++ b/vendor/MDBC/plugins/trace/trace_example.c @@ -0,0 +1,458 @@ +/************************************************************************************ + Copyright (C) 2015 MariaDB Corporation AB + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not see + or write to the Free Software Foundation, Inc., + 51 Franklin St., Fifth Floor, Boston, MA 02110, USA +*************************************************************************************/ +#ifndef _WIN32 +#define _GNU_SOURCE 1 +#endif + +#include +#include +#include +#include +#include + +#ifndef WIN32 +#include +#endif + +#define READ 0 +#define WRITE 1 + +/* function prototypes */ +static int trace_init(char *errormsg, + size_t errormsg_size, + int unused __attribute__((unused)), + va_list unused1 __attribute__((unused))); +static int trace_deinit(void); + +int (*register_callback)(my_bool register_callback, + void (*callback_function)(int mode, MYSQL *mysql, const uchar *buffer, size_t length)); +void trace_callback(int mode, MYSQL *mysql, const uchar *buffer, size_t length); + +#ifndef HAVE_TRACE_EXAMPLE_PLUGIN_DYNAMIC +struct st_mysql_client_plugin trace_example_plugin= +#else +struct st_mysql_client_plugin _mysql_client_plugin_declaration_ = +#endif +{ + MARIADB_CLIENT_TRACE_PLUGIN, + MARIADB_CLIENT_TRACE_PLUGIN_INTERFACE_VERSION, + "trace_example", + "Georg Richter", + "Trace example plugin", + {1,0,0}, + "LGPL", + NULL, + &trace_init, + &trace_deinit, + NULL +}; + +static const char *commands[]= { + "COM_SLEEP", + "COM_QUIT", + "COM_INIT_DB", + "COM_QUERY", + "COM_FIELD_LIST", + "COM_CREATE_DB", + "COM_DROP_DB", + "COM_REFRESH", + "COM_SHUTDOWN", + "COM_STATISTICS", + "COM_PROCESS_INFO", + "COM_CONNECT", + "COM_PROCESS_KILL", + "COM_DEBUG", + "COM_PING", + "COM_TIME", + "COM_DELAYED_INSERT", + "COM_CHANGE_USER", + "COM_BINLOG_DUMP", + "COM_TABLE_DUMP", + "COM_CONNECT_OUT", + "COM_REGISTER_SLAVE", + "COM_STMT_PREPARE", + "COM_STMT_EXECUTE", + "COM_STMT_SEND_LONG_DATA", + "COM_STMT_CLOSE", + "COM_STMT_RESET", + "COM_SET_OPTION", + "COM_STMT_FETCH", + "COM_DAEMON", + "COM_END" +}; + +typedef struct { + unsigned long thread_id; + int last_command; /* COM_* values, -1 for handshake */ + unsigned int max_packet_size; + unsigned int num_commands; + size_t total_size[2]; + unsigned int client_flags; + char *username; + char *db; + char *command; + char *filename; + unsigned long refid; /* stmt_id, thread_id for kill */ + uchar charset; + void *next; + int local_infile; + unsigned long pkt_length; +} TRACE_INFO; + +#define TRACE_STATUS(a) ((!a) ? "ok" : "error") + +TRACE_INFO *trace_info= NULL; + +static TRACE_INFO *get_trace_info(unsigned long thread_id) +{ + TRACE_INFO *info= trace_info; + + /* search connection */ + while (info) + { + if (info->thread_id == thread_id) + return info; + else + info= (TRACE_INFO *)info->next; + } + + if (!(info= (TRACE_INFO *)calloc(sizeof(TRACE_INFO), 1))) + return NULL; + info->thread_id= thread_id; + info->next= trace_info; + trace_info= info; + return info; +} + +static void delete_trace_info(unsigned long thread_id) +{ + TRACE_INFO *last= NULL, *current; + current= trace_info; + + while (current) + { + if (current->thread_id == thread_id) + { + printf("deleting thread %lu\n", thread_id); + + if (last) + last->next= current->next; + else + trace_info= (TRACE_INFO *)current->next; + if (current->command) + free(current->command); + if (current->db) + free(current->db); + if (current->username) + free(current->username); + if (current->filename) + free(current->filename); + free(current); + } + last= current; + current= (TRACE_INFO *)current->next; + } + +} + + +/* {{{ static int trace_init */ +/* + Initialization routine + + SYNOPSIS + trace_init + unused1 + unused2 + unused3 + unused4 + + DESCRIPTION + Init function registers a callback handler for PVIO interface. + + RETURN + 0 success +*/ +static int trace_init(char *errormsg, + size_t errormsg_size, + int unused1 __attribute__((unused)), + va_list unused2 __attribute__((unused))) +{ + void *func; + +#ifdef WIN32 + if (!(func= GetProcAddress(GetModuleHandle(NULL), "ma_pvio_register_callback"))) +#else + if (!(func= dlsym(RTLD_DEFAULT, "ma_pvio_register_callback"))) +#endif + { + strncpy(errormsg, "Can't find ma_pvio_register_callback function", errormsg_size); + return 1; + } + register_callback= func; + register_callback(TRUE, trace_callback); + + return 0; +} +/* }}} */ + +static int trace_deinit(void) +{ + /* unregister plugin */ + while(trace_info) + { + printf("Warning: Connection for thread %lu not properly closed\n", trace_info->thread_id); + trace_info= (TRACE_INFO *)trace_info->next; + } + register_callback(FALSE, trace_callback); + return 0; +} + +static void trace_set_command(TRACE_INFO *info, char *buffer, size_t size) +{ + if (info->command) + free(info->command); + + info->command= calloc(1, size + 1); + memcpy(info->command, buffer, size); +} + +void dump_buffer(uchar *buffer, size_t len) +{ + uchar *p= buffer; + while (p < buffer + len) + { + printf("%02x ", *p); + p++; + } + printf("\n"); +} + +static void dump_simple(TRACE_INFO *info, my_bool is_error) +{ + printf("%8lu: %s %s\n", info->thread_id, commands[info->last_command], TRACE_STATUS(is_error)); +} + +static void dump_reference(TRACE_INFO *info, my_bool is_error) +{ + printf("%8lu: %s(%lu) %s\n", info->thread_id, commands[info->last_command], (long)info->refid, TRACE_STATUS(is_error)); +} + +static void dump_command(TRACE_INFO *info, my_bool is_error) +{ + size_t i; + printf("%8lu: %s(", info->thread_id, commands[info->last_command]); + for (i= 0; info->command && i < strlen(info->command); i++) + if (info->command[i] == '\n') + printf("\\n"); + else if (info->command[i] == '\r') + printf("\\r"); + else if (info->command[i] == '\t') + printf("\\t"); + else + printf("%c", info->command[i]); + printf(") %s\n", TRACE_STATUS(is_error)); +} + +void trace_callback(int mode, MYSQL *mysql, const uchar *buffer, size_t length) +{ + unsigned long thread_id= mysql->thread_id; + TRACE_INFO *info; + + /* check if package is server greeting package, + * and set thread_id */ + if (!thread_id && mode == READ) + { + char *p= (char *)buffer; + p+= 4; /* packet length */ + if ((uchar)*p != 0xFF) /* protocol version 0xFF indicates error */ + { + p+= strlen(p + 1) + 2; + thread_id= uint4korr(p); + } + info= get_trace_info(thread_id); + info->last_command= -1; + } + else + { + char *p= (char *)buffer; + info= get_trace_info(thread_id); + + if (info->last_command == -1) + { + if (mode == WRITE) + { + /* client authentication reply packet: + * + * ofs description length + * ------------------------ + * 0 length 3 + * 3 packet_no 1 + * 4 client capab. 4 + * 8 max_packet_size 4 + * 12 character set 1 + * 13 reserved 23 + * ------------------------ + * 36 username (zero terminated) + * len (1 byte) + password or + */ + + p+= 4; + info->client_flags= uint4korr(p); + p+= 4; + info->max_packet_size= uint4korr(p); + p+= 4; + info->charset= *p; + p+= 24; + info->username= strdup(p); + p+= strlen(p) + 1; + if (*p) /* we are not interested in authentication data */ + p+= *p; + p++; + if (info->client_flags & CLIENT_CONNECT_WITH_DB) + info->db= strdup(p); + } + else + { + p++; + if ((uchar)*p == 0xFF) + printf("%8lu: CONNECT_ERROR(%d)\n", info->thread_id, uint4korr(p+1)); + else + printf("%8lu: CONNECT_SUCCESS(host=%s,user=%s,db=%s)\n", info->thread_id, + mysql->host, info->username, info->db ? info->db : "'none'"); + info->last_command= COM_SLEEP; + } + } + else { + char *p= (char *)buffer; + int len; + + if (mode == WRITE) + { + if (info->pkt_length > 0) + { + info->pkt_length-= length; + return; + } + len= uint3korr(p); + info->pkt_length= len + 4 - length; + p+= 4; + info->last_command= *p; + p++; + + switch (info->last_command) { + case COM_INIT_DB: + case COM_DROP_DB: + case COM_CREATE_DB: + case COM_DEBUG: + case COM_QUERY: + case COM_STMT_PREPARE: + trace_set_command(info, p, len - 1); + break; + case COM_PROCESS_KILL: + info->refid= uint4korr(p); + break; + case COM_QUIT: + printf("%8lu: COM_QUIT\n", info->thread_id); + delete_trace_info(info->thread_id); + break; + case COM_PING: + printf("%8lu: COM_PING\n", info->thread_id); + break; + case COM_STMT_EXECUTE: + case COM_STMT_RESET: + case COM_STMT_CLOSE: + info->refid= uint4korr(p); + break; + case COM_CHANGE_USER: + break; + default: + if (info->local_infile == 1) + { + printf("%8lu: SEND_LOCAL_INFILE(%s) ", info->thread_id, info->filename); + if (len) + printf("sent %d bytes\n", len); + else + printf("- error\n"); + info->local_infile= 2; + } + else + printf("%8lu: UNKNOWN_COMMAND: %d\n", info->thread_id, info->last_command); + break; + } + } + else + { + my_bool is_error; + + len= uint3korr(p); + p+= 4; + + is_error= (len == -1); + + switch(info->last_command) { + case COM_STMT_EXECUTE: + case COM_STMT_RESET: + case COM_STMT_CLOSE: + case COM_PROCESS_KILL: + dump_reference(info, is_error); + info->refid= 0; + info->last_command= 0; + break; + case COM_QUIT: + dump_simple(info, is_error); + break; + case COM_QUERY: + case COM_INIT_DB: + case COM_DROP_DB: + case COM_CREATE_DB: + case COM_DEBUG: + case COM_CHANGE_USER: + if (info->last_command == COM_QUERY && (uchar)*p == 251) + { + info->local_infile= 1; + p++; + info->filename= (char *)malloc(len); + strncpy(info->filename, (char *)p, len); + dump_command(info, is_error); + break; + } + dump_command(info, is_error); + if (info->local_infile != 1) + { + free(info->command); + info->command= NULL; + } + break; + case COM_STMT_PREPARE: + printf("%8lu: COM_STMT_PREPARE(%s) ", info->thread_id, info->command); + if (!*p) + { + unsigned long stmt_id= uint4korr(p+1); + printf("-> stmt_id(%lu)\n", stmt_id); + } + else + printf("error\n"); + break; + } + } + } + } + info->total_size[mode]+= length; +} diff --git a/vendor/MDBC/scripts/create_man b/vendor/MDBC/scripts/create_man new file mode 100644 index 00000000..4ff118b0 --- /dev/null +++ b/vendor/MDBC/scripts/create_man @@ -0,0 +1,54 @@ +#!/usr/bin/python3 + +import re +import os +import argparse + +def read_content(file): + try: + f=open(file, "r") + content= f.read() + f.close() + except: + raise + return content + +def header(function, version): + hdr= "%% %s(3) Version %s | MariaDB Connector/C\n" % (function, version) + return hdr + +def replace_links(content): + links= list(re.compile(r'\[([^\]]+)\]\(([^)]+)\)').findall(content)) + for l in links: + search= "[%s()](%s)" % (l[1], l[1]) + replace= "**%s(3)**" % l[1] + content= content.replace(search, replace) + return content + +parser= argparse.ArgumentParser(prog="create_man.py", + description="Create man pages for MariaDB Connector/C") +parser.add_argument('--docs', type=str, metavar='docs', help='Directory of MariaDB Connector/C documentation') +parser.add_argument('--funcs', type=str, metavar='funcs', help='File which contains exported functions.') +parser.add_argument('--version', type=str, metavar='version', help='Connector/C version') +args= parser.parse_args() +print(args) + +func_list= read_content(args.funcs) +funcs= func_list.split(";") + +for function in funcs: + + try: + print("%s/%s.md" % (args.docs, function)) + content= read_content("%s/%s.md" % (args.docs, function)) + + except: + print("warning: No documentation for function %s found" % function) + continue + + f= open("%s.3.md" % function, "w") + f.write(header(function, args.version)) + f.write(replace_links(content)) + f.close() + ret= os.system("pandoc --standalone --to man %s.3.md -o man/%s.3" % (function, function)) + os.unlink("%s.3.md" % function) diff --git a/vendor/MDBC/travis.sh b/vendor/MDBC/travis.sh new file mode 100644 index 00000000..ea65dfe3 --- /dev/null +++ b/vendor/MDBC/travis.sh @@ -0,0 +1,93 @@ +#!/bin/bash + +set -e + +if [ -n "$server_branch" ] ; then + + ################################################################################################################### + # run server test suite + ################################################################################################################### + echo "run server test suite" + + # change travis localhost to use only 127.0.0.1 + sudo sed -i 's/127\.0\.1\.1 localhost/127.0.0.1 localhost/' /etc/hosts + sudo tail /etc/hosts + + # get latest server + git clone -b ${server_branch} https://github.com/mariadb/server ../workdir-server + + cd ../workdir-server + # don't pull in submodules. We want the latest C/C as libmariadb + # build latest server with latest C/C as libmariadb + # skip to build some storage engines to speed up the build + cmake -DPLUGIN_MROONGA=NO -DPLUGIN_ROCKSDB=NO -DPLUGIN_SPIDER=NO -DPLUGIN_TOKUDB=NO + cd libmariadb + echo "PR:${TRAVIS_PULL_REQUEST} TRAVIS_COMMIT:${TRAVIS_COMMIT}" + if [ -n "$TRAVIS_PULL_REQUEST" ] && [ "$TRAVIS_PULL_REQUEST" != "false" ] ; then + # fetching pull request + echo "fetching PR" + git fetch origin pull/${TRAVIS_PULL_REQUEST}/head:PR_${TRAVIS_PULL_REQUEST} + echo "checkout PR" + git checkout PR_${TRAVIS_PULL_REQUEST} + else + echo "checkout commit" + git checkout ${TRAVIS_COMMIT} + fi + + cd .. + git add libmariadb + make -j9 + + cd mysql-test/ + ./mysql-test-run.pl --suite=main ${TEST_OPTION} --parallel=auto --skip-test=session_tracker_last_gtid + +else + + ################################################################################################################### + # run connector test suite + ################################################################################################################### + echo "run connector test suite" + + cmake . -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCERT_PATH=${SSLCERT} + + if [ "$TRAVIS_OS_NAME" = "windows" ] ; then + echo "build from windows" + set MARIADB_CC_TEST=1 + set MYSQL_TEST_DB=testc + set MYSQL_TEST_TLS=%TEST_REQUIRE_TLS% + set MYSQL_TEST_USER=%TEST_DB_USER% + set MYSQL_TEST_HOST=%TEST_DB_HOST% + set MYSQL_TEST_PASSWD=%TEST_DB_PASSWORD% + set MYSQL_TEST_PORT=%TEST_DB_PORT% + set MYSQL_TEST_TLS=%TEST_REQUIRE_TLS% + cmake --build . --config RelWithDebInfo + else + echo "build from linux" + export MARIADB_CC_TEST=1 + export MYSQL_TEST_USER=$TEST_DB_USER + export MYSQL_TEST_HOST=$TEST_DB_HOST + export MYSQL_TEST_PASSWD=$TEST_DB_PASSWORD + export MYSQL_TEST_PORT=$TEST_DB_PORT + export MYSQL_TEST_DB=testc + export MYSQL_TEST_TLS=$TEST_REQUIRE_TLS + export SSLCERT=$TEST_DB_SERVER_CERT + export MARIADB_PLUGIN_DIR=$PWD + + echo "MYSQL_TEST_PLUGINDIR=$MYSQL_TEST_PLUGINDIR" + if [ -n "$MYSQL_TEST_SSL_PORT" ] ; then + export MYSQL_TEST_SSL_PORT=$MYSQL_TEST_SSL_PORT + fi + export MYSQL_TEST_TLS=$TEST_REQUIRE_TLS + export SSLCERT=$TEST_DB_SERVER_CERT + if [ -n "$MYSQL_TEST_SSL_PORT" ] ; then + export MYSQL_TEST_SSL_PORT=$MYSQL_TEST_SSL_PORT + fi + make + fi + + ls -lrt + + openssl ciphers -v + cd unittest/libmariadb + ctest -V +fi diff --git a/vendor/MDBC/unittest/libmariadb/CMakeLists.txt b/vendor/MDBC/unittest/libmariadb/CMakeLists.txt new file mode 100644 index 00000000..e3ba18b8 --- /dev/null +++ b/vendor/MDBC/unittest/libmariadb/CMakeLists.txt @@ -0,0 +1,67 @@ +# Copyright (C) 2008 Sun Microsystems, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; version 2 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +IF(SKIP_TESTS) + RETURN() +ENDIF() + +ENABLE_TESTING() + + +INCLUDE_DIRECTORIES(${CC_SOURCE_DIR}/include + ${CC_BINARY_DIR}/include + ${CC_SOURCE_DIR}/unittest/mytap + ${CC_SOURCE_DIR}/unittest/libmariadb) +ADD_DEFINITIONS(-DLIBMARIADB) + +SET(API_TESTS "conc336" "bulk1" "performance" "basic-t" "fetch" "charset" "logs" "cursor" "errors" "view" "ps" "ps_bugs" "sp" "result" "connection" "misc" "ps_new" "thread" "features-10_2" "bulk1") +IF(WITH_DYNCOL) + SET(API_TESTS ${API_TESTS} "dyncol") +ENDIF() + +SET(API_TESTS ${API_TESTS} "async") + +#exclude following tests from ctests, since we need to run them maually with different credentials +SET(MANUAL_TESTS "t_aurora" "t_conc173" "rpl_api") +# Get finger print from server certificate +IF(WITH_SSL) + IF(CERT_PATH AND NOT DEFINED ENV{TRAVIS}) + SET(API_TESTS ${API_TESTS} "ssl") + IF(WIN32) + STRING(REPLACE "\\" "\\\\" CERT_PATH ${CERT_PATH}) + ENDIF() + ADD_DEFINITIONS(-DCERT_PATH="${CERT_PATH}") + ENDIF() +ENDIF() + +ADD_LIBRARY(ma_getopt ma_getopt.c) + +FOREACH(API_TEST ${API_TESTS}) + IF (NOT TARGET ${API_TEST}) + ADD_EXECUTABLE(${API_TEST} ${API_TEST}.c) + ENDIF() + TARGET_LINK_LIBRARIES(${API_TEST} cctap ma_getopt mariadbclient) + ADD_TEST(${API_TEST} ${EXECUTABLE_OUTPUT_PATH}/${API_TEST}) + IF(${API_TEST} STREQUAL "cursor" OR ${API_TEST} STREQUAL "ps_new") + SET_TESTS_PROPERTIES(${API_TEST} PROPERTIES TIMEOUT 360) + ELSE() + SET_TESTS_PROPERTIES(${API_TEST} PROPERTIES TIMEOUT 180) + ENDIF() +ENDFOREACH(API_TEST) + +FOREACH(API_TEST ${MANUAL_TESTS}) + ADD_EXECUTABLE(${API_TEST} ${API_TEST}.c) + TARGET_LINK_LIBRARIES(${API_TEST} cctap ma_getopt mariadbclient) +ENDFOREACH() diff --git a/vendor/MDBC/unittest/libmariadb/async.c b/vendor/MDBC/unittest/libmariadb/async.c new file mode 100644 index 00000000..079f19d8 --- /dev/null +++ b/vendor/MDBC/unittest/libmariadb/async.c @@ -0,0 +1,271 @@ +/* + Copyright 2011 Kristian Nielsen and Monty Program Ab. + + This file is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this. If not, see . +*/ +#include "my_test.h" +#include "ma_common.h" + + +#ifndef _WIN32 +#include +#else +#include +#endif + +#include +#include +#include + +my_bool skip_async= 0; + +static int test_async(MYSQL *mysql) +{ + int type; + mariadb_get_info(mysql, MARIADB_CONNECTION_PVIO_TYPE, &type); + if (type > MARIADB_CONNECTION_TCP) + { + skip_async= 1; + diag("Asnyc IO not supported"); + } + return OK; +} + +static int +wait_for_mysql(MYSQL *mysql, int status) +{ +#ifdef _WIN32 + fd_set rs, ws, es; + int res; + struct timeval tv, *timeout; + my_socket s= mysql_get_socket(mysql); + FD_ZERO(&rs); + FD_ZERO(&ws); + FD_ZERO(&es); + if (status & MYSQL_WAIT_READ) + FD_SET(s, &rs); + if (status & MYSQL_WAIT_WRITE) + FD_SET(s, &ws); + if (status & MYSQL_WAIT_EXCEPT) + FD_SET(s, &es); + if (status & MYSQL_WAIT_TIMEOUT) + { + tv.tv_sec= mysql_get_timeout_value(mysql); + tv.tv_usec= 0; + timeout= &tv; + } + else + timeout= NULL; + res= select(1, &rs, &ws, &es, timeout); + if (res == 0) + return MYSQL_WAIT_TIMEOUT; + else if (res == SOCKET_ERROR) + { + /* + In a real event framework, we should handle errors and re-try the select. + */ + return MYSQL_WAIT_TIMEOUT; + } + else + { + int status= 0; + if (FD_ISSET(s, &rs)) + status|= MYSQL_WAIT_READ; + if (FD_ISSET(s, &ws)) + status|= MYSQL_WAIT_WRITE; + if (FD_ISSET(s, &es)) + status|= MYSQL_WAIT_EXCEPT; + return status; + } +#else + struct pollfd pfd; + int timeout; + int res= -1; + + pfd.fd= mysql_get_socket(mysql); + pfd.events= + (status & MYSQL_WAIT_READ ? POLLIN : 0) | + (status & MYSQL_WAIT_WRITE ? POLLOUT : 0) | + (status & MYSQL_WAIT_EXCEPT ? POLLPRI : 0); + if (status & MYSQL_WAIT_TIMEOUT) + { + timeout= mysql_get_timeout_value_ms(mysql); + } + else + timeout= -1; + do { + res= poll(&pfd, 1, timeout); + } while (res == -1 && errno == EINTR); + if (res == 0) + return MYSQL_WAIT_TIMEOUT; + else if (res < 0) + { + /* + In a real event framework, we should handle EINTR and re-try the poll. + */ + return MYSQL_WAIT_TIMEOUT; + } + else + { + int status= 0; + if (pfd.revents & POLLIN) + status|= MYSQL_WAIT_READ; + if (pfd.revents & POLLOUT) + status|= MYSQL_WAIT_WRITE; + if (pfd.revents & POLLPRI) + status|= MYSQL_WAIT_EXCEPT; + return status; + } +#endif +} + +static int async1(MYSQL *unused __attribute__((unused))) +{ + int err= 0, rc; + MYSQL mysql, *ret; + MYSQL_RES *res; + MYSQL_ROW row; + int status; + uint default_timeout; + int i; + + if (skip_async) + return SKIP; + + for (i=0; i < 100; i++) + { + + mysql_init(&mysql); + rc= mysql_options(&mysql, MYSQL_OPT_NONBLOCK, 0); + check_mysql_rc(rc, (MYSQL *)&mysql); + + /* set timeouts to 300 microseconds */ + default_timeout= 3; + mysql_options(&mysql, MYSQL_OPT_READ_TIMEOUT, &default_timeout); + mysql_options(&mysql, MYSQL_OPT_CONNECT_TIMEOUT, &default_timeout); + mysql_options(&mysql, MYSQL_OPT_WRITE_TIMEOUT, &default_timeout); + mysql_options(&mysql, MYSQL_READ_DEFAULT_GROUP, "myapp"); + if (force_tls) + mysql_ssl_set(&mysql, NULL, NULL, NULL, NULL,NULL); + + /* Returns 0 when done, else flag for what to wait for when need to block. */ + status= mysql_real_connect_start(&ret, &mysql, hostname, username, password, schema, port, socketname, 0); + while (status) + { + status= wait_for_mysql(&mysql, status); + status= mysql_real_connect_cont(&ret, &mysql, status); + } + if (!ret) + { + diag("Error: %s", mysql_error(&mysql)); + FAIL_IF(!ret, "Failed to mysql_real_connect()"); + } + + if (force_tls && !mysql_get_ssl_cipher(&mysql)) + { + diag("Error: No tls connection"); + return FAIL; + } + + status= mysql_real_query_start(&err, &mysql, SL("SHOW STATUS")); + while (status) + { + status= wait_for_mysql(&mysql, status); + status= mysql_real_query_cont(&err, &mysql, status); + } + FAIL_IF(err, "mysql_real_query() returns error"); + + /* This method cannot block. */ + res= mysql_use_result(&mysql); + FAIL_IF(!res, "mysql_use_result() returns error"); + + for (;;) + { + status= mysql_fetch_row_start(&row, res); + while (status) + { + status= wait_for_mysql(&mysql, status); + status= mysql_fetch_row_cont(&row, res, status); + } + if (!row) + break; + } + FAIL_IF(mysql_errno(&mysql), "Got error while retrieving rows"); + mysql_free_result(res); + + /* + mysql_close() sends a COM_QUIT packet, and so in principle could block + waiting for the socket to accept the data. + In practise, for many applications it will probably be fine to use the + blocking mysql_close(). + */ + status= mysql_close_start(&mysql); + while (status) + { + status= wait_for_mysql(&mysql, status); + status= mysql_close_cont(&mysql, status); + } + } + return OK; +} + +static int test_conc131(MYSQL *unused __attribute__((unused))) +{ + int rc; + /* this test needs to run under valgrind */ + MYSQL *mysql; + + if (skip_async) + return SKIP; + + mysql= mysql_init(NULL); + rc= mysql_options(mysql, MYSQL_OPT_NONBLOCK, 0); + check_mysql_rc(rc, mysql); + mysql_close(mysql); + return OK; +} + +static int test_conc129(MYSQL *unused __attribute__((unused))) +{ + MYSQL *mysql; + + if (skip_async) + return SKIP; + + mysql= mysql_init(NULL); + FAIL_IF(mysql_close_start(mysql), "No error expected"); + return OK; +} + + +struct my_tests_st my_tests[] = { + {"test_async", test_async, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"async1", async1, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_conc131", test_conc131, TEST_CONNECTION_NONE, 0, NULL, NULL}, + {"test_conc129", test_conc129, TEST_CONNECTION_NONE, 0, NULL, NULL}, + {NULL, NULL, 0, 0, NULL, NULL} +}; + + +int main(int argc, char **argv) +{ + if (argc > 1) + get_options(argc, argv); + + get_envvars(); + + run_tests(my_tests); + + return(exit_status()); +} diff --git a/vendor/MDBC/unittest/libmariadb/basic-t.c b/vendor/MDBC/unittest/libmariadb/basic-t.c new file mode 100644 index 00000000..87bff9a9 --- /dev/null +++ b/vendor/MDBC/unittest/libmariadb/basic-t.c @@ -0,0 +1,843 @@ +/* +Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. + +The MySQL Connector/C is licensed under the terms of the GPLv2 +, like most +MySQL Connectors. There are special exceptions to the terms and +conditions of the GPLv2 as it is applied to this software, see the +FLOSS License Exception +. + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published +by the Free Software Foundation; version 2 of the License. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + + +/** + Some basic tests of the client API. +*/ + +#include "my_test.h" +#include "ma_common.h" + +static int test_conc75(MYSQL *my) +{ + int rc; + MYSQL *mysql; + int i; + my_bool reconnect= 1; + + SKIP_SKYSQL; + SKIP_MAXSCALE; + + mysql= mysql_init(NULL); + + mysql_options(mysql, MYSQL_OPT_RECONNECT, &reconnect); + my_test_connect(mysql, hostname, username, password, schema, port, socketname, 0| CLIENT_MULTI_RESULTS | CLIENT_REMEMBER_OPTIONS); + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS a"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE a (a varchar(200))"); + check_mysql_rc(rc, mysql); + + rc= mysql_set_character_set(mysql, "utf8"); + check_mysql_rc(rc, mysql); + + for (i=0; i < 10; i++) + { + ulong thread_id= mysql_thread_id(mysql); + /* force reconnect */ + mysql_options(mysql, MYSQL_OPT_RECONNECT, &reconnect); + diag("killing connection"); + mysql_kill(my, thread_id); + mysql_ping(mysql); + rc= mysql_query(mysql, "load data local infile './nonexistingfile.csv' into table a (`a`)"); + FAIL_IF(!test(mysql->options.client_flag | CLIENT_LOCAL_FILES), "client_flags not correct"); + diag("thread1: %ld %ld", thread_id, mysql_thread_id(mysql)); + FAIL_IF(thread_id == mysql_thread_id(mysql), "new thread id expected"); + //diag("cs: %s", mysql->charset->csname); + //FAIL_IF(strcmp(mysql->charset->csname, "utf8"), "wrong character set"); + } + rc= mysql_query(mysql, "DROP TABLE IF EXISTS a"); + check_mysql_rc(rc, mysql); + mysql_close(mysql); + return OK; +} + + +static int test_conc74(MYSQL *unused __attribute__((unused))) +{ + int rc; + MYSQL *mysql; + + mysql= mysql_init(NULL); + + + if (!my_test_connect(mysql, hostname, username, password, schema, port, socketname, 0| CLIENT_MULTI_RESULTS | CLIENT_REMEMBER_OPTIONS)) + { + diag("Error: %s", mysql_error(mysql)); + mysql_close(mysql); + return FAIL; + } + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS a"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE a (a varchar(200))"); + check_mysql_rc(rc, mysql); + + mysql->options.client_flag&= ~CLIENT_LOCAL_FILES; + + rc= mysql_query(mysql, "load data local infile './nonexistingfile.csv' into table a (`a`)"); + FAIL_IF(!rc, "Error expected"); + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS a"); + check_mysql_rc(rc, mysql); + + mysql_close(mysql); + return OK; +} + + +static int test_conc71(MYSQL *my) +{ + int rc; + MYSQL *mysql; + + /* uncomment if you want to test manually */ + return SKIP; + + mysql= mysql_init(NULL); + + + mysql_options(mysql, MYSQL_SET_CHARSET_NAME, "utf8"); + mysql_options(mysql, MYSQL_OPT_COMPRESS, 0); + mysql_options(mysql, MYSQL_INIT_COMMAND, "/*!40101 SET SQL_MODE='' */"); + mysql_options(mysql, MYSQL_INIT_COMMAND, "/*!40101 set @@session.wait_timeout=28800 */"); + + FAIL_IF(!my_test_connect(mysql, hostname, username, password, schema, + port, socketname, 0), mysql_error(my)); + + diag("kill server"); + + rc= mysql_query(mysql, "SELECT 'foo' FROM DUAL"); + check_mysql_rc(rc, mysql); + + mysql_close(mysql); + return OK; +} + +static int test_conc70(MYSQL *my) +{ + int rc; + MYSQL_RES *res; + MYSQL_ROW row; + MYSQL *mysql; + + SKIP_CONNECTION_HANDLER; + + SKIP_SKYSQL; + SKIP_MAXSCALE; + + mysql= mysql_init(NULL); + + rc= mysql_query(my, "SET @a:=@@max_allowed_packet"); + check_mysql_rc(rc, my); + + mysql_query(my, "SET global max_allowed_packet=1024*1024*22"); + check_mysql_rc(rc, my); + + mysql_options(mysql, MYSQL_OPT_COMPRESS, (void *)1); + FAIL_IF(!my_test_connect(mysql, hostname, username, password, schema, + port, socketname, 0), mysql_error(my)); + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE t1 (a LONGBLOB) engine=MyISAM"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "INSERT INTO t1 VALUES (REPEAT('A', 1024 * 1024 * 20))"); + check_mysql_rc(rc, mysql); + + if (mysql_warning_count(mysql)) + { + diag("server doesn't accept package size"); + return SKIP; + } + + + rc= mysql_query(mysql, "SELECT a FROM t1"); + check_mysql_rc(rc, mysql); + + if (!(res= mysql_store_result(mysql))) + { + diag("Error: %s", mysql_error(mysql)); + return FAIL; + } + + row= mysql_fetch_row(res); + diag("Length: %ld", (long)strlen(row[0])); + FAIL_IF(strlen(row[0]) != 1024 * 1024 * 20, "Wrong length"); + + mysql_free_result(res); + rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1"); + check_mysql_rc(rc, mysql); + + mysql_close(mysql); + + rc= mysql_query(my, "SET global max_allowed_packet=@a"); + check_mysql_rc(rc, my); + + return OK; +} + +static int test_conc68(MYSQL *my) +{ + int rc; + MYSQL_RES *res; + MYSQL_ROW row; + MYSQL *mysql; + + SKIP_CONNECTION_HANDLER; + SKIP_SKYSQL; + SKIP_MAXSCALE; + + mysql= mysql_init(NULL); + + rc= mysql_query(my, "SET @a:=@@max_allowed_packet"); + check_mysql_rc(rc, my); + + mysql_query(my, "SET global max_allowed_packet=1024*1024*22"); + + FAIL_IF(!my_test_connect(mysql, hostname, username, password, schema, + port, socketname, 0), mysql_error(my)); + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE t1 (a LONGBLOB) ENGINE=MyISAM"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "INSERT INTO t1 VALUES (REPEAT('A', 1024 * 1024 * 20))"); + check_mysql_rc(rc, mysql); + if (mysql_warning_count(mysql)) + { + diag("server doesn't accept package size"); + return SKIP; + } + + rc= mysql_query(mysql, "SELECT a FROM t1"); + check_mysql_rc(rc, mysql); + + if (!(res= mysql_store_result(mysql))) + { + diag("Error: %s", mysql_error(mysql)); + return FAIL; + } + + row= mysql_fetch_row(res); + diag("Length: %ld", (long)strlen(row[0])); + FAIL_IF(strlen(row[0]) != 1024 * 1024 * 20, "Wrong length"); + + mysql_free_result(res); + mysql_close(mysql); + + rc= mysql_query(my, "SET global max_allowed_packet=@a"); + check_mysql_rc(rc, my); + + return OK; +} + + +static int basic_connect(MYSQL *unused __attribute__((unused))) +{ + MYSQL_ROW row; + MYSQL_RES *res; + MYSQL_FIELD *field; + int rc; + MYSQL *my; + + my= mysql_init(NULL); + FAIL_IF(!my, "mysql_init() failed"); + + FAIL_IF(!my_test_connect(my, hostname, username, password, schema, + port, socketname, 0), mysql_error(my)); + + rc= mysql_query(my, "SELECT @@version"); + check_mysql_rc(rc, my); + + res= mysql_store_result(my); + FAIL_IF(!res, mysql_error(my)); + field= mysql_fetch_fields(res); + FAIL_IF(!field, "couldn't fetch field"); + while ((row= mysql_fetch_row(res)) != NULL) + { + FAIL_IF(mysql_num_fields(res) != 1, "Got the wrong number of fields"); + } + FAIL_IF(mysql_errno(my), mysql_error(my)); + + mysql_free_result(res); + mysql_close(my); + + return OK; +} + + +static int use_utf8(MYSQL *my) +{ + MYSQL_ROW row; + MYSQL_RES *res; + int rc; + + /* Make sure that we actually ended up with utf8. */ + rc= mysql_query(my, "SELECT @@character_set_connection"); + check_mysql_rc(rc, my); + + res= mysql_store_result(my); + FAIL_IF(!res, mysql_error(my)); + + while ((row= mysql_fetch_row(res)) != NULL) + { + FAIL_IF(strncmp(row[0], "utf8", 4), "wrong character set"); + } + FAIL_IF(mysql_errno(my), mysql_error(my)); + mysql_free_result(res); + + return OK; +} + +int client_query(MYSQL *mysql) { + int rc; + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "CREATE TABLE t1(" + "id int primary key auto_increment, " + "name varchar(20))"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "CREATE TABLE t1(id int, name varchar(20))"); + FAIL_IF(!rc, "Error expected"); + rc= mysql_query(mysql, "INSERT INTO t1(name) VALUES('mysql')"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "INSERT INTO t1(name) VALUES('monty')"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "INSERT INTO t1(name) VALUES('venu')"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "INSERT INTO t1(name) VALUES('deleted')"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "INSERT INTO t1(name) VALUES('deleted')"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "UPDATE t1 SET name= 'updated' " + "WHERE name= 'deleted'"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "UPDATE t1 SET id= 3 WHERE name= 'updated'"); + FAIL_IF(!rc, "Error expected"); + rc= mysql_query(mysql, "drop table t1"); + check_mysql_rc(rc, mysql); + + return OK; +} + +static int test_bug12001(MYSQL *mysql) +{ + MYSQL_RES *result; + const char *query= "DROP TABLE IF EXISTS test_table;" + "CREATE TABLE test_table(id INT);" + "INSERT INTO test_table VALUES(10);" + "UPDATE test_table SET id=20 WHERE id=10;" + "SELECT * FROM test_table;" + "INSERT INTO non_existent_table VALUES(11);"; + int rc, res; + + + rc= mysql_query(mysql, query); + check_mysql_rc(rc, mysql); + + do + { + if (mysql_field_count(mysql) && + (result= mysql_use_result(mysql))) + { + mysql_free_result(result); + } + } + while (!(res= mysql_next_result(mysql))); + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_table"); + check_mysql_rc(rc, mysql); + + FAIL_UNLESS(res==1, "res != 1"); + + return OK; +} + + +/* connection options */ +struct my_option_st opt_utf8[] = { + {MYSQL_SET_CHARSET_NAME, (char *)"utf8"}, + {0, NULL} +}; + +static int test_bad_union(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + int rc; + const char *query= "SELECT 1, 2 union SELECT 1"; + + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(query)); + FAIL_UNLESS(rc && mysql_errno(mysql) == 1222, "Error expected"); + + mysql_stmt_close(stmt); + return OK; +} + +/* + Test that mysql_insert_id() behaves as documented in our manual +*/ +static int test_mysql_insert_id(MYSQL *mysql) +{ + unsigned long long res; + int rc; + + if (mysql_get_server_version(mysql) < 50100) { + diag("Test requires MySQL Server version 5.1 or above"); + return SKIP; + } + + rc= mysql_query(mysql, "drop table if exists t1"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "drop table if exists t2"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "drop table if exists t3"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "drop table if exists t4"); + check_mysql_rc(rc, mysql); + /* table without auto_increment column */ + rc= mysql_query(mysql, "create table t1 (f1 int, f2 varchar(255), key(f1))"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "create table t2 (f1 int not null primary key auto_increment, f2 varchar(255))"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "create table t3 (f1 int not null primary key auto_increment, f2 varchar(255)) engine=MyISAM"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "create table t4 (f1 int not null primary key " + "auto_increment, f2 varchar(200), unique (f2)) engine=MyISAM"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "FLUSH TABLES"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "START TRANSACTION"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "insert into t1 values (1,'a')"); + check_mysql_rc(rc, mysql); + res= mysql_insert_id(mysql); + FAIL_UNLESS(res == 0, ""); + rc= mysql_query(mysql, "insert into t1 values (null,'b')"); + check_mysql_rc(rc, mysql); + res= mysql_insert_id(mysql); + FAIL_UNLESS(res == 0, ""); + rc= mysql_query(mysql, "insert into t1 select 5,'c'"); + check_mysql_rc(rc, mysql); + res= mysql_insert_id(mysql); + FAIL_UNLESS(res == 0, ""); + + /* + Test for bug #34889: mysql_client_test::test_mysql_insert_id test fails + sporadically + */ + rc= mysql_query(mysql, "insert into t2 values (null,'b')"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "insert into t1 select 5,'c'"); + check_mysql_rc(rc, mysql); + res= mysql_insert_id(mysql); + FAIL_UNLESS(res == 0, ""); + rc= mysql_query(mysql, "insert into t1 select null,'d'"); + check_mysql_rc(rc, mysql); + res= mysql_insert_id(mysql); + FAIL_UNLESS(res == 0, ""); + rc= mysql_query(mysql, "insert into t1 values (null,last_insert_id(300))"); + check_mysql_rc(rc, mysql); + res= mysql_insert_id(mysql); + FAIL_UNLESS(res == 300, ""); + rc= mysql_query(mysql, "insert into t1 select null,last_insert_id(400)"); + check_mysql_rc(rc, mysql); + res= mysql_insert_id(mysql); + /* + Behaviour change: old code used to return 0; but 400 is consistent + with INSERT VALUES, and the manual's section of mysql_insert_id() does not + say INSERT SELECT should be different. + */ + FAIL_UNLESS(res == 400, ""); + + /* table with auto_increment column */ + rc= mysql_query(mysql, "insert into t3 values (1,'a')"); + check_mysql_rc(rc, mysql); + res= mysql_insert_id(mysql); + FAIL_UNLESS(res == 1, ""); + /* this should not influence next INSERT if it doesn't have auto_inc */ + rc= mysql_query(mysql, "insert into t1 values (10,'e')"); + check_mysql_rc(rc, mysql); + res= mysql_insert_id(mysql); + FAIL_UNLESS(res == 0, ""); + + rc= mysql_query(mysql, "insert into t3 values (null,'b')"); + check_mysql_rc(rc, mysql); + res= mysql_insert_id(mysql); + FAIL_UNLESS(res == 2, ""); + rc= mysql_query(mysql, "insert into t3 select 5,'c'"); + check_mysql_rc(rc, mysql); + res= mysql_insert_id(mysql); + /* + Manual says that for multirow insert this should have been 5, but does not + say for INSERT SELECT. This is a behaviour change: old code used to return + 0. We try to be consistent with INSERT VALUES. + */ + FAIL_UNLESS(res == 5, ""); + rc= mysql_query(mysql, "insert into t3 select null,'d'"); + check_mysql_rc(rc, mysql); + res= mysql_insert_id(mysql); + FAIL_UNLESS(res == 6, ""); + /* with more than one row */ + rc= mysql_query(mysql, "insert into t3 values (10,'a'),(11,'b')"); + check_mysql_rc(rc, mysql); + res= mysql_insert_id(mysql); + FAIL_UNLESS(res == 11, ""); + rc= mysql_query(mysql, "insert into t3 select 12,'a' union select 13,'b'"); + check_mysql_rc(rc, mysql); + res= mysql_insert_id(mysql); + /* + Manual says that for multirow insert this should have been 13, but does + not say for INSERT SELECT. This is a behaviour change: old code used to + return 0. We try to be consistent with INSERT VALUES. + */ + FAIL_UNLESS(res == 13, ""); + rc= mysql_query(mysql, "insert into t3 values (null,'a'),(null,'b')"); + check_mysql_rc(rc, mysql); + res= mysql_insert_id(mysql); + FAIL_UNLESS(res == 14, ""); + rc= mysql_query(mysql, "insert into t3 select null,'a' union select null,'b'"); + check_mysql_rc(rc, mysql); + res= mysql_insert_id(mysql); + FAIL_UNLESS(res == 16, ""); + rc= mysql_query(mysql, "insert into t3 select 12,'a' union select 13,'b'"); + FAIL_IF(!rc, "Error expected"); + rc= mysql_query(mysql, "insert ignore into t3 select 12,'a' union select 13,'b'"); + check_mysql_rc(rc, mysql); + res= mysql_insert_id(mysql); + FAIL_UNLESS(res == 0, ""); + rc= mysql_query(mysql, "insert into t3 values (12,'a'),(13,'b')"); + FAIL_IF(!rc, "Error expected"); + res= mysql_insert_id(mysql); + FAIL_UNLESS(res == 0, ""); + rc= mysql_query(mysql, "insert ignore into t3 values (12,'a'),(13,'b')"); + check_mysql_rc(rc, mysql); + res= mysql_insert_id(mysql); + FAIL_UNLESS(res == 0, ""); + /* mixing autogenerated and explicit values */ + rc= mysql_query(mysql, "insert into t3 values (null,'e'),(12,'a'),(13,'b')"); + FAIL_IF(!rc, "Error expected"); + rc= mysql_query(mysql, "insert into t3 values (null,'e'),(12,'a'),(13,'b'),(25,'g')"); + FAIL_IF(!rc, "Error expected"); + rc= mysql_query(mysql, "insert into t3 values (null,last_insert_id(300))"); + check_mysql_rc(rc, mysql); + res= mysql_insert_id(mysql); + /* + according to the manual, this might be 20 or 300, but it looks like + auto_increment column takes priority over last_insert_id(). + */ + diag("res: %lld", res); + FAIL_UNLESS(res == 20, ""); + /* If first autogenerated number fails and 2nd works: */ + rc= mysql_query(mysql, "insert into t4 values (null,'e')"); + res= mysql_insert_id(mysql); + FAIL_UNLESS(res == 1, ""); + rc= mysql_query(mysql, "insert ignore into t4 values (null,'e'),(null,'a'),(null,'e')"); + check_mysql_rc(rc, mysql); + res= mysql_insert_id(mysql); + FAIL_UNLESS(res == 2, ""); + /* If autogenerated fails and explicit works: */ + rc= mysql_query(mysql, "insert ignore into t4 values (null,'e'),(12,'c'),(null,'d')"); + check_mysql_rc(rc, mysql); + res= mysql_insert_id(mysql); + /* + Behaviour change: old code returned 3 (first autogenerated, even if it + fails); we now return first successful autogenerated. + */ + FAIL_UNLESS(res == 13, ""); + /* UPDATE may update mysql_insert_id() if it uses LAST_INSERT_ID(#) */ + rc= mysql_query(mysql, "update t4 set f1=14 where f1=12"); + check_mysql_rc(rc, mysql); + res= mysql_insert_id(mysql); + FAIL_UNLESS(res == 0, ""); + rc= mysql_query(mysql, "update t4 set f1=0 where f1=14"); + check_mysql_rc(rc, mysql); + res= mysql_insert_id(mysql); + FAIL_UNLESS(res == 0, ""); + rc= mysql_query(mysql, "update t4 set f2=last_insert_id(372) where f1=0"); + check_mysql_rc(rc, mysql); + res= mysql_insert_id(mysql); + FAIL_UNLESS(res == 372, ""); + /* check that LAST_INSERT_ID() does not update mysql_insert_id(): */ + rc= mysql_query(mysql, "insert into t4 values (null,'g')"); + check_mysql_rc(rc, mysql); + res= mysql_insert_id(mysql); + FAIL_UNLESS(res == 15, ""); + rc= mysql_query(mysql, "update t4 set f2=(@li:=last_insert_id()) where f1=15"); + check_mysql_rc(rc, mysql); + res= mysql_insert_id(mysql); + FAIL_UNLESS(res == 0, ""); + /* + Behaviour change: now if ON DUPLICATE KEY UPDATE updates a row, + mysql_insert_id() returns the id of the row, instead of not being + affected. + */ + rc= mysql_query(mysql, "insert into t4 values (null,@li) on duplicate key " + "update f2=concat('we updated ',f2)"); + check_mysql_rc(rc, mysql); + res= mysql_insert_id(mysql); + FAIL_UNLESS(res == 15, ""); + + rc= mysql_query(mysql, "drop table t1,t2,t3,t4"); + check_mysql_rc(rc, mysql); + return OK; +} + +/* Test simple select to debug */ + +static int test_select_direct(MYSQL *mysql) +{ + int rc; + MYSQL_RES *result; + + + rc= mysql_autocommit(mysql, TRUE); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_select"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE test_select(id int, id1 tinyint, " + " id2 float, " + " id3 double, " + " name varchar(50))"); + check_mysql_rc(rc, mysql); + + /* insert a row and commit the transaction */ + rc= mysql_query(mysql, "INSERT INTO test_select VALUES(10, 5, 2.3, 4.5, 'venu')"); + check_mysql_rc(rc, mysql); + + rc= mysql_commit(mysql); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "SELECT * FROM test_select"); + check_mysql_rc(rc, mysql); + + /* get the result */ + result= mysql_store_result(mysql); + FAIL_IF(!result, "Invalid result set"); + + mysql_free_result(result); + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_select"); + check_mysql_rc(rc, mysql); + return OK; +} + +/* + Ensure we execute the status code while testing +*/ + +static int test_status(MYSQL *mysql) +{ + mysql_stat(mysql); + check_mysql_rc(mysql_errno(mysql), mysql); + return OK; +} + +static int bug_conc1(MYSQL *mysql) +{ + my_test_connect(mysql, hostname, username, password, schema, + port, socketname, 0); + diag("errno: %d", mysql_errno(mysql)); + FAIL_IF(mysql_errno(mysql) != CR_ALREADY_CONNECTED, + "Expected errno=CR_ALREADY_CONNECTED"); + return OK; +} + +static int test_options_initcmd(MYSQL *unused __attribute__((unused))) +{ + MYSQL *mysql= mysql_init(NULL); + MYSQL_RES *res; + int rc; + + mysql_options(mysql, MYSQL_INIT_COMMAND, "DROP TABLE IF EXISTS t1; CREATE TABLE t1 (a int)"); + mysql_options(mysql, MYSQL_INIT_COMMAND, "INSERT INTO t1 VALUES (1),(2),(3)"); + FAIL_IF(!my_test_connect(mysql, hostname, username, password, schema, + port, socketname, + CLIENT_MULTI_STATEMENTS | CLIENT_MULTI_RESULTS), mysql_error(mysql)); + + rc= mysql_query(mysql, "SELECT a FROM t1"); + check_mysql_rc(rc, mysql); + + res= mysql_store_result(mysql); + FAIL_IF(mysql_num_rows(res) != 3, "Expected 3 rows"); + + mysql_free_result(res); + + rc= mysql_query(mysql, "DROP TABLE t1"); + check_mysql_rc(rc, mysql); + mysql_close(mysql); + return OK; +} + +static int test_extended_init_values(MYSQL *unused __attribute__((unused))) +{ + MYSQL *mysql= mysql_init(NULL); + + mysql_options(mysql, MYSQL_DEFAULT_AUTH, "unknown"); + FAIL_IF(strcmp(mysql->options.extension->default_auth, "unknown"), "option not set"); + + mysql_options(mysql, MYSQL_PLUGIN_DIR, "/tmp/foo"); + FAIL_IF(strcmp(mysql->options.extension->plugin_dir, "/tmp/foo"), "option not set"); + + mysql_close(mysql); + return OK; +} + +static int test_reconnect_maxpackage(MYSQL *unused __attribute__((unused))) +{ + int rc; + ulong max_packet= 0; + MYSQL *mysql; + MYSQL_RES *res; + MYSQL_ROW row; + char *query; + my_bool reconnect= 1; + + SKIP_CONNECTION_HANDLER; + + mysql= mysql_init(NULL); + + FAIL_IF(!my_test_connect(mysql, hostname, username, password, schema, + port, socketname, + CLIENT_MULTI_STATEMENTS | CLIENT_MULTI_RESULTS), mysql_error(mysql)); + mysql_options(mysql, MYSQL_OPT_RECONNECT, &reconnect); + + rc= mysql_query(mysql, "SELECT @@max_allowed_packet"); + check_mysql_rc(rc, mysql); + res= mysql_store_result(mysql); + row= mysql_fetch_row(res); + max_packet= atol(row[0]); + diag("max_allowed_packet=%lu", max_packet); + mysql_free_result(res); + + query= (char *)malloc(max_packet + 30); + memset(query, 0, max_packet + 30); + + strcpy(query, "SELECT '"); + memset(query + 8, 'A', max_packet); + strcat(query, "' FROM DUAL"); + + rc= mysql_query(mysql, query); + free(query); + if (!rc) + { + diag("expected error"); + mysql_close(mysql); + return FAIL; + } + else + diag("Error (expected): %s", mysql_error(mysql)); + + rc= mysql_ping(mysql); + /* if the server is under load, poll might not report closed + socket since FIN packet came too late */ + if (rc) + rc= mysql_ping(mysql); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "SELECT @@max_allowed_packet"); + check_mysql_rc(rc, mysql); + res= mysql_store_result(mysql); + row= mysql_fetch_row(res); + max_packet= atol(row[0]); + diag("max_allowed_packet=%lu", max_packet); + mysql_free_result(res); + + + mysql_close(mysql); + return OK; +} + +static int test_compressed(MYSQL *unused __attribute__((unused))) +{ + int rc; + MYSQL *mysql= mysql_init(NULL); + MYSQL_RES *res; + my_bool reconnect= 1; + + mysql_options(mysql, MYSQL_OPT_COMPRESS, (void *)1); + FAIL_IF(!my_test_connect(mysql, hostname, username, password, schema, + port, socketname, + CLIENT_MULTI_STATEMENTS | CLIENT_MULTI_RESULTS), mysql_error(mysql)); + mysql_options(mysql, MYSQL_OPT_RECONNECT, &reconnect); + + rc= mysql_query(mysql, "SHOW VARIABLES"); + check_mysql_rc(rc, mysql); + + if ((res= mysql_store_result(mysql))) + mysql_free_result(res); + + mysql_close(mysql); + + return OK; +} + +struct my_tests_st my_tests[] = { + {"test_conc75", test_conc75, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_conc74", test_conc74, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_conc71", test_conc71, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_conc70", test_conc70, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_conc68", test_conc68, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_compressed", test_compressed, TEST_CONNECTION_NONE, 0, NULL, NULL}, + {"test_reconnect_maxpackage", test_reconnect_maxpackage, TEST_CONNECTION_NONE, 0, NULL, NULL}, + {"basic_connect", basic_connect, TEST_CONNECTION_NONE, 0, NULL, NULL}, + {"use_utf8", use_utf8, TEST_CONNECTION_NEW, 0, opt_utf8, NULL}, + {"client_query", client_query, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_bad_union", test_bad_union, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_select_direct", test_select_direct, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_mysql_insert_id", test_mysql_insert_id, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_bug12001", test_bug12001, TEST_CONNECTION_NEW, CLIENT_MULTI_STATEMENTS, NULL, NULL}, + {"test_status", test_status, TEST_CONNECTION_NEW, CLIENT_MULTI_STATEMENTS, NULL, NULL}, + {"bug_conc1", bug_conc1, TEST_CONNECTION_NEW, 0, NULL, NULL}, + {"test_options_initcmd", test_options_initcmd, TEST_CONNECTION_NONE, 0, NULL, NULL}, + {"test_extended_init_values", test_extended_init_values, TEST_CONNECTION_NONE, 0, NULL, NULL}, + {NULL, NULL, 0, 0, NULL, NULL} +}; + + +int main(int argc, char **argv) +{ + if (argc > 1) + get_options(argc, argv); + + get_envvars(); + + diag("user: %s", username); + + run_tests(my_tests); + + return(exit_status()); +} diff --git a/vendor/MDBC/unittest/libmariadb/bulk1.c b/vendor/MDBC/unittest/libmariadb/bulk1.c new file mode 100644 index 00000000..d220aa31 --- /dev/null +++ b/vendor/MDBC/unittest/libmariadb/bulk1.c @@ -0,0 +1,1100 @@ +/* + Copyright 2011 Kristian Nielsen and Monty Program Ab. + + This file is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this. If not, see . +*/ +#include "my_test.h" +#include "ma_common.h" + +#define TEST_ARRAY_SIZE 1024 + +static my_bool bulk_enabled= 0; + +char *rand_str(size_t length) { + const char charset[] = "0123456789" + "abcdefghijklmnopqrstuvwxyz" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + char *dest= (char *)malloc(length+1); + char *p= dest; + while (length-- > 0) { + *dest++ = charset[rand() % sizeof(charset)]; + } + *dest = '\0'; + return p; +} + +static int check_bulk(MYSQL *mysql) +{ + bulk_enabled= (!(mysql->server_capabilities & CLIENT_MYSQL) && + (mysql->extension->mariadb_server_capabilities & + (MARIADB_CLIENT_STMT_BULK_OPERATIONS >> 32))); + diag("bulk %ssupported", bulk_enabled ? "" : "not "); + return OK; +} + +static int bulk1(MYSQL *mysql) +{ + MYSQL_STMT *stmt= mysql_stmt_init(mysql); + const char *stmt_str= "INSERT INTO bulk1 VALUES (?,?)"; + unsigned int array_size= TEST_ARRAY_SIZE; + int rc; + unsigned int i; + char **buffer; + unsigned long *lengths; + unsigned int *vals; + MYSQL_BIND bind[2]; + MYSQL_RES *res; + MYSQL_ROW row; + unsigned int intval; + + if (!bulk_enabled) + return SKIP; + + rc= mysql_select_db(mysql, "testc"); + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS bulk1"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE bulk1 (a int , b VARCHAR(255))"); + check_mysql_rc(rc, mysql); + + rc= mysql_stmt_prepare(stmt, SL(stmt_str)); + check_stmt_rc(rc, stmt); + + /* allocate memory */ + buffer= calloc(TEST_ARRAY_SIZE, sizeof(char *)); + lengths= (unsigned long *)calloc(sizeof(long), TEST_ARRAY_SIZE); + vals= (unsigned int *)calloc(sizeof(int), TEST_ARRAY_SIZE); + + for (i=0; i < TEST_ARRAY_SIZE; i++) + { + buffer[i]= rand_str(254); + lengths[i]= -1; + vals[i]= i; + } + + memset(bind, 0, sizeof(MYSQL_BIND) * 2); + bind[0].buffer_type= MYSQL_TYPE_LONG; + bind[0].buffer= vals; + bind[1].buffer_type= MYSQL_TYPE_STRING; + bind[1].buffer= (void *)buffer; + bind[1].length= (unsigned long *)lengths; + + rc= mysql_stmt_attr_set(stmt, STMT_ATTR_ARRAY_SIZE, &array_size); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_bind_param(stmt, bind); + check_stmt_rc(rc, stmt); + + for (i=0; i < 100; i++) + { + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + FAIL_IF(mysql_stmt_affected_rows(stmt) != TEST_ARRAY_SIZE, "affected_rows != TEST_ARRAY_SIZE"); + } + + for (i=0; i < array_size; i++) + free(buffer[i]); + + free(buffer); + free(lengths); + free(vals); + + rc= mysql_stmt_close(stmt); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "SELECT COUNT(*) FROM bulk1"); + check_mysql_rc(rc, mysql); + + res= mysql_store_result(mysql); + row= mysql_fetch_row(res); + intval= atoi(row[0]); + mysql_free_result(res); + FAIL_IF(intval != array_size * 100, "Expected 102400 rows"); + + rc= mysql_query(mysql, "SELECT MAX(a) FROM bulk1"); + check_mysql_rc(rc, mysql); + + res= mysql_store_result(mysql); + row= mysql_fetch_row(res); + intval= atoi(row[0]); + mysql_free_result(res); + FAIL_IF(intval != array_size - 1, "Expected max value 1024"); + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS bulk1"); + check_mysql_rc(rc, mysql); + return OK; +} + +static int bulk2(MYSQL *mysql) +{ + MYSQL_STMT *stmt= mysql_stmt_init(mysql); + int rc; + MYSQL_BIND bind[2]; + unsigned int i; + unsigned int array_size=1024; + char indicator[1024]; + long lval[1024]; + + if (!bulk_enabled) + return SKIP; + rc= mysql_query(mysql, "DROP TABLE IF EXISTS bulk2"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE bulk2 (a int default 4, b int default 2)"); + check_mysql_rc(rc, mysql); + + rc= mysql_stmt_prepare(stmt, SL("INSERT INTO bulk2 VALUES (?,1)")); + check_stmt_rc(rc, stmt); + + memset(bind, 0, 2 * sizeof(MYSQL_BIND)); + + for (i=0; i < array_size; i++) + { + indicator[i]= STMT_INDICATOR_DEFAULT; + lval[i]= i; + } + + bind[0].buffer_type= MYSQL_TYPE_LONG; + bind[0].u.indicator= indicator; + bind[1].buffer_type= MYSQL_TYPE_LONG; + bind[1].buffer= &lval; + + rc= mysql_stmt_attr_set(stmt, STMT_ATTR_ARRAY_SIZE, &array_size); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_bind_param(stmt, bind); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + mysql_stmt_close(stmt); + rc= mysql_query(mysql, "DROP TABLE IF EXISTS bulk2"); + check_mysql_rc(rc, mysql); + + return OK; +} + +static int bulk3(MYSQL *mysql) +{ + struct st_bulk3 { + char char_value[20]; + unsigned long length; + int int_value; + }; + + struct st_bulk3 val[3]= {{"Row 1", 5, 1}, + {"Row 02", 6, 2}, + {"Row 003", 7, 3}}; + int rc; + MYSQL_BIND bind[2]; + MYSQL_STMT *stmt= mysql_stmt_init(mysql); + size_t row_size= sizeof(struct st_bulk3); + int array_size= 3; + + if (!bulk_enabled) + return SKIP; + rc= mysql_query(mysql, "DROP TABLE IF EXISTS bulk3"); + check_mysql_rc(rc,mysql); + rc= mysql_query(mysql, "CREATE TABLE bulk3 (name varchar(20), row int)"); + check_mysql_rc(rc,mysql); + + rc= mysql_stmt_prepare(stmt, SL("INSERT INTO bulk3 VALUES (?,?)")); + check_stmt_rc(rc, stmt); + + memset(bind, 0, sizeof(MYSQL_BIND)*2); + + rc= mysql_stmt_attr_set(stmt, STMT_ATTR_ARRAY_SIZE, &array_size); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_attr_set(stmt, STMT_ATTR_ROW_SIZE, &row_size); + check_stmt_rc(rc, stmt); + + bind[0].buffer_type= MYSQL_TYPE_STRING; + bind[0].buffer= &val[0].char_value; + bind[0].length= &val[0].length; + bind[1].buffer_type= MYSQL_TYPE_LONG; + bind[1].buffer= &val[0].int_value; + + rc= mysql_stmt_bind_param(stmt, bind); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + mysql_stmt_close(stmt); + rc= mysql_query(mysql, "DROP TABLE IF EXISTS bulk3"); + check_mysql_rc(rc, mysql); + return OK; +} + +static int bulk4(MYSQL *mysql) +{ + struct st_bulk4 { + char char_value[20]; + char indicator1; + int int_value; + char indicator2; + }; + + struct st_bulk4 val[]= {{"Row 1", STMT_INDICATOR_NTS, 0, STMT_INDICATOR_DEFAULT}, + {"Row 2", STMT_INDICATOR_NTS, 0, STMT_INDICATOR_DEFAULT}, + {"Row 3", STMT_INDICATOR_NTS, 0, STMT_INDICATOR_DEFAULT}}; + int rc; + MYSQL_BIND bind[2]; + MYSQL_RES *res; + MYSQL_STMT *stmt= mysql_stmt_init(mysql); + size_t row_size= sizeof(struct st_bulk4); + int array_size= 3; + unsigned long lengths[3]= {-1, -1, -1}; + + if (!bulk_enabled) + return SKIP; + rc= mysql_query(mysql, "DROP TABLE IF EXISTS bulk4"); + check_mysql_rc(rc,mysql); + rc= mysql_query(mysql, "CREATE TABLE bulk4 (name varchar(20), row int not null default 3)"); + check_mysql_rc(rc,mysql); + + rc= mysql_stmt_prepare(stmt, SL("INSERT INTO bulk4 VALUES (?,?)")); + check_stmt_rc(rc, stmt); + + memset(bind, 0, sizeof(MYSQL_BIND)*2); + + rc= mysql_stmt_attr_set(stmt, STMT_ATTR_ARRAY_SIZE, &array_size); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_attr_set(stmt, STMT_ATTR_ROW_SIZE, &row_size); + check_stmt_rc(rc, stmt); + + bind[0].buffer_type= MYSQL_TYPE_STRING; + bind[0].u.indicator= &val[0].indicator1; + bind[0].buffer= &val[0].char_value; + bind[0].length= lengths; + bind[1].buffer_type= MYSQL_TYPE_LONG; + bind[1].u.indicator= &val[0].indicator2; + + rc= mysql_stmt_bind_param(stmt, bind); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + mysql_stmt_close(stmt); + + rc= mysql_query(mysql, "SELECT * FROM bulk4 WHERE row=3"); + check_mysql_rc(rc, mysql); + res= mysql_store_result(mysql); + rc= (int)mysql_num_rows(res); + mysql_free_result(res); + FAIL_IF(rc != 3, "expected 3 rows"); + rc= mysql_query(mysql, "DROP TABLE IF EXISTS bulk4"); + check_mysql_rc(rc, mysql); + return OK; +} + +static int bulk_null(MYSQL *mysql) +{ + MYSQL_STMT *stmt= mysql_stmt_init(mysql); + int rc; + MYSQL_BIND bind[2]; + unsigned int param_count= 2; + unsigned int array_size= 2; + unsigned long lengths[2]= {-1, -1}; + char **buf= calloc(1, 2 * sizeof(char *)); + + if (!bulk_enabled) + { + free(buf); + return SKIP; + } + + buf[0]= strdup("foo"); + buf[1]= strdup("foobar"); + + rc= mariadb_stmt_execute_direct(stmt, "DROP TABLE IF EXISTS bulk_null", -1); + check_stmt_rc(rc, stmt); + + rc= mariadb_stmt_execute_direct(stmt, "CREATE TABLE bulk_null (a int not null auto_increment primary key, b varchar(20))", -1); + check_stmt_rc(rc, stmt); + + memset(bind, 0, 2 * sizeof(MYSQL_BIND)); + bind[0].buffer_type= MYSQL_TYPE_NULL; + bind[1].buffer_type= MYSQL_TYPE_STRING; + bind[1].buffer= buf; + bind[1].length= lengths; + + mysql_stmt_close(stmt); + stmt= mysql_stmt_init(mysql); + + rc= mysql_stmt_attr_set(stmt, STMT_ATTR_PREBIND_PARAMS, ¶m_count); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_attr_set(stmt, STMT_ATTR_ARRAY_SIZE, &array_size); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_bind_param(stmt, bind); + check_stmt_rc(rc, stmt); + + rc= mariadb_stmt_execute_direct(stmt, "INSERT INTO bulk_null VALUES (?, ?)", -1); + check_stmt_rc(rc, stmt); + + mysql_stmt_close(stmt); + free(buf[0]); + free(buf[1]); + free(buf); + rc= mysql_query(mysql, "DROP TABLE IF EXISTS bulk_null"); + check_mysql_rc(rc, mysql); + return OK; +} + +static int bulk5(MYSQL *mysql) +{ + MYSQL_STMT *stmt= mysql_stmt_init(mysql); + MYSQL_BIND bind[3]; + MYSQL_RES *res; + unsigned long rows; + unsigned int array_size= 5; + int rc; + int intval[]= {12,13,14,15,16}; + int id[]= {1,2,3,4,5}; + + if (!bulk_enabled) + return SKIP; + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS bulk5"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE bulk5 (a int, b int)"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "INSERT INTO bulk5 VALUES (1,1), (2,2), (3,3), (4,4), (5,5)"); + check_mysql_rc(rc, mysql); + + + memset(bind, 0, sizeof(MYSQL_BIND) * 3); + + rc= mysql_stmt_prepare(stmt, SL("UPDATE bulk5 SET a=? WHERE a=?")); + check_stmt_rc(rc, stmt); + + bind[0].buffer_type= MYSQL_TYPE_LONG; + bind[0].buffer= &intval; + bind[1].buffer_type= MYSQL_TYPE_LONG; + bind[1].buffer= &id; + + rc= mysql_stmt_attr_set(stmt, STMT_ATTR_ARRAY_SIZE, &array_size); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_bind_param(stmt, bind); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + mysql_stmt_close(stmt); + + rc= mysql_query(mysql, "SELECT * FROM bulk5 WHERE a=b+11"); + check_mysql_rc(rc, mysql); + + res= mysql_store_result(mysql); + rows= (unsigned long)mysql_num_rows(res); + diag("rows: %lu", rows); + mysql_free_result(res); + + FAIL_IF(rows != 5, "expected 5 rows"); + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS bulk5"); + check_mysql_rc(rc, mysql); + + return OK; +} + +static int bulk6(MYSQL *mysql) +{ + MYSQL_STMT *stmt= mysql_stmt_init(mysql); + MYSQL_BIND bind[3]; + MYSQL_RES *res; + unsigned long rows; + unsigned int array_size= 5; + int rc; + int intval[]= {12,13,14,15,16}; + int id[]= {1,2,3,4,5}; + char indicator[5]; + + if (!bulk_enabled) + return SKIP; + memset(indicator, STMT_INDICATOR_IGNORE, 5); + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS bulk6"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE bulk6 (a int, b int default 4)"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "INSERT INTO bulk6 VALUES (1,1), (2,2), (3,3), (4,4), (5,5)"); + check_mysql_rc(rc, mysql); + + + memset(bind, 0, sizeof(MYSQL_BIND) * 3); + + /* 1st case: UPDATE */ + rc= mysql_stmt_prepare(stmt, SL("UPDATE bulk6 SET a=?, b=? WHERE a=?")); + check_stmt_rc(rc, stmt); + + bind[0].buffer_type= MYSQL_TYPE_LONG; + bind[0].buffer= &intval; + bind[1].buffer_type= MYSQL_TYPE_LONG; + bind[1].buffer= &intval; + bind[1].u.indicator= indicator; + bind[2].buffer_type= MYSQL_TYPE_LONG; + bind[2].buffer= &id; + + rc= mysql_stmt_attr_set(stmt, STMT_ATTR_ARRAY_SIZE, &array_size); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_bind_param(stmt, bind); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + mysql_stmt_close(stmt); + + rc= mysql_query(mysql, "SELECT * FROM bulk6 WHERE a=b+11"); + check_mysql_rc(rc, mysql); + + res= mysql_store_result(mysql); + rows= (unsigned long)mysql_num_rows(res); + mysql_free_result(res); + + FAIL_IF(rows != 5, "expected 5 rows"); + + /* 2nd case: INSERT - ignore indicator should be same as default */ + rc= mysql_query(mysql, "DELETE FROM bulk6"); + check_mysql_rc(rc, mysql); + + stmt= mysql_stmt_init(mysql); + rc= mysql_stmt_prepare(stmt, SL("INSERT INTO bulk6 VALUES (?,?)")); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_attr_set(stmt, STMT_ATTR_ARRAY_SIZE, &array_size); + check_stmt_rc(rc, stmt); + + /* this should insert 5 default values (=4) */ + memset(indicator, STMT_INDICATOR_DEFAULT, 5); + rc= mysql_stmt_bind_param(stmt, bind); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + /* this should insert 5 default values (=4) */ + memset(indicator, STMT_INDICATOR_IGNORE, 5); + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + mysql_stmt_close(stmt); + + rc= mysql_query(mysql, "SELECT * FROM bulk6 WHERE b=4"); + check_mysql_rc(rc, mysql); + + res= mysql_store_result(mysql); + rows= (unsigned long)mysql_num_rows(res); + mysql_free_result(res); + + FAIL_IF(rows != 10, "expected 10 rows"); + rc= mysql_query(mysql, "DROP TABLE IF EXISTS bulk6"); + check_mysql_rc(rc, mysql); + + return OK; +} + +static int test_conc243(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + MYSQL_BIND bind[3]; + MYSQL_RES *result; + MYSQL_ROW row; + + struct st_data { + unsigned long id; + char id_ind; + char forename[30]; + char forename_ind; + char surname[30]; + char surname_ind; + }; + + struct st_data data[]= { + {0, STMT_INDICATOR_NULL, "Monty", STMT_INDICATOR_NTS, "Widenius", STMT_INDICATOR_NTS}, + {0, STMT_INDICATOR_NULL, "David", STMT_INDICATOR_NTS, "Axmark", STMT_INDICATOR_NTS}, + {0, STMT_INDICATOR_NULL, "default", STMT_INDICATOR_DEFAULT, "N.N.", STMT_INDICATOR_NTS}, + }; + + unsigned int array_size= 1; + size_t row_size= sizeof(struct st_data); + int rc; + + if (!bulk_enabled) + return SKIP; + rc= mysql_query(mysql, "DROP TABLE IF EXISTS bulk_example2"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE bulk_example2 (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,"\ + "forename CHAR(30) NOT NULL DEFAULT 'unknown', surname CHAR(30))"); + check_mysql_rc(rc, mysql); + + stmt= mysql_stmt_init(mysql); + rc= mysql_stmt_prepare(stmt, SL("INSERT INTO bulk_example2 VALUES (?,?,?)")); + check_stmt_rc(rc, stmt); + + memset(bind, 0, sizeof(MYSQL_BIND) * 3); + + /* We autogenerate id's, so all indicators are STMT_INDICATOR_NULL */ + bind[0].u.indicator= &data[0].id_ind; + bind[0].buffer_type= MYSQL_TYPE_LONG; + + bind[1].buffer= &data[0].forename; + bind[1].buffer_type= MYSQL_TYPE_STRING; + bind[1].u.indicator= &data[0].forename_ind; + + bind[2].buffer_type= MYSQL_TYPE_STRING; + bind[2].buffer= &data[0].surname; + bind[2].u.indicator= &data[0].surname_ind; + + /* set array size */ + mysql_stmt_attr_set(stmt, STMT_ATTR_ARRAY_SIZE, &array_size); + + /* set row size */ + mysql_stmt_attr_set(stmt, STMT_ATTR_ROW_SIZE, &row_size); + + /* bind parameter */ + mysql_stmt_bind_param(stmt, bind); + + /* execute */ + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + mysql_stmt_close(stmt); + + rc= mysql_query(mysql, "SELECT forename, surname FROM bulk_example2"); + check_mysql_rc(rc, mysql); + + result= mysql_store_result(mysql); + FAIL_IF(!result || !mysql_num_rows(result), "Invalid resultset"); + row = mysql_fetch_row(result); + if (strcmp(row[0], "Monty") || strcmp(row[1], "Widenius")) + { + mysql_free_result(result); + diag("Wrong values"); + return FAIL; + } + mysql_free_result(result); + rc= mysql_query(mysql, "DROP TABLE bulk_example2"); + check_mysql_rc(rc, mysql); + return OK; +} +static int bulk7(MYSQL *mysql) +{ + MYSQL_STMT *stmt= mysql_stmt_init(mysql); + int rc; + int array_size= 5; + + 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)"); + check_mysql_rc(rc, mysql); + + rc= mysql_stmt_prepare(stmt, SL("UPDATE t1 SET a=a+1")); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_attr_set(stmt, STMT_ATTR_ARRAY_SIZE, &array_size); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_execute(stmt); + + FAIL_IF(!rc, "Error expected: Bulk operation without parameters is not supported"); + diag("%s", mysql_stmt_error(stmt)); + + mysql_stmt_close(stmt); + rc= mysql_query(mysql, "DROP TABLE t1"); + check_mysql_rc(rc, mysql); + + return OK; +} + +static int test_char_conv1(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + int rc; + MYSQL_BIND bind_in, bind_out; + char buffer[100]; + char outbuffer[100]; + + if (!bulk_enabled) + return SKIP; + stmt= mysql_stmt_init(mysql); + strcpy (buffer, "\xC3\x82\xC3\x83\xC3\x84\x00"); + + rc= mysql_query(mysql, "SET NAMES UTF8"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "DROP TABLE IF EXISTS char_conv"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "CREATE TABLE char_conv (a varchar(20)) CHARSET=latin1"); + check_mysql_rc(rc, mysql); + + rc= mysql_stmt_prepare(stmt, SL("INSERT INTO char_conv VALUES (?)")); + check_stmt_rc(rc, stmt); + + memset(&bind_in, 0, sizeof(MYSQL_BIND)); + bind_in.buffer_type= MYSQL_TYPE_STRING; + bind_in.buffer_length= -1; + bind_in.buffer= &buffer; + + rc= mysql_stmt_bind_param(stmt, &bind_in); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + mysql_stmt_close(stmt); + + stmt= mysql_stmt_init(mysql); + + rc= mysql_stmt_prepare(stmt, SL("SELECT a from char_conv")); + check_stmt_rc(rc, stmt); + + memset(&bind_out, 0, sizeof(MYSQL_BIND)); + bind_out.buffer_type= MYSQL_TYPE_STRING; + bind_out.buffer_length= 100; + bind_out.buffer= outbuffer; + + rc= mysql_stmt_bind_result(stmt, &bind_out); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_fetch(stmt); + FAIL_IF(rc == MYSQL_NO_DATA, "Error"); + + mysql_stmt_close(stmt); + + + if (strcmp(buffer, outbuffer)) + { + diag("Error: Expected '%s' instead of '%s'", buffer, outbuffer); + return FAIL; + } + + rc= mysql_query(mysql, "DROP TABLE char_conv"); + check_mysql_rc(rc, mysql); + + return OK; +} + + +static int test_char_conv2(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + int rc; + int array_size= 1; + MYSQL_BIND bind_in, bind_out; + char *buffer[1]; + char outbuffer[100]; + + if (!bulk_enabled) + return SKIP; + + stmt= mysql_stmt_init(mysql); + buffer[0]= calloc(1, 7); + strcpy (buffer[0], "\xC3\x82\xC3\x83\xC3\x84\x00"); + + rc= mysql_query(mysql, "SET NAMES UTF8"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "DROP TABLE IF EXISTS char_conv"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "CREATE TABLE char_conv (a varchar(20)) CHARSET=latin1"); + check_mysql_rc(rc, mysql); + + rc= mysql_stmt_prepare(stmt, SL("INSERT INTO char_conv VALUES (?)")); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_attr_set(stmt, STMT_ATTR_ARRAY_SIZE, &array_size); + check_stmt_rc(rc, stmt); + + memset(&bind_in, 0, sizeof(MYSQL_BIND)); + bind_in.buffer_type= MYSQL_TYPE_STRING; + bind_in.buffer_length= -1; + bind_in.buffer= &buffer; + + rc= mysql_stmt_bind_param(stmt, &bind_in); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + mysql_stmt_close(stmt); + + stmt= mysql_stmt_init(mysql); + + rc= mysql_stmt_prepare(stmt, SL("SELECT a from char_conv")); + check_stmt_rc(rc, stmt); + + memset(&bind_out, 0, sizeof(MYSQL_BIND)); + bind_out.buffer_type= MYSQL_TYPE_STRING; + bind_out.buffer_length= 100; + bind_out.buffer= outbuffer; + + rc= mysql_stmt_bind_result(stmt, &bind_out); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_fetch(stmt); + FAIL_IF(rc == MYSQL_NO_DATA, "Error"); + + mysql_stmt_close(stmt); + + + if (strcmp(buffer[0], outbuffer)) + { + diag("Error: Expected '%s' instead of '%s'", buffer[0], outbuffer); + return FAIL; + } + free(buffer[0]); + + rc= mysql_query(mysql, "DROP TABLE char_conv"); + check_mysql_rc(rc, mysql); + + return OK; +} + + +static int bulk_skip_row(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + MYSQL_BIND bind[3]; + MYSQL_RES *result; + MYSQL_ROW row; + + struct st_data { + unsigned long id; + char id_ind; + char forename[30]; + char forename_ind; + char surname[30]; + char surname_ind; + }; + + struct st_data data[]={ + { 0, STMT_INDICATOR_NULL, "Monty", STMT_INDICATOR_NTS, "Widenius", STMT_INDICATOR_IGNORE_ROW }, + { 0, STMT_INDICATOR_IGNORE_ROW, "David", STMT_INDICATOR_NTS, "Axmark", STMT_INDICATOR_NTS }, + { 0, STMT_INDICATOR_NULL, "default", STMT_INDICATOR_DEFAULT, "N.N.", STMT_INDICATOR_NTS }, + }; + + unsigned int array_size= 3; + size_t row_size= sizeof(struct st_data); + int rc; + + if (!bulk_enabled) + return SKIP; + rc= mysql_query(mysql, "DROP TABLE IF EXISTS bulk_example2"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE bulk_example2 (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,"\ + "forename CHAR(30) NOT NULL DEFAULT 'unknown', surname CHAR(30))"); + check_mysql_rc(rc, mysql); + + stmt= mysql_stmt_init(mysql); + rc= mysql_stmt_prepare(stmt, SL("INSERT INTO bulk_example2 VALUES (?,?,?)")); + check_stmt_rc(rc, stmt); + + memset(bind, 0, sizeof(MYSQL_BIND) * 3); + + /* We autogenerate id's, so all indicators are STMT_INDICATOR_NULL */ + bind[0].u.indicator= &data[0].id_ind; + bind[0].buffer_type= MYSQL_TYPE_LONG; + + bind[1].buffer= &data[0].forename; + bind[1].buffer_type= MYSQL_TYPE_STRING; + bind[1].u.indicator= &data[0].forename_ind; + + bind[2].buffer_type= MYSQL_TYPE_STRING; + bind[2].buffer= &data[0].surname; + bind[2].u.indicator= &data[0].surname_ind; + + /* set array size */ + mysql_stmt_attr_set(stmt, STMT_ATTR_ARRAY_SIZE, &array_size); + + /* set row size */ + mysql_stmt_attr_set(stmt, STMT_ATTR_ROW_SIZE, &row_size); + + /* bind parameter */ + mysql_stmt_bind_param(stmt, bind); + + /* execute */ + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + mysql_stmt_close(stmt); + + rc= mysql_query(mysql, "SELECT forename, surname FROM bulk_example2"); + check_mysql_rc(rc, mysql); + + result= mysql_store_result(mysql); + FAIL_IF(!result || mysql_num_rows(result) != 1, "Invalid resultset"); + + row = mysql_fetch_row(result); + if (strcmp(row[0], "unknown") || strcmp(row[1], "N.N.")) + { + mysql_free_result(result); + diag("Wrong values"); + return FAIL; + } + mysql_free_result(result); + rc= mysql_query(mysql, "DROP TABLE bulk_example2"); + check_mysql_rc(rc, mysql); + return OK; +} + +static int bulk_null_null(MYSQL *mysql) +{ + struct st_bulk4 { + char char_value[20]; + char indicator1; + int int_value; + char indicator2; + double double_value; + char indicator3; + char time_value[20]; + char indicator4; + char decimal_value[4]; + char indicator5; + }; + + struct st_bulk4 val[]= {{"3", STMT_INDICATOR_NTS, + 3, STMT_INDICATOR_NONE, + 3.0, STMT_INDICATOR_NONE, + "00:00:00", STMT_INDICATOR_NTS, + "3.0", STMT_INDICATOR_NTS}, + {"3", STMT_INDICATOR_NULL, + 3, STMT_INDICATOR_NULL, + 3.0, STMT_INDICATOR_NULL, + "00:00:00", STMT_INDICATOR_NULL, + "3.0", STMT_INDICATOR_NULL}, + {"3", STMT_INDICATOR_NTS, + 3, STMT_INDICATOR_NONE, + 3.0, STMT_INDICATOR_NONE, + "00:00:00", STMT_INDICATOR_NTS, + "3.0", STMT_INDICATOR_NTS}}; + int rc; + MYSQL_BIND bind[5]; + MYSQL_RES *res; + MYSQL_STMT *stmt= mysql_stmt_init(mysql); + size_t row_size= sizeof(struct st_bulk4); + int array_size= 3; + unsigned long server_version= mysql_get_server_version(mysql); + unsigned long lengths[3]= {-1, -1, -1}; + + if (!bulk_enabled) + return SKIP; + + if (server_version > 100300 && + server_version < 100305) + return SKIP; + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS bulk_null"); + check_mysql_rc(rc,mysql); + rc= mysql_query(mysql, "CREATE TABLE bulk_null " + "(s varchar(20), " + " i int, " + " d double, " + " t time, " + " c decimal(3,1))"); + check_mysql_rc(rc,mysql); + + rc= mysql_stmt_prepare(stmt, "INSERT INTO bulk_null VALUES (?,?,?,?,?)", -1); + check_stmt_rc(rc, stmt); + + memset(bind, 0, sizeof(MYSQL_BIND)*2); + + rc= mysql_stmt_attr_set(stmt, STMT_ATTR_ARRAY_SIZE, &array_size); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_attr_set(stmt, STMT_ATTR_ROW_SIZE, &row_size); + check_stmt_rc(rc, stmt); + + bind[0].buffer_type= MYSQL_TYPE_STRING; + bind[0].u.indicator= &val[0].indicator1; + bind[0].buffer= &val[0].char_value; + bind[0].length= lengths; + bind[1].buffer_type= MYSQL_TYPE_LONG; + bind[1].buffer= &val[0].int_value; + bind[1].u.indicator= &val[0].indicator2; + bind[2].buffer_type= MYSQL_TYPE_DOUBLE; + bind[2].buffer= &val[0].double_value; + bind[2].u.indicator= &val[0].indicator3; + bind[3].buffer_type= MYSQL_TYPE_STRING; + bind[3].u.indicator= &val[0].indicator4; + bind[3].buffer= &val[0].time_value; + bind[3].length= lengths; + bind[4].buffer_type= MYSQL_TYPE_NEWDECIMAL; + bind[4].u.indicator= &val[0].indicator5; + bind[4].buffer= &val[0].decimal_value; + bind[4].length= lengths; + + rc= mysql_stmt_bind_param(stmt, bind); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + mysql_stmt_close(stmt); + + rc= mysql_query(mysql, "SELECT * FROM bulk_null WHERE s='3'"); + check_mysql_rc(rc, mysql); + res= mysql_store_result(mysql); + rc= (int)mysql_num_rows(res); + mysql_free_result(res); + FAIL_IF(rc != 2, "expected 2 rows"); + + rc= mysql_query(mysql, "SELECT * FROM bulk_null WHERE i=3"); + check_mysql_rc(rc, mysql); + res= mysql_store_result(mysql); + rc= (int)mysql_num_rows(res); + mysql_free_result(res); + FAIL_IF(rc != 2, "expected 2 rows"); + + rc= mysql_query(mysql, "SELECT * FROM bulk_null WHERE d=3.0"); + check_mysql_rc(rc, mysql); + res= mysql_store_result(mysql); + rc= (int)mysql_num_rows(res); + mysql_free_result(res); + FAIL_IF(rc != 2, "expected 2 rows"); + + rc= mysql_query(mysql, "SELECT * FROM bulk_null WHERE t='00:00:00'"); + check_mysql_rc(rc, mysql); + res= mysql_store_result(mysql); + rc= (int)mysql_num_rows(res); + mysql_free_result(res); + FAIL_IF(rc != 2, "expected 2 rows"); + + rc= mysql_query(mysql, "SELECT * FROM bulk_null WHERE c=3.0"); + check_mysql_rc(rc, mysql); + res= mysql_store_result(mysql); + rc= (int)mysql_num_rows(res); + mysql_free_result(res); + FAIL_IF(rc != 2, "expected 2 rows"); + + rc= mysql_query(mysql, "DROP TABLE bulk_null"); + check_mysql_rc(rc, mysql); + return OK; +} + +static int test_mdev16593(MYSQL *mysql) +{ + int i; + int rc; + MYSQL_BIND bind[2]; + unsigned int array_size= 2; + int val_a[2]= {1,2}; + char indicators[2]= {STMT_INDICATOR_NULL, STMT_INDICATOR_NULL}; + const char *testcase[]= {"MYSQL_TYPE_LONG", "MYSQL_TYPE_NULL", "STMT_INDICATOR_NULL"}; + + diag("waiting for server fix"); + return SKIP; + + for (i=0; i < 3; i++) + { + MYSQL_RES *res; + MYSQL_ROW row; + MYSQL_STMT *stmt= mysql_stmt_init(mysql); + rc= mysql_query(mysql, "CREATE OR REPLACE TABLE t1 (a int not null auto_increment primary key, b int)"); + check_mysql_rc(rc, mysql); + + memset(&bind, 0, sizeof(MYSQL_BIND)); + switch (i) { + case 0: + bind[0].buffer_type= MYSQL_TYPE_LONG; + break; + case 1: + bind[0].buffer_type= MYSQL_TYPE_NULL; + break; + case 2: + bind[0].buffer_type= MYSQL_TYPE_LONG; + bind[0].u.indicator= indicators; + break; + } + bind[0].buffer= val_a; + bind[1].buffer_type= MYSQL_TYPE_LONG; + bind[1].buffer= val_a; + + rc= mysql_stmt_prepare(stmt, SL("insert into t1 values(?,?)")); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_attr_set(stmt, STMT_ATTR_ARRAY_SIZE, &array_size); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_bind_param(stmt, bind); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_query(mysql, "COMMIT"); + check_mysql_rc(rc, mysql); + + diag("Insert id with buffer_type %s: %lld", + testcase[i], + mysql_stmt_insert_id(stmt)); + + rc= mysql_query(mysql, "SELECT max(a) FROM t1"); + check_mysql_rc(rc, mysql); + + res= mysql_store_result(mysql); + row= mysql_fetch_row(res); + diag("Max value for t1.a=%s", row[0]); + mysql_free_result(res); + + mysql_stmt_close(stmt); + } + return OK; +} + +struct my_tests_st my_tests[] = { + {"check_bulk", check_bulk, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_mdev16593", test_mdev16593, TEST_CONNECTION_NEW, 0, NULL, NULL}, + {"bulk_null_null", bulk_null_null, TEST_CONNECTION_NEW, 0, NULL, NULL}, + {"test_char_conv1", test_char_conv1, TEST_CONNECTION_NEW, 0, NULL, NULL}, + {"test_char_conv2", test_char_conv2, TEST_CONNECTION_NEW, 0, NULL, NULL}, + {"test_conc243", test_conc243, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"update_no_param", bulk7, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"bulk5", bulk5, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"bulk6", bulk6, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"bulk1", bulk1, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"bulk2", bulk2, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"bulk3", bulk3, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"bulk4", bulk4, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"bulk_null", bulk_null, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"bulk_skip_row", bulk_skip_row, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {NULL, NULL, 0, 0, NULL, NULL} +}; + +int main(int argc, char **argv) +{ + if (argc > 1) + get_options(argc, argv); + + get_envvars(); + + run_tests(my_tests); + + return(exit_status()); +} diff --git a/vendor/MDBC/unittest/libmariadb/charset.c b/vendor/MDBC/unittest/libmariadb/charset.c new file mode 100644 index 00000000..ecc3bb65 --- /dev/null +++ b/vendor/MDBC/unittest/libmariadb/charset.c @@ -0,0 +1,846 @@ +/* +Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. + +The MySQL Connector/C is licensed under the terms of the GPLv2 +, like most +MySQL Connectors. There are special exceptions to the terms and +conditions of the GPLv2 as it is applied to this software, see the +FLOSS License Exception +. + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published +by the Free Software Foundation; version 2 of the License. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include "my_test.h" + +/* + test gbk charset escaping + + The important part is that 0x27 (') is the second-byte in a invalid + two-byte GBK character here. But 0xbf5c is a valid GBK character, so + it needs to be escaped as 0x5cbf27 + +*/ +#define TEST_BUG8378_IN "\xef\xbb\xbf\x27\xbf\x10" +#define TEST_BUG8378_OUT "\xef\xbb\x5c\xbf\x5c\x27\x5c\xbf\x10" + +/* set connection options */ +struct my_option_st opt_bug8378[] = { + {MYSQL_SET_CHARSET_NAME, (char *) "gbk"}, + {0, NULL} +}; + +int bug_8378(MYSQL *mysql) { + int rc, len; + char out[9], buf[256]; + MYSQL_RES *res; + MYSQL_ROW row; + + len= mysql_real_escape_string(mysql, out, TEST_BUG8378_IN, 4); + FAIL_IF(memcmp(out, TEST_BUG8378_OUT, len), "wrong result"); + + sprintf(buf, "SELECT '%s' FROM DUAL", TEST_BUG8378_OUT); + + rc= mysql_query(mysql, buf); + check_mysql_rc(rc, mysql); + + if ((res= mysql_store_result(mysql))) { + row= mysql_fetch_row(res); + if (memcmp(row[0], TEST_BUG8378_IN, 4)) { + mysql_free_result(res); + return FAIL; + } + mysql_free_result(res); + } else + return FAIL; + + return OK; +} + +int test_client_character_set(MYSQL *mysql) +{ + MY_CHARSET_INFO cs; + char *csname= (char*) "latin2"; + char *csdefault= (char*)mysql_character_set_name(mysql); + + + FAIL_IF(mysql_set_character_set(mysql, csname), mysql_error(mysql)); + + mysql_get_character_set_info(mysql, &cs); + + FAIL_IF(strcmp(cs.csname, "latin2") || strcmp(cs.name, "latin2_general_ci"), + "Character set != latin2"); + FAIL_IF(mysql_set_character_set(mysql, csdefault), mysql_error(mysql)); + + return OK; +} + +/* + * Regression test for bug #10214 + * + * Test escaping with NO_BACKSLASH_ESCAPES + * + */ +int bug_10214(MYSQL *mysql) +{ + int len, rc; + char out[8]; + + /* reset sql_mode */ + rc= mysql_query(mysql, "SET sql_mode=''"); + check_mysql_rc(rc, mysql); + + len= mysql_real_escape_string(mysql, out, "a'b\\c", 5); + FAIL_IF(memcmp(out, "a\\'b\\\\c", len), "wrong result"); + + rc= mysql_query(mysql, "set sql_mode='NO_BACKSLASH_ESCAPES'"); + check_mysql_rc(rc, mysql); + FAIL_IF(!(mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES), + "wrong server status: NO_BACKSLASH_ESCAPES not set"); + + len= mysql_real_escape_string(mysql, out, "a'b\\c", 5); + FAIL_IF(memcmp(out, "a''b\\c", len), "wrong result"); + + return OK; +} + +/* + * simple escaping of special chars + */ +int test_escaping(MYSQL *mysql) +{ + int i= 0, rc, len; + char out[20]; + const char *escape_chars[] = {"'", "\x0", "\n", "\r", "\\", "\0", NULL}; + + /* reset sql_mode, mysql_change_user call doesn't reset it */ + rc= mysql_query(mysql, "SET sql_mode=''"); + check_mysql_rc(rc, mysql); + + while (escape_chars[i]) { + len= mysql_real_escape_string(mysql, out, escape_chars[i], 1); + FAIL_IF(len < 2, "Len < 2"); + i++; + } + + return OK; +} + +/* + * server doesn't reset sql_mode after COM_CHANGE_USER + */ +int bug_41785(MYSQL *mysql) +{ + char out[10]; + int rc, len; + + len= mysql_real_escape_string(mysql, out, "\\", 1); + FAIL_IF(len != 2, "len != 2"); + + rc= mysql_query(mysql, "SET SQL_MODE=NO_BACKSLASH_ESCAPES"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "SET sql_mode=''"); + check_mysql_rc(rc, mysql); + + mysql_change_user(mysql, "root", "", "test"); + + len= mysql_real_escape_string(mysql, out, "\\", 1); + FAIL_IF(len != 2, "len != 2"); + + return OK; +} + +static int test_conversion(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + const char *stmt_text; + int rc; + MYSQL_BIND my_bind[1]; + uchar buff[4]; + ulong length; + + stmt_text= "DROP TABLE IF EXISTS t1"; + rc= mysql_real_query(mysql, SL(stmt_text)); + check_mysql_rc(rc, mysql); + stmt_text= "CREATE TABLE t1 (a TEXT) DEFAULT CHARSET latin1"; + rc= mysql_real_query(mysql, SL(stmt_text)); + check_mysql_rc(rc, mysql); + stmt_text= "SET character_set_connection=utf8, character_set_client=utf8, " + " character_set_results=latin1"; + rc= mysql_real_query(mysql, SL(stmt_text)); + check_mysql_rc(rc, mysql); + + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + stmt_text= "INSERT INTO t1 (a) VALUES (?)"; + rc= mysql_stmt_prepare(stmt, SL(stmt_text)); + check_stmt_rc(rc, stmt); + + memset(my_bind, '\0', sizeof(my_bind)); + my_bind[0].buffer= (char*) buff; + my_bind[0].length= &length; + my_bind[0].buffer_type= MYSQL_TYPE_STRING; + + mysql_stmt_bind_param(stmt, my_bind); + + buff[0]= (uchar) 0xC3; + buff[1]= (uchar) 0xA0; + length= 2; + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + stmt_text= "SELECT a FROM t1"; + rc= mysql_stmt_prepare(stmt, SL(stmt_text)); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + my_bind[0].buffer_length= sizeof(buff); + mysql_stmt_bind_result(stmt, my_bind); + + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + FAIL_UNLESS(length == 1, "length != 1"); + FAIL_UNLESS(buff[0] == 0xE0, "buff[0] != 0xE0"); + rc= mysql_stmt_fetch(stmt); + FAIL_UNLESS(rc == MYSQL_NO_DATA, "rc != MYSQL_NO_DATA"); + + mysql_stmt_close(stmt); + stmt_text= "DROP TABLE t1"; + rc= mysql_real_query(mysql, SL(stmt_text)); + check_mysql_rc(rc, mysql); + stmt_text= "SET NAMES DEFAULT"; + rc= mysql_real_query(mysql, SL(stmt_text)); + check_mysql_rc(rc, mysql); + + return OK; +} + +static int test_bug27876(MYSQL *mysql) +{ + int rc; + MYSQL_RES *result; + + uchar utf8_func[] = + { + 0xd1, 0x84, 0xd1, 0x83, 0xd0, 0xbd, 0xd0, 0xba, + 0xd1, 0x86, 0xd0, 0xb8, 0xd0, 0xb9, 0xd0, 0xba, + 0xd0, 0xb0, + 0x00 + }; + + uchar utf8_param[] = + { + 0xd0, 0xbf, 0xd0, 0xb0, 0xd1, 0x80, 0xd0, 0xb0, + 0xd0, 0xbc, 0xd0, 0xb5, 0xd1, 0x82, 0xd1, 0x8a, + 0xd1, 0x80, 0x5f, 0xd0, 0xb2, 0xd0, 0xb5, 0xd1, + 0x80, 0xd1, 0x81, 0xd0, 0xb8, 0xd1, 0x8f, + 0x00 + }; + + char query[500]; + + rc= mysql_query(mysql, "set names utf8"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "select version()"); + check_mysql_rc(rc, mysql); + result= mysql_store_result(mysql); + FAIL_IF(!result, "Invalid result set"); + mysql_free_result(result); + + sprintf(query, "DROP FUNCTION IF EXISTS %s", (char*) utf8_func); + rc= mysql_query(mysql, query); + check_mysql_rc(rc, mysql); + + sprintf(query, + "CREATE FUNCTION %s( %s VARCHAR(25))" + " RETURNS VARCHAR(25) DETERMINISTIC RETURN %s", + (char*) utf8_func, (char*) utf8_param, (char*) utf8_param); + rc= mysql_query(mysql, query); + check_mysql_rc(rc, mysql); + sprintf(query, "SELECT %s(VERSION())", (char*) utf8_func); + rc= mysql_query(mysql, query); + check_mysql_rc(rc, mysql); + result= mysql_store_result(mysql); + FAIL_IF(!result, "Invalid result set"); + mysql_free_result(result); + + sprintf(query, "DROP FUNCTION %s", (char*) utf8_func); + rc= mysql_query(mysql, query); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "set names default"); + check_mysql_rc(rc, mysql); + return OK; +} + +static int test_ps_i18n(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + int rc; + const char *stmt_text; + MYSQL_BIND bind_array[2]; + + /* Represented as numbers to keep UTF8 tools from clobbering them. */ + const char *koi8= "\xee\xd5\x2c\x20\xda\xc1\x20\xd2\xd9\xc2\xc1\xcc\xcb\xd5"; + const char *cp1251= "\xcd\xf3\x2c\x20\xe7\xe0\x20\xf0\xfb\xe1\xe0\xeb\xea\xf3"; + char buf1[16], buf2[16]; + ulong buf1_len, buf2_len; + + stmt_text= "DROP TABLE IF EXISTS t1"; + rc= mysql_real_query(mysql, SL(stmt_text)); + check_mysql_rc(rc, mysql); + + /* + Create table with binary columns, set session character set to cp1251, + client character set to koi8, and make sure that there is conversion + on insert and no conversion on select + */ + + stmt_text= "CREATE TABLE t1 (c1 VARBINARY(255), c2 VARBINARY(255))"; + rc= mysql_real_query(mysql, SL(stmt_text)); + check_mysql_rc(rc, mysql); + + stmt_text= "SET CHARACTER_SET_CLIENT=koi8r, " + "CHARACTER_SET_CONNECTION=cp1251, " + "CHARACTER_SET_RESULTS=koi8r"; + + rc= mysql_real_query(mysql, SL(stmt_text)); + check_mysql_rc(rc, mysql); + + memset(bind_array, '\0', sizeof(bind_array)); + bind_array[0].buffer_type= MYSQL_TYPE_STRING; + bind_array[0].buffer= (void *) koi8; + bind_array[0].buffer_length= (unsigned long)strlen(koi8); + + bind_array[1].buffer_type= MYSQL_TYPE_STRING; + bind_array[1].buffer= (void *) koi8; + bind_array[1].buffer_length= (unsigned long)strlen(koi8); + + stmt= mysql_stmt_init(mysql); + check_stmt_rc(rc, stmt); + + stmt_text= "INSERT INTO t1 (c1, c2) VALUES (?, ?)"; + + rc= mysql_stmt_prepare(stmt, SL(stmt_text)); + check_stmt_rc(rc, stmt); + mysql_stmt_bind_param(stmt, bind_array); + check_stmt_rc(rc, stmt); + +// mysql_stmt_send_long_data(stmt, 0, koi8, strlen(koi8)); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + stmt_text= "SELECT c1, c2 FROM t1"; + + /* c1 and c2 are binary so no conversion will be done on select */ + rc= mysql_stmt_prepare(stmt, SL(stmt_text)); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + bind_array[0].buffer= buf1; + bind_array[0].buffer_length= sizeof(buf1); + bind_array[0].length= &buf1_len; + + bind_array[1].buffer= buf2; + bind_array[1].buffer_length= sizeof(buf2); + bind_array[1].length= &buf2_len; + + mysql_stmt_bind_result(stmt, bind_array); + + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + FAIL_UNLESS(buf1_len == strlen(cp1251), "buf1_len != strlen(cp1251)"); + FAIL_UNLESS(buf2_len == strlen(cp1251), "buf2_len != strlen(cp1251)"); + FAIL_UNLESS(!memcmp(buf1, cp1251, buf1_len), "buf1 != cp1251"); + FAIL_UNLESS(!memcmp(buf2, cp1251, buf1_len), "buf2 != cp1251"); + + rc= mysql_stmt_fetch(stmt); + FAIL_UNLESS(rc == MYSQL_NO_DATA, "rc != MYSQL_NO_DATA"); + + stmt_text= "DROP TABLE IF EXISTS t1"; + rc= mysql_real_query(mysql, SL(stmt_text)); + check_mysql_rc(rc, mysql); + + /* + Now create table with two cp1251 columns, set client character + set to koi8 and supply columns of one row as string and another as + binary data. Binary data must not be converted on insert, and both + columns must be converted to client character set on select. + */ + + stmt_text= "CREATE TABLE t1 (c1 VARCHAR(255) CHARACTER SET cp1251, " + "c2 VARCHAR(255) CHARACTER SET cp1251)"; + + rc= mysql_real_query(mysql, SL(stmt_text)); + check_mysql_rc(rc, mysql); + + stmt_text= "INSERT INTO t1 (c1, c2) VALUES (?, ?)"; + + rc= mysql_stmt_prepare(stmt, SL(stmt_text)); + check_stmt_rc(rc, stmt); + /* this data must be converted */ + bind_array[0].buffer_type= MYSQL_TYPE_STRING; + bind_array[0].buffer= (void *) koi8; + bind_array[0].buffer_length= (unsigned long)strlen(koi8); + + bind_array[1].buffer_type= MYSQL_TYPE_STRING; + bind_array[1].buffer= (void *) koi8; + bind_array[1].buffer_length= (unsigned long)strlen(koi8); + + mysql_stmt_bind_param(stmt, bind_array); + +// mysql_stmt_send_long_data(stmt, 0, koi8, strlen(koi8)); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + /* this data must not be converted */ + bind_array[0].buffer_type= MYSQL_TYPE_BLOB; + bind_array[0].buffer= (void *) cp1251; + bind_array[0].buffer_length= (unsigned long)strlen(cp1251); + + bind_array[1].buffer_type= MYSQL_TYPE_BLOB; + bind_array[1].buffer= (void *) cp1251; + bind_array[1].buffer_length= (unsigned long)strlen(cp1251); + + mysql_stmt_bind_param(stmt, bind_array); + +// mysql_stmt_send_long_data(stmt, 0, cp1251, strlen(cp1251)); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + /* Fetch data and verify that rows are in koi8 */ + + stmt_text= "SELECT c1, c2 FROM t1"; + + /* c1 and c2 are binary so no conversion will be done on select */ + rc= mysql_stmt_prepare(stmt, SL(stmt_text)); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + bind_array[0].buffer= buf1; + bind_array[0].buffer_length= sizeof(buf1); + bind_array[0].length= &buf1_len; + + bind_array[1].buffer= buf2; + bind_array[1].buffer_length= sizeof(buf2); + bind_array[1].length= &buf2_len; + + mysql_stmt_bind_result(stmt, bind_array); + + while ((rc= mysql_stmt_fetch(stmt)) == 0) + { + FAIL_UNLESS(buf1_len == strlen(koi8), "buf1_len != strlen(koi8)"); + FAIL_UNLESS(buf2_len == strlen(koi8), "buf2_len != strlen(koi8)"); + FAIL_UNLESS(!memcmp(buf1, koi8, buf1_len), "buf1 != koi8"); + FAIL_UNLESS(!memcmp(buf2, koi8, buf1_len), "buf2 != koi8"); + } + FAIL_UNLESS(rc == MYSQL_NO_DATA, "rc != MYSQL_NO_DATA"); + mysql_stmt_close(stmt); + + stmt_text= "DROP TABLE t1"; + rc= mysql_real_query(mysql, SL(stmt_text)); + check_mysql_rc(rc, mysql); + stmt_text= "SET NAMES DEFAULT"; + rc= mysql_real_query(mysql, SL(stmt_text)); + check_mysql_rc(rc, mysql); + return OK; +} + +/* + Bug#30472: libmysql doesn't reset charset, insert_id after succ. + mysql_change_user() call row insertions. +*/ + +static int bug30472_retrieve_charset_info(MYSQL *con, + char *character_set_name, + char *character_set_client, + char *character_set_results, + char *collation_connection) +{ + MYSQL_RES *rs; + MYSQL_ROW row; + int rc; + + /* Get the cached client character set name. */ + + strcpy(character_set_name, mysql_character_set_name(con)); + + /* Retrieve server character set information. */ + + rc= mysql_query(con, "SHOW VARIABLES LIKE 'character_set_client'"); + check_mysql_rc(rc, con); + + rs= mysql_store_result(con); + FAIL_IF(!rs, "Invalid result set"); + row= mysql_fetch_row(rs); + FAIL_IF(!row, "Couldn't fetch row"); + strcpy(character_set_client, row[1]); + mysql_free_result(rs); + + rc= mysql_query(con, "SHOW VARIABLES LIKE 'character_set_results'"); + check_mysql_rc(rc, con); + rs= mysql_store_result(con); + FAIL_IF(!rs, "Invalid result set"); + row= mysql_fetch_row(rs); + FAIL_IF(!row, "Couldn't fetch row"); + strcpy(character_set_results, row[1]); + mysql_free_result(rs); + + rc= mysql_query(con, "SHOW VARIABLES LIKE 'collation_connection'"); + check_mysql_rc(rc, con); + rs= mysql_store_result(con); + FAIL_IF(!rs, "Invalid result set"); + row= mysql_fetch_row(rs); + FAIL_IF(!row, "Couldn't fetch row"); + strcpy(collation_connection, row[1]); + mysql_free_result(rs); + return OK; +} + +#define MY_CS_NAME_SIZE 32 + +static int test_bug30472(MYSQL *mysql) +{ + int rc; + + char character_set_name_1[MY_CS_NAME_SIZE]; + char character_set_client_1[MY_CS_NAME_SIZE]; + char character_set_results_1[MY_CS_NAME_SIZE]; + char collation_connnection_1[MY_CS_NAME_SIZE]; + + char character_set_name_2[MY_CS_NAME_SIZE]; + char character_set_client_2[MY_CS_NAME_SIZE]; + char character_set_results_2[MY_CS_NAME_SIZE]; + char collation_connnection_2[MY_CS_NAME_SIZE]; + + char character_set_name_3[MY_CS_NAME_SIZE]; + char character_set_client_3[MY_CS_NAME_SIZE]; + char character_set_results_3[MY_CS_NAME_SIZE]; + char collation_connnection_3[MY_CS_NAME_SIZE]; + + char character_set_name_4[MY_CS_NAME_SIZE]; + char character_set_client_4[MY_CS_NAME_SIZE]; + char character_set_results_4[MY_CS_NAME_SIZE]; + char collation_connnection_4[MY_CS_NAME_SIZE]; + + SKIP_MAXSCALE; + + if (mysql_get_server_version(mysql) < 50100 || !is_mariadb) + { + diag("Test requires MySQL Server version 5.1 or above"); + return SKIP; + } + /* Retrieve character set information. */ + + mysql_set_character_set(mysql, "latin1"); + bug30472_retrieve_charset_info(mysql, + character_set_name_1, + character_set_client_1, + character_set_results_1, + collation_connnection_1); + + /* Switch client character set. */ + + FAIL_IF(mysql_set_character_set(mysql, "ascii"), + "Setting cs to ascii failed"); + + /* Retrieve character set information. */ + + bug30472_retrieve_charset_info(mysql, + character_set_name_2, + character_set_client_2, + character_set_results_2, + collation_connnection_2); + + /* + Check that + 1) character set has been switched and + 2) new character set is different from the original one. + */ + + FAIL_UNLESS(strcmp(character_set_name_2, "ascii") == 0, "cs_name != ascii"); + FAIL_UNLESS(strcmp(character_set_client_2, "ascii") == 0, "cs_client != ascii"); + FAIL_UNLESS(strcmp(character_set_results_2, "ascii") == 0, "cs_result != ascii"); + FAIL_UNLESS(strcmp(collation_connnection_2, "ascii_general_ci") == 0, + "collation != ascii_general_ci"); + + diag("%s %s", character_set_name_1, character_set_name_2); + FAIL_UNLESS(strcmp(character_set_name_1, character_set_name_2) != 0, "cs_name1 = cs_name2"); + FAIL_UNLESS(strcmp(character_set_client_1, character_set_client_2) != 0, "cs_client1 = cs_client2"); + FAIL_UNLESS(strcmp(character_set_results_1, character_set_results_2) != 0, "cs_result1 = cs_result2"); + FAIL_UNLESS(strcmp(collation_connnection_1, collation_connnection_2) != 0, "collation1 = collation2"); + + /* Call mysql_change_user() with the same username, password, database. */ + + rc= mysql_change_user(mysql, username, password, (schema) ? schema : "test"); + mysql_set_character_set(mysql, "latin1"); + check_mysql_rc(rc, mysql); + + /* Retrieve character set information. */ + + bug30472_retrieve_charset_info(mysql, + character_set_name_3, + character_set_client_3, + character_set_results_3, + collation_connnection_3); + + /* Check that character set information has been reset. */ + + FAIL_UNLESS(strcmp(character_set_name_1, character_set_name_3) == 0, "cs_name1 != cs_name3"); + FAIL_UNLESS(strcmp(character_set_client_1, character_set_client_3) == 0, "cs_client1 != cs_client3"); + FAIL_UNLESS(strcmp(character_set_results_1, character_set_results_3) == 0, "cs_result1 != cs_result3"); + FAIL_UNLESS(strcmp(collation_connnection_1, collation_connnection_3) == 0, "collation1 != collation3"); + + /* Change connection-default character set in the client. */ + + mysql_options(mysql, MYSQL_SET_CHARSET_NAME, "latin2"); + + /* + Call mysql_change_user() in order to check that new connection will + have UTF8 character set on the client and on the server. + */ + + rc= mysql_change_user(mysql, username, password, (schema) ? schema : "test"); + check_mysql_rc(rc, mysql); + + /* Retrieve character set information. */ + + bug30472_retrieve_charset_info(mysql, + character_set_name_4, + character_set_client_4, + character_set_results_4, + collation_connnection_4); + + /* Check that we have UTF8 on the server and on the client. */ + + FAIL_UNLESS(strcmp(character_set_name_4, "latin2") == 0, "cs_name != latin2"); + FAIL_UNLESS(strcmp(character_set_client_4, "latin2") == 0, "cs_client != latin2"); + FAIL_UNLESS(strcmp(character_set_results_4, "latin2") == 0, "cs_result != latin2"); + FAIL_UNLESS(strcmp(collation_connnection_4, "latin2_general_ci") == 0, + "collation_connection != latin2_general_ci"); + + /* That's it. Cleanup. */ + + return OK; +} + +static int test_bug_54100(MYSQL *mysql) +{ + MYSQL_RES *result; + MYSQL_ROW row; + int rc; + + rc= mysql_query(mysql, "SHOW CHARACTER SET"); + check_mysql_rc(rc, mysql); + + result= mysql_store_result(mysql); + + while ((row= mysql_fetch_row(result))) + { + /* ignore ucs2 */ + if (strcmp(row[0], "ucs2") + && strcmp(row[0], "utf16le") + && (strcmp(row[0], "utf8mb4") && mariadb_connection(mysql) && mysql_get_server_version(mysql) < 100600) + && (strcmp(row[0], "utf8") && mariadb_connection(mysql) && mysql_get_server_version(mysql) >= 100600) + && strcmp(row[0], "utf16") + && strcmp(row[0], "utf32")) { + rc= mysql_set_character_set(mysql, row[0]); + check_mysql_rc(rc, mysql); + } + } + mysql_free_result(result); + + return OK; +} + + +/* We need this internal function for the test */ + +static int test_utf16_utf32_noboms(MYSQL *mysql __attribute__((unused))) +{ +#ifndef HAVE_ICONV + diag("MariaDB Connector/C was built without iconv support"); + return SKIP; +#else + const char *csname[]= {"utf16", "utf16le", "utf32", "utf8"}; + MARIADB_CHARSET_INFO *csinfo[sizeof(csname)/sizeof(char*)]; + + const int UTF8= sizeof(csname)/sizeof(char*) - 1; + + unsigned char in_string[][8]= {"\xd8\x02\xdc\x60\0", /* utf16(be) */ + "\x02\xd8\x60\xdc\0", /* utf16le */ + "\x00\x01\x08\x60\0\0\0", /* utf32(be) */ + "\xF0\x90\xA1\xA0" }; /* utf8 */ + size_t in_oct_len[]= {6, 6, 8, 5}; + + char buffer[8], as_hex[16]; + int i, error; + size_t rc, in_len, out_len; + + for (i= 0; i < (int)(sizeof(csname)/sizeof(char*)); ++i) + { + csinfo[i]= mariadb_get_charset_by_name(csname[i]); + + if (csinfo[i] == NULL) + { + diag("Could not get cs info for %s", csname[i]); + return FAIL; + } + } + + for (i= 0; i < UTF8; ++i) + { + in_len= in_oct_len[i]; + out_len= sizeof(buffer); + + diag("Converting %s->%s", csname[i], csname[UTF8]); + rc= mariadb_convert_string((char *)in_string[i], &in_len, csinfo[i], buffer, &out_len, csinfo[UTF8], &error); + + FAIL_IF(rc == (size_t)-1, "Conversion failed"); + FAIL_IF(rc != in_oct_len[UTF8], "Incorrect number of written bytes"); + + if (memcmp(buffer, in_string[UTF8], rc) != 0) + { + mysql_hex_string(as_hex, buffer, (unsigned long)rc); + diag("Converted string(%s) does not match the expected one", as_hex); + return FAIL; + } + + in_len= in_oct_len[UTF8]; + out_len= sizeof(buffer); + + diag("Converting %s->%s", csname[UTF8], csname[i]); + rc= mariadb_convert_string((char *)in_string[UTF8], &in_len, csinfo[UTF8], buffer, &out_len, csinfo[i], &error); + + FAIL_IF(rc == (size_t)-1, "Conversion failed"); + diag("rc=%lu oct_len: %lu", (unsigned long)rc, (unsigned long)in_oct_len[i]); + FAIL_IF(rc != in_oct_len[i], "Incorrect number of written bytes"); + + if (memcmp(buffer, in_string[i], rc) != 0) + { + mysql_hex_string(as_hex, buffer, (unsigned long)rc); + diag("Converted string(%s) does not match the expected one", as_hex); + return FAIL; + } + } + + return OK; +#endif +} + +static int charset_auto(MYSQL *my __attribute__((unused))) +{ + const char *csname1, *csname2; + const char *osname; + MYSQL *mysql= mysql_init(NULL); + int rc; + + osname= madb_get_os_character_set(); + + mysql_options(mysql, MYSQL_SET_CHARSET_NAME, "auto"); + + FAIL_IF(!my_test_connect(mysql, hostname, username, + password, schema, port, socketname, 0), + mysql_error(mysql)); + + csname1= mysql_character_set_name(mysql); + diag("Character set: %s os charset: %s", csname1, osname); + + FAIL_IF(!strcasecmp(osname,"utf8") ? strncmp(osname, csname1, 4) : + strcmp(osname, csname1), + "character set is not os character set"); + if (strcmp(osname, "utf8")) + { + rc= mysql_set_character_set(mysql, "utf8"); + check_mysql_rc(rc, mysql); + + csname2= mysql_character_set_name(mysql); + diag("Character set: %s", csname2); + FAIL_IF(!strcmp(csname2, csname1), "Wrong charset: expected utf8"); + + rc= mysql_set_character_set(mysql, "auto"); + check_mysql_rc(rc, mysql); + + csname2= mysql_character_set_name(mysql); + diag("Character set: %s", csname2); + FAIL_IF(strcmp(csname2, osname), "Wrong charset: expected os charset"); + } + mysql_close(mysql); + return OK; +} + +/* check if all server character sets are supported */ +static int test_conc223(MYSQL *mysql) +{ + int rc; + MYSQL_RES *res; + MYSQL_ROW row; + int found= 0; + + SKIP_MYSQL(mysql); + + rc= mysql_query(mysql, "SELECT ID, CHARACTER_SET_NAME, COLLATION_NAME FROM INFORMATION_SCHEMA.COLLATIONS"); + check_mysql_rc(rc, mysql); + + res= mysql_store_result(mysql); + while ((row = mysql_fetch_row(res))) + { + int id= atoi(row[0]); + if (!mariadb_get_charset_by_nr(id)) + { + diag("%04d %s %s", id, row[1], row[2]); + found++; + } + } + mysql_free_result(res); + if (found) + { + diag("%d character sets/collations not found", found); + return FAIL; + } + return OK; +} + +struct my_tests_st my_tests[] = { + {"test_conc223", test_conc223, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"charset_auto", charset_auto, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"bug_8378: mysql_real_escape with gbk", bug_8378, TEST_CONNECTION_NEW, 0, opt_bug8378, NULL}, + {"test_client_character_set", test_client_character_set, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"bug_10214: mysql_real_escape with NO_BACKSLASH_ESCAPES", bug_10214, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_escaping", test_escaping, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_conversion", test_conversion, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"bug_41785", bug_41785, TEST_CONNECTION_DEFAULT, 0, NULL, "not fixed yet"}, + {"test_bug27876", test_bug27876, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_bug30472", test_bug30472, TEST_CONNECTION_NEW, 0, NULL, NULL}, + {"test_ps_i18n", test_ps_i18n, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_bug_54100", test_bug_54100, TEST_CONNECTION_NEW, 0, NULL, NULL}, + {"test_utf16_utf32_noboms", test_utf16_utf32_noboms, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {NULL, NULL, 0, 0, NULL, 0} +}; + + +int main(int argc, char **argv) +{ + if (argc > 1) + get_options(argc, argv); + + get_envvars(); + + run_tests(my_tests); + + return(exit_status()); +} diff --git a/vendor/MDBC/unittest/libmariadb/conc336.c b/vendor/MDBC/unittest/libmariadb/conc336.c new file mode 100644 index 00000000..e382f471 --- /dev/null +++ b/vendor/MDBC/unittest/libmariadb/conc336.c @@ -0,0 +1,53 @@ +#include "my_test.h" + +#define MAX_COUNT 2000 + +int main(int argc, char *argv[]) { + + MYSQL *mysql; + int i; + + if (argc > 1) + get_options(argc, argv); + + get_envvars(); + + if (IS_SKYSQL(hostname)) + return 0; + + diag("hostname: %s", hostname); + + for (i = 0; i < MAX_COUNT; ++i) { + + if (mysql_library_init(-1, NULL, NULL) != 0) { + diag("mysql_library_init failed"); + return 1; + } + + mysql = mysql_init(NULL); + if (!mysql) { + diag("mysql_init failed"); + return 1; + } + + if (force_tls) + mysql_options(mysql, MYSQL_OPT_SSL_ENFORCE, &force_tls); + + if (!mysql_real_connect(mysql, hostname, username, password, schema, port, socketname, 0)) { + diag("mysql_real_connect failed: %s", mysql_error(mysql)); + return 1; + } + + if (mysql_query(mysql, "SELECT NULL LIMIT 0") != 0) { + diag("mysql_query failed: %s", mysql_error(mysql)); + return 1; + } + + mysql_close(mysql); + mysql_library_end(); + + } + + return 0; + +} diff --git a/vendor/MDBC/unittest/libmariadb/connection.c b/vendor/MDBC/unittest/libmariadb/connection.c new file mode 100644 index 00000000..5cbea6ec --- /dev/null +++ b/vendor/MDBC/unittest/libmariadb/connection.c @@ -0,0 +1,1972 @@ +/* +Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. + +The MySQL Connector/C is licensed under the terms of the GPLv2 +, like most +MySQL Connectors. There are special exceptions to the terms and +conditions of the GPLv2 as it is applied to this software, see the +FLOSS License Exception +. + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published +by the Free Software Foundation; version 2 of the License. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ +/** + Some basic tests of the client API. +*/ + +#include "my_test.h" + +static int test_conc66(MYSQL *my) +{ + MYSQL *mysql= mysql_init(NULL); + int rc; + FILE *fp; + char query[1024]; + + SKIP_SKYSQL; + SKIP_MAXSCALE; + + if (!is_mariadb) + return SKIP; + + if (!(fp= fopen("./my-conc66-test.cnf", "w"))) + return FAIL; + + fprintf(fp, "[notmygroup]\n"); + fprintf(fp, "user=foo\n"); + fprintf(fp, "[conc-66]\n"); + fprintf(fp, "user=conc66\n"); + fprintf(fp, "port=3306\n"); + fprintf(fp, "enable-local-infile\n"); + fprintf(fp, "password='test@A1\\\";#test'\n"); + + fclose(fp); + + rc= mysql_options(mysql, MYSQL_READ_DEFAULT_GROUP, "conc-66"); + check_mysql_rc(rc, mysql); + rc= mysql_options(mysql, MYSQL_READ_DEFAULT_FILE, "./my-conc66-test.cnf"); + check_mysql_rc(rc, mysql); + + sprintf(query, "GRANT ALL ON %s.* TO 'conc66'@'%s' IDENTIFIED BY 'test@A1\";#test'", schema, this_host ? this_host : "localhost"); + rc= mysql_query(my, query); + check_mysql_rc(rc, my); + rc= mysql_query(my, "FLUSH PRIVILEGES"); + check_mysql_rc(rc, my); + if (!my_test_connect(mysql, hostname, NULL, + NULL, schema, port, socketname, 0)) + { + diag("user: %s", mysql->options.user); + diag("Error: %s", mysql_error(mysql)); + return FAIL; + } + diag("user: %s", mysql->options.user); + + sprintf(query, "DROP user 'conc66'@'%s'", this_host ? this_host : "localhost"); + rc= mysql_query(my, query); + + check_mysql_rc(rc, my); + mysql_close(mysql); + return OK; +} + +static int test_bug20023(MYSQL *mysql) +{ + int sql_big_selects_orig; + int max_join_size_orig; + + int sql_big_selects_2; + int sql_big_selects_3; + int sql_big_selects_4; + int sql_big_selects_5; + int rc; + + SKIP_SKYSQL; + SKIP_MAXSCALE; + + if (!is_mariadb) + return SKIP; + + if (mysql_get_server_version(mysql) < 50100) { + diag("Test requires MySQL Server version 5.1 or above"); + return SKIP; + } + + /*********************************************************************** + Remember original SQL_BIG_SELECTS, MAX_JOIN_SIZE values. + ***********************************************************************/ + + query_int_variable(mysql, + "@@session.sql_big_selects", + &sql_big_selects_orig); + + query_int_variable(mysql, + "@@global.max_join_size", + &max_join_size_orig); + + /*********************************************************************** + Test that COM_CHANGE_USER resets the SQL_BIG_SELECTS to the initial value. + ***********************************************************************/ + + /* Issue COM_CHANGE_USER. */ + rc= mysql_change_user(mysql, username, password, schema); + check_mysql_rc(rc, mysql); + + /* Query SQL_BIG_SELECTS. */ + + query_int_variable(mysql, + "@@session.sql_big_selects", + &sql_big_selects_2); + + /* Check that SQL_BIG_SELECTS is reset properly. */ + + FAIL_UNLESS(sql_big_selects_orig == sql_big_selects_2, "Different value for sql_big_select"); + + /*********************************************************************** + Test that if MAX_JOIN_SIZE set to non-default value, + SQL_BIG_SELECTS will be 0. + ***********************************************************************/ + + /* Set MAX_JOIN_SIZE to some non-default value. */ + + rc= mysql_query(mysql, "SET @@global.max_join_size = 10000"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "SET @@session.max_join_size = default"); + check_mysql_rc(rc, mysql); + + /* Issue COM_CHANGE_USER. */ + + rc= mysql_change_user(mysql, username, password, schema); + check_mysql_rc(rc, mysql); + + /* Query SQL_BIG_SELECTS. */ + + query_int_variable(mysql, + "@@session.sql_big_selects", + &sql_big_selects_3); + + /* Check that SQL_BIG_SELECTS is 0. */ + + FAIL_UNLESS(sql_big_selects_3 == 0, "big_selects != 0"); + + /*********************************************************************** + Test that if MAX_JOIN_SIZE set to default value, + SQL_BIG_SELECTS will be 1. + ***********************************************************************/ + + /* Set MAX_JOIN_SIZE to the default value (-1). */ + + rc= mysql_query(mysql, "SET @@global.max_join_size = cast(-1 as unsigned int)"); + rc= mysql_query(mysql, "SET @@session.max_join_size = default"); + + /* Issue COM_CHANGE_USER. */ + + rc= mysql_change_user(mysql, username, password, schema); + check_mysql_rc(rc, mysql); + + /* Query SQL_BIG_SELECTS. */ + + query_int_variable(mysql, + "@@session.sql_big_selects", + &sql_big_selects_4); + + /* Check that SQL_BIG_SELECTS is 1. */ + + FAIL_UNLESS(sql_big_selects_4 == 1, "sql_big_select != 1"); + + /*********************************************************************** + Restore MAX_JOIN_SIZE. + Check that SQL_BIG_SELECTS will be the original one. + ***********************************************************************/ + + rc= mysql_query(mysql, "SET @@global.max_join_size = cast(-1 as unsigned int)"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "SET @@session.max_join_size = default"); + check_mysql_rc(rc, mysql); + + /* Issue COM_CHANGE_USER. */ + + rc= mysql_change_user(mysql, username, password, schema); + check_mysql_rc(rc, mysql); + + /* Query SQL_BIG_SELECTS. */ + + query_int_variable(mysql, + "@@session.sql_big_selects", + &sql_big_selects_5); + + /* Check that SQL_BIG_SELECTS is 1. */ + + FAIL_UNLESS(sql_big_selects_5 == sql_big_selects_orig, "big_select != 1"); + + /*********************************************************************** + That's it. Cleanup. + ***********************************************************************/ + + return OK; +} + +static int test_change_user(MYSQL *mysql) +{ + char buff[256]; + const char *user_pw= "mysqltest_pw"; + const char *user_no_pw= "mysqltest_no_pw"; + const char *pw= "password"; + const char *db= "mysqltest_user_test_database"; + int rc; + + diag("Due to mysql_change_user security fix this test will not work anymore."); + return(SKIP); + + /* Prepare environment */ + sprintf(buff, "drop database if exists %s", db); + rc= mysql_query(mysql, buff); + check_mysql_rc(rc, mysql); + + sprintf(buff, "create database %s", db); + rc= mysql_query(mysql, buff); + check_mysql_rc(rc, mysql); + + sprintf(buff, + "grant select on %s.* to %s@'%%' identified by '%s'", + db, + user_pw, + pw); + rc= mysql_query(mysql, buff); + check_mysql_rc(rc, mysql); + + sprintf(buff, + "grant select on %s.* to %s@'%%'", + db, + user_no_pw); + rc= mysql_query(mysql, buff); + check_mysql_rc(rc, mysql); + + + /* Try some combinations */ + rc= mysql_change_user(mysql, NULL, NULL, NULL); + FAIL_UNLESS(rc, "Error expected"); + + + rc= mysql_change_user(mysql, "", NULL, NULL); + FAIL_UNLESS(rc, "Error expected"); + + rc= mysql_change_user(mysql, "", "", NULL); + FAIL_UNLESS(rc, "Error expected"); + + rc= mysql_change_user(mysql, "", "", ""); + FAIL_UNLESS(rc, "Error expected"); + + rc= mysql_change_user(mysql, NULL, "", ""); + FAIL_UNLESS(rc, "Error expected"); + + + rc= mysql_change_user(mysql, NULL, NULL, ""); + FAIL_UNLESS(rc, "Error expected"); + + rc= mysql_change_user(mysql, "", NULL, ""); + FAIL_UNLESS(rc, "Error expected"); + + rc= mysql_change_user(mysql, user_pw, NULL, ""); + FAIL_UNLESS(rc, "Error expected"); + + rc= mysql_change_user(mysql, user_pw, "", ""); + FAIL_UNLESS(rc, "Error expected"); + + rc= mysql_change_user(mysql, user_pw, "", NULL); + FAIL_UNLESS(rc, "Error expected"); + + rc= mysql_change_user(mysql, user_pw, NULL, NULL); + FAIL_UNLESS(rc, "Error expected"); + + rc= mysql_change_user(mysql, user_pw, "", db); + FAIL_UNLESS(rc, "Error expected"); + + rc= mysql_change_user(mysql, user_pw, NULL, db); + FAIL_UNLESS(rc, "Error expected"); + + rc= mysql_change_user(mysql, user_pw, pw, db); + check_mysql_rc(rc, mysql); + + rc= mysql_change_user(mysql, user_pw, pw, NULL); + check_mysql_rc(rc, mysql); + + rc= mysql_change_user(mysql, user_pw, pw, ""); + check_mysql_rc(rc, mysql); + + rc= mysql_change_user(mysql, user_no_pw, pw, db); + FAIL_UNLESS(rc, "Error expected"); + + rc= mysql_change_user(mysql, user_no_pw, pw, ""); + FAIL_UNLESS(rc, "Error expected"); + + rc= mysql_change_user(mysql, user_no_pw, pw, NULL); + FAIL_UNLESS(rc, "Error expected"); + + rc= mysql_change_user(mysql, user_no_pw, "", NULL); + check_mysql_rc(rc, mysql); + + rc= mysql_change_user(mysql, user_no_pw, "", ""); + check_mysql_rc(rc, mysql); + + rc= mysql_change_user(mysql, user_no_pw, "", db); + check_mysql_rc(rc, mysql); + + rc= mysql_change_user(mysql, user_no_pw, NULL, db); + check_mysql_rc(rc, mysql); + + rc= mysql_change_user(mysql, "", pw, db); + FAIL_UNLESS(rc, "Error expected"); + + rc= mysql_change_user(mysql, "", pw, ""); + FAIL_UNLESS(rc, "Error expected"); + + rc= mysql_change_user(mysql, "", pw, NULL); + FAIL_UNLESS(rc, "Error expected"); + + rc= mysql_change_user(mysql, NULL, pw, NULL); + FAIL_UNLESS(rc, "Error expected"); + + rc= mysql_change_user(mysql, NULL, NULL, db); + FAIL_UNLESS(rc, "Error expected"); + + rc= mysql_change_user(mysql, NULL, "", db); + FAIL_UNLESS(rc, "Error expected"); + + rc= mysql_change_user(mysql, "", "", db); + FAIL_UNLESS(rc, "Error expected"); + + /* Cleanup the environment */ + + rc= mysql_change_user(mysql, username, password, schema); + check_mysql_rc(rc, mysql); + + sprintf(buff, "drop database %s", db); + rc= mysql_query(mysql, buff); + check_mysql_rc(rc, mysql); + + sprintf(buff, "drop user %s@'%%'", user_pw); + rc= mysql_query(mysql, buff); + check_mysql_rc(rc, mysql); + + sprintf(buff, "drop user %s@'%%'", user_no_pw); + rc= mysql_query(mysql, buff); + check_mysql_rc(rc, mysql); + + return OK; +} + +/** + Bug#31669 Buffer overflow in mysql_change_user() +*/ + +#define LARGE_BUFFER_SIZE 2048 + +static int test_bug31669(MYSQL *mysql) +{ + int rc; + static char buff[LARGE_BUFFER_SIZE+1]; + static char user[USERNAME_CHAR_LENGTH+1]; + static char db[NAME_CHAR_LEN+1]; + static char query[LARGE_BUFFER_SIZE*2]; + + diag("Due to mysql_change_user security fix this test will not work anymore."); + return(SKIP); + + rc= mysql_change_user(mysql, NULL, NULL, NULL); + FAIL_UNLESS(rc, "Error expected"); + + rc= mysql_change_user(mysql, "", "", ""); + FAIL_UNLESS(rc, "Error expected"); + + memset(buff, 'a', sizeof(buff)); + + rc= mysql_change_user(mysql, buff, buff, buff); + FAIL_UNLESS(rc, "Error expected"); + + rc = mysql_change_user(mysql, username, password, schema); + check_mysql_rc(rc, mysql); + + memset(db, 'a', sizeof(db)); + db[NAME_CHAR_LEN]= 0; + sprintf(query, "CREATE DATABASE IF NOT EXISTS %s", db); + rc= mysql_query(mysql, query); + check_mysql_rc(rc, mysql); + + memset(user, 'b', sizeof(user)); + user[USERNAME_CHAR_LENGTH]= 0; + memset(buff, 'c', sizeof(buff)); + buff[LARGE_BUFFER_SIZE]= 0; + sprintf(query, "GRANT ALL PRIVILEGES ON *.* TO '%s'@'%%' IDENTIFIED BY '%s' WITH GRANT OPTION", user, buff); + rc= mysql_query(mysql, query); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "FLUSH PRIVILEGES"); + check_mysql_rc(rc, mysql); + + rc= mysql_change_user(mysql, user, buff, db); + check_mysql_rc(rc, mysql); + + user[USERNAME_CHAR_LENGTH-1]= 'a'; + rc= mysql_change_user(mysql, user, buff, db); + FAIL_UNLESS(rc, "Error expected"); + + user[USERNAME_CHAR_LENGTH-1]= 'b'; + buff[LARGE_BUFFER_SIZE-1]= 'd'; + rc= mysql_change_user(mysql, user, buff, db); + FAIL_UNLESS(rc, "Error expected"); + + buff[LARGE_BUFFER_SIZE-1]= 'c'; + db[NAME_CHAR_LEN-1]= 'e'; + rc= mysql_change_user(mysql, user, buff, db); + FAIL_UNLESS(rc, "Error expected"); + + db[NAME_CHAR_LEN-1]= 'a'; + rc= mysql_change_user(mysql, user, buff, db); + FAIL_UNLESS(!rc, "Error expected"); + + rc= mysql_change_user(mysql, user + 1, buff + 1, db + 1); + FAIL_UNLESS(rc, "Error expected"); + + rc = mysql_change_user(mysql, username, password, schema); + check_mysql_rc(rc, mysql); + + sprintf(query, "DROP DATABASE %s", db); + rc= mysql_query(mysql, query); + check_mysql_rc(rc, mysql); + + sprintf(query, "DELETE FROM mysql.user WHERE User='%s'", user); + rc= mysql_query(mysql, query); + check_mysql_rc(rc, mysql); + FAIL_UNLESS(mysql_affected_rows(mysql) == 1, ""); + + return OK; +} + +/** + Bug# 33831 my_test_connect() should fail if + given an already connected MYSQL handle. +*/ + +static int test_bug33831(MYSQL *mysql) +{ + FAIL_IF(my_test_connect(mysql, hostname, username, + password, schema, port, socketname, 0), + "Error expected"); + + return OK; +} + +/* Test MYSQL_OPT_RECONNECT, Bug#15719 */ + +static int test_opt_reconnect(MYSQL *mysql) +{ + my_bool my_true= TRUE; + int rc; + my_bool reconnect; + + printf("true: %d\n", TRUE); + + mysql= mysql_init(NULL); + FAIL_IF(!mysql, "not enough memory"); + + mysql_get_option(mysql, MYSQL_OPT_RECONNECT, &reconnect); + FAIL_UNLESS(reconnect == 0, "reconnect != 0"); + + rc= mysql_options(mysql, MYSQL_OPT_RECONNECT, &my_true); + check_mysql_rc(rc, mysql); + + mysql_get_option(mysql, MYSQL_OPT_RECONNECT, &reconnect); + FAIL_UNLESS(reconnect == 1, "reconnect != 1"); + + if (!(my_test_connect(mysql, hostname, username, + password, schema, port, + socketname, 0))) + { + diag("connection failed"); + mysql_close(mysql); + return FAIL; + } + + mysql_get_option(mysql, MYSQL_OPT_RECONNECT, &reconnect); + FAIL_UNLESS(reconnect == 1, "reconnect != 1"); + + mysql_close(mysql); + + mysql= mysql_init(NULL); + FAIL_IF(!mysql, "not enough memory"); + + mysql_get_option(mysql, MYSQL_OPT_RECONNECT, &reconnect); + FAIL_UNLESS(reconnect == 0, "reconnect != 0"); + + if (!(my_test_connect(mysql, hostname, username, + password, schema, port, + socketname, 0))) + { + diag("connection failed"); + mysql_close(mysql); + return FAIL; + } + + mysql_get_option(mysql, MYSQL_OPT_RECONNECT, &reconnect); + FAIL_UNLESS(reconnect == 0, "reconnect != 0"); + + mysql_close(mysql); + return OK; +} + + +static int test_compress(MYSQL *mysql) +{ + // maxscale doesn't support compression + MYSQL_RES *res; + MYSQL_ROW row; + int rc; + SKIP_MAXSCALE; + + mysql= mysql_init(NULL); + FAIL_IF(!mysql, "not enough memory"); + + /* use compressed protocol */ + rc= mysql_options(mysql, MYSQL_OPT_COMPRESS, NULL); + + + + if (!(my_test_connect(mysql, hostname, username, + password, schema, port, + socketname, 0))) + { + diag("connection failed"); + return FAIL; + } + + rc= mysql_query(mysql, "SHOW STATUS LIKE 'compression'"); + check_mysql_rc(rc, mysql); + res= mysql_store_result(mysql); + row= mysql_fetch_row(res); + FAIL_UNLESS(strcmp(row[1], "ON") == 0, "Compression off"); + mysql_free_result(res); + + mysql_close(mysql); + return OK; +} + +static int test_reconnect(MYSQL *mysql) +{ + my_bool my_true= TRUE; + MYSQL *mysql1; + int rc; + my_bool reconnect; + SKIP_MAXSCALE; + + mysql1= mysql_init(NULL); + FAIL_IF(!mysql1, "not enough memory"); + + mysql_get_option(mysql1, MYSQL_OPT_RECONNECT, &reconnect); + FAIL_UNLESS(reconnect == 0, "reconnect != 0"); + + rc= mysql_options(mysql1, MYSQL_OPT_RECONNECT, &my_true); + check_mysql_rc(rc, mysql1); + + mysql_get_option(mysql1, MYSQL_OPT_RECONNECT, &reconnect); + FAIL_UNLESS(reconnect == 1, "reconnect != 1"); + + if (!(my_test_connect(mysql1, hostname, username, + password, schema, port, + socketname, 0))) + { + diag("connection failed"); + return FAIL; + } + + mysql_get_option(mysql1, MYSQL_OPT_RECONNECT, &reconnect); + FAIL_UNLESS(reconnect == 1, "reconnect != 1"); + + diag("Thread_id before kill: %lu", mysql_thread_id(mysql1)); + mysql_kill(mysql, mysql_thread_id(mysql1)); + + mysql_ping(mysql1); + + rc= mysql_query(mysql1, "SELECT 1 FROM DUAL LIMIT 0"); + check_mysql_rc(rc, mysql1); + diag("Thread_id after kill: %lu", mysql_thread_id(mysql1)); + + mysql_get_option(mysql1, MYSQL_OPT_RECONNECT, &reconnect); + FAIL_UNLESS(reconnect == 1, "reconnect != 1"); + mysql_close(mysql1); + return OK; +} + +int test_conc21(MYSQL *mysql) +{ + int rc; + MYSQL_RES *res= NULL; + MYSQL_ROW row; + char tmp[256]; + unsigned int check_server_version= 0; + int major=0, minor= 0, patch=0; + SKIP_MAXSCALE; + + rc= mysql_query(mysql, "SELECT @@version"); + check_mysql_rc(rc, mysql); + + res= mysql_store_result(mysql); + FAIL_IF(res == NULL, "invalid result set"); + + row= mysql_fetch_row(res); + strcpy(tmp, row[0]); + mysql_free_result(res); + + sscanf(tmp, "%d.%d.%d", &major, &minor, &patch); + + check_server_version= major * 10000 + minor * 100 + patch; + + FAIL_IF(mysql_get_server_version(mysql) != check_server_version, "Numeric server version mismatch"); + FAIL_IF(strcmp(mysql_get_server_info(mysql), tmp) != 0, "String server version mismatch"); + return OK; +} + +int test_conc26(MYSQL *unused __attribute__((unused))) +{ + MYSQL *mysql= mysql_init(NULL); + mysql_options(mysql, MYSQL_SET_CHARSET_NAME, "ascii"); + + FAIL_IF(my_test_connect(mysql, hostname, "notexistinguser", "password", schema, port, NULL, CLIENT_REMEMBER_OPTIONS), + "Error expected"); + FAIL_IF(!mysql->options.charset_name || strcmp(mysql->options.charset_name, "ascii") != 0, + "expected charsetname=ascii"); + mysql_close(mysql); + + mysql= mysql_init(NULL); + FAIL_IF(my_test_connect(mysql, hostname, "notexistinguser", "password", schema, port, NULL, 0), + "Error expected"); + FAIL_IF(mysql->options.charset_name, "Error: options not freed"); + mysql_close(mysql); + + return OK; +} + +int test_connection_timeout(MYSQL *unused __attribute__((unused))) +{ + unsigned int timeout= 5; + time_t start, elapsed; + MYSQL *mysql= mysql_init(NULL); + mysql_options(mysql, MYSQL_OPT_CONNECT_TIMEOUT, (unsigned int *)&timeout); + start= time(NULL); + if (my_test_connect(mysql, "192.168.1.101", "notexistinguser", "password", schema, port, NULL, CLIENT_REMEMBER_OPTIONS)) + { + diag("Error expected - maybe you have to change hostname"); + return FAIL; + } + elapsed= time(NULL) - start; + diag("elapsed: %lu", (unsigned long)elapsed); + mysql_close(mysql); + FAIL_IF((unsigned int)elapsed > 2 * timeout, "timeout ignored"); + return OK; +} + +int test_connection_timeout2(MYSQL *unused __attribute__((unused))) +{ + unsigned int timeout= 5; + time_t start, elapsed; + MYSQL *mysql; + + SKIP_SKYSQL; + SKIP_MAXSCALE; + + mysql= mysql_init(NULL); + mysql_options(mysql, MYSQL_OPT_CONNECT_TIMEOUT, (unsigned int *)&timeout); + mysql_options(mysql, MYSQL_INIT_COMMAND, "set @a:=SLEEP(6)"); + start= time(NULL); + if (my_test_connect(mysql, hostname, username, password, schema, port, NULL, CLIENT_REMEMBER_OPTIONS)) + { + diag("timeout error expected"); + return FAIL; + } + elapsed= time(NULL) - start; + diag("elapsed: %lu", (unsigned long)elapsed); + mysql_close(mysql); + FAIL_IF((unsigned int)elapsed > 2 * timeout, "timeout ignored"); + return OK; +} + +int test_connection_timeout3(MYSQL *unused __attribute__((unused))) +{ + unsigned int timeout= 5; + unsigned int read_write_timeout= 10; + int rc; + time_t start, elapsed; + MYSQL *mysql= mysql_init(NULL); + mysql_options(mysql, MYSQL_OPT_CONNECT_TIMEOUT, (unsigned int *)&timeout); + mysql_options(mysql, MYSQL_OPT_READ_TIMEOUT, (unsigned int *)&read_write_timeout); + mysql_options(mysql, MYSQL_OPT_WRITE_TIMEOUT, (unsigned int *)&read_write_timeout); + mysql_options(mysql, MYSQL_INIT_COMMAND, "set @a:=SLEEP(6)"); + start= time(NULL); + if (my_test_connect(mysql, hostname, username, password, schema, port, socketname, CLIENT_REMEMBER_OPTIONS)) + { + diag("timeout error expected"); + elapsed= time(NULL) - start; + diag("elapsed: %lu", (unsigned long)elapsed); + return FAIL; + } + elapsed= time(NULL) - start; + diag("elapsed: %lu", (unsigned long)elapsed); + FAIL_IF((unsigned int)elapsed > timeout + 1, "timeout ignored"); + + mysql_close(mysql); + mysql= mysql_init(NULL); + mysql_options(mysql, MYSQL_OPT_CONNECT_TIMEOUT, (unsigned int *)&timeout); + mysql_options(mysql, MYSQL_OPT_READ_TIMEOUT, (unsigned int *)&read_write_timeout); + mysql_options(mysql, MYSQL_OPT_WRITE_TIMEOUT, (unsigned int *)&read_write_timeout); + + if (!my_test_connect(mysql, hostname, username, password, schema, port, socketname, CLIENT_REMEMBER_OPTIONS)) + { + diag("Error: %s", mysql_error(mysql)); + return FAIL; + } + + start= time(NULL); + rc= mysql_query(mysql, "SET @a:=SLEEP(12)"); + elapsed= time(NULL) - start; + diag("elapsed: %lu", (unsigned long)elapsed); + FAIL_IF(!rc, "timeout expected"); + mysql_close(mysql); + return OK; +} + + +/* test should run with valgrind */ +static int test_conc118(MYSQL *mysql) +{ + int rc; + my_bool reconnect= 1; + SKIP_SKYSQL; + SKIP_MAXSCALE; + + mysql_options(mysql, MYSQL_OPT_RECONNECT, &reconnect); + + mysql->options.unused_1= 1; + + rc= mysql_kill(mysql, mysql_thread_id(mysql)); + + mysql_ping(mysql); + + rc= mysql_query(mysql, "SET @a:=1"); + check_mysql_rc(rc, mysql); + + FAIL_IF(mysql->options.unused_1 != 1, "options got lost"); + + rc= mysql_kill(mysql, mysql_thread_id(mysql)); + + mysql_ping(mysql); + rc= mysql_query(mysql, "SET @a:=1"); + check_mysql_rc(rc, mysql); + + return OK; +} + +static int test_wrong_bind_address(MYSQL *unused __attribute__((unused))) +{ + const char *bind_addr= "100.188.111.112"; + MYSQL *mysql; + + if (!hostname || !strcmp(hostname, "localhost")) + { + diag("test doesn't work with unix sockets"); + return SKIP; + } + + mysql= mysql_init(NULL); + + mysql_options(mysql, MYSQL_OPT_BIND, bind_addr); + if (my_test_connect(mysql, hostname, username, + password, schema, port, socketname, 0)) + { + diag("Error expected"); + mysql_close(mysql); + return FAIL; + } + diag("Error: %s", mysql_error(mysql)); + mysql_close(mysql); + return OK; +} + +static int test_bind_address(MYSQL *my) +{ + MYSQL *mysql; + char *bind_addr= getenv("MYSQL_TEST_BINDADDR"); + char query[128]; + int rc; + + SKIP_SKYSQL; + + if (!hostname || !strcmp(hostname, "localhost")) + { + diag("test doesn't work with unix sockets"); + return SKIP; + } + + sprintf(query, "DROP USER '%s'@'%s'", username, bind_addr); + rc= mysql_query(my, query); + + sprintf(query, "CREATE USER '%s'@'%s' IDENTIFIED BY '%s'", username, bind_addr, password); + rc= mysql_query(my, query); + check_mysql_rc(rc, my); + + sprintf(query, "GRANT ALL ON %s.* TO '%s'@'%s'", schema, username, bind_addr); + rc= mysql_query(my, query); + check_mysql_rc(rc, my); + + if (!bind_addr) + { + diag("No bind address specified"); + return SKIP; + } + + mysql= mysql_init(NULL); + mysql_options(mysql, MYSQL_OPT_BIND, bind_addr); + + if (!my_test_connect(mysql, bind_addr, username, + password, schema, port, socketname, 0)) + { + diag("Error: %s\n", mysql_error(mysql)); + mysql_close(mysql); + return FAIL; + } + diag("%s", mysql_get_host_info(mysql)); + mysql_close(mysql); + return OK; +} + +static int test_get_options(MYSQL *unused __attribute__((unused))) +{ + MYSQL *mysql= mysql_init(NULL); + int options_int[]= {MYSQL_OPT_CONNECT_TIMEOUT, MYSQL_OPT_LOCAL_INFILE, + MYSQL_OPT_PROTOCOL, MYSQL_OPT_READ_TIMEOUT, MYSQL_OPT_WRITE_TIMEOUT, 0}; + my_bool options_bool[]= {MYSQL_OPT_RECONNECT, MYSQL_REPORT_DATA_TRUNCATION, + MYSQL_OPT_COMPRESS, MYSQL_OPT_SSL_VERIFY_SERVER_CERT, MYSQL_SECURE_AUTH, +#ifdef _WIN32 + MYSQL_OPT_NAMED_PIPE, +#endif + 0}; + int options_char[]= {MYSQL_READ_DEFAULT_FILE, MYSQL_READ_DEFAULT_GROUP, MYSQL_SET_CHARSET_NAME, + MYSQL_OPT_SSL_KEY, MYSQL_OPT_SSL_CA, MYSQL_OPT_SSL_CERT, MYSQL_OPT_SSL_CAPATH, + MYSQL_OPT_SSL_CIPHER, MYSQL_OPT_BIND, MARIADB_OPT_SSL_FP, MARIADB_OPT_SSL_FP_LIST, + MARIADB_OPT_TLS_PASSPHRASE, 0}; + + const char *init_command[3]= {"SET @a:=1", "SET @b:=2", "SET @c:=3"}; + int elements= 0; + char **command; + + + int intval[2]= {1, 0}; + my_bool boolval[2]= {1, 0}; + const char *char1= "test"; + char *char2; + int i; + MYSQL *userdata; + const char *attr_key[] = {"foo1", "foo2", "foo3"}; + const char *attr_val[] = {"bar1", "bar2", "bar3"}; + char **key, **val; + + for (i=0; options_int[i]; i++) + { + mysql_options(mysql, options_int[i], &intval[0]); + intval[1]= 0; + mysql_get_optionv(mysql, options_int[i], &intval[1]); + FAIL_IF(intval[0] != intval[1], "mysql_get_optionv (int) failed"); + } + for (i=0; options_bool[i]; i++) + { + mysql_options(mysql, options_bool[i], &boolval[0]); + intval[1]= 0; + mysql_get_optionv(mysql, options_bool[i], &boolval[1]); + FAIL_IF(boolval[0] != boolval[1], "mysql_get_optionv (my_bool) failed"); + } + for (i=0; options_char[i]; i++) + { + mysql_options(mysql, options_char[i], char1); + char2= NULL; + mysql_get_optionv(mysql, options_char[i], (void *)&char2); + if (options_char[i] != MYSQL_SET_CHARSET_NAME) + FAIL_IF(strcmp(char1, char2), "mysql_get_optionv (char) failed"); + } + + for (i=0; i < 3; i++) + mysql_options(mysql, MYSQL_INIT_COMMAND, init_command[i]); + + mysql_get_optionv(mysql, MYSQL_INIT_COMMAND, &command, &elements); + FAIL_IF(elements != 3, "expected 3 elements"); + for (i=0; i < 3; i++) + FAIL_IF(strcmp(init_command[i], command[i]), "wrong init command"); + for (i=0; i < 3; i++) + mysql_optionsv(mysql, MYSQL_OPT_CONNECT_ATTR_ADD, attr_key[i], attr_val[i]); + + mysql_get_optionv(mysql, MYSQL_OPT_CONNECT_ATTRS, NULL, NULL, &elements); + FAIL_IF(elements != 3, "expected 3 connection attributes"); + + key= (char **)malloc(sizeof(char *) * elements); + val= (char **)malloc(sizeof(char *) * elements); + + mysql_get_optionv(mysql, MYSQL_OPT_CONNECT_ATTRS, &key, &val, &elements); + for (i=0; i < elements; i++) + { + diag("%s => %s", key[i], val[i]); + } + + free(key); + free(val); + + mysql_optionsv(mysql, MARIADB_OPT_USERDATA, "my_app", (void *)mysql); + mysql_get_optionv(mysql, MARIADB_OPT_USERDATA, (char *)"my_app", &userdata); + + FAIL_IF(mysql != userdata, "wrong userdata"); + mysql_close(mysql); + return OK; +} + +static int test_sess_track_db(MYSQL *mysql) +{ + int rc; + const char *data; + size_t len; + char tmp_str[512]; + + + if (!(mysql->server_capabilities & CLIENT_SESSION_TRACKING)) + { + diag("Server doesn't support session tracking (cap=%lu)", mysql->server_capabilities); + return SKIP; + } + + rc= mysql_query(mysql, "USE mysql"); + check_mysql_rc(rc, mysql); + FAIL_IF(strcmp(mysql->db, "mysql"), "Expected new schema 'mysql'"); + + FAIL_IF(mysql_session_track_get_first(mysql, SESSION_TRACK_SCHEMA, &data, &len), + "session_track_get_first failed"); + FAIL_IF(strncmp(data, "mysql", len), "Expected new schema 'mysql'"); + + sprintf(tmp_str, "USE %s", schema); + rc= mysql_query(mysql, tmp_str); + check_mysql_rc(rc, mysql); + + sprintf(tmp_str, "Expected new schema '%s'.", schema); + + FAIL_IF(strcmp(mysql->db, schema), tmp_str); + + FAIL_IF(mysql_session_track_get_first(mysql, SESSION_TRACK_SCHEMA, &data, &len), + "session_track_get_first failed"); + FAIL_IF(strncmp(data, schema, len), tmp_str); + + if (mysql_get_server_version(mysql) >= 100300) + { + diag("charset: %s", mysql->charset->csname); + rc= mysql_query(mysql, "SET NAMES ascii"); + check_mysql_rc(rc, mysql); + if (!mysql_session_track_get_first(mysql, SESSION_TRACK_SYSTEM_VARIABLES, &data, &len)) + do { + printf("# SESSION_TRACK_VARIABLES: %*.*s\n", (int)len, (int)len, data); + } while (!mysql_session_track_get_next(mysql, SESSION_TRACK_SYSTEM_VARIABLES, &data, &len)); + diag("charset: %s", mysql->charset->csname); + FAIL_IF(strcmp(mysql->charset->csname, "ascii"), + "Expected charset 'ascii'"); + + rc= mysql_query(mysql, "SET NAMES latin1"); + check_mysql_rc(rc, mysql); + FAIL_IF(strcmp(mysql->charset->csname, "latin1"), "Expected charset 'latin1'"); + } + rc= mysql_query(mysql, "CREATE PROCEDURE p1() " + "BEGIN " + "SET @@autocommit=0; " + "SET NAMES utf8; " + "SET session auto_increment_increment=2; " + "END "); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CALL p1()"); + check_mysql_rc(rc, mysql); + + if (!mysql_session_track_get_first(mysql, SESSION_TRACK_SYSTEM_VARIABLES, &data, &len)) + do { + printf("# SESSION_TRACK_VARIABLES: %*.*s\n", (int)len, (int)len, data); + } while (!mysql_session_track_get_next(mysql, SESSION_TRACK_SYSTEM_VARIABLES, &data, &len)); + + rc= mysql_query(mysql, "DROP PROCEDURE IF EXISTS p1"); + check_mysql_rc(rc, mysql); + + return OK; +} + +static int test_conc496(MYSQL *mysql) +{ + int rc; + const char *data; + size_t len; + + rc= mysql_query(mysql, "set @@session.session_track_transaction_info=STATE"); + + if (rc && mysql_errno(mysql) == ER_UNKNOWN_SYSTEM_VARIABLE) + { + diag("session_track_transaction_info not supported"); + return SKIP; + } + + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "BEGIN"); + check_mysql_rc(rc, mysql); + if (!mysql_session_track_get_first(mysql, SESSION_TRACK_TRANSACTION_STATE, &data, &len)) + do { + FAIL_IF(len != 8, "expected 8 bytes"); + FAIL_IF(data[0] != 'T', "expected transaction"); + } while (!mysql_session_track_get_next(mysql, SESSION_TRACK_TRANSACTION_STATE, &data, &len)); + + rc= mysql_query(mysql, "CREATE TEMPORARY TABLE t1(a int) ENGINE=InnoDB"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "COMMIT"); + + check_mysql_rc(rc, mysql); + + if (!mysql_session_track_get_first(mysql, SESSION_TRACK_TRANSACTION_STATE, &data, &len)) + do { + FAIL_IF(len != 8, "expected 8 bytes"); + FAIL_IF(data[0] != '_', "expected underscore"); + } while (!mysql_session_track_get_next(mysql, SESSION_TRACK_TRANSACTION_STATE, &data, &len)); + + return OK; +} + + +static int test_unix_socket_close(MYSQL *unused __attribute__((unused))) +{ +#ifdef _WIN32 + diag("test does not run on Windows"); + return SKIP; +#else + MYSQL *mysql= mysql_init(NULL); + FILE *fp; + int i; + + SKIP_SKYSQL; + SKIP_TRAVIS(); + + if (!(fp= fopen("./dummy_sock", "w"))) + { + diag("couldn't create dummy socket"); + return FAIL; + } + fclose(fp); + + for (i=0; i < 10000; i++) + { + my_test_connect(mysql, "localhost", "user", "passwd", NULL, 0, "./dummy_sock", 0); + /* check if we run out of sockets */ + if (mysql_errno(mysql) == 2001) + { + diag("out of sockets after %d attempts", i); + mysql_close(mysql); + return FAIL; + } + } + mysql_close(mysql); + return OK; +#endif +} + + +static int test_reset(MYSQL *mysql) +{ + int rc; + MYSQL_RES *res; + + if (mysql_get_server_version(mysql) < 100200) + return SKIP; + + 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),(3)"); + check_mysql_rc(rc, mysql); + + FAIL_IF(mysql_affected_rows(mysql) != 3, "Expected 3 rows"); + + rc= mysql_reset_connection(mysql); + check_mysql_rc(rc, mysql); + + FAIL_IF(mysql_affected_rows(mysql) != ~(my_ulonglong)0, "Expected 0 rows"); + + rc= mysql_query(mysql, "SELECT a FROM t1"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "SELECT 1 FROM DUAL"); + FAIL_IF(!rc, "Error expected"); + + rc= mysql_reset_connection(mysql); + check_mysql_rc(rc, mysql); + + res= mysql_store_result(mysql); + FAIL_IF(res, "expected no result"); + + rc= mysql_query(mysql, "SELECT a FROM t1"); + check_mysql_rc(rc, mysql); + + res= mysql_use_result(mysql); + FAIL_IF(!res, "expected result"); + + rc= mysql_reset_connection(mysql); + check_mysql_rc(rc, mysql); + + FAIL_IF(mysql_fetch_row(res), "expected error"); + + mysql_free_result(res); + + rc= mysql_query(mysql, "DROP TABLE t1"); + check_mysql_rc(rc, mysql); + + return OK; +} + +static int test_auth256(MYSQL *my) +{ + MYSQL *mysql= mysql_init(NULL); + int rc; + MYSQL_RES *res; + my_ulonglong num_rows= 0; + char query[1024]; + SKIP_MAXSCALE; + + if (IS_SKYSQL(hostname)) + return SKIP; + + if (!mysql_client_find_plugin(mysql, "sha256_password", MYSQL_CLIENT_AUTHENTICATION_PLUGIN)) + { + diag("sha256_password plugin not available"); + mysql_close(mysql); + return SKIP; + } + + rc= mysql_query(my, "SELECT * FROM information_schema.plugins where plugin_name='sha256_password'"); + check_mysql_rc(rc, mysql); + + res= mysql_store_result(my); + num_rows= mysql_num_rows(res); + mysql_free_result(res); + + if (!num_rows) + { + diag("server doesn't support sha256 authentication"); + mysql_close(mysql); + return SKIP; + } + + rc= mysql_query(my, "DROP USER IF EXISTS sha256user@localhost"); + check_mysql_rc(rc, mysql); + + sprintf(query, "CREATE user 'sha256user'@'%s' identified with sha256_password by 'foo'", this_host); + rc= mysql_query(my, query); + check_mysql_rc(rc, my); + + if (!my_test_connect(mysql, hostname, "sha256user", "foo", NULL, port, socketname, 0)) + { + diag("error: %s", mysql_error(mysql)); + mysql_close(mysql); + return FAIL; + } + mysql_close(mysql); + + mysql= mysql_init(NULL); + mysql_options(mysql, MYSQL_SERVER_PUBLIC_KEY, "rsa_public_key.pem"); + if (!my_test_connect(mysql, hostname, "sha256user", "foo", NULL, port, socketname, 0)) + { + diag("error: %s", mysql_error(mysql)); + mysql_close(mysql); + return FAIL; + } + mysql_close(mysql); + sprintf(query, "DROP USER 'sha256user'@'%s'", this_host); + rc= mysql_query(my, query); + check_mysql_rc(rc, mysql); + return OK; +} + +static int test_mdev13100(MYSQL *my __attribute__((unused))) +{ + MYSQL *mysql= mysql_init(NULL); + int rc; + FILE *fp; + + if (!(fp= fopen("./mdev13100.cnf", "w"))) + return FAIL; + + /* [client] group only */ + fprintf(fp, "[client]\n"); + fprintf(fp, "default-character-set=latin2\n"); + + fclose(fp); + + rc= mysql_options(mysql, MYSQL_READ_DEFAULT_FILE, "./mdev13100.cnf"); + check_mysql_rc(rc, mysql); + + if (!my_test_connect(mysql, hostname, username, + password, schema, port, socketname, 0)) + { + diag("Error: %s", mysql_error(mysql)); + return FAIL; + } + FAIL_IF(strcmp("latin2", mysql_character_set_name(mysql)), "Expected charset latin2"); + mysql_close(mysql); + + /* value from client-mariadb group */ + mysql= mysql_init(NULL); + if (!(fp= fopen("./mdev13100.cnf", "w"))) + return FAIL; + + fprintf(fp, "[client]\n"); + fprintf(fp, "default-character-set=latin1\n"); + fprintf(fp, "[client-server]\n"); + fprintf(fp, "default-character-set=latin2\n"); + + fclose(fp); + + rc= mysql_options(mysql, MYSQL_READ_DEFAULT_FILE, "./mdev13100.cnf"); + check_mysql_rc(rc, mysql); + + if (!my_test_connect(mysql, hostname, username, + password, schema, port, socketname, 0)) + { + diag("Error: %s", mysql_error(mysql)); + return FAIL; + } + FAIL_IF(strcmp("latin2", mysql_character_set_name(mysql)), "Expected charset latin2"); + mysql_close(mysql); + +/* values from client-mariadb group */ + mysql= mysql_init(NULL); + +if (!(fp= fopen("./mdev13100.cnf", "w"))) + return FAIL; + + fprintf(fp, "[client]\n"); + fprintf(fp, "default-character-set=latin1\n"); + fprintf(fp, "[client-server]\n"); + fprintf(fp, "default-character-set=utf8\n"); + fprintf(fp, "[client-mariadb]\n"); + fprintf(fp, "default-character-set=latin2\n"); + + fclose(fp); + + rc= mysql_options(mysql, MYSQL_READ_DEFAULT_FILE, "./mdev13100.cnf"); + check_mysql_rc(rc, mysql); + + if (!my_test_connect(mysql, hostname, username, + password, schema, port, socketname, 0)) + { + diag("Error: %s", mysql_error(mysql)); + return FAIL; + } + FAIL_IF(strcmp("latin2", mysql_character_set_name(mysql)), "Expected charset latin2"); + mysql_close(mysql); + +/* values from mdev-13100 group */ + mysql= mysql_init(NULL); + if (!(fp= fopen("./mdev13100.cnf", "w"))) + return FAIL; + + fprintf(fp, "[client]\n"); + fprintf(fp, "default-character-set=latin1\n"); + fprintf(fp, "[client-server]\n"); + fprintf(fp, "default-character-set=latin1\n"); + fprintf(fp, "[client-mariadb]\n"); + fprintf(fp, "default-character-set=utf8\n"); + fprintf(fp, "[mdev13100]\n"); + fprintf(fp, "default-character-set=latin2\n"); + + fclose(fp); + + rc= mysql_options(mysql, MYSQL_READ_DEFAULT_FILE, "./mdev13100.cnf"); + check_mysql_rc(rc, mysql); + rc= mysql_options(mysql, MYSQL_READ_DEFAULT_GROUP, "mdev13100"); + check_mysql_rc(rc, mysql); + + if (!my_test_connect(mysql, hostname, username, + password, schema, port, socketname, 0)) + { + diag("Error: %s", mysql_error(mysql)); + return FAIL; + } + FAIL_IF(strcmp("latin2", mysql_character_set_name(mysql)), "Expected charset latin2"); + mysql_close(mysql); + +/* values from [programname] group */ + mysql= mysql_init(NULL); + if (!(fp= fopen("./mdev13100.cnf", "w"))) + return FAIL; + + fprintf(fp, "[client]\n"); + fprintf(fp, "default-character-set=utf8\n"); + fprintf(fp, "[client-server]\n"); + fprintf(fp, "default-character-set=utf8\n"); + fprintf(fp, "[client-mariadb]\n"); + fprintf(fp, "default-character-set=latin2\n"); + + fclose(fp); + + rc= mysql_options(mysql, MYSQL_READ_DEFAULT_FILE, "./mdev13100.cnf"); + check_mysql_rc(rc, mysql); + rc= mysql_options(mysql, MYSQL_READ_DEFAULT_GROUP, ""); + check_mysql_rc(rc, mysql); + + if (!my_test_connect(mysql, hostname, username, + password, schema, port, socketname, 0)) + { + diag("Error: %s", mysql_error(mysql)); + return FAIL; + } + diag("character set: %s", mysql_character_set_name(mysql)); + FAIL_IF(strcmp("latin2", mysql_character_set_name(mysql)), "Expected charset latin2"); + mysql_close(mysql); + + remove("./mdev13100.cnf"); + + return OK; +} + +static int test_conc276(MYSQL *unused __attribute__((unused))) +{ + MYSQL *mysql= mysql_init(NULL); + int rc; + my_bool val= 1; + + mysql_options(mysql, MYSQL_OPT_SSL_ENFORCE, &val); + mysql_options(mysql, MYSQL_OPT_RECONNECT, &val); + + if (!my_test_connect(mysql, hostname, username, password, schema, port, socketname, 0)) + { + diag("Connection failed. Error: %s", mysql_error(mysql)); + mysql_close(mysql); + return FAIL; + } + diag("Cipher in use: %s", mysql_get_ssl_cipher(mysql)); + + rc= mariadb_reconnect(mysql); + check_mysql_rc(rc, mysql); + + diag("Cipher in use: %s", mysql_get_ssl_cipher(mysql)); + /* this shouldn't crash anymore */ + rc= mysql_query(mysql, "SET @a:=1"); + check_mysql_rc(rc, mysql); + + mysql_close(mysql); + return OK; +} + +static int test_expired_pw(MYSQL *my) +{ + MYSQL *mysql; + int rc; + char query[512]; + unsigned char expire= 1; + + if (mariadb_connection(my) || + !(my->server_capabilities & CLIENT_CAN_HANDLE_EXPIRED_PASSWORDS)) + { + diag("Server doesn't support password expiration"); + return SKIP; + } + sprintf(query, "DROP USER 'foo'@'%s'", this_host); + rc= mysql_query(my, query); + + sprintf(query, "CREATE USER 'foo'@'%s' IDENTIFIED BY 'foo'", this_host); + rc= mysql_query(my, query); + check_mysql_rc(rc, my); + + sprintf(query, "GRANT ALL ON *.* TO 'foo'@'%s'", this_host); + rc= mysql_query(my, query); + check_mysql_rc(rc, my); + + sprintf(query, "ALTER USER 'foo'@'%s' PASSWORD EXPIRE", this_host); + rc= mysql_query(my, query); + check_mysql_rc(rc, my); + + mysql= mysql_init(NULL); + + my_test_connect(mysql, hostname, "foo", "foo", schema, + port, socketname, 0); + + FAIL_IF(!mysql_errno(mysql), "Error expected"); + mysql_close(mysql); + + mysql= mysql_init(NULL); + mysql_optionsv(mysql, MYSQL_OPT_CAN_HANDLE_EXPIRED_PASSWORDS, &expire); + + my_test_connect(mysql, hostname, "foo", "foo", schema, + port, socketname, 0); + + /* we should be in sandbox mode now, only set commands should be allowed */ + rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1"); + FAIL_IF(!rc, "Error expected (we are in sandbox mode"); + + diag("error: %d %s", mysql_errno(mysql), mysql_error(mysql)); + FAIL_IF(mysql_errno(mysql) != ER_MUST_CHANGE_PASSWORD && + mysql_errno(mysql) != ER_MUST_CHANGE_PASSWORD_LOGIN, "Error 1820/1862 expected"); + + mysql_close(mysql); + + sprintf(query, "DROP USER 'foo'@'%s'", this_host); + rc= mysql_query(my, query); + check_mysql_rc(rc, my); + + return OK; +} + +static int test_conc315(MYSQL *mysql) +{ + int rc; + const char *csname; + SKIP_SKYSQL; + SKIP_MAXSCALE; + + if (!is_mariadb) + return SKIP; + + mysql_get_optionv(mysql, MYSQL_SET_CHARSET_NAME, (void *)&csname); + diag("csname=%s", csname); + FAIL_UNLESS(strcmp(csname, MARIADB_DEFAULT_CHARSET) == 0, "Wrong default character set"); + + rc= mysql_change_user(mysql, username, password, schema); + check_mysql_rc(rc, mysql); + mysql_get_optionv(mysql, MYSQL_SET_CHARSET_NAME, (void *)&csname); + FAIL_UNLESS(strcmp(csname, MARIADB_DEFAULT_CHARSET) == 0, "Wrong default character set"); + return OK; +} +#ifndef WIN32 +static int test_conc317(MYSQL *unused __attribute__((unused))) +{ + MYSQL *mysql; + my_bool reconnect = 0; + FILE *fp= NULL; + const char *env= getenv("MYSQL_TMP_DIR"); + char cnf_file1[FN_REFLEN + 1]; + + SKIP_SKYSQL; + + if (travis_test) + return SKIP; + + if (!env) + env= "/tmp"; + + setenv("HOME", env, 1); + + snprintf(cnf_file1, FN_REFLEN, "%s%c.my.cnf", env, FN_LIBCHAR); + + FAIL_IF(!access(cnf_file1, R_OK), "access"); + + mysql= mysql_init(NULL); + fp= fopen(cnf_file1, "w"); + FAIL_IF(!fp, "fopen"); + + fprintf(fp, "[client]\ndefault-character-set = latin2\nreconnect= 1\n"); + fclose(fp); + + mysql_options(mysql, MYSQL_READ_DEFAULT_GROUP, ""); + my_test_connect(mysql, hostname, username, password, + schema, port, socketname, 0); + + remove(cnf_file1); + + FAIL_IF(strcmp(mysql_character_set_name(mysql), "latin2"), "expected charset latin2"); + mysql_get_optionv(mysql, MYSQL_OPT_RECONNECT, &reconnect); + FAIL_IF(reconnect != 1, "expected reconnect=1"); + mysql_close(mysql); + return OK; +} + +static int test_conc327(MYSQL *unused __attribute__((unused))) +{ + MYSQL *mysql; + my_bool reconnect = 0; + FILE *fp1= NULL, *fp2= NULL; + const char *env= getenv("MYSQL_TMP_DIR"); + char cnf_file1[FN_REFLEN + 1]; + char cnf_file2[FN_REFLEN + 1]; + + SKIP_SKYSQL; + + if (travis_test) + return SKIP; + + if (!env) + env= "/tmp"; + + setenv("HOME", env, 1); + + snprintf(cnf_file1, FN_REFLEN, "%s%c.my.cnf", env, FN_LIBCHAR); + snprintf(cnf_file2, FN_REFLEN, "%s%c.my.tmp", env, FN_LIBCHAR); + + FAIL_IF(!access(cnf_file1, R_OK), "access"); + + fp1= fopen(cnf_file1, "w"); + fp2= fopen(cnf_file2, "w"); + FAIL_IF(!fp1 || !fp2, "fopen failed"); + + fprintf(fp1, "!include %s\n", cnf_file2); + + fprintf(fp2, "[client]\ndefault-character-set = latin2\nreconnect= 1\n"); + fclose(fp1); + fclose(fp2); + + mysql= mysql_init(NULL); + mysql_options(mysql, MYSQL_READ_DEFAULT_GROUP, ""); + my_test_connect(mysql, hostname, username, password, + schema, port, socketname, 0); + + remove(cnf_file1); + remove(cnf_file2); + + diag("new charset: %s", mysql->options.charset_name); + FAIL_IF(strcmp(mysql_character_set_name(mysql), "latin2"), "expected charset latin2"); + mysql_get_optionv(mysql, MYSQL_OPT_RECONNECT, &reconnect); + FAIL_IF(reconnect != 1, "expected reconnect=1"); + mysql_close(mysql); + + snprintf(cnf_file1, FN_REFLEN, "%s%cmy.cnf", env, FN_LIBCHAR); + fp1= fopen(cnf_file1, "w"); + fp2= fopen(cnf_file2, "w"); + FAIL_IF(!fp1 || !fp2, "fopen failed"); + + fprintf(fp2, "!includedir %s\n", env); + + fprintf(fp1, "[client]\ndefault-character-set = latin2\nreconnect= 1\n"); + fclose(fp1); + fclose(fp2); + mysql= mysql_init(NULL); + mysql_options(mysql, MYSQL_READ_DEFAULT_FILE, cnf_file2); + my_test_connect(mysql, hostname, username, password, + schema, port, socketname, 0); + + remove(cnf_file1); + remove(cnf_file2); + + FAIL_IF(strcmp(mysql_character_set_name(mysql), "latin2"), "expected charset latin2"); + mysql_get_optionv(mysql, MYSQL_OPT_RECONNECT, &reconnect); + FAIL_IF(reconnect != 1, "expected reconnect=1"); + mysql_close(mysql); + + return OK; +} +#endif + +static int test_conc332(MYSQL *unused __attribute__((unused))) +{ + int rc; + MYSQL *mysql= mysql_init(NULL); + int server_status1, server_status2; + + SKIP_SKYSQL; + SKIP_MAXSCALE; + + mysql_options(mysql, MYSQL_SET_CHARSET_NAME, "utf8mb4"); + + my_test_connect(mysql, hostname, username, password, schema, + port, socketname, 0); + + FAIL_IF(mysql_errno(mysql), "Error during connect"); + + mariadb_get_infov(mysql, MARIADB_CONNECTION_SERVER_STATUS, &server_status1); + diag("server_status: %d", server_status1); + + if (server_status1 & SERVER_STATUS_AUTOCOMMIT) + rc= mysql_query(mysql, "SET autocommit= 0"); + else + rc= mysql_query(mysql, "SET autocommit= 1"); + check_mysql_rc(rc, mysql); + mariadb_get_infov(mysql, MARIADB_CONNECTION_SERVER_STATUS, &server_status2); + diag("server_status after changing autocommit: %d", server_status2); + + rc= mysql_change_user(mysql, username, password, schema); + check_mysql_rc(rc, mysql); + + mariadb_get_infov(mysql, MARIADB_CONNECTION_SERVER_STATUS, &server_status2); + diag("server_status after mysql_change_user: %d", server_status2); + if (server_status1 != server_status2) + { + diag("Expected server_status %d instead of %d", server_status1, server_status2); + mysql_close(mysql); + return FAIL; + } + mysql_close(mysql); + return OK; +} + +static int test_conc351(MYSQL *unused __attribute__((unused))) +{ + int rc; + const char *data; + size_t len; + MYSQL *mysql= mysql_init(NULL); + ulong capabilities= 0; + + my_test_connect(mysql, hostname, username, password, schema, + port, socketname, 0); + + FAIL_IF(mysql_errno(mysql), "Error during connect"); + + mariadb_get_infov(mysql, MARIADB_CONNECTION_SERVER_CAPABILITIES, &capabilities); + if (!(capabilities & CLIENT_SESSION_TRACKING)) + { + mysql_close(mysql); + diag("Server doesn't support session tracking (cap=%lu)", mysql->server_capabilities); + return SKIP; + } + rc= mysql_query(mysql, "USE mysql"); + check_mysql_rc(rc, mysql); + FAIL_IF(strcmp(mysql->db, "mysql"), "Expected new schema 'mysql'"); + + FAIL_IF(mysql_session_track_get_first(mysql, SESSION_TRACK_SCHEMA, &data, &len), "expected session track schema"); + + rc= mysql_query(mysql, "SET @a:=1"); + check_mysql_rc(rc, mysql); + + FAIL_IF(!mysql_session_track_get_first(mysql, SESSION_TRACK_SCHEMA, &data, &len), "expected no schema tracking information"); + + mysql_close(mysql); + return OK; +} + +static int test_conc312(MYSQL *my) +{ + int rc; + char query[1024]; + MYSQL *mysql; + + sprintf(query, "DROP USER 'foo'@'%s'", this_host); + rc= mysql_query(my, query); + + sprintf(query, "CREATE USER 'foo'@'%s' IDENTIFIED WITH caching_sha2_password BY 'foo'", this_host); + rc= mysql_query(my, query); + + if (rc) + { + diag("caching_sha256_password not supported"); + return SKIP; + } + + sprintf(query, "GRANT ALL ON %s.* TO 'foo'@'%s'", schema, this_host); + rc= mysql_query(my, query); + check_mysql_rc(rc, my); + + mysql= mysql_init(NULL); + if (!my_test_connect(mysql, hostname, "foo", "foo", schema, port, socketname, 0)) + { + diag("Error: %s", mysql_error(mysql)); + return FAIL; + } + + mysql_close(mysql); + + sprintf(query, "DROP USER 'foo'@'%s'", this_host); + rc= mysql_query(my, query); + check_mysql_rc(rc, mysql); + + return OK; +} + +static int test_conc366(MYSQL *mysql) +{ + char query[1024]; + int rc; + MYSQL *my; + + SKIP_SKYSQL; + SKIP_MAXSCALE; + + if (!is_mariadb) + { + diag("feature not supported by MySQL server"); + return SKIP; + } + + /* check if ed25519 plugin is available */ + if (!mysql_client_find_plugin(mysql, "client_ed25519", MYSQL_CLIENT_AUTHENTICATION_PLUGIN)) + { + diag("client_ed25519 plugin not available"); + return SKIP; + } + + rc= mysql_query(mysql, "INSTALL SONAME 'auth_ed25519'"); + if (rc) + { + diag("feature not supported, ed25519 plugin not available"); + return SKIP; + } + + if (mysql_get_server_version(mysql) < 100400) { + sprintf(query, "CREATE OR REPLACE USER 'ede'@'%s' IDENTIFIED VIA ed25519 USING '6aW9C7ENlasUfymtfMvMZZtnkCVlcb1ssxOLJ0kj/AA'", this_host); + } else { + sprintf(query, "CREATE OR REPLACE USER 'ede'@'%s' IDENTIFIED VIA ed25519 USING PASSWORD('MySup8%%rPassw@ord')", this_host); + } + rc= mysql_query(mysql, query); + check_mysql_rc(rc, mysql); + + sprintf(query, "GRANT ALL ON %s.* TO 'ede'@'%s'", schema, this_host); + rc= mysql_query(mysql, query); + check_mysql_rc(rc, mysql); + + my= mysql_init(NULL); + if (plugindir) + mysql_options(my, MYSQL_PLUGIN_DIR, plugindir); + if (!my_test_connect(my, hostname, "ede", "MySup8%rPassw@ord", schema, port, socketname, 0)) + { + diag("Error: %s", mysql_error(my)); + return FAIL; + } + mysql_close(my); + + sprintf(query, "DROP USER 'ede'@'%s'", this_host); + rc= mysql_query(mysql, query); + check_mysql_rc(rc, mysql); + + sprintf(query, "UNINSTALL SONAME 'auth_ed25519'"); + rc= mysql_query(mysql, query); + check_mysql_rc(rc, mysql); + return OK; +} + +static int test_conc392(MYSQL *mysql) +{ + int rc; + const char *data; + size_t len; + ulong capabilities= 0; + + SKIP_MYSQL(mysql); + + mariadb_get_infov(mysql, MARIADB_CONNECTION_SERVER_CAPABILITIES, &capabilities); + if (!(capabilities & CLIENT_SESSION_TRACKING)) + { + diag("Server doesn't support session tracking (cap=%lu)", mysql->server_capabilities); + return SKIP; + } + + rc= mysql_query(mysql, "set session_track_state_change=1"); + check_mysql_rc(rc, mysql); + + if (mysql_session_track_get_first(mysql, SESSION_TRACK_STATE_CHANGE, &data, &len)) + { + diag("session_track_get_first failed"); + return FAIL; + } + + FAIL_IF(len != 1, "Expected length 1"); + return OK; +} + +static int test_conc443(MYSQL *my __attribute__((unused))) +{ + my_bool x= 1; + unsigned long thread_id= 0; + char query[128]; + MYSQL_RES *result; + MYSQL_ROW row; + int rc; + + MYSQL *mysql= mysql_init(NULL); + + SKIP_MAXSCALE; + + mysql_options(mysql, MYSQL_INIT_COMMAND, "set @a:=3"); + mysql_options(mysql, MYSQL_OPT_RECONNECT, &x); + + if (!my_test_connect(mysql, hostname, username, password, schema, port, socketname, CLIENT_REMEMBER_OPTIONS)) + { + diag("Connection failed. Error: %s", mysql_error(mysql)); + mysql_close(mysql); + } + + thread_id= mysql_thread_id(mysql); + + sprintf(query, "KILL %lu", thread_id); + rc= mysql_query(mysql, query); + + sleep(3); + + rc= mysql_ping(mysql); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "SELECT @a"); + check_mysql_rc(rc, mysql); + + FAIL_IF(mysql_thread_id(mysql) == thread_id, "Expected different thread id"); + + result= mysql_store_result(mysql); + if (!result) + return FAIL; + row= mysql_fetch_row(result); + FAIL_IF(strcmp(row[0],"3"), "Wrong result"); + + mysql_free_result(result); + mysql_close(mysql); + + return OK; +} + +static int test_default_auth(MYSQL *my __attribute__((unused))) +{ + MYSQL *mysql; + + SKIP_SKYSQL; + SKIP_MAXSCALE; + + if (!is_mariadb) + return SKIP; + + mysql= mysql_init(NULL); + mysql_options(mysql, MYSQL_DEFAULT_AUTH, "mysql_clear_password"); + + if (!my_test_connect(mysql, hostname, username, password, schema, port, socketname, CLIENT_REMEMBER_OPTIONS)) + { + diag("Connection failed. Error: %s", mysql_error(mysql)); + mysql_close(mysql); + return FAIL; + } + mysql_close(mysql); + + mysql= mysql_init(NULL); + mysql_options(mysql, MYSQL_DEFAULT_AUTH, "caching_sha2_password"); + + if (!my_test_connect(mysql, hostname, username, password, schema, port, socketname, CLIENT_REMEMBER_OPTIONS)) + { + diag("Connection failed. Error: %s", mysql_error(mysql)); + mysql_close(mysql); + return FAIL; + + } + mysql_close(mysql); + return OK; +} + +static int test_gtid(MYSQL *mysql) +{ + int rc; + const char *data; + size_t len; + + if (is_mariadb) + return SKIP; + + rc= mysql_query(mysql, "SET @@session.session_track_state_change=1"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "SET @@session.session_track_gtids=OWN_GTID"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "BEGIN"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1"); + check_mysql_rc(rc, mysql); + + if (!mysql_session_track_get_first(mysql, SESSION_TRACK_GTIDS, &data, &len)) + do { + printf("# SESSION_TRACK_GTIDS: %*.*s\n", (int)len, (int)len, data); + } while (!mysql_session_track_get_next(mysql, SESSION_TRACK_GTIDS, &data, &len)); + + rc= mysql_query(mysql, "CREATE TABLE t1 (a int)"); + check_mysql_rc(rc, mysql); + + if (!mysql_session_track_get_first(mysql, SESSION_TRACK_GTIDS, &data, &len)) + do { + printf("# SESSION_TRACK_GTIDS: %*.*s\n", (int)len, (int)len, data); + } while (!mysql_session_track_get_next(mysql, SESSION_TRACK_GTIDS, &data, &len)); + + rc= mysql_query(mysql, "COMMIT"); + check_mysql_rc(rc, mysql); + + return OK; +} + +static int test_conc490(MYSQL *my __attribute__((unused))) +{ + MYSQL *mysql= mysql_init(NULL); + + if (!my_test_connect(mysql, hostname, username, + password, NULL, port, socketname, CLIENT_CONNECT_WITH_DB)) + { + diag("error: %s\n", mysql_error(mysql)); + return FAIL; + } + mysql_close(mysql); + return OK; +} + +struct my_tests_st my_tests[] = { + {"test_conc490", test_conc490, TEST_CONNECTION_NONE, 0, NULL, NULL}, + {"test_gtid", test_gtid, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_conc496", test_conc496, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_default_auth", test_default_auth, TEST_CONNECTION_NONE, 0, NULL, NULL}, + {"test_conc443", test_conc443, TEST_CONNECTION_NONE, 0, NULL, NULL}, + {"test_conc366", test_conc366, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_conc392", test_conc392, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_conc312", test_conc312, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_conc351", test_conc351, TEST_CONNECTION_NONE, 0, NULL, NULL}, + {"test_conc332", test_conc332, TEST_CONNECTION_NONE, 0, NULL, NULL}, +#ifndef WIN32 + {"test_conc327", test_conc327, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_conc317", test_conc317, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, +#endif + {"test_conc315", test_conc315, TEST_CONNECTION_NEW, 0, NULL, NULL}, + {"test_expired_pw", test_expired_pw, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_conc276", test_conc276, TEST_CONNECTION_NONE, 0, NULL, NULL}, + {"test_mdev13100", test_mdev13100, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_auth256", test_auth256, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_reset", test_reset, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_unix_socket_close", test_unix_socket_close, TEST_CONNECTION_NONE, 0, NULL, NULL}, + {"test_sess_track_db", test_sess_track_db, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_get_options", test_get_options, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_wrong_bind_address", test_wrong_bind_address, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_bind_address", test_bind_address, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_conc118", test_conc118, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_conc66", test_conc66, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_bug20023", test_bug20023, TEST_CONNECTION_NEW, 0, NULL, NULL}, + {"test_bug31669", test_bug31669, TEST_CONNECTION_NEW, 0, NULL, NULL}, + {"test_bug33831", test_bug33831, TEST_CONNECTION_NEW, 0, NULL, NULL}, + {"test_change_user", test_change_user, TEST_CONNECTION_NEW, 0, NULL, NULL}, + {"test_opt_reconnect", test_opt_reconnect, TEST_CONNECTION_NONE, 0, NULL, NULL}, + {"test_compress", test_compress, TEST_CONNECTION_NONE, 0, NULL, NULL}, + {"test_reconnect", test_reconnect, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_conc21", test_conc21, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_conc26", test_conc26, TEST_CONNECTION_NONE, 0, NULL, NULL}, + {"test_connection_timeout", test_connection_timeout, TEST_CONNECTION_NONE, 0, NULL, NULL}, + {"test_connection_timeout2", test_connection_timeout2, TEST_CONNECTION_NONE, 0, NULL, NULL}, + {"test_connection_timeout3", test_connection_timeout3, TEST_CONNECTION_NONE, 0, NULL, NULL}, + {NULL, NULL, 0, 0, NULL, NULL} +}; + + +int main(int argc, char **argv) +{ + if (argc > 1) + get_options(argc, argv); + + get_envvars(); + + run_tests(my_tests); + + return(exit_status()); +} diff --git a/vendor/MDBC/unittest/libmariadb/cursor.c b/vendor/MDBC/unittest/libmariadb/cursor.c new file mode 100644 index 00000000..6378501a --- /dev/null +++ b/vendor/MDBC/unittest/libmariadb/cursor.c @@ -0,0 +1,1841 @@ +/* +Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. + +The MySQL Connector/C is licensed under the terms of the GPLv2 +, like most +MySQL Connectors. There are special exceptions to the terms and +conditions of the GPLv2 as it is applied to this software, see the +FLOSS License Exception +. + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published +by the Free Software Foundation; version 2 of the License. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ +#include "my_test.h" + +/* helper functions */ +enum { MAX_COLUMN_LENGTH= 255 }; + +typedef struct st_stmt_fetch +{ + const char *query; + unsigned stmt_no; + MYSQL_STMT *handle; + my_bool is_open; + MYSQL_BIND *bind_array; + char **out_data; + unsigned long *out_data_length; + unsigned column_count; + unsigned row_count; +} Stmt_fetch; + +MYSQL_STMT *open_cursor(MYSQL *mysql, const char *query) +{ + int rc; + const ulong type= (ulong)CURSOR_TYPE_READ_ONLY; + + MYSQL_STMT *stmt= mysql_stmt_init(mysql); + rc= mysql_stmt_prepare(stmt, SL(query)); + if (rc) { + diag("Error: %s", mysql_stmt_error(stmt)); + return NULL; + } + mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, (void*) &type); + return stmt; +} + +/* + Create statement handle, prepare it with statement, execute and allocate + fetch buffers. +*/ + +int stmt_fetch_init(MYSQL *mysql, Stmt_fetch *fetch, unsigned int stmt_no_arg, + const char *query_arg) +{ + unsigned long type= CURSOR_TYPE_READ_ONLY; + int rc; + unsigned int i; + MYSQL_RES *metadata; + + /* Save query and statement number for error messages */ + fetch->stmt_no= stmt_no_arg; + fetch->query= query_arg; + + fetch->handle= mysql_stmt_init(mysql); + + rc= mysql_stmt_prepare(fetch->handle, SL(fetch->query)); + FAIL_IF(rc, mysql_stmt_error(fetch->handle)); + + /* + The attribute is sent to server on execute and asks to open read-only + for result set + */ + mysql_stmt_attr_set(fetch->handle, STMT_ATTR_CURSOR_TYPE, + (const void*) &type); + + rc= mysql_stmt_execute(fetch->handle); + FAIL_IF(rc, mysql_stmt_error(fetch->handle)); + + /* Find out total number of columns in result set */ + metadata= mysql_stmt_result_metadata(fetch->handle); + fetch->column_count= mysql_num_fields(metadata); + mysql_free_result(metadata); + + /* + Now allocate bind handles and buffers for output data: + calloc memory to reduce number of MYSQL_BIND members we need to + set up. + */ + + fetch->bind_array= (MYSQL_BIND *) calloc(1, sizeof(MYSQL_BIND) * + fetch->column_count); + fetch->out_data= (char**) calloc(1, sizeof(char*) * fetch->column_count); + fetch->out_data_length= (ulong*) calloc(1, sizeof(ulong) * + fetch->column_count); + for (i= 0; i < fetch->column_count; ++i) + { + fetch->out_data[i]= (char*) calloc(1, MAX_COLUMN_LENGTH); + fetch->bind_array[i].buffer_type= MYSQL_TYPE_STRING; + fetch->bind_array[i].buffer= fetch->out_data[i]; + fetch->bind_array[i].buffer_length= MAX_COLUMN_LENGTH; + fetch->bind_array[i].length= fetch->out_data_length + i; + } + + mysql_stmt_bind_result(fetch->handle, fetch->bind_array); + + fetch->row_count= 0; + fetch->is_open= TRUE; + + /* Ready for reading rows */ + return OK; +} + + +int fill_tables(MYSQL *mysql, const char **query_list, unsigned query_count) +{ + int rc; + const char **query; + for (query= query_list; query < query_list + query_count; + ++query) + { + rc= mysql_query(mysql, *query); + check_mysql_rc(rc, mysql); + } + return OK; +} + +int stmt_fetch_fetch_row(Stmt_fetch *fetch) +{ + int rc; + unsigned i; + + if ((rc= mysql_stmt_fetch(fetch->handle)) == 0) + { + ++fetch->row_count; + for (i= 0; i < fetch->column_count; ++i) + { + fetch->out_data[i][fetch->out_data_length[i]]= '\0'; + } + } + else + fetch->is_open= FALSE; + + return rc; +} + +void stmt_fetch_close(Stmt_fetch *fetch) +{ + unsigned i; + + for (i= 0; i < fetch->column_count; ++i) + free(fetch->out_data[i]); + free(fetch->out_data); + free(fetch->out_data_length); + free(fetch->bind_array); + mysql_stmt_close(fetch->handle); +} + + + +enum fetch_type { USE_ROW_BY_ROW_FETCH= 0, USE_STORE_RESULT= 1 }; + +int fetch_n(MYSQL *mysql, const char **query_list, unsigned query_count, + enum fetch_type fetch_type) +{ + unsigned open_statements= query_count; + int rc, error_count= 0; + Stmt_fetch *fetch_array= (Stmt_fetch*) calloc(1, sizeof(Stmt_fetch) * + query_count); + Stmt_fetch *fetch; + + for (fetch= fetch_array; fetch < fetch_array + query_count; ++fetch) + { + if (stmt_fetch_init(mysql, fetch, (unsigned int)(fetch - fetch_array), + query_list[fetch - fetch_array])) + return FAIL; + } + + if (fetch_type == USE_STORE_RESULT) + { + for (fetch= fetch_array; fetch < fetch_array + query_count; ++fetch) + { + rc= mysql_stmt_store_result(fetch->handle); + FAIL_IF(rc, mysql_stmt_error(fetch->handle)); + } + } + + while (open_statements) + { + for (fetch= fetch_array; fetch < fetch_array + query_count; ++fetch) + { + if (fetch->is_open && (rc= stmt_fetch_fetch_row(fetch))) + { + open_statements--; + /* + We try to fetch from the rest of the statements in case of + error + */ + if (rc != MYSQL_NO_DATA) + error_count++; + } + } + } + if (!error_count) + { + unsigned total_row_count= 0; + for (fetch= fetch_array; fetch < fetch_array + query_count; ++fetch) + total_row_count+= fetch->row_count; + } + for (fetch= fetch_array; fetch < fetch_array + query_count; ++fetch) + stmt_fetch_close(fetch); + free(fetch_array); + + return (error_count) ? FAIL:OK; +} + +static int test_basic_cursors(MYSQL *mysql) +{ + const char *basic_tables[]= + { + "DROP TABLE IF EXISTS t1, t2", + + "CREATE TABLE t1 " + "(id INTEGER NOT NULL PRIMARY KEY, " + " name VARCHAR(20) NOT NULL)", + + "INSERT INTO t1 (id, name) VALUES " + " (2, 'Ja'), (3, 'Ede'), " + " (4, 'Haag'), (5, 'Kabul'), " + " (6, 'Almere'), (7, 'Utrecht'), " + " (8, 'Qandahar'), (9, 'Amsterdam'), " + " (10, 'Amersfoort'), (11, 'Constantine')", + + "CREATE TABLE t2 " + "(id INTEGER NOT NULL PRIMARY KEY, " + " name VARCHAR(20) NOT NULL)", + + "INSERT INTO t2 (id, name) VALUES " + " (4, 'Guam'), (5, 'Aruba'), " + " (6, 'Angola'), (7, 'Albania'), " + " (8, 'Anguilla'), (9, 'Argentina'), " + " (10, 'Azerbaijan'), (11, 'Afghanistan'), " + " (12, 'Burkina Faso'), (13, 'Faroe Islands')" + }; + + const char *queries[]= + { + "SELECT * FROM t1", + "SELECT * FROM t2" + }; + + + FAIL_IF(fill_tables(mysql, basic_tables, sizeof(basic_tables)/sizeof(*basic_tables)), "fill_tables failed"); + + FAIL_IF(fetch_n(mysql, queries, sizeof(queries)/sizeof(*queries), USE_ROW_BY_ROW_FETCH), "fetch_n failed"); + FAIL_IF(fetch_n(mysql, queries, sizeof(queries)/sizeof(*queries), USE_STORE_RESULT), "fetch_n failed"); + return OK; +} + + +static int test_cursors_with_union(MYSQL *mysql) +{ + const char *queries[]= + { + "SELECT t1.name FROM t1 UNION SELECT t2.name FROM t2", + "SELECT t1.id FROM t1 WHERE t1.id < 5" + }; + FAIL_IF(fetch_n(mysql, queries, sizeof(queries)/sizeof(*queries), USE_ROW_BY_ROW_FETCH), "fetch_n failed"); + FAIL_IF(fetch_n(mysql, queries, sizeof(queries)/sizeof(*queries), USE_STORE_RESULT), "fetch_n failed"); + + return OK; +} + + +static int test_cursors_with_procedure(MYSQL *mysql) +{ + const char *queries[]= + { + "SELECT * FROM t1 procedure analyse()" + }; + SKIP_MYSQL(mysql); + FAIL_IF(fetch_n(mysql, queries, sizeof(queries)/sizeof(*queries), USE_ROW_BY_ROW_FETCH), "fetch_n failed"); + FAIL_IF(fetch_n(mysql, queries, sizeof(queries)/sizeof(*queries), USE_STORE_RESULT), "fetch_n failed"); + + return OK; +} + +/* + Bug#21206: memory corruption when too many cursors are opened at once + + Memory corruption happens when more than 1024 cursors are open + simultaneously. +*/ +static int test_bug21206(MYSQL *mysql) +{ + int retcode= OK; + + const size_t cursor_count= 1025; + + const char *create_table[]= + { + "DROP TABLE IF EXISTS t1", + "CREATE TABLE t1 (i INT)", + "INSERT INTO t1 VALUES (1), (2), (3)" + }; + const char *query= "SELECT * FROM t1"; + + Stmt_fetch *fetch_array= + (Stmt_fetch*) calloc(cursor_count, sizeof(Stmt_fetch)); + + Stmt_fetch *fetch; + + FAIL_IF(fill_tables(mysql, create_table, sizeof(create_table) / sizeof(*create_table)), "fill_tables failed"); + + for (fetch= fetch_array; fetch < fetch_array + cursor_count; ++fetch) + { + if ((retcode= stmt_fetch_init(mysql, fetch, (unsigned int)(fetch - fetch_array), query))) + break; + } + + for (fetch= fetch_array; fetch < fetch_array + cursor_count; ++fetch) + stmt_fetch_close(fetch); + + free(fetch_array); + + return retcode; +} + +static int test_bug10729(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + MYSQL_BIND my_bind[1]; + char a[21]; + int rc; + const char *stmt_text; + int i= 0; + const char *name_array[3]= { "aaa", "bbb", "ccc" }; + ulong type; + + mysql_query(mysql, "drop table if exists t1"); + mysql_query(mysql, "create table t1 (id integer not null primary key," + "name VARCHAR(20) NOT NULL)"); + rc= mysql_query(mysql, "insert into t1 (id, name) values " + "(1, 'aaa'), (2, 'bbb'), (3, 'ccc')"); + check_mysql_rc(rc, mysql); + + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + + type= (ulong) CURSOR_TYPE_READ_ONLY; + rc= mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, (void*) &type); + check_stmt_rc(rc, stmt); + stmt_text= "select name from t1"; + rc= mysql_stmt_prepare(stmt, SL(stmt_text)); + check_stmt_rc(rc, stmt); + + memset(my_bind, '\0', sizeof(my_bind)); + my_bind[0].buffer_type= MYSQL_TYPE_STRING; + my_bind[0].buffer= (void*) a; + my_bind[0].buffer_length= sizeof(a); + mysql_stmt_bind_result(stmt, my_bind); + + for (i= 0; i < 3; i++) + { + int row_no= 0; + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + while ((rc= mysql_stmt_fetch(stmt)) == 0) + { + FAIL_UNLESS(strcmp(a, name_array[row_no]) == 0, "a != name_array[row_no]"); + ++row_no; + } + FAIL_UNLESS(rc == MYSQL_NO_DATA, "rc != MYSQL_NO_DATA"); + } + rc= mysql_stmt_close(stmt); + + rc= mysql_query(mysql, "drop table t1"); + check_mysql_rc(rc, mysql); + + return OK; +} + +/* Bug#10736: cursors and subqueries, memroot management */ + +static int test_bug10736(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + MYSQL_BIND my_bind[1]; + char a[21]; + int rc; + const char *stmt_text; + int i= 0; + ulong type; + + rc= mysql_query(mysql, "drop table if exists t1"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "create table t1 (id integer not null primary key," + "name VARCHAR(20) NOT NULL)"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "insert into t1 (id, name) values " + "(1, 'aaa'), (2, 'bbb'), (3, 'ccc')"); + check_mysql_rc(rc, mysql); + + stmt= mysql_stmt_init(mysql); + + type= (ulong) CURSOR_TYPE_READ_ONLY; + rc= mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, (void*) &type); + check_stmt_rc(rc, stmt); + stmt_text= "select name from t1 where name=(select name from t1 where id=2)"; + rc= mysql_stmt_prepare(stmt, SL(stmt_text)); + check_stmt_rc(rc, stmt); + + memset(my_bind, '\0', sizeof(my_bind)); + my_bind[0].buffer_type= MYSQL_TYPE_STRING; + my_bind[0].buffer= (void*) a; + my_bind[0].buffer_length= sizeof(a); + mysql_stmt_bind_result(stmt, my_bind); + + for (i= 0; i < 3; i++) + { + int row_no= 0; + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + while ((rc= mysql_stmt_fetch(stmt)) == 0) + ++row_no; + FAIL_UNLESS(rc == MYSQL_NO_DATA, "rc != MYSQL_NO_DATA"); + } + rc= mysql_stmt_close(stmt); + + rc= mysql_query(mysql, "drop table t1"); + check_mysql_rc(rc, mysql); + + return OK; +} + +/* Bug#10794: cursors, packets out of order */ + +static int test_bug10794(MYSQL *mysql) +{ + MYSQL_STMT *stmt, *stmt1; + MYSQL_BIND my_bind[2]; + char a[21]; + int id_val; + ulong a_len; + int rc; + const char *stmt_text; + int i= 0; + ulong type; + + rc= mysql_query(mysql, "drop table if exists t1"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "create table t1 (id integer not null primary key," + "name varchar(20) not null)"); + check_mysql_rc(rc, mysql); + + stmt= mysql_stmt_init(mysql); + stmt_text= "insert into t1 (id, name) values (?, ?)"; + rc= mysql_stmt_prepare(stmt, SL(stmt_text)); + check_stmt_rc(rc, stmt); + + memset(my_bind, '\0', sizeof(my_bind)); + my_bind[0].buffer_type= MYSQL_TYPE_LONG; + my_bind[0].buffer= (void*) &id_val; + my_bind[1].buffer_type= MYSQL_TYPE_STRING; + my_bind[1].buffer= (void*) a; + my_bind[1].length= &a_len; + rc= mysql_stmt_bind_param(stmt, my_bind); + check_stmt_rc(rc, stmt); + for (i= 0; i < 42; i++) + { + id_val= (i+1)*10; + sprintf(a, "a%d", i); + a_len= (unsigned long)strlen(a); /* safety against broken sprintf */ + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + } + stmt_text= "select name from t1"; + rc= mysql_stmt_prepare(stmt, SL(stmt_text)); + type= (ulong) CURSOR_TYPE_READ_ONLY; + mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, (const void*) &type); + stmt1= mysql_stmt_init(mysql); + mysql_stmt_attr_set(stmt1, STMT_ATTR_CURSOR_TYPE, (const void*) &type); + memset(my_bind, '\0', sizeof(my_bind)); + my_bind[0].buffer_type= MYSQL_TYPE_STRING; + my_bind[0].buffer= (void*) a; + my_bind[0].buffer_length= sizeof(a); + my_bind[0].length= &a_len; + rc= mysql_stmt_bind_result(stmt, my_bind); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + /* Don't optimize: an attribute of the original test case */ + mysql_stmt_free_result(stmt); + mysql_stmt_reset(stmt); + stmt_text= "select name from t1 where id=10"; + rc= mysql_stmt_prepare(stmt1, SL(stmt_text)); + check_stmt_rc(rc, stmt1); + rc= mysql_stmt_bind_result(stmt1, my_bind); + check_stmt_rc(rc, stmt1); + rc= mysql_stmt_execute(stmt1); + check_stmt_rc(rc, stmt1); + while (1) + { + rc= mysql_stmt_fetch(stmt1); + if (rc == MYSQL_NO_DATA) + { + break; + } + check_stmt_rc(rc, stmt1); + } + mysql_stmt_close(stmt); + mysql_stmt_close(stmt1); + + rc= mysql_query(mysql, "drop table t1"); + check_mysql_rc(rc, mysql); + + return OK; +} + +/* Bug#10760: cursors, crash in a fetch after rollback. */ + +static int test_bug10760(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + MYSQL_BIND my_bind[1]; + int rc; + const char *stmt_text; + char id_buf[20]; + ulong id_len; + int i= 0; + ulong type; + + rc= mysql_query(mysql, "drop table if exists t1, t2"); + check_mysql_rc(rc, mysql); + + /* create tables */ + rc= mysql_query(mysql, "create table t1 (id integer not null primary key)" + " engine=MyISAM"); + check_mysql_rc(rc, mysql);; + for (; i < 42; ++i) + { + char buf[100]; + sprintf(buf, "insert into t1 (id) values (%d)", i+1); + rc= mysql_query(mysql, buf); + check_mysql_rc(rc, mysql);; + } + mysql_autocommit(mysql, FALSE); + /* create statement */ + stmt= mysql_stmt_init(mysql); + type= (ulong) CURSOR_TYPE_READ_ONLY; + mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, (const void*) &type); + + /* + 1: check that a deadlock within the same connection + is resolved and an error is returned. The deadlock is modelled + as follows: + con1: open cursor for select * from t1; + con1: insert into t1 (id) values (1) + */ + stmt_text= "select id from t1 order by 1"; + rc= mysql_stmt_prepare(stmt, SL(stmt_text)); + check_stmt_rc(rc, stmt);; + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt);; + rc= mysql_query(mysql, "update t1 set id=id+100"); + /* + If cursors are not materialized, the update will return an error; + we mainly test that it won't deadlock. + */ + /* FAIL_IF(!rc, "Error expected"); */ + /* + 2: check that MyISAM tables used in cursors survive + COMMIT/ROLLBACK. + */ + rc= mysql_rollback(mysql); /* should not close the cursor */ + check_mysql_rc(rc, mysql);; + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt);; + + /* + 3: check that cursors to InnoDB tables are closed (for now) by + COMMIT/ROLLBACK. + */ + if (check_variable(mysql, "@@have_innodb", "YES")) + { + stmt_text= "select id from t1 order by 1"; + rc= mysql_stmt_prepare(stmt, SL(stmt_text)); + check_stmt_rc(rc, stmt);; + + rc= mysql_query(mysql, "alter table t1 engine=InnoDB"); + check_mysql_rc(rc, mysql);; + + memset(my_bind, '\0', sizeof(my_bind)); + my_bind[0].buffer_type= MYSQL_TYPE_STRING; + my_bind[0].buffer= (void*) id_buf; + my_bind[0].buffer_length= sizeof(id_buf); + my_bind[0].length= &id_len; + check_stmt_rc(rc, stmt);; + mysql_stmt_bind_result(stmt, my_bind); + + rc= mysql_stmt_execute(stmt); + rc= mysql_stmt_fetch(stmt); + FAIL_UNLESS(rc == 0, "rc != 0"); + rc= mysql_rollback(mysql); /* should close the cursor */ + } + + mysql_stmt_close(stmt); + rc= mysql_query(mysql, "drop table t1"); + check_mysql_rc(rc, mysql); + rc= mysql_autocommit(mysql, TRUE); /* restore default */ + check_mysql_rc(rc, mysql); + + return OK; +} + +/* Bug#11172: cursors, crash on a fetch from a datetime column */ + +static int test_bug11172(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + MYSQL_BIND bind_in[1], bind_out[2]; + MYSQL_TIME hired; + int rc; + const char *stmt_text; + int i= 0, id; + ulong type; + + rc= mysql_query(mysql, "drop table if exists t1"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "create table t1 (id integer not null primary key," + "hired date not null)"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, + "insert into t1 (id, hired) values (1, '1933-08-24'), " + "(2, '1965-01-01'), (3, '1949-08-17'), (4, '1945-07-07'), " + "(5, '1941-05-15'), (6, '1978-09-15'), (7, '1936-03-28')"); + check_mysql_rc(rc, mysql); + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + stmt_text= "SELECT id, hired FROM t1 WHERE hired=?"; + rc= mysql_stmt_prepare(stmt, SL(stmt_text)); + check_stmt_rc(rc, stmt); + + type= (ulong) CURSOR_TYPE_READ_ONLY; + mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, (const void*) &type); + + memset(bind_in, '\0', sizeof(bind_in)); + memset(bind_out, '\0', sizeof(bind_out)); + memset(&hired, '\0', sizeof(hired)); + hired.year= 1965; + hired.month= 1; + hired.day= 1; + bind_in[0].buffer_type= MYSQL_TYPE_DATE; + bind_in[0].buffer= (void*) &hired; + bind_in[0].buffer_length= sizeof(hired); + bind_out[0].buffer_type= MYSQL_TYPE_LONG; + bind_out[0].buffer= (void*) &id; + bind_out[1]= bind_in[0]; + + for (i= 0; i < 3; i++) + { + rc= mysql_stmt_bind_param(stmt, bind_in); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_bind_result(stmt, bind_out); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + while ((rc= mysql_stmt_fetch(stmt)) == 0); + FAIL_UNLESS(rc == MYSQL_NO_DATA, "rc != MYSQL_NO_DATA"); + if (!mysql_stmt_free_result(stmt)) + mysql_stmt_reset(stmt); + } + mysql_stmt_close(stmt); + mysql_rollback(mysql); + mysql_rollback(mysql); + + rc= mysql_query(mysql, "drop table t1"); + check_mysql_rc(rc, mysql); + + return OK; +} + +/* Bug#11656: cursors, crash on a fetch from a query with distinct. */ + +static int test_bug11656(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + MYSQL_BIND my_bind[2]; + int rc; + const char *stmt_text; + char buf[2][20]; + int i= 0; + ulong type; + + rc= mysql_query(mysql, "drop table if exists t1"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "create table t1 (" + "server varchar(40) not null, " + "test_kind varchar(1) not null, " + "test_id varchar(30) not null , " + "primary key (server,test_kind,test_id))"); + check_mysql_rc(rc, mysql); + + stmt_text= "select distinct test_kind, test_id from t1 " + "where server in (?, ?)"; + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(stmt_text)); + check_stmt_rc(rc, stmt); + type= (ulong) CURSOR_TYPE_READ_ONLY; + mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, (const void*) &type); + + memset(my_bind, '\0', sizeof(my_bind)); + strcpy(buf[0], "pcint502_MY2"); + strcpy(buf[1], "*"); + for (i=0; i < 2; i++) + { + my_bind[i].buffer_type= MYSQL_TYPE_STRING; + my_bind[i].buffer= (uchar* *)&buf[i]; + my_bind[i].buffer_length= (unsigned long)strlen(buf[i]); + } + rc= mysql_stmt_bind_param(stmt, my_bind); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_fetch(stmt); + FAIL_UNLESS(rc == MYSQL_NO_DATA, "rc != MYSQL_NO_DATA"); + + mysql_stmt_close(stmt); + rc= mysql_query(mysql, "drop table t1"); + check_mysql_rc(rc, mysql); + + return OK; +} + +/* Cursors: opening a cursor to a compilicated query with ORDER BY */ + +static int test_bug11901(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + MYSQL_BIND my_bind[2]; + int rc; + char workdept[20]; + ulong workdept_len; + uint32 empno; + const ulong type= (ulong)CURSOR_TYPE_READ_ONLY; + const char *stmt_text; + + + stmt_text= "drop table if exists t1, t2"; + rc= mysql_real_query(mysql, SL(stmt_text)); + check_mysql_rc(rc, mysql); + + stmt_text= "create table t1 (" + " empno int(11) not null, firstname varchar(20) not null," + " midinit varchar(20) not null, lastname varchar(20) not null," + " workdept varchar(6) not null, salary double not null," + " bonus float not null, primary key (empno), " + " unique key (workdept, empno) " + ") default charset=latin1 collate=latin1_bin"; + rc= mysql_real_query(mysql, SL(stmt_text)); + check_mysql_rc(rc, mysql); + + stmt_text= "insert into t1 values " + "(10, 'CHRISTINE', 'I', 'HAAS', 'A00', 52750, 1000)," + "(20, 'MICHAEL', 'L', 'THOMPSON', 'B01', 41250, 800), " + "(30, 'SALLY', 'A', 'KWAN', 'C01', 38250, 800), " + "(50, 'JOHN', 'B', 'GEYER', 'E01', 40175, 800), " + "(60, 'IRVING', 'F', 'STERN', 'D11', 32250, 500), " + "(70, 'EVA', 'D', 'PULASKI', 'D21', 36170, 700), " + "(90, 'EILEEN', 'W', 'HENDERSON', 'E11', 29750, 600), " + "(100, 'THEODORE', 'Q', 'SPENSER', 'E21', 26150, 500), " + "(110, 'VINCENZO', 'G', 'LUCCHESSI', 'A00', 46500, 900), " + "(120, 'SEAN', '', 'O\\'CONNELL', 'A00', 29250, 600), " + "(130, 'DOLORES', 'M', 'QUINTANA', 'C01', 23800, 500), " + "(140, 'HEATHER', 'A', 'NICHOLLS', 'C01', 28420, 600), " + "(150, 'BRUCE', '', 'ADAMSON', 'D11', 25280, 500), " + "(160, 'ELIZABETH', 'R', 'PIANKA', 'D11', 22250, 400), " + "(170, 'MASATOSHI', 'J', 'YOSHIMURA', 'D11', 24680, 500), " + "(180, 'MARILYN', 'S', 'SCOUTTEN', 'D11', 21340, 500), " + "(190, 'JAMES', 'H', 'WALKER', 'D11', 20450, 400), " + "(200, 'DAVID', '', 'BROWN', 'D11', 27740, 600), " + "(210, 'WILLIAM', 'T', 'JONES', 'D11', 18270, 400), " + "(220, 'JENNIFER', 'K', 'LUTZ', 'D11', 29840, 600), " + "(230, 'JAMES', 'J', 'JEFFERSON', 'D21', 22180, 400), " + "(240, 'SALVATORE', 'M', 'MARINO', 'D21', 28760, 600), " + "(250, 'DANIEL', 'S', 'SMITH', 'D21', 19180, 400), " + "(260, 'SYBIL', 'P', 'JOHNSON', 'D21', 17250, 300), " + "(270, 'MARIA', 'L', 'PEREZ', 'D21', 27380, 500), " + "(280, 'ETHEL', 'R', 'SCHNEIDER', 'E11', 26250, 500), " + "(290, 'JOHN', 'R', 'PARKER', 'E11', 15340, 300), " + "(300, 'PHILIP', 'X', 'SMITH', 'E11', 17750, 400), " + "(310, 'MAUDE', 'F', 'SETRIGHT', 'E11', 15900, 300), " + "(320, 'RAMLAL', 'V', 'MEHTA', 'E21', 19950, 400), " + "(330, 'WING', '', 'LEE', 'E21', 25370, 500), " + "(340, 'JASON', 'R', 'GOUNOT', 'E21', 23840, 500)"; + + rc= mysql_real_query(mysql, SL(stmt_text)); + check_mysql_rc(rc, mysql); + + stmt_text= "create table t2 (" + " deptno varchar(6) not null, deptname varchar(20) not null," + " mgrno int(11) not null, location varchar(20) not null," + " admrdept varchar(6) not null, refcntd int(11) not null," + " refcntu int(11) not null, primary key (deptno)" + ") default charset=latin1 collate=latin1_bin"; + rc= mysql_real_query(mysql, SL(stmt_text)); + check_mysql_rc(rc, mysql); + + stmt_text= "insert into t2 values " + "('A00', 'SPIFFY COMPUTER SERV', 10, '', 'A00', 0, 0), " + "('B01', 'PLANNING', 20, '', 'A00', 0, 0), " + "('C01', 'INFORMATION CENTER', 30, '', 'A00', 0, 0), " + "('D01', 'DEVELOPMENT CENTER', 0, '', 'A00', 0, 0)," + "('D11', 'MANUFACTURING SYSTEM', 60, '', 'D01', 0, 0), " + "('D21', 'ADMINISTRATION SYSTE', 70, '', 'D01', 0, 0), " + "('E01', 'SUPPORT SERVICES', 50, '', 'A00', 0, 0), " + "('E11', 'OPERATIONS', 90, '', 'E01', 0, 0), " + "('E21', 'SOFTWARE SUPPORT', 100,'', 'E01', 0, 0)"; + rc= mysql_real_query(mysql, SL(stmt_text)); + check_mysql_rc(rc, mysql); + + stmt_text= "select t1.empno, t1.workdept " + "from (t1 left join t2 on t2.deptno = t1.workdept) " + "where t2.deptno in " + " (select t2.deptno " + " from (t1 left join t2 on t2.deptno = t1.workdept) " + " where t1.empno = ?) " + "order by 1"; + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(stmt_text)); + check_stmt_rc(rc, stmt); + mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, (void*) &type); + check_stmt_rc(rc, stmt); + + + memset(my_bind, '\0', sizeof(my_bind)); + + my_bind[0].buffer_type= MYSQL_TYPE_LONG; + my_bind[0].buffer= &empno; + rc= mysql_stmt_bind_param(stmt, my_bind); + check_stmt_rc(rc, stmt); + + my_bind[1].buffer_type= MYSQL_TYPE_VAR_STRING; + my_bind[1].buffer= (void*) workdept; + my_bind[1].buffer_length= sizeof(workdept); + my_bind[1].length= &workdept_len; + + rc= mysql_stmt_bind_result(stmt, my_bind); + check_stmt_rc(rc, stmt); + + empno= 10; + + /* ERROR: next statement causes a server crash */ + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + mysql_stmt_close(stmt); + + rc= mysql_query(mysql, "drop table t1, t2"); + check_mysql_rc(rc, mysql); + + return OK; +} + +/* Bug#11904: mysql_stmt_attr_set CURSOR_TYPE_READ_ONLY grouping wrong result */ + +static int test_bug11904(MYSQL *mysql) +{ + MYSQL_STMT *stmt1; + int rc; + const char *stmt_text; + const ulong type= (ulong)CURSOR_TYPE_READ_ONLY; + MYSQL_BIND my_bind[2]; + int country_id=0; + char row_data[11]= {0}; + + /* create tables */ + rc= mysql_query(mysql, "DROP TABLE IF EXISTS bug11904b"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "CREATE TABLE bug11904b (id int, name char(10), primary key(id, name))"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "INSERT INTO bug11904b VALUES (1, 'sofia'), (1,'plovdiv')," + " (1,'varna'), (2,'LA'), (2,'new york'), (3,'heidelberg')," + " (3,'berlin'), (3, 'frankfurt')"); + + check_mysql_rc(rc, mysql); + mysql_commit(mysql); + /* create statement */ + stmt1= mysql_stmt_init(mysql); + mysql_stmt_attr_set(stmt1, STMT_ATTR_CURSOR_TYPE, (const void*) &type); + + stmt_text= "SELECT id, MIN(name) FROM bug11904b GROUP BY id ORDER BY id"; + + rc= mysql_stmt_prepare(stmt1, SL(stmt_text)); + check_stmt_rc(rc, stmt1); + + memset(my_bind, 0, sizeof(my_bind)); + my_bind[0].buffer_type= MYSQL_TYPE_LONG; + my_bind[0].buffer=& country_id; + my_bind[0].buffer_length= 0; + my_bind[0].length= 0; + + my_bind[1].buffer_type= MYSQL_TYPE_STRING; + my_bind[1].buffer=& row_data; + my_bind[1].buffer_length= sizeof(row_data) - 1; + my_bind[1].length= 0; + + rc= mysql_stmt_bind_result(stmt1, my_bind); + check_stmt_rc(rc, stmt1); + + rc= mysql_stmt_execute(stmt1); + check_stmt_rc(rc, stmt1); + + rc= mysql_stmt_fetch(stmt1); + check_stmt_rc(rc, stmt1); + FAIL_UNLESS(country_id == 1, "country_id != 1"); + FAIL_UNLESS(memcmp(row_data, "plovdiv", 7) == 0, "row_data != 'plovdiv'"); + + rc= mysql_stmt_fetch(stmt1); + check_stmt_rc(rc, stmt1); + FAIL_UNLESS(country_id == 2, "country_id != 2"); + FAIL_UNLESS(memcmp(row_data, "LA", 2) == 0, "row_data != 'LA'"); + + rc= mysql_stmt_fetch(stmt1); + check_stmt_rc(rc, stmt1); + FAIL_UNLESS(country_id == 3, "country_id != 3"); + FAIL_UNLESS(memcmp(row_data, "berlin", 6) == 0, "row_data != 'Berlin'"); + + rc= mysql_stmt_close(stmt1); + check_stmt_rc(rc, stmt1); + + rc= mysql_query(mysql, "drop table bug11904b"); + check_mysql_rc(rc, mysql); + + return OK; +} + + +/* Bug#12243: multiple cursors, crash in a fetch after commit. */ + +static int test_bug12243(MYSQL *mysql) +{ + MYSQL_STMT *stmt1, *stmt2; + int rc; + const char *stmt_text; + ulong type; + + if (!check_variable(mysql, "@@have_innodb", "YES")) + { + diag("Skip -> Test required InnoDB"); + return SKIP; + } + + /* create tables */ + rc= mysql_query(mysql, "drop table if exists t1"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "create table t1 (a int) engine=InnoDB"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "insert into t1 (a) values (1), (2)"); + check_mysql_rc(rc, mysql); + mysql_autocommit(mysql, FALSE); + /* create statement */ + stmt1= mysql_stmt_init(mysql); + stmt2= mysql_stmt_init(mysql); + type= (ulong) CURSOR_TYPE_READ_ONLY; + rc= mysql_stmt_attr_set(stmt1, STMT_ATTR_CURSOR_TYPE, (const void*) &type); + check_stmt_rc(rc, stmt1); + rc= mysql_stmt_attr_set(stmt2, STMT_ATTR_CURSOR_TYPE, (const void*) &type); + check_stmt_rc(rc, stmt1); + + stmt_text= "select a from t1"; + + rc= mysql_stmt_prepare(stmt1, SL(stmt_text)); + check_stmt_rc(rc, stmt1); + rc= mysql_stmt_execute(stmt1); + check_stmt_rc(rc, stmt1); + rc= mysql_stmt_fetch(stmt1); + check_stmt_rc(rc, stmt1); + + rc= mysql_stmt_prepare(stmt2, SL(stmt_text)); + check_stmt_rc(rc, stmt2); + rc= mysql_stmt_execute(stmt2); + check_stmt_rc(rc, stmt2); + rc= mysql_stmt_fetch(stmt2); + check_stmt_rc(rc, stmt2); + + rc= mysql_stmt_close(stmt1); + check_stmt_rc(rc, stmt1); + rc= mysql_commit(mysql); + check_mysql_rc(rc, mysql); + rc= mysql_stmt_fetch(stmt2); + check_stmt_rc(rc, stmt2); + + mysql_stmt_close(stmt2); + rc= mysql_query(mysql, "drop table t1"); + check_mysql_rc(rc, mysql); + mysql_autocommit(mysql, TRUE); /* restore default */ + + return OK; +} + +/* Bug#11909: wrong metadata if fetching from two cursors */ + +static int test_bug11909(MYSQL *mysql) +{ + MYSQL_STMT *stmt1, *stmt2; + MYSQL_BIND my_bind[7]; + int rc; + char firstname[20], midinit[20], lastname[20], workdept[20]; + ulong firstname_len, midinit_len, lastname_len, workdept_len; + uint32 empno; + double salary; + float bonus; + const char *stmt_text; + const ulong type= (ulong)CURSOR_TYPE_READ_ONLY; + + + stmt_text= "drop table if exists t1"; + rc= mysql_real_query(mysql, SL(stmt_text)); + check_mysql_rc(rc, mysql); + + stmt_text= "create table t1 (" + " empno int(11) not null, firstname varchar(20) not null," + " midinit varchar(20) not null, lastname varchar(20) not null," + " workdept varchar(6) not null, salary double not null," + " bonus float not null, primary key (empno)" + ") default charset=latin1 collate=latin1_bin"; + rc= mysql_real_query(mysql, SL(stmt_text)); + check_mysql_rc(rc, mysql); + + stmt_text= "insert into t1 values " + "(10, 'CHRISTINE', 'I', 'HAAS', 'A00', 52750, 1000), " + "(20, 'MICHAEL', 'L', 'THOMPSON', 'B01', 41250, 800)," + "(30, 'SALLY', 'A', 'KWAN', 'C01', 38250, 800)," + "(50, 'JOHN', 'B', 'GEYER', 'E01', 40175, 800), " + "(60, 'IRVING', 'F', 'STERN', 'D11', 32250, 500)"; + rc= mysql_real_query(mysql, SL(stmt_text)); + check_mysql_rc(rc, mysql); + + /* ****** Begin of trace ****** */ + + stmt_text= "SELECT empno, firstname, midinit, lastname," + "workdept, salary, bonus FROM t1 ORDER BY empno"; + stmt1= mysql_stmt_init(mysql); + FAIL_IF(!stmt1, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt1, SL(stmt_text)); + check_stmt_rc(rc, stmt1); + mysql_stmt_attr_set(stmt1, STMT_ATTR_CURSOR_TYPE, + (const void*) &type); + + memset(my_bind, '\0', sizeof(my_bind)); + my_bind[0].buffer_type= MYSQL_TYPE_LONG; + my_bind[0].buffer= (void*) &empno; + + my_bind[1].buffer_type= MYSQL_TYPE_VAR_STRING; + my_bind[1].buffer= (void*) firstname; + my_bind[1].buffer_length= sizeof(firstname); + my_bind[1].length= &firstname_len; + + my_bind[2].buffer_type= MYSQL_TYPE_VAR_STRING; + my_bind[2].buffer= (void*) midinit; + my_bind[2].buffer_length= sizeof(midinit); + my_bind[2].length= &midinit_len; + + my_bind[3].buffer_type= MYSQL_TYPE_VAR_STRING; + my_bind[3].buffer= (void*) lastname; + my_bind[3].buffer_length= sizeof(lastname); + my_bind[3].length= &lastname_len; + + my_bind[4].buffer_type= MYSQL_TYPE_VAR_STRING; + my_bind[4].buffer= (void*) workdept; + my_bind[4].buffer_length= sizeof(workdept); + my_bind[4].length= &workdept_len; + + my_bind[5].buffer_type= MYSQL_TYPE_DOUBLE; + my_bind[5].buffer= (void*) &salary; + + my_bind[6].buffer_type= MYSQL_TYPE_FLOAT; + my_bind[6].buffer= (void*) &bonus; + rc= mysql_stmt_bind_result(stmt1, my_bind); + check_stmt_rc(rc, stmt1); + + rc= mysql_stmt_execute(stmt1); + check_stmt_rc(rc, stmt1); + + rc= mysql_stmt_fetch(stmt1); + FAIL_UNLESS(rc == 0, "rc != 0"); + FAIL_UNLESS(empno == 10, "empno != 10"); + FAIL_UNLESS(strcmp(firstname, "CHRISTINE""") == 0, "firstname != 'Christine'"); + FAIL_UNLESS(strcmp(midinit, "I""") == 0, ""); + FAIL_UNLESS(strcmp(lastname, "HAAS""") == 0, "lastname != 'HAAS'"); + FAIL_UNLESS(strcmp(workdept, "A00""") == 0, "workdept != 'A00'"); + FAIL_UNLESS(salary == (double) 52750.0, "salary != 52750"); + FAIL_UNLESS(bonus == (float) 1000.0, "bonus =! 1000"); + + stmt_text = "SELECT empno, firstname FROM t1"; + stmt2= mysql_stmt_init(mysql); + FAIL_IF(!stmt2, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt2, SL(stmt_text)); + check_stmt_rc(rc, stmt2); + mysql_stmt_attr_set(stmt2, STMT_ATTR_CURSOR_TYPE, + (const void*) &type); + rc= mysql_stmt_bind_result(stmt2, my_bind); + check_stmt_rc(rc, stmt2); + + rc= mysql_stmt_execute(stmt2); + check_stmt_rc(rc, stmt2); + + rc= mysql_stmt_fetch(stmt2); + FAIL_UNLESS(rc == 0, "rc != 0"); + + FAIL_UNLESS(empno == 10, "empno != 10"); + FAIL_UNLESS(strcmp(firstname, "CHRISTINE""") == 0, "firstname != 'Christine'"); + + rc= mysql_stmt_reset(stmt2); + check_stmt_rc(rc, stmt2); + + /* ERROR: next statement should return 0 */ + + rc= mysql_stmt_fetch(stmt1); + FAIL_UNLESS(rc == 0, "rc != 0"); + + mysql_stmt_close(stmt1); + mysql_stmt_close(stmt2); + rc= mysql_rollback(mysql); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "drop table t1"); + check_mysql_rc(rc, mysql); + + return OK; +} + +/* Bug#13488: wrong column metadata when fetching from cursor */ + +static int test_bug13488(MYSQL *mysql) +{ + MYSQL_BIND my_bind[3]; + MYSQL_STMT *stmt1; + int rc, f1, f2, f3, i; + const ulong type= CURSOR_TYPE_READ_ONLY; + const char *query= "select f1, f2, f3 from t1 left join t2 on f1=f2 where f1=1"; + + + rc= mysql_query(mysql, "drop table if exists t1, t2"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "create table t1 (f1 int not null primary key)"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "create table t2 (f2 int not null primary key, " + "f3 int not null)"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "insert into t1 values (1), (2)"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "insert into t2 values (1,2), (2,4)"); + check_mysql_rc(rc, mysql); + + memset(my_bind, 0, sizeof(my_bind)); + for (i= 0; i < 3; i++) + { + my_bind[i].buffer_type= MYSQL_TYPE_LONG; + my_bind[i].buffer_length= 4; + my_bind[i].length= 0; + } + my_bind[0].buffer=&f1; + my_bind[1].buffer=&f2; + my_bind[2].buffer=&f3; + + stmt1= mysql_stmt_init(mysql); + rc= mysql_stmt_attr_set(stmt1,STMT_ATTR_CURSOR_TYPE, (const void *)&type); + check_stmt_rc(rc, stmt1); + + rc= mysql_stmt_prepare(stmt1, SL(query)); + check_stmt_rc(rc, stmt1); + + rc= mysql_stmt_execute(stmt1); + check_stmt_rc(rc, stmt1); + + rc= mysql_stmt_bind_result(stmt1, my_bind); + check_stmt_rc(rc, stmt1); + + rc= mysql_stmt_fetch(stmt1); + check_stmt_rc(rc, stmt1); + + rc= mysql_stmt_free_result(stmt1); + check_stmt_rc(rc, stmt1); + + rc= mysql_stmt_reset(stmt1); + check_stmt_rc(rc, stmt1); + + rc= mysql_stmt_close(stmt1); + check_stmt_rc(rc, stmt1); + + FAIL_UNLESS(f1 == 1, "f1 != 1"); + FAIL_UNLESS(f2 == 1, "f2 != 1"); + FAIL_UNLESS(f3 == 2, "f3 != 2"); + rc= mysql_query(mysql, "drop table t1, t2"); + check_mysql_rc(rc, mysql); + + return OK; +} + +/* + Bug#13524: warnings of a previous command are not reset when fetching + from a cursor. +*/ + +static int test_bug13524(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + int rc; + unsigned int warning_count; + const ulong type= CURSOR_TYPE_READ_ONLY; + const char *query= "select * from t1"; + + + rc= mysql_query(mysql, "drop table if exists t1, t2"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "create table t1 (a int not null primary key)"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "insert into t1 values (1), (2), (3), (4)"); + check_mysql_rc(rc, mysql); + + stmt= mysql_stmt_init(mysql); + rc= mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, (const void*) &type); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + + warning_count= mysql_warning_count(mysql); + FAIL_UNLESS(warning_count == 0, "warning_count != 0"); + + /* Check that DROP TABLE produced a warning (no such table) */ + rc= mysql_query(mysql, "drop table if exists t2"); + check_mysql_rc(rc, mysql); + warning_count= mysql_warning_count(mysql); + FAIL_UNLESS(warning_count == 1, "warning_count != 1"); + + /* + Check that fetch from a cursor cleared the warning from the previous + command. + */ + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + warning_count= mysql_warning_count(mysql); + FAIL_UNLESS(warning_count == 0, "warning_count != 0"); + + /* Cleanup */ + mysql_stmt_close(stmt); + rc= mysql_query(mysql, "drop table t1"); + check_mysql_rc(rc, mysql); + + return OK; +} + +/* + Bug#14845 "mysql_stmt_fetch returns MYSQL_NO_DATA when COUNT(*) is 0" +*/ + +static int test_bug14845(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + int rc; + const ulong type= CURSOR_TYPE_READ_ONLY; + const char *query= "select count(*) from t1 where 1 = 0"; + + + rc= mysql_query(mysql, "drop table if exists t1"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "create table t1 (id int(11) default null, " + "name varchar(20) default null)" + "engine=MyISAM DEFAULT CHARSET=utf8"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "insert into t1 values (1,'abc'),(2,'def')"); + check_mysql_rc(rc, mysql); + + stmt= mysql_stmt_init(mysql); + rc= mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, (const void*) &type); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_fetch(stmt); + FAIL_UNLESS(rc == 0, ""); + + rc= mysql_stmt_fetch(stmt); + FAIL_UNLESS(rc == MYSQL_NO_DATA, ""); + + /* Cleanup */ + mysql_stmt_close(stmt); + rc= mysql_query(mysql, "drop table t1"); + check_mysql_rc(rc, mysql); + return OK; +} + +/* + Bug#14210 "Simple query with > operator on large table gives server + crash" +*/ + +static int test_bug14210(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + int rc, i; + const char *stmt_text; + ulong type; + + rc= mysql_query(mysql, "drop table if exists t1"); + check_mysql_rc(rc, mysql); + /* + To trigger the problem the table must be InnoDB, although the problem + itself is not InnoDB related. In case the table is MyISAM this test + is harmless. + */ + rc= mysql_query(mysql, "create table t1 (a varchar(255)) engine=InnoDB"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "insert into t1 (a) values (repeat('a', 256))"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "set @@session.max_heap_table_size=16384"); + + /* Create a big enough table (more than max_heap_table_size) */ + for (i= 0; i < 8; i++) + { + rc= mysql_query(mysql, "insert into t1 (a) select a from t1"); + check_mysql_rc(rc, mysql); + } + /* create statement */ + stmt= mysql_stmt_init(mysql); + type= (ulong) CURSOR_TYPE_READ_ONLY; + mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, (const void*) &type); + + stmt_text= "select a from t1"; + + rc= mysql_stmt_prepare(stmt, SL(stmt_text)); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_execute(stmt); + while ((rc= mysql_stmt_fetch(stmt)) == 0); + FAIL_UNLESS(rc == MYSQL_NO_DATA, "rc != MYSQL_NO_DATA"); + + rc= mysql_stmt_close(stmt); + + rc= mysql_query(mysql, "drop table t1"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "set @@session.max_heap_table_size=default"); + check_mysql_rc(rc, mysql); + + return OK; +} + +/* + Bug#24179 "select b into $var" fails with --cursor_protocol" + The failure is correct, check that the returned message is meaningful. +*/ + +static int test_bug24179(MYSQL *mysql) +{ + int rc; + MYSQL_STMT *stmt; + + stmt= open_cursor(mysql, "select 1 into @a"); + rc= mysql_stmt_execute(stmt); + FAIL_UNLESS(rc, "Error expected"); + FAIL_UNLESS(mysql_stmt_errno(stmt) == 1323, "stmt_errno != 1323"); + mysql_stmt_close(stmt); + + return OK; +} + +/** + Bug#32265 Server returns different metadata if prepared statement is used +*/ + +static int test_bug32265(MYSQL *mysql) +{ + int rc; + MYSQL_STMT *stmt; + MYSQL_FIELD *field; + MYSQL_RES *metadata; + + if (mysql_get_server_version(mysql) < 50100) { + diag("Test requires MySQL Server version 5.1 or above"); + return SKIP; + } + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "DROP VIEW IF EXISTS v1"); + rc= mysql_query(mysql, "CREATE TABLE t1 (a INTEGER)"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "INSERT INTO t1 VALUES (1)"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "CREATE VIEW v1 AS SELECT * FROM t1"); + check_mysql_rc(rc, mysql); + + stmt= open_cursor(mysql, "SELECT * FROM t1"); + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + metadata= mysql_stmt_result_metadata(stmt); + field= mysql_fetch_field(metadata); + FAIL_UNLESS(field, "couldn't fetch field"); + FAIL_UNLESS(strcmp(field->table, "t1") == 0, "table != t1"); + FAIL_UNLESS(strcmp(field->org_table, "t1") == 0, "org_table != t1"); + FAIL_UNLESS(strcmp(field->db, schema) == 0, "db != schema"); + mysql_free_result(metadata); + mysql_stmt_close(stmt); + + stmt= open_cursor(mysql, "SELECT a '' FROM t1 ``"); + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + metadata= mysql_stmt_result_metadata(stmt); + field= mysql_fetch_field(metadata); + FAIL_UNLESS(strcmp(field->table, "") == 0, "field != ''"); + FAIL_UNLESS(strcmp(field->org_table, "t1") == 0, "org_table != t1"); + FAIL_UNLESS(strcmp(field->db, schema) == 0, "db != schema"); + mysql_free_result(metadata); + mysql_stmt_close(stmt); + + stmt= open_cursor(mysql, "SELECT a '' FROM t1 ``"); + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + metadata= mysql_stmt_result_metadata(stmt); + field= mysql_fetch_field(metadata); + FAIL_UNLESS(strcmp(field->table, "") == 0, "table != ''"); + FAIL_UNLESS(strcmp(field->org_table, "t1") == 0, "org_table != t1"); + FAIL_UNLESS(strcmp(field->db, schema) == 0, "db != schema"); + mysql_free_result(metadata); + mysql_stmt_close(stmt); + + stmt= open_cursor(mysql, "SELECT * FROM v1"); + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + metadata= mysql_stmt_result_metadata(stmt); + field= mysql_fetch_field(metadata); + FAIL_UNLESS(strcmp(field->table, "v1") == 0, "table != v1"); + FAIL_UNLESS(strcmp(field->org_table, "v1") == 0, "org_table != v1"); + FAIL_UNLESS(strcmp(field->db, schema) == 0, "db != schema"); + mysql_free_result(metadata); + mysql_stmt_close(stmt); + + stmt= open_cursor(mysql, "SELECT * FROM v1 /* SIC */ GROUP BY 1"); + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + metadata= mysql_stmt_result_metadata(stmt); + field= mysql_fetch_field(metadata); + FAIL_UNLESS(strcmp(field->table, "v1") == 0, "table != v1"); + FAIL_UNLESS(strcmp(field->org_table, "v1") == 0, "org_table != v1"); + FAIL_UNLESS(strcmp(field->db, schema) == 0, "schema != db"); + mysql_free_result(metadata); + mysql_stmt_close(stmt); + + rc= mysql_query(mysql, "DROP VIEW v1"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "DROP TABLE t1"); + check_mysql_rc(rc, mysql); + + return OK; +} + +/** + Bug#38486 Crash when using cursor protocol +*/ + +static int test_bug38486(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + const char *stmt_text; + int rc; + unsigned long type= CURSOR_TYPE_READ_ONLY; + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS t10"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE t10 (a INT)"); + check_mysql_rc(rc, mysql); + + stmt= mysql_stmt_init(mysql); + rc= mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, (void*)&type); + check_stmt_rc(rc, stmt); + stmt_text= "INSERT INTO t10 VALUES (1)"; + rc= mysql_stmt_prepare(stmt, SL(stmt_text)); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + mysql_stmt_close(stmt); + + return OK; +} + +static int test_bug8880(MYSQL *mysql) +{ + MYSQL_STMT *stmt_list[2], **stmt; + MYSQL_STMT **stmt_list_end= (MYSQL_STMT**) stmt_list + 2; + int rc; + + + rc= mysql_query(mysql, "drop table if exists t1"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "create table t1 (a int not null primary key, b int)"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "insert into t1 values (1,1)"); + check_mysql_rc(rc, mysql); + /* + when inserting 2 rows everything works well + mysql_query(mysql, "INSERT INTO t1 VALUES (1,1),(2,2)"); + */ + for (stmt= stmt_list; stmt < stmt_list_end; stmt++) + *stmt= open_cursor(mysql, "select a from t1"); + for (stmt= stmt_list; stmt < stmt_list_end; stmt++) + { + rc= mysql_stmt_execute(*stmt); + check_stmt_rc(rc, *stmt); + } + for (stmt= stmt_list; stmt < stmt_list_end; stmt++) + mysql_stmt_close(*stmt); + return OK; +} + +static int test_bug9159(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + int rc; + const char *stmt_text= "select a, b from t1"; + const unsigned long type= CURSOR_TYPE_READ_ONLY; + + + mysql_query(mysql, "drop table if exists t1"); + mysql_query(mysql, "create table t1 (a int not null primary key, b int)"); + rc= mysql_query(mysql, "insert into t1 values (1,1)"); + check_mysql_rc(rc, mysql); + + stmt= mysql_stmt_init(mysql); + mysql_stmt_prepare(stmt, SL(stmt_text)); + mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, (const void *)&type); + + mysql_stmt_execute(stmt); + mysql_stmt_close(stmt); + rc= mysql_query(mysql, "drop table if exists t1"); + check_mysql_rc(rc, mysql); + return OK; +} + +/* + We can't have more than one cursor open for a prepared statement. + Test re-executions of a PS with cursor; mysql_stmt_reset must close + the cursor attached to the statement, if there is one. +*/ + +static int test_bug9478(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + MYSQL_BIND my_bind[1]; + char a[6]; + ulong a_len; + int rc, i; + + mysql_query(mysql, "drop table if exists t1"); + mysql_query(mysql, "create table t1 (id integer not null primary key, " + " name varchar(20) not null)"); + rc= mysql_query(mysql, "insert into t1 (id, name) values " + " (1, 'aaa'), (2, 'bbb'), (3, 'ccc')"); + check_mysql_rc(rc, mysql); + + stmt= open_cursor(mysql, "select name from t1 where id=2"); + + memset(my_bind, '\0', sizeof(my_bind)); + my_bind[0].buffer_type= MYSQL_TYPE_STRING; + my_bind[0].buffer= (char*) a; + my_bind[0].buffer_length= sizeof(a); + my_bind[0].length= &a_len; + mysql_stmt_bind_result(stmt, my_bind); + + for (i= 0; i < 5; i++) + { + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + + /* + The query above is a one-row result set. Therefore, there is no + cursor associated with it, as the server won't bother with opening + a cursor for a one-row result set. The first row was read from the + server in the fetch above. But there is eof packet pending in the + network. mysql_stmt_execute will flush the packet and successfully + execute the statement. + */ + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_fetch(stmt); + FAIL_UNLESS(rc == MYSQL_NO_DATA, "rc != MYSQL_NO_DATA"); + + { + char buff[8]; + /* Fill in the fetch packet */ + int4store(buff, stmt->stmt_id); + buff[4]= 1; /* prefetch rows */ +/* rc= ((*mysql->methods->advanced_command)(mysql, COM_STMT_FETCH, + (uchar*) buff, + sizeof(buff), 0,0,1,NULL) || + (*mysql->methods->read_query_result)(mysql)); */ + FAIL_UNLESS(rc, "error expected"); + } + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_reset(stmt); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_fetch(stmt); + + /* mariadb client supports GEOMETRY, so no error will + be returned + FAIL_UNLESS(rc && mysql_stmt_errno(stmt), "Error expected"); + */ + } + rc= mysql_stmt_close(stmt); + check_stmt_rc(rc, stmt); + + /* Test the case with a server side cursor */ + stmt= open_cursor(mysql, "select name from t1"); + + mysql_stmt_bind_result(stmt, my_bind); + + for (i= 0; i < 5; i++) + { + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + while (! (rc= mysql_stmt_fetch(stmt))); + FAIL_UNLESS(rc == MYSQL_NO_DATA, "rc != MYSQL_NO_DATA"); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_reset(stmt); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_fetch(stmt); + FAIL_UNLESS(rc && mysql_stmt_errno(stmt), "Error expected"); + } + + rc= mysql_stmt_close(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_query(mysql, "drop table t1"); + check_mysql_rc(rc, mysql); + return OK; +} + +/* Crash when opening a cursor to a query with DISTICNT and no key */ + +static int test_bug9520(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + MYSQL_BIND my_bind[1]; + char a[6]; + ulong a_len; + int rc, row_count= 0; + + + mysql_query(mysql, "drop table if exists t1"); + mysql_query(mysql, "create table t1 (a char(5), b char(5), c char(5)," + " primary key (a, b, c))"); + rc= mysql_query(mysql, "insert into t1 values ('x', 'y', 'z'), " + " ('a', 'b', 'c'), ('k', 'l', 'm')"); + check_mysql_rc(rc, mysql); + + stmt= open_cursor(mysql, "select distinct b from t1"); + + /* + Not crashes with: + stmt= open_cursor(mysql, "select distinct a from t1"); + */ + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + memset(my_bind, '\0', sizeof(my_bind)); + my_bind[0].buffer_type= MYSQL_TYPE_STRING; + my_bind[0].buffer= (char*) a; + my_bind[0].buffer_length= sizeof(a); + my_bind[0].length= &a_len; + + mysql_stmt_bind_result(stmt, my_bind); + + while (!(rc= mysql_stmt_fetch(stmt))) + row_count++; + + FAIL_UNLESS(rc == MYSQL_NO_DATA, "rc != MYSQL_NO_DATA"); + + FAIL_UNLESS(row_count == 3, "row_count != 3"); + + mysql_stmt_close(stmt); + + rc= mysql_query(mysql, "drop table t1"); + check_mysql_rc(rc, mysql); + return OK; +} + +/* + Error message is returned for unsupported features. + Test also cursors with non-default PREFETCH_ROWS +*/ + +static int test_bug9643(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + MYSQL_BIND my_bind[1]; + int32 a; + int rc; + const char *stmt_text; + int num_rows= 0; + ulong type; + ulong prefetch_rows= 5; + + + mysql_query(mysql, "drop table if exists t1"); + mysql_query(mysql, "create table t1 (id integer not null primary key)"); + rc= mysql_query(mysql, "insert into t1 (id) values " + " (1), (2), (3), (4), (5), (6), (7), (8), (9)"); + check_mysql_rc(rc, mysql); + + stmt= mysql_stmt_init(mysql); + /* Not implemented in 5.0 */ + type= (ulong) CURSOR_TYPE_SCROLLABLE; + rc= mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, (void*) &type); + FAIL_UNLESS(rc, "Error expected"); + + type= (ulong) CURSOR_TYPE_READ_ONLY; + rc= mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, (void*) &type); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_attr_set(stmt, STMT_ATTR_PREFETCH_ROWS, + (void*) &prefetch_rows); + check_stmt_rc(rc, stmt); + stmt_text= "select * from t1"; + rc= mysql_stmt_prepare(stmt, SL(stmt_text)); + check_stmt_rc(rc, stmt); + + memset(my_bind, '\0', sizeof(my_bind)); + my_bind[0].buffer_type= MYSQL_TYPE_LONG; + my_bind[0].buffer= (void*) &a; + my_bind[0].buffer_length= sizeof(a); + mysql_stmt_bind_result(stmt, my_bind); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + while ((rc= mysql_stmt_fetch(stmt)) == 0) + ++num_rows; + FAIL_UNLESS(num_rows == 9, "num_rows != 9"); + + rc= mysql_stmt_close(stmt); + FAIL_UNLESS(rc == 0, ""); + + rc= mysql_query(mysql, "drop table t1"); + check_mysql_rc(rc, mysql); + return OK; +} + + +struct my_tests_st my_tests[] = { + {"test_basic_cursors", test_basic_cursors, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_cursors_with_union", test_cursors_with_union, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_cursors_with_procedure", test_cursors_with_procedure, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_bug21206", test_bug21206, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_bug10729", test_bug10729, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_bug10736", test_bug10736, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_bug10794", test_bug10794, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_bug10760", test_bug10760, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_bug11172", test_bug11172, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_bug11656", test_bug11656, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_bug11901", test_bug11901, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_bug11904", test_bug11904, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_bug12243", test_bug12243, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_bug11909", test_bug11909, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_bug13488", test_bug13488, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_bug13524", test_bug13524, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_bug14845", test_bug14845, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_bug14210", test_bug14210, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_bug24179", test_bug24179, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_bug32265", test_bug32265, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_bug38486", test_bug38486, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_bug8880", test_bug8880, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_bug9159", test_bug9159, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_bug9478", test_bug9478, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_bug9520", test_bug9520, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_bug9643", test_bug9643, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {NULL, NULL, 0, 0, NULL, NULL} +}; + +int main(int argc, char **argv) +{ + if (argc > 1) + get_options(argc, argv); + + get_envvars(); + + run_tests(my_tests); + + return(exit_status()); +} diff --git a/vendor/MDBC/unittest/libmariadb/data.csv b/vendor/MDBC/unittest/libmariadb/data.csv new file mode 100644 index 00000000..07471374 --- /dev/null +++ b/vendor/MDBC/unittest/libmariadb/data.csv @@ -0,0 +1,100 @@ +00000100,1,60000.000000 +00000101,2,60000.000000 +00000102,3,60000.000000 +00000103,1,60000.000000 +00000104,2,60000.000000 +00000105,3,60000.000000 +00000106,1,60000.000000 +00000107,2,60000.000000 +00000108,3,60000.000000 +00000109,1,60000.000000 +00000110,2,60000.000000 +00000111,3,60000.000000 +00000112,1,60000.000000 +00000113,2,60000.000000 +00000114,3,60000.000000 +00000115,1,60000.000000 +00000116,2,60000.000000 +00000117,3,60000.000000 +00000118,1,60000.000000 +00000119,2,60000.000000 +00000120,3,60000.000000 +00000121,1,60000.000000 +00000122,2,60000.000000 +00000123,3,60000.000000 +00000124,1,60000.000000 +00000125,2,60000.000000 +00000126,3,60000.000000 +00000127,1,60000.000000 +00000128,2,60000.000000 +00000129,3,60000.000000 +00000130,1,60000.000000 +00000131,2,60000.000000 +00000132,3,60000.000000 +00000133,1,60000.000000 +00000134,2,60000.000000 +00000135,3,60000.000000 +00000136,1,60000.000000 +00000137,2,60000.000000 +00000138,3,60000.000000 +00000139,1,60000.000000 +00000140,2,60000.000000 +00000141,3,60000.000000 +00000142,1,60000.000000 +00000143,2,60000.000000 +00000144,3,60000.000000 +00000145,1,60000.000000 +00000146,2,60000.000000 +00000147,3,60000.000000 +00000148,1,60000.000000 +00000149,2,60000.000000 +00000150,3,60000.000000 +00000151,1,60000.000000 +00000152,2,60000.000000 +00000153,3,60000.000000 +00000154,1,60000.000000 +00000155,2,60000.000000 +00000156,3,60000.000000 +00000157,1,60000.000000 +00000158,2,60000.000000 +00000159,3,60000.000000 +00000160,1,60000.000000 +00000161,2,60000.000000 +00000162,3,60000.000000 +00000163,1,60000.000000 +00000164,2,60000.000000 +00000165,3,60000.000000 +00000166,1,60000.000000 +00000167,2,60000.000000 +00000168,3,60000.000000 +00000169,1,60000.000000 +00000170,2,60000.000000 +00000171,3,60000.000000 +00000172,1,60000.000000 +00000173,2,60000.000000 +00000174,3,60000.000000 +00000175,1,60000.000000 +00000176,2,60000.000000 +00000177,3,60000.000000 +00000178,1,60000.000000 +00000179,2,60000.000000 +00000180,3,60000.000000 +00000181,1,60000.000000 +00000182,2,60000.000000 +00000183,3,60000.000000 +00000184,1,60000.000000 +00000185,2,60000.000000 +00000186,3,60000.000000 +00000187,1,60000.000000 +00000188,2,60000.000000 +00000189,3,60000.000000 +00000190,1,60000.000000 +00000191,2,60000.000000 +00000192,3,60000.000000 +00000193,1,60000.000000 +00000194,2,60000.000000 +00000195,3,60000.000000 +00000196,1,60000.000000 +00000197,2,60000.000000 +00000198,3,60000.000000 +00000199,1,60000.000000 diff --git a/vendor/MDBC/unittest/libmariadb/dyncol.c b/vendor/MDBC/unittest/libmariadb/dyncol.c new file mode 100644 index 00000000..8edb20a8 --- /dev/null +++ b/vendor/MDBC/unittest/libmariadb/dyncol.c @@ -0,0 +1,323 @@ +/* +Copyright (c) 2013 Monty Program AB. All rights reserved. + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published +by the Free Software Foundation; version 2 of the License. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include "my_test.h" +#include "mariadb_dyncol.h" + +static int create_dyncol_named(MYSQL *mysql) +{ + DYNAMIC_COLUMN dyncol; + DYNAMIC_COLUMN_VALUE *vals; + uint i, column_count= 6; + int rc; + const char *strval[]= {"Val1", "Val2", "Val3", "Val4", "Val5", "Val6"}; + MYSQL_LEX_STRING keys1[]= {{(char *)"key1", 4}, {(char *)"key2", 4}, + {(char *)"key3", 4}, {(char *)"key4", 4}, + {(char *)"key5", 4}, {(char *)"key6", 4}}, + + keys2[]= {{(char *)"key1", 4}, {(char *)"key1", 4}, + {(char *)"key3", 4}, {(char *)"key4", 4}, + {(char *)"key5", 4}, {(char *)"key6", 4}}, + + keys3[]= {{(char *)"\x70\x61\x72\x61\x00\x30", 6}, + {(char *)"\x70\x61\x72\x61\x00\x31", 6}, + {(char *)"\x70\x61\x72\x61\x00\x32", 6}, + {(char *)"\x70\x61\x72\x61\x00\x33", 6}, + {(char *)"\x70\x61\x72\x61\x00\x34", 6}, + {(char *)"\x70\x61\x72\x61\x00\x35", 6}}; + MYSQL_LEX_STRING *my_keys; + uint my_count; + + vals= (DYNAMIC_COLUMN_VALUE *)malloc(column_count * sizeof(DYNAMIC_COLUMN_VALUE)); + + for (i=0; i < column_count; i++) + { + vals[i].type= DYN_COL_STRING; + vals[i].x.string.value.str= (char *)strval[i]; + vals[i].x.string.value.length= strlen(strval[i]); + vals[i].x.string.charset= (MARIADB_CHARSET_INFO *)mysql->charset; + diag("%s", keys3[i].str); + } + + mariadb_dyncol_init(&dyncol); + rc= mariadb_dyncol_create_many_named(&dyncol, column_count, keys1, vals, 0); + mariadb_dyncol_free(&dyncol); + FAIL_IF(mariadb_dyncol_create_many_named(&dyncol, column_count, keys1, vals, 1) < 0, "Error"); + column_count= 0; + FAIL_IF(mariadb_dyncol_column_count(&dyncol, &column_count) < 0, "Error"); + + FAIL_IF(column_count != 6, "6 columns expected"); + mariadb_dyncol_free(&dyncol); + + rc= mariadb_dyncol_create_many_named(&dyncol, column_count, keys3, vals, 1); + if (rc < 0) { + diag("Error!!: %d", rc); + return FAIL; + } + column_count= 0; + FAIL_IF(mariadb_dyncol_column_count(&dyncol, &column_count) < 0, "Error"); + + FAIL_IF(column_count != 6, "6 columns expected"); + + mariadb_dyncol_free(&dyncol); + + /* Now try to add a duplicate key */ + + FAIL_IF(mariadb_dyncol_create_many_named(&dyncol, column_count, keys2, vals, 1) >=0, "Error expected"); + mariadb_dyncol_free(&dyncol); + + /* binary keys */ + rc= mariadb_dyncol_create_many_named(&dyncol, column_count, keys3, vals, 1); + FAIL_IF(rc < 0, "binary keys failed"); + + /* get keys*/ + rc= mariadb_dyncol_list_named(&dyncol, &my_count, &my_keys); + FAIL_IF(rc < 0, "list named failed"); + + for (i=0; i < my_count; i++) + { + if (memcmp(my_keys[i].str, keys3[i].str, keys3[i].length) != 0) + diag("error key %d", i); + vals[i].type=DYN_COL_NULL; + } + rc= mariadb_dyncol_update_many_named(&dyncol, column_count, keys3, vals); + FAIL_IF(rc < 0, "update failed"); + mariadb_dyncol_free(&dyncol); + + keys3[0].str= (char *)"test"; + for (i=0; i < column_count; i++) + diag("%s", my_keys[i].str); + + free(vals); + free(my_keys); + return OK; +} + +static int mdev_4994(MYSQL *unused __attribute__((unused))) +{ + DYNAMIC_COLUMN dyncol; + uint key= 1; + DYNAMIC_COLUMN_VALUE val; + int rc; + + + val.type= DYN_COL_NULL; + + mariadb_dyncol_init(&dyncol); + rc= mariadb_dyncol_create_many_num(&dyncol, 1, &key, &val, 0); + FAIL_IF(rc < 0, "Unexpected error"); + mariadb_dyncol_free(&dyncol); + return OK; +} + +static int create_dyncol_num(MYSQL *mysql) +{ + DYNAMIC_COLUMN dyncol; + DYNAMIC_COLUMN_VALUE vals[5]; + uint i, column_count= 5; + uint my_count; + MYSQL_LEX_STRING *my_keys; + DYNAMIC_COLUMN_VALUE *my_vals; + int rc; + const char *strval[]= {"Val1", "Val2", "Val3", "Val4", "Val5"}; + + uint keys1[5]= {1,2,3,4,5}, + keys2[5]= {1,2,2,4,5}; + MYSQL_LEX_STRING key1= {(char *)"1",1}; + + for (i=0; i < column_count; i++) + { + vals[i].type= DYN_COL_STRING; + vals[i].x.string.value.str= (char *)strval[i]; + vals[i].x.string.value.length= strlen(strval[i]); + vals[i].x.string.charset= (MARIADB_CHARSET_INFO *)mysql->charset; + } + FAIL_IF(mariadb_dyncol_create_many_num(&dyncol, column_count, keys1, vals, 1) <0, "Error (keys1)"); + + vals[0].x.string.value.str= (char *)strval[1]; + rc= mariadb_dyncol_update_many_named(&dyncol,1, &key1, vals); + diag("update: %d", rc); + + rc= mariadb_dyncol_unpack(&dyncol, &my_count, &my_keys, &my_vals); + diag("unpack: %d %d", rc, my_count); + + free(my_keys); + free(my_vals); + + FAIL_IF(mariadb_dyncol_column_count(&dyncol, &column_count) < 0, "Error"); + FAIL_IF(column_count != 5, "5 columns expected"); + mariadb_dyncol_free(&dyncol); + FAIL_IF(mariadb_dyncol_create_many_num(&dyncol, column_count, keys2, vals, 1) >=0, "Error expected (keys2)"); + mariadb_dyncol_free(&dyncol); + return OK; +} + +static int mdev_x1(MYSQL *mysql) +{ + int rc; + uint i; + uint num_keys[5]= {1,2,3,4,5}; + const char *strval[]= {"Val1", "Val2", "Val3", "Val4", "Val5"}; + DYNAMIC_COLUMN_VALUE vals[5]; + DYNAMIC_COLUMN dynstr; + MYSQL_LEX_STRING my_key= {(char *)"1", 2}; + uint unpack_columns; + MYSQL_LEX_STRING *unpack_keys; + DYNAMIC_COLUMN_VALUE *unpack_vals; + + for (i=0; i < 5; i++) + { + vals[i].type= DYN_COL_STRING; + vals[i].x.string.value.str= (char *)strval[i]; + vals[i].x.string.value.length= strlen(strval[i]); + vals[i].x.string.charset= (MARIADB_CHARSET_INFO *)mysql->charset; + } + + mariadb_dyncol_init(&dynstr); + + /* create numeric */ + rc= mariadb_dyncol_create_many_num(&dynstr, 5, num_keys, vals, 1); + if (rc < 0) + { + diag("Error: %d", rc); + return FAIL; + } + + /* unpack and print values */ + rc= mariadb_dyncol_unpack(&dynstr, &unpack_columns, &unpack_keys, &unpack_vals); + if (rc < 0) + { + diag("Error: %d", rc); + return FAIL; + } + + for (i=0; i < unpack_columns; i++) + if (memcmp(unpack_vals[i].x.string.value.str, vals[i].x.string.value.str, vals[i].x.string.value.length)) + diag("Error1: key: %1s val: %s %s", unpack_keys[i].str, unpack_vals[i].x.string.value.str, vals[i].x.string.value.str); + + free(unpack_keys); + free(unpack_vals); + + /* change one value and update with named key */ +/* vals[0].x.string.value.str= strval[1]; */ + rc= mariadb_dyncol_update_many_named(&dynstr, 1, &my_key, vals); + if (rc < 0) + { + diag("Error: %d", rc); + return FAIL; + } + + /* unpack and print values */ + rc= mariadb_dyncol_unpack(&dynstr, &unpack_columns, &unpack_keys, &unpack_vals); + if (rc < 0) + { + diag("Error: %d", rc); + return FAIL; + } + diag("Columns: %d", unpack_columns); + + for (i=0; i < unpack_columns; i++) + diag("Key: %s Len: %lu", unpack_keys[i].str, (unsigned long)unpack_keys[i].length); + + + free(unpack_keys); + free(unpack_vals); + + mariadb_dyncol_free(&dynstr); + return OK; +} + +static int dyncol_column_count(MYSQL *unused __attribute__((unused))) +{ + DYNAMIC_COLUMN dyncol; + uint column_count= 5; + int rc; + + mariadb_dyncol_init(&dyncol); /* memset(&dyncol, 0, sizeof(DYNAMIC_COLUMN)) */ + rc= mariadb_dyncol_column_count(&dyncol, &column_count); + diag("rc=%d", rc); + FAIL_IF(rc < 0, "unexpected error"); + FAIL_IF(column_count > 0, "Expected column_count=0"); + return OK; +} + +static int dyncol_nested(MYSQL *mysql __attribute__((unused))) +{ + DYNAMIC_COLUMN col1, col2; + DYNAMIC_COLUMN_VALUE value[2]; + MYSQL_LEX_STRING cols[2]= {{(char *)"0",1},{(char *)"1",1}}; + DYNAMIC_STRING s; + + mariadb_dyncol_init(&col1); + mariadb_dyncol_init(&col2); + + memset(&value, 0, sizeof(DYNAMIC_COLUMN_VALUE)); + + value[0].type= DYN_COL_UINT; + value[0].x.ulong_value = 17; + + mariadb_dyncol_create_many_named(&col1, 1, cols, value, 0); + if (mariadb_dyncol_check(&col1) != ER_DYNCOL_OK) + { + diag("Error while creating col1"); + return FAIL; + } + + value[1].type= DYN_COL_DYNCOL; + value[1].x.string.value.str= col1.str; + value[1].x.string.value.length= col1.length; + + mariadb_dyncol_create_many_named(&col2, 2, cols, value, 0); + if (mariadb_dyncol_check(&col2) != ER_DYNCOL_OK) + { + diag("Error while creating col1"); + return FAIL; + } + mariadb_dyncol_json(&col2, &s); + if (strcmp(s.str, "{\"0\":17,\"1\":{\"0\":17}}") != 0) + { + diag("%s != %s", s.str, "{\"0\":17,\"1\":{\"0\":17}}"); + return FAIL; + } + ma_dynstr_free(&s); + mariadb_dyncol_free(&col1); + mariadb_dyncol_free(&col2); + return OK; +} + +struct my_tests_st my_tests[] = { + {"mdev_x1", mdev_x1, TEST_CONNECTION_NEW, 0, NULL, NULL}, + {"mdev_4994", mdev_4994, TEST_CONNECTION_NEW, 0, NULL, NULL}, + {"create_dyncol_named", create_dyncol_named, TEST_CONNECTION_NEW, 0, NULL, NULL}, + {"create_dyncol_num", create_dyncol_num, TEST_CONNECTION_NEW, 0, NULL, NULL}, + {"dyncol_column_count", dyncol_column_count, TEST_CONNECTION_NEW, 0, NULL, NULL}, + {"dyncol_nested", dyncol_nested, TEST_CONNECTION_NEW, 0, NULL, NULL}, + {NULL, NULL, 0, 0, NULL, 0} +}; + + +int main(int argc, char **argv) +{ + if (argc > 1) + get_options(argc, argv); + + get_envvars(); + + run_tests(my_tests); + + return(exit_status()); +} diff --git a/vendor/MDBC/unittest/libmariadb/errors.c b/vendor/MDBC/unittest/libmariadb/errors.c new file mode 100644 index 00000000..79060a50 --- /dev/null +++ b/vendor/MDBC/unittest/libmariadb/errors.c @@ -0,0 +1,290 @@ +/* +Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. + +The MySQL Connector/C is licensed under the terms of the GPLv2 +, like most +MySQL Connectors. There are special exceptions to the terms and +conditions of the GPLv2 as it is applied to this software, see the +FLOSS License Exception +. + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published +by the Free Software Foundation; version 2 of the License. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ +#include "my_test.h" + +/* Test warnings */ + +static int test_client_warnings(MYSQL *mysql) +{ + int rc; + + rc= mysql_query(mysql, "DROP TABLE if exists test_non_exists"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "DROP TABLE if exists test_non_exists"); + check_mysql_rc(rc, mysql); + + FAIL_IF(!mysql_warning_count(mysql), "Warning expected"); + + return OK; +} + + +static int test_ps_client_warnings(MYSQL *mysql) +{ + int rc; + MYSQL_STMT *stmt; + const char *query= "DROP TABLE IF EXISTS test_non_exists"; + + rc= mysql_query(mysql, "DROP TABLE if exists test_non_exists"); + check_mysql_rc(rc, mysql); + + stmt= mysql_stmt_init(mysql); + rc= mysql_stmt_prepare(stmt, SL(query)); + FAIL_IF(rc, mysql_stmt_error(stmt)); + + rc= mysql_stmt_execute(stmt); + FAIL_IF(rc, mysql_stmt_error(stmt)); + + FAIL_IF(!mysql_warning_count(mysql), "Warning expected"); + + mysql_stmt_close(stmt); + + return OK; +} + +static int test_server_warnings(MYSQL *mysql) +{ + int rc; + MYSQL_RES *result; + + rc= mysql_query(mysql, "DROP TABLE if exists test_non_exists"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "DROP TABLE if exists test_non_exists"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "SHOW WARNINGS"); + check_mysql_rc(rc, mysql); + + result= mysql_store_result(mysql); + FAIL_IF(!result, mysql_error(mysql)); + FAIL_IF(!mysql_num_rows(result), "Empty resultset"); + + mysql_free_result(result); + + return OK; +} + + +/* Test errors */ + +static int test_client_errors(MYSQL *mysql) +{ + int rc; + + rc= mysql_query(mysql, "DROP TABLE if exists test_non_exists"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "DROP TABLE test_non_exists"); + FAIL_IF(!rc, "Error expected"); + + FAIL_IF(!mysql_errno(mysql), "Error expected"); + FAIL_IF(!strlen(mysql_error(mysql)), "Empty errormsg"); + FAIL_IF(strcmp(mysql_sqlstate(mysql), "00000") == 0, "Invalid SQLstate"); + + return OK; +} + +static int test_ps_client_errors(MYSQL *mysql) +{ + int rc; + MYSQL_STMT *stmt; + const char *query= "DROP TABLE test_non_exists"; + + rc= mysql_query(mysql, "DROP TABLE if exists test_non_exists"); + check_mysql_rc(rc, mysql); + + stmt= mysql_stmt_init(mysql); + rc= mysql_stmt_prepare(stmt, SL(query)); + FAIL_IF(rc, mysql_stmt_error(stmt)); + + rc= mysql_stmt_execute(stmt); + FAIL_IF(!rc, mysql_stmt_error(stmt)); + + FAIL_IF(!mysql_stmt_errno(stmt), "Error expected"); + FAIL_IF(!strlen(mysql_stmt_error(stmt)), "Empty errormsg"); + FAIL_IF(strcmp(mysql_stmt_sqlstate(stmt), "00000") == 0, "Invalid SQLstate"); + + mysql_stmt_close(stmt); + + return OK; +} + +static int test_server_errors(MYSQL *mysql) +{ + int rc; + MYSQL_RES *result; + + rc= mysql_query(mysql, "DROP TABLE if exists test_non_exists"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "DROP TABLE test_non_exists"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "SHOW ERRORS"); + check_mysql_rc(rc, mysql); + + result= mysql_store_result(mysql); + FAIL_IF(!result, mysql_error(mysql)); + FAIL_IF(!mysql_num_rows(result), "Empty resultset"); + mysql_free_result(result); + + return OK; +} + +/* Bug #16143: mysql_stmt_sqlstate returns an empty string instead of '00000' */ + +static int test_bug16143(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + /* Check mysql_stmt_sqlstate return "no error" */ + FAIL_UNLESS(strcmp(mysql_stmt_sqlstate(stmt), "00000") == 0, "Expected SQLstate 000000"); + mysql_stmt_close(stmt); + return OK; +} + +/* Test warnings for cuted rows */ + +static int test_cuted_rows(MYSQL *mysql) +{ + int rc, count; + MYSQL_RES *result; + + if (!is_mariadb) + return SKIP; + + rc= mysql_query(mysql, "DROP TABLE if exists t1"); + check_mysql_rc(rc, mysql); + mysql_query(mysql, "DROP TABLE if exists t2"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "CREATE TABLE t1(c1 tinyint)"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "CREATE TABLE t2(c1 int not null)"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "FLUSH TABLES"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "START TRANSACTION"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "INSERT INTO t1 values(10), (NULL), (NULL)"); + check_mysql_rc(rc, mysql); + + count= mysql_warning_count(mysql); + FAIL_UNLESS(count == 0, "warnings != 0"); + + rc= mysql_query(mysql, "INSERT INTO t2 SELECT * FROM t1"); + check_mysql_rc(rc, mysql); + + count= mysql_warning_count(mysql); + FAIL_UNLESS(count == 2, "warnings != 2"); + + rc= mysql_query(mysql, "SHOW WARNINGS"); + check_mysql_rc(rc, mysql); + + result= mysql_store_result(mysql); + FAIL_IF(!result, "Invalid result set"); + + rc= 0; + while (mysql_fetch_row(result)) + rc++; + FAIL_UNLESS(rc == 2, "rowcount != 2"); + mysql_free_result(result); + + rc= mysql_query(mysql, "INSERT INTO t1 VALUES('junk'), (876789)"); + check_mysql_rc(rc, mysql); + + count= mysql_warning_count(mysql); + FAIL_UNLESS(count == 2, "warnings != 2"); + + rc= mysql_query(mysql, "SHOW WARNINGS"); + check_mysql_rc(rc, mysql); + + result= mysql_store_result(mysql); + FAIL_IF(!result, "Invalid result set"); + + rc= 0; + while (mysql_fetch_row(result)) + rc++; + FAIL_UNLESS(rc == 2, "rowcount != 2"); + mysql_free_result(result); + + rc= mysql_query(mysql, "DROP TABLE t1, t2"); + check_mysql_rc(rc, mysql); + return OK; +} + +static int test_parse_error_and_bad_length(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + int rc; + char stmt_str[128]; + + /* check that we get 4 syntax errors over the 4 calls */ + + rc= mysql_query(mysql, "SHOW DATABAAAA"); + FAIL_UNLESS(rc, "Error expected"); + rc= mysql_real_query(mysql, SL_BIN("SHOW DATABASES\0AAA")); + FAIL_UNLESS(rc, "Error expected"); + + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL("SHOW DATABAAAA")); + FAIL_IF(!rc, "Error expected"); + mysql_stmt_close(stmt); + stmt= mysql_stmt_init(mysql); + FAIL_UNLESS(stmt, ""); + memset(stmt_str, 0, 100); + strcpy(stmt_str, "SHOW DATABASES"); + rc= mysql_stmt_prepare(stmt, stmt_str, 99); + FAIL_IF(!rc, "Error expected"); + mysql_stmt_close(stmt); + return OK; +} + + +struct my_tests_st my_tests[] = { + {"test_client_warnings", test_client_warnings, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_ps_client_warnings", test_ps_client_warnings, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_server_warnings", test_server_warnings, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_client_errors", test_client_errors, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_ps_client_errors", test_ps_client_errors, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_server_errors", test_server_errors, TEST_CONNECTION_DEFAULT, 0, NULL , "Open bug: #42364"}, + {"test_bug16143", test_bug16143, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_cuted_rows", test_cuted_rows, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_parse_error_and_bad_length", test_parse_error_and_bad_length, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {NULL, NULL, 0, 0, NULL, NULL} +}; + +int main(int argc, char **argv) +{ + if (argc > 1) + get_options(argc, argv); + + get_envvars(); + + run_tests(my_tests); + + return(exit_status()); +} diff --git a/vendor/MDBC/unittest/libmariadb/features-10_2.c b/vendor/MDBC/unittest/libmariadb/features-10_2.c new file mode 100644 index 00000000..e09db5aa --- /dev/null +++ b/vendor/MDBC/unittest/libmariadb/features-10_2.c @@ -0,0 +1,249 @@ +/* +*/ + +#include "my_test.h" + +static int execute_direct(MYSQL *mysql) +{ + int rc= 0; + long i= 0; + MYSQL_STMT *stmt; + MYSQL_BIND bind; + unsigned int param_count= 1; + MYSQL_RES *res= NULL; + + stmt= mysql_stmt_init(mysql); + + rc= mariadb_stmt_execute_direct(stmt, "DROP TABLE IF EXISTS t1", -1); + check_stmt_rc(rc, stmt); + + rc= mariadb_stmt_execute_direct(stmt, "SELECT 1", -1); + check_stmt_rc(rc, stmt); + + while (!mysql_stmt_fetch(stmt)); + + rc= mariadb_stmt_execute_direct(stmt, "SELECT 1", -1); + check_stmt_rc(rc, stmt); + + rc= mariadb_stmt_execute_direct(stmt, "CREATE TABLE t1 (a int)", -1); + check_stmt_rc(rc, stmt); + + rc= mysql_query(mysql, "FLUSH TABLES"); + check_mysql_rc(rc, mysql); + + memset(&bind, 0, sizeof(MYSQL_BIND)); + + bind.buffer= &i; + bind.buffer_type= MYSQL_TYPE_LONG; + bind.buffer_length= sizeof(long); + + mysql_stmt_close(stmt); + stmt= mysql_stmt_init(mysql); + mysql_stmt_attr_set(stmt, STMT_ATTR_PREBIND_PARAMS, ¶m_count); + + rc= mysql_stmt_bind_param(stmt, &bind); + check_stmt_rc(rc, stmt); + rc= mariadb_stmt_execute_direct(stmt, "INSERT INTO t1 VALUES (?)", -1); + check_stmt_rc(rc, stmt); + + rc= mysql_query(mysql, "START TRANSACTION"); + check_mysql_rc(rc, mysql); + + for (i=1; i < 1000; i++) + { + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + } + rc= mysql_stmt_close(stmt); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "SELECT * FROM t1"); + check_mysql_rc(rc, mysql); + + res= mysql_store_result(mysql); + FAIL_IF(mysql_num_rows(res) != 1000, "Expected 1000 rows"); + + mysql_free_result(res); + rc= mysql_query(mysql, "COMMIT"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "DROP TABLE t1"); + check_mysql_rc(rc, mysql); + + return OK; +} + +static int execute_direct_example(MYSQL *mysql) +{ + MYSQL_STMT *stmt= mysql_stmt_init(mysql); + MYSQL_BIND bind[2]; + int intval= 1; + int param_count= 2; + int rc; + const char *strval= "execute_direct_example1"; + + /* Direct execution without parameters */ + rc= mariadb_stmt_execute_direct(stmt, "DROP TABLE IF EXISTS execute_direct", -1); + check_stmt_rc(rc, stmt); + rc= mariadb_stmt_execute_direct(stmt, "CREATE TABLE execute_direct (a int, b varchar(20))", -1); + rc= mysql_stmt_close(stmt); + stmt= mysql_stmt_init(mysql); + check_stmt_rc(rc, stmt); + memset(bind, 0, sizeof(MYSQL_BIND) * 2); + bind[0].buffer_type= MYSQL_TYPE_SHORT; + bind[0].buffer= &intval; + bind[1].buffer_type= MYSQL_TYPE_STRING; + bind[1].buffer= (char *)strval; + bind[1].buffer_length= (unsigned long)strlen(strval); + + /* set number of parameters */ + rc= mysql_stmt_attr_set(stmt, STMT_ATTR_PREBIND_PARAMS, ¶m_count); + check_stmt_rc(rc, stmt); + + /* bind parameters */ + rc= mysql_stmt_bind_param(stmt, bind); + check_stmt_rc(rc, stmt); + + rc= mariadb_stmt_execute_direct(stmt, "INSERT INTO execute_direct VALUES (?,?)", -1); + check_stmt_rc(rc, stmt); + + mysql_stmt_close(stmt); + + rc= mysql_query(mysql, "DROP TABLE execute_direct"); + check_mysql_rc(rc, mysql); + return OK; +} + +static int conc_213(MYSQL *mysql) +{ + MYSQL_BIND bind; + unsigned int param_count= 1; + long id= 1234; + MYSQL_STMT *stmt; + + stmt = mysql_stmt_init(mysql); + + memset(&bind, '\0', sizeof(bind)); + + bind.buffer_type = MYSQL_TYPE_LONG; + bind.buffer = (void *)&id; + bind.buffer_length = sizeof(long); +/* bind.is_null = &is_null; + bind.length = &length; + bind.error = &error; */ + + mysql_stmt_attr_set(stmt, STMT_ATTR_PREBIND_PARAMS, ¶m_count); + check_stmt_rc(mysql_stmt_bind_param(stmt, &bind), stmt); + check_stmt_rc(mariadb_stmt_execute_direct(stmt, "SELECT ?", -1), stmt); + check_stmt_rc(mysql_stmt_store_result(stmt), stmt); + check_stmt_rc(mysql_stmt_free_result(stmt), stmt); + + mysql_stmt_close(stmt); + + return OK; +} + +static int conc_212(MYSQL *mysql) +{ + MYSQL_STMT *stmt= mysql_stmt_init(mysql); + int rc; + + rc= mariadb_stmt_execute_direct(stmt, "SELECT 1, 2", -1); + check_stmt_rc(rc, stmt); + mysql_stmt_store_result(stmt); + mysql_stmt_free_result(stmt); + + rc= mariadb_stmt_execute_direct(stmt, "SELECT 1, 2", -1); + check_stmt_rc(rc, stmt); + mysql_stmt_store_result(stmt); + mysql_stmt_free_result(stmt); + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1"); + check_mysql_rc(rc,mysql); + + + rc= mysql_stmt_close(stmt); + + return OK; +} + +static int conc_218(MYSQL *mysql) +{ + MYSQL_STMT *stmt= mysql_stmt_init(mysql); + MYSQL_BIND bind[2]; + int id=1; + my_bool is_null= 0, error= 0; + unsigned int param_count= 1; + + memset(bind, 0, 2 * sizeof(MYSQL_BIND)); + bind[0].buffer_type = MYSQL_TYPE_LONG; + bind[0].buffer = (void *)&id; + bind[0].buffer_length = 4; + bind[0].is_null = &is_null; + bind[0].error = &error; + + mysql_stmt_attr_set(stmt, STMT_ATTR_PREBIND_PARAMS, ¶m_count); + check_stmt_rc(mysql_stmt_bind_param(stmt, bind), stmt); + check_stmt_rc(mariadb_stmt_execute_direct(stmt, "SELECT ?", -1), stmt); + check_stmt_rc(mysql_stmt_store_result(stmt), stmt); + + check_stmt_rc(mysql_stmt_free_result(stmt), stmt); + + param_count= 1; + mysql_stmt_attr_set(stmt, STMT_ATTR_PREBIND_PARAMS, ¶m_count); + check_stmt_rc(mysql_stmt_bind_param(stmt, bind), stmt); + check_stmt_rc(mariadb_stmt_execute_direct(stmt, "SELECT ?", -1), stmt); + mysql_stmt_close(stmt); + + return OK; +} + +static int test_cursor(MYSQL *mysql) +{ + int rc; + MYSQL_STMT *stmt; + unsigned long prefetch_rows= 1; + unsigned long cursor_type= CURSOR_TYPE_READ_ONLY; + + stmt= mysql_stmt_init(mysql); + rc= mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, &cursor_type); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_attr_set(stmt, STMT_ATTR_PREFETCH_ROWS, &prefetch_rows); + check_stmt_rc(rc, stmt); + rc= mariadb_stmt_execute_direct(stmt, "SELECT 1 FROM DUAL UNION SELECT 2 FROM DUAL", -1); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + rc= mariadb_stmt_execute_direct(stmt, "SELECT 1 FROM DUAL UNION SELECT 2 FROM DUAL", -1); + check_stmt_rc(rc, stmt); + mysql_stmt_close(stmt); + return OK; +} + + +struct my_tests_st my_tests[] = { + {"test_cursor", test_cursor, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"conc_218", conc_218, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"conc_212", conc_212, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"conc_213", conc_213, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"execute_direct", execute_direct, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"execute_direct_example", execute_direct_example, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {NULL, NULL, 0, 0, NULL, NULL} +}; + + +int main(int argc, char **argv) +{ + + mysql_library_init(0,0,NULL); + + if (argc > 1) + get_options(argc, argv); + + get_envvars(); + + run_tests(my_tests); + + mysql_server_end(); + return(exit_status()); +} diff --git a/vendor/MDBC/unittest/libmariadb/fetch.c b/vendor/MDBC/unittest/libmariadb/fetch.c new file mode 100644 index 00000000..6394e51d --- /dev/null +++ b/vendor/MDBC/unittest/libmariadb/fetch.c @@ -0,0 +1,1003 @@ +/* +Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. + +The MySQL Connector/C is licensed under the terms of the GPLv2 +, like most +MySQL Connectors. There are special exceptions to the terms and +conditions of the GPLv2 as it is applied to this software, see the +FLOSS License Exception +. + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published +by the Free Software Foundation; version 2 of the License. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ +#include "my_test.h" + +/* Generalized fetch conversion routine for all basic types */ + +static int bind_fetch(MYSQL *mysql, int row_count) +{ + MYSQL_STMT *stmt; + int rc, i, count= row_count; + int32 data[10]; + int8 i8_data; + int16 i16_data; + int i32_data; + longlong i64_data; + float f_data; + double d_data; + char s_data[10]; + ulong length[10]; + MYSQL_BIND my_bind[7]; + my_bool is_null[7]; + char query[MAX_TEST_QUERY_LENGTH]; + + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + + strcpy(query, "INSERT INTO test_bind_fetch VALUES (?, ?, ?, ?, ?, ?, ?)"); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc,stmt); + + FAIL_UNLESS(mysql_stmt_param_count(stmt) == 7, "ParamCount != 7"); + + memset(my_bind, '\0', sizeof(my_bind)); + + for (i= 0; i < (int) array_elements(my_bind); i++) + { + my_bind[i].buffer_type= MYSQL_TYPE_LONG; + my_bind[i].buffer= (void *) &data[i]; + } + rc= mysql_stmt_bind_param(stmt, my_bind); + check_stmt_rc(rc,stmt); + + while (count--) + { + rc= 10+count; + for (i= 0; i < (int) array_elements(my_bind); i++) + { + data[i]= rc+i; + rc+= 12; + } + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc,stmt); + } + + rc= mysql_commit(mysql); + check_stmt_rc(rc,stmt); + + mysql_stmt_close(stmt); + + rc= my_stmt_result(mysql, "SELECT * FROM test_bind_fetch"); + FAIL_UNLESS(row_count == rc, "Wrong number of rows"); + + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + + strcpy(query, "SELECT * FROM test_bind_fetch"); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc,stmt); + + for (i= 0; i < (int) array_elements(my_bind); i++) + { + my_bind[i].buffer= (void *) &data[i]; + my_bind[i].length= &length[i]; + my_bind[i].is_null= &is_null[i]; + } + + my_bind[0].buffer_type= MYSQL_TYPE_TINY; + my_bind[0].buffer= (void *)&i8_data; + + my_bind[1].buffer_type= MYSQL_TYPE_SHORT; + my_bind[1].buffer= (void *)&i16_data; + + my_bind[2].buffer_type= MYSQL_TYPE_LONG; + my_bind[2].buffer= (void *)&i32_data; + + my_bind[3].buffer_type= MYSQL_TYPE_LONGLONG; + my_bind[3].buffer= (void *)&i64_data; + + my_bind[4].buffer_type= MYSQL_TYPE_FLOAT; + my_bind[4].buffer= (void *)&f_data; + + my_bind[5].buffer_type= MYSQL_TYPE_DOUBLE; + my_bind[5].buffer= (void *)&d_data; + + my_bind[6].buffer_type= MYSQL_TYPE_STRING; + my_bind[6].buffer= (void *)&s_data; + my_bind[6].buffer_length= sizeof(s_data); + + rc= mysql_stmt_bind_result(stmt, my_bind); + check_stmt_rc(rc,stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc,stmt); + + rc= mysql_stmt_store_result(stmt); + check_stmt_rc(rc,stmt); + + while (row_count--) + { + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc,stmt); + + rc= 10+row_count; + + /* TINY */ + FAIL_UNLESS((int) i8_data == rc, "Invalid value for i8_data"); + FAIL_UNLESS(length[0] == 1, "Invalid length"); + rc+= 13; + + /* SHORT */ + FAIL_UNLESS((int) i16_data == rc, "Invalid value for i16_data"); + FAIL_UNLESS(length[1] == 2, "Invalid length"); + rc+= 13; + + /* LONG */ + FAIL_UNLESS((int) i32_data == rc, "Invalid value for i32_data"); + FAIL_UNLESS(length[2] == 4, "Invalid length"); + rc+= 13; + + /* LONGLONG */ + FAIL_UNLESS((int) i64_data == rc, "Invalid value for i64_data"); + FAIL_UNLESS(length[3] == 8, "Invalid length"); + rc+= 13; + + /* FLOAT */ + FAIL_UNLESS((int)f_data == rc, "Invalid value for f_data"); + FAIL_UNLESS(length[4] == 4, "Invalid length"); + rc+= 13; + + /* DOUBLE */ + FAIL_UNLESS((int)d_data == rc, "Invalid value for d_data"); + FAIL_UNLESS(length[5] == 8, "Invalid length"); + rc+= 13; + + /* CHAR */ + { + char buff[20]; + long len= sprintf(buff, "%d", rc); + FAIL_UNLESS(strcmp(s_data, buff) == 0, "Invalid value for s_data"); + FAIL_UNLESS(length[6] == (ulong) len, "Invalid length"); + } + } + rc= mysql_stmt_fetch(stmt); + FAIL_UNLESS(rc == MYSQL_NO_DATA, "Expected MYSQL_NO_DATA"); + + mysql_stmt_close(stmt); + return OK; +} + + +static int test_fetch_seek(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + MYSQL_BIND my_bind[3]; + MYSQL_ROW_OFFSET row; + int rc; + int32 c1; + char c2[11], c3[20]; + const char *query = "SELECT * FROM t1"; + + rc= mysql_query(mysql, "drop table if exists t1"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "create table t1(c1 int primary key auto_increment, c2 char(10), c3 timestamp)"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "insert into t1(c2) values('venu'), ('mysql'), ('open'), ('source')"); + check_mysql_rc(rc, mysql); + + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc,stmt); + + memset(my_bind, '\0', sizeof(my_bind)); + my_bind[0].buffer_type= MYSQL_TYPE_LONG; + my_bind[0].buffer= (void *)&c1; + + my_bind[1].buffer_type= MYSQL_TYPE_STRING; + my_bind[1].buffer= (void *)c2; + my_bind[1].buffer_length= sizeof(c2); + + my_bind[2]= my_bind[1]; + my_bind[2].buffer= (void *)c3; + my_bind[2].buffer_length= sizeof(c3); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc,stmt); + + rc= mysql_stmt_bind_result(stmt, my_bind); + check_stmt_rc(rc,stmt); + + rc= mysql_stmt_store_result(stmt); + check_stmt_rc(rc,stmt); + + + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc,stmt); + + row= mysql_stmt_row_tell(stmt); + + row= mysql_stmt_row_seek(stmt, row); + + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc,stmt); + + row= mysql_stmt_row_seek(stmt, row); + + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc,stmt); + + mysql_stmt_data_seek(stmt, 0); + + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc,stmt); + + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc,stmt); + + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc,stmt); + + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc,stmt); + + rc= mysql_stmt_fetch(stmt); + FAIL_IF(rc != MYSQL_NO_DATA, "Expected MYSQL_NO_DATA"); + + mysql_stmt_close(stmt); + rc= mysql_query(mysql, "drop table t1"); + check_mysql_rc(rc, mysql); + + return OK; +} + +/* Test mysql_stmt_fetch_column() with offset */ + +static int test_fetch_offset(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + MYSQL_BIND my_bind[2]; + char data[11], chunk[5]; + ulong length[2]; + int rc; + my_bool is_null[2]; + const char *query = "SELECT * FROM t1"; + + + rc= mysql_query(mysql, "drop table if exists t1"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "create table t1(a char(10), b mediumblob)"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "insert into t1 values('abcdefghij', 'klmnopqrstzy'), (null, null)"); + check_mysql_rc(rc, mysql); + + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc,stmt); + + memset(my_bind, '\0', sizeof(my_bind)); + my_bind[0].buffer_type= MYSQL_TYPE_STRING; + my_bind[0].buffer= (void *)data; + my_bind[0].buffer_length= 11; + my_bind[0].is_null= &is_null[0]; + my_bind[0].length= &length[0]; + + my_bind[1].buffer_type= MYSQL_TYPE_MEDIUM_BLOB; + my_bind[1].buffer= NULL; + my_bind[1].buffer_length= 0; + my_bind[1].is_null= &is_null[1]; + my_bind[1].length= &length[1]; + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc,stmt); + + rc= mysql_stmt_fetch_column(stmt, my_bind, 0, 0); + FAIL_IF(!rc, "Error expected"); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc,stmt); + + rc= mysql_stmt_bind_result(stmt, my_bind); + check_stmt_rc(rc,stmt); + + rc= mysql_stmt_store_result(stmt); + check_stmt_rc(rc,stmt); +diag("truncation: %d", mysql->options.report_data_truncation); + rc= mysql_stmt_fetch(stmt); + FAIL_UNLESS(rc == MYSQL_DATA_TRUNCATED, "rc != MYSQL_DATA_TRUNCATED"); + + data[0]= '\0'; + rc= mysql_stmt_fetch_column(stmt, &my_bind[0], 0, 0); + check_stmt_rc(rc,stmt); + + + FAIL_IF(!(strncmp(data, "abcdefghij", 11) == 0 && length[0] == 10), "Wrong value"); + FAIL_IF(my_bind[0].error_value, "No truncation, but error is set"); + + rc= mysql_stmt_fetch_column(stmt, &my_bind[0], 0, 5); + check_stmt_rc(rc,stmt); + FAIL_IF(!(strncmp(data, "fghij", 6) == 0 && length[0] == 10), "Wrong value"); + FAIL_IF(my_bind[0].error_value, "No truncation, but error is set"); + + rc= mysql_stmt_fetch_column(stmt, &my_bind[0], 0, 9); + check_stmt_rc(rc,stmt); + FAIL_IF(!(strncmp(data, "j", 2) == 0 && length[0] == 10), "Wrong value"); + FAIL_IF(my_bind[0].error_value, "No truncation, but error is set"); + + /* Now blob field */ + my_bind[1].buffer= chunk; + my_bind[1].buffer_length= sizeof(chunk); + + rc= mysql_stmt_fetch_column(stmt, &my_bind[1], 1, 0); + check_stmt_rc(rc,stmt); + + FAIL_IF(!(strncmp(chunk, "klmno", 5) == 0 && length[1] == 12), "Wrong value"); + FAIL_IF(my_bind[1].error_value == '\0', "Truncation, but error is not set"); + + rc= mysql_stmt_fetch_column(stmt, &my_bind[1], 1, 5); + check_stmt_rc(rc,stmt); + FAIL_IF(!(strncmp(chunk, "pqrst", 5) == 0 && length[1] == 12), "Wrong value"); + FAIL_IF(my_bind[1].error_value == '\0', "Truncation, but error is not set"); + + rc= mysql_stmt_fetch_column(stmt, &my_bind[1], 1, 10); + check_stmt_rc(rc,stmt); + FAIL_IF(!(strncmp(chunk, "zy", 2) == 0 && length[1] == 12), "Wrong value"); + FAIL_IF(my_bind[1].error_value, "No truncation, but error is set"); + + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc,stmt); + + memset(is_null, 0, sizeof(is_null)); + + rc= mysql_stmt_fetch_column(stmt, &my_bind[0], 0, 0); + check_stmt_rc(rc,stmt); + + FAIL_IF(is_null[0] != 1, "Null flag not set"); + + rc= mysql_stmt_fetch_column(stmt, &my_bind[1], 1, 0); + check_stmt_rc(rc,stmt); + + FAIL_IF(is_null[1] != 1, "Null flag not set"); + + rc= mysql_stmt_fetch(stmt); + FAIL_IF(rc != MYSQL_NO_DATA, "Expected MYSQL_NO_DATA"); + + rc= mysql_stmt_fetch_column(stmt, my_bind, 1, 0); + FAIL_IF(!rc, "Error expected"); + + mysql_stmt_close(stmt); + + rc= mysql_query(mysql, "drop table t1"); + check_mysql_rc(rc, mysql); + + return OK; +} + +/* Test mysql_stmt_fetch_column() */ + +static int test_fetch_column(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + MYSQL_BIND my_bind[2]; + char c2[20], bc2[20]; + ulong l1, l2, bl1, bl2; + int rc, c1, bc1; + const char *query= "SELECT * FROM t1 ORDER BY c2 DESC"; + + rc= mysql_query(mysql, "drop table if exists t1"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "create table t1(c1 int primary key auto_increment, c2 char(10))"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "insert into t1(c2) values('venu'), ('mysql')"); + check_mysql_rc(rc, mysql); + + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc,stmt); + + memset(my_bind, '\0', sizeof(my_bind)); + my_bind[0].buffer_type= MYSQL_TYPE_LONG; + my_bind[0].buffer= (void *)&bc1; + my_bind[0].buffer_length= 0; + my_bind[0].is_null= 0; + my_bind[0].length= &bl1; + my_bind[1].buffer_type= MYSQL_TYPE_STRING; + my_bind[1].buffer= (void *)bc2; + my_bind[1].buffer_length= 7; + my_bind[1].is_null= 0; + my_bind[1].length= &bl2; + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc,stmt); + + rc= mysql_stmt_bind_result(stmt, my_bind); + check_stmt_rc(rc,stmt); + + rc= mysql_stmt_store_result(stmt); + check_stmt_rc(rc,stmt); + + rc= mysql_stmt_fetch_column(stmt, my_bind, 1, 0); /* No-op at this point */ + FAIL_IF(!rc, "Error expected"); + + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc,stmt); + + c2[0]= '\0'; l2= 0; + my_bind[0].buffer_type= MYSQL_TYPE_STRING; + my_bind[0].buffer= (void *)c2; + my_bind[0].buffer_length= 7; + my_bind[0].is_null= 0; + my_bind[0].length= &l2; + + rc= mysql_stmt_fetch_column(stmt, my_bind, 1, 0); + check_stmt_rc(rc,stmt); + FAIL_IF(!(strncmp(c2, "venu", 4) == 0 && l2 == 4), "Expected c2='venu'"); + + c2[0]= '\0'; l2= 0; + rc= mysql_stmt_fetch_column(stmt, my_bind, 1, 0); + check_stmt_rc(rc,stmt); + FAIL_IF(!(strcmp(c2, "venu") == 0 && l2 == 4), "Expected c2='venu'"); + + c1= 0; + my_bind[0].buffer_type= MYSQL_TYPE_LONG; + my_bind[0].buffer= (void *)&c1; + my_bind[0].buffer_length= 0; + my_bind[0].is_null= 0; + my_bind[0].length= &l1; + + rc= mysql_stmt_fetch_column(stmt, my_bind, 0, 0); + check_stmt_rc(rc,stmt); + FAIL_IF(!(c1 == 1 && l1 == 4), "Expected c1=1"); + + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc,stmt); + + c2[0]= '\0'; l2= 0; + my_bind[0].buffer_type= MYSQL_TYPE_STRING; + my_bind[0].buffer= (void *)c2; + my_bind[0].buffer_length= 7; + my_bind[0].is_null= 0; + my_bind[0].length= &l2; + + rc= mysql_stmt_fetch_column(stmt, my_bind, 1, 0); + check_stmt_rc(rc,stmt); + FAIL_IF(!(strncmp(c2, "mysq", 4) == 0 && l2 == 5), "Expected c2='mysql'"); + + c2[0]= '\0'; l2= 0; + rc= mysql_stmt_fetch_column(stmt, my_bind, 1, 0); + check_stmt_rc(rc,stmt); + FAIL_IF(!(strcmp(c2, "mysql") == 0 && l2 == 5), "Expected c2='mysql'"); + + c1= 0; + my_bind[0].buffer_type= MYSQL_TYPE_LONG; + my_bind[0].buffer= (void *)&c1; + my_bind[0].buffer_length= 0; + my_bind[0].is_null= 0; + my_bind[0].length= &l1; + + rc= mysql_stmt_fetch_column(stmt, my_bind, 0, 0); + check_stmt_rc(rc,stmt); + FAIL_IF(!(c1 == 2 && l1 == 4), "Expected c2=2"); + + rc= mysql_stmt_fetch(stmt); + FAIL_IF(rc!=MYSQL_NO_DATA, "Expected MYSQL_NO_DATA"); + + rc= mysql_stmt_fetch_column(stmt, my_bind, 1, 0); + FAIL_IF(!rc, "Error expected"); + + mysql_stmt_close(stmt); + rc= mysql_query(mysql, "drop table t1"); + check_mysql_rc(rc, mysql); + + return OK; +} + +/* Test fetch without prior bound buffers */ + +static int test_fetch_nobuffs(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + MYSQL_BIND my_bind[4]; + char str[4][50]; + int rc; + const char *query = "SELECT DATABASE(), CURRENT_USER(), \ + CURRENT_DATE(), CURRENT_TIME()"; + + stmt = mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc= 0; + while (mysql_stmt_fetch(stmt) != MYSQL_NO_DATA) + rc++; + + FAIL_IF(rc != 1, "Expected 1 row"); + + memset(my_bind, '\0', sizeof(my_bind)); + my_bind[0].buffer_type= MYSQL_TYPE_STRING; + my_bind[0].buffer= (void *)str[0]; + my_bind[0].buffer_length= sizeof(str[0]); + my_bind[1]= my_bind[2]= my_bind[3]= my_bind[0]; + my_bind[1].buffer= (void *)str[1]; + my_bind[2].buffer= (void *)str[2]; + my_bind[3].buffer= (void *)str[3]; + + rc= mysql_stmt_bind_result(stmt, my_bind); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc= 0; + while (mysql_stmt_fetch(stmt) != MYSQL_NO_DATA) + { + rc++; + } + FAIL_IF(rc != 1, "Expected 1 row"); + + mysql_stmt_close(stmt); + + return OK; +} + +/* Test fetch null */ + +static int test_fetch_null(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + int rc; + int i; + int nData= 0; + MYSQL_BIND my_bind[11]; + ulong length[11]; + my_bool is_null[11]; + char query[MAX_TEST_QUERY_LENGTH]; + + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_fetch_null"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE test_fetch_null(" + " col1 tinyint, col2 smallint, " + " col3 int, col4 bigint, " + " col5 float, col6 double, " + " col7 date, col8 time, " + " col9 varbinary(10), " + " col10 varchar(50), " + " col11 char(20))"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "INSERT INTO test_fetch_null (col11) " + "VALUES (1000), (88), (389789)"); + check_mysql_rc(rc, mysql); + + rc= mysql_commit(mysql); + FAIL_IF(rc, mysql_error(mysql)); + + /* fetch */ + memset(my_bind, '\0', sizeof(my_bind)); + for (i= 0; i < (int) array_elements(my_bind); i++) + { + my_bind[i].buffer_type= MYSQL_TYPE_LONG; + my_bind[i].is_null= &is_null[i]; + my_bind[i].length= &length[i]; + } + my_bind[i-1].buffer= (void *)&nData; /* Last column is not null */ + + strcpy((char *)query , "SELECT * FROM test_fetch_null"); + + rc= my_stmt_result(mysql, query); + FAIL_UNLESS(rc == 3, "Exoected 3 rows"); + + stmt = mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_bind_result(stmt, my_bind); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc= 0; + while (mysql_stmt_fetch(stmt) != MYSQL_NO_DATA) + { + rc++; + for (i= 0; i < 10; i++) + { + FAIL_IF(!is_null[i], "Expected is_null"); + } + FAIL_UNLESS(nData == 1000 || nData == 88 || nData == 389789, "Wrong value for nData"); + FAIL_UNLESS(is_null[i] == 0, "Exoected !is_null"); + FAIL_UNLESS(length[i] == 4, "Expected length=4"); + } + FAIL_UNLESS(rc == 3, "Expected 3 rows"); + mysql_stmt_close(stmt); + + rc= mysql_query(mysql, "DROP TABLE test_fetch_null"); + check_mysql_rc(rc, mysql); + + return OK; +} + +/* Test fetching of date, time and ts */ + +static int test_fetch_date(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + uint i; + int rc; + long year; + char date[25], my_time[25], ts[25], ts_4[25], ts_6[20], dt[20]; + ulong d_length, t_length, ts_length, ts4_length, ts6_length, + dt_length, y_length; + MYSQL_BIND my_bind[8]; + my_bool is_null[8]; + ulong length[8]; + const char *query= "SELECT * FROM test_bind_result"; + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_bind_result"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE test_bind_result(c1 date, c2 time, \ + c3 timestamp, \ + c4 year, \ + c5 datetime, \ + c6 timestamp, \ + c7 timestamp)"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "SET SQL_MODE=''"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "INSERT INTO test_bind_result VALUES('2002-01-02', \ + '12:49:00', \ + '2002-01-02 17:46:59', \ + 2010, \ + '2010-07-10', \ + '2020', '1999-12-29')"); + check_mysql_rc(rc, mysql); + + rc= mysql_commit(mysql); + FAIL_IF(rc, mysql_error(mysql)); + + memset(my_bind, '\0', sizeof(my_bind)); + for (i= 0; i < array_elements(my_bind); i++) + { + my_bind[i].is_null= &is_null[i]; + my_bind[i].length= &length[i]; + } + + my_bind[0].buffer_type= MYSQL_TYPE_STRING; + my_bind[1]= my_bind[2]= my_bind[0]; + + my_bind[0].buffer= (void *)&date; + my_bind[0].buffer_length= sizeof(date); + my_bind[0].length= &d_length; + + my_bind[1].buffer= (void *)&my_time; + my_bind[1].buffer_length= sizeof(my_time); + my_bind[1].length= &t_length; + + my_bind[2].buffer= (void *)&ts; + my_bind[2].buffer_length= sizeof(ts); + my_bind[2].length= &ts_length; + + my_bind[3].buffer_type= MYSQL_TYPE_LONG; + my_bind[3].buffer= (void *)&year; + my_bind[3].length= &y_length; + + my_bind[4].buffer_type= MYSQL_TYPE_STRING; + my_bind[4].buffer= (void *)&dt; + my_bind[4].buffer_length= sizeof(dt); + my_bind[4].length= &dt_length; + + my_bind[5].buffer_type= MYSQL_TYPE_STRING; + my_bind[5].buffer= (void *)&ts_4; + my_bind[5].buffer_length= sizeof(ts_4); + my_bind[5].length= &ts4_length; + + my_bind[6].buffer_type= MYSQL_TYPE_STRING; + my_bind[6].buffer= (void *)&ts_6; + my_bind[6].buffer_length= sizeof(ts_6); + my_bind[6].length= &ts6_length; + + rc= my_stmt_result(mysql, "SELECT * FROM test_bind_result"); + FAIL_UNLESS(rc == 1, "Expected 1 row"); + + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_bind_result(stmt, my_bind); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + ts_4[0]= '\0'; + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + + FAIL_UNLESS(strcmp(date, "2002-01-02") == 0, "date != '2002-01-02'"); + FAIL_UNLESS(d_length == 10, "d_length != 10"); + + FAIL_UNLESS(strcmp(my_time, "12:49:00") == 0, "mytime != '12:49:00'"); + FAIL_UNLESS(t_length == 8, "t_length != 8"); + + FAIL_UNLESS(strcmp(ts, "2002-01-02 17:46:59") == 0, "ts != '2002-01-02 17:46:59'"); + FAIL_UNLESS(ts_length == 19, "ts_length != 19"); + + FAIL_UNLESS(strcmp(dt, "2010-07-10 00:00:00") == 0, "dt != 2010-07-10 00:00:00"); + FAIL_UNLESS(dt_length == 19, "dt_length != 19"); + + FAIL_UNLESS(strcmp(ts_4, "0000-00-00 00:00:00") == 0, "ts4 != '0000-00-00 00:00:00'"); + FAIL_UNLESS(ts4_length == strlen("0000-00-00 00:00:00"), "ts4_length != 19"); + + FAIL_UNLESS(strcmp(ts_6, "1999-12-29 00:00:00") == 0, "ts_6 != '1999-12-29 00:00:00'"); + FAIL_UNLESS(ts6_length == 19, "ts6_length != 19"); + + rc= mysql_stmt_fetch(stmt); + FAIL_UNLESS(rc == MYSQL_NO_DATA, "rc != MYSQL_NO_DATA"); + + mysql_stmt_close(stmt); + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_bind_result"); + check_mysql_rc(rc, mysql); + + return OK; +} + +/* Test fetching of str to all types */ + +static int test_fetch_str(MYSQL *mysql) +{ + int rc; + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_bind_fetch"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE test_bind_fetch(c1 char(10), \ + c2 char(10), \ + c3 char(20), \ + c4 char(20), \ + c5 char(30), \ + c6 char(40), \ + c7 char(20))"); + check_mysql_rc(rc, mysql); + + rc= bind_fetch(mysql, 3); + mysql_query(mysql, "DROP TABLE IF EXISTS test_bind_fetch"); + return rc; +} + +/* Test fetching of long to all types */ + +static int test_fetch_long(MYSQL *mysql) +{ + int rc; + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_bind_fetch"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "CREATE TABLE test_bind_fetch(c1 int unsigned, \ + c2 int unsigned, \ + c3 int, \ + c4 int, \ + c5 int, \ + c6 int unsigned, \ + c7 int)"); + check_mysql_rc(rc, mysql); + rc= bind_fetch(mysql, 4); + mysql_query(mysql, "DROP TABLE IF EXISTS test_bind_fetch"); + return rc; +} + + +/* Test fetching of short to all types */ + +static int test_fetch_short(MYSQL *mysql) +{ + int rc; + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_bind_fetch"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "CREATE TABLE test_bind_fetch(c1 smallint unsigned, \ + c2 smallint, \ + c3 smallint unsigned, \ + c4 smallint, \ + c5 smallint, \ + c6 smallint, \ + c7 smallint unsigned)"); + check_mysql_rc(rc, mysql); + rc= bind_fetch(mysql, 5); + mysql_query(mysql, "DROP TABLE IF EXISTS test_bind_fetch"); + return rc; +} + + +/* Test fetching of tiny to all types */ + +static int test_fetch_tiny(MYSQL *mysql) +{ + int rc; + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_bind_fetch"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE test_bind_fetch(c1 tinyint unsigned, \ + c2 tinyint, \ + c3 tinyint unsigned, \ + c4 tinyint, \ + c5 tinyint, \ + c6 tinyint, \ + c7 tinyint unsigned)"); + check_mysql_rc(rc, mysql); + rc= bind_fetch(mysql, 3); + mysql_query(mysql, "DROP TABLE IF EXISTS test_bind_fetch"); + return rc; +} + + +/* Test fetching of longlong to all types */ + +static int test_fetch_bigint(MYSQL *mysql) +{ + int rc; + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_bind_fetch"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE test_bind_fetch(c1 bigint, \ + c2 bigint, \ + c3 bigint unsigned, \ + c4 bigint unsigned, \ + c5 bigint unsigned, \ + c6 bigint unsigned, \ + c7 bigint unsigned)"); + check_mysql_rc(rc, mysql); + rc= bind_fetch(mysql, 2); + mysql_query(mysql, "DROP TABLE IF EXISTS test_bind_fetch"); + return rc; +} + + +/* Test fetching of float to all types */ + +static int test_fetch_float(MYSQL *mysql) +{ + int rc; + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_bind_fetch"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE test_bind_fetch(c1 float(3), \ + c2 float, \ + c3 float unsigned, \ + c4 float, \ + c5 float, \ + c6 float, \ + c7 float(10) unsigned)"); + check_mysql_rc(rc, mysql); + + rc= bind_fetch(mysql, 2); + mysql_query(mysql, "DROP TABLE IF EXISTS test_bind_fetch"); + return rc; +} + + +/* Test fetching of double to all types */ + +static int test_fetch_double(MYSQL *mysql) +{ + int rc; + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_bind_fetch"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "CREATE TABLE test_bind_fetch(c1 double(5, 2), " + "c2 double unsigned, c3 double unsigned, " + "c4 double unsigned, c5 double unsigned, " + "c6 double unsigned, c7 double unsigned)"); + check_mysql_rc(rc, mysql); + rc= bind_fetch(mysql, 3); + mysql_query(mysql, "DROP TABLE IF EXISTS test_bind_fetch"); + return rc; +} + +static int test_conc281(MYSQL *mysql) +{ + int rc; + MYSQL_STMT *stmt= mysql_stmt_init(mysql); + MYSQL_BIND bind[2]; + unsigned long length= 0; + char buffer[2048]; + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS conc282"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE conc282 (a blob, b varchar(1000), c int)"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "INSERT INTO conc282 VALUES (REPEAT('A',2000), REPEAT('B', 999),3)"); + check_mysql_rc(rc, mysql); + + rc= mysql_stmt_prepare(stmt, "SELECT a, b FROM conc282", -1); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + + memset(bind, 0, sizeof(MYSQL_BIND) * 2); + + bind[0].buffer_type= MYSQL_TYPE_BLOB; + bind[0].buffer= buffer; + bind[0].buffer_length= 2048; + bind[0].length= &length; + + rc= mysql_stmt_fetch_column(stmt, &bind[0], 0, 0); + check_stmt_rc(rc, stmt); + + FAIL_IF(length != 2000, "Expected length= 2000"); + FAIL_IF(buffer[0] != 'A' || buffer[1999] != 'A', "Wrong result"); + + mysql_stmt_close(stmt); + + rc= mysql_query(mysql, "DROP TABLE conc282"); + check_mysql_rc(rc, mysql); + + return OK; + +} + +struct my_tests_st my_tests[] = { + {"test_conc281", test_conc281, 1, 0, NULL, NULL}, + {"test_fetch_seek", test_fetch_seek, 1, 0, NULL , NULL}, + {"test_fetch_offset", test_fetch_offset, 1, 0, NULL , NULL}, + {"test_fetch_column", test_fetch_column, 1, 0, NULL , NULL}, + {"test_fetch_nobuffs", test_fetch_nobuffs, 1, 0, NULL , NULL}, + {"test_fetch_null", test_fetch_null, 1, 0, NULL , NULL}, + {"test_fetch_date", test_fetch_date, 1, 0, NULL , NULL}, + {"test_fetch_str", test_fetch_str, 1, 0, NULL , NULL}, + {"test_fetch_long", test_fetch_long, 1, 0, NULL , NULL}, + {"test_fetch_short", test_fetch_short, 1, 0, NULL , NULL}, + {"test_fetch_tiny", test_fetch_tiny, 1, 0, NULL , NULL}, + {"test_fetch_bigint", test_fetch_bigint, 1, 0, NULL , NULL}, + {"test_fetch_float", test_fetch_float, 1, 0, NULL , NULL}, + {"test_fetch_double", test_fetch_double, 1, 0, NULL , NULL}, + {NULL, NULL, 0, 0, NULL, NULL} +}; + +int main(int argc, char **argv) +{ + if (argc > 1) + get_options(argc, argv); + + get_envvars(); + + run_tests(my_tests); + + return(exit_status()); +} diff --git a/vendor/MDBC/unittest/libmariadb/fingerprint.list.in b/vendor/MDBC/unittest/libmariadb/fingerprint.list.in new file mode 100644 index 00000000..06f2be28 --- /dev/null +++ b/vendor/MDBC/unittest/libmariadb/fingerprint.list.in @@ -0,0 +1,4 @@ +86DD6D764C0CA47C5014E1E7802674BFDB674ED3 +@SSL_CERT_FINGER_PRINT@ +73F1FEC1FE041473563BFF2D624B88F6CFCFE626 + diff --git a/vendor/MDBC/unittest/libmariadb/getopt.c b/vendor/MDBC/unittest/libmariadb/getopt.c new file mode 100644 index 00000000..50debeff --- /dev/null +++ b/vendor/MDBC/unittest/libmariadb/getopt.c @@ -0,0 +1,742 @@ +/* Getopt for GNU. + NOTE: getopt is now part of the C library, so if you don't know what + "Keep this file name-space clean" means, talk to roland@gnu.ai.mit.edu + before changing it! + + Copyright (C) 1987, 88, 89, 90, 91, 92, 93, 94 + Free Software Foundation, Inc. + +Changes by monty: +- Added include of string.h when necessary. +- Removed two warnings from gcc. + +This file is part of the GNU C Library. Its master source is NOT part of +the C library, however. The master source lives in /gd/gnu/lib. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Library General Public License as +published by the Free Software Foundation; either version 2 of the +License, or (at your option) any later version. + +The GNU C Library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Library General Public License for more details. + +You should have received a copy of the GNU Library General Public +License along with the GNU C Library; see the file COPYING.LIB. If +not, write to the Free Software Foundation, Inc., 675 Mass Ave, +Cambridge, MA 02139, USA. */ + +/* This tells Alpha OSF/1 not to define a getopt prototype in . + Ditto for AIX 3.2 and . */ +#ifndef _NO_PROTO +#define _NO_PROTO +#endif + +#ifdef HAVE_CONFIG_H +#include +#endif + +#if (!defined (__STDC__) || !__STDC__) && !defined(MSDOS) && !defined(OS2) +/* This is a separate conditional since some stdc systems + reject `defined (const)'. */ +#ifndef const +#define const +#endif +#endif + +#include /* Changes for mysys */ +#include + +/* Comment out all this code if we are using the GNU C Library, and are not + actually compiling the library itself. This code is part of the GNU C + Library, but also included in many other GNU distributions. Compiling + and linking in this code is a waste when using the GNU C library + (especially if it is a shared library). Rather than having every GNU + program understand `configure --with-gnu-libc' and omit the object files, + it is simpler to just do this in the source for each such file. */ + +#if defined (_LIBC) || !defined (__GNU_LIBRARY__) + + +/* This needs to come after some library #include + to get __GNU_LIBRARY__ defined. */ +#ifdef __GNU_LIBRARY__ +/* Don't include stdlib.h for non-GNU C libraries because some of them + contain conflicting prototypes for getopt. */ +#include +#endif /* GNU C library. */ + +/* This version of `getopt' appears to the caller like standard Unix `getopt' + but it behaves differently for the user, since it allows the user + to intersperse the options with the other arguments. + + As `getopt' works, it permutes the elements of ARGV so that, + when it is done, all the options precede everything else. Thus + all application programs are extended to handle flexible argument order. + + Setting the environment variable POSIXLY_CORRECT disables permutation. + Then the behavior is completely standard. + + GNU application programs can use a third alternative mode in which + they can distinguish the relative order of options and other arguments. */ + +#include "ma_getopt.h" + +/* For communication from `getopt' to the caller. + When `getopt' finds an option that takes an argument, + the argument value is returned here. + Also, when `ordering' is RETURN_IN_ORDER, + each non-option ARGV-element is returned here. */ + +char *optarg = NULL; + +/* Index in ARGV of the next element to be scanned. + This is used for communication to and from the caller + and for communication between successive calls to `getopt'. + + On entry to `getopt', zero means this is the first call; initialize. + + When `getopt' returns EOF, this is the index of the first of the + non-option elements that the caller should itself scan. + + Otherwise, `optind' communicates from one call to the next + how much of ARGV has been scanned so far. */ + +/* XXX 1003.2 says this must be 1 before any call. */ +int optind = 1; + +/* The next char to be scanned in the option-element + in which the last option character we returned was found. + This allows us to pick up the scan where we left off. + + If this is zero, or a null string, it means resume the scan + by advancing to the next ARGV-element. */ + +static char *nextchar; + +/* Callers store zero here to inhibit the error message + for unrecognized options. */ + +int opterr = 1; + +/* Set to an option character which was unrecognized. + This must be initialized on some systems to avoid linking in the + system's own getopt implementation. */ + +int optopt = '?'; + +/* Describe how to deal with options that follow non-option ARGV-elements. + + If the caller did not specify anything, + the default is REQUIRE_ORDER if the environment variable + POSIXLY_CORRECT is defined, PERMUTE otherwise. + + REQUIRE_ORDER means don't recognize them as options; + stop option processing when the first non-option is seen. + This is what Unix does. + This mode of operation is selected by either setting the environment + variable POSIXLY_CORRECT, or using `+' as the first character + of the list of option characters. + + PERMUTE is the default. We permute the contents of ARGV as we scan, + so that eventually all the non-options are at the end. This allows options + to be given in any order, even with programs that were not written to + expect this. + + RETURN_IN_ORDER is an option available to programs that were written + to expect options and other ARGV-elements in any order and that care about + the ordering of the two. We describe each non-option ARGV-element + as if it were the argument of an option with character code 1. + Using `-' as the first character of the list of option characters + selects this mode of operation. + + The special argument `--' forces an end of option-scanning regardless + of the value of `ordering'. In the case of RETURN_IN_ORDER, only + `--' can cause `getopt' to return EOF with `optind' != ARGC. */ + +static enum +{ + REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER +} ordering; + +/* Value of POSIXLY_CORRECT environment variable. */ +static char *posixly_correct; + +#ifdef __GNU_LIBRARY__ +/* We want to avoid inclusion of string.h with non-GNU libraries + because there are many ways it can cause trouble. + On some systems, it contains special magic macros that don't work + in GCC. */ +#include +#define my_index strchr +#else + +/* Avoid depending on library functions or files + whose names are inconsistent. */ + +static char * +my_index (const char *str, int chr) +{ + while (*str) + { + if (*str == chr) + return (char *) str; + str++; + } + return 0; +} + +/* If using GCC, we can safely declare strlen this way. + If not using GCC, it is ok not to declare it. */ +#ifdef __GNUC__ +/* Note that Motorola Delta 68k R3V7 comes with GCC but not stddef.h. + That was relevant to code that was here before. */ +#if !defined (__STDC__) || !__STDC__ +/* gcc with -traditional declares the built-in strlen to return int, + and has done so at least since version 2.4.5. -- rms. */ +extern int strlen (const char *); +#endif /* not __STDC__ */ +#endif /* __GNUC__ */ + +#endif /* not __GNU_LIBRARY__ */ + +/* Handle permutation of arguments. */ + +/* Describe the part of ARGV that contains non-options that have + been skipped. `first_nonopt' is the index in ARGV of the first of them; + `last_nonopt' is the index after the last of them. */ + +static int first_nonopt; +static int last_nonopt; + +/* Exchange two adjacent subsequences of ARGV. + One subsequence is elements [first_nonopt,last_nonopt) + which contains all the non-options that have been skipped so far. + The other is elements [last_nonopt,optind), which contains all + the options processed since those non-options were skipped. + + `first_nonopt' and `last_nonopt' are relocated so that they describe + the new indices of the non-options in ARGV after they are moved. */ + +static void +exchange (char **argv) +{ + int bottom = first_nonopt; + int middle = last_nonopt; + int top = optind; + char *tem; + + /* Exchange the shorter segment with the far end of the longer segment. + That puts the shorter segment into the right place. + It leaves the longer segment in the right place overall, + but it consists of two parts that need to be swapped next. */ + + while (top > middle && middle > bottom) + { + if (top - middle > middle - bottom) + { + /* Bottom segment is the short one. */ + int len = middle - bottom; + register int i; + + /* Swap it with the top part of the top segment. */ + for (i = 0; i < len; i++) + { + tem = argv[bottom + i]; + argv[bottom + i] = argv[top - (middle - bottom) + i]; + argv[top - (middle - bottom) + i] = tem; + } + /* Exclude the moved bottom segment from further swapping. */ + top -= len; + } + else + { + /* Top segment is the short one. */ + int len = top - middle; + register int i; + + /* Swap it with the bottom part of the bottom segment. */ + for (i = 0; i < len; i++) + { + tem = argv[bottom + i]; + argv[bottom + i] = argv[middle + i]; + argv[middle + i] = tem; + } + /* Exclude the moved top segment from further swapping. */ + bottom += len; + } + } + + /* Update records for the slots the non-options now occupy. */ + + first_nonopt += (optind - last_nonopt); + last_nonopt = optind; +} + +/* Initialize the internal data when the first call is made. */ + +static const char * +_getopt_initialize (const char *optstring) +{ + /* Start processing options with ARGV-element 1 (since ARGV-element 0 + is the program name); the sequence of previously skipped + non-option ARGV-elements is empty. */ + + first_nonopt = last_nonopt = optind = 1; + + nextchar = NULL; + + posixly_correct = getenv ("POSIXLY_CORRECT"); + + /* Determine how to handle the ordering of options and nonoptions. */ + + if (optstring[0] == '-') + { + ordering = RETURN_IN_ORDER; + ++optstring; + } + else if (optstring[0] == '+') + { + ordering = REQUIRE_ORDER; + ++optstring; + } + else if (posixly_correct != NULL) + ordering = REQUIRE_ORDER; + else + ordering = PERMUTE; + + return optstring; +} + +/* Scan elements of ARGV (whose length is ARGC) for option characters + given in OPTSTRING. + + If an element of ARGV starts with '-', and is not exactly "-" or "--", + then it is an option element. The characters of this element + (aside from the initial '-') are option characters. If `getopt' + is called repeatedly, it returns successively each of the option characters + from each of the option elements. + + If `getopt' finds another option character, it returns that character, + updating `optind' and `nextchar' so that the next call to `getopt' can + resume the scan with the following option character or ARGV-element. + + If there are no more option characters, `getopt' returns `EOF'. + Then `optind' is the index in ARGV of the first ARGV-element + that is not an option. (The ARGV-elements have been permuted + so that those that are not options now come last.) + + OPTSTRING is a string containing the legitimate option characters. + If an option character is seen that is not listed in OPTSTRING, + return '?' after printing an error message. If you set `opterr' to + zero, the error message is suppressed but we still return '?'. + + If a char in OPTSTRING is followed by a colon, that means it wants an arg, + so the following text in the same ARGV-element, or the text of the following + ARGV-element, is returned in `optarg'. Two colons mean an option that + wants an optional arg; if there is text in the current ARGV-element, + it is returned in `optarg', otherwise `optarg' is set to zero. + + If OPTSTRING starts with `-' or `+', it requests different methods of + handling the non-option ARGV-elements. + See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above. + + Long-named options begin with `--' instead of `-'. + Their names may be abbreviated as long as the abbreviation is unique + or is an exact match for some defined option. If they have an + argument, it follows the option name in the same ARGV-element, separated + from the option name by a `=', or else the in next ARGV-element. + When `getopt' finds a long-named option, it returns 0 if that option's + `flag' field is nonzero, the value of the option's `val' field + if the `flag' field is zero. + + The elements of ARGV aren't really const, because we permute them. + But we pretend they're const in the prototype to be compatible + with other systems. + + LONGOPTS is a vector of `struct option' terminated by an + element containing a name which is zero. + + LONGIND returns the index in LONGOPT of the long-named option found. + It is only valid when a long-named option has been found by the most + recent call. + + If LONG_ONLY is nonzero, '-' as well as '--' can introduce + long-named options. */ + +int +_getopt_internal (int argc, char *const *argv, const char *optstring, const struct option *longopts, int *longind, int long_only) +{ + optarg = NULL; + + if (optind == 0) + optstring = _getopt_initialize (optstring); + + if (nextchar == NULL || *nextchar == '\0') + { + /* Advance to the next ARGV-element. */ + + if (ordering == PERMUTE) + { + /* If we have just processed some options following some non-options, + exchange them so that the options come first. */ + + if (first_nonopt != last_nonopt && last_nonopt != optind) + exchange ((char **) argv); + else if (last_nonopt != optind) + first_nonopt = optind; + + /* Skip any additional non-options + and extend the range of non-options previously skipped. */ + + while (optind < argc + && (argv[optind][0] != '-' || argv[optind][1] == '\0')) + optind++; + last_nonopt = optind; + } + + /* The special ARGV-element `--' means premature end of options. + Skip it like a null option, + then exchange with previous non-options as if it were an option, + then skip everything else like a non-option. */ + + if (optind != argc && !strcmp (argv[optind], "--")) + { + optind++; + + if (first_nonopt != last_nonopt && last_nonopt != optind) + exchange ((char **) argv); + else if (first_nonopt == last_nonopt) + first_nonopt = optind; + last_nonopt = argc; + + optind = argc; + } + + /* If we have done all the ARGV-elements, stop the scan + and back over any non-options that we skipped and permuted. */ + + if (optind == argc) + { + /* Set the next-arg-index to point at the non-options + that we previously skipped, so the caller will digest them. */ + if (first_nonopt != last_nonopt) + optind = first_nonopt; + return EOF; + } + + /* If we have come to a non-option and did not permute it, + either stop the scan or describe it to the caller and pass it by. */ + + if ((argv[optind][0] != '-' || argv[optind][1] == '\0')) + { + if (ordering == REQUIRE_ORDER) + return EOF; + optarg = argv[optind++]; + return 1; + } + + /* We have found another option-ARGV-element. + Skip the initial punctuation. */ + + nextchar = (argv[optind] + 1 + + (longopts != NULL && argv[optind][1] == '-')); + } + + /* Decode the current option-ARGV-element. */ + + /* Check whether the ARGV-element is a long option. + + If long_only and the ARGV-element has the form "-f", where f is + a valid short option, don't consider it an abbreviated form of + a long option that starts with f. Otherwise there would be no + way to give the -f short option. + + On the other hand, if there's a long option "fubar" and + the ARGV-element is "-fu", do consider that an abbreviation of + the long option, just like "--fu", and not "-f" with arg "u". + + This distinction seems to be the most useful approach. */ + + if (longopts != NULL + && (argv[optind][1] == '-' + || (long_only && (argv[optind][2] || !my_index (optstring, argv[optind][1]))))) + { + char *nameend; + const struct option *p; + const struct option *pfound = NULL; + int exact = 0; + int ambig = 0; + int indfound=0; /* Keep gcc happy */ + int option_index; + + for (nameend = nextchar; *nameend && *nameend != '='; nameend++) + /* Do nothing. */ ; + + /* Test all long options for either exact match + or abbreviated matches. */ + for (p = longopts, option_index = 0; p->name; p++, option_index++) + if (!strncmp (p->name, nextchar, nameend - nextchar)) + { + if ((size_t) (nameend - nextchar) == (size_t) strlen (p->name)) + { + /* Exact match found. */ + pfound = p; + indfound = option_index; + exact = 1; + break; + } + else if (pfound == NULL) + { + /* First nonexact match found. */ + pfound = p; + indfound = option_index; + } + else + /* Second or later nonexact match found. */ + ambig = 1; + } + + if (ambig && !exact) + { + if (opterr) + fprintf (stderr, "%s: option `%s' is ambiguous\n", + argv[0], argv[optind]); + nextchar += strlen (nextchar); + optind++; + return '?'; + } + + if (pfound != NULL) + { + option_index = indfound; + optind++; + if (*nameend) + { + /* Don't test has_arg with >, because some C compilers don't + allow it to be used on enums. */ + if (pfound->has_arg) + optarg = nameend + 1; + else + { + if (opterr) + { + if (argv[optind - 1][1] == '-') + /* --option */ + fprintf (stderr, + "%s: option `--%s' doesn't allow an argument\n", + argv[0], pfound->name); + else + /* +option or -option */ + fprintf (stderr, + "%s: option `%c%s' doesn't allow an argument\n", + argv[0], argv[optind - 1][0], pfound->name); + } + nextchar += strlen (nextchar); + return '?'; + } + } + else if (pfound->has_arg == 1) + { + if (optind < argc) + optarg = argv[optind++]; + else + { + if (opterr) + fprintf (stderr, "%s: option `%s' requires an argument\n", + argv[0], argv[optind - 1]); + nextchar += strlen (nextchar); + return optstring[0] == ':' ? ':' : '?'; + } + } + nextchar += strlen (nextchar); + if (longind != NULL) + *longind = option_index; + if (pfound->flag) + { + *(pfound->flag) = pfound->val; + return 0; + } + return pfound->val; + } + + /* Can't find it as a long option. If this is not getopt_long_only, + or the option starts with '--' or is not a valid short + option, then it's an error. + Otherwise interpret it as a short option. */ + if (!long_only || argv[optind][1] == '-' + || my_index (optstring, *nextchar) == NULL) + { + if (opterr) + { + if (argv[optind][1] == '-') + /* --option */ + fprintf (stderr, "%s: unrecognized option `--%s'\n", + argv[0], nextchar); + else + /* +option or -option */ + fprintf (stderr, "%s: unrecognized option `%c%s'\n", + argv[0], argv[optind][0], nextchar); + } + nextchar = (char *) ""; + optind++; + return '?'; + } + } + + /* Look at and handle the next short option-character. */ + + { + char c = *nextchar++; + char *temp = my_index (optstring, c); + + /* Increment `optind' when we start to process its last character. */ + if (*nextchar == '\0') + ++optind; + + if (temp == NULL || c == ':') + { + if (opterr) + { + if (posixly_correct) + /* 1003.2 specifies the format of this message. */ + fprintf (stderr, "%s: illegal option -- %c\n", argv[0], c); + else + fprintf (stderr, "%s: invalid option -- %c\n", argv[0], c); + } + optopt = c; + return '?'; + } + if (temp[1] == ':') + { + if (temp[2] == ':') + { + /* This is an option that accepts an argument optionally. */ + if (*nextchar != '\0') + { + optarg = nextchar; + optind++; + } + else + optarg = NULL; + nextchar = NULL; + } + else + { + /* This is an option that requires an argument. */ + if (*nextchar != '\0') + { + optarg = nextchar; + /* If we end this ARGV-element by taking the rest as an arg, + we must advance to the next element now. */ + optind++; + } + else if (optind == argc) + { + if (opterr) + { + /* 1003.2 specifies the format of this message. */ + fprintf (stderr, "%s: option requires an argument -- %c\n", + argv[0], c); + } + optopt = c; + if (optstring[0] == ':') + c = ':'; + else + c = '?'; + } + else + /* We already incremented `optind' once; + increment it again when taking next ARGV-elt as argument. */ + optarg = argv[optind++]; + nextchar = NULL; + } + } + return c; + } +} + +int +getopt (int argc, char *const *argv, const char *optstring) +{ + return _getopt_internal (argc, argv, optstring, + (const struct option *) 0, + (int *) 0, + 0); +} + +#endif /* _LIBC or not __GNU_LIBRARY__. */ + +#ifdef TEST + +/* Compile with -DTEST to make an executable for use in testing + the above definition of `getopt'. */ + +int +main (argc, argv) + int argc; + char **argv; +{ + int c; + int digit_optind = 0; + + while (1) + { + int this_option_optind = optind ? optind : 1; + + c = getopt (argc, argv, "abc:d:0123456789"); + if (c == EOF) + break; + + switch (c) + { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + if (digit_optind != 0 && digit_optind != this_option_optind) + printf ("digits occur in two different argv-elements.\n"); + digit_optind = this_option_optind; + printf ("option %c\n", c); + break; + + case 'a': + printf ("option a\n"); + break; + + case 'b': + printf ("option b\n"); + break; + + case 'c': + printf ("option c with value `%s'\n", optarg); + break; + + case '?': + break; + + default: + printf ("?? getopt returned character code 0%o ??\n", c); + } + } + + if (optind < argc) + { + printf ("non-option ARGV-elements: "); + while (optind < argc) + printf ("%s ", argv[optind++]); + printf ("\n"); + } + + exit (0); +} + +#endif /* TEST */ diff --git a/vendor/MDBC/unittest/libmariadb/logs.c b/vendor/MDBC/unittest/libmariadb/logs.c new file mode 100644 index 00000000..e66144cf --- /dev/null +++ b/vendor/MDBC/unittest/libmariadb/logs.c @@ -0,0 +1,217 @@ +/* +Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. + +The MySQL Connector/C is licensed under the terms of the GPLv2 +, like most +MySQL Connectors. There are special exceptions to the terms and +conditions of the GPLv2 as it is applied to this software, see the +FLOSS License Exception +. + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published +by the Free Software Foundation; version 2 of the License. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ +#include "my_test.h" + +#ifdef ENABLE_IF_IN_USE +static int enable_general_log(MYSQL *mysql, int truncate) +{ + int rc; + + rc= mysql_query(mysql, "set @save_global_general_log=@@global.general_log"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "set @@global.general_log=on"); + check_mysql_rc(rc, mysql); + + if (truncate) + { + rc= mysql_query(mysql, "truncate mysql.general_log"); + check_mysql_rc(rc, mysql); + } + + return OK; +} + + +static int restore_general_log(MYSQL *mysql) +{ + int rc; + rc= mysql_query(mysql, "set @@global.general_log=@save_global_general_log"); + check_mysql_rc(rc, mysql); + + return OK; +} +#endif + +/* Test update/binary logs */ + +static int test_logs(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + MYSQL_BIND my_bind[2]; + char data[255]; + size_t length; + int rc; + short id; + + rc= mysql_query(mysql, "SET session sql_mode=''"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_logs"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE test_logs(id smallint, name varchar(20))"); + check_mysql_rc(rc, mysql); + + strcpy((char *)data, "INSERT INTO test_logs VALUES(?, ?)"); + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + + rc= mysql_stmt_prepare(stmt, SL(data)); + check_stmt_rc(rc, stmt); + + memset(my_bind, '\0', sizeof(my_bind)); + + my_bind[0].buffer_type= MYSQL_TYPE_SHORT; + my_bind[0].buffer= (void *)&id; + + my_bind[1].buffer_type= MYSQL_TYPE_STRING; + my_bind[1].buffer= (void *)&data; + my_bind[1].buffer_length= 255; + my_bind[1].length= (unsigned long *)&length; + + id= 9876; + strcpy((char *)data, "MySQL - Open Source Database"); + length= strlen(data); + + rc= mysql_stmt_bind_param(stmt, my_bind); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + strcpy((char *)data, "'"); + length= 1; + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + strcpy((char *)data, "\""); + length= 1; + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + strcpy((char *)data, "my\'sql\'"); + length= strlen(data); + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + strcpy((char *)data, "my\"sql\""); + length= strlen(data); + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + mysql_stmt_close(stmt); + + strcpy((char *)data, "INSERT INTO test_logs VALUES(20, 'mysql')"); + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + + rc= mysql_stmt_prepare(stmt, SL(data)); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + mysql_stmt_close(stmt); + + strcpy((char *)data, "SELECT * FROM test_logs WHERE id=?"); + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + + rc= mysql_stmt_prepare(stmt, SL(data)); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_bind_param(stmt, my_bind); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + my_bind[1].buffer_length= 255; + rc= mysql_stmt_bind_result(stmt, my_bind); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + + FAIL_UNLESS(id == 9876, "id != 9876"); + FAIL_UNLESS(length == 19 || length == 20, "Invalid Length"); /* Due to VARCHAR(20) */ + FAIL_UNLESS(strncmp(data, "MySQL - Open Source", 19) == 0, "data != 'MySQL - Open Source'"); + + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + + FAIL_UNLESS(length == 1, "length != 1"); + FAIL_UNLESS(strcmp(data, "'") == 0, "data != '''"); + + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + + FAIL_UNLESS(length == 1, "length != 1"); + FAIL_UNLESS(strcmp(data, "\"") == 0, "data != '\"'"); + + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + + FAIL_UNLESS(length == 7, "length != 7"); + FAIL_UNLESS(strcmp(data, "my\'sql\'") == 0, "data != my'sql'"); + + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + + FAIL_UNLESS(length == 7, "length != 7"); + + rc= mysql_stmt_fetch(stmt); + FAIL_UNLESS(rc == MYSQL_NO_DATA, "rc != MYSQL_NO_DATA"); + + mysql_stmt_close(stmt); + + rc= mysql_query(mysql, "DROP TABLE test_logs"); + check_mysql_rc(rc, mysql); + + return OK; +} + + +struct my_tests_st my_tests[] = { + {"test_logs", test_logs, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {NULL, NULL, 0, 0, NULL, NULL} +}; + +int main(int argc, char **argv) +{ + if (argc > 1) + get_options(argc, argv); + + get_envvars(); + + run_tests(my_tests); + + return(exit_status()); +} diff --git a/vendor/MDBC/unittest/libmariadb/ma_getopt.c b/vendor/MDBC/unittest/libmariadb/ma_getopt.c new file mode 100644 index 00000000..186cdcd5 --- /dev/null +++ b/vendor/MDBC/unittest/libmariadb/ma_getopt.c @@ -0,0 +1,741 @@ +/* Getopt for GNU. + NOTE: getopt is now part of the C library, so if you don't know what + "Keep this file name-space clean" means, talk to roland@gnu.ai.mit.edu + before changing it! + + Copyright (C) 1987, 88, 89, 90, 91, 92, 93, 94 + Free Software Foundation, Inc. + +Changes by monty: +- Added include of string.h when necessary. +- Removed two warnings from gcc. + +This file is part of the GNU C Library. Its master source is NOT part of +the C library, however. The master source lives in /gd/gnu/lib. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Library General Public License as +published by the Free Software Foundation; either version 2 of the +License, or (at your option) any later version. + +The GNU C Library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Library General Public License for more details. + +You should have received a copy of the GNU Library General Public +License along with the GNU C Library; see the file COPYING.LIB. If +not, write to the Free Software Foundation, Inc., 675 Mass Ave, +Cambridge, MA 02139, USA. */ + +/* This tells Alpha OSF/1 not to define a getopt prototype in . + Ditto for AIX 3.2 and . */ +#ifndef _NO_PROTO +#define _NO_PROTO +#endif + +#ifdef HAVE_CONFIG_H +#include +#endif + +#if (!defined (__STDC__) || !__STDC__) && !defined(MSDOS) && !defined(OS2) +/* This is a separate conditional since some stdc systems + reject `defined (const)'. */ +#ifndef const +#define const +#endif +#endif +#include +#include +#include +/* Comment out all this code if we are using the GNU C Library, and are not + actually compiling the library itself. This code is part of the GNU C + Library, but also included in many other GNU distributions. Compiling + and linking in this code is a waste when using the GNU C library + (especially if it is a shared library). Rather than having every GNU + program understand `configure --with-gnu-libc' and omit the object files, + it is simpler to just do this in the source for each such file. */ + +#if defined (_LIBC) || !defined (__GNU_LIBRARY__) + + +/* This needs to come after some library #include + to get __GNU_LIBRARY__ defined. */ +#ifdef __GNU_LIBRARY__ +/* Don't include stdlib.h for non-GNU C libraries because some of them + contain conflicting prototypes for getopt. */ +#include +#endif /* GNU C library. */ + +/* This version of `getopt' appears to the caller like standard Unix `getopt' + but it behaves differently for the user, since it allows the user + to intersperse the options with the other arguments. + + As `getopt' works, it permutes the elements of ARGV so that, + when it is done, all the options precede everything else. Thus + all application programs are extended to handle flexible argument order. + + Setting the environment variable POSIXLY_CORRECT disables permutation. + Then the behavior is completely standard. + + GNU application programs can use a third alternative mode in which + they can distinguish the relative order of options and other arguments. */ + +#include "ma_getopt.h" + +/* For communication from `getopt' to the caller. + When `getopt' finds an option that takes an argument, + the argument value is returned here. + Also, when `ordering' is RETURN_IN_ORDER, + each non-option ARGV-element is returned here. */ + +char *optarg = NULL; + +/* Index in ARGV of the next element to be scanned. + This is used for communication to and from the caller + and for communication between successive calls to `getopt'. + + On entry to `getopt', zero means this is the first call; initialize. + + When `getopt' returns EOF, this is the index of the first of the + non-option elements that the caller should itself scan. + + Otherwise, `optind' communicates from one call to the next + how much of ARGV has been scanned so far. */ + +/* XXX 1003.2 says this must be 1 before any call. */ +int optind = 1; + +/* The next char to be scanned in the option-element + in which the last option character we returned was found. + This allows us to pick up the scan where we left off. + + If this is zero, or a null string, it means resume the scan + by advancing to the next ARGV-element. */ + +static char *nextchar; + +/* Callers store zero here to inhibit the error message + for unrecognized options. */ + +int opterr = 1; + +/* Set to an option character which was unrecognized. + This must be initialized on some systems to avoid linking in the + system's own getopt implementation. */ + +int optopt = '?'; + +/* Describe how to deal with options that follow non-option ARGV-elements. + + If the caller did not specify anything, + the default is REQUIRE_ORDER if the environment variable + POSIXLY_CORRECT is defined, PERMUTE otherwise. + + REQUIRE_ORDER means don't recognize them as options; + stop option processing when the first non-option is seen. + This is what Unix does. + This mode of operation is selected by either setting the environment + variable POSIXLY_CORRECT, or using `+' as the first character + of the list of option characters. + + PERMUTE is the default. We permute the contents of ARGV as we scan, + so that eventually all the non-options are at the end. This allows options + to be given in any order, even with programs that were not written to + expect this. + + RETURN_IN_ORDER is an option available to programs that were written + to expect options and other ARGV-elements in any order and that care about + the ordering of the two. We describe each non-option ARGV-element + as if it were the argument of an option with character code 1. + Using `-' as the first character of the list of option characters + selects this mode of operation. + + The special argument `--' forces an end of option-scanning regardless + of the value of `ordering'. In the case of RETURN_IN_ORDER, only + `--' can cause `getopt' to return EOF with `optind' != ARGC. */ + +static enum +{ + REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER +} ordering; + +/* Value of POSIXLY_CORRECT environment variable. */ +static char *posixly_correct; + +#ifdef __GNU_LIBRARY__ +/* We want to avoid inclusion of string.h with non-GNU libraries + because there are many ways it can cause trouble. + On some systems, it contains special magic macros that don't work + in GCC. */ +#include +#define my_index strchr +#else + +/* Avoid depending on library functions or files + whose names are inconsistent. */ + +static char * +my_index (const char *str, int chr) +{ + while (*str) + { + if (*str == chr) + return (char *) str; + str++; + } + return 0; +} + +/* If using GCC, we can safely declare strlen this way. + If not using GCC, it is ok not to declare it. */ +#ifdef __GNUC__ +/* Note that Motorola Delta 68k R3V7 comes with GCC but not stddef.h. + That was relevant to code that was here before. */ +#if !defined (__STDC__) || !__STDC__ +/* gcc with -traditional declares the built-in strlen to return int, + and has done so at least since version 2.4.5. -- rms. */ +extern int strlen (const char *); +#endif /* not __STDC__ */ +#endif /* __GNUC__ */ + +#endif /* not __GNU_LIBRARY__ */ + +/* Handle permutation of arguments. */ + +/* Describe the part of ARGV that contains non-options that have + been skipped. `first_nonopt' is the index in ARGV of the first of them; + `last_nonopt' is the index after the last of them. */ + +static int first_nonopt; +static int last_nonopt; + +/* Exchange two adjacent subsequences of ARGV. + One subsequence is elements [first_nonopt,last_nonopt) + which contains all the non-options that have been skipped so far. + The other is elements [last_nonopt,optind), which contains all + the options processed since those non-options were skipped. + + `first_nonopt' and `last_nonopt' are relocated so that they describe + the new indices of the non-options in ARGV after they are moved. */ + +static void +exchange (char **argv) +{ + int bottom = first_nonopt; + int middle = last_nonopt; + int top = optind; + char *tem; + + /* Exchange the shorter segment with the far end of the longer segment. + That puts the shorter segment into the right place. + It leaves the longer segment in the right place overall, + but it consists of two parts that need to be swapped next. */ + + while (top > middle && middle > bottom) + { + if (top - middle > middle - bottom) + { + /* Bottom segment is the short one. */ + int len = middle - bottom; + register int i; + + /* Swap it with the top part of the top segment. */ + for (i = 0; i < len; i++) + { + tem = argv[bottom + i]; + argv[bottom + i] = argv[top - (middle - bottom) + i]; + argv[top - (middle - bottom) + i] = tem; + } + /* Exclude the moved bottom segment from further swapping. */ + top -= len; + } + else + { + /* Top segment is the short one. */ + int len = top - middle; + register int i; + + /* Swap it with the bottom part of the bottom segment. */ + for (i = 0; i < len; i++) + { + tem = argv[bottom + i]; + argv[bottom + i] = argv[middle + i]; + argv[middle + i] = tem; + } + /* Exclude the moved top segment from further swapping. */ + bottom += len; + } + } + + /* Update records for the slots the non-options now occupy. */ + + first_nonopt += (optind - last_nonopt); + last_nonopt = optind; +} + +/* Initialize the internal data when the first call is made. */ + +static const char * +_getopt_initialize (const char *optstring) +{ + /* Start processing options with ARGV-element 1 (since ARGV-element 0 + is the program name); the sequence of previously skipped + non-option ARGV-elements is empty. */ + + first_nonopt = last_nonopt = optind = 1; + + nextchar = NULL; + + posixly_correct = getenv ("POSIXLY_CORRECT"); + + /* Determine how to handle the ordering of options and nonoptions. */ + + if (optstring[0] == '-') + { + ordering = RETURN_IN_ORDER; + ++optstring; + } + else if (optstring[0] == '+') + { + ordering = REQUIRE_ORDER; + ++optstring; + } + else if (posixly_correct != NULL) + ordering = REQUIRE_ORDER; + else + ordering = PERMUTE; + + return optstring; +} + +/* Scan elements of ARGV (whose length is ARGC) for option characters + given in OPTSTRING. + + If an element of ARGV starts with '-', and is not exactly "-" or "--", + then it is an option element. The characters of this element + (aside from the initial '-') are option characters. If `getopt' + is called repeatedly, it returns successively each of the option characters + from each of the option elements. + + If `getopt' finds another option character, it returns that character, + updating `optind' and `nextchar' so that the next call to `getopt' can + resume the scan with the following option character or ARGV-element. + + If there are no more option characters, `getopt' returns `EOF'. + Then `optind' is the index in ARGV of the first ARGV-element + that is not an option. (The ARGV-elements have been permuted + so that those that are not options now come last.) + + OPTSTRING is a string containing the legitimate option characters. + If an option character is seen that is not listed in OPTSTRING, + return '?' after printing an error message. If you set `opterr' to + zero, the error message is suppressed but we still return '?'. + + If a char in OPTSTRING is followed by a colon, that means it wants an arg, + so the following text in the same ARGV-element, or the text of the following + ARGV-element, is returned in `optarg'. Two colons mean an option that + wants an optional arg; if there is text in the current ARGV-element, + it is returned in `optarg', otherwise `optarg' is set to zero. + + If OPTSTRING starts with `-' or `+', it requests different methods of + handling the non-option ARGV-elements. + See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above. + + Long-named options begin with `--' instead of `-'. + Their names may be abbreviated as long as the abbreviation is unique + or is an exact match for some defined option. If they have an + argument, it follows the option name in the same ARGV-element, separated + from the option name by a `=', or else the in next ARGV-element. + When `getopt' finds a long-named option, it returns 0 if that option's + `flag' field is nonzero, the value of the option's `val' field + if the `flag' field is zero. + + The elements of ARGV aren't really const, because we permute them. + But we pretend they're const in the prototype to be compatible + with other systems. + + LONGOPTS is a vector of `struct option' terminated by an + element containing a name which is zero. + + LONGIND returns the index in LONGOPT of the long-named option found. + It is only valid when a long-named option has been found by the most + recent call. + + If LONG_ONLY is nonzero, '-' as well as '--' can introduce + long-named options. */ + +int +_getopt_internal (int argc, char *const *argv, const char *optstring, const struct option *longopts, int *longind, int long_only) +{ + optarg = NULL; + + if (optind == 0) + optstring = _getopt_initialize (optstring); + + if (nextchar == NULL || *nextchar == '\0') + { + /* Advance to the next ARGV-element. */ + + if (ordering == PERMUTE) + { + /* If we have just processed some options following some non-options, + exchange them so that the options come first. */ + + if (first_nonopt != last_nonopt && last_nonopt != optind) + exchange ((char **) argv); + else if (last_nonopt != optind) + first_nonopt = optind; + + /* Skip any additional non-options + and extend the range of non-options previously skipped. */ + + while (optind < argc + && (argv[optind][0] != '-' || argv[optind][1] == '\0')) + optind++; + last_nonopt = optind; + } + + /* The special ARGV-element `--' means premature end of options. + Skip it like a null option, + then exchange with previous non-options as if it were an option, + then skip everything else like a non-option. */ + + if (optind != argc && !strcmp (argv[optind], "--")) + { + optind++; + + if (first_nonopt != last_nonopt && last_nonopt != optind) + exchange ((char **) argv); + else if (first_nonopt == last_nonopt) + first_nonopt = optind; + last_nonopt = argc; + + optind = argc; + } + + /* If we have done all the ARGV-elements, stop the scan + and back over any non-options that we skipped and permuted. */ + + if (optind == argc) + { + /* Set the next-arg-index to point at the non-options + that we previously skipped, so the caller will digest them. */ + if (first_nonopt != last_nonopt) + optind = first_nonopt; + return EOF; + } + + /* If we have come to a non-option and did not permute it, + either stop the scan or describe it to the caller and pass it by. */ + + if ((argv[optind][0] != '-' || argv[optind][1] == '\0')) + { + if (ordering == REQUIRE_ORDER) + return EOF; + optarg = argv[optind++]; + return 1; + } + + /* We have found another option-ARGV-element. + Skip the initial punctuation. */ + + nextchar = (argv[optind] + 1 + + (longopts != NULL && argv[optind][1] == '-')); + } + + /* Decode the current option-ARGV-element. */ + + /* Check whether the ARGV-element is a long option. + + If long_only and the ARGV-element has the form "-f", where f is + a valid short option, don't consider it an abbreviated form of + a long option that starts with f. Otherwise there would be no + way to give the -f short option. + + On the other hand, if there's a long option "fubar" and + the ARGV-element is "-fu", do consider that an abbreviation of + the long option, just like "--fu", and not "-f" with arg "u". + + This distinction seems to be the most useful approach. */ + + if (longopts != NULL + && (argv[optind][1] == '-' + || (long_only && (argv[optind][2] || !my_index (optstring, argv[optind][1]))))) + { + char *nameend; + const struct option *p; + const struct option *pfound = NULL; + int exact = 0; + int ambig = 0; + int indfound=0; /* Keep gcc happy */ + int option_index; + + for (nameend = nextchar; *nameend && *nameend != '='; nameend++) + /* Do nothing. */ ; + + /* Test all long options for either exact match + or abbreviated matches. */ + for (p = longopts, option_index = 0; p->name; p++, option_index++) + if (!strncmp (p->name, nextchar, nameend - nextchar)) + { + if ((size_t) (nameend - nextchar) == (size_t) strlen (p->name)) + { + /* Exact match found. */ + pfound = p; + indfound = option_index; + exact = 1; + break; + } + else if (pfound == NULL) + { + /* First nonexact match found. */ + pfound = p; + indfound = option_index; + } + else + /* Second or later nonexact match found. */ + ambig = 1; + } + + if (ambig && !exact) + { + if (opterr) + fprintf (stderr, "%s: option `%s' is ambiguous\n", + argv[0], argv[optind]); + nextchar += strlen (nextchar); + optind++; + return '?'; + } + + if (pfound != NULL) + { + option_index = indfound; + optind++; + if (*nameend) + { + /* Don't test has_arg with >, because some C compilers don't + allow it to be used on enums. */ + if (pfound->has_arg) + optarg = nameend + 1; + else + { + if (opterr) + { + if (argv[optind - 1][1] == '-') + /* --option */ + fprintf (stderr, + "%s: option `--%s' doesn't allow an argument\n", + argv[0], pfound->name); + else + /* +option or -option */ + fprintf (stderr, + "%s: option `%c%s' doesn't allow an argument\n", + argv[0], argv[optind - 1][0], pfound->name); + } + nextchar += strlen (nextchar); + return '?'; + } + } + else if (pfound->has_arg == 1) + { + if (optind < argc) + optarg = argv[optind++]; + else + { + if (opterr) + fprintf (stderr, "%s: option `%s' requires an argument\n", + argv[0], argv[optind - 1]); + nextchar += strlen (nextchar); + return optstring[0] == ':' ? ':' : '?'; + } + } + nextchar += strlen (nextchar); + if (longind != NULL) + *longind = option_index; + if (pfound->flag) + { + *(pfound->flag) = pfound->val; + return 0; + } + return pfound->val; + } + + /* Can't find it as a long option. If this is not getopt_long_only, + or the option starts with '--' or is not a valid short + option, then it's an error. + Otherwise interpret it as a short option. */ + if (!long_only || argv[optind][1] == '-' + || my_index (optstring, *nextchar) == NULL) + { + if (opterr) + { + if (argv[optind][1] == '-') + /* --option */ + fprintf (stderr, "%s: unrecognized option `--%s'\n", + argv[0], nextchar); + else + /* +option or -option */ + fprintf (stderr, "%s: unrecognized option `%c%s'\n", + argv[0], argv[optind][0], nextchar); + } + nextchar = (char *) ""; + optind++; + return '?'; + } + } + + /* Look at and handle the next short option-character. */ + + { + char c = *nextchar++; + char *temp = my_index (optstring, c); + + /* Increment `optind' when we start to process its last character. */ + if (*nextchar == '\0') + ++optind; + + if (temp == NULL || c == ':') + { + if (opterr) + { + if (posixly_correct) + /* 1003.2 specifies the format of this message. */ + fprintf (stderr, "%s: illegal option -- %c\n", argv[0], c); + else + fprintf (stderr, "%s: invalid option -- %c\n", argv[0], c); + } + optopt = c; + return '?'; + } + if (temp[1] == ':') + { + if (temp[2] == ':') + { + /* This is an option that accepts an argument optionally. */ + if (*nextchar != '\0') + { + optarg = nextchar; + optind++; + } + else + optarg = NULL; + nextchar = NULL; + } + else + { + /* This is an option that requires an argument. */ + if (*nextchar != '\0') + { + optarg = nextchar; + /* If we end this ARGV-element by taking the rest as an arg, + we must advance to the next element now. */ + optind++; + } + else if (optind == argc) + { + if (opterr) + { + /* 1003.2 specifies the format of this message. */ + fprintf (stderr, "%s: option requires an argument -- %c\n", + argv[0], c); + } + optopt = c; + if (optstring[0] == ':') + c = ':'; + else + c = '?'; + } + else + /* We already incremented `optind' once; + increment it again when taking next ARGV-elt as argument. */ + optarg = argv[optind++]; + nextchar = NULL; + } + } + return c; + } +} + +int +getopt (int argc, char *const *argv, const char *optstring) +{ + return _getopt_internal (argc, argv, optstring, + (const struct option *) 0, + (int *) 0, + 0); +} + +#endif /* _LIBC or not __GNU_LIBRARY__. */ + +#ifdef TEST + +/* Compile with -DTEST to make an executable for use in testing + the above definition of `getopt'. */ + +int +main (argc, argv) + int argc; + char **argv; +{ + int c; + int digit_optind = 0; + + while (1) + { + int this_option_optind = optind ? optind : 1; + + c = getopt (argc, argv, "abc:d:0123456789"); + if (c == EOF) + break; + + switch (c) + { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + if (digit_optind != 0 && digit_optind != this_option_optind) + printf ("digits occur in two different argv-elements.\n"); + digit_optind = this_option_optind; + printf ("option %c\n", c); + break; + + case 'a': + printf ("option a\n"); + break; + + case 'b': + printf ("option b\n"); + break; + + case 'c': + printf ("option c with value `%s'\n", optarg); + break; + + case '?': + break; + + default: + printf ("?? getopt returned character code 0%o ??\n", c); + } + } + + if (optind < argc) + { + printf ("non-option ARGV-elements: "); + while (optind < argc) + printf ("%s ", argv[optind++]); + printf ("\n"); + } + + exit (0); +} + +#endif /* TEST */ diff --git a/vendor/MDBC/unittest/libmariadb/ma_getopt.h b/vendor/MDBC/unittest/libmariadb/ma_getopt.h new file mode 100644 index 00000000..790915b9 --- /dev/null +++ b/vendor/MDBC/unittest/libmariadb/ma_getopt.h @@ -0,0 +1,135 @@ +/* Declarations for getopt. + Copyright (C) 1989, 90, 91, 92, 93, 94 Free Software Foundation, Inc. + +This file is part of the GNU C Library. Its master source is NOT part of +the C library, however. The master source lives in /gd/gnu/lib. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Library General Public License as +published by the Free Software Foundation; either version 2 of the +License, or (at your option) any later version. + +The GNU C Library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Library General Public License for more details. + +You should have received a copy of the GNU Library General Public +License along with the GNU C Library; see the file COPYING.LIB. If +not, write to the Free Software Foundation, Inc., 675 Mass Ave, +Cambridge, MA 02139, USA. */ + +#ifndef _GETOPT_H +#define _GETOPT_H 1 + +#ifdef __cplusplus +extern "C" { +#endif + +/* For communication from `getopt' to the caller. + When `getopt' finds an option that takes an argument, + the argument value is returned here. + Also, when `ordering' is RETURN_IN_ORDER, + each non-option ARGV-element is returned here. */ + +extern char *optarg; + +/* Index in ARGV of the next element to be scanned. + This is used for communication to and from the caller + and for communication between successive calls to `getopt'. + + On entry to `getopt', zero means this is the first call; initialize. + + When `getopt' returns EOF, this is the index of the first of the + non-option elements that the caller should itself scan. + + Otherwise, `optind' communicates from one call to the next + how much of ARGV has been scanned so far. */ + +extern int optind; + +/* Callers store zero here to inhibit the error message `getopt' prints + for unrecognized options. */ + +extern int opterr; + +/* Set to an option character which was unrecognized. */ + +extern int optopt; + +/* Describe the long-named options requested by the application. + The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector + of `struct option' terminated by an element containing a name which is + zero. + + The field `has_arg' is: + no_argument (or 0) if the option does not take an argument, + required_argument (or 1) if the option requires an argument, + optional_argument (or 2) if the option takes an optional argument. + + If the field `flag' is not NULL, it points to a variable that is set + to the value given in the field `val' when the option is found, but + left unchanged if the option is not found. + + To have a long-named option do something other than set an `int' to + a compiled-in constant, such as set a value from `optarg', set the + option's `flag' field to zero and its `val' field to a nonzero + value (the equivalent single-letter option character, if there is + one). For long options that have a zero `flag' field, `getopt' + returns the contents of the `val' field. */ + +struct option +{ +#if defined (__STDC__) && __STDC__ || defined(__cplusplus) + const char *name; +#else + char *name; +#endif + /* has_arg can't be an enum because some compilers complain about + type mismatches in all the code that assumes it is an int. */ + int has_arg; + int *flag; + int val; +}; + +/* Names for the values of the `has_arg' field of `struct option'. */ + +#define no_argument 0 +#define required_argument 1 +#define optional_argument 2 + +#if ( defined (__STDC__) && __STDC__ ) || defined(__cplusplus) || defined(MSDOS) +#ifdef __EMX__ +int getopt (int, char **, __const__ char *); +#elif defined( __GNU_LIBRARY__) +/* Many other libraries have conflicting prototypes for getopt, with + differences in the consts, in stdlib.h. To avoid compilation + errors, only prototype getopt for the GNU C library. */ +extern int getopt (int argc, char *const *argv, const char *shortopts); +#else /* not __GNU_LIBRARY__ */ +extern int getopt (int argc, char *const *argv, const char *optstring); +#endif /* __GNU_LIBRARY__ */ +extern int getopt_long (int argc, char *const *argv, const char *shortopts, + const struct option *longopts, int *longind); +extern int getopt_long_only (int argc, char *const *argv, + const char *shortopts, + const struct option *longopts, int *longind); + +/* Internal only. Users should not call this directly. */ +extern int _getopt_internal (int argc, char *const *argv, + const char *shortopts, + const struct option *longopts, int *longind, + int long_only); +#else /* not __STDC__ */ +extern int getopt (); +extern int getopt_long (); +extern int getopt_long_only (); + +extern int _getopt_internal (); +#endif /* __STDC__ */ + +#ifdef __cplusplus +} +#endif + +#endif /* _GETOPT_H */ diff --git a/vendor/MDBC/unittest/libmariadb/misc.c b/vendor/MDBC/unittest/libmariadb/misc.c new file mode 100644 index 00000000..ea7dd62a --- /dev/null +++ b/vendor/MDBC/unittest/libmariadb/misc.c @@ -0,0 +1,1666 @@ +/* +Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. + +The MySQL Connector/C is licensed under the terms of the GPLv2 +, like most +MySQL Connectors. There are special exceptions to the terms and +conditions of the GPLv2 as it is applied to this software, see the +FLOSS License Exception +. + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published +by the Free Software Foundation; version 2 of the License. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ +#include "my_test.h" +#include "ma_common.h" + +#include + + +/* + Bug#28075 "COM_DEBUG crashes mysqld" +*/ +#ifdef _WIN32 +#define R_OK 4 +#endif + +static int test_bug28075(MYSQL *mysql) +{ + int rc; + + SKIP_SKYSQL; + SKIP_MAXSCALE; + + rc= mysql_dump_debug_info(mysql); + check_mysql_rc(rc, mysql); + + rc= mysql_ping(mysql); + check_mysql_rc(rc, mysql); + + return OK; +} + +/* + Bug#28505: mysql_affected_rows() returns wrong value if CLIENT_FOUND_ROWS + flag is set. +*/ + +static int test_bug28505(MYSQL *mysql) +{ + unsigned long long res; + int rc; + + rc= mysql_query(mysql, "drop table if exists t1"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "create table t1(f1 int primary key)"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "insert into t1 values(1)"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "insert into t1 values(1) on duplicate key update f1=1"); + check_mysql_rc(rc, mysql); + res= mysql_affected_rows(mysql); + FAIL_UNLESS(!res, "res != 0"); + rc= mysql_query(mysql, "drop table t1"); + check_mysql_rc(rc, mysql); + return OK; +} + +/* + Bug #29692 Single row inserts can incorrectly report a huge number of + row insertions +*/ + +static int test_bug29692(MYSQL *mysql) +{ + int rc; + rc= mysql_query(mysql, "drop table if exists t1"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "create table t1(f1 int)"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "insert into t1 values(1)"); + check_mysql_rc(rc, mysql); + FAIL_UNLESS(1 == mysql_affected_rows(mysql), "affected_rows != 1"); + rc= mysql_query(mysql, "drop table t1"); + check_mysql_rc(rc, mysql); + return OK; +} + +static int bug31418_impl() +{ + my_bool is_null; + MYSQL *mysql; + int rc; + + + /* Create a new connection. */ + + mysql= test_connect(NULL); + if (!mysql) + return FAIL; + + /*********************************************************************** + Check that lock is free: + - IS_FREE_LOCK() should return 1; + - IS_USED_LOCK() should return NULL; + ***********************************************************************/ + + is_null= query_int_variable(mysql, + "IS_FREE_LOCK('bug31418')", + &rc); + FAIL_UNLESS(!is_null && rc, "rc = 0"); + + is_null= query_int_variable(mysql, + "IS_USED_LOCK('bug31418')", + &rc); + FAIL_UNLESS(is_null, "rc = 0"); + + /*********************************************************************** + Acquire lock and check the lock status (the lock must be in use): + - IS_FREE_LOCK() should return 0; + - IS_USED_LOCK() should return non-zero thread id; + ***********************************************************************/ + + query_int_variable(mysql, "GET_LOCK('bug31418', 1)", &rc); + FAIL_UNLESS(rc, "rc = 0"); + + is_null= query_int_variable(mysql, + "IS_FREE_LOCK('bug31418')", + &rc); + FAIL_UNLESS(!is_null && !rc, "rc = 0"); + + is_null= query_int_variable(mysql, + "IS_USED_LOCK('bug31418')", + &rc); + FAIL_UNLESS(!is_null && rc, "rc = 0"); + + /*********************************************************************** + Issue COM_CHANGE_USER command and check the lock status + (the lock must be free): + - IS_FREE_LOCK() should return 1; + - IS_USED_LOCK() should return NULL; + **********************************************************************/ + + rc= mysql_change_user(mysql, username, password, schema ? schema : "test"); + check_mysql_rc(rc, mysql); + + is_null= query_int_variable(mysql, + "IS_FREE_LOCK('bug31418')", + &rc); + FAIL_UNLESS(!is_null && rc, "rc = 0"); + + is_null= query_int_variable(mysql, + "IS_USED_LOCK('bug31418')", + &rc); + FAIL_UNLESS(is_null, "rc = 0"); + + /*********************************************************************** + That's it. Cleanup. + ***********************************************************************/ + + mysql_close(mysql); + return OK; +} + +static int test_bug31418(MYSQL *unused __attribute__((unused))) +{ + int i; + SKIP_MAXSCALE; + + if (!is_mariadb) + return SKIP; + /* Run test case for BUG#31418 for three different connections. */ + + for (i=0; i < 3; i++) + if (bug31418_impl()) + return FAIL; + + return OK; +} + +/* Query processing */ + +static int test_debug_example(MYSQL *mysql) +{ + int rc; + MYSQL_RES *result; + + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_debug_example"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE test_debug_example(" + "id INT PRIMARY KEY AUTO_INCREMENT, " + "name VARCHAR(20), xxx INT)"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "INSERT INTO test_debug_example (name) " + "VALUES ('mysql')"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "UPDATE test_debug_example SET name='updated' " + "WHERE name='deleted'"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "SELECT * FROM test_debug_example where name='mysql'"); + check_mysql_rc(rc, mysql); + + result= mysql_use_result(mysql); + FAIL_IF(!result, "Invalid result set"); + + while (mysql_fetch_row(result)); + mysql_free_result(result); + + rc= mysql_query(mysql, "DROP TABLE test_debug_example"); + check_mysql_rc(rc, mysql); + return OK; +} + +/* + Test a crash when invalid/corrupted .frm is used in the + SHOW TABLE STATUS + bug #93 (reported by serg@mysql.com). +*/ + +static int test_frm_bug(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + MYSQL_BIND my_bind[2]; + MYSQL_RES *result; + MYSQL_ROW row; + FILE *test_file; + char data_dir[FN_REFLEN]; + char test_frm[1024]; + int rc; + + SKIP_MYSQL(mysql); + + mysql_autocommit(mysql, TRUE); + + rc= mysql_query(mysql, "drop table if exists test_frm_bug"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "flush tables"); + check_mysql_rc(rc, mysql); + + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL("show variables like 'datadir'")); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + memset(my_bind, '\0', sizeof(my_bind)); + my_bind[0].buffer_type= MYSQL_TYPE_STRING; + my_bind[0].buffer= data_dir; + my_bind[0].buffer_length= FN_REFLEN; + my_bind[1]= my_bind[0]; + + rc= mysql_stmt_bind_result(stmt, my_bind); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_fetch(stmt); + FAIL_UNLESS(rc == MYSQL_NO_DATA, "rc != MYSQL_NO_DATA"); + + snprintf(test_frm, sizeof(test_frm)-1, "%s/%s/test_frm_bug.frm", data_dir, schema); + + if (!(test_file= fopen(test_frm, "w"))) + { + mysql_stmt_close(stmt); + diag("Can't write to file %s -> SKIP", test_frm); + return SKIP; + } + + rc= mysql_query(mysql, "SHOW TABLE STATUS like 'test_frm_bug'"); + check_mysql_rc(rc, mysql); + + result= mysql_store_result(mysql); + FAIL_IF(!result, "Invalid result set");/* It can't be NULL */ + + rc= 0; + while (mysql_fetch_row(result)) + rc++; + FAIL_UNLESS(rc == 1, "rowcount != 0"); + + mysql_data_seek(result, 0); + + row= mysql_fetch_row(result); + FAIL_IF(!row, "couldn't fetch row"); + + FAIL_UNLESS(row[17] != 0, "row[17] != 0"); + + mysql_free_result(result); + mysql_stmt_close(stmt); + + fclose(test_file); + mysql_query(mysql, "drop table if exists test_frm_bug"); + unlink(test_frm); + return OK; +} + +static int test_wl4166_1(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + int int_data; + char str_data[50]; + char tiny_data; + short small_data; + longlong big_data; + float real_data; + double double_data; + ulong length[7]; + my_bool is_null[7]; + MYSQL_BIND my_bind[7]; + const char *query; + int rc; + int i; + + if (mysql_get_server_version(mysql) < 50100) { + diag("Test requires MySQL Server version 5.1 or above"); + return SKIP; + } + rc= mysql_query(mysql, "DROP TABLE IF EXISTS table_4166"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE table_4166(col1 tinyint NOT NULL, " + "col2 varchar(15), col3 int, " + "col4 smallint, col5 bigint, " + "col6 float, col7 double, " + "colX varchar(10) default NULL)"); + check_mysql_rc(rc, mysql); + + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + query= "INSERT INTO table_4166(col1, col2, col3, col4, col5, col6, col7) " + "VALUES(?, ?, ?, ?, ?, ?, ?)"; + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + FAIL_IF(mysql_stmt_param_count(stmt) != 7, "param_count != 7"); + + memset(my_bind, '\0', sizeof(my_bind)); + /* tinyint */ + my_bind[0].buffer_type= MYSQL_TYPE_TINY; + my_bind[0].buffer= (void *)&tiny_data; + /* string */ + my_bind[1].buffer_type= MYSQL_TYPE_STRING; + my_bind[1].buffer= (void *)str_data; + my_bind[1].buffer_length= 1000; /* Max string length */ + /* integer */ + my_bind[2].buffer_type= MYSQL_TYPE_LONG; + my_bind[2].buffer= (void *)&int_data; + /* short */ + my_bind[3].buffer_type= MYSQL_TYPE_SHORT; + my_bind[3].buffer= (void *)&small_data; + /* bigint */ + my_bind[4].buffer_type= MYSQL_TYPE_LONGLONG; + my_bind[4].buffer= (void *)&big_data; + /* float */ + my_bind[5].buffer_type= MYSQL_TYPE_FLOAT; + my_bind[5].buffer= (void *)&real_data; + /* double */ + my_bind[6].buffer_type= MYSQL_TYPE_DOUBLE; + my_bind[6].buffer= (void *)&double_data; + + for (i= 0; i < (int) array_elements(my_bind); i++) + { + my_bind[i].length= &length[i]; + my_bind[i].is_null= &is_null[i]; + is_null[i]= 0; + } + + rc= mysql_stmt_bind_param(stmt, my_bind); + check_stmt_rc(rc, stmt); + + int_data= 320; + small_data= 1867; + big_data= 1000; + real_data= 2; + double_data= 6578.001; + + /* now, execute the prepared statement to insert 10 records.. */ + for (tiny_data= 0; tiny_data < 10; tiny_data++) + { + length[1]= sprintf(str_data, "MySQL%d", int_data); + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + int_data += 25; + small_data += 10; + big_data += 100; + real_data += 1; + double_data += 10.09; + } + + /* force a re-prepare with some DDL */ + + rc= mysql_query(mysql, + "ALTER TABLE table_4166 change colX colX varchar(20) default NULL"); + check_mysql_rc(rc, mysql); + + /* + execute the prepared statement again, + without changing the types of parameters already bound. + */ + + for (tiny_data= 50; tiny_data < 60; tiny_data++) + { + length[1]= sprintf(str_data, "MySQL%d", int_data); + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + int_data += 25; + small_data += 10; + big_data += 100; + real_data += 1; + double_data += 10.09; + } + + mysql_stmt_close(stmt); + + rc= mysql_query(mysql, "DROP TABLE table_4166"); + check_mysql_rc(rc, mysql); + return OK; +} + + +static int test_wl4166_2(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + int c_int; + MYSQL_TIME d_date; + MYSQL_BIND bind_out[2]; + int rc; + + if (mysql_get_server_version(mysql) < 50100) { + diag("Test requires MySQL Server version 5.1 or above"); + return SKIP; + } + + rc= mysql_query(mysql, "drop table if exists t1"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "create table t1 (c_int int, d_date date)"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, + "insert into t1 (c_int, d_date) values (42, '1948-05-15')"); + check_mysql_rc(rc, mysql); + + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL("select * from t1")); + check_stmt_rc(rc, stmt); + + memset(bind_out, '\0', sizeof(bind_out)); + bind_out[0].buffer_type= MYSQL_TYPE_LONG; + bind_out[0].buffer= (void*) &c_int; + + bind_out[1].buffer_type= MYSQL_TYPE_DATE; + bind_out[1].buffer= (void*) &d_date; + + rc= mysql_stmt_bind_result(stmt, bind_out); + check_stmt_rc(rc, stmt); + + /* int -> varchar transition */ + + rc= mysql_query(mysql, + "alter table t1 change column c_int c_int varchar(11)"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "FLUSH TABLES"); + check_mysql_rc(rc, mysql); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + + FAIL_UNLESS(c_int == 42, "c_int != 42"); + FAIL_UNLESS(d_date.year == 1948, "y!=1948"); + FAIL_UNLESS(d_date.month == 5, "m != 5"); + FAIL_UNLESS(d_date.day == 15, "d != 15"); + + rc= mysql_stmt_fetch(stmt); + FAIL_UNLESS(rc == MYSQL_NO_DATA, "rc != MYSQL_NO_DATA"); + + /* varchar to int retrieval with truncation */ + + rc= mysql_query(mysql, "update t1 set c_int='abcde'"); + check_mysql_rc(rc, mysql); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_fetch(stmt); + FAIL_IF(!rc, "Error expected"); + + FAIL_UNLESS(c_int == 0, "c != 0"); + + rc= mysql_stmt_fetch(stmt); + FAIL_UNLESS(rc == MYSQL_NO_DATA, "rc != MYSQL_NO_DATA"); + + /* alter table and increase the number of columns */ + rc= mysql_query(mysql, "alter table t1 add column d_int int"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "FLUSH TABLES"); + check_mysql_rc(rc, mysql); + + rc= mysql_stmt_execute(stmt); + FAIL_IF(!rc, "Error expected"); + + rc= mysql_stmt_reset(stmt); + check_stmt_rc(rc, stmt); + + /* decrease the number of columns */ + rc= mysql_query(mysql, "alter table t1 drop d_date, drop d_int"); + check_mysql_rc(rc, mysql); + rc= mysql_stmt_execute(stmt); + diag("rc=%d error: %d\n", rc, mysql_stmt_errno(stmt)); + FAIL_IF(!rc, "Error expected"); + + mysql_stmt_close(stmt); + rc= mysql_query(mysql, "drop table t1"); + check_mysql_rc(rc, mysql); + + return OK; +} + + +/** + Test how warnings generated during assignment of parameters + are (currently not) preserve in case of reprepare. +*/ + +static int test_wl4166_3(MYSQL *mysql) +{ + int rc; + MYSQL_STMT *stmt; + MYSQL_BIND my_bind[1]; + MYSQL_TIME tm[1]; + + if (mysql_get_server_version(mysql) < 50100) { + diag("Test requires MySQL Server version 5.1 or above"); + return SKIP; + } + + rc= mysql_query(mysql, "drop table if exists t1"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "create table t1 (year datetime)"); + check_mysql_rc(rc, mysql); + + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL("insert into t1 (year) values (?)")); + check_stmt_rc(rc, stmt); + + FAIL_IF(mysql_stmt_param_count(stmt) != 1, "param_count != 1"); + + memset(my_bind, '\0', sizeof(my_bind)); + my_bind[0].buffer_type= MYSQL_TYPE_DATETIME; + my_bind[0].buffer= &tm[0]; + + rc= mysql_stmt_bind_param(stmt, my_bind); + check_stmt_rc(rc, stmt); + + tm[0].year= 2014; + tm[0].month= 1; tm[0].day= 1; + tm[0].hour= 1; tm[0].minute= 1; tm[0].second= 1; + tm[0].second_part= 0; tm[0].neg= 0; + + /* Cause a statement reprepare */ + rc= mysql_query(mysql, "alter table t1 add column c int"); + check_mysql_rc(rc, mysql); + + rc= mysql_stmt_execute(stmt); + diag("rc=%d %s", rc, mysql_stmt_error(stmt)); + check_stmt_rc(rc, stmt); + + if (verify_col_data(mysql, "t1", "year", "2014-01-01 01:01:01")) { + mysql_stmt_close(stmt); + rc= mysql_query(mysql, "drop table t1"); + return FAIL; + } + + mysql_stmt_close(stmt); + + rc= mysql_query(mysql, "drop table t1"); + check_mysql_rc(rc, mysql); + return OK; +} + + +/** + Test that long data parameters, as well as parameters + that were originally in a different character set, are + preserved in case of reprepare. +*/ + +static int test_wl4166_4(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + int rc; + const char *stmt_text; + MYSQL_BIND bind_array[2]; + + /* Represented as numbers to keep UTF8 tools from clobbering them. */ + const char *koi8= "\xee\xd5\x2c\x20\xda\xc1\x20\xd2\xd9\xc2\xc1\xcc\xcb\xd5"; + const char *cp1251= "\xcd\xf3\x2c\x20\xe7\xe0\x20\xf0\xfb\xe1\xe0\xeb\xea\xf3"; + char buf1[16], buf2[16]; + ulong buf1_len, buf2_len; + + if (mysql_get_server_version(mysql) < 50100) { + diag("Test requires MySQL Server version 5.1 or above"); + return SKIP; + } + + rc= mysql_query(mysql, "drop table if exists t1"); + check_mysql_rc(rc, mysql); + + /* + Create table with binary columns, set session character set to cp1251, + client character set to koi8, and make sure that there is conversion + on insert and no conversion on select + */ + rc= mysql_query(mysql, + "create table t1 (c1 varbinary(255), c2 varbinary(255))"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "set character_set_client=koi8r, " + "character_set_connection=cp1251, " + "character_set_results=koi8r"); + check_mysql_rc(rc, mysql); + + memset(bind_array, '\0', sizeof(bind_array)); + + bind_array[0].buffer_type= MYSQL_TYPE_STRING; + + bind_array[1].buffer_type= MYSQL_TYPE_STRING; + bind_array[1].buffer= (void *) koi8; + bind_array[1].buffer_length= (unsigned long)strlen(koi8); + + stmt= mysql_stmt_init(mysql); + check_stmt_rc(rc, stmt); + + stmt_text= "insert into t1 (c1, c2) values (?, ?)"; + + rc= mysql_stmt_prepare(stmt, SL(stmt_text)); + check_stmt_rc(rc, stmt); + + mysql_stmt_bind_param(stmt, bind_array); + + mysql_stmt_send_long_data(stmt, 0, koi8, (unsigned long)strlen(koi8)); + + /* Cause a reprepare at statement execute */ + rc= mysql_query(mysql, "alter table t1 add column d int"); + check_mysql_rc(rc, mysql); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + stmt_text= "select c1, c2 from t1"; + + /* c1 and c2 are binary so no conversion will be done on select */ + rc= mysql_stmt_prepare(stmt, SL(stmt_text)); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + bind_array[0].buffer= buf1; + bind_array[0].buffer_length= sizeof(buf1); + bind_array[0].length= &buf1_len; + + bind_array[1].buffer= buf2; + bind_array[1].buffer_length= sizeof(buf2); + bind_array[1].length= &buf2_len; + + mysql_stmt_bind_result(stmt, bind_array); + + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + + FAIL_UNLESS(buf1_len == strlen(cp1251), ""); + FAIL_UNLESS(buf2_len == strlen(cp1251), ""); + FAIL_UNLESS(!memcmp(buf1, cp1251, buf1_len), ""); + FAIL_UNLESS(!memcmp(buf2, cp1251, buf1_len), ""); + + rc= mysql_stmt_fetch(stmt); + FAIL_UNLESS(rc == MYSQL_NO_DATA, ""); + + mysql_stmt_close(stmt); + + rc= mysql_query(mysql, "drop table t1"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "set names default"); + check_mysql_rc(rc, mysql); + return OK; +} + +/** + Test that COM_REFRESH issues a implicit commit. +*/ + +static int test_wl4284_1(MYSQL *mysql) +{ + int rc; + MYSQL_ROW row; + MYSQL_RES *result; + + diag("Test temporarily disabled"); + return SKIP; + + if (mysql_get_server_version(mysql) < 60000) { + diag("Test requires MySQL Server version 6.0 or above"); + return SKIP; + } + + /* set AUTOCOMMIT to OFF */ + rc= mysql_autocommit(mysql, FALSE); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS trans"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE trans (a INT) ENGINE=InnoDB"); + + if (mysql_errno(mysql) == ER_UNKNOWN_STORAGE_ENGINE) + { + diag("InnoDB not configured or available"); + return SKIP; + } + + check_mysql_rc(rc, mysql); + + + rc= mysql_query(mysql, "INSERT INTO trans VALUES(1)"); + check_mysql_rc(rc, mysql); + + rc= mysql_refresh(mysql, REFRESH_GRANT | REFRESH_TABLES); + check_mysql_rc(rc, mysql); + + rc= mysql_rollback(mysql); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "SELECT * FROM trans"); + check_mysql_rc(rc, mysql); + + result= mysql_use_result(mysql); + FAIL_IF(!result, "Invalid result set"); + + row= mysql_fetch_row(result); + FAIL_IF(!row, "Can't fetch row"); + + mysql_free_result(result); + + /* set AUTOCOMMIT to OFF */ + rc= mysql_autocommit(mysql, FALSE); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "DROP TABLE trans"); + check_mysql_rc(rc, mysql); + + return OK; +} + +static int test_bug49694(MYSQL *mysql) +{ + int rc; + MYSQL_RES *res; + MYSQL_ROW row; + int i; + FILE *fp; + + diag("Load local infile server : %ld", (mysql->server_capabilities & CLIENT_LOCAL_FILES)); + diag("Load local infile client : %ld", (mysql->client_flag & CLIENT_LOCAL_FILES)); + + SKIP_LOAD_INFILE_DISABLE; + SKIP_SKYSQL; + + rc= mysql_query(mysql, "select @@LOCAL_INFILE"); + check_mysql_rc(rc, mysql); + res= mysql_store_result(mysql); + row= mysql_fetch_row(res); + if (atol(row[0]) == 0) { + diag("Load local infile disable"); + return SKIP; + } + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS enclist"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE `enclist` (" + " `pat_id` int(11) NOT NULL," + " `episode_id` int(11) NOT NULL," + " `enc_id` double NOT NULL," + " PRIMARY KEY (`pat_id`,`episode_id`,`enc_id`)" + ") ENGINE=MyISAM DEFAULT CHARSET=latin1"); + check_mysql_rc(rc, mysql); + + fp= fopen("data.csv", "w"); + FAIL_IF(!fp, "Can't open data.csv"); + + for (i=0; i < 100; i++) + fprintf (fp, "%.08d,%d,%f\r\n", 100 + i, i % 3 + 1, 60000.0 + i/100); + fclose(fp); + + rc= mysql_query(mysql, "LOAD DATA LOCAL INFILE 'data.csv' INTO TABLE enclist " + "FIELDS TERMINATED BY '.' LINES TERMINATED BY '\r\n'"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "DELETE FROM enclist"); + check_mysql_rc(rc, mysql); + + FAIL_IF(mysql_affected_rows(mysql) != 100, "Import failure. Expected 2 imported rows"); + + rc= mysql_query(mysql, "DROP TABLE enclist"); + check_mysql_rc(rc, mysql); + mysql_free_result(res); + return OK; +} + +static int test_conc49(MYSQL *mysql) +{ + int rc; + MYSQL_RES *res; + MYSQL_ROW row; + + int i; + FILE *fp; + + SKIP_LOAD_INFILE_DISABLE; + SKIP_SKYSQL; + + rc= mysql_query(mysql, "select @@LOCAL_INFILE"); + check_mysql_rc(rc, mysql); + res= mysql_store_result(mysql); + row= mysql_fetch_row(res); + if (atol(row[0]) == 0) { + diag("Load local infile disable"); + return SKIP; + } + + fp= fopen("./sample.csv", "w"); + for (i=1; i < 4; i++) + fprintf(fp, "\"%d\", \"%d\", \"%d\"\r\n", i, i, i); + fclose(fp); + rc= mysql_query(mysql, "DROP TABLE IF EXISTS conc49"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "CREATE TABLE conc49 (a int, b int, c int) Engine=InnoDB DEFAULT CHARSET=latin1"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "LOAD DATA LOCAL INFILE './sample.csv' INTO TABLE conc49 FIELDS ESCAPED BY ' ' TERMINATED BY ',' ENCLOSED BY '\"' LINES TERMINATED BY '\r\n'"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "SELECT a FROM conc49"); + check_mysql_rc(rc, mysql); + res= mysql_store_result(mysql); + rc= (int)mysql_num_rows(res); + mysql_free_result(res); + FAIL_IF(rc != 3, "3 rows expected"); + rc= mysql_query(mysql, "DROP TABLE IF EXISTS conc49"); + check_mysql_rc(rc, mysql); + return OK; +} + +static int test_ldi_path(MYSQL *mysql) +{ + int rc; + + 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, "FLUSH TABLES"); + check_mysql_rc(rc, mysql); + +#ifdef _WIN32 + rc= mysql_query(mysql, "LOAD DATA LOCAL INFILE 'X:/non_existing_path/data.csv' INTO TABLE t1 " + "FIELDS TERMINATED BY '.' LINES TERMINATED BY '\r\n'"); +#else + rc= mysql_query(mysql, "LOAD DATA LOCAL INFILE '/non_existing_path/data.csv' INTO TABLE t1 " + "FIELDS TERMINATED BY '.' LINES TERMINATED BY '\r\n'"); +#endif + FAIL_IF(rc== 0, "Error expected"); + diag("Error: %d", mysql_errno(mysql)); + FAIL_IF(mysql_errno(mysql) == 0, "Error expected"); + + rc= mysql_query(mysql, "DROP TABLE t1"); + check_mysql_rc(rc, mysql); + return OK; +} + +#if _WIN32 +static int test_conc44(MYSQL *mysql) +{ + char query[1024]; + char *a_filename= "æøå.csv"; + int rc; + int i; + FILE *fp; + + rc= mysql_set_character_set(mysql, "latin1"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS enclist"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE `enclist` (" + " `pat_id` int(11) NOT NULL," + " `episode_id` int(11) NOT NULL," + " `enc_id` double NOT NULL," + " PRIMARY KEY (`pat_id`,`episode_id`,`enc_id`)" + ") ENGINE=MyISAM DEFAULT CHARSET=latin1"); + check_mysql_rc(rc, mysql); + + fp= fopen(a_filename, "w"); + FAIL_IF(!fp, "Can't open file"); + + for (i=0; i < 100; i++) + fprintf (fp, "%.08d,%d,%f\r\n", 100 + i, i % 3 + 1, 60000.0 + i/100); + fclose(fp); + + sprintf(query, "LOAD DATA LOCAL INFILE '%s' INTO TABLE enclist " + "FIELDS TERMINATED BY '.' LINES TERMINATED BY '\r\n'", a_filename); + rc= mysql_query(mysql, query); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "DELETE FROM enclist"); + check_mysql_rc(rc, mysql); + + FAIL_IF(mysql_affected_rows(mysql) != 100, "Import failure. Expected 2 imported rows"); + + rc= mysql_query(mysql, "DROP TABLE enclist"); + check_mysql_rc(rc, mysql); + return OK; +} +#endif + +static int test_connect_attrs(MYSQL *my) +{ + MYSQL *mysql; + MYSQL_RES *result; + int rc, len; + + rc= mysql_query(my, "SELECT * FROM performance_schema.session_connect_attrs LIMIT 1"); + if (rc != 0) + { + diag("Server doesn't support connection attributes"); + return SKIP; + } + + result= mysql_store_result(my); + /* MariaDB Connector/C already sent connection attrs after handshake. So if the table is + empty, it indicates that the performance schema is disabled */ + if (!mysql_num_rows(result)) + { + diag("skip: performance_schema not enabled"); + mysql_free_result(result); + return SKIP; + } + mysql_free_result(result); + + mysql= mysql_init(NULL); + + mysql_options4(mysql, MYSQL_OPT_CONNECT_ATTR_ADD, "foo0", "bar0"); + mysql_options4(mysql, MYSQL_OPT_CONNECT_ATTR_ADD, "foo1", "bar1"); + mysql_options4(mysql, MYSQL_OPT_CONNECT_ATTR_ADD, "foo2", "bar2"); + + FAIL_IF(!my_test_connect(mysql, hostname, username, password, schema, + port, socketname, 0), mysql_error(my)); + + if (!(mysql->server_capabilities & CLIENT_CONNECT_ATTRS)) + { + diag("Server doesn't support connection attributes"); + return SKIP; + } + + rc= mysql_query(mysql, "SELECT * FROM performance_schema.session_connect_attrs where attr_name like 'foo%'"); + check_mysql_rc(rc, mysql); + result= mysql_store_result(mysql); + rc= (int)mysql_num_rows(result); + mysql_free_result(result); + + mysql_options(mysql, MYSQL_OPT_CONNECT_ATTR_RESET, NULL); + mysql_options4(mysql, MYSQL_OPT_CONNECT_ATTR_ADD, "foo0", "bar0"); + mysql_options4(mysql, MYSQL_OPT_CONNECT_ATTR_ADD, "foo1", "bar1"); + mysql_options4(mysql, MYSQL_OPT_CONNECT_ATTR_ADD, "foo2", "bar2"); + mysql_options(mysql, MYSQL_OPT_CONNECT_ATTR_DELETE, "foo0"); + mysql_options(mysql, MYSQL_OPT_CONNECT_ATTR_DELETE, "foo1"); + mysql_options(mysql, MYSQL_OPT_CONNECT_ATTR_DELETE, "foo2"); + + len= (int)mysql->options.extension->connect_attrs_len; + + mysql_close(mysql); + + FAIL_IF(rc < 3, "Expected 3 or more rows"); + FAIL_IF(len != 0, "Expected connection_attr_len=0"); + + return OK; +} + +static int test_conc_114(MYSQL *mysql) +{ + if (mysql_client_find_plugin(mysql, "foo", 0)) + { + diag("Null pointer expected"); + return FAIL; + } + diag("Error: %s", mysql_error(mysql)); + return OK; +} + +/* run with valgrind */ +static int test_conc117(MYSQL *unused __attribute__((unused))) +{ + my_bool reconnect= 1; + MYSQL *my= mysql_init(NULL); + SKIP_MAXSCALE; + FAIL_IF(!my_test_connect(my, hostname, username, password, schema, + port, socketname, 0), mysql_error(my)); + + mysql_kill(my, mysql_thread_id(my)); + + mysql_options(my, MYSQL_OPT_RECONNECT, &reconnect); + + mysql_query(my, "SET @a:=1"); + mysql_close(my); + + return OK; +} + +static int test_read_timeout(MYSQL *unused __attribute__((unused))) +{ + int timeout= 5, rc; + MYSQL *my= mysql_init(NULL); + SKIP_MAXSCALE; + mysql_options(my, MYSQL_OPT_READ_TIMEOUT, &timeout); + FAIL_IF(!my_test_connect(my, hostname, username, password, schema, + port, socketname, 0), mysql_error(my)); + + rc= mysql_query(my, "SELECT SLEEP(50)"); + + FAIL_IF(rc == 0, "error expected"); + diag("error: %s", mysql_error(my)); + + mysql_close(my); + + return OK; +} + +#ifdef HAVE_REMOTEIO +void *remote_plugin; +static int test_remote1(MYSQL *mysql) +{ + int rc; + MYSQL_RES *res; + MYSQL_ROW row; + + SKIP_SKYSQL; + + remote_plugin= (void *)mysql_client_find_plugin(mysql, "remote_io", MARIADB_CLIENT_REMOTEIO_PLUGIN); + if (!remote_plugin) + { + diag("skip - no remote io plugin available"); + diag("error: %s", mysql_error(mysql)); + return SKIP; + } + + SKIP_LOAD_INFILE_DISABLE; + + rc= mysql_query(mysql, "select @@LOCAL_INFILE"); + check_mysql_rc(rc, mysql); + res= mysql_store_result(mysql); + row= mysql_fetch_row(res); + if (atol(row[0]) == 0) { + diag("Load local infile disable"); + return SKIP; + } + mysql_free_result(res); + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE t1 (a text)"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "LOAD DATA LOCAL INFILE 'http://www.example.com' INTO TABLE t1"); + if (rc && mysql_errno(mysql) == 2058) + { + diag("remote_io plugin not available"); + return SKIP; + } + check_mysql_rc(rc, mysql); + return OK; +} + +static int test_remote2(MYSQL *my) +{ + MYSQL *mysql; + + if (!remote_plugin) + { + diag("skip - no remote io plugin available"); + return SKIP; + } + mysql= mysql_init(NULL); + + mysql_options(mysql, MYSQL_READ_DEFAULT_FILE, "http://localhost/test.cnf"); + mysql_options(mysql, MYSQL_READ_DEFAULT_GROUP, "test"); + my_test_connect(mysql, hostname, username, password, schema, + 0, socketname, 0), mysql_error(my); + diag("port: %d", mysql->port); + mysql_close(mysql); + return OK; +} +#endif + +#ifndef _WIN32 +static int test_mdev12965(MYSQL *unused __attribute__((unused))) +{ + MYSQL *mysql; + my_bool reconnect = 0; + FILE *fp= NULL; + const char *env= getenv("MYSQL_TMP_DIR"); + char cnf_file1[FN_REFLEN + 1]; + + SKIP_SKYSQL; + if (travis_test) + return SKIP; + + if (!env) + env= "/tmp"; + + setenv("HOME", env, 1); + + snprintf(cnf_file1, FN_REFLEN, "%s%c.my.cnf", env, FN_LIBCHAR); + + diag("Config file: %s", cnf_file1); + + FAIL_IF(!access(cnf_file1, R_OK), "access"); + + mysql= mysql_init(NULL); + fp= fopen(cnf_file1, "w"); + FAIL_IF(!fp, "fopen"); + + fprintf(fp, "[client]\ndefault-character-set=latin2\nreconnect=1\n"); + fclose(fp); + + mysql_options(mysql, MYSQL_READ_DEFAULT_GROUP, ""); + my_test_connect(mysql, hostname, username, password, + schema, port, socketname, 0); + + remove(cnf_file1); + + FAIL_IF(strcmp(mysql_character_set_name(mysql), "latin2"), "expected charset latin2"); + mysql_get_optionv(mysql, MYSQL_OPT_RECONNECT, &reconnect); + FAIL_IF(reconnect != 1, "expected reconnect=1"); + mysql_close(mysql); + return OK; +} +#endif + +static int test_get_info(MYSQL *mysql) +{ + size_t sval; + unsigned int ival; + char *cval; + int rc; + MY_CHARSET_INFO cs; + MARIADB_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: %lu", (unsigned long)sval); + rc= mariadb_get_infov(mysql, MARIADB_NET_BUFFER_LENGTH, &sval); + FAIL_IF(rc, "mysql_get_info failed"); + diag("net_buffer_length: %lu", (unsigned long)sval); + rc= mariadb_get_infov(mysql, MARIADB_CLIENT_VERSION_ID, &sval); + FAIL_IF(rc, "mysql_get_info failed"); + diag("client_version_id: %lu", (unsigned long)sval); + rc= mariadb_get_infov(mysql, MARIADB_CONNECTION_SERVER_VERSION_ID, &sval); + FAIL_IF(rc, "mysql_get_info failed"); + diag("server_version_id: %lu", (unsigned long)sval); + rc= mariadb_get_infov(mysql, MARIADB_CONNECTION_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; +} + +static int test_zerofill(MYSQL *mysql) +{ + int rc; + MYSQL_ROW row; + MYSQL_RES *res; + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE t1 (a int(10) zerofill)"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "INSERT INTO t1 VALUES (1)"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "SELECT a FROM t1"); + check_mysql_rc(rc, mysql); + + if ((res= mysql_store_result(mysql))) + { + row= mysql_fetch_row(res); + diag("zerofill: %s", row[0]); + mysql_free_result(res); + } + return OK; +} + +static int test_server_status(MYSQL *mysql) +{ + int rc; + unsigned int server_status; +// MYSQL_STMT *stmt; + + if (mysql_get_server_version(mysql) < 100200) + return SKIP; + +// stmt= mysql_stmt_init(mysql); + + rc= mysql_autocommit(mysql, 1); + mariadb_get_infov(mysql, MARIADB_CONNECTION_SERVER_STATUS, &server_status); + FAIL_IF(!(server_status & SERVER_STATUS_AUTOCOMMIT), + "autocommit flag not set"); + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE t1 (a int, b int)"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "INSERT INTO t1 (a) VALUES (1),(2),(3),(4),(5)"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "UPDATE t1 SET a=9 WHERE a=8"); + check_mysql_rc(rc, mysql); + + mariadb_get_infov(mysql, MARIADB_CONNECTION_SERVER_STATUS, &server_status); + FAIL_IF(!(server_status & SERVER_QUERY_NO_INDEX_USED), "autocommit flag not set"); + + rc= mysql_query(mysql, "CREATE SCHEMA test_tmp"); + check_mysql_rc(rc, mysql); + + rc= mysql_select_db(mysql, "test_tmp"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "DROP SCHEMA test_tmp"); + check_mysql_rc(rc, mysql); + + mariadb_get_infov(mysql, MARIADB_CONNECTION_SERVER_STATUS, &server_status); + FAIL_IF(!(server_status & SERVER_STATUS_DB_DROPPED), + "DB_DROP flag not set"); + + FAIL_IF(!(server_status & SERVER_SESSION_STATE_CHANGED), + "SESSION_STATE_CHANGED flag not set"); + + rc= mysql_select_db(mysql, schema); + check_mysql_rc(rc, mysql); + +// mysql_stmt_close(stmt); + + return OK; +} + +static int test_wl6797(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + int rc; + const char *stmt_text; + my_ulonglong res; + + if (mysql_get_server_version(mysql) < 50703 || + (mariadb_connection(mysql) && mysql_get_server_version(mysql) < 100203)) + { + diag("Skipping test_wl6797: " + "tested feature does not exist in versions before MySQL 5.7.3 and MariaDB 10.2\n"); + return OK; + } + /* clean up the session */ + rc= mysql_reset_connection(mysql); + FAIL_UNLESS(rc == 0, ""); + + /* do prepare of a query */ + mysql_query(mysql, "use test"); + mysql_query(mysql, "DROP TABLE IF EXISTS t1"); + mysql_query(mysql, "CREATE TABLE t1 (a int)"); + + stmt= mysql_stmt_init(mysql); + stmt_text= "INSERT INTO t1 VALUES (1), (2)"; + + rc= mysql_stmt_prepare(stmt, SL(stmt_text)); + check_mysql_rc(rc, mysql); + + /* Execute the insert statement */ + rc= mysql_stmt_execute(stmt); + check_mysql_rc(rc, mysql); + + /* + clean the session this should remove the prepare statement + from the cache. + */ + rc= mysql_reset_connection(mysql); + FAIL_UNLESS(rc == 0, ""); + + /* this below stmt should report error */ + rc= mysql_stmt_execute(stmt); + FAIL_IF(rc == 0, ""); + + /* + bug#17653288: MYSQL_RESET_CONNECTION DOES NOT RESET LAST_INSERT_ID + */ + + mysql_query(mysql, "DROP TABLE IF EXISTS t2"); + rc= mysql_query(mysql, "CREATE TABLE t2 (a int NOT NULL PRIMARY KEY"\ + " auto_increment)"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "INSERT INTO t2 VALUES (null)"); + check_mysql_rc(rc, mysql); + res= mysql_insert_id(mysql); + FAIL_UNLESS(res == 1, ""); + rc= mysql_reset_connection(mysql); + FAIL_UNLESS(rc == 0, ""); + res= mysql_insert_id(mysql); + FAIL_UNLESS(res == 0, ""); + + rc= mysql_query(mysql, "INSERT INTO t2 VALUES (last_insert_id(100))"); + check_mysql_rc(rc, mysql); + res= mysql_insert_id(mysql); + FAIL_UNLESS(res == 100, ""); + rc= mysql_reset_connection(mysql); + FAIL_UNLESS(rc == 0, ""); + res= mysql_insert_id(mysql); + FAIL_UNLESS(res == 0, ""); + + mysql_query(mysql, "DROP TABLE IF EXISTS t1"); + mysql_query(mysql, "DROP TABLE IF EXISTS t2"); + mysql_stmt_close(stmt); + return OK; +} + +static int test_conc384(MYSQL *my __attribute__((unused))) +{ + char value[1000]; + int len; + MYSQL *mysql= mysql_init(NULL); + + memset(&value, 'A', 999); + value[999]= 0; + + mysql_optionsv(mysql, MYSQL_OPT_CONNECT_ATTR_ADD, "foo", value); + len= (int)mysql->options.extension->connect_attrs_len; + /* Length: 1 (=len) + 3 (="foo") + 3 (=len) + 999 (="AAA...") = 1006 */ + FAIL_IF(len != 1006, "Wrong length"); + mysql_optionsv(mysql, MYSQL_OPT_CONNECT_ATTR_DELETE, "foo"); + len= (int)mysql->options.extension->connect_attrs_len; + /* Length should be zero after deleting the connection attribute */ + FAIL_IF(len != 0, "Wrong length"); + mysql_close(mysql); + return OK; +} + +#ifndef _WIN32 +static int test_conc395(MYSQL *unused __attribute__((unused))) +{ + MYSQL *mysql; + FILE *fp= NULL; + const char *env= getenv("MYSQL_TMP_DIR"); + char cnf_file1[FN_REFLEN + 1]; + + SKIP_SKYSQL; + if (travis_test) + return SKIP; + + if (!env) + env= "/tmp"; + + setenv("HOME", env, 1); + + snprintf(cnf_file1, FN_REFLEN, "%s%c.my.cnf", env, FN_LIBCHAR); + + FAIL_IF(!access(cnf_file1, R_OK), "access"); + + mysql= mysql_init(NULL); + fp= fopen(cnf_file1, "w"); + FAIL_IF(!fp, "fopen"); + + /* Mix dash and underscore */ + fprintf(fp, "[client]\ndefault_character-set=latin2\n"); + fclose(fp); + + mysql_options(mysql, MYSQL_READ_DEFAULT_GROUP, ""); + my_test_connect(mysql, hostname, username, password, + schema, port, socketname, 0); + + remove(cnf_file1); + + FAIL_IF(strcmp(mysql_character_set_name(mysql), "latin2"), "expected charset latin2"); + mysql_close(mysql); + return OK; +} + +static int test_sslenforce(MYSQL *unused __attribute__((unused))) +{ + MYSQL *mysql; + FILE *fp= NULL; + const char *env= getenv("MYSQL_TMP_DIR"); + char cnf_file1[FN_REFLEN + 1]; + + SKIP_NOTLS; + SKIP_SKYSQL; + + if (travis_test) + return SKIP; + + if (!env) + env= "/tmp"; + setenv("HOME", env, 1); + + snprintf(cnf_file1, FN_REFLEN, "%s%c.my.cnf", env, FN_LIBCHAR); + + FAIL_IF(!access(cnf_file1, R_OK), "access"); + + mysql= mysql_init(NULL); + fp= fopen(cnf_file1, "w"); + FAIL_IF(!fp, "fopen"); + + /* Mix dash and underscore */ + fprintf(fp, "[client]\nssl_enforce=1\n"); + fclose(fp); + + mysql_options(mysql, MYSQL_READ_DEFAULT_GROUP, ""); + my_test_connect(mysql, hostname, username, password, + schema, port, socketname, 0); + + remove(cnf_file1); + + FAIL_IF(!mysql_get_ssl_cipher(mysql), "no secure connection"); + mysql_close(mysql); + return OK; +} +#endif + +static int test_conc457(MYSQL *mysql) +{ + MYSQL_RES *result; + + SKIP_MYSQL(mysql); + + result= mysql_list_processes(mysql); + + FAIL_IF(mysql_field_count(mysql) != 9, "expected 9 columns"); + mysql_free_result(result); + return OK; +} + +static int test_conc458(MYSQL *my __attribute__((unused))) +{ + MYSQL *mysql= mysql_init(NULL); + FAIL_IF(mysql_get_timeout_value(mysql) != 0, "expected timeout 0"); + mysql_close(mysql); + return OK; +} + + +static int test_conc533(MYSQL *mysql) +{ + my_bool skip= 1; + int rc; + MYSQL_RES *result; + MYSQL_ROW row; + MYSQL_STMT *stmt; + MYSQL_BIND bind[1]; + char buffer[10]; + + rc= mysql_options(mysql, MARIADB_OPT_SKIP_READ_RESPONSE, &skip); + + rc= mysql_real_query(mysql, SL("SELECT 1")); + check_mysql_rc(rc, mysql); + + rc= mysql->methods->db_read_query_result(mysql); + check_mysql_rc(rc, mysql); + + result= mysql_store_result(mysql); + row= mysql_fetch_row(result); + + FAIL_IF(strcmp(row[0], "1"), "Expected value \"1\""); + mysql_free_result(result); + + stmt= mysql_stmt_init(mysql); + rc= mysql_stmt_prepare(stmt, SL("SELECT 1")); + check_stmt_rc(rc, stmt); + + rc= mysql->methods->db_read_prepare_response(stmt); + check_stmt_rc(rc, stmt); + + FAIL_IF(mysql_stmt_field_count(stmt) != 1, "Expected field_count= 1"); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql->methods->db_read_execute_response(stmt); + check_stmt_rc(rc, stmt); + + memset(bind, 0, sizeof(MYSQL_BIND)); + bind[0].buffer= buffer; + bind[0].buffer_type= MYSQL_TYPE_STRING; + bind[0].buffer_length= 10; + + rc= mysql_stmt_bind_result(stmt, bind); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + + FAIL_IF(strcmp(buffer, "1"), "Expected value \"1\""); + + mysql_stmt_close(stmt); + + return OK; +} + +int display_extended_field_attribute(MYSQL *mysql) +{ + MYSQL_RES *result; + MYSQL_FIELD *fields; + + if (mysql_query(mysql, "CREATE TEMPORARY TABLE t1 (a POINT)")) + return 1; + + if (mysql_query(mysql, "SELECT a FROM t1")) + return 1; + + if (!(result= mysql_store_result(mysql))) + return 1; + + if ((fields= mysql_fetch_fields(result))) + { + MARIADB_CONST_STRING field_attr; + + if (!mariadb_field_attr(&field_attr, &fields[0], + MARIADB_FIELD_ATTR_DATA_TYPE_NAME)) + { + printf("Extended field attribute: %s\n", field_attr.str); + } + } + mysql_free_result(result); + return 0; +} + + +static int test_ext_field_attr(MYSQL *mysql) +{ + display_extended_field_attribute(mysql); + + return OK; +} + +struct my_tests_st my_tests[] = { + {"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_conc458", test_conc458, TEST_CONNECTION_NONE, 0, NULL, NULL}, + {"test_conc457", test_conc457, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_conc384", test_conc384, TEST_CONNECTION_NONE, 0, NULL, NULL}, +#ifndef _WIN32 + {"test_mdev12965", test_mdev12965, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_conc395", test_conc395, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_sslenforce", test_sslenforce, TEST_CONNECTION_NONE, 0, NULL, NULL}, +#endif + {"test_wl6797", test_wl6797, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_server_status", test_server_status, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_read_timeout", test_read_timeout, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_zerofill", test_zerofill, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, +#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}, + {"test_conc49", test_conc49, TEST_CONNECTION_NEW, 0, NULL, NULL}, + {"test_bug28075", test_bug28075, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_bug28505", test_bug28505, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_debug_example", test_debug_example, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_bug29692", test_bug29692, TEST_CONNECTION_NEW, CLIENT_FOUND_ROWS, NULL, NULL}, + {"test_bug31418", test_bug31418, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_frm_bug", test_frm_bug, TEST_CONNECTION_NEW, 0, NULL, NULL}, + {"test_wl4166_1", test_wl4166_1, TEST_CONNECTION_NEW, 0, NULL, NULL}, + {"test_wl4166_2", test_wl4166_2, TEST_CONNECTION_NEW, 0, NULL, NULL}, + {"test_wl4166_3", test_wl4166_3, TEST_CONNECTION_NEW, 0, NULL, NULL}, + {"test_wl4166_4", test_wl4166_4, TEST_CONNECTION_NEW, 0, NULL, NULL}, + {"test_wl4284_1", test_wl4284_1, TEST_CONNECTION_NEW, 0, NULL, NULL}, + {"test_bug49694", test_bug49694, TEST_CONNECTION_NEW, 0, NULL, NULL}, + {"test_ldi_path", test_ldi_path, TEST_CONNECTION_NEW, 0, NULL, NULL}, +#ifdef _WIN32 + {"test_conc44", test_conc44, TEST_CONNECTION_NEW, 0, NULL, NULL}, +#endif + {NULL, NULL, 0, 0, NULL, 0} +}; + + +int main(int argc, char **argv) +{ + if (argc > 1) + get_options(argc, argv); + + get_envvars(); + + run_tests(my_tests); + + return(exit_status()); +} diff --git a/vendor/MDBC/unittest/libmariadb/my_test.h b/vendor/MDBC/unittest/libmariadb/my_test.h new file mode 100644 index 00000000..5fc8b1a5 --- /dev/null +++ b/vendor/MDBC/unittest/libmariadb/my_test.h @@ -0,0 +1,711 @@ +/* +Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. + +The MySQL Connector/C is licensed under the terms of the GPLv2 +, like most +MySQL Connectors. There are special exceptions to the terms and +conditions of the GPLv2 as it is applied to this software, see the +FLOSS License Exception +. + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published +by the Free Software Foundation; version 2 of the License. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ +#include +#include +#include +#include +#include "ma_getopt.h" +#include +#include +#include +#include +#include +#include + +#ifndef WIN32 +#include +#else +#include +#endif + +#ifndef OK +# define OK 0 +#endif +#ifndef FAIL +# define FAIL 1 +#endif +#ifndef SKIP +# define SKIP -1 +#endif +#ifndef FALSE +# define FALSE 0 +#endif +#ifndef TRUE +# define TRUE 1 +#endif + +#define IS_SKYSQL(a) ((a) && strstr((a), "db.skysql.net")) +#define SKIP_SKYSQL \ +if (IS_SKYSQL(hostname)) \ +{ \ + diag("Not supported by SkySQL"); \ + return SKIP; \ +} + +#ifndef HAVE_SSL +#define SKIP_NOTLS \ +{ \ + diag("TLS not supported"); \ + return SKIP;\ +} +#else +#define SKIP_NOTLS +#endif + +#define IS_MAXSCALE() (getenv("srv")!=NULL && (strcmp(getenv("srv"), "maxscale") == 0 || strcmp(getenv("srv"), "skysql-ha") == 0)) +#define SKIP_MAXSCALE \ +if (IS_MAXSCALE()) \ +{ \ + diag("test disabled with maxscale"); \ + return SKIP; \ +} + +#define SKIP_LOAD_INFILE_DISABLE \ +if (!((mysql->server_capabilities & CLIENT_LOCAL_FILES) && \ + (mysql->options.client_flag & CLIENT_LOCAL_FILES))) { \ + diag("Load local infile not supported"); \ + return SKIP; \ +} + +#define MAX_KEY MAX_INDEXES +#define MAX_KEY_LENGTH_DECIMAL_WIDTH 4 /* strlen("4096") */ + +#define SL(s) (s), (unsigned long)strlen((s)) +#define SL_BIN(s) (s), (unsigned long)sizeof((s)) + +#define MAX_TEST_QUERY_LENGTH 300 /* MAX QUERY BUFFER LENGTH */ + +/* prevent warnings on Win64 by using STMT_LEN instead of strlen */ +#define STMT_LEN(A) ((unsigned long)strlen((A))) + +#define SKIP_TRAVIS()\ +do {\ + if (getenv("TRAVIS"))\ + {\ + diag("Skip test on Travis CI");\ + return SKIP;\ + }\ +}while(0) + +#define SKIP_MYSQL(mysql)\ +do {\ + if (!mariadb_connection(mysql))\ + {\ + diag("Skip test for non MariaDB server");\ + return OK;\ + }\ +} while(0) + +#define check_mysql_rc(rc, mysql) \ +do {\ + if (rc)\ + {\ + diag("Error (%d): %s (%d) in %s line %d", rc, mysql_error(mysql), \ + mysql_errno(mysql), __FILE__, __LINE__);\ + return(FAIL);\ + }\ +} while(0) + +#define check_stmt_rc(rc, stmt) \ +do {\ + if (rc)\ + {\ + diag("Error: %s (%s: %d)", mysql_stmt_error(stmt), __FILE__, __LINE__);\ + return(FAIL);\ + }\ +} while(0) + +#define FAIL_IF(expr, reason)\ +do {\ + if (expr)\ + {\ + diag("Error: %s (%s: %d)", reason, __FILE__, __LINE__);\ + return FAIL;\ + }\ +} while(0) + +#define FAIL_UNLESS(expr, reason)\ +do {\ + if (!(expr))\ + {\ + diag("Error: %s (%s: %d)", reason, __FILE__, __LINE__);\ + return FAIL;\ + }\ +} while(0) + +#define SKIP_CONNECTION_HANDLER \ +do {\ + if (hostname && strstr(hostname, "://"))\ + {\ + diag("Test skipped (connection handler)");\ + return SKIP;\ + }\ +} while(0) + +/* connection options */ +#define TEST_CONNECTION_DEFAULT 1 /* default connection */ +#define TEST_CONNECTION_NONE 2 /* tests creates own connection */ +#define TEST_CONNECTION_NEW 4 /* create a separate connection */ +#define TEST_CONNECTION_DONT_CLOSE 8 /* don't close connection */ + +struct my_option_st +{ + enum mysql_option option; + char *value; +}; + +struct my_tests_st +{ + const char *name; + int (*function)(MYSQL *); + int connection; + ulong connect_flags; + struct my_option_st *options; + const char *skipmsg; +}; + +MYSQL *my_test_connect(MYSQL *mysql, + const char *host, + const char *user, + const char *passwd, + const char *db, + unsigned int port, + const char *unix_socket, + unsigned long clientflag); + +static const char *schema = 0; +static char *hostname = 0; +static char *password = 0; +static unsigned int port = 0; +static unsigned int ssl_port = 0; +static char *socketname = 0; +static char *username = 0; +static int force_tls= 0; +static uchar is_mariadb= 0; +static char *this_host= 0; +static char *plugindir= 0; +static unsigned char travis_test= 0; +/* +static struct my_option test_options[] = +{ + {"schema", 'd', "database to use", (uchar **) &schema, (uchar **) &schema, + 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"help", '?', "Display this help and exit", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, + 0, 0, 0, 0, 0}, + {"host", 'h', "Connect to host", (uchar **) &hostname, (uchar **) &hostname, + 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"password", 'p', + "Password to use when connecting to server.", (uchar **) &password, (uchar **) &password, + 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0}, + {"port", 'P', "Port number to use for connection or 0 for default to, in " + "order of preference, my.cnf, $MYSQL_TCP_PORT, " +#if MYSQL_PORT_DEFAULT == 0 + "/etc/services, " +#endif + "built-in default (" STRINGIFY_ARG(MYSQL_PORT) ").", + (uchar **) &port, + (uchar **) &port, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"socket", 'S', "Socket file to use for connection", + (uchar **) &socketname, (uchar **) &socketname, 0, GET_STR, + REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"user", 'u', "User for login if not current user", (uchar **) &username, + (uchar **) &username, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0} +}; +*/ +#define verify_prepare_field(result,no,name,org_name,type,table,\ + org_table,db,length,def) \ + do_verify_prepare_field((result),(no),(name),(org_name),(type), \ + (table),(org_table),(db),(length),(def), \ + __FILE__, __LINE__) + +int do_verify_prepare_field(MYSQL_RES *result, + unsigned int no, const char *name, + const char *org_name, + enum enum_field_types type __attribute__((unused)), + const char *table, + const char *org_table, const char *db, + unsigned long length __attribute__((unused)), + const char *def __attribute__((unused)), + const char *file __attribute__((unused)), + int line __attribute__((unused))) +{ + MYSQL_FIELD *field; +/* MARIADB_CHARSET_INFO *cs; */ + + FAIL_IF(!(field= mysql_fetch_field_direct(result, no)), "FAILED to get result"); +/* cs= mysql_find_charset_nr(field->charsetnr); + FAIL_UNLESS(cs, "Couldn't get character set"); */ + FAIL_UNLESS(strcmp(field->name, name) == 0, "field->name differs"); + FAIL_UNLESS(strcmp(field->org_name, org_name) == 0, "field->org_name differs"); +/* + if ((expected_field_length= length * cs->mbmaxlen) > UINT_MAX32) + expected_field_length= UINT_MAX32; +*/ + /* + XXX: silent column specification change works based on number of + bytes a column occupies. So CHAR -> VARCHAR upgrade is possible even + for CHAR(2) column if its character set is multibyte. + VARCHAR -> CHAR downgrade won't work for VARCHAR(3) as one would + expect. + */ +// if (cs->char_maxlen == 1) +// FAIL_UNLESS(field->type == type, "field->type differs"); + if (table) + FAIL_UNLESS(strcmp(field->table, table) == 0, "field->table differs"); + if (org_table) + FAIL_UNLESS(strcmp(field->org_table, org_table) == 0, "field->org_table differs"); + if (strcmp(field->db,db)) + diag("%s / %s", field->db, db); + FAIL_UNLESS(strcmp(field->db, db) == 0, "field->db differs"); + /* + Character set should be taken into account for multibyte encodings, such + as utf8. Field length is calculated as number of characters * maximum + number of bytes a character can occupy. + */ + + return OK; +} + +void get_this_host(MYSQL *mysql) +{ + MYSQL_RES *res; + MYSQL_ROW row; + + if (mysql_query(mysql, "select substr(current_user(), locate('@', current_user())+1)")) + return; + + if ((res= mysql_store_result(mysql))) + { + if ((row= mysql_fetch_row(res))) + this_host= strdup(row[0]); + mysql_free_result(res); + } +} + +/* Prepare statement, execute, and process result set for given query */ + +int my_stmt_result(MYSQL *mysql, const char *buff) +{ + MYSQL_STMT *stmt; + int row_count= 0; + int rc; + + stmt= mysql_stmt_init(mysql); + + rc= mysql_stmt_prepare(stmt, buff, (unsigned long)strlen(buff)); + FAIL_IF(rc, mysql_stmt_error(stmt)); + + rc= mysql_stmt_execute(stmt); + FAIL_IF(rc, mysql_stmt_error(stmt)); + + while (mysql_stmt_fetch(stmt) != MYSQL_NO_DATA) + row_count++; + + mysql_stmt_close(stmt); + + return row_count; +} +/* +static my_bool +get_one_option(int optid, const struct my_option *opt __attribute__((unused)), + char *argument) +{ + switch (optid) { + case '?': + case 'I': + my_print_help(test_options); + exit(0); + break; + } + return 0; +} +*/ +/* Utility function to verify a particular column data */ + +int verify_col_data(MYSQL *mysql, const char *table, const char *col, + const char *exp_data) +{ + static char query[MAX_TEST_QUERY_LENGTH]; + MYSQL_RES *result; + MYSQL_ROW row; + int rc; + + if (table && col) + { + sprintf(query, "SELECT %s FROM %s LIMIT 1", col, table); + rc= mysql_query(mysql, query); + check_mysql_rc(rc, mysql); + } + result= mysql_use_result(mysql); + FAIL_IF(!result, "Invalid result set"); + + if (!(row= mysql_fetch_row(result)) || !row[0]) { + diag("Failed to get the result"); + goto error; + } + if(strcmp(row[0], exp_data)) { + diag("Expected %s, got %s", exp_data, row[0]); + goto error; + } + mysql_free_result(result); + + return OK; + +error: + mysql_free_result(result); + return FAIL; +} + +my_bool query_int_variable(MYSQL *con, const char *var_name, int *var_value) +{ + MYSQL_RES *rs; + MYSQL_ROW row; + + char query_buffer[MAX_TEST_QUERY_LENGTH]; + + my_bool is_null; + + sprintf(query_buffer, + "SELECT %s", + (const char *) var_name); + + FAIL_IF(mysql_query(con, query_buffer), "Query failed"); + FAIL_UNLESS(rs= mysql_store_result(con), "Invaliid result set"); + FAIL_UNLESS(row= mysql_fetch_row(rs), "Nothing to fetch"); + + is_null= row[0] == NULL; + + if (!is_null) + *var_value= atoi(row[0]); + + mysql_free_result(rs); + + return is_null; +} + +static void usage() +{ + printf("Execute test with the following options:\n"); + printf("-h hostname\n"); + printf("-u username\n"); + printf("-p password\n"); + printf("-d database\n"); + printf("-S socketname\n"); + printf("-t force use of TLS\n"); + printf("-P port number\n"); + printf("? displays this help and exits\n"); +} + +void get_options(int argc, char **argv) +{ + int c= 0; + + while ((c=getopt(argc,argv, "h:u:p:d:w:P:S:t:?")) >= 0) + { + switch(c) { + case 'h': + hostname= optarg; + break; + case 'u': + username= optarg; + break; + case 'p': + password= optarg; + break; + case 'd': + schema= optarg; + break; + case 'P': + port= atoi(optarg); + ssl_port=port; + break; + case 'S': + socketname= optarg; + break; + case 't': + force_tls= 1; + break; + case '?': + usage(); + exit(0); + break; + default: + usage(); + BAIL_OUT("Unknown option %c\n", c); + } + } +} + + +int check_variable(MYSQL *mysql, const char *variable, const char *value) +{ + char query[MAX_TEST_QUERY_LENGTH]; + MYSQL_RES *result; + MYSQL_ROW row; + + sprintf(query, "SELECT %s", variable); + result= mysql_store_result(mysql); + if (!result) + return FAIL; + + if ((row = mysql_fetch_row(result))) + if (strcmp(row[0], value) == 0) { + mysql_free_result(result); + return OK; + } + mysql_free_result(result); + return FAIL; +} + +/* + * function *test_connect + * + * returns a new connection. This function will be called, if the test doesn't + * use default_connection. + */ +MYSQL *test_connect(struct my_tests_st *test) +{ + MYSQL *mysql; + int i= 0, rc; + int timeout= 10; + my_bool truncation_report= 1; + if (!(mysql = mysql_init(NULL))) { + BAIL_OUT("Not enough memory available - mysql_init failed"); + } + mysql_options(mysql, MYSQL_REPORT_DATA_TRUNCATION, &truncation_report); + mysql_options(mysql, MYSQL_OPT_CONNECT_TIMEOUT, &timeout); + if (plugindir) + mysql_options(mysql, MYSQL_PLUGIN_DIR, plugindir); + + /* option handling */ + if (test && test->options) { + + while (test->options[i].option) + { + if (mysql_options(mysql, test->options[i].option, test->options[i].value)) { + diag("Couldn't set option %d. Error (%d) %s", test->options[i].option, + mysql_errno(mysql), mysql_error(mysql)); + mysql_close(mysql); + return(NULL); + } + i++; + } + } + if (!(my_test_connect(mysql, hostname, username, password, + schema, port, socketname, (test) ? test->connect_flags:0))) + { + diag("Couldn't establish connection to server %s. Error (%d): %s", + hostname, mysql_errno(mysql), mysql_error(mysql)); + mysql_close(mysql); + return(NULL); + } + + /* Clear sql_mode when establishing a new connection. */ + rc= mysql_query(mysql, "SET sql_mode=''"); + if (rc) + { + diag("Error (%d): %s (%d) in %s line %d", rc, mysql_error(mysql), + mysql_errno(mysql), __FILE__, __LINE__); + return(NULL); + } + + return(mysql); +} + +static int reset_connection(MYSQL *mysql) { + int rc; + + if (is_mariadb && !IS_MAXSCALE()) + rc= mysql_change_user(mysql, username, password, schema); + else + rc= mysql_reset_connection(mysql); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "SET sql_mode=''"); + check_mysql_rc(rc, mysql); + + return OK; +} + +/* + * function get_envvars(( + * + * checks for connection related environment variables + */ +void get_envvars() { + char *envvar; + + if (!getenv("MYSQLTEST_VARDIR") && + !getenv("MARIADB_CC_TEST")) + { + skip_all("Tests skipped.\nFor running unittest suite outside of MariaDB server tests,\nplease specify MARIADB_CC_TEST environment variable."); + exit(0); + } + + if (getenv("TRAVIS_JOB_ID")) + travis_test= 1; + + if (!hostname && (envvar= getenv("MYSQL_TEST_HOST"))) + hostname= envvar; + + + if (!username) + { + if ((envvar= getenv("MYSQL_TEST_USER"))) + username= envvar; + else + username= (char *)"root"; + } + if (!password && (envvar= getenv("MYSQL_TEST_PASSWD"))) + password= envvar; + if (!schema && (envvar= getenv("MYSQL_TEST_DB"))) + schema= envvar; + if (!schema) + schema= "test"; + if (!port) + { + if ((envvar= getenv("MYSQL_TEST_PORT"))) + port= atoi(envvar); + else if ((envvar= getenv("MASTER_MYPORT"))) + port= atoi(envvar); + diag("port: %d", port); + } + if (!ssl_port) + { + if ((envvar= getenv("MYSQL_TEST_SSL_PORT"))) + ssl_port= atoi(envvar); + else + ssl_port = port; + diag("ssl_port: %d", ssl_port); + } + + if (!force_tls && (envvar= getenv("MYSQL_TEST_TLS"))) + force_tls= atoi(envvar); + if (!socketname) + { + if ((envvar= getenv("MYSQL_TEST_SOCKET"))) + socketname= envvar; + else if ((envvar= getenv("MASTER_MYSOCK"))) + socketname= envvar; + diag("socketname: %s", socketname); + } + if ((envvar= getenv("MYSQL_TEST_PLUGINDIR"))) + plugindir= envvar; +} + +MYSQL *my_test_connect(MYSQL *mysql, + const char *host, + const char *user, + const char *passwd, + const char *db, + unsigned int port, + const char *unix_socket, + unsigned long clientflag) +{ + if (force_tls) + mysql_options(mysql, MYSQL_OPT_SSL_ENFORCE, &force_tls); + if (!mysql_real_connect(mysql, host, user, passwd, db, port, unix_socket, clientflag)) + { + diag("error: %s", mysql_error(mysql)); + return NULL; + } + + if (mysql && force_tls && !mysql_get_ssl_cipher(mysql)) + { + diag("Error: TLS connection not established"); + return NULL; + } + if (!this_host) + get_this_host(mysql); + return mysql; +} + + +void run_tests(struct my_tests_st *test) { + int i, rc, total=0; + MYSQL *mysql, *mysql_default= NULL; /* default connection */ + + while (test[total].function) + total++; + plan(total); + + if ((mysql_default= test_connect(NULL))) + { + diag("Testing against MySQL Server %s", mysql_get_server_info(mysql_default)); + diag("Host: %s", mysql_get_host_info(mysql_default)); + diag("Client library: %s", mysql_get_client_info()); + is_mariadb= mariadb_connection(mysql_default); + } + else + { + BAIL_OUT("Can't connect to a server. Aborting...."); + } + + for (i=0; i < total; i++) { + if (!mysql_default && (test[i].connection & TEST_CONNECTION_DEFAULT)) + { + diag("MySQL server not running"); + skip(1, "%s", test[i].name); + } else if (!test[i].skipmsg) { + mysql= mysql_default; + if (test[i].connection & TEST_CONNECTION_NEW) + mysql= test_connect(&test[i]); + if (test[i].connection & TEST_CONNECTION_NONE) + mysql= NULL; + + /* run test */ + rc= test[i].function(mysql); + + if (rc == SKIP) + skip(1, "%s", test[i].name); + else + ok(rc == OK, "%s", test[i].name); + + /* if test failed, close and reopen default connection to prevent + errors for further tests */ + if ((rc == FAIL || mysql_errno(mysql_default)) && (test[i].connection & TEST_CONNECTION_DEFAULT)) { + mysql_close(mysql_default); + mysql_default= test_connect(&test[i]); + } + /* clear connection: reset default connection or close extra connection */ + else if (mysql_default && (test[i].connection & TEST_CONNECTION_DEFAULT)) { + if (reset_connection(mysql)) + return; /* default doesn't work anymore */ + } + else if (mysql && !(test[i].connection & TEST_CONNECTION_DONT_CLOSE)) + { + mysql_close(mysql); + } + } else { + skip(1, "%s", test[i].skipmsg); + } + } + if (this_host) + free(this_host); + + if (mysql_default) { + diag("close default"); + mysql_close(mysql_default); + } +} diff --git a/vendor/MDBC/unittest/libmariadb/performance.c b/vendor/MDBC/unittest/libmariadb/performance.c new file mode 100644 index 00000000..f99253f7 --- /dev/null +++ b/vendor/MDBC/unittest/libmariadb/performance.c @@ -0,0 +1,76 @@ +/* +Copyright (c) 2016 MariaDB Corporation AB + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published +by the Free Software Foundation; version 2 of the License. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + + +/** + Some basic tests of the client API. +*/ + +#include "my_test.h" +#include "ma_common.h" + +static int perf1(MYSQL *mysql) +{ + int rc; + MYSQL_STMT *stmt; + const char *stmtstr= "SELECT s.emp_no, s.salary, e.emp_no, e.first_name, e.last_name, e.gender FROM salaries s, employees e WHERE s.emp_no = e.emp_no"; + + rc= mysql_select_db(mysql, "employees"); + if (rc) + { + diag("Employees database not installed"); + return SKIP; + } + + stmt= mysql_stmt_init(mysql); + + diag("prepare"); + rc= mysql_stmt_prepare(stmt, SL(stmtstr)); + check_stmt_rc(rc, stmt); + + diag("execute"); + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + diag("store"); + rc= mysql_stmt_store_result(stmt); + check_stmt_rc(rc, stmt); + + diag("fetch"); + while (!mysql_stmt_fetch(stmt)); + + mysql_stmt_close(stmt); + return OK; +} + +struct my_tests_st my_tests[] = { + {"perf1", perf1, TEST_CONNECTION_NEW, 0, NULL, NULL}, + {NULL, NULL, 0, 0, NULL, NULL} +}; + + +int main(int argc, char **argv) +{ + if (argc > 1) + get_options(argc, argv); + + get_envvars(); + + run_tests(my_tests); + + return(exit_status()); +} diff --git a/vendor/MDBC/unittest/libmariadb/ps.c b/vendor/MDBC/unittest/libmariadb/ps.c new file mode 100644 index 00000000..40ccad6f --- /dev/null +++ b/vendor/MDBC/unittest/libmariadb/ps.c @@ -0,0 +1,5208 @@ +/* +Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. + +The MySQL Connector/C is licensed under the terms of the GPLv2 +, like most +MySQL Connectors. There are special exceptions to the terms and +conditions of the GPLv2 as it is applied to this software, see the +FLOSS License Exception +. + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published +by the Free Software Foundation; version 2 of the License. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ +#include "my_test.h" + +/* Utility function to verify the field members */ + +static int test_conc97(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + int rc; + + diag("Please run this test manually"); + return SKIP; + stmt= mysql_stmt_init(mysql); + + mysql_close(mysql); + + rc= mysql_stmt_reset(stmt); + FAIL_IF(!rc, "Error expected while resetting stmt"); + + rc= mysql_stmt_close(stmt); + check_stmt_rc(rc, stmt); + + mysql= mysql_init(NULL); + + return OK; +} + +static int test_conc83(MYSQL *unused __attribute__((unused))) +{ + MYSQL_STMT *stmt; + int rc; + MYSQL *mysql= mysql_init(NULL); + my_bool reconnect= 1; + + const char *query= "SELECT 1,2,3 FROM DUAL"; + + SKIP_MAXSCALE; + + stmt= mysql_stmt_init(mysql); + + mysql_options(mysql, MYSQL_OPT_RECONNECT, &reconnect); + FAIL_IF(!(my_test_connect(mysql, hostname, username, password, + schema, port, socketname, 0)), "my_test_connect failed"); + + /* 1. Status is inited, so prepare should work */ + + rc= mysql_kill(mysql, mysql_thread_id(mysql)); + + rc= mysql_ping(mysql); + check_mysql_rc(rc, mysql); + + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + diag("Ok"); + + /* 2. Status is prepared, execute should fail */ + rc= mysql_kill(mysql, mysql_thread_id(mysql)); + + rc= mysql_stmt_execute(stmt); + FAIL_IF(!rc, "Error expected"); + + mysql_stmt_close(stmt); + mysql_close(mysql); + return OK; +} + + +static int test_conc60(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + int rc; + const char *query= "SELECT * FROM agendas"; + my_bool x= 1; + + stmt= mysql_stmt_init(mysql); + + rc= mysql_stmt_attr_set(stmt, STMT_ATTR_UPDATE_MAX_LENGTH, (void *)&x); + + rc= mysql_stmt_prepare(stmt, SL(query)); + if (rc && mysql_stmt_errno(stmt) == 1146) { + diag("Internal test - customer data not available"); + mysql_stmt_close(stmt); + return SKIP; + } + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_store_result(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_free_result(stmt); + check_stmt_rc(rc, stmt); + + mysql_stmt_close(stmt); + + return OK; +} + +static int test_prepare_insert_update(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + int rc; + int i; + const char *testcase[]= { + "CREATE TABLE t1 (a INT, b INT, c INT, UNIQUE (A), UNIQUE(B))", + "INSERT t1 VALUES (1,2,10), (3,4,20)", + "INSERT t1 VALUES (5,6,30), (7,4,40), (8,9,60) ON DUPLICATE KEY UPDATE c=c+100", + "SELECT * FROM t1", + "INSERT t1 SET a=5 ON DUPLICATE KEY UPDATE b=0", + "SELECT * FROM t1", + "INSERT t1 VALUES (2,1,11), (7,4,40) ON DUPLICATE KEY UPDATE c=c+VALUES(a)", + NULL}; + const char **cur_query; + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1"); + check_mysql_rc(rc, mysql); + + for (cur_query= testcase; *cur_query; cur_query++) + { + char query[MAX_TEST_QUERY_LENGTH]; + strcpy(query, *cur_query); + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + FAIL_IF(mysql_stmt_param_count(stmt) != 0, "Paramcount is not 0"); + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + /* try the last query several times */ + if (!cur_query[1]) + { + for (i=0; i < 3;i++) + { + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + } + } + mysql_stmt_close(stmt); + } + + rc= mysql_commit(mysql); + check_mysql_rc(rc, mysql); + + return OK; +} + +/* + Generalized conversion routine to handle DATE, TIME and DATETIME + conversion using MYSQL_TIME structure +*/ + +static int test_bind_date_conv(MYSQL *mysql, uint row_count) +{ + MYSQL_STMT *stmt= 0; + uint rc, i, count= row_count; + MYSQL_BIND my_bind[4]; + my_bool is_null[4]= {0,0,0,0}; + MYSQL_TIME tm[4]; + ulong second_part; + uint year, month, day, hour, minute, sec; + + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL("INSERT INTO test_date VALUES(?, ?, ?, ?)")); + check_stmt_rc(rc, stmt); + + FAIL_IF(mysql_stmt_param_count(stmt) != 4, "param_count != 4"); + + /* + We need to bzero bind structure because mysql_stmt_bind_param checks all + its members. + */ + memset(my_bind, '\0', sizeof(my_bind)); + + my_bind[0].buffer_type= MYSQL_TYPE_TIMESTAMP; + my_bind[1].buffer_type= MYSQL_TYPE_TIME; + my_bind[2].buffer_type= MYSQL_TYPE_DATETIME; + my_bind[3].buffer_type= MYSQL_TYPE_DATETIME; + + for (i= 0; i < (int) array_elements(my_bind); i++) + { + my_bind[i].buffer= (void *) &tm[i]; + my_bind[i].is_null= &is_null[i]; + my_bind[i].buffer_length= sizeof(MYSQL_TIME); + } + + second_part= 0; + + year= 2000; + month= 01; + day= 10; + + hour= 11; + minute= 16; + sec= 20; + + rc= mysql_stmt_bind_param(stmt, my_bind); + check_stmt_rc(rc, stmt); + + for (count= 0; count < row_count; count++) + { + for (i= 0; i < (int) array_elements(my_bind); i++) + { + memset(&tm[i], 0, sizeof(MYSQL_TIME)); + tm[i].neg= 0; + tm[i].second_part= second_part+count; + if (my_bind[i].buffer_type != MYSQL_TYPE_TIME) + { + tm[i].year= year+count; + tm[i].month= month+count; + tm[i].day= day+count; + } + else + tm[i].year= tm[i].month= tm[i].day= 0; + if (my_bind[i].buffer_type != MYSQL_TYPE_DATE) + { + tm[i].hour= hour+count; + tm[i].minute= minute+count; + tm[i].second= sec+count; + } + else + tm[i].hour= tm[i].minute= tm[i].second= 0; + } + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + } + + rc= mysql_commit(mysql); + check_mysql_rc(rc, mysql); + + mysql_stmt_close(stmt); + + rc= my_stmt_result(mysql, "SELECT * FROM test_date"); + FAIL_UNLESS(row_count == rc, "rowcount != rc"); + + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL("SELECT * FROM test_date")); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_bind_result(stmt, my_bind); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_store_result(stmt); + check_stmt_rc(rc, stmt); + + for (count= 0; count < row_count; count++) + { + rc= mysql_stmt_fetch(stmt); + FAIL_UNLESS(rc == 0 || rc == MYSQL_DATA_TRUNCATED, "rc != 0 | rc != MYSQL_DATA_TRUNCATED"); + + for (i= 0; i < array_elements(my_bind); i++) + { + FAIL_UNLESS(tm[i].year == 0 || tm[i].year == year+count, "wrong value for year"); + FAIL_UNLESS(tm[i].month == 0 || tm[i].month == month+count, "wrong value for month"); + FAIL_UNLESS(tm[i].day == 0 || tm[i].day == day+count, "wrong value for day"); + FAIL_UNLESS(tm[i].hour == 0 || tm[i].hour % 24 == 0 || tm[i].hour % 24 == hour+count, "wrong value for hour"); + FAIL_UNLESS(tm[i].minute == 0 || tm[i].minute == minute+count, "wrong value for minute"); + FAIL_UNLESS(tm[i].second == 0 || tm[i].second == sec+count, "wrong value for second"); + FAIL_UNLESS(tm[i].second_part == 0 || + tm[i].second_part == second_part+count, "wrong value for second_part"); + } + } + rc= mysql_stmt_fetch(stmt); + FAIL_UNLESS(rc == MYSQL_NO_DATA, "rc != MYSQL_NO_DATA"); + + mysql_stmt_close(stmt); + return OK; +} + + +/* Test simple prepares of all DML statements */ + +static int test_prepare_simple(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + int rc; + char query[MAX_TEST_QUERY_LENGTH]; + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_prepare_simple"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE test_prepare_simple(" + "id int, name varchar(50))"); + check_mysql_rc(rc, mysql); + + /* insert */ + strcpy(query, "INSERT INTO test_prepare_simple VALUES(?, ?)"); + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + FAIL_IF(mysql_stmt_param_count(stmt) != 2, "Paramcount is not 2"); + mysql_stmt_close(stmt); + + /* update */ + strcpy(query, "UPDATE test_prepare_simple SET id=? " + "WHERE id=? AND CONVERT(name USING utf8)= ?"); + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + FAIL_IF(mysql_stmt_param_count(stmt) != 3, "Paramcount is not 3"); + mysql_stmt_close(stmt); + + /* delete */ + strcpy(query, "DELETE FROM test_prepare_simple WHERE id=10"); + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + FAIL_IF(mysql_stmt_param_count(stmt) != 0, "Paramcount is not 0"); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + mysql_stmt_close(stmt); + + /* delete */ + strcpy(query, "DELETE FROM test_prepare_simple WHERE id=?"); + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + FAIL_IF(mysql_stmt_param_count(stmt) != 1, "Paramcount != 1"); + + mysql_stmt_close(stmt); + + /* select */ + strcpy(query, "SELECT * FROM test_prepare_simple WHERE id=? " + "AND CONVERT(name USING utf8)= ?"); + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + FAIL_IF(mysql_stmt_param_count(stmt) != 2, "Paramcount != 2"); + + mysql_stmt_close(stmt); + + /* now fetch the results ..*/ + rc= mysql_commit(mysql); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_prepare_simple"); + check_mysql_rc(rc, mysql); + + return OK; +} + +static int test_prepare_field_result(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + MYSQL_RES *result; + int rc; + char query[MAX_TEST_QUERY_LENGTH]; + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_prepare_field_result"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE test_prepare_field_result(int_c int, " + "var_c varchar(50), ts_c timestamp, " + "char_c char(4), date_c date, extra tinyint)"); + check_mysql_rc(rc, mysql); + + /* insert */ + strcpy(query, "SELECT int_c, var_c, date_c as date, ts_c, char_c FROM " + " test_prepare_field_result as t1 WHERE int_c=?"); + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + FAIL_IF(mysql_stmt_param_count(stmt) != 1, "Paramcount != 1"); + + result= mysql_stmt_result_metadata(stmt); + FAIL_IF(!result, mysql_stmt_error(stmt)); + + if (verify_prepare_field(result, 0, "int_c", "int_c", MYSQL_TYPE_LONG, + "t1", "test_prepare_field_result", schema, 11, 0)) + goto error; + if (verify_prepare_field(result, 1, "var_c", "var_c", MYSQL_TYPE_VAR_STRING, + "t1", "test_prepare_field_result", schema, 50, 0)) + goto error; + if (verify_prepare_field(result, 2, "date", "date_c", MYSQL_TYPE_DATE, + "t1", "test_prepare_field_result", schema, 10, 0)) + goto error; + if (verify_prepare_field(result, 3, "ts_c", "ts_c", MYSQL_TYPE_TIMESTAMP, + "t1", "test_prepare_field_result", schema, 19, 0)) + goto error; + if (verify_prepare_field(result, 4, "char_c", "char_c", + (mysql_get_server_version(mysql) <= 50000 ? + MYSQL_TYPE_VAR_STRING : MYSQL_TYPE_STRING), + "t1", "test_prepare_field_result", schema, 4, 0)) + goto error; + + FAIL_IF(mysql_num_fields(result) != 5, "Paramcount != 5"); + mysql_free_result(result); + mysql_stmt_close(stmt); + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_prepare_field_result"); + check_mysql_rc(rc, mysql); + + return OK; + +error: + mysql_free_result(result); + mysql_stmt_close(stmt); + return FAIL; +} + + +/* Test simple prepare field results */ + +static int test_prepare_syntax(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + int rc; + char query[MAX_TEST_QUERY_LENGTH]; + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_prepare_syntax"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE test_prepare_syntax(" + "id int, name varchar(50), extra int)"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "FLUSH TABLES"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "START TRANSACTION"); + check_mysql_rc(rc, mysql); + + strcpy(query, "INSERT INTO test_prepare_syntax VALUES(?"); + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(query)); + FAIL_IF(!rc, "error expected"); + + strcpy(query, "SELECT id, name FROM test_prepare_syntax WHERE id=? AND WHERE"); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(query)); + FAIL_IF(!rc, "error expected"); + + /* now fetch the results ..*/ + rc= mysql_commit(mysql); + check_mysql_rc(rc, mysql); + + mysql_stmt_close(stmt); + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_prepare_syntax"); + check_mysql_rc(rc, mysql); + + return OK; +} + +static int test_prepare(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + int rc, i; + int int_data, o_int_data; + char str_data[50], data[50]; + char tiny_data, o_tiny_data; + short small_data, o_small_data; + longlong big_data, o_big_data; + float real_data, o_real_data; + double double_data, o_double_data; + ulong length[7], len; + my_bool is_null[7]; + MYSQL_BIND my_bind[7]; + char query[MAX_TEST_QUERY_LENGTH]; + + rc= mysql_autocommit(mysql, TRUE); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS my_prepare"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE my_prepare(col1 tinyint, " + "col2 varchar(15), col3 int, " + "col4 smallint, col5 bigint, " + "col6 float, col7 double )"); + check_mysql_rc(rc, mysql); + + /* insert by prepare */ + strcpy(query, "INSERT INTO my_prepare VALUES(?, ?, ?, ?, ?, ?, ?)"); + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + FAIL_IF(mysql_stmt_param_count(stmt) != 7, "Paramcount != 7"); + + memset(my_bind, '\0', sizeof(my_bind)); + + /* tinyint */ + my_bind[0].buffer_type= MYSQL_TYPE_TINY; + my_bind[0].buffer= (void *)&tiny_data; + /* string */ + my_bind[1].buffer_type= MYSQL_TYPE_STRING; + my_bind[1].buffer= (void *)str_data; + my_bind[1].buffer_length= 1000; /* Max string length */ + /* integer */ + my_bind[2].buffer_type= MYSQL_TYPE_LONG; + my_bind[2].buffer= (void *)&int_data; + /* short */ + my_bind[3].buffer_type= MYSQL_TYPE_SHORT; + my_bind[3].buffer= (void *)&small_data; + /* bigint */ + my_bind[4].buffer_type= MYSQL_TYPE_LONGLONG; + my_bind[4].buffer= (void *)&big_data; + /* float */ + my_bind[5].buffer_type= MYSQL_TYPE_FLOAT; + my_bind[5].buffer= (void *)&real_data; + /* double */ + my_bind[6].buffer_type= MYSQL_TYPE_DOUBLE; + my_bind[6].buffer= (void *)&double_data; + + for (i= 0; i < (int) array_elements(my_bind); i++) + { + my_bind[i].length= &length[i]; + my_bind[i].is_null= &is_null[i]; + is_null[i]= 0; + } + + rc= mysql_stmt_bind_param(stmt, my_bind); + check_stmt_rc(rc, stmt); + + int_data= 320; + small_data= 1867; + big_data= 1000; + real_data= 2; + double_data= 6578.001; + + /* now, execute the prepared statement to insert 10 records.. */ + for (tiny_data= 0; tiny_data < 100; tiny_data++) + { + length[1]= sprintf(str_data, "MySQL%d", int_data); + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + int_data += 25; + small_data += 10; + big_data += 100; + real_data += 1; + double_data += 10.09; + } + + mysql_stmt_close(stmt); + + /* now fetch the results ..*/ + rc= mysql_commit(mysql); + check_mysql_rc(rc, mysql); + + /* test the results now, only one row should exist */ + rc= my_stmt_result(mysql, "SELECT * FROM my_prepare"); + FAIL_UNLESS(rc != 1, "rowcount != 1"); + + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, "SELECT * FROM my_prepare", 25); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_bind_result(stmt, my_bind); + check_stmt_rc(rc, stmt); + + /* get the result */ + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + o_int_data= 320; + o_small_data= 1867; + o_big_data= 1000; + o_real_data= 2; + o_double_data= 6578.001; + + /* now, execute the prepared statement to insert 10 records.. */ + for (o_tiny_data= 0; o_tiny_data < 100; o_tiny_data++) + { + len= sprintf(data, "MySQL%d", o_int_data); + + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + + FAIL_UNLESS(tiny_data == o_tiny_data, "Wrong value for tiny_data"); + FAIL_UNLESS(is_null[0] == 0, "Wrong value for is_null"); + FAIL_UNLESS(length[0] == 1, "length != 0"); + + FAIL_UNLESS(int_data == o_int_data, "Wrong value for int_data"); + FAIL_UNLESS(length[2] == 4, "length != 4"); + + FAIL_UNLESS(small_data == o_small_data, "Wrong value for small_data"); + FAIL_UNLESS(length[3] == 2, "length != 2"); + + FAIL_UNLESS(big_data == o_big_data, "Wrong value for big_data"); + FAIL_UNLESS(length[4] == 8, "length != 8"); + + FAIL_UNLESS(real_data == o_real_data, "Wrong value for real_data"); + FAIL_UNLESS(length[5] == 4, "length != 4"); + + FAIL_UNLESS(double_data == o_double_data, "Wrong value for double_data"); + FAIL_UNLESS(length[6] == 8, "length != 8"); + + FAIL_UNLESS(strcmp(data, str_data) == 0, "Wrong value for data"); + FAIL_UNLESS(length[1] == len, "length != len"); + + o_int_data += 25; + o_small_data += 10; + o_big_data += 100; + o_real_data += 1; + o_double_data += 10.09; + } + + rc= mysql_stmt_fetch(stmt); + FAIL_UNLESS(rc == MYSQL_NO_DATA, "MYSQL_NO_DATA expected"); + + mysql_stmt_close(stmt); + rc= mysql_query(mysql, "DROP TABLE IF EXISTS my_prepare"); + check_mysql_rc(rc, mysql); + + return OK; +} + +static int test_prepare_multi_statements(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + char query[MAX_TEST_QUERY_LENGTH]; + int rc; + + strcpy(query, "select 1; select 'another value'"); + + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(query)); + FAIL_IF(!rc, "Error expected"); + + mysql_stmt_close(stmt); + + return OK; +} + +static int test_prepare_ext(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + int rc; + char *sql; + int nData= 1; + char tData= 1; + short sData= 10; + longlong bData= 20; + int rowcount= 0; + MYSQL_BIND my_bind[6]; + char query[MAX_TEST_QUERY_LENGTH]; + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_prepare_ext"); + check_mysql_rc(rc, mysql); + + sql= (char *)"CREATE TABLE test_prepare_ext" + "(" + " c1 tinyint," + " c2 smallint," + " c3 mediumint," + " c4 int," + " c5 integer," + " c6 bigint," + " c7 float," + " c8 double," + " c9 double precision," + " c10 real," + " c11 decimal(7, 4)," + " c12 numeric(8, 4)," + " c13 date," + " c14 datetime," + " c15 timestamp," + " c16 time," + " c17 year," + " c18 bit," + " c19 bool," + " c20 char," + " c21 char(10)," + " c22 varchar(30)," + " c23 tinyblob," + " c24 tinytext," + " c25 blob," + " c26 text," + " c27 mediumblob," + " c28 mediumtext," + " c29 longblob," + " c30 longtext," + " c31 enum('one', 'two', 'three')," + " c32 set('monday', 'tuesday', 'wednesday'))"; + + rc= mysql_query(mysql, sql); + check_mysql_rc(rc, mysql); + + /* insert by prepare - all integers */ + strcpy(query, "INSERT INTO test_prepare_ext(c1, c2, c3, c4, c5, c6) VALUES(?, ?, ?, ?, ?, ?)"); + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + FAIL_IF(mysql_stmt_param_count(stmt) != 6, "Paramcount != 6"); + + memset(my_bind, '\0', sizeof(my_bind)); + + /*tinyint*/ + my_bind[0].buffer_type= MYSQL_TYPE_TINY; + my_bind[0].buffer= (void *)&tData; + + /*smallint*/ + my_bind[1].buffer_type= MYSQL_TYPE_SHORT; + my_bind[1].buffer= (void *)&sData; + + /*mediumint*/ + my_bind[2].buffer_type= MYSQL_TYPE_LONG; + my_bind[2].buffer= (void *)&nData; + + /*int*/ + my_bind[3].buffer_type= MYSQL_TYPE_LONG; + my_bind[3].buffer= (void *)&nData; + + /*integer*/ + my_bind[4].buffer_type= MYSQL_TYPE_LONG; + my_bind[4].buffer= (void *)&nData; + + /*bigint*/ + my_bind[5].buffer_type= MYSQL_TYPE_LONGLONG; + my_bind[5].buffer= (void *)&bData; + + rc= mysql_stmt_bind_param(stmt, my_bind); + check_stmt_rc(rc, stmt); + + /* + * integer to integer + */ + for (nData= 0; nData<10; nData++, tData++, sData++, bData++) + { + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + } + mysql_stmt_close(stmt); + + /* now fetch the results ..*/ + + strcpy(query, "SELECT c1, c2, c3, c4, c5, c6 FROM test_prepare_ext"); + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + /* get the result */ + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + while (mysql_stmt_fetch(stmt) != MYSQL_NO_DATA) + rowcount++; + + FAIL_UNLESS(nData == rowcount, "Invalid rowcount"); + + mysql_stmt_close(stmt); + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_prepare_ext"); + check_mysql_rc(rc, mysql); + + return OK; +} + +static int test_prepare_alter(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + MYSQL *mysql_new; + int rc, id; + MYSQL_BIND my_bind[1]; + my_bool is_null; + char query[MAX_TEST_QUERY_LENGTH]; + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_prep_alter"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE test_prep_alter(id int, name char(20))"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "INSERT INTO test_prep_alter values(10, 'venu'), (20, 'mysql')"); + check_mysql_rc(rc, mysql); + + strcpy(query, "INSERT INTO test_prep_alter VALUES(?, 'monty')"); + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + FAIL_IF(mysql_stmt_param_count(stmt) != 1, "Paramcount != 1"); + + memset(my_bind, '\0', sizeof(my_bind)); + + is_null= 0; + my_bind[0].buffer_type= MYSQL_TYPE_SHORT; + my_bind[0].buffer= (void *)&id; + my_bind[0].is_null= &is_null; + + rc= mysql_stmt_bind_param(stmt, my_bind); + check_stmt_rc(rc, stmt); + + id= 30; + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + mysql_new= mysql_init(NULL); + FAIL_IF(!mysql_new, "mysql_init failed"); + FAIL_IF(!(my_test_connect(mysql_new, hostname, username, password, + schema, port, socketname, 0)), "my_test_connect failed"); + rc= mysql_query(mysql_new, "ALTER TABLE test_prep_alter change id id_new varchar(20)"); + diag("Error: %d %s", mysql_errno(mysql_new), mysql_error(mysql_new)); + check_mysql_rc(rc, mysql_new); + mysql_close(mysql_new); + + is_null= 1; + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc= my_stmt_result(mysql, "SELECT * FROM test_prep_alter"); + FAIL_UNLESS(rc == 4, "rowcount != 4"); + + mysql_stmt_close(stmt); + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_prep_alter"); + check_mysql_rc(rc, mysql); + + return OK; +} + +static int test_prepare_resultset(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + int rc; + MYSQL_RES *result; + char query[MAX_TEST_QUERY_LENGTH]; + + rc= mysql_autocommit(mysql, TRUE); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_prepare_resultset"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE test_prepare_resultset(id int, \ + name varchar(50), extra double)"); + check_mysql_rc(rc, mysql); + + stmt= mysql_stmt_init(mysql); + strcpy(query, "SELECT * FROM test_prepare_resultset"); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + FAIL_IF(mysql_stmt_param_count(stmt), "Paramcount != 0"); + + result= mysql_stmt_result_metadata(stmt); + FAIL_IF(!result, "Invalid resultset"); + mysql_free_result(result); + mysql_stmt_close(stmt); + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_prepare_resultset"); + check_mysql_rc(rc, mysql); + + return OK; +} + +/* Test the direct query execution in the middle of open stmts */ + +static int test_open_direct(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + MYSQL_RES *result; + int rc; + char query[MAX_TEST_QUERY_LENGTH]; + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_open_direct"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE test_open_direct(id int, name char(6))"); + check_mysql_rc(rc, mysql); + + strcpy(query, "INSERT INTO test_open_direct values(10, 'mysql')"); + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + rc= mysql_query(mysql, "SELECT * FROM test_open_direct"); + + result= mysql_store_result(mysql); + FAIL_IF(!result, "invalid resultset"); + + FAIL_IF(mysql_num_rows(result), "rowcount != 0"); + mysql_free_result(result); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + FAIL_IF(mysql_stmt_affected_rows(stmt) != 1, "affected rows != 1"); + + rc= mysql_query(mysql, "SELECT * FROM test_open_direct"); + check_mysql_rc(rc, mysql); + + result= mysql_store_result(mysql); + FAIL_IF(!result, "invalid resultset"); + + FAIL_IF(mysql_num_rows(result) != 1, "rowcount != 1"); + mysql_free_result(result); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + FAIL_IF(mysql_stmt_affected_rows(stmt) != 1, "affected rows != 1"); + + rc= mysql_query(mysql, "SELECT * FROM test_open_direct"); + check_mysql_rc(rc, mysql); + + result= mysql_store_result(mysql); + FAIL_IF(!result, "Invalid resultset"); + FAIL_IF(mysql_num_rows(result) != 2, "rowcount != 2"); + + mysql_free_result(result); + + mysql_stmt_close(stmt); + + /* run a direct query in the middle of a fetch */ + + strcpy(query, "SELECT * FROM test_open_direct"); + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_query(mysql, "INSERT INTO test_open_direct(id) VALUES(20)"); + FAIL_IF(!rc, "Error expected"); + + rc= mysql_stmt_close(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_query(mysql, "INSERT INTO test_open_direct(id) VALUES(20)"); + check_mysql_rc(rc, mysql); + + /* run a direct query with store result */ + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_store_result(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_query(mysql, "drop table test_open_direct"); + check_mysql_rc(rc, mysql); + + rc= mysql_stmt_close(stmt); + check_stmt_rc(rc, stmt); + + return OK; +} + +static int test_select_show(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + int rc; + char query[MAX_TEST_QUERY_LENGTH]; + int rowcount; + + rc= mysql_autocommit(mysql, TRUE); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_show"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE test_show(id int(4) NOT NULL primary " + " key, name char(2))"); + check_mysql_rc(rc, mysql); + + strcpy(query, "show columns from test_show"); + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + FAIL_IF(mysql_stmt_param_count(stmt) != 0, "Paramcount != 0"); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rowcount= 0; + while (mysql_stmt_fetch(stmt) != MYSQL_NO_DATA) + rowcount++; + FAIL_IF(rowcount != 2, "rowcount != 2"); + + mysql_stmt_close(stmt); + + strcpy(query, "show tables from mysql like ?"); + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(query)); + FAIL_IF(!rc, "Error expected"); + + strcpy(query, "show tables like \'test_show\'"); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rowcount= 0; + while (mysql_stmt_fetch(stmt) != MYSQL_NO_DATA) + rowcount++; + FAIL_IF(rowcount != 1, "rowcount != 1"); + mysql_stmt_close(stmt); + + strcpy(query, "describe test_show"); + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rowcount= 0; + while (mysql_stmt_fetch(stmt) != MYSQL_NO_DATA) + rowcount++; + FAIL_IF(rowcount != 2, "rowcount != 2"); + mysql_stmt_close(stmt); + + strcpy(query, "show keys from test_show"); + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rowcount= 0; + while (mysql_stmt_fetch(stmt) != MYSQL_NO_DATA) + rowcount++; + FAIL_IF(rowcount != 1, "rowcount != 1"); + + mysql_stmt_close(stmt); + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_show"); + check_mysql_rc(rc, mysql); + + return OK; +} + +static int test_simple_update(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + int rc; + char szData[25]; + int nData= 1; + MYSQL_RES *result; + MYSQL_BIND my_bind[2]; + ulong length[2]; + int rowcount= 0; + char query[MAX_TEST_QUERY_LENGTH]; + + rc= mysql_autocommit(mysql, TRUE); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_update"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE test_update(col1 int, " + " col2 varchar(50), col3 int )"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "INSERT INTO test_update VALUES(1, 'MySQL', 100)"); + check_mysql_rc(rc, mysql); + + FAIL_IF(mysql_affected_rows(mysql) != 1, "Affected rows != 1"); + + rc= mysql_commit(mysql); + check_mysql_rc(rc, mysql); + + /* insert by prepare */ + strcpy(query, "UPDATE test_update SET col2= ? WHERE col1= ?"); + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + FAIL_IF(mysql_stmt_param_count(stmt) != 2, "Paramcount != 2"); + + memset(my_bind, '\0', sizeof(my_bind)); + + nData= 1; + my_bind[0].buffer_type= MYSQL_TYPE_STRING; + my_bind[0].buffer= szData; /* string data */ + my_bind[0].buffer_length= sizeof(szData); + my_bind[0].length= &length[0]; + length[0]= sprintf(szData, "updated-data"); + + my_bind[1].buffer= (void *) &nData; + my_bind[1].buffer_type= MYSQL_TYPE_LONG; + + rc= mysql_stmt_bind_param(stmt, my_bind); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + FAIL_IF(mysql_stmt_affected_rows(stmt) != 1, "Affected_rows != 1"); + + mysql_stmt_close(stmt); + + /* now fetch the results ..*/ + rc= mysql_commit(mysql); + check_mysql_rc(rc, mysql); + + /* test the results now, only one row should exist */ + rc= mysql_query(mysql, "SELECT * FROM test_update"); + check_mysql_rc(rc, mysql); + + /* get the result */ + result= mysql_store_result(mysql); + FAIL_IF(!result, "Invalid resultset"); + + while (mysql_fetch_row(result)) + rowcount++; + + FAIL_IF(rowcount != 1, "rowcount != 1"); + + mysql_free_result(result); + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_update"); + check_mysql_rc(rc, mysql); + + return OK; +} + + +/* Test simple long data handling */ + +static int test_long_data(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + int rc, int_data; + char *data= NullS; + MYSQL_RES *result; + MYSQL_BIND my_bind[3]; + int rowcount; + char query[MAX_TEST_QUERY_LENGTH]; + + rc= mysql_autocommit(mysql, TRUE); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_long_data"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE test_long_data(col1 int, " + " col2 long varchar, col3 long varbinary)"); + check_mysql_rc(rc, mysql); + + strcpy(query, "INSERT INTO test_long_data(col1, col2) VALUES(?)"); + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(query)); + FAIL_IF(!rc, "Error expected"); + rc= mysql_stmt_close(stmt); + check_stmt_rc(rc, stmt); + + strcpy(query, "INSERT INTO test_long_data(col1, col2, col3) VALUES(?, ?, ?)"); + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + FAIL_IF(mysql_stmt_param_count(stmt) != 3, "Paramcount != 3"); + + memset(my_bind, '\0', sizeof(my_bind)); + + my_bind[0].buffer= (void *)&int_data; + my_bind[0].buffer_type= MYSQL_TYPE_LONG; + + my_bind[1].buffer_type= MYSQL_TYPE_STRING; + + my_bind[2]= my_bind[1]; + rc= mysql_stmt_bind_param(stmt, my_bind); + check_stmt_rc(rc, stmt); + + int_data= 999; + data= (char *)"Michael"; + + /* supply data in pieces */ + rc= mysql_stmt_send_long_data(stmt, 1, SL(data)); + check_stmt_rc(rc, stmt); + data= (char *)" 'Monty' Widenius"; + rc= mysql_stmt_send_long_data(stmt, 1, SL(data)); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_send_long_data(stmt, 2, "Venu (venu@mysql.com)", 4); + check_stmt_rc(rc, stmt); + + /* execute */ + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_commit(mysql); + check_mysql_rc(rc, mysql); + + /* now fetch the results ..*/ + rc= mysql_query(mysql, "SELECT * FROM test_long_data"); + check_mysql_rc(rc, mysql); + + /* get the result */ + result= mysql_store_result(mysql); + FAIL_IF(!result, "Invalid result set"); + + rowcount= 0; + while (mysql_fetch_row(result)) + rowcount++; + FAIL_IF(rowcount != 1, "rowcount != 1"); + mysql_free_result(result); + + if (verify_col_data(mysql, "test_long_data", "col1", "999")) + goto error; + if (verify_col_data(mysql, "test_long_data", "col2", "Michael 'Monty' Widenius")) + goto error; + if (verify_col_data(mysql, "test_long_data", "col3", "Venu")) + goto error; + + mysql_stmt_close(stmt); + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_long_data"); + check_mysql_rc(rc, mysql); + return OK; + +error: + mysql_stmt_close(stmt); + return FAIL; +} + + +/* Test long data (string) handling */ + +static int test_long_data_str(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + int rc, i, rowcount= 0; + char data[255]; + long length; + ulong length1; + MYSQL_RES *result; + MYSQL_BIND my_bind[2]; + my_bool is_null[2]; + char query[MAX_TEST_QUERY_LENGTH]; + + rc= mysql_autocommit(mysql, TRUE); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_long_data_str"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE test_long_data_str(id int, longstr long varchar)"); + check_mysql_rc(rc, mysql); + + strcpy(query, "INSERT INTO test_long_data_str VALUES(?, ?)"); + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + FAIL_IF(mysql_stmt_param_count(stmt) != 2, "Paramcount != 2"); + + memset(my_bind, '\0', sizeof(my_bind)); + + my_bind[0].buffer= (void *)&length; + my_bind[0].buffer_type= MYSQL_TYPE_LONG; + my_bind[0].is_null= &is_null[0]; + is_null[0]= 0; + length= 0; + + my_bind[1].buffer= data; /* string data */ + my_bind[1].buffer_type= MYSQL_TYPE_STRING; + my_bind[1].length= &length1; + my_bind[1].is_null= &is_null[1]; + is_null[1]= 0; + rc= mysql_stmt_bind_param(stmt, my_bind); + check_stmt_rc(rc, stmt); + + length= 40; + strcpy(data, "MySQL AB"); + + /* supply data in pieces */ + for(i= 0; i < 4; i++) + { + rc= mysql_stmt_send_long_data(stmt, 1, (char *)data, 5); + check_stmt_rc(rc, stmt); + } + /* execute */ + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + mysql_stmt_close(stmt); + + rc= mysql_commit(mysql); + check_mysql_rc(rc, mysql); + + /* now fetch the results ..*/ + rc= mysql_query(mysql, "SELECT LENGTH(longstr), longstr FROM test_long_data_str"); + check_mysql_rc(rc, mysql); + + /* get the result */ + result= mysql_store_result(mysql); + FAIL_IF(!result, "Invalid result set"); + + while (mysql_fetch_row(result)) + rowcount++; + FAIL_IF(rowcount != 1, "rowcount != 1"); + + mysql_free_result(result); + + sprintf(data, "%d", i*5); + if (verify_col_data(mysql, "test_long_data_str", "LENGTH(longstr)", data)) + goto error; + strcpy(data, "MySQLMySQLMySQLMySQL"); + if (verify_col_data(mysql, "test_long_data_str", "longstr", data)) + goto error; + + rc= mysql_query(mysql, "DROP TABLE test_long_data_str"); + check_mysql_rc(rc, mysql); + + return OK; + +error: + rc= mysql_query(mysql, "DROP TABLE test_long_data_str"); + check_mysql_rc(rc, mysql); + return FAIL; +} + + +/* Test long data (string) handling */ + +static int test_long_data_str1(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + int rc, i, rowcount= 0; + char data[255]; + long length; + unsigned long max_blob_length, blob_length, length1; + my_bool true_value; + MYSQL_RES *result; + MYSQL_BIND my_bind[2]; + MYSQL_FIELD *field; + char query[MAX_TEST_QUERY_LENGTH]; + + rc= mysql_autocommit(mysql, TRUE); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_long_data_str"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE test_long_data_str(longstr long varchar, blb long varbinary)"); + check_mysql_rc(rc, mysql); + + strcpy(query, "INSERT INTO test_long_data_str VALUES(?, ?)"); + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + FAIL_IF(mysql_stmt_param_count(stmt) != 2, "Paramcount != 2"); + + memset(my_bind, '\0', sizeof(my_bind)); + + my_bind[0].buffer= data; /* string data */ + my_bind[0].buffer_length= sizeof(data); + my_bind[0].length= (unsigned long *)&length1; + my_bind[0].buffer_type= MYSQL_TYPE_STRING; + length1= 0; + + my_bind[1]= my_bind[0]; + my_bind[1].buffer_type= MYSQL_TYPE_BLOB; + + rc= mysql_stmt_bind_param(stmt, my_bind); + check_stmt_rc(rc, stmt); + length= sprintf(data, "MySQL AB"); + + /* supply data in pieces */ + for (i= 0; i < 3; i++) + { + rc= mysql_stmt_send_long_data(stmt, 0, data, length); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_send_long_data(stmt, 1, data, 2); + check_stmt_rc(rc, stmt); + } + + /* execute */ + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + mysql_stmt_close(stmt); + + rc= mysql_commit(mysql); + check_mysql_rc(rc, mysql); + + /* now fetch the results ..*/ + rc= mysql_query(mysql, "SELECT LENGTH(longstr), longstr, LENGTH(blb), blb FROM test_long_data_str"); + check_mysql_rc(rc, mysql); + + /* get the result */ + result= mysql_store_result(mysql); + + mysql_field_seek(result, 1); + field= mysql_fetch_field(result); + max_blob_length= field->max_length; + + FAIL_IF(!result, "Invalid result set"); + + while (mysql_fetch_row(result)) + rowcount++; + + FAIL_IF(rowcount != 1, "rowcount != 1"); + mysql_free_result(result); + + sprintf(data, "%ld", (long)i*length); + if (verify_col_data(mysql, "test_long_data_str", "length(longstr)", data)) + return FAIL; + + sprintf(data, "%d", i*2); + if (verify_col_data(mysql, "test_long_data_str", "length(blb)", data)) + return FAIL; + + /* Test length of field->max_length */ + strcpy(query, "SELECT * from test_long_data_str"); + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + FAIL_IF(mysql_stmt_param_count(stmt) != 0, "Paramcount != 0"); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_store_result(stmt); + check_stmt_rc(rc, stmt); + + result= mysql_stmt_result_metadata(stmt); + field= mysql_fetch_fields(result); + + /* First test what happens if STMT_ATTR_UPDATE_MAX_LENGTH is not used */ + FAIL_IF(field->max_length != 0, "field->max_length != 0"); + mysql_free_result(result); + + /* Enable updating of field->max_length */ + true_value= 1; + mysql_stmt_attr_set(stmt, STMT_ATTR_UPDATE_MAX_LENGTH, (void*) &true_value); + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_store_result(stmt); + check_stmt_rc(rc, stmt); + + result= mysql_stmt_result_metadata(stmt); + field= mysql_fetch_fields(result); + + diag("max_length: %lu max_blob_length: %lu", (unsigned long)field->max_length, (unsigned long)max_blob_length); + FAIL_UNLESS(field->max_length == max_blob_length, "field->max_length != max_blob_length"); + + /* Fetch results into a data buffer that is smaller than data */ + memset(my_bind, '\0', sizeof(*my_bind)); + my_bind[0].buffer_type= MYSQL_TYPE_BLOB; + my_bind[0].buffer= (void *) &data; /* this buffer won't be altered */ + my_bind[0].buffer_length= 16; + my_bind[0].length= (unsigned long *)&blob_length; + my_bind[0].error= &my_bind[0].error_value; + rc= mysql_stmt_bind_result(stmt, my_bind); + data[16]= 0; + + rc= mysql_stmt_fetch(stmt); + FAIL_UNLESS(rc == MYSQL_DATA_TRUNCATED, "truncation expected"); + FAIL_UNLESS(my_bind[0].error_value, "No error value"); + FAIL_UNLESS(strlen(data) == 16, "Invalid string length"); + FAIL_UNLESS(blob_length == max_blob_length, "blob_length != max_blob_length"); + + /* Fetch all data */ + memset((my_bind+1), '\0', sizeof(*my_bind)); + my_bind[1].buffer_type= MYSQL_TYPE_BLOB; + my_bind[1].buffer= (void *) &data; /* this buffer won't be altered */ + my_bind[1].buffer_length= sizeof(data); + my_bind[1].length= (unsigned long *)&blob_length; + memset(data, '\0', sizeof(data)); + mysql_stmt_fetch_column(stmt, my_bind+1, 0, 0); + FAIL_UNLESS(strlen(data) == max_blob_length, "strlen(data) != max_blob_length"); + + mysql_free_result(result); + mysql_stmt_close(stmt); + + /* Drop created table */ + rc= mysql_query(mysql, "DROP TABLE test_long_data_str"); + check_mysql_rc(rc, mysql); + + return OK; +} + + +/* Test long data (binary) handling */ + +static int test_long_data_bin(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + int rc, rowcount= 0; + char data[255]; + long length; + MYSQL_RES *result; + MYSQL_BIND my_bind[2]; + char query[MAX_TEST_QUERY_LENGTH]; + + + rc= mysql_autocommit(mysql, TRUE); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_long_data_bin"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE test_long_data_bin(id int, longbin long varbinary)"); + check_mysql_rc(rc, mysql); + + strcpy(query, "INSERT INTO test_long_data_bin VALUES(?, ?)"); + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + FAIL_IF(mysql_stmt_param_count(stmt) != 2, "Paramcount != 2"); + + memset(my_bind, '\0', sizeof(my_bind)); + + my_bind[0].buffer= (void *)&length; + my_bind[0].buffer_type= MYSQL_TYPE_LONG; + length= 0; + + my_bind[1].buffer= data; /* string data */ + my_bind[1].buffer_type= MYSQL_TYPE_LONG_BLOB; + rc= mysql_stmt_bind_param(stmt, my_bind); + check_stmt_rc(rc, stmt); + + length= 10; + strcpy(data, "MySQL AB"); + + /* supply data in pieces */ + { + int i; + for (i= 0; i < 100; i++) + { + rc= mysql_stmt_send_long_data(stmt, 1, (char *)data, 4); + check_stmt_rc(rc, stmt); + } + } + /* execute */ + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + mysql_stmt_close(stmt); + + rc= mysql_commit(mysql); + check_mysql_rc(rc, mysql); + + /* now fetch the results ..*/ + rc= mysql_query(mysql, "SELECT LENGTH(longbin), longbin FROM test_long_data_bin"); + check_mysql_rc(rc, mysql); + + /* get the result */ + result= mysql_store_result(mysql); + FAIL_IF(!result, "Invalid result set"); + + while (mysql_fetch_row(result)) + rowcount++; + + FAIL_IF(rowcount != 1, "rowcount != 1"); + mysql_free_result(result); + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_long_data_bin"); + check_mysql_rc(rc, mysql); + return OK; +} + + +/* Test simple delete */ + +static int test_simple_delete(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + int rc, rowcount= 0; + char szData[30]= {0}; + int nData= 1; + MYSQL_RES *result; + MYSQL_BIND my_bind[2]; + ulong length[2]; + char query[MAX_TEST_QUERY_LENGTH]; + + rc= mysql_autocommit(mysql, TRUE); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_simple_delete"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE test_simple_delete(col1 int, \ + col2 varchar(50), col3 int )"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "INSERT INTO test_simple_delete VALUES(1, 'MySQL', 100)"); + check_mysql_rc(rc, mysql); + + FAIL_IF(mysql_affected_rows(mysql) != 1, "Affected rows != 1"); + + rc= mysql_commit(mysql); + check_mysql_rc(rc, mysql); + + /* insert by prepare */ + strcpy(query, "DELETE FROM test_simple_delete WHERE col1= ? AND " + "CONVERT(col2 USING utf8)= ? AND col3= 100"); + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + FAIL_IF(mysql_stmt_param_count(stmt) != 2, "Paramcount != 2"); + + memset(my_bind, '\0', sizeof(my_bind)); + + nData= 1; + strcpy(szData, "MySQL"); + my_bind[1].buffer_type= MYSQL_TYPE_STRING; + my_bind[1].buffer= szData; /* string data */ + my_bind[1].buffer_length= sizeof(szData); + my_bind[1].length= &length[1]; + length[1]= 5; + + my_bind[0].buffer= (void *)&nData; + my_bind[0].buffer_type= MYSQL_TYPE_LONG; + + rc= mysql_stmt_bind_param(stmt, my_bind); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + FAIL_IF(mysql_stmt_affected_rows(stmt) != 1, "Affected rows != 1"); + + mysql_stmt_close(stmt); + + /* now fetch the results ..*/ + rc= mysql_commit(mysql); + check_mysql_rc(rc, mysql); + + /* test the results now, only one row should exist */ + rc= mysql_query(mysql, "SELECT * FROM test_simple_delete"); + check_mysql_rc(rc, mysql); + + /* get the result */ + result= mysql_store_result(mysql); + FAIL_IF(!result, "Invalid result set"); + + while (mysql_fetch_row(result)) + rowcount++; + + FAIL_IF(rowcount, "rowcount > 0"); + mysql_free_result(result); + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_simple_delete"); + check_mysql_rc(rc, mysql); + + return OK; +} + +static int test_update(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + int rc; + char szData[25]; + int nData= 1, rowcount= 0; + MYSQL_RES *result; + MYSQL_BIND my_bind[2]; + ulong length[2]; + char query[MAX_TEST_QUERY_LENGTH]; + + rc= mysql_autocommit(mysql, TRUE); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_update"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE test_update(" + "col1 int primary key auto_increment, " + "col2 varchar(50), col3 int )"); + check_mysql_rc(rc, mysql); + + strcpy(query, "INSERT INTO test_update(col2, col3) VALUES(?, ?)"); + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + FAIL_IF(mysql_stmt_param_count(stmt) != 2, "Paramcount != 2"); + + memset(my_bind, '\0', sizeof(my_bind)); + + /* string data */ + my_bind[0].buffer_type= MYSQL_TYPE_STRING; + my_bind[0].buffer= szData; + my_bind[0].buffer_length= sizeof(szData); + my_bind[0].length= &length[0]; + length[0]= sprintf(szData, "inserted-data"); + + my_bind[1].buffer= (void *)&nData; + my_bind[1].buffer_type= MYSQL_TYPE_LONG; + + rc= mysql_stmt_bind_param(stmt, my_bind); + check_stmt_rc(rc, stmt); + + nData= 100; + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + FAIL_IF(mysql_stmt_affected_rows(stmt) != 1, "Affected rows != 1"); + mysql_stmt_close(stmt); + + strcpy(query, "UPDATE test_update SET col2= ? WHERE col3= ?"); + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + FAIL_IF(mysql_stmt_param_count(stmt) != 2, "Paramcount != 2"); + nData= 100; + + memset(my_bind, '\0', sizeof(my_bind)); + + my_bind[0].buffer_type= MYSQL_TYPE_STRING; + my_bind[0].buffer= szData; + my_bind[0].buffer_length= sizeof(szData); + my_bind[0].length= &length[0]; + length[0]= sprintf(szData, "updated-data"); + + my_bind[1].buffer= (void *)&nData; + my_bind[1].buffer_type= MYSQL_TYPE_LONG; + + rc= mysql_stmt_bind_param(stmt, my_bind); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + FAIL_IF(mysql_stmt_affected_rows(stmt) != 1, "Affected rows != 1"); + + + mysql_stmt_close(stmt); + + /* now fetch the results ..*/ + rc= mysql_commit(mysql); + check_mysql_rc(rc, mysql); + + /* test the results now, only one row should exist */ + rc= mysql_query(mysql, "SELECT * FROM test_update"); + check_mysql_rc(rc, mysql); + + /* get the result */ + result= mysql_store_result(mysql); + FAIL_IF(!result, "Invalid result set"); + + while (mysql_fetch_row(result)) + rowcount++; + FAIL_IF(rowcount != 1, "rowcount != 1"); + mysql_free_result(result); + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_update"); + check_mysql_rc(rc, mysql); + + return OK; +} + + +/* Test prepare without parameters */ + +static int test_prepare_noparam(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + int rc, rowcount= 0; + MYSQL_RES *result; + char query[MAX_TEST_QUERY_LENGTH]; + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS my_prepare"); + check_mysql_rc(rc, mysql); + + + rc= mysql_query(mysql, "CREATE TABLE my_prepare(col1 int, col2 varchar(50))"); + check_mysql_rc(rc, mysql); + + /* insert by prepare */ + strcpy(query, "INSERT INTO my_prepare VALUES(10, 'venu')"); + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + FAIL_IF(mysql_stmt_param_count(stmt) != 0, "Paramcount != 0"); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + mysql_stmt_close(stmt); + + /* now fetch the results ..*/ + rc= mysql_commit(mysql); + check_mysql_rc(rc, mysql); + + /* test the results now, only one row should exist */ + rc= mysql_query(mysql, "SELECT * FROM my_prepare"); + check_mysql_rc(rc, mysql); + + /* get the result */ + result= mysql_store_result(mysql); + FAIL_IF(!result, "Invalid result set"); + + while (mysql_fetch_row(result)) + rowcount++; + + FAIL_IF(rowcount != 1, "rowcount != 1"); + mysql_free_result(result); + rc= mysql_query(mysql, "DROP TABLE IF EXISTS my_prepare"); + check_mysql_rc(rc, mysql); + + return OK; +} + + +/* Test simple bind result */ + +static int test_bind_result(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + int rc; + int nData; + ulong length1; + char szData[100]; + MYSQL_BIND my_bind[2]; + my_bool is_null[2]; + char query[MAX_TEST_QUERY_LENGTH]; + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_bind_result"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE test_bind_result(col1 int , col2 varchar(50))"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "INSERT INTO test_bind_result VALUES(10, 'venu')"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "INSERT INTO test_bind_result VALUES(20, 'MySQL')"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "INSERT INTO test_bind_result(col2) VALUES('monty')"); + check_mysql_rc(rc, mysql); + + rc= mysql_commit(mysql); + check_mysql_rc(rc, mysql); + + /* fetch */ + + memset(my_bind, '\0', sizeof(my_bind)); + my_bind[0].buffer_type= MYSQL_TYPE_LONG; + my_bind[0].buffer= (void *) &nData; /* integer data */ + my_bind[0].is_null= &is_null[0]; + + my_bind[1].buffer_type= MYSQL_TYPE_STRING; + my_bind[1].buffer= szData; /* string data */ + my_bind[1].buffer_length= sizeof(szData); + my_bind[1].length= &length1; + my_bind[1].is_null= &is_null[1]; + + strcpy(query, "SELECT * FROM test_bind_result"); + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_bind_result(stmt, my_bind); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + + FAIL_UNLESS(nData == 10, "nData != 10"); + FAIL_UNLESS(strcmp(szData, "venu") == 0, "szData != 'Venu'"); + FAIL_UNLESS(length1 == 4, "length1 != 4"); + + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + + FAIL_UNLESS(nData == 20, "nData != 20"); + FAIL_UNLESS(strcmp(szData, "MySQL") == 0, "szData != 'MySQL'"); + FAIL_UNLESS(length1 == 5, "length1 != 5"); + + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + + FAIL_UNLESS(is_null[0], "null flag not set"); + FAIL_UNLESS(strcmp(szData, "monty") == 0, "szData != 'Monty'"); + FAIL_UNLESS(length1 == 5, "length1 != 5"); + + rc= mysql_stmt_fetch(stmt); + FAIL_UNLESS(rc == MYSQL_NO_DATA, "MYSQL_NO_DATA expected"); + + mysql_stmt_close(stmt); + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_bind_result"); + check_mysql_rc(rc, mysql); + + return OK; +} + +static int test_bind_result_ext(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + int rc, i; + uchar t_data; + short s_data; + int i_data; + longlong b_data; + float f_data; + double d_data; + char szData[20], bData[20]; + ulong szLength, bLength; + MYSQL_BIND my_bind[8]; + ulong length[8]; + my_bool is_null[8]; + char query[MAX_TEST_QUERY_LENGTH]; + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_bind_result"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE test_bind_result(c1 tinyint, " + " c2 smallint, " + " c3 int, c4 bigint, " + " c5 float, c6 double, " + " c7 varbinary(10), " + " c8 varchar(50))"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "INSERT INTO test_bind_result " + "VALUES (19, 2999, 3999, 4999999, " + " 2345.6, 5678.89563, 'venu', 'mysql')"); + check_mysql_rc(rc, mysql); + + rc= mysql_commit(mysql); + check_mysql_rc(rc, mysql); + + memset(my_bind, '\0', sizeof(my_bind)); + for (i= 0; i < (int) array_elements(my_bind); i++) + { + my_bind[i].length= &length[i]; + my_bind[i].is_null= &is_null[i]; + } + + my_bind[0].buffer_type= MYSQL_TYPE_TINY; + my_bind[0].buffer= (void *)&t_data; + + my_bind[1].buffer_type= MYSQL_TYPE_SHORT; + my_bind[2].buffer_type= MYSQL_TYPE_LONG; + + my_bind[3].buffer_type= MYSQL_TYPE_LONGLONG; + my_bind[1].buffer= (void *)&s_data; + + my_bind[2].buffer= (void *)&i_data; + my_bind[3].buffer= (void *)&b_data; + + my_bind[4].buffer_type= MYSQL_TYPE_FLOAT; + my_bind[4].buffer= (void *)&f_data; + + my_bind[5].buffer_type= MYSQL_TYPE_DOUBLE; + my_bind[5].buffer= (void *)&d_data; + + my_bind[6].buffer_type= MYSQL_TYPE_STRING; + my_bind[6].buffer= (void *)szData; + my_bind[6].buffer_length= sizeof(szData); + my_bind[6].length= &szLength; + + my_bind[7].buffer_type= MYSQL_TYPE_TINY_BLOB; + my_bind[7].buffer= (void *)&bData; + my_bind[7].length= &bLength; + my_bind[7].buffer_length= sizeof(bData); + + strcpy(query, "select * from test_bind_result"); + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_bind_result(stmt, my_bind); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + + FAIL_UNLESS(t_data == 19, "tdata != 19"); + FAIL_UNLESS(s_data == 2999, "s_data != 2999"); + FAIL_UNLESS(i_data == 3999, "i_data != 3999"); + FAIL_UNLESS(b_data == 4999999, "b_data != 4999999"); + FAIL_UNLESS(strcmp(szData, "venu") == 0, "szData != 'Venu'"); + FAIL_UNLESS(strncmp(bData, "mysql", 5) == 0, "nData != 'mysql'"); + FAIL_UNLESS(szLength == 4, "szLength != 4"); + FAIL_UNLESS(bLength == 5, "bLength != 5"); + + rc= mysql_stmt_fetch(stmt); + FAIL_UNLESS(rc == MYSQL_NO_DATA, "MYSQL_NO_DATA expected"); + + mysql_stmt_close(stmt); + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_bind_result"); + check_mysql_rc(rc, mysql); + return OK; +} + + +/* Test ext bind result */ + +static int test_bind_result_ext1(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + uint i; + int rc; + char t_data[20]; + float s_data; + short i_data; + uchar b_data; + int f_data; + long bData; + char d_data[20]; + double szData; + MYSQL_BIND my_bind[8]; + ulong length[8]; + my_bool is_null[8]; + char query[MAX_TEST_QUERY_LENGTH]; + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_bind_result"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE test_bind_result(c1 tinyint, c2 smallint, \ + c3 int, c4 bigint, \ + c5 float, c6 double, \ + c7 varbinary(10), \ + c8 varchar(10))"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "INSERT INTO test_bind_result VALUES(120, 2999, 3999, 54, \ + 2.6, 58.89, \ + '206', '6.7')"); + check_mysql_rc(rc, mysql); + + rc= mysql_commit(mysql); + check_mysql_rc(rc, mysql); + + memset(my_bind, '\0', sizeof(my_bind)); + my_bind[0].buffer_type= MYSQL_TYPE_STRING; + my_bind[0].buffer= (void *) t_data; + my_bind[0].buffer_length= sizeof(t_data); + my_bind[0].error= &my_bind[0].error_value; + + my_bind[1].buffer_type= MYSQL_TYPE_FLOAT; + my_bind[1].buffer= (void *)&s_data; + my_bind[1].buffer_length= 0; + my_bind[1].error= &my_bind[1].error_value; + + my_bind[2].buffer_type= MYSQL_TYPE_SHORT; + my_bind[2].buffer= (void *)&i_data; + my_bind[2].buffer_length= 0; + my_bind[2].error= &my_bind[2].error_value; + + my_bind[3].buffer_type= MYSQL_TYPE_TINY; + my_bind[3].buffer= (void *)&b_data; + my_bind[3].buffer_length= 0; + my_bind[3].error= &my_bind[3].error_value; + + my_bind[4].buffer_type= MYSQL_TYPE_LONG; + my_bind[4].buffer= (void *)&f_data; + my_bind[4].buffer_length= 0; + my_bind[4].error= &my_bind[4].error_value; + + my_bind[5].buffer_type= MYSQL_TYPE_STRING; + my_bind[5].buffer= (void *)d_data; + my_bind[5].buffer_length= sizeof(d_data); + my_bind[5].error= &my_bind[5].error_value; + + my_bind[6].buffer_type= MYSQL_TYPE_LONG; + my_bind[6].buffer= (void *)&bData; + my_bind[6].buffer_length= 0; + my_bind[6].error= &my_bind[6].error_value; + + my_bind[7].buffer_type= MYSQL_TYPE_DOUBLE; + my_bind[7].buffer= (void *)&szData; + my_bind[7].buffer_length= 0; + my_bind[7].error= &my_bind[7].error_value; + + for (i= 0; i < array_elements(my_bind); i++) + { + my_bind[i].is_null= &is_null[i]; + my_bind[i].length= &length[i]; + } + + strcpy(query, "select * from test_bind_result"); + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_bind_result(stmt, my_bind); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + + FAIL_UNLESS(strcmp(t_data, "120") == 0, "t_data != 120"); + FAIL_UNLESS(i_data == 3999, "i_data != 3999"); + FAIL_UNLESS(f_data == 2, "f_data != 2"); + FAIL_UNLESS(strcmp(d_data, "58.89") == 0, "d_data != 58.89"); + FAIL_UNLESS(b_data == 54, "b_data != 54"); + + FAIL_UNLESS(length[0] == 3, "Wrong length"); + FAIL_UNLESS(length[1] == 4, "Wrong length"); + FAIL_UNLESS(length[2] == 2, "Wrong length"); + FAIL_UNLESS(length[3] == 1, "Wrong length"); + FAIL_UNLESS(length[4] == 4, "Wrong length"); + FAIL_UNLESS(length[5] == 5, "Wrong length"); + FAIL_UNLESS(length[6] == 4, "Wrong length"); + FAIL_UNLESS(length[7] == 8, "Wrong length"); + + rc= mysql_stmt_fetch(stmt); + FAIL_UNLESS(rc == MYSQL_NO_DATA, "MYSQL_NO_DATA expected"); + + mysql_stmt_close(stmt); + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_bind_result"); + check_mysql_rc(rc, mysql); + return OK; +} + +static int test_bind_negative(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + char *query; + int rc; + MYSQL_BIND my_bind[1]; + int32 my_val= 0; + ulong my_length= 0L; + my_bool my_null= FALSE; + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "create temporary table t1 (c1 int)"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "INSERT INTO t1 VALUES (1), (-1)"); + check_mysql_rc(rc, mysql); + + query= (char*)"INSERT INTO t1 VALUES (?)"; + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + /* bind parameters */ + memset(my_bind, '\0', sizeof(my_bind)); + + my_bind[0].buffer_type= MYSQL_TYPE_LONG; + my_bind[0].buffer= (void *)&my_val; + my_bind[0].length= &my_length; + my_bind[0].is_null= &my_null; + + rc= mysql_stmt_bind_param(stmt, my_bind); + check_stmt_rc(rc, stmt); + + my_val= -1; + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + mysql_stmt_close(stmt); + rc= mysql_query(mysql, "drop table t1"); + check_mysql_rc(rc, mysql); + + return OK; +} + +static int test_buffers(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + MYSQL_BIND my_bind[1]; + int rc; + ulong length; + my_bool is_null; + char buffer[20]; + char query[MAX_TEST_QUERY_LENGTH]; + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_buffer"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE test_buffer(str varchar(20))"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "insert into test_buffer values('MySQL')\ + , ('Database'), ('Open-Source'), ('Popular')"); + check_mysql_rc(rc, mysql); + + strcpy(query, "select str from test_buffer"); + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + memset(buffer, '\0', sizeof(buffer)); /* Avoid overruns in printf() */ + + memset(my_bind, '\0', sizeof(my_bind)); + my_bind[0].length= &length; + my_bind[0].is_null= &is_null; + my_bind[0].buffer_length= 1; + my_bind[0].buffer_type= MYSQL_TYPE_STRING; + my_bind[0].buffer= (void *)buffer; + my_bind[0].error= &my_bind[0].error_value; + + rc= mysql_stmt_bind_result(stmt, my_bind); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_store_result(stmt); + check_stmt_rc(rc, stmt); + + buffer[1]= 'X'; + rc= mysql_stmt_fetch(stmt); + + FAIL_UNLESS(rc == MYSQL_DATA_TRUNCATED, "rc != MYSQL_DATA_TRUNCATED"); + FAIL_UNLESS(my_bind[0].error_value, "Errorflag not set"); + FAIL_UNLESS(buffer[0] == 'M', "buffer[0] != M"); + FAIL_UNLESS(buffer[1] == 'X', "buffer[1] != X"); + FAIL_UNLESS(length == 5, "length != 5"); + + my_bind[0].buffer_length= 8; + rc= mysql_stmt_bind_result(stmt, my_bind);/* re-bind */ + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + FAIL_UNLESS(strncmp(buffer, "Database", 8) == 0, "buffer != 'Database'"); + FAIL_UNLESS(length == 8, "length != 8"); + + my_bind[0].buffer_length= 12; + rc= mysql_stmt_bind_result(stmt, my_bind);/* re-bind */ + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + FAIL_UNLESS(strcmp(buffer, "Open-Source") == 0, "buffer != 'Open-Source'"); + FAIL_UNLESS(length == 11, "Length != 11"); + + my_bind[0].buffer_length= 6; + rc= mysql_stmt_bind_result(stmt, my_bind);/* re-bind */ + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_fetch(stmt); + FAIL_UNLESS(rc == MYSQL_DATA_TRUNCATED, "rc != MYSQL_DATA_TRUNCATED"); + FAIL_UNLESS(my_bind[0].error_value, "Errorflag not set"); + FAIL_UNLESS(strncmp(buffer, "Popula", 6) == 0, "buffer != 'Popula'"); + FAIL_UNLESS(length == 7, "length != 7"); + + mysql_stmt_close(stmt); + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_buffer"); + check_mysql_rc(rc, mysql); + + return OK; +} + +static int test_xjoin(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + int rc, i; + const char *query= + "select t.id, p1.value, n1.value, p2.value, n2.value from t3 t LEFT JOIN t1 p1 ON (p1.id=t.param1_id) LEFT JOIN t2 p2 ON (p2.id=t.param2_id) LEFT JOIN t4 n1 ON (n1.id=p1.name_id) LEFT JOIN t4 n2 ON (n2.id=p2.name_id) where t.id=1"; + + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1, t2, t3, t4"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "create table t3 (id int(8), param1_id int(8), param2_id int(8)) ENGINE=InnoDB DEFAULT CHARSET=utf8"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "create table t1 ( id int(8), name_id int(8), value varchar(10)) ENGINE=InnoDB DEFAULT CHARSET=utf8"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "create table t2 (id int(8), name_id int(8), value varchar(10)) ENGINE=InnoDB DEFAULT CHARSET=utf8;"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "create table t4(id int(8), value varchar(10)) ENGINE=InnoDB DEFAULT CHARSET=utf8"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "insert into t3 values (1, 1, 1), (2, 2, null)"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "insert into t1 values (1, 1, 'aaa'), (2, null, 'bbb')"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "insert into t2 values (1, 2, 'ccc')"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "insert into t4 values (1, 'Name1'), (2, null)"); + check_mysql_rc(rc, mysql); + + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + for (i= 0; i < 3; i++) + { + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + rc= 0; + while (mysql_stmt_fetch(stmt) != MYSQL_NO_DATA) + rc++; + FAIL_UNLESS(rc == 1, "rowcount != 1"); + } + mysql_stmt_close(stmt); + + rc= mysql_query(mysql, "DROP TABLE t1, t2, t3, t4"); + check_mysql_rc(rc, mysql); + + return OK; +} + +static int test_union_param(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + char *query; + int rc, i; + MYSQL_BIND my_bind[2]; + char my_val[4]; + ulong my_length= 3L; + my_bool my_null= FALSE; + + strcpy(my_val, "abc"); + + query= (char*)"select ? as my_col union distinct select ?"; + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + /* + We need to bzero bind structure because mysql_stmt_bind_param checks all + its members. + */ + memset(my_bind, '\0', sizeof(my_bind)); + + /* bind parameters */ + my_bind[0].buffer_type= MYSQL_TYPE_STRING; + my_bind[0].buffer= (char*) &my_val; + my_bind[0].buffer_length= 4; + my_bind[0].length= &my_length; + my_bind[0].is_null= &my_null; + my_bind[1].buffer_type= MYSQL_TYPE_STRING; + my_bind[1].buffer= (char*) &my_val; + my_bind[1].buffer_length= 4; + my_bind[1].length= &my_length; + my_bind[1].is_null= &my_null; + + rc= mysql_stmt_bind_param(stmt, my_bind); + check_stmt_rc(rc, stmt); + + for (i= 0; i < 3; i++) + { + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + rc= 0; + while (mysql_stmt_fetch(stmt) != MYSQL_NO_DATA) + rc++; + FAIL_UNLESS(rc == 1, "rowcount != 1"); + } + + mysql_stmt_close(stmt); + + return OK; +} + +static int test_union(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + int rc; + const char *query= "SELECT t1.name FROM t1 UNION " + "SELECT t2.name FROM t2"; + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1, t2"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, + "CREATE TABLE t1 " + "(id INTEGER NOT NULL PRIMARY KEY, " + " name VARCHAR(20) NOT NULL)"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, + "INSERT INTO t1 (id, name) VALUES " + "(2, 'Ja'), (3, 'Ede'), " + "(4, 'Haag'), (5, 'Kabul'), " + "(6, 'Almere'), (7, 'Utrecht'), " + "(8, 'Qandahar'), (9, 'Amsterdam'), " + "(10, 'Amersfoort'), (11, 'Constantine')"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, + "CREATE TABLE t2 " + "(id INTEGER NOT NULL PRIMARY KEY, " + " name VARCHAR(20) NOT NULL)"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, + "INSERT INTO t2 (id, name) VALUES " + "(4, 'Guam'), (5, 'Aruba'), " + "(6, 'Angola'), (7, 'Albania'), " + "(8, 'Anguilla'), (9, 'Argentina'), " + "(10, 'Azerbaijan'), (11, 'Afghanistan'), " + "(12, 'Burkina Faso'), (13, 'Faroe Islands')"); + check_mysql_rc(rc, mysql); + + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + rc= 0; + while (mysql_stmt_fetch(stmt) != MYSQL_NO_DATA) + rc++; + FAIL_UNLESS(rc == 20, "rc != 20"); + mysql_stmt_close(stmt); + + rc= mysql_query(mysql, "DROP TABLE t1, t2"); + check_mysql_rc(rc, mysql); + + return OK; +} + +static int test_union2(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + int rc, i; + const char *query= "select col1 FROM t1 where col1=1 union distinct " + "select col1 FROM t1 where col1=2"; + + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE t1(col1 INT, \ + col2 VARCHAR(40), \ + col3 SMALLINT, \ + col4 TIMESTAMP)"); + check_mysql_rc(rc, mysql); + + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + for (i= 0; i < 3; i++) + { + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + rc= 0; + while (mysql_stmt_fetch(stmt) != MYSQL_NO_DATA) + rc++; + FAIL_UNLESS(rc == 0, "rowcount != 0"); + } + + mysql_stmt_close(stmt); + + rc= mysql_query(mysql, "DROP TABLE t1"); + check_mysql_rc(rc, mysql); + + return OK; +} + +/* Misc tests to keep pure coverage happy */ + +static int test_pure_coverage(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + MYSQL_BIND my_bind[1]; + int rc; + ulong length; + + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_pure"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE test_pure(c1 int, c2 varchar(20))"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "FLUSH TABLES"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "START TRANSACTION"); + check_mysql_rc(rc, mysql); + + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL("insert into test_pure(c67788) values(10)")); + FAIL_IF(!rc, "Error expected"); + mysql_stmt_close(stmt); + + /* Query without params and result should allow one to bind 0 arrays */ + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL("insert into test_pure(c2) values(10)")); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_bind_param(stmt, (MYSQL_BIND*)0); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_bind_result(stmt, (MYSQL_BIND*)0); + FAIL_UNLESS(rc == 1, ""); + + mysql_stmt_close(stmt); + + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL("insert into test_pure(c2) values(?)")); + check_stmt_rc(rc, stmt); + + /* + We need to bzero bind structure because mysql_stmt_bind_param checks all + its members. + */ + memset(my_bind, '\0', sizeof(my_bind)); + my_bind[0].length= &length; + my_bind[0].is_null= 0; + my_bind[0].buffer_length= 0; + + my_bind[0].buffer_type= MYSQL_TYPE_GEOMETRY; + rc= mysql_stmt_bind_param(stmt, my_bind); + FAIL_IF(!rc, "Error expected"); + + my_bind[0].buffer_type= MYSQL_TYPE_STRING; + rc= mysql_stmt_bind_param(stmt, my_bind); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_store_result(stmt); + check_stmt_rc(rc, stmt); + mysql_stmt_close(stmt); + + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL("select * from test_pure")); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + mysql_stmt_close(stmt); + + mysql_query(mysql, "DROP TABLE test_pure"); + return OK; +} + +static int test_insert_select(MYSQL *mysql) +{ + MYSQL_STMT *stmt_insert, *stmt_select; + char *query; + int rc; + uint i; + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1, t2"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "create table t1 (a int)"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "create table t2 (a int)"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "insert into t2 values (1)"); + check_mysql_rc(rc, mysql); + + query= (char*)"insert into t1 select a from t2"; + stmt_insert= mysql_stmt_init(mysql); + FAIL_IF(!stmt_insert, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt_insert, SL(query)); + check_stmt_rc(rc, stmt_insert); + + query= (char*)"select * from t1"; + stmt_select= mysql_stmt_init(mysql); + FAIL_IF(!stmt_select, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt_select, SL(query)); + check_stmt_rc(rc, stmt_select); + + for(i= 0; i < 3; i++) + { + rc= mysql_stmt_execute(stmt_insert); + check_stmt_rc(rc, stmt_insert); + + rc= mysql_stmt_execute(stmt_select); + check_stmt_rc(rc, stmt_select); + rc= 0; + while (mysql_stmt_fetch(stmt_select) != MYSQL_NO_DATA) + rc++; + FAIL_UNLESS(rc == (int)(i+1), "rc != i+1"); + } + + mysql_stmt_close(stmt_insert); + mysql_stmt_close(stmt_select); + rc= mysql_query(mysql, "drop table t1, t2"); + check_mysql_rc(rc, mysql); + return OK; +} + +/* Test simple prepare-insert */ + +static int test_insert(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + int rc; + char str_data[50]; + char tiny_data; + MYSQL_RES *result; + MYSQL_BIND my_bind[2]; + ulong length; + + + rc= mysql_autocommit(mysql, TRUE); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_prep_insert"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE test_prep_insert(col1 tinyint, \ + col2 varchar(50))"); + check_mysql_rc(rc, mysql); + + /* insert by prepare */ + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL("INSERT INTO test_prep_insert VALUES(?, ?)")); + check_stmt_rc(rc, stmt); + + FAIL_IF(mysql_stmt_param_count(stmt) != 2, "Param_count != 2"); + + /* + We need to bzero bind structure because mysql_stmt_bind_param checks all + its members. + */ + memset(my_bind, '\0', sizeof(my_bind)); + + /* tinyint */ + my_bind[0].buffer_type= MYSQL_TYPE_TINY; + my_bind[0].buffer= (void *)&tiny_data; + + /* string */ + my_bind[1].buffer_type= MYSQL_TYPE_STRING; + my_bind[1].buffer= str_data; + my_bind[1].buffer_length= sizeof(str_data);; + my_bind[1].length= &length; + + rc= mysql_stmt_bind_param(stmt, my_bind); + check_stmt_rc(rc, stmt); + + /* now, execute the prepared statement to insert 10 records.. */ + for (tiny_data= 0; tiny_data < 3; tiny_data++) + { + length= sprintf(str_data, "MySQL%d", tiny_data); + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + } + + mysql_stmt_close(stmt); + + /* now fetch the results ..*/ + rc= mysql_commit(mysql); + check_mysql_rc(rc, mysql); + + /* test the results now, only one row should exist */ + rc= mysql_query(mysql, "SELECT * FROM test_prep_insert"); + check_mysql_rc(rc, mysql); + + /* get the result */ + result= mysql_store_result(mysql); + FAIL_IF(!result, "Invalid result set"); + + rc= 0; + while (mysql_fetch_row(result)) + rc++; + FAIL_UNLESS((int) tiny_data == rc, "rowcount != tinydata"); + mysql_free_result(result); + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_prep_insert"); + check_mysql_rc(rc, mysql); + + return OK; +} + +static int test_join(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + int rc, i, j; + const char *query[]= {"SELECT * FROM t2 join t1 on (t1.a=t2.a)", + "SELECT * FROM t2 natural join t1", + "SELECT * FROM t2 join t1 using(a)", + "SELECT * FROM t2 left join t1 on(t1.a=t2.a)", + "SELECT * FROM t2 natural left join t1", + "SELECT * FROM t2 left join t1 using(a)", + "SELECT * FROM t2 right join t1 on(t1.a=t2.a)", + "SELECT * FROM t2 natural right join t1", + "SELECT * FROM t2 right join t1 using(a)"}; + + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1, t2"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE t1 (a int , b int);"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, + "insert into t1 values (1, 1), (2, 2), (3, 3), (4, 4), (5, 5);"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE t2 (a int , c int);"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, + "insert into t2 values (1, 1), (2, 2), (3, 3), (4, 4), (5, 5);"); + check_mysql_rc(rc, mysql); + + for (j= 0; j < 9; j++) + { + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(query[j])); + check_stmt_rc(rc, stmt); + for (i= 0; i < 3; i++) + { + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + rc= 0; + while (mysql_stmt_fetch(stmt) != MYSQL_NO_DATA) + rc++; + FAIL_UNLESS(rc == 5, "rowcount != 5"); + } + mysql_stmt_close(stmt); + } + + rc= mysql_query(mysql, "DROP TABLE t1, t2"); + check_mysql_rc(rc, mysql); + return OK; +} + +static int test_left_join_view(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + int rc, i; + const char *query= + "select t1.a, v1.x from t1 left join v1 on (t1.a= v1.x);"; + + + rc = mysql_query(mysql, "DROP TABLE IF EXISTS t1,v1"); + check_mysql_rc(rc, mysql); + + rc = mysql_query(mysql, "DROP VIEW IF EXISTS v1,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), (3)"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql,"create view v1 (x) as select a from t1 where a > 1"); + check_mysql_rc(rc, mysql); + stmt= mysql_stmt_init(mysql); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + for (i= 0; i < 3; i++) + { + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + rc= 0; + while (mysql_stmt_fetch(stmt) != MYSQL_NO_DATA) + rc++; + FAIL_UNLESS(rc == 3, "rowcount != 3"); + } + mysql_stmt_close(stmt); + + rc= mysql_query(mysql, "DROP VIEW v1"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "DROP TABLE t1"); + check_mysql_rc(rc, mysql); + return OK; +} + +/* Test simple sample - manual */ + +static int test_manual_sample(MYSQL *mysql) +{ + unsigned int param_count; + MYSQL_STMT *stmt; + short small_data; + int int_data; + int rc; + char str_data[50]; + ulonglong affected_rows; + MYSQL_BIND my_bind[3]; + my_bool is_null; + char query[MAX_TEST_QUERY_LENGTH]; + + + /* + Sample which is incorporated directly in the manual under Prepared + statements section (Example from mysql_stmt_execute() + */ + + memset(str_data, 0, sizeof(str_data)); + mysql_autocommit(mysql, 1); + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_table"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "CREATE TABLE test_table(col1 int, col2 varchar(50), \ + col3 smallint, \ + col4 timestamp)"); + check_mysql_rc(rc, mysql); + + /* Prepare a insert query with 3 parameters */ + strcpy(query, "INSERT INTO test_table(col1, col2, col3) values(?, ?, ?)"); + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + /* Get the parameter count from the statement */ + param_count= mysql_stmt_param_count(stmt); + FAIL_IF(param_count != 3, "param_count != 3"); + + memset(my_bind, '\0', sizeof(my_bind)); + + /* INTEGER PART */ + my_bind[0].buffer_type= MYSQL_TYPE_LONG; + my_bind[0].buffer= (void *)&int_data; + + /* STRING PART */ + my_bind[1].buffer_type= MYSQL_TYPE_VAR_STRING; + my_bind[1].buffer= (void *)str_data; + my_bind[1].buffer_length= sizeof(str_data); + + /* SMALLINT PART */ + my_bind[2].buffer_type= MYSQL_TYPE_SHORT; + my_bind[2].buffer= (void *)&small_data; + my_bind[2].is_null= &is_null; + is_null= 0; + + /* Bind the buffers */ + rc= mysql_stmt_bind_param(stmt, my_bind); + check_stmt_rc(rc, stmt); + + /* Specify the data */ + int_data= 10; /* integer */ + strcpy(str_data, "MySQL"); /* string */ + + /* INSERT SMALLINT data as NULL */ + is_null= 1; + + /* Execute the insert statement - 1*/ + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + /* Get the total rows affected */ + affected_rows= mysql_stmt_affected_rows(stmt); + FAIL_IF(affected_rows != 1, "affected-rows != 1"); + + /* Re-execute the insert, by changing the values */ + int_data= 1000; + strcpy(str_data, "The most popular open source database"); + small_data= 1000; /* smallint */ + is_null= 0; /* reset */ + + /* Execute the insert statement - 2*/ + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + /* Get the total rows affected */ + affected_rows= mysql_stmt_affected_rows(stmt); + + FAIL_IF(affected_rows != 1, "affected_rows != 1"); + + /* Close the statement */ + rc= mysql_stmt_close(stmt); + check_stmt_rc(rc, stmt); + + /* DROP THE TABLE */ + rc= mysql_query(mysql, "DROP TABLE test_table"); + check_mysql_rc(rc, mysql); + return OK; +} + +static int test_create_drop(MYSQL *mysql) +{ + MYSQL_STMT *stmt_create, *stmt_drop, *stmt_select, *stmt_create_select; + char *query; + int rc, i; + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1, t2"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "create table t2 (a int);"); + 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 t2 values (3), (2), (1);"); + check_mysql_rc(rc, mysql); + + query= (char*)"create table t1 (a int)"; + stmt_create= mysql_stmt_init(mysql); + FAIL_IF(!stmt_create, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt_create, SL(query)); + check_stmt_rc(rc, stmt_create); + + query= (char*)"drop table t1"; + stmt_drop= mysql_stmt_init(mysql); + FAIL_IF(!stmt_drop, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt_drop, SL(query)); + check_stmt_rc(rc, stmt_drop); + + query= (char*)"select a in (select a from t2) from t1"; + stmt_select= mysql_stmt_init(mysql); + FAIL_IF(!stmt_select, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt_select, SL(query)); + check_stmt_rc(rc, stmt_select); + + rc= mysql_query(mysql, "DROP TABLE t1"); + check_mysql_rc(rc, mysql); + + query= (char*)"create table t1 select a from t2"; + stmt_create_select= mysql_stmt_init(mysql); + FAIL_IF(!stmt_create_select, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt_create_select, SL(query)); + check_stmt_rc(rc, stmt_create_select); + + for (i= 0; i < 3; i++) + { + rc= mysql_stmt_execute(stmt_create); + check_stmt_rc(rc, stmt_create); + + rc= mysql_stmt_execute(stmt_select); + check_stmt_rc(rc, stmt_select); + + rc= 0; + while (mysql_stmt_fetch(stmt_select) != MYSQL_NO_DATA) + rc++; + FAIL_UNLESS(rc == 0, "rowcount != 0"); + + rc= mysql_stmt_execute(stmt_drop); + check_stmt_rc(rc, stmt_drop); + + rc= mysql_stmt_execute(stmt_create_select); + check_stmt_rc(rc, stmt_create); + + rc= mysql_stmt_execute(stmt_select); + check_stmt_rc(rc, stmt_select); + rc= 0; + while (mysql_stmt_fetch(stmt_select) != MYSQL_NO_DATA) + rc++; + FAIL_UNLESS(rc == 3, "rowcount != 3"); + + rc= mysql_stmt_execute(stmt_drop); + check_stmt_rc(rc, stmt_drop); + } + + mysql_stmt_close(stmt_create); + mysql_stmt_close(stmt_drop); + mysql_stmt_close(stmt_select); + mysql_stmt_close(stmt_create_select); + + rc= mysql_query(mysql, "DROP TABLE t2"); + check_mysql_rc(rc, mysql); + return OK; +} + +/* Test DATE, TIME, DATETIME and TS with MYSQL_TIME conversion */ + +static int test_date(MYSQL *mysql) +{ + int rc; + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_date"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE test_date(c1 TIMESTAMP, \ + c2 TIME, \ + c3 DATETIME, \ + c4 DATE)"); + + check_mysql_rc(rc, mysql); + + rc= test_bind_date_conv(mysql, 5); + mysql_query(mysql, "DROP TABLE IF EXISTS test_date"); + return rc; +} + + +/* Test all time types to DATE and DATE to all types */ + +static int test_date_date(MYSQL *mysql) +{ + int rc; + + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_date"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE test_date(c1 DATE, \ + c2 DATE, \ + c3 DATE, \ + c4 DATE)"); + + check_mysql_rc(rc, mysql); + + rc= test_bind_date_conv(mysql, 3); + mysql_query(mysql, "DROP TABLE IF EXISTS test_date"); + return rc; +} + +/* Test all time types to TIMESTAMP and TIMESTAMP to all types */ + +static int test_date_ts(MYSQL *mysql) +{ + int rc; + + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_date"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE test_date(c1 TIMESTAMP, \ + c2 TIMESTAMP, \ + c3 TIMESTAMP, \ + c4 TIMESTAMP)"); + + check_mysql_rc(rc, mysql); + + rc= test_bind_date_conv(mysql, 2); + mysql_query(mysql, "DROP TABLE IF EXISTS test_date"); + return rc; +} + + +/* Test all time types to DATETIME and DATETIME to all types */ + +static int test_date_dt(MYSQL *mysql) +{ + int rc; + + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_date"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE test_date(c1 datetime, " + " c2 datetime, c3 datetime, c4 date)"); + check_mysql_rc(rc, mysql); + + rc= test_bind_date_conv(mysql, 2); + mysql_query(mysql, "DROP TABLE IF EXISTS test_date"); + return rc; +} + +/* Test all time types to TIME and TIME to all types */ + +static int test_date_time(MYSQL *mysql) +{ + int rc; + + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_date"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE test_date(c1 TIME, \ + c2 TIME, \ + c3 TIME, \ + c4 TIME)"); + + check_mysql_rc(rc, mysql); + + rc= test_bind_date_conv(mysql, 3); + mysql_query(mysql, "DROP TABLE IF EXISTS test_date"); + return rc; +} + +/* + Test of basic checks that are performed in server for components + of MYSQL_TIME parameters. +*/ + +static int test_datetime_ranges(MYSQL *mysql) +{ + const char *stmt_text; + int rc, i; + MYSQL_STMT *stmt; + MYSQL_BIND my_bind[6]; + MYSQL_TIME tm[6]; + + if (!is_mariadb) + return SKIP; + + stmt_text= "drop table if exists t1"; + rc= mysql_real_query(mysql, SL(stmt_text)); + check_mysql_rc(rc, mysql); + + stmt_text= "create table t1 (year datetime, month datetime, day datetime, " + "hour datetime, min datetime, sec datetime)"; + rc= mysql_real_query(mysql, SL(stmt_text)); + check_mysql_rc(rc, mysql); + + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + stmt_text= "INSERT INTO t1 VALUES (?, ?, ?, ?, ?, ?)"; + rc= mysql_stmt_prepare(stmt, SL(stmt_text)); + check_stmt_rc(rc, stmt); + FAIL_IF(mysql_stmt_param_count(stmt) != 6, "param_count != 6"); + + memset(my_bind, '\0', sizeof(my_bind)); + for (i= 0; i < 6; i++) + { + my_bind[i].buffer_type= MYSQL_TYPE_DATETIME; + my_bind[i].buffer= &tm[i]; + } + rc= mysql_stmt_bind_param(stmt, my_bind); + check_stmt_rc(rc, stmt); + + tm[0].year= 2004; tm[0].month= 11; tm[0].day= 10; + tm[0].hour= 12; tm[0].minute= 30; tm[0].second= 30; + tm[0].second_part= 0; tm[0].neg= 0; + + tm[5]= tm[4]= tm[3]= tm[2]= tm[1]= tm[0]; + tm[0].year= 10000; tm[1].month= 13; tm[2].day= 32; + tm[3].hour= 24; tm[4].minute= 60; tm[5].second= 60; + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + FAIL_IF(!mysql_warning_count(mysql), "warnings expected"); + + if (verify_col_data(mysql, "t1", "year", "0000-00-00 00:00:00")) + goto error; + if (verify_col_data(mysql, "t1", "month", "0000-00-00 00:00:00")) + goto error; + if (verify_col_data(mysql, "t1", "day", "0000-00-00 00:00:00")) + goto error; + if (verify_col_data(mysql, "t1", "hour", "0000-00-00 00:00:00")) + goto error; + if (verify_col_data(mysql, "t1", "min", "0000-00-00 00:00:00")) + goto error; + if (verify_col_data(mysql, "t1", "sec", "0000-00-00 00:00:00")) + goto error; + + mysql_stmt_close(stmt); + + stmt_text= "delete from t1"; + rc= mysql_real_query(mysql, SL(stmt_text)); + check_mysql_rc(rc, mysql); + + stmt_text= "INSERT INTO t1 (year, month, day) VALUES (?, ?, ?)"; + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(stmt_text)); + check_stmt_rc(rc, stmt); + + /* + We reuse contents of bind and tm arrays left from previous part of test. + */ + for (i= 0; i < 3; i++) + my_bind[i].buffer_type= MYSQL_TYPE_DATE; + + rc= mysql_stmt_bind_param(stmt, my_bind); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + FAIL_IF(!mysql_warning_count(mysql), "warnings expected"); + + if (verify_col_data(mysql, "t1", "year", "0000-00-00 00:00:00")) + goto error; + if (verify_col_data(mysql, "t1", "month", "0000-00-00 00:00:00")) + goto error; + if (verify_col_data(mysql, "t1", "day", "0000-00-00 00:00:00")) + goto error; + + mysql_stmt_close(stmt); + + stmt_text= "drop table t1"; + rc= mysql_real_query(mysql, SL(stmt_text)); + check_mysql_rc(rc, mysql); + + stmt_text= "create table t1 (day_ovfl time, day time, hour time, min time, sec time)"; + rc= mysql_real_query(mysql, SL(stmt_text)); + check_mysql_rc(rc, mysql); + + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + stmt_text= "INSERT INTO t1 VALUES (?,?,?,?,?)"; + rc= mysql_stmt_prepare(stmt, SL(stmt_text)); + check_stmt_rc(rc, stmt); + FAIL_IF(mysql_stmt_param_count(stmt) != 5, "param_count != 5"); + + /* + Again we reuse what we can from previous part of test. + */ + for (i= 0; i < 5; i++) + my_bind[i].buffer_type= MYSQL_TYPE_TIME; + + rc= mysql_stmt_bind_param(stmt, my_bind); + check_stmt_rc(rc, stmt); + + tm[0].year= 0; tm[0].month= 0; tm[0].day= 10; + tm[0].hour= 12; tm[0].minute= 30; tm[0].second= 30; + tm[0].second_part= 0; tm[0].neg= 0; + + tm[4]= tm[3]= tm[2]= tm[1]= tm[0]; + tm[0].day= 35; tm[1].day= 34; tm[2].hour= 30; tm[3].minute= 60; tm[4].second= 60; + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + FAIL_IF(mysql_warning_count(mysql) != 2, "warning_count != 2"); + + if (verify_col_data(mysql, "t1", "day_ovfl", "838:59:59")) + goto error; + if (verify_col_data(mysql, "t1", "day", "828:30:30")) + goto error; + if (verify_col_data(mysql, "t1", "hour", "270:30:30")) + goto error; + if (verify_col_data(mysql, "t1", "min", "00:00:00")) + goto error; + if (verify_col_data(mysql, "t1", "sec", "00:00:00")) + goto error; + + mysql_stmt_close(stmt); + stmt_text= "drop table t1"; + rc= mysql_real_query(mysql, SL(stmt_text)); + check_mysql_rc(rc, mysql); + return OK; +error: + mysql_stmt_close(stmt); + stmt_text= "drop table t1"; + rc= mysql_real_query(mysql, SL(stmt_text)); + check_mysql_rc(rc, mysql); + return OK; +} + +static int test_derived(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + int rc, i; + MYSQL_BIND my_bind[1]; + int32 my_val= 0; + ulong my_length= 0L; + my_bool my_null= FALSE; + const char *query= + "select count(1) from (select f.id from t1 f where f.id=?) as x"; + + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "create table t1 (id int(8), primary key (id)) \ +ENGINE=InnoDB DEFAULT CHARSET=utf8"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "insert into t1 values (1)"); + check_mysql_rc(rc, mysql); + + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + memset(my_bind, '\0', sizeof(my_bind)); + + my_bind[0].buffer_type= MYSQL_TYPE_LONG; + my_bind[0].buffer= (void *)&my_val; + my_bind[0].length= &my_length; + my_bind[0].is_null= &my_null; + my_val= 1; + rc= mysql_stmt_bind_param(stmt, my_bind); + check_stmt_rc(rc, stmt); + + for (i= 0; i < 3; i++) + { + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + rc= 0; + while (!mysql_stmt_fetch(stmt)) + rc++; + FAIL_UNLESS(rc == 1, "rowcount != 1"); + } + mysql_stmt_close(stmt); + + rc= mysql_query(mysql, "DROP TABLE t1"); + check_mysql_rc(rc, mysql); + return OK; +} + +static int test_distinct(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + int rc, i; + const char *query= + "SELECT 2+count(distinct b), group_concat(a) FROM t1 group by a"; + + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE t1 (a int , b int);"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, + "insert into t1 values (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), \ +(1, 10), (2, 20), (3, 30), (4, 40), (5, 50);"); + check_mysql_rc(rc, mysql); + + for (i= 0; i < 3; i++) + { + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc= 0; + while (!mysql_stmt_fetch(stmt)) + rc++; + FAIL_UNLESS(rc == 5, "rowcount != 5"); + mysql_stmt_close(stmt); + } + + rc= mysql_query(mysql, "DROP TABLE t1"); + check_mysql_rc(rc, mysql); + return OK; +} + +static int test_do_set(MYSQL *mysql) +{ + MYSQL_STMT *stmt_do, *stmt_set; + char *query; + int rc, i; + + 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); + + query= (char*)"do @var:=(1 in (select * from t1))"; + stmt_do= mysql_stmt_init(mysql); + FAIL_IF(!stmt_do, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt_do, SL(query)); + check_stmt_rc(rc, stmt_do); + + query= (char*)"set @var=(1 in (select * from t1))"; + stmt_set= mysql_stmt_init(mysql); + FAIL_IF(!stmt_set, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt_set, SL(query)); + check_stmt_rc(rc, stmt_set); + + for (i= 0; i < 3; i++) + { + rc= mysql_stmt_execute(stmt_do); + check_stmt_rc(rc, stmt_do); + rc= mysql_stmt_execute(stmt_set); + check_stmt_rc(rc, stmt_set); + } + + mysql_stmt_close(stmt_do); + mysql_stmt_close(stmt_set); + return OK; +} + +static int test_double_compare(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + int rc; + char real_data[10], tiny_data; + double double_data; + MYSQL_RES *result; + MYSQL_BIND my_bind[3]; + ulong length[3]; + char query[MAX_TEST_QUERY_LENGTH]; + + + rc= mysql_autocommit(mysql, TRUE); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_double_compare"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE test_double_compare(col1 tinyint, " + " col2 float, col3 double )"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "INSERT INTO test_double_compare " + "VALUES (1, 10.2, 34.5)"); + check_mysql_rc(rc, mysql); + + strcpy(query, "UPDATE test_double_compare SET col1=100 " + "WHERE col1 = ? AND col2 = ? AND COL3 = ?"); + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + FAIL_IF(mysql_stmt_param_count(stmt) != 3, "param_count != 3"); + + memset(my_bind, '\0', sizeof(my_bind)); + + /* tinyint */ + my_bind[0].buffer_type= MYSQL_TYPE_TINY; + my_bind[0].buffer= (void *)&tiny_data; + + /* string->float */ + my_bind[1].buffer_type= MYSQL_TYPE_STRING; + my_bind[1].buffer= (void *)&real_data; + my_bind[1].buffer_length= sizeof(real_data); + my_bind[1].length= &length[1]; + + /* double */ + my_bind[2].buffer_type= MYSQL_TYPE_DOUBLE; + my_bind[2].buffer= (void *)&double_data; + + tiny_data= 1; + strcpy(real_data, "10.2"); + length[1]= (ulong)strlen(real_data); + double_data= 34.5; + rc= mysql_stmt_bind_param(stmt, my_bind); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + FAIL_IF(mysql_stmt_affected_rows(stmt), "affected_rows != 0"); + + mysql_stmt_close(stmt); + + /* now fetch the results ..*/ + rc= mysql_commit(mysql); + check_mysql_rc(rc, mysql); + + /* test the results now, only one row should exist */ + rc= mysql_query(mysql, "SELECT * FROM test_double_compare"); + check_mysql_rc(rc, mysql); + + /* get the result */ + result= mysql_store_result(mysql); + FAIL_IF(!result, "Invalid result set"); + + rc= 0; + while (mysql_fetch_row(result)) + rc++; + FAIL_UNLESS((int)tiny_data == rc, "rowcount != tinydata"); + mysql_free_result(result); + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_double_compare"); + check_mysql_rc(rc, mysql); + return OK; +} + +static int test_multi(MYSQL *mysql) +{ + MYSQL_STMT *stmt_delete, *stmt_update, *stmt_select1, *stmt_select2; + char *query; + MYSQL_BIND my_bind[1]; + int rc, i; + int32 param= 1; + ulong length= 1; + + /* + We need to bzero bind structure because mysql_stmt_bind_param checks all + its members. + */ + memset(my_bind, '\0', sizeof(my_bind)); + + my_bind[0].buffer_type= MYSQL_TYPE_LONG; + my_bind[0].buffer= (void *)¶m; + my_bind[0].length= &length; + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1, t2"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "create table t1 (a int, b int)"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "create table t2 (a int, b int)"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "insert into t1 values (3, 3), (2, 2), (1, 1)"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "insert into t2 values (3, 3), (2, 2), (1, 1)"); + check_mysql_rc(rc, mysql); + + query= (char*)"delete t1, t2 from t1, t2 where t1.a=t2.a and t1.b=10"; + stmt_delete= mysql_stmt_init(mysql); + FAIL_IF(!stmt_delete, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt_delete, SL(query)); + check_stmt_rc(rc, stmt_delete); + + query= (char*)"update t1, t2 set t1.b=10, t2.b=10 where t1.a=t2.a and t1.b=?"; + stmt_update= mysql_stmt_init(mysql); + FAIL_IF(!stmt_update, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt_update, SL(query)); + check_stmt_rc(rc, stmt_update); + + query= (char*)"select * from t1"; + stmt_select1= mysql_stmt_init(mysql); + FAIL_IF(!stmt_select1, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt_select1, SL(query)); + check_stmt_rc(rc, stmt_select1); + + query= (char*)"select * from t2"; + stmt_select2= mysql_stmt_init(mysql); + FAIL_IF(!stmt_select2, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt_select2, SL(query)); + check_stmt_rc(rc, stmt_select2); + + for(i= 0; i < 3; i++) + { + rc= mysql_stmt_bind_param(stmt_update, my_bind); + check_stmt_rc(rc, stmt_update); + + rc= mysql_stmt_execute(stmt_update); + check_stmt_rc(rc, stmt_update); + + rc= mysql_stmt_execute(stmt_delete); + check_stmt_rc(rc, stmt_delete); + + rc= mysql_stmt_execute(stmt_select1); + check_stmt_rc(rc, stmt_select1); + rc= 0; + while (!mysql_stmt_fetch(stmt_select1)) + rc++; + FAIL_UNLESS(rc == 3-param, "rc != 3 - param"); + + rc= mysql_stmt_execute(stmt_select2); + check_stmt_rc(rc, stmt_select2); + rc= 0; + while (!mysql_stmt_fetch(stmt_select2)) + rc++; + FAIL_UNLESS(rc == 3-param, "rc != 3 - param"); + + param++; + } + + mysql_stmt_close(stmt_delete); + mysql_stmt_close(stmt_update); + mysql_stmt_close(stmt_select1); + mysql_stmt_close(stmt_select2); + rc= mysql_query(mysql, "drop table t1, t2"); + check_mysql_rc(rc, mysql); + + return OK; +} + +/* Multiple stmts .. */ + +static int test_multi_stmt(MYSQL *mysql) +{ + + MYSQL_STMT *stmt, *stmt1, *stmt2; + int rc; + uint32 id; + char name[50]; + MYSQL_BIND my_bind[2]; + ulong length[2]; + my_bool is_null[2]; + const char *query; + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_multi_table"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE test_multi_table(id int, name char(20))"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "INSERT INTO test_multi_table values(10, 'mysql')"); + check_mysql_rc(rc, mysql); + + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + query= "SELECT * FROM test_multi_table WHERE id=?"; + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + stmt2= mysql_stmt_init(mysql); + FAIL_IF(!stmt2, mysql_error(mysql)); + query= "UPDATE test_multi_table SET name='updated' WHERE id=10"; + rc= mysql_stmt_prepare(stmt2, SL(query)); + check_stmt_rc(rc, stmt2); + + FAIL_IF(mysql_stmt_param_count(stmt) != 1, "param_count != 1"); + + memset(my_bind, '\0', sizeof(my_bind)); + + my_bind[0].buffer_type= MYSQL_TYPE_LONG; + my_bind[0].buffer= (void *)&id; + my_bind[0].is_null= &is_null[0]; + my_bind[0].length= &length[0]; + is_null[0]= 0; + length[0]= 0; + + my_bind[1].buffer_type= MYSQL_TYPE_STRING; + my_bind[1].buffer= (void *)name; + my_bind[1].buffer_length= sizeof(name); + my_bind[1].length= &length[1]; + my_bind[1].is_null= &is_null[1]; + + rc= mysql_stmt_bind_param(stmt, my_bind); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_bind_result(stmt, my_bind); + check_stmt_rc(rc, stmt); + + id= 10; + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + id= 999; + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + + FAIL_UNLESS(id == 10, "id != 10"); + FAIL_UNLESS(strcmp(name, "mysql") == 0, "name != 'mysql'"); + + rc= mysql_stmt_fetch(stmt); + FAIL_UNLESS(rc == MYSQL_NO_DATA, ""); + + /* alter the table schema now */ + stmt1= mysql_stmt_init(mysql); + FAIL_IF(!stmt1, mysql_error(mysql)); + query= "DELETE FROM test_multi_table WHERE id=? AND CONVERT(name USING utf8)=?"; + rc= mysql_stmt_prepare(stmt1, SL(query)); + check_stmt_rc(rc, stmt1); + + FAIL_IF(mysql_stmt_param_count(stmt1) != 2, "param_count != 2"); + + rc= mysql_stmt_bind_param(stmt1, my_bind); + check_stmt_rc(rc, stmt1); + + rc= mysql_stmt_execute(stmt2); + check_stmt_rc(rc, stmt2); + + FAIL_IF(mysql_stmt_affected_rows(stmt2) != 1, "affected_rows != 1"); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + + FAIL_UNLESS(id == 10, "id != 10"); + FAIL_UNLESS(strcmp(name, "updated") == 0, "name != 'updated'"); + + rc= mysql_stmt_fetch(stmt); + FAIL_UNLESS(rc == MYSQL_NO_DATA, "rc != MYSQL_NO_DATA"); + + rc= mysql_stmt_execute(stmt1); + check_stmt_rc(rc, stmt1); + + FAIL_IF(mysql_stmt_affected_rows(stmt1) != 1, "affected_rows != 1"); + + mysql_stmt_close(stmt1); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_fetch(stmt); + FAIL_UNLESS(rc == MYSQL_NO_DATA, "rc != MYSQL_NO_DATA"); + + rc= my_stmt_result(mysql, "SELECT * FROM test_multi_table"); + FAIL_UNLESS(rc == 0, "rc != 0"); + + mysql_stmt_close(stmt); + mysql_stmt_close(stmt2); + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_multi_table"); + check_mysql_rc(rc, mysql); + + return OK; +} + +/* Test 'n' statements create and close */ + +static int test_nstmts(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + char query[255]; + int rc; + static uint i, total_stmts= 2000; + MYSQL_BIND my_bind[1]; + + SKIP_SKYSQL; + + mysql_autocommit(mysql, TRUE); + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_nstmts"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE test_nstmts(id int)"); + check_mysql_rc(rc, mysql); + + memset(my_bind, '\0', sizeof(my_bind)); + + my_bind[0].buffer= (void *)&i; + my_bind[0].buffer_type= MYSQL_TYPE_LONG; + + for (i= 0; i < total_stmts; i++) + { + strcpy(query, "insert into test_nstmts values(?)"); + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_bind_param(stmt, my_bind); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + mysql_stmt_close(stmt); + } + + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(" select count(*) from test_nstmts")); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + i= 0; + rc= mysql_stmt_bind_result(stmt, my_bind); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + FAIL_UNLESS( i == total_stmts, "total_stmts != i"); + + rc= mysql_stmt_fetch(stmt); + FAIL_UNLESS(rc == MYSQL_NO_DATA, "rc != MYSQL_NO_DATA"); + + mysql_stmt_close(stmt); + + rc= mysql_query(mysql, "DROP TABLE test_nstmts"); + check_mysql_rc(rc, mysql); + return OK; +} + +/* Test simple null */ + +static int test_null(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + int rc; + uint nData; + MYSQL_BIND my_bind[2]; + my_bool is_null[2]; + char query[MAX_TEST_QUERY_LENGTH]; + + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_null"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE test_null(col1 int, col2 varchar(50))"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "FLUSH TABLES"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "START TRANSACTION"); + check_mysql_rc(rc, mysql); + + /* insert by prepare, wrong column name */ + strcpy(query, "INSERT INTO test_null(col3, col2) VALUES(?, ?)"); + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(query)); + FAIL_IF(!rc, "Error expected"); + mysql_stmt_close(stmt); + + strcpy(query, "INSERT INTO test_null(col1, col2) VALUES(?, ?)"); + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + FAIL_IF(mysql_stmt_param_count(stmt) != 2, "param_count != 2"); + + memset(my_bind, '\0', sizeof(my_bind)); + + my_bind[0].buffer_type= MYSQL_TYPE_LONG; + my_bind[0].is_null= &is_null[0]; + is_null[0]= 1; + my_bind[1]= my_bind[0]; + + rc= mysql_stmt_bind_param(stmt, my_bind); + check_stmt_rc(rc, stmt); + + /* now, execute the prepared statement to insert 10 records.. */ + for (nData= 0; nData<10; nData++) + { + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + } + + /* Re-bind with MYSQL_TYPE_NULL */ + my_bind[0].buffer_type= MYSQL_TYPE_NULL; + is_null[0]= 0; /* reset */ + my_bind[1]= my_bind[0]; + + rc= mysql_stmt_bind_param(stmt, my_bind); + check_stmt_rc(rc, stmt); + + for (nData= 0; nData<10; nData++) + { + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + } + + mysql_stmt_close(stmt); + + /* now fetch the results ..*/ + rc= mysql_commit(mysql); + check_mysql_rc(rc, mysql); + + nData*= 2; + rc= my_stmt_result(mysql, "SELECT * FROM test_null");; + FAIL_UNLESS((int) nData == rc, "rc != ndata"); + + /* Fetch results */ + my_bind[0].buffer_type= MYSQL_TYPE_LONG; + my_bind[0].buffer= (void *)&nData; /* this buffer won't be altered */ + my_bind[0].length= 0; + my_bind[1]= my_bind[0]; + my_bind[0].is_null= &is_null[0]; + my_bind[1].is_null= &is_null[1]; + + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL("SELECT * FROM test_null")); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_bind_result(stmt, my_bind); + check_stmt_rc(rc, stmt); + + rc= 0; + is_null[0]= is_null[1]= 0; + while (mysql_stmt_fetch(stmt) != MYSQL_NO_DATA) + { + FAIL_UNLESS(is_null[0], "!is_null"); + FAIL_UNLESS(is_null[1], "!is_null"); + rc++; + is_null[0]= is_null[1]= 0; + } + FAIL_UNLESS(rc == (int) nData, "rc != nData"); + mysql_stmt_close(stmt); + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_null"); + check_mysql_rc(rc, mysql); + return OK; +} + +static int test_order_param(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + int rc; + const char *query; + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE t1(a INT, b char(10))"); + check_mysql_rc(rc, mysql); + + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + query= "select sum(a) + 200, 1 from t1 " + " union distinct " + "select sum(a) + 200, 1 from t1 group by b "; + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + mysql_stmt_close(stmt); + + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + query= "select sum(a) + 200, ? from t1 group by b " + " union distinct " + "select sum(a) + 200, 1 from t1 group by b "; + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + mysql_stmt_close(stmt); + + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + query= "select sum(a) + 200, ? from t1 " + " union distinct " + "select sum(a) + 200, 1 from t1 group by b "; + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + mysql_stmt_close(stmt); + + rc= mysql_query(mysql, "DROP TABLE t1"); + check_mysql_rc(rc, mysql); + return OK; +} + +static int test_rename(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + const char *query= "rename table t1 to t2, t3 to t4"; + int rc; + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1, t2, t3, t4"); + check_mysql_rc(rc, mysql); + + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + rc= mysql_query(mysql, "create table t1 (a int)"); + check_mysql_rc(rc, mysql); + + rc= mysql_stmt_execute(stmt); + FAIL_IF(!rc, "Error expected"); + + rc= mysql_query(mysql, "create table t3 (a int)"); + check_mysql_rc(rc, mysql); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + FAIL_IF(!rc, "Errr expected"); + + rc= mysql_query(mysql, "rename table t2 to t1, t4 to t3"); + check_mysql_rc(rc, mysql); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + mysql_stmt_close(stmt); + + rc= mysql_query(mysql, "DROP TABLE t2, t4"); + check_mysql_rc(rc, mysql); + return OK; +} + +static int test_rewind(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + MYSQL_BIND my_bind; + int rc = 0; + const char *stmt_text; + long unsigned int length=4, Data=0; + my_bool isnull=0; + + + stmt_text= "CREATE TABLE t1 (a int)"; + rc= mysql_real_query(mysql, SL(stmt_text)); + check_mysql_rc(rc, mysql); + stmt_text= "INSERT INTO t1 VALUES(2),(3),(4)"; + rc= mysql_real_query(mysql, SL(stmt_text)); + check_mysql_rc(rc, mysql); + + stmt= mysql_stmt_init(mysql); + stmt_text= "SELECT * FROM t1"; + rc= mysql_stmt_prepare(stmt, SL(stmt_text)); + check_stmt_rc(rc, stmt); + + memset(&my_bind, '\0', sizeof(MYSQL_BIND)); + my_bind.buffer_type= MYSQL_TYPE_LONG; + my_bind.buffer= (void *)&Data; /* this buffer won't be altered */ + my_bind.length= &length; + my_bind.is_null= &isnull; + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_store_result(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_bind_result(stmt, &my_bind); + check_stmt_rc(rc, stmt); + + /* retrieve all result sets till we are at the end */ + while(!(rc=mysql_stmt_fetch(stmt))); + FAIL_UNLESS(rc == MYSQL_NO_DATA, "rc != MYSQL_NO_DATA"); + + /* seek to the first row */ + mysql_stmt_data_seek(stmt, 0); + + /* now we should be able to fetch the results again */ + /* but mysql_stmt_fetch returns MYSQL_NO_DATA */ + while(!(rc= mysql_stmt_fetch(stmt))); + + FAIL_UNLESS(rc == MYSQL_NO_DATA, "rc != MYSQL_NO_DATA"); + + stmt_text= "DROP TABLE t1"; + rc= mysql_real_query(mysql, SL(stmt_text)); + check_mysql_rc(rc, mysql); + rc= mysql_stmt_free_result(stmt); + rc= mysql_stmt_close(stmt); + return OK; +} + +/* Test simple select */ + +static int test_select(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + int rc; + char szData[25]; + int nData= 1; + MYSQL_BIND my_bind[2]; + ulong length[2]; + char query[MAX_TEST_QUERY_LENGTH]; + + + rc= mysql_autocommit(mysql, TRUE); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_select"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE test_select(id int, name varchar(50))"); + check_mysql_rc(rc, mysql); + + /* insert a row and commit the transaction */ + rc= mysql_query(mysql, "INSERT INTO test_select VALUES(10, 'venu')"); + check_mysql_rc(rc, mysql); + + /* now insert the second row, and roll back the transaction */ + rc= mysql_query(mysql, "INSERT INTO test_select VALUES(20, 'mysql')"); + check_mysql_rc(rc, mysql); + + rc= mysql_commit(mysql); + check_mysql_rc(rc, mysql); + + strcpy(query, "SELECT * FROM test_select WHERE id= ? " + "AND CONVERT(name USING utf8) =?"); + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + FAIL_IF(mysql_stmt_param_count(stmt) != 2, "param_count != 2"); + + memset(my_bind, '\0', sizeof(my_bind)); + + /* string data */ + nData= 10; + strcpy(szData, (char *)"venu"); + my_bind[1].buffer_type= MYSQL_TYPE_STRING; + my_bind[1].buffer= (void *)szData; + my_bind[1].buffer_length= 4; + my_bind[1].length= &length[1]; + length[1]= 4; + + my_bind[0].buffer= (void *)&nData; + my_bind[0].buffer_type= MYSQL_TYPE_LONG; + + rc= mysql_stmt_bind_param(stmt, my_bind); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc= 0; + while (!mysql_stmt_fetch(stmt)) + rc++; + FAIL_UNLESS(rc == 1, "rc != 1"); + + mysql_stmt_close(stmt); + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_select"); + check_mysql_rc(rc, mysql); + return OK; +} + +/* Test simple select with prepare */ + +static int test_select_prepare(MYSQL *mysql) +{ + int rc; + MYSQL_STMT *stmt; + + + rc= mysql_autocommit(mysql, TRUE); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_select"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE test_select(id int, name varchar(50))"); + check_mysql_rc(rc, mysql); + + /* insert a row and commit the transaction */ + rc= mysql_query(mysql, "INSERT INTO test_select VALUES(10, 'venu')"); + check_mysql_rc(rc, mysql); + + rc= mysql_commit(mysql); + check_mysql_rc(rc, mysql); + + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL("SELECT * FROM test_select")); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc= 0; + while (!mysql_stmt_fetch(stmt)) + rc++; + FAIL_UNLESS(rc == 1, "rowcount != 1"); + mysql_stmt_close(stmt); + + rc= mysql_query(mysql, "DROP TABLE test_select"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE test_select(id tinyint, id1 int, " + " id2 float, id3 float, " + " name varchar(50))"); + check_mysql_rc(rc, mysql); + + /* insert a row and commit the transaction */ + rc= mysql_query(mysql, "INSERT INTO test_select(id, id1, id2, name) VALUES(10, 5, 2.3, 'venu')"); + check_mysql_rc(rc, mysql); + + rc= mysql_commit(mysql); + check_mysql_rc(rc, mysql); + + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL("SELECT * FROM test_select")); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc= 0; + while (!mysql_stmt_fetch(stmt)) + rc++; + FAIL_UNLESS(rc == 1, "rowcount != 1"); + mysql_stmt_close(stmt); + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_select"); + check_mysql_rc(rc, mysql); + return OK; +} + +/* Test simple show */ + +static int test_select_show_table(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + int rc, i; + + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL("SHOW TABLES FROM mysql")); + check_stmt_rc(rc, stmt); + + FAIL_IF(mysql_stmt_param_count(stmt), "param_count != 0"); + + for (i= 1; i < 3; i++) + { + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + } + + while (!mysql_stmt_fetch(stmt)); + mysql_stmt_close(stmt); + return OK; +} + +/* Test simple select */ + +static int test_select_version(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + int rc; + + + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL("SELECT @@version")); + check_stmt_rc(rc, stmt); + + FAIL_IF(mysql_stmt_param_count(stmt), "param_count != 0"); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + while (!mysql_stmt_fetch(stmt)); + mysql_stmt_close(stmt); + return OK; +} + +static int test_selecttmp(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + int rc, i; + const char *query= "select a, (select count(distinct t1.b) as sum from t1, t2 where t1.a=t2.a and t2.b > 0 and t1.a <= t3.b group by t1.a order by sum limit 1) from t3"; + + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1, t2, t3"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE t1 (a int , b int);"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "create table t2 (a int, b int);"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "create table t3 (a int, b int);"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, + "insert into t1 values (0, 100), (1, 2), (1, 3), (2, 2), (2, 7), \ +(2, -1), (3, 10);"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, + "insert into t2 values (0, 0), (1, 1), (2, 1), (3, 1), (4, 1);"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, + "insert into t3 values (3, 3), (2, 2), (1, 1);"); + check_mysql_rc(rc, mysql); + + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + for (i= 0; i < 3; i++) + { + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + rc= 0; + while (!mysql_stmt_fetch(stmt)) + rc++; + FAIL_UNLESS(rc == 3, "rowcount != 3"); + } + mysql_stmt_close(stmt); + + rc= mysql_query(mysql, "DROP TABLE t1, t2, t3"); + check_mysql_rc(rc, mysql); + return OK; +} + +static int test_set_option(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + MYSQL_RES *result; + int rc; + + + mysql_autocommit(mysql, TRUE); + + /* LIMIT the rows count to 2 */ + rc= mysql_query(mysql, "SET SQL_SELECT_LIMIT= 2"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_limit"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE test_limit(a tinyint)"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "INSERT INTO test_limit VALUES(10), (20), (30), (40)"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "SELECT * FROM test_limit"); + check_mysql_rc(rc, mysql); + + result= mysql_store_result(mysql); + FAIL_IF(!result, "Invalid result set"); + + rc= 0; + while (mysql_fetch_row(result)) + rc++; + FAIL_UNLESS(rc == 2, "rowcunt != 2"); + mysql_free_result(result); + + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL("SELECT * FROM test_limit")); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc= 0; + while (!mysql_stmt_fetch(stmt)) + rc++; + FAIL_UNLESS(rc == 2, ""); + + mysql_stmt_close(stmt); + + /* RESET the LIMIT the rows count to 0 */ + rc= mysql_query(mysql, "SET SQL_SELECT_LIMIT=DEFAULT"); + check_mysql_rc(rc, mysql); + + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL("SELECT * FROM test_limit")); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc= 0; + while (!mysql_stmt_fetch(stmt)) + rc++; + FAIL_UNLESS(rc == 4, "rowcount != 4"); + + mysql_stmt_close(stmt); + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_limit"); + check_mysql_rc(rc, mysql); + return OK; +} + +/* Test simple set-variable prepare */ + +static int test_set_variable(MYSQL *mysql) +{ + MYSQL_STMT *stmt, *stmt1; + int rc; + int set_count, def_count, get_count; + ulong length; + char var[NAME_LEN+1]; + MYSQL_BIND set_bind[1], get_bind[2]; + + + mysql_autocommit(mysql, TRUE); + + stmt1= mysql_stmt_init(mysql); + FAIL_IF(!stmt1, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt1, SL("show variables like 'max_error_count'")); + check_stmt_rc(rc, stmt1); + + memset(get_bind, '\0', sizeof(get_bind)); + + get_bind[0].buffer_type= MYSQL_TYPE_STRING; + get_bind[0].buffer= (void *)var; + get_bind[0].length= &length; + get_bind[0].buffer_length= (int)NAME_LEN; + length= NAME_LEN; + + get_bind[1].buffer_type= MYSQL_TYPE_LONG; + get_bind[1].buffer= (void *)&get_count; + + rc= mysql_stmt_execute(stmt1); + check_stmt_rc(rc, stmt1); + + rc= mysql_stmt_bind_result(stmt1, get_bind); + check_stmt_rc(rc, stmt1); + + rc= mysql_stmt_fetch(stmt1); + check_stmt_rc(rc, stmt1); + + def_count= get_count; + + FAIL_UNLESS(strcmp(var, "max_error_count") == 0, "var != max_error_count"); + rc= mysql_stmt_fetch(stmt1); + FAIL_UNLESS(rc == MYSQL_NO_DATA, "rc != MYSQL_NO_DATA"); + + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL("set max_error_count=?")); + check_stmt_rc(rc, stmt); + + memset(set_bind, '\0', sizeof(set_bind)); + + set_bind[0].buffer_type= MYSQL_TYPE_LONG; + set_bind[0].buffer= (void *)&set_count; + + rc= mysql_stmt_bind_param(stmt, set_bind); + check_stmt_rc(rc, stmt); + + set_count= 31; + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + mysql_commit(mysql); + + rc= mysql_stmt_execute(stmt1); + check_stmt_rc(rc, stmt1); + + rc= mysql_stmt_fetch(stmt1); + check_stmt_rc(rc, stmt1); + + FAIL_UNLESS(get_count == set_count, "get_count != set_count"); + + rc= mysql_stmt_fetch(stmt1); + FAIL_UNLESS(rc == MYSQL_NO_DATA, "rc != MYSQL_NO_DATA"); + + /* restore back to default */ + set_count= def_count; + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt1); + check_stmt_rc(rc, stmt1); + + rc= mysql_stmt_fetch(stmt1); + check_stmt_rc(rc, stmt1); + + FAIL_UNLESS(get_count == set_count, "get_count != set_count"); + + rc= mysql_stmt_fetch(stmt1); + FAIL_UNLESS(rc == MYSQL_NO_DATA, "rc != MYSQL_NO_DATA"); + + mysql_stmt_close(stmt); + mysql_stmt_close(stmt1); + return OK; +} + +/* Test SQLmode */ + +static int test_sqlmode(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + MYSQL_BIND my_bind[2]; + char c1[5], c2[5]; + int rc; + int ignore_space= 0; + char query[MAX_TEST_QUERY_LENGTH]; + + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_piping"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE test_piping(name varchar(10))"); + check_mysql_rc(rc, mysql); + + /* PIPES_AS_CONCAT */ + strcpy(query, "SET SQL_MODE= \"PIPES_AS_CONCAT\""); + rc= mysql_query(mysql, query); + check_mysql_rc(rc, mysql); + + strcpy(query, "INSERT INTO test_piping VALUES(?||?)"); + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + memset(my_bind, '\0', sizeof(my_bind)); + + my_bind[0].buffer_type= MYSQL_TYPE_STRING; + my_bind[0].buffer= (void *)c1; + my_bind[0].buffer_length= 2; + + my_bind[1].buffer_type= MYSQL_TYPE_STRING; + my_bind[1].buffer= (void *)c2; + my_bind[1].buffer_length= 3; + + rc= mysql_stmt_bind_param(stmt, my_bind); + check_stmt_rc(rc, stmt); + + strcpy(c1, "My"); strcpy(c2, "SQL"); + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + mysql_stmt_close(stmt); + + if (verify_col_data(mysql, "test_piping", "name", "MySQL")) + return FAIL; + + rc= mysql_query(mysql, "DELETE FROM test_piping"); + check_mysql_rc(rc, mysql); + + strcpy(query, "SELECT connection_id ()"); + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + mysql_stmt_close(stmt); + + /* ANSI */ + strcpy(query, "SET SQL_MODE= \"ANSI\""); + rc= mysql_query(mysql, query); + check_mysql_rc(rc, mysql); + + strcpy(query, "INSERT INTO test_piping VALUES(?||?)"); + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_bind_param(stmt, my_bind); + check_stmt_rc(rc, stmt); + + strcpy(c1, "My"); strcpy(c2, "SQL"); + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + mysql_stmt_close(stmt); + if (verify_col_data(mysql, "test_piping", "name", "MySQL")) + return FAIL; + + /* ANSI mode spaces ... + skip, if ignore_space was set + */ + query_int_variable(mysql, "@@sql_mode LIKE '%IGNORE_SPACE%'", &ignore_space); + + if (!ignore_space) + { + strcpy(query, "SELECT connection_id ()"); + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_fetch(stmt); + FAIL_UNLESS(rc == MYSQL_NO_DATA, "rc != MYSQL_NO_DATA"); + + mysql_stmt_close(stmt); + } + /* IGNORE SPACE MODE */ + strcpy(query, "SET SQL_MODE= \"IGNORE_SPACE\""); + rc= mysql_query(mysql, query); + check_mysql_rc(rc, mysql); + + strcpy(query, "SELECT connection_id ()"); + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_fetch(stmt); + FAIL_UNLESS(rc == MYSQL_NO_DATA, "rc != MYSQL_NO_DATA"); + + mysql_stmt_close(stmt); + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_piping"); + check_mysql_rc(rc, mysql); + return OK; +} + +/* Test mysql_stmt_close for open stmts */ + +static int test_stmt_close(MYSQL *mysql) +{ + MYSQL_STMT *stmt1, *stmt2, *stmt3, *stmt_x; + MYSQL_BIND my_bind[1]; + MYSQL_RES *result; + unsigned int count; + int rc; + char query[MAX_TEST_QUERY_LENGTH]; + my_bool reconnect= 1; + + mysql_options(mysql, MYSQL_OPT_RECONNECT, &reconnect); + + /* set AUTOCOMMIT to ON*/ + mysql_autocommit(mysql, TRUE); + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_stmt_close"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE test_stmt_close(id int)"); + check_mysql_rc(rc, mysql); + + strcpy(query, "DO \"nothing\""); + stmt1= mysql_stmt_init(mysql); + FAIL_IF(!stmt1, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt1, SL(query)); + check_stmt_rc(rc, stmt1); + + FAIL_IF(mysql_stmt_param_count(stmt1), "param_count != 0"); + + strcpy(query, "INSERT INTO test_stmt_close(id) VALUES(?)"); + stmt_x= mysql_stmt_init(mysql); + FAIL_IF(!stmt_x, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt_x, SL(query)); + check_stmt_rc(rc, stmt_x); + + FAIL_IF(mysql_stmt_param_count(stmt_x) != 1, "param_count != 1"); + + strcpy(query, "UPDATE test_stmt_close SET id= ? WHERE id= ?"); + stmt3= mysql_stmt_init(mysql); + FAIL_IF(!stmt3, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt3, SL(query)); + check_stmt_rc(rc, stmt3); + + FAIL_IF(mysql_stmt_param_count(stmt3) != 2, "param_count != 2"); + + strcpy(query, "SELECT * FROM test_stmt_close WHERE id= ?"); + stmt2= mysql_stmt_init(mysql); + FAIL_IF(!stmt2, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt2, SL(query)); + check_stmt_rc(rc, stmt2); + + FAIL_IF(mysql_stmt_param_count(stmt2) != 1, "param_count != 1"); + + rc= mysql_stmt_close(stmt1); + + /* + Originally we were going to close all statements automatically in + mysql_close(). This proved to not work well - users weren't able to + close statements by hand once mysql_close() had been called. + Now mysql_close() doesn't free any statements, so this test doesn't + serve its original designation any more. + Here we free stmt2 and stmt3 by hand to avoid memory leaks. + */ + mysql_stmt_close(stmt2); + mysql_stmt_close(stmt3); + + /* + We need to bzero bind structure because mysql_stmt_bind_param checks all + its members. + */ + memset(my_bind, '\0', sizeof(my_bind)); + + my_bind[0].buffer= (void *)&count; + my_bind[0].buffer_type= MYSQL_TYPE_LONG; + count= 100; + + rc= mysql_stmt_bind_param(stmt_x, my_bind); + check_stmt_rc(rc, stmt_x); + + rc= mysql_stmt_execute(stmt_x); + check_stmt_rc(rc, stmt_x); + + FAIL_IF(mysql_stmt_affected_rows(stmt_x) != 1, "affected_rows != 1"); + + rc= mysql_stmt_close(stmt_x); + check_stmt_rc(rc, stmt_x); + + rc= mysql_query(mysql, "SELECT id FROM test_stmt_close"); + check_mysql_rc(rc, mysql); + + result= mysql_store_result(mysql); + FAIL_IF(!result, "Invalid result set"); + + rc= 0; + while (mysql_fetch_row(result)) + rc++; + FAIL_UNLESS(rc == 1, "rwcount != 1"); + mysql_free_result(result); + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_stmt_close"); + check_mysql_rc(rc, mysql); + return OK; +} + +static int test_new_date(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + MYSQL_BIND bind[1]; + int rc; + char buffer[50]; + my_bool reconnect= 1; + mysql_options(mysql, MYSQL_OPT_RECONNECT, &reconnect); + + /* set AUTOCOMMIT to ON*/ + mysql_autocommit(mysql, TRUE); + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE t1 (a date, b date)"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "INSERT INTO t1 VALUES (now(), now() + INTERVAL 1 day)"); + check_mysql_rc(rc, mysql); + + stmt= mysql_stmt_init(mysql); + rc= mysql_stmt_prepare(stmt, "SELECT if(1, a, b) FROM t1", 26); + check_stmt_rc(rc, stmt); + + memset(bind, 0, sizeof(MYSQL_BIND)); + bind[0].buffer_length= 50; + bind[0].buffer= (void *)buffer; + bind[0].buffer_type= MYSQL_TYPE_STRING; + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_bind_result(stmt, bind); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_fetch(stmt); + FAIL_IF(rc != MYSQL_NO_DATA, "NO DATA expected"); + + mysql_stmt_close(stmt); + rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1"); + check_mysql_rc(rc, mysql); + return OK; +} + +static int test_long_data1(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + int rc; + MYSQL_BIND bind[1]; + char query[MAX_TEST_QUERY_LENGTH]; + const char *data= "12345"; + + rc= mysql_autocommit(mysql, TRUE); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS tld"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE tld (col1 int, " + "col2 long varbinary)"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "INSERT INTO tld VALUES (1,'test')"); + check_mysql_rc(rc, mysql); + + strcpy(query, "UPDATE tld SET col2=? WHERE col1=1"); + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + memset(bind, 0, sizeof(MYSQL_BIND)); + bind[0].buffer_type= MYSQL_TYPE_STRING; + rc= mysql_stmt_bind_param(stmt, bind); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_send_long_data(stmt, 0, data, 6); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_close(stmt); + check_stmt_rc(rc, stmt); + rc= mysql_query(mysql, "DROP TABLE IF EXISTS tld"); + check_mysql_rc(rc, mysql); + return OK; +} + +int test_blob_9000(MYSQL *mysql) +{ + MYSQL_BIND bind[1]; + MYSQL_STMT *stmt; + int rc; + char buffer[9200]; + const char *query= "INSERT INTO tb9000 VALUES (?)"; + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS tb9000"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "CREATE TABLE tb9000 (a blob)"); + check_mysql_rc(rc, mysql); + + stmt= mysql_stmt_init(mysql); + rc= mysql_stmt_prepare(stmt, SL(query)); + + memset(bind, 0, sizeof(MYSQL_BIND)); + memset(buffer, 'C', 9200); + bind[0].buffer= buffer; + bind[0].buffer_length= 9200; + bind[0].buffer_type= MYSQL_TYPE_STRING; + rc= mysql_stmt_bind_param(stmt, bind); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + mysql_stmt_close(stmt); + rc= mysql_query(mysql, "DROP TABLE IF EXISTS tb9000"); + check_mysql_rc(rc, mysql); + return OK; +} + +int test_fracseconds(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + int rc; + const char *str= "SELECT NOW(6)"; + char buffer[60], buffer1[60]; + MYSQL_BIND bind[2]; + + stmt= mysql_stmt_init(mysql); + rc= mysql_stmt_prepare(stmt, SL(str)); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + memset(&bind, 0, sizeof(MYSQL_BIND)); + bind[0].buffer= buffer; + bind[0].buffer_length=60; + bind[0].buffer_type= MYSQL_TYPE_STRING; + + rc= mysql_stmt_bind_result(stmt, bind); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + + FAIL_IF(strlen(buffer) != 26, "Expected timestamp with length of 26"); + + rc= mysql_stmt_close(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE t1 (a timestamp(6), b time(6))"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "INSERT INTO t1 VALUES ('2012-04-25 10:20:49.0194','10:20:49.0194' )"); + check_mysql_rc(rc, mysql); + + stmt= mysql_stmt_init(mysql); + rc= mysql_stmt_prepare(stmt, "SELECT a,b FROM t1", 18); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + memset(bind, 0, 2 * sizeof(MYSQL_BIND)); + bind[0].buffer= buffer; + bind[1].buffer= buffer1; + bind[0].buffer_length= bind[1].buffer_length= 60; + bind[0].buffer_type= bind[1].buffer_type= MYSQL_TYPE_STRING; + + rc= mysql_stmt_bind_result(stmt, bind); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + FAIL_IF(strcmp(buffer, "2012-04-25 10:20:49.019400") != 0, "Wrong result"); + FAIL_IF(strcmp(buffer1, "10:20:49.019400") != 0, "Wrong result"); + + rc= mysql_stmt_close(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_query(mysql, "DROP TABLE t1"); + + return OK; +} + +int test_notrunc(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + my_bool trunc= 1; + MYSQL_BIND bind[2]; + char buffer[5], buffer2[5]; + int rc; + my_bool error= 0; + unsigned long len= 1; + + const char *query= "SELECT '1234567890', 'foo' FROM DUAL"; + + mysql_options(mysql, MYSQL_REPORT_DATA_TRUNCATION, &trunc); + + stmt= mysql_stmt_init(mysql); + + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + strcpy(buffer, "bar"); + + memset(bind, 0, sizeof(MYSQL_BIND) * 2); + bind[0].buffer_type= MYSQL_TYPE_NULL; + bind[0].buffer= buffer; + bind[0].buffer_length= 1; + bind[0].length= &len; + bind[0].flags|= MADB_BIND_DUMMY; + bind[0].error= &error; + bind[1].buffer_type= MYSQL_TYPE_STRING; + bind[1].buffer= buffer2; + bind[1].buffer_length= 5; + + rc= mysql_stmt_bind_result(stmt, bind); + check_stmt_rc(rc, stmt); + mysql_stmt_store_result(stmt); + + rc= mysql_stmt_fetch(stmt); + mysql_stmt_close(stmt); + + FAIL_IF(rc!= 0, "expected rc= 0"); + FAIL_IF(strcmp(buffer, "bar"), "Bind dummy failed"); + FAIL_IF(strcmp(buffer2, "foo"), "Invalid second buffer"); + + return OK; +} + +static int test_bit2tiny(MYSQL *mysql) +{ + MYSQL_BIND bind[2]; + char data[11]; + unsigned long length[2]; + my_bool is_null[2], error[2]; + const char *query = "SELECT val FROM justbit"; + MYSQL_STMT *stmt; + int rc; + + mysql_query(mysql, "DROP TABLE IF EXISTS justbit"); + mysql_query(mysql, "CREATE TABLE justbit(val bit(1) not null)"); + mysql_query(mysql, "INSERT INTO justbit values (1)"); + + stmt= mysql_stmt_init(mysql); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + memset(bind, '\0', sizeof(bind)); + + bind[0].buffer_type= MYSQL_TYPE_TINY; + bind[0].buffer= &data[0]; + bind[0].buffer_length= 1; + bind[0].is_null= &is_null[0]; + bind[0].length= &length[0]; + bind[0].error= &error[0]; + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_bind_result(stmt, bind); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_store_result(stmt); + check_stmt_rc(rc, stmt); + + mysql_stmt_fetch(stmt); + + FAIL_IF(data[0] != 1, "Value should be 1"); + + mysql_stmt_free_result(stmt); + mysql_stmt_close(stmt); + rc= mysql_query(mysql, "DROP TABLE IF EXISTS justbit"); + check_mysql_rc(rc, mysql); + return OK; +} + +static int test_reexecute(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + MYSQL_BIND ps_params[3]; /* input parameter buffers */ + int int_data[3]; /* input/output values */ + int rc; + + if (!mariadb_connection(mysql)) + return SKIP; + + /* set up stored procedure */ + rc = mysql_query(mysql, "DROP PROCEDURE IF EXISTS p1"); + check_mysql_rc(rc, mysql); + + rc = mysql_query(mysql, + "CREATE PROCEDURE p1(" + " IN p_in INT, " + " OUT p_out INT, " + " INOUT p_inout INT) " + "BEGIN " + " SELECT p_in, p_out, p_inout; " + " SET p_in = 100, p_out = 200, p_inout = 300; " + " SELECT p_in, p_out, p_inout; " + "END"); + check_mysql_rc(rc, mysql); + + /* initialize and prepare CALL statement with parameter placeholders */ + stmt = mysql_stmt_init(mysql); + if (!stmt) + { + diag("Could not initialize statement"); + exit(1); + } + rc = mysql_stmt_prepare(stmt, "CALL p1(?, ?, ?)", 16); + check_stmt_rc(rc, stmt); + + /* initialize parameters: p_in, p_out, p_inout (all INT) */ + memset(ps_params, 0, sizeof (ps_params)); + + ps_params[0].buffer_type = MYSQL_TYPE_LONG; + ps_params[0].buffer = (char *) &int_data[0]; + ps_params[0].length = 0; + ps_params[0].is_null = 0; + + ps_params[1].buffer_type = MYSQL_TYPE_LONG; + ps_params[1].buffer = (char *) &int_data[1]; + ps_params[1].length = 0; + ps_params[1].is_null = 0; + + ps_params[2].buffer_type = MYSQL_TYPE_LONG; + ps_params[2].buffer = (char *) &int_data[2]; + ps_params[2].length = 0; + ps_params[2].is_null = 0; + + /* bind parameters */ + rc = mysql_stmt_bind_param(stmt, ps_params); + check_stmt_rc(rc, stmt); + + /* assign values to parameters and execute statement */ + int_data[0]= 10; /* p_in */ + int_data[1]= 20; /* p_out */ + int_data[2]= 30; /* p_inout */ + + rc = mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + mysql_stmt_close(stmt); + + rc = mysql_query(mysql, "DROP PROCEDURE IF EXISTS p1"); + check_mysql_rc(rc, mysql); + return OK; +} + +static int test_prepare_error(MYSQL *mysql) +{ + MYSQL_STMT *stmt= mysql_stmt_init(mysql); + int rc; + + rc= mysql_stmt_prepare(stmt, SL("SELECT 1 FROM tbl_not_exists")); + FAIL_IF(!rc, "Expected error"); + + rc= mysql_stmt_reset(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_prepare(stmt, SL("SELECT 1 FROM tbl_not_exists")); + FAIL_IF(!rc, "Expected error"); + + rc= mysql_stmt_reset(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_prepare(stmt, SL("SET @a:=1")); + check_stmt_rc(rc, stmt); + + mysql_stmt_close(stmt); + return OK; +} + +static int test_conc349(MYSQL *mysql) +{ + MYSQL_STMT *stmt= mysql_stmt_init(mysql); + int rc; + enum mysql_stmt_state state; + + rc= mysql_stmt_attr_get(stmt, STMT_ATTR_STATE, &state); + FAIL_IF(state != MYSQL_STMT_INITTED, "expected status MYSQL_STMT_INITTED"); + + rc= mysql_stmt_prepare(stmt, SL("SET @a:=1")); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_attr_get(stmt, STMT_ATTR_STATE, &state); + FAIL_IF(state != MYSQL_STMT_PREPARED, "expected status MYSQL_STMT_PREPARED"); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_attr_get(stmt, STMT_ATTR_STATE, &state); + FAIL_IF(state != MYSQL_STMT_EXECUTED, "expected status MYSQL_STMT_EXECUTED"); + + mysql_stmt_close(stmt); + return OK; +} + +struct my_tests_st my_tests[] = { + {"test_conc349", test_conc349, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_prepare_error", test_prepare_error, TEST_CONNECTION_NEW, 0, NULL, NULL}, + {"test_reexecute", test_reexecute, TEST_CONNECTION_NEW, 0, NULL, NULL}, + {"test_bit2tiny", test_bit2tiny, TEST_CONNECTION_NEW, 0, NULL, NULL}, + {"test_conc97", test_conc97, TEST_CONNECTION_NEW, 0, NULL, NULL}, + {"test_conc83", test_conc83, TEST_CONNECTION_NONE, 0, NULL, NULL}, + {"test_conc60", test_conc60, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_notrunc", test_notrunc, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_fracseconds", test_fracseconds, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_blob_9000", test_blob_9000, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_long_data1", test_long_data1, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_prepare_insert_update", test_prepare_insert_update, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_prepare_simple", test_prepare_simple, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_prepare_syntax", test_prepare_syntax, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_prepare_field_result", test_prepare_field_result, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_prepare", test_prepare, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_prepare_ext", test_prepare_ext, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_prepare_multi_statements", test_prepare_multi_statements, TEST_CONNECTION_NEW, 0, NULL , NULL}, + {"test_prepare_alter", test_prepare_alter, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_prepare_resultset", test_prepare_resultset, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_open_direct", test_open_direct, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_select_show", test_select_show, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_select", test_select, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_long_data", test_long_data, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_long_data_str", test_long_data_str, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_long_data_str1", test_long_data_str1, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_long_data_bin", test_long_data_bin, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_simple_update", test_simple_update, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_simple_delete", test_simple_delete, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_update", test_update, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_prepare_noparam", test_prepare_noparam, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_bind_result", test_bind_result, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_bind_result_ext", test_bind_result_ext, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_bind_result_ext1", test_bind_result_ext1, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_bind_negative", test_bind_negative, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_buffers", test_buffers, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_xjoin", test_xjoin, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_union", test_union, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_union2", test_union2, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_union_param", test_union_param, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_pure_coverage", test_pure_coverage, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_insert_select", test_insert_select, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_insert", test_insert, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_join", test_join, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_left_join_view", test_left_join_view, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_manual_sample", test_manual_sample, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_create_drop", test_create_drop, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_date", test_date, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_date_ts", test_date_ts, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_date_dt", test_date_dt, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_date_date", test_date_date, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_date_time", test_date_time, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_datetime_ranges", test_datetime_ranges, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_derived", test_derived, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_distinct", test_distinct, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_do_set", test_do_set, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_double_compare", test_double_compare, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_multi", test_multi, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_multi_stmt", test_multi_stmt, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_nstmts", test_nstmts, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_null", test_null, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_order_param", test_order_param, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_rename", test_rename, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_rewind", test_rewind, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_select_prepare", test_select_prepare, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_select_show_table", test_select_show_table, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_select_version", test_select_version, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_selecttmp", test_selecttmp, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_set_option", test_set_option, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_set_variable", test_set_variable, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_sqlmode", test_sqlmode, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_stmt_close", test_stmt_close, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_new_date", test_new_date, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {NULL, NULL, 0, 0, NULL, NULL} +}; + +int main(int argc, char **argv) +{ + if (argc > 1) + get_options(argc, argv); + + get_envvars(); + + run_tests(my_tests); + + return(exit_status()); +} diff --git a/vendor/MDBC/unittest/libmariadb/ps_bugs.c b/vendor/MDBC/unittest/libmariadb/ps_bugs.c new file mode 100644 index 00000000..e7faa064 --- /dev/null +++ b/vendor/MDBC/unittest/libmariadb/ps_bugs.c @@ -0,0 +1,5484 @@ +/* +Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. + +The MySQL Connector/C is licensed under the terms of the GPLv2 +, like most +MySQL Connectors. There are special exceptions to the terms and +conditions of the GPLv2 as it is applied to this software, see the +FLOSS License Exception +. + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published +by the Free Software Foundation; version 2 of the License. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ +#include "my_test.h" + +#define MY_INT64_NUM_DECIMAL_DIGITS 21 +#define MAX_INDEXES 64 + +/* A workaround for Sun Forte 5.6 on Solaris x86 */ + +static int cmp_double(double *a, double *b) +{ + return *a == *b; + return OK; +} + +/* Test BUG#1115 (incorrect string parameter value allocation) */ + +static int test_conc67(MYSQL *mysql) +{ + MYSQL_STMT *stmt= mysql_stmt_init(mysql); + const char *query= "SELECT a,b FROM conc67 WHERE a=?"; + int rc, i; + MYSQL_BIND bind[2]; + char val[20]; + MYSQL_BIND rbind; + MYSQL_RES *res; + ulong prefetch_rows= 1000; + ulong cursor_type= CURSOR_TYPE_READ_ONLY; + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS conc67"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE conc67 (a int, b text)"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "INSERT INTO conc67 VALUES (1, 'foo')"); + check_mysql_rc(rc, mysql); + + rc= mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, &cursor_type); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_attr_set(stmt, STMT_ATTR_PREFETCH_ROWS, &prefetch_rows); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + memset(&rbind, 0, sizeof(MYSQL_BIND)); + i= 1; + rbind.buffer_type= MYSQL_TYPE_LONG; + rbind.buffer= &i; + rbind.buffer_length= 4; + mysql_stmt_bind_param(stmt, &rbind); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + res= mysql_stmt_result_metadata(stmt); + mysql_free_result(res); + + memset(bind, 0, 2 * sizeof(MYSQL_BIND)); + + i= 0; + bind[0].buffer_type= MYSQL_TYPE_LONG; + bind[0].buffer= &i; + bind[0].buffer_length= 4; + bind[1].buffer_type= MYSQL_TYPE_STRING; + bind[1].buffer= &val; + bind[1].buffer_length= 20; + + mysql_stmt_bind_result(stmt, bind); + + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + + FAIL_IF(i != 1, "expected value 1 for first row"); + + rc= mysql_stmt_fetch(stmt); + FAIL_IF(rc != MYSQL_NO_DATA, "Eof expected"); + + mysql_stmt_close(stmt); + rc= mysql_query(mysql, "DROP TABLE IF EXISTS conc67"); + check_mysql_rc(rc, mysql); + return OK; +} + +static int test_bug1115(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + int rc, rowcount; + MYSQL_BIND my_bind[1]; + ulong length[1]; + char szData[11]; + char query[MAX_TEST_QUERY_LENGTH]; + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_select"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE test_select(\ +session_id char(9) NOT NULL, \ + a int(8) unsigned NOT NULL, \ + b int(5) NOT NULL, \ + c int(5) NOT NULL, \ + d datetime NOT NULL)"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "INSERT INTO test_select VALUES " + "(\"abc\", 1, 2, 3, 2003-08-30), " + "(\"abd\", 1, 2, 3, 2003-08-30), " + "(\"abf\", 1, 2, 3, 2003-08-30), " + "(\"abg\", 1, 2, 3, 2003-08-30), " + "(\"abh\", 1, 2, 3, 2003-08-30), " + "(\"abj\", 1, 2, 3, 2003-08-30), " + "(\"abk\", 1, 2, 3, 2003-08-30), " + "(\"abl\", 1, 2, 3, 2003-08-30), " + "(\"abq\", 1, 2, 3, 2003-08-30) "); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "INSERT INTO test_select VALUES " + "(\"abw\", 1, 2, 3, 2003-08-30), " + "(\"abe\", 1, 2, 3, 2003-08-30), " + "(\"abr\", 1, 2, 3, 2003-08-30), " + "(\"abt\", 1, 2, 3, 2003-08-30), " + "(\"aby\", 1, 2, 3, 2003-08-30), " + "(\"abu\", 1, 2, 3, 2003-08-30), " + "(\"abi\", 1, 2, 3, 2003-08-30), " + "(\"abo\", 1, 2, 3, 2003-08-30), " + "(\"abp\", 1, 2, 3, 2003-08-30), " + "(\"abz\", 1, 2, 3, 2003-08-30), " + "(\"abx\", 1, 2, 3, 2003-08-30)"); + check_mysql_rc(rc, mysql); + + strcpy(query, "SELECT * FROM test_select WHERE " + "CONVERT(session_id USING utf8)= ?"); + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + FAIL_IF(mysql_stmt_param_count(stmt) != 1, "Paramcount != 1"); + + memset(my_bind, '\0', sizeof(MYSQL_BIND)); + + strcpy(szData, (char *)"abc"); + my_bind[0].buffer_type= MYSQL_TYPE_STRING; + my_bind[0].buffer= (void *)szData; + my_bind[0].buffer_length= 10; + my_bind[0].length= &length[0]; + length[0]= 3; + + rc= mysql_stmt_bind_param(stmt, my_bind); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rowcount= 0; + while (mysql_stmt_fetch(stmt) != MYSQL_NO_DATA) + rowcount++; + FAIL_IF(rowcount != 1, "rowcount=%d != 1"); + + strcpy(szData, (char *)"venu"); + my_bind[0].buffer_type= MYSQL_TYPE_STRING; + my_bind[0].buffer= (void *)szData; + my_bind[0].buffer_length= 10; + my_bind[0].length= &length[0]; + length[0]= 4; + my_bind[0].is_null= 0; + + rc= mysql_stmt_bind_param(stmt, my_bind); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rowcount= 0; + while (mysql_stmt_fetch(stmt) != MYSQL_NO_DATA) + rowcount++; + FAIL_IF(rowcount != 0, "rowcount != 0"); + + strcpy(szData, (char *)"abc"); + my_bind[0].buffer_type= MYSQL_TYPE_STRING; + my_bind[0].buffer= (void *)szData; + my_bind[0].buffer_length= 10; + my_bind[0].length= &length[0]; + length[0]= 3; + my_bind[0].is_null= 0; + + rc= mysql_stmt_bind_param(stmt, my_bind); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rowcount= 0; + while (mysql_stmt_fetch(stmt) != MYSQL_NO_DATA) + rowcount++; + FAIL_IF(rowcount != 1, "rowcount != 1"); + + mysql_stmt_close(stmt); + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_select"); + check_mysql_rc(rc, mysql); + + return OK; +} +/* Test BUG#1180 (optimized away part of WHERE clause) */ + +static int test_bug1180(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + int rc, rowcount; + MYSQL_BIND my_bind[1]; + ulong length[1]; + char szData[11]; + char query[MAX_TEST_QUERY_LENGTH]; + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_select"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE test_select(session_id char(9) NOT NULL)"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "INSERT INTO test_select VALUES (\"abc\")"); + check_mysql_rc(rc, mysql); + + strcpy(query, "SELECT * FROM test_select WHERE ?= \"1111\" and " + "session_id= \"abc\""); + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + FAIL_IF(mysql_stmt_param_count(stmt) != 1, "Paramcount != 1"); + + memset(my_bind, '\0', sizeof(MYSQL_BIND)); + + strcpy(szData, (char *)"abc"); + my_bind[0].buffer_type= MYSQL_TYPE_STRING; + my_bind[0].buffer= (void *)szData; + my_bind[0].buffer_length= 10; + my_bind[0].length= &length[0]; + length[0]= 3; + my_bind[0].is_null= 0; + + rc= mysql_stmt_bind_param(stmt, my_bind); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + + rowcount= 0; + while (mysql_stmt_fetch(stmt) != MYSQL_NO_DATA) + rowcount++; + FAIL_IF(rowcount != 0, "rowcount != 0"); + + strcpy(szData, (char *)"1111"); + my_bind[0].buffer_type= MYSQL_TYPE_STRING; + my_bind[0].buffer= (void *)szData; + my_bind[0].buffer_length= 10; + my_bind[0].length= &length[0]; + length[0]= 4; + my_bind[0].is_null= 0; + + rc= mysql_stmt_bind_param(stmt, my_bind); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rowcount= 0; + while (mysql_stmt_fetch(stmt) != MYSQL_NO_DATA) + rowcount++; + FAIL_IF(rowcount != 1, "rowcount != 1"); + + strcpy(szData, (char *)"abc"); + my_bind[0].buffer_type= MYSQL_TYPE_STRING; + my_bind[0].buffer= (void *)szData; + my_bind[0].buffer_length= 10; + my_bind[0].length= &length[0]; + length[0]= 3; + my_bind[0].is_null= 0; + + rc= mysql_stmt_bind_param(stmt, my_bind); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rowcount= 0; + while (mysql_stmt_fetch(stmt) != MYSQL_NO_DATA) + rowcount++; + FAIL_IF(rowcount != 0, "rowcount != 0"); + + mysql_stmt_close(stmt); + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_select"); + check_mysql_rc(rc, mysql); + + return OK; +} + + +/* + Test BUG#1644 (Insertion of more than 3 NULL columns with parameter + binding fails) +*/ + +static int test_bug1644(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + MYSQL_RES *result; + MYSQL_ROW row; + MYSQL_BIND my_bind[4]; + int num; + my_bool isnull; + int rc, i; + char query[MAX_TEST_QUERY_LENGTH]; + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS foo_dfr"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, + "CREATE TABLE foo_dfr(col1 int, col2 int, col3 int, col4 int);"); + check_mysql_rc(rc, mysql); + + strcpy(query, "INSERT INTO foo_dfr VALUES (?, ?, ?, ? )"); + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + FAIL_IF(mysql_stmt_param_count(stmt) != 4, "Paramcount != 4"); + + memset(my_bind, '\0', sizeof(MYSQL_BIND) * 4); + + num= 22; + isnull= 0; + for (i= 0 ; i < 4 ; i++) + { + my_bind[i].buffer_type= MYSQL_TYPE_LONG; + my_bind[i].buffer= (void *)# + my_bind[i].is_null= &isnull; + } + + rc= mysql_stmt_bind_param(stmt, my_bind); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + isnull= 1; + for (i= 0 ; i < 4 ; i++) + my_bind[i].is_null= &isnull; + + rc= mysql_stmt_bind_param(stmt, my_bind); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + isnull= 0; + num= 88; + for (i= 0 ; i < 4 ; i++) + my_bind[i].is_null= &isnull; + + rc= mysql_stmt_bind_param(stmt, my_bind); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + mysql_stmt_close(stmt); + + rc= mysql_query(mysql, "SELECT * FROM foo_dfr"); + check_mysql_rc(rc, mysql); + + result= mysql_store_result(mysql); + FAIL_IF(!result, "Invalid resultset"); + + FAIL_IF(mysql_num_rows(result) != 3, "rowcount != 3"); + + mysql_data_seek(result, 0); + + row= mysql_fetch_row(result); + FAIL_IF(!row, "row = NULL"); + for (i= 0 ; i < 4 ; i++) + { + FAIL_UNLESS(strcmp(row[i], "22") == 0, "Wrong value"); + } + row= mysql_fetch_row(result); + FAIL_IF(!row, "Invalid row"); + for (i= 0 ; i < 4 ; i++) + { + FAIL_UNLESS(row[i] == 0, "row[i] != 0"); + } + row= mysql_fetch_row(result); + FAIL_IF(!row, "Invalid row"); + for (i= 0 ; i < 4 ; i++) + { + FAIL_UNLESS(strcmp(row[i], "88") == 0, "row[i] != 88"); + } + row= mysql_fetch_row(result); + FAIL_IF(row, "row != NULL"); + + mysql_free_result(result); + rc= mysql_query(mysql, "DROP TABLE IF EXISTS foo_dfr"); + check_mysql_rc(rc, mysql); + + return OK; +} + +static int test_bug11037(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + int rc; + const char *stmt_text; + + rc= mysql_query(mysql, "drop table if exists t1"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "create table t1 (id int not null)"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "insert into t1 values (1)"); + check_mysql_rc(rc, mysql); + + stmt_text= "select id FROM t1"; + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(stmt_text)); + check_stmt_rc(rc, stmt); + + /* expected error */ + rc = mysql_stmt_fetch(stmt); + FAIL_UNLESS(rc==1, "Error expedted"); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_fetch(stmt); + FAIL_UNLESS(rc==MYSQL_NO_DATA, "rc != MYSQL_NO_DATA"); + + rc= mysql_stmt_fetch(stmt); + FAIL_UNLESS(rc==MYSQL_NO_DATA, "rc != MYSQL_NO_DATA"); + + mysql_stmt_close(stmt); + rc= mysql_query(mysql, "drop table t1"); + check_mysql_rc(rc, mysql); + + return OK; +} + +/* Bug#11183 "mysql_stmt_reset() doesn't reset information about error" */ + +static int test_bug11183(MYSQL *mysql) +{ + int rc; + MYSQL_STMT *stmt; + char bug_statement[]= "insert into t1 values (1)"; + + 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); + + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + + rc= mysql_stmt_prepare(stmt, SL(bug_statement)); + check_stmt_rc(rc, stmt); + + rc= mysql_query(mysql, "drop table t1"); + check_mysql_rc(rc, mysql); + + /* Trying to execute statement that should fail on execute stage */ + rc= mysql_stmt_execute(stmt); + FAIL_IF(!rc, "Error expected"); + + mysql_stmt_reset(stmt); + FAIL_IF(mysql_stmt_errno(stmt) != 0, "stmt->error != 0"); + + rc= mysql_query(mysql, "create table t1 (a int)"); + check_mysql_rc(rc, mysql); + + /* Trying to execute statement that should pass ok */ + if (mysql_stmt_execute(stmt)) + { + mysql_stmt_reset(stmt); + FAIL_IF(mysql_stmt_errno(stmt) == 0, "stmt->error != 0"); + } + + mysql_stmt_close(stmt); + + rc= mysql_query(mysql, "drop table t1"); + check_mysql_rc(rc, mysql); + + return OK; +} + +static int test_bug12744(MYSQL *mysql) +{ + MYSQL_STMT *stmt = NULL; + int rc; + + SKIP_MAXSCALE; + + stmt = mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, "SET @a:=1", 9); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + /* set reconnect, kill and ping to reconnect */ + rc= mysql_query(mysql, "SET @a:=1"); + check_mysql_rc(rc, mysql); + rc= mysql_options(mysql, MYSQL_OPT_RECONNECT, "1"); + check_mysql_rc(rc, mysql); + rc= mysql_kill(mysql, mysql_thread_id(mysql)); + + rc= mysql_ping(mysql); + check_mysql_rc(rc, mysql); + + rc= mysql_stmt_close(stmt); + check_mysql_rc(rc, mysql); + + return OK; +} + +static int test_bug1500(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + MYSQL_BIND my_bind[3]; + int rc= 0; + int32 int_data[3]= {2, 3, 4}; + const char *data; + const char *query; + + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_bg1500"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE test_bg1500 (i INT)"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "INSERT INTO test_bg1500 VALUES (1), (2)"); + check_mysql_rc(rc, mysql); + + rc= mysql_commit(mysql); + check_mysql_rc(rc, mysql); + + query= "SELECT i FROM test_bg1500 WHERE i IN (?, ?, ?)"; + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + FAIL_IF(mysql_stmt_param_count(stmt) != 3, "paramcount != 3"); + + memset(my_bind, '\0', sizeof(my_bind)); + + my_bind[0].buffer= (void *)int_data; + my_bind[0].buffer_type= MYSQL_TYPE_LONG; + my_bind[2]= my_bind[1]= my_bind[0]; + my_bind[1].buffer= (void *)(int_data + 1); + my_bind[2].buffer= (void *)(int_data + 2); + + rc= mysql_stmt_bind_param(stmt, my_bind); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc= 0; + while (mysql_stmt_fetch(stmt) != MYSQL_NO_DATA) + rc++; + FAIL_UNLESS(rc == 1, "rowcount != 1"); + + mysql_stmt_close(stmt); + + rc= mysql_query(mysql, "DROP TABLE test_bg1500"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE test_bg1500 (s VARCHAR(25), FULLTEXT(s)) engine=MyISAM"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, + "INSERT INTO test_bg1500 VALUES ('Gravedigger'), ('Greed'), ('Hollow Dogs')"); + check_mysql_rc(rc, mysql); + + rc= mysql_commit(mysql); + check_mysql_rc(rc, mysql); + + query= "SELECT s FROM test_bg1500 WHERE MATCH (s) AGAINST (?)"; + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + FAIL_IF(mysql_stmt_param_count(stmt) != 1, "paramcount != 1"); + + data= "Dogs"; + my_bind[0].buffer_type= MYSQL_TYPE_STRING; + my_bind[0].buffer= (void *) data; + my_bind[0].buffer_length= (unsigned long)strlen(data); + my_bind[0].is_null= 0; + my_bind[0].length= 0; + + rc= mysql_stmt_bind_param(stmt, my_bind); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc= 0; + while (mysql_stmt_fetch(stmt) != MYSQL_NO_DATA) + rc++; + FAIL_UNLESS(rc == 1, "rowcount != 1"); + + mysql_stmt_close(stmt); + + /* This should work too */ + query= "SELECT s FROM test_bg1500 WHERE MATCH (s) AGAINST (CONCAT(?, 'digger'))"; + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + FAIL_IF(mysql_stmt_param_count(stmt) != 1, "paramcount != 1"); + + data= "Grave"; + my_bind[0].buffer_type= MYSQL_TYPE_STRING; + my_bind[0].buffer= (void *) data; + my_bind[0].buffer_length= (unsigned long)strlen(data); + + rc= mysql_stmt_bind_param(stmt, my_bind); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc= 0; + while (mysql_stmt_fetch(stmt) != MYSQL_NO_DATA) + rc++; + FAIL_UNLESS(rc == 1, "rowcount != 1"); + + mysql_stmt_close(stmt); + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_bg1500"); + check_mysql_rc(rc, mysql); + + return OK; +} + +static int test_bug15510(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + int rc; + const char *query= "select 1 from dual where 1/0"; + + SKIP_MYSQL(mysql); + + rc= mysql_query(mysql, "set @@sql_mode='ERROR_FOR_DIVISION_BY_ZERO'"); + check_mysql_rc(rc, mysql); + + stmt= mysql_stmt_init(mysql); + + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_fetch(stmt); + FAIL_UNLESS(mysql_warning_count(mysql), "Warning expected"); + + /* Cleanup */ + mysql_stmt_close(stmt); + rc= mysql_query(mysql, "set @@sql_mode=''"); + check_mysql_rc(rc, mysql); + + return OK; +} + +/* + Bug #15518 - Reusing a stmt that has failed during prepare + does not clear error +*/ + +static int test_bug15518(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + int rc; + + stmt= mysql_stmt_init(mysql); + + /* + The prepare of foo should fail with errno 1064 since + it's not a valid query + */ + rc= mysql_stmt_prepare(stmt, "foo", 3); + FAIL_UNLESS(rc && mysql_stmt_errno(stmt) && mysql_errno(mysql), "Error expected"); + + /* + Use the same stmt and reprepare with another query that + succeeds + */ + rc= mysql_stmt_prepare(stmt, "SHOW STATUS", 12); + FAIL_UNLESS(!rc || mysql_stmt_errno(stmt) || mysql_errno(mysql), "Error expected"); + + rc= mysql_stmt_close(stmt); + check_mysql_rc(rc, mysql); + /* + part2, when connection to server has been closed + after first prepare + */ + stmt= mysql_stmt_init(mysql); + rc= mysql_stmt_prepare(stmt, "foo", 3); + FAIL_UNLESS(rc && mysql_stmt_errno(stmt) && mysql_errno(mysql), "Error expected"); + + /* Close connection to server */ + mysql_close(mysql); + + /* + Use the same stmt and reprepare with another query that + succeeds. The prepare should fail with error 2013 since + connection to server has been closed. + */ + rc= mysql_stmt_prepare(stmt, "SHOW STATUS", 12); + FAIL_UNLESS(rc && mysql_stmt_errno(stmt), "Error expected"); + + mysql_stmt_close(stmt); + + return OK; +} + +/* + Bug #15613: "libmysqlclient API function mysql_stmt_prepare returns wrong + field length" +*/ + +static int test_bug15613(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + const char *stmt_text; + MYSQL_RES *metadata; + MYSQL_FIELD *field; + int rc; + + /* I. Prepare the table */ + rc= mysql_query(mysql, "set names latin1"); + check_mysql_rc(rc, mysql); + mysql_query(mysql, "drop table if exists t1"); + rc= mysql_query(mysql, + "create table t1 (t text character set utf8, " + "tt tinytext character set utf8, " + "mt mediumtext character set utf8, " + "lt longtext character set utf8, " + "vl varchar(255) character set latin1," + "vb varchar(255) character set binary," + "vu varchar(255) character set utf8)"); + check_mysql_rc(rc, mysql); + + stmt= mysql_stmt_init(mysql); + + /* II. Check SELECT metadata */ + stmt_text= ("select t, tt, mt, lt, vl, vb, vu from t1"); + rc= mysql_stmt_prepare(stmt, SL(stmt_text)); + metadata= mysql_stmt_result_metadata(stmt); + field= mysql_fetch_fields(metadata); + FAIL_UNLESS(field[0].length == 65535, "length != 65535"); + FAIL_UNLESS(field[1].length == 255, "length != 244"); + FAIL_UNLESS(field[2].length == 16777215, "length != 166777215"); + FAIL_UNLESS(field[3].length == 4294967295UL, "length != 4294967295UL"); + FAIL_UNLESS(field[4].length == 255, "length != 255"); + FAIL_UNLESS(field[5].length == 255, "length != 255"); + FAIL_UNLESS(field[6].length == 255, "length != 255"); + mysql_free_result(metadata); + mysql_stmt_free_result(stmt); + + /* III. Cleanup */ + rc= mysql_query(mysql, "drop table t1"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "set names default"); + check_mysql_rc(rc, mysql); + mysql_stmt_close(stmt); + + return OK; +} + +static int test_bug16144(MYSQL *mysql) +{ + const my_bool flag_orig= (my_bool) 0xde; + my_bool flag= flag_orig; + MYSQL_STMT *stmt; + + /* Check that attr_get returns correct data on little and big endian CPUs */ + stmt= mysql_stmt_init(mysql); + mysql_stmt_attr_set(stmt, STMT_ATTR_UPDATE_MAX_LENGTH, (const void*) &flag); + mysql_stmt_attr_get(stmt, STMT_ATTR_UPDATE_MAX_LENGTH, (void*) &flag); + FAIL_UNLESS(flag == flag_orig, "flag != flag_orig"); + + mysql_stmt_close(stmt); + + return OK; +} + +/* + This tests for various mysql_stmt_send_long_data bugs described in #1664 +*/ + +static int test_bug1664(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + int rc, int_data; + const char *data; + const char *str_data= "Simple string"; + MYSQL_BIND my_bind[2]; + const char *query= "INSERT INTO test_long_data(col2, col1) VALUES(?, ?)"; + + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_long_data"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE test_long_data(col1 int, col2 long varchar)"); + check_mysql_rc(rc, mysql); + + stmt= mysql_stmt_init(mysql); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + FAIL_IF(mysql_stmt_param_count(stmt) != 2, "Param count != 2"); + + memset(my_bind, '\0', sizeof(my_bind)); + + my_bind[0].buffer_type= MYSQL_TYPE_STRING; + my_bind[0].buffer= (void *)str_data; + my_bind[0].buffer_length= (unsigned long)strlen(str_data); + + my_bind[1].buffer= (void *)&int_data; + my_bind[1].buffer_type= MYSQL_TYPE_LONG; + + rc= mysql_stmt_bind_param(stmt, my_bind); + check_stmt_rc(rc, stmt); + + int_data= 1; + + /* + Let us supply empty long_data. This should work and should + not break following execution. + */ + data= ""; + rc= mysql_stmt_send_long_data(stmt, 0, SL(data)); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + if (verify_col_data(mysql, "test_long_data", "col1", "1")) + goto error; + if (verify_col_data(mysql, "test_long_data", "col2", "")) + goto error; + rc= mysql_query(mysql, "DELETE FROM test_long_data"); + check_mysql_rc(rc, mysql); + + /* This should pass OK */ + data= (char *)"Data"; + rc= mysql_stmt_send_long_data(stmt, 0, SL(data)); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + if (verify_col_data(mysql, "test_long_data", "col1", "1")) + goto error; + if (verify_col_data(mysql, "test_long_data", "col2", "Data")) + goto error; + + /* clean up */ + rc= mysql_query(mysql, "DELETE FROM test_long_data"); + check_mysql_rc(rc, mysql); + + /* + Now we are changing int parameter and don't do anything + with first parameter. Second mysql_stmt_execute() should run + OK treating this first parameter as string parameter. + */ + + int_data= 2; + /* execute */ + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + if (verify_col_data(mysql, "test_long_data", "col1", "2")) + goto error; + if (verify_col_data(mysql, "test_long_data", "col2", str_data)) + goto error; + + /* clean up */ + rc= mysql_query(mysql, "DELETE FROM test_long_data"); + check_mysql_rc(rc, mysql); + + /* + Now we are sending other long data. It should not be + concatenated to previous. + */ + + data= (char *)"SomeOtherData"; + rc= mysql_stmt_send_long_data(stmt, 0, SL(data)); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + if (verify_col_data(mysql, "test_long_data", "col1", "2")) + goto error; + if (verify_col_data(mysql, "test_long_data", "col2", "SomeOtherData")) + goto error; + + mysql_stmt_close(stmt); + + /* clean up */ + rc= mysql_query(mysql, "DELETE FROM test_long_data"); + check_mysql_rc(rc, mysql); + + /* Now let us test how mysql_stmt_reset works. */ + stmt= mysql_stmt_init(mysql); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_bind_param(stmt, my_bind); + check_stmt_rc(rc, stmt); + + data= (char *)"SomeData"; + rc= mysql_stmt_send_long_data(stmt, 0, SL(data)); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_reset(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + if (verify_col_data(mysql, "test_long_data", "col1", "2")) + goto error; + if (verify_col_data(mysql, "test_long_data", "col2", str_data)) + goto error; + + mysql_stmt_close(stmt); + + /* Final clean up */ + rc= mysql_query(mysql, "DROP TABLE test_long_data"); + check_mysql_rc(rc, mysql); + + return OK; + +error: + mysql_stmt_close(stmt); + rc= mysql_query(mysql, "DROP TABLE test_long_data"); + return FAIL; +} +/* Test a misc bug */ + +static int test_ushort_bug(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + MYSQL_BIND my_bind[4]; + ushort short_value; + uint32 long_value; + ulong s_length, l_length, ll_length, t_length; + ulonglong longlong_value; + int rc; + uchar tiny_value; + const char *query= "SELECT * FROM test_ushort"; + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_ushort"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE test_ushort(a smallint unsigned, \ + b smallint unsigned, \ + c smallint unsigned, \ + d smallint unsigned)"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, + "INSERT INTO test_ushort VALUES(35999, 35999, 35999, 200)"); + check_mysql_rc(rc, mysql); + + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + memset(my_bind, '\0', sizeof(my_bind)); + my_bind[0].buffer_type= MYSQL_TYPE_SHORT; + my_bind[0].buffer= (void *)&short_value; + my_bind[0].is_unsigned= TRUE; + my_bind[0].length= &s_length; + + my_bind[1].buffer_type= MYSQL_TYPE_LONG; + my_bind[1].buffer= (void *)&long_value; + my_bind[1].length= &l_length; + + my_bind[2].buffer_type= MYSQL_TYPE_LONGLONG; + my_bind[2].buffer= (void *)&longlong_value; + my_bind[2].length= &ll_length; + + my_bind[3].buffer_type= MYSQL_TYPE_TINY; + my_bind[3].buffer= (void *)&tiny_value; + my_bind[3].is_unsigned= TRUE; + my_bind[3].length= &t_length; + + rc= mysql_stmt_bind_result(stmt, my_bind); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + + FAIL_UNLESS(short_value == 35999, "short_value != 35999"); + FAIL_UNLESS(s_length == 2, "length != 2"); + + FAIL_UNLESS(long_value == 35999, "long_value != 35999"); + FAIL_UNLESS(l_length == 4, "length != 4"); + + FAIL_UNLESS(longlong_value == 35999, "longlong_value != 35999"); + FAIL_UNLESS(ll_length == 8, "length != 8"); + + FAIL_UNLESS(tiny_value == 200, "tiny_value != 200"); + FAIL_UNLESS(t_length == 1, "length != 1"); + + rc= mysql_stmt_fetch(stmt); + FAIL_UNLESS(rc == MYSQL_NO_DATA, "rc != MYSQL_NO_DATA"); + + mysql_stmt_close(stmt); + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_ushort"); + check_mysql_rc(rc, mysql); + + return OK; +} + +static int test_bug1946(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + int rc; + const char *query= "INSERT INTO prepare_command VALUES (?)"; + + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS prepare_command"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE prepare_command(ID INT)"); + check_mysql_rc(rc, mysql); + + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + rc= mysql_real_query(mysql, SL(query)); + FAIL_IF(!rc, "Error expected"); + + mysql_stmt_close(stmt); + rc= mysql_query(mysql, "DROP TABLE prepare_command"); + check_mysql_rc(rc, mysql); + return OK; +} + +static int test_bug20152(MYSQL *mysql) +{ + MYSQL_BIND my_bind[1]; + MYSQL_STMT *stmt; + MYSQL_TIME tm; + int rc; + const char *query= "INSERT INTO t1 (f1) VALUES (?)"; + + + memset(my_bind, '\0', sizeof(my_bind)); + my_bind[0].buffer_type= MYSQL_TYPE_DATE; + my_bind[0].buffer= (void*)&tm; + + memset(&tm, 0, sizeof(MYSQL_TIME)); + + tm.year = 2006; + tm.month = 6; + tm.day = 18; + tm.hour = 14; + tm.minute = 9; + tm.second = 42; + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "CREATE TABLE t1 (f1 DATE)"); + check_mysql_rc(rc, mysql); + + stmt= mysql_stmt_init(mysql); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_bind_param(stmt, my_bind); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_close(stmt); + check_stmt_rc(rc, stmt); + rc= mysql_query(mysql, "DROP TABLE t1"); + check_mysql_rc(rc, mysql); + FAIL_UNLESS(tm.hour == 14 && tm.minute == 9 && tm.second == 42, "time != 14:09:42"); + return OK; +} + +static int test_bug2247(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + MYSQL_RES *res; + int rc; + int i; + const char *create= "CREATE TABLE bug2247(id INT UNIQUE AUTO_INCREMENT)"; + const char *insert= "INSERT INTO bug2247 VALUES (NULL)"; + const char *SELECT= "SELECT id FROM bug2247"; + const char *update= "UPDATE bug2247 SET id=id+10"; + const char *drop= "DROP TABLE IF EXISTS bug2247"; + ulonglong exp_count; + enum { NUM_ROWS= 5 }; + + + /* create table and insert few rows */ + rc= mysql_query(mysql, drop); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, create); + check_mysql_rc(rc, mysql); + + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(insert)); + check_stmt_rc(rc, stmt); + for (i= 0; i < NUM_ROWS; ++i) + { + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + } + exp_count= mysql_stmt_affected_rows(stmt); + FAIL_UNLESS(exp_count == 1, "exp_count != 1"); + + rc= mysql_query(mysql, SELECT); + check_mysql_rc(rc, mysql); + /* + mysql_store_result overwrites mysql->affected_rows. Check that + mysql_stmt_affected_rows() returns the same value, whereas + mysql_affected_rows() value is correct. + */ + res= mysql_store_result(mysql); + FAIL_IF(!res, "Invalid result set"); + + FAIL_UNLESS(mysql_affected_rows(mysql) == NUM_ROWS, "affected_rows != NUM_ROWS"); + FAIL_UNLESS(exp_count == mysql_stmt_affected_rows(stmt), "affected_rows != exp_count"); + + rc= mysql_query(mysql, update); + check_mysql_rc(rc, mysql); + FAIL_UNLESS(mysql_affected_rows(mysql) == NUM_ROWS, "affected_rows != NUM_ROWS"); + FAIL_UNLESS(exp_count == mysql_stmt_affected_rows(stmt), "affected_rows != exp_count"); + + mysql_free_result(res); + mysql_stmt_close(stmt); + + /* check that mysql_stmt_store_result modifies mysql_stmt_affected_rows */ + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(SELECT)); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); rc= mysql_stmt_store_result(stmt); + check_stmt_rc(rc, stmt); exp_count= mysql_stmt_affected_rows(stmt); + FAIL_UNLESS(exp_count == NUM_ROWS, "exp_count != NUM_ROWS"); + + rc= mysql_query(mysql, insert); + check_mysql_rc(rc, mysql); + FAIL_UNLESS(mysql_affected_rows(mysql) == 1, "affected_rows != 1"); + FAIL_UNLESS(exp_count == mysql_stmt_affected_rows(stmt), "affected_rows != exp_count"); + + mysql_stmt_close(stmt); + rc= mysql_query(mysql, drop); + check_mysql_rc(rc, mysql); + return OK; +} + +/* + Test for bug#2248 "mysql_fetch without prior mysql_stmt_execute hangs" +*/ + +static int test_bug2248(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + int rc; + const char *query1= "SELECT DATABASE()"; + const char *query2= "INSERT INTO test_bug2248 VALUES (10)"; + + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_bug2248"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE test_bug2248 (id int)"); + check_mysql_rc(rc, mysql); + + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(query1)); + check_stmt_rc(rc, stmt); + + /* This should not hang */ + rc= mysql_stmt_fetch(stmt); + FAIL_IF(!rc, "Error expected"); + + /* And this too */ + rc= mysql_stmt_store_result(stmt); + FAIL_IF(!rc, "Error expected"); + + mysql_stmt_close(stmt); + + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(query2)); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + /* This too should not hang but should return proper error */ + rc= mysql_stmt_fetch(stmt); + FAIL_UNLESS(rc == 1, "rc != 1"); + + /* This too should not hang but should not bark */ + rc= mysql_stmt_store_result(stmt); + check_stmt_rc(rc, stmt); + /* This should return proper error */ + rc= mysql_stmt_fetch(stmt); + FAIL_UNLESS(rc == 1, "rc != 1"); + + mysql_stmt_close(stmt); + + rc= mysql_query(mysql, "DROP TABLE test_bug2248"); + check_mysql_rc(rc, mysql); + return OK; +} + +/* + BUG#23383: mysql_affected_rows() returns different values than + mysql_stmt_affected_rows() + + Test that both mysql_affected_rows() and mysql_stmt_affected_rows() + return -1 on error, 0 when no rows were affected, and (positive) row + count when some rows were affected. +*/ +static int test_bug23383(MYSQL *mysql) +{ + const char *insert_query= "INSERT INTO t1 VALUES (1), (2)"; + const char *update_query= "UPDATE t1 SET i= 4 WHERE i = 3"; + MYSQL_STMT *stmt; + unsigned long long row_count; + int rc; + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE t1 (i INT UNIQUE)"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, insert_query); + check_mysql_rc(rc, mysql); + row_count= mysql_affected_rows(mysql); + FAIL_UNLESS(row_count == 2, "row_count != 2"); + + rc= mysql_query(mysql, insert_query); + FAIL_IF(!rc, "Error expected"); + row_count= mysql_affected_rows(mysql); + FAIL_UNLESS(row_count == (unsigned long long)-1, "rowcount != -1"); + + rc= mysql_query(mysql, update_query); + check_mysql_rc(rc, mysql); + row_count= mysql_affected_rows(mysql); + FAIL_UNLESS(row_count == 0, ""); + + rc= mysql_query(mysql, "DELETE FROM t1"); + check_mysql_rc(rc, mysql); + + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + + rc= mysql_stmt_prepare(stmt, SL(insert_query)); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + row_count= mysql_stmt_affected_rows(stmt); + FAIL_UNLESS(row_count == 2, "row_count != 2"); + + rc= mysql_stmt_execute(stmt); + FAIL_UNLESS(rc != 0, ""); + row_count= mysql_stmt_affected_rows(stmt); + FAIL_UNLESS(row_count == (unsigned long long)-1, "rowcount != -1"); + + rc= mysql_stmt_prepare(stmt, SL(update_query)); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + row_count= mysql_stmt_affected_rows(stmt); + FAIL_UNLESS(row_count == 0, "rowcount != 0"); + + rc= mysql_stmt_close(stmt); + check_stmt_rc(rc, stmt); + rc= mysql_query(mysql, "DROP TABLE t1"); + check_mysql_rc(rc, mysql); + + return OK; +} + +/* + Bug#27592 (stack overrun when storing datetime value using prepared statements) +*/ + +static int test_bug27592(MYSQL *mysql) +{ + const int NUM_ITERATIONS= 40; + int i; + int rc; + MYSQL_STMT *stmt= NULL; + MYSQL_BIND bind[1]; + MYSQL_TIME time_val; + + mysql_query(mysql, "DROP TABLE IF EXISTS t1"); + mysql_query(mysql, "CREATE TABLE t1(c2 DATETIME)"); + + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL("INSERT INTO t1 VALUES (?)")); + check_stmt_rc(rc, stmt); + + memset(bind, '\0', sizeof(bind)); + + bind[0].buffer_type= MYSQL_TYPE_DATETIME; + bind[0].buffer= (char *) &time_val; + bind[0].length= NULL; + + for (i= 0; i < NUM_ITERATIONS; i++) + { + time_val.year= 2007; + time_val.month= 6; + time_val.day= 7; + time_val.hour= 18; + time_val.minute= 41; + time_val.second= 3; + + time_val.second_part=0; + time_val.neg=0; + + rc= mysql_stmt_bind_param(stmt, bind); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + } + + mysql_stmt_close(stmt); + mysql_query(mysql, "DROP TABLE IF EXISTS t1"); + + return OK; +} + +/* + Bug#28934: server crash when receiving malformed com_execute packets +*/ + +static int test_bug28934(MYSQL *mysql) +{ + my_bool error= 0; + MYSQL_BIND bind[5]; + MYSQL_STMT *stmt; + int rc, cnt; + + rc= mysql_query(mysql, "drop table if exists t1"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "create table t1(id int)"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "insert into t1 values(1),(2),(3),(4),(5)"); + check_mysql_rc(rc, mysql); + + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL("select * from t1 where id in(?,?,?,?,?)")); + check_stmt_rc(rc, stmt); + + memset (&bind, '\0', sizeof (bind)); + for (cnt= 0; cnt < 5; cnt++) + { + bind[cnt].buffer_type= MYSQL_TYPE_LONG; + bind[cnt].buffer= (char*)&cnt; + bind[cnt].buffer_length= 0; + } + rc= mysql_stmt_bind_param(stmt, bind); + check_stmt_rc(rc, stmt); + + stmt->param_count=2; + error= mysql_stmt_execute(stmt); + FAIL_UNLESS(error != 0, "Error expected"); + mysql_stmt_close(stmt); + + rc= mysql_query(mysql, "drop table t1"); + check_mysql_rc(rc, mysql); + return OK; +} + +static int test_bug3035(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + int rc; + MYSQL_BIND bind_array[12], *my_bind= bind_array, *bind_end= my_bind + 12; + int8 int8_val; + uint8 uint8_val; + int16 int16_val; + uint16 uint16_val; + int32 int32_val; + uint32 uint32_val; + longlong int64_val; + ulonglong uint64_val; + double double_val, udouble_val, double_tmp; + char longlong_as_string[22], ulonglong_as_string[22]; + + /* mins and maxes */ + const int8 int8_min= -128; + const int8 int8_max= 127; + const uint8 uint8_min= 0; + const uint8 uint8_max= 255; + + const int16 int16_min= -32768; + const int16 int16_max= 32767; + const uint16 uint16_min= 0; + const uint16 uint16_max= 65535; + + const int32 int32_max= 2147483647L; + const int32 int32_min= -int32_max - 1; + const uint32 uint32_min= 0; + const uint32 uint32_max= 4294967295U; + + /* it might not work okay everyplace */ + const longlong int64_max= 9223372036854775807LL; + const longlong int64_min= -int64_max - 1; + + const ulonglong uint64_min= 0U; + const ulonglong uint64_max= 18446744073709551615ULL; + + const char *stmt_text; + + + stmt_text= "DROP TABLE IF EXISTS t1"; + rc= mysql_real_query(mysql, SL(stmt_text)); + check_mysql_rc(rc, mysql); + + stmt_text= "CREATE TABLE t1 (i8 TINYINT, ui8 TINYINT UNSIGNED, " + "i16 SMALLINT, ui16 SMALLINT UNSIGNED, " + "i32 INT, ui32 INT UNSIGNED, " + "i64 BIGINT, ui64 BIGINT UNSIGNED, " + "id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT)"; + rc= mysql_real_query(mysql, SL(stmt_text)); + check_mysql_rc(rc, mysql); + + memset(bind_array, '\0', sizeof(bind_array)); + for (my_bind= bind_array; my_bind < bind_end; my_bind++) + my_bind->error= &my_bind->error_value; + + bind_array[0].buffer_type= MYSQL_TYPE_TINY; + bind_array[0].buffer= (void *) &int8_val; + + bind_array[1].buffer_type= MYSQL_TYPE_TINY; + bind_array[1].buffer= (void *) &uint8_val; + bind_array[1].is_unsigned= 1; + + bind_array[2].buffer_type= MYSQL_TYPE_SHORT; + bind_array[2].buffer= (void *) &int16_val; + + bind_array[3].buffer_type= MYSQL_TYPE_SHORT; + bind_array[3].buffer= (void *) &uint16_val; + bind_array[3].is_unsigned= 1; + + bind_array[4].buffer_type= MYSQL_TYPE_LONG; + bind_array[4].buffer= (void *) &int32_val; + + bind_array[5].buffer_type= MYSQL_TYPE_LONG; + bind_array[5].buffer= (void *) &uint32_val; + bind_array[5].is_unsigned= 1; + + bind_array[6].buffer_type= MYSQL_TYPE_LONGLONG; + bind_array[6].buffer= (void *) &int64_val; + + bind_array[7].buffer_type= MYSQL_TYPE_LONGLONG; + bind_array[7].buffer= (void *) &uint64_val; + bind_array[7].is_unsigned= 1; + + stmt= mysql_stmt_init(mysql); + check_stmt_rc(rc, stmt); + + stmt_text= "INSERT INTO t1 (i8, ui8, i16, ui16, i32, ui32, i64, ui64) " + "VALUES (?, ?, ?, ?, ?, ?, ?, ?)"; + rc= mysql_stmt_prepare(stmt, SL(stmt_text)); + check_stmt_rc(rc, stmt); + mysql_stmt_bind_param(stmt, bind_array); + + int8_val= int8_min; + uint8_val= uint8_min; + int16_val= int16_min; + uint16_val= uint16_min; + int32_val= int32_min; + uint32_val= uint32_min; + int64_val= int64_min; + uint64_val= uint64_min; + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + int8_val= int8_max; + uint8_val= uint8_max; + int16_val= int16_max; + uint16_val= uint16_max; + int32_val= int32_max; + uint32_val= uint32_max; + int64_val= int64_max; + uint64_val= uint64_max; + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + stmt_text= "SELECT i8, ui8, i16, ui16, i32, ui32, i64, ui64, ui64, " + "cast(ui64 as signed), ui64, cast(ui64 as signed)" + "FROM t1 ORDER BY id ASC"; + + rc= mysql_stmt_prepare(stmt, SL(stmt_text)); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + bind_array[8].buffer_type= MYSQL_TYPE_DOUBLE; + bind_array[8].buffer= (void *) &udouble_val; + + bind_array[9].buffer_type= MYSQL_TYPE_DOUBLE; + bind_array[9].buffer= (void *) &double_val; + + bind_array[10].buffer_type= MYSQL_TYPE_STRING; + bind_array[10].buffer= (void *) &ulonglong_as_string; + bind_array[10].buffer_length= sizeof(ulonglong_as_string); + + bind_array[11].buffer_type= MYSQL_TYPE_STRING; + bind_array[11].buffer= (void *) &longlong_as_string; + bind_array[11].buffer_length= sizeof(longlong_as_string); + + mysql_stmt_bind_result(stmt, bind_array); + + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + FAIL_UNLESS(int8_val == int8_min, "int8_val != int8_min"); + FAIL_UNLESS(uint8_val == uint8_min, "uint8_val != uint8_min"); + FAIL_UNLESS(int16_val == int16_min, "int16_val != int16_min"); + FAIL_UNLESS(uint16_val == uint16_min, "uint16_val != uint16_min"); + FAIL_UNLESS(int32_val == int32_min, "int32_val != int32_min"); + FAIL_UNLESS(uint32_val == uint32_min, "uint32_val != uint32_min"); + FAIL_UNLESS(int64_val == int64_min, "int64_val != int64_min"); + FAIL_UNLESS(uint64_val == uint64_min, "uint64_val != uint64_min"); + FAIL_UNLESS(double_val == (longlong) uint64_min, "double_val != uint64_min"); + double_tmp= ulonglong2double(uint64_val); + FAIL_UNLESS(cmp_double(&udouble_val,&double_tmp), "udouble_val != double_tmp"); + FAIL_UNLESS(!strcmp(longlong_as_string, "0"), "longlong_as_string != '0'"); + FAIL_UNLESS(!strcmp(ulonglong_as_string, "0"), "ulonglong_as_string != '0'"); + + rc= mysql_stmt_fetch(stmt); + + FAIL_UNLESS(rc == MYSQL_DATA_TRUNCATED || rc == 0, "rc != 0,MYSQL_DATA_TRUNCATED"); + + FAIL_UNLESS(int8_val == int8_max, "int8_val != int8_max"); + FAIL_UNLESS(uint8_val == uint8_max, "uint8_val != uint8_max"); + FAIL_UNLESS(int16_val == int16_max, "int16_val != int16_max"); + FAIL_UNLESS(uint16_val == uint16_max, "uint16_val != uint16_max"); + FAIL_UNLESS(int32_val == int32_max, "int32_val != int32_max"); + FAIL_UNLESS(uint32_val == uint32_max, "uint32_val != uint32_max"); + FAIL_UNLESS(int64_val == int64_max, "int64_val != int64_max"); + FAIL_UNLESS(uint64_val == uint64_max, "uint64_val != uint64_max"); + FAIL_UNLESS(double_val == (longlong) uint64_val, "double_val != uint64_val"); + double_tmp= ulonglong2double(uint64_val); + FAIL_UNLESS(cmp_double(&udouble_val,&double_tmp), "udouble_val != double_tmp"); + FAIL_UNLESS(!strcmp(longlong_as_string, "-1"), "longlong_as_string != '-1'"); + FAIL_UNLESS(!strcmp(ulonglong_as_string, "18446744073709551615"), "ulonglong_as_string != '18446744073709551615'"); + + rc= mysql_stmt_fetch(stmt); + FAIL_UNLESS(rc == MYSQL_NO_DATA, ""); + + mysql_stmt_close(stmt); + + stmt_text= "DROP TABLE t1"; + mysql_real_query(mysql, SL(stmt_text)); + return OK; +} + +/* + Test for BUG#3420 ("select id1, value1 from t where id= ? or value= ?" + returns all rows in the table) +*/ + +static int test_ps_conj_select(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + int rc; + MYSQL_BIND my_bind[2]; + int32 int_data; + char str_data[32]; + unsigned long str_length; + char query[MAX_TEST_QUERY_LENGTH]; + + rc= mysql_query(mysql, "drop table if exists t1"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "create table t1 (id1 int(11) NOT NULL default '0', " + "value2 varchar(100), value1 varchar(100))"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "insert into t1 values (1, 'hh', 'hh'), " + "(2, 'hh', 'hh'), (1, 'ii', 'ii'), (2, 'ii', 'ii')"); + check_mysql_rc(rc, mysql); + + strcpy(query, "select id1, value1 from t1 where id1= ? or " + "CONVERT(value1 USING utf8)= ?"); + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + FAIL_IF(mysql_stmt_param_count(stmt) != 2, "param_count != 2"); + + /* Always bzero all members of bind parameter */ + memset(my_bind, '\0', sizeof(my_bind)); + my_bind[0].buffer_type= MYSQL_TYPE_LONG; + my_bind[0].buffer= (void *)&int_data; + + my_bind[1].buffer_type= MYSQL_TYPE_VAR_STRING; + my_bind[1].buffer= (void *)str_data; + my_bind[1].buffer_length= array_elements(str_data); + my_bind[1].length= &str_length; + + rc= mysql_stmt_bind_param(stmt, my_bind); + check_stmt_rc(rc, stmt); + int_data= 1; + strcpy(str_data, "hh"); + str_length= (unsigned long)strlen(str_data); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc=0; + while (mysql_stmt_fetch(stmt) != MYSQL_NO_DATA) + rc++; + FAIL_UNLESS(rc == 3, "rc != 3"); + + mysql_stmt_close(stmt); + rc= mysql_query(mysql, "drop table if exists t1"); + check_mysql_rc(rc, mysql); + return OK; +} + +/* Test for NULL as PS parameter (BUG#3367, BUG#3371) */ + +static int test_ps_null_param(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + int rc; + + MYSQL_BIND in_bind; + my_bool in_is_null; + long int in_long; + + MYSQL_BIND out_bind; + ulong out_length; + my_bool out_is_null; + char out_str_data[20]; + + const char *queries[]= {"select ?", "select ?+1", + "select col1 from test_ps_nulls where col1 <=> ?", + NULL + }; + const char **cur_query= queries; + + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_ps_nulls"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE test_ps_nulls(col1 int)"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "INSERT INTO test_ps_nulls values (1), (null)"); + check_mysql_rc(rc, mysql); + + /* Always bzero all members of bind parameter */ + memset(&in_bind, '\0', sizeof(in_bind)); + memset(&out_bind, '\0', sizeof(out_bind)); + in_bind.buffer_type= MYSQL_TYPE_LONG; + in_bind.is_null= &in_is_null; + in_bind.length= 0; + in_bind.buffer= (void *)&in_long; + in_is_null= 1; + in_long= 1; + + out_bind.buffer_type= MYSQL_TYPE_STRING; + out_bind.is_null= &out_is_null; + out_bind.length= &out_length; + out_bind.buffer= out_str_data; + out_bind.buffer_length= array_elements(out_str_data); + + /* Execute several queries, all returning NULL in result. */ + for(cur_query= queries; *cur_query; cur_query++) + { + char query[MAX_TEST_QUERY_LENGTH]; + strcpy(query, *cur_query); + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(query)); + diag("statement: %s", query); + check_stmt_rc(rc, stmt); + FAIL_IF(mysql_stmt_param_count(stmt) != 1, "param_count != 1"); + + rc= mysql_stmt_bind_param(stmt, &in_bind); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_bind_result(stmt, &out_bind); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_fetch(stmt); + FAIL_UNLESS(rc != MYSQL_NO_DATA, "rc != MYSQL_NO_DATA"); + FAIL_UNLESS(out_is_null, "!out_is_null"); + rc= mysql_stmt_fetch(stmt); + FAIL_UNLESS(rc == MYSQL_NO_DATA, "rc != MYSQL_NO_DATA"); + mysql_stmt_close(stmt); + } + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_ps_nulls"); + check_mysql_rc(rc, mysql); + return OK; +} + +/* + utility for the next test; expects 3 rows in the result from a SELECT, + compares each row/field with an expected value. + */ +#define test_ps_query_cache_result(i1,s1,l1,i2,s2,l2,i3,s3,l3) \ + r_metadata= mysql_stmt_result_metadata(stmt); \ + FAIL_UNLESS(r_metadata != NULL, ""); \ + rc= mysql_stmt_fetch(stmt); \ + check_stmt_rc(rc,stmt); \ + FAIL_UNLESS((r_int_data == i1) && (r_str_length == l1) && \ + (strcmp(r_str_data, s1) == 0), "test_ps_query_cache_result failure"); \ + rc= mysql_stmt_fetch(stmt); \ + check_stmt_rc(rc,stmt); \ + FAIL_UNLESS((r_int_data == i2) && (r_str_length == l2) && \ + (strcmp(r_str_data, s2) == 0), "test_ps_query_cache_result failure"); \ + rc= mysql_stmt_fetch(stmt); \ + check_stmt_rc(rc,stmt); \ + FAIL_UNLESS((r_int_data == i3) && (r_str_length == l3) && \ + (strcmp(r_str_data, s3) == 0), "test_ps_query_cache_result failure"); \ + rc= mysql_stmt_fetch(stmt); \ + FAIL_UNLESS(rc == MYSQL_NO_DATA, "rc != MYSQL_NO_DATA"); \ + mysql_free_result(r_metadata); + +/* reads Qcache_hits from server and returns its value */ +static int query_cache_hits(MYSQL *mysql) +{ + MYSQL_RES *res; + MYSQL_ROW row; + int rc; + uint result; + + rc= mysql_query(mysql, "show status like 'qcache_hits'"); + check_mysql_rc(rc, mysql); + res= mysql_use_result(mysql); + + row= mysql_fetch_row(res); + + result= atoi(row[1]); + mysql_free_result(res); + return result; +} + + +/* + Test that prepared statements make use of the query cache just as normal + statements (BUG#735). +*/ +static int test_ps_query_cache(MYSQL *mysql) +{ + MYSQL *lmysql= mysql; + MYSQL_STMT *stmt; + int rc; + MYSQL_BIND p_bind[2],r_bind[2]; /* p: param bind; r: result bind */ + int32 p_int_data, r_int_data; + char p_str_data[32], r_str_data[32]; + unsigned long p_str_length, r_str_length; + MYSQL_RES *r_metadata; + char query[MAX_TEST_QUERY_LENGTH]; + uint hits1, hits2; + enum enum_test_ps_query_cache + { + /* + We iterate the same prepare/executes block, but have iterations where + we vary the query cache conditions. + */ + /* the query cache is enabled for the duration of prep&execs: */ + TEST_QCACHE_ON= 0, + /* + same but using a new connection (to see if qcache serves results from + the previous connection as it should): + */ + TEST_QCACHE_ON_WITH_OTHER_CONN, + /* + First border case: disables the query cache before prepare and + re-enables it before execution (to test if we have no bug then): + */ + TEST_QCACHE_OFF_ON, + /* + Second border case: enables the query cache before prepare and + disables it before execution: + */ + TEST_QCACHE_ON_OFF + }; + enum enum_test_ps_query_cache iteration; + + diag("test needs to be fixed"); + return SKIP; + /* prepare the table */ + + rc= mysql_query(mysql, "drop table if exists t1"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "create table t1 (id1 int(11) NOT NULL default '0', " + "value2 varchar(100), value1 varchar(100))"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "insert into t1 values (1, 'hh', 'hh'), " + "(2, 'hh', 'hh'), (1, 'ii', 'ii'), (2, 'ii', 'ii')"); + check_mysql_rc(rc, mysql); + + for (iteration= TEST_QCACHE_ON; iteration <= TEST_QCACHE_ON_OFF; iteration++) + { + switch (iteration) { + case TEST_QCACHE_ON: + case TEST_QCACHE_ON_OFF: + rc= mysql_query(lmysql, "set global query_cache_size=1000000"); + check_mysql_rc(rc, mysql); + break; + case TEST_QCACHE_OFF_ON: + rc= mysql_query(lmysql, "set global query_cache_size=0"); + check_mysql_rc(rc, mysql); + break; + case TEST_QCACHE_ON_WITH_OTHER_CONN: + lmysql= test_connect(NULL); + FAIL_IF(!lmysql, "Opening new connection failed"); + break; + } + + strcpy(query, "select id1, value1 from t1 where id1= ? or " + "CONVERT(value1 USING utf8)= ?"); + stmt= mysql_stmt_init(lmysql); + FAIL_IF(!stmt, mysql_error(lmysql)); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + FAIL_IF(mysql_stmt_param_count(stmt) != 2, "param_count != 2"); + + switch (iteration) { + case TEST_QCACHE_OFF_ON: + rc= mysql_query(lmysql, "set global query_cache_size=1000000"); + check_mysql_rc(rc, mysql); + break; + case TEST_QCACHE_ON_OFF: + rc= mysql_query(lmysql, "set global query_cache_size=0"); + check_mysql_rc(rc, mysql); + default: + break; + } + + memset(p_bind, '\0', sizeof(p_bind)); + p_bind[0].buffer_type= MYSQL_TYPE_LONG; + p_bind[0].buffer= (void *)&p_int_data; + p_bind[1].buffer_type= MYSQL_TYPE_VAR_STRING; + p_bind[1].buffer= (void *)p_str_data; + p_bind[1].buffer_length= array_elements(p_str_data); + p_bind[1].length= &p_str_length; + + rc= mysql_stmt_bind_param(stmt, p_bind); + check_stmt_rc(rc, stmt); + p_int_data= 1; + strcpy(p_str_data, "hh"); + p_str_length= (unsigned long)strlen(p_str_data); + + memset(r_bind, '\0', sizeof(r_bind)); + r_bind[0].buffer_type= MYSQL_TYPE_LONG; + r_bind[0].buffer= (void *)&r_int_data; + r_bind[1].buffer_type= MYSQL_TYPE_VAR_STRING; + r_bind[1].buffer= (void *)r_str_data; + r_bind[1].buffer_length= array_elements(r_str_data); + r_bind[1].length= &r_str_length; + + rc= mysql_stmt_bind_result(stmt, r_bind); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + test_ps_query_cache_result(1, "hh", 2, 2, "hh", 2, 1, "ii", 2); + r_metadata= mysql_stmt_result_metadata(stmt); + FAIL_UNLESS(r_metadata != NULL, ""); + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc,stmt); + FAIL_UNLESS((r_int_data == 1) && (r_str_length == 2) && + (strcmp(r_str_data, "hh") == 0), "test_ps_query_cache_result failure"); \ + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc,stmt); + FAIL_UNLESS((r_int_data == 2) && (r_str_length == 2) && + (strcmp(r_str_data, "hh") == 0), "test_ps_query_cache_result failure"); \ + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc,stmt); + FAIL_UNLESS((r_int_data == 1) && (r_str_length == 2) && + (strcmp(r_str_data, "ii") == 0), "test_ps_query_cache_result failure"); \ + rc= mysql_stmt_fetch(stmt); + FAIL_UNLESS(rc == MYSQL_NO_DATA, "rc != MYSQL_NO_DATA"); + mysql_free_result(r_metadata); + + + /* now retry with the same parameter values and see qcache hits */ + hits1= query_cache_hits(lmysql); + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); test_ps_query_cache_result(1, "hh", 2, 2, "hh", 2, 1, "ii", 2); + hits2= query_cache_hits(lmysql); + switch(iteration) { + case TEST_QCACHE_ON_WITH_OTHER_CONN: + case TEST_QCACHE_ON: /* should have hit */ + FAIL_UNLESS(hits2-hits1 == 1, "hits2 != hits1 + 1"); + break; + case TEST_QCACHE_OFF_ON: + case TEST_QCACHE_ON_OFF: /* should not have hit */ + FAIL_UNLESS(hits2-hits1 == 0, "hits2 != hits1"); + break; + } + + /* now modify parameter values and see qcache hits */ + strcpy(p_str_data, "ii"); + p_str_length= (unsigned long)strlen(p_str_data); + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + test_ps_query_cache_result(1, "hh", 2, 1, "ii", 2, 2, "ii", 2); + hits1= query_cache_hits(lmysql); + + switch(iteration) { + case TEST_QCACHE_ON: + case TEST_QCACHE_OFF_ON: + case TEST_QCACHE_ON_OFF: /* should not have hit */ + FAIL_UNLESS(hits2-hits1 == 0, "hits2 != hits1"); + break; + case TEST_QCACHE_ON_WITH_OTHER_CONN: /* should have hit */ + FAIL_UNLESS(hits1-hits2 == 1, "hits2 != hits1+1"); + break; + } + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + test_ps_query_cache_result(1, "hh", 2, 1, "ii", 2, 2, "ii", 2); + hits2= query_cache_hits(lmysql); + + mysql_stmt_close(stmt); + + switch(iteration) { + case TEST_QCACHE_ON: /* should have hit */ + FAIL_UNLESS(hits2-hits1 == 1, "hits2 != hits1+1"); + break; + case TEST_QCACHE_OFF_ON: + case TEST_QCACHE_ON_OFF: /* should not have hit */ + FAIL_UNLESS(hits2-hits1 == 0, "hits2 != hits1"); + break; + case TEST_QCACHE_ON_WITH_OTHER_CONN: /* should have hit */ + FAIL_UNLESS(hits2-hits1 == 1, "hits2 != hits1+1"); + break; + } + + } /* for(iteration=...) */ + + if (lmysql != mysql) + mysql_close(lmysql); + + rc= mysql_query(mysql, "set global query_cache_size=0"); + check_mysql_rc(rc, mysql); + return OK; +} + +static int test_bug3117(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + MYSQL_BIND buffer; + longlong lii; + ulong length; + my_bool is_null; + int rc; + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE t1 (id int auto_increment primary key)"); + check_mysql_rc(rc, mysql); + + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL("SELECT LAST_INSERT_ID()")); + check_stmt_rc(rc, stmt); + + rc= mysql_query(mysql, "INSERT INTO t1 VALUES (NULL)"); + check_mysql_rc(rc, mysql); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + memset(&buffer, '\0', sizeof(buffer)); + buffer.buffer_type= MYSQL_TYPE_LONGLONG; + buffer.buffer_length= sizeof(lii); + buffer.buffer= (void *)&lii; + buffer.length= &length; + buffer.is_null= &is_null; + + rc= mysql_stmt_bind_result(stmt, &buffer); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_store_result(stmt); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + FAIL_UNLESS(is_null == 0 && lii == 1, "is_null != 0 || lii != 1"); + + rc= mysql_query(mysql, "INSERT INTO t1 VALUES (NULL)"); + check_mysql_rc(rc, mysql); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + FAIL_UNLESS(is_null == 0 && lii == 2, "is_null != 0 || lii != 2"); + + mysql_stmt_close(stmt); + + rc= mysql_query(mysql, "DROP TABLE t1"); + check_mysql_rc(rc, mysql); + return OK; +} + +/** + Bug#36004 mysql_stmt_prepare resets the list of warnings +*/ + +static int test_bug36004(MYSQL *mysql) +{ + int rc, warning_count= 0; + MYSQL_STMT *stmt; + SKIP_MAXSCALE; + SKIP_MYSQL(mysql); // don't send expected warnings + + if (mysql_get_server_version(mysql) < 60000) { + diag("Test requires MySQL Server version 6.0 or above"); + return SKIP; + } + + rc= mysql_query(mysql, "drop table if exists inexistant"); + check_mysql_rc(rc, mysql); + + FAIL_UNLESS(mysql_warning_count(mysql) == 1, ""); + query_int_variable(mysql, "@@warning_count", &warning_count); + FAIL_UNLESS(warning_count, "Warning expected"); + + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL("select 1")); + check_stmt_rc(rc, stmt); + + FAIL_UNLESS(mysql_warning_count(mysql) == 0, "No warning expected"); + query_int_variable(mysql, "@@warning_count", &warning_count); + FAIL_UNLESS(warning_count, "warning expected"); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + FAIL_UNLESS(mysql_warning_count(mysql) == 0, "No warning expected"); + mysql_stmt_close(stmt); + + query_int_variable(mysql, "@@warning_count", &warning_count); + FAIL_UNLESS(warning_count, "Warning expected"); + + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL("drop table if exists inexistant")); + check_stmt_rc(rc, stmt); + + query_int_variable(mysql, "@@warning_count", &warning_count); + FAIL_UNLESS(warning_count == 0, "No warning expected"); + mysql_stmt_close(stmt); + + return OK; +} + +static int test_bug3796(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + MYSQL_BIND my_bind[1]; + const char *concat_arg0= "concat_with_"; + enum { OUT_BUFF_SIZE= 30 }; + char out_buff[OUT_BUFF_SIZE]; + char canonical_buff[OUT_BUFF_SIZE]; + ulong out_length; + const char *stmt_text; + int rc; + + + /* Create and fill test table */ + stmt_text= "DROP TABLE IF EXISTS t1"; + rc= mysql_real_query(mysql, SL(stmt_text)); + check_mysql_rc(rc, mysql); + + stmt_text= "CREATE TABLE t1 (a INT, b VARCHAR(30))"; + rc= mysql_real_query(mysql, SL(stmt_text)); + check_mysql_rc(rc, mysql); + + stmt_text= "INSERT INTO t1 VALUES(1, 'ONE'), (2, 'TWO')"; + rc= mysql_real_query(mysql, SL(stmt_text)); + check_mysql_rc(rc, mysql); + + /* Create statement handle and prepare it with select */ + stmt= mysql_stmt_init(mysql); + stmt_text= "SELECT concat(?, b) FROM t1"; + + rc= mysql_stmt_prepare(stmt, SL(stmt_text)); + check_stmt_rc(rc, stmt); + /* Bind input buffers */ + memset(my_bind, '\0', sizeof(my_bind)); + my_bind[0].buffer_type= MYSQL_TYPE_STRING; + my_bind[0].buffer= (void *) concat_arg0; + my_bind[0].buffer_length= (unsigned long)strlen(concat_arg0); + + mysql_stmt_bind_param(stmt, my_bind); + + /* Execute the select statement */ + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + my_bind[0].buffer= (void *) out_buff; + my_bind[0].buffer_length= OUT_BUFF_SIZE; + my_bind[0].length= &out_length; + + mysql_stmt_bind_result(stmt, my_bind); + + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + strcpy(canonical_buff, concat_arg0); + strcat(canonical_buff, "ONE"); + FAIL_UNLESS(strlen(canonical_buff) == out_length && + strncmp(out_buff, canonical_buff, out_length) == 0, ""); + + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + strcpy(canonical_buff + strlen(concat_arg0), "TWO"); + FAIL_UNLESS(strlen(canonical_buff) == out_length && + strncmp(out_buff, canonical_buff, out_length) == 0, ""); + + rc= mysql_stmt_fetch(stmt); + FAIL_UNLESS(rc == MYSQL_NO_DATA, "rc != MYSQL_NO_DATA"); + + mysql_stmt_close(stmt); + + stmt_text= "DROP TABLE IF EXISTS t1"; + rc= mysql_real_query(mysql, SL(stmt_text)); + check_mysql_rc(rc, mysql); + return OK; +} + +static int test_bug4026(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + MYSQL_BIND my_bind[2]; + MYSQL_TIME time_in, time_out; + MYSQL_TIME datetime_in, datetime_out; + const char *stmt_text; + int rc; + + + /* Check that microseconds are inserted and selected successfully */ + + /* Create a statement handle and prepare it with select */ + stmt= mysql_stmt_init(mysql); + stmt_text= "SELECT ?, ?"; + + rc= mysql_stmt_prepare(stmt, SL(stmt_text)); + check_stmt_rc(rc, stmt); + /* Bind input buffers */ + memset(my_bind, '\0', sizeof(MYSQL_BIND) * 2); + memset(&time_in, '\0', sizeof(MYSQL_TIME)); + memset(&time_out, '\0', sizeof(MYSQL_TIME)); + memset(&datetime_in, '\0', sizeof(MYSQL_TIME)); + memset(&datetime_out, '\0', sizeof(MYSQL_TIME)); + my_bind[0].buffer_type= MYSQL_TYPE_TIME; + my_bind[0].buffer= (void *) &time_in; + my_bind[1].buffer_type= MYSQL_TYPE_DATETIME; + my_bind[1].buffer= (void *) &datetime_in; + + time_in.hour= 23; + time_in.minute= 59; + time_in.second= 59; + time_in.second_part= 123456; + /* + This is not necessary, just to make DIE_UNLESS below work: this field + is filled in when time is received from server + */ + time_in.time_type= MYSQL_TIMESTAMP_TIME; + + datetime_in= time_in; + datetime_in.year= 2003; + datetime_in.month= 12; + datetime_in.day= 31; + datetime_in.time_type= MYSQL_TIMESTAMP_DATETIME; + + mysql_stmt_bind_param(stmt, my_bind); + + /* Execute the select statement */ + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + my_bind[0].buffer= (void *) &time_out; + my_bind[1].buffer= (void *) &datetime_out; + + mysql_stmt_bind_result(stmt, my_bind); + + rc= mysql_stmt_fetch(stmt); + FAIL_UNLESS(rc == 0, "rc != 0"); + FAIL_UNLESS(memcmp(&time_in, &time_out, sizeof(time_in)) == 0, "time_in != time_out"); + FAIL_UNLESS(memcmp(&datetime_in, &datetime_out, sizeof(datetime_in)) == 0, "datetime_in != datetime_out"); + mysql_stmt_close(stmt); + + return OK; +} + +static int test_bug4030(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + MYSQL_BIND my_bind[3]; + MYSQL_TIME time_canonical, time_out; + MYSQL_TIME date_canonical, date_out; + MYSQL_TIME datetime_canonical, datetime_out; + const char *stmt_text; + int rc; + + + /* Check that microseconds are inserted and selected successfully */ + + /* Execute a query with time values in prepared mode */ + stmt= mysql_stmt_init(mysql); + stmt_text= "SELECT '23:59:59.123456', '2003-12-31', " + "'2003-12-31 23:59:59.123456'"; + rc= mysql_stmt_prepare(stmt, SL(stmt_text)); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + /* Bind output buffers */ + memset(my_bind, '\0', sizeof(my_bind)); + memset(&time_canonical, '\0', sizeof(time_canonical)); + memset(&time_out, '\0', sizeof(time_out)); + memset(&date_canonical, '\0', sizeof(date_canonical)); + memset(&date_out, '\0', sizeof(date_out)); + memset(&datetime_canonical, '\0', sizeof(datetime_canonical)); + memset(&datetime_out, '\0', sizeof(datetime_out)); + my_bind[0].buffer_type= MYSQL_TYPE_TIME; + my_bind[0].buffer= (void *) &time_out; + my_bind[1].buffer_type= MYSQL_TYPE_DATE; + my_bind[1].buffer= (void *) &date_out; + my_bind[2].buffer_type= MYSQL_TYPE_DATETIME; + my_bind[2].buffer= (void *) &datetime_out; + + time_canonical.hour= 23; + time_canonical.minute= 59; + time_canonical.second= 59; + time_canonical.second_part= 123456; + time_canonical.time_type= MYSQL_TIMESTAMP_TIME; + + date_canonical.year= 2003; + date_canonical.month= 12; + date_canonical.day= 31; + date_canonical.time_type= MYSQL_TIMESTAMP_DATE; + + datetime_canonical= time_canonical; + datetime_canonical.year= 2003; + datetime_canonical.month= 12; + datetime_canonical.day= 31; + datetime_canonical.time_type= MYSQL_TIMESTAMP_DATETIME; + + mysql_stmt_bind_result(stmt, my_bind); + + rc= mysql_stmt_fetch(stmt); + FAIL_UNLESS(rc == 0, "rc != 0"); + FAIL_UNLESS(memcmp(&time_canonical, &time_out, sizeof(time_out)) == 0, "time_canonical != time_out"); + FAIL_UNLESS(memcmp(&date_canonical, &date_out, sizeof(date_out)) == 0, "date_canoncical != date_out"); + FAIL_UNLESS(memcmp(&datetime_canonical, &datetime_out, sizeof(datetime_out)) == 0, "datetime_canonical != datetime_out"); + mysql_stmt_close(stmt); + return OK; +} + +static int test_bug4079(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + MYSQL_BIND my_bind[1]; + const char *stmt_text; + uint32 res; + int rc; + + /* Create and fill table */ + mysql_query(mysql, "DROP TABLE IF EXISTS t1"); + mysql_query(mysql, "CREATE TABLE t1 (a int)"); + mysql_query(mysql, "INSERT INTO t1 VALUES (1), (2)"); + + /* Prepare erroneous statement */ + stmt= mysql_stmt_init(mysql); + stmt_text= "SELECT 1 < (SELECT a FROM t1)"; + + rc= mysql_stmt_prepare(stmt, SL(stmt_text)); + check_stmt_rc(rc, stmt); + /* Execute the select statement */ + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + /* Bind input buffers */ + memset(my_bind, '\0', sizeof(my_bind)); + my_bind[0].buffer_type= MYSQL_TYPE_LONG; + my_bind[0].buffer= (void *) &res; + + mysql_stmt_bind_result(stmt, my_bind); + + rc= mysql_stmt_fetch(stmt); + FAIL_UNLESS(rc == 1, "rc != 1"); + /* buggy version of libmysql hanged up here */ + mysql_stmt_close(stmt); + return OK; +} + +static int test_bug4172(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + MYSQL_BIND my_bind[3]; + const char *stmt_text; + MYSQL_RES *res; + MYSQL_ROW row; + int rc; + char f[100], d[100], e[100]; + ulong f_len, d_len, e_len; + + mysql_query(mysql, "DROP TABLE IF EXISTS t1"); + mysql_query(mysql, "CREATE TABLE t1 (f float, d double, e decimal(10,4))"); + mysql_query(mysql, "INSERT INTO t1 VALUES (12345.1234, 123456.123456, " + "123456.1234)"); + + stmt= mysql_stmt_init(mysql); + stmt_text= "SELECT f, d, e FROM t1"; + + rc= mysql_stmt_prepare(stmt, SL(stmt_text)); + check_stmt_rc(rc, stmt); rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + memset(my_bind, '\0', sizeof(my_bind)); my_bind[0].buffer_type= MYSQL_TYPE_STRING; + my_bind[0].buffer= f; + my_bind[0].buffer_length= sizeof(f); + my_bind[0].length= &f_len; + my_bind[1].buffer_type= MYSQL_TYPE_STRING; + my_bind[1].buffer= d; + my_bind[1].buffer_length= sizeof(d); + my_bind[1].length= &d_len; + my_bind[2].buffer_type= MYSQL_TYPE_STRING; + my_bind[2].buffer= e; + my_bind[2].buffer_length= sizeof(e); + my_bind[2].length= &e_len; + + mysql_stmt_bind_result(stmt, my_bind); + + mysql_stmt_store_result(stmt); + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + rc= mysql_real_query(mysql, SL(stmt_text)); + check_mysql_rc(rc, mysql); + res= mysql_store_result(mysql); + row= mysql_fetch_row(res); + + diag("expected %s %s %s", row[0], row[1], row[2]); + diag("fetched %s %s %s", f, d, e); + FAIL_UNLESS(!strcmp(f, row[0]) && !strcmp(d, row[1]) && !strcmp(e, row[2]), ""); + + mysql_free_result(res); + mysql_stmt_close(stmt); + return OK; +} + +static int test_bug4231(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + MYSQL_BIND my_bind[2]; + MYSQL_TIME tm[2]; + const char *stmt_text; + int rc; + + + stmt_text= "DROP TABLE IF EXISTS t1"; + rc= mysql_real_query(mysql, SL(stmt_text)); + check_mysql_rc(rc, mysql); + + stmt_text= "CREATE TABLE t1 (a int)"; + rc= mysql_real_query(mysql, SL(stmt_text)); + check_mysql_rc(rc, mysql); + + stmt_text= "INSERT INTO t1 VALUES (1)"; + rc= mysql_real_query(mysql, SL(stmt_text)); + check_mysql_rc(rc, mysql); + + stmt= mysql_stmt_init(mysql); + stmt_text= "SELECT a FROM t1 WHERE ? = ?"; + rc= mysql_stmt_prepare(stmt, SL(stmt_text)); + check_stmt_rc(rc, stmt); + /* Bind input buffers */ + memset(my_bind, '\0', sizeof(my_bind)); memset(tm, '\0', sizeof(tm)); + my_bind[0].buffer_type= MYSQL_TYPE_DATE; + my_bind[0].buffer= &tm[0]; + my_bind[1].buffer_type= MYSQL_TYPE_DATE; + my_bind[1].buffer= &tm[1]; + + mysql_stmt_bind_param(stmt, my_bind); + check_stmt_rc(rc, stmt); + /* + First set server-side params to some non-zero non-equal values: + then we will check that they are not used when client sends + new (zero) times. + */ + tm[0].time_type = MYSQL_TIMESTAMP_DATE; + tm[0].year = 2000; + tm[0].month = 1; + tm[0].day = 1; + tm[1]= tm[0]; + --tm[1].year; /* tm[0] != tm[1] */ + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_fetch(stmt); + + /* binds are unequal, no rows should be returned */ + FAIL_UNLESS(rc == MYSQL_NO_DATA, "rc != MYSQL_NO_DATA"); + + /* Set one of the dates to zero */ + tm[0].year= tm[0].month= tm[0].day= 0; + tm[1]= tm[0]; + mysql_stmt_execute(stmt); + rc= mysql_stmt_fetch(stmt); + FAIL_UNLESS(rc == 0, "rc != 0"); + + mysql_stmt_close(stmt); + stmt_text= "DROP TABLE t1"; + rc= mysql_real_query(mysql, SL(stmt_text)); + check_mysql_rc(rc, mysql); + return OK; +} + +static int test_bug4236(MYSQL *mysql) +{ + MYSQL_STMT *stmt, *stmt1; + const char *stmt_text; + int rc; + MYSQL_STMT backup; + MYSQL *mysql1; + + + stmt= mysql_stmt_init(mysql); + + /* mysql_stmt_execute() of statement with statement id= 0 crashed server */ + stmt_text= "SELECT 1"; + /* We need to prepare statement to pass by possible check in libmysql */ + rc= mysql_stmt_prepare(stmt, SL(stmt_text)); + check_stmt_rc(rc, stmt); /* Hack to check that server works OK if statement wasn't found */ + backup.stmt_id= stmt->stmt_id; + stmt->stmt_id= 0; + rc= mysql_stmt_execute(stmt); + FAIL_IF(!rc, "Error expected"); + + /* lets try to hack with a new connection */ + mysql1= test_connect(NULL); + stmt1= mysql_stmt_init(mysql1); + stmt_text= "SELECT 2"; + rc= mysql_stmt_prepare(stmt1, SL(stmt_text)); + check_stmt_rc(rc, stmt); + + stmt->stmt_id= stmt1->stmt_id; + rc= mysql_stmt_execute(stmt); + FAIL_IF(!rc, "Error expected"); + + mysql_stmt_close(stmt1); + mysql_close(mysql1); + + /* Restore original statement id to be able to reprepare it */ + stmt->stmt_id= backup.stmt_id; + + mysql_stmt_close(stmt); + return OK; +} + +static int test_bug5126(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + MYSQL_BIND my_bind[2]; + int32 c1, c2; + const char *stmt_text; + int rc; + + + stmt_text= "DROP TABLE IF EXISTS t1"; + rc= mysql_real_query(mysql, SL(stmt_text)); + check_mysql_rc(rc, mysql); + + stmt_text= "CREATE TABLE t1 (a mediumint, b int)"; + rc= mysql_real_query(mysql, SL(stmt_text)); + check_mysql_rc(rc, mysql); + + stmt_text= "INSERT INTO t1 VALUES (8386608, 1)"; + rc= mysql_real_query(mysql, SL(stmt_text)); + check_mysql_rc(rc, mysql); + + stmt= mysql_stmt_init(mysql); + stmt_text= "SELECT a, b FROM t1"; + rc= mysql_stmt_prepare(stmt, SL(stmt_text)); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + /* Bind output buffers */ + memset(my_bind, '\0', sizeof(my_bind)); + my_bind[0].buffer_type= MYSQL_TYPE_LONG; + my_bind[0].buffer= &c1; + my_bind[1].buffer_type= MYSQL_TYPE_LONG; + my_bind[1].buffer= &c2; + + mysql_stmt_bind_result(stmt, my_bind); + + rc= mysql_stmt_fetch(stmt); + FAIL_UNLESS(rc == 0, "rc != 0"); + FAIL_UNLESS(c1 == 8386608 && c2 == 1, "c1 != 8386608 || c2 != 1"); + mysql_stmt_close(stmt); + return OK; +} + +static int test_bug5194(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + MYSQL_BIND *my_bind; + char *query; + char *param_str; + int param_str_length; + const char *stmt_text; + int rc; + float float_array[250] = + { + 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, + 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, + 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, + 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, + 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, + 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, + 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, + 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, + 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, + 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, + 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, + 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, + 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, + 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, + 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, + 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, + 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, + 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, + 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, + 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, + 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, + 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, + 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, + 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, + 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25 + }; + float *fa_ptr= float_array; + /* Number of columns per row */ + const int COLUMN_COUNT= sizeof(float_array)/sizeof(*float_array); + /* Number of rows per bulk insert to start with */ + const int MIN_ROWS_PER_INSERT= 262; + /* Max number of rows per bulk insert to end with */ + const int MAX_ROWS_PER_INSERT= 300; + const int MAX_PARAM_COUNT= COLUMN_COUNT*MAX_ROWS_PER_INSERT; + const char *query_template= "insert into t1 values %s"; + const int CHARS_PER_PARAM= 5; /* space needed to place ", ?" in the query */ + const int uint16_max= 65535; + int nrows, i; + + SKIP_MAXSCALE; + + stmt_text= "drop table if exists t1"; + rc= mysql_real_query(mysql, SL(stmt_text)); + + stmt_text= "create table if not exists t1" + "(c1 float, c2 float, c3 float, c4 float, c5 float, c6 float, " + "c7 float, c8 float, c9 float, c10 float, c11 float, c12 float, " + "c13 float, c14 float, c15 float, c16 float, c17 float, c18 float, " + "c19 float, c20 float, c21 float, c22 float, c23 float, c24 float, " + "c25 float, c26 float, c27 float, c28 float, c29 float, c30 float, " + "c31 float, c32 float, c33 float, c34 float, c35 float, c36 float, " + "c37 float, c38 float, c39 float, c40 float, c41 float, c42 float, " + "c43 float, c44 float, c45 float, c46 float, c47 float, c48 float, " + "c49 float, c50 float, c51 float, c52 float, c53 float, c54 float, " + "c55 float, c56 float, c57 float, c58 float, c59 float, c60 float, " + "c61 float, c62 float, c63 float, c64 float, c65 float, c66 float, " + "c67 float, c68 float, c69 float, c70 float, c71 float, c72 float, " + "c73 float, c74 float, c75 float, c76 float, c77 float, c78 float, " + "c79 float, c80 float, c81 float, c82 float, c83 float, c84 float, " + "c85 float, c86 float, c87 float, c88 float, c89 float, c90 float, " + "c91 float, c92 float, c93 float, c94 float, c95 float, c96 float, " + "c97 float, c98 float, c99 float, c100 float, c101 float, c102 float, " + "c103 float, c104 float, c105 float, c106 float, c107 float, c108 float, " + "c109 float, c110 float, c111 float, c112 float, c113 float, c114 float, " + "c115 float, c116 float, c117 float, c118 float, c119 float, c120 float, " + "c121 float, c122 float, c123 float, c124 float, c125 float, c126 float, " + "c127 float, c128 float, c129 float, c130 float, c131 float, c132 float, " + "c133 float, c134 float, c135 float, c136 float, c137 float, c138 float, " + "c139 float, c140 float, c141 float, c142 float, c143 float, c144 float, " + "c145 float, c146 float, c147 float, c148 float, c149 float, c150 float, " + "c151 float, c152 float, c153 float, c154 float, c155 float, c156 float, " + "c157 float, c158 float, c159 float, c160 float, c161 float, c162 float, " + "c163 float, c164 float, c165 float, c166 float, c167 float, c168 float, " + "c169 float, c170 float, c171 float, c172 float, c173 float, c174 float, " + "c175 float, c176 float, c177 float, c178 float, c179 float, c180 float, " + "c181 float, c182 float, c183 float, c184 float, c185 float, c186 float, " + "c187 float, c188 float, c189 float, c190 float, c191 float, c192 float, " + "c193 float, c194 float, c195 float, c196 float, c197 float, c198 float, " + "c199 float, c200 float, c201 float, c202 float, c203 float, c204 float, " + "c205 float, c206 float, c207 float, c208 float, c209 float, c210 float, " + "c211 float, c212 float, c213 float, c214 float, c215 float, c216 float, " + "c217 float, c218 float, c219 float, c220 float, c221 float, c222 float, " + "c223 float, c224 float, c225 float, c226 float, c227 float, c228 float, " + "c229 float, c230 float, c231 float, c232 float, c233 float, c234 float, " + "c235 float, c236 float, c237 float, c238 float, c239 float, c240 float, " + "c241 float, c242 float, c243 float, c244 float, c245 float, c246 float, " + "c247 float, c248 float, c249 float, c250 float)"; + rc= mysql_real_query(mysql, SL(stmt_text)); + check_mysql_rc(rc, mysql); + + my_bind= (MYSQL_BIND*) malloc(MAX_PARAM_COUNT * sizeof(MYSQL_BIND)); + query= (char*) malloc(strlen(query_template) + + MAX_PARAM_COUNT * CHARS_PER_PARAM + 1); + param_str= (char*) malloc(COLUMN_COUNT * CHARS_PER_PARAM); + + FAIL_IF(my_bind == 0 || query == 0 || param_str == 0, "Not enough memory"); + + stmt= mysql_stmt_init(mysql); + + /* setup a template for one row of parameters */ + sprintf(param_str, "("); + for (i= 1; i < COLUMN_COUNT; ++i) + strcat(param_str, "?, "); + strcat(param_str, "?)"); + param_str_length= (int)strlen(param_str); + + /* setup bind array */ + memset(my_bind, '\0', MAX_PARAM_COUNT * sizeof(MYSQL_BIND)); + for (i= 0; i < MAX_PARAM_COUNT; ++i) + { + my_bind[i].buffer_type= MYSQL_TYPE_FLOAT; + my_bind[i].buffer= fa_ptr; + if (++fa_ptr == float_array + COLUMN_COUNT) + fa_ptr= float_array; + } + + /* + Test each number of rows per bulk insert, so that we can see where + MySQL fails. + */ + for (nrows= MIN_ROWS_PER_INSERT; nrows <= MAX_ROWS_PER_INSERT; ++nrows) + { + char *query_ptr; + /* Create statement text for current number of rows */ + sprintf(query, query_template, param_str); + query_ptr= query + (unsigned long)strlen(query); + for (i= 1; i < nrows; ++i) + { + memcpy(query_ptr, ", ", 2); + query_ptr+= 2; + memcpy(query_ptr, param_str, param_str_length); + query_ptr+= param_str_length; + } + *query_ptr= '\0'; + + rc= mysql_stmt_prepare(stmt, query, (ulong)(query_ptr - query)); + + if (rc && nrows * COLUMN_COUNT > uint16_max) /* expected error */ + break; + + check_stmt_rc(rc, stmt); + + /* bind the parameter array and execute the query */ + rc= mysql_stmt_bind_param(stmt, my_bind); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_reset(stmt); + } + + free(param_str); + free(query); + rc= mysql_stmt_close(stmt); + check_stmt_rc(rc, stmt); + free(my_bind); + stmt_text= "drop table t1"; + rc= mysql_real_query(mysql, SL(stmt_text)); + check_mysql_rc(rc, mysql); + return OK; +} + +static int test_bug5315(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + const char *stmt_text; + int rc; + SKIP_MAXSCALE; + + if (!is_mariadb) + return SKIP; + + stmt_text= "SELECT 1"; + stmt= mysql_stmt_init(mysql); + rc= mysql_stmt_prepare(stmt, SL(stmt_text)); + check_stmt_rc(rc, stmt); + rc= mysql_change_user(mysql, username, password, schema); + check_mysql_rc(rc, mysql); + + rc= mysql_stmt_execute(stmt); + FAIL_UNLESS(rc != 0, "Error expected"); + + rc= mysql_stmt_close(stmt); + check_stmt_rc(rc, stmt); + + stmt= mysql_stmt_init(mysql); + rc= mysql_stmt_prepare(stmt, SL(stmt_text)); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + mysql_stmt_close(stmt); + return OK; +} + +static int test_bug5399(MYSQL *mysql) +{ + /* + Ascii 97 is 'a', which gets mapped to Ascii 65 'A' unless internal + statement id hash in the server uses binary collation. + */ +#define NUM_OF_USED_STMT 97 + MYSQL_STMT *stmt_list[NUM_OF_USED_STMT]; + MYSQL_STMT **stmt; + MYSQL_BIND my_bind[1]; + char buff[600]; + int rc; + int32 no; + + + memset(my_bind, '\0', sizeof(my_bind)); my_bind[0].buffer_type= MYSQL_TYPE_LONG; + my_bind[0].buffer= &no; + + for (stmt= stmt_list; stmt != stmt_list + NUM_OF_USED_STMT; ++stmt) + { + sprintf(buff, "select %d", (int) (stmt - stmt_list)); + *stmt= mysql_stmt_init(mysql); + rc= mysql_stmt_prepare(*stmt, SL(buff)); + check_stmt_rc(rc, *stmt); mysql_stmt_bind_result(*stmt, my_bind); + } + + for (stmt= stmt_list; stmt != stmt_list + NUM_OF_USED_STMT; ++stmt) + { + rc= mysql_stmt_execute(*stmt); + check_stmt_rc(rc, *stmt); + rc= mysql_stmt_store_result(*stmt); + check_stmt_rc(rc, *stmt); + rc= mysql_stmt_fetch(*stmt); + FAIL_UNLESS((int32) (stmt - stmt_list) == no, ""); + } + + for (stmt= stmt_list; stmt != stmt_list + NUM_OF_USED_STMT; ++stmt) + mysql_stmt_close(*stmt); +#undef NUM_OF_USED_STMT + return OK; +} + +static int test_bug6046(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + const char *stmt_text; + int rc; + short b= 1; + MYSQL_BIND my_bind[1]; + + + stmt_text= "DROP TABLE IF EXISTS t1"; + rc= mysql_real_query(mysql, SL(stmt_text)); + check_mysql_rc(rc, mysql); + stmt_text= "CREATE TABLE t1 (a int, b int)"; + rc= mysql_real_query(mysql, SL(stmt_text)); + check_mysql_rc(rc, mysql); + stmt_text= "INSERT INTO t1 VALUES (1,1),(2,2),(3,1),(4,2)"; + rc= mysql_real_query(mysql, SL(stmt_text)); + check_mysql_rc(rc, mysql); + + stmt= mysql_stmt_init(mysql); + + stmt_text= "SELECT t1.a FROM t1 NATURAL JOIN t1 as X1 " + "WHERE t1.b > ? ORDER BY t1.a"; + + rc= mysql_stmt_prepare(stmt, SL(stmt_text)); + check_stmt_rc(rc, stmt); + b= 1; + memset(my_bind, '\0', sizeof(my_bind)); my_bind[0].buffer= &b; + my_bind[0].buffer_type= MYSQL_TYPE_SHORT; + + mysql_stmt_bind_param(stmt, my_bind); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + mysql_stmt_store_result(stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + mysql_stmt_close(stmt); + return OK; +} + +static int test_bug6049(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + MYSQL_BIND my_bind[1]; + MYSQL_RES *res; + MYSQL_ROW row; + const char *stmt_text; + char buffer[30]; + ulong length; + int rc; + + + stmt_text= "SELECT MAKETIME(-25, 12, 12)"; + + rc= mysql_real_query(mysql, SL(stmt_text)); + check_mysql_rc(rc, mysql); + res= mysql_store_result(mysql); + row= mysql_fetch_row(res); + + stmt= mysql_stmt_init(mysql); + rc= mysql_stmt_prepare(stmt, SL(stmt_text)); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + memset(my_bind, '\0', sizeof(my_bind)); + my_bind[0].buffer_type = MYSQL_TYPE_STRING; + my_bind[0].buffer = &buffer; + my_bind[0].buffer_length = sizeof(buffer); + my_bind[0].length = &length; + + mysql_stmt_bind_result(stmt, my_bind); + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + + FAIL_UNLESS(strcmp(row[0], (char*) buffer) == 0, "row[0] != buffer"); + + mysql_free_result(res); + mysql_stmt_close(stmt); + return OK; +} + +static int test_bug6058(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + MYSQL_BIND my_bind[1]; + MYSQL_RES *res; + MYSQL_ROW row; + const char *stmt_text; + char buffer[30]; + ulong length; + int rc; + + + stmt_text= "SELECT CAST('0000-00-00' AS DATE)"; + + rc= mysql_real_query(mysql, SL(stmt_text)); + check_mysql_rc(rc, mysql); + res= mysql_store_result(mysql); + row= mysql_fetch_row(res); + + stmt= mysql_stmt_init(mysql); + rc= mysql_stmt_prepare(stmt, SL(stmt_text)); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + memset(my_bind, '\0', sizeof(my_bind)); + my_bind[0].buffer_type = MYSQL_TYPE_STRING; + my_bind[0].buffer = &buffer; + my_bind[0].buffer_length = sizeof(buffer); + my_bind[0].length = &length; + + mysql_stmt_bind_result(stmt, my_bind); + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + + FAIL_UNLESS(strcmp(row[0], buffer) == 0, "row[0] != buffer"); + + mysql_free_result(res); + mysql_stmt_close(stmt); + return OK; +} + + +static int test_bug6059(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + const char *stmt_text; + int rc; + + SKIP_SKYSQL; + + stmt_text= "SELECT 'foo' INTO OUTFILE 'x.3'"; + + stmt= mysql_stmt_init(mysql); + rc= mysql_stmt_prepare(stmt, SL(stmt_text)); + check_stmt_rc(rc, stmt); + FAIL_UNLESS(mysql_stmt_field_count(stmt) == 0, ""); + mysql_stmt_close(stmt); + return OK; +} + +static int test_bug6096(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + MYSQL_RES *query_result, *stmt_metadata; + const char *stmt_text; + MYSQL_BIND my_bind[12]; + MYSQL_FIELD *query_field_list, *stmt_field_list; + ulong query_field_count, stmt_field_count; + int rc; + my_bool update_max_length= TRUE; + uint i; + + + stmt_text= "drop table if exists t1"; + rc= mysql_real_query(mysql, SL(stmt_text)); + check_mysql_rc(rc, mysql); + + mysql_query(mysql, "set sql_mode=''"); + stmt_text= "create table t1 (c_tinyint tinyint, c_smallint smallint, " + " c_mediumint mediumint, c_int int, " + " c_bigint bigint, c_float float, " + " c_double double, c_varchar varchar(20), " + " c_char char(20), c_time time, c_date date, " + " c_datetime datetime)"; + rc= mysql_real_query(mysql, SL(stmt_text)); + check_mysql_rc(rc, mysql); + stmt_text= "insert into t1 values (-100, -20000, 30000000, 4, 8, 1.0, " + "2.0, 'abc', 'def', now(), now(), now())"; + rc= mysql_real_query(mysql, SL(stmt_text)); + check_mysql_rc(rc, mysql); + + stmt_text= "select * from t1"; + + /* Run select in prepared and non-prepared mode and compare metadata */ + rc= mysql_real_query(mysql, SL(stmt_text)); + check_mysql_rc(rc, mysql); + query_result= mysql_store_result(mysql); + query_field_list= mysql_fetch_fields(query_result); + FAIL_IF(!query_field_list, "fetch_fields failed"); + query_field_count= mysql_num_fields(query_result); + + stmt= mysql_stmt_init(mysql); + rc= mysql_stmt_prepare(stmt, SL(stmt_text)); + check_stmt_rc(rc, stmt); rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); mysql_stmt_attr_set(stmt, STMT_ATTR_UPDATE_MAX_LENGTH, + (void*) &update_max_length); + mysql_stmt_store_result(stmt); + stmt_metadata= mysql_stmt_result_metadata(stmt); + stmt_field_list= mysql_fetch_fields(stmt_metadata); + stmt_field_count= mysql_num_fields(stmt_metadata); + FAIL_UNLESS(stmt_field_count == query_field_count, ""); + + + /* Bind and fetch the data */ + + memset(my_bind, '\0', sizeof(my_bind)); + for (i= 0; i < stmt_field_count; ++i) + { + my_bind[i].buffer_type= MYSQL_TYPE_STRING; + my_bind[i].buffer_length= stmt_field_list[i].max_length + 1; + my_bind[i].buffer= malloc(my_bind[i].buffer_length); + } + mysql_stmt_bind_result(stmt, my_bind); + rc= mysql_stmt_fetch(stmt); + diag("rc=%d", rc); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_fetch(stmt); + FAIL_UNLESS(rc == MYSQL_NO_DATA, "rc != MYSQL_NO_DATA"); + + /* Clean up */ + + for (i= 0; i < stmt_field_count; ++i) + free(my_bind[i].buffer); + mysql_stmt_close(stmt); + mysql_free_result(query_result); + mysql_free_result(stmt_metadata); + stmt_text= "drop table t1"; + rc= mysql_real_query(mysql, SL(stmt_text)); + check_mysql_rc(rc, mysql); + return OK; +} + +/* Bug#7990 - mysql_stmt_close doesn't reset mysql->net.last_error */ + +static int test_bug7990(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + int rc; + + stmt= mysql_stmt_init(mysql); + rc= mysql_stmt_prepare(stmt, "foo", 3); + /* + XXX: the fact that we store errno both in STMT and in + MYSQL is not documented and is subject to change in 5.0 + */ + FAIL_UNLESS(rc && mysql_stmt_errno(stmt) && mysql_errno(mysql), "Error expected"); + mysql_stmt_close(stmt); + return OK; +} + +/* Bug#8330 - mysql_stmt_execute crashes (libmysql) */ + +static int test_bug8330(MYSQL *mysql) +{ + const char *stmt_text; + MYSQL_STMT *stmt[2]; + int i, rc; + const char *query= "select a,b from t1 where a=?"; + MYSQL_BIND my_bind[2]; + long lval[2]= {1,2}; + + stmt_text= "drop table if exists t1"; + /* in case some previous test failed */ + rc= mysql_real_query(mysql, SL(stmt_text)); + check_mysql_rc(rc, mysql); + stmt_text= "create table t1 (a int, b int)"; + rc= mysql_real_query(mysql, SL(stmt_text)); + check_mysql_rc(rc, mysql); + + memset(my_bind, '\0', sizeof(my_bind)); + for (i=0; i < 2; i++) + { + stmt[i]= mysql_stmt_init(mysql); + rc= mysql_stmt_prepare(stmt[i], SL(query)); + check_stmt_rc(rc, stmt[i]); + my_bind[i].buffer_type= MYSQL_TYPE_LONG; + my_bind[i].buffer= (void*) &lval[i]; + my_bind[i].is_null= 0; + mysql_stmt_bind_param(stmt[i], &my_bind[i]); + } + + rc= mysql_stmt_execute(stmt[0]); + check_stmt_rc(rc, stmt[0]); + rc= mysql_stmt_execute(stmt[1]); + FAIL_UNLESS(rc && mysql_stmt_errno(stmt[1]) == CR_COMMANDS_OUT_OF_SYNC, "Error expected"); + rc= mysql_stmt_execute(stmt[0]); + check_stmt_rc(rc, stmt[0]); + mysql_stmt_close(stmt[0]); + mysql_stmt_close(stmt[1]); + + stmt_text= "drop table t1"; + rc= mysql_real_query(mysql, SL(stmt_text)); + check_mysql_rc(rc, mysql); + return OK; +} + +/* Test misc field information, bug: #74 */ + +static int test_field_misc(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + MYSQL_RES *result; + int rc; + + + rc= mysql_query(mysql, "SELECT @@autocommit"); + check_mysql_rc(rc, mysql); + + result= mysql_store_result(mysql); + FAIL_IF(!result, "Invalid result set"); + + rc= 0; + while (mysql_fetch_row(result)) + rc++; + FAIL_UNLESS(rc == 1, "rowcount != 1"); + + verify_prepare_field(result, 0, + "@@autocommit", "", /* field and its org name */ + MYSQL_TYPE_LONGLONG, /* field type */ + "", "", /* table and its org name */ + "", 1, 0); /* db name, length(its bool flag)*/ + + mysql_free_result(result); + + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL("SELECT @@autocommit")); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + result= mysql_stmt_result_metadata(stmt); + FAIL_IF(!result, "Invalid result set"); + + rc= 0; + while (mysql_stmt_fetch(stmt) != MYSQL_NO_DATA) + rc++; + FAIL_UNLESS(rc == 1, "rowcount != 1"); + + verify_prepare_field(result, 0, + "@@autocommit", "", /* field and its org name */ + MYSQL_TYPE_LONGLONG, /* field type */ + "", "", /* table and its org name */ + "", 1, 0); /* db name, length(its bool flag)*/ + + mysql_free_result(result); + mysql_stmt_close(stmt); + + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL("SELECT @@max_error_count")); + check_stmt_rc(rc, stmt); + + result= mysql_stmt_result_metadata(stmt); + FAIL_IF(!result, "Invalid result set"); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc= 0; + while (mysql_stmt_fetch(stmt) != MYSQL_NO_DATA) + rc++; + FAIL_UNLESS(rc == 1, "rowcount != 1"); + + if (verify_prepare_field(result, 0, + "@@max_error_count", "", /* field and its org name */ + MYSQL_TYPE_LONGLONG, /* field type */ + "", "", /* table and its org name */ + /* db name, length */ + "", MY_INT64_NUM_DECIMAL_DIGITS , 0)) + goto error; + + mysql_free_result(result); + mysql_stmt_close(stmt); + + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL("SELECT @@max_allowed_packet")); + check_stmt_rc(rc, stmt); + + result= mysql_stmt_result_metadata(stmt); + FAIL_IF(!result, "Invalid result set"); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc= 0; + while (mysql_stmt_fetch(stmt) != MYSQL_NO_DATA) + rc++; + FAIL_UNLESS(rc == 1, "rowcount != 1"); + + if (verify_prepare_field(result, 0, + "@@max_allowed_packet", "", /* field and its org name */ + MYSQL_TYPE_LONGLONG, /* field type */ + "", "", /* table and its org name */ + /* db name, length */ + "", MY_INT64_NUM_DECIMAL_DIGITS, 0)) + goto error; + + mysql_free_result(result); + mysql_stmt_close(stmt); + + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL("SELECT @@sql_warnings")); + check_stmt_rc(rc, stmt); + + result= mysql_stmt_result_metadata(stmt); + FAIL_IF(!result, "Invalid result set"); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc= 0; + while (mysql_stmt_fetch(stmt) != MYSQL_NO_DATA) + rc++; + FAIL_UNLESS(rc == 1, "rowcount != 1"); + + if (verify_prepare_field(result, 0, + "@@sql_warnings", "", /* field and its org name */ + MYSQL_TYPE_LONGLONG, /* field type */ + "", "", /* table and its org name */ + "", 1, 0)) /* db name, length */ + goto error; + + mysql_free_result(result); + mysql_stmt_close(stmt); + return OK; + +error: + mysql_free_result(result); + mysql_stmt_close(stmt); + return FAIL; +} + +/* Test a memory ovverun bug */ + +static int test_mem_overun(MYSQL *mysql) +{ + char buffer[10000], field[12]; + MYSQL_STMT *stmt; + MYSQL_RES *field_res, *res; + int rc, i, length; + + /* + Test a memory ovverun bug when a table had 1000 fields with + a row of data + */ + rc= mysql_query(mysql, "drop table if exists t_mem_overun"); + check_mysql_rc(rc, mysql); + + strcpy(buffer, "create table t_mem_overun("); + for (i= 0; i < 1000; i++) + { + sprintf(field, "c%d int, ", i); + strcat(buffer, field); + } + length= (int)strlen(buffer); + buffer[length-2]= ')'; + buffer[--length]= '\0'; + + rc= mysql_real_query(mysql, buffer, length); + check_mysql_rc(rc, mysql); + + strcpy(buffer, "insert into t_mem_overun values("); + for (i= 0; i < 1000; i++) + { + strcat(buffer, "1, "); + } + length= (int)strlen(buffer); + buffer[length-2]= ')'; + buffer[--length]= '\0'; + + rc= mysql_real_query(mysql, buffer, length); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "select * from t_mem_overun"); + check_mysql_rc(rc, mysql); + + res= mysql_store_result(mysql); + rc= 0; + while (mysql_fetch_row(res)) + rc++; + FAIL_UNLESS(rc == 1, "rowcount != 1"); + mysql_free_result(res); + + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL("select * from t_mem_overun")); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + field_res= mysql_stmt_result_metadata(stmt); + FAIL_IF(!field_res, "Invalid result set"); + + FAIL_UNLESS( 1000 == mysql_num_fields(field_res), "fields != 1000"); + + rc= mysql_stmt_store_result(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_fetch(stmt); + FAIL_UNLESS(rc == MYSQL_NO_DATA, ""); + + mysql_free_result(field_res); + + mysql_stmt_close(stmt); + rc= mysql_query(mysql, "drop table if exists t_mem_overun"); + check_mysql_rc(rc, mysql); + return OK; +} + +static int test_bug8722(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + int rc; + const char *stmt_text; + + /* Prepare test data */ + stmt_text= "drop table if exists t1"; + rc= mysql_real_query(mysql, SL(stmt_text)); + check_mysql_rc(rc, mysql); + stmt_text= "drop view if exists v1"; + rc= mysql_real_query(mysql, SL(stmt_text)); + check_mysql_rc(rc, mysql); + stmt_text= "CREATE TABLE t1 (c1 varchar(10), c2 varchar(10), c3 varchar(10)," + " c4 varchar(10), c5 varchar(10), c6 varchar(10)," + " c7 varchar(10), c8 varchar(10), c9 varchar(10)," + "c10 varchar(10))"; + rc= mysql_real_query(mysql, SL(stmt_text)); + check_mysql_rc(rc, mysql); + stmt_text= "INSERT INTO t1 VALUES (1,2,3,4,5,6,7,8,9,10)"; + rc= mysql_real_query(mysql, SL(stmt_text)); + check_mysql_rc(rc, mysql); + stmt_text= "CREATE VIEW v1 AS SELECT * FROM t1"; + rc= mysql_real_query(mysql, SL(stmt_text)); + check_mysql_rc(rc, mysql); + + stmt= mysql_stmt_init(mysql); + stmt_text= "select * from v1"; + rc= mysql_stmt_prepare(stmt, SL(stmt_text)); + check_stmt_rc(rc, stmt); + mysql_stmt_close(stmt); + stmt_text= "drop table if exists t1, v1"; + rc= mysql_query(mysql, "DROP TABLE t1"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "DROP VIEW v1"); + check_mysql_rc(rc, mysql); + return OK; +} + +/* Test DECIMAL conversion */ + +static int test_decimal_bug(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + MYSQL_BIND my_bind[1]; + char data[30]; + int rc; + my_bool is_null; + + mysql_autocommit(mysql, TRUE); + + rc= mysql_query(mysql, "drop table if exists test_decimal_bug"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "create table test_decimal_bug(c1 decimal(10, 2))"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "insert into test_decimal_bug value(8), (10.22), (5.61)"); + check_mysql_rc(rc, mysql); + + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL("select c1 from test_decimal_bug where c1=?")); + check_stmt_rc(rc, stmt); + + /* + We need to bzero bind structure because mysql_stmt_bind_param checks all + its members. + */ + memset(my_bind, '\0', sizeof(my_bind)); + + memset(data, 0, sizeof(data)); + my_bind[0].buffer_type= MYSQL_TYPE_NEWDECIMAL; + my_bind[0].buffer= (void *)data; + my_bind[0].buffer_length= 25; + my_bind[0].is_null= &is_null; + + is_null= 0; + rc= mysql_stmt_bind_param(stmt, my_bind); + check_stmt_rc(rc, stmt); + + strcpy(data, "8.0"); + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + data[0]= 0; + rc= mysql_stmt_bind_result(stmt, my_bind); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + + FAIL_UNLESS(strcmp(data, "8.00") == 0, "data != '8.00'"); + + rc= mysql_stmt_fetch(stmt); + FAIL_UNLESS(rc == MYSQL_NO_DATA, "rc != MYSQL_NO_DATA"); + + strcpy(data, "5.61"); + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + data[0]= 0; + rc= mysql_stmt_bind_result(stmt, my_bind); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + + FAIL_UNLESS(strcmp(data, "5.61") == 0, "data != '5.61'"); + + rc= mysql_stmt_fetch(stmt); + FAIL_UNLESS(rc == MYSQL_NO_DATA, "rc != MYSQL_NO_DATA"); + + is_null= 1; + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_fetch(stmt); + FAIL_UNLESS(rc == MYSQL_NO_DATA, "rc != MYSQL_NO_DATA"); + + strcpy(data, "10.22"); is_null= 0; + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + data[0]= 0; + rc= mysql_stmt_bind_result(stmt, my_bind); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + + FAIL_UNLESS(strcmp(data, "10.22") == 0, "data != '10.22'"); + + rc= mysql_stmt_fetch(stmt); + FAIL_UNLESS(rc == MYSQL_NO_DATA, "rc != MYSQL_NO_DATA"); + + mysql_stmt_close(stmt); + rc= mysql_query(mysql, "drop table if exists test_decimal_bug"); + check_mysql_rc(rc, mysql); + return OK; +} + +/* Test EXPLAIN bug (#115, reported by mark@mysql.com & georg@php.net). */ + +static int test_explain_bug(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + MYSQL_RES *result; + int rc; + + if (!is_mariadb) + return SKIP; + + mysql_autocommit(mysql, TRUE); + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_explain"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE test_explain(id int, name char(2))"); + check_mysql_rc(rc, mysql); + + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL("explain test_explain")); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc= 0; + while (!mysql_stmt_fetch(stmt)) + rc++; + FAIL_UNLESS(rc == 2, "rowcount != 2"); + + result= mysql_stmt_result_metadata(stmt); + FAIL_IF(!result, "Invalid result set"); + + FAIL_UNLESS(6 == mysql_num_fields(result), "fields != 6"); + + if (verify_prepare_field(result, 0, "Field", "COLUMN_NAME", + mysql_get_server_version(mysql) <= 50000 ? + MYSQL_TYPE_STRING : MYSQL_TYPE_VAR_STRING, + 0, 0, + mysql_get_server_version(mysql) <= 50400 ? "" : "information_schema", + 64, 0)) + goto error; + + if (verify_prepare_field(result, 1, "Type", "COLUMN_TYPE", MYSQL_TYPE_BLOB, + 0, 0, + mysql_get_server_version(mysql) <= 50400 ? "" : "information_schema", + 0, 0)) + goto error; + + if (verify_prepare_field(result, 2, "Null", "IS_NULLABLE", + mysql_get_server_version(mysql) <= 50000 ? + MYSQL_TYPE_STRING : MYSQL_TYPE_VAR_STRING, + 0, 0, + mysql_get_server_version(mysql) <= 50400 ? "" : "information_schema", + 3, 0)) + goto error; + + if (verify_prepare_field(result, 3, "Key", "COLUMN_KEY", + mysql_get_server_version(mysql) <= 50000 ? + MYSQL_TYPE_STRING : MYSQL_TYPE_VAR_STRING, + 0, 0, + mysql_get_server_version(mysql) <= 50400 ? "" : "information_schema", + 3, 0)) + goto error; + + if ( mysql_get_server_version(mysql) >= 50027 ) + { + /* The patch for bug#23037 changes column type of DEAULT to blob */ + if (verify_prepare_field(result, 4, "Default", "COLUMN_DEFAULT", + MYSQL_TYPE_BLOB, 0, 0, + mysql_get_server_version(mysql) <= 50400 ? "" : "information_schema", + 0, 0)) + goto error; + } + else + { + if (verify_prepare_field(result, 4, "Default", "COLUMN_DEFAULT", + mysql_get_server_version(mysql) >= 50027 ? + MYSQL_TYPE_BLOB : + mysql_get_server_version(mysql) <= 50000 ? + MYSQL_TYPE_STRING : MYSQL_TYPE_VAR_STRING, + 0, 0, + mysql_get_server_version(mysql) <= 50400 ? "" : "information_schema", + mysql_get_server_version(mysql) >= 50027 ? 0 :64, 0)) + goto error; + } + + if (verify_prepare_field(result, 5, "Extra", "EXTRA", + mysql_get_server_version(mysql) <= 50000 ? + MYSQL_TYPE_STRING : MYSQL_TYPE_VAR_STRING, + 0, 0, + mysql_get_server_version(mysql) <= 50400 ? "" : "information_schema", + 27, 0)) + goto error; + + mysql_free_result(result); + mysql_stmt_close(stmt); + + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL("explain select id, name FROM test_explain")); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc= 0; + while (!mysql_stmt_fetch(stmt)) + rc++; + FAIL_UNLESS(rc == 1, "rowcount != 1"); + + result= mysql_stmt_result_metadata(stmt); + FAIL_IF(!result, "Invalid result set"); + + FAIL_UNLESS(10 == mysql_num_fields(result), "fields != 10"); + + if (verify_prepare_field(result, 0, "id", "", MYSQL_TYPE_LONGLONG, "", "", "", 3, 0)) + goto error; + + if (verify_prepare_field(result, 1, "select_type", "", MYSQL_TYPE_VAR_STRING, "", "", "", 19, 0)) + goto error; + + if (verify_prepare_field(result, 2, "table", "", MYSQL_TYPE_VAR_STRING, "", "", "", NAME_CHAR_LEN, 0)) + goto error; + + if (verify_prepare_field(result, 3, "type", "", MYSQL_TYPE_VAR_STRING, "", "", "", 10, 0)) + goto error; + + if (verify_prepare_field(result, 4, "possible_keys", "", MYSQL_TYPE_VAR_STRING, "", "", "", NAME_CHAR_LEN*MAX_KEY, 0)) + goto error; + + if ( verify_prepare_field(result, 5, "key", "", MYSQL_TYPE_VAR_STRING, "", "", "", NAME_CHAR_LEN, 0)) + goto error; + + if (mysql_get_server_version(mysql) <= 50000) + { + if (verify_prepare_field(result, 6, "key_len", "", MYSQL_TYPE_LONGLONG, "", "", "", 3, 0)) + goto error; + } + else if (mysql_get_server_version(mysql) <= 60000) + { + if (verify_prepare_field(result, 6, "key_len", "", MYSQL_TYPE_VAR_STRING, "", "", "", NAME_CHAR_LEN*MAX_KEY, 0)) + goto error; + } + else + { + if (verify_prepare_field(result, 6, "key_len", "", MYSQL_TYPE_VAR_STRING, "", "", "", (MAX_KEY_LENGTH_DECIMAL_WIDTH + 1) * MAX_KEY, 0)) + goto error; + } + + if (verify_prepare_field(result, 7, "ref", "", MYSQL_TYPE_VAR_STRING, "", "", "", + NAME_CHAR_LEN*16, 0)) + goto error; + + if (verify_prepare_field(result, 8, "rows", "", MYSQL_TYPE_LONGLONG, "", "", "", 10, 0)) + goto error; + + if (verify_prepare_field(result, 9, "Extra", "", MYSQL_TYPE_VAR_STRING, "", "", "", 255, 0)) + goto error; + + mysql_free_result(result); + mysql_stmt_close(stmt); + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_explain"); + check_mysql_rc(rc, mysql); + return OK; +error: + mysql_free_result(result); + mysql_stmt_close(stmt); + return FAIL; +} + +static int test_sshort_bug(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + MYSQL_BIND my_bind[4]; + short short_value; + int32 long_value; + ulong s_length, l_length, ll_length, t_length; + ulonglong longlong_value; + int rc; + uchar tiny_value; + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_sshort"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE test_sshort(a smallint signed, \ + b smallint signed, \ + c smallint unsigned, \ + d smallint unsigned)"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "INSERT INTO test_sshort VALUES(-5999, -5999, 35999, 200)"); + check_mysql_rc(rc, mysql); + + + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL("SELECT * FROM test_sshort")); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + memset(my_bind, '\0', sizeof(my_bind)); + my_bind[0].buffer_type= MYSQL_TYPE_SHORT; + my_bind[0].buffer= (void *)&short_value; + my_bind[0].length= &s_length; + + my_bind[1].buffer_type= MYSQL_TYPE_LONG; + my_bind[1].buffer= (void *)&long_value; + my_bind[1].length= &l_length; + + my_bind[2].buffer_type= MYSQL_TYPE_LONGLONG; + my_bind[2].buffer= (void *)&longlong_value; + my_bind[2].length= &ll_length; + + my_bind[3].buffer_type= MYSQL_TYPE_TINY; + my_bind[3].buffer= (void *)&tiny_value; + my_bind[3].is_unsigned= TRUE; + my_bind[3].length= &t_length; + + rc= mysql_stmt_bind_result(stmt, my_bind); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + + FAIL_UNLESS(short_value == -5999, "sv != -5999"); + FAIL_UNLESS(s_length == 2, "s_length != 2"); + + FAIL_UNLESS(long_value == -5999, "l_v != -5999"); + FAIL_UNLESS(l_length == 4, "l_length != 4"); + + FAIL_UNLESS(longlong_value == 35999, "llv != 35999"); + FAIL_UNLESS(ll_length == 8, "ll_length != 8"); + + FAIL_UNLESS(tiny_value == 200, "t_v != 200"); + FAIL_UNLESS(t_length == 1, "t_length != 1"); + + rc= mysql_stmt_fetch(stmt); + FAIL_UNLESS(rc == MYSQL_NO_DATA, "rc != MYSQL_NO_DATA"); + + mysql_stmt_close(stmt); + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_sshort"); + check_mysql_rc(rc, mysql); + return OK; +} + + +/* Test a misc tinyint-signed conversion bug */ + +static int test_stiny_bug(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + MYSQL_BIND my_bind[4]; + short short_value; + int32 long_value; + ulong s_length, l_length, ll_length, t_length; + ulonglong longlong_value; + int rc; + uchar tiny_value; + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_stiny"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE test_stiny(a tinyint signed, \ + b tinyint signed, \ + c tinyint unsigned, \ + d tinyint unsigned)"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "INSERT INTO test_stiny VALUES(-128, -127, 255, 0)"); + check_mysql_rc(rc, mysql); + + + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL("SELECT * FROM test_stiny")); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + memset(my_bind, '\0', sizeof(my_bind)); + my_bind[0].buffer_type= MYSQL_TYPE_SHORT; + my_bind[0].buffer= (void *)&short_value; + my_bind[0].length= &s_length; + + my_bind[1].buffer_type= MYSQL_TYPE_LONG; + my_bind[1].buffer= (void *)&long_value; + my_bind[1].length= &l_length; + + my_bind[2].buffer_type= MYSQL_TYPE_LONGLONG; + my_bind[2].buffer= (void *)&longlong_value; + my_bind[2].length= &ll_length; + + my_bind[3].buffer_type= MYSQL_TYPE_TINY; + my_bind[3].buffer= (void *)&tiny_value; + my_bind[3].length= &t_length; + + rc= mysql_stmt_bind_result(stmt, my_bind); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + + FAIL_UNLESS(short_value == -128, "s_v != -128"); + FAIL_UNLESS(s_length == 2, "s_length != 2"); + + FAIL_UNLESS(long_value == -127, "l_v != -127"); + FAIL_UNLESS(l_length == 4, "l_length != 4"); + + FAIL_UNLESS(longlong_value == 255, "llv != 255"); + FAIL_UNLESS(ll_length == 8, "ll_length != 8"); + + FAIL_UNLESS(tiny_value == 0, "t_v != 0"); + FAIL_UNLESS(t_length == 1, "t_length != 1"); + + rc= mysql_stmt_fetch(stmt); + FAIL_UNLESS(rc == MYSQL_NO_DATA, "rc != MYSQL_NO_DATA"); + + mysql_stmt_close(stmt); + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_stiny"); + check_mysql_rc(rc, mysql); + return OK; +} + +static int test_bug53311(MYSQL *mysql) +{ + int rc; + MYSQL_STMT *stmt; + int i; + const char *query= "INSERT INTO bug53311 VALUES (1)"; + SKIP_MAXSCALE; + + rc= mysql_options(mysql, MYSQL_OPT_RECONNECT, "1"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS bug53311"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE bug53311 (a int)"); + check_mysql_rc(rc, mysql); + + stmt= mysql_stmt_init(mysql); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + for (i=0; i < 2; i++) + { + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + } + + /* kill connection */ + rc= mysql_kill(mysql, mysql_thread_id(mysql)); + + rc= mysql_stmt_execute(stmt); + FAIL_IF(rc == 0, "Error expected"); + FAIL_IF(mysql_stmt_errno(stmt) == 0, "Errno != 0 expected"); + rc= mysql_stmt_close(stmt); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "DROP TABLE IF EXISTS bug53311"); + check_mysql_rc(rc, mysql); + + return OK; +} +#define PREPARE_SQL "EXPLAIN SELECT t1.*, t2.* FROM test AS t1, test AS t2" + +#ifdef NOT_IN_USE +static int test_metadata(MYSQL *mysql) +{ + int rc; + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "CREATE TABLE test(id INT, label CHAR(1), PRIMARY KEY(id)) ENGINE=MYISAM"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "INSERT INTO test(id, label) VALUES (1, 'a'), (2, 'b'), (3, 'c'), (4, 'd'), (5, 'e'), (6, 'f')"); + check_mysql_rc(rc, mysql); + printf("Client=%s\n", mysql_get_client_info()); + printf("Server=%s\n", mysql_get_server_info(mysql)); + + { + MYSQL_STMT * stmt = mysql_stmt_init(mysql); + if (!stmt) { + fprintf(stderr, "Failed to init stmt: Error: %s\n", mysql_error(mysql)); + goto end; + } + if (mysql_stmt_prepare(stmt, PREPARE_SQL, sizeof(PREPARE_SQL) - 1)) { + fprintf(stderr, "Failed to prepare stmt: Error: %s\n", mysql_stmt_error(stmt)); + goto end2; + } + if (mysql_stmt_execute(stmt)) { + fprintf(stderr, "Failed to execute stmt: Error: %s\n", mysql_stmt_error(stmt)); + goto end2; + } + { + MYSQL_FIELD * field = NULL; + MYSQL_RES * res = mysql_stmt_result_metadata(stmt); + if (!res) { + fprintf(stderr, "Failed to get metadata: Error: %s\n", mysql_stmt_error(stmt)); + goto end2; + } + while ((field = mysql_fetch_field(res))) { + printf("name=%s\n", field->name); + printf("catalog=%s\n", field->catalog); + } + mysql_free_result(res); + + } +end2: + mysql_stmt_close(stmt); + } +end: + return 0; +} +#endif + +static int test_conc_5(MYSQL *mysql) +{ + const char *query= "SELECT a FROM t1"; + MYSQL_RES *res; + MYSQL_STMT *stmt; + MYSQL_FIELD *fields; + int rc; + + 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)"); + check_mysql_rc(rc, mysql); + + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, "couldn't allocate memory"); + + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + res= mysql_stmt_result_metadata(stmt); + FAIL_IF(!res, "Can't obtain resultset"); + + fields= mysql_fetch_fields(res); + FAIL_IF(!fields, "Can't obtain fields"); + + FAIL_IF(strcmp("def", fields[0].catalog), "unexpected value for field->catalog"); + + mysql_free_result(res); + mysql_stmt_close(stmt); + return OK; +} + +static int test_conc141(MYSQL *mysql) +{ + int rc; + const char *query= "CALL p_conc141"; + MYSQL_STMT *stmt= mysql_stmt_init(mysql); + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS conc141"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "CREATE TABLE conc141 (KeyVal int not null primary key)"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "INSERT INTO conc141 VALUES(1)"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "DROP PROCEDURE IF EXISTS p_conc141"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "CREATE PROCEDURE p_conc141()\n" + "BEGIN\n" + "select * from conc141;\n" + "insert into conc141(KeyVal) VALUES(1);\n" + "END"); + check_mysql_rc(rc, mysql); + + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + /* skip first result */ + rc= mysql_stmt_next_result(stmt); + FAIL_IF(rc==-1, "No more results and error expected"); + mysql_stmt_free_result(stmt); + FAIL_IF(mysql_stmt_errno(stmt), "No Error expected"); + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + mysql_stmt_close(stmt); + rc= mysql_query(mysql, "DROP TABLE IF EXISTS conc141"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "DROP PROCEDURE IF EXISTS p_conc141"); + check_mysql_rc(rc, mysql); + return OK; +} + +static int test_conc154(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + const char *stmtstr= "SELECT * FROM t1"; + int rc; + + /* 1st: empty result set without free_result */ + rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "CREATE TABLE t1 (a varchar(20))"); + check_mysql_rc(rc, mysql); + + stmt= mysql_stmt_init(mysql); + rc= mysql_stmt_prepare(stmt, SL(stmtstr)); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_store_result(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_store_result(stmt); + check_stmt_rc(rc, stmt); + + mysql_stmt_close(stmt); + + /* 2nd: empty result set with free_result */ + stmt= mysql_stmt_init(mysql); + rc= mysql_stmt_prepare(stmt, SL(stmtstr)); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_store_result(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_free_result(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_store_result(stmt); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_free_result(stmt); + check_stmt_rc(rc, stmt); + + mysql_stmt_close(stmt); + + /* 3rd: non empty result without free_result */ + rc= mysql_query(mysql, "INSERT INTO t1 VALUES ('test_conc154')"); + check_mysql_rc(rc, mysql); + + stmt= mysql_stmt_init(mysql); + rc= mysql_stmt_prepare(stmt, SL(stmtstr)); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_store_result(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_store_result(stmt); + check_stmt_rc(rc, stmt); + + mysql_stmt_close(stmt); + + /* 4th non empty result set with free_result */ + stmt= mysql_stmt_init(mysql); + rc= mysql_stmt_prepare(stmt, SL(stmtstr)); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_store_result(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_free_result(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_store_result(stmt); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_free_result(stmt); + check_stmt_rc(rc, stmt); + + mysql_stmt_close(stmt); + rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1"); + check_mysql_rc(rc, mysql); + + return OK; +} + +static int test_conc155(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + MYSQL_BIND bind; + char buffer[50]; + int rc; + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "CREATE TABLE t1 (a TEXT)"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "INSERT INTO t1 VALUES ('zero terminated string')"); + check_mysql_rc(rc, mysql); + + stmt= mysql_stmt_init(mysql); + rc= mysql_stmt_prepare(stmt, SL("SELECT a FROM t1")); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + memset(buffer, 'X', 50); + memset(&bind, 0, sizeof(MYSQL_BIND)); + + bind.buffer= buffer; + bind.buffer_length= 50; + bind.buffer_type= MYSQL_TYPE_STRING; + + rc= mysql_stmt_bind_result(stmt, &bind); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + + if (strlen(buffer) != strlen("zero terminated string")) + { + diag("Wrong buffer length"); + return FAIL; + } + + mysql_stmt_close(stmt); + rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1"); + check_mysql_rc(rc, mysql); + return OK; +} + +static int test_conc168(MYSQL *mysql) +{ + MYSQL_STMT *stmt= mysql_stmt_init(mysql); + + MYSQL_BIND bind; + char buffer[100]; + int rc; + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS conc168"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "CREATE TABLE conc168(a datetime(3))"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "INSERT INTO conc168 VALUES ('2016-03-09 07:51:49.000'),('2016-03-09 07:51:49.001'),('2016-03-09 07:51:49.010')"); + check_mysql_rc(rc, mysql); + + memset(&bind, 0, sizeof(MYSQL_BIND)); + bind.buffer= buffer; + bind.buffer_type= MYSQL_TYPE_STRING; + bind.buffer_length= 100; + + rc= mysql_stmt_prepare(stmt, SL("SELECT a FROM conc168")); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_bind_result(stmt, &bind); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + FAIL_IF(strcmp(buffer, "2016-03-09 07:51:49.000"), "expected: 2016-03-09 07:51:49.000"); + + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + FAIL_IF(strcmp(buffer, "2016-03-09 07:51:49.001"), "expected: 2016-03-09 07:51:49.001"); + + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + FAIL_IF(strcmp(buffer, "2016-03-09 07:51:49.010"), "expected: 2016-03-09 07:51:49.010"); + + mysql_stmt_close(stmt); + rc= mysql_query(mysql, "DROP TABLE IF EXISTS conc168"); + check_mysql_rc(rc, mysql); + return OK; +} + +static int test_conc167(MYSQL *mysql) +{ + MYSQL_STMT *stmt= mysql_stmt_init(mysql); + + MYSQL_BIND bind[3]; + char buffer[100]; + int bit1=0, bit2=0; + int rc; + const char *stmt_str= "SELECT a,b,c FROM conc168"; + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS conc168"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "CREATE TABLE conc168(a bit, b bit, c varchar(10))"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "INSERT INTO conc168 VALUES (1,0, 'test12345')"); + check_mysql_rc(rc, mysql); + + memset(bind, 0, 3 * sizeof(MYSQL_BIND)); + bind[0].buffer= &bit1; + bind[0].buffer_type= MYSQL_TYPE_BIT; + bind[0].buffer_length= sizeof(int); + bind[1].buffer= &bit2; + bind[1].buffer_type= MYSQL_TYPE_BIT; + bind[1].buffer_length= sizeof(int); + bind[2].buffer= buffer; + bind[2].buffer_type= MYSQL_TYPE_STRING; + bind[2].buffer_length= 100; + + rc= mysql_stmt_prepare(stmt, SL(stmt_str)); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_bind_result(stmt, bind); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_store_result(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + + diag("bit=%d %d char=%s", bit1, bit2, buffer); + + mysql_stmt_close(stmt); + return OK; +} + +static int test_conc177(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + int rc; + MYSQL_BIND bind[2]; + const char *stmt_str= "SELECT a,b FROM t1"; + char buf1[128], buf2[128]; + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE t1 (a double zerofill default 8.8,b float zerofill default 8.8)"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "INSERT INTO t1 VALUES (DEFAULT, DEFAULT)"); + check_mysql_rc(rc, mysql); + + stmt= mysql_stmt_init(mysql); + rc= mysql_stmt_prepare(stmt, SL(stmt_str)); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + memset(bind, 0, 2 * sizeof(MYSQL_BIND)); + bind[0].buffer= &buf1; + bind[0].buffer_type= MYSQL_TYPE_STRING; + bind[0].buffer_length= 128; + bind[1].buffer= &buf2; + bind[1].buffer_type= MYSQL_TYPE_STRING; + bind[1].buffer_length= 128; + + rc= mysql_stmt_bind_result(stmt, bind); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_fetch(stmt); + mysql_stmt_close(stmt); + + diag("buf1 %s\nbuf2 %s", buf1, buf2); + + FAIL_IF(strcmp(buf1, "00000000000000000008.8"), "Expected 00000000000000000008.8"); + FAIL_IF(strcmp(buf2, "0000000008.8"), "Expected 0000000008.8"); + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE t1 (a int(8) zerofill default 1, b int(4) zerofill default 1)"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "INSERT INTO t1 VALUES (DEFAULT, DEFAULT)"); + check_mysql_rc(rc, mysql); + + stmt= mysql_stmt_init(mysql); + rc= mysql_stmt_prepare(stmt, SL(stmt_str)); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + memset(bind, 0, 2 * sizeof(MYSQL_BIND)); + bind[0].buffer= &buf1; + bind[0].buffer_type= MYSQL_TYPE_STRING; + bind[0].buffer_length= 128; + bind[1].buffer= &buf2; + bind[1].buffer_type= MYSQL_TYPE_STRING; + bind[1].buffer_length= 128; + + rc= mysql_stmt_bind_result(stmt, bind); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_fetch(stmt); + mysql_stmt_close(stmt); + + diag("buf1 %s\nbuf2 %s", buf1, buf2); + + FAIL_IF(strcmp(buf1, "00000001"), "Expected 00000001"); + FAIL_IF(strcmp(buf2, "0001"), "Expected 0001"); + rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1"); + check_mysql_rc(rc, mysql); + return OK; +} + +static int test_conc179(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + int rc; + const char *stmtstr= "select 1 as ' '"; + + stmt= mysql_stmt_init(mysql); + rc= mysql_stmt_prepare(stmt, SL(stmtstr)); + check_stmt_rc(rc, stmt); + + if (mysql_get_server_version(mysql) >= 100100) + { + FAIL_IF(mysql_warning_count(mysql) < 1, "expected 1 or more warnings"); + FAIL_IF(mysql_stmt_warning_count(stmt) < 1, "expected 1 or more warnings"); + } + + mysql_stmt_close(stmt); + rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1"); + check_mysql_rc(rc, mysql); + + return OK; +} + +static int test_conc182(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + int rc; + MYSQL_BIND bind[2]; + char buf1[22]; + MYSQL_RES *result; + MYSQL_ROW row; + + stmt= mysql_stmt_init(mysql); + rc= mariadb_stmt_execute_direct(stmt, "DROP TABLE IF EXISTS t1", -1); + check_stmt_rc(rc, stmt); + rc= mariadb_stmt_execute_direct(stmt, "DROP TABLE IF EXISTS t1", -1); + check_stmt_rc(rc, stmt); + rc= mariadb_stmt_execute_direct(stmt, "SELECT 1", -1); + check_stmt_rc(rc, stmt); + rc= mariadb_stmt_execute_direct(stmt, "SELECT 1", -1); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_close(stmt); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "SELECT row_count()"); + result= mysql_store_result(mysql); + row= mysql_fetch_row(result); + diag("buf: %s", row[0]); + mysql_free_result(result); + + + stmt= mysql_stmt_init(mysql); + rc= mysql_stmt_prepare(stmt, "SELECT row_count()", -1); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_execute(stmt); + + memset(bind, 0, 2 * sizeof(MYSQL_BIND)); + bind[0].buffer= &buf1; + bind[0].buffer_length= bind[1].buffer_length= 20; + bind[0].buffer_type= bind[1].buffer_type= MYSQL_TYPE_STRING; + + rc= mysql_stmt_bind_result(stmt, bind); + + while(!mysql_stmt_fetch(stmt)) + diag("b1: %s", buf1); + rc= mysql_stmt_close(stmt); + rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1"); + check_mysql_rc(rc, mysql); + return OK; +} + +static int test_conc181(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + int rc; + MYSQL_BIND bind; + const char *stmt_str= "SELECT a FROM t1"; + float f=1; + my_bool err= 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(1073741825)"); + check_mysql_rc(rc, mysql); + + stmt= mysql_stmt_init(mysql); + rc= mysql_stmt_prepare(stmt, SL(stmt_str)); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + memset(&bind, 0, sizeof(MYSQL_BIND)); + bind.buffer= &f; + bind.error= &err; + bind.buffer_type= MYSQL_TYPE_FLOAT; + rc= mysql_stmt_bind_result(stmt, &bind); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_fetch(stmt); + diag("rc=%d err=%d float=%f, %d", rc, err, f, MYSQL_DATA_TRUNCATED); + + rc= mysql_stmt_close(stmt); + rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1"); + check_mysql_rc(rc, mysql); + return OK; +} + +static int test_conc198(MYSQL *mysql) +{ + MYSQL_STMT *stmt1, *stmt2; + MYSQL_BIND my_bind[1]; + int32 a; + int rc; + int num_rows= 0; + ulong type; + ulong prefetch_rows= 3; + + + mysql_query(mysql, "drop table if exists t1"); + mysql_query(mysql, "create table t1 (id integer not null primary key)"); + rc= mysql_query(mysql, "insert into t1 (id) values " + " (1), (2), (3), (4), (5), (6), (7), (8), (9)"); + check_mysql_rc(rc, mysql); + + stmt1= mysql_stmt_init(mysql); + stmt2= mysql_stmt_init(mysql); + /* Not implemented in 5.0 */ + type= (ulong) CURSOR_TYPE_SCROLLABLE; + rc= mysql_stmt_attr_set(stmt1, STMT_ATTR_CURSOR_TYPE, (void*) &type); + FAIL_UNLESS(rc, "Error expected"); + rc= mysql_stmt_attr_set(stmt2, STMT_ATTR_CURSOR_TYPE, (void*) &type); + FAIL_UNLESS(rc, "Error expected"); + + type= (ulong) CURSOR_TYPE_READ_ONLY; + rc= mysql_stmt_attr_set(stmt1, STMT_ATTR_CURSOR_TYPE, (void*) &type); + check_stmt_rc(rc, stmt1); + rc= mysql_stmt_attr_set(stmt2, STMT_ATTR_CURSOR_TYPE, (void*) &type); + check_stmt_rc(rc, stmt2); + rc= mysql_stmt_attr_set(stmt1, STMT_ATTR_PREFETCH_ROWS, + (void*) &prefetch_rows); + check_stmt_rc(rc, stmt1); + rc= mysql_stmt_attr_set(stmt2, STMT_ATTR_PREFETCH_ROWS, + (void*) &prefetch_rows); + check_stmt_rc(rc, stmt2); + rc= mysql_stmt_prepare(stmt1, "SELECT * FROM t1 ORDER by id ASC" , -1); + check_stmt_rc(rc, stmt1); + rc= mysql_stmt_prepare(stmt2, "SELECT * FROM t1 ORDER by id DESC", -1); + check_stmt_rc(rc, stmt2); + + rc= mysql_stmt_execute(stmt1); + check_stmt_rc(rc, stmt1); + rc= mysql_stmt_execute(stmt2); + check_stmt_rc(rc, stmt2); + + memset(my_bind, '\0', sizeof(my_bind)); + my_bind[0].buffer_type= MYSQL_TYPE_LONG; + my_bind[0].buffer= (void*) &a; + my_bind[0].buffer_length= sizeof(a); + mysql_stmt_bind_result(stmt1, my_bind); + mysql_stmt_bind_result(stmt2, my_bind); + + while ((rc= mysql_stmt_fetch(stmt1)) == 0) + ++num_rows; + FAIL_UNLESS(num_rows == 9, "num_rows != 9"); + + num_rows= 0; + while ((rc= mysql_stmt_fetch(stmt2)) == 0) + ++num_rows; + FAIL_UNLESS(num_rows == 9, "num_rows != 9"); + + rc= mysql_stmt_close(stmt1); + rc= mysql_stmt_close(stmt2); + FAIL_UNLESS(rc == 0, ""); + + rc= mysql_query(mysql, "drop table t1"); + check_mysql_rc(rc, mysql); + return OK; +} + +static int test_conc205(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + MYSQL_BIND my_bind[3]; + char data[8]; + ulong length[3]; + int rc, int_col; + short smint_col; + my_bool is_null[3]; + const char *query = "SELECT text_col, smint_col, int_col FROM test_conc205"; + + rc= mysql_query(mysql, "drop table if exists test_conc205"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "CREATE TABLE test_conc205 (text_col TEXT, smint_col SMALLINT, int_col INT)"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "INSERT INTO test_conc205 VALUES('data01', 21893, 1718038908), ('data2', -25734, -1857802040)"); + check_mysql_rc(rc, mysql); + + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + memset(my_bind, '\0', sizeof(my_bind)); + my_bind[0].buffer_type= MYSQL_TYPE_STRING; + my_bind[0].buffer= (void *)data; + my_bind[0].buffer_length= sizeof(data); + my_bind[0].is_null= &is_null[0]; + my_bind[0].length= &length[0]; + + my_bind[1].buffer_type= MYSQL_TYPE_SHORT; + my_bind[1].buffer= &smint_col; + my_bind[1].buffer_length= 2; + my_bind[1].is_null= &is_null[1]; + my_bind[1].length= &length[1]; + + my_bind[2].buffer_type= MYSQL_TYPE_LONG; + my_bind[2].buffer= &int_col; + my_bind[2].buffer_length= 4; + my_bind[2].is_null= &is_null[2]; + my_bind[2].length= &length[2]; + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_bind_result(stmt, my_bind); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + + FAIL_IF(length[0] != 6, "Wrong fetched string length"); + FAIL_IF(length[1] != 2, "Wrong fetched short length"); + FAIL_IF(length[2] != 4, "Wrong fetched int length"); + + FAIL_IF(strncmp(data, "data01", length[0] + 1) != 0, "Wrong string value"); + FAIL_IF(smint_col != 21893, "Expected 21893"); + FAIL_IF(int_col != 1718038908, "Expected 1718038908"); + + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + + FAIL_IF(length[0] != 5, "Wrong fetched string length"); + FAIL_IF(length[1] != 2, "Wrong fetched short length"); + FAIL_IF(length[2] != 4, "Wrong fetched int length"); + + FAIL_IF(strncmp(data, "data2", length[0] + 1) != 0, "Wrong string value"); + FAIL_IF(smint_col != -25734, "Expected 21893"); + FAIL_IF(int_col != -1857802040, "Expected 1718038908"); + + rc= mysql_stmt_fetch(stmt); + FAIL_IF(rc != MYSQL_NO_DATA, "Expected MYSQL_NO_DATA"); + + mysql_stmt_close(stmt); + + rc= mysql_query(mysql, "drop table test_conc205"); + check_mysql_rc(rc, mysql); + + return OK; +} + +static int test_conc217(MYSQL *mysql) +{ + MYSQL_STMT *stmt= mysql_stmt_init(mysql); + int rc; + + SKIP_MAXSCALE; + rc= mariadb_stmt_execute_direct(stmt, "SELECT 1 FROM nonexisting_table", -1); + FAIL_IF(rc==0, "Expected error\n"); + rc= mysql_query(mysql, "drop table if exists t_count"); + check_mysql_rc(rc, mysql); + mysql_stmt_close(stmt); + check_mysql_rc(rc, mysql); + return OK; +} + +static int test_conc208(MYSQL *mysql) +{ + MYSQL_STMT *stmt= mysql_stmt_init(mysql); + int rc; + int data; + MYSQL_BIND bind; + + rc= mysql_stmt_prepare(stmt, "SELECT \"100\" UNION SELECT \"88\" UNION SELECT \"389789\"", -1); + check_stmt_rc(rc, stmt); + + memset(&bind, 0, sizeof(MYSQL_BIND)); + bind.buffer_type= MYSQL_TYPE_LONG; + bind.buffer= (void *)&data; + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_bind_result(stmt, &bind); + + while (mysql_stmt_fetch(stmt) != MYSQL_NO_DATA) + { + diag("data=%d", data); + FAIL_IF(data != 100 && data != 88 && data != 389789, "Wrong value"); + } + mysql_stmt_close(stmt); + return OK; +} + +static int test_mdev14165(MYSQL *mysql) +{ + int rc; + MYSQL_STMT *stmt= mysql_stmt_init(mysql); + MYSQL_FIELD *fields; + MYSQL_RES *result; + my_bool val= 1; + MYSQL_BIND bind[1]; + char buf1[52]; + + rc= mysql_options(mysql, MYSQL_REPORT_DATA_TRUNCATION, &val); + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1"); + rc= mysql_query(mysql, "CREATE TABLE t1 (i INT(20) ZEROFILL)"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "INSERT INTO t1 VALUES (2),(1)"); + check_mysql_rc(rc, mysql); + rc= mysql_stmt_prepare(stmt, "SELECT i FROM t1", -1); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + memset(bind, 0, sizeof(MYSQL_BIND)); + bind[0].buffer_type= MYSQL_TYPE_STRING; + bind[0].buffer_length= 51; + bind[0].buffer= buf1; + + mysql_stmt_bind_result(stmt, bind); + + rc= mysql_stmt_attr_set(stmt, STMT_ATTR_UPDATE_MAX_LENGTH, &val); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_store_result(stmt); + check_stmt_rc(rc, stmt); + + result= mysql_stmt_result_metadata(stmt); + + fields= mysql_fetch_fields(result); + + FAIL_IF(fields[0].length < 20, "Expected length=20"); + FAIL_IF(fields[0].max_length < 20, "Expected max_length=20"); + + mysql_stmt_fetch(stmt); + + FAIL_UNLESS(strcmp(buf1, "00000000000000000002") == 0, "Wrong result"); + mysql_free_result(result); + + mysql_stmt_close(stmt); + + rc= mysql_query(mysql, "DROP TABLE t1"); + check_mysql_rc(rc, mysql); + return OK; +} + +static int test_compress(MYSQL *mysql) +{ + MYSQL_STMT *stmt= mysql_stmt_init(mysql); + int rc; + + rc= mariadb_stmt_execute_direct(stmt, SL("SELECT 1 FROM DUAL")); + check_stmt_rc(rc, stmt); + + mysql_stmt_close(stmt); + + return OK; +} + +static int equal_MYSQL_TIME(MYSQL_TIME *tm1, MYSQL_TIME *tm2) +{ + return tm1->day==tm2->day && tm1->hour==tm2->hour && tm1->minute==tm2->minute && + tm1->month==tm2->month && tm1->neg==tm2->neg && tm1->second==tm2->second && + tm1->second_part==tm2->second_part && tm1->time_type==tm2->time_type && tm1->year==tm2->year; +} + +static int test_str_to_int(MYSQL *mysql) +{ + int i; + struct st_atoi_test{ + const char *str_value; + int int_value; + int rc; + } atoi_tests[]= + { + {"0", 0, 0}, + {" 1",1, 0}, + {"123 ",123, 0}, + {"10.2",10, MYSQL_DATA_TRUNCATED}, + {"a", 0, MYSQL_DATA_TRUNCATED}, + {"1 2 3", 1, MYSQL_DATA_TRUNCATED}, + {NULL, 0, 0} + }; + + for(i=0; atoi_tests[i].str_value; i++) + { + int rc; + MYSQL_STMT *stmt; + MYSQL_BIND bind[1]; + struct st_atoi_test *test= &atoi_tests[i]; + char sql[256]; + int int_value; + + snprintf(sql, sizeof(sql), "SELECT '%s'",test->str_value); + + stmt= mysql_stmt_init(mysql); + + rc= mysql_stmt_prepare(stmt, sql, (ulong)strlen(sql)); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_store_result(stmt); + + memset(bind, 0, sizeof(MYSQL_BIND)); + bind[0].buffer_type= MYSQL_TYPE_LONG; + bind[0].buffer= &int_value; + bind[0].buffer_length= sizeof(int_value); + + rc= mysql_stmt_bind_result(stmt, bind); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_fetch(stmt); + + diag("test: str='%s', expected/returned value =%d/%d, expected/returned rc=%d/%d", + test->str_value, test->int_value, int_value, test->rc, rc); + FAIL_UNLESS(rc == test->rc, "unexpected return code"); + FAIL_UNLESS(int_value == test->int_value, "unexpected int value"); + mysql_stmt_close(stmt); + } + return OK; +} + + +static int test_codbc138(MYSQL *mysql) +{ + int rc; + MYSQL_STMT *stmt; + MYSQL_BIND bind[1]; + MYSQL_TIME tm; + int i= 0; + + struct st_time_test { + const char *statement; + MYSQL_TIME tm; + } time_test[]={ + { "SELECT DATE_ADD('2018-02-01', INTERVAL -188 DAY)", + { 2017,7,28,0,0,0,0L,0, MYSQL_TIMESTAMP_DATE } + }, + { "SELECT '2001-02-03 11:12:13.123456'", + { 2001,2,3,11,12,13,123456L,0, MYSQL_TIMESTAMP_DATETIME } + }, + { "SELECT '2001-02-03 11:12:13.123'", + { 2001,2,3,11,12,13,123000L,0, MYSQL_TIMESTAMP_DATETIME } + }, + { "SELECT '-11:12:13'", + { 0,0,0,11,12,13,0,1, MYSQL_TIMESTAMP_TIME } + }, + { "SELECT ' '", + { 0,0,0,0,0,0,0,0, MYSQL_TIMESTAMP_ERROR } + }, + { "SELECT '1--'", + { 0,0,0,0,0,0,0,0, MYSQL_TIMESTAMP_ERROR } + }, + { "SELECT '-2001-01-01'", + { 0,0,0,0,0,0,0,0, MYSQL_TIMESTAMP_ERROR } + }, + { "SELECT '-11:00'", + { 0,0,0,0,0,0,0,0, MYSQL_TIMESTAMP_ERROR } + }, + {"SELECT '1972-04-22'", + {1972,4,22, 0,0,0, 0,0,MYSQL_TIMESTAMP_DATE} + }, + {"SELECT ' 1972-04-22 '", + {1972,4,22, 0,0,0, 0,0,MYSQL_TIMESTAMP_DATE} + }, + {"SELECT '1972-04-22a'", + {1972,4,22, 0,0,0, 0,0,MYSQL_TIMESTAMP_DATE} + }, + {"SELECT '0000-00-00'", + {0,0,0, 0,0,0 ,0,0,MYSQL_TIMESTAMP_DATE} + }, + {"SELECT '1970-01-00'", + {1970,1,0, 0,0,0, 0,0, MYSQL_TIMESTAMP_DATE} + }, + {"SELECT '0069-12-31'", + {69,12,31, 0,0,0, 0,0, MYSQL_TIMESTAMP_DATE} + }, + {"SELECT '69-12-31'", + {2069,12,31, 0,0,0, 0,0, MYSQL_TIMESTAMP_DATE} + }, + {"SELECT '68-12-31'", + {2068,12,31, 0,0,0, 0,0, MYSQL_TIMESTAMP_DATE} + }, + {"SELECT '70-01-01'", + {1970,1,1, 0,0,0, 0,0, MYSQL_TIMESTAMP_DATE} + }, + {"SELECT '2010-1-1'", + {2010,1,1, 0,0,0, 0,0, MYSQL_TIMESTAMP_DATE} + }, + + {"SELECT '10000-01-01'", + {0,0,0, 0,0,0, 0,0, MYSQL_TIMESTAMP_ERROR} + }, + {"SELECT '1979-a-01'", + {0,0,0, 0,0,0, 0,0, MYSQL_TIMESTAMP_ERROR} + }, + {"SELECT '1979-01-32'", + {0,0,0, 0,0,0, 0,0, MYSQL_TIMESTAMP_ERROR} + }, + {"SELECT '1979-13-01'", + {0,0,0, 0,0,0, 0,0, MYSQL_TIMESTAMP_ERROR} + }, + {"SELECT '1YYY-01-01'", + {0,0,0, 0,0,0, 0,0, MYSQL_TIMESTAMP_ERROR} + }, + {"SELECT '1979-0M-01'", + {0,0,0, 0,0,0, 0,0, MYSQL_TIMESTAMP_ERROR} + }, + {"SELECT '1979-00-'", + {0,0,0, 0,0,0, 0,0, MYSQL_TIMESTAMP_ERROR} + }, + {"SELECT '1979-00'", + {0,0,0, 0,0,0, 0,0,MYSQL_TIMESTAMP_ERROR} + }, + {"SELECT '1979'", + {0,0,0, 0,0,0, 0,0, MYSQL_TIMESTAMP_ERROR} + }, + {"SELECT '79'", + {0,0,0, 0,0,0, 0,0, MYSQL_TIMESTAMP_ERROR} + }, + + {"SELECT '10:15:00'", + {0,0,0, 10,15,0, 0,0, MYSQL_TIMESTAMP_TIME} + }, + {"SELECT '10:15:01'", + {0,0,0, 10,15,1, 0,0, MYSQL_TIMESTAMP_TIME} + }, + {"SELECT '00:00:00'", + {0,0,0, 0,0,0, 0,0, MYSQL_TIMESTAMP_TIME} + }, + {"SELECT '0:0:0'", + {0,0,0, 0,0,0, 0,0, MYSQL_TIMESTAMP_TIME} + }, + {"SELECT '10:15:01.'", + {0,0,0, 10,15,1, 0,0, MYSQL_TIMESTAMP_TIME}, + }, + {"SELECT '25:59:59'", + {0,0,0, 25,59,59, 0,0, MYSQL_TIMESTAMP_TIME}, + }, + {"SELECT '838:59:59'", + {0,0,0, 838,59,59, 0,0, MYSQL_TIMESTAMP_TIME}, + }, + {"SELECT '-838:59:59'", + {0,0,0, 838,59,59, 0, 1, MYSQL_TIMESTAMP_TIME}, + }, + + {"SELECT '00:60:00'", + {0,0,0, 0,0,0, 0,0, MYSQL_TIMESTAMP_ERROR}, + }, + {"SELECT '00:60:00'", + {0,0,0, 0,0,0, 0,0, MYSQL_TIMESTAMP_ERROR}, + }, + {"SELECT '839:00:00'", + {0,0,0, 0,0,0, 0,0, MYSQL_TIMESTAMP_ERROR}, + }, + {"SELECT '-839:00:00'", + {0,0,0, 0,0,0, 0,0, MYSQL_TIMESTAMP_ERROR}, + }, + {"SELECT '-10:15:a'", + { 0,0,0, 0,0,0, 0,0, MYSQL_TIMESTAMP_ERROR }, + }, + {"SELECT '1999-12-31 23:59:59.9999999'", + {1999,12,31, 23,59,59, 999999, 0, MYSQL_TIMESTAMP_DATETIME}, + }, + {"SELECT '00-08-11 8:46:40'", + {2000,8,11, 8,46,40, 0,0, MYSQL_TIMESTAMP_DATETIME}, + }, + {"SELECT '1999-12-31 25:59:59.999999'", + {0,0,0, 0,0,0, 0,0, MYSQL_TIMESTAMP_ERROR }, + }, + { NULL,{ 0 } } + }; + + while (time_test[i].statement) + { + stmt= mysql_stmt_init(mysql); + rc= mysql_stmt_prepare(stmt, SL(time_test[i].statement)); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_store_result(stmt); + + memset(bind, 0, sizeof(MYSQL_BIND)); + bind[0].buffer_type= MYSQL_TYPE_DATETIME; + bind[0].buffer= &tm; + bind[0].buffer_length= sizeof(MYSQL_TIME); + + rc= mysql_stmt_bind_result(stmt, bind); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + diag("test: %s %d %d", time_test[i].statement, tm.time_type, time_test[i].tm.time_type); + if (time_test[i].tm.time_type == MYSQL_TIMESTAMP_ERROR) + { + FAIL_UNLESS(tm.time_type == MYSQL_TIMESTAMP_ERROR, "MYSQL_TIMESTAMP_ERROR expected"); + } + else + FAIL_UNLESS(equal_MYSQL_TIME(&tm, &time_test[i].tm), "time_in != time_out"); + mysql_stmt_close(stmt); + i++; + } + + return OK; +} + +static int test_conc334(MYSQL *mysql) +{ + MYSQL_STMT *stmt= mysql_stmt_init(mysql); + MYSQL_RES *result; + MYSQL_FIELD *field; + int rc; + + rc= mysql_stmt_prepare(stmt, SL("SHOW ENGINES")); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + result= mysql_stmt_result_metadata(stmt); + if (!result) + { + diag("Couldn't retrieve result set"); + mysql_stmt_close(stmt); + return FAIL; + } + + mysql_field_seek(result, 0); + + while ((field= mysql_fetch_field(result))) + { + FAIL_IF(field->name_length == 0, "Invalid name length (0)"); + FAIL_IF(field->table_length == 0, "Invalid name length (0)"); + } + mysql_free_result(result); + mysql_stmt_close(stmt); + + return OK; +} +static int test_conc344(MYSQL *mysql) +{ + MYSQL_STMT *stmt= mysql_stmt_init(mysql); + int rc; + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE t1 (a int, b int)"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "INSERT INTO t1 VALUES (1,1), (2,2),(3,3),(4,4),(5,5)"); + check_mysql_rc(rc, mysql); + + rc= mysql_stmt_prepare(stmt, SL("SELECT * FROM t1 ORDER BY a")); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + while (!mysql_stmt_fetch(stmt)); + FAIL_IF(mysql_stmt_num_rows(stmt) != 5, "expected 5 rows"); + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_fetch(stmt); + diag("num_rows: %lld", mysql_stmt_num_rows(stmt)); + FAIL_IF(mysql_stmt_num_rows(stmt) != 1, "expected 1 row"); + + mysql_stmt_close(stmt); + return OK; +} + + +static int test_conc_fraction(MYSQL *mysql) +{ + MYSQL_TIME tm; + MYSQL_BIND bind[1]; + char query[1024]; + int i; + MYSQL_STMT *stmt= mysql_stmt_init(mysql); + int rc; + unsigned long frac= 0; + + for (i=0; i < 10; i++, frac=frac*10+i) + { + unsigned long expected= 0; + sprintf(query, "SELECT '2018-11-05 22:25:59.%ld'", frac); + + diag("%d: %s", i, query); + + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + check_stmt_rc(rc, stmt); + rc= mysql_stmt_store_result(stmt); + + memset(bind, 0, sizeof(MYSQL_BIND)); + bind[0].buffer_type= MYSQL_TYPE_DATETIME; + bind[0].buffer= &tm; + bind[0].buffer_length= sizeof(MYSQL_TIME); + + rc= mysql_stmt_bind_result(stmt, bind); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + + diag("second_part: %ld", tm.second_part); + + expected= i > 6 ? 123456 : frac * (unsigned int)powl(10, (6 - i)); + + diag("tm.second_part=%ld expected=%ld", tm.second_part, expected); + FAIL_IF(tm.second_part != expected, "expected fractional part to be 900000"); + + } + mysql_stmt_close(stmt); + return OK; +} + +static int test_zerofill_1byte(MYSQL *mysql) +{ + MYSQL_STMT *stmt= mysql_stmt_init(mysql); + int rc; + MYSQL_BIND bind; + char buffer[3]; + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE t1 (a int zerofill)"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "INSERT INTO t1 VALUES(1)"); + check_mysql_rc(rc, mysql); + + rc= mysql_stmt_prepare(stmt, SL("SELECT a FROM t1")); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + memset(&bind, 0, sizeof(MYSQL_BIND)); + bind.buffer_type= MYSQL_TYPE_STRING; + bind.buffer= buffer; + bind.buffer_length= 1; + + rc= mysql_stmt_bind_result(stmt, &bind); + + rc= mysql_stmt_fetch(stmt); + FAIL_IF(rc != 101, "expected truncation warning"); + + mysql_stmt_close(stmt); + rc= mysql_query(mysql, "DROP TABLE t1"); + check_mysql_rc(rc, mysql); + + return OK; +} + +static int test_conc424(MYSQL *mysql) +{ + int rc; + MYSQL_STMT *stmt; + my_bool max_len= 1; + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_table1"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "CREATE TABLE test_table1 (test_int INT, b int)"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "INSERT INTO test_table1 values(10,11),(11,12)"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "DROP PROCEDURE IF EXISTS testCursor"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE PROCEDURE testCursor()\n" + "BEGIN\n" + "DECLARE test_int INT;\n" + "DECLARE b INT;\n" + "DECLARE done INT DEFAULT FALSE;\n" + "DECLARE testCursor CURSOR\n" + "FOR\n" + "SELECT test_int,b FROM test_table1;\n" + "DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;\n" + "OPEN testCursor;\n" + + " read_loop: LOOP\n" + " FETCH testCursor INTO test_int, b;\n" + " IF done THEN\n" + " LEAVE read_loop;\n" + " END IF;\n" + " SELECT test_int,b;" + " END LOOP;\n" + "CLOSE testCursor;\n" + "END"); + check_mysql_rc(rc, mysql); + + stmt= mysql_stmt_init(mysql); + rc= mysql_stmt_prepare(stmt, SL("CALL testCursor()")); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_attr_set(stmt, STMT_ATTR_UPDATE_MAX_LENGTH, &max_len); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + do { + if (mysql_stmt_field_count(stmt)) + { + MYSQL_RES *res= mysql_stmt_result_metadata(stmt); + rc= mysql_stmt_fetch(stmt); + FAIL_IF(rc, "Wrong return code"); + mysql_free_result(res); + } + rc= mysql_stmt_next_result(stmt); + + } while (!rc); + + mysql_stmt_close(stmt); + rc= mysql_query(mysql, "DROP PROCEDURE testCursor"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "DROP TABLE test_table1"); + check_mysql_rc(rc, mysql); + + return OK; +} + +static int test_maxparam(MYSQL *mysql) +{ + const char *query= "INSERT INTO t1 VALUES (?)"; + int rc; + char *buffer; + int i; + int val= 1; + size_t mem= strlen(query) + 1 + 4 * 65535 + 1; + MYSQL_STMT *stmt= mysql_stmt_init(mysql); + MYSQL_BIND* bind; + + bind = calloc(sizeof(MYSQL_BIND), 65535); + + 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); + + buffer= calloc(1, mem); + strcpy(buffer, query); + for (i=0; i < 65534.; i++) + strcat(buffer, ",(?)"); + rc= mysql_stmt_prepare(stmt, SL(buffer)); + check_stmt_rc(rc, stmt); + + for (i=0; i < 65534; i++) + { + bind[i].buffer_type= MYSQL_TYPE_LONG; + bind[i].buffer= &val; + } + + rc= mysql_stmt_bind_param(stmt, bind); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + FAIL_IF(mysql_stmt_affected_rows(stmt) != 65535, "Expected affected_rows=65535"); + + strcat(buffer, ",(?)"); + rc= mysql_stmt_prepare(stmt, SL(buffer)); + free(buffer); + FAIL_IF(!rc, "Error expected"); + FAIL_IF(mysql_stmt_errno(stmt) != ER_PS_MANY_PARAM, "Expected ER_PS_MANY_PARAM error"); + + mysql_stmt_close(stmt); + free(bind); + return OK; +} + +static int test_mdev_21920(MYSQL *mysql) +{ + MYSQL_STMT *stmt= mysql_stmt_init(mysql); + MYSQL_BIND bind[1]; + int rc; + char buffer[128]; + + rc= mysql_stmt_prepare(stmt, SL("SELECT ''")); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + buffer[0]= 1; + + memset(bind, 0, sizeof(MYSQL_BIND)); + bind[0].buffer_type= MYSQL_TYPE_STRING; + bind[0].buffer= buffer; + bind[0].buffer_length= 127; + + rc= mysql_stmt_bind_result(stmt, bind); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + + FAIL_IF(buffer[0] != 0, "Expected empty string"); + + + mysql_stmt_close(stmt); + + return OK; +} + +static int test_returning(MYSQL *mysql) +{ + MYSQL_STMT *stmt= mysql_stmt_init(mysql); + MYSQL_RES *result; + int rc; + + diag("MDEV-23768 not fixed yet"); + mysql_stmt_close(stmt); + return SKIP; + + rc= mysql_query(mysql, "CREATE TEMPORARY TABLE t1 (a int not null auto_increment primary key, b json)"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "INSERT INTO t1 (a,b) VALUES (NULL, '[incorrect json]') RETURNING a"); + check_mysql_rc(rc, mysql); + + if (!rc) diag("should have fail"); + + result= mysql_store_result(mysql); + mysql_free_result(result); + + diag("Error: %s", mysql_error(mysql)); + + rc= mysql_stmt_prepare(stmt, SL("INSERT INTO t1 (a,b) VALUES (NULL, '[incorrect json]') RETURNING a")); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_close(stmt); + + return OK; +} + +static int test_conc504(MYSQL *mysql) +{ + int rc; + MYSQL_STMT *stmt= mysql_stmt_init(mysql); + const char *sp= "CREATE PROCEDURE p1()\n" \ + "BEGIN\n"\ + " SELECT 1;\n"\ + " SELECT 2;\n"\ + " SELECT 3;\n"\ + "END"; + + rc= mysql_query(mysql, "DROP PROCEDURE IF EXISTS p1"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, sp); + check_mysql_rc(rc, mysql); + + rc= mysql_stmt_prepare(stmt, SL("CALL p1()")); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + mysql_stmt_store_result(stmt); + FAIL_IF(mysql_stmt_num_rows(stmt) != 1, "Expected 1 row"); + + mysql_stmt_next_result(stmt); + mysql_stmt_store_result(stmt); + FAIL_IF(mysql_stmt_num_rows(stmt) != 1, "Expected 1 row"); + + mysql_stmt_next_result(stmt); + mysql_stmt_store_result(stmt); + FAIL_IF(mysql_stmt_num_rows(stmt) != 1, "Expected 1 row"); + + mysql_stmt_close(stmt); + + rc= mysql_query(mysql, "DROP PROCEDURE p1"); + check_mysql_rc(rc, mysql); + + return OK; +} + +static int test_conc512(MYSQL *mysql) +{ + int rc; + MYSQL_STMT *stmt; + MYSQL_BIND bind; + float f; + + rc= mysql_query(mysql, "drop table if exists t1"); + + rc= mysql_real_query(mysql, SL("CREATE TABLE t1 (a int)")); + + rc= mysql_real_query(mysql, SL("INSERT INTO t1 VALUES (1073741825)")); + + stmt= mysql_stmt_init(mysql); + rc= mysql_stmt_prepare(stmt, SL("SELECT a FROM t1")); + check_stmt_rc(rc, stmt); + + memset(&bind, 0, sizeof(MYSQL_BIND)); + bind.buffer= &f; + bind.buffer_type= MYSQL_TYPE_FLOAT; + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_bind_result(stmt, &bind); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_fetch(stmt); + FAIL_IF(rc != 101, "Truncation expected"); + + mysql_stmt_close(stmt); + + rc= mysql_query(mysql, "DROP TABLE t1"); + check_mysql_rc(rc, mysql); + return OK; +} + +static int test_conc525(MYSQL *mysql) +{ + FILE *fp; + MYSQL_STMT *stmt; + int rc; + + rc= mysql_query(mysql, "create temporary table t1 (a blob)"); + check_mysql_rc(rc, mysql); + + /* create a dummy import file */ + if (!(fp= fopen("./test.csv", "w"))) + { + diag("couldn't create file './test.csv'"); + return FAIL; + } + fprintf(fp, "1\n2\n"); + fclose(fp); + + /* Test: prepare and execute + should fail due to non existing file */ + stmt= mysql_stmt_init(mysql); + + rc= mysql_stmt_prepare(stmt, SL("LOAD DATA LOCAL INFILE './test.notexist' INTO table t1")); + + if (rc && mysql_stmt_errno(stmt) == ER_UNSUPPORTED_PS) + { + diag("Server doesn't support LOAD LOCAL INFILE in binary protocol."); + mysql_stmt_close(stmt); + return SKIP; + } + + rc= mysql_stmt_execute(stmt); + FAIL_IF(!rc, "Error expected (file does not exist)"); + + mysql_stmt_close(stmt); + + /* Test: prepare and execute + 2 rows should be inserted */ + stmt= mysql_stmt_init(mysql); + + rc= mysql_stmt_prepare(stmt, SL("LOAD DATA LOCAL INFILE './test.csv' INTO table t1")); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + FAIL_IF(mysql_stmt_affected_rows(stmt) != 2, "Expected 2 inserted rows"); + + mysql_stmt_close(stmt); + stmt= mysql_stmt_init(mysql); + + /* Test: execute_direct + 2 rows should be inserted */ + rc= mariadb_stmt_execute_direct(stmt, SL("LOAD DATA LOCAL INFILE './test.csv' INTO table t1")); + check_stmt_rc(rc, stmt); + + FAIL_IF(mysql_stmt_affected_rows(stmt) != 2, "Expected 2 inserted rows"); + + /* Cleanup */ + mysql_stmt_close(stmt); + unlink("./test.csv"); + + return OK; +} + +struct my_tests_st my_tests[] = { + {"test_conc525", test_conc525, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_conc512", test_conc512, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_conc504", test_conc504, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_returning", test_returning, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_mdev_21920", test_mdev_21920, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_maxparam", test_maxparam, TEST_CONNECTION_NEW, 0, NULL, NULL}, + {"test_conc424", test_conc424, TEST_CONNECTION_NEW, 0, NULL, NULL}, + {"test_conc344", test_conc344, TEST_CONNECTION_NEW, 0, NULL, NULL}, + {"test_conc334", test_conc334, TEST_CONNECTION_NEW, 0, NULL, NULL}, + {"test_compress", test_compress, TEST_CONNECTION_NEW, CLIENT_COMPRESS, NULL, NULL}, + {"test_zerofill_1byte", test_zerofill_1byte, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_codbc138", test_codbc138, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_conc208", test_conc208, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_mdev14165", test_mdev14165, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_conc208", test_conc208, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_conc217", test_conc217, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_conc205", test_conc205, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_conc198", test_conc198, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_conc182", test_conc182, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_conc181", test_conc181, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_conc179", test_conc179, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_conc177", test_conc177, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_conc167", test_conc167, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_conc168", test_conc168, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_conc155", test_conc155, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_conc154", test_conc154, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_conc141", test_conc141, TEST_CONNECTION_NEW, 0, NULL , NULL}, + {"test_conc67", test_conc67, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_conc_5", test_conc_5, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_bug1115", test_bug1115, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_bug1180", test_bug1180, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_bug1644", test_bug1644, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_bug11037", test_bug11037, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_bug11183", test_bug11183, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_bug12744", test_bug12744, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_bug1500", test_bug1500, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_bug15510", test_bug15510, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_bug15518", test_bug15518, TEST_CONNECTION_NEW | TEST_CONNECTION_DONT_CLOSE, CLIENT_MULTI_STATEMENTS, NULL , NULL}, + {"test_bug15613", test_bug15613, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_bug16144", test_bug16144, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_bug1664", test_bug1664, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_bug1946", test_bug1946, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_bug2247", test_bug2247, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_bug2248", test_bug2248, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_bug20152", test_bug20152, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_bug23383", test_bug23383, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_bug27592", test_bug27592, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_bug28934", test_bug28934, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_bug36004", test_bug36004, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_bug3035", test_bug3035, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_bug3117", test_bug3117, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_bug3796", test_bug3796, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_bug4026", test_bug4026, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_bug4030", test_bug4030, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_bug4079", test_bug4079, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_bug4172", test_bug4172, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_bug4231", test_bug4231, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_bug4236", test_bug4236, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_bug5126", test_bug5126, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_bug5194", test_bug5194, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_bug5315", test_bug5315, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_bug5399", test_bug5399, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_bug6046", test_bug6046, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_bug6049", test_bug6049, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_bug6058", test_bug6058, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_bug6059", test_bug6059, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_bug6096", test_bug6096, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_bug7990", test_bug7990, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_bug8330", test_bug8330, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_bug8722", test_bug8722, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_ps_conj_select", test_ps_conj_select, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_ps_null_param", test_ps_null_param, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_ps_query_cache", test_ps_query_cache, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_ushort_bug", test_ushort_bug, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_field_misc", test_field_misc, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_mem_overun", test_mem_overun, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_decimal_bug", test_decimal_bug, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_explain_bug", test_explain_bug, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_sshort_bug", test_sshort_bug, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_stiny_bug", test_stiny_bug, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_bug53311", test_bug53311, TEST_CONNECTION_NEW, 0, NULL , NULL}, + {"test_conc_fraction", test_conc_fraction, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_str_to_int", test_str_to_int, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {NULL, NULL, 0, 0, NULL, NULL} +}; + +int main(int argc, char **argv) +{ + if (argc > 1) + get_options(argc, argv); + + get_envvars(); + + run_tests(my_tests); + + return(exit_status()); +} diff --git a/vendor/MDBC/unittest/libmariadb/ps_new.c b/vendor/MDBC/unittest/libmariadb/ps_new.c new file mode 100644 index 00000000..9b89d6f9 --- /dev/null +++ b/vendor/MDBC/unittest/libmariadb/ps_new.c @@ -0,0 +1,511 @@ +/************************************************************************************ + Copyright (C) 2012 Monty Program AB + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not see + or write to the Free Software Foundation, Inc., + 51 Franklin St., Fifth Floor, Boston, MA 02110, USA + *************************************************************************************/ + +#include "my_test.h" + +/* Utility function to verify the field members */ + + +static int test_multi_result(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + MYSQL_BIND ps_params[3]; /* input parameter buffers */ + MYSQL_BIND rs_bind[3]; + int int_data[3]; /* input/output values */ + my_bool is_null[3]; /* output value nullability */ + int rc, i; + + /* set up stored procedure */ + rc = mysql_query(mysql, "DROP PROCEDURE IF EXISTS p1"); + check_mysql_rc(rc, mysql); + + rc = mysql_query(mysql, + "CREATE PROCEDURE p1(" + " IN p_in INT, " + " OUT p_out INT, " + " INOUT p_inout INT) " + "BEGIN " + " SELECT p_in, p_out, p_inout; " + " SET p_in = 100, p_out = 200, p_inout = 300; " + " SELECT p_in, p_out, p_inout; " + "END"); + check_mysql_rc(rc, mysql); + + /* initialize and prepare CALL statement with parameter placeholders */ + stmt = mysql_stmt_init(mysql); + if (!stmt) + { + diag("Could not initialize statement"); + exit(1); + } + rc = mysql_stmt_prepare(stmt, "CALL p1(?, ?, ?)", 16); + check_stmt_rc(rc, stmt); + + /* initialize parameters: p_in, p_out, p_inout (all INT) */ + memset(ps_params, 0, sizeof (ps_params)); + + ps_params[0].buffer_type = MYSQL_TYPE_LONG; + ps_params[0].buffer = (char *) &int_data[0]; + ps_params[0].length = 0; + ps_params[0].is_null = 0; + + ps_params[1].buffer_type = MYSQL_TYPE_LONG; + ps_params[1].buffer = (char *) &int_data[1]; + ps_params[1].length = 0; + ps_params[1].is_null = 0; + + ps_params[2].buffer_type = MYSQL_TYPE_LONG; + ps_params[2].buffer = (char *) &int_data[2]; + ps_params[2].length = 0; + ps_params[2].is_null = 0; + + /* bind parameters */ + rc = mysql_stmt_bind_param(stmt, ps_params); + check_stmt_rc(rc, stmt); + + /* assign values to parameters and execute statement */ + int_data[0]= 10; /* p_in */ + int_data[1]= 20; /* p_out */ + int_data[2]= 30; /* p_inout */ + + rc = mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + FAIL_IF(mysql_stmt_field_count(stmt) != 3, "expected 3 fields"); + + memset(rs_bind, 0, sizeof (MYSQL_BIND) * 3); + for (i=0; i < 3; i++) + { + rs_bind[i].buffer = (char *) &(int_data[i]); + rs_bind[i].buffer_length = sizeof (int_data); + rs_bind[i].buffer_type = MYSQL_TYPE_LONG; + rs_bind[i].is_null = &is_null[i]; + } + rc= mysql_stmt_bind_result(stmt, rs_bind); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + + FAIL_IF(int_data[0] != 10 || int_data[1] != 20 || int_data[2] != 30, + "expected 10 20 30"); + rc= mysql_stmt_next_result(stmt); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_bind_result(stmt, rs_bind); + + rc= mysql_stmt_fetch(stmt); + FAIL_IF(mysql_stmt_field_count(stmt) != 3, "expected 3 fields"); + FAIL_IF(int_data[0] != 100 || int_data[1] != 200 || int_data[2] != 300, + "expected 100 200 300"); + + FAIL_IF(mysql_stmt_next_result(stmt) != 0, "expected more results"); + rc= mysql_stmt_bind_result(stmt, rs_bind); + + rc= mysql_stmt_fetch(stmt); + FAIL_IF(mysql_stmt_field_count(stmt) != 2, "expected 2 fields"); + FAIL_IF(int_data[0] != 200 || int_data[1] != 300, + "expected 100 200 300"); + + FAIL_IF(mysql_stmt_next_result(stmt) != 0, "expected more results"); + FAIL_IF(mysql_stmt_field_count(stmt) != 0, "expected 0 fields"); + + rc= mysql_stmt_close(stmt); + rc = mysql_query(mysql, "DROP PROCEDURE IF EXISTS p1"); + check_mysql_rc(rc, mysql); + return OK; +} + +int test_sp_params(MYSQL *mysql) +{ + int i, rc; + MYSQL_STMT *stmt; + int a[] = {10,20,30}; + MYSQL_BIND bind[3]; + const char *stmtstr= "CALL P1(?,?,?)"; + char res[3][20]; + + rc= mysql_query(mysql, "DROP PROCEDURE IF EXISTS p1"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE PROCEDURE p1(OUT p_out VARCHAR(19), IN p_in INT, INOUT p_inout INT)" + "BEGIN " + " SET p_in = 300, p_out := 'This is OUT param', p_inout = 200; " + " SELECT p_inout, p_in, substring(p_out, 9);" + "END"); + check_mysql_rc(rc, mysql); + + stmt= mysql_stmt_init(mysql); + check_mysql_rc(rc, mysql); + + rc= mysql_stmt_prepare(stmt,SL(stmtstr)); + check_stmt_rc(rc, stmt); + + FAIL_IF(mysql_stmt_param_count(stmt) != 3, "expected param_count=3"); + + memset(bind, 0, sizeof(MYSQL_BIND) * 3); + for (i=0; i < 3; i++) + { + bind[i].buffer= &a[i]; + bind[i].buffer_type= MYSQL_TYPE_LONG; + } + bind[0].buffer_type= MYSQL_TYPE_NULL; + rc= mysql_stmt_bind_param(stmt, bind); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + memset(res, 0, 60); + + memset(bind, 0, sizeof(MYSQL_BIND) * 3); + for (i=0; i < 3; i++) + { + bind[i].buffer_type= MYSQL_TYPE_STRING; + bind[i].buffer_length= 20; + bind[i].buffer= res[i]; + } + + do { + if (mysql->server_status & SERVER_PS_OUT_PARAMS) + { + diag("out param result set"); + FAIL_IF(mysql_stmt_field_count(stmt) != 2, "expected 2 columns"); + FAIL_IF(strcmp(stmt->fields[0].org_name, "p_out") != 0, "wrong field name"); + FAIL_IF(strcmp(stmt->fields[1].org_name, "p_inout") != 0, "wrong field name"); + rc= mysql_stmt_bind_result(stmt, bind); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + FAIL_IF(strcmp(res[0],"This is OUT param") != 0, "comparison failed"); + FAIL_IF(strcmp(res[1],"200") != 0, "comparison failed"); + } + else + if (mysql_stmt_field_count(stmt)) + { + diag("sp result set"); + FAIL_IF(mysql_stmt_field_count(stmt) != 3, "expected 3 columns"); + rc= mysql_stmt_bind_result(stmt, bind); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + FAIL_IF(strcmp(res[0],"200") != 0, "comparison failed"); + FAIL_IF(strcmp(res[1],"300") != 0, "comparison failed"); + FAIL_IF(strcmp(res[2],"OUT param") != 0, "comparison failed"); + + } + } while (mysql_stmt_next_result(stmt) == 0); + + rc= mysql_stmt_close(stmt); + return OK; +} + +int test_sp_reset(MYSQL *mysql) +{ + int i, rc; + MYSQL_STMT *stmt; + int a[] = {10,20,30}; + MYSQL_BIND bind[3]; + const char *stmtstr= "CALL P1(?,?,?)"; + + rc= mysql_query(mysql, "DROP PROCEDURE IF EXISTS p1"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE PROCEDURE p1(OUT p_out VARCHAR(19), IN p_in INT, INOUT p_inout INT)" + "BEGIN " + " SET p_in = 300, p_out := 'This is OUT param', p_inout = 200; " + " SELECT p_inout, p_in, substring(p_out, 9);" + "END"); + check_mysql_rc(rc, mysql); + + stmt= mysql_stmt_init(mysql); + check_mysql_rc(rc, mysql); + + rc= mysql_stmt_prepare(stmt,SL(stmtstr)); + check_stmt_rc(rc, stmt); + + FAIL_IF(mysql_stmt_param_count(stmt) != 3, "expected param_count=3"); + + memset(bind, 0, sizeof(MYSQL_BIND) * 3); + for (i=0; i < 3; i++) + { + bind[i].buffer= &a[i]; + bind[i].buffer_type= MYSQL_TYPE_LONG; + } + bind[0].buffer_type= MYSQL_TYPE_NULL; + rc= mysql_stmt_bind_param(stmt, bind); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_reset(stmt); + check_stmt_rc(rc, stmt); + + /*connection shouldn't be blocked now */ + + rc= mysql_query(mysql, "DROP PROCEDURE p1"); + check_mysql_rc(rc, mysql); + + rc= mysql_stmt_close(stmt); + return OK; +} + +int test_sp_reset1(MYSQL *mysql) +{ + int rc; + MYSQL_STMT *stmt; + MYSQL_BIND bind[1]; + + char tmp[20]; + const char *stmtstr= "CALL P1(?)"; + + rc= mysql_query(mysql, "DROP PROCEDURE IF EXISTS p1"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "CREATE PROCEDURE p1(OUT p_out VARCHAR(19))" + "BEGIN " + " SET p_out = 'foo';" + " SELECT 'foo' FROM DUAL;" + " SELECT 'bar' FROM DUAL;" + "END"); + check_mysql_rc(rc, mysql); + + stmt= mysql_stmt_init(mysql); + check_mysql_rc(rc, mysql); + + rc= mysql_stmt_prepare(stmt,SL(stmtstr)); + check_stmt_rc(rc, stmt); + + memset(tmp, 0, sizeof(tmp)); + memset(bind, 0, sizeof(MYSQL_BIND)); + bind[0].buffer= tmp; + bind[0].buffer_type= MYSQL_TYPE_STRING; + bind[0].buffer_length= 4; + + mysql_stmt_bind_param(stmt, bind); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_store_result(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_next_result(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + + /* mysql_stmt_reset should set statement in prepared state. + * this means: all subsequent result sets should be flushed. + * Let's try! + */ + rc= mysql_stmt_reset(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_query(mysql, "DROP PROCEDURE p1"); + check_mysql_rc(rc, mysql); + + mysql_stmt_close(stmt); + return OK; +} + +int test_sp_reset2(MYSQL *mysql) +{ + int rc, i; + MYSQL_STMT *stmt; + MYSQL_BIND bind[4]; + long l[4]; + const char *stmtstr= "CALL P1()"; + + memset(l, 0, sizeof(l)); + + 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, "DROP PROCEDURE IF EXISTS p1"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE PROCEDURE p1()" + "BEGIN " + " SET @a:=1;" + " INSERT INTO t1 VALUES(1);" + " SELECT 1 FROM DUAL;" + " SELECT 2,3 FROM DUAL;" + " INSERT INTO t1 VALUES(2);" + " SELECT 3,4,5 FROM DUAL;" + " SELECT 4,5,6,7 FROM DUAL;" + "END"); + check_mysql_rc(rc, mysql); + + stmt= mysql_stmt_init(mysql); + check_mysql_rc(rc, mysql); + + rc= mysql_stmt_prepare(stmt,SL(stmtstr)); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + memset(bind, 0, sizeof(MYSQL_BIND) * 4); + for (i=0; i < 4; i++) + { + bind[i].buffer_type= MYSQL_TYPE_LONG; + bind[i].buffer= &l[i]; + } + + rc= mysql_stmt_bind_result(stmt, bind); + check_stmt_rc(rc, stmt); + + while (rc != MYSQL_NO_DATA) + { + rc= mysql_stmt_fetch(stmt); + diag("l=%ld", l[0]); + } + + rc= mysql_stmt_next_result(stmt); + check_stmt_rc(rc, stmt); + + /* now rebind since we expect 2 columns */ + rc= mysql_stmt_bind_result(stmt, bind); + check_stmt_rc(rc, stmt); + + while (rc != MYSQL_NO_DATA) + { + rc= mysql_stmt_fetch(stmt); + diag("l=%ld l=%ld", l[0], l[1]); + } + + + rc= mysql_stmt_next_result(stmt); + check_stmt_rc(rc, stmt); + + /* now rebind since we expect 2 columns */ + rc= mysql_stmt_bind_result(stmt, bind); + check_stmt_rc(rc, stmt); + + while (rc != MYSQL_NO_DATA) + { + rc= mysql_stmt_fetch(stmt); + diag("l=%ld l=%ld l=%ld", l[0], l[1], l[2]); + } + + rc= mysql_stmt_close(stmt); + + + rc= mysql_query(mysql, "DROP PROCEDURE p1"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1"); + check_mysql_rc(rc, mysql); + + return OK; +} + +int test_query(MYSQL *mysql) +{ + int rc; + int i; + MYSQL_STMT *stmt; + MYSQL_BIND bind[1]; + + char tmp[20]; + const char *stmtstr= "CALL P1(?)"; + + rc= mysql_query(mysql, "DROP PROCEDURE IF EXISTS p1"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "CREATE PROCEDURE p1(OUT p_out VARCHAR(19))" + "BEGIN " + " SET p_out = 'foo';" + " SELECT 1 FROM DUAL;" + "END"); + check_mysql_rc(rc, mysql); + + stmt= mysql_stmt_init(mysql); + check_mysql_rc(rc, mysql); + + rc= mysql_stmt_prepare(stmt,SL(stmtstr)); + check_stmt_rc(rc, stmt); + + for (i=0; i < 1000; i++) + { + int status; + memset(tmp, 0, sizeof(tmp)); + memset(bind, 0, sizeof(MYSQL_BIND)); + bind[0].buffer= tmp; + bind[0].buffer_type= MYSQL_TYPE_STRING; + bind[0].buffer_length= 4; + + mysql_stmt_bind_param(stmt, bind); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + do { + if (stmt->field_count) + { + mysql_stmt_bind_result(stmt, bind); + rc= mysql_stmt_store_result(stmt); + check_stmt_rc(rc, stmt); + while(mysql_stmt_fetch(stmt) == 0); + + rc= mysql_stmt_free_result(stmt); + check_stmt_rc(rc, stmt); + } + status= mysql_stmt_next_result(stmt); + if (status == 1) + check_stmt_rc(status, stmt); + } while (status == 0); + + rc= mysql_stmt_reset(stmt); + if (rc) + diag("reset failed after %d iterations", i); + check_stmt_rc(rc, stmt); + } + mysql_stmt_close(stmt); + rc= mysql_query(mysql, "DROP PROCEDURE IF EXISTS p1"); + check_mysql_rc(rc, mysql); + + return OK; +} + + +struct my_tests_st my_tests[] = { + {"test_query", test_query, TEST_CONNECTION_DEFAULT, CLIENT_MULTI_RESULTS , NULL , NULL}, + {"test_sp_params", test_sp_params, TEST_CONNECTION_DEFAULT, CLIENT_MULTI_STATEMENTS, NULL , NULL}, + {"test_sp_reset", test_sp_reset, TEST_CONNECTION_DEFAULT, CLIENT_MULTI_STATEMENTS, NULL , NULL}, + {"test_sp_reset1", test_sp_reset1, TEST_CONNECTION_DEFAULT, CLIENT_MULTI_STATEMENTS, NULL , NULL}, + {"test_sp_reset2", test_sp_reset2, TEST_CONNECTION_DEFAULT, CLIENT_MULTI_STATEMENTS, NULL , NULL}, + {"test_multi_result", test_multi_result, TEST_CONNECTION_DEFAULT, CLIENT_MULTI_STATEMENTS, NULL , NULL}, + {NULL, NULL, 0, 0, NULL, NULL} +}; + +int main(int argc, char **argv) +{ + if (argc > 1) + get_options(argc, argv); + + get_envvars(); + + run_tests(my_tests); + + return(exit_status()); +} diff --git a/vendor/MDBC/unittest/libmariadb/result.c b/vendor/MDBC/unittest/libmariadb/result.c new file mode 100644 index 00000000..13f40b2c --- /dev/null +++ b/vendor/MDBC/unittest/libmariadb/result.c @@ -0,0 +1,1102 @@ +/* +Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. + +The MySQL Connector/C is licensed under the terms of the GPLv2 +, like most +MySQL Connectors. There are special exceptions to the terms and +conditions of the GPLv2 as it is applied to this software, see the +FLOSS License Exception +. + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published +by the Free Software Foundation; version 2 of the License. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ +/** + Some basic tests of the client API. +*/ + +#include "my_test.h" + +static int client_store_result(MYSQL *mysql) +{ + MYSQL_RES *result; + int rc, rowcount= 0; + + rc= mysql_query(mysql, "SELECT 'foo' FROM DUAL UNION SELECT 'bar' FROM DUAL"); + check_mysql_rc(rc, mysql); + + /* get the result */ + result= mysql_store_result(mysql); + FAIL_IF(!result, "Invalid result set"); + + /* since we use store result, we should be able execute other api calls */ + rc= mysql_ping(mysql); + FAIL_IF(rc, "mysql_ping failed"); + + while (mysql_fetch_row(result)) + rowcount++; + + FAIL_IF(rowcount != 2, "rowcount != 2"); + + mysql_free_result(result); + + return OK; +} + +static int client_use_result(MYSQL *mysql) +{ + MYSQL_RES *result; + int rc, rowcount= 0; + + rc= mysql_query(mysql, "SELECT 'foo' FROM DUAL UNION SELECT 'bar' FROM DUAL"); + check_mysql_rc(rc, mysql); + + /* get the result */ + result= mysql_use_result(mysql); + FAIL_IF(!result, "Invalid result set"); + + /* since we use use result, we shouldn't be able execute other api calls */ + rc= mysql_ping(mysql); + FAIL_IF(!rc, "Error expected"); + + while (mysql_fetch_row(result)) + rowcount++; + + FAIL_IF(rowcount != 2, "rowcount != 2"); + + mysql_free_result(result); + + return OK; +} + +static int test_free_result(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + MYSQL_BIND my_bind[1]; + char c2[5]; + ulong bl1, l2; + int rc, c1, bc1; + char query[MAX_TEST_QUERY_LENGTH]; + + rc= mysql_query(mysql, "drop table if exists test_free_result"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "create table test_free_result(" + "c1 int primary key auto_increment)"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "insert into test_free_result values(), (), ()"); + check_mysql_rc(rc, mysql); + + strcpy(query, "select * from test_free_result"); + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + memset(my_bind, '\0', sizeof(my_bind)); + my_bind[0].buffer_type= MYSQL_TYPE_LONG; + my_bind[0].buffer= (void *)&bc1; + my_bind[0].length= &bl1; + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_bind_result(stmt, my_bind); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + + c2[0]= '\0'; l2= 0; + my_bind[0].buffer_type= MYSQL_TYPE_STRING; + my_bind[0].buffer= (void *)c2; + my_bind[0].buffer_length= 7; + my_bind[0].is_null= 0; + my_bind[0].length= &l2; + + rc= mysql_stmt_fetch_column(stmt, my_bind, 0, 0); + check_stmt_rc(rc, stmt); + FAIL_UNLESS(strncmp(c2, "1", 1) == 0, "c2 != '1'"); + FAIL_UNLESS(l2 == 1, "l2 != 1"); + + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + + c1= 0, l2= 0; + my_bind[0].buffer_type= MYSQL_TYPE_LONG; + my_bind[0].buffer= (void *)&c1; + my_bind[0].buffer_length= 0; + my_bind[0].is_null= 0; + my_bind[0].length= &l2; + + rc= mysql_stmt_fetch_column(stmt, my_bind, 0, 0); + check_stmt_rc(rc, stmt); + FAIL_UNLESS(c1 == 2, "c1 != 2"); + FAIL_UNLESS(l2 == 4, "l2 != 4"); + + rc= mysql_query(mysql, "drop table test_free_result"); + FAIL_IF(!rc, "Error commands out of sync expected"); + + rc= mysql_stmt_free_result(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_query(mysql, "drop table test_free_result"); + check_mysql_rc(rc, mysql); /* should be successful */ + + mysql_stmt_close(stmt); + + return OK; +} + + +/* Test mysql_stmt_store_result() */ + +static int test_free_store_result(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + MYSQL_BIND my_bind[1]; + char c2[5]; + ulong bl1, l2; + int rc, c1, bc1; + char query[MAX_TEST_QUERY_LENGTH]; + + rc= mysql_query(mysql, "drop table if exists test_free_result"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "create table test_free_result(c1 int primary key auto_increment)"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "insert into test_free_result values(), (), ()"); + check_mysql_rc(rc, mysql); + + strcpy(query, "select * from test_free_result"); + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + memset(my_bind, '\0', sizeof(my_bind)); + my_bind[0].buffer_type= MYSQL_TYPE_LONG; + my_bind[0].buffer= (void *)&bc1; + my_bind[0].buffer_length= 0; + my_bind[0].is_null= 0; + my_bind[0].length= &bl1; + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_bind_result(stmt, my_bind); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_store_result(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + + c2[0]= '\0'; l2= 0; + my_bind[0].buffer_type= MYSQL_TYPE_STRING; + my_bind[0].buffer= (void *)c2; + my_bind[0].buffer_length= 7; + my_bind[0].is_null= 0; + my_bind[0].length= &l2; + + rc= mysql_stmt_fetch_column(stmt, my_bind, 0, 0); + check_stmt_rc(rc, stmt); + FAIL_UNLESS(strncmp(c2, "1", 1) == 0, "c2 != '1'"); + FAIL_UNLESS(l2 == 1, "l2 != 1"); + + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + + c1= 0, l2= 0; + my_bind[0].buffer_type= MYSQL_TYPE_LONG; + my_bind[0].buffer= (void *)&c1; + my_bind[0].buffer_length= 0; + my_bind[0].is_null= 0; + my_bind[0].length= &l2; + + rc= mysql_stmt_fetch_column(stmt, my_bind, 0, 0); + check_stmt_rc(rc, stmt); + FAIL_UNLESS(c1 == 2, "c1 != 2"); + FAIL_UNLESS(l2 == 4, "l2 != 4"); + + rc= mysql_stmt_free_result(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_query(mysql, "drop table test_free_result"); + check_mysql_rc(rc, mysql); + + mysql_stmt_close(stmt); + + return OK; +} + +static int test_store_result(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + int rc; + int32 nData; + char szData[100]; + MYSQL_BIND my_bind[2]; + ulong length, length1; + my_bool is_null[2]; + char query[MAX_TEST_QUERY_LENGTH]; + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_store_result"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE test_store_result(col1 int , col2 varchar(50))"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "INSERT INTO test_store_result VALUES(10, 'venu'), (20, 'mysql')"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "INSERT INTO test_store_result(col2) VALUES('monty')"); + check_mysql_rc(rc, mysql); + + rc= mysql_commit(mysql); + check_mysql_rc(rc, mysql); + + /* fetch */ + memset(my_bind, '\0', sizeof(my_bind)); + my_bind[0].buffer_type= MYSQL_TYPE_LONG; + my_bind[0].buffer= (void *) &nData; /* integer data */ + my_bind[0].length= &length; + my_bind[0].is_null= &is_null[0]; + + length= 0; + my_bind[1].buffer_type= MYSQL_TYPE_STRING; + my_bind[1].buffer= szData; /* string data */ + my_bind[1].buffer_length= sizeof(szData); + my_bind[1].length= &length1; + my_bind[1].is_null= &is_null[1]; + length1= 0; + + strcpy(query, "SELECT * FROM test_store_result"); + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_bind_result(stmt, my_bind); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_store_result(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + + FAIL_UNLESS(nData == 10, "nData != 10"); + FAIL_UNLESS(strcmp(szData, "venu") == 0, "szData != 'Venu'"); + FAIL_UNLESS(length1 == 4, "length1 != 4"); + + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + + FAIL_UNLESS(nData == 20, "nData != 20"); + FAIL_UNLESS(strcmp(szData, "mysql") == 0, "szDaza != 'mysql'"); + FAIL_UNLESS(length1 == 5, "length1 != 5"); + + length= 99; + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + + FAIL_UNLESS(is_null[0], "isnull set"); + FAIL_UNLESS(strcmp(szData, "monty") == 0, "szData != 'monty'"); + FAIL_UNLESS(length1 == 5, "length1 != 5"); + + rc= mysql_stmt_fetch(stmt); + FAIL_UNLESS(rc == MYSQL_NO_DATA, "rc != MYSQL_NO_DATA"); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_store_result(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + + FAIL_UNLESS(nData == 10, "nData != 10"); + FAIL_UNLESS(strcmp(szData, "venu") == 0, "szData != 'Venu'"); + FAIL_UNLESS(length1 == 4, "length1 != 4"); + + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + + FAIL_UNLESS(nData == 20, "nData != 20"); + FAIL_UNLESS(strcmp(szData, "mysql") == 0, "szDaza != 'mysql'"); + FAIL_UNLESS(length1 == 5, "length1 != 5"); + + length= 99; + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + + FAIL_UNLESS(is_null[0], "isnull set"); + FAIL_UNLESS(strcmp(szData, "monty") == 0, "szData != 'monty'"); + FAIL_UNLESS(length1 == 5, "length1 != 5"); + + rc= mysql_stmt_fetch(stmt); + FAIL_UNLESS(rc == MYSQL_NO_DATA, "rc != MYSQL_NO_DATA"); + + mysql_stmt_close(stmt); + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_store_result"); + check_mysql_rc(rc, mysql); + + return OK; +} + + +/* Test simple bind store result */ + +static int test_store_result1(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + int rc; + char query[MAX_TEST_QUERY_LENGTH]; + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_store_result"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE test_store_result(col1 int , col2 varchar(50))"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "INSERT INTO test_store_result VALUES(10, 'venu'), (20, 'mysql')"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "INSERT INTO test_store_result(col2) VALUES('monty')"); + check_mysql_rc(rc, mysql); + + rc= mysql_commit(mysql); + check_mysql_rc(rc, mysql); + + strcpy(query, "SELECT * FROM test_store_result"); + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_store_result(stmt); + check_stmt_rc(rc, stmt); + + rc= 0; + while (mysql_stmt_fetch(stmt) != MYSQL_NO_DATA) + rc++; + FAIL_UNLESS(rc == 3, "rowcount != 3"); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_store_result(stmt); + check_stmt_rc(rc, stmt); + + rc= 0; + while (mysql_stmt_fetch(stmt) != MYSQL_NO_DATA) + rc++; + FAIL_UNLESS(rc == 3, "rowcount != 3"); + + mysql_stmt_close(stmt); + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_store_result"); + check_mysql_rc(rc, mysql); + + return OK; +} + + +/* Another test for bind and store result */ + +static int test_store_result2(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + int rc; + int nData; + ulong length; + MYSQL_BIND my_bind[1]; + char query[MAX_TEST_QUERY_LENGTH]; + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_store_result"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE test_store_result(col1 int , col2 varchar(50))"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "INSERT INTO test_store_result VALUES(10, 'venu'), (20, 'mysql')"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "INSERT INTO test_store_result(col2) VALUES('monty')"); + check_mysql_rc(rc, mysql); + + rc= mysql_commit(mysql); + check_mysql_rc(rc, mysql); + + memset(my_bind, '\0', sizeof(my_bind)); + + my_bind[0].buffer_type= MYSQL_TYPE_LONG; + my_bind[0].buffer= (void *) &nData; /* integer data */ + my_bind[0].length= &length; + my_bind[0].is_null= 0; + + strcpy((char *)query , "SELECT col1 FROM test_store_result where col1= ?"); + stmt= mysql_stmt_init(mysql); + FAIL_IF(!stmt, mysql_error(mysql)); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_bind_param(stmt, my_bind); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_bind_result(stmt, my_bind); + check_stmt_rc(rc, stmt); + + nData= 10; length= 0; + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + nData= 0; + rc= mysql_stmt_store_result(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + + FAIL_UNLESS(nData == 10, "nData != 10"); + + rc= mysql_stmt_fetch(stmt); + FAIL_UNLESS(rc == MYSQL_NO_DATA, "rc != MYSQL_NO_DATA"); + + nData= 20; + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + nData= 0; + rc= mysql_stmt_store_result(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + + FAIL_UNLESS(nData == 20, "nData != 20"); + + rc= mysql_stmt_fetch(stmt); + FAIL_UNLESS(rc == MYSQL_NO_DATA, "rc != MYSQL_NO_DATA"); + mysql_stmt_close(stmt); + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_store_result"); + check_mysql_rc(rc, mysql); + + return OK; +} + +static int test_bug11718(MYSQL *mysql) +{ + MYSQL_RES *res; + int rc; + const char *query= "select str_to_date(concat(f3),'%Y%m%d') from t1,t2 " + "where f1=f2 order by f1"; + + rc= mysql_query(mysql, "drop table if exists t1, t2"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "create table t1 (f1 int)"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "create table t2 (f2 int, f3 numeric(8))"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "insert into t1 values (1), (2)"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "insert into t2 values (1,20050101), (2,20050202)"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, query); + check_mysql_rc(rc, mysql); + res = mysql_store_result(mysql); + + FAIL_UNLESS(res->fields[0].type == MYSQL_TYPE_DATE, "type != MYSQL_TYPE_DATE"); + mysql_free_result(res); + rc= mysql_query(mysql, "drop table t1, t2"); + check_mysql_rc(rc, mysql); + + return OK; +} + +static int test_bug19671(MYSQL *mysql) +{ + MYSQL_RES *result; + int rc; + + mysql_query(mysql, "set sql_mode=''"); + rc= mysql_query(mysql, "drop table if exists t1"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "drop view if exists v1"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "create table t1(f1 int)"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "create view v1 as select va.* from t1 va"); + check_mysql_rc(rc, mysql); + + result= mysql_list_fields(mysql, "v1", NULL); + FAIL_IF(!result, "Invalid result set"); + + rc= 0; + while (mysql_fetch_row(result)) + rc++; + FAIL_UNLESS(rc == 0, ""); + + if (verify_prepare_field(result, 0, "f1", "f1", MYSQL_TYPE_LONG, + "v1", "v1", schema, 11, "0")) { + mysql_free_result(result); + diag("verify_prepare_field failed"); + return FAIL; + } + + mysql_free_result(result); + check_mysql_rc(mysql_query(mysql, "drop view v1"), mysql); + check_mysql_rc(mysql_query(mysql, "drop table t1"), mysql); + return OK; +} + +/* + Bug#21726: Incorrect result with multiple invocations of + LAST_INSERT_ID + + Test that client gets updated value of insert_id on UPDATE that uses + LAST_INSERT_ID(expr). + select_query added to test for bug + #26921 Problem in mysql_insert_id() Embedded C API function +*/ +static int test_bug21726(MYSQL *mysql) +{ + const char *create_table[]= + { + "DROP TABLE IF EXISTS t1", + "CREATE TABLE t1 (i INT)", + "INSERT INTO t1 VALUES (1)", + }; + const char *update_query= "UPDATE t1 SET i= LAST_INSERT_ID(i + 1)"; + int rc; + unsigned long long insert_id; + const char *select_query= "SELECT * FROM t1"; + MYSQL_RES *result; + + rc= mysql_query(mysql, create_table[0]); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, create_table[1]); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, create_table[2]); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, update_query); + check_mysql_rc(rc, mysql); + insert_id= mysql_insert_id(mysql); + FAIL_UNLESS(insert_id == 2, "insert_id != 2"); + + rc= mysql_query(mysql, update_query); + check_mysql_rc(rc, mysql); + insert_id= mysql_insert_id(mysql); + FAIL_UNLESS(insert_id == 3, "insert_id != 3"); + + rc= mysql_query(mysql, select_query); + check_mysql_rc(rc, mysql); + insert_id= mysql_insert_id(mysql); + FAIL_UNLESS(insert_id == 3, "insert_id != 3"); + result= mysql_store_result(mysql); + mysql_free_result(result); + + return OK; +} + +/* Bug#6761 - mysql_list_fields doesn't work */ + +static int test_bug6761(MYSQL *mysql) +{ + const char *stmt_text; + MYSQL_RES *res; + int rc; + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1"); + check_mysql_rc(rc, mysql); + + stmt_text= "CREATE TABLE t1 (a int, b char(255), c decimal)"; + rc= mysql_real_query(mysql, stmt_text, (unsigned long)strlen(stmt_text)); + check_mysql_rc(rc, mysql); + + res= mysql_list_fields(mysql, "t1", "%"); + FAIL_UNLESS(res && mysql_num_fields(res) == 3, "num_fields != 3"); + mysql_free_result(res); + + stmt_text= "DROP TABLE t1"; + rc= mysql_real_query(mysql, stmt_text, (unsigned long)strlen(stmt_text)); + check_mysql_rc(rc, mysql); + return OK; +} + +/* Test field flags (verify .NET provider) */ + +static int test_field_flags(MYSQL *mysql) +{ + int rc; + MYSQL_RES *result; + MYSQL_FIELD *field; + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_field_flags"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE test_field_flags(id int NOT NULL AUTO_INCREMENT PRIMARY KEY, \ + id1 int NOT NULL, \ + id2 int UNIQUE, \ + id3 int, \ + id4 int NOT NULL, \ + id5 int, \ + KEY(id3, id4))"); + check_mysql_rc(rc, mysql); + + /* with table name included with TRUE column name */ + rc= mysql_query(mysql, "SELECT * FROM test_field_flags"); + check_mysql_rc(rc, mysql); + + result= mysql_use_result(mysql); + FAIL_IF(!result, "Invalid result set"); + + mysql_field_seek(result, 0); + + field= mysql_fetch_field(result); + FAIL_UNLESS(field->flags & NOT_NULL_FLAG && + field->flags & PRI_KEY_FLAG && + field->flags & AUTO_INCREMENT_FLAG, "Wrong flags for field 0"); + + field= mysql_fetch_field(result); + FAIL_UNLESS(field->flags & NOT_NULL_FLAG, "Wrong flags for field 1"); + + field= mysql_fetch_field(result); + FAIL_UNLESS(field->flags & UNIQUE_KEY_FLAG, "Wrong flags for field 2"); + + field= mysql_fetch_field(result); + FAIL_UNLESS(field->flags & MULTIPLE_KEY_FLAG, "Wrong flags for field 3"); + + field= mysql_fetch_field(result); + FAIL_UNLESS(field->flags & NOT_NULL_FLAG, "Wrong flags for field 4"); + + mysql_free_result(result); + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_field_flags"); + check_mysql_rc(rc, mysql); + return OK; +} + +/* Test real and alias names */ + +static int test_field_names(MYSQL *mysql) +{ + int rc; + MYSQL_RES *result; + + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_field_names1"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_field_names2"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE test_field_names1(id int, name varchar(50))"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE test_field_names2(id int, name varchar(50))"); + check_mysql_rc(rc, mysql); + + /* with table name included with TRUE column name */ + rc= mysql_query(mysql, "SELECT id as 'id-alias' FROM test_field_names1"); + check_mysql_rc(rc, mysql); + + result= mysql_use_result(mysql); + FAIL_IF(!result, "Invalid result set"); + + rc= 0; + while (mysql_fetch_row(result)) + rc++; + FAIL_UNLESS(rc == 0, "rowcount != 0"); + mysql_free_result(result); + + /* with table name included with TRUE column name */ + rc= mysql_query(mysql, "SELECT t1.id as 'id-alias', test_field_names2.name FROM test_field_names1 t1, test_field_names2"); + check_mysql_rc(rc, mysql); + + result= mysql_use_result(mysql); + FAIL_IF(!result, "Invalid result set"); + + rc= 0; + while (mysql_fetch_row(result)) + rc++; + FAIL_UNLESS(rc == 0, "rowcount != 0"); + mysql_free_result(result); + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_field_names1"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_field_names2"); + check_mysql_rc(rc, mysql); + return OK; +} + +/* Test FUNCTION field info / DATE_FORMAT() table_name . */ + +static int test_func_fields(MYSQL *mysql) +{ + int rc; + MYSQL_RES *result; + MYSQL_FIELD *field; + + + rc= mysql_autocommit(mysql, TRUE); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_dateformat"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE test_dateformat(id int, \ + ts timestamp)"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "INSERT INTO test_dateformat(id) values(10)"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "SELECT ts FROM test_dateformat"); + check_mysql_rc(rc, mysql); + + result= mysql_store_result(mysql); + FAIL_IF(!result, "Invalid result set"); + + field= mysql_fetch_field(result); + FAIL_IF(!field, "Invalid field"); + FAIL_UNLESS(strcmp(field->table, "test_dateformat") == 0, "field->table != 'test_dateformat'"); + + field= mysql_fetch_field(result); + FAIL_IF(field, "no more fields expected"); + + mysql_free_result(result); + + /* DATE_FORMAT */ + rc= mysql_query(mysql, "SELECT DATE_FORMAT(ts, '%Y') AS 'venu' FROM test_dateformat"); + check_mysql_rc(rc, mysql); + + result= mysql_store_result(mysql); + FAIL_IF(!result, "Invalid result set"); + + field= mysql_fetch_field(result); + FAIL_IF(!field, "Invalid field"); + FAIL_UNLESS(field->table[0] == '\0', "field->table != ''"); + + field= mysql_fetch_field(result); + FAIL_IF(field, "no more fields expected"); + + mysql_free_result(result); + + /* FIELD ALIAS TEST */ + rc= mysql_query(mysql, "SELECT DATE_FORMAT(ts, '%Y') AS 'YEAR' FROM test_dateformat"); + check_mysql_rc(rc, mysql); + + result= mysql_store_result(mysql); + FAIL_IF(!result, "Invalid result set"); + + field= mysql_fetch_field(result); + FAIL_IF(!field, "Invalid field"); + FAIL_UNLESS(strcmp(field->name, "YEAR") == 0, "name != 'YEAR'"); + FAIL_UNLESS(field->org_name[0] == '\0', "org_name != ''"); + + field= mysql_fetch_field(result); + FAIL_IF(field, "no more fields expected"); + + mysql_free_result(result); + rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_dateformat"); + check_mysql_rc(rc, mysql); + return OK; +} + +/* Test mysql_list_fields() */ + +static int test_list_fields(MYSQL *mysql) +{ + MYSQL_RES *result; + int rc; + + rc= mysql_query(mysql, "drop table if exists t1"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "create table t1(c1 int primary key auto_increment, c2 char(10) default 'mysql')"); + check_mysql_rc(rc, mysql); + + result= mysql_list_fields(mysql, "t1", NULL); + FAIL_IF(!result, "Invalid result set"); + + rc= 0; + while (mysql_fetch_row(result)) + rc++; + FAIL_UNLESS(rc == 0, "rowcount != 0"); + + if (verify_prepare_field(result, 0, "c1", "c1", MYSQL_TYPE_LONG, + "t1", "t1", + schema, 11, "0")) + goto error; + + if (verify_prepare_field(result, 1, "c2", "c2", MYSQL_TYPE_STRING, + "t1", "t1", + schema, 10, "mysql")) + goto error; + + mysql_free_result(result); + check_mysql_rc(mysql_query(mysql, "drop table t1"), mysql); + return OK; + +error: + mysql_free_result(result); + check_mysql_rc(mysql_query(mysql, "drop table t1"), mysql); + return FAIL; +} + +/* Test correct max length for MEDIUMTEXT and LONGTEXT columns */ + +static int test_bug9735(MYSQL *mysql) +{ + MYSQL_RES *res; + int rc; + + + rc= mysql_query(mysql, "drop table if exists t1"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "create table t1 (a mediumtext, b longtext) " + "character set latin1"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "select * from t1"); + check_mysql_rc(rc, mysql); + res= mysql_store_result(mysql); + if (verify_prepare_field(res, 0, "a", "a", MYSQL_TYPE_BLOB, + "t1", "t1", schema, (1U << 24)-1, 0)) + goto error; + if (verify_prepare_field(res, 1, "b", "b", MYSQL_TYPE_BLOB, + "t1", "t1", schema, ~0U, 0)) + goto error; + mysql_free_result(res); + rc= mysql_query(mysql, "drop table t1"); + check_mysql_rc(rc, mysql); + return OK; +error: + mysql_free_result(res); + rc= mysql_query(mysql, "drop table t1"); + return FAIL; +} + +/* + Check that mysql_next_result works properly in case when one of + the statements used in a multi-statement query is erroneous +*/ + +static int test_bug9992(MYSQL *mysql) +{ + MYSQL_RES* res ; + int rc; + + /* Sic: SHOW DATABASE is incorrect syntax. */ + rc= mysql_query(mysql, "SHOW TABLES; SHOW DATABASE; SELECT 1;"); + check_mysql_rc(rc, mysql); + + res= mysql_store_result(mysql); + FAIL_UNLESS(res, "Invalid resultset"); + mysql_free_result(res); + rc= mysql_next_result(mysql); + FAIL_UNLESS(rc == 1, "Error expected"); /* Got errors, as expected */ + + return OK; +} + +/* Test the support of multi-statement executions */ + +static int test_multi_statements(MYSQL *mysql) +{ + MYSQL *mysql_local; + MYSQL_RES *result; + int rc; + + const char *query= "\ +DROP TABLE IF EXISTS test_multi_tab;\ +CREATE TABLE test_multi_tab(id int, name char(20));\ +INSERT INTO test_multi_tab(id) VALUES(10), (20);\ +INSERT INTO test_multi_tab VALUES(20, 'insert;comma');\ +SELECT * FROM test_multi_tab;\ +UPDATE test_multi_tab SET name='new;name' WHERE id=20;\ +DELETE FROM test_multi_tab WHERE name='new;name';\ +SELECT * FROM test_multi_tab;\ +DELETE FROM test_multi_tab WHERE id=10;\ +SELECT * FROM test_multi_tab;\ +DROP TABLE test_multi_tab;\ +select 1;\ +DROP TABLE IF EXISTS test_multi_tab"; + uint count, exp_value; + uint rows[]= {0, 0, 2, 1, 3, 2, 2, 1, 1, 0, 0, 1, 0}; + my_bool reconnect= 1; + + SKIP_SKYSQL; + SKIP_MAXSCALE; + + /* + First test that we get an error for multi statements + (Because default connection is not opened with CLIENT_MULTI_STATEMENTS) + */ + mysql_local= mysql; + mysql = test_connect(NULL); + rc= mysql_query(mysql, query); /* syntax error */ + FAIL_IF(!rc, "Error expected"); + + rc= mysql_next_result(mysql); + FAIL_UNLESS(rc == -1, "rc != -1"); + rc= mysql_more_results(mysql); + FAIL_UNLESS(rc == 0, "rc != 0"); + + mysql_close(mysql); + mysql= mysql_local; + + mysql_options(mysql_local, MYSQL_OPT_RECONNECT, &reconnect); + + rc= mysql_query(mysql_local, query); + check_mysql_rc(rc, mysql); + + for (count= 0 ; count < array_elements(rows) ; count++) + { + if ((result= mysql_store_result(mysql_local))) + { + mysql_free_result(result); + } + + exp_value= (uint) mysql_affected_rows(mysql_local); + FAIL_IF(rows[count] != exp_value, "row[count] != exp_value"); + if (count != array_elements(rows) -1) + { + rc= mysql_more_results(mysql_local); + FAIL_IF(!rc, "More results expected"); + rc= mysql_next_result(mysql_local); + check_mysql_rc(rc, mysql_local); + } + else + { + rc= mysql_more_results(mysql_local); + FAIL_UNLESS(rc == 0, "rc != 0"); + rc= mysql_next_result(mysql_local); + FAIL_UNLESS(rc == -1, "rc != -1"); + } + } + + /* check that errors abort multi statements */ + + rc= mysql_query(mysql_local, "select 1+1+a;select 1+1"); + FAIL_IF(!rc, "Error expected"); + rc= mysql_more_results(mysql_local); + FAIL_UNLESS(rc == 0, "rc != 0"); + rc= mysql_next_result(mysql_local); + FAIL_UNLESS(rc == -1, "rc != -1"); + + rc= mysql_query(mysql_local, "select 1+1;select 1+1+a;select 1"); + check_mysql_rc(rc, mysql); + result= mysql_store_result(mysql_local); + FAIL_IF(!result, "Invalid result set"); + mysql_free_result(result); + rc= mysql_more_results(mysql_local); + FAIL_UNLESS(rc == 1, "rc != 1"); + rc= mysql_next_result(mysql_local); + FAIL_UNLESS(rc > 0, "rc <= 0"); + + /* + Ensure that we can now do a simple query (this checks that the server is + not trying to send us the results for the last 'select 1' + */ + rc= mysql_query(mysql_local, "select 1+1+1"); + check_mysql_rc(rc, mysql); + result= mysql_store_result(mysql_local); + FAIL_IF(!result, "Invalid result set"); + mysql_free_result(result); + + /* + Check if errors in one of the queries handled properly. + */ + rc= mysql_query(mysql_local, "select 1; select * from not_existing_table"); + check_mysql_rc(rc, mysql); + result= mysql_store_result(mysql_local); + mysql_free_result(result); + + rc= mysql_next_result(mysql_local); + FAIL_UNLESS(rc > 0, "rc <= 0"); + + rc= mysql_next_result(mysql_local); + FAIL_UNLESS(rc < 0, "rc >= 0"); + + return OK; +} + +static int test_conc160(MYSQL *mysql) +{ + MYSQL_RES *result; + MYSQL_FIELD *field; + int rc; + + rc= mysql_query(mysql, "SELECT cast(1.234 AS DECIMAL)"); + check_mysql_rc(rc, mysql); + + result= mysql_store_result(mysql); + field= mysql_fetch_field(result); + + FAIL_UNLESS(field->flags & NUM_FLAG, "Numceric flag not set"); + + mysql_free_result(result); + return OK; +} + + + +struct my_tests_st my_tests[] = { + {"test_conc160", test_conc160, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"client_store_result", client_store_result, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"client_use_result", client_use_result, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_free_result", test_free_result, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_free_store_result", test_free_store_result, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_store_result", test_store_result, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_store_result1", test_store_result1, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_store_result2", test_store_result2, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_bug11718", test_bug11718, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_bug19671", test_bug19671, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_bug21726", test_bug21726, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_bug6761", test_bug6761, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_field_flags", test_field_flags, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_field_names", test_field_names, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_func_fields", test_func_fields, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_list_fields", test_list_fields, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_bug9735", test_bug9735, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_bug9992", test_bug9992, TEST_CONNECTION_NEW, CLIENT_MULTI_STATEMENTS, NULL, NULL}, + {"test_multi_statements", test_multi_statements, TEST_CONNECTION_NEW, CLIENT_MULTI_STATEMENTS, NULL, NULL}, + {NULL, NULL, 0, 0, NULL, NULL} +}; + + +int main(int argc, char **argv) +{ + if (argc > 1) + get_options(argc, argv); + + get_envvars(); + + run_tests(my_tests); + + return(exit_status()); +} diff --git a/vendor/MDBC/unittest/libmariadb/rpl_api.c b/vendor/MDBC/unittest/libmariadb/rpl_api.c new file mode 100644 index 00000000..e7ff31ac --- /dev/null +++ b/vendor/MDBC/unittest/libmariadb/rpl_api.c @@ -0,0 +1,74 @@ +/* +Copyright (c) 2018 MariaDB Corporation AB + +The MySQL Connector/C is licensed under the terms of the GPLv2 +, like most +MySQL Connectors. There are special exceptions to the terms and +conditions of the GPLv2 as it is applied to this software, see the +FLOSS License Exception +. + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published +by the Free Software Foundation; version 2 of the License. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ +/** + Some basic tests of the client API. +*/ + +#include "my_test.h" +#include "mariadb_rpl.h" + +static int test_rpl_01(MYSQL *mysql) +{ + MARIADB_RPL_EVENT *event= NULL; + MARIADB_RPL *rpl= mariadb_rpl_init(mysql); + mysql_query(mysql, "SET @mariadb_slave_capability=4"); + mysql_query(mysql, "SET NAMES latin1"); + mysql_query(mysql, "SET @slave_gtid_strict_mode=1"); + mysql_query(mysql, "SET @slave_gtid_ignore_duplicates=1"); + mysql_query(mysql, "SET NAMES utf8"); + mysql_query(mysql, "SET @master_binlog_checksum= @@global.binlog_checksum"); + rpl->server_id= 12; + rpl->start_position= 4; + rpl->flags= MARIADB_RPL_BINLOG_SEND_ANNOTATE_ROWS; + + if (mariadb_rpl_open(rpl)) + return FAIL; + + while((event= mariadb_rpl_fetch(rpl, event))) + { + diag("event: %d\n", event->event_type); + } + mariadb_free_rpl_event(event); + mariadb_rpl_close(rpl); + return OK; +} + + +struct my_tests_st my_tests[] = { + {"test_rpl_01", test_rpl_01, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {NULL, NULL, 0, 0, NULL, NULL} +}; + + +int main(int argc, char **argv) +{ + if (argc > 1) + get_options(argc, argv); + + get_envvars(); + + run_tests(my_tests); + + return(exit_status()); +} diff --git a/vendor/MDBC/unittest/libmariadb/sp.c b/vendor/MDBC/unittest/libmariadb/sp.c new file mode 100644 index 00000000..6aeb557e --- /dev/null +++ b/vendor/MDBC/unittest/libmariadb/sp.c @@ -0,0 +1,91 @@ +/* +Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. + +The MySQL Connector/C is licensed under the terms of the GPLv2 +, like most +MySQL Connectors. There are special exceptions to the terms and +conditions of the GPLv2 as it is applied to this software, see the +FLOSS License Exception +. + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published +by the Free Software Foundation; version 2 of the License. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ +#include "my_test.h" + +/* Bug#15752 "Lost connection to MySQL server when calling a SP from C API" */ + +static int test_bug15752(MYSQL *mysql) +{ + int rc, i; + const int ITERATION_COUNT= 100; + const char *query= "CALL p1()"; + + + rc= mysql_query(mysql, "drop procedure if exists p1"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "create procedure p1() select 1"); + check_mysql_rc(rc, mysql); + + rc= mysql_real_query(mysql, SL(query)); + check_mysql_rc(rc, mysql); + mysql_free_result(mysql_store_result(mysql)); + + rc= mysql_real_query(mysql, SL(query)); + FAIL_UNLESS(rc && mysql_errno(mysql) == CR_COMMANDS_OUT_OF_SYNC, "Error expected"); + + rc= mysql_next_result(mysql); + check_mysql_rc(rc, mysql); + + mysql_free_result(mysql_store_result(mysql)); + + rc= mysql_next_result(mysql); + FAIL_IF(rc != -1, "rc != -1"); + + for (i = 0; i < ITERATION_COUNT; i++) + { + rc= mysql_real_query(mysql, SL(query)); + check_mysql_rc(rc, mysql); + mysql_free_result(mysql_store_result(mysql)); + rc= mysql_next_result(mysql); + check_mysql_rc(rc, mysql); + mysql_free_result(mysql_store_result(mysql)); + rc= mysql_next_result(mysql); + FAIL_IF(rc != -1, "rc != -1"); + + } + rc= mysql_query(mysql, "drop procedure p1"); + check_mysql_rc(rc, mysql); + + return OK; +} + + + + +struct my_tests_st my_tests[] = { + {"test_bug15752", test_bug15752, TEST_CONNECTION_NEW, 0, NULL , NULL}, + {NULL, NULL, 0, 0, NULL, NULL} +}; + +int main(int argc, char **argv) +{ + if (argc > 1) + get_options(argc, argv); + + get_envvars(); + + run_tests(my_tests); + + return(exit_status()); +} diff --git a/vendor/MDBC/unittest/libmariadb/ssl.c b/vendor/MDBC/unittest/libmariadb/ssl.c new file mode 100644 index 00000000..0cabe7c4 --- /dev/null +++ b/vendor/MDBC/unittest/libmariadb/ssl.c @@ -0,0 +1,1424 @@ +/************************************************************************************ + Copyright (C) 2012 Monty Program AB + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not see + or write to the Free Software Foundation, Inc., + 51 Franklin St., Fifth Floor, Boston, MA 02110, USA + *************************************************************************************/ +#if defined(WIN32) && defined(HEAP_CHECK) +#define _CRTDBG_MAP_ALLOC +#include +#include +#endif + +#include "my_test.h" +#include +#ifdef HAVE_OPENSSL +#include +#include +#endif + +#define FNLEN 4096 + +static int skip_ssl= 1; +static uchar have_openssl= 1; +static unsigned char have_tls13= 0; + +const char *ssluser= "ssluser"; +const char *sslpw= "sslpw"; +char sslhost[128]; +char sslcert[FNLEN]; +char sslcombined[FNLEN]; +char sslkey[FNLEN]; +char sslkey_enc[FNLEN]; +char sslca[FNLEN]; +char sslcrl[FNLEN]; +char ssl_cert_finger_print[129]= {0}; +char bad_cert_finger_print[]= "00:11:22:33:44:55:66:77:88:99:AA:BB:CC:DD:EE:FF:01:23:45:67"; + +pthread_mutex_t LOCK_test; + +void read_fingerprint() +{ + FILE *f= fopen(CERT_PATH "/server-cert.sha1", "r"); + if (f) + { + if (!fscanf(f, "%128s", ssl_cert_finger_print)) + ssl_cert_finger_print[0]= 0; + fclose(f); + } +} + +int check_skip_ssl() +{ + const char *ssldir= NULL; +#ifndef HAVE_TLS + diag("client library built without OpenSSL support -> skip"); + return 1; +#endif + if (skip_ssl) + { + diag("server doesn't support SSL -> skip"); + return 1; + } + if (!(ssldir= getenv("SECURE_LOAD_PATH"))) + { + ssldir= CERT_PATH; + if (!strlen(ssldir)) + { + diag("certificate directory not found"); + return 1; + } + } + snprintf(sslcert, FNLEN - 1, "%s/%s", ssldir, "client-cert.pem"); + snprintf(sslcombined, FNLEN - 1, "%s/%s", ssldir, "client-certkey.pem"); + snprintf(sslkey, FNLEN - 1, "%s/%s", ssldir, "client-key.pem"); + snprintf(sslkey_enc, FNLEN - 1, "%s/%s", ssldir, "client-key-enc.pem"); + snprintf(sslca, FNLEN - 1, "%s/%s", ssldir, "cacert.pem"); + return 0; +} + +static int check_cipher(MYSQL *mysql) +{ + char *cipher= (char *)mysql_get_ssl_cipher(mysql); + if (!cipher) + return 1; + diag("cipher: %s", cipher); + + return 0; +} + +static int create_ssl_user(const char *ssluser, my_bool is_X509) +{ + int rc; + char query[1024]; + MYSQL *mysql= mysql_init(NULL); + + FAIL_IF(!mysql_real_connect(mysql, hostname, username, password, schema, + port, socketname, 0), mysql_error(mysql)); + + sprintf(query, "DROP USER '%s'@'%s'", ssluser, this_host); + rc= mysql_query(mysql, query); + + sprintf(query, "CREATE USER '%s'@'%s' IDENTIFIED BY '%s'", ssluser, this_host, sslpw); + rc= mysql_query(mysql, query); + check_mysql_rc(rc,mysql); + + sprintf(query, "GRANT ALL ON %s.* TO '%s'@'%s' REQUIRE %s", schema, ssluser, this_host, is_X509 ? "X509" : "SSL"); + rc= mysql_query(mysql, query); + check_mysql_rc(rc,mysql); + rc= mysql_query(mysql, "FLUSH PRIVILEGES"); + check_mysql_rc(rc,mysql); + + mysql_close(mysql); + + return rc; +} + +static int test_ssl(MYSQL *mysql) +{ + int rc; + unsigned int iversion; + MYSQL_RES *res; + MYSQL_ROW row; + char *tls_library; + MYSQL *my= mysql_init(NULL); + + mysql_ssl_set(my,0, 0, 0, 0, 0); + + create_ssl_user("ssluser", 0); + + FAIL_IF(!mysql_real_connect(my, hostname, ssluser, sslpw, schema, + ssl_port, socketname, 0), mysql_error(my)); + + mariadb_get_infov(my, MARIADB_CONNECTION_TLS_VERSION_ID, &iversion); + diag("iversion: %d", iversion); + if (iversion == 4) + have_tls13= 1; + + mysql_close(my); + + rc= mysql_query(mysql, "SELECT @@have_ssl, @@have_openssl"); + check_mysql_rc(rc, mysql); + + res= mysql_store_result(mysql); + FAIL_IF(!res, mysql_error(mysql)); + + while ((row= mysql_fetch_row(res))) + { + if (!strcmp(row[0], "YES")) + skip_ssl= 0; + if (strcmp(row[1], "YES")) + have_openssl= 0; + diag("SSL: %s", row[0]); + } + mysql_free_result(res); + + /* In MySQL we need to check tls_version */ + if (!mariadb_connection(mysql)) + { + rc= mysql_query(mysql, "select locate('v1.2', @@tls_version) > 0"); + check_mysql_rc(rc, mysql); + + res= mysql_store_result(mysql); + FAIL_IF(!res, mysql_error(mysql)); + + if ((row= mysql_fetch_row(res))) + { + if (row[0] && row[0][0] == '0') + have_openssl= 0; + } + mysql_free_result(res); + } + diag("OpenSSL: %d", have_openssl); + + mariadb_get_infov(NULL, MARIADB_TLS_LIBRARY, &tls_library); + diag("SSL library: %s", tls_library); + + sslhost[0]= 0; + + if (!skip_ssl) + { + char *p; + + rc= mysql_query(mysql, "SELECT CURRENT_USER()"); + check_mysql_rc(rc, mysql); + res= mysql_store_result(mysql); + row= mysql_fetch_row(res); + diag("user: %s", row[0]); + if ((p= strchr(row[0], '@'))) + strcpy(sslhost, p+1); + mysql_free_result(res); + } + + return OK; +} + +static int test_ssl_cipher(MYSQL *unused __attribute__((unused))) +{ + MYSQL *my; + MYSQL_RES *res; + MYSQL_ROW row; + int rc; + + if (check_skip_ssl()) + return SKIP; + + my= mysql_init(NULL); + FAIL_IF(!my, "mysql_init() failed"); + + mysql_ssl_set(my,0, 0, sslca, 0, 0); + + FAIL_IF(!mysql_real_connect(my, hostname, ssluser, sslpw, schema, + ssl_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; +} + +static int test_conc95(MYSQL *unused __attribute__((unused))) +{ + MYSQL *mysql; + + if (check_skip_ssl()) + return SKIP; + + create_ssl_user("ssluser1", 1); + + mysql= mysql_init(NULL); + mysql_ssl_set(mysql, + sslkey, + sslcert, + NULL, + NULL, + NULL); + + if (!mysql_real_connect(mysql, hostname, "ssluser1", sslpw, schema, + ssl_port, socketname, 0)) + { + diag("could not establish x509 connection. Error: %s", mysql_error(mysql)); + mysql_close(mysql); + return FAIL; + } + mysql_close(mysql); + return OK; +} + +static int test_multi_ssl_connections(MYSQL *unused __attribute__((unused))) +{ + MYSQL *mysql[50], *my; + int i, rc; + int old_connections= 0, new_connections= 0; + MYSQL_RES *res; + MYSQL_ROW row; + + if (check_skip_ssl()) + return SKIP; + + diag("Test doesn't work with yassl"); + return SKIP; + + create_ssl_user(ssluser, 0); + + my= mysql_init(NULL); + FAIL_IF(!my,"mysql_init() failed"); + FAIL_IF(!mysql_real_connect(my, hostname, ssluser, sslpw, schema, + ssl_port, socketname, 0), mysql_error(my)); + + rc= mysql_query(my, "SHOW STATUS LIKE 'Ssl_accepts'"); + check_mysql_rc(rc, my); + + res= mysql_store_result(my); + if ((row= mysql_fetch_row(res))) + old_connections= atoi(row[1]); + mysql_free_result(res); + + for (i=0; i < 50; i++) + { + mysql[i]= mysql_init(NULL); + FAIL_IF(!mysql[i],"mysql_init() failed"); + + mysql_ssl_set(mysql[i], 0, 0, sslca, 0, 0); + + mysql_real_connect(mysql[i], hostname, ssluser, sslpw, schema, + ssl_port, socketname, 0); + if (mysql_errno(mysql[i])) + { + diag("loop: %d error: %d %s", i, mysql_errno(mysql[i]), mysql_error(mysql[i])); + return FAIL; + } + + FAIL_IF(check_cipher(mysql[i]) != 0, "Invalid cipher"); + } + for (i=0; i < 50; i++) + mysql_close(mysql[i]); + + rc= mysql_query(my, "SHOW STATUS LIKE 'Ssl_accepts'"); + check_mysql_rc(rc, my); + + res= mysql_store_result(my); + if ((row= mysql_fetch_row(res))) + new_connections= atoi(row[1]); + mysql_free_result(res); + + mysql_close(my); + + diag("%d SSL connections processed", new_connections - old_connections); + FAIL_IF(new_connections - old_connections < 50, "new_connections should be at least old_connections + 50"); + return OK; +} + +#ifndef WIN32 +static void ssl_thread(void *unused __attribute__((unused))) +#else +DWORD WINAPI ssl_thread(void *dummy) +#endif +{ + MYSQL *mysql= NULL; + + mysql_thread_init(); + + if (!(mysql= mysql_init(NULL))) + { + goto end; + } + mysql_ssl_set(mysql, 0, 0, sslca, 0, 0); + + if(!mysql_real_connect(mysql, hostname, ssluser, sslpw, schema, + ssl_port, socketname, 0)) + { + diag(">Error: %s", mysql_error(mysql)); + goto end; + } + + pthread_mutex_lock(&LOCK_test); + mysql_query(mysql, "UPDATE ssltest SET a=a+1"); + pthread_mutex_unlock(&LOCK_test); + +end: + if(mysql) + mysql_close(mysql); + mysql_thread_end(); +#ifdef _WIN32 + return 0; +#endif +} + +static int test_ssl_threads(MYSQL *mysql) +{ + int i, rc; +#ifndef WIN32 + pthread_t threads[50]; +#else + HANDLE hthreads[50]; + DWORD dthreads[50]; +#endif + MYSQL_RES *res; + MYSQL_ROW row; + + if (check_skip_ssl()) + return SKIP; + + rc= mysql_query(mysql, "DROP TABLE IF exists ssltest"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "CREATE TABLE ssltest (a int)"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "INSERT into ssltest VALUES (0)"); + check_mysql_rc(rc, mysql); + pthread_mutex_init(&LOCK_test, NULL); + + pthread_mutex_init(&LOCK_test, NULL); + + for (i=0; i < 50; i++) + { +#ifndef WIN32 + pthread_create(&threads[i], NULL, (void *)ssl_thread, NULL); +#else + hthreads[i]= CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)ssl_thread, NULL, 0, &dthreads[i]); + if (hthreads[i]==NULL) + diag("error while starting thread"); +#endif + } + for (i=0; i < 50; i++) +#ifndef WIN32 + pthread_join(threads[i], NULL); +#else + WaitForSingleObject(hthreads[i], INFINITE); +#endif + + pthread_mutex_destroy(&LOCK_test); + + rc= mysql_query(mysql, "SELECT a FROM ssltest"); + check_mysql_rc(rc, mysql); + res= mysql_store_result(mysql); + row= mysql_fetch_row(res); + diag("Found: %s", row[0]); + FAIL_IF(strcmp(row[0], "50") != 0, "Expected 50"); + mysql_free_result(res); + rc= mysql_query(mysql, "DROP TABLE IF exists ssltest"); + check_mysql_rc(rc, mysql); + return OK; +} + +static int test_phpbug51647(MYSQL *unused __attribute__((unused))) +{ + MYSQL* mysql; + + if (check_skip_ssl()) + return SKIP; + + mysql= mysql_init(NULL); + FAIL_IF(!mysql, "Can't allocate memory"); + + mysql_ssl_set(mysql, sslkey, + sslcert, + sslca, 0, 0); + + FAIL_IF(!mysql_real_connect(mysql, hostname, ssluser, sslpw, schema, + ssl_port, socketname, 0), mysql_error(mysql)); + diag("%s", mysql_get_ssl_cipher(mysql)); + mysql_close(mysql); + + return OK; +} + +static int test_password_protected(MYSQL *unused __attribute__((unused))) +{ + MYSQL* mysql; + + if (check_skip_ssl()) + return SKIP; + + mysql= mysql_init(NULL); + FAIL_IF(!mysql, "Can't allocate memory"); + + mysql_ssl_set(mysql, sslkey_enc, + sslcert, + sslca, 0, 0); + + mysql_options(mysql, MARIADB_OPT_TLS_PASSPHRASE, "qwerty"); + + FAIL_IF(!mysql_real_connect(mysql, hostname, ssluser, sslpw, schema, + ssl_port, socketname, 0), mysql_error(mysql)); + diag("%s", mysql_get_ssl_cipher(mysql)); + mysql_close(mysql); + + return OK; +} + + +static int test_conc50(MYSQL *unused __attribute__((unused))) +{ + MYSQL *mysql; + + if (check_skip_ssl()) + return SKIP; + + mysql= mysql_init(NULL); + FAIL_IF(!mysql, "Can't allocate memory"); + + mysql_ssl_set(mysql, NULL, NULL, "./non_exisiting_cert.pem", NULL, NULL); + + mysql_real_connect(mysql, hostname, ssluser, sslpw, schema, + ssl_port, socketname, 0); + diag("Error: %d %s", mysql_errno(mysql), mysql_error(mysql)); + FAIL_IF(mysql_errno(mysql) != 2026, "Expected errno 2026"); + mysql_close(mysql); + + return OK; +} + +static int test_conc50_1(MYSQL *unused __attribute__((unused))) +{ + MYSQL *mysql; + + if (check_skip_ssl()) + return SKIP; + + if (!have_openssl) + { + diag("Server with OpenSSL required"); + return SKIP; + } + + create_ssl_user(ssluser, 0); + + mysql= mysql_init(NULL); + FAIL_IF(!mysql, "Can't allocate memory"); + + mysql_ssl_set(mysql, NULL, NULL, sslca, NULL, NULL); + + mysql_real_connect(mysql, hostname, ssluser, sslpw, schema, + ssl_port, socketname, 0); + if (mysql_errno(mysql)) + diag("Error: %d %s", mysql_errno(mysql), mysql_error(mysql)); + FAIL_IF(mysql_errno(mysql), "No error expected"); + + mysql_close(mysql); + + return OK; +} + +static int test_conc50_2(MYSQL *unused __attribute__((unused))) +{ + MYSQL *mysql; + + if (check_skip_ssl()) + return SKIP; + + mysql= mysql_init(NULL); + FAIL_IF(!mysql, "Can't allocate memory"); + + mysql_ssl_set(mysql, NULL, NULL, "./non_exisiting_cert.pem", NULL, NULL); + + mysql_real_connect(mysql, hostname, ssluser, sslpw, schema, + ssl_port, socketname, 0); + FAIL_IF(mysql_errno(mysql) != 2026, "Expected errno 2026"); + mysql_close(mysql); + + return OK; +} + +static int test_conc127(MYSQL *unused __attribute__((unused))) +{ + MYSQL *mysql; + + diag("test disabled - for testing disable other tests or run this test as first test"); + return SKIP; + + if (check_skip_ssl()) + return SKIP; + + mysql= mysql_init(NULL); + FAIL_IF(!mysql, "Can't allocate memory"); + + mysql_ssl_set(mysql, NULL, NULL, "./non_exisiting.pem", NULL, NULL); + + mysql_real_connect(mysql, hostname, ssluser, sslpw, schema, + ssl_port, socketname, 0); + diag("Error: %s", mysql_error(mysql)); + FAIL_IF(mysql_errno(mysql) == 0, "Error expected (invalid certificate)"); + mysql_close(mysql); + + return OK; +} + +static int test_conc50_3(MYSQL *unused __attribute__((unused))) +{ + MYSQL *mysql; + + if (check_skip_ssl()) + return SKIP; + + create_ssl_user(ssluser, 0); + + mysql= mysql_init(NULL); + FAIL_IF(!mysql, "Can't allocate memory"); + + mysql_real_connect(mysql, hostname, ssluser, sslpw, schema, + ssl_port, socketname, 0); + FAIL_IF(!mysql_errno(mysql), "Error expected, SSL connection required!"); + mysql_close(mysql); + + mysql= mysql_init(NULL); + FAIL_IF(!mysql, "Can't allocate memory"); + + mysql_ssl_set(mysql, NULL, NULL, sslca, NULL, NULL); + + mysql_real_connect(mysql, hostname, ssluser, sslpw, schema, + ssl_port, socketname, 0); + diag("Error: %s<", mysql_error(mysql)); + FAIL_IF(mysql_errno(mysql), "No error expected"); + mysql_close(mysql); + + return OK; +} + +static int test_conc50_4(MYSQL *unused __attribute__((unused))) +{ + MYSQL *mysql; + + if (check_skip_ssl()) + return SKIP; + + mysql= mysql_init(NULL); + FAIL_IF(!mysql, "Can't allocate memory"); + + mysql_ssl_set(mysql, NULL, sslca, NULL, NULL, NULL); + + mysql_real_connect(mysql, hostname, ssluser, sslpw, schema, + ssl_port, socketname, 0); + FAIL_IF(!mysql_errno(mysql) , "Error expected"); + mysql_close(mysql); + + return OK; +} + +static int verify_ssl_server_cert(MYSQL *unused __attribute__((unused))) +{ + MYSQL *mysql; + uint verify= 1; + + if (check_skip_ssl()) + return SKIP; + + if (!hostname || !strcmp(hostname, "localhost")) + return SKIP; + + SKIP_TRAVIS(); + + mysql= mysql_init(NULL); + FAIL_IF(!mysql, "Can't allocate memory"); + + mysql_ssl_set(mysql, NULL, NULL, sslca, NULL, NULL); + mysql_options(mysql, MYSQL_OPT_SSL_VERIFY_SERVER_CERT, &verify); + + mysql_real_connect(mysql, hostname, ssluser, sslpw, schema, + ssl_port, socketname, 0); + + FAIL_IF(!mysql_errno(mysql), "Expected error"); + diag("Error (expected): %s", mysql_error(mysql)); + mysql_close(mysql); + + return OK; +} + +static int test_bug62743(MYSQL *unused __attribute__((unused))) +{ + MYSQL *mysql; + + if (check_skip_ssl()) + return SKIP; + + mysql= mysql_init(NULL); + FAIL_IF(!mysql, "Can't allocate memory"); + + mysql_ssl_set(mysql, "dummykey", NULL, NULL, NULL, NULL); + + mysql_real_connect(mysql, hostname, ssluser, sslpw, schema, + ssl_port, socketname, 0); + diag("Error: %s", mysql_error(mysql)); + FAIL_IF(mysql_errno(mysql) != 2026, "Expected errno 2026"); + mysql_close(mysql); + + mysql= mysql_init(NULL); + FAIL_IF(!mysql, "Can't allocate memory"); + + mysql_ssl_set(mysql, sslkey, NULL, NULL, NULL, NULL); + + mysql_real_connect(mysql, hostname, ssluser, sslpw, schema, + ssl_port, socketname, 0); + diag("Error with key: %s", mysql_error(mysql)); + FAIL_IF(mysql_errno(mysql) != 2026, "Expected errno 2026"); + mysql_close(mysql); + + mysql= mysql_init(NULL); + FAIL_IF(!mysql, "Can't allocate memory"); + + mysql_ssl_set(mysql, sslkey, + sslcert, NULL, NULL, NULL); + + mysql_real_connect(mysql, hostname, ssluser, sslpw, schema, + ssl_port, socketname, 0); + FAIL_IF(mysql_errno(mysql) != 0, "Expected no error"); + mysql_close(mysql); + + mysql= mysql_init(NULL); + FAIL_IF(!mysql, "Can't allocate memory"); + + mysql_ssl_set(mysql, sslkey, "blablubb", NULL, NULL, NULL); + + mysql_real_connect(mysql, hostname, ssluser, sslpw, schema, + ssl_port, socketname, 0); + diag("Error with cert: %s", mysql_error(mysql)); + FAIL_IF(mysql_errno(mysql) == 0, "Expected error"); + mysql_close(mysql); + + return OK; +} + +#ifndef WIN32 +int thread_conc102(void) +#else +DWORD WINAPI thread_conc102(void) +#endif +{ + MYSQL *mysql; + int rc; + MYSQL_RES *res; + mysql_thread_init(); + mysql= mysql_init(NULL); + + mysql_ssl_set(mysql, sslkey, + sslcert, + sslca, + NULL, NULL); + mysql_ssl_set(mysql,0, 0, sslca, 0, 0); + + if(!mysql_real_connect(mysql, hostname, username, password, schema, + ssl_port, socketname, 0)) + { + diag(">Error: %s", mysql_error(mysql)); + goto end; + } + if (!mysql_get_ssl_cipher(mysql)) + { + diag("Error: No ssl connection"); + goto end; + } + pthread_mutex_lock(&LOCK_test); + rc= mysql_query(mysql, "UPDATE t_conc102 SET a=a+1"); + check_mysql_rc(rc, mysql); + pthread_mutex_unlock(&LOCK_test); + check_mysql_rc(rc, mysql); + if ((res= mysql_store_result(mysql))) + mysql_free_result(res); +end: + mysql_close(mysql); + mysql_thread_end(); + return 0; +} + +static int test_conc_102(MYSQL *mysql) +{ + + int rc; + int i; + MYSQL_ROW row; + MYSQL_RES *res; +#ifndef WIN32 + pthread_t threads[50]; +#else + HANDLE hthreads[50]; + DWORD threads[50]; +#endif + + if (check_skip_ssl()) + return SKIP; + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS t_conc102"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "CREATE TABLE t_conc102 ( a int)"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "INSERT INTO t_conc102 VALUES (0)"); + check_mysql_rc(rc, mysql); + pthread_mutex_init(&LOCK_test, NULL); + + for (i=0; i < 50; i++) + { +#ifndef WIN32 + pthread_create(&threads[i], NULL, (void *)thread_conc102, NULL); +#else + hthreads[i]= CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)thread_conc102, NULL, 0, &threads[i]); + if (hthreads[i]==NULL) + diag("error while starting thread"); +#endif + } + for (i=0; i < 50; i++) + { +#ifndef WIN32 + pthread_join(threads[i], NULL); +#else + WaitForSingleObject(hthreads[i], INFINITE); +#endif + } + pthread_mutex_destroy(&LOCK_test); + rc= mysql_query(mysql, "SELECT a FROM t_conc102"); + check_mysql_rc(rc, mysql); + res= mysql_store_result(mysql); + row= mysql_fetch_row(res); + diag("Found: %s", row[0]); + FAIL_IF(strcmp(row[0], "50") != 0, "Expected 50"); + mysql_free_result(res); + rc= mysql_query(mysql, "DROP TABLE IF EXISTS t_conc102"); + check_mysql_rc(rc, mysql); + return OK; +} + +static int test_ssl_fp(MYSQL *unused __attribute__((unused))) +{ + MYSQL *my; + MYSQL_RES *res; + MYSQL_ROW row; + int rc; + + if (check_skip_ssl()) + return SKIP; + + my= mysql_init(NULL); + FAIL_IF(!my, "mysql_init() failed"); + + mysql_ssl_set(my,0, 0, sslca, 0, 0); + + mysql_options(my, MARIADB_OPT_SSL_FP, bad_cert_finger_print); + + FAIL_IF(mysql_real_connect(my, hostname, username, password, schema, + ssl_port, socketname, 0), mysql_error(my)); + + mysql_options(my, MARIADB_OPT_SSL_FP, ssl_cert_finger_print); + + FAIL_IF(!mysql_real_connect(my, hostname, username, password, schema, + ssl_port, socketname, 0), mysql_error(my)); + + FAIL_IF(check_cipher(my) != 0, "Invalid cipher"); + + rc= mysql_query(my, "SET @a:=1"); + check_mysql_rc(rc, my); + + rc= mysql_query(my, "SELECT @a"); + check_mysql_rc(rc, my); + + if ((res= mysql_store_result(my))) + { + row= mysql_fetch_row(res); + diag("@a:=%s", row[0]); + mysql_free_result(res); + } + + mysql_close(my); + return OK; +} + +static int test_ssl_fp_list(MYSQL *unused __attribute__((unused))) +{ + MYSQL *my; + + if (check_skip_ssl()) + return SKIP; + + my= mysql_init(NULL); + FAIL_IF(!my, "mysql_init() failed"); + + mysql_ssl_set(my,0, 0, sslca, 0, 0); + + mysql_options(my, MARIADB_OPT_SSL_FP_LIST, CERT_PATH "/server-cert.sha1"); + + if(!mysql_real_connect(my, hostname, username, password, schema, + ssl_port, socketname, 0)) + { + diag("Error: %s", mysql_error(my)); + mysql_close(my); + return FAIL; + } + + FAIL_IF(check_cipher(my) != 0, "Invalid cipher"); + mysql_close(my); + return OK; +} + +static int test_ssl_version(MYSQL *unused __attribute__((unused))) +{ + unsigned int iversion; + char *version, *library; + MYSQL *my; + + if (check_skip_ssl()) + return SKIP; + + my= mysql_init(NULL); + FAIL_IF(!my, "mysql_init() failed"); + + mysql_ssl_set(my,0, 0, sslca, 0, 0); + FAIL_IF(!mysql_real_connect(my, hostname, ssluser, sslpw, schema, + ssl_port, socketname, 0), mysql_error(my)); + + diag("cipher: %s", mysql_get_ssl_cipher(my)); + mariadb_get_infov(my, MARIADB_CONNECTION_TLS_VERSION_ID, &iversion); + diag("protocol: %d", iversion); + mariadb_get_infov(my, MARIADB_CONNECTION_TLS_VERSION, &version); + diag("protocol: %s", version); + + mariadb_get_infov(my, MARIADB_TLS_LIBRARY, &library); + diag("library: %s", library); + + mysql_close(my); + + return OK; +} + +#ifdef HAVE_SCHANNEL +static int test_schannel_cipher(MYSQL *unused __attribute__((unused))) +{ + MYSQL *my; + unsigned int cipher_strength= 256; + + if (check_skip_ssl()) + return SKIP; + + my= mysql_init(NULL); + FAIL_IF(!my, "mysql_init() failed"); + + mysql_ssl_set(my,0, 0, sslca, 0, 0); + mysql_options(my, MARIADB_OPT_TLS_CIPHER_STRENGTH, &cipher_strength); + FAIL_IF(!mysql_real_connect(my, hostname, ssluser, sslpw, schema, + ssl_port, socketname, 0), mysql_error(my)); + + diag("cipher: %s", mysql_get_ssl_cipher(my)); + + mysql_close(my); + + return OK; +} + +#endif + +#if defined(HAVE_GNUTLS) || defined(HAVE_OPENSSL) + +static int test_cipher_mapping(MYSQL *unused __attribute__((unused))) +{ + unsigned int i=0; + const char *ciphers[]= { "DHE-RSA-AES256-GCM-SHA384", "DHE-RSA-AES256-SHA256", "DHE-RSA-AES256-SHA", +#ifdef TEST_CAMELLIA_CIPHER + "DHE-RSA-CAMELLIA256-SHA", "CAMELLIA256-SHA", + "DHE-RSA-CAMELLIA128-SHA", "CAMELLIA128-SHA", +#endif +#ifdef TEST_DES_CIPHER + "EDH-RSA-DES-CBC3-SHA", + "DES-CBC3-SHA", +#endif + "AES256-GCM-SHA384", "AES256-SHA256", "AES256-SHA", + "DHE-RSA-AES128-GCM-SHA256", "DHE-RSA-AES128-SHA256", "DHE-RSA-AES128-SHA", + "AES128-GCM-SHA256", "AES128-SHA256", "AES128-SHA", + "DHE-RSA-AES256-SHA", "AES256-SHA", + NULL }; + + diag("This test depends on OpenSSL version - since several ciphers might not be available"); + return SKIP; + + if (check_skip_ssl()) + return SKIP; + + if (!have_openssl) + { + diag("test requires Server with OpenSSL"); + return SKIP; + } + + while (ciphers[i] != NULL) + { + MYSQL *mysql= mysql_init(NULL); + MYSQL_ROW row; + MYSQL_RES *res; + char c[100]; + int rc; + const char *cipher; + + mysql_options(mysql, MYSQL_OPT_TLS_VERSION, "TLSv1.0,TLSv1.1,TLSv1.2"); + mysql_ssl_set(mysql, NULL, NULL, NULL, NULL, ciphers[i]); + diag("%s", ciphers[i]); + + mysql->options.use_ssl= 1; + FAIL_IF(!mysql_real_connect(mysql, hostname, username, password, schema, + ssl_port, socketname, 0), mysql_error(mysql)); + if (!(cipher= mysql_get_ssl_cipher(mysql)) || + strcmp(ciphers[i], cipher) != 0) + { + diag("cipher %s differs: (%s)", ciphers[i], cipher); + mysql_close(mysql); + goto cont; + } + else + { + rc= mysql_query(mysql, "SHOW STATUS LIKE 'ssl_cipher'"); + check_mysql_rc(rc, mysql); + res= mysql_store_result(mysql); + row= mysql_fetch_row(res); + strcpy(c, row[1]); + mysql_free_result(res); + mysql_close(mysql); + if (strcmp(ciphers[i], c) != 0) + { + diag("expected: %s instead of %s", ciphers[i], c); + /* depending if server supports ECC, ciphers may differ, + so we don't return failure here */ + } + } +cont: + i++; + } + return OK; +} +#endif + +static int test_openssl_1(MYSQL *mysql) +{ + int rc; + MYSQL *my; + uchar val= 1; + char query[1024]; + int i; + + if (check_skip_ssl()) + return SKIP; + + if (have_tls13) + return SKIP; + + if (!mariadb_connection(mysql)) + return SKIP; + + for (i=1; i < 6; i++) + { + sprintf(query, "DROP USER 'ssluser%d'@'%s'", i, this_host); + rc= mysql_query(mysql, query); + sprintf(query, "CREATE USER 'ssluser%d'@'%s'", i, this_host); + rc= mysql_query(mysql, query); + check_mysql_rc(rc, mysql); + } + rc= mysql_query(mysql, "FLUSH PRIVILEGES"); + check_mysql_rc(rc, mysql); + diag("sslusers created"); + + diag("ssluser1"); + sprintf(query, "grant select on %s.* to 'ssluser1'@'%s' require ssl", schema, this_host); + rc= mysql_query(mysql, query); + check_mysql_rc(rc, mysql); + + + my= mysql_init(NULL); + mysql_ssl_set(my, NULL, NULL, NULL, NULL, "AES128-SHA"); + FAIL_IF(!mysql_real_connect(my, hostname, "ssluser1", NULL, schema, + ssl_port, socketname, 0), mysql_error(my)); + FAIL_IF(!mysql_get_ssl_cipher(my), "No TLS connection"); + mysql_close(my); + + my= mysql_init(NULL); + mysql_options(my, MYSQL_OPT_SSL_ENFORCE, &val); + FAIL_IF(!mysql_real_connect(my, hostname, "ssluser1", NULL, schema, + ssl_port, socketname, 0), mysql_error(my)); + FAIL_IF(!mysql_get_ssl_cipher(my), "No TLS connection"); + mysql_close(my); + + diag("ssluser2"); + sprintf(query, "grant select on %s.* to 'ssluser2'@'%s' require cipher 'AES256-SHA'", schema, this_host); + rc= mysql_query(mysql, query); + check_mysql_rc(rc, mysql); + +#ifdef TEST_RANDOM_RESULT +/* ssl_user2: connect with enforce should work */ + my= mysql_init(NULL); + mysql_options(my, MYSQL_OPT_SSL_ENFORCE, &val); + mysql_real_connect(my, hostname, "ssluser2", NULL, schema, + ssl_port, socketname, 0); + if (!mysql_error(my) && + strcmp(mysql_get_ssl_cipher(my), "AES256-SHA")) + { + diag("Expected error or correct cipher"); + return FAIL; + } + mysql_close(my); +#endif + /* ssl_user2: connect with correct cipher */ + diag("ssluser2"); + if (mysql_get_server_version(mysql) >= 100100) + { + my= mysql_init(NULL); + mysql_ssl_set(my, NULL, NULL, NULL, NULL, "AES256-SHA"); + FAIL_IF(!mysql_real_connect(my, hostname, "ssluser2", NULL, schema, + ssl_port, socketname, 0), mysql_error(my)); + FAIL_IF(strcmp("AES256-SHA", mysql_get_ssl_cipher(my)) != 0, "expected cipher AES256-SHA"); + mysql_close(my); + } + + /* ssl_user2: connect with wrong cipher should not work */ + diag("ssluser2"); + my= mysql_init(NULL); + mysql_ssl_set(my, NULL, NULL, NULL, NULL, "AES128-SHA"); + FAIL_IF(mysql_real_connect(my, hostname, "ssluser2", NULL, schema, + ssl_port, socketname, 0), "Error expected"); + mysql_close(my); + + + if (!travis_test) + { + sprintf(query, "grant select on %s.* to 'ssluser3'@'%s' require cipher 'AES256-SHA' AND " + " SUBJECT '/C=FI/ST=Helsinki/L=Helsinki/O=MariaDB/CN=client'", schema, this_host); + rc= mysql_query(mysql, query); + check_mysql_rc(rc, mysql); + + /* ssluser3: connect with cipher only */ + my= mysql_init(NULL); + mysql_ssl_set(my, NULL, NULL, NULL, NULL, "AES256-SHA"); + FAIL_IF(mysql_real_connect(my, hostname, "ssluser3", NULL, schema, + ssl_port, socketname, 0), "Error expected"); + mysql_close(my); + + /* ssluser3 connect with cipher and certs */ + my= mysql_init(NULL); + mysql_ssl_set(my, sslkey, + sslcert, + sslca, + NULL, + "AES256-SHA"); + FAIL_IF(!mysql_real_connect(my, hostname, "ssluser3", NULL, schema, + ssl_port, socketname, 0), mysql_error(my)); + + mysql_close(my); + + sprintf(query, "grant select on %s.* to 'ssluser4'@'%s' require cipher 'AES256-SHA' AND " + " ISSUER '/CN=cacert/C=FI/ST=Helsinki/L=Helsinki/O=MariaDB'", schema, this_host); + rc= mysql_query(mysql, query); + check_mysql_rc(rc, mysql); + + /* ssluser4: connect with cipher only */ + my= mysql_init(NULL); + mysql_ssl_set(my, NULL, NULL, NULL, NULL, "AES256-SHA"); + FAIL_IF(mysql_real_connect(my, hostname, "ssluser4", NULL, schema, + ssl_port, socketname, 0), "Error expected"); + mysql_close(my); + + /* ssluser4 connect with cipher and certs */ + my= mysql_init(NULL); + mysql_ssl_set(my, sslkey, + sslcert, + sslca, + NULL, + "AES256-SHA"); + FAIL_IF(!mysql_real_connect(my, hostname, "ssluser4", NULL, schema, + ssl_port, socketname, 0), mysql_error(my)); + mysql_close(my); + } + diag("drop users"); + for (i=1; i < 6; i++) + { + sprintf(query, "DROP USER 'ssluser%d'@'%s'", i, this_host); + rc= mysql_query(mysql, query); + } + + return OK; +} + +static int test_ssl_timeout(MYSQL *unused __attribute__((unused))) +{ + MYSQL *mysql; + my_bool enforce= 1; + int read_timeout= 1; + int rc; + + if (check_skip_ssl()) + return SKIP; + + mysql= mysql_init(NULL); + mysql_options(mysql, MYSQL_OPT_SSL_ENFORCE, &enforce); + mysql_options(mysql, MYSQL_OPT_READ_TIMEOUT, &read_timeout); + mysql->options.use_ssl= 1; + FAIL_IF(!mysql_real_connect(mysql, hostname, username, password, schema, + ssl_port, socketname, 0), mysql_error(mysql)); + diag("cipher: %s\n", mysql_get_ssl_cipher(mysql)); + rc= mysql_query(mysql, "SELECT SLEEP(600)"); + if (!rc) + { + diag("error expected (timeout)"); + return FAIL; + } + + mysql_close(mysql); + return OK; +} + +static int drop_ssl_user(MYSQL *mysql) +{ + int rc; + + rc= mysql_query(mysql, "DELETE FROM mysql.user where user like 'ssl%'"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "DELETE FROM mysql.db where user like 'ssl%'"); + check_mysql_rc(rc, mysql); + return OK; +} + +static int test_conc286(MYSQL *unused __attribute__((unused))) +{ + MYSQL *my; + + if (check_skip_ssl()) + return SKIP; + + my= mysql_init(NULL); + FAIL_IF(!my, "mysql_init() failed"); + + mysql_options(my, MARIADB_OPT_SSL_FP, ssl_cert_finger_print); + + FAIL_IF(!mysql_real_connect(my, hostname, username, password, schema, + ssl_port, socketname, 0), mysql_error(my)); + + FAIL_IF(check_cipher(my) != 0, "Invalid cipher"); + + mysql_close(my); + return OK; +} + +static int test_mdev14027(MYSQL *mysql __attribute__((unused))) +{ + char *tls_library; + const char *check_library= +#if defined(HAVE_OPENSSL) +#if defined(HAVE_LIBRESSL) + "LibreSSL"; +#else + "OpenSSL"; +#endif +#elif defined(HAVE_GNUTLS) + "GnuTLS"; +#elif defined(HAVE_SCHANNEL) + "Schannel"; +#else + "Off"; +#endif + mariadb_get_infov(NULL, MARIADB_TLS_LIBRARY, &tls_library); + diag("TLS/SSL library in use: %s\n", tls_library); + if (!strstr(tls_library, check_library)) + { + diag("expected %s, got %s", check_library, tls_library); + return FAIL; + } + return OK; +} + +static int test_mdev14101(MYSQL *my __attribute__((unused))) +{ + struct { + bool do_yassl; + const char *opt_tls_version; + const char *expected; + } combinations[]= { + {1, "TLSv1.1", "TLSv1.1"}, + {1, "TLSv1,TLSv1.1", "TLSv1.1"}, + {0, "TLSv1.2", "TLSv1.2"}, + {0, "TLSv1.1,TLSv1.2", "TLSv1.2"}, + {1, NULL, NULL} + }; + + int i; +#ifdef HAVE_SCHANNEL + bool skip_tlsv12= 1; +#else + bool skip_tlsv12= !have_openssl; +#endif + +#if defined(HAVE_OPENSSL) && defined(TLS1_3_VERSION) + diag("Test fails with TLS v1.3"); + return(SKIP); +#endif + + for (i=0; combinations[i].expected; i++) + { + MYSQL *mysql; + bool val=1; + char *tls_version; + + if (!combinations[i].do_yassl && skip_tlsv12) + break; + + diag("combination %d: %s", i, combinations[i].opt_tls_version); + + mysql= mysql_init(NULL); + mysql_options(mysql, MYSQL_OPT_SSL_ENFORCE, &val); + mysql_options(mysql, MARIADB_OPT_TLS_VERSION, combinations[i].opt_tls_version); + FAIL_IF(!mysql_real_connect(mysql, hostname, username, password, schema, + ssl_port, socketname, 0), mysql_error(mysql)); + mariadb_get_infov(mysql, MARIADB_CONNECTION_TLS_VERSION, &tls_version); + diag("options: %s", combinations[i].opt_tls_version); + diag("protocol: %s expected: %s", tls_version, combinations[i].expected); + FAIL_IF(strcmp(combinations[i].expected, tls_version), "Wrong tls_version"); + mysql_close(mysql); + } + return OK; +} + +static int test_conc386(MYSQL *mysql) +{ + mysql= mysql_init(NULL); + mysql_ssl_set(mysql, + sslcombined, + NULL, + NULL, + NULL, + NULL); + FAIL_IF(!mysql_real_connect(mysql, hostname, username, password, schema, + ssl_port, socketname, 0), mysql_error(mysql)); + FAIL_IF(check_cipher(mysql) != 0, "Invalid cipher"); + mysql_close(mysql); + return OK; +} + +#ifndef HAVE_SCHANNEL +static int test_ssl_verify(MYSQL *my __attribute__((unused))) +{ + MYSQL *mysql; + my_bool verify= 1, enforce= 1; + + if (check_skip_ssl()) + return SKIP; + + /* verify, using system ca should fail with self signed certificate */ + mysql= mysql_init(NULL); + mysql_options(mysql, MYSQL_OPT_SSL_ENFORCE, &enforce); + mysql_options(mysql, MYSQL_OPT_SSL_VERIFY_SERVER_CERT, &verify); + FAIL_IF(mysql_real_connect(mysql, hostname, username, password, schema, + ssl_port, socketname, 0), "Error expected"); + diag("error expected: %s\n", mysql_error(mysql)); + mysql_close(mysql); + + /* verify, using system ca should pass */ + + /* Disable this for now, since for some unknown reason it fails on travis + setenv("SSL_CERT_DIR", CERT_PATH, 1); + mysql= mysql_init(NULL); + mysql_options(mysql, MYSQL_OPT_SSL_ENFORCE, &enforce); + mysql_options(mysql, MYSQL_OPT_SSL_VERIFY_SERVER_CERT, &verify); + FAIL_IF(!mysql_real_connect(mysql, hostname, username, password, schema, + port, socketname, 0), mysql_error(mysql)); + mysql_close(mysql); + unsetenv("SSL_CERT_DIR"); + */ + + /* verify against local ca, this should pass */ + mysql= mysql_init(NULL); + mysql_ssl_set(mysql,0, 0, sslca, 0, 0); + mysql_options(mysql, MYSQL_OPT_SSL_VERIFY_SERVER_CERT, &verify); + FAIL_IF(!mysql_real_connect(mysql, hostname, username, password, schema, + ssl_port, socketname, 0), mysql_error(mysql)); + mysql_close(mysql); + + mysql= mysql_init(NULL); + mysql_options(mysql, MYSQL_OPT_SSL_ENFORCE, &enforce); + FAIL_IF(!mysql_real_connect(mysql, hostname, username, password, schema, + ssl_port, socketname, 0), mysql_error(mysql)); + + diag("cipher: %s", mysql_get_ssl_cipher(mysql)); + mysql_close(mysql); + return OK; +} +#endif + +struct my_tests_st my_tests[] = { + {"test_ssl", test_ssl, TEST_CONNECTION_NEW, 0, NULL, NULL}, +#ifndef HAVE_SCHANNEL + {"test_ssl_verify", test_ssl_verify, TEST_CONNECTION_NEW, 0, NULL, NULL}, +#endif + {"test_mdev14101", test_mdev14101, TEST_CONNECTION_NEW, 0, NULL, NULL}, + {"test_mdev14027", test_mdev14027, TEST_CONNECTION_NEW, 0, NULL, NULL}, + {"test_conc286", test_conc286, TEST_CONNECTION_NEW, 0, NULL, NULL}, + {"test_ssl_timeout", test_ssl_timeout, TEST_CONNECTION_NEW, 0, NULL, NULL}, + {"test_openssl_1", test_openssl_1, TEST_CONNECTION_NEW, 0, NULL, NULL}, +#ifndef HAVE_SCHANNEL + {"test_cipher_mapping", test_cipher_mapping, TEST_CONNECTION_NONE, 0, NULL, NULL}, +#endif + {"test_conc127", test_conc127, TEST_CONNECTION_NEW, 0, NULL, NULL}, +/* Both tests work with GNU tls, however we can't create fingerprints with + gnutls-cli in CMakeLists.txt */ +#ifndef HAVE_SCHANNEL + {"test_ssl_fp", test_ssl_fp, TEST_CONNECTION_NEW, 0, NULL, NULL}, + {"test_ssl_fp_list", test_ssl_fp_list, TEST_CONNECTION_NEW, 0, NULL, NULL}, +#endif + {"test_conc50", test_conc50, TEST_CONNECTION_NEW, 0, NULL, NULL}, + {"test_conc50_1", test_conc50_1, TEST_CONNECTION_NEW, 0, NULL, NULL}, + {"test_conc50_2", test_conc50_2, TEST_CONNECTION_NEW, 0, NULL, NULL}, + {"test_conc50_3", test_conc50_3, TEST_CONNECTION_NEW, 0, NULL, NULL}, + {"test_conc50_4", test_conc50_4, TEST_CONNECTION_NEW, 0, NULL, NULL}, + {"test_conc95", test_conc95, TEST_CONNECTION_NEW, 0, NULL, NULL}, + {"verify_ssl_server_cert", verify_ssl_server_cert, TEST_CONNECTION_NEW, 0, NULL, NULL}, + {"test_bug62743", test_bug62743, TEST_CONNECTION_NEW, 0, NULL, NULL}, + {"test_phpbug51647", test_phpbug51647, TEST_CONNECTION_NONE, 0, NULL, NULL}, + {"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}, +#else + {"test_schannel_cipher", test_schannel_cipher, TEST_CONNECTION_NEW, 0, NULL, NULL}, +#endif + {"test_conc386", test_conc386, TEST_CONNECTION_NEW, 0, NULL, NULL}, + {"drop_ssl_user", drop_ssl_user, TEST_CONNECTION_NEW, 0, NULL, NULL}, + {NULL, NULL, 0, 0, NULL, NULL} +}; + + +int main(int argc, char **argv) +{ +#if defined(WIN32) && defined(HEAP_CHECK) + _CrtSetReportMode( _CRT_WARN, _CRTDBG_MODE_FILE ); + _CrtSetReportFile( _CRT_WARN, _CRTDBG_FILE_STDOUT ); + _CrtSetReportMode( _CRT_ERROR, _CRTDBG_MODE_FILE ); + _CrtSetReportFile( _CRT_ERROR, _CRTDBG_FILE_STDOUT ); + _CrtSetReportMode( _CRT_ASSERT, _CRTDBG_MODE_FILE ); + _CrtSetReportFile( _CRT_ASSERT, _CRTDBG_FILE_STDOUT ); +#endif + + get_envvars(); + read_fingerprint(); + + if (argc > 1) + get_options(argc, argv); + run_tests(my_tests); + + mysql_server_end(); +#if defined(WIN32) && defined(HEAP_CHECK) + _CrtDumpMemoryLeaks(); +#endif + return(exit_status()); +} + diff --git a/vendor/MDBC/unittest/libmariadb/t_aurora.c b/vendor/MDBC/unittest/libmariadb/t_aurora.c new file mode 100644 index 00000000..655b84e1 --- /dev/null +++ b/vendor/MDBC/unittest/libmariadb/t_aurora.c @@ -0,0 +1,164 @@ +/* +*/ + +#include "my_test.h" +#include "ma_pvio.h" + +static int aurora1(MYSQL *unused __attribute__((unused))) +{ + int rc; + my_bool read_only= 1; + char *primary, *my_schema; + MYSQL_RES *res; + MYSQL *mysql= mysql_init(NULL); + + if (!mysql_real_connect(mysql, hostname, username, password, schema, port, NULL, 0)) + { + diag("Error: %s", mysql_error(mysql)); + mysql_close(mysql); + return FAIL; + } + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE t1 (a int, b varchar(20))"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "INSERT INTO t1 VALUES (1, 'foo'), (2, 'bar')"); + check_mysql_rc(rc, mysql); + + mariadb_get_infov(mysql, MARIADB_CONNECTION_HOST, &primary); + diag("primary: %s", primary); + + mysql_options(mysql, MARIADB_OPT_CONNECTION_READ_ONLY, &read_only); + + /* ensure, that this is a replica, so INSERT should fail */ + rc= mysql_query(mysql, "INSERT INTO t1 VALUES (3, 'error')"); + if (rc) + diag("Expected error: %s", mysql_error(mysql)); + + rc= mysql_query(mysql, "SELECT a, b FROM t1"); + check_mysql_rc(rc, mysql); + + res= mysql_store_result(mysql); + + diag("Num_rows: %lld", mysql_num_rows(res)); + mysql_free_result(res); + + mariadb_get_infov(mysql, MARIADB_CONNECTION_SCHEMA, &my_schema); + diag("db: %s", my_schema); + + mysql_close(mysql); + + return OK; +} + +static int test_wrong_user(MYSQL *unused __attribute__((unused))) +{ + MYSQL *mysql= mysql_init(NULL); + + if (mysql_real_connect(mysql, hostname, "wrong_user", NULL, NULL, 0, NULL, 0)) + { + diag("Error expected"); + mysql_close(mysql); + return FAIL; + } + mysql_close(mysql); + return OK; +} + +static int test_reconnect(MYSQL *unused __attribute__((unused))) +{ + MYSQL *mysql= mysql_init(NULL); + MYSQL_RES *res; + my_bool read_only= 1; + int rc; + my_bool reconnect= 1; + char *aurora_host; + + mysql_options(mysql, MYSQL_OPT_RECONNECT, &reconnect); + + if (!mysql_real_connect(mysql, hostname, username, password, schema, port, NULL, 0)) + { + diag("Error: %s", mysql_error(mysql)); + mysql_close(mysql); + return FAIL; + } + + mariadb_get_infov(mysql, MARIADB_CONNECTION_HOST, &aurora_host); + diag("host: %s", aurora_host); + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS tx01"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "CREATE TABLE tx01 (a int)"); + check_mysql_rc(rc, mysql); + + /* we force cluster restart and promoting new primary: + * we wait for 50 seconds - however there is no guarantee that + * cluster was restarted already - so this test might fail */ + rc= system("/usr/local/aws/bin/aws rds failover-db-cluster --db-cluster-identifier instance-1-cluster"); + + diag("aws return code: %d", rc); + + sleep(50); + diag("Q1"); + rc= mysql_query(mysql, "INSERT INTO tx01 VALUES (1)"); + if (!rc) + diag("error expected!"); + diag("Error: %s", mysql_error(mysql)); + + diag("Q2"); + rc= mysql_query(mysql, "INSERT INTO tx01 VALUES (1)"); + if (rc) + { + diag("no error expected!"); + diag("Error: %s", mysql_error(mysql)); + diag("host: %s", mysql->host); + } + else + { + mariadb_get_infov(mysql, MARIADB_CONNECTION_HOST, &aurora_host); + diag("host: %s", aurora_host); + } + + mysql_options(mysql, MARIADB_OPT_CONNECTION_READ_ONLY, &read_only); + + rc= mysql_query(mysql, "SELECT * from tx01"); + check_mysql_rc(rc, mysql); + + if ((res= mysql_store_result(mysql))) + { + diag("num_rows: %lld", mysql_num_rows(res)); + mysql_free_result(res); + } + + mariadb_get_infov(mysql, MARIADB_CONNECTION_HOST, &aurora_host); + diag("host: %s", aurora_host); + + mysql_close(mysql); + return OK; +} + +struct my_tests_st my_tests[] = { + {"aurora1", aurora1, TEST_CONNECTION_NONE, 0, NULL, NULL}, + {"test_wrong_user", test_wrong_user, TEST_CONNECTION_NONE, 0, NULL, NULL}, + {"test_reconnect", test_reconnect, TEST_CONNECTION_NONE, 0, NULL, NULL}, + {NULL, NULL, 0, 0, NULL, NULL} +}; + + +int main(int argc, char **argv) +{ + mysql_library_init(0,0,NULL); + + if (argc > 1) + get_options(argc, argv); + + get_envvars(); + + run_tests(my_tests); + + mysql_server_end(); + return(exit_status()); +} diff --git a/vendor/MDBC/unittest/libmariadb/t_conc173.c b/vendor/MDBC/unittest/libmariadb/t_conc173.c new file mode 100644 index 00000000..97d05d47 --- /dev/null +++ b/vendor/MDBC/unittest/libmariadb/t_conc173.c @@ -0,0 +1,72 @@ +/* +Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. + +The MySQL Connector/C is licensed under the terms of the GPLv2 +, like most +MySQL Connectors. There are special exceptions to the terms and +conditions of the GPLv2 as it is applied to this software, see the +FLOSS License Exception +. + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published +by the Free Software Foundation; version 2 of the License. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ +/** + Some basic tests of the client API. +*/ + +#include "my_test.h" + +static int test_conc_173(MYSQL *unused __attribute__((unused))) +{ + MYSQL mysql; + int arg; + int i=0; + + for (;;) + { + mysql_init(&mysql); + mysql_options(&mysql, MYSQL_READ_DEFAULT_GROUP, "client"); + mysql_options(&mysql, MYSQL_OPT_COMPRESS, 0); + + mysql_options(&mysql, MYSQL_OPT_NAMED_PIPE, 0); + + arg = MYSQL_PROTOCOL_SOCKET; + + mysql_options(&mysql, MYSQL_OPT_PROTOCOL, &arg); + + if(!mysql_real_connect(&mysql, hostname, username, password, schema, port, 0, 0)) { + fprintf(stderr, "Failed to connect to database after %d iterations: Error: %s\n", i, mysql_error(&mysql)); + return 1; + } + mysql_close(&mysql); + } + return OK; +} + +struct my_tests_st my_tests[] = { + {"test_conc_173", test_conc_173, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, +}; + + +int main(int argc, char **argv) +{ + if (argc > 1) + get_options(argc, argv); + + get_envvars(); + + run_tests(my_tests); + + return(exit_status()); +} diff --git a/vendor/MDBC/unittest/libmariadb/thread.c b/vendor/MDBC/unittest/libmariadb/thread.c new file mode 100644 index 00000000..6fae38a8 --- /dev/null +++ b/vendor/MDBC/unittest/libmariadb/thread.c @@ -0,0 +1,180 @@ +/* +*/ + +#include "my_test.h" +#include + +static int basic_connect(MYSQL *unused __attribute__((unused))) +{ + MYSQL_ROW row; + MYSQL_RES *res; + MYSQL_FIELD *field; + int rc; + + MYSQL *my= mysql_init(NULL); + FAIL_IF(!my, "mysql_init() failed"); + + FAIL_IF(!my_test_connect(my, hostname, username, password, schema, + port, socketname, 0), mysql_error(my)); + + rc= mysql_query(my, "SELECT @@version"); + check_mysql_rc(rc, my); + + res= mysql_store_result(my); + FAIL_IF(!res, mysql_error(my)); + field= mysql_fetch_fields(res); + FAIL_IF(!field, "Couldn't fetch fields"); + + while ((row= mysql_fetch_row(res)) != NULL) + { + FAIL_IF(mysql_num_fields(res) != 1, "Got the wrong number of fields"); + } + FAIL_IF(mysql_errno(my), mysql_error(my)); + + mysql_free_result(res); + mysql_close(my); + + + return OK; +} + +pthread_mutex_t LOCK_test; + +#ifndef _WIN32 +int thread_conc27(void); +#else +DWORD WINAPI thread_conc27(void); +#endif + +#define THREAD_NUM 100 + +/* run this test as root and increase the number of handles (ulimit -n) */ +static int test_conc_27(MYSQL *mysql) +{ + + int rc; + int i; + MYSQL_ROW row; + MYSQL_RES *res; +#ifndef _WIN32 + pthread_t threads[THREAD_NUM]; +#else + HANDLE hthreads[THREAD_NUM]; + DWORD threads[THREAD_NUM]; +#endif + + diag("please run this test manually as root"); + return SKIP; + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS t_conc27"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE t_conc27(a int)"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "INSERT INTO t_conc27 VALUES(0)"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "SET @a:=@@max_connections"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "SET GLOBAL max_connections=100000"); + check_mysql_rc(rc, mysql); + + pthread_mutex_init(&LOCK_test, NULL); + for (i=0; i < THREAD_NUM; i++) + { +#ifndef _WIN32 + pthread_create(&threads[i], NULL, (void *)thread_conc27, NULL); +#else + hthreads[i]= CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)thread_conc27, NULL, 0, &threads[i]); + if (hthreads[i]==NULL) + diag("error while starting thread"); +#endif + } + for (i=0; i < THREAD_NUM; i++) + { +#ifndef _WIN32 + pthread_join(threads[i], NULL); +#else + WaitForSingleObject(hthreads[i], INFINITE); +#endif + } + + pthread_mutex_destroy(&LOCK_test); + + rc= mysql_query(mysql, "SET GLOBAL max_connections=@a"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "SELECT a FROM t_conc27"); + check_mysql_rc(rc,mysql); + + res= mysql_store_result(mysql); + FAIL_IF(!res, "invalid result"); + + row= mysql_fetch_row(res); + FAIL_IF(!row, "can't fetch row"); + + diag("row=%s", row[0]); + FAIL_IF(atoi(row[0]) != THREAD_NUM, "expected value THREAD_NUM"); + mysql_free_result(res); + rc= mysql_query(mysql, "DROP TABLE t_conc27"); + check_mysql_rc(rc,mysql); + + return OK; +} + +#ifndef _WIN32 +int thread_conc27(void) +#else +DWORD WINAPI thread_conc27(void) +#endif +{ + MYSQL *mysql; + int rc; + MYSQL_RES *res; + mysql_thread_init(); + mysql= mysql_init(NULL); + if(!my_test_connect(mysql, hostname, username, password, schema, + port, socketname, 0)) + { + diag(">Error: %s", mysql_error(mysql)); + mysql_close(mysql); + mysql_thread_end(); + goto end; + } + pthread_mutex_lock(&LOCK_test); + rc= mysql_query(mysql, "UPDATE t_conc27 SET a=a+1"); + check_mysql_rc(rc, mysql); + pthread_mutex_unlock(&LOCK_test); + check_mysql_rc(rc, mysql); + if ((res= mysql_store_result(mysql))) + mysql_free_result(res); + mysql_close(mysql); +end: + mysql_thread_end(); + return 0; +} + +struct my_tests_st my_tests[] = { + {"basic_connect", basic_connect, TEST_CONNECTION_NONE, 0, NULL, NULL}, + {"test_conc_27", test_conc_27, TEST_CONNECTION_NEW, 0, NULL, NULL}, + {NULL, NULL, 0, 0, NULL, NULL} +}; + + +int main(int argc, char **argv) +{ + + mysql_library_init(0,0,NULL); + + if (argc > 1) + get_options(argc, argv); + + get_envvars(); + + run_tests(my_tests); + + mysql_server_end(); + return(exit_status()); +} diff --git a/vendor/MDBC/unittest/libmariadb/view.c b/vendor/MDBC/unittest/libmariadb/view.c new file mode 100644 index 00000000..10d6f3ef --- /dev/null +++ b/vendor/MDBC/unittest/libmariadb/view.c @@ -0,0 +1,697 @@ +/* +Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. + +The MySQL Connector/C is licensed under the terms of the GPLv2 +, like most +MySQL Connectors. There are special exceptions to the terms and +conditions of the GPLv2 as it is applied to this software, see the +FLOSS License Exception +. + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published +by the Free Software Foundation; version 2 of the License. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ +#include "my_test.h" + +static int test_view(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + int rc, i; + MYSQL_BIND my_bind[1]; + char str_data[50]; + ulong length = 0L; + my_bool is_null = 0; + const char *query= + "SELECT COUNT(*) FROM v1 WHERE SERVERNAME=?"; + + rc = mysql_query(mysql, "DROP TABLE IF EXISTS t1,t2,t3,v1"); + check_mysql_rc(rc, mysql); + + rc = mysql_query(mysql, "DROP VIEW IF EXISTS v1,t1,t2,t3"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql,"CREATE TABLE t1 (" + " SERVERGRP varchar(20) NOT NULL default '', " + " DBINSTANCE varchar(20) NOT NULL default '', " + " PRIMARY KEY (SERVERGRP)) " + " CHARSET=latin1 collate=latin1_bin"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql,"CREATE TABLE t2 (" + " SERVERNAME varchar(20) NOT NULL, " + " SERVERGRP varchar(20) NOT NULL, " + " PRIMARY KEY (SERVERNAME)) " + " CHARSET=latin1 COLLATE latin1_bin"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, + "CREATE TABLE t3 (" + " SERVERGRP varchar(20) BINARY NOT NULL, " + " TABNAME varchar(30) NOT NULL, MAPSTATE char(1) NOT NULL, " + " ACTSTATE char(1) NOT NULL , " + " LOCAL_NAME varchar(30) NOT NULL, " + " CHG_DATE varchar(8) NOT NULL default '00000000', " + " CHG_TIME varchar(6) NOT NULL default '000000', " + " MXUSER varchar(12) NOT NULL default '', " + " PRIMARY KEY (SERVERGRP, TABNAME, MAPSTATE, ACTSTATE, " + " LOCAL_NAME)) CHARSET=latin1 COLLATE latin1_bin"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql,"CREATE VIEW v1 AS select sql_no_cache" + " T0001.SERVERNAME AS SERVERNAME, T0003.TABNAME AS" + " TABNAME,T0003.LOCAL_NAME AS LOCAL_NAME,T0002.DBINSTANCE AS" + " DBINSTANCE from t2 T0001 join t1 T0002 join t3 T0003 where" + " ((T0002.SERVERGRP = T0001.SERVERGRP) and" + " (T0002.SERVERGRP = T0003.SERVERGRP)" + " and (T0003.MAPSTATE = _latin1'A') and" + " (T0003.ACTSTATE = _latin1' '))"); + check_mysql_rc(rc, mysql); + + stmt= mysql_stmt_init(mysql); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + strcpy(str_data, "TEST"); + memset(my_bind, '\0', sizeof(MYSQL_BIND)); + my_bind[0].buffer_type= MYSQL_TYPE_STRING; + my_bind[0].buffer= (char *)&str_data; + my_bind[0].buffer_length= 50; + my_bind[0].length= &length; + length= 4; + my_bind[0].is_null= &is_null; + rc= mysql_stmt_bind_param(stmt, my_bind); + check_stmt_rc(rc, stmt); + + for (i= 0; i < 3; i++) + { + int rowcount= 0; + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + while (mysql_stmt_fetch(stmt) != MYSQL_NO_DATA) + rowcount++; + FAIL_IF(rowcount != 1, "Expected 1 row"); + } + mysql_stmt_close(stmt); + + rc= mysql_query(mysql, "DROP TABLE t1,t2,t3"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "DROP VIEW v1"); + check_mysql_rc(rc, mysql); + + return OK; +} + + +static int test_view_where(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + int rc, i; + const char *query= + "select v1.c,v2.c from v1, v2"; + + rc = mysql_query(mysql, "DROP TABLE IF EXISTS t1,v1,v2"); + check_mysql_rc(rc, mysql); + + rc = mysql_query(mysql, "DROP VIEW IF EXISTS v1,v2,t1"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql,"CREATE TABLE t1 (a int, b int)"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql,"insert into t1 values (1,2), (1,3), (2,4), (2,5), (3,10)"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql,"create view v1 (c) as select b from t1 where a<3"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql,"create view v2 (c) as select b from t1 where a>=3"); + check_mysql_rc(rc, mysql); + + stmt= mysql_stmt_init(mysql); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + for (i= 0; i < 3; i++) + { + int rowcount= 0; + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + while (mysql_stmt_fetch(stmt) != MYSQL_NO_DATA) + rowcount++; + FAIL_UNLESS(4 == rowcount, "Expected 4 rows"); + } + mysql_stmt_close(stmt); + + rc= mysql_query(mysql, "DROP TABLE t1"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "DROP VIEW v1, v2"); + check_mysql_rc(rc, mysql); + + return OK; +} + + +static int test_view_2where(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + int rc, i; + MYSQL_BIND my_bind[8]; + char params[8][100]; + ulong length[8]; + const char *query= + "select relid, report, handle, log_group, username, variant, type, " + "version, erfdat, erftime, erfname, aedat, aetime, aename, dependvars, " + "inactive from V_LTDX where mandt = ? and relid = ? and report = ? and " + "handle = ? and log_group = ? and username in ( ? , ? ) and type = ?"; + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS LTDX"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "DROP VIEW IF EXISTS V_LTDX"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, + "CREATE TABLE LTDX (MANDT char(3) NOT NULL default '000', " + " RELID char(2) NOT NULL, REPORT varchar(40) NOT NULL," + " HANDLE varchar(4) NOT NULL, LOG_GROUP varchar(4) NOT NULL," + " USERNAME varchar(12) NOT NULL," + " VARIANT varchar(12) NOT NULL," + " TYPE char(1) NOT NULL, SRTF2 int(11) NOT NULL," + " VERSION varchar(6) NOT NULL default '000000'," + " ERFDAT varchar(8) NOT NULL default '00000000'," + " ERFTIME varchar(6) NOT NULL default '000000'," + " ERFNAME varchar(12) NOT NULL," + " AEDAT varchar(8) NOT NULL default '00000000'," + " AETIME varchar(6) NOT NULL default '000000'," + " AENAME varchar(12) NOT NULL," + " DEPENDVARS varchar(10) NOT NULL," + " INACTIVE char(1) NOT NULL, CLUSTR smallint(6) NOT NULL," + " CLUSTD blob," + " PRIMARY KEY (MANDT, RELID, REPORT, HANDLE, LOG_GROUP, " + "USERNAME, VARIANT, TYPE, SRTF2))" + " CHARSET=latin1 COLLATE latin1_bin"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, + "CREATE VIEW V_LTDX AS select T0001.MANDT AS " + " MANDT,T0001.RELID AS RELID,T0001.REPORT AS " + " REPORT,T0001.HANDLE AS HANDLE,T0001.LOG_GROUP AS " + " LOG_GROUP,T0001.USERNAME AS USERNAME,T0001.VARIANT AS " + " VARIANT,T0001.TYPE AS TYPE,T0001.VERSION AS " + " VERSION,T0001.ERFDAT AS ERFDAT,T0001.ERFTIME AS " + " ERFTIME,T0001.ERFNAME AS ERFNAME,T0001.AEDAT AS " + " AEDAT,T0001.AETIME AS AETIME,T0001.AENAME AS " + " AENAME,T0001.DEPENDVARS AS DEPENDVARS,T0001.INACTIVE AS " + " INACTIVE from LTDX T0001 where (T0001.SRTF2 = 0)"); + check_mysql_rc(rc, mysql); + memset(my_bind, '\0', sizeof(MYSQL_BIND)); + for (i=0; i < 8; i++) { + strcpy(params[i], "1"); + my_bind[i].buffer_type = MYSQL_TYPE_VAR_STRING; + my_bind[i].buffer = (char *)¶ms[i]; + my_bind[i].buffer_length = 1; + my_bind[i].is_null = 0; + length[i] = 1; + my_bind[i].length = &length[i]; + } + stmt= mysql_stmt_init(mysql); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_bind_param(stmt, my_bind); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_fetch(stmt); + FAIL_UNLESS(MYSQL_NO_DATA == rc, "Expected 0 rows"); + + mysql_stmt_close(stmt); + + rc= mysql_query(mysql, "DROP VIEW V_LTDX"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "DROP TABLE LTDX"); + check_mysql_rc(rc, mysql); + + return OK; +} + + +static int test_view_star(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + int rc, i; + MYSQL_BIND my_bind[8]; + char params[8][100]; + ulong length[8]; + const char *query= "SELECT * FROM vt1 WHERE a IN (?,?)"; + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1, vt1"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "DROP VIEW IF EXISTS t1, vt1"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "CREATE TABLE t1 (a int)"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "CREATE VIEW vt1 AS SELECT a FROM t1"); + check_mysql_rc(rc, mysql); + memset(my_bind, '\0', sizeof(MYSQL_BIND)); + for (i= 0; i < 2; i++) { + sprintf((char *)¶ms[i], "%d", i); + my_bind[i].buffer_type = MYSQL_TYPE_VAR_STRING; + my_bind[i].buffer = (char *)¶ms[i]; + my_bind[i].buffer_length = 100; + my_bind[i].is_null = 0; + my_bind[i].length = &length[i]; + length[i] = 1; + } + + stmt= mysql_stmt_init(mysql); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_bind_param(stmt, my_bind); + check_stmt_rc(rc, stmt); + + for (i= 0; i < 3; i++) + { + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_fetch(stmt); + FAIL_UNLESS(MYSQL_NO_DATA == rc, "Expected 0 rows"); + } + + mysql_stmt_close(stmt); + + rc= mysql_query(mysql, "DROP TABLE t1"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "DROP VIEW vt1"); + check_mysql_rc(rc, mysql); + + return OK; +} + + +static int test_view_insert(MYSQL *mysql) +{ + MYSQL_STMT *insert_stmt, *select_stmt; + int rc, i; + MYSQL_BIND my_bind[1]; + int my_val = 0; + ulong my_length = 0L; + my_bool my_null = 0; + const char *query= + "insert into v1 values (?)"; + + rc = mysql_query(mysql, "DROP TABLE IF EXISTS t1,v1"); + check_mysql_rc(rc, mysql); + rc = mysql_query(mysql, "DROP VIEW IF EXISTS t1,v1"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql,"create table t1 (a int, primary key (a))"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "create view v1 as select a from t1 where a>=1"); + check_mysql_rc(rc, mysql); + + insert_stmt= mysql_stmt_init(mysql); + rc= mysql_stmt_prepare(insert_stmt, SL(query)); + check_stmt_rc(rc, insert_stmt); + query= "select * from t1"; + select_stmt= mysql_stmt_init(mysql); + rc= mysql_stmt_prepare(select_stmt, SL(query)); + check_stmt_rc(rc, select_stmt); + + memset(my_bind, '\0', sizeof(MYSQL_BIND)); + my_bind[0].buffer_type = MYSQL_TYPE_LONG; + my_bind[0].buffer = (char *)&my_val; + my_bind[0].length = &my_length; + my_bind[0].is_null = &my_null; + rc= mysql_stmt_bind_param(insert_stmt, my_bind); + check_stmt_rc(rc, select_stmt); + + for (i= 0; i < 3; i++) + { + int rowcount= 0; + my_val= i; + + rc= mysql_stmt_execute(insert_stmt); + check_stmt_rc(rc, insert_stmt);; + + rc= mysql_stmt_execute(select_stmt); + check_stmt_rc(rc, select_stmt);; + while (mysql_stmt_fetch(select_stmt) != MYSQL_NO_DATA) + rowcount++; + FAIL_UNLESS((i+1) == rowcount, "rowcount != i+1"); + } + mysql_stmt_close(insert_stmt); + mysql_stmt_close(select_stmt); + + rc= mysql_query(mysql, "DROP VIEW v1"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "DROP TABLE t1"); + check_mysql_rc(rc, mysql); + + return OK; +} + + +static int test_left_join_view(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + int rc, i; + const char *query= + "select t1.a, v1.x from t1 left join v1 on (t1.a= v1.x);"; + + rc = mysql_query(mysql, "DROP TABLE IF EXISTS t1,v1"); + check_mysql_rc(rc, mysql); + + rc = mysql_query(mysql, "DROP VIEW IF EXISTS v1,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), (3)"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql,"create view v1 (x) as select a from t1 where a > 1"); + check_mysql_rc(rc, mysql); + stmt= mysql_stmt_init(mysql); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + + for (i= 0; i < 3; i++) + { + int rowcount= 0; + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + while (mysql_stmt_fetch(stmt) != MYSQL_NO_DATA) + rowcount++; + FAIL_UNLESS(3 == rowcount, "Expected 3 rows"); + } + mysql_stmt_close(stmt); + + rc= mysql_query(mysql, "DROP VIEW v1"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "DROP TABLE t1"); + check_mysql_rc(rc, mysql); + + return OK; +} + + +static int test_view_insert_fields(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + char parm[11][1000]; + ulong l[11]; + int rc, i; + int rowcount= 0; + MYSQL_BIND my_bind[11]; + const char *query= "INSERT INTO `v1` ( `K1C4` ,`K2C4` ,`K3C4` ,`K4N4` ,`F1C4` ,`F2I4` ,`F3N5` ,`F7F8` ,`F6N4` ,`F5C8` ,`F9D8` ) VALUES( ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? )"; + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1, v1"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "DROP VIEW IF EXISTS t1, v1"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, + "CREATE TABLE t1 (K1C4 varchar(4) NOT NULL," + "K2C4 varchar(4) NOT NULL, K3C4 varchar(4) NOT NULL," + "K4N4 varchar(4) NOT NULL default '0000'," + "F1C4 varchar(4) NOT NULL, F2I4 int(11) NOT NULL," + "F3N5 varchar(5) NOT NULL default '00000'," + "F4I4 int(11) NOT NULL default '0', F5C8 varchar(8) NOT NULL," + "F6N4 varchar(4) NOT NULL default '0000'," + "F7F8 double NOT NULL default '0'," + "F8F8 double NOT NULL default '0'," + "F9D8 decimal(8,2) NOT NULL default '0.00'," + "PRIMARY KEY (K1C4,K2C4,K3C4,K4N4))"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, + "CREATE VIEW v1 AS select sql_no_cache " + " K1C4 AS K1C4, K2C4 AS K2C4, K3C4 AS K3C4, K4N4 AS K4N4, " + " F1C4 AS F1C4, F2I4 AS F2I4, F3N5 AS F3N5," + " F7F8 AS F7F8, F6N4 AS F6N4, F5C8 AS F5C8, F9D8 AS F9D8" + " from t1 T0001"); + + memset(my_bind, '\0', sizeof(my_bind)); + for (i= 0; i < 11; i++) + { + l[i]= 20; + my_bind[i].buffer_type= MYSQL_TYPE_STRING; + my_bind[i].is_null= 0; + my_bind[i].buffer= (char *)&parm[i]; + + strcpy(parm[i], "1"); + my_bind[i].buffer_length= 2; + my_bind[i].length= &l[i]; + } + stmt= mysql_stmt_init(mysql); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_bind_param(stmt, my_bind); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + mysql_stmt_close(stmt); + + query= "select * from t1"; + stmt= mysql_stmt_init(mysql); + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + while (mysql_stmt_fetch(stmt) != MYSQL_NO_DATA) + rowcount++; + FAIL_UNLESS(1 == rowcount, "Expected 1 row"); + + mysql_stmt_close(stmt); + rc= mysql_query(mysql, "DROP VIEW v1"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "DROP TABLE t1"); + check_mysql_rc(rc, mysql); + + return OK; +} + +static int test_view_sp_list_fields(MYSQL *mysql) +{ + int rc; + MYSQL_RES *res; + MYSQL_ROW row; + int skip; + + /* skip this test if bin_log is on */ + rc= mysql_query(mysql, "SHOW VARIABLES LIKE 'log_bin'"); + check_mysql_rc(rc, mysql); + res= mysql_store_result(mysql); + FAIL_IF(!res, "empty/invalid resultset"); + row = mysql_fetch_row(res); + skip= (strcmp((char *)row[1], "ON") == 0); + mysql_free_result(res); + + if (skip) { + diag("bin_log is ON -> skip"); + return SKIP; + } + + rc= mysql_query(mysql, "DROP FUNCTION IF EXISTS f1"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "DROP TABLE IF EXISTS v1, t1, t2"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "DROP VIEW IF EXISTS v1, t1, t2"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "create function f1 () returns int return 5"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "create table t1 (s1 char,s2 char)"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "create table t2 (s1 int);"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "create view v1 as select s2,sum(s1) - \ +count(s2) as vx from t1 group by s2 having sum(s1) - count(s2) < (select f1() \ +from t2);"); + check_mysql_rc(rc, mysql); + res= mysql_list_fields(mysql, "v1", NullS); + FAIL_UNLESS(res != 0 && mysql_num_fields(res) != 0, "0 Fields"); + rc= mysql_query(mysql, "DROP FUNCTION f1"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "DROP VIEW v1"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "DROP TABLE t1, t2"); + mysql_free_result(res); + check_mysql_rc(rc, mysql); + + return OK; +} + +static int test_bug19671(MYSQL *mysql) +{ + MYSQL_RES *result; + MYSQL_FIELD *field; + int rc, retcode= OK; + + + rc= mysql_query(mysql, "set sql_mode=''"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "drop table if exists t1"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "drop view if exists v1"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "create table t1(f1 int)"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "create view v1 as select va.* from t1 va"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "SELECT * FROM v1"); + check_mysql_rc(rc, mysql); + + result= mysql_store_result(mysql); + FAIL_IF(!result, "Invalid result set"); + + field= mysql_fetch_field(result); + FAIL_IF(!field, "Can't fetch field"); + + if (strcmp(field->table, "v1") != 0) { + diag("Wrong value '%s' for field_table. Expected 'v1'. (%s: %d)", field->table, __FILE__, __LINE__); + retcode= FAIL; + } + + mysql_free_result(result); + + rc= mysql_query(mysql, "drop view v1"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "drop table t1"); + check_mysql_rc(rc, mysql); + + return retcode; +} + +/* + Bug#11111: fetch from view returns wrong data +*/ + +static int test_bug11111(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + MYSQL_BIND my_bind[2]; + char buf[2][20]; + ulong len[2]; + int i; + int rc; + const char *query= "SELECT DISTINCT f1,ff2 FROM v1"; + + rc= mysql_query(mysql, "drop table if exists t1, t2, v1"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "drop view if exists t1, t2, v1"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "create table t1 (f1 int, f2 int)"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "create table t2 (ff1 int, ff2 int)"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "create view v1 as select * from t1, t2 where f1=ff1"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "insert into t1 values (1,1), (2,2), (3,3)"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "insert into t2 values (1,1), (2,2), (3,3)"); + check_mysql_rc(rc, mysql); + + stmt= mysql_stmt_init(mysql); + + rc= mysql_stmt_prepare(stmt, SL(query)); + check_stmt_rc(rc, stmt); + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + memset(my_bind, '\0', sizeof(my_bind)); + for (i=0; i < 2; i++) + { + my_bind[i].buffer_type= MYSQL_TYPE_STRING; + my_bind[i].buffer= (uchar* *)&buf[i]; + my_bind[i].buffer_length= 20; + my_bind[i].length= &len[i]; + } + + rc= mysql_stmt_bind_result(stmt, my_bind); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_fetch(stmt); + check_stmt_rc(rc, stmt); + FAIL_UNLESS(!strcmp(buf[1],"1"), "buf[1] != '1'"); + mysql_stmt_close(stmt); + rc= mysql_query(mysql, "drop view v1"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "drop table t1, t2"); + check_mysql_rc(rc, mysql); + + return OK; +} + +/** + Bug#29306 Truncated data in MS Access with decimal (3,1) columns in a VIEW +*/ + +static int test_bug29306(MYSQL *mysql) +{ + MYSQL_FIELD *field; + int rc; + MYSQL_RES *res; + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS tab17557"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "DROP VIEW IF EXISTS view17557"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "CREATE TABLE tab17557 (dd decimal (3,1))"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "CREATE VIEW view17557 as SELECT dd FROM tab17557"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "INSERT INTO tab17557 VALUES (7.6)"); + check_mysql_rc(rc, mysql); + + /* Checking the view */ + res= mysql_list_fields(mysql, "view17557", NULL); + while ((field= mysql_fetch_field(res))) + { + FAIL_UNLESS(field->decimals == 1, "field->decimals != 1"); + } + mysql_free_result(res); + + rc= mysql_query(mysql, "DROP TABLE tab17557"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "DROP VIEW view17557"); + check_mysql_rc(rc, mysql); + + return OK; +} + + +struct my_tests_st my_tests[] = { + {"test_view", test_view, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_view_where", test_view_where, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_view_2where", test_view_2where, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_view_star", test_view_star, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_view_insert", test_view_insert, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_left_join_view", test_left_join_view, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_view_insert_fields", test_view_insert_fields, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_view_sp_list_fields", test_view_sp_list_fields,TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_bug19671", test_bug19671, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_bug29306", test_bug29306, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {"test_bug11111", test_bug11111, TEST_CONNECTION_DEFAULT, 0, NULL , NULL}, + {NULL, NULL, 0, 0, NULL, NULL} +}; + +int main(int argc, char **argv) +{ + if (argc > 1) + get_options(argc, argv); + + get_envvars(); + + run_tests(my_tests); + + return(exit_status()); +} diff --git a/vendor/MDBC/unittest/mytap/CMakeLists.txt b/vendor/MDBC/unittest/mytap/CMakeLists.txt new file mode 100644 index 00000000..1a03d7ac --- /dev/null +++ b/vendor/MDBC/unittest/mytap/CMakeLists.txt @@ -0,0 +1,19 @@ +# Copyright (C) 2007 MySQL AB +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; version 2 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + +INCLUDE_DIRECTORIES(${CC_SOURCE_DIR}/include ${CC_SOURCE_DIR}/zlib + ${CC_BINARY_DIR}/include) +ADD_LIBRARY(cctap tap.c) diff --git a/vendor/MDBC/unittest/mytap/Doxyfile b/vendor/MDBC/unittest/mytap/Doxyfile new file mode 100644 index 00000000..1b1c82b4 --- /dev/null +++ b/vendor/MDBC/unittest/mytap/Doxyfile @@ -0,0 +1,1156 @@ +# Doxyfile 1.3.8 + +# This file describes the settings to be used by the documentation system +# doxygen (www.doxygen.org) for a project +# +# All text after a hash (#) is considered a comment and will be ignored +# The format is: +# TAG = value [value, ...] +# For lists items can also be appended using: +# TAG += value [value, ...] +# Values that contain spaces should be placed between quotes (" ") + +#--------------------------------------------------------------------------- +# Project related configuration options +#--------------------------------------------------------------------------- + +# The PROJECT_NAME tag is a single word (or a sequence of words surrounded +# by quotes) that should identify the project. + +PROJECT_NAME = + +# The PROJECT_NUMBER tag can be used to enter a project or revision number. +# This could be handy for archiving the generated documentation or +# if some version control system is used. + +PROJECT_NUMBER = + +# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) +# base path where the generated documentation will be put. +# If a relative path is entered, it will be relative to the location +# where doxygen was started. If left blank the current directory will be used. + +OUTPUT_DIRECTORY = + +# If the CREATE_SUBDIRS tag is set to YES, then doxygen will create +# 4096 sub-directories (in 2 levels) under the output directory of each output +# format and will distribute the generated files over these directories. +# Enabling this option can be useful when feeding doxygen a huge amount of source +# files, where putting all generated files in the same directory would otherwise +# cause performance problems for the file system. + +CREATE_SUBDIRS = NO + +# The OUTPUT_LANGUAGE tag is used to specify the language in which all +# documentation generated by doxygen is written. Doxygen will use this +# information to generate all constant output in the proper language. +# The default language is English, other supported languages are: +# Brazilian, Catalan, Chinese, Chinese-Traditional, Croatian, Czech, Danish, +# Dutch, Finnish, French, German, Greek, Hungarian, Italian, Japanese, +# Japanese-en (Japanese with English messages), Korean, Korean-en, Norwegian, +# Polish, Portuguese, Romanian, Russian, Serbian, Slovak, Slovene, Spanish, +# Swedish, and Ukrainian. + +OUTPUT_LANGUAGE = English + +# This tag can be used to specify the encoding used in the generated output. +# The encoding is not always determined by the language that is chosen, +# but also whether or not the output is meant for Windows or non-Windows users. +# In case there is a difference, setting the USE_WINDOWS_ENCODING tag to YES +# forces the Windows encoding (this is the default for the Windows binary), +# whereas setting the tag to NO uses a Unix-style encoding (the default for +# all platforms other than Windows). + +USE_WINDOWS_ENCODING = NO + +# If the BRIEF_MEMBER_DESC tag is set to YES (the default) Doxygen will +# include brief member descriptions after the members that are listed in +# the file and class documentation (similar to JavaDoc). +# Set to NO to disable this. + +BRIEF_MEMBER_DESC = YES + +# If the REPEAT_BRIEF tag is set to YES (the default) Doxygen will prepend +# the brief description of a member or function before the detailed description. +# Note: if both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the +# brief descriptions will be completely suppressed. + +REPEAT_BRIEF = YES + +# This tag implements a quasi-intelligent brief description abbreviator +# that is used to form the text in various listings. Each string +# in this list, if found as the leading text of the brief description, will be +# stripped from the text and the result after processing the whole list, is used +# as the annotated text. Otherwise, the brief description is used as-is. If left +# blank, the following values are used ("$name" is automatically replaced with the +# name of the entity): "The $name class" "The $name widget" "The $name file" +# "is" "provides" "specifies" "contains" "represents" "a" "an" "the" + +ABBREVIATE_BRIEF = + +# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then +# Doxygen will generate a detailed section even if there is only a brief +# description. + +ALWAYS_DETAILED_SEC = NO + +# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all inherited +# members of a class in the documentation of that class as if those members were +# ordinary class members. Constructors, destructors and assignment operators of +# the base classes will not be shown. + +INLINE_INHERITED_MEMB = NO + +# If the FULL_PATH_NAMES tag is set to YES then Doxygen will prepend the full +# path before files name in the file list and in the header files. If set +# to NO the shortest path that makes the file name unique will be used. + +FULL_PATH_NAMES = YES + +# If the FULL_PATH_NAMES tag is set to YES then the STRIP_FROM_PATH tag +# can be used to strip a user-defined part of the path. Stripping is +# only done if one of the specified strings matches the left-hand part of +# the path. The tag can be used to show relative paths in the file list. +# If left blank the directory from which doxygen is run is used as the +# path to strip. + +STRIP_FROM_PATH = + +# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of +# the path mentioned in the documentation of a class, which tells +# the reader which header file to include in order to use a class. +# If left blank only the name of the header file containing the class +# definition is used. Otherwise one should specify the include paths that +# are normally passed to the compiler using the -I flag. + +STRIP_FROM_INC_PATH = + +# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter +# (but less readable) file names. This can be useful is your file systems +# doesn't support long names like on DOS, Mac, or CD-ROM. + +SHORT_NAMES = NO + +# If the JAVADOC_AUTOBRIEF tag is set to YES then Doxygen +# will interpret the first line (until the first dot) of a JavaDoc-style +# comment as the brief description. If set to NO, the JavaDoc +# comments will behave just like the Qt-style comments (thus requiring an +# explicit @brief command for a brief description. + +JAVADOC_AUTOBRIEF = YES + +# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make Doxygen +# treat a multi-line C++ special comment block (i.e. a block of //! or /// +# comments) as a brief description. This used to be the default behaviour. +# The new default is to treat a multi-line C++ comment block as a detailed +# description. Set this tag to YES if you prefer the old behaviour instead. + +MULTILINE_CPP_IS_BRIEF = NO + +# If the DETAILS_AT_TOP tag is set to YES then Doxygen +# will output the detailed description near the top, like JavaDoc. +# If set to NO, the detailed description appears after the member +# documentation. + +DETAILS_AT_TOP = NO + +# If the INHERIT_DOCS tag is set to YES (the default) then an undocumented +# member inherits the documentation from any documented member that it +# re-implements. + +INHERIT_DOCS = YES + +# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC +# tag is set to YES, then doxygen will reuse the documentation of the first +# member in the group (if any) for the other members of the group. By default +# all members of a group must be documented explicitly. + +DISTRIBUTE_GROUP_DOC = NO + +# The TAB_SIZE tag can be used to set the number of spaces in a tab. +# Doxygen uses this value to replace tabs by spaces in code fragments. + +TAB_SIZE = 8 + +# This tag can be used to specify a number of aliases that acts +# as commands in the documentation. An alias has the form "name=value". +# For example adding "sideeffect=\par Side Effects:\n" will allow you to +# put the command \sideeffect (or @sideeffect) in the documentation, which +# will result in a user-defined paragraph with heading "Side Effects:". +# You can put \n's in the value part of an alias to insert newlines. + +ALIASES = + +# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C sources +# only. Doxygen will then generate output that is more tailored for C. +# For instance, some of the names that are used will be different. The list +# of all members will be omitted, etc. + +OPTIMIZE_OUTPUT_FOR_C = YES + +# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java sources +# only. Doxygen will then generate output that is more tailored for Java. +# For instance, namespaces will be presented as packages, qualified scopes +# will look different, etc. + +OPTIMIZE_OUTPUT_JAVA = NO + +# Set the SUBGROUPING tag to YES (the default) to allow class member groups of +# the same type (for instance a group of public functions) to be put as a +# subgroup of that type (e.g. under the Public Functions section). Set it to +# NO to prevent subgrouping. Alternatively, this can be done per class using +# the \nosubgrouping command. + +SUBGROUPING = YES + +#--------------------------------------------------------------------------- +# Build related configuration options +#--------------------------------------------------------------------------- + +# If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in +# documentation are documented, even if no documentation was available. +# Private class members and static file members will be hidden unless +# the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set to YES + +EXTRACT_ALL = YES + +# If the EXTRACT_PRIVATE tag is set to YES all private members of a class +# will be included in the documentation. + +EXTRACT_PRIVATE = YES + +# If the EXTRACT_STATIC tag is set to YES all static members of a file +# will be included in the documentation. + +EXTRACT_STATIC = YES + +# If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs) +# defined locally in source files will be included in the documentation. +# If set to NO only classes defined in header files are included. + +EXTRACT_LOCAL_CLASSES = YES + +# This flag is only useful for Objective-C code. When set to YES local +# methods, which are defined in the implementation section but not in +# the interface are included in the documentation. +# If set to NO (the default) only methods in the interface are included. + +EXTRACT_LOCAL_METHODS = NO + +# If the HIDE_UNDOC_MEMBERS tag is set to YES, Doxygen will hide all +# undocumented members of documented classes, files or namespaces. +# If set to NO (the default) these members will be included in the +# various overviews, but no documentation section is generated. +# This option has no effect if EXTRACT_ALL is enabled. + +HIDE_UNDOC_MEMBERS = NO + +# If the HIDE_UNDOC_CLASSES tag is set to YES, Doxygen will hide all +# undocumented classes that are normally visible in the class hierarchy. +# If set to NO (the default) these classes will be included in the various +# overviews. This option has no effect if EXTRACT_ALL is enabled. + +HIDE_UNDOC_CLASSES = NO + +# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, Doxygen will hide all +# friend (class|struct|union) declarations. +# If set to NO (the default) these declarations will be included in the +# documentation. + +HIDE_FRIEND_COMPOUNDS = NO + +# If the HIDE_IN_BODY_DOCS tag is set to YES, Doxygen will hide any +# documentation blocks found inside the body of a function. +# If set to NO (the default) these blocks will be appended to the +# function's detailed documentation block. + +HIDE_IN_BODY_DOCS = NO + +# The INTERNAL_DOCS tag determines if documentation +# that is typed after a \internal command is included. If the tag is set +# to NO (the default) then the documentation will be excluded. +# Set it to YES to include the internal documentation. + +INTERNAL_DOCS = NO + +# If the CASE_SENSE_NAMES tag is set to NO then Doxygen will only generate +# file names in lower-case letters. If set to YES upper-case letters are also +# allowed. This is useful if you have classes or files whose names only differ +# in case and if your file system supports case sensitive file names. Windows +# and Mac users are advised to set this option to NO. + +CASE_SENSE_NAMES = YES + +# If the HIDE_SCOPE_NAMES tag is set to NO (the default) then Doxygen +# will show members with their full class and namespace scopes in the +# documentation. If set to YES the scope will be hidden. + +HIDE_SCOPE_NAMES = NO + +# If the SHOW_INCLUDE_FILES tag is set to YES (the default) then Doxygen +# will put a list of the files that are included by a file in the documentation +# of that file. + +SHOW_INCLUDE_FILES = YES + +# If the INLINE_INFO tag is set to YES (the default) then a tag [inline] +# is inserted in the documentation for inline members. + +INLINE_INFO = YES + +# If the SORT_MEMBER_DOCS tag is set to YES (the default) then doxygen +# will sort the (detailed) documentation of file and class members +# alphabetically by member name. If set to NO the members will appear in +# declaration order. + +SORT_MEMBER_DOCS = YES + +# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the +# brief documentation of file, namespace and class members alphabetically +# by member name. If set to NO (the default) the members will appear in +# declaration order. + +SORT_BRIEF_DOCS = NO + +# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be +# sorted by fully-qualified names, including namespaces. If set to +# NO (the default), the class list will be sorted only by class name, +# not including the namespace part. +# Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES. +# Note: This option applies only to the class list, not to the +# alphabetical list. + +SORT_BY_SCOPE_NAME = NO + +# The GENERATE_TODOLIST tag can be used to enable (YES) or +# disable (NO) the todo list. This list is created by putting \todo +# commands in the documentation. + +GENERATE_TODOLIST = YES + +# The GENERATE_TESTLIST tag can be used to enable (YES) or +# disable (NO) the test list. This list is created by putting \test +# commands in the documentation. + +GENERATE_TESTLIST = YES + +# The GENERATE_BUGLIST tag can be used to enable (YES) or +# disable (NO) the bug list. This list is created by putting \bug +# commands in the documentation. + +GENERATE_BUGLIST = YES + +# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or +# disable (NO) the deprecated list. This list is created by putting +# \deprecated commands in the documentation. + +GENERATE_DEPRECATEDLIST= YES + +# The ENABLED_SECTIONS tag can be used to enable conditional +# documentation sections, marked by \if sectionname ... \endif. + +ENABLED_SECTIONS = + +# The MAX_INITIALIZER_LINES tag determines the maximum number of lines +# the initial value of a variable or define consists of for it to appear in +# the documentation. If the initializer consists of more lines than specified +# here it will be hidden. Use a value of 0 to hide initializers completely. +# The appearance of the initializer of individual variables and defines in the +# documentation can be controlled using \showinitializer or \hideinitializer +# command in the documentation regardless of this setting. + +MAX_INITIALIZER_LINES = 30 + +# Set the SHOW_USED_FILES tag to NO to disable the list of files generated +# at the bottom of the documentation of classes and structs. If set to YES the +# list will mention the files that were used to generate the documentation. + +SHOW_USED_FILES = YES + +#--------------------------------------------------------------------------- +# configuration options related to warning and progress messages +#--------------------------------------------------------------------------- + +# The QUIET tag can be used to turn on/off the messages that are generated +# by doxygen. Possible values are YES and NO. If left blank NO is used. + +QUIET = NO + +# The WARNINGS tag can be used to turn on/off the warning messages that are +# generated by doxygen. Possible values are YES and NO. If left blank +# NO is used. + +WARNINGS = YES + +# If WARN_IF_UNDOCUMENTED is set to YES, then doxygen will generate warnings +# for undocumented members. If EXTRACT_ALL is set to YES then this flag will +# automatically be disabled. + +WARN_IF_UNDOCUMENTED = YES + +# If WARN_IF_DOC_ERROR is set to YES, doxygen will generate warnings for +# potential errors in the documentation, such as not documenting some +# parameters in a documented function, or documenting parameters that +# don't exist or using markup commands wrongly. + +WARN_IF_DOC_ERROR = YES + +# The WARN_FORMAT tag determines the format of the warning messages that +# doxygen can produce. The string should contain the $file, $line, and $text +# tags, which will be replaced by the file and line number from which the +# warning originated and the warning text. + +WARN_FORMAT = "$file:$line: $text" + +# The WARN_LOGFILE tag can be used to specify a file to which warning +# and error messages should be written. If left blank the output is written +# to stderr. + +WARN_LOGFILE = + +#--------------------------------------------------------------------------- +# configuration options related to the input files +#--------------------------------------------------------------------------- + +# The INPUT tag can be used to specify the files and/or directories +# that contain documented source files. You may enter file names like +# "myfile.cpp" or directories like "/usr/src/myproject". Separate the +# files or directories with spaces. + +INPUT = + +# If the value of the INPUT tag contains directories, you can use the +# FILE_PATTERNS tag to specify one or more wildcard pattern (like +# *.cpp and *.h) to filter out the source-files in the directories. If +# left blank the following patterns are tested: *.c *.cc *.cxx *.cpp +# *.c++ *.java *.ii *.ixx *.ipp *.i++ *.inl *.h *.hh *.hxx *.hpp *.h++ +# *.idl *.odl *.cs *.php *.php3 *.inc *.m *.mm + +FILE_PATTERNS = + +# The RECURSIVE tag can be used to turn specify whether or not +# subdirectories should be searched for input files as well. Possible +# values are YES and NO. If left blank NO is used. + +RECURSIVE = NO + +# The EXCLUDE tag can be used to specify files and/or directories that +# should excluded from the INPUT source files. This way you can easily +# exclude a subdirectory from a directory tree whose root is specified +# with the INPUT tag. + +EXCLUDE = + +# The EXCLUDE_SYMLINKS tag can be used select whether or not files or +# directories that are symbolic links (a Unix filesystem feature) are +# excluded from the input. + +EXCLUDE_SYMLINKS = NO + +# If the value of the INPUT tag contains directories, you can use the +# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to +# exclude certain files from those directories. + +EXCLUDE_PATTERNS = + +# The EXAMPLE_PATH tag can be used to specify one or more files or +# directories that contain example code fragments that are included (see +# the \include command). + +EXAMPLE_PATH = e + +# If the value of the EXAMPLE_PATH tag contains directories, you can use the +# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp +# and *.h) to filter out the source-files in the directories. If left +# blank all files are included. + +EXAMPLE_PATTERNS = *.c + +# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be +# searched for input files to be used with the \include or \dontinclude +# commands irrespective of the value of the RECURSIVE tag. +# Possible values are YES and NO. If left blank NO is used. + +EXAMPLE_RECURSIVE = NO + +# The IMAGE_PATH tag can be used to specify one or more files or +# directories that contain image that are included in the documentation (see +# the \image command). + +IMAGE_PATH = + +# The INPUT_FILTER tag can be used to specify a program that doxygen should +# invoke to filter for each input file. Doxygen will invoke the filter program +# by executing (via popen()) the command , where +# is the value of the INPUT_FILTER tag, and is the name of an +# input file. Doxygen will then use the output that the filter program writes +# to standard output. If FILTER_PATTERNS is specified, this tag will be +# ignored. + +INPUT_FILTER = + +# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern +# basis. Doxygen will compare the file name with each pattern and apply the +# filter if there is a match. The filters are a list of the form: +# pattern=filter (like *.cpp=my_cpp_filter). See INPUT_FILTER for further +# info on how filters are used. If FILTER_PATTERNS is empty, INPUT_FILTER +# is applied to all files. + +FILTER_PATTERNS = + +# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using +# INPUT_FILTER) will be used to filter the input files when producing source +# files to browse (i.e. when SOURCE_BROWSER is set to YES). + +FILTER_SOURCE_FILES = NO + +#--------------------------------------------------------------------------- +# configuration options related to source browsing +#--------------------------------------------------------------------------- + +# If the SOURCE_BROWSER tag is set to YES then a list of source files will +# be generated. Documented entities will be cross-referenced with these sources. +# Note: To get rid of all source code in the generated output, make sure also +# VERBATIM_HEADERS is set to NO. + +SOURCE_BROWSER = NO + +# Setting the INLINE_SOURCES tag to YES will include the body +# of functions and classes directly in the documentation. + +INLINE_SOURCES = NO + +# Setting the STRIP_CODE_COMMENTS tag to YES (the default) will instruct +# doxygen to hide any special comment blocks from generated source code +# fragments. Normal C and C++ comments will always remain visible. + +STRIP_CODE_COMMENTS = YES + +# If the REFERENCED_BY_RELATION tag is set to YES (the default) +# then for each documented function all documented +# functions referencing it will be listed. + +REFERENCED_BY_RELATION = YES + +# If the REFERENCES_RELATION tag is set to YES (the default) +# then for each documented function all documented entities +# called/used by that function will be listed. + +REFERENCES_RELATION = YES + +# If the VERBATIM_HEADERS tag is set to YES (the default) then Doxygen +# will generate a verbatim copy of the header file for each class for +# which an include is specified. Set to NO to disable this. + +VERBATIM_HEADERS = YES + +#--------------------------------------------------------------------------- +# configuration options related to the alphabetical class index +#--------------------------------------------------------------------------- + +# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index +# of all compounds will be generated. Enable this if the project +# contains a lot of classes, structs, unions or interfaces. + +ALPHABETICAL_INDEX = NO + +# If the alphabetical index is enabled (see ALPHABETICAL_INDEX) then +# the COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns +# in which this list will be split (can be a number in the range [1..20]) + +COLS_IN_ALPHA_INDEX = 5 + +# In case all classes in a project start with a common prefix, all +# classes will be put under the same header in the alphabetical index. +# The IGNORE_PREFIX tag can be used to specify one or more prefixes that +# should be ignored while generating the index headers. + +IGNORE_PREFIX = + +#--------------------------------------------------------------------------- +# configuration options related to the HTML output +#--------------------------------------------------------------------------- + +# If the GENERATE_HTML tag is set to YES (the default) Doxygen will +# generate HTML output. + +GENERATE_HTML = YES + +# The HTML_OUTPUT tag is used to specify where the HTML docs will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `html' will be used as the default path. + +HTML_OUTPUT = html + +# The HTML_FILE_EXTENSION tag can be used to specify the file extension for +# each generated HTML page (for example: .htm,.php,.asp). If it is left blank +# doxygen will generate files with .html extension. + +HTML_FILE_EXTENSION = .html + +# The HTML_HEADER tag can be used to specify a personal HTML header for +# each generated HTML page. If it is left blank doxygen will generate a +# standard header. + +HTML_HEADER = + +# The HTML_FOOTER tag can be used to specify a personal HTML footer for +# each generated HTML page. If it is left blank doxygen will generate a +# standard footer. + +HTML_FOOTER = + +# The HTML_STYLESHEET tag can be used to specify a user-defined cascading +# style sheet that is used by each HTML page. It can be used to +# fine-tune the look of the HTML output. If the tag is left blank doxygen +# will generate a default style sheet. Note that doxygen will try to copy +# the style sheet file to the HTML output directory, so don't put your own +# stylesheet in the HTML output directory as well, or it will be erased! + +HTML_STYLESHEET = + +# If the HTML_ALIGN_MEMBERS tag is set to YES, the members of classes, +# files or namespaces will be aligned in HTML using tables. If set to +# NO a bullet list will be used. + +HTML_ALIGN_MEMBERS = YES + +# If the GENERATE_HTMLHELP tag is set to YES, additional index files +# will be generated that can be used as input for tools like the +# Microsoft HTML help workshop to generate a compressed HTML help file (.chm) +# of the generated HTML documentation. + +GENERATE_HTMLHELP = NO + +# If the GENERATE_HTMLHELP tag is set to YES, the CHM_FILE tag can +# be used to specify the file name of the resulting .chm file. You +# can add a path in front of the file if the result should not be +# written to the html output directory. + +CHM_FILE = + +# If the GENERATE_HTMLHELP tag is set to YES, the HHC_LOCATION tag can +# be used to specify the location (absolute path including file name) of +# the HTML help compiler (hhc.exe). If non-empty doxygen will try to run +# the HTML help compiler on the generated index.hhp. + +HHC_LOCATION = + +# If the GENERATE_HTMLHELP tag is set to YES, the GENERATE_CHI flag +# controls if a separate .chi index file is generated (YES) or that +# it should be included in the master .chm file (NO). + +GENERATE_CHI = NO + +# If the GENERATE_HTMLHELP tag is set to YES, the BINARY_TOC flag +# controls whether a binary table of contents is generated (YES) or a +# normal table of contents (NO) in the .chm file. + +BINARY_TOC = NO + +# The TOC_EXPAND flag can be set to YES to add extra items for group members +# to the contents of the HTML help documentation and to the tree view. + +TOC_EXPAND = NO + +# The DISABLE_INDEX tag can be used to turn on/off the condensed index at +# top of each HTML page. The value NO (the default) enables the index and +# the value YES disables it. + +DISABLE_INDEX = NO + +# This tag can be used to set the number of enum values (range [1..20]) +# that doxygen will group on one line in the generated HTML documentation. + +ENUM_VALUES_PER_LINE = 4 + +# If the GENERATE_TREEVIEW tag is set to YES, a side panel will be +# generated containing a tree-like index structure (just like the one that +# is generated for HTML Help). For this to work a browser that supports +# JavaScript, DHTML, CSS and frames is required (for instance Mozilla 1.0+, +# Netscape 6.0+, Internet explorer 5.0+, or Konqueror). Windows users are +# probably better off using the HTML help feature. + +GENERATE_TREEVIEW = NO + +# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be +# used to set the initial width (in pixels) of the frame in which the tree +# is shown. + +TREEVIEW_WIDTH = 250 + +#--------------------------------------------------------------------------- +# configuration options related to the LaTeX output +#--------------------------------------------------------------------------- + +# If the GENERATE_LATEX tag is set to YES (the default) Doxygen will +# generate Latex output. + +GENERATE_LATEX = NO + +# The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `latex' will be used as the default path. + +LATEX_OUTPUT = latex + +# The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be +# invoked. If left blank `latex' will be used as the default command name. + +LATEX_CMD_NAME = latex + +# The MAKEINDEX_CMD_NAME tag can be used to specify the command name to +# generate index for LaTeX. If left blank `makeindex' will be used as the +# default command name. + +MAKEINDEX_CMD_NAME = makeindex + +# If the COMPACT_LATEX tag is set to YES Doxygen generates more compact +# LaTeX documents. This may be useful for small projects and may help to +# save some trees in general. + +COMPACT_LATEX = NO + +# The PAPER_TYPE tag can be used to set the paper type that is used +# by the printer. Possible values are: a4, a4wide, letter, legal and +# executive. If left blank a4wide will be used. + +PAPER_TYPE = a4wide + +# The EXTRA_PACKAGES tag can be to specify one or more names of LaTeX +# packages that should be included in the LaTeX output. + +EXTRA_PACKAGES = + +# The LATEX_HEADER tag can be used to specify a personal LaTeX header for +# the generated latex document. The header should contain everything until +# the first chapter. If it is left blank doxygen will generate a +# standard header. Notice: only use this tag if you know what you are doing! + +LATEX_HEADER = + +# If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated +# is prepared for conversion to pdf (using ps2pdf). The pdf file will +# contain links (just like the HTML output) instead of page references +# This makes the output suitable for online browsing using a pdf viewer. + +PDF_HYPERLINKS = NO + +# If the USE_PDFLATEX tag is set to YES, pdflatex will be used instead of +# plain latex in the generated Makefile. Set this option to YES to get a +# higher quality PDF documentation. + +USE_PDFLATEX = NO + +# If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \\batchmode. +# command to the generated LaTeX files. This will instruct LaTeX to keep +# running if errors occur, instead of asking the user for help. +# This option is also used when generating formulas in HTML. + +LATEX_BATCHMODE = NO + +# If LATEX_HIDE_INDICES is set to YES then doxygen will not +# include the index chapters (such as File Index, Compound Index, etc.) +# in the output. + +LATEX_HIDE_INDICES = NO + +#--------------------------------------------------------------------------- +# configuration options related to the RTF output +#--------------------------------------------------------------------------- + +# If the GENERATE_RTF tag is set to YES Doxygen will generate RTF output +# The RTF output is optimized for Word 97 and may not look very pretty with +# other RTF readers or editors. + +GENERATE_RTF = NO + +# The RTF_OUTPUT tag is used to specify where the RTF docs will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `rtf' will be used as the default path. + +RTF_OUTPUT = rtf + +# If the COMPACT_RTF tag is set to YES Doxygen generates more compact +# RTF documents. This may be useful for small projects and may help to +# save some trees in general. + +COMPACT_RTF = NO + +# If the RTF_HYPERLINKS tag is set to YES, the RTF that is generated +# will contain hyperlink fields. The RTF file will +# contain links (just like the HTML output) instead of page references. +# This makes the output suitable for online browsing using WORD or other +# programs which support those fields. +# Note: wordpad (write) and others do not support links. + +RTF_HYPERLINKS = NO + +# Load stylesheet definitions from file. Syntax is similar to doxygen's +# config file, i.e. a series of assignments. You only have to provide +# replacements, missing definitions are set to their default value. + +RTF_STYLESHEET_FILE = + +# Set optional variables used in the generation of an rtf document. +# Syntax is similar to doxygen's config file. + +RTF_EXTENSIONS_FILE = + +#--------------------------------------------------------------------------- +# configuration options related to the man page output +#--------------------------------------------------------------------------- + +# If the GENERATE_MAN tag is set to YES (the default) Doxygen will +# generate man pages + +GENERATE_MAN = NO + +# The MAN_OUTPUT tag is used to specify where the man pages will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `man' will be used as the default path. + +MAN_OUTPUT = man + +# The MAN_EXTENSION tag determines the extension that is added to +# the generated man pages (default is the subroutine's section .3) + +MAN_EXTENSION = .3 + +# If the MAN_LINKS tag is set to YES and Doxygen generates man output, +# then it will generate one additional man file for each entity +# documented in the real man page(s). These additional files +# only source the real man page, but without them the man command +# would be unable to find the correct page. The default is NO. + +MAN_LINKS = NO + +#--------------------------------------------------------------------------- +# configuration options related to the XML output +#--------------------------------------------------------------------------- + +# If the GENERATE_XML tag is set to YES Doxygen will +# generate an XML file that captures the structure of +# the code including all documentation. + +GENERATE_XML = NO + +# The XML_OUTPUT tag is used to specify where the XML pages will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `xml' will be used as the default path. + +XML_OUTPUT = xml + +# The XML_SCHEMA tag can be used to specify an XML schema, +# which can be used by a validating XML parser to check the +# syntax of the XML files. + +XML_SCHEMA = + +# The XML_DTD tag can be used to specify an XML DTD, +# which can be used by a validating XML parser to check the +# syntax of the XML files. + +XML_DTD = + +# If the XML_PROGRAMLISTING tag is set to YES Doxygen will +# dump the program listings (including syntax highlighting +# and cross-referencing information) to the XML output. Note that +# enabling this will significantly increase the size of the XML output. + +XML_PROGRAMLISTING = YES + +#--------------------------------------------------------------------------- +# configuration options for the AutoGen Definitions output +#--------------------------------------------------------------------------- + +# If the GENERATE_AUTOGEN_DEF tag is set to YES Doxygen will +# generate an AutoGen Definitions (see autogen.sf.net) file +# that captures the structure of the code including all +# documentation. Note that this feature is still experimental +# and incomplete at the moment. + +GENERATE_AUTOGEN_DEF = NO + +#--------------------------------------------------------------------------- +# configuration options related to the Perl module output +#--------------------------------------------------------------------------- + +# If the GENERATE_PERLMOD tag is set to YES Doxygen will +# generate a Perl module file that captures the structure of +# the code including all documentation. Note that this +# feature is still experimental and incomplete at the +# moment. + +GENERATE_PERLMOD = NO + +# If the PERLMOD_LATEX tag is set to YES Doxygen will generate +# the necessary Makefile rules, Perl scripts and LaTeX code to be able +# to generate PDF and DVI output from the Perl module output. + +PERLMOD_LATEX = NO + +# If the PERLMOD_PRETTY tag is set to YES the Perl module output will be +# nicely formatted so it can be parsed by a human reader. This is useful +# if you want to understand what is going on. On the other hand, if this +# tag is set to NO the size of the Perl module output will be much smaller +# and Perl will parse it just the same. + +PERLMOD_PRETTY = YES + +# The names of the make variables in the generated doxyrules.make file +# are prefixed with the string contained in PERLMOD_MAKEVAR_PREFIX. +# This is useful so different doxyrules.make files included by the same +# Makefile don't overwrite each other's variables. + +PERLMOD_MAKEVAR_PREFIX = + +#--------------------------------------------------------------------------- +# Configuration options related to the preprocessor +#--------------------------------------------------------------------------- + +# If the ENABLE_PREPROCESSING tag is set to YES (the default) Doxygen will +# evaluate all C-preprocessor directives found in the sources and include +# files. + +ENABLE_PREPROCESSING = YES + +# If the MACRO_EXPANSION tag is set to YES Doxygen will expand all macro +# names in the source code. If set to NO (the default) only conditional +# compilation will be performed. Macro expansion can be done in a controlled +# way by setting EXPAND_ONLY_PREDEF to YES. + +MACRO_EXPANSION = YES + +# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES +# then the macro expansion is limited to the macros specified with the +# PREDEFINED and EXPAND_AS_PREDEFINED tags. + +EXPAND_ONLY_PREDEF = YES + +# If the SEARCH_INCLUDES tag is set to YES (the default) the includes files +# in the INCLUDE_PATH (see below) will be search if a #include is found. + +SEARCH_INCLUDES = YES + +# The INCLUDE_PATH tag can be used to specify one or more directories that +# contain include files that are not input files but should be processed by +# the preprocessor. + +INCLUDE_PATH = + +# You can use the INCLUDE_FILE_PATTERNS tag to specify one or more +# wildcard patterns (like *.h and *.hpp) to filter out the +# header-files in the directories. If left blank, the patterns +# specified with FILE_PATTERNS will be used. + +INCLUDE_FILE_PATTERNS = + +# The PREDEFINED tag can be used to specify one or more macro names +# that are defined before the preprocessor is started (similar to the +# -D option of gcc). The argument of the tag is a list of macros of +# the form: name or name=definition (no spaces). If the definition and +# the = are omitted =1 is assumed. + +PREDEFINED = + +# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES +# then this tag can be used to specify a list of macro names that +# should be expanded. The macro definition that is found in the +# sources will be used. Use the PREDEFINED tag if you want to use a +# different macro definition. + +EXPAND_AS_DEFINED = __attribute__ + +# If the SKIP_FUNCTION_MACROS tag is set to YES (the default) then +# doxygen's preprocessor will remove all function-like macros that are +# alone on a line, have an all uppercase name, and do not end with a +# semicolon. Such function macros are typically used for boiler-plate +# code, and will confuse the parser if not removed. + +SKIP_FUNCTION_MACROS = YES + +#--------------------------------------------------------------------------- +# Configuration::additions related to external references +#--------------------------------------------------------------------------- + +# The TAGFILES option can be used to specify one or more tagfiles. +# Optionally an initial location of the external documentation +# can be added for each tagfile. The format of a tag file without +# this location is as follows: +# TAGFILES = file1 file2 ... +# Adding location for the tag files is done as follows: +# TAGFILES = file1=loc1 "file2 = loc2" ... +# where "loc1" and "loc2" can be relative or absolute paths or +# URLs. If a location is present for each tag, the installdox tool +# does not have to be run to correct the links. +# Note that each tag file must have a unique name +# (where the name does NOT include the path) +# If a tag file is not located in the directory in which doxygen +# is run, you must also specify the path to the tagfile here. + +TAGFILES = + +# When a file name is specified after GENERATE_TAGFILE, doxygen will create +# a tag file that is based on the input files it reads. + +GENERATE_TAGFILE = + +# If the ALLEXTERNALS tag is set to YES all external classes will be listed +# in the class index. If set to NO only the inherited external classes +# will be listed. + +ALLEXTERNALS = NO + +# If the EXTERNAL_GROUPS tag is set to YES all external groups will be listed +# in the modules index. If set to NO, only the current project's groups will +# be listed. + +EXTERNAL_GROUPS = YES + +# The PERL_PATH should be the absolute path and name of the perl script +# interpreter (i.e. the result of `which perl'). + +PERL_PATH = /usr/bin/perl + +#--------------------------------------------------------------------------- +# Configuration options related to the dot tool +#--------------------------------------------------------------------------- + +# If the CLASS_DIAGRAMS tag is set to YES (the default) Doxygen will +# generate a inheritance diagram (in HTML, RTF and LaTeX) for classes with base or +# super classes. Setting the tag to NO turns the diagrams off. Note that this +# option is superseded by the HAVE_DOT option below. This is only a fallback. It is +# recommended to install and use dot, since it yields more powerful graphs. + +CLASS_DIAGRAMS = YES + +# If set to YES, the inheritance and collaboration graphs will hide +# inheritance and usage relations if the target is undocumented +# or is not a class. + +HIDE_UNDOC_RELATIONS = YES + +# If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is +# available from the path. This tool is part of Graphviz, a graph visualization +# toolkit from AT&T and Lucent Bell Labs. The other options in this section +# have no effect if this option is set to NO (the default) + +HAVE_DOT = NO + +# If the CLASS_GRAPH and HAVE_DOT tags are set to YES then doxygen +# will generate a graph for each documented class showing the direct and +# indirect inheritance relations. Setting this tag to YES will force the +# the CLASS_DIAGRAMS tag to NO. + +CLASS_GRAPH = YES + +# If the COLLABORATION_GRAPH and HAVE_DOT tags are set to YES then doxygen +# will generate a graph for each documented class showing the direct and +# indirect implementation dependencies (inheritance, containment, and +# class references variables) of the class with other documented classes. + +COLLABORATION_GRAPH = YES + +# If the UML_LOOK tag is set to YES doxygen will generate inheritance and +# collaboration diagrams in a style similar to the OMG's Unified Modeling +# Language. + +UML_LOOK = NO + +# If set to YES, the inheritance and collaboration graphs will show the +# relations between templates and their instances. + +TEMPLATE_RELATIONS = NO + +# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDE_GRAPH, and HAVE_DOT +# tags are set to YES then doxygen will generate a graph for each documented +# file showing the direct and indirect include dependencies of the file with +# other documented files. + +INCLUDE_GRAPH = YES + +# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDED_BY_GRAPH, and +# HAVE_DOT tags are set to YES then doxygen will generate a graph for each +# documented header file showing the documented files that directly or +# indirectly include this file. + +INCLUDED_BY_GRAPH = YES + +# If the CALL_GRAPH and HAVE_DOT tags are set to YES then doxygen will +# generate a call dependency graph for every global function or class method. +# Note that enabling this option will significantly increase the time of a run. +# So in most cases it will be better to enable call graphs for selected +# functions only using the \callgraph command. + +CALL_GRAPH = YES + +# If the GRAPHICAL_HIERARCHY and HAVE_DOT tags are set to YES then doxygen +# will graphical hierarchy of all classes instead of a textual one. + +GRAPHICAL_HIERARCHY = YES + +# The DOT_IMAGE_FORMAT tag can be used to set the image format of the images +# generated by dot. Possible values are png, jpg, or gif +# If left blank png will be used. + +DOT_IMAGE_FORMAT = png + +# The tag DOT_PATH can be used to specify the path where the dot tool can be +# found. If left blank, it is assumed the dot tool can be found on the path. + +DOT_PATH = + +# The DOTFILE_DIRS tag can be used to specify one or more directories that +# contain dot files that are included in the documentation (see the +# \dotfile command). + +DOTFILE_DIRS = + +# The MAX_DOT_GRAPH_WIDTH tag can be used to set the maximum allowed width +# (in pixels) of the graphs generated by dot. If a graph becomes larger than +# this value, doxygen will try to truncate the graph, so that it fits within +# the specified constraint. Beware that most browsers cannot cope with very +# large images. + +MAX_DOT_GRAPH_WIDTH = 1024 + +# The MAX_DOT_GRAPH_HEIGHT tag can be used to set the maximum allows height +# (in pixels) of the graphs generated by dot. If a graph becomes larger than +# this value, doxygen will try to truncate the graph, so that it fits within +# the specified constraint. Beware that most browsers cannot cope with very +# large images. + +MAX_DOT_GRAPH_HEIGHT = 1024 + +# The MAX_DOT_GRAPH_DEPTH tag can be used to set the maximum depth of the +# graphs generated by dot. A depth value of 3 means that only nodes reachable +# from the root by following a path via at most 3 edges will be shown. Nodes that +# lay further from the root node will be omitted. Note that setting this option to +# 1 or 2 may greatly reduce the computation time needed for large code bases. Also +# note that a graph may be further truncated if the graph's image dimensions are +# not sufficient to fit the graph (see MAX_DOT_GRAPH_WIDTH and MAX_DOT_GRAPH_HEIGHT). +# If 0 is used for the depth value (the default), the graph is not depth-constrained. + +MAX_DOT_GRAPH_DEPTH = 0 + +# If the GENERATE_LEGEND tag is set to YES (the default) Doxygen will +# generate a legend page explaining the meaning of the various boxes and +# arrows in the dot generated graphs. + +GENERATE_LEGEND = YES + +# If the DOT_CLEANUP tag is set to YES (the default) Doxygen will +# remove the intermediate dot files that are used to generate +# the various graphs. + +DOT_CLEANUP = YES + +#--------------------------------------------------------------------------- +# Configuration::additions related to the search engine +#--------------------------------------------------------------------------- + +# The SEARCHENGINE tag specifies whether or not a search engine should be +# used. If set to NO the values of all tags below this one will be ignored. + +SEARCHENGINE = NO diff --git a/vendor/MDBC/unittest/mytap/t/basic-t.c b/vendor/MDBC/unittest/mytap/t/basic-t.c new file mode 100644 index 00000000..c0ceb5bf --- /dev/null +++ b/vendor/MDBC/unittest/mytap/t/basic-t.c @@ -0,0 +1,33 @@ +/* Copyright (C) 2006 MySQL AB + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ + +#include "my_config.h" + +#include +#include "../tap.h" + +int main() { + plan(5); + ok(1 == 1, "testing basic functions"); + ok(2 == 2, " "); + ok(3 == 3, NULL); + if (1 == 1) + skip(2, "Sensa fragoli"); + else { + ok(1 == 2, "Should not be run at all"); + ok(1, "This one neither"); + } + return exit_status(); +} diff --git a/vendor/MDBC/unittest/mytap/tap.c b/vendor/MDBC/unittest/mytap/tap.c new file mode 100644 index 00000000..d0b52f4d --- /dev/null +++ b/vendor/MDBC/unittest/mytap/tap.c @@ -0,0 +1,600 @@ +/* Copyright (C) 2006 MySQL AB + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + MA 02111-1301, USA + + Library for providing TAP support for testing C and C++ was written + by Mats Kindahl . +*/ + +#include "tap.h" + +#include "ma_global.h" + +#include +#include +#include +#include +#include + +/* + Visual Studio 2003 does not know vsnprintf but knows _vsnprintf. + We don't put this #define in config-win.h because we prefer + ma_vsnprintf everywhere instead, except when linking with libmysys + is not desirable - the case here. +*/ +#if defined(_MSC_VER) && ( _MSC_VER == 1310 ) +#define vsnprintf _vsnprintf +#endif + +/** + @defgroup MyTAP_Internal MyTAP Internals + + Internal functions and data structures for the MyTAP implementation. +*/ + +/** + Test data structure. + + Data structure containing all information about the test suite. + + @ingroup MyTAP_Internal + */ +static TEST_DATA g_test = { 0, 0, 0, "" }; + +/** + Output stream for test report message. + + The macro is just a temporary solution. + + @ingroup MyTAP_Internal + */ +#define tapout stdout + +/** + Emit the beginning of a test line, that is: "(not) ok", test number, + and description. + + To emit the directive, use the emit_dir() function + + @ingroup MyTAP_Internal + + @see emit_dir + + @param pass 'true' if test passed, 'false' otherwise + @param fmt Description of test in printf() format. + @param ap Vararg list for the description string above. + */ +static void +vemit_tap(int pass, char const *fmt, va_list ap) +{ + fprintf(tapout, "%sok %d%s", + pass ? "" : "not ", + ++g_test.last, + (fmt && *fmt) ? " - " : ""); + if (fmt && *fmt) + vfprintf(tapout, fmt, ap); +} + + +/** + Emit a TAP directive. + + TAP directives are comments after that have the form: + + @code + ok 1 # skip reason for skipping + not ok 2 # todo some text explaining what remains + @endcode + + @ingroup MyTAP_Internal + + @param dir Directive as a string + @param why Explanation string + */ +static void +emit_dir(const char *dir, const char *why) +{ + fprintf(tapout, " # %s %s", dir, why); +} + + +/** + Emit a newline to the TAP output stream. + + @ingroup MyTAP_Internal + */ +static void +emit_endl() +{ + fprintf(tapout, "\n"); +} + +static void +handle_core_signal(int signo) +{ + BAIL_OUT("Signal %d thrown", signo); +} + +void +BAIL_OUT(char const *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + fprintf(tapout, "Bail out! "); + vfprintf(tapout, fmt, ap); + emit_endl(); + va_end(ap); + exit(255); +} + + +void +diag(char const *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + fprintf(tapout, "# "); + vfprintf(tapout, fmt, ap); + emit_endl(); + va_end(ap); +} + +typedef struct signal_entry { + int signo; + void (*handler)(int); +} signal_entry; + +static signal_entry install_signal[]= { +#ifdef SIGQUIT + { SIGQUIT, handle_core_signal }, +#endif + { SIGILL, handle_core_signal }, + { SIGABRT, handle_core_signal }, + { SIGFPE, handle_core_signal }, + { SIGSEGV, handle_core_signal } +#ifdef SIGBUS + , { SIGBUS, handle_core_signal } +#endif +#ifdef SIGXCPU + , { SIGXCPU, handle_core_signal } +#endif +#ifdef SIGXCPU + , { SIGXFSZ, handle_core_signal } +#endif +#ifdef SIGXCPU + , { SIGSYS, handle_core_signal } +#endif +#ifdef SIGXCPU + , { SIGTRAP, handle_core_signal } +#endif +}; + +int skip_big_tests= 1; + +void +plan(int const count) +{ + char *config= getenv("MYTAP_CONFIG"); + size_t i; + + if (config) + skip_big_tests= strcmp(config, "big"); + + setvbuf(tapout, 0, _IONBF, 0); /* provide output at once */ + /* + Install signal handler + */ + + for (i= 0; i < sizeof(install_signal)/sizeof(*install_signal); ++i) + signal(install_signal[i].signo, install_signal[i].handler); + + g_test.plan= count; + switch (count) + { + case NO_PLAN: + break; + default: + if (count > 0) + fprintf(tapout, "1..%d\n", count); + break; + } +} + + +void +skip_all(char const *reason, ...) +{ + va_list ap; + va_start(ap, reason); + fprintf(tapout, "1..0 # skip "); + vfprintf(tapout, reason, ap); + va_end(ap); + exit(0); +} + +void +ok(int const pass, char const *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + + if (!pass && *g_test.todo == '\0') + ++g_test.failed; + + vemit_tap(pass, fmt, ap); + va_end(ap); + if (*g_test.todo != '\0') + emit_dir("todo", g_test.todo); + emit_endl(); +} + + +void +skip(int how_many, char const *const fmt, ...) +{ + char reason[80]; + if (fmt && *fmt) + { + va_list ap; + va_start(ap, fmt); + vsnprintf(reason, sizeof(reason), fmt, ap); + va_end(ap); + } + else + reason[0] = '\0'; + + while (how_many-- > 0) + { + va_list ap; + memset((char*) &ap, 0, sizeof(ap)); /* Keep compiler happy */ + vemit_tap(1, NULL, ap); + emit_dir("skip", reason); + emit_endl(); + } +} + +void +todo_start(char const *message, ...) +{ + va_list ap; + va_start(ap, message); + vsnprintf(g_test.todo, sizeof(g_test.todo), message, ap); + va_end(ap); +} + +void +todo_end() +{ + *g_test.todo = '\0'; +} + +int exit_status() { + /* + If there were no plan, we write one last instead. + */ + if (g_test.plan == NO_PLAN) + plan(g_test.last); + + if (g_test.plan != g_test.last) + { + diag("%d tests planned but%s %d executed", + g_test.plan, (g_test.plan > g_test.last ? " only" : ""), g_test.last); + return EXIT_FAILURE; + } + + if (g_test.failed > 0) + { + diag("Failed %d tests!", g_test.failed); + return EXIT_FAILURE; + } + + return EXIT_SUCCESS; +} + +/** + @mainpage Testing C and C++ using MyTAP + + @section IntroSec Introduction + + Unit tests are used to test individual components of a system. In + contrast, functional tests usually test the entire system. The + rationale is that each component should be correct if the system is + to be correct. Unit tests are usually small pieces of code that + tests an individual function, class, a module, or other unit of the + code. + + Observe that a correctly functioning system can be built from + "faulty" components. The problem with this approach is that as the + system evolves, the bugs surface in unexpected ways, making + maintenance harder. + + The advantages of using unit tests to test components of the system + are several: + + - The unit tests can make a more thorough testing than the + functional tests by testing correctness even for pathological use + (which shouldn't be present in the system). This increases the + overall robustness of the system and makes maintenance easier. + + - It is easier and faster to find problems with a malfunctioning + component than to find problems in a malfunctioning system. This + shortens the compile-run-edit cycle and therefore improves the + overall performance of development. + + - The component has to support at least two uses: in the system and + in a unit test. This leads to more generic and stable interfaces + and in addition promotes the development of reusable components. + + For example, the following are typical functional tests: + - Does transactions work according to specifications? + - Can we connect a client to the server and execute statements? + + In contrast, the following are typical unit tests: + + - Can the 'String' class handle a specified list of character sets? + - Does all operations for 'my_bitmap' produce the correct result? + - Does all the NIST test vectors for the AES implementation encrypt + correctly? + + + @section UnitTest Writing unit tests + + The purpose of writing unit tests is to use them to drive component + development towards a solution that passes the tests. This means that the + unit tests has to be as complete as possible, testing at least: + + - Normal input + - Borderline cases + - Faulty input + - Error handling + - Bad environment + + @subsection NormalSubSec Normal input + + This is to test that the component have the expected behaviour. + This is just plain simple: test that it works. For example, test + that you can unpack what you packed, adding gives the sum, pincing + the duck makes it quack. + + This is what everybody does when they write tests. + + + @subsection BorderlineTests Borderline cases + + If you have a size anywhere for your component, does it work for + size 1? Size 0? Sizes close to UINT_MAX? + + It might not be sensible to have a size 0, so in this case it is + not a borderline case, but rather a faulty input (see @ref + FaultyInputTests). + + + @subsection FaultyInputTests Faulty input + + Does your bitmap handle 0 bits size? Well, it might not be designed + for it, but is should not crash the application, but + rather produce an error. This is called defensive programming. + + Unfortunately, adding checks for values that should just not be + entered at all is not always practical: the checks cost cycles and + might cost more than it's worth. For example, some functions are + designed so that you may not give it a null pointer. In those + cases it's not sensible to pass it NULL just to see it + crash. + + Since every experienced programmer add an assert() to + ensure that you get a proper failure for the debug builds when a + null pointer passed (you add asserts too, right?), you will in this + case instead have a controlled (early) crash in the debug build. + + + @subsection ErrorHandlingTests Error handling + + This is testing that the errors your component is designed to give + actually are produced. For example, testing that trying to open a + non-existing file produces a sensible error code. + + + @subsection BadEnvironmentTests Environment + + Sometimes, modules has to behave well even when the environment + fails to work correctly. Typical examples are when the computer is + out of dynamic memory or when the disk is full. You can emulate + this by replacing, e.g., malloc() with your own + version that will work for a while, but then fail. Some things are + worth to keep in mind here: + + - Make sure to make the function fail deterministically, so that + you really can repeat the test. + + - Make sure that it doesn't just fail immediately. The unit might + have checks for the first case, but might actually fail some time + in the near future. + + + @section UnitTest How to structure a unit test + + In this section we will give some advice on how to structure the + unit tests to make the development run smoothly. The basic + structure of a test is: + + - Plan + - Test + - Report + + + @subsection TestPlanning Plan the test + + Planning the test means telling how many tests there are. In the + event that one of the tests causes a crash, it is then possible to + see that there are fewer tests than expected, and print a proper + error message. + + To plan a test, use the @c plan() function in the following manner: + + @code + int main(int argc, char *argv[]) + { + plan(5); + . + . + . + } + @endcode + + If you don't call the @c plan() function, the number of tests + executed will be printed at the end. This is intended to be used + while developing the unit and you are constantly adding tests. It + is not indented to be used after the unit has been released. + + + @subsection TestRunning Execute the test + + To report the status of a test, the @c ok() function is used in the + following manner: + + @code + int main(int argc, char *argv[]) + { + plan(5); + ok(ducks == paddling_ducks, + "%d ducks did not paddle", ducks - paddling_ducks); + . + . + . + } + @endcode + + This will print a test result line on the standard output in TAP + format, which allows TAP handling frameworks (like Test::Harness) + to parse the status of the test. + + @subsection TestReport Report the result of the test + + At the end, a complete test report should be written, with some + statistics. If the test returns EXIT_SUCCESS, all tests were + successful, otherwise at least one test failed. + + To get a TAP compliant output and exit status, report the exit + status in the following manner: + + @code + int main(int argc, char *argv[]) + { + plan(5); + ok(ducks == paddling_ducks, + "%d ducks did not paddle", ducks - paddling_ducks); + . + . + . + return exit_status(); + } + @endcode + + @section DontDoThis Ways to not do unit testing + + In this section, we'll go through some quite common ways to write + tests that are not a good idea. + + @subsection BreadthFirstTests Doing breadth-first testing + + If you're writing a library with several functions, don't test all + functions using size 1, then all functions using size 2, etc. If a + test for size 42 fails, you have no easy way of tracking down why + it failed. + + It is better to concentrate on getting one function to work at a + time, which means that you test each function for all sizes that + you think is reasonable. Then you continue with the next function, + doing the same. This is usually also the way that a library is + developed (one function at a time) so stick to testing that is + appropriate for now the unit is developed. + + @subsection JustToBeSafeTest Writing unnecessarily large tests + + Don't write tests that use parameters in the range 1-1024 unless + you have a very good reason to believe that the component will + succeed for 562 but fail for 564 (the numbers picked are just + examples). + + It is very common to write extensive tests "just to be safe." + Having a test suite with a lot of values might give you a warm + fuzzy feeling, but it doesn't really help you find the bugs. Good + tests fail; seriously, if you write a test that you expect to + succeed, you don't need to write it. If you think that it + might fail, then you should write it. + + Don't take this as an excuse to avoid writing any tests at all + "since I make no mistakes" (when it comes to this, there are two + kinds of people: those who admit they make mistakes, and those who + don't); rather, this means that there is no reason to test that + using a buffer with size 100 works when you have a test for buffer + size 96. + + The drawback is that the test suite takes longer to run, for little + or no benefit. It is acceptable to do a exhaustive test if it + doesn't take too long to run and it is quite common to do an + exhaustive test of a function for a small set of values. + Use your judgment to decide what is excessive: your milage may + vary. +*/ + +/** + @example simple.t.c + + This is an simple example of how to write a test using the + library. The output of this program is: + + @code + 1..1 + # Testing basic functions + ok 1 - Testing gcs() + @endcode + + The basic structure is: plan the number of test points using the + plan() function, perform the test and write out the result of each + test point using the ok() function, print out a diagnostics message + using diag(), and report the result of the test by calling the + exit_status() function. Observe that this test does excessive + testing (see @ref JustToBeSafeTest), but the test point doesn't + take very long time. +*/ + +/** + @example todo.t.c + + This example demonstrates how to use the todo_start() + and todo_end() function to mark a sequence of tests to + be done. Observe that the tests are assumed to fail: if any test + succeeds, it is considered a "bonus". +*/ + +/** + @example skip.t.c + + This is an example of how the SKIP_BLOCK_IF can be + used to skip a predetermined number of tests. Observe that the + macro actually skips the following statement, but it's not sensible + to use anything than a block. +*/ + +/** + @example skip_all.t.c + + Sometimes, you skip an entire test because it's testing a feature + that doesn't exist on the system that you're testing. To skip an + entire test, use the skip_all() function according to + this example. + */ diff --git a/vendor/MDBC/unittest/mytap/tap.h b/vendor/MDBC/unittest/mytap/tap.h new file mode 100644 index 00000000..15b1842b --- /dev/null +++ b/vendor/MDBC/unittest/mytap/tap.h @@ -0,0 +1,305 @@ +/* Copyright (C) 2006 MySQL AB + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + MA 02111-1301, USA + + Library for providing TAP support for testing C and C++ was written + by Mats Kindahl . +*/ + +#ifndef TAP_H +#define TAP_H + +#include "ma_global.h" + +/* + @defgroup MyTAP MySQL support for performing unit tests according to + the Test Anything Protocol (TAP). +*/ + +#define NO_PLAN (0) + +/** + Data about test plan. + + @ingroup MyTAP_Internal + + @internal We are using the "typedef struct X { ... } X" idiom to + create class/struct X both in C and C++. + */ + +typedef struct TEST_DATA { + /** + Number of tests that is planned to execute. + + Can be zero (NO_PLAN) meaning that the plan string + will be printed at the end of test instead. + */ + int plan; + + /** Number of last test that was done or skipped. */ + int last; + + /** Number of tests that failed. */ + int failed; + + /** Todo reason. */ + char todo[128]; +} TEST_DATA; + +#ifdef __cplusplus +extern "C" { +#endif + +/** + Defines whether "big" tests should be skipped. + + This variable is set by plan() function unless MYTAP_CONFIG environment + variable is set to the string "big". It is supposed to be used as + + @code + if (skip_big_tests) { + skip(1, "Big test skipped"); + } else { + ok(life_universe_and_everything() == 42, "The answer is CORRECT"); + } + @endcode + + @see SKIP_BIG_TESTS +*/ +extern int skip_big_tests; + +/** + @defgroup MyTAP_API MyTAP API + + MySQL support for performing unit tests according to TAP. + + @{ +*/ + +/** + Set number of tests that is planned to execute. + + The function also accepts the predefined constant + NO_PLAN. If the function is not called, it is as if + it was called with NO_PLAN, i.e., the test plan will + be printed after all the test lines. + + The plan() function will install signal handlers for all signals + that generate a core, so if you want to override these signals, do + it after you have called the plan() function. + + It will also set skip_big_tests variable if MYTAP_CONFIG environment + variable is defined. + + @see skip_big_tests + + @param count The planned number of tests to run. +*/ + +void plan(int const count); + + +/** + Report test result as a TAP line. + + Function used to write status of an individual test. Call this + function in the following manner: + + @code + ok(ducks == paddling, + "%d ducks did not paddle", ducks - paddling); + @endcode + + @param pass Zero if the test failed, non-zero if it passed. + @param fmt Format string in printf() format. NULL is allowed, in + which case nothing is printed. +*/ + +void ok(int const pass, char const *fmt, ...) + __attribute__((format(printf,2,3))); + + +/** + Skip a determined number of tests. + + Function to print that how_many tests have been skipped. + The reason is printed for each skipped test. Observe that this + function does not do the actual skipping for you, it just prints + information that tests have been skipped. This function is not + usually used, but rather the macro @c SKIP_BLOCK_IF, which does the + skipping for you. + + It shall be used in the following manner: + + @code + if (ducks == 0) { + skip(2, "No ducks in the pond"); + } else { + int i; + for (i = 0 ; i < 2 ; ++i) + ok(duck[i] == paddling, "is duck %d paddling?", i); + } + @endcode + + @see SKIP_BLOCK_IF + + @param how_many Number of tests that are to be skipped. + @param reason A reason for skipping the tests + */ + +void skip(int how_many, char const *const reason, ...) + __attribute__((format(printf,2,3))); + + +/** + Helper macro to skip a block of code. The macro can be used to + simplify conditionally skipping a block of code. It is used in the + following manner: + + @code + SKIP_BLOCK_IF(ducks == 0, 2, "No ducks in the pond") + { + int i; + for (i = 0 ; i < 2 ; ++i) + ok(duck[i] == paddling, "is duck %d paddling?", i); + } + @endcode + + @see skip + */ + +#define SKIP_BLOCK_IF(SKIP_IF_TRUE, COUNT, REASON) \ + if (SKIP_IF_TRUE) skip((COUNT),(REASON)); else + + +/** + Helper macro to skip a group of "big" tests. It is used in the following + manner: + + @code + SKIP_BIG_TESTS(1) + { + ok(life_universe_and_everything() == 42, "The answer is CORRECT"); + } + @endcode + + @see skip_big_tests + */ + +#define SKIP_BIG_TESTS(COUNT) \ + if (skip_big_tests) skip((COUNT), "big test"); else + + +/** + Print a diagnostics message. + + @param fmt Diagnostics message in printf() format. + */ + +void diag(char const *fmt, ...) + __attribute__((format(printf,1,2))); + + +/** + Print a bail out message. + + A bail out message can be issued when no further testing can be + done, e.g., when there are missing dependencies. + + The test will exit with status 255. This function does not return. + + @code + BAIL_OUT("Lost connection to server %s", server_name); + @endcode + + @note A bail out message is printed if a signal that generates a + core is raised. + + @param fmt Bail out message in printf() format. +*/ + +void BAIL_OUT(char const *fmt, ...) + __attribute__((noreturn, format(printf,1,2))); + + +/** + Print summary report and return exit status. + + This function will print a summary report of how many tests passed, + how many were skipped, and how many remains to do. The function + should be called after all tests are executed in the following + manner: + + @code + return exit_status(); + @endcode + + @returns @c EXIT_SUCCESS if all tests passed, @c EXIT_FAILURE if + one or more tests failed. + */ + +int exit_status(void); + + +/** + Skip entire test suite. + + To skip the entire test suite, use this function. It will + automatically call exit(), so there is no need to have checks + around it. + */ + +void skip_all(char const *reason, ...) + __attribute__((noreturn, format(printf, 1, 2))); + + +/** + Start section of tests that are not yet ready. + + To start a section of tests that are not ready and are expected to + fail, use this function and todo_end() in the following manner: + + @code + todo_start("Not ready yet"); + ok(is_rocketeering(duck), "Rocket-propelled ducks"); + ok(is_kamikaze(duck), "Kamikaze ducks"); + todo_end(); + @endcode + + @see todo_end + + @note + It is not possible to nest todo sections. + + @param message Message that will be printed before the todo tests. +*/ + +void todo_start(char const *message, ...) + __attribute__((format(printf, 1, 2))); + + +/** + End a section of tests that are not yet ready. +*/ + +void todo_end(); + +/** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /* TAP_H */ diff --git a/vendor/MDBC/win-iconv/iconv.h b/vendor/MDBC/win-iconv/iconv.h new file mode 100644 index 00000000..eca8070b --- /dev/null +++ b/vendor/MDBC/win-iconv/iconv.h @@ -0,0 +1,14 @@ +#ifndef _LIBICONV_H +#define _LIBICONV_H +#include +#ifdef __cplusplus +extern "C" { +#endif +typedef void* iconv_t; +iconv_t iconv_open(const char *tocode, const char *fromcode); +int iconv_close(iconv_t cd); +size_t iconv(iconv_t cd, const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft); +#ifdef __cplusplus +} +#endif +#endif//_LIBICONV_H \ No newline at end of file diff --git a/vendor/MDBC/win-iconv/mlang.h b/vendor/MDBC/win-iconv/mlang.h new file mode 100644 index 00000000..5cbf779c --- /dev/null +++ b/vendor/MDBC/win-iconv/mlang.h @@ -0,0 +1,54 @@ +HRESULT WINAPI ConvertINetString( + LPDWORD lpdwMode, + DWORD dwSrcEncoding, + DWORD dwDstEncoding, + LPCSTR lpSrcStr, + LPINT lpnSrcSize, + LPBYTE lpDstStr, + LPINT lpnDstSize +); + +HRESULT WINAPI ConvertINetMultiByteToUnicode( + LPDWORD lpdwMode, + DWORD dwSrcEncoding, + LPCSTR lpSrcStr, + LPINT lpnMultiCharCount, + LPWSTR lpDstStr, + LPINT lpnWideCharCount +); + +HRESULT WINAPI ConvertINetUnicodeToMultiByte( + LPDWORD lpdwMode, + DWORD dwEncoding, + LPCWSTR lpSrcStr, + LPINT lpnWideCharCount, + LPSTR lpDstStr, + LPINT lpnMultiCharCount +); + +HRESULT WINAPI IsConvertINetStringAvailable( + DWORD dwSrcEncoding, + DWORD dwDstEncoding +); + +HRESULT WINAPI LcidToRfc1766A( + LCID Locale, + LPSTR pszRfc1766, + int nChar +); + +HRESULT WINAPI LcidToRfc1766W( + LCID Locale, + LPWSTR pszRfc1766, + int nChar +); + +HRESULT WINAPI Rfc1766ToLcidA( + LCID *pLocale, + LPSTR pszRfc1766 +); + +HRESULT WINAPI Rfc1766ToLcidW( + LCID *pLocale, + LPWSTR pszRfc1766 +); diff --git a/vendor/MDBC/win-iconv/win_iconv.c b/vendor/MDBC/win-iconv/win_iconv.c new file mode 100644 index 00000000..84bb43b0 --- /dev/null +++ b/vendor/MDBC/win-iconv/win_iconv.c @@ -0,0 +1,2051 @@ +/* + * iconv implementation using Win32 API to convert. + * + * This file is placed in the public domain. + */ + +/* for WC_NO_BEST_FIT_CHARS */ +#ifndef WINVER +# define WINVER 0x0500 +#endif + +#define STRICT +#include +#include +#include +#include + +#ifdef __GNUC__ +#define UNUSED __attribute__((unused)) +#else +#define UNUSED +#endif + +/* WORKAROUND: */ +#ifndef UNDER_CE +#define GetProcAddressA GetProcAddress +#endif + +#if 0 +# define MAKE_EXE +# define MAKE_DLL +# define USE_LIBICONV_DLL +#endif + +#if !defined(DEFAULT_LIBICONV_DLL) +# define DEFAULT_LIBICONV_DLL "" +#endif + +#define MB_CHAR_MAX 16 + +#define UNICODE_MODE_BOM_DONE 1 +#define UNICODE_MODE_SWAPPED 2 + +#define FLAG_USE_BOM 1 +#define FLAG_TRANSLIT 2 /* //TRANSLIT */ +#define FLAG_IGNORE 4 /* //IGNORE */ + +typedef unsigned char uchar; +typedef unsigned short ushort; +typedef unsigned int uint; + +typedef void* iconv_t; + +iconv_t iconv_open(const char *tocode, const char *fromcode); +int iconv_close(iconv_t cd); +size_t iconv(iconv_t cd, const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft); + +/* libiconv interface for vim */ +#if defined(MAKE_DLL) +int +iconvctl (iconv_t cd, int request, void* argument) +{ + /* not supported */ + return 0; +} +#endif + +typedef struct compat_t compat_t; +typedef struct csconv_t csconv_t; +typedef struct rec_iconv_t rec_iconv_t; + +typedef iconv_t (*f_iconv_open)(const char *tocode, const char *fromcode); +typedef int (*f_iconv_close)(iconv_t cd); +typedef size_t (*f_iconv)(iconv_t cd, const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft); +typedef int* (*f_errno)(void); +typedef int (*f_mbtowc)(csconv_t *cv, const uchar *buf, int bufsize, ushort *wbuf, int *wbufsize); +typedef int (*f_wctomb)(csconv_t *cv, ushort *wbuf, int wbufsize, uchar *buf, int bufsize); +typedef int (*f_mblen)(csconv_t *cv, const uchar *buf, int bufsize); +typedef int (*f_flush)(csconv_t *cv, uchar *buf, int bufsize); + +#define COMPAT_IN 1 +#define COMPAT_OUT 2 + +/* unicode mapping for compatibility with other conversion table. */ +struct compat_t { + uint in; + uint out; + uint flag; +}; + +struct csconv_t { + int codepage; + int flags; + f_mbtowc mbtowc; + f_wctomb wctomb; + f_mblen mblen; + f_flush flush; + DWORD mode; + compat_t *compat; +}; + +struct rec_iconv_t { + iconv_t cd; + f_iconv_close iconv_close; + f_iconv iconv; + f_errno _errno; + csconv_t from; + csconv_t to; +#if defined(USE_LIBICONV_DLL) + HMODULE hlibiconv; +#endif +}; + +static int win_iconv_open(rec_iconv_t *cd, const char *tocode, const char *fromcode); +static int win_iconv_close(iconv_t cd); +static size_t win_iconv(iconv_t cd, const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft); + +static int load_mlang(void); +static int make_csconv(const char *name, csconv_t *cv); +static int name_to_codepage(const char *name); +static uint utf16_to_ucs4(const ushort *wbuf); +static void ucs4_to_utf16(uint wc, ushort *wbuf, int *wbufsize); +static int mbtowc_flags(int codepage); +static int must_use_null_useddefaultchar(int codepage); +static char *strrstr(const char *str, const char *token); +static char *xstrndup(const char *s, size_t n); +static int seterror(int err); + +#if defined(USE_LIBICONV_DLL) +static int libiconv_iconv_open(rec_iconv_t *cd, const char *tocode, const char *fromcode); +static PVOID MyImageDirectoryEntryToData(LPVOID Base, BOOLEAN MappedAsImage, USHORT DirectoryEntry, PULONG Size); +static HMODULE find_imported_module_by_funcname(HMODULE hModule, const char *funcname); + +static HMODULE hwiniconv; +#endif + +static int sbcs_mblen(csconv_t *cv, const uchar *buf, int bufsize); +static int dbcs_mblen(csconv_t *cv, const uchar *buf, int bufsize); +static int mbcs_mblen(csconv_t *cv, const uchar *buf, int bufsize); +static int utf8_mblen(csconv_t *cv, const uchar *buf, int bufsize); +static int eucjp_mblen(csconv_t *cv, const uchar *buf, int bufsize); + +static int kernel_mbtowc(csconv_t *cv, const uchar *buf, int bufsize, ushort *wbuf, int *wbufsize); +static int kernel_wctomb(csconv_t *cv, ushort *wbuf, int wbufsize, uchar *buf, int bufsize); +static int mlang_mbtowc(csconv_t *cv, const uchar *buf, int bufsize, ushort *wbuf, int *wbufsize); +static int mlang_wctomb(csconv_t *cv, ushort *wbuf, int wbufsize, uchar *buf, int bufsize); +static int utf16_mbtowc(csconv_t *cv, const uchar *buf, int bufsize, ushort *wbuf, int *wbufsize); +static int utf16_wctomb(csconv_t *cv, ushort *wbuf, int wbufsize, uchar *buf, int bufsize); +static int utf32_mbtowc(csconv_t *cv, const uchar *buf, int bufsize, ushort *wbuf, int *wbufsize); +static int utf32_wctomb(csconv_t *cv, ushort *wbuf, int wbufsize, uchar *buf, int bufsize); +static int iso2022jp_mbtowc(csconv_t *cv, const uchar *buf, int bufsize, ushort *wbuf, int *wbufsize); +static int iso2022jp_wctomb(csconv_t *cv, ushort *wbuf, int wbufsize, uchar *buf, int bufsize); +static int iso2022jp_flush(csconv_t *cv, uchar *buf, int bufsize); + +static struct { + int codepage; + const char *name; +} codepage_alias[] = { + {65001, "CP65001"}, + {65001, "UTF8"}, + {65001, "UTF-8"}, + + {1200, "CP1200"}, + {1200, "UTF16LE"}, + {1200, "UTF-16LE"}, + {1200, "UCS2LE"}, + {1200, "UCS-2LE"}, + + {1201, "CP1201"}, + {1201, "UTF16BE"}, + {1201, "UTF-16BE"}, + {1201, "UCS2BE"}, + {1201, "UCS-2BE"}, + {1201, "unicodeFFFE"}, + + {12000, "CP12000"}, + {12000, "UTF32LE"}, + {12000, "UTF-32LE"}, + {12000, "UCS4LE"}, + {12000, "UCS-4LE"}, + + {12001, "CP12001"}, + {12001, "UTF32BE"}, + {12001, "UTF-32BE"}, + {12001, "UCS4BE"}, + {12001, "UCS-4BE"}, + +#ifndef GLIB_COMPILATION + /* + * Default is big endian. + * See rfc2781 4.3 Interpreting text labelled as UTF-16. + */ + {1201, "UTF16"}, + {1201, "UTF-16"}, + {1201, "UCS2"}, + {1201, "UCS-2"}, + {12001, "UTF32"}, + {12001, "UTF-32"}, + {12001, "UCS-4"}, + {12001, "UCS4"}, +#else + /* Default is little endian, because the platform is */ + {1200, "UTF16"}, + {1200, "UTF-16"}, + {1200, "UCS2"}, + {1200, "UCS-2"}, + {12000, "UTF32"}, + {12000, "UTF-32"}, + {12000, "UCS4"}, + {12000, "UCS-4"}, +#endif + + /* copy from libiconv `iconv -l` */ + /* !IsValidCodePage(367) */ + {20127, "ANSI_X3.4-1968"}, + {20127, "ANSI_X3.4-1986"}, + {20127, "ASCII"}, + {20127, "CP367"}, + {20127, "IBM367"}, + {20127, "ISO-IR-6"}, + {20127, "ISO646-US"}, + {20127, "ISO_646.IRV:1991"}, + {20127, "US"}, + {20127, "US-ASCII"}, + {20127, "CSASCII"}, + + /* !IsValidCodePage(819) */ + {1252, "CP819"}, + {1252, "IBM819"}, + {28591, "ISO-8859-1"}, + {28591, "ISO-IR-100"}, + {28591, "ISO8859-1"}, + {28591, "ISO_8859-1"}, + {28591, "ISO_8859-1:1987"}, + {28591, "L1"}, + {28591, "LATIN1"}, + {28591, "CSISOLATIN1"}, + + {1250, "CP1250"}, + {1250, "MS-EE"}, + {1250, "WINDOWS-1250"}, + + {1251, "CP1251"}, + {1251, "MS-CYRL"}, + {1251, "WINDOWS-1251"}, + + {1252, "CP1252"}, + {1252, "MS-ANSI"}, + {1252, "WINDOWS-1252"}, + + {1253, "CP1253"}, + {1253, "MS-GREEK"}, + {1253, "WINDOWS-1253"}, + + {1254, "CP1254"}, + {1254, "MS-TURK"}, + {1254, "WINDOWS-1254"}, + + {1255, "CP1255"}, + {1255, "MS-HEBR"}, + {1255, "WINDOWS-1255"}, + + {1256, "CP1256"}, + {1256, "MS-ARAB"}, + {1256, "WINDOWS-1256"}, + + {1257, "CP1257"}, + {1257, "WINBALTRIM"}, + {1257, "WINDOWS-1257"}, + + {1258, "CP1258"}, + {1258, "WINDOWS-1258"}, + + {850, "850"}, + {850, "CP850"}, + {850, "IBM850"}, + {850, "CSPC850MULTILINGUAL"}, + + /* !IsValidCodePage(862) */ + {862, "862"}, + {862, "CP862"}, + {862, "IBM862"}, + {862, "CSPC862LATINHEBREW"}, + + {866, "866"}, + {866, "CP866"}, + {866, "IBM866"}, + {866, "CSIBM866"}, + + /* !IsValidCodePage(154) */ + {154, "CP154"}, + {154, "CYRILLIC-ASIAN"}, + {154, "PT154"}, + {154, "PTCP154"}, + {154, "CSPTCP154"}, + + /* !IsValidCodePage(1133) */ + {1133, "CP1133"}, + {1133, "IBM-CP1133"}, + + {874, "CP874"}, + {874, "WINDOWS-874"}, + + /* !IsValidCodePage(51932) */ + {51932, "CP51932"}, + {51932, "MS51932"}, + {51932, "WINDOWS-51932"}, + {51932, "EUC-JP"}, + + {932, "CP932"}, + {932, "MS932"}, + {932, "SHIFFT_JIS"}, + {932, "SHIFFT_JIS-MS"}, + {932, "SJIS"}, + {932, "SJIS-MS"}, + {932, "SJIS-OPEN"}, + {932, "SJIS-WIN"}, + {932, "WINDOWS-31J"}, + {932, "WINDOWS-932"}, + {932, "CSWINDOWS31J"}, + + {50221, "CP50221"}, + {50221, "ISO-2022-JP"}, + {50221, "ISO-2022-JP-MS"}, + {50221, "ISO2022-JP"}, + {50221, "ISO2022-JP-MS"}, + {50221, "MS50221"}, + {50221, "WINDOWS-50221"}, + + {936, "CP936"}, + {936, "GBK"}, + {936, "MS936"}, + {936, "WINDOWS-936"}, + + {950, "CP950"}, + {950, "BIG5"}, + {950, "BIG5HKSCS"}, + {950, "BIG5-HKSCS"}, + + {949, "CP949"}, + {949, "UHC"}, + {949, "EUC-KR"}, + + {1361, "CP1361"}, + {1361, "JOHAB"}, + + {437, "437"}, + {437, "CP437"}, + {437, "IBM437"}, + {437, "CSPC8CODEPAGE437"}, + + {737, "CP737"}, + + {775, "CP775"}, + {775, "IBM775"}, + {775, "CSPC775BALTIC"}, + + {852, "852"}, + {852, "CP852"}, + {852, "IBM852"}, + {852, "CSPCP852"}, + + /* !IsValidCodePage(853) */ + {853, "CP853"}, + + {855, "855"}, + {855, "CP855"}, + {855, "IBM855"}, + {855, "CSIBM855"}, + + {857, "857"}, + {857, "CP857"}, + {857, "IBM857"}, + {857, "CSIBM857"}, + + /* !IsValidCodePage(858) */ + {858, "CP858"}, + + {860, "860"}, + {860, "CP860"}, + {860, "IBM860"}, + {860, "CSIBM860"}, + + {861, "861"}, + {861, "CP-IS"}, + {861, "CP861"}, + {861, "IBM861"}, + {861, "CSIBM861"}, + + {863, "863"}, + {863, "CP863"}, + {863, "IBM863"}, + {863, "CSIBM863"}, + + {864, "CP864"}, + {864, "IBM864"}, + {864, "CSIBM864"}, + + {865, "865"}, + {865, "CP865"}, + {865, "IBM865"}, + {865, "CSIBM865"}, + + {869, "869"}, + {869, "CP-GR"}, + {869, "CP869"}, + {869, "IBM869"}, + {869, "CSIBM869"}, + + /* !IsValidCodePage(1152) */ + {1125, "CP1125"}, + + /* + * Code Page Identifiers + * http://msdn2.microsoft.com/en-us/library/ms776446.aspx + */ + {37, "IBM037"}, /* IBM EBCDIC US-Canada */ + {437, "IBM437"}, /* OEM United States */ + {500, "IBM500"}, /* IBM EBCDIC International */ + {708, "ASMO-708"}, /* Arabic (ASMO 708) */ + /* 709 Arabic (ASMO-449+, BCON V4) */ + /* 710 Arabic - Transparent Arabic */ + {720, "DOS-720"}, /* Arabic (Transparent ASMO); Arabic (DOS) */ + {737, "ibm737"}, /* OEM Greek (formerly 437G); Greek (DOS) */ + {775, "ibm775"}, /* OEM Baltic; Baltic (DOS) */ + {850, "ibm850"}, /* OEM Multilingual Latin 1; Western European (DOS) */ + {852, "ibm852"}, /* OEM Latin 2; Central European (DOS) */ + {855, "IBM855"}, /* OEM Cyrillic (primarily Russian) */ + {857, "ibm857"}, /* OEM Turkish; Turkish (DOS) */ + {858, "IBM00858"}, /* OEM Multilingual Latin 1 + Euro symbol */ + {860, "IBM860"}, /* OEM Portuguese; Portuguese (DOS) */ + {861, "ibm861"}, /* OEM Icelandic; Icelandic (DOS) */ + {862, "DOS-862"}, /* OEM Hebrew; Hebrew (DOS) */ + {863, "IBM863"}, /* OEM French Canadian; French Canadian (DOS) */ + {864, "IBM864"}, /* OEM Arabic; Arabic (864) */ + {865, "IBM865"}, /* OEM Nordic; Nordic (DOS) */ + {866, "cp866"}, /* OEM Russian; Cyrillic (DOS) */ + {869, "ibm869"}, /* OEM Modern Greek; Greek, Modern (DOS) */ + {870, "IBM870"}, /* IBM EBCDIC Multilingual/ROECE (Latin 2); IBM EBCDIC Multilingual Latin 2 */ + {874, "windows-874"}, /* ANSI/OEM Thai (same as 28605, ISO 8859-15); Thai (Windows) */ + {875, "cp875"}, /* IBM EBCDIC Greek Modern */ + {932, "shift_jis"}, /* ANSI/OEM Japanese; Japanese (Shift-JIS) */ + {932, "shift-jis"}, /* alternative name for it */ + {936, "gb2312"}, /* ANSI/OEM Simplified Chinese (PRC, Singapore); Chinese Simplified (GB2312) */ + {949, "ks_c_5601-1987"}, /* ANSI/OEM Korean (Unified Hangul Code) */ + {950, "big5"}, /* ANSI/OEM Traditional Chinese (Taiwan; Hong Kong SAR, PRC); Chinese Traditional (Big5) */ + {950, "big5hkscs"}, /* ANSI/OEM Traditional Chinese (Hong Kong SAR); Chinese Traditional (Big5-HKSCS) */ + {950, "big5-hkscs"}, /* alternative name for it */ + {1026, "IBM1026"}, /* IBM EBCDIC Turkish (Latin 5) */ + {1047, "IBM01047"}, /* IBM EBCDIC Latin 1/Open System */ + {1140, "IBM01140"}, /* IBM EBCDIC US-Canada (037 + Euro symbol); IBM EBCDIC (US-Canada-Euro) */ + {1141, "IBM01141"}, /* IBM EBCDIC Germany (20273 + Euro symbol); IBM EBCDIC (Germany-Euro) */ + {1142, "IBM01142"}, /* IBM EBCDIC Denmark-Norway (20277 + Euro symbol); IBM EBCDIC (Denmark-Norway-Euro) */ + {1143, "IBM01143"}, /* IBM EBCDIC Finland-Sweden (20278 + Euro symbol); IBM EBCDIC (Finland-Sweden-Euro) */ + {1144, "IBM01144"}, /* IBM EBCDIC Italy (20280 + Euro symbol); IBM EBCDIC (Italy-Euro) */ + {1145, "IBM01145"}, /* IBM EBCDIC Latin America-Spain (20284 + Euro symbol); IBM EBCDIC (Spain-Euro) */ + {1146, "IBM01146"}, /* IBM EBCDIC United Kingdom (20285 + Euro symbol); IBM EBCDIC (UK-Euro) */ + {1147, "IBM01147"}, /* IBM EBCDIC France (20297 + Euro symbol); IBM EBCDIC (France-Euro) */ + {1148, "IBM01148"}, /* IBM EBCDIC International (500 + Euro symbol); IBM EBCDIC (International-Euro) */ + {1149, "IBM01149"}, /* IBM EBCDIC Icelandic (20871 + Euro symbol); IBM EBCDIC (Icelandic-Euro) */ + {1250, "windows-1250"}, /* ANSI Central European; Central European (Windows) */ + {1251, "windows-1251"}, /* ANSI Cyrillic; Cyrillic (Windows) */ + {1252, "windows-1252"}, /* ANSI Latin 1; Western European (Windows) */ + {1253, "windows-1253"}, /* ANSI Greek; Greek (Windows) */ + {1254, "windows-1254"}, /* ANSI Turkish; Turkish (Windows) */ + {1255, "windows-1255"}, /* ANSI Hebrew; Hebrew (Windows) */ + {1256, "windows-1256"}, /* ANSI Arabic; Arabic (Windows) */ + {1257, "windows-1257"}, /* ANSI Baltic; Baltic (Windows) */ + {1258, "windows-1258"}, /* ANSI/OEM Vietnamese; Vietnamese (Windows) */ + {1361, "Johab"}, /* Korean (Johab) */ + {10000, "macintosh"}, /* MAC Roman; Western European (Mac) */ + {10001, "x-mac-japanese"}, /* Japanese (Mac) */ + {10002, "x-mac-chinesetrad"}, /* MAC Traditional Chinese (Big5); Chinese Traditional (Mac) */ + {10003, "x-mac-korean"}, /* Korean (Mac) */ + {10004, "x-mac-arabic"}, /* Arabic (Mac) */ + {10005, "x-mac-hebrew"}, /* Hebrew (Mac) */ + {10006, "x-mac-greek"}, /* Greek (Mac) */ + {10007, "x-mac-cyrillic"}, /* Cyrillic (Mac) */ + {10008, "x-mac-chinesesimp"}, /* MAC Simplified Chinese (GB 2312); Chinese Simplified (Mac) */ + {10010, "x-mac-romanian"}, /* Romanian (Mac) */ + {10017, "x-mac-ukrainian"}, /* Ukrainian (Mac) */ + {10021, "x-mac-thai"}, /* Thai (Mac) */ + {10029, "x-mac-ce"}, /* MAC Latin 2; Central European (Mac) */ + {10079, "x-mac-icelandic"}, /* Icelandic (Mac) */ + {10081, "x-mac-turkish"}, /* Turkish (Mac) */ + {10082, "x-mac-croatian"}, /* Croatian (Mac) */ + {20000, "x-Chinese_CNS"}, /* CNS Taiwan; Chinese Traditional (CNS) */ + {20001, "x-cp20001"}, /* TCA Taiwan */ + {20002, "x_Chinese-Eten"}, /* Eten Taiwan; Chinese Traditional (Eten) */ + {20003, "x-cp20003"}, /* IBM5550 Taiwan */ + {20004, "x-cp20004"}, /* TeleText Taiwan */ + {20005, "x-cp20005"}, /* Wang Taiwan */ + {20105, "x-IA5"}, /* IA5 (IRV International Alphabet No. 5, 7-bit); Western European (IA5) */ + {20106, "x-IA5-German"}, /* IA5 German (7-bit) */ + {20107, "x-IA5-Swedish"}, /* IA5 Swedish (7-bit) */ + {20108, "x-IA5-Norwegian"}, /* IA5 Norwegian (7-bit) */ + {20127, "us-ascii"}, /* US-ASCII (7-bit) */ + {20261, "x-cp20261"}, /* T.61 */ + {20269, "x-cp20269"}, /* ISO 6937 Non-Spacing Accent */ + {20273, "IBM273"}, /* IBM EBCDIC Germany */ + {20277, "IBM277"}, /* IBM EBCDIC Denmark-Norway */ + {20278, "IBM278"}, /* IBM EBCDIC Finland-Sweden */ + {20280, "IBM280"}, /* IBM EBCDIC Italy */ + {20284, "IBM284"}, /* IBM EBCDIC Latin America-Spain */ + {20285, "IBM285"}, /* IBM EBCDIC United Kingdom */ + {20290, "IBM290"}, /* IBM EBCDIC Japanese Katakana Extended */ + {20297, "IBM297"}, /* IBM EBCDIC France */ + {20420, "IBM420"}, /* IBM EBCDIC Arabic */ + {20423, "IBM423"}, /* IBM EBCDIC Greek */ + {20424, "IBM424"}, /* IBM EBCDIC Hebrew */ + {20833, "x-EBCDIC-KoreanExtended"}, /* IBM EBCDIC Korean Extended */ + {20838, "IBM-Thai"}, /* IBM EBCDIC Thai */ + {20866, "koi8-r"}, /* Russian (KOI8-R); Cyrillic (KOI8-R) */ + {20871, "IBM871"}, /* IBM EBCDIC Icelandic */ + {20880, "IBM880"}, /* IBM EBCDIC Cyrillic Russian */ + {20905, "IBM905"}, /* IBM EBCDIC Turkish */ + {20924, "IBM00924"}, /* IBM EBCDIC Latin 1/Open System (1047 + Euro symbol) */ + {20932, "EUC-JP"}, /* Japanese (JIS 0208-1990 and 0121-1990) */ + {20936, "x-cp20936"}, /* Simplified Chinese (GB2312); Chinese Simplified (GB2312-80) */ + {20949, "x-cp20949"}, /* Korean Wansung */ + {21025, "cp1025"}, /* IBM EBCDIC Cyrillic Serbian-Bulgarian */ + /* 21027 (deprecated) */ + {21866, "koi8-u"}, /* Ukrainian (KOI8-U); Cyrillic (KOI8-U) */ + {28591, "iso-8859-1"}, /* ISO 8859-1 Latin 1; Western European (ISO) */ + {28591, "iso8859-1"}, /* ISO 8859-1 Latin 1; Western European (ISO) */ + {28592, "iso-8859-2"}, /* ISO 8859-2 Central European; Central European (ISO) */ + {28592, "iso8859-2"}, /* ISO 8859-2 Central European; Central European (ISO) */ + {28593, "iso-8859-3"}, /* ISO 8859-3 Latin 3 */ + {28593, "iso8859-3"}, /* ISO 8859-3 Latin 3 */ + {28594, "iso-8859-4"}, /* ISO 8859-4 Baltic */ + {28594, "iso8859-4"}, /* ISO 8859-4 Baltic */ + {28595, "iso-8859-5"}, /* ISO 8859-5 Cyrillic */ + {28595, "iso8859-5"}, /* ISO 8859-5 Cyrillic */ + {28596, "iso-8859-6"}, /* ISO 8859-6 Arabic */ + {28596, "iso8859-6"}, /* ISO 8859-6 Arabic */ + {28597, "iso-8859-7"}, /* ISO 8859-7 Greek */ + {28597, "iso8859-7"}, /* ISO 8859-7 Greek */ + {28598, "iso-8859-8"}, /* ISO 8859-8 Hebrew; Hebrew (ISO-Visual) */ + {28598, "iso8859-8"}, /* ISO 8859-8 Hebrew; Hebrew (ISO-Visual) */ + {28599, "iso-8859-9"}, /* ISO 8859-9 Turkish */ + {28599, "iso8859-9"}, /* ISO 8859-9 Turkish */ + {28603, "iso-8859-13"}, /* ISO 8859-13 Estonian */ + {28603, "iso8859-13"}, /* ISO 8859-13 Estonian */ + {28605, "iso-8859-15"}, /* ISO 8859-15 Latin 9 */ + {28605, "iso8859-15"}, /* ISO 8859-15 Latin 9 */ + {29001, "x-Europa"}, /* Europa 3 */ + {38598, "iso-8859-8-i"}, /* ISO 8859-8 Hebrew; Hebrew (ISO-Logical) */ + {38598, "iso8859-8-i"}, /* ISO 8859-8 Hebrew; Hebrew (ISO-Logical) */ + {50220, "iso-2022-jp"}, /* ISO 2022 Japanese with no halfwidth Katakana; Japanese (JIS) */ + {50221, "csISO2022JP"}, /* ISO 2022 Japanese with halfwidth Katakana; Japanese (JIS-Allow 1 byte Kana) */ + {50222, "iso-2022-jp"}, /* ISO 2022 Japanese JIS X 0201-1989; Japanese (JIS-Allow 1 byte Kana - SO/SI) */ + {50225, "iso-2022-kr"}, /* ISO 2022 Korean */ + {50225, "iso2022-kr"}, /* ISO 2022 Korean */ + {50227, "x-cp50227"}, /* ISO 2022 Simplified Chinese; Chinese Simplified (ISO 2022) */ + /* 50229 ISO 2022 Traditional Chinese */ + /* 50930 EBCDIC Japanese (Katakana) Extended */ + /* 50931 EBCDIC US-Canada and Japanese */ + /* 50933 EBCDIC Korean Extended and Korean */ + /* 50935 EBCDIC Simplified Chinese Extended and Simplified Chinese */ + /* 50936 EBCDIC Simplified Chinese */ + /* 50937 EBCDIC US-Canada and Traditional Chinese */ + /* 50939 EBCDIC Japanese (Latin) Extended and Japanese */ + {51932, "euc-jp"}, /* EUC Japanese */ + {51936, "EUC-CN"}, /* EUC Simplified Chinese; Chinese Simplified (EUC) */ + {51949, "euc-kr"}, /* EUC Korean */ + /* 51950 EUC Traditional Chinese */ + {52936, "hz-gb-2312"}, /* HZ-GB2312 Simplified Chinese; Chinese Simplified (HZ) */ + {54936, "GB18030"}, /* Windows XP and later: GB18030 Simplified Chinese (4 byte); Chinese Simplified (GB18030) */ + {57002, "x-iscii-de"}, /* ISCII Devanagari */ + {57003, "x-iscii-be"}, /* ISCII Bengali */ + {57004, "x-iscii-ta"}, /* ISCII Tamil */ + {57005, "x-iscii-te"}, /* ISCII Telugu */ + {57006, "x-iscii-as"}, /* ISCII Assamese */ + {57007, "x-iscii-or"}, /* ISCII Oriya */ + {57008, "x-iscii-ka"}, /* ISCII Kannada */ + {57009, "x-iscii-ma"}, /* ISCII Malayalam */ + {57010, "x-iscii-gu"}, /* ISCII Gujarati */ + {57011, "x-iscii-pa"}, /* ISCII Punjabi */ + + {0, NULL} +}; + +/* + * SJIS SHIFTJIS table CP932 table + * ---- --------------------------- -------------------------------- + * 5C U+00A5 YEN SIGN U+005C REVERSE SOLIDUS + * 7E U+203E OVERLINE U+007E TILDE + * 815C U+2014 EM DASH U+2015 HORIZONTAL BAR + * 815F U+005C REVERSE SOLIDUS U+FF3C FULLWIDTH REVERSE SOLIDUS + * 8160 U+301C WAVE DASH U+FF5E FULLWIDTH TILDE + * 8161 U+2016 DOUBLE VERTICAL LINE U+2225 PARALLEL TO + * 817C U+2212 MINUS SIGN U+FF0D FULLWIDTH HYPHEN-MINUS + * 8191 U+00A2 CENT SIGN U+FFE0 FULLWIDTH CENT SIGN + * 8192 U+00A3 POUND SIGN U+FFE1 FULLWIDTH POUND SIGN + * 81CA U+00AC NOT SIGN U+FFE2 FULLWIDTH NOT SIGN + * + * EUC-JP and ISO-2022-JP should be compatible with CP932. + * + * Kernel and MLang have different Unicode mapping table. Make sure + * which API is used. + */ +static compat_t cp932_compat[] = { + {0x00A5, 0x005C, COMPAT_OUT}, + {0x203E, 0x007E, COMPAT_OUT}, + {0x2014, 0x2015, COMPAT_OUT}, + {0x301C, 0xFF5E, COMPAT_OUT}, + {0x2016, 0x2225, COMPAT_OUT}, + {0x2212, 0xFF0D, COMPAT_OUT}, + {0x00A2, 0xFFE0, COMPAT_OUT}, + {0x00A3, 0xFFE1, COMPAT_OUT}, + {0x00AC, 0xFFE2, COMPAT_OUT}, + {0, 0, 0} +}; + +static compat_t cp20932_compat[] = { + {0x00A5, 0x005C, COMPAT_OUT}, + {0x203E, 0x007E, COMPAT_OUT}, + {0x2014, 0x2015, COMPAT_OUT}, + {0xFF5E, 0x301C, COMPAT_OUT|COMPAT_IN}, + {0x2225, 0x2016, COMPAT_OUT|COMPAT_IN}, + {0xFF0D, 0x2212, COMPAT_OUT|COMPAT_IN}, + {0xFFE0, 0x00A2, COMPAT_OUT|COMPAT_IN}, + {0xFFE1, 0x00A3, COMPAT_OUT|COMPAT_IN}, + {0xFFE2, 0x00AC, COMPAT_OUT|COMPAT_IN}, + {0, 0, 0} +}; + +static compat_t *cp51932_compat = cp932_compat; + +/* cp20932_compat for kernel. cp932_compat for mlang. */ +static compat_t *cp5022x_compat = cp932_compat; + +typedef HRESULT (WINAPI *CONVERTINETSTRING)( + LPDWORD lpdwMode, + DWORD dwSrcEncoding, + DWORD dwDstEncoding, + LPCSTR lpSrcStr, + LPINT lpnSrcSize, + LPBYTE lpDstStr, + LPINT lpnDstSize +); +typedef HRESULT (WINAPI *CONVERTINETMULTIBYTETOUNICODE)( + LPDWORD lpdwMode, + DWORD dwSrcEncoding, + LPCSTR lpSrcStr, + LPINT lpnMultiCharCount, + LPWSTR lpDstStr, + LPINT lpnWideCharCount +); +typedef HRESULT (WINAPI *CONVERTINETUNICODETOMULTIBYTE)( + LPDWORD lpdwMode, + DWORD dwEncoding, + LPCWSTR lpSrcStr, + LPINT lpnWideCharCount, + LPSTR lpDstStr, + LPINT lpnMultiCharCount +); +typedef HRESULT (WINAPI *ISCONVERTINETSTRINGAVAILABLE)( + DWORD dwSrcEncoding, + DWORD dwDstEncoding +); +typedef HRESULT (WINAPI *LCIDTORFC1766A)( + LCID Locale, + LPSTR pszRfc1766, + int nChar +); +typedef HRESULT (WINAPI *LCIDTORFC1766W)( + LCID Locale, + LPWSTR pszRfc1766, + int nChar +); +typedef HRESULT (WINAPI *RFC1766TOLCIDA)( + LCID *pLocale, + LPSTR pszRfc1766 +); +typedef HRESULT (WINAPI *RFC1766TOLCIDW)( + LCID *pLocale, + LPWSTR pszRfc1766 +); +static CONVERTINETSTRING ConvertINetString; +static CONVERTINETMULTIBYTETOUNICODE ConvertINetMultiByteToUnicode; +static CONVERTINETUNICODETOMULTIBYTE ConvertINetUnicodeToMultiByte; +static ISCONVERTINETSTRINGAVAILABLE IsConvertINetStringAvailable; +static LCIDTORFC1766A LcidToRfc1766A; +static RFC1766TOLCIDA Rfc1766ToLcidA; + +static int +load_mlang(void) +{ + HMODULE h; + if (ConvertINetString != NULL) + return TRUE; + h = LoadLibrary(TEXT("mlang.dll")); + if (!h) + return FALSE; + ConvertINetString = (CONVERTINETSTRING)GetProcAddressA(h, "ConvertINetString"); + ConvertINetMultiByteToUnicode = (CONVERTINETMULTIBYTETOUNICODE)GetProcAddressA(h, "ConvertINetMultiByteToUnicode"); + ConvertINetUnicodeToMultiByte = (CONVERTINETUNICODETOMULTIBYTE)GetProcAddressA(h, "ConvertINetUnicodeToMultiByte"); + IsConvertINetStringAvailable = (ISCONVERTINETSTRINGAVAILABLE)GetProcAddressA(h, "IsConvertINetStringAvailable"); + LcidToRfc1766A = (LCIDTORFC1766A)GetProcAddressA(h, "LcidToRfc1766A"); + Rfc1766ToLcidA = (RFC1766TOLCIDA)GetProcAddressA(h, "Rfc1766ToLcidA"); + return TRUE; +} + +iconv_t +iconv_open(const char *tocode, const char *fromcode) +{ + rec_iconv_t *cd; + + cd = (rec_iconv_t *)calloc(1, sizeof(rec_iconv_t)); + if (cd == NULL) + return (iconv_t)(-1); + +#if defined(USE_LIBICONV_DLL) + errno = 0; + if (libiconv_iconv_open(cd, tocode, fromcode)) + return (iconv_t)cd; +#endif + + /* reset the errno to prevent reporting wrong error code. + * 0 for unsorted error. */ + errno = 0; + if (win_iconv_open(cd, tocode, fromcode)) + return (iconv_t)cd; + + free(cd); + + return (iconv_t)(-1); +} + +int +iconv_close(iconv_t _cd) +{ + rec_iconv_t *cd = (rec_iconv_t *)_cd; + int r = cd->iconv_close(cd->cd); + int e = *(cd->_errno()); +#if defined(USE_LIBICONV_DLL) + if (cd->hlibiconv != NULL) + FreeLibrary(cd->hlibiconv); +#endif + free(cd); + errno = e; + return r; +} + +size_t +iconv(iconv_t _cd, const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft) +{ + rec_iconv_t *cd = (rec_iconv_t *)_cd; + size_t r = cd->iconv(cd->cd, inbuf, inbytesleft, outbuf, outbytesleft); + errno = *(cd->_errno()); + return r; +} + +static int +win_iconv_open(rec_iconv_t *cd, const char *tocode, const char *fromcode) +{ + if (!make_csconv(fromcode, &cd->from) || !make_csconv(tocode, &cd->to)) + return FALSE; + cd->iconv_close = win_iconv_close; + cd->iconv = win_iconv; + cd->_errno = _errno; + cd->cd = (iconv_t)cd; + return TRUE; +} + +static int +win_iconv_close(iconv_t cd UNUSED) +{ + return 0; +} + +static size_t +win_iconv(iconv_t _cd, const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft) +{ + rec_iconv_t *cd = (rec_iconv_t *)_cd; + ushort wbuf[MB_CHAR_MAX]; /* enough room for one character */ + int insize; + int outsize; + int wsize; + DWORD frommode; + DWORD tomode; + uint wc; + compat_t *cp; + int i; + + if (inbuf == NULL || *inbuf == NULL) + { + if (outbuf != NULL && *outbuf != NULL && cd->to.flush != NULL) + { + tomode = cd->to.mode; + outsize = cd->to.flush(&cd->to, (uchar *)*outbuf, (int)*outbytesleft); + if (outsize == -1) + { + if ((cd->to.flags & FLAG_IGNORE) && errno != E2BIG) + { + outsize = 0; + } + else + { + cd->to.mode = tomode; + return (size_t)(-1); + } + } + *outbuf += outsize; + *outbytesleft -= outsize; + } + cd->from.mode = 0; + cd->to.mode = 0; + return 0; + } + + while (*inbytesleft != 0) + { + frommode = cd->from.mode; + tomode = cd->to.mode; + wsize = MB_CHAR_MAX; + + insize = cd->from.mbtowc(&cd->from, (const uchar *)*inbuf, (int)*inbytesleft, wbuf, &wsize); + if (insize == -1) + { + if (cd->to.flags & FLAG_IGNORE) + { + cd->from.mode = frommode; + insize = 1; + wsize = 0; + } + else + { + cd->from.mode = frommode; + return (size_t)(-1); + } + } + + if (wsize == 0) + { + *inbuf += insize; + *inbytesleft -= insize; + continue; + } + + if (cd->from.compat != NULL) + { + wc = utf16_to_ucs4(wbuf); + cp = cd->from.compat; + for (i = 0; cp[i].in != 0; ++i) + { + if ((cp[i].flag & COMPAT_IN) && cp[i].out == wc) + { + ucs4_to_utf16(cp[i].in, wbuf, &wsize); + break; + } + } + } + + if (cd->to.compat != NULL) + { + wc = utf16_to_ucs4(wbuf); + cp = cd->to.compat; + for (i = 0; cp[i].in != 0; ++i) + { + if ((cp[i].flag & COMPAT_OUT) && cp[i].in == wc) + { + ucs4_to_utf16(cp[i].out, wbuf, &wsize); + break; + } + } + } + + outsize = cd->to.wctomb(&cd->to, wbuf, wsize, (uchar *)*outbuf, (int)*outbytesleft); + if (outsize == -1) + { + if ((cd->to.flags & FLAG_IGNORE) && errno != E2BIG) + { + cd->to.mode = tomode; + outsize = 0; + } + else + { + cd->from.mode = frommode; + cd->to.mode = tomode; + return (size_t)(-1); + } + } + + *inbuf += insize; + *outbuf += outsize; + *inbytesleft -= insize; + *outbytesleft -= outsize; + } + + return 0; +} + +static int +make_csconv(const char *_name, csconv_t *cv) +{ + CPINFO cpinfo; + int use_compat = TRUE; + int flag = 0; + char *name; + char *p; + + name = xstrndup(_name, strlen(_name)); + if (name == NULL) + return FALSE; + + /* check for option "enc_name//opt1//opt2" */ + while ((p = strrstr(name, "//")) != NULL) + { + if (_stricmp(p + 2, "nocompat") == 0) + use_compat = FALSE; + else if (_stricmp(p + 2, "translit") == 0) + flag |= FLAG_TRANSLIT; + else if (_stricmp(p + 2, "ignore") == 0) + flag |= FLAG_IGNORE; + *p = 0; + } + + cv->mode = 0; + cv->flags = flag; + cv->mblen = NULL; + cv->flush = NULL; + cv->compat = NULL; + cv->codepage = name_to_codepage(name); + if (cv->codepage == 1200 || cv->codepage == 1201) + { + cv->mbtowc = utf16_mbtowc; + cv->wctomb = utf16_wctomb; + if (_stricmp(name, "UTF-16") == 0 || _stricmp(name, "UTF16") == 0 || + _stricmp(name, "UCS-2") == 0 || _stricmp(name, "UCS2") == 0) + cv->flags |= FLAG_USE_BOM; + } + else if (cv->codepage == 12000 || cv->codepage == 12001) + { + cv->mbtowc = utf32_mbtowc; + cv->wctomb = utf32_wctomb; + if (_stricmp(name, "UTF-32") == 0 || _stricmp(name, "UTF32") == 0 || + _stricmp(name, "UCS-4") == 0 || _stricmp(name, "UCS4") == 0) + cv->flags |= FLAG_USE_BOM; + } + else if (cv->codepage == 65001) + { + cv->mbtowc = kernel_mbtowc; + cv->wctomb = kernel_wctomb; + cv->mblen = utf8_mblen; + } + else if ((cv->codepage == 50220 || cv->codepage == 50221 || cv->codepage == 50222) && load_mlang()) + { + cv->mbtowc = iso2022jp_mbtowc; + cv->wctomb = iso2022jp_wctomb; + cv->flush = iso2022jp_flush; + } + else if (cv->codepage == 51932 && load_mlang()) + { + cv->mbtowc = mlang_mbtowc; + cv->wctomb = mlang_wctomb; + cv->mblen = eucjp_mblen; + } + else if (IsValidCodePage(cv->codepage) + && GetCPInfo(cv->codepage, &cpinfo) != 0) + { + cv->mbtowc = kernel_mbtowc; + cv->wctomb = kernel_wctomb; + if (cpinfo.MaxCharSize == 1) + cv->mblen = sbcs_mblen; + else if (cpinfo.MaxCharSize == 2) + cv->mblen = dbcs_mblen; + else + cv->mblen = mbcs_mblen; + } + else + { + /* not supported */ + free(name); + errno = EINVAL; + return FALSE; + } + + if (use_compat) + { + switch (cv->codepage) + { + case 932: cv->compat = cp932_compat; break; + case 20932: cv->compat = cp20932_compat; break; + case 51932: cv->compat = cp51932_compat; break; + case 50220: case 50221: case 50222: cv->compat = cp5022x_compat; break; + } + } + + free(name); + + return TRUE; +} + +static int +name_to_codepage(const char *name) +{ + int i; + + if (*name == '\0' || + strcmp(name, "char") == 0) + return GetACP(); + else if (strcmp(name, "wchar_t") == 0) + return 1200; + else if (_strnicmp(name, "cp", 2) == 0) + return atoi(name + 2); /* CP123 */ + else if ('0' <= name[0] && name[0] <= '9') + return atoi(name); /* 123 */ + else if (_strnicmp(name, "xx", 2) == 0) + return atoi(name + 2); /* XX123 for debug */ + + for (i = 0; codepage_alias[i].name != NULL; ++i) + if (_stricmp(name, codepage_alias[i].name) == 0) + return codepage_alias[i].codepage; + return -1; +} + +/* + * http://www.faqs.org/rfcs/rfc2781.html + */ +static uint +utf16_to_ucs4(const ushort *wbuf) +{ + uint wc = wbuf[0]; + if (0xD800 <= wbuf[0] && wbuf[0] <= 0xDBFF) + wc = ((wbuf[0] & 0x3FF) << 10) + (wbuf[1] & 0x3FF) + 0x10000; + return wc; +} + +static void +ucs4_to_utf16(uint wc, ushort *wbuf, int *wbufsize) +{ + if (wc < 0x10000) + { + wbuf[0] = wc; + *wbufsize = 1; + } + else + { + wc -= 0x10000; + wbuf[0] = 0xD800 | ((wc >> 10) & 0x3FF); + wbuf[1] = 0xDC00 | (wc & 0x3FF); + *wbufsize = 2; + } +} + +/* + * Check if codepage is one of those for which the dwFlags parameter + * to MultiByteToWideChar() must be zero. Return zero or + * MB_ERR_INVALID_CHARS. The docs in Platform SDK for for Windows + * Server 2003 R2 claims that also codepage 65001 is one of these, but + * that doesn't seem to be the case. The MSDN docs for MSVS2008 leave + * out 65001 (UTF-8), and that indeed seems to be the case on XP, it + * works fine to pass MB_ERR_INVALID_CHARS in dwFlags when converting + * from UTF-8. + */ +static int +mbtowc_flags(int codepage) +{ + return (codepage == 50220 || codepage == 50221 || + codepage == 50222 || codepage == 50225 || + codepage == 50227 || codepage == 50229 || + codepage == 52936 || codepage == 54936 || + (codepage >= 57002 && codepage <= 57011) || + codepage == 65000 || codepage == 42) ? 0 : MB_ERR_INVALID_CHARS; +} + +/* + * Check if codepage is one those for which the lpUsedDefaultChar + * parameter to WideCharToMultiByte() must be NULL. The docs in + * Platform SDK for for Windows Server 2003 R2 claims that this is the + * list below, while the MSDN docs for MSVS2008 claim that it is only + * for 65000 (UTF-7) and 65001 (UTF-8). This time the earlier Platform + * SDK seems to be correct, at least for XP. + */ +static int +must_use_null_useddefaultchar(int codepage) +{ + return (codepage == 65000 || codepage == 65001 || + codepage == 50220 || codepage == 50221 || + codepage == 50222 || codepage == 50225 || + codepage == 50227 || codepage == 50229 || + codepage == 52936 || codepage == 54936 || + (codepage >= 57002 && codepage <= 57011) || + codepage == 42); +} + +static char * +strrstr(const char *str, const char *token) +{ + size_t len = strlen(token); + const char *p = str + strlen(str); + + while (str <= --p) + if (p[0] == token[0] && strncmp(p, token, len) == 0) + return (char *)p; + return NULL; +} + +static char * +xstrndup(const char *s, size_t n) +{ + char *p; + + p = (char *)malloc(n + 1); + if (p == NULL) + return NULL; + memcpy(p, s, n); + p[n] = '\0'; + return p; +} + +static int +seterror(int err) +{ + errno = err; + return -1; +} + +#if defined(USE_LIBICONV_DLL) +static int +libiconv_iconv_open(rec_iconv_t *cd, const char *tocode, const char *fromcode) +{ + HMODULE hlibiconv = NULL; + HMODULE hmsvcrt = NULL; + char *dllname; + const char *p; + const char *e; + f_iconv_open _iconv_open; + + /* + * always try to load dll, so that we can switch dll in runtime. + */ + + /* XXX: getenv() can't get variable set by SetEnvironmentVariable() */ + p = getenv("WINICONV_LIBICONV_DLL"); + if (p == NULL) + p = DEFAULT_LIBICONV_DLL; + /* parse comma separated value */ + for ( ; *p != 0; p = (*e == ',') ? e + 1 : e) + { + e = strchr(p, ','); + if (p == e) + continue; + else if (e == NULL) + e = p + strlen(p); + dllname = xstrndup(p, e - p); + if (dllname == NULL) + return FALSE; + hlibiconv = LoadLibraryA(dllname); + free(dllname); + if (hlibiconv != NULL) + { + if (hlibiconv == hwiniconv) + { + FreeLibrary(hlibiconv); + hlibiconv = NULL; + continue; + } + break; + } + } + + if (hlibiconv == NULL) + goto failed; + + hmsvcrt = find_imported_module_by_funcname(hlibiconv, "_errno"); + if (hmsvcrt == NULL) + goto failed; + + _iconv_open = (f_iconv_open)GetProcAddressA(hlibiconv, "libiconv_open"); + if (_iconv_open == NULL) + _iconv_open = (f_iconv_open)GetProcAddressA(hlibiconv, "iconv_open"); + cd->iconv_close = (f_iconv_close)GetProcAddressA(hlibiconv, "libiconv_close"); + if (cd->iconv_close == NULL) + cd->iconv_close = (f_iconv_close)GetProcAddressA(hlibiconv, "iconv_close"); + cd->iconv = (f_iconv)GetProcAddressA(hlibiconv, "libiconv"); + if (cd->iconv == NULL) + cd->iconv = (f_iconv)GetProcAddressA(hlibiconv, "iconv"); + cd->_errno = (f_errno)GetProcAddressA(hmsvcrt, "_errno"); + if (_iconv_open == NULL || cd->iconv_close == NULL + || cd->iconv == NULL || cd->_errno == NULL) + goto failed; + + cd->cd = _iconv_open(tocode, fromcode); + if (cd->cd == (iconv_t)(-1)) + goto failed; + + cd->hlibiconv = hlibiconv; + return TRUE; + +failed: + if (hlibiconv != NULL) + FreeLibrary(hlibiconv); + /* do not free hmsvcrt which is obtained by GetModuleHandle() */ + return FALSE; +} + +/* + * Reference: + * http://forums.belution.com/ja/vc/000/234/78s.shtml + * http://nienie.com/~masapico/api_ImageDirectoryEntryToData.html + * + * The formal way is + * imagehlp.h or dbghelp.h + * imagehlp.lib or dbghelp.lib + * ImageDirectoryEntryToData() + */ +#define TO_DOS_HEADER(base) ((PIMAGE_DOS_HEADER)(base)) +#define TO_NT_HEADERS(base) ((PIMAGE_NT_HEADERS)((LPBYTE)(base) + TO_DOS_HEADER(base)->e_lfanew)) +static PVOID +MyImageDirectoryEntryToData(LPVOID Base, BOOLEAN MappedAsImage, USHORT DirectoryEntry, PULONG Size) +{ + /* TODO: MappedAsImage? */ + PIMAGE_DATA_DIRECTORY p; + p = TO_NT_HEADERS(Base)->OptionalHeader.DataDirectory + DirectoryEntry; + if (p->VirtualAddress == 0) { + *Size = 0; + return NULL; + } + *Size = p->Size; + return (PVOID)((LPBYTE)Base + p->VirtualAddress); +} + +static HMODULE +find_imported_module_by_funcname(HMODULE hModule, const char *funcname) +{ + DWORD_PTR Base; + ULONG Size; + PIMAGE_IMPORT_DESCRIPTOR Imp; + PIMAGE_THUNK_DATA Name; /* Import Name Table */ + PIMAGE_IMPORT_BY_NAME ImpName; + + Base = (DWORD_PTR)hModule; + Imp = (PIMAGE_IMPORT_DESCRIPTOR)MyImageDirectoryEntryToData( + (LPVOID)Base, + TRUE, + IMAGE_DIRECTORY_ENTRY_IMPORT, + &Size); + if (Imp == NULL) + return NULL; + for ( ; Imp->OriginalFirstThunk != 0; ++Imp) + { + Name = (PIMAGE_THUNK_DATA)(Base + Imp->OriginalFirstThunk); + for ( ; Name->u1.Ordinal != 0; ++Name) + { + if (!IMAGE_SNAP_BY_ORDINAL(Name->u1.Ordinal)) + { + ImpName = (PIMAGE_IMPORT_BY_NAME) + (Base + (DWORD_PTR)Name->u1.AddressOfData); + if (strcmp((char *)ImpName->Name, funcname) == 0) + return GetModuleHandleA((char *)(Base + Imp->Name)); + } + } + } + return NULL; +} +#endif + +static int +sbcs_mblen(csconv_t *cv UNUSED, const uchar *buf UNUSED, int bufsize UNUSED) +{ + return 1; +} + +static int +dbcs_mblen(csconv_t *cv, const uchar *buf, int bufsize) +{ + int len = IsDBCSLeadByteEx(cv->codepage, buf[0]) ? 2 : 1; + if (bufsize < len) + return seterror(EINVAL); + return len; +} + +static int +mbcs_mblen(csconv_t *cv, const uchar *buf, int bufsize) +{ + int len = 0; + + if (cv->codepage == 54936) { + if (buf[0] <= 0x7F) len = 1; + else if (buf[0] >= 0x81 && buf[0] <= 0xFE && + bufsize >= 2 && + ((buf[1] >= 0x40 && buf[1] <= 0x7E) || + (buf[1] >= 0x80 && buf[1] <= 0xFE))) len = 2; + else if (buf[0] >= 0x81 && buf[0] <= 0xFE && + bufsize >= 4 && + buf[1] >= 0x30 && buf[1] <= 0x39) len = 4; + else + return seterror(EINVAL); + return len; + } + else + return seterror(EINVAL); +} + +static int +utf8_mblen(csconv_t *cv UNUSED, const uchar *buf, int bufsize) +{ + int len = 0; + + if (buf[0] < 0x80) len = 1; + else if ((buf[0] & 0xE0) == 0xC0) len = 2; + else if ((buf[0] & 0xF0) == 0xE0) len = 3; + else if ((buf[0] & 0xF8) == 0xF0) len = 4; + else if ((buf[0] & 0xFC) == 0xF8) len = 5; + else if ((buf[0] & 0xFE) == 0xFC) len = 6; + + if (len == 0) + return seterror(EILSEQ); + else if (bufsize < len) + return seterror(EINVAL); + return len; +} + +static int +eucjp_mblen(csconv_t *cv UNUSED, const uchar *buf, int bufsize) +{ + if (buf[0] < 0x80) /* ASCII */ + return 1; + else if (buf[0] == 0x8E) /* JIS X 0201 */ + { + if (bufsize < 2) + return seterror(EINVAL); + else if (!(0xA1 <= buf[1] && buf[1] <= 0xDF)) + return seterror(EILSEQ); + return 2; + } + else if (buf[0] == 0x8F) /* JIS X 0212 */ + { + if (bufsize < 3) + return seterror(EINVAL); + else if (!(0xA1 <= buf[1] && buf[1] <= 0xFE) + || !(0xA1 <= buf[2] && buf[2] <= 0xFE)) + return seterror(EILSEQ); + return 3; + } + else /* JIS X 0208 */ + { + if (bufsize < 2) + return seterror(EINVAL); + else if (!(0xA1 <= buf[0] && buf[0] <= 0xFE) + || !(0xA1 <= buf[1] && buf[1] <= 0xFE)) + return seterror(EILSEQ); + return 2; + } +} + +static int +kernel_mbtowc(csconv_t *cv, const uchar *buf, int bufsize, ushort *wbuf, int *wbufsize) +{ + int len; + + len = cv->mblen(cv, buf, bufsize); + if (len == -1) + return -1; + *wbufsize = MultiByteToWideChar(cv->codepage, mbtowc_flags (cv->codepage), + (const char *)buf, len, (wchar_t *)wbuf, *wbufsize); + if (*wbufsize == 0) + return seterror(EILSEQ); + return len; +} + +static int +kernel_wctomb(csconv_t *cv, ushort *wbuf, int wbufsize, uchar *buf, int bufsize) +{ + BOOL usedDefaultChar = 0; + BOOL *p = NULL; + int flags = 0; + int len; + + if (bufsize == 0) + return seterror(E2BIG); + if (!must_use_null_useddefaultchar(cv->codepage)) + { + p = &usedDefaultChar; +#ifdef WC_NO_BEST_FIT_CHARS + if (!(cv->flags & FLAG_TRANSLIT)) + flags |= WC_NO_BEST_FIT_CHARS; +#endif + } + len = WideCharToMultiByte(cv->codepage, flags, + (const wchar_t *)wbuf, wbufsize, (char *)buf, bufsize, NULL, p); + if (len == 0) + { + if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) + return seterror(E2BIG); + return seterror(EILSEQ); + } + else if (usedDefaultChar && !(cv->flags & FLAG_TRANSLIT)) + return seterror(EILSEQ); + else if (cv->mblen(cv, buf, len) != len) /* validate result */ + return seterror(EILSEQ); + return len; +} + +/* + * It seems that the mode (cv->mode) is fixnum. + * For example, when converting iso-2022-jp(cp50221) to unicode: + * in ascii sequence: mode=0xC42C0000 + * in jisx0208 sequence: mode=0xC42C0001 + * "C42C" is same for each convert session. + * It should be: ((codepage-1)<<16)|state + */ +static int +mlang_mbtowc(csconv_t *cv, const uchar *buf, int bufsize, ushort *wbuf, int *wbufsize) +{ + int len; + int insize; + HRESULT hr; + + len = cv->mblen(cv, buf, bufsize); + if (len == -1) + return -1; + insize = len; + hr = ConvertINetMultiByteToUnicode(&cv->mode, cv->codepage, + (const char *)buf, &insize, (wchar_t *)wbuf, wbufsize); + if (hr != S_OK || insize != len) + return seterror(EILSEQ); + return len; +} + +static int +mlang_wctomb(csconv_t *cv, ushort *wbuf, int wbufsize, uchar *buf, int bufsize) +{ + char tmpbuf[MB_CHAR_MAX]; /* enough room for one character */ + int tmpsize = MB_CHAR_MAX; + int insize = wbufsize; + HRESULT hr; + + hr = ConvertINetUnicodeToMultiByte(&cv->mode, cv->codepage, + (const wchar_t *)wbuf, &wbufsize, tmpbuf, &tmpsize); + if (hr != S_OK || insize != wbufsize) + return seterror(EILSEQ); + else if (bufsize < tmpsize) + return seterror(E2BIG); + else if (cv->mblen(cv, (uchar *)tmpbuf, tmpsize) != tmpsize) + return seterror(EILSEQ); + memcpy(buf, tmpbuf, tmpsize); + return tmpsize; +} + +static int +utf16_mbtowc(csconv_t *cv, const uchar *buf, int bufsize, ushort *wbuf, int *wbufsize) +{ + int codepage = cv->codepage; + + /* swap endian: 1200 <-> 1201 */ + if (cv->mode & UNICODE_MODE_SWAPPED) + codepage ^= 1; + + if (bufsize < 2) + return seterror(EINVAL); + if (codepage == 1200) /* little endian */ + wbuf[0] = (buf[1] << 8) | buf[0]; + else if (codepage == 1201) /* big endian */ + wbuf[0] = (buf[0] << 8) | buf[1]; + + if ((cv->flags & FLAG_USE_BOM) && !(cv->mode & UNICODE_MODE_BOM_DONE)) + { + cv->mode |= UNICODE_MODE_BOM_DONE; + if (wbuf[0] == 0xFFFE) + { + cv->mode |= UNICODE_MODE_SWAPPED; + *wbufsize = 0; + return 2; + } + else if (wbuf[0] == 0xFEFF) + { + *wbufsize = 0; + return 2; + } + } + + if (0xDC00 <= wbuf[0] && wbuf[0] <= 0xDFFF) + return seterror(EILSEQ); + if (0xD800 <= wbuf[0] && wbuf[0] <= 0xDBFF) + { + if (bufsize < 4) + return seterror(EINVAL); + if (codepage == 1200) /* little endian */ + wbuf[1] = (buf[3] << 8) | buf[2]; + else if (codepage == 1201) /* big endian */ + wbuf[1] = (buf[2] << 8) | buf[3]; + if (!(0xDC00 <= wbuf[1] && wbuf[1] <= 0xDFFF)) + return seterror(EILSEQ); + *wbufsize = 2; + return 4; + } + *wbufsize = 1; + return 2; +} + +static int +utf16_wctomb(csconv_t *cv, ushort *wbuf, int wbufsize, uchar *buf, int bufsize) +{ + if ((cv->flags & FLAG_USE_BOM) && !(cv->mode & UNICODE_MODE_BOM_DONE)) + { + int r; + + cv->mode |= UNICODE_MODE_BOM_DONE; + if (bufsize < 2) + return seterror(E2BIG); + if (cv->codepage == 1200) /* little endian */ + memcpy(buf, "\xFF\xFE", 2); + else if (cv->codepage == 1201) /* big endian */ + memcpy(buf, "\xFE\xFF", 2); + + r = utf16_wctomb(cv, wbuf, wbufsize, buf + 2, bufsize - 2); + if (r == -1) + return -1; + return r + 2; + } + + if (bufsize < 2) + return seterror(E2BIG); + if (cv->codepage == 1200) /* little endian */ + { + buf[0] = (wbuf[0] & 0x00FF); + buf[1] = (wbuf[0] & 0xFF00) >> 8; + } + else if (cv->codepage == 1201) /* big endian */ + { + buf[0] = (wbuf[0] & 0xFF00) >> 8; + buf[1] = (wbuf[0] & 0x00FF); + } + if (0xD800 <= wbuf[0] && wbuf[0] <= 0xDBFF) + { + if (bufsize < 4) + return seterror(E2BIG); + if (cv->codepage == 1200) /* little endian */ + { + buf[2] = (wbuf[1] & 0x00FF); + buf[3] = (wbuf[1] & 0xFF00) >> 8; + } + else if (cv->codepage == 1201) /* big endian */ + { + buf[2] = (wbuf[1] & 0xFF00) >> 8; + buf[3] = (wbuf[1] & 0x00FF); + } + return 4; + } + return 2; +} + +static int +utf32_mbtowc(csconv_t *cv, const uchar *buf, int bufsize, ushort *wbuf, int *wbufsize) +{ + int codepage = cv->codepage; + uint wc; + + /* swap endian: 12000 <-> 12001 */ + if (cv->mode & UNICODE_MODE_SWAPPED) + codepage ^= 1; + + if (bufsize < 4) + return seterror(EINVAL); + if (codepage == 12000) /* little endian */ + wc = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0]; + else if (codepage == 12001) /* big endian */ + wc = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]; + + if ((cv->flags & FLAG_USE_BOM) && !(cv->mode & UNICODE_MODE_BOM_DONE)) + { + cv->mode |= UNICODE_MODE_BOM_DONE; + if (wc == 0xFFFE0000) + { + cv->mode |= UNICODE_MODE_SWAPPED; + *wbufsize = 0; + return 4; + } + else if (wc == 0x0000FEFF) + { + *wbufsize = 0; + return 4; + } + } + + if ((0xD800 <= wc && wc <= 0xDFFF) || 0x10FFFF < wc) + return seterror(EILSEQ); + ucs4_to_utf16(wc, wbuf, wbufsize); + return 4; +} + +static int +utf32_wctomb(csconv_t *cv, ushort *wbuf, int wbufsize, uchar *buf, int bufsize) +{ + uint wc; + + if ((cv->flags & FLAG_USE_BOM) && !(cv->mode & UNICODE_MODE_BOM_DONE)) + { + int r; + + cv->mode |= UNICODE_MODE_BOM_DONE; + if (bufsize < 4) + return seterror(E2BIG); + if (cv->codepage == 12000) /* little endian */ + memcpy(buf, "\xFF\xFE\x00\x00", 4); + else if (cv->codepage == 12001) /* big endian */ + memcpy(buf, "\x00\x00\xFE\xFF", 4); + + r = utf32_wctomb(cv, wbuf, wbufsize, buf + 4, bufsize - 4); + if (r == -1) + return -1; + return r + 4; + } + + if (bufsize < 4) + return seterror(E2BIG); + wc = utf16_to_ucs4(wbuf); + if (cv->codepage == 12000) /* little endian */ + { + buf[0] = wc & 0x000000FF; + buf[1] = (wc & 0x0000FF00) >> 8; + buf[2] = (wc & 0x00FF0000) >> 16; + buf[3] = (wc & 0xFF000000) >> 24; + } + else if (cv->codepage == 12001) /* big endian */ + { + buf[0] = (wc & 0xFF000000) >> 24; + buf[1] = (wc & 0x00FF0000) >> 16; + buf[2] = (wc & 0x0000FF00) >> 8; + buf[3] = wc & 0x000000FF; + } + return 4; +} + +/* + * 50220: ISO 2022 Japanese with no halfwidth Katakana; Japanese (JIS) + * 50221: ISO 2022 Japanese with halfwidth Katakana; Japanese (JIS-Allow + * 1 byte Kana) + * 50222: ISO 2022 Japanese JIS X 0201-1989; Japanese (JIS-Allow 1 byte + * Kana - SO/SI) + * + * MultiByteToWideChar() and WideCharToMultiByte() behave differently + * depending on Windows version. On XP, WideCharToMultiByte() doesn't + * terminate result sequence with ascii escape. But Vista does. + * Use MLang instead. + */ + +#define ISO2022_MODE(cs, shift) (((cs) << 8) | (shift)) +#define ISO2022_MODE_CS(mode) (((mode) >> 8) & 0xFF) +#define ISO2022_MODE_SHIFT(mode) ((mode) & 0xFF) + +#define ISO2022_SI 0 +#define ISO2022_SO 1 + +/* shift in */ +static const char iso2022_SI_seq[] = "\x0F"; +/* shift out */ +static const char iso2022_SO_seq[] = "\x0E"; + +typedef struct iso2022_esc_t iso2022_esc_t; +struct iso2022_esc_t { + const char *esc; + int esc_len; + int len; + int cs; +}; + +#define ISO2022JP_CS_ASCII 0 +#define ISO2022JP_CS_JISX0201_ROMAN 1 +#define ISO2022JP_CS_JISX0201_KANA 2 +#define ISO2022JP_CS_JISX0208_1978 3 +#define ISO2022JP_CS_JISX0208_1983 4 +#define ISO2022JP_CS_JISX0212 5 + +static iso2022_esc_t iso2022jp_esc[] = { + {"\x1B\x28\x42", 3, 1, ISO2022JP_CS_ASCII}, + {"\x1B\x28\x4A", 3, 1, ISO2022JP_CS_JISX0201_ROMAN}, + {"\x1B\x28\x49", 3, 1, ISO2022JP_CS_JISX0201_KANA}, + {"\x1B\x24\x40", 3, 2, ISO2022JP_CS_JISX0208_1983}, /* unify 1978 with 1983 */ + {"\x1B\x24\x42", 3, 2, ISO2022JP_CS_JISX0208_1983}, + {"\x1B\x24\x28\x44", 4, 2, ISO2022JP_CS_JISX0212}, + {NULL, 0, 0, 0} +}; + +static int +iso2022jp_mbtowc(csconv_t *cv, const uchar *buf, int bufsize, ushort *wbuf, int *wbufsize) +{ + iso2022_esc_t *iesc = iso2022jp_esc; + char tmp[MB_CHAR_MAX]; + int insize; + HRESULT hr; + DWORD dummy = 0; + int len; + int esc_len; + int cs; + int shift; + int i; + + if (buf[0] == 0x1B) + { + for (i = 0; iesc[i].esc != NULL; ++i) + { + esc_len = iesc[i].esc_len; + if (bufsize < esc_len) + { + if (strncmp((char *)buf, iesc[i].esc, bufsize) == 0) + return seterror(EINVAL); + } + else + { + if (strncmp((char *)buf, iesc[i].esc, esc_len) == 0) + { + cv->mode = ISO2022_MODE(iesc[i].cs, ISO2022_SI); + *wbufsize = 0; + return esc_len; + } + } + } + /* not supported escape sequence */ + return seterror(EILSEQ); + } + else if (buf[0] == iso2022_SO_seq[0]) + { + cv->mode = ISO2022_MODE(ISO2022_MODE_CS(cv->mode), ISO2022_SO); + *wbufsize = 0; + return 1; + } + else if (buf[0] == iso2022_SI_seq[0]) + { + cv->mode = ISO2022_MODE(ISO2022_MODE_CS(cv->mode), ISO2022_SI); + *wbufsize = 0; + return 1; + } + + cs = ISO2022_MODE_CS(cv->mode); + shift = ISO2022_MODE_SHIFT(cv->mode); + + /* reset the mode for informal sequence */ + if (buf[0] < 0x20) + { + cs = ISO2022JP_CS_ASCII; + shift = ISO2022_SI; + } + + len = iesc[cs].len; + if (bufsize < len) + return seterror(EINVAL); + for (i = 0; i < len; ++i) + if (!(buf[i] < 0x80)) + return seterror(EILSEQ); + esc_len = iesc[cs].esc_len; + memcpy(tmp, iesc[cs].esc, esc_len); + if (shift == ISO2022_SO) + { + memcpy(tmp + esc_len, iso2022_SO_seq, 1); + esc_len += 1; + } + memcpy(tmp + esc_len, buf, len); + + if ((cv->codepage == 50220 || cv->codepage == 50221 + || cv->codepage == 50222) && shift == ISO2022_SO) + { + /* XXX: shift-out cannot be used for mbtowc (both kernel and + * mlang) */ + esc_len = iesc[ISO2022JP_CS_JISX0201_KANA].esc_len; + memcpy(tmp, iesc[ISO2022JP_CS_JISX0201_KANA].esc, esc_len); + memcpy(tmp + esc_len, buf, len); + } + + insize = len + esc_len; + hr = ConvertINetMultiByteToUnicode(&dummy, cv->codepage, + (const char *)tmp, &insize, (wchar_t *)wbuf, wbufsize); + if (hr != S_OK || insize != len + esc_len) + return seterror(EILSEQ); + + /* Check for conversion error. Assuming defaultChar is 0x3F. */ + /* ascii should be converted from ascii */ + if (wbuf[0] == buf[0] + && cv->mode != ISO2022_MODE(ISO2022JP_CS_ASCII, ISO2022_SI)) + return seterror(EILSEQ); + + /* reset the mode for informal sequence */ + if (cv->mode != (DWORD)ISO2022_MODE(cs, shift)) + cv->mode = (DWORD)ISO2022_MODE(cs, shift); + + return len; +} + +static int +iso2022jp_wctomb(csconv_t *cv, ushort *wbuf, int wbufsize, uchar *buf, int bufsize) +{ + iso2022_esc_t *iesc = iso2022jp_esc; + char tmp[MB_CHAR_MAX]; + int tmpsize = MB_CHAR_MAX; + int insize = wbufsize; + HRESULT hr; + DWORD dummy = 0; + int len; + int esc_len; + int cs; + int shift; + int i; + + /* + * MultiByte = [escape sequence] + character + [escape sequence] + * + * Whether trailing escape sequence is added depends on which API is + * used (kernel or MLang, and its version). + */ + hr = ConvertINetUnicodeToMultiByte(&dummy, cv->codepage, + (const wchar_t *)wbuf, &wbufsize, tmp, &tmpsize); + if (hr != S_OK || insize != wbufsize) + return seterror(EILSEQ); + else if (bufsize < tmpsize) + return seterror(E2BIG); + + if (tmpsize == 1) + { + cs = ISO2022JP_CS_ASCII; + esc_len = 0; + } + else + { + for (i = 1; iesc[i].esc != NULL; ++i) + { + esc_len = iesc[i].esc_len; + if (strncmp(tmp, iesc[i].esc, esc_len) == 0) + { + cs = iesc[i].cs; + break; + } + } + if (iesc[i].esc == NULL) + /* not supported escape sequence */ + return seterror(EILSEQ); + } + + shift = ISO2022_SI; + if (tmp[esc_len] == iso2022_SO_seq[0]) + { + shift = ISO2022_SO; + esc_len += 1; + } + + len = iesc[cs].len; + + /* Check for converting error. Assuming defaultChar is 0x3F. */ + /* ascii should be converted from ascii */ + if (cs == ISO2022JP_CS_ASCII && !(wbuf[0] < 0x80)) + return seterror(EILSEQ); + else if (tmpsize < esc_len + len) + return seterror(EILSEQ); + + if (cv->mode == ISO2022_MODE(cs, shift)) + { + /* remove escape sequence */ + if (esc_len != 0) + memmove(tmp, tmp + esc_len, len); + esc_len = 0; + } + else + { + if (cs == ISO2022JP_CS_ASCII) + { + esc_len = iesc[ISO2022JP_CS_ASCII].esc_len; + memmove(tmp + esc_len, tmp, len); + memcpy(tmp, iesc[ISO2022JP_CS_ASCII].esc, esc_len); + } + if (ISO2022_MODE_SHIFT(cv->mode) == ISO2022_SO) + { + /* shift-in before changing to other mode */ + memmove(tmp + 1, tmp, len + esc_len); + memcpy(tmp, iso2022_SI_seq, 1); + esc_len += 1; + } + } + + if (bufsize < len + esc_len) + return seterror(E2BIG); + memcpy(buf, tmp, len + esc_len); + cv->mode = ISO2022_MODE(cs, shift); + return len + esc_len; +} + +static int +iso2022jp_flush(csconv_t *cv, uchar *buf, int bufsize) +{ + iso2022_esc_t *iesc = iso2022jp_esc; + int esc_len; + + if (cv->mode != ISO2022_MODE(ISO2022JP_CS_ASCII, ISO2022_SI)) + { + esc_len = 0; + if (ISO2022_MODE_SHIFT(cv->mode) != ISO2022_SI) + esc_len += 1; + if (ISO2022_MODE_CS(cv->mode) != ISO2022JP_CS_ASCII) + esc_len += iesc[ISO2022JP_CS_ASCII].esc_len; + if (bufsize < esc_len) + return seterror(E2BIG); + + esc_len = 0; + if (ISO2022_MODE_SHIFT(cv->mode) != ISO2022_SI) + { + memcpy(buf, iso2022_SI_seq, 1); + esc_len += 1; + } + if (ISO2022_MODE_CS(cv->mode) != ISO2022JP_CS_ASCII) + { + memcpy(buf + esc_len, iesc[ISO2022JP_CS_ASCII].esc, + iesc[ISO2022JP_CS_ASCII].esc_len); + esc_len += iesc[ISO2022JP_CS_ASCII].esc_len; + } + return esc_len; + } + return 0; +} + +#if defined(MAKE_DLL) && defined(USE_LIBICONV_DLL) +BOOL WINAPI +DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved) +{ + switch( fdwReason ) + { + case DLL_PROCESS_ATTACH: + hwiniconv = (HMODULE)hinstDLL; + break; + case DLL_THREAD_ATTACH: + case DLL_THREAD_DETACH: + case DLL_PROCESS_DETACH: + break; + } + return TRUE; +} +#endif + +#if defined(MAKE_EXE) +#include +#include +#include +int +main(int argc, char **argv) +{ + char *fromcode = NULL; + char *tocode = NULL; + int i; + char inbuf[BUFSIZ]; + char outbuf[BUFSIZ]; + char *pin; + char *pout; + size_t inbytesleft; + size_t outbytesleft; + size_t rest = 0; + iconv_t cd; + size_t r; + FILE *in = stdin; + FILE *out = stdout; + int ignore = 0; + char *p; + + _setmode(_fileno(stdin), _O_BINARY); + _setmode(_fileno(stdout), _O_BINARY); + + for (i = 1; i < argc; ++i) + { + if (strcmp(argv[i], "-l") == 0) + { + for (i = 0; codepage_alias[i].name != NULL; ++i) + printf("%s\n", codepage_alias[i].name); + return 0; + } + + if (strcmp(argv[i], "-f") == 0) + fromcode = argv[++i]; + else if (strcmp(argv[i], "-t") == 0) + tocode = argv[++i]; + else if (strcmp(argv[i], "-c") == 0) + ignore = 1; + else if (strcmp(argv[i], "--output") == 0) + { + out = fopen(argv[++i], "wb"); + if(out == NULL) + { + fprintf(stderr, "cannot open %s\n", argv[i]); + return 1; + } + } + else + { + in = fopen(argv[i], "rb"); + if (in == NULL) + { + fprintf(stderr, "cannot open %s\n", argv[i]); + return 1; + } + break; + } + } + + if (fromcode == NULL || tocode == NULL) + { + printf("usage: %s [-c] -f from-enc -t to-enc [file]\n", argv[0]); + return 0; + } + + if (ignore) + { + p = tocode; + tocode = (char *)malloc(strlen(p) + strlen("//IGNORE") + 1); + if (tocode == NULL) + { + perror("fatal error"); + return 1; + } + strcpy(tocode, p); + strcat(tocode, "//IGNORE"); + } + + cd = iconv_open(tocode, fromcode); + if (cd == (iconv_t)(-1)) + { + perror("iconv_open error"); + return 1; + } + + while ((inbytesleft = fread(inbuf + rest, 1, sizeof(inbuf) - rest, in)) != 0 + || rest != 0) + { + inbytesleft += rest; + pin = inbuf; + pout = outbuf; + outbytesleft = sizeof(outbuf); + r = iconv(cd, &pin, &inbytesleft, &pout, &outbytesleft); + fwrite(outbuf, 1, sizeof(outbuf) - outbytesleft, out); + if (r == (size_t)(-1) && errno != E2BIG && (errno != EINVAL || feof(in))) + { + perror("conversion error"); + return 1; + } + memmove(inbuf, pin, inbytesleft); + rest = inbytesleft; + } + pout = outbuf; + outbytesleft = sizeof(outbuf); + r = iconv(cd, NULL, NULL, &pout, &outbytesleft); + fwrite(outbuf, 1, sizeof(outbuf) - outbytesleft, out); + if (r == (size_t)(-1)) + { + perror("conversion error"); + return 1; + } + + iconv_close(cd); + + return 0; +} +#endif + diff --git a/vendor/MDBC/win/packaging/CMakeLists.txt b/vendor/MDBC/win/packaging/CMakeLists.txt new file mode 100644 index 00000000..df72db43 --- /dev/null +++ b/vendor/MDBC/win/packaging/CMakeLists.txt @@ -0,0 +1,105 @@ +SET(CLIENT_LIB_DIR ${CC_BINARY_DIR}/libmariadb/${CMAKE_BUILD_TYPE}) +SET(CLIENT_BIN_DIR ${CC_BINARY_DIR}/client/${CMAKE_BUILD_TYPE}) +SET(CLIENT_DBG_DIR ${CC_BINARY_DIR}/libmariadb/Debug) +SET(CLIENT_INC_DIR ${CC_SOURCE_DIR}/include) + +SET(PRODUCT_NAME "MariaDB Connector C") +SET(PRODUCT_INSTALL_DIR "MariaDB") +SET(PRODUCT_MANUFACTURER "MariaDB Corporation") +SET(PRODUCT_VERSION "${CPACK_PACKAGE_VERSION}") + +IF (${CMAKE_SIZEOF_VOID_P} EQUAL 8) + SET(PRODUCT_NAME "${PRODUCT_NAME} 64-bit") + SET(PLATFORM "win64") + SET(IS_WIN64 "yes") + SET(WIXPLATFORM "x64") + SET(PRODUCT_UPGRADE_CODE "4E630B8C-4645-416D-A561-45D88E7BDCF1") + SET(FOLDER "ProgramFiles64Folder") +ELSE() + SET(PLATFORM "win32") + SET(IS_WIN64 "no") + SET(WIXPLATFORM "x86") + SET(PRODUCT_UPGRADE_CODE "FCBC4419-07C8-4595-9803-DFD602A84F29") + SET(FOLDER "ProgramFilesFolder") +ENDIF() + +# +# process dynamic plugins +# +FOREACH(plugin ${PLUGINS_DYNAMIC}) + SET(TARGET ${plugin}) + # Get dependencies + SET(DYNAMIC_TARGETS ${DYNAMIC_TARGETS} ${TARGET}) + SET(FILE ${CC_BINARY_DIR}/${CMAKE_BUILD_TYPE}/${TARGET}.dll) + SET(PDB ${CC_BINARY_DIR}/${CMAKE_BUILD_TYPE}/${TARGET}.pdb) + MESSAGE(STATUS "Location for ${TARGET}: ${FILE}") + # build file list + STRING(REPLACE "$(Configuration)" "RelWithDebInfo" FILE ${FILE}) + SET(MARIADB_PLUGINS "${MARIADB_PLUGINS} \n") + SET(MARIADB_PLUGINS "${MARIADB_PLUGINS} \n") +ENDFOREACH() + +FOREACH(src ${WIX_INCLUDES}) + STRING(REPLACE "${CC_SOURCE_DIR}/include/" "" src ${src}) + # check binary dir + STRING(REPLACE "${CC_BINARY_DIR}/include/" "" chgbin ${src}) + IF (${chgbin} STREQUAL ${src}) + SET(SRC_DIR ${CC_SOURCE_DIR}) + ELSE() + SET(SRC_DIR ${CC_BINARY_DIR}) + STRING(REPLACE "${CC_BINARY_DIR}/include/" "" src ${src}) + ENDIF() + STRING(REPLACE "-" "_" src_id ${src}) + STRING(REPLACE "mysql/" "" src_id ${src_id}) + STRING(REPLACE "mysql/" "" src_name ${src}) + STRING(REPLACE "mariadb/" "" src_name ${src_name}) + STRING(REPLACE "mariadb/" "" src_id ${src_id}) + IF(${src} MATCHES "mysql/") + SET(MARIADB_INCLUDEMYSQL_FILES "${MARIADB_INCLUDEMYSQL_FILES} \n") + ELSE() + SET(MARIADB_INCLUDE_FILES "${MARIADB_INCLUDE_FILES} \n") + ENDIF() +ENDFOREACH() + + +IF(NOT WIX_DIR) + SET(WIX_DIR $ENV{WIX}/bin) +ENDIF() + +IF(NOT PACKAGE_STATUS_SUFFIX) + SET(MSI_PACKAGE "mariadb-connector-c-${PRODUCT_VERSION}-${PLATFORM}.msi") +ELSE() + SET(MSI_PACKAGE "mariadb-connector-c-${PRODUCT_VERSION}-${PACKAGE_STATUS_SUFFIX}-${PLATFORM}.msi") +ENDIF() + +IF(WITH_SIGNCODE) + IF(EXISTS "/tools/sign.bat") + ADD_CUSTOM_TARGET(SIGNMSI + DEPENDS ${MSI_PACKAGE} + COMMAND /tools/sign.bat ${MSI_PACKAGE}) + ELSE() + ADD_CUSTOM_TARGET(SIGNMSI + DEPENDS ${MSI_PACKAGE} + COMMAND signtool sign ${SIGN_OPTIONS} ${MSI_PACKAGE}) + ENDIF() + ADD_DEPENDENCIES(SIGNMSI ${MSI_PACKAGE}) + SET_TARGET_PROPERTIES(SIGNMSI PROPERTIES EXCLUDE_FROM_ALL OFF) +ENDIF() + +ADD_CUSTOM_TARGET( + ${MSI_PACKAGE} + DEPENDS WIXOBJ +#mariadb-connector-c.wixobj + COMMAND ${WIX_DIR}/light.exe -ext WixUIExtension mariadb-connector-c.wixobj -o ${MSI_PACKAGE}) + +ADD_CUSTOM_TARGET(WIXOBJ + DEPENDS mariadb-connector-c.xml} + COMMAND ${WIX_DIR}/candle.exe mariadb-connector-c.xml -o mariadb-connector-c.wixobj) + +SET_TARGET_PROPERTIES(${MSI_PACKAGE} PROPERTIES EXCLUDE_FROM_ALL OFF) +SET_TARGET_PROPERTIES(${WIXOBJ} PROPERTIES EXCLUDE_FROM_ALL OFF) +ADD_DEPENDENCIES(${MSI_PACKAGE} WIXOBJ) +ADD_DEPENDENCIES(WIXOBJ libmariadb mariadbclient ${DYNAMIC_TARGETS}) + +CONFIGURE_FILE(${CC_SOURCE_DIR}/win/packaging/mariadb-connector-c.xml.in + ${CC_BINARY_DIR}/win/packaging/mariadb-connector-c.xml) diff --git a/vendor/MDBC/win/packaging/WixUIBannerBmp.jpg b/vendor/MDBC/win/packaging/WixUIBannerBmp.jpg new file mode 100644 index 0000000000000000000000000000000000000000..60cce899773c5da4558d270a65e67fbb9a9961a5 GIT binary patch literal 7401 zcmbVQ2|SeFyMJfKjKN?qb}{xzvJTl9vK5&@*&sB&D*HWKCtMNF-Eb zCrkEhWs4Lk_l){2|NFc5|GEGB%)FoX`#$G6=RMDJmgjrkt#@0a5O$w|u>k~w!5|~> zgSN&{m-ItD+#tx?W~|Hcjg6JUsKJseh02l}E zC&1+qL$_@c3-C2?fmdul|8X}oHYMW~WaQ;!CJv}`G1DX+oW5zHsVR+d&SaCb}gami+2?*fD zWF+w-(xL(aggrZ@<>ZM(qL8Gjriy}wj3QBi)(DJ&fdRvW;bCUxQ4kgoR``!)>p8@R zh6G{2SrG`%21BsHwi+NI&`%^7QQDyX78o2sheXk%85o&>K{=KdDFmDjfke{L0qby3 z4$-k8*@fjvC=QAfy@)?fAu=T!Evj2q$7$ZNB&O&b5XHdA#m&RZCoUmL*eOL+Qr@GY zs;0MB-@wqwc%Oyk!9!NoHnuLVN8Q|yd3Xk%2nr4f4LeCacRo5M_CnmH)XQmC(ywM* z%gMccC+}|ly@Cf1AC*^BRy}@F|Dxe#V^j01*PUJ6J-vPJ`Ul3wCni5kP0!5EEq`8F z{j&D;+xiC0FPfi!$S=qKn_q0eFE||?f{vc%7YrT(E(9ALQdl0vPNL8|`E!UUM51xJ zDcNOp45EtWOPtOD9gJLJ#4+(@nrqvh{ofpm`hR)$r(=KlH2`4{Ffe!sHb@&<)iWWk zP_A{aFGuInz-{4+lxtyme6A_w2A&4_trSsagYFedIXRl|Vu2o|T)~Flf?2ab(eeUM z5AWS_xgPfBfveqX`2$z4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n)l%^3*A|Avy4c zMf5jU950u%5+;t!&S7h~*+&_;T0$&cmrX*seZkGqn9;!Y*&WWgl@rR@7(`AR|d2ui9}ApN2(&bWl+>Qj5E`JzI}>hu2qe!GvC literal 0 HcmV?d00001 diff --git a/vendor/MDBC/win/packaging/license.rtf b/vendor/MDBC/win/packaging/license.rtf new file mode 100644 index 00000000..1ed38609 --- /dev/null +++ b/vendor/MDBC/win/packaging/license.rtf @@ -0,0 +1,464 @@ +{\rtf1\adeflang1025\ansi\ansicpg1252\uc1\adeff31507\deff0\stshfdbch31505\stshfloch31506\stshfhich31506\stshfbi31507\deflang1031\deflangfe1031\themelang1031\themelangfe0\themelangcs0{\fonttbl{\f0\fbidi \froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman;}{\f2\fbidi \fmodern\fcharset0\fprq1{\*\panose 02070309020205020404}Courier New;} +{\f34\fbidi \froman\fcharset0\fprq2{\*\panose 02040503050406030204}Cambria Math;}{\f37\fbidi \fswiss\fcharset0\fprq2{\*\panose 020f0502020204030204}Calibri;}{\flomajor\f31500\fbidi \froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman;} +{\fdbmajor\f31501\fbidi \froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman;}{\fhimajor\f31502\fbidi \froman\fcharset0\fprq2{\*\panose 02040503050406030204}Cambria;} +{\fbimajor\f31503\fbidi \froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman;}{\flominor\f31504\fbidi \froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman;} +{\fdbminor\f31505\fbidi \froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman;}{\fhiminor\f31506\fbidi \fswiss\fcharset0\fprq2{\*\panose 020f0502020204030204}Calibri;} +{\fbiminor\f31507\fbidi \froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman;}{\f322\fbidi \froman\fcharset238\fprq2 Times New Roman CE;}{\f323\fbidi \froman\fcharset204\fprq2 Times New Roman Cyr;} +{\f325\fbidi \froman\fcharset161\fprq2 Times New Roman Greek;}{\f326\fbidi \froman\fcharset162\fprq2 Times New Roman Tur;}{\f327\fbidi \froman\fcharset177\fprq2 Times New Roman (Hebrew);}{\f328\fbidi \froman\fcharset178\fprq2 Times New Roman (Arabic);} +{\f329\fbidi \froman\fcharset186\fprq2 Times New Roman Baltic;}{\f330\fbidi \froman\fcharset163\fprq2 Times New Roman (Vietnamese);}{\f342\fbidi \fmodern\fcharset238\fprq1 Courier New CE;}{\f343\fbidi \fmodern\fcharset204\fprq1 Courier New Cyr;} +{\f345\fbidi \fmodern\fcharset161\fprq1 Courier New Greek;}{\f346\fbidi \fmodern\fcharset162\fprq1 Courier New Tur;}{\f347\fbidi \fmodern\fcharset177\fprq1 Courier New (Hebrew);}{\f348\fbidi \fmodern\fcharset178\fprq1 Courier New (Arabic);} +{\f349\fbidi \fmodern\fcharset186\fprq1 Courier New Baltic;}{\f350\fbidi \fmodern\fcharset163\fprq1 Courier New (Vietnamese);}{\f662\fbidi \froman\fcharset238\fprq2 Cambria Math CE;}{\f663\fbidi \froman\fcharset204\fprq2 Cambria Math Cyr;} +{\f665\fbidi \froman\fcharset161\fprq2 Cambria Math Greek;}{\f666\fbidi \froman\fcharset162\fprq2 Cambria Math Tur;}{\f669\fbidi \froman\fcharset186\fprq2 Cambria Math Baltic;}{\f670\fbidi \froman\fcharset163\fprq2 Cambria Math (Vietnamese);} +{\f692\fbidi \fswiss\fcharset238\fprq2 Calibri CE;}{\f693\fbidi \fswiss\fcharset204\fprq2 Calibri Cyr;}{\f695\fbidi \fswiss\fcharset161\fprq2 Calibri Greek;}{\f696\fbidi \fswiss\fcharset162\fprq2 Calibri Tur;} +{\f699\fbidi \fswiss\fcharset186\fprq2 Calibri Baltic;}{\f700\fbidi \fswiss\fcharset163\fprq2 Calibri (Vietnamese);}{\flomajor\f31508\fbidi \froman\fcharset238\fprq2 Times New Roman CE;} +{\flomajor\f31509\fbidi \froman\fcharset204\fprq2 Times New Roman Cyr;}{\flomajor\f31511\fbidi \froman\fcharset161\fprq2 Times New Roman Greek;}{\flomajor\f31512\fbidi \froman\fcharset162\fprq2 Times New Roman Tur;} +{\flomajor\f31513\fbidi \froman\fcharset177\fprq2 Times New Roman (Hebrew);}{\flomajor\f31514\fbidi \froman\fcharset178\fprq2 Times New Roman (Arabic);}{\flomajor\f31515\fbidi \froman\fcharset186\fprq2 Times New Roman Baltic;} +{\flomajor\f31516\fbidi \froman\fcharset163\fprq2 Times New Roman (Vietnamese);}{\fdbmajor\f31518\fbidi \froman\fcharset238\fprq2 Times New Roman CE;}{\fdbmajor\f31519\fbidi \froman\fcharset204\fprq2 Times New Roman Cyr;} +{\fdbmajor\f31521\fbidi \froman\fcharset161\fprq2 Times New Roman Greek;}{\fdbmajor\f31522\fbidi \froman\fcharset162\fprq2 Times New Roman Tur;}{\fdbmajor\f31523\fbidi \froman\fcharset177\fprq2 Times New Roman (Hebrew);} +{\fdbmajor\f31524\fbidi \froman\fcharset178\fprq2 Times New Roman (Arabic);}{\fdbmajor\f31525\fbidi \froman\fcharset186\fprq2 Times New Roman Baltic;}{\fdbmajor\f31526\fbidi \froman\fcharset163\fprq2 Times New Roman (Vietnamese);} +{\fhimajor\f31528\fbidi \froman\fcharset238\fprq2 Cambria CE;}{\fhimajor\f31529\fbidi \froman\fcharset204\fprq2 Cambria Cyr;}{\fhimajor\f31531\fbidi \froman\fcharset161\fprq2 Cambria Greek;}{\fhimajor\f31532\fbidi \froman\fcharset162\fprq2 Cambria Tur;} +{\fhimajor\f31535\fbidi \froman\fcharset186\fprq2 Cambria Baltic;}{\fhimajor\f31536\fbidi \froman\fcharset163\fprq2 Cambria (Vietnamese);}{\fbimajor\f31538\fbidi \froman\fcharset238\fprq2 Times New Roman CE;} +{\fbimajor\f31539\fbidi \froman\fcharset204\fprq2 Times New Roman Cyr;}{\fbimajor\f31541\fbidi \froman\fcharset161\fprq2 Times New Roman Greek;}{\fbimajor\f31542\fbidi \froman\fcharset162\fprq2 Times New Roman Tur;} +{\fbimajor\f31543\fbidi \froman\fcharset177\fprq2 Times New Roman (Hebrew);}{\fbimajor\f31544\fbidi \froman\fcharset178\fprq2 Times New Roman (Arabic);}{\fbimajor\f31545\fbidi \froman\fcharset186\fprq2 Times New Roman Baltic;} +{\fbimajor\f31546\fbidi \froman\fcharset163\fprq2 Times New Roman (Vietnamese);}{\flominor\f31548\fbidi \froman\fcharset238\fprq2 Times New Roman CE;}{\flominor\f31549\fbidi \froman\fcharset204\fprq2 Times New Roman Cyr;} +{\flominor\f31551\fbidi \froman\fcharset161\fprq2 Times New Roman Greek;}{\flominor\f31552\fbidi \froman\fcharset162\fprq2 Times New Roman Tur;}{\flominor\f31553\fbidi \froman\fcharset177\fprq2 Times New Roman (Hebrew);} +{\flominor\f31554\fbidi \froman\fcharset178\fprq2 Times New Roman (Arabic);}{\flominor\f31555\fbidi \froman\fcharset186\fprq2 Times New Roman Baltic;}{\flominor\f31556\fbidi \froman\fcharset163\fprq2 Times New Roman (Vietnamese);} +{\fdbminor\f31558\fbidi \froman\fcharset238\fprq2 Times New Roman CE;}{\fdbminor\f31559\fbidi \froman\fcharset204\fprq2 Times New Roman Cyr;}{\fdbminor\f31561\fbidi \froman\fcharset161\fprq2 Times New Roman Greek;} +{\fdbminor\f31562\fbidi \froman\fcharset162\fprq2 Times New Roman Tur;}{\fdbminor\f31563\fbidi \froman\fcharset177\fprq2 Times New Roman (Hebrew);}{\fdbminor\f31564\fbidi \froman\fcharset178\fprq2 Times New Roman (Arabic);} +{\fdbminor\f31565\fbidi \froman\fcharset186\fprq2 Times New Roman Baltic;}{\fdbminor\f31566\fbidi \froman\fcharset163\fprq2 Times New Roman (Vietnamese);}{\fhiminor\f31568\fbidi \fswiss\fcharset238\fprq2 Calibri CE;} +{\fhiminor\f31569\fbidi \fswiss\fcharset204\fprq2 Calibri Cyr;}{\fhiminor\f31571\fbidi \fswiss\fcharset161\fprq2 Calibri Greek;}{\fhiminor\f31572\fbidi \fswiss\fcharset162\fprq2 Calibri Tur;} +{\fhiminor\f31575\fbidi \fswiss\fcharset186\fprq2 Calibri Baltic;}{\fhiminor\f31576\fbidi \fswiss\fcharset163\fprq2 Calibri (Vietnamese);}{\fbiminor\f31578\fbidi \froman\fcharset238\fprq2 Times New Roman CE;} +{\fbiminor\f31579\fbidi \froman\fcharset204\fprq2 Times New Roman Cyr;}{\fbiminor\f31581\fbidi \froman\fcharset161\fprq2 Times New Roman Greek;}{\fbiminor\f31582\fbidi \froman\fcharset162\fprq2 Times New Roman Tur;} +{\fbiminor\f31583\fbidi \froman\fcharset177\fprq2 Times New Roman (Hebrew);}{\fbiminor\f31584\fbidi \froman\fcharset178\fprq2 Times New Roman (Arabic);}{\fbiminor\f31585\fbidi \froman\fcharset186\fprq2 Times New Roman Baltic;} +{\fbiminor\f31586\fbidi \froman\fcharset163\fprq2 Times New Roman (Vietnamese);}}{\colortbl;\red0\green0\blue0;\red0\green0\blue255;\red0\green255\blue255;\red0\green255\blue0;\red255\green0\blue255;\red255\green0\blue0;\red255\green255\blue0; +\red255\green255\blue255;\red0\green0\blue128;\red0\green128\blue128;\red0\green128\blue0;\red128\green0\blue128;\red128\green0\blue0;\red128\green128\blue0;\red128\green128\blue128;\red192\green192\blue192;}{\*\defchp +\fs22\loch\af31506\hich\af31506\dbch\af31505 }{\*\defpap \ql \li0\ri0\sa200\sl276\slmult1\widctlpar\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0 }\noqfpromote {\stylesheet{\ql \li0\ri0\sa200\sl276\slmult1 +\widctlpar\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0 \rtlch\fcs1 \af31507\afs22\alang1025 \ltrch\fcs0 \fs22\lang1031\langfe1031\loch\f31506\hich\af31506\dbch\af31505\cgrid\langnp1031\langfenp1031 \snext0 \sqformat \spriority0 Normal;} +{\*\cs10 \additive \ssemihidden \sunhideused \spriority1 Default Paragraph Font;}{\* +\ts11\tsrowd\trftsWidthB3\trpaddl108\trpaddr108\trpaddfl3\trpaddft3\trpaddfb3\trpaddfr3\trcbpat1\trcfpat1\tblind0\tblindtype3\tsvertalt\tsbrdrt\tsbrdrl\tsbrdrb\tsbrdrr\tsbrdrdgl\tsbrdrdgr\tsbrdrh\tsbrdrv \ql \li0\ri0\sa200\sl276\slmult1 +\widctlpar\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0 \rtlch\fcs1 \af31507\afs22\alang1025 \ltrch\fcs0 \fs22\lang1031\langfe1031\loch\f31506\hich\af31506\dbch\af31505\cgrid\langnp1031\langfenp1031 \snext11 \ssemihidden \sunhideused +Normal Table;}{\s15\ql \li0\ri0\widctlpar\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0 \rtlch\fcs1 \af31507\afs22\alang1025 \ltrch\fcs0 \fs22\lang1031\langfe1031\loch\f31506\hich\af31506\dbch\af31505\cgrid\langnp1031\langfenp1031 +\snext15 \sqformat \spriority1 \styrsid7013135 No Spacing;}}{\*\rsidtbl \rsid1254708\rsid7013135}{\mmathPr\mmathFont34\mbrkBin0\mbrkBinSub0\msmallFrac0\mdispDef1\mlMargin0\mrMargin0\mdefJc1\mwrapIndent1440\mintLim0\mnaryLim1}{\info{\operator Windows User} +{\creatim\yr2013\mo10\dy26\hr9\min47}{\revtim\yr2013\mo10\dy26\hr9\min55}{\version2}{\edmins0}{\nofpages9}{\nofwords3590}{\nofchars22619}{\nofcharsws26157}{\vern49167}}{\*\xmlnstbl {\xmlns1 http://schemas.microsoft.com/office/word/2003/wordml}} +\paperw12240\paperh15840\margl1417\margr1417\margt1417\margb1134\gutter0\ltrsect +\widowctrl\ftnbj\aenddoc\hyphhotz425\trackmoves0\trackformatting1\donotembedsysfont0\relyonvml0\donotembedlingdata1\grfdocevents0\validatexml0\showplaceholdtext0\ignoremixedcontent0\saveinvalidxml0\showxmlerrors0\horzdoc\dghspace120\dgvspace120 +\dghorigin1701\dgvorigin1984\dghshow0\dgvshow3\jcompress\viewkind1\viewscale100\rsidroot7013135 \fet0{\*\wgrffmtfilter 2450}\ilfomacatclnup0\ltrpar \sectd \ltrsect\linex0\sectdefaultcl\sftnbj {\*\pnseclvl1\pnucrm\pnstart1\pnindent720\pnhang {\pntxta .}} +{\*\pnseclvl2\pnucltr\pnstart1\pnindent720\pnhang {\pntxta .}}{\*\pnseclvl3\pndec\pnstart1\pnindent720\pnhang {\pntxta .}}{\*\pnseclvl4\pnlcltr\pnstart1\pnindent720\pnhang {\pntxta )}}{\*\pnseclvl5\pndec\pnstart1\pnindent720\pnhang {\pntxtb (}{\pntxta )}} +{\*\pnseclvl6\pnlcltr\pnstart1\pnindent720\pnhang {\pntxtb (}{\pntxta )}}{\*\pnseclvl7\pnlcrm\pnstart1\pnindent720\pnhang {\pntxtb (}{\pntxta )}}{\*\pnseclvl8\pnlcltr\pnstart1\pnindent720\pnhang {\pntxtb (}{\pntxta )}}{\*\pnseclvl9 +\pnlcrm\pnstart1\pnindent720\pnhang {\pntxtb (}{\pntxta )}}\pard\plain \ltrpar\qc \li0\ri0\nowidctlpar\wrapdefault\faauto\rin0\lin0\itap0\pararsid7013135 \rtlch\fcs1 \af31507\afs22\alang1025 \ltrch\fcs0 +\fs22\lang1031\langfe1031\loch\af31506\hich\af31506\dbch\af31505\cgrid\langnp1031\langfenp1031 {\rtlch\fcs1 \af2\afs28 \ltrch\fcs0 \b\fs28\lang1033\langfe1031\langnp1033\insrsid1254708\charrsid7013135 \hich\af31506\dbch\af31505\loch\f31506 +GNU LESSER GENERAL PUBLIC LICENSE +\par }{\rtlch\fcs1 \af2 \ltrch\fcs0 \lang1033\langfe1031\langnp1033\insrsid1254708\charrsid7013135 \hich\af31506\dbch\af31505\loch\f31506 Version 2.1, February 1999 +\par }\pard \ltrpar\ql \li0\ri0\nowidctlpar\wrapdefault\faauto\rin0\lin0\itap0 {\rtlch\fcs1 \af2 \ltrch\fcs0 \lang1033\langfe1031\langnp1033\insrsid1254708\charrsid7013135 +\par }\pard \ltrpar\qc \li0\ri0\nowidctlpar\wrapdefault\faauto\rin0\lin0\itap0\pararsid7013135 {\rtlch\fcs1 \af2 \ltrch\fcs0 \lang1033\langfe1031\langnp1033\insrsid1254708\charrsid7013135 \hich\af31506\dbch\af31505\loch\f31506 +Copyright (C) 1991, 1999 Free Software Foundation, Inc. +\par \hich\af31506\dbch\af31505\loch\f31506 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +\par \hich\af31506\dbch\af31505\loch\f31506 Everyone is permitted to copy and distribute verbatim copies +\par \hich\af31506\dbch\af31505\loch\f31506 of this license document, but changing it is not allowed. +\par +\par \hich\af31506\dbch\af31505\loch\f31506 [This is the first released version of the Lesser GPL. \hich\af31506\dbch\af31505\loch\f31506 It also counts as the successor of the GNU Library Public License, version 2, \hich\af31506\dbch\af31505\loch\f31506 +hence the version number 2.1.] +\par }\pard \ltrpar\ql \li0\ri0\nowidctlpar\wrapdefault\faauto\rin0\lin0\itap0 {\rtlch\fcs1 \af2 \ltrch\fcs0 \lang1033\langfe1031\langnp1033\insrsid1254708\charrsid7013135 +\par }\pard \ltrpar\qc \li0\ri0\nowidctlpar\wrapdefault\faauto\rin0\lin0\itap0\pararsid7013135 {\rtlch\fcs1 \af2 \ltrch\fcs0 \b\lang1033\langfe1031\langnp1033\insrsid1254708\charrsid7013135 \hich\af31506\dbch\af31505\loch\f31506 Preamble +\par }\pard \ltrpar\ql \li0\ri0\nowidctlpar\wrapdefault\faauto\rin0\lin0\itap0 {\rtlch\fcs1 \af2 \ltrch\fcs0 \lang1033\langfe1031\langnp1033\insrsid1254708\charrsid7013135 +\par }\pard\plain \ltrpar\s15\ql \li0\ri0\widctlpar\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0\pararsid7013135 \rtlch\fcs1 \af31507\afs22\alang1025 \ltrch\fcs0 +\fs22\lang1031\langfe1031\loch\af31506\hich\af31506\dbch\af31505\cgrid\langnp1031\langfenp1031 {\rtlch\fcs1 \af31507 \ltrch\fcs0 \lang1033\langfe1031\langnp1033\insrsid1254708\charrsid7013135 \hich\af31506\dbch\af31505\loch\f31506 + The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to sh\hich\af31506\dbch\af31505\loch\f31506 +are and change free software--to make sure the software is free for all its users. +\par }\pard\plain \ltrpar\ql \li0\ri0\nowidctlpar\wrapdefault\faauto\rin0\lin0\itap0 \rtlch\fcs1 \af31507\afs22\alang1025 \ltrch\fcs0 \fs22\lang1031\langfe1031\loch\af31506\hich\af31506\dbch\af31505\cgrid\langnp1031\langfenp1031 {\rtlch\fcs1 \af2 \ltrch\fcs0 +\lang1033\langfe1031\langnp1033\insrsid1254708\charrsid7013135 +\par \hich\af31506\dbch\af31505\loch\f31506 This license, the Lesser General Public License, applies to some specially designated software packages--typically libraries--of the Free Software Foundation and other au\hich\af31506\dbch\af31505\loch\f31506 +thors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below. +\par +\par \hich\af31506\dbch\af31505\loch\f31506 When we sp\hich\af31506\dbch\af31505\loch\f31506 +eak of free software, we are referring to freedom of use, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish); that you receive source +\hich\af31506\dbch\af31505\loch\f31506 c\hich\af31506\dbch\af31505\loch\f31506 ode or can get it if you want it; that you can change the software and use pieces of it in new free programs; and that you are informed that you can do these things. +\par +\par \hich\af31506\dbch\af31505\loch\f31506 To protect your rights, we need to make restrictions that forbid distributors to deny y\hich\af31506\dbch\af31505\loch\f31506 +ou these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it. +\par \hich\af31506\dbch\af31505\loch\f31506 For example, if you distribute copies of the library, whether gratis\hich\af31506\dbch\af31505\loch\f31506 + or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so tha +\hich\af31506\dbch\af31505\loch\f31506 t\hich\af31506\dbch\af31505\loch\f31506 they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights. +\par +\par \hich\af31506\dbch\af31505\loch\f31506 We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer y\hich\af31506\dbch\af31505\loch\f31506 +ou this license, which gives you legal permission to copy, distribute and/or modify the library. To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else +\hich\af31506\dbch\af31505\loch\f31506 a\hich\af31506\dbch\af31505\loch\f31506 +nd passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others. +\par +\par \hich\af31506\dbch\af31505\loch\f31506 Finally, software patents pose a constant threat to t\hich\af31506\dbch\af31505\loch\f31506 +he existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of +\hich\af31506\dbch\af31505\loch\f31506 \hich\af31506\dbch\af31505\loch\f31506 the library must be consistent with the full freedom of use specified in this license. +\par +\par \hich\af31506\dbch\af31505\loch\f31506 Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to c\hich\af31506\dbch\af31505\loch\f31506 +ertain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs. +\par +\par \hich\af31506\dbch\af31505\loch\f31506 When a program is linked with a library, whether \hich\af31506\dbch\af31505\loch\f31506 +statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteri +\hich\af31506\dbch\af31505\loch\f31506 a\hich\af31506\dbch\af31505\loch\f31506 of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library. +\par +\par \hich\af31506\dbch\af31505\loch\f31506 + We call this license the "Lesser" General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. +\hich\af31506\dbch\af31505\loch\f31506 \hich\af31506\dbch\af31505\loch\f31506 + These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances. +\par +\par \hich\af31506\dbch\af31505\loch\f31506 For example, on rare occasions, there may be a special need to encourag\hich\af31506\dbch\af31505\loch\f31506 +e the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free librarie +\hich\af31506\dbch\af31505\loch\f31506 s\hich\af31506\dbch\af31505\loch\f31506 . In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License. +\par +\par \hich\af31506\dbch\af31505\loch\f31506 In other cases, permission to use a particular library in non-free programs enables a greater number of people to u\hich\af31506\dbch\af31505\loch\f31506 +se a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system. +\par +\par \hich\af31506\dbch\af31505\loch\f31506 Although the Lesser General \hich\af31506\dbch\af31505\loch\f31506 +Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library. +\par +\par \hich\af31506\dbch\af31505\loch\f31506 The precise terms and con\hich\af31506\dbch\af31505\loch\f31506 +ditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, whereas the latter must be comb +\hich\af31506\dbch\af31505\loch\f31506 i\hich\af31506\dbch\af31505\loch\f31506 ned with the library in order to run. +\par \page +\par }\pard \ltrpar\qc \li0\ri0\nowidctlpar\wrapdefault\faauto\rin0\lin0\itap0\pararsid7013135 {\rtlch\fcs1 \af2\afs24 \ltrch\fcs0 \b\fs24\lang1033\langfe1031\langnp1033\insrsid1254708\charrsid7013135 \hich\af31506\dbch\af31505\loch\f31506 +GNU LESSER GENERAL PUBLIC LICENSE +\par \hich\af31506\dbch\af31505\loch\f31506 TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION +\par }\pard \ltrpar\ql \li0\ri0\nowidctlpar\wrapdefault\faauto\rin0\lin0\itap0 {\rtlch\fcs1 \af2 \ltrch\fcs0 \lang1033\langfe1031\langnp1033\insrsid1254708\charrsid7013135 +\par \hich\af31506\dbch\af31505\loch\f31506 0. This License Agreement applies to any software library or other program which contains a no\hich\af31506\dbch\af31505\loch\f31506 +tice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you". +\par +\par \hich\af31506\dbch\af31505\loch\f31506 A "library" means a collection of softwa\hich\af31506\dbch\af31505\loch\f31506 +re functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables. +\par +\par \hich\af31506\dbch\af31505\loch\f31506 The "Library", below, refers to any such software library or work which has been distributed un\hich\af31506\dbch\af31505\loch\f31506 +der these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardl +\hich\af31506\dbch\af31505\loch\f31506 y\hich\af31506\dbch\af31505\loch\f31506 into another language. (Hereinafter, translation is included without limitation in the term "modification".) +\par +\par \hich\af31506\dbch\af31505\loch\f31506 "Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all t\hich\af31506\dbch\af31505\loch\f31506 +he source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library. +\par +\par \hich\af31506\dbch\af31505\loch\f31506 Activities other than copying, distribution and modification are not covered by thi\hich\af31506\dbch\af31505\loch\f31506 +s License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a too +\hich\af31506\dbch\af31505\loch\f31506 l\hich\af31506\dbch\af31505\loch\f31506 for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does. +\par +\par \hich\af31506\dbch\af31505\loch\f31506 1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided tha\hich\af31506\dbch\af31505\loch\f31506 +t you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along w +\hich\af31506\dbch\af31505\loch\f31506 i\hich\af31506\dbch\af31505\loch\f31506 th the Library. +\par +\par \hich\af31506\dbch\af31505\loch\f31506 You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. +\par \page +\par \hich\af31506\dbch\af31505\loch\f31506 2. You may modify your copy or copies of the Library or any portion of it, thus forming a w\hich\af31506\dbch\af31505\loch\f31506 +ork based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: +\par +\par \hich\af31506\dbch\af31505\loch\f31506 a) The modified work must itself be a software library. +\par +\par \hich\af31506\dbch\af31505\loch\f31506 b) You mus\hich\af31506\dbch\af31505\loch\f31506 t cause the files modified to carry prominent notices stating that you changed the files and the date of any change. +\par +\par \hich\af31506\dbch\af31505\loch\f31506 c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License. +\par +\par \hich\af31506\dbch\af31505\loch\f31506 d) If a\hich\af31506\dbch\af31505\loch\f31506 + facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that +,\hich\af31506\dbch\af31505\loch\f31506 in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful. +\par +\par \hich\af31506\dbch\af31505\loch\f31506 (For example, a function in a library to compute square roots has a purpose that is entirel\hich\af31506\dbch\af31505\loch\f31506 +y well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute sq +\hich\af31506\dbch\af31505\loch\f31506 u\hich\af31506\dbch\af31505\loch\f31506 are roots.) +\par +\par \hich\af31506\dbch\af31505\loch\f31506 +These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, +\hich\af31506\dbch\af31505\loch\f31506 + do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permi +\hich\af31506\dbch\af31505\loch\f31506 s\hich\af31506\dbch\af31505\loch\f31506 sions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. +\par +\par \hich\af31506\dbch\af31505\loch\f31506 Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to e\hich\af31506\dbch\af31505\loch\f31506 +xercise the right to control the distribution of derivative or collective works based on the Library. +\par +\par \hich\af31506\dbch\af31505\loch\f31506 In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or\hich\af31506\dbch\af31505\loch\f31506 + distribution medium does not bring the other work under the scope of this License. +\par +\par \hich\af31506\dbch\af31505\loch\f31506 3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the \hich\af31506\dbch\af31505\loch\f31506 +notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify tha +\hich\af31506\dbch\af31505\loch\f31506 t\hich\af31506\dbch\af31505\loch\f31506 version instead if you wish.) Do not make any other change in +\par \hich\af31506\dbch\af31505\loch\f31506 these notices. +\par +\par \hich\af31506\dbch\af31505\loch\f31506 Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works m\hich\af31506\dbch\af31505\loch\f31506 +ade from that copy. +\par +\par \hich\af31506\dbch\af31505\loch\f31506 This option is useful when you wish to copy part of the code of the Library into a program that is not a library. +\par +\par \hich\af31506\dbch\af31505\loch\f31506 4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or exe\hich\af31506\dbch\af31505\loch\f31506 +cutable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for softwa +\hich\af31506\dbch\af31505\loch\f31506 r\hich\af31506\dbch\af31505\loch\f31506 e interchange. +\par +\par \hich\af31506\dbch\af31505\loch\f31506 + If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though th +\hich\af31506\dbch\af31505\loch\f31506 ird parties are not compelled to copy the source along with the object code. +\par +\par \hich\af31506\dbch\af31505\loch\f31506 + 5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the L +\hich\af31506\dbch\af31505\loch\f31506 i\hich\af31506\dbch\af31505\loch\f31506 brary, and therefore falls outside the scope of this License. +\par +\par \hich\af31506\dbch\af31505\loch\f31506 However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work t +\hich\af31506\dbch\af31505\loch\f31506 hat uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables. +\par +\par \hich\af31506\dbch\af31505\loch\f31506 When a "work that uses the Library" uses material from a header file that is part of the Library, the object code \hich\af31506\dbch\af31505\loch\f31506 +for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true +\hich\af31506\dbch\af31505\loch\f31506 i\hich\af31506\dbch\af31505\loch\f31506 s not precisely defined by law. +\par +\par \hich\af31506\dbch\af31505\loch\f31506 + If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, rega +\hich\af31506\dbch\af31505\loch\f31506 rdless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.) +\par +\par \hich\af31506\dbch\af31505\loch\f31506 Otherwise, if the work is a derivative of the Library, you may distribute the object code for the\hich\af31506\dbch\af31505\loch\f31506 + work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself. +\par +\par \hich\af31506\dbch\af31505\loch\f31506 6. As an exception to the Sections above, you may also combine or link a "work that use\hich\af31506\dbch\af31505\loch\f31506 +s the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debug +\hich\af31506\dbch\af31505\loch\f31506 g\hich\af31506\dbch\af31505\loch\f31506 ing such modifications. +\par +\par \hich\af31506\dbch\af31505\loch\f31506 + You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution display +\hich\af31506\dbch\af31505\loch\f31506 s copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things: +\par +\par \hich\af31506\dbch\af31505\loch\f31506 a) Accompany the work with the complete corresponding\hich\af31506\dbch\af31505\loch\f31506 + machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work th +\hich\af31506\dbch\af31505\loch\f31506 a\hich\af31506\dbch\af31505\loch\f31506 +t uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions file +\hich\af31506\dbch\af31505\loch\f31506 s\hich\af31506\dbch\af31505\loch\f31506 in the Library will not necessarily be able to recompile the application to use the modified definitions.) +\par +\par \hich\af31506\dbch\af31505\loch\f31506 b) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the l\hich\af31506\dbch\af31505\loch\f31506 +ibrary already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-c +\hich\af31506\dbch\af31505\loch\f31506 o\hich\af31506\dbch\af31505\loch\f31506 mpatible with the version that the work was made with. +\par +\par \hich\af31506\dbch\af31505\loch\f31506 c) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing +\hich\af31506\dbch\af31505\loch\f31506 this distribution. +\par +\par \hich\af31506\dbch\af31505\loch\f31506 d) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place. +\par +\par \hich\af31506\dbch\af31505\loch\f31506 e) Verify that the user has already received a copy o\hich\af31506\dbch\af31505\loch\f31506 f these materials or that you have already sent this user a copy. +\par +\par \hich\af31506\dbch\af31505\loch\f31506 For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special e +\hich\af31506\dbch\af31505\loch\f31506 +xception, the materials to be distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that co +\hich\af31506\dbch\af31505\loch\f31506 m\hich\af31506\dbch\af31505\loch\f31506 ponent itself accompanies the executable. +\par +\par \hich\af31506\dbch\af31505\loch\f31506 It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them a +\hich\af31506\dbch\af31505\loch\f31506 nd the Library together in an executable that you distribute. +\par +\par \hich\af31506\dbch\af31505\loch\f31506 + 7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution +\hich\af31506\dbch\af31505\loch\f31506 \hich\af31506\dbch\af31505\loch\f31506 of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things: +\par +\par \hich\af31506\dbch\af31505\loch\f31506 a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other libr\hich\af31506\dbch\af31505\loch\f31506 +ary facilities. This must be distributed under the terms of the Sections above. +\par +\par \hich\af31506\dbch\af31505\loch\f31506 b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined fo\hich\af31506\dbch\af31505\loch\f31506 +rm of the same work. +\par +\par \hich\af31506\dbch\af31505\loch\f31506 + 8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will +\hich\af31506\dbch\af31505\loch\f31506 +l automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. +\par +\par \hich\af31506\dbch\af31505\loch\f31506 9. You are not requir\hich\af31506\dbch\af31505\loch\f31506 +ed to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modif +\hich\af31506\dbch\af31505\loch\f31506 y\hich\af31506\dbch\af31505\loch\f31506 +ing or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it. +\par +\par \hich\af31506\dbch\af31505\loch\f31506 10. Each time you redist\hich\af31506\dbch\af31505\loch\f31506 +ribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further re +\hich\af31506\dbch\af31505\loch\f31506 s\hich\af31506\dbch\af31505\loch\f31506 trictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties with this License. +\par +\par \hich\af31506\dbch\af31505\loch\f31506 11. If, as a consequence of a court judgment or allegation of patent infringement or for any other \hich\af31506\dbch\af31505\loch\f31506 +reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so +\hich\af31506\dbch\af31505\loch\f31506 a\hich\af31506\dbch\af31505\loch\f31506 +s to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Lib +\hich\af31506\dbch\af31505\loch\f31506 r\hich\af31506\dbch\af31505\loch\f31506 +ary by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library. +\par +\par \hich\af31506\dbch\af31505\loch\f31506 If any portion of this section is held invalid or unenforce\hich\af31506\dbch\af31505\loch\f31506 +able under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances. +\par +\par \hich\af31506\dbch\af31505\loch\f31506 It is not the purpose of this section to induce you to infringe any patents or other property \hich\af31506\dbch\af31505\loch\f31506 +right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions +\hich\af31506\dbch\af31505\loch\f31506 t\hich\af31506\dbch\af31505\loch\f31506 +o the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose +\hich\af31506\dbch\af31505\loch\f31506 t\hich\af31506\dbch\af31505\loch\f31506 hat choice. +\par +\par \hich\af31506\dbch\af31505\loch\f31506 This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. +\par +\par \hich\af31506\dbch\af31505\loch\f31506 12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted int\hich\af31506\dbch\af31505\loch\f31506 +erfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such c +\hich\af31506\dbch\af31505\loch\f31506 a\hich\af31506\dbch\af31505\loch\f31506 se, this License incorporates the limitation as if written in the body of this License. +\par +\par \hich\af31506\dbch\af31505\loch\f31506 13. The Free Software Foundation may publish revised and/or new versions of the Lesser General Public License from time to time. Such new versions will be similar i\hich\af31506\dbch\af31505\loch\f31506 +n spirit to the present version, but may differ in detail to address new problems or concerns. +\par +\par \hich\af31506\dbch\af31505\loch\f31506 Each version is given a distinguishing version number. If the Library specifies a version number of this License which applies to it and "any later version", y\hich\af31506\dbch\af31505\loch\f31506 +ou have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the +\hich\af31506\dbch\af31505\loch\f31506 F\hich\af31506\dbch\af31505\loch\f31506 ree Software Foundation. +\par +\par \hich\af31506\dbch\af31505\loch\f31506 + 14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free So +\hich\af31506\dbch\af31505\loch\f31506 +ftware Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of +\hich\af31506\dbch\af31505\loch\f31506 s\hich\af31506\dbch\af31505\loch\f31506 oftware generally. +\par +\par \hich\af31506\dbch\af31505\loch\f31506 }{\rtlch\fcs1 \af2 \ltrch\fcs0 \b\lang1033\langfe1031\langnp1033\insrsid1254708\charrsid7013135 \hich\af31506\dbch\af31505\loch\f31506 NO WARRANTY +\par }{\rtlch\fcs1 \af2 \ltrch\fcs0 \lang1033\langfe1031\langnp1033\insrsid1254708\charrsid7013135 +\par \hich\af31506\dbch\af31505\loch\f31506 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTH\hich\af31506\dbch\af31505\loch\f31506 +ERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULA +\hich\af31506\dbch\af31505\loch\f31506 R\hich\af31506\dbch\af31505\loch\f31506 + PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. +\par +\par \hich\af31506\dbch\af31505\loch\f31506 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGRE\hich\af31506\dbch\af31505\loch\f31506 +ED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR I +\hich\af31506\dbch\af31505\loch\f31506 N\hich\af31506\dbch\af31505\loch\f31506 +ABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEE +\hich\af31506\dbch\af31505\loch\f31506 N\hich\af31506\dbch\af31505\loch\f31506 ADVISED OF THE POSSIBILITY OF SUCH +\par \hich\af31506\dbch\af31505\loch\f31506 DAMAGES. +\par +\par }\pard \ltrpar\qc \li0\ri0\nowidctlpar\wrapdefault\faauto\rin0\lin0\itap0\pararsid7013135 {\rtlch\fcs1 \af2 \ltrch\fcs0 \lang1033\langfe1031\langnp1033\insrsid1254708\charrsid7013135 \hich\af31506\dbch\af31505\loch\f31506 END OF TERMS AND CONDITIONS + +\par }\pard \ltrpar\ql \li0\ri0\nowidctlpar\wrapdefault\faauto\rin0\lin0\itap0 {\rtlch\fcs1 \af2 \ltrch\fcs0 \lang1033\langfe1031\langnp1033\insrsid1254708\charrsid7013135 +\par }\pard \ltrpar\qc \li0\ri0\nowidctlpar\wrapdefault\faauto\rin0\lin0\itap0\pararsid7013135 {\rtlch\fcs1 \af2 \ltrch\fcs0 \b\lang1033\langfe1031\langnp1033\insrsid1254708\charrsid7013135 \hich\af31506\dbch\af31505\loch\f31506 +How to Apply These Terms to Your New Libraries +\par }\pard \ltrpar\ql \li0\ri0\nowidctlpar\wrapdefault\faauto\rin0\lin0\itap0 {\rtlch\fcs1 \af2 \ltrch\fcs0 \lang1033\langfe1031\langnp1033\insrsid1254708\charrsid7013135 +\par \hich\af31506\dbch\af31505\loch\f31506 If you develop a new library, and you want it to be of the greatest possible use to the public, we \hich\af31506\dbch\af31505\loch\f31506 +recommend making it free software that everyone can redistribute and change. You can do so by permitting redistribution under these terms (or, alternatively, under the terms of the ordinary General Public License). +\par +\par \hich\af31506\dbch\af31505\loch\f31506 To apply these terms, attach the foll\hich\af31506\dbch\af31505\loch\f31506 +owing notices to the library. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. + +\par +\par \hich\af31506\dbch\af31505\loch\f31506 \hich\af31506\dbch\af31505\loch\f31506 }{\rtlch\fcs1 \af2 \ltrch\fcs0 \insrsid1254708\charrsid7013135 +\hich\af31506\dbch\af31505\loch\f31506 Copyright (C) +\par +\par }{\rtlch\fcs1 \af2 \ltrch\fcs0 \lang1033\langfe1031\langnp1033\insrsid1254708\charrsid7013135 \hich\af31506\dbch\af31505\loch\f31506 + This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as publishe\hich\af31506\dbch\af31505\loch\f31506 +d by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. +\par +\par \hich\af31506\dbch\af31505\loch\f31506 This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\hich\af31506\dbch\af31505\loch\f31506 + or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. +\par +\par \hich\af31506\dbch\af31505\loch\f31506 You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software +\par \hich\af31506\dbch\af31505\loch\f31506 Foundation, Inc\hich\af31506\dbch\af31505\loch\f31506 ., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +\par +\par \hich\af31506\dbch\af31505\loch\f31506 Also add information on how to contact you by electronic and paper mail. +\par +\par \hich\af31506\dbch\af31505\loch\f31506 You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaim\hich\af31506\dbch\af31505\loch\f31506 er" for the library, if +\par \hich\af31506\dbch\af31505\loch\f31506 necessary. Here is a sample; alter the names: +\par +\par \hich\af31506\dbch\af31505\loch\f31506 Yoyodyne, Inc., hereby disclaims all copyright interest in the +\par \hich\af31506\dbch\af31505\loch\f31506 library `Frob' (a library for tweaking knobs) written by James Random Hacker. +\par +\par \hich\af31506\dbch\af31505\loch\f31506 , 1 April 1990 +\par \hich\af31506\dbch\af31505\loch\f31506 }{\rtlch\fcs1 \af2 \ltrch\fcs0 \insrsid1254708\charrsid7013135 \hich\af31506\dbch\af31505\loch\f31506 Ty Coon, President of Vice +\par +\par }{\rtlch\fcs1 \af2 \ltrch\fcs0 \lang1033\langfe1031\langnp1033\insrsid1254708\charrsid7013135 \hich\af31506\dbch\af31505\loch\f31506 That's all there is to it! +\par }{\rtlch\fcs1 \af2 \ltrch\fcs0 \lang1033\langfe1031\langnp1033\insrsid1254708\charrsid7013135 +\par }{\*\themedata 504b030414000600080000002100e9de0fbfff0000001c020000130000005b436f6e74656e745f54797065735d2e786d6cac91cb4ec3301045f748fc83e52d4a +9cb2400825e982c78ec7a27cc0c8992416c9d8b2a755fbf74cd25442a820166c2cd933f79e3be372bd1f07b5c3989ca74aaff2422b24eb1b475da5df374fd9ad +5689811a183c61a50f98f4babebc2837878049899a52a57be670674cb23d8e90721f90a4d2fa3802cb35762680fd800ecd7551dc18eb899138e3c943d7e503b6 +b01d583deee5f99824e290b4ba3f364eac4a430883b3c092d4eca8f946c916422ecab927f52ea42b89a1cd59c254f919b0e85e6535d135a8de20f20b8c12c3b0 +0c895fcf6720192de6bf3b9e89ecdbd6596cbcdd8eb28e7c365ecc4ec1ff1460f53fe813d3cc7f5b7f020000ffff0300504b030414000600080000002100a5d6 +a7e7c0000000360100000b0000005f72656c732f2e72656c73848fcf6ac3300c87ef85bd83d17d51d2c31825762fa590432fa37d00e1287f68221bdb1bebdb4f +c7060abb0884a4eff7a93dfeae8bf9e194e720169aaa06c3e2433fcb68e1763dbf7f82c985a4a725085b787086a37bdbb55fbc50d1a33ccd311ba548b6309512 +0f88d94fbc52ae4264d1c910d24a45db3462247fa791715fd71f989e19e0364cd3f51652d73760ae8fa8c9ffb3c330cc9e4fc17faf2ce545046e37944c69e462 +a1a82fe353bd90a865aad41ed0b5b8f9d6fd010000ffff0300504b0304140006000800000021006b799616830000008a0000001c0000007468656d652f746865 +6d652f7468656d654d616e616765722e786d6c0ccc4d0ac3201040e17da17790d93763bb284562b2cbaebbf600439c1a41c7a0d29fdbd7e5e38337cedf14d59b +4b0d592c9c070d8a65cd2e88b7f07c2ca71ba8da481cc52c6ce1c715e6e97818c9b48d13df49c873517d23d59085adb5dd20d6b52bd521ef2cdd5eb9246a3d8b +4757e8d3f729e245eb2b260a0238fd010000ffff0300504b03041400060008000000210030dd4329a8060000a41b0000160000007468656d652f7468656d652f +7468656d65312e786d6cec594f6fdb3614bf0fd87720746f6327761a07758ad8b19b2d4d1bc46e871e698996d850a240d2497d1bdae38001c3ba618715d86d87 +615b8116d8a5fb34d93a6c1dd0afb0475292c5585e9236d88aad3e2412f9e3fbff1e1fa9abd7eec70c1d1221294fda5efd72cd4324f1794093b0eddd1ef62fad +79482a9c0498f184b4bd2991deb58df7dfbb8ad755446282607d22d771db8b944ad79796a40fc3585ee62949606ecc458c15bc8a702910f808e8c66c69b9565b +5d8a314d3c94e018c8de1a8fa94fd05093f43672e23d06af89927ac06762a049136785c10607758d9053d965021d62d6f6804fc08f86e4bef210c352c144dbab +999fb7b4717509af678b985ab0b6b4ae6f7ed9ba6c4170b06c788a705430adf71bad2b5b057d03606a1ed7ebf5babd7a41cf00b0ef83a6569632cd467faddec9 +699640f6719e76b7d6ac355c7c89feca9cccad4ea7d36c65b258a206641f1b73f8b5da6a6373d9c11b90c537e7f08dce66b7bbeae00dc8e257e7f0fd2badd586 +8b37a088d1e4600ead1ddaef67d40bc898b3ed4af81ac0d76a197c86826828a24bb318f3442d8ab518dfe3a20f000d6458d104a9694ac6d88728eee2782428d6 +0cf03ac1a5193be4cbb921cd0b495fd054b5bd0f530c1931a3f7eaf9f7af9e3f45c70f9e1d3ff8e9f8e1c3e3073f5a42ceaa6d9c84e5552fbffdeccfc71fa33f +9e7ef3f2d117d57859c6fffac327bffcfc793510d26726ce8b2f9ffcf6ecc98baf3efdfdbb4715f04d814765f890c644a29be408edf3181433567125272371be +15c308d3f28acd249438c19a4b05fd9e8a1cf4cd296699771c393ac4b5e01d01e5a30a787d72cf1178108989a2159c77a2d801ee72ce3a5c545a6147f32a9979 +3849c26ae66252c6ed637c58c5bb8b13c7bfbd490a75330f4b47f16e441c31f7184e140e494214d273fc80900aedee52ead87597fa824b3e56e82e451d4c2b4d +32a423279a668bb6690c7e9956e90cfe766cb37b077538abd27a8b1cba48c80acc2a841f12e698f13a9e281c57911ce298950d7e03aba84ac8c154f8655c4f2a +f074481847bd804859b5e696007d4b4edfc150b12addbecba6b18b148a1e54d1bc81392f23b7f84137c2715a851dd0242a633f900710a218ed715505dfe56e86 +e877f0034e16bafb0e258ebb4faf06b769e888340b103d331115bebc4eb813bf83291b63624a0d1475a756c734f9bbc2cd28546ecbe1e20a3794ca175f3fae90 +fb6d2dd99bb07b55e5ccf68942bd0877b23c77b908e8db5f9db7f024d9239010f35bd4bbe2fcae387bfff9e2bc289f2fbe24cfaa301468dd8bd846dbb4ddf1c2 +ae7b4c191ba8292337a469bc25ec3d411f06f53a73e224c5292c8de0516732307070a1c0660d125c7d44553488700a4d7bddd3444299910e254ab984c3a219ae +a4adf1d0f82b7bd46cea4388ad1c12ab5d1ed8e1153d9c9f350a3246aad01c6873462b9ac05999ad5cc988826eafc3acae853a33b7ba11cd1445875ba1b236b1 +399483c90bd560b0b0263435085a21b0f22a9cf9356b38ec6046026d77eba3dc2dc60b17e92219e180643ed27acffba86e9c94c7ca9c225a0f1b0cfae0788ad5 +4adc5a9aec1b703b8b93caec1a0bd8e5de7b132fe5113cf312503b998e2c2927274bd051db6b35979b1ef271daf6c6704e86c73805af4bdd476216c26593af84 +0dfb5393d964f9cc9bad5c313709ea70f561ed3ea7b053075221d51696910d0d339585004b34272bff7213cc7a510a5454a3b349b1b206c1f0af490176745d4b +c663e2abb2b34b23da76f6352ba57ca2881844c1111ab189d8c7e07e1daaa04f40255c77988aa05fe06e4e5bdb4cb9c5394bbaf28d98c1d971ccd20867e556a7 +689ec9166e0a522183792b8907ba55ca6e943bbf2a26e52f48957218ffcf54d1fb09dc3eac04da033e5c0d0b8c74a6b43d2e54c4a10aa511f5fb021a07533b20 +5ae07e17a621a8e082dafc17e450ffb739676998b48643a4daa7211214f623150942f6a02c99e83b85583ddbbb2c4996113211551257a656ec1139246ca86be0 +aadedb3d1441a89b6a929501833b197fee7b9641a3503739e57c732a59b1f7da1cf8a73b1f9bcca0945b874d4393dbbf10b1680f66bbaa5d6f96e77b6f59113d +316bb31a795600b3d256d0cad2fe354538e7566b2bd69cc6cbcd5c38f0e2bcc63058344429dc2121fd07f63f2a7c66bf76e80d75c8f7a1b622f878a18941d840 +545fb28d07d205d20e8ea071b283369834296bdaac75d256cb37eb0bee740bbe278cad253b8bbfcf69eca23973d939b97891c6ce2cecd8da8e2d343578f6648a +c2d0383fc818c798cf64e52f597c740f1cbd05df0c264c49134cf09d4a60e8a107260f20f92d47b374e32f000000ffff0300504b030414000600080000002100 +0dd1909fb60000001b010000270000007468656d652f7468656d652f5f72656c732f7468656d654d616e616765722e786d6c2e72656c73848f4d0ac2301484f7 +8277086f6fd3ba109126dd88d0add40384e4350d363f2451eced0dae2c082e8761be9969bb979dc9136332de3168aa1a083ae995719ac16db8ec8e4052164e89 +d93b64b060828e6f37ed1567914b284d262452282e3198720e274a939cd08a54f980ae38a38f56e422a3a641c8bbd048f7757da0f19b017cc524bd62107bd500 +1996509affb3fd381a89672f1f165dfe514173d9850528a2c6cce0239baa4c04ca5bbabac4df000000ffff0300504b01022d0014000600080000002100e9de0f +bfff0000001c0200001300000000000000000000000000000000005b436f6e74656e745f54797065735d2e786d6c504b01022d0014000600080000002100a5d6 +a7e7c0000000360100000b00000000000000000000000000300100005f72656c732f2e72656c73504b01022d00140006000800000021006b799616830000008a +0000001c00000000000000000000000000190200007468656d652f7468656d652f7468656d654d616e616765722e786d6c504b01022d00140006000800000021 +0030dd4329a8060000a41b00001600000000000000000000000000d60200007468656d652f7468656d652f7468656d65312e786d6c504b01022d001400060008 +00000021000dd1909fb60000001b0100002700000000000000000000000000b20900007468656d652f7468656d652f5f72656c732f7468656d654d616e616765722e786d6c2e72656c73504b050600000000050005005d010000ad0a00000000} +{\*\colorschememapping 3c3f786d6c2076657273696f6e3d22312e302220656e636f64696e673d225554462d3822207374616e64616c6f6e653d22796573223f3e0d0a3c613a636c724d +617020786d6c6e733a613d22687474703a2f2f736368656d61732e6f70656e786d6c666f726d6174732e6f72672f64726177696e676d6c2f323030362f6d6169 +6e22206267313d226c743122207478313d22646b3122206267323d226c743222207478323d22646b322220616363656e74313d22616363656e74312220616363 +656e74323d22616363656e74322220616363656e74333d22616363656e74332220616363656e74343d22616363656e74342220616363656e74353d22616363656e74352220616363656e74363d22616363656e74362220686c696e6b3d22686c696e6b2220666f6c486c696e6b3d22666f6c486c696e6b222f3e} +{\*\latentstyles\lsdstimax267\lsdlockeddef0\lsdsemihiddendef1\lsdunhideuseddef1\lsdqformatdef0\lsdprioritydef99{\lsdlockedexcept \lsdsemihidden0 \lsdunhideused0 \lsdqformat1 \lsdpriority0 \lsdlocked0 Normal; +\lsdsemihidden0 \lsdunhideused0 \lsdqformat1 \lsdpriority9 \lsdlocked0 heading 1;\lsdqformat1 \lsdpriority9 \lsdlocked0 heading 2;\lsdqformat1 \lsdpriority9 \lsdlocked0 heading 3;\lsdqformat1 \lsdpriority9 \lsdlocked0 heading 4; +\lsdqformat1 \lsdpriority9 \lsdlocked0 heading 5;\lsdqformat1 \lsdpriority9 \lsdlocked0 heading 6;\lsdqformat1 \lsdpriority9 \lsdlocked0 heading 7;\lsdqformat1 \lsdpriority9 \lsdlocked0 heading 8;\lsdqformat1 \lsdpriority9 \lsdlocked0 heading 9; +\lsdpriority39 \lsdlocked0 toc 1;\lsdpriority39 \lsdlocked0 toc 2;\lsdpriority39 \lsdlocked0 toc 3;\lsdpriority39 \lsdlocked0 toc 4;\lsdpriority39 \lsdlocked0 toc 5;\lsdpriority39 \lsdlocked0 toc 6;\lsdpriority39 \lsdlocked0 toc 7; +\lsdpriority39 \lsdlocked0 toc 8;\lsdpriority39 \lsdlocked0 toc 9;\lsdqformat1 \lsdpriority35 \lsdlocked0 caption;\lsdsemihidden0 \lsdunhideused0 \lsdqformat1 \lsdpriority10 \lsdlocked0 Title;\lsdpriority1 \lsdlocked0 Default Paragraph Font; +\lsdsemihidden0 \lsdunhideused0 \lsdqformat1 \lsdpriority11 \lsdlocked0 Subtitle;\lsdsemihidden0 \lsdunhideused0 \lsdqformat1 \lsdpriority22 \lsdlocked0 Strong;\lsdsemihidden0 \lsdunhideused0 \lsdqformat1 \lsdpriority20 \lsdlocked0 Emphasis; +\lsdsemihidden0 \lsdunhideused0 \lsdpriority59 \lsdlocked0 Table Grid;\lsdunhideused0 \lsdlocked0 Placeholder Text;\lsdsemihidden0 \lsdunhideused0 \lsdqformat1 \lsdpriority1 \lsdlocked0 No Spacing; +\lsdsemihidden0 \lsdunhideused0 \lsdpriority60 \lsdlocked0 Light Shading;\lsdsemihidden0 \lsdunhideused0 \lsdpriority61 \lsdlocked0 Light List;\lsdsemihidden0 \lsdunhideused0 \lsdpriority62 \lsdlocked0 Light Grid; +\lsdsemihidden0 \lsdunhideused0 \lsdpriority63 \lsdlocked0 Medium Shading 1;\lsdsemihidden0 \lsdunhideused0 \lsdpriority64 \lsdlocked0 Medium Shading 2;\lsdsemihidden0 \lsdunhideused0 \lsdpriority65 \lsdlocked0 Medium List 1; +\lsdsemihidden0 \lsdunhideused0 \lsdpriority66 \lsdlocked0 Medium List 2;\lsdsemihidden0 \lsdunhideused0 \lsdpriority67 \lsdlocked0 Medium Grid 1;\lsdsemihidden0 \lsdunhideused0 \lsdpriority68 \lsdlocked0 Medium Grid 2; +\lsdsemihidden0 \lsdunhideused0 \lsdpriority69 \lsdlocked0 Medium Grid 3;\lsdsemihidden0 \lsdunhideused0 \lsdpriority70 \lsdlocked0 Dark List;\lsdsemihidden0 \lsdunhideused0 \lsdpriority71 \lsdlocked0 Colorful Shading; +\lsdsemihidden0 \lsdunhideused0 \lsdpriority72 \lsdlocked0 Colorful List;\lsdsemihidden0 \lsdunhideused0 \lsdpriority73 \lsdlocked0 Colorful Grid;\lsdsemihidden0 \lsdunhideused0 \lsdpriority60 \lsdlocked0 Light Shading Accent 1; +\lsdsemihidden0 \lsdunhideused0 \lsdpriority61 \lsdlocked0 Light List Accent 1;\lsdsemihidden0 \lsdunhideused0 \lsdpriority62 \lsdlocked0 Light Grid Accent 1;\lsdsemihidden0 \lsdunhideused0 \lsdpriority63 \lsdlocked0 Medium Shading 1 Accent 1; +\lsdsemihidden0 \lsdunhideused0 \lsdpriority64 \lsdlocked0 Medium Shading 2 Accent 1;\lsdsemihidden0 \lsdunhideused0 \lsdpriority65 \lsdlocked0 Medium List 1 Accent 1;\lsdunhideused0 \lsdlocked0 Revision; +\lsdsemihidden0 \lsdunhideused0 \lsdqformat1 \lsdpriority34 \lsdlocked0 List Paragraph;\lsdsemihidden0 \lsdunhideused0 \lsdqformat1 \lsdpriority29 \lsdlocked0 Quote;\lsdsemihidden0 \lsdunhideused0 \lsdqformat1 \lsdpriority30 \lsdlocked0 Intense Quote; +\lsdsemihidden0 \lsdunhideused0 \lsdpriority66 \lsdlocked0 Medium List 2 Accent 1;\lsdsemihidden0 \lsdunhideused0 \lsdpriority67 \lsdlocked0 Medium Grid 1 Accent 1;\lsdsemihidden0 \lsdunhideused0 \lsdpriority68 \lsdlocked0 Medium Grid 2 Accent 1; +\lsdsemihidden0 \lsdunhideused0 \lsdpriority69 \lsdlocked0 Medium Grid 3 Accent 1;\lsdsemihidden0 \lsdunhideused0 \lsdpriority70 \lsdlocked0 Dark List Accent 1;\lsdsemihidden0 \lsdunhideused0 \lsdpriority71 \lsdlocked0 Colorful Shading Accent 1; +\lsdsemihidden0 \lsdunhideused0 \lsdpriority72 \lsdlocked0 Colorful List Accent 1;\lsdsemihidden0 \lsdunhideused0 \lsdpriority73 \lsdlocked0 Colorful Grid Accent 1;\lsdsemihidden0 \lsdunhideused0 \lsdpriority60 \lsdlocked0 Light Shading Accent 2; +\lsdsemihidden0 \lsdunhideused0 \lsdpriority61 \lsdlocked0 Light List Accent 2;\lsdsemihidden0 \lsdunhideused0 \lsdpriority62 \lsdlocked0 Light Grid Accent 2;\lsdsemihidden0 \lsdunhideused0 \lsdpriority63 \lsdlocked0 Medium Shading 1 Accent 2; +\lsdsemihidden0 \lsdunhideused0 \lsdpriority64 \lsdlocked0 Medium Shading 2 Accent 2;\lsdsemihidden0 \lsdunhideused0 \lsdpriority65 \lsdlocked0 Medium List 1 Accent 2;\lsdsemihidden0 \lsdunhideused0 \lsdpriority66 \lsdlocked0 Medium List 2 Accent 2; +\lsdsemihidden0 \lsdunhideused0 \lsdpriority67 \lsdlocked0 Medium Grid 1 Accent 2;\lsdsemihidden0 \lsdunhideused0 \lsdpriority68 \lsdlocked0 Medium Grid 2 Accent 2;\lsdsemihidden0 \lsdunhideused0 \lsdpriority69 \lsdlocked0 Medium Grid 3 Accent 2; +\lsdsemihidden0 \lsdunhideused0 \lsdpriority70 \lsdlocked0 Dark List Accent 2;\lsdsemihidden0 \lsdunhideused0 \lsdpriority71 \lsdlocked0 Colorful Shading Accent 2;\lsdsemihidden0 \lsdunhideused0 \lsdpriority72 \lsdlocked0 Colorful List Accent 2; +\lsdsemihidden0 \lsdunhideused0 \lsdpriority73 \lsdlocked0 Colorful Grid Accent 2;\lsdsemihidden0 \lsdunhideused0 \lsdpriority60 \lsdlocked0 Light Shading Accent 3;\lsdsemihidden0 \lsdunhideused0 \lsdpriority61 \lsdlocked0 Light List Accent 3; +\lsdsemihidden0 \lsdunhideused0 \lsdpriority62 \lsdlocked0 Light Grid Accent 3;\lsdsemihidden0 \lsdunhideused0 \lsdpriority63 \lsdlocked0 Medium Shading 1 Accent 3;\lsdsemihidden0 \lsdunhideused0 \lsdpriority64 \lsdlocked0 Medium Shading 2 Accent 3; +\lsdsemihidden0 \lsdunhideused0 \lsdpriority65 \lsdlocked0 Medium List 1 Accent 3;\lsdsemihidden0 \lsdunhideused0 \lsdpriority66 \lsdlocked0 Medium List 2 Accent 3;\lsdsemihidden0 \lsdunhideused0 \lsdpriority67 \lsdlocked0 Medium Grid 1 Accent 3; +\lsdsemihidden0 \lsdunhideused0 \lsdpriority68 \lsdlocked0 Medium Grid 2 Accent 3;\lsdsemihidden0 \lsdunhideused0 \lsdpriority69 \lsdlocked0 Medium Grid 3 Accent 3;\lsdsemihidden0 \lsdunhideused0 \lsdpriority70 \lsdlocked0 Dark List Accent 3; +\lsdsemihidden0 \lsdunhideused0 \lsdpriority71 \lsdlocked0 Colorful Shading Accent 3;\lsdsemihidden0 \lsdunhideused0 \lsdpriority72 \lsdlocked0 Colorful List Accent 3;\lsdsemihidden0 \lsdunhideused0 \lsdpriority73 \lsdlocked0 Colorful Grid Accent 3; +\lsdsemihidden0 \lsdunhideused0 \lsdpriority60 \lsdlocked0 Light Shading Accent 4;\lsdsemihidden0 \lsdunhideused0 \lsdpriority61 \lsdlocked0 Light List Accent 4;\lsdsemihidden0 \lsdunhideused0 \lsdpriority62 \lsdlocked0 Light Grid Accent 4; +\lsdsemihidden0 \lsdunhideused0 \lsdpriority63 \lsdlocked0 Medium Shading 1 Accent 4;\lsdsemihidden0 \lsdunhideused0 \lsdpriority64 \lsdlocked0 Medium Shading 2 Accent 4;\lsdsemihidden0 \lsdunhideused0 \lsdpriority65 \lsdlocked0 Medium List 1 Accent 4; +\lsdsemihidden0 \lsdunhideused0 \lsdpriority66 \lsdlocked0 Medium List 2 Accent 4;\lsdsemihidden0 \lsdunhideused0 \lsdpriority67 \lsdlocked0 Medium Grid 1 Accent 4;\lsdsemihidden0 \lsdunhideused0 \lsdpriority68 \lsdlocked0 Medium Grid 2 Accent 4; +\lsdsemihidden0 \lsdunhideused0 \lsdpriority69 \lsdlocked0 Medium Grid 3 Accent 4;\lsdsemihidden0 \lsdunhideused0 \lsdpriority70 \lsdlocked0 Dark List Accent 4;\lsdsemihidden0 \lsdunhideused0 \lsdpriority71 \lsdlocked0 Colorful Shading Accent 4; +\lsdsemihidden0 \lsdunhideused0 \lsdpriority72 \lsdlocked0 Colorful List Accent 4;\lsdsemihidden0 \lsdunhideused0 \lsdpriority73 \lsdlocked0 Colorful Grid Accent 4;\lsdsemihidden0 \lsdunhideused0 \lsdpriority60 \lsdlocked0 Light Shading Accent 5; +\lsdsemihidden0 \lsdunhideused0 \lsdpriority61 \lsdlocked0 Light List Accent 5;\lsdsemihidden0 \lsdunhideused0 \lsdpriority62 \lsdlocked0 Light Grid Accent 5;\lsdsemihidden0 \lsdunhideused0 \lsdpriority63 \lsdlocked0 Medium Shading 1 Accent 5; +\lsdsemihidden0 \lsdunhideused0 \lsdpriority64 \lsdlocked0 Medium Shading 2 Accent 5;\lsdsemihidden0 \lsdunhideused0 \lsdpriority65 \lsdlocked0 Medium List 1 Accent 5;\lsdsemihidden0 \lsdunhideused0 \lsdpriority66 \lsdlocked0 Medium List 2 Accent 5; +\lsdsemihidden0 \lsdunhideused0 \lsdpriority67 \lsdlocked0 Medium Grid 1 Accent 5;\lsdsemihidden0 \lsdunhideused0 \lsdpriority68 \lsdlocked0 Medium Grid 2 Accent 5;\lsdsemihidden0 \lsdunhideused0 \lsdpriority69 \lsdlocked0 Medium Grid 3 Accent 5; +\lsdsemihidden0 \lsdunhideused0 \lsdpriority70 \lsdlocked0 Dark List Accent 5;\lsdsemihidden0 \lsdunhideused0 \lsdpriority71 \lsdlocked0 Colorful Shading Accent 5;\lsdsemihidden0 \lsdunhideused0 \lsdpriority72 \lsdlocked0 Colorful List Accent 5; +\lsdsemihidden0 \lsdunhideused0 \lsdpriority73 \lsdlocked0 Colorful Grid Accent 5;\lsdsemihidden0 \lsdunhideused0 \lsdpriority60 \lsdlocked0 Light Shading Accent 6;\lsdsemihidden0 \lsdunhideused0 \lsdpriority61 \lsdlocked0 Light List Accent 6; +\lsdsemihidden0 \lsdunhideused0 \lsdpriority62 \lsdlocked0 Light Grid Accent 6;\lsdsemihidden0 \lsdunhideused0 \lsdpriority63 \lsdlocked0 Medium Shading 1 Accent 6;\lsdsemihidden0 \lsdunhideused0 \lsdpriority64 \lsdlocked0 Medium Shading 2 Accent 6; +\lsdsemihidden0 \lsdunhideused0 \lsdpriority65 \lsdlocked0 Medium List 1 Accent 6;\lsdsemihidden0 \lsdunhideused0 \lsdpriority66 \lsdlocked0 Medium List 2 Accent 6;\lsdsemihidden0 \lsdunhideused0 \lsdpriority67 \lsdlocked0 Medium Grid 1 Accent 6; +\lsdsemihidden0 \lsdunhideused0 \lsdpriority68 \lsdlocked0 Medium Grid 2 Accent 6;\lsdsemihidden0 \lsdunhideused0 \lsdpriority69 \lsdlocked0 Medium Grid 3 Accent 6;\lsdsemihidden0 \lsdunhideused0 \lsdpriority70 \lsdlocked0 Dark List Accent 6; +\lsdsemihidden0 \lsdunhideused0 \lsdpriority71 \lsdlocked0 Colorful Shading Accent 6;\lsdsemihidden0 \lsdunhideused0 \lsdpriority72 \lsdlocked0 Colorful List Accent 6;\lsdsemihidden0 \lsdunhideused0 \lsdpriority73 \lsdlocked0 Colorful Grid Accent 6; +\lsdsemihidden0 \lsdunhideused0 \lsdqformat1 \lsdpriority19 \lsdlocked0 Subtle Emphasis;\lsdsemihidden0 \lsdunhideused0 \lsdqformat1 \lsdpriority21 \lsdlocked0 Intense Emphasis; +\lsdsemihidden0 \lsdunhideused0 \lsdqformat1 \lsdpriority31 \lsdlocked0 Subtle Reference;\lsdsemihidden0 \lsdunhideused0 \lsdqformat1 \lsdpriority32 \lsdlocked0 Intense Reference; +\lsdsemihidden0 \lsdunhideused0 \lsdqformat1 \lsdpriority33 \lsdlocked0 Book Title;\lsdpriority37 \lsdlocked0 Bibliography;\lsdqformat1 \lsdpriority39 \lsdlocked0 TOC Heading;}}{\*\datastore 010500000200000018000000 +4d73786d6c322e534158584d4c5265616465722e362e3000000000000000000000060000 +d0cf11e0a1b11ae1000000000000000000000000000000003e000300feff090006000000000000000000000001000000010000000000000000100000feffffff00000000feffffff0000000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff +ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff +ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff +ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff +fffffffffffffffffdfffffffeffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff +ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff +ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff +ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff +ffffffffffffffffffffffffffffffff52006f006f007400200045006e00740072007900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000016000500ffffffffffffffffffffffff0c6ad98892f1d411a65f0040963251e500000000000000000000000050f6 +efc420d2ce01feffffff00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ffffffffffffffffffffffff00000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ffffffffffffffffffffffff0000000000000000000000000000000000000000000000000000 +000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ffffffffffffffffffffffff000000000000000000000000000000000000000000000000 +0000000000000000000000000000000000000000000000000105000000000000}} \ No newline at end of file diff --git a/vendor/MDBC/win/packaging/mariadb-connector-c.xml.in b/vendor/MDBC/win/packaging/mariadb-connector-c.xml.in new file mode 100644 index 00000000..f3d03c16 --- /dev/null +++ b/vendor/MDBC/win/packaging/mariadb-connector-c.xml.in @@ -0,0 +1,79 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @MARIADB_PLUGINS@ + + + @MARIADB_INCLUDE_FILES@ + + + + @MARIADB_INCLUDEMYSQL_FILES@ + + + + diff --git a/vendor/MDBC/win/resource.rc.in b/vendor/MDBC/win/resource.rc.in new file mode 100644 index 00000000..399c88cb --- /dev/null +++ b/vendor/MDBC/win/resource.rc.in @@ -0,0 +1,34 @@ +#include "winver.h" + +VS_VERSION_INFO VERSIONINFO + FILEVERSION 3,0,0,7 + PRODUCTVERSION 3,0,0,0 + FILEFLAGSMASK 0x3fL +#ifdef _DEBUG + FILEFLAGS 0x1L +#else + FILEFLAGS 0x0L +#endif + FILEOS 0x40004L + FILETYPE @FILE_TYPE@ + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "000904b0" + BEGIN + VALUE "CompanyName", "MariaDB Corporation AB" + VALUE "FileDescription", "@FILE_DESCRIPTION@" + VALUE "FileVersion", "@CPACK_PACKAGE_VERSION_MAJOR@.@CPACK_PACKAGE_VERSION_MINOR@.@CPACK_PACKAGE_VERSION_PATCH@.@FILE_VERSION@" + VALUE "LegalCopyright", "2013-2018 MariaDB Corporation Ab" + VALUE "ProductName", "MariaDB Connector/C" + VALUE "ProductVersion", "@CPACK_PACKAGE_VERSION_MAJOR@.@CPACK_PACKAGE_VERSION_MINOR@.@CPACK_PACKAGE_VERSION_PATCH@" + VALUE "OriginalFilename", "@ORIGINAL_FILE_NAME@" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x9, 1200 + END +END + diff --git a/vendor/POCO/CMakeLists.txt b/vendor/POCO/CMakeLists.txt index 4e052729..e39512fc 100644 --- a/vendor/POCO/CMakeLists.txt +++ b/vendor/POCO/CMakeLists.txt @@ -113,10 +113,16 @@ else() option(ENABLE_APACHECONNECTOR "Enable ApacheConnector" OFF) endif() -if(ENABLE_DATA_MYSQL) - find_package(MySQL REQUIRED) +if (NOT ENABLE_BUILTIN_MYSQL_C) + if(ENABLE_DATA_MYSQL) + find_package(MySQL REQUIRED) + else() + find_package(MySQL) + endif() else() - find_package(MySQL) + SET(MYSQL_FOUND TRUE) + SET(MYSQL_LIBRARIES "mariadbclient") + get_target_property(MYSQL_INCLUDE_DIRS mariadbclient INCLUDE_DIRECTORIES) endif() if(MYSQL_FOUND) diff --git a/vendor/POCO/Data/CMakeLists.txt b/vendor/POCO/Data/CMakeLists.txt index 7d1e99ea..30c39024 100644 --- a/vendor/POCO/Data/CMakeLists.txt +++ b/vendor/POCO/Data/CMakeLists.txt @@ -45,7 +45,7 @@ else(ENABLE_DATA_SQLITE) message(STATUS "SQLite Support Disabled") endif() -if(MYSQL_FOUND AND ENABLE_DATA_MYSQL) +if((ENABLE_BUILTIN_MYSQL_C OR MYSQL_FOUND) AND ENABLE_DATA_MYSQL) message(STATUS "MySQL Support Enabled") add_subdirectory(MySQL) else() diff --git a/vendor/POCO/Data/MySQL/CMakeLists.txt b/vendor/POCO/Data/MySQL/CMakeLists.txt index 5c6088eb..69e49a03 100644 --- a/vendor/POCO/Data/MySQL/CMakeLists.txt +++ b/vendor/POCO/Data/MySQL/CMakeLists.txt @@ -20,8 +20,11 @@ set_target_properties(DataMySQL OUTPUT_NAME PocoDataMySQL DEFINE_SYMBOL MySQL_EXPORTS ) - -target_link_libraries(DataMySQL PUBLIC Poco::Data MySQL::client) +if (ENABLE_BUILTIN_MYSQL_C) + target_link_libraries(DataMySQL PUBLIC Poco::Data mariadbclient) +else() + target_link_libraries(DataMySQL PUBLIC Poco::Data MySQL::client) +endif() target_include_directories(DataMySQL PUBLIC $ @@ -43,8 +46,11 @@ if(UNIX) endif() endif() -POCO_INSTALL(DataMySQL) -POCO_GENERATE_PACKAGE(DataMySQL) +# Meh... +if (NOT ENABLE_BUILTIN_MYSQL_C) + POCO_INSTALL(DataMySQL) + POCO_GENERATE_PACKAGE(DataMySQL) +endif() if(ENABLE_TESTS) add_subdirectory(testsuite)