From f1006fa62041f5d21bf15f4fcf397c42ebec4480 Mon Sep 17 00:00:00 2001 From: "jimw@mysql.com" <> Date: Wed, 5 Oct 2005 12:54:04 -0700 Subject: [PATCH 001/108] In the command-line client, try to abort the current query by issuing a KILL command on a second connection when handling Ctrl-C. (WL#2852) Based on patch by Harrison Fisk. --- client/mysql.cc | 59 ++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 53 insertions(+), 6 deletions(-) diff --git a/client/mysql.cc b/client/mysql.cc index d82d29a9a54..965d4116873 100644 --- a/client/mysql.cc +++ b/client/mysql.cc @@ -135,7 +135,8 @@ static my_bool info_flag=0,ignore_errors=0,wait_flag=0,quick=0, opt_xml=0,opt_nopager=1, opt_outfile=0, named_cmds= 0, tty_password= 0, opt_nobeep=0, opt_reconnect=1, default_charset_used= 0, opt_secure_auth= 0, - default_pager_set= 0, opt_sigint_ignore= 0; + default_pager_set= 0, opt_sigint_ignore= 0, + executing_query= 0, interrupted_query= 0; static ulong opt_max_allowed_packet, opt_net_buffer_length; static uint verbose=0,opt_silent=0,opt_mysql_port=0, opt_local_infile=0; static my_string opt_mysql_unix_port=0; @@ -325,7 +326,7 @@ static void end_timer(ulong start_time,char *buff); static void mysql_end_timer(ulong start_time,char *buff); static void nice_time(double sec,char *buff,bool part_second); static sig_handler mysql_end(int sig); - +static sig_handler handle_sigint(int sig); int main(int argc,char *argv[]) { @@ -408,7 +409,7 @@ int main(int argc,char *argv[]) if (opt_sigint_ignore) signal(SIGINT, SIG_IGN); else - signal(SIGINT, mysql_end); // Catch SIGINT to clean up + signal(SIGINT, handle_sigint); // Catch SIGINT to clean up signal(SIGQUIT, mysql_end); // Catch SIGQUIT to clean up /* @@ -502,6 +503,35 @@ sig_handler mysql_end(int sig) } +/* + This function handles sigint calls + If query is in process, kill query + no query in process, terminate like previous behavior + */ +sig_handler handle_sigint(int sig) +{ + char kill_buffer[40]; + MYSQL *kill_mysql= NULL; + + /* terminate if no query being executed, or we already tried interrupting */ + if (!executing_query || interrupted_query) + mysql_end(sig); + + kill_mysql= mysql_init(kill_mysql); + if (!mysql_real_connect(kill_mysql,current_host, current_user, opt_password, + "", opt_mysql_port, opt_mysql_unix_port,0)) + mysql_end(sig); + + /* kill_buffer is always big enough because max length of %lu is 15 */ + sprintf(kill_buffer, "KILL /*!50000 QUERY */ %lu", mysql_thread_id(&mysql)); + mysql_real_query(kill_mysql, kill_buffer, strlen(kill_buffer)); + mysql_close(kill_mysql); + tee_fprintf(stdout, "Query aborted by Ctrl+C\n"); + + interrupted_query= 1; +} + + static struct my_option my_long_options[] = { {"help", '?', "Display this help and exit.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, @@ -1858,6 +1888,7 @@ com_go(String *buffer,char *line __attribute__((unused))) uint error= 0; int err= 0; + interrupted_query= 0; if (!status.batch) { old_buffer= *buffer; // Save for edit command @@ -1893,7 +1924,7 @@ com_go(String *buffer,char *line __attribute__((unused))) } timer=start_timer(); - + executing_query= 1; error= mysql_real_query_for_lazy(buffer->ptr(),buffer->length()); #ifdef HAVE_READLINE @@ -1907,6 +1938,7 @@ com_go(String *buffer,char *line __attribute__((unused))) if (error) { + executing_query= 0; buffer->length(0); // Remove query on error return error; } @@ -1918,13 +1950,19 @@ com_go(String *buffer,char *line __attribute__((unused))) if (quick) { if (!(result=mysql_use_result(&mysql)) && mysql_field_count(&mysql)) - return put_error(&mysql); + { + executing_query= 0; + return put_error(&mysql); + } } else { error= mysql_store_result_for_lazy(&result); if (error) - return error; + { + executing_query= 0; + return error; + } } if (verbose >= 3 || !opt_silent) @@ -1992,6 +2030,7 @@ com_go(String *buffer,char *line __attribute__((unused))) (mysql.server_status & SERVER_STATUS_DB_DROPPED)) get_current_db(); + executing_query= 0; return error; /* New command follows */ } @@ -2122,6 +2161,8 @@ print_table_data(MYSQL_RES *result) while ((cur= mysql_fetch_row(result))) { + if (interrupted_query) + break; ulong *lengths= mysql_fetch_lengths(result); (void) tee_fputs("|", PAGER); mysql_field_seek(result, 0); @@ -2171,6 +2212,8 @@ print_table_data_html(MYSQL_RES *result) } while ((cur = mysql_fetch_row(result))) { + if (interrupted_query) + break; ulong *lengths=mysql_fetch_lengths(result); (void) tee_fputs("", PAGER); for (uint i=0; i < mysql_num_fields(result); i++) @@ -2200,6 +2243,8 @@ print_table_data_xml(MYSQL_RES *result) fields = mysql_fetch_fields(result); while ((cur = mysql_fetch_row(result))) { + if (interrupted_query) + break; ulong *lengths=mysql_fetch_lengths(result); (void) tee_fputs("\n \n", PAGER); for (uint i=0; i < mysql_num_fields(result); i++) @@ -2236,6 +2281,8 @@ print_table_data_vertically(MYSQL_RES *result) mysql_field_seek(result,0); for (uint row_count=1; (cur= mysql_fetch_row(result)); row_count++) { + if (interrupted_query) + break; mysql_field_seek(result,0); tee_fprintf(PAGER, "*************************** %d. row ***************************\n", row_count); From db8344aa6fbac555fd6979b8287519b6d0a359e8 Mon Sep 17 00:00:00 2001 From: "mats@mysql.com" <> Date: Wed, 1 Mar 2006 11:48:33 +0100 Subject: [PATCH 002/108] Removing unnecessary assertion. --- sql/sql_base.cc | 2 -- 1 file changed, 2 deletions(-) diff --git a/sql/sql_base.cc b/sql/sql_base.cc index f48df61e9a1..074747cab18 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -2409,7 +2409,6 @@ void abort_locked_tables(THD *thd,const char *db, const char *table_name) share is non-NULL The LOCK_open mutex is locked - The share->mutex is locked POST-CONDITION(S) @@ -2429,7 +2428,6 @@ void assign_new_table_id(TABLE_SHARE *share) /* Preconditions */ DBUG_ASSERT(share != NULL); safe_mutex_assert_owner(&LOCK_open); - safe_mutex_assert_owner(&share->mutex); ulong tid= ++last_table_id; /* get next id */ /* From 2d8f8ac6e1a1c91c247b7546716c44e413aa5729 Mon Sep 17 00:00:00 2001 From: "kent@mysql.com" <> Date: Thu, 6 Apr 2006 00:43:58 +0200 Subject: [PATCH 003/108] configure.in: Check for crypt() in libc first (bug#16478) --- configure.in | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/configure.in b/configure.in index b230b7f042e..9123f87924d 100644 --- a/configure.in +++ b/configure.in @@ -827,9 +827,8 @@ AC_CHECK_FUNC(yp_get_default_domain, , AC_CHECK_FUNC(p2open, , AC_CHECK_LIB(gen, p2open)) # This may get things to compile even if bind-8 is installed AC_CHECK_FUNC(bind, , AC_CHECK_LIB(bind, bind)) -# For crypt() on Linux -AC_CHECK_LIB(crypt, crypt) -AC_CHECK_FUNC(crypt, AC_DEFINE([HAVE_CRYPT], [1], [crypt])) +# Check if crypt() exists in libc or libcrypt, sets LIBS if needed +AC_SEARCH_LIBS(crypt, crypt, AC_DEFINE(HAVE_CRYPT, 1, [crypt])) # For sem_xxx functions on Solaris 2.6 AC_CHECK_FUNC(sem_init, , AC_CHECK_LIB(posix4, sem_init)) From e8723ca453c4bef12083ca7252aef1814cda1458 Mon Sep 17 00:00:00 2001 From: "msvensson@shellback.(none)" <> Date: Fri, 7 Apr 2006 11:35:12 +0200 Subject: [PATCH 004/108] Update yassl to 1.2.2 --- extra/yassl/README | 135 +- extra/yassl/examples/client/client.cpp | 96 ++ extra/yassl/examples/client/client.dsp | 102 ++ .../yassl/examples/echoclient/echoclient.cpp | 89 + .../yassl/examples/echoclient/echoclient.dsp | 102 ++ extra/yassl/examples/echoclient/input | 93 ++ extra/yassl/examples/echoclient/quit | 2 + .../yassl/examples/echoserver/echoserver.cpp | 126 ++ .../yassl/examples/echoserver/echoserver.dsp | 102 ++ extra/yassl/examples/server/server.cpp | 73 + extra/yassl/examples/server/server.dsp | 109 ++ extra/yassl/include/cert_wrapper.hpp | 3 + extra/yassl/include/crypto_wrapper.hpp | 6 +- extra/yassl/include/openssl/ssl.h | 7 +- extra/yassl/include/socket_wrapper.hpp | 2 +- extra/yassl/include/yassl.hpp | 88 + extra/yassl/include/yassl_error.hpp | 4 + extra/yassl/include/yassl_imp.hpp | 2 +- extra/yassl/include/yassl_int.hpp | 8 +- extra/yassl/include/yassl_types.hpp | 73 +- extra/yassl/mySTL/helpers.hpp | 8 +- extra/yassl/mySTL/list.hpp | 4 +- extra/yassl/mySTL/vector.hpp | 3 +- extra/yassl/src/buffer.cpp | 15 +- extra/yassl/src/cert_wrapper.cpp | 34 +- extra/yassl/src/crypto_wrapper.cpp | 58 +- extra/yassl/src/handshake.cpp | 47 +- extra/yassl/src/make.bat | 27 + extra/yassl/src/socket_wrapper.cpp | 26 +- extra/yassl/src/ssl.cpp | 137 +- extra/yassl/src/timer.cpp | 12 +- extra/yassl/src/yassl.cpp | 244 +++ extra/yassl/src/yassl_error.cpp | 179 ++ extra/yassl/src/yassl_imp.cpp | 112 +- extra/yassl/src/yassl_int.cpp | 163 +- extra/yassl/taocrypt/benchmark/benchmark.cpp | 440 +++++ extra/yassl/taocrypt/benchmark/benchmark.dsp | 101 ++ extra/yassl/taocrypt/benchmark/make.bat | 10 + extra/yassl/taocrypt/include/aes.hpp | 42 +- extra/yassl/taocrypt/include/arc4.hpp | 1 + extra/yassl/taocrypt/include/asn.hpp | 13 +- extra/yassl/taocrypt/include/block.hpp | 2 +- extra/yassl/taocrypt/include/blowfish.hpp | 79 + extra/yassl/taocrypt/include/des.hpp | 82 +- extra/yassl/taocrypt/include/dh.hpp | 2 +- extra/yassl/taocrypt/include/hash.hpp | 13 +- extra/yassl/taocrypt/include/hmac.hpp | 10 +- extra/yassl/taocrypt/include/kernelc.hpp | 49 + extra/yassl/taocrypt/include/md5.hpp | 3 + extra/yassl/taocrypt/include/misc.hpp | 159 +- extra/yassl/taocrypt/include/modes.hpp | 15 +- extra/yassl/taocrypt/include/pwdbased.hpp | 93 ++ extra/yassl/taocrypt/include/ripemd.hpp | 2 + extra/yassl/taocrypt/include/runtime.hpp | 10 +- extra/yassl/taocrypt/include/sha.hpp | 2 + extra/yassl/taocrypt/include/twofish.hpp | 86 + extra/yassl/taocrypt/include/types.hpp | 3 +- extra/yassl/taocrypt/src/aes.cpp | 1453 ++++++++++++++++- extra/yassl/taocrypt/src/aestables.cpp | 683 -------- extra/yassl/taocrypt/src/algebra.cpp | 2 + extra/yassl/taocrypt/src/arc4.cpp | 136 ++ extra/yassl/taocrypt/src/asn.cpp | 39 +- extra/yassl/taocrypt/src/bftables.cpp | 306 ++++ extra/yassl/taocrypt/src/blowfish.cpp | 358 ++++ extra/yassl/taocrypt/src/coding.cpp | 7 +- extra/yassl/taocrypt/src/des.cpp | 623 +++++-- extra/yassl/taocrypt/src/dh.cpp | 28 +- extra/yassl/taocrypt/src/hash.cpp | 29 +- extra/yassl/taocrypt/src/integer.cpp | 18 +- extra/yassl/taocrypt/src/make.bat | 38 + extra/yassl/taocrypt/src/md5.cpp | 347 +++- extra/yassl/taocrypt/src/misc.cpp | 60 +- extra/yassl/taocrypt/src/random.cpp | 7 +- extra/yassl/taocrypt/src/ripemd.cpp | 577 ++++++- extra/yassl/taocrypt/src/sha.cpp | 483 +++++- extra/yassl/taocrypt/src/tftables.cpp | 352 ++++ extra/yassl/taocrypt/src/twofish.cpp | 591 +++++++ extra/yassl/taocrypt/taocrypt.dsp | 40 +- extra/yassl/taocrypt/test.dsp | 102 ++ extra/yassl/taocrypt/test.dsw | 29 + extra/yassl/taocrypt/test/make.bat | 9 + extra/yassl/taocrypt/test/memory.cpp | 312 ++++ extra/yassl/taocrypt/test/test.cpp | 947 +++++++++++ extra/yassl/testsuite/input | 107 ++ extra/yassl/testsuite/make.bat | 14 + extra/yassl/testsuite/quit | 2 + extra/yassl/testsuite/test.hpp | 352 ++++ extra/yassl/testsuite/testsuite.cpp | 155 ++ extra/yassl/testsuite/testsuite.dsp | 127 ++ extra/yassl/yassl.dsp | 4 +- extra/yassl/yassl.dsw | 15 + 91 files changed, 10544 insertions(+), 1316 deletions(-) create mode 100644 extra/yassl/examples/client/client.cpp create mode 100644 extra/yassl/examples/client/client.dsp create mode 100644 extra/yassl/examples/echoclient/echoclient.cpp create mode 100644 extra/yassl/examples/echoclient/echoclient.dsp create mode 100644 extra/yassl/examples/echoclient/input create mode 100644 extra/yassl/examples/echoclient/quit create mode 100644 extra/yassl/examples/echoserver/echoserver.cpp create mode 100644 extra/yassl/examples/echoserver/echoserver.dsp create mode 100644 extra/yassl/examples/server/server.cpp create mode 100644 extra/yassl/examples/server/server.dsp create mode 100644 extra/yassl/include/yassl.hpp create mode 100644 extra/yassl/src/make.bat create mode 100644 extra/yassl/src/yassl.cpp create mode 100644 extra/yassl/taocrypt/benchmark/benchmark.cpp create mode 100644 extra/yassl/taocrypt/benchmark/benchmark.dsp create mode 100644 extra/yassl/taocrypt/benchmark/make.bat create mode 100644 extra/yassl/taocrypt/include/blowfish.hpp create mode 100644 extra/yassl/taocrypt/include/kernelc.hpp create mode 100644 extra/yassl/taocrypt/include/pwdbased.hpp create mode 100644 extra/yassl/taocrypt/include/twofish.hpp create mode 100644 extra/yassl/taocrypt/src/bftables.cpp create mode 100644 extra/yassl/taocrypt/src/blowfish.cpp create mode 100644 extra/yassl/taocrypt/src/make.bat create mode 100644 extra/yassl/taocrypt/src/tftables.cpp create mode 100644 extra/yassl/taocrypt/src/twofish.cpp create mode 100644 extra/yassl/taocrypt/test.dsp create mode 100644 extra/yassl/taocrypt/test.dsw create mode 100644 extra/yassl/taocrypt/test/make.bat create mode 100644 extra/yassl/taocrypt/test/memory.cpp create mode 100644 extra/yassl/taocrypt/test/test.cpp create mode 100644 extra/yassl/testsuite/input create mode 100644 extra/yassl/testsuite/make.bat create mode 100644 extra/yassl/testsuite/quit create mode 100644 extra/yassl/testsuite/test.hpp create mode 100644 extra/yassl/testsuite/testsuite.cpp create mode 100644 extra/yassl/testsuite/testsuite.dsp diff --git a/extra/yassl/README b/extra/yassl/README index 198a1031cb7..ad59fe3965e 100644 --- a/extra/yassl/README +++ b/extra/yassl/README @@ -1,4 +1,137 @@ -yaSSL Release notes, version 0.9.6 +yaSSL Release notes, version 1.2.2 (03/27/06) + + + This release of yaSSL contains minor bug fixes and portability enhancements. + +See build instructions below under 1.0.6: + + + +*******************yaSSL Release notes, version 1.2.0 + + + This release of yaSSL contains minor bug fixes, portability enhancements, + Diffie-Hellman compatibility fixes for other servers and client, + optimization improvements, and x86 ASM changes. + +See build instructions below under 1.0.6: + + + +*****************yaSSL Release notes, version 1.1.5 + + This release of yaSSL contains minor bug fixes, portability enhancements, + and user requested changes including the ability to add all certificates in + a directory, more robust socket handling, no new overloading unless + requested, and an SSL_VERIFY_NONE option. + + +See build instructions below under 1.0.6: + + + +******************yaSSL Release notes, version 1.0.6 + +This release of yaSSL contains minor bug fixes, portability enhancements, +x86 assembly for ARC4, SHA, MD5, and RIPEMD, --enable-ia32-asm configure +option, and a security patch for certificate chain processing. + +--To build on Linux, Solaris, *BSD, Mac OS X, or Cygwin: + + ./configure + make + + run testsuite from yaSSL-Home/testsuite to test the build + +to make a release build: + + ./configure --disable-debug + make + + run testsuite from yaSSL-Home/testsuite to test the build + + +--To build on Win32 + +Choose (Re)Build All from the project workspace + +run Debug\testsuite.exe from yaSSL-Home\testsuite to test the build + + +--To enable ia32 assembly for TaoCrypt ciphers and message digests + + On MSVC this is always on + + On GCC **, use ./configure --enable-ia32-asm + + ** This isn't on by default because of the use of intel syntax and the + problem that olders versions of gas have with some addressing statements. + If you enable this and get assemler errors during compilation or can't + pass the TaoCrypt tests, please send todd@yassl.com a message and disable + this option in the meantime. + + +***************** yaSSL Release notes, version 1.0.5 + +This release of yaSSL contains minor bug fixes, portability enhancements, +x86 assembly for AES, 3DES, BLOWFISH, and TWOFISH, --without-debug configure +option, and --enable-kernel-mode configure option for using TaoCrypt with +kernel modules. + +--To build on Linux, Solaris, *BSD, Mac OS X, or Cygwin: + + ./configure + make + + run testsuite from yaSSL-Home/testsuite to test the build + +to make a release build: + + ./configure --without-debug + make + + run testsuite from yaSSL-Home/testsuite to test the build + + +--To build on Win32 + +Choose (Re)Build All from the project workspace + +run Debug\testsuite.exe from yaSSL-Home\testsuite to test the build + + +******************yaSSL Release notes, version 1.0.1 + +This release of yaSSL contains minor bug fixes, portability enhancements, +GCC 3.4.4 support, MSVC 2003 support, and more documentation. + +Please see build instructions in the release notes for 0.9.6 below. + + +******************yaSSL Release notes, version 1.0 + +This release of yaSSL contains minor bug fixes, portability enhancements, +GCC 4.0 support, testsuite, improvements, and API additions. + +Please see build instructions in the release notes for 0.9.6 below. + + +******************yaSSL Release notes, version 0.9.9 + +This release of yaSSL contains minor bug fixes, portability enchancements, +MSVC 7 support, memory improvements, and API additions. + +Please see build instructions in the release notes for 0.9.6 below. + + +******************yaSSL Release notes, version 0.9.8 + +This release of yaSSL contains minor bug fixes and portability enchancements. + +Please see build instructions in the release notes for 0.9.6 below. + + +******************yaSSL Release notes, version 0.9.6 This release of yaSSL contains minor bug fixes, removal of STL support, and removal of exceptions and rtti so that the library can be linked without the diff --git a/extra/yassl/examples/client/client.cpp b/extra/yassl/examples/client/client.cpp new file mode 100644 index 00000000000..704a8e76637 --- /dev/null +++ b/extra/yassl/examples/client/client.cpp @@ -0,0 +1,96 @@ +/* client.cpp */ + +#include "../../testsuite/test.hpp" + +//#define TEST_RESUME + + +void client_test(void* args) +{ +#ifdef _WIN32 + WSADATA wsd; + WSAStartup(0x0002, &wsd); +#endif + + SOCKET_T sockfd = 0; + int argc = 0; + char** argv = 0; + + set_args(argc, argv, *static_cast(args)); + tcp_connect(sockfd); + + SSL_METHOD* method = TLSv1_client_method(); + SSL_CTX* ctx = SSL_CTX_new(method); + + set_certs(ctx); + SSL* ssl = SSL_new(ctx); + + SSL_set_fd(ssl, sockfd); + + if (SSL_connect(ssl) != SSL_SUCCESS) err_sys("SSL_connect failed"); + showPeer(ssl); + + const char* cipher = 0; + int index = 0; + char list[1024]; + strcpy(list, "cipherlist"); + while ( (cipher = SSL_get_cipher_list(ssl, index++)) ) { + strcat(list, ":"); + strcat(list, cipher); + } + printf("%s\n", list); + printf("Using Cipher Suite %s\n", SSL_get_cipher(ssl)); + + char msg[] = "hello yassl!"; + if (SSL_write(ssl, msg, sizeof(msg)) != sizeof(msg)) + err_sys("SSL_write failed"); + + char reply[1024]; + reply[SSL_read(ssl, reply, sizeof(reply))] = 0; + printf("Server response: %s\n", reply); + +#ifdef TEST_RESUME + SSL_SESSION* session = SSL_get_session(ssl); + SSL* sslResume = SSL_new(ctx); +#endif + + SSL_shutdown(ssl); + SSL_free(ssl); + +#ifdef TEST_RESUME + tcp_connect(sockfd); + SSL_set_fd(sslResume, sockfd); + SSL_set_session(sslResume, session); + + if (SSL_connect(sslResume) != SSL_SUCCESS) err_sys("SSL resume failed"); + + if (SSL_write(sslResume, msg, sizeof(msg)) != sizeof(msg)) + err_sys("SSL_write failed"); + + reply[SSL_read(sslResume, reply, sizeof(reply))] = 0; + printf("Server response: %s\n", reply); + + SSL_shutdown(sslResume); + SSL_free(sslResume); +#endif // TEST_RESUME + + SSL_CTX_free(ctx); + ((func_args*)args)->return_code = 0; +} + + +#ifndef NO_MAIN_DRIVER + + int main(int argc, char** argv) + { + func_args args; + + args.argc = argc; + args.argv = argv; + + client_test(&args); + return args.return_code; + } + +#endif // NO_MAIN_DRIVER + diff --git a/extra/yassl/examples/client/client.dsp b/extra/yassl/examples/client/client.dsp new file mode 100644 index 00000000000..1caa585dadb --- /dev/null +++ b/extra/yassl/examples/client/client.dsp @@ -0,0 +1,102 @@ +# Microsoft Developer Studio Project File - Name="client" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=client - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "client.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "client.mak" CFG="client - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "client - Win32 Release" (based on "Win32 (x86) Console Application") +!MESSAGE "client - Win32 Debug" (based on "Win32 (x86) Console Application") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +RSC=rc.exe + +!IF "$(CFG)" == "client - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Release" +# PROP Intermediate_Dir "Release" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD CPP /nologo /MT /W3 /O2 /I "..\..\taocrypt\include" /I "..\..\include" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib Ws2_32.lib /nologo /subsystem:console /machine:I386 + +!ELSEIF "$(CFG)" == "client - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Debug" +# PROP Intermediate_Dir "Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c +# ADD CPP /nologo /MTd /W3 /Gm /ZI /Od /I "..\..\include" /I "..\..\taocrypt\include" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FR /YX /FD /GZ /c +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib Ws2_32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept + +!ENDIF + +# Begin Target + +# Name "client - Win32 Release" +# Name "client - Win32 Debug" +# Begin Group "Source Files" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=.\client.cpp +# End Source File +# End Group +# Begin Group "Header Files" + +# PROP Default_Filter "h;hpp;hxx;hm;inl" +# End Group +# Begin Group "Resource Files" + +# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" +# End Group +# End Target +# End Project diff --git a/extra/yassl/examples/echoclient/echoclient.cpp b/extra/yassl/examples/echoclient/echoclient.cpp new file mode 100644 index 00000000000..ca557cca8af --- /dev/null +++ b/extra/yassl/examples/echoclient/echoclient.cpp @@ -0,0 +1,89 @@ +/* echoclient.cpp */ + +#include "../../testsuite/test.hpp" + + +void echoclient_test(void* args) +{ +#ifdef _WIN32 + WSADATA wsd; + WSAStartup(0x0002, &wsd); +#endif + + SOCKET_T sockfd = 0; + int argc = 0; + char** argv = 0; + + FILE* fin = stdin; + FILE* fout = stdout; + + bool inCreated = false; + bool outCreated = false; + + set_args(argc, argv, *static_cast(args)); + if (argc >= 2) { + fin = fopen(argv[1], "r"); + inCreated = true; + } + if (argc >= 3) { + fout = fopen(argv[2], "w"); + outCreated = true; + } + + if (!fin) err_sys("can't open input file"); + if (!fout) err_sys("can't open output file"); + + tcp_connect(sockfd); + + SSL_METHOD* method = TLSv1_client_method(); + SSL_CTX* ctx = SSL_CTX_new(method); + set_certs(ctx); + SSL* ssl = SSL_new(ctx); + + SSL_set_fd(ssl, sockfd); + if (SSL_connect(ssl) != SSL_SUCCESS) err_sys("SSL_connect failed"); + + char send[1024]; + char reply[1024]; + + while (fgets(send, sizeof(send), fin)) { + + int sendSz = strlen(send) + 1; + if (SSL_write(ssl, send, sendSz) != sendSz) + err_sys("SSL_write failed"); + + if (strncmp(send, "quit", 4) == 0) { + fputs("sending server shutdown command: quit!\n", fout); + break; + } + + if (SSL_read(ssl, reply, sizeof(reply)) > 0) + fputs(reply, fout); + } + + SSL_CTX_free(ctx); + SSL_free(ssl); + + fflush(fout); + if (inCreated) fclose(fin); + if (outCreated) fclose(fout); + + ((func_args*)args)->return_code = 0; +} + + +#ifndef NO_MAIN_DRIVER + + int main(int argc, char** argv) + { + func_args args; + + args.argc = argc; + args.argv = argv; + + echoclient_test(&args); + + return args.return_code; + } + +#endif // NO_MAIN_DRIVER diff --git a/extra/yassl/examples/echoclient/echoclient.dsp b/extra/yassl/examples/echoclient/echoclient.dsp new file mode 100644 index 00000000000..52052c6dc44 --- /dev/null +++ b/extra/yassl/examples/echoclient/echoclient.dsp @@ -0,0 +1,102 @@ +# Microsoft Developer Studio Project File - Name="echoclient" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=echoclient - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "echoclient.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "echoclient.mak" CFG="echoclient - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "echoclient - Win32 Release" (based on "Win32 (x86) Console Application") +!MESSAGE "echoclient - Win32 Debug" (based on "Win32 (x86) Console Application") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +RSC=rc.exe + +!IF "$(CFG)" == "echoclient - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Release" +# PROP Intermediate_Dir "Release" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD CPP /nologo /MT /W3 /O2 /I "..\..\include" /I "..\..\taocrypt\include" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib Ws2_32.lib /nologo /subsystem:console /machine:I386 + +!ELSEIF "$(CFG)" == "echoclient - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Debug" +# PROP Intermediate_Dir "Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c +# ADD CPP /nologo /MTd /W3 /Gm /ZI /Od /I "..\..\include" /I "..\..\taocrypt\include" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /FR /YX /FD /GZ /c +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib Ws2_32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept + +!ENDIF + +# Begin Target + +# Name "echoclient - Win32 Release" +# Name "echoclient - Win32 Debug" +# Begin Group "Source Files" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=.\echoclient.cpp +# End Source File +# End Group +# Begin Group "Header Files" + +# PROP Default_Filter "h;hpp;hxx;hm;inl" +# End Group +# Begin Group "Resource Files" + +# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" +# End Group +# End Target +# End Project diff --git a/extra/yassl/examples/echoclient/input b/extra/yassl/examples/echoclient/input new file mode 100644 index 00000000000..438a592852c --- /dev/null +++ b/extra/yassl/examples/echoclient/input @@ -0,0 +1,93 @@ +/* echoclient.cpp */ + +#include "openssl/ssl.h" /* openssl compatibility test */ +#include +#include + + +#ifdef WIN32 + #include +#else + #include + #include + #include + #include + #include + #include + #include + #include +#endif /* WIN32 */ + + +void err_sys(const char* msg) +{ + fputs("yassl client error: ", stderr); + fputs(msg, stderr); + exit(EXIT_FAILURE); +} + +const char* loopback = "127.0.0.1"; +const short yasslPort = 11111; + +using namespace yaSSL; + + +int main(int argc, char** argv) +{ +#ifdef WIN32 + WSADATA wsd; + WSAStartup(0x0002, &wsd); + int sockfd; +#else + unsigned int sockfd; +#endif /* WIN32 */ + + FILE* fin = stdin; + FILE* fout = stdout; + + if (argc >= 2) fin = fopen(argv[1], "r"); + if (argc >= 3) fout = fopen(argv[2], "w"); + + if (!fin) err_sys("can't open input file"); + if (!fout) err_sys("can't open output file"); + + sockfd = socket(AF_INET, SOCK_STREAM, 0); + sockaddr_in servaddr; + memset(&servaddr, 0, sizeof(servaddr)); + servaddr.sin_family = AF_INET; + + servaddr.sin_port = htons(yasslPort); + servaddr.sin_addr.s_addr = inet_addr(loopback); + if (connect(sockfd, (const sockaddr*)&servaddr, sizeof(servaddr)) != 0) + err_sys("tcp connect failed"); + + SSL_METHOD* method = TLSv1_client_method(); + SSL_CTX* ctx = SSL_CTX_new(method); + SSL* ssl = SSL_new(ctx); + + SSL_set_fd(ssl, sockfd); + if (SSL_connect(ssl) != SSL_SUCCESS) err_sys("SSL_connect failed"); + + char send[1024]; + char reply[1024]; + + while (fgets(send, sizeof(send), fin)) { + + int sendSz = strlen(send) + 1; + if (SSL_write(ssl, send, sendSz) != sendSz) + err_sys("SSL_write failed"); + + if (strncmp(send, "quit", 4) == 0) { + fputs("sending server shutdown command: quit!", fout); + break; + } + + if (SSL_read(ssl, reply, sizeof(reply)) > 0) + fputs(reply, fout); + } + + SSL_CTX_free(ctx); + SSL_free(ssl); + + return 0; +} diff --git a/extra/yassl/examples/echoclient/quit b/extra/yassl/examples/echoclient/quit new file mode 100644 index 00000000000..3db49b3ad12 --- /dev/null +++ b/extra/yassl/examples/echoclient/quit @@ -0,0 +1,2 @@ +quit + diff --git a/extra/yassl/examples/echoserver/echoserver.cpp b/extra/yassl/examples/echoserver/echoserver.cpp new file mode 100644 index 00000000000..14a37a7e175 --- /dev/null +++ b/extra/yassl/examples/echoserver/echoserver.cpp @@ -0,0 +1,126 @@ +/* echoserver.cpp */ + +#include "../../testsuite/test.hpp" + + +#ifndef NO_MAIN_DRIVER + #define ECHO_OUT + + THREAD_RETURN YASSL_API echoserver_test(void*); + int main(int argc, char** argv) + { + func_args args; + + args.argc = argc; + args.argv = argv; + + echoserver_test(&args); + return args.return_code; + } + +#endif // NO_MAIN_DRIVER + + +THREAD_RETURN YASSL_API echoserver_test(void* args) +{ +#ifdef _WIN32 + WSADATA wsd; + WSAStartup(0x0002, &wsd); +#endif + + SOCKET_T sockfd = 0; + int argc = 0; + char** argv = 0; + + set_args(argc, argv, *static_cast(args)); + +#ifdef ECHO_OUT + FILE* fout = stdout; + if (argc >= 2) fout = fopen(argv[1], "w"); + if (!fout) err_sys("can't open output file"); +#endif + + tcp_listen(sockfd); + + SSL_METHOD* method = TLSv1_server_method(); + SSL_CTX* ctx = SSL_CTX_new(method); + + set_serverCerts(ctx); + DH* dh = set_tmpDH(ctx); + + bool shutdown(false); + +#if defined(_POSIX_THREADS) && defined(NO_MAIN_DRIVER) + // signal ready to tcp_accept + func_args& server_args = *((func_args*)args); + tcp_ready& ready = *server_args.signal_; + pthread_mutex_lock(&ready.mutex_); + ready.ready_ = true; + pthread_cond_signal(&ready.cond_); + pthread_mutex_unlock(&ready.mutex_); +#endif + + while (!shutdown) { + sockaddr_in client; + socklen_t client_len = sizeof(client); + int clientfd = accept(sockfd, (sockaddr*)&client, &client_len); + if (clientfd == -1) err_sys("tcp accept failed"); + + SSL* ssl = SSL_new(ctx); + SSL_set_fd(ssl, clientfd); + if (SSL_accept(ssl) != SSL_SUCCESS) err_sys("SSL_accept failed"); + + char command[1024]; + int echoSz(0); + while ( (echoSz = SSL_read(ssl, command, sizeof(command))) > 0) { + + if ( strncmp(command, "quit", 4) == 0) { + printf("client sent quit command: shutting down!\n"); + shutdown = true; + break; + } + else if ( strncmp(command, "GET", 3) == 0) { + char type[] = "HTTP/1.0 200 ok\r\nContent-type:" + " text/html\r\n\r\n"; + char header[] = "\n
\n";
+                char body[]   = "greetings from yaSSL\n";
+                char footer[] = "\r\n\r\n";
+            
+                strncpy(command, type, sizeof(type));
+                echoSz = sizeof(type) - 1;
+
+                strncpy(&command[echoSz], header, sizeof(header));
+                echoSz += sizeof(header) - 1;
+                strncpy(&command[echoSz], body, sizeof(body));
+                echoSz += sizeof(body) - 1;
+                strncpy(&command[echoSz], footer, sizeof(footer));
+                echoSz += sizeof(footer);
+
+                if (SSL_write(ssl, command, echoSz) != echoSz)
+                    err_sys("SSL_write failed");
+                break;
+            }
+            command[echoSz] = 0;
+
+        #ifdef ECHO_OUT
+            fputs(command, fout);
+        #endif
+
+            if (SSL_write(ssl, command, echoSz) != echoSz)
+                err_sys("SSL_write failed");
+        }
+        SSL_free(ssl);
+    }
+
+#ifdef _WIN32
+    closesocket(sockfd);
+#else
+    close(sockfd);
+#endif
+
+    DH_free(dh);
+    SSL_CTX_free(ctx);
+
+    ((func_args*)args)->return_code = 0;
+    return 0;
+}
diff --git a/extra/yassl/examples/echoserver/echoserver.dsp b/extra/yassl/examples/echoserver/echoserver.dsp
new file mode 100644
index 00000000000..21a965b013c
--- /dev/null
+++ b/extra/yassl/examples/echoserver/echoserver.dsp
@@ -0,0 +1,102 @@
+# Microsoft Developer Studio Project File - Name="echoserver" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Console Application" 0x0103
+
+CFG=echoserver - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE 
+!MESSAGE NMAKE /f "echoserver.mak".
+!MESSAGE 
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE 
+!MESSAGE NMAKE /f "echoserver.mak" CFG="echoserver - Win32 Debug"
+!MESSAGE 
+!MESSAGE Possible choices for configuration are:
+!MESSAGE 
+!MESSAGE "echoserver - Win32 Release" (based on "Win32 (x86) Console Application")
+!MESSAGE "echoserver - Win32 Debug" (based on "Win32 (x86) Console Application")
+!MESSAGE 
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF  "$(CFG)" == "echoserver - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /G6 /MT /W3 /O2 /I "..\..\include" /I "..\..\taocrypt\include" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib Ws2_32.lib /nologo /subsystem:console /machine:I386
+
+!ELSEIF  "$(CFG)" == "echoserver - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /MTd /W3 /Gm /ZI /Od /I "..\..\include" /I "..\..\taocrypt\include" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /FR /YX /FD /GZ /c
+# ADD BASE RSC /l 0x409 /d "_DEBUG"
+# ADD RSC /l 0x409 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib Ws2_32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+
+!ENDIF 
+
+# Begin Target
+
+# Name "echoserver - Win32 Release"
+# Name "echoserver - Win32 Debug"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\echoserver.cpp
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# End Group
+# Begin Group "Resource Files"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# End Target
+# End Project
diff --git a/extra/yassl/examples/server/server.cpp b/extra/yassl/examples/server/server.cpp
new file mode 100644
index 00000000000..4d3f121cf2c
--- /dev/null
+++ b/extra/yassl/examples/server/server.cpp
@@ -0,0 +1,73 @@
+/* server.cpp */
+
+
+#include "../../testsuite/test.hpp"
+
+
+THREAD_RETURN YASSL_API server_test(void* args)
+{
+#ifdef _WIN32
+    WSADATA wsd;
+    WSAStartup(0x0002, &wsd);
+#endif
+
+    SOCKET_T sockfd   = 0;
+    int      clientfd = 0;
+    int      argc     = 0;
+    char**   argv     = 0;
+
+    set_args(argc, argv, *static_cast(args));
+    tcp_accept(sockfd, clientfd, *static_cast(args));
+
+#ifdef _WIN32
+    closesocket(sockfd);
+#else
+    close(sockfd);
+#endif
+
+    SSL_METHOD* method = TLSv1_server_method();
+    SSL_CTX*    ctx = SSL_CTX_new(method);
+
+    //SSL_CTX_set_cipher_list(ctx, "RC4-SHA");
+    SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, 0);
+    set_serverCerts(ctx);
+    DH* dh = set_tmpDH(ctx);
+
+    SSL* ssl = SSL_new(ctx);
+    SSL_set_fd(ssl, clientfd);
+   
+    if (SSL_accept(ssl) != SSL_SUCCESS) err_sys("SSL_accept failed");
+    showPeer(ssl);
+    printf("Using Cipher Suite %s\n", SSL_get_cipher(ssl));
+
+    char command[1024];
+    command[SSL_read(ssl, command, sizeof(command))] = 0;
+    printf("First client command: %s\n", command);
+
+    char msg[] = "I hear you, fa shizzle!";
+    if (SSL_write(ssl, msg, sizeof(msg)) != sizeof(msg))
+        err_sys("SSL_write failed"); 
+
+    DH_free(dh);
+    SSL_CTX_free(ctx);
+    SSL_free(ssl);
+
+    ((func_args*)args)->return_code = 0;
+    return 0;
+}
+
+
+#ifndef NO_MAIN_DRIVER
+
+    int main(int argc, char** argv)
+    {
+        func_args args;
+
+        args.argc = argc;
+        args.argv = argv;
+
+        server_test(&args);
+        return args.return_code;
+    }
+
+#endif // NO_MAIN_DRIVER
diff --git a/extra/yassl/examples/server/server.dsp b/extra/yassl/examples/server/server.dsp
new file mode 100644
index 00000000000..9c797c54dfe
--- /dev/null
+++ b/extra/yassl/examples/server/server.dsp
@@ -0,0 +1,109 @@
+# Microsoft Developer Studio Project File - Name="server" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Application" 0x0101
+
+CFG=server - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE 
+!MESSAGE NMAKE /f "server.mak".
+!MESSAGE 
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE 
+!MESSAGE NMAKE /f "server.mak" CFG="server - Win32 Debug"
+!MESSAGE 
+!MESSAGE Possible choices for configuration are:
+!MESSAGE 
+!MESSAGE "server - Win32 Release" (based on "Win32 (x86) Application")
+!MESSAGE "server - Win32 Debug" (based on "Win32 (x86) Application")
+!MESSAGE 
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+MTL=midl.exe
+RSC=rc.exe
+
+!IF  "$(CFG)" == "server - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /MT /W3 /O2 /I "..\..\include" /I "..\..\taocrypt\include" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /c
+# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib Ws2_32.lib /nologo /subsystem:console /machine:I386
+# SUBTRACT LINK32 /pdb:none
+
+!ELSEIF  "$(CFG)" == "server - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /MTd /W3 /Gm /ZI /Od /I "..\..\include" /I "..\..\taocrypt\include" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /FR /YX /FD /GZ /c
+# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x409 /d "_DEBUG"
+# ADD RSC /l 0x409 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib Ws2_32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# SUBTRACT LINK32 /pdb:none /nodefaultlib
+
+!ENDIF 
+
+# Begin Target
+
+# Name "server - Win32 Release"
+# Name "server - Win32 Debug"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\server.cpp
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# End Group
+# Begin Group "Resource Files"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# End Target
+# End Project
diff --git a/extra/yassl/include/cert_wrapper.hpp b/extra/yassl/include/cert_wrapper.hpp
index 2381347c27e..2a214c529fd 100644
--- a/extra/yassl/include/cert_wrapper.hpp
+++ b/extra/yassl/include/cert_wrapper.hpp
@@ -83,6 +83,7 @@ class CertManager {
     SignerList   signers_;              // decoded CA keys and names
                                         //    plus verified chained certs
     bool verifyPeer_;
+    bool verifyNone_;                   // no error if verify fails
     bool failNoCert_;
     bool sendVerify_;
 public:
@@ -107,10 +108,12 @@ public:
     uint get_privateKeyLength()    const;
 
     bool verifyPeer() const;
+    bool verifyNone() const;
     bool failNoCert() const;
     bool sendVerify() const;
 
     void setVerifyPeer();
+    void setVerifyNone();
     void setFailNoCert();
     void setSendVerify();
 private:
diff --git a/extra/yassl/include/crypto_wrapper.hpp b/extra/yassl/include/crypto_wrapper.hpp
index ca9d870677e..cb542c25a67 100644
--- a/extra/yassl/include/crypto_wrapper.hpp
+++ b/extra/yassl/include/crypto_wrapper.hpp
@@ -41,8 +41,8 @@
 namespace yaSSL {
 
 
-// Digest policy should implement a get_digest, update, and get sizes for pad and 
-// digest
+// Digest policy should implement a get_digest, update, and get sizes for pad
+// and  digest
 struct Digest : public virtual_base {
     virtual void   get_digest(byte*) = 0;
     virtual void   get_digest(byte*, const byte*, unsigned int) = 0;
@@ -380,7 +380,7 @@ public:
     uint        get_agreedKeyLength() const;
     const byte* get_agreedKey()       const;
     const byte* get_publicKey()       const;
-    void        makeAgreement(const byte*);
+    void        makeAgreement(const byte*, unsigned int);
 
     void        set_sizes(int&, int&, int&) const;
     void        get_parms(byte*, byte*, byte*) const;
diff --git a/extra/yassl/include/openssl/ssl.h b/extra/yassl/include/openssl/ssl.h
index 1c8291c2f13..d6b91bc66c4 100644
--- a/extra/yassl/include/openssl/ssl.h
+++ b/extra/yassl/include/openssl/ssl.h
@@ -23,6 +23,8 @@
  *
  */
 
+
+
 #ifndef ysSSL_openssl_h__
 #define yaSSL_openssl_h__
 
@@ -49,7 +51,7 @@ extern "C" {
     class X509_NAME;
 #else
     typedef struct SSL         SSL;          
-    typedef struct SSL_SESION  SSL_SESSION;
+    typedef struct SSL_SESSION  SSL_SESSION;
     typedef struct SSL_METHOD  SSL_METHOD;
     typedef struct SSL_CTX     SSL_CTX;
     typedef struct SSL_CIPHER  SSL_CIPHER;
@@ -258,6 +260,8 @@ int SSL_pending(SSL*);
 
 
 enum { /* ssl Constants */
+    SSL_BAD_STAT        = -7,
+    SSL_BAD_PATH        = -6,
     SSL_BAD_FILETYPE    = -5,
     SSL_BAD_FILE        = -4,
     SSL_NOT_IMPLEMENTED = -3,
@@ -341,7 +345,6 @@ long SSL_CTX_sess_set_cache_size(SSL_CTX*, long);
 long SSL_CTX_set_tmp_dh(SSL_CTX*, DH*);
 
 void OpenSSL_add_all_algorithms(void);
-void SSL_library_init();
 void SSLeay_add_ssl_algorithms(void);
 
 
diff --git a/extra/yassl/include/socket_wrapper.hpp b/extra/yassl/include/socket_wrapper.hpp
index 38a9ce3bd25..d2258a93723 100644
--- a/extra/yassl/include/socket_wrapper.hpp
+++ b/extra/yassl/include/socket_wrapper.hpp
@@ -77,7 +77,7 @@ public:
     uint send(const byte* buf, unsigned int len, int flags = 0) const;
     uint receive(byte* buf, unsigned int len, int flags = 0)    const;
 
-    void wait() const;
+    bool wait() const;
 
     void closeSocket();
     void shutDown(int how = SD_SEND);
diff --git a/extra/yassl/include/yassl.hpp b/extra/yassl/include/yassl.hpp
new file mode 100644
index 00000000000..edb8e416eb6
--- /dev/null
+++ b/extra/yassl/include/yassl.hpp
@@ -0,0 +1,88 @@
+/* yassl.hpp                                
+ *
+ * Copyright (C) 2003 Sawtooth Consulting Ltd.
+ *
+ * This file is part of yaSSL.
+ *
+ * yaSSL 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; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * yaSSL 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ */
+
+
+/* yaSSL externel header defines yaSSL API
+ */
+
+
+#ifndef yaSSL_EXT_HPP
+#define yaSSL_EXT_HPP
+
+
+namespace yaSSL {
+
+
+#ifdef _WIN32
+    typedef unsigned int SOCKET_T;
+#else
+    typedef int          SOCKET_T;
+#endif
+
+
+class Client {
+public:
+    Client();
+    ~Client();
+
+    // basics
+    int Connect(SOCKET_T);
+    int Write(const void*, int);
+    int Read(void*, int);
+
+    // options
+    void SetCA(const char*);
+    void SetCert(const char*);
+    void SetKey(const char*);
+private:
+    struct ClientImpl;
+    ClientImpl* pimpl_;
+
+    Client(const Client&);              // hide copy
+    Client& operator=(const Client&);   // and assign  
+};
+
+
+class Server {
+public:
+    Server();
+    ~Server();
+
+    // basics
+    int Accept(SOCKET_T);
+    int Write(const void*, int);
+    int Read(void*, int);
+
+    // options
+    void SetCA(const char*);
+    void SetCert(const char*);
+    void SetKey(const char*);
+private:
+    struct ServerImpl;
+    ServerImpl* pimpl_;
+
+    Server(const Server&);              // hide copy
+    Server& operator=(const Server&);   // and assign
+};
+
+
+} // namespace yaSSL
+#endif // yaSSL_EXT_HPP
diff --git a/extra/yassl/include/yassl_error.hpp b/extra/yassl/include/yassl_error.hpp
index 0b06a37a635..9c12b06e34a 100644
--- a/extra/yassl/include/yassl_error.hpp
+++ b/extra/yassl/include/yassl_error.hpp
@@ -59,6 +59,10 @@ enum YasslError {
 
 
 enum Library { yaSSL_Lib = 0, CryptoLib, SocketLib };
+enum { MAX_ERROR_SZ = 80 };
+
+void SetErrorString(YasslError, char*);
+
 
 // Base class for all yaSSL exceptions
 class Error : public mySTL::runtime_error {
diff --git a/extra/yassl/include/yassl_imp.hpp b/extra/yassl/include/yassl_imp.hpp
index 3de58901f8e..2f240b71c03 100644
--- a/extra/yassl/include/yassl_imp.hpp
+++ b/extra/yassl/include/yassl_imp.hpp
@@ -662,7 +662,7 @@ struct Parameters {
     uint8                suites_size_;
     Cipher               suites_[MAX_SUITE_SZ];
     char                 cipher_name_[MAX_SUITE_NAME];
-    char                 cipher_list_[MAX_CIPHER_LIST];
+    char                 cipher_list_[MAX_CIPHERS][MAX_SUITE_NAME];
 
     Parameters(ConnectionEnd, const Ciphers&, ProtocolVersion);
 
diff --git a/extra/yassl/include/yassl_int.hpp b/extra/yassl/include/yassl_int.hpp
index 60a78a3970e..ce22d4edb1d 100644
--- a/extra/yassl/include/yassl_int.hpp
+++ b/extra/yassl/include/yassl_int.hpp
@@ -77,8 +77,6 @@ enum ServerState {
 
 // combines all states
 class States {
-    enum {MAX_ERROR_SZ = 80 };
-
     RecordLayerState recordLayer_;
     HandShakeState   handshakeLayer_;
     ClientState      clientState_;
@@ -231,7 +229,8 @@ sslFactory& GetSSL_Factory();
 class SSL_METHOD {
     ProtocolVersion version_;
     ConnectionEnd   side_;
-    bool            verifyPeer_;
+    bool            verifyPeer_;    // request or send certificate
+    bool            verifyNone_;    // whether to verify certificate
     bool            failNoCert_;
 public:
     explicit SSL_METHOD(ConnectionEnd ce, ProtocolVersion pv);
@@ -240,9 +239,11 @@ public:
     ConnectionEnd   getSide()    const;
 
     void setVerifyPeer();
+    void setVerifyNone();
     void setFailNoCert();
 
     bool verifyPeer() const;
+    bool verifyNone() const;
     bool failNoCert() const;
 private:
     SSL_METHOD(const SSL_METHOD&);              // hide copy
@@ -335,6 +336,7 @@ public:
     const Stats&      GetStats()    const;
 
     void setVerifyPeer();
+    void setVerifyNone();
     void setFailNoCert();
     bool SetCipherList(const char*);
     bool SetDH(const DH&);
diff --git a/extra/yassl/include/yassl_types.hpp b/extra/yassl/include/yassl_types.hpp
index ec9e6fb7ceb..be219d2cead 100644
--- a/extra/yassl/include/yassl_types.hpp
+++ b/extra/yassl/include/yassl_types.hpp
@@ -34,32 +34,34 @@
 
 namespace yaSSL {
 
-// library allocation
-struct new_t {};      // yaSSL New type
-extern new_t ys;      // pass in parameter
+#ifdef YASSL_PURE_C
 
-} // namespace yaSSL
+    // library allocation
+    struct new_t {};      // yaSSL New type
+    extern new_t ys;      // pass in parameter
 
-void* operator new  (size_t, yaSSL::new_t);
-void* operator new[](size_t, yaSSL::new_t);
+    } // namespace yaSSL
 
-void operator delete  (void*, yaSSL::new_t);
-void operator delete[](void*, yaSSL::new_t);
+    void* operator new  (size_t, yaSSL::new_t);
+    void* operator new[](size_t, yaSSL::new_t);
+
+    void operator delete  (void*, yaSSL::new_t);
+    void operator delete[](void*, yaSSL::new_t);
 
 
-namespace yaSSL {
+    namespace yaSSL {
 
 
-template
-void ysDelete(T* ptr)
-{
+    template
+    void ysDelete(T* ptr)
+    {
     if (ptr) ptr->~T();
     ::operator delete(ptr, yaSSL::ys);
-}
+    }
 
-template
-void ysArrayDelete(T* ptr)
-{
+    template
+    void ysArrayDelete(T* ptr)
+    {
     // can't do array placement destruction since not tracking size in
     // allocation, only allow builtins to use array placement since they
     // don't need destructors called
@@ -67,15 +69,40 @@ void ysArrayDelete(T* ptr)
     (void)sizeof(builtin);
 
     ::operator delete[](ptr, yaSSL::ys);
-}
+    }
 
+    #define NEW_YS new (ys) 
 
-// to resolve compiler generated operator delete on base classes with
-// virtual destructors (when on stack), make sure doesn't get called
-class virtual_base {
-public:
+    // to resolve compiler generated operator delete on base classes with
+    // virtual destructors (when on stack), make sure doesn't get called
+    class virtual_base {
+    public:
     static void operator delete(void*) { assert(0); }
-};
+    };
+
+
+#else   // YASSL_PURE_C
+
+
+    template
+    void ysDelete(T* ptr)
+    {
+        delete ptr;
+    }
+
+    template
+    void ysArrayDelete(T* ptr)
+    {
+        delete[] ptr;
+    }
+
+    #define NEW_YS new
+
+    class virtual_base {};
+
+
+
+#endif // YASSL_PURE_C
 
 
 typedef unsigned char  uint8;
@@ -105,7 +132,7 @@ const int KEY_PREFIX        =   7;  // up to 7 prefix letters for key rounds
 const int FORTEZZA_MAX      = 128;  // Maximum Fortezza Key length
 const int MAX_SUITE_SZ      =  64;  // 32 max suites * sizeof(suite)
 const int MAX_SUITE_NAME    =  48;  // max length of suite name
-const int MAX_CIPHER_LIST   = 512;  // max length of cipher list names
+const int MAX_CIPHERS       =  32;  // max supported ciphers for cipher list
 const int SIZEOF_ENUM       =   1;  // SSL considers an enum 1 byte, not 4
 const int SIZEOF_SENDER     =   4;  // Sender constant, for finished generation
 const int PAD_MD5           =  48;  // pad length 1 and 2 for md5 finished
diff --git a/extra/yassl/mySTL/helpers.hpp b/extra/yassl/mySTL/helpers.hpp
index de825c23fec..8d2061fc4f1 100644
--- a/extra/yassl/mySTL/helpers.hpp
+++ b/extra/yassl/mySTL/helpers.hpp
@@ -28,11 +28,14 @@
 #define mySTL_HELPERS_HPP
 
 #include 
+#include         // placement new
 
+
+
+#ifdef __IBMCPP__
 /*
       Workaround for the lack of operator new(size_t, void*)
       in IBM VA C++ 6.0
-      Also used as a workaround to avoid including 
 */
     struct Dummy {};
 
@@ -42,6 +45,9 @@
     }
 
     typedef Dummy* yassl_pointer;
+#else
+    typedef void*  yassl_pointer;
+#endif
 
 
 namespace mySTL {
diff --git a/extra/yassl/mySTL/list.hpp b/extra/yassl/mySTL/list.hpp
index dd8485f48a7..8aaeefaafe8 100644
--- a/extra/yassl/mySTL/list.hpp
+++ b/extra/yassl/mySTL/list.hpp
@@ -164,7 +164,7 @@ void list::push_front(T t)
 {
     void* mem = malloc(sizeof(node));
     if (!mem) abort();
-    node* add = new (reinterpret_cast(mem)) node(t);
+    node* add = new (mem) node(t);
 
     if (head_) {
         add->next_ = head_;
@@ -210,7 +210,7 @@ void list::push_back(T t)
 {
     void* mem = malloc(sizeof(node));
     if (!mem) abort();
-    node* add = new (reinterpret_cast(mem)) node(t);
+    node* add = new (mem) node(t);
 
     if (tail_) {
         tail_->next_ = add;
diff --git a/extra/yassl/mySTL/vector.hpp b/extra/yassl/mySTL/vector.hpp
index 9eab91cfda8..e7f63c37c7c 100644
--- a/extra/yassl/mySTL/vector.hpp
+++ b/extra/yassl/mySTL/vector.hpp
@@ -45,8 +45,7 @@ struct vector_base {
     vector_base() : start_(0), finish_(0), end_of_storage_(0) {}
     vector_base(size_t n)
     {
-        // Don't allow malloc(0), if n is 0 use 1
-        start_ = static_cast(malloc((n ? n : 1) * sizeof(T)));
+        start_ = static_cast(malloc(n * sizeof(T)));
         if (!start_) abort();
         finish_ = start_;
         end_of_storage_ = start_ + n;
diff --git a/extra/yassl/src/buffer.cpp b/extra/yassl/src/buffer.cpp
index 56d355bea80..3bc6dced887 100644
--- a/extra/yassl/src/buffer.cpp
+++ b/extra/yassl/src/buffer.cpp
@@ -24,6 +24,7 @@
  * with SSL types and sockets
  */
 
+
 #include              // memcpy
 #include "runtime.hpp"
 #include "buffer.hpp"
@@ -63,13 +64,13 @@ input_buffer::input_buffer()
 
 
 input_buffer::input_buffer(uint s) 
-    : size_(0), current_(0), buffer_(new (ys) byte[s]), end_(buffer_ + s)
+    : size_(0), current_(0), buffer_(NEW_YS byte[s]), end_(buffer_ + s)
 {}
 
 
 // with assign
 input_buffer::input_buffer(uint s, const byte* t, uint len) 
-    : size_(0), current_(0), buffer_(new (ys) byte[s]), end_(buffer_ + s) 
+    : size_(0), current_(0), buffer_(NEW_YS byte[s]), end_(buffer_ + s) 
 { 
     assign(t, len); 
 }
@@ -85,7 +86,7 @@ input_buffer::~input_buffer()
 void input_buffer::allocate(uint s) 
 { 
     assert(!buffer_);       // find realloc error
-    buffer_ = new (ys) byte[s];
+    buffer_ = NEW_YS byte[s];
     end_ = buffer_ + s; 
 }
 
@@ -97,7 +98,7 @@ byte* input_buffer::get_buffer() const
 }
 
 
-// after a raw write user can set new (ys) size
+// after a raw write user can set NEW_YS size
 // if you know the size before the write use assign()
 void input_buffer::add_size(uint i) 
 { 
@@ -199,13 +200,13 @@ output_buffer::output_buffer()
 
 // with allocate
 output_buffer::output_buffer(uint s) 
-    : current_(0), buffer_(new (ys) byte[s]), end_(buffer_ + s) 
+    : current_(0), buffer_(NEW_YS byte[s]), end_(buffer_ + s) 
 {}
 
 
 // with assign
 output_buffer::output_buffer(uint s, const byte* t, uint len) 
-    : current_(0), buffer_(new (ys) byte[s]), end_(buffer_+ s) 
+    : current_(0), buffer_(NEW_YS byte[s]), end_(buffer_+ s) 
 { 
     write(t, len); 
 }
@@ -240,7 +241,7 @@ void output_buffer::set_current(uint c)
 void output_buffer::allocate(uint s) 
 { 
     assert(!buffer_);   // find realloc error
-    buffer_ = new (ys) byte[s]; end_ = buffer_ + s; 
+    buffer_ = NEW_YS byte[s]; end_ = buffer_ + s; 
 }
 
 
diff --git a/extra/yassl/src/cert_wrapper.cpp b/extra/yassl/src/cert_wrapper.cpp
index a775c366a92..b98c7faf1d0 100644
--- a/extra/yassl/src/cert_wrapper.cpp
+++ b/extra/yassl/src/cert_wrapper.cpp
@@ -39,7 +39,7 @@
 namespace yaSSL {
 
 
-x509::x509(uint sz) : length_(sz), buffer_(new (ys) opaque[sz]) 
+x509::x509(uint sz) : length_(sz), buffer_(NEW_YS opaque[sz]) 
 {
 }
 
@@ -51,7 +51,7 @@ x509::~x509()
 
 
 x509::x509(const x509& that) : length_(that.length_),
-                               buffer_(new (ys) opaque[length_])
+                               buffer_(NEW_YS opaque[length_])
 {
     memcpy(buffer_, that.buffer_, length_);
 }
@@ -92,7 +92,8 @@ opaque* x509::use_buffer()
 
 //CertManager
 CertManager::CertManager()
-    : peerX509_(0), verifyPeer_(false), failNoCert_(false), sendVerify_(false)
+    : peerX509_(0), verifyPeer_(false), verifyNone_(false), failNoCert_(false),
+      sendVerify_(false)
 {}
 
 
@@ -114,6 +115,12 @@ bool CertManager::verifyPeer() const
 }
 
 
+bool CertManager::verifyNone() const
+{
+    return verifyNone_;
+}
+
+
 bool CertManager::failNoCert() const
 {
     return failNoCert_;
@@ -132,6 +139,12 @@ void CertManager::setVerifyPeer()
 }
 
 
+void CertManager::setVerifyNone()
+{
+    verifyNone_ = true;
+}
+
+
 void CertManager::setFailNoCert()
 {
     failNoCert_ = true;
@@ -153,7 +166,7 @@ void CertManager::AddPeerCert(x509* x)
 void CertManager::CopySelfCert(const x509* x)
 {
     if (x)
-        list_.push_back(new (ys) x509(*x));
+        list_.push_back(NEW_YS x509(*x));
 }
 
 
@@ -161,11 +174,12 @@ void CertManager::CopySelfCert(const x509* x)
 int CertManager::CopyCaCert(const x509* x)
 {
     TaoCrypt::Source source(x->get_buffer(), x->get_length());
-    TaoCrypt::CertDecoder cert(source, true, &signers_);
+    TaoCrypt::CertDecoder cert(source, true, &signers_, verifyNone_,
+                               TaoCrypt::CertDecoder::CA);
 
     if (!cert.GetError().What()) {
         const TaoCrypt::PublicKey& key = cert.GetPublicKey();
-        signers_.push_back(new (ys) TaoCrypt::Signer(key.GetKey(), key.size(),
+        signers_.push_back(NEW_YS TaoCrypt::Signer(key.GetKey(), key.size(),
                                         cert.GetCommonName(), cert.GetHash()));
     }
     return cert.GetError().What();
@@ -228,13 +242,13 @@ int CertManager::Validate()
 
     while ( count > 1 ) {
         TaoCrypt::Source source((*last)->get_buffer(), (*last)->get_length());
-        TaoCrypt::CertDecoder cert(source, true, &signers_);
+        TaoCrypt::CertDecoder cert(source, true, &signers_, verifyNone_);
 
         if (int err = cert.GetError().What())
             return err;
 
         const TaoCrypt::PublicKey& key = cert.GetPublicKey();
-        signers_.push_back(new (ys) TaoCrypt::Signer(key.GetKey(), key.size(),
+        signers_.push_back(NEW_YS TaoCrypt::Signer(key.GetKey(), key.size(),
                                         cert.GetCommonName(), cert.GetHash()));
         --last;
         --count;
@@ -243,7 +257,7 @@ int CertManager::Validate()
     if (count) {
         // peer's is at the front
         TaoCrypt::Source source((*last)->get_buffer(), (*last)->get_length());
-        TaoCrypt::CertDecoder cert(source, true, &signers_);
+        TaoCrypt::CertDecoder cert(source, true, &signers_, verifyNone_);
 
         if (int err = cert.GetError().What())
             return err;
@@ -259,7 +273,7 @@ int CertManager::Validate()
 
         int iSz = cert.GetIssuer() ? strlen(cert.GetIssuer()) + 1 : 0;
         int sSz = cert.GetCommonName() ? strlen(cert.GetCommonName()) + 1 : 0;
-        peerX509_ = new (ys) X509(cert.GetIssuer(), iSz, cert.GetCommonName(),
+        peerX509_ = NEW_YS X509(cert.GetIssuer(), iSz, cert.GetCommonName(),
                                   sSz);
     }
     return 0;
diff --git a/extra/yassl/src/crypto_wrapper.cpp b/extra/yassl/src/crypto_wrapper.cpp
index 80cadd3d722..8859fbdd70f 100644
--- a/extra/yassl/src/crypto_wrapper.cpp
+++ b/extra/yassl/src/crypto_wrapper.cpp
@@ -58,13 +58,13 @@ struct MD5::MD5Impl {
 };
 
 
-MD5::MD5() : pimpl_(new (ys) MD5Impl) {}
+MD5::MD5() : pimpl_(NEW_YS MD5Impl) {}
 
 
 MD5::~MD5() { ysDelete(pimpl_); }
 
 
-MD5::MD5(const MD5& that) : Digest(), pimpl_(new (ys) 
+MD5::MD5(const MD5& that) : Digest(), pimpl_(NEW_YS 
                                              MD5Impl(that.pimpl_->md5_)) {}
 
 
@@ -116,13 +116,13 @@ struct SHA::SHAImpl {
 };
 
 
-SHA::SHA() : pimpl_(new (ys) SHAImpl) {}
+SHA::SHA() : pimpl_(NEW_YS SHAImpl) {}
 
 
 SHA::~SHA() { ysDelete(pimpl_); }
 
 
-SHA::SHA(const SHA& that) : Digest(), pimpl_(new (ys) SHAImpl(that.pimpl_->sha_)) {}
+SHA::SHA(const SHA& that) : Digest(), pimpl_(NEW_YS SHAImpl(that.pimpl_->sha_)) {}
 
 SHA& SHA::operator=(const SHA& that)
 {
@@ -173,13 +173,13 @@ struct RMD::RMDImpl {
 };
 
 
-RMD::RMD() : pimpl_(new (ys) RMDImpl) {}
+RMD::RMD() : pimpl_(NEW_YS RMDImpl) {}
 
 
 RMD::~RMD() { ysDelete(pimpl_); }
 
 
-RMD::RMD(const RMD& that) : Digest(), pimpl_(new (ys) RMDImpl(that.pimpl_->rmd_)) {}
+RMD::RMD(const RMD& that) : Digest(), pimpl_(NEW_YS RMDImpl(that.pimpl_->rmd_)) {}
 
 RMD& RMD::operator=(const RMD& that)
 {
@@ -230,7 +230,7 @@ struct HMAC_MD5::HMAC_MD5Impl {
 
 
 HMAC_MD5::HMAC_MD5(const byte* secret, unsigned int len) 
-    : pimpl_(new (ys) HMAC_MD5Impl) 
+    : pimpl_(NEW_YS HMAC_MD5Impl) 
 {
     pimpl_->mac_.SetKey(secret, len);
 }
@@ -280,7 +280,7 @@ struct HMAC_SHA::HMAC_SHAImpl {
 
 
 HMAC_SHA::HMAC_SHA(const byte* secret, unsigned int len) 
-    : pimpl_(new (ys) HMAC_SHAImpl) 
+    : pimpl_(NEW_YS HMAC_SHAImpl) 
 {
     pimpl_->mac_.SetKey(secret, len);
 }
@@ -331,7 +331,7 @@ struct HMAC_RMD::HMAC_RMDImpl {
 
 
 HMAC_RMD::HMAC_RMD(const byte* secret, unsigned int len) 
-    : pimpl_(new (ys) HMAC_RMDImpl) 
+    : pimpl_(NEW_YS HMAC_RMDImpl) 
 {
     pimpl_->mac_.SetKey(secret, len);
 }
@@ -379,7 +379,7 @@ struct DES::DESImpl {
 };
 
 
-DES::DES() : pimpl_(new (ys) DESImpl) {}
+DES::DES() : pimpl_(NEW_YS DESImpl) {}
 
 DES::~DES() { ysDelete(pimpl_); }
 
@@ -415,7 +415,7 @@ struct DES_EDE::DES_EDEImpl {
 };
 
 
-DES_EDE::DES_EDE() : pimpl_(new (ys) DES_EDEImpl) {}
+DES_EDE::DES_EDE() : pimpl_(NEW_YS DES_EDEImpl) {}
 
 DES_EDE::~DES_EDE() { ysDelete(pimpl_); }
 
@@ -453,7 +453,7 @@ struct RC4::RC4Impl {
 };
 
 
-RC4::RC4() : pimpl_(new (ys) RC4Impl) {}
+RC4::RC4() : pimpl_(NEW_YS RC4Impl) {}
 
 RC4::~RC4() { ysDelete(pimpl_); }
 
@@ -495,7 +495,7 @@ struct AES::AESImpl {
 };
 
 
-AES::AES(unsigned int ks) : pimpl_(new (ys) AESImpl(ks)) {}
+AES::AES(unsigned int ks) : pimpl_(NEW_YS AESImpl(ks)) {}
 
 AES::~AES() { ysDelete(pimpl_); }
 
@@ -536,7 +536,7 @@ struct RandomPool::RandomImpl {
     TaoCrypt::RandomNumberGenerator RNG_;
 };
 
-RandomPool::RandomPool() : pimpl_(new (ys) RandomImpl) {}
+RandomPool::RandomPool() : pimpl_(NEW_YS RandomImpl) {}
 
 RandomPool::~RandomPool() { ysDelete(pimpl_); }
 
@@ -580,7 +580,7 @@ void DSS::DSSImpl::SetPrivate(const byte* key, unsigned int sz)
 
 // Set public or private key
 DSS::DSS(const byte* key, unsigned int sz, bool publicKey) 
-    : pimpl_(new (ys) DSSImpl)
+    : pimpl_(NEW_YS DSSImpl)
 {
     if (publicKey) 
         pimpl_->SetPublic(key, sz);
@@ -651,7 +651,7 @@ void RSA::RSAImpl::SetPrivate(const byte* key, unsigned int sz)
 
 // Set public or private key
 RSA::RSA(const byte* key, unsigned int sz, bool publicKey) 
-    : pimpl_(new (ys) RSAImpl)
+    : pimpl_(NEW_YS RSAImpl)
 {
     if (publicKey) 
         pimpl_->SetPublic(key, sz);
@@ -723,13 +723,13 @@ struct Integer::IntegerImpl {
     explicit IntegerImpl(const TaoCrypt::Integer& i) : int_(i) {}
 };
 
-Integer::Integer() : pimpl_(new (ys) IntegerImpl) {}
+Integer::Integer() : pimpl_(NEW_YS IntegerImpl) {}
 
 Integer::~Integer() { ysDelete(pimpl_); }
 
 
 
-Integer::Integer(const Integer& other) : pimpl_(new (ys) 
+Integer::Integer(const Integer& other) : pimpl_(NEW_YS 
                                                IntegerImpl(other.pimpl_->int_))
 {}
 
@@ -773,9 +773,9 @@ struct DiffieHellman::DHImpl {
 
     void AllocKeys(unsigned int pubSz, unsigned int privSz, unsigned int agrSz)
     {
-        publicKey_  = new (ys) byte[pubSz];
-        privateKey_ = new (ys) byte[privSz];
-        agreedKey_  = new (ys) byte[agrSz];
+        publicKey_  = NEW_YS byte[pubSz];
+        privateKey_ = NEW_YS byte[privSz];
+        agreedKey_  = NEW_YS byte[agrSz];
     }
 };
 
@@ -784,7 +784,7 @@ struct DiffieHellman::DHImpl {
 /*
 // server Side DH, server's view
 DiffieHellman::DiffieHellman(const char* file, const RandomPool& random)
-    : pimpl_(new (ys) DHImpl(random.pimpl_->RNG_))
+    : pimpl_(NEW_YS DHImpl(random.pimpl_->RNG_))
 {
     using namespace TaoCrypt;
     Source source;
@@ -808,12 +808,12 @@ DiffieHellman::DiffieHellman(const char* file, const RandomPool& random)
 DiffieHellman::DiffieHellman(const byte* p, unsigned int pSz, const byte* g,
                              unsigned int gSz, const byte* pub,
                              unsigned int pubSz, const RandomPool& random)
-    : pimpl_(new (ys) DHImpl(random.pimpl_->RNG_))
+    : pimpl_(NEW_YS DHImpl(random.pimpl_->RNG_))
 {
     using TaoCrypt::Integer;
 
     pimpl_->dh_.Initialize(Integer(p, pSz).Ref(), Integer(g, gSz).Ref());
-    pimpl_->publicKey_ = new (ys) opaque[pubSz];
+    pimpl_->publicKey_ = NEW_YS opaque[pubSz];
     memcpy(pimpl_->publicKey_, pub, pubSz);
 }
 
@@ -821,7 +821,7 @@ DiffieHellman::DiffieHellman(const byte* p, unsigned int pSz, const byte* g,
 // Server Side DH, server's view
 DiffieHellman::DiffieHellman(const Integer& p, const Integer& g,
                              const RandomPool& random)
-: pimpl_(new (ys) DHImpl(random.pimpl_->RNG_))
+: pimpl_(NEW_YS DHImpl(random.pimpl_->RNG_))
 {
     using TaoCrypt::Integer;
 
@@ -839,7 +839,7 @@ DiffieHellman::~DiffieHellman() { ysDelete(pimpl_); }
 
 // Client side and view, use server that for p and g
 DiffieHellman::DiffieHellman(const DiffieHellman& that) 
-    : pimpl_(new (ys) DHImpl(*that.pimpl_))
+    : pimpl_(NEW_YS DHImpl(*that.pimpl_))
 {   
     pimpl_->dh_.GenerateKeyPair(pimpl_->ranPool_, pimpl_->privateKey_,
                                                   pimpl_->publicKey_);
@@ -855,9 +855,9 @@ DiffieHellman& DiffieHellman::operator=(const DiffieHellman& that)
 }
 
 
-void DiffieHellman::makeAgreement(const byte* other)
+void DiffieHellman::makeAgreement(const byte* other, unsigned int otherSz)
 {
-    pimpl_->dh_.Agree(pimpl_->agreedKey_, pimpl_->privateKey_, other); 
+    pimpl_->dh_.Agree(pimpl_->agreedKey_, pimpl_->privateKey_, other, otherSz); 
 }
 
 
@@ -960,7 +960,7 @@ x509* PemToDer(const char* fname, CertType type)
     Base64Decoder b64Dec(der);
 
     uint sz = der.size();
-    mySTL::auto_ptr x(new (ys) x509(sz), ysDelete);
+    mySTL::auto_ptr x(NEW_YS x509(sz), ysDelete);
     memcpy(x->use_buffer(), der.get_buffer(), sz);
 
     fclose(file);
diff --git a/extra/yassl/src/handshake.cpp b/extra/yassl/src/handshake.cpp
index d7df438b8df..534e91e8989 100644
--- a/extra/yassl/src/handshake.cpp
+++ b/extra/yassl/src/handshake.cpp
@@ -24,6 +24,8 @@
  * the various handshake messages.
  */
 
+
+
 #include "runtime.hpp"
 #include "handshake.hpp"
 #include "yassl_int.hpp"
@@ -362,9 +364,9 @@ void p_hash(output_buffer& result, const output_buffer& secret,
     if (lastLen) times += 1;
 
     if (hash == md5)
-        hmac.reset(new (ys) HMAC_MD5(secret.get_buffer(), secret.get_size()));
+        hmac.reset(NEW_YS HMAC_MD5(secret.get_buffer(), secret.get_size()));
     else
-        hmac.reset(new (ys) HMAC_SHA(secret.get_buffer(), secret.get_size()));
+        hmac.reset(NEW_YS HMAC_SHA(secret.get_buffer(), secret.get_size()));
                                                                    // A0 = seed
     hmac->get_digest(previous, seed.get_buffer(), seed.get_size());// A1
     uint lastTime = times - 1;
@@ -582,11 +584,11 @@ void TLS_hmac(SSL& ssl, byte* digest, const byte* buffer, uint sz,
     MACAlgorithm algo = ssl.getSecurity().get_parms().mac_algorithm_;
 
     if (algo == sha)
-        hmac.reset(new (ys) HMAC_SHA(ssl.get_macSecret(verify), SHA_LEN));
+        hmac.reset(NEW_YS HMAC_SHA(ssl.get_macSecret(verify), SHA_LEN));
     else if (algo == rmd)
-        hmac.reset(new (ys) HMAC_RMD(ssl.get_macSecret(verify), RMD_LEN));
+        hmac.reset(NEW_YS HMAC_RMD(ssl.get_macSecret(verify), RMD_LEN));
     else
-        hmac.reset(new (ys) HMAC_MD5(ssl.get_macSecret(verify), MD5_LEN));
+        hmac.reset(NEW_YS HMAC_MD5(ssl.get_macSecret(verify), MD5_LEN));
     
     hmac->update(seq, SEQ_SZ);                                       // seq_num
     inner[0] = content;                                              // type
@@ -603,7 +605,7 @@ void TLS_hmac(SSL& ssl, byte* digest, const byte* buffer, uint sz,
 void PRF(byte* digest, uint digLen, const byte* secret, uint secLen,
          const byte* label, uint labLen, const byte* seed, uint seedLen)
 {
-    uint half = secLen / 2 + secLen % 2;
+    uint half = (secLen + 1) / 2;
 
     output_buffer md5_half(half);
     output_buffer sha_half(half);
@@ -654,13 +656,13 @@ mySTL::auto_ptr null_buffer(ysDelete);
 mySTL::auto_ptr
 DoProcessReply(SSL& ssl, mySTL::auto_ptr buffered)
 {
-    ssl.getSocket().wait();                  // wait for input if blocking
-    uint ready = ssl.getSocket().get_ready();
-    if (!ready) {
-      // Nothing to receive after blocking wait => error
+    // wait for input if blocking
+    if (!ssl.getSocket().wait()) {
       ssl.SetError(receive_error);
-      return buffered= null_buffer;
+        return buffered = null_buffer;
     }
+    uint ready = ssl.getSocket().get_ready();
+    if (!ready) return buffered; 
 
     // add buffered data if its there
     uint buffSz = buffered.get() ? buffered.get()->get_size() : 0;
@@ -670,7 +672,7 @@ DoProcessReply(SSL& ssl, mySTL::auto_ptr buffered)
         buffered = null_buffer;
     }
 
-    // add new (ys) data
+    // add NEW_YS data
     uint read  = ssl.getSocket().receive(buffer.get_buffer() + buffSz, ready);
     buffer.add_size(read);
     uint offset = 0;
@@ -691,7 +693,7 @@ DoProcessReply(SSL& ssl, mySTL::auto_ptr buffered)
         // make sure we have enough input in buffer to process this record
         if (hdr.length_ > buffer.get_remaining()) { 
             uint sz = buffer.get_remaining() + RECORD_HEADER;
-            buffered.reset(new (ys) input_buffer(sz, buffer.get_buffer() +
+            buffered.reset(NEW_YS input_buffer(sz, buffer.get_buffer() +
                            buffer.get_current() - RECORD_HEADER, sz));
             break;
         }
@@ -727,6 +729,7 @@ void processReply(SSL& ssl)
             buffered = tmp;
         else
             break;
+        if (ssl.GetError()) return;
     }
 }
 
@@ -764,7 +767,7 @@ void sendClientKeyExchange(SSL& ssl, BufferOutput buffer)
 
     RecordLayerHeader rlHeader;
     HandShakeHeader   hsHeader;
-    mySTL::auto_ptr out(new (ys) output_buffer, ysDelete);
+    mySTL::auto_ptr out(NEW_YS output_buffer, ysDelete);
     buildHeaders(ssl, hsHeader, rlHeader, ck);
     buildOutput(*out.get(), rlHeader, hsHeader, ck);
     hashHandShake(ssl, *out.get());
@@ -785,7 +788,7 @@ void sendServerKeyExchange(SSL& ssl, BufferOutput buffer)
 
     RecordLayerHeader rlHeader;
     HandShakeHeader   hsHeader;
-    mySTL::auto_ptr out(new (ys) output_buffer, ysDelete);
+    mySTL::auto_ptr out(NEW_YS output_buffer, ysDelete);
     buildHeaders(ssl, hsHeader, rlHeader, sk);
     buildOutput(*out.get(), rlHeader, hsHeader, sk);
     hashHandShake(ssl, *out.get());
@@ -810,7 +813,7 @@ void sendChangeCipher(SSL& ssl, BufferOutput buffer)
     ChangeCipherSpec ccs;
     RecordLayerHeader rlHeader;
     buildHeader(ssl, rlHeader, ccs);
-    mySTL::auto_ptr out(new (ys) output_buffer, ysDelete);
+    mySTL::auto_ptr out(NEW_YS output_buffer, ysDelete);
     buildOutput(*out.get(), rlHeader, ccs);
    
     if (buffer == buffered)
@@ -827,7 +830,7 @@ void sendFinished(SSL& ssl, ConnectionEnd side, BufferOutput buffer)
 
     Finished fin;
     buildFinished(ssl, fin, side == client_end ? client : server);
-    mySTL::auto_ptr out(new (ys) output_buffer, ysDelete);
+    mySTL::auto_ptr out(NEW_YS output_buffer, ysDelete);
     cipherFinished(ssl, fin, *out.get());                   // hashes handshake
 
     if (ssl.getSecurity().get_resuming()) {
@@ -911,7 +914,7 @@ void sendServerHello(SSL& ssl, BufferOutput buffer)
     ServerHello       sh(ssl.getSecurity().get_connection().version_);
     RecordLayerHeader rlHeader;
     HandShakeHeader   hsHeader;
-    mySTL::auto_ptr out(new (ys) output_buffer, ysDelete);
+    mySTL::auto_ptr out(NEW_YS output_buffer, ysDelete);
 
     buildServerHello(ssl, sh);
     ssl.set_random(sh.get_random(), server_end);
@@ -934,7 +937,7 @@ void sendServerHelloDone(SSL& ssl, BufferOutput buffer)
     ServerHelloDone   shd;
     RecordLayerHeader rlHeader;
     HandShakeHeader   hsHeader;
-    mySTL::auto_ptr out(new (ys) output_buffer, ysDelete);
+    mySTL::auto_ptr out(NEW_YS output_buffer, ysDelete);
 
     buildHeaders(ssl, hsHeader, rlHeader, shd);
     buildOutput(*out.get(), rlHeader, hsHeader, shd);
@@ -955,7 +958,7 @@ void sendCertificate(SSL& ssl, BufferOutput buffer)
     Certificate       cert(ssl.getCrypto().get_certManager().get_cert());
     RecordLayerHeader rlHeader;
     HandShakeHeader   hsHeader;
-    mySTL::auto_ptr out(new (ys) output_buffer, ysDelete);
+    mySTL::auto_ptr out(NEW_YS output_buffer, ysDelete);
 
     buildHeaders(ssl, hsHeader, rlHeader, cert);
     buildOutput(*out.get(), rlHeader, hsHeader, cert);
@@ -977,7 +980,7 @@ void sendCertificateRequest(SSL& ssl, BufferOutput buffer)
     request.Build();
     RecordLayerHeader  rlHeader;
     HandShakeHeader    hsHeader;
-    mySTL::auto_ptr out(new (ys) output_buffer, ysDelete);
+    mySTL::auto_ptr out(NEW_YS output_buffer, ysDelete);
 
     buildHeaders(ssl, hsHeader, rlHeader, request);
     buildOutput(*out.get(), rlHeader, hsHeader, request);
@@ -999,7 +1002,7 @@ void sendCertificateVerify(SSL& ssl, BufferOutput buffer)
     verify.Build(ssl);
     RecordLayerHeader  rlHeader;
     HandShakeHeader    hsHeader;
-    mySTL::auto_ptr out(new (ys) output_buffer, ysDelete);
+    mySTL::auto_ptr out(NEW_YS output_buffer, ysDelete);
 
     buildHeaders(ssl, hsHeader, rlHeader, verify);
     buildOutput(*out.get(), rlHeader, hsHeader, verify);
diff --git a/extra/yassl/src/make.bat b/extra/yassl/src/make.bat
new file mode 100644
index 00000000000..4c79a9c6406
--- /dev/null
+++ b/extra/yassl/src/make.bat
@@ -0,0 +1,27 @@
+# quick and dirty build file for testing different MSDEVs
+setlocal 
+
+set myFLAGS= /I../include /I../mySTL /I../taocrypt/include /W3 /c /ZI
+
+cl %myFLAGS% buffer.cpp
+cl %myFLAGS% cert_wrapper.cpp
+cl %myFLAGS% crypto_wrapper.cpp
+cl %myFLAGS% handshake.cpp
+
+cl %myFLAGS% lock.cpp
+cl %myFLAGS% log.cpp
+cl %myFLAGS% socket_wrapper.cpp
+cl %myFLAGS% ssl.cpp
+
+cl %myFLAGS% template_instnt.cpp
+cl %myFLAGS% timer.cpp
+cl %myFLAGS% yassl.cpp
+cl %myFLAGS% yassl_error.cpp
+
+cl %myFLAGS% yassl_imp.cpp
+cl %myFLAGS% yassl_int.cpp
+
+link.exe -lib /out:yassl.lib buffer.obj cert_wrapper.obj crypto_wrapper.obj handshake.obj lock.obj log.obj socket_wrapper.obj ssl.obj template_instnt.obj timer.obj yassl.obj yassl_error.obj yassl_imp.obj yassl_int.obj
+
+
+
diff --git a/extra/yassl/src/socket_wrapper.cpp b/extra/yassl/src/socket_wrapper.cpp
index 285e0dee2e5..f43a4925447 100644
--- a/extra/yassl/src/socket_wrapper.cpp
+++ b/extra/yassl/src/socket_wrapper.cpp
@@ -39,16 +39,18 @@
     #include 
 #endif // _WIN32
 
-#if defined(__sun) || defined(__SCO_VERSION__)
+#ifdef __sun
     #include 
 #endif
 
 #ifdef _WIN32
     const int SOCKET_EINVAL = WSAEINVAL;
     const int SOCKET_EWOULDBLOCK = WSAEWOULDBLOCK;
+    const int SOCKET_EAGAIN = WSAEWOULDBLOCK;
 #else
     const int SOCKET_EINVAL = EINVAL;
     const int SOCKET_EWOULDBLOCK = EWOULDBLOCK;
+    const int SOCKET_EAGAIN = EAGAIN;
 #endif // _WIN32
 
 
@@ -93,15 +95,11 @@ void Socket::closeSocket()
 
 uint Socket::get_ready() const
 {
-#ifdef _WIN32
     unsigned long ready = 0;
+
+#ifdef _WIN32
     ioctlsocket(socket_, FIONREAD, &ready);
 #else
-    /*
-      64-bit Solaris requires the variable passed to
-      FIONREAD be a 32-bit value.
-    */
-    int ready = 0;
     ioctl(socket_, FIONREAD, &ready);
 #endif
 
@@ -126,18 +124,24 @@ uint Socket::receive(byte* buf, unsigned int sz, int flags) const
     assert(socket_ != INVALID_SOCKET);
     int recvd = ::recv(socket_, reinterpret_cast(buf), sz, flags);
 
-    if (recvd == -1) 
+    // idea to seperate error from would block by arnetheduck@gmail.com
+    if (recvd == -1) {
+        if (get_lastError() == SOCKET_EWOULDBLOCK || 
+            get_lastError() == SOCKET_EAGAIN)
         return 0;
+    }
+    else if (recvd == 0)
+        return static_cast(-1);
 
     return recvd;
 }
 
 
-// wait if blocking for input, or error
-void Socket::wait() const
+// wait if blocking for input, return false for error
+bool Socket::wait() const
 {
     byte b;
-    receive(&b, 1, MSG_PEEK);
+    return receive(&b, 1, MSG_PEEK) != static_cast(-1);
 }
 
 
diff --git a/extra/yassl/src/ssl.cpp b/extra/yassl/src/ssl.cpp
index 94e783167b3..7cc0d592822 100644
--- a/extra/yassl/src/ssl.cpp
+++ b/extra/yassl/src/ssl.cpp
@@ -38,6 +38,14 @@
 #include "yassl_int.hpp"
 #include 
 
+#ifdef _WIN32
+    #include     // FindFirstFile etc..
+#else
+    #include   // file helper
+    #include    // stat
+    #include      // opendir
+#endif
+
 
 namespace yaSSL {
 
@@ -52,25 +60,25 @@ SSL_METHOD* SSLv3_method()
 
 SSL_METHOD* SSLv3_server_method()
 {
-    return new (ys) SSL_METHOD(server_end, ProtocolVersion(3,0));
+    return NEW_YS SSL_METHOD(server_end, ProtocolVersion(3,0));
 }
 
 
 SSL_METHOD* SSLv3_client_method()
 {
-    return new (ys) SSL_METHOD(client_end, ProtocolVersion(3,0));
+    return NEW_YS SSL_METHOD(client_end, ProtocolVersion(3,0));
 }
 
 
 SSL_METHOD* TLSv1_server_method()
 {
-    return new (ys) SSL_METHOD(server_end, ProtocolVersion(3,1));
+    return NEW_YS SSL_METHOD(server_end, ProtocolVersion(3,1));
 }
 
 
 SSL_METHOD* TLSv1_client_method()
 {
-    return new (ys) SSL_METHOD(client_end, ProtocolVersion(3,1));
+    return NEW_YS SSL_METHOD(client_end, ProtocolVersion(3,1));
 }
 
 
@@ -83,7 +91,7 @@ SSL_METHOD* SSLv23_server_method()
 
 SSL_CTX* SSL_CTX_new(SSL_METHOD* method)
 {
-    return new (ys) SSL_CTX(method);
+    return NEW_YS SSL_CTX(method);
 }
 
 
@@ -95,7 +103,7 @@ void SSL_CTX_free(SSL_CTX* ctx)
 
 SSL* SSL_new(SSL_CTX* ctx)
 {
-    return new (ys) SSL(ctx);
+    return NEW_YS SSL(ctx);
 }
 
 
@@ -115,7 +123,12 @@ int SSL_set_fd(SSL* ssl, int fd)
 int SSL_connect(SSL* ssl)
 {
     sendClientHello(*ssl);
+    ClientState neededState = ssl->getSecurity().get_resuming() ?
+        serverFinishedComplete : serverHelloDoneComplete;
+    while (ssl->getStates().getClient() < neededState) {
+        if (ssl->GetError()) break;
     processReply(*ssl);
+    }
 
     if(ssl->getCrypto().get_certManager().sendVerify())
         sendCertificate(*ssl);
@@ -130,7 +143,10 @@ int SSL_connect(SSL* ssl)
     sendFinished(*ssl, client_end);
     ssl->flushBuffer();
     if (!ssl->getSecurity().get_resuming())
+        while (ssl->getStates().getClient() < serverFinishedComplete) {
+            if (ssl->GetError()) break;
         processReply(*ssl);
+        }
 
     ssl->verifyState(serverFinishedComplete);
     ssl->useLog().ShowTCP(ssl->getSocket().get_fd());
@@ -171,9 +187,7 @@ int SSL_accept(SSL* ssl)
         sendServerHelloDone(*ssl);
         ssl->flushBuffer();
 
-        // Java Client sends fragmented response
-        while (ssl->getStates().getServer() <
-               clientFinishedComplete) {
+        while (ssl->getStates().getServer() < clientFinishedComplete) {
             if (ssl->GetError()) break;
             processReply(*ssl);
         }
@@ -182,10 +196,7 @@ int SSL_accept(SSL* ssl)
     sendFinished(*ssl, server_end);
     ssl->flushBuffer();
     if (ssl->getSecurity().get_resuming()) {
-
-      // Java Client sends fragmented response
-      while (ssl->getStates().getServer() <
-             clientFinishedComplete) {
+        while (ssl->getStates().getServer() < clientFinishedComplete) {
           if (ssl->GetError()) break;
           processReply(*ssl);
       }
@@ -281,9 +292,15 @@ char* SSL_get_shared_ciphers(SSL* /*ssl*/, char* buf, int len)
 }
 
 
-const char* SSL_get_cipher_list(SSL* ssl, int /*priority */)
+const char* SSL_get_cipher_list(SSL* ssl, int priority)
 {
-    return ssl->getSecurity().get_parms().cipher_list_;
+    if (priority < 0 || priority >= MAX_CIPHERS)
+        return 0;
+
+    if (ssl->getSecurity().get_parms().cipher_list_[priority][0])
+        return ssl->getSecurity().get_parms().cipher_list_[priority];
+
+    return 0;
 }
 
 
@@ -455,7 +472,7 @@ int read_file(SSL_CTX* ctx, const char* file, int format, CertType type)
             fseek(input, 0, SEEK_END);
             long sz = ftell(input);
             rewind(input);
-            x = new (ys) x509(sz); // takes ownership
+            x = NEW_YS x509(sz); // takes ownership
             size_t bytes = fread(x->use_buffer(), sz, 1, input);
             if (bytes != 1) {
                 fclose(input);
@@ -492,16 +509,74 @@ void SSL_CTX_set_verify(SSL_CTX* ctx, int mode, VerifyCallback /*vc*/)
     if (mode & SSL_VERIFY_PEER)
         ctx->setVerifyPeer();
 
+    if (mode == SSL_VERIFY_NONE)
+        ctx->setVerifyNone();
+
     if (mode & SSL_VERIFY_FAIL_IF_NO_PEER_CERT)
         ctx->setFailNoCert();
 }
 
 
 int SSL_CTX_load_verify_locations(SSL_CTX* ctx, const char* file,
-                                  const char* /*path*/)
+                                  const char* path)
 {
-    // just files for now
-    return read_file(ctx, file, SSL_FILETYPE_PEM, CA);
+    int       ret = SSL_SUCCESS;
+    const int HALF_PATH = 128;
+
+    if (file) ret = read_file(ctx, file, SSL_FILETYPE_PEM, CA);
+
+    if (ret == SSL_SUCCESS && path) {
+        // call read_file for each reqular file in path
+#ifdef _WIN32
+
+        WIN32_FIND_DATA FindFileData;
+        HANDLE hFind;
+
+        char name[MAX_PATH + 1];  // directory specification
+        strncpy(name, path, MAX_PATH - 3);
+        strncat(name, "\\*", 3);
+
+        hFind = FindFirstFile(name, &FindFileData);
+        if (hFind == INVALID_HANDLE_VALUE) return SSL_BAD_PATH;
+
+        do {
+            if (FindFileData.dwFileAttributes != FILE_ATTRIBUTE_DIRECTORY) {
+                strncpy(name, path, MAX_PATH - 2 - HALF_PATH);
+                strncat(name, "\\", 2);
+                strncat(name, FindFileData.cFileName, HALF_PATH);
+                ret = read_file(ctx, name, SSL_FILETYPE_PEM, CA);
+            }
+        } while (ret == SSL_SUCCESS && FindNextFile(hFind, &FindFileData));
+
+        FindClose(hFind);
+
+#else   // _WIN32
+
+        const int MAX_PATH = 260;
+
+        DIR* dir = opendir(path);
+        if (!dir) return SSL_BAD_PATH;
+
+        struct dirent* entry;
+        struct stat    buf;
+        char           name[MAX_PATH + 1];
+
+        while (ret == SSL_SUCCESS && (entry = readdir(dir))) {
+            strncpy(name, path, MAX_PATH - 1 - HALF_PATH);
+            strncat(name, "/", 1);
+            strncat(name, entry->d_name, HALF_PATH);
+            if (stat(name, &buf) < 0) return SSL_BAD_STAT;
+     
+            if (S_ISREG(buf.st_mode))
+                ret = read_file(ctx, name, SSL_FILETYPE_PEM, CA);
+        }
+
+        closedir(dir);
+
+#endif
+    }
+
+    return ret;
 }
 
 
@@ -648,13 +723,9 @@ void OpenSSL_add_all_algorithms()  // compatibility only
 {}
 
 
-void SSL_library_init()  // compatibility only
-{}
-
-
 DH* DH_new(void)
 {
-    DH* dh = new (ys) DH;
+    DH* dh = NEW_YS DH;
     if (dh)
         dh->p = dh->g = 0;
     return dh;
@@ -679,7 +750,7 @@ BIGNUM* BN_bin2bn(const unsigned char* num, int sz, BIGNUM* retVal)
 
     if (!retVal) {
         created = true;
-        bn.reset(new (ys) BIGNUM);
+        bn.reset(NEW_YS BIGNUM);
         retVal = bn.get();
     }
 
@@ -706,12 +777,14 @@ void ERR_print_errors_fp(FILE* /*fp*/)
 }
 
 
-char* ERR_error_string(unsigned long /*err*/, char* buffer)
+char* ERR_error_string(unsigned long errNumber, char* buffer)
 {
-    // TODO:
-    static char* msg = "Not Implemented";
-    if (buffer)
-        return strncpy(buffer, msg, strlen(msg));
+    static char* msg = "Please supply a buffer for error string";
+
+    if (buffer) {
+        SetErrorString(YasslError(errNumber), buffer);
+        return buffer;
+    }
 
     return msg;
 }
@@ -728,14 +801,14 @@ const char* X509_verify_cert_error_string(long /* error */)
 const EVP_MD* EVP_md5(void)
 {
     // TODO: FIX add to some list for destruction
-    return new (ys) MD5;
+    return NEW_YS MD5;
 }
 
 
 const EVP_CIPHER* EVP_des_ede3_cbc(void)
 {
     // TODO: FIX add to some list for destruction
-    return new (ys) DES_EDE;
+    return NEW_YS DES_EDE;
 }
 
 
diff --git a/extra/yassl/src/timer.cpp b/extra/yassl/src/timer.cpp
index 8b7d2d17a84..4fe0d3aa4f9 100644
--- a/extra/yassl/src/timer.cpp
+++ b/extra/yassl/src/timer.cpp
@@ -26,17 +26,13 @@
 #include "runtime.hpp"
 #include "timer.hpp"
 
-#ifdef _WIN32
-#define WIN32_LEAN_AND_MEAN
-#include 
-#else
-#include 
-#endif
-
 namespace yaSSL {
 
 #ifdef _WIN32
 
+    #define WIN32_LEAN_AND_MEAN
+    #include 
+
     timer_d timer()
     {
         static bool          init(false);
@@ -61,6 +57,8 @@ namespace yaSSL {
 
 #else // _WIN32
 
+    #include 
+
     timer_d timer()
     {
         struct timeval tv;
diff --git a/extra/yassl/src/yassl.cpp b/extra/yassl/src/yassl.cpp
new file mode 100644
index 00000000000..86af12fd448
--- /dev/null
+++ b/extra/yassl/src/yassl.cpp
@@ -0,0 +1,244 @@
+/* yassl.cpp                                
+ *
+ * Copyright (C) 2003 Sawtooth Consulting Ltd.
+ *
+ * This file is part of yaSSL.
+ *
+ * yaSSL 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; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * yaSSL 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ */
+
+
+/* yaSSL implements external API
+ */
+
+#include "runtime.hpp"
+#include "yassl.hpp"
+#include "yassl_int.hpp"
+#include "handshake.hpp"
+#include 
+
+#include "openssl/ssl.h"  // get rid of this
+
+
+// yaSSL overloads hide these
+void* operator new[](size_t sz)
+{
+    return ::operator new(sz);
+}
+
+void operator delete[](void* ptr)
+{
+    ::operator delete(ptr);
+}
+
+
+namespace yaSSL {
+
+using mySTL::min;
+
+
+struct Base {
+    SSL_METHOD* method_;
+    SSL_CTX*    ctx_;
+    SSL*        ssl_;
+
+    char*       ca_;
+    char*       cert_;
+    char*       key_;
+
+    DH*         dh_;
+
+    Base() : method_(0), ctx_(0), ssl_(0), ca_(0), cert_(0), key_(0), dh_(0)
+    {}
+
+    ~Base()
+    {
+        if (dh_) DH_free(dh_);
+        delete[] key_;
+        delete[] cert_;
+        delete[] ca_;
+        SSL_CTX_free(ctx_);   // frees method_ too
+        SSL_free(ssl_);
+    }
+};
+
+
+void SetDH(Base&);
+
+void SetUpBase(Base& base, ConnectionEnd end, SOCKET_T s)
+{
+    base.method_ = new SSL_METHOD(end, ProtocolVersion(3,1));
+    base.ctx_ =    new SSL_CTX(base.method_);
+
+    if (base.ca_)
+        if (SSL_CTX_load_verify_locations(base.ctx_,
+            base.ca_, 0) != SSL_SUCCESS) assert(0);
+    if (base.cert_)
+        if (SSL_CTX_use_certificate_file(base.ctx_,
+            base.cert_, SSL_FILETYPE_PEM) != SSL_SUCCESS) assert(0);
+    if (base.key_)
+        if (SSL_CTX_use_PrivateKey_file(base.ctx_, base.key_,
+            SSL_FILETYPE_PEM) != SSL_SUCCESS) assert(0);
+
+    if (end == server_end) SetDH(base);
+
+    base.ssl_ = new SSL(base.ctx_);
+    base.ssl_->useSocket().set_fd(s);
+}
+
+
+void SetDH(Base& base)
+{
+    static unsigned char dh512_p[] =
+    {
+      0xDA,0x58,0x3C,0x16,0xD9,0x85,0x22,0x89,0xD0,0xE4,0xAF,0x75,
+      0x6F,0x4C,0xCA,0x92,0xDD,0x4B,0xE5,0x33,0xB8,0x04,0xFB,0x0F,
+      0xED,0x94,0xEF,0x9C,0x8A,0x44,0x03,0xED,0x57,0x46,0x50,0xD3,
+      0x69,0x99,0xDB,0x29,0xD7,0x76,0x27,0x6B,0xA2,0xD3,0xD4,0x12,
+      0xE2,0x18,0xF4,0xDD,0x1E,0x08,0x4C,0xF6,0xD8,0x00,0x3E,0x7C,
+      0x47,0x74,0xE8,0x33,
+    };
+
+    static unsigned char dh512_g[] =
+    {
+      0x02,
+    };
+
+    if ( (base.dh_ = DH_new()) ) {
+        base.dh_->p = BN_bin2bn(dh512_p, sizeof(dh512_p), 0);
+        base.dh_->g = BN_bin2bn(dh512_g, sizeof(dh512_g), 0);
+    }
+    if (!base.dh_->p || !base.dh_->g) {
+        DH_free(base.dh_);
+        base.dh_ = 0;
+    }
+    SSL_CTX_set_tmp_dh(base.ctx_, base.dh_);
+}
+
+
+void NewCopy(char*& dst, const char* src)
+{
+    size_t len = strlen(src) + 1;
+    dst = new char[len];
+
+    strncpy(dst, src, len);
+}
+
+
+// Client Implementation
+struct Client::ClientImpl {
+    Base base_;
+};
+
+
+Client::Client() : pimpl_(new ClientImpl)
+{}
+
+
+Client::~Client() { delete pimpl_; }
+
+
+int Client::Connect(SOCKET_T s)
+{
+    SetUpBase(pimpl_->base_, client_end, s);
+    return SSL_connect(pimpl_->base_.ssl_);
+}
+
+
+int Client::Write(const void* buffer, int sz)
+{
+    return sendData(*pimpl_->base_.ssl_, buffer, sz);
+}
+
+
+int Client::Read(void* buffer, int sz)
+{
+    Data data(min(sz, MAX_RECORD_SIZE), static_cast(buffer));
+    return receiveData(*pimpl_->base_.ssl_, data);
+}
+
+
+void Client::SetCA(const char* name)
+{
+    NewCopy(pimpl_->base_.ca_, name);
+}
+
+
+void Client::SetCert(const char* name)
+{
+    NewCopy(pimpl_->base_.cert_, name);
+}
+
+
+void Client::SetKey(const char* name)
+{
+    NewCopy(pimpl_->base_.key_, name);
+}
+
+
+
+// Server Implementation
+struct Server::ServerImpl {
+    Base base_;
+};
+
+
+Server::Server() : pimpl_(new ServerImpl)
+{}
+
+
+Server::~Server() { delete pimpl_; }
+
+
+int Server::Accept(SOCKET_T s)
+{
+    SetUpBase(pimpl_->base_, server_end, s);
+    return SSL_accept(pimpl_->base_.ssl_);
+}
+
+
+int Server::Write(const void* buffer, int sz)
+{
+    return sendData(*pimpl_->base_.ssl_, buffer, sz);
+}
+
+
+int Server::Read(void* buffer, int sz)
+{
+    Data data(min(sz, MAX_RECORD_SIZE), static_cast(buffer));
+    return receiveData(*pimpl_->base_.ssl_, data);
+}
+
+
+void Server::SetCA(const char* name)
+{
+    NewCopy(pimpl_->base_.ca_, name);
+}
+
+
+void Server::SetCert(const char* name)
+{
+    NewCopy(pimpl_->base_.cert_, name);
+}
+
+
+void Server::SetKey(const char* name)
+{
+    NewCopy(pimpl_->base_.key_, name);
+}
+
+
+
+} // namespace yaSSL
diff --git a/extra/yassl/src/yassl_error.cpp b/extra/yassl/src/yassl_error.cpp
index c53aef2068d..59113d7438c 100644
--- a/extra/yassl/src/yassl_error.cpp
+++ b/extra/yassl/src/yassl_error.cpp
@@ -25,6 +25,7 @@
 
 #include "runtime.hpp"
 #include "yassl_error.hpp"
+#include "error.hpp"        // TaoCrypt error numbers
 
 namespace yaSSL {
 
@@ -48,6 +49,184 @@ Library Error::get_lib() const
 }
 
 
+void SetErrorString(YasslError error, char* buffer)
+{
+    using namespace TaoCrypt;
+    const int max = MAX_ERROR_SZ;  // shorthand
+
+    switch (error) {
+
+        // yaSSL proper errors
+    case range_error :
+        strncpy(buffer, "buffer index error, out of range", max);
+        break; 
+
+    case realloc_error :
+        strncpy(buffer, "trying to realloc a fixed buffer", max);
+        break; 
+
+    case factory_error : 
+        strncpy(buffer, "unknown factory create request", max);
+        break; 
+
+    case unknown_cipher :
+        strncpy(buffer, "trying to use an unknown cipher", max);
+        break; 
+
+    case prefix_error : 
+        strncpy(buffer, "bad master secret derivation, prefix too big", max);
+        break; 
+
+    case record_layer : 
+        strncpy(buffer, "record layer not ready yet", max);
+        break; 
+        
+    case handshake_layer :
+        strncpy(buffer, "handshake layer not ready yet", max);
+        break; 
+
+    case out_of_order :
+        strncpy(buffer, "handshake message received in wrong order", max);
+        break; 
+
+    case bad_input : 
+        strncpy(buffer, "bad cipher suite input", max);
+        break; 
+
+    case match_error :
+        strncpy(buffer, "unable to match a supported cipher suite", max);
+        break; 
+
+    case no_key_file : 
+        strncpy(buffer, "the server needs a private key file", max);
+        break; 
+
+    case verify_error :
+        strncpy(buffer, "unable to verify peer checksum", max);
+        break; 
+
+    case send_error :
+        strncpy(buffer, "socket layer send error", max);
+        break; 
+
+    case receive_error :
+        strncpy(buffer, "socket layer receive error", max);
+        break; 
+
+    case certificate_error :
+        strncpy(buffer, "unable to proccess cerificate", max);
+        break; 
+
+        // TaoCrypt errors
+    case NO_ERROR :
+        strncpy(buffer, "not in error state", max);
+        break;
+
+    case WINCRYPT_E :
+        strncpy(buffer, "bad wincrypt acquire", max);
+        break;
+
+    case CRYPTGEN_E :
+        strncpy(buffer, "CryptGenRandom error", max);
+        break;
+
+    case OPEN_RAN_E :
+        strncpy(buffer, "unable to use random device", max);
+        break;
+
+    case READ_RAN_E :
+        strncpy(buffer, "unable to use random device", max);
+        break;
+
+    case INTEGER_E :
+        strncpy(buffer, "ASN: bad DER Integer Header", max);
+        break;
+
+    case SEQUENCE_E :
+        strncpy(buffer, "ASN: bad Sequence Header", max);
+        break;
+
+    case SET_E :
+        strncpy(buffer, "ASN: bad Set Header", max);
+        break;
+
+    case VERSION_E :
+        strncpy(buffer, "ASN: version length not 1", max);
+        break;
+
+    case SIG_OID_E :
+        strncpy(buffer, "ASN: signature OID mismatch", max);
+        break;
+
+    case BIT_STR_E :
+        strncpy(buffer, "ASN: bad BitString Header", max);
+        break;
+
+    case UNKNOWN_OID_E :
+        strncpy(buffer, "ASN: unknown key OID type", max);
+        break;
+
+    case OBJECT_ID_E :
+        strncpy(buffer, "ASN: bad Ojbect ID Header", max);
+        break;
+
+    case TAG_NULL_E :
+        strncpy(buffer, "ASN: expected TAG NULL", max);
+        break;
+
+    case EXPECT_0_E :
+        strncpy(buffer, "ASN: expected 0", max);
+        break;
+
+    case OCTET_STR_E :
+        strncpy(buffer, "ASN: bad Octet String Header", max);
+        break;
+
+    case TIME_E :
+        strncpy(buffer, "ASN: bad TIME", max);
+        break;
+
+    case DATE_SZ_E :
+        strncpy(buffer, "ASN: bad Date Size", max);
+        break;
+
+    case SIG_LEN_E :
+        strncpy(buffer, "ASN: bad Signature Length", max);
+        break;
+
+    case UNKOWN_SIG_E :
+        strncpy(buffer, "ASN: unknown signature OID", max);
+        break;
+
+    case UNKOWN_HASH_E :
+        strncpy(buffer, "ASN: unknown hash OID", max);
+        break;
+
+    case DSA_SZ_E :
+        strncpy(buffer, "ASN: bad DSA r or s size", max);
+        break;
+
+    case BEFORE_DATE_E :
+        strncpy(buffer, "ASN: before date in the future", max);
+        break;
+
+    case AFTER_DATE_E :
+        strncpy(buffer, "ASN: after date in the past", max);
+        break;
+
+    case SIG_CONFIRM_E :
+        strncpy(buffer, "ASN: bad self signature confirmation", max);
+        break;
+
+    case SIG_OTHER_E :
+        strncpy(buffer, "ASN: bad other signature confirmation", max);
+        break;
+
+    default :
+        strncpy(buffer, "unknown error number", max);
+    }
+}
+
 
 
 }  // namespace yaSSL
diff --git a/extra/yassl/src/yassl_imp.cpp b/extra/yassl/src/yassl_imp.cpp
index 1d9db46816b..f5c6acba10c 100644
--- a/extra/yassl/src/yassl_imp.cpp
+++ b/extra/yassl/src/yassl_imp.cpp
@@ -29,6 +29,7 @@
 #include "asn.hpp"  // provide crypto wrapper??
 
 
+
 namespace yaSSL {
 
 
@@ -111,10 +112,14 @@ void ClientDiffieHellmanPublic::build(SSL& ssl)
     uint keyLength = dhClient.get_agreedKeyLength(); // pub and agree same
 
     alloc(keyLength, true);
-    dhClient.makeAgreement(dhServer.get_publicKey());
+    dhClient.makeAgreement(dhServer.get_publicKey(), keyLength);
     c16toa(keyLength, Yc_);
     memcpy(Yc_ + KEY_OFFSET, dhClient.get_publicKey(), keyLength);
 
+    // because of encoding first byte might be zero, don't use it for preMaster
+    if (*dhClient.get_agreedKey() == 0) 
+        ssl.set_preMaster(dhClient.get_agreedKey() + 1, keyLength - 1);
+    else
     ssl.set_preMaster(dhClient.get_agreedKey(), keyLength);
 }
 
@@ -134,10 +139,10 @@ void DH_Server::build(SSL& ssl)
     const CertManager& cert = ssl.getCrypto().get_certManager();
     
     if (ssl.getSecurity().get_parms().sig_algo_ == rsa_sa_algo)
-        auth.reset(new (ys) RSA(cert.get_privateKey(),
+        auth.reset(NEW_YS RSA(cert.get_privateKey(),
                    cert.get_privateKeyLength(), false));
     else {
-        auth.reset(new (ys) DSS(cert.get_privateKey(),
+        auth.reset(NEW_YS DSS(cert.get_privateKey(),
                    cert.get_privateKeyLength(), false));
         sigSz += DSS_ENCODED_EXTRA;
     }
@@ -168,7 +173,7 @@ void DH_Server::build(SSL& ssl)
     byte hash[FINISHED_SZ];
     MD5  md5;
     SHA  sha;
-    signature_ = new (ys) byte[sigSz];
+    signature_ = NEW_YS byte[sigSz];
 
     const Connection& conn = ssl.getSecurity().get_connection();
     // md5
@@ -199,7 +204,7 @@ void DH_Server::build(SSL& ssl)
     tmp.write(signature_, sigSz);
 
     // key message
-    keyMessage_ = new (ys) opaque[length_];
+    keyMessage_ = NEW_YS opaque[length_];
     memcpy(keyMessage_, tmp.get_buffer(), tmp.get_size());
 }
 
@@ -253,7 +258,7 @@ opaque* EncryptedPreMasterSecret::get_clientKey() const
 void EncryptedPreMasterSecret::alloc(int sz)
 {
     length_ = sz;
-    secret_ = new (ys) opaque[sz];
+    secret_ = NEW_YS opaque[sz];
 }
 
 
@@ -269,10 +274,14 @@ void ClientDiffieHellmanPublic::read(SSL& ssl, input_buffer& input)
     ato16(tmp, keyLength);
 
     alloc(keyLength);
-    input.read(Yc_, length_);
-    dh.makeAgreement(Yc_);
+    input.read(Yc_, keyLength);
+    dh.makeAgreement(Yc_, keyLength); 
 
-    ssl.set_preMaster(dh.get_agreedKey(), keyLength);
+    // because of encoding, first byte might be 0, don't use for preMaster 
+    if (*dh.get_agreedKey() == 0) 
+        ssl.set_preMaster(dh.get_agreedKey() + 1, dh.get_agreedKeyLength() - 1);
+    else
+        ssl.set_preMaster(dh.get_agreedKey(), dh.get_agreedKeyLength());
     ssl.makeMasterSecret();
 }
 
@@ -303,7 +312,7 @@ opaque* ClientDiffieHellmanPublic::get_clientKey() const
 void ClientDiffieHellmanPublic::alloc(int sz, bool offset) 
 {
     length_ = sz + (offset ? KEY_OFFSET : 0); 
-    Yc_ = new (ys) opaque[length_];
+    Yc_ = NEW_YS opaque[length_];
 }
 
 
@@ -348,7 +357,7 @@ void DH_Server::read(SSL& ssl, input_buffer& input)
     tmp[1] = input[AUTO];
     ato16(tmp, length);
 
-    signature_ = new (ys) byte[length];
+    signature_ = NEW_YS byte[length];
     input.read(signature_, length);
 
     // verify signature
@@ -386,7 +395,7 @@ void DH_Server::read(SSL& ssl, input_buffer& input)
     }
 
     // save input
-    ssl.useCrypto().SetDH(new (ys) DiffieHellman(parms_.get_p(),
+    ssl.useCrypto().SetDH(NEW_YS DiffieHellman(parms_.get_p(),
                parms_.get_pSize(), parms_.get_g(), parms_.get_gSize(),
                parms_.get_pub(), parms_.get_pubSize(),
                ssl.getCrypto().get_random()));
@@ -438,7 +447,7 @@ void Parameters::SetSuites(ProtocolVersion pv)
     int i = 0;
     // available suites, best first
     // when adding more, make sure cipher_names is updated and
-    //      MAX_CIPHER_LIST is big enough
+    //      MAX_CIPHERS is big enough
 
     if (isTLS(pv)) {
         suites_[i++] = 0x00;
@@ -510,13 +519,10 @@ void Parameters::SetCipherNames()
 
     for (int j = 0; j < suites; j++) {
         int index = suites_[j*2 + 1];  // every other suite is suite id
-        int len = strlen(cipher_names[index]);
-        memcpy(&cipher_list_[pos], cipher_names[index], len);
-        pos += len;
-        cipher_list_[pos++] = ':';
+        int len = strlen(cipher_names[index]) + 1;
+        strncpy(cipher_list_[pos++], cipher_names[index], len);
     }
-    if (suites)
-        cipher_list_[--pos] = 0;
+    cipher_list_[pos][0] = 0;
 }
 
 
@@ -928,7 +934,7 @@ void Data::Process(input_buffer& input, SSL& ssl)
     // read data
     if (dataSz) {
         input_buffer* data;
-        ssl.addData(data = new (ys) input_buffer(dataSz));
+        ssl.addData(data = NEW_YS input_buffer(dataSz));
         input.read(data->get_buffer(), dataSz);
         data->add_size(dataSz);
 
@@ -1025,7 +1031,7 @@ void Certificate::Process(input_buffer& input, SSL& ssl)
         c24to32(tmp, cert_sz);
         
         x509* myCert;
-        cm.AddPeerCert(myCert = new (ys) x509(cert_sz));
+        cm.AddPeerCert(myCert = NEW_YS x509(cert_sz));
         input.read(myCert->use_buffer(), myCert->get_length());
 
         list_sz -= cert_sz + CERT_HEADER;
@@ -1111,21 +1117,21 @@ const opaque* ServerDHParams::get_pub() const
 
 opaque* ServerDHParams::alloc_p(int sz)
 {
-    p_ = new (ys) opaque[pSz_ = sz];
+    p_ = NEW_YS opaque[pSz_ = sz];
     return p_;
 }
 
 
 opaque* ServerDHParams::alloc_g(int sz)
 {
-    g_ = new (ys) opaque[gSz_ = sz];
+    g_ = NEW_YS opaque[gSz_ = sz];
     return g_;
 }
 
 
 opaque* ServerDHParams::alloc_pub(int sz)
 {
-    Ys_ = new (ys) opaque[pubSz_ = sz];
+    Ys_ = NEW_YS opaque[pubSz_ = sz];
     return Ys_;
 }
 
@@ -1537,7 +1543,7 @@ void CertificateRequest::Build()
     for (int j = 0; j < authCount; j++) {
         int sz = REQUEST_HEADER + MIN_DIS_SIZE;
         DistinguishedName dn;
-        certificate_authorities_.push_back(dn = new (ys) byte[sz]);
+        certificate_authorities_.push_back(dn = NEW_YS byte[sz]);
 
         opaque tmp[REQUEST_HEADER];
         c16toa(MIN_DIS_SIZE, tmp);
@@ -1584,7 +1590,7 @@ input_buffer& operator>>(input_buffer& input, CertificateRequest& request)
         ato16(tmp, dnSz);
         
         DistinguishedName dn;
-        request.certificate_authorities_.push_back(dn = new (ys) 
+        request.certificate_authorities_.push_back(dn = NEW_YS 
                                                   byte[REQUEST_HEADER + dnSz]);
         memcpy(dn, tmp, REQUEST_HEADER);
         input.read(&dn[REQUEST_HEADER], dnSz);
@@ -1630,7 +1636,11 @@ output_buffer& operator<<(output_buffer& output,
 // CertificateRequest processing handler
 void CertificateRequest::Process(input_buffer&, SSL& ssl)
 {
-    ssl.useCrypto().use_certManager().setSendVerify();
+    CertManager& cm = ssl.useCrypto().use_certManager();
+
+    // make sure user provided cert and key before sending and using
+    if (cm.get_cert() && cm.get_privateKey())
+        cm.setSendVerify();
 }
 
 
@@ -1665,7 +1675,7 @@ void CertificateVerify::Build(SSL& ssl)
         RSA rsa(cert.get_privateKey(), cert.get_privateKeyLength(), false);
 
         sz = rsa.get_cipherLength() + VERIFY_HEADER;
-        sig.reset(new (ys) byte[sz]);
+        sig.reset(NEW_YS byte[sz]);
 
         c16toa(sz - VERIFY_HEADER, len);
         memcpy(sig.get(), len, VERIFY_HEADER);
@@ -1676,7 +1686,7 @@ void CertificateVerify::Build(SSL& ssl)
         DSS dss(cert.get_privateKey(), cert.get_privateKeyLength(), false);
 
         sz = DSS_SIG_SZ + DSS_ENCODED_EXTRA + VERIFY_HEADER;
-        sig.reset(new (ys) byte[sz]);
+        sig.reset(NEW_YS byte[sz]);
 
         c16toa(sz - VERIFY_HEADER, len);
         memcpy(sig.get(), len, VERIFY_HEADER);
@@ -1714,7 +1724,7 @@ input_buffer& operator>>(input_buffer& input, CertificateVerify& request)
     ato16(tmp, sz);
     request.set_length(sz);
 
-    request.signature_ = new (ys) byte[sz];
+    request.signature_ = NEW_YS byte[sz];
     input.read(request.signature_, sz);
 
     return input;
@@ -1975,7 +1985,7 @@ Connection::~Connection()
 
 void Connection::AllocPreSecret(uint sz) 
 { 
-    pre_master_secret_ = new (ys) opaque[pre_secret_len_ = sz];
+    pre_master_secret_ = NEW_YS opaque[pre_secret_len_ = sz];
 }
 
 
@@ -2011,35 +2021,35 @@ void Connection::CleanPreMaster()
 
 
 // Create functions for message factory
-Message* CreateCipherSpec() { return new (ys) ChangeCipherSpec; }
-Message* CreateAlert()      { return new (ys) Alert; }
-Message* CreateHandShake()  { return new (ys) HandShakeHeader; }
-Message* CreateData()       { return new (ys) Data; }
+Message* CreateCipherSpec() { return NEW_YS ChangeCipherSpec; }
+Message* CreateAlert()      { return NEW_YS Alert; }
+Message* CreateHandShake()  { return NEW_YS HandShakeHeader; }
+Message* CreateData()       { return NEW_YS Data; }
 
 // Create functions for handshake factory
-HandShakeBase* CreateHelloRequest()       { return new (ys) HelloRequest; }
-HandShakeBase* CreateClientHello()        { return new (ys) ClientHello; }
-HandShakeBase* CreateServerHello()        { return new (ys) ServerHello; }
-HandShakeBase* CreateCertificate()        { return new (ys) Certificate; }
-HandShakeBase* CreateServerKeyExchange()  { return new (ys) ServerKeyExchange;}
-HandShakeBase* CreateCertificateRequest() { return new (ys) 
+HandShakeBase* CreateHelloRequest()       { return NEW_YS HelloRequest; }
+HandShakeBase* CreateClientHello()        { return NEW_YS ClientHello; }
+HandShakeBase* CreateServerHello()        { return NEW_YS ServerHello; }
+HandShakeBase* CreateCertificate()        { return NEW_YS Certificate; }
+HandShakeBase* CreateServerKeyExchange()  { return NEW_YS ServerKeyExchange;}
+HandShakeBase* CreateCertificateRequest() { return NEW_YS 
                                                     CertificateRequest; }
-HandShakeBase* CreateServerHelloDone()    { return new (ys) ServerHelloDone; }
-HandShakeBase* CreateCertificateVerify()  { return new (ys) CertificateVerify;}
-HandShakeBase* CreateClientKeyExchange()  { return new (ys) ClientKeyExchange;}
-HandShakeBase* CreateFinished()           { return new (ys) Finished; }
+HandShakeBase* CreateServerHelloDone()    { return NEW_YS ServerHelloDone; }
+HandShakeBase* CreateCertificateVerify()  { return NEW_YS CertificateVerify;}
+HandShakeBase* CreateClientKeyExchange()  { return NEW_YS ClientKeyExchange;}
+HandShakeBase* CreateFinished()           { return NEW_YS Finished; }
 
 // Create functions for server key exchange factory
-ServerKeyBase* CreateRSAServerKEA()       { return new (ys) RSA_Server; }
-ServerKeyBase* CreateDHServerKEA()        { return new (ys) DH_Server; }
-ServerKeyBase* CreateFortezzaServerKEA()  { return new (ys) Fortezza_Server; }
+ServerKeyBase* CreateRSAServerKEA()       { return NEW_YS RSA_Server; }
+ServerKeyBase* CreateDHServerKEA()        { return NEW_YS DH_Server; }
+ServerKeyBase* CreateFortezzaServerKEA()  { return NEW_YS Fortezza_Server; }
 
 // Create functions for client key exchange factory
-ClientKeyBase* CreateRSAClient()      { return new (ys) 
+ClientKeyBase* CreateRSAClient()      { return NEW_YS 
                                                 EncryptedPreMasterSecret; }
-ClientKeyBase* CreateDHClient()       { return new (ys) 
+ClientKeyBase* CreateDHClient()       { return NEW_YS 
                                                 ClientDiffieHellmanPublic; }
-ClientKeyBase* CreateFortezzaClient() { return new (ys) FortezzaKeys; }
+ClientKeyBase* CreateFortezzaClient() { return NEW_YS FortezzaKeys; }
 
 
 // Constructor calls this to Register compile time callbacks
diff --git a/extra/yassl/src/yassl_int.cpp b/extra/yassl/src/yassl_int.cpp
index 740618ce701..ab5c829a570 100644
--- a/extra/yassl/src/yassl_int.cpp
+++ b/extra/yassl/src/yassl_int.cpp
@@ -31,40 +31,41 @@
 #include "openssl/ssl.h"  // for DH
 
 
-void* operator new(size_t sz, yaSSL::new_t)
-{
 #ifdef YASSL_PURE_C
+
+    void* operator new(size_t sz, yaSSL::new_t)
+    {
     void* ptr = malloc(sz ? sz : 1);
     if (!ptr) abort();
 
     return ptr;
-#else
-    return ::operator new(sz);
-#endif
-}
+    }
 
 
-void operator delete(void* ptr, yaSSL::new_t)
-{
-#ifdef YASSL_PURE_C
+    void operator delete(void* ptr, yaSSL::new_t)
+    {
     if (ptr) free(ptr);
-#else
-    ::operator delete(ptr);
-#endif
-}
+    }
 
 
-void* operator new[](size_t sz, yaSSL::new_t nt)
-{
+    void* operator new[](size_t sz, yaSSL::new_t nt)
+    {
     return ::operator new(sz, nt);
-}
+    }
 
 
-void operator delete[](void* ptr, yaSSL::new_t nt)
-{
+    void operator delete[](void* ptr, yaSSL::new_t nt)
+    {
     ::operator delete(ptr, nt);
-}
+    }
 
+    namespace yaSSL {
+
+        new_t ys;   // for yaSSL library new
+
+    }
+
+#endif // YASSL_PURE_C
 
 
 namespace yaSSL {
@@ -72,7 +73,6 @@ namespace yaSSL {
 
 using mySTL::min;
 
-new_t ys;   // for yaSSL library new
 
 
 
@@ -286,6 +286,8 @@ SSL::SSL(SSL_CTX* ctx)
 
     if (ctx->getMethod()->verifyPeer())
         cm.setVerifyPeer();
+    if (ctx->getMethod()->verifyNone())
+        cm.setVerifyNone();
     if (ctx->getMethod()->failNoCert())
         cm.setFailNoCert();
 
@@ -321,8 +323,8 @@ void SSL::set_pending(Cipher suite)
         parms.key_size_  = AES_256_KEY_SZ;
         parms.iv_size_   = AES_BLOCK_SZ;
         parms.cipher_type_ = block;
-        crypto_.setDigest(new (ys) SHA);
-        crypto_.setCipher(new (ys) AES(AES_256_KEY_SZ));
+        crypto_.setDigest(NEW_YS SHA);
+        crypto_.setCipher(NEW_YS AES(AES_256_KEY_SZ));
         strncpy(parms.cipher_name_, cipher_names[TLS_RSA_WITH_AES_256_CBC_SHA],
                 MAX_SUITE_NAME);
         break;
@@ -335,8 +337,8 @@ void SSL::set_pending(Cipher suite)
         parms.key_size_  = AES_128_KEY_SZ;
         parms.iv_size_   = AES_BLOCK_SZ;
         parms.cipher_type_ = block;
-        crypto_.setDigest(new (ys) SHA);
-        crypto_.setCipher(new (ys) AES);
+        crypto_.setDigest(NEW_YS SHA);
+        crypto_.setCipher(NEW_YS AES);
         strncpy(parms.cipher_name_, cipher_names[TLS_RSA_WITH_AES_128_CBC_SHA],
                 MAX_SUITE_NAME);
         break;
@@ -349,8 +351,8 @@ void SSL::set_pending(Cipher suite)
         parms.key_size_  = DES_EDE_KEY_SZ;
         parms.iv_size_   = DES_IV_SZ;
         parms.cipher_type_ = block;
-        crypto_.setDigest(new (ys) SHA);
-        crypto_.setCipher(new (ys) DES_EDE);
+        crypto_.setDigest(NEW_YS SHA);
+        crypto_.setCipher(NEW_YS DES_EDE);
         strncpy(parms.cipher_name_, cipher_names[SSL_RSA_WITH_3DES_EDE_CBC_SHA]
                 , MAX_SUITE_NAME);
         break;
@@ -363,8 +365,8 @@ void SSL::set_pending(Cipher suite)
         parms.key_size_  = DES_KEY_SZ;
         parms.iv_size_   = DES_IV_SZ;
         parms.cipher_type_ = block;
-        crypto_.setDigest(new (ys) SHA);
-        crypto_.setCipher(new (ys) DES);
+        crypto_.setDigest(NEW_YS SHA);
+        crypto_.setCipher(NEW_YS DES);
         strncpy(parms.cipher_name_, cipher_names[SSL_RSA_WITH_DES_CBC_SHA],
                 MAX_SUITE_NAME);
         break;
@@ -377,8 +379,8 @@ void SSL::set_pending(Cipher suite)
         parms.key_size_  = RC4_KEY_SZ;
         parms.iv_size_   = 0;
         parms.cipher_type_ = stream;
-        crypto_.setDigest(new (ys) SHA);
-        crypto_.setCipher(new (ys) RC4);
+        crypto_.setDigest(NEW_YS SHA);
+        crypto_.setCipher(NEW_YS RC4);
         strncpy(parms.cipher_name_, cipher_names[SSL_RSA_WITH_RC4_128_SHA],
                 MAX_SUITE_NAME);
         break;
@@ -391,8 +393,8 @@ void SSL::set_pending(Cipher suite)
         parms.key_size_  = RC4_KEY_SZ;
         parms.iv_size_   = 0;
         parms.cipher_type_ = stream;
-        crypto_.setDigest(new (ys) MD5);
-        crypto_.setCipher(new (ys) RC4);
+        crypto_.setDigest(NEW_YS MD5);
+        crypto_.setCipher(NEW_YS RC4);
         strncpy(parms.cipher_name_, cipher_names[SSL_RSA_WITH_RC4_128_MD5],
                 MAX_SUITE_NAME);
         break;
@@ -407,8 +409,8 @@ void SSL::set_pending(Cipher suite)
         parms.iv_size_   = DES_IV_SZ;
         parms.cipher_type_ = block;
         secure_.use_connection().send_server_key_  = true; // eph
-        crypto_.setDigest(new (ys) SHA);
-        crypto_.setCipher(new (ys) DES);
+        crypto_.setDigest(NEW_YS SHA);
+        crypto_.setCipher(NEW_YS DES);
         strncpy(parms.cipher_name_, cipher_names[SSL_DHE_RSA_WITH_DES_CBC_SHA],
                 MAX_SUITE_NAME);
         break;
@@ -423,8 +425,8 @@ void SSL::set_pending(Cipher suite)
         parms.iv_size_   = DES_IV_SZ;
         parms.cipher_type_ = block;
         secure_.use_connection().send_server_key_  = true; // eph
-        crypto_.setDigest(new (ys) SHA);
-        crypto_.setCipher(new (ys) DES_EDE);
+        crypto_.setDigest(NEW_YS SHA);
+        crypto_.setCipher(NEW_YS DES_EDE);
         strncpy(parms.cipher_name_,
               cipher_names[SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA], MAX_SUITE_NAME);
         break;
@@ -439,8 +441,8 @@ void SSL::set_pending(Cipher suite)
         parms.iv_size_   = AES_BLOCK_SZ;
         parms.cipher_type_ = block;
         secure_.use_connection().send_server_key_  = true; // eph
-        crypto_.setDigest(new (ys) SHA);
-        crypto_.setCipher(new (ys) AES(AES_256_KEY_SZ));
+        crypto_.setDigest(NEW_YS SHA);
+        crypto_.setCipher(NEW_YS AES(AES_256_KEY_SZ));
         strncpy(parms.cipher_name_,
                cipher_names[TLS_DHE_RSA_WITH_AES_256_CBC_SHA], MAX_SUITE_NAME);
         break;
@@ -455,8 +457,8 @@ void SSL::set_pending(Cipher suite)
         parms.iv_size_   = AES_BLOCK_SZ;
         parms.cipher_type_ = block;
         secure_.use_connection().send_server_key_  = true; // eph
-        crypto_.setDigest(new (ys) SHA);
-        crypto_.setCipher(new (ys) AES);
+        crypto_.setDigest(NEW_YS SHA);
+        crypto_.setCipher(NEW_YS AES);
         strncpy(parms.cipher_name_,
                cipher_names[TLS_DHE_RSA_WITH_AES_128_CBC_SHA], MAX_SUITE_NAME);
         break;
@@ -471,8 +473,8 @@ void SSL::set_pending(Cipher suite)
         parms.iv_size_   = DES_IV_SZ;
         parms.cipher_type_ = block;
         secure_.use_connection().send_server_key_  = true; // eph
-        crypto_.setDigest(new (ys) SHA);
-        crypto_.setCipher(new (ys) DES);
+        crypto_.setDigest(NEW_YS SHA);
+        crypto_.setCipher(NEW_YS DES);
         strncpy(parms.cipher_name_, cipher_names[SSL_DHE_DSS_WITH_DES_CBC_SHA],
                 MAX_SUITE_NAME);
         break;
@@ -487,8 +489,8 @@ void SSL::set_pending(Cipher suite)
         parms.iv_size_   = DES_IV_SZ;
         parms.cipher_type_ = block;
         secure_.use_connection().send_server_key_  = true; // eph
-        crypto_.setDigest(new (ys) SHA);
-        crypto_.setCipher(new (ys) DES_EDE);
+        crypto_.setDigest(NEW_YS SHA);
+        crypto_.setCipher(NEW_YS DES_EDE);
         strncpy(parms.cipher_name_,
               cipher_names[SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA], MAX_SUITE_NAME);
         break;
@@ -503,8 +505,8 @@ void SSL::set_pending(Cipher suite)
         parms.iv_size_   = AES_BLOCK_SZ;
         parms.cipher_type_ = block;
         secure_.use_connection().send_server_key_  = true; // eph
-        crypto_.setDigest(new (ys) SHA);
-        crypto_.setCipher(new (ys) AES(AES_256_KEY_SZ));
+        crypto_.setDigest(NEW_YS SHA);
+        crypto_.setCipher(NEW_YS AES(AES_256_KEY_SZ));
         strncpy(parms.cipher_name_,
                cipher_names[TLS_DHE_DSS_WITH_AES_256_CBC_SHA], MAX_SUITE_NAME);
         break;
@@ -519,8 +521,8 @@ void SSL::set_pending(Cipher suite)
         parms.iv_size_   = AES_BLOCK_SZ;
         parms.cipher_type_ = block;
         secure_.use_connection().send_server_key_  = true; // eph
-        crypto_.setDigest(new (ys) SHA);
-        crypto_.setCipher(new (ys) AES);
+        crypto_.setDigest(NEW_YS SHA);
+        crypto_.setCipher(NEW_YS AES);
         strncpy(parms.cipher_name_,
                cipher_names[TLS_DHE_DSS_WITH_AES_128_CBC_SHA], MAX_SUITE_NAME);
         break;
@@ -533,8 +535,8 @@ void SSL::set_pending(Cipher suite)
         parms.key_size_  = AES_256_KEY_SZ;
         parms.iv_size_   = AES_BLOCK_SZ;
         parms.cipher_type_ = block;
-        crypto_.setDigest(new (ys) RMD);
-        crypto_.setCipher(new (ys) AES(AES_256_KEY_SZ));
+        crypto_.setDigest(NEW_YS RMD);
+        crypto_.setCipher(NEW_YS AES(AES_256_KEY_SZ));
         strncpy(parms.cipher_name_,
                 cipher_names[TLS_RSA_WITH_AES_256_CBC_RMD160], MAX_SUITE_NAME);
         break;
@@ -547,8 +549,8 @@ void SSL::set_pending(Cipher suite)
         parms.key_size_  = AES_128_KEY_SZ;
         parms.iv_size_   = AES_BLOCK_SZ;
         parms.cipher_type_ = block;
-        crypto_.setDigest(new (ys) RMD);
-        crypto_.setCipher(new (ys) AES);
+        crypto_.setDigest(NEW_YS RMD);
+        crypto_.setCipher(NEW_YS AES);
         strncpy(parms.cipher_name_,
                 cipher_names[TLS_RSA_WITH_AES_128_CBC_RMD160], MAX_SUITE_NAME);
         break;
@@ -561,8 +563,8 @@ void SSL::set_pending(Cipher suite)
         parms.key_size_  = DES_EDE_KEY_SZ;
         parms.iv_size_   = DES_IV_SZ;
         parms.cipher_type_ = block;
-        crypto_.setDigest(new (ys) RMD);
-        crypto_.setCipher(new (ys) DES_EDE);
+        crypto_.setDigest(NEW_YS RMD);
+        crypto_.setCipher(NEW_YS DES_EDE);
         strncpy(parms.cipher_name_,
                cipher_names[TLS_RSA_WITH_3DES_EDE_CBC_RMD160], MAX_SUITE_NAME);
         break;
@@ -577,8 +579,8 @@ void SSL::set_pending(Cipher suite)
         parms.iv_size_   = DES_IV_SZ;
         parms.cipher_type_ = block;
         secure_.use_connection().send_server_key_  = true; // eph
-        crypto_.setDigest(new (ys) RMD);
-        crypto_.setCipher(new (ys) DES_EDE);
+        crypto_.setDigest(NEW_YS RMD);
+        crypto_.setCipher(NEW_YS DES_EDE);
         strncpy(parms.cipher_name_,
                 cipher_names[TLS_DHE_RSA_WITH_3DES_EDE_CBC_RMD160],
                 MAX_SUITE_NAME);
@@ -594,8 +596,8 @@ void SSL::set_pending(Cipher suite)
         parms.iv_size_   = AES_BLOCK_SZ;
         parms.cipher_type_ = block;
         secure_.use_connection().send_server_key_  = true; // eph
-        crypto_.setDigest(new (ys) RMD);
-        crypto_.setCipher(new (ys) AES(AES_256_KEY_SZ));
+        crypto_.setDigest(NEW_YS RMD);
+        crypto_.setCipher(NEW_YS AES(AES_256_KEY_SZ));
         strncpy(parms.cipher_name_,
                 cipher_names[TLS_DHE_RSA_WITH_AES_256_CBC_RMD160],
                 MAX_SUITE_NAME);
@@ -611,8 +613,8 @@ void SSL::set_pending(Cipher suite)
         parms.iv_size_   = AES_BLOCK_SZ;
         parms.cipher_type_ = block;
         secure_.use_connection().send_server_key_  = true; // eph
-        crypto_.setDigest(new (ys) RMD);
-        crypto_.setCipher(new (ys) AES);
+        crypto_.setDigest(NEW_YS RMD);
+        crypto_.setCipher(NEW_YS AES);
         strncpy(parms.cipher_name_,
                 cipher_names[TLS_DHE_RSA_WITH_AES_128_CBC_RMD160],
                 MAX_SUITE_NAME);
@@ -628,8 +630,8 @@ void SSL::set_pending(Cipher suite)
         parms.iv_size_   = DES_IV_SZ;
         parms.cipher_type_ = block;
         secure_.use_connection().send_server_key_  = true; // eph
-        crypto_.setDigest(new (ys) RMD);
-        crypto_.setCipher(new (ys) DES_EDE);
+        crypto_.setDigest(NEW_YS RMD);
+        crypto_.setCipher(NEW_YS DES_EDE);
         strncpy(parms.cipher_name_,
                 cipher_names[TLS_DHE_DSS_WITH_3DES_EDE_CBC_RMD160],
                 MAX_SUITE_NAME);
@@ -645,8 +647,8 @@ void SSL::set_pending(Cipher suite)
         parms.iv_size_   = AES_BLOCK_SZ;
         parms.cipher_type_ = block;
         secure_.use_connection().send_server_key_  = true; // eph
-        crypto_.setDigest(new (ys) RMD);
-        crypto_.setCipher(new (ys) AES(AES_256_KEY_SZ));
+        crypto_.setDigest(NEW_YS RMD);
+        crypto_.setCipher(NEW_YS AES(AES_256_KEY_SZ));
         strncpy(parms.cipher_name_,
                 cipher_names[TLS_DHE_DSS_WITH_AES_256_CBC_RMD160],
                 MAX_SUITE_NAME);
@@ -662,8 +664,8 @@ void SSL::set_pending(Cipher suite)
         parms.iv_size_   = AES_BLOCK_SZ;
         parms.cipher_type_ = block;
         secure_.use_connection().send_server_key_  = true; // eph
-        crypto_.setDigest(new (ys) RMD);
-        crypto_.setCipher(new (ys) AES);
+        crypto_.setDigest(NEW_YS RMD);
+        crypto_.setCipher(NEW_YS AES);
         strncpy(parms.cipher_name_,
                 cipher_names[TLS_DHE_DSS_WITH_AES_128_CBC_RMD160],
                 MAX_SUITE_NAME);
@@ -830,7 +832,7 @@ void SSL::deriveKeys()
     int length = 2 * secure_.get_parms().hash_size_ + 
                  2 * secure_.get_parms().key_size_  +
                  2 * secure_.get_parms().iv_size_;
-    int rounds = length / MD5_LEN + ((length % MD5_LEN) ? 1 : 0);
+    int rounds = (length + MD5_LEN - 1 ) / MD5_LEN;
     input_buffer key_data(rounds * MD5_LEN);
 
     opaque sha_output[SHA_LEN];
@@ -1383,7 +1385,7 @@ typedef Mutex::Lock Lock;
 void Sessions::add(const SSL& ssl) 
 {
     Lock guard(mutex_);
-    list_.push_back(new (ys) SSL_SESSION(ssl, random_));
+    list_.push_back(NEW_YS SSL_SESSION(ssl, random_));
 }
 
 
@@ -1450,7 +1452,8 @@ void Sessions::remove(const opaque* id)
 
 
 SSL_METHOD::SSL_METHOD(ConnectionEnd ce, ProtocolVersion pv) 
-    : version_(pv), side_(ce), verifyPeer_(false), failNoCert_(false) 
+    : version_(pv), side_(ce), verifyPeer_(false), verifyNone_(false),
+      failNoCert_(false) 
 {}
 
 
@@ -1472,6 +1475,12 @@ void SSL_METHOD::setVerifyPeer()
 }
 
 
+void SSL_METHOD::setVerifyNone()
+{
+    verifyNone_ = true;
+}
+
+
 void SSL_METHOD::setFailNoCert()
 {
     failNoCert_ = true;
@@ -1484,6 +1493,12 @@ bool SSL_METHOD::verifyPeer() const
 }
 
 
+bool SSL_METHOD::verifyNone() const
+{
+    return verifyNone_;
+}
+
+
 bool SSL_METHOD::failNoCert() const
 {
     return failNoCert_;
@@ -1560,6 +1575,12 @@ void SSL_CTX::setVerifyPeer()
 }
 
 
+void SSL_CTX::setVerifyNone()
+{
+    method_->setVerifyNone();
+}
+
+
 void SSL_CTX::setFailNoCert()
 {
     method_->setFailNoCert();
@@ -1782,7 +1803,7 @@ void Crypto::SetDH(DiffieHellman* dh)
 void Crypto::SetDH(const DH_Parms& dh)
 {
     if (dh.set_)
-        dh_ = new (ys) DiffieHellman(dh.p_, dh.g_, random_);
+        dh_ = NEW_YS DiffieHellman(dh.p_, dh.g_, random_);
 }
 
 
@@ -1949,7 +1970,7 @@ X509_NAME::X509_NAME(const char* n, size_t sz)
     : name_(0)
 {
     if (sz) {
-        name_ = new (ys) char[sz];
+        name_ = NEW_YS char[sz];
         memcpy(name_, n, sz);
     }
 }
diff --git a/extra/yassl/taocrypt/benchmark/benchmark.cpp b/extra/yassl/taocrypt/benchmark/benchmark.cpp
new file mode 100644
index 00000000000..2905e7df6a9
--- /dev/null
+++ b/extra/yassl/taocrypt/benchmark/benchmark.cpp
@@ -0,0 +1,440 @@
+// benchmark.cpp
+// TaoCrypt benchmark
+
+#include 
+#include 
+
+#include "runtime.hpp"
+#include "des.hpp"
+#include "aes.hpp"
+#include "twofish.hpp"
+#include "blowfish.hpp"
+#include "arc4.hpp"
+#include "md5.hpp"
+#include "sha.hpp"
+#include "ripemd.hpp"
+#include "rsa.hpp"
+#include "dh.hpp"
+#include "dsa.hpp"
+
+
+using namespace TaoCrypt;
+
+void bench_aes(bool show);
+void bench_des();
+void bench_blowfish();
+void bench_twofish();
+void bench_arc4();
+
+void bench_md5();
+void bench_sha();
+void bench_ripemd();
+
+void bench_rsa();
+void bench_dh();
+void bench_dsa();
+
+double current_time();
+
+
+
+
+int main(int argc, char** argv)
+{
+    bench_aes(false);
+    bench_aes(true);
+    bench_blowfish();
+    bench_twofish();
+    bench_arc4();
+    bench_des();
+    
+    printf("\n");
+
+    bench_md5();
+    bench_sha();
+    bench_ripemd();
+
+    printf("\n");
+    
+    bench_rsa();
+    bench_dh();
+    bench_dsa();
+
+    return 0;
+}
+
+const int megs = 5;  // how much to test
+
+const byte key[] = 
+{
+    0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
+    0xfe,0xde,0xba,0x98,0x76,0x54,0x32,0x10,
+    0x89,0xab,0xcd,0xef,0x01,0x23,0x45,0x67
+};
+
+const byte iv[] = 
+{
+    0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef,
+    0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
+    0x11,0x21,0x31,0x41,0x51,0x61,0x71,0x81
+    
+};
+
+
+byte plain [1024*1024];
+byte cipher[1024*1024];
+
+
+void bench_des()
+{
+    DES_EDE3_CBC_Encryption enc;
+    enc.SetKey(key, 16, iv);
+
+    double start = current_time();
+
+    for(int i = 0; i < megs; i++)
+        enc.Process(plain, cipher, sizeof(plain));
+
+    double total = current_time() - start;
+
+    double persec = 1 / total * megs;
+
+    printf("3DES     %d megs took %5.3f seconds, %5.2f MB/s\n", megs, total,
+                                                             persec);
+}
+
+
+void bench_aes(bool show)
+{
+    AES_CBC_Encryption enc;
+    enc.SetKey(key, 16, iv);
+
+    double start = current_time();
+ 
+    for(int i = 0; i < megs; i++)
+        enc.Process(plain, cipher, sizeof(plain));
+
+    double total = current_time() - start;
+
+    double persec = 1 / total * megs;
+
+    if (show)
+        printf("AES      %d megs took %5.3f seconds, %5.2f MB/s\n", megs, total,
+                                                                 persec);
+}
+
+
+void bench_twofish()
+{
+    Twofish_CBC_Encryption enc;
+    enc.SetKey(key, 16, iv);
+
+    double start = current_time();
+
+    for(int i = 0; i < megs; i++)
+        enc.Process(plain, cipher, sizeof(plain));
+
+    double total = current_time() - start;
+
+    double persec = 1 / total * megs;
+
+    printf("Twofish  %d megs took %5.3f seconds, %5.2f MB/s\n", megs, total,
+                                                            persec);
+
+}
+
+
+void bench_blowfish()
+{
+    Blowfish_CBC_Encryption enc;
+    enc.SetKey(key, 16, iv);
+
+    double start = current_time();
+
+    for(int i = 0; i < megs; i++)
+        enc.Process(plain, cipher, sizeof(plain));
+
+    double total = current_time() - start;
+
+    double persec = 1 / total * megs;
+
+    printf("Blowfish %d megs took %5.3f seconds, %5.2f MB/s\n", megs, total,
+                                                             persec);
+}
+
+
+void bench_arc4()
+{
+    ARC4 enc;
+    enc.SetKey(key, 16);
+
+    double start = current_time();
+
+    for(int i = 0; i < megs; i++)
+        enc.Process(cipher, plain, sizeof(plain));
+
+    double total = current_time() - start;
+
+    double persec = 1 / total * megs;
+
+    printf("ARC4     %d megs took %5.3f seconds, %5.2f MB/s\n", megs, total,
+                                                             persec);
+}
+
+
+void bench_md5()
+{
+    MD5 hash;
+    byte digest[MD5::DIGEST_SIZE];
+
+    double start = current_time();
+
+    
+    for(int i = 0; i < megs; i++)
+        hash.Update(plain, sizeof(plain));
+   
+    hash.Final(digest);
+
+    double total = current_time() - start;
+
+    double persec = 1 / total * megs;
+
+    printf("MD5      %d megs took %5.3f seconds, %5.2f MB/s\n", megs, total,
+                                                             persec);
+}
+
+
+void bench_sha()
+{
+    SHA hash;
+    byte digest[SHA::DIGEST_SIZE];
+
+    double start = current_time();
+
+    
+    for(int i = 0; i < megs; i++)
+        hash.Update(plain, sizeof(plain));
+   
+    hash.Final(digest);
+
+    /*
+    for(int i = 0; i < megs; i++)
+        hash.AsmTransform(plain, 16384);
+    */
+
+
+    double total = current_time() - start;
+
+    double persec = 1 / total * megs;
+
+    printf("SHA      %d megs took %5.3f seconds, %5.2f MB/s\n", megs, total,
+                                                             persec);
+}
+
+
+void bench_ripemd()
+{
+    RIPEMD160 hash;
+    byte digest[RIPEMD160::DIGEST_SIZE];
+
+    double start = current_time();
+
+    
+    for(int i = 0; i < megs; i++)
+        hash.Update(plain, sizeof(plain));
+   
+    hash.Final(digest);
+
+    double total = current_time() - start;
+
+    double persec = 1 / total * megs;
+
+    printf("RIPEMD   %d megs took %5.3f seconds, %5.2f MB/s\n", megs, total,
+                                                             persec);
+}
+
+RandomNumberGenerator rng;
+
+void bench_rsa()
+{
+    const int times = 100;
+
+    Source source;
+    FileSource("./rsa1024.der", source);
+
+    if (source.size() == 0) {
+        printf("can't find ./rsa1024.der\n");
+        return;
+    }
+    RSA_PrivateKey priv(source);
+    RSAES_Encryptor enc(priv);
+
+    byte      message[] = "Everyone gets Friday off.";
+    byte      cipher[128];  // for 1024 bit
+    byte      plain[128];   // for 1024 bit
+    const int len = strlen((char*)message);
+    
+    int i;    
+    double start = current_time();
+
+    for (i = 0; i < times; i++)
+        enc.Encrypt(message, len, cipher, rng);
+
+    double total = current_time() - start;
+    double each  = total / times;   // per second
+    double milliEach = each * 1000; // milliseconds
+
+    printf("RSA 1024 encryption took  %3.2f milliseconds, avg over %d" 
+           " iterations\n", milliEach, times);
+
+    RSAES_Decryptor dec(priv);
+
+    start = current_time();
+
+    for (i = 0; i < times; i++)
+        dec.Decrypt(cipher, 128, plain, rng);
+
+    total = current_time() - start;
+    each  = total / times;   // per second
+    milliEach = each * 1000; // milliseconds
+
+    printf("RSA 1024 decryption took %3.2f milliseconds, avg over %d" 
+           " iterations\n", milliEach, times);
+}
+
+
+void bench_dh()
+{
+    const int times = 100;
+
+    Source source;
+    FileSource("./dh1024.der", source);
+
+    if (source.size() == 0) {
+        printf("can't find ./dh1024.der\n");
+        return;
+    }
+    DH dh(source);
+
+    byte      pub[128];    // for 1024 bit
+    byte      priv[128];   // for 1024 bit
+    
+    int i;    
+    double start = current_time();
+
+    for (i = 0; i < times; i++)
+        dh.GenerateKeyPair(rng, priv, pub);
+
+    double total = current_time() - start;
+    double each  = total / times;   // per second
+    double milliEach = each * 1000; // milliseconds
+
+    printf("DH  1024 key generation   %3.2f milliseconds, avg over %d" 
+           " iterations\n", milliEach, times);
+
+    DH dh2(dh); 
+    byte      pub2[128];    // for 1024 bit
+    byte      priv2[128];   // for 1024 bit
+    dh2.GenerateKeyPair(rng, priv2, pub2);
+    unsigned char key[256];
+
+    start = current_time();
+
+    for (i = 0; i < times; i++)
+        dh.Agree(key, priv, pub2);
+
+    total = current_time() - start;
+    each  = total / times;      // per second
+    milliEach = each * 1000;   //  in milliseconds
+
+    printf("DH  1024 key agreement    %3.2f milliseconds, avg over %d"
+           " iterations\n", milliEach, times);
+}
+
+void bench_dsa()
+{
+    const int times = 100;
+
+    Source source;
+    FileSource("./dsa1024.der", source);
+
+    if (source.size() == 0) {
+        printf("can't find ./dsa1024.der\n");
+        return;
+    }
+
+    DSA_PrivateKey key(source);
+    DSA_Signer signer(key);
+
+    SHA sha;
+    byte digest[SHA::DIGEST_SIZE];
+    byte signature[40];
+    const char msg[] = "this is the message";
+    sha.Update((byte*)msg, sizeof(msg));
+    sha.Final(digest);
+    
+    int i;    
+    double start = current_time();
+
+    for (i = 0; i < times; i++)
+        signer.Sign(digest, signature, rng); 
+
+    double total = current_time() - start;
+    double each  = total / times;   // per second
+    double milliEach = each * 1000; // milliseconds
+
+    printf("DSA 1024 sign   took      %3.2f milliseconds, avg over %d" 
+           " iterations\n", milliEach, times);
+
+    DSA_Verifier verifier(key);
+
+    start = current_time();
+
+    for (i = 0; i < times; i++)
+        verifier.Verify(digest, signature); 
+
+    total = current_time() - start;
+    each  = total / times;      // per second
+    milliEach = each * 1000;   //  in milliseconds
+
+    printf("DSA 1024 verify took      %3.2f milliseconds, avg over %d"
+           " iterations\n", milliEach, times);
+}
+
+
+
+#ifdef _WIN32
+
+    #define WIN32_LEAN_AND_MEAN
+    #include 
+
+    double current_time()
+    {
+        static bool          init(false);
+        static LARGE_INTEGER freq;
+    
+        if (!init) {
+            QueryPerformanceFrequency(&freq);
+            init = true;
+        }
+
+        LARGE_INTEGER count;
+        QueryPerformanceCounter(&count);
+
+        return static_cast(count.QuadPart) / freq.QuadPart;
+    }
+
+#else
+
+    #include 
+
+    double current_time()
+    {
+        struct timeval tv;
+        gettimeofday(&tv, 0);
+
+        return static_cast(tv.tv_sec) 
+             + static_cast(tv.tv_usec) / 1000000;
+    }
+
+#endif // _WIN32
diff --git a/extra/yassl/taocrypt/benchmark/benchmark.dsp b/extra/yassl/taocrypt/benchmark/benchmark.dsp
new file mode 100644
index 00000000000..ed8fef316bb
--- /dev/null
+++ b/extra/yassl/taocrypt/benchmark/benchmark.dsp
@@ -0,0 +1,101 @@
+# Microsoft Developer Studio Project File - Name="benchmark" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Console Application" 0x0103
+
+CFG=benchmark - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE 
+!MESSAGE NMAKE /f "benchmark.mak".
+!MESSAGE 
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE 
+!MESSAGE NMAKE /f "benchmark.mak" CFG="benchmark - Win32 Debug"
+!MESSAGE 
+!MESSAGE Possible choices for configuration are:
+!MESSAGE 
+!MESSAGE "benchmark - Win32 Release" (based on "Win32 (x86) Console Application")
+!MESSAGE "benchmark - Win32 Debug" (based on "Win32 (x86) Console Application")
+!MESSAGE 
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF  "$(CFG)" == "benchmark - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "benchmark___Win32_Release"
+# PROP BASE Intermediate_Dir "benchmark___Win32_Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /MT /W3 /GX /O2 /I "..\include" /I "..\..\mySTL" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib  kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib  kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+
+!ELSEIF  "$(CFG)" == "benchmark - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "benchmark___Win32_Debug"
+# PROP BASE Intermediate_Dir "benchmark___Win32_Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ  /c
+# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "..\include" /I "..\..\mySTL" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ  /c
+# ADD BASE RSC /l 0x409 /d "_DEBUG"
+# ADD RSC /l 0x409 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib  kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib  kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+
+!ENDIF 
+
+# Begin Target
+
+# Name "benchmark - Win32 Release"
+# Name "benchmark - Win32 Debug"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\benchmark.cpp
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# End Group
+# Begin Group "Resource Files"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# End Target
+# End Project
diff --git a/extra/yassl/taocrypt/benchmark/make.bat b/extra/yassl/taocrypt/benchmark/make.bat
new file mode 100644
index 00000000000..63391578cfa
--- /dev/null
+++ b/extra/yassl/taocrypt/benchmark/make.bat
@@ -0,0 +1,10 @@
+# quick and dirty build file for testing different MSDEVs
+setlocal 
+
+set myFLAGS= /I../include /I../../mySTL /c /W3 /G6 /O2
+#set myFLAGS= /I../include /I../../mySTL /c /W3 
+
+cl %myFLAGS% benchmark.cpp
+
+link.exe  /out:benchmark.exe ../src/taocrypt.lib benchmark.obj
+
diff --git a/extra/yassl/taocrypt/include/aes.hpp b/extra/yassl/taocrypt/include/aes.hpp
index b8436d35c5f..e2c1a34b0e3 100644
--- a/extra/yassl/taocrypt/include/aes.hpp
+++ b/extra/yassl/taocrypt/include/aes.hpp
@@ -26,13 +26,13 @@
 #ifndef TAO_CRYPT_AES_HPP
 #define TAO_CRYPT_AES_HPP
 
-#include 
 #include "misc.hpp"
 #include "modes.hpp"
-#include "block.hpp"
+
 
 namespace TaoCrypt {
 
+
 enum { AES_BLOCK_SIZE = 16 };
 
 
@@ -45,32 +45,38 @@ public:
         : Mode_BASE(BLOCK_SIZE), dir_(DIR), mode_(MODE) {}
 
     void Process(byte*, const byte*, word32);
-    void SetKey(const byte* iv, word32 sz, CipherDir fake = ENCRYPTION);
-
-    void ProcessAndXorBlock(const byte*, const byte*, byte*) const;
+    void SetKey(const byte* key, word32 sz, CipherDir fake = ENCRYPTION);
+    void SetIV(const byte* iv) { memcpy(r_, iv, BLOCK_SIZE); }
 private:
     CipherDir dir_;
     Mode      mode_;
 
-    static const word32 Te0[256];
-    static const word32 Te1[256];
-    static const word32 Te2[256];
-    static const word32 Te3[256];
-    static const word32 Te4[256];
-
-    static const word32 Td0[256];
-    static const word32 Td1[256];
-    static const word32 Td2[256];
-    static const word32 Td3[256];
-    static const word32 Td4[256];
-
     static const word32 rcon_[];
 
     word32      rounds_;
-    Word32Block key_;
+    word32      key_[60];                        // max size
+
+    static const word32 Te[5][256];
+    static const word32 Td[5][256];
+
+    static const word32* Te0;
+    static const word32* Te1;
+    static const word32* Te2;
+    static const word32* Te3;
+    static const word32* Te4;
+
+    static const word32* Td0;
+    static const word32* Td1;
+    static const word32* Td2;
+    static const word32* Td3;
+    static const word32* Td4;
 
     void encrypt(const byte*, const byte*, byte*) const;
+    void AsmEncrypt(const byte*, byte*, void*) const;
     void decrypt(const byte*, const byte*, byte*) const;
+    void AsmDecrypt(const byte*, byte*, void*) const;
+
+    void ProcessAndXorBlock(const byte*, const byte*, byte*) const;
 
     AES(const AES&);            // hide copy
     AES& operator=(const AES&); // and assign
diff --git a/extra/yassl/taocrypt/include/arc4.hpp b/extra/yassl/taocrypt/include/arc4.hpp
index c919c8ea2ae..c37b89fb294 100644
--- a/extra/yassl/taocrypt/include/arc4.hpp
+++ b/extra/yassl/taocrypt/include/arc4.hpp
@@ -42,6 +42,7 @@ public:
     ARC4() {}
 
     void Process(byte*, const byte*, word32);
+    void AsmProcess(byte*, const byte*, word32);
     void SetKey(const byte*, word32);
 private:
     byte x_;
diff --git a/extra/yassl/taocrypt/include/asn.hpp b/extra/yassl/taocrypt/include/asn.hpp
index 14fcf22d843..6a1163fbb1c 100644
--- a/extra/yassl/taocrypt/include/asn.hpp
+++ b/extra/yassl/taocrypt/include/asn.hpp
@@ -232,7 +232,12 @@ enum KeyType  { DSAk = 515, RSAk = 645 };     // sums of algo OID
 // an x509v Certificate BER Decoder
 class CertDecoder : public BER_Decoder {
 public:
-    explicit CertDecoder(Source&, bool decode = true, SignerList* = 0);
+    enum DateType { BEFORE, AFTER };   
+    enum NameType { ISSUER, SUBJECT };
+    enum CertType { CA, USER };
+
+    explicit CertDecoder(Source&, bool decode = true, SignerList* sl = 0,
+                         bool noVerify = false, CertType ct = USER);
     ~CertDecoder();
 
     const PublicKey& GetPublicKey()  const { return key_; }
@@ -242,9 +247,6 @@ public:
     const byte*      GetHash()       const { return subjectHash_; }
 
     void DecodeToKey();
-
-    enum DateType { BEFORE, AFTER };   
-    enum NameType { ISSUER, SUBJECT };
 private:
     PublicKey key_;
     word32    certBegin_;               // offset to start of cert
@@ -257,9 +259,10 @@ private:
     byte*     signature_;
     char*     issuer_;                  // CommonName
     char*     subject_;                 // CommonName
+    bool      verify_;                  // Default to yes, but could be off
 
     void   ReadHeader();
-    void   Decode(SignerList*);
+    void   Decode(SignerList*, CertType);
     void   StoreKey();
     void   AddDSA();
     bool   ValidateSelfSignature();
diff --git a/extra/yassl/taocrypt/include/block.hpp b/extra/yassl/taocrypt/include/block.hpp
index ee00ad7487f..4c262e1a540 100644
--- a/extra/yassl/taocrypt/include/block.hpp
+++ b/extra/yassl/taocrypt/include/block.hpp
@@ -99,7 +99,7 @@ public:
         CheckSize(n);
         if (n == 0)
             return 0;
-        return new (tc) T[n];
+        return NEW_TC T[n];
     }
 
     void deallocate(void* p, size_type n)
diff --git a/extra/yassl/taocrypt/include/blowfish.hpp b/extra/yassl/taocrypt/include/blowfish.hpp
new file mode 100644
index 00000000000..7d794a37329
--- /dev/null
+++ b/extra/yassl/taocrypt/include/blowfish.hpp
@@ -0,0 +1,79 @@
+/* blowfish.hpp                                
+ *
+ * Copyright (C) 2003 Sawtooth Consulting Ltd.
+ *
+ * This file is part of yaSSL.
+ *
+ * yaSSL 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; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * yaSSL 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ */
+
+/* blowfish.hpp defines Blowfish
+*/
+
+
+#ifndef TAO_CRYPT_BLOWFISH_HPP
+#define TAO_CRYPT_BLOWFISH_HPP
+
+#include "misc.hpp"
+#include "modes.hpp"
+#include "algorithm.hpp"
+
+namespace TaoCrypt {
+
+enum { BLOWFISH_BLOCK_SIZE = 8 };
+
+
+// Blowfish encryption and decryption, see 
+class Blowfish : public Mode_BASE {
+public:
+    enum { BLOCK_SIZE = BLOWFISH_BLOCK_SIZE, ROUNDS = 16 };
+
+    Blowfish(CipherDir DIR, Mode MODE)
+        : Mode_BASE(BLOCK_SIZE), dir_(DIR), mode_(MODE) {}
+
+    void Process(byte*, const byte*, word32);
+    void SetKey(const byte* key, word32 sz, CipherDir fake = ENCRYPTION);
+    void SetIV(const byte* iv) { memcpy(r_, iv, BLOCK_SIZE); }
+private:
+    CipherDir dir_;
+    Mode      mode_;
+
+	static const word32 p_init_[ROUNDS + 2];
+	static const word32 s_init_[4 * 256];
+
+	word32 pbox_[ROUNDS + 2];
+	word32 sbox_[4 * 256];
+
+    void crypt_block(const word32 in[2], word32 out[2]) const;
+    void AsmProcess(const byte* in, byte* out) const;
+    void ProcessAndXorBlock(const byte*, const byte*, byte*) const;
+
+    Blowfish(const Blowfish&);            // hide copy
+    Blowfish& operator=(const Blowfish&); // and assign
+};
+
+
+typedef BlockCipher Blowfish_ECB_Encryption;
+typedef BlockCipher Blowfish_ECB_Decryption;
+
+typedef BlockCipher Blowfish_CBC_Encryption;
+typedef BlockCipher Blowfish_CBC_Decryption;
+
+
+
+} // naemspace
+
+#endif // TAO_CRYPT_BLOWFISH_HPP
+
diff --git a/extra/yassl/taocrypt/include/des.hpp b/extra/yassl/taocrypt/include/des.hpp
index 127b8ddc6d5..e0867b09166 100644
--- a/extra/yassl/taocrypt/include/des.hpp
+++ b/extra/yassl/taocrypt/include/des.hpp
@@ -27,73 +27,87 @@
 #ifndef TAO_CRYPT_DES_HPP
 #define TAO_CRYPT_DES_HPP
 
-#include 
 #include "misc.hpp"
 #include "modes.hpp"
 
 namespace TaoCrypt {
 
-enum { DES_BLOCK_SIZE = 8 };
 
-// Base for all DES types
-class DES_BASE : public Mode_BASE {
+enum { DES_BLOCK_SIZE = 8, DES_KEY_SIZE = 32 };
+
+
+class BasicDES {
 public:
-    enum { BLOCK_SIZE = DES_BLOCK_SIZE, KEY_SIZE = 32, BOXES = 8,
-           BOX_SIZE = 64 };
-
-    DES_BASE(CipherDir DIR, Mode MODE) 
-        : Mode_BASE(BLOCK_SIZE), dir_(DIR), mode_(MODE) {}
-
-    void Process(byte*, const byte*, word32);
+    void SetKey(const byte*, word32, CipherDir dir);
+    void RawProcessBlock(word32&, word32&) const;
 protected:
-    CipherDir dir_;
-    Mode      mode_;
-private:
-    DES_BASE(const DES_BASE&);              // hide copy
-    DES_BASE& operator=(const DES_BASE&);   // and assign
+    word32 k_[DES_KEY_SIZE];
 };
 
 
 // DES 
-class DES : public DES_BASE {
+class DES : public Mode_BASE, public BasicDES {
 public:
-    DES(CipherDir DIR, Mode MODE) : DES_BASE(DIR, MODE) {}
+    DES(CipherDir DIR, Mode MODE) 
+        : Mode_BASE(DES_BLOCK_SIZE), dir_(DIR), mode_(MODE) {}
 
-    void SetKey(const byte*, word32, CipherDir dir);
-    void RawProcessBlock(word32&, word32&) const;
-    void ProcessAndXorBlock(const byte*, const byte*, byte*) const;
+    void Process(byte*, const byte*, word32);
 private:
-    word32 k_[KEY_SIZE];
+    CipherDir dir_;
+    Mode      mode_;
+
+    void ProcessAndXorBlock(const byte*, const byte*, byte*) const;
+
+    DES(const DES&);              // hide copy
+    DES& operator=(const DES&);   // and assign
 };
 
 
 // DES_EDE2
-class DES_EDE2 : public DES_BASE {
+class DES_EDE2 : public Mode_BASE {
 public:
     DES_EDE2(CipherDir DIR, Mode MODE) 
-        : DES_BASE(DIR, MODE), des1_(DIR, MODE), des2_(DIR, MODE) {}
+        : Mode_BASE(DES_BLOCK_SIZE), dir_(DIR), mode_(MODE) {}
 
     void SetKey(const byte*, word32, CipherDir dir);
-    void ProcessAndXorBlock(const byte*, const byte*, byte*) const;
+    void Process(byte*, const byte*, word32);
 private:
-    DES des1_;
-    DES des2_;
+    CipherDir dir_;
+    Mode      mode_;
+
+    BasicDES  des1_;
+    BasicDES  des2_;
+
+    void ProcessAndXorBlock(const byte*, const byte*, byte*) const;
+
+    DES_EDE2(const DES_EDE2&);              // hide copy
+    DES_EDE2& operator=(const DES_EDE2&);   // and assign
 };
 
 
+
 // DES_EDE3
-class DES_EDE3 : public DES_BASE {
+class DES_EDE3 : public Mode_BASE {
 public:
     DES_EDE3(CipherDir DIR, Mode MODE) 
-        : DES_BASE(DIR, MODE), des1_(DIR, MODE), des2_(DIR, MODE),
-                               des3_(DIR, MODE) {}
+        : Mode_BASE(DES_BLOCK_SIZE), dir_(DIR), mode_(MODE) {}
 
     void SetKey(const byte*, word32, CipherDir dir);
-    void ProcessAndXorBlock(const byte*, const byte*, byte*) const;
+    void SetIV(const byte* iv) { memcpy(r_, iv, DES_BLOCK_SIZE); }
+    void Process(byte*, const byte*, word32);
 private:
-    DES des1_;
-    DES des2_;
-    DES des3_;
+    CipherDir dir_;
+    Mode      mode_;
+
+    BasicDES  des1_;
+    BasicDES  des2_;
+    BasicDES  des3_;
+
+    void AsmProcess(const byte* in, byte* out, void* box) const;
+    void ProcessAndXorBlock(const byte*, const byte*, byte*) const;
+
+    DES_EDE3(const DES_EDE3&);              // hide copy
+    DES_EDE3& operator=(const DES_EDE3&);   // and assign
 };
 
 
diff --git a/extra/yassl/taocrypt/include/dh.hpp b/extra/yassl/taocrypt/include/dh.hpp
index 54a1705546b..75a5d6280d3 100644
--- a/extra/yassl/taocrypt/include/dh.hpp
+++ b/extra/yassl/taocrypt/include/dh.hpp
@@ -64,7 +64,7 @@ public:
     }
 
     void GenerateKeyPair(RandomNumberGenerator&, byte*, byte*);
-    void Agree(byte*, const byte*, const byte*);
+    void Agree(byte*, const byte*, const byte*, word32 otherSz = 0);
 
     void SetP(const Integer& p) { p_ = p; }
     void SetG(const Integer& g) { g_ = g; }
diff --git a/extra/yassl/taocrypt/include/hash.hpp b/extra/yassl/taocrypt/include/hash.hpp
index 5c90d01aefe..16112cb644d 100644
--- a/extra/yassl/taocrypt/include/hash.hpp
+++ b/extra/yassl/taocrypt/include/hash.hpp
@@ -57,17 +57,26 @@ public:
     virtual void Update(const byte*, word32);
     virtual void Final(byte*);
 
+    word32  GetBitCountLo() const { return  loLen_ << 3; }
+    word32  GetBitCountHi() const { return (loLen_ >> (8*sizeof(loLen_) - 3)) +
+                                           (hiLen_ << 3); } 
+
     enum { MaxDigestSz = 5, MaxBufferSz = 64 };
 protected:
-    word32  buffLen_;
-    word32  length_;    // in Bits
+    typedef word32 HashLengthType;
+    word32          buffLen_;   // in bytes
+    HashLengthType  loLen_;     // length in bytes
+    HashLengthType  hiLen_;     // length in bytes
     word32  digest_[MaxDigestSz];
     word32  buffer_[MaxBufferSz / sizeof(word32)];
 
     virtual void Transform() = 0;
+
+    void AddLength(word32);
 };
 
 
+
 } // namespace
 
 #endif // TAO_CRYPT_HASH_HPP
diff --git a/extra/yassl/taocrypt/include/hmac.hpp b/extra/yassl/taocrypt/include/hmac.hpp
index cf029812ce2..543366afc3a 100644
--- a/extra/yassl/taocrypt/include/hmac.hpp
+++ b/extra/yassl/taocrypt/include/hmac.hpp
@@ -56,12 +56,12 @@ private:
     T     mac_;
 
     // MSVC 6 HACK, gives compiler error if calculated in array
-    enum { HMAC_BSIZE = T::BLOCK_SIZE  / sizeof(word32),
-           HMAC_DSIZE = T::DIGEST_SIZE / sizeof(word32) };
+    enum { BSIZE = T::BLOCK_SIZE  / sizeof(word32),
+           DSIZE = T::DIGEST_SIZE / sizeof(word32) };
 
-    word32 ip_[HMAC_BSIZE];          // align ipad_ on word32
-    word32 op_[HMAC_BSIZE];          // align opad_ on word32
-    word32 innerH_[HMAC_DSIZE];      // align innerHash_ on word32
+    word32 ip_[BSIZE];          // align ipad_ on word32
+    word32 op_[BSIZE];          // align opad_ on word32
+    word32 innerH_[DSIZE];      // align innerHash_ on word32
 
     void KeyInnerHash();
 
diff --git a/extra/yassl/taocrypt/include/kernelc.hpp b/extra/yassl/taocrypt/include/kernelc.hpp
new file mode 100644
index 00000000000..bb74c10ad07
--- /dev/null
+++ b/extra/yassl/taocrypt/include/kernelc.hpp
@@ -0,0 +1,49 @@
+/* kernelc.hpp                                
+ *
+ * Copyright (C) 2003 Sawtooth Consulting Ltd.
+ *
+ * This file is part of yaSSL.
+ *
+ * yaSSL 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; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * yaSSL 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ */
+
+/* kernelc.hpp provides support for C std lib when compiled in kernel mode
+*/
+
+#ifndef TAOCRYPT_KERNELC_HPP
+#define TAOCRYPT_KERNELC_HPP
+
+#include    // get right size_t
+
+// system functions that c++ doesn't like headers for 
+
+extern "C" void* memcpy(void*, const void*, size_t);
+extern "C" void* memset(void*, int, size_t);
+extern "C" void  printk(char *fmt, ...);
+
+#define KERN_ERR "<3>"   /* error conditions */
+
+#if defined(NDEBUG)
+    #define assert(p)  	((void)0)
+#else
+    #define assert(expr)   \
+    if (!(expr))         { \
+         printk(KERN_ERR "Assertion failed! %s,%s,%s,line=%d\n", \
+         #expr,__FILE__,__FUNCTION__,__LINE__); }
+#endif
+
+
+
+#endif // TAOCRYPT_KERNELC_HPP
diff --git a/extra/yassl/taocrypt/include/md5.hpp b/extra/yassl/taocrypt/include/md5.hpp
index 0198daa466e..981f29108fe 100644
--- a/extra/yassl/taocrypt/include/md5.hpp
+++ b/extra/yassl/taocrypt/include/md5.hpp
@@ -45,10 +45,13 @@ public:
     MD5(const MD5&);
     MD5& operator= (const MD5&);
 
+    void Update(const byte*, word32);
+
     void Init();
     void Swap(MD5&);
 private:
     void Transform();
+    void AsmTransform(const byte* data, word32 times);
 };
 
 inline void swap(MD5& a, MD5& b)
diff --git a/extra/yassl/taocrypt/include/misc.hpp b/extra/yassl/taocrypt/include/misc.hpp
index f705cc99970..7a71784893f 100644
--- a/extra/yassl/taocrypt/include/misc.hpp
+++ b/extra/yassl/taocrypt/include/misc.hpp
@@ -24,9 +24,15 @@
 #ifndef TAO_CRYPT_MISC_HPP
 #define TAO_CRYPT_MISC_HPP
 
-#include 
-#include 
-#include 
+
+#if !defined(DO_TAOCRYPT_KERNEL_MODE)
+    #include 
+    #include 
+    #include 
+#else
+    #include "kernelc.hpp"
+#endif
+
 #include "types.hpp"
 #include "type_traits.hpp"
 
@@ -34,31 +40,33 @@
 
 namespace TaoCrypt {
 
-// library allocation
-struct new_t {};      // TaoCrypt New type
-extern new_t tc;      // pass in parameter
+#ifdef YASSL_PURE_C
 
-} // namespace TaoCrypt
+    // library allocation
+    struct new_t {};      // TaoCrypt New type
+    extern new_t tc;      // pass in parameter
 
-void* operator new  (size_t, TaoCrypt::new_t);
-void* operator new[](size_t, TaoCrypt::new_t);
+    } // namespace TaoCrypt
 
-void operator delete  (void*, TaoCrypt::new_t);
-void operator delete[](void*, TaoCrypt::new_t);
+    void* operator new  (size_t, TaoCrypt::new_t);
+    void* operator new[](size_t, TaoCrypt::new_t);
+
+    void operator delete  (void*, TaoCrypt::new_t);
+    void operator delete[](void*, TaoCrypt::new_t);
 
 
-namespace TaoCrypt {
+    namespace TaoCrypt {
 
-template
-void tcDelete(T* ptr)
-{
+    template
+    void tcDelete(T* ptr)
+    {
     if (ptr) ptr->~T();
     ::operator delete(ptr, TaoCrypt::tc);
-}
+    }
 
-template
-void tcArrayDelete(T* ptr)
-{
+    template
+    void tcArrayDelete(T* ptr)
+    {
     // can't do array placement destruction since not tracking size in
     // allocation, only allow builtins to use array placement since they
     // don't need destructors called
@@ -66,15 +74,39 @@ void tcArrayDelete(T* ptr)
     (void)sizeof(builtin);
 
     ::operator delete[](ptr, TaoCrypt::tc);
-}
+    }
+
+    #define NEW_TC new (tc)
 
 
-// to resolve compiler generated operator delete on base classes with
-// virtual destructors (when on stack), make sure doesn't get called
-class virtual_base {
-public:
+    // to resolve compiler generated operator delete on base classes with
+    // virtual destructors (when on stack), make sure doesn't get called
+    class virtual_base {
+    public:
     static void operator delete(void*) { assert(0); }
-};
+    };
+
+#else // YASSL_PURE_C
+
+
+    template
+    void tcDelete(T* ptr)
+    {
+        delete ptr;
+    }
+
+    template
+    void tcArrayDelete(T* ptr)
+    {
+        delete[] ptr;
+    }
+
+    #define NEW_TC new
+
+    class virtual_base {};
+   
+ 
+#endif // YASSL_PURE_C
 
 
 #if defined(_MSC_VER) || defined(__BCPLUSPLUS__)
@@ -91,19 +123,12 @@ public:
 
 
 // no gas on these systems ?, disable for now
-#if defined(__sun__) || defined (__QNX__) || defined (__APPLE__)
+#if defined(__sun__) || defined (__QNX__)
     #define TAOCRYPT_DISABLE_X86ASM
 #endif
 
 
-// Disable assmebler when compiling with icc
-// Temporary workaround for bug12717
-#if defined(__INTEL_COMPILER)
-    #define TAOCRYPT_DISABLE_X86ASM
-#endif
-
-
-
+// Turn on ia32 ASM for Big Integer
 // CodeWarrior defines _MSC_VER
 #if !defined(TAOCRYPT_DISABLE_X86ASM) && ((defined(_MSC_VER) && \
    !defined(__MWERKS__) && defined(_M_IX86)) || \
@@ -112,6 +137,20 @@ public:
 #endif
 
 
+// Turn on ia32 ASM for Ciphers and Message Digests
+// Seperate define since these are more complex, use member offsets
+// and user may want to turn off while leaving Big Integer optos on 
+#if defined(TAOCRYPT_X86ASM_AVAILABLE) && !defined(DISABLE_TAO_ASM)
+    #define TAO_ASM
+#endif
+
+
+//  Extra word in older vtable implementations, for ASM member offset
+#if defined(__GNUC__) && __GNUC__ < 3
+    #define OLD_GCC_OFFSET
+#endif
+
+
 #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
 #	define TAOCRYPT_MALLOC_ALIGNMENT_IS_16
 #endif
@@ -432,6 +471,58 @@ inline void ByteReverseIf(T* out, const T* in, word32 bc, ByteOrder order)
 }
 
 
+
+// do Asm Reverse is host is Little and x86asm 
+#ifdef LITTLE_ENDIAN_ORDER
+    #ifdef TAOCRYPT_X86ASM_AVAILABLE
+        #define LittleReverse AsmReverse
+    #else
+        #define LittleReverse ByteReverse
+    #endif
+#else
+    #define LittleReverse
+#endif
+
+
+// do Asm Reverse is host is Big and x86asm 
+#ifdef BIG_ENDIAN_ORDER
+    #ifdef TAOCRYPT_X86ASM_AVAILABLE
+        #define BigReverse AsmReverse
+    #else
+        #define BigReverse ByteReverse
+    #endif
+#else
+    #define BigReverse
+#endif
+
+
+#ifdef TAOCRYPT_X86ASM_AVAILABLE
+
+    // faster than rotate, use bswap
+
+    inline word32 AsmReverse(word32 wd)
+    {
+    #ifdef __GNUC__
+        __asm__ 
+        (
+            "bswap %1"
+            : "=r"(wd)
+            : "0"(wd)
+        );
+    #else
+        __asm 
+        {
+            mov   eax, wd
+            bswap eax
+            mov   wd, eax
+        }
+    #endif
+        return wd;
+    }
+
+#endif 
+
+
 template 
 inline void GetUserKey(ByteOrder order, T* out, word32 outlen, const byte* in,
                        word32 inlen)
diff --git a/extra/yassl/taocrypt/include/modes.hpp b/extra/yassl/taocrypt/include/modes.hpp
index a23d14db7da..10f336c00eb 100644
--- a/extra/yassl/taocrypt/include/modes.hpp
+++ b/extra/yassl/taocrypt/include/modes.hpp
@@ -26,7 +26,6 @@
 #ifndef TAO_CRYPT_MODES_HPP
 #define TAO_CRYPT_MODES_HPP
 
-#include 
 #include "misc.hpp"
 
 namespace TaoCrypt {
@@ -68,14 +67,8 @@ public:
     }
     virtual ~Mode_BASE() {}
 
-    virtual void ProcessAndXorBlock(const byte*, const byte*, byte*) const = 0;
-
-    void ECB_Process(byte*, const byte*, word32);
-    void CBC_Encrypt(byte*, const byte*, word32);
-    void CBC_Decrypt(byte*, const byte*, word32);
-
     void SetIV(const byte* iv) { memcpy(reg_, iv, blockSz_); }
-private:
+protected:
     int   blockSz_;
     byte* reg_;
     byte* tmp_;
@@ -83,9 +76,15 @@ private:
     word32 r_[MaxBlockSz / sizeof(word32)];  // align reg_ on word32
     word32 t_[MaxBlockSz / sizeof(word32)];  // align tmp_ on word32
 
+    void ECB_Process(byte*, const byte*, word32);
+    void CBC_Encrypt(byte*, const byte*, word32);
+    void CBC_Decrypt(byte*, const byte*, word32);
 
     Mode_BASE(const Mode_BASE&);            // hide copy
     Mode_BASE& operator=(const Mode_BASE&); // and assign
+
+private:
+    virtual void ProcessAndXorBlock(const byte*, const byte*, byte*) const = 0;
 };
 
 
diff --git a/extra/yassl/taocrypt/include/pwdbased.hpp b/extra/yassl/taocrypt/include/pwdbased.hpp
new file mode 100644
index 00000000000..f40c48fe026
--- /dev/null
+++ b/extra/yassl/taocrypt/include/pwdbased.hpp
@@ -0,0 +1,93 @@
+/* pwdbased.hpp                                
+ *
+ * Copyright (C) 2003 Sawtooth Consulting Ltd.
+ *
+ * This file is part of yaSSL.
+ *
+ * yaSSL 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; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * yaSSL 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ */
+
+/* pwdbased.hpp defines PBKDF2 from PKCS #5
+*/
+
+
+#ifndef TAO_CRYPT_PWDBASED_HPP
+#define TAO_CRYPT_PWDBASED_HPP
+
+#include 
+#include "misc.hpp"
+#include "block.hpp"
+#include "hmac.hpp"
+
+namespace TaoCrypt {
+
+
+// From PKCS #5, T must be type suitable for HMAC 
+template 
+class PBKDF2_HMAC {
+public:
+    word32 MaxDerivedKeyLength() const { return 0xFFFFFFFFU;} // avoid overflow
+
+    word32 DeriveKey(byte* derived, word32 dLen, const byte* pwd, word32 pLen,
+                     const byte* salt, word32 sLen, word32 iterations) const;
+}; 
+
+
+
+template 
+word32 PBKDF2_HMAC::DeriveKey(byte* derived, word32 dLen, const byte* pwd,
+                                 word32 pLen, const byte* salt, word32 sLen,
+                                 word32 iterations) const
+{
+	assert(dLen <= MaxDerivedKeyLength());
+	assert(iterations > 0);
+
+    ByteBlock buffer(T::DIGEST_SIZE);
+	HMAC   hmac;
+
+    hmac.SetKey(pwd, pLen);
+
+	word32 i = 1;
+
+	while (dLen > 0) {
+		hmac.Update(salt, sLen);
+		word32 j;
+		for (j = 0; j < 4; j++) {
+			byte b = i >> ((3-j)*8);
+			hmac.Update(&b, 1);
+		}
+		hmac.Final(buffer.get_buffer());
+
+		word32 segmentLen = mySTL::min(dLen, buffer.size());
+		memcpy(derived, buffer.get_buffer(), segmentLen);
+
+		for (j = 1; j < iterations; j++) {
+			hmac.Update(buffer.get_buffer(), buffer.size());
+            hmac.Final(buffer.get_buffer());
+			xorbuf(derived, buffer.get_buffer(), segmentLen);
+		}
+		derived += segmentLen;
+		dLen    -= segmentLen;
+		i++;
+	}
+	return iterations;
+}
+
+
+
+
+} // naemspace
+
+#endif // TAO_CRYPT_PWDBASED_HPP
diff --git a/extra/yassl/taocrypt/include/ripemd.hpp b/extra/yassl/taocrypt/include/ripemd.hpp
index 4f8e1fd0386..b72e503f095 100644
--- a/extra/yassl/taocrypt/include/ripemd.hpp
+++ b/extra/yassl/taocrypt/include/ripemd.hpp
@@ -45,10 +45,12 @@ public:
     RIPEMD160(const RIPEMD160&);
     RIPEMD160& operator= (const RIPEMD160&);
 
+    void Update(const byte*, word32);
     void Init();
     void Swap(RIPEMD160&);
 private:
     void Transform();
+    void AsmTransform(const byte* data, word32 times);
 };
 
 inline void swap(RIPEMD160& a, RIPEMD160& b)
diff --git a/extra/yassl/taocrypt/include/runtime.hpp b/extra/yassl/taocrypt/include/runtime.hpp
index 254e67a7f64..aae4581cc40 100644
--- a/extra/yassl/taocrypt/include/runtime.hpp
+++ b/extra/yassl/taocrypt/include/runtime.hpp
@@ -25,15 +25,18 @@
 
 
 
-#if !defined(yaSSL_NEW_HPP) && defined(__GNUC__) 
-#if !(defined(__ICC) || defined(__INTEL_COMPILER))
+#if !defined(yaSSL_NEW_HPP) && defined(__GNUC__) && !defined(__ICC)
 
 #define yaSSL_NEW_HPP
 
 #if __GNUC__ > 2
 
 extern "C" {
-#include 
+#if !defined(DO_TAOCRYPT_KERNEL_MODE)
+    #include 
+#else
+    #include "kernelc.hpp"
+#endif
 
 /* Disallow inline __cxa_pure_virtual() */
 static int __cxa_pure_virtual() __attribute__((noinline, used));
@@ -47,6 +50,5 @@ static int __cxa_pure_virtual()
 } // extern "C"
 
 #endif // __GNUC__ > 2
-#endif // ! _ICC
 #endif // yaSSL_NEW_HPP && __GNUC__
 
diff --git a/extra/yassl/taocrypt/include/sha.hpp b/extra/yassl/taocrypt/include/sha.hpp
index b75d9e3f670..3e301a6f0ae 100644
--- a/extra/yassl/taocrypt/include/sha.hpp
+++ b/extra/yassl/taocrypt/include/sha.hpp
@@ -42,6 +42,7 @@ public:
     word32    getDigestSize() const { return DIGEST_SIZE; }
     word32    getPadSize()    const { return PAD_SIZE; }
 
+    void Update(const byte* data, word32 len);
     void Init();
 
     SHA(const SHA&);
@@ -50,6 +51,7 @@ public:
     void Swap(SHA&);
 private:
     void Transform();
+    void AsmTransform(const byte* data, word32 times);
 };
 
 
diff --git a/extra/yassl/taocrypt/include/twofish.hpp b/extra/yassl/taocrypt/include/twofish.hpp
new file mode 100644
index 00000000000..8605221854f
--- /dev/null
+++ b/extra/yassl/taocrypt/include/twofish.hpp
@@ -0,0 +1,86 @@
+/* twofish.hpp                                
+ *
+ * Copyright (C) 2003 Sawtooth Consulting Ltd.
+ *
+ * This file is part of yaSSL.
+ *
+ * yaSSL 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; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * yaSSL 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ */
+
+/* twofish.hpp defines Twofish
+*/
+
+
+#ifndef TAO_CRYPT_TWOFISH_HPP
+#define TAO_CRYPT_TWOFISH_HPP
+
+#include "misc.hpp"
+#include "modes.hpp"
+#include "algorithm.hpp"
+
+namespace TaoCrypt {
+
+enum { TWOFISH_BLOCK_SIZE = 16 };
+
+
+// Twofish encryption and decryption, see 
+class Twofish : public Mode_BASE {
+public:
+    enum { BLOCK_SIZE = TWOFISH_BLOCK_SIZE };
+
+    Twofish(CipherDir DIR, Mode MODE)
+        : Mode_BASE(BLOCK_SIZE), dir_(DIR), mode_(MODE) {}
+
+    void Process(byte*, const byte*, word32);
+    void SetKey(const byte* key, word32 sz, CipherDir fake = ENCRYPTION);
+    void SetIV(const byte* iv) { memcpy(r_, iv, BLOCK_SIZE); }
+private:
+    CipherDir dir_;
+    Mode      mode_;
+
+	static const byte     q_[2][256];
+	static const word32 mds_[4][256];
+
+	word32 k_[40];
+	word32 s_[4][256];
+
+	static word32 h0(word32 x, const word32 *key, unsigned int kLen);
+	static word32 h(word32 x, const word32 *key, unsigned int kLen);
+
+    void ProcessAndXorBlock(const byte*, const byte*, byte*) const;
+
+    void encrypt(const byte*, const byte*, byte*) const;
+    void decrypt(const byte*, const byte*, byte*) const;
+
+    void AsmEncrypt(const byte* inBlock, byte* outBlock) const;
+    void AsmDecrypt(const byte* inBlock, byte* outBlock) const;
+
+    Twofish(const Twofish&);            // hide copy
+    Twofish& operator=(const Twofish&); // and assign
+};
+
+
+typedef BlockCipher Twofish_ECB_Encryption;
+typedef BlockCipher Twofish_ECB_Decryption;
+
+typedef BlockCipher Twofish_CBC_Encryption;
+typedef BlockCipher Twofish_CBC_Decryption;
+
+
+
+} // naemspace
+
+#endif // TAO_CRYPT_TWOFISH_HPP
+
diff --git a/extra/yassl/taocrypt/include/types.hpp b/extra/yassl/taocrypt/include/types.hpp
index db9c3792bbd..92164eaaab4 100644
--- a/extra/yassl/taocrypt/include/types.hpp
+++ b/extra/yassl/taocrypt/include/types.hpp
@@ -61,10 +61,9 @@ typedef unsigned int   word32;
 
 // compilers we've found 64-bit multiply insructions for
 #if defined(__GNUC__) || defined(_MSC_VER) || defined(__DECCXX)
-#if !(defined(__ICC) || defined(__INTEL_COMPILER))
     #define HAVE_64_MULTIPLY
 #endif
-#endif
+
     
 #if defined(HAVE_64_MULTIPLY) && (defined(__alpha__) || defined(__ia64__) \
     || defined(_ARCH_PPC64) || defined(__mips64)  || defined(__x86_64__)) 
diff --git a/extra/yassl/taocrypt/src/aes.cpp b/extra/yassl/taocrypt/src/aes.cpp
index 09cf28a40b0..e737af33df3 100644
--- a/extra/yassl/taocrypt/src/aes.cpp
+++ b/extra/yassl/taocrypt/src/aes.cpp
@@ -19,15 +19,28 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
  */
 
-/* based on Wei Dai's aes.cpp from CryptoPP */
+/* C++ based on Wei Dai's aes.cpp from CryptoPP */
+/* x86 asm original */
+
+#if defined(TAOCRYPT_KERNEL_MODE)
+    #define DO_TAOCRYPT_KERNEL_MODE
+#endif                                  // only some modules now support this
 
 #include "runtime.hpp"
 #include "aes.hpp"
 
 
+#if defined(TAOCRYPT_X86ASM_AVAILABLE) && defined(TAO_ASM)
+    #define DO_AES_ASM
+#endif
+
+
 namespace TaoCrypt {
 
 
+#if !defined(DO_AES_ASM)
+
+// Generic Version
 void AES::Process(byte* out, const byte* in, word32 sz)
 {
     if (mode_ == ECB)
@@ -39,6 +52,52 @@ void AES::Process(byte* out, const byte* in, word32 sz)
             CBC_Decrypt(out, in, sz);
 }
 
+#else
+
+// ia32 optimized version
+void AES::Process(byte* out, const byte* in, word32 sz)
+{
+    word32 blocks = sz / BLOCK_SIZE;
+
+    if (mode_ == ECB)
+        while (blocks--) {
+            if (dir_ == ENCRYPTION)
+                AsmEncrypt(in, out, (void*)Te0);
+            else
+                AsmDecrypt(in, out, (void*)Td0);               
+            out += BLOCK_SIZE;
+            in  += BLOCK_SIZE;
+        }
+    else if (mode_ == CBC)    
+        if (dir_ == ENCRYPTION)
+            while (blocks--) {
+                r_[0] ^= *(word32*)in;
+                r_[1] ^= *(word32*)(in +  4);
+                r_[2] ^= *(word32*)(in +  8);
+                r_[3] ^= *(word32*)(in + 12);
+
+                AsmEncrypt((byte*)r_, (byte*)r_, (void*)Te0);
+
+                memcpy(out, r_, BLOCK_SIZE);
+                out += BLOCK_SIZE;
+                in  += BLOCK_SIZE;
+            }
+        else
+            while (blocks--) {
+                AsmDecrypt(in, out, (void*)Td0);
+                
+                *(word32*)out        ^= r_[0];
+                *(word32*)(out +  4) ^= r_[1];
+                *(word32*)(out +  8) ^= r_[2];
+                *(word32*)(out + 12) ^= r_[3];
+
+                memcpy(r_, in, BLOCK_SIZE);
+                out += BLOCK_SIZE;
+                in  += BLOCK_SIZE;
+            }
+}
+
+#endif // DO_AES_ASM
 
 
 void AES::SetKey(const byte* userKey, word32 keylen, CipherDir /*dummy*/)
@@ -46,9 +105,8 @@ void AES::SetKey(const byte* userKey, word32 keylen, CipherDir /*dummy*/)
     assert( (keylen == 16) || (keylen == 24) || (keylen == 32) );
 
     rounds_ = keylen/4 + 6;
-    key_.New(4*(rounds_+1));
 
-    word32 temp, *rk = key_.get_buffer();
+    word32 temp, *rk = key_;
     unsigned int i=0;
 
     GetUserKey(BigEndianOrder, rk, keylen/4, userKey, keylen);
@@ -128,7 +186,7 @@ void AES::SetKey(const byte* userKey, word32 keylen, CipherDir /*dummy*/)
     if (dir_ == DECRYPTION)
     {
         unsigned int i, j;
-        rk = key_.get_buffer();
+        rk = key_;
 
         /* invert the order of the round keys: */
         for (i = 0, j = 4*rounds_; i < j; i += 4, j -= 4) {
@@ -166,8 +224,6 @@ void AES::SetKey(const byte* userKey, word32 keylen, CipherDir /*dummy*/)
 }
 
 
-typedef BlockGetAndPut gpBlock;
-
 void AES::ProcessAndXorBlock(const byte* in, const byte* xOr, byte* out) const
 {
     if (dir_ == ENCRYPTION)
@@ -177,12 +233,16 @@ void AES::ProcessAndXorBlock(const byte* in, const byte* xOr, byte* out) const
 }
 
 
+typedef BlockGetAndPut gpBlock;
+
+	
 void AES::encrypt(const byte* inBlock, const byte* xorBlock,
                   byte* outBlock) const
 {
-    word32 s0, s1, s2, s3, t0, t1, t2, t3;
-    const word32 *rk = key_.get_buffer();
+    word32 s0, s1, s2, s3;
+    word32 t0, t1, t2, t3;
 
+    const word32 *rk = key_;
     /*
      * map byte array block to cipher state
      * and add initial round key:
@@ -192,9 +252,11 @@ void AES::encrypt(const byte* inBlock, const byte* xorBlock,
     s1 ^= rk[1];
     s2 ^= rk[2];
     s3 ^= rk[3];
+   
     /*
      * Nr - 1 full rounds:
      */
+
     unsigned int r = rounds_ >> 1;
     for (;;) {
         t0 =
@@ -252,6 +314,7 @@ void AES::encrypt(const byte* inBlock, const byte* xorBlock,
             Te3[GETBYTE(t2, 0)] ^
             rk[3];
     }
+
     /*
      * apply last round and
      * map cipher state to byte array block:
@@ -282,16 +345,17 @@ void AES::encrypt(const byte* inBlock, const byte* xorBlock,
         (Te4[GETBYTE(t2, 0)] & 0x000000ff) ^
         rk[3];
 
-    gpBlock::Put(xorBlock, outBlock)(s0)(s1)(s2)(s3);
 
+    gpBlock::Put(xorBlock, outBlock)(s0)(s1)(s2)(s3);
 }
 
 
 void AES::decrypt(const byte* inBlock, const byte* xorBlock,
                   byte* outBlock) const
 {
-    word32 s0, s1, s2, s3, t0, t1, t2, t3;
-    const word32* rk = key_.get_buffer();
+    word32 s0, s1, s2, s3;
+    word32 t0, t1, t2, t3;
+    const word32* rk = key_;
 
     /*
      * map byte array block to cipher state
@@ -302,9 +366,11 @@ void AES::decrypt(const byte* inBlock, const byte* xorBlock,
     s1 ^= rk[1];
     s2 ^= rk[2];
     s3 ^= rk[3];
+
     /*
      * Nr - 1 full rounds:
      */
+
     unsigned int r = rounds_ >> 1;
     for (;;) {
         t0 =
@@ -395,6 +461,1371 @@ void AES::decrypt(const byte* inBlock, const byte* xorBlock,
 }
 
 
+#if defined(DO_AES_ASM)
+    #ifdef __GNUC__
+        #define AS1(x)    asm(#x);
+        #define AS2(x, y) asm(#x ", " #y);
+
+        #define PROLOG()  \
+            asm(".intel_syntax noprefix"); \
+            AS2(    movd  mm3, edi                      )   \
+            AS2(    movd  mm4, ebx                      )   \
+            AS2(    sub   esp, 4                        )   \
+            AS2(    movd  mm7, ebp                      )   \
+            AS2(    mov   [ebp - 4], esi                )   \
+            AS2(    mov   ecx, DWORD PTR [ebp +  8]     )   \
+            AS2(    mov   esi, DWORD PTR [ebp + 12]     )   \
+            AS2(    mov   ebp, DWORD PTR [ebp + 20]     )
+
+        #define EPILOG()  \
+            AS2(    mov  esi, [ebp - 4]             )   \
+            AS2(    mov  esp, ebp                   )   \
+            AS2(    movd ebx, mm4                   )   \
+            AS2(    movd edi, mm3                   )   \
+            AS1(    emms                            )   \
+            asm(".att_syntax");
+    #else
+        #define AS1(x)    __asm x
+        #define AS2(x, y) __asm x, y
+
+        #define PROLOG() \
+            AS1(    push  ebp                           )   \
+            AS2(    mov   ebp, esp                      )   \
+            AS2(    movd  mm3, edi                      )   \
+            AS2(    movd  mm4, ebx                      )   \
+            AS2(    sub   esp, 4                        )   \
+            AS2(    movd  mm7, ebp                      )   \
+            AS2(    mov   [ebp - 4], esi                )   \
+            AS2(    mov   esi, DWORD PTR [ebp +  8]     )   \
+            AS2(    mov   ebp, DWORD PTR [ebp + 16]     )
+
+        // ebp is restored at end
+        #define EPILOG()  \
+            AS2(    mov   esi, [ebp - 4]                )   \
+            AS2(    movd  ebx, mm4                      )   \
+            AS2(    movd  edi, mm3                      )   \
+            AS2(    mov   esp, ebp                      )   \
+            AS1(    pop   ebp                           )   \
+            AS1(    emms                                )   \
+            AS1(    ret   12                            )
+            
+            
+    #endif
+
+
+#ifdef _MSC_VER
+    __declspec(naked) 
+#endif
+void AES::AsmEncrypt(const byte* inBlock, byte* outBlock, void* boxes) const
+{
+
+    PROLOG()
+
+    #ifdef OLD_GCC_OFFSET
+        AS2(    mov   edx, DWORD PTR [ecx + 60]     )   // rounds
+        AS2(    lea   edi, [ecx + 64]               )   // rk
+    #else
+        AS2(    mov   edx, DWORD PTR [ecx + 56]     )   // rounds
+        AS2(    lea   edi, [ecx + 60]               )   // rk
+    #endif
+
+    AS1(    dec   edx                           )
+    AS2(    movd  mm6, edi                      )   // save rk
+    AS2(    movd  mm5, edx                      )   // save rounds
+  
+    AS2(    mov   eax, DWORD PTR [esi]                                  )
+    AS2(    mov   ebx, DWORD PTR [esi + 4]                              )
+    AS2(    mov   ecx, DWORD PTR [esi + 8]                              )
+    AS2(    mov   edx, DWORD PTR [esi + 12]                             )
+
+    AS1(    bswap eax                                                   )
+    AS1(    bswap ebx                                                   )
+    AS1(    bswap ecx                                                   )
+    AS1(    bswap edx                                                   )
+
+    AS2(    xor   eax, DWORD PTR [edi]               )   // s0
+    AS2(    xor   ebx, DWORD PTR [edi +  4]          )   // s1
+    AS2(    xor   ecx, DWORD PTR [edi +  8]          )   // s2
+    AS2(    xor   edx, DWORD PTR [edi + 12]          )   // s3
+
+    AS1(loop1:                                                          )
+            /* Put0 (mm0) =  
+                Te0[get0,rs 24] ^
+                Te1[get1,rs 16] ^
+                Te2[get2,rs  8] ^
+                Te3[get3,rs  0]
+            */
+       
+    AS2(    mov   esi, eax                                              )
+    AS2(    shr   esi, 24                                               )
+    AS2(    mov   esi, DWORD PTR [ebp + esi*4]                          )
+                                                    
+    AS2(    mov   edi, ebx                                              )
+    AS2(    shr   edi, 16                                               )
+    AS2(    and   edi, 255                                              )
+    AS2(    xor   esi, DWORD PTR [ebp + 1024 + edi*4]                   )
+
+    AS2(    movzx edi, ch                                               )
+    AS2(    xor   esi, DWORD PTR [ebp + 2048 + edi*4]                   )
+
+    AS2(    movzx edi, dl                                               )
+    AS2(    xor   esi, DWORD PTR [ebp + 3072 + edi*4]                   )
+
+    AS2(    movd  mm0, esi                                              )
+
+             /* Put1 (mm1) =  
+                Te0[get1,rs 24] ^
+                Te1[get2,rs 16] ^
+                Te2[get3,rs  8] ^
+                Te3[get0,rs  0]
+            */
+
+    AS2(    mov   esi, ebx                                              )
+    AS2(    shr   esi, 24                                               )
+    AS2(    mov   esi, DWORD PTR [ebp + esi*4]                          )
+
+    AS2(    mov   edi, ecx                                              )
+    AS2(    shr   edi, 16                                               )
+    AS2(    and   edi, 255                                              )
+    AS2(    xor   esi, DWORD PTR [ebp + 1024 + edi*4]                   )
+
+    AS2(    movzx edi, dh                                               )
+    AS2(    xor   esi, DWORD PTR [ebp + 2048 + edi*4]                   )
+
+    AS2(    movzx edi, al                                               )
+    AS2(    xor   esi, DWORD PTR [ebp + 3072 + edi*4]                   )
+
+    AS2(    movd  mm1, esi                                              )
+
+
+             /* Put2 (mm2) =  
+                Te0[get2,rs 24] ^
+                Te1[get3,rs 16] ^
+                Te2[get0,rs  8] ^
+                Te3[get1,rs  0] 
+            */
+
+    AS2(    mov   esi, ecx                                              )
+    AS2(    shr   esi, 24                                               )
+    AS2(    mov   esi, DWORD PTR [ebp + esi*4]                          )
+
+    AS2(    mov   edi, edx                                              )
+    AS2(    shr   edi, 16                                               )
+    AS2(    and   edi, 255                                              )
+    AS2(    xor   esi, DWORD PTR [ebp + 1024 + edi*4]                   )
+
+    AS2(    movzx edi, ah                                               )
+    AS2(    xor   esi, DWORD PTR [ebp + 2048 + edi*4]                   )
+
+    AS2(    movzx edi, bl                                               )
+    AS2(    xor   esi, DWORD PTR [ebp + 3072 + edi*4]                   )
+
+    AS2(    movd  mm2, esi                                              )
+
+             /* Put3 (edx) =  
+                Te0[get3,rs 24] ^
+                Te1[get0,rs 16] ^
+                Te2[get1,rs  8] ^
+                Te3[get2,rs  0] 
+            */
+
+    AS2(    mov   esi, edx                                              )
+    AS2(    shr   esi, 24                                               )
+    AS2(    mov   edx, DWORD PTR [ebp + esi*4]                          )
+
+    AS2(    mov   edi, eax                                              )
+    AS2(    shr   edi, 16                                               )
+    AS2(    and   edi, 255                                              )
+    AS2(    xor   edx, DWORD PTR [ebp + 1024 + edi*4]                   )
+
+    AS2(    movzx esi, bh                                               )
+    AS2(    xor   edx, DWORD PTR [ebp + 2048 + esi*4]                   )
+
+    AS2(    movzx edi, cl                                               )
+    AS2(    xor   edx, DWORD PTR [ebp + 3072 + edi*4]                   )
+
+            // xOr
+
+    AS2(    movd   esi, mm6                      )   //  rk
+
+    AS2(    movd   eax, mm0                                             )
+    AS2(    add    esi, 16                                              )
+    AS2(    movd   ebx, mm1                                             )
+    AS2(    movd   mm6, esi                      )   //  save back
+    AS2(    movd   ecx, mm2                                             )
+
+    AS2(    xor   eax, DWORD PTR [esi]                                  )
+    AS2(    xor   ebx, DWORD PTR [esi +  4]                             )
+    AS2(    movd  edi, mm5                                              )
+    AS2(    xor   ecx, DWORD PTR [esi +  8]                             )
+    AS2(    xor   edx, DWORD PTR [esi + 12]                             )
+
+    AS1(    dec   edi                                                   )
+    AS2(    movd  mm5, edi                                              )
+
+    AS1(    jnz   loop1                                                 )
+
+            // last round
+            /*
+            Put0 (mm0) =
+                (Te4[get0, rs24] & 0xff000000) ^  h = 4278190080
+                (Te4[get1, rs16] & 0x00ff0000) ^  h =   16711680
+                (Te4[get2, rs 8] & 0x0000ff00) ^  h =      65280
+                (Te4[get3, rs 0] & 0x000000ff)    h =        255
+            */
+    AS2(    mov   esi, eax                                              )
+    AS2(    shr   esi, 24                                               )
+    AS2(    mov   esi, DWORD PTR [ebp + 4096 + esi*4]                   )
+    AS2(    and   esi, 4278190080                                       )
+
+    AS2(    mov   edi, ebx                                              )
+    AS2(    shr   edi, 16                                               )
+    AS2(    and   edi, 255                                              )
+    AS2(    mov   edi, DWORD PTR [ebp + 4096 + edi*4]                   )
+    AS2(    and   edi, 16711680                                         )
+    AS2(    xor   esi, edi                                              )
+
+    AS2(    movzx edi, ch                                               )
+    AS2(    mov   edi, DWORD PTR [ebp + 4096 + edi*4]                   )
+    AS2(    and   edi, 65280                                            )
+    AS2(    xor   esi, edi                                              )
+
+    AS2(    movzx edi, dl                                               )
+    AS2(    mov   edi, DWORD PTR [ebp + 4096 + edi*4]                   )
+    AS2(    and   edi, 255                                              )
+    AS2(    xor   esi, edi                                              )
+
+    AS2(    movd  mm0, esi                                              )
+
+            /*
+            Put1 (mm1) =
+                (Te4[get1, rs24] & 0xff000000) ^  h = 4278190080
+                (Te4[get2, rs16] & 0x00ff0000) ^  h =   16711680
+                (Te4[get3, rs 8] & 0x0000ff00) ^  h =      65280
+                (Te4[get0, rs 0] & 0x000000ff)    h =        255
+            */
+    AS2(    mov   esi, ebx                                              )
+    AS2(    shr   esi, 24                                               )
+    AS2(    mov   esi, DWORD PTR [ebp + 4096 + esi*4]                   )
+    AS2(    and   esi, 4278190080                                       )
+
+    AS2(    mov   edi, ecx                                              )
+    AS2(    shr   edi, 16                                               )
+    AS2(    and   edi, 255                                              )
+    AS2(    mov   edi, DWORD PTR [ebp + 4096 + edi*4]                   )
+    AS2(    and   edi, 16711680                                         )
+    AS2(    xor   esi, edi                                              )
+
+    AS2(    movzx edi, dh                                               )
+    AS2(    mov   edi, DWORD PTR [ebp + 4096 + edi*4]                   )
+    AS2(    and   edi, 65280                                            )
+    AS2(    xor   esi, edi                                              )
+
+    AS2(    movzx edi, al                                               )
+    AS2(    mov   edi, DWORD PTR [ebp + 4096 + edi*4]                   )
+    AS2(    and   edi, 255                                              )
+    AS2(    xor   esi, edi                                              )
+
+    AS2(    movd  mm1, esi                                              )
+
+            /*
+            Put2 (mm2) =
+                (Te4[get2, rs24] & 0xff000000) ^  h = 4278190080
+                (Te4[get3, rs16] & 0x00ff0000) ^  h =   16711680
+                (Te4[get0, rs 8] & 0x0000ff00) ^  h =      65280
+                (Te4[get1, rs 0] & 0x000000ff)    h =        255
+            */
+    AS2(    mov   esi, ecx                                              )
+    AS2(    shr   esi, 24                                               )
+    AS2(    mov   esi, DWORD PTR [ebp + 4096 + esi*4]                   )
+    AS2(    and   esi, 4278190080                                       )
+
+    AS2(    mov   edi, edx                                              )
+    AS2(    shr   edi, 16                                               )
+    AS2(    and   edi, 255                                              )
+    AS2(    mov   edi, DWORD PTR [ebp + 4096 + edi*4]                   )
+    AS2(    and   edi, 16711680                                         )
+    AS2(    xor   esi, edi                                              )
+
+    AS2(    movzx edi, ah                                               )
+    AS2(    mov   edi, DWORD PTR [ebp + 4096 + edi*4]                   )
+    AS2(    and   edi, 65280                                            )
+    AS2(    xor   esi, edi                                              )
+
+    AS2(    movzx edi, bl                                               )
+    AS2(    mov   edi, DWORD PTR [ebp + 4096 + edi*4]                   )
+    AS2(    and   edi, 255                                              )
+    AS2(    xor   esi, edi                                              )
+
+    AS2(    movd  mm2, esi                                              )
+
+            /*
+            Put3 (edx) =
+                (Te4[get3, rs24] & 0xff000000) ^  h = 4278190080
+                (Te4[get0, rs16] & 0x00ff0000) ^  h =   16711680
+                (Te4[get1, rs 8] & 0x0000ff00) ^  h =      65280
+                (Te4[get2, rs 0] & 0x000000ff)    h =        255
+            */
+    AS2(    mov   esi, edx                                              )
+    AS2(    shr   esi, 24                                               )
+    AS2(    mov   edx, DWORD PTR [ebp + 4096 + esi*4]                   )
+    AS2(    and   edx, 4278190080                                       )
+
+    AS2(    mov   edi, eax                                              )
+    AS2(    shr   edi, 16                                               )
+    AS2(    and   edi, 255                                              )
+    AS2(    mov   esi, DWORD PTR [ebp + 4096 + edi*4]                   )
+    AS2(    and   esi, 16711680                                         )
+    AS2(    xor   edx, esi                                              )
+
+    AS2(    movzx esi, bh                                               )
+    AS2(    mov   edi, DWORD PTR [ebp + 4096 + esi*4]                   )
+    AS2(    and   edi, 65280                                            )
+    AS2(    xor   edx, edi                                              )
+
+    AS2(    movzx edi, cl                                               )
+    AS2(    mov   esi, DWORD PTR [ebp + 4096 + edi*4]                   )
+    AS2(    and   esi, 255                                              )
+    AS2(    xor   edx, esi                                              )
+
+    
+            // xOr
+    AS2(    movd   eax, mm0                                             )
+    AS2(    movd   esi, mm6                      )   //  rk
+    AS2(    movd   ebx, mm1                                             )
+    AS2(    add    esi, 16                                               )
+    AS2(    movd   ecx, mm2                                             )
+
+    AS2(    xor   eax, DWORD PTR [esi]                                  )
+    AS2(    xor   ebx, DWORD PTR [esi +  4]                             )
+    AS2(    xor   ecx, DWORD PTR [esi +  8]                             )
+    AS2(    xor   edx, DWORD PTR [esi + 12]                             )
+
+    // end
+    AS2(    movd  ebp, mm7                                              )
+
+            // swap
+    AS1(    bswap eax                                                   )
+    AS1(    bswap ebx                                                   )
+
+            // store
+    #ifdef __GNUC__
+        AS2(    mov esi, DWORD PTR [ebp + 16]       )   //  outBlock
+    #else
+        AS2(    mov esi, DWORD PTR [ebp + 12]       )   //  outBlock
+    #endif
+
+    AS1(    bswap ecx                                                   )
+    AS1(    bswap edx                                                   )
+
+    AS2(    mov DWORD PTR [esi],      eax                               )
+    AS2(    mov DWORD PTR [esi +  4], ebx                               )
+    AS2(    mov DWORD PTR [esi +  8], ecx                               )
+    AS2(    mov DWORD PTR [esi + 12], edx                               )
+
+
+    EPILOG()
+}
+
+
+#ifdef _MSC_VER
+    __declspec(naked) 
+#endif
+void AES::AsmDecrypt(const byte* inBlock, byte* outBlock, void* boxes) const
+{
+
+    PROLOG()
+
+    #ifdef OLD_GCC_OFFSET
+        AS2(    mov   edx, DWORD PTR [ecx + 60]     )   // rounds
+        AS2(    lea   edi, [ecx + 64]               )   // rk 
+    #else
+        AS2(    mov   edx, DWORD PTR [ecx + 56]     )   // rounds
+        AS2(    lea   edi, [ecx + 60]               )   // rk 
+    #endif
+   
+    AS1(    dec   edx                           )
+    AS2(    movd  mm6, edi                      )   // save rk
+    AS2(    movd  mm5, edx                      )   // save rounds
+
+    AS2(    mov   eax, DWORD PTR [esi]                                  )
+    AS2(    mov   ebx, DWORD PTR [esi + 4]                              )
+    AS2(    mov   ecx, DWORD PTR [esi + 8]                              )
+    AS2(    mov   edx, DWORD PTR [esi + 12]                             )
+
+    AS1(    bswap eax                                                   )
+    AS1(    bswap ebx                                                   )
+    AS1(    bswap ecx                                                   )
+    AS1(    bswap edx                                                   )
+
+    AS2(    xor   eax, DWORD PTR [edi]               )   // s0
+    AS2(    xor   ebx, DWORD PTR [edi +  4]          )   // s1
+    AS2(    xor   ecx, DWORD PTR [edi +  8]          )   // s2
+    AS2(    xor   edx, DWORD PTR [edi + 12]          )   // s3
+
+
+    AS1(loop2:                                                          )
+       /*   Put0 (mm0) =
+            Td0[GETBYTE(get0, rs24)] ^
+            Td1[GETBYTE(get3, rs16)] ^
+            Td2[GETBYTE(get2, rs 8)] ^
+            Td3[GETBYTE(tet1,     )]  
+        */
+    AS2(    mov   esi, eax                                              )
+    AS2(    shr   esi, 24                                               )
+    AS2(    mov   esi, DWORD PTR [ebp + esi*4]                          )
+                                                    
+    AS2(    mov   edi, edx                                              )
+    AS2(    shr   edi, 16                                               )
+    AS2(    and   edi, 255                                              )
+    AS2(    xor   esi, DWORD PTR [ebp + 1024 + edi*4]                   )
+
+    AS2(    movzx edi, ch                                               )
+    AS2(    xor   esi, DWORD PTR [ebp + 2048 + edi*4]                   )
+
+    AS2(    movzx edi, bl                                               )
+    AS2(    xor   esi, DWORD PTR [ebp + 3072 + edi*4]                   )
+
+    AS2(    movd  mm0, esi                                              )
+
+      /*    Put1 (mm1) =
+            Td0[GETBYTE(get1, rs24)] ^
+            Td1[GETBYTE(get0, rs16)] ^
+            Td2[GETBYTE(get3, rs 8)] ^
+            Td3[GETBYTE(tet2,     )]  
+        */
+    AS2(    mov   esi, ebx                                              )
+    AS2(    shr   esi, 24                                               )
+    AS2(    mov   esi, DWORD PTR [ebp + esi*4]                          )
+                                                    
+    AS2(    mov   edi, eax                                              )
+    AS2(    shr   edi, 16                                               )
+    AS2(    and   edi, 255                                              )
+    AS2(    xor   esi, DWORD PTR [ebp + 1024 + edi*4]                   )
+
+    AS2(    movzx edi, dh                                               )
+    AS2(    xor   esi, DWORD PTR [ebp + 2048 + edi*4]                   )
+
+    AS2(    movzx edi, cl                                               )
+    AS2(    xor   esi, DWORD PTR [ebp + 3072 + edi*4]                   )
+
+    AS2(    movd  mm1, esi                                              )
+
+      /*    Put2 (mm2) =
+            Td0[GETBYTE(get2, rs24)] ^
+            Td1[GETBYTE(get1, rs16)] ^
+            Td2[GETBYTE(get0, rs 8)] ^
+            Td3[GETBYTE(tet3,     )]  
+      */
+    AS2(    mov   esi, ecx                                              )
+    AS2(    shr   esi, 24                                               )
+    AS2(    mov   esi, DWORD PTR [ebp + esi*4]                          )
+                                                    
+    AS2(    mov   edi, ebx                                              )
+    AS2(    shr   edi, 16                                               )
+    AS2(    and   edi, 255                                              )
+    AS2(    xor   esi, DWORD PTR [ebp + 1024 + edi*4]                   )
+
+    AS2(    movzx edi, ah                                               )
+    AS2(    xor   esi, DWORD PTR [ebp + 2048 + edi*4]                   )
+
+    AS2(    movzx edi, dl                                               )
+    AS2(    xor   esi, DWORD PTR [ebp + 3072 + edi*4]                   )
+
+    AS2(    movd  mm2, esi                                              )
+
+      /*    Put3 (edx) =
+            Td0[GETBYTE(get3, rs24)] ^
+            Td1[GETBYTE(get2, rs16)] ^
+            Td2[GETBYTE(get1, rs 8)] ^
+            Td3[GETBYTE(tet0,     )]  
+      */
+    AS2(    mov   esi, edx                                              )
+    AS2(    shr   esi, 24                                               )
+    AS2(    mov   edx, DWORD PTR [ebp + esi*4]                          )
+                                                    
+    AS2(    mov   edi, ecx                                              )
+    AS2(    shr   edi, 16                                               )
+    AS2(    and   edi, 255                                              )
+    AS2(    xor   edx, DWORD PTR [ebp + 1024 + edi*4]                   )
+
+    AS2(    movzx esi, bh                                               )
+    AS2(    xor   edx, DWORD PTR [ebp + 2048 + esi*4]                   )
+
+    AS2(    movzx edi, al                                               )
+    AS2(    xor   edx, DWORD PTR [ebp + 3072 + edi*4]                   )
+
+
+            // xOr
+
+    AS2(    movd  esi, mm6                      )   //  rk
+    AS2(    add   esi, 16                                               )
+    AS2(    movd  mm6, esi                      )   //  save back
+
+    AS2(    movd  eax, mm0                                              )
+    AS2(    movd  ebx, mm1                                              )
+    AS2(    movd  ecx, mm2                                              )
+
+    AS2(    xor   eax, DWORD PTR [esi]                                  )
+    AS2(    xor   ebx, DWORD PTR [esi +  4]                             )
+    AS2(    xor   ecx, DWORD PTR [esi +  8]                             )
+    AS2(    xor   edx, DWORD PTR [esi + 12]                             )
+
+    AS2(    movd  edi, mm5                                              )
+    AS1(    dec   edi                                                   )
+    AS2(    movd  mm5, edi                                              )
+
+    AS1(    jnz   loop2                                                 )
+
+            // last round
+            /*
+            Put0 (mm0) =
+                (Td4[get0, rs24] & 0xff000000) ^  h = 4278190080
+                (Td4[get3, rs16] & 0x00ff0000) ^  h =   16711680
+                (Td4[get2, rs 8] & 0x0000ff00) ^  h =      65280
+                (Td4[get1, rs 0] & 0x000000ff)    h =        255
+            */
+    AS2(    mov   esi, eax                                              )
+    AS2(    shr   esi, 24                                               )
+    AS2(    mov   esi, DWORD PTR [ebp + 4096 + esi*4]                   )
+    AS2(    and   esi, 4278190080                                       )
+
+    AS2(    mov   edi, edx                                              )
+    AS2(    shr   edi, 16                                               )
+    AS2(    and   edi, 255                                              )
+    AS2(    mov   edi, DWORD PTR [ebp + 4096 + edi*4]                   )
+    AS2(    and   edi, 16711680                                         )
+    AS2(    xor   esi, edi                                              )
+
+    AS2(    movzx edi, ch                                               )
+    AS2(    mov   edi, DWORD PTR [ebp + 4096 + edi*4]                   )
+    AS2(    and   edi, 65280                                            )
+    AS2(    xor   esi, edi                                              )
+
+    AS2(    movzx edi, bl                                               )
+    AS2(    mov   edi, DWORD PTR [ebp + 4096 + edi*4]                   )
+    AS2(    and   edi, 255                                              )
+    AS2(    xor   esi, edi                                              )
+
+    AS2(    movd  mm0, esi                                              )
+
+            /*
+            Put1 (mm1) =
+                (Td4[get1, rs24] & 0xff000000) ^  h = 4278190080
+                (Td4[get0, rs16] & 0x00ff0000) ^  h =   16711680
+                (Td4[get3, rs 8] & 0x0000ff00) ^  h =      65280
+                (Td4[get2, rs 0] & 0x000000ff)    h =        255
+            */
+    AS2(    mov   esi, ebx                                              )
+    AS2(    shr   esi, 24                                               )
+    AS2(    mov   esi, DWORD PTR [ebp + 4096 + esi*4]                   )
+    AS2(    and   esi, 4278190080                                       )
+
+    AS2(    mov   edi, eax                                              )
+    AS2(    shr   edi, 16                                               )
+    AS2(    and   edi, 255                                              )
+    AS2(    mov   edi, DWORD PTR [ebp + 4096 + edi*4]                   )
+    AS2(    and   edi, 16711680                                         )
+    AS2(    xor   esi, edi                                              )
+
+    AS2(    movzx edi, dh                                               )
+    AS2(    mov   edi, DWORD PTR [ebp + 4096 + edi*4]                   )
+    AS2(    and   edi, 65280                                            )
+    AS2(    xor   esi, edi                                              )
+
+    AS2(    movzx edi, cl                                               )
+    AS2(    mov   edi, DWORD PTR [ebp + 4096 + edi*4]                   )
+    AS2(    and   edi, 255                                              )
+    AS2(    xor   esi, edi                                              )
+
+    AS2(    movd  mm1, esi                                              )
+
+            /*
+            Put2 (mm2) =
+                (Td4[get2, rs24] & 0xff000000) ^  h = 4278190080
+                (Td4[get1, rs16] & 0x00ff0000) ^  h =   16711680
+                (Td4[get0, rs 8] & 0x0000ff00) ^  h =      65280
+                (Td4[get3, rs 0] & 0x000000ff)    h =        255
+            */
+    AS2(    mov   esi, ecx                                              )
+    AS2(    shr   esi, 24                                               )
+    AS2(    mov   esi, DWORD PTR [ebp + 4096 + esi*4]                   )
+    AS2(    and   esi, 4278190080                                       )
+
+    AS2(    mov   edi, ebx                                              )
+    AS2(    shr   edi, 16                                               )
+    AS2(    and   edi, 255                                              )
+    AS2(    mov   edi, DWORD PTR [ebp + 4096 + edi*4]                   )
+    AS2(    and   edi, 16711680                                         )
+    AS2(    xor   esi, edi                                              )
+
+    AS2(    movzx edi, ah                                               )
+    AS2(    mov   edi, DWORD PTR [ebp + 4096 + edi*4]                   )
+    AS2(    and   edi, 65280                                            )
+    AS2(    xor   esi, edi                                              )
+
+    AS2(    movzx edi, dl                                               )
+    AS2(    mov   edi, DWORD PTR [ebp + 4096 + edi*4]                   )
+    AS2(    and   edi, 255                                              )
+    AS2(    xor   esi, edi                                              )
+
+    AS2(    movd  mm2, esi                                              )
+
+            /*
+            Put3 (edx) =
+                (Td4[get3, rs24] & 0xff000000) ^  h = 4278190080
+                (Td4[get2, rs16] & 0x00ff0000) ^  h =   16711680
+                (Td4[get1, rs 8] & 0x0000ff00) ^  h =      65280
+                (Td4[get0, rs 0] & 0x000000ff)    h =        255
+            */
+    AS2(    mov   esi, edx                                              )
+    AS2(    shr   esi, 24                                               )
+    AS2(    mov   edx, DWORD PTR [ebp + 4096 + esi*4]                   )
+    AS2(    and   edx, 4278190080                                       )
+
+    AS2(    mov   edi, ecx                                              )
+    AS2(    shr   edi, 16                                               )
+    AS2(    and   edi, 255                                              )
+    AS2(    mov   esi, DWORD PTR [ebp + 4096 + edi*4]                   )
+    AS2(    and   esi, 16711680                                         )
+    AS2(    xor   edx, esi                                              )
+
+    AS2(    movzx esi, bh                                               )
+    AS2(    mov   edi, DWORD PTR [ebp + 4096 + esi*4]                   )
+    AS2(    and   edi, 65280                                            )
+    AS2(    xor   edx, edi                                              )
+
+    AS2(    movzx edi, al                                               )
+    AS2(    mov   esi, DWORD PTR [ebp + 4096 + edi*4]                   )
+    AS2(    and   esi, 255                                              )
+    AS2(    xor   edx, esi                                              )
+
+
+            // xOr
+    AS2(    movd  esi, mm6                      )   //  rk
+    AS2(    add   esi, 16                                               )
+
+    AS2(    movd   eax, mm0                                             )
+    AS2(    movd   ebx, mm1                                             )
+    AS2(    movd   ecx, mm2                                             )
+
+    AS2(    xor   eax, DWORD PTR [esi]                                  )
+    AS2(    xor   ebx, DWORD PTR [esi +  4]                             )
+    AS2(    xor   ecx, DWORD PTR [esi +  8]                             )
+    AS2(    xor   edx, DWORD PTR [esi + 12]                             )
+
+    // end
+    AS2(    movd  ebp, mm7                                              )
+
+            // swap
+    AS1(    bswap eax                                                   )
+    AS1(    bswap ebx                                                   )
+    AS1(    bswap ecx                                                   )
+    AS1(    bswap edx                                                   )
+
+            // store
+    #ifdef __GNUC__
+        AS2(    mov esi, DWORD PTR [ebp + 16]       )   //  outBlock
+    #else
+        AS2(    mov esi, DWORD PTR [ebp + 12]       )   //  outBlock
+    #endif
+    AS2(    mov DWORD PTR [esi],      eax                               )
+    AS2(    mov DWORD PTR [esi +  4], ebx                               )
+    AS2(    mov DWORD PTR [esi +  8], ecx                               )
+    AS2(    mov DWORD PTR [esi + 12], edx                               )
+
+
+    EPILOG()
+}
+
+
+
+#endif // defined(DO_AES_ASM)
+
+
+
+const word32 AES::Te[5][256] = {
+{
+    0xc66363a5U, 0xf87c7c84U, 0xee777799U, 0xf67b7b8dU,
+    0xfff2f20dU, 0xd66b6bbdU, 0xde6f6fb1U, 0x91c5c554U,
+    0x60303050U, 0x02010103U, 0xce6767a9U, 0x562b2b7dU,
+    0xe7fefe19U, 0xb5d7d762U, 0x4dababe6U, 0xec76769aU,
+    0x8fcaca45U, 0x1f82829dU, 0x89c9c940U, 0xfa7d7d87U,
+    0xeffafa15U, 0xb25959ebU, 0x8e4747c9U, 0xfbf0f00bU,
+    0x41adadecU, 0xb3d4d467U, 0x5fa2a2fdU, 0x45afafeaU,
+    0x239c9cbfU, 0x53a4a4f7U, 0xe4727296U, 0x9bc0c05bU,
+    0x75b7b7c2U, 0xe1fdfd1cU, 0x3d9393aeU, 0x4c26266aU,
+    0x6c36365aU, 0x7e3f3f41U, 0xf5f7f702U, 0x83cccc4fU,
+    0x6834345cU, 0x51a5a5f4U, 0xd1e5e534U, 0xf9f1f108U,
+    0xe2717193U, 0xabd8d873U, 0x62313153U, 0x2a15153fU,
+    0x0804040cU, 0x95c7c752U, 0x46232365U, 0x9dc3c35eU,
+    0x30181828U, 0x379696a1U, 0x0a05050fU, 0x2f9a9ab5U,
+    0x0e070709U, 0x24121236U, 0x1b80809bU, 0xdfe2e23dU,
+    0xcdebeb26U, 0x4e272769U, 0x7fb2b2cdU, 0xea75759fU,
+    0x1209091bU, 0x1d83839eU, 0x582c2c74U, 0x341a1a2eU,
+    0x361b1b2dU, 0xdc6e6eb2U, 0xb45a5aeeU, 0x5ba0a0fbU,
+    0xa45252f6U, 0x763b3b4dU, 0xb7d6d661U, 0x7db3b3ceU,
+    0x5229297bU, 0xdde3e33eU, 0x5e2f2f71U, 0x13848497U,
+    0xa65353f5U, 0xb9d1d168U, 0x00000000U, 0xc1eded2cU,
+    0x40202060U, 0xe3fcfc1fU, 0x79b1b1c8U, 0xb65b5bedU,
+    0xd46a6abeU, 0x8dcbcb46U, 0x67bebed9U, 0x7239394bU,
+    0x944a4adeU, 0x984c4cd4U, 0xb05858e8U, 0x85cfcf4aU,
+    0xbbd0d06bU, 0xc5efef2aU, 0x4faaaae5U, 0xedfbfb16U,
+    0x864343c5U, 0x9a4d4dd7U, 0x66333355U, 0x11858594U,
+    0x8a4545cfU, 0xe9f9f910U, 0x04020206U, 0xfe7f7f81U,
+    0xa05050f0U, 0x783c3c44U, 0x259f9fbaU, 0x4ba8a8e3U,
+    0xa25151f3U, 0x5da3a3feU, 0x804040c0U, 0x058f8f8aU,
+    0x3f9292adU, 0x219d9dbcU, 0x70383848U, 0xf1f5f504U,
+    0x63bcbcdfU, 0x77b6b6c1U, 0xafdada75U, 0x42212163U,
+    0x20101030U, 0xe5ffff1aU, 0xfdf3f30eU, 0xbfd2d26dU,
+    0x81cdcd4cU, 0x180c0c14U, 0x26131335U, 0xc3ecec2fU,
+    0xbe5f5fe1U, 0x359797a2U, 0x884444ccU, 0x2e171739U,
+    0x93c4c457U, 0x55a7a7f2U, 0xfc7e7e82U, 0x7a3d3d47U,
+    0xc86464acU, 0xba5d5de7U, 0x3219192bU, 0xe6737395U,
+    0xc06060a0U, 0x19818198U, 0x9e4f4fd1U, 0xa3dcdc7fU,
+    0x44222266U, 0x542a2a7eU, 0x3b9090abU, 0x0b888883U,
+    0x8c4646caU, 0xc7eeee29U, 0x6bb8b8d3U, 0x2814143cU,
+    0xa7dede79U, 0xbc5e5ee2U, 0x160b0b1dU, 0xaddbdb76U,
+    0xdbe0e03bU, 0x64323256U, 0x743a3a4eU, 0x140a0a1eU,
+    0x924949dbU, 0x0c06060aU, 0x4824246cU, 0xb85c5ce4U,
+    0x9fc2c25dU, 0xbdd3d36eU, 0x43acacefU, 0xc46262a6U,
+    0x399191a8U, 0x319595a4U, 0xd3e4e437U, 0xf279798bU,
+    0xd5e7e732U, 0x8bc8c843U, 0x6e373759U, 0xda6d6db7U,
+    0x018d8d8cU, 0xb1d5d564U, 0x9c4e4ed2U, 0x49a9a9e0U,
+    0xd86c6cb4U, 0xac5656faU, 0xf3f4f407U, 0xcfeaea25U,
+    0xca6565afU, 0xf47a7a8eU, 0x47aeaee9U, 0x10080818U,
+    0x6fbabad5U, 0xf0787888U, 0x4a25256fU, 0x5c2e2e72U,
+    0x381c1c24U, 0x57a6a6f1U, 0x73b4b4c7U, 0x97c6c651U,
+    0xcbe8e823U, 0xa1dddd7cU, 0xe874749cU, 0x3e1f1f21U,
+    0x964b4bddU, 0x61bdbddcU, 0x0d8b8b86U, 0x0f8a8a85U,
+    0xe0707090U, 0x7c3e3e42U, 0x71b5b5c4U, 0xcc6666aaU,
+    0x904848d8U, 0x06030305U, 0xf7f6f601U, 0x1c0e0e12U,
+    0xc26161a3U, 0x6a35355fU, 0xae5757f9U, 0x69b9b9d0U,
+    0x17868691U, 0x99c1c158U, 0x3a1d1d27U, 0x279e9eb9U,
+    0xd9e1e138U, 0xebf8f813U, 0x2b9898b3U, 0x22111133U,
+    0xd26969bbU, 0xa9d9d970U, 0x078e8e89U, 0x339494a7U,
+    0x2d9b9bb6U, 0x3c1e1e22U, 0x15878792U, 0xc9e9e920U,
+    0x87cece49U, 0xaa5555ffU, 0x50282878U, 0xa5dfdf7aU,
+    0x038c8c8fU, 0x59a1a1f8U, 0x09898980U, 0x1a0d0d17U,
+    0x65bfbfdaU, 0xd7e6e631U, 0x844242c6U, 0xd06868b8U,
+    0x824141c3U, 0x299999b0U, 0x5a2d2d77U, 0x1e0f0f11U,
+    0x7bb0b0cbU, 0xa85454fcU, 0x6dbbbbd6U, 0x2c16163aU,
+},
+{
+    0xa5c66363U, 0x84f87c7cU, 0x99ee7777U, 0x8df67b7bU,
+    0x0dfff2f2U, 0xbdd66b6bU, 0xb1de6f6fU, 0x5491c5c5U,
+    0x50603030U, 0x03020101U, 0xa9ce6767U, 0x7d562b2bU,
+    0x19e7fefeU, 0x62b5d7d7U, 0xe64dababU, 0x9aec7676U,
+    0x458fcacaU, 0x9d1f8282U, 0x4089c9c9U, 0x87fa7d7dU,
+    0x15effafaU, 0xebb25959U, 0xc98e4747U, 0x0bfbf0f0U,
+    0xec41adadU, 0x67b3d4d4U, 0xfd5fa2a2U, 0xea45afafU,
+    0xbf239c9cU, 0xf753a4a4U, 0x96e47272U, 0x5b9bc0c0U,
+    0xc275b7b7U, 0x1ce1fdfdU, 0xae3d9393U, 0x6a4c2626U,
+    0x5a6c3636U, 0x417e3f3fU, 0x02f5f7f7U, 0x4f83ccccU,
+    0x5c683434U, 0xf451a5a5U, 0x34d1e5e5U, 0x08f9f1f1U,
+    0x93e27171U, 0x73abd8d8U, 0x53623131U, 0x3f2a1515U,
+    0x0c080404U, 0x5295c7c7U, 0x65462323U, 0x5e9dc3c3U,
+    0x28301818U, 0xa1379696U, 0x0f0a0505U, 0xb52f9a9aU,
+    0x090e0707U, 0x36241212U, 0x9b1b8080U, 0x3ddfe2e2U,
+    0x26cdebebU, 0x694e2727U, 0xcd7fb2b2U, 0x9fea7575U,
+    0x1b120909U, 0x9e1d8383U, 0x74582c2cU, 0x2e341a1aU,
+    0x2d361b1bU, 0xb2dc6e6eU, 0xeeb45a5aU, 0xfb5ba0a0U,
+    0xf6a45252U, 0x4d763b3bU, 0x61b7d6d6U, 0xce7db3b3U,
+    0x7b522929U, 0x3edde3e3U, 0x715e2f2fU, 0x97138484U,
+    0xf5a65353U, 0x68b9d1d1U, 0x00000000U, 0x2cc1ededU,
+    0x60402020U, 0x1fe3fcfcU, 0xc879b1b1U, 0xedb65b5bU,
+    0xbed46a6aU, 0x468dcbcbU, 0xd967bebeU, 0x4b723939U,
+    0xde944a4aU, 0xd4984c4cU, 0xe8b05858U, 0x4a85cfcfU,
+    0x6bbbd0d0U, 0x2ac5efefU, 0xe54faaaaU, 0x16edfbfbU,
+    0xc5864343U, 0xd79a4d4dU, 0x55663333U, 0x94118585U,
+    0xcf8a4545U, 0x10e9f9f9U, 0x06040202U, 0x81fe7f7fU,
+    0xf0a05050U, 0x44783c3cU, 0xba259f9fU, 0xe34ba8a8U,
+    0xf3a25151U, 0xfe5da3a3U, 0xc0804040U, 0x8a058f8fU,
+    0xad3f9292U, 0xbc219d9dU, 0x48703838U, 0x04f1f5f5U,
+    0xdf63bcbcU, 0xc177b6b6U, 0x75afdadaU, 0x63422121U,
+    0x30201010U, 0x1ae5ffffU, 0x0efdf3f3U, 0x6dbfd2d2U,
+    0x4c81cdcdU, 0x14180c0cU, 0x35261313U, 0x2fc3ececU,
+    0xe1be5f5fU, 0xa2359797U, 0xcc884444U, 0x392e1717U,
+    0x5793c4c4U, 0xf255a7a7U, 0x82fc7e7eU, 0x477a3d3dU,
+    0xacc86464U, 0xe7ba5d5dU, 0x2b321919U, 0x95e67373U,
+    0xa0c06060U, 0x98198181U, 0xd19e4f4fU, 0x7fa3dcdcU,
+    0x66442222U, 0x7e542a2aU, 0xab3b9090U, 0x830b8888U,
+    0xca8c4646U, 0x29c7eeeeU, 0xd36bb8b8U, 0x3c281414U,
+    0x79a7dedeU, 0xe2bc5e5eU, 0x1d160b0bU, 0x76addbdbU,
+    0x3bdbe0e0U, 0x56643232U, 0x4e743a3aU, 0x1e140a0aU,
+    0xdb924949U, 0x0a0c0606U, 0x6c482424U, 0xe4b85c5cU,
+    0x5d9fc2c2U, 0x6ebdd3d3U, 0xef43acacU, 0xa6c46262U,
+    0xa8399191U, 0xa4319595U, 0x37d3e4e4U, 0x8bf27979U,
+    0x32d5e7e7U, 0x438bc8c8U, 0x596e3737U, 0xb7da6d6dU,
+    0x8c018d8dU, 0x64b1d5d5U, 0xd29c4e4eU, 0xe049a9a9U,
+    0xb4d86c6cU, 0xfaac5656U, 0x07f3f4f4U, 0x25cfeaeaU,
+    0xafca6565U, 0x8ef47a7aU, 0xe947aeaeU, 0x18100808U,
+    0xd56fbabaU, 0x88f07878U, 0x6f4a2525U, 0x725c2e2eU,
+    0x24381c1cU, 0xf157a6a6U, 0xc773b4b4U, 0x5197c6c6U,
+    0x23cbe8e8U, 0x7ca1ddddU, 0x9ce87474U, 0x213e1f1fU,
+    0xdd964b4bU, 0xdc61bdbdU, 0x860d8b8bU, 0x850f8a8aU,
+    0x90e07070U, 0x427c3e3eU, 0xc471b5b5U, 0xaacc6666U,
+    0xd8904848U, 0x05060303U, 0x01f7f6f6U, 0x121c0e0eU,
+    0xa3c26161U, 0x5f6a3535U, 0xf9ae5757U, 0xd069b9b9U,
+    0x91178686U, 0x5899c1c1U, 0x273a1d1dU, 0xb9279e9eU,
+    0x38d9e1e1U, 0x13ebf8f8U, 0xb32b9898U, 0x33221111U,
+    0xbbd26969U, 0x70a9d9d9U, 0x89078e8eU, 0xa7339494U,
+    0xb62d9b9bU, 0x223c1e1eU, 0x92158787U, 0x20c9e9e9U,
+    0x4987ceceU, 0xffaa5555U, 0x78502828U, 0x7aa5dfdfU,
+    0x8f038c8cU, 0xf859a1a1U, 0x80098989U, 0x171a0d0dU,
+    0xda65bfbfU, 0x31d7e6e6U, 0xc6844242U, 0xb8d06868U,
+    0xc3824141U, 0xb0299999U, 0x775a2d2dU, 0x111e0f0fU,
+    0xcb7bb0b0U, 0xfca85454U, 0xd66dbbbbU, 0x3a2c1616U,
+},
+{
+    0x63a5c663U, 0x7c84f87cU, 0x7799ee77U, 0x7b8df67bU,
+    0xf20dfff2U, 0x6bbdd66bU, 0x6fb1de6fU, 0xc55491c5U,
+    0x30506030U, 0x01030201U, 0x67a9ce67U, 0x2b7d562bU,
+    0xfe19e7feU, 0xd762b5d7U, 0xabe64dabU, 0x769aec76U,
+    0xca458fcaU, 0x829d1f82U, 0xc94089c9U, 0x7d87fa7dU,
+    0xfa15effaU, 0x59ebb259U, 0x47c98e47U, 0xf00bfbf0U,
+    0xadec41adU, 0xd467b3d4U, 0xa2fd5fa2U, 0xafea45afU,
+    0x9cbf239cU, 0xa4f753a4U, 0x7296e472U, 0xc05b9bc0U,
+    0xb7c275b7U, 0xfd1ce1fdU, 0x93ae3d93U, 0x266a4c26U,
+    0x365a6c36U, 0x3f417e3fU, 0xf702f5f7U, 0xcc4f83ccU,
+    0x345c6834U, 0xa5f451a5U, 0xe534d1e5U, 0xf108f9f1U,
+    0x7193e271U, 0xd873abd8U, 0x31536231U, 0x153f2a15U,
+    0x040c0804U, 0xc75295c7U, 0x23654623U, 0xc35e9dc3U,
+    0x18283018U, 0x96a13796U, 0x050f0a05U, 0x9ab52f9aU,
+    0x07090e07U, 0x12362412U, 0x809b1b80U, 0xe23ddfe2U,
+    0xeb26cdebU, 0x27694e27U, 0xb2cd7fb2U, 0x759fea75U,
+    0x091b1209U, 0x839e1d83U, 0x2c74582cU, 0x1a2e341aU,
+    0x1b2d361bU, 0x6eb2dc6eU, 0x5aeeb45aU, 0xa0fb5ba0U,
+    0x52f6a452U, 0x3b4d763bU, 0xd661b7d6U, 0xb3ce7db3U,
+    0x297b5229U, 0xe33edde3U, 0x2f715e2fU, 0x84971384U,
+    0x53f5a653U, 0xd168b9d1U, 0x00000000U, 0xed2cc1edU,
+    0x20604020U, 0xfc1fe3fcU, 0xb1c879b1U, 0x5bedb65bU,
+    0x6abed46aU, 0xcb468dcbU, 0xbed967beU, 0x394b7239U,
+    0x4ade944aU, 0x4cd4984cU, 0x58e8b058U, 0xcf4a85cfU,
+    0xd06bbbd0U, 0xef2ac5efU, 0xaae54faaU, 0xfb16edfbU,
+    0x43c58643U, 0x4dd79a4dU, 0x33556633U, 0x85941185U,
+    0x45cf8a45U, 0xf910e9f9U, 0x02060402U, 0x7f81fe7fU,
+    0x50f0a050U, 0x3c44783cU, 0x9fba259fU, 0xa8e34ba8U,
+    0x51f3a251U, 0xa3fe5da3U, 0x40c08040U, 0x8f8a058fU,
+    0x92ad3f92U, 0x9dbc219dU, 0x38487038U, 0xf504f1f5U,
+    0xbcdf63bcU, 0xb6c177b6U, 0xda75afdaU, 0x21634221U,
+    0x10302010U, 0xff1ae5ffU, 0xf30efdf3U, 0xd26dbfd2U,
+    0xcd4c81cdU, 0x0c14180cU, 0x13352613U, 0xec2fc3ecU,
+    0x5fe1be5fU, 0x97a23597U, 0x44cc8844U, 0x17392e17U,
+    0xc45793c4U, 0xa7f255a7U, 0x7e82fc7eU, 0x3d477a3dU,
+    0x64acc864U, 0x5de7ba5dU, 0x192b3219U, 0x7395e673U,
+    0x60a0c060U, 0x81981981U, 0x4fd19e4fU, 0xdc7fa3dcU,
+    0x22664422U, 0x2a7e542aU, 0x90ab3b90U, 0x88830b88U,
+    0x46ca8c46U, 0xee29c7eeU, 0xb8d36bb8U, 0x143c2814U,
+    0xde79a7deU, 0x5ee2bc5eU, 0x0b1d160bU, 0xdb76addbU,
+    0xe03bdbe0U, 0x32566432U, 0x3a4e743aU, 0x0a1e140aU,
+    0x49db9249U, 0x060a0c06U, 0x246c4824U, 0x5ce4b85cU,
+    0xc25d9fc2U, 0xd36ebdd3U, 0xacef43acU, 0x62a6c462U,
+    0x91a83991U, 0x95a43195U, 0xe437d3e4U, 0x798bf279U,
+    0xe732d5e7U, 0xc8438bc8U, 0x37596e37U, 0x6db7da6dU,
+    0x8d8c018dU, 0xd564b1d5U, 0x4ed29c4eU, 0xa9e049a9U,
+    0x6cb4d86cU, 0x56faac56U, 0xf407f3f4U, 0xea25cfeaU,
+    0x65afca65U, 0x7a8ef47aU, 0xaee947aeU, 0x08181008U,
+    0xbad56fbaU, 0x7888f078U, 0x256f4a25U, 0x2e725c2eU,
+    0x1c24381cU, 0xa6f157a6U, 0xb4c773b4U, 0xc65197c6U,
+    0xe823cbe8U, 0xdd7ca1ddU, 0x749ce874U, 0x1f213e1fU,
+    0x4bdd964bU, 0xbddc61bdU, 0x8b860d8bU, 0x8a850f8aU,
+    0x7090e070U, 0x3e427c3eU, 0xb5c471b5U, 0x66aacc66U,
+    0x48d89048U, 0x03050603U, 0xf601f7f6U, 0x0e121c0eU,
+    0x61a3c261U, 0x355f6a35U, 0x57f9ae57U, 0xb9d069b9U,
+    0x86911786U, 0xc15899c1U, 0x1d273a1dU, 0x9eb9279eU,
+    0xe138d9e1U, 0xf813ebf8U, 0x98b32b98U, 0x11332211U,
+    0x69bbd269U, 0xd970a9d9U, 0x8e89078eU, 0x94a73394U,
+    0x9bb62d9bU, 0x1e223c1eU, 0x87921587U, 0xe920c9e9U,
+    0xce4987ceU, 0x55ffaa55U, 0x28785028U, 0xdf7aa5dfU,
+    0x8c8f038cU, 0xa1f859a1U, 0x89800989U, 0x0d171a0dU,
+    0xbfda65bfU, 0xe631d7e6U, 0x42c68442U, 0x68b8d068U,
+    0x41c38241U, 0x99b02999U, 0x2d775a2dU, 0x0f111e0fU,
+    0xb0cb7bb0U, 0x54fca854U, 0xbbd66dbbU, 0x163a2c16U,
+},
+{
+    0x6363a5c6U, 0x7c7c84f8U, 0x777799eeU, 0x7b7b8df6U,
+    0xf2f20dffU, 0x6b6bbdd6U, 0x6f6fb1deU, 0xc5c55491U,
+    0x30305060U, 0x01010302U, 0x6767a9ceU, 0x2b2b7d56U,
+    0xfefe19e7U, 0xd7d762b5U, 0xababe64dU, 0x76769aecU,
+    0xcaca458fU, 0x82829d1fU, 0xc9c94089U, 0x7d7d87faU,
+    0xfafa15efU, 0x5959ebb2U, 0x4747c98eU, 0xf0f00bfbU,
+    0xadadec41U, 0xd4d467b3U, 0xa2a2fd5fU, 0xafafea45U,
+    0x9c9cbf23U, 0xa4a4f753U, 0x727296e4U, 0xc0c05b9bU,
+    0xb7b7c275U, 0xfdfd1ce1U, 0x9393ae3dU, 0x26266a4cU,
+    0x36365a6cU, 0x3f3f417eU, 0xf7f702f5U, 0xcccc4f83U,
+    0x34345c68U, 0xa5a5f451U, 0xe5e534d1U, 0xf1f108f9U,
+    0x717193e2U, 0xd8d873abU, 0x31315362U, 0x15153f2aU,
+    0x04040c08U, 0xc7c75295U, 0x23236546U, 0xc3c35e9dU,
+    0x18182830U, 0x9696a137U, 0x05050f0aU, 0x9a9ab52fU,
+    0x0707090eU, 0x12123624U, 0x80809b1bU, 0xe2e23ddfU,
+    0xebeb26cdU, 0x2727694eU, 0xb2b2cd7fU, 0x75759feaU,
+    0x09091b12U, 0x83839e1dU, 0x2c2c7458U, 0x1a1a2e34U,
+    0x1b1b2d36U, 0x6e6eb2dcU, 0x5a5aeeb4U, 0xa0a0fb5bU,
+    0x5252f6a4U, 0x3b3b4d76U, 0xd6d661b7U, 0xb3b3ce7dU,
+    0x29297b52U, 0xe3e33eddU, 0x2f2f715eU, 0x84849713U,
+    0x5353f5a6U, 0xd1d168b9U, 0x00000000U, 0xeded2cc1U,
+    0x20206040U, 0xfcfc1fe3U, 0xb1b1c879U, 0x5b5bedb6U,
+    0x6a6abed4U, 0xcbcb468dU, 0xbebed967U, 0x39394b72U,
+    0x4a4ade94U, 0x4c4cd498U, 0x5858e8b0U, 0xcfcf4a85U,
+    0xd0d06bbbU, 0xefef2ac5U, 0xaaaae54fU, 0xfbfb16edU,
+    0x4343c586U, 0x4d4dd79aU, 0x33335566U, 0x85859411U,
+    0x4545cf8aU, 0xf9f910e9U, 0x02020604U, 0x7f7f81feU,
+    0x5050f0a0U, 0x3c3c4478U, 0x9f9fba25U, 0xa8a8e34bU,
+    0x5151f3a2U, 0xa3a3fe5dU, 0x4040c080U, 0x8f8f8a05U,
+    0x9292ad3fU, 0x9d9dbc21U, 0x38384870U, 0xf5f504f1U,
+    0xbcbcdf63U, 0xb6b6c177U, 0xdada75afU, 0x21216342U,
+    0x10103020U, 0xffff1ae5U, 0xf3f30efdU, 0xd2d26dbfU,
+    0xcdcd4c81U, 0x0c0c1418U, 0x13133526U, 0xecec2fc3U,
+    0x5f5fe1beU, 0x9797a235U, 0x4444cc88U, 0x1717392eU,
+    0xc4c45793U, 0xa7a7f255U, 0x7e7e82fcU, 0x3d3d477aU,
+    0x6464acc8U, 0x5d5de7baU, 0x19192b32U, 0x737395e6U,
+    0x6060a0c0U, 0x81819819U, 0x4f4fd19eU, 0xdcdc7fa3U,
+    0x22226644U, 0x2a2a7e54U, 0x9090ab3bU, 0x8888830bU,
+    0x4646ca8cU, 0xeeee29c7U, 0xb8b8d36bU, 0x14143c28U,
+    0xdede79a7U, 0x5e5ee2bcU, 0x0b0b1d16U, 0xdbdb76adU,
+    0xe0e03bdbU, 0x32325664U, 0x3a3a4e74U, 0x0a0a1e14U,
+    0x4949db92U, 0x06060a0cU, 0x24246c48U, 0x5c5ce4b8U,
+    0xc2c25d9fU, 0xd3d36ebdU, 0xacacef43U, 0x6262a6c4U,
+    0x9191a839U, 0x9595a431U, 0xe4e437d3U, 0x79798bf2U,
+    0xe7e732d5U, 0xc8c8438bU, 0x3737596eU, 0x6d6db7daU,
+    0x8d8d8c01U, 0xd5d564b1U, 0x4e4ed29cU, 0xa9a9e049U,
+    0x6c6cb4d8U, 0x5656faacU, 0xf4f407f3U, 0xeaea25cfU,
+    0x6565afcaU, 0x7a7a8ef4U, 0xaeaee947U, 0x08081810U,
+    0xbabad56fU, 0x787888f0U, 0x25256f4aU, 0x2e2e725cU,
+    0x1c1c2438U, 0xa6a6f157U, 0xb4b4c773U, 0xc6c65197U,
+    0xe8e823cbU, 0xdddd7ca1U, 0x74749ce8U, 0x1f1f213eU,
+    0x4b4bdd96U, 0xbdbddc61U, 0x8b8b860dU, 0x8a8a850fU,
+    0x707090e0U, 0x3e3e427cU, 0xb5b5c471U, 0x6666aaccU,
+    0x4848d890U, 0x03030506U, 0xf6f601f7U, 0x0e0e121cU,
+    0x6161a3c2U, 0x35355f6aU, 0x5757f9aeU, 0xb9b9d069U,
+    0x86869117U, 0xc1c15899U, 0x1d1d273aU, 0x9e9eb927U,
+    0xe1e138d9U, 0xf8f813ebU, 0x9898b32bU, 0x11113322U,
+    0x6969bbd2U, 0xd9d970a9U, 0x8e8e8907U, 0x9494a733U,
+    0x9b9bb62dU, 0x1e1e223cU, 0x87879215U, 0xe9e920c9U,
+    0xcece4987U, 0x5555ffaaU, 0x28287850U, 0xdfdf7aa5U,
+    0x8c8c8f03U, 0xa1a1f859U, 0x89898009U, 0x0d0d171aU,
+    0xbfbfda65U, 0xe6e631d7U, 0x4242c684U, 0x6868b8d0U,
+    0x4141c382U, 0x9999b029U, 0x2d2d775aU, 0x0f0f111eU,
+    0xb0b0cb7bU, 0x5454fca8U, 0xbbbbd66dU, 0x16163a2cU,
+},
+{
+    0x63636363U, 0x7c7c7c7cU, 0x77777777U, 0x7b7b7b7bU,
+    0xf2f2f2f2U, 0x6b6b6b6bU, 0x6f6f6f6fU, 0xc5c5c5c5U,
+    0x30303030U, 0x01010101U, 0x67676767U, 0x2b2b2b2bU,
+    0xfefefefeU, 0xd7d7d7d7U, 0xababababU, 0x76767676U,
+    0xcacacacaU, 0x82828282U, 0xc9c9c9c9U, 0x7d7d7d7dU,
+    0xfafafafaU, 0x59595959U, 0x47474747U, 0xf0f0f0f0U,
+    0xadadadadU, 0xd4d4d4d4U, 0xa2a2a2a2U, 0xafafafafU,
+    0x9c9c9c9cU, 0xa4a4a4a4U, 0x72727272U, 0xc0c0c0c0U,
+    0xb7b7b7b7U, 0xfdfdfdfdU, 0x93939393U, 0x26262626U,
+    0x36363636U, 0x3f3f3f3fU, 0xf7f7f7f7U, 0xccccccccU,
+    0x34343434U, 0xa5a5a5a5U, 0xe5e5e5e5U, 0xf1f1f1f1U,
+    0x71717171U, 0xd8d8d8d8U, 0x31313131U, 0x15151515U,
+    0x04040404U, 0xc7c7c7c7U, 0x23232323U, 0xc3c3c3c3U,
+    0x18181818U, 0x96969696U, 0x05050505U, 0x9a9a9a9aU,
+    0x07070707U, 0x12121212U, 0x80808080U, 0xe2e2e2e2U,
+    0xebebebebU, 0x27272727U, 0xb2b2b2b2U, 0x75757575U,
+    0x09090909U, 0x83838383U, 0x2c2c2c2cU, 0x1a1a1a1aU,
+    0x1b1b1b1bU, 0x6e6e6e6eU, 0x5a5a5a5aU, 0xa0a0a0a0U,
+    0x52525252U, 0x3b3b3b3bU, 0xd6d6d6d6U, 0xb3b3b3b3U,
+    0x29292929U, 0xe3e3e3e3U, 0x2f2f2f2fU, 0x84848484U,
+    0x53535353U, 0xd1d1d1d1U, 0x00000000U, 0xededededU,
+    0x20202020U, 0xfcfcfcfcU, 0xb1b1b1b1U, 0x5b5b5b5bU,
+    0x6a6a6a6aU, 0xcbcbcbcbU, 0xbebebebeU, 0x39393939U,
+    0x4a4a4a4aU, 0x4c4c4c4cU, 0x58585858U, 0xcfcfcfcfU,
+    0xd0d0d0d0U, 0xefefefefU, 0xaaaaaaaaU, 0xfbfbfbfbU,
+    0x43434343U, 0x4d4d4d4dU, 0x33333333U, 0x85858585U,
+    0x45454545U, 0xf9f9f9f9U, 0x02020202U, 0x7f7f7f7fU,
+    0x50505050U, 0x3c3c3c3cU, 0x9f9f9f9fU, 0xa8a8a8a8U,
+    0x51515151U, 0xa3a3a3a3U, 0x40404040U, 0x8f8f8f8fU,
+    0x92929292U, 0x9d9d9d9dU, 0x38383838U, 0xf5f5f5f5U,
+    0xbcbcbcbcU, 0xb6b6b6b6U, 0xdadadadaU, 0x21212121U,
+    0x10101010U, 0xffffffffU, 0xf3f3f3f3U, 0xd2d2d2d2U,
+    0xcdcdcdcdU, 0x0c0c0c0cU, 0x13131313U, 0xececececU,
+    0x5f5f5f5fU, 0x97979797U, 0x44444444U, 0x17171717U,
+    0xc4c4c4c4U, 0xa7a7a7a7U, 0x7e7e7e7eU, 0x3d3d3d3dU,
+    0x64646464U, 0x5d5d5d5dU, 0x19191919U, 0x73737373U,
+    0x60606060U, 0x81818181U, 0x4f4f4f4fU, 0xdcdcdcdcU,
+    0x22222222U, 0x2a2a2a2aU, 0x90909090U, 0x88888888U,
+    0x46464646U, 0xeeeeeeeeU, 0xb8b8b8b8U, 0x14141414U,
+    0xdedededeU, 0x5e5e5e5eU, 0x0b0b0b0bU, 0xdbdbdbdbU,
+    0xe0e0e0e0U, 0x32323232U, 0x3a3a3a3aU, 0x0a0a0a0aU,
+    0x49494949U, 0x06060606U, 0x24242424U, 0x5c5c5c5cU,
+    0xc2c2c2c2U, 0xd3d3d3d3U, 0xacacacacU, 0x62626262U,
+    0x91919191U, 0x95959595U, 0xe4e4e4e4U, 0x79797979U,
+    0xe7e7e7e7U, 0xc8c8c8c8U, 0x37373737U, 0x6d6d6d6dU,
+    0x8d8d8d8dU, 0xd5d5d5d5U, 0x4e4e4e4eU, 0xa9a9a9a9U,
+    0x6c6c6c6cU, 0x56565656U, 0xf4f4f4f4U, 0xeaeaeaeaU,
+    0x65656565U, 0x7a7a7a7aU, 0xaeaeaeaeU, 0x08080808U,
+    0xbabababaU, 0x78787878U, 0x25252525U, 0x2e2e2e2eU,
+    0x1c1c1c1cU, 0xa6a6a6a6U, 0xb4b4b4b4U, 0xc6c6c6c6U,
+    0xe8e8e8e8U, 0xddddddddU, 0x74747474U, 0x1f1f1f1fU,
+    0x4b4b4b4bU, 0xbdbdbdbdU, 0x8b8b8b8bU, 0x8a8a8a8aU,
+    0x70707070U, 0x3e3e3e3eU, 0xb5b5b5b5U, 0x66666666U,
+    0x48484848U, 0x03030303U, 0xf6f6f6f6U, 0x0e0e0e0eU,
+    0x61616161U, 0x35353535U, 0x57575757U, 0xb9b9b9b9U,
+    0x86868686U, 0xc1c1c1c1U, 0x1d1d1d1dU, 0x9e9e9e9eU,
+    0xe1e1e1e1U, 0xf8f8f8f8U, 0x98989898U, 0x11111111U,
+    0x69696969U, 0xd9d9d9d9U, 0x8e8e8e8eU, 0x94949494U,
+    0x9b9b9b9bU, 0x1e1e1e1eU, 0x87878787U, 0xe9e9e9e9U,
+    0xcecececeU, 0x55555555U, 0x28282828U, 0xdfdfdfdfU,
+    0x8c8c8c8cU, 0xa1a1a1a1U, 0x89898989U, 0x0d0d0d0dU,
+    0xbfbfbfbfU, 0xe6e6e6e6U, 0x42424242U, 0x68686868U,
+    0x41414141U, 0x99999999U, 0x2d2d2d2dU, 0x0f0f0f0fU,
+    0xb0b0b0b0U, 0x54545454U, 0xbbbbbbbbU, 0x16161616U,
+}
+};
+
+
+const word32 AES::Td[5][256] = {
+{
+    0x51f4a750U, 0x7e416553U, 0x1a17a4c3U, 0x3a275e96U,
+    0x3bab6bcbU, 0x1f9d45f1U, 0xacfa58abU, 0x4be30393U,
+    0x2030fa55U, 0xad766df6U, 0x88cc7691U, 0xf5024c25U,
+    0x4fe5d7fcU, 0xc52acbd7U, 0x26354480U, 0xb562a38fU,
+    0xdeb15a49U, 0x25ba1b67U, 0x45ea0e98U, 0x5dfec0e1U,
+    0xc32f7502U, 0x814cf012U, 0x8d4697a3U, 0x6bd3f9c6U,
+    0x038f5fe7U, 0x15929c95U, 0xbf6d7aebU, 0x955259daU,
+    0xd4be832dU, 0x587421d3U, 0x49e06929U, 0x8ec9c844U,
+    0x75c2896aU, 0xf48e7978U, 0x99583e6bU, 0x27b971ddU,
+    0xbee14fb6U, 0xf088ad17U, 0xc920ac66U, 0x7dce3ab4U,
+    0x63df4a18U, 0xe51a3182U, 0x97513360U, 0x62537f45U,
+    0xb16477e0U, 0xbb6bae84U, 0xfe81a01cU, 0xf9082b94U,
+    0x70486858U, 0x8f45fd19U, 0x94de6c87U, 0x527bf8b7U,
+    0xab73d323U, 0x724b02e2U, 0xe31f8f57U, 0x6655ab2aU,
+    0xb2eb2807U, 0x2fb5c203U, 0x86c57b9aU, 0xd33708a5U,
+    0x302887f2U, 0x23bfa5b2U, 0x02036abaU, 0xed16825cU,
+    0x8acf1c2bU, 0xa779b492U, 0xf307f2f0U, 0x4e69e2a1U,
+    0x65daf4cdU, 0x0605bed5U, 0xd134621fU, 0xc4a6fe8aU,
+    0x342e539dU, 0xa2f355a0U, 0x058ae132U, 0xa4f6eb75U,
+    0x0b83ec39U, 0x4060efaaU, 0x5e719f06U, 0xbd6e1051U,
+    0x3e218af9U, 0x96dd063dU, 0xdd3e05aeU, 0x4de6bd46U,
+    0x91548db5U, 0x71c45d05U, 0x0406d46fU, 0x605015ffU,
+    0x1998fb24U, 0xd6bde997U, 0x894043ccU, 0x67d99e77U,
+    0xb0e842bdU, 0x07898b88U, 0xe7195b38U, 0x79c8eedbU,
+    0xa17c0a47U, 0x7c420fe9U, 0xf8841ec9U, 0x00000000U,
+    0x09808683U, 0x322bed48U, 0x1e1170acU, 0x6c5a724eU,
+    0xfd0efffbU, 0x0f853856U, 0x3daed51eU, 0x362d3927U,
+    0x0a0fd964U, 0x685ca621U, 0x9b5b54d1U, 0x24362e3aU,
+    0x0c0a67b1U, 0x9357e70fU, 0xb4ee96d2U, 0x1b9b919eU,
+    0x80c0c54fU, 0x61dc20a2U, 0x5a774b69U, 0x1c121a16U,
+    0xe293ba0aU, 0xc0a02ae5U, 0x3c22e043U, 0x121b171dU,
+    0x0e090d0bU, 0xf28bc7adU, 0x2db6a8b9U, 0x141ea9c8U,
+    0x57f11985U, 0xaf75074cU, 0xee99ddbbU, 0xa37f60fdU,
+    0xf701269fU, 0x5c72f5bcU, 0x44663bc5U, 0x5bfb7e34U,
+    0x8b432976U, 0xcb23c6dcU, 0xb6edfc68U, 0xb8e4f163U,
+    0xd731dccaU, 0x42638510U, 0x13972240U, 0x84c61120U,
+    0x854a247dU, 0xd2bb3df8U, 0xaef93211U, 0xc729a16dU,
+    0x1d9e2f4bU, 0xdcb230f3U, 0x0d8652ecU, 0x77c1e3d0U,
+    0x2bb3166cU, 0xa970b999U, 0x119448faU, 0x47e96422U,
+    0xa8fc8cc4U, 0xa0f03f1aU, 0x567d2cd8U, 0x223390efU,
+    0x87494ec7U, 0xd938d1c1U, 0x8ccaa2feU, 0x98d40b36U,
+    0xa6f581cfU, 0xa57ade28U, 0xdab78e26U, 0x3fadbfa4U,
+    0x2c3a9de4U, 0x5078920dU, 0x6a5fcc9bU, 0x547e4662U,
+    0xf68d13c2U, 0x90d8b8e8U, 0x2e39f75eU, 0x82c3aff5U,
+    0x9f5d80beU, 0x69d0937cU, 0x6fd52da9U, 0xcf2512b3U,
+    0xc8ac993bU, 0x10187da7U, 0xe89c636eU, 0xdb3bbb7bU,
+    0xcd267809U, 0x6e5918f4U, 0xec9ab701U, 0x834f9aa8U,
+    0xe6956e65U, 0xaaffe67eU, 0x21bccf08U, 0xef15e8e6U,
+    0xbae79bd9U, 0x4a6f36ceU, 0xea9f09d4U, 0x29b07cd6U,
+    0x31a4b2afU, 0x2a3f2331U, 0xc6a59430U, 0x35a266c0U,
+    0x744ebc37U, 0xfc82caa6U, 0xe090d0b0U, 0x33a7d815U,
+    0xf104984aU, 0x41ecdaf7U, 0x7fcd500eU, 0x1791f62fU,
+    0x764dd68dU, 0x43efb04dU, 0xccaa4d54U, 0xe49604dfU,
+    0x9ed1b5e3U, 0x4c6a881bU, 0xc12c1fb8U, 0x4665517fU,
+    0x9d5eea04U, 0x018c355dU, 0xfa877473U, 0xfb0b412eU,
+    0xb3671d5aU, 0x92dbd252U, 0xe9105633U, 0x6dd64713U,
+    0x9ad7618cU, 0x37a10c7aU, 0x59f8148eU, 0xeb133c89U,
+    0xcea927eeU, 0xb761c935U, 0xe11ce5edU, 0x7a47b13cU,
+    0x9cd2df59U, 0x55f2733fU, 0x1814ce79U, 0x73c737bfU,
+    0x53f7cdeaU, 0x5ffdaa5bU, 0xdf3d6f14U, 0x7844db86U,
+    0xcaaff381U, 0xb968c43eU, 0x3824342cU, 0xc2a3405fU,
+    0x161dc372U, 0xbce2250cU, 0x283c498bU, 0xff0d9541U,
+    0x39a80171U, 0x080cb3deU, 0xd8b4e49cU, 0x6456c190U,
+    0x7bcb8461U, 0xd532b670U, 0x486c5c74U, 0xd0b85742U,
+},
+{
+    0x5051f4a7U, 0x537e4165U, 0xc31a17a4U, 0x963a275eU,
+    0xcb3bab6bU, 0xf11f9d45U, 0xabacfa58U, 0x934be303U,
+    0x552030faU, 0xf6ad766dU, 0x9188cc76U, 0x25f5024cU,
+    0xfc4fe5d7U, 0xd7c52acbU, 0x80263544U, 0x8fb562a3U,
+    0x49deb15aU, 0x6725ba1bU, 0x9845ea0eU, 0xe15dfec0U,
+    0x02c32f75U, 0x12814cf0U, 0xa38d4697U, 0xc66bd3f9U,
+    0xe7038f5fU, 0x9515929cU, 0xebbf6d7aU, 0xda955259U,
+    0x2dd4be83U, 0xd3587421U, 0x2949e069U, 0x448ec9c8U,
+    0x6a75c289U, 0x78f48e79U, 0x6b99583eU, 0xdd27b971U,
+    0xb6bee14fU, 0x17f088adU, 0x66c920acU, 0xb47dce3aU,
+    0x1863df4aU, 0x82e51a31U, 0x60975133U, 0x4562537fU,
+    0xe0b16477U, 0x84bb6baeU, 0x1cfe81a0U, 0x94f9082bU,
+    0x58704868U, 0x198f45fdU, 0x8794de6cU, 0xb7527bf8U,
+    0x23ab73d3U, 0xe2724b02U, 0x57e31f8fU, 0x2a6655abU,
+    0x07b2eb28U, 0x032fb5c2U, 0x9a86c57bU, 0xa5d33708U,
+    0xf2302887U, 0xb223bfa5U, 0xba02036aU, 0x5ced1682U,
+    0x2b8acf1cU, 0x92a779b4U, 0xf0f307f2U, 0xa14e69e2U,
+    0xcd65daf4U, 0xd50605beU, 0x1fd13462U, 0x8ac4a6feU,
+    0x9d342e53U, 0xa0a2f355U, 0x32058ae1U, 0x75a4f6ebU,
+    0x390b83ecU, 0xaa4060efU, 0x065e719fU, 0x51bd6e10U,
+    0xf93e218aU, 0x3d96dd06U, 0xaedd3e05U, 0x464de6bdU,
+    0xb591548dU, 0x0571c45dU, 0x6f0406d4U, 0xff605015U,
+    0x241998fbU, 0x97d6bde9U, 0xcc894043U, 0x7767d99eU,
+    0xbdb0e842U, 0x8807898bU, 0x38e7195bU, 0xdb79c8eeU,
+    0x47a17c0aU, 0xe97c420fU, 0xc9f8841eU, 0x00000000U,
+    0x83098086U, 0x48322bedU, 0xac1e1170U, 0x4e6c5a72U,
+    0xfbfd0effU, 0x560f8538U, 0x1e3daed5U, 0x27362d39U,
+    0x640a0fd9U, 0x21685ca6U, 0xd19b5b54U, 0x3a24362eU,
+    0xb10c0a67U, 0x0f9357e7U, 0xd2b4ee96U, 0x9e1b9b91U,
+    0x4f80c0c5U, 0xa261dc20U, 0x695a774bU, 0x161c121aU,
+    0x0ae293baU, 0xe5c0a02aU, 0x433c22e0U, 0x1d121b17U,
+    0x0b0e090dU, 0xadf28bc7U, 0xb92db6a8U, 0xc8141ea9U,
+    0x8557f119U, 0x4caf7507U, 0xbbee99ddU, 0xfda37f60U,
+    0x9ff70126U, 0xbc5c72f5U, 0xc544663bU, 0x345bfb7eU,
+    0x768b4329U, 0xdccb23c6U, 0x68b6edfcU, 0x63b8e4f1U,
+    0xcad731dcU, 0x10426385U, 0x40139722U, 0x2084c611U,
+    0x7d854a24U, 0xf8d2bb3dU, 0x11aef932U, 0x6dc729a1U,
+    0x4b1d9e2fU, 0xf3dcb230U, 0xec0d8652U, 0xd077c1e3U,
+    0x6c2bb316U, 0x99a970b9U, 0xfa119448U, 0x2247e964U,
+    0xc4a8fc8cU, 0x1aa0f03fU, 0xd8567d2cU, 0xef223390U,
+    0xc787494eU, 0xc1d938d1U, 0xfe8ccaa2U, 0x3698d40bU,
+    0xcfa6f581U, 0x28a57adeU, 0x26dab78eU, 0xa43fadbfU,
+    0xe42c3a9dU, 0x0d507892U, 0x9b6a5fccU, 0x62547e46U,
+    0xc2f68d13U, 0xe890d8b8U, 0x5e2e39f7U, 0xf582c3afU,
+    0xbe9f5d80U, 0x7c69d093U, 0xa96fd52dU, 0xb3cf2512U,
+    0x3bc8ac99U, 0xa710187dU, 0x6ee89c63U, 0x7bdb3bbbU,
+    0x09cd2678U, 0xf46e5918U, 0x01ec9ab7U, 0xa8834f9aU,
+    0x65e6956eU, 0x7eaaffe6U, 0x0821bccfU, 0xe6ef15e8U,
+    0xd9bae79bU, 0xce4a6f36U, 0xd4ea9f09U, 0xd629b07cU,
+    0xaf31a4b2U, 0x312a3f23U, 0x30c6a594U, 0xc035a266U,
+    0x37744ebcU, 0xa6fc82caU, 0xb0e090d0U, 0x1533a7d8U,
+    0x4af10498U, 0xf741ecdaU, 0x0e7fcd50U, 0x2f1791f6U,
+    0x8d764dd6U, 0x4d43efb0U, 0x54ccaa4dU, 0xdfe49604U,
+    0xe39ed1b5U, 0x1b4c6a88U, 0xb8c12c1fU, 0x7f466551U,
+    0x049d5eeaU, 0x5d018c35U, 0x73fa8774U, 0x2efb0b41U,
+    0x5ab3671dU, 0x5292dbd2U, 0x33e91056U, 0x136dd647U,
+    0x8c9ad761U, 0x7a37a10cU, 0x8e59f814U, 0x89eb133cU,
+    0xeecea927U, 0x35b761c9U, 0xede11ce5U, 0x3c7a47b1U,
+    0x599cd2dfU, 0x3f55f273U, 0x791814ceU, 0xbf73c737U,
+    0xea53f7cdU, 0x5b5ffdaaU, 0x14df3d6fU, 0x867844dbU,
+    0x81caaff3U, 0x3eb968c4U, 0x2c382434U, 0x5fc2a340U,
+    0x72161dc3U, 0x0cbce225U, 0x8b283c49U, 0x41ff0d95U,
+    0x7139a801U, 0xde080cb3U, 0x9cd8b4e4U, 0x906456c1U,
+    0x617bcb84U, 0x70d532b6U, 0x74486c5cU, 0x42d0b857U,
+},
+{
+    0xa75051f4U, 0x65537e41U, 0xa4c31a17U, 0x5e963a27U,
+    0x6bcb3babU, 0x45f11f9dU, 0x58abacfaU, 0x03934be3U,
+    0xfa552030U, 0x6df6ad76U, 0x769188ccU, 0x4c25f502U,
+    0xd7fc4fe5U, 0xcbd7c52aU, 0x44802635U, 0xa38fb562U,
+    0x5a49deb1U, 0x1b6725baU, 0x0e9845eaU, 0xc0e15dfeU,
+    0x7502c32fU, 0xf012814cU, 0x97a38d46U, 0xf9c66bd3U,
+    0x5fe7038fU, 0x9c951592U, 0x7aebbf6dU, 0x59da9552U,
+    0x832dd4beU, 0x21d35874U, 0x692949e0U, 0xc8448ec9U,
+    0x896a75c2U, 0x7978f48eU, 0x3e6b9958U, 0x71dd27b9U,
+    0x4fb6bee1U, 0xad17f088U, 0xac66c920U, 0x3ab47dceU,
+    0x4a1863dfU, 0x3182e51aU, 0x33609751U, 0x7f456253U,
+    0x77e0b164U, 0xae84bb6bU, 0xa01cfe81U, 0x2b94f908U,
+    0x68587048U, 0xfd198f45U, 0x6c8794deU, 0xf8b7527bU,
+    0xd323ab73U, 0x02e2724bU, 0x8f57e31fU, 0xab2a6655U,
+    0x2807b2ebU, 0xc2032fb5U, 0x7b9a86c5U, 0x08a5d337U,
+    0x87f23028U, 0xa5b223bfU, 0x6aba0203U, 0x825ced16U,
+    0x1c2b8acfU, 0xb492a779U, 0xf2f0f307U, 0xe2a14e69U,
+    0xf4cd65daU, 0xbed50605U, 0x621fd134U, 0xfe8ac4a6U,
+    0x539d342eU, 0x55a0a2f3U, 0xe132058aU, 0xeb75a4f6U,
+    0xec390b83U, 0xefaa4060U, 0x9f065e71U, 0x1051bd6eU,
+
+    0x8af93e21U, 0x063d96ddU, 0x05aedd3eU, 0xbd464de6U,
+    0x8db59154U, 0x5d0571c4U, 0xd46f0406U, 0x15ff6050U,
+    0xfb241998U, 0xe997d6bdU, 0x43cc8940U, 0x9e7767d9U,
+    0x42bdb0e8U, 0x8b880789U, 0x5b38e719U, 0xeedb79c8U,
+    0x0a47a17cU, 0x0fe97c42U, 0x1ec9f884U, 0x00000000U,
+    0x86830980U, 0xed48322bU, 0x70ac1e11U, 0x724e6c5aU,
+    0xfffbfd0eU, 0x38560f85U, 0xd51e3daeU, 0x3927362dU,
+    0xd9640a0fU, 0xa621685cU, 0x54d19b5bU, 0x2e3a2436U,
+    0x67b10c0aU, 0xe70f9357U, 0x96d2b4eeU, 0x919e1b9bU,
+    0xc54f80c0U, 0x20a261dcU, 0x4b695a77U, 0x1a161c12U,
+    0xba0ae293U, 0x2ae5c0a0U, 0xe0433c22U, 0x171d121bU,
+    0x0d0b0e09U, 0xc7adf28bU, 0xa8b92db6U, 0xa9c8141eU,
+    0x198557f1U, 0x074caf75U, 0xddbbee99U, 0x60fda37fU,
+    0x269ff701U, 0xf5bc5c72U, 0x3bc54466U, 0x7e345bfbU,
+    0x29768b43U, 0xc6dccb23U, 0xfc68b6edU, 0xf163b8e4U,
+    0xdccad731U, 0x85104263U, 0x22401397U, 0x112084c6U,
+    0x247d854aU, 0x3df8d2bbU, 0x3211aef9U, 0xa16dc729U,
+    0x2f4b1d9eU, 0x30f3dcb2U, 0x52ec0d86U, 0xe3d077c1U,
+    0x166c2bb3U, 0xb999a970U, 0x48fa1194U, 0x642247e9U,
+    0x8cc4a8fcU, 0x3f1aa0f0U, 0x2cd8567dU, 0x90ef2233U,
+    0x4ec78749U, 0xd1c1d938U, 0xa2fe8ccaU, 0x0b3698d4U,
+    0x81cfa6f5U, 0xde28a57aU, 0x8e26dab7U, 0xbfa43fadU,
+    0x9de42c3aU, 0x920d5078U, 0xcc9b6a5fU, 0x4662547eU,
+    0x13c2f68dU, 0xb8e890d8U, 0xf75e2e39U, 0xaff582c3U,
+    0x80be9f5dU, 0x937c69d0U, 0x2da96fd5U, 0x12b3cf25U,
+    0x993bc8acU, 0x7da71018U, 0x636ee89cU, 0xbb7bdb3bU,
+    0x7809cd26U, 0x18f46e59U, 0xb701ec9aU, 0x9aa8834fU,
+    0x6e65e695U, 0xe67eaaffU, 0xcf0821bcU, 0xe8e6ef15U,
+    0x9bd9bae7U, 0x36ce4a6fU, 0x09d4ea9fU, 0x7cd629b0U,
+    0xb2af31a4U, 0x23312a3fU, 0x9430c6a5U, 0x66c035a2U,
+    0xbc37744eU, 0xcaa6fc82U, 0xd0b0e090U, 0xd81533a7U,
+    0x984af104U, 0xdaf741ecU, 0x500e7fcdU, 0xf62f1791U,
+    0xd68d764dU, 0xb04d43efU, 0x4d54ccaaU, 0x04dfe496U,
+    0xb5e39ed1U, 0x881b4c6aU, 0x1fb8c12cU, 0x517f4665U,
+    0xea049d5eU, 0x355d018cU, 0x7473fa87U, 0x412efb0bU,
+    0x1d5ab367U, 0xd25292dbU, 0x5633e910U, 0x47136dd6U,
+    0x618c9ad7U, 0x0c7a37a1U, 0x148e59f8U, 0x3c89eb13U,
+    0x27eecea9U, 0xc935b761U, 0xe5ede11cU, 0xb13c7a47U,
+    0xdf599cd2U, 0x733f55f2U, 0xce791814U, 0x37bf73c7U,
+    0xcdea53f7U, 0xaa5b5ffdU, 0x6f14df3dU, 0xdb867844U,
+    0xf381caafU, 0xc43eb968U, 0x342c3824U, 0x405fc2a3U,
+    0xc372161dU, 0x250cbce2U, 0x498b283cU, 0x9541ff0dU,
+    0x017139a8U, 0xb3de080cU, 0xe49cd8b4U, 0xc1906456U,
+    0x84617bcbU, 0xb670d532U, 0x5c74486cU, 0x5742d0b8U,
+},
+{
+    0xf4a75051U, 0x4165537eU, 0x17a4c31aU, 0x275e963aU,
+    0xab6bcb3bU, 0x9d45f11fU, 0xfa58abacU, 0xe303934bU,
+    0x30fa5520U, 0x766df6adU, 0xcc769188U, 0x024c25f5U,
+    0xe5d7fc4fU, 0x2acbd7c5U, 0x35448026U, 0x62a38fb5U,
+    0xb15a49deU, 0xba1b6725U, 0xea0e9845U, 0xfec0e15dU,
+    0x2f7502c3U, 0x4cf01281U, 0x4697a38dU, 0xd3f9c66bU,
+    0x8f5fe703U, 0x929c9515U, 0x6d7aebbfU, 0x5259da95U,
+    0xbe832dd4U, 0x7421d358U, 0xe0692949U, 0xc9c8448eU,
+    0xc2896a75U, 0x8e7978f4U, 0x583e6b99U, 0xb971dd27U,
+    0xe14fb6beU, 0x88ad17f0U, 0x20ac66c9U, 0xce3ab47dU,
+    0xdf4a1863U, 0x1a3182e5U, 0x51336097U, 0x537f4562U,
+    0x6477e0b1U, 0x6bae84bbU, 0x81a01cfeU, 0x082b94f9U,
+    0x48685870U, 0x45fd198fU, 0xde6c8794U, 0x7bf8b752U,
+    0x73d323abU, 0x4b02e272U, 0x1f8f57e3U, 0x55ab2a66U,
+    0xeb2807b2U, 0xb5c2032fU, 0xc57b9a86U, 0x3708a5d3U,
+    0x2887f230U, 0xbfa5b223U, 0x036aba02U, 0x16825cedU,
+    0xcf1c2b8aU, 0x79b492a7U, 0x07f2f0f3U, 0x69e2a14eU,
+    0xdaf4cd65U, 0x05bed506U, 0x34621fd1U, 0xa6fe8ac4U,
+    0x2e539d34U, 0xf355a0a2U, 0x8ae13205U, 0xf6eb75a4U,
+    0x83ec390bU, 0x60efaa40U, 0x719f065eU, 0x6e1051bdU,
+    0x218af93eU, 0xdd063d96U, 0x3e05aeddU, 0xe6bd464dU,
+    0x548db591U, 0xc45d0571U, 0x06d46f04U, 0x5015ff60U,
+    0x98fb2419U, 0xbde997d6U, 0x4043cc89U, 0xd99e7767U,
+    0xe842bdb0U, 0x898b8807U, 0x195b38e7U, 0xc8eedb79U,
+    0x7c0a47a1U, 0x420fe97cU, 0x841ec9f8U, 0x00000000U,
+    0x80868309U, 0x2bed4832U, 0x1170ac1eU, 0x5a724e6cU,
+    0x0efffbfdU, 0x8538560fU, 0xaed51e3dU, 0x2d392736U,
+    0x0fd9640aU, 0x5ca62168U, 0x5b54d19bU, 0x362e3a24U,
+    0x0a67b10cU, 0x57e70f93U, 0xee96d2b4U, 0x9b919e1bU,
+    0xc0c54f80U, 0xdc20a261U, 0x774b695aU, 0x121a161cU,
+    0x93ba0ae2U, 0xa02ae5c0U, 0x22e0433cU, 0x1b171d12U,
+    0x090d0b0eU, 0x8bc7adf2U, 0xb6a8b92dU, 0x1ea9c814U,
+    0xf1198557U, 0x75074cafU, 0x99ddbbeeU, 0x7f60fda3U,
+    0x01269ff7U, 0x72f5bc5cU, 0x663bc544U, 0xfb7e345bU,
+    0x4329768bU, 0x23c6dccbU, 0xedfc68b6U, 0xe4f163b8U,
+    0x31dccad7U, 0x63851042U, 0x97224013U, 0xc6112084U,
+    0x4a247d85U, 0xbb3df8d2U, 0xf93211aeU, 0x29a16dc7U,
+    0x9e2f4b1dU, 0xb230f3dcU, 0x8652ec0dU, 0xc1e3d077U,
+    0xb3166c2bU, 0x70b999a9U, 0x9448fa11U, 0xe9642247U,
+    0xfc8cc4a8U, 0xf03f1aa0U, 0x7d2cd856U, 0x3390ef22U,
+    0x494ec787U, 0x38d1c1d9U, 0xcaa2fe8cU, 0xd40b3698U,
+    0xf581cfa6U, 0x7ade28a5U, 0xb78e26daU, 0xadbfa43fU,
+    0x3a9de42cU, 0x78920d50U, 0x5fcc9b6aU, 0x7e466254U,
+    0x8d13c2f6U, 0xd8b8e890U, 0x39f75e2eU, 0xc3aff582U,
+    0x5d80be9fU, 0xd0937c69U, 0xd52da96fU, 0x2512b3cfU,
+    0xac993bc8U, 0x187da710U, 0x9c636ee8U, 0x3bbb7bdbU,
+    0x267809cdU, 0x5918f46eU, 0x9ab701ecU, 0x4f9aa883U,
+    0x956e65e6U, 0xffe67eaaU, 0xbccf0821U, 0x15e8e6efU,
+    0xe79bd9baU, 0x6f36ce4aU, 0x9f09d4eaU, 0xb07cd629U,
+    0xa4b2af31U, 0x3f23312aU, 0xa59430c6U, 0xa266c035U,
+    0x4ebc3774U, 0x82caa6fcU, 0x90d0b0e0U, 0xa7d81533U,
+    0x04984af1U, 0xecdaf741U, 0xcd500e7fU, 0x91f62f17U,
+    0x4dd68d76U, 0xefb04d43U, 0xaa4d54ccU, 0x9604dfe4U,
+    0xd1b5e39eU, 0x6a881b4cU, 0x2c1fb8c1U, 0x65517f46U,
+    0x5eea049dU, 0x8c355d01U, 0x877473faU, 0x0b412efbU,
+    0x671d5ab3U, 0xdbd25292U, 0x105633e9U, 0xd647136dU,
+    0xd7618c9aU, 0xa10c7a37U, 0xf8148e59U, 0x133c89ebU,
+    0xa927eeceU, 0x61c935b7U, 0x1ce5ede1U, 0x47b13c7aU,
+    0xd2df599cU, 0xf2733f55U, 0x14ce7918U, 0xc737bf73U,
+    0xf7cdea53U, 0xfdaa5b5fU, 0x3d6f14dfU, 0x44db8678U,
+    0xaff381caU, 0x68c43eb9U, 0x24342c38U, 0xa3405fc2U,
+    0x1dc37216U, 0xe2250cbcU, 0x3c498b28U, 0x0d9541ffU,
+    0xa8017139U, 0x0cb3de08U, 0xb4e49cd8U, 0x56c19064U,
+    0xcb84617bU, 0x32b670d5U, 0x6c5c7448U, 0xb85742d0U,
+},
+{
+    0x52525252U, 0x09090909U, 0x6a6a6a6aU, 0xd5d5d5d5U,
+    0x30303030U, 0x36363636U, 0xa5a5a5a5U, 0x38383838U,
+    0xbfbfbfbfU, 0x40404040U, 0xa3a3a3a3U, 0x9e9e9e9eU,
+    0x81818181U, 0xf3f3f3f3U, 0xd7d7d7d7U, 0xfbfbfbfbU,
+    0x7c7c7c7cU, 0xe3e3e3e3U, 0x39393939U, 0x82828282U,
+    0x9b9b9b9bU, 0x2f2f2f2fU, 0xffffffffU, 0x87878787U,
+    0x34343434U, 0x8e8e8e8eU, 0x43434343U, 0x44444444U,
+    0xc4c4c4c4U, 0xdedededeU, 0xe9e9e9e9U, 0xcbcbcbcbU,
+    0x54545454U, 0x7b7b7b7bU, 0x94949494U, 0x32323232U,
+    0xa6a6a6a6U, 0xc2c2c2c2U, 0x23232323U, 0x3d3d3d3dU,
+    0xeeeeeeeeU, 0x4c4c4c4cU, 0x95959595U, 0x0b0b0b0bU,
+    0x42424242U, 0xfafafafaU, 0xc3c3c3c3U, 0x4e4e4e4eU,
+    0x08080808U, 0x2e2e2e2eU, 0xa1a1a1a1U, 0x66666666U,
+    0x28282828U, 0xd9d9d9d9U, 0x24242424U, 0xb2b2b2b2U,
+    0x76767676U, 0x5b5b5b5bU, 0xa2a2a2a2U, 0x49494949U,
+    0x6d6d6d6dU, 0x8b8b8b8bU, 0xd1d1d1d1U, 0x25252525U,
+    0x72727272U, 0xf8f8f8f8U, 0xf6f6f6f6U, 0x64646464U,
+    0x86868686U, 0x68686868U, 0x98989898U, 0x16161616U,
+    0xd4d4d4d4U, 0xa4a4a4a4U, 0x5c5c5c5cU, 0xccccccccU,
+    0x5d5d5d5dU, 0x65656565U, 0xb6b6b6b6U, 0x92929292U,
+    0x6c6c6c6cU, 0x70707070U, 0x48484848U, 0x50505050U,
+    0xfdfdfdfdU, 0xededededU, 0xb9b9b9b9U, 0xdadadadaU,
+    0x5e5e5e5eU, 0x15151515U, 0x46464646U, 0x57575757U,
+    0xa7a7a7a7U, 0x8d8d8d8dU, 0x9d9d9d9dU, 0x84848484U,
+    0x90909090U, 0xd8d8d8d8U, 0xababababU, 0x00000000U,
+    0x8c8c8c8cU, 0xbcbcbcbcU, 0xd3d3d3d3U, 0x0a0a0a0aU,
+    0xf7f7f7f7U, 0xe4e4e4e4U, 0x58585858U, 0x05050505U,
+    0xb8b8b8b8U, 0xb3b3b3b3U, 0x45454545U, 0x06060606U,
+    0xd0d0d0d0U, 0x2c2c2c2cU, 0x1e1e1e1eU, 0x8f8f8f8fU,
+    0xcacacacaU, 0x3f3f3f3fU, 0x0f0f0f0fU, 0x02020202U,
+    0xc1c1c1c1U, 0xafafafafU, 0xbdbdbdbdU, 0x03030303U,
+    0x01010101U, 0x13131313U, 0x8a8a8a8aU, 0x6b6b6b6bU,
+    0x3a3a3a3aU, 0x91919191U, 0x11111111U, 0x41414141U,
+    0x4f4f4f4fU, 0x67676767U, 0xdcdcdcdcU, 0xeaeaeaeaU,
+    0x97979797U, 0xf2f2f2f2U, 0xcfcfcfcfU, 0xcecececeU,
+    0xf0f0f0f0U, 0xb4b4b4b4U, 0xe6e6e6e6U, 0x73737373U,
+    0x96969696U, 0xacacacacU, 0x74747474U, 0x22222222U,
+    0xe7e7e7e7U, 0xadadadadU, 0x35353535U, 0x85858585U,
+    0xe2e2e2e2U, 0xf9f9f9f9U, 0x37373737U, 0xe8e8e8e8U,
+    0x1c1c1c1cU, 0x75757575U, 0xdfdfdfdfU, 0x6e6e6e6eU,
+    0x47474747U, 0xf1f1f1f1U, 0x1a1a1a1aU, 0x71717171U,
+    0x1d1d1d1dU, 0x29292929U, 0xc5c5c5c5U, 0x89898989U,
+    0x6f6f6f6fU, 0xb7b7b7b7U, 0x62626262U, 0x0e0e0e0eU,
+    0xaaaaaaaaU, 0x18181818U, 0xbebebebeU, 0x1b1b1b1bU,
+    0xfcfcfcfcU, 0x56565656U, 0x3e3e3e3eU, 0x4b4b4b4bU,
+    0xc6c6c6c6U, 0xd2d2d2d2U, 0x79797979U, 0x20202020U,
+    0x9a9a9a9aU, 0xdbdbdbdbU, 0xc0c0c0c0U, 0xfefefefeU,
+    0x78787878U, 0xcdcdcdcdU, 0x5a5a5a5aU, 0xf4f4f4f4U,
+    0x1f1f1f1fU, 0xddddddddU, 0xa8a8a8a8U, 0x33333333U,
+    0x88888888U, 0x07070707U, 0xc7c7c7c7U, 0x31313131U,
+    0xb1b1b1b1U, 0x12121212U, 0x10101010U, 0x59595959U,
+    0x27272727U, 0x80808080U, 0xececececU, 0x5f5f5f5fU,
+    0x60606060U, 0x51515151U, 0x7f7f7f7fU, 0xa9a9a9a9U,
+    0x19191919U, 0xb5b5b5b5U, 0x4a4a4a4aU, 0x0d0d0d0dU,
+    0x2d2d2d2dU, 0xe5e5e5e5U, 0x7a7a7a7aU, 0x9f9f9f9fU,
+    0x93939393U, 0xc9c9c9c9U, 0x9c9c9c9cU, 0xefefefefU,
+    0xa0a0a0a0U, 0xe0e0e0e0U, 0x3b3b3b3bU, 0x4d4d4d4dU,
+    0xaeaeaeaeU, 0x2a2a2a2aU, 0xf5f5f5f5U, 0xb0b0b0b0U,
+    0xc8c8c8c8U, 0xebebebebU, 0xbbbbbbbbU, 0x3c3c3c3cU,
+    0x83838383U, 0x53535353U, 0x99999999U, 0x61616161U,
+    0x17171717U, 0x2b2b2b2bU, 0x04040404U, 0x7e7e7e7eU,
+    0xbabababaU, 0x77777777U, 0xd6d6d6d6U, 0x26262626U,
+    0xe1e1e1e1U, 0x69696969U, 0x14141414U, 0x63636363U,
+    0x55555555U, 0x21212121U, 0x0c0c0c0cU, 0x7d7d7d7dU,
+}
+};
+
+
+const word32* AES::Te0 = AES::Te[0];
+const word32* AES::Te1 = AES::Te[1];
+const word32* AES::Te2 = AES::Te[2];
+const word32* AES::Te3 = AES::Te[3];
+const word32* AES::Te4 = AES::Te[4];
+
+const word32* AES::Td0 = AES::Td[0];
+const word32* AES::Td1 = AES::Td[1];
+const word32* AES::Td2 = AES::Td[2];
+const word32* AES::Td3 = AES::Td[3];
+const word32* AES::Td4 = AES::Td[4];
+
+
 
 } // namespace
 
diff --git a/extra/yassl/taocrypt/src/aestables.cpp b/extra/yassl/taocrypt/src/aestables.cpp
index 7ba25bc9ffb..af9924703ef 100644
--- a/extra/yassl/taocrypt/src/aestables.cpp
+++ b/extra/yassl/taocrypt/src/aestables.cpp
@@ -28,689 +28,6 @@
 namespace TaoCrypt {
 
 
-/*
-Te0[x] = S [x].[02, 01, 01, 03];
-Te1[x] = S [x].[03, 02, 01, 01];
-Te2[x] = S [x].[01, 03, 02, 01];
-Te3[x] = S [x].[01, 01, 03, 02];
-Te4[x] = S [x].[01, 01, 01, 01];
-
-Td0[x] = Si[x].[0e, 09, 0d, 0b];
-Td1[x] = Si[x].[0b, 0e, 09, 0d];
-Td2[x] = Si[x].[0d, 0b, 0e, 09];
-Td3[x] = Si[x].[09, 0d, 0b, 0e];
-Td4[x] = Si[x].[01, 01, 01, 01];
-*/
-
-const word32 AES::Te0[256] = {
-    0xc66363a5U, 0xf87c7c84U, 0xee777799U, 0xf67b7b8dU,
-    0xfff2f20dU, 0xd66b6bbdU, 0xde6f6fb1U, 0x91c5c554U,
-    0x60303050U, 0x02010103U, 0xce6767a9U, 0x562b2b7dU,
-    0xe7fefe19U, 0xb5d7d762U, 0x4dababe6U, 0xec76769aU,
-    0x8fcaca45U, 0x1f82829dU, 0x89c9c940U, 0xfa7d7d87U,
-    0xeffafa15U, 0xb25959ebU, 0x8e4747c9U, 0xfbf0f00bU,
-    0x41adadecU, 0xb3d4d467U, 0x5fa2a2fdU, 0x45afafeaU,
-    0x239c9cbfU, 0x53a4a4f7U, 0xe4727296U, 0x9bc0c05bU,
-    0x75b7b7c2U, 0xe1fdfd1cU, 0x3d9393aeU, 0x4c26266aU,
-    0x6c36365aU, 0x7e3f3f41U, 0xf5f7f702U, 0x83cccc4fU,
-    0x6834345cU, 0x51a5a5f4U, 0xd1e5e534U, 0xf9f1f108U,
-    0xe2717193U, 0xabd8d873U, 0x62313153U, 0x2a15153fU,
-    0x0804040cU, 0x95c7c752U, 0x46232365U, 0x9dc3c35eU,
-    0x30181828U, 0x379696a1U, 0x0a05050fU, 0x2f9a9ab5U,
-    0x0e070709U, 0x24121236U, 0x1b80809bU, 0xdfe2e23dU,
-    0xcdebeb26U, 0x4e272769U, 0x7fb2b2cdU, 0xea75759fU,
-    0x1209091bU, 0x1d83839eU, 0x582c2c74U, 0x341a1a2eU,
-    0x361b1b2dU, 0xdc6e6eb2U, 0xb45a5aeeU, 0x5ba0a0fbU,
-    0xa45252f6U, 0x763b3b4dU, 0xb7d6d661U, 0x7db3b3ceU,
-    0x5229297bU, 0xdde3e33eU, 0x5e2f2f71U, 0x13848497U,
-    0xa65353f5U, 0xb9d1d168U, 0x00000000U, 0xc1eded2cU,
-    0x40202060U, 0xe3fcfc1fU, 0x79b1b1c8U, 0xb65b5bedU,
-    0xd46a6abeU, 0x8dcbcb46U, 0x67bebed9U, 0x7239394bU,
-    0x944a4adeU, 0x984c4cd4U, 0xb05858e8U, 0x85cfcf4aU,
-    0xbbd0d06bU, 0xc5efef2aU, 0x4faaaae5U, 0xedfbfb16U,
-    0x864343c5U, 0x9a4d4dd7U, 0x66333355U, 0x11858594U,
-    0x8a4545cfU, 0xe9f9f910U, 0x04020206U, 0xfe7f7f81U,
-    0xa05050f0U, 0x783c3c44U, 0x259f9fbaU, 0x4ba8a8e3U,
-    0xa25151f3U, 0x5da3a3feU, 0x804040c0U, 0x058f8f8aU,
-    0x3f9292adU, 0x219d9dbcU, 0x70383848U, 0xf1f5f504U,
-    0x63bcbcdfU, 0x77b6b6c1U, 0xafdada75U, 0x42212163U,
-    0x20101030U, 0xe5ffff1aU, 0xfdf3f30eU, 0xbfd2d26dU,
-    0x81cdcd4cU, 0x180c0c14U, 0x26131335U, 0xc3ecec2fU,
-    0xbe5f5fe1U, 0x359797a2U, 0x884444ccU, 0x2e171739U,
-    0x93c4c457U, 0x55a7a7f2U, 0xfc7e7e82U, 0x7a3d3d47U,
-    0xc86464acU, 0xba5d5de7U, 0x3219192bU, 0xe6737395U,
-    0xc06060a0U, 0x19818198U, 0x9e4f4fd1U, 0xa3dcdc7fU,
-    0x44222266U, 0x542a2a7eU, 0x3b9090abU, 0x0b888883U,
-    0x8c4646caU, 0xc7eeee29U, 0x6bb8b8d3U, 0x2814143cU,
-    0xa7dede79U, 0xbc5e5ee2U, 0x160b0b1dU, 0xaddbdb76U,
-    0xdbe0e03bU, 0x64323256U, 0x743a3a4eU, 0x140a0a1eU,
-    0x924949dbU, 0x0c06060aU, 0x4824246cU, 0xb85c5ce4U,
-    0x9fc2c25dU, 0xbdd3d36eU, 0x43acacefU, 0xc46262a6U,
-    0x399191a8U, 0x319595a4U, 0xd3e4e437U, 0xf279798bU,
-    0xd5e7e732U, 0x8bc8c843U, 0x6e373759U, 0xda6d6db7U,
-    0x018d8d8cU, 0xb1d5d564U, 0x9c4e4ed2U, 0x49a9a9e0U,
-    0xd86c6cb4U, 0xac5656faU, 0xf3f4f407U, 0xcfeaea25U,
-    0xca6565afU, 0xf47a7a8eU, 0x47aeaee9U, 0x10080818U,
-    0x6fbabad5U, 0xf0787888U, 0x4a25256fU, 0x5c2e2e72U,
-    0x381c1c24U, 0x57a6a6f1U, 0x73b4b4c7U, 0x97c6c651U,
-    0xcbe8e823U, 0xa1dddd7cU, 0xe874749cU, 0x3e1f1f21U,
-    0x964b4bddU, 0x61bdbddcU, 0x0d8b8b86U, 0x0f8a8a85U,
-    0xe0707090U, 0x7c3e3e42U, 0x71b5b5c4U, 0xcc6666aaU,
-    0x904848d8U, 0x06030305U, 0xf7f6f601U, 0x1c0e0e12U,
-    0xc26161a3U, 0x6a35355fU, 0xae5757f9U, 0x69b9b9d0U,
-    0x17868691U, 0x99c1c158U, 0x3a1d1d27U, 0x279e9eb9U,
-    0xd9e1e138U, 0xebf8f813U, 0x2b9898b3U, 0x22111133U,
-    0xd26969bbU, 0xa9d9d970U, 0x078e8e89U, 0x339494a7U,
-    0x2d9b9bb6U, 0x3c1e1e22U, 0x15878792U, 0xc9e9e920U,
-    0x87cece49U, 0xaa5555ffU, 0x50282878U, 0xa5dfdf7aU,
-    0x038c8c8fU, 0x59a1a1f8U, 0x09898980U, 0x1a0d0d17U,
-    0x65bfbfdaU, 0xd7e6e631U, 0x844242c6U, 0xd06868b8U,
-    0x824141c3U, 0x299999b0U, 0x5a2d2d77U, 0x1e0f0f11U,
-    0x7bb0b0cbU, 0xa85454fcU, 0x6dbbbbd6U, 0x2c16163aU,
-};
-const word32 AES::Te1[256] = {
-    0xa5c66363U, 0x84f87c7cU, 0x99ee7777U, 0x8df67b7bU,
-    0x0dfff2f2U, 0xbdd66b6bU, 0xb1de6f6fU, 0x5491c5c5U,
-    0x50603030U, 0x03020101U, 0xa9ce6767U, 0x7d562b2bU,
-    0x19e7fefeU, 0x62b5d7d7U, 0xe64dababU, 0x9aec7676U,
-    0x458fcacaU, 0x9d1f8282U, 0x4089c9c9U, 0x87fa7d7dU,
-    0x15effafaU, 0xebb25959U, 0xc98e4747U, 0x0bfbf0f0U,
-    0xec41adadU, 0x67b3d4d4U, 0xfd5fa2a2U, 0xea45afafU,
-    0xbf239c9cU, 0xf753a4a4U, 0x96e47272U, 0x5b9bc0c0U,
-    0xc275b7b7U, 0x1ce1fdfdU, 0xae3d9393U, 0x6a4c2626U,
-    0x5a6c3636U, 0x417e3f3fU, 0x02f5f7f7U, 0x4f83ccccU,
-    0x5c683434U, 0xf451a5a5U, 0x34d1e5e5U, 0x08f9f1f1U,
-    0x93e27171U, 0x73abd8d8U, 0x53623131U, 0x3f2a1515U,
-    0x0c080404U, 0x5295c7c7U, 0x65462323U, 0x5e9dc3c3U,
-    0x28301818U, 0xa1379696U, 0x0f0a0505U, 0xb52f9a9aU,
-    0x090e0707U, 0x36241212U, 0x9b1b8080U, 0x3ddfe2e2U,
-    0x26cdebebU, 0x694e2727U, 0xcd7fb2b2U, 0x9fea7575U,
-    0x1b120909U, 0x9e1d8383U, 0x74582c2cU, 0x2e341a1aU,
-    0x2d361b1bU, 0xb2dc6e6eU, 0xeeb45a5aU, 0xfb5ba0a0U,
-    0xf6a45252U, 0x4d763b3bU, 0x61b7d6d6U, 0xce7db3b3U,
-    0x7b522929U, 0x3edde3e3U, 0x715e2f2fU, 0x97138484U,
-    0xf5a65353U, 0x68b9d1d1U, 0x00000000U, 0x2cc1ededU,
-    0x60402020U, 0x1fe3fcfcU, 0xc879b1b1U, 0xedb65b5bU,
-    0xbed46a6aU, 0x468dcbcbU, 0xd967bebeU, 0x4b723939U,
-    0xde944a4aU, 0xd4984c4cU, 0xe8b05858U, 0x4a85cfcfU,
-    0x6bbbd0d0U, 0x2ac5efefU, 0xe54faaaaU, 0x16edfbfbU,
-    0xc5864343U, 0xd79a4d4dU, 0x55663333U, 0x94118585U,
-    0xcf8a4545U, 0x10e9f9f9U, 0x06040202U, 0x81fe7f7fU,
-    0xf0a05050U, 0x44783c3cU, 0xba259f9fU, 0xe34ba8a8U,
-    0xf3a25151U, 0xfe5da3a3U, 0xc0804040U, 0x8a058f8fU,
-    0xad3f9292U, 0xbc219d9dU, 0x48703838U, 0x04f1f5f5U,
-    0xdf63bcbcU, 0xc177b6b6U, 0x75afdadaU, 0x63422121U,
-    0x30201010U, 0x1ae5ffffU, 0x0efdf3f3U, 0x6dbfd2d2U,
-    0x4c81cdcdU, 0x14180c0cU, 0x35261313U, 0x2fc3ececU,
-    0xe1be5f5fU, 0xa2359797U, 0xcc884444U, 0x392e1717U,
-    0x5793c4c4U, 0xf255a7a7U, 0x82fc7e7eU, 0x477a3d3dU,
-    0xacc86464U, 0xe7ba5d5dU, 0x2b321919U, 0x95e67373U,
-    0xa0c06060U, 0x98198181U, 0xd19e4f4fU, 0x7fa3dcdcU,
-    0x66442222U, 0x7e542a2aU, 0xab3b9090U, 0x830b8888U,
-    0xca8c4646U, 0x29c7eeeeU, 0xd36bb8b8U, 0x3c281414U,
-    0x79a7dedeU, 0xe2bc5e5eU, 0x1d160b0bU, 0x76addbdbU,
-    0x3bdbe0e0U, 0x56643232U, 0x4e743a3aU, 0x1e140a0aU,
-    0xdb924949U, 0x0a0c0606U, 0x6c482424U, 0xe4b85c5cU,
-    0x5d9fc2c2U, 0x6ebdd3d3U, 0xef43acacU, 0xa6c46262U,
-    0xa8399191U, 0xa4319595U, 0x37d3e4e4U, 0x8bf27979U,
-    0x32d5e7e7U, 0x438bc8c8U, 0x596e3737U, 0xb7da6d6dU,
-    0x8c018d8dU, 0x64b1d5d5U, 0xd29c4e4eU, 0xe049a9a9U,
-    0xb4d86c6cU, 0xfaac5656U, 0x07f3f4f4U, 0x25cfeaeaU,
-    0xafca6565U, 0x8ef47a7aU, 0xe947aeaeU, 0x18100808U,
-    0xd56fbabaU, 0x88f07878U, 0x6f4a2525U, 0x725c2e2eU,
-    0x24381c1cU, 0xf157a6a6U, 0xc773b4b4U, 0x5197c6c6U,
-    0x23cbe8e8U, 0x7ca1ddddU, 0x9ce87474U, 0x213e1f1fU,
-    0xdd964b4bU, 0xdc61bdbdU, 0x860d8b8bU, 0x850f8a8aU,
-    0x90e07070U, 0x427c3e3eU, 0xc471b5b5U, 0xaacc6666U,
-    0xd8904848U, 0x05060303U, 0x01f7f6f6U, 0x121c0e0eU,
-    0xa3c26161U, 0x5f6a3535U, 0xf9ae5757U, 0xd069b9b9U,
-    0x91178686U, 0x5899c1c1U, 0x273a1d1dU, 0xb9279e9eU,
-    0x38d9e1e1U, 0x13ebf8f8U, 0xb32b9898U, 0x33221111U,
-    0xbbd26969U, 0x70a9d9d9U, 0x89078e8eU, 0xa7339494U,
-    0xb62d9b9bU, 0x223c1e1eU, 0x92158787U, 0x20c9e9e9U,
-    0x4987ceceU, 0xffaa5555U, 0x78502828U, 0x7aa5dfdfU,
-    0x8f038c8cU, 0xf859a1a1U, 0x80098989U, 0x171a0d0dU,
-    0xda65bfbfU, 0x31d7e6e6U, 0xc6844242U, 0xb8d06868U,
-    0xc3824141U, 0xb0299999U, 0x775a2d2dU, 0x111e0f0fU,
-    0xcb7bb0b0U, 0xfca85454U, 0xd66dbbbbU, 0x3a2c1616U,
-};
-const word32 AES::Te2[256] = {
-    0x63a5c663U, 0x7c84f87cU, 0x7799ee77U, 0x7b8df67bU,
-    0xf20dfff2U, 0x6bbdd66bU, 0x6fb1de6fU, 0xc55491c5U,
-    0x30506030U, 0x01030201U, 0x67a9ce67U, 0x2b7d562bU,
-    0xfe19e7feU, 0xd762b5d7U, 0xabe64dabU, 0x769aec76U,
-    0xca458fcaU, 0x829d1f82U, 0xc94089c9U, 0x7d87fa7dU,
-    0xfa15effaU, 0x59ebb259U, 0x47c98e47U, 0xf00bfbf0U,
-    0xadec41adU, 0xd467b3d4U, 0xa2fd5fa2U, 0xafea45afU,
-    0x9cbf239cU, 0xa4f753a4U, 0x7296e472U, 0xc05b9bc0U,
-    0xb7c275b7U, 0xfd1ce1fdU, 0x93ae3d93U, 0x266a4c26U,
-    0x365a6c36U, 0x3f417e3fU, 0xf702f5f7U, 0xcc4f83ccU,
-    0x345c6834U, 0xa5f451a5U, 0xe534d1e5U, 0xf108f9f1U,
-    0x7193e271U, 0xd873abd8U, 0x31536231U, 0x153f2a15U,
-    0x040c0804U, 0xc75295c7U, 0x23654623U, 0xc35e9dc3U,
-    0x18283018U, 0x96a13796U, 0x050f0a05U, 0x9ab52f9aU,
-    0x07090e07U, 0x12362412U, 0x809b1b80U, 0xe23ddfe2U,
-    0xeb26cdebU, 0x27694e27U, 0xb2cd7fb2U, 0x759fea75U,
-    0x091b1209U, 0x839e1d83U, 0x2c74582cU, 0x1a2e341aU,
-    0x1b2d361bU, 0x6eb2dc6eU, 0x5aeeb45aU, 0xa0fb5ba0U,
-    0x52f6a452U, 0x3b4d763bU, 0xd661b7d6U, 0xb3ce7db3U,
-    0x297b5229U, 0xe33edde3U, 0x2f715e2fU, 0x84971384U,
-    0x53f5a653U, 0xd168b9d1U, 0x00000000U, 0xed2cc1edU,
-    0x20604020U, 0xfc1fe3fcU, 0xb1c879b1U, 0x5bedb65bU,
-    0x6abed46aU, 0xcb468dcbU, 0xbed967beU, 0x394b7239U,
-    0x4ade944aU, 0x4cd4984cU, 0x58e8b058U, 0xcf4a85cfU,
-    0xd06bbbd0U, 0xef2ac5efU, 0xaae54faaU, 0xfb16edfbU,
-    0x43c58643U, 0x4dd79a4dU, 0x33556633U, 0x85941185U,
-    0x45cf8a45U, 0xf910e9f9U, 0x02060402U, 0x7f81fe7fU,
-    0x50f0a050U, 0x3c44783cU, 0x9fba259fU, 0xa8e34ba8U,
-    0x51f3a251U, 0xa3fe5da3U, 0x40c08040U, 0x8f8a058fU,
-    0x92ad3f92U, 0x9dbc219dU, 0x38487038U, 0xf504f1f5U,
-    0xbcdf63bcU, 0xb6c177b6U, 0xda75afdaU, 0x21634221U,
-    0x10302010U, 0xff1ae5ffU, 0xf30efdf3U, 0xd26dbfd2U,
-    0xcd4c81cdU, 0x0c14180cU, 0x13352613U, 0xec2fc3ecU,
-    0x5fe1be5fU, 0x97a23597U, 0x44cc8844U, 0x17392e17U,
-    0xc45793c4U, 0xa7f255a7U, 0x7e82fc7eU, 0x3d477a3dU,
-    0x64acc864U, 0x5de7ba5dU, 0x192b3219U, 0x7395e673U,
-    0x60a0c060U, 0x81981981U, 0x4fd19e4fU, 0xdc7fa3dcU,
-    0x22664422U, 0x2a7e542aU, 0x90ab3b90U, 0x88830b88U,
-    0x46ca8c46U, 0xee29c7eeU, 0xb8d36bb8U, 0x143c2814U,
-    0xde79a7deU, 0x5ee2bc5eU, 0x0b1d160bU, 0xdb76addbU,
-    0xe03bdbe0U, 0x32566432U, 0x3a4e743aU, 0x0a1e140aU,
-    0x49db9249U, 0x060a0c06U, 0x246c4824U, 0x5ce4b85cU,
-    0xc25d9fc2U, 0xd36ebdd3U, 0xacef43acU, 0x62a6c462U,
-    0x91a83991U, 0x95a43195U, 0xe437d3e4U, 0x798bf279U,
-    0xe732d5e7U, 0xc8438bc8U, 0x37596e37U, 0x6db7da6dU,
-    0x8d8c018dU, 0xd564b1d5U, 0x4ed29c4eU, 0xa9e049a9U,
-    0x6cb4d86cU, 0x56faac56U, 0xf407f3f4U, 0xea25cfeaU,
-    0x65afca65U, 0x7a8ef47aU, 0xaee947aeU, 0x08181008U,
-    0xbad56fbaU, 0x7888f078U, 0x256f4a25U, 0x2e725c2eU,
-    0x1c24381cU, 0xa6f157a6U, 0xb4c773b4U, 0xc65197c6U,
-    0xe823cbe8U, 0xdd7ca1ddU, 0x749ce874U, 0x1f213e1fU,
-    0x4bdd964bU, 0xbddc61bdU, 0x8b860d8bU, 0x8a850f8aU,
-    0x7090e070U, 0x3e427c3eU, 0xb5c471b5U, 0x66aacc66U,
-    0x48d89048U, 0x03050603U, 0xf601f7f6U, 0x0e121c0eU,
-    0x61a3c261U, 0x355f6a35U, 0x57f9ae57U, 0xb9d069b9U,
-    0x86911786U, 0xc15899c1U, 0x1d273a1dU, 0x9eb9279eU,
-    0xe138d9e1U, 0xf813ebf8U, 0x98b32b98U, 0x11332211U,
-    0x69bbd269U, 0xd970a9d9U, 0x8e89078eU, 0x94a73394U,
-    0x9bb62d9bU, 0x1e223c1eU, 0x87921587U, 0xe920c9e9U,
-    0xce4987ceU, 0x55ffaa55U, 0x28785028U, 0xdf7aa5dfU,
-    0x8c8f038cU, 0xa1f859a1U, 0x89800989U, 0x0d171a0dU,
-    0xbfda65bfU, 0xe631d7e6U, 0x42c68442U, 0x68b8d068U,
-    0x41c38241U, 0x99b02999U, 0x2d775a2dU, 0x0f111e0fU,
-    0xb0cb7bb0U, 0x54fca854U, 0xbbd66dbbU, 0x163a2c16U,
-};
-
-const word32 AES::Te3[256] = {
-    0x6363a5c6U, 0x7c7c84f8U, 0x777799eeU, 0x7b7b8df6U,
-    0xf2f20dffU, 0x6b6bbdd6U, 0x6f6fb1deU, 0xc5c55491U,
-    0x30305060U, 0x01010302U, 0x6767a9ceU, 0x2b2b7d56U,
-    0xfefe19e7U, 0xd7d762b5U, 0xababe64dU, 0x76769aecU,
-    0xcaca458fU, 0x82829d1fU, 0xc9c94089U, 0x7d7d87faU,
-    0xfafa15efU, 0x5959ebb2U, 0x4747c98eU, 0xf0f00bfbU,
-    0xadadec41U, 0xd4d467b3U, 0xa2a2fd5fU, 0xafafea45U,
-    0x9c9cbf23U, 0xa4a4f753U, 0x727296e4U, 0xc0c05b9bU,
-    0xb7b7c275U, 0xfdfd1ce1U, 0x9393ae3dU, 0x26266a4cU,
-    0x36365a6cU, 0x3f3f417eU, 0xf7f702f5U, 0xcccc4f83U,
-    0x34345c68U, 0xa5a5f451U, 0xe5e534d1U, 0xf1f108f9U,
-    0x717193e2U, 0xd8d873abU, 0x31315362U, 0x15153f2aU,
-    0x04040c08U, 0xc7c75295U, 0x23236546U, 0xc3c35e9dU,
-    0x18182830U, 0x9696a137U, 0x05050f0aU, 0x9a9ab52fU,
-    0x0707090eU, 0x12123624U, 0x80809b1bU, 0xe2e23ddfU,
-    0xebeb26cdU, 0x2727694eU, 0xb2b2cd7fU, 0x75759feaU,
-    0x09091b12U, 0x83839e1dU, 0x2c2c7458U, 0x1a1a2e34U,
-    0x1b1b2d36U, 0x6e6eb2dcU, 0x5a5aeeb4U, 0xa0a0fb5bU,
-    0x5252f6a4U, 0x3b3b4d76U, 0xd6d661b7U, 0xb3b3ce7dU,
-    0x29297b52U, 0xe3e33eddU, 0x2f2f715eU, 0x84849713U,
-    0x5353f5a6U, 0xd1d168b9U, 0x00000000U, 0xeded2cc1U,
-    0x20206040U, 0xfcfc1fe3U, 0xb1b1c879U, 0x5b5bedb6U,
-    0x6a6abed4U, 0xcbcb468dU, 0xbebed967U, 0x39394b72U,
-    0x4a4ade94U, 0x4c4cd498U, 0x5858e8b0U, 0xcfcf4a85U,
-    0xd0d06bbbU, 0xefef2ac5U, 0xaaaae54fU, 0xfbfb16edU,
-    0x4343c586U, 0x4d4dd79aU, 0x33335566U, 0x85859411U,
-    0x4545cf8aU, 0xf9f910e9U, 0x02020604U, 0x7f7f81feU,
-    0x5050f0a0U, 0x3c3c4478U, 0x9f9fba25U, 0xa8a8e34bU,
-    0x5151f3a2U, 0xa3a3fe5dU, 0x4040c080U, 0x8f8f8a05U,
-    0x9292ad3fU, 0x9d9dbc21U, 0x38384870U, 0xf5f504f1U,
-    0xbcbcdf63U, 0xb6b6c177U, 0xdada75afU, 0x21216342U,
-    0x10103020U, 0xffff1ae5U, 0xf3f30efdU, 0xd2d26dbfU,
-    0xcdcd4c81U, 0x0c0c1418U, 0x13133526U, 0xecec2fc3U,
-    0x5f5fe1beU, 0x9797a235U, 0x4444cc88U, 0x1717392eU,
-    0xc4c45793U, 0xa7a7f255U, 0x7e7e82fcU, 0x3d3d477aU,
-    0x6464acc8U, 0x5d5de7baU, 0x19192b32U, 0x737395e6U,
-    0x6060a0c0U, 0x81819819U, 0x4f4fd19eU, 0xdcdc7fa3U,
-    0x22226644U, 0x2a2a7e54U, 0x9090ab3bU, 0x8888830bU,
-    0x4646ca8cU, 0xeeee29c7U, 0xb8b8d36bU, 0x14143c28U,
-    0xdede79a7U, 0x5e5ee2bcU, 0x0b0b1d16U, 0xdbdb76adU,
-    0xe0e03bdbU, 0x32325664U, 0x3a3a4e74U, 0x0a0a1e14U,
-    0x4949db92U, 0x06060a0cU, 0x24246c48U, 0x5c5ce4b8U,
-    0xc2c25d9fU, 0xd3d36ebdU, 0xacacef43U, 0x6262a6c4U,
-    0x9191a839U, 0x9595a431U, 0xe4e437d3U, 0x79798bf2U,
-    0xe7e732d5U, 0xc8c8438bU, 0x3737596eU, 0x6d6db7daU,
-    0x8d8d8c01U, 0xd5d564b1U, 0x4e4ed29cU, 0xa9a9e049U,
-    0x6c6cb4d8U, 0x5656faacU, 0xf4f407f3U, 0xeaea25cfU,
-    0x6565afcaU, 0x7a7a8ef4U, 0xaeaee947U, 0x08081810U,
-    0xbabad56fU, 0x787888f0U, 0x25256f4aU, 0x2e2e725cU,
-    0x1c1c2438U, 0xa6a6f157U, 0xb4b4c773U, 0xc6c65197U,
-    0xe8e823cbU, 0xdddd7ca1U, 0x74749ce8U, 0x1f1f213eU,
-    0x4b4bdd96U, 0xbdbddc61U, 0x8b8b860dU, 0x8a8a850fU,
-    0x707090e0U, 0x3e3e427cU, 0xb5b5c471U, 0x6666aaccU,
-    0x4848d890U, 0x03030506U, 0xf6f601f7U, 0x0e0e121cU,
-    0x6161a3c2U, 0x35355f6aU, 0x5757f9aeU, 0xb9b9d069U,
-    0x86869117U, 0xc1c15899U, 0x1d1d273aU, 0x9e9eb927U,
-    0xe1e138d9U, 0xf8f813ebU, 0x9898b32bU, 0x11113322U,
-    0x6969bbd2U, 0xd9d970a9U, 0x8e8e8907U, 0x9494a733U,
-    0x9b9bb62dU, 0x1e1e223cU, 0x87879215U, 0xe9e920c9U,
-    0xcece4987U, 0x5555ffaaU, 0x28287850U, 0xdfdf7aa5U,
-    0x8c8c8f03U, 0xa1a1f859U, 0x89898009U, 0x0d0d171aU,
-    0xbfbfda65U, 0xe6e631d7U, 0x4242c684U, 0x6868b8d0U,
-    0x4141c382U, 0x9999b029U, 0x2d2d775aU, 0x0f0f111eU,
-    0xb0b0cb7bU, 0x5454fca8U, 0xbbbbd66dU, 0x16163a2cU,
-};
-
-const word32 AES::Te4[256] = {
-    0x63636363U, 0x7c7c7c7cU, 0x77777777U, 0x7b7b7b7bU,
-    0xf2f2f2f2U, 0x6b6b6b6bU, 0x6f6f6f6fU, 0xc5c5c5c5U,
-    0x30303030U, 0x01010101U, 0x67676767U, 0x2b2b2b2bU,
-    0xfefefefeU, 0xd7d7d7d7U, 0xababababU, 0x76767676U,
-    0xcacacacaU, 0x82828282U, 0xc9c9c9c9U, 0x7d7d7d7dU,
-    0xfafafafaU, 0x59595959U, 0x47474747U, 0xf0f0f0f0U,
-    0xadadadadU, 0xd4d4d4d4U, 0xa2a2a2a2U, 0xafafafafU,
-    0x9c9c9c9cU, 0xa4a4a4a4U, 0x72727272U, 0xc0c0c0c0U,
-    0xb7b7b7b7U, 0xfdfdfdfdU, 0x93939393U, 0x26262626U,
-    0x36363636U, 0x3f3f3f3fU, 0xf7f7f7f7U, 0xccccccccU,
-    0x34343434U, 0xa5a5a5a5U, 0xe5e5e5e5U, 0xf1f1f1f1U,
-    0x71717171U, 0xd8d8d8d8U, 0x31313131U, 0x15151515U,
-    0x04040404U, 0xc7c7c7c7U, 0x23232323U, 0xc3c3c3c3U,
-    0x18181818U, 0x96969696U, 0x05050505U, 0x9a9a9a9aU,
-    0x07070707U, 0x12121212U, 0x80808080U, 0xe2e2e2e2U,
-    0xebebebebU, 0x27272727U, 0xb2b2b2b2U, 0x75757575U,
-    0x09090909U, 0x83838383U, 0x2c2c2c2cU, 0x1a1a1a1aU,
-    0x1b1b1b1bU, 0x6e6e6e6eU, 0x5a5a5a5aU, 0xa0a0a0a0U,
-    0x52525252U, 0x3b3b3b3bU, 0xd6d6d6d6U, 0xb3b3b3b3U,
-    0x29292929U, 0xe3e3e3e3U, 0x2f2f2f2fU, 0x84848484U,
-    0x53535353U, 0xd1d1d1d1U, 0x00000000U, 0xededededU,
-    0x20202020U, 0xfcfcfcfcU, 0xb1b1b1b1U, 0x5b5b5b5bU,
-    0x6a6a6a6aU, 0xcbcbcbcbU, 0xbebebebeU, 0x39393939U,
-    0x4a4a4a4aU, 0x4c4c4c4cU, 0x58585858U, 0xcfcfcfcfU,
-    0xd0d0d0d0U, 0xefefefefU, 0xaaaaaaaaU, 0xfbfbfbfbU,
-    0x43434343U, 0x4d4d4d4dU, 0x33333333U, 0x85858585U,
-    0x45454545U, 0xf9f9f9f9U, 0x02020202U, 0x7f7f7f7fU,
-    0x50505050U, 0x3c3c3c3cU, 0x9f9f9f9fU, 0xa8a8a8a8U,
-    0x51515151U, 0xa3a3a3a3U, 0x40404040U, 0x8f8f8f8fU,
-    0x92929292U, 0x9d9d9d9dU, 0x38383838U, 0xf5f5f5f5U,
-    0xbcbcbcbcU, 0xb6b6b6b6U, 0xdadadadaU, 0x21212121U,
-    0x10101010U, 0xffffffffU, 0xf3f3f3f3U, 0xd2d2d2d2U,
-    0xcdcdcdcdU, 0x0c0c0c0cU, 0x13131313U, 0xececececU,
-    0x5f5f5f5fU, 0x97979797U, 0x44444444U, 0x17171717U,
-    0xc4c4c4c4U, 0xa7a7a7a7U, 0x7e7e7e7eU, 0x3d3d3d3dU,
-    0x64646464U, 0x5d5d5d5dU, 0x19191919U, 0x73737373U,
-    0x60606060U, 0x81818181U, 0x4f4f4f4fU, 0xdcdcdcdcU,
-    0x22222222U, 0x2a2a2a2aU, 0x90909090U, 0x88888888U,
-    0x46464646U, 0xeeeeeeeeU, 0xb8b8b8b8U, 0x14141414U,
-    0xdedededeU, 0x5e5e5e5eU, 0x0b0b0b0bU, 0xdbdbdbdbU,
-    0xe0e0e0e0U, 0x32323232U, 0x3a3a3a3aU, 0x0a0a0a0aU,
-    0x49494949U, 0x06060606U, 0x24242424U, 0x5c5c5c5cU,
-    0xc2c2c2c2U, 0xd3d3d3d3U, 0xacacacacU, 0x62626262U,
-    0x91919191U, 0x95959595U, 0xe4e4e4e4U, 0x79797979U,
-    0xe7e7e7e7U, 0xc8c8c8c8U, 0x37373737U, 0x6d6d6d6dU,
-    0x8d8d8d8dU, 0xd5d5d5d5U, 0x4e4e4e4eU, 0xa9a9a9a9U,
-    0x6c6c6c6cU, 0x56565656U, 0xf4f4f4f4U, 0xeaeaeaeaU,
-    0x65656565U, 0x7a7a7a7aU, 0xaeaeaeaeU, 0x08080808U,
-    0xbabababaU, 0x78787878U, 0x25252525U, 0x2e2e2e2eU,
-    0x1c1c1c1cU, 0xa6a6a6a6U, 0xb4b4b4b4U, 0xc6c6c6c6U,
-    0xe8e8e8e8U, 0xddddddddU, 0x74747474U, 0x1f1f1f1fU,
-    0x4b4b4b4bU, 0xbdbdbdbdU, 0x8b8b8b8bU, 0x8a8a8a8aU,
-    0x70707070U, 0x3e3e3e3eU, 0xb5b5b5b5U, 0x66666666U,
-    0x48484848U, 0x03030303U, 0xf6f6f6f6U, 0x0e0e0e0eU,
-    0x61616161U, 0x35353535U, 0x57575757U, 0xb9b9b9b9U,
-    0x86868686U, 0xc1c1c1c1U, 0x1d1d1d1dU, 0x9e9e9e9eU,
-    0xe1e1e1e1U, 0xf8f8f8f8U, 0x98989898U, 0x11111111U,
-    0x69696969U, 0xd9d9d9d9U, 0x8e8e8e8eU, 0x94949494U,
-    0x9b9b9b9bU, 0x1e1e1e1eU, 0x87878787U, 0xe9e9e9e9U,
-    0xcecececeU, 0x55555555U, 0x28282828U, 0xdfdfdfdfU,
-    0x8c8c8c8cU, 0xa1a1a1a1U, 0x89898989U, 0x0d0d0d0dU,
-    0xbfbfbfbfU, 0xe6e6e6e6U, 0x42424242U, 0x68686868U,
-    0x41414141U, 0x99999999U, 0x2d2d2d2dU, 0x0f0f0f0fU,
-    0xb0b0b0b0U, 0x54545454U, 0xbbbbbbbbU, 0x16161616U,
-};
-
-const word32 AES::Td0[256] = {
-    0x51f4a750U, 0x7e416553U, 0x1a17a4c3U, 0x3a275e96U,
-    0x3bab6bcbU, 0x1f9d45f1U, 0xacfa58abU, 0x4be30393U,
-    0x2030fa55U, 0xad766df6U, 0x88cc7691U, 0xf5024c25U,
-    0x4fe5d7fcU, 0xc52acbd7U, 0x26354480U, 0xb562a38fU,
-    0xdeb15a49U, 0x25ba1b67U, 0x45ea0e98U, 0x5dfec0e1U,
-    0xc32f7502U, 0x814cf012U, 0x8d4697a3U, 0x6bd3f9c6U,
-    0x038f5fe7U, 0x15929c95U, 0xbf6d7aebU, 0x955259daU,
-    0xd4be832dU, 0x587421d3U, 0x49e06929U, 0x8ec9c844U,
-    0x75c2896aU, 0xf48e7978U, 0x99583e6bU, 0x27b971ddU,
-    0xbee14fb6U, 0xf088ad17U, 0xc920ac66U, 0x7dce3ab4U,
-    0x63df4a18U, 0xe51a3182U, 0x97513360U, 0x62537f45U,
-    0xb16477e0U, 0xbb6bae84U, 0xfe81a01cU, 0xf9082b94U,
-    0x70486858U, 0x8f45fd19U, 0x94de6c87U, 0x527bf8b7U,
-    0xab73d323U, 0x724b02e2U, 0xe31f8f57U, 0x6655ab2aU,
-    0xb2eb2807U, 0x2fb5c203U, 0x86c57b9aU, 0xd33708a5U,
-    0x302887f2U, 0x23bfa5b2U, 0x02036abaU, 0xed16825cU,
-    0x8acf1c2bU, 0xa779b492U, 0xf307f2f0U, 0x4e69e2a1U,
-    0x65daf4cdU, 0x0605bed5U, 0xd134621fU, 0xc4a6fe8aU,
-    0x342e539dU, 0xa2f355a0U, 0x058ae132U, 0xa4f6eb75U,
-    0x0b83ec39U, 0x4060efaaU, 0x5e719f06U, 0xbd6e1051U,
-    0x3e218af9U, 0x96dd063dU, 0xdd3e05aeU, 0x4de6bd46U,
-    0x91548db5U, 0x71c45d05U, 0x0406d46fU, 0x605015ffU,
-    0x1998fb24U, 0xd6bde997U, 0x894043ccU, 0x67d99e77U,
-    0xb0e842bdU, 0x07898b88U, 0xe7195b38U, 0x79c8eedbU,
-    0xa17c0a47U, 0x7c420fe9U, 0xf8841ec9U, 0x00000000U,
-    0x09808683U, 0x322bed48U, 0x1e1170acU, 0x6c5a724eU,
-    0xfd0efffbU, 0x0f853856U, 0x3daed51eU, 0x362d3927U,
-    0x0a0fd964U, 0x685ca621U, 0x9b5b54d1U, 0x24362e3aU,
-    0x0c0a67b1U, 0x9357e70fU, 0xb4ee96d2U, 0x1b9b919eU,
-    0x80c0c54fU, 0x61dc20a2U, 0x5a774b69U, 0x1c121a16U,
-    0xe293ba0aU, 0xc0a02ae5U, 0x3c22e043U, 0x121b171dU,
-    0x0e090d0bU, 0xf28bc7adU, 0x2db6a8b9U, 0x141ea9c8U,
-    0x57f11985U, 0xaf75074cU, 0xee99ddbbU, 0xa37f60fdU,
-    0xf701269fU, 0x5c72f5bcU, 0x44663bc5U, 0x5bfb7e34U,
-    0x8b432976U, 0xcb23c6dcU, 0xb6edfc68U, 0xb8e4f163U,
-    0xd731dccaU, 0x42638510U, 0x13972240U, 0x84c61120U,
-    0x854a247dU, 0xd2bb3df8U, 0xaef93211U, 0xc729a16dU,
-    0x1d9e2f4bU, 0xdcb230f3U, 0x0d8652ecU, 0x77c1e3d0U,
-    0x2bb3166cU, 0xa970b999U, 0x119448faU, 0x47e96422U,
-    0xa8fc8cc4U, 0xa0f03f1aU, 0x567d2cd8U, 0x223390efU,
-    0x87494ec7U, 0xd938d1c1U, 0x8ccaa2feU, 0x98d40b36U,
-    0xa6f581cfU, 0xa57ade28U, 0xdab78e26U, 0x3fadbfa4U,
-    0x2c3a9de4U, 0x5078920dU, 0x6a5fcc9bU, 0x547e4662U,
-    0xf68d13c2U, 0x90d8b8e8U, 0x2e39f75eU, 0x82c3aff5U,
-    0x9f5d80beU, 0x69d0937cU, 0x6fd52da9U, 0xcf2512b3U,
-    0xc8ac993bU, 0x10187da7U, 0xe89c636eU, 0xdb3bbb7bU,
-    0xcd267809U, 0x6e5918f4U, 0xec9ab701U, 0x834f9aa8U,
-    0xe6956e65U, 0xaaffe67eU, 0x21bccf08U, 0xef15e8e6U,
-    0xbae79bd9U, 0x4a6f36ceU, 0xea9f09d4U, 0x29b07cd6U,
-    0x31a4b2afU, 0x2a3f2331U, 0xc6a59430U, 0x35a266c0U,
-    0x744ebc37U, 0xfc82caa6U, 0xe090d0b0U, 0x33a7d815U,
-    0xf104984aU, 0x41ecdaf7U, 0x7fcd500eU, 0x1791f62fU,
-    0x764dd68dU, 0x43efb04dU, 0xccaa4d54U, 0xe49604dfU,
-    0x9ed1b5e3U, 0x4c6a881bU, 0xc12c1fb8U, 0x4665517fU,
-    0x9d5eea04U, 0x018c355dU, 0xfa877473U, 0xfb0b412eU,
-    0xb3671d5aU, 0x92dbd252U, 0xe9105633U, 0x6dd64713U,
-    0x9ad7618cU, 0x37a10c7aU, 0x59f8148eU, 0xeb133c89U,
-    0xcea927eeU, 0xb761c935U, 0xe11ce5edU, 0x7a47b13cU,
-    0x9cd2df59U, 0x55f2733fU, 0x1814ce79U, 0x73c737bfU,
-    0x53f7cdeaU, 0x5ffdaa5bU, 0xdf3d6f14U, 0x7844db86U,
-    0xcaaff381U, 0xb968c43eU, 0x3824342cU, 0xc2a3405fU,
-    0x161dc372U, 0xbce2250cU, 0x283c498bU, 0xff0d9541U,
-    0x39a80171U, 0x080cb3deU, 0xd8b4e49cU, 0x6456c190U,
-    0x7bcb8461U, 0xd532b670U, 0x486c5c74U, 0xd0b85742U,
-};
-
-const word32 AES::Td1[256] = {
-    0x5051f4a7U, 0x537e4165U, 0xc31a17a4U, 0x963a275eU,
-    0xcb3bab6bU, 0xf11f9d45U, 0xabacfa58U, 0x934be303U,
-    0x552030faU, 0xf6ad766dU, 0x9188cc76U, 0x25f5024cU,
-    0xfc4fe5d7U, 0xd7c52acbU, 0x80263544U, 0x8fb562a3U,
-    0x49deb15aU, 0x6725ba1bU, 0x9845ea0eU, 0xe15dfec0U,
-    0x02c32f75U, 0x12814cf0U, 0xa38d4697U, 0xc66bd3f9U,
-    0xe7038f5fU, 0x9515929cU, 0xebbf6d7aU, 0xda955259U,
-    0x2dd4be83U, 0xd3587421U, 0x2949e069U, 0x448ec9c8U,
-    0x6a75c289U, 0x78f48e79U, 0x6b99583eU, 0xdd27b971U,
-    0xb6bee14fU, 0x17f088adU, 0x66c920acU, 0xb47dce3aU,
-    0x1863df4aU, 0x82e51a31U, 0x60975133U, 0x4562537fU,
-    0xe0b16477U, 0x84bb6baeU, 0x1cfe81a0U, 0x94f9082bU,
-    0x58704868U, 0x198f45fdU, 0x8794de6cU, 0xb7527bf8U,
-    0x23ab73d3U, 0xe2724b02U, 0x57e31f8fU, 0x2a6655abU,
-    0x07b2eb28U, 0x032fb5c2U, 0x9a86c57bU, 0xa5d33708U,
-    0xf2302887U, 0xb223bfa5U, 0xba02036aU, 0x5ced1682U,
-    0x2b8acf1cU, 0x92a779b4U, 0xf0f307f2U, 0xa14e69e2U,
-    0xcd65daf4U, 0xd50605beU, 0x1fd13462U, 0x8ac4a6feU,
-    0x9d342e53U, 0xa0a2f355U, 0x32058ae1U, 0x75a4f6ebU,
-    0x390b83ecU, 0xaa4060efU, 0x065e719fU, 0x51bd6e10U,
-    0xf93e218aU, 0x3d96dd06U, 0xaedd3e05U, 0x464de6bdU,
-    0xb591548dU, 0x0571c45dU, 0x6f0406d4U, 0xff605015U,
-    0x241998fbU, 0x97d6bde9U, 0xcc894043U, 0x7767d99eU,
-    0xbdb0e842U, 0x8807898bU, 0x38e7195bU, 0xdb79c8eeU,
-    0x47a17c0aU, 0xe97c420fU, 0xc9f8841eU, 0x00000000U,
-    0x83098086U, 0x48322bedU, 0xac1e1170U, 0x4e6c5a72U,
-    0xfbfd0effU, 0x560f8538U, 0x1e3daed5U, 0x27362d39U,
-    0x640a0fd9U, 0x21685ca6U, 0xd19b5b54U, 0x3a24362eU,
-    0xb10c0a67U, 0x0f9357e7U, 0xd2b4ee96U, 0x9e1b9b91U,
-    0x4f80c0c5U, 0xa261dc20U, 0x695a774bU, 0x161c121aU,
-    0x0ae293baU, 0xe5c0a02aU, 0x433c22e0U, 0x1d121b17U,
-    0x0b0e090dU, 0xadf28bc7U, 0xb92db6a8U, 0xc8141ea9U,
-    0x8557f119U, 0x4caf7507U, 0xbbee99ddU, 0xfda37f60U,
-    0x9ff70126U, 0xbc5c72f5U, 0xc544663bU, 0x345bfb7eU,
-    0x768b4329U, 0xdccb23c6U, 0x68b6edfcU, 0x63b8e4f1U,
-    0xcad731dcU, 0x10426385U, 0x40139722U, 0x2084c611U,
-    0x7d854a24U, 0xf8d2bb3dU, 0x11aef932U, 0x6dc729a1U,
-    0x4b1d9e2fU, 0xf3dcb230U, 0xec0d8652U, 0xd077c1e3U,
-    0x6c2bb316U, 0x99a970b9U, 0xfa119448U, 0x2247e964U,
-    0xc4a8fc8cU, 0x1aa0f03fU, 0xd8567d2cU, 0xef223390U,
-    0xc787494eU, 0xc1d938d1U, 0xfe8ccaa2U, 0x3698d40bU,
-    0xcfa6f581U, 0x28a57adeU, 0x26dab78eU, 0xa43fadbfU,
-    0xe42c3a9dU, 0x0d507892U, 0x9b6a5fccU, 0x62547e46U,
-    0xc2f68d13U, 0xe890d8b8U, 0x5e2e39f7U, 0xf582c3afU,
-    0xbe9f5d80U, 0x7c69d093U, 0xa96fd52dU, 0xb3cf2512U,
-    0x3bc8ac99U, 0xa710187dU, 0x6ee89c63U, 0x7bdb3bbbU,
-    0x09cd2678U, 0xf46e5918U, 0x01ec9ab7U, 0xa8834f9aU,
-    0x65e6956eU, 0x7eaaffe6U, 0x0821bccfU, 0xe6ef15e8U,
-    0xd9bae79bU, 0xce4a6f36U, 0xd4ea9f09U, 0xd629b07cU,
-    0xaf31a4b2U, 0x312a3f23U, 0x30c6a594U, 0xc035a266U,
-    0x37744ebcU, 0xa6fc82caU, 0xb0e090d0U, 0x1533a7d8U,
-    0x4af10498U, 0xf741ecdaU, 0x0e7fcd50U, 0x2f1791f6U,
-    0x8d764dd6U, 0x4d43efb0U, 0x54ccaa4dU, 0xdfe49604U,
-    0xe39ed1b5U, 0x1b4c6a88U, 0xb8c12c1fU, 0x7f466551U,
-    0x049d5eeaU, 0x5d018c35U, 0x73fa8774U, 0x2efb0b41U,
-    0x5ab3671dU, 0x5292dbd2U, 0x33e91056U, 0x136dd647U,
-    0x8c9ad761U, 0x7a37a10cU, 0x8e59f814U, 0x89eb133cU,
-    0xeecea927U, 0x35b761c9U, 0xede11ce5U, 0x3c7a47b1U,
-    0x599cd2dfU, 0x3f55f273U, 0x791814ceU, 0xbf73c737U,
-    0xea53f7cdU, 0x5b5ffdaaU, 0x14df3d6fU, 0x867844dbU,
-    0x81caaff3U, 0x3eb968c4U, 0x2c382434U, 0x5fc2a340U,
-    0x72161dc3U, 0x0cbce225U, 0x8b283c49U, 0x41ff0d95U,
-    0x7139a801U, 0xde080cb3U, 0x9cd8b4e4U, 0x906456c1U,
-    0x617bcb84U, 0x70d532b6U, 0x74486c5cU, 0x42d0b857U,
-};
-
-const word32 AES::Td2[256] = {
-    0xa75051f4U, 0x65537e41U, 0xa4c31a17U, 0x5e963a27U,
-    0x6bcb3babU, 0x45f11f9dU, 0x58abacfaU, 0x03934be3U,
-    0xfa552030U, 0x6df6ad76U, 0x769188ccU, 0x4c25f502U,
-    0xd7fc4fe5U, 0xcbd7c52aU, 0x44802635U, 0xa38fb562U,
-    0x5a49deb1U, 0x1b6725baU, 0x0e9845eaU, 0xc0e15dfeU,
-    0x7502c32fU, 0xf012814cU, 0x97a38d46U, 0xf9c66bd3U,
-    0x5fe7038fU, 0x9c951592U, 0x7aebbf6dU, 0x59da9552U,
-    0x832dd4beU, 0x21d35874U, 0x692949e0U, 0xc8448ec9U,
-    0x896a75c2U, 0x7978f48eU, 0x3e6b9958U, 0x71dd27b9U,
-    0x4fb6bee1U, 0xad17f088U, 0xac66c920U, 0x3ab47dceU,
-    0x4a1863dfU, 0x3182e51aU, 0x33609751U, 0x7f456253U,
-    0x77e0b164U, 0xae84bb6bU, 0xa01cfe81U, 0x2b94f908U,
-    0x68587048U, 0xfd198f45U, 0x6c8794deU, 0xf8b7527bU,
-    0xd323ab73U, 0x02e2724bU, 0x8f57e31fU, 0xab2a6655U,
-    0x2807b2ebU, 0xc2032fb5U, 0x7b9a86c5U, 0x08a5d337U,
-    0x87f23028U, 0xa5b223bfU, 0x6aba0203U, 0x825ced16U,
-    0x1c2b8acfU, 0xb492a779U, 0xf2f0f307U, 0xe2a14e69U,
-    0xf4cd65daU, 0xbed50605U, 0x621fd134U, 0xfe8ac4a6U,
-    0x539d342eU, 0x55a0a2f3U, 0xe132058aU, 0xeb75a4f6U,
-    0xec390b83U, 0xefaa4060U, 0x9f065e71U, 0x1051bd6eU,
-
-    0x8af93e21U, 0x063d96ddU, 0x05aedd3eU, 0xbd464de6U,
-    0x8db59154U, 0x5d0571c4U, 0xd46f0406U, 0x15ff6050U,
-    0xfb241998U, 0xe997d6bdU, 0x43cc8940U, 0x9e7767d9U,
-    0x42bdb0e8U, 0x8b880789U, 0x5b38e719U, 0xeedb79c8U,
-    0x0a47a17cU, 0x0fe97c42U, 0x1ec9f884U, 0x00000000U,
-    0x86830980U, 0xed48322bU, 0x70ac1e11U, 0x724e6c5aU,
-    0xfffbfd0eU, 0x38560f85U, 0xd51e3daeU, 0x3927362dU,
-    0xd9640a0fU, 0xa621685cU, 0x54d19b5bU, 0x2e3a2436U,
-    0x67b10c0aU, 0xe70f9357U, 0x96d2b4eeU, 0x919e1b9bU,
-    0xc54f80c0U, 0x20a261dcU, 0x4b695a77U, 0x1a161c12U,
-    0xba0ae293U, 0x2ae5c0a0U, 0xe0433c22U, 0x171d121bU,
-    0x0d0b0e09U, 0xc7adf28bU, 0xa8b92db6U, 0xa9c8141eU,
-    0x198557f1U, 0x074caf75U, 0xddbbee99U, 0x60fda37fU,
-    0x269ff701U, 0xf5bc5c72U, 0x3bc54466U, 0x7e345bfbU,
-    0x29768b43U, 0xc6dccb23U, 0xfc68b6edU, 0xf163b8e4U,
-    0xdccad731U, 0x85104263U, 0x22401397U, 0x112084c6U,
-    0x247d854aU, 0x3df8d2bbU, 0x3211aef9U, 0xa16dc729U,
-    0x2f4b1d9eU, 0x30f3dcb2U, 0x52ec0d86U, 0xe3d077c1U,
-    0x166c2bb3U, 0xb999a970U, 0x48fa1194U, 0x642247e9U,
-    0x8cc4a8fcU, 0x3f1aa0f0U, 0x2cd8567dU, 0x90ef2233U,
-    0x4ec78749U, 0xd1c1d938U, 0xa2fe8ccaU, 0x0b3698d4U,
-    0x81cfa6f5U, 0xde28a57aU, 0x8e26dab7U, 0xbfa43fadU,
-    0x9de42c3aU, 0x920d5078U, 0xcc9b6a5fU, 0x4662547eU,
-    0x13c2f68dU, 0xb8e890d8U, 0xf75e2e39U, 0xaff582c3U,
-    0x80be9f5dU, 0x937c69d0U, 0x2da96fd5U, 0x12b3cf25U,
-    0x993bc8acU, 0x7da71018U, 0x636ee89cU, 0xbb7bdb3bU,
-    0x7809cd26U, 0x18f46e59U, 0xb701ec9aU, 0x9aa8834fU,
-    0x6e65e695U, 0xe67eaaffU, 0xcf0821bcU, 0xe8e6ef15U,
-    0x9bd9bae7U, 0x36ce4a6fU, 0x09d4ea9fU, 0x7cd629b0U,
-    0xb2af31a4U, 0x23312a3fU, 0x9430c6a5U, 0x66c035a2U,
-    0xbc37744eU, 0xcaa6fc82U, 0xd0b0e090U, 0xd81533a7U,
-    0x984af104U, 0xdaf741ecU, 0x500e7fcdU, 0xf62f1791U,
-    0xd68d764dU, 0xb04d43efU, 0x4d54ccaaU, 0x04dfe496U,
-    0xb5e39ed1U, 0x881b4c6aU, 0x1fb8c12cU, 0x517f4665U,
-    0xea049d5eU, 0x355d018cU, 0x7473fa87U, 0x412efb0bU,
-    0x1d5ab367U, 0xd25292dbU, 0x5633e910U, 0x47136dd6U,
-    0x618c9ad7U, 0x0c7a37a1U, 0x148e59f8U, 0x3c89eb13U,
-    0x27eecea9U, 0xc935b761U, 0xe5ede11cU, 0xb13c7a47U,
-    0xdf599cd2U, 0x733f55f2U, 0xce791814U, 0x37bf73c7U,
-    0xcdea53f7U, 0xaa5b5ffdU, 0x6f14df3dU, 0xdb867844U,
-    0xf381caafU, 0xc43eb968U, 0x342c3824U, 0x405fc2a3U,
-    0xc372161dU, 0x250cbce2U, 0x498b283cU, 0x9541ff0dU,
-    0x017139a8U, 0xb3de080cU, 0xe49cd8b4U, 0xc1906456U,
-    0x84617bcbU, 0xb670d532U, 0x5c74486cU, 0x5742d0b8U,
-};
-
-const word32 AES::Td3[256] = {
-    0xf4a75051U, 0x4165537eU, 0x17a4c31aU, 0x275e963aU,
-    0xab6bcb3bU, 0x9d45f11fU, 0xfa58abacU, 0xe303934bU,
-    0x30fa5520U, 0x766df6adU, 0xcc769188U, 0x024c25f5U,
-    0xe5d7fc4fU, 0x2acbd7c5U, 0x35448026U, 0x62a38fb5U,
-    0xb15a49deU, 0xba1b6725U, 0xea0e9845U, 0xfec0e15dU,
-    0x2f7502c3U, 0x4cf01281U, 0x4697a38dU, 0xd3f9c66bU,
-    0x8f5fe703U, 0x929c9515U, 0x6d7aebbfU, 0x5259da95U,
-    0xbe832dd4U, 0x7421d358U, 0xe0692949U, 0xc9c8448eU,
-    0xc2896a75U, 0x8e7978f4U, 0x583e6b99U, 0xb971dd27U,
-    0xe14fb6beU, 0x88ad17f0U, 0x20ac66c9U, 0xce3ab47dU,
-    0xdf4a1863U, 0x1a3182e5U, 0x51336097U, 0x537f4562U,
-    0x6477e0b1U, 0x6bae84bbU, 0x81a01cfeU, 0x082b94f9U,
-    0x48685870U, 0x45fd198fU, 0xde6c8794U, 0x7bf8b752U,
-    0x73d323abU, 0x4b02e272U, 0x1f8f57e3U, 0x55ab2a66U,
-    0xeb2807b2U, 0xb5c2032fU, 0xc57b9a86U, 0x3708a5d3U,
-    0x2887f230U, 0xbfa5b223U, 0x036aba02U, 0x16825cedU,
-    0xcf1c2b8aU, 0x79b492a7U, 0x07f2f0f3U, 0x69e2a14eU,
-    0xdaf4cd65U, 0x05bed506U, 0x34621fd1U, 0xa6fe8ac4U,
-    0x2e539d34U, 0xf355a0a2U, 0x8ae13205U, 0xf6eb75a4U,
-    0x83ec390bU, 0x60efaa40U, 0x719f065eU, 0x6e1051bdU,
-    0x218af93eU, 0xdd063d96U, 0x3e05aeddU, 0xe6bd464dU,
-    0x548db591U, 0xc45d0571U, 0x06d46f04U, 0x5015ff60U,
-    0x98fb2419U, 0xbde997d6U, 0x4043cc89U, 0xd99e7767U,
-    0xe842bdb0U, 0x898b8807U, 0x195b38e7U, 0xc8eedb79U,
-    0x7c0a47a1U, 0x420fe97cU, 0x841ec9f8U, 0x00000000U,
-    0x80868309U, 0x2bed4832U, 0x1170ac1eU, 0x5a724e6cU,
-    0x0efffbfdU, 0x8538560fU, 0xaed51e3dU, 0x2d392736U,
-    0x0fd9640aU, 0x5ca62168U, 0x5b54d19bU, 0x362e3a24U,
-    0x0a67b10cU, 0x57e70f93U, 0xee96d2b4U, 0x9b919e1bU,
-    0xc0c54f80U, 0xdc20a261U, 0x774b695aU, 0x121a161cU,
-    0x93ba0ae2U, 0xa02ae5c0U, 0x22e0433cU, 0x1b171d12U,
-    0x090d0b0eU, 0x8bc7adf2U, 0xb6a8b92dU, 0x1ea9c814U,
-    0xf1198557U, 0x75074cafU, 0x99ddbbeeU, 0x7f60fda3U,
-    0x01269ff7U, 0x72f5bc5cU, 0x663bc544U, 0xfb7e345bU,
-    0x4329768bU, 0x23c6dccbU, 0xedfc68b6U, 0xe4f163b8U,
-    0x31dccad7U, 0x63851042U, 0x97224013U, 0xc6112084U,
-    0x4a247d85U, 0xbb3df8d2U, 0xf93211aeU, 0x29a16dc7U,
-    0x9e2f4b1dU, 0xb230f3dcU, 0x8652ec0dU, 0xc1e3d077U,
-    0xb3166c2bU, 0x70b999a9U, 0x9448fa11U, 0xe9642247U,
-    0xfc8cc4a8U, 0xf03f1aa0U, 0x7d2cd856U, 0x3390ef22U,
-    0x494ec787U, 0x38d1c1d9U, 0xcaa2fe8cU, 0xd40b3698U,
-    0xf581cfa6U, 0x7ade28a5U, 0xb78e26daU, 0xadbfa43fU,
-    0x3a9de42cU, 0x78920d50U, 0x5fcc9b6aU, 0x7e466254U,
-    0x8d13c2f6U, 0xd8b8e890U, 0x39f75e2eU, 0xc3aff582U,
-    0x5d80be9fU, 0xd0937c69U, 0xd52da96fU, 0x2512b3cfU,
-    0xac993bc8U, 0x187da710U, 0x9c636ee8U, 0x3bbb7bdbU,
-    0x267809cdU, 0x5918f46eU, 0x9ab701ecU, 0x4f9aa883U,
-    0x956e65e6U, 0xffe67eaaU, 0xbccf0821U, 0x15e8e6efU,
-    0xe79bd9baU, 0x6f36ce4aU, 0x9f09d4eaU, 0xb07cd629U,
-    0xa4b2af31U, 0x3f23312aU, 0xa59430c6U, 0xa266c035U,
-    0x4ebc3774U, 0x82caa6fcU, 0x90d0b0e0U, 0xa7d81533U,
-    0x04984af1U, 0xecdaf741U, 0xcd500e7fU, 0x91f62f17U,
-    0x4dd68d76U, 0xefb04d43U, 0xaa4d54ccU, 0x9604dfe4U,
-    0xd1b5e39eU, 0x6a881b4cU, 0x2c1fb8c1U, 0x65517f46U,
-    0x5eea049dU, 0x8c355d01U, 0x877473faU, 0x0b412efbU,
-    0x671d5ab3U, 0xdbd25292U, 0x105633e9U, 0xd647136dU,
-    0xd7618c9aU, 0xa10c7a37U, 0xf8148e59U, 0x133c89ebU,
-    0xa927eeceU, 0x61c935b7U, 0x1ce5ede1U, 0x47b13c7aU,
-    0xd2df599cU, 0xf2733f55U, 0x14ce7918U, 0xc737bf73U,
-    0xf7cdea53U, 0xfdaa5b5fU, 0x3d6f14dfU, 0x44db8678U,
-    0xaff381caU, 0x68c43eb9U, 0x24342c38U, 0xa3405fc2U,
-    0x1dc37216U, 0xe2250cbcU, 0x3c498b28U, 0x0d9541ffU,
-    0xa8017139U, 0x0cb3de08U, 0xb4e49cd8U, 0x56c19064U,
-    0xcb84617bU, 0x32b670d5U, 0x6c5c7448U, 0xb85742d0U,
-};
-
-const word32 AES::Td4[256] = {
-    0x52525252U, 0x09090909U, 0x6a6a6a6aU, 0xd5d5d5d5U,
-    0x30303030U, 0x36363636U, 0xa5a5a5a5U, 0x38383838U,
-    0xbfbfbfbfU, 0x40404040U, 0xa3a3a3a3U, 0x9e9e9e9eU,
-    0x81818181U, 0xf3f3f3f3U, 0xd7d7d7d7U, 0xfbfbfbfbU,
-    0x7c7c7c7cU, 0xe3e3e3e3U, 0x39393939U, 0x82828282U,
-    0x9b9b9b9bU, 0x2f2f2f2fU, 0xffffffffU, 0x87878787U,
-    0x34343434U, 0x8e8e8e8eU, 0x43434343U, 0x44444444U,
-    0xc4c4c4c4U, 0xdedededeU, 0xe9e9e9e9U, 0xcbcbcbcbU,
-    0x54545454U, 0x7b7b7b7bU, 0x94949494U, 0x32323232U,
-    0xa6a6a6a6U, 0xc2c2c2c2U, 0x23232323U, 0x3d3d3d3dU,
-    0xeeeeeeeeU, 0x4c4c4c4cU, 0x95959595U, 0x0b0b0b0bU,
-    0x42424242U, 0xfafafafaU, 0xc3c3c3c3U, 0x4e4e4e4eU,
-    0x08080808U, 0x2e2e2e2eU, 0xa1a1a1a1U, 0x66666666U,
-    0x28282828U, 0xd9d9d9d9U, 0x24242424U, 0xb2b2b2b2U,
-    0x76767676U, 0x5b5b5b5bU, 0xa2a2a2a2U, 0x49494949U,
-    0x6d6d6d6dU, 0x8b8b8b8bU, 0xd1d1d1d1U, 0x25252525U,
-    0x72727272U, 0xf8f8f8f8U, 0xf6f6f6f6U, 0x64646464U,
-    0x86868686U, 0x68686868U, 0x98989898U, 0x16161616U,
-    0xd4d4d4d4U, 0xa4a4a4a4U, 0x5c5c5c5cU, 0xccccccccU,
-    0x5d5d5d5dU, 0x65656565U, 0xb6b6b6b6U, 0x92929292U,
-    0x6c6c6c6cU, 0x70707070U, 0x48484848U, 0x50505050U,
-    0xfdfdfdfdU, 0xededededU, 0xb9b9b9b9U, 0xdadadadaU,
-    0x5e5e5e5eU, 0x15151515U, 0x46464646U, 0x57575757U,
-    0xa7a7a7a7U, 0x8d8d8d8dU, 0x9d9d9d9dU, 0x84848484U,
-    0x90909090U, 0xd8d8d8d8U, 0xababababU, 0x00000000U,
-    0x8c8c8c8cU, 0xbcbcbcbcU, 0xd3d3d3d3U, 0x0a0a0a0aU,
-    0xf7f7f7f7U, 0xe4e4e4e4U, 0x58585858U, 0x05050505U,
-    0xb8b8b8b8U, 0xb3b3b3b3U, 0x45454545U, 0x06060606U,
-    0xd0d0d0d0U, 0x2c2c2c2cU, 0x1e1e1e1eU, 0x8f8f8f8fU,
-    0xcacacacaU, 0x3f3f3f3fU, 0x0f0f0f0fU, 0x02020202U,
-    0xc1c1c1c1U, 0xafafafafU, 0xbdbdbdbdU, 0x03030303U,
-    0x01010101U, 0x13131313U, 0x8a8a8a8aU, 0x6b6b6b6bU,
-    0x3a3a3a3aU, 0x91919191U, 0x11111111U, 0x41414141U,
-    0x4f4f4f4fU, 0x67676767U, 0xdcdcdcdcU, 0xeaeaeaeaU,
-    0x97979797U, 0xf2f2f2f2U, 0xcfcfcfcfU, 0xcecececeU,
-    0xf0f0f0f0U, 0xb4b4b4b4U, 0xe6e6e6e6U, 0x73737373U,
-    0x96969696U, 0xacacacacU, 0x74747474U, 0x22222222U,
-    0xe7e7e7e7U, 0xadadadadU, 0x35353535U, 0x85858585U,
-    0xe2e2e2e2U, 0xf9f9f9f9U, 0x37373737U, 0xe8e8e8e8U,
-    0x1c1c1c1cU, 0x75757575U, 0xdfdfdfdfU, 0x6e6e6e6eU,
-    0x47474747U, 0xf1f1f1f1U, 0x1a1a1a1aU, 0x71717171U,
-    0x1d1d1d1dU, 0x29292929U, 0xc5c5c5c5U, 0x89898989U,
-    0x6f6f6f6fU, 0xb7b7b7b7U, 0x62626262U, 0x0e0e0e0eU,
-    0xaaaaaaaaU, 0x18181818U, 0xbebebebeU, 0x1b1b1b1bU,
-    0xfcfcfcfcU, 0x56565656U, 0x3e3e3e3eU, 0x4b4b4b4bU,
-    0xc6c6c6c6U, 0xd2d2d2d2U, 0x79797979U, 0x20202020U,
-    0x9a9a9a9aU, 0xdbdbdbdbU, 0xc0c0c0c0U, 0xfefefefeU,
-    0x78787878U, 0xcdcdcdcdU, 0x5a5a5a5aU, 0xf4f4f4f4U,
-    0x1f1f1f1fU, 0xddddddddU, 0xa8a8a8a8U, 0x33333333U,
-    0x88888888U, 0x07070707U, 0xc7c7c7c7U, 0x31313131U,
-    0xb1b1b1b1U, 0x12121212U, 0x10101010U, 0x59595959U,
-    0x27272727U, 0x80808080U, 0xececececU, 0x5f5f5f5fU,
-    0x60606060U, 0x51515151U, 0x7f7f7f7fU, 0xa9a9a9a9U,
-    0x19191919U, 0xb5b5b5b5U, 0x4a4a4a4aU, 0x0d0d0d0dU,
-    0x2d2d2d2dU, 0xe5e5e5e5U, 0x7a7a7a7aU, 0x9f9f9f9fU,
-    0x93939393U, 0xc9c9c9c9U, 0x9c9c9c9cU, 0xefefefefU,
-    0xa0a0a0a0U, 0xe0e0e0e0U, 0x3b3b3b3bU, 0x4d4d4d4dU,
-    0xaeaeaeaeU, 0x2a2a2a2aU, 0xf5f5f5f5U, 0xb0b0b0b0U,
-    0xc8c8c8c8U, 0xebebebebU, 0xbbbbbbbbU, 0x3c3c3c3cU,
-    0x83838383U, 0x53535353U, 0x99999999U, 0x61616161U,
-    0x17171717U, 0x2b2b2b2bU, 0x04040404U, 0x7e7e7e7eU,
-    0xbabababaU, 0x77777777U, 0xd6d6d6d6U, 0x26262626U,
-    0xe1e1e1e1U, 0x69696969U, 0x14141414U, 0x63636363U,
-    0x55555555U, 0x21212121U, 0x0c0c0c0cU, 0x7d7d7d7dU,
-};
-
 const word32 AES::rcon_[] = {
     0x01000000, 0x02000000, 0x04000000, 0x08000000,
     0x10000000, 0x20000000, 0x40000000, 0x80000000,
diff --git a/extra/yassl/taocrypt/src/algebra.cpp b/extra/yassl/taocrypt/src/algebra.cpp
index 45bbcfa662a..9249289d505 100644
--- a/extra/yassl/taocrypt/src/algebra.cpp
+++ b/extra/yassl/taocrypt/src/algebra.cpp
@@ -20,6 +20,8 @@
  */
 
 /* based on Wei Dai's algebra.cpp from CryptoPP */
+#undef  NDEBUG
+#define DEBUG   // GCC 4.0 bug if NDEBUG and Optimize > 1
 
 #include "runtime.hpp"
 #include "algebra.hpp"
diff --git a/extra/yassl/taocrypt/src/arc4.cpp b/extra/yassl/taocrypt/src/arc4.cpp
index 1e521b48f0c..6d1c4d4e3a6 100644
--- a/extra/yassl/taocrypt/src/arc4.cpp
+++ b/extra/yassl/taocrypt/src/arc4.cpp
@@ -25,6 +25,11 @@
 #include "arc4.hpp"
 
 
+#if defined(TAOCRYPT_X86ASM_AVAILABLE) && defined(TAO_ASM)
+    #define DO_ARC4_ASM
+#endif
+
+
 namespace TaoCrypt {
 
 void ARC4::SetKey(const byte* key, word32 length)
@@ -71,6 +76,8 @@ inline unsigned int MakeByte(word32& x, word32& y, byte* s)
 } // namespace
 
 
+#ifndef DO_ARC4_ASM
+
 void ARC4::Process(byte* out, const byte* in, word32 length)
 {
     if (length == 0) return;
@@ -89,5 +96,134 @@ void ARC4::Process(byte* out, const byte* in, word32 length)
     y_ = y;
 }
 
+#else  // DO_ARC4_ASM
+
+
+#ifdef _MSC_VER
+    __declspec(naked) 
+#endif
+void ARC4::Process(byte* out, const byte* in, word32 length)
+{
+#ifdef __GNUC__
+    #define AS1(x)    asm(#x);
+    #define AS2(x, y) asm(#x ", " #y);
+
+    #define PROLOG()  \
+        asm(".intel_syntax noprefix"); \
+        AS2(    movd  mm3, edi                      )   \
+        AS2(    movd  mm4, ebx                      )   \
+        AS2(    movd  mm5, esi                      )   \
+        AS2(    movd  mm6, ebp                      )   \
+        AS2(    mov   ecx, DWORD PTR [ebp +  8]     )   \
+        AS2(    mov   edi, DWORD PTR [ebp + 12]     )   \
+        AS2(    mov   esi, DWORD PTR [ebp + 16]     )   \
+        AS2(    mov   ebp, DWORD PTR [ebp + 20]     )
+
+    #define EPILOG()  \
+        AS2(    movd  ebp, mm6                  )   \
+        AS2(    movd  esi, mm5                  )   \
+        AS2(    movd  ebx, mm4                  )   \
+        AS2(    mov   esp, ebp                  )   \
+        AS2(    movd  edi, mm3                  )   \
+        AS1(    emms                            )   \
+        asm(".att_syntax");
+#else
+    #define AS1(x)    __asm x
+    #define AS2(x, y) __asm x, y
+
+    #define PROLOG() \
+        AS1(    push  ebp                       )   \
+        AS2(    mov   ebp, esp                  )   \
+        AS2(    movd  mm3, edi                  )   \
+        AS2(    movd  mm4, ebx                  )   \
+        AS2(    movd  mm5, esi                  )   \
+        AS2(    movd  mm6, ebp                  )   \
+        AS2(    mov   edi, DWORD PTR [ebp +  8] )   \
+        AS2(    mov   esi, DWORD PTR [ebp + 12] )   \
+        AS2(    mov   ebp, DWORD PTR [ebp + 16] )
+
+    #define EPILOG() \
+        AS2(    movd  ebp, mm6                  )   \
+        AS2(    movd  esi, mm5                  )   \
+        AS2(    movd  ebx, mm4                  )   \
+        AS2(    movd  edi, mm3                  )   \
+        AS2(    mov   esp, ebp                  )   \
+        AS1(    pop   ebp                       )   \
+        AS1(    emms                            )   \
+        AS1(    ret 12                          )
+        
+#endif
+
+    PROLOG()
+
+    AS2(    sub    esp, 4                   )   // make room 
+
+    AS2(    cmp    ebp, 0                   )
+    AS1(    jz     nothing                  )
+
+    AS2(    mov    [esp], ebp               )   // length
+
+    AS2(    movzx  edx, BYTE PTR [ecx + 1]  )   // y
+    AS2(    lea    ebp, [ecx + 2]           )   // state_
+    AS2(    movzx  ecx, BYTE PTR [ecx]      )   // x
+
+    // setup loop
+    // a = s[x];
+    AS2(    movzx  eax, BYTE PTR [ebp + ecx]    )
+
+
+AS1( begin:                             )
+
+    // y = (y+a) & 0xff;
+    AS2(    add    edx, eax                     )
+    AS2(    and    edx, 255                     )
+
+    // b = s[y];
+    AS2(    movzx  ebx, BYTE PTR [ebp + edx]    )
+
+    // s[x] = b;
+    AS2(    mov    [ebp + ecx], bl              )
+
+    // s[y] = a;
+    AS2(    mov    [ebp + edx], al              )
+
+    // x = (x+1) & 0xff;
+    AS1(    inc    ecx                          )
+    AS2(    and    ecx, 255                     )
+
+    //return s[(a+b) & 0xff];
+    AS2(    add    eax, ebx                     )
+    AS2(    and    eax, 255                     )
+    
+    AS2(    movzx  ebx, BYTE PTR [ebp + eax]    )
+
+    // a = s[x];   for next round
+    AS2(    movzx  eax, BYTE PTR [ebp + ecx]    )
+
+    // xOr w/ inByte
+    AS2(    xor    bl,  BYTE PTR [esi]          )
+    AS1(    inc    esi                          )
+
+    // write to outByte
+    AS2(    mov    [edi], bl                    )
+    AS1(    inc    edi                          )
+
+    AS1(    dec    DWORD PTR [esp]              )
+    AS1(    jnz    begin                        )
+
+
+    // write back to x_ and y_
+    AS2(    mov    [ebp - 2], cl            )
+    AS2(    mov    [ebp - 1], dl            )
+
+
+AS1( nothing:                           )
+
+
+    EPILOG()
+}
+
+#endif // DO_ARC4_ASM
+
 
 }  // namespace
diff --git a/extra/yassl/taocrypt/src/asn.cpp b/extra/yassl/taocrypt/src/asn.cpp
index 8f8d2ba52da..3efc26ab168 100644
--- a/extra/yassl/taocrypt/src/asn.cpp
+++ b/extra/yassl/taocrypt/src/asn.cpp
@@ -186,7 +186,7 @@ PublicKey::PublicKey(const byte* k, word32 s) : key_(0), sz_(0)
 void PublicKey::SetSize(word32 s)
 {
     sz_ = s;
-    key_ = new (tc) byte[sz_];
+    key_ = NEW_TC byte[sz_];
 }
 
 
@@ -198,7 +198,7 @@ void PublicKey::SetKey(const byte* k)
 
 void PublicKey::AddToEnd(const byte* data, word32 len)
 {
-    mySTL::auto_ptr tmp(new (tc) byte[sz_ + len], tcArrayDelete);
+    mySTL::auto_ptr tmp(NEW_TC byte[sz_ + len], tcArrayDelete);
 
     memcpy(tmp.get(), key_, sz_);
     memcpy(tmp.get() + sz_, data, len);
@@ -217,7 +217,7 @@ Signer::Signer(const byte* k, word32 kSz, const char* n, const byte* h)
 {
     if (n) {
         int sz = strlen(n);
-        name_ = new (tc) char[sz + 1];
+        name_ = NEW_TC char[sz + 1];
         memcpy(name_, n, sz);
         name_[sz] = 0;
     }
@@ -421,12 +421,13 @@ void DH_Decoder::Decode(DH& key)
 }
 
 
-CertDecoder::CertDecoder(Source& s, bool decode, SignerList* signers)
+CertDecoder::CertDecoder(Source& s, bool decode, SignerList* signers,
+                         bool noVerify, CertType ct)
     : BER_Decoder(s), certBegin_(0), sigIndex_(0), sigLength_(0),
-      signature_(0), issuer_(0), subject_(0)
+      signature_(0), issuer_(0), subject_(0), verify_(!noVerify)
 { 
     if (decode)
-        Decode(signers); 
+        Decode(signers, ct); 
 }
 
 
@@ -455,7 +456,7 @@ void CertDecoder::ReadHeader()
 
 
 // Decode a x509v3 Certificate
-void CertDecoder::Decode(SignerList* signers)
+void CertDecoder::Decode(SignerList* signers, CertType ct)
 {
     if (source_.GetError().What()) return;
     DecodeToKey();
@@ -473,12 +474,16 @@ void CertDecoder::Decode(SignerList* signers)
         return;
     }
 
+    if (ct == CA) {
     if ( memcmp(issuerHash_, subjectHash_, SHA::DIGEST_SIZE) == 0 ) {
-        if (!ValidateSelfSignature())
+            if (!ValidateSelfSignature() && verify_)
             source_.SetError(SIG_CONFIRM_E);
     }
     else
-        if (!ValidateSignature(signers))
+            if (!ValidateSignature(signers) && verify_)
+                source_.SetError(SIG_OTHER_E);
+    }
+    else if (!ValidateSignature(signers) && verify_)
             source_.SetError(SIG_OTHER_E);
 }
 
@@ -631,7 +636,7 @@ word32 CertDecoder::GetSignature()
     }
     sigLength_--;
 
-    signature_ = new (tc) byte[sigLength_];
+    signature_ = NEW_TC byte[sigLength_];
     memcpy(signature_, source_.get_current(), sigLength_);
     source_.advance(sigLength_);
 
@@ -652,7 +657,7 @@ word32 CertDecoder::GetDigest()
 
     sigLength_ = GetLength(source_);
 
-    signature_ = new (tc) byte[sigLength_];
+    signature_ = NEW_TC byte[sigLength_];
     memcpy(signature_, source_.get_current(), sigLength_);
     source_.advance(sigLength_);
 
@@ -692,7 +697,7 @@ void CertDecoder::GetName(NameType nt)
 
             if (id == COMMON_NAME) {
                 char*& ptr = (nt == ISSUER) ? issuer_ : subject_;
-                ptr = new (tc) char[strLen + 1];
+                ptr = NEW_TC char[strLen + 1];
                 memcpy(ptr, source_.get_current(), strLen);
                 ptr[strLen] = 0;
             }
@@ -734,7 +739,7 @@ void CertDecoder::GetDate(DateType dt)
     memcpy(date, source_.get_current(), length);
     source_.advance(length);
 
-    if (!ValidateDate(date, b, dt))
+    if (!ValidateDate(date, b, dt) && verify_)
         if (dt == BEFORE)
             source_.SetError(BEFORE_DATE_E);
         else
@@ -802,22 +807,22 @@ bool CertDecoder::ValidateSignature(SignerList* signers)
 }
 
 
-// RSA confirm
+// confirm certificate signature
 bool CertDecoder::ConfirmSignature(Source& pub)
 {
     HashType ht;
     mySTL::auto_ptr hasher(tcDelete);
 
     if (signatureOID_ == MD5wRSA) {
-        hasher.reset(new (tc) MD5);
+        hasher.reset(NEW_TC MD5);
         ht = MD5h;
     }
     else if (signatureOID_ == MD2wRSA) {
-        hasher.reset(new (tc) MD2);
+        hasher.reset(NEW_TC MD2);
         ht = MD2h;
     }
     else if (signatureOID_ == SHAwRSA || signatureOID_ == SHAwDSA) {
-        hasher.reset(new (tc) SHA);
+        hasher.reset(NEW_TC SHA);
         ht = SHAh;
     }
     else {
diff --git a/extra/yassl/taocrypt/src/bftables.cpp b/extra/yassl/taocrypt/src/bftables.cpp
new file mode 100644
index 00000000000..e072b117f54
--- /dev/null
+++ b/extra/yassl/taocrypt/src/bftables.cpp
@@ -0,0 +1,306 @@
+/* bftables.cpp                                
+ *
+ * Copyright (C) 2003 Sawtooth Consulting Ltd.
+ *
+ * This file is part of yaSSL.
+ *
+ * yaSSL 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; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * yaSSL 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ */
+
+/* based on Wei Dai's bfinit.cpp from CryptoPP */
+
+#include "runtime.hpp"
+#include "blowfish.hpp"
+
+
+namespace TaoCrypt {
+
+const word32 Blowfish::p_init_[Blowfish::ROUNDS+2] =
+{
+  608135816U, 2242054355U,  320440878U,   57701188U,
+ 2752067618U,  698298832U,  137296536U, 3964562569U,
+ 1160258022U,  953160567U, 3193202383U,  887688300U,
+ 3232508343U, 3380367581U, 1065670069U, 3041331479U,
+ 2450970073U, 2306472731U
+} ;
+
+
+const word32 Blowfish::s_init_[4*256] = {
+ 3509652390U, 2564797868U,  805139163U, 3491422135U,
+ 3101798381U, 1780907670U, 3128725573U, 4046225305U,
+  614570311U, 3012652279U,  134345442U, 2240740374U,
+ 1667834072U, 1901547113U, 2757295779U, 4103290238U,
+  227898511U, 1921955416U, 1904987480U, 2182433518U,
+ 2069144605U, 3260701109U, 2620446009U,  720527379U,
+ 3318853667U,  677414384U, 3393288472U, 3101374703U,
+ 2390351024U, 1614419982U, 1822297739U, 2954791486U,
+ 3608508353U, 3174124327U, 2024746970U, 1432378464U,
+ 3864339955U, 2857741204U, 1464375394U, 1676153920U,
+ 1439316330U,  715854006U, 3033291828U,  289532110U,
+ 2706671279U, 2087905683U, 3018724369U, 1668267050U,
+  732546397U, 1947742710U, 3462151702U, 2609353502U,
+ 2950085171U, 1814351708U, 2050118529U,  680887927U,
+  999245976U, 1800124847U, 3300911131U, 1713906067U,
+ 1641548236U, 4213287313U, 1216130144U, 1575780402U,
+ 4018429277U, 3917837745U, 3693486850U, 3949271944U,
+  596196993U, 3549867205U,  258830323U, 2213823033U,
+  772490370U, 2760122372U, 1774776394U, 2652871518U,
+  566650946U, 4142492826U, 1728879713U, 2882767088U,
+ 1783734482U, 3629395816U, 2517608232U, 2874225571U,
+ 1861159788U,  326777828U, 3124490320U, 2130389656U,
+ 2716951837U,  967770486U, 1724537150U, 2185432712U,
+ 2364442137U, 1164943284U, 2105845187U,  998989502U,
+ 3765401048U, 2244026483U, 1075463327U, 1455516326U,
+ 1322494562U,  910128902U,  469688178U, 1117454909U,
+  936433444U, 3490320968U, 3675253459U, 1240580251U,
+  122909385U, 2157517691U,  634681816U, 4142456567U,
+ 3825094682U, 3061402683U, 2540495037U,   79693498U,
+ 3249098678U, 1084186820U, 1583128258U,  426386531U,
+ 1761308591U, 1047286709U,  322548459U,  995290223U,
+ 1845252383U, 2603652396U, 3431023940U, 2942221577U,
+ 3202600964U, 3727903485U, 1712269319U,  422464435U,
+ 3234572375U, 1170764815U, 3523960633U, 3117677531U,
+ 1434042557U,  442511882U, 3600875718U, 1076654713U,
+ 1738483198U, 4213154764U, 2393238008U, 3677496056U,
+ 1014306527U, 4251020053U,  793779912U, 2902807211U,
+  842905082U, 4246964064U, 1395751752U, 1040244610U,
+ 2656851899U, 3396308128U,  445077038U, 3742853595U,
+ 3577915638U,  679411651U, 2892444358U, 2354009459U,
+ 1767581616U, 3150600392U, 3791627101U, 3102740896U,
+  284835224U, 4246832056U, 1258075500U,  768725851U,
+ 2589189241U, 3069724005U, 3532540348U, 1274779536U,
+ 3789419226U, 2764799539U, 1660621633U, 3471099624U,
+ 4011903706U,  913787905U, 3497959166U,  737222580U,
+ 2514213453U, 2928710040U, 3937242737U, 1804850592U,
+ 3499020752U, 2949064160U, 2386320175U, 2390070455U,
+ 2415321851U, 4061277028U, 2290661394U, 2416832540U,
+ 1336762016U, 1754252060U, 3520065937U, 3014181293U,
+  791618072U, 3188594551U, 3933548030U, 2332172193U,
+ 3852520463U, 3043980520U,  413987798U, 3465142937U,
+ 3030929376U, 4245938359U, 2093235073U, 3534596313U,
+  375366246U, 2157278981U, 2479649556U,  555357303U,
+ 3870105701U, 2008414854U, 3344188149U, 4221384143U,
+ 3956125452U, 2067696032U, 3594591187U, 2921233993U,
+	2428461U,  544322398U,  577241275U, 1471733935U,
+  610547355U, 4027169054U, 1432588573U, 1507829418U,
+ 2025931657U, 3646575487U,  545086370U,   48609733U,
+ 2200306550U, 1653985193U,  298326376U, 1316178497U,
+ 3007786442U, 2064951626U,  458293330U, 2589141269U,
+ 3591329599U, 3164325604U,  727753846U, 2179363840U,
+  146436021U, 1461446943U, 4069977195U,  705550613U,
+ 3059967265U, 3887724982U, 4281599278U, 3313849956U,
+ 1404054877U, 2845806497U,  146425753U, 1854211946U,
+
+ 1266315497U, 3048417604U, 3681880366U, 3289982499U,
+ 2909710000U, 1235738493U, 2632868024U, 2414719590U,
+ 3970600049U, 1771706367U, 1449415276U, 3266420449U,
+  422970021U, 1963543593U, 2690192192U, 3826793022U,
+ 1062508698U, 1531092325U, 1804592342U, 2583117782U,
+ 2714934279U, 4024971509U, 1294809318U, 4028980673U,
+ 1289560198U, 2221992742U, 1669523910U,   35572830U,
+  157838143U, 1052438473U, 1016535060U, 1802137761U,
+ 1753167236U, 1386275462U, 3080475397U, 2857371447U,
+ 1040679964U, 2145300060U, 2390574316U, 1461121720U,
+ 2956646967U, 4031777805U, 4028374788U,   33600511U,
+ 2920084762U, 1018524850U,  629373528U, 3691585981U,
+ 3515945977U, 2091462646U, 2486323059U,  586499841U,
+  988145025U,  935516892U, 3367335476U, 2599673255U,
+ 2839830854U,  265290510U, 3972581182U, 2759138881U,
+ 3795373465U, 1005194799U,  847297441U,  406762289U,
+ 1314163512U, 1332590856U, 1866599683U, 4127851711U,
+  750260880U,  613907577U, 1450815602U, 3165620655U,
+ 3734664991U, 3650291728U, 3012275730U, 3704569646U,
+ 1427272223U,  778793252U, 1343938022U, 2676280711U,
+ 2052605720U, 1946737175U, 3164576444U, 3914038668U,
+ 3967478842U, 3682934266U, 1661551462U, 3294938066U,
+ 4011595847U,  840292616U, 3712170807U,  616741398U,
+  312560963U,  711312465U, 1351876610U,  322626781U,
+ 1910503582U,  271666773U, 2175563734U, 1594956187U,
+   70604529U, 3617834859U, 1007753275U, 1495573769U,
+ 4069517037U, 2549218298U, 2663038764U,  504708206U,
+ 2263041392U, 3941167025U, 2249088522U, 1514023603U,
+ 1998579484U, 1312622330U,  694541497U, 2582060303U,
+ 2151582166U, 1382467621U,  776784248U, 2618340202U,
+ 3323268794U, 2497899128U, 2784771155U,  503983604U,
+ 4076293799U,  907881277U,  423175695U,  432175456U,
+ 1378068232U, 4145222326U, 3954048622U, 3938656102U,
+ 3820766613U, 2793130115U, 2977904593U,   26017576U,
+ 3274890735U, 3194772133U, 1700274565U, 1756076034U,
+ 4006520079U, 3677328699U,  720338349U, 1533947780U,
+  354530856U,  688349552U, 3973924725U, 1637815568U,
+  332179504U, 3949051286U,   53804574U, 2852348879U,
+ 3044236432U, 1282449977U, 3583942155U, 3416972820U,
+ 4006381244U, 1617046695U, 2628476075U, 3002303598U,
+ 1686838959U,  431878346U, 2686675385U, 1700445008U,
+ 1080580658U, 1009431731U,  832498133U, 3223435511U,
+ 2605976345U, 2271191193U, 2516031870U, 1648197032U,
+ 4164389018U, 2548247927U,  300782431U,  375919233U,
+  238389289U, 3353747414U, 2531188641U, 2019080857U,
+ 1475708069U,  455242339U, 2609103871U,  448939670U,
+ 3451063019U, 1395535956U, 2413381860U, 1841049896U,
+ 1491858159U,  885456874U, 4264095073U, 4001119347U,
+ 1565136089U, 3898914787U, 1108368660U,  540939232U,
+ 1173283510U, 2745871338U, 3681308437U, 4207628240U,
+ 3343053890U, 4016749493U, 1699691293U, 1103962373U,
+ 3625875870U, 2256883143U, 3830138730U, 1031889488U,
+ 3479347698U, 1535977030U, 4236805024U, 3251091107U,
+ 2132092099U, 1774941330U, 1199868427U, 1452454533U,
+  157007616U, 2904115357U,  342012276U,  595725824U,
+ 1480756522U,  206960106U,  497939518U,  591360097U,
+  863170706U, 2375253569U, 3596610801U, 1814182875U,
+ 2094937945U, 3421402208U, 1082520231U, 3463918190U,
+ 2785509508U,  435703966U, 3908032597U, 1641649973U,
+ 2842273706U, 3305899714U, 1510255612U, 2148256476U,
+ 2655287854U, 3276092548U, 4258621189U,  236887753U,
+ 3681803219U,  274041037U, 1734335097U, 3815195456U,
+ 3317970021U, 1899903192U, 1026095262U, 4050517792U,
+  356393447U, 2410691914U, 3873677099U, 3682840055U,
+
+ 3913112168U, 2491498743U, 4132185628U, 2489919796U,
+ 1091903735U, 1979897079U, 3170134830U, 3567386728U,
+ 3557303409U,  857797738U, 1136121015U, 1342202287U,
+  507115054U, 2535736646U,  337727348U, 3213592640U,
+ 1301675037U, 2528481711U, 1895095763U, 1721773893U,
+ 3216771564U,   62756741U, 2142006736U,  835421444U,
+ 2531993523U, 1442658625U, 3659876326U, 2882144922U,
+  676362277U, 1392781812U,  170690266U, 3921047035U,
+ 1759253602U, 3611846912U, 1745797284U,  664899054U,
+ 1329594018U, 3901205900U, 3045908486U, 2062866102U,
+ 2865634940U, 3543621612U, 3464012697U, 1080764994U,
+  553557557U, 3656615353U, 3996768171U,  991055499U,
+  499776247U, 1265440854U,  648242737U, 3940784050U,
+  980351604U, 3713745714U, 1749149687U, 3396870395U,
+ 4211799374U, 3640570775U, 1161844396U, 3125318951U,
+ 1431517754U,  545492359U, 4268468663U, 3499529547U,
+ 1437099964U, 2702547544U, 3433638243U, 2581715763U,
+ 2787789398U, 1060185593U, 1593081372U, 2418618748U,
+ 4260947970U,   69676912U, 2159744348U,   86519011U,
+ 2512459080U, 3838209314U, 1220612927U, 3339683548U,
+  133810670U, 1090789135U, 1078426020U, 1569222167U,
+  845107691U, 3583754449U, 4072456591U, 1091646820U,
+  628848692U, 1613405280U, 3757631651U,  526609435U,
+  236106946U,   48312990U, 2942717905U, 3402727701U,
+ 1797494240U,  859738849U,  992217954U, 4005476642U,
+ 2243076622U, 3870952857U, 3732016268U,  765654824U,
+ 3490871365U, 2511836413U, 1685915746U, 3888969200U,
+ 1414112111U, 2273134842U, 3281911079U, 4080962846U,
+  172450625U, 2569994100U,  980381355U, 4109958455U,
+ 2819808352U, 2716589560U, 2568741196U, 3681446669U,
+ 3329971472U, 1835478071U,  660984891U, 3704678404U,
+ 4045999559U, 3422617507U, 3040415634U, 1762651403U,
+ 1719377915U, 3470491036U, 2693910283U, 3642056355U,
+ 3138596744U, 1364962596U, 2073328063U, 1983633131U,
+  926494387U, 3423689081U, 2150032023U, 4096667949U,
+ 1749200295U, 3328846651U,  309677260U, 2016342300U,
+ 1779581495U, 3079819751U,  111262694U, 1274766160U,
+  443224088U,  298511866U, 1025883608U, 3806446537U,
+ 1145181785U,  168956806U, 3641502830U, 3584813610U,
+ 1689216846U, 3666258015U, 3200248200U, 1692713982U,
+ 2646376535U, 4042768518U, 1618508792U, 1610833997U,
+ 3523052358U, 4130873264U, 2001055236U, 3610705100U,
+ 2202168115U, 4028541809U, 2961195399U, 1006657119U,
+ 2006996926U, 3186142756U, 1430667929U, 3210227297U,
+ 1314452623U, 4074634658U, 4101304120U, 2273951170U,
+ 1399257539U, 3367210612U, 3027628629U, 1190975929U,
+ 2062231137U, 2333990788U, 2221543033U, 2438960610U,
+ 1181637006U,  548689776U, 2362791313U, 3372408396U,
+ 3104550113U, 3145860560U,  296247880U, 1970579870U,
+ 3078560182U, 3769228297U, 1714227617U, 3291629107U,
+ 3898220290U,  166772364U, 1251581989U,  493813264U,
+  448347421U,  195405023U, 2709975567U,  677966185U,
+ 3703036547U, 1463355134U, 2715995803U, 1338867538U,
+ 1343315457U, 2802222074U, 2684532164U,  233230375U,
+ 2599980071U, 2000651841U, 3277868038U, 1638401717U,
+ 4028070440U, 3237316320U,    6314154U,  819756386U,
+  300326615U,  590932579U, 1405279636U, 3267499572U,
+ 3150704214U, 2428286686U, 3959192993U, 3461946742U,
+ 1862657033U, 1266418056U,  963775037U, 2089974820U,
+ 2263052895U, 1917689273U,  448879540U, 3550394620U,
+ 3981727096U,  150775221U, 3627908307U, 1303187396U,
+  508620638U, 2975983352U, 2726630617U, 1817252668U,
+ 1876281319U, 1457606340U,  908771278U, 3720792119U,
+ 3617206836U, 2455994898U, 1729034894U, 1080033504U,
+
+  976866871U, 3556439503U, 2881648439U, 1522871579U,
+ 1555064734U, 1336096578U, 3548522304U, 2579274686U,
+ 3574697629U, 3205460757U, 3593280638U, 3338716283U,
+ 3079412587U,  564236357U, 2993598910U, 1781952180U,
+ 1464380207U, 3163844217U, 3332601554U, 1699332808U,
+ 1393555694U, 1183702653U, 3581086237U, 1288719814U,
+  691649499U, 2847557200U, 2895455976U, 3193889540U,
+ 2717570544U, 1781354906U, 1676643554U, 2592534050U,
+ 3230253752U, 1126444790U, 2770207658U, 2633158820U,
+ 2210423226U, 2615765581U, 2414155088U, 3127139286U,
+  673620729U, 2805611233U, 1269405062U, 4015350505U,
+ 3341807571U, 4149409754U, 1057255273U, 2012875353U,
+ 2162469141U, 2276492801U, 2601117357U,  993977747U,
+ 3918593370U, 2654263191U,  753973209U,   36408145U,
+ 2530585658U,   25011837U, 3520020182U, 2088578344U,
+  530523599U, 2918365339U, 1524020338U, 1518925132U,
+ 3760827505U, 3759777254U, 1202760957U, 3985898139U,
+ 3906192525U,  674977740U, 4174734889U, 2031300136U,
+ 2019492241U, 3983892565U, 4153806404U, 3822280332U,
+  352677332U, 2297720250U,   60907813U,   90501309U,
+ 3286998549U, 1016092578U, 2535922412U, 2839152426U,
+  457141659U,  509813237U, 4120667899U,  652014361U,
+ 1966332200U, 2975202805U,   55981186U, 2327461051U,
+  676427537U, 3255491064U, 2882294119U, 3433927263U,
+ 1307055953U,  942726286U,  933058658U, 2468411793U,
+ 3933900994U, 4215176142U, 1361170020U, 2001714738U,
+ 2830558078U, 3274259782U, 1222529897U, 1679025792U,
+ 2729314320U, 3714953764U, 1770335741U,  151462246U,
+ 3013232138U, 1682292957U, 1483529935U,  471910574U,
+ 1539241949U,  458788160U, 3436315007U, 1807016891U,
+ 3718408830U,  978976581U, 1043663428U, 3165965781U,
+ 1927990952U, 4200891579U, 2372276910U, 3208408903U,
+ 3533431907U, 1412390302U, 2931980059U, 4132332400U,
+ 1947078029U, 3881505623U, 4168226417U, 2941484381U,
+ 1077988104U, 1320477388U,  886195818U,   18198404U,
+ 3786409000U, 2509781533U,  112762804U, 3463356488U,
+ 1866414978U,  891333506U,   18488651U,  661792760U,
+ 1628790961U, 3885187036U, 3141171499U,  876946877U,
+ 2693282273U, 1372485963U,  791857591U, 2686433993U,
+ 3759982718U, 3167212022U, 3472953795U, 2716379847U,
+  445679433U, 3561995674U, 3504004811U, 3574258232U,
+   54117162U, 3331405415U, 2381918588U, 3769707343U,
+ 4154350007U, 1140177722U, 4074052095U,  668550556U,
+ 3214352940U,  367459370U,  261225585U, 2610173221U,
+ 4209349473U, 3468074219U, 3265815641U,  314222801U,
+ 3066103646U, 3808782860U,  282218597U, 3406013506U,
+ 3773591054U,  379116347U, 1285071038U,  846784868U,
+ 2669647154U, 3771962079U, 3550491691U, 2305946142U,
+  453669953U, 1268987020U, 3317592352U, 3279303384U,
+ 3744833421U, 2610507566U, 3859509063U,  266596637U,
+ 3847019092U,  517658769U, 3462560207U, 3443424879U,
+  370717030U, 4247526661U, 2224018117U, 4143653529U,
+ 4112773975U, 2788324899U, 2477274417U, 1456262402U,
+ 2901442914U, 1517677493U, 1846949527U, 2295493580U,
+ 3734397586U, 2176403920U, 1280348187U, 1908823572U,
+ 3871786941U,  846861322U, 1172426758U, 3287448474U,
+ 3383383037U, 1655181056U, 3139813346U,  901632758U,
+ 1897031941U, 2986607138U, 3066810236U, 3447102507U,
+ 1393639104U,  373351379U,  950779232U,  625454576U,
+ 3124240540U, 4148612726U, 2007998917U,  544563296U,
+ 2244738638U, 2330496472U, 2058025392U, 1291430526U,
+  424198748U,   50039436U,   29584100U, 3605783033U,
+ 2429876329U, 2791104160U, 1057563949U, 3255363231U,
+ 3075367218U, 3463963227U, 1469046755U,  985887462U
+};
+
+
+
+
+} // namespace
+
diff --git a/extra/yassl/taocrypt/src/blowfish.cpp b/extra/yassl/taocrypt/src/blowfish.cpp
new file mode 100644
index 00000000000..16e2277dc10
--- /dev/null
+++ b/extra/yassl/taocrypt/src/blowfish.cpp
@@ -0,0 +1,358 @@
+/* blowfish.cpp                                
+ *
+ * Copyright (C) 2003 Sawtooth Consulting Ltd.
+ *
+ * This file is part of yaSSL.
+ *
+ * yaSSL 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; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * yaSSL 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ */
+
+/* C++ code based on Wei Dai's blowfish.cpp from CryptoPP */
+/* x86 asm is original */
+
+
+#if defined(TAOCRYPT_KERNEL_MODE)
+    #define DO_TAOCRYPT_KERNEL_MODE
+#endif                                  // only some modules now support this
+
+
+#include "runtime.hpp"
+#include "blowfish.hpp"
+
+
+
+#if defined(TAOCRYPT_X86ASM_AVAILABLE) && defined(TAO_ASM)
+    #define DO_BLOWFISH_ASM
+#endif
+
+
+
+namespace TaoCrypt {
+
+
+#if !defined(DO_BLOWFISH_ASM)
+
+// Generic Version
+void Blowfish::Process(byte* out, const byte* in, word32 sz)
+{
+    if (mode_ == ECB)
+        ECB_Process(out, in, sz);
+    else if (mode_ == CBC)
+        if (dir_ == ENCRYPTION)
+            CBC_Encrypt(out, in, sz);
+        else
+            CBC_Decrypt(out, in, sz);
+}
+
+#else
+
+// ia32 optimized version
+void Blowfish::Process(byte* out, const byte* in, word32 sz)
+{
+    word32 blocks = sz / BLOCK_SIZE;
+
+    if (mode_ == ECB)
+        while (blocks--) {
+            AsmProcess(in, out);
+            out += BLOCK_SIZE;
+            in  += BLOCK_SIZE;
+        }
+    else if (mode_ == CBC)
+        if (dir_ == ENCRYPTION)
+            while (blocks--) {
+                r_[0] ^= *(word32*)in;
+                r_[1] ^= *(word32*)(in + 4);
+
+                AsmProcess((byte*)r_, (byte*)r_);
+                
+                memcpy(out, r_, BLOCK_SIZE);
+
+                out += BLOCK_SIZE;
+                in  += BLOCK_SIZE;
+            }
+        else
+            while (blocks--) {
+                AsmProcess(in, out);
+                
+                *(word32*)out       ^= r_[0];
+                *(word32*)(out + 4) ^= r_[1];
+
+                memcpy(r_, in, BLOCK_SIZE);
+
+                out += BLOCK_SIZE;
+                in  += BLOCK_SIZE;
+            }
+}
+
+#endif // DO_BLOWFISH_ASM
+
+
+void Blowfish::SetKey(const byte* key_string, word32 keylength, CipherDir dir)
+{
+	assert(keylength >= 4 && keylength <= 56);
+
+	unsigned i, j=0, k;
+	word32 data, dspace[2] = {0, 0};
+
+	memcpy(pbox_, p_init_, sizeof(p_init_));
+	memcpy(sbox_, s_init_, sizeof(s_init_));
+
+	// Xor key string into encryption key vector
+	for (i=0 ; i> 8)&0xFF)
+#define BFBYTE_2(x) ((x>>16)&0xFF)
+#define BFBYTE_3(x) ( x>>24)
+
+
+#define BF_S(Put, Get, I) (\
+        Put ^= p[I], \
+		tmp =  p[18 + BFBYTE_3(Get)],  \
+        tmp += p[274+ BFBYTE_2(Get)],  \
+        tmp ^= p[530+ BFBYTE_1(Get)],  \
+        tmp += p[786+ BFBYTE_0(Get)],  \
+        Put ^= tmp \
+    )
+
+
+#define BF_ROUNDS           \
+    BF_S(right, left,  1);  \
+    BF_S(left,  right, 2);  \
+    BF_S(right, left,  3);  \
+    BF_S(left,  right, 4);  \
+    BF_S(right, left,  5);  \
+    BF_S(left,  right, 6);  \
+    BF_S(right, left,  7);  \
+    BF_S(left,  right, 8);  \
+    BF_S(right, left,  9);  \
+    BF_S(left,  right, 10); \
+    BF_S(right, left,  11); \
+    BF_S(left,  right, 12); \
+    BF_S(right, left,  13); \
+    BF_S(left,  right, 14); \
+    BF_S(right, left,  15); \
+    BF_S(left,  right, 16); 
+
+#define BF_EXTRA_ROUNDS     \
+    BF_S(right, left,  17); \
+    BF_S(left,  right, 18); \
+    BF_S(right, left,  19); \
+    BF_S(left,  right, 20);
+
+
+// Used by key setup, no byte swapping
+void Blowfish::crypt_block(const word32 in[2], word32 out[2]) const
+{
+	word32 left  = in[0];
+	word32 right = in[1];
+
+	const word32* p = pbox_;
+    word32 tmp;
+
+	left ^= p[0];
+
+    BF_ROUNDS
+
+#if ROUNDS == 20
+    BF_EXTRA_ROUNDS
+#endif
+
+	right ^= p[ROUNDS + 1];
+
+	out[0] = right;
+	out[1] = left;
+}
+
+
+typedef BlockGetAndPut gpBlock;
+
+void Blowfish::ProcessAndXorBlock(const byte* in, const byte* xOr, byte* out)
+    const
+{
+    word32 tmp, left, right;
+    const word32* p = pbox_;
+    
+    gpBlock::Get(in)(left)(right);
+	left ^= p[0];
+
+    BF_ROUNDS
+
+#if ROUNDS == 20
+    BF_EXTRA_ROUNDS
+#endif
+
+	right ^= p[ROUNDS + 1];
+
+    gpBlock::Put(xOr, out)(right)(left);
+}
+
+
+#if defined(DO_BLOWFISH_ASM)
+    #ifdef __GNUC__
+        #define AS1(x)    asm(#x);
+        #define AS2(x, y) asm(#x ", " #y);
+
+        #define PROLOG()  \
+            asm(".intel_syntax noprefix"); \
+            AS2(    movd  mm3, edi                      )   \
+            AS2(    movd  mm4, ebx                      )   \
+            AS2(    movd  mm5, esi                      )   \
+            AS2(    mov   ecx, DWORD PTR [ebp +  8]     )   \
+            AS2(    mov   esi, DWORD PTR [ebp + 12]     )
+
+        #define EPILOG()  \
+            AS2(    movd esi, mm5                  )   \
+            AS2(    movd ebx, mm4                  )   \
+            AS2(    movd edi, mm3                  )   \
+            AS1(    emms                           )   \
+            asm(".att_syntax");
+    #else
+        #define AS1(x)    __asm x
+        #define AS2(x, y) __asm x, y
+
+        #define PROLOG() \
+            AS1(    push  ebp                           )   \
+            AS2(    mov   ebp, esp                      )   \
+            AS2(    movd  mm3, edi                      )   \
+            AS2(    movd  mm4, ebx                      )   \
+            AS2(    movd  mm5, esi                      )   \
+            AS2(    mov   esi, DWORD PTR [ebp +  8]     )
+
+        #define EPILOG()  \
+            AS2(    movd esi, mm5                       )   \
+            AS2(    movd ebx, mm4                       )   \
+            AS2(    movd edi, mm3                       )   \
+            AS2(    mov  esp, ebp                       )   \
+            AS1(    pop  ebp                            )   \
+            AS1(    emms                                )   \
+            AS1(    ret 8                               )
+            
+    #endif
+
+
+#define BF_ROUND(P, G, I)   \
+    /* Put ^= p[I]  */                              \
+    AS2(    xor   P,   [edi + I*4]              )   \
+    /* tmp =  p[18 + BFBYTE_3(Get)] */              \
+    AS2(    mov   ecx, G                        )   \
+    AS2(    shr   ecx, 16                       )   \
+    AS2(    movzx edx, ch                       )   \
+    AS2(    mov   esi, [edi + edx*4 +   72]     )   \
+    /* tmp += p[274+ BFBYTE_2(Get)] */              \
+    AS2(    movzx ecx, cl                       )   \
+    AS2(    add   esi, [edi + ecx*4 + 1096]     )   \
+    /* tmp ^= p[530+ BFBYTE_1(Get)] */              \
+    AS2(    mov   ecx, G                        )   \
+    AS2(    movzx edx, ch                       )   \
+    AS2(    xor   esi, [edi + edx*4 + 2120]     )   \
+    /* tmp += p[786+ BFBYTE_0(Get)] */              \
+    AS2(    movzx ecx, cl                       )   \
+    AS2(    add   esi, [edi + ecx*4 + 3144]     )   \
+    /* Put ^= tmp */                                \
+    AS2(    xor   P,   esi                      )
+
+
+#ifdef _MSC_VER
+    __declspec(naked) 
+#endif
+void Blowfish::AsmProcess(const byte* inBlock, byte* outBlock) const
+{
+    PROLOG()
+
+    #ifdef OLD_GCC_OFFSET
+        AS2(    lea   edi, [ecx + 60]                       )   // pbox
+    #else
+        AS2(    lea   edi, [ecx + 56]                       )   // pbox
+    #endif
+
+    AS2(    mov   eax, DWORD PTR [esi]                                  )
+    AS2(    mov   edx, DWORD PTR [edi]                                  )
+    AS1(    bswap eax                                                   )
+
+    AS2(    mov   ebx, DWORD PTR [esi + 4]                              )
+    AS2(    xor   eax, edx                      )   // left
+    AS1(    bswap ebx                           )   // right
+
+
+    BF_ROUND(ebx, eax, 1)
+    BF_ROUND(eax, ebx, 2)
+    BF_ROUND(ebx, eax, 3)
+    BF_ROUND(eax, ebx, 4)
+    BF_ROUND(ebx, eax, 5)
+    BF_ROUND(eax, ebx, 6)
+    BF_ROUND(ebx, eax, 7)
+    BF_ROUND(eax, ebx, 8)
+    BF_ROUND(ebx, eax, 9)
+    BF_ROUND(eax, ebx, 10)
+    BF_ROUND(ebx, eax, 11)
+    BF_ROUND(eax, ebx, 12)
+    BF_ROUND(ebx, eax, 13)
+    BF_ROUND(eax, ebx, 14)
+    BF_ROUND(ebx, eax, 15)
+    BF_ROUND(eax, ebx, 16)
+    #if ROUNDS == 20
+        BF_ROUND(ebx, eax, 17)
+        BF_ROUND(eax, ebx, 18)
+        BF_ROUND(ebx, eax, 19)
+        BF_ROUND(eax, ebx, 20)
+
+        AS2(    xor   ebx, [edi + 84]           )   // 20 + 1 (x4)
+    #else
+        AS2(    xor   ebx, [edi + 68]           )   // 16 + 1 (x4)
+    #endif
+
+    #ifdef __GNUC__
+        AS2(    mov   edi, [ebp + 16]           ) // outBlock
+    #else
+        AS2(    mov   edi, [ebp + 12]           ) // outBlock
+    #endif
+
+    AS1(    bswap ebx                           )
+    AS1(    bswap eax                           )
+
+    AS2(    mov   [edi]    , ebx                )
+    AS2(    mov   [edi + 4], eax                )
+
+    EPILOG()
+}
+
+
+#endif  // DO_BLOWFISH_ASM
+
+
+} // namespace
+
diff --git a/extra/yassl/taocrypt/src/coding.cpp b/extra/yassl/taocrypt/src/coding.cpp
index 944a47c288e..01ea399df13 100644
--- a/extra/yassl/taocrypt/src/coding.cpp
+++ b/extra/yassl/taocrypt/src/coding.cpp
@@ -130,7 +130,7 @@ void Base64Encoder::Encode()
     word32 outSz = bytes * 4 / 3;
     outSz += (outSz % 4);           // 4 byte integrals         
 
-    outSz += outSz / pemLineSz + ( (outSz % pemLineSz) ? 1 : 0);  // new lines
+    outSz += (outSz + pemLineSz - 1) / pemLineSz;  // new lines
     encoded_.New(outSz);
 
     word32 i = 0;
@@ -187,9 +187,8 @@ void Base64Encoder::Encode()
 void Base64Decoder::Decode()
 {
     word32 bytes = coded_.size();
-    word32 plainSz = bytes - (bytes / pemLineSz + ( (bytes % pemLineSz) ? 
-                                                                      1 : 0));
-    plainSz = plainSz * 3 / 4 + (( (plainSz * 3) % 4) ? 1 : 0);
+    word32 plainSz = bytes - ((bytes + (pemLineSz - 1)) / pemLineSz); 
+    plainSz = (plainSz * 3 + 3) / 4;
     decoded_.New(plainSz);
 
     word32 i = 0;
diff --git a/extra/yassl/taocrypt/src/des.cpp b/extra/yassl/taocrypt/src/des.cpp
index e5d3331500c..d2db4fc939e 100644
--- a/extra/yassl/taocrypt/src/des.cpp
+++ b/extra/yassl/taocrypt/src/des.cpp
@@ -19,14 +19,25 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
  */
 
-/* based on Wei Dai's des.cpp from CryptoPP */
+/* C++ part based on Wei Dai's des.cpp from CryptoPP */
+/* x86 asm is original */
+
+
+#if defined(TAOCRYPT_KERNEL_MODE)
+    #define DO_TAOCRYPT_KERNEL_MODE
+#endif                                  // only some modules now support this
+
 
 #include "runtime.hpp"
 #include "des.hpp"
-#include 
 #include "algorithm.hpp"    // mySTL::swap
 
 
+#if defined(TAOCRYPT_X86ASM_AVAILABLE) && defined(TAO_ASM)
+    #define DO_DES_ASM
+#endif
+
+
 namespace TaoCrypt {
 
 
@@ -67,101 +78,7 @@ static const int bytebit[] = {
        0200,0100,040,020,010,04,02,01
 };
 
-
-void DES::SetKey(const byte* key, word32 /*length*/, CipherDir dir)
-{
-    byte buffer[56+56+8];
-    byte *const pc1m = buffer;                 /* place to modify pc1 into */
-    byte *const pcr = pc1m + 56;               /* place to rotate pc1 into */
-    byte *const ks = pcr + 56;
-    register int i,j,l;
-    int m;
-
-    for (j = 0; j < 56; j++) {          /* convert pc1 to bits of key */
-        l = pc1[j] - 1;                 /* integer bit location  */
-        m = l & 07;                     /* find bit              */
-        pc1m[j] = (key[l >> 3] &        /* find which key byte l is in */
-            bytebit[m])                 /* and which bit of that byte */
-            ? 1 : 0;                    /* and store 1-bit result */
-    }
-    for (i = 0; i < 16; i++) {          /* key chunk for each iteration */
-        memset(ks, 0, 8);               /* Clear key schedule */
-        for (j = 0; j < 56; j++)        /* rotate pc1 the right amount */
-            pcr[j] = pc1m[(l = j + totrot[i]) < (j < 28 ? 28 : 56) ? l: l-28];
-        /* rotate left and right halves independently */
-        for (j = 0; j < 48; j++){   /* select bits individually */
-            /* check bit that goes to ks[j] */
-            if (pcr[pc2[j] - 1]){
-                /* mask it in if it's there */
-                l= j % 6;
-                ks[j/6] |= bytebit[l] >> 2;
-            }
-        }
-        /* Now convert to odd/even interleaved form for use in F */
-        k_[2*i] = ((word32)ks[0] << 24)
-            | ((word32)ks[2] << 16)
-            | ((word32)ks[4] << 8)
-            | ((word32)ks[6]);
-        k_[2*i + 1] = ((word32)ks[1] << 24)
-            | ((word32)ks[3] << 16)
-            | ((word32)ks[5] << 8)
-            | ((word32)ks[7]);
-    }
-    
-    // reverse key schedule order
-    if (dir == DECRYPTION)
-        for (i = 0; i < 16; i += 2) {
-            mySTL::swap(k_[i],   k_[32 - 2 - i]);
-            mySTL::swap(k_[i+1], k_[32 - 1 - i]);
-        }
-   
-}
-
-static inline void IPERM(word32& left, word32& right)
-{
-    word32 work;
-
-    right = rotlFixed(right, 4U);
-    work = (left ^ right) & 0xf0f0f0f0;
-    left ^= work;
-    right = rotrFixed(right^work, 20U);
-    work = (left ^ right) & 0xffff0000;
-    left ^= work;
-    right = rotrFixed(right^work, 18U);
-    work = (left ^ right) & 0x33333333;
-    left ^= work;
-    right = rotrFixed(right^work, 6U);
-    work = (left ^ right) & 0x00ff00ff;
-    left ^= work;
-    right = rotlFixed(right^work, 9U);
-    work = (left ^ right) & 0xaaaaaaaa;
-    left = rotlFixed(left^work, 1U);
-    right ^= work;
-}
-
-static inline void FPERM(word32& left, word32& right)
-{
-    word32 work;
-
-    right = rotrFixed(right, 1U);
-    work = (left ^ right) & 0xaaaaaaaa;
-    right ^= work;
-    left = rotrFixed(left^work, 9U);
-    work = (left ^ right) & 0x00ff00ff;
-    right ^= work;
-    left = rotlFixed(left^work, 6U);
-    work = (left ^ right) & 0x33333333;
-    right ^= work;
-    left = rotlFixed(left^work, 18U);
-    work = (left ^ right) & 0xffff0000;
-    right ^= work;
-    left = rotlFixed(left^work, 20U);
-    work = (left ^ right) & 0xf0f0f0f0;
-    right ^= work;
-    left = rotrFixed(left^work, 4U);
-}
-
-const word32 Spbox[DES::BOXES][DES::BOX_SIZE] = {
+const word32 Spbox[8][64] = {
 {
 0x01010400,0x00000000,0x00010000,0x01010404,
 0x01010004,0x00010404,0x00000004,0x00010000,
@@ -301,8 +218,105 @@ const word32 Spbox[DES::BOXES][DES::BOX_SIZE] = {
 };
 
 
+void BasicDES::SetKey(const byte* key, word32 /*length*/, CipherDir dir)
+{
+    byte buffer[56+56+8];
+    byte *const pc1m = buffer;                 /* place to modify pc1 into */
+    byte *const pcr = pc1m + 56;               /* place to rotate pc1 into */
+    byte *const ks = pcr + 56;
+    register int i,j,l;
+    int m;
 
-void DES::RawProcessBlock(word32& lIn, word32& rIn) const
+    for (j = 0; j < 56; j++) {          /* convert pc1 to bits of key */
+        l = pc1[j] - 1;                 /* integer bit location  */
+        m = l & 07;                     /* find bit              */
+        pc1m[j] = (key[l >> 3] &        /* find which key byte l is in */
+            bytebit[m])                 /* and which bit of that byte */
+            ? 1 : 0;                    /* and store 1-bit result */
+    }
+    for (i = 0; i < 16; i++) {          /* key chunk for each iteration */
+        memset(ks, 0, 8);               /* Clear key schedule */
+        for (j = 0; j < 56; j++)        /* rotate pc1 the right amount */
+            pcr[j] = pc1m[(l = j + totrot[i]) < (j < 28 ? 28 : 56) ? l: l-28];
+        /* rotate left and right halves independently */
+        for (j = 0; j < 48; j++){   /* select bits individually */
+            /* check bit that goes to ks[j] */
+            if (pcr[pc2[j] - 1]){
+                /* mask it in if it's there */
+                l= j % 6;
+                ks[j/6] |= bytebit[l] >> 2;
+            }
+        }
+        /* Now convert to odd/even interleaved form for use in F */
+        k_[2*i] = ((word32)ks[0] << 24)
+            | ((word32)ks[2] << 16)
+            | ((word32)ks[4] << 8)
+            | ((word32)ks[6]);
+        k_[2*i + 1] = ((word32)ks[1] << 24)
+            | ((word32)ks[3] << 16)
+            | ((word32)ks[5] << 8)
+            | ((word32)ks[7]);
+    }
+    
+    // reverse key schedule order
+    if (dir == DECRYPTION)
+        for (i = 0; i < 16; i += 2) {
+            mySTL::swap(k_[i],   k_[32 - 2 - i]);
+            mySTL::swap(k_[i+1], k_[32 - 1 - i]);
+        }
+   
+}
+
+static inline void IPERM(word32& left, word32& right)
+{
+    word32 work;
+
+    right = rotlFixed(right, 4U);
+    work = (left ^ right) & 0xf0f0f0f0;
+    left ^= work;
+
+    right = rotrFixed(right^work, 20U);
+    work = (left ^ right) & 0xffff0000;
+    left ^= work;
+
+    right = rotrFixed(right^work, 18U);
+    work = (left ^ right) & 0x33333333;
+    left ^= work;
+
+    right = rotrFixed(right^work, 6U);
+    work = (left ^ right) & 0x00ff00ff;
+    left ^= work;
+
+    right = rotlFixed(right^work, 9U);
+    work = (left ^ right) & 0xaaaaaaaa;
+    left = rotlFixed(left^work, 1U);
+    right ^= work;
+}
+
+static inline void FPERM(word32& left, word32& right)
+{
+    word32 work;
+
+    right = rotrFixed(right, 1U);
+    work = (left ^ right) & 0xaaaaaaaa;
+    right ^= work;
+    left = rotrFixed(left^work, 9U);
+    work = (left ^ right) & 0x00ff00ff;
+    right ^= work;
+    left = rotlFixed(left^work, 6U);
+    work = (left ^ right) & 0x33333333;
+    right ^= work;
+    left = rotlFixed(left^work, 18U);
+    work = (left ^ right) & 0xffff0000;
+    right ^= work;
+    left = rotlFixed(left^work, 20U);
+    work = (left ^ right) & 0xf0f0f0f0;
+    right ^= work;
+    left = rotrFixed(left^work, 4U);
+}
+
+
+void BasicDES::RawProcessBlock(word32& lIn, word32& rIn) const
 {
     word32 l = lIn, r = rIn;
     const word32* kptr = k_;
@@ -336,7 +350,7 @@ void DES::RawProcessBlock(word32& lIn, word32& rIn) const
 }
 
 
-void DES_BASE::Process(byte* out, const byte* in, word32 sz)
+void DES::Process(byte* out, const byte* in, word32 sz)
 {
     if (mode_ == ECB)
         ECB_Process(out, in, sz);
@@ -358,38 +372,24 @@ void DES::ProcessAndXorBlock(const byte* in, const byte* xOr, byte* out) const
     Block::Get(in)(l)(r);
     IPERM(l,r);
 
-    const word32* kptr = k_;
-
-    for (unsigned i = 0; i < 8; i++)
-    {
-        word32 work = rotrFixed(r, 4U) ^ kptr[4*i+0];
-        l ^= Spbox[6][(work) & 0x3f]
-          ^  Spbox[4][(work >> 8) & 0x3f]
-          ^  Spbox[2][(work >> 16) & 0x3f]
-          ^  Spbox[0][(work >> 24) & 0x3f];
-        work = r ^ kptr[4*i+1];
-        l ^= Spbox[7][(work) & 0x3f]
-          ^  Spbox[5][(work >> 8) & 0x3f]
-          ^  Spbox[3][(work >> 16) & 0x3f]
-          ^  Spbox[1][(work >> 24) & 0x3f];
-
-        work = rotrFixed(l, 4U) ^ kptr[4*i+2];
-        r ^= Spbox[6][(work) & 0x3f]
-          ^  Spbox[4][(work >> 8) & 0x3f]
-          ^  Spbox[2][(work >> 16) & 0x3f]
-          ^  Spbox[0][(work >> 24) & 0x3f];
-        work = l ^ kptr[4*i+3];
-        r ^= Spbox[7][(work) & 0x3f]
-          ^  Spbox[5][(work >> 8) & 0x3f]
-          ^  Spbox[3][(work >> 16) & 0x3f]
-          ^  Spbox[1][(work >> 24) & 0x3f];
-    }
+    RawProcessBlock(l, r);
 
     FPERM(l,r);
     Block::Put(xOr, out)(r)(l);
 }
 
 
+void DES_EDE2::Process(byte* out, const byte* in, word32 sz)
+{
+    if (mode_ == ECB)
+        ECB_Process(out, in, sz);
+    else if (mode_ == CBC)
+        if (dir_ == ENCRYPTION)
+            CBC_Encrypt(out, in, sz);
+        else
+            CBC_Decrypt(out, in, sz);
+}
+
 void DES_EDE2::SetKey(const byte* key, word32 sz, CipherDir dir)
 {
     des1_.SetKey(key, sz, dir);
@@ -403,9 +403,11 @@ void DES_EDE2::ProcessAndXorBlock(const byte* in, const byte* xOr,
     word32 l,r;
     Block::Get(in)(l)(r);
     IPERM(l,r);
+
     des1_.RawProcessBlock(l, r);
     des2_.RawProcessBlock(r, l);
     des1_.RawProcessBlock(l, r);
+
     FPERM(l,r);
     Block::Put(xOr, out)(r)(l);
 }
@@ -418,18 +420,389 @@ void DES_EDE3::SetKey(const byte* key, word32 sz, CipherDir dir)
     des3_.SetKey(key+(dir==DECRYPTION?0:2*8), sz, dir);
 }
 
+
+
+#if !defined(DO_DES_ASM)
+
+// Generic Version
+void DES_EDE3::Process(byte* out, const byte* in, word32 sz)
+{
+    if (mode_ == ECB)
+        ECB_Process(out, in, sz);
+    else if (mode_ == CBC)
+        if (dir_ == ENCRYPTION)
+            CBC_Encrypt(out, in, sz);
+        else
+            CBC_Decrypt(out, in, sz);
+}
+
+#else
+
+// ia32 optimized version
+void DES_EDE3::Process(byte* out, const byte* in, word32 sz)
+{
+    word32 blocks = sz / DES_BLOCK_SIZE;
+
+    if (mode_ == CBC)    
+        if (dir_ == ENCRYPTION)
+            while (blocks--) {
+                r_[0] ^= *(word32*)in;
+                r_[1] ^= *(word32*)(in + 4);
+
+                AsmProcess((byte*)r_, (byte*)r_, (void*)Spbox);
+                
+                memcpy(out, r_, DES_BLOCK_SIZE);
+
+                in  += DES_BLOCK_SIZE;
+                out += DES_BLOCK_SIZE;
+            }
+        else
+            while (blocks--) {
+                AsmProcess(in, out, (void*)Spbox);
+               
+                *(word32*)out       ^= r_[0];
+                *(word32*)(out + 4) ^= r_[1];
+
+                memcpy(r_, in, DES_BLOCK_SIZE);
+
+                out += DES_BLOCK_SIZE;
+                in  += DES_BLOCK_SIZE;
+            }
+    else
+        while (blocks--) {
+            AsmProcess(in, out, (void*)Spbox);
+           
+            out += DES_BLOCK_SIZE;
+            in  += DES_BLOCK_SIZE;
+        }
+}
+
+#endif // DO_DES_ASM
+
+
 void DES_EDE3::ProcessAndXorBlock(const byte* in, const byte* xOr,
                                   byte* out) const
 {
     word32 l,r;
     Block::Get(in)(l)(r);
     IPERM(l,r);
+
     des1_.RawProcessBlock(l, r);
     des2_.RawProcessBlock(r, l);
     des3_.RawProcessBlock(l, r);
+
     FPERM(l,r);
     Block::Put(xOr, out)(r)(l);
 }
 
 
+#if defined(DO_DES_ASM)
+
+/* Uses IPERM algorithm from above
+
+   left  is in eax
+   right is in ebx
+
+   uses ecx
+*/
+#define AsmIPERM() {\
+    AS2(    rol   ebx, 4                        )   \
+    AS2(    mov   ecx, eax                      )   \
+    AS2(    xor   ecx, ebx                      )   \
+    AS2(    and   ecx, 0xf0f0f0f0               )   \
+    AS2(    xor   ebx, ecx                      )   \
+    AS2(    xor   eax, ecx                      )   \
+    AS2(    ror   ebx, 20                       )   \
+    AS2(    mov   ecx, eax                      )   \
+    AS2(    xor   ecx, ebx                      )   \
+    AS2(    and   ecx, 0xffff0000               )   \
+    AS2(    xor   ebx, ecx                      )   \
+    AS2(    xor   eax, ecx                      )   \
+    AS2(    ror   ebx, 18                       )   \
+    AS2(    mov   ecx, eax                      )   \
+    AS2(    xor   ecx, ebx                      )   \
+    AS2(    and   ecx, 0x33333333               )   \
+    AS2(    xor   ebx, ecx                      )   \
+    AS2(    xor   eax, ecx                      )   \
+    AS2(    ror   ebx, 6                        )   \
+    AS2(    mov   ecx, eax                      )   \
+    AS2(    xor   ecx, ebx                      )   \
+    AS2(    and   ecx, 0x00ff00ff               )   \
+    AS2(    xor   ebx, ecx                      )   \
+    AS2(    xor   eax, ecx                      )   \
+    AS2(    rol   ebx, 9                        )   \
+    AS2(    mov   ecx, eax                      )   \
+    AS2(    xor   ecx, ebx                      )   \
+    AS2(    and   ecx, 0xaaaaaaaa               )   \
+    AS2(    xor   eax, ecx                      )   \
+    AS2(    rol   eax, 1                        )   \
+    AS2(    xor   ebx, ecx                      ) }
+
+
+/* Uses FPERM algorithm from above
+
+   left  is in eax
+   right is in ebx
+
+   uses ecx
+*/
+#define AsmFPERM()    {\
+    AS2(    ror  ebx, 1                     )    \
+    AS2(    mov  ecx, eax                   )    \
+    AS2(    xor  ecx, ebx                   )    \
+    AS2(    and  ecx, 0xaaaaaaaa            )    \
+    AS2(    xor  eax, ecx                   )    \
+    AS2(    xor  ebx, ecx                   )    \
+    AS2(    ror  eax, 9                     )    \
+    AS2(    mov  ecx, ebx                   )    \
+    AS2(    xor  ecx, eax                   )    \
+    AS2(    and  ecx, 0x00ff00ff            )    \
+    AS2(    xor  eax, ecx                   )    \
+    AS2(    xor  ebx, ecx                   )    \
+    AS2(    rol  eax, 6                     )    \
+    AS2(    mov  ecx, ebx                   )    \
+    AS2(    xor  ecx, eax                   )    \
+    AS2(    and  ecx, 0x33333333            )    \
+    AS2(    xor  eax, ecx                   )    \
+    AS2(    xor  ebx, ecx                   )    \
+    AS2(    rol  eax, 18                    )    \
+    AS2(    mov  ecx, ebx                   )    \
+    AS2(    xor  ecx, eax                   )    \
+    AS2(    and  ecx, 0xffff0000            )    \
+    AS2(    xor  eax, ecx                   )    \
+    AS2(    xor  ebx, ecx                   )    \
+    AS2(    rol  eax, 20                    )    \
+    AS2(    mov  ecx, ebx                   )    \
+    AS2(    xor  ecx, eax                   )    \
+    AS2(    and  ecx, 0xf0f0f0f0            )    \
+    AS2(    xor  eax, ecx                   )    \
+    AS2(    xor  ebx, ecx                   )    \
+    AS2(    ror  eax, 4                     ) }
+
+
+
+
+/* DesRound implements this algorithm:
+
+        word32 work = rotrFixed(r, 4U) ^ key[0];
+        l ^= Spbox[6][(work) & 0x3f]
+          ^  Spbox[4][(work >> 8) & 0x3f]
+          ^  Spbox[2][(work >> 16) & 0x3f]
+          ^  Spbox[0][(work >> 24) & 0x3f];
+        work = r ^ key[1];
+        l ^= Spbox[7][(work) & 0x3f]
+          ^  Spbox[5][(work >> 8) & 0x3f]
+          ^  Spbox[3][(work >> 16) & 0x3f]
+          ^  Spbox[1][(work >> 24) & 0x3f];
+
+        work = rotrFixed(l, 4U) ^ key[2];
+        r ^= Spbox[6][(work) & 0x3f]
+          ^  Spbox[4][(work >> 8) & 0x3f]
+          ^  Spbox[2][(work >> 16) & 0x3f]
+          ^  Spbox[0][(work >> 24) & 0x3f];
+        work = l ^ key[3];
+        r ^= Spbox[7][(work) & 0x3f]
+          ^  Spbox[5][(work >> 8) & 0x3f]
+          ^  Spbox[3][(work >> 16) & 0x3f]
+          ^  Spbox[1][(work >> 24) & 0x3f];
+
+   left  is in aex
+   right is in ebx
+   key   is in edx
+
+   edvances key for next round
+
+   uses ecx, esi, and edi
+*/
+#define DesRound() \
+    AS2(    mov   ecx,  ebx                     )\
+    AS2(    mov   esi,  DWORD PTR [edx]         )\
+    AS2(    ror   ecx,  4                       )\
+    AS2(    xor   ecx,  esi                     )\
+    AS2(    and   ecx,  0x3f3f3f3f              )\
+    AS2(    movzx esi,  cl                      )\
+    AS2(    movzx edi,  ch                      )\
+    AS2(    xor   eax,  [ebp + esi*4 + 6*256]   )\
+    AS2(    shr   ecx,  16                      )\
+    AS2(    xor   eax,  [ebp + edi*4 + 4*256]   )\
+    AS2(    movzx esi,  cl                      )\
+    AS2(    movzx edi,  ch                      )\
+    AS2(    xor   eax,  [ebp + esi*4 + 2*256]   )\
+    AS2(    mov   esi,  DWORD PTR [edx + 4]     )\
+    AS2(    xor   eax,  [ebp + edi*4]           )\
+    AS2(    mov   ecx,  ebx                     )\
+    AS2(    xor   ecx,  esi                     )\
+    AS2(    and   ecx,  0x3f3f3f3f              )\
+    AS2(    movzx esi,  cl                      )\
+    AS2(    movzx edi,  ch                      )\
+    AS2(    xor   eax,  [ebp + esi*4 + 7*256]   )\
+    AS2(    shr   ecx,  16                      )\
+    AS2(    xor   eax,  [ebp + edi*4 + 5*256]   )\
+    AS2(    movzx esi,  cl                      )\
+    AS2(    movzx edi,  ch                      )\
+    AS2(    xor   eax,  [ebp + esi*4 + 3*256]   )\
+    AS2(    mov   esi,  DWORD PTR [edx + 8]     )\
+    AS2(    xor   eax,  [ebp + edi*4 + 1*256]   )\
+    AS2(    mov   ecx,  eax                     )\
+    AS2(    ror   ecx,  4                       )\
+    AS2(    xor   ecx,  esi                     )\
+    AS2(    and   ecx,  0x3f3f3f3f              )\
+    AS2(    movzx esi,  cl                      )\
+    AS2(    movzx edi,  ch                      )\
+    AS2(    xor   ebx,  [ebp + esi*4 + 6*256]   )\
+    AS2(    shr   ecx,  16                      )\
+    AS2(    xor   ebx,  [ebp + edi*4 + 4*256]   )\
+    AS2(    movzx esi,  cl                      )\
+    AS2(    movzx edi,  ch                      )\
+    AS2(    xor   ebx,  [ebp + esi*4 + 2*256]   )\
+    AS2(    mov   esi,  DWORD PTR [edx + 12]    )\
+    AS2(    xor   ebx,  [ebp + edi*4]           )\
+    AS2(    mov   ecx,  eax                     )\
+    AS2(    xor   ecx,  esi                     )\
+    AS2(    and   ecx,  0x3f3f3f3f              )\
+    AS2(    movzx esi,  cl                      )\
+    AS2(    movzx edi,  ch                      )\
+    AS2(    xor   ebx,  [ebp + esi*4 + 7*256]   )\
+    AS2(    shr   ecx,  16                      )\
+    AS2(    xor   ebx,  [ebp + edi*4 + 5*256]   )\
+    AS2(    movzx esi,  cl                      )\
+    AS2(    movzx edi,  ch                      )\
+    AS2(    xor   ebx,  [ebp + esi*4 + 3*256]   )\
+    AS2(    add   edx,  16                      )\
+    AS2(    xor   ebx,  [ebp + edi*4 + 1*256]   )
+
+
+#ifdef _MSC_VER
+    __declspec(naked) 
+#endif
+void DES_EDE3::AsmProcess(const byte* in, byte* out, void* box) const
+{
+#ifdef __GNUC__
+    #define AS1(x)    asm(#x);
+    #define AS2(x, y) asm(#x ", " #y);
+
+    asm(".intel_syntax noprefix");
+
+    #define PROLOG()  \
+        AS2(    movd  mm3, edi                      )   \
+        AS2(    movd  mm4, ebx                      )   \
+        AS2(    movd  mm5, esi                      )   \
+        AS2(    movd  mm6, ebp                      )   \
+        AS2(    mov   edx, DWORD PTR [ebp +  8]     )   \
+        AS2(    mov   esi, DWORD PTR [ebp + 12]     )   \
+        AS2(    mov   ebp, DWORD PTR [ebp + 20]     )
+
+    // ebp restored at end
+    #define EPILOG()    \
+        AS2(    movd  edi, mm3                      )   \
+        AS2(    movd  ebx, mm4                      )   \
+        AS2(    movd  esi, mm5                      )   \
+        AS1(    emms                                )   \
+        asm(".att_syntax");
+
+#else
+    #define AS1(x)      __asm x
+    #define AS2(x, y)   __asm x, y
+
+    #define PROLOG()  \
+        AS1(    push  ebp                           )   \
+        AS2(    mov   ebp, esp                      )   \
+        AS2(    movd  mm3, edi                      )   \
+        AS2(    movd  mm4, ebx                      )   \
+        AS2(    movd  mm5, esi                      )   \
+        AS2(    movd  mm6, ebp                      )   \
+        AS2(    mov   esi, DWORD PTR [ebp +  8]     )   \
+        AS2(    mov   edx, ecx                      )   \
+        AS2(    mov   ebp, DWORD PTR [ebp + 16]     )
+
+    // ebp restored at end
+    #define EPILOG() \
+        AS2(    movd  edi, mm3                      )   \
+        AS2(    movd  ebx, mm4                      )   \
+        AS2(    movd  esi, mm5                      )   \
+        AS2(    mov   esp, ebp                      )   \
+        AS1(    pop   ebp                           )   \
+        AS1(    emms                                )   \
+        AS1(    ret 12                              )
+
+#endif
+
+
+    PROLOG()
+
+    AS2(    movd  mm2, edx                      )
+
+    #ifdef OLD_GCC_OFFSET
+        AS2(    add   edx, 60                       )   // des1 = des1 key
+    #else
+        AS2(    add   edx, 56                       )   // des1 = des1 key
+    #endif
+
+    AS2(    mov   eax, DWORD PTR [esi]          )
+    AS2(    mov   ebx, DWORD PTR [esi + 4]      )
+    AS1(    bswap eax                           )    // left
+    AS1(    bswap ebx                           )    // right
+
+    AsmIPERM()
+
+    DesRound() // 1
+    DesRound() // 2
+    DesRound() // 3
+    DesRound() // 4
+    DesRound() // 5
+    DesRound() // 6
+    DesRound() // 7
+    DesRound() // 8
+
+    // swap left and right 
+    AS2(    xchg  eax, ebx                      )
+
+    DesRound() // 1
+    DesRound() // 2
+    DesRound() // 3
+    DesRound() // 4
+    DesRound() // 5
+    DesRound() // 6
+    DesRound() // 7
+    DesRound() // 8
+
+    // swap left and right
+    AS2(    xchg  eax, ebx                      )
+
+    DesRound() // 1
+    DesRound() // 2
+    DesRound() // 3
+    DesRound() // 4
+    DesRound() // 5
+    DesRound() // 6
+    DesRound() // 7
+    DesRound() // 8
+
+    AsmFPERM()
+
+    //end
+    AS2(    movd  ebp, mm6                      )
+
+    // swap and write out
+    AS1(    bswap ebx                           )
+    AS1(    bswap eax                           )
+
+#ifdef __GNUC__
+    AS2(    mov   esi, DWORD PTR [ebp +  16]    )   // outBlock
+#else
+    AS2(    mov   esi, DWORD PTR [ebp +  12]    )   // outBlock
+#endif
+
+    AS2(    mov   DWORD PTR [esi],     ebx      )   // right first
+    AS2(    mov   DWORD PTR [esi + 4], eax      )
+    
+
+    EPILOG()
+}
+
+
+
+#endif // defined(DO_DES_ASM)
+
+
 }  // namespace
diff --git a/extra/yassl/taocrypt/src/dh.cpp b/extra/yassl/taocrypt/src/dh.cpp
index ea1b5846f7d..44934394343 100644
--- a/extra/yassl/taocrypt/src/dh.cpp
+++ b/extra/yassl/taocrypt/src/dh.cpp
@@ -26,10 +26,26 @@
 #include "runtime.hpp"
 #include "dh.hpp"
 #include "asn.hpp"
+#include 
 
 namespace TaoCrypt {
 
 
+namespace {  // locals
+
+unsigned int DiscreteLogWorkFactor(unsigned int n)
+{
+    // assuming discrete log takes about the same time as factoring
+    if (n<5)
+        return 0;
+    else
+        return (unsigned int)(2.4 * pow((double)n, 1.0/3.0) *
+                pow(log(double(n)), 2.0/3.0) - 5);
+}
+
+} // namespace locals
+
+
 // Generate a DH Key Pair
 void DH::GenerateKeyPair(RandomNumberGenerator& rng, byte* priv, byte* pub)
 {
@@ -41,7 +57,8 @@ void DH::GenerateKeyPair(RandomNumberGenerator& rng, byte* priv, byte* pub)
 // Generate private value
 void DH::GeneratePrivate(RandomNumberGenerator& rng, byte* priv)
 {
-    Integer x(rng, Integer::One(), p_ - 1);
+    Integer x(rng, Integer::One(), mySTL::min(p_ - 1,
+        Integer::Power2(2*DiscreteLogWorkFactor(p_.BitCount())) ) );
     x.Encode(priv, p_.ByteCount());
 }
 
@@ -57,11 +74,16 @@ void DH::GeneratePublic(const byte* priv, byte* pub)
 
 
 // Generate Agreement
-void DH::Agree(byte* agree, const byte* priv, const byte* otherPub)
+void DH::Agree(byte* agree, const byte* priv, const byte* otherPub, word32
+               otherSz)
 {
     const word32 bc(p_.ByteCount());
     Integer x(priv, bc);
-    Integer y(otherPub, bc);
+    Integer y;
+    if (otherSz)
+        y.Decode(otherPub, otherSz);
+    else
+        y.Decode(otherPub, bc);
 
     Integer z(a_exp_b_mod_c(y, x, p_));
     z.Encode(agree, bc);
diff --git a/extra/yassl/taocrypt/src/hash.cpp b/extra/yassl/taocrypt/src/hash.cpp
index 53b1b489b14..4e783e2c3b1 100644
--- a/extra/yassl/taocrypt/src/hash.cpp
+++ b/extra/yassl/taocrypt/src/hash.cpp
@@ -39,6 +39,15 @@ HASHwithTransform::HASHwithTransform(word32 digSz, word32 buffSz)
 }
 
 
+void HASHwithTransform::AddLength(word32 len)
+{
+    HashLengthType tmp = loLen_;
+    if ( (loLen_ += len) < tmp)
+        hiLen_++;                       // carry low to high
+    hiLen_ += SafeRightShift<8*sizeof(HashLengthType)>(len);
+}
+
+
 // Update digest with data of size len, do in blocks
 void HASHwithTransform::Update(const byte* data, word32 len)
 {
@@ -57,6 +66,8 @@ void HASHwithTransform::Update(const byte* data, word32 len)
         if (buffLen_ == blockSz) {
             ByteReverseIf(local, local, blockSz, getByteOrder());
             Transform();
+            AddLength(blockSz);
+            buffLen_ = 0;
         }
     }
 }
@@ -69,25 +80,29 @@ void HASHwithTransform::Final(byte* hash)
     word32    digestSz  = getDigestSize();
     word32    padSz     = getPadSize();
     ByteOrder order     = getByteOrder();
-    word32    prePadLen = length_ + buffLen_ * 8;  // in bits
+
+    AddLength(buffLen_);                        // before adding pads
+    HashLengthType preLoLen = GetBitCountLo();
+    HashLengthType preHiLen = GetBitCountHi();
     byte*     local     = reinterpret_cast(buffer_);
 
     local[buffLen_++] = 0x80;  // add 1
 
     // pad with zeros
     if (buffLen_ > padSz) {
-        while (buffLen_ < blockSz) local[buffLen_++] = 0;
+        memset(&local[buffLen_], 0, blockSz - buffLen_);
+        buffLen_ += blockSz - buffLen_;
+
         ByteReverseIf(local, local, blockSz, order);
         Transform();
+        buffLen_ = 0;
     }
-    while (buffLen_ < padSz) local[buffLen_++] = 0;
+    memset(&local[buffLen_], 0, padSz - buffLen_);
 
     ByteReverseIf(local, local, blockSz, order);
     
-    word32 hiSize = 0;  // for future 64 bit length TODO:
-    memcpy(&local[padSz],   order ? &hiSize : &prePadLen, sizeof(prePadLen));
-    memcpy(&local[padSz+4], order ? &prePadLen : &hiSize, sizeof(prePadLen));
-
+    memcpy(&local[padSz],   order ? &preHiLen : &preLoLen, sizeof(preLoLen));
+    memcpy(&local[padSz+4], order ? &preLoLen : &preHiLen, sizeof(preLoLen));
 
     Transform();
     ByteReverseIf(digest_, digest_, digestSz, order);
diff --git a/extra/yassl/taocrypt/src/integer.cpp b/extra/yassl/taocrypt/src/integer.cpp
index 71324b04b92..083c5bf7d30 100644
--- a/extra/yassl/taocrypt/src/integer.cpp
+++ b/extra/yassl/taocrypt/src/integer.cpp
@@ -114,7 +114,7 @@ CPP_TYPENAME AllocatorBase::pointer AlignedAllocator::allocate(
         assert(IsAlignedOn(p, 16));
         return (T*)p;
     }
-    return new (tc) T[n];
+    return NEW_TC T[n];
 }
 
 
@@ -555,7 +555,7 @@ static word AtomicInverseModPower2(word A)
     for (unsigned i=3; i= BLOCK_SIZE) {
+                memcpy(&local[0], data, BLOCK_SIZE);
+
+                data     += BLOCK_SIZE;
+                len      -= BLOCK_SIZE;
+
+                ByteReverseIf(local, local, BLOCK_SIZE, LittleEndianOrder);
+                Transform();
+                AddLength(BLOCK_SIZE);
+            }
+        #else
+            word32 times = len / BLOCK_SIZE;
+            if (times) {
+                AsmTransform(data, times);
+                const word32 add = BLOCK_SIZE * times;
+                AddLength(add);
+                len  -= add;
+                data += add;
+            }
+        #endif
+    }
+
+    // cache any data left
+    if (len) {
+        memcpy(&local[buffLen_], data, len);
+        buffLen_ += len;
+    }
+}
+
+
+#ifdef DO_MD5_ASM
+
+
+/*
+    // w = rotlFixed(w + f(x, y, z) + index[edi] + data, s) + x
+#define ASMMD5STEP(f, w, x, y, z, index, data, s)       \
+    f(x, y, z)                                          \
+    AS2(    mov   ebp, [edi + index * 4]            )   \
+    AS2(    lea     w, [esi + w + data]             )   \
+    AS2(    add     w, ebp                          )   \
+    AS2(    rol     w, s                            )   \
+    AS2(    add     w, x                            )
+
+
+    // F1(x, y, z) (z ^ (x & (y ^ z)))
+    // place in esi
+#define ASMF1(x, y, z) \
+    AS2(    mov   esi, y                )   \
+    AS2(    xor   esi, z                )   \
+    AS2(    and   esi, x                )   \
+    AS2(    xor   esi, z                )
+
+
+#define ASMF2(x, y, z) ASMF1(z, x, y)
+
+
+    // F3(x ^ y ^ z)
+    // place in esi
+#define ASMF3(x, y, z)  \
+    AS2(    mov   esi, x                )   \
+    AS2(    xor   esi, y                )   \
+    AS2(    xor   esi, z                )
+
+
+
+    // F4(x, y, z) (y ^ (x | ~z))
+    // place in esi
+#define ASMF4(x, y, z)  \
+    AS2(    mov   esi, z                )   \
+    AS1(    not   esi                   )   \
+    AS2(     or   esi, x                )   \
+    AS2(    xor   esi, y                )
+*/
+
+
+    // combine above ASMMD5STEP(f w/ each f ASMF1 - F4
+
+    // esi already set up, after using set for next round
+    // ebp already set up, set up using next round index
+    
+#define MD5STEP1(w, x, y, z, index, data, s)    \
+    AS2(    xor   esi, z                    )   \
+    AS2(    and   esi, x                    )   \
+    AS2(    lea     w, [ebp + w + data]     )   \
+    AS2(    xor   esi, z                    )   \
+    AS2(    add     w, esi                  )   \
+    AS2(    mov   esi, x                    )   \
+    AS2(    rol     w, s                    )   \
+    AS2(    mov   ebp, [edi + index * 4]    )   \
+    AS2(    add     w, x                    )
+
+#define MD5STEP2(w, x, y, z, index, data, s)    \
+    AS2(    xor   esi, x                    )   \
+    AS2(    and   esi, z                    )   \
+    AS2(    lea     w, [ebp + w + data]     )   \
+    AS2(    xor   esi, y                    )   \
+    AS2(    add     w, esi                  )   \
+    AS2(    mov   esi, x                    )   \
+    AS2(    rol     w, s                    )   \
+    AS2(    mov   ebp, [edi + index * 4]    )   \
+    AS2(    add     w, x                    )
+
+
+#define MD5STEP3(w, x, y, z, index, data, s)    \
+    AS2(    xor   esi, z                    )   \
+    AS2(    lea     w, [ebp + w + data]     )   \
+    AS2(    xor   esi, x                    )   \
+    AS2(    add     w, esi                  )   \
+    AS2(    mov   esi, x                    )   \
+    AS2(    rol     w, s                    )   \
+    AS2(    mov   ebp, [edi + index * 4]    )   \
+    AS2(    add     w, x                    )
+
+
+#define MD5STEP4(w, x, y, z, index, data, s)    \
+    AS2(     or   esi, x                    )   \
+    AS2(    lea     w, [ebp + w + data]     )   \
+    AS2(    xor   esi, y                    )   \
+    AS2(    add     w, esi                  )   \
+    AS2(    mov   esi, y                    )   \
+    AS2(    rol     w, s                    )   \
+    AS1(    not   esi                       )   \
+    AS2(    mov   ebp, [edi + index * 4]    )   \
+    AS2(    add     w, x                    )
+
+
+
+#ifdef _MSC_VER
+    __declspec(naked) 
+#endif
+void MD5::AsmTransform(const byte* data, word32 times)
+{
+#ifdef __GNUC__
+    #define AS1(x)    asm(#x);
+    #define AS2(x, y) asm(#x ", " #y);
+
+    #define PROLOG()  \
+        asm(".intel_syntax noprefix"); \
+        AS2(    movd  mm3, edi                      )   \
+        AS2(    movd  mm4, ebx                      )   \
+        AS2(    movd  mm5, esi                      )   \
+        AS2(    movd  mm6, ebp                      )   \
+        AS2(    mov   ecx, DWORD PTR [ebp +  8]     )   \
+        AS2(    mov   edi, DWORD PTR [ebp + 12]     )   \
+        AS2(    mov   eax, DWORD PTR [ebp + 16]     )
+
+    #define EPILOG()  \
+        AS2(    movd  ebp, mm6                  )   \
+        AS2(    movd  esi, mm5                  )   \
+        AS2(    movd  ebx, mm4                  )   \
+        AS2(    mov   esp, ebp                  )   \
+        AS2(    movd  edi, mm3                  )   \
+        AS1(    emms                            )   \
+        asm(".att_syntax");
+#else
+    #define AS1(x)    __asm x
+    #define AS2(x, y) __asm x, y
+
+    #define PROLOG() \
+        AS1(    push  ebp                       )   \
+        AS2(    mov   ebp, esp                  )   \
+        AS2(    movd  mm3, edi                  )   \
+        AS2(    movd  mm4, ebx                  )   \
+        AS2(    movd  mm5, esi                  )   \
+        AS2(    movd  mm6, ebp                  )   \
+        AS2(    mov   edi, DWORD PTR [ebp +  8] )   \
+        AS2(    mov   eax, DWORD PTR [ebp + 12] )
+
+    #define EPILOG() \
+        AS2(    movd  ebp, mm6                  )   \
+        AS2(    movd  esi, mm5                  )   \
+        AS2(    movd  ebx, mm4                  )   \
+        AS2(    movd  edi, mm3                  )   \
+        AS2(    mov   esp, ebp                  )   \
+        AS1(    pop   ebp                       )   \
+        AS1(    emms                            )   \
+        AS1(    ret  8                          )
+        
+#endif
+
+
+    PROLOG()
+
+    AS2(    mov   esi, ecx              )
+
+    #ifdef OLD_GCC_OFFSET
+        AS2(    add   esi, 20               )   // digest_[0]
+    #else
+        AS2(    add   esi, 16               )   // digest_[0]
+    #endif
+
+    AS2(    movd  mm2, eax              )   // store times_
+    AS2(    movd  mm1, esi              )   // store digest_
+    
+    AS2(    mov   eax, [esi]            )   // a
+    AS2(    mov   ebx, [esi +  4]       )   // b
+    AS2(    mov   ecx, [esi +  8]       )   // c
+    AS2(    mov   edx, [esi + 12]       )   // d
+  
+AS1(loopStart:)
+
+    // set up
+    AS2(    mov   esi, ecx      )
+    AS2(    mov   ebp, [edi]    )
+
+    MD5STEP1( eax, ebx, ecx, edx, 1,   0xd76aa478,  7)
+    MD5STEP1( edx, eax, ebx, ecx, 2,   0xe8c7b756, 12)
+    MD5STEP1( ecx, edx, eax, ebx, 3,   0x242070db, 17)
+    MD5STEP1( ebx, ecx, edx, eax, 4,   0xc1bdceee, 22)
+    MD5STEP1( eax, ebx, ecx, edx, 5,   0xf57c0faf,  7)
+    MD5STEP1( edx, eax, ebx, ecx, 6,   0x4787c62a, 12)
+    MD5STEP1( ecx, edx, eax, ebx, 7,   0xa8304613, 17)
+    MD5STEP1( ebx, ecx, edx, eax, 8,   0xfd469501, 22)
+    MD5STEP1( eax, ebx, ecx, edx, 9,   0x698098d8,  7)
+    MD5STEP1( edx, eax, ebx, ecx, 10,  0x8b44f7af, 12)
+    MD5STEP1( ecx, edx, eax, ebx, 11,  0xffff5bb1, 17)
+    MD5STEP1( ebx, ecx, edx, eax, 12,  0x895cd7be, 22)
+    MD5STEP1( eax, ebx, ecx, edx, 13,  0x6b901122,  7)
+    MD5STEP1( edx, eax, ebx, ecx, 14,  0xfd987193, 12)
+    MD5STEP1( ecx, edx, eax, ebx, 15,  0xa679438e, 17)
+    MD5STEP1( ebx, ecx, edx, eax, 1,   0x49b40821, 22)
+
+    MD5STEP2( eax, ebx, ecx, edx, 6,  0xf61e2562,  5)
+    MD5STEP2( edx, eax, ebx, ecx, 11, 0xc040b340,  9)
+    MD5STEP2( ecx, edx, eax, ebx, 0,  0x265e5a51, 14)
+    MD5STEP2( ebx, ecx, edx, eax, 5,  0xe9b6c7aa, 20)
+    MD5STEP2( eax, ebx, ecx, edx, 10, 0xd62f105d,  5)
+    MD5STEP2( edx, eax, ebx, ecx, 15, 0x02441453,  9)
+    MD5STEP2( ecx, edx, eax, ebx, 4,  0xd8a1e681, 14)
+    MD5STEP2( ebx, ecx, edx, eax, 9,  0xe7d3fbc8, 20)
+    MD5STEP2( eax, ebx, ecx, edx, 14, 0x21e1cde6,  5)
+    MD5STEP2( edx, eax, ebx, ecx, 3,  0xc33707d6,  9)
+    MD5STEP2( ecx, edx, eax, ebx, 8,  0xf4d50d87, 14)
+    MD5STEP2( ebx, ecx, edx, eax, 13, 0x455a14ed, 20)
+    MD5STEP2( eax, ebx, ecx, edx, 2,  0xa9e3e905,  5)
+    MD5STEP2( edx, eax, ebx, ecx, 7,  0xfcefa3f8,  9)
+    MD5STEP2( ecx, edx, eax, ebx, 12, 0x676f02d9, 14)
+    MD5STEP2( ebx, ecx, edx, eax, 5,  0x8d2a4c8a, 20)
+
+    MD5STEP3(  eax, ebx, ecx, edx, 8,   0xfffa3942,  4)
+    MD5STEP3(  edx, eax, ebx, ecx, 11,  0x8771f681, 11)
+    MD5STEP3(  ecx, edx, eax, ebx, 14,  0x6d9d6122, 16)
+    MD5STEP3(  ebx, ecx, edx, eax, 1,   0xfde5380c, 23)
+    MD5STEP3(  eax, ebx, ecx, edx, 4,   0xa4beea44,  4)
+    MD5STEP3(  edx, eax, ebx, ecx, 7,   0x4bdecfa9, 11)
+    MD5STEP3(  ecx, edx, eax, ebx, 10,  0xf6bb4b60, 16)
+    MD5STEP3(  ebx, ecx, edx, eax, 13,  0xbebfbc70, 23)
+    MD5STEP3(  eax, ebx, ecx, edx, 0,   0x289b7ec6,  4)
+    MD5STEP3(  edx, eax, ebx, ecx, 3,   0xeaa127fa, 11)
+    MD5STEP3(  ecx, edx, eax, ebx, 6,   0xd4ef3085, 16)
+    MD5STEP3(  ebx, ecx, edx, eax, 9,   0x04881d05, 23)
+    MD5STEP3(  eax, ebx, ecx, edx, 12,  0xd9d4d039,  4)
+    MD5STEP3(  edx, eax, ebx, ecx, 15,  0xe6db99e5, 11)
+    MD5STEP3(  ecx, edx, eax, ebx, 2,   0x1fa27cf8, 16)
+    MD5STEP3(  ebx, ecx, edx, eax, 0,   0xc4ac5665, 23)
+
+    // setup
+    AS2(    mov   esi, edx      )
+    AS1(    not   esi           )
+
+    MD5STEP4(  eax, ebx, ecx, edx, 7,   0xf4292244,  6)
+    MD5STEP4(  edx, eax, ebx, ecx, 14,  0x432aff97, 10)
+    MD5STEP4(  ecx, edx, eax, ebx, 5,   0xab9423a7, 15)
+    MD5STEP4(  ebx, ecx, edx, eax, 12,  0xfc93a039, 21)
+    MD5STEP4(  eax, ebx, ecx, edx, 3,   0x655b59c3,  6)
+    MD5STEP4(  edx, eax, ebx, ecx, 10,  0x8f0ccc92, 10)
+    MD5STEP4(  ecx, edx, eax, ebx, 1,   0xffeff47d, 15)
+    MD5STEP4(  ebx, ecx, edx, eax, 8,   0x85845dd1, 21)
+    MD5STEP4(  eax, ebx, ecx, edx, 15,  0x6fa87e4f,  6)
+    MD5STEP4(  edx, eax, ebx, ecx, 6,   0xfe2ce6e0, 10)
+    MD5STEP4(  ecx, edx, eax, ebx, 13,  0xa3014314, 15)
+    MD5STEP4(  ebx, ecx, edx, eax, 4,   0x4e0811a1, 21)
+    MD5STEP4(  eax, ebx, ecx, edx, 11,  0xf7537e82,  6)
+    MD5STEP4(  edx, eax, ebx, ecx, 2,   0xbd3af235, 10)
+    MD5STEP4(  ecx, edx, eax, ebx, 9,   0x2ad7d2bb, 15)
+    MD5STEP4(  ebx, ecx, edx, eax, 9,   0xeb86d391, 21)
+    
+    AS2(    movd  esi, mm1              )   // digest_
+
+    AS2(    add   [esi],      eax       )   // write out
+    AS2(    add   [esi +  4], ebx       )
+    AS2(    add   [esi +  8], ecx       )
+    AS2(    add   [esi + 12], edx       )
+
+    AS2(    add   edi, 64               )
+
+    AS2(    mov   eax, [esi]            )
+    AS2(    mov   ebx, [esi +  4]       )
+    AS2(    mov   ecx, [esi +  8]       )
+    AS2(    mov   edx, [esi + 12]       )
+
+    AS2(    movd  ebp, mm2              )   // times
+    AS1(    dec   ebp                   )
+    AS2(    movd  mm2, ebp              )
+    AS1(    jnz   loopStart             )
+
+
+    EPILOG()
+}
+
+
+#endif // DO_MD5_ASM
+
+
 void MD5::Transform()
 {
 #define F1(x, y, z) (z ^ (x & (y ^ z)))
@@ -161,10 +498,8 @@ void MD5::Transform()
 
     // Wipe variables
     a = b = c = d = 0;
-
-    buffLen_ = 0;
-    length_ += 512;
 }
 
+
 } // namespace
 
diff --git a/extra/yassl/taocrypt/src/misc.cpp b/extra/yassl/taocrypt/src/misc.cpp
index 0b33bb38aea..9a35daff240 100644
--- a/extra/yassl/taocrypt/src/misc.cpp
+++ b/extra/yassl/taocrypt/src/misc.cpp
@@ -24,61 +24,61 @@
 
 #include "runtime.hpp"
 #include "misc.hpp"
+#include         // for NewHandler
 
-
-void* operator new(size_t sz, TaoCrypt::new_t)
-{
 #ifdef YASSL_PURE_C
+
+    void* operator new(size_t sz, TaoCrypt::new_t)
+    {
     void* ptr = malloc(sz ? sz : 1);
     if (!ptr) abort();
 
     return ptr;
-#else
-    return ::operator new(sz);
-#endif
-}
+    }
 
 
-void operator delete(void* ptr, TaoCrypt::new_t)
-{
-#ifdef YASSL_PURE_C
+    void operator delete(void* ptr, TaoCrypt::new_t)
+    {
     if (ptr) free(ptr);
-#else
-    ::operator delete(ptr);
-#endif
-}
+    }
 
 
-void* operator new[](size_t sz, TaoCrypt::new_t nt)
-{
+    void* operator new[](size_t sz, TaoCrypt::new_t nt)
+    {
     return ::operator new(sz, nt);
-}
+    }
 
 
-void operator delete[](void* ptr, TaoCrypt::new_t nt)
-{
+    void operator delete[](void* ptr, TaoCrypt::new_t nt)
+    {
     ::operator delete(ptr, nt);
-}
+    }
 
 
-/* uncomment to test
-// make sure not using globals anywhere by forgetting to use overloaded
-void* operator new(size_t sz);
+    /* uncomment to test
+    // make sure not using globals anywhere by forgetting to use overloaded
+    void* operator new(size_t sz);
 
-void operator delete(void* ptr);
+    void operator delete(void* ptr);
 
-void* operator new[](size_t sz);
+    void* operator new[](size_t sz);
 
-void operator delete[](void* ptr);
-*/
+    void operator delete[](void* ptr);
+    */
+
+
+    namespace TaoCrypt {
+
+        new_t tc;   // for library new
+
+    }
+
+#endif // YASSL_PURE_C
 
 
 namespace TaoCrypt {
 
 
-new_t tc;   // for library new
-
-
 inline void XorWords(word* r, const word* a, unsigned int n)
 {
     for (unsigned int i=0; i
+
 
 #if defined(_WIN32)
     #define _WIN32_WINNT 0x0400
@@ -52,6 +54,7 @@ RandomNumberGenerator::RandomNumberGenerator()
 // place a generated block in output
 void RandomNumberGenerator::GenerateBlock(byte* output, word32 sz)
 {
+    memset(output, 0, sz);
     cipher_.Process(output, output, sz);
 }
 
@@ -95,11 +98,7 @@ OS_Seed::OS_Seed()
 {
     fd_ = open("/dev/urandom",O_RDONLY);
     if (fd_ == -1)
-    {
-      fd_ = open("/dev/random",O_RDONLY);
-      if (fd_ == -1)
         error_.SetError(OPEN_RAN_E);
-    }
 }
 
 
diff --git a/extra/yassl/taocrypt/src/ripemd.cpp b/extra/yassl/taocrypt/src/ripemd.cpp
index 0534a0d572d..da96b6cc1b4 100644
--- a/extra/yassl/taocrypt/src/ripemd.cpp
+++ b/extra/yassl/taocrypt/src/ripemd.cpp
@@ -26,6 +26,12 @@
 #include "ripemd.hpp"
 #include "algorithm.hpp"    // mySTL::swap
 
+
+
+#if defined(TAOCRYPT_X86ASM_AVAILABLE) && defined(TAO_ASM)
+    #define DO_RIPEMD_ASM
+#endif
+
 namespace TaoCrypt {
 
 void RIPEMD160::Init()
@@ -37,7 +43,8 @@ void RIPEMD160::Init()
     digest_[4] = 0xc3d2e1f0L;
 
     buffLen_ = 0;
-    length_  = 0;
+    loLen_  = 0;
+    hiLen_  = 0;
 }
 
 
@@ -45,7 +52,8 @@ RIPEMD160::RIPEMD160(const RIPEMD160& that)
     : HASHwithTransform(DIGEST_SIZE / sizeof(word32), BLOCK_SIZE) 
 { 
     buffLen_ = that.buffLen_;
-    length_  = that.length_;
+    loLen_   = that.loLen_;
+    hiLen_   = that.hiLen_;
 
     memcpy(digest_, that.digest_, DIGEST_SIZE);
     memcpy(buffer_, that.buffer_, BLOCK_SIZE);
@@ -63,7 +71,8 @@ RIPEMD160& RIPEMD160::operator= (const RIPEMD160& that)
 
 void RIPEMD160::Swap(RIPEMD160& other)
 {
-    mySTL::swap(length_,  other.length_);
+    mySTL::swap(loLen_,   other.loLen_);
+    mySTL::swap(hiLen_,   other.hiLen_);
     mySTL::swap(buffLen_, other.buffLen_);
 
     memcpy(digest_, other.digest_, DIGEST_SIZE);
@@ -71,6 +80,61 @@ void RIPEMD160::Swap(RIPEMD160& other)
 }
 
 
+// Update digest with data of size len, do in blocks
+void RIPEMD160::Update(const byte* data, word32 len)
+{
+    byte* local = (byte*)buffer_;
+
+    // remove buffered data if possible
+    if (buffLen_)  {   
+        word32 add = min(len, BLOCK_SIZE - buffLen_);
+        memcpy(&local[buffLen_], data, add);
+
+        buffLen_ += add;
+        data     += add;
+        len      -= add;
+
+        if (buffLen_ == BLOCK_SIZE) {
+            ByteReverseIf(local, local, BLOCK_SIZE, LittleEndianOrder);
+            Transform();
+            AddLength(BLOCK_SIZE);
+            buffLen_ = 0;
+        }
+    }
+
+    // do block size transforms or all at once for asm
+    if (buffLen_ == 0) {
+        #ifndef DO_RIPEMD_ASM
+            while (len >= BLOCK_SIZE) {
+                memcpy(&local[0], data, BLOCK_SIZE);
+
+                data     += BLOCK_SIZE;
+                len      -= BLOCK_SIZE;
+
+                ByteReverseIf(local, local, BLOCK_SIZE, LittleEndianOrder);
+                Transform();
+                AddLength(BLOCK_SIZE);
+            }
+        #else
+            word32 times = len / BLOCK_SIZE;
+            if (times) {
+                AsmTransform(data, times);
+                const word32 add = BLOCK_SIZE * times;
+                AddLength(add);
+                len  -= add;
+                data += add;
+            }
+        #endif
+    }
+
+    // cache any data left
+    if (len) {
+        memcpy(&local[buffLen_], data, len);
+        buffLen_ += len;
+    }
+}
+
+
 // for all
 #define F(x, y, z)    (x ^ y ^ z) 
 #define G(x, y, z)    (z ^ (x & (y^z)))
@@ -79,14 +143,14 @@ void RIPEMD160::Swap(RIPEMD160& other)
 #define J(x, y, z)    (x ^ (y | ~z))
 
 #define k0 0
-#define k1 0x5a827999UL
-#define k2 0x6ed9eba1UL
-#define k3 0x8f1bbcdcUL
-#define k4 0xa953fd4eUL
-#define k5 0x50a28be6UL
-#define k6 0x5c4dd124UL
-#define k7 0x6d703ef3UL
-#define k8 0x7a6d76e9UL
+#define k1 0x5a827999
+#define k2 0x6ed9eba1
+#define k3 0x8f1bbcdc
+#define k4 0xa953fd4e
+#define k5 0x50a28be6
+#define k6 0x5c4dd124
+#define k7 0x6d703ef3
+#define k8 0x7a6d76e9
 #define k9 0
 
 // for 160 and 320
@@ -281,10 +345,495 @@ void RIPEMD160::Transform()
     digest_[3] = digest_[4] + a1 + b2;
     digest_[4] = digest_[0] + b1 + c2;
     digest_[0] = c1;
-
-    buffLen_ = 0;
-    length_ += 512;
 }
 
 
+#ifdef DO_RIPEMD_ASM
+
+/*
+    // F(x ^ y ^ z)
+    // place in esi
+#define ASMF(x, y, z)  \
+    AS2(    mov   esi, x                )   \
+    AS2(    xor   esi, y                )   \
+    AS2(    xor   esi, z                )
+
+
+    // G(z ^ (x & (y^z)))
+    // place in esi
+#define ASMG(x, y, z)  \
+    AS2(    mov   esi, z                )   \
+    AS2(    xor   esi, y                )   \
+    AS2(    and   esi, x                )   \
+    AS2(    xor   esi, z                )
+
+    
+    // H(z ^ (x | ~y))
+    // place in esi
+#define ASMH(x, y, z) \
+    AS2(    mov   esi, y                )   \
+    AS1(    not   esi                   )   \
+    AS2(     or   esi, x                )   \
+    AS2(    xor   esi, z                )
+
+
+    // I(y ^ (z & (x^y)))
+    // place in esi
+#define ASMI(x, y, z)  \
+    AS2(    mov   esi, y                )   \
+    AS2(    xor   esi, x                )   \
+    AS2(    and   esi, z                )   \
+    AS2(    xor   esi, y                )
+
+
+    // J(x ^ (y | ~z)))
+    // place in esi
+#define ASMJ(x, y, z)   \
+    AS2(    mov   esi, z                )   \
+    AS1(    not   esi                   )   \
+    AS2(     or   esi, y                )   \
+    AS2(    xor   esi, x                )
+
+
+// for 160 and 320
+// #define ASMSubround(f, a, b, c, d, e, i, s, k) 
+//    a += f(b, c, d) + data[i] + k;
+//    a = rotlFixed((word32)a, s) + e;
+//    c = rotlFixed((word32)c, 10U)
+
+#define ASMSubround(f, a, b, c, d, e, index, s, k) \
+    // a += f(b, c, d) + data[i] + k                    \
+    AS2(    mov   esp, [edi + index * 4]            )   \
+    f(b, c, d)                                          \
+    AS2(    add   esi, k                            )   \
+    AS2(    add   esi, esp                          )   \
+    AS2(    add     a, esi                          )   \
+    // a = rotlFixed((word32)a, s) + e                  \
+    AS2(    rol     a, s                            )   \
+    AS2(    rol     c, 10                           )   \
+    // c = rotlFixed((word32)c, 10U)                    \
+    AS2(    add     a, e                            )
+*/
+
+
+// combine F into subround w/ setup
+// esi already has c, setup for next round when done
+// esp already has edi[index], setup for next round when done
+
+#define ASMSubroundF(a, b, c, d, e, index, s) \
+    /* a += (b ^ c ^ d) + data[i] + k  */               \
+    AS2(    xor   esi, b                            )   \
+    AS2(    add     a, [edi + index * 4]            )   \
+    AS2(    xor   esi, d                            )   \
+    AS2(    add     a, esi                          )   \
+    /* a = rotlFixed((word32)a, s) + e */               \
+    AS2(    mov   esi, b                            )   \
+    AS2(    rol     a, s                            )   \
+    /* c = rotlFixed((word32)c, 10U) */                 \
+    AS2(    rol     c, 10                           )   \
+    AS2(    add     a, e                            )
+
+
+// combine G into subround w/ setup
+// esi already has c, setup for next round when done
+// esp already has edi[index], setup for next round when done
+
+#define ASMSubroundG(a, b, c, d, e, index, s, k) \
+    /* a += (d ^ (b & (c^d))) + data[i] + k  */         \
+    AS2(    xor   esi, d                            )   \
+    AS2(    and   esi, b                            )   \
+    AS2(    add     a, [edi + index * 4]            )   \
+    AS2(    xor   esi, d                            )   \
+    AS2(    lea     a, [esi + a + k]                )   \
+    /* a = rotlFixed((word32)a, s) + e */               \
+    AS2(    mov   esi, b                            )   \
+    AS2(    rol     a, s                            )   \
+    /* c = rotlFixed((word32)c, 10U) */                 \
+    AS2(    rol     c, 10                           )   \
+    AS2(    add     a, e                            )
+
+
+// combine H into subround w/ setup
+// esi already has c, setup for next round when done
+// esp already has edi[index], setup for next round when done
+
+#define ASMSubroundH(a, b, c, d, e, index, s, k) \
+    /* a += (d ^ (b | ~c)) + data[i] + k  */            \
+    AS1(    not   esi                               )   \
+    AS2(     or   esi, b                            )   \
+    AS2(    add     a, [edi + index * 4]            )   \
+    AS2(    xor   esi, d                            )   \
+    AS2(    lea     a, [esi + a + k]                )   \
+    /* a = rotlFixed((word32)a, s) + e */               \
+    AS2(    mov   esi, b                            )   \
+    AS2(    rol     a, s                            )   \
+    /* c = rotlFixed((word32)c, 10U) */                 \
+    AS2(    rol     c, 10                           )   \
+    AS2(    add     a, e                            )
+
+
+// combine I into subround w/ setup
+// esi already has c, setup for next round when done
+// esp already has edi[index], setup for next round when done
+
+#define ASMSubroundI(a, b, c, d, e, index, s, k) \
+    /* a += (c ^ (d & (b^c))) + data[i] + k  */         \
+    AS2(    xor   esi, b                            )   \
+    AS2(    and   esi, d                            )   \
+    AS2(    add     a, [edi + index * 4]            )   \
+    AS2(    xor   esi, c                            )   \
+    AS2(    lea     a, [esi + a + k]                )   \
+    /* a = rotlFixed((word32)a, s) + e */               \
+    AS2(    mov   esi, b                            )   \
+    AS2(    rol     a, s                            )   \
+    /* c = rotlFixed((word32)c, 10U) */                 \
+    AS2(    rol     c, 10                           )   \
+    AS2(    add     a, e                            )
+
+
+// combine J into subround w/ setup
+// esi already has d, setup for next round when done
+// esp already has edi[index], setup for next round when done
+
+#define ASMSubroundJ(a, b, c, d, e, index, s, k) \
+    /* a += (b ^ (c | ~d))) + data[i] + k  */           \
+    AS1(    not   esi                               )   \
+    AS2(     or   esi, c                            )   \
+    /* c = rotlFixed((word32)c, 10U) */                 \
+    AS2(    add     a, [edi + index * 4]            )   \
+    AS2(    xor   esi, b                            )   \
+    AS2(    rol     c, 10                           )   \
+    AS2(    lea     a, [esi + a + k]                )   \
+    /* a = rotlFixed((word32)a, s) + e */               \
+    AS2(    rol     a, s                            )   \
+    AS2(    mov   esi, c                            )   \
+    AS2(    add     a, e                            )
+
+
+#ifdef _MSC_VER
+    __declspec(naked) 
+#endif
+void RIPEMD160::AsmTransform(const byte* data, word32 times)
+{
+#ifdef __GNUC__
+    #define AS1(x)    asm(#x);
+    #define AS2(x, y) asm(#x ", " #y);
+
+    #define PROLOG()  \
+        asm(".intel_syntax noprefix"); \
+        AS2(    movd  mm3, edi                      )   \
+        AS2(    movd  mm4, ebx                      )   \
+        AS2(    movd  mm5, esi                      )   \
+        AS2(    movd  mm6, ebp                      )   \
+        AS2(    mov   ecx, DWORD PTR [ebp +  8]     )   \
+        AS2(    mov   edi, DWORD PTR [ebp + 12]     )   \
+        AS2(    mov   edx, DWORD PTR [ebp + 16]     )
+
+    #define EPILOG()  \
+        AS2(    movd  ebp, mm6                  )   \
+        AS2(    movd  esi, mm5                  )   \
+        AS2(    movd  ebx, mm4                  )   \
+        AS2(    mov   esp, ebp                  )   \
+        AS2(    movd  edi, mm3                  )   \
+        AS1(    emms                            )   \
+        asm(".att_syntax");
+#else
+    #define AS1(x)    __asm x
+    #define AS2(x, y) __asm x, y
+
+    #define PROLOG() \
+        AS1(    push  ebp                       )   \
+        AS2(    mov   ebp, esp                  )   \
+        AS2(    movd  mm3, edi                  )   \
+        AS2(    movd  mm4, ebx                  )   \
+        AS2(    movd  mm5, esi                  )   \
+        AS2(    movd  mm6, ebp                  )   \
+        AS2(    mov   edi, DWORD PTR [ebp +  8] )   \
+        AS2(    mov   edx, DWORD PTR [ebp + 12] )
+
+    #define EPILOG() \
+        AS2(    movd  ebp, mm6                  )   \
+        AS2(    movd  esi, mm5                  )   \
+        AS2(    movd  ebx, mm4                  )   \
+        AS2(    movd  edi, mm3                  )   \
+        AS2(    mov   esp, ebp                  )   \
+        AS1(    pop   ebp                       )   \
+        AS1(    emms                            )   \
+        AS1(    ret   8                         )
+        
+#endif
+
+    PROLOG()
+
+    #ifdef OLD_GCC_OFFSET
+        AS2(    lea   esi, [ecx + 20]               )   // digest_[0]
+    #else
+        AS2(    lea   esi, [ecx + 16]               )   // digest_[0]
+    #endif
+
+    AS2(    sub   esp, 24               )   // make room for tmp a1 - e1
+    AS2(    movd  mm1, esi              )   // store digest_
+    
+AS1( loopStart: )
+
+    AS2(    movd  mm2, edx              )   // store times_
+
+    AS2(    mov   eax, [esi]            )   // a1
+    AS2(    mov   ebx, [esi +  4]       )   // b1
+    AS2(    mov   ecx, [esi +  8]       )   // c1
+    AS2(    mov   edx, [esi + 12]       )   // d1
+    AS2(    mov   ebp, [esi + 16]       )   // e1
+
+    // setup 
+    AS2(    mov   esi, ecx      )
+
+    ASMSubroundF( eax, ebx, ecx, edx, ebp,  0, 11)
+    ASMSubroundF( ebp, eax, ebx, ecx, edx,  1, 14)
+    ASMSubroundF( edx, ebp, eax, ebx, ecx,  2, 15)
+    ASMSubroundF( ecx, edx, ebp, eax, ebx,  3, 12)
+    ASMSubroundF( ebx, ecx, edx, ebp, eax,  4,  5)
+    ASMSubroundF( eax, ebx, ecx, edx, ebp,  5,  8)
+    ASMSubroundF( ebp, eax, ebx, ecx, edx,  6,  7)
+    ASMSubroundF( edx, ebp, eax, ebx, ecx,  7,  9)
+    ASMSubroundF( ecx, edx, ebp, eax, ebx,  8, 11)
+    ASMSubroundF( ebx, ecx, edx, ebp, eax,  9, 13)
+    ASMSubroundF( eax, ebx, ecx, edx, ebp, 10, 14)
+    ASMSubroundF( ebp, eax, ebx, ecx, edx, 11, 15)
+    ASMSubroundF( edx, ebp, eax, ebx, ecx, 12,  6)
+    ASMSubroundF( ecx, edx, ebp, eax, ebx, 13,  7)
+    ASMSubroundF( ebx, ecx, edx, ebp, eax, 14,  9)
+    ASMSubroundF( eax, ebx, ecx, edx, ebp, 15,  8)
+
+    ASMSubroundG( ebp, eax, ebx, ecx, edx,  7,  7, k1)
+    ASMSubroundG( edx, ebp, eax, ebx, ecx,  4,  6, k1)
+    ASMSubroundG( ecx, edx, ebp, eax, ebx, 13,  8, k1)
+    ASMSubroundG( ebx, ecx, edx, ebp, eax,  1, 13, k1)
+    ASMSubroundG( eax, ebx, ecx, edx, ebp, 10, 11, k1)
+    ASMSubroundG( ebp, eax, ebx, ecx, edx,  6,  9, k1)
+    ASMSubroundG( edx, ebp, eax, ebx, ecx, 15,  7, k1)
+    ASMSubroundG( ecx, edx, ebp, eax, ebx,  3, 15, k1)
+    ASMSubroundG( ebx, ecx, edx, ebp, eax, 12,  7, k1)
+    ASMSubroundG( eax, ebx, ecx, edx, ebp,  0, 12, k1)
+    ASMSubroundG( ebp, eax, ebx, ecx, edx,  9, 15, k1)
+    ASMSubroundG( edx, ebp, eax, ebx, ecx,  5,  9, k1)
+    ASMSubroundG( ecx, edx, ebp, eax, ebx,  2, 11, k1)
+    ASMSubroundG( ebx, ecx, edx, ebp, eax, 14,  7, k1)
+    ASMSubroundG( eax, ebx, ecx, edx, ebp, 11, 13, k1)
+    ASMSubroundG( ebp, eax, ebx, ecx, edx,  8, 12, k1)
+
+    ASMSubroundH( edx, ebp, eax, ebx, ecx,  3, 11, k2)
+    ASMSubroundH( ecx, edx, ebp, eax, ebx, 10, 13, k2)
+    ASMSubroundH( ebx, ecx, edx, ebp, eax, 14,  6, k2)
+    ASMSubroundH( eax, ebx, ecx, edx, ebp,  4,  7, k2)
+    ASMSubroundH( ebp, eax, ebx, ecx, edx,  9, 14, k2)
+    ASMSubroundH( edx, ebp, eax, ebx, ecx, 15,  9, k2)
+    ASMSubroundH( ecx, edx, ebp, eax, ebx,  8, 13, k2)
+    ASMSubroundH( ebx, ecx, edx, ebp, eax,  1, 15, k2)
+    ASMSubroundH( eax, ebx, ecx, edx, ebp,  2, 14, k2)
+    ASMSubroundH( ebp, eax, ebx, ecx, edx,  7,  8, k2)
+    ASMSubroundH( edx, ebp, eax, ebx, ecx,  0, 13, k2)
+    ASMSubroundH( ecx, edx, ebp, eax, ebx,  6,  6, k2)
+    ASMSubroundH( ebx, ecx, edx, ebp, eax, 13,  5, k2)
+    ASMSubroundH( eax, ebx, ecx, edx, ebp, 11, 12, k2)
+    ASMSubroundH( ebp, eax, ebx, ecx, edx,  5,  7, k2)
+    ASMSubroundH( edx, ebp, eax, ebx, ecx, 12,  5, k2)
+
+    ASMSubroundI( ecx, edx, ebp, eax, ebx,  1, 11, k3)
+    ASMSubroundI( ebx, ecx, edx, ebp, eax,  9, 12, k3)
+    ASMSubroundI( eax, ebx, ecx, edx, ebp, 11, 14, k3)
+    ASMSubroundI( ebp, eax, ebx, ecx, edx, 10, 15, k3)
+    ASMSubroundI( edx, ebp, eax, ebx, ecx,  0, 14, k3)
+    ASMSubroundI( ecx, edx, ebp, eax, ebx,  8, 15, k3)
+    ASMSubroundI( ebx, ecx, edx, ebp, eax, 12,  9, k3)
+    ASMSubroundI( eax, ebx, ecx, edx, ebp,  4,  8, k3)
+    ASMSubroundI( ebp, eax, ebx, ecx, edx, 13,  9, k3)
+    ASMSubroundI( edx, ebp, eax, ebx, ecx,  3, 14, k3)
+    ASMSubroundI( ecx, edx, ebp, eax, ebx,  7,  5, k3)
+    ASMSubroundI( ebx, ecx, edx, ebp, eax, 15,  6, k3)
+    ASMSubroundI( eax, ebx, ecx, edx, ebp, 14,  8, k3)
+    ASMSubroundI( ebp, eax, ebx, ecx, edx,  5,  6, k3)
+    ASMSubroundI( edx, ebp, eax, ebx, ecx,  6,  5, k3)
+    ASMSubroundI( ecx, edx, ebp, eax, ebx,  2, 12, k3)
+
+    // setup
+    AS2(    mov   esi, ebp      )
+
+    ASMSubroundJ( ebx, ecx, edx, ebp, eax,  4,  9, k4)
+    ASMSubroundJ( eax, ebx, ecx, edx, ebp,  0, 15, k4)
+    ASMSubroundJ( ebp, eax, ebx, ecx, edx,  5,  5, k4)
+    ASMSubroundJ( edx, ebp, eax, ebx, ecx,  9, 11, k4)
+    ASMSubroundJ( ecx, edx, ebp, eax, ebx,  7,  6, k4)
+    ASMSubroundJ( ebx, ecx, edx, ebp, eax, 12,  8, k4)
+    ASMSubroundJ( eax, ebx, ecx, edx, ebp,  2, 13, k4)
+    ASMSubroundJ( ebp, eax, ebx, ecx, edx, 10, 12, k4)
+    ASMSubroundJ( edx, ebp, eax, ebx, ecx, 14,  5, k4)
+    ASMSubroundJ( ecx, edx, ebp, eax, ebx,  1, 12, k4)
+    ASMSubroundJ( ebx, ecx, edx, ebp, eax,  3, 13, k4)
+    ASMSubroundJ( eax, ebx, ecx, edx, ebp,  8, 14, k4)
+    ASMSubroundJ( ebp, eax, ebx, ecx, edx, 11, 11, k4)
+    ASMSubroundJ( edx, ebp, eax, ebx, ecx,  6,  8, k4)
+    ASMSubroundJ( ecx, edx, ebp, eax, ebx, 15,  5, k4)
+    ASMSubroundJ( ebx, ecx, edx, ebp, eax, 13,  6, k4)
+
+    // store a1 - e1 on stack
+    AS2(    movd  esi, mm1              )   // digest_
+
+    AS2(    mov   [esp],      eax       )
+    AS2(    mov   [esp +  4], ebx       )
+    AS2(    mov   [esp +  8], ecx       )
+    AS2(    mov   [esp + 12], edx       )
+    AS2(    mov   [esp + 16], ebp       )
+
+    AS2(    mov   eax, [esi]            )   // a2
+    AS2(    mov   ebx, [esi +  4]       )   // b2
+    AS2(    mov   ecx, [esi +  8]       )   // c2
+    AS2(    mov   edx, [esi + 12]       )   // d2
+    AS2(    mov   ebp, [esi + 16]       )   // e2
+
+
+    // setup
+    AS2(    mov   esi, edx      )
+
+    ASMSubroundJ( eax, ebx, ecx, edx, ebp,  5,  8, k5)
+    ASMSubroundJ( ebp, eax, ebx, ecx, edx, 14,  9, k5)
+    ASMSubroundJ( edx, ebp, eax, ebx, ecx,  7,  9, k5)
+    ASMSubroundJ( ecx, edx, ebp, eax, ebx,  0, 11, k5)
+    ASMSubroundJ( ebx, ecx, edx, ebp, eax,  9, 13, k5)
+    ASMSubroundJ( eax, ebx, ecx, edx, ebp,  2, 15, k5)
+    ASMSubroundJ( ebp, eax, ebx, ecx, edx, 11, 15, k5)
+    ASMSubroundJ( edx, ebp, eax, ebx, ecx,  4,  5, k5)
+    ASMSubroundJ( ecx, edx, ebp, eax, ebx, 13,  7, k5)
+    ASMSubroundJ( ebx, ecx, edx, ebp, eax,  6,  7, k5)
+    ASMSubroundJ( eax, ebx, ecx, edx, ebp, 15,  8, k5)
+    ASMSubroundJ( ebp, eax, ebx, ecx, edx,  8, 11, k5)
+    ASMSubroundJ( edx, ebp, eax, ebx, ecx,  1, 14, k5)
+    ASMSubroundJ( ecx, edx, ebp, eax, ebx, 10, 14, k5)
+    ASMSubroundJ( ebx, ecx, edx, ebp, eax,  3, 12, k5)
+    ASMSubroundJ( eax, ebx, ecx, edx, ebp, 12,  6, k5)
+
+    // setup
+    AS2(    mov   esi, ebx      )
+
+    ASMSubroundI( ebp, eax, ebx, ecx, edx,  6,  9, k6) 
+    ASMSubroundI( edx, ebp, eax, ebx, ecx, 11, 13, k6)
+    ASMSubroundI( ecx, edx, ebp, eax, ebx,  3, 15, k6)
+    ASMSubroundI( ebx, ecx, edx, ebp, eax,  7,  7, k6)
+    ASMSubroundI( eax, ebx, ecx, edx, ebp,  0, 12, k6)
+    ASMSubroundI( ebp, eax, ebx, ecx, edx, 13,  8, k6)
+    ASMSubroundI( edx, ebp, eax, ebx, ecx,  5,  9, k6)
+    ASMSubroundI( ecx, edx, ebp, eax, ebx, 10, 11, k6)
+    ASMSubroundI( ebx, ecx, edx, ebp, eax, 14,  7, k6)
+    ASMSubroundI( eax, ebx, ecx, edx, ebp, 15,  7, k6)
+    ASMSubroundI( ebp, eax, ebx, ecx, edx,  8, 12, k6)
+    ASMSubroundI( edx, ebp, eax, ebx, ecx, 12,  7, k6)
+    ASMSubroundI( ecx, edx, ebp, eax, ebx,  4,  6, k6)
+    ASMSubroundI( ebx, ecx, edx, ebp, eax,  9, 15, k6)
+    ASMSubroundI( eax, ebx, ecx, edx, ebp,  1, 13, k6)
+    ASMSubroundI( ebp, eax, ebx, ecx, edx,  2, 11, k6)
+
+    ASMSubroundH( edx, ebp, eax, ebx, ecx, 15,  9, k7)
+    ASMSubroundH( ecx, edx, ebp, eax, ebx,  5,  7, k7)
+    ASMSubroundH( ebx, ecx, edx, ebp, eax,  1, 15, k7)
+    ASMSubroundH( eax, ebx, ecx, edx, ebp,  3, 11, k7)
+    ASMSubroundH( ebp, eax, ebx, ecx, edx,  7,  8, k7)
+    ASMSubroundH( edx, ebp, eax, ebx, ecx, 14,  6, k7)
+    ASMSubroundH( ecx, edx, ebp, eax, ebx,  6,  6, k7)
+    ASMSubroundH( ebx, ecx, edx, ebp, eax,  9, 14, k7)
+    ASMSubroundH( eax, ebx, ecx, edx, ebp, 11, 12, k7)
+    ASMSubroundH( ebp, eax, ebx, ecx, edx,  8, 13, k7)
+    ASMSubroundH( edx, ebp, eax, ebx, ecx, 12,  5, k7)
+    ASMSubroundH( ecx, edx, ebp, eax, ebx,  2, 14, k7)
+    ASMSubroundH( ebx, ecx, edx, ebp, eax, 10, 13, k7)
+    ASMSubroundH( eax, ebx, ecx, edx, ebp,  0, 13, k7)
+    ASMSubroundH( ebp, eax, ebx, ecx, edx,  4,  7, k7)
+    ASMSubroundH( edx, ebp, eax, ebx, ecx, 13,  5, k7)
+
+    ASMSubroundG( ecx, edx, ebp, eax, ebx,  8, 15, k8)
+    ASMSubroundG( ebx, ecx, edx, ebp, eax,  6,  5, k8)
+    ASMSubroundG( eax, ebx, ecx, edx, ebp,  4,  8, k8)
+    ASMSubroundG( ebp, eax, ebx, ecx, edx,  1, 11, k8)
+    ASMSubroundG( edx, ebp, eax, ebx, ecx,  3, 14, k8)
+    ASMSubroundG( ecx, edx, ebp, eax, ebx, 11, 14, k8)
+    ASMSubroundG( ebx, ecx, edx, ebp, eax, 15,  6, k8)
+    ASMSubroundG( eax, ebx, ecx, edx, ebp,  0, 14, k8)
+    ASMSubroundG( ebp, eax, ebx, ecx, edx,  5,  6, k8)
+    ASMSubroundG( edx, ebp, eax, ebx, ecx, 12,  9, k8)
+    ASMSubroundG( ecx, edx, ebp, eax, ebx,  2, 12, k8)
+    ASMSubroundG( ebx, ecx, edx, ebp, eax, 13,  9, k8)
+    ASMSubroundG( eax, ebx, ecx, edx, ebp,  9, 12, k8)
+    ASMSubroundG( ebp, eax, ebx, ecx, edx,  7,  5, k8)
+    ASMSubroundG( edx, ebp, eax, ebx, ecx, 10, 15, k8)
+    ASMSubroundG( ecx, edx, ebp, eax, ebx, 14,  8, k8)
+
+    ASMSubroundF( ebx, ecx, edx, ebp, eax, 12,  8)
+    ASMSubroundF( eax, ebx, ecx, edx, ebp, 15,  5)
+    ASMSubroundF( ebp, eax, ebx, ecx, edx, 10, 12)
+    ASMSubroundF( edx, ebp, eax, ebx, ecx,  4,  9)
+    ASMSubroundF( ecx, edx, ebp, eax, ebx,  1, 12)
+    ASMSubroundF( ebx, ecx, edx, ebp, eax,  5,  5)
+    ASMSubroundF( eax, ebx, ecx, edx, ebp,  8, 14)
+    ASMSubroundF( ebp, eax, ebx, ecx, edx,  7,  6)
+    ASMSubroundF( edx, ebp, eax, ebx, ecx,  6,  8)
+    ASMSubroundF( ecx, edx, ebp, eax, ebx,  2, 13)
+    ASMSubroundF( ebx, ecx, edx, ebp, eax, 13,  6)
+    ASMSubroundF( eax, ebx, ecx, edx, ebp, 14,  5)
+    ASMSubroundF( ebp, eax, ebx, ecx, edx,  0, 15)
+    ASMSubroundF( edx, ebp, eax, ebx, ecx,  3, 13)
+    ASMSubroundF( ecx, edx, ebp, eax, ebx,  9, 11)
+    ASMSubroundF( ebx, ecx, edx, ebp, eax, 11, 11)
+
+    // advance data and store for next round
+    AS2(    add   edi, 64                       )
+    AS2(    movd  esi, mm1                      )   // digest_
+    AS2(    movd  mm0, edi                      )   // store
+
+    // now edi as tmp
+
+    // c1         = digest_[1] + c1 + d2;
+    AS2(    add   [esp +  8], edx               )   // + d2
+    AS2(    mov   edi, [esi + 4]                )   // digest_[1]
+    AS2(    add   [esp +  8], edi               )
+
+    // digest_[1] = digest_[2] + d1 + e2;
+    AS2(    mov   [esi + 4], ebp                )   // e2
+    AS2(    mov   edi, [esp + 12]               )   // d1
+    AS2(    add   edi, [esi + 8]                )   // digest_[2]
+    AS2(    add   [esi + 4], edi                )
+
+    // digest_[2] = digest_[3] + e1 + a2;
+    AS2(    mov   [esi + 8], eax                )   // a2
+    AS2(    mov   edi, [esp + 16]               )   // e1
+    AS2(    add   edi, [esi + 12]               )   // digest_[3]
+    AS2(    add   [esi + 8], edi                )
+
+    // digest_[3] = digest_[4] + a1 + b2;
+    AS2(    mov   [esi + 12], ebx               )   // b2
+    AS2(    mov   edi, [esp]                    )   // a1
+    AS2(    add   edi, [esi + 16]               )   // digest_[4]
+    AS2(    add   [esi + 12], edi               )
+
+    // digest_[4] = digest_[0] + b1 + c2;
+    AS2(    mov   [esi + 16], ecx               )   // c2
+    AS2(    mov   edi, [esp +  4]               )   // b1
+    AS2(    add   edi, [esi]                    )   // digest_[0]
+    AS2(    add   [esi + 16], edi               )
+
+    // digest_[0] = c1;
+    AS2(    mov   edi, [esp +  8]               )   // c1
+    AS2(    mov   [esi], edi                    )
+
+    // setup for loop back
+    AS2(    movd  edx, mm2              )   // times
+    AS2(    movd  edi, mm0              )   // data, already advanced
+    AS1(    dec   edx                   )
+    AS1(    jnz   loopStart             )
+
+
+    EPILOG()
+}
+
+
+#endif // DO_RIPEMD_ASM
+
+
 } // namespace TaoCrypt
diff --git a/extra/yassl/taocrypt/src/sha.cpp b/extra/yassl/taocrypt/src/sha.cpp
index 13a4cfc22d3..12f80c1af75 100644
--- a/extra/yassl/taocrypt/src/sha.cpp
+++ b/extra/yassl/taocrypt/src/sha.cpp
@@ -27,6 +27,11 @@
 #include "sha.hpp"
 
 
+#if defined(TAOCRYPT_X86ASM_AVAILABLE) && defined(TAO_ASM)
+    #define DO_SHA_ASM
+#endif
+
+
 namespace TaoCrypt {
 
 #define blk0(i) (W[i] = buffer_[i])
@@ -60,7 +65,8 @@ void SHA::Init()
     digest_[4] = 0xC3D2E1F0L;
 
     buffLen_ = 0;
-    length_  = 0;
+    loLen_  = 0;
+    hiLen_  = 0;
 }
 
 
@@ -68,7 +74,8 @@ SHA::SHA(const SHA& that) : HASHwithTransform(DIGEST_SIZE / sizeof(word32),
                                               BLOCK_SIZE) 
 { 
     buffLen_ = that.buffLen_;
-    length_  = that.length_;
+    loLen_   = that.loLen_;
+    hiLen_   = that.hiLen_;
 
     memcpy(digest_, that.digest_, DIGEST_SIZE);
     memcpy(buffer_, that.buffer_, BLOCK_SIZE);
@@ -85,7 +92,8 @@ SHA& SHA::operator= (const SHA& that)
 
 void SHA::Swap(SHA& other)
 {
-    mySTL::swap(length_,  other.length_);
+    mySTL::swap(loLen_,   other.loLen_);
+    mySTL::swap(hiLen_,   other.hiLen_);
     mySTL::swap(buffLen_, other.buffLen_);
 
     memcpy(digest_, other.digest_, DIGEST_SIZE);
@@ -93,6 +101,61 @@ void SHA::Swap(SHA& other)
 }
 
 
+// Update digest with data of size len, do in blocks
+void SHA::Update(const byte* data, word32 len)
+{
+    byte* local = (byte*)buffer_;
+
+    // remove buffered data if possible
+    if (buffLen_)  {   
+        word32 add = min(len, BLOCK_SIZE - buffLen_);
+        memcpy(&local[buffLen_], data, add);
+
+        buffLen_ += add;
+        data     += add;
+        len      -= add;
+
+        if (buffLen_ == BLOCK_SIZE) {
+            ByteReverseIf(local, local, BLOCK_SIZE, BigEndianOrder);
+            Transform();
+            AddLength(BLOCK_SIZE);
+            buffLen_ = 0;
+        }
+    }
+
+    // do block size transforms or all at once for asm
+    if (buffLen_ == 0) {
+        #ifndef DO_SHA_ASM
+            while (len >= BLOCK_SIZE) {
+                memcpy(&local[0], data, BLOCK_SIZE);
+
+                data     += BLOCK_SIZE;
+                len      -= BLOCK_SIZE;
+
+                ByteReverseIf(local, local, BLOCK_SIZE, BigEndianOrder);
+                Transform();
+                AddLength(BLOCK_SIZE);
+            }
+        #else
+            word32 times = len / BLOCK_SIZE;
+            if (times) {
+                AsmTransform(data, times);
+                const word32 add = BLOCK_SIZE * times;
+                AddLength(add);
+                 len  -= add;
+                data += add;
+            }
+        #endif
+    }
+
+    // cache any data left
+    if (len) {
+        memcpy(&local[buffLen_], data, len);
+        buffLen_ += len;
+    }
+}
+
+
 void SHA::Transform()
 {
     word32 W[BLOCK_SIZE / sizeof(word32)];
@@ -109,17 +172,21 @@ void SHA::Transform()
     R0(b,c,d,e,a, 4); R0(a,b,c,d,e, 5); R0(e,a,b,c,d, 6); R0(d,e,a,b,c, 7);
     R0(c,d,e,a,b, 8); R0(b,c,d,e,a, 9); R0(a,b,c,d,e,10); R0(e,a,b,c,d,11);
     R0(d,e,a,b,c,12); R0(c,d,e,a,b,13); R0(b,c,d,e,a,14); R0(a,b,c,d,e,15);
+
     R1(e,a,b,c,d,16); R1(d,e,a,b,c,17); R1(c,d,e,a,b,18); R1(b,c,d,e,a,19);
+
     R2(a,b,c,d,e,20); R2(e,a,b,c,d,21); R2(d,e,a,b,c,22); R2(c,d,e,a,b,23);
     R2(b,c,d,e,a,24); R2(a,b,c,d,e,25); R2(e,a,b,c,d,26); R2(d,e,a,b,c,27);
     R2(c,d,e,a,b,28); R2(b,c,d,e,a,29); R2(a,b,c,d,e,30); R2(e,a,b,c,d,31);
     R2(d,e,a,b,c,32); R2(c,d,e,a,b,33); R2(b,c,d,e,a,34); R2(a,b,c,d,e,35);
     R2(e,a,b,c,d,36); R2(d,e,a,b,c,37); R2(c,d,e,a,b,38); R2(b,c,d,e,a,39);
+
     R3(a,b,c,d,e,40); R3(e,a,b,c,d,41); R3(d,e,a,b,c,42); R3(c,d,e,a,b,43);
     R3(b,c,d,e,a,44); R3(a,b,c,d,e,45); R3(e,a,b,c,d,46); R3(d,e,a,b,c,47);
     R3(c,d,e,a,b,48); R3(b,c,d,e,a,49); R3(a,b,c,d,e,50); R3(e,a,b,c,d,51);
     R3(d,e,a,b,c,52); R3(c,d,e,a,b,53); R3(b,c,d,e,a,54); R3(a,b,c,d,e,55);
     R3(e,a,b,c,d,56); R3(d,e,a,b,c,57); R3(c,d,e,a,b,58); R3(b,c,d,e,a,59);
+
     R4(a,b,c,d,e,60); R4(e,a,b,c,d,61); R4(d,e,a,b,c,62); R4(c,d,e,a,b,63);
     R4(b,c,d,e,a,64); R4(a,b,c,d,e,65); R4(e,a,b,c,d,66); R4(d,e,a,b,c,67);
     R4(c,d,e,a,b,68); R4(b,c,d,e,a,69); R4(a,b,c,d,e,70); R4(e,a,b,c,d,71);
@@ -136,10 +203,414 @@ void SHA::Transform()
     // Wipe variables
     a = b = c = d = e = 0;
     memset(W, 0, sizeof(W));
-
-    buffLen_ = 0;
-    length_ += 512;
 }
 
 
+#ifdef DO_SHA_ASM
+
+// f1(x,y,z) (z^(x &(y^z)))
+// place in esi
+#define ASMf1(x,y,z)   \
+    AS2(    mov   esi, y    )   \
+    AS2(    xor   esi, z    )   \
+    AS2(    and   esi, x    )   \
+    AS2(    xor   esi, z    )
+
+
+// R0(v,w,x,y,z,i) =
+//      z+= f1(w,x,y) + W[i] + 0x5A827999 + rotlFixed(v,5);
+//      w = rotlFixed(w,30);
+
+//      use esi for f
+//      use edi as tmp
+
+
+#define ASMR0(v,w,x,y,z,i) \
+    AS2(    mov   esi, x                        )   \
+    AS2(    mov   edi, [esp + i * 4]            )   \
+    AS2(    xor   esi, y                        )   \
+    AS2(    and   esi, w                        )   \
+    AS2(    lea     z, [edi + z + 0x5A827999]   )   \
+    AS2(    mov   edi, v                        )   \
+    AS2(    xor   esi, y                        )   \
+    AS2(    rol   edi, 5                        )   \
+    AS2(    add     z, esi                      )   \
+    AS2(    rol     w, 30                       )   \
+    AS2(    add     z, edi                      )
+
+
+/*  Some macro stuff, but older gas ( < 2,16 ) can't process &, so do by hand
+    % won't work on gas at all
+
+#define xstr(s) str(s)
+#define  str(s) #s
+
+#define WOFF1(a) ( a       & 15)
+#define WOFF2(a) ((a +  2) & 15)
+#define WOFF3(a) ((a +  8) & 15)
+#define WOFF4(a) ((a + 13) & 15)
+
+#ifdef __GNUC__
+    #define WGET1(i) asm("mov esp, [edi - "xstr(WOFF1(i))" * 4] ");
+    #define WGET2(i) asm("xor esp, [edi - "xstr(WOFF2(i))" * 4] ");
+    #define WGET3(i) asm("xor esp, [edi - "xstr(WOFF3(i))" * 4] ");
+    #define WGET4(i) asm("xor esp, [edi - "xstr(WOFF4(i))" * 4] ");
+    #define WPUT1(i) asm("mov [edi - "xstr(WOFF1(i))" * 4], esp ");
+#else
+    #define WGET1(i) AS2( mov   esp, [edi - WOFF1(i) * 4]   )
+    #define WGET2(i) AS2( xor   esp, [edi - WOFF2(i) * 4]   )
+    #define WGET3(i) AS2( xor   esp, [edi - WOFF3(i) * 4]   )
+    #define WGET4(i) AS2( xor   esp, [edi - WOFF4(i) * 4]   )
+    #define WPUT1(i) AS2( mov   [edi - WOFF1(i) * 4], esp   )
+#endif
+*/
+
+// ASMR1 = ASMR0 but use esp for W calcs
+
+#define ASMR1(v,w,x,y,z,i,W1,W2,W3,W4) \
+    AS2(    mov   edi, [esp + W1 * 4]           )   \
+    AS2(    mov   esi, x                        )   \
+    AS2(    xor   edi, [esp + W2 * 4]           )   \
+    AS2(    xor   esi, y                        )   \
+    AS2(    xor   edi, [esp + W3 * 4]           )   \
+    AS2(    and   esi, w                        )   \
+    AS2(    xor   edi, [esp + W4 * 4]           )   \
+    AS2(    rol   edi, 1                        )   \
+    AS2(    xor   esi, y                        )   \
+    AS2(    mov   [esp + W1 * 4], edi           )   \
+    AS2(    lea     z, [edi + z + 0x5A827999]   )   \
+    AS2(    mov   edi, v                        )   \
+    AS2(    rol   edi, 5                        )   \
+    AS2(    add     z, esi                      )   \
+    AS2(    rol     w, 30                       )   \
+    AS2(    add     z, edi                      )
+
+
+// ASMR2 = ASMR1 but f is xor, xor instead
+
+#define ASMR2(v,w,x,y,z,i,W1,W2,W3,W4) \
+    AS2(    mov   edi, [esp + W1 * 4]           )   \
+    AS2(    mov   esi, x                        )   \
+    AS2(    xor   edi, [esp + W2 * 4]           )   \
+    AS2(    xor   esi, y                        )   \
+    AS2(    xor   edi, [esp + W3 * 4]           )   \
+    AS2(    xor   esi, w                        )   \
+    AS2(    xor   edi, [esp + W4 * 4]           )   \
+    AS2(    rol   edi, 1                        )   \
+    AS2(    add     z, esi                      )   \
+    AS2(    mov   [esp + W1 * 4], edi           )   \
+    AS2(    lea     z, [edi + z + 0x6ED9EBA1]   )   \
+    AS2(    mov   edi, v                        )   \
+    AS2(    rol   edi, 5                        )   \
+    AS2(    rol     w, 30                       )   \
+    AS2(    add     z, edi                      )
+
+
+// ASMR3 = ASMR2 but f is (x&y)|(z&(x|y))
+//               which is (w&x)|(y&(w|x))
+
+#define ASMR3(v,w,x,y,z,i,W1,W2,W3,W4) \
+    AS2(    mov   edi, [esp + W1 * 4]           )   \
+    AS2(    mov   esi, x                        )   \
+    AS2(    xor   edi, [esp + W2 * 4]           )   \
+    AS2(     or   esi, w                        )   \
+    AS2(    xor   edi, [esp + W3 * 4]           )   \
+    AS2(    and   esi, y                        )   \
+    AS2(    xor   edi, [esp + W4 * 4]           )   \
+    AS2(    movd  mm0, esi                      )   \
+    AS2(    rol   edi, 1                        )   \
+    AS2(    mov   esi, x                        )   \
+    AS2(    mov   [esp + W1 * 4], edi           )   \
+    AS2(    and   esi, w                        )   \
+    AS2(    lea     z, [edi + z + 0x8F1BBCDC]   )   \
+    AS2(    movd  edi, mm0                      )   \
+    AS2(     or   esi, edi                      )   \
+    AS2(    mov   edi, v                        )   \
+    AS2(    rol   edi, 5                        )   \
+    AS2(    add     z, esi                      )   \
+    AS2(    rol     w, 30                       )   \
+    AS2(    add     z, edi                      )
+
+
+// ASMR4 = ASMR2 but different constant
+
+#define ASMR4(v,w,x,y,z,i,W1,W2,W3,W4) \
+    AS2(    mov   edi, [esp + W1 * 4]           )   \
+    AS2(    mov   esi, x                        )   \
+    AS2(    xor   edi, [esp + W2 * 4]           )   \
+    AS2(    xor   esi, y                        )   \
+    AS2(    xor   edi, [esp + W3 * 4]           )   \
+    AS2(    xor   esi, w                        )   \
+    AS2(    xor   edi, [esp + W4 * 4]           )   \
+    AS2(    rol   edi, 1                        )   \
+    AS2(    add     z, esi                      )   \
+    AS2(    mov   [esp + W1 * 4], edi           )   \
+    AS2(    lea     z, [edi + z + 0xCA62C1D6]   )   \
+    AS2(    mov   edi, v                        )   \
+    AS2(    rol   edi, 5                        )   \
+    AS2(    rol     w, 30                       )   \
+    AS2(    add     z, edi                      )
+
+
+#ifdef _MSC_VER
+    __declspec(naked) 
+#endif
+void SHA::AsmTransform(const byte* data, word32 times)
+{
+#ifdef __GNUC__
+    #define AS1(x)    asm(#x);
+    #define AS2(x, y) asm(#x ", " #y);
+
+    #define PROLOG()  \
+        asm(".intel_syntax noprefix"); \
+        AS2(    movd  mm3, edi                      )   \
+        AS2(    movd  mm4, ebx                      )   \
+        AS2(    movd  mm5, esi                      )   \
+        AS2(    movd  mm6, ebp                      )   \
+        AS2(    mov   ecx, DWORD PTR [ebp +  8]     )   \
+        AS2(    mov   edi, DWORD PTR [ebp + 12]     )   \
+        AS2(    mov   eax, DWORD PTR [ebp + 16]     )
+
+    #define EPILOG()  \
+        AS2(    movd  ebp, mm6                  )   \
+        AS2(    movd  esi, mm5                  )   \
+        AS2(    movd  ebx, mm4                  )   \
+        AS2(    mov   esp, ebp                  )   \
+        AS2(    movd  edi, mm3                  )   \
+        AS1(    emms                            )   \
+        asm(".att_syntax");
+#else
+    #define AS1(x)    __asm x
+    #define AS2(x, y) __asm x, y
+
+    #define PROLOG() \
+        AS1(    push  ebp                           )   \
+        AS2(    mov   ebp, esp                      )   \
+        AS2(    movd  mm3, edi                      )   \
+        AS2(    movd  mm4, ebx                      )   \
+        AS2(    movd  mm5, esi                      )   \
+        AS2(    movd  mm6, ebp                      )   \
+        AS2(    mov   edi, data                     )   \
+        AS2(    mov   eax, times                    )
+
+    #define EPILOG() \
+        AS2(    movd  ebp, mm6                  )   \
+        AS2(    movd  esi, mm5                  )   \
+        AS2(    movd  ebx, mm4                  )   \
+        AS2(    movd  edi, mm3                  )   \
+        AS2(    mov   esp, ebp                  )   \
+        AS1(    pop   ebp                       )   \
+        AS1(    emms   )                            \
+        AS1(    ret 8  )   
+#endif
+
+    PROLOG()
+
+    AS2(    mov   esi, ecx              )
+
+    #ifdef OLD_GCC_OFFSET
+        AS2(    add   esi, 20               )   // digest_[0]
+    #else
+        AS2(    add   esi, 16               )   // digest_[0]
+    #endif
+
+    AS2(    movd  mm2, eax              )   // store times_
+    AS2(    movd  mm1, esi              )   // store digest_
+
+    AS2(    sub   esp, 68               )   // make room on stack
+
+AS1( loopStart: )
+
+    // byte reverse 16 words of input, 4 at a time, put on stack for W[]
+
+    // part 1
+    AS2(    mov   eax, [edi]        )
+    AS2(    mov   ebx, [edi +  4]   )
+    AS2(    mov   ecx, [edi +  8]   )
+    AS2(    mov   edx, [edi + 12]   )
+
+    AS1(    bswap eax   )
+    AS1(    bswap ebx   )
+    AS1(    bswap ecx   )
+    AS1(    bswap edx   )
+
+    AS2(    mov   [esp],      eax   )
+    AS2(    mov   [esp +  4], ebx   )
+    AS2(    mov   [esp +  8], ecx   )
+    AS2(    mov   [esp + 12], edx   )
+
+    // part 2
+    AS2(    mov   eax, [edi + 16]   )
+    AS2(    mov   ebx, [edi + 20]   )
+    AS2(    mov   ecx, [edi + 24]   )
+    AS2(    mov   edx, [edi + 28]   )
+
+    AS1(    bswap eax   )
+    AS1(    bswap ebx   )
+    AS1(    bswap ecx   )
+    AS1(    bswap edx   )
+
+    AS2(    mov   [esp + 16], eax   )
+    AS2(    mov   [esp + 20], ebx   )
+    AS2(    mov   [esp + 24], ecx   )
+    AS2(    mov   [esp + 28], edx   )
+
+
+    // part 3
+    AS2(    mov   eax, [edi + 32]   )
+    AS2(    mov   ebx, [edi + 36]   )
+    AS2(    mov   ecx, [edi + 40]   )
+    AS2(    mov   edx, [edi + 44]   )
+
+    AS1(    bswap eax   )
+    AS1(    bswap ebx   )
+    AS1(    bswap ecx   )
+    AS1(    bswap edx   )
+
+    AS2(    mov   [esp + 32], eax   )
+    AS2(    mov   [esp + 36], ebx   )
+    AS2(    mov   [esp + 40], ecx   )
+    AS2(    mov   [esp + 44], edx   )
+
+
+    // part 4
+    AS2(    mov   eax, [edi + 48]   )
+    AS2(    mov   ebx, [edi + 52]   )
+    AS2(    mov   ecx, [edi + 56]   )
+    AS2(    mov   edx, [edi + 60]   )
+
+    AS1(    bswap eax   )
+    AS1(    bswap ebx   )
+    AS1(    bswap ecx   )
+    AS1(    bswap edx   )
+
+    AS2(    mov   [esp + 48], eax   )
+    AS2(    mov   [esp + 52], ebx   )
+    AS2(    mov   [esp + 56], ecx   )
+    AS2(    mov   [esp + 60], edx   )
+
+    AS2(    mov   [esp + 64], edi   )   // store edi for end
+
+    // read from digest_
+    AS2(    mov   eax, [esi]            )   // a1
+    AS2(    mov   ebx, [esi +  4]       )   // b1
+    AS2(    mov   ecx, [esi +  8]       )   // c1
+    AS2(    mov   edx, [esi + 12]       )   // d1
+    AS2(    mov   ebp, [esi + 16]       )   // e1
+
+
+    ASMR0(eax, ebx, ecx, edx, ebp,  0)
+    ASMR0(ebp, eax, ebx, ecx, edx,  1)
+    ASMR0(edx, ebp, eax, ebx, ecx,  2)
+    ASMR0(ecx, edx, ebp, eax, ebx,  3)
+    ASMR0(ebx, ecx, edx, ebp, eax,  4)
+    ASMR0(eax, ebx, ecx, edx, ebp,  5)
+    ASMR0(ebp, eax, ebx, ecx, edx,  6)
+    ASMR0(edx, ebp, eax, ebx, ecx,  7)
+    ASMR0(ecx, edx, ebp, eax, ebx,  8)
+    ASMR0(ebx, ecx, edx, ebp, eax,  9)
+    ASMR0(eax, ebx, ecx, edx, ebp, 10)
+    ASMR0(ebp, eax, ebx, ecx, edx, 11)
+    ASMR0(edx, ebp, eax, ebx, ecx, 12)
+    ASMR0(ecx, edx, ebp, eax, ebx, 13)
+    ASMR0(ebx, ecx, edx, ebp, eax, 14)
+    ASMR0(eax, ebx, ecx, edx, ebp, 15)
+
+    ASMR1(ebp, eax, ebx, ecx, edx, 16,  0,  2,  8, 13)
+    ASMR1(edx, ebp, eax, ebx, ecx, 17,  1,  3,  9, 14)
+    ASMR1(ecx, edx, ebp, eax, ebx, 18,  2,  4, 10, 15)
+    ASMR1(ebx, ecx, edx, ebp, eax, 19,  3,  5, 11,  0)
+
+    ASMR2(eax, ebx, ecx, edx, ebp, 20,  4,  6, 12,  1)
+    ASMR2(ebp, eax, ebx, ecx, edx, 21,  5,  7, 13,  2)
+    ASMR2(edx, ebp, eax, ebx, ecx, 22,  6,  8, 14,  3)
+    ASMR2(ecx, edx, ebp, eax, ebx, 23,  7,  9, 15,  4)
+    ASMR2(ebx, ecx, edx, ebp, eax, 24,  8, 10,  0,  5)
+    ASMR2(eax, ebx, ecx, edx, ebp, 25,  9, 11,  1,  6)
+    ASMR2(ebp, eax, ebx, ecx, edx, 26, 10, 12,  2,  7)
+    ASMR2(edx, ebp, eax, ebx, ecx, 27, 11, 13,  3,  8)
+    ASMR2(ecx, edx, ebp, eax, ebx, 28, 12, 14,  4,  9)
+    ASMR2(ebx, ecx, edx, ebp, eax, 29, 13, 15,  5, 10)
+    ASMR2(eax, ebx, ecx, edx, ebp, 30, 14,  0,  6, 11)
+    ASMR2(ebp, eax, ebx, ecx, edx, 31, 15,  1,  7, 12)
+    ASMR2(edx, ebp, eax, ebx, ecx, 32,  0,  2,  8, 13)
+    ASMR2(ecx, edx, ebp, eax, ebx, 33,  1,  3,  9, 14)
+    ASMR2(ebx, ecx, edx, ebp, eax, 34,  2,  4, 10, 15)
+    ASMR2(eax, ebx, ecx, edx, ebp, 35,  3,  5, 11,  0)
+    ASMR2(ebp, eax, ebx, ecx, edx, 36,  4,  6, 12,  1)
+    ASMR2(edx, ebp, eax, ebx, ecx, 37,  5,  7, 13,  2)
+    ASMR2(ecx, edx, ebp, eax, ebx, 38,  6,  8, 14,  3)
+    ASMR2(ebx, ecx, edx, ebp, eax, 39,  7,  9, 15,  4)
+
+
+    ASMR3(eax, ebx, ecx, edx, ebp, 40,  8, 10,  0,  5)
+    ASMR3(ebp, eax, ebx, ecx, edx, 41,  9, 11,  1,  6)
+    ASMR3(edx, ebp, eax, ebx, ecx, 42, 10, 12,  2,  7)
+    ASMR3(ecx, edx, ebp, eax, ebx, 43, 11, 13,  3,  8)
+    ASMR3(ebx, ecx, edx, ebp, eax, 44, 12, 14,  4,  9)
+    ASMR3(eax, ebx, ecx, edx, ebp, 45, 13, 15,  5, 10)
+    ASMR3(ebp, eax, ebx, ecx, edx, 46, 14,  0,  6, 11)
+    ASMR3(edx, ebp, eax, ebx, ecx, 47, 15,  1,  7, 12)
+    ASMR3(ecx, edx, ebp, eax, ebx, 48,  0,  2,  8, 13)
+    ASMR3(ebx, ecx, edx, ebp, eax, 49,  1,  3,  9, 14)
+    ASMR3(eax, ebx, ecx, edx, ebp, 50,  2,  4, 10, 15)
+    ASMR3(ebp, eax, ebx, ecx, edx, 51,  3,  5, 11,  0)
+    ASMR3(edx, ebp, eax, ebx, ecx, 52,  4,  6, 12,  1)
+    ASMR3(ecx, edx, ebp, eax, ebx, 53,  5,  7, 13,  2)
+    ASMR3(ebx, ecx, edx, ebp, eax, 54,  6,  8, 14,  3)
+    ASMR3(eax, ebx, ecx, edx, ebp, 55,  7,  9, 15,  4)
+    ASMR3(ebp, eax, ebx, ecx, edx, 56,  8, 10,  0,  5)
+    ASMR3(edx, ebp, eax, ebx, ecx, 57,  9, 11,  1,  6)
+    ASMR3(ecx, edx, ebp, eax, ebx, 58, 10, 12,  2,  7)
+    ASMR3(ebx, ecx, edx, ebp, eax, 59, 11, 13,  3,  8)
+
+    ASMR4(eax, ebx, ecx, edx, ebp, 60, 12, 14,  4,  9)
+    ASMR4(ebp, eax, ebx, ecx, edx, 61, 13, 15,  5, 10)
+    ASMR4(edx, ebp, eax, ebx, ecx, 62, 14,  0,  6, 11)
+    ASMR4(ecx, edx, ebp, eax, ebx, 63, 15,  1,  7, 12)
+    ASMR4(ebx, ecx, edx, ebp, eax, 64,  0,  2,  8, 13)
+    ASMR4(eax, ebx, ecx, edx, ebp, 65,  1,  3,  9, 14)
+    ASMR4(ebp, eax, ebx, ecx, edx, 66,  2,  4, 10, 15)
+    ASMR4(edx, ebp, eax, ebx, ecx, 67,  3,  5, 11,  0)
+    ASMR4(ecx, edx, ebp, eax, ebx, 68,  4,  6, 12,  1)
+    ASMR4(ebx, ecx, edx, ebp, eax, 69,  5,  7, 13,  2)
+    ASMR4(eax, ebx, ecx, edx, ebp, 70,  6,  8, 14,  3)
+    ASMR4(ebp, eax, ebx, ecx, edx, 71,  7,  9, 15,  4)
+    ASMR4(edx, ebp, eax, ebx, ecx, 72,  8, 10,  0,  5)
+    ASMR4(ecx, edx, ebp, eax, ebx, 73,  9, 11,  1,  6)
+    ASMR4(ebx, ecx, edx, ebp, eax, 74, 10, 12,  2,  7)
+    ASMR4(eax, ebx, ecx, edx, ebp, 75, 11, 13,  3,  8)
+    ASMR4(ebp, eax, ebx, ecx, edx, 76, 12, 14,  4,  9)
+    ASMR4(edx, ebp, eax, ebx, ecx, 77, 13, 15,  5, 10)
+    ASMR4(ecx, edx, ebp, eax, ebx, 78, 14,  0,  6, 11)
+    ASMR4(ebx, ecx, edx, ebp, eax, 79, 15,  1,  7, 12)
+
+
+    AS2(    movd  esi, mm1              )   // digest_
+
+    AS2(    add   [esi],      eax       )   // write out
+    AS2(    add   [esi +  4], ebx       )
+    AS2(    add   [esi +  8], ecx       )
+    AS2(    add   [esi + 12], edx       )
+    AS2(    add   [esi + 16], ebp       )
+
+    // setup next round
+    AS2(    movd  ebp, mm2              )   // times
+ 
+    AS2(    mov   edi, DWORD PTR [esp + 64] )   // data
+    
+    AS2(    add   edi, 64               )   // next round of data
+    AS2(    mov   [esp + 64], edi       )   // restore
+    
+    AS1(    dec   ebp                   )
+    AS2(    movd  mm2, ebp              )
+    AS1(    jnz   loopStart             )
+
+
+    EPILOG()
+}
+
+
+#endif // DO_SHA_ASM
+
 } // namespace
diff --git a/extra/yassl/taocrypt/src/tftables.cpp b/extra/yassl/taocrypt/src/tftables.cpp
new file mode 100644
index 00000000000..55846d5f79d
--- /dev/null
+++ b/extra/yassl/taocrypt/src/tftables.cpp
@@ -0,0 +1,352 @@
+/* tftables.cpp                                
+ *
+ * Copyright (C) 2003 Sawtooth Consulting Ltd.
+ *
+ * This file is part of yaSSL.
+ *
+ * yaSSL 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; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * yaSSL 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ */
+
+/* based on Wei Dai's tftables.cpp from CryptoPP */
+
+#include "runtime.hpp"
+#include "twofish.hpp"
+
+
+namespace TaoCrypt {
+
+
+const byte Twofish::q_[2][256] = {
+{
+   0xA9, 0x67, 0xB3, 0xE8, 0x04, 0xFD, 0xA3, 0x76, 0x9A, 0x92, 0x80, 0x78,
+   0xE4, 0xDD, 0xD1, 0x38, 0x0D, 0xC6, 0x35, 0x98, 0x18, 0xF7, 0xEC, 0x6C,
+   0x43, 0x75, 0x37, 0x26, 0xFA, 0x13, 0x94, 0x48, 0xF2, 0xD0, 0x8B, 0x30,
+   0x84, 0x54, 0xDF, 0x23, 0x19, 0x5B, 0x3D, 0x59, 0xF3, 0xAE, 0xA2, 0x82,
+   0x63, 0x01, 0x83, 0x2E, 0xD9, 0x51, 0x9B, 0x7C, 0xA6, 0xEB, 0xA5, 0xBE,
+   0x16, 0x0C, 0xE3, 0x61, 0xC0, 0x8C, 0x3A, 0xF5, 0x73, 0x2C, 0x25, 0x0B,
+   0xBB, 0x4E, 0x89, 0x6B, 0x53, 0x6A, 0xB4, 0xF1, 0xE1, 0xE6, 0xBD, 0x45,
+   0xE2, 0xF4, 0xB6, 0x66, 0xCC, 0x95, 0x03, 0x56, 0xD4, 0x1C, 0x1E, 0xD7,
+   0xFB, 0xC3, 0x8E, 0xB5, 0xE9, 0xCF, 0xBF, 0xBA, 0xEA, 0x77, 0x39, 0xAF,
+   0x33, 0xC9, 0x62, 0x71, 0x81, 0x79, 0x09, 0xAD, 0x24, 0xCD, 0xF9, 0xD8,
+   0xE5, 0xC5, 0xB9, 0x4D, 0x44, 0x08, 0x86, 0xE7, 0xA1, 0x1D, 0xAA, 0xED,
+   0x06, 0x70, 0xB2, 0xD2, 0x41, 0x7B, 0xA0, 0x11, 0x31, 0xC2, 0x27, 0x90,
+   0x20, 0xF6, 0x60, 0xFF, 0x96, 0x5C, 0xB1, 0xAB, 0x9E, 0x9C, 0x52, 0x1B,
+   0x5F, 0x93, 0x0A, 0xEF, 0x91, 0x85, 0x49, 0xEE, 0x2D, 0x4F, 0x8F, 0x3B,
+   0x47, 0x87, 0x6D, 0x46, 0xD6, 0x3E, 0x69, 0x64, 0x2A, 0xCE, 0xCB, 0x2F,
+   0xFC, 0x97, 0x05, 0x7A, 0xAC, 0x7F, 0xD5, 0x1A, 0x4B, 0x0E, 0xA7, 0x5A,
+   0x28, 0x14, 0x3F, 0x29, 0x88, 0x3C, 0x4C, 0x02, 0xB8, 0xDA, 0xB0, 0x17,
+   0x55, 0x1F, 0x8A, 0x7D, 0x57, 0xC7, 0x8D, 0x74, 0xB7, 0xC4, 0x9F, 0x72,
+   0x7E, 0x15, 0x22, 0x12, 0x58, 0x07, 0x99, 0x34, 0x6E, 0x50, 0xDE, 0x68,
+   0x65, 0xBC, 0xDB, 0xF8, 0xC8, 0xA8, 0x2B, 0x40, 0xDC, 0xFE, 0x32, 0xA4,
+   0xCA, 0x10, 0x21, 0xF0, 0xD3, 0x5D, 0x0F, 0x00, 0x6F, 0x9D, 0x36, 0x42,
+   0x4A, 0x5E, 0xC1, 0xE0
+},
+{
+   0x75, 0xF3, 0xC6, 0xF4, 0xDB, 0x7B, 0xFB, 0xC8, 0x4A, 0xD3, 0xE6, 0x6B,
+   0x45, 0x7D, 0xE8, 0x4B, 0xD6, 0x32, 0xD8, 0xFD, 0x37, 0x71, 0xF1, 0xE1,
+   0x30, 0x0F, 0xF8, 0x1B, 0x87, 0xFA, 0x06, 0x3F, 0x5E, 0xBA, 0xAE, 0x5B,
+   0x8A, 0x00, 0xBC, 0x9D, 0x6D, 0xC1, 0xB1, 0x0E, 0x80, 0x5D, 0xD2, 0xD5,
+   0xA0, 0x84, 0x07, 0x14, 0xB5, 0x90, 0x2C, 0xA3, 0xB2, 0x73, 0x4C, 0x54,
+   0x92, 0x74, 0x36, 0x51, 0x38, 0xB0, 0xBD, 0x5A, 0xFC, 0x60, 0x62, 0x96,
+   0x6C, 0x42, 0xF7, 0x10, 0x7C, 0x28, 0x27, 0x8C, 0x13, 0x95, 0x9C, 0xC7,
+   0x24, 0x46, 0x3B, 0x70, 0xCA, 0xE3, 0x85, 0xCB, 0x11, 0xD0, 0x93, 0xB8,
+   0xA6, 0x83, 0x20, 0xFF, 0x9F, 0x77, 0xC3, 0xCC, 0x03, 0x6F, 0x08, 0xBF,
+   0x40, 0xE7, 0x2B, 0xE2, 0x79, 0x0C, 0xAA, 0x82, 0x41, 0x3A, 0xEA, 0xB9,
+   0xE4, 0x9A, 0xA4, 0x97, 0x7E, 0xDA, 0x7A, 0x17, 0x66, 0x94, 0xA1, 0x1D,
+   0x3D, 0xF0, 0xDE, 0xB3, 0x0B, 0x72, 0xA7, 0x1C, 0xEF, 0xD1, 0x53, 0x3E,
+   0x8F, 0x33, 0x26, 0x5F, 0xEC, 0x76, 0x2A, 0x49, 0x81, 0x88, 0xEE, 0x21,
+   0xC4, 0x1A, 0xEB, 0xD9, 0xC5, 0x39, 0x99, 0xCD, 0xAD, 0x31, 0x8B, 0x01,
+   0x18, 0x23, 0xDD, 0x1F, 0x4E, 0x2D, 0xF9, 0x48, 0x4F, 0xF2, 0x65, 0x8E,
+   0x78, 0x5C, 0x58, 0x19, 0x8D, 0xE5, 0x98, 0x57, 0x67, 0x7F, 0x05, 0x64,
+   0xAF, 0x63, 0xB6, 0xFE, 0xF5, 0xB7, 0x3C, 0xA5, 0xCE, 0xE9, 0x68, 0x44,
+   0xE0, 0x4D, 0x43, 0x69, 0x29, 0x2E, 0xAC, 0x15, 0x59, 0xA8, 0x0A, 0x9E,
+   0x6E, 0x47, 0xDF, 0x34, 0x35, 0x6A, 0xCF, 0xDC, 0x22, 0xC9, 0xC0, 0x9B,
+   0x89, 0xD4, 0xED, 0xAB, 0x12, 0xA2, 0x0D, 0x52, 0xBB, 0x02, 0x2F, 0xA9,
+   0xD7, 0x61, 0x1E, 0xB4, 0x50, 0x04, 0xF6, 0xC2, 0x16, 0x25, 0x86, 0x56,
+   0x55, 0x09, 0xBE, 0x91
+}
+};
+
+
+const word32 Twofish::mds_[4][256] = {
+    {
+	0xbcbc3275, 0xecec21f3, 0x202043c6, 0xb3b3c9f4, 
+	0xdada03db, 0x02028b7b, 0xe2e22bfb, 0x9e9efac8, 
+	0xc9c9ec4a, 0xd4d409d3, 0x18186be6, 0x1e1e9f6b, 
+	0x98980e45, 0xb2b2387d, 0xa6a6d2e8, 0x2626b74b, 
+	0x3c3c57d6, 0x93938a32, 0x8282eed8, 0x525298fd, 
+	0x7b7bd437, 0xbbbb3771, 0x5b5b97f1, 0x474783e1, 
+	0x24243c30, 0x5151e20f, 0xbabac6f8, 0x4a4af31b, 
+	0xbfbf4887, 0x0d0d70fa, 0xb0b0b306, 0x7575de3f, 
+	0xd2d2fd5e, 0x7d7d20ba, 0x666631ae, 0x3a3aa35b, 
+	0x59591c8a, 0x00000000, 0xcdcd93bc, 0x1a1ae09d, 
+	0xaeae2c6d, 0x7f7fabc1, 0x2b2bc7b1, 0xbebeb90e, 
+	0xe0e0a080, 0x8a8a105d, 0x3b3b52d2, 0x6464bad5, 
+	0xd8d888a0, 0xe7e7a584, 0x5f5fe807, 0x1b1b1114, 
+	0x2c2cc2b5, 0xfcfcb490, 0x3131272c, 0x808065a3, 
+	0x73732ab2, 0x0c0c8173, 0x79795f4c, 0x6b6b4154, 
+	0x4b4b0292, 0x53536974, 0x94948f36, 0x83831f51, 
+	0x2a2a3638, 0xc4c49cb0, 0x2222c8bd, 0xd5d5f85a, 
+	0xbdbdc3fc, 0x48487860, 0xffffce62, 0x4c4c0796, 
+	0x4141776c, 0xc7c7e642, 0xebeb24f7, 0x1c1c1410, 
+	0x5d5d637c, 0x36362228, 0x6767c027, 0xe9e9af8c, 
+	0x4444f913, 0x1414ea95, 0xf5f5bb9c, 0xcfcf18c7, 
+	0x3f3f2d24, 0xc0c0e346, 0x7272db3b, 0x54546c70, 
+	0x29294cca, 0xf0f035e3, 0x0808fe85, 0xc6c617cb, 
+	0xf3f34f11, 0x8c8ce4d0, 0xa4a45993, 0xcaca96b8, 
+	0x68683ba6, 0xb8b84d83, 0x38382820, 0xe5e52eff, 
+	0xadad569f, 0x0b0b8477, 0xc8c81dc3, 0x9999ffcc, 
+	0x5858ed03, 0x19199a6f, 0x0e0e0a08, 0x95957ebf, 
+	0x70705040, 0xf7f730e7, 0x6e6ecf2b, 0x1f1f6ee2, 
+	0xb5b53d79, 0x09090f0c, 0x616134aa, 0x57571682, 
+	0x9f9f0b41, 0x9d9d803a, 0x111164ea, 0x2525cdb9, 
+	0xafafdde4, 0x4545089a, 0xdfdf8da4, 0xa3a35c97, 
+	0xeaead57e, 0x353558da, 0xededd07a, 0x4343fc17, 
+	0xf8f8cb66, 0xfbfbb194, 0x3737d3a1, 0xfafa401d, 
+	0xc2c2683d, 0xb4b4ccf0, 0x32325dde, 0x9c9c71b3, 
+	0x5656e70b, 0xe3e3da72, 0x878760a7, 0x15151b1c, 
+	0xf9f93aef, 0x6363bfd1, 0x3434a953, 0x9a9a853e, 
+	0xb1b1428f, 0x7c7cd133, 0x88889b26, 0x3d3da65f, 
+	0xa1a1d7ec, 0xe4e4df76, 0x8181942a, 0x91910149, 
+	0x0f0ffb81, 0xeeeeaa88, 0x161661ee, 0xd7d77321, 
+	0x9797f5c4, 0xa5a5a81a, 0xfefe3feb, 0x6d6db5d9, 
+	0x7878aec5, 0xc5c56d39, 0x1d1de599, 0x7676a4cd, 
+	0x3e3edcad, 0xcbcb6731, 0xb6b6478b, 0xefef5b01, 
+	0x12121e18, 0x6060c523, 0x6a6ab0dd, 0x4d4df61f, 
+	0xcecee94e, 0xdede7c2d, 0x55559df9, 0x7e7e5a48, 
+	0x2121b24f, 0x03037af2, 0xa0a02665, 0x5e5e198e, 
+	0x5a5a6678, 0x65654b5c, 0x62624e58, 0xfdfd4519, 
+	0x0606f48d, 0x404086e5, 0xf2f2be98, 0x3333ac57, 
+	0x17179067, 0x05058e7f, 0xe8e85e05, 0x4f4f7d64, 
+	0x89896aaf, 0x10109563, 0x74742fb6, 0x0a0a75fe, 
+	0x5c5c92f5, 0x9b9b74b7, 0x2d2d333c, 0x3030d6a5, 
+	0x2e2e49ce, 0x494989e9, 0x46467268, 0x77775544, 
+	0xa8a8d8e0, 0x9696044d, 0x2828bd43, 0xa9a92969, 
+	0xd9d97929, 0x8686912e, 0xd1d187ac, 0xf4f44a15, 
+	0x8d8d1559, 0xd6d682a8, 0xb9b9bc0a, 0x42420d9e, 
+	0xf6f6c16e, 0x2f2fb847, 0xdddd06df, 0x23233934, 
+	0xcccc6235, 0xf1f1c46a, 0xc1c112cf, 0x8585ebdc, 
+	0x8f8f9e22, 0x7171a1c9, 0x9090f0c0, 0xaaaa539b, 
+	0x0101f189, 0x8b8be1d4, 0x4e4e8ced, 0x8e8e6fab, 
+	0xababa212, 0x6f6f3ea2, 0xe6e6540d, 0xdbdbf252, 
+	0x92927bbb, 0xb7b7b602, 0x6969ca2f, 0x3939d9a9, 
+	0xd3d30cd7, 0xa7a72361, 0xa2a2ad1e, 0xc3c399b4, 
+	0x6c6c4450, 0x07070504, 0x04047ff6, 0x272746c2, 
+	0xacaca716, 0xd0d07625, 0x50501386, 0xdcdcf756, 
+	0x84841a55, 0xe1e15109, 0x7a7a25be, 0x1313ef91
+    },
+    {
+	0xa9d93939, 0x67901717, 0xb3719c9c, 0xe8d2a6a6, 
+	0x04050707, 0xfd985252, 0xa3658080, 0x76dfe4e4, 
+	0x9a084545, 0x92024b4b, 0x80a0e0e0, 0x78665a5a, 
+	0xe4ddafaf, 0xddb06a6a, 0xd1bf6363, 0x38362a2a, 
+	0x0d54e6e6, 0xc6432020, 0x3562cccc, 0x98bef2f2, 
+	0x181e1212, 0xf724ebeb, 0xecd7a1a1, 0x6c774141, 
+	0x43bd2828, 0x7532bcbc, 0x37d47b7b, 0x269b8888, 
+	0xfa700d0d, 0x13f94444, 0x94b1fbfb, 0x485a7e7e, 
+	0xf27a0303, 0xd0e48c8c, 0x8b47b6b6, 0x303c2424, 
+	0x84a5e7e7, 0x54416b6b, 0xdf06dddd, 0x23c56060, 
+	0x1945fdfd, 0x5ba33a3a, 0x3d68c2c2, 0x59158d8d, 
+	0xf321ecec, 0xae316666, 0xa23e6f6f, 0x82165757, 
+	0x63951010, 0x015befef, 0x834db8b8, 0x2e918686, 
+	0xd9b56d6d, 0x511f8383, 0x9b53aaaa, 0x7c635d5d, 
+	0xa63b6868, 0xeb3ffefe, 0xa5d63030, 0xbe257a7a, 
+	0x16a7acac, 0x0c0f0909, 0xe335f0f0, 0x6123a7a7, 
+	0xc0f09090, 0x8cafe9e9, 0x3a809d9d, 0xf5925c5c, 
+	0x73810c0c, 0x2c273131, 0x2576d0d0, 0x0be75656, 
+	0xbb7b9292, 0x4ee9cece, 0x89f10101, 0x6b9f1e1e, 
+	0x53a93434, 0x6ac4f1f1, 0xb499c3c3, 0xf1975b5b, 
+	0xe1834747, 0xe66b1818, 0xbdc82222, 0x450e9898, 
+	0xe26e1f1f, 0xf4c9b3b3, 0xb62f7474, 0x66cbf8f8, 
+	0xccff9999, 0x95ea1414, 0x03ed5858, 0x56f7dcdc, 
+	0xd4e18b8b, 0x1c1b1515, 0x1eada2a2, 0xd70cd3d3, 
+	0xfb2be2e2, 0xc31dc8c8, 0x8e195e5e, 0xb5c22c2c, 
+	0xe9894949, 0xcf12c1c1, 0xbf7e9595, 0xba207d7d, 
+	0xea641111, 0x77840b0b, 0x396dc5c5, 0xaf6a8989, 
+	0x33d17c7c, 0xc9a17171, 0x62ceffff, 0x7137bbbb, 
+	0x81fb0f0f, 0x793db5b5, 0x0951e1e1, 0xaddc3e3e, 
+	0x242d3f3f, 0xcda47676, 0xf99d5555, 0xd8ee8282, 
+	0xe5864040, 0xc5ae7878, 0xb9cd2525, 0x4d049696, 
+	0x44557777, 0x080a0e0e, 0x86135050, 0xe730f7f7, 
+	0xa1d33737, 0x1d40fafa, 0xaa346161, 0xed8c4e4e, 
+	0x06b3b0b0, 0x706c5454, 0xb22a7373, 0xd2523b3b, 
+	0x410b9f9f, 0x7b8b0202, 0xa088d8d8, 0x114ff3f3, 
+	0x3167cbcb, 0xc2462727, 0x27c06767, 0x90b4fcfc, 
+	0x20283838, 0xf67f0404, 0x60784848, 0xff2ee5e5, 
+	0x96074c4c, 0x5c4b6565, 0xb1c72b2b, 0xab6f8e8e, 
+	0x9e0d4242, 0x9cbbf5f5, 0x52f2dbdb, 0x1bf34a4a, 
+	0x5fa63d3d, 0x9359a4a4, 0x0abcb9b9, 0xef3af9f9, 
+	0x91ef1313, 0x85fe0808, 0x49019191, 0xee611616, 
+	0x2d7cdede, 0x4fb22121, 0x8f42b1b1, 0x3bdb7272, 
+	0x47b82f2f, 0x8748bfbf, 0x6d2caeae, 0x46e3c0c0, 
+	0xd6573c3c, 0x3e859a9a, 0x6929a9a9, 0x647d4f4f, 
+	0x2a948181, 0xce492e2e, 0xcb17c6c6, 0x2fca6969, 
+	0xfcc3bdbd, 0x975ca3a3, 0x055ee8e8, 0x7ad0eded, 
+	0xac87d1d1, 0x7f8e0505, 0xd5ba6464, 0x1aa8a5a5, 
+	0x4bb72626, 0x0eb9bebe, 0xa7608787, 0x5af8d5d5, 
+	0x28223636, 0x14111b1b, 0x3fde7575, 0x2979d9d9, 
+	0x88aaeeee, 0x3c332d2d, 0x4c5f7979, 0x02b6b7b7, 
+	0xb896caca, 0xda583535, 0xb09cc4c4, 0x17fc4343, 
+	0x551a8484, 0x1ff64d4d, 0x8a1c5959, 0x7d38b2b2, 
+	0x57ac3333, 0xc718cfcf, 0x8df40606, 0x74695353, 
+	0xb7749b9b, 0xc4f59797, 0x9f56adad, 0x72dae3e3, 
+	0x7ed5eaea, 0x154af4f4, 0x229e8f8f, 0x12a2abab, 
+	0x584e6262, 0x07e85f5f, 0x99e51d1d, 0x34392323, 
+	0x6ec1f6f6, 0x50446c6c, 0xde5d3232, 0x68724646, 
+	0x6526a0a0, 0xbc93cdcd, 0xdb03dada, 0xf8c6baba, 
+	0xc8fa9e9e, 0xa882d6d6, 0x2bcf6e6e, 0x40507070, 
+	0xdceb8585, 0xfe750a0a, 0x328a9393, 0xa48ddfdf, 
+	0xca4c2929, 0x10141c1c, 0x2173d7d7, 0xf0ccb4b4, 
+	0xd309d4d4, 0x5d108a8a, 0x0fe25151, 0x00000000, 
+	0x6f9a1919, 0x9de01a1a, 0x368f9494, 0x42e6c7c7, 
+	0x4aecc9c9, 0x5efdd2d2, 0xc1ab7f7f, 0xe0d8a8a8
+    },
+    {
+	0xbc75bc32, 0xecf3ec21, 0x20c62043, 0xb3f4b3c9, 
+	0xdadbda03, 0x027b028b, 0xe2fbe22b, 0x9ec89efa, 
+	0xc94ac9ec, 0xd4d3d409, 0x18e6186b, 0x1e6b1e9f, 
+	0x9845980e, 0xb27db238, 0xa6e8a6d2, 0x264b26b7, 
+	0x3cd63c57, 0x9332938a, 0x82d882ee, 0x52fd5298, 
+	0x7b377bd4, 0xbb71bb37, 0x5bf15b97, 0x47e14783, 
+	0x2430243c, 0x510f51e2, 0xbaf8bac6, 0x4a1b4af3, 
+	0xbf87bf48, 0x0dfa0d70, 0xb006b0b3, 0x753f75de, 
+	0xd25ed2fd, 0x7dba7d20, 0x66ae6631, 0x3a5b3aa3, 
+	0x598a591c, 0x00000000, 0xcdbccd93, 0x1a9d1ae0, 
+	0xae6dae2c, 0x7fc17fab, 0x2bb12bc7, 0xbe0ebeb9, 
+	0xe080e0a0, 0x8a5d8a10, 0x3bd23b52, 0x64d564ba, 
+	0xd8a0d888, 0xe784e7a5, 0x5f075fe8, 0x1b141b11, 
+	0x2cb52cc2, 0xfc90fcb4, 0x312c3127, 0x80a38065, 
+	0x73b2732a, 0x0c730c81, 0x794c795f, 0x6b546b41, 
+	0x4b924b02, 0x53745369, 0x9436948f, 0x8351831f, 
+	0x2a382a36, 0xc4b0c49c, 0x22bd22c8, 0xd55ad5f8, 
+	0xbdfcbdc3, 0x48604878, 0xff62ffce, 0x4c964c07, 
+	0x416c4177, 0xc742c7e6, 0xebf7eb24, 0x1c101c14, 
+	0x5d7c5d63, 0x36283622, 0x672767c0, 0xe98ce9af, 
+	0x441344f9, 0x149514ea, 0xf59cf5bb, 0xcfc7cf18, 
+	0x3f243f2d, 0xc046c0e3, 0x723b72db, 0x5470546c, 
+	0x29ca294c, 0xf0e3f035, 0x088508fe, 0xc6cbc617, 
+	0xf311f34f, 0x8cd08ce4, 0xa493a459, 0xcab8ca96, 
+	0x68a6683b, 0xb883b84d, 0x38203828, 0xe5ffe52e, 
+	0xad9fad56, 0x0b770b84, 0xc8c3c81d, 0x99cc99ff, 
+	0x580358ed, 0x196f199a, 0x0e080e0a, 0x95bf957e, 
+	0x70407050, 0xf7e7f730, 0x6e2b6ecf, 0x1fe21f6e, 
+	0xb579b53d, 0x090c090f, 0x61aa6134, 0x57825716, 
+	0x9f419f0b, 0x9d3a9d80, 0x11ea1164, 0x25b925cd, 
+	0xafe4afdd, 0x459a4508, 0xdfa4df8d, 0xa397a35c, 
+	0xea7eead5, 0x35da3558, 0xed7aedd0, 0x431743fc, 
+	0xf866f8cb, 0xfb94fbb1, 0x37a137d3, 0xfa1dfa40, 
+	0xc23dc268, 0xb4f0b4cc, 0x32de325d, 0x9cb39c71, 
+	0x560b56e7, 0xe372e3da, 0x87a78760, 0x151c151b, 
+	0xf9eff93a, 0x63d163bf, 0x345334a9, 0x9a3e9a85, 
+	0xb18fb142, 0x7c337cd1, 0x8826889b, 0x3d5f3da6, 
+	0xa1eca1d7, 0xe476e4df, 0x812a8194, 0x91499101, 
+	0x0f810ffb, 0xee88eeaa, 0x16ee1661, 0xd721d773, 
+	0x97c497f5, 0xa51aa5a8, 0xfeebfe3f, 0x6dd96db5, 
+	0x78c578ae, 0xc539c56d, 0x1d991de5, 0x76cd76a4, 
+	0x3ead3edc, 0xcb31cb67, 0xb68bb647, 0xef01ef5b, 
+	0x1218121e, 0x602360c5, 0x6add6ab0, 0x4d1f4df6, 
+	0xce4ecee9, 0xde2dde7c, 0x55f9559d, 0x7e487e5a, 
+	0x214f21b2, 0x03f2037a, 0xa065a026, 0x5e8e5e19, 
+	0x5a785a66, 0x655c654b, 0x6258624e, 0xfd19fd45, 
+	0x068d06f4, 0x40e54086, 0xf298f2be, 0x335733ac, 
+	0x17671790, 0x057f058e, 0xe805e85e, 0x4f644f7d, 
+	0x89af896a, 0x10631095, 0x74b6742f, 0x0afe0a75, 
+	0x5cf55c92, 0x9bb79b74, 0x2d3c2d33, 0x30a530d6, 
+	0x2ece2e49, 0x49e94989, 0x46684672, 0x77447755, 
+	0xa8e0a8d8, 0x964d9604, 0x284328bd, 0xa969a929, 
+	0xd929d979, 0x862e8691, 0xd1acd187, 0xf415f44a, 
+	0x8d598d15, 0xd6a8d682, 0xb90ab9bc, 0x429e420d, 
+	0xf66ef6c1, 0x2f472fb8, 0xdddfdd06, 0x23342339, 
+	0xcc35cc62, 0xf16af1c4, 0xc1cfc112, 0x85dc85eb, 
+	0x8f228f9e, 0x71c971a1, 0x90c090f0, 0xaa9baa53, 
+	0x018901f1, 0x8bd48be1, 0x4eed4e8c, 0x8eab8e6f, 
+	0xab12aba2, 0x6fa26f3e, 0xe60de654, 0xdb52dbf2, 
+	0x92bb927b, 0xb702b7b6, 0x692f69ca, 0x39a939d9, 
+	0xd3d7d30c, 0xa761a723, 0xa21ea2ad, 0xc3b4c399, 
+	0x6c506c44, 0x07040705, 0x04f6047f, 0x27c22746, 
+	0xac16aca7, 0xd025d076, 0x50865013, 0xdc56dcf7, 
+	0x8455841a, 0xe109e151, 0x7abe7a25, 0x139113ef
+    },
+    {
+	0xd939a9d9, 0x90176790, 0x719cb371, 0xd2a6e8d2, 
+	0x05070405, 0x9852fd98, 0x6580a365, 0xdfe476df, 
+	0x08459a08, 0x024b9202, 0xa0e080a0, 0x665a7866, 
+	0xddafe4dd, 0xb06addb0, 0xbf63d1bf, 0x362a3836, 
+	0x54e60d54, 0x4320c643, 0x62cc3562, 0xbef298be, 
+	0x1e12181e, 0x24ebf724, 0xd7a1ecd7, 0x77416c77, 
+	0xbd2843bd, 0x32bc7532, 0xd47b37d4, 0x9b88269b, 
+	0x700dfa70, 0xf94413f9, 0xb1fb94b1, 0x5a7e485a, 
+	0x7a03f27a, 0xe48cd0e4, 0x47b68b47, 0x3c24303c, 
+	0xa5e784a5, 0x416b5441, 0x06dddf06, 0xc56023c5, 
+	0x45fd1945, 0xa33a5ba3, 0x68c23d68, 0x158d5915, 
+	0x21ecf321, 0x3166ae31, 0x3e6fa23e, 0x16578216, 
+	0x95106395, 0x5bef015b, 0x4db8834d, 0x91862e91, 
+	0xb56dd9b5, 0x1f83511f, 0x53aa9b53, 0x635d7c63, 
+	0x3b68a63b, 0x3ffeeb3f, 0xd630a5d6, 0x257abe25, 
+	0xa7ac16a7, 0x0f090c0f, 0x35f0e335, 0x23a76123, 
+	0xf090c0f0, 0xafe98caf, 0x809d3a80, 0x925cf592, 
+	0x810c7381, 0x27312c27, 0x76d02576, 0xe7560be7, 
+	0x7b92bb7b, 0xe9ce4ee9, 0xf10189f1, 0x9f1e6b9f, 
+	0xa93453a9, 0xc4f16ac4, 0x99c3b499, 0x975bf197, 
+	0x8347e183, 0x6b18e66b, 0xc822bdc8, 0x0e98450e, 
+	0x6e1fe26e, 0xc9b3f4c9, 0x2f74b62f, 0xcbf866cb, 
+	0xff99ccff, 0xea1495ea, 0xed5803ed, 0xf7dc56f7, 
+	0xe18bd4e1, 0x1b151c1b, 0xada21ead, 0x0cd3d70c, 
+	0x2be2fb2b, 0x1dc8c31d, 0x195e8e19, 0xc22cb5c2, 
+	0x8949e989, 0x12c1cf12, 0x7e95bf7e, 0x207dba20, 
+	0x6411ea64, 0x840b7784, 0x6dc5396d, 0x6a89af6a, 
+	0xd17c33d1, 0xa171c9a1, 0xceff62ce, 0x37bb7137, 
+	0xfb0f81fb, 0x3db5793d, 0x51e10951, 0xdc3eaddc, 
+	0x2d3f242d, 0xa476cda4, 0x9d55f99d, 0xee82d8ee, 
+	0x8640e586, 0xae78c5ae, 0xcd25b9cd, 0x04964d04, 
+	0x55774455, 0x0a0e080a, 0x13508613, 0x30f7e730, 
+	0xd337a1d3, 0x40fa1d40, 0x3461aa34, 0x8c4eed8c, 
+	0xb3b006b3, 0x6c54706c, 0x2a73b22a, 0x523bd252, 
+	0x0b9f410b, 0x8b027b8b, 0x88d8a088, 0x4ff3114f, 
+	0x67cb3167, 0x4627c246, 0xc06727c0, 0xb4fc90b4, 
+	0x28382028, 0x7f04f67f, 0x78486078, 0x2ee5ff2e, 
+	0x074c9607, 0x4b655c4b, 0xc72bb1c7, 0x6f8eab6f, 
+	0x0d429e0d, 0xbbf59cbb, 0xf2db52f2, 0xf34a1bf3, 
+	0xa63d5fa6, 0x59a49359, 0xbcb90abc, 0x3af9ef3a, 
+	0xef1391ef, 0xfe0885fe, 0x01914901, 0x6116ee61, 
+	0x7cde2d7c, 0xb2214fb2, 0x42b18f42, 0xdb723bdb, 
+	0xb82f47b8, 0x48bf8748, 0x2cae6d2c, 0xe3c046e3, 
+	0x573cd657, 0x859a3e85, 0x29a96929, 0x7d4f647d, 
+	0x94812a94, 0x492ece49, 0x17c6cb17, 0xca692fca, 
+	0xc3bdfcc3, 0x5ca3975c, 0x5ee8055e, 0xd0ed7ad0, 
+	0x87d1ac87, 0x8e057f8e, 0xba64d5ba, 0xa8a51aa8, 
+	0xb7264bb7, 0xb9be0eb9, 0x6087a760, 0xf8d55af8, 
+	0x22362822, 0x111b1411, 0xde753fde, 0x79d92979, 
+	0xaaee88aa, 0x332d3c33, 0x5f794c5f, 0xb6b702b6, 
+	0x96cab896, 0x5835da58, 0x9cc4b09c, 0xfc4317fc, 
+	0x1a84551a, 0xf64d1ff6, 0x1c598a1c, 0x38b27d38, 
+	0xac3357ac, 0x18cfc718, 0xf4068df4, 0x69537469, 
+	0x749bb774, 0xf597c4f5, 0x56ad9f56, 0xdae372da, 
+	0xd5ea7ed5, 0x4af4154a, 0x9e8f229e, 0xa2ab12a2, 
+	0x4e62584e, 0xe85f07e8, 0xe51d99e5, 0x39233439, 
+	0xc1f66ec1, 0x446c5044, 0x5d32de5d, 0x72466872, 
+	0x26a06526, 0x93cdbc93, 0x03dadb03, 0xc6baf8c6, 
+	0xfa9ec8fa, 0x82d6a882, 0xcf6e2bcf, 0x50704050, 
+	0xeb85dceb, 0x750afe75, 0x8a93328a, 0x8ddfa48d, 
+	0x4c29ca4c, 0x141c1014, 0x73d72173, 0xccb4f0cc, 
+	0x09d4d309, 0x108a5d10, 0xe2510fe2, 0x00000000, 
+	0x9a196f9a, 0xe01a9de0, 0x8f94368f, 0xe6c742e6, 
+	0xecc94aec, 0xfdd25efd, 0xab7fc1ab, 0xd8a8e0d8
+    }
+};
+
+
+} // namespace
+
diff --git a/extra/yassl/taocrypt/src/twofish.cpp b/extra/yassl/taocrypt/src/twofish.cpp
new file mode 100644
index 00000000000..8b896ad5dc4
--- /dev/null
+++ b/extra/yassl/taocrypt/src/twofish.cpp
@@ -0,0 +1,591 @@
+/* twofish.cpp                                
+ *
+ * Copyright (C) 2003 Sawtooth Consulting Ltd.
+ *
+ * This file is part of yaSSL.
+ *
+ * yaSSL 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; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * yaSSL 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ */
+
+/* C++ based on Wei Dai's twofish.cpp from CryptoPP */
+/* x86 asm original */
+
+
+#if defined(TAOCRYPT_KERNEL_MODE)
+    #define DO_TAOCRYPT_KERNEL_MODE
+#endif                                  // only some modules now support this
+
+#include "runtime.hpp"
+#include "twofish.hpp"
+
+
+#if defined(TAOCRYPT_X86ASM_AVAILABLE) && defined(TAO_ASM)
+    #define DO_TWOFISH_ASM
+#endif
+
+
+namespace TaoCrypt {
+
+
+#if !defined(DO_TWOFISH_ASM)
+
+// Generic Version
+void Twofish::Process(byte* out, const byte* in, word32 sz)
+{
+    if (mode_ == ECB)
+        ECB_Process(out, in, sz);
+    else if (mode_ == CBC)
+        if (dir_ == ENCRYPTION)
+            CBC_Encrypt(out, in, sz);
+        else
+            CBC_Decrypt(out, in, sz);
+}
+
+#else
+
+// ia32 optimized version
+void Twofish::Process(byte* out, const byte* in, word32 sz)
+{
+    word32 blocks = sz / BLOCK_SIZE;
+
+    if (mode_ == ECB)
+        while (blocks--) {
+            if (dir_ == ENCRYPTION)
+                AsmEncrypt(in, out);
+            else
+                AsmDecrypt(in, out);
+        
+            out += BLOCK_SIZE;
+            in  += BLOCK_SIZE;
+        }
+    else if (mode_ == CBC)
+        if (dir_ == ENCRYPTION)
+            while (blocks--) {
+                r_[0] ^= *(word32*)in;
+                r_[1] ^= *(word32*)(in +  4);
+                r_[2] ^= *(word32*)(in +  8);
+                r_[3] ^= *(word32*)(in + 12);
+
+                AsmEncrypt((byte*)r_, (byte*)r_);
+                memcpy(out, r_, BLOCK_SIZE);
+
+                out += BLOCK_SIZE;
+                in  += BLOCK_SIZE;
+            }
+        else
+            while (blocks--) {
+                AsmDecrypt(in, out);
+               
+                *(word32*)out        ^= r_[0];
+                *(word32*)(out +  4) ^= r_[1];
+                *(word32*)(out +  8) ^= r_[2];
+                *(word32*)(out + 12) ^= r_[3];
+
+                memcpy(r_, in, BLOCK_SIZE);
+
+                out += BLOCK_SIZE;
+                in  += BLOCK_SIZE;
+            }
+}
+
+#endif // DO_TWOFISH_ASM
+
+
+namespace {     // locals
+
+// compute (c * x^4) mod (x^4 + (a + 1/a) * x^3 + a * x^2 + (a + 1/a) * x + 1)
+// over GF(256)
+static inline unsigned int Mod(unsigned int c)
+{
+	static const unsigned int modulus = 0x14d;
+	unsigned int c2 = (c<<1) ^ ((c & 0x80) ? modulus : 0);
+	unsigned int c1 = c2 ^ (c>>1) ^ ((c & 1) ? (modulus>>1) : 0);
+	return c | (c1 << 8) | (c2 << 16) | (c1 << 24);
+}
+
+// compute RS(12,8) code with the above polynomial as generator
+// this is equivalent to multiplying by the RS matrix
+static word32 ReedSolomon(word32 high, word32 low)
+{
+	for (unsigned int i=0; i<8; i++) {
+		high = Mod(high>>24) ^ (high<<8) ^ (low>>24);
+		low <<= 8;
+	}
+	return high;
+}
+
+}  // local namespace
+
+
+
+inline word32 Twofish::h0(word32 x, const word32* key, unsigned int kLen)
+{
+	x = x | (x<<8) | (x<<16) | (x<<24);
+	switch(kLen)
+	{
+#define Q(a, b, c, d, t) q_[a][GETBYTE(t,0)] ^ (q_[b][GETBYTE(t,1)] << 8) ^  \
+            (q_[c][GETBYTE(t,2)] << 16) ^ (q_[d][GETBYTE(t,3)] << 24)
+	case 4: x = Q(1, 0, 0, 1, x) ^ key[6];
+	case 3: x = Q(1, 1, 0, 0, x) ^ key[4];
+	case 2: x = Q(0, 1, 0, 1, x) ^ key[2];
+			x = Q(0, 0, 1, 1, x) ^ key[0];
+	}
+	return x;
+}
+
+inline word32 Twofish::h(word32 x, const word32* key, unsigned int kLen)
+{
+	x = h0(x, key, kLen);
+	return mds_[0][GETBYTE(x,0)] ^ mds_[1][GETBYTE(x,1)] ^ 
+        mds_[2][GETBYTE(x,2)] ^ mds_[3][GETBYTE(x,3)];
+}
+
+
+void Twofish::SetKey(const byte* userKey, word32 keylen, CipherDir /*dummy*/)
+{
+	assert(keylen >= 16 && keylen <= 32);
+
+	unsigned int len = (keylen <= 16 ? 2 : (keylen <= 24 ? 3 : 4));
+    word32 key[8];
+	GetUserKey(LittleEndianOrder, key, len*2, userKey, keylen);
+
+	unsigned int i;
+	for (i=0; i<40; i+=2) {
+		word32 a = h(i, key, len);
+		word32 b = rotlFixed(h(i+1, key+1, len), 8);
+		k_[i] = a+b;
+		k_[i+1] = rotlFixed(a+2*b, 9);
+	}
+
+	word32 svec[8];
+	for (i=0; i gpBlock;
+
+void Twofish::encrypt(const byte* inBlock, const byte* xorBlock,
+                  byte* outBlock) const
+{
+	word32 x, y, a, b, c, d;
+
+	gpBlock::Get(inBlock)(a)(b)(c)(d);
+
+	a ^= k_[0];
+	b ^= k_[1];
+	c ^= k_[2];
+	d ^= k_[3];
+
+	const word32 *k = k_+8;
+
+	ENCCYCLE (0);
+	ENCCYCLE (1);
+	ENCCYCLE (2);
+	ENCCYCLE (3);
+	ENCCYCLE (4);
+	ENCCYCLE (5);
+	ENCCYCLE (6);
+	ENCCYCLE (7);
+
+	c ^= k_[4];
+	d ^= k_[5];
+	a ^= k_[6];
+	b ^= k_[7]; 
+
+	gpBlock::Put(xorBlock, outBlock)(c)(d)(a)(b);
+}
+
+
+void Twofish::decrypt(const byte* inBlock, const byte* xorBlock,
+                  byte* outBlock) const
+{
+	word32 x, y, a, b, c, d;
+
+	gpBlock::Get(inBlock)(c)(d)(a)(b);
+
+	c ^= k_[4];
+	d ^= k_[5];
+	a ^= k_[6];
+	b ^= k_[7];
+
+	const word32 *k = k_+8;
+	DECCYCLE (7);
+	DECCYCLE (6);
+	DECCYCLE (5);
+	DECCYCLE (4);
+	DECCYCLE (3);
+	DECCYCLE (2);
+	DECCYCLE (1);
+	DECCYCLE (0);
+
+	a ^= k_[0];
+	b ^= k_[1];
+	c ^= k_[2];
+	d ^= k_[3];
+
+	gpBlock::Put(xorBlock, outBlock)(a)(b)(c)(d);
+}
+
+
+
+#if defined(DO_TWOFISH_ASM)
+    #ifdef __GNUC__
+        #define AS1(x)    asm(#x);
+        #define AS2(x, y) asm(#x ", " #y);
+
+        #define PROLOG()  \
+            asm(".intel_syntax noprefix"); \
+            AS2(    movd  mm3, edi                      )   \
+            AS2(    movd  mm4, ebx                      )   \
+            AS2(    movd  mm5, esi                      )   \
+            AS2(    movd  mm6, ebp                      )   \
+            AS2(    mov   edi, DWORD PTR [ebp +  8]     )   \
+            AS2(    mov   esi, DWORD PTR [ebp + 12]     )
+
+        #define EPILOG()  \
+            AS2(    movd esp, mm6                  )   \
+            AS2(    movd esi, mm5                  )   \
+            AS2(    movd ebx, mm4                  )   \
+            AS2(    movd edi, mm3                  )   \
+            AS1(    emms                           )   \
+            asm(".att_syntax");
+    #else
+        #define AS1(x)    __asm x
+        #define AS2(x, y) __asm x, y
+
+        #define PROLOG() \
+            AS1(    push  ebp                           )   \
+            AS2(    mov   ebp, esp                      )   \
+            AS2(    movd  mm3, edi                      )   \
+            AS2(    movd  mm4, ebx                      )   \
+            AS2(    movd  mm5, esi                      )   \
+            AS2(    movd  mm6, ebp                      )   \
+            AS2(    mov   edi, ecx                      )   \
+            AS2(    mov   esi, DWORD PTR [ebp +  8]     )
+
+        /* ebp already set */
+        #define EPILOG()  \
+            AS2(    movd esi, mm5                   )   \
+            AS2(    movd ebx, mm4                   )   \
+            AS2(    movd edi, mm3                   )   \
+            AS2(    mov  esp, ebp                   )   \
+            AS1(    pop  ebp                        )   \
+            AS1(    emms                            )   \
+            AS1(    ret 8                           )    
+            
+    #endif
+
+
+
+
+    // x = esi, y = [esp], s_ = ebp
+    // edi always open for G1 and G2
+    // G1 also uses edx after save and restore
+    // G2 also uses eax after save and restore
+    //      and ecx for tmp [esp] which Rounds also use
+    //      and restore from mm7
+
+    // x = G1(a)   bytes(0,1,2,3)
+#define ASMG1(z, zl, zh) \
+    AS2(    movd  mm2, edx                          )   \
+    AS2(    movzx edi, zl                           )   \
+    AS2(    mov   esi, DWORD PTR     [ebp + edi*4]  )   \
+    AS2(    movzx edx, zh                           )   \
+    AS2(    xor   esi, DWORD PTR 1024[ebp + edx*4]  )   \
+                                                        \
+    AS2(    mov   edx, z                            )   \
+    AS2(    shr   edx, 16                           )   \
+    AS2(    movzx edi, dl                           )   \
+    AS2(    xor   esi, DWORD PTR 2048[ebp + edi*4]  )   \
+    AS2(    movzx edx, dh                           )   \
+    AS2(    xor   esi, DWORD PTR 3072[ebp + edx*4]  )   \
+    AS2(    movd  edx, mm2                          )
+
+
+    // y = G2(b)  bytes(3,0,1,2)  [ put y into ecx for Rounds ]
+#define ASMG2(z, zl, zh)    \
+    AS2(    movd  mm7, ecx                          )   \
+    AS2(    movd  mm2, eax                          )   \
+    AS2(    mov   edi, z                            )   \
+    AS2(    shr   edi, 24                           )   \
+    AS2(    mov   ecx, DWORD PTR     [ebp + edi*4]  )   \
+    AS2(    movzx eax, zl                           )   \
+    AS2(    xor   ecx, DWORD PTR 1024[ebp + eax*4]  )   \
+                                                        \
+    AS2(    mov   eax, z                            )   \
+    AS2(    shr   eax, 16                           )   \
+    AS2(    movzx edi, zh                           )   \
+    AS2(    xor   ecx, DWORD PTR 2048[ebp + edi*4]  )   \
+    AS2(    movzx eax, al                           )   \
+    AS2(    xor   ecx, DWORD PTR 3072[ebp + eax*4]  )   \
+    AS2(    movd  eax, mm2                          )
+
+
+    // encrypt Round (n), 
+    // x = esi, k = ebp, edi open
+    // y is in ecx from G2, restore when done from mm7
+    //      before C (which be same register!)
+#define ASMENCROUND(N, A, A2, A3, B, B2, B3, C, D)      \
+    /* setup s_  */                                     \
+    AS2(    movd  ebp, mm1                          )   \
+    ASMG1(A, A2, A3)                                    \
+    ASMG2(B, B2, B3)                                    \
+    /* setup k  */                                      \
+    AS2(    movd  ebp, mm0                          )   \
+    /* x += y   */                                      \
+    AS2(    add   esi, ecx                          )   \
+    AS2(    add   ebp, 32                           )   \
+    /* y += x + k[2 * (n) + 1] */                       \
+    AS2(    add   ecx, esi                          )   \
+    AS2(    rol   D,   1                            )   \
+    AS2(    add   ecx, DWORD PTR [ebp + 8 * N + 4]  )   \
+	/* (d) = rotlFixed(d, 1) ^ y  */                    \
+    AS2(    xor   D,   ecx                          )   \
+    AS2(    movd  ecx, mm7                          )   \
+	/* (c) ^= x + k[2 * (n)] */                         \
+    AS2(    mov   edi, esi                          )   \
+    AS2(    add   edi, DWORD PTR [ebp + 8 * N]      )   \
+    AS2(    xor   C,   edi                          )   \
+	/* (c) = rotrFixed(c, 1) */                         \
+    AS2(    ror   C,   1                            )
+
+
+    // decrypt Round (n), 
+    // x = esi, k = ebp, edi open
+    // y is in ecx from G2, restore ecx from mm7 when done
+#define ASMDECROUND(N, A, A2, A3, B, B2, B3, C, D)      \
+    /* setup s_  */                                     \
+    AS2(    movd  ebp, mm1                          )   \
+    ASMG1(A, A2, A3)                                    \
+    ASMG2(B, B2, B3)                                    \
+    /* setup k  */                                      \
+    AS2(    movd  ebp, mm0                          )   \
+    /* x += y   */                                      \
+    AS2(    add   esi, ecx                          )   \
+    AS2(    add   ebp, 32                           )   \
+    /* y += x     */                                    \
+    AS2(    add   ecx, esi                          )   \
+	/* (d) ^= y + k[2 * (n) + 1] */                     \
+    AS2(    mov   edi, DWORD PTR [ebp + 8 * N + 4]  )   \
+    AS2(    add   edi, ecx                          )   \
+    AS2(    movd  ecx, mm7                          )   \
+    AS2(    xor   D,   edi                          )   \
+	/* (d) = rotrFixed(d, 1)     */                     \
+    AS2(    ror   D,   1                            )   \
+	/* (c) = rotlFixed(c, 1)     */                     \
+    AS2(    rol   C,   1                            )   \
+	/* (c) ^= (x + k[2 * (n)])   */                     \
+    AS2(    mov   edi, esi                          )   \
+    AS2(    add   edi, DWORD PTR [ebp + 8 * N]      )   \
+    AS2(    xor   C,   edi                          )
+
+
+#ifdef _MSC_VER
+    __declspec(naked) 
+#endif
+void Twofish::AsmEncrypt(const byte* inBlock, byte* outBlock) const
+{
+    PROLOG()
+
+    #ifdef OLD_GCC_OFFSET
+        AS2(    add   edi, 60                       ) // k_
+    #else
+        AS2(    add   edi, 56                       ) // k_
+    #endif
+
+    AS2(    mov   ebp, edi                      )
+
+    AS2(    mov   eax, DWORD PTR [esi]          ) // a
+    AS2(    movd  mm0, edi                      ) // store k_
+    AS2(    mov   ebx, DWORD PTR [esi +  4]     ) // b
+    AS2(    add   ebp, 160                      ) // s_[0]
+    AS2(    mov   ecx, DWORD PTR [esi +  8]     ) // c
+    AS2(    movd  mm1, ebp                      ) // store s_
+    AS2(    mov   edx, DWORD PTR [esi + 12]     ) // d
+    
+    AS2(    xor   eax, DWORD PTR [edi]          ) // k_[0]
+    AS2(    xor   ebx, DWORD PTR [edi +  4]     ) //   [1]
+    AS2(    xor   ecx, DWORD PTR [edi +  8]     ) //   [2]
+    AS2(    xor   edx, DWORD PTR [edi + 12]     ) //   [3]
+
+
+    ASMENCROUND( 0, eax, al, ah, ebx, bl, bh, ecx, edx)
+    ASMENCROUND( 1, ecx, cl, ch, edx, dl, dh, eax, ebx)
+    ASMENCROUND( 2, eax, al, ah, ebx, bl, bh, ecx, edx)
+    ASMENCROUND( 3, ecx, cl, ch, edx, dl, dh, eax, ebx)
+    ASMENCROUND( 4, eax, al, ah, ebx, bl, bh, ecx, edx)
+    ASMENCROUND( 5, ecx, cl, ch, edx, dl, dh, eax, ebx)
+    ASMENCROUND( 6, eax, al, ah, ebx, bl, bh, ecx, edx)
+    ASMENCROUND( 7, ecx, cl, ch, edx, dl, dh, eax, ebx)
+    ASMENCROUND( 8, eax, al, ah, ebx, bl, bh, ecx, edx)
+    ASMENCROUND( 9, ecx, cl, ch, edx, dl, dh, eax, ebx)
+    ASMENCROUND(10, eax, al, ah, ebx, bl, bh, ecx, edx)
+    ASMENCROUND(11, ecx, cl, ch, edx, dl, dh, eax, ebx)
+    ASMENCROUND(12, eax, al, ah, ebx, bl, bh, ecx, edx)
+    ASMENCROUND(13, ecx, cl, ch, edx, dl, dh, eax, ebx)
+    ASMENCROUND(14, eax, al, ah, ebx, bl, bh, ecx, edx)
+    ASMENCROUND(15, ecx, cl, ch, edx, dl, dh, eax, ebx)
+
+
+    AS2(    movd  ebp, mm6                      )
+    AS2(    movd  esi, mm0                      ) // k_
+    #ifdef __GNUC__
+        AS2(    mov   edi, [ebp + 16]           ) // outBlock
+    #else
+        AS2(    mov   edi, [ebp + 12]           ) // outBlock
+    #endif
+
+    AS2(    xor   ecx, DWORD PTR [esi + 16]     ) // k_[4]
+    AS2(    xor   edx, DWORD PTR [esi + 20]     ) // k_[5]
+    AS2(    xor   eax, DWORD PTR [esi + 24]     ) // k_[6]
+    AS2(    xor   ebx, DWORD PTR [esi + 28]     ) // k_[7]
+
+    AS2(    mov   [edi],      ecx               ) // write out
+    AS2(    mov   [edi +  4], edx               ) // write out
+    AS2(    mov   [edi +  8], eax               ) // write out
+    AS2(    mov   [edi + 12], ebx               ) // write out
+
+
+    EPILOG()
+}
+
+
+#ifdef _MSC_VER
+    __declspec(naked) 
+#endif
+void Twofish::AsmDecrypt(const byte* inBlock, byte* outBlock) const
+{
+    PROLOG()
+
+    #ifdef OLD_GCC_OFFSET
+        AS2(    add   edi, 60                       ) // k_
+    #else
+        AS2(    add   edi, 56                       ) // k_
+    #endif
+
+    AS2(    mov   ebp, edi                      )
+
+    AS2(    mov   ecx, DWORD PTR [esi]          ) // c
+    AS2(    movd  mm0, edi                      ) // store k_
+    AS2(    mov   edx, DWORD PTR [esi +  4]     ) // d
+    AS2(    add   ebp, 160                      ) // s_[0]
+    AS2(    mov   eax, DWORD PTR [esi +  8]     ) // a
+    AS2(    movd  mm1, ebp                      ) // store s_
+    AS2(    mov   ebx, DWORD PTR [esi + 12]     ) // b
+
+    AS2(    xor   ecx, DWORD PTR [edi + 16]     ) // k_[4]
+    AS2(    xor   edx, DWORD PTR [edi + 20]     ) //   [5]
+    AS2(    xor   eax, DWORD PTR [edi + 24]     ) //   [6]
+    AS2(    xor   ebx, DWORD PTR [edi + 28]     ) //   [7]
+
+
+    ASMDECROUND(15, ecx, cl, ch, edx, dl, dh, eax, ebx)
+    ASMDECROUND(14, eax, al, ah, ebx, bl, bh, ecx, edx)
+    ASMDECROUND(13, ecx, cl, ch, edx, dl, dh, eax, ebx)
+    ASMDECROUND(12, eax, al, ah, ebx, bl, bh, ecx, edx)
+    ASMDECROUND(11, ecx, cl, ch, edx, dl, dh, eax, ebx)
+    ASMDECROUND(10, eax, al, ah, ebx, bl, bh, ecx, edx)
+    ASMDECROUND( 9, ecx, cl, ch, edx, dl, dh, eax, ebx)
+    ASMDECROUND( 8, eax, al, ah, ebx, bl, bh, ecx, edx)
+    ASMDECROUND( 7, ecx, cl, ch, edx, dl, dh, eax, ebx)
+    ASMDECROUND( 6, eax, al, ah, ebx, bl, bh, ecx, edx)
+    ASMDECROUND( 5, ecx, cl, ch, edx, dl, dh, eax, ebx)
+    ASMDECROUND( 4, eax, al, ah, ebx, bl, bh, ecx, edx)
+    ASMDECROUND( 3, ecx, cl, ch, edx, dl, dh, eax, ebx)
+    ASMDECROUND( 2, eax, al, ah, ebx, bl, bh, ecx, edx)
+    ASMDECROUND( 1, ecx, cl, ch, edx, dl, dh, eax, ebx)
+    ASMDECROUND( 0, eax, al, ah, ebx, bl, bh, ecx, edx)
+
+
+    AS2(    movd  ebp, mm6                      )
+    AS2(    movd  esi, mm0                      ) // k_
+    #ifdef __GNUC__
+        AS2(    mov   edi, [ebp + 16]           ) // outBlock
+    #else
+        AS2(    mov   edi, [ebp + 12]           ) // outBlock
+    #endif
+
+    AS2(    xor   eax, DWORD PTR [esi     ]     ) // k_[0]
+    AS2(    xor   ebx, DWORD PTR [esi +  4]     ) // k_[1]
+    AS2(    xor   ecx, DWORD PTR [esi +  8]     ) // k_[2]
+    AS2(    xor   edx, DWORD PTR [esi + 12]     ) // k_[3]
+
+    AS2(    mov   [edi],      eax               ) // write out
+    AS2(    mov   [edi +  4], ebx               ) // write out
+    AS2(    mov   [edi +  8], ecx               ) // write out
+    AS2(    mov   [edi + 12], edx               ) // write out
+
+
+    EPILOG()
+}
+
+
+
+#endif // defined(DO_TWOFISH_ASM)
+
+
+
+
+
+} // namespace
+
+
diff --git a/extra/yassl/taocrypt/taocrypt.dsp b/extra/yassl/taocrypt/taocrypt.dsp
index 115ad0cb272..13b9a07419b 100644
--- a/extra/yassl/taocrypt/taocrypt.dsp
+++ b/extra/yassl/taocrypt/taocrypt.dsp
@@ -41,7 +41,7 @@ RSC=rc.exe
 # PROP Intermediate_Dir "Release"
 # PROP Target_Dir ""
 # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
-# ADD CPP /nologo /MT /W3 /GX- /O2 /I "include" /I "..\mySTL" /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
+# ADD CPP /nologo /G6 /MT /W3 /O2 /I "include" /I "..\mySTL" /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
 # ADD BASE RSC /l 0x409 /d "NDEBUG"
 # ADD RSC /l 0x409 /d "NDEBUG"
 BSC32=bscmake.exe
@@ -64,7 +64,7 @@ LIB32=link.exe -lib
 # PROP Intermediate_Dir "Debug"
 # PROP Target_Dir ""
 # ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
-# ADD CPP /nologo /MTd /W3 /Gm /GX- /ZI /Od /I "include" /I "..\mySTL" /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /FR /YX /FD /GZ /c
+# ADD CPP /nologo /MTd /W3 /Gm /ZI /Od /I "include" /I "..\mySTL" /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /FR /YX /FD /GZ /c
 # ADD BASE RSC /l 0x409 /d "_DEBUG"
 # ADD RSC /l 0x409 /d "_DEBUG"
 BSC32=bscmake.exe
@@ -105,6 +105,14 @@ SOURCE=.\src\asn.cpp
 # End Source File
 # Begin Source File
 
+SOURCE=.\src\bftables.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\src\blowfish.cpp
+# End Source File
+# Begin Source File
+
 SOURCE=.\src\coding.cpp
 # End Source File
 # Begin Source File
@@ -159,6 +167,14 @@ SOURCE=.\src\rsa.cpp
 
 SOURCE=.\src\sha.cpp
 # End Source File
+# Begin Source File
+
+SOURCE=.\src\tftables.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\src\twofish.cpp
+# End Source File
 # End Group
 # Begin Group "Header Files"
 
@@ -185,6 +201,10 @@ SOURCE=.\include\block.hpp
 # End Source File
 # Begin Source File
 
+SOURCE=.\include\blowfish.hpp
+# End Source File
+# Begin Source File
+
 SOURCE=.\include\coding.hpp
 # End Source File
 # Begin Source File
@@ -241,6 +261,10 @@ SOURCE=.\include\modes.hpp
 # End Source File
 # Begin Source File
 
+SOURCE=.\include\pwdbased.hpp
+# End Source File
+# Begin Source File
+
 SOURCE=.\include\random.hpp
 # End Source File
 # Begin Source File
@@ -255,6 +279,18 @@ SOURCE=.\include\rsa.hpp
 
 SOURCE=.\include\sha.hpp
 # End Source File
+# Begin Source File
+
+SOURCE=.\include\twofish.hpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\include\type_traits.hpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\include\types.hpp
+# End Source File
 # End Group
 # End Target
 # End Project
diff --git a/extra/yassl/taocrypt/test.dsp b/extra/yassl/taocrypt/test.dsp
new file mode 100644
index 00000000000..a5e05ed0ac0
--- /dev/null
+++ b/extra/yassl/taocrypt/test.dsp
@@ -0,0 +1,102 @@
+# Microsoft Developer Studio Project File - Name="test" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Console Application" 0x0103
+
+CFG=test - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE 
+!MESSAGE NMAKE /f "test.mak".
+!MESSAGE 
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE 
+!MESSAGE NMAKE /f "test.mak" CFG="test - Win32 Debug"
+!MESSAGE 
+!MESSAGE Possible choices for configuration are:
+!MESSAGE 
+!MESSAGE "test - Win32 Release" (based on "Win32 (x86) Console Application")
+!MESSAGE "test - Win32 Debug" (based on "Win32 (x86) Console Application")
+!MESSAGE 
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF  "$(CFG)" == "test - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "test___Win32_Release"
+# PROP BASE Intermediate_Dir "test___Win32_Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "test\Release"
+# PROP Intermediate_Dir "test\Release"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /MT /W3 /O2 /I "include" /I "../mySTL" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /FR /YX /FD /c
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+
+!ELSEIF  "$(CFG)" == "test - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "test___Win32_Debug"
+# PROP BASE Intermediate_Dir "test___Win32_Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "test\Debug"
+# PROP Intermediate_Dir "test\Debug"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /MTd /W3 /Gm /ZI /Od /I "include" /I "../mySTL" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FR /YX /FD /GZ /c
+# ADD BASE RSC /l 0x409 /d "_DEBUG"
+# ADD RSC /l 0x409 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+
+!ENDIF 
+
+# Begin Target
+
+# Name "test - Win32 Release"
+# Name "test - Win32 Debug"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\test\test.cpp
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# End Group
+# Begin Group "Resource Files"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# End Target
+# End Project
diff --git a/extra/yassl/taocrypt/test.dsw b/extra/yassl/taocrypt/test.dsw
new file mode 100644
index 00000000000..b5c03bc6e03
--- /dev/null
+++ b/extra/yassl/taocrypt/test.dsw
@@ -0,0 +1,29 @@
+Microsoft Developer Studio Workspace File, Format Version 6.00
+# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
+
+###############################################################################
+
+Project: "test"=.\test.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+}}}
+
+###############################################################################
+
+Global:
+
+Package=<5>
+{{{
+}}}
+
+Package=<3>
+{{{
+}}}
+
+###############################################################################
+
diff --git a/extra/yassl/taocrypt/test/make.bat b/extra/yassl/taocrypt/test/make.bat
new file mode 100644
index 00000000000..e1a4cbce7cd
--- /dev/null
+++ b/extra/yassl/taocrypt/test/make.bat
@@ -0,0 +1,9 @@
+# quick and dirty build file for testing different MSDEVs
+setlocal 
+
+set myFLAGS= /I../include /I../../mySTL /c /W3 /G6 /O2
+
+cl %myFLAGS% test.cpp
+
+link.exe  /out:test.exe ../src/taocrypt.lib test.obj advapi32.lib
+
diff --git a/extra/yassl/taocrypt/test/memory.cpp b/extra/yassl/taocrypt/test/memory.cpp
new file mode 100644
index 00000000000..726c9c0ef54
--- /dev/null
+++ b/extra/yassl/taocrypt/test/memory.cpp
@@ -0,0 +1,312 @@
+// memory.cpp
+#include "../../include/lock.hpp"     // locking
+#include           // std::bad_alloc
+#include       // malloc
+#include       // memset
+#include       // ofstream
+#include       // stringstream
+#include       // assert
+#include       // setiosflags
+
+/*********************************************************************
+
+To use MemoryTracker merely add this file to your project
+No need to instantiate anything
+
+If your app is multi threaded define MULTI_THREADED
+
+*********************************************************************/
+
+
+// locals
+namespace {
+
+class MemoryTracker {
+    std::ofstream log_;
+public:
+    MemoryTracker();
+    ~MemoryTracker();
+private:
+    MemoryTracker(const MemoryTracker&);             // hide copy
+    MemoryTracker& operator=(const MemoryTracker&);  // and assign
+
+    void LogStats();
+};
+
+
+struct alloc_node {
+    alloc_node* left_;
+    alloc_node* right_;
+  
+    alloc_node() : left_(0), right_(0) {}
+};
+
+
+alloc_node* Root = 0;
+
+size_t Allocs    = 0;
+size_t DeAllocs  = 0;
+size_t Bytes     = 0;
+
+
+struct size_tracker {
+    size_t size_;
+    size_t count_;
+};
+
+size_tracker sizes[] = 
+{
+    {0,0},
+    {2,0},
+    {4,0},
+    {8,0},
+    {16,0},
+    {32,0},
+    {64,0},
+    {128,0},
+    {256,0},
+    {512,0},
+    {1024,0},
+    {2048,0},
+    {4096,0},
+    {8192,0},
+};
+
+const size_t size_elements(sizeof(sizes) / sizeof(size_tracker));
+
+bool Tracking(false);
+
+using   yaSSL::Mutex;
+typedef Mutex::Lock Lock;
+
+Mutex mutex;
+
+MemoryTracker theTracker;
+
+
+bool lookup(alloc_node*& find, void* key, alloc_node*& prev)
+{
+    bool found(false);
+
+    while (find) {
+        if (find == key) {
+            found = true;
+            break;
+        }
+        prev = find;
+        if (key < find)
+            find = find->left_;
+        else
+            find = find->right_;
+    }
+    return found;
+}
+
+
+// iterative insert
+void insert(alloc_node* entry)
+{
+    if (!Root) {
+        Root = entry;
+        return;
+    }
+       
+    alloc_node* tmp  = Root;
+    alloc_node* prev = 0;
+
+    if (lookup(tmp, entry, prev)) 
+        assert(0); // duplicate
+
+    if (entry < prev)
+        prev->left_  = entry;
+    else
+        prev->right_ = entry;
+}
+
+
+alloc_node* predecessorSwap(alloc_node* del)
+{
+    alloc_node* pred = del->left_;
+    alloc_node* predPrev = del;
+
+    while (pred->right_) {
+        predPrev = pred;
+        pred = pred->right_;
+    }
+    if (predPrev == del)
+        predPrev->left_  = pred->left_;
+    else
+        predPrev->right_ = pred->left_;
+
+    pred->left_  = del->left_;
+    pred->right_ = del->right_;
+
+    return pred;
+}
+
+
+// iterative remove
+void remove(void* ptr)
+{
+    alloc_node* del  = Root;
+    alloc_node* prev = 0;
+    alloc_node* replace = 0;
+
+    if ( lookup(del, ptr, prev) == false)
+        assert(0); // oops, not there
+
+    if (del->left_ && del->right_)          // two children
+        replace = predecessorSwap(del);
+    else if (!del->left_ && !del->right_)   // no children
+        replace = 0;
+    else                                    // one child
+        replace = (del->left_) ? del->left_ : del->right_;
+
+    if (del == Root)
+        Root = replace;
+    else if (prev->left_ == del)
+        prev->left_  = replace;
+    else
+        prev->right_ = replace;
+}
+
+
+typedef void (*fp)(alloc_node*, void*);
+
+void applyInOrder(alloc_node* root, fp f, void* arg)
+{
+    if (root == 0)
+        return;
+    
+    applyInOrder(root->left_,  f, arg);
+    f(root, arg);
+    applyInOrder(root->right_, f, arg);
+}
+
+
+void show(alloc_node* ptr, void* arg)
+{
+    std::ofstream* log = static_cast(arg);
+    *log << ptr << '\n';
+}
+
+
+MemoryTracker::MemoryTracker() : log_("memory.log")
+{
+#ifdef __GNUC__
+    // Force pool allocator to cleanup at exit
+    setenv("GLIBCPP_FORCE_NEW", "1", 0);
+#endif
+
+#ifdef _MSC_VER
+    // msvc6 needs to create Facility for ostream before main starts, otherwise
+    // if another ostream is created and destroyed in main scope, log stats
+    // will access a dead Facility reference (std::numput)
+    int msvcFac = 6;
+    log_ << "MSVC " << msvcFac << "workaround" << std::endl; 
+#endif
+
+
+    Tracking = true;
+}
+
+
+MemoryTracker::~MemoryTracker()
+{
+    // stop tracking before log (which will alloc on output)
+    Tracking = false;
+    LogStats();
+
+    //assert(Allocs == DeAllocs);
+    //assert(Root == 0);
+}
+
+
+void MemoryTracker::LogStats()
+{
+    log_ << "Number of Allocs:     " << Allocs    << '\n';
+    log_ << "Number of DeAllocs:   " << DeAllocs  << '\n';
+    log_ << "Number of bytes used: " << Bytes     << '\n';
+
+    log_ << "Alloc size table:\n";
+    log_ << " Bytes " << '\t' << "   Times\n";
+
+    for (size_t i = 0; i < size_elements; ++i) {
+        log_ << " " << sizes[i].size_  << "  " << '\t';
+        log_ << std::setiosflags(std::ios::right) << std::setw(8);
+        log_ << sizes[i].count_ << '\n';
+    }
+
+    if (Allocs != DeAllocs) {
+        log_<< "Showing new'd allocs with no deletes" << '\n';
+        applyInOrder(Root, show, &log_);
+    }
+    log_.flush();
+}
+
+
+// return power of 2 up to size_tracker elements
+size_t powerOf2(size_t sz)
+{
+    size_t shifts = 0;
+
+    if (sz)
+        sz -= 1;
+    else
+        return 0;
+	   
+    while (sz) {
+        sz >>= 1;
+        ++shifts;
+    }
+
+    return shifts < size_elements ? shifts : size_elements;
+}
+
+
+} // namespace local
+
+
+void* operator new(size_t sz)
+{
+    // put alloc node in front of requested memory
+    void* ptr = malloc(sz + sizeof(alloc_node));
+    if (ptr) {
+        if (Tracking) {
+            Lock l(mutex);
+            ++Allocs;
+            Bytes += sz;
+            ++sizes[powerOf2(sz)].count_;
+            insert(new (ptr) alloc_node);
+        }
+        return static_cast(ptr) + sizeof(alloc_node);
+    }
+    else
+        assert(0);
+}
+
+
+void operator delete(void* ptr)
+{
+    if (ptr) {
+        ptr = static_cast(ptr) - sizeof(alloc_node);  // correct offset
+        if (Tracking) {
+            Lock l(mutex);
+            ++DeAllocs;
+            remove(ptr);
+        }
+        free(ptr);
+    }
+}
+
+
+void* operator new[](size_t sz)
+{
+    return ::operator new(sz);
+}
+
+
+void operator delete[](void* ptr)
+{
+    ::operator delete(ptr);
+}
diff --git a/extra/yassl/taocrypt/test/test.cpp b/extra/yassl/taocrypt/test/test.cpp
new file mode 100644
index 00000000000..c1f07cd4795
--- /dev/null
+++ b/extra/yassl/taocrypt/test/test.cpp
@@ -0,0 +1,947 @@
+// test.cpp
+// test taocrypt functionality
+
+#include 
+#include 
+
+#include "runtime.hpp"
+#include "sha.hpp"
+#include "md5.hpp"
+#include "md2.hpp"
+#include "ripemd.hpp"
+#include "hmac.hpp"
+#include "arc4.hpp"
+#include "des.hpp"
+#include "rsa.hpp"
+#include "dsa.hpp"
+#include "aes.hpp"
+#include "twofish.hpp"
+#include "blowfish.hpp"
+#include "asn.hpp"
+#include "dh.hpp"
+#include "coding.hpp"
+#include "random.hpp"
+#include "pwdbased.hpp"
+
+
+
+using TaoCrypt::byte;
+using TaoCrypt::word32;
+using TaoCrypt::SHA;
+using TaoCrypt::MD5;
+using TaoCrypt::MD2;
+using TaoCrypt::RIPEMD160;
+using TaoCrypt::HMAC;
+using TaoCrypt::ARC4;
+using TaoCrypt::DES_EDE3_CBC_Encryption;
+using TaoCrypt::DES_EDE3_CBC_Decryption;
+using TaoCrypt::DES_CBC_Encryption;
+using TaoCrypt::DES_CBC_Decryption;
+using TaoCrypt::DES_ECB_Encryption;
+using TaoCrypt::DES_ECB_Decryption;
+using TaoCrypt::AES_CBC_Encryption;
+using TaoCrypt::AES_CBC_Decryption;
+using TaoCrypt::AES_ECB_Encryption;
+using TaoCrypt::AES_ECB_Decryption;
+using TaoCrypt::Twofish_CBC_Encryption;
+using TaoCrypt::Twofish_CBC_Decryption;
+using TaoCrypt::Twofish_ECB_Encryption;
+using TaoCrypt::Twofish_ECB_Decryption;
+using TaoCrypt::Blowfish_CBC_Encryption;
+using TaoCrypt::Blowfish_CBC_Decryption;
+using TaoCrypt::Blowfish_ECB_Encryption;
+using TaoCrypt::Blowfish_ECB_Decryption;
+using TaoCrypt::RSA_PrivateKey;
+using TaoCrypt::RSA_PublicKey;
+using TaoCrypt::DSA_PrivateKey;
+using TaoCrypt::DSA_PublicKey;
+using TaoCrypt::DSA_Signer;
+using TaoCrypt::DSA_Verifier;
+using TaoCrypt::RSAES_Encryptor;
+using TaoCrypt::RSAES_Decryptor;
+using TaoCrypt::Source;
+using TaoCrypt::FileSource;
+using TaoCrypt::FileSource;
+using TaoCrypt::HexDecoder;
+using TaoCrypt::HexEncoder;
+using TaoCrypt::Base64Decoder;
+using TaoCrypt::Base64Encoder;
+using TaoCrypt::CertDecoder;
+using TaoCrypt::DH;
+using TaoCrypt::EncodeDSA_Signature;
+using TaoCrypt::DecodeDSA_Signature;
+using TaoCrypt::PBKDF2_HMAC;
+
+
+
+struct testVector {
+    byte*  input_;
+    byte*  output_; 
+    size_t inLen_;
+    size_t outLen_;
+
+    testVector(const char* in, const char* out) : input_((byte*)in),
+               output_((byte*)out), inLen_(strlen(in)), outLen_(strlen(out)) {}
+};
+
+void file_test(int, char**);
+int  sha_test();
+int  md5_test();
+int  md2_test();
+int  ripemd_test();
+int  hmac_test();
+int  arc4_test();
+int  des_test();
+int  aes_test();
+int  twofish_test();
+int  blowfish_test();
+int  rsa_test();
+int  dsa_test();
+int  dh_test();
+int  pwdbased_test();
+
+TaoCrypt::RandomNumberGenerator rng;
+
+
+void err_sys(const char* msg, int es)
+{
+    printf("%s", msg);
+    exit(es);    
+}
+
+// func_args from test.hpp, so don't have to pull in other junk
+struct func_args {
+    int    argc;
+    char** argv;
+    int    return_code;
+};
+
+
+void taocrypt_test(void* args)
+{
+    ((func_args*)args)->return_code = -1; // error state
+    
+
+    int ret = 0;
+    if ( (ret = sha_test()) ) 
+        err_sys("SHA      test failed!\n", ret);
+    else
+        printf( "SHA      test passed!\n");
+
+    if ( (ret = md5_test()) ) 
+        err_sys("MD5      test failed!\n", ret);
+    else
+        printf( "MD5      test passed!\n");
+
+    if ( (ret = md2_test()) ) 
+        err_sys("MD2      test failed!\n", ret);
+    else
+        printf( "MD2      test passed!\n");
+
+    if ( (ret = ripemd_test()) )
+        err_sys("RIPEMD   test failed!\n", ret);
+    else
+        printf( "RIPEMD   test passed!\n");
+
+    if ( ( ret = hmac_test()) )
+        err_sys("HMAC     test failed!\n", ret);
+    else
+        printf( "HMAC     test passed!\n");
+
+    if ( (ret = arc4_test()) )
+        err_sys("ARC4     test failed!\n", ret);
+    else
+        printf( "ARC4     test passed!\n");
+
+    if ( (ret = des_test()) )
+        err_sys("DES      test failed!\n", ret);
+    else
+        printf( "DES      test passed!\n");
+
+    if ( (ret = aes_test()) )
+        err_sys("AES      test failed!\n", ret);
+    else
+        printf( "AES      test passed!\n");
+
+    if ( (ret = twofish_test()) )
+        err_sys("Twofish  test failed!\n", ret);
+    else
+        printf( "Twofish  test passed!\n");
+
+    if ( (ret = blowfish_test()) )
+        err_sys("Blowfish test failed!\n", ret);
+    else
+        printf( "Blowfish test passed!\n");
+
+    if ( (ret = rsa_test()) )
+        err_sys("RSA      test failed!\n", ret);
+    else
+        printf( "RSA      test passed!\n");
+
+    if ( (ret = dh_test()) )
+        err_sys("DH       test failed!\n", ret);
+    else
+        printf( "DH       test passed!\n");
+
+    if ( (ret = dsa_test()) )
+        err_sys("DSA      test failed!\n", ret);
+    else
+        printf( "DSA      test passed!\n");
+
+    if ( (ret = pwdbased_test()) )
+        err_sys("PBKDF2   test failed!\n", ret);
+    else
+        printf( "PBKDF2   test passed!\n");
+
+
+    ((func_args*)args)->return_code = ret;
+}
+
+
+// so overall tests can pull in test function 
+#ifndef NO_MAIN_DRIVER
+
+    int main(int argc, char** argv)
+    {
+        func_args args;
+
+        args.argc = argc;
+        args.argv = argv;
+
+        taocrypt_test(&args);
+        return args.return_code;
+    }
+
+#endif // NO_MAIN_DRIVER
+
+
+void file_test(char* file, byte* check)
+{
+    FILE* f;
+    int   i(0);
+    MD5   md5;
+    byte  buf[1024];
+    byte  md5sum[MD5::DIGEST_SIZE];
+    
+    if( !( f = fopen( file, "rb" ) )) {
+        printf("Can't open %s\n", file);
+        return;
+    }
+    while( ( i = fread(buf, 1, sizeof(buf), f )) > 0 )
+        md5.Update(buf, i);
+    
+    md5.Final(md5sum);
+    memcpy(check, md5sum, sizeof(md5sum));
+
+    for(int j = 0; j < MD5::DIGEST_SIZE; ++j ) 
+        printf( "%02x", md5sum[j] );
+   
+    printf("  %s\n", file);
+
+    fclose(f);
+}
+
+
+int sha_test()
+{
+    SHA  sha;
+    byte hash[SHA::DIGEST_SIZE];
+
+    testVector test_sha[] =
+    {
+        testVector("abc", 
+                 "\xA9\x99\x3E\x36\x47\x06\x81\x6A\xBA\x3E\x25\x71\x78\x50\xC2"
+                 "\x6C\x9C\xD0\xD8\x9D"),
+        testVector("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
+                 "\x84\x98\x3E\x44\x1C\x3B\xD2\x6E\xBA\xAE\x4A\xA1\xF9\x51\x29"
+                 "\xE5\xE5\x46\x70\xF1"),
+        testVector("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
+                 "aaaaaa", 
+                 "\x00\x98\xBA\x82\x4B\x5C\x16\x42\x7B\xD7\xA1\x12\x2A\x5A\x44"
+                 "\x2A\x25\xEC\x64\x4D"),
+        testVector("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
+                 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
+                 "aaaaaaaaaa",
+                 "\xAD\x5B\x3F\xDB\xCB\x52\x67\x78\xC2\x83\x9D\x2F\x15\x1E\xA7"
+                 "\x53\x99\x5E\x26\xA0")  
+    };
+
+    int times( sizeof(test_sha) / sizeof(testVector) );
+    for (int i = 0; i < times; ++i) {
+        sha.Update(test_sha[i].input_, test_sha[i].inLen_);
+        sha.Final(hash);
+
+        if (memcmp(hash, test_sha[i].output_, SHA::DIGEST_SIZE) != 0)
+            return -1 - i;
+    }
+
+    return 0;
+}
+
+
+int md5_test()
+{
+    MD5  md5;
+    byte hash[MD5::DIGEST_SIZE];
+
+    testVector test_md5[] =
+    {
+        testVector("abc", 
+                 "\x90\x01\x50\x98\x3c\xd2\x4f\xb0\xd6\x96\x3f\x7d\x28\xe1\x7f"
+                 "\x72"),
+        testVector("message digest", 
+                 "\xf9\x6b\x69\x7d\x7c\xb7\x93\x8d\x52\x5a\x2f\x31\xaa\xf1\x61"
+                 "\xd0"),
+        testVector("abcdefghijklmnopqrstuvwxyz",
+                 "\xc3\xfc\xd3\xd7\x61\x92\xe4\x00\x7d\xfb\x49\x6c\xca\x67\xe1"
+                 "\x3b"),
+        testVector("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz012345"
+                 "6789",
+                 "\xd1\x74\xab\x98\xd2\x77\xd9\xf5\xa5\x61\x1c\x2c\x9f\x41\x9d"
+                 "\x9f"),
+        testVector("1234567890123456789012345678901234567890123456789012345678"
+                 "9012345678901234567890",
+                 "\x57\xed\xf4\xa2\x2b\xe3\xc9\x55\xac\x49\xda\x2e\x21\x07\xb6"
+                 "\x7a")
+    };
+
+    int times( sizeof(test_md5) / sizeof(testVector) );
+    for (int i = 0; i < times; ++i) {
+        md5.Update(test_md5[i].input_, test_md5[i].inLen_);
+        md5.Final(hash);
+
+        if (memcmp(hash, test_md5[i].output_, MD5::DIGEST_SIZE) != 0)
+            return -5 - i;
+    }
+
+    return 0;
+}
+
+
+int md2_test()
+{
+    MD2  md5;
+    byte hash[MD2::DIGEST_SIZE];
+
+    testVector test_md2[] =
+    {
+        testVector("",
+                   "\x83\x50\xe5\xa3\xe2\x4c\x15\x3d\xf2\x27\x5c\x9f\x80\x69"
+                   "\x27\x73"),
+        testVector("a",
+                   "\x32\xec\x01\xec\x4a\x6d\xac\x72\xc0\xab\x96\xfb\x34\xc0"
+                   "\xb5\xd1"),
+        testVector("abc",
+                   "\xda\x85\x3b\x0d\x3f\x88\xd9\x9b\x30\x28\x3a\x69\xe6\xde"
+                   "\xd6\xbb"),
+        testVector("message digest",
+                   "\xab\x4f\x49\x6b\xfb\x2a\x53\x0b\x21\x9f\xf3\x30\x31\xfe"
+                   "\x06\xb0"),
+        testVector("abcdefghijklmnopqrstuvwxyz",
+                   "\x4e\x8d\xdf\xf3\x65\x02\x92\xab\x5a\x41\x08\xc3\xaa\x47"
+                   "\x94\x0b"),
+        testVector("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
+                   "0123456789",
+                   "\xda\x33\xde\xf2\xa4\x2d\xf1\x39\x75\x35\x28\x46\xc3\x03"
+                   "\x38\xcd"),
+        testVector("12345678901234567890123456789012345678901234567890123456"
+                   "789012345678901234567890",
+                   "\xd5\x97\x6f\x79\xd8\x3d\x3a\x0d\xc9\x80\x6c\x3c\x66\xf3"
+                   "\xef\xd8")
+    };
+
+    int times( sizeof(test_md2) / sizeof(testVector) );
+    for (int i = 0; i < times; ++i) {
+        md5.Update(test_md2[i].input_, test_md2[i].inLen_);
+        md5.Final(hash);
+
+        if (memcmp(hash, test_md2[i].output_, MD2::DIGEST_SIZE) != 0)
+            return -10 - i;
+    }
+
+    return 0;
+}
+
+
+int ripemd_test()
+{
+    RIPEMD160  ripe160;
+    byte hash[RIPEMD160::DIGEST_SIZE];
+
+    testVector test_ripemd[] =
+    {
+        testVector("",
+                   "\x9c\x11\x85\xa5\xc5\xe9\xfc\x54\x61\x28\x08\x97\x7e\xe8"
+                   "\xf5\x48\xb2\x25\x8d\x31"),
+        testVector("a",
+                   "\x0b\xdc\x9d\x2d\x25\x6b\x3e\xe9\xda\xae\x34\x7b\xe6\xf4"
+                   "\xdc\x83\x5a\x46\x7f\xfe"),
+        testVector("abc",
+                   "\x8e\xb2\x08\xf7\xe0\x5d\x98\x7a\x9b\x04\x4a\x8e\x98\xc6"
+                   "\xb0\x87\xf1\x5a\x0b\xfc"),
+        testVector("message digest",
+                   "\x5d\x06\x89\xef\x49\xd2\xfa\xe5\x72\xb8\x81\xb1\x23\xa8"
+                   "\x5f\xfa\x21\x59\x5f\x36"),
+        testVector("abcdefghijklmnopqrstuvwxyz",
+                   "\xf7\x1c\x27\x10\x9c\x69\x2c\x1b\x56\xbb\xdc\xeb\x5b\x9d"
+                   "\x28\x65\xb3\x70\x8d\xbc"),
+        testVector("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
+                   "\x12\xa0\x53\x38\x4a\x9c\x0c\x88\xe4\x05\xa0\x6c\x27\xdc"
+                   "\xf4\x9a\xda\x62\xeb\x2b"),
+        testVector("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123"
+                   "456789",
+                   "\xb0\xe2\x0b\x6e\x31\x16\x64\x02\x86\xed\x3a\x87\xa5\x71"
+                   "\x30\x79\xb2\x1f\x51\x89"),
+        testVector("12345678901234567890123456789012345678901234567890123456"
+                   "789012345678901234567890",
+                   "\x9b\x75\x2e\x45\x57\x3d\x4b\x39\xf4\xdb\xd3\x32\x3c\xab"
+                   "\x82\xbf\x63\x32\x6b\xfb"),
+    };
+
+    int times( sizeof(test_ripemd) / sizeof(testVector) );
+    for (int i = 0; i < times; ++i) {
+        ripe160.Update(test_ripemd[i].input_, test_ripemd[i].inLen_);
+        ripe160.Final(hash);
+
+        if (memcmp(hash, test_ripemd[i].output_, RIPEMD160::DIGEST_SIZE) != 0)
+            return -100 - i;
+    }
+
+    return 0;
+}
+
+
+int hmac_test()
+{
+    HMAC hmacMD5;
+    byte hash[MD5::DIGEST_SIZE];
+
+    const char* keys[]=
+    {
+        "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b",
+        "Jefe",
+        "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
+    };
+
+    testVector test_hmacMD5[] = 
+    {
+        testVector("Hi There",
+                 "\x92\x94\x72\x7a\x36\x38\xbb\x1c\x13\xf4\x8e\xf8\x15\x8b\xfc"
+                 "\x9d"),
+        testVector("what do ya want for nothing?",
+                 "\x75\x0c\x78\x3e\x6a\xb0\xb5\x03\xea\xa8\x6e\x31\x0a\x5d\xb7"
+                 "\x38"),
+        testVector("\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
+                 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
+                 "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
+                 "\xDD\xDD\xDD\xDD\xDD\xDD",
+                 "\x56\xbe\x34\x52\x1d\x14\x4c\x88\xdb\xb8\xc7\x33\xf0\xe8\xb3"
+                 "\xf6")
+    };
+
+    int times( sizeof(test_hmacMD5) / sizeof(testVector) );
+    for (int i = 0; i < times; ++i) {
+        hmacMD5.SetKey((byte*)keys[i], strlen(keys[i]));
+        hmacMD5.Update(test_hmacMD5[i].input_, test_hmacMD5[i].inLen_);
+        hmacMD5.Final(hash);
+
+        if (memcmp(hash, test_hmacMD5[i].output_, MD5::DIGEST_SIZE) != 0)
+            return -20 - i;
+    }
+
+    return 0;
+}
+
+
+int arc4_test()
+{
+    byte cipher[16];
+    byte plain[16];
+
+    const char* keys[] = 
+    {           
+        "\x01\x23\x45\x67\x89\xab\xcd\xef",
+        "\x01\x23\x45\x67\x89\xab\xcd\xef",
+        "\x00\x00\x00\x00\x00\x00\x00\x00",
+        "\xef\x01\x23\x45"
+    };
+
+    testVector test_arc4[] =
+    {
+        testVector("\x01\x23\x45\x67\x89\xab\xcd\xef",
+                   "\x75\xb7\x87\x80\x99\xe0\xc5\x96"),
+        testVector("\x00\x00\x00\x00\x00\x00\x00\x00",
+                   "\x74\x94\xc2\xe7\x10\x4b\x08\x79"),
+        testVector("\x00\x00\x00\x00\x00\x00\x00\x00",
+                   "\xde\x18\x89\x41\xa3\x37\x5d\x3a"),
+        testVector("\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
+                   "\xd6\xa1\x41\xa7\xec\x3c\x38\xdf\xbd\x61")
+    };
+
+
+    int times( sizeof(test_arc4) / sizeof(testVector) );
+    for (int i = 0; i < times; ++i) {
+        ARC4::Encryption enc;
+        ARC4::Decryption dec;
+
+        enc.SetKey((byte*)keys[i], strlen(keys[i]));
+        dec.SetKey((byte*)keys[i], strlen(keys[i]));
+
+        enc.Process(cipher, test_arc4[i].input_, test_arc4[i].outLen_);
+        dec.Process(plain,  cipher, test_arc4[i].outLen_);
+
+        if (memcmp(plain, test_arc4[i].input_, test_arc4[i].outLen_))
+            return -30 - i;
+
+        if (memcmp(cipher, test_arc4[i].output_, test_arc4[i].outLen_))
+            return -40 - i;
+    }
+
+    return 0;
+}
+
+
+int des_test()
+{
+    //ECB mode
+    DES_ECB_Encryption enc;
+    DES_ECB_Decryption dec;
+
+ 
+    const byte key[] = { 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef };
+    const byte iv[] =  { 0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef };
+
+    const byte vector[] = { // "Now is the time for all " w/o trailing 0
+        0x4e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
+        0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
+        0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
+    };
+
+    byte plain[24];
+    byte cipher[24];
+
+    enc.SetKey(key, sizeof(key));
+    enc.Process(cipher, vector, sizeof(vector));
+    dec.SetKey(key, sizeof(key));
+    dec.Process(plain, cipher, sizeof(cipher));
+
+    if (memcmp(plain, vector, sizeof(plain)))
+        return -50;
+
+    const byte verify1[] = 
+    {
+        0x3f,0xa4,0x0e,0x8a,0x98,0x4d,0x48,0x15,
+        0x6a,0x27,0x17,0x87,0xab,0x88,0x83,0xf9,
+        0x89,0x3d,0x51,0xec,0x4b,0x56,0x3b,0x53
+    };
+
+    if (memcmp(cipher, verify1, sizeof(cipher)))
+        return -51;
+
+    // CBC mode
+    DES_CBC_Encryption enc2;
+    DES_CBC_Decryption dec2;
+
+    enc2.SetKey(key, sizeof(key), iv);
+    enc2.Process(cipher, vector, sizeof(vector));
+    dec2.SetKey(key, sizeof(key), iv);
+    dec2.Process(plain, cipher, sizeof(cipher));
+
+    if (memcmp(plain, vector, sizeof(plain)))
+        return -52;
+
+    const byte verify2[] = 
+    {
+        0xe5,0xc7,0xcd,0xde,0x87,0x2b,0xf2,0x7c,
+        0x43,0xe9,0x34,0x00,0x8c,0x38,0x9c,0x0f,
+        0x68,0x37,0x88,0x49,0x9a,0x7c,0x05,0xf6
+    };
+
+    if (memcmp(cipher, verify2, sizeof(cipher)))
+        return -53;
+
+    // EDE3 CBC mode
+    DES_EDE3_CBC_Encryption enc3;
+    DES_EDE3_CBC_Decryption dec3;
+
+    const byte key3[] = 
+    {
+        0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
+        0xfe,0xde,0xba,0x98,0x76,0x54,0x32,0x10,
+        0x89,0xab,0xcd,0xef,0x01,0x23,0x45,0x67
+    };
+    const byte iv3[] = 
+    {
+        0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef,
+        0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
+        0x11,0x21,0x31,0x41,0x51,0x61,0x71,0x81
+        
+    };
+
+    enc3.SetKey(key3, sizeof(key3), iv3);
+    enc3.Process(cipher, vector, sizeof(vector));
+    dec3.SetKey(key3, sizeof(key3), iv3);
+    dec3.Process(plain, cipher, sizeof(cipher));
+
+    if (memcmp(plain, vector, sizeof(plain)))
+        return -54;
+
+    const byte verify3[] = 
+    {
+        0x43,0xa0,0x29,0x7e,0xd1,0x84,0xf8,0x0e,
+        0x89,0x64,0x84,0x32,0x12,0xd5,0x08,0x98,
+        0x18,0x94,0x15,0x74,0x87,0x12,0x7d,0xb0
+    };
+
+    if (memcmp(cipher, verify3, sizeof(cipher)))
+        return -55;
+
+    return 0;
+}
+
+
+int aes_test()
+{
+    AES_CBC_Encryption enc;
+    AES_CBC_Decryption dec;
+    const int bs(TaoCrypt::AES::BLOCK_SIZE);
+
+    const byte msg[] = { // "Now is the time for all " w/o trailing 0
+        0x6e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
+        0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
+        0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
+    };
+
+    byte key[] = "0123456789abcdef   ";  // align
+    byte iv[]  = "1234567890abcdef   ";  // align
+
+    byte cipher[bs];
+    byte plain [bs];
+
+    enc.SetKey(key, bs, iv);
+    dec.SetKey(key, bs, iv);
+
+    enc.Process(cipher, msg, bs);
+    dec.Process(plain, cipher, bs);
+
+    if (memcmp(plain, msg, bs))
+        return -60;
+
+    const byte verify[] = 
+    {
+        0x95,0x94,0x92,0x57,0x5f,0x42,0x81,0x53,
+        0x2c,0xcc,0x9d,0x46,0x77,0xa2,0x33,0xcb
+    };
+
+    if (memcmp(cipher, verify, bs))
+        return -61;
+
+    AES_ECB_Encryption enc2;
+    AES_ECB_Decryption dec2;
+
+    enc2.SetKey(key, bs, iv);
+    dec2.SetKey(key, bs, iv);
+
+    enc2.Process(cipher, msg, bs);
+    dec2.Process(plain, cipher, bs);
+
+    if (memcmp(plain, msg, bs))
+        return -62;
+
+    const byte verify2[] = 
+    {
+        0xd0,0xc9,0xd9,0xc9,0x40,0xe8,0x97,0xb6,
+        0xc8,0x8c,0x33,0x3b,0xb5,0x8f,0x85,0xd1
+    };
+
+    if (memcmp(cipher, verify2, bs))
+        return -63;
+
+    return 0;
+}
+
+
+int twofish_test()
+{
+    Twofish_CBC_Encryption enc;
+    Twofish_CBC_Decryption dec;
+    const int bs(TaoCrypt::Twofish::BLOCK_SIZE);
+
+    const byte msg[] = { // "Now is the time for all " w/o trailing 0
+        0x6e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
+        0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
+        0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
+    };
+
+    byte key[] = "0123456789abcdef   ";  // align
+    byte iv[]  = "1234567890abcdef   ";  // align
+
+    byte cipher[bs];
+    byte plain [bs];
+
+    enc.SetKey(key, bs, iv);
+    dec.SetKey(key, bs, iv);
+
+    enc.Process(cipher, msg, bs);
+    dec.Process(plain, cipher, bs);
+
+    if (memcmp(plain, msg, bs))
+        return -60;
+
+    const byte verify[] = 
+    {
+        0xD2,0xD7,0x47,0x47,0x4A,0x65,0x4E,0x16,
+        0x21,0x03,0x58,0x79,0x5F,0x02,0x27,0x2C
+    };
+
+    if (memcmp(cipher, verify, bs))
+        return -61;
+
+    Twofish_ECB_Encryption enc2;
+    Twofish_ECB_Decryption dec2;
+
+    enc2.SetKey(key, bs, iv);
+    dec2.SetKey(key, bs, iv);
+
+    enc2.Process(cipher, msg, bs);
+    dec2.Process(plain, cipher, bs);
+
+    if (memcmp(plain, msg, bs))
+        return -62;
+
+    const byte verify2[] = 
+    {
+        0x3B,0x6C,0x63,0x10,0x34,0xAB,0xB2,0x87,
+        0xC4,0xCD,0x6B,0x91,0x14,0xC5,0x3A,0x09
+    };
+
+    if (memcmp(cipher, verify2, bs))
+        return -63;
+
+    return 0;
+}
+
+
+int blowfish_test()
+{
+    Blowfish_CBC_Encryption enc;
+    Blowfish_CBC_Decryption dec;
+    const int bs(TaoCrypt::Blowfish::BLOCK_SIZE);
+
+    const byte msg[] = { // "Now is the time for all " w/o trailing 0
+        0x6e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
+        0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
+        0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
+    };
+
+    byte key[] = "0123456789abcdef   ";  // align
+    byte iv[]  = "1234567890abcdef   ";  // align
+
+    byte cipher[bs * 2];
+    byte plain [bs * 2];
+
+    enc.SetKey(key, 16, iv);
+    dec.SetKey(key, 16, iv);
+
+    enc.Process(cipher, msg, bs * 2);
+    dec.Process(plain, cipher, bs * 2);
+
+    if (memcmp(plain, msg, bs))
+        return -60;
+
+    const byte verify[] = 
+    {
+        0x0E,0x26,0xAA,0x29,0x11,0x25,0xAB,0xB5,
+        0xBC,0xD9,0x08,0xC4,0x94,0x6C,0x89,0xA3
+    };
+
+    if (memcmp(cipher, verify, bs))
+        return -61;
+
+    Blowfish_ECB_Encryption enc2;
+    Blowfish_ECB_Decryption dec2;
+
+    enc2.SetKey(key, 16, iv);
+    dec2.SetKey(key, 16, iv);
+
+    enc2.Process(cipher, msg, bs * 2);
+    dec2.Process(plain, cipher, bs * 2);
+
+    if (memcmp(plain, msg, bs))
+        return -62;
+
+    const byte verify2[] = 
+    {
+        0xE7,0x42,0xB9,0x37,0xC8,0x7D,0x93,0xCA,
+        0x8F,0xCE,0x39,0x32,0xDE,0xD7,0xBC,0x5B
+    };
+
+    if (memcmp(cipher, verify2, bs))
+        return -63;
+
+    return 0;
+}
+
+
+int rsa_test()
+{
+    Source source;
+    FileSource("../certs/client-key.der", source);
+    if (source.size() == 0) {
+        FileSource("../../certs/client-key.der", source);  // for testsuite
+        if (source.size() == 0) {
+            FileSource("../../../certs/client-key.der", source); // Debug dir
+            if (source.size() == 0)
+                err_sys("where's your certs dir?", -79);
+        }
+    }
+    RSA_PrivateKey priv(source);
+
+    RSAES_Encryptor enc(priv);
+    byte message[] = "Everyone gets Friday off.";
+    const int len(strlen((char*)message));
+    byte cipher[64];
+    enc.Encrypt(message, len, cipher, rng);
+
+    RSAES_Decryptor dec(priv);
+    byte plain[64];
+    dec.Decrypt(cipher, sizeof(cipher), plain, rng);
+
+    if (memcmp(plain, message, len))
+        return -70;
+
+    dec.SSL_Sign(message, len, cipher, rng);
+    if (!enc.SSL_Verify(message, len, cipher))
+        return -71;
+
+
+    // test decode   
+    Source source2;
+    FileSource("../certs/client-cert.der", source2);
+    if (source2.size() == 0) {
+        FileSource("../../certs/client-cert.der", source2);  // for testsuite
+        if (source2.size() == 0) {
+            FileSource("../../../certs/client-cert.der", source2); // Debug dir
+            if (source2.size() == 0)
+                err_sys("where's your certs dir?", -79);
+        }
+    }
+    CertDecoder cd(source2, true, 0, false, CertDecoder::CA);
+    Source source3(cd.GetPublicKey().GetKey(), cd.GetPublicKey().size());
+    RSA_PublicKey pub(source3);
+ 
+    return 0;
+}
+
+
+int dh_test()
+{
+    Source source;
+    FileSource("../certs/dh1024.dat", source);
+    if (source.size() == 0) {
+        FileSource("../../certs/dh1024.dat", source);  // for testsuite
+        if (source.size() == 0) {
+            FileSource("../../../certs/dh1024.dat", source); // win32 Debug dir
+            if (source.size() == 0)
+                err_sys("where's your certs dir?", -79);
+        }
+    }
+    HexDecoder hDec(source);
+
+    DH dh(source);
+
+    byte pub[128];
+    byte priv[128];
+    byte agree[128];
+    byte pub2[128];
+    byte priv2[128];
+    byte agree2[128];
+
+    DH dh2(dh);
+
+    dh.GenerateKeyPair(rng, priv, pub);
+    dh2.GenerateKeyPair(rng, priv2, pub2);
+    dh.Agree(agree, priv, pub2); 
+    dh2.Agree(agree2, priv2, pub);
+
+    
+    if ( memcmp(agree, agree2, dh.GetByteLength()) )
+        return -80;
+
+    return 0;
+}
+
+
+int dsa_test()
+{
+    Source source;
+    FileSource("../certs/dsa512.der", source);
+    if (source.size() == 0) {
+        FileSource("../../certs/dsa512.der", source);  // for testsuite
+        if (source.size() == 0) {
+            FileSource("../../../certs/dsa512.der", source); // win32 Debug dir
+            if (source.size() == 0)
+                err_sys("where's your certs dir?", -89);
+        }
+    }
+
+    const char msg[] = "this is the message";
+    byte signature[40];
+
+    DSA_PrivateKey priv(source);
+    DSA_Signer signer(priv);
+
+    SHA sha;
+    byte digest[SHA::DIGEST_SIZE];
+    sha.Update((byte*)msg, sizeof(msg));
+    sha.Final(digest);
+
+    signer.Sign(digest, signature, rng);
+
+    byte encoded[sizeof(signature) + 6];
+    byte decoded[40];
+
+    word32 encSz = EncodeDSA_Signature(signer.GetR(), signer.GetS(), encoded);
+    DecodeDSA_Signature(decoded, encoded, encSz);
+
+    DSA_PublicKey pub(priv);
+    DSA_Verifier verifier(pub);
+
+    if (!verifier.Verify(digest, decoded))
+        return -90;
+
+    return 0;
+}
+
+
+int pwdbased_test()
+{
+    PBKDF2_HMAC pb;
+
+    byte derived[32];
+    const byte pwd1[] = "password   ";  // align
+    const byte salt[]  = { 0x12, 0x34, 0x56, 0x78, 0x78, 0x56, 0x34, 0x12 };
+    
+    pb.DeriveKey(derived, 8, pwd1, 8, salt, sizeof(salt), 5);
+
+    const byte verify1[] = { 0xD1, 0xDA, 0xA7, 0x86, 0x15, 0xF2, 0x87, 0xE6 };
+
+    if ( memcmp(derived, verify1, sizeof(verify1)) )
+        return -101;
+
+
+    const byte pwd2[] = "All n-entities must communicate with other n-entities"
+                        " via n-1 entiteeheehees   ";  // align
+
+    pb.DeriveKey(derived, 24, pwd2, 76, salt, sizeof(salt), 500);
+
+    const byte verify2[] = { 0x6A, 0x89, 0x70, 0xBF, 0x68, 0xC9, 0x2C, 0xAE,
+                             0xA8, 0x4A, 0x8D, 0xF2, 0x85, 0x10, 0x85, 0x86,
+                             0x07, 0x12, 0x63, 0x80, 0xCC, 0x47, 0xAB, 0x2D
+    };
+
+    if ( memcmp(derived, verify2, sizeof(verify2)) )
+        return -102;
+
+    return 0;
+}
diff --git a/extra/yassl/testsuite/input b/extra/yassl/testsuite/input
new file mode 100644
index 00000000000..d16cbc40750
--- /dev/null
+++ b/extra/yassl/testsuite/input
@@ -0,0 +1,107 @@
+// testsuite.cpp
+
+#include "test.hpp"
+#include "md5.hpp"
+
+typedef unsigned char byte;
+
+void taocrypt_test(void*);
+void file_test(char*, byte*);
+
+void client_test(void*);
+void echoclient_test(void*);
+
+THREAD_RETURN YASSL_API server_test(void*);
+THREAD_RETURN YASSL_API echoserver_test(void*);
+
+int main(int argc, char** argv)
+{
+    func_args args(argc, argv);
+    func_args server_args(args);
+
+    // *** Crypto Test ***
+    taocrypt_test(&args);
+    assert(args.return_code == 0);
+    
+    
+    // *** Simple yaSSL client server test ***
+    THREAD_TYPE thread;
+
+    start_thread(server_test, &server_args, &thread);
+    client_test(&args);
+
+    assert(args.return_code == 0);
+    join_thread(thread);
+    assert(server_args.return_code == 0);
+    
+
+    // *** Echo input yaSSL client server test ***
+    start_thread(echoserver_test, &server_args, &thread);
+    func_args echo_args;
+
+            // setup args
+    echo_args.argc = 3;
+    echo_args.argv = new char*[echo_args.argc];
+    for (int i = 0; i < echo_args.argc; i++)
+        echo_args.argv[i] = new char[32];
+   
+    strcpy(echo_args.argv[0], "echoclient");
+    strcpy(echo_args.argv[1], "input");
+    strcpy(echo_args.argv[2], "output");
+    remove("output");
+
+            // make sure OK
+    echoclient_test(&echo_args);
+    assert(echo_args.return_code == 0);
+
+
+    // *** Echo quit yaSSL client server test ***
+    echo_args.argc = 2;
+    strcpy(echo_args.argv[1], "quit");
+
+    echoclient_test(&echo_args);
+    assert(echo_args.return_code == 0);
+    join_thread(thread);
+    assert(server_args.return_code == 0);
+
+
+            // input output compare
+    byte input[TaoCrypt::MD5::DIGEST_SIZE];
+    byte output[TaoCrypt::MD5::DIGEST_SIZE];
+    file_test("input", input);
+    file_test("output", output);
+    assert(memcmp(input, output, sizeof(input)) == 0);
+
+    printf("\nAll tests passed!\n");
+
+    // cleanup
+    for (int j = echo_args.argc; j >= 0; j--)
+        delete[] echo_args.argv[j];
+    delete[] echo_args.argv;
+
+    return 0;
+}
+
+
+
+void start_thread(THREAD_FUNC fun, func_args* args, THREAD_TYPE* thread)
+{
+#ifdef _WIN32
+    *thread = _beginthreadex(0, 0, fun, args, 0, 0);
+#else
+    pthread_create(thread, 0, fun, args);
+#endif
+}
+
+
+void join_thread(THREAD_TYPE thread)
+{
+#ifdef _WIN32
+    int res = WaitForSingleObject(reinterpret_cast(thread), INFINITE);
+    assert(res == WAIT_OBJECT_0);
+    res = CloseHandle(reinterpret_cast(thread));
+    assert(res);
+#else
+    pthread_join(thread, 0);
+#endif
+}
diff --git a/extra/yassl/testsuite/make.bat b/extra/yassl/testsuite/make.bat
new file mode 100644
index 00000000000..d8a55b0d3af
--- /dev/null
+++ b/extra/yassl/testsuite/make.bat
@@ -0,0 +1,14 @@
+# quick and dirty build file for testing different MSDEVs
+setlocal 
+
+set myFLAGS= /I../include /I../taocrypt/include /I../mySTL /c /W3 /G6 /O2 /MT /D"WIN32" /D"NO_MAIN_DRIVER"
+
+cl %myFLAGS% testsuite.cpp
+cl %myFLAGS% ../examples/client/client.cpp
+cl %myFLAGS% ../examples/echoclient/echoclient.cpp
+cl %myFLAGS% ../examples/server/server.cpp
+cl %myFLAGS% ../examples/echoserver/echoserver.cpp
+cl %myFLAGS% ../taocrypt/test/test.cpp
+
+link.exe  /out:testsuite.exe ../src/yassl.lib ../taocrypt/src/taocrypt.lib testsuite.obj client.obj server.obj echoclient.obj echoserver.obj test.obj advapi32.lib Ws2_32.lib
+
diff --git a/extra/yassl/testsuite/quit b/extra/yassl/testsuite/quit
new file mode 100644
index 00000000000..3db49b3ad12
--- /dev/null
+++ b/extra/yassl/testsuite/quit
@@ -0,0 +1,2 @@
+quit
+
diff --git a/extra/yassl/testsuite/test.hpp b/extra/yassl/testsuite/test.hpp
new file mode 100644
index 00000000000..79d02b63558
--- /dev/null
+++ b/extra/yassl/testsuite/test.hpp
@@ -0,0 +1,352 @@
+// test.hpp
+
+#ifndef yaSSL_TEST_HPP
+#define yaSSL_TEST_HPP
+
+#include "runtime.hpp"
+#include "openssl/ssl.h"   /* openssl compatibility test */
+#include 
+#include 
+#include 
+
+#ifdef _WIN32
+    #include 
+    #include 
+    #define SOCKET_T unsigned int
+#else
+    #include 
+    #include 
+    #include 
+    #include 
+    #include 
+    #include 
+    #include 
+    #include 
+    #include 
+    #define SOCKET_T int
+#endif /* _WIN32 */
+
+
+#if defined(__MACH__) || defined(_WIN32)
+    typedef int socklen_t;
+#endif
+
+
+// HPUX doesn't use socklent_t for third parameter to accept
+#if !defined(__hpux__)
+    typedef socklen_t* ACCEPT_THIRD_T;
+#else
+    typedef int*       ACCEPT_THIRD_T;
+#endif
+
+
+#ifndef _POSIX_THREADS
+    typedef unsigned int  THREAD_RETURN;
+    typedef unsigned long THREAD_TYPE;
+    #define YASSL_API __stdcall
+#else
+    typedef void*         THREAD_RETURN;
+    typedef pthread_t     THREAD_TYPE;
+    #define YASSL_API 
+#endif
+
+
+struct tcp_ready {
+#ifdef _POSIX_THREADS
+    pthread_mutex_t mutex_;
+    pthread_cond_t  cond_;
+    bool            ready_;   // predicate
+
+    tcp_ready() : ready_(false)
+    {
+        pthread_mutex_init(&mutex_, 0);
+        pthread_cond_init(&cond_, 0);
+    }
+
+    ~tcp_ready()
+    {
+        pthread_mutex_destroy(&mutex_);
+        pthread_cond_destroy(&cond_);
+    }
+#endif
+};    
+
+
+struct func_args {
+    int    argc;
+    char** argv;
+    int    return_code;
+    tcp_ready* signal_;
+
+    func_args(int c = 0, char** v = 0) : argc(c), argv(v) {}
+
+    void SetSignal(tcp_ready* p) { signal_ = p; }
+};
+
+typedef THREAD_RETURN YASSL_API THREAD_FUNC(void*);
+
+void start_thread(THREAD_FUNC, func_args*, THREAD_TYPE*);
+void join_thread(THREAD_TYPE);
+
+// yaSSL
+const char* const    yasslIP   = "127.0.0.1";
+const unsigned short yasslPort = 11111;
+
+
+// client
+const char* const cert = "../certs/client-cert.pem";
+const char* const key  = "../certs/client-key.pem";
+
+const char* const certSuite = "../../certs/client-cert.pem";
+const char* const keySuite  = "../../certs/client-key.pem";
+
+const char* const certDebug = "../../../certs/client-cert.pem";
+const char* const keyDebug  = "../../../certs/client-key.pem";
+
+
+// server
+const char* const svrCert = "../certs/server-cert.pem";
+const char* const svrKey  = "../certs/server-key.pem";
+
+const char* const svrCert2 = "../../certs/server-cert.pem";
+const char* const svrKey2  = "../../certs/server-key.pem";
+
+const char* const svrCert3 = "../../../certs/server-cert.pem";
+const char* const svrKey3  = "../../../certs/server-key.pem";
+
+
+// server dsa
+const char* const dsaCert = "../certs/dsa-cert.pem";
+const char* const dsaKey  = "../certs/dsa512.der";
+
+const char* const dsaCert2 = "../../certs/dsa-cert.pem";
+const char* const dsaKey2  = "../../certs/dsa512.der";
+
+const char* const dsaCert3 = "../../../certs/dsa-cert.pem";
+const char* const dsaKey3  = "../../../certs/dsa512.der";
+
+
+// CA 
+const char* const caCert  = "../certs/ca-cert.pem";
+const char* const caCert2 = "../../certs/ca-cert.pem";
+const char* const caCert3 = "../../../certs/ca-cert.pem";
+
+
+using namespace yaSSL;
+
+
+inline void err_sys(const char* msg)
+{
+    printf("yassl error: %s\n", msg);
+    exit(EXIT_FAILURE);
+}
+
+
+inline void store_ca(SSL_CTX* ctx)
+{
+    // To allow testing from serveral dirs
+    if (SSL_CTX_load_verify_locations(ctx, caCert, 0) != SSL_SUCCESS)
+        if (SSL_CTX_load_verify_locations(ctx, caCert2, 0) != SSL_SUCCESS)
+            if (SSL_CTX_load_verify_locations(ctx, caCert3, 0) != SSL_SUCCESS)
+                err_sys("failed to use certificate: certs/cacert.pem");
+
+    // load client CA for server verify
+    if (SSL_CTX_load_verify_locations(ctx, cert, 0) != SSL_SUCCESS)
+        if (SSL_CTX_load_verify_locations(ctx, certSuite, 0) != SSL_SUCCESS)
+            if (SSL_CTX_load_verify_locations(ctx, certDebug,0) != SSL_SUCCESS)
+                err_sys("failed to use certificate: certs/client-cert.pem");
+}
+
+
+// client
+inline void set_certs(SSL_CTX* ctx)
+{
+    store_ca(ctx);
+
+    // To allow testing from serveral dirs
+    if (SSL_CTX_use_certificate_file(ctx, cert, SSL_FILETYPE_PEM)
+        != SSL_SUCCESS)
+        if (SSL_CTX_use_certificate_file(ctx, certSuite, SSL_FILETYPE_PEM)
+            != SSL_SUCCESS)
+            if (SSL_CTX_use_certificate_file(ctx, certDebug, SSL_FILETYPE_PEM)
+                != SSL_SUCCESS)
+                err_sys("failed to use certificate: certs/client-cert.pem");
+    
+    // To allow testing from several dirs
+    if (SSL_CTX_use_PrivateKey_file(ctx, key, SSL_FILETYPE_PEM)
+         != SSL_SUCCESS) 
+         if (SSL_CTX_use_PrivateKey_file(ctx, keySuite, SSL_FILETYPE_PEM)
+            != SSL_SUCCESS) 
+                if (SSL_CTX_use_PrivateKey_file(ctx,keyDebug,SSL_FILETYPE_PEM)
+                    != SSL_SUCCESS) 
+                    err_sys("failed to use key file: certs/client-key.pem");
+}
+
+
+// server
+inline void set_serverCerts(SSL_CTX* ctx)
+{
+    store_ca(ctx);
+
+    // To allow testing from serveral dirs
+    if (SSL_CTX_use_certificate_file(ctx, svrCert, SSL_FILETYPE_PEM)
+        != SSL_SUCCESS)
+        if (SSL_CTX_use_certificate_file(ctx, svrCert2, SSL_FILETYPE_PEM)
+            != SSL_SUCCESS)
+            if (SSL_CTX_use_certificate_file(ctx, svrCert3, SSL_FILETYPE_PEM)
+                != SSL_SUCCESS)
+                err_sys("failed to use certificate: certs/server-cert.pem");
+    
+    // To allow testing from several dirs
+    if (SSL_CTX_use_PrivateKey_file(ctx, svrKey, SSL_FILETYPE_PEM)
+         != SSL_SUCCESS) 
+         if (SSL_CTX_use_PrivateKey_file(ctx, svrKey2, SSL_FILETYPE_PEM)
+            != SSL_SUCCESS) 
+                if (SSL_CTX_use_PrivateKey_file(ctx, svrKey3,SSL_FILETYPE_PEM)
+                    != SSL_SUCCESS) 
+                    err_sys("failed to use key file: certs/server-key.pem");
+}
+
+
+// dsa server
+inline void set_dsaServerCerts(SSL_CTX* ctx)
+{
+    store_ca(ctx);
+
+    // To allow testing from serveral dirs
+    if (SSL_CTX_use_certificate_file(ctx, dsaCert, SSL_FILETYPE_PEM)
+        != SSL_SUCCESS)
+        if (SSL_CTX_use_certificate_file(ctx, dsaCert2, SSL_FILETYPE_PEM)
+            != SSL_SUCCESS)
+            if (SSL_CTX_use_certificate_file(ctx, dsaCert3, SSL_FILETYPE_PEM)
+                != SSL_SUCCESS)
+                err_sys("failed to use certificate: certs/dsa-cert.pem");
+    
+    // To allow testing from several dirs
+    if (SSL_CTX_use_PrivateKey_file(ctx, dsaKey, SSL_FILETYPE_ASN1)
+         != SSL_SUCCESS) 
+         if (SSL_CTX_use_PrivateKey_file(ctx, dsaKey2, SSL_FILETYPE_ASN1)
+            != SSL_SUCCESS) 
+                if (SSL_CTX_use_PrivateKey_file(ctx, dsaKey3,SSL_FILETYPE_ASN1)
+                    != SSL_SUCCESS) 
+                    err_sys("failed to use key file: certs/dsa512.der");
+}
+
+
+inline void set_args(int& argc, char**& argv, func_args& args)
+{
+    argc = args.argc;
+    argv = args.argv;
+    args.return_code = -1; // error state
+}
+
+
+inline void tcp_socket(SOCKET_T& sockfd, sockaddr_in& addr)
+{
+    sockfd = socket(AF_INET, SOCK_STREAM, 0);
+    memset(&addr, 0, sizeof(addr));
+    addr.sin_family = AF_INET;
+
+    addr.sin_port = htons(yasslPort);
+    addr.sin_addr.s_addr = inet_addr(yasslIP);
+}
+
+
+inline void tcp_connect(SOCKET_T& sockfd)
+{
+    sockaddr_in addr;
+    tcp_socket(sockfd, addr);
+
+    if (connect(sockfd, (const sockaddr*)&addr, sizeof(addr)) != 0)
+        err_sys("tcp connect failed");
+}
+
+
+inline void tcp_listen(SOCKET_T& sockfd)
+{
+    sockaddr_in addr;
+    tcp_socket(sockfd, addr);
+
+    if (bind(sockfd, (const sockaddr*)&addr, sizeof(addr)) != 0)
+        err_sys("tcp bind failed");
+    if (listen(sockfd, 3) != 0)
+        err_sys("tcp listen failed");
+}
+
+
+inline void tcp_accept(SOCKET_T& sockfd, int& clientfd, func_args& args)
+{
+    tcp_listen(sockfd);
+
+    sockaddr_in client;
+    socklen_t client_len = sizeof(client);
+
+#if defined(_POSIX_THREADS) && defined(NO_MAIN_DRIVER)
+    // signal ready to tcp_accept
+    tcp_ready& ready = *args.signal_;
+    pthread_mutex_lock(&ready.mutex_);
+    ready.ready_ = true;
+    pthread_cond_signal(&ready.cond_);
+    pthread_mutex_unlock(&ready.mutex_);
+#endif
+
+    clientfd = accept(sockfd, (sockaddr*)&client, (ACCEPT_THIRD_T)&client_len);
+
+    if (clientfd == -1)
+        err_sys("tcp accept failed");
+}
+
+
+inline void showPeer(SSL* ssl)
+{
+    X509* peer = SSL_get_peer_certificate(ssl);
+    if (peer) {
+        char* issuer  = X509_NAME_oneline(X509_get_issuer_name(peer), 0, 0);
+        char* subject = X509_NAME_oneline(X509_get_subject_name(peer), 0, 0);
+
+        printf("peer's cert info:\n");
+        printf("issuer  is: %s\n", issuer);
+        printf("subject is: %s\n", subject);
+
+        free(subject);
+        free(issuer);
+    }
+    else
+        printf("peer has no cert!\n");
+}
+
+
+
+inline DH* set_tmpDH(SSL_CTX* ctx)
+{
+    static unsigned char dh512_p[] =
+    {
+      0xDA,0x58,0x3C,0x16,0xD9,0x85,0x22,0x89,0xD0,0xE4,0xAF,0x75,
+      0x6F,0x4C,0xCA,0x92,0xDD,0x4B,0xE5,0x33,0xB8,0x04,0xFB,0x0F,
+      0xED,0x94,0xEF,0x9C,0x8A,0x44,0x03,0xED,0x57,0x46,0x50,0xD3,
+      0x69,0x99,0xDB,0x29,0xD7,0x76,0x27,0x6B,0xA2,0xD3,0xD4,0x12,
+      0xE2,0x18,0xF4,0xDD,0x1E,0x08,0x4C,0xF6,0xD8,0x00,0x3E,0x7C,
+      0x47,0x74,0xE8,0x33,
+    };
+
+    static unsigned char dh512_g[] =
+    {
+      0x02,
+    };
+
+    DH* dh;
+    if ( (dh = DH_new()) ) {
+        dh->p = BN_bin2bn(dh512_p, sizeof(dh512_p), 0);
+        dh->g = BN_bin2bn(dh512_g, sizeof(dh512_g), 0);
+    }
+    if (!dh->p || !dh->g) {
+        DH_free(dh);
+        dh = 0;
+    }
+    SSL_CTX_set_tmp_dh(ctx, dh);
+    return dh;
+}
+
+
+#endif // yaSSL_TEST_HPP
+
diff --git a/extra/yassl/testsuite/testsuite.cpp b/extra/yassl/testsuite/testsuite.cpp
new file mode 100644
index 00000000000..af988432a86
--- /dev/null
+++ b/extra/yassl/testsuite/testsuite.cpp
@@ -0,0 +1,155 @@
+// testsuite.cpp
+
+#include "test.hpp"
+#include "md5.hpp"
+
+
+typedef unsigned char byte;
+
+void taocrypt_test(void*);
+void file_test(char*, byte*);
+
+void client_test(void*);
+void echoclient_test(void*);
+
+THREAD_RETURN YASSL_API server_test(void*);
+THREAD_RETURN YASSL_API echoserver_test(void*);
+
+void wait_tcp_ready(func_args&);
+
+
+
+int main(int argc, char** argv)
+{
+    func_args args(argc, argv);
+    func_args server_args(argc, argv);
+
+    // *** Crypto Test ***
+    taocrypt_test(&args);
+    assert(args.return_code == 0);
+    
+    
+    // *** Simple yaSSL client server test ***
+    tcp_ready ready;
+    server_args.SetSignal(&ready);
+
+    THREAD_TYPE serverThread;
+    start_thread(server_test, &server_args, &serverThread);
+    wait_tcp_ready(server_args);
+
+    client_test(&args);
+    assert(args.return_code == 0);
+    join_thread(serverThread);
+    assert(server_args.return_code == 0);
+    
+
+    // *** Echo input yaSSL client server test ***
+    start_thread(echoserver_test, &server_args, &serverThread);
+    wait_tcp_ready(server_args);
+    func_args echo_args;
+
+            // setup args
+    const int numArgs = 3;
+    echo_args.argc = numArgs;
+    char* myArgv[numArgs];
+
+    char argc0[32];
+    char argc1[32];
+    char argc2[32];
+
+    myArgv[0] = argc0;
+    myArgv[1] = argc1;
+    myArgv[2] = argc2;
+
+    echo_args.argv = myArgv;
+   
+    strcpy(echo_args.argv[0], "echoclient");
+    strcpy(echo_args.argv[1], "input");
+    strcpy(echo_args.argv[2], "output");
+    remove("output");
+
+            // make sure OK
+    echoclient_test(&echo_args);
+    assert(echo_args.return_code == 0);
+
+
+    // *** Echo quit yaSSL client server test ***
+    echo_args.argc = 2;
+    strcpy(echo_args.argv[1], "quit");
+
+    echoclient_test(&echo_args);
+    assert(echo_args.return_code == 0);
+    join_thread(serverThread);
+    assert(server_args.return_code == 0);
+
+
+            // input output compare
+    byte input[TaoCrypt::MD5::DIGEST_SIZE];
+    byte output[TaoCrypt::MD5::DIGEST_SIZE];
+    file_test("input", input);
+    file_test("output", output);
+    assert(memcmp(input, output, sizeof(input)) == 0);
+
+    printf("\nAll tests passed!\n");
+
+    return 0;
+}
+
+
+
+void start_thread(THREAD_FUNC fun, func_args* args, THREAD_TYPE* thread)
+{
+#ifndef _POSIX_THREADS
+    *thread = _beginthreadex(0, 0, fun, args, 0, 0);
+#else
+    pthread_create(thread, 0, fun, args);
+#endif
+}
+
+
+void join_thread(THREAD_TYPE thread)
+{
+#ifndef _POSIX_THREADS
+    int res = WaitForSingleObject(reinterpret_cast(thread), INFINITE);
+    assert(res == WAIT_OBJECT_0);
+    res = CloseHandle(reinterpret_cast(thread));
+    assert(res);
+#else
+    pthread_join(thread, 0);
+#endif
+}
+
+
+
+void wait_tcp_ready(func_args& args)
+{
+#ifdef _POSIX_THREADS
+    pthread_mutex_lock(&args.signal_->mutex_);
+    
+    if (!args.signal_->ready_)
+        pthread_cond_wait(&args.signal_->cond_, &args.signal_->mutex_);
+    args.signal_->ready_ = false; // reset
+
+    pthread_mutex_unlock(&args.signal_->mutex_);
+#endif
+}
+
+
+int test_openSSL_des()
+{
+    /* test des encrypt/decrypt */
+    char data[] = "this is my data ";
+    int  dataSz = strlen(data);
+    DES_key_schedule key[3];
+    byte iv[8];
+    EVP_BytesToKey(EVP_des_ede3_cbc(), EVP_md5(), NULL, (byte*)data, dataSz, 1,
+                   (byte*)key, iv);
+
+    byte cipher[16];
+    DES_ede3_cbc_encrypt((byte*)data, cipher, dataSz, &key[0], &key[8],
+                         &key[16], &iv, true);
+    byte plain[16];
+    DES_ede3_cbc_encrypt(cipher, plain, 16, &key[0], &key[8], &key[16],
+                         &iv, false);
+    return 0;
+}
diff --git a/extra/yassl/testsuite/testsuite.dsp b/extra/yassl/testsuite/testsuite.dsp
new file mode 100644
index 00000000000..f896aa7f020
--- /dev/null
+++ b/extra/yassl/testsuite/testsuite.dsp
@@ -0,0 +1,127 @@
+# Microsoft Developer Studio Project File - Name="testsuite" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Console Application" 0x0103
+
+CFG=testsuite - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE 
+!MESSAGE NMAKE /f "testsuite.mak".
+!MESSAGE 
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE 
+!MESSAGE NMAKE /f "testsuite.mak" CFG="testsuite - Win32 Debug"
+!MESSAGE 
+!MESSAGE Possible choices for configuration are:
+!MESSAGE 
+!MESSAGE "testsuite - Win32 Release" (based on "Win32 (x86) Console Application")
+!MESSAGE "testsuite - Win32 Debug" (based on "Win32 (x86) Console Application")
+!MESSAGE 
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF  "$(CFG)" == "testsuite - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /MT /W3 /GX- /O2 /I "../taocrypt/include" /I "../include" /I "../mySTL" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "NO_MAIN_DRIVER" /YX /FD /c
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib Ws2_32.lib /nologo /subsystem:console /machine:I386 /nodefaultlib:"LIBC"
+# SUBTRACT LINK32 /nodefaultlib
+
+!ELSEIF  "$(CFG)" == "testsuite - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /MTd /W3 /Gm /GX- /ZI /Od /I "../taocrypt/include" /I "../include" /I "../mySTL" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "NO_MAIN_DRIVER" /FR /YX /FD /GZ /c
+# ADD BASE RSC /l 0x409 /d "_DEBUG"
+# ADD RSC /l 0x409 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib Ws2_32.lib /nologo /subsystem:console /debug /machine:I386 /nodefaultlib:"LIBCD" /pdbtype:sept
+
+!ENDIF 
+
+# Begin Target
+
+# Name "testsuite - Win32 Release"
+# Name "testsuite - Win32 Debug"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=..\examples\client\client.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=..\examples\echoclient\echoclient.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=..\examples\echoserver\echoserver.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=..\examples\server\server.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=..\taocrypt\test\test.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\testsuite.cpp
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# Begin Source File
+
+SOURCE=.\test.hpp
+# End Source File
+# End Group
+# Begin Group "Resource Files"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# End Target
+# End Project
diff --git a/extra/yassl/yassl.dsp b/extra/yassl/yassl.dsp
index f51c19eebbf..dc090512743 100644
--- a/extra/yassl/yassl.dsp
+++ b/extra/yassl/yassl.dsp
@@ -41,7 +41,7 @@ RSC=rc.exe
 # PROP Intermediate_Dir "Release"
 # PROP Target_Dir ""
 # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
-# ADD CPP /nologo /MT /W3 /GX- /O2 /I "include" /I "taocrypt\include" /I "mySTL" /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
+# ADD CPP /nologo /MT /W3 /O2 /I "include" /I "taocrypt\include" /I "mySTL" /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
 # ADD BASE RSC /l 0x409 /d "NDEBUG"
 # ADD RSC /l 0x409 /d "NDEBUG"
 BSC32=bscmake.exe
@@ -64,7 +64,7 @@ LIB32=link.exe -lib
 # PROP Intermediate_Dir "Debug"
 # PROP Target_Dir ""
 # ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
-# ADD CPP /nologo /MTd /W3 /Gm /GX- /ZI /Od /I "include" /I "taocrypt\include" /I "mySTL" /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /FR /YX /FD /GZ /c
+# ADD CPP /nologo /MTd /W3 /Gm /ZI /Od /I "include" /I "taocrypt\include" /I "mySTL" /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /FR /YX /FD /GZ /c
 # ADD BASE RSC /l 0x409 /d "_DEBUG"
 # ADD RSC /l 0x409 /d "_DEBUG"
 BSC32=bscmake.exe
diff --git a/extra/yassl/yassl.dsw b/extra/yassl/yassl.dsw
index c0bba9acdce..288c88dfd5b 100644
--- a/extra/yassl/yassl.dsw
+++ b/extra/yassl/yassl.dsw
@@ -3,6 +3,21 @@ Microsoft Developer Studio Workspace File, Format Version 6.00
 
 ###############################################################################
 
+Project: "benchmark"=.\taocrypt\benchmark\benchmark.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+    Begin Project Dependency
+    Project_Dep_Name taocrypt
+    End Project Dependency
+}}}
+
+###############################################################################
+
 Project: "client"=.\examples\client\client.dsp - Package Owner=<4>
 
 Package=<5>

From 70404e2a75bf2ee36a4ca416a3c03baacb96dd81 Mon Sep 17 00:00:00 2001
From: "msvensson@shellback.(none)" <>
Date: Fri, 7 Apr 2006 12:46:50 +0200
Subject: [PATCH 005/108] Fix spelling error

---
 include/my_global.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/my_global.h b/include/my_global.h
index 969617c084b..7adf4845984 100644
--- a/include/my_global.h
+++ b/include/my_global.h
@@ -464,7 +464,7 @@ typedef unsigned short ushort;
 
 /*
   Wen using the embedded library, users might run into link problems,
-  dupicate declaration of __cxa_pure_virtual, solved by declaring it a
+  duplicate declaration of __cxa_pure_virtual, solved by declaring it a
   weak symbol.
 */
 #ifdef USE_MYSYS_NEW

From 1c4e31d5feb6c0c645a7672c423af37bbe3ae5a4 Mon Sep 17 00:00:00 2001
From: "msvensson@shellback.(none)" <>
Date: Tue, 11 Apr 2006 23:51:14 +0200
Subject: [PATCH 006/108] Add new yaSSL files Add benchmark, testsuite and
 taocrypt/test as places where to produce Makfiles and build - very useful for
 debugging

---
 config/ac-macros/yassl.m4                  |  5 ++++-
 extra/yassl/Makefile.am                    |  2 +-
 extra/yassl/taocrypt/Makefile.am           |  2 +-
 extra/yassl/taocrypt/benchmark/Makefile.am |  8 ++++++++
 extra/yassl/taocrypt/src/Makefile.am       | 10 ++++++----
 extra/yassl/taocrypt/test/Makefile.am      |  8 ++++++++
 extra/yassl/testsuite/Makefile.am          | 11 +++++++++++
 7 files changed, 39 insertions(+), 7 deletions(-)
 create mode 100644 extra/yassl/taocrypt/benchmark/Makefile.am
 create mode 100644 extra/yassl/taocrypt/test/Makefile.am
 create mode 100644 extra/yassl/testsuite/Makefile.am

diff --git a/config/ac-macros/yassl.m4 b/config/ac-macros/yassl.m4
index c736f2f10f2..5beb87c7652 100644
--- a/config/ac-macros/yassl.m4
+++ b/config/ac-macros/yassl.m4
@@ -1,7 +1,10 @@
 AC_CONFIG_FILES(extra/yassl/Makefile dnl
 extra/yassl/taocrypt/Makefile dnl
 extra/yassl/taocrypt/src/Makefile dnl
-extra/yassl/src/Makefile)
+extra/yassl/src/Makefile dnl
+extra/yassl/testsuite/Makefile dnl
+extra/yassl/taocrypt/test/Makefile dnl
+extra/yassl/taocrypt/benchmark/Makefile)
 
 AC_DEFUN([MYSQL_CHECK_YASSL], [
   AC_MSG_CHECKING(for yaSSL)
diff --git a/extra/yassl/Makefile.am b/extra/yassl/Makefile.am
index 41c4d84f24f..d0415012767 100644
--- a/extra/yassl/Makefile.am
+++ b/extra/yassl/Makefile.am
@@ -1,2 +1,2 @@
-SUBDIRS = taocrypt src
+SUBDIRS = taocrypt src testsuite
 EXTRA_DIST = yassl.dsp yassl.dsw $(wildcard mySTL/*.hpp)
diff --git a/extra/yassl/taocrypt/Makefile.am b/extra/yassl/taocrypt/Makefile.am
index af3ded7abfd..2aa43a6c814 100644
--- a/extra/yassl/taocrypt/Makefile.am
+++ b/extra/yassl/taocrypt/Makefile.am
@@ -1,2 +1,2 @@
-SUBDIRS = src
+SUBDIRS = src test
 EXTRA_DIST = taocrypt.dsw taocrypt.dsp
diff --git a/extra/yassl/taocrypt/benchmark/Makefile.am b/extra/yassl/taocrypt/benchmark/Makefile.am
new file mode 100644
index 00000000000..81200ff7e6a
--- /dev/null
+++ b/extra/yassl/taocrypt/benchmark/Makefile.am
@@ -0,0 +1,8 @@
+INCLUDES = -I../include -I../../mySTL
+bin_PROGRAMS       = benchmark
+benchmark_SOURCES  = benchmark.cpp
+benchmark_LDFLAGS  = -L../src
+benchmark_LDADD    = -ltaocrypt
+benchmark_CXXFLAGS = -DYASSL_PURE_C
+benchmark_DEPENDENCIES = ../src/libtaocrypt.la
+EXTRA_DIST = benchmark.dsp rsa1024.der dh1024.der dsa1024.der make.bat
diff --git a/extra/yassl/taocrypt/src/Makefile.am b/extra/yassl/taocrypt/src/Makefile.am
index d89fa95a940..d3e72346110 100644
--- a/extra/yassl/taocrypt/src/Makefile.am
+++ b/extra/yassl/taocrypt/src/Makefile.am
@@ -2,10 +2,12 @@ INCLUDES = -I../include -I../../mySTL
 
 noinst_LTLIBRARIES = libtaocrypt.la
 
-libtaocrypt_la_SOURCES  = aes.cpp aestables.cpp algebra.cpp arc4.cpp asn.cpp \
-	coding.cpp dh.cpp des.cpp dsa.cpp file.cpp hash.cpp \
-	md2.cpp md5.cpp misc.cpp random.cpp ripemd.cpp rsa.cpp sha.cpp \
-	template_instnt.cpp integer.cpp
+libtaocrypt_la_SOURCES  = aes.cpp aestables.cpp algebra.cpp arc4.cpp \
+        asn.cpp bftables.cpp blowfish.cpp coding.cpp des.cpp dh.cpp \
+        dsa.cpp file.cpp hash.cpp integer.cpp md2.cpp md5.cpp misc.cpp \
+        random.cpp ripemd.cpp rsa.cpp sha.cpp template_instnt.cpp \
+        tftables.cpp twofish.cpp
+
 libtaocrypt_la_CXXFLAGS = @yassl_taocrypt_extra_cxxflags@ -DYASSL_PURE_C
 
 EXTRA_DIST = $(wildcard ../include/*.hpp)
diff --git a/extra/yassl/taocrypt/test/Makefile.am b/extra/yassl/taocrypt/test/Makefile.am
new file mode 100644
index 00000000000..0b238f1e057
--- /dev/null
+++ b/extra/yassl/taocrypt/test/Makefile.am
@@ -0,0 +1,8 @@
+INCLUDES = -I../include -I../../mySTL
+bin_PROGRAMS = test
+test_SOURCES = test.cpp
+test_LDFLAGS  = -L../src
+test_LDADD    = -ltaocrypt
+test_DEPENDENCIES = ../src/libtaocrypt.la
+test_CXXFLAGS = -DYASSL_PURE_C
+EXTRA_DIST = make.bat
diff --git a/extra/yassl/testsuite/Makefile.am b/extra/yassl/testsuite/Makefile.am
new file mode 100644
index 00000000000..3a07ac316e1
--- /dev/null
+++ b/extra/yassl/testsuite/Makefile.am
@@ -0,0 +1,11 @@
+INCLUDES = -I../include -I../taocrypt/include -I../mySTL
+bin_PROGRAMS       = testsuite
+testsuite_SOURCES  = testsuite.cpp ../taocrypt/test/test.cpp \
+	../examples/client/client.cpp ../examples/server/server.cpp \
+	../examples/echoclient/echoclient.cpp \
+	../examples/echoserver/echoserver.cpp
+testsuite_LDFLAGS  = -L../src/ -L../taocrypt/src $(PTHREAD_LDFLAGS)
+testsuite_CXXFLAGS = -DYASSL_PURE_C -DNO_MAIN_DRIVER -Wall -Wno-unused $(PTHREAD_CFLAGS)
+testsuite_LDADD    = -lyassl -ltaocrypt $(EXTRA_PTHREAD) $(EXTRA_SOCKET)
+testsuite_DEPENDENCIES = ../src/libyassl.la ../taocrypt/src/libtaocrypt.la
+EXTRA_DIST = testsuite.dsp test.hpp input quit make.bat

From 9cdd78078e0434cca3eb20d1d9612a3f1c38abb6 Mon Sep 17 00:00:00 2001
From: "msvensson@neptunus.(none)" <>
Date: Wed, 12 Apr 2006 15:13:16 +0200
Subject: [PATCH 007/108] Bug#18564  Test failure due to test not checking
 preconditions  - Add variable "have_dynamic_loading" and use it to check if
 the udf test should be run.

---
 mysql-test/include/have_udf.inc | 14 +++++---------
 mysql-test/r/have_udf.require   |  3 ++-
 mysql-test/t/disabled.def       |  1 -
 sql/mysql_priv.h                |  2 +-
 sql/mysqld.cc                   |  7 ++++++-
 sql/set_var.cc                  |  1 +
 6 files changed, 15 insertions(+), 13 deletions(-)

diff --git a/mysql-test/include/have_udf.inc b/mysql-test/include/have_udf.inc
index a22b2a52e61..b6e6f0f2516 100644
--- a/mysql-test/include/have_udf.inc
+++ b/mysql-test/include/have_udf.inc
@@ -1,12 +1,8 @@
 #
-# To check if the udf_example.so is available,
-# try to load one function from it.
-#
+# Check if server has support for loading udf's
+# i.e it will support dlopen
 #
 --require r/have_udf.require
---disable_abort_on_error
-CREATE FUNCTION metaphon RETURNS STRING SONAME 'udf_example.so';
---disable_query_log
-DROP FUNCTION metaphon;
---enable_query_log
---enable_abort_on_error
+disable_query_log;
+show variables like "have_dynamic_loading";
+enable_query_log;
diff --git a/mysql-test/r/have_udf.require b/mysql-test/r/have_udf.require
index 869d1b254fd..2d21f65e4ac 100644
--- a/mysql-test/r/have_udf.require
+++ b/mysql-test/r/have_udf.require
@@ -1 +1,2 @@
-CREATE FUNCTION metaphon RETURNS STRING SONAME 'udf_example.so';
+Variable_name	Value
+have_dynamic_loading	YES
diff --git a/mysql-test/t/disabled.def b/mysql-test/t/disabled.def
index a836b1a2897..f71e24ff3ed 100644
--- a/mysql-test/t/disabled.def
+++ b/mysql-test/t/disabled.def
@@ -12,4 +12,3 @@
 
 sp-goto         : GOTO is currently is disabled - will be fixed in the future
 ndb_load        : Bug#17233
-udf             : Bug#18564 (Permission by Brian)
diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h
index ca7801039c5..4e9015910cb 100644
--- a/sql/mysql_priv.h
+++ b/sql/mysql_priv.h
@@ -1296,7 +1296,7 @@ extern SHOW_COMP_OPTION have_ndbcluster;
 #endif
 
 extern SHOW_COMP_OPTION have_isam;
-extern SHOW_COMP_OPTION have_raid, have_openssl, have_symlink;
+extern SHOW_COMP_OPTION have_raid, have_openssl, have_symlink, have_dlopen;
 extern SHOW_COMP_OPTION have_query_cache;
 extern SHOW_COMP_OPTION have_geometry, have_rtree_keys;
 extern SHOW_COMP_OPTION have_crypt;
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index 9dd37bbebc9..f97a9ebadc3 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -474,7 +474,7 @@ CHARSET_INFO *character_set_filesystem;
 
 SHOW_COMP_OPTION have_isam;
 SHOW_COMP_OPTION have_raid, have_openssl, have_symlink, have_query_cache;
-SHOW_COMP_OPTION have_geometry, have_rtree_keys;
+SHOW_COMP_OPTION have_geometry, have_rtree_keys, have_dlopen;
 SHOW_COMP_OPTION have_crypt, have_compress;
 
 /* Thread specific variables */
@@ -6415,6 +6415,11 @@ static void mysql_init_variables(void)
 #else
   have_symlink=SHOW_OPTION_YES;
 #endif
+#ifdef HAVE_DLOPEN
+  have_dlopen=SHOW_OPTION_YES;
+#else
+  have_dlopen=SHOW_OPTION_NO;
+#endif
 #ifdef HAVE_QUERY_CACHE
   have_query_cache=SHOW_OPTION_YES;
 #else
diff --git a/sql/set_var.cc b/sql/set_var.cc
index 7be79ab59f0..a1860027630 100644
--- a/sql/set_var.cc
+++ b/sql/set_var.cc
@@ -810,6 +810,7 @@ struct show_var_st init_vars[]= {
   {"have_compress",	      (char*) &have_compress,		    SHOW_HAVE},
   {"have_crypt",	      (char*) &have_crypt,		    SHOW_HAVE},
   {"have_csv",	              (char*) &have_csv_db,	            SHOW_HAVE},
+  {"have_dynamic_loading",    (char*) &have_dlopen,	            SHOW_HAVE},
   {"have_example_engine",     (char*) &have_example_db,	            SHOW_HAVE},
   {"have_federated_engine",   (char*) &have_federated_db,           SHOW_HAVE},
   {"have_geometry",           (char*) &have_geometry,               SHOW_HAVE},

From f3373899e2e077f7ad5fb2e07a3581eb4a0cf960 Mon Sep 17 00:00:00 2001
From: "msvensson@neptunus.(none)" <>
Date: Thu, 13 Apr 2006 13:02:58 +0200
Subject: [PATCH 008/108] Bug#18837 Many build and test failures when
 configuring without --disable-shared Build "NOINST" tools with -static flag
 to avoid  any ld problems when using them

---
 configure.in | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/configure.in b/configure.in
index 3e936ae422f..41ba8f4c8f0 100644
--- a/configure.in
+++ b/configure.in
@@ -513,7 +513,7 @@ then
   AC_MSG_ERROR([MySQL requires an ANSI C compiler (and a C++ compiler). Try gcc. See the Installation chapter in the Reference Manual.])
 fi
 
-NOINST_LDFLAGS=
+NOINST_LDFLAGS="-static"
 
 static_nss=""
 STATIC_NSS_FLAGS=""

From 4e11a4d94199c710b0c7d0bf547157c14c480f19 Mon Sep 17 00:00:00 2001
From: "acurtis@xiphis.org" <>
Date: Thu, 13 Apr 2006 13:49:29 -0700
Subject: [PATCH 009/108] WL#3201   " Configure support for server plugins "

---
 BUILD/SETUP.sh                             |  15 +-
 Makefile.am                                |   3 +-
 config/ac-macros/ha_archive.m4             |  29 -
 config/ac-macros/ha_berkeley.m4            |   3 -
 config/ac-macros/ha_blackhole.m4           |  29 -
 config/ac-macros/ha_example.m4             |  30 -
 config/ac-macros/ha_federated.m4           |  29 -
 config/ac-macros/ha_innodb.m4              |  77 ---
 config/ac-macros/ha_ndbcluster.m4          |   7 +-
 config/ac-macros/ha_partition.m4           |  33 --
 config/ac-macros/ha_tina.m4                |  29 -
 config/ac-macros/plugins.m4                | 603 +++++++++++++++++++++
 config/ac-macros/storage.m4                |  55 --
 configure.in                               | 185 ++++---
 include/mysql/plugin.h                     |  21 +-
 libmysqld/Makefile.am                      |  24 +-
 plugin/Makefile.am                         |  28 +-
 plugin/fulltext/Makefile.am                |  47 +-
 plugin/fulltext/plugin_example.c           |   2 +-
 sql/Makefile.am                            |  32 +-
 sql/ha_berkeley.cc                         |  18 +
 sql/ha_federated.cc                        |  19 +
 sql/ha_heap.cc                             |  13 +
 sql/ha_innodb.cc                           |  17 +
 sql/ha_myisam.cc                           |  16 +
 sql/ha_myisammrg.cc                        |  15 +
 sql/ha_ndbcluster.cc                       |  19 +
 sql/ha_ndbcluster_binlog.cc                |   2 +
 sql/ha_partition.cc                        |  19 +
 sql/handler.cc                             | 159 +++---
 sql/handler.h                              |   5 +-
 sql/handlerton-win.cc                      |  72 ---
 sql/handlerton.cc.in                       |  14 -
 sql/log.cc                                 |  15 +
 sql/mysqld.cc                              |  30 +-
 sql/partition_info.cc                      |   3 +-
 sql/sql_builtin.cc.in                      |  13 +
 sql/sql_delete.cc                          |   2 +
 sql/sql_plugin.cc                          |  75 ++-
 sql/sql_show.cc                            |  45 +-
 sql/sql_yacc.yy                            |   2 +-
 storage/archive/Makefile.am                |  50 +-
 {sql => storage/archive}/ha_archive.cc     |  50 +-
 {sql => storage/archive}/ha_archive.h      |   2 +-
 storage/blackhole/Makefile.am              |  51 ++
 {sql => storage/blackhole}/ha_blackhole.cc |  14 +
 {sql => storage/blackhole}/ha_blackhole.h  |   0
 storage/csv/Makefile.am                    |  13 +-
 storage/csv/ha_tina.cc                     |   6 +-
 storage/example/Makefile.am                |  30 +-
 storage/example/ha_example.cc              |   6 +-
 storage/innobase/Makefile.am               |  29 +
 52 files changed, 1387 insertions(+), 718 deletions(-)
 delete mode 100644 config/ac-macros/ha_archive.m4
 delete mode 100644 config/ac-macros/ha_blackhole.m4
 delete mode 100644 config/ac-macros/ha_example.m4
 delete mode 100644 config/ac-macros/ha_federated.m4
 delete mode 100644 config/ac-macros/ha_innodb.m4
 delete mode 100644 config/ac-macros/ha_partition.m4
 delete mode 100644 config/ac-macros/ha_tina.m4
 create mode 100644 config/ac-macros/plugins.m4
 delete mode 100644 config/ac-macros/storage.m4
 delete mode 100644 sql/handlerton-win.cc
 delete mode 100644 sql/handlerton.cc.in
 create mode 100644 sql/sql_builtin.cc.in
 rename {sql => storage/archive}/ha_archive.cc (97%)
 rename {sql => storage/archive}/ha_archive.h (99%)
 create mode 100644 storage/blackhole/Makefile.am
 rename {sql => storage/blackhole}/ha_blackhole.cc (95%)
 rename {sql => storage/blackhole}/ha_blackhole.h (100%)

diff --git a/BUILD/SETUP.sh b/BUILD/SETUP.sh
index 3c3facae34f..7b6dc29ad66 100755
--- a/BUILD/SETUP.sh
+++ b/BUILD/SETUP.sh
@@ -146,18 +146,9 @@ static_link="$static_link --with-client-ldflags=-all-static"
 local_infile_configs="--enable-local-infile"
 
 
-max_configs="--with-innodb --with-berkeley-db"
-max_configs="$max_configs --with-archive-storage-engine"
-max_configs="$max_configs --with-big-tables"
-max_configs="$max_configs --with-blackhole-storage-engine"
-max_configs="$max_configs --with-federated-storage-engine"
-max_configs="$max_configs --with-csv-storage-engine"
-max_configs="$max_configs --with-example-storage-engine"
-max_configs="$max_configs --with-partition $SSL_LIBRARY"
-
-max_no_embedded_configs="$max_configs --with-ndbcluster"
-max_no_ndb_configs="$max_configs --without-ndbcluster --with-embedded-server"
-max_configs="$max_configs --with-ndbcluster --with-embedded-server"
+max_no_embedded_configs="$SSL_LIBRARY --with-modules=max"
+max_no_ndb_configs="$SSL_LIBRARY --with-modules=max-no-ndb --with-embedded-server"
+max_configs="$SSL_LIBRARY --with-modules=max --with-embedded-server"
 
 #
 # CPU and platform specific compilation flags.
diff --git a/Makefile.am b/Makefile.am
index 4e648dabe27..86bf6d6c03d 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -24,9 +24,8 @@ EXTRA_DIST =		INSTALL-SOURCE INSTALL-WIN-SOURCE \
 SUBDIRS =		. include @docs_dirs@ @zlib_dir@ @yassl_dir@ \
 			@readline_topdir@ sql-common \
 			@thread_dirs@ pstack \
-			@sql_union_dirs@ @mysql_se_dirs@ \
+			@sql_union_dirs@ @mysql_plugin_dirs@ \
 			@sql_server@ scripts @man_dirs@ tests \
-			@mysql_se_plugins@ \
 			netware @libmysqld_dirs@ \
 			@bench_dirs@ support-files @tools_dirs@ \
 			plugin win
diff --git a/config/ac-macros/ha_archive.m4 b/config/ac-macros/ha_archive.m4
deleted file mode 100644
index 2d2558ea600..00000000000
--- a/config/ac-macros/ha_archive.m4
+++ /dev/null
@@ -1,29 +0,0 @@
-dnl ---------------------------------------------------------------------------
-dnl Macro: MYSQL_CHECK_ARCHIVEDB
-dnl Sets HAVE_ARCHIVE_DB if --with-archive-storage-engine is used
-dnl ---------------------------------------------------------------------------
-AC_DEFUN([MYSQL_CHECK_ARCHIVEDB], [
-  AC_ARG_WITH([archive-storage-engine],
-              [
-  --with-archive-storage-engine
-                          Enable the Archive Storage Engine],
-              [archivedb="$withval"],
-              [archivedb=no])
-  AC_MSG_CHECKING([for archive storage engine])
-
-  case "$archivedb" in
-    yes )
-      AC_DEFINE([HAVE_ARCHIVE_DB], [1], [Builds Archive Storage Engine])
-      AC_MSG_RESULT([yes])
-      [archivedb=yes]
-      ;;
-    * )
-      AC_MSG_RESULT([no])
-      [archivedb=no]
-      ;;
-  esac
-
-])
-dnl ---------------------------------------------------------------------------
-dnl END OF MYSQL_CHECK_ARCHIVE SECTION
-dnl ---------------------------------------------------------------------------
diff --git a/config/ac-macros/ha_berkeley.m4 b/config/ac-macros/ha_berkeley.m4
index 183a622dfc9..c389077ea8b 100644
--- a/config/ac-macros/ha_berkeley.m4
+++ b/config/ac-macros/ha_berkeley.m4
@@ -120,12 +120,9 @@ AC_DEFUN([MYSQL_SETUP_BERKELEY_DB], [
        sh $rel_srcdir/$bdb/dist/configure $bdb_conf_flags) || \
         AC_MSG_ERROR([could not configure Berkeley DB])
  
-  mysql_se_libs="$mysql_se_libs $bdb_libs_with_path" 
-
   AC_SUBST(bdb_includes)
   AC_SUBST(bdb_libs)
   AC_SUBST(bdb_libs_with_path)
-  AC_CONFIG_FILES(storage/bdb/Makefile)
 ])
 
 AC_DEFUN([MYSQL_CHECK_INSTALLED_BDB], [
diff --git a/config/ac-macros/ha_blackhole.m4 b/config/ac-macros/ha_blackhole.m4
deleted file mode 100644
index cc4d360f5a8..00000000000
--- a/config/ac-macros/ha_blackhole.m4
+++ /dev/null
@@ -1,29 +0,0 @@
-dnl ---------------------------------------------------------------------------
-dnl Macro: MYSQL_CHECK_BLACKHOLEDB
-dnl Sets HAVE_BLACKHOLE_DB if --with-blackhole-storage-engine is used
-dnl ---------------------------------------------------------------------------
-AC_DEFUN([MYSQL_CHECK_BLACKHOLEDB], [
-  AC_ARG_WITH([blackhole-storage-engine],
-              [
-  --with-blackhole-storage-engine
-                          Enable the Blackhole Storage Engine],
-              [blackholedb="$withval"],
-              [blackholedb=no])
-  AC_MSG_CHECKING([for blackhole storage engine])
-
-  case "$blackholedb" in
-    yes )
-      AC_DEFINE([HAVE_BLACKHOLE_DB], [1], [Builds Blackhole Storage Engine])
-      AC_MSG_RESULT([yes])
-      [blackholedb=yes]
-      ;;
-    * )
-      AC_MSG_RESULT([no])
-      [blackholedb=no]
-      ;;
-  esac
-
-])
-dnl ---------------------------------------------------------------------------
-dnl END OF MYSQL_CHECK_BLACKHOLE SECTION
-dnl ---------------------------------------------------------------------------
diff --git a/config/ac-macros/ha_example.m4 b/config/ac-macros/ha_example.m4
deleted file mode 100644
index f8067931ce6..00000000000
--- a/config/ac-macros/ha_example.m4
+++ /dev/null
@@ -1,30 +0,0 @@
-dnl ---------------------------------------------------------------------------
-dnl Macro: MYSQL_CHECK_EXAMPLEDB
-dnl Sets HAVE_EXAMPLE_DB if --with-example-storage-engine is used
-dnl ---------------------------------------------------------------------------
-AC_DEFUN([MYSQL_CHECK_EXAMPLEDB], [
-  AC_ARG_WITH([example-storage-engine],
-              [
-  --with-example-storage-engine
-                          Enable the Example Storage Engine],
-              [exampledb="$withval"],
-              [exampledb=no])
-  AC_MSG_CHECKING([for example storage engine])
-
-  case "$exampledb" in
-    yes )
-      AC_DEFINE([HAVE_EXAMPLE_DB], [1], [Builds Example DB])
-      AC_MSG_RESULT([yes])
-      [exampledb=yes]
-      ;;
-    * )
-      AC_MSG_RESULT([no])
-      [exampledb=no]
-      ;;
-  esac
-
-])
-dnl ---------------------------------------------------------------------------
-dnl END OF MYSQL_CHECK_EXAMPLE SECTION
-dnl ---------------------------------------------------------------------------
-
diff --git a/config/ac-macros/ha_federated.m4 b/config/ac-macros/ha_federated.m4
deleted file mode 100644
index 5c991f31666..00000000000
--- a/config/ac-macros/ha_federated.m4
+++ /dev/null
@@ -1,29 +0,0 @@
-dnl ---------------------------------------------------------------------------
-dnl Macro: MYSQL_CHECK_FEDERATED
-dnl Sets HAVE_FEDERATED if --with-federated-storage-engine is used
-dnl ---------------------------------------------------------------------------
-AC_DEFUN([MYSQL_CHECK_FEDERATED], [
-  AC_ARG_WITH([federated-storage-engine],
-              [
-  --with-federated-storage-engine
-                        Enable the MySQL Federated Storage Engine],
-              [federateddb="$withval"],
-              [federateddb=no])
-  AC_MSG_CHECKING([for MySQL federated storage engine])
-
-  case "$federateddb" in
-    yes )
-      AC_DEFINE([HAVE_FEDERATED_DB], [1], [Define to enable Federated Handler])
-      AC_MSG_RESULT([yes])
-      [federateddb=yes]
-      ;;
-    * )
-      AC_MSG_RESULT([no])
-      [federateddb=no]
-      ;;
-  esac
-
-])
-dnl ---------------------------------------------------------------------------
-dnl END OF MYSQL_CHECK_FEDERATED SECTION
-dnl ---------------------------------------------------------------------------
diff --git a/config/ac-macros/ha_innodb.m4 b/config/ac-macros/ha_innodb.m4
deleted file mode 100644
index 287b77c8851..00000000000
--- a/config/ac-macros/ha_innodb.m4
+++ /dev/null
@@ -1,77 +0,0 @@
-dnl ---------------------------------------------------------------------------
-dnl Macro: MYSQL_CHECK_INNODB
-dnl Sets HAVE_INNOBASE_DB if --with-innodb is used
-dnl ---------------------------------------------------------------------------
-
-AC_DEFUN([MYSQL_CHECK_INNODB], [
-  AC_ARG_WITH([innodb],
-              [
-  --without-innodb        Do not include the InnoDB table handler],
-              [innodb="$withval"],
-              [innodb=yes])
-
-  AC_MSG_CHECKING([for Innodb])
-
-  have_innodb=no
-  innodb_includes=
-  innodb_libs=
-  case "$innodb" in
-    yes )
-      AC_MSG_RESULT([Using Innodb])
-      AC_DEFINE([HAVE_INNOBASE_DB], [1], [Using Innobase DB])
-      have_innodb="yes"
-      innodb_includes="-I\$(top_builddir)/innobase/include"
-      innodb_system_libs=""
-dnl Some libs are listed several times, in order for gcc to sort out
-dnl circular references.
-      innodb_libs="\
- \$(top_builddir)/storage/innobase/usr/libusr.a\
- \$(top_builddir)/storage/innobase/srv/libsrv.a\
- \$(top_builddir)/storage/innobase/dict/libdict.a\
- \$(top_builddir)/storage/innobase/que/libque.a\
- \$(top_builddir)/storage/innobase/srv/libsrv.a\
- \$(top_builddir)/storage/innobase/ibuf/libibuf.a\
- \$(top_builddir)/storage/innobase/row/librow.a\
- \$(top_builddir)/storage/innobase/pars/libpars.a\
- \$(top_builddir)/storage/innobase/btr/libbtr.a\
- \$(top_builddir)/storage/innobase/trx/libtrx.a\
- \$(top_builddir)/storage/innobase/read/libread.a\
- \$(top_builddir)/storage/innobase/usr/libusr.a\
- \$(top_builddir)/storage/innobase/buf/libbuf.a\
- \$(top_builddir)/storage/innobase/ibuf/libibuf.a\
- \$(top_builddir)/storage/innobase/eval/libeval.a\
- \$(top_builddir)/storage/innobase/log/liblog.a\
- \$(top_builddir)/storage/innobase/fsp/libfsp.a\
- \$(top_builddir)/storage/innobase/fut/libfut.a\
- \$(top_builddir)/storage/innobase/fil/libfil.a\
- \$(top_builddir)/storage/innobase/lock/liblock.a\
- \$(top_builddir)/storage/innobase/mtr/libmtr.a\
- \$(top_builddir)/storage/innobase/page/libpage.a\
- \$(top_builddir)/storage/innobase/rem/librem.a\
- \$(top_builddir)/storage/innobase/thr/libthr.a\
- \$(top_builddir)/storage/innobase/sync/libsync.a\
- \$(top_builddir)/storage/innobase/data/libdata.a\
- \$(top_builddir)/storage/innobase/mach/libmach.a\
- \$(top_builddir)/storage/innobase/ha/libha.a\
- \$(top_builddir)/storage/innobase/dyn/libdyn.a\
- \$(top_builddir)/storage/innobase/mem/libmem.a\
- \$(top_builddir)/storage/innobase/sync/libsync.a\
- \$(top_builddir)/storage/innobase/ut/libut.a\
- \$(top_builddir)/storage/innobase/os/libos.a\
- \$(top_builddir)/storage/innobase/ut/libut.a"
-
-      AC_CHECK_LIB(rt, aio_read, [innodb_system_libs="-lrt"])
-      ;;
-    * )
-      AC_MSG_RESULT([Not using Innodb])
-      ;;
-  esac
-
-  AC_SUBST(innodb_includes)
-  AC_SUBST(innodb_libs)
-  AC_SUBST(innodb_system_libs)
-])
-
-dnl ---------------------------------------------------------------------------
-dnl END OF MYSQL_CHECK_INNODB SECTION
-dnl ---------------------------------------------------------------------------
diff --git a/config/ac-macros/ha_ndbcluster.m4 b/config/ac-macros/ha_ndbcluster.m4
index 8e839d8fee9..1358807e000 100644
--- a/config/ac-macros/ha_ndbcluster.m4
+++ b/config/ac-macros/ha_ndbcluster.m4
@@ -191,7 +191,6 @@ AC_DEFUN([MYSQL_SETUP_NDBCLUSTER], [
   ndbcluster_libs="\$(top_builddir)/storage/ndb/src/.libs/libndbclient.a"
   ndbcluster_system_libs=""
   ndb_mgmclient_libs="\$(top_builddir)/storage/ndb/src/mgmclient/libndbmgmclient.la"
-  mysql_se_objs="$mysql_se_objs ha_ndbcluster_binlog.o"
 
   MYSQL_CHECK_NDB_OPTIONS
   NDBCLUSTER_WORKAROUNDS
@@ -282,9 +281,6 @@ AC_DEFUN([MYSQL_SETUP_NDBCLUSTER], [
     ndb_bin_am_ldflags=""
   fi
 
-  mysql_se_libs="$mysql_se_libs $ndbcluster_libs $ndbcluster_system_libs"
-  mysql_se_libs="$mysql_se_libs $NDB_SCI_LIBS"
-
   AC_SUBST(NDB_VERSION_MAJOR)
   AC_SUBST(NDB_VERSION_MINOR)
   AC_SUBST(NDB_VERSION_BUILD)
@@ -302,6 +298,7 @@ AC_DEFUN([MYSQL_SETUP_NDBCLUSTER], [
   AC_SUBST(ndbcluster_libs)
   AC_SUBST(ndbcluster_system_libs)
   AC_SUBST(ndb_mgmclient_libs)
+  AC_SUBST(NDB_SCI_LIBS)
 
   AC_SUBST(ndb_transporter_opt_objs)
   AC_SUBST(ndb_port)
@@ -310,7 +307,9 @@ AC_DEFUN([MYSQL_SETUP_NDBCLUSTER], [
 
   AC_SUBST(NDB_DEFS)
   AC_SUBST(ndb_cxxflags_fix)
+])
 
+AC_DEFUN([NDBCLUSTER_CONFIG_FILES], [
   AC_CONFIG_FILES(storage/ndb/Makefile storage/ndb/include/Makefile dnl
    storage/ndb/src/Makefile storage/ndb/src/common/Makefile dnl
    storage/ndb/docs/Makefile dnl
diff --git a/config/ac-macros/ha_partition.m4 b/config/ac-macros/ha_partition.m4
deleted file mode 100644
index 1ce7dedc5f3..00000000000
--- a/config/ac-macros/ha_partition.m4
+++ /dev/null
@@ -1,33 +0,0 @@
-dnl ---------------------------------------------------------------------------
-dnl Macro: MYSQL_CHECK_PARTITIONDB
-dnl Sets HAVE_PARTITION_DB if --with-partition is used
-dnl ---------------------------------------------------------------------------
-AC_DEFUN([MYSQL_CHECK_PARTITIONDB], [
-  AC_ARG_WITH([partition],
-              [
-  --with-partition
-                        Enable the Partition Storage Engine],
-              [partitiondb="$withval"],
-              [partitiondb=no])
-  AC_MSG_CHECKING([for partition])
-
-dnl  case "$partitiondb" in
-dnl    yes )
-dnl      AC_DEFINE([HAVE_PARTITION_DB], [1], [Builds Partition DB])
-dnl      AC_MSG_RESULT([yes])
-dnl      [partitiondb=yes]
-dnl      ;;
-dnl    * )
-dnl      AC_MSG_RESULT([no])
-dnl      [partitiondb=no]
-dnl      ;;
-dnl  esac
-      AC_DEFINE([HAVE_PARTITION_DB], [1], [Builds Partition DB])
-      AC_MSG_RESULT([yes])
-      [partitiondb=yes]
-
-])
-dnl ---------------------------------------------------------------------------
-dnl END OF MYSQL_CHECK_PARTITION SECTION
-dnl ---------------------------------------------------------------------------
-
diff --git a/config/ac-macros/ha_tina.m4 b/config/ac-macros/ha_tina.m4
deleted file mode 100644
index fe6e382ce20..00000000000
--- a/config/ac-macros/ha_tina.m4
+++ /dev/null
@@ -1,29 +0,0 @@
-dnl ---------------------------------------------------------------------------
-dnl Macro: MYSQL_CHECK_CSVDB
-dnl Sets HAVE_CSV_DB if --with-csv-storage-engine is used
-dnl ---------------------------------------------------------------------------
-AC_DEFUN([MYSQL_CHECK_CSVDB], [
-  AC_ARG_WITH([csv-storage-engine],
-              [
-  --with-csv-storage-engine
-                          Enable the CSV Storage Engine],
-              [csvdb="$withval"],
-              [csvdb=no])
-  AC_MSG_CHECKING([for csv storage engine])
-
-  case "$csvdb" in
-    yes )
-      AC_DEFINE([HAVE_CSV_DB], [1], [Builds the CSV Storage Engine])
-      AC_MSG_RESULT([yes])
-      [csvdb=yes]
-      ;;
-    * )
-      AC_MSG_RESULT([no])
-      [csvdb=no]
-      ;;
-  esac
-
-])
-dnl ---------------------------------------------------------------------------
-dnl END OF MYSQL_CHECK_CSV SECTION
-dnl ---------------------------------------------------------------------------
diff --git a/config/ac-macros/plugins.m4 b/config/ac-macros/plugins.m4
new file mode 100644
index 00000000000..5969a85dc14
--- /dev/null
+++ b/config/ac-macros/plugins.m4
@@ -0,0 +1,603 @@
+dnl ===========================================================================
+dnl Support for plugable mysql server modules
+dnl ===========================================================================
+dnl
+dnl WorkLog#3201
+dnl
+dnl Framework for pluggable static and dynamic modules for mysql
+dnl
+dnl ---------------------------------------------------------------------------
+dnl Macro: MYSQL_MODULE
+dnl
+dnl Syntax:
+dnl   MYSQL_MODULE([name],[Plugin module name],
+dnl                [Plugin module description],
+dnl                [group,group...])
+dnl   
+dnl What it does:
+dnl   First declaration for a plugin module (mandatory).
+dnl   Adds module as member to configuration groups (if specified)
+dnl
+dnl ---------------------------------------------------------------------------
+
+AC_DEFUN([MYSQL_MODULE],[ dnl
+ _MYSQL_MODULE(
+  [$1],
+  [__MYSQL_MODULE_]AS_TR_CPP([$1])[__],
+  m4_default([$2], [$1 plugin]),
+  m4_default([$3], [plugin for $1]),
+  m4_default([$4], []),
+ ) dnl
+])
+
+AC_DEFUN([_MYSQL_MODULE],[ dnl
+ m4_ifdef([$2], [ dnl
+  AC_FATAL([[Duplicate MYSQL_MODULE declaration for ]][$3]) dnl
+ ],[ dnl 
+  m4_define([$2], [$1]) dnl
+  _MYSQL_PLUGAPPEND([__mysql_plugin_list__],[$1]) dnl
+  AC_DEFUN([MYSQL_MODULE_NAME_]AS_TR_CPP([$1]), [$3]) dnl
+  AC_DEFUN([MYSQL_MODULE_DESC_]AS_TR_CPP([$1]), [$4]) dnl
+  ifelse([$5], [], [], [ dnl
+   _MYSQL_PLUGAPPEND_OPTS([$1], $5) dnl
+  ]) dnl
+ ]) dnl
+])
+
+
+dnl ---------------------------------------------------------------------------
+dnl Macro: MYSQL_STORAGE_ENGINE
+dnl
+dnl What it does:
+dnl   Short cut for storage engine declarations
+dnl
+dnl ---------------------------------------------------------------------------
+
+AC_DEFUN([MYSQL_STORAGE_ENGINE],[ dnl
+ MYSQL_MODULE([$1], [$3], [$4], [[$5]]) dnl
+ MYSQL_MODULE_DEFINE([$1], [WITH_]AS_TR_CPP([$1])[_STORAGE_ENGINE]) dnl
+ ifelse([$2],[no],[],[ dnl
+  _MYSQL_LEGACY_STORAGE_ENGINE([$1],m4_default([$2], [$1-storage-engine])) dnl
+ ]) dnl
+])
+
+AC_DEFUN([_MYSQL_LEGACY_STORAGE_ENGINE],[
+if test "[${with_]m4_bpatsubst($2, -, _)[+set}]" = set; then
+  [with_module_]m4_bpatsubst($1, -, _)="[$with_]m4_bpatsubst($2, -, _)"
+fi dnl
+])
+
+
+dnl ---------------------------------------------------------------------------
+dnl Macro: MYSQL_MODULE_DEFINE
+dnl
+dnl What it does:
+dnl   When a plugin module is to be statically linked, define the C macro
+dnl
+dnl ---------------------------------------------------------------------------
+
+AC_DEFUN([MYSQL_MODULE_DEFINE],[ dnl
+ REQUIRE_PLUGIN([$1]) dnl
+ AC_DEFUN([MYSQL_MODULE_DEFINE_]AS_TR_CPP([$1]), [$2]) dnl
+])
+
+
+dnl ---------------------------------------------------------------------------
+dnl Macro: MYSQL_MODULE_DIRECTORY
+dnl
+dnl What it does:
+dnl   Adds a directory to the build process
+dnl
+dnl ---------------------------------------------------------------------------
+
+AC_DEFUN([MYSQL_MODULE_DIRECTORY],[ dnl
+ REQUIRE_PLUGIN([$1]) dnl
+ AC_DEFUN([MYSQL_MODULE_DIRECTORY_]AS_TR_CPP([$1]), [$2]) dnl
+])
+
+
+dnl ---------------------------------------------------------------------------
+dnl Macro: MYSQL_MODULE_STATIC
+dnl
+dnl What it does:
+dnl   Declare the name for the static library 
+dnl
+dnl ---------------------------------------------------------------------------
+
+AC_DEFUN([MYSQL_MODULE_STATIC],[ dnl
+ REQUIRE_PLUGIN([$1]) dnl
+ AC_DEFUN([MYSQL_MODULE_STATIC_]AS_TR_CPP([$1]), [$2]) dnl
+])
+
+
+dnl ---------------------------------------------------------------------------
+dnl Macro: MYSQL_MODULE_DYNAMIC
+dnl
+dnl What it does:
+dnl   Declare the name for the shared library
+dnl
+dnl ---------------------------------------------------------------------------
+
+AC_DEFUN([MYSQL_MODULE_DYNAMIC],[ dnl
+ REQUIRE_PLUGIN([$1]) dnl
+ AC_DEFUN([MYSQL_MODULE_DYNAMIC_]AS_TR_CPP([$1]), [$2]) dnl
+])
+
+
+dnl ---------------------------------------------------------------------------
+dnl Macro: MYSQL_MODULE_MANDATORY
+dnl
+dnl What it does:
+dnl   Marks the specified plugin as a mandatory module
+dnl
+dnl ---------------------------------------------------------------------------
+
+AC_DEFUN([MYSQL_MODULE_MANDATORY],[ dnl
+ REQUIRE_PLUGIN([$1]) dnl
+ _MYSQL_MODULE_MANDATORY([$1],
+  [MYSQL_MODULE_MANDATORY_]AS_TR_CPP([$1]),
+  [MYSQL_MODULE_DISABLED_]AS_TR_CPP([$1])
+ ) dnl
+])
+
+AC_DEFUN([_MYSQL_MODULE_MANDATORY],[ dnl
+ m4_define([$2], [yes]) dnl
+ m4_ifdef([$3], [ dnl
+  AC_WARNING([syntax],[Mandatory plugin $1 has been disabled]) dnl
+  m4_undefine([$2]) dnl
+ ]) dnl
+])
+
+
+dnl ---------------------------------------------------------------------------
+dnl Macro: MYSQL_MODULE_DISABLED
+dnl
+dnl What it does:
+dnl   Marks the specified plugin as a disabled module
+dnl
+dnl ---------------------------------------------------------------------------
+
+AC_DEFUN([MYSQL_MODULE_DISABLED],[ dnl
+ REQUIRE_PLUGIN([$1]) dnl
+ _MYSQL_MODULE_DISABLED([$1], 
+  [MYSQL_MODULE_DISABLED_]AS_TR_CPP([$1]),
+  [MYSQL_MODULE_MANDATORY_]AS_TR_CPP([$1])
+ ) dnl
+])
+
+AC_DEFUN([_MYSQL_MODULE_DISABLED],[ dnl
+ m4_define([$2], [yes]) dnl
+ m4_ifdef([$3], [ dnl
+  AC_FATAL([attempt to disable mandatory plugin $1]) dnl
+  m4_undefine([$2]) dnl
+ ]) dnl
+])
+
+
+dnl ---------------------------------------------------------------------------
+dnl Macro: MYSQL_MODULE_DEPENDS
+dnl
+dnl What it does:
+dnl   Enables other modules neccessary for this module
+dnl   Dependency checking is not recursive so if any 
+dnl   required module requires further modules, list them
+dnl   here too!
+dnl
+dnl ---------------------------------------------------------------------------
+
+AC_DEFUN([MYSQL_MODULE_DEPENDS],[ dnl
+ REQUIRE_PLUGIN([$1]) dnl
+ ifelse($#, 0, [], $#, 1, [ dnl
+  AC_FATAL([[bad number of arguments]]) dnl
+ ], $#, 2, [ dnl
+  _MYSQL_MODULE_DEPEND([$1],[$2]) dnl
+ ],[ dnl
+  _MYSQL_MODULE_DEPEND([$1],[$2]) dnl
+  MYSQL_MODULE_DEPENDS([$1], m4_shift(m4_shift($@))) dnl
+ ])
+])
+
+AC_DEFUN([_MYSQL_MODULE_DEPEND],[ dnl
+ REQUIRE_PLUGIN([$2]) dnl
+ _MYSQL_PLUGAPPEND([__mysql_plugdepends_$1__],[$2]) dnl
+])
+
+
+dnl ---------------------------------------------------------------------------
+dnl Macro: MYSQL_MODULE_ACTIONS
+dnl
+dnl What it does:
+dnl   Declares additional actions required to configure the module
+dnl
+dnl ---------------------------------------------------------------------------
+
+AC_DEFUN([MYSQL_MODULE_ACTIONS],[ dnl
+ REQUIRE_PLUGIN([$1]) dnl
+ m4_ifdef([$2],[ dnl
+   m4_define([MYSQL_MODULE_ACTIONS_]AS_TR_CPP([$1]),m4_defn([$2])) dnl
+ ],[ dnl
+   AC_DEFUN([MYSQL_MODULE_ACTIONS_]AS_TR_CPP([$1]), [$2]) dnl
+ ])
+])
+
+
+dnl ---------------------------------------------------------------------------
+dnl Macro: MYSQL_CONFIGURE_PLUGINS
+dnl
+dnl What it does:
+dnl   Called last, emits all required shell code to configure the modules
+dnl
+dnl ---------------------------------------------------------------------------
+
+AC_DEFUN([MYSQL_CONFIGURE_PLUGINS],[ dnl
+ m4_ifdef([__mysql_plugin_configured__],[ dnl
+   AC_FATAL([cannot call [MYSQL_CONFIGURE_PLUGINS] multiple times]) dnl
+ ],[ dnl
+   m4_define([__mysql_plugin_configured__],[done]) dnl
+   m4_ifdef([__mysql_plugin_list__],[ dnl
+    _MYSQL_CHECK_PLUGIN_ARGS([none])
+    _MYSQL_CONFIGURE_PLUGINS(m4_bpatsubst(__mysql_plugin_list__, :, [,]))
+   ]) dnl
+ ]) dnl
+])
+
+AC_DEFUN([_MYSQL_CONFIGURE_PLUGINS],[ dnl
+ ifelse($#, 0, [], $#, 1, [ dnl
+  _MYSQL_CHECK_PLUGIN([$1]) dnl
+ ],[ dnl
+  _MYSQL_CHECK_PLUGIN([$1]) dnl
+  _MYSQL_CONFIGURE_PLUGINS(m4_shift($@)) dnl
+ ])
+])
+
+AC_DEFUN([_MYSQL_CHECK_PLUGIN],[ dnl
+ _DO_MYSQL_CHECK_PLUGIN(
+  [$1],
+  [$1-plugin],
+  [MYSQL_MODULE_NAME_]AS_TR_CPP([$1]),
+  [MYSQL_MODULE_DESC_]AS_TR_CPP([$1]),
+  [MYSQL_MODULE_DEFINE_]AS_TR_CPP([$1]),
+  [MYSQL_MODULE_DIRECTORY_]AS_TR_CPP([$1]),
+  [MYSQL_MODULE_STATIC_]AS_TR_CPP([$1]),
+  [MYSQL_MODULE_DYNAMIC_]AS_TR_CPP([$1]),
+  [MYSQL_MODULE_MANDATORY_]AS_TR_CPP([$1]),
+  [MYSQL_MODULE_DISABLED_]AS_TR_CPP([$1]),
+  [MYSQL_MODULE_ACTIONS_]AS_TR_CPP([$1])
+ ) dnl
+])
+
+AC_DEFUN([_DO_MYSQL_CHECK_PLUGIN],[ dnl
+ m4_ifdef([$5],[ dnl
+  AH_TEMPLATE($5, [Include ]$4[ into mysqld])
+ ])
+ AC_MSG_CHECKING([whether to use ]$3) dnl
+ m4_ifdef([$10],[
+  if test "[$mysql_module_]m4_bpatsubst([$1], -, _)" == "yes" -a \
+          "[$with_module_]m4_bpatsubst([$1], -, _)" != "no" -o \
+          "[$with_module_]m4_bpatsubst([$1], -, _)" == "yes"; then
+    AC_MSG_ERROR([disabled])
+  fi
+  AC_MSG_RESULT([no]) dnl
+ ],[ dnl
+  m4_ifdef([$9],[
+   if test "[$with_module_]m4_bpatsubst([$1], -, _)" == "no"; then
+     AC_MSG_ERROR([cannot disable mandatory module])
+   fi
+   [mysql_module_]m4_bpatsubst([$1], -, _)="yes" dnl
+  ])
+  if test "[$with_module_]m4_bpatsubst([$1], -, _)" != "no"; then
+    if test "[$mysql_module_]m4_bpatsubst([$1], -, _)" != "yes" -a \
+            "[$with_module_]m4_bpatsubst([$1], -, _)" != "yes"; then dnl
+      m4_ifdef([$8],[ dnl
+       m4_ifdef([$6],[
+        mysql_plugin_dirs="$mysql_plugin_dirs $6" dnl
+       ])
+       AC_SUBST([plugin_]m4_bpatsubst([$1], -, _)[_shared_target], "$8")
+       AC_SUBST([plugin_]m4_bpatsubst([$1], -, _)[_static_target], [""])
+       [with_module_]m4_bpatsubst([$1], -, _)="yes" dnl
+      ],[
+       AC_MSG_RESULT([cannot build dynamically])
+       [with_module_]m4_bpatsubst([$1], -, _)="no" dnl
+      ])
+    else dnl
+      m4_ifdef([$7],[
+       ifelse(m4_bregexp($7, [^lib[^.]+\.a$]), -2, [ dnl
+        m4_ifdef([$6],[
+         mysql_plugin_dirs="$mysql_plugin_dirs $6"
+         mysql_plugin_libs="$mysql_plugin_libs -L[\$(top_builddir)]/$6" dnl
+        ])
+        mysql_plugin_libs="$mysql_plugin_libs dnl
+[-l]m4_bregexp($7, [^lib\([^.]+\)], [\1])" dnl
+       ], m4_bregexp($7, [^\\\$]), 0, [ dnl
+        m4_ifdef([$6],[
+         mysql_plugin_dirs="$mysql_plugin_dirs $6" dnl
+        ])
+        mysql_plugin_libs="$mysql_plugin_libs $7" dnl
+       ], [ dnl
+        m4_ifdef([$6],[
+         mysql_plugin_dirs="$mysql_plugin_dirs $6"
+         mysql_plugin_libs="$mysql_plugin_libs \$(top_builddir)/$6/$7" dnl
+        ],[
+         mysql_plugin_libs="$mysql_plugin_libs $7" dnl
+        ]) dnl
+       ]) dnl
+       m4_ifdef([$5],[
+        AC_DEFINE($5) dnl
+       ])
+       AC_SUBST([plugin_]m4_bpatsubst([$1], -, _)[_static_target], "$7")
+       AC_SUBST([plugin_]m4_bpatsubst([$1], -, _)[_shared_target], [""]) dnl
+      ],[ dnl
+       m4_ifdef([$6],[
+        AC_FATAL([plugin directory specified without library for ]$3) dnl
+       ],[ dnl
+        m4_ifdef([$5],[
+         AC_DEFINE($5)
+         AC_SUBST([plugin_]m4_bpatsubst([$1], -, _)[_static_target], ["yes"])
+         AC_SUBST([plugin_]m4_bpatsubst([$1], -, _)[_shared_target], [""]) dnl
+        ]) dnl
+       ]) dnl
+      ])
+      mysql_plugin_defs="$mysql_plugin_defs, [builtin_]m4_bpatsubst([$2], -, _)"
+      [with_module_]m4_bpatsubst([$1], -, _)="yes"
+    fi
+  else
+    AC_MSG_RESULT([no])
+  fi
+
+  if test "[$with_module_]m4_bpatsubst([$1], -, _)" == "yes"; then
+    if test "[$plugin_]m4_bpatsubst([$1], -, _)[_static_target]" != ""; then
+      AC_MSG_RESULT([static])
+    elif test "[$plugin_]m4_bpatsubst([$1], -, _)[_shared_target]" != ""; then
+      AC_MSG_RESULT([plugin])
+    else
+      AC_MSG_ERROR([thats strange])
+    fi
+    $11
+  fi dnl
+ ]) dnl
+])
+
+
+
+dnl ===========================================================================
+dnl  Private helper macros
+dnl ===========================================================================
+
+
+AC_DEFUN([REQUIRE_PLUGIN],[ dnl
+ _REQUIRE_PLUGIN([$1], [__MYSQL_MODULE_]AS_TR_CPP([$1])[__]) dnl
+])
+
+define([_REQUIRE_PLUGIN],[ dnl
+ ifdef([$2],[ dnl
+  ifelse($2, [$1], [], [ dnl
+   AC_FATAL([[Misspelt MYSQL_MODULE declaration for ]][$1]) dnl
+  ]) dnl
+ ],[ dnl
+  AC_FATAL([[Missing MYSQL_MODULE declaration for ]][$1]) dnl
+ ])
+])
+
+
+dnl ---------------------------------------------------------------------------
+
+
+AC_DEFUN([_MYSQL_MODULE_META_CHECK], [ifelse($#, 0, [], $#, 1, dnl
+[_MYSQL_CHECK_PLUGIN_META([$1], [__mysql_]m4_bpatsubst($1, -, _)[_plugins__]) dnl
+], dnl
+[_MYSQL_CHECK_PLUGIN_META([$1], [__mysql_]m4_bpatsubst($1, -, _)[_plugins__]) dnl
+_MYSQL_MODULE_META_CHECK(m4_shift($@))]) dnl
+])
+
+AC_DEFUN([_MYSQL_CHECK_PLUGIN_META], [
+  elif test "$mysql_modules" == "[$1]"; then dnl
+m4_ifdef([$2], [
+    mysql_modules="m4_bpatsubst($2, :, [,])" dnl
+],[
+    mysql_modules="" dnl
+]) dnl
+])
+
+
+dnl ---------------------------------------------------------------------------
+
+
+AC_DEFUN([_MYSQL_PLUGAPPEND],[ dnl
+ m4_ifdef([$1],[ dnl
+  m4_define([__plugin_append_tmp__], m4_defn([$1])) dnl
+  m4_undefine([$1]) dnl
+  m4_define([$1], __plugin_append_tmp__[:$2]) dnl
+  m4_undefine([__plugin_append_tmp__]) dnl
+ ],[ dnl
+  m4_define([$1], [$2]) dnl
+  $3
+ ]) dnl
+])
+
+AC_DEFUN([_MYSQL_PLUGAPPEND_OPTS],[ dnl
+ ifelse($#, 0, [], $#, 1, [ dnl
+  AC_FATAL([[bad number of args]])
+ ], $#, 2, [ dnl
+  _MYSQL_PLUGAPPEND_OPTONE([$1],[$2]) dnl
+ ],[ dnl
+  _MYSQL_PLUGAPPEND_OPTONE([$1],[$2]) dnl
+  _MYSQL_PLUGAPPEND_OPTS([$1], m4_shift(m4_shift($@)))
+ ])
+])
+
+AC_DEFUN([_MYSQL_PLUGAPPEND_OPTONE],[ dnl
+ ifelse([$2], [all], [ dnl
+  AC_FATAL([[protected plugin group: all]]) dnl
+ ],[ dnl
+  ifelse([$2], [none], [ dnl
+   AC_FATAL([[protected plugin group: none]]) dnl
+  ],[ dnl
+   _MYSQL_PLUGAPPEND([__mysql_$1_configs__],[$2]) dnl
+   _MYSQL_PLUGAPPEND([__mysql_]m4_bpatsubst($2, -, _)[_plugins__],[$1], [ dnl
+    _MYSQL_PLUGAPPEND([__mysql_metaplugin_list__],[$2]) dnl
+   ]) dnl
+  ]) dnl
+ ]) dnl
+])
+
+
+dnl ---------------------------------------------------------------------------
+
+
+AC_DEFUN([MYSQL_LIST_PLUGINS],[ dnl
+ m4_ifdef([__mysql_plugin_list__],[ dnl
+  _MYSQL_LIST_PLUGINS(m4_bpatsubst(__mysql_plugin_list__, :, [,])) dnl
+ ]) dnl
+])
+
+AC_DEFUN([_MYSQL_LIST_PLUGINS],[ dnl
+ ifelse($#, 0, [], $#, 1, [ dnl
+  MYSQL_SHOW_PLUGIN([$1]) dnl
+ ],[ dnl
+  MYSQL_SHOW_PLUGIN([$1]) dnl
+  _MYSQL_LIST_PLUGINS(m4_shift($@)) dnl
+ ]) dnl
+])
+
+AC_DEFUN([MYSQL_SHOW_PLUGIN],[ dnl
+ _MYSQL_SHOW_PLUGIN(
+  [$1],
+  [$1-plugin],
+  [MYSQL_MODULE_NAME_]AS_TR_CPP([$1]),
+  [MYSQL_MODULE_DESC_]AS_TR_CPP([$1]),
+  [MYSQL_MODULE_DEFINE_]AS_TR_CPP([$1]),
+  [MYSQL_MODULE_DIRECTORY_]AS_TR_CPP([$1]),
+  [MYSQL_MODULE_STATIC_]AS_TR_CPP([$1]),
+  [MYSQL_MODULE_DYNAMIC_]AS_TR_CPP([$1]),
+  [MYSQL_MODULE_MANDATORY_]AS_TR_CPP([$1]),
+  [MYSQL_MODULE_DISABLED_]AS_TR_CPP([$1]),
+  [MYSQL_MODULE_ACTIONS_]AS_TR_CPP([$1]),
+  __mysql_[$1]_configs__,
+ )
+])
+
+AC_DEFUN([_MYSQL_SHOW_PLUGIN],[
+  === Plug-in: $3 ===
+  Module Name:      [$1]
+  Description:      $4
+  Supports build:   _PLUGIN_BUILD_TYPE([$7],[$8]) dnl
+m4_ifdef([$12],[
+  Configurations:   m4_bpatsubst($12, :, [, ])]) dnl
+m4_ifdef([$10],[
+  Status:           disabled], [ dnl
+m4_ifdef([$9],[
+  Status:           mandatory])])])
+
+AC_DEFUN([_PLUGIN_BUILD_TYPE], dnl
+[m4_ifdef([$1],[ifelse($1,[no],[],[static ]m4_ifdef([$2],[and dnl
+]))])[]m4_ifdef([$2],[dynamic],[m4_ifdef([$1],[],[static])])])
+
+
+dnl ---------------------------------------------------------------------------
+
+
+AC_DEFUN([_MYSQL_MODULE_ARGS_CHECK],[ dnl
+ ifelse($#, 0, [], $#, 1, [ dnl
+  _MYSQL_CHECK_PLUGIN_ARG([$1],
+   [MYSQL_MODULE_DISABLED_]AS_TR_CPP([$1]),
+   [MYSQL_MODULE_ACTIONS_]AS_TR_CPP([$1])) dnl
+ ],[ dnl
+  _MYSQL_CHECK_PLUGIN_ARG([$1],
+   [MYSQL_MODULE_DISABLED_]AS_TR_CPP([$1]),
+   [MYSQL_MODULE_ACTIONS_]AS_TR_CPP([$1])) dnl
+  _MYSQL_MODULE_ARGS_CHECK(m4_shift($@)) dnl
+ ]) dnl
+])
+
+AC_DEFUN([_MYSQL_CHECK_PLUGIN_ARG],[ dnl
+m4_ifdef([$3], [], [AC_DEFUN([$3],[ ])])
+    elif test "$plugin" == "[$1]"; then dnl
+m4_ifdef([$2],[
+      AC_MSG_ERROR([plugin $1 is disabled]) dnl
+],[
+      [mysql_module_]m4_bpatsubst([$1], -, _)="yes" dnl
+]) dnl
+])
+
+AC_DEFUN([_MYSQL_CHECK_DEPENDENCIES], [ dnl
+ ifelse($#, 0, [], $#, 1, [ dnl
+  _MYSQL_CHECK_DEPENDS([$1],[__mysql_plugdepends_$1__]) dnl
+ ],[ dnl
+  _MYSQL_CHECK_DEPENDS([$1],[__mysql_plugdepends_$1__]) dnl
+  _MYSQL_CHECK_DEPENDENCIES(m4_shift($@)) dnl
+ ]) dnl
+])
+
+AC_DEFUN([_MYSQL_CHECK_DEPENDS], [ dnl
+ m4_ifdef([$2], [
+   if test "[$mysql_module_]m4_bpatsubst([$1], -, _)" == "yes" -a \
+           "[$with_module_]m4_bpatsubst([$1], -, _)" != "no" -o \
+           "[$with_module_]m4_bpatsubst([$1], -, _)" == "yes"; then dnl
+     _MYSQL_GEN_DEPENDS(m4_bpatsubst($2, :, [,]))
+   fi
+ ]) dnl
+])
+
+AC_DEFUN([_MYSQL_GEN_DEPENDS], [ dnl
+ ifelse($#, 0, [], $#, 1, [
+      [mysql_module_]m4_bpatsubst([$1], -, _)="yes"
+      if test "[$with_module_]m4_bpatsubst([$1], -, _)" == "no"; then
+        AC_MSG_ERROR([depends upon disabled module $1])
+      fi dnl
+ ],[
+      [mysql_module_]m4_bpatsubst([$1], -, _)="yes"
+      if test "[$with_module_]m4_bpatsubst([$1], -, _)" == "no"; then
+        AC_MSG_ERROR([depends upon disabled module $1])
+      fi dnl
+  _MYSQL_GEN_DEPENDS(m4_shift($@)) dnl
+ ]) dnl
+])
+  
+
+AC_DEFUN([_MYSQL_CHECK_PLUGIN_ARGS],[
+
+ AC_ARG_WITH([modules], [
+   --with-modules=PLUGIN[[,PLUGIN..]]
+m4_text_wrap([Plugin modules to include in mysqld. (default is: $1)
+Must be configuration name or a comma seperated list of modules.],
+[                          ])
+m4_text_wrap([Available configurations are: ]
+m4_bpatsubst(m4_ifdef([__mysql_metaplugin_list__], dnl
+none:all:__mysql_metaplugin_list__,none:all), :, [ ])[.],
+[                          ])
+m4_text_wrap([Available plugin modules are: ] dnl
+m4_bpatsubst(__mysql_plugin_list__, :, [ ])[.], [                          ])
+  --without-module-PLUGIN
+m4_text_wrap([Disable the named module from being built. Otherwise, 
+for modules which are not selected for inclusion in mysqld will be 
+built dynamically (if supported)],[                          ])],
+[mysql_modules="$withval"], [mysql_modules=['$1']])
+
+m4_divert_once([HELP_VAR_END],[
+Description of plugin modules:
+m4_indir([MYSQL_LIST_PLUGINS])
+])
+
+  if test "$mysql_modules" == "all"; then
+    mysql_modules="m4_bpatsubst(__mysql_plugin_list__, :, [,])"
+  elif test "$mysql_modules" == "none"; then
+    mysql_modules="" dnl
+m4_ifdef([__mysql_metaplugin_list__],[ dnl
+_MYSQL_MODULE_META_CHECK(m4_bpatsubst(__mysql_metaplugin_list__, :, [,])) dnl
+])
+  fi
+
+  for plugin in `echo $mysql_modules | tr ",.:;" "    "`; do
+    if test "$plugin" == "all" -o "$plugin" == "none"; then
+      AC_MSG_ERROR([bad module name: $plugin]) dnl
+_MYSQL_MODULE_ARGS_CHECK(m4_bpatsubst(__mysql_plugin_list__, :, [,]))
+    else
+      AC_MSG_ERROR([unknown plugin module: $plugin])
+    fi
+  done
+  
+  _MYSQL_CHECK_DEPENDENCIES(m4_bpatsubst(__mysql_plugin_list__, :, [,]))
+])
+
+
+dnl ===========================================================================
diff --git a/config/ac-macros/storage.m4 b/config/ac-macros/storage.m4
deleted file mode 100644
index 4148aed818d..00000000000
--- a/config/ac-macros/storage.m4
+++ /dev/null
@@ -1,55 +0,0 @@
-dnl ---------------------------------------------------------------------------
-dnl Macro: MYSQL_STORAGE_ENGINE
-dnl
-dnl What it does:
-dnl   creates --with-xxx configure option
-dnl   adds HAVE_XXX to config.h
-dnl   appends &xxx_hton, to the list of hanldertons
-dnl   appends a dir to the list of source directories
-dnl   appends ha_xxx.cc to the list of handler files
-dnl
-dnl  all names above are configurable with reasonable defaults.
-dnl
-dnl ---------------------------------------------------------------------------
-
-AC_DEFUN([MYSQL_STORAGE_ENGINE],
-[_MYSQL_STORAGE_ENGINE(
-[$1],                                dnl name
-m4_default([$2], [$1 storage engine]),    dnl verbose name
-m4_default([$3], [$1-storage-engine]),    dnl with-name
-m4_default([$4], no),                     dnl default
-m4_default([$5], [WITH_]AS_TR_CPP([$1])[_STORAGE_ENGINE]),
-m4_default([$6], $1[_hton]),              dnl hton
-m4_default([$7], []),                     dnl path to the code
-m4_default([$8], [ha_$1.o]),             dnl path to the handler in
-m4_default([$9], []),                    dnl path to extra libraries
-[$10],                                     dnl code-if-set
-)])
-
-AC_DEFUN([_MYSQL_STORAGE_ENGINE],
-[
-AC_ARG_WITH([$3], AS_HELP_STRING([--with-$3], [enable $2 (default is $4)]),
-[], [ [with_]m4_bpatsubst([$3], -, _)=['$4']])
-AC_CACHE_CHECK([whether to use $2], [mysql_cv_use_]m4_bpatsubst([$3], -, _),
-[mysql_cv_use_]m4_bpatsubst([$3], -, _)=[$with_]m4_bpatsubst([$3], -, _))
-AH_TEMPLATE([$5], [Build $2])
-if test "[$mysql_cv_use_]m4_bpatsubst([$3], -, _)" != no; then
-if test "$6" != "no"
-then
-  AC_DEFINE([$5])
-  mysql_se_decls="${mysql_se_decls},$6"
-  mysql_se_htons="${mysql_se_htons},&$6"
-  if test "$8" != "no"
-  then
-    mysql_se_objs="$mysql_se_objs $8"
-  fi
-  mysql_se_dirs="$mysql_se_dirs $7"
-  mysql_se_libs="$mysql_se_libs $9"
-else
-  mysql_se_plugins="$mysql_se_plugins $7"
-fi
-$10
-fi
-])
-
-dnl ---------------------------------------------------------------------------
diff --git a/configure.in b/configure.in
index e2c94060ae7..70d36ee84f5 100644
--- a/configure.in
+++ b/configure.in
@@ -31,7 +31,7 @@ sinclude(config/ac-macros/alloca.m4)
 sinclude(config/ac-macros/check_cpu.m4)
 sinclude(config/ac-macros/character_sets.m4)
 sinclude(config/ac-macros/compiler_flag.m4)
-sinclude(config/ac-macros/storage.m4)
+sinclude(config/ac-macros/plugins.m4)
 sinclude(config/ac-macros/ha_berkeley.m4)
 sinclude(config/ac-macros/ha_ndbcluster.m4)
 sinclude(config/ac-macros/large_file.m4)
@@ -48,6 +48,92 @@ czech danish dutch english estonian french german greek hungarian \
 italian japanese korean norwegian norwegian-ny polish portuguese \
 romanian russian serbian slovak spanish swedish ukrainian"
 
+#--------------------------------------------------------------------
+# Declare our plugin modules
+#--------------------------------------------------------------------
+
+MYSQL_STORAGE_ENGINE(archive,,  [Archive Storage Engine],
+        [Archive Storage Engine], [max,max-no-ndb])
+MYSQL_MODULE_DIRECTORY(archive, [storage/archive])
+MYSQL_MODULE_STATIC(archive,    [libarchive.a])
+MYSQL_MODULE_DYNAMIC(archive,   [ha_archive.la])
+
+MYSQL_STORAGE_ENGINE(berkeley,  berkeley-db, [BerkeleyDB Storage Engine],
+        [Transactional Tables using BerkeleyDB], [max,max-no-ndb])
+MYSQL_MODULE_DIRECTORY(berkeley,[storage/bdb])
+MYSQL_MODULE_STATIC(berkeley,   [[\$(bdb_libs_with_path)]])
+MYSQL_MODULE_ACTIONS(berkeley,  [MYSQL_SETUP_BERKELEY_DB])
+
+MYSQL_STORAGE_ENGINE(blackhole,,[Blackhole Storage Engine],
+        [Basic Write-only Read-never tables], [max,max-no-ndb])
+MYSQL_MODULE_DIRECTORY(blackhole, [storage/blackhole])
+MYSQL_MODULE_STATIC(blackhole,  [libblackhole.a])
+MYSQL_MODULE_DYNAMIC(blackhole, [ha_blackhole.la])
+
+MYSQL_STORAGE_ENGINE(csv,,      [CSV Storage Engine],
+        [Stores tables in text CSV format])
+MYSQL_MODULE_DIRECTORY(csv,     [storage/csv])
+MYSQL_MODULE_STATIC(csv,        [libcsv.a])
+
+MYSQL_STORAGE_ENGINE(example,,  [Example Storage Engine],
+        [Skeleton for Storage Engines for developers], [max,max-no-ndb])
+MYSQL_MODULE_DIRECTORY(example, [storage/example])
+MYSQL_MODULE_STATIC(example,    [libexample.a])
+MYSQL_MODULE_DYNAMIC(example,   [ha_example.la])
+
+MYSQL_STORAGE_ENGINE(federated,,[Federated Storage Engine],
+        [Connects to tables on remote MySQL servers], [max,max-no-ndb])
+
+MYSQL_MODULE(ftexample,         [Simple Parser],
+        [Simple full-text parser plugin])
+MYSQL_MODULE_DIRECTORY(ftexample, [plugin/fulltext])
+MYSQL_MODULE_STATIC(ftexample,  [libftexample.a])
+MYSQL_MODULE_DYNAMIC(ftexample, [ft_example.la])
+
+MYSQL_STORAGE_ENGINE(heap,no,   [Memory Storage Engine],
+        [In memory hashed tables])
+MYSQL_MODULE_DIRECTORY(heap,    [storage/heap])
+MYSQL_MODULE_STATIC(heap,       [libheap.a])
+
+MYSQL_STORAGE_ENGINE(innobase,  innodb, [InnoDB Storage Engine],
+        [Transactional Tables using InnoDB], [max,max-no-ndb])
+MYSQL_MODULE_DIRECTORY(innobase, [storage/innobase])
+MYSQL_MODULE_STATIC(innobase,   [libinnobase.a])
+MYSQL_MODULE_ACTIONS(innobase,  [
+  AC_CHECK_LIB(rt, aio_read, [innodb_system_libs="-lrt"])
+  AC_SUBST(innodb_includes)
+  AC_SUBST(innodb_libs)
+  AC_SUBST(innodb_system_libs)
+  other_configures="$other_configures storage/innobase/configure"
+])
+
+MYSQL_STORAGE_ENGINE(myisam,no, [MyISAM Storage Engine],
+        [Traditional non-transactional MySQL tables])
+MYSQL_MODULE_DIRECTORY(myisam,  [storage/myisam])
+MYSQL_MODULE_STATIC(myisam,     [libmyisam.a])
+
+MYSQL_STORAGE_ENGINE(myisammrg,no,[MyISAM MERGE Engine],
+        [Merge multiple MySQL tables into one])
+MYSQL_MODULE_DIRECTORY(myisammrg,[storage/myisammrg])
+MYSQL_MODULE_STATIC(myisammrg,  [libmyisammrg.a])
+
+MYSQL_STORAGE_ENGINE(ndbcluster, ndbcluster, [Cluster Storage Engine],
+        [High Availability Clustered tables], [max])
+MYSQL_MODULE_DIRECTORY(ndbcluster,[storage/ndb])
+MYSQL_MODULE_STATIC(ndbcluster, [[\$(ndbcluster_libs) \$(ndbcluster_system_libs) \$(NDB_SCI_LIBS)]])
+MYSQL_MODULE_ACTIONS(ndbcluster,[MYSQL_SETUP_NDBCLUSTER])
+
+MYSQL_STORAGE_ENGINE(partition, partition, [Partition Engine],
+        [MySQL Table Partitioning Engine], [max,max-no-ndb])
+
+MYSQL_MODULE_MANDATORY(csv)     dnl Used for logging
+MYSQL_MODULE_MANDATORY(heap)    dnl Memory tables
+MYSQL_MODULE_MANDATORY(myisam)  dnl Default
+MYSQL_MODULE_MANDATORY(myisammrg)
+
+dnl -- ndbcluster requires partition to be enabled
+MYSQL_MODULE_DEPENDS(ndbcluster, partition)
+
 #####
 #####
 
@@ -671,6 +757,16 @@ MYSQL_SYS_LARGEFILE
 # Types that must be checked AFTER large file support is checked
 AC_TYPE_SIZE_T
 
+#--------------------------------------------------------------------
+# Check for requested features
+#--------------------------------------------------------------------
+
+MYSQL_CHECK_BIG_TABLES
+MYSQL_CHECK_MAX_INDEXES
+MYSQL_CHECK_REPLICATION
+
+MYSQL_CONFIGURE_PLUGINS([none])
+
 #--------------------------------------------------------------------
 # Check for system header files
 #--------------------------------------------------------------------
@@ -2416,74 +2512,6 @@ AC_SUBST(readline_basedir)
 AC_SUBST(readline_link)
 AC_SUBST(readline_h_ln_cmd)
 
-MYSQL_CHECK_BIG_TABLES
-MYSQL_CHECK_MAX_INDEXES
-MYSQL_CHECK_REPLICATION
-
-MYSQL_STORAGE_ENGINE(innobase,,innodb,,,,storage/innobase,ha_innodb.o,[ dnl
-  \$(top_builddir)/storage/innobase/usr/libusr.a dnl
-  \$(top_builddir)/storage/innobase/srv/libsrv.a dnl
-  \$(top_builddir)/storage/innobase/dict/libdict.a dnl
-  \$(top_builddir)/storage/innobase/que/libque.a dnl
-  \$(top_builddir)/storage/innobase/srv/libsrv.a dnl
-  \$(top_builddir)/storage/innobase/ibuf/libibuf.a dnl
-  \$(top_builddir)/storage/innobase/row/librow.a dnl
-  \$(top_builddir)/storage/innobase/pars/libpars.a dnl
-  \$(top_builddir)/storage/innobase/btr/libbtr.a dnl
-  \$(top_builddir)/storage/innobase/trx/libtrx.a dnl
-  \$(top_builddir)/storage/innobase/read/libread.a dnl
-  \$(top_builddir)/storage/innobase/usr/libusr.a dnl
-  \$(top_builddir)/storage/innobase/buf/libbuf.a dnl
-  \$(top_builddir)/storage/innobase/ibuf/libibuf.a dnl
-  \$(top_builddir)/storage/innobase/eval/libeval.a dnl
-  \$(top_builddir)/storage/innobase/log/liblog.a dnl
-  \$(top_builddir)/storage/innobase/fsp/libfsp.a dnl
-  \$(top_builddir)/storage/innobase/fut/libfut.a dnl
-  \$(top_builddir)/storage/innobase/fil/libfil.a dnl
-  \$(top_builddir)/storage/innobase/lock/liblock.a dnl
-  \$(top_builddir)/storage/innobase/mtr/libmtr.a dnl
-  \$(top_builddir)/storage/innobase/page/libpage.a dnl
-  \$(top_builddir)/storage/innobase/rem/librem.a dnl
-  \$(top_builddir)/storage/innobase/thr/libthr.a dnl
-  \$(top_builddir)/storage/innobase/sync/libsync.a dnl
-  \$(top_builddir)/storage/innobase/data/libdata.a dnl
-  \$(top_builddir)/storage/innobase/mach/libmach.a dnl
-  \$(top_builddir)/storage/innobase/ha/libha.a dnl
-  \$(top_builddir)/storage/innobase/dyn/libdyn.a dnl
-  \$(top_builddir)/storage/innobase/mem/libmem.a dnl
-  \$(top_builddir)/storage/innobase/sync/libsync.a dnl
-  \$(top_builddir)/storage/innobase/ut/libut.a dnl
-  \$(top_builddir)/storage/innobase/os/libos.a dnl
-  \$(top_builddir)/storage/innobase/ut/libut.a],[
-  AC_CHECK_LIB(rt, aio_read, [innodb_system_libs="-lrt"])
-  AC_SUBST(innodb_includes)
-  AC_SUBST(innodb_libs)
-  AC_SUBST(innodb_system_libs)
-  other_configures="$other_configures storage/innobase/configure"
-])
-
-MYSQL_STORAGE_ENGINE(berkeley,,berkeley-db,,,,storage/bdb,,,[
-  MYSQL_SETUP_BERKELEY_DB
-])
-MYSQL_STORAGE_ENGINE(example,,,,,,storage/example,no,
- \$(top_builddir)/storage/example/libexample.a,[
-  AC_CONFIG_FILES(storage/example/Makefile)
-])
-MYSQL_STORAGE_ENGINE(archive,,,,,,storage/archive,,
- \$(top_builddir)/storage/archive/libarchive.a, [
-  AC_CONFIG_FILES(storage/archive/Makefile)
-])
-MYSQL_STORAGE_ENGINE(csv,,,"yes",,tina_hton,storage/csv,no,
-  \$(top_builddir)/storage/csv/libcsv.a,[
-  AC_CONFIG_FILES(storage/csv/Makefile)
-])
-MYSQL_STORAGE_ENGINE(blackhole)
-MYSQL_STORAGE_ENGINE(federated)
-MYSQL_STORAGE_ENGINE(ndbcluster,,ndbcluster,,,,storage/ndb,,,[
-  MYSQL_SETUP_NDBCLUSTER
-])
-MYSQL_STORAGE_ENGINE(partition,,partition)
-
 # If we have threads generate some library functions and test programs
 sql_server_dirs=
 sql_server=
@@ -2539,7 +2567,6 @@ then
   AC_SUBST(THREAD_LOBJECTS)
   server_scripts="mysqld_safe mysql_install_db"
   sql_server_dirs="strings mysys dbug extra regex"
-  mysql_se_dirs="storage/myisam storage/myisammrg storage/heap $mysql_se_dirs"
   sql_server="$sql_server vio sql"
 fi
 
@@ -2555,12 +2582,9 @@ AC_SUBST(sql_server)
 AC_SUBST(thread_dirs)
 AC_SUBST(server_scripts)
 
-AC_SUBST(mysql_se_dirs)
-AC_SUBST(mysql_se_libs)
-AC_SUBST(mysql_se_objs)
-AC_SUBST(mysql_se_htons)
-AC_SUBST(mysql_se_decls)
-AC_SUBST(mysql_se_plugins)
+AC_SUBST(mysql_plugin_dirs)
+AC_SUBST(mysql_plugin_libs)
+AC_SUBST(mysql_plugin_defs)
 
 
 # Now that sql_client_dirs and sql_server_dirs are stable, determine the union.
@@ -2600,14 +2624,19 @@ done
 
 AC_SUBST(MAKE_BINARY_DISTRIBUTION_OPTIONS)
 
+NDBCLUSTER_CONFIG_FILES
+
 # Output results
 AC_CONFIG_FILES(Makefile extra/Makefile mysys/Makefile dnl
- strings/Makefile regex/Makefile storage/Makefile storage/heap/Makefile dnl
+ strings/Makefile regex/Makefile dnl
+ storage/Makefile dnl
+ storage/archive/Makefile storage/bdb/Makefile storage/blackhole/Makefile dnl
+ storage/csv/Makefile storage/example/Makefile storage/heap/Makefile dnl
  storage/myisam/Makefile storage/myisammrg/Makefile dnl
  man/Makefile BUILD/Makefile vio/Makefile dnl
  libmysql/Makefile client/Makefile dnl
  pstack/Makefile pstack/aout/Makefile sql/Makefile sql/share/Makefile dnl
- sql/handlerton.cc sql-common/Makefile SSL/Makefile dnl
+ sql/sql_builtin.cc sql-common/Makefile SSL/Makefile dnl
  dbug/Makefile scripts/Makefile dnl
  include/Makefile sql-bench/Makefile dnl
  server-tools/Makefile server-tools/instance-manager/Makefile dnl
diff --git a/include/mysql/plugin.h b/include/mysql/plugin.h
index a7b3606061f..2093043744a 100644
--- a/include/mysql/plugin.h
+++ b/include/mysql/plugin.h
@@ -37,10 +37,25 @@
   be a st_mysql_plugin struct for each plugin to be declared.
 */
 
-#define mysql_declare_plugin                                          \
-int _mysql_plugin_interface_version_= MYSQL_PLUGIN_INTERFACE_VERSION; \
-int _mysql_sizeof_struct_st_plugin_= sizeof(struct st_mysql_plugin); \
+
+#ifndef MYSQL_DYNAMIC_PLUGIN
+#define __DECLARE_PLUGIN(NAME, VERSION, PSIZE, DECLS)                         \
+int VERSION= MYSQL_PLUGIN_INTERFACE_VERSION;                                  \
+int PSIZE= sizeof(struct st_mysql_plugin);                                    \
+struct st_mysql_plugin DECLS[]= {
+#else
+#define __DECLARE_PLUGIN(NAME, VERSION, PSIZE, DECLS)                         \
+int _mysql_plugin_interface_version_= MYSQL_PLUGIN_INTERFACE_VERSION;         \
+int _mysql_sizeof_struct_st_plugin_= sizeof(struct st_mysql_plugin);          \
 struct st_mysql_plugin _mysql_plugin_declarations_[]= {
+#endif
+
+#define _DECLARE_PLUGIN(NAME) \
+__DECLARE_PLUGIN(NAME, builtin_ ## NAME ## _plugin_interface_version, \
+                 builtin_ ## NAME ## _sizeof_struct_st_plugin, \
+                 builtin_ ## NAME ## _plugin)
+
+#define mysql_declare_plugin(NAME) _DECLARE_PLUGIN(NAME)
 #define mysql_declare_plugin_end ,{0,0,0,0,0,0,0,0,0}}
 
 /*
diff --git a/libmysqld/Makefile.am b/libmysqld/Makefile.am
index 6e38fb267d9..32cccf2c942 100644
--- a/libmysqld/Makefile.am
+++ b/libmysqld/Makefile.am
@@ -44,7 +44,10 @@ libmysqlsources =	errmsg.c get_password.c libmysql.c client.c pack.c \
 noinst_HEADERS =	embedded_priv.h emb_qcache.h
 
 sqlsources = derror.cc field.cc field_conv.cc strfunc.cc filesort.cc \
-	ha_heap.cc ha_myisam.cc ha_myisammrg.cc handler.cc sql_handler.cc \
+	ha_heap.cc ha_myisam.cc ha_myisammrg.cc \
+	ha_innodb.cc ha_berkeley.cc ha_federated.cc ha_ndbcluster.cc \
+	ha_ndbcluster_binlog.cc ha_partition.cc \
+	handler.cc sql_handler.cc \
 	hostname.cc init.cc password.c \
 	item.cc item_buff.cc item_cmpfunc.cc item_create.cc \
 	item_func.cc item_strfunc.cc item_sum.cc item_timefunc.cc \
@@ -65,17 +68,12 @@ sqlsources = derror.cc field.cc field_conv.cc strfunc.cc filesort.cc \
 	spatial.cc gstream.cc sql_help.cc tztime.cc sql_cursor.cc \
 	sp_head.cc sp_pcontext.cc sp.cc sp_cache.cc sp_rcontext.cc \
 	parse_file.cc sql_view.cc sql_trigger.cc my_decimal.cc \
-        event_executor.cc event.cc event_timed.cc \
-        rpl_filter.cc sql_partition.cc handlerton.cc sql_plugin.cc \
-        sql_tablespace.cc \
-        rpl_injector.cc my_user.c partition_info.cc
+	event_executor.cc event.cc event_timed.cc \
+	rpl_filter.cc sql_partition.cc sql_builtin.cc sql_plugin.cc \
+	sql_tablespace.cc \
+	rpl_injector.cc my_user.c partition_info.cc
 
 libmysqld_int_a_SOURCES= $(libmysqld_sources) $(libmysqlsources) $(sqlsources)
-EXTRA_libmysqld_a_SOURCES =	ha_innodb.cc ha_berkeley.cc ha_archive.cc \
-			ha_blackhole.cc ha_federated.cc ha_ndbcluster.cc \
-			ha_ndbcluster_binlog.cc \
-			ha_partition.cc
-libmysqld_a_DEPENDENCIES= @mysql_se_objs@
 libmysqld_a_SOURCES=
 
 sqlstoragesources =	$(EXTRA_libmysqld_a_SOURCES)
@@ -85,15 +83,11 @@ sql_yacc.cc sql_yacc.h: $(top_srcdir)/sql/sql_yacc.yy
 
 # The following libraries should be included in libmysqld.a
 INC_LIB=	$(top_builddir)/regex/libregex.a \
-		$(top_builddir)/storage/myisam/libmyisam.a \
-		$(top_builddir)/storage/myisammrg/libmyisammrg.a \
-		$(top_builddir)/storage/archive/libarchive.a \
-		$(top_builddir)/storage/heap/libheap.a \
 		$(top_builddir)/mysys/libmysys.a \
 		$(top_builddir)/strings/libmystrings.a \
 		$(top_builddir)/dbug/libdbug.a \
 		$(top_builddir)/vio/libvio.a \
-		@mysql_se_libs@ \
+		@mysql_plugin_libs@ \
 		$(yassl_las)
 
 if HAVE_YASSL
diff --git a/plugin/Makefile.am b/plugin/Makefile.am
index da4ff0a8d5c..2e98d6a3328 100644
--- a/plugin/Makefile.am
+++ b/plugin/Makefile.am
@@ -1 +1,27 @@
-SUBDIRS= fulltext
+# Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult 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; either version 2 of the License, or
+# (at your option) any later version.
+# 
+# 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+# Process this file with automake to create Makefile.in
+
+AUTOMAKE_OPTIONS =	foreign
+
+# These are built from source in the Docs directory
+EXTRA_DIST =		
+SUBDIRS =	
+DIST_SUBDIRS = . fulltext
+
+# Don't update the files from bitkeeper
+%::SCCS/s.%
diff --git a/plugin/fulltext/Makefile.am b/plugin/fulltext/Makefile.am
index 4df5a1dc78a..331db7c98f8 100644
--- a/plugin/fulltext/Makefile.am
+++ b/plugin/fulltext/Makefile.am
@@ -1,9 +1,44 @@
 #Makefile.am example for a plugin
 
-pkglibdir=$(libdir)/mysql
-INCLUDES= -I$(top_builddir)/include -I$(top_srcdir)/include
-noinst_LTLIBRARIES= mypluglib.la
-#pkglib_LTLIBRARIES= mypluglib.la
-mypluglib_la_SOURCES= plugin_example.c
-mypluglib_la_LDFLAGS= -module -rpath $(pkglibdir)
+#MYSQL_MODULE(ftexample,         [Simple Parser],
+#        [Simple full-text parser plugin])
+#MYSQL_MODULE_DIRECTORY(ftexample, [plugin/fulltext])
+#MYSQL_MODULE_STATIC(ftexample,  [libftexample.a])
+#MYSQL_MODULE_DYNAMIC(ftexample, [ft_example.la])
 
+
+#called from the top level Makefile
+
+MYSQLDATAdir =          $(localstatedir)
+MYSQLSHAREdir =         $(pkgdatadir)
+MYSQLBASEdir=           $(prefix)
+MYSQLLIBdir=            $(pkglibdir)
+INCLUDES =              -I$(top_srcdir)/include \
+			-I$(top_srcdir)/regex \
+			-I$(top_srcdir)/sql \
+                        -I$(srcdir)
+WRAPLIBS=
+
+LDADD =
+
+DEFS =                  @DEFS@
+
+noinst_HEADERS =	
+
+EXTRA_LTLIBRARIES =	ft_example.la
+pkglib_LTLIBRARIES =	@plugin_ftexample_shared_target@
+ft_example_la_LDFLAGS =	-module -rpath $(MYSQLLIBdir)
+ft_example_la_CXXFLAGS=	$(AM_CFLAGS) -DMYSQL_DYNAMIC_PLUGIN
+ft_example_la_CFLAGS=	$(AM_CFLAGS) -DMYSQL_DYNAMIC_PLUGIN
+ft_example_la_SOURCES =	plugin_example.c
+
+
+EXTRA_LIBRARIES =	libftexample.a
+noinst_LIBRARIES =	@plugin_ftexample_static_target@
+libftexample_a_CXXFLAGS=$(AM_CFLAGS)
+libftexample_a_CFLAGS =	$(AM_CFLAGS)
+libftexample_a_SOURCES=	plugin_example.c
+
+
+# Don't update the files from bitkeeper
+%::SCCS/s.%
diff --git a/plugin/fulltext/plugin_example.c b/plugin/fulltext/plugin_example.c
index cdf1527b310..9b937453ce4 100644
--- a/plugin/fulltext/plugin_example.c
+++ b/plugin/fulltext/plugin_example.c
@@ -216,7 +216,7 @@ static struct st_mysql_show_var simple_status[]=
   Plugin library descriptor
 */
 
-mysql_declare_plugin
+mysql_declare_plugin(ftexample)
 {
   MYSQL_FTPARSER_PLUGIN,      /* type                            */
   &simple_parser_descriptor,  /* descriptor                      */
diff --git a/sql/Makefile.am b/sql/Makefile.am
index 60e7891931f..2665e3fcfd5 100644
--- a/sql/Makefile.am
+++ b/sql/Makefile.am
@@ -30,10 +30,7 @@ libexec_PROGRAMS =	mysqld
 noinst_PROGRAMS =	gen_lex_hash
 bin_PROGRAMS =		mysql_tzinfo_to_sql
 gen_lex_hash_LDFLAGS =  @NOINST_LDFLAGS@
-LDADD =			$(top_builddir)/storage/myisam/libmyisam.a \
-			$(top_builddir)/storage/myisammrg/libmyisammrg.a \
-			$(top_builddir)/storage/heap/libheap.a \
-			$(top_builddir)/vio/libvio.a \
+LDADD =			$(top_builddir)/vio/libvio.a \
 			$(top_builddir)/mysys/libmysys.a \
 			$(top_builddir)/dbug/libdbug.a \
 			$(top_builddir)/regex/libregex.a \
@@ -41,7 +38,7 @@ LDADD =			$(top_builddir)/storage/myisam/libmyisam.a \
 
 mysqld_LDADD =		@MYSQLD_EXTRA_LDFLAGS@ \
 			@pstack_libs@ \
-			@mysql_se_objs@ @mysql_se_libs@ \
+			@mysql_plugin_libs@ \
 			$(LDADD)  $(CXXLDFLAGS) $(WRAPLIBS) @LIBDL@ \
                         @yassl_libs@ @openssl_libs@
 noinst_HEADERS =	item.h item_func.h item_sum.h item_cmpfunc.h \
@@ -53,6 +50,9 @@ noinst_HEADERS =	item.h item_func.h item_sum.h item_cmpfunc.h \
 			sql_manager.h sql_map.h sql_string.h unireg.h \
 			sql_error.h field.h handler.h mysqld_suffix.h \
 			ha_heap.h ha_myisam.h ha_myisammrg.h ha_partition.h \
+			ha_innodb.h  ha_berkeley.h ha_federated.h \
+			ha_ndbcluster.h ha_ndbcluster_binlog.h \
+			ha_ndbcluster_tables.h
 			opt_range.h protocol.h rpl_tblmap.h \
 			log.h sql_show.h rpl_rli.h \
 			sql_select.h structs.h table.h sql_udf.h hash_filo.h\
@@ -61,12 +61,12 @@ noinst_HEADERS =	item.h item_func.h item_sum.h item_cmpfunc.h \
 			rpl_injector.h \
 			stacktrace.h sql_sort.h sql_cache.h set_var.h \
 			spatial.h gstream.h client_settings.h tzfile.h \
-                        tztime.h my_decimal.h\
+			tztime.h my_decimal.h\
 			sp_head.h sp_pcontext.h sp_rcontext.h sp.h sp_cache.h \
 			parse_file.h sql_view.h	sql_trigger.h \
 			sql_array.h sql_cursor.h event.h event_priv.h \
 			sql_plugin.h authors.h sql_partition.h \
-                        partition_info.h partition_element.h
+			partition_info.h partition_element.h
 mysqld_SOURCES =	sql_lex.cc sql_handler.cc sql_partition.cc \
 			item.cc item_sum.cc item_buff.cc item_func.cc \
 			item_cmpfunc.cc item_strfunc.cc item_timefunc.cc \
@@ -79,7 +79,7 @@ mysqld_SOURCES =	sql_lex.cc sql_handler.cc sql_partition.cc \
 			mysqld.cc password.c hash_filo.cc hostname.cc \
 			set_var.cc sql_parse.cc sql_yacc.yy \
 			sql_base.cc table.cc sql_select.cc sql_insert.cc \
-                        sql_prepare.cc sql_error.cc \
+			sql_prepare.cc sql_error.cc \
 			sql_update.cc sql_delete.cc uniques.cc sql_do.cc \
 			procedure.cc item_uniq.cc sql_test.cc \
 			log.cc log_event.cc init.cc derror.cc sql_acl.cc \
@@ -87,6 +87,9 @@ mysqld_SOURCES =	sql_lex.cc sql_handler.cc sql_partition.cc \
 			discover.cc time.cc opt_range.cc opt_sum.cc \
 		   	records.cc filesort.cc handler.cc \
 			ha_heap.cc ha_myisam.cc ha_myisammrg.cc \
+			ha_partition.cc ha_innodb.cc ha_berkeley.cc \
+			ha_federated.cc \
+                        ha_ndbcluster.cc ha_ndbcluster_binlog.cc \
 			sql_db.cc sql_table.cc sql_rename.cc sql_crypt.cc \
 			sql_load.cc mf_iocache.cc field_conv.cc sql_show.cc \
 			sql_udf.cc sql_analyse.cc sql_analyse.h sql_cache.cc \
@@ -102,15 +105,9 @@ mysqld_SOURCES =	sql_lex.cc sql_handler.cc sql_partition.cc \
 			sp_cache.cc parse_file.cc sql_trigger.cc \
                         event_executor.cc event.cc event_timed.cc \
 			sql_plugin.cc sql_binlog.cc \
-			handlerton.cc sql_tablespace.cc partition_info.cc
-EXTRA_mysqld_SOURCES =	ha_innodb.cc ha_berkeley.cc ha_archive.cc \
-			ha_innodb.h  ha_berkeley.h  ha_archive.h \
-			ha_blackhole.cc ha_federated.cc ha_ndbcluster.cc \
-			ha_blackhole.h  ha_federated.h  ha_ndbcluster.h \
-			ha_ndbcluster_binlog.cc ha_ndbcluster_binlog.h \
-			ha_ndbcluster_tables.h \
-			ha_partition.cc ha_partition.h
-mysqld_DEPENDENCIES =	@mysql_se_objs@
+			sql_builtin.cc sql_tablespace.cc partition_info.cc
+
+
 gen_lex_hash_SOURCES =	gen_lex_hash.cc
 gen_lex_hash_LDADD =	$(LDADD) $(CXXLDFLAGS)
 mysql_tzinfo_to_sql_SOURCES =   mysql_tzinfo_to_sql.cc
@@ -162,6 +159,7 @@ sql_yacc.o:	sql_yacc.cc sql_yacc.h $(HEADERS)
 lex_hash.h:	gen_lex_hash$(EXEEXT)
 		./gen_lex_hash$(EXEEXT) > $@
 
+# the following three should eventually be moved out of this directory
 ha_berkeley.o:	ha_berkeley.cc ha_berkeley.h
 		$(CXXCOMPILE) @bdb_includes@ $(LM_CFLAGS) -c $<
 
diff --git a/sql/ha_berkeley.cc b/sql/ha_berkeley.cc
index 6ea4cc9aeb5..0fabd00faa3 100644
--- a/sql/ha_berkeley.cc
+++ b/sql/ha_berkeley.cc
@@ -56,10 +56,14 @@
 #include 
 #include 
 #include 
+
+#ifdef WITH_BERKELEY_STORAGE_ENGINE
 #include "ha_berkeley.h"
 #include "sql_manager.h"
 #include 
 
+#include 
+
 #define HA_BERKELEY_ROWS_IN_TABLE 10000 /* to get optimization right */
 #define HA_BERKELEY_RANGE_COUNT   100
 #define HA_BERKELEY_MAX_ROWS	  10000000 /* Max rows in table */
@@ -2725,3 +2729,17 @@ bool ha_berkeley::check_if_incompatible_data(HA_CREATE_INFO *info,
 }
 
 
+mysql_declare_plugin(berkeley)
+{
+  MYSQL_STORAGE_ENGINE_PLUGIN,
+  &berkeley_hton,
+  berkeley_hton.name,
+  "MySQL AB",
+  "BerkeleyDB Storage Engine",
+  NULL, /* Plugin Init */
+  NULL, /* Plugin Deinit */
+  0x0100 /* 1.0 */,
+}
+mysql_declare_plugin_end;
+
+#endif
diff --git a/sql/ha_federated.cc b/sql/ha_federated.cc
index 129a44b5721..f1d2b0025a9 100644
--- a/sql/ha_federated.cc
+++ b/sql/ha_federated.cc
@@ -351,9 +351,13 @@
 #pragma implementation                          // gcc: Class implementation
 #endif
 
+#ifdef WITH_FEDERATED_STORAGE_ENGINE
 #include "ha_federated.h"
 
 #include "m_string.h"
+
+#include 
+
 /* Variables for federated share methods */
 static HASH federated_open_tables;              // To track open tables
 pthread_mutex_t federated_mutex;                // To init the hash
@@ -2804,3 +2808,18 @@ int ha_federated::execute_simple_query(const char *query, int len)
   DBUG_RETURN(0);
 }
 
+
+mysql_declare_plugin(federated)
+{
+  MYSQL_STORAGE_ENGINE_PLUGIN,
+  &federated_hton,
+  federated_hton.name,
+  "Patrick Galbraith and Brian Aker, MySQL AB",
+  "Federated Storage Engine",
+  NULL, /* Plugin Init */
+  NULL, /* Plugin Deinit */
+  0x0100 /* 1.0 */,
+}
+mysql_declare_plugin_end;
+
+#endif
diff --git a/sql/ha_heap.cc b/sql/ha_heap.cc
index f20dfe259fb..1223de37af8 100644
--- a/sql/ha_heap.cc
+++ b/sql/ha_heap.cc
@@ -706,3 +706,16 @@ bool ha_heap::check_if_incompatible_data(HA_CREATE_INFO *info,
     return COMPATIBLE_DATA_NO;
   return COMPATIBLE_DATA_YES;
 }
+
+mysql_declare_plugin(heap)
+{
+  MYSQL_STORAGE_ENGINE_PLUGIN,
+  &heap_hton,
+  heap_hton.name,
+  NULL,
+  heap_hton.comment,
+  NULL,
+  NULL,
+  0
+}
+mysql_declare_plugin_end;
diff --git a/sql/ha_innodb.cc b/sql/ha_innodb.cc
index 1b0f4c34acc..e94b08cf4fb 100644
--- a/sql/ha_innodb.cc
+++ b/sql/ha_innodb.cc
@@ -42,6 +42,7 @@ have disables the InnoDB inlining in this file. */
 
 #define MAX_ULONG_BIT ((ulong) 1 << (sizeof(ulong)*8-1))
 
+#ifdef WITH_INNOBASE_STORAGE_ENGINE
 #include "ha_innodb.h"
 
 pthread_mutex_t innobase_share_mutex,	/* to protect innobase_open_files */
@@ -7533,3 +7534,19 @@ bool ha_innobase::check_if_incompatible_data(
 
 	return COMPATIBLE_DATA_YES;
 }
+
+
+mysql_declare_plugin(innobase)
+{
+  MYSQL_STORAGE_ENGINE_PLUGIN,
+  &innobase_hton,
+  innobase_hton.name,
+  "Innobase OY",
+  "InnoDB Storage Engine",
+  NULL, /* Plugin Init */
+  NULL, /* Plugin Deinit */
+  0x0100 /* 1.0 */,
+}
+mysql_declare_plugin_end;
+
+#endif
diff --git a/sql/ha_myisam.cc b/sql/ha_myisam.cc
index ec39ee00efc..9a0a4a9896f 100644
--- a/sql/ha_myisam.cc
+++ b/sql/ha_myisam.cc
@@ -31,6 +31,8 @@
 #include "../storage/myisam/rt_index.h"
 #endif
 
+#include 
+
 ulong myisam_recover_options= HA_RECOVER_NONE;
 
 /* bits in myisam_recover_options */
@@ -1787,3 +1789,17 @@ bool ha_myisam::check_if_incompatible_data(HA_CREATE_INFO *info,
     return COMPATIBLE_DATA_NO;
   return COMPATIBLE_DATA_YES;
 }
+
+
+mysql_declare_plugin(myisam)
+{
+  MYSQL_STORAGE_ENGINE_PLUGIN,
+  &myisam_hton,
+  myisam_hton.name,
+  "MySQL AB",
+  "MyISAM Storage Engine",
+  NULL, /* Plugin Init */
+  NULL, /* Plugin Deinit */
+  0x0100 /* 1.0 */,
+}
+mysql_declare_plugin_end;
diff --git a/sql/ha_myisammrg.cc b/sql/ha_myisammrg.cc
index 0ce4e1d8bcb..8130a5d939a 100644
--- a/sql/ha_myisammrg.cc
+++ b/sql/ha_myisammrg.cc
@@ -28,6 +28,8 @@
 #include "../storage/myisammrg/myrg_def.h"
 #endif
 
+#include 
+
 /*****************************************************************************
 ** MyISAM MERGE tables
 *****************************************************************************/
@@ -573,3 +575,16 @@ bool ha_myisammrg::check_if_incompatible_data(HA_CREATE_INFO *info,
   */
   return COMPATIBLE_DATA_NO;
 }
+
+mysql_declare_plugin(myisammrg)
+{
+  MYSQL_STORAGE_ENGINE_PLUGIN,
+  &myisammrg_hton,
+  myisammrg_hton.name,
+  "MySQL AB",
+  "MyISAMMRG Storage Engine",
+  NULL, /* Plugin Init */
+  NULL, /* Plugin Deinit */
+  0x0100 /* 1.0 */,
+}
+mysql_declare_plugin_end;
diff --git a/sql/ha_ndbcluster.cc b/sql/ha_ndbcluster.cc
index 28e026b8a10..83367fa4bee 100644
--- a/sql/ha_ndbcluster.cc
+++ b/sql/ha_ndbcluster.cc
@@ -27,6 +27,7 @@
 #include "mysql_priv.h"
 
 #include 
+#ifdef WITH_NDBCLUSTER_STORAGE_ENGINE
 #include "ha_ndbcluster.h"
 #include 
 #include 
@@ -36,6 +37,8 @@
 #include "ha_ndbcluster_binlog.h"
 #include "ha_ndbcluster_tables.h"
 
+#include 
+
 #ifdef ndb_dynamite
 #undef assert
 #define assert(x) do { if(x) break; ::printf("%s %d: assert failed: %s\n", __FILE__, __LINE__, #x); ::fflush(stdout); ::signal(SIGABRT,SIG_DFL); ::abort(); ::kill(::getpid(),6); ::kill(::getpid(),9); } while (0)
@@ -10146,3 +10149,19 @@ static int ndbcluster_fill_files_table(THD *thd, TABLE_LIST *tables, COND *cond)
   }
   DBUG_RETURN(0);
 }
+
+
+mysql_declare_plugin(ndbcluster)
+{
+  MYSQL_STORAGE_ENGINE_PLUGIN,
+  &ndbcluster_hton,
+  ndbcluster_hton.name,
+  "MySQL AB",
+  "NDB Storage Engine",
+  NULL, /* Plugin Init */
+  NULL, /* Plugin Deinit */
+  0x0100 /* 1.0 */,
+}
+mysql_declare_plugin_end;
+
+#endif
diff --git a/sql/ha_ndbcluster_binlog.cc b/sql/ha_ndbcluster_binlog.cc
index 60ccb661703..b248bb8534a 100644
--- a/sql/ha_ndbcluster_binlog.cc
+++ b/sql/ha_ndbcluster_binlog.cc
@@ -16,6 +16,7 @@
 */
 
 #include "mysql_priv.h"
+#ifdef WITH_NDBCLUSTER_STORAGE_ENGINE
 #include "ha_ndbcluster.h"
 
 #ifdef HAVE_NDB_BINLOG
@@ -3510,3 +3511,4 @@ ndbcluster_show_status_binlog(THD* thd, stat_print_fn *stat_print,
 }
 
 #endif /* HAVE_NDB_BINLOG */
+#endif
diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc
index 3ee9a2954eb..fc9985cf87f 100644
--- a/sql/ha_partition.cc
+++ b/sql/ha_partition.cc
@@ -54,8 +54,11 @@
 
 #include "mysql_priv.h"
 
+#ifdef WITH_PARTITION_STORAGE_ENGINE
 #include "ha_partition.h"
 
+#include 
+
 static const char *ha_par_ext= ".par";
 #ifdef NOT_USED
 static int free_share(PARTITION_SHARE * share);
@@ -5487,3 +5490,19 @@ static int free_share(PARTITION_SHARE *share)
   return 0;
 }
 #endif /* NOT_USED */
+
+
+mysql_declare_plugin(partition)
+{
+  MYSQL_STORAGE_ENGINE_PLUGIN,
+  &partition_hton,
+  partition_hton.name,
+  "Mikael Ronstrom, MySQL AB",
+  "Partitioning Engine",
+  NULL, /* Plugin Init */
+  NULL, /* Plugin Deinit */
+  0x0100 /* 1.0 */,
+}
+mysql_declare_plugin_end;
+
+#endif
diff --git a/sql/handler.cc b/sql/handler.cc
index 808dd0841c5..56938f2eff7 100644
--- a/sql/handler.cc
+++ b/sql/handler.cc
@@ -35,6 +35,7 @@
 #define NDB_MAX_ATTRIBUTES_IN_TABLE 128
 #include "ha_ndbcluster.h"
 #endif
+
 #ifdef WITH_PARTITION_STORAGE_ENGINE
 #include "ha_partition.h"
 #endif
@@ -43,7 +44,7 @@
 #include "ha_innodb.h"
 #endif
 
-extern handlerton *sys_table_types[];
+static handlerton *installed_htons[128];
 
 #define BITMAP_STACKBUF_SIZE (128/8)
 
@@ -138,30 +139,8 @@ handlerton *ha_resolve_by_name(THD *thd, LEX_STRING *name)
 }
 
 
-struct plugin_find_dbtype_st
-{
-  enum legacy_db_type db_type;
-  handlerton *hton;
-};
-
-
-static my_bool plugin_find_dbtype(THD *unused, st_plugin_int *plugin,
-                                  void *arg)
-{
-  handlerton *types= (handlerton *) plugin->plugin->info;
-  if (types->db_type == ((struct plugin_find_dbtype_st *)arg)->db_type)
-  {
-    ((struct plugin_find_dbtype_st *)arg)->hton= types;
-    return TRUE;
-  }
-  return FALSE;
-}
-
-
 const char *ha_get_storage_engine(enum legacy_db_type db_type)
 {
-  struct plugin_find_dbtype_st info;
-  
   switch (db_type)
   {
   case DB_TYPE_DEFAULT:
@@ -169,13 +148,10 @@ const char *ha_get_storage_engine(enum legacy_db_type db_type)
   case DB_TYPE_UNKNOWN:
     return "UNKNOWN";
   default:
-    info.db_type= db_type;
-
-    if (!plugin_foreach(NULL, plugin_find_dbtype, 
-                        MYSQL_STORAGE_ENGINE_PLUGIN, &info))
+    if (db_type > DB_TYPE_UNKNOWN && db_type < DB_TYPE_DEFAULT &&
+        installed_htons[db_type])
+      return installed_htons[db_type]->name;
       return "*NONE*";
-
-    return info.hton->name;
   }
 }
 
@@ -190,8 +166,6 @@ static handler *create_default(TABLE_SHARE *table)
 
 handlerton *ha_resolve_by_legacy_type(THD *thd, enum legacy_db_type db_type)
 {
-  struct plugin_find_dbtype_st info;
-
   switch (db_type)
   {
   case DB_TYPE_DEFAULT:
@@ -202,12 +176,9 @@ handlerton *ha_resolve_by_legacy_type(THD *thd, enum legacy_db_type db_type)
   case DB_TYPE_UNKNOWN:
     return NULL;
   default:
-    info.db_type= db_type;
-    if (!plugin_foreach(NULL, plugin_find_dbtype, 
-                        MYSQL_STORAGE_ENGINE_PLUGIN, &info))
+    if (db_type > DB_TYPE_UNKNOWN && db_type < DB_TYPE_DEFAULT)
+      return installed_htons[db_type];
       return NULL;
-
-    return info.hton;
   }
 }
 
@@ -394,32 +365,77 @@ static int ha_finish_errors(void)
 }
 
 
-static void ha_was_inited_ok(handlerton *ht)
+int ha_finalize_handlerton(st_plugin_int *plugin)
 {
-  uint tmp= ht->savepoint_offset;
-  ht->savepoint_offset= savepoint_alloc_size;
-  savepoint_alloc_size+= tmp;
-  ht->slot= total_ha++;
-  if (ht->prepare)
-    total_ha_2pc++;
-}
+  handlerton *hton;
+  DBUG_ENTER("ha_finalize_handlerton");
 
-
-int ha_initialize_handlerton(handlerton *hton)
-{
-  DBUG_ENTER("ha_initialize_handlerton");
-
-  if (hton == NULL)
+  if (!(hton= (handlerton *) plugin->plugin->info))
     DBUG_RETURN(1);
 
   switch (hton->state)
   {
+  case SHOW_OPTION_NO:
+  case SHOW_OPTION_DISABLED:
+    break;
+  case SHOW_OPTION_YES:
+    if (hton->panic && hton->panic(HA_PANIC_CLOSE))
+      DBUG_RETURN(1);
+    if (installed_htons[hton->db_type] == hton)
+      installed_htons[hton->db_type]= NULL;
+    break;
+  };
+  DBUG_RETURN(0);
+}
+
+
+int ha_initialize_handlerton(st_plugin_int *plugin)
+{
+  handlerton *hton;
+  DBUG_ENTER("ha_initialize_handlerton");
+
+  if (!(hton= (handlerton *) plugin->plugin->info))
+    DBUG_RETURN(1);
+
+  /* for the sake of sanity, we set the handlerton name to be the
+     same as the plugin name */
+  hton->name= plugin->name.str;
+
+
+  switch (hton->state) {
   case SHOW_OPTION_NO:
     break;
   case SHOW_OPTION_YES:
     if (!hton->init || !hton->init())
     {
-      ha_was_inited_ok(hton);
+      uint tmp= hton->savepoint_offset;
+      hton->savepoint_offset= savepoint_alloc_size;
+      savepoint_alloc_size+= tmp;
+      hton->slot= total_ha++;
+      if (hton->prepare)
+        total_ha_2pc++;
+        
+      /* now check the db_type for conflict */
+      if (hton->db_type <= DB_TYPE_UNKNOWN || 
+          hton->db_type >= DB_TYPE_DEFAULT ||
+          installed_htons[hton->db_type])
+      {
+        int idx= (int) DB_TYPE_FIRST_DYNAMIC;
+        
+        while (idx < (int) DB_TYPE_DEFAULT && installed_htons[idx])
+          idx++;
+
+        if (idx == (int) DB_TYPE_DEFAULT)
+        {
+          sql_print_warning("Too many storage engines!");
+          DBUG_RETURN(1);
+        }
+        if (hton->db_type != DB_TYPE_UNKNOWN)
+          sql_print_warning("Storage engine '%s' has conflicting typecode. "
+                            "Assigning value %d.", hton->name, idx);
+        hton->db_type= (enum legacy_db_type) idx;
+      }
+      installed_htons[hton->db_type]= hton;
       break;
     }
     /* fall through */
@@ -436,7 +452,7 @@ static my_bool init_handlerton(THD *unused1, st_plugin_int *plugin,
 {
   if (plugin->state == PLUGIN_IS_UNINITIALIZED)
   {
-    ha_initialize_handlerton((handlerton *) plugin->plugin->info);
+    ha_initialize_handlerton(plugin);
     plugin->state= PLUGIN_IS_READY;
   }
   return FALSE;
@@ -447,12 +463,15 @@ int ha_init()
 {
   int error= 0;
   total_ha= savepoint_alloc_size= 0;
+  DBUG_ENTER("ha_init");
+
+  bzero(installed_htons, sizeof(installed_htons));
 
   if (ha_init_errors())
-    return 1;
+    DBUG_RETURN(1);
 
   if (plugin_foreach(NULL, init_handlerton, MYSQL_STORAGE_ENGINE_PLUGIN, 0))
-    return 1;
+    DBUG_RETURN(1);
 
   DBUG_ASSERT(total_ha < MAX_HA);
   /*
@@ -462,37 +481,7 @@ int ha_init()
   */
   opt_using_transactions= total_ha>(ulong)opt_bin_log;
   savepoint_alloc_size+= sizeof(SAVEPOINT);
-  return error;
-}
-
-
-int ha_register_builtin_plugins()
-{
-  handlerton **hton;
-  uint size= 0;
-  struct st_mysql_plugin *plugin;
-  DBUG_ENTER("ha_register_builtin_plugins");
-
-  for (hton= sys_table_types; *hton; hton++)
-    size+= sizeof(struct st_mysql_plugin);
-  
-  if (!(plugin= (struct st_mysql_plugin *)
-        my_once_alloc(size, MYF(MY_WME | MY_ZEROFILL))))
-    DBUG_RETURN(1);
-  
-  for (hton= sys_table_types; *hton; hton++, plugin++)
-  {
-    plugin->type= MYSQL_STORAGE_ENGINE_PLUGIN;
-    plugin->info= *hton;
-    plugin->version= 0;
-    plugin->name= (*hton)->name;
-    plugin->author= NULL;
-    plugin->descr= (*hton)->comment;
-    
-    if (plugin_register_builtin(plugin))
-      DBUG_RETURN(1);
-  }
-  DBUG_RETURN(0);
+  DBUG_RETURN(error);
 }
 
 
diff --git a/sql/handler.h b/sql/handler.h
index e93fdfe67e3..90bee61dc14 100644
--- a/sql/handler.h
+++ b/sql/handler.h
@@ -233,6 +233,7 @@ enum legacy_db_type
   DB_TYPE_BLACKHOLE_DB,
   DB_TYPE_PARTITION_DB,
   DB_TYPE_BINLOG,
+  DB_TYPE_FIRST_DYNAMIC=32,
   DB_TYPE_DEFAULT=127 // Must be last
 };
 
@@ -1545,8 +1546,8 @@ static inline bool ha_storage_engine_is_enabled(const handlerton *db_type)
 
 /* basic stuff */
 int ha_init(void);
-int ha_register_builtin_plugins();
-int ha_initialize_handlerton(handlerton *hton);
+int ha_initialize_handlerton(st_plugin_int *plugin);
+int ha_finalize_handlerton(st_plugin_int *plugin);
 
 TYPELIB *ha_known_exts(void);
 int ha_panic(enum ha_panic_function flag);
diff --git a/sql/handlerton-win.cc b/sql/handlerton-win.cc
deleted file mode 100644
index 9ce4eab2444..00000000000
--- a/sql/handlerton-win.cc
+++ /dev/null
@@ -1,72 +0,0 @@
-#include "mysql_priv.h"
-
-extern handlerton heap_hton;
-extern handlerton myisam_hton;
-extern handlerton myisammrg_hton;
-extern handlerton binlog_hton;
-#ifdef WITH_INNOBASE_STORAGE_ENGINE
-extern handlerton innobase_hton;
-#endif
-#ifdef WITH_BERKELEY_STORAGE_ENGINE
-extern handlerton berkeley_hton;
-#endif
-#ifdef WITH_EXAMPLE_STORAGE_ENGINE
-extern handlerton example_hton;
-#endif
-#ifdef WITH_ARCHIVE_STORAGE_ENGINE
-extern handlerton archive_hton;
-#endif
-#ifdef WITH_CSV_STORAGE_ENGINE
-extern handlerton tina_hton;
-#endif
-#ifdef WITH_BLACKHOLE_STORAGE_ENGINE
-extern handlerton blackhole_hton;
-#endif
-#ifdef WITH_FEDERATED_STORAGE_ENGINE
-extern handlerton federated_hton;
-#endif
-#ifdef WITH_NDBCLUSTER_STORAGE_ENGINE
-extern handlerton ndbcluster_hton;
-#endif
-#ifdef WITH_PARTITION_STORAGE_ENGINE
-extern handlerton partition_hton;
-#endif
-
-/*
-  This array is used for processing compiled in engines.
-*/
-handlerton *sys_table_types[]=
-{
-  &heap_hton,
-  &myisam_hton,
-#ifdef WITH_INNOBASE_STORAGE_ENGINE
-  &innobase_hton,
-#endif
-#ifdef WITH_BERKELEY_STORAGE_ENGINE
-  &berkeley_hton,
-#endif
-#ifdef WITH_EXAMPLE_STORAGE_ENGINE
-  &example_hton,
-#endif
-#ifdef WITH_ARCHIVE_STORAGE_ENGINE
-  &archive_hton,
-#endif
-#ifdef WITH_CSV_STORAGE_ENGINE
-  &tina_hton,
-#endif
-#ifdef WITH_BLACKHOLE_STORAGE_ENGINE
-  &blackhole_hton,
-#endif
-#ifdef WITH_FEDERATED_STORAGE_ENGINE
-  &federated_hton,
-#endif
-#ifdef WITH_NDBCLUSTER_STORAGE_ENGINE
-  &ndbcluster_hton,
-#endif
-#ifdef WITH_PARTITION_STORAGE_ENGINE
-  &partition_hton,
-#endif
-  &myisammrg_hton,
-  &binlog_hton,
-  NULL
-};
diff --git a/sql/handlerton.cc.in b/sql/handlerton.cc.in
deleted file mode 100644
index 55af8cdd8cf..00000000000
--- a/sql/handlerton.cc.in
+++ /dev/null
@@ -1,14 +0,0 @@
-
-#include "mysql_priv.h"
-
-extern handlerton heap_hton,myisam_hton,myisammrg_hton,
-  binlog_hton@mysql_se_decls@;
-
-/*
-  This array is used for processing compiled in engines.
-*/
-handlerton *sys_table_types[]=
-{
-  &heap_hton,&myisam_hton@mysql_se_htons@,&myisammrg_hton,&binlog_hton,NULL
-};
-
diff --git a/sql/log.cc b/sql/log.cc
index 5c67443d238..82f430f968f 100644
--- a/sql/log.cc
+++ b/sql/log.cc
@@ -34,6 +34,8 @@
 #include "message.h"
 #endif
 
+#include 
+
 /* max size of the log message */
 #define MAX_LOG_BUFFER_SIZE 1024
 #define MAX_USER_HOST_SIZE 512
@@ -4331,3 +4333,16 @@ err1:
   return 1;
 }
 
+
+mysql_declare_plugin(binlog)
+{
+  MYSQL_STORAGE_ENGINE_PLUGIN,
+  &binlog_hton,
+  binlog_hton.name,
+  "MySQL AB",
+  "Binlog Engine",
+  NULL, /* Plugin Init */
+  NULL, /* Plugin Deinit */
+  0x0100 /* 1.0 */,
+}
+mysql_declare_plugin_end;
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index 71067630535..0c7908c6b1a 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -2703,12 +2703,6 @@ static int init_common_variables(const char *conf_file_name, int argc,
     return 1;
   }
 
-  if (ha_register_builtin_plugins())
-  {
-    sql_print_error("Failed to register built-in storage engines.");
-    return 1;
-  }
-
   load_defaults(conf_file_name, groups, &argc, &argv);
   defaults_argv=argv;
   get_options(argc,argv);
@@ -3077,6 +3071,19 @@ static int init_server_components()
     }
   }
 
+  if (xid_cache_init())
+  {
+    sql_print_error("Out of memory");
+    unireg_abort(1);
+  }
+
+  /* We have to initialize the storage engines before CSV logging */
+  if (ha_init())
+  {
+    sql_print_error("Can't init databases");
+    unireg_abort(1);
+  }
+
 #ifdef WITH_CSV_STORAGE_ENGINE
   if (opt_bootstrap)
     log_output_options= LOG_FILE;
@@ -3240,17 +3247,6 @@ server.");
     using_update_log=1;
   }
 
-  if (xid_cache_init())
-  {
-    sql_print_error("Out of memory");
-    unireg_abort(1);
-  }
-  if (ha_init())
-  {
-    sql_print_error("Can't init databases");
-    unireg_abort(1);
-  }
-
   /*
     Check that the default storage engine is actually available.
   */
diff --git a/sql/partition_info.cc b/sql/partition_info.cc
index e2bf37d6ef3..9646e913851 100644
--- a/sql/partition_info.cc
+++ b/sql/partition_info.cc
@@ -21,9 +21,10 @@
 #endif
 
 #include "mysql_priv.h"
-#include "ha_partition.h"
 
 #ifdef WITH_PARTITION_STORAGE_ENGINE
+#include "ha_partition.h"
+
 
 partition_info *partition_info::get_clone()
 {
diff --git a/sql/sql_builtin.cc.in b/sql/sql_builtin.cc.in
new file mode 100644
index 00000000000..18705aa3dfb
--- /dev/null
+++ b/sql/sql_builtin.cc.in
@@ -0,0 +1,13 @@
+
+#include 
+
+typedef struct st_mysql_plugin builtin_plugin[];
+
+extern builtin_plugin 
+  builtin_binlog_plugin@mysql_plugin_defs@;
+
+struct st_mysql_plugin *mysqld_builtins[]=
+{
+  builtin_binlog_plugin@mysql_plugin_defs@,(struct st_mysql_plugin *)0
+};
+
diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc
index 4365d5b04ce..44b0fe1a2f1 100644
--- a/sql/sql_delete.cc
+++ b/sql/sql_delete.cc
@@ -21,7 +21,9 @@
 */
 
 #include "mysql_priv.h"
+#ifdef WITH_INNOBASE_STORAGE_ENGINE
 #include "ha_innodb.h"
+#endif
 #include "sql_select.h"
 #include "sp_head.h"
 #include "sql_trigger.h"
diff --git a/sql/sql_plugin.cc b/sql/sql_plugin.cc
index 3d42bfea104..70dfb8bded9 100644
--- a/sql/sql_plugin.cc
+++ b/sql/sql_plugin.cc
@@ -19,6 +19,8 @@
 #define REPORT_TO_LOG  1
 #define REPORT_TO_USER 2
 
+extern struct st_mysql_plugin *mysqld_builtins[];
+
 char *opt_plugin_dir_ptr;
 char opt_plugin_dir[FN_REFLEN];
 LEX_STRING plugin_type_names[]=
@@ -540,6 +542,53 @@ err:
   DBUG_RETURN(1);
 }
 
+static int plugin_finalize(THD *thd, struct st_plugin_int *plugin)
+{
+  int rc;
+  DBUG_ENTER("plugin_finalize");
+  
+  if (plugin->ref_count)
+  {
+    push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, 0,
+                 "Plugin is busy and will be uninstalled on shutdown");
+    goto err;
+  }
+  
+  switch (plugin->plugin->type)
+  {
+  case MYSQL_STORAGE_ENGINE_PLUGIN:
+    if (ha_finalize_handlerton(plugin))
+    {
+      push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, 0,
+                   "Storage engine shutdown failed. "
+                   "It will be uninstalled on shutdown");
+      sql_print_warning("Storage engine '%s' shutdown failed. "
+                        "It will be uninstalled on shutdown", plugin->name.str);
+      goto err;
+    }
+    break;
+  default:
+    break;
+  }
+
+  if (plugin->plugin->deinit)
+  {
+    if ((rc= plugin->plugin->deinit()))
+    {
+      push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, 0,
+                   "Plugin deinit failed. "
+                   "It will be uninstalled on shutdown");
+      sql_print_warning("Plugin '%s' deinit failed. "
+                        "It will be uninstalled on shutdown", plugin->name.str);
+      goto err;
+    }
+  }
+  
+  DBUG_RETURN(0);
+err:
+  DBUG_RETURN(1);
+}
+
 static void plugin_call_initializer(void)
 {
   uint i;
@@ -598,6 +647,8 @@ static byte *get_hash_key(const byte *buff, uint *length,
 int plugin_init(void)
 {
   int i;
+  struct st_mysql_plugin **builtins;
+  struct st_mysql_plugin *plugin;
   DBUG_ENTER("plugin_init");
 
   if (initialized)
@@ -617,6 +668,16 @@ int plugin_init(void)
                   get_hash_key, NULL, 0))
       goto err;
   }
+  
+  /* Register all the built-in plugins */
+  for (builtins= mysqld_builtins; *builtins; builtins++)
+  {
+    for (plugin= *builtins; plugin->info; plugin++)
+    {
+      if (plugin_register_builtin(plugin))
+        goto err;
+    }
+  }
 
   initialized= 1;
 
@@ -823,18 +884,10 @@ my_bool mysql_uninstall_plugin(THD *thd, LEX_STRING *name)
     goto err;
   }
 
-  if (plugin->ref_count)
-  {
-    plugin->state= PLUGIN_IS_DELETED;
-    push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, 0,
-                 "Plugin is not deleted, waiting on tables.");
-  }
-  else
-  {
-    if (plugin->plugin->deinit)
-      plugin->plugin->deinit();
+  if (!plugin_finalize(thd, plugin))
     plugin_del(name);
-  }
+  else
+    plugin->state= PLUGIN_IS_DELETED;
 
   table->field[0]->store(name->str, name->length, system_charset_info);
   table->file->extra(HA_EXTRA_RETRIEVE_ALL_COLS);
diff --git a/sql/sql_show.cc b/sql/sql_show.cc
index 95433828a1e..042c0397be3 100644
--- a/sql/sql_show.cc
+++ b/sql/sql_show.cc
@@ -111,6 +111,10 @@ static my_bool show_plugins(THD *thd, st_plugin_int *plugin,
   CHARSET_INFO *cs= system_charset_info;
   char version_buf[20];
 
+  /* we normally hide all the built-in plugins */
+  if (!plugin->plugin_dl && !thd->lex->verbose)
+    return 0;
+
   restore_record(table, s->default_values);
 
   table->field[0]->store(plugin->name.str, plugin->name.length, cs);
@@ -3000,46 +3004,53 @@ int fill_schema_charsets(THD *thd, TABLE_LIST *tables, COND *cond)
 }
 
 
-int fill_schema_engines(THD *thd, TABLE_LIST *tables, COND *cond)
+static my_bool iter_schema_engines(THD *thd, st_plugin_int *plugin,
+                                   void *ptable)
 {
+  TABLE *table= (TABLE *) ptable;
+  handlerton *hton= (handlerton *) plugin->plugin->info;
   const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NullS;
-  TABLE *table= tables->table;
   CHARSET_INFO *scs= system_charset_info;
-  handlerton **types;
+  DBUG_ENTER("iter_schema_engines");
 
-  DBUG_ENTER("fill_schema_engines");
-
-  for (types= sys_table_types; *types; types++)
+  if (!(hton->flags & HTON_HIDDEN))
   {
-    if ((*types)->flags & HTON_HIDDEN)
-      continue;
-
     if (!(wild && wild[0] &&
-          wild_case_compare(scs, (*types)->name,wild)))
+          wild_case_compare(scs, hton->name,wild)))
     {
       const char *tmp;
       restore_record(table, s->default_values);
 
-      table->field[0]->store((*types)->name, strlen((*types)->name), scs);
-      tmp= (*types)->state ? "DISABLED" : "ENABLED";
+      table->field[0]->store(hton->name, strlen(hton->name), scs);
+      tmp= hton->state ? "DISABLED" : "ENABLED";
       table->field[1]->store( tmp, strlen(tmp), scs);
-      table->field[2]->store((*types)->comment, strlen((*types)->comment), scs);
-      tmp= (*types)->commit ? "YES" : "NO";
+      table->field[2]->store(hton->comment, strlen(hton->comment), scs);
+      tmp= hton->commit ? "YES" : "NO";
       table->field[3]->store( tmp, strlen(tmp), scs);
-      tmp= (*types)->prepare ? "YES" : "NO";
+      tmp= hton->prepare ? "YES" : "NO";
       table->field[4]->store( tmp, strlen(tmp), scs);
-      tmp= (*types)->savepoint_set ? "YES" : "NO";
+      tmp= hton->savepoint_set ? "YES" : "NO";
       table->field[5]->store( tmp, strlen(tmp), scs);
 
       if (schema_table_store_record(thd, table))
         DBUG_RETURN(1);
     }
   }
-
   DBUG_RETURN(0);
 }
 
 
+int fill_schema_engines(THD *thd, TABLE_LIST *tables, COND *cond)
+{
+  const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NullS;
+  TABLE *table= tables->table;
+  CHARSET_INFO *scs= system_charset_info;
+
+  return plugin_foreach(thd, iter_schema_engines, 
+                        MYSQL_STORAGE_ENGINE_PLUGIN, table);
+}
+
+
 int fill_schema_collation(THD *thd, TABLE_LIST *tables, COND *cond)
 {
   CHARSET_INFO **cs;
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index f570cbcd782..6a8a4f745ba 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -8173,7 +8173,7 @@ show_param:
             if (prepare_schema_table(YYTHD, lex, 0, SCH_OPEN_TABLES))
               YYABORT;
 	  }
-        | PLUGIN_SYM
+        | opt_full PLUGIN_SYM
 	  {
 	    LEX *lex= Lex;
 	    WARN_DEPRECATED(yythd, "5.2", "SHOW PLUGIN", "'SHOW PLUGINS'");
diff --git a/storage/archive/Makefile.am b/storage/archive/Makefile.am
index 415e0dc8f8f..0920fe1a897 100644
--- a/storage/archive/Makefile.am
+++ b/storage/archive/Makefile.am
@@ -14,20 +14,48 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
-INCLUDES =		-I$(top_builddir)/include -I$(top_srcdir)/include \
-			@ZLIB_INCLUDES@
+#called from the top level Makefile
 
-LDADD =			libarchive.a \
-			$(top_builddir)/mysys/libmysys.a \
-			$(top_builddir)/dbug/libdbug.a \
-			$(top_builddir)/strings/libmystrings.a \
-			@ZLIB_LIBS@
-pkglib_LIBRARIES =	libarchive.a
+MYSQLDATAdir =          $(localstatedir)
+MYSQLSHAREdir =         $(pkgdatadir)
+MYSQLBASEdir=           $(prefix)
+MYSQLLIBdir=            $(pkglibdir)
+INCLUDES =              -I$(top_srcdir)/include \
+			-I$(top_srcdir)/regex \
+			-I$(top_srcdir)/sql \
+                        -I$(srcdir) @ZLIB_INCLUDES@
+WRAPLIBS=
+
+LDADD =
+
+DEFS =                  @DEFS@
+
+noinst_HEADERS =	ha_archive.h azlib.h
 noinst_PROGRAMS	=	archive_test
+
+EXTRA_LTLIBRARIES =	ha_archive.la
+pkglib_LTLIBRARIES =	@plugin_archive_shared_target@
+ha_archive_la_LDFLAGS =	-module -rpath $(MYSQLLIBdir)
+ha_archive_la_CXXFLAGS=	$(AM_CFLAGS) -DMYSQL_DYNAMIC_PLUGIN
+ha_archive_la_CFLAGS =	$(AM_CFLAGS) -DMYSQL_DYNAMIC_PLUGIN
+ha_archive_la_SOURCES =	ha_archive.cc azio.c
+
+
+EXTRA_LIBRARIES =	libarchive.a
+noinst_LIBRARIES =	@plugin_archive_static_target@
+libarchive_a_CXXFLAGS =	$(AM_CFLAGS)
+libarchive_a_CFLAGS =	$(AM_CFLAGS)
+libarchive_a_SOURCES =	ha_archive.cc azio.c
+
+
+archive_test_SOURCES =	archive_test.c azio.c
+archive_test_CFLAGS =	$(AM_CFLAGS)
+archive_test_LDADD =	$(top_srcdir)/mysys/libmysys.a \
+			$(top_srcdir)/dbug/libdbug.a \
+			$(top_srcdir)/strings/libmystrings.a \
+			@ZLIB_LIBS@
 archive_test_LDFLAGS = @NOINST_LDFLAGS@
-noinst_HEADERS =	azlib.h
-libarchive_a_SOURCES =	azio.c
-EXTRA_DIST =		cmakelists.txt
+
 
 # Don't update the files from bitkeeper
 %::SCCS/s.%
diff --git a/sql/ha_archive.cc b/storage/archive/ha_archive.cc
similarity index 97%
rename from sql/ha_archive.cc
rename to storage/archive/ha_archive.cc
index 403855b6a01..3cbb388bba1 100644
--- a/sql/ha_archive.cc
+++ b/storage/archive/ha_archive.cc
@@ -19,10 +19,13 @@
 #endif
 
 #include "mysql_priv.h"
+#include 
 
 #include "ha_archive.h"
 #include 
 
+#include 
+
 /*
   First, if you want to understand storage engines you should look at 
   ha_example.cc and ha_example.h. 
@@ -216,6 +219,8 @@ static byte* archive_get_key(ARCHIVE_SHARE *share,uint *length,
 bool archive_db_init()
 {
   DBUG_ENTER("archive_db_init");
+  if (archive_inited)
+    DBUG_RETURN(FALSE);
   if (pthread_mutex_init(&archive_mutex, MY_MUTEX_INIT_FAST))
     goto error;
   if (hash_init(&archive_open_tables, system_charset_info, 32, 0, 0,
@@ -229,7 +234,6 @@ bool archive_db_init()
     DBUG_RETURN(FALSE);
   }
 error:
-  have_archive_db= SHOW_OPTION_DISABLED;	// If we couldn't use handler
   DBUG_RETURN(TRUE);
 }
 
@@ -237,14 +241,14 @@ error:
   Release the archive handler.
 
   SYNOPSIS
-    archive_db_end()
+    archive_db_done()
     void
 
   RETURN
     FALSE       OK
 */
 
-int archive_db_end(ha_panic_function type)
+int archive_db_done()
 {
   if (archive_inited)
   {
@@ -255,6 +259,12 @@ int archive_db_end(ha_panic_function type)
   return 0;
 }
 
+
+int archive_db_end(ha_panic_function type)
+{
+  return archive_db_done();
+}
+
 ha_archive::ha_archive(TABLE_SHARE *table_arg)
   :handler(&archive_hton, table_arg), delayed_insert(0), bulk_insert(0)
 {
@@ -781,7 +791,7 @@ int ha_archive::write_row(byte *buf)
   if (share->crashed)
       DBUG_RETURN(HA_ERR_CRASHED_ON_USAGE);
 
-  statistic_increment(table->in_use->status_var.ha_write_count, &LOCK_status);
+  ha_statistic_increment(&SSV::ha_write_count);
   if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_INSERT)
     table->timestamp_field->set_time();
   pthread_mutex_lock(&share->mutex);
@@ -1098,8 +1108,7 @@ int ha_archive::rnd_next(byte *buf)
     DBUG_RETURN(HA_ERR_END_OF_FILE);
   scan_rows--;
 
-  statistic_increment(table->in_use->status_var.ha_read_rnd_next_count,
-		      &LOCK_status);
+  ha_statistic_increment(&SSV::ha_read_rnd_next_count);
   current_position= aztell(&archive);
   rc= get_row(&archive, buf);
 
@@ -1135,8 +1144,7 @@ void ha_archive::position(const byte *record)
 int ha_archive::rnd_pos(byte * buf, byte *pos)
 {
   DBUG_ENTER("ha_archive::rnd_pos");
-  statistic_increment(table->in_use->status_var.ha_read_rnd_next_count,
-		      &LOCK_status);
+  ha_statistic_increment(&SSV::ha_read_rnd_next_count);
   current_position= (my_off_t)my_get_ptr(pos, ref_length);
   (void)azseek(&archive, current_position, SEEK_SET);
 
@@ -1320,8 +1328,8 @@ THR_LOCK_DATA **ha_archive::store_lock(THD *thd,
     */
 
     if ((lock_type >= TL_WRITE_CONCURRENT_INSERT &&
-         lock_type <= TL_WRITE) && !thd->in_lock_tables
-        && !thd->tablespace_op)
+         lock_type <= TL_WRITE) && !thd_in_lock_tables(thd)
+        && !thd_tablespace_op(thd))
       lock_type = TL_WRITE_ALLOW_WRITE;
 
     /* 
@@ -1332,7 +1340,7 @@ THR_LOCK_DATA **ha_archive::store_lock(THD *thd,
       concurrent inserts to t2. 
     */
 
-    if (lock_type == TL_READ_NO_INSERT && !thd->in_lock_tables) 
+    if (lock_type == TL_READ_NO_INSERT && !thd_in_lock_tables(thd)) 
       lock_type = TL_READ;
 
     lock.type=lock_type;
@@ -1443,11 +1451,11 @@ int ha_archive::check(THD* thd, HA_CHECK_OPT* check_opt)
 {
   int rc= 0;
   byte *buf; 
-  const char *old_proc_info=thd->proc_info;
+  const char *old_proc_info;
   ha_rows count= share->rows_recorded;
   DBUG_ENTER("ha_archive::check");
 
-  thd->proc_info= "Checking table";
+  old_proc_info= thd_proc_info(thd, "Checking table");
   /* Flush any waiting data */
   azflush(&(share->archive_write), Z_SYNC_FLUSH);
   share->forced_flushes++;
@@ -1472,7 +1480,7 @@ int ha_archive::check(THD* thd, HA_CHECK_OPT* check_opt)
 
   my_free((char*)buf, MYF(0));
 
-  thd->proc_info= old_proc_info;
+  thd_proc_info(thd, old_proc_info);
 
   if ((rc && rc != HA_ERR_END_OF_FILE) || count)  
   {
@@ -1497,3 +1505,17 @@ bool ha_archive::check_and_repair(THD *thd)
 
   DBUG_RETURN(repair(thd, &check_opt));
 }
+
+
+mysql_declare_plugin(archive)
+{
+  MYSQL_STORAGE_ENGINE_PLUGIN,
+  &archive_hton,
+  archive_hton.name,
+  "Brian Aker, MySQL AB",
+  "Archive Storage Engine",
+  NULL, /* Plugin Init */
+  archive_db_done, /* Plugin Deinit */
+  0x0100 /* 1.0 */,
+}
+mysql_declare_plugin_end;
diff --git a/sql/ha_archive.h b/storage/archive/ha_archive.h
similarity index 99%
rename from sql/ha_archive.h
rename to storage/archive/ha_archive.h
index 9b351b7e8da..b64897ff046 100644
--- a/sql/ha_archive.h
+++ b/storage/archive/ha_archive.h
@@ -19,7 +19,7 @@
 #endif
 
 #include 
-#include "../storage/archive/azlib.h"
+#include "azlib.h"
 
 /*
   Please read ha_archive.cc first. If you are looking for more general
diff --git a/storage/blackhole/Makefile.am b/storage/blackhole/Makefile.am
new file mode 100644
index 00000000000..060eaffce66
--- /dev/null
+++ b/storage/blackhole/Makefile.am
@@ -0,0 +1,51 @@
+# Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult 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; either version 2 of the License, or
+# (at your option) any later version.
+# 
+# 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+#called from the top level Makefile
+
+MYSQLDATAdir =          $(localstatedir)
+MYSQLSHAREdir =         $(pkgdatadir)
+MYSQLBASEdir=           $(prefix)
+MYSQLLIBdir=            $(pkglibdir)
+INCLUDES =              -I$(top_srcdir)/include \
+			-I$(top_srcdir)/regex \
+			-I$(top_srcdir)/sql \
+                        -I$(srcdir)
+WRAPLIBS=
+
+LDADD =
+
+DEFS =                  @DEFS@
+
+noinst_HEADERS =	ha_blackhole.h
+
+EXTRA_LTLIBRARIES =	ha_blackhole.la
+pkglib_LTLIBRARIES =	@plugin_blackhole_shared_target@
+ha_blackhole_la_LDFLAGS=-module -rpath $(MYSQLLIBdir)
+ha_blackhole_la_CXXFLAGS=$(AM_CFLAGS) -DMYSQL_DYNAMIC_PLUGIN
+ha_blackhole_la_CFLAGS=	$(AM_CFLAGS) -DMYSQL_DYNAMIC_PLUGIN
+ha_blackhole_la_SOURCES=ha_blackhole.cc
+
+
+EXTRA_LIBRARIES =	libblackhole.a
+noinst_LIBRARIES =	@plugin_blackhole_static_target@
+libblackhole_a_CXXFLAGS=$(AM_CFLAGS)
+libblackhole_a_CFLAGS =	$(AM_CFLAGS)
+libblackhole_a_SOURCES=	ha_blackhole.cc
+
+
+# Don't update the files from bitkeeper
+%::SCCS/s.%
diff --git a/sql/ha_blackhole.cc b/storage/blackhole/ha_blackhole.cc
similarity index 95%
rename from sql/ha_blackhole.cc
rename to storage/blackhole/ha_blackhole.cc
index 2f5e8ee0abc..31d0b0c3917 100644
--- a/sql/ha_blackhole.cc
+++ b/storage/blackhole/ha_blackhole.cc
@@ -22,6 +22,8 @@
 #include "mysql_priv.h"
 #include "ha_blackhole.h"
 
+#include 
+
 /* Static declarations for handlerton */
 
 static handler *blackhole_create_handler(TABLE_SHARE *table);
@@ -250,3 +252,15 @@ int ha_blackhole::index_last(byte * buf)
   DBUG_RETURN(HA_ERR_END_OF_FILE);
 }
 
+mysql_declare_plugin(blackhole)
+{
+  MYSQL_STORAGE_ENGINE_PLUGIN,
+  &blackhole_hton,
+  blackhole_hton.name,
+  "MySQL AB",
+  "Blackhole Storage Engine",
+  NULL, /* Plugin Init */
+  NULL, /* Plugin Deinit */
+  0x0100 /* 1.0 */,
+}
+mysql_declare_plugin_end;
diff --git a/sql/ha_blackhole.h b/storage/blackhole/ha_blackhole.h
similarity index 100%
rename from sql/ha_blackhole.h
rename to storage/blackhole/ha_blackhole.h
diff --git a/storage/csv/Makefile.am b/storage/csv/Makefile.am
index 5573df720a3..0d3fd654745 100644
--- a/storage/csv/Makefile.am
+++ b/storage/csv/Makefile.am
@@ -25,15 +25,20 @@ INCLUDES =              -I$(top_builddir)/include \
 			-I$(top_srcdir)/regex \
 			-I$(top_srcdir)/sql \
                         -I$(srcdir)
-
-pkglib_LIBRARIES =	libcsv.a
-
 LDADD =
 
 DEFS =	@DEFS@
+noinst_HEADERS	  =	ha_tina.h
 
+EXTRA_LTLIBRARIES =	ha_csv.la
+pkglib_LTLIBRARIES =	@plugin_csv_shared_target@
+ha_csv_la_LDFLAGS =	-module -rpath $(MYSQLLIBdir)
+ha_csv_la_CXXFLAGS =	$(AM_CFLAGS) -DMYSQL_PLUGIN
+ha_csv_la_SOURCES =	ha_tina.cc
+
+EXTRA_LIBRARIES =	libcsv.a
+noinst_LIBRARIES =	@plugin_csv_static_target@
 libcsv_a_CXXFLAGS =	$(AM_CFLAGS)
-noinst_HEADERS = 	ha_tina.h
 libcsv_a_SOURCES =	ha_tina.cc
 
 # Don't update the files from bitkeeper
diff --git a/storage/csv/ha_tina.cc b/storage/csv/ha_tina.cc
index aed861279d9..8b1cfe71fa2 100644
--- a/storage/csv/ha_tina.cc
+++ b/storage/csv/ha_tina.cc
@@ -1398,8 +1398,8 @@ bool ha_tina::check_if_incompatible_data(HA_CREATE_INFO *info,
   return COMPATIBLE_DATA_YES;
 }
 
-#ifdef MYSQL_PLUGIN
-mysql_declare_plugin
+
+mysql_declare_plugin(csv)
 {
   MYSQL_STORAGE_ENGINE_PLUGIN,
   &tina_hton,
@@ -1411,4 +1411,4 @@ mysql_declare_plugin
   0x0100 /* 1.0 */,
 }
 mysql_declare_plugin_end;
-#endif
+
diff --git a/storage/example/Makefile.am b/storage/example/Makefile.am
index 518d82abe2d..5565c5e85fc 100644
--- a/storage/example/Makefile.am
+++ b/storage/example/Makefile.am
@@ -1,15 +1,15 @@
 # Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult 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; either version 2 of the License, or
 # (at your option) any later version.
-#
+# 
 # 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
@@ -26,14 +26,26 @@ INCLUDES =              -I$(top_srcdir)/include \
                         -I$(srcdir)
 WRAPLIBS=
 
-pkglib_LIBRARIES =	libexample.a
-
-noinst_HEADERS	      =	ha_example.h
-libexample_a_SOURCES =	ha_example.cc
-EXTRA_DIST	      = cmakelists.txt
 LDADD =
 
-DEFS =                  -DMYSQL_SERVER @DEFS@
+DEFS =                  @DEFS@
+
+noinst_HEADERS =	ha_example.h
+
+EXTRA_LTLIBRARIES =	ha_example.la
+pkglib_LTLIBRARIES =	@plugin_example_shared_target@
+ha_example_la_LDFLAGS =	-module -rpath $(MYSQLLIBdir)
+ha_example_la_CXXFLAGS=	$(AM_CFLAGS) -DMYSQL_DYNAMIC_PLUGIN
+ha_example_la_CFLAGS =	$(AM_CFLAGS) -DMYSQL_DYNAMIC_PLUGIN
+ha_example_la_SOURCES =	ha_example.cc
+
+
+EXTRA_LIBRARIES =	libexample.a
+noinst_LIBRARIES =	@plugin_example_static_target@
+libexample_a_CXXFLAGS =	$(AM_CFLAGS)
+libexample_a_CFLAGS =	$(AM_CFLAGS)
+libexample_a_SOURCES=	ha_example.cc
+
 
 # Don't update the files from bitkeeper
 %::SCCS/s.%
diff --git a/storage/example/ha_example.cc b/storage/example/ha_example.cc
index 433fc3e78e0..a8c5c63606f 100644
--- a/storage/example/ha_example.cc
+++ b/storage/example/ha_example.cc
@@ -726,8 +726,8 @@ int ha_example::create(const char *name, TABLE *table_arg,
   DBUG_RETURN(0);
 }
 
-#ifdef MYSQL_PLUGIN
-mysql_declare_plugin
+
+mysql_declare_plugin(example)
 {
   MYSQL_STORAGE_ENGINE_PLUGIN,
   &example_hton,
@@ -739,4 +739,4 @@ mysql_declare_plugin
   0x0001 /* 0.1 */,
 }
 mysql_declare_plugin_end;
-#endif
+
diff --git a/storage/innobase/Makefile.am b/storage/innobase/Makefile.am
index 22796b45882..8504d587e09 100644
--- a/storage/innobase/Makefile.am
+++ b/storage/innobase/Makefile.am
@@ -79,5 +79,34 @@ EXTRA_DIST = 	include/btr0btr.h include/btr0btr.ic include/btr0cur.h include/btr
 		include/ut0sort.h include/ut0ut.h include/ut0ut.ic \
 		cmakelists.txt
 
+noinst_LIBRARIES =	libinnobase.a
+libinnobase_a_LIBADD =	usr/libusr.a srv/libsrv.a dict/libdict.a \
+			que/libque.a srv/libsrv.a ibuf/libibuf.a \
+			row/librow.a pars/libpars.a btr/libbtr.a \
+			trx/libtrx.a read/libread.a usr/libusr.a \
+			buf/libbuf.a ibuf/libibuf.a eval/libeval.a \
+			log/liblog.a fsp/libfsp.a fut/libfut.a \
+			fil/libfil.a lock/liblock.a mtr/libmtr.a \
+			page/libpage.a rem/librem.a thr/libthr.a \
+			sync/libsync.a data/libdata.a mach/libmach.a \
+			ha/libha.a dyn/libdyn.a mem/libmem.a \
+			ut/libut.a os/libos.a ut/libut.a
+libinnobase_a_SOURCES =	
+
+
+libinnobase.a:		$(libinnobase_a_LIBADD)
+		-rm -f $@
+		if test "$(host_os)" = "netware" ; \
+		then \
+		  $(libmysqld_a_AR) $@ $(libinnobase_a_LIBADD) ; \
+		else \
+		  (for arc in $(libinnobase_a_LIBADD); do \
+		    arpath=`echo $$arc|sed 's|[^/]*$$||'`; \
+		    $(AR) t $$arc|xargs -n 1 find $$arpath -name; \
+		    $(AR) t $$arc|xargs -n 1 find `dirname $$arpath` -path \*/`basename $$arpath`/\* -name; \
+		  done ) | sort -u | xargs $(AR) cq $@ ; \
+		  $(RANLIB) $@	; \
+		fi
+
 # Don't update the files from bitkeeper
 %::SCCS/s.%

From faee72a936226d7ebb2740375418f2966b86e38a Mon Sep 17 00:00:00 2001
From: "bar@mysql.com" <>
Date: Mon, 17 Apr 2006 11:49:20 +0500
Subject: [PATCH 010/108] Bug#18170: XML: ExtractValue(): XPath expression
 can't use QNames (colon in names)

Problem source:
Qualified names (aka QName) didn't work as tag names and attribute names,
because the parser lacked a real rule to scan QName, so it understood
only non-qualified names without prefixes.

Solution:
New rule was added to check both "ident" and "ident:ident" sequences.
---
 mysql-test/r/xml.result |  9 +++++++++
 mysql-test/t/xml.test   |  8 ++++++++
 sql/item_xmlfunc.cc     | 26 +++++++++++++++++++++++++-
 3 files changed, 42 insertions(+), 1 deletion(-)

diff --git a/mysql-test/r/xml.result b/mysql-test/r/xml.result
index 7e44673dd78..fdc06a0a2e6 100644
--- a/mysql-test/r/xml.result
+++ b/mysql-test/r/xml.result
@@ -641,3 +641,12 @@ CALL p2();
 EXTRACTVALUE(p,'/Ñ/r')
 A
 DROP PROCEDURE p2;
+select extractValue('','count(ns:element)');
+extractValue('','count(ns:element)')
+1
+select extractValue('a','/ns:element');
+extractValue('a','/ns:element')
+a
+select extractValue('a','/ns:element/@xmlns:ns');
+extractValue('a','/ns:element/@xmlns:ns')
+myns
diff --git a/mysql-test/t/xml.test b/mysql-test/t/xml.test
index 8ed623883b6..d3e2da46413 100644
--- a/mysql-test/t/xml.test
+++ b/mysql-test/t/xml.test
@@ -321,3 +321,11 @@ END//
 DELIMITER ;//
 CALL p2();
 DROP PROCEDURE p2;
+
+#
+# Bug#18170: XML: ExtractValue():
+# XPath expression can't use QNames (colon in names)
+#
+select extractValue('','count(ns:element)');
+select extractValue('a','/ns:element');
+select extractValue('a','/ns:element/@xmlns:ns');
diff --git a/sql/item_xmlfunc.cc b/sql/item_xmlfunc.cc
index 71900c26c2d..2e70b896af7 100644
--- a/sql/item_xmlfunc.cc
+++ b/sql/item_xmlfunc.cc
@@ -2266,6 +2266,30 @@ static int my_xpath_parse_Number(MY_XPATH *xpath)
 }
 
 
+/*
+  QName grammar can be found in a separate document
+  http://www.w3.org/TR/REC-xml-names/#NT-QName
+
+  [6] 	QName     ::= (Prefix ':')? LocalPart
+  [7] 	Prefix    ::= NCName
+  [8] 	LocalPart ::= NCName
+*/
+static int
+my_xpath_parse_QName(MY_XPATH *xpath)
+{
+  const char *beg;
+  if (!my_xpath_parse_term(xpath, MY_XPATH_LEX_IDENT))
+    return 0;
+  beg= xpath->prevtok.beg;
+  if (!my_xpath_parse_term(xpath, MY_XPATH_LEX_COLON))
+    return 1; /* Non qualified name */
+  if (!my_xpath_parse_term(xpath, MY_XPATH_LEX_IDENT))
+    return 0;
+  xpath->prevtok.beg= beg;
+  return 1;
+}
+
+
 /*
   Scan Variable reference
 
@@ -2299,7 +2323,7 @@ my_xpath_parse_VariableReference(MY_XPATH *xpath)
 static int
 my_xpath_parse_NodeTest_QName(MY_XPATH *xpath)
 {
-  if (!my_xpath_parse_term(xpath, MY_XPATH_LEX_IDENT))
+  if (!my_xpath_parse_QName(xpath))
     return 0;
   DBUG_ASSERT(xpath->context);
   uint len= xpath->prevtok.end - xpath->prevtok.beg;

From 13062cbad63ec17b47865ceb13718771db060a9b Mon Sep 17 00:00:00 2001
From: "msvensson@shellback.(none)" <>
Date: Tue, 18 Apr 2006 10:46:17 +0200
Subject: [PATCH 011/108] BUG#13310 incorrect user parsing by SP  - Strip
 surrounding ''s from username when a new user connects. There    is no user
 'a@', it should be a@

---
 mysql-test/r/grant2.result | 13 +++++++++++++
 mysql-test/t/grant2.test   | 25 +++++++++++++++++++++++++
 sql/sql_parse.cc           | 15 ++++++++++++---
 3 files changed, 50 insertions(+), 3 deletions(-)

diff --git a/mysql-test/r/grant2.result b/mysql-test/r/grant2.result
index a42ad0d79a5..fa25df3203f 100644
--- a/mysql-test/r/grant2.result
+++ b/mysql-test/r/grant2.result
@@ -356,3 +356,16 @@ insert into mysql.user select * from t1;
 drop table t1, t2;
 drop database TESTDB;
 flush privileges;
+grant all privileges on test.* to `a@`@localhost;
+grant execute on * to `a@`@localhost;
+create table t2 (s1 int);
+insert into t2 values (1);
+drop function if exists f2;
+create function f2 () returns int begin declare v int; select s1 from t2
+into v; return v; end//
+select f2();
+f2()
+1
+drop function f2;
+drop table t2;
+REVOKE ALL PRIVILEGES, GRANT OPTION FROM `a@`@localhost;
diff --git a/mysql-test/t/grant2.test b/mysql-test/t/grant2.test
index 2c62d2f1bd3..32232360afa 100644
--- a/mysql-test/t/grant2.test
+++ b/mysql-test/t/grant2.test
@@ -465,3 +465,28 @@ drop table t1, t2;
 drop database TESTDB;
 flush privileges;
 
+#
+# BUG#13310 incorrect user parsing by SP
+#
+
+grant all privileges on test.* to `a@`@localhost;
+grant execute on * to `a@`@localhost;
+connect (bug13310,localhost,'a@',,test);
+connection bug13310;
+create table t2 (s1 int);
+insert into t2 values (1);
+--disable_warnings
+drop function if exists f2;
+--enable_warnings
+delimiter //;
+create function f2 () returns int begin declare v int; select s1 from t2
+into v; return v; end//
+delimiter ;//
+select f2();
+
+drop function f2;
+drop table t2;
+disconnect bug13310;
+
+connection default;
+REVOKE ALL PRIVILEGES, GRANT OPTION FROM `a@`@localhost;
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index d9f5499f362..e163a7a1093 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -993,6 +993,7 @@ static int check_connection(THD *thd)
 
   char *user= end;
   char *passwd= strend(user)+1;
+  uint user_len= passwd - user - 1;
   char *db= passwd;
   char db_buff[NAME_LEN+1];                     // buffer to store db in utf8
   char user_buff[USERNAME_LENGTH+1];		// buffer to store user in utf8
@@ -1018,11 +1019,19 @@ static int check_connection(THD *thd)
     db= db_buff;
   }
 
-  user_buff[copy_and_convert(user_buff, sizeof(user_buff)-1,
-                             system_charset_info, user, strlen(user),
-                             thd->charset(), &dummy_errors)]= '\0';
+  user_buff[user_len= copy_and_convert(user_buff, sizeof(user_buff)-1,
+                                       system_charset_info, user, user_len,
+                                       thd->charset(), &dummy_errors)]= '\0';
   user= user_buff;
 
+  /* If username starts and ends in "'", chop them off */
+  if (user_len > 1 && user[0] == '\'' && user[user_len - 1] == '\'')
+  {
+    user[user_len-1]= 0;
+    user++;
+    user_len-= 2;
+  }
+
   if (thd->main_security_ctx.user)
     x_free(thd->main_security_ctx.user);
   if (!(thd->main_security_ctx.user= my_strdup(user, MYF(0))))

From 0d1bd3b1f28a22b8d69138787f2ca0bd16be3c3f Mon Sep 17 00:00:00 2001
From: "msvensson@shellback.(none)" <>
Date: Tue, 18 Apr 2006 14:41:43 +0200
Subject: [PATCH 012/108] Import from yaSSL upstream

---
 extra/yassl/include/openssl/rsa.h            |  2 +-
 extra/yassl/include/openssl/ssl.h            |  3 ++-
 extra/yassl/include/yassl_int.hpp            |  4 ----
 extra/yassl/include/yassl_types.hpp          |  5 ++++
 extra/yassl/mySTL/helpers.hpp                | 12 ++++------
 extra/yassl/mySTL/list.hpp                   |  4 ++--
 extra/yassl/mySTL/vector.hpp                 |  3 ++-
 extra/yassl/src/handshake.cpp                | 16 ++++++++-----
 extra/yassl/src/socket_wrapper.cpp           | 10 +++++---
 extra/yassl/src/ssl.cpp                      |  4 ++++
 extra/yassl/src/yassl_imp.cpp                |  1 +
 extra/yassl/src/yassl_int.cpp                | 20 ++++++++++++----
 extra/yassl/taocrypt/benchmark/benchmark.cpp | 12 +++++-----
 extra/yassl/taocrypt/include/integer.hpp     |  3 ---
 extra/yassl/taocrypt/include/misc.hpp        | 12 +++++++++-
 extra/yassl/taocrypt/include/runtime.hpp     | 24 +++++++++++++++++---
 extra/yassl/taocrypt/include/types.hpp       |  2 ++
 extra/yassl/taocrypt/src/algebra.cpp         |  4 +++-
 extra/yassl/taocrypt/src/integer.cpp         | 20 ++++++++++++----
 extra/yassl/taocrypt/src/misc.cpp            |  1 -
 extra/yassl/taocrypt/src/random.cpp          |  3 +++
 extra/yassl/taocrypt/src/template_instnt.cpp |  9 ++++++++
 22 files changed, 125 insertions(+), 49 deletions(-)

diff --git a/extra/yassl/include/openssl/rsa.h b/extra/yassl/include/openssl/rsa.h
index 1ab9d13b89f..fe64e655bdc 100644
--- a/extra/yassl/include/openssl/rsa.h
+++ b/extra/yassl/include/openssl/rsa.h
@@ -1,7 +1,7 @@
 /* rsa.h for openSSL */
 
 
-#ifndef ysSSL_rsa_h__
+#ifndef yaSSL_rsa_h__
 #define yaSSL_rsa_h__
 
 enum { RSA_F4 = 1 };
diff --git a/extra/yassl/include/openssl/ssl.h b/extra/yassl/include/openssl/ssl.h
index d6b91bc66c4..b6840d006df 100644
--- a/extra/yassl/include/openssl/ssl.h
+++ b/extra/yassl/include/openssl/ssl.h
@@ -25,7 +25,7 @@
 
 
 
-#ifndef ysSSL_openssl_h__
+#ifndef yaSSL_openssl_h__
 #define yaSSL_openssl_h__
 
 #include    /* ERR_print fp */
@@ -345,6 +345,7 @@ long SSL_CTX_sess_set_cache_size(SSL_CTX*, long);
 long SSL_CTX_set_tmp_dh(SSL_CTX*, DH*);
 
 void OpenSSL_add_all_algorithms(void);
+void SSL_library_init();
 void SSLeay_add_ssl_algorithms(void);
 
 
diff --git a/extra/yassl/include/yassl_int.hpp b/extra/yassl/include/yassl_int.hpp
index ce22d4edb1d..935bae582ea 100644
--- a/extra/yassl/include/yassl_int.hpp
+++ b/extra/yassl/include/yassl_int.hpp
@@ -121,8 +121,6 @@ public:
 
     friend sslFactory& GetSSL_Factory();        // singleton creator
 private:
-    static sslFactory instance_;
-
     sslFactory(const sslFactory&);              // hide copy
     sslFactory& operator=(const sslFactory&);   // and assign   
 };
@@ -214,8 +212,6 @@ public:
 
     friend Sessions& GetSessions(); // singleton creator
 private:
-    static Sessions instance_;
-
     Sessions(const Sessions&);              // hide copy
     Sessions& operator=(const Sessions&);   // and assign
 };
diff --git a/extra/yassl/include/yassl_types.hpp b/extra/yassl/include/yassl_types.hpp
index be219d2cead..bfb6467182b 100644
--- a/extra/yassl/include/yassl_types.hpp
+++ b/extra/yassl/include/yassl_types.hpp
@@ -34,6 +34,11 @@
 
 namespace yaSSL {
 
+
+// Delete static singleton memory holders
+void CleanUp();
+
+
 #ifdef YASSL_PURE_C
 
     // library allocation
diff --git a/extra/yassl/mySTL/helpers.hpp b/extra/yassl/mySTL/helpers.hpp
index 8d2061fc4f1..5aa14d838b1 100644
--- a/extra/yassl/mySTL/helpers.hpp
+++ b/extra/yassl/mySTL/helpers.hpp
@@ -28,14 +28,14 @@
 #define mySTL_HELPERS_HPP
 
 #include 
-#include         // placement new
+#ifdef _MSC_VER
+    #include 
+#endif
 
-
-
-#ifdef __IBMCPP__
 /*
       Workaround for the lack of operator new(size_t, void*)
       in IBM VA C++ 6.0
+      Also used as a workaround to avoid including 
 */
     struct Dummy {};
 
@@ -45,10 +45,6 @@
     }
 
     typedef Dummy* yassl_pointer;
-#else
-    typedef void*  yassl_pointer;
-#endif
-
 
 namespace mySTL {
 
diff --git a/extra/yassl/mySTL/list.hpp b/extra/yassl/mySTL/list.hpp
index 8aaeefaafe8..dd8485f48a7 100644
--- a/extra/yassl/mySTL/list.hpp
+++ b/extra/yassl/mySTL/list.hpp
@@ -164,7 +164,7 @@ void list::push_front(T t)
 {
     void* mem = malloc(sizeof(node));
     if (!mem) abort();
-    node* add = new (mem) node(t);
+    node* add = new (reinterpret_cast(mem)) node(t);
 
     if (head_) {
         add->next_ = head_;
@@ -210,7 +210,7 @@ void list::push_back(T t)
 {
     void* mem = malloc(sizeof(node));
     if (!mem) abort();
-    node* add = new (mem) node(t);
+    node* add = new (reinterpret_cast(mem)) node(t);
 
     if (tail_) {
         tail_->next_ = add;
diff --git a/extra/yassl/mySTL/vector.hpp b/extra/yassl/mySTL/vector.hpp
index e7f63c37c7c..9eab91cfda8 100644
--- a/extra/yassl/mySTL/vector.hpp
+++ b/extra/yassl/mySTL/vector.hpp
@@ -45,7 +45,8 @@ struct vector_base {
     vector_base() : start_(0), finish_(0), end_of_storage_(0) {}
     vector_base(size_t n)
     {
-        start_ = static_cast(malloc(n * sizeof(T)));
+        // Don't allow malloc(0), if n is 0 use 1
+        start_ = static_cast(malloc((n ? n : 1) * sizeof(T)));
         if (!start_) abort();
         finish_ = start_;
         end_of_storage_ = start_ + n;
diff --git a/extra/yassl/src/handshake.cpp b/extra/yassl/src/handshake.cpp
index 534e91e8989..2603365e41a 100644
--- a/extra/yassl/src/handshake.cpp
+++ b/extra/yassl/src/handshake.cpp
@@ -650,7 +650,6 @@ void build_certHashes(SSL& ssl, Hashes& hashes)
 }
 
 
-mySTL::auto_ptr null_buffer(ysDelete);
 
 // do process input requests
 mySTL::auto_ptr
@@ -659,7 +658,8 @@ DoProcessReply(SSL& ssl, mySTL::auto_ptr buffered)
     // wait for input if blocking
     if (!ssl.getSocket().wait()) {
       ssl.SetError(receive_error);
-        return buffered = null_buffer;
+        buffered.reset(0);
+        return buffered;
     }
     uint ready = ssl.getSocket().get_ready();
     if (!ready) return buffered; 
@@ -669,10 +669,10 @@ DoProcessReply(SSL& ssl, mySTL::auto_ptr buffered)
     input_buffer buffer(buffSz + ready);
     if (buffSz) {
         buffer.assign(buffered.get()->get_buffer(), buffSz);
-        buffered = null_buffer;
+        buffered.reset(0);
     }
 
-    // add NEW_YS data
+    // add new data
     uint read  = ssl.getSocket().receive(buffer.get_buffer() + buffSz, ready);
     buffer.add_size(read);
     uint offset = 0;
@@ -705,11 +705,15 @@ DoProcessReply(SSL& ssl, mySTL::auto_ptr buffered)
             mySTL::auto_ptr msg(mf.CreateObject(hdr.type_), ysDelete);
             if (!msg.get()) {
                 ssl.SetError(factory_error);
-                return buffered = null_buffer;
+                buffered.reset(0);
+                return buffered;
             }
             buffer >> *msg;
             msg->Process(buffer, ssl);
-            if (ssl.GetError()) return buffered = null_buffer;
+            if (ssl.GetError()) {
+                buffered.reset(0);
+                return buffered;
+            }
         }
         offset += hdr.length_ + RECORD_HEADER;
     }
diff --git a/extra/yassl/src/socket_wrapper.cpp b/extra/yassl/src/socket_wrapper.cpp
index f43a4925447..c6611803421 100644
--- a/extra/yassl/src/socket_wrapper.cpp
+++ b/extra/yassl/src/socket_wrapper.cpp
@@ -39,7 +39,7 @@
     #include 
 #endif // _WIN32
 
-#ifdef __sun
+#if defined(__sun) || defined(__SCO_VERSION__)
     #include 
 #endif
 
@@ -95,11 +95,15 @@ void Socket::closeSocket()
 
 uint Socket::get_ready() const
 {
-    unsigned long ready = 0;
-
 #ifdef _WIN32
+    unsigned long ready = 0;
     ioctlsocket(socket_, FIONREAD, &ready);
 #else
+    /*
+       64-bit Solaris requires the variable passed to
+       FIONREAD be a 32-bit value.
+    */
+    unsigned int ready = 0;
     ioctl(socket_, FIONREAD, &ready);
 #endif
 
diff --git a/extra/yassl/src/ssl.cpp b/extra/yassl/src/ssl.cpp
index 7cc0d592822..1aab14009d3 100644
--- a/extra/yassl/src/ssl.cpp
+++ b/extra/yassl/src/ssl.cpp
@@ -723,6 +723,10 @@ void OpenSSL_add_all_algorithms()  // compatibility only
 {}
 
 
+void SSL_library_init()  // compatiblity only
+{}
+
+
 DH* DH_new(void)
 {
     DH* dh = NEW_YS DH;
diff --git a/extra/yassl/src/yassl_imp.cpp b/extra/yassl/src/yassl_imp.cpp
index f5c6acba10c..1d2d5396ea0 100644
--- a/extra/yassl/src/yassl_imp.cpp
+++ b/extra/yassl/src/yassl_imp.cpp
@@ -1329,6 +1329,7 @@ input_buffer& operator>>(input_buffer& input, ClientHello& hello)
 
     // Compression
     hello.comp_len_ = input[AUTO];
+    while (hello.comp_len_--)  // ignore for now
     hello.compression_methods_ = CompressionMethod(input[AUTO]);
 
     return input;
diff --git a/extra/yassl/src/yassl_int.cpp b/extra/yassl/src/yassl_int.cpp
index ab5c829a570..cab1932a9e6 100644
--- a/extra/yassl/src/yassl_int.cpp
+++ b/extra/yassl/src/yassl_int.cpp
@@ -1363,19 +1363,31 @@ SSL_SESSION::~SSL_SESSION()
 }
 
 
-Sessions Sessions::instance_; // simple singleton
+static Sessions* sessionsInstance = 0;
 
 Sessions& GetSessions()
 {
-    return Sessions::instance_;
+    if (!sessionsInstance)
+        sessionsInstance = NEW_YS Sessions;
+    return *sessionsInstance;
 }
 
 
-sslFactory sslFactory::instance_; // simple singleton
+static sslFactory* sslFactoryInstance = 0;
 
 sslFactory& GetSSL_Factory()
 {   
-    return sslFactory::instance_;
+    if (!sslFactoryInstance)
+        sslFactoryInstance = NEW_YS sslFactory;
+    return *sslFactoryInstance;
+}
+
+
+void CleanUp()
+{
+    TaoCrypt::CleanUp();
+    ysDelete(sslFactoryInstance);
+    ysDelete(sessionsInstance);
 }
 
 
diff --git a/extra/yassl/taocrypt/benchmark/benchmark.cpp b/extra/yassl/taocrypt/benchmark/benchmark.cpp
index 2905e7df6a9..bb725a90187 100644
--- a/extra/yassl/taocrypt/benchmark/benchmark.cpp
+++ b/extra/yassl/taocrypt/benchmark/benchmark.cpp
@@ -284,7 +284,7 @@ void bench_rsa()
     double each  = total / times;   // per second
     double milliEach = each * 1000; // milliseconds
 
-    printf("RSA 1024 encryption took  %3.2f milliseconds, avg over %d" 
+    printf("RSA 1024 encryption took %6.2f milliseconds, avg over %d" 
            " iterations\n", milliEach, times);
 
     RSAES_Decryptor dec(priv);
@@ -298,7 +298,7 @@ void bench_rsa()
     each  = total / times;   // per second
     milliEach = each * 1000; // milliseconds
 
-    printf("RSA 1024 decryption took %3.2f milliseconds, avg over %d" 
+    printf("RSA 1024 decryption took %6.2f milliseconds, avg over %d" 
            " iterations\n", milliEach, times);
 }
 
@@ -329,7 +329,7 @@ void bench_dh()
     double each  = total / times;   // per second
     double milliEach = each * 1000; // milliseconds
 
-    printf("DH  1024 key generation   %3.2f milliseconds, avg over %d" 
+    printf("DH  1024 key generation  %6.2f milliseconds, avg over %d" 
            " iterations\n", milliEach, times);
 
     DH dh2(dh); 
@@ -347,7 +347,7 @@ void bench_dh()
     each  = total / times;      // per second
     milliEach = each * 1000;   //  in milliseconds
 
-    printf("DH  1024 key agreement    %3.2f milliseconds, avg over %d"
+    printf("DH  1024 key agreement   %6.2f milliseconds, avg over %d"
            " iterations\n", milliEach, times);
 }
 
@@ -383,7 +383,7 @@ void bench_dsa()
     double each  = total / times;   // per second
     double milliEach = each * 1000; // milliseconds
 
-    printf("DSA 1024 sign   took      %3.2f milliseconds, avg over %d" 
+    printf("DSA 1024 sign   took     %6.2f milliseconds, avg over %d" 
            " iterations\n", milliEach, times);
 
     DSA_Verifier verifier(key);
@@ -397,7 +397,7 @@ void bench_dsa()
     each  = total / times;      // per second
     milliEach = each * 1000;   //  in milliseconds
 
-    printf("DSA 1024 verify took      %3.2f milliseconds, avg over %d"
+    printf("DSA 1024 verify took     %6.2f milliseconds, avg over %d"
            " iterations\n", milliEach, times);
 }
 
diff --git a/extra/yassl/taocrypt/include/integer.hpp b/extra/yassl/taocrypt/include/integer.hpp
index 76034c3ae8f..ee83906cfbc 100644
--- a/extra/yassl/taocrypt/include/integer.hpp
+++ b/extra/yassl/taocrypt/include/integer.hpp
@@ -274,9 +274,6 @@ private:
                                Integer& dividend, const Integer& divisor);
     AlignedWordBlock reg_;
     Sign             sign_;
-
-    static const Integer zero_;
-    static const Integer one_;
 };
 
 inline bool operator==(const Integer& a, const Integer& b) 
diff --git a/extra/yassl/taocrypt/include/misc.hpp b/extra/yassl/taocrypt/include/misc.hpp
index 7a71784893f..fc632208e76 100644
--- a/extra/yassl/taocrypt/include/misc.hpp
+++ b/extra/yassl/taocrypt/include/misc.hpp
@@ -40,6 +40,11 @@
 
 namespace TaoCrypt {
 
+
+// Delete static singleton holders
+void CleanUp();
+
+
 #ifdef YASSL_PURE_C
 
     // library allocation
@@ -123,7 +128,12 @@ namespace TaoCrypt {
 
 
 // no gas on these systems ?, disable for now
-#if defined(__sun__) || defined (__QNX__)
+#if defined(__sun__) || defined (__QNX__) || defined (__APPLE__)
+    #define TAOCRYPT_DISABLE_X86ASM
+#endif
+
+// icc problem with -03 and integer, disable for now
+#if defined(__INTEL_COMPILER)
     #define TAOCRYPT_DISABLE_X86ASM
 #endif
 
diff --git a/extra/yassl/taocrypt/include/runtime.hpp b/extra/yassl/taocrypt/include/runtime.hpp
index aae4581cc40..3a5cf62865a 100644
--- a/extra/yassl/taocrypt/include/runtime.hpp
+++ b/extra/yassl/taocrypt/include/runtime.hpp
@@ -25,10 +25,27 @@
 
 
 
-#if !defined(yaSSL_NEW_HPP) && defined(__GNUC__) && !defined(__ICC)
-
+#ifndef yaSSL_NEW_HPP
 #define yaSSL_NEW_HPP
 
+
+#ifdef __sun
+ 
+#include 
+
+// Handler for pure virtual functions
+namespace __Crun {
+    static void pure_error(void)
+    {
+       assert("Pure virtual method called." == "Aborted");
+    }
+} // namespace __Crun
+
+#endif // __sun
+
+
+#if defined(__GNUC__) && !(defined(__ICC) || defined(__INTEL_COMPILER))
+
 #if __GNUC__ > 2
 
 extern "C" {
@@ -50,5 +67,6 @@ static int __cxa_pure_virtual()
 } // extern "C"
 
 #endif // __GNUC__ > 2
-#endif // yaSSL_NEW_HPP && __GNUC__
+#endif // compiler check
+#endif // yaSSL_NEW_HPP
 
diff --git a/extra/yassl/taocrypt/include/types.hpp b/extra/yassl/taocrypt/include/types.hpp
index 92164eaaab4..a2453a994fb 100644
--- a/extra/yassl/taocrypt/include/types.hpp
+++ b/extra/yassl/taocrypt/include/types.hpp
@@ -61,7 +61,9 @@ typedef unsigned int   word32;
 
 // compilers we've found 64-bit multiply insructions for
 #if defined(__GNUC__) || defined(_MSC_VER) || defined(__DECCXX)
+    #if !(defined(__ICC) || defined(__INTEL_COMPILER))
     #define HAVE_64_MULTIPLY
+    #endif
 #endif
 
     
diff --git a/extra/yassl/taocrypt/src/algebra.cpp b/extra/yassl/taocrypt/src/algebra.cpp
index 9249289d505..9c485609dd0 100644
--- a/extra/yassl/taocrypt/src/algebra.cpp
+++ b/extra/yassl/taocrypt/src/algebra.cpp
@@ -78,7 +78,9 @@ const Integer& AbstractEuclideanDomain::Mod(const Element &a,
 const Integer& AbstractEuclideanDomain::Gcd(const Element &a,
                                             const Element &b) const
 {
-    Element g[3]={b, a};
+    mySTL::vector g(3);
+    g[0]= b;
+    g[1]= a;
     unsigned int i0=0, i1=1, i2=2;
 
     while (!Equal(g[i1], this->Identity()))
diff --git a/extra/yassl/taocrypt/src/integer.cpp b/extra/yassl/taocrypt/src/integer.cpp
index 083c5bf7d30..f50175b9b67 100644
--- a/extra/yassl/taocrypt/src/integer.cpp
+++ b/extra/yassl/taocrypt/src/integer.cpp
@@ -2709,22 +2709,34 @@ unsigned int Integer::Encode(byte* output, unsigned int outputLen,
 }
 
 
-const Integer Integer::zero_;
+static Integer* zero = 0;
 
 const Integer &Integer::Zero()
 {
-    return zero_;
+    if (!zero)
+        zero = NEW_TC Integer;
+    return *zero;
 }
 
 
-const Integer Integer::one_(1,2);
+static Integer* one = 0;
 
 const Integer &Integer::One()
 {
-    return one_;
+    if (!one)
+        one = NEW_TC Integer(1,2);
+    return *one;
 }
 
 
+// Clean up static singleton holders, not a leak, but helpful to have gone
+// when checking for leaks
+void CleanUp()
+{
+    tcDelete(one);
+    tcDelete(zero);
+}
+
 Integer::Integer(RandomNumberGenerator& rng, const Integer& min,
                  const Integer& max)
 {
diff --git a/extra/yassl/taocrypt/src/misc.cpp b/extra/yassl/taocrypt/src/misc.cpp
index 9a35daff240..3d0539187a7 100644
--- a/extra/yassl/taocrypt/src/misc.cpp
+++ b/extra/yassl/taocrypt/src/misc.cpp
@@ -24,7 +24,6 @@
 
 #include "runtime.hpp"
 #include "misc.hpp"
-#include         // for NewHandler
 
 #ifdef YASSL_PURE_C
 
diff --git a/extra/yassl/taocrypt/src/random.cpp b/extra/yassl/taocrypt/src/random.cpp
index 6aaa626b648..945a7fa6ff7 100644
--- a/extra/yassl/taocrypt/src/random.cpp
+++ b/extra/yassl/taocrypt/src/random.cpp
@@ -97,8 +97,11 @@ void OS_Seed::GenerateSeed(byte* output, word32 sz)
 OS_Seed::OS_Seed() 
 {
     fd_ = open("/dev/urandom",O_RDONLY);
+    if (fd_ == -1) {
+        fd_ = open("/dev/random",O_RDONLY);
     if (fd_ == -1)
         error_.SetError(OPEN_RAN_E);
+    }
 }
 
 
diff --git a/extra/yassl/taocrypt/src/template_instnt.cpp b/extra/yassl/taocrypt/src/template_instnt.cpp
index 9a3c12badfc..557224067ce 100644
--- a/extra/yassl/taocrypt/src/template_instnt.cpp
+++ b/extra/yassl/taocrypt/src/template_instnt.cpp
@@ -24,8 +24,13 @@
  */
 
 
+#include "runtime.hpp"
 #include "integer.hpp"
 #include "rsa.hpp"
+#include "sha.hpp"
+#include "md5.hpp"
+#include "hmac.hpp"
+#include "pwdbased.hpp"
 #include "algebra.hpp"
 #include "vector.hpp"
 #include "hash.hpp"
@@ -52,6 +57,10 @@ template AllocatorWithCleanup::pointer StdReallocate(char*);
+
+template class PBKDF2_HMAC;
+template class HMAC;
+template class HMAC;
 }
 
 namespace mySTL {

From 3f683e2ba4eb8f823e66fa703fbe871b6fee4e65 Mon Sep 17 00:00:00 2001
From: "msvensson@neptunus.(none)" <>
Date: Tue, 18 Apr 2006 18:10:47 +0200
Subject: [PATCH 013/108] Cleanup test cases that leaves "stuff" behind

---
 mysql-test/r/ctype_latin2_ch.result | 1 +
 mysql-test/r/grant2.result          | 1 +
 mysql-test/r/openssl_1.result       | 5 ++---
 mysql-test/r/rpl_openssl.result     | 3 ++-
 mysql-test/r/sp-security.result     | 1 +
 mysql-test/r/sp_notembedded.result  | 1 +
 mysql-test/r/trigger.result         | 2 +-
 mysql-test/t/ctype_latin2_ch.test   | 2 ++
 mysql-test/t/grant2.test            | 1 +
 mysql-test/t/openssl_1.test         | 6 +++---
 mysql-test/t/rpl_openssl.test       | 1 +
 mysql-test/t/sp-security.test       | 1 +
 mysql-test/t/sp_notembedded.test    | 1 +
 mysql-test/t/trigger.test           | 2 +-
 14 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/mysql-test/r/ctype_latin2_ch.result b/mysql-test/r/ctype_latin2_ch.result
index 2b3765c07c4..5b607872737 100644
--- a/mysql-test/r/ctype_latin2_ch.result
+++ b/mysql-test/r/ctype_latin2_ch.result
@@ -28,3 +28,4 @@ select * from t1 ignore index (primary) where tt like 'AA%';
 id	tt
 select * from t1 where tt like '%AA%';
 id	tt
+drop table t1;
diff --git a/mysql-test/r/grant2.result b/mysql-test/r/grant2.result
index fa25df3203f..eb9e95c40bd 100644
--- a/mysql-test/r/grant2.result
+++ b/mysql-test/r/grant2.result
@@ -369,3 +369,4 @@ f2()
 drop function f2;
 drop table t2;
 REVOKE ALL PRIVILEGES, GRANT OPTION FROM `a@`@localhost;
+drop user `a@`@localhost;
diff --git a/mysql-test/r/openssl_1.result b/mysql-test/r/openssl_1.result
index 77f2d5495a9..91382619b6c 100644
--- a/mysql-test/r/openssl_1.result
+++ b/mysql-test/r/openssl_1.result
@@ -38,7 +38,6 @@ f1
 5
 delete from t1;
 ERROR 42000: DELETE command denied to user 'ssl_user4'@'localhost' for table 't1'
-delete from mysql.user where user='ssl_user%';
-delete from mysql.db where user='ssl_user%';
-flush privileges;
+drop user ssl_user1@localhost, ssl_user2@localhost,
+ssl_user3@localhost, ssl_user4@localhost;
 drop table t1;
diff --git a/mysql-test/r/rpl_openssl.result b/mysql-test/r/rpl_openssl.result
index d916e9f2c5c..c10606bc03f 100644
--- a/mysql-test/r/rpl_openssl.result
+++ b/mysql-test/r/rpl_openssl.result
@@ -24,7 +24,8 @@ Slave_IO_State	Master_Host	Master_User	Master_Port	Connect_Retry	Master_Log_File
 stop slave;
 change master to master_user='root',master_password='', master_ssl=0;
 start slave;
+drop user replssl@localhost;
 drop table t1;
 show slave status;
 Slave_IO_State	Master_Host	Master_User	Master_Port	Connect_Retry	Master_Log_File	Read_Master_Log_Pos	Relay_Log_File	Relay_Log_Pos	Relay_Master_Log_File	Slave_IO_Running	Slave_SQL_Running	Replicate_Do_DB	Replicate_Ignore_DB	Replicate_Do_Table	Replicate_Ignore_Table	Replicate_Wild_Do_Table	Replicate_Wild_Ignore_Table	Last_Errno	Last_Error	Skip_Counter	Exec_Master_Log_Pos	Relay_Log_Space	Until_Condition	Until_Log_File	Until_Log_Pos	Master_SSL_Allowed	Master_SSL_CA_File	Master_SSL_CA_Path	Master_SSL_Cert	Master_SSL_Cipher	Master_SSL_Key	Seconds_Behind_Master
-#	127.0.0.1	root	MASTER_MYPORT	1	master-bin.000001	474	#	#	master-bin.000001	Yes	Yes							0		0	474	#	None		0	No	MYSQL_TEST_DIR/std_data/cacert.pem		MYSQL_TEST_DIR/std_data/client-cert.pem		MYSQL_TEST_DIR/std_data/client-key.pem	#
+#	127.0.0.1	root	MASTER_MYPORT	1	master-bin.000001	564	#	#	master-bin.000001	Yes	Yes							0		0	564	#	None		0	No	MYSQL_TEST_DIR/std_data/cacert.pem		MYSQL_TEST_DIR/std_data/client-cert.pem		MYSQL_TEST_DIR/std_data/client-key.pem	#
diff --git a/mysql-test/r/sp-security.result b/mysql-test/r/sp-security.result
index 896b6fa572c..04f2f58ba37 100644
--- a/mysql-test/r/sp-security.result
+++ b/mysql-test/r/sp-security.result
@@ -322,6 +322,7 @@ Warnings:
 Warning	1287	'SHOW INNODB STATUS' is deprecated; use 'SHOW ENGINE INNODB STATUS' instead
 GRANT EXECUTE ON PROCEDURE p1 TO user_bug7787@localhost;
 DROP DATABASE db_bug7787;
+drop user user_bug7787@localhost;
 use test;
 
 ---> connection: root
diff --git a/mysql-test/r/sp_notembedded.result b/mysql-test/r/sp_notembedded.result
index d434f5c32ce..e39ddd1d79d 100644
--- a/mysql-test/r/sp_notembedded.result
+++ b/mysql-test/r/sp_notembedded.result
@@ -204,3 +204,4 @@ drop procedure bug10100pv|
 drop procedure bug10100pd|
 drop procedure bug10100pc|
 drop view v1|
+drop table t3|
diff --git a/mysql-test/r/trigger.result b/mysql-test/r/trigger.result
index 681b805f547..f897af6d69f 100644
--- a/mysql-test/r/trigger.result
+++ b/mysql-test/r/trigger.result
@@ -949,7 +949,7 @@ insert into t1 values
 create function f2() returns int return (select max(b) from t2);
 insert into t2 select a, f2() from t1;
 load data infile '../std_data_ln/words.dat' into table t1 (a) set b:= f1();
-drop table t1;
+drop table t1, t2;
 drop function f1;
 drop function f2;
 DROP TABLE IF EXISTS t1;
diff --git a/mysql-test/t/ctype_latin2_ch.test b/mysql-test/t/ctype_latin2_ch.test
index 626d83fa17d..3925d02659d 100644
--- a/mysql-test/t/ctype_latin2_ch.test
+++ b/mysql-test/t/ctype_latin2_ch.test
@@ -28,3 +28,5 @@ select * from t1 ignore index (primary) where tt like 'AA%';
 select * from t1 where tt like '%AA%';
 
 # End of 4.1 tests
+
+drop table t1;
diff --git a/mysql-test/t/grant2.test b/mysql-test/t/grant2.test
index 32232360afa..2b9a273df7e 100644
--- a/mysql-test/t/grant2.test
+++ b/mysql-test/t/grant2.test
@@ -490,3 +490,4 @@ disconnect bug13310;
 
 connection default;
 REVOKE ALL PRIVILEGES, GRANT OPTION FROM `a@`@localhost;
+drop user `a@`@localhost;
diff --git a/mysql-test/t/openssl_1.test b/mysql-test/t/openssl_1.test
index 359b8b69a4d..4cc9113048f 100644
--- a/mysql-test/t/openssl_1.test
+++ b/mysql-test/t/openssl_1.test
@@ -48,9 +48,9 @@ select * from t1;
 delete from t1;
 
 connection default;
-delete from mysql.user where user='ssl_user%';
-delete from mysql.db where user='ssl_user%';
-flush privileges;
+drop user ssl_user1@localhost, ssl_user2@localhost,
+ssl_user3@localhost, ssl_user4@localhost;
+
 drop table t1;
 
 # End of 4.1 tests
diff --git a/mysql-test/t/rpl_openssl.test b/mysql-test/t/rpl_openssl.test
index e15eb9b179a..7d769ad448e 100644
--- a/mysql-test/t/rpl_openssl.test
+++ b/mysql-test/t/rpl_openssl.test
@@ -53,6 +53,7 @@ stop slave;
 change master to master_user='root',master_password='', master_ssl=0;
 start slave;
 connection master;
+drop user replssl@localhost;
 drop table t1;
 save_master_pos;
 connection slave;
diff --git a/mysql-test/t/sp-security.test b/mysql-test/t/sp-security.test
index f369dc64b0e..a8c3c0a22eb 100644
--- a/mysql-test/t/sp-security.test
+++ b/mysql-test/t/sp-security.test
@@ -545,6 +545,7 @@ GRANT EXECUTE ON PROCEDURE p1 TO user_bug7787@localhost;
 # Cleanup.
 
 DROP DATABASE db_bug7787;
+drop user user_bug7787@localhost;
 use test;
 
 
diff --git a/mysql-test/t/sp_notembedded.test b/mysql-test/t/sp_notembedded.test
index 3854297ec0c..4eb429156b2 100644
--- a/mysql-test/t/sp_notembedded.test
+++ b/mysql-test/t/sp_notembedded.test
@@ -258,5 +258,6 @@ drop procedure bug10100pv|
 drop procedure bug10100pd|
 drop procedure bug10100pc|
 drop view v1|
+drop table t3|
 
 delimiter ;|
diff --git a/mysql-test/t/trigger.test b/mysql-test/t/trigger.test
index a0b67b2204d..8f225b1ef0d 100644
--- a/mysql-test/t/trigger.test
+++ b/mysql-test/t/trigger.test
@@ -1111,7 +1111,7 @@ insert into t1 values
 create function f2() returns int return (select max(b) from t2);
 insert into t2 select a, f2() from t1;
 load data infile '../std_data_ln/words.dat' into table t1 (a) set b:= f1();
-drop table t1;
+drop table t1, t2;
 drop function f1;
 drop function f2;
 

From a965875aaaf005a0ac34afe737fb921b2a892e23 Mon Sep 17 00:00:00 2001
From: "msvensson@shellback.(none)" <>
Date: Wed, 19 Apr 2006 10:21:00 +0200
Subject: [PATCH 014/108] Import from upstream yaSSL

---
 extra/yassl/src/template_instnt.cpp          |   2 +
 extra/yassl/taocrypt/include/misc.hpp        |   2 +-
 extra/yassl/taocrypt/src/template_instnt.cpp |   1 +
 extra/yassl/taocrypt/test/test.cpp           | 108 +++++++++----------
 4 files changed, 55 insertions(+), 58 deletions(-)

diff --git a/extra/yassl/src/template_instnt.cpp b/extra/yassl/src/template_instnt.cpp
index 5ee57e76aed..c55ca39bec2 100644
--- a/extra/yassl/src/template_instnt.cpp
+++ b/extra/yassl/src/template_instnt.cpp
@@ -87,6 +87,8 @@ template void ysDelete(BulkCipher*);
 template void ysDelete(Digest*);
 template void ysDelete(X509*);
 template void ysDelete(Message*);
+template void ysDelete(sslFactory*);
+template void ysDelete(Sessions*);
 template void ysArrayDelete(unsigned char*);
 template void ysArrayDelete(char*);
 }
diff --git a/extra/yassl/taocrypt/include/misc.hpp b/extra/yassl/taocrypt/include/misc.hpp
index fc632208e76..0808d76ccdf 100644
--- a/extra/yassl/taocrypt/include/misc.hpp
+++ b/extra/yassl/taocrypt/include/misc.hpp
@@ -81,7 +81,7 @@ void CleanUp();
     ::operator delete[](ptr, TaoCrypt::tc);
     }
 
-    #define NEW_TC new (tc)
+    #define NEW_TC new (TaoCrypt::tc)
 
 
     // to resolve compiler generated operator delete on base classes with
diff --git a/extra/yassl/taocrypt/src/template_instnt.cpp b/extra/yassl/taocrypt/src/template_instnt.cpp
index 557224067ce..eabcc6d9779 100644
--- a/extra/yassl/taocrypt/src/template_instnt.cpp
+++ b/extra/yassl/taocrypt/src/template_instnt.cpp
@@ -46,6 +46,7 @@ template class RSA_Decryptor;
 template class RSA_Encryptor;
 template class RSA_Encryptor;
 template void tcDelete(HASH*);
+template void tcDelete(Integer*);
 template void tcArrayDelete(byte*);
 template AllocatorWithCleanup::pointer StdReallocate >(AllocatorWithCleanup&, byte*, AllocatorWithCleanup::size_type, AllocatorWithCleanup::size_type, bool);
 template void tcArrayDelete(word*);
diff --git a/extra/yassl/taocrypt/test/test.cpp b/extra/yassl/taocrypt/test/test.cpp
index c1f07cd4795..b8618b18d47 100644
--- a/extra/yassl/taocrypt/test/test.cpp
+++ b/extra/yassl/taocrypt/test/test.cpp
@@ -71,6 +71,7 @@ using TaoCrypt::DH;
 using TaoCrypt::EncodeDSA_Signature;
 using TaoCrypt::DecodeDSA_Signature;
 using TaoCrypt::PBKDF2_HMAC;
+using TaoCrypt::tcArrayDelete;
 
 
 
@@ -117,10 +118,36 @@ struct func_args {
 };
 
 
+/* 
+   DES, AES, Blowfish, and Twofish need aligned (4 byte) input/output for
+   processing, can turn this off by setting gpBlock(assumeAligned = false)
+   but would hurt performance.  yaSSL always uses dynamic memory so we have
+   at least 8 byte alignment.  This test tried to force alignment for stack
+   variables (for convenience) but some compiler versions and optimizations
+   seemed to be off.  So we have msgTmp variable which we copy into dynamic
+   memory at runtime to ensure proper alignment, along with plain/cipher.
+   Whew!
+*/
+const byte msgTmp[] = { // "now is the time for all " w/o trailing 0
+    0x6e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
+    0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
+    0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
+};
+
+byte* msg    = 0;   // for block cipher input
+byte* plain  = 0;   // for cipher decrypt comparison 
+byte* cipher = 0;   // block output
+
+
 void taocrypt_test(void* args)
 {
     ((func_args*)args)->return_code = -1; // error state
     
+    msg    = NEW_TC byte[24];
+    plain  = NEW_TC byte[24];
+    cipher = NEW_TC byte[24];
+
+    memcpy(msg, msgTmp, 24);
 
     int ret = 0;
     if ( (ret = sha_test()) ) 
@@ -193,6 +220,9 @@ void taocrypt_test(void* args)
     else
         printf( "PBKDF2   test passed!\n");
 
+    tcArrayDelete(cipher);
+    tcArrayDelete(plain);
+    tcArrayDelete(msg);
 
     ((func_args*)args)->return_code = ret;
 }
@@ -507,35 +537,26 @@ int des_test()
     DES_ECB_Encryption enc;
     DES_ECB_Decryption dec;
 
- 
+    const int sz = TaoCrypt::DES_BLOCK_SIZE * 3;
     const byte key[] = { 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef };
     const byte iv[] =  { 0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef };
 
-    const byte vector[] = { // "Now is the time for all " w/o trailing 0
-        0x4e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
-        0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
-        0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
-    };
-
-    byte plain[24];
-    byte cipher[24];
-
     enc.SetKey(key, sizeof(key));
-    enc.Process(cipher, vector, sizeof(vector));
+    enc.Process(cipher, msg, sz);
     dec.SetKey(key, sizeof(key));
-    dec.Process(plain, cipher, sizeof(cipher));
+    dec.Process(plain, cipher, sz);
 
-    if (memcmp(plain, vector, sizeof(plain)))
+    if (memcmp(plain, msg, sz))
         return -50;
 
     const byte verify1[] = 
     {
-        0x3f,0xa4,0x0e,0x8a,0x98,0x4d,0x48,0x15,
+        0xf9,0x99,0xb8,0x8e,0xaf,0xea,0x71,0x53,
         0x6a,0x27,0x17,0x87,0xab,0x88,0x83,0xf9,
         0x89,0x3d,0x51,0xec,0x4b,0x56,0x3b,0x53
     };
 
-    if (memcmp(cipher, verify1, sizeof(cipher)))
+    if (memcmp(cipher, verify1, sz))
         return -51;
 
     // CBC mode
@@ -543,21 +564,21 @@ int des_test()
     DES_CBC_Decryption dec2;
 
     enc2.SetKey(key, sizeof(key), iv);
-    enc2.Process(cipher, vector, sizeof(vector));
+    enc2.Process(cipher, msg, sz);
     dec2.SetKey(key, sizeof(key), iv);
-    dec2.Process(plain, cipher, sizeof(cipher));
+    dec2.Process(plain, cipher, sz);
 
-    if (memcmp(plain, vector, sizeof(plain)))
+    if (memcmp(plain, msg, sz))
         return -52;
 
     const byte verify2[] = 
     {
-        0xe5,0xc7,0xcd,0xde,0x87,0x2b,0xf2,0x7c,
-        0x43,0xe9,0x34,0x00,0x8c,0x38,0x9c,0x0f,
-        0x68,0x37,0x88,0x49,0x9a,0x7c,0x05,0xf6
+        0x8b,0x7c,0x52,0xb0,0x01,0x2b,0x6c,0xb8,
+        0x4f,0x0f,0xeb,0xf3,0xfb,0x5f,0x86,0x73,
+        0x15,0x85,0xb3,0x22,0x4b,0x86,0x2b,0x4b
     };
 
-    if (memcmp(cipher, verify2, sizeof(cipher)))
+    if (memcmp(cipher, verify2, sz))
         return -53;
 
     // EDE3 CBC mode
@@ -579,21 +600,21 @@ int des_test()
     };
 
     enc3.SetKey(key3, sizeof(key3), iv3);
-    enc3.Process(cipher, vector, sizeof(vector));
+    enc3.Process(cipher, msg, sz);
     dec3.SetKey(key3, sizeof(key3), iv3);
-    dec3.Process(plain, cipher, sizeof(cipher));
+    dec3.Process(plain, cipher, sz);
 
-    if (memcmp(plain, vector, sizeof(plain)))
+    if (memcmp(plain, msg, sz))
         return -54;
 
     const byte verify3[] = 
     {
-        0x43,0xa0,0x29,0x7e,0xd1,0x84,0xf8,0x0e,
-        0x89,0x64,0x84,0x32,0x12,0xd5,0x08,0x98,
-        0x18,0x94,0x15,0x74,0x87,0x12,0x7d,0xb0
+        0x08,0x8a,0xae,0xe6,0x9a,0xa9,0xc1,0x13,
+        0x93,0x7d,0xf7,0x3a,0x11,0x56,0x66,0xb3,
+        0x18,0xbc,0xbb,0x6d,0xd2,0xb1,0x16,0xda
     };
 
-    if (memcmp(cipher, verify3, sizeof(cipher)))
+    if (memcmp(cipher, verify3, sz))
         return -55;
 
     return 0;
@@ -606,18 +627,9 @@ int aes_test()
     AES_CBC_Decryption dec;
     const int bs(TaoCrypt::AES::BLOCK_SIZE);
 
-    const byte msg[] = { // "Now is the time for all " w/o trailing 0
-        0x6e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
-        0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
-        0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
-    };
-
     byte key[] = "0123456789abcdef   ";  // align
     byte iv[]  = "1234567890abcdef   ";  // align
 
-    byte cipher[bs];
-    byte plain [bs];
-
     enc.SetKey(key, bs, iv);
     dec.SetKey(key, bs, iv);
 
@@ -667,18 +679,9 @@ int twofish_test()
     Twofish_CBC_Decryption dec;
     const int bs(TaoCrypt::Twofish::BLOCK_SIZE);
 
-    const byte msg[] = { // "Now is the time for all " w/o trailing 0
-        0x6e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
-        0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
-        0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
-    };
-
     byte key[] = "0123456789abcdef   ";  // align
     byte iv[]  = "1234567890abcdef   ";  // align
 
-    byte cipher[bs];
-    byte plain [bs];
-
     enc.SetKey(key, bs, iv);
     dec.SetKey(key, bs, iv);
 
@@ -728,18 +731,9 @@ int blowfish_test()
     Blowfish_CBC_Decryption dec;
     const int bs(TaoCrypt::Blowfish::BLOCK_SIZE);
 
-    const byte msg[] = { // "Now is the time for all " w/o trailing 0
-        0x6e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
-        0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
-        0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
-    };
-
     byte key[] = "0123456789abcdef   ";  // align
     byte iv[]  = "1234567890abcdef   ";  // align
 
-    byte cipher[bs * 2];
-    byte plain [bs * 2];
-
     enc.SetKey(key, 16, iv);
     dec.SetKey(key, 16, iv);
 
@@ -805,7 +799,7 @@ int rsa_test()
 
     RSAES_Decryptor dec(priv);
     byte plain[64];
-    dec.Decrypt(cipher, sizeof(cipher), plain, rng);
+    dec.Decrypt(cipher, sizeof(plain), plain, rng);
 
     if (memcmp(plain, message, len))
         return -70;

From cd942a0fce58ad557e68aaf3c8426cca81d16ff2 Mon Sep 17 00:00:00 2001
From: "msvensson@shellback.(none)" <>
Date: Wed, 19 Apr 2006 11:33:49 +0200
Subject: [PATCH 015/108] Add .der files, used by yaSSL benchmark Add benchamrk
 to dirs to build

---
 extra/yassl/taocrypt/Makefile.am | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/extra/yassl/taocrypt/Makefile.am b/extra/yassl/taocrypt/Makefile.am
index 2aa43a6c814..ac0c1bc29dd 100644
--- a/extra/yassl/taocrypt/Makefile.am
+++ b/extra/yassl/taocrypt/Makefile.am
@@ -1,2 +1,2 @@
-SUBDIRS = src test
+SUBDIRS = src test benchmark
 EXTRA_DIST = taocrypt.dsw taocrypt.dsp

From 3d61068fbe855b6a222bdf9dab797f08003ca200 Mon Sep 17 00:00:00 2001
From: "msvensson@shellback.(none)" <>
Date: Wed, 19 Apr 2006 11:42:55 +0200
Subject: [PATCH 016/108] Add the .der files used by yaSSL benchmark

---
 extra/yassl/taocrypt/benchmark/dh1024.der  | Bin 0 -> 140 bytes
 extra/yassl/taocrypt/benchmark/dsa1024.der | Bin 0 -> 448 bytes
 extra/yassl/taocrypt/benchmark/rsa1024.der | Bin 0 -> 610 bytes
 3 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 extra/yassl/taocrypt/benchmark/dh1024.der
 create mode 100644 extra/yassl/taocrypt/benchmark/dsa1024.der
 create mode 100644 extra/yassl/taocrypt/benchmark/rsa1024.der

diff --git a/extra/yassl/taocrypt/benchmark/dh1024.der b/extra/yassl/taocrypt/benchmark/dh1024.der
new file mode 100644
index 0000000000000000000000000000000000000000..1a85d90f3f73bfac8eadcce347ac184517b7696f
GIT binary patch
literal 140
zcmV;70CWE^frkQtfdJzSP$YVrg24|O8KaTE_~w4Yl;};FUoGsR9lw0C(6T;r
u7lz80Qg_hFWcwke)}*PMa1+xurq+{@w?<}rUFSuFc-iKdchdp^0tyNQaz)+%

literal 0
HcmV?d00001

diff --git a/extra/yassl/taocrypt/benchmark/dsa1024.der b/extra/yassl/taocrypt/benchmark/dsa1024.der
new file mode 100644
index 0000000000000000000000000000000000000000..1fcb37fad6a8faa17c04840ad011e4c8244e588d
GIT binary patch
literal 448
zcmV;x0YCmQf&sb$0RRGlfdGY;GA122v6Zit#o~2yEAdw|`9S}F6VlbhZ%oJ{udl2?
z8$kW+RDugM9mCw>YTyqlLLi+v{@G1Qx9}O>X+J6;k5Np*1%QyYiORw=kP`76+^0`6
zN)~9}BSK*KgIk37ql+^1#&ybI%Z>MmmvWhqyaZ
z1aWrcK}^J&B13cKWP7al9mk2EXe;pm!1}sI^^IH%#OGEGsS>qr(S8qWz*BuoIRcE$
z`#0&NUd1!Bv8e7=>J9sE_$q`M+J<%8%zwHsZ;*8|1i%Ks>Q5uY0)c>E;P0KPS5H(1
z@T5?dF?)a+&&VHlZ|_ge+5E3uEjEh|u$Fm^LAjtJTD2EJBP8HXYXqCvff3Y^7cwiJ
z)a*L`!&-uB2H@{T8j7Hi>|7wsuWCFawo5V>P>l&K0
zrX%jPSh6J$`^r=F_JsI}%?7h0d@7l*0~d`1%uf{zH|jmi0uox9!Mm0iEA!FLl<2x7UhANydFKV?z@k^zn*
zm@au#H~F0Dcsoz%MQ^BVHr(K|l^RFSgZz1Lg
z&3=g5e|kQ>W)2lM5dGmbm^Gh@p#cIx0OW)I+q=HyA=q`(oQl3N+66CaS-E3oyc3C_
zyXm7kK|U~?^JnvW1+#MK^;t@{`;X>VqndLY{ujltq{@8K^#VZv-L3|iOpZ9xxKziP
z7m*Y3HzEu8lRCqf4vN{EEU4U&AX)CQ)EB6OC8ZEO8?xSY0!aP|(zV
wur`ZFW8N|E>PSda;r-oUvyn->=ib1Phx0tDuwOPetj4i{W@d6X(P8Kc3RWQ=vH$=8

literal 0
HcmV?d00001


From 231936a43c325f277169f4ed9d9dd1fad505d7ff Mon Sep 17 00:00:00 2001
From: "msvensson@neptunus.(none)" <>
Date: Wed, 19 Apr 2006 20:26:40 +0200
Subject: [PATCH 017/108] Bug#18818 configure: No longer finds OpenSSL on Mac
 OS X  - Eval shrext_cmds variable before using it

---
 acinclude.m4 | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/acinclude.m4 b/acinclude.m4
index 8a55c1fdb20..c8cad48ff0b 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -311,8 +311,9 @@ case $SYSTEM_TYPE in
         ;;
       *)
         # Just to be safe, we test for ".so" anyway
+	eval shrexts=\"$shrext_cmds\"
         if test \( -f "$mysql_zlib_dir/lib/libz.a"  -o -f "$mysql_zlib_dir/lib/libz.so" -o \
-                   -f "$mysql_zlib_dir/lib/libz$shrext_cmds" \) \
+                   -f "$mysql_zlib_dir/lib/libz$shrexts" \) \
                 -a -f "$mysql_zlib_dir/include/zlib.h"; then
           ZLIB_INCLUDES="-I$mysql_zlib_dir/include"
           ZLIB_LIBS="-L$mysql_zlib_dir/lib -lz"
@@ -967,6 +968,7 @@ AC_DEFUN([MYSQL_CHECK_VIO], [
 AC_DEFUN([MYSQL_FIND_OPENSSL], [
   incs="$1"
   libs="$2"
+  eval shrexts=\"$shrext_cmds\"
   case "$incs---$libs" in
     ---)
       for d in /usr/ssl/include /usr/local/ssl/include /usr/include \
@@ -981,7 +983,7 @@ AC_DEFUN([MYSQL_FIND_OPENSSL], [
 /usr/lib /usr/lib64 /opt/ssl/lib /opt/openssl/lib \
 /usr/freeware/lib32 /usr/local/lib/ ; do
       # Just to be safe, we test for ".so" anyway
-      if test -f $d/libssl.a || test -f $d/libssl.so || test -f $d/libssl$shrext_cmds ; then
+      if test -f $d/libssl.a || test -f $d/libssl.so || test -f $d/libssl$shrexts ; then
         OPENSSL_LIB=$d
       fi
       done
@@ -994,7 +996,7 @@ AC_DEFUN([MYSQL_FIND_OPENSSL], [
         OPENSSL_INCLUDE=-I$incs
       fi
       # Just to be safe, we test for ".so" anyway
-      if test -f $libs/libssl.a || test -f $libs/libssl.so || test -f $libs/libssl$shrext_cmds ; then
+      if test -f $libs/libssl.a || test -f $libs/libssl.so || test -f "$libs/libssl$shrexts" ; then
         OPENSSL_LIB=$libs
       fi
       ;;

From d42d01b9ead281eb855fde87621645b34ab7b79b Mon Sep 17 00:00:00 2001
From: "tnurnberg@mysql.com" <>
Date: Wed, 19 Apr 2006 22:56:48 +0200
Subject: [PATCH 018/108] Bug#18964 "return 0 instead of DBUG_RETURN(0) in
 sql_base.cc::open_table()"

fixlet corrects return to DBUG_RETURN to restore the balance.
---
 sql/sql_base.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sql/sql_base.cc b/sql/sql_base.cc
index 2b5a3d1f38d..4b063fdb5e6 100644
--- a/sql/sql_base.cc
+++ b/sql/sql_base.cc
@@ -1103,7 +1103,7 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root,
 
   /* an open table operation needs a lot of the stack space */
   if (check_stack_overrun(thd, STACK_MIN_SIZE_FOR_OPEN, (char *)&alias))
-    return 0;
+    DBUG_RETURN(0);
 
   if (thd->killed)
     DBUG_RETURN(0);

From f08eb57b26b43d1babeb28245a008f8a4b4eaabc Mon Sep 17 00:00:00 2001
From: "tnurnberg@mysql.com" <>
Date: Thu, 20 Apr 2006 00:55:30 +0200
Subject: [PATCH 019/108] debugging a BK issue

---
 sql/sql_base.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sql/sql_base.cc b/sql/sql_base.cc
index 4b063fdb5e6..2b5a3d1f38d 100644
--- a/sql/sql_base.cc
+++ b/sql/sql_base.cc
@@ -1103,7 +1103,7 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root,
 
   /* an open table operation needs a lot of the stack space */
   if (check_stack_overrun(thd, STACK_MIN_SIZE_FOR_OPEN, (char *)&alias))
-    DBUG_RETURN(0);
+    return 0;
 
   if (thd->killed)
     DBUG_RETURN(0);

From cd5af2ba70adb860056a2a4ff4cc5cba3d175e11 Mon Sep 17 00:00:00 2001
From: "tnurnberg@mysql.com" <>
Date: Thu, 20 Apr 2006 01:02:33 +0200
Subject: [PATCH 020/108] Bug#18964 "return 0 instead of DBUG_RETURN(0) in
 sql_base.cc::open_table()"

fixlet corrects return to DBUG_RETURN to restore the balance.
---
 sql/sql_base.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sql/sql_base.cc b/sql/sql_base.cc
index 2b5a3d1f38d..4b063fdb5e6 100644
--- a/sql/sql_base.cc
+++ b/sql/sql_base.cc
@@ -1103,7 +1103,7 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root,
 
   /* an open table operation needs a lot of the stack space */
   if (check_stack_overrun(thd, STACK_MIN_SIZE_FOR_OPEN, (char *)&alias))
-    return 0;
+    DBUG_RETURN(0);
 
   if (thd->killed)
     DBUG_RETURN(0);

From 35166137f087b79686e2b7411a89054ae8b53139 Mon Sep 17 00:00:00 2001
From: "acurtis@xiphis.org" <>
Date: Thu, 20 Apr 2006 10:03:15 -0700
Subject: [PATCH 021/108] WL#3201   Fixes after first review

---
 config/ac-macros/ha_ndbcluster.m4 |   2 -
 config/ac-macros/plugins.m4       | 198 ++++++++++++++++++++----------
 configure.in                      |   6 +-
 sql/ha_partition.cc               |   2 +-
 sql/handler.cc                    |   3 +
 5 files changed, 136 insertions(+), 75 deletions(-)

diff --git a/config/ac-macros/ha_ndbcluster.m4 b/config/ac-macros/ha_ndbcluster.m4
index 1358807e000..c7e163e065f 100644
--- a/config/ac-macros/ha_ndbcluster.m4
+++ b/config/ac-macros/ha_ndbcluster.m4
@@ -307,9 +307,7 @@ AC_DEFUN([MYSQL_SETUP_NDBCLUSTER], [
 
   AC_SUBST(NDB_DEFS)
   AC_SUBST(ndb_cxxflags_fix)
-])
 
-AC_DEFUN([NDBCLUSTER_CONFIG_FILES], [
   AC_CONFIG_FILES(storage/ndb/Makefile storage/ndb/include/Makefile dnl
    storage/ndb/src/Makefile storage/ndb/src/common/Makefile dnl
    storage/ndb/docs/Makefile dnl
diff --git a/config/ac-macros/plugins.m4 b/config/ac-macros/plugins.m4
index 5969a85dc14..20d7e2cc11c 100644
--- a/config/ac-macros/plugins.m4
+++ b/config/ac-macros/plugins.m4
@@ -36,8 +36,8 @@ AC_DEFUN([_MYSQL_MODULE],[ dnl
  ],[ dnl 
   m4_define([$2], [$1]) dnl
   _MYSQL_PLUGAPPEND([__mysql_plugin_list__],[$1]) dnl
-  AC_DEFUN([MYSQL_MODULE_NAME_]AS_TR_CPP([$1]), [$3]) dnl
-  AC_DEFUN([MYSQL_MODULE_DESC_]AS_TR_CPP([$1]), [$4]) dnl
+  m4_define([MYSQL_MODULE_NAME_]AS_TR_CPP([$1]), [$3]) dnl
+  m4_define([MYSQL_MODULE_DESC_]AS_TR_CPP([$1]), [$4]) dnl
   ifelse([$5], [], [], [ dnl
    _MYSQL_PLUGAPPEND_OPTS([$1], $5) dnl
   ]) dnl
@@ -78,7 +78,7 @@ dnl ---------------------------------------------------------------------------
 
 AC_DEFUN([MYSQL_MODULE_DEFINE],[ dnl
  REQUIRE_PLUGIN([$1]) dnl
- AC_DEFUN([MYSQL_MODULE_DEFINE_]AS_TR_CPP([$1]), [$2]) dnl
+ m4_define([MYSQL_MODULE_DEFINE_]AS_TR_CPP([$1]), [$2]) dnl
 ])
 
 
@@ -92,7 +92,7 @@ dnl ---------------------------------------------------------------------------
 
 AC_DEFUN([MYSQL_MODULE_DIRECTORY],[ dnl
  REQUIRE_PLUGIN([$1]) dnl
- AC_DEFUN([MYSQL_MODULE_DIRECTORY_]AS_TR_CPP([$1]), [$2]) dnl
+ m4_define([MYSQL_MODULE_DIRECTORY_]AS_TR_CPP([$1]), [$2]) dnl
 ])
 
 
@@ -106,7 +106,7 @@ dnl ---------------------------------------------------------------------------
 
 AC_DEFUN([MYSQL_MODULE_STATIC],[ dnl
  REQUIRE_PLUGIN([$1]) dnl
- AC_DEFUN([MYSQL_MODULE_STATIC_]AS_TR_CPP([$1]), [$2]) dnl
+ m4_define([MYSQL_MODULE_STATIC_]AS_TR_CPP([$1]), [$2]) dnl
 ])
 
 
@@ -120,7 +120,7 @@ dnl ---------------------------------------------------------------------------
 
 AC_DEFUN([MYSQL_MODULE_DYNAMIC],[ dnl
  REQUIRE_PLUGIN([$1]) dnl
- AC_DEFUN([MYSQL_MODULE_DYNAMIC_]AS_TR_CPP([$1]), [$2]) dnl
+ m4_define([MYSQL_MODULE_DYNAMIC_]AS_TR_CPP([$1]), [$2]) dnl
 ])
 
 
@@ -216,7 +216,7 @@ AC_DEFUN([MYSQL_MODULE_ACTIONS],[ dnl
  m4_ifdef([$2],[ dnl
    m4_define([MYSQL_MODULE_ACTIONS_]AS_TR_CPP([$1]),m4_defn([$2])) dnl
  ],[ dnl
-   AC_DEFUN([MYSQL_MODULE_ACTIONS_]AS_TR_CPP([$1]), [$2]) dnl
+   m4_define([MYSQL_MODULE_ACTIONS_]AS_TR_CPP([$1]), [$2]) dnl
  ])
 ])
 
@@ -235,8 +235,9 @@ AC_DEFUN([MYSQL_CONFIGURE_PLUGINS],[ dnl
  ],[ dnl
    m4_define([__mysql_plugin_configured__],[done]) dnl
    m4_ifdef([__mysql_plugin_list__],[ dnl
-    _MYSQL_CHECK_PLUGIN_ARGS([none])
+    _MYSQL_CHECK_PLUGIN_ARGS([$1])
     _MYSQL_CONFIGURE_PLUGINS(m4_bpatsubst(__mysql_plugin_list__, :, [,]))
+    _MYSQL_DO_PLUGIN_ACTIONS(m4_bpatsubst(__mysql_plugin_list__, :, [,]))
    ]) dnl
  ]) dnl
 ])
@@ -272,32 +273,33 @@ AC_DEFUN([_DO_MYSQL_CHECK_PLUGIN],[ dnl
  ])
  AC_MSG_CHECKING([whether to use ]$3) dnl
  m4_ifdef([$10],[
-  if test "[$mysql_module_]m4_bpatsubst([$1], -, _)" == "yes" -a \
-          "[$with_module_]m4_bpatsubst([$1], -, _)" != "no" -o \
-          "[$with_module_]m4_bpatsubst([$1], -, _)" == "yes"; then
+  if test "[$mysql_module_]m4_bpatsubst([$1], -, _)" = yes -a \
+          "[$with_module_]m4_bpatsubst([$1], -, _)" != no -o \
+          "[$with_module_]m4_bpatsubst([$1], -, _)" = yes; then
     AC_MSG_ERROR([disabled])
   fi
   AC_MSG_RESULT([no]) dnl
  ],[ dnl
   m4_ifdef([$9],[
-   if test "[$with_module_]m4_bpatsubst([$1], -, _)" == "no"; then
+   if test "[$with_module_]m4_bpatsubst([$1], -, _)" = no; then
      AC_MSG_ERROR([cannot disable mandatory module])
    fi
-   [mysql_module_]m4_bpatsubst([$1], -, _)="yes" dnl
+   [mysql_module_]m4_bpatsubst([$1], -, _)=yes dnl
   ])
-  if test "[$with_module_]m4_bpatsubst([$1], -, _)" != "no"; then
-    if test "[$mysql_module_]m4_bpatsubst([$1], -, _)" != "yes" -a \
-            "[$with_module_]m4_bpatsubst([$1], -, _)" != "yes"; then dnl
+  if test "[$with_module_]m4_bpatsubst([$1], -, _)" != no; then
+    if test "[$mysql_module_]m4_bpatsubst([$1], -, _)" != yes -a \
+            "[$with_module_]m4_bpatsubst([$1], -, _)" != yes; then dnl
       m4_ifdef([$8],[ dnl
        m4_ifdef([$6],[
         mysql_plugin_dirs="$mysql_plugin_dirs $6" dnl
        ])
        AC_SUBST([plugin_]m4_bpatsubst([$1], -, _)[_shared_target], "$8")
        AC_SUBST([plugin_]m4_bpatsubst([$1], -, _)[_static_target], [""])
-       [with_module_]m4_bpatsubst([$1], -, _)="yes" dnl
+       [with_module_]m4_bpatsubst([$1], -, _)=yes
+       AC_MSG_RESULT([plugin]) dnl
       ],[
-       AC_MSG_RESULT([cannot build dynamically])
-       [with_module_]m4_bpatsubst([$1], -, _)="no" dnl
+       [with_module_]m4_bpatsubst([$1], -, _)=no
+       AC_MSG_RESULT([no]) dnl
       ])
     else dnl
       m4_ifdef([$7],[
@@ -338,19 +340,47 @@ AC_DEFUN([_DO_MYSQL_CHECK_PLUGIN],[ dnl
        ]) dnl
       ])
       mysql_plugin_defs="$mysql_plugin_defs, [builtin_]m4_bpatsubst([$2], -, _)"
-      [with_module_]m4_bpatsubst([$1], -, _)="yes"
+      [with_module_]m4_bpatsubst([$1], -, _)=yes
+      AC_MSG_RESULT([yes])
     fi
   else
     AC_MSG_RESULT([no])
-  fi
+  fi dnl
+ ]) dnl
+])
 
-  if test "[$with_module_]m4_bpatsubst([$1], -, _)" == "yes"; then
-    if test "[$plugin_]m4_bpatsubst([$1], -, _)[_static_target]" != ""; then
-      AC_MSG_RESULT([static])
-    elif test "[$plugin_]m4_bpatsubst([$1], -, _)[_shared_target]" != ""; then
-      AC_MSG_RESULT([plugin])
-    else
-      AC_MSG_ERROR([thats strange])
+AC_DEFUN([_MYSQL_DO_PLUGIN_ACTIONS],[ dnl
+ ifelse($#, 0, [], $#, 1, [ dnl
+  _MYSQL_PLUGIN_ACTIONS([$1]) dnl
+ ],[ dnl
+  _MYSQL_PLUGIN_ACTIONS([$1]) dnl
+  _MYSQL_DO_PLUGIN_ACTIONS(m4_shift($@)) dnl
+ ])
+])
+
+AC_DEFUN([_MYSQL_PLUGIN_ACTIONS],[ dnl
+ _DO_MYSQL_PLUGIN_ACTIONS(
+  [$1],
+  [$1-plugin],
+  [MYSQL_MODULE_NAME_]AS_TR_CPP([$1]),
+  [MYSQL_MODULE_DESC_]AS_TR_CPP([$1]),
+  [MYSQL_MODULE_DEFINE_]AS_TR_CPP([$1]),
+  [MYSQL_MODULE_DIRECTORY_]AS_TR_CPP([$1]),
+  [MYSQL_MODULE_STATIC_]AS_TR_CPP([$1]),
+  [MYSQL_MODULE_DYNAMIC_]AS_TR_CPP([$1]),
+  [MYSQL_MODULE_MANDATORY_]AS_TR_CPP([$1]),
+  [MYSQL_MODULE_DISABLED_]AS_TR_CPP([$1]),
+  [MYSQL_MODULE_ACTIONS_]AS_TR_CPP([$1])
+ ) dnl
+])
+
+
+AC_DEFUN([_DO_MYSQL_PLUGIN_ACTIONS],[ dnl
+ m4_ifdef([$10], [], [
+  if test "[$with_module_]m4_bpatsubst([$1], -, _)" = yes; then
+    if test -z "[$plugin_]m4_bpatsubst([$1], -, _)[_static_target]" -a \
+            -z "[$plugin_]m4_bpatsubst([$1], -, _)[_shared_target]"; then
+      AC_MSG_ERROR([thats strange, $1 failed sanity check])
     fi
     $11
   fi dnl
@@ -390,12 +420,13 @@ _MYSQL_MODULE_META_CHECK(m4_shift($@))]) dnl
 ])
 
 AC_DEFUN([_MYSQL_CHECK_PLUGIN_META], [
-  elif test "$mysql_modules" == "[$1]"; then dnl
+  [$1] ) dnl
 m4_ifdef([$2], [
-    mysql_modules="m4_bpatsubst($2, :, [,])" dnl
+    mysql_modules='m4_bpatsubst($2, :, [ ])' dnl
 ],[
-    mysql_modules="" dnl
-]) dnl
+    mysql_modules='' dnl
+])
+    ;; dnl
 ])
 
 
@@ -410,7 +441,7 @@ AC_DEFUN([_MYSQL_PLUGAPPEND],[ dnl
   m4_undefine([__plugin_append_tmp__]) dnl
  ],[ dnl
   m4_define([$1], [$2]) dnl
-  $3
+  $3 dnl
  ]) dnl
 ])
 
@@ -510,13 +541,30 @@ AC_DEFUN([_MYSQL_MODULE_ARGS_CHECK],[ dnl
 ])
 
 AC_DEFUN([_MYSQL_CHECK_PLUGIN_ARG],[ dnl
-m4_ifdef([$3], [], [AC_DEFUN([$3],[ ])])
-    elif test "$plugin" == "[$1]"; then dnl
-m4_ifdef([$2],[
+ m4_ifdef([$3], [], [m4_define([$3],[ ])])
+    [$1] ) dnl
+ m4_ifdef([$2],[
       AC_MSG_ERROR([plugin $1 is disabled]) dnl
-],[
-      [mysql_module_]m4_bpatsubst([$1], -, _)="yes" dnl
-]) dnl
+ ],[
+      [mysql_module_]m4_bpatsubst([$1], -, _)=yes dnl
+ ])
+      ;; dnl
+])
+
+AC_DEFUN([_MYSQL_SANE_VARS], [ dnl
+ ifelse($#, 0, [], $#, 1, [ dnl
+  _MYSQL_SANEVAR([$1]) dnl
+ ],[ dnl
+  _MYSQL_SANEVAR([$1]) dnl
+  _MYSQL_SANE_VARS(m4_shift($@)) dnl
+ ]) dnl
+])
+
+AC_DEFUN([_MYSQL_SANEVAR], [
+   test -z "[$mysql_module_]m4_bpatsubst([$1], -, _)" && dnl
+[mysql_module_]m4_bpatsubst([$1], -, _)='.'
+   test -z "[$with_module_]m4_bpatsubst([$1], -, _)" && dnl
+[with_module_]m4_bpatsubst([$1], -, _)='.' dnl
 ])
 
 AC_DEFUN([_MYSQL_CHECK_DEPENDENCIES], [ dnl
@@ -530,32 +578,35 @@ AC_DEFUN([_MYSQL_CHECK_DEPENDENCIES], [ dnl
 
 AC_DEFUN([_MYSQL_CHECK_DEPENDS], [ dnl
  m4_ifdef([$2], [
-   if test "[$mysql_module_]m4_bpatsubst([$1], -, _)" == "yes" -a \
-           "[$with_module_]m4_bpatsubst([$1], -, _)" != "no" -o \
-           "[$with_module_]m4_bpatsubst([$1], -, _)" == "yes"; then dnl
+   if test "[$mysql_module_]m4_bpatsubst([$1], -, _)" = yes -a \
+           "[$with_module_]m4_bpatsubst([$1], -, _)" != no -o \
+           "[$with_module_]m4_bpatsubst([$1], -, _)" = yes; then dnl
      _MYSQL_GEN_DEPENDS(m4_bpatsubst($2, :, [,]))
-   fi
+   fi dnl
  ]) dnl
 ])
 
 AC_DEFUN([_MYSQL_GEN_DEPENDS], [ dnl
- ifelse($#, 0, [], $#, 1, [
-      [mysql_module_]m4_bpatsubst([$1], -, _)="yes"
-      if test "[$with_module_]m4_bpatsubst([$1], -, _)" == "no"; then
-        AC_MSG_ERROR([depends upon disabled module $1])
-      fi dnl
- ],[
-      [mysql_module_]m4_bpatsubst([$1], -, _)="yes"
-      if test "[$with_module_]m4_bpatsubst([$1], -, _)" == "no"; then
-        AC_MSG_ERROR([depends upon disabled module $1])
-      fi dnl
+ ifelse($#, 0, [], $#, 1, [ dnl
+  _MYSQL_GEN_DEPEND([$1]) dnl
+ ],[ dnl
+  _MYSQL_GEN_DEPEND([$1]) dnl
   _MYSQL_GEN_DEPENDS(m4_shift($@)) dnl
  ]) dnl
 ])
-  
+
+AC_DEFUN([_MYSQL_GEN_DEPEND], [ dnl
+ m4_ifdef([MYSQL_MODULE_DISABLED_]AS_TR_CPP([$1]),[
+      AC_MSG_ERROR([depends upon disabled module $1]) dnl
+ ],[
+      [mysql_module_]m4_bpatsubst([$1], -, _)=yes
+      if test "[$with_module_]m4_bpatsubst([$1], -, _)" = no; then
+        AC_MSG_ERROR([depends upon disabled module $1])
+      fi dnl
+ ]) dnl
+])
 
 AC_DEFUN([_MYSQL_CHECK_PLUGIN_ARGS],[
-
  AC_ARG_WITH([modules], [
    --with-modules=PLUGIN[[,PLUGIN..]]
 m4_text_wrap([Plugin modules to include in mysqld. (default is: $1)
@@ -570,32 +621,43 @@ m4_bpatsubst(__mysql_plugin_list__, :, [ ])[.], [                          ])
   --without-module-PLUGIN
 m4_text_wrap([Disable the named module from being built. Otherwise, 
 for modules which are not selected for inclusion in mysqld will be 
-built dynamically (if supported)],[                          ])],
-[mysql_modules="$withval"], [mysql_modules=['$1']])
+built dynamically (if supported)],[                          ])
+],[mysql_modules="`echo $withval | tr ',.:;*[]' '       '`"], 
+  [mysql_modules=['$1']])
 
 m4_divert_once([HELP_VAR_END],[
 Description of plugin modules:
 m4_indir([MYSQL_LIST_PLUGINS])
 ])
 
-  if test "$mysql_modules" == "all"; then
-    mysql_modules="m4_bpatsubst(__mysql_plugin_list__, :, [,])"
-  elif test "$mysql_modules" == "none"; then
-    mysql_modules="" dnl
+  case "$mysql_modules" in
+  all )
+    mysql_modules='m4_bpatsubst(__mysql_plugin_list__, :, [ ])'
+    ;;
+  none )
+    mysql_modules=''
+    ;; dnl
 m4_ifdef([__mysql_metaplugin_list__],[ dnl
 _MYSQL_MODULE_META_CHECK(m4_bpatsubst(__mysql_metaplugin_list__, :, [,])) dnl
 ])
-  fi
+  esac
 
-  for plugin in `echo $mysql_modules | tr ",.:;" "    "`; do
-    if test "$plugin" == "all" -o "$plugin" == "none"; then
-      AC_MSG_ERROR([bad module name: $plugin]) dnl
+  for plugin in $mysql_modules; do
+    case "$plugin" in
+    all )
+      AC_MSG_ERROR([bad module name: $plugin])
+      ;;
+    none )
+      AC_MSG_ERROR([bad module name: $plugin])
+      ;; dnl
 _MYSQL_MODULE_ARGS_CHECK(m4_bpatsubst(__mysql_plugin_list__, :, [,]))
-    else
+    * )
       AC_MSG_ERROR([unknown plugin module: $plugin])
-    fi
+      ;;
+    esac
   done
-  
+
+  _MYSQL_SANE_VARS(m4_bpatsubst(__mysql_plugin_list__, :, [,]))  
   _MYSQL_CHECK_DEPENDENCIES(m4_bpatsubst(__mysql_plugin_list__, :, [,]))
 ])
 
diff --git a/configure.in b/configure.in
index 70d36ee84f5..0e4ea0422c3 100644
--- a/configure.in
+++ b/configure.in
@@ -123,8 +123,8 @@ MYSQL_MODULE_DIRECTORY(ndbcluster,[storage/ndb])
 MYSQL_MODULE_STATIC(ndbcluster, [[\$(ndbcluster_libs) \$(ndbcluster_system_libs) \$(NDB_SCI_LIBS)]])
 MYSQL_MODULE_ACTIONS(ndbcluster,[MYSQL_SETUP_NDBCLUSTER])
 
-MYSQL_STORAGE_ENGINE(partition, partition, [Partition Engine],
-        [MySQL Table Partitioning Engine], [max,max-no-ndb])
+MYSQL_STORAGE_ENGINE(partition, partition, [Partition Support],
+        [MySQL Partitioning Support], [max,max-no-ndb])
 
 MYSQL_MODULE_MANDATORY(csv)     dnl Used for logging
 MYSQL_MODULE_MANDATORY(heap)    dnl Memory tables
@@ -2624,8 +2624,6 @@ done
 
 AC_SUBST(MAKE_BINARY_DISTRIBUTION_OPTIONS)
 
-NDBCLUSTER_CONFIG_FILES
-
 # Output results
 AC_CONFIG_FILES(Makefile extra/Makefile mysys/Makefile dnl
  strings/Makefile regex/Makefile dnl
diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc
index fc9985cf87f..25b4b8f09f0 100644
--- a/sql/ha_partition.cc
+++ b/sql/ha_partition.cc
@@ -5498,7 +5498,7 @@ mysql_declare_plugin(partition)
   &partition_hton,
   partition_hton.name,
   "Mikael Ronstrom, MySQL AB",
-  "Partitioning Engine",
+  "Partitioning Support",
   NULL, /* Plugin Init */
   NULL, /* Plugin Deinit */
   0x0100 /* 1.0 */,
diff --git a/sql/handler.cc b/sql/handler.cc
index 56938f2eff7..bf84ec16ea8 100644
--- a/sql/handler.cc
+++ b/sql/handler.cc
@@ -44,6 +44,9 @@
 #include "ha_innodb.h"
 #endif
 
+/* While we have legacy_db_type, we have this array to
+   check for dups and to find handlerton from legacy_db_type.
+   Remove when legacy_db_type is finally gone */
 static handlerton *installed_htons[128];
 
 #define BITMAP_STACKBUF_SIZE (128/8)

From bdbb4afc6cd249ea362cd4f4ff9ad9e6881da719 Mon Sep 17 00:00:00 2001
From: "acurtis@xiphis.org" <>
Date: Thu, 20 Apr 2006 10:37:37 -0700
Subject: [PATCH 022/108] WL#3201   cmake changes

---
 cmakelists.txt                   | 49 +++++++++++++++++---------------
 sql/cmakelists.txt               | 13 +++++++--
 storage/archive/cmakelists.txt   |  2 +-
 storage/blackhole/cmakelists.txt |  5 ++++
 4 files changed, 42 insertions(+), 27 deletions(-)
 create mode 100644 storage/blackhole/cmakelists.txt

diff --git a/cmakelists.txt b/cmakelists.txt
index 0e91f49be90..28d75c62c41 100644
--- a/cmakelists.txt
+++ b/cmakelists.txt
@@ -9,52 +9,49 @@ SET(WITH_CSV_STORAGE_ENGINE TRUE)
 CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/include/mysql_version.h.in
                ${CMAKE_SOURCE_DIR}/include/mysql_version.h @ONLY)
 
+SET(WITH_HEAP_STORAGE_ENGINE TRUE)
+ADD_DEFINITIONS(-D WITH_HEAP_STORAGE_ENGINE)
+SET (mysql_plugin_defs "${mysql_plugin_defs},builtin_heap_plugin")
+
+SET(WITH_MYISAM_STORAGE_ENGINE TRUE)
+ADD_DEFINITIONS(-D WITH_MYISAM_STORAGE_ENGINE)
+SET (mysql_plugin_defs "${mysql_plugin_defs},builtin_myisam_plugin")
+
+SET(WITH_MYISAMMRG_STORAGE_ENGINE TRUE)
+ADD_DEFINITIONS(-D WITH_MYISAMMRG_STORAGE_ENGINE)
+SET (mysql_plugin_defs "${mysql_plugin_defs},builtin_myisammrg_plugin")
+
 IF(WITH_ARCHIVE_STORAGE_ENGINE)
   ADD_DEFINITIONS(-D WITH_ARCHIVE_STORAGE_ENGINE)
-  SET (mysql_se_htons "${mysql_se_htons}, &archive_hton")
-  SET (mysql_se_decls "${mysql_se_decls}, archive_hton")
-  SET (mysql_se_ha_src ${mysql_se_ha_src} "../sql/ha_archive.cc")
+  SET (mysql_plugin_defs "${mysql_plugin_defs},builtin_archive_plugin")
 ENDIF(WITH_ARCHIVE_STORAGE_ENGINE)
 IF(WITH_BLACKHOLE_STORAGE_ENGINE)
   ADD_DEFINITIONS(-D WITH_BLACKHOLE_STORAGE_ENGINE)
-  SET (mysql_se_htons "${mysql_se_htons}, &blackhole_hton")
-  SET (mysql_se_decls "${mysql_se_decls}, blackhole_hton")
-  SET (mysql_se_ha_src ${mysql_se_ha_src} "../sql/ha_blackhole.cc")
+  SET (mysql_plugin_defs "${mysql_plugin_defs},builtin_blackhole_plugin")
 ENDIF(WITH_BLACKHOLE_STORAGE_ENGINE)
 IF(WITH_CSV_STORAGE_ENGINE)
   ADD_DEFINITIONS(-D WITH_CSV_STORAGE_ENGINE)
-  SET (mysql_se_htons "${mysql_se_htons}, &tina_hton")
-  SET (mysql_se_decls "${mysql_se_decls}, tina_hton")
-  SET (mysql_se_ha_src ${mysql_se_ha_src} "../storage/csv/ha_tina.cc")
+  SET (mysql_plugin_defs "${mysql_plugin_defs},builtin_csv_plugin")
 ENDIF(WITH_CSV_STORAGE_ENGINE)
 IF(WITH_EXAMPLE_STORAGE_ENGINE)
   ADD_DEFINITIONS(-D WITH_EXAMPLE_STORAGE_ENGINE)
-  SET (mysql_se_htons "${mysql_se_htons}, &example_hton")
-  SET (mysql_se_decls "${mysql_se_decls}, example_hton")
+  SET (mysql_plugin_defs "${mysql_plugin_defs},builtin_example_plugin")
 ENDIF(WITH_EXAMPLE_STORAGE_ENGINE)
 IF(WITH_INNOBASE_STORAGE_ENGINE)
   ADD_DEFINITIONS(-D WITH_INNOBASE_STORAGE_ENGINE)
-  SET (mysql_se_htons "${mysql_se_htons}, &innobase_hton")
-  SET (mysql_se_decls "${mysql_se_decls}, innobase_hton")
-  SET (mysql_se_ha_src ${mysql_se_ha_src} "../sql/ha_innodb.cc")
+  SET (mysql_plugin_defs "${mysql_plugin_defs},builtin_innobase_plugin")
 ENDIF(WITH_INNOBASE_STORAGE_ENGINE)
 IF(WITH_PARTITION_STORAGE_ENGINE)
   ADD_DEFINITIONS(-D WITH_PARTITION_STORAGE_ENGINE)
-  SET (mysql_se_htons "${mysql_se_htons}, &partition_hton")
-  SET (mysql_se_decls "${mysql_se_decls}, partition_hton")
-  SET (mysql_se_ha_src ${mysql_se_ha_src} "../sql/ha_partition.cc")
+  SET (mysql_plugin_defs "${mysql_plugin_defs},builtin_partition_plugin")
 ENDIF(WITH_PARTITION_STORAGE_ENGINE)
 IF(WITH_FEDERATED_STORAGE_ENGINE)
   ADD_DEFINITIONS(-D WITH_FEDERATED_STORAGE_ENGINE)
-  SET (mysql_se_htons "${mysql_se_htons}, &federated_hton")
-  SET (mysql_se_decls "${mysql_se_decls}, federated_hton")
-  SET (mysql_se_ha_src ${mysql_se_ha_src} "../sql/ha_federated.cc")
+  SET (mysql_plugin_defs "${mysql_plugin_defs},builtin_federated_plugin")
 ENDIF(WITH_FEDERATED_STORAGE_ENGINE)
 IF(WITH_BERKELEY_STORAGE_ENGINE)
   ADD_DEFINITIONS(-D WITH_BERKELEY_STORAGE_ENGINE)
-  SET (mysql_se_htons "${mysql_se_htons}, &berkeley_hton")
-  SET (mysql_se_decls "${mysql_se_decls}, berkeley_hton")
-  SET (mysql_se_ha_src ${mysql_se_ha_src} "../sql/ha_berkeley.cc")
+  SET (mysql_plugin_defs "${mysql_plugin_defs},builtin_berkeley_plugin")
 ENDIF(WITH_BERKELEY_STORAGE_ENGINE)
 
 CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/sql/handlerton.cc.in 
@@ -137,6 +134,12 @@ ENDIF(WITH_ARCHIVE_STORAGE_ENGINE)
 IF(WITH_BERKELEY_STORAGE_ENGINE)
   ADD_SUBDIRECTORY(storage/bdb)
 ENDIF(WITH_BERKELEY_STORAGE_ENGINE)
+IF(WITH_BLACKHOLE_STORAGE_ENGINE)
+  ADD_SUBDIRECTORY(storage/blackhole)
+ENDIF(WITH_BLACKHOLE_STORAGE_ENGINE)
+IF(WITH_CSV_STORAGE_ENGINE)
+  ADD_SUBDIRECTORY(storage/csv)
+ENDIF(WITH_CSV_STORAGE_ENGINE)
 IF(WITH_EXAMPLE_STORAGE_ENGINE)
   ADD_SUBDIRECTORY(storage/example)
 ENDIF(WITH_EXAMPLE_STORAGE_ENGINE)
diff --git a/sql/cmakelists.txt b/sql/cmakelists.txt
index 381d22c605c..05b1efdbe51 100644
--- a/sql/cmakelists.txt
+++ b/sql/cmakelists.txt
@@ -16,7 +16,7 @@ SET_SOURCE_FILES_PROPERTIES(${CMAKE_SOURCE_DIR}/sql/message.rc
 							${CMAKE_SOURCE_DIR}/sql/sql_yacc.h 
 							${CMAKE_SOURCE_DIR}/sql/sql_yacc.cc
                             ${CMAKE_SOURCE_DIR}/include/mysql_version.h
-                            ${CMAKE_SOURCE_DIR}/sql/handlerton.cc
+                            ${CMAKE_SOURCE_DIR}/sql/sql_builtin.cc
                             ${CMAKE_SOURCE_DIR}/sql/lex_hash.h 
                             ${PROJECT_SOURCE_DIR}/include/mysqld_error.h
                             ${PROJECT_SOURCE_DIR}/include/mysqld_ername.h
@@ -29,7 +29,8 @@ ADD_DEFINITIONS(-DHAVE_ROW_BASED_REPLICATION -DMYSQL_SERVER
 ADD_EXECUTABLE(mysqld ../sql-common/client.c derror.cc des_key_file.cc
                discover.cc ../libmysql/errmsg.c field.cc field_conv.cc 
                filesort.cc gstream.cc  ha_heap.cc ha_myisam.cc ha_myisammrg.cc
-               ${mysql_se_ha_src} handler.cc hash_filo.cc hash_filo.h 
+               ha_innodb.cc ha_partition.cc ha_federated.cc ha_berkeley.cc
+               handler.cc hash_filo.cc hash_filo.h 
                hostname.cc init.cc item.cc item_buff.cc item_cmpfunc.cc 
                item_create.cc item_func.cc item_geofunc.cc item_row.cc 
                item_strfunc.cc item_subselect.cc item_sum.cc item_timefunc.cc 
@@ -59,13 +60,19 @@ ADD_EXECUTABLE(mysqld ../sql-common/client.c derror.cc des_key_file.cc
 			   ${PROJECT_SOURCE_DIR}/include/mysqld_ername.h 
 			   ${PROJECT_SOURCE_DIR}/include/sql_state.h
 			   ${PROJECT_SOURCE_DIR}/include/mysql_version.h 
-			   ${PROJECT_SOURCE_DIR}/sql/handlerton.cc
+			   ${PROJECT_SOURCE_DIR}/sql/sql_builtin.cc
 			   ${PROJECT_SOURCE_DIR}/sql/lex_hash.h)
 TARGET_LINK_LIBRARIES(mysqld heap myisam myisammrg mysys yassl zlib dbug yassl 
                       taocrypt strings vio regex wsock32)
 IF(WITH_ARCHIVE_STORAGE_ENGINE)
   TARGET_LINK_LIBRARIES(mysqld archive)
 ENDIF(WITH_ARCHIVE_STORAGE_ENGINE)
+IF(WITH_BLACKHOLE_STORAGE_ENGINE)
+  TARGET_LINK_LIBRARIES(mysqld blackhole)
+ENDIF(WITH_BLACKHOLE_STORAGE_ENGINE)
+IF(WITH_CSV_STORAGE_ENGINE)
+  TARGET_LINK_LIBRARIES(mysqld csv)
+ENDIF(WITH_CSV_STORAGE_ENGINE)
 IF(WITH_EXAMPLE_STORAGE_ENGINE)
   TARGET_LINK_LIBRARIES(mysqld example)
 ENDIF(WITH_EXAMPLE_STORAGE_ENGINE)
diff --git a/storage/archive/cmakelists.txt b/storage/archive/cmakelists.txt
index 4189781e73a..939f5562d50 100644
--- a/storage/archive/cmakelists.txt
+++ b/storage/archive/cmakelists.txt
@@ -2,5 +2,5 @@ SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DSAFEMALLOC -DSAFE_MUTEX")
 SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DSAFEMALLOC -DSAFE_MUTEX")
 
 INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/zlib)
-ADD_LIBRARY(archive azio.c)
+ADD_LIBRARY(archive azio.c ha_archive.cc ha_archive.h)
 TARGET_LINK_LIBRARIES(archive zlib mysys dbug strings)
diff --git a/storage/blackhole/cmakelists.txt b/storage/blackhole/cmakelists.txt
new file mode 100644
index 00000000000..29c0e1bb94b
--- /dev/null
+++ b/storage/blackhole/cmakelists.txt
@@ -0,0 +1,5 @@
+SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DSAFEMALLOC -DSAFE_MUTEX")
+SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DSAFEMALLOC -DSAFE_MUTEX")
+
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
+ADD_LIBRARY(blackhole ha_blackhole.cc ha_blackhole.h)

From 91801e5cc051b60c1d9670438f614c73d759f7da Mon Sep 17 00:00:00 2001
From: "acurtis@xiphis.org" <>
Date: Thu, 20 Apr 2006 10:44:21 -0700
Subject: [PATCH 023/108] WL#3201   handlerton -> sql_builtin

---
 cmakelists.txt | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/cmakelists.txt b/cmakelists.txt
index 28d75c62c41..5edc33b9f5a 100644
--- a/cmakelists.txt
+++ b/cmakelists.txt
@@ -54,8 +54,8 @@ IF(WITH_BERKELEY_STORAGE_ENGINE)
   SET (mysql_plugin_defs "${mysql_plugin_defs},builtin_berkeley_plugin")
 ENDIF(WITH_BERKELEY_STORAGE_ENGINE)
 
-CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/sql/handlerton.cc.in 
-               ${CMAKE_SOURCE_DIR}/sql/handlerton.cc @ONLY)
+CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/sql/sql_builtin.cc.in 
+               ${CMAKE_SOURCE_DIR}/sql/sql_builtin.cc @ONLY)
 
 SET(localstatedir "C:\\mysql\\data")
 CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/support-files/my-huge.cnf.sh

From 663fee9c052bf061191a68dff7d77a1362ca2e21 Mon Sep 17 00:00:00 2001
From: "evgen@moonbone.local" <>
Date: Fri, 21 Apr 2006 01:52:59 +0400
Subject: [PATCH 024/108] Fixed bug#18739: non-standard HAVING extension was
 allowed in strict ANSI sql mode.

The SQL standard doesn't allow to use in HAVING clause fields that are not
present in GROUP BY clause and not under any aggregate function in the HAVING
clause. However, mysql allows using such fields. This extension assume that
the non-grouping fields will have the same group-wise values. Otherwise, the
result will be unpredictable. This extension allowed in strict
MODE_ONLY_FULL_GROUP_BY sql mode results in misunderstanding of HAVING
capabilities.

The new error message ER_NON_GROUPING_FIELD_USED message is added. It says
"non-grouping field '%-.64s' is used in %-.64s clause". This message is
supposed to be used for reporting errors when some field is not found in the
GROUP BY clause but have to be present there. Use cases for this message are
this bug and when a field is present in a SELECT item list not under any
aggregate function and there is GROUP BY clause present which doesn't mention
that field. It renders the ER_WRONG_FIELD_WITH_GROUP error message obsolete as
being more descriptive.
The resolve_ref_in_select_and_group() function now reports the
ER_NON_GROUPING_FIELD_FOUND error if the strict mode is set and the field for
HAVING clause is found in the SELECT item list only.
---
 mysql-test/r/having.result | 13 +++++++++++++
 mysql-test/t/having.test   | 13 +++++++++++++
 sql/item.cc                | 18 ++++++++++++++++--
 sql/share/errmsg.txt       |  2 ++
 sql/sql_select.cc          |  4 ++++
 5 files changed, 48 insertions(+), 2 deletions(-)

diff --git a/mysql-test/r/having.result b/mysql-test/r/having.result
index fe918e4c3ff..a37f260ff31 100644
--- a/mysql-test/r/having.result
+++ b/mysql-test/r/having.result
@@ -392,3 +392,16 @@ HAVING HU.PROJ.CITY = HU.STAFF.CITY);
 EMPNUM	GRADE*1000
 E3	13000
 DROP SCHEMA HU;
+USE test;
+create table t1(f1 int);
+select f1 from t1 having max(f1)=f1;
+f1
+select f1 from t1 group by f1 having max(f1)=f1;
+f1
+set session sql_mode='ONLY_FULL_GROUP_BY';
+select f1 from t1 having max(f1)=f1;
+ERROR 42000: non-grouping field 'f1' is used in HAVING clause
+select f1 from t1 group by f1 having max(f1)=f1;
+f1
+set session sql_mode='';
+drop table t1;
diff --git a/mysql-test/t/having.test b/mysql-test/t/having.test
index 9b21e544657..779b694987b 100644
--- a/mysql-test/t/having.test
+++ b/mysql-test/t/having.test
@@ -393,3 +393,16 @@ SELECT EMPNUM, GRADE*1000
                            HAVING HU.PROJ.CITY = HU.STAFF.CITY);
 
 DROP SCHEMA HU;
+USE test;
+#
+# Bug#18739: non-standard HAVING extension was allowed in strict ANSI sql mode.
+#
+create table t1(f1 int);
+select f1 from t1 having max(f1)=f1;
+select f1 from t1 group by f1 having max(f1)=f1;
+set session sql_mode='ONLY_FULL_GROUP_BY';
+--error 1461
+select f1 from t1 having max(f1)=f1;
+select f1 from t1 group by f1 having max(f1)=f1;
+set session sql_mode='';
+drop table t1;
diff --git a/sql/item.cc b/sql/item.cc
index e3da950ceef..9498bf3fcd8 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -3153,7 +3153,8 @@ static Item** find_field_in_group_list(Item *find_item, ORDER *group_list)
     both clauses contain different fields with the same names, a warning is
     issued that name of 'ref' is ambiguous. We extend ANSI SQL in that when no
     GROUP BY column is found, then a HAVING name is resolved as a possibly
-    derived SELECT column.
+    derived SELECT column. This extension is allowed only if the
+    MODE_ONLY_FULL_GROUP_BY sql mode isn't enabled.
 
   NOTES
     The resolution procedure is:
@@ -3163,7 +3164,9 @@ static Item** find_field_in_group_list(Item *find_item, ORDER *group_list)
       in the GROUP BY clause of Q.
     - If found different columns with the same name in GROUP BY and SELECT
       - issue a warning and return the GROUP BY column,
-      - otherwise return the found SELECT column.
+      - otherwise
+        - if the MODE_ONLY_FULL_GROUP_BY mode is enabled return error
+        - else return the found SELECT column.
 
 
   RETURN
@@ -3208,6 +3211,17 @@ resolve_ref_in_select_and_group(THD *thd, Item_ident *ref, SELECT_LEX *select)
     }
   }
 
+  if (thd->variables.sql_mode & MODE_ONLY_FULL_GROUP_BY &&
+      select_ref != not_found_item && !group_by_ref)
+  {
+    /*
+      Report the error if fields was found only in the SELECT item list and
+      the strict mode is enabled.
+    */
+    my_error(ER_NON_GROUPING_FIELD_USED, MYF(0),
+             ref->name, "HAVING");
+    return NULL;
+  }
   if (select_ref != not_found_item || group_by_ref)
   {
     if (select_ref != not_found_item && !ambiguous_fields)
diff --git a/sql/share/errmsg.txt b/sql/share/errmsg.txt
index 37487c245a9..e0adb3fc408 100644
--- a/sql/share/errmsg.txt
+++ b/sql/share/errmsg.txt
@@ -5611,3 +5611,5 @@ ER_TABLE_NEEDS_UPGRADE
          eng "Table upgrade required. Please do \"REPAIR TABLE `%-.32s`\" to fix it!"
 ER_SP_NO_AGGREGATE 42000
 	eng "AGGREGATE is not supported for stored functions"
+ER_NON_GROUPING_FIELD_USED 42000
+	eng "non-grouping field '%-.64s' is used in %-.64s clause"
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 0211539e784..8daed345433 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -12613,6 +12613,10 @@ setup_group(THD *thd, Item **ref_pointer_array, TABLE_LIST *tables,
       if (item->type() != Item::SUM_FUNC_ITEM && !item->marker &&
 	  !item->const_item())
       {
+        /*
+          TODO: change ER_WRONG_FIELD_WITH_GROUP to more detailed
+          ER_NON_GROUPING_FIELD_USED
+        */
 	my_error(ER_WRONG_FIELD_WITH_GROUP, MYF(0), item->full_name());
 	return 1;
       }

From f48b10f34022203932a93db85c040739f17d2e09 Mon Sep 17 00:00:00 2001
From: "brian@zim.(none)" <>
Date: Thu, 20 Apr 2006 18:23:04 -0700
Subject: [PATCH 025/108] Dean noticed that constant flush calls caused the
 archive stream file to flush empty buffers. This patch removes that behavior.

---
 sql/ha_archive.cc | 43 ++++++++++++++++++++++++++++++++-----------
 sql/ha_archive.h  |  2 ++
 2 files changed, 34 insertions(+), 11 deletions(-)

diff --git a/sql/ha_archive.cc b/sql/ha_archive.cc
index cad81926a72..bfb90b607ee 100644
--- a/sql/ha_archive.cc
+++ b/sql/ha_archive.cc
@@ -396,6 +396,7 @@ ARCHIVE_SHARE *ha_archive::get_share(const char *table_name,
     share->table_name_length= length;
     share->table_name= tmp_name;
     share->crashed= FALSE;
+    share->archive_write_open= FALSE;
     fn_format(share->data_file_name,table_name,"",ARZ,MY_REPLACE_EXT|MY_UNPACK_FILENAME);
     fn_format(meta_file_name,table_name,"",ARM,MY_REPLACE_EXT|MY_UNPACK_FILENAME);
     strmov(share->table_name,table_name);
@@ -413,16 +414,7 @@ ARCHIVE_SHARE *ha_archive::get_share(const char *table_name,
     */
     if (read_meta_file(share->meta_file, &share->rows_recorded))
       share->crashed= TRUE;
-    else
-      (void)write_meta_file(share->meta_file, share->rows_recorded, TRUE);
 
-    /* 
-      It is expensive to open and close the data files and since you can't have
-      a gzip file that can be both read and written we keep a writer open
-      that is shared amoung all open tables.
-    */
-    if ((share->archive_write= gzopen(share->data_file_name, "ab")) == NULL)
-      share->crashed= TRUE;
     VOID(my_hash_insert(&archive_open_tables, (byte*) share));
     thr_lock_init(&share->lock);
   }
@@ -460,8 +452,9 @@ int ha_archive::free_share(ARCHIVE_SHARE *share)
       (void)write_meta_file(share->meta_file, share->rows_recorded, TRUE);
     else
       (void)write_meta_file(share->meta_file, share->rows_recorded, FALSE);
-    if (gzclose(share->archive_write) == Z_ERRNO)
-      rc= 1;
+    if (share->archive_write_open)
+      if (gzclose(share->archive_write) == Z_ERRNO)
+        rc= 1;
     if (my_close(share->meta_file, MYF(0)))
       rc= 1;
     my_free((gptr) share, MYF(0));
@@ -471,6 +464,26 @@ int ha_archive::free_share(ARCHIVE_SHARE *share)
   DBUG_RETURN(rc);
 }
 
+int ha_archive::init_archive_writer()
+{
+  DBUG_ENTER("ha_archive::init_archive_writer");
+  (void)write_meta_file(share->meta_file, share->rows_recorded, TRUE);
+
+  /* 
+    It is expensive to open and close the data files and since you can't have
+    a gzip file that can be both read and written we keep a writer open
+    that is shared amoung all open tables.
+  */
+  if ((share->archive_write= gzopen(share->data_file_name, "ab")) == NULL)
+  {
+    share->crashed= TRUE;
+    DBUG_RETURN(1);
+  }
+  share->archive_write_open= TRUE;
+
+  DBUG_RETURN(0);
+}
+
 
 /*
   We just implement one additional file extension.
@@ -693,6 +706,10 @@ int ha_archive::write_row(byte *buf)
   if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_INSERT)
     table->timestamp_field->set_time();
   pthread_mutex_lock(&share->mutex);
+  if (!share->archive_write_open)
+    if (init_archive_writer())
+      DBUG_RETURN(HA_ERR_CRASHED_ON_USAGE);
+
   share->rows_recorded++;
   rc= real_write_row(buf, share->archive_write);
   pthread_mutex_unlock(&share->mutex);
@@ -893,6 +910,10 @@ int ha_archive::optimize(THD* thd, HA_CHECK_OPT* check_opt)
   gzFile writer;
   char writer_filename[FN_REFLEN];
 
+  /* Open up the writer if we haven't yet */
+  if (!share->archive_write_open)
+    init_archive_writer();
+
   /* Flush any waiting data */
   gzflush(share->archive_write, Z_SYNC_FLUSH);
 
diff --git a/sql/ha_archive.h b/sql/ha_archive.h
index 0fa5cdc56ca..2bac9fa605e 100644
--- a/sql/ha_archive.h
+++ b/sql/ha_archive.h
@@ -34,6 +34,7 @@ typedef struct st_archive_share {
   THR_LOCK lock;
   File meta_file;           /* Meta file we use */
   gzFile archive_write;     /* Archive file we are working with */
+  bool archive_write_open;
   bool dirty;               /* Flag for if a flush should occur */
   bool crashed;             /* Meta file is crashed */
   ha_rows rows_recorded;    /* Number of rows in tables */
@@ -87,6 +88,7 @@ public:
   int write_meta_file(File meta_file, ha_rows rows, bool dirty);
   ARCHIVE_SHARE *get_share(const char *table_name, TABLE *table, int *rc);
   int free_share(ARCHIVE_SHARE *share);
+  int init_archive_writer();
   bool auto_repair() const { return 1; } // For the moment we just do this
   int read_data_header(gzFile file_to_read);
   int write_data_header(gzFile file_to_write);

From 57980ef4d52a9495d18be80fb8716e8ecb80f522 Mon Sep 17 00:00:00 2001
From: "jimw@mysql.com" <>
Date: Thu, 20 Apr 2006 19:17:14 -0700
Subject: [PATCH 026/108] Bug #18617: mysql-test-run.pl, partially wrong
 handling of option "start-dirty"

  This was a case of too much code. The --start-dirty option should act
  just like --start-and-exit, except it skips the database initialization
  step. Now it does, which means it picks up the options from the specified
  test case.
---
 mysql-test/mysql-test-run.pl | 33 ++++++++++-----------------------
 1 file changed, 10 insertions(+), 23 deletions(-)

diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl
index a045441e046..f37fb5b721a 100755
--- a/mysql-test/mysql-test-run.pl
+++ b/mysql-test/mysql-test-run.pl
@@ -407,22 +407,7 @@ sub main () {
     }
   }
 
-  if ( $opt_start_dirty )
-  {
-    if ( ndbcluster_start($opt_with_ndbcluster) )
-    {
-      mtr_error("Can't start ndbcluster");
-    }
-    if ( mysqld_start('master',0,[],[],$using_ndbcluster_master) )
-    {
-      mtr_report("Servers started, exiting");
-    }
-    else
-    {
-      mtr_error("Can't start the mysqld server");
-    }
-  }
-  elsif ( $opt_bench )
+  if ( $opt_bench )
   {
     run_benchmarks(shift);      # Shift what? Extra arguments?!
   }
@@ -2027,10 +2012,11 @@ sub run_testcase ($) {
   }
 
   # ----------------------------------------------------------------------
-  # If --start-and-exit given, stop here to let user manually run tests
+  # If --start-and-exit or --start-dirty given, stop here to let user manually
+  # run tests
   # ----------------------------------------------------------------------
 
-  if ( $opt_start_and_exit )
+  if ( $opt_start_and_exit or $opt_start_dirty )
   {
     mtr_report("\nServers started, exiting");
     exit(0);
@@ -3409,11 +3395,12 @@ Misc options
   comment=STR           Write STR to the output
   script-debug          Debug this script itself
   timer                 Show test case execution time
-  start-and-exit        Only initiate and start the "mysqld" servers, use the startup
-                        settings for the specified test case if any
-  start-dirty           Only start the "mysqld" servers without initiation
-  fast                  Don't try to cleanup from earlier runs
-  reorder               Reorder tests to get less server restarts
+  start-and-exit        Only initialize and start the servers, using the
+                        startup settings for the specified test case (if any)
+  start-dirty           Only start the servers (without initialization) for
+                        the specified test case (if any)
+  fast                  Don't try to clean up from earlier runs
+  reorder               Reorder tests to get fewer server restarts
   help                  Get this help text
   unified-diff | udiff  When presenting differences, use unified diff
 

From 4d392fb9f4a2cb50fb72393cb0f1512d515f05f5 Mon Sep 17 00:00:00 2001
From: "jimw@mysql.com" <>
Date: Thu, 20 Apr 2006 20:41:12 -0700
Subject: [PATCH 027/108] Bug #16195: SHOW VARIABLES doesn't report correctly
 sql_warnings and sql_notes values

  SQL_WARNINGS and SQL_NOTES were being displayed with SHOW_BOOL, but they
  are system variables that need SHOW_SYS to be used.
---
 mysql-test/r/variables.result | 15 +++++++++++++++
 mysql-test/t/variables.test   | 13 ++++++++++++-
 sql/set_var.cc                |  4 ++--
 3 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/mysql-test/r/variables.result b/mysql-test/r/variables.result
index 1d1c76ab3fe..b6ff60ebb34 100644
--- a/mysql-test/r/variables.result
+++ b/mysql-test/r/variables.result
@@ -584,3 +584,18 @@ set @@global.character_set_filesystem=default;
 select @@global.character_set_filesystem;
 @@global.character_set_filesystem
 binary
+set @@sql_notes = 0, @@sql_warnings = 0;
+show variables like 'sql_notes';
+Variable_name	Value
+sql_notes	OFF
+show variables like 'sql_warnings';
+Variable_name	Value
+sql_warnings	OFF
+set @@sql_notes = 1, @@sql_warnings = 1;
+show variables like 'sql_notes';
+Variable_name	Value
+sql_notes	ON
+show variables like 'sql_warnings';
+Variable_name	Value
+sql_warnings	ON
+End of 5.0 tests
diff --git a/mysql-test/t/variables.test b/mysql-test/t/variables.test
index 8d8dc7896df..79f4675d013 100644
--- a/mysql-test/t/variables.test
+++ b/mysql-test/t/variables.test
@@ -472,4 +472,15 @@ select @@character_set_filesystem;
 set @@global.character_set_filesystem=default;
 select @@global.character_set_filesystem;
 
-# End of 5.0 tests
+#
+# Bug #16195: SHOW VARIABLES doesn't report correctly sql_warnings and
+# sql_notes values
+# 
+set @@sql_notes = 0, @@sql_warnings = 0;
+show variables like 'sql_notes';
+show variables like 'sql_warnings';
+set @@sql_notes = 1, @@sql_warnings = 1;
+show variables like 'sql_notes';
+show variables like 'sql_warnings';
+
+--echo End of 5.0 tests
diff --git a/sql/set_var.cc b/sql/set_var.cc
index a0b60251354..1f46865b260 100644
--- a/sql/set_var.cc
+++ b/sql/set_var.cc
@@ -989,8 +989,8 @@ struct show_var_st init_vars[]= {
 #endif
   {sys_sort_buffer.name,      (char*) &sys_sort_buffer, 	    SHOW_SYS},
   {sys_sql_mode.name,         (char*) &sys_sql_mode,                SHOW_SYS},
-  {"sql_notes",               (char*) &sys_sql_notes,               SHOW_BOOL},
-  {"sql_warnings",            (char*) &sys_sql_warnings,            SHOW_BOOL},
+  {"sql_notes",               (char*) &sys_sql_notes,               SHOW_SYS},
+  {"sql_warnings",            (char*) &sys_sql_warnings,            SHOW_SYS},
   {sys_storage_engine.name,   (char*) &sys_storage_engine,          SHOW_SYS},
   {sys_sync_frm.name,         (char*) &sys_sync_frm,               SHOW_SYS},
 #ifdef HAVE_TZNAME

From ec00b92f48b9ed02731ad37f51477d6c8cb1f277 Mon Sep 17 00:00:00 2001
From: "jimw@mysql.com" <>
Date: Thu, 20 Apr 2006 21:56:53 -0700
Subject: [PATCH 028/108] Bug #12792: @@system_time_zone is not SELECTable Bug
 #15684: @@version_* are not all SELECTable

  Added the appropriate information as read-only system variables, and
  also removed some special-case handling of @@version along the way.

  @@version_bdb was added, but isn't included in the test because it
  depends on the presence of BDB.
---
 mysql-test/r/variables.result | 11 ++++++++++-
 mysql-test/t/variables.test   | 21 +++++++++++++++++++--
 sql/item_func.cc              |  6 ------
 sql/set_var.cc                | 33 ++++++++++++++++++++++++++-------
 4 files changed, 55 insertions(+), 16 deletions(-)

diff --git a/mysql-test/r/variables.result b/mysql-test/r/variables.result
index 1d1c76ab3fe..77b3b54c861 100644
--- a/mysql-test/r/variables.result
+++ b/mysql-test/r/variables.result
@@ -275,7 +275,7 @@ ERROR HY000: Variable 'autocommit' is a SESSION variable and can't be used with
 select @@global.timestamp;
 ERROR HY000: Variable 'timestamp' is a SESSION variable
 set @@version='';
-ERROR HY000: Unknown system variable 'version'
+ERROR HY000: Variable 'version' is a read only variable
 set @@concurrent_insert=1;
 ERROR HY000: Variable 'concurrent_insert' is a GLOBAL variable and should be set with SET GLOBAL
 set @@global.sql_auto_is_null=1;
@@ -384,6 +384,7 @@ select @@sql_max_join_size,@@max_join_size;
 set sql_quote_show_create=1;
 set sql_safe_updates=1;
 set sql_select_limit=1;
+set sql_select_limit=default;
 set sql_warnings=1;
 set global table_cache=100;
 set storage_engine=myisam;
@@ -584,3 +585,11 @@ set @@global.character_set_filesystem=default;
 select @@global.character_set_filesystem;
 @@global.character_set_filesystem
 binary
+select @@system_time_zone;
+@@system_time_zone
+#
+select @@version, @@version_comment, @@version_compile_machine,
+@@version_compile_os;
+@@version	@@version_comment	@@version_compile_machine	@@version_compile_os
+#	#	#	#
+End of 5.0 tests
diff --git a/mysql-test/t/variables.test b/mysql-test/t/variables.test
index 8d8dc7896df..fde352efa7b 100644
--- a/mysql-test/t/variables.test
+++ b/mysql-test/t/variables.test
@@ -169,7 +169,7 @@ set collation_connection=NULL;
 set global autocommit=1;
 --error 1238
 select @@global.timestamp;
---error 1193
+--error 1238 
 set @@version='';
 --error 1229
 set @@concurrent_insert=1;
@@ -258,6 +258,8 @@ select @@sql_max_join_size,@@max_join_size;
 set sql_quote_show_create=1;
 set sql_safe_updates=1;
 set sql_select_limit=1;
+# reset it, so later tests don't get confused
+set sql_select_limit=default;
 set sql_warnings=1;
 set global table_cache=100;
 set storage_engine=myisam;
@@ -472,4 +474,19 @@ select @@character_set_filesystem;
 set @@global.character_set_filesystem=default;
 select @@global.character_set_filesystem;
 
-# End of 5.0 tests
+#
+# Bug #12792: @@system_time_zone is not SELECTable.
+#
+# Don't actually output, since it depends on the system
+--replace_column 1 #
+select @@system_time_zone;
+
+#
+# Bug #15684: system variables cannot be SELECTed (e.g. @@version_comment)
+#
+# Don't actually output, since it depends on the system
+--replace_column 1 # 2 # 3 # 4 #
+select @@version, @@version_comment, @@version_compile_machine,
+       @@version_compile_os;
+
+--echo End of 5.0 tests
diff --git a/sql/item_func.cc b/sql/item_func.cc
index 4bdb62c6e7a..1eda622ab0d 100644
--- a/sql/item_func.cc
+++ b/sql/item_func.cc
@@ -4558,12 +4558,6 @@ Item *get_system_var(THD *thd, enum_var_type var_type, LEX_STRING name,
   sys_var *var;
   LEX_STRING *base_name, *component_name;
 
-  if (component.str == 0 &&
-      !my_strcasecmp(system_charset_info, name.str, "VERSION"))
-    return new Item_string(NULL, server_version,
-			   (uint) strlen(server_version),
-			   system_charset_info, DERIVATION_SYSCONST);
-
   if (component.str)
   {
     base_name= &component;
diff --git a/sql/set_var.cc b/sql/set_var.cc
index a0b60251354..907f14c0c20 100644
--- a/sql/set_var.cc
+++ b/sql/set_var.cc
@@ -377,6 +377,8 @@ sys_var_thd_table_type  sys_table_type("table_type",
 sys_var_thd_storage_engine sys_storage_engine("storage_engine",
 				       &SV::table_type);
 sys_var_bool_ptr	sys_sync_frm("sync_frm", &opt_sync_frm);
+sys_var_const_str	sys_system_time_zone("system_time_zone",
+                                             system_time_zone);
 sys_var_long_ptr	sys_table_cache_size("table_cache",
 					     &table_cache_size);
 sys_var_long_ptr	sys_table_lock_wait_timeout("table_lock_wait_timeout",
@@ -391,6 +393,16 @@ sys_var_thd_ulong	sys_tmp_table_size("tmp_table_size",
 					   &SV::tmp_table_size);
 sys_var_bool_ptr  sys_timed_mutexes("timed_mutexes",
                                     &timed_mutexes);
+sys_var_const_str	sys_version("version", server_version);
+#ifdef HAVE_BERKELEY_DB
+sys_var_const_str	sys_version_bdb("version_bdb", DB_VERSION_STRING);
+#endif
+sys_var_const_str	sys_version_comment("version_comment",
+                                            MYSQL_COMPILATION_COMMENT);
+sys_var_const_str	sys_version_compile_machine("version_compile_machine",
+                                                    MACHINE_TYPE);
+sys_var_const_str	sys_version_compile_os("version_compile_os",
+                                               SYSTEM_TYPE);
 sys_var_thd_ulong	sys_net_wait_timeout("wait_timeout",
 					     &SV::net_wait_timeout);
 
@@ -546,7 +558,6 @@ sys_var_thd_time_zone            sys_time_zone("time_zone");
 
 /* Read only variables */
 
-sys_var_const_str		sys_os("version_compile_os", SYSTEM_TYPE);
 sys_var_readonly                sys_have_innodb("have_innodb", OPT_GLOBAL,
                                                 SHOW_CHAR, get_have_innodb);
 /* Global read-only variable describing server license */
@@ -698,6 +709,7 @@ sys_var *sys_variables[]=
   &sys_sql_notes,
   &sys_storage_engine,
   &sys_sync_frm,
+  &sys_system_time_zone,
   &sys_table_cache_size,
   &sys_table_lock_wait_timeout,
   &sys_table_type,
@@ -710,7 +722,13 @@ sys_var *sys_variables[]=
   &sys_trans_alloc_block_size,
   &sys_trans_prealloc_size,
   &sys_tx_isolation,
-  &sys_os,
+  &sys_version,
+#ifdef HAVE_BERKELEY_DB
+  &sys_version_bdb,
+#endif
+  &sys_version_comment,
+  &sys_version_compile_machine,
+  &sys_version_compile_os,
 #ifdef HAVE_INNOBASE_DB
   &sys_innodb_fast_shutdown,
   &sys_innodb_max_dirty_pages_pct,
@@ -1015,13 +1033,14 @@ struct show_var_st init_vars[]= {
   {sys_tx_isolation.name,     (char*) &sys_tx_isolation,	    SHOW_SYS},
   {sys_updatable_views_with_limit.name,
                               (char*) &sys_updatable_views_with_limit,SHOW_SYS},
-  {"version",                 server_version,                       SHOW_CHAR},
+  {sys_version.name,          (char*) &sys_version,                 SHOW_SYS},
 #ifdef HAVE_BERKELEY_DB
-  {"version_bdb",             (char*) DB_VERSION_STRING,            SHOW_CHAR},
+  {sys_version_bdb.name,      (char*) &sys_version_bdb,             SHOW_SYS},
 #endif
-  {"version_comment",         (char*) MYSQL_COMPILATION_COMMENT,    SHOW_CHAR},
-  {"version_compile_machine", (char*) MACHINE_TYPE,		    SHOW_CHAR},
-  {sys_os.name,		      (char*) &sys_os,			    SHOW_SYS},
+  {sys_version_comment.name,  (char*) &sys_version_comment,         SHOW_SYS},
+  {sys_version_compile_machine.name, (char*) &sys_version_compile_machine,
+   SHOW_SYS},
+  {sys_version_compile_os.name,	(char*) &sys_version_compile_os,    SHOW_SYS},
   {sys_net_wait_timeout.name, (char*) &sys_net_wait_timeout,	    SHOW_SYS},
   {NullS, NullS, SHOW_LONG}
 };

From d1640175dbe68a21b965a38e6c7e63990bb64059 Mon Sep 17 00:00:00 2001
From: "msvensson@neptunus.(none)" <>
Date: Fri, 21 Apr 2006 12:30:33 +0200
Subject: [PATCH 029/108] Don't run mysqld when started in ddd Maybe we should
 do the same for gdb?

---
 mysql-test/mysql-test-run.pl | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl
index a045441e046..15c1817bdf4 100755
--- a/mysql-test/mysql-test-run.pl
+++ b/mysql-test/mysql-test-run.pl
@@ -3212,8 +3212,7 @@ sub ddd_arguments {
 	       "break mysql_parse\n" .
 	       "commands 1\n" .
 	       "disable 1\n" .
-	       "end\n" .
-	       "run");
+	       "end");
   }
 
   if ( $opt_manual_ddd )

From 752dd29157a2e053aaa4c23d463848a917c275c0 Mon Sep 17 00:00:00 2001
From: "msvensson@neptunus.(none)" <>
Date: Fri, 21 Apr 2006 15:57:03 +0200
Subject: [PATCH 030/108] Disable udf test

---
 mysql-test/t/disabled.def | 1 +
 1 file changed, 1 insertion(+)

diff --git a/mysql-test/t/disabled.def b/mysql-test/t/disabled.def
index f71e24ff3ed..fb1fee24c43 100644
--- a/mysql-test/t/disabled.def
+++ b/mysql-test/t/disabled.def
@@ -12,3 +12,4 @@
 
 sp-goto         : GOTO is currently is disabled - will be fixed in the future
 ndb_load        : Bug#17233
+udf             : Disabled by Magnus 

From 7af32b07485f33387e6d1d9a9604902a0fb0951c Mon Sep 17 00:00:00 2001
From: "msvensson@neptunus.(none)" <>
Date: Fri, 21 Apr 2006 18:19:50 +0200
Subject: [PATCH 031/108] Move telpate instantiations of taocrypt objects to
 taocrypt/template_instnt.cpp

---
 extra/yassl/src/template_instnt.cpp          | 7 -------
 extra/yassl/taocrypt/src/template_instnt.cpp | 3 +++
 2 files changed, 3 insertions(+), 7 deletions(-)

diff --git a/extra/yassl/src/template_instnt.cpp b/extra/yassl/src/template_instnt.cpp
index c55ca39bec2..5782df213ea 100644
--- a/extra/yassl/src/template_instnt.cpp
+++ b/extra/yassl/src/template_instnt.cpp
@@ -35,13 +35,6 @@
 #include "openssl/ssl.h"
 
 #ifdef HAVE_EXPLICIT_TEMPLATE_INSTANTIATION
-#if !defined(USE_CRYPTOPP_LIB)
-namespace TaoCrypt {
-template class HMAC;
-template class HMAC;
-template class HMAC;
-}
-#endif  // USE_CRYPTOPP_LIB
 
 namespace mySTL {
 template class list;
diff --git a/extra/yassl/taocrypt/src/template_instnt.cpp b/extra/yassl/taocrypt/src/template_instnt.cpp
index eabcc6d9779..12bcd8238f2 100644
--- a/extra/yassl/taocrypt/src/template_instnt.cpp
+++ b/extra/yassl/taocrypt/src/template_instnt.cpp
@@ -30,6 +30,7 @@
 #include "sha.hpp"
 #include "md5.hpp"
 #include "hmac.hpp"
+#include "ripemd.hpp"
 #include "pwdbased.hpp"
 #include "algebra.hpp"
 #include "vector.hpp"
@@ -62,6 +63,8 @@ template void tcArrayDelete(char*);
 template class PBKDF2_HMAC;
 template class HMAC;
 template class HMAC;
+template class HMAC;
+
 }
 
 namespace mySTL {

From 559995f160ef36a7e5a3b9afdd2aa6b31521efb7 Mon Sep 17 00:00:00 2001
From: "jimw@mysql.com" <>
Date: Fri, 21 Apr 2006 09:48:49 -0700
Subject: [PATCH 032/108] Bug #19083 ./mysql-test-run.pl starts NDB when it is
 not needed

  Now NDB is only initialized and started when the tests that are
  being run will make use of it. The same thing is also done for the
  slave databases and the instance manager.

  After review from Magnus: Only take a snapshot of the data directories
  that are in use.
---
 mysql-test/mysql-test-run.pl | 107 ++++++++++++++++++++++-------------
 mysql-test/ndb/ndbcluster.sh |   4 +-
 2 files changed, 71 insertions(+), 40 deletions(-)

diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl
index a045441e046..63bc9115891 100755
--- a/mysql-test/mysql-test-run.pl
+++ b/mysql-test/mysql-test-run.pl
@@ -333,6 +333,7 @@ our @data_dir_lst;
 sub main ();
 sub initial_setup ();
 sub command_line_setup ();
+sub snapshot_setup ();
 sub executable_setup ();
 sub environment_setup ();
 sub kill_running_server ();
@@ -343,7 +344,7 @@ sub ndbcluster_install ();
 sub ndbcluster_start ($);
 sub ndbcluster_stop ();
 sub run_benchmarks ($);
-sub run_tests ();
+sub initialize_servers ();
 sub mysql_install_db ();
 sub install_db ($$);
 sub run_testcase ($);
@@ -374,7 +375,7 @@ sub main () {
   command_line_setup();
   executable_setup();
 
-  check_ndbcluster_support();
+  check_ndbcluster_support(); # We check whether to actually use it later
   check_ssl_support();
 
   environment_setup();
@@ -389,24 +390,7 @@ sub main () {
   {
     gprof_prepare();
   }
-
-  if ( ! $glob_use_running_server )
-  {
-    if ( $opt_start_dirty )
-    {
-      kill_running_server();
-    }
-    else
-    {
-      kill_and_cleanup();
-      mysql_install_db();
-      if ( $opt_force )
-      {
-	save_installed_db();
-      }
-    }
-  }
-
+  
   if ( $opt_start_dirty )
   {
     if ( ndbcluster_start($opt_with_ndbcluster) )
@@ -424,15 +408,35 @@ sub main () {
   }
   elsif ( $opt_bench )
   {
+    initialize_servers();
     run_benchmarks(shift);      # Shift what? Extra arguments?!
   }
   elsif ( $opt_stress )
   {
+    initialize_servers();
     run_stress_test()
   }
   else
   {
-    run_tests();
+    # Figure out which tests we are going to run
+    my $tests= collect_test_cases($opt_suite);
+
+    # Turn off NDB and other similar options if no tests use it
+    my ($need_ndbcluster,$need_im,$need_slave);
+    foreach my $test (@$tests)
+    {
+      $need_ndbcluster||= $test->{ndb_test};
+      $need_im||= $test->{component_id} eq 'im';
+      $need_slave||= $test->{slave_num};
+    }
+    $opt_with_ndbcluster= 0 unless $need_ndbcluster;
+    $opt_skip_im= 1 unless $need_im;
+    $opt_skip_rpl= 1 unless $need_slave;
+
+    snapshot_setup();
+    initialize_servers();
+
+    run_suite($opt_suite, $tests);
   }
 
   mtr_exit(0);
@@ -983,20 +987,29 @@ sub command_line_setup () {
   $path_mysqltest_log=  "$opt_vardir/log/mysqltest.log";
 
   $path_snapshot= "$opt_tmpdir/snapshot_$opt_master_myport/";
+}
+
+sub snapshot_setup () {
 
   # Make a list of all data_dirs
   @data_dir_lst = (
     $master->[0]->{'path_myddir'},
-    $master->[1]->{'path_myddir'},
-    $slave->[0]->{'path_myddir'},
-    $slave->[1]->{'path_myddir'},
-    $slave->[2]->{'path_myddir'});
+    $master->[1]->{'path_myddir'});
 
-  foreach my $instance (@{$instance_manager->{'instances'}})
+  unless ($opt_skip_rpl)
   {
-    push(@data_dir_lst, $instance->{'path_datadir'});
+    push @data_dir_lst, ($slave->[0]->{'path_myddir'},
+                         $slave->[1]->{'path_myddir'},
+                         $slave->[2]->{'path_myddir'});
   }
 
+  unless ($opt_skip_im)
+  {
+    foreach my $instance (@{$instance_manager->{'instances'}})
+    {
+      push(@data_dir_lst, $instance->{'path_datadir'});
+    }
+  }
 }
 
 
@@ -1388,7 +1401,7 @@ sub check_ndbcluster_support () {
 
   if ($opt_with_ndbcluster)
   {
-    mtr_report("Using ndbcluster");
+    mtr_report("Using ndbcluster if necessary");
     return;
   }
 
@@ -1404,7 +1417,7 @@ sub check_ndbcluster_support () {
     $opt_with_ndbcluster= 0;
     return;
   }
-  mtr_report("Using ndbcluster, mysqld supports it");
+  mtr_report("Using ndbcluster if necessary, mysqld supports it");
   $opt_with_ndbcluster= 1;
   return;
 }
@@ -1561,12 +1574,9 @@ sub run_benchmarks ($) {
 
 # FIXME how to specify several suites to run? Comma separated list?
 
-sub run_tests () {
-  run_suite($opt_suite);
-}
 
 sub run_suite () {
-  my $suite= shift;
+  my ($suite, $tests)= @_;
 
   mtr_print_thick_line();
 
@@ -1574,8 +1584,6 @@ sub run_suite () {
 
   mtr_timer_start($glob_timers,"suite", 60 * $opt_suite_timeout);
 
-  my $tests= collect_test_cases($suite);
-
   mtr_report("Starting Tests in the '$suite' suite");
 
   mtr_print_header();
@@ -1617,14 +1625,37 @@ sub run_suite () {
 #
 ##############################################################################
 
+sub initialize_servers () {
+  if ( ! $glob_use_running_server )
+  {
+    if ( $opt_start_dirty )
+    {
+      kill_running_server();
+    }
+    else
+    {
+      kill_and_cleanup();
+      mysql_install_db();
+      if ( $opt_force )
+      {
+	save_installed_db();
+      }
+    }
+  }
+}
+
 sub mysql_install_db () {
 
   # FIXME not exactly true I think, needs improvements
   install_db('master', $master->[0]->{'path_myddir'});
   install_db('master', $master->[1]->{'path_myddir'});
-  install_db('slave',  $slave->[0]->{'path_myddir'});
-  install_db('slave',  $slave->[1]->{'path_myddir'});
-  install_db('slave',  $slave->[2]->{'path_myddir'});
+
+  if ( ! $opt_skip_rpl )
+  {
+    install_db('slave',  $slave->[0]->{'path_myddir'});
+    install_db('slave',  $slave->[1]->{'path_myddir'});
+    install_db('slave',  $slave->[2]->{'path_myddir'});
+  }
 
   if ( ! $opt_skip_im )
   {
diff --git a/mysql-test/ndb/ndbcluster.sh b/mysql-test/ndb/ndbcluster.sh
index c09c013552e..c17b3d316f4 100644
--- a/mysql-test/ndb/ndbcluster.sh
+++ b/mysql-test/ndb/ndbcluster.sh
@@ -232,8 +232,8 @@ cat `find "$fs_ndb" -name 'ndb_*.pid'` > "$fs_ndb/$pidfile"
 
 # test if Ndb Cluster starts properly
 
-echo "Waiting for started..."
-if ( $exec_waiter ) | grep "NDBT_ProgramExit: 0 - OK"; then :; else
+echo "Waiting for NDB data nodes to start..."
+if ( $exec_waiter ) | grep -q "NDBT_ProgramExit: 0 - OK"; then :; else
   echo "Ndbcluster startup failed"
   stop_default_ndbcluster
   exit 1

From c28ea5b03b06b052b5a59b3ddeb99bc51dec4428 Mon Sep 17 00:00:00 2001
From: "jimw@mysql.com" <>
Date: Fri, 21 Apr 2006 10:48:53 -0700
Subject: [PATCH 033/108] Bug #18312: mysqltest: --sleep=0 doesn't disable
 sleep

  Allow --sleep=0 to be specified to mysqltest, so that sleep calls
  can be disabled.

  Original patch from Paul DuBois.
---
 client/mysqltest.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/client/mysqltest.c b/client/mysqltest.c
index e51d83270b5..ecf54e40400 100644
--- a/client/mysqltest.c
+++ b/client/mysqltest.c
@@ -153,7 +153,7 @@ static uint global_expected_errors;
 
 /* ************************************************************************ */
 
-static int record = 0, opt_sleep=0;
+static int record= 0, opt_sleep= -1;
 static char *db = 0, *pass=0;
 const char *user = 0, *host = 0, *unix_sock = 0, *opt_basedir="./";
 static int port = 0;
@@ -1724,11 +1724,12 @@ int do_sleep(struct st_query *query, my_bool real_sleep)
 		query->first_argument);
 
   /* Fixed sleep time selected by --sleep option */
-  if (opt_sleep && !real_sleep)
+  if (opt_sleep >= 0 && !real_sleep)
     sleep_val= opt_sleep;
 
   DBUG_PRINT("info", ("sleep_val: %f", sleep_val));
-  my_sleep((ulong) (sleep_val * 1000000L));
+  if (sleep_val)
+    my_sleep((ulong) (sleep_val * 1000000L));
   query->last_argument= sleep_end;
   return 0;
 }
@@ -2935,7 +2936,7 @@ static struct my_option my_long_options[] =
    "Don't use the memory allocation checking.", 0, 0, 0, GET_NO_ARG, NO_ARG,
    0, 0, 0, 0, 0, 0},
   {"sleep", 'T', "Sleep always this many seconds on sleep commands.",
-   (gptr*) &opt_sleep, (gptr*) &opt_sleep, 0, GET_INT, REQUIRED_ARG, 0, 0, 0,
+   (gptr*) &opt_sleep, (gptr*) &opt_sleep, 0, GET_INT, REQUIRED_ARG, -1, 0, 0,
    0, 0, 0},
   {"socket", 'S', "Socket file to use for connection.",
    (gptr*) &unix_sock, (gptr*) &unix_sock, 0, GET_STR, REQUIRED_ARG, 0, 0, 0,

From 26be6ababe97a8c2374d0ca5af41c43ac575a7c3 Mon Sep 17 00:00:00 2001
From: "msvensson@neptunus.(none)" <>
Date: Fri, 21 Apr 2006 19:53:30 +0200
Subject: [PATCH 034/108] Remove -Wall  etc, not so portable compiler options

---
 extra/yassl/testsuite/Makefile.am | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/extra/yassl/testsuite/Makefile.am b/extra/yassl/testsuite/Makefile.am
index 3a07ac316e1..d91822f609e 100644
--- a/extra/yassl/testsuite/Makefile.am
+++ b/extra/yassl/testsuite/Makefile.am
@@ -4,8 +4,8 @@ testsuite_SOURCES  = testsuite.cpp ../taocrypt/test/test.cpp \
 	../examples/client/client.cpp ../examples/server/server.cpp \
 	../examples/echoclient/echoclient.cpp \
 	../examples/echoserver/echoserver.cpp
-testsuite_LDFLAGS  = -L../src/ -L../taocrypt/src $(PTHREAD_LDFLAGS)
-testsuite_CXXFLAGS = -DYASSL_PURE_C -DNO_MAIN_DRIVER -Wall -Wno-unused $(PTHREAD_CFLAGS)
-testsuite_LDADD    = -lyassl -ltaocrypt $(EXTRA_PTHREAD) $(EXTRA_SOCKET)
+testsuite_LDFLAGS  = -L../src/ -L../taocrypt/src
+testsuite_CXXFLAGS = -DYASSL_PURE_C -DNO_MAIN_DRIVER
+testsuite_LDADD    = -lyassl -ltaocrypt
 testsuite_DEPENDENCIES = ../src/libyassl.la ../taocrypt/src/libtaocrypt.la
 EXTRA_DIST = testsuite.dsp test.hpp input quit make.bat

From 29ace143a1cad2ef38d29816b8c3ff17632c298c Mon Sep 17 00:00:00 2001
From: "msvensson@neptunus.(none)" <>
Date: Sat, 22 Apr 2006 00:48:13 +0200
Subject: [PATCH 035/108] Backport fix for mysql client not using SSl library
 directly  - Add function mysql_get_ssl_cipher  - Use function
 mysql_get_ssl_cipher from mysql

---
 client/mysql.cc         |  5 ++---
 include/mysql.h         |  1 +
 libmysql/libmysql.def   |  1 +
 libmysqld/libmysqld.def |  1 +
 sql-common/client.c     | 21 +++++++++++++++++++++
 5 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/client/mysql.cc b/client/mysql.cc
index 8589bdb05ed..5b53570bf34 100644
--- a/client/mysql.cc
+++ b/client/mysql.cc
@@ -3235,10 +3235,9 @@ com_status(String *buffer __attribute__((unused)),
       mysql_free_result(result);
     } 
 #ifdef HAVE_OPENSSL
-    if (mysql.net.vio && mysql.net.vio->ssl_arg &&
-	SSL_get_cipher((SSL*) mysql.net.vio->ssl_arg))
+    if ((status= mysql_get_ssl_cipher(&mysql)))
       tee_fprintf(stdout, "SSL:\t\t\tCipher in use is %s\n",
-		  SSL_get_cipher((SSL*) mysql.net.vio->ssl_arg));
+		  status);
     else
 #endif /* HAVE_OPENSSL */
       tee_puts("SSL:\t\t\tNot in use", stdout);
diff --git a/include/mysql.h b/include/mysql.h
index 925a4525378..6217ce631b5 100644
--- a/include/mysql.h
+++ b/include/mysql.h
@@ -409,6 +409,7 @@ MYSQL *		STDCALL mysql_init(MYSQL *mysql);
 my_bool		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,
diff --git a/libmysql/libmysql.def b/libmysql/libmysql.def
index a469c67c466..cf45e20a697 100644
--- a/libmysql/libmysql.def
+++ b/libmysql/libmysql.def
@@ -65,6 +65,7 @@ EXPORTS
 	mysql_get_proto_info
 	mysql_get_server_info
 	mysql_get_client_version
+	mysql_get_ssl_cipher
 	mysql_info
 	mysql_init
 	mysql_insert_id
diff --git a/libmysqld/libmysqld.def b/libmysqld/libmysqld.def
index 93456901a7d..3895588e02c 100644
--- a/libmysqld/libmysqld.def
+++ b/libmysqld/libmysqld.def
@@ -58,6 +58,7 @@ EXPORTS
 	mysql_get_host_info
 	mysql_get_proto_info
 	mysql_get_server_info
+	mysql_get_ssl_cipher
 	mysql_info
 	mysql_init
 	mysql_insert_id
diff --git a/sql-common/client.c b/sql-common/client.c
index 84df31b7440..72745d72b12 100644
--- a/sql-common/client.c
+++ b/sql-common/client.c
@@ -1535,6 +1535,27 @@ mysql_ssl_free(MYSQL *mysql __attribute__((unused)))
   mysql->connector_fd = 0;
   DBUG_VOID_RETURN;
 }
+
+
+/*
+  Return the SSL cipher (if any) used for current
+  connection to the server.
+
+  SYNOPSYS
+    mysql_get_ssl_cipher()
+      mysql pointer to the mysql connection
+
+*/
+
+const char * STDCALL
+mysql_get_ssl_cipher(MYSQL *mysql)
+{
+  DBUG_ENTER("mysql_get_ssl_cipher");
+  if (mysql->net.vio && mysql->net.vio->ssl_arg)
+    DBUG_RETURN(SSL_get_cipher_name((SSL*)mysql->net.vio->ssl_arg));
+  DBUG_RETURN(NULL);
+}
+
 #endif /* HAVE_OPENSSL */
 
 

From 99b2d44c9c72d393f9fc330f73a855da728b1a56 Mon Sep 17 00:00:00 2001
From: "jimw@mysql.com" <>
Date: Fri, 21 Apr 2006 18:26:39 -0700
Subject: [PATCH 036/108] Bug #18607: LOAD DATA FROM MASTER fails because of
 INFORMATION_SCHEMA database

  Simply exclude INFORMATION_SCHEMA from LOAD DATA FROM MASTER just like
  we exclude the `mysql` database.

  There's no test for this, because it requires an unfiltered 'LOAD DATA
  FROM MASTER' which is too likely to cause chaos (such as when running
  the test suite against an external server).
---
 sql/repl_failsafe.cc | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/sql/repl_failsafe.cc b/sql/repl_failsafe.cc
index 5cdd24afba4..21e46e71825 100644
--- a/sql/repl_failsafe.cc
+++ b/sql/repl_failsafe.cc
@@ -860,7 +860,8 @@ bool load_master_data(THD* thd)
 
       if (!db_ok(db, replicate_do_db, replicate_ignore_db) ||
           !db_ok_with_wild_table(db) ||
-	  !strcmp(db,"mysql"))
+	  !strcmp(db,"mysql") ||
+          is_schema_db(db))
       {
 	*cur_table_res = 0;
 	continue;

From 3761b25696de07b6efee4cb8137b510b4efce0c0 Mon Sep 17 00:00:00 2001
From: "jimw@mysql.com" <>
Date: Fri, 21 Apr 2006 19:29:22 -0700
Subject: [PATCH 037/108] Bug #18495: mysqltest does not use the correct error
 number

  When looking up the error number for named errors in mysqltest .test
  files, we inadvertantly would match ER_WRONG_VALUE against
  ER_WRONG_VALUE_COUNT because we were using the length of the shorter
  string in strncmp(). Now we double-check the length of matches to
  make sure it was a complete match.
---
 client/mysqltest.c       | 8 +++++++-
 mysql-test/t/events.test | 4 ++--
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/client/mysqltest.c b/client/mysqltest.c
index cfd69e45ba7..b630de8be4e 100644
--- a/client/mysqltest.c
+++ b/client/mysqltest.c
@@ -1956,7 +1956,13 @@ static uint get_errcodes(match_err *to,struct st_query *q)
 	;
       for (; e->name; e++)
       {
-	if (!strncmp(start, e->name, (int) (p - start)))
+        /*
+          If we get a match, we need to check the length of the name we
+          matched against in case it was longer than what we are checking
+          (as in ER_WRONG_VALUE vs. ER_WRONG_VALUE_COUNT).
+        */
+	if (!strncmp(start, e->name, (int) (p - start)) &&
+            strlen(e->name) == (p - start))
 	{
 	  to[count].code.errnum= (uint) e->code;
 	  to[count].type= ERR_ERRNO;
diff --git a/mysql-test/t/events.test b/mysql-test/t/events.test
index f80297682b7..fbcd4924d56 100644
--- a/mysql-test/t/events.test
+++ b/mysql-test/t/events.test
@@ -320,9 +320,9 @@ drop event one_event;
 create event e_26 on schedule at '2017-01-01 00:00:00' disable do set @a = 5;
 select db, name, body, definer, convert_tz(execute_at, 'UTC', 'SYSTEM'), on_completion from mysql.event;
 drop event e_26;
---error 1504
+--error ER_WRONG_VALUE
 create event e_26 on schedule at NULL disabled do set @a = 5;
---error 1504
+--error ER_WRONG_VALUE
 create event e_26 on schedule at 'definitely not a datetime' disabled do set @a = 5;
 
 set names utf8;

From 56f1424c1ace31904b119d617634a51ff0c025fa Mon Sep 17 00:00:00 2001
From: "msvensson@shellback.(none)" <>
Date: Sat, 22 Apr 2006 21:53:33 +0200
Subject: [PATCH 038/108] Fix for building shared libraries on AIX with 64-bit
 mode Set building of shared libraries on QNX to defatul OFF

---
 configure.in | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)

diff --git a/configure.in b/configure.in
index c10edbd841a..fe6ac7483ba 100644
--- a/configure.in
+++ b/configure.in
@@ -218,6 +218,46 @@ then
 else
   AC_PATH_PROG(AS, as, as)
 fi
+
+# These checks has to be made befoe we buil libtool as they affect
+# what is written into libtool.
+case $SYSTEM_TYPE in
+    *aix5*)
+       # Find out which ABI we are using.
+      echo 'int i;' > conftest.$ac_ext
+      if AC_TRY_EVAL(ac_compile); then
+        case `/usr/bin/file conftest.$ac_objext` in
+        *"32-bit XCOFF"*)
+          # OBJECT_MODE=32
+          ;;
+         *"64-bit XCOFF"*)
+	   AC_MSG_WARN([Setting 64-bit mode for AIX 5.*])
+           # It was detected that compiler is using 64-bit mode
+	   # Set flags for CC and NM so that those tools will work
+           # in 64-bit mode when called from libtool
+	   # The easiest way fix this is "export OBJECT_MODE=64"
+	   CC="$CC -q64"
+	   CXX="$CXX -q64"
+	   if test "X${NM+set}" != Xset; then
+	     NM="/usr/bin/nm -B -X64"
+           fi
+          ;;
+	esac
+      fi
+      rm -rf conftest*
+    ;;
+    *qnx*)
+    # Don't build shared libraries on QNX as it will run out of
+    # stack and segfault
+    AC_MSG_WARN([Turning off building of shared libraries])
+    AC_DISABLE_SHARED
+    ;;
+    *)
+    ;;
+esac
+
+LINK= "OBJECT_MODE=64 $LINK"
+
 # Still need ranlib for readline; local static use only so no libtool.
 AC_PROG_RANLIB
 # We use libtool
@@ -229,6 +269,13 @@ AC_PROG_LIBTOOL
 LIBTOOL="$LIBTOOL --preserve-dup-deps"
 AC_SUBST(LIBTOOL)dnl
 
+AC_SUBST(NM)dnl
+
+# NM= "$NM -X64"
+#archive_expsym_cmds= `echo "$archive_expsym_cmds" | sed -e '/"$(CC)"//'`
+#archive_expsym_cmds= "$CC -q64 $archive_expsym_cmds"
+#  CXXFLAGS=`echo "$CXXFLAGS -Werror" | sed -e 's/-fbranch-probabilities//; s/-Wall//; s/-ansi//; s/-pedantic//; s/-Wcheck//'`
+
 #AC_LIBTOOL_DLOPEN AC_LIBTOOL_WIN32_DLL AC_DISABLE_FAST_INSTALL AC_DISABLE_SHARED AC_DISABLE_STATIC
 
 # AC_PROG_INSTALL

From d59a0f4840efb8cec88edf0165507afb8c8bc3f1 Mon Sep 17 00:00:00 2001
From: "msvensson@neptunus.(none)" <>
Date: Mon, 24 Apr 2006 10:21:09 +0200
Subject: [PATCH 039/108] Bug#17002  mysql-test-run as root user  - Add test to
 see if tests are running with root permissions  - Disables tests that uses
 chmod if that is the case

---
 mysql-test/include/not_as_root.inc   |  4 ++++
 mysql-test/mysql-test-run.pl         | 29 ++++++++++++++++++++++++++++
 mysql-test/r/not_as_root.require     |  2 ++
 mysql-test/t/information_schema.test |  3 +++
 mysql-test/t/rpl_rotate_logs.test    |  3 +++
 5 files changed, 41 insertions(+)
 create mode 100644 mysql-test/include/not_as_root.inc
 create mode 100644 mysql-test/r/not_as_root.require

diff --git a/mysql-test/include/not_as_root.inc b/mysql-test/include/not_as_root.inc
new file mode 100644
index 00000000000..315963d824e
--- /dev/null
+++ b/mysql-test/include/not_as_root.inc
@@ -0,0 +1,4 @@
+-- require r/not_as_root.require
+disable_query_log;
+select $MYSQL_TEST_ROOT as running_as_root;
+enable_query_log;
diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl
index a045441e046..9a801884855 100755
--- a/mysql-test/mysql-test-run.pl
+++ b/mysql-test/mysql-test-run.pl
@@ -338,6 +338,7 @@ sub environment_setup ();
 sub kill_running_server ();
 sub kill_and_cleanup ();
 sub check_ssl_support ();
+sub check_running_as_root();
 sub check_ndbcluster_support ();
 sub ndbcluster_install ();
 sub ndbcluster_start ($);
@@ -376,6 +377,7 @@ sub main () {
 
   check_ndbcluster_support();
   check_ssl_support();
+  check_running_as_root();
 
   environment_setup();
   signal_setup();
@@ -1337,6 +1339,33 @@ sub kill_and_cleanup () {
 }
 
 
+sub  check_running_as_root () {
+  # Check if running as root
+  # i.e a file can be read regardless what mode we set it to
+  my $test_file= "test_running_as_root.txt";
+  mtr_tofile($test_file, "MySQL");
+  chmod(oct("0000"), $test_file);
+
+  my $result="";
+  if (open(FILE,"<",$test_file))
+  {
+    $result= join('', );
+    close FILE;
+  }
+
+  chmod(oct("0755"), $test_file);
+  unlink($test_file);
+
+  $ENV{'MYSQL_TEST_ROOT'}= "NO";
+  if ($result eq "MySQL")
+  {
+    mtr_warning("running this script as _root_ will cause some " .
+                "tests to be skipped");
+    $ENV{'MYSQL_TEST_ROOT'}= "YES";
+  }
+}
+
+
 
 sub check_ssl_support () {
 
diff --git a/mysql-test/r/not_as_root.require b/mysql-test/r/not_as_root.require
new file mode 100644
index 00000000000..d9ea5244efc
--- /dev/null
+++ b/mysql-test/r/not_as_root.require
@@ -0,0 +1,2 @@
+running_as_root
+NO
diff --git a/mysql-test/t/information_schema.test b/mysql-test/t/information_schema.test
index 47f262a9d59..90b0fd95eee 100644
--- a/mysql-test/t/information_schema.test
+++ b/mysql-test/t/information_schema.test
@@ -1,6 +1,9 @@
 # This test  uses grants, which can't get tested for embedded server
 -- source include/not_embedded.inc
 
+# This test uses chmod, can't be run with root permissions
+-- source include/not_as_root.inc
+
 # Test for information_schema.schemata &
 # show databases
 
diff --git a/mysql-test/t/rpl_rotate_logs.test b/mysql-test/t/rpl_rotate_logs.test
index 77a8fb7d9a4..ee49f92910a 100644
--- a/mysql-test/t/rpl_rotate_logs.test
+++ b/mysql-test/t/rpl_rotate_logs.test
@@ -1,3 +1,6 @@
+# This test uses chmod, can't be run with root permissions
+-- source include/not_as_root.inc
+
 #
 # Test is run with max_binlog_size=2048 to force automatic rotation of the
 # binary log

From 1f2ac2195a9a53af43b317fcca0d7c6a4336b0f3 Mon Sep 17 00:00:00 2001
From: "msvensson@neptunus.(none)" <>
Date: Mon, 24 Apr 2006 10:22:26 +0200
Subject: [PATCH 040/108] Remove 5 second sleep for win32

---
 mysql-test/lib/mtr_process.pl | 2 --
 1 file changed, 2 deletions(-)

diff --git a/mysql-test/lib/mtr_process.pl b/mysql-test/lib/mtr_process.pl
index 58652960e36..3ccf3d9bbba 100644
--- a/mysql-test/lib/mtr_process.pl
+++ b/mysql-test/lib/mtr_process.pl
@@ -736,8 +736,6 @@ sub mtr_mysqladmin_shutdown {
 
   $timeout or mtr_debug("At least one server is still listening to its port");
 
-  sleep(5) if $::glob_win32;            # FIXME next startup fails if no sleep
-
   return $res;
 }
 

From cb69ff25daa365e0d99835789d692383f1961f74 Mon Sep 17 00:00:00 2001
From: "msvensson@neptunus.(none)" <>
Date: Mon, 24 Apr 2006 10:27:13 +0200
Subject: [PATCH 041/108] Move copy_dir to mtr_misc and rename it to
 mtr_copy_dir

---
 mysql-test/lib/mtr_misc.pl   | 25 +++++++++++++++++--------
 mysql-test/mysql-test-run.pl | 24 ++----------------------
 2 files changed, 19 insertions(+), 30 deletions(-)

diff --git a/mysql-test/lib/mtr_misc.pl b/mysql-test/lib/mtr_misc.pl
index 5b2fd5c6df6..90617194897 100644
--- a/mysql-test/lib/mtr_misc.pl
+++ b/mysql-test/lib/mtr_misc.pl
@@ -111,18 +111,27 @@ sub mtr_exe_exists (@) {
   }
 }
 
+
 sub mtr_copy_dir($$) {
-  my $srcdir= shift;
-  my $dstdir= shift;
+  my $from_dir= shift;
+  my $to_dir= shift;
+
+  mkpath("$to_dir");
+  opendir(DIR, "$from_dir")
+    or mtr_error("Can't find $from_dir$!");
+  for(readdir(DIR)) {
+    next if "$_" eq "." or "$_" eq "..";
+    if ( -d "$from_dir/$_" )
+    {
+      mtr_copy_dir("$from_dir/$_", "$to_dir/$_");
+      next;
+    }
+    copy("$from_dir/$_", "$to_dir/$_");
+  }
+  closedir(DIR);
 
-  # Create destination directory
-  mkpath($dstdir);
-  find(\&mtr_copy_one_file, $dstdir);
 }
 
-sub mtr_copy_one_file {
-  print $File::Find::name, "\n";
-}
 
 sub mtr_same_opts ($$) {
   my $l1= shift;
diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl
index 9a801884855..637f31c713f 100755
--- a/mysql-test/mysql-test-run.pl
+++ b/mysql-test/mysql-test-run.pl
@@ -2125,26 +2125,6 @@ sub run_testcase ($) {
   }
 }
 
-sub copy_dir($$) {
-  my $from_dir= shift;
-  my $to_dir= shift;
-
-  mkpath("$to_dir");
-  opendir(DIR, "$from_dir")
-    or mtr_error("Can't find $from_dir$!");
-  for(readdir(DIR)) {
-    next if "$_" eq "." or "$_" eq "..";
-    if ( -d "$from_dir/$_" )
-    {
-      copy_dir("$from_dir/$_", "$to_dir/$_");
-      next;
-    }
-    copy("$from_dir/$_", "$to_dir/$_");
-  }
-  closedir(DIR);
-
-}
-
 #
 # Save a snapshot of the installed test db(s)
 # I.e take a snapshot of the var/ dir
@@ -2157,7 +2137,7 @@ sub save_installed_db () {
   foreach my $data_dir (@data_dir_lst)
   {
     my $name= basename($data_dir);
-    copy_dir("$data_dir", "$path_snapshot/$name");
+    mtr_copy_dir("$data_dir", "$path_snapshot/$name");
   }
 }
 
@@ -2199,7 +2179,7 @@ sub restore_installed_db ($) {
       my $name= basename($data_dir);
       save_files_before_restore($test_name, $data_dir);
       rmtree("$data_dir");
-      copy_dir("$path_snapshot/$name", "$data_dir");
+      mtr_copy_dir("$path_snapshot/$name", "$data_dir");
     }
     if ($opt_with_ndbcluster)
     {

From 7f1d1586be62177b2833d05ddae52141458000ca Mon Sep 17 00:00:00 2001
From: "msvensson@neptunus.(none)" <>
Date: Mon, 24 Apr 2006 10:33:24 +0200
Subject: [PATCH 042/108] Remove the old unused code for setting a PATH

---
 mysql-test/mysql-test-run.pl | 5 -----
 1 file changed, 5 deletions(-)

diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl
index 637f31c713f..4d84d0ff672 100755
--- a/mysql-test/mysql-test-run.pl
+++ b/mysql-test/mysql-test-run.pl
@@ -2922,11 +2922,6 @@ sub run_mysqltest ($) {
     "--port=$master->[0]->{'path_myport'} " .
     "--socket=$master->[0]->{'path_mysock'}";
 
-
-
-  # FIXME really needing a PATH???
-  # $ENV{'PATH'}= "/bin:/usr/bin:/usr/local/bin:/usr/bsd:/usr/X11R6/bin:/usr/openwin/bin:/usr/bin/X11:$ENV{'PATH'}";
-
   $ENV{'MYSQL'}=                    $cmdline_mysql;
   $ENV{'MYSQL_CHECK'}=              $cmdline_mysqlcheck;
   $ENV{'MYSQL_DUMP'}=               $cmdline_mysqldump;

From 7831bd00024ae7b3dfdad81705cd5bc6e04ceff3 Mon Sep 17 00:00:00 2001
From: "msvensson@neptunus.(none)" <>
Date: Mon, 24 Apr 2006 10:39:56 +0200
Subject: [PATCH 043/108] Cleanup formatting

---
 .bzrignore                   |  3 ++
 mysql-test/mysql-test-run.pl | 82 +++++++++++++++++++-----------------
 2 files changed, 47 insertions(+), 38 deletions(-)

diff --git a/.bzrignore b/.bzrignore
index 1bd9f91fccf..352629ab5c5 100644
--- a/.bzrignore
+++ b/.bzrignore
@@ -1278,3 +1278,6 @@ include/openssl
 mysql-test/r/bdb.log
 mysql-test/r/im_client_port.log
 mysql-test/r/udf.log
+extra/yassl/taocrypt/benchmark/benchmark
+extra/yassl/taocrypt/test/test
+extra/yassl/testsuite/testsuite
diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl
index 4d84d0ff672..4ab01c9f575 100755
--- a/mysql-test/mysql-test-run.pl
+++ b/mysql-test/mysql-test-run.pl
@@ -1223,6 +1223,7 @@ sub signal_setup () {
   $SIG{INT}= \&handle_int_signal;
 }
 
+
 sub handle_int_signal () {
   $SIG{INT}= 'DEFAULT';         # If we get a ^C again, we die...
   mtr_warning("got INT signal, cleaning up.....");
@@ -1438,7 +1439,6 @@ sub check_ndbcluster_support () {
   return;
 }
 
-# FIXME why is there a different start below?!
 
 sub ndbcluster_install () {
 
@@ -1465,6 +1465,7 @@ sub ndbcluster_install () {
   return 0;
 }
 
+
 sub ndbcluster_start ($) {
   my $use_ndbcluster= shift;
 
@@ -1497,6 +1498,7 @@ sub ndbcluster_start ($) {
   return 0;
 }
 
+
 sub ndbcluster_stop () {
   if ( ! $using_ndbcluster_master or $glob_use_running_ndbcluster )
   {
@@ -1594,6 +1596,7 @@ sub run_tests () {
   run_suite($opt_suite);
 }
 
+
 sub run_suite () {
   my $suite= shift;
 
@@ -1756,15 +1759,15 @@ sub im_create_passwd_file($) {
   my $instance_manager = shift;
 
   my $pwd_file_path = $instance_manager->{'password_file'};
-  
+
   mtr_report("Creating IM password file ($pwd_file_path)");
-  
+
   open(OUT, ">", $pwd_file_path)
     or mtr_error("Can't write to $pwd_file_path: $!");
-  
+
   print OUT $instance_manager->{'admin_login'}, ":",
         $instance_manager->{'admin_sha1'}, "\n";
-  
+
   close(OUT);
 }
 
@@ -1776,7 +1779,7 @@ sub im_create_defaults_file($) {
 
   open(OUT, ">", $defaults_file)
     or mtr_error("Can't write to $defaults_file: $!");
-  
+
   print OUT <[0]->{'path_myerr'},"CURRENT_TEST: $tname\n");
 
-# FIXME test cases that depend on each other, prevent this from
-# being at this location.
-#  do_before_start_master($tname,$tinfo->{'master_sh'});
+  # FIXME test cases that depend on each other, prevent this from
+  # being at this location.
+  # do_before_start_master($tname,$tinfo->{'master_sh'});
 
   # ----------------------------------------------------------------------
   # If any mysqld servers running died, we have to know
@@ -2125,6 +2128,7 @@ sub run_testcase ($) {
   }
 }
 
+
 #
 # Save a snapshot of the installed test db(s)
 # I.e take a snapshot of the var/ dir
@@ -2161,6 +2165,7 @@ sub save_files_before_restore($$) {
   }
 }
 
+
 #
 # Restore snapshot of the installed test db(s)
 # if the snapshot exists
@@ -2230,9 +2235,9 @@ sub report_failure_and_restart ($) {
 #
 ##############################################################################
 
+
 # The embedded server needs the cleanup so we do some of the start work
 # but stop before actually running mysqld or anything.
-
 sub do_before_start_master ($$) {
   my $tname=       shift;
   my $init_script= shift;
@@ -2265,13 +2270,14 @@ sub do_before_start_master ($$) {
     if ( $ret != 0 )
     {
       # FIXME rewrite those scripts to return 0 if successful
-#      mtr_warning("$init_script exited with code $ret");
+      # mtr_warning("$init_script exited with code $ret");
     }
   }
   # for gcov  FIXME needed? If so we need more absolute paths
-# chdir($glob_basedir);
+  # chdir($glob_basedir);
 }
 
+
 sub do_before_start_slave ($$) {
   my $tname=       shift;
   my $init_script= shift;
@@ -2299,7 +2305,7 @@ sub do_before_start_slave ($$) {
     if ( $ret != 0 )
     {
       # FIXME rewrite those scripts to return 0 if successful
-#      mtr_warning("$init_script exited with code $ret");
+      # mtr_warning("$init_script exited with code $ret");
     }
   }
 
@@ -2309,6 +2315,7 @@ sub do_before_start_slave ($$) {
   }
 }
 
+
 sub mysqld_arguments ($$$$$$) {
   my $args=              shift;
   my $type=              shift;        # master/slave/bootstrap
@@ -2532,14 +2539,6 @@ sub mysqld_arguments ($$$$$$) {
   return $args;
 }
 
-# FIXME
-#  if ( $type eq 'master' and $glob_use_embedded_server )
-#  {
-#    # Add a -A to each argument to pass it to embedded server
-#    my @mysqltest_opt=  map {("-A",$_)} @args;
-#    $opt_extra_mysqltest_opt=  \@mysqltest_opt;
-#    return;
-#  }
 
 ##############################################################################
 #
@@ -2639,6 +2638,7 @@ sub mysqld_start ($$$$$) {
   return 0;
 }
 
+
 sub stop_masters_slaves () {
 
   print  "Ending Tests\n";
@@ -2648,7 +2648,7 @@ sub stop_masters_slaves () {
     print  "Shutting-down Instance Manager\n";
     im_stop($instance_manager);
   }
-  
+
   print  "Shutting-down MySQL daemon\n\n";
   stop_masters();
   print "Master(s) shutdown finished\n";
@@ -2656,6 +2656,7 @@ sub stop_masters_slaves () {
   print "Slave(s) shutdown finished\n";
 }
 
+
 sub stop_masters () {
 
   my @args;
@@ -2685,6 +2686,7 @@ sub stop_masters () {
   mtr_stop_mysqld_servers(\@args);
 }
 
+
 sub stop_slaves () {
   my $force= shift;
 
@@ -2727,7 +2729,7 @@ sub im_start($$) {
     mtr_add_arg($args, $opt);
   }
 
-  $instance_manager->{'pid'} = 
+  $instance_manager->{'pid'} =
     mtr_spawn(
       $exe_im,                          # path to the executable
       $args,                            # cmd-line args
@@ -2743,7 +2745,7 @@ sub im_start($$) {
     mtr_report('Could not start Instance Manager');
     return;
   }
-  
+
   # Instance Manager can be run in daemon mode. In this case, it creates
   # several processes and the parent process, created by mtr_spawn(), exits just
   # after start. So, we have to obtain Instance Manager PID from the PID file.
@@ -2761,6 +2763,7 @@ sub im_start($$) {
     mtr_get_pid_from_file($instance_manager->{'path_pid'});
 }
 
+
 sub im_stop($) {
   my $instance_manager = shift;
 
@@ -2795,12 +2798,13 @@ sub im_stop($) {
   # Kill processes.
 
   mtr_kill_processes(\@pids);
-  
+
   stop_reap_all();
 
   $instance_manager->{'pid'} = undef;
 }
 
+
 #
 # Run include/check-testcase.test
 # Before a testcase, run in record mode, save result file to var
@@ -2849,6 +2853,7 @@ sub run_check_testcase ($) {
   }
 }
 
+
 sub run_mysqltest ($) {
   my $tinfo=       shift;
 
@@ -3185,6 +3190,7 @@ sub gdb_arguments {
   $$exe= "xterm";
 }
 
+
 #
 # Modify the exe and args so that program is run in ddd
 #
@@ -3430,18 +3436,18 @@ Deprecated options
 
 Options not yet described, or that I want to look into more
 
-  big-test              
-  debug                 
-  local                 
-  local-master          
-  netware               
-  old-master            
-  sleep=SECONDS         
-  socket=PATH           
-  user-test=s           
-  wait-timeout=SECONDS  
-  warnings              
-  log-warnings          
+  big-test
+  debug
+  local
+  local-master
+  netware
+  old-master
+  sleep=SECONDS
+  socket=PATH
+  user-test=s
+  wait-timeout=SECONDS
+  warnings
+  log-warnings
 
 HERE
   mtr_exit(1);

From 7e3593def8726bcdf4f9c613e29b83b12feec447 Mon Sep 17 00:00:00 2001
From: "msvensson@neptunus.(none)" <>
Date: Mon, 24 Apr 2006 11:26:41 +0200
Subject: [PATCH 044/108] Bug#19084  	./mysql-test-run.pl do not print
 bootstrap run info  - Log boostratp/install to var/log/boostrap.log  - Log
 output from mysqladmin to var/log/mysqladmin.log  - Remove old manager
 references

---
 mysql-test/lib/mtr_process.pl |  9 +++++----
 mysql-test/mysql-test-run.pl  | 25 +++++++++++--------------
 2 files changed, 16 insertions(+), 18 deletions(-)

diff --git a/mysql-test/lib/mtr_process.pl b/mysql-test/lib/mtr_process.pl
index 3ccf3d9bbba..c41978127b3 100644
--- a/mysql-test/lib/mtr_process.pl
+++ b/mysql-test/lib/mtr_process.pl
@@ -663,8 +663,6 @@ sub mtr_mysqladmin_shutdown {
 
   foreach my $srv ( @to_kill_specs )
   {
-    # FIXME wrong log.....
-    # FIXME, stderr.....
     # Shutdown time must be high as slave may be in reconnect
     my $args;
 
@@ -688,11 +686,14 @@ sub mtr_mysqladmin_shutdown {
     mtr_add_arg($args, "--connect_timeout=5");
     mtr_add_arg($args, "--shutdown_timeout=$adm_shutdown_tmo");
     mtr_add_arg($args, "shutdown");
-    # We don't wait for termination of mysqladmin
+
+    my $path_mysqladmin_log= "$::opt_vardir/log/mysqladmin.log";
     my $pid= mtr_spawn($::exe_mysqladmin, $args,
-                       "", $::path_manager_log, $::path_manager_log, "",
+                       "", $path_mysqladmin_log, $path_mysqladmin_log, "",
                        { append_log_file => 1 });
     $mysql_admin_pids{$pid}= 1;
+
+    # We don't wait for termination of mysqladmin
   }
 
   # As mysqladmin is such a simple program, we trust it to terminate.
diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl
index 4ab01c9f575..947ca2ed9c1 100755
--- a/mysql-test/mysql-test-run.pl
+++ b/mysql-test/mysql-test-run.pl
@@ -156,9 +156,9 @@ our $path_client_bindir;
 our $path_language;
 our $path_timefile;
 our $path_snapshot;
-our $path_manager_log;           # Used by mysqldadmin
 our $path_slave_load_tmpdir;     # What is this?!
 our $path_mysqltest_log;
+our $path_current_test_log;
 our $path_my_basedir;
 our $opt_vardir;                 # A path but set directly on cmd line
 our $opt_vardir_trace;           # unix formatted opt_vardir for trace files
@@ -205,7 +205,6 @@ our $opt_sp_protocol;
 our $opt_cursor_protocol;
 our $opt_view_protocol;
 
-our $opt_current_test;
 our $opt_debug;
 our $opt_do_test;
 our @opt_cases;                  # The test cases names in argv
@@ -246,9 +245,6 @@ our $instance_manager;
 our $opt_ndbcluster_port;
 our $opt_ndbconnectstring;
 
-our $opt_no_manager;            # Does nothing now, we never use manager
-our $opt_manager_port;          # Does nothing now, we never use manager
-
 our $opt_old_master;
 
 our $opt_record;
@@ -571,7 +567,6 @@ sub command_line_setup () {
              'compress'                 => \$opt_compress,
              'bench'                    => \$opt_bench,
              'small-bench'              => \$opt_small_bench,
-             'no-manager'               => \$opt_no_manager, # Currently not used
 
              # Control what test suites or cases to run
              'force'                    => \$opt_force,
@@ -588,7 +583,6 @@ sub command_line_setup () {
              'master_port=i'            => \$opt_master_myport,
              'slave_port=i'             => \$opt_slave_myport,
              'ndbcluster_port=i'        => \$opt_ndbcluster_port,
-             'manager-port=i'           => \$opt_manager_port, # Currently not used
              'im-port=i'                => \$im_port, # Instance Manager port.
              'im-mysqld1-port=i'        => \$im_mysqld1_port, # Port of mysqld, controlled by IM
              'im-mysqld2-port=i'        => \$im_mysqld2_port, # Port of mysqld, controlled by IM
@@ -730,11 +724,6 @@ sub command_line_setup () {
 
   $opt_tmpdir=       "$opt_vardir/tmp" unless $opt_tmpdir;
   $opt_tmpdir =~ s,/+$,,;       # Remove ending slash if any
-  # FIXME maybe not needed?
-  $path_manager_log= "$opt_vardir/log/manager.log"
-    unless $path_manager_log;
-  $opt_current_test= "$opt_vardir/log/current_test"
-    unless $opt_current_test;
 
   # --------------------------------------------------------------------------
   # Do sanity checks of command line arguments
@@ -983,6 +972,7 @@ sub command_line_setup () {
 
   $path_timefile=  "$opt_vardir/log/mysqltest-time";
   $path_mysqltest_log=  "$opt_vardir/log/mysqltest.log";
+  $path_current_test_log= "$opt_vardir/log/current_test";
 
   $path_snapshot= "$opt_tmpdir/snapshot_$opt_master_myport/";
 
@@ -1736,8 +1726,15 @@ sub install_db ($$) {
     mtr_add_arg($args, "--character-sets-dir=%s", $path_charsetsdir);
   }
 
+  # Log bootstrap command
+  my $path_bootstrap_log= "$opt_vardir/log/bootstrap.log";
+  mtr_tofile($path_bootstrap_log,
+	     "$exe_mysqld " . join(" ", @$args) . "\n");
+
   if ( mtr_run($exe_mysqld, $args, $init_db_sql_tmp,
-               $path_manager_log, $path_manager_log, "") != 0 )
+               $path_bootstrap_log, $path_bootstrap_log,
+	       "", { append_log_file => 1 }) != 0 )
+
   {
     unlink($init_db_sql_tmp);
     mtr_error("Error executing mysqld --bootstrap\n" .
@@ -1858,7 +1855,7 @@ sub run_testcase ($) {
 
   my $tname= $tinfo->{'name'};
 
-  mtr_tonewfile($opt_current_test,"$tname\n"); # Always tell where we are
+  mtr_tonewfile($path_current_test_log,"$tname\n"); # Always tell where we are
 
   # output current test to ndbcluster log file to enable diagnostics
   mtr_tofile($file_ndb_testrun_log,"CURRENT TEST $tname\n");

From d1536ba0c9fc165faf4ee3ec3ab43310183fe834 Mon Sep 17 00:00:00 2001
From: "msvensson@neptunus.(none)" <>
Date: Mon, 24 Apr 2006 12:00:11 +0200
Subject: [PATCH 045/108] Make have_ndb.in portable

---
 mysql-test/include/have_ndb.inc | 9 ++++++++-
 mysql-test/mysql-test-run.pl    | 5 +++--
 2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/mysql-test/include/have_ndb.inc b/mysql-test/include/have_ndb.inc
index 28fcf18cb16..721d79392b7 100644
--- a/mysql-test/include/have_ndb.inc
+++ b/mysql-test/include/have_ndb.inc
@@ -1,6 +1,13 @@
---exec test x$NDB_STATUS_OK = x1
+# Check that server is compiled and started with support for NDB
 -- require r/have_ndb.require
 disable_query_log;
 show variables like "have_ndbcluster";
 enable_query_log;
 
+# Check that NDB is installed and known to be working
+-- require r/have_ndb_status_ok.require
+disable_query_log;
+eval select "$NDB_STATUS_OK" as ndb_status_ok;
+enable_query_log;
+
+
diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl
index 947ca2ed9c1..c5107bcd679 100755
--- a/mysql-test/mysql-test-run.pl
+++ b/mysql-test/mysql-test-run.pl
@@ -1175,6 +1175,7 @@ sub environment_setup () {
   $ENV{'MYSQL_TCP_PORT'}=     3306;
 
   $ENV{'NDBCLUSTER_PORT'}=    $opt_ndbcluster_port;
+  $ENV{'NDB_STATUS_OK'}=      "YES";
 
   $ENV{'IM_PATH_PID'}=        $instance_manager->{path_pid};
   $ENV{'IM_PORT'}=            $instance_manager->{port};
@@ -1661,6 +1662,7 @@ sub mysql_install_db () {
       mtr_report("ndbcluster_install failed, continuing without cluster");
       $opt_with_ndbcluster= 0;
       $flag_ndb_status_ok= 0;
+      $ENV{'NDB_STATUS_OK'}= "NO";
     }
     else
     {
@@ -1682,7 +1684,7 @@ sub install_db ($$) {
   my $init_db_sql_tmp= "/tmp/init_db.sql$$";
   my $args;
 
-  mtr_report("Installing \u$type Databases");
+  mtr_report("Installing \u$type Database");
 
   open(IN, $init_db_sql)
     or mtr_error("Can't open $init_db_sql: $!");
@@ -2935,7 +2937,6 @@ sub run_mysqltest ($) {
   $ENV{'CHARSETSDIR'}=              $path_charsetsdir;
   $ENV{'MYSQL_MY_PRINT_DEFAULTS'}=  $exe_my_print_defaults;
 
-  $ENV{'NDB_STATUS_OK'}=            $flag_ndb_status_ok;
   $ENV{'NDB_MGM'}=                  $exe_ndb_mgm;
   $ENV{'NDB_BACKUP_DIR'}=           $path_ndb_data_dir;
   $ENV{'NDB_DATA_DIR'}=             $path_ndb_data_dir;

From b30df055afe0e2e765a160c9e31f41fe8909a035 Mon Sep 17 00:00:00 2001
From: "msvensson@neptunus.(none)" <>
Date: Mon, 24 Apr 2006 12:01:16 +0200
Subject: [PATCH 046/108] Use "eval select" when evaluating the environment
 variable "$MYSQL_TEST_ROOT"

---
 mysql-test/include/not_as_root.inc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mysql-test/include/not_as_root.inc b/mysql-test/include/not_as_root.inc
index 315963d824e..e0277ea593e 100644
--- a/mysql-test/include/not_as_root.inc
+++ b/mysql-test/include/not_as_root.inc
@@ -1,4 +1,4 @@
 -- require r/not_as_root.require
 disable_query_log;
-select $MYSQL_TEST_ROOT as running_as_root;
+eval select "$MYSQL_TEST_ROOT" as running_as_root;
 enable_query_log;

From 9e49e393a4e90dada25916dc65bfbc206f265110 Mon Sep 17 00:00:00 2001
From: "msvensson@neptunus.(none)" <>
Date: Mon, 24 Apr 2006 13:25:50 +0200
Subject: [PATCH 047/108] Ad file "have_ndb_status_ok.require"

---
 mysql-test/r/have_ndb_status_ok.require | 2 ++
 1 file changed, 2 insertions(+)
 create mode 100644 mysql-test/r/have_ndb_status_ok.require

diff --git a/mysql-test/r/have_ndb_status_ok.require b/mysql-test/r/have_ndb_status_ok.require
new file mode 100644
index 00000000000..8a82871234b
--- /dev/null
+++ b/mysql-test/r/have_ndb_status_ok.require
@@ -0,0 +1,2 @@
+ndb_status_ok
+YES

From fd52c34124f34b9a8b453656e2e18b81cd68f614 Mon Sep 17 00:00:00 2001
From: "msvensson@neptunus.(none)" <>
Date: Mon, 24 Apr 2006 13:33:33 +0200
Subject: [PATCH 048/108] Update help message for start-and-exit

---
 mysql-test/mysql-test-run.pl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl
index c5107bcd679..e4bfc73dbdd 100755
--- a/mysql-test/mysql-test-run.pl
+++ b/mysql-test/mysql-test-run.pl
@@ -3417,7 +3417,7 @@ Misc options
   comment=STR           Write STR to the output
   script-debug          Debug this script itself
   timer                 Show test case execution time
-  start-and-exit        Only initiate and start the "mysqld" servers, use the startup
+  start-and-exit        Only initiate and start all servers, use the startup
                         settings for the specified test case if any
   start-dirty           Only start the "mysqld" servers without initiation
   fast                  Don't try to cleanup from earlier runs

From c2efcc4adf69f1b9dd7910cbc59b358db91f6d97 Mon Sep 17 00:00:00 2001
From: "msvensson@neptunus.(none)" <>
Date: Mon, 24 Apr 2006 13:51:21 +0200
Subject: [PATCH 049/108] Test it it works better to set no read access for a
 file by using 000 instead of -r Looks like the trigger.test works that way

---
 mysql-test/t/information_schema.test | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/mysql-test/t/information_schema.test b/mysql-test/t/information_schema.test
index 90b0fd95eee..770722f7707 100644
--- a/mysql-test/t/information_schema.test
+++ b/mysql-test/t/information_schema.test
@@ -798,9 +798,9 @@ DROP FUNCTION func2;
 #
 create database mysqltest;
 create table mysqltest.t1(a int);
---exec chmod -r $MYSQLTEST_VARDIR/master-data/mysqltest
+--exec chmod 000 $MYSQLTEST_VARDIR/master-data/mysqltest
 select table_schema from information_schema.tables where table_schema='mysqltest';
---exec chmod +r $MYSQLTEST_VARDIR/master-data/mysqltest
+--exec chmod 600 $MYSQLTEST_VARDIR/master-data/mysqltest
 drop database mysqltest;
 
 #

From 92cd4762affe27ec9c808d14a98a9885b21d5d46 Mon Sep 17 00:00:00 2001
From: "msvensson@neptunus.(none)" <>
Date: Mon, 24 Apr 2006 14:25:34 +0200
Subject: [PATCH 050/108] Update disabled message to include bug no.

---
 mysql-test/t/disabled.def | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mysql-test/t/disabled.def b/mysql-test/t/disabled.def
index fb1fee24c43..dee6146017d 100644
--- a/mysql-test/t/disabled.def
+++ b/mysql-test/t/disabled.def
@@ -12,4 +12,4 @@
 
 sp-goto         : GOTO is currently is disabled - will be fixed in the future
 ndb_load        : Bug#17233
-udf             : Disabled by Magnus 
+udf             : Bug#18564

From 2033f7ba45503ed5a9e26160e4d8abe5361dc7ce Mon Sep 17 00:00:00 2001
From: "dlenev@mysql.com" <>
Date: Mon, 24 Apr 2006 18:57:00 +0400
Subject: [PATCH 051/108] Fix for bug#11081 "Using a CONVERT_TZ function in a
 stored function or trigger fails".

In cases when CONVERT_TZ() function was used in trigger or stored function
(or in stored procedure which was called from trigger or stored function)
error about non existing '.' table was reported.

Statements that use CONVERT_TZ() function should have time zone related
tables in their table list. tz_init_table_list() function which is used
to produce part of table list containing those tables didn't set
TABLE_LIST::db_length/table_name_length members properly. As result time
zone tables needed for CONVERT_TZ() function were incorrectly handled by
prelocking algorithm and "Table '.' doesn't exist' error was emitted.
This fix changes tz_init_table_list() in such way that it properly inits
TABLE_LIST::table_name_length/db_length members and thus produces table list
which can be handled by prelocking algorithm correctly.
---
 mysql-test/r/timezone2.result | 15 +++++++
 mysql-test/t/timezone2.test   | 20 +++++++++
 sql/tztime.cc                 | 82 ++++++++++++++++++++++-------------
 sql/tztime.h                  | 13 +++++-
 4 files changed, 98 insertions(+), 32 deletions(-)

diff --git a/mysql-test/r/timezone2.result b/mysql-test/r/timezone2.result
index df51a6aac9b..a1ae2f63212 100644
--- a/mysql-test/r/timezone2.result
+++ b/mysql-test/r/timezone2.result
@@ -1,4 +1,5 @@
 drop table if exists t1, t2;
+drop function if exists f1;
 create table t1 (ts timestamp);
 set time_zone='+00:00';
 select unix_timestamp(utc_timestamp())-unix_timestamp(current_timestamp());
@@ -268,3 +269,17 @@ select * from t1;
 convert_tz(NULL, NULL, NULL)
 NULL
 drop table t1;
+create table t1 (ldt datetime, udt datetime);
+create function f1(i datetime) returns datetime
+return convert_tz(i, 'UTC', 'Europe/Moscow');
+create trigger t1_bi before insert on t1 for each row
+set new.udt:= convert_tz(new.ldt, 'Europe/Moscow', 'UTC');
+insert into t1 (ldt) values ('2006-04-19 16:30:00');
+select * from t1;
+ldt	udt
+2006-04-19 16:30:00	2006-04-19 12:30:00
+select ldt, f1(udt) as ldt2 from t1;
+ldt	ldt2
+2006-04-19 16:30:00	2006-04-19 16:30:00
+drop table t1;
+drop function f1;
diff --git a/mysql-test/t/timezone2.test b/mysql-test/t/timezone2.test
index 069c19341e4..bfc909d6995 100644
--- a/mysql-test/t/timezone2.test
+++ b/mysql-test/t/timezone2.test
@@ -3,6 +3,7 @@
 # Preparing playground
 --disable_warnings
 drop table if exists t1, t2;
+drop function if exists f1;
 --enable_warnings
 
 
@@ -222,3 +223,22 @@ select * from t1;
 drop table t1;
 
 # End of 4.1 tests
+
+#
+# Test for bug #11081 "Using a CONVERT_TZ function in a stored function
+# or trigger fails".
+#
+create table t1 (ldt datetime, udt datetime);
+create function f1(i datetime) returns datetime
+  return convert_tz(i, 'UTC', 'Europe/Moscow');
+create trigger t1_bi before insert on t1 for each row
+  set new.udt:= convert_tz(new.ldt, 'Europe/Moscow', 'UTC');
+# This should work without errors
+insert into t1 (ldt) values ('2006-04-19 16:30:00');
+select * from t1;
+# This should work without errors as well
+select ldt, f1(udt) as ldt2 from t1;
+drop table t1;
+drop function f1;
+
+# End of 5.0 tests
diff --git a/sql/tztime.cc b/sql/tztime.cc
index b86c9a44561..079abfc9299 100644
--- a/sql/tztime.cc
+++ b/sql/tztime.cc
@@ -1370,11 +1370,30 @@ static LS_INFO *tz_lsis= 0;
 static bool time_zone_tables_exist= 1;
 
 
-typedef struct st_tz_names_entry: public Sql_alloc
+/*
+  Names of tables (with their lengths) that are needed
+  for dynamical loading of time zone descriptions.
+*/
+
+static const LEX_STRING tz_tables_names[MY_TZ_TABLES_COUNT]=
 {
+  {(char *) STRING_WITH_LEN("time_zone_name")},
+  {(char *) STRING_WITH_LEN("time_zone")},
+  {(char *) STRING_WITH_LEN("time_zone_transition_type")},
+  {(char *) STRING_WITH_LEN("time_zone_transition")}
+};
+
+/* Name of database to which those tables belong. */
+
+static const LEX_STRING tz_tables_db_name= {(char *) STRING_WITH_LEN("mysql")};
+
+
+class Tz_names_entry: public Sql_alloc
+{
+public:
   String name;
   Time_zone *tz;
-} TZ_NAMES_ENTRY;
+};
 
 
 /*
@@ -1382,7 +1401,7 @@ typedef struct st_tz_names_entry: public Sql_alloc
   they should obey C calling conventions.
 */
 
-extern "C" byte* my_tz_names_get_key(TZ_NAMES_ENTRY *entry, uint *length,
+extern "C" byte* my_tz_names_get_key(Tz_names_entry *entry, uint *length,
                               my_bool not_used __attribute__((unused)))
 {
   *length= entry->name.length();
@@ -1403,7 +1422,8 @@ extern "C" byte* my_offset_tzs_get_key(Time_zone_offset *entry, uint *length,
 
   SYNOPSIS
     tz_init_table_list()
-      tz_tabs         - pointer to preallocated array of 4 TABLE_LIST objects
+      tz_tabs         - pointer to preallocated array of MY_TZ_TABLES_COUNT
+                        TABLE_LIST objects
       global_next_ptr - pointer to variable which points to global_next member
                         of last element of global table list (or list root
                         then list is empty) (in/out).
@@ -1418,27 +1438,27 @@ extern "C" byte* my_offset_tzs_get_key(Time_zone_offset *entry, uint *length,
 static void
 tz_init_table_list(TABLE_LIST *tz_tabs, TABLE_LIST ***global_next_ptr)
 {
-  bzero(tz_tabs, sizeof(TABLE_LIST) * 4);
-  tz_tabs[0].alias= tz_tabs[0].table_name= (char*)"time_zone_name";
-  tz_tabs[1].alias= tz_tabs[1].table_name= (char*)"time_zone";
-  tz_tabs[2].alias= tz_tabs[2].table_name= (char*)"time_zone_transition_type";
-  tz_tabs[3].alias= tz_tabs[3].table_name= (char*)"time_zone_transition";
-  tz_tabs[0].next_global= tz_tabs[0].next_local= tz_tabs+1;
-  tz_tabs[1].next_global= tz_tabs[1].next_local= tz_tabs+2;
-  tz_tabs[2].next_global= tz_tabs[2].next_local= tz_tabs+3;
-  tz_tabs[0].lock_type= tz_tabs[1].lock_type= tz_tabs[2].lock_type=
-    tz_tabs[3].lock_type= TL_READ;
-  tz_tabs[0].db= tz_tabs[1].db= tz_tabs[2].db= tz_tabs[3].db= (char *)"mysql";
+  bzero(tz_tabs, sizeof(TABLE_LIST) * MY_TZ_TABLES_COUNT);
+
+  for (int i= 0; i < MY_TZ_TABLES_COUNT; i++)
+  {
+    tz_tabs[i].alias= tz_tabs[i].table_name= tz_tables_names[i].str;
+    tz_tabs[i].table_name_length= tz_tables_names[i].length;
+    tz_tabs[i].db= tz_tables_db_name.str;
+    tz_tabs[i].db_length= tz_tables_db_name.length;
+    tz_tabs[i].lock_type= TL_READ;
+
+    if (i != MY_TZ_TABLES_COUNT - 1)
+      tz_tabs[i].next_global= tz_tabs[i].next_local= &tz_tabs[i+1];
+    if (i != 0)
+      tz_tabs[i].prev_global= &tz_tabs[i-1].next_global;
+  }
 
   /* Link into global list */
   tz_tabs[0].prev_global= *global_next_ptr;
-  tz_tabs[1].prev_global= &tz_tabs[0].next_global;
-  tz_tabs[2].prev_global= &tz_tabs[1].next_global;
-  tz_tabs[3].prev_global= &tz_tabs[2].next_global;
-
   **global_next_ptr= tz_tabs;
   /* Update last-global-pointer to point to pointer in last table */
-  *global_next_ptr= &tz_tabs[3].next_global;
+  *global_next_ptr= &tz_tabs[MY_TZ_TABLES_COUNT-1].next_global;
 }
 
 
@@ -1467,7 +1487,8 @@ TABLE_LIST fake_time_zone_tables_list;
 
   NOTE
     my_tz_check_n_skip_implicit_tables() function depends on fact that
-    elements of list created are allocated as TABLE_LIST[4] array.
+    elements of list created are allocated as TABLE_LIST[MY_TZ_TABLES_COUNT]
+    array.
 
   RETURN VALUES
     Returns pointer to first TABLE_LIST object, (could be 0 if time zone
@@ -1483,7 +1504,8 @@ my_tz_get_table_list(THD *thd, TABLE_LIST ***global_next_ptr)
   if (!time_zone_tables_exist)
     DBUG_RETURN(0);
 
-  if (!(tz_tabs= (TABLE_LIST *)thd->alloc(sizeof(TABLE_LIST) * 4)))
+  if (!(tz_tabs= (TABLE_LIST *)thd->alloc(sizeof(TABLE_LIST) *
+                                          MY_TZ_TABLES_COUNT)))
     DBUG_RETURN(&fake_time_zone_tables_list);
 
   tz_init_table_list(tz_tabs, global_next_ptr);
@@ -1522,9 +1544,9 @@ my_tz_init(THD *org_thd, const char *default_tzname, my_bool bootstrap)
 {
   THD *thd;
   TABLE_LIST *tables= 0;
-  TABLE_LIST tables_buff[5], **last_global_next_ptr;
+  TABLE_LIST tables_buff[1+MY_TZ_TABLES_COUNT], **last_global_next_ptr;
   TABLE *table;
-  TZ_NAMES_ENTRY *tmp_tzname;
+  Tz_names_entry *tmp_tzname;
   my_bool return_val= 1;
   int res;
   DBUG_ENTER("my_tz_init");
@@ -1556,7 +1578,7 @@ my_tz_init(THD *org_thd, const char *default_tzname, my_bool bootstrap)
   tz_inited= 1;
 
   /* Add 'SYSTEM' time zone to tz_names hash */
-  if (!(tmp_tzname= new (&tz_storage) TZ_NAMES_ENTRY()))
+  if (!(tmp_tzname= new (&tz_storage) Tz_names_entry()))
   {
     sql_print_error("Fatal error: OOM while initializing time zones");
     goto end_with_cleanup;
@@ -1752,7 +1774,7 @@ tz_load_from_open_tables(const String *tz_name, TABLE_LIST *tz_tables)
 {
   TABLE *table= 0;
   TIME_ZONE_INFO *tz_info;
-  TZ_NAMES_ENTRY *tmp_tzname;
+  Tz_names_entry *tmp_tzname;
   Time_zone *return_val= 0;
   int res;
   uint tzid, ttid;
@@ -2027,7 +2049,7 @@ tz_load_from_open_tables(const String *tz_name, TABLE_LIST *tz_tables)
   }
 
 
-  if (!(tmp_tzname= new (&tz_storage) TZ_NAMES_ENTRY()) ||
+  if (!(tmp_tzname= new (&tz_storage) Tz_names_entry()) ||
       !(tmp_tzname->tz= new (&tz_storage) Time_zone_db(tz_info,
                                             &(tmp_tzname->name))) ||
       (tmp_tzname->name.set(tz_name_buff, tz_name->length(),
@@ -2174,7 +2196,7 @@ str_to_offset(const char *str, uint length, long *offset)
 Time_zone *
 my_tz_find(const String * name, TABLE_LIST *tz_tables)
 {
-  TZ_NAMES_ENTRY *tmp_tzname;
+  Tz_names_entry *tmp_tzname;
   Time_zone *result_tz= 0;
   long offset;
 
@@ -2210,7 +2232,7 @@ my_tz_find(const String * name, TABLE_LIST *tz_tables)
   else
   {
     result_tz= 0;
-    if ((tmp_tzname= (TZ_NAMES_ENTRY *)hash_search(&tz_names,
+    if ((tmp_tzname= (Tz_names_entry *)hash_search(&tz_names,
                                                    (const byte *)name->ptr(),
                                                    name->length())))
       result_tz= tmp_tzname->tz;
@@ -2262,7 +2284,7 @@ Time_zone *my_tz_find_with_opening_tz_tables(THD *thd, const String *name)
       our time zone tables. Note that if we don't have tz tables on this
       slave, we don't even try.
     */
-    TABLE_LIST tables[4];
+    TABLE_LIST tables[MY_TZ_TABLES_COUNT];
     TABLE_LIST *dummy;
     TABLE_LIST **dummyp= &dummy;
     tz_init_table_list(tables, &dummyp);
diff --git a/sql/tztime.h b/sql/tztime.h
index 23460a8e739..c49b9fe4592 100644
--- a/sql/tztime.h
+++ b/sql/tztime.h
@@ -68,6 +68,15 @@ extern void        my_tz_free();
 
 extern TABLE_LIST fake_time_zone_tables_list;
 
+/*
+  Number of elements in table list produced by my_tz_get_table_list()
+  (this table list contains tables which are needed for dynamical loading
+  of time zone descriptions). Actually it is imlementation detail that
+  should not be used anywhere outside of tztime.h and tztime.cc.
+*/
+
+static const int MY_TZ_TABLES_COUNT= 4;
+
 /*
   Check if we have pointer to the begining of list of implicitly used time
   zone tables, set SELECT_ACL for them and fast-forward to its end.
@@ -90,9 +99,9 @@ inline bool my_tz_check_n_skip_implicit_tables(TABLE_LIST **table,
 {
   if (*table == tz_tables)
   {
-    for (int i= 0; i < 4; i++)
+    for (int i= 0; i < MY_TZ_TABLES_COUNT; i++)
       (*table)[i].grant.privilege= SELECT_ACL;
-    (*table)+= 3;
+    (*table)+= MY_TZ_TABLES_COUNT - 1;
     return TRUE;
   }
   return FALSE;

From 3c06a20bfe35bf8f2fed55c4159251a598f760a3 Mon Sep 17 00:00:00 2001
From: "evgen@moonbone.local" <>
Date: Mon, 24 Apr 2006 20:59:23 +0400
Subject: [PATCH 052/108] having.test:   After merge fix for bug#18739

---
 mysql-test/t/having.test | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mysql-test/t/having.test b/mysql-test/t/having.test
index 779b694987b..9bea78a7bca 100644
--- a/mysql-test/t/having.test
+++ b/mysql-test/t/having.test
@@ -401,7 +401,7 @@ create table t1(f1 int);
 select f1 from t1 having max(f1)=f1;
 select f1 from t1 group by f1 having max(f1)=f1;
 set session sql_mode='ONLY_FULL_GROUP_BY';
---error 1461
+--error 1463
 select f1 from t1 having max(f1)=f1;
 select f1 from t1 group by f1 having max(f1)=f1;
 set session sql_mode='';

From 95cac6792145cbe590174a558262e6082e5bb7e7 Mon Sep 17 00:00:00 2001
From: "msvensson@neptunus.(none)" <>
Date: Mon, 24 Apr 2006 21:42:44 +0200
Subject: [PATCH 053/108] Revert use of octal numbers for chmod

---
 mysql-test/t/information_schema.test | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/mysql-test/t/information_schema.test b/mysql-test/t/information_schema.test
index 770722f7707..90b0fd95eee 100644
--- a/mysql-test/t/information_schema.test
+++ b/mysql-test/t/information_schema.test
@@ -798,9 +798,9 @@ DROP FUNCTION func2;
 #
 create database mysqltest;
 create table mysqltest.t1(a int);
---exec chmod 000 $MYSQLTEST_VARDIR/master-data/mysqltest
+--exec chmod -r $MYSQLTEST_VARDIR/master-data/mysqltest
 select table_schema from information_schema.tables where table_schema='mysqltest';
---exec chmod 600 $MYSQLTEST_VARDIR/master-data/mysqltest
+--exec chmod +r $MYSQLTEST_VARDIR/master-data/mysqltest
 drop database mysqltest;
 
 #

From e2ac9dda830469aa32f646f32300af47b4094e9f Mon Sep 17 00:00:00 2001
From: "acurtis@xiphis.org" <>
Date: Mon, 24 Apr 2006 14:32:45 -0700
Subject: [PATCH 054/108] WL#3201   post-merge fixes

---
 config/ac-macros/plugins.m4 | 18 ++++++++++++++++++
 sql/sql_plugin.cc           |  2 +-
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/config/ac-macros/plugins.m4 b/config/ac-macros/plugins.m4
index 20d7e2cc11c..8ea5aca2595 100644
--- a/config/ac-macros/plugins.m4
+++ b/config/ac-macros/plugins.m4
@@ -238,6 +238,7 @@ AC_DEFUN([MYSQL_CONFIGURE_PLUGINS],[ dnl
     _MYSQL_CHECK_PLUGIN_ARGS([$1])
     _MYSQL_CONFIGURE_PLUGINS(m4_bpatsubst(__mysql_plugin_list__, :, [,]))
     _MYSQL_DO_PLUGIN_ACTIONS(m4_bpatsubst(__mysql_plugin_list__, :, [,]))
+    _MYSQL_POST_PLUGIN_FIXUP()
    ]) dnl
  ]) dnl
 ])
@@ -661,5 +662,22 @@ _MYSQL_MODULE_ARGS_CHECK(m4_bpatsubst(__mysql_plugin_list__, :, [,]))
   _MYSQL_CHECK_DEPENDENCIES(m4_bpatsubst(__mysql_plugin_list__, :, [,]))
 ])
 
+AC_DEFUN([_MYSQL_POST_PLUGIN_FIXUP],[
+  for plugdir in $mysql_plugin_dirs; do
+    case "$plugdir" in
+    storage/* )
+      mysql_se_dirs="$mysql_se_dirs `echo $plugdir | sed -e 's@^storage/@@'`"
+      ;;
+    plugin/* )
+      mysql_pg_dirs="$mysql_pg_dirs `echo $plugdir | sed -e 's@^plugin/@@'`"
+      ;;
+    *)
+      AC_MSG_ERROR([don't know how to handle plugin dir $plugdir])      
+      ;;    
+    esac
+  done
+  AC_SUBST(mysql_se_dirs)
+  AC_SUBST(mysql_pg_dirs)
+])
 
 dnl ===========================================================================
diff --git a/sql/sql_plugin.cc b/sql/sql_plugin.cc
index 249ce6c9823..01faae22c57 100644
--- a/sql/sql_plugin.cc
+++ b/sql/sql_plugin.cc
@@ -531,7 +531,7 @@ static int plugin_initialize(struct st_plugin_int *plugin)
   switch (plugin->plugin->type)
   {
   case MYSQL_STORAGE_ENGINE_PLUGIN:
-    if (ha_initialize_handlerton((handlerton*) plugin->plugin->info))
+    if (ha_initialize_handlerton(plugin))
     {
       sql_print_error("Plugin '%s' handlerton init returned error.",
                       plugin->name.str);

From f912a26b4a0c18cc4c0eb350989e59557292d2bd Mon Sep 17 00:00:00 2001
From: "konstantin@mysql.com" <>
Date: Tue, 25 Apr 2006 04:27:23 +0400
Subject: [PATCH 055/108] A fix and a test case for Bug#19308
 "REPAIR/OPTIMIZE/ANALYZE supported in SP but not in PS": just enable them in
 prepared statements, the supporting functionality was implemented when they
 were enabled in stored procedures.

---
 mysql-test/r/ps.result          | 101 ++++++++++++++++++++++++++++++++
 mysql-test/r/ps_1general.result |   3 -
 mysql-test/r/sp-dynamic.result  |   6 +-
 mysql-test/t/ps.test            |  36 ++++++++++++
 mysql-test/t/ps_1general.test   |   3 -
 sql/sql_prepare.cc              |   3 +
 6 files changed, 143 insertions(+), 9 deletions(-)

diff --git a/mysql-test/r/ps.result b/mysql-test/r/ps.result
index b29185eaaea..fccaa9b1b66 100644
--- a/mysql-test/r/ps.result
+++ b/mysql-test/r/ps.result
@@ -1056,3 +1056,104 @@ a	b
 1	9
 3	7
 drop table t1;
+create table t1 (a int);
+create table t2 like t1;
+create table t3 like t2;
+prepare stmt from "repair table t1";
+execute stmt;
+Table	Op	Msg_type	Msg_text
+test.t1	repair	status	OK
+execute stmt;
+Table	Op	Msg_type	Msg_text
+test.t1	repair	status	OK
+prepare stmt from "optimize table t1";
+execute stmt;
+Table	Op	Msg_type	Msg_text
+test.t1	optimize	status	OK
+execute stmt;
+Table	Op	Msg_type	Msg_text
+test.t1	optimize	status	Table is already up to date
+prepare stmt from "analyze table t1";
+execute stmt;
+Table	Op	Msg_type	Msg_text
+test.t1	analyze	status	Table is already up to date
+execute stmt;
+Table	Op	Msg_type	Msg_text
+test.t1	analyze	status	Table is already up to date
+prepare stmt from "repair table t1, t2, t3";
+execute stmt;
+Table	Op	Msg_type	Msg_text
+test.t1	repair	status	OK
+test.t2	repair	status	OK
+test.t3	repair	status	OK
+execute stmt;
+Table	Op	Msg_type	Msg_text
+test.t1	repair	status	OK
+test.t2	repair	status	OK
+test.t3	repair	status	OK
+prepare stmt from "optimize table t1, t2, t3";
+execute stmt;
+Table	Op	Msg_type	Msg_text
+test.t1	optimize	status	OK
+test.t2	optimize	status	OK
+test.t3	optimize	status	OK
+execute stmt;
+Table	Op	Msg_type	Msg_text
+test.t1	optimize	status	Table is already up to date
+test.t2	optimize	status	Table is already up to date
+test.t3	optimize	status	Table is already up to date
+prepare stmt from "analyze table t1, t2, t3";
+execute stmt;
+Table	Op	Msg_type	Msg_text
+test.t1	analyze	status	Table is already up to date
+test.t2	analyze	status	Table is already up to date
+test.t3	analyze	status	Table is already up to date
+execute stmt;
+Table	Op	Msg_type	Msg_text
+test.t1	analyze	status	Table is already up to date
+test.t2	analyze	status	Table is already up to date
+test.t3	analyze	status	Table is already up to date
+prepare stmt from "repair table t1, t4, t3";
+execute stmt;
+Table	Op	Msg_type	Msg_text
+test.t1	repair	status	OK
+test.t4	repair	error	Table 'test.t4' doesn't exist
+test.t3	repair	status	OK
+Warnings:
+Error	1146	Table 'test.t4' doesn't exist
+execute stmt;
+Table	Op	Msg_type	Msg_text
+test.t1	repair	status	OK
+test.t4	repair	error	Table 'test.t4' doesn't exist
+test.t3	repair	status	OK
+Warnings:
+Error	1146	Table 'test.t4' doesn't exist
+prepare stmt from "optimize table t1, t3, t4";
+execute stmt;
+Table	Op	Msg_type	Msg_text
+test.t1	optimize	status	OK
+test.t3	optimize	status	OK
+test.t4	optimize	error	Table 'test.t4' doesn't exist
+Warnings:
+Error	1146	Table 'test.t4' doesn't exist
+execute stmt;
+Table	Op	Msg_type	Msg_text
+test.t1	optimize	status	Table is already up to date
+test.t3	optimize	status	Table is already up to date
+test.t4	optimize	error	Table 'test.t4' doesn't exist
+Warnings:
+Error	1146	Table 'test.t4' doesn't exist
+prepare stmt from "analyze table t4, t1";
+execute stmt;
+Table	Op	Msg_type	Msg_text
+test.t4	analyze	error	Table 'test.t4' doesn't exist
+test.t1	analyze	status	Table is already up to date
+Warnings:
+Error	1146	Table 'test.t4' doesn't exist
+execute stmt;
+Table	Op	Msg_type	Msg_text
+test.t4	analyze	error	Table 'test.t4' doesn't exist
+test.t1	analyze	status	Table is already up to date
+Warnings:
+Error	1146	Table 'test.t4' doesn't exist
+deallocate prepare stmt;
diff --git a/mysql-test/r/ps_1general.result b/mysql-test/r/ps_1general.result
index 8e22c5daa8e..3c736a508d3 100644
--- a/mysql-test/r/ps_1general.result
+++ b/mysql-test/r/ps_1general.result
@@ -422,13 +422,10 @@ ERROR HY000: This command is not supported in the prepared statement protocol ye
 prepare stmt1 from ' select * into outfile ''data.txt'' from t1 ';
 execute stmt1 ;
 prepare stmt1 from ' optimize table t1 ' ;
-ERROR HY000: This command is not supported in the prepared statement protocol yet
 prepare stmt1 from ' analyze table t1 ' ;
-ERROR HY000: This command is not supported in the prepared statement protocol yet
 prepare stmt1 from ' checksum table t1 ' ;
 ERROR HY000: This command is not supported in the prepared statement protocol yet
 prepare stmt1 from ' repair table t1 ' ;
-ERROR HY000: This command is not supported in the prepared statement protocol yet
 prepare stmt1 from ' restore table t1 from ''data.txt'' ' ;
 ERROR HY000: This command is not supported in the prepared statement protocol yet
 prepare stmt1 from ' handler t1 open ';
diff --git a/mysql-test/r/sp-dynamic.result b/mysql-test/r/sp-dynamic.result
index c00b09f90e1..d9d5706cded 100644
--- a/mysql-test/r/sp-dynamic.result
+++ b/mysql-test/r/sp-dynamic.result
@@ -286,12 +286,12 @@ id	stmt_text	status
 1	select 1	supported
 2	flush tables	not supported
 3	handler t1 open as ha	not supported
-4	analyze table t1	not supported
+4	analyze table t1	supported
 5	check table t1	not supported
 6	checksum table t1	not supported
 7	check table t1	not supported
-8	optimize table t1	not supported
-9	repair table t1	not supported
+8	optimize table t1	supported
+9	repair table t1	supported
 10	describe extended select * from t1	supported
 11	help help	not supported
 12	show databases	supported
diff --git a/mysql-test/t/ps.test b/mysql-test/t/ps.test
index 1f5f17fe976..cc7d7ef2d82 100644
--- a/mysql-test/t/ps.test
+++ b/mysql-test/t/ps.test
@@ -1110,4 +1110,40 @@ select * from t1 order by 1+1;
 
 drop table t1;
 
+#
+# Bug#19308 "REPAIR/OPTIMIZE/ANALYZE supported in SP but not in PS".
+# Add test coverage for the added commands.
+#
+create table t1 (a int);
+create table t2 like t1;
+create table t3 like t2;
+prepare stmt from "repair table t1";
+execute stmt;
+execute stmt;
+prepare stmt from "optimize table t1";
+execute stmt;
+execute stmt;
+prepare stmt from "analyze table t1";
+execute stmt;
+execute stmt;
+prepare stmt from "repair table t1, t2, t3";
+execute stmt;
+execute stmt;
+prepare stmt from "optimize table t1, t2, t3";
+execute stmt;
+execute stmt;
+prepare stmt from "analyze table t1, t2, t3";
+execute stmt;
+execute stmt;
+prepare stmt from "repair table t1, t4, t3";
+execute stmt;
+execute stmt;
+prepare stmt from "optimize table t1, t3, t4";
+execute stmt;
+execute stmt;
+prepare stmt from "analyze table t4, t1";
+execute stmt;
+execute stmt;
+deallocate prepare stmt;
+
 # End of 5.0 tests
diff --git a/mysql-test/t/ps_1general.test b/mysql-test/t/ps_1general.test
index 89fad3fa4fb..72b69fc8d9f 100644
--- a/mysql-test/t/ps_1general.test
+++ b/mysql-test/t/ps_1general.test
@@ -453,13 +453,10 @@ into table t1 fields terminated by ''\t'' ';
 prepare stmt1 from ' select * into outfile ''data.txt'' from t1 ';
 execute stmt1 ;
 ## 
---error 1295
 prepare stmt1 from ' optimize table t1 ' ;
---error 1295
 prepare stmt1 from ' analyze table t1 ' ;
 --error 1295
 prepare stmt1 from ' checksum table t1 ' ;
---error 1295
 prepare stmt1 from ' repair table t1 ' ;
 --error 1295
 prepare stmt1 from ' restore table t1 from ''data.txt'' ' ;
diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc
index 4fa0a2dcb6e..f7935a55572 100644
--- a/sql/sql_prepare.cc
+++ b/sql/sql_prepare.cc
@@ -1753,6 +1753,9 @@ static bool check_prepared_statement(Prepared_statement *stmt,
   case SQLCOM_CALL:
   case SQLCOM_CREATE_VIEW:
   case SQLCOM_DROP_VIEW:
+  case SQLCOM_REPAIR:
+  case SQLCOM_ANALYZE:
+  case SQLCOM_OPTIMIZE:
     break;
 
   default:

From 5b3bf3998799dfec0cbc6e6db6c1c6d946a2eb2f Mon Sep 17 00:00:00 2001
From: "mikael@zim.(none)" <>
Date: Tue, 25 Apr 2006 14:33:54 -0700
Subject: [PATCH 056/108] BUG#19313: Crash after mysqld starts and stops
 immediately afterwards.

---
 sql/sql_table.cc | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index ca13fb27f96..e16f63a8175 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -428,10 +428,6 @@ static uint read_ddl_log_header()
   bool successful_open= FALSE;
   DBUG_ENTER("read_ddl_log_header");
 
-  bzero(file_entry_buf, sizeof(global_ddl_log.file_entry_buf));
-  global_ddl_log.inited= FALSE;
-  global_ddl_log.recovery_phase= TRUE;
-  global_ddl_log.io_size= IO_SIZE;
   create_ddl_log_file_name(file_name);
   if ((global_ddl_log.file_id= my_open(file_name,
                                         O_RDWR | O_BINARY, MYF(MY_WME))) >= 0)
@@ -1067,6 +1063,15 @@ void execute_ddl_log_recovery()
   char file_name[FN_REFLEN];
   DBUG_ENTER("execute_ddl_log_recovery");
 
+  /*
+    Initialise global_ddl_log struct
+  */
+  bzero(global_ddl_log.file_entry_buf, sizeof(global_ddl_log.file_entry_buf));
+  global_ddl_log.inited= FALSE;
+  global_ddl_log.recovery_phase= TRUE;
+  global_ddl_log.io_size= IO_SIZE;
+  global_ddl_log.file_id=(File)-1;
+
   /*
     To be able to run this from boot, we allocate a temporary THD
   */
@@ -1130,7 +1135,8 @@ void release_ddl_log()
     my_free((char*)free_list, MYF(0));
     free_list= tmp;
   }
-  VOID(my_close(global_ddl_log.file_id, MYF(0)));
+  if (global_ddl_log.file_id != (File)-1)
+    VOID(my_close(global_ddl_log.file_id, MYF(0)));
   pthread_mutex_unlock(&LOCK_gdl);
   VOID(pthread_mutex_destroy(&LOCK_gdl));
   DBUG_VOID_RETURN;

From 1409dc6f594af5b333e87db8a93a69732b886206 Mon Sep 17 00:00:00 2001
From: "serg@sergbook.mysql.com" <>
Date: Tue, 25 Apr 2006 16:41:12 -0700
Subject: [PATCH 057/108] small optimization of the previous bugfix (based on
 the fact that packet is ALWAYS \0 terminated, see my_net_read)

---
 sql/sql_parse.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index 93f696f6d49..8f8eacbb77b 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -647,7 +647,7 @@ check_connections(THD *thd)
   char *db=0;
   if (thd->client_capabilities & CLIENT_CONNECT_WITH_DB)
     db=strend(passwd)+1;
-  if (strend(db ? db : passwd) - (char*)net->read_pos > pkt_len)
+  if ((db ? db : passwd) - (char*)net->read_pos > pkt_len)
   {
     inc_host_errors(&thd->remote.sin_addr);
     return ER_HANDSHAKE_ERROR;

From 2c3a3bd87f9679851ef2fa65c3a675d58605145f Mon Sep 17 00:00:00 2001
From: "msvensson@neptunus.(none)" <>
Date: Wed, 26 Apr 2006 12:16:57 +0200
Subject: [PATCH 058/108] Remove hacks for building shared libs on aix and qnx

---
 configure.in | 39 ---------------------------------------
 1 file changed, 39 deletions(-)

diff --git a/configure.in b/configure.in
index fe6ac7483ba..a21f12a07af 100644
--- a/configure.in
+++ b/configure.in
@@ -219,45 +219,6 @@ else
   AC_PATH_PROG(AS, as, as)
 fi
 
-# These checks has to be made befoe we buil libtool as they affect
-# what is written into libtool.
-case $SYSTEM_TYPE in
-    *aix5*)
-       # Find out which ABI we are using.
-      echo 'int i;' > conftest.$ac_ext
-      if AC_TRY_EVAL(ac_compile); then
-        case `/usr/bin/file conftest.$ac_objext` in
-        *"32-bit XCOFF"*)
-          # OBJECT_MODE=32
-          ;;
-         *"64-bit XCOFF"*)
-	   AC_MSG_WARN([Setting 64-bit mode for AIX 5.*])
-           # It was detected that compiler is using 64-bit mode
-	   # Set flags for CC and NM so that those tools will work
-           # in 64-bit mode when called from libtool
-	   # The easiest way fix this is "export OBJECT_MODE=64"
-	   CC="$CC -q64"
-	   CXX="$CXX -q64"
-	   if test "X${NM+set}" != Xset; then
-	     NM="/usr/bin/nm -B -X64"
-           fi
-          ;;
-	esac
-      fi
-      rm -rf conftest*
-    ;;
-    *qnx*)
-    # Don't build shared libraries on QNX as it will run out of
-    # stack and segfault
-    AC_MSG_WARN([Turning off building of shared libraries])
-    AC_DISABLE_SHARED
-    ;;
-    *)
-    ;;
-esac
-
-LINK= "OBJECT_MODE=64 $LINK"
-
 # Still need ranlib for readline; local static use only so no libtool.
 AC_PROG_RANLIB
 # We use libtool

From a0a8a711d6e52ee3d1bc9e72487e2e04f7e825dc Mon Sep 17 00:00:00 2001
From: "msvensson@neptunus.(none)" <>
Date: Wed, 26 Apr 2006 12:45:22 +0200
Subject: [PATCH 059/108] Bug#19362 im_daemon_lifecycle fails when built from
 source distribution - Add function "mysqld_real_path" which is needed if the
 mysqld_path is a symlink or a script(like libtool) that executes the real
 mysqld. - Add new variable mysqld_real_path - Use mysqld_real_path from
 fill_instance_version

---
 .../instance-manager/instance_options.cc      | 59 ++++++++++++++++++-
 .../instance-manager/instance_options.h       |  5 +-
 2 files changed, 61 insertions(+), 3 deletions(-)

diff --git a/server-tools/instance-manager/instance_options.cc b/server-tools/instance-manager/instance_options.cc
index 83f13b34aa2..9389694822a 100644
--- a/server-tools/instance-manager/instance_options.cc
+++ b/server-tools/instance-manager/instance_options.cc
@@ -22,6 +22,7 @@
 
 #include "parse_output.h"
 #include "buffer.h"
+#include "log.h"
 
 #include 
 #include 
@@ -132,7 +133,7 @@ int Instance_options::fill_instance_version()
 
   bzero(result, MAX_VERSION_STRING_LENGTH);
 
-  rc= parse_output_and_get_value(cmd.buffer, mysqld_path,
+  rc= parse_output_and_get_value(cmd.buffer, mysqld_real_path,
                                  result, MAX_VERSION_STRING_LENGTH,
                                  GET_LINE);
 
@@ -143,6 +144,60 @@ int Instance_options::fill_instance_version()
     mysqld_version= strdup_root(&alloc, result);
   }
 err:
+  if (rc)
+    log_error("fill_instance_version: Failed to get version of '%s'",
+              mysqld_path);
+  return rc;
+}
+
+
+/*
+  Fill mysqld_real_path
+
+  SYNOPSYS
+    fill_mysqld_real_path()
+
+  DESCRIPTION
+
+  Get the real path to mysqld from "mysqld --help" output.
+  Will print the realpath of mysqld between "Usage: " and "[OPTIONS]"
+
+  This is needed if the mysqld_path variable is pointing at a
+  script(for example libtool) or a symlink.
+
+  RETURN
+    0 - ok
+    1 - error occured
+*/
+
+int Instance_options::fill_mysqld_real_path()
+{
+  char result[FN_REFLEN];
+  char help_option[]= " --no-defaults --help";
+  int rc= 1;
+  Buffer cmd(mysqld_path_len + sizeof(help_option));
+
+  if (create_mysqld_command(&cmd, mysqld_path, mysqld_path_len,
+                            help_option, sizeof(help_option)))
+    goto err;
+
+  bzero(result, FN_REFLEN);
+
+  rc= parse_output_and_get_value(cmd.buffer, "Usage: ",
+                                 result, FN_REFLEN,
+                                 GET_LINE);
+
+  if (*result != '\0')
+  {
+    char* options_str;
+    /* chop the path of at [OPTIONS] */
+    if ((options_str= strstr(result, "[OPTIONS]")))
+      *options_str= '\0';
+    mysqld_real_path= strdup_root(&alloc, result);
+  }
+err:
+  if (rc)
+    log_error("fill_mysqld_real_path: Failed to get real path of mysqld");
   return rc;
 }
 
@@ -405,7 +460,7 @@ int Instance_options::complete_initialization(const char *default_path,
          options_array.elements*sizeof(char*));
   argv[filled_default_options + options_array.elements]= 0;
 
-  if (fill_log_options() || fill_instance_version())
+  if (fill_log_options() || fill_mysqld_real_path() || fill_instance_version())
     goto err;
 
   return 0;
diff --git a/server-tools/instance-manager/instance_options.h b/server-tools/instance-manager/instance_options.h
index dae1c2695d1..b316dbf00fc 100644
--- a/server-tools/instance-manager/instance_options.h
+++ b/server-tools/instance-manager/instance_options.h
@@ -44,7 +44,8 @@ public:
   Instance_options() :
     mysqld_version(0), mysqld_socket(0), mysqld_datadir(0),
     mysqld_bind_address(0), mysqld_pid_file(0), mysqld_port(0),
-    mysqld_port_val(0), mysqld_path(0), nonguarded(0), shutdown_delay(0),
+    mysqld_port_val(0), mysqld_path(0), mysqld_real_path(0),
+    nonguarded(0), shutdown_delay(0),
     shutdown_delay_val(0), filled_default_options(0)
   {}
   ~Instance_options();
@@ -84,6 +85,7 @@ public:
   uint instance_name_len;
   const char *mysqld_path;
   uint mysqld_path_len;
+  const char *mysqld_real_path;
   const char *nonguarded;
   const char *shutdown_delay;
   uint shutdown_delay_val;
@@ -95,6 +97,7 @@ public:
 private:
   int fill_log_options();
   int fill_instance_version();
+  int fill_mysqld_real_path();
   int add_to_argv(const char *option);
   int get_default_option(char *result, size_t result_len,
                          const char *option_name);

From 0e08e3976375c58786c37f2bdfceec8b43a20239 Mon Sep 17 00:00:00 2001
From: "msvensson@neptunus.(none)" <>
Date: Wed, 26 Apr 2006 13:22:18 +0200
Subject: [PATCH 060/108] Change sleep_until_file_created to sleep 100
 millisecond instead of sleeping 1 seconds between each iteration.

---
 mysql-test/lib/mtr_process.pl | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/mysql-test/lib/mtr_process.pl b/mysql-test/lib/mtr_process.pl
index c41978127b3..973655a3eb6 100644
--- a/mysql-test/lib/mtr_process.pl
+++ b/mysql-test/lib/mtr_process.pl
@@ -832,30 +832,36 @@ sub sleep_until_file_created ($$$) {
   my $pidfile= shift;
   my $timeout= shift;
   my $pid=     shift;
+  my $sleeptime= 100; # Milliseconds
+  my $loops= ($timeout * 1000) / $sleeptime;
 
-  for ( my $loop= 1; $loop <= $timeout; $loop++ )
+  for ( my $loop= 1; $loop <= $loops; $loop++ )
   {
     if ( -r $pidfile )
     {
       return $pid;
     }
 
-    # Check if it died after the fork() was successful 
-    if ( $pid > 0 && waitpid($pid,&WNOHANG) == $pid )
+    # Check if it died after the fork() was successful
+    if ( $pid != 0 && waitpid($pid,&WNOHANG) == $pid )
     {
       return 0;
     }
 
-    mtr_debug("Sleep 1 second waiting for creation of $pidfile");
+    mtr_debug("Sleep $sleeptime milliseconds waiting for ".
+	      "creation of $pidfile");
 
-    if ( $loop % 60 == 0 )
+    # Print extra message every 60 seconds
+    my $seconds= ($loop * $sleeptime) / 1000;
+    if ( $seconds > 1 and $seconds % 60 == 0 )
     {
-      my $left= $timeout - $loop;
-      mtr_warning("Waited $loop seconds for $pidfile to be created, " .
+      my $left= $timeout - $seconds;
+      mtr_warning("Waited $seconds seconds for $pidfile to be created, " .
                   "still waiting for $left seconds...");
     }
 
-    sleep(1);
+    # Millisceond sleep emulated with select
+    select(undef, undef, undef, ($sleeptime/1000));
   }
 
   return 0;

From d96fbd738d9108332d376ee80ba38688229687be Mon Sep 17 00:00:00 2001
From: "elliot@mysql.com" <>
Date: Wed, 26 Apr 2006 11:55:26 -0400
Subject: [PATCH 061/108] The fix for bug#17248 accidentally removed the
 sync_binlog variable. This patch restores sync_binlog.

---
 sql/set_var.cc | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/sql/set_var.cc b/sql/set_var.cc
index a0b60251354..71ecf97a6fa 100644
--- a/sql/set_var.cc
+++ b/sql/set_var.cc
@@ -376,6 +376,9 @@ sys_var_thd_table_type  sys_table_type("table_type",
 				       &SV::table_type);
 sys_var_thd_storage_engine sys_storage_engine("storage_engine",
 				       &SV::table_type);
+#ifdef HAVE_REPLICATION
+sys_var_sync_binlog_period sys_sync_binlog_period("sync_binlog", &sync_binlog_period);
+#endif
 sys_var_bool_ptr	sys_sync_frm("sync_frm", &opt_sync_frm);
 sys_var_long_ptr	sys_table_cache_size("table_cache",
 					     &table_cache_size);
@@ -697,6 +700,9 @@ sys_var *sys_variables[]=
   &sys_sql_warnings,
   &sys_sql_notes,
   &sys_storage_engine,
+#ifdef HAVE_REPLICATION
+  &sys_sync_binlog_period,
+#endif
   &sys_sync_frm,
   &sys_table_cache_size,
   &sys_table_lock_wait_timeout,
@@ -992,6 +998,9 @@ struct show_var_st init_vars[]= {
   {"sql_notes",               (char*) &sys_sql_notes,               SHOW_BOOL},
   {"sql_warnings",            (char*) &sys_sql_warnings,            SHOW_BOOL},
   {sys_storage_engine.name,   (char*) &sys_storage_engine,          SHOW_SYS},
+#ifdef HAVE_REPLICATION
+  {sys_sync_binlog_period.name,(char*) &sys_sync_binlog_period,     SHOW_SYS},
+#endif
   {sys_sync_frm.name,         (char*) &sys_sync_frm,               SHOW_SYS},
 #ifdef HAVE_TZNAME
   {"system_time_zone",        system_time_zone,                     SHOW_CHAR},

From 960c5621ebe7bd581a959146e1580158c816309f Mon Sep 17 00:00:00 2001
From: "jimw@mysql.com" <>
Date: Wed, 26 Apr 2006 09:21:53 -0700
Subject: [PATCH 062/108] Bug #17849: sql_big_selects not shown in SHOW
 VARIABLES output

  This patch simply adds sql_big_selects to the list of variables
  output by SHOW VARIABLES.
---
 mysql-test/r/variables.result |  7 +++++++
 mysql-test/t/variables.test   | 10 +++++++++-
 sql/set_var.cc                |  3 ++-
 3 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/mysql-test/r/variables.result b/mysql-test/r/variables.result
index 1d1c76ab3fe..269a9bfdbd9 100644
--- a/mysql-test/r/variables.result
+++ b/mysql-test/r/variables.result
@@ -584,3 +584,10 @@ set @@global.character_set_filesystem=default;
 select @@global.character_set_filesystem;
 @@global.character_set_filesystem
 binary
+set @old_sql_big_selects = @@sql_big_selects;
+set @@sql_big_selects = 1;
+show variables like 'sql_big_selects';
+Variable_name	Value
+sql_big_selects	ON
+set @@sql_big_selects = @old_sql_big_selects;
+End of 5.0 tests
diff --git a/mysql-test/t/variables.test b/mysql-test/t/variables.test
index 8d8dc7896df..5b8db2f8786 100644
--- a/mysql-test/t/variables.test
+++ b/mysql-test/t/variables.test
@@ -472,4 +472,12 @@ select @@character_set_filesystem;
 set @@global.character_set_filesystem=default;
 select @@global.character_set_filesystem;
 
-# End of 5.0 tests
+#
+# Bug #17849: Show sql_big_selects in SHOW VARIABLES
+#
+set @old_sql_big_selects = @@sql_big_selects;
+set @@sql_big_selects = 1;
+show variables like 'sql_big_selects';
+set @@sql_big_selects = @old_sql_big_selects;
+
+--echo End of 5.0 tests
diff --git a/sql/set_var.cc b/sql/set_var.cc
index 71ecf97a6fa..4e8575f3df2 100644
--- a/sql/set_var.cc
+++ b/sql/set_var.cc
@@ -993,7 +993,8 @@ struct show_var_st init_vars[]= {
 #ifdef HAVE_SYS_UN_H
   {"socket",                  (char*) &mysqld_unix_port,             SHOW_CHAR_PTR},
 #endif
-  {sys_sort_buffer.name,      (char*) &sys_sort_buffer, 	    SHOW_SYS},
+  {sys_sort_buffer.name,      (char*) &sys_sort_buffer,             SHOW_SYS},
+  {sys_big_selects.name,      (char*) &sys_big_selects,             SHOW_SYS},
   {sys_sql_mode.name,         (char*) &sys_sql_mode,                SHOW_SYS},
   {"sql_notes",               (char*) &sys_sql_notes,               SHOW_BOOL},
   {"sql_warnings",            (char*) &sys_sql_warnings,            SHOW_BOOL},

From 58cb2f317c4a684c8941a66bdf473170ade21582 Mon Sep 17 00:00:00 2001
From: "jimw@mysql.com" <>
Date: Wed, 26 Apr 2006 17:09:41 -0700
Subject: [PATCH 063/108] Remove obsolete test

---
 mysql-test/r/user_var.result | 3 ---
 mysql-test/t/user_var.test   | 2 --
 2 files changed, 5 deletions(-)

diff --git a/mysql-test/r/user_var.result b/mysql-test/r/user_var.result
index 75a680e504d..7439f9132fb 100644
--- a/mysql-test/r/user_var.result
+++ b/mysql-test/r/user_var.result
@@ -215,9 +215,6 @@ select @@version;
 select @@global.version;
 @@global.version
 #
-select @@session.VERSION;
-@@session.VERSION
-#
 set @first_var= NULL;
 create table t1 select @first_var;
 show create table t1;
diff --git a/mysql-test/t/user_var.test b/mysql-test/t/user_var.test
index 61861c26ea8..e1b23a1782f 100644
--- a/mysql-test/t/user_var.test
+++ b/mysql-test/t/user_var.test
@@ -143,8 +143,6 @@ select @@Max_Allowed_Packet;
 select @@version;
 --replace_column 1 #
 select @@global.version;
---replace_column 1 #
-select @@session.VERSION;
 
 # End of 4.1 tests
 

From 31a428928e81e4d83f4382da7c796f047fa711e4 Mon Sep 17 00:00:00 2001
From: "jimw@mysql.com" <>
Date: Wed, 26 Apr 2006 20:50:27 -0700
Subject: [PATCH 064/108] Fix bug in ndbcluster.sh on Solaris (now that line is
 the same as in 5.1)

---
 mysql-test/ndb/ndbcluster.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mysql-test/ndb/ndbcluster.sh b/mysql-test/ndb/ndbcluster.sh
index 50eb3987a36..3710da71e10 100644
--- a/mysql-test/ndb/ndbcluster.sh
+++ b/mysql-test/ndb/ndbcluster.sh
@@ -237,7 +237,7 @@ cat `find "$fs_ndb" -name 'ndb_*.pid'` > "$fs_ndb/$pidfile"
 # test if Ndb Cluster starts properly
 
 echo "Waiting for NDB data nodes to start..."
-if ( $exec_waiter ) | grep -q "NDBT_ProgramExit: 0 - OK"; then :; else
+if ( $exec_waiter ) | grep "NDBT_ProgramExit: 0 - OK" > /dev/null 2>&1; then :; else
   echo "Ndbcluster startup failed"
   stop_default_ndbcluster
   exit 1

From 7162fa4a1abcbe19c37dea62d1f846dc20b94e19 Mon Sep 17 00:00:00 2001
From: "paul@polar.kitebird.com" <>
Date: Thu, 27 Apr 2006 07:51:56 -0500
Subject: [PATCH 065/108] set_var.cc:   System variable was added out of
 lexical order.

---
 sql/set_var.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sql/set_var.cc b/sql/set_var.cc
index 681c70c4c02..f845cdd0c5d 100644
--- a/sql/set_var.cc
+++ b/sql/set_var.cc
@@ -850,9 +850,9 @@ struct show_var_st init_vars[]= {
   {sys_old_passwords.name,    (char*) &sys_old_passwords,           SHOW_SYS},
   {"open_files_limit",	      (char*) &open_files_limit,	    SHOW_LONG},
   {"pid_file",                (char*) pidfile_name,                 SHOW_CHAR},
-  {sys_prepared_stmt_count.name, (char*) &sys_prepared_stmt_count, SHOW_SYS},
   {"port",                    (char*) &mysqld_port,                  SHOW_INT},
   {sys_preload_buff_size.name, (char*) &sys_preload_buff_size,      SHOW_SYS},
+  {sys_prepared_stmt_count.name, (char*) &sys_prepared_stmt_count, SHOW_SYS},
   {"protocol_version",        (char*) &protocol_version,            SHOW_INT},
   {sys_query_alloc_block_size.name, (char*) &sys_query_alloc_block_size,
    SHOW_SYS},

From 0e5113aead49dd97f20c062c817f7ef2ffee9693 Mon Sep 17 00:00:00 2001
From: "msvensson@shellback.(none)" <>
Date: Thu, 27 Apr 2006 16:32:40 +0200
Subject: [PATCH 066/108] Add test to mysql-test-run.pl to see if the
 udf_example.so is availble. Set envioronment variable UDF_EXAMPLE_LIB if it
 is. Then check in have_udf if that variable is set. Finally use tahe variable
 when loading the shared library.

---
 mysql-test/include/have_udf.inc       |  8 ++++++++
 mysql-test/lib/mtr_misc.pl            | 16 +++++++++++++++
 mysql-test/mysql-test-run.pl          |  4 ++++
 mysql-test/r/have_udf_example.require |  2 ++
 mysql-test/r/udf.result               | 16 +++++++--------
 mysql-test/t/disabled.def             |  1 -
 mysql-test/t/udf.test                 | 28 +++++++++++++++++----------
 7 files changed, 56 insertions(+), 19 deletions(-)
 create mode 100644 mysql-test/r/have_udf_example.require

diff --git a/mysql-test/include/have_udf.inc b/mysql-test/include/have_udf.inc
index b6e6f0f2516..42b9942f74d 100644
--- a/mysql-test/include/have_udf.inc
+++ b/mysql-test/include/have_udf.inc
@@ -6,3 +6,11 @@
 disable_query_log;
 show variables like "have_dynamic_loading";
 enable_query_log;
+
+#
+# Check if the variable UDF_EXAMPLE_LIB is set
+#
+--require r/have_udf_example.require
+disable_query_log;
+eval select LENGTH("$UDF_EXAMPLE_LIB") > 0 as "have_udf_example_lib";
+enable_query_log;
diff --git a/mysql-test/lib/mtr_misc.pl b/mysql-test/lib/mtr_misc.pl
index 90617194897..7676401f08e 100644
--- a/mysql-test/lib/mtr_misc.pl
+++ b/mysql-test/lib/mtr_misc.pl
@@ -12,6 +12,7 @@ sub mtr_init_args ($);
 sub mtr_add_arg ($$@);
 sub mtr_path_exists(@);
 sub mtr_script_exists(@);
+sub mtr_file_exists(@);
 sub mtr_exe_exists(@);
 sub mtr_copy_dir($$);
 sub mtr_same_opts($$);
@@ -94,6 +95,21 @@ sub mtr_script_exists (@) {
   }
 }
 
+sub mtr_file_exists (@) {
+  foreach my $path ( @_ )
+  {
+    return $path if -e $path;
+  }
+  if ( @_ == 1 )
+  {
+    mtr_error("Could not find $_[0]");
+  }
+  else
+  {
+    mtr_error("Could not find any of " . join(" ", @_));
+  }
+}
+
 sub mtr_exe_exists (@) {
   my @path= @_;
   map {$_.= ".exe"} @path if $::glob_win32;
diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl
index e4bfc73dbdd..b7a19bc8a74 100755
--- a/mysql-test/mysql-test-run.pl
+++ b/mysql-test/mysql-test-run.pl
@@ -188,6 +188,7 @@ our $exe_mysqltest;
 our $exe_slave_mysqld;
 our $exe_im;
 our $exe_my_print_defaults;
+our $lib_udf_example;
 
 our $opt_bench= 0;
 our $opt_small_bench= 0;
@@ -1057,6 +1058,8 @@ sub executable_setup () {
       mtr_script_exists("$glob_basedir/scripts/mysql_fix_privilege_tables");
     $path_ndb_tools_dir= mtr_path_exists("$glob_basedir/ndb/tools");
     $exe_ndb_mgm=        "$glob_basedir/ndb/src/mgmclient/ndb_mgm";
+    $lib_udf_example=
+      mtr_file_exists("$glob_basedir/sql/.libs/udf_example.so");
   }
   else
   {
@@ -2936,6 +2939,7 @@ sub run_mysqltest ($) {
   $ENV{'MYSQL_CLIENT_TEST'}=        $cmdline_mysql_client_test;
   $ENV{'CHARSETSDIR'}=              $path_charsetsdir;
   $ENV{'MYSQL_MY_PRINT_DEFAULTS'}=  $exe_my_print_defaults;
+  $ENV{'UDF_EXAMPLE_LIB'}=          basename($lib_udf_example);
 
   $ENV{'NDB_MGM'}=                  $exe_ndb_mgm;
   $ENV{'NDB_BACKUP_DIR'}=           $path_ndb_data_dir;
diff --git a/mysql-test/r/have_udf_example.require b/mysql-test/r/have_udf_example.require
new file mode 100644
index 00000000000..e60fab1dbe0
--- /dev/null
+++ b/mysql-test/r/have_udf_example.require
@@ -0,0 +1,2 @@
+have_udf_example_lib
+1
diff --git a/mysql-test/r/udf.result b/mysql-test/r/udf.result
index ce9271224dc..be52fd7f87c 100644
--- a/mysql-test/r/udf.result
+++ b/mysql-test/r/udf.result
@@ -1,15 +1,15 @@
 drop table if exists t1;
-CREATE FUNCTION metaphon RETURNS STRING SONAME 'udf_example.so';
-CREATE FUNCTION myfunc_double RETURNS REAL SONAME 'udf_example.so';
-CREATE FUNCTION myfunc_nonexist RETURNS INTEGER SONAME 'udf_example.so';
+CREATE FUNCTION metaphon RETURNS STRING SONAME "UDF_EXAMPLE_LIB";
+CREATE FUNCTION myfunc_double RETURNS REAL SONAME "UDF_EXAMPLE_LIB";
+CREATE FUNCTION myfunc_nonexist RETURNS INTEGER SONAME "UDF_EXAMPLE_LIB";
 ERROR HY000: Can't find function 'myfunc_nonexist' in library
-CREATE FUNCTION myfunc_int RETURNS INTEGER SONAME 'udf_example.so';
-CREATE FUNCTION sequence RETURNS INTEGER SONAME "udf_example.so";
-CREATE FUNCTION lookup RETURNS STRING SONAME 'udf_example.so';
+CREATE FUNCTION myfunc_int RETURNS INTEGER SONAME "UDF_EXAMPLE_LIB";
+CREATE FUNCTION sequence RETURNS INTEGER SONAME "UDF_EXAMPLE_LIB";
+CREATE FUNCTION lookup RETURNS STRING SONAME "UDF_EXAMPLE_LIB";
 CREATE FUNCTION reverse_lookup
-RETURNS STRING SONAME 'udf_example.so';
+RETURNS STRING SONAME "UDF_EXAMPLE_LIB";
 CREATE AGGREGATE FUNCTION avgcost
-RETURNS REAL SONAME 'udf_example.so';
+RETURNS REAL SONAME "UDF_EXAMPLE_LIB";
 select myfunc_double();
 ERROR HY000: myfunc_double must have at least one argument
 select myfunc_double(1);
diff --git a/mysql-test/t/disabled.def b/mysql-test/t/disabled.def
index dee6146017d..f71e24ff3ed 100644
--- a/mysql-test/t/disabled.def
+++ b/mysql-test/t/disabled.def
@@ -12,4 +12,3 @@
 
 sp-goto         : GOTO is currently is disabled - will be fixed in the future
 ndb_load        : Bug#17233
-udf             : Bug#18564
diff --git a/mysql-test/t/udf.test b/mysql-test/t/udf.test
index c9f22cf410b..e2556692612 100644
--- a/mysql-test/t/udf.test
+++ b/mysql-test/t/udf.test
@@ -14,18 +14,26 @@ drop table if exists t1;
 # Create the example functions from udf_example
 #
 
-CREATE FUNCTION metaphon RETURNS STRING SONAME 'udf_example.so';
-CREATE FUNCTION myfunc_double RETURNS REAL SONAME 'udf_example.so';
+--replace_result $UDF_EXAMPLE_LIB UDF_EXAMPLE_LIB
+eval CREATE FUNCTION metaphon RETURNS STRING SONAME "$UDF_EXAMPLE_LIB";
+--replace_result $UDF_EXAMPLE_LIB UDF_EXAMPLE_LIB
+eval CREATE FUNCTION myfunc_double RETURNS REAL SONAME "$UDF_EXAMPLE_LIB";
 
+--replace_result $UDF_EXAMPLE_LIB UDF_EXAMPLE_LIB
 --error ER_CANT_FIND_DL_ENTRY
-CREATE FUNCTION myfunc_nonexist RETURNS INTEGER SONAME 'udf_example.so';
-CREATE FUNCTION myfunc_int RETURNS INTEGER SONAME 'udf_example.so';
-CREATE FUNCTION sequence RETURNS INTEGER SONAME "udf_example.so";
-CREATE FUNCTION lookup RETURNS STRING SONAME 'udf_example.so';
-CREATE FUNCTION reverse_lookup
-        RETURNS STRING SONAME 'udf_example.so';
-CREATE AGGREGATE FUNCTION avgcost
-        RETURNS REAL SONAME 'udf_example.so';
+eval CREATE FUNCTION myfunc_nonexist RETURNS INTEGER SONAME "$UDF_EXAMPLE_LIB";
+--replace_result $UDF_EXAMPLE_LIB UDF_EXAMPLE_LIB
+eval CREATE FUNCTION myfunc_int RETURNS INTEGER SONAME "$UDF_EXAMPLE_LIB";
+--replace_result $UDF_EXAMPLE_LIB UDF_EXAMPLE_LIB
+eval CREATE FUNCTION sequence RETURNS INTEGER SONAME "$UDF_EXAMPLE_LIB";
+--replace_result $UDF_EXAMPLE_LIB UDF_EXAMPLE_LIB
+eval CREATE FUNCTION lookup RETURNS STRING SONAME "$UDF_EXAMPLE_LIB";
+--replace_result $UDF_EXAMPLE_LIB UDF_EXAMPLE_LIB
+eval CREATE FUNCTION reverse_lookup
+        RETURNS STRING SONAME "$UDF_EXAMPLE_LIB";
+--replace_result $UDF_EXAMPLE_LIB UDF_EXAMPLE_LIB
+eval CREATE AGGREGATE FUNCTION avgcost
+        RETURNS REAL SONAME "$UDF_EXAMPLE_LIB";
 
 --error 0
 select myfunc_double();

From 36155b63eb94bc7d558abad025af1b7029a0577c Mon Sep 17 00:00:00 2001
From: "jimw@mysql.com" <>
Date: Thu, 27 Apr 2006 10:53:19 -0700
Subject: [PATCH 067/108] Bug #19393: Federated tests fail on Windows under
 pushbuild

  Supplying --skip-rpl to mysql-test-run.pl would always disable the
  slaves, but those slaves may still be needed for the federated tests.
  Now we only disable the slaves when they are not used by any of the
  tests.
---
 mysql-test/mysql-test-run.pl | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl
index bc24b77207f..a2e1df51464 100755
--- a/mysql-test/mysql-test-run.pl
+++ b/mysql-test/mysql-test-run.pl
@@ -258,6 +258,7 @@ our $opt_result_ext;
 
 our $opt_skip;
 our $opt_skip_rpl;
+our $use_slaves;
 our $opt_skip_test;
 our $opt_skip_im;
 
@@ -407,16 +408,15 @@ sub main () {
     my $tests= collect_test_cases($opt_suite);
 
     # Turn off NDB and other similar options if no tests use it
-    my ($need_ndbcluster,$need_im,$need_slave);
+    my ($need_ndbcluster,$need_im);
     foreach my $test (@$tests)
     {
       $need_ndbcluster||= $test->{ndb_test};
       $need_im||= $test->{component_id} eq 'im';
-      $need_slave||= $test->{slave_num};
+      $use_slaves||= $test->{slave_num};
     }
     $opt_with_ndbcluster= 0 unless $need_ndbcluster;
     $opt_skip_im= 1 unless $need_im;
-    $opt_skip_rpl= 1 unless $need_slave;
 
     snapshot_setup();
     initialize_servers();
@@ -981,7 +981,7 @@ sub snapshot_setup () {
     $master->[0]->{'path_myddir'},
     $master->[1]->{'path_myddir'});
 
-  unless ($opt_skip_rpl)
+  if ($use_slaves)
   {
     push @data_dir_lst, ($slave->[0]->{'path_myddir'},
                          $slave->[1]->{'path_myddir'},
@@ -1636,7 +1636,7 @@ sub mysql_install_db () {
   install_db('master', $master->[0]->{'path_myddir'});
   install_db('master', $master->[1]->{'path_myddir'});
 
-  if ( ! $opt_skip_rpl )
+  if ( $use_slaves )
   {
     install_db('slave',  $slave->[0]->{'path_myddir'});
     install_db('slave',  $slave->[1]->{'path_myddir'});

From 6aa775f348cac3cfbded9f85032fcad9f7105891 Mon Sep 17 00:00:00 2001
From: "msvensson@shellback.(none)" <>
Date: Thu, 27 Apr 2006 21:26:24 +0200
Subject: [PATCH 068/108] Return empty string if file does not exist Set
 LD_LIBRARY_PATH and UDF_EXAMPLE_LIB from $lib_udf_example

---
 mysql-test/lib/mtr_misc.pl   | 9 +--------
 mysql-test/mysql-test-run.pl | 5 +++--
 2 files changed, 4 insertions(+), 10 deletions(-)

diff --git a/mysql-test/lib/mtr_misc.pl b/mysql-test/lib/mtr_misc.pl
index 7676401f08e..b5a2e5a4a68 100644
--- a/mysql-test/lib/mtr_misc.pl
+++ b/mysql-test/lib/mtr_misc.pl
@@ -100,14 +100,7 @@ sub mtr_file_exists (@) {
   {
     return $path if -e $path;
   }
-  if ( @_ == 1 )
-  {
-    mtr_error("Could not find $_[0]");
-  }
-  else
-  {
-    mtr_error("Could not find any of " . join(" ", @_));
-  }
+  return "";
 }
 
 sub mtr_exe_exists (@) {
diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl
index aca1b859030..e595009c283 100755
--- a/mysql-test/mysql-test-run.pl
+++ b/mysql-test/mysql-test-run.pl
@@ -1150,7 +1150,7 @@ sub environment_setup () {
   # Add the path where mysqld will find udf_example.so
   # --------------------------------------------------------------------------
   $ENV{'LD_LIBRARY_PATH'}=
-    "$glob_basedir/sql/.libs" .
+    ($lib_udf_example ?  dirname($lib_udf_example) : "") .
       ($ENV{'LD_LIBRARY_PATH'} ? ":$ENV{'LD_LIBRARY_PATH'}" : "");
 
 
@@ -2956,7 +2956,8 @@ sub run_mysqltest ($) {
   $ENV{'MYSQL_CLIENT_TEST'}=        $cmdline_mysql_client_test;
   $ENV{'CHARSETSDIR'}=              $path_charsetsdir;
   $ENV{'MYSQL_MY_PRINT_DEFAULTS'}=  $exe_my_print_defaults;
-  $ENV{'UDF_EXAMPLE_LIB'}=          basename($lib_udf_example);
+  $ENV{'UDF_EXAMPLE_LIB'}=
+    ($lib_udf_example ? basename($lib_udf_example) : "");
 
   $ENV{'NDB_MGM'}=                  $exe_ndb_mgm;
   $ENV{'NDB_BACKUP_DIR'}=           $path_ndb_data_dir;

From f52247a6e8000b743ef61b5cea1e3d3f7a723241 Mon Sep 17 00:00:00 2001
From: "msvensson@shellback.(none)" <>
Date: Thu, 27 Apr 2006 22:21:23 +0200
Subject: [PATCH 069/108] Fix merge error

---
 extra/yassl/src/yassl_int.cpp        | 2 +-
 extra/yassl/taocrypt/src/integer.cpp | 8 --------
 2 files changed, 1 insertion(+), 9 deletions(-)

diff --git a/extra/yassl/src/yassl_int.cpp b/extra/yassl/src/yassl_int.cpp
index d998dbf905e..396461a6ed5 100644
--- a/extra/yassl/src/yassl_int.cpp
+++ b/extra/yassl/src/yassl_int.cpp
@@ -1375,7 +1375,7 @@ Sessions& GetSessions()
 
 static sslFactory* sslFactoryInstance = 0;
 
-sslFactory& GetSSL_Factory()
+sslFactory& GetSSL_Factory(){
     if (!sslFactoryInstance)
         sslFactoryInstance = NEW_YS sslFactory;
     return *sslFactoryInstance;
diff --git a/extra/yassl/taocrypt/src/integer.cpp b/extra/yassl/taocrypt/src/integer.cpp
index b2a66bd5bf3..82a248ff7da 100644
--- a/extra/yassl/taocrypt/src/integer.cpp
+++ b/extra/yassl/taocrypt/src/integer.cpp
@@ -2738,14 +2738,6 @@ void CleanUp()
 }
 
 
-// Clean up static singleton holders, not a leak, but helpful to have gone
-// when checking for leaks
-void CleanUp()
-{
-    tcDelete(one);
-    tcDelete(zero);
-}
-
 Integer::Integer(RandomNumberGenerator& rng, const Integer& min,
                  const Integer& max)
 {

From 480a55287dbb4498e9debc2dc93a3f4ff263bd1c Mon Sep 17 00:00:00 2001
From: "msvensson@shellback.(none)" <>
Date: Thu, 27 Apr 2006 22:30:14 +0200
Subject: [PATCH 070/108] Disable udf.test

---
 mysql-test/t/disabled.def | 1 +
 1 file changed, 1 insertion(+)

diff --git a/mysql-test/t/disabled.def b/mysql-test/t/disabled.def
index 007847fab37..1b587eea40f 100644
--- a/mysql-test/t/disabled.def
+++ b/mysql-test/t/disabled.def
@@ -11,3 +11,4 @@
 ##############################################################################
 
 ndb_load        : Bug#17233
+udf             : Not yet            

From 5617f3387aa94f34320d9f4d658a1698f4e67720 Mon Sep 17 00:00:00 2001
From: "elliot@mysql.com" <>
Date: Thu, 27 Apr 2006 17:42:55 -0400
Subject: [PATCH 071/108] Fix merge

---
 sql/set_var.cc | 252 ++++++++++++-------------------------------------
 1 file changed, 60 insertions(+), 192 deletions(-)

diff --git a/sql/set_var.cc b/sql/set_var.cc
index a8274215edd..16a0c752639 100644
--- a/sql/set_var.cc
+++ b/sql/set_var.cc
@@ -623,202 +623,70 @@ sys_var_thd_time_zone            sys_time_zone("time_zone");
 /* Read only variables */
 
 sys_var_const_str		sys_os("version_compile_os", SYSTEM_TYPE);
-sys_var_readonly                sys_have_innodb("have_innodb", OPT_GLOBAL,
-                                                SHOW_CHAR, get_have_innodb);
+sys_var_have_variable sys_have_archive_db("have_archive", &have_archive_db);
+sys_var_have_variable sys_have_berkeley_db("have_bdb", &have_berkeley_db);
+sys_var_have_variable sys_have_blackhole_db("have_blackhole_engine",
+                                            &have_blackhole_db);
+sys_var_have_variable sys_have_compress("have_compress", &have_compress);
+sys_var_have_variable sys_have_crypt("have_crypt", &have_crypt);
+sys_var_have_variable sys_have_csv_db("have_csv", &have_csv_db);
+sys_var_have_variable sys_have_dlopen("have_dlopen", &have_dlopen);
+sys_var_have_variable sys_have_example_db("have_example_engine",
+                                          &have_example_db);
+sys_var_have_variable sys_have_federated_db("have_federated_engine",
+                                            &have_federated_db);
+sys_var_have_variable sys_have_geometry("have_geometry", &have_geometry);
+sys_var_have_variable sys_have_innodb("have_innodb", &have_innodb);
+sys_var_have_variable sys_have_ndbcluster("have_ndbcluster", &have_ndbcluster);
+sys_var_have_variable sys_have_openssl("have_openssl", &have_openssl);
+sys_var_have_variable sys_have_partition_db("have_partitioning",
+                                            &have_partition_db);
+sys_var_have_variable sys_have_query_cache("have_query_cache",
+                                           &have_query_cache);
+sys_var_have_variable sys_have_rtree_keys("have_rtree_keys", &have_rtree_keys);
+sys_var_have_variable sys_have_symlink("have_symlink", &have_symlink);
+sys_var_have_variable sys_have_row_based_replication("have_row_based_replication",&have_row_based_replication);
 /* Global read-only variable describing server license */
 sys_var_const_str		sys_license("license", STRINGIFY_ARG(LICENSE));
 
-
-/*
-  List of all variables for initialisation and storage in hash
-  This is sorted in alphabetical order to make it easy to add new variables
-
-  If the variable is not in this list, it can't be changed with
-  SET variable_name=
-*/
-
-sys_var *sys_variables[]=
+#ifdef HAVE_REPLICATION
+static int show_slave_skip_errors(THD *thd, SHOW_VAR *var, char *buff)
 {
-  &sys_auto_is_null,
-  &sys_auto_increment_increment,
-  &sys_auto_increment_offset,
-  &sys_autocommit,
-  &sys_automatic_sp_privileges,
-  &sys_big_tables,
-  &sys_big_selects,
-  &sys_binlog_cache_size,
-  &sys_buffer_results,
-  &sys_bulk_insert_buff_size,
-  &sys_character_set_server,
-  &sys_character_set_database,
-  &sys_character_set_client,
-  &sys_character_set_connection,
-  &sys_character_set_results,
-  &sys_character_set_filesystem,
-  &sys_charset_system,
-  &sys_collation_connection,
-  &sys_collation_database,
-  &sys_collation_server,
-  &sys_completion_type,
-  &sys_concurrent_insert,
-  &sys_connect_timeout,
-  &sys_date_format,
-  &sys_datetime_format,
-  &sys_div_precincrement,
-  &sys_default_week_format,
-  &sys_delay_key_write,
-  &sys_delayed_insert_limit,
-  &sys_delayed_insert_timeout,
-  &sys_delayed_queue_size,
-  &sys_error_count,
-  &sys_expire_logs_days,
-  &sys_flush,
-  &sys_flush_time,
-  &sys_ft_boolean_syntax,
-  &sys_foreign_key_checks,
-  &sys_group_concat_max_len,
-  &sys_have_innodb,
-  &sys_identity,
-  &sys_init_connect,
-  &sys_init_slave,
-  &sys_insert_id,
-  &sys_interactive_timeout,
-  &sys_join_buffer_size,
-  &sys_key_buffer_size,
-  &sys_key_cache_block_size,
-  &sys_key_cache_division_limit,
-  &sys_key_cache_age_threshold,
-  &sys_last_insert_id,
-  &sys_license,
-  &sys_local_infile,
-  &sys_log_binlog,
-  &sys_log_off,
-  &sys_log_update,
-  &sys_log_warnings,
-  &sys_long_query_time,
-  &sys_low_priority_updates,
-  &sys_max_allowed_packet,
-  &sys_max_binlog_cache_size,
-  &sys_max_binlog_size,
-  &sys_max_connect_errors,
-  &sys_max_connections,
-  &sys_max_delayed_threads,
-  &sys_max_error_count,
-  &sys_max_insert_delayed_threads,
-  &sys_max_heap_table_size,
-  &sys_max_join_size,
-  &sys_max_length_for_sort_data,
-  &sys_max_prepared_stmt_count,
-  &sys_max_relay_log_size,
-  &sys_max_seeks_for_key,
-  &sys_max_sort_length,
-  &sys_max_sp_recursion_depth,
-  &sys_max_tmp_tables,
-  &sys_max_user_connections,
-  &sys_max_write_lock_count,
-  &sys_multi_range_count,
-  &sys_myisam_data_pointer_size,
-  &sys_myisam_max_sort_file_size,
-  &sys_myisam_repair_threads,
-  &sys_myisam_sort_buffer_size,
-  &sys_myisam_stats_method,
-  &sys_net_buffer_length,
-  &sys_net_read_timeout,
-  &sys_net_retry_count,
-  &sys_net_wait_timeout,
-  &sys_net_write_timeout,
-  &sys_new_mode,
-  &sys_old_passwords,
-  &sys_optimizer_prune_level,
-  &sys_optimizer_search_depth,
-  &sys_preload_buff_size,
-  &sys_prepared_stmt_count,
-  &sys_pseudo_thread_id,
-  &sys_query_alloc_block_size,
-  &sys_query_cache_size,
-  &sys_query_prealloc_size,
-#ifdef HAVE_QUERY_CACHE
-  &sys_query_cache_limit,
-  &sys_query_cache_min_res_unit,
-  &sys_query_cache_type,
-  &sys_query_cache_wlock_invalidate,
-#endif /* HAVE_QUERY_CACHE */
-  &sys_quote_show_create,
-  &sys_rand_seed1,
-  &sys_rand_seed2,
-  &sys_range_alloc_block_size,
-  &sys_readonly,
-  &sys_read_buff_size,
-  &sys_read_rnd_buff_size,
-#ifdef HAVE_REPLICATION
-  &sys_relay_log_purge,
-#endif
-  &sys_rpl_recovery_rank,
-  &sys_safe_updates,
-  &sys_secure_auth,
-  &sys_select_limit,
-  &sys_server_id,
-#ifdef HAVE_REPLICATION
-  &sys_slave_compressed_protocol,
-  &sys_slave_net_timeout,
-  &sys_slave_trans_retries,
-  &sys_slave_skip_counter,
-#endif
-  &sys_slow_launch_time,
-  &sys_sort_buffer,
-  &sys_sql_big_tables,
-  &sys_sql_low_priority_updates,
-  &sys_sql_max_join_size,
-  &sys_sql_mode,
-  &sys_sql_warnings,
-  &sys_sql_notes,
-  &sys_storage_engine,
-#ifdef HAVE_REPLICATION
-  &sys_sync_binlog_period,
-#endif
-  &sys_sync_frm,
-  &sys_table_cache_size,
-  &sys_table_lock_wait_timeout,
-  &sys_table_type,
-  &sys_thread_cache_size,
-  &sys_time_format,
-  &sys_timed_mutexes,
-  &sys_timestamp,
-  &sys_time_zone,
-  &sys_tmp_table_size,
-  &sys_trans_alloc_block_size,
-  &sys_trans_prealloc_size,
-  &sys_tx_isolation,
-  &sys_os,
-#ifdef HAVE_INNOBASE_DB
-  &sys_innodb_fast_shutdown,
-  &sys_innodb_max_dirty_pages_pct,
-  &sys_innodb_max_purge_lag,
-  &sys_innodb_table_locks,
-  &sys_innodb_support_xa,
-  &sys_innodb_max_purge_lag,
-  &sys_innodb_autoextend_increment,
-  &sys_innodb_sync_spin_loops,
-  &sys_innodb_concurrency_tickets,
-  &sys_innodb_thread_sleep_delay,
-  &sys_innodb_thread_concurrency,
-  &sys_innodb_commit_concurrency,
-  &sys_innodb_flush_log_at_trx_commit,
-#endif
-  &sys_trust_routine_creators,
-  &sys_trust_function_creators,
-  &sys_engine_condition_pushdown,
-#ifdef HAVE_NDBCLUSTER_DB
-  &sys_ndb_autoincrement_prefetch_sz,
-  &sys_ndb_cache_check_time,
-  &sys_ndb_force_send,
-  &sys_ndb_use_exact_count,
-  &sys_ndb_use_transactions,
-#endif
-  &sys_unique_checks,
-  &sys_updatable_views_with_limit,
-  &sys_warning_count
-};
+  var->type=SHOW_CHAR;
+  var->value= buff;
+  if (!use_slave_mask || bitmap_is_clear_all(&slave_error_mask))
+  {
+    var->value= const_cast("OFF");
+  }
+  else if (bitmap_is_set_all(&slave_error_mask))
+  {
+    var->value= const_cast("ALL");
+  }
+  else
+  {
+    /* 10 is enough assuming errors are max 4 digits */
+    int i;
+    var->value= buff;
+    for (i= 1;
+         i < MAX_SLAVE_ERROR &&
+         (buff - var->value) < SHOW_VAR_FUNC_BUFF_SIZE;
+         i++)
+    {
+      if (bitmap_is_set(&slave_error_mask, i))
+      {
+        buff= int10_to_str(i, buff, 10);
+        *buff++= ',';
+      }
+    }
+    if (var->value != buff)
+      buff--;				// Remove last ','
+    if (i < MAX_SLAVE_ERROR)
+      buff= strmov(buff, "...");  // Couldn't show all errors
+    *buff=0;
+  }
+  return 0;
+}
+#endif /* HAVE_REPLICATION */
 
 
 /*

From 5a75f865c2b70c8ea72d2fa4c344ed395c4ab4a4 Mon Sep 17 00:00:00 2001
From: "holyfoot@deer.(none)" <>
Date: Fri, 28 Apr 2006 09:07:25 +0500
Subject: [PATCH 072/108] bug #18115 (mysql_upgrade on Windows) pushed in 5.0

---
 VC++Files/client/mysql_upgrade.dsp      | 124 ++++++++
 VC++Files/client/mysql_upgrade.vcproj   | 232 ++++++++++++++
 VC++Files/client/mysql_upgrade_ia64.dsp | 124 ++++++++
 VC++Files/mysql.dsw                     |  21 ++
 VC++Files/mysql.sln                     |   8 +
 VC++Files/mysql_ia64.dsw                |  18 ++
 client/Makefile.am                      |   6 +-
 client/mysql_upgrade.c                  | 400 ++++++++++++++++++++++++
 8 files changed, 932 insertions(+), 1 deletion(-)
 create mode 100644 VC++Files/client/mysql_upgrade.dsp
 create mode 100644 VC++Files/client/mysql_upgrade.vcproj
 create mode 100644 VC++Files/client/mysql_upgrade_ia64.dsp
 create mode 100644 client/mysql_upgrade.c

diff --git a/VC++Files/client/mysql_upgrade.dsp b/VC++Files/client/mysql_upgrade.dsp
new file mode 100644
index 00000000000..28eb2a58f39
--- /dev/null
+++ b/VC++Files/client/mysql_upgrade.dsp
@@ -0,0 +1,124 @@
+# Microsoft Developer Studio Project File - Name="mysql_upgrade" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Console Application" 0x0103
+
+CFG=mysql_upgrade - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "mysql_upgrade.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "mysql_upgrade.mak" CFG="mysql_upgrade - Win32 Debug"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "mysql_upgrade - Win32 Release" (based on "Win32 (x86) Console Application")
+!MESSAGE "mysql_upgrade - Win32 Debug" (based on "Win32 (x86) Console Application")
+!MESSAGE "mysql_upgrade - Win32 classic" (based on "Win32 (x86) Console Application")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=xicl6.exe
+RSC=rc.exe
+
+!IF  "$(CFG)" == "mysql_upgrade - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "release"
+# PROP Intermediate_Dir "release"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /G6 /MT /W3 /O2 /I "../include" /I "../" /D "DBUG_OFF" /D "_CONSOLE" /D "_MBCS" /D "_WINDOWS" /D "NDEBUG" /FD /c
+# SUBTRACT CPP /YX
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=xilink6.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 mysqlclient.lib mysys.lib wsock32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib zlib.lib ..\extra\yassl\Release\yassl.lib /nologo /subsystem:console /machine:I386 /out:"../client_release/mysql_upgrade.exe" /libpath:"..\lib_release\\"
+# SUBTRACT LINK32 /incremental:yes
+
+!ELSEIF  "$(CFG)" == "mysql_upgrade - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "mysqlimp"
+# PROP BASE Intermediate_Dir "mysqlimp"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "debug"
+# PROP Intermediate_Dir "debug"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /G6 /MTd /W3 /Z7 /Od /I "../include" /I "../" /D "_DEBUG" /D "SAFEMALLOC" /D "SAFE_MUTEX" /D "_CONSOLE" /D "_MBCS" /D "_WINDOWS" /FD /c
+# SUBTRACT CPP /YX
+# ADD BASE RSC /l 0x409 /d "_DEBUG"
+# ADD RSC /l 0x409 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=xilink6.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 mysqlclient.lib mysys.lib wsock32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib zlib.lib setargv.obj ..\extra\yassl\Debug\yassl.lib /nologo /subsystem:console /incremental:no /debug /machine:I386 /out:"../client_debug/mysql_upgrade.exe" /pdbtype:sept /libpath:"..\lib_debug\\"
+
+!ELSEIF  "$(CFG)" == "mysql_upgrade - Win32 classic"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "mysql_upgrade___Win32_classic"
+# PROP BASE Intermediate_Dir "mysql_upgrade___Win32_classic"
+# PROP BASE Ignore_Export_Lib 0
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "classic"
+# PROP Intermediate_Dir "classic"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /G6 /MT /W3 /O2 /I "../include" /I "../" /D "DBUG_OFF" /D "_CONSOLE" /D "_MBCS" /D "_WINDOWS" /D "NDEBUG"  /FD /c
+# SUBTRACT BASE CPP /YX
+# ADD CPP /nologo /G6 /MT /W3 /O2 /I "../include" /I "../" /D "_CONSOLE" /D "_WINDOWS" /D LICENSE=Commercial /D "DBUG_OFF" /D "_MBCS" /D "NDEBUG" /FD  /c
+# SUBTRACT CPP /YX
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=xilink6.exe
+# ADD BASE LINK32 mysqlclient.lib mysys.lib wsock32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:"../client_release/mysql_upgrade.exe" /libpath:"..\lib_release\\"
+# SUBTRACT BASE LINK32 /incremental:yes
+# ADD LINK32 mysqlclient.lib mysys.lib wsock32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib zlib.lib ..\extra\yassl\Release\yassl.lib /nologo /subsystem:console /machine:I386 /out:"../client_classic/mysql_upgrade.exe" /libpath:"..\lib_release\\"
+# SUBTRACT LINK32 /incremental:yes
+
+!ENDIF
+
+# Begin Target
+
+# Name "mysql_upgrade - Win32 Release"
+# Name "mysql_upgrade - Win32 Debug"
+# Name "mysql_upgrade - Win32 classic"
+# Begin Source File
+
+SOURCE=.\mysql_upgrade.c
+# End Source File
+# End Target
+# End Project
diff --git a/VC++Files/client/mysql_upgrade.vcproj b/VC++Files/client/mysql_upgrade.vcproj
new file mode 100644
index 00000000000..38cae600a75
--- /dev/null
+++ b/VC++Files/client/mysql_upgrade.vcproj
@@ -0,0 +1,232 @@
+
+
+	
+		
+	
+	
+		
+			
+			
+			
+			
+			
+			
+			
+			
+			
+			
+			
+			
+			
+		
+		
+			
+			
+			
+			
+			
+			
+			
+			
+			
+			
+			
+			
+			
+		
+		
+			
+			
+			
+			
+			
+			
+			
+			
+			
+			
+			
+			
+			
+		
+	
+	
+	
+	
+		
+			
+				
+			
+			
+				
+			
+			
+				
+			
+		
+	
+	
+	
+
diff --git a/VC++Files/client/mysql_upgrade_ia64.dsp b/VC++Files/client/mysql_upgrade_ia64.dsp
new file mode 100644
index 00000000000..5cb42ba0224
--- /dev/null
+++ b/VC++Files/client/mysql_upgrade_ia64.dsp
@@ -0,0 +1,124 @@
+# Microsoft Developer Studio Project File - Name="mysql_upgrade" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Console Application" 0x0103
+
+CFG=mysql_upgrade - WinIA64 classic
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE 
+!MESSAGE NMAKE /f "mysql_upgrade_ia64.mak".
+!MESSAGE 
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE 
+!MESSAGE NMAKE /f "mysql_upgrade_ia64.mak" CFG="mysql_upgrade - WinIA64 classic"
+!MESSAGE 
+!MESSAGE Possible choices for configuration are:
+!MESSAGE 
+!MESSAGE "mysql_upgrade - WinIA64 Release" (based on "Win32 (x86) Console Application")
+!MESSAGE "mysql_upgrade - WinIA64 Debug" (based on "Win32 (x86) Console Application")
+!MESSAGE "mysql_upgrade - WinIA64 classic" (based on "Win32 (x86) Console Application")
+!MESSAGE 
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF  "$(CFG)" == "mysql_upgrade - WinIA64 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "release"
+# PROP Intermediate_Dir "release"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+MTL=midl.exe
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN64" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /MT /W3 /Zi /O2 /I "../include" /I "../" /D "DBUG_OFF" /D "_CONSOLE" /D "_MBCS" /D "_WINDOWS" /D "NDEBUG" /D "_IA64_" /D "WIN64" /D "WIN32" /D "_AFX_NO_DAO_SUPPORT" /FD /G2 /EHsc /Wp64 /Zm600 /c
+# SUBTRACT CPP /YX
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console  /machine:IA64
+# ADD LINK32 ..\lib_release\zlib.lib mysqlclient.lib wsock32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib bufferoverflowU.lib zlib.lib /nologo /subsystem:console  /out:"../client_release/mysql_upgrade.exe" /libpath:"..\lib_release\\" /machine:IA64
+
+!ELSEIF  "$(CFG)" == "mysql_upgrade - WinIA64 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "mysqlimp"
+# PROP BASE Intermediate_Dir "mysqlimp"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "debug"
+# PROP Intermediate_Dir "debug"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+MTL=midl.exe
+# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN64" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /MTd /W3 /Zi /Od /I "../include" /I "../" /D "_DEBUG" /D "SAFEMALLOC" /D "SAFE_MUTEX" /D "_CONSOLE" /D "_MBCS" /D "_WINDOWS" /D "_IA64_" /D "WIN64" /D "WIN32" /D "_AFX_NO_DAO_SUPPORT" /FD /G2 /EHsc /Wp64 /Zm600 /c
+# SUBTRACT CPP /YX
+# ADD BASE RSC /l 0x409 /d "_DEBUG"
+# ADD RSC /l 0x409 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug  /machine:IA64
+# ADD LINK32 setargv.obj ..\lib_debug\zlib.lib ..\lib_debug\dbug.lib mysqlclient.lib wsock32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib bufferoverflowU.lib zlib.lib /nologo /subsystem:console /incremental:no /debug  /out:"../client_debug/mysql_upgrade.exe" /libpath:"..\lib_debug\\" /machine:IA64
+
+!ELSEIF  "$(CFG)" == "mysql_upgrade - WinIA64 classic"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "mysql_upgrade___WinIA64_classic"
+# PROP BASE Intermediate_Dir "mysql_upgrade___WinIA64_classic"
+# PROP BASE Ignore_Export_Lib 0
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "classic"
+# PROP Intermediate_Dir "classic"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+MTL=midl.exe
+# ADD BASE CPP /nologo /G6 /MT /W3 /O2 /I "../include" /I "../" /D "DBUG_OFF" /D "_CONSOLE" /D "_MBCS" /D "_WINDOWS" /D "NDEBUG" /FD /c
+# SUBTRACT BASE CPP /YX
+# ADD CPP /nologo /MT /W3 /Zi /O2 /I "../include" /I "../" /D "_CONSOLE" /D "_WINDOWS" /D LICENSE=Commercial /D "DBUG_OFF" /D "_MBCS" /D "NDEBUG" /D "_IA64_" /D "WIN64" /D "WIN32" /D "_AFX_NO_DAO_SUPPORT" /FD /G2 /EHsc /Wp64 /Zm600 /c
+# SUBTRACT CPP /YX
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 mysqlclient.lib wsock32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console  /out:"../client_release/mysql_upgrade.exe" /libpath:"..\lib_release\\" /machine:IA64
+# ADD LINK32 ..\lib_release\zlib.lib mysqlclient.lib wsock32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib bufferoverflowU.lib zlib.lib /nologo /subsystem:console  /out:"../client_classic/mysql_upgrade.exe" /libpath:"..\lib_release\\" /machine:IA64
+
+!ENDIF 
+
+# Begin Target
+
+# Name "mysql_upgrade - WinIA64 Release"
+# Name "mysql_upgrade - WinIA64 Debug"
+# Name "mysql_upgrade - WinIA64 classic"
+# Begin Source File
+
+SOURCE=.\mysql_upgrade.c
+# End Source File
+# End Target
+# End Project
diff --git a/VC++Files/mysql.dsw b/VC++Files/mysql.dsw
index b1d09552705..911b895c1ad 100644
--- a/VC++Files/mysql.dsw
+++ b/VC++Files/mysql.dsw
@@ -423,6 +423,9 @@ Package=<4>
     Project_Dep_Name mysqlimport
     End Project Dependency
     Begin Project Dependency
+    Project_Dep_Name mysql_upgrade
+    End Project Dependency
+    Begin Project Dependency
     Project_Dep_Name mysqlshow
     End Project Dependency
     Begin Project Dependency
@@ -507,6 +510,24 @@ Package=<4>
 
 ###############################################################################
 
+Project: "mysql_upgrade"=".\client\mysql_upgade.dsp" - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+    Begin Project Dependency
+    Project_Dep_Name mysqlclient
+    End Project Dependency
+    Begin Project Dependency
+    Project_Dep_Name mysys
+    End Project Dependency
+}}}
+
+###############################################################################
+
 Project: "mysqlserver"=".\mysqlserver\mysqlserver.dsp" - Package Owner=<4>
 
 Package=<5>
diff --git a/VC++Files/mysql.sln b/VC++Files/mysql.sln
index 083ddef96ed..14f16f8fd8d 100644
--- a/VC++Files/mysql.sln
+++ b/VC++Files/mysql.sln
@@ -174,6 +174,14 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mysqlimport", "client\mysql
 		{44D9C7DC-6636-4B82-BD01-6876C64017DF} = {44D9C7DC-6636-4B82-BD01-6876C64017DF}
 	EndProjectSection
 EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mysql_upgrade", "client\mysql_upgrade.vcproj", "{AD95DAD3-6DB9-4F8B-A345-7A39A83AAD3D}"
+	ProjectSection(ProjectDependencies) = postProject
+		{BA86AE72-0CF5-423D-BBA2-E12B0D72EBFB} = {BA86AE72-0CF5-423D-BBA2-E12B0D72EBFB}
+		{26383276-4843-494B-8BE0-8936ED3EBAAB} = {26383276-4843-494B-8BE0-8936ED3EBAAB}
+		{8762A9B8-72A9-462E-A9A2-F3265081F8AF} = {8762A9B8-72A9-462E-A9A2-F3265081F8AF}
+		{44D9C7DC-6636-4B82-BD01-6876C64017DF} = {44D9C7DC-6636-4B82-BD01-6876C64017DF}
+	EndProjectSection
+EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mysqlserver", "mysqlserver\mysqlserver.vcproj", "{94B86159-C581-42CD-825D-C69CBC237E5C}"
 	ProjectSection(ProjectDependencies) = postProject
 		{EEC1300B-85A5-497C-B3E1-F708021DF859} = {EEC1300B-85A5-497C-B3E1-F708021DF859}
diff --git a/VC++Files/mysql_ia64.dsw b/VC++Files/mysql_ia64.dsw
index 3b588deee61..add59f8b471 100644
--- a/VC++Files/mysql_ia64.dsw
+++ b/VC++Files/mysql_ia64.dsw
@@ -508,6 +508,9 @@ Package=<4>
     Project_Dep_Name mysqlimport
     End Project Dependency
     Begin Project Dependency
+    Project_Dep_Name mysql_upgrade
+    End Project Dependency
+    Begin Project Dependency
     Project_Dep_Name mysqlshow
     End Project Dependency
     Begin Project Dependency
@@ -580,6 +583,21 @@ Package=<4>
 
 ###############################################################################
 
+Project: "mysql_upgrade"=".\client\mysql_upgrade_ia64.dsp" - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+    Begin Project Dependency
+    Project_Dep_Name mysqlclient
+    End Project Dependency
+}}}
+
+###############################################################################
+
 Project: "mysqlserver"=".\mysqlserver\mysqlserver_ia64.dsp" - Package Owner=<4>
 
 Package=<5>
diff --git a/client/Makefile.am b/client/Makefile.am
index 2c513d3d7c7..9d133125a0d 100644
--- a/client/Makefile.am
+++ b/client/Makefile.am
@@ -31,6 +31,7 @@ LDADD=				@CLIENT_EXTRA_LDFLAGS@ \
                                 $(top_builddir)/libmysql/libmysqlclient.la
 bin_PROGRAMS =			mysql mysqladmin mysqlcheck mysqlshow \
 				mysqldump mysqlimport mysqltest mysqlbinlog \
+				mysql_upgrade \
 				mysqltestmanagerc mysqltestmanager-pwgen
 noinst_HEADERS =		sql_string.h completion_hash.h my_readline.h \
 				client_priv.h
@@ -48,11 +49,14 @@ mysqlcheck_SOURCES=             mysqlcheck.c $(yassl_dummy_link_fix)
 mysqlshow_SOURCES=              mysqlshow.c $(yassl_dummy_link_fix)
 mysqldump_SOURCES=              mysqldump.c my_user.c $(yassl_dummy_link_fix)
 mysqlimport_SOURCES=            mysqlimport.c $(yassl_dummy_link_fix)
+mysql_upgrade_SOURCES=          mysql_upgrade.c $(yassl_dummy_link_fix)
 sql_src=log_event.h mysql_priv.h log_event.cc my_decimal.h my_decimal.cc
 strings_src=decimal.c
 
 # Fix for mit-threads
-DEFS =			-DUNDEF_THREADS_HACK
+DEFS =			-DUNDEF_THREADS_HACK \
+			-DDEFAULT_MYSQL_HOME="\"$(prefix)\"" \
+			-DDATADIR="\"$(localstatedir)\"" 
 
 link_sources:
 	for f in $(sql_src) ; do \
diff --git a/client/mysql_upgrade.c b/client/mysql_upgrade.c
new file mode 100644
index 00000000000..78e4acd4c1d
--- /dev/null
+++ b/client/mysql_upgrade.c
@@ -0,0 +1,400 @@
+/* Copyright (C) 2000 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; either version 2 of the License, or
+   (at your option) any later version.
+
+   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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
+
+#include "client_priv.h"
+#include 
+
+static my_bool opt_force= 0, opt_verbose= 0, tty_password= 0;
+static char *user= (char*) "root", *basedir= 0, *datadir= 0, *opt_password= 0;
+static my_bool upgrade_defaults_created= 0;
+static my_string opt_mysql_port, opt_mysql_unix_port= 0;
+static char *default_dbug_option= (char*) "d:t:O,/tmp/comp_err.trace";
+static my_bool info_flag= 0;
+
+static struct my_option my_long_options[]=
+{
+  {"help", '?', "Display this help message and exit.", 0, 0, 0, GET_NO_ARG,
+   NO_ARG, 0, 0, 0, 0, 0, 0},
+  {"basedir", 'b', "Specifies the directory where MySQL is installed",
+   (gptr*) &basedir,
+   (gptr*) &basedir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
+  {"datadir", 'd', "Specifies the data directory", (gptr*) &datadir,
+   (gptr*) &datadir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
+#ifdef DBUG_OFF
+  {"debug", '#', "This is a non-debug version. Catch this and exit",
+   0, 0, 0, GET_DISABLED, OPT_ARG, 0, 0, 0, 0, 0, 0},
+#else
+  {"debug", '#', "Output debug log", (gptr *) & default_dbug_option,
+   (gptr *) & default_dbug_option, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
+#endif
+  {"debug-info", 'T', "Print some debug info at exit.", (gptr *) & info_flag,
+   (gptr *) & info_flag, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
+  {"force", 'f', "Continue even if we get an sql-error.",
+   (gptr*) &opt_force, (gptr*) &opt_force, 0, GET_BOOL, NO_ARG, 0, 0,
+   0, 0, 0, 0},
+  {"password", 'p',
+   "Password to use when connecting to server. If password is not given it's solicited on the tty.",
+   0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
+  {"port", 'P', "Port number to use for connection.", (gptr*) &opt_mysql_port,
+   (gptr*) &opt_mysql_port, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0,
+   0},
+  {"protocol", OPT_MYSQL_PROTOCOL,
+   "The protocol of connection (tcp,socket,pipe,memory).",
+   0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
+  {"socket", 'S', "Socket file to use for connection.",
+   (gptr*) &opt_mysql_unix_port, (gptr*) &opt_mysql_unix_port, 0, GET_STR,
+   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
+  {"user", 'u', "User for login if not current user.", (gptr*) &user,
+   (gptr*) &user, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
+  {"verbose", 'v', "Display more output about the process", (gptr*) &opt_verbose,
+    (gptr *) &opt_verbose, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
+  {0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
+};
+static const char *load_default_groups[]=
+{
+  "mysql_upgrade", "client", 0
+};
+
+#include 
+
+static my_bool
+get_one_option(int optid, const struct my_option *opt __attribute__ ((unused)),
+               char *argument)
+{
+  switch (optid) {
+  case '?':
+    puts
+      ("MySQL utility script to upgrade database to the current server version");
+    puts("");
+    my_print_help(my_long_options);
+    exit(0);
+  case '#':
+    DBUG_PUSH(argument ? argument : default_dbug_option);
+    break;
+  case 'f':
+    opt_force= TRUE;
+    break;
+  case 'p':
+    tty_password= 1;
+    if (argument)
+    {
+      char *start= argument;
+      my_free(opt_password, MYF(MY_ALLOW_ZERO_PTR));
+      opt_password= my_strdup(argument, MYF(MY_FAE));
+      while (*argument)
+        *argument++= 'x';                       /* Destroy argument */
+      if (*start)
+        start[1]= 0;                            /* Cut length of argument */
+      tty_password= 0;
+    }
+    break;
+  default:;
+  };
+  return 0;
+}
+
+
+/* buffer should be not smaller than FN_REFLEN */
+static my_bool test_file_exists_res(const char *dir, const char *fname,
+                                    char *buffer, char **buf_end)
+{
+  MY_STAT stat_info;
+
+  *buf_end= strxnmov(buffer, FN_REFLEN-1, dir, "/", fname, NullS);
+  unpack_filename(buffer, buffer);
+  return my_stat(buffer, &stat_info, MYF(0)) != 0;
+}
+
+
+static my_bool test_file_exists(const char *dir, const char *fname)
+{
+  char path[FN_REFLEN];
+  char *path_end;
+  return test_file_exists_res(dir, fname, path, &path_end);
+}
+
+
+static int create_check_file(const char *path)
+{
+  File check_file= my_open(path, O_CREAT | O_WRONLY, MYF(MY_FAE | MY_WME));
+  int error;
+
+  if (check_file < 0)
+    return 1;
+
+  error= my_write(check_file, VERSION, strlen(VERSION), MYF(MY_WME | MY_FNABP));
+  error= my_close(check_file, MYF(MY_FAE | MY_WME)) || error;
+  return error;
+}
+
+
+static int create_defaults_file(const char *path, const char *our_defaults_path)
+{
+  uint b_read;
+  File our_defaults_file, defaults_file;
+  char buffer[512];
+  char *buffer_end;
+  int error;
+
+  /* check if the defaults file is needed at all */
+  if (!opt_password)
+    return 0;
+
+  defaults_file= my_open(path, O_BINARY | O_CREAT | O_WRONLY,
+                         MYF(MY_FAE | MY_WME));
+
+  if (defaults_file < 0)
+    return 1;
+  upgrade_defaults_created= 1;
+  if (our_defaults_path)
+  {
+    our_defaults_file= my_open(our_defaults_path, O_RDONLY,
+                               MYF(MY_FAE | MY_WME));
+    if (our_defaults_file < 0)
+      return 1;
+    do
+    {
+      if (((b_read= my_read(our_defaults_file, buffer,
+                            sizeof(buffer), MYF(MY_WME))) == MY_FILE_ERROR) ||
+          my_write(defaults_file, buffer, b_read, MYF(MY_FNABP | MY_WME)))
+      {
+        error= 1;
+        goto close_return;
+      }
+    } while (b_read == sizeof(buffer));
+  }
+  buffer_end= strnmov(buffer, "\n[client]", sizeof(buffer));
+  if (opt_password)
+    buffer_end= strxnmov(buffer, sizeof(buffer),
+                         "\npassword=", opt_password, NullS);
+  error= my_write(defaults_file, buffer, (int) (buffer_end - buffer),
+                  MYF(MY_WME | MY_FNABP));
+close_return:
+  return my_close(defaults_file, MYF(MY_WME)) || error;
+}
+
+
+int main(int argc, char **argv)
+{
+  char bindir[FN_REFLEN];
+  char *bindir_end, *buf_end;
+  char datadir_buf[FN_REFLEN];
+  char mysqlcheck_line[FN_REFLEN], *mysqlcheck_end;
+  char check_file_name[FN_REFLEN];
+  int check_file;
+  char fix_priv_tables_cmd[FN_REFLEN], *fix_cmd_end;
+  char script_line[FN_REFLEN];
+  int error;
+  char *forced_defaults_file;
+  char *forced_extra_defaults;
+  char *defaults_group_suffix;
+  char upgrade_defaults_path[FN_REFLEN], *defaults_to_use= 0;
+  char port_socket[100], *port_socket_end;
+
+  MY_INIT(argv[0]);
+#ifdef __NETWARE__
+  setscreenmode(SCR_AUTOCLOSE_ON_EXIT);
+#endif
+
+  load_defaults("my", load_default_groups, &argc, &argv);
+
+  if ((error= handle_options(&argc, &argv, my_long_options, get_one_option)))
+    exit(error);
+
+  if (tty_password)
+    opt_password= get_tty_password(NullS);
+
+  /* Check if we want to force the use a specific default file */
+  get_defaults_options(argc, argv,
+                       &forced_defaults_file, &forced_extra_defaults,
+                       &defaults_group_suffix);
+
+  port_socket_end= port_socket;
+  if (opt_mysql_port)
+    port_socket_end= strxnmov(port_socket, sizeof(port_socket) - 1, " --port=",
+                              opt_mysql_port, NullS);
+  if (opt_mysql_unix_port)
+    port_socket_end= strxnmov(port_socket_end,
+                              sizeof(port_socket) -
+                                (int)(port_socket_end - port_socket) - 1,
+                              " --socket=", opt_mysql_unix_port, NullS);
+  *port_socket_end= 0;
+
+  if (basedir)
+  {
+    bindir_end= strmake(bindir, basedir, sizeof(bindir)-1);
+  }
+  else
+  {
+    if (test_file_exists("./share/mysql/english", "errmsg.sys")
+        && (test_file_exists("./bin", "mysqld") ||
+            test_file_exists("./libexec", "mysqld")))
+    {
+      getcwd(bindir, sizeof(bindir));
+      bindir_end= bindir + strlen(bindir);
+    }
+    else
+    {
+      bindir_end= strmake(bindir, DEFAULT_MYSQL_HOME, sizeof(bindir)-1);
+    }
+  }
+
+  if (!datadir)
+  {
+    datadir= datadir_buf;
+    if (test_file_exists(bindir, "data/mysql"))
+    {
+      *strxnmov(datadir_buf, sizeof(datadir_buf)-1, bindir, "/data", NullS)= 0;
+    }
+    else if (test_file_exists(bindir, "var/mysql"))
+    {
+      *strxnmov(datadir_buf, sizeof(datadir_buf)-1, bindir, "/var", NullS)= 0;
+    }
+    else
+      datadir= (char*) DATADIR;
+  }
+
+  strmake(bindir_end, "/bin", sizeof(bindir) - (int) (bindir_end - bindir)-1);
+
+  if (!test_file_exists_res
+      (bindir, "mysqlcheck", mysqlcheck_line, &mysqlcheck_end))
+  {
+    printf("Can't find program '%s'\n", mysqlcheck_line);
+    puts("Please restart with --basedir=mysql-install-directory");
+    exit(1);
+  }
+
+  if (!test_file_exists(datadir, "mysql/user.frm"))
+  {
+    puts
+      ("Can't find data directory. Please restart with --datadir=path-to-data-dir");
+    exit(1);
+  }
+
+  /* create the modified defaults file to be used by mysqlcheck */
+  /* and mysql tools                                            */
+  *strxnmov(upgrade_defaults_path, sizeof(upgrade_defaults_path)-1,
+           datadir, "/upgrade_defaults", NullS)= 0;
+  unpack_filename(upgrade_defaults_path, upgrade_defaults_path);
+  if ((error=
+       create_defaults_file(upgrade_defaults_path, forced_extra_defaults)))
+    goto err_exit;
+
+  defaults_to_use= upgrade_defaults_created ?
+    upgrade_defaults_path : forced_extra_defaults;
+
+  if (test_file_exists_res(datadir, "mysql_upgrade_info", check_file_name,
+                           &buf_end) && !opt_force)
+  {
+    char chf_buffer[50];
+    int b_read;
+    check_file= my_open(check_file_name, O_RDONLY, MYF(0));
+    b_read= my_read(check_file, chf_buffer, sizeof(chf_buffer)-1, MYF(0));
+    chf_buffer[b_read]= 0;
+    my_close(check_file, MYF(0));
+    if (!strcmp(chf_buffer, VERSION))
+    {
+      if (opt_verbose)
+        puts("mysql_upgrade already done for this version");
+      goto fix_priv_tables;
+    }
+  }
+
+  if (defaults_to_use)
+  {
+    mysqlcheck_end= strxnmov(mysqlcheck_end,
+                             sizeof(mysqlcheck_line) - (int) (mysqlcheck_end -
+                                                              mysqlcheck_line),
+                             " --defaults-extra-file=", defaults_to_use,NullS);
+  }
+
+  mysqlcheck_end= strxnmov(mysqlcheck_end,
+                           sizeof(mysqlcheck_line) -
+                             (int) (mysqlcheck_end - mysqlcheck_line - 1),
+                           " --check-upgrade --all-databases --auto-repair --user=",
+                           user, port_socket, NullS);
+  *mysqlcheck_end= 0;
+
+  if (opt_verbose)
+    printf("Running %s\n", mysqlcheck_line);
+  if ((error= system(mysqlcheck_line)))
+  {
+    printf("Error executing '%s'\n", mysqlcheck_line);
+    goto err_exit;
+  }
+
+  if ((error= create_check_file(check_file_name)))
+    goto err_exit;
+
+fix_priv_tables:
+  if (!test_file_exists_res(bindir, "mysql", fix_priv_tables_cmd, &fix_cmd_end))
+  {
+    puts("Could not find MySQL command-line client (mysql).");
+    puts
+      ("Please use --basedir to specify the directory where MySQL is installed.");
+    error= 1;
+    goto err_exit;
+  }
+
+  if (!test_file_exists_res(basedir,
+                            "support_files/mysql_fix_privilege_tables.sql",
+                            script_line, &buf_end)
+      && !test_file_exists_res(basedir, "share/mysql_fix_privilege_tables.sql",
+                               script_line, &buf_end)
+      && !test_file_exists_res(basedir,
+                               "share/mysql/mysql_fix_privilege_tables.sql",
+                               script_line, &buf_end)
+      && !test_file_exists_res(basedir,
+                               "scripts/mysql_fix_privilege_tables.sql",
+                               script_line, &buf_end)
+      && !test_file_exists_res("/usr/local/mysql/share/mysql",
+                               "mysql_fix_privilege_tables.sql", script_line,
+                               &buf_end))
+  {
+    puts("Could not find file mysql_fix_privilege_tables.sql");
+    puts
+      ("Please use --basedir to specify the directory where MySQL is installed");
+    error= 1;
+    goto err_exit;
+  }
+
+  if (defaults_to_use)
+  {
+    fix_cmd_end= strxnmov(fix_cmd_end,
+                          sizeof(fix_priv_tables_cmd) -
+                            (int) (fix_cmd_end - fix_priv_tables_cmd - 1),
+                          " --defaults-extra-file=", defaults_to_use, NullS);
+  }
+  fix_cmd_end= strxnmov(fix_cmd_end,
+           sizeof(fix_priv_tables_cmd) - (int) (fix_cmd_end -
+                                                fix_priv_tables_cmd),
+           " --user=", user, port_socket, " mysql < ", script_line, NullS);
+  *fix_cmd_end= 0;
+
+  if ((error= system(fix_priv_tables_cmd)))
+  {
+    /* Problem is that the 'Duplicate column' error           */
+    /* which is not a bug for the script makes 'mysql' return */
+    /* an error                                               */
+    /* printf("Error executing '%s'\n", fix_priv_tables_cmd); */
+  }
+
+err_exit:
+  if (upgrade_defaults_created)
+    my_delete(upgrade_defaults_path, MYF(0));
+  my_end(info_flag ? MY_CHECK_ERROR | MY_GIVE_INFO : 0);
+  return error;
+}                                               /* main */

From 6c2f477259eb01019530c725a9128a5360d003dd Mon Sep 17 00:00:00 2001
From: "knielsen@mysql.com" <>
Date: Fri, 28 Apr 2006 09:29:40 +0200
Subject: [PATCH 073/108] Disable unstable test case.

---
 mysql-test/t/disabled.def | 1 +
 1 file changed, 1 insertion(+)

diff --git a/mysql-test/t/disabled.def b/mysql-test/t/disabled.def
index 41776f0b5ec..d92aed1d1a2 100644
--- a/mysql-test/t/disabled.def
+++ b/mysql-test/t/disabled.def
@@ -15,6 +15,7 @@ events                   : BUG#17619 2006-02-21 andrey  Race conditions
 events_scheduling        : BUG#19170 2006-04-26 andrey  Test case of 19170 fails on some platforms. Has to be checked.
 ndb_autodiscover         : BUG#18952 2006-02-16 jmiller Needs to be fixed w.r.t binlog
 ndb_autodiscover2        : BUG#18952 2006-02-16 jmiller Needs to be fixed w.r.t binlog
+ndb_binlog_discover      : BUG#19395 2006-04-28 tomas/knielsen mysqld does not always detect cluster shutdown
 #ndb_cache2               : BUG#18597 2006-03-28 brian simultaneous drop table and ndb statistics update triggers node failure
 #ndb_cache_multi2         : BUG#18597 2006-04-10 kent  simultaneous drop table and ndb statistics update triggers node failure
 partition_03ndb          : BUG#16385 2006-03-24 mikael Partitions: crash when updating a range partitioned NDB table

From ca79343359b2da6b03c3f35df3d52f2ce3607eab Mon Sep 17 00:00:00 2001
From: "gkodinov@lsmy3.wdf.sap.corp" <>
Date: Fri, 28 Apr 2006 11:23:31 +0200
Subject: [PATCH 074/108] BUG#18492: mysqld reports ER_ILLEGAL_REFERENCE in
 --ps-protocol

In the code that converts IN predicates to EXISTS predicates it is changing
the select list elements to constant 1. Example :
SELECT ... FROM ...  WHERE a IN (SELECT c FROM ...)
is transformed to :
SELECT ... FROM ... WHERE EXISTS (SELECT 1 FROM ...  HAVING a = c)
However there can be no FROM clause in the IN subquery and it may not be
a simple select : SELECT ... FROM ... WHERE a IN (SELECT f(..) AS
c UNION SELECT ...) This query is transformed to : SELECT ... FROM ...
WHERE EXISTS (SELECT 1 FROM (SELECT f(..) AS c UNION SELECT ...)
x HAVING a = c) In the above query c in the HAVING clause is made to be
an Item_null_helper (a subclass of Item_ref) pointing to the real
Item_field (which is not referenced anywhere else in the query anymore).
This is done because Item_ref_null_helper collects information whether
there are NULL values in the result.  This is OK for directly executed
statements, because the Item_field pointed by the Item_null_helper is
already fixed when the transformation is done.  But when executed as
a prepared statement all the Item instances are "un-fixed" before the
recompilation of the prepared statement. So when the Item_null_helper
gets fixed it discovers that the Item_field it points to is not fixed
and issues an error.  The remedy is to keep the original select list
references when there are no tables in the FROM clause. So the above
becomes : SELECT ... FROM ...  WHERE EXISTS (SELECT c FROM (SELECT f(..)
AS c UNION SELECT ...) x HAVING a = c) In this way c is referenced
directly in the select list as well as by reference in the HAVING
clause. So it gets correctly fixed even with prepared statements.  And
since the Item_null_helper subclass of Item_ref_null_helper is not used
anywhere else it's taken out.
---
 mysql-test/r/ps_11bugs.result | 14 ++++++++++++++
 mysql-test/r/subselect.result |  2 +-
 mysql-test/t/ps_11bugs.test   | 14 ++++++++++++++
 sql/item.cc                   |  8 --------
 sql/item.h                    | 13 -------------
 sql/item_subselect.cc         | 16 +++++++++-------
 6 files changed, 38 insertions(+), 29 deletions(-)

diff --git a/mysql-test/r/ps_11bugs.result b/mysql-test/r/ps_11bugs.result
index c0d7fe502af..c849c25d646 100644
--- a/mysql-test/r/ps_11bugs.result
+++ b/mysql-test/r/ps_11bugs.result
@@ -116,3 +116,17 @@ execute st_1676 using @arg0, @arg1, @arg2;
 cola	colb	cold
 aaaa	yyyy	R
 drop table t1, t2;
+create table t1 (a int primary key);
+insert into t1 values (1);
+explain select * from t1 where 3 in (select (1+1) union select 1);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
+2	DEPENDENT SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
+3	DEPENDENT UNION	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
+NULL	UNION RESULT		ALL	NULL	NULL	NULL	NULL	NULL	
+select * from t1 where 3 in (select (1+1) union select 1);
+a
+prepare st_18492 from 'select * from t1 where 3 in (select (1+1) union select 1)';
+execute st_18492;
+a
+drop table t1;
diff --git a/mysql-test/r/subselect.result b/mysql-test/r/subselect.result
index 500aa4b1728..7925715a8b7 100644
--- a/mysql-test/r/subselect.result
+++ b/mysql-test/r/subselect.result
@@ -734,7 +734,7 @@ id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
 3	DEPENDENT UNION	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
 NULL	UNION RESULT		ALL	NULL	NULL	NULL	NULL	NULL	
 Warnings:
-Note	1003	select test.t2.id AS `id` from test.t2 where (test.t2.id,(select 1 AS `Not_used` having ((test.t2.id) = (1)) union select 1 AS `Not_used` having ((test.t2.id) = (3))))
+Note	1003	select test.t2.id AS `id` from test.t2 where (test.t2.id,(select 1 AS `1` having ((test.t2.id) = (1)) union select 3 AS `3` having ((test.t2.id) = (3))))
 SELECT * FROM t2 WHERE id IN (SELECT 5 UNION SELECT 3);
 id
 SELECT * FROM t2 WHERE id IN (SELECT 5 UNION SELECT 2);
diff --git a/mysql-test/t/ps_11bugs.test b/mysql-test/t/ps_11bugs.test
index e214afeaaf3..ff1c87f3bd8 100644
--- a/mysql-test/t/ps_11bugs.test
+++ b/mysql-test/t/ps_11bugs.test
@@ -130,3 +130,17 @@ drop table t1, t2;
 # end of bug#1676
 
 # End of 4.1 tests
+
+# bug#18492: mysqld reports ER_ILLEGAL_REFERENCE in --ps-protocol
+
+create table t1 (a int primary key);
+insert into t1 values (1);
+
+explain select * from t1 where 3 in (select (1+1) union select 1);
+
+select * from t1 where 3 in (select (1+1) union select 1);
+
+prepare st_18492 from 'select * from t1 where 3 in (select (1+1) union select 1)';
+execute st_18492;
+
+drop table t1;
diff --git a/sql/item.cc b/sql/item.cc
index 5964ed388c6..7c9f6ec77fb 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -2716,14 +2716,6 @@ void Item_ref_null_helper::print(String *str)
 }
 
 
-void Item_null_helper::print(String *str)
-{
-  str->append("(", 14);
-  store->print(str);
-  str->append(')');
-}
-
-
 bool Item_default_value::eq(const Item *item, bool binary_cmp) const
 {
   return item->type() == DEFAULT_VALUE_ITEM && 
diff --git a/sql/item.h b/sql/item.h
index 1d01ce0d3f3..66da7ad4e74 100644
--- a/sql/item.h
+++ b/sql/item.h
@@ -1045,19 +1045,6 @@ public:
   }
 };
 
-class Item_null_helper :public Item_ref_null_helper
-{
-  Item *store;
-public:
-  Item_null_helper(Item_in_subselect* master, Item *item,
-		   const char *table_name_par, const char *field_name_par)
-    :Item_ref_null_helper(master, &item, table_name_par, field_name_par),
-     store(item)
-    { ref= &store; }
-  void print(String *str);
-};
-
-
 /*
   The following class is used to optimize comparing of date and bigint columns
   We need to save the original item ('ref') to be able to call
diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc
index c8405a9f8f4..8241a8e0402 100644
--- a/sql/item_subselect.cc
+++ b/sql/item_subselect.cc
@@ -822,13 +822,13 @@ Item_in_subselect::single_value_transformer(JOIN *join,
   }
   else
   {
-    select_lex->item_list.empty();
-    select_lex->item_list.push_back(new Item_int("Not_used",
-						 (longlong) 1, 21));
-    select_lex->ref_pointer_array[0]= select_lex->item_list.head();
     if (select_lex->table_list.elements)
     {
       Item *having= item, *orig_item= item;
+      select_lex->item_list.empty();
+      select_lex->item_list.push_back(new Item_int("Not_used",
+                                                   (longlong) 1, 21));
+      select_lex->ref_pointer_array[0]= select_lex->item_list.head();
       item= func->create(expr, item);
       if (!abort_on_null && orig_item->maybe_null)
       {
@@ -875,9 +875,11 @@ Item_in_subselect::single_value_transformer(JOIN *join,
 	select_lex->having=
 	  join->having=
 	  func->create(expr,
-		       new Item_null_helper(this, item,
-					    (char *)"",
-					    (char *)""));
+                       new Item_ref_null_helper(this,
+                                            select_lex->ref_pointer_array,
+                                            (char *)"",
+                                            (char *)""));
+
 	select_lex->having_fix_field= 1;
 	if (join->having->fix_fields(thd, join->tables_list,
 				     0))

From 50c920ffab6818336c5cb44067462c1a2f855407 Mon Sep 17 00:00:00 2001
From: "msvensson@neptunus.(none)" <>
Date: Fri, 28 Apr 2006 13:55:40 +0200
Subject: [PATCH 075/108] Bug#18818 configure: No longer finds OpenSSL on Mac
 OS X  - Eval shrext_cmds variable before using it  - Moved from acinclude.m4
 to openssl.m4 and zlib.m4 when merging 4.1 -> 5.0

---
 config/ac-macros/openssl.m4 | 5 +++--
 config/ac-macros/zlib.m4    | 3 ++-
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/config/ac-macros/openssl.m4 b/config/ac-macros/openssl.m4
index 1f9d53abe01..a23c46eed00 100644
--- a/config/ac-macros/openssl.m4
+++ b/config/ac-macros/openssl.m4
@@ -1,6 +1,7 @@
 AC_DEFUN([MYSQL_FIND_OPENSSL], [
   incs="$1"
   libs="$2"
+  eval shrexts=\"$shrext_cmds\"
   case "$incs---$libs" in
     ---)
       for d in /usr/ssl/include /usr/local/ssl/include /usr/include \
@@ -15,7 +16,7 @@ AC_DEFUN([MYSQL_FIND_OPENSSL], [
 /usr/lib /usr/lib64 /opt/ssl/lib /opt/openssl/lib \
 /usr/freeware/lib32 /usr/local/lib/ ; do
       # Just to be safe, we test for ".so" anyway
-      if test -f $d/libssl.a || test -f $d/libssl.so || test -f $d/libssl$shrext_cmds ; then
+      if test -f $d/libssl.a || test -f $d/libssl.so || test -f $d/libssl$shrext ; then
         OPENSSL_LIB=$d
       fi
       done
@@ -28,7 +29,7 @@ AC_DEFUN([MYSQL_FIND_OPENSSL], [
         OPENSSL_INCLUDE=-I$incs
       fi
       # Just to be safe, we test for ".so" anyway
-      if test -f $libs/libssl.a || test -f $libs/libssl.so || test -f $libs/libssl$shrext_cmds ; then
+      if test -f $libs/libssl.a || test -f $libs/libssl.so || test -f $libs/libssl$shrext ; then
         OPENSSL_LIB=$libs
       fi
       ;;
diff --git a/config/ac-macros/zlib.m4 b/config/ac-macros/zlib.m4
index a8c54c845a1..c75bac58d7c 100644
--- a/config/ac-macros/zlib.m4
+++ b/config/ac-macros/zlib.m4
@@ -90,8 +90,9 @@ case $SYSTEM_TYPE in
         ;;
       *)
         # Just to be safe, we test for ".so" anyway
+        eval shrexts=\"$shrext_cmds\"
         if test \( -f "$mysql_zlib_dir/lib/libz.a"  -o -f "$mysql_zlib_dir/lib/libz.so" -o \
-                   -f "$mysql_zlib_dir/lib/libz$shrext_cmds" \) \
+                   -f "$mysql_zlib_dir/lib/libz$shrext" \) \
                 -a -f "$mysql_zlib_dir/include/zlib.h"; then
           ZLIB_INCLUDES="-I$mysql_zlib_dir/include"
           ZLIB_LIBS="-L$mysql_zlib_dir/lib -lz"

From 50e8ba04cfad8ff19d568b5b3078377fd62eb527 Mon Sep 17 00:00:00 2001
From: "kent@mysql.com" <>
Date: Fri, 28 Apr 2006 17:03:11 +0200
Subject: [PATCH 076/108] mysql.spec.sh:   Include and run mysql_upgrade if
 needed (bug#19353)

---
 support-files/mysql.spec.sh | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/support-files/mysql.spec.sh b/support-files/mysql.spec.sh
index 39525cc9669..30f9d45cf74 100644
--- a/support-files/mysql.spec.sh
+++ b/support-files/mysql.spec.sh
@@ -488,9 +488,12 @@ usermod -g %{mysqld_group} %{mysqld_user} 2> /dev/null || true
 # owns all database files.
 chown -R %{mysqld_user}:%{mysqld_group} $mysql_datadir
 
-# Initiate databases
+# Initiate databases if needed
 %{_bindir}/mysql_install_db --rpm --user=%{mysqld_user}
 
+# Upgrade databases if needed
+%{_bindir}/mysql_upgrade --user=%{mysqld_user}
+
 # Change permissions again to fix any new files.
 chown -R %{mysqld_user}:%{mysqld_group} $mysql_datadir
 
@@ -561,6 +564,7 @@ fi
 %doc %attr(644, root, man) %{_mandir}/man1/mysqld_multi.1*
 %doc %attr(644, root, man) %{_mandir}/man1/mysqld_safe.1*
 %doc %attr(644, root, man) %{_mandir}/man1/mysql_fix_privilege_tables.1*
+%doc %attr(644, root, man) %{_mandir}/man1/mysql_upgrade.1*
 %doc %attr(644, root, man) %{_mandir}/man1/mysqlhotcopy.1*
 %doc %attr(644, root, man) %{_mandir}/man1/mysqlmanager.1*
 %doc %attr(644, root, man) %{_mandir}/man1/mysql.server.1*
@@ -585,6 +589,7 @@ fi
 %attr(755, root, root) %{_bindir}/mysql_explain_log
 %attr(755, root, root) %{_bindir}/mysql_fix_extensions
 %attr(755, root, root) %{_bindir}/mysql_fix_privilege_tables
+%attr(755, root, root) %{_bindir}/mysql_upgrade
 %attr(755, root, root) %{_bindir}/mysqlhotcopy
 %attr(755, root, root) %{_bindir}/mysql_install_db
 %attr(755, root, root) %{_bindir}/mysql_secure_installation
@@ -724,6 +729,10 @@ fi
 # itself - note that they must be ordered by date (important when
 # merging BK trees)
 %changelog 
+* Fri Apr 28 2006 Kent Boortz 
+
+- Install and run "mysql_upgrade"
+
 * Sat Apr 01 2006 Kent Boortz 
 
 - Set $LDFLAGS from $MYSQL_BUILD_LDFLAGS

From 7c4ddc8bd42d9179a1f4462dd26560dcf3698fdc Mon Sep 17 00:00:00 2001
From: "paul@polar.kitebird.com" <>
Date: Fri, 28 Apr 2006 10:44:08 -0500
Subject: [PATCH 077/108] mysqlslap.c:   Avoid embedding a bunch of whitespace
 in --help message.

---
 client/mysqlslap.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/client/mysqlslap.c b/client/mysqlslap.c
index d9b4230348e..11d3ae5a2df 100644
--- a/client/mysqlslap.c
+++ b/client/mysqlslap.c
@@ -457,8 +457,8 @@ static struct my_option my_long_options[] =
     (gptr*) &opt_mysql_port, 0, GET_UINT, REQUIRED_ARG, MYSQL_PORT, 0, 0, 0, 0,
     0},
   {"preserve-schema", OPT_MYSQL_PRESERVE_SCHEMA,
-    "Preserve the schema from the mysqlslap run, this happens unless \
-      --auto-generate-sql or --create are used.",
+    "Preserve the schema from the mysqlslap run, this happens unless "
+      "--auto-generate-sql or --create are used.",
     (gptr*) &opt_preserve, (gptr*) &opt_preserve, 0, GET_BOOL,
     NO_ARG, TRUE, 0, 0, 0, 0, 0},
   {"protocol", OPT_MYSQL_PROTOCOL,

From 604b5836bbf9677a543b12dca89fef3974771774 Mon Sep 17 00:00:00 2001
From: "elliot@mysql.com" <>
Date: Fri, 28 Apr 2006 12:15:29 -0400
Subject: [PATCH 078/108] BUG#19145: mysqld crashes if you set the default
 value of an enum field to NULL

Now test for NULLness the pointers returned from objects created from the
default value. Pushing patch on behalf of cmiller.
---
 mysql-test/r/null.result | 42 ++++++++++++++++++++++++++++++++++
 mysql-test/t/null.test   | 41 +++++++++++++++++++++++++++++++++
 sql/sql_table.cc         | 49 ++++++++++++++++++++++++++++++++--------
 3 files changed, 122 insertions(+), 10 deletions(-)

diff --git a/mysql-test/r/null.result b/mysql-test/r/null.result
index 3e233eb512a..4d90aac0e68 100644
--- a/mysql-test/r/null.result
+++ b/mysql-test/r/null.result
@@ -269,3 +269,45 @@ field('str1', null, 'STR1') as c05,
 c01	c02	c03	c04	c05	c08	c09
 str	str	0	1	2	1	1
 set names latin1;
+create table bug19145a (e enum('a','b','c')          default 'b' , s set('x', 'y', 'z')          default 'y' ) engine=MyISAM;
+create table bug19145b (e enum('a','b','c')          default null, s set('x', 'y', 'z')          default null) engine=MyISAM;
+create table bug19145c (e enum('a','b','c') not null default 'b' , s set('x', 'y', 'z') not null default 'y' ) engine=MyISAM;
+create table bug19145setnotnulldefaultnull (e enum('a','b','c')          default null, s set('x', 'y', 'z') not null default null) engine=MyISAM;
+ERROR 42000: Invalid default value for 's'
+create table bug19145enumnotnulldefaultnull (e enum('a','b','c') not null default null, s set('x', 'y', 'z')          default null) engine=MyISAM;
+ERROR 42000: Invalid default value for 'e'
+alter table bug19145a alter column e set default null;
+alter table bug19145a alter column s set default null;
+alter table bug19145a add column (i int);
+alter table bug19145b alter column e set default null;
+alter table bug19145b alter column s set default null;
+alter table bug19145b add column (i int);
+alter table bug19145c alter column e set default null;
+ERROR 42000: Invalid default value for 'e'
+alter table bug19145c alter column s set default null;
+ERROR 42000: Invalid default value for 's'
+alter table bug19145c add column (i int);
+show create table bug19145a;
+Table	Create Table
+bug19145a	CREATE TABLE `bug19145a` (
+  `e` enum('a','b','c') default NULL,
+  `s` set('x','y','z') default NULL,
+  `i` int(11) default NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+show create table bug19145b;
+Table	Create Table
+bug19145b	CREATE TABLE `bug19145b` (
+  `e` enum('a','b','c') default NULL,
+  `s` set('x','y','z') default NULL,
+  `i` int(11) default NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+show create table bug19145c;
+Table	Create Table
+bug19145c	CREATE TABLE `bug19145c` (
+  `e` enum('a','b','c') NOT NULL default 'b',
+  `s` set('x','y','z') NOT NULL default 'y',
+  `i` int(11) default NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+drop table bug19145a;
+drop table bug19145b;
+drop table bug19145c;
diff --git a/mysql-test/t/null.test b/mysql-test/t/null.test
index 731f0a4cb34..b405b8fb852 100644
--- a/mysql-test/t/null.test
+++ b/mysql-test/t/null.test
@@ -187,4 +187,45 @@ select
 # Restore charset to the default value.
 set names latin1;
 
+#
+# Bug#19145: mysqld crashes if you set the default value of an enum field to NULL
+#
+create table bug19145a (e enum('a','b','c')          default 'b' , s set('x', 'y', 'z')          default 'y' ) engine=MyISAM;
+create table bug19145b (e enum('a','b','c')          default null, s set('x', 'y', 'z')          default null) engine=MyISAM;
+
+create table bug19145c (e enum('a','b','c') not null default 'b' , s set('x', 'y', 'z') not null default 'y' ) engine=MyISAM;
+
+# Invalid default value for 's'
+--error 1067
+create table bug19145setnotnulldefaultnull (e enum('a','b','c')          default null, s set('x', 'y', 'z') not null default null) engine=MyISAM;
+
+# Invalid default value for 'e'
+--error 1067
+create table bug19145enumnotnulldefaultnull (e enum('a','b','c') not null default null, s set('x', 'y', 'z')          default null) engine=MyISAM;
+
+alter table bug19145a alter column e set default null;
+alter table bug19145a alter column s set default null;
+alter table bug19145a add column (i int);
+
+alter table bug19145b alter column e set default null;
+alter table bug19145b alter column s set default null;
+alter table bug19145b add column (i int);
+
+# Invalid default value for 'e'
+--error 1067
+alter table bug19145c alter column e set default null;
+
+# Invalid default value for 's'
+--error 1067
+alter table bug19145c alter column s set default null;
+alter table bug19145c add column (i int);
+
+show create table bug19145a;
+show create table bug19145b;
+show create table bug19145c;
+
+drop table bug19145a;
+drop table bug19145b;
+drop table bug19145c;
+
 # End of 4.1 tests
diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index c9513ec71ab..0454cadc774 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -601,7 +601,7 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info,
         if (need_to_change_arena)
           thd->restore_backup_item_arena(thd->current_arena, &backup_arena);
 
-        if (! sql_field->def)
+        if (sql_field->def == NULL)
         {
           /* Could not convert */
           my_error(ER_INVALID_DEFAULT, MYF(0), sql_field->field_name);
@@ -611,15 +611,30 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info,
 
       if (sql_field->sql_type == FIELD_TYPE_SET)
       {
-        if (sql_field->def)
+        if (sql_field->def != NULL)
         {
           char *not_used;
           uint not_used2;
           bool not_found= 0;
           String str, *def= sql_field->def->val_str(&str);
-          def->length(cs->cset->lengthsp(cs, def->ptr(), def->length()));
-          (void) find_set(interval, def->ptr(), def->length(),
-                          cs, ¬_used, ¬_used2, ¬_found);
+          if (def == NULL) /* SQL "NULL" maps to NULL */
+          {
+            if ((sql_field->flags & NOT_NULL_FLAG) != 0)
+            {
+              my_error(ER_INVALID_DEFAULT, MYF(0), sql_field->field_name);
+              DBUG_RETURN(-1);
+            }
+
+            /* else, NULL is an allowed value */
+            (void) find_set(interval, NULL, 0,
+                            cs, ¬_used, ¬_used2, ¬_found);
+          }
+          else /* not NULL */
+          {
+            (void) find_set(interval, def->ptr(), def->length(),
+                            cs, ¬_used, ¬_used2, ¬_found);
+          }
+
           if (not_found)
           {
             my_error(ER_INVALID_DEFAULT, MYF(0), sql_field->field_name);
@@ -631,14 +646,28 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info,
       }
       else  /* FIELD_TYPE_ENUM */
       {
-        if (sql_field->def)
+        DBUG_ASSERT(sql_field->sql_type == FIELD_TYPE_ENUM);
+        if (sql_field->def != NULL)
         {
           String str, *def= sql_field->def->val_str(&str);
-          def->length(cs->cset->lengthsp(cs, def->ptr(), def->length()));
-          if (!find_type2(interval, def->ptr(), def->length(), cs))
+          if (def == NULL) /* SQL "NULL" maps to NULL */
           {
-            my_error(ER_INVALID_DEFAULT, MYF(0), sql_field->field_name);
-            DBUG_RETURN(-1);
+            if ((sql_field->flags & NOT_NULL_FLAG) != 0)
+            {
+              my_error(ER_INVALID_DEFAULT, MYF(0), sql_field->field_name);
+              DBUG_RETURN(-1);
+            }
+
+            /* else, the defaults yield the correct length for NULLs. */
+          } 
+          else /* not NULL */
+          {
+            def->length(cs->cset->lengthsp(cs, def->ptr(), def->length()));
+            if (find_type2(interval, def->ptr(), def->length(), cs) == 0) /* not found */
+            {
+              my_error(ER_INVALID_DEFAULT, MYF(0), sql_field->field_name);
+              DBUG_RETURN(-1);
+            }
           }
         }
         calculate_interval_lengths(cs, interval, &sql_field->length, &dummy);

From b714a0cec4da4372151422348bae47ad9d2fcc66 Mon Sep 17 00:00:00 2001
From: "kent@mysql.com" <>
Date: Sat, 29 Apr 2006 01:28:04 +0200
Subject: [PATCH 079/108] mysql.spec.sh:   Backport of changes in 5.0
 (bug#18294)

---
 support-files/mysql.spec.sh | 72 +++++++++++++++++++++++++++++--------
 1 file changed, 57 insertions(+), 15 deletions(-)

diff --git a/support-files/mysql.spec.sh b/support-files/mysql.spec.sh
index b161ec13073..ab2319fa2bb 100644
--- a/support-files/mysql.spec.sh
+++ b/support-files/mysql.spec.sh
@@ -28,7 +28,7 @@ Release:	%{release}
 License:	%{license}
 Source:		http://www.mysql.com/Downloads/MySQL-@MYSQL_BASE_VERSION@/mysql-%{mysql_version}.tar.gz
 URL:		http://www.mysql.com/
-Packager:	Lenz Grimmer 
+Packager:	MySQL Production Engineering Team 
 Vendor:		MySQL AB
 Provides:	msqlormysql MySQL-server mysql
 BuildRequires: ncurses-devel
@@ -297,7 +297,6 @@ then
 fi
 
 BuildMySQL "--enable-shared \
-		--without-openssl \
 		--with-berkeley-db \
 		--with-innodb \
 		--with-ndbcluster \
@@ -307,13 +306,25 @@ BuildMySQL "--enable-shared \
 		--with-example-storage-engine \
 		--with-blackhole-storage-engine \
 		--with-embedded-server \
-		--with-comment=\"MySQL Community Edition - Max (GPL)\" \
-		--with-server-suffix='-Max'"
+		--with-comment=\"MySQL Community Edition - Experimental (GPL)\" \
+		--with-server-suffix='-max'"
+
+# We might want to save the config log file
+if test -n "$MYSQL_MAXCONFLOG_DEST"
+then
+  cp -fp config.log "$MYSQL_MAXCONFLOG_DEST"
+fi
 
 make -i test-force || true
 
 # Save mysqld-max
-mv sql/mysqld sql/mysqld-max
+# check if mysqld was installed in .libs/
+if test -f sql/.libs/mysqld
+then
+	cp sql/.libs/mysqld sql/mysqld-max
+else
+	cp sql/mysqld sql/mysqld-max
+fi
 nm --numeric-sort sql/mysqld-max > sql/mysqld-max.sym
 # Save the perror binary so it supports the NDB error codes (BUG#13740)
 mv extra/perror extra/perror.ndb
@@ -362,7 +373,18 @@ BuildMySQL "--disable-shared \
 		--with-innodb \
 		--without-vio \
 		--without-openssl"
-nm --numeric-sort sql/mysqld > sql/mysqld.sym
+if test -f sql/.libs/mysqld
+then
+	nm --numeric-sort sql/.libs/mysqld > sql/mysqld.sym
+else
+	nm --numeric-sort sql/mysqld > sql/mysqld.sym
+fi
+
+# We might want to save the config log file
+if test -n "$MYSQL_CONFLOG_DEST"
+then
+  cp -fp config.log "$MYSQL_CONFLOG_DEST"
+fi
 
 make -i test-force || true
 
@@ -456,7 +478,7 @@ usermod -g %{mysqld_group} %{mysqld_user} 2> /dev/null || true
 # owns all database files.
 chown -R %{mysqld_user}:%{mysqld_group} $mysql_datadir
 
-# Initiate databases
+# Initiate databases if needed
 %{_bindir}/mysql_install_db --rpm --user=%{mysqld_user}
 
 # Change permissions again to fix any new files.
@@ -543,31 +565,31 @@ fi
 
 %attr(755, root, root) %{_bindir}/isamchk
 %attr(755, root, root) %{_bindir}/isamlog
-%attr(755, root, root) %{_bindir}/myisamchk
+%attr(755, root, root) %{_bindir}/my_print_defaults
 %attr(755, root, root) %{_bindir}/myisam_ftdump
+%attr(755, root, root) %{_bindir}/myisamchk
 %attr(755, root, root) %{_bindir}/myisamlog
 %attr(755, root, root) %{_bindir}/myisampack
-%attr(755, root, root) %{_bindir}/my_print_defaults
-%attr(755, root, root) %{_bindir}/mysqlbug
 %attr(755, root, root) %{_bindir}/mysql_convert_table_format
 %attr(755, root, root) %{_bindir}/mysql_create_system_tables
-%attr(755, root, root) %{_bindir}/mysqld_multi
-%attr(755, root, root) %{_bindir}/mysqld_safe
 %attr(755, root, root) %{_bindir}/mysql_explain_log
 %attr(755, root, root) %{_bindir}/mysql_fix_extensions
 %attr(755, root, root) %{_bindir}/mysql_fix_privilege_tables
-%attr(755, root, root) %{_bindir}/mysqlhotcopy
 %attr(755, root, root) %{_bindir}/mysql_install_db
 %attr(755, root, root) %{_bindir}/mysql_secure_installation
 %attr(755, root, root) %{_bindir}/mysql_setpermission
-%attr(755, root, root) %{_bindir}/mysqltest
 %attr(755, root, root) %{_bindir}/mysql_tzinfo_to_sql
 %attr(755, root, root) %{_bindir}/mysql_zap
+%attr(755, root, root) %{_bindir}/mysqlbug
+%attr(755, root, root) %{_bindir}/mysqld_multi
+%attr(755, root, root) %{_bindir}/mysqld_safe
+%attr(755, root, root) %{_bindir}/mysqlhotcopy
+%attr(755, root, root) %{_bindir}/mysqltest
 %attr(755, root, root) %{_bindir}/pack_isam
 %attr(755, root, root) %{_bindir}/perror
 %attr(755, root, root) %{_bindir}/replace
-%attr(755, root, root) %{_bindir}/resolveip
 %attr(755, root, root) %{_bindir}/resolve_stack_dump
+%attr(755, root, root) %{_bindir}/resolveip
 %attr(755, root, root) %{_bindir}/safe_mysqld
 
 %attr(755, root, root) %{_sbindir}/mysqld
@@ -662,6 +684,11 @@ fi
 %{_libdir}/mysql/libmysys.a
 %{_libdir}/mysql/libnisam.a
 %{_libdir}/mysql/libvio.a
+%if %{STATIC_BUILD}
+%else
+%{_libdir}/mysql/libz.a
+%{_libdir}/mysql/libz.la
+%endif
 
 %files shared
 %defattr(-, root, root, 0755)
@@ -694,11 +721,26 @@ fi
 
 - Set $LDFLAGS from $MYSQL_BUILD_LDFLAGS
 
+* Fri Mar 03 2006 Kent Boortz 
+
+- Can't use bundled zlib when doing static build. Might be a
+  automake/libtool problem, having two .la files, "libmysqlclient.la"
+  and "libz.la", on the same command line to link "thread_test"
+  expands to too many "-lc", "-lpthread" and other libs giving hard
+  to nail down duplicate symbol defintion problems.
+
 * Fri Jan 10 2006 Joerg Bruehe 
 
 - Use "-i" on "make test-force";
   this is essential for later evaluation of this log file.
 
+* Fri Dec 12 2005 Rodrigo Novo 
+
+- Added zlib to the list of (static) libraries installed
+- Added check against libtool wierdness (WRT: sql/mysqld || sql/.libs/mysqld)
+- Compile MySQL with bundled zlib
+- Fixed %packager name to "MySQL Production Engineering Team"
+
 * Mon Dec 05 2005 Joerg Bruehe 
 
 - Avoid using the "bundled" zlib on "shared" builds: 

From a14f1250d6523e71c569c7198ed39cf271b9c7d6 Mon Sep 17 00:00:00 2001
From: "kent@mysql.com" <>
Date: Sat, 29 Apr 2006 07:32:12 +0200
Subject: [PATCH 080/108] configure.in:   Changed version to 4.1.20

---
 configure.in | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/configure.in b/configure.in
index 4b8f30511c5..2dfa2d0b420 100644
--- a/configure.in
+++ b/configure.in
@@ -5,7 +5,7 @@ AC_INIT(sql/mysqld.cc)
 AC_CANONICAL_SYSTEM
 # The Docs Makefile.am parses this line!
 # remember to also change ndb version below and update version.c in ndb
-AM_INIT_AUTOMAKE(mysql, 4.1.19)
+AM_INIT_AUTOMAKE(mysql, 4.1.20)
 AM_CONFIG_HEADER(config.h)
 
 PROTOCOL_VERSION=10
@@ -17,7 +17,7 @@ SHARED_LIB_VERSION=$SHARED_LIB_MAJOR_VERSION:0:0
 # ndb version
 NDB_VERSION_MAJOR=4
 NDB_VERSION_MINOR=1
-NDB_VERSION_BUILD=19
+NDB_VERSION_BUILD=20
 NDB_VERSION_STATUS=""
 
 # Set all version vars based on $VERSION. How do we do this more elegant ?

From 5e717959d0198ed96cfa2d594509629ae0afcedb Mon Sep 17 00:00:00 2001
From: "kent@mysql.com" <>
Date: Sat, 29 Apr 2006 15:58:02 +0200
Subject: [PATCH 081/108] config-win.h:   Fix strange "double" define for
 popen.   Avoid warnings about sprintf() etc. being unsafe.   Corrected typo
 "#endfif"

---
 include/config-win.h | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/include/config-win.h b/include/config-win.h
index 03f130ad37e..bb54a43b8bb 100644
--- a/include/config-win.h
+++ b/include/config-win.h
@@ -22,6 +22,11 @@ functions */
 #define _WIN32_WINNT     0x0500
 #endif
 
+#if defined(_MSC_VER) && _MSC_VER >= 1400
+/* Avoid endless warnings about sprintf() etc. being unsafe. */
+#define _CRT_SECURE_NO_DEPRECATE 1
+#endif
+
 #include 
 #include 
 #include 			/* Because of rint() */
@@ -195,7 +200,7 @@ typedef uint rf_SetTimer;
 #define my_sigset(A,B) signal((A),(B))
 #define finite(A) _finite(A)
 #define sleep(A)  Sleep((A)*1000)
-#define popen(A) popen(A,B) _popen((A),(B))
+#define popen(A,B) _popen((A),(B))
 #define pclose(A) _pclose(A)
 
 #ifndef __BORLANDC__
@@ -385,7 +390,7 @@ inline double ulonglong2double(ulonglong value)
 #else
 #define MYSQL_DEFAULT_CHARSET_NAME "latin1"
 #define MYSQL_DEFAULT_COLLATION_NAME "latin1_swedish_ci"
-#enfif
+#endif
 
 #define HAVE_SPATIAL 1
 #define HAVE_RTREE_KEYS 1

From 281fb1cfc5358389e51e6dbac304b9d0fbfbbf86 Mon Sep 17 00:00:00 2001
From: "serg@sergbook.mysql.com" <>
Date: Sat, 29 Apr 2006 09:33:34 -0700
Subject: [PATCH 082/108] make distcheck and cosmetic fixes

---
 config/ac-macros/ha_berkeley.m4   |  15 +-
 config/ac-macros/ha_ndbcluster.m4 |   2 +-
 config/ac-macros/misc.m4          |   8 +-
 config/ac-macros/plugins.m4       | 609 +++++++++++++++---------------
 configure.in                      |  37 +-
 plugin/Makefile.am                |   4 +-
 sql/Makefile.am                   |   4 +-
 storage/archive/Makefile.am       |   8 +-
 storage/blackhole/Makefile.am     |   2 +-
 storage/example/Makefile.am       |   2 +-
 storage/innobase/Makefile.am      |  11 +-
 11 files changed, 347 insertions(+), 355 deletions(-)

diff --git a/config/ac-macros/ha_berkeley.m4 b/config/ac-macros/ha_berkeley.m4
index c389077ea8b..c7d99bd8e03 100644
--- a/config/ac-macros/ha_berkeley.m4
+++ b/config/ac-macros/ha_berkeley.m4
@@ -8,23 +8,20 @@ dnl ---------------------------------------------------------------------------
 
 AC_DEFUN([MYSQL_SETUP_BERKELEY_DB], [
   AC_ARG_WITH([berkeley-db],
-              [
-  --with-berkeley-db[=DIR]
-                          Use BerkeleyDB located in DIR],
+              AS_HELP_STRING([--with-berkeley-db[[[[[=DIR]]]]]],
+                             [Use BerkeleyDB located in DIR]),
               [bdb="$withval"],
               [bdb=yes])
 
   AC_ARG_WITH([berkeley-db-includes],
-              [
-  --with-berkeley-db-includes=DIR
-                          Find Berkeley DB headers in DIR],
+              AS_HELP_STRING([--with-berkeley-db-includes=DIR],
+                             [Find Berkeley DB headers in DIR]),
               [bdb_includes="$withval"],
               [bdb_includes=default])
 
   AC_ARG_WITH([berkeley-db-libs],
-              [
-  --with-berkeley-db-libs=DIR
-                          Find Berkeley DB libraries in DIR],
+              AS_HELP_STRING([--with-berkeley-db-libs=DIR],
+                             [Find Berkeley DB libraries in DIR]),
               [bdb_libs="$withval"],
               [bdb_libs=default])
 
diff --git a/config/ac-macros/ha_ndbcluster.m4 b/config/ac-macros/ha_ndbcluster.m4
index c7e163e065f..aee445f8d58 100644
--- a/config/ac-macros/ha_ndbcluster.m4
+++ b/config/ac-macros/ha_ndbcluster.m4
@@ -308,7 +308,7 @@ AC_DEFUN([MYSQL_SETUP_NDBCLUSTER], [
   AC_SUBST(NDB_DEFS)
   AC_SUBST(ndb_cxxflags_fix)
 
-  AC_CONFIG_FILES(storage/ndb/Makefile storage/ndb/include/Makefile dnl
+  AC_CONFIG_FILES(storage/ndb/include/Makefile dnl
    storage/ndb/src/Makefile storage/ndb/src/common/Makefile dnl
    storage/ndb/docs/Makefile dnl
    storage/ndb/tools/Makefile dnl
diff --git a/config/ac-macros/misc.m4 b/config/ac-macros/misc.m4
index d8199f5970e..a2f70071e2d 100644
--- a/config/ac-macros/misc.m4
+++ b/config/ac-macros/misc.m4
@@ -675,8 +675,8 @@ dnl Sets BIG_TABLES if --with-big-tables is used
 dnl ---------------------------------------------------------------------------
 AC_DEFUN([MYSQL_CHECK_BIG_TABLES], [
   AC_ARG_WITH([big-tables],
-              [
-  --with-big-tables       Support tables with more than 4 G rows even on 32 bit platforms],
+  AS_HELP_STRING([--with-big-tables],
+              [Support tables with more than 4 G rows even on 32 bit platforms]),
               [bigtables="$withval"],
               [bigtables=no])
   AC_MSG_CHECKING([for big tables support])
@@ -703,8 +703,8 @@ dnl Sets MAX_INDEXES
 dnl ---------------------------------------------------------------------------
 AC_DEFUN([MYSQL_CHECK_MAX_INDEXES], [
   AC_ARG_WITH([max-indexes],
-              [
-  --with-max-indexes=\#      Sets the maximum number of indexes per table, default 64],
+              AS_HELP_STRING([--with-max-indexes=N],
+                             [Sets the maximum number of indexes per table, default 64]),
               [max_indexes="$withval"],
               [max_indexes=64])
   AC_MSG_CHECKING([max indexes per table])
diff --git a/config/ac-macros/plugins.m4 b/config/ac-macros/plugins.m4
index 8ea5aca2595..51f83e19e5f 100644
--- a/config/ac-macros/plugins.m4
+++ b/config/ac-macros/plugins.m4
@@ -20,28 +20,28 @@ dnl   Adds module as member to configuration groups (if specified)
 dnl
 dnl ---------------------------------------------------------------------------
 
-AC_DEFUN([MYSQL_MODULE],[ dnl
+AC_DEFUN([MYSQL_MODULE],[
  _MYSQL_MODULE(
   [$1],
   [__MYSQL_MODULE_]AS_TR_CPP([$1])[__],
   m4_default([$2], [$1 plugin]),
   m4_default([$3], [plugin for $1]),
   m4_default([$4], []),
- ) dnl
+ )
 ])
 
-AC_DEFUN([_MYSQL_MODULE],[ dnl
- m4_ifdef([$2], [ dnl
-  AC_FATAL([[Duplicate MYSQL_MODULE declaration for ]][$3]) dnl
+AC_DEFUN([_MYSQL_MODULE],[
+ m4_ifdef([$2], [
+  AC_FATAL([[Duplicate MYSQL_MODULE declaration for ]][$3])
  ],[ dnl 
-  m4_define([$2], [$1]) dnl
-  _MYSQL_PLUGAPPEND([__mysql_plugin_list__],[$1]) dnl
-  m4_define([MYSQL_MODULE_NAME_]AS_TR_CPP([$1]), [$3]) dnl
-  m4_define([MYSQL_MODULE_DESC_]AS_TR_CPP([$1]), [$4]) dnl
-  ifelse([$5], [], [], [ dnl
-   _MYSQL_PLUGAPPEND_OPTS([$1], $5) dnl
-  ]) dnl
- ]) dnl
+  m4_define([$2], [$1])
+  _MYSQL_PLUGAPPEND([__mysql_plugin_list__],[$1])
+  m4_define([MYSQL_MODULE_NAME_]AS_TR_CPP([$1]), [$3])
+  m4_define([MYSQL_MODULE_DESC_]AS_TR_CPP([$1]), [$4])
+  ifelse([$5], [], [], [
+   _MYSQL_PLUGAPPEND_OPTS([$1], $5)
+  ])
+ ])
 ])
 
 
@@ -53,18 +53,18 @@ dnl   Short cut for storage engine declarations
 dnl
 dnl ---------------------------------------------------------------------------
 
-AC_DEFUN([MYSQL_STORAGE_ENGINE],[ dnl
- MYSQL_MODULE([$1], [$3], [$4], [[$5]]) dnl
- MYSQL_MODULE_DEFINE([$1], [WITH_]AS_TR_CPP([$1])[_STORAGE_ENGINE]) dnl
- ifelse([$2],[no],[],[ dnl
-  _MYSQL_LEGACY_STORAGE_ENGINE([$1],m4_default([$2], [$1-storage-engine])) dnl
- ]) dnl
+AC_DEFUN([MYSQL_STORAGE_ENGINE],[
+ MYSQL_MODULE([$1], [$3], [$4], [[$5]])
+ MYSQL_MODULE_DEFINE([$1], [WITH_]AS_TR_CPP([$1])[_STORAGE_ENGINE])
+ ifelse([$2],[no],[],[
+  _MYSQL_LEGACY_STORAGE_ENGINE([$1],m4_default([$2], [$1-storage-engine]))
+ ])
 ])
 
 AC_DEFUN([_MYSQL_LEGACY_STORAGE_ENGINE],[
 if test "[${with_]m4_bpatsubst($2, -, _)[+set}]" = set; then
   [with_module_]m4_bpatsubst($1, -, _)="[$with_]m4_bpatsubst($2, -, _)"
-fi dnl
+fi
 ])
 
 
@@ -76,9 +76,9 @@ dnl   When a plugin module is to be statically linked, define the C macro
 dnl
 dnl ---------------------------------------------------------------------------
 
-AC_DEFUN([MYSQL_MODULE_DEFINE],[ dnl
- REQUIRE_PLUGIN([$1]) dnl
- m4_define([MYSQL_MODULE_DEFINE_]AS_TR_CPP([$1]), [$2]) dnl
+AC_DEFUN([MYSQL_MODULE_DEFINE],[
+ REQUIRE_PLUGIN([$1])
+ m4_define([MYSQL_MODULE_DEFINE_]AS_TR_CPP([$1]), [$2])
 ])
 
 
@@ -90,9 +90,9 @@ dnl   Adds a directory to the build process
 dnl
 dnl ---------------------------------------------------------------------------
 
-AC_DEFUN([MYSQL_MODULE_DIRECTORY],[ dnl
- REQUIRE_PLUGIN([$1]) dnl
- m4_define([MYSQL_MODULE_DIRECTORY_]AS_TR_CPP([$1]), [$2]) dnl
+AC_DEFUN([MYSQL_MODULE_DIRECTORY],[
+ REQUIRE_PLUGIN([$1])
+ m4_define([MYSQL_MODULE_DIRECTORY_]AS_TR_CPP([$1]), [$2])
 ])
 
 
@@ -104,9 +104,9 @@ dnl   Declare the name for the static library
 dnl
 dnl ---------------------------------------------------------------------------
 
-AC_DEFUN([MYSQL_MODULE_STATIC],[ dnl
- REQUIRE_PLUGIN([$1]) dnl
- m4_define([MYSQL_MODULE_STATIC_]AS_TR_CPP([$1]), [$2]) dnl
+AC_DEFUN([MYSQL_MODULE_STATIC],[
+ REQUIRE_PLUGIN([$1])
+ m4_define([MYSQL_MODULE_STATIC_]AS_TR_CPP([$1]), [$2])
 ])
 
 
@@ -118,9 +118,9 @@ dnl   Declare the name for the shared library
 dnl
 dnl ---------------------------------------------------------------------------
 
-AC_DEFUN([MYSQL_MODULE_DYNAMIC],[ dnl
- REQUIRE_PLUGIN([$1]) dnl
- m4_define([MYSQL_MODULE_DYNAMIC_]AS_TR_CPP([$1]), [$2]) dnl
+AC_DEFUN([MYSQL_MODULE_DYNAMIC],[
+ REQUIRE_PLUGIN([$1])
+ m4_define([MYSQL_MODULE_DYNAMIC_]AS_TR_CPP([$1]), [$2])
 ])
 
 
@@ -132,20 +132,20 @@ dnl   Marks the specified plugin as a mandatory module
 dnl
 dnl ---------------------------------------------------------------------------
 
-AC_DEFUN([MYSQL_MODULE_MANDATORY],[ dnl
- REQUIRE_PLUGIN([$1]) dnl
+AC_DEFUN([MYSQL_MODULE_MANDATORY],[
+ REQUIRE_PLUGIN([$1])
  _MYSQL_MODULE_MANDATORY([$1],
   [MYSQL_MODULE_MANDATORY_]AS_TR_CPP([$1]),
   [MYSQL_MODULE_DISABLED_]AS_TR_CPP([$1])
- ) dnl
+ )
 ])
 
-AC_DEFUN([_MYSQL_MODULE_MANDATORY],[ dnl
- m4_define([$2], [yes]) dnl
- m4_ifdef([$3], [ dnl
-  AC_WARNING([syntax],[Mandatory plugin $1 has been disabled]) dnl
-  m4_undefine([$2]) dnl
- ]) dnl
+AC_DEFUN([_MYSQL_MODULE_MANDATORY],[
+ m4_define([$2], [yes])
+ m4_ifdef([$3], [
+  AC_WARNING([syntax],[Mandatory plugin $1 has been disabled])
+  m4_undefine([$2])
+ ])
 ])
 
 
@@ -157,20 +157,20 @@ dnl   Marks the specified plugin as a disabled module
 dnl
 dnl ---------------------------------------------------------------------------
 
-AC_DEFUN([MYSQL_MODULE_DISABLED],[ dnl
- REQUIRE_PLUGIN([$1]) dnl
+AC_DEFUN([MYSQL_MODULE_DISABLED],[
+ REQUIRE_PLUGIN([$1])
  _MYSQL_MODULE_DISABLED([$1], 
   [MYSQL_MODULE_DISABLED_]AS_TR_CPP([$1]),
   [MYSQL_MODULE_MANDATORY_]AS_TR_CPP([$1])
- ) dnl
+ )
 ])
 
-AC_DEFUN([_MYSQL_MODULE_DISABLED],[ dnl
- m4_define([$2], [yes]) dnl
- m4_ifdef([$3], [ dnl
-  AC_FATAL([attempt to disable mandatory plugin $1]) dnl
-  m4_undefine([$2]) dnl
- ]) dnl
+AC_DEFUN([_MYSQL_MODULE_DISABLED],[
+ m4_define([$2], [yes])
+ m4_ifdef([$3], [
+  AC_FATAL([attempt to disable mandatory plugin $1])
+  m4_undefine([$2])
+ ])
 ])
 
 
@@ -185,21 +185,21 @@ dnl   here too!
 dnl
 dnl ---------------------------------------------------------------------------
 
-AC_DEFUN([MYSQL_MODULE_DEPENDS],[ dnl
- REQUIRE_PLUGIN([$1]) dnl
- ifelse($#, 0, [], $#, 1, [ dnl
-  AC_FATAL([[bad number of arguments]]) dnl
- ], $#, 2, [ dnl
-  _MYSQL_MODULE_DEPEND([$1],[$2]) dnl
- ],[ dnl
-  _MYSQL_MODULE_DEPEND([$1],[$2]) dnl
-  MYSQL_MODULE_DEPENDS([$1], m4_shift(m4_shift($@))) dnl
+AC_DEFUN([MYSQL_MODULE_DEPENDS],[
+ REQUIRE_PLUGIN([$1])
+ ifelse($#, 0, [], $#, 1, [
+  AC_FATAL([[bad number of arguments]])
+ ], $#, 2, [
+  _MYSQL_MODULE_DEPEND([$1],[$2])
+ ],[
+  _MYSQL_MODULE_DEPEND([$1],[$2])
+  MYSQL_MODULE_DEPENDS([$1], m4_shift(m4_shift($@)))
  ])
 ])
 
-AC_DEFUN([_MYSQL_MODULE_DEPEND],[ dnl
- REQUIRE_PLUGIN([$2]) dnl
- _MYSQL_PLUGAPPEND([__mysql_plugdepends_$1__],[$2]) dnl
+AC_DEFUN([_MYSQL_MODULE_DEPEND],[
+ REQUIRE_PLUGIN([$2])
+ _MYSQL_PLUGAPPEND([__mysql_plugdepends_$1__],[$2])
 ])
 
 
@@ -211,12 +211,12 @@ dnl   Declares additional actions required to configure the module
 dnl
 dnl ---------------------------------------------------------------------------
 
-AC_DEFUN([MYSQL_MODULE_ACTIONS],[ dnl
- REQUIRE_PLUGIN([$1]) dnl
- m4_ifdef([$2],[ dnl
-   m4_define([MYSQL_MODULE_ACTIONS_]AS_TR_CPP([$1]),m4_defn([$2])) dnl
- ],[ dnl
-   m4_define([MYSQL_MODULE_ACTIONS_]AS_TR_CPP([$1]), [$2]) dnl
+AC_DEFUN([MYSQL_MODULE_ACTIONS],[
+ REQUIRE_PLUGIN([$1])
+ m4_ifdef([$2],[
+   m4_define([MYSQL_MODULE_ACTIONS_]AS_TR_CPP([$1]),m4_defn([$2]))
+ ],[
+   m4_define([MYSQL_MODULE_ACTIONS_]AS_TR_CPP([$1]), [$2])
  ])
 ])
 
@@ -229,33 +229,33 @@ dnl   Called last, emits all required shell code to configure the modules
 dnl
 dnl ---------------------------------------------------------------------------
 
-AC_DEFUN([MYSQL_CONFIGURE_PLUGINS],[ dnl
- m4_ifdef([__mysql_plugin_configured__],[ dnl
-   AC_FATAL([cannot call [MYSQL_CONFIGURE_PLUGINS] multiple times]) dnl
- ],[ dnl
-   m4_define([__mysql_plugin_configured__],[done]) dnl
-   m4_ifdef([__mysql_plugin_list__],[ dnl
+AC_DEFUN([MYSQL_CONFIGURE_PLUGINS],[
+ m4_ifdef([__mysql_plugin_configured__],[
+   AC_FATAL([cannot call [MYSQL_CONFIGURE_PLUGINS] multiple times])
+ ],[
+   m4_define([__mysql_plugin_configured__],[done])
+   m4_ifdef([__mysql_plugin_list__],[
     _MYSQL_CHECK_PLUGIN_ARGS([$1])
     _MYSQL_CONFIGURE_PLUGINS(m4_bpatsubst(__mysql_plugin_list__, :, [,]))
     _MYSQL_DO_PLUGIN_ACTIONS(m4_bpatsubst(__mysql_plugin_list__, :, [,]))
     _MYSQL_POST_PLUGIN_FIXUP()
-   ]) dnl
- ]) dnl
-])
-
-AC_DEFUN([_MYSQL_CONFIGURE_PLUGINS],[ dnl
- ifelse($#, 0, [], $#, 1, [ dnl
-  _MYSQL_CHECK_PLUGIN([$1]) dnl
- ],[ dnl
-  _MYSQL_CHECK_PLUGIN([$1]) dnl
-  _MYSQL_CONFIGURE_PLUGINS(m4_shift($@)) dnl
+   ])
  ])
 ])
 
-AC_DEFUN([_MYSQL_CHECK_PLUGIN],[ dnl
+AC_DEFUN([_MYSQL_CONFIGURE_PLUGINS],[
+ ifelse($#, 0, [], $#, 1, [
+  _MYSQL_CHECK_PLUGIN([$1])
+ ],[
+  _MYSQL_CHECK_PLUGIN([$1])
+  _MYSQL_CONFIGURE_PLUGINS(m4_shift($@))
+ ])
+])
+
+AC_DEFUN([_MYSQL_CHECK_PLUGIN],[
  _DO_MYSQL_CHECK_PLUGIN(
   [$1],
-  [$1-plugin],
+  m4_bpatsubst([$1], -, _),
   [MYSQL_MODULE_NAME_]AS_TR_CPP([$1]),
   [MYSQL_MODULE_DESC_]AS_TR_CPP([$1]),
   [MYSQL_MODULE_DEFINE_]AS_TR_CPP([$1]),
@@ -265,104 +265,111 @@ AC_DEFUN([_MYSQL_CHECK_PLUGIN],[ dnl
   [MYSQL_MODULE_MANDATORY_]AS_TR_CPP([$1]),
   [MYSQL_MODULE_DISABLED_]AS_TR_CPP([$1]),
   [MYSQL_MODULE_ACTIONS_]AS_TR_CPP([$1])
- ) dnl
+ )
 ])
 
-AC_DEFUN([_DO_MYSQL_CHECK_PLUGIN],[ dnl
- m4_ifdef([$5],[ dnl
+AC_DEFUN([_DO_MYSQL_CHECK_PLUGIN],[
+ m4_ifdef([$5],[
   AH_TEMPLATE($5, [Include ]$4[ into mysqld])
  ])
- AC_MSG_CHECKING([whether to use ]$3) dnl
+ AC_MSG_CHECKING([whether to use ]$3)
  m4_ifdef([$10],[
-  if test "[$mysql_module_]m4_bpatsubst([$1], -, _)" = yes -a \
-          "[$with_module_]m4_bpatsubst([$1], -, _)" != no -o \
-          "[$with_module_]m4_bpatsubst([$1], -, _)" = yes; then
+  if test "[$mysql_module_]$2" = yes -a \
+          "[$with_module_]$2" != no -o \
+          "[$with_module_]$2" = yes; then
     AC_MSG_ERROR([disabled])
   fi
-  AC_MSG_RESULT([no]) dnl
- ],[ dnl
+  AC_MSG_RESULT([no])
+ ],[
   m4_ifdef([$9],[
-   if test "[$with_module_]m4_bpatsubst([$1], -, _)" = no; then
+   if test "[$with_module_]$2" = no; then
      AC_MSG_ERROR([cannot disable mandatory module])
    fi
-   [mysql_module_]m4_bpatsubst([$1], -, _)=yes dnl
+   [mysql_module_]$2=yes
   ])
-  if test "[$with_module_]m4_bpatsubst([$1], -, _)" != no; then
-    if test "[$mysql_module_]m4_bpatsubst([$1], -, _)" != yes -a \
-            "[$with_module_]m4_bpatsubst([$1], -, _)" != yes; then dnl
-      m4_ifdef([$8],[ dnl
+  if test "[$with_module_]$2" = no; then
+    AC_MSG_RESULT([no])
+  else
+    if test "[$mysql_module_]$2" != yes -a \
+            "[$with_module_]$2" != yes; then
+      m4_ifdef([$8],[
        m4_ifdef([$6],[
-        mysql_plugin_dirs="$mysql_plugin_dirs $6" dnl
+         if test -d "$srcdir/$6" ; then
+           mysql_plugin_dirs="$mysql_plugin_dirs $6"
+       ])
+       AC_SUBST([plugin_]$2[_shared_target], "$8")
+       AC_SUBST([plugin_]$2[_static_target], [""])
+       [with_module_]$2=yes
+       AC_MSG_RESULT([plugin])
+       m4_ifdef([$6],[
+         else
+           [mysql_module_]$2=no
+           AC_MSG_RESULT([no])
+         fi
        ])
-       AC_SUBST([plugin_]m4_bpatsubst([$1], -, _)[_shared_target], "$8")
-       AC_SUBST([plugin_]m4_bpatsubst([$1], -, _)[_static_target], [""])
-       [with_module_]m4_bpatsubst([$1], -, _)=yes
-       AC_MSG_RESULT([plugin]) dnl
       ],[
-       [with_module_]m4_bpatsubst([$1], -, _)=no
-       AC_MSG_RESULT([no]) dnl
+       [with_module_]$2=no
+       AC_MSG_RESULT([no])
       ])
-    else dnl
+    else
       m4_ifdef([$7],[
-       ifelse(m4_bregexp($7, [^lib[^.]+\.a$]), -2, [ dnl
+       ifelse(m4_bregexp($7, [^lib[^.]+\.a$]), -2, [
         m4_ifdef([$6],[
          mysql_plugin_dirs="$mysql_plugin_dirs $6"
-         mysql_plugin_libs="$mysql_plugin_libs -L[\$(top_builddir)]/$6" dnl
+         mysql_plugin_libs="$mysql_plugin_libs -L[\$(top_builddir)]/$6"
         ])
-        mysql_plugin_libs="$mysql_plugin_libs dnl
-[-l]m4_bregexp($7, [^lib\([^.]+\)], [\1])" dnl
-       ], m4_bregexp($7, [^\\\$]), 0, [ dnl
-        m4_ifdef([$6],[
-         mysql_plugin_dirs="$mysql_plugin_dirs $6" dnl
-        ])
-        mysql_plugin_libs="$mysql_plugin_libs $7" dnl
-       ], [ dnl
+        mysql_plugin_libs="$mysql_plugin_libs
+[-l]m4_bregexp($7, [^lib\([^.]+\)], [\1])"
+       ], m4_bregexp($7, [^\\\$]), 0, [
         m4_ifdef([$6],[
          mysql_plugin_dirs="$mysql_plugin_dirs $6"
-         mysql_plugin_libs="$mysql_plugin_libs \$(top_builddir)/$6/$7" dnl
+        ])
+        mysql_plugin_libs="$mysql_plugin_libs $7"
+       ], [
+        m4_ifdef([$6],[
+         mysql_plugin_dirs="$mysql_plugin_dirs $6"
+         mysql_plugin_libs="$mysql_plugin_libs \$(top_builddir)/$6/$7"
         ],[
-         mysql_plugin_libs="$mysql_plugin_libs $7" dnl
-        ]) dnl
-       ]) dnl
-       m4_ifdef([$5],[
-        AC_DEFINE($5) dnl
+         mysql_plugin_libs="$mysql_plugin_libs $7"
+        ])
        ])
-       AC_SUBST([plugin_]m4_bpatsubst([$1], -, _)[_static_target], "$7")
-       AC_SUBST([plugin_]m4_bpatsubst([$1], -, _)[_shared_target], [""]) dnl
-      ],[ dnl
+       m4_ifdef([$5],[
+        AC_DEFINE($5)
+       ])
+       AC_SUBST([plugin_]$2[_static_target], "$7")
+       AC_SUBST([plugin_]$2[_shared_target], [""])
+      ],[
        m4_ifdef([$6],[
-        AC_FATAL([plugin directory specified without library for ]$3) dnl
-       ],[ dnl
+        AC_FATAL([plugin directory specified without library for ]$3)
+       ],[
         m4_ifdef([$5],[
          AC_DEFINE($5)
-         AC_SUBST([plugin_]m4_bpatsubst([$1], -, _)[_static_target], ["yes"])
-         AC_SUBST([plugin_]m4_bpatsubst([$1], -, _)[_shared_target], [""]) dnl
-        ]) dnl
-       ]) dnl
+         AC_SUBST([plugin_]$2[_static_target], ["yes"])
+         AC_SUBST([plugin_]$2[_shared_target], [""])
+        ])
+       ])
       ])
-      mysql_plugin_defs="$mysql_plugin_defs, [builtin_]m4_bpatsubst([$2], -, _)"
-      [with_module_]m4_bpatsubst([$1], -, _)=yes
+      mysql_plugin_defs="$mysql_plugin_defs, [builtin_]$2[_plugin]"
+      [with_module_]$2=yes
       AC_MSG_RESULT([yes])
     fi
-  else
-    AC_MSG_RESULT([no])
-  fi dnl
- ]) dnl
-])
-
-AC_DEFUN([_MYSQL_DO_PLUGIN_ACTIONS],[ dnl
- ifelse($#, 0, [], $#, 1, [ dnl
-  _MYSQL_PLUGIN_ACTIONS([$1]) dnl
- ],[ dnl
-  _MYSQL_PLUGIN_ACTIONS([$1]) dnl
-  _MYSQL_DO_PLUGIN_ACTIONS(m4_shift($@)) dnl
+  fi
  ])
 ])
 
-AC_DEFUN([_MYSQL_PLUGIN_ACTIONS],[ dnl
+AC_DEFUN([_MYSQL_DO_PLUGIN_ACTIONS],[
+ ifelse($#, 0, [], $#, 1, [
+  _MYSQL_PLUGIN_ACTIONS([$1])
+ ],[
+  _MYSQL_PLUGIN_ACTIONS([$1])
+  _MYSQL_DO_PLUGIN_ACTIONS(m4_shift($@))
+ ])
+])
+
+AC_DEFUN([_MYSQL_PLUGIN_ACTIONS],[
  _DO_MYSQL_PLUGIN_ACTIONS(
   [$1],
-  [$1-plugin],
+  m4_bpatsubst([$1], -, _),
   [MYSQL_MODULE_NAME_]AS_TR_CPP([$1]),
   [MYSQL_MODULE_DESC_]AS_TR_CPP([$1]),
   [MYSQL_MODULE_DEFINE_]AS_TR_CPP([$1]),
@@ -372,20 +379,20 @@ AC_DEFUN([_MYSQL_PLUGIN_ACTIONS],[ dnl
   [MYSQL_MODULE_MANDATORY_]AS_TR_CPP([$1]),
   [MYSQL_MODULE_DISABLED_]AS_TR_CPP([$1]),
   [MYSQL_MODULE_ACTIONS_]AS_TR_CPP([$1])
- ) dnl
+ )
 ])
 
 
-AC_DEFUN([_DO_MYSQL_PLUGIN_ACTIONS],[ dnl
+AC_DEFUN([_DO_MYSQL_PLUGIN_ACTIONS],[
  m4_ifdef([$10], [], [
-  if test "[$with_module_]m4_bpatsubst([$1], -, _)" = yes; then
-    if test -z "[$plugin_]m4_bpatsubst([$1], -, _)[_static_target]" -a \
-            -z "[$plugin_]m4_bpatsubst([$1], -, _)[_shared_target]"; then
-      AC_MSG_ERROR([thats strange, $1 failed sanity check])
+  if test "[$with_module_]$2" = yes; then
+    if test -z "[$plugin_]$2[_static_target]" -a \
+            -z "[$plugin_]$2[_shared_target]"; then
+      AC_MSG_ERROR([that's strange, $1 failed sanity check])
     fi
     $11
-  fi dnl
- ]) dnl
+  fi
+ ])
 ])
 
 
@@ -395,17 +402,17 @@ dnl  Private helper macros
 dnl ===========================================================================
 
 
-AC_DEFUN([REQUIRE_PLUGIN],[ dnl
- _REQUIRE_PLUGIN([$1], [__MYSQL_MODULE_]AS_TR_CPP([$1])[__]) dnl
+AC_DEFUN([REQUIRE_PLUGIN],[
+ _REQUIRE_PLUGIN([$1], [__MYSQL_MODULE_]AS_TR_CPP([$1])[__])
 ])
 
-define([_REQUIRE_PLUGIN],[ dnl
- ifdef([$2],[ dnl
-  ifelse($2, [$1], [], [ dnl
-   AC_FATAL([[Misspelt MYSQL_MODULE declaration for ]][$1]) dnl
-  ]) dnl
- ],[ dnl
-  AC_FATAL([[Missing MYSQL_MODULE declaration for ]][$1]) dnl
+define([_REQUIRE_PLUGIN],[
+ ifdef([$2],[
+  ifelse($2, [$1], [], [
+   AC_FATAL([[Misspelt MYSQL_MODULE declaration for ]][$1])
+  ])
+ ],[
+  AC_FATAL([[Missing MYSQL_MODULE declaration for ]][$1])
  ])
 ])
 
@@ -413,85 +420,85 @@ define([_REQUIRE_PLUGIN],[ dnl
 dnl ---------------------------------------------------------------------------
 
 
-AC_DEFUN([_MYSQL_MODULE_META_CHECK], [ifelse($#, 0, [], $#, 1, dnl
-[_MYSQL_CHECK_PLUGIN_META([$1], [__mysql_]m4_bpatsubst($1, -, _)[_plugins__]) dnl
-], dnl
-[_MYSQL_CHECK_PLUGIN_META([$1], [__mysql_]m4_bpatsubst($1, -, _)[_plugins__]) dnl
-_MYSQL_MODULE_META_CHECK(m4_shift($@))]) dnl
+AC_DEFUN([_MYSQL_MODULE_META_CHECK], [ifelse($#, 0, [], $#, 1,
+[_MYSQL_CHECK_PLUGIN_META([$1], [__mysql_]m4_bpatsubst($1, -, _)[_plugins__])
+],
+[_MYSQL_CHECK_PLUGIN_META([$1], [__mysql_]m4_bpatsubst($1, -, _)[_plugins__])
+_MYSQL_MODULE_META_CHECK(m4_shift($@))])
 ])
 
 AC_DEFUN([_MYSQL_CHECK_PLUGIN_META], [
-  [$1] ) dnl
+  [$1] )
 m4_ifdef([$2], [
-    mysql_modules='m4_bpatsubst($2, :, [ ])' dnl
+    mysql_modules='m4_bpatsubst($2, :, [ ])'
 ],[
-    mysql_modules='' dnl
+    mysql_modules=''
 ])
-    ;; dnl
+    ;;
 ])
 
 
 dnl ---------------------------------------------------------------------------
 
 
-AC_DEFUN([_MYSQL_PLUGAPPEND],[ dnl
- m4_ifdef([$1],[ dnl
-  m4_define([__plugin_append_tmp__], m4_defn([$1])) dnl
-  m4_undefine([$1]) dnl
-  m4_define([$1], __plugin_append_tmp__[:$2]) dnl
-  m4_undefine([__plugin_append_tmp__]) dnl
- ],[ dnl
-  m4_define([$1], [$2]) dnl
-  $3 dnl
- ]) dnl
+AC_DEFUN([_MYSQL_PLUGAPPEND],[
+ m4_ifdef([$1],[
+  m4_define([__plugin_append_tmp__], m4_defn([$1]))
+  m4_undefine([$1])
+  m4_define([$1], __plugin_append_tmp__[:$2])
+  m4_undefine([__plugin_append_tmp__])
+ ],[
+  m4_define([$1], [$2])
+  $3
+ ])
 ])
 
-AC_DEFUN([_MYSQL_PLUGAPPEND_OPTS],[ dnl
- ifelse($#, 0, [], $#, 1, [ dnl
+AC_DEFUN([_MYSQL_PLUGAPPEND_OPTS],[
+ ifelse($#, 0, [], $#, 1, [
   AC_FATAL([[bad number of args]])
- ], $#, 2, [ dnl
-  _MYSQL_PLUGAPPEND_OPTONE([$1],[$2]) dnl
- ],[ dnl
-  _MYSQL_PLUGAPPEND_OPTONE([$1],[$2]) dnl
+ ], $#, 2, [
+  _MYSQL_PLUGAPPEND_OPTONE([$1],[$2])
+ ],[
+  _MYSQL_PLUGAPPEND_OPTONE([$1],[$2])
   _MYSQL_PLUGAPPEND_OPTS([$1], m4_shift(m4_shift($@)))
  ])
 ])
 
-AC_DEFUN([_MYSQL_PLUGAPPEND_OPTONE],[ dnl
- ifelse([$2], [all], [ dnl
-  AC_FATAL([[protected plugin group: all]]) dnl
- ],[ dnl
-  ifelse([$2], [none], [ dnl
-   AC_FATAL([[protected plugin group: none]]) dnl
-  ],[ dnl
-   _MYSQL_PLUGAPPEND([__mysql_$1_configs__],[$2]) dnl
-   _MYSQL_PLUGAPPEND([__mysql_]m4_bpatsubst($2, -, _)[_plugins__],[$1], [ dnl
-    _MYSQL_PLUGAPPEND([__mysql_metaplugin_list__],[$2]) dnl
-   ]) dnl
-  ]) dnl
- ]) dnl
+AC_DEFUN([_MYSQL_PLUGAPPEND_OPTONE],[
+ ifelse([$2], [all], [
+  AC_FATAL([[protected plugin group: all]])
+ ],[
+  ifelse([$2], [none], [
+   AC_FATAL([[protected plugin group: none]])
+  ],[
+   _MYSQL_PLUGAPPEND([__mysql_$1_configs__],[$2])
+   _MYSQL_PLUGAPPEND([__mysql_]m4_bpatsubst($2, -, _)[_plugins__],[$1], [
+    _MYSQL_PLUGAPPEND([__mysql_metaplugin_list__],[$2])
+   ])
+  ])
+ ])
 ])
 
 
 dnl ---------------------------------------------------------------------------
 
 
-AC_DEFUN([MYSQL_LIST_PLUGINS],[ dnl
- m4_ifdef([__mysql_plugin_list__],[ dnl
-  _MYSQL_LIST_PLUGINS(m4_bpatsubst(__mysql_plugin_list__, :, [,])) dnl
- ]) dnl
+AC_DEFUN([MYSQL_LIST_PLUGINS],[dnl
+ m4_ifdef([__mysql_plugin_list__],[dnl
+  _MYSQL_LIST_PLUGINS(m4_bpatsubst(__mysql_plugin_list__, :, [,]))dnl
+ ])dnl
 ])
 
-AC_DEFUN([_MYSQL_LIST_PLUGINS],[ dnl
- ifelse($#, 0, [], $#, 1, [ dnl
-  MYSQL_SHOW_PLUGIN([$1]) dnl
- ],[ dnl
-  MYSQL_SHOW_PLUGIN([$1]) dnl
-  _MYSQL_LIST_PLUGINS(m4_shift($@)) dnl
- ]) dnl
+AC_DEFUN([_MYSQL_LIST_PLUGINS],[dnl
+ ifelse($#, 0, [], $#, 1, [dnl
+  MYSQL_SHOW_PLUGIN([$1])dnl
+ ],[dnl
+  MYSQL_SHOW_PLUGIN([$1])dnl
+  _MYSQL_LIST_PLUGINS(m4_shift($@))dnl
+ ])dnl
 ])
 
-AC_DEFUN([MYSQL_SHOW_PLUGIN],[ dnl
+AC_DEFUN([MYSQL_SHOW_PLUGIN],[
  _MYSQL_SHOW_PLUGIN(
   [$1],
   [$1-plugin],
@@ -508,19 +515,20 @@ AC_DEFUN([MYSQL_SHOW_PLUGIN],[ dnl
  )
 ])
 
-AC_DEFUN([_MYSQL_SHOW_PLUGIN],[
-  === Plug-in: $3 ===
+AC_DEFUN([_MYSQL_SHOW_PLUGIN],[dnl
+  === Plugin: $3 ===
   Module Name:      [$1]
   Description:      $4
-  Supports build:   _PLUGIN_BUILD_TYPE([$7],[$8]) dnl
+  Supports build:   _PLUGIN_BUILD_TYPE([$7],[$8])[]dnl
 m4_ifdef([$12],[
-  Configurations:   m4_bpatsubst($12, :, [, ])]) dnl
+  Configurations:   m4_bpatsubst($12, :, [, ])])[]dnl
 m4_ifdef([$10],[
-  Status:           disabled], [ dnl
+  Status:           disabled])[]dnl
 m4_ifdef([$9],[
-  Status:           mandatory])])])
+  Status:           mandatory])[]dnl
+])
 
-AC_DEFUN([_PLUGIN_BUILD_TYPE], dnl
+AC_DEFUN([_PLUGIN_BUILD_TYPE],
 [m4_ifdef([$1],[ifelse($1,[no],[],[static ]m4_ifdef([$2],[and dnl
 ]))])[]m4_ifdef([$2],[dynamic],[m4_ifdef([$1],[],[static])])])
 
@@ -528,108 +536,107 @@ AC_DEFUN([_PLUGIN_BUILD_TYPE], dnl
 dnl ---------------------------------------------------------------------------
 
 
-AC_DEFUN([_MYSQL_MODULE_ARGS_CHECK],[ dnl
- ifelse($#, 0, [], $#, 1, [ dnl
+AC_DEFUN([_MYSQL_MODULE_ARGS_CHECK],[
+ ifelse($#, 0, [], $#, 1, [
   _MYSQL_CHECK_PLUGIN_ARG([$1],
    [MYSQL_MODULE_DISABLED_]AS_TR_CPP([$1]),
-   [MYSQL_MODULE_ACTIONS_]AS_TR_CPP([$1])) dnl
- ],[ dnl
-  _MYSQL_CHECK_PLUGIN_ARG([$1],
-   [MYSQL_MODULE_DISABLED_]AS_TR_CPP([$1]),
-   [MYSQL_MODULE_ACTIONS_]AS_TR_CPP([$1])) dnl
-  _MYSQL_MODULE_ARGS_CHECK(m4_shift($@)) dnl
- ]) dnl
-])
-
-AC_DEFUN([_MYSQL_CHECK_PLUGIN_ARG],[ dnl
- m4_ifdef([$3], [], [m4_define([$3],[ ])])
-    [$1] ) dnl
- m4_ifdef([$2],[
-      AC_MSG_ERROR([plugin $1 is disabled]) dnl
+   [MYSQL_MODULE_ACTIONS_]AS_TR_CPP([$1]))
  ],[
-      [mysql_module_]m4_bpatsubst([$1], -, _)=yes dnl
+  _MYSQL_CHECK_PLUGIN_ARG([$1],
+   [MYSQL_MODULE_DISABLED_]AS_TR_CPP([$1]),
+   [MYSQL_MODULE_ACTIONS_]AS_TR_CPP([$1]))
+  _MYSQL_MODULE_ARGS_CHECK(m4_shift($@))
  ])
-      ;; dnl
 ])
 
-AC_DEFUN([_MYSQL_SANE_VARS], [ dnl
- ifelse($#, 0, [], $#, 1, [ dnl
-  _MYSQL_SANEVAR([$1]) dnl
- ],[ dnl
-  _MYSQL_SANEVAR([$1]) dnl
-  _MYSQL_SANE_VARS(m4_shift($@)) dnl
- ]) dnl
+AC_DEFUN([_MYSQL_CHECK_PLUGIN_ARG],[
+ m4_ifdef([$3], [], [m4_define([$3],[ ])])
+    [$1] )
+ m4_ifdef([$2],[
+      AC_MSG_ERROR([plugin $1 is disabled])
+ ],[
+      [mysql_module_]m4_bpatsubst([$1], -, _)=yes
+ ])
+      ;;
+])
+
+AC_DEFUN([_MYSQL_SANE_VARS], [
+ ifelse($#, 0, [], $#, 1, [
+  _MYSQL_SANEVAR([$1])
+ ],[
+  _MYSQL_SANEVAR([$1])
+  _MYSQL_SANE_VARS(m4_shift($@))
+ ])
 ])
 
 AC_DEFUN([_MYSQL_SANEVAR], [
-   test -z "[$mysql_module_]m4_bpatsubst([$1], -, _)" && dnl
+   test -z "[$mysql_module_]m4_bpatsubst([$1], -, _)" &&
 [mysql_module_]m4_bpatsubst([$1], -, _)='.'
-   test -z "[$with_module_]m4_bpatsubst([$1], -, _)" && dnl
-[with_module_]m4_bpatsubst([$1], -, _)='.' dnl
+   test -z "[$with_module_]m4_bpatsubst([$1], -, _)" &&
+[with_module_]m4_bpatsubst([$1], -, _)='.'
 ])
 
-AC_DEFUN([_MYSQL_CHECK_DEPENDENCIES], [ dnl
- ifelse($#, 0, [], $#, 1, [ dnl
-  _MYSQL_CHECK_DEPENDS([$1],[__mysql_plugdepends_$1__]) dnl
- ],[ dnl
-  _MYSQL_CHECK_DEPENDS([$1],[__mysql_plugdepends_$1__]) dnl
-  _MYSQL_CHECK_DEPENDENCIES(m4_shift($@)) dnl
- ]) dnl
+AC_DEFUN([_MYSQL_CHECK_DEPENDENCIES], [
+ ifelse($#, 0, [], $#, 1, [
+  _MYSQL_CHECK_DEPENDS([$1],[__mysql_plugdepends_$1__])
+ ],[
+  _MYSQL_CHECK_DEPENDS([$1],[__mysql_plugdepends_$1__])
+  _MYSQL_CHECK_DEPENDENCIES(m4_shift($@))
+ ])
 ])
 
-AC_DEFUN([_MYSQL_CHECK_DEPENDS], [ dnl
+AC_DEFUN([_MYSQL_CHECK_DEPENDS], [
  m4_ifdef([$2], [
    if test "[$mysql_module_]m4_bpatsubst([$1], -, _)" = yes -a \
            "[$with_module_]m4_bpatsubst([$1], -, _)" != no -o \
-           "[$with_module_]m4_bpatsubst([$1], -, _)" = yes; then dnl
+           "[$with_module_]m4_bpatsubst([$1], -, _)" = yes; then
      _MYSQL_GEN_DEPENDS(m4_bpatsubst($2, :, [,]))
-   fi dnl
- ]) dnl
+   fi
+ ])
 ])
 
-AC_DEFUN([_MYSQL_GEN_DEPENDS], [ dnl
- ifelse($#, 0, [], $#, 1, [ dnl
-  _MYSQL_GEN_DEPEND([$1]) dnl
- ],[ dnl
-  _MYSQL_GEN_DEPEND([$1]) dnl
-  _MYSQL_GEN_DEPENDS(m4_shift($@)) dnl
- ]) dnl
+AC_DEFUN([_MYSQL_GEN_DEPENDS], [
+ ifelse($#, 0, [], $#, 1, [
+  _MYSQL_GEN_DEPEND([$1])
+ ],[
+  _MYSQL_GEN_DEPEND([$1])
+  _MYSQL_GEN_DEPENDS(m4_shift($@))
+ ])
 ])
 
-AC_DEFUN([_MYSQL_GEN_DEPEND], [ dnl
+AC_DEFUN([_MYSQL_GEN_DEPEND], [
  m4_ifdef([MYSQL_MODULE_DISABLED_]AS_TR_CPP([$1]),[
-      AC_MSG_ERROR([depends upon disabled module $1]) dnl
+      AC_MSG_ERROR([depends upon disabled module $1])
  ],[
       [mysql_module_]m4_bpatsubst([$1], -, _)=yes
       if test "[$with_module_]m4_bpatsubst([$1], -, _)" = no; then
         AC_MSG_ERROR([depends upon disabled module $1])
-      fi dnl
- ]) dnl
+      fi
+ ])
 ])
 
 AC_DEFUN([_MYSQL_CHECK_PLUGIN_ARGS],[
- AC_ARG_WITH([modules], [
-   --with-modules=PLUGIN[[,PLUGIN..]]
-m4_text_wrap([Plugin modules to include in mysqld. (default is: $1)
-Must be configuration name or a comma seperated list of modules.],
-[                          ])
-m4_text_wrap([Available configurations are: ]
-m4_bpatsubst(m4_ifdef([__mysql_metaplugin_list__], dnl
-none:all:__mysql_metaplugin_list__,none:all), :, [ ])[.],
-[                          ])
-m4_text_wrap([Available plugin modules are: ] dnl
-m4_bpatsubst(__mysql_plugin_list__, :, [ ])[.], [                          ])
-  --without-module-PLUGIN
-m4_text_wrap([Disable the named module from being built. Otherwise, 
-for modules which are not selected for inclusion in mysqld will be 
-built dynamically (if supported)],[                          ])
-],[mysql_modules="`echo $withval | tr ',.:;*[]' '       '`"], 
-  [mysql_modules=['$1']])
+ AC_ARG_WITH([modules],
+AS_HELP_STRING([--with-modules=PLUGIN[[[[[,PLUGIN..]]]]]],
+ [Plugin modules to include in mysqld. (default is: $1) Must be a
+ configuration name or a comma separated list of modules.])
+AS_HELP_STRING([],[Available configurations are:] dnl
+m4_bpatsubst([none:all]m4_ifdef([__mysql_metaplugin_list__],
+__mysql_metaplugin_list__), :, [ ])[.])
+AS_HELP_STRING([],[Available plugin modules are:] dnl
+m4_bpatsubst(__mysql_plugin_list__, :, [ ])[.])
+AS_HELP_STRING([--without-module-PLUGIN],
+                [Disable the named module from being built. Otherwise, for
+                modules which are not selected for inclusion in mysqld will be
+                built dynamically (if supported)])
+AS_HELP_STRING([--with-module-PLUGIN],
+               [Forces the named module to be linked into mysqld statically.]),
+ [mysql_modules="`echo $withval | tr ',.:;*[]' '       '`"],
+ [mysql_modules=['$1']])
 
 m4_divert_once([HELP_VAR_END],[
 Description of plugin modules:
-m4_indir([MYSQL_LIST_PLUGINS])
-])
+MYSQL_LIST_PLUGINS])
 
   case "$mysql_modules" in
   all )
@@ -637,20 +644,17 @@ m4_indir([MYSQL_LIST_PLUGINS])
     ;;
   none )
     mysql_modules=''
-    ;; dnl
-m4_ifdef([__mysql_metaplugin_list__],[ dnl
-_MYSQL_MODULE_META_CHECK(m4_bpatsubst(__mysql_metaplugin_list__, :, [,])) dnl
+    ;;
+m4_ifdef([__mysql_metaplugin_list__],[
+_MYSQL_MODULE_META_CHECK(m4_bpatsubst(__mysql_metaplugin_list__, :, [,]))
 ])
   esac
 
   for plugin in $mysql_modules; do
     case "$plugin" in
-    all )
+    all | none )
       AC_MSG_ERROR([bad module name: $plugin])
       ;;
-    none )
-      AC_MSG_ERROR([bad module name: $plugin])
-      ;; dnl
 _MYSQL_MODULE_ARGS_CHECK(m4_bpatsubst(__mysql_plugin_list__, :, [,]))
     * )
       AC_MSG_ERROR([unknown plugin module: $plugin])
@@ -675,6 +679,11 @@ AC_DEFUN([_MYSQL_POST_PLUGIN_FIXUP],[
       AC_MSG_ERROR([don't know how to handle plugin dir $plugdir])      
       ;;    
     esac
+    if test -f "$srcdir/$plugdir/configure" ; then
+      other_configures="$other_configures $plugdir/configure"
+    else
+      ac_config_files="$ac_config_files $plugdir/Makefile"
+    fi
   done
   AC_SUBST(mysql_se_dirs)
   AC_SUBST(mysql_pg_dirs)
diff --git a/configure.in b/configure.in
index 7a279cb0b39..c2e35c1b6b6 100644
--- a/configure.in
+++ b/configure.in
@@ -104,7 +104,6 @@ MYSQL_MODULE_ACTIONS(innobase,  [
   AC_SUBST(innodb_includes)
   AC_SUBST(innodb_libs)
   AC_SUBST(innodb_system_libs)
-  other_configures="$other_configures storage/innobase/configure"
 ])
 
 MYSQL_STORAGE_ENGINE(myisam,no, [MyISAM Storage Engine],
@@ -1712,7 +1711,7 @@ fi
 
 # If we should allow error injection tests
 AC_ARG_WITH(error-inject,
-    [ --with-error-inject    Enable error injection in MySQL Server],
+    AC_HELP_STRING([--with-error-inject],[Enable error injection in MySQL Server]),
     [ with_error_inject=$withval ],
     [ with_error_inject=no ])
 
@@ -2338,14 +2337,14 @@ fi
 tools_dirs=""
 
 AC_ARG_WITH([mysqlmanager],
-  AC_HELP_STRING([--with-mysqlmanager], [Build the mysqlmanager binary: yes/no (default: build if server is built.)]),
-  [if test "x${withval}" != "xno"; then
-    tools_dirs="$tools_dirs server-tools"
-   fi],
-  [if test "x${with_server}" = "xyes"; then
-     tools_dirs="$tools_dirs server-tools"
-   fi]
-)
+  AC_HELP_STRING([--with-mysqlmanager], [Build the mysqlmanager binary: yes/no (default: build if server is built.)]),,)
+
+if test "$with_mysqlmanager" = "yes" -o \
+        '(' "$with_mysqlmanager:$with_server" = ":yes" -a \
+            -d "$srcdir/server-tools" ')' ; then
+  tools_dirs="$tools_dirs server-tools"
+  AC_CONFIG_FILES(server-tools/Makefile server-tools/instance-manager/Makefile)
+fi
 
 AC_SUBST(tools_dirs)
 
@@ -2633,28 +2632,18 @@ AC_SUBST(MAKE_BINARY_DISTRIBUTION_OPTIONS)
 
 # Output results
 AC_CONFIG_FILES(Makefile extra/Makefile mysys/Makefile dnl
- unittest/Makefile dnl
- unittest/mytap/Makefile unittest/mytap/t/Makefile dnl
+ unittest/Makefile unittest/mytap/Makefile unittest/mytap/t/Makefile dnl
  unittest/mysys/Makefile unittest/examples/Makefile dnl
- strings/Makefile regex/Makefile dnl
- storage/Makefile dnl
- storage/archive/Makefile storage/bdb/Makefile storage/blackhole/Makefile dnl
- storage/csv/Makefile storage/example/Makefile storage/heap/Makefile dnl
- storage/myisam/Makefile storage/myisammrg/Makefile dnl
+ strings/Makefile regex/Makefile storage/Makefile dnl
  man/Makefile BUILD/Makefile vio/Makefile dnl
  libmysql/Makefile client/Makefile dnl
  pstack/Makefile pstack/aout/Makefile sql/Makefile sql/share/Makefile dnl
  sql/sql_builtin.cc sql-common/Makefile dnl
- dbug/Makefile scripts/Makefile dnl
- include/Makefile dnl
- server-tools/Makefile server-tools/instance-manager/Makefile dnl
+ dbug/Makefile scripts/Makefile include/Makefile dnl
  tests/Makefile Docs/Makefile support-files/Makefile dnl
  support-files/MacOSX/Makefile mysql-test/Makefile dnl
  mysql-test/ndb/Makefile netware/Makefile dnl
- include/mysql_version.h dnl
- plugin/Makefile dnl
- plugin/fulltext/Makefile dnl
- win/Makefile)
+ include/mysql_version.h plugin/Makefile win/Makefile)
  AC_CONFIG_COMMANDS([default], , test -z "$CONFIG_HEADERS" || echo timestamp > stamp-h)
  AC_OUTPUT
 
diff --git a/plugin/Makefile.am b/plugin/Makefile.am
index 8b421e0ad5a..deb73c988b3 100644
--- a/plugin/Makefile.am
+++ b/plugin/Makefile.am
@@ -18,10 +18,8 @@
 
 AUTOMAKE_OPTIONS =	foreign
 
-# These are built from source in the Docs directory
 EXTRA_DIST =	fulltext/configure.in	
-SUBDIRS =	
-DIST_SUBDIRS = . fulltext
+SUBDIRS =	@mysql_pg_dirs@
 
 # Don't update the files from bitkeeper
 %::SCCS/s.%
diff --git a/sql/Makefile.am b/sql/Makefile.am
index 2665e3fcfd5..ba9b58c0c5e 100644
--- a/sql/Makefile.am
+++ b/sql/Makefile.am
@@ -52,10 +52,10 @@ noinst_HEADERS =	item.h item_func.h item_sum.h item_cmpfunc.h \
 			ha_heap.h ha_myisam.h ha_myisammrg.h ha_partition.h \
 			ha_innodb.h  ha_berkeley.h ha_federated.h \
 			ha_ndbcluster.h ha_ndbcluster_binlog.h \
-			ha_ndbcluster_tables.h
+			ha_ndbcluster_tables.h \
 			opt_range.h protocol.h rpl_tblmap.h \
 			log.h sql_show.h rpl_rli.h \
-			sql_select.h structs.h table.h sql_udf.h hash_filo.h\
+			sql_select.h structs.h table.h sql_udf.h hash_filo.h \
 			lex.h lex_symbol.h sql_acl.h sql_crypt.h  \
 			log_event.h sql_repl.h slave.h rpl_filter.h \
 			rpl_injector.h \
diff --git a/storage/archive/Makefile.am b/storage/archive/Makefile.am
index 0920fe1a897..4263d8f2659 100644
--- a/storage/archive/Makefile.am
+++ b/storage/archive/Makefile.am
@@ -20,7 +20,7 @@ MYSQLDATAdir =          $(localstatedir)
 MYSQLSHAREdir =         $(pkgdatadir)
 MYSQLBASEdir=           $(prefix)
 MYSQLLIBdir=            $(pkglibdir)
-INCLUDES =              -I$(top_srcdir)/include \
+INCLUDES =              -I$(top_srcdir)/include -I$(top_builddir)/include \
 			-I$(top_srcdir)/regex \
 			-I$(top_srcdir)/sql \
                         -I$(srcdir) @ZLIB_INCLUDES@
@@ -50,9 +50,9 @@ libarchive_a_SOURCES =	ha_archive.cc azio.c
 
 archive_test_SOURCES =	archive_test.c azio.c
 archive_test_CFLAGS =	$(AM_CFLAGS)
-archive_test_LDADD =	$(top_srcdir)/mysys/libmysys.a \
-			$(top_srcdir)/dbug/libdbug.a \
-			$(top_srcdir)/strings/libmystrings.a \
+archive_test_LDADD =	$(top_builddir)/mysys/libmysys.a \
+			$(top_builddir)/dbug/libdbug.a \
+			$(top_builddir)/strings/libmystrings.a \
 			@ZLIB_LIBS@
 archive_test_LDFLAGS = @NOINST_LDFLAGS@
 
diff --git a/storage/blackhole/Makefile.am b/storage/blackhole/Makefile.am
index 060eaffce66..3a235bc86dd 100644
--- a/storage/blackhole/Makefile.am
+++ b/storage/blackhole/Makefile.am
@@ -20,7 +20,7 @@ MYSQLDATAdir =          $(localstatedir)
 MYSQLSHAREdir =         $(pkgdatadir)
 MYSQLBASEdir=           $(prefix)
 MYSQLLIBdir=            $(pkglibdir)
-INCLUDES =              -I$(top_srcdir)/include \
+INCLUDES =              -I$(top_srcdir)/include -I$(top_builddir)/include \
 			-I$(top_srcdir)/regex \
 			-I$(top_srcdir)/sql \
                         -I$(srcdir)
diff --git a/storage/example/Makefile.am b/storage/example/Makefile.am
index 5565c5e85fc..f97dcc09e6b 100644
--- a/storage/example/Makefile.am
+++ b/storage/example/Makefile.am
@@ -20,7 +20,7 @@ MYSQLDATAdir =          $(localstatedir)
 MYSQLSHAREdir =         $(pkgdatadir)
 MYSQLBASEdir=           $(prefix)
 MYSQLLIBdir=            $(pkglibdir)
-INCLUDES =              -I$(top_srcdir)/include \
+INCLUDES =              -I$(top_srcdir)/include -I$(top_builddir)/include \
 			-I$(top_srcdir)/regex \
 			-I$(top_srcdir)/sql \
                         -I$(srcdir)
diff --git a/storage/innobase/Makefile.am b/storage/innobase/Makefile.am
index 7a999b2f4fe..908f5d669a2 100644
--- a/storage/innobase/Makefile.am
+++ b/storage/innobase/Makefile.am
@@ -98,13 +98,12 @@ libinnobase.a:		$(libinnobase_a_LIBADD)
 		-rm -f $@
 		if test "$(host_os)" = "netware" ; \
 		then \
-		  $(libmysqld_a_AR) $@ $(libinnobase_a_LIBADD) ; \
+		  $(libinnobase_a_AR) $@ $(libinnobase_a_LIBADD) ; \
 		else \
-		  (for arc in $(libinnobase_a_LIBADD); do \
-		    arpath=`echo $$arc|sed 's|[^/]*$$||'`; \
-		    $(AR) t $$arc|xargs -n 1 find $$arpath -name; \
-		    $(AR) t $$arc|xargs -n 1 find `dirname $$arpath` -path \*/`basename $$arpath`/\* -name; \
-		  done ) | sort -u | xargs $(AR) cq $@ ; \
+		  for arc in $(libinnobase_a_LIBADD); do \
+		     arpath=`echo $$arc|sed 's|[^/]*$$||'`; \
+		     $(AR) t $$arc|sed "s|^|$$arpath|"; \
+		  done | sort -u | xargs $(AR) cq $@ ; \
 		  $(RANLIB) $@	; \
 		fi
 

From 506f9800bd9fed00efb7f65a3dbc6030e5cbc895 Mon Sep 17 00:00:00 2001
From: "serg@sergbook.mysql.com" <>
Date: Sun, 30 Apr 2006 15:52:30 -0400
Subject: [PATCH 083/108] fixes

---
 .bzrignore                  |  3 ++
 Makefile.am                 |  4 +-
 config/ac-macros/plugins.m4 | 80 ++++++++++++++++++-------------------
 configure.in                |  5 +--
 plugin/Makefile.am          |  3 ++
 plugin/fulltext/Makefile.am | 47 +++-------------------
 sql/sql_show.cc             | 12 +-----
 7 files changed, 56 insertions(+), 98 deletions(-)

diff --git a/.bzrignore b/.bzrignore
index 751b823f1ea..cd5d285651e 100644
--- a/.bzrignore
+++ b/.bzrignore
@@ -1764,3 +1764,6 @@ unittest/examples/*.t
 unittest/mysys/*.t
 unittest/mytap/t/*.t
 unittest/unit
+compile
+libmysqld/sql_builtin.cc
+sql/sql_builtin.cc
diff --git a/Makefile.am b/Makefile.am
index b9775577110..8709fca34c3 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -24,11 +24,11 @@ EXTRA_DIST =		INSTALL-SOURCE INSTALL-WIN-SOURCE \
 SUBDIRS =		. include @docs_dirs@ @zlib_dir@ \
 			@readline_topdir@ sql-common \
 			@thread_dirs@ pstack \
-			@sql_union_dirs@ storage \
+			@sql_union_dirs@ storage plugin \
 			@sql_server@ scripts @man_dirs@ tests \
 			netware @libmysqld_dirs@ \
 			mysql-test support-files @tools_dirs@ \
-			plugin unittest win
+			unittest win
 
 DIST_SUBDIRS =		$(SUBDIRS) BUILD
 
diff --git a/config/ac-macros/plugins.m4 b/config/ac-macros/plugins.m4
index 51f83e19e5f..19b951ea467 100644
--- a/config/ac-macros/plugins.m4
+++ b/config/ac-macros/plugins.m4
@@ -32,8 +32,8 @@ AC_DEFUN([MYSQL_MODULE],[
 
 AC_DEFUN([_MYSQL_MODULE],[
  m4_ifdef([$2], [
-  AC_FATAL([[Duplicate MYSQL_MODULE declaration for ]][$3])
- ],[ dnl 
+  AC_FATAL([Duplicate MYSQL_MODULE declaration for $3])
+ ],[
   m4_define([$2], [$1])
   _MYSQL_PLUGAPPEND([__mysql_plugin_list__],[$1])
   m4_define([MYSQL_MODULE_NAME_]AS_TR_CPP([$1]), [$3])
@@ -57,13 +57,14 @@ AC_DEFUN([MYSQL_STORAGE_ENGINE],[
  MYSQL_MODULE([$1], [$3], [$4], [[$5]])
  MYSQL_MODULE_DEFINE([$1], [WITH_]AS_TR_CPP([$1])[_STORAGE_ENGINE])
  ifelse([$2],[no],[],[
-  _MYSQL_LEGACY_STORAGE_ENGINE([$1],m4_default([$2], [$1-storage-engine]))
+  _MYSQL_LEGACY_STORAGE_ENGINE(
+      m4_bpatsubst(m4_default([$2], [$1-storage-engine]), -, _))
  ])
 ])
 
 AC_DEFUN([_MYSQL_LEGACY_STORAGE_ENGINE],[
-if test "[${with_]m4_bpatsubst($2, -, _)[+set}]" = set; then
-  [with_module_]m4_bpatsubst($1, -, _)="[$with_]m4_bpatsubst($2, -, _)"
+if test "[${with_]$1[+set}]" = set; then
+  [with_module_]$1="[$with_]$1"
 fi
 ])
 
@@ -188,7 +189,7 @@ dnl ---------------------------------------------------------------------------
 AC_DEFUN([MYSQL_MODULE_DEPENDS],[
  REQUIRE_PLUGIN([$1])
  ifelse($#, 0, [], $#, 1, [
-  AC_FATAL([[bad number of arguments]])
+  AC_FATAL([bad number of arguments])
  ], $#, 2, [
   _MYSQL_MODULE_DEPEND([$1],[$2])
  ],[
@@ -238,7 +239,8 @@ AC_DEFUN([MYSQL_CONFIGURE_PLUGINS],[
     _MYSQL_CHECK_PLUGIN_ARGS([$1])
     _MYSQL_CONFIGURE_PLUGINS(m4_bpatsubst(__mysql_plugin_list__, :, [,]))
     _MYSQL_DO_PLUGIN_ACTIONS(m4_bpatsubst(__mysql_plugin_list__, :, [,]))
-    _MYSQL_POST_PLUGIN_FIXUP()
+    AC_SUBST([mysql_se_dirs])
+    AC_SUBST([mysql_pg_dirs])
    ])
  ])
 ])
@@ -273,16 +275,19 @@ AC_DEFUN([_DO_MYSQL_CHECK_PLUGIN],[
   AH_TEMPLATE($5, [Include ]$4[ into mysqld])
  ])
  AC_MSG_CHECKING([whether to use ]$3)
+ mysql_use_plugin_dir=""
  m4_ifdef([$10],[
   if test "[$mysql_module_]$2" = yes -a \
           "[$with_module_]$2" != no -o \
           "[$with_module_]$2" = yes; then
+    AC_MSG_RESULT([error])
     AC_MSG_ERROR([disabled])
   fi
   AC_MSG_RESULT([no])
  ],[
   m4_ifdef([$9],[
    if test "[$with_module_]$2" = no; then
+     AC_MSG_RESULT([error])
      AC_MSG_ERROR([cannot disable mandatory module])
    fi
    [mysql_module_]$2=yes
@@ -295,7 +300,7 @@ AC_DEFUN([_DO_MYSQL_CHECK_PLUGIN],[
       m4_ifdef([$8],[
        m4_ifdef([$6],[
          if test -d "$srcdir/$6" ; then
-           mysql_plugin_dirs="$mysql_plugin_dirs $6"
+           mysql_use_plugin_dir="$6"
        ])
        AC_SUBST([plugin_]$2[_shared_target], "$8")
        AC_SUBST([plugin_]$2[_static_target], [""])
@@ -315,19 +320,19 @@ AC_DEFUN([_DO_MYSQL_CHECK_PLUGIN],[
       m4_ifdef([$7],[
        ifelse(m4_bregexp($7, [^lib[^.]+\.a$]), -2, [
         m4_ifdef([$6],[
-         mysql_plugin_dirs="$mysql_plugin_dirs $6"
+         mysql_use_plugin_dir="$6"
          mysql_plugin_libs="$mysql_plugin_libs -L[\$(top_builddir)]/$6"
         ])
         mysql_plugin_libs="$mysql_plugin_libs
 [-l]m4_bregexp($7, [^lib\([^.]+\)], [\1])"
        ], m4_bregexp($7, [^\\\$]), 0, [
         m4_ifdef([$6],[
-         mysql_plugin_dirs="$mysql_plugin_dirs $6"
+         mysql_use_plugin_dir="$6"
         ])
         mysql_plugin_libs="$mysql_plugin_libs $7"
        ], [
         m4_ifdef([$6],[
-         mysql_plugin_dirs="$mysql_plugin_dirs $6"
+         mysql_use_plugin_dir="$6"
          mysql_plugin_libs="$mysql_plugin_libs \$(top_builddir)/$6/$7"
         ],[
          mysql_plugin_libs="$mysql_plugin_libs $7"
@@ -340,7 +345,8 @@ AC_DEFUN([_DO_MYSQL_CHECK_PLUGIN],[
        AC_SUBST([plugin_]$2[_shared_target], [""])
       ],[
        m4_ifdef([$6],[
-        AC_FATAL([plugin directory specified without library for ]$3)
+        AC_MSG_RESULT([error])
+        AC_MSG_ERROR([Plugin $1 does not support static linking])
        ],[
         m4_ifdef([$5],[
          AC_DEFINE($5)
@@ -353,6 +359,21 @@ AC_DEFUN([_DO_MYSQL_CHECK_PLUGIN],[
       [with_module_]$2=yes
       AC_MSG_RESULT([yes])
     fi
+    m4_ifdef([$6],[
+      if test -n "$mysql_use_plugin_dir" ; then
+        mysql_plugin_dirs="$mysql_plugin_dirs $6"
+        if test -f "$srcdir/$6/configure" ; then
+          other_configures="$other_configures $6/configure"
+        else
+          AC_CONFIG_FILES($6/Makefile)
+        fi
+        ifelse(m4_substr($6, 0, 8), [storage/],
+          [mysql_se_dirs="$mysql_se_dirs ]m4_substr($6, 8)",
+          m4_substr($6, 0, 7), [plugin/],
+          [mysql_pg_dirs="$mysql_pg_dirs ]m4_substr($6, 7)",
+          [AC_FATAL([don't know how to handle plugin dir ]$6)])
+      fi
+    ])
   fi
  ])
 ])
@@ -409,10 +430,10 @@ AC_DEFUN([REQUIRE_PLUGIN],[
 define([_REQUIRE_PLUGIN],[
  ifdef([$2],[
   ifelse($2, [$1], [], [
-   AC_FATAL([[Misspelt MYSQL_MODULE declaration for ]][$1])
+   AC_FATAL([Misspelt MYSQL_MODULE declaration for $1])
   ])
  ],[
-  AC_FATAL([[Missing MYSQL_MODULE declaration for ]][$1])
+  AC_FATAL([Missing MYSQL_MODULE declaration for $1])
  ])
 ])
 
@@ -455,7 +476,7 @@ AC_DEFUN([_MYSQL_PLUGAPPEND],[
 
 AC_DEFUN([_MYSQL_PLUGAPPEND_OPTS],[
  ifelse($#, 0, [], $#, 1, [
-  AC_FATAL([[bad number of args]])
+  AC_FATAL([bad number of args])
  ], $#, 2, [
   _MYSQL_PLUGAPPEND_OPTONE([$1],[$2])
  ],[
@@ -466,10 +487,10 @@ AC_DEFUN([_MYSQL_PLUGAPPEND_OPTS],[
 
 AC_DEFUN([_MYSQL_PLUGAPPEND_OPTONE],[
  ifelse([$2], [all], [
-  AC_FATAL([[protected plugin group: all]])
+  AC_FATAL([protected plugin group: all])
  ],[
   ifelse([$2], [none], [
-   AC_FATAL([[protected plugin group: none]])
+   AC_FATAL([protected plugin group: none])
   ],[
    _MYSQL_PLUGAPPEND([__mysql_$1_configs__],[$2])
    _MYSQL_PLUGAPPEND([__mysql_]m4_bpatsubst($2, -, _)[_plugins__],[$1], [
@@ -516,7 +537,7 @@ AC_DEFUN([MYSQL_SHOW_PLUGIN],[
 ])
 
 AC_DEFUN([_MYSQL_SHOW_PLUGIN],[dnl
-  === Plugin: $3 ===
+  === $3 ===
   Module Name:      [$1]
   Description:      $4
   Supports build:   _PLUGIN_BUILD_TYPE([$7],[$8])[]dnl
@@ -666,27 +687,4 @@ _MYSQL_MODULE_ARGS_CHECK(m4_bpatsubst(__mysql_plugin_list__, :, [,]))
   _MYSQL_CHECK_DEPENDENCIES(m4_bpatsubst(__mysql_plugin_list__, :, [,]))
 ])
 
-AC_DEFUN([_MYSQL_POST_PLUGIN_FIXUP],[
-  for plugdir in $mysql_plugin_dirs; do
-    case "$plugdir" in
-    storage/* )
-      mysql_se_dirs="$mysql_se_dirs `echo $plugdir | sed -e 's@^storage/@@'`"
-      ;;
-    plugin/* )
-      mysql_pg_dirs="$mysql_pg_dirs `echo $plugdir | sed -e 's@^plugin/@@'`"
-      ;;
-    *)
-      AC_MSG_ERROR([don't know how to handle plugin dir $plugdir])      
-      ;;    
-    esac
-    if test -f "$srcdir/$plugdir/configure" ; then
-      other_configures="$other_configures $plugdir/configure"
-    else
-      ac_config_files="$ac_config_files $plugdir/Makefile"
-    fi
-  done
-  AC_SUBST(mysql_se_dirs)
-  AC_SUBST(mysql_pg_dirs)
-])
-
 dnl ===========================================================================
diff --git a/configure.in b/configure.in
index c2e35c1b6b6..78a0ea5f7b2 100644
--- a/configure.in
+++ b/configure.in
@@ -87,8 +87,7 @@ MYSQL_STORAGE_ENGINE(federated,,[Federated Storage Engine],
 MYSQL_MODULE(ftexample,         [Simple Parser],
         [Simple full-text parser plugin])
 MYSQL_MODULE_DIRECTORY(ftexample, [plugin/fulltext])
-MYSQL_MODULE_STATIC(ftexample,  [libftexample.a])
-MYSQL_MODULE_DYNAMIC(ftexample, [ft_example.la])
+MYSQL_MODULE_DYNAMIC(ftexample, [mypluglib.la])
 
 MYSQL_STORAGE_ENGINE(heap,no,   [Memory Storage Engine],
         [In memory hashed tables])
@@ -101,8 +100,6 @@ MYSQL_MODULE_DIRECTORY(innobase, [storage/innobase])
 MYSQL_MODULE_STATIC(innobase,   [libinnobase.a])
 MYSQL_MODULE_ACTIONS(innobase,  [
   AC_CHECK_LIB(rt, aio_read, [innodb_system_libs="-lrt"])
-  AC_SUBST(innodb_includes)
-  AC_SUBST(innodb_libs)
   AC_SUBST(innodb_system_libs)
 ])
 
diff --git a/plugin/Makefile.am b/plugin/Makefile.am
index deb73c988b3..6dee710103e 100644
--- a/plugin/Makefile.am
+++ b/plugin/Makefile.am
@@ -18,7 +18,10 @@
 
 AUTOMAKE_OPTIONS =	foreign
 
+# extra plugin example files are listed here, to
+# keep its Makefile.am cleaner as a template
 EXTRA_DIST =	fulltext/configure.in	
+
 SUBDIRS =	@mysql_pg_dirs@
 
 # Don't update the files from bitkeeper
diff --git a/plugin/fulltext/Makefile.am b/plugin/fulltext/Makefile.am
index 331db7c98f8..4df5a1dc78a 100644
--- a/plugin/fulltext/Makefile.am
+++ b/plugin/fulltext/Makefile.am
@@ -1,44 +1,9 @@
 #Makefile.am example for a plugin
 
-#MYSQL_MODULE(ftexample,         [Simple Parser],
-#        [Simple full-text parser plugin])
-#MYSQL_MODULE_DIRECTORY(ftexample, [plugin/fulltext])
-#MYSQL_MODULE_STATIC(ftexample,  [libftexample.a])
-#MYSQL_MODULE_DYNAMIC(ftexample, [ft_example.la])
+pkglibdir=$(libdir)/mysql
+INCLUDES= -I$(top_builddir)/include -I$(top_srcdir)/include
+noinst_LTLIBRARIES= mypluglib.la
+#pkglib_LTLIBRARIES= mypluglib.la
+mypluglib_la_SOURCES= plugin_example.c
+mypluglib_la_LDFLAGS= -module -rpath $(pkglibdir)
 
-
-#called from the top level Makefile
-
-MYSQLDATAdir =          $(localstatedir)
-MYSQLSHAREdir =         $(pkgdatadir)
-MYSQLBASEdir=           $(prefix)
-MYSQLLIBdir=            $(pkglibdir)
-INCLUDES =              -I$(top_srcdir)/include \
-			-I$(top_srcdir)/regex \
-			-I$(top_srcdir)/sql \
-                        -I$(srcdir)
-WRAPLIBS=
-
-LDADD =
-
-DEFS =                  @DEFS@
-
-noinst_HEADERS =	
-
-EXTRA_LTLIBRARIES =	ft_example.la
-pkglib_LTLIBRARIES =	@plugin_ftexample_shared_target@
-ft_example_la_LDFLAGS =	-module -rpath $(MYSQLLIBdir)
-ft_example_la_CXXFLAGS=	$(AM_CFLAGS) -DMYSQL_DYNAMIC_PLUGIN
-ft_example_la_CFLAGS=	$(AM_CFLAGS) -DMYSQL_DYNAMIC_PLUGIN
-ft_example_la_SOURCES =	plugin_example.c
-
-
-EXTRA_LIBRARIES =	libftexample.a
-noinst_LIBRARIES =	@plugin_ftexample_static_target@
-libftexample_a_CXXFLAGS=$(AM_CFLAGS)
-libftexample_a_CFLAGS =	$(AM_CFLAGS)
-libftexample_a_SOURCES=	plugin_example.c
-
-
-# Don't update the files from bitkeeper
-%::SCCS/s.%
diff --git a/sql/sql_show.cc b/sql/sql_show.cc
index 042c0397be3..da5ed3e46f8 100644
--- a/sql/sql_show.cc
+++ b/sql/sql_show.cc
@@ -111,10 +111,6 @@ static my_bool show_plugins(THD *thd, st_plugin_int *plugin,
   CHARSET_INFO *cs= system_charset_info;
   char version_buf[20];
 
-  /* we normally hide all the built-in plugins */
-  if (!plugin->plugin_dl && !thd->lex->verbose)
-    return 0;
-
   restore_record(table, s->default_values);
 
   table->field[0]->store(plugin->name.str, plugin->name.length, cs);
@@ -123,7 +119,7 @@ static my_bool show_plugins(THD *thd, st_plugin_int *plugin,
         make_version_string(version_buf, sizeof(version_buf), plug->version),
         cs);
 
-    
+
   switch (plugin->state)
   {
   /* case PLUGIN_IS_FREED: does not happen */
@@ -3042,12 +3038,8 @@ static my_bool iter_schema_engines(THD *thd, st_plugin_int *plugin,
 
 int fill_schema_engines(THD *thd, TABLE_LIST *tables, COND *cond)
 {
-  const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NullS;
-  TABLE *table= tables->table;
-  CHARSET_INFO *scs= system_charset_info;
-
   return plugin_foreach(thd, iter_schema_engines, 
-                        MYSQL_STORAGE_ENGINE_PLUGIN, table);
+                        MYSQL_STORAGE_ENGINE_PLUGIN, tables->table);
 }
 
 

From 08eb2588bffdf1b5a2f06ee1a6e5d7c189ed2201 Mon Sep 17 00:00:00 2001
From: "jimw@mysql.com" <>
Date: Sun, 30 Apr 2006 13:06:28 -0700
Subject: [PATCH 084/108] Fix error in having.test to use name instead of
 number (fixes merge problem)

---
 mysql-test/t/having.test | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mysql-test/t/having.test b/mysql-test/t/having.test
index 9bea78a7bca..41266cc6d32 100644
--- a/mysql-test/t/having.test
+++ b/mysql-test/t/having.test
@@ -401,7 +401,7 @@ create table t1(f1 int);
 select f1 from t1 having max(f1)=f1;
 select f1 from t1 group by f1 having max(f1)=f1;
 set session sql_mode='ONLY_FULL_GROUP_BY';
---error 1463
+--error ER_NON_GROUPING_FIELD_USED
 select f1 from t1 having max(f1)=f1;
 select f1 from t1 group by f1 having max(f1)=f1;
 set session sql_mode='';

From b4586b290808b90ab0affecebc059b5ec69d6673 Mon Sep 17 00:00:00 2001
From: "jimw@mysql.com" <>
Date: Mon, 1 May 2006 00:14:32 -0700
Subject: [PATCH 085/108] Clean up after big merge

---
 config/ac-macros/yassl.m4       | 5 ++++-
 mysql-test/lib/mtr_process.pl   | 1 +
 mysql-test/mysql-test-run.pl    | 7 ++++---
 mysql-test/r/rpl_openssl.result | 2 +-
 sql/mysqld.cc                   | 2 +-
 sql/set_var.cc                  | 1 -
 6 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/config/ac-macros/yassl.m4 b/config/ac-macros/yassl.m4
index 906a65a2fc3..f6eee32ff84 100644
--- a/config/ac-macros/yassl.m4
+++ b/config/ac-macros/yassl.m4
@@ -11,8 +11,11 @@ AC_DEFUN([MYSQL_CHECK_YASSL], [
     AC_MSG_RESULT([using bundled yaSSL])
     AC_CONFIG_FILES(extra/yassl/Makefile dnl
     extra/yassl/taocrypt/Makefile dnl
+    extra/yassl/taocrypt/benchmark/Makefile dnl
     extra/yassl/taocrypt/src/Makefile dnl
-    extra/yassl/src/Makefile)
+    extra/yassl/taocrypt/test/Makefile dnl
+    extra/yassl/src/Makefile dnl
+    extra/yassl/testsuite/Makefile)
     yassl_dir="yassl"
     yassl_libs="-L\$(top_srcdir)/extra/yassl/src -lyassl -L\$(top_srcdir)/extra/yassl/taocrypt/src -ltaocrypt"
     yassl_includes="-I\$(top_srcdir)/extra/yassl/include"
diff --git a/mysql-test/lib/mtr_process.pl b/mysql-test/lib/mtr_process.pl
index d1d74ec9a61..a3fb7ec0183 100644
--- a/mysql-test/lib/mtr_process.pl
+++ b/mysql-test/lib/mtr_process.pl
@@ -672,6 +672,7 @@ sub mtr_mysqladmin_shutdown {
     # Shutdown time must be high as slave may be in reconnect
     mtr_add_arg($args, "--shutdown_timeout=$adm_shutdown_tmo");
     mtr_add_arg($args, "shutdown");
+    my $path_mysqladmin_log= "$::opt_vardir/log/mysqladmin.log";
     # Start mysqladmin in paralell and wait for termination later
     my $pid= mtr_spawn($::exe_mysqladmin, $args,
                        "", $path_mysqladmin_log, $path_mysqladmin_log, "",
diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl
index fc8495e6acc..30ac61c80e8 100755
--- a/mysql-test/mysql-test-run.pl
+++ b/mysql-test/mysql-test-run.pl
@@ -428,7 +428,8 @@ sub main () {
       $need_im||= $test->{component_id} eq 'im';
       $use_slaves||= $test->{slave_num};
     }
-    $opt_with_ndbcluster= 0 unless $need_ndbcluster;
+    $opt_with_ndbcluster= $opt_with_ndbcluster_slave= 0
+      unless $need_ndbcluster;
     $opt_skip_im= 1 unless $need_im;
 
     snapshot_setup();
@@ -3234,8 +3235,8 @@ sub run_mysqltest ($) {
   $ENV{'UDF_EXAMPLE_LIB'}=
     ($lib_udf_example ? basename($lib_udf_example) : "");
 
-  $ENV{'NDB_STATUS_OK'}=            $flag_ndb_status_ok;
-  $ENV{'NDB_SLAVE_STATUS_OK'}=      $flag_ndb_slave_status_ok;
+  $ENV{'NDB_STATUS_OK'}=            $flag_ndb_status_ok ? "YES" : "NO";
+  $ENV{'NDB_SLAVE_STATUS_OK'}=      $flag_ndb_slave_status_ok ? "YES" : "NO";
   $ENV{'NDB_EXTRA_TEST'}=           $opt_ndb_extra_test;
   $ENV{'NDB_MGM'}=                  $exe_ndb_mgm;
   $ENV{'NDB_BACKUP_DIR'}=           $path_ndb_data_dir;
diff --git a/mysql-test/r/rpl_openssl.result b/mysql-test/r/rpl_openssl.result
index 1bd28415434..4fe02088632 100644
--- a/mysql-test/r/rpl_openssl.result
+++ b/mysql-test/r/rpl_openssl.result
@@ -28,4 +28,4 @@ drop user replssl@localhost;
 drop table t1;
 show slave status;
 Slave_IO_State	Master_Host	Master_User	Master_Port	Connect_Retry	Master_Log_File	Read_Master_Log_Pos	Relay_Log_File	Relay_Log_Pos	Relay_Master_Log_File	Slave_IO_Running	Slave_SQL_Running	Replicate_Do_DB	Replicate_Ignore_DB	Replicate_Do_Table	Replicate_Ignore_Table	Replicate_Wild_Do_Table	Replicate_Wild_Ignore_Table	Last_Errno	Last_Error	Skip_Counter	Exec_Master_Log_Pos	Relay_Log_Space	Until_Condition	Until_Log_File	Until_Log_Pos	Master_SSL_Allowed	Master_SSL_CA_File	Master_SSL_CA_Path	Master_SSL_Cert	Master_SSL_Cipher	Master_SSL_Key	Seconds_Behind_Master
-#	127.0.0.1	root	MASTER_MYPORT	1	master-bin.000001	564	#	#	master-bin.000001	Yes	Yes							0		0	564	#	None		0	No	MYSQL_TEST_DIR/std_data/cacert.pem		MYSQL_TEST_DIR/std_data/client-cert.pem		MYSQL_TEST_DIR/std_data/client-key.pem	#
+#	127.0.0.1	root	MASTER_MYPORT	1	#	#	#	#	#	#	Yes				#			0		0	#	#	None		0	No	MYSQL_TEST_DIR/std_data/cacert.pem		MYSQL_TEST_DIR/std_data/client-cert.pem		MYSQL_TEST_DIR/std_data/client-key.pem	#
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index d4f65b5ae69..4de1e95d0f3 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -579,7 +579,7 @@ CHARSET_INFO *character_set_filesystem;
 
 SHOW_COMP_OPTION have_row_based_replication;
 SHOW_COMP_OPTION have_openssl, have_symlink, have_dlopen, have_query_cache;
-SHOW_COMP_OPTION have_geometry, have_rtree_keys, have_dlopen;
+SHOW_COMP_OPTION have_geometry, have_rtree_keys;
 SHOW_COMP_OPTION have_crypt, have_compress;
 
 /* Thread specific variables */
diff --git a/sql/set_var.cc b/sql/set_var.cc
index 87d129c5a4a..ae45b299196 100644
--- a/sql/set_var.cc
+++ b/sql/set_var.cc
@@ -910,7 +910,6 @@ SHOW_VAR init_vars[]= {
    SHOW_SYS},
   {"pid_file",                (char*) pidfile_name,                 SHOW_CHAR},
   {"plugin_dir",              (char*) opt_plugin_dir,               SHOW_CHAR},
-  {sys_prepared_stmt_count.name, (char*) &sys_prepared_stmt_count, SHOW_SYS},
   {"port",                    (char*) &mysqld_port,                  SHOW_INT},
   {sys_preload_buff_size.name, (char*) &sys_preload_buff_size,      SHOW_SYS},
   {sys_prepared_stmt_count.name, (char*) &sys_prepared_stmt_count, SHOW_SYS},

From 9b832153f9d43281f0506b0a968754c357ef6e00 Mon Sep 17 00:00:00 2001
From: "holyfoot@deer.(none)" <>
Date: Mon, 1 May 2006 22:16:08 +0500
Subject: [PATCH 086/108] Fix for Win build

---
 .bzrignore             | 1 +
 client/mysql_upgrade.c | 6 ++++--
 include/config-win.h   | 1 +
 3 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/.bzrignore b/.bzrignore
index 352629ab5c5..80ed7872005 100644
--- a/.bzrignore
+++ b/.bzrignore
@@ -1281,3 +1281,4 @@ mysql-test/r/udf.log
 extra/yassl/taocrypt/benchmark/benchmark
 extra/yassl/taocrypt/test/test
 extra/yassl/testsuite/testsuite
+client/mysql_upgrade
diff --git a/client/mysql_upgrade.c b/client/mysql_upgrade.c
index 78e4acd4c1d..551be79fc99 100644
--- a/client/mysql_upgrade.c
+++ b/client/mysql_upgrade.c
@@ -135,7 +135,9 @@ static int create_check_file(const char *path)
   if (check_file < 0)
     return 1;
 
-  error= my_write(check_file, VERSION, strlen(VERSION), MYF(MY_WME | MY_FNABP));
+  error= my_write(check_file,
+                  MYSQL_SERVER_VERSION, strlen(MYSQL_SERVER_VERSION),
+                  MYF(MY_WME | MY_FNABP));
   error= my_close(check_file, MYF(MY_FAE | MY_WME)) || error;
   return error;
 }
@@ -243,7 +245,7 @@ int main(int argc, char **argv)
         && (test_file_exists("./bin", "mysqld") ||
             test_file_exists("./libexec", "mysqld")))
     {
-      getcwd(bindir, sizeof(bindir));
+      my_getwd(bindir, sizeof(bindir), MYF(0));
       bindir_end= bindir + strlen(bindir);
     }
     else
diff --git a/include/config-win.h b/include/config-win.h
index b2e1c9831d4..8d937ffed22 100644
--- a/include/config-win.h
+++ b/include/config-win.h
@@ -367,6 +367,7 @@ inline double ulonglong2double(ulonglong value)
 #include 
 #else
 #define DEFAULT_MYSQL_HOME	"c:\\mysql"
+#define DATADIR         	"c:\\mysql\\data"
 #define PACKAGE			"mysql"
 #define DEFAULT_BASEDIR		"C:\\"
 #define SHAREDIR		"share"

From f45d6d3cc61199587b43da617aee5017c7401ddb Mon Sep 17 00:00:00 2001
From: "kent@mysql.com" <>
Date: Mon, 1 May 2006 19:48:31 +0200
Subject: [PATCH 087/108] mysql.spec.sh:   Use "./libtool --mode=execute" to
 find real path to executables

---
 support-files/mysql.spec.sh | 26 +++++++++++---------------
 1 file changed, 11 insertions(+), 15 deletions(-)

diff --git a/support-files/mysql.spec.sh b/support-files/mysql.spec.sh
index ab2319fa2bb..efe42a035e6 100644
--- a/support-files/mysql.spec.sh
+++ b/support-files/mysql.spec.sh
@@ -318,16 +318,11 @@ fi
 make -i test-force || true
 
 # Save mysqld-max
-# check if mysqld was installed in .libs/
-if test -f sql/.libs/mysqld
-then
-	cp sql/.libs/mysqld sql/mysqld-max
-else
-	cp sql/mysqld sql/mysqld-max
-fi
-nm --numeric-sort sql/mysqld-max > sql/mysqld-max.sym
+./libtool --mode=execute cp sql/mysqld sql/mysqld-max
+./libtool --mode=execute nm --numeric-sort sql/mysqld-max > sql/mysqld-max.sym
+
 # Save the perror binary so it supports the NDB error codes (BUG#13740)
-mv extra/perror extra/perror.ndb
+./libtool --mode=execute cp extra/perror extra/perror.ndb
 
 # Install the ndb binaries
 (cd ndb; make install DESTDIR=$RBR)
@@ -373,12 +368,8 @@ BuildMySQL "--disable-shared \
 		--with-innodb \
 		--without-vio \
 		--without-openssl"
-if test -f sql/.libs/mysqld
-then
-	nm --numeric-sort sql/.libs/mysqld > sql/mysqld.sym
-else
-	nm --numeric-sort sql/mysqld > sql/mysqld.sym
-fi
+
+./libtool --mode=execute nm --numeric-sort sql/mysqld > sql/mysqld.sym
 
 # We might want to save the config log file
 if test -n "$MYSQL_CONFLOG_DEST"
@@ -717,6 +708,11 @@ fi
 # itself - note that they must be ordered by date (important when
 # merging BK trees)
 %changelog 
+* Mon May 01 2006 Kent Boortz 
+
+- Use "./libtool --mode=execute" instead of searching for the
+  executable in current directory and ".libs".
+
 * Sat Apr 01 2006 Kent Boortz 
 
 - Set $LDFLAGS from $MYSQL_BUILD_LDFLAGS

From 44e984276c348aa8832cc638a5a6e94382c311cd Mon Sep 17 00:00:00 2001
From: "jimw@mysql.com" <>
Date: Mon, 1 May 2006 17:12:51 -0700
Subject: [PATCH 088/108] Fix name of error in view_grant test

---
 mysql-test/t/view_grant.test | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mysql-test/t/view_grant.test b/mysql-test/t/view_grant.test
index 8335c1de20a..8deff474587 100644
--- a/mysql-test/t/view_grant.test
+++ b/mysql-test/t/view_grant.test
@@ -32,7 +32,7 @@ grant create view,select on test.* to mysqltest_1@localhost;
 connect (user1,localhost,mysqltest_1,,test);
 connection user1;
 
--- error ER_SPECIFIC_ACCESS_DENIED
+-- error ER_SPECIFIC_ACCESS_DENIED_ERROR
 create definer=root@localhost view v1 as select * from mysqltest.t1;
 create view v1 as select * from mysqltest.t1;
 # try to modify view without DROP privilege on it

From 85ffd9640eb5bb9e4f00857090a3f854ade78694 Mon Sep 17 00:00:00 2001
From: "cmiller@zippy.(none)" <>
Date: Mon, 1 May 2006 22:10:50 -0400
Subject: [PATCH 089/108] SECURITY FIX

Bug#17667: An attacker has the opportunity to bypass query logging.

This adds a new, local-only printf format specifier to our *printf functions
that allows us to print known-size buffers that must not be interpreted as
NUL-terminated "strings."

It uses this format-specifier to print to the log, thus fixing this
problem.
---
 include/my_sys.h                   |  5 ++
 mysql-test/t/mysql_client_test.opt |  1 +
 mysys/Makefile.am                  |  1 +
 mysys/mf_iocache2.c                | 92 +++++++++++++++++++++++-------
 mysys/my_memmem.c                  | 65 +++++++++++++++++++++
 sql/sql_parse.cc                   |  2 +-
 strings/my_vsnprintf.c             |  9 ++-
 tests/Makefile.am                  |  2 +-
 tests/mysql_client_test.c          | 66 +++++++++++++++++++++
 9 files changed, 220 insertions(+), 23 deletions(-)
 create mode 100644 mysql-test/t/mysql_client_test.opt
 create mode 100644 mysys/my_memmem.c

diff --git a/include/my_sys.h b/include/my_sys.h
index 44fe383bf4f..65a295ee39e 100644
--- a/include/my_sys.h
+++ b/include/my_sys.h
@@ -599,6 +599,11 @@ extern char *_my_strdup_with_length(const byte *from, uint length,
 				    const char *sFile, uint uLine,
 				    myf MyFlag);
 
+/* implemented in my_memmem.c */
+extern void *my_memmem(const void *haystack, size_t haystacklen,
+    const void *needle, size_t needlelen);
+
+
 #ifdef __WIN__
 extern int my_access(const char *path, int amode);
 extern File my_sopen(const char *path, int oflag, int shflag, int pmode);
diff --git a/mysql-test/t/mysql_client_test.opt b/mysql-test/t/mysql_client_test.opt
new file mode 100644
index 00000000000..968ba95c6cc
--- /dev/null
+++ b/mysql-test/t/mysql_client_test.opt
@@ -0,0 +1 @@
+--log
diff --git a/mysys/Makefile.am b/mysys/Makefile.am
index ee0dcb544b6..d9de36d4e45 100644
--- a/mysys/Makefile.am
+++ b/mysys/Makefile.am
@@ -55,6 +55,7 @@ libmysys_a_SOURCES =    my_init.c my_getwd.c mf_getdate.c my_mmap.c \
 			charset.c charset-def.c my_bitmap.c my_bit.c md5.c \
 			my_gethostbyname.c rijndael.c my_aes.c sha1.c \
 			my_handler.c my_netware.c my_largepage.c \
+			my_memmem.c \
 			my_windac.c my_access.c base64.c
 EXTRA_DIST =		thr_alarm.c thr_lock.c my_pthread.c my_thr_init.c \
 			thr_mutex.c thr_rwlock.c
diff --git a/mysys/mf_iocache2.c b/mysys/mf_iocache2.c
index e181ccfb88d..f1ea21c2a47 100644
--- a/mysys/mf_iocache2.c
+++ b/mysys/mf_iocache2.c
@@ -252,37 +252,89 @@ uint my_b_printf(IO_CACHE *info, const char* fmt, ...)
 uint my_b_vprintf(IO_CACHE *info, const char* fmt, va_list args)
 {
   uint out_length=0;
+  uint minimum_width; /* as yet unimplemented */
+  uint minimum_width_sign;
+  uint precision; /* as yet unimplemented for anything but %b */
 
-  for (; *fmt ; fmt++)
+  /*
+    Store the location of the beginning of a format directive, for the
+    case where we learn we shouldn't have been parsing a format string
+    at all, and we don't want to lose the flag/precision/width/size
+    information.
+   */
+  const char* backtrack;
+
+  for (; *fmt != '\0'; fmt++)
   {
-    if (*fmt++ != '%')
+    /* Copy everything until '%' or end of string */
+    const char *start=fmt;
+    uint length;
+    
+    for (; (*fmt != '\0') && (*fmt != '%'); fmt++) ;
+
+    length= (uint) (fmt - start);
+    out_length+=length;
+    if (my_b_write(info, start, length))
+      goto err;
+
+    if (*fmt == '\0')				/* End of format */
     {
-      /* Copy everything until '%' or end of string */
-      const char *start=fmt-1;
-      uint length;
-      for (; *fmt && *fmt != '%' ; fmt++ ) ;
-      length= (uint) (fmt - start);
-      out_length+=length;
-      if (my_b_write(info, start, length))
-	goto err;
-      if (!*fmt)				/* End of format */
-      {
-	return out_length;
-      }
-      fmt++;
-      /* Found one '%' */
+      return out_length;
     }
+
+    /* 
+      By this point, *fmt must be a percent;  Keep track of this location and
+      skip over the percent character. 
+    */
+    DBUG_ASSERT(*fmt == '%');
+    backtrack= fmt;
+    fmt++;
+
+    minimum_width= 0;
+    precision= 0;
+    minimum_width_sign= 1;
     /* Skip if max size is used (to be compatible with printf) */
-    while (my_isdigit(&my_charset_latin1, *fmt) || *fmt == '.' || *fmt == '-')
+    while (*fmt == '-') { fmt++; minimum_width_sign= -1; }
+    if (*fmt == '*') {
+      precision= (int) va_arg(args, int);
       fmt++;
+    } else {
+      while (my_isdigit(&my_charset_latin1, *fmt)) {
+        minimum_width=(minimum_width * 10) + (*fmt - '0');
+        fmt++;
+      }
+    }
+    minimum_width*= minimum_width_sign;
+
+    if (*fmt == '.') {
+      fmt++;
+      if (*fmt == '*') {
+        precision= (int) va_arg(args, int);
+        fmt++;
+      } else {
+        while (my_isdigit(&my_charset_latin1, *fmt)) {
+          precision=(precision * 10) + (*fmt - '0');
+          fmt++;
+        }
+      }
+    }
+
     if (*fmt == 's')				/* String parameter */
     {
       reg2 char *par = va_arg(args, char *);
       uint length = (uint) strlen(par);
+      /* TODO: implement minimum width and precision */
       out_length+=length;
       if (my_b_write(info, par, length))
 	goto err;
     }
+    else if (*fmt == 'b')                       /* Sized buffer parameter, only precision makes sense */
+    {
+      char *par = va_arg(args, char *);
+      out_length+= precision;
+      if (my_b_write(info, par, precision))
+        goto err;
+    }
     else if (*fmt == 'd' || *fmt == 'u')	/* Integer parameter */
     {
       register int iarg;
@@ -317,9 +369,9 @@ uint my_b_vprintf(IO_CACHE *info, const char* fmt, va_list args)
     else
     {
       /* %% or unknown code */
-      if (my_b_write(info, "%", 1))
-	goto err;
-      out_length++;
+      if (my_b_write(info, backtrack, fmt-backtrack))
+        goto err;
+      out_length+= fmt-backtrack;
     }
   }
   return out_length;
diff --git a/mysys/my_memmem.c b/mysys/my_memmem.c
new file mode 100644
index 00000000000..3a71d39c262
--- /dev/null
+++ b/mysys/my_memmem.c
@@ -0,0 +1,65 @@
+#include "my_base.h"
+
+/*
+  my_memmem, port of a GNU extension.
+
+  Returns a pointer to the beginning of the substring, needle, or NULL if the
+  substring is not found in haystack.
+*/
+void *my_memmem(const void *haystack, size_t haystacklen,
+    const void *needle, size_t needlelen)
+{
+  const void *cursor;
+  const void *last_possible_needle_location = haystack + haystacklen - needlelen;
+
+  /* Easy answers */
+  if (needlelen > haystacklen) return(NULL);
+  if (needle == NULL) return(NULL);
+  if (haystack == NULL) return(NULL);
+  if (needlelen == 0) return(NULL);
+  if (haystacklen == 0) return(NULL);
+
+  for (cursor = haystack; cursor <= last_possible_needle_location; cursor++) {
+    if (memcmp(needle, cursor, needlelen) == 0) {
+      return((void *) cursor);
+    }
+  }
+  return(NULL);
+}
+
+  
+
+#ifdef MAIN
+#include 
+
+int main(int argc, char *argv[]) {
+  char haystack[10], needle[3];
+
+  memmove(haystack, "0123456789", 10);
+
+  memmove(needle, "no", 2);
+  assert(my_memmem(haystack, 10, needle, 2) == NULL);
+
+  memmove(needle, "345", 3);
+  assert(my_memmem(haystack, 10, needle, 3) != NULL);
+
+  memmove(needle, "789", 3);
+  assert(my_memmem(haystack, 10, needle, 3) != NULL);
+  assert(my_memmem(haystack, 9, needle, 3) == NULL);
+
+  memmove(needle, "012", 3);
+  assert(my_memmem(haystack, 10, needle, 3) != NULL);
+  assert(my_memmem(NULL, 10, needle, 3) == NULL);
+
+  assert(my_memmem(NULL, 10, needle, 3) == NULL);
+  assert(my_memmem(haystack, 0, needle, 3) == NULL);
+  assert(my_memmem(haystack, 10, NULL, 3) == NULL);
+  assert(my_memmem(haystack, 10, needle, 0) == NULL);
+
+  assert(my_memmem(haystack, 1, needle, 3) == NULL);
+
+  printf("success\n");
+  return(0);
+}
+
+#endif
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index f9d04fc873e..ce8f6012824 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -1711,7 +1711,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
     if (alloc_query(thd, packet, packet_length))
       break;					// fatal error is set
     char *packet_end= thd->query + thd->query_length;
-    mysql_log.write(thd,command,"%s",thd->query);
+    mysql_log.write(thd,command, "%.*b", thd->query_length, thd->query);
     DBUG_PRINT("query",("%-.4096s",thd->query));
 
     if (!(specialflag & SPECIAL_NO_PRIOR))
diff --git a/strings/my_vsnprintf.c b/strings/my_vsnprintf.c
index 0e036c2bbcd..d917e9e11b2 100644
--- a/strings/my_vsnprintf.c
+++ b/strings/my_vsnprintf.c
@@ -27,6 +27,7 @@
     %#[l]d
     %#[l]u
     %#[l]x
+    %#.#b 	Local format; note first # is ignored and second is REQUIRED
     %#.#s	Note first # is ignored
     
   RETURN
@@ -40,7 +41,7 @@ int my_vsnprintf(char *to, size_t n, const char* fmt, va_list ap)
 
   for (; *fmt ; fmt++)
   {
-    if (fmt[0] != '%')
+    if (*fmt != '%')
     {
       if (to == end)			/* End of buffer */
 	break;
@@ -95,6 +96,12 @@ int my_vsnprintf(char *to, size_t n, const char* fmt, va_list ap)
       to=strnmov(to,par,plen);
       continue;
     }
+    else if (*fmt == 'b')				/* Buffer parameter */
+    {
+      char *par = va_arg(ap, char *);
+      to=memmove(to, par, abs(width));
+      continue;
+    }
     else if (*fmt == 'd' || *fmt == 'u'|| *fmt== 'x')	/* Integer parameter */
     {
       register long larg;
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 131f8b1b625..ec732462ca5 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -42,7 +42,7 @@ INCLUDES =		-I$(top_builddir)/include -I$(top_srcdir)/include \
 LIBS =			@CLIENT_LIBS@
 LDADD =			@CLIENT_EXTRA_LDFLAGS@ \
                         $(top_builddir)/libmysql/libmysqlclient.la
-mysql_client_test_LDADD= $(LDADD) $(CXXLDFLAGS)
+mysql_client_test_LDADD= $(LDADD) $(CXXLDFLAGS) -lmysys -L../mysys
 mysql_client_test_SOURCES= mysql_client_test.c $(yassl_dummy_link_fix)
 insert_test_SOURCES=       insert_test.c $(yassl_dummy_link_fix)
 select_test_SOURCES=       select_test.c $(yassl_dummy_link_fix)
diff --git a/tests/mysql_client_test.c b/tests/mysql_client_test.c
index b1ea5f8ea06..4bd636a7ae3 100644
--- a/tests/mysql_client_test.c
+++ b/tests/mysql_client_test.c
@@ -14822,6 +14822,71 @@ static void test_bug15613()
   mysql_stmt_close(stmt);
 }
 
+/*
+  Bug#17667: An attacker has the opportunity to bypass query logging.
+*/
+static void test_bug17667()
+{
+  int rc;
+  myheader("test_bug17667");
+  struct buffer_and_length {
+    const char *buffer;
+    const uint length;
+  } statements[]= {
+    { "drop table if exists bug17667", 29 },
+    { "create table bug17667 (c varchar(20))", 37 },
+    { "insert into bug17667 (c) values ('regular') /* NUL=\0 with comment */", 68 },
+    { "insert into bug17667 (c) values ('NUL=\0 in value')", 50 },
+    { "insert into bug17667 (c) values ('5 NULs=\0\0\0\0\0')", 48 },
+    { "/* NUL=\0 with comment */ insert into bug17667 (c) values ('encore')", 67 },
+    { "drop table bug17667", 19 },
+    { NULL, 0 } };  
+
+  struct buffer_and_length *statement_cursor;
+  FILE *log_file;
+
+  for (statement_cursor= statements; statement_cursor->buffer != NULL;
+      statement_cursor++) {
+    rc= mysql_real_query(mysql, statement_cursor->buffer,
+        statement_cursor->length);
+    myquery(rc);
+  }
+
+  sleep(1); /* The server may need time to flush the data to the log. */
+  log_file= fopen("var/log/master.log", "r");
+  if (log_file != NULL) {
+
+    for (statement_cursor= statements; statement_cursor->buffer != NULL;
+        statement_cursor++) {
+     char line_buffer[MAX_TEST_QUERY_LENGTH*2]; 
+     /* more than enough room for the query and some marginalia. */
+
+      do {
+        memset(line_buffer, '/', MAX_TEST_QUERY_LENGTH*2);
+
+        DIE_UNLESS(fgets(line_buffer, MAX_TEST_QUERY_LENGTH*2, log_file) !=
+            NULL);
+        /* If we reach EOF before finishing the statement list, then we failed. */
+
+      } while (my_memmem(line_buffer, MAX_TEST_QUERY_LENGTH*2,
+            statement_cursor->buffer, statement_cursor->length) == NULL);
+    }
+
+    printf("success.  All queries found intact in the log.\n");
+
+  } else {
+    fprintf(stderr, "Could not find the log file, var/log/master.log, so "
+        "test_bug17667 is \ninconclusive.  Run test from the "
+        "mysql-test/mysql-test-run* program \nto set up the correct "
+        "environment for this test.\n\n");
+  }
+
+  if (log_file != NULL)
+    fclose(log_file);
+
+}
+
+
 /*
   Bug#14169: type of group_concat() result changed to blob if tmp_table was used
 */
@@ -15121,6 +15186,7 @@ static struct my_tests_st my_tests[]= {
   { "test_bug16143", test_bug16143 },
   { "test_bug15613", test_bug15613 },
   { "test_bug14169", test_bug14169 },
+  { "test_bug17667", test_bug17667 },
   { 0, 0 }
 };
 

From aab0e9c24e37eae19a86b554b19285db27b43b90 Mon Sep 17 00:00:00 2001
From: "holyfoot@deer.(none)" <>
Date: Tue, 2 May 2006 08:59:49 +0500
Subject: [PATCH 090/108] Win build fix

---
 client/mysql_upgrade.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/client/mysql_upgrade.c b/client/mysql_upgrade.c
index 551be79fc99..3288b627554 100644
--- a/client/mysql_upgrade.c
+++ b/client/mysql_upgrade.c
@@ -307,7 +307,7 @@ int main(int argc, char **argv)
     b_read= my_read(check_file, chf_buffer, sizeof(chf_buffer)-1, MYF(0));
     chf_buffer[b_read]= 0;
     my_close(check_file, MYF(0));
-    if (!strcmp(chf_buffer, VERSION))
+    if (!strcmp(chf_buffer, MYSQL_SERVER_VERSION))
     {
       if (opt_verbose)
         puts("mysql_upgrade already done for this version");

From 0736d183378695b26890e134f93113b646699cec Mon Sep 17 00:00:00 2001
From: "acurtis@xiphis.org" <>
Date: Mon, 1 May 2006 21:33:09 -0700
Subject: [PATCH 091/108] WL#3201 post-review fixups   end plugin/module naming
 schizophrenia   fixup shell code and m4 macro comments   cmakelists.txt
 included in EXTRA_DIST

---
 BUILD/SETUP.sh                |   6 +-
 config/ac-macros/plugins.m4   | 551 ++++++++++++++++++----------------
 configure.in                  |  70 ++---
 storage/archive/Makefile.am   |   1 +
 storage/blackhole/Makefile.am |   1 +
 storage/csv/Makefile.am       |   1 +
 storage/example/Makefile.am   |   1 +
 7 files changed, 330 insertions(+), 301 deletions(-)

diff --git a/BUILD/SETUP.sh b/BUILD/SETUP.sh
index d115e3c29dc..589e609beeb 100755
--- a/BUILD/SETUP.sh
+++ b/BUILD/SETUP.sh
@@ -147,9 +147,9 @@ static_link="$static_link --with-client-ldflags=-all-static"
 local_infile_configs="--enable-local-infile"
 
 
-max_no_embedded_configs="$SSL_LIBRARY --with-modules=max"
-max_no_ndb_configs="$SSL_LIBRARY --with-modules=max-no-ndb --with-embedded-server"
-max_configs="$SSL_LIBRARY --with-modules=max --with-embedded-server"
+max_no_embedded_configs="$SSL_LIBRARY --with-plugins=max"
+max_no_ndb_configs="$SSL_LIBRARY --with-plugins=max-no-ndb --with-embedded-server"
+max_configs="$SSL_LIBRARY --with-plugins=max --with-embedded-server"
 
 #
 # CPU and platform specific compilation flags.
diff --git a/config/ac-macros/plugins.m4 b/config/ac-macros/plugins.m4
index 19b951ea467..0ca952c4354 100644
--- a/config/ac-macros/plugins.m4
+++ b/config/ac-macros/plugins.m4
@@ -1,45 +1,45 @@
 dnl ===========================================================================
-dnl Support for plugable mysql server modules
+dnl Support for mysql server plugins
 dnl ===========================================================================
 dnl
 dnl WorkLog#3201
 dnl
-dnl Framework for pluggable static and dynamic modules for mysql
+dnl Framework for pluggable static and dynamic plugins for mysql
 dnl
 dnl ---------------------------------------------------------------------------
-dnl Macro: MYSQL_MODULE
+dnl Macro: MYSQL_PLUGIN
 dnl
-dnl Syntax:
-dnl   MYSQL_MODULE([name],[Plugin module name],
-dnl                [Plugin module description],
+dnl SYNOPSIS
+dnl   MYSQL_PLUGIN([name],[Plugin name],
+dnl                [Plugin description],
 dnl                [group,group...])
 dnl   
-dnl What it does:
-dnl   First declaration for a plugin module (mandatory).
-dnl   Adds module as member to configuration groups (if specified)
+dnl DESCRIPTION
+dnl   First declaration for a plugin (mandatory).
+dnl   Adds plugin as member to configuration groups (if specified)
 dnl
 dnl ---------------------------------------------------------------------------
 
-AC_DEFUN([MYSQL_MODULE],[
- _MYSQL_MODULE(
+AC_DEFUN([MYSQL_PLUGIN],[
+ _MYSQL_PLUGIN(
   [$1],
-  [__MYSQL_MODULE_]AS_TR_CPP([$1])[__],
+  [__MYSQL_PLUGIN_]AS_TR_CPP([$1])[__],
   m4_default([$2], [$1 plugin]),
   m4_default([$3], [plugin for $1]),
   m4_default([$4], []),
  )
 ])
 
-AC_DEFUN([_MYSQL_MODULE],[
+AC_DEFUN([_MYSQL_PLUGIN],[
  m4_ifdef([$2], [
-  AC_FATAL([Duplicate MYSQL_MODULE declaration for $3])
+  AC_FATAL([Duplicate MYSQL_PLUGIN declaration for $3])
  ],[
   m4_define([$2], [$1])
   _MYSQL_PLUGAPPEND([__mysql_plugin_list__],[$1])
-  m4_define([MYSQL_MODULE_NAME_]AS_TR_CPP([$1]), [$3])
-  m4_define([MYSQL_MODULE_DESC_]AS_TR_CPP([$1]), [$4])
+  m4_define([MYSQL_PLUGIN_NAME_]AS_TR_CPP([$1]), [$3])
+  m4_define([MYSQL_PLUGIN_DESC_]AS_TR_CPP([$1]), [$4])
   ifelse([$5], [], [], [
-   _MYSQL_PLUGAPPEND_OPTS([$1], $5)
+   _MYSQL_PLUGAPPEND_META([$1], $5)
   ])
  ])
 ])
@@ -48,14 +48,18 @@ AC_DEFUN([_MYSQL_MODULE],[
 dnl ---------------------------------------------------------------------------
 dnl Macro: MYSQL_STORAGE_ENGINE
 dnl
-dnl What it does:
+dnl SYNOPSIS
+dnl   MYSQL_STORAGE_ENGINE([name],[legacy-option],[Storage engine name],
+dnl                        [Storage engine description],[group,group...])
+dnl
+dnl DESCRIPTION
 dnl   Short cut for storage engine declarations
 dnl
 dnl ---------------------------------------------------------------------------
 
 AC_DEFUN([MYSQL_STORAGE_ENGINE],[
- MYSQL_MODULE([$1], [$3], [$4], [[$5]])
- MYSQL_MODULE_DEFINE([$1], [WITH_]AS_TR_CPP([$1])[_STORAGE_ENGINE])
+ MYSQL_PLUGIN([$1], [$3], [$4], [[$5]])
+ MYSQL_PLUGIN_DEFINE([$1], [WITH_]AS_TR_CPP([$1])[_STORAGE_ENGINE])
  ifelse([$2],[no],[],[
   _MYSQL_LEGACY_STORAGE_ENGINE(
       m4_bpatsubst(m4_default([$2], [$1-storage-engine]), -, _))
@@ -64,109 +68,127 @@ AC_DEFUN([MYSQL_STORAGE_ENGINE],[
 
 AC_DEFUN([_MYSQL_LEGACY_STORAGE_ENGINE],[
 if test "[${with_]$1[+set}]" = set; then
-  [with_module_]$1="[$with_]$1"
+  [with_plugin_]$1="[$with_]$1"
 fi
 ])
 
 
 dnl ---------------------------------------------------------------------------
-dnl Macro: MYSQL_MODULE_DEFINE
+dnl Macro: MYSQL_PLUGIN_DEFINE
 dnl
-dnl What it does:
-dnl   When a plugin module is to be statically linked, define the C macro
+dnl SYNOPSIS
+dnl   MYSQL_PLUGIN_DEFILE([name],[MYSQL_CPP_DEFINE])
+dnl
+dnl DESCRIPTION
+dnl   When a plugin is to be statically linked, define the C macro
 dnl
 dnl ---------------------------------------------------------------------------
 
-AC_DEFUN([MYSQL_MODULE_DEFINE],[
- REQUIRE_PLUGIN([$1])
- m4_define([MYSQL_MODULE_DEFINE_]AS_TR_CPP([$1]), [$2])
+AC_DEFUN([MYSQL_PLUGIN_DEFINE],[
+ MYSQL_REQUIRE_PLUGIN([$1])
+ m4_define([MYSQL_PLUGIN_DEFINE_]AS_TR_CPP([$1]), [$2])
 ])
 
 
 dnl ---------------------------------------------------------------------------
-dnl Macro: MYSQL_MODULE_DIRECTORY
+dnl Macro: MYSQL_PLUGIN_DIRECTORY
 dnl
-dnl What it does:
+dnl SYNOPSIS
+dnl   MYSQL_PLUGIN_DIRECTORY([name],[plugin/dir])
+dnl
+dnl DESCRIPTION
 dnl   Adds a directory to the build process
 dnl
 dnl ---------------------------------------------------------------------------
 
-AC_DEFUN([MYSQL_MODULE_DIRECTORY],[
- REQUIRE_PLUGIN([$1])
- m4_define([MYSQL_MODULE_DIRECTORY_]AS_TR_CPP([$1]), [$2])
+AC_DEFUN([MYSQL_PLUGIN_DIRECTORY],[
+ MYSQL_REQUIRE_PLUGIN([$1])
+ m4_define([MYSQL_PLUGIN_DIRECTORY_]AS_TR_CPP([$1]), [$2])
 ])
 
 
 dnl ---------------------------------------------------------------------------
-dnl Macro: MYSQL_MODULE_STATIC
+dnl Macro: MYSQL_PLUGIN_STATIC
 dnl
-dnl What it does:
+dnl SYNOPSIS
+dnl   MYSQL_PLUGIN_STATIC([name],[libmyplugin.a])
+dnl
+dnl DESCRIPTION
 dnl   Declare the name for the static library 
 dnl
 dnl ---------------------------------------------------------------------------
 
-AC_DEFUN([MYSQL_MODULE_STATIC],[
- REQUIRE_PLUGIN([$1])
- m4_define([MYSQL_MODULE_STATIC_]AS_TR_CPP([$1]), [$2])
+AC_DEFUN([MYSQL_PLUGIN_STATIC],[
+ MYSQL_REQUIRE_PLUGIN([$1])
+ m4_define([MYSQL_PLUGIN_STATIC_]AS_TR_CPP([$1]), [$2])
 ])
 
 
 dnl ---------------------------------------------------------------------------
-dnl Macro: MYSQL_MODULE_DYNAMIC
+dnl Macro: MYSQL_PLUGIN_DYNAMIC
 dnl
-dnl What it does:
+dnl SYNOPSIS
+dnl  MYSQL_PLUGIN_DYNAMIC([name],[myplugin.la])
+dnl
+dnl DESCRIPTION
 dnl   Declare the name for the shared library
 dnl
 dnl ---------------------------------------------------------------------------
 
-AC_DEFUN([MYSQL_MODULE_DYNAMIC],[
- REQUIRE_PLUGIN([$1])
- m4_define([MYSQL_MODULE_DYNAMIC_]AS_TR_CPP([$1]), [$2])
+AC_DEFUN([MYSQL_PLUGIN_DYNAMIC],[
+ MYSQL_REQUIRE_PLUGIN([$1])
+ m4_define([MYSQL_PLUGIN_DYNAMIC_]AS_TR_CPP([$1]), [$2])
 ])
 
 
 dnl ---------------------------------------------------------------------------
-dnl Macro: MYSQL_MODULE_MANDATORY
+dnl Macro: MYSQL_PLUGIN_MANDATORY
 dnl
-dnl What it does:
-dnl   Marks the specified plugin as a mandatory module
+dnl SYNOPSIS
+dnl   MYSQL_PLUGIN_MANDATORY([name])
+dnl
+dnl DESCRIPTION
+dnl   Marks the specified plugin as a mandatory plugin
 dnl
 dnl ---------------------------------------------------------------------------
 
-AC_DEFUN([MYSQL_MODULE_MANDATORY],[
- REQUIRE_PLUGIN([$1])
- _MYSQL_MODULE_MANDATORY([$1],
-  [MYSQL_MODULE_MANDATORY_]AS_TR_CPP([$1]),
-  [MYSQL_MODULE_DISABLED_]AS_TR_CPP([$1])
+AC_DEFUN([MYSQL_PLUGIN_MANDATORY],[
+ MYSQL_REQUIRE_PLUGIN([$1])
+ _MYSQL_PLUGIN_MANDATORY([$1],
+  [MYSQL_PLUGIN_MANDATORY_]AS_TR_CPP([$1]),
+  [MYSQL_PLUGIN_DISABLED_]AS_TR_CPP([$1])
  )
 ])
 
-AC_DEFUN([_MYSQL_MODULE_MANDATORY],[
+AC_DEFUN([_MYSQL_PLUGIN_MANDATORY],[
  m4_define([$2], [yes])
  m4_ifdef([$3], [
-  AC_WARNING([syntax],[Mandatory plugin $1 has been disabled])
+  AC_FATAL([mandatory plugin $1 has been disabled])
   m4_undefine([$2])
  ])
 ])
 
 
 dnl ---------------------------------------------------------------------------
-dnl Macro: MYSQL_MODULE_DISABLED
+dnl Macro: MYSQL_PLUGIN_DISABLED
 dnl
-dnl What it does:
-dnl   Marks the specified plugin as a disabled module
+dnl SYNOPSIS
+dnl   MYSQL_PLUGIN_DISABLED([name])
+dnl
+dnl DESCRIPTION
+dnl   Marks the specified plugin as a disabled plugin
 dnl
 dnl ---------------------------------------------------------------------------
 
-AC_DEFUN([MYSQL_MODULE_DISABLED],[
- REQUIRE_PLUGIN([$1])
- _MYSQL_MODULE_DISABLED([$1], 
-  [MYSQL_MODULE_DISABLED_]AS_TR_CPP([$1]),
-  [MYSQL_MODULE_MANDATORY_]AS_TR_CPP([$1])
+AC_DEFUN([MYSQL_PLUGIN_DISABLED],[
+ MYSQL_REQUIRE_PLUGIN([$1])
+ _MYSQL_PLUGIN_DISABLED([$1], 
+  [MYSQL_PLUGIN_DISABLED_]AS_TR_CPP([$1]),
+  [MYSQL_PLUGIN_MANDATORY_]AS_TR_CPP([$1])
  )
 ])
 
-AC_DEFUN([_MYSQL_MODULE_DISABLED],[
+AC_DEFUN([_MYSQL_PLUGIN_DISABLED],[
  m4_define([$2], [yes])
  m4_ifdef([$3], [
   AC_FATAL([attempt to disable mandatory plugin $1])
@@ -176,48 +198,54 @@ AC_DEFUN([_MYSQL_MODULE_DISABLED],[
 
 
 dnl ---------------------------------------------------------------------------
-dnl Macro: MYSQL_MODULE_DEPENDS
+dnl Macro: MYSQL_PLUGIN_DEPENDS
 dnl
-dnl What it does:
-dnl   Enables other modules neccessary for this module
+dnl SYNOPSIS
+dnl   MYSQL_PLUGIN_DEPENDS([name],[prereq,prereq...])
+dnl
+dnl DESCRIPTION
+dnl   Enables other plugins neccessary for the named plugin
 dnl   Dependency checking is not recursive so if any 
-dnl   required module requires further modules, list them
+dnl   required plugin requires further plugins, list them
 dnl   here too!
 dnl
 dnl ---------------------------------------------------------------------------
 
-AC_DEFUN([MYSQL_MODULE_DEPENDS],[
- REQUIRE_PLUGIN([$1])
- ifelse($#, 0, [], $#, 1, [
+AC_DEFUN([MYSQL_PLUGIN_DEPENDS],[
+ MYSQL_REQUIRE_PLUGIN([$1])
+ ifelse($#, 2, [
+  _MYSQL_PLUGIN_DEPEND([$1], $2)
+ ], [
   AC_FATAL([bad number of arguments])
- ], $#, 2, [
-  _MYSQL_MODULE_DEPEND([$1],[$2])
- ],[
-  _MYSQL_MODULE_DEPEND([$1],[$2])
-  MYSQL_MODULE_DEPENDS([$1], m4_shift(m4_shift($@)))
  ])
 ])
 
-AC_DEFUN([_MYSQL_MODULE_DEPEND],[
- REQUIRE_PLUGIN([$2])
- _MYSQL_PLUGAPPEND([__mysql_plugdepends_$1__],[$2])
+AC_DEFUN([_MYSQL_PLUGIN_DEPEND],[
+ ifelse($#, 1, [], [$#:$2], [2:], [
+  MYSQL_REQUIRE_PLUGIN([$2])
+  _MYSQL_PLUGAPPEND([__mysql_plugdepends_$1__],[$2])
+  _MYSQL_PLUGIN_DEPEND([$1], m4_shift(m4_shift($@)))
+ ])
 ])
 
 
 dnl ---------------------------------------------------------------------------
-dnl Macro: MYSQL_MODULE_ACTIONS
+dnl Macro: MYSQL_PLUGIN_ACTIONS
 dnl
-dnl What it does:
-dnl   Declares additional actions required to configure the module
+dnl SYNOPSIS
+dnl   MYSQL_PLUGIN_ACTIONS([name],[PLUGIN_CONFIGURE_STUFF])
+dnl
+dnl DESCRIPTION
+dnl   Declares additional autoconf actions required to configure the plugin
 dnl
 dnl ---------------------------------------------------------------------------
 
-AC_DEFUN([MYSQL_MODULE_ACTIONS],[
- REQUIRE_PLUGIN([$1])
+AC_DEFUN([MYSQL_PLUGIN_ACTIONS],[
+ MYSQL_REQUIRE_PLUGIN([$1])
  m4_ifdef([$2],[
-   m4_define([MYSQL_MODULE_ACTIONS_]AS_TR_CPP([$1]),m4_defn([$2]))
+   m4_define([MYSQL_PLUGIN_ACTIONS_]AS_TR_CPP([$1]),m4_defn([$2]))
  ],[
-   m4_define([MYSQL_MODULE_ACTIONS_]AS_TR_CPP([$1]), [$2])
+   m4_define([MYSQL_PLUGIN_ACTIONS_]AS_TR_CPP([$1]), [$2])
  ])
 ])
 
@@ -225,20 +253,24 @@ AC_DEFUN([MYSQL_MODULE_ACTIONS],[
 dnl ---------------------------------------------------------------------------
 dnl Macro: MYSQL_CONFIGURE_PLUGINS
 dnl
-dnl What it does:
-dnl   Called last, emits all required shell code to configure the modules
+dnl SYNOPSIS
+dnl   MYSQL_PLUGIN_DEPENDS([name,name...])
+dnl
+dnl DESCRIPTION
+dnl   Used last, emits all required shell code to configure the plugins
+dnl   Argument is a list of default plugins or meta-plugin
 dnl
 dnl ---------------------------------------------------------------------------
 
 AC_DEFUN([MYSQL_CONFIGURE_PLUGINS],[
  m4_ifdef([__mysql_plugin_configured__],[
-   AC_FATAL([cannot call [MYSQL_CONFIGURE_PLUGINS] multiple times])
+   AC_FATAL([cannot use [MYSQL_CONFIGURE_PLUGINS] multiple times])
  ],[
    m4_define([__mysql_plugin_configured__],[done])
    m4_ifdef([__mysql_plugin_list__],[
     _MYSQL_CHECK_PLUGIN_ARGS([$1])
     _MYSQL_CONFIGURE_PLUGINS(m4_bpatsubst(__mysql_plugin_list__, :, [,]))
-    _MYSQL_DO_PLUGIN_ACTIONS(m4_bpatsubst(__mysql_plugin_list__, :, [,]))
+    _MYSQL_EMIT_PLUGIN_ACTIONS(m4_bpatsubst(__mysql_plugin_list__, :, [,]))
     AC_SUBST([mysql_se_dirs])
     AC_SUBST([mysql_pg_dirs])
    ])
@@ -247,56 +279,56 @@ AC_DEFUN([MYSQL_CONFIGURE_PLUGINS],[
 
 AC_DEFUN([_MYSQL_CONFIGURE_PLUGINS],[
  ifelse($#, 0, [], $#, 1, [
-  _MYSQL_CHECK_PLUGIN([$1])
+  _MYSQL_EMIT_CHECK_PLUGIN([$1])
  ],[
-  _MYSQL_CHECK_PLUGIN([$1])
+  _MYSQL_EMIT_CHECK_PLUGIN([$1])
   _MYSQL_CONFIGURE_PLUGINS(m4_shift($@))
  ])
 ])
 
-AC_DEFUN([_MYSQL_CHECK_PLUGIN],[
- _DO_MYSQL_CHECK_PLUGIN(
+AC_DEFUN([_MYSQL_EMIT_CHECK_PLUGIN],[
+ __MYSQL_EMIT_CHECK_PLUGIN(
   [$1],
   m4_bpatsubst([$1], -, _),
-  [MYSQL_MODULE_NAME_]AS_TR_CPP([$1]),
-  [MYSQL_MODULE_DESC_]AS_TR_CPP([$1]),
-  [MYSQL_MODULE_DEFINE_]AS_TR_CPP([$1]),
-  [MYSQL_MODULE_DIRECTORY_]AS_TR_CPP([$1]),
-  [MYSQL_MODULE_STATIC_]AS_TR_CPP([$1]),
-  [MYSQL_MODULE_DYNAMIC_]AS_TR_CPP([$1]),
-  [MYSQL_MODULE_MANDATORY_]AS_TR_CPP([$1]),
-  [MYSQL_MODULE_DISABLED_]AS_TR_CPP([$1]),
-  [MYSQL_MODULE_ACTIONS_]AS_TR_CPP([$1])
+  [MYSQL_PLUGIN_NAME_]AS_TR_CPP([$1]),
+  [MYSQL_PLUGIN_DESC_]AS_TR_CPP([$1]),
+  [MYSQL_PLUGIN_DEFINE_]AS_TR_CPP([$1]),
+  [MYSQL_PLUGIN_DIRECTORY_]AS_TR_CPP([$1]),
+  [MYSQL_PLUGIN_STATIC_]AS_TR_CPP([$1]),
+  [MYSQL_PLUGIN_DYNAMIC_]AS_TR_CPP([$1]),
+  [MYSQL_PLUGIN_MANDATORY_]AS_TR_CPP([$1]),
+  [MYSQL_PLUGIN_DISABLED_]AS_TR_CPP([$1]),
+  [MYSQL_PLUGIN_ACTIONS_]AS_TR_CPP([$1])
  )
 ])
 
-AC_DEFUN([_DO_MYSQL_CHECK_PLUGIN],[
+AC_DEFUN([__MYSQL_EMIT_CHECK_PLUGIN],[
  m4_ifdef([$5],[
   AH_TEMPLATE($5, [Include ]$4[ into mysqld])
  ])
  AC_MSG_CHECKING([whether to use ]$3)
  mysql_use_plugin_dir=""
  m4_ifdef([$10],[
-  if test "[$mysql_module_]$2" = yes -a \
-          "[$with_module_]$2" != no -o \
-          "[$with_module_]$2" = yes; then
+  if test "X[$mysql_plugin_]$2" = Xyes -a \
+          "X[$with_plugin_]$2" != Xno -o \
+          "X[$with_plugin_]$2" = Xyes; then
     AC_MSG_RESULT([error])
     AC_MSG_ERROR([disabled])
   fi
   AC_MSG_RESULT([no])
  ],[
   m4_ifdef([$9],[
-   if test "[$with_module_]$2" = no; then
+   if test "X[$with_plugin_]$2" = Xno; then
      AC_MSG_RESULT([error])
-     AC_MSG_ERROR([cannot disable mandatory module])
+     AC_MSG_ERROR([cannot disable mandatory plugin])
    fi
-   [mysql_module_]$2=yes
+   [mysql_plugin_]$2=yes
   ])
-  if test "[$with_module_]$2" = no; then
+  if test "X[$with_plugin_]$2" = Xno; then
     AC_MSG_RESULT([no])
   else
-    if test "[$mysql_module_]$2" != yes -a \
-            "[$with_module_]$2" != yes; then
+    if test "X[$mysql_plugin_]$2" != Xyes -a \
+            "X[$with_plugin_]$2" != Xyes; then
       m4_ifdef([$8],[
        m4_ifdef([$6],[
          if test -d "$srcdir/$6" ; then
@@ -304,16 +336,16 @@ AC_DEFUN([_DO_MYSQL_CHECK_PLUGIN],[
        ])
        AC_SUBST([plugin_]$2[_shared_target], "$8")
        AC_SUBST([plugin_]$2[_static_target], [""])
-       [with_module_]$2=yes
+       [with_plugin_]$2=yes
        AC_MSG_RESULT([plugin])
        m4_ifdef([$6],[
          else
-           [mysql_module_]$2=no
+           [mysql_plugin_]$2=no
            AC_MSG_RESULT([no])
          fi
        ])
       ],[
-       [with_module_]$2=no
+       [with_plugin_]$2=no
        AC_MSG_RESULT([no])
       ])
     else
@@ -356,7 +388,7 @@ AC_DEFUN([_DO_MYSQL_CHECK_PLUGIN],[
        ])
       ])
       mysql_plugin_defs="$mysql_plugin_defs, [builtin_]$2[_plugin]"
-      [with_module_]$2=yes
+      [with_plugin_]$2=yes
       AC_MSG_RESULT([yes])
     fi
     m4_ifdef([$6],[
@@ -378,40 +410,33 @@ AC_DEFUN([_DO_MYSQL_CHECK_PLUGIN],[
  ])
 ])
 
-AC_DEFUN([_MYSQL_DO_PLUGIN_ACTIONS],[
+AC_DEFUN([_MYSQL_EMIT_PLUGIN_ACTIONS],[
  ifelse($#, 0, [], $#, 1, [
-  _MYSQL_PLUGIN_ACTIONS([$1])
+  _MYSQL_EMIT_PLUGIN_ACTION([$1])
  ],[
-  _MYSQL_PLUGIN_ACTIONS([$1])
-  _MYSQL_DO_PLUGIN_ACTIONS(m4_shift($@))
+  _MYSQL_EMIT_PLUGIN_ACTION([$1])
+  _MYSQL_EMIT_PLUGIN_ACTIONS(m4_shift($@))
  ])
 ])
 
-AC_DEFUN([_MYSQL_PLUGIN_ACTIONS],[
- _DO_MYSQL_PLUGIN_ACTIONS(
+AC_DEFUN([_MYSQL_EMIT_PLUGIN_ACTION],[
+ __MYSQL_EMIT_PLUGIN_ACTION(
   [$1],
   m4_bpatsubst([$1], -, _),
-  [MYSQL_MODULE_NAME_]AS_TR_CPP([$1]),
-  [MYSQL_MODULE_DESC_]AS_TR_CPP([$1]),
-  [MYSQL_MODULE_DEFINE_]AS_TR_CPP([$1]),
-  [MYSQL_MODULE_DIRECTORY_]AS_TR_CPP([$1]),
-  [MYSQL_MODULE_STATIC_]AS_TR_CPP([$1]),
-  [MYSQL_MODULE_DYNAMIC_]AS_TR_CPP([$1]),
-  [MYSQL_MODULE_MANDATORY_]AS_TR_CPP([$1]),
-  [MYSQL_MODULE_DISABLED_]AS_TR_CPP([$1]),
-  [MYSQL_MODULE_ACTIONS_]AS_TR_CPP([$1])
+  [MYSQL_PLUGIN_DISABLED_]AS_TR_CPP([$1]),
+  [MYSQL_PLUGIN_ACTIONS_]AS_TR_CPP([$1])
  )
 ])
 
 
-AC_DEFUN([_DO_MYSQL_PLUGIN_ACTIONS],[
- m4_ifdef([$10], [], [
-  if test "[$with_module_]$2" = yes; then
-    if test -z "[$plugin_]$2[_static_target]" -a \
-            -z "[$plugin_]$2[_shared_target]"; then
+AC_DEFUN([__MYSQL_EMIT_PLUGIN_ACTION],[
+ m4_ifdef([$3], [], [
+  if test "X[$with_plugin_]$2" = Xyes; then
+    if test "X[$plugin_]$2[_static_target]" = X -a \
+            "X[$plugin_]$2[_shared_target]" = X; then
       AC_MSG_ERROR([that's strange, $1 failed sanity check])
     fi
-    $11
+    $4
   fi
  ])
 ])
@@ -423,17 +448,23 @@ dnl  Private helper macros
 dnl ===========================================================================
 
 
-AC_DEFUN([REQUIRE_PLUGIN],[
- _REQUIRE_PLUGIN([$1], [__MYSQL_MODULE_]AS_TR_CPP([$1])[__])
+dnl SYNOPSIS
+dnl   MYSQL_REQUIRE_PLUGIN([name])
+dnl
+dnl DESCRIPTION
+dnl   Checks that the specified plugin does exist
+
+AC_DEFUN([MYSQL_REQUIRE_PLUGIN],[
+ _MYSQL_REQUIRE_PLUGIN([$1], [__MYSQL_PLUGIN_]AS_TR_CPP([$1])[__])
 ])
 
-define([_REQUIRE_PLUGIN],[
+define([_MYSQL_REQUIRE_PLUGIN],[
  ifdef([$2],[
   ifelse($2, [$1], [], [
-   AC_FATAL([Misspelt MYSQL_MODULE declaration for $1])
+   AC_FATAL([Misspelt MYSQL_PLUGIN declaration for $1])
   ])
  ],[
-  AC_FATAL([Missing MYSQL_MODULE declaration for $1])
+  AC_FATAL([Missing MYSQL_PLUGIN declaration for $1])
  ])
 ])
 
@@ -441,19 +472,25 @@ define([_REQUIRE_PLUGIN],[
 dnl ---------------------------------------------------------------------------
 
 
-AC_DEFUN([_MYSQL_MODULE_META_CHECK], [ifelse($#, 0, [], $#, 1,
-[_MYSQL_CHECK_PLUGIN_META([$1], [__mysql_]m4_bpatsubst($1, -, _)[_plugins__])
+dnl SYNOPSIS
+dnl   _MYSQL_EMIT_METAPLUGINS([name,name...])
+dnl
+dnl DESCRIPTION
+dnl   Emits shell code for metaplugins
+
+AC_DEFUN([_MYSQL_EMIT_METAPLUGINS], [ifelse($#, 0, [], $#, 1,
+[_MYSQL_EMIT_METAPLUGIN([$1], [__mysql_]m4_bpatsubst($1, -, _)[_plugins__])
 ],
-[_MYSQL_CHECK_PLUGIN_META([$1], [__mysql_]m4_bpatsubst($1, -, _)[_plugins__])
-_MYSQL_MODULE_META_CHECK(m4_shift($@))])
+[_MYSQL_EMIT_METAPLUGIN([$1], [__mysql_]m4_bpatsubst($1, -, _)[_plugins__])
+_MYSQL_EMIT_METAPLUGINS(m4_shift($@))])
 ])
 
-AC_DEFUN([_MYSQL_CHECK_PLUGIN_META], [
+AC_DEFUN([_MYSQL_EMIT_METAPLUGIN], [
   [$1] )
 m4_ifdef([$2], [
-    mysql_modules='m4_bpatsubst($2, :, [ ])'
+    mysql_plugins='m4_bpatsubst($2, :, [ ])'
 ],[
-    mysql_modules=''
+    mysql_plugins=''
 ])
     ;;
 ])
@@ -462,6 +499,12 @@ m4_ifdef([$2], [
 dnl ---------------------------------------------------------------------------
 
 
+dnl SYNOPSIS
+dnl   _MYSQL_PLUGAPPEND([name],[to-append])
+dnl
+dnl DESCRIPTION
+dnl   Helper macro for appending to colon-delimited lists
+
 AC_DEFUN([_MYSQL_PLUGAPPEND],[
  m4_ifdef([$1],[
   m4_define([__plugin_append_tmp__], m4_defn([$1]))
@@ -474,29 +517,24 @@ AC_DEFUN([_MYSQL_PLUGAPPEND],[
  ])
 ])
 
-AC_DEFUN([_MYSQL_PLUGAPPEND_OPTS],[
- ifelse($#, 0, [], $#, 1, [
-  AC_FATAL([bad number of args])
- ], $#, 2, [
-  _MYSQL_PLUGAPPEND_OPTONE([$1],[$2])
- ],[
-  _MYSQL_PLUGAPPEND_OPTONE([$1],[$2])
-  _MYSQL_PLUGAPPEND_OPTS([$1], m4_shift(m4_shift($@)))
- ])
-])
 
-AC_DEFUN([_MYSQL_PLUGAPPEND_OPTONE],[
- ifelse([$2], [all], [
+dnl SYNOPSIS
+dnl   _MYSQL_PLUGAPPEND_META([name],[meta,meta...])
+dnl
+dnl DESCRIPTION
+dnl   Helper macro for adding plugins to meta plugins
+
+AC_DEFUN([_MYSQL_PLUGAPPEND_META],[
+ ifelse($#, 1, [], [$#:$2], [2:], [], [$2], [all], [
   AC_FATAL([protected plugin group: all])
+ ], [$2], [none], [
+  AC_FATAL([protected plugin group: none])
  ],[
-  ifelse([$2], [none], [
-   AC_FATAL([protected plugin group: none])
-  ],[
-   _MYSQL_PLUGAPPEND([__mysql_$1_configs__],[$2])
-   _MYSQL_PLUGAPPEND([__mysql_]m4_bpatsubst($2, -, _)[_plugins__],[$1], [
-    _MYSQL_PLUGAPPEND([__mysql_metaplugin_list__],[$2])
-   ])
+  _MYSQL_PLUGAPPEND([__mysql_$1_configs__],[$2])
+  _MYSQL_PLUGAPPEND([__mysql_]m4_bpatsubst($2, -, _)[_plugins__],[$1], [
+   _MYSQL_PLUGAPPEND([__mysql_metaplugin_list__],[$2])
   ])
+  _MYSQL_PLUGAPPEND_META([$1], m4_shift(m4_shift($@)))
  ])
 ])
 
@@ -504,6 +542,12 @@ AC_DEFUN([_MYSQL_PLUGAPPEND_OPTONE],[
 dnl ---------------------------------------------------------------------------
 
 
+dnl SYNOPSIS
+dnl   MYSQL_LIST_PLUGINS
+dnl
+dnl DESCRIPTION
+dnl   Emits formatted list of declared plugins
+
 AC_DEFUN([MYSQL_LIST_PLUGINS],[dnl
  m4_ifdef([__mysql_plugin_list__],[dnl
   _MYSQL_LIST_PLUGINS(m4_bpatsubst(__mysql_plugin_list__, :, [,]))dnl
@@ -523,22 +567,22 @@ AC_DEFUN([MYSQL_SHOW_PLUGIN],[
  _MYSQL_SHOW_PLUGIN(
   [$1],
   [$1-plugin],
-  [MYSQL_MODULE_NAME_]AS_TR_CPP([$1]),
-  [MYSQL_MODULE_DESC_]AS_TR_CPP([$1]),
-  [MYSQL_MODULE_DEFINE_]AS_TR_CPP([$1]),
-  [MYSQL_MODULE_DIRECTORY_]AS_TR_CPP([$1]),
-  [MYSQL_MODULE_STATIC_]AS_TR_CPP([$1]),
-  [MYSQL_MODULE_DYNAMIC_]AS_TR_CPP([$1]),
-  [MYSQL_MODULE_MANDATORY_]AS_TR_CPP([$1]),
-  [MYSQL_MODULE_DISABLED_]AS_TR_CPP([$1]),
-  [MYSQL_MODULE_ACTIONS_]AS_TR_CPP([$1]),
+  [MYSQL_PLUGIN_NAME_]AS_TR_CPP([$1]),
+  [MYSQL_PLUGIN_DESC_]AS_TR_CPP([$1]),
+  [MYSQL_PLUGIN_DEFINE_]AS_TR_CPP([$1]),
+  [MYSQL_PLUGIN_DIRECTORY_]AS_TR_CPP([$1]),
+  [MYSQL_PLUGIN_STATIC_]AS_TR_CPP([$1]),
+  [MYSQL_PLUGIN_DYNAMIC_]AS_TR_CPP([$1]),
+  [MYSQL_PLUGIN_MANDATORY_]AS_TR_CPP([$1]),
+  [MYSQL_PLUGIN_DISABLED_]AS_TR_CPP([$1]),
+  [MYSQL_PLUGIN_ACTIONS_]AS_TR_CPP([$1]),
   __mysql_[$1]_configs__,
  )
 ])
 
 AC_DEFUN([_MYSQL_SHOW_PLUGIN],[dnl
   === $3 ===
-  Module Name:      [$1]
+  Plugin Name:      [$1]
   Description:      $4
   Supports build:   _PLUGIN_BUILD_TYPE([$7],[$8])[]dnl
 m4_ifdef([$12],[
@@ -557,134 +601,115 @@ AC_DEFUN([_PLUGIN_BUILD_TYPE],
 dnl ---------------------------------------------------------------------------
 
 
-AC_DEFUN([_MYSQL_MODULE_ARGS_CHECK],[
- ifelse($#, 0, [], $#, 1, [
-  _MYSQL_CHECK_PLUGIN_ARG([$1],
-   [MYSQL_MODULE_DISABLED_]AS_TR_CPP([$1]),
-   [MYSQL_MODULE_ACTIONS_]AS_TR_CPP([$1]))
- ],[
-  _MYSQL_CHECK_PLUGIN_ARG([$1],
-   [MYSQL_MODULE_DISABLED_]AS_TR_CPP([$1]),
-   [MYSQL_MODULE_ACTIONS_]AS_TR_CPP([$1]))
-  _MYSQL_MODULE_ARGS_CHECK(m4_shift($@))
- ])
-])
-
-AC_DEFUN([_MYSQL_CHECK_PLUGIN_ARG],[
- m4_ifdef([$3], [], [m4_define([$3],[ ])])
+AC_DEFUN([_MYSQL_EMIT_PLUGINS],[
+ ifelse($#, 0, [], [$#:$1], [1:], [], [
+  m4_ifdef([MYSQL_PLUGIN_ACTIONS_]AS_TR_CPP([$1]), [], [
+   m4_define([MYSQL_PLUGIN_ACTIONS_]AS_TR_CPP([$1]),[ ])
+  ])
     [$1] )
- m4_ifdef([$2],[
+  m4_ifdef([MYSQL_PLUGIN_DISABLED_]AS_TR_CPP([$1]),[
       AC_MSG_ERROR([plugin $1 is disabled])
- ],[
-      [mysql_module_]m4_bpatsubst([$1], -, _)=yes
- ])
+  ],[
+      [mysql_plugin_]m4_bpatsubst([$1], -, _)=yes
+  ])
       ;;
-])
-
-AC_DEFUN([_MYSQL_SANE_VARS], [
- ifelse($#, 0, [], $#, 1, [
-  _MYSQL_SANEVAR([$1])
- ],[
-  _MYSQL_SANEVAR([$1])
-  _MYSQL_SANE_VARS(m4_shift($@))
+  _MYSQL_EMIT_PLUGINS(m4_shift($@))
  ])
 ])
 
-AC_DEFUN([_MYSQL_SANEVAR], [
-   test -z "[$mysql_module_]m4_bpatsubst([$1], -, _)" &&
-[mysql_module_]m4_bpatsubst([$1], -, _)='.'
-   test -z "[$with_module_]m4_bpatsubst([$1], -, _)" &&
-[with_module_]m4_bpatsubst([$1], -, _)='.'
-])
-
-AC_DEFUN([_MYSQL_CHECK_DEPENDENCIES], [
- ifelse($#, 0, [], $#, 1, [
-  _MYSQL_CHECK_DEPENDS([$1],[__mysql_plugdepends_$1__])
- ],[
-  _MYSQL_CHECK_DEPENDS([$1],[__mysql_plugdepends_$1__])
-  _MYSQL_CHECK_DEPENDENCIES(m4_shift($@))
+AC_DEFUN([_MYSQL_EMIT_PLUGIN_DEPENDS], [
+ ifelse($#, 0, [], [$#:$1], [1:], [], [
+  _MYSQL_EMIT_CHECK_DEPENDS(m4_bpatsubst([$1], -, _), 
+                            [__mysql_plugdepends_$1__])
+  _MYSQL_EMIT_PLUGIN_DEPENDS(m4_shift($@))
  ])
 ])
 
-AC_DEFUN([_MYSQL_CHECK_DEPENDS], [
+AC_DEFUN([_MYSQL_EMIT_CHECK_DEPENDS], [
  m4_ifdef([$2], [
-   if test "[$mysql_module_]m4_bpatsubst([$1], -, _)" = yes -a \
-           "[$with_module_]m4_bpatsubst([$1], -, _)" != no -o \
-           "[$with_module_]m4_bpatsubst([$1], -, _)" = yes; then
-     _MYSQL_GEN_DEPENDS(m4_bpatsubst($2, :, [,]))
+   if test "X[$mysql_plugin_]$1" = Xyes -a \
+           "X[$with_plugin_]$1" != Xno -o \
+           "X[$with_plugin_]$1" = Xyes; then
+     _MYSQL_EMIT_PLUGIN_DEPENDENCIES(m4_bpatsubst($2, :, [,]))
    fi
  ])
 ])
 
-AC_DEFUN([_MYSQL_GEN_DEPENDS], [
- ifelse($#, 0, [], $#, 1, [
-  _MYSQL_GEN_DEPEND([$1])
- ],[
-  _MYSQL_GEN_DEPEND([$1])
-  _MYSQL_GEN_DEPENDS(m4_shift($@))
+AC_DEFUN([_MYSQL_EMIT_PLUGIN_DEPENDENCIES], [
+ ifelse($#, 0, [], [
+  m4_ifdef([MYSQL_PLUGIN_DISABLED_]AS_TR_CPP([$1]),[
+       AC_MSG_ERROR([depends upon disabled plugin $1])
+  ],[
+       [mysql_plugin_]m4_bpatsubst([$1], -, _)=yes
+       if test "X[$with_plugin_]m4_bpatsubst([$1], -, _)" = Xno; then
+         AC_MSG_ERROR([depends upon disabled plugin $1])
+       fi
+  ])
+  _MYSQL_EMIT_PLUGIN_DEPENDENCIES(m4_shift($@))
  ])
 ])
 
-AC_DEFUN([_MYSQL_GEN_DEPEND], [
- m4_ifdef([MYSQL_MODULE_DISABLED_]AS_TR_CPP([$1]),[
-      AC_MSG_ERROR([depends upon disabled module $1])
- ],[
-      [mysql_module_]m4_bpatsubst([$1], -, _)=yes
-      if test "[$with_module_]m4_bpatsubst([$1], -, _)" = no; then
-        AC_MSG_ERROR([depends upon disabled module $1])
-      fi
- ])
-])
+dnl SYNOPSIS
+dnl   _MYSQL_CHECK_PLUGIN_ARGS([plugin],[plugin]...)
+dnl
+dnl DESCRIPTION
+dnl   Emits shell script for checking configure arguments
+dnl   Arguments to this macro is default value for selected plugins
 
 AC_DEFUN([_MYSQL_CHECK_PLUGIN_ARGS],[
- AC_ARG_WITH([modules],
-AS_HELP_STRING([--with-modules=PLUGIN[[[[[,PLUGIN..]]]]]],
- [Plugin modules to include in mysqld. (default is: $1) Must be a
- configuration name or a comma separated list of modules.])
-AS_HELP_STRING([],[Available configurations are:] dnl
-m4_bpatsubst([none:all]m4_ifdef([__mysql_metaplugin_list__],
-__mysql_metaplugin_list__), :, [ ])[.])
-AS_HELP_STRING([],[Available plugin modules are:] dnl
+ __MYSQL_CHECK_PLUGIN_ARGS(m4_default([$1], [none]))
+])
+
+AC_DEFUN([__MYSQL_CHECK_PLUGIN_ARGS],[
+ AC_ARG_WITH([plugins],
+AS_HELP_STRING([--with-plugins=PLUGIN[[[[[,PLUGIN..]]]]]],
+               [Plugins to include in mysqld. (default is: $1) Must be a
+                configuration name or a comma separated list of plugins.])
+AS_HELP_STRING([],
+               [Available configurations are:] dnl
+m4_bpatsubst([none:]m4_ifdef([__mysql_metaplugin_list__],
+             __mysql_metaplugin_list__:)[all], :, [ ])[.])
+AS_HELP_STRING([],
+               [Available plugins are:] dnl
 m4_bpatsubst(__mysql_plugin_list__, :, [ ])[.])
-AS_HELP_STRING([--without-module-PLUGIN],
-                [Disable the named module from being built. Otherwise, for
-                modules which are not selected for inclusion in mysqld will be
+AS_HELP_STRING([--without-plugin-PLUGIN],
+               [Disable the named plugin from being built. Otherwise, for
+                plugins which are not selected for inclusion in mysqld will be
                 built dynamically (if supported)])
-AS_HELP_STRING([--with-module-PLUGIN],
-               [Forces the named module to be linked into mysqld statically.]),
- [mysql_modules="`echo $withval | tr ',.:;*[]' '       '`"],
- [mysql_modules=['$1']])
+AS_HELP_STRING([--with-plugin-PLUGIN],
+               [Forces the named plugin to be linked into mysqld statically.]),
+ [mysql_plugins="`echo $withval | tr ',.:;*[]' '       '`"],
+ [mysql_plugins=['$1']])
 
 m4_divert_once([HELP_VAR_END],[
-Description of plugin modules:
+Description of plugins:
 MYSQL_LIST_PLUGINS])
 
-  case "$mysql_modules" in
+  case "$mysql_plugins" in
   all )
-    mysql_modules='m4_bpatsubst(__mysql_plugin_list__, :, [ ])'
+    mysql_plugins='m4_bpatsubst(__mysql_plugin_list__, :, [ ])'
     ;;
   none )
-    mysql_modules=''
+    mysql_plugins=''
     ;;
 m4_ifdef([__mysql_metaplugin_list__],[
-_MYSQL_MODULE_META_CHECK(m4_bpatsubst(__mysql_metaplugin_list__, :, [,]))
+_MYSQL_EMIT_METAPLUGINS(m4_bpatsubst(__mysql_metaplugin_list__, :, [,]))
 ])
   esac
 
-  for plugin in $mysql_modules; do
+  for plugin in $mysql_plugins; do
     case "$plugin" in
     all | none )
-      AC_MSG_ERROR([bad module name: $plugin])
+      AC_MSG_ERROR([bad plugin name: $plugin])
       ;;
-_MYSQL_MODULE_ARGS_CHECK(m4_bpatsubst(__mysql_plugin_list__, :, [,]))
+_MYSQL_EMIT_PLUGINS(m4_bpatsubst(__mysql_plugin_list__, :, [,]))
     * )
-      AC_MSG_ERROR([unknown plugin module: $plugin])
+      AC_MSG_ERROR([unknown plugin: $plugin])
       ;;
     esac
   done
 
-  _MYSQL_SANE_VARS(m4_bpatsubst(__mysql_plugin_list__, :, [,]))  
-  _MYSQL_CHECK_DEPENDENCIES(m4_bpatsubst(__mysql_plugin_list__, :, [,]))
+  _MYSQL_EMIT_PLUGIN_DEPENDS(m4_bpatsubst(__mysql_plugin_list__, :, [,]))
 ])
 
 dnl ===========================================================================
diff --git a/configure.in b/configure.in
index 78a0ea5f7b2..c027e41ed7c 100644
--- a/configure.in
+++ b/configure.in
@@ -54,81 +54,81 @@ romanian russian serbian slovak spanish swedish ukrainian"
 
 MYSQL_STORAGE_ENGINE(archive,,  [Archive Storage Engine],
         [Archive Storage Engine], [max,max-no-ndb])
-MYSQL_MODULE_DIRECTORY(archive, [storage/archive])
-MYSQL_MODULE_STATIC(archive,    [libarchive.a])
-MYSQL_MODULE_DYNAMIC(archive,   [ha_archive.la])
+MYSQL_PLUGIN_DIRECTORY(archive, [storage/archive])
+MYSQL_PLUGIN_STATIC(archive,    [libarchive.a])
+MYSQL_PLUGIN_DYNAMIC(archive,   [ha_archive.la])
 
 MYSQL_STORAGE_ENGINE(berkeley,  berkeley-db, [BerkeleyDB Storage Engine],
         [Transactional Tables using BerkeleyDB], [max,max-no-ndb])
-MYSQL_MODULE_DIRECTORY(berkeley,[storage/bdb])
-MYSQL_MODULE_STATIC(berkeley,   [[\$(bdb_libs_with_path)]])
-MYSQL_MODULE_ACTIONS(berkeley,  [MYSQL_SETUP_BERKELEY_DB])
+MYSQL_PLUGIN_DIRECTORY(berkeley,[storage/bdb])
+MYSQL_PLUGIN_STATIC(berkeley,   [[\$(bdb_libs_with_path)]])
+MYSQL_PLUGIN_ACTIONS(berkeley,  [MYSQL_SETUP_BERKELEY_DB])
 
 MYSQL_STORAGE_ENGINE(blackhole,,[Blackhole Storage Engine],
         [Basic Write-only Read-never tables], [max,max-no-ndb])
-MYSQL_MODULE_DIRECTORY(blackhole, [storage/blackhole])
-MYSQL_MODULE_STATIC(blackhole,  [libblackhole.a])
-MYSQL_MODULE_DYNAMIC(blackhole, [ha_blackhole.la])
+MYSQL_PLUGIN_DIRECTORY(blackhole, [storage/blackhole])
+MYSQL_PLUGIN_STATIC(blackhole,  [libblackhole.a])
+MYSQL_PLUGIN_DYNAMIC(blackhole, [ha_blackhole.la])
 
 MYSQL_STORAGE_ENGINE(csv,,      [CSV Storage Engine],
         [Stores tables in text CSV format])
-MYSQL_MODULE_DIRECTORY(csv,     [storage/csv])
-MYSQL_MODULE_STATIC(csv,        [libcsv.a])
+MYSQL_PLUGIN_DIRECTORY(csv,     [storage/csv])
+MYSQL_PLUGIN_STATIC(csv,        [libcsv.a])
+MYSQL_PLUGIN_MANDATORY(csv)     dnl Used for logging
 
 MYSQL_STORAGE_ENGINE(example,,  [Example Storage Engine],
         [Skeleton for Storage Engines for developers], [max,max-no-ndb])
-MYSQL_MODULE_DIRECTORY(example, [storage/example])
-MYSQL_MODULE_STATIC(example,    [libexample.a])
-MYSQL_MODULE_DYNAMIC(example,   [ha_example.la])
+MYSQL_PLUGIN_DIRECTORY(example, [storage/example])
+MYSQL_PLUGIN_STATIC(example,    [libexample.a])
+MYSQL_PLUGIN_DYNAMIC(example,   [ha_example.la])
 
 MYSQL_STORAGE_ENGINE(federated,,[Federated Storage Engine],
         [Connects to tables on remote MySQL servers], [max,max-no-ndb])
 
-MYSQL_MODULE(ftexample,         [Simple Parser],
+MYSQL_PLUGIN(ftexample,         [Simple Parser],
         [Simple full-text parser plugin])
-MYSQL_MODULE_DIRECTORY(ftexample, [plugin/fulltext])
-MYSQL_MODULE_DYNAMIC(ftexample, [mypluglib.la])
+MYSQL_PLUGIN_DIRECTORY(ftexample, [plugin/fulltext])
+MYSQL_PLUGIN_DYNAMIC(ftexample, [mypluglib.la])
 
 MYSQL_STORAGE_ENGINE(heap,no,   [Memory Storage Engine],
         [In memory hashed tables])
-MYSQL_MODULE_DIRECTORY(heap,    [storage/heap])
-MYSQL_MODULE_STATIC(heap,       [libheap.a])
+MYSQL_PLUGIN_DIRECTORY(heap,    [storage/heap])
+MYSQL_PLUGIN_STATIC(heap,       [libheap.a])
+MYSQL_PLUGIN_MANDATORY(heap)    dnl Memory tables
 
 MYSQL_STORAGE_ENGINE(innobase,  innodb, [InnoDB Storage Engine],
         [Transactional Tables using InnoDB], [max,max-no-ndb])
-MYSQL_MODULE_DIRECTORY(innobase, [storage/innobase])
-MYSQL_MODULE_STATIC(innobase,   [libinnobase.a])
-MYSQL_MODULE_ACTIONS(innobase,  [
+MYSQL_PLUGIN_DIRECTORY(innobase, [storage/innobase])
+MYSQL_PLUGIN_STATIC(innobase,   [libinnobase.a])
+MYSQL_PLUGIN_ACTIONS(innobase,  [
   AC_CHECK_LIB(rt, aio_read, [innodb_system_libs="-lrt"])
   AC_SUBST(innodb_system_libs)
 ])
 
 MYSQL_STORAGE_ENGINE(myisam,no, [MyISAM Storage Engine],
         [Traditional non-transactional MySQL tables])
-MYSQL_MODULE_DIRECTORY(myisam,  [storage/myisam])
-MYSQL_MODULE_STATIC(myisam,     [libmyisam.a])
+MYSQL_PLUGIN_DIRECTORY(myisam,  [storage/myisam])
+MYSQL_PLUGIN_STATIC(myisam,     [libmyisam.a])
+MYSQL_PLUGIN_MANDATORY(myisam)  dnl Default
 
 MYSQL_STORAGE_ENGINE(myisammrg,no,[MyISAM MERGE Engine],
         [Merge multiple MySQL tables into one])
-MYSQL_MODULE_DIRECTORY(myisammrg,[storage/myisammrg])
-MYSQL_MODULE_STATIC(myisammrg,  [libmyisammrg.a])
+MYSQL_PLUGIN_DIRECTORY(myisammrg,[storage/myisammrg])
+MYSQL_PLUGIN_STATIC(myisammrg,  [libmyisammrg.a])
+MYSQL_PLUGIN_MANDATORY(myisammrg)
 
 MYSQL_STORAGE_ENGINE(ndbcluster, ndbcluster, [Cluster Storage Engine],
         [High Availability Clustered tables], [max])
-MYSQL_MODULE_DIRECTORY(ndbcluster,[storage/ndb])
-MYSQL_MODULE_STATIC(ndbcluster, [[\$(ndbcluster_libs) \$(ndbcluster_system_libs) \$(NDB_SCI_LIBS)]])
-MYSQL_MODULE_ACTIONS(ndbcluster,[MYSQL_SETUP_NDBCLUSTER])
+MYSQL_PLUGIN_DIRECTORY(ndbcluster,[storage/ndb])
+MYSQL_PLUGIN_STATIC(ndbcluster, [[\$(ndbcluster_libs) \$(ndbcluster_system_libs) \$(NDB_SCI_LIBS)]])
+MYSQL_PLUGIN_ACTIONS(ndbcluster,[MYSQL_SETUP_NDBCLUSTER])
 
 MYSQL_STORAGE_ENGINE(partition, partition, [Partition Support],
         [MySQL Partitioning Support], [max,max-no-ndb])
 
-MYSQL_MODULE_MANDATORY(csv)     dnl Used for logging
-MYSQL_MODULE_MANDATORY(heap)    dnl Memory tables
-MYSQL_MODULE_MANDATORY(myisam)  dnl Default
-MYSQL_MODULE_MANDATORY(myisammrg)
-
 dnl -- ndbcluster requires partition to be enabled
-MYSQL_MODULE_DEPENDS(ndbcluster, partition)
+MYSQL_PLUGIN_DEPENDS(ndbcluster, [partition])
+
 
 #####
 #####
diff --git a/storage/archive/Makefile.am b/storage/archive/Makefile.am
index 4263d8f2659..85577f406da 100644
--- a/storage/archive/Makefile.am
+++ b/storage/archive/Makefile.am
@@ -57,5 +57,6 @@ archive_test_LDADD =	$(top_builddir)/mysys/libmysys.a \
 archive_test_LDFLAGS = @NOINST_LDFLAGS@
 
 
+EXTRA_DIST =		cmakelists.txt
 # Don't update the files from bitkeeper
 %::SCCS/s.%
diff --git a/storage/blackhole/Makefile.am b/storage/blackhole/Makefile.am
index 3a235bc86dd..902d57c1668 100644
--- a/storage/blackhole/Makefile.am
+++ b/storage/blackhole/Makefile.am
@@ -47,5 +47,6 @@ libblackhole_a_CFLAGS =	$(AM_CFLAGS)
 libblackhole_a_SOURCES=	ha_blackhole.cc
 
 
+EXTRA_DIST =		cmakelists.txt
 # Don't update the files from bitkeeper
 %::SCCS/s.%
diff --git a/storage/csv/Makefile.am b/storage/csv/Makefile.am
index 0d3fd654745..a2afeba137f 100644
--- a/storage/csv/Makefile.am
+++ b/storage/csv/Makefile.am
@@ -41,5 +41,6 @@ noinst_LIBRARIES =	@plugin_csv_static_target@
 libcsv_a_CXXFLAGS =	$(AM_CFLAGS)
 libcsv_a_SOURCES =	ha_tina.cc
 
+EXTRA_DIST =		cmakelists.txt
 # Don't update the files from bitkeeper
 %::SCCS/s.%
diff --git a/storage/example/Makefile.am b/storage/example/Makefile.am
index f97dcc09e6b..9c4bedb2160 100644
--- a/storage/example/Makefile.am
+++ b/storage/example/Makefile.am
@@ -47,5 +47,6 @@ libexample_a_CFLAGS =	$(AM_CFLAGS)
 libexample_a_SOURCES=	ha_example.cc
 
 
+EXTRA_DIST =		cmakelists.txt
 # Don't update the files from bitkeeper
 %::SCCS/s.%

From f0341ac431cc925ab64e0dd59581a3461a38f0e6 Mon Sep 17 00:00:00 2001
From: "knielsen@mysql.com" <>
Date: Tue, 2 May 2006 09:19:54 +0200
Subject: [PATCH 092/108] Fix a bunch of non-Linux compile failures.

---
 VC++Files/mysql.sln          |  1 +
 VC++Files/mysys/mysys.vcproj | 43 ++++++++++++++++++++++++++++++++++++
 mysys/my_memmem.c            |  5 +++--
 tests/Makefile.am            |  2 +-
 tests/mysql_client_test.c    |  3 ++-
 5 files changed, 50 insertions(+), 4 deletions(-)

diff --git a/VC++Files/mysql.sln b/VC++Files/mysql.sln
index 14f16f8fd8d..3e3e4c67e17 100644
--- a/VC++Files/mysql.sln
+++ b/VC++Files/mysql.sln
@@ -278,6 +278,7 @@ EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mysql_client_test", "tests\mysql_client_test.vcproj", "{DA224DAB-5006-42BE-BB77-16E8BE5326D5}"
 	ProjectSection(ProjectDependencies) = postProject
 		{26383276-4843-494B-8BE0-8936ED3EBAAB} = {26383276-4843-494B-8BE0-8936ED3EBAAB}
+		{44D9C7DC-6636-4B82-BD01-6876C64017DF} = {44D9C7DC-6636-4B82-BD01-6876C64017DF}
 	EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mysql_test_run_new", "mysql-test\mysql_test_run_new.vcproj", "{6189F838-21C6-42A1-B2D0-9146316573F7}"
diff --git a/VC++Files/mysys/mysys.vcproj b/VC++Files/mysys/mysys.vcproj
index d124551e0bb..1053b605119 100644
--- a/VC++Files/mysys/mysys.vcproj
+++ b/VC++Files/mysys/mysys.vcproj
@@ -3188,6 +3188,49 @@
 					PreprocessorDefinitions=""/>
 			
 		
+		
+			
+				
+			
+			
+				
+			
+			
+				
+			
+			
+				
+			
+			
+				
+			
+		
 		
 			 haystacklen) return(NULL);
diff --git a/tests/Makefile.am b/tests/Makefile.am
index ec732462ca5..ebe97393045 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -42,7 +42,7 @@ INCLUDES =		-I$(top_builddir)/include -I$(top_srcdir)/include \
 LIBS =			@CLIENT_LIBS@
 LDADD =			@CLIENT_EXTRA_LDFLAGS@ \
                         $(top_builddir)/libmysql/libmysqlclient.la
-mysql_client_test_LDADD= $(LDADD) $(CXXLDFLAGS) -lmysys -L../mysys
+mysql_client_test_LDADD= $(LDADD) $(CXXLDFLAGS) -L../mysys -lmysys
 mysql_client_test_SOURCES= mysql_client_test.c $(yassl_dummy_link_fix)
 insert_test_SOURCES=       insert_test.c $(yassl_dummy_link_fix)
 select_test_SOURCES=       select_test.c $(yassl_dummy_link_fix)
diff --git a/tests/mysql_client_test.c b/tests/mysql_client_test.c
index 4bd636a7ae3..b0971980168 100644
--- a/tests/mysql_client_test.c
+++ b/tests/mysql_client_test.c
@@ -14828,7 +14828,6 @@ static void test_bug15613()
 static void test_bug17667()
 {
   int rc;
-  myheader("test_bug17667");
   struct buffer_and_length {
     const char *buffer;
     const uint length;
@@ -14845,6 +14844,8 @@ static void test_bug17667()
   struct buffer_and_length *statement_cursor;
   FILE *log_file;
 
+  myheader("test_bug17667");
+
   for (statement_cursor= statements; statement_cursor->buffer != NULL;
       statement_cursor++) {
     rc= mysql_real_query(mysql, statement_cursor->buffer,

From f1d4921139a353c0f99751c6bfd710b81e074929 Mon Sep 17 00:00:00 2001
From: "acurtis@xiphis.org" <>
Date: Tue, 2 May 2006 04:11:00 -0700
Subject: [PATCH 093/108] WL#3201 additional post-review fixes

---
 config/ac-macros/plugins.m4       |  8 ++++----
 configure.in                      |  2 +-
 include/mysql/plugin.h            | 10 +++++-----
 sql/ha_berkeley.cc                | 14 +++++++++-----
 sql/ha_federated.cc               | 11 +++++++----
 sql/ha_heap.cc                    | 14 +++++++++-----
 sql/ha_innodb.cc                  | 12 ++++++++----
 sql/ha_myisam.cc                  | 12 ++++++++----
 sql/ha_myisammrg.cc               | 12 ++++++++----
 sql/ha_ndbcluster.cc              |  7 +++++--
 sql/ha_partition.cc               | 11 +++++++----
 storage/archive/ha_archive.cc     | 11 +++++++----
 storage/blackhole/ha_blackhole.cc | 12 ++++++++----
 storage/csv/ha_tina.cc            | 11 +++++++----
 storage/example/ha_example.cc     | 11 +++++++----
 15 files changed, 100 insertions(+), 58 deletions(-)

diff --git a/config/ac-macros/plugins.m4 b/config/ac-macros/plugins.m4
index 0ca952c4354..385b6f1d66c 100644
--- a/config/ac-macros/plugins.m4
+++ b/config/ac-macros/plugins.m4
@@ -38,9 +38,7 @@ AC_DEFUN([_MYSQL_PLUGIN],[
   _MYSQL_PLUGAPPEND([__mysql_plugin_list__],[$1])
   m4_define([MYSQL_PLUGIN_NAME_]AS_TR_CPP([$1]), [$3])
   m4_define([MYSQL_PLUGIN_DESC_]AS_TR_CPP([$1]), [$4])
-  ifelse([$5], [], [], [
-   _MYSQL_PLUGAPPEND_META([$1], $5)
-  ])
+  _MYSQL_PLUGAPPEND_META([$1], $5)
  ])
 ])
 
@@ -351,11 +349,13 @@ AC_DEFUN([__MYSQL_EMIT_CHECK_PLUGIN],[
     else
       m4_ifdef([$7],[
        ifelse(m4_bregexp($7, [^lib[^.]+\.a$]), -2, [
+dnl change above "-2" to "0" to enable this section
+dnl Although this is "pretty", it breaks libmysqld build
         m4_ifdef([$6],[
          mysql_use_plugin_dir="$6"
          mysql_plugin_libs="$mysql_plugin_libs -L[\$(top_builddir)]/$6"
         ])
-        mysql_plugin_libs="$mysql_plugin_libs
+        mysql_plugin_libs="$mysql_plugin_libs dnl
 [-l]m4_bregexp($7, [^lib\([^.]+\)], [\1])"
        ], m4_bregexp($7, [^\\\$]), 0, [
         m4_ifdef([$6],[
diff --git a/configure.in b/configure.in
index e7b06530012..162bff48b7f 100644
--- a/configure.in
+++ b/configure.in
@@ -91,7 +91,7 @@ MYSQL_PLUGIN_DIRECTORY(ftexample, [plugin/fulltext])
 MYSQL_PLUGIN_DYNAMIC(ftexample, [mypluglib.la])
 
 MYSQL_STORAGE_ENGINE(heap,no,   [Memory Storage Engine],
-        [In memory hashed tables])
+        [Volatile memory based tables])
 MYSQL_PLUGIN_DIRECTORY(heap,    [storage/heap])
 MYSQL_PLUGIN_STATIC(heap,       [libheap.a])
 MYSQL_PLUGIN_MANDATORY(heap)    dnl Memory tables
diff --git a/include/mysql/plugin.h b/include/mysql/plugin.h
index 2093043744a..ab5ca6e7be4 100644
--- a/include/mysql/plugin.h
+++ b/include/mysql/plugin.h
@@ -39,23 +39,23 @@
 
 
 #ifndef MYSQL_DYNAMIC_PLUGIN
-#define __DECLARE_PLUGIN(NAME, VERSION, PSIZE, DECLS)                         \
+#define __MYSQL_DECLARE_PLUGIN(NAME, VERSION, PSIZE, DECLS)                   \
 int VERSION= MYSQL_PLUGIN_INTERFACE_VERSION;                                  \
 int PSIZE= sizeof(struct st_mysql_plugin);                                    \
 struct st_mysql_plugin DECLS[]= {
 #else
-#define __DECLARE_PLUGIN(NAME, VERSION, PSIZE, DECLS)                         \
+#define __MYSQL_DECLARE_PLUGIN(NAME, VERSION, PSIZE, DECLS)                   \
 int _mysql_plugin_interface_version_= MYSQL_PLUGIN_INTERFACE_VERSION;         \
 int _mysql_sizeof_struct_st_plugin_= sizeof(struct st_mysql_plugin);          \
 struct st_mysql_plugin _mysql_plugin_declarations_[]= {
 #endif
 
-#define _DECLARE_PLUGIN(NAME) \
-__DECLARE_PLUGIN(NAME, builtin_ ## NAME ## _plugin_interface_version, \
+#define mysql_declare_plugin(NAME) \
+__MYSQL_DECLARE_PLUGIN(NAME, \
+                 builtin_ ## NAME ## _plugin_interface_version, \
                  builtin_ ## NAME ## _sizeof_struct_st_plugin, \
                  builtin_ ## NAME ## _plugin)
 
-#define mysql_declare_plugin(NAME) _DECLARE_PLUGIN(NAME)
 #define mysql_declare_plugin_end ,{0,0,0,0,0,0,0,0,0}}
 
 /*
diff --git a/sql/ha_berkeley.cc b/sql/ha_berkeley.cc
index 0fabd00faa3..ef1876c0e2e 100644
--- a/sql/ha_berkeley.cc
+++ b/sql/ha_berkeley.cc
@@ -125,11 +125,15 @@ static int berkeley_savepoint(THD* thd, void *savepoint);
 static int berkeley_release_savepoint(THD* thd, void *savepoint);
 static handler *berkeley_create_handler(TABLE_SHARE *table);
 
+static const char berkeley_hton_name[]= "BerkeleyDB";
+static const char berkeley_hton_comment[]=
+  "Supports transactions and page-level locking";
+
 handlerton berkeley_hton = {
   MYSQL_HANDLERTON_INTERFACE_VERSION,
-  "BerkeleyDB",
+  berkeley_hton_name,
   SHOW_OPTION_YES,
-  "Supports transactions and page-level locking", 
+  berkeley_hton_comment, 
   DB_TYPE_BERKELEY_DB,
   berkeley_init,
   0, /* slot */
@@ -2733,9 +2737,9 @@ mysql_declare_plugin(berkeley)
 {
   MYSQL_STORAGE_ENGINE_PLUGIN,
   &berkeley_hton,
-  berkeley_hton.name,
-  "MySQL AB",
-  "BerkeleyDB Storage Engine",
+  berkeley_hton_name,
+  "Sleepycat Software",
+  berkeley_hton_comment,
   NULL, /* Plugin Init */
   NULL, /* Plugin Deinit */
   0x0100 /* 1.0 */,
diff --git a/sql/ha_federated.cc b/sql/ha_federated.cc
index f1d2b0025a9..f4fc5f47193 100644
--- a/sql/ha_federated.cc
+++ b/sql/ha_federated.cc
@@ -370,11 +370,14 @@ static int federated_rollback(THD *thd, bool all);
 
 /* Federated storage engine handlerton */
 
+static const char federated_hton_name[]= "FEDERATED";
+static const char federated_hton_comment[]= "Federated MySQL storage engine";
+
 handlerton federated_hton= {
   MYSQL_HANDLERTON_INTERFACE_VERSION,
-  "FEDERATED",
+  federated_hton_name,
   SHOW_OPTION_YES,
-  "Federated MySQL storage engine", 
+  federated_hton_comment, 
   DB_TYPE_FEDERATED_DB,
   federated_db_init,
   0,       /* slot */
@@ -2813,9 +2816,9 @@ mysql_declare_plugin(federated)
 {
   MYSQL_STORAGE_ENGINE_PLUGIN,
   &federated_hton,
-  federated_hton.name,
+  federated_hton_name,
   "Patrick Galbraith and Brian Aker, MySQL AB",
-  "Federated Storage Engine",
+  federated_hton_comment,
   NULL, /* Plugin Init */
   NULL, /* Plugin Deinit */
   0x0100 /* 1.0 */,
diff --git a/sql/ha_heap.cc b/sql/ha_heap.cc
index 1223de37af8..ca33a31de4b 100644
--- a/sql/ha_heap.cc
+++ b/sql/ha_heap.cc
@@ -26,11 +26,15 @@
 
 static handler *heap_create_handler(TABLE_SHARE *table);
 
+static const char heap_hton_name[]= "MEMORY";
+static const char heap_hton_comment[]=
+  "Hash based, stored in memory, useful for temporary tables";
+
 handlerton heap_hton= {
   MYSQL_HANDLERTON_INTERFACE_VERSION,
-  "MEMORY",
+  heap_hton_name,
   SHOW_OPTION_YES,
-  "Hash based, stored in memory, useful for temporary tables", 
+  heap_hton_comment,
   DB_TYPE_HEAP,
   NULL,
   0,       /* slot */
@@ -711,9 +715,9 @@ mysql_declare_plugin(heap)
 {
   MYSQL_STORAGE_ENGINE_PLUGIN,
   &heap_hton,
-  heap_hton.name,
-  NULL,
-  heap_hton.comment,
+  heap_hton_name,
+  "MySQL AB",
+  heap_hton_comment,
   NULL,
   NULL,
   0
diff --git a/sql/ha_innodb.cc b/sql/ha_innodb.cc
index 530d513cf21..ad7c5fd2c0e 100644
--- a/sql/ha_innodb.cc
+++ b/sql/ha_innodb.cc
@@ -205,11 +205,15 @@ static int innobase_savepoint(THD* thd, void *savepoint);
 static int innobase_release_savepoint(THD* thd, void *savepoint);
 static handler *innobase_create_handler(TABLE_SHARE *table);
 
+static const char innobase_hton_name[]= "InnoDB";
+static const char innobase_hton_comment[]=
+  "Supports transactions, row-level locking, and foreign keys";
+
 handlerton innobase_hton = {
   MYSQL_HANDLERTON_INTERFACE_VERSION,
-  "InnoDB",
+  innobase_hton_name,
   SHOW_OPTION_YES,
-  "Supports transactions, row-level locking, and foreign keys",
+  innobase_hton_comment,
   DB_TYPE_INNODB,
   innobase_init,
   0,				/* slot */
@@ -7439,9 +7443,9 @@ mysql_declare_plugin(innobase)
 {
   MYSQL_STORAGE_ENGINE_PLUGIN,
   &innobase_hton,
-  innobase_hton.name,
+  innobase_hton_name,
   "Innobase OY",
-  "InnoDB Storage Engine",
+  innobase_hton_comment,
   NULL, /* Plugin Init */
   NULL, /* Plugin Deinit */
   0x0100 /* 1.0 */,
diff --git a/sql/ha_myisam.cc b/sql/ha_myisam.cc
index 9a0a4a9896f..74aa157cbc1 100644
--- a/sql/ha_myisam.cc
+++ b/sql/ha_myisam.cc
@@ -56,11 +56,15 @@ static handler *myisam_create_handler(TABLE_SHARE *table);
 
 /* MyISAM handlerton */
 
+static const char myisam_hton_name[]= "MyISAM";
+static const char myisam_hton_comment[]=
+  "Default engine as of MySQL 3.23 with great performance";
+
 handlerton myisam_hton= {
   MYSQL_HANDLERTON_INTERFACE_VERSION,
-  "MyISAM",
+  myisam_hton_name,
   SHOW_OPTION_YES,
-  "Default engine as of MySQL 3.23 with great performance", 
+  myisam_hton_comment, 
   DB_TYPE_MYISAM,
   NULL,
   0,       /* slot */
@@ -1795,9 +1799,9 @@ mysql_declare_plugin(myisam)
 {
   MYSQL_STORAGE_ENGINE_PLUGIN,
   &myisam_hton,
-  myisam_hton.name,
+  myisam_hton_name,
   "MySQL AB",
-  "MyISAM Storage Engine",
+  myisam_hton_comment,
   NULL, /* Plugin Init */
   NULL, /* Plugin Deinit */
   0x0100 /* 1.0 */,
diff --git a/sql/ha_myisammrg.cc b/sql/ha_myisammrg.cc
index 8130a5d939a..89f0f9e3647 100644
--- a/sql/ha_myisammrg.cc
+++ b/sql/ha_myisammrg.cc
@@ -38,11 +38,15 @@ static handler *myisammrg_create_handler(TABLE_SHARE *table);
 
 /* MyISAM MERGE handlerton */
 
+static const char myisammrg_hton_name[]= "MRG_MYISAM";
+static const char myisammrg_hton_comment[]=
+  "Collection of identical MyISAM tables";
+
 handlerton myisammrg_hton= {
   MYSQL_HANDLERTON_INTERFACE_VERSION,
-  "MRG_MYISAM",
+  myisammrg_hton_name,
   SHOW_OPTION_YES,
-  "Collection of identical MyISAM tables", 
+  myisammrg_hton_comment, 
   DB_TYPE_MRG_MYISAM,
   NULL,
   0,       /* slot */
@@ -580,9 +584,9 @@ mysql_declare_plugin(myisammrg)
 {
   MYSQL_STORAGE_ENGINE_PLUGIN,
   &myisammrg_hton,
-  myisammrg_hton.name,
+  myisammrg_hton_name,
   "MySQL AB",
-  "MyISAMMRG Storage Engine",
+  myisammrg_hton_comment,
   NULL, /* Plugin Init */
   NULL, /* Plugin Deinit */
   0x0100 /* 1.0 */,
diff --git a/sql/ha_ndbcluster.cc b/sql/ha_ndbcluster.cc
index 89084f72217..a20026c7af9 100644
--- a/sql/ha_ndbcluster.cc
+++ b/sql/ha_ndbcluster.cc
@@ -69,6 +69,9 @@ static bool ndbcluster_show_status(THD*,stat_print_fn *,enum ha_stat_type);
 static int ndbcluster_alter_tablespace(THD* thd, st_alter_tablespace *info);
 static int ndbcluster_fill_files_table(THD *thd, TABLE_LIST *tables, COND *cond);
 
+static const char ndbcluster_hton_name[]= "ndbcluster";
+static const char ndbcluster_hton_comment[]= "Clustered, fault-tolerant tables";
+
 handlerton ndbcluster_hton = {
   MYSQL_HANDLERTON_INTERFACE_VERSION,
   "ndbcluster",
@@ -10287,9 +10290,9 @@ mysql_declare_plugin(ndbcluster)
 {
   MYSQL_STORAGE_ENGINE_PLUGIN,
   &ndbcluster_hton,
-  ndbcluster_hton.name,
+  ndbcluster_hton_name,
   "MySQL AB",
-  "NDB Storage Engine",
+  ndbcluster_hton_comment,
   NULL, /* Plugin Init */
   NULL, /* Plugin Deinit */
   0x0100 /* 1.0 */,
diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc
index 6b29d6588fc..bff21d6681d 100644
--- a/sql/ha_partition.cc
+++ b/sql/ha_partition.cc
@@ -73,11 +73,14 @@ static handler *partition_create_handler(TABLE_SHARE *share);
 static uint partition_flags();
 static uint alter_table_flags(uint flags);
 
+static const char partition_hton_name[]= "partition";
+static const char partition_hton_comment[]= "Partition Storage Engine Helper";
+
 handlerton partition_hton = {
   MYSQL_HANDLERTON_INTERFACE_VERSION,
-  "partition",
+  partition_hton_name,
   SHOW_OPTION_YES,
-  "Partition Storage Engine Helper", /* A comment used by SHOW to describe an engine */
+  partition_hton_comment, /* A comment used by SHOW to describe an engine */
   DB_TYPE_PARTITION_DB,
   0, /* Method that initializes a storage engine */
   0, /* slot */
@@ -5447,9 +5450,9 @@ mysql_declare_plugin(partition)
 {
   MYSQL_STORAGE_ENGINE_PLUGIN,
   &partition_hton,
-  partition_hton.name,
+  partition_hton_name,
   "Mikael Ronstrom, MySQL AB",
-  "Partitioning Support",
+  partition_hton_comment,
   NULL, /* Plugin Init */
   NULL, /* Plugin Deinit */
   0x0100 /* 1.0 */,
diff --git a/storage/archive/ha_archive.cc b/storage/archive/ha_archive.cc
index cd28deaea47..e39ee976eb1 100644
--- a/storage/archive/ha_archive.cc
+++ b/storage/archive/ha_archive.cc
@@ -146,12 +146,15 @@ static handler *archive_create_handler(TABLE_SHARE *table);
 #define ARCHIVE_MIN_ROWS_TO_USE_BULK_INSERT 2
 
 
+static const char archive_hton_name[]= "ARCHIVE";
+static const char archive_hton_comment[]= "Archive storage engine";
+
 /* dummy handlerton - only to have something to return from archive_db_init */
 handlerton archive_hton = {
   MYSQL_HANDLERTON_INTERFACE_VERSION,
-  "ARCHIVE",
+  archive_hton_name,
   SHOW_OPTION_YES,
-  "Archive storage engine", 
+  archive_hton_comment, 
   DB_TYPE_ARCHIVE_DB,
   archive_db_init,
   0,       /* slot */
@@ -1577,9 +1580,9 @@ mysql_declare_plugin(archive)
 {
   MYSQL_STORAGE_ENGINE_PLUGIN,
   &archive_hton,
-  archive_hton.name,
+  archive_hton_name,
   "Brian Aker, MySQL AB",
-  "Archive Storage Engine",
+  archive_hton_comment,
   NULL, /* Plugin Init */
   archive_db_done, /* Plugin Deinit */
   0x0100 /* 1.0 */,
diff --git a/storage/blackhole/ha_blackhole.cc b/storage/blackhole/ha_blackhole.cc
index 31d0b0c3917..e9fd1c2319d 100644
--- a/storage/blackhole/ha_blackhole.cc
+++ b/storage/blackhole/ha_blackhole.cc
@@ -29,13 +29,17 @@
 static handler *blackhole_create_handler(TABLE_SHARE *table);
 
 
+static const char blackhole_hton_name[]= "BLACKHOLE";
+static const char blackhole_hton_comment[]=
+  "/dev/null storage engine (anything you write to it disappears)";
+
 /* Blackhole storage engine handlerton */
 
 handlerton blackhole_hton= {
   MYSQL_HANDLERTON_INTERFACE_VERSION,
-  "BLACKHOLE",
+  blackhole_hton_name,
   SHOW_OPTION_YES,
-  "/dev/null storage engine (anything you write to it disappears)",
+  blackhole_hton_comment,
   DB_TYPE_BLACKHOLE_DB,
   NULL,
   0,       /* slot */
@@ -256,9 +260,9 @@ mysql_declare_plugin(blackhole)
 {
   MYSQL_STORAGE_ENGINE_PLUGIN,
   &blackhole_hton,
-  blackhole_hton.name,
+  blackhole_hton_name,
   "MySQL AB",
-  "Blackhole Storage Engine",
+  blackhole_hton_comment,
   NULL, /* Plugin Init */
   NULL, /* Plugin Deinit */
   0x0100 /* 1.0 */,
diff --git a/storage/csv/ha_tina.cc b/storage/csv/ha_tina.cc
index 8b1cfe71fa2..de69df90ed5 100644
--- a/storage/csv/ha_tina.cc
+++ b/storage/csv/ha_tina.cc
@@ -77,11 +77,14 @@ static int tina_init= 0;
 static handler *tina_create_handler(TABLE_SHARE *table);
 static int tina_init_func();
 
+static const char tina_hton_name[]= "CSV";
+static const char tina_hton_comment[]= "CSV storage engine";
+
 handlerton tina_hton= {
   MYSQL_HANDLERTON_INTERFACE_VERSION,
-  "CSV",
+  tina_hton_name,
   SHOW_OPTION_YES,
-  "CSV storage engine", 
+  tina_hton_comment, 
   DB_TYPE_CSV_DB,
   (bool (*)()) tina_init_func,
   0,       /* slot */
@@ -1403,9 +1406,9 @@ mysql_declare_plugin(csv)
 {
   MYSQL_STORAGE_ENGINE_PLUGIN,
   &tina_hton,
-  tina_hton.name,
+  tina_hton_name,
   "Brian Aker, MySQL AB",
-  "CSV Storage Engine",
+  tina_hton_comment,
   tina_init_func, /* Plugin Init */
   tina_done_func, /* Plugin Deinit */
   0x0100 /* 1.0 */,
diff --git a/storage/example/ha_example.cc b/storage/example/ha_example.cc
index c723dcf648e..2ce543dfbb0 100644
--- a/storage/example/ha_example.cc
+++ b/storage/example/ha_example.cc
@@ -77,11 +77,14 @@ static int example_init_func();
 static bool example_init_func_for_handlerton();
 static int example_panic(enum ha_panic_function flag);
 
+static const char example_hton_name[]= "EXAMPLE";
+static const char example_hton_comment[]= "Example storage engine";
+
 handlerton example_hton= {
   MYSQL_HANDLERTON_INTERFACE_VERSION,
-  "EXAMPLE",
+  example_hton_name,
   SHOW_OPTION_YES,
-  "Example storage engine", 
+  example_hton_comment, 
   DB_TYPE_EXAMPLE_DB,
   example_init_func_for_handlerton,
   0,       /* slot */
@@ -747,9 +750,9 @@ mysql_declare_plugin(example)
 {
   MYSQL_STORAGE_ENGINE_PLUGIN,
   &example_hton,
-  example_hton.name,
+  example_hton_name,
   "Brian Aker, MySQL AB",
-  "Example Storage Engine",
+  example_hton_comment,
   example_init_func, /* Plugin Init */
   example_done_func, /* Plugin Deinit */
   0x0001 /* 0.1 */,

From 19de86dd63e99a052bc1a692a25504260b8ffcac Mon Sep 17 00:00:00 2001
From: "gluh@eagle.intranet.mysql.r18.ru" <>
Date: Tue, 2 May 2006 16:31:39 +0500
Subject: [PATCH 094/108] WL#2257 REFERENTIAL_CONSTRAINTS view added
 I_S.REFARENTIAL_CONSTRAINTS table

---
 mysql-test/r/information_schema.result      |  6 +-
 mysql-test/r/information_schema_db.result   |  1 +
 mysql-test/r/information_schema_inno.result | 31 ++++++++
 mysql-test/t/information_schema_inno.test   | 32 ++++++++
 sql/ha_innodb.cc                            | 77 +++++++++++-------
 sql/sql_show.cc                             | 88 +++++++++++++++++++++
 sql/table.h                                 |  4 +-
 7 files changed, 208 insertions(+), 31 deletions(-)

diff --git a/mysql-test/r/information_schema.result b/mysql-test/r/information_schema.result
index 5e915b5742c..002e444acca 100644
--- a/mysql-test/r/information_schema.result
+++ b/mysql-test/r/information_schema.result
@@ -50,6 +50,7 @@ KEY_COLUMN_USAGE
 PARTITIONS
 PLUGINS
 PROCESSLIST
+REFERENTIAL_CONSTRAINTS
 ROUTINES
 SCHEMATA
 SCHEMA_PRIVILEGES
@@ -745,7 +746,7 @@ CREATE TABLE t_crashme ( f1 BIGINT);
 CREATE VIEW a1 (t_CRASHME) AS SELECT f1 FROM t_crashme GROUP BY f1;
 CREATE VIEW a2 AS SELECT t_CRASHME FROM a1;
 count(*)
-112
+113
 drop view a2, a1;
 drop table t_crashme;
 select table_schema,table_name, column_name from
@@ -832,6 +833,7 @@ COLUMN_PRIVILEGES	TABLE_NAME	select
 FILES	TABLE_NAME	select
 KEY_COLUMN_USAGE	TABLE_NAME	select
 PARTITIONS	TABLE_NAME	select
+REFERENTIAL_CONSTRAINTS	TABLE_NAME	select
 STATISTICS	TABLE_NAME	select
 TABLES	TABLE_NAME	select
 TABLE_CONSTRAINTS	TABLE_NAME	select
@@ -843,7 +845,7 @@ flush privileges;
 SELECT table_schema, count(*) FROM information_schema.TABLES GROUP BY TABLE_SCHEMA;
 table_schema	count(*)
 cluster	1
-information_schema	22
+information_schema	23
 mysql	21
 create table t1 (i int, j int);
 create trigger trg1 before insert on t1 for each row
diff --git a/mysql-test/r/information_schema_db.result b/mysql-test/r/information_schema_db.result
index 584e1701a14..37537e257da 100644
--- a/mysql-test/r/information_schema_db.result
+++ b/mysql-test/r/information_schema_db.result
@@ -13,6 +13,7 @@ KEY_COLUMN_USAGE
 PARTITIONS
 PLUGINS
 PROCESSLIST
+REFERENTIAL_CONSTRAINTS
 ROUTINES
 SCHEMATA
 SCHEMA_PRIVILEGES
diff --git a/mysql-test/r/information_schema_inno.result b/mysql-test/r/information_schema_inno.result
index fb6584673f6..9bb3185c6fb 100644
--- a/mysql-test/r/information_schema_inno.result
+++ b/mysql-test/r/information_schema_inno.result
@@ -25,3 +25,34 @@ NULL	test	PRIMARY	NULL	test	t3	id	1	NULL	NULL	NULL	NULL
 NULL	test	t3_ibfk_1	NULL	test	t3	id	1	1	test	t2	t1_id
 NULL	test	t3_ibfk_1	NULL	test	t3	t2_id	2	2	test	t2	id
 drop table t3, t2, t1;
+CREATE TABLE t1(a1 INT NOT NULL, a2 INT NOT NULL,
+PRIMARY KEY(a1, a2)) ENGINE=INNODB;
+CREATE TABLE t2(b1 INT, b2 INT, INDEX (b1, b2),
+CONSTRAINT A1
+FOREIGN KEY (b1, b2) REFERENCES t1(a1, a2)
+ON UPDATE CASCADE ON DELETE NO ACTION) ENGINE=INNODB;
+CREATE TABLE t3(b1 INT, b2 INT, INDEX (b1, b2),
+CONSTRAINT A2
+FOREIGN KEY (b1, b2) REFERENCES t2(b1, b2)
+ON UPDATE SET NULL ON DELETE RESTRICT) ENGINE=INNODB;
+CREATE TABLE t4(b1 INT, b2 INT, INDEX (b1, b2),
+CONSTRAINT A3
+FOREIGN KEY (b1, b2) REFERENCES t3(b1, b2)
+ON UPDATE NO ACTION ON DELETE SET NULL) ENGINE=INNODB;
+CREATE TABLE t5(b1 INT, b2 INT, INDEX (b1, b2),
+CONSTRAINT A4
+FOREIGN KEY (b1, b2) REFERENCES t4(b1, b2)
+ON UPDATE RESTRICT ON DELETE CASCADE) ENGINE=INNODB;
+select a.CONSTRAINT_SCHEMA, b.TABLE_NAME, CONSTRAINT_TYPE,
+b.CONSTRAINT_NAME, UNIQUE_CONSTRAINT_SCHEMA, UNIQUE_CONSTRAINT_NAME,
+MATCH_OPTION, UPDATE_RULE, DELETE_RULE
+from information_schema.TABLE_CONSTRAINTS a,
+information_schema.REFERENTIAL_CONSTRAINTS b
+where a.CONSTRAINT_SCHEMA = 'test' and a.CONSTRAINT_SCHEMA = b.CONSTRAINT_SCHEMA and
+a.CONSTRAINT_NAME = b.CONSTRAINT_NAME;
+CONSTRAINT_SCHEMA	TABLE_NAME	CONSTRAINT_TYPE	CONSTRAINT_NAME	UNIQUE_CONSTRAINT_SCHEMA	UNIQUE_CONSTRAINT_NAME	MATCH_OPTION	UPDATE_RULE	DELETE_RULE
+test	t2	FOREIGN KEY	A1	test	t1	NONE	CASCADE	NO ACTION
+test	t3	FOREIGN KEY	A2	test	t2	NONE	SET NULL	RESTRICT
+test	t4	FOREIGN KEY	A3	test	t3	NONE	NO ACTION	SET NULL
+test	t5	FOREIGN KEY	A4	test	t4	NONE	RESTRICT	CASCADE
+drop tables t5, t4, t3, t2, t1;
diff --git a/mysql-test/t/information_schema_inno.test b/mysql-test/t/information_schema_inno.test
index 9cd64a54ad9..195bf57a880 100644
--- a/mysql-test/t/information_schema_inno.test
+++ b/mysql-test/t/information_schema_inno.test
@@ -21,3 +21,35 @@ select * from information_schema.KEY_COLUMN_USAGE where
 TABLE_SCHEMA= "test";
 
 drop table t3, t2, t1;
+
+#
+# Test for REFERENTIAL_CONSTRAINTS table
+#
+CREATE TABLE t1(a1 INT NOT NULL, a2 INT NOT NULL,
+                PRIMARY KEY(a1, a2)) ENGINE=INNODB;
+CREATE TABLE t2(b1 INT, b2 INT, INDEX (b1, b2),
+                CONSTRAINT A1
+                FOREIGN KEY (b1, b2) REFERENCES t1(a1, a2)
+                ON UPDATE CASCADE ON DELETE NO ACTION) ENGINE=INNODB;
+CREATE TABLE t3(b1 INT, b2 INT, INDEX (b1, b2),
+		CONSTRAINT A2
+		FOREIGN KEY (b1, b2) REFERENCES t2(b1, b2)
+		ON UPDATE SET NULL ON DELETE RESTRICT) ENGINE=INNODB;
+CREATE TABLE t4(b1 INT, b2 INT, INDEX (b1, b2),
+                CONSTRAINT A3
+                FOREIGN KEY (b1, b2) REFERENCES t3(b1, b2)
+                ON UPDATE NO ACTION ON DELETE SET NULL) ENGINE=INNODB;
+CREATE TABLE t5(b1 INT, b2 INT, INDEX (b1, b2),
+                CONSTRAINT A4
+                FOREIGN KEY (b1, b2) REFERENCES t4(b1, b2)
+                ON UPDATE RESTRICT ON DELETE CASCADE) ENGINE=INNODB;
+		
+		
+select a.CONSTRAINT_SCHEMA, b.TABLE_NAME, CONSTRAINT_TYPE,
+       b.CONSTRAINT_NAME, UNIQUE_CONSTRAINT_SCHEMA, UNIQUE_CONSTRAINT_NAME,
+       MATCH_OPTION, UPDATE_RULE, DELETE_RULE
+from information_schema.TABLE_CONSTRAINTS a,
+     information_schema.REFERENTIAL_CONSTRAINTS b
+where a.CONSTRAINT_SCHEMA = 'test' and a.CONSTRAINT_SCHEMA = b.CONSTRAINT_SCHEMA and
+a.CONSTRAINT_NAME = b.CONSTRAINT_NAME;
+drop tables t5, t4, t3, t2, t1;
diff --git a/sql/ha_innodb.cc b/sql/ha_innodb.cc
index 42def845174..a02361a0eac 100644
--- a/sql/ha_innodb.cc
+++ b/sql/ha_innodb.cc
@@ -5827,34 +5827,55 @@ ha_innobase::get_foreign_key_list(THD *thd, List *f_key_list)
 			  break;
 	  }
 
-	  ulong length= 0;
-	  if (foreign->type == DICT_FOREIGN_ON_DELETE_CASCADE) {
-		  length=17;
-		  tmp_buff= "ON DELETE CASCADE";
-	  }
-	  else if (foreign->type == DICT_FOREIGN_ON_DELETE_SET_NULL) {
-		  length=18;
-		  tmp_buff= "ON DELETE SET NULL";
-	  }
-	  else if (foreign->type == DICT_FOREIGN_ON_DELETE_NO_ACTION) {
-		  length=19;
-		  tmp_buff= "ON DELETE NO ACTION";
-	  }
-	  else if (foreign->type == DICT_FOREIGN_ON_UPDATE_CASCADE) {
-		  length=17;
-		  tmp_buff= "ON UPDATE CASCADE";
-	  }
-	  else if (foreign->type == DICT_FOREIGN_ON_UPDATE_SET_NULL) {
-		  length=18;
-		  tmp_buff= "ON UPDATE SET NULL";
-	  }
-	  else if (foreign->type == DICT_FOREIGN_ON_UPDATE_NO_ACTION) {
-		  length=19;
-		  tmp_buff= "ON UPDATE NO ACTION";
-	  }
-	  f_key_info.constraint_method= make_lex_string(thd,
-		  f_key_info.constraint_method,
-		  tmp_buff, length, 1);
+          ulong length;
+          if (foreign->type & DICT_FOREIGN_ON_DELETE_CASCADE)
+          {
+            length=7;
+            tmp_buff= "CASCADE";
+          }	
+          else if (foreign->type & DICT_FOREIGN_ON_DELETE_SET_NULL)
+          {
+            length=8;
+            tmp_buff= "SET NULL";
+          }
+          else if (foreign->type & DICT_FOREIGN_ON_DELETE_NO_ACTION)
+          {
+            length=9;
+            tmp_buff= "NO ACTION";
+          }
+          else
+          {
+            length=8;
+            tmp_buff= "RESTRICT";
+          }
+          f_key_info.delete_method= make_lex_string(thd, f_key_info.delete_method,
+                                                    tmp_buff, length, 1);
+ 
+ 
+          if (foreign->type & DICT_FOREIGN_ON_UPDATE_CASCADE)
+          {
+            length=7;
+            tmp_buff= "CASCADE";
+          }
+          else if (foreign->type & DICT_FOREIGN_ON_UPDATE_SET_NULL)
+          {
+            length=8;
+            tmp_buff= "SET NULL";
+          }
+          else if (foreign->type & DICT_FOREIGN_ON_UPDATE_NO_ACTION)
+          {
+            length=9;
+            tmp_buff= "NO ACTION";
+          }
+          else
+          {
+            length=8;
+            tmp_buff= "RESTRICT";
+          }
+          f_key_info.update_method= make_lex_string(thd, f_key_info.update_method,
+                                                    tmp_buff, length, 1);
+
+
 
 	  FOREIGN_KEY_INFO *pf_key_info= ((FOREIGN_KEY_INFO *)
 		  thd->memdup((gptr) &f_key_info,
diff --git a/sql/sql_show.cc b/sql/sql_show.cc
index 95433828a1e..5e54040f0ae 100644
--- a/sql/sql_show.cc
+++ b/sql/sql_show.cc
@@ -4231,6 +4231,75 @@ int fill_status(THD *thd, TABLE_LIST *tables, COND *cond)
 }
 
 
+/*
+  Fill and store records into I_S.referential_constraints table
+
+  SYNOPSIS
+    get_referential_constraints_record()
+    thd                 thread handle
+    tables              table list struct(processed table)
+    table               I_S table
+    res                 1 means the error during opening of the processed table
+                        0 means processed table is opened without error
+    base_name           db name
+    file_name           table name
+
+  RETURN
+    0	ok
+    #   error
+*/
+
+static int
+get_referential_constraints_record(THD *thd, struct st_table_list *tables,
+                                   TABLE *table, bool res,
+                                   const char *base_name, const char *file_name)
+{
+  CHARSET_INFO *cs= system_charset_info;
+  DBUG_ENTER("get_referential_constraints_record");
+
+  if (res)
+  {
+    if (!tables->view)
+      push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
+                   thd->net.last_errno, thd->net.last_error);
+    thd->clear_error();
+    DBUG_RETURN(0);
+  }
+  if (!tables->view)
+  {
+    List f_key_list;
+    TABLE *show_table= tables->table;
+    show_table->file->info(HA_STATUS_VARIABLE | 
+                           HA_STATUS_NO_LOCK |
+                           HA_STATUS_TIME);
+
+    show_table->file->get_foreign_key_list(thd, &f_key_list);
+    FOREIGN_KEY_INFO *f_key_info;
+    List_iterator_fast it(f_key_list);
+    while ((f_key_info= it++))
+    {
+      restore_record(table, s->default_values);
+      table->field[1]->store(base_name, strlen(base_name), cs);
+      table->field[9]->store(file_name, strlen(file_name), cs);
+      table->field[2]->store(f_key_info->forein_id->str,
+                             f_key_info->forein_id->length, cs);
+      table->field[4]->store(f_key_info->referenced_db->str, 
+                             f_key_info->referenced_db->length, cs);
+      table->field[5]->store(f_key_info->referenced_table->str, 
+                             f_key_info->referenced_table->length, cs);
+      table->field[6]->store(STRING_WITH_LEN("NONE"), cs);
+      table->field[7]->store(f_key_info->update_method->str, 
+                             f_key_info->update_method->length, cs);
+      table->field[8]->store(f_key_info->delete_method->str, 
+                             f_key_info->delete_method->length, cs);
+      if (schema_table_store_record(thd, table))
+        DBUG_RETURN(1);
+    }
+  }
+  DBUG_RETURN(0);
+}
+
+
 /*
   Find schema_tables elment by name
 
@@ -5160,6 +5229,22 @@ ST_FIELD_INFO files_fields_info[]=
   {0, 0, MYSQL_TYPE_STRING, 0, 0, 0}
 };
 
+ST_FIELD_INFO referential_constraints_fields_info[]=
+{
+  {"CONSTRAINT_CATALOG", FN_REFLEN, MYSQL_TYPE_STRING, 0, 1, 0},
+  {"CONSTRAINT_SCHEMA", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 0},
+  {"CONSTRAINT_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 0},
+  {"UNIQUE_CONSTRAINT_CATALOG", FN_REFLEN, MYSQL_TYPE_STRING, 0, 1, 0},
+  {"UNIQUE_CONSTRAINT_SCHEMA", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 0},
+  {"UNIQUE_CONSTRAINT_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 0},
+  {"MATCH_OPTION", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 0},
+  {"UPDATE_RULE", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 0},
+  {"DELETE_RULE", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 0},
+  {"TABLE_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 0},
+  {0, 0, MYSQL_TYPE_STRING, 0, 0, 0}
+};
+
+
 /*
   Description of ST_FIELD_INFO in table.h
 
@@ -5195,6 +5280,9 @@ ST_SCHEMA_TABLE schema_tables[]=
     fill_plugins, make_old_format, 0, -1, -1, 0},
   {"PROCESSLIST", processlist_fields_info, create_schema_table,
     fill_schema_processlist, make_old_format, 0, -1, -1, 0},
+  {"REFERENTIAL_CONSTRAINTS", referential_constraints_fields_info,
+   create_schema_table, get_all_tables, 0, get_referential_constraints_record,
+   1, 9, 0},
   {"ROUTINES", proc_fields_info, create_schema_table, 
     fill_schema_proc, make_proc_old_format, 0, -1, -1, 0},
   {"SCHEMATA", schema_fields_info, create_schema_table,
diff --git a/sql/table.h b/sql/table.h
index aec9a7115e6..85d49444b29 100644
--- a/sql/table.h
+++ b/sql/table.h
@@ -335,7 +335,8 @@ typedef struct st_foreign_key_info
   LEX_STRING *forein_id;
   LEX_STRING *referenced_db;
   LEX_STRING *referenced_table;
-  LEX_STRING *constraint_method;
+  LEX_STRING *update_method;
+  LEX_STRING *delete_method;
   List foreign_fields;
   List referenced_fields;
 } FOREIGN_KEY_INFO;
@@ -359,6 +360,7 @@ enum enum_schema_tables
   SCH_PARTITIONS,
   SCH_PLUGINS,
   SCH_PROCESSLIST,
+  SCH_REFERENTIAL_CONSTRAINTS,
   SCH_PROCEDURES,
   SCH_SCHEMATA,
   SCH_SCHEMA_PRIVILEGES,

From c0b5b3cd4031e4ce1aab1bda3e3def2a61f8a583 Mon Sep 17 00:00:00 2001
From: "elliot@mysql.com" <>
Date: Tue, 2 May 2006 09:13:58 -0400
Subject: [PATCH 095/108] Fix spelling in comments as requested by Osku This
 will make charset code easier to understand

---
 include/m_ctype.h             | 6 +++---
 mysql-test/t/cast.test        | 2 +-
 mysql-test/t/query_cache.test | 2 +-
 sql/sql_string.cc             | 2 +-
 strings/CHARSET_INFO.txt      | 4 ++--
 5 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/include/m_ctype.h b/include/m_ctype.h
index 913272b2a11..40cadad0017 100644
--- a/include/m_ctype.h
+++ b/include/m_ctype.h
@@ -176,7 +176,7 @@ typedef struct my_charset_handler_st
   uint    (*lengthsp)(struct charset_info_st *, const char *ptr, uint length);
   uint    (*numcells)(struct charset_info_st *, const char *b, const char *e);
   
-  /* Unicode convertion */
+  /* Unicode conversion */
   int (*mb_wc)(struct charset_info_st *cs,my_wc_t *wc,
 	       const unsigned char *s,const unsigned char *e);
   int (*wc_mb)(struct charset_info_st *cs,my_wc_t wc,
@@ -186,7 +186,7 @@ typedef struct my_charset_handler_st
   int (*ctype)(struct charset_info_st *cs, int *ctype,
                const unsigned char *s, const unsigned char *e);
   
-  /* Functions for case and sort convertion */
+  /* Functions for case and sort conversion */
   void    (*caseup_str)(struct charset_info_st *, char *);
   void    (*casedn_str)(struct charset_info_st *, char *);
   uint    (*caseup)(struct charset_info_st *, char *src, uint srclen,
@@ -204,7 +204,7 @@ typedef struct my_charset_handler_st
   
   void (*fill)(struct charset_info_st *, char *to, uint len, int fill);
   
-  /* String-to-number convertion routines */
+  /* String-to-number conversion routines */
   long        (*strntol)(struct charset_info_st *, const char *s, uint l,
 			 int base, char **e, int *err);
   ulong      (*strntoul)(struct charset_info_st *, const char *s, uint l,
diff --git a/mysql-test/t/cast.test b/mysql-test/t/cast.test
index 533da542855..b733a23f398 100644
--- a/mysql-test/t/cast.test
+++ b/mysql-test/t/cast.test
@@ -47,7 +47,7 @@ select cast('1a' as signed);
 select cast('' as signed);
 
 #
-# Character set convertion
+# Character set conversion
 #
 set names binary;
 select cast(_latin1'test' as char character set latin2);
diff --git a/mysql-test/t/query_cache.test b/mysql-test/t/query_cache.test
index 7596a7ba708..e2ff20e6ecc 100644
--- a/mysql-test/t/query_cache.test
+++ b/mysql-test/t/query_cache.test
@@ -207,7 +207,7 @@ show status like "Qcache_queries_in_cache";
 drop table t1;
 
 #
-# Charset convertion (cp1251_koi8 always present)
+# Charset conversion (cp1251_koi8 always present)
 #
 create table t1 (a char(1) not null collate koi8r_general_ci);
 insert into t1 values(_koi8r"á");
diff --git a/sql/sql_string.cc b/sql/sql_string.cc
index 79228be8a76..19ee9f259dc 100644
--- a/sql/sql_string.cc
+++ b/sql/sql_string.cc
@@ -331,7 +331,7 @@ bool String::set_or_copy_aligned(const char *str,uint32 arg_length,
   return copy_aligned(str, arg_length, offset, cs);
 }
 
-	/* Copy with charset convertion */
+	/* Copy with charset conversion */
 
 bool String::copy(const char *str, uint32 arg_length,
 		  CHARSET_INFO *from_cs, CHARSET_INFO *to_cs, uint *errors)
diff --git a/strings/CHARSET_INFO.txt b/strings/CHARSET_INFO.txt
index f7a10f95880..40f171440a4 100644
--- a/strings/CHARSET_INFO.txt
+++ b/strings/CHARSET_INFO.txt
@@ -172,7 +172,7 @@ mb_wc       - converts the left multibyte sequence into it Unicode code.
 mc_mb       - converts the given Unicode code into multibyte sequence.
 
 
-Case and sort convertion
+Case and sort conversion
 ------------------------
 caseup_str  - converts the given 0-terminated string into the upper case
 casedn_str  - converts the given 0-terminated string into the lower case
@@ -227,4 +227,4 @@ hash_sort()   - calculates hash value taking in account
                 the collation rules, e.g. case-insensitivity, 
                 accent sensitivity, etc.
 
- 
\ No newline at end of file
+ 

From 0f63c3d39c51d2749bd13c54e68bd48cc04fa300 Mon Sep 17 00:00:00 2001
From: "cmiller@zippy.(none)" <>
Date: Tue, 2 May 2006 13:42:35 -0400
Subject: [PATCH 096/108] An update to as-yet unused new feature of snprintf,
 which was added to bring our sprintf()-alike in sync with our fprintf()-alike
 features.

---
 strings/my_vsnprintf.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/strings/my_vsnprintf.c b/strings/my_vsnprintf.c
index d917e9e11b2..e4302f50c58 100644
--- a/strings/my_vsnprintf.c
+++ b/strings/my_vsnprintf.c
@@ -99,7 +99,11 @@ int my_vsnprintf(char *to, size_t n, const char* fmt, va_list ap)
     else if (*fmt == 'b')				/* Buffer parameter */
     {
       char *par = va_arg(ap, char *);
-      to=memmove(to, par, abs(width));
+      DBUG_ASSERT(to <= end);
+      if (to + abs(width) + 1 > end)
+        width= end - to - 1;  /* sign doesn't matter */
+      memmove(to, par, abs(width));
+      to+= width;
       continue;
     }
     else if (*fmt == 'd' || *fmt == 'u'|| *fmt== 'x')	/* Integer parameter */

From 230b52a83518d2cd678993d7d7a5a08131d8ee7e Mon Sep 17 00:00:00 2001
From: "cmiller@zippy.(none)" <>
Date: Tue, 2 May 2006 13:56:43 -0400
Subject: [PATCH 097/108] Manually merged

---
 sql/sql_parse.cc          | 506 ++++++++++++++++++++++++++------------
 tests/mysql_client_test.c |  38 ++-
 2 files changed, 379 insertions(+), 165 deletions(-)

diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index 196e723299a..b1b498b356d 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -17,22 +17,16 @@
 #define MYSQL_LEX 1
 #include "mysql_priv.h"
 #include "sql_repl.h"
+#include "rpl_filter.h"
 #include "repl_failsafe.h"
 #include 
 #include 
 #include 
 
-#ifdef HAVE_INNOBASE_DB
-#include "ha_innodb.h"
-#endif
-
-#ifdef HAVE_NDBCLUSTER_DB
-#include "ha_ndbcluster.h"
-#endif
-
 #include "sp_head.h"
 #include "sp.h"
 #include "sp_cache.h"
+#include "event.h"
 
 #ifdef HAVE_OPENSSL
 /*
@@ -74,19 +68,41 @@ static void decrease_user_connections(USER_CONN *uc);
 static bool check_db_used(THD *thd,TABLE_LIST *tables);
 static bool check_multi_update_lock(THD *thd);
 static void remove_escape(char *name);
-static bool append_file_to_dir(THD *thd, const char **filename_ptr,
-			       const char *table_name);
 
 const char *any_db="*any*";	// Special symbol for check_access
 
-const char *command_name[]={
-  "Sleep", "Quit", "Init DB", "Query", "Field List", "Create DB",
-  "Drop DB", "Refresh", "Shutdown", "Statistics", "Processlist",
-  "Connect","Kill","Debug","Ping","Time","Delayed insert","Change user",
-  "Binlog Dump","Table Dump",  "Connect Out", "Register Slave",
-  "Prepare", "Execute", "Long Data", "Close stmt",
-  "Reset stmt", "Set option", "Fetch",
-  "Error"					// Last command number
+LEX_STRING command_name[]={
+  (char *)STRING_WITH_LEN("Sleep"),
+  (char *)STRING_WITH_LEN("Quit"),
+  (char *)STRING_WITH_LEN("Init DB"),
+  (char *)STRING_WITH_LEN("Query"),
+  (char *)STRING_WITH_LEN("Field List"),
+  (char *)STRING_WITH_LEN("Create DB"),
+  (char *)STRING_WITH_LEN("Drop DB"),
+  (char *)STRING_WITH_LEN("Refresh"),
+  (char *)STRING_WITH_LEN("Shutdown"),
+  (char *)STRING_WITH_LEN("Statistics"),
+  (char *)STRING_WITH_LEN("Processlist"),
+  (char *)STRING_WITH_LEN("Connect"),
+  (char *)STRING_WITH_LEN("Kill"),
+  (char *)STRING_WITH_LEN("Debug"),
+  (char *)STRING_WITH_LEN("Ping"),
+  (char *)STRING_WITH_LEN("Time"),
+  (char *)STRING_WITH_LEN("Delayed insert"),
+  (char *)STRING_WITH_LEN("Change user"),
+  (char *)STRING_WITH_LEN("Binlog Dump"),
+  (char *)STRING_WITH_LEN("Table Dump"),
+  (char *)STRING_WITH_LEN("Connect Out"),
+  (char *)STRING_WITH_LEN("Register Slave"),
+  (char *)STRING_WITH_LEN("Prepare"),
+  (char *)STRING_WITH_LEN("Execute"),
+  (char *)STRING_WITH_LEN("Long Data"),
+  (char *)STRING_WITH_LEN("Close stmt"),
+  (char *)STRING_WITH_LEN("Reset stmt"),
+  (char *)STRING_WITH_LEN("Set option"),
+  (char *)STRING_WITH_LEN("Fetch"),
+  (char *)STRING_WITH_LEN("Daemon"),
+  (char *)STRING_WITH_LEN("Error")  // Last command number
 };
 
 const char *xa_state_names[]={
@@ -101,10 +117,6 @@ static void  test_signal(int sig_ptr)
 #if !defined( DBUG_OFF)
   MessageBox(NULL,"Test signal","DBUG",MB_OK);
 #endif
-#if defined(OS2)
-  fprintf(stderr, "Test signal %d\n", sig_ptr);
-  fflush(stderr);
-#endif
 }
 static void init_signals(void)
 {
@@ -155,7 +167,7 @@ static bool end_active_trans(THD *thd)
   DBUG_RETURN(error);
 }
 
-static bool begin_trans(THD *thd)
+bool begin_trans(THD *thd)
 {
   int error=0;
   if (unlikely(thd->in_sub_stmt))
@@ -189,7 +201,8 @@ static bool begin_trans(THD *thd)
 */
 inline bool all_tables_not_ok(THD *thd, TABLE_LIST *tables)
 {
-  return table_rules_on && tables && !tables_ok(thd,tables);
+  return rpl_filter->is_on() && tables && !thd->spcont &&
+         !rpl_filter->tables_ok(thd->db, tables);
 }
 #endif
 
@@ -327,7 +340,7 @@ int check_user(THD *thd, enum enum_server_command command,
   if (opt_secure_auth_local && passwd_len == SCRAMBLE_LENGTH_323)
   {
     net_printf_error(thd, ER_NOT_SUPPORTED_AUTH_MODE);
-    mysql_log.write(thd, COM_CONNECT, ER(ER_NOT_SUPPORTED_AUTH_MODE));
+    general_log_print(thd, COM_CONNECT, ER(ER_NOT_SUPPORTED_AUTH_MODE));
     DBUG_RETURN(-1);
   }
   if (passwd_len != 0 &&
@@ -361,9 +374,9 @@ int check_user(THD *thd, enum enum_server_command command,
       net_printf_error(thd, ER_SERVER_IS_IN_SECURE_AUTH_MODE,
                        thd->main_security_ctx.user,
                        thd->main_security_ctx.host_or_ip);
-      mysql_log.write(thd, COM_CONNECT, ER(ER_SERVER_IS_IN_SECURE_AUTH_MODE),
-                      thd->main_security_ctx.user,
-                      thd->main_security_ctx.host_or_ip);
+      general_log_print(thd, COM_CONNECT, ER(ER_SERVER_IS_IN_SECURE_AUTH_MODE),
+                        thd->main_security_ctx.user,
+                        thd->main_security_ctx.host_or_ip);
       DBUG_RETURN(-1);
     }
     /* We have to read very specific packet size */
@@ -411,14 +424,14 @@ int check_user(THD *thd, enum enum_server_command command,
       }
 
       /* Why logging is performed before all checks've passed? */
-      mysql_log.write(thd, command,
-                      (thd->main_security_ctx.priv_user ==
-                       thd->main_security_ctx.user ?
-                       (char*) "%s@%s on %s" :
-                       (char*) "%s@%s as anonymous on %s"),
-                      thd->main_security_ctx.user,
-                      thd->main_security_ctx.host_or_ip,
-                      db ? db : (char*) "");
+      general_log_print(thd, command,
+                        (thd->main_security_ctx.priv_user ==
+                         thd->main_security_ctx.user ?
+                         (char*) "%s@%s on %s" :
+                         (char*) "%s@%s as anonymous on %s"),
+                        thd->main_security_ctx.user,
+                        thd->main_security_ctx.host_or_ip,
+                        db ? db : (char*) "");
 
       /*
         This is the default access rights for the current database.  It's
@@ -465,17 +478,17 @@ int check_user(THD *thd, enum enum_server_command command,
   else if (res == 2) // client gave short hash, server has long hash
   {
     net_printf_error(thd, ER_NOT_SUPPORTED_AUTH_MODE);
-    mysql_log.write(thd,COM_CONNECT,ER(ER_NOT_SUPPORTED_AUTH_MODE));
+    general_log_print(thd, COM_CONNECT, ER(ER_NOT_SUPPORTED_AUTH_MODE));
     DBUG_RETURN(-1);
   }
   net_printf_error(thd, ER_ACCESS_DENIED_ERROR,
                    thd->main_security_ctx.user,
                    thd->main_security_ctx.host_or_ip,
                    passwd_len ? ER(ER_YES) : ER(ER_NO));
-  mysql_log.write(thd, COM_CONNECT, ER(ER_ACCESS_DENIED_ERROR),
-                  thd->main_security_ctx.user,
-                  thd->main_security_ctx.host_or_ip,
-                  passwd_len ? ER(ER_YES) : ER(ER_NO));
+  general_log_print(thd, COM_CONNECT, ER(ER_ACCESS_DENIED_ERROR),
+                    thd->main_security_ctx.user,
+                    thd->main_security_ctx.host_or_ip,
+                    passwd_len ? ER(ER_YES) : ER(ER_NO));
   DBUG_RETURN(-1);
 #endif /* NO_EMBEDDED_ACCESS_CHECKS */
 }
@@ -648,6 +661,9 @@ void init_update_queries(void)
   uc_update_queries[SQLCOM_DROP_INDEX]=1;
   uc_update_queries[SQLCOM_CREATE_VIEW]=1;
   uc_update_queries[SQLCOM_DROP_VIEW]=1;
+  uc_update_queries[SQLCOM_CREATE_EVENT]=1;
+  uc_update_queries[SQLCOM_ALTER_EVENT]=1;
+  uc_update_queries[SQLCOM_DROP_EVENT]=1;  
 }
 
 bool is_update_query(enum enum_sql_command command)
@@ -1087,7 +1103,7 @@ pthread_handler_t handle_one_connection(void *arg)
 
   pthread_detach_this_thread();
 
-#if !defined( __WIN__) && !defined(OS2)	// Win32 calls this in pthread_create
+#if !defined( __WIN__) // Win32 calls this in pthread_create
   /* The following calls needs to be done before we call DBUG_ macros */
   if (!(test_flags & TEST_NO_THREADS) & my_thread_init())
   {
@@ -1111,7 +1127,7 @@ pthread_handler_t handle_one_connection(void *arg)
 
 #if defined(__WIN__)
   init_signals();
-#elif !defined(OS2) && !defined(__NETWARE__)
+#elif !defined(__NETWARE__)
   sigset_t set;
   VOID(sigemptyset(&set));			// Get mask in use
   VOID(pthread_sigmask(SIG_UNBLOCK,&set,&thd->block_signals));
@@ -1235,7 +1251,7 @@ pthread_handler_t handle_bootstrap(void *arg)
 #ifndef EMBEDDED_LIBRARY
   pthread_detach_this_thread();
   thd->thread_stack= (char*) &thd;
-#if !defined(__WIN__) && !defined(OS2) && !defined(__NETWARE__)
+#if !defined(__WIN__) && !defined(__NETWARE__)
   sigset_t set;
   VOID(sigemptyset(&set));			// Get mask in use
   VOID(pthread_sigmask(SIG_UNBLOCK,&set,&thd->block_signals));
@@ -1249,6 +1265,7 @@ pthread_handler_t handle_bootstrap(void *arg)
   thd->version=refresh_version;
   thd->security_ctx->priv_user=
     thd->security_ctx->user= (char*) my_strdup("boot", MYF(MY_WME));
+  thd->security_ctx->priv_host[0]=0;
 
   buff= (char*) thd->net.buff;
   thd->init_for_queries();
@@ -1588,7 +1605,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
 			packet, strlen(packet), thd->charset());
     if (!mysql_change_db(thd, tmp.str, FALSE))
     {
-      mysql_log.write(thd,command,"%s",thd->db);
+      general_log_print(thd, command, "%s",thd->db);
       send_ok(thd);
     }
     break;
@@ -1736,7 +1753,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
     if (alloc_query(thd, packet, packet_length))
       break;					// fatal error is set
     char *packet_end= thd->query + thd->query_length;
-    mysql_log.write(thd,command, "%.*b", thd->query_length, thd->query);
+    general_log_print(thd, command, "%.*b", thd->query_length, thd->query);
     DBUG_PRINT("query",("%-.4096s",thd->query));
 
     if (!(specialflag & SPECIAL_NO_PRIOR))
@@ -1792,8 +1809,9 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
     TABLE_LIST table_list;
     LEX_STRING conv_name;
     /* Saved variable value */
-    my_bool old_innodb_table_locks= 
-              IF_INNOBASE_DB(thd->variables.innodb_table_locks, FALSE);
+    my_bool old_innodb_table_locks=  thd->variables.innodb_table_locks;
+
+
     /* used as fields initializator */
     lex_start(thd, 0, 0);
 
@@ -1823,7 +1841,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
     thd->query_length= strlen(packet);       // for simplicity: don't optimize
     if (!(thd->query=fields=thd->memdup(packet,thd->query_length+1)))
       break;
-    mysql_log.write(thd,command,"%s %s",table_list.table_name, fields);
+    general_log_print(thd, command, "%s %s", table_list.table_name, fields);
     if (lower_case_table_names)
       my_casedn_str(files_charset_info, table_list.table_name);
     remove_escape(table_list.table_name);	// This can't have wildcards
@@ -1852,7 +1870,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
 #endif
   case COM_QUIT:
     /* We don't calculate statistics for this command */
-    mysql_log.write(thd,command,NullS);
+    general_log_print(thd, command, NullS);
     net->error=0;				// Don't give 'abort' message
     error=TRUE;					// End server
     break;
@@ -1872,7 +1890,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
       }
       if (check_access(thd,CREATE_ACL,db,0,1,0,is_schema_db(db)))
 	break;
-      mysql_log.write(thd,command,packet);
+      general_log_print(thd, command, packet);
       bzero(&create_info, sizeof(create_info));
       mysql_create_db(thd, (lower_case_table_names == 2 ? alias : db),
                       &create_info, 0);
@@ -1897,7 +1915,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
                    ER(ER_LOCK_OR_ACTIVE_TRANSACTION), MYF(0));
 	break;
       }
-      mysql_log.write(thd,command,db);
+      general_log_print(thd, command, db);
       mysql_rm_db(thd, db, 0, 0);
       break;
     }
@@ -1921,7 +1939,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
 	kill_zombie_dump_threads(slave_server_id);
       thd->server_id = slave_server_id;
 
-      mysql_log.write(thd, command, "Log: '%s'  Pos: %ld", packet+10,
+      general_log_print(thd, command, "Log: '%s'  Pos: %ld", packet+10,
                       (long) pos);
       mysql_binlog_send(thd, thd->strdup(packet + 10), (my_off_t) pos, flags);
       unregister_slave(thd,1,1);
@@ -1939,7 +1957,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
     ulong options= (ulong) (uchar) packet[0];
     if (check_global_access(thd,RELOAD_ACL))
       break;
-    mysql_log.write(thd,command,NullS);
+    general_log_print(thd, command, NullS);
     if (!reload_acl_and_cache(thd, options, (TABLE_LIST*) 0, ¬_used))
       send_ok(thd);
     break;
@@ -1967,14 +1985,12 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
       break;
     }
     DBUG_PRINT("quit",("Got shutdown command for level %u", level));
-    mysql_log.write(thd,command,NullS);
+    general_log_print(thd, command, NullS);
     send_eof(thd);
 #ifdef __WIN__
     sleep(1);					// must wait after eof()
 #endif
-#ifndef OS2
     send_eof(thd);				// This is for 'quit request'
-#endif
     close_connection(thd, 0, 1);
     close_thread_tables(thd);			// Free before kill
     kill_mysql();
@@ -1984,7 +2000,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
 #endif
   case COM_STATISTICS:
   {
-    mysql_log.write(thd,command,NullS);
+    general_log_print(thd, command, NullS);
     statistic_increment(thd->status_var.com_stat[SQLCOM_SHOW_STATUS],
 			&LOCK_status);
 #ifndef EMBEDDED_LIBRARY
@@ -1998,7 +2014,8 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
 	    uptime,
 	    (int) thread_count, (ulong) thd->query_id,
             (ulong) thd->status_var.long_query_count,
-	    thd->status_var.opened_tables, refresh_version, cached_tables(),
+	    thd->status_var.opened_tables, refresh_version,
+            cached_open_tables(),
 	    (uptime ? (ulonglong2double(thd->query_id) / (double) uptime) :
 	     (double) 0));
 #ifdef SAFEMALLOC
@@ -2023,7 +2040,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
     if (!thd->security_ctx->priv_user[0] &&
         check_global_access(thd, PROCESS_ACL))
       break;
-    mysql_log.write(thd,command,NullS);
+    general_log_print(thd, command, NullS);
     mysqld_list_processes(thd,
 			  thd->security_ctx->master_access & PROCESS_ACL ? 
 			  NullS : thd->security_ctx->priv_user, 0);
@@ -2060,7 +2077,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
     if (check_global_access(thd, SUPER_ACL))
       break;					/* purecov: inspected */
     mysql_print_status();
-    mysql_log.write(thd,command,NullS);
+    general_log_print(thd, command, NullS);
     send_eof(thd);
     break;
   case COM_SLEEP:
@@ -2115,6 +2132,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
 void log_slow_statement(THD *thd)
 {
   time_t start_of_query;
+  DBUG_ENTER("log_slow_statement");
 
   /*
     The following should never be true with our current code base,
@@ -2122,7 +2140,7 @@ void log_slow_statement(THD *thd)
     statement in a trigger or stored function
   */
   if (unlikely(thd->in_sub_stmt))
-    return;                                     // Don't set time for sub stmt
+    DBUG_VOID_RETURN;                           // Don't set time for sub stmt
 
   start_of_query= thd->start_time;
   thd->end_time();				// Set start time
@@ -2142,9 +2160,10 @@ void log_slow_statement(THD *thd)
 	 (specialflag & SPECIAL_LOG_QUERIES_NOT_USING_INDEXES)))
     {
       thd->status_var.long_query_count++;
-      mysql_slow_log.write(thd, thd->query, thd->query_length, start_of_query);
+      slow_log_print(thd, thd->query, thd->query_length, start_of_query);
     }
   }
+  DBUG_VOID_RETURN;
 }
 
 
@@ -2169,6 +2188,7 @@ int prepare_schema_table(THD *thd, LEX *lex, Table_ident *table_ident,
   case SCH_TABLES:
   case SCH_VIEWS:
   case SCH_TRIGGERS:
+  case SCH_EVENTS:
 #ifdef DONT_ALLOW_SHOW_COMMANDS
     my_message(ER_NOT_ALLOWED_COMMAND,
                ER(ER_NOT_ALLOWED_COMMAND), MYF(0)); /* purecov: inspected */
@@ -2243,6 +2263,7 @@ int prepare_schema_table(THD *thd, LEX *lex, Table_ident *table_ident,
   case SCH_STATUS:
   case SCH_PROCEDURES:
   case SCH_CHARSETS:
+  case SCH_ENGINES:
   case SCH_COLLATIONS:
   case SCH_COLLATION_CHARACTER_SET_APPLICABILITY:
   case SCH_USER_PRIVILEGES:
@@ -2355,6 +2376,9 @@ mysql_execute_command(THD *thd)
   /* Saved variable value */
   DBUG_ENTER("mysql_execute_command");
   thd->net.no_send_error= 0;
+#ifdef WITH_PARTITION_STORAGE_ENGINE
+  thd->work_part_info= 0;
+#endif
 
   /*
     In many cases first table of main SELECT_LEX have special meaning =>
@@ -2444,6 +2468,9 @@ mysql_execute_command(THD *thd)
     statistic_increment(thd->status_var.com_stat[lex->sql_command],
                         &LOCK_status);
 
+  if (lex->binlog_row_based_if_mixed)
+    thd->set_current_stmt_binlog_row_based_if_mixed();
+
   switch (lex->sql_command) {
   case SQLCOM_SELECT:
   {
@@ -2459,11 +2486,15 @@ mysql_execute_command(THD *thd)
     if (all_tables)
     {
       if (lex->orig_sql_command != SQLCOM_SHOW_STATUS_PROC &&
-          lex->orig_sql_command != SQLCOM_SHOW_STATUS_FUNC)
+          lex->orig_sql_command != SQLCOM_SHOW_STATUS_FUNC &&
+          lex->orig_sql_command != SQLCOM_SHOW_EVENTS)
         res= check_table_access(thd,
                                 lex->exchange ? SELECT_ACL | FILE_ACL :
                                 SELECT_ACL,
                                 all_tables, 0);
+      else if (lex->orig_sql_command == SQLCOM_SHOW_EVENTS)
+        res= check_access(thd, EVENT_ACL, thd->lex->select_lex.db, 0, 0, 0,
+                       is_schema_db(thd->lex->select_lex.db));
     }
     else
       res= check_access(thd,
@@ -2708,29 +2739,20 @@ mysql_execute_command(THD *thd)
       res = load_master_data(thd);
     break;
 #endif /* HAVE_REPLICATION */
-#ifdef HAVE_NDBCLUSTER_DB
-  case SQLCOM_SHOW_NDBCLUSTER_STATUS:
-    {
-      res = ndbcluster_show_status(thd);
-      break;
-    }
-#endif
-#ifdef HAVE_INNOBASE_DB
-  case SQLCOM_SHOW_INNODB_STATUS:
-    {
-      if (check_global_access(thd, SUPER_ACL))
-	goto error;
-      res = innodb_show_status(thd);
-      break;
-    }
-  case SQLCOM_SHOW_MUTEX_STATUS:
+  case SQLCOM_SHOW_ENGINE_STATUS:
     {
       if (check_global_access(thd, SUPER_ACL))
         goto error;
-      res = innodb_mutex_show_status(thd);
+      res = ha_show_status(thd, lex->create_info.db_type, HA_ENGINE_STATUS);
+      break;
+    }
+  case SQLCOM_SHOW_ENGINE_MUTEX:
+    {
+      if (check_global_access(thd, SUPER_ACL))
+        goto error;
+      res = ha_show_status(thd, lex->create_info.db_type, HA_ENGINE_MUTEX);
       break;
     }
-#endif
 #ifdef HAVE_REPLICATION
   case SQLCOM_LOAD_MASTER_TABLE:
   {
@@ -2897,11 +2919,20 @@ mysql_execute_command(THD *thd)
     else
     {
       /* regular create */
-      if (lex->name)
+      if (lex->like_name)
         res= mysql_create_like_table(thd, create_table, &lex->create_info, 
-                                     (Table_ident *)lex->name); 
+                                     lex->like_name); 
       else
       {
+#ifdef WITH_PARTITION_STORAGE_ENGINE
+        partition_info *part_info= thd->lex->part_info;
+        if (part_info && !(part_info= thd->lex->part_info->get_clone()))
+        {
+          res= -1;
+          goto end_with_restore_list;
+        }
+        thd->work_part_info= part_info;
+#endif
         res= mysql_create_table(thd, create_table->db,
 				create_table->table_name, &lex->create_info,
 				lex->create_list,
@@ -2979,6 +3010,11 @@ end_with_restore_list:
 #else
     {
       ulong priv=0;
+      ulong priv_needed= ALTER_ACL;
+      /* We also require DROP priv for ALTER TABLE ... DROP PARTITION */
+      if (lex->alter_info.flags & ALTER_DROP_PARTITION)
+        priv_needed|= DROP_ACL;
+
       if (lex->name && (!lex->name[0] || strlen(lex->name) > NAME_LEN))
       {
 	my_error(ER_WRONG_TABLE_NAME, MYF(0), lex->name);
@@ -3003,7 +3039,7 @@ end_with_restore_list:
         else
           select_lex->db= first_table->db;
       }
-      if (check_access(thd, ALTER_ACL, first_table->db,
+      if (check_access(thd, priv_needed, first_table->db,
 		       &first_table->grant.privilege, 0, 0,
                        test(first_table->schema_table)) ||
 	  check_access(thd,INSERT_ACL | CREATE_ACL,select_lex->db,&priv,0,0,
@@ -3014,7 +3050,7 @@ end_with_restore_list:
 	goto error;				/* purecov: inspected */
       if (grant_option)
       {
-	if (check_grant(thd, ALTER_ACL, all_tables, 0, UINT_MAX, 0))
+	if (check_grant(thd, priv_needed, all_tables, 0, UINT_MAX, 0))
 	  goto error;
 	if (lex->name && !test_all_bits(priv,INSERT_ACL | CREATE_ACL))
 	{					// Rename of table
@@ -3079,7 +3115,7 @@ end_with_restore_list:
       }
     }
     query_cache_invalidate3(thd, first_table, 0);
-    if (end_active_trans(thd) || mysql_rename_tables(thd, first_table))
+    if (end_active_trans(thd) || mysql_rename_tables(thd, first_table, 0))
       goto error;
     break;
   }
@@ -3144,8 +3180,8 @@ end_with_restore_list:
       if (mysql_bin_log.is_open())
       {
 	thd->clear_error(); // No binlog error generated
-        Query_log_event qinfo(thd, thd->query, thd->query_length, 0, FALSE);
-        mysql_bin_log.write(&qinfo);
+        thd->binlog_query(THD::STMT_QUERY_TYPE,
+                          thd->query, thd->query_length, 0, FALSE);
       }
     }
     select_lex->table_list.first= (byte*) first_table;
@@ -3178,8 +3214,8 @@ end_with_restore_list:
       if (mysql_bin_log.is_open())
       {
 	thd->clear_error(); // No binlog error generated
-        Query_log_event qinfo(thd, thd->query, thd->query_length, 0, FALSE);
-        mysql_bin_log.write(&qinfo);
+        thd->binlog_query(THD::STMT_QUERY_TYPE,
+                          thd->query, thd->query_length, 0, FALSE);
       }
     }
     select_lex->table_list.first= (byte*) first_table;
@@ -3203,8 +3239,8 @@ end_with_restore_list:
       if (mysql_bin_log.is_open())
       {
 	thd->clear_error(); // No binlog error generated
-        Query_log_event qinfo(thd, thd->query, thd->query_length, 0, FALSE);
-        mysql_bin_log.write(&qinfo);
+        thd->binlog_query(THD::STMT_QUERY_TYPE,
+                          thd->query, thd->query_length, 0, FALSE);
       }
     }
     select_lex->table_list.first= (byte*) first_table;
@@ -3492,13 +3528,16 @@ end_with_restore_list:
   case SQLCOM_SHOW_STORAGE_ENGINES:
     res= mysqld_show_storage_engines(thd);
     break;
+  case SQLCOM_SHOW_AUTHORS:
+    res= mysqld_show_authors(thd);
+    break;
   case SQLCOM_SHOW_PRIVILEGES:
     res= mysqld_show_privileges(thd);
     break;
   case SQLCOM_SHOW_COLUMN_TYPES:
     res= mysqld_show_column_types(thd);
     break;
-  case SQLCOM_SHOW_LOGS:
+  case SQLCOM_SHOW_ENGINE_LOGS:
 #ifdef DONT_ALLOW_SHOW_COMMANDS
     my_message(ER_NOT_ALLOWED_COMMAND, ER(ER_NOT_ALLOWED_COMMAND),
                MYF(0));	/* purecov: inspected */
@@ -3507,7 +3546,7 @@ end_with_restore_list:
     {
       if (grant_option && check_access(thd, FILE_ACL, any_db,0,0,0,0))
 	goto error;
-      res= mysqld_show_logs(thd);
+      res= ha_show_status(thd, lex->create_info.db_type, HA_ENGINE_LOGS);
       break;
     }
 #endif
@@ -3626,9 +3665,9 @@ end_with_restore_list:
       above was not called. So we have to check rules again here.
     */
 #ifdef HAVE_REPLICATION
-    if (thd->slave_thread &&
-	(!db_ok(lex->name, replicate_do_db, replicate_ignore_db) ||
-	 !db_ok_with_wild_table(lex->name)))
+    if (thd->slave_thread && 
+	(!rpl_filter->db_ok(lex->name) ||
+	 !rpl_filter->db_ok_with_wild_table(lex->name)))
     {
       my_message(ER_SLAVE_IGNORED_TABLE, ER(ER_SLAVE_IGNORED_TABLE), MYF(0));
       break;
@@ -3661,8 +3700,8 @@ end_with_restore_list:
     */
 #ifdef HAVE_REPLICATION
     if (thd->slave_thread && 
-	(!db_ok(lex->name, replicate_do_db, replicate_ignore_db) ||
-	 !db_ok_with_wild_table(lex->name)))
+	(!rpl_filter->db_ok(lex->name) ||
+	 !rpl_filter->db_ok_with_wild_table(lex->name)))
     {
       my_message(ER_SLAVE_IGNORED_TABLE, ER(ER_SLAVE_IGNORED_TABLE), MYF(0));
       break;
@@ -3679,6 +3718,48 @@ end_with_restore_list:
     res= mysql_rm_db(thd, lex->name, lex->drop_if_exists, 0);
     break;
   }
+  case SQLCOM_RENAME_DB:
+  {
+    LEX_STRING *olddb, *newdb;
+    List_iterator  db_list(lex->db_list);
+    olddb= db_list++;
+    newdb= db_list++;
+    if (end_active_trans(thd))
+    {
+      res= 1;
+      break;
+    }
+#ifdef HAVE_REPLICATION
+    if (thd->slave_thread && 
+       (!rpl_filter->db_ok(olddb->str) ||
+        !rpl_filter->db_ok(newdb->str) ||
+        !rpl_filter->db_ok_with_wild_table(olddb->str) ||
+        !rpl_filter->db_ok_with_wild_table(newdb->str)))
+    {
+      res= 1;
+      my_message(ER_SLAVE_IGNORED_TABLE, ER(ER_SLAVE_IGNORED_TABLE), MYF(0));
+      break;
+    }
+#endif
+    if (check_access(thd,ALTER_ACL,olddb->str,0,1,0,is_schema_db(olddb->str)) ||
+        check_access(thd,DROP_ACL,olddb->str,0,1,0,is_schema_db(olddb->str)) ||
+        check_access(thd,CREATE_ACL,newdb->str,0,1,0,is_schema_db(newdb->str)))
+    {
+      res= 1;
+      break;
+    }
+    if (thd->locked_tables || thd->active_transaction())
+    {
+      res= 1;
+      my_message(ER_LOCK_OR_ACTIVE_TRANSACTION,
+                 ER(ER_LOCK_OR_ACTIVE_TRANSACTION), MYF(0));
+      goto error;
+    }
+    res= mysql_rename_db(thd, olddb, newdb);
+    if (!res)
+      send_ok(thd);
+    break;
+  }
   case SQLCOM_ALTER_DB:
   {
     char *db= lex->name ? lex->name : thd->db;
@@ -3689,7 +3770,7 @@ end_with_restore_list:
     }
     if (!strip_sp(db) || check_db_name(db))
     {
-      my_error(ER_WRONG_DB_NAME, MYF(0), lex->name);
+      my_error(ER_WRONG_DB_NAME, MYF(0), db);
       break;
     }
     /*
@@ -3701,8 +3782,8 @@ end_with_restore_list:
     */
 #ifdef HAVE_REPLICATION
     if (thd->slave_thread &&
-	(!db_ok(db, replicate_do_db, replicate_ignore_db) ||
-	 !db_ok_with_wild_table(db)))
+	(!rpl_filter->db_ok(db) ||
+	 !rpl_filter->db_ok_with_wild_table(db)))
     {
       my_message(ER_SLAVE_IGNORED_TABLE, ER(ER_SLAVE_IGNORED_TABLE), MYF(0));
       break;
@@ -3726,11 +3807,83 @@ end_with_restore_list:
       my_error(ER_WRONG_DB_NAME, MYF(0), lex->name);
       break;
     }
-    if (check_access(thd,SELECT_ACL,lex->name,0,1,0,is_schema_db(lex->name)))
-      break;
     res=mysqld_show_create_db(thd,lex->name,&lex->create_info);
     break;
   }
+  case SQLCOM_CREATE_EVENT:
+  case SQLCOM_ALTER_EVENT:
+  case SQLCOM_DROP_EVENT:
+  {
+    uint rows_affected= 1;
+    DBUG_ASSERT(lex->et);
+    do {
+      if (! lex->et->dbname.str)
+      {
+        my_message(ER_NO_DB_ERROR, ER(ER_NO_DB_ERROR), MYF(0));
+        res= true;
+        break;
+      }
+
+      if (check_access(thd, EVENT_ACL, lex->et->dbname.str, 0, 0, 0,
+                       is_schema_db(lex->et->dbname.str)))
+        break;
+
+      if (end_active_trans(thd))
+      {
+        res= -1;
+        break;
+      }
+
+      switch (lex->sql_command) {
+      case SQLCOM_CREATE_EVENT:
+        res= evex_create_event(thd, lex->et, (uint) lex->create_info.options,
+                               &rows_affected);
+        break;
+      case SQLCOM_ALTER_EVENT:
+        res= evex_update_event(thd, lex->et, lex->spname, &rows_affected);
+        break;
+      case SQLCOM_DROP_EVENT:
+        res= evex_drop_event(thd, lex->et, lex->drop_if_exists, &rows_affected);
+      default:;
+      }
+      DBUG_PRINT("info", ("CREATE/ALTER/DROP returned error code=%d af_rows=%d",
+                  res, rows_affected));
+      if (!res)
+        send_ok(thd, rows_affected);
+
+      /* lex->unit.cleanup() is called outside, no need to call it here */
+    } while (0);
+    if (!thd->spcont)
+    {
+      lex->et->free_sphead_on_delete= true;
+      lex->et->free_sp();
+      lex->et->deinit_mutexes();
+    }
+    
+    break;
+  }
+  case SQLCOM_SHOW_CREATE_EVENT:
+  {
+    DBUG_ASSERT(lex->spname);
+    DBUG_ASSERT(lex->et);
+    if (! lex->spname->m_db.str)
+    {
+      my_message(ER_NO_DB_ERROR, ER(ER_NO_DB_ERROR), MYF(0));
+      res= true;
+      break;
+    }
+    if (check_access(thd, EVENT_ACL, lex->spname->m_db.str, 0, 0, 0,
+                     is_schema_db(lex->spname->m_db.str)))
+      break;
+
+    if (lex->spname->m_name.length > NAME_LEN)
+    {
+      my_error(ER_TOO_LONG_IDENT, MYF(0), lex->spname->m_name.str);
+      goto error;
+    }
+    res= evex_show_create_event(thd, lex->spname, lex->et->definer);
+    break;
+  }
   case SQLCOM_CREATE_FUNCTION:                  // UDF function
   {
     if (check_access(thd,INSERT_ACL,"mysql",0,1,0,0))
@@ -3761,10 +3914,8 @@ end_with_restore_list:
     if (!(res= mysql_create_user(thd, lex->users_list)))
     {
       if (mysql_bin_log.is_open())
-      {
-        Query_log_event qinfo(thd, thd->query, thd->query_length, 0, FALSE);
-        mysql_bin_log.write(&qinfo);
-      }
+        thd->binlog_query(THD::MYSQL_QUERY_TYPE,
+                          thd->query, thd->query_length, FALSE, FALSE);
       send_ok(thd);
     }
     break;
@@ -3780,8 +3931,8 @@ end_with_restore_list:
     {
       if (mysql_bin_log.is_open())
       {
-        Query_log_event qinfo(thd, thd->query, thd->query_length, 0, FALSE);
-        mysql_bin_log.write(&qinfo);
+        thd->binlog_query(THD::MYSQL_QUERY_TYPE,
+                          thd->query, thd->query_length, FALSE, FALSE);
       }
       send_ok(thd);
     }
@@ -3798,8 +3949,8 @@ end_with_restore_list:
     {
       if (mysql_bin_log.is_open())
       {
-        Query_log_event qinfo(thd, thd->query, thd->query_length, 0, FALSE);
-        mysql_bin_log.write(&qinfo);
+        thd->binlog_query(THD::MYSQL_QUERY_TYPE,
+                          thd->query, thd->query_length, FALSE, FALSE);
       }
       send_ok(thd);
     }
@@ -3814,8 +3965,8 @@ end_with_restore_list:
     {
       if (mysql_bin_log.is_open())
       {
-	Query_log_event qinfo(thd, thd->query, thd->query_length, 0, FALSE);
-	mysql_bin_log.write(&qinfo);
+        thd->binlog_query(THD::MYSQL_QUERY_TYPE,
+                          thd->query, thd->query_length, FALSE, FALSE);
       }
       send_ok(thd);
     }
@@ -3894,8 +4045,8 @@ end_with_restore_list:
       if (!res && mysql_bin_log.is_open())
       {
         thd->clear_error();
-        Query_log_event qinfo(thd, thd->query, thd->query_length, 0, FALSE);
-        mysql_bin_log.write(&qinfo);
+        thd->binlog_query(THD::MYSQL_QUERY_TYPE,
+                          thd->query, thd->query_length, FALSE, FALSE);
       }
     }
     else
@@ -3914,8 +4065,8 @@ end_with_restore_list:
 	if (mysql_bin_log.is_open())
 	{
           thd->clear_error();
-	  Query_log_event qinfo(thd, thd->query, thd->query_length, 0, FALSE);
-	  mysql_bin_log.write(&qinfo);
+          thd->binlog_query(THD::MYSQL_QUERY_TYPE,
+                            thd->query, thd->query_length, FALSE, FALSE);
 	}
 	if (lex->sql_command == SQLCOM_GRANT)
 	{
@@ -3954,8 +4105,8 @@ end_with_restore_list:
       {
         if (mysql_bin_log.is_open())
         {
-          Query_log_event qinfo(thd, thd->query, thd->query_length, 0, FALSE);
-          mysql_bin_log.write(&qinfo);
+          thd->binlog_query(THD::STMT_QUERY_TYPE,
+                            thd->query, thd->query_length, 0, FALSE);
         }
       }
       send_ok(thd);
@@ -4295,12 +4446,12 @@ end_with_restore_list:
       			       db, name,
                                lex->sql_command == SQLCOM_CREATE_PROCEDURE, 1))
       {
-        close_thread_tables(thd);
         if (sp_grant_privileges(thd, db, name, 
                                 lex->sql_command == SQLCOM_CREATE_PROCEDURE))
           push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, 
 	  	       ER_PROC_AUTO_GRANT_FAIL,
 		       ER(ER_PROC_AUTO_GRANT_FAIL));
+        close_thread_tables(thd);
       }
 #endif
       send_ok(thd);
@@ -4518,8 +4669,8 @@ end_with_restore_list:
         if (mysql_bin_log.is_open())
         {
           thd->clear_error();
-          Query_log_event qinfo(thd, thd->query, thd->query_length, 0, FALSE);
-          mysql_bin_log.write(&qinfo);
+          thd->binlog_query(THD::MYSQL_QUERY_TYPE,
+                            thd->query, thd->query_length, FALSE, FALSE);
         }
 	send_ok(thd);
 	break;
@@ -4603,8 +4754,8 @@ end_with_restore_list:
         if (mysql_bin_log.is_open())
         {
           thd->clear_error();
-          Query_log_event qinfo(thd, thd->query, thd->query_length, 0, FALSE);
-          mysql_bin_log.write(&qinfo);
+          thd->binlog_query(THD::MYSQL_QUERY_TYPE,
+                            thd->query, thd->query_length, FALSE, FALSE);
         }
 	send_ok(thd);
 	break;
@@ -4728,8 +4879,8 @@ end_with_restore_list:
         buff.append(STRING_WITH_LEN(" AS "));
         buff.append(first_table->source.str, first_table->source.length);
 
-        Query_log_event qinfo(thd, buff.ptr(), buff.length(), 0, FALSE);
-        mysql_bin_log.write(&qinfo);
+        thd->binlog_query(THD::STMT_QUERY_TYPE,
+                          buff.ptr(), buff.length(), FALSE, FALSE);
       }
       break;
     }
@@ -4742,8 +4893,8 @@ end_with_restore_list:
           mysql_bin_log.is_open())
       {
         thd->clear_error();
-        Query_log_event qinfo(thd, thd->query, thd->query_length, 0, FALSE);
-        mysql_bin_log.write(&qinfo);
+        thd->binlog_query(THD::STMT_QUERY_TYPE,
+                          thd->query, thd->query_length, FALSE, FALSE);
       }
       break;
     }
@@ -4937,6 +5088,30 @@ end_with_restore_list:
   case SQLCOM_XA_RECOVER:
     res= mysql_xa_recover(thd);
     break;
+  case SQLCOM_ALTER_TABLESPACE:
+    if (check_access(thd, ALTER_ACL, thd->db, 0, 1, 0, thd->db ? is_schema_db(thd->db) : 0))
+      break;
+    if (!(res= mysql_alter_tablespace(thd, lex->alter_tablespace_info)))
+      send_ok(thd);
+    break;
+  case SQLCOM_INSTALL_PLUGIN:
+    if (! (res= mysql_install_plugin(thd, &thd->lex->comment,
+                                     &thd->lex->ident)))
+      send_ok(thd);
+    break;
+  case SQLCOM_UNINSTALL_PLUGIN:
+    if (! (res= mysql_uninstall_plugin(thd, &thd->lex->comment)))
+      send_ok(thd);
+    break;
+  case SQLCOM_BINLOG_BASE64_EVENT:
+  {
+#ifndef EMBEDDED_LIBRARY
+    mysql_client_binlog_statement(thd);
+#else /* EMBEDDED_LIBRARY */
+    my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0), "embedded");
+#endif /* EMBEDDED_LIBRARY */
+    break;
+  }
   default:
 #ifndef EMBEDDED_LIBRARY
     DBUG_ASSERT(0);                             /* Impossible */
@@ -4944,10 +5119,12 @@ end_with_restore_list:
     send_ok(thd);
     break;
   }
+
+end:
   thd->proc_info="query end";
-  /* Two binlog-related cleanups: */
 
   /*
+    Binlog-related cleanup:
     Reset system variables temporarily modified by SET ONE SHOT.
 
     Exception: If this is a SET, do nothing. This is to allow
@@ -4958,6 +5135,7 @@ end_with_restore_list:
   */
   if (thd->one_shot_set && lex->sql_command != SQLCOM_SET_OPTION)
     reset_one_shot_variables(thd);
+  thd->reset_current_stmt_binlog_row_based();
 
   /*
     The return value for ROW_COUNT() is "implementation dependent" if the
@@ -4973,7 +5151,8 @@ end_with_restore_list:
   DBUG_RETURN(res || thd->net.report_error);
 
 error:
-  DBUG_RETURN(1);
+  res= 1;           // would be better to set res=1 before "goto error"
+  goto end;
 }
 
 
@@ -5649,7 +5828,6 @@ void mysql_init_multi_delete(LEX *lex)
   lex->query_tables_last= &lex->query_tables;
 }
 
-
 /*
   When you modify mysql_parse(), you may need to mofify
   mysql_test_parse_for_slave() in this same file.
@@ -5679,11 +5857,16 @@ void mysql_parse(THD *thd, char *inBuf, uint length)
       {
 	if (thd->net.report_error)
 	{
-	  if (thd->lex->sphead)
-	  {
-	    delete thd->lex->sphead;
-	    thd->lex->sphead= NULL;
-	  }
+          delete lex->sphead;
+          lex->sphead= NULL;
+          if (lex->et)
+          {
+            lex->et->free_sphead_on_delete= true;
+            /* alloced on thd->mem_root so no real memory free but dtor call */
+            lex->et->free_sp();
+            lex->et->deinit_mutexes();
+            lex->et= NULL;
+          }
 	}
 	else
 	{
@@ -5713,11 +5896,18 @@ void mysql_parse(THD *thd, char *inBuf, uint length)
 			 thd->is_fatal_error));
       query_cache_abort(&thd->net);
       lex->unit.cleanup();
-      if (thd->lex->sphead)
+      if (lex->sphead)
       {
 	/* Clean up after failed stored procedure/function */
-	delete thd->lex->sphead;
-	thd->lex->sphead= NULL;
+	delete lex->sphead;
+	lex->sphead= NULL;
+      }
+      if (lex->et)
+      {
+        lex->et->free_sphead_on_delete= true;
+        lex->et->free_sp();
+        lex->et->deinit_mutexes();
+        lex->et= NULL;
       }
     }
     thd->proc_info="freeing items";
@@ -5842,10 +6032,7 @@ bool add_field_to_list(THD *thd, char *field_name, enum_field_types type,
     */
     char buf[32];
     my_snprintf(buf, sizeof(buf), "TIMESTAMP(%s)", length);
-    push_warning_printf(thd,MYSQL_ERROR::WARN_LEVEL_WARN,
-                        ER_WARN_DEPRECATED_SYNTAX,
-                        ER(ER_WARN_DEPRECATED_SYNTAX),
-                        buf, "TIMESTAMP");
+    WARN_DEPRECATED(thd, "5.2", buf, "'TIMESTAMP'");
   }
 
   if (!(new_field= new create_field()) ||
@@ -5974,12 +6161,16 @@ TABLE_LIST *st_select_lex::add_table_to_list(THD *thd,
   if (!table)
     DBUG_RETURN(0);				// End of memory
   alias_str= alias ? alias->str : table->table.str;
-  if (check_table_name(table->table.str,table->table.length) ||
-      table->db.str && check_db_name(table->db.str))
+  if (check_table_name(table->table.str,table->table.length))
   {
     my_error(ER_WRONG_TABLE_NAME, MYF(0), table->table.str);
     DBUG_RETURN(0);
   }
+  if (table->db.str && check_db_name(table->db.str))
+  {
+    my_error(ER_WRONG_DB_NAME, MYF(0), table->db.str);
+    DBUG_RETURN(0);
+  }
 
   if (!alias)					/* Alias is case sensitive */
   {
@@ -6596,7 +6787,8 @@ bool reload_acl_and_cache(THD *thd, ulong options, TABLE_LIST *tables,
   {
     /*
       Flush the normal query log, the update log, the binary log,
-      the slow query log, and the relay log (if it exists).
+      the slow query log, the relay log (if it exists) and the log
+      tables.
     */
 
     /*
@@ -6606,15 +6798,17 @@ bool reload_acl_and_cache(THD *thd, ulong options, TABLE_LIST *tables,
       than it would help them)
     */
     tmp_write_to_binlog= 0;
-    mysql_log.new_file(1);
-    mysql_slow_log.new_file(1);
     mysql_bin_log.rotate_and_purge(RP_FORCE_ROTATE);
 #ifdef HAVE_REPLICATION
     pthread_mutex_lock(&LOCK_active_mi);
     rotate_relay_log(active_mi);
     pthread_mutex_unlock(&LOCK_active_mi);
 #endif
-    if (ha_flush_logs())
+
+    /* flush slow and general logs */
+    logger.flush_logs(thd);
+
+    if (ha_flush_logs(NULL))
       result=1;
     if (flush_error_log())
       result=1;
@@ -6738,6 +6932,8 @@ void kill_one_thread(THD *thd, ulong id, bool only_kill_query)
   I_List_iterator it(threads);
   while ((tmp=it++))
   {
+    if (tmp->command == COM_DAEMON)
+      continue;
     if (tmp->thread_id == id)
     {
       pthread_mutex_lock(&tmp->LOCK_delete);	// Lock from delete
@@ -6767,8 +6963,8 @@ void kill_one_thread(THD *thd, ulong id, bool only_kill_query)
 
 	/* If pointer is not a null pointer, append filename to it */
 
-static bool append_file_to_dir(THD *thd, const char **filename_ptr,
-			       const char *table_name)
+bool append_file_to_dir(THD *thd, const char **filename_ptr,
+                        const char *table_name)
 {
   char buff[FN_REFLEN],*ptr, *end;
   if (!*filename_ptr)
@@ -6908,7 +7104,7 @@ bool mysql_create_index(THD *thd, TABLE_LIST *table_list, List &keys)
   HA_CREATE_INFO create_info;
   DBUG_ENTER("mysql_create_index");
   bzero((char*) &create_info,sizeof(create_info));
-  create_info.db_type=DB_TYPE_DEFAULT;
+  create_info.db_type= (handlerton*) &default_hton;
   create_info.default_table_charset= thd->variables.collation_database;
   DBUG_RETURN(mysql_alter_table(thd,table_list->db,table_list->table_name,
 				&create_info, table_list,
@@ -6924,7 +7120,7 @@ bool mysql_drop_index(THD *thd, TABLE_LIST *table_list, ALTER_INFO *alter_info)
   HA_CREATE_INFO create_info;
   DBUG_ENTER("mysql_drop_index");
   bzero((char*) &create_info,sizeof(create_info));
-  create_info.db_type=DB_TYPE_DEFAULT;
+  create_info.db_type= (handlerton*) &default_hton;
   create_info.default_table_charset= thd->variables.collation_database;
   alter_info->clear();
   alter_info->flags= ALTER_DROP_INDEX;
diff --git a/tests/mysql_client_test.c b/tests/mysql_client_test.c
index 4bd636a7ae3..9bc24c17824 100644
--- a/tests/mysql_client_test.c
+++ b/tests/mysql_client_test.c
@@ -1213,7 +1213,7 @@ static void test_tran_bdb()
 
   /* create the table 'mytran_demo' of type BDB' or 'InnoDB' */
   rc= mysql_query(mysql, "CREATE TABLE my_demo_transaction( "
-                         "col1 int , col2 varchar(30)) TYPE= BDB");
+                         "col1 int , col2 varchar(30)) ENGINE= BDB");
   myquery(rc);
 
   /* insert a row and commit the transaction */
@@ -1286,7 +1286,7 @@ static void test_tran_innodb()
 
   /* create the table 'mytran_demo' of type BDB' or 'InnoDB' */
   rc= mysql_query(mysql, "CREATE TABLE my_demo_transaction(col1 int, "
-                         "col2 varchar(30)) TYPE= InnoDB");
+                         "col2 varchar(30)) ENGINE= InnoDB");
   myquery(rc);
 
   /* insert a row and commit the transaction */
@@ -9810,7 +9810,7 @@ static void test_derived()
   myquery(rc);
 
   rc= mysql_query(mysql, "create table t1 (id  int(8), primary key (id)) \
-TYPE=InnoDB DEFAULT CHARSET=utf8");
+ENGINE=InnoDB DEFAULT CHARSET=utf8");
   myquery(rc);
 
   rc= mysql_query(mysql, "insert into t1 values (1)");
@@ -9858,16 +9858,16 @@ static void test_xjoin()
   rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1, t2, t3, t4");
   myquery(rc);
 
-  rc= mysql_query(mysql, "create table t3 (id int(8), param1_id int(8), param2_id int(8)) TYPE=InnoDB DEFAULT CHARSET=utf8");
+  rc= mysql_query(mysql, "create table t3 (id int(8), param1_id int(8), param2_id int(8)) ENGINE=InnoDB DEFAULT CHARSET=utf8");
   myquery(rc);
 
-  rc= mysql_query(mysql, "create table t1 ( id int(8), name_id int(8), value varchar(10)) TYPE=InnoDB DEFAULT CHARSET=utf8");
+  rc= mysql_query(mysql, "create table t1 ( id int(8), name_id int(8), value varchar(10)) ENGINE=InnoDB DEFAULT CHARSET=utf8");
   myquery(rc);
 
-  rc= mysql_query(mysql, "create table t2 (id int(8), name_id int(8), value varchar(10)) TYPE=InnoDB DEFAULT CHARSET=utf8;");
+  rc= mysql_query(mysql, "create table t2 (id int(8), name_id int(8), value varchar(10)) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
   myquery(rc);
 
-  rc= mysql_query(mysql, "create table t4(id int(8), value varchar(10)) TYPE=InnoDB DEFAULT CHARSET=utf8");
+  rc= mysql_query(mysql, "create table t4(id int(8), value varchar(10)) ENGINE=InnoDB DEFAULT CHARSET=utf8");
   myquery(rc);
 
   rc= mysql_query(mysql, "insert into t3 values (1, 1, 1), (2, 2, null)");
@@ -14401,7 +14401,7 @@ static void test_bug14210()
     itself is not InnoDB related. In case the table is MyISAM this test
     is harmless.
   */
-  mysql_query(mysql, "create table t1 (a varchar(255)) type=InnoDB");
+  mysql_query(mysql, "create table t1 (a varchar(255)) engine=InnoDB");
   rc= mysql_query(mysql, "insert into t1 (a) values (repeat('a', 256))");
   myquery(rc);
   rc= mysql_query(mysql, "set @@session.max_heap_table_size=16384");
@@ -14758,6 +14758,24 @@ static void test_bug16143()
 }
 
 
+/* Bug #16144: mysql_stmt_attr_get type error */
+
+static void test_bug16144()
+{
+  const my_bool flag_orig= (my_bool) 0xde;
+  my_bool flag= flag_orig;
+  MYSQL_STMT *stmt;
+  myheader("test_bug16144");
+
+  /* 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);
+  DIE_UNLESS(flag == flag_orig);
+
+  mysql_stmt_close(stmt);
+}
+
 /*
   Bug #15613: "libmysqlclient API function mysql_stmt_prepare returns wrong
   field length"
@@ -15180,10 +15198,11 @@ static struct my_tests_st my_tests[]= {
   { "test_bug13488", test_bug13488 },
   { "test_bug13524", test_bug13524 },
   { "test_bug14845", test_bug14845 },
-  { "test_bug15510", test_bug15510 },
   { "test_opt_reconnect", test_opt_reconnect },
+  { "test_bug15510", test_bug15510},
   { "test_bug12744", test_bug12744 },
   { "test_bug16143", test_bug16143 },
+  { "test_bug16144", test_bug16144 },
   { "test_bug15613", test_bug15613 },
   { "test_bug14169", test_bug14169 },
   { "test_bug17667", test_bug17667 },
@@ -15300,7 +15319,6 @@ int main(int argc, char **argv)
 {
   struct my_tests_st *fptr;
 
-  DEBUGGER_OFF;
   MY_INIT(argv[0]);
 
   load_defaults("my", client_test_load_default_groups, &argc, &argv);

From 20b687ce0dac926fd82a9f653afa0e2bb7f2e490 Mon Sep 17 00:00:00 2001
From: "acurtis@xiphis.org" <>
Date: Tue, 2 May 2006 12:04:20 -0700
Subject: [PATCH 098/108] WL#3201 post-review fixups

---
 config/ac-macros/plugins.m4 | 22 +++++++++++++++++++---
 sql/log.cc                  | 12 ++++++++----
 2 files changed, 27 insertions(+), 7 deletions(-)

diff --git a/config/ac-macros/plugins.m4 b/config/ac-macros/plugins.m4
index 385b6f1d66c..79353201971 100644
--- a/config/ac-macros/plugins.m4
+++ b/config/ac-macros/plugins.m4
@@ -325,6 +325,7 @@ AC_DEFUN([__MYSQL_EMIT_CHECK_PLUGIN],[
   if test "X[$with_plugin_]$2" = Xno; then
     AC_MSG_RESULT([no])
   else
+    m4_ifdef([$8],m4_ifdef([$7],[],[[with_plugin_]$2='']))
     if test "X[$mysql_plugin_]$2" != Xyes -a \
             "X[$with_plugin_]$2" != Xyes; then
       m4_ifdef([$8],[
@@ -504,6 +505,8 @@ dnl   _MYSQL_PLUGAPPEND([name],[to-append])
 dnl
 dnl DESCRIPTION
 dnl   Helper macro for appending to colon-delimited lists
+dnl   Optinal 3rd argument is for actions only required when defining
+dnl   macro named for the first time.
 
 AC_DEFUN([_MYSQL_PLUGAPPEND],[
  m4_ifdef([$1],[
@@ -594,8 +597,8 @@ m4_ifdef([$9],[
 ])
 
 AC_DEFUN([_PLUGIN_BUILD_TYPE],
-[m4_ifdef([$1],[ifelse($1,[no],[],[static ]m4_ifdef([$2],[and dnl
-]))])[]m4_ifdef([$2],[dynamic],[m4_ifdef([$1],[],[static])])])
+[m4_ifdef([$1],[static ]m4_ifdef([$2],[and dnl
+]))[]m4_ifdef([$2],[dynamic],[m4_ifdef([$1],[],[static])])])
 
 
 dnl ---------------------------------------------------------------------------
@@ -610,13 +613,26 @@ AC_DEFUN([_MYSQL_EMIT_PLUGINS],[
   m4_ifdef([MYSQL_PLUGIN_DISABLED_]AS_TR_CPP([$1]),[
       AC_MSG_ERROR([plugin $1 is disabled])
   ],[
-      [mysql_plugin_]m4_bpatsubst([$1], -, _)=yes
+    _MYSQL_EMIT_PLUGIN_ENABLE([$1], m4_bpatsubst([$1], -, _),
+      [MYSQL_PLUGIN_NAME_]AS_TR_CPP([$1]),
+      [MYSQL_PLUGIN_STATIC_]AS_TR_CPP([$1]),
+      [MYSQL_PLUGIN_DYNAMIC_]AS_TR_CPP([$1]))
   ])
       ;;
   _MYSQL_EMIT_PLUGINS(m4_shift($@))
  ])
 ])
 
+AC_DEFUN([_MYSQL_EMIT_PLUGIN_ENABLE],[
+    m4_ifdef([$5],m4_ifdef([$4],[
+      [mysql_plugin_]$2=yes
+    ],[
+      AC_MSG_WARN([$3 can only be built as a plugin])
+    ]),[
+      [mysql_plugin_]$2=yes
+    ])      
+])
+
 AC_DEFUN([_MYSQL_EMIT_PLUGIN_DEPENDS], [
  ifelse($#, 0, [], [$#:$1], [1:], [], [
   _MYSQL_EMIT_CHECK_DEPENDS(m4_bpatsubst([$1], -, _), 
diff --git a/sql/log.cc b/sql/log.cc
index 61d280f8504..e9a5011db4d 100644
--- a/sql/log.cc
+++ b/sql/log.cc
@@ -70,11 +70,15 @@ struct binlog_trx_data {
   Rows_log_event *pending;                // The pending binrows event
 };
 
+static const char binlog_hton_name[]= "binlog";
+static const char binlog_hton_comment[]=
+  "This is a meta storage engine to represent the binlog in a transaction";
+
 handlerton binlog_hton = {
   MYSQL_HANDLERTON_INTERFACE_VERSION,
-  "binlog",
+  binlog_hton_name,
   SHOW_OPTION_YES,
-  "This is a meta storage engine to represent the binlog in a transaction",
+  binlog_hton_comment,
   DB_TYPE_BINLOG,               /* IGNORE  for now */
   binlog_init,
   0,
@@ -4350,9 +4354,9 @@ mysql_declare_plugin(binlog)
 {
   MYSQL_STORAGE_ENGINE_PLUGIN,
   &binlog_hton,
-  binlog_hton.name,
+  binlog_hton_name,
   "MySQL AB",
-  "Binlog Engine",
+  binlog_hton_comment,
   NULL, /* Plugin Init */
   NULL, /* Plugin Deinit */
   0x0100 /* 1.0 */,

From 5de7b78bd2e5f865a197ad5e1e0c4a04bde70b9f Mon Sep 17 00:00:00 2001
From: "cmiller@zippy.(none)" <>
Date: Tue, 2 May 2006 15:07:00 -0400
Subject: [PATCH 099/108] More merging assistence.

Logging behavior changed in early 5.1.  (The filename was never right, but
the "opt" file is unnecessary in 5.0 anyway.)
---
 mysql-test/t/mysql_client_test-master.opt | 1 +
 mysql-test/t/mysql_client_test.opt        | 1 -
 2 files changed, 1 insertion(+), 1 deletion(-)
 create mode 100644 mysql-test/t/mysql_client_test-master.opt
 delete mode 100644 mysql-test/t/mysql_client_test.opt

diff --git a/mysql-test/t/mysql_client_test-master.opt b/mysql-test/t/mysql_client_test-master.opt
new file mode 100644
index 00000000000..3711946168d
--- /dev/null
+++ b/mysql-test/t/mysql_client_test-master.opt
@@ -0,0 +1 @@
+--log --log-output=FILE 
diff --git a/mysql-test/t/mysql_client_test.opt b/mysql-test/t/mysql_client_test.opt
deleted file mode 100644
index 968ba95c6cc..00000000000
--- a/mysql-test/t/mysql_client_test.opt
+++ /dev/null
@@ -1 +0,0 @@
---log

From f6073b273501227b5b6b967aa0c610cf7408940a Mon Sep 17 00:00:00 2001
From: "aivanov@mysql.com" <>
Date: Tue, 2 May 2006 23:08:22 +0400
Subject: [PATCH 100/108] WL#3148: Modifying sizes of i_s.processlist columns
 ('time', 'info').

---
 mysql-test/r/information_schema.result |  1 +
 sql/mysql_priv.h                       |  2 ++
 sql/sql_show.cc                        | 11 ++++-------
 3 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/mysql-test/r/information_schema.result b/mysql-test/r/information_schema.result
index 5e915b5742c..967507740be 100644
--- a/mysql-test/r/information_schema.result
+++ b/mysql-test/r/information_schema.result
@@ -759,6 +759,7 @@ information_schema	PARTITIONS	PARTITION_EXPRESSION
 information_schema	PARTITIONS	SUBPARTITION_EXPRESSION
 information_schema	PARTITIONS	PARTITION_DESCRIPTION
 information_schema	PLUGINS	PLUGIN_DESCRIPTION
+information_schema	PROCESSLIST	INFO
 information_schema	ROUTINES	ROUTINE_DEFINITION
 information_schema	ROUTINES	SQL_MODE
 information_schema	TRIGGERS	ACTION_CONDITION
diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h
index bc398b3d20a..749a968a5af 100644
--- a/sql/mysql_priv.h
+++ b/sql/mysql_priv.h
@@ -177,6 +177,8 @@ extern CHARSET_INFO *national_charset_info, *table_alias_charset;
 
 /* Characters shown for the command in 'show processlist' */
 #define PROCESS_LIST_WIDTH 100
+/* Characters shown for the command in 'information_schema.processlist' */
+#define PROCESS_LIST_INFO_WIDTH 65535
 
 /* Time handling defaults */
 #define TIMESTAMP_MAX_YEAR 2038
diff --git a/sql/sql_show.cc b/sql/sql_show.cc
index 95433828a1e..9976f0e1cfa 100644
--- a/sql/sql_show.cc
+++ b/sql/sql_show.cc
@@ -1553,15 +1553,11 @@ int fill_schema_processlist(THD* thd, TABLE_LIST* tables, COND* cond)
   TABLE *table= tables->table;
   CHARSET_INFO *cs= system_charset_info;
   char *user;
-  bool verbose;
-  ulong max_query_length;
   time_t now= time(0);
   DBUG_ENTER("fill_process_list");
 
   user= thd->security_ctx->master_access & PROCESS_ACL ?
         NullS : thd->security_ctx->priv_user;
-  verbose= thd->lex->verbose;
-  max_query_length= PROCESS_LIST_WIDTH;
 
   VOID(pthread_mutex_lock(&LOCK_thread_count));
 
@@ -1645,7 +1641,8 @@ int fill_schema_processlist(THD* thd, TABLE_LIST* tables, COND* cond)
       if (tmp->query)
       {
         table->field[7]->store(tmp->query,
-                               min(max_query_length, tmp->query_length), cs);
+                               min(PROCESS_LIST_INFO_WIDTH,
+                                   tmp->query_length), cs);
         table->field[7]->set_notnull();
       }
 
@@ -5096,9 +5093,9 @@ ST_FIELD_INFO processlist_fields_info[]=
   {"HOST", LIST_PROCESS_HOST_LEN,  MYSQL_TYPE_STRING, 0, 0, "Host"},
   {"DB", NAME_LEN, MYSQL_TYPE_STRING, 0, 1, "Db"},
   {"COMMAND", 16, MYSQL_TYPE_STRING, 0, 0, "Command"},
-  {"TIME", 4, MYSQL_TYPE_LONG, 0, 0, "Time"},
+  {"TIME", 7, MYSQL_TYPE_LONG, 0, 0, "Time"},
   {"STATE", 30, MYSQL_TYPE_STRING, 0, 1, "State"},
-  {"INFO", PROCESS_LIST_WIDTH, MYSQL_TYPE_STRING, 0, 1, "Info"},
+  {"INFO", PROCESS_LIST_INFO_WIDTH, MYSQL_TYPE_STRING, 0, 1, "Info"},
   {0, 0, MYSQL_TYPE_STRING, 0, 0, 0}
 };
 

From 2b253498209dca9d563a6c80210e26f4e261d583 Mon Sep 17 00:00:00 2001
From: "pekka@mysql.com" <>
Date: Tue, 2 May 2006 21:47:53 +0200
Subject: [PATCH 101/108] pekka:get - push push push

---
 BitKeeper/etc/config | 1 +
 1 file changed, 1 insertion(+)

diff --git a/BitKeeper/etc/config b/BitKeeper/etc/config
index b68810b77ac..6d06edd193e 100644
--- a/BitKeeper/etc/config
+++ b/BitKeeper/etc/config
@@ -74,5 +74,6 @@ hours:
 [jonas:]checkout:get
 [tomas:]checkout:get
 [guilhem:]checkout:get
+[pekka:]checkout:get
 checkout:edit
 eoln:unix

From 4ba1a4b3cd3629f3ab8e46f6a024d8b2f26f8104 Mon Sep 17 00:00:00 2001
From: "knielsen@mysql.com" <>
Date: Wed, 3 May 2006 09:06:22 +0200
Subject: [PATCH 102/108] Windows build fixes for CMake

---
 mysys/cmakelists.txt | 2 +-
 tests/cmakelists.txt | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/mysys/cmakelists.txt b/mysys/cmakelists.txt
index 5a3b8f1657e..4aa99a70121 100644
--- a/mysys/cmakelists.txt
+++ b/mysys/cmakelists.txt
@@ -26,4 +26,4 @@ ADD_LIBRARY(mysys array.c charset-def.c charset.c checksum.c default.c default_m
 				my_static.c my_symlink.c my_symlink2.c my_sync.c my_thr_init.c my_wincond.c
 				my_windac.c my_winsem.c my_winthread.c my_write.c ptr_cmp.c queues.c
 				rijndael.c safemalloc.c sha1.c string.c thr_alarm.c thr_lock.c thr_mutex.c
-				thr_rwlock.c tree.c typelib.c my_vle.c base64.c)
+				thr_rwlock.c tree.c typelib.c my_vle.c base64.c my_memmem.c)
diff --git a/tests/cmakelists.txt b/tests/cmakelists.txt
index c9b0b8735a2..46c42d461f3 100644
--- a/tests/cmakelists.txt
+++ b/tests/cmakelists.txt
@@ -6,4 +6,4 @@ ADD_DEFINITIONS("-DMYSQL_CLIENT")
 INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
 
 ADD_EXECUTABLE(mysql_client_test mysql_client_test.c)
-TARGET_LINK_LIBRARIES(mysql_client_test dbug mysqlclient yassl taocrypt zlib wsock32)
+TARGET_LINK_LIBRARIES(mysql_client_test dbug mysys mysqlclient yassl taocrypt zlib wsock32)

From 375d3e8258a9535972857c417f39a0a906ef978a Mon Sep 17 00:00:00 2001
From: "serg@sergbook.mysql.com" <>
Date: Wed, 3 May 2006 09:46:19 -0400
Subject: [PATCH 103/108] Fixed dependency checking

---
 config/ac-macros/plugins.m4 | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/config/ac-macros/plugins.m4 b/config/ac-macros/plugins.m4
index 79353201971..1488932c1ad 100644
--- a/config/ac-macros/plugins.m4
+++ b/config/ac-macros/plugins.m4
@@ -75,7 +75,7 @@ dnl ---------------------------------------------------------------------------
 dnl Macro: MYSQL_PLUGIN_DEFINE
 dnl
 dnl SYNOPSIS
-dnl   MYSQL_PLUGIN_DEFILE([name],[MYSQL_CPP_DEFINE])
+dnl   MYSQL_PLUGIN_DEFINE([name],[MYSQL_CPP_DEFINE])
 dnl
 dnl DESCRIPTION
 dnl   When a plugin is to be statically linked, define the C macro
@@ -96,6 +96,7 @@ dnl   MYSQL_PLUGIN_DIRECTORY([name],[plugin/dir])
 dnl
 dnl DESCRIPTION
 dnl   Adds a directory to the build process
+dnl   if it contains 'configure' it will be picked up automatically
 dnl
 dnl ---------------------------------------------------------------------------
 
@@ -219,7 +220,7 @@ AC_DEFUN([MYSQL_PLUGIN_DEPENDS],[
 ])
 
 AC_DEFUN([_MYSQL_PLUGIN_DEPEND],[
- ifelse($#, 1, [], [$#:$2], [2:], [
+ ifelse($#, 1, [], [$#:$2], [2:], [], [
   MYSQL_REQUIRE_PLUGIN([$2])
   _MYSQL_PLUGAPPEND([__mysql_plugdepends_$1__],[$2])
   _MYSQL_PLUGIN_DEPEND([$1], m4_shift(m4_shift($@)))
@@ -652,7 +653,7 @@ AC_DEFUN([_MYSQL_EMIT_CHECK_DEPENDS], [
 ])
 
 AC_DEFUN([_MYSQL_EMIT_PLUGIN_DEPENDENCIES], [
- ifelse($#, 0, [], [
+ ifelse([$1], [], [], [
   m4_ifdef([MYSQL_PLUGIN_DISABLED_]AS_TR_CPP([$1]),[
        AC_MSG_ERROR([depends upon disabled plugin $1])
   ],[

From a5789854ee1fe17ab8d370555ae50e57ce832321 Mon Sep 17 00:00:00 2001
From: "cmiller@zippy.(none)" <>
Date: Wed, 3 May 2006 09:55:34 -0400
Subject: [PATCH 104/108] Added code to remove closing comment code from event
 text, as would be supplied inside a  /*!VERSION event-text */  segment. 
 (Fixes Bug#18078

---
 mysql-test/t/disabled.def   |  1 -
 mysql-test/t/mysqldump.test | 10 ++++----
 sql/event_timed.cc          | 46 ++++++++++++++++++++++++++++++++++---
 3 files changed, 48 insertions(+), 9 deletions(-)

diff --git a/mysql-test/t/disabled.def b/mysql-test/t/disabled.def
index d92aed1d1a2..2d7d1b1ca8d 100644
--- a/mysql-test/t/disabled.def
+++ b/mysql-test/t/disabled.def
@@ -33,7 +33,6 @@ rpl_row_blob_innodb      : BUG#18980 2006-04-10 kent    Test fails randomly
 rpl_row_func003		 : BUG#19074 2006-13-04 andrei  test failed
 rpl_row_inexist_tbl      : BUG#18948 2006-03-09 mats    Disabled since patch makes this test wait forever
 rpl_sp                   : BUG#16456 2006-02-16 jmiller
-mysqldump                : BUG#18078 2006-03-10 lars
 udf                      : BUG#18564 2006-03-27 ian     (Permission by Brian)
 
 # the below testcase have been reworked to avoid the bug, test contains comment, keep bug open
diff --git a/mysql-test/t/mysqldump.test b/mysql-test/t/mysqldump.test
index 5ba7838bb81..59e09a6407a 100644
--- a/mysql-test/t/mysqldump.test
+++ b/mysql-test/t/mysqldump.test
@@ -1174,8 +1174,8 @@ create database first;
 use first;
 set time_zone = 'UTC';
 
-## prove one works
-create event ee1 on schedule at '2035-12-31 20:01:23' do set @a=5;
+## prove one works (with spaces and tabs on the end)
+create event ee1 on schedule at '2035-12-31 20:01:23' do set @a=5;    	 	
 show events;
 show create event ee1;
 --exec $MYSQL_DUMP --events first > $MYSQLTEST_VARDIR/tmp/bug16853-1.sql
@@ -1187,10 +1187,10 @@ use second;
 show events;
 show create event ee1;
 
-## prove three works
+## prove three works (with spaces and tabs on the end)
 # start with one from the previous restore
-create event ee2 on schedule at '2018-12-31 21:01:23' do set @a=5;
-create event ee3 on schedule at '2030-12-31 22:01:23' do set @a=5;
+create event ee2 on schedule at '2018-12-31 21:01:23' do set @a=5;	      
+create event ee3 on schedule at '2030-12-31 22:01:23' do set @a=5;    		
 show events;
 --exec $MYSQL_DUMP --events second > $MYSQLTEST_VARDIR/tmp/bug16853-2.sql
 drop database second;
diff --git a/sql/event_timed.cc b/sql/event_timed.cc
index adf28b8877c..ed012ecd399 100644
--- a/sql/event_timed.cc
+++ b/sql/event_timed.cc
@@ -106,6 +106,9 @@ Event_timed::init_name(THD *thd, sp_name *spn)
   NOTE
     The body is extracted by copying all data between the
     start of the body set by another method and the current pointer in Lex.
+ 
+    Some questionable removal of characters is done in here, and that part
+    should be refactored when the parser is smarter.
 */
 
 void
@@ -116,9 +119,46 @@ Event_timed::init_body(THD *thd)
              body_begin, thd->lex->ptr));
 
   body.length= thd->lex->ptr - body_begin;
-  /* Trim nuls at the end */
-  while (body.length && body_begin[body.length-1] == '\0')
-    body.length--;
+  const uchar *body_end= body_begin + body.length - 1;
+
+  /* Trim nuls or close-comments ('*'+'/') or spaces at the end */
+  while (body_begin < body_end)
+  {
+
+    if ((*body_end == '\0') || 
+        (my_isspace(thd->variables.character_set_client, *body_end)))
+    { /* consume NULs and meaningless whitespace */
+      --body.length;
+      --body_end;
+      continue;
+    }
+
+    /*  
+       consume closing comments
+
+       This is arguably wrong, but it's the best we have until the parser is
+       changed to be smarter.   FIXME PARSER 
+
+       See also the sp_head code, where something like this is done also.
+
+       One idea is to keep in the lexer structure the count of the number of
+       open-comments we've entered, and scan left-to-right looking for a
+       closing comment IFF the count is greater than zero.
+
+       Another idea is to remove the closing comment-characters wholly in the
+       parser, since that's where it "removes" the opening characters.
+    */
+    if ((*(body_end - 1) == '*') && (*body_end == '/'))
+    {
+      DBUG_PRINT("info", ("consumend one '*" "/' comment in the query '%s'", 
+          body_begin));
+      body.length-= 2;
+      body_end-= 2;
+      continue;
+    }
+
+    break;  /* none were found, so we have excised all we can. */
+  }
 
   /* the first is always whitespace which I cannot skip in the parser */
   while (my_isspace(thd->variables.character_set_client, *body_begin))

From d546f0d93e413be5f13225f75e581036045d503b Mon Sep 17 00:00:00 2001
From: "aivanov@mysql.com" <>
Date: Wed, 3 May 2006 23:25:01 +0400
Subject: [PATCH 105/108] Applied innodb-4.1-ss26 snapshot.  Fixed BUG#19366:
 "consistent_snapshot.test fails".

---
 innobase/include/dict0dict.ic | 2 --
 1 file changed, 2 deletions(-)

diff --git a/innobase/include/dict0dict.ic b/innobase/include/dict0dict.ic
index 85e4aaf1a05..4c1a88cfd1b 100644
--- a/innobase/include/dict0dict.ic
+++ b/innobase/include/dict0dict.ic
@@ -93,7 +93,6 @@ dict_table_get_n_user_cols(
 {
 	ut_ad(table);
 	ut_ad(table->magic_n == DICT_TABLE_MAGIC_N);
-	ut_ad(table->cached);
 	
 	return(table->n_cols - DATA_N_SYS_COLS);
 }
@@ -127,7 +126,6 @@ dict_table_get_n_cols(
 {
 	ut_ad(table);
 	ut_ad(table->magic_n == DICT_TABLE_MAGIC_N);
-	ut_ad(table->cached);
 	
 	return(table->n_cols);
 }

From 4cff042a588d8687af94bb62e68f8584eb6ac8b7 Mon Sep 17 00:00:00 2001
From: "aivanov@mysql.com" <>
Date: Thu, 4 May 2006 00:32:34 +0400
Subject: [PATCH 106/108] Applied innodb-5.0-ss521 snapshot.  Fixed BUG#19366:
 "consistent_snapshot.test fails".

---
 innobase/include/dict0dict.ic | 2 --
 1 file changed, 2 deletions(-)

diff --git a/innobase/include/dict0dict.ic b/innobase/include/dict0dict.ic
index 928a693f860..861da5d057a 100644
--- a/innobase/include/dict0dict.ic
+++ b/innobase/include/dict0dict.ic
@@ -92,7 +92,6 @@ dict_table_get_n_user_cols(
 {
 	ut_ad(table);
 	ut_ad(table->magic_n == DICT_TABLE_MAGIC_N);
-	ut_ad(table->cached);
 	
 	return(table->n_cols - DATA_N_SYS_COLS);
 }
@@ -126,7 +125,6 @@ dict_table_get_n_cols(
 {
 	ut_ad(table);
 	ut_ad(table->magic_n == DICT_TABLE_MAGIC_N);
-	ut_ad(table->cached);
 	
 	return(table->n_cols);
 }

From 16d8d6bcca2fe667baf7bb8bb249a59e353b504e Mon Sep 17 00:00:00 2001
From: "acurtis@xiphis.org" <>
Date: Wed, 3 May 2006 15:58:15 -0700
Subject: [PATCH 107/108] fix legacy configure option handling

---
 config/ac-macros/plugins.m4 | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/config/ac-macros/plugins.m4 b/config/ac-macros/plugins.m4
index 1488932c1ad..aa28a611e9e 100644
--- a/config/ac-macros/plugins.m4
+++ b/config/ac-macros/plugins.m4
@@ -60,13 +60,14 @@ AC_DEFUN([MYSQL_STORAGE_ENGINE],[
  MYSQL_PLUGIN_DEFINE([$1], [WITH_]AS_TR_CPP([$1])[_STORAGE_ENGINE])
  ifelse([$2],[no],[],[
   _MYSQL_LEGACY_STORAGE_ENGINE(
+      m4_bpatsubst([$1], -, _),
       m4_bpatsubst(m4_default([$2], [$1-storage-engine]), -, _))
  ])
 ])
 
 AC_DEFUN([_MYSQL_LEGACY_STORAGE_ENGINE],[
-if test "[${with_]$1[+set}]" = set; then
-  [with_plugin_]$1="[$with_]$1"
+if test "[${with_]$2[+set}]" = set; then
+  [with_plugin_]$1="[$with_]$2"
 fi
 ])
 

From 9d4a065ffd191faa9eac50c0603d8db74a1f2c00 Mon Sep 17 00:00:00 2001
From: "acurtis@xiphis.org" <>
Date: Wed, 3 May 2006 15:58:16 -0700
Subject: [PATCH 108/108] fix include path in windows build

---
 storage/archive/cmakelists.txt   | 4 +++-
 storage/blackhole/cmakelists.txt | 3 ++-
 storage/csv/cmakelists.txt       | 3 ++-
 3 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/storage/archive/cmakelists.txt b/storage/archive/cmakelists.txt
index 939f5562d50..a631f194b1a 100644
--- a/storage/archive/cmakelists.txt
+++ b/storage/archive/cmakelists.txt
@@ -1,6 +1,8 @@
 SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DSAFEMALLOC -DSAFE_MUTEX")
 SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DSAFEMALLOC -DSAFE_MUTEX")
 
-INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/zlib)
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/zlib
+                    ${CMAKE_SOURCE_DIR}/sql
+                    ${CMAKE_SOURCE_DIR}/extra/yassl/include)
 ADD_LIBRARY(archive azio.c ha_archive.cc ha_archive.h)
 TARGET_LINK_LIBRARIES(archive zlib mysys dbug strings)
diff --git a/storage/blackhole/cmakelists.txt b/storage/blackhole/cmakelists.txt
index 29c0e1bb94b..ea3a7eae38e 100644
--- a/storage/blackhole/cmakelists.txt
+++ b/storage/blackhole/cmakelists.txt
@@ -1,5 +1,6 @@
 SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DSAFEMALLOC -DSAFE_MUTEX")
 SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DSAFEMALLOC -DSAFE_MUTEX")
 
-INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/sql
+                    ${CMAKE_SOURCE_DIR}/extra/yassl/include)
 ADD_LIBRARY(blackhole ha_blackhole.cc ha_blackhole.h)
diff --git a/storage/csv/cmakelists.txt b/storage/csv/cmakelists.txt
index 4e142646b2d..28748527cc3 100644
--- a/storage/csv/cmakelists.txt
+++ b/storage/csv/cmakelists.txt
@@ -1,5 +1,6 @@
 SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DSAFEMALLOC -DSAFE_MUTEX")
 SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DSAFEMALLOC -DSAFE_MUTEX")
 
-INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/sql
+                    ${CMAKE_SOURCE_DIR}/extra/yassl/include)
 ADD_LIBRARY(csv ha_tina.cc ha_tina.h)