diff options
Diffstat (limited to 'sql/Attic')
-rw-r--r-- | sql/Attic/lex_hash.h | 416 | ||||
-rw-r--r-- | sql/Attic/mini_client.c | 783 | ||||
-rw-r--r-- | sql/Attic/mini_client_errors.c | 64 | ||||
-rw-r--r-- | sql/Attic/mybinlogdump.cc | 138 | ||||
-rw-r--r-- | sql/Attic/net_serv.c | 616 |
5 files changed, 2017 insertions, 0 deletions
diff --git a/sql/Attic/lex_hash.h b/sql/Attic/lex_hash.h new file mode 100644 index 00000000000..6e89119a3dc --- /dev/null +++ b/sql/Attic/lex_hash.h @@ -0,0 +1,416 @@ +/* This code is generated by program for seeking hash algorithms, copyright TcX Datakonsult AB */ + +#include "lex.h" + +static uint16 char_table[] = { +258,39835,4883,21845,23130,46003,12850,35980,514,65278,61937,7196,40863,26728,26985,9766, +5654,23644,21331,17733,3341,25186,30069,1542,31354,39321,4626,52171,46260,57568,21588,14906, +60652,20560,6939,39578,52428,10794,46517,40606,58596,17990,58339,24672,42148,60138,3598,5911, +43947,37522,36494,1799,36751,30840,57311,34952,56540,27499,45232,41891,61423,38550,29812,24158, +771,37779,57054,257,8224,64250,51657,16962,13878,20303,42662,6168,19275,20817,34438,44461, +12336,48059,49087,28013,3855,16191,32896,26214,57825,38807,29298,35723,51400,12079,6682,25957, +8738,37779,57054,257,8224,64250,51657,16962,13878,20303,42662,6168,19275,20817,34438,44461, +12336,48059,49087,28013,3855,16191,32896,26214,57825,38807,29298,32639,11051,43690,2313,33924, +16705,53970,4112,24415,30583,17476,45746,7967,34695,35466,25700,6425,29555,59881,10537,37008, +7710,2827,62965,11565,26471,43433,34181,30326,13364,29041,54998,47802,52685,63993,2056,51914, +31097,44718,48830,50372,23387,62194,19789,19532,53456,62451,16448,54741,63736,18761,10023,3084, +20046,31868,50629,15420,54484,42405,47288,31611,28270,47031,61680,65535,49344,23901,42919,48316, +10280,55512,60395,51143,9252,53199,40349,56797,13621,11308,49601,36237,18247,15934,18504,46774, +43176,11822,56283,28784,59624,39064,63479,19018,58853,65021,9509,8995,58082,5140,5397,15163, +27242,22102,28527,22873,59367,47545,13107,60909,41120,24929,22616,49858,38036,17219,4369,64507, +50115,62708,7453,41377,53713,33153,32382,59110,64764,50886,33410,8481,63222,41634,12593,56026 +}; + + +static uchar unique_length[] = { +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,3,1,2,0, +0,5,5,13,9,7,6,6,6,7,1,4,5,7,5,7, +8,3,12,10,6,7,4,5,0,5,1,0,0,0,0,0, +0,5,5,13,9,7,6,6,6,7,1,4,5,7,5,7, +8,3,12,10,6,7,4,5,0,5,1,0,1,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 +}; + + +static uint16 my_function_table[] = { +32767,32767,32767,32767,32767,32767,32767,32767,102,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,282, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,297,32767,32767,202,382,126,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,169,32767,32767,32767,32767,32767,32767,32767, +32767,32767,306,152,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,354,32767,32767,32767,32767,32767,370,256,32767, +32767,32767,32767,32767,32767,32767,355,32767,32767,32767,32767,361, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,313,32767,32767,32767,32767,32767,32767, +14,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,315, +32767,32767,32767,32767,32767,32767,32767,32767,42,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,189,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,27,32767,32767,32767,32767,32767,32767,32767,374,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,166,32767,32767,32767,32767,32767,32767,349,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +46,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,353,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,223, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +216,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,143,32767,32767,32767,32767,32767,32767,32767, +32767,20,32767,32767,32767,140,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,125,32767,32767,32767, +32767,224,32767,32767,32767,32767,267,32767,175,32767,32767,32767, +246,32767,32767,32767,32767,32767,32767,109,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,324,32767, +32767,32767,32767,32767,161,32767,21,32767,32767,32767,32767,32767, +32767,32767,32767,32767,11,32767,32767,32767,32767,32767,32767,32767, +194,32767,32767,32767,32767,32767,32767,32767,32767,332,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,364,342,32767, +32767,32767,32767,32767,32767,193,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,373,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,212,32767,32767,32767,32,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,54, +67,32767,32767,32767,32767,32767,32767,32767,32767,287,32767,32767, +32767,32767,32767,51,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,273,219,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,261,32767,32767,32767,32767, +32767,123,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,198,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,233,32767,32767,32767,32767,32767,32767,32767,338,32767,32767, +32767,32767,32767,32767,32767,236,32767,32767,32767,310,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,232,32767,32767,32767,32767,135,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,65,32767,32767,150,32767,32767,32767, +32767,32767,32767,32767,32767,32767,2,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,378,32767,32767,32767,32767,32767,107,32767,32767,32767,32767, +32767,32767,32767,335,32767,358,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,188,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +254,32767,32767,146,32767,32767,32767,32767,32767,153,33,32767, +32767,32767,32767,32767,32767,32767,242,32767,32767,32767,32767,32767, +32767,32767,32767,226,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,167,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,104,32767,32767, +32767,32767,32767,32767,32767,195,37,32767,32767,253,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,88,32767,32767,32767,32767,154,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,300,32767,32767,32767,330,314,326, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,259,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,134,32767,32767,32767,32767,341, +32767,32767,32767,32767,32767,32767,281,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,316,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,22,32767,32767,32767,32767,32767, +32767,32767,268,32767,32767,144,32767,32767,32767,32767,32767,32767, +32767,239,165,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,200,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,351,87,32767,32767,255,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,180,32767,32767,32767,32767,32767,10,24,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,376,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,230,32767,32767,32767,32767,32767,303,44,217, +32767,32767,32767,32767,32767,32767,32767,32767,317,32767,32767,32767, +266,32767,58,32767,84,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,181,32767,381,32767,296,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,40,32767,32767,32767,32767,32767,133,196,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,263,32767, +32767,32767,32767,32767,32767,182,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,28,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,307,32767,32767, +32767,32767,3,32767,32767,32767,32767,32767,32767,32767,32767,32767, +174,298,32767,32767,32767,32767,362,32767,32767,32767,151,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,99,32767,112, +32767,32767,15,32767,32767,32767,32767,32767,32767,32767,32767,129, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,76,32767,32767,32767,32767,93,32767,337,32767,32767, +356,32767,32767,32767,328,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,91,32767,250,32767,32767,32767,32767, +32767,32767,32767,32767,205,32767,32767,32767,32767,32767,32767,32767, +32767,368,32767,1,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,38,32767,203,32767,176,32767,32767,32767,32767, +32767,32767,208,32767,32767,32767,32767,32767,32767,32767,320,32767, +156,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,277,32767,32767,32767,32767,32767,32767, +32767,30,32767,32767,344,32767,32767,32767,32767,383,32767,32767, +155,32767,32767,119,32767,32767,32767,32767,32767,32767,32767,32767, +32767,211,43,32767,32767,32767,32767,32767,141,32767,158,32767, +32767,32767,32767,32767,283,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,280,32767,120,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,35,32767,32767,32767,32767,32767,347,32767,32767, +32767,32767,318,32767,32767,32767,235,32767,32767,32767,32767,32767, +32767,32767,32767,32767,262,32767,32767,32767,32767,45,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,305,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,278,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,238,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,7,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,122,32767,19,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,288,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,206,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,139,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,56,32767,32767,32767,32767,106,32767,77,32767,32767,32767, +32767,101,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,379, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,4,32767,32767,62,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,201, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,163,32767,32767, +98,32767,32767,32767,32767,32767,32767,162,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,192,82, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,340,32767,32767,32767,145,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,184,32767,32767,32767,32767,32767,32767,173,32767,32767,32767, +32767,32767,32767,32767,32767,32767,301,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,149,32767,32767,32767,32767,32767,32767,32767,32767,279,32767, +142,32767,32767,294,32767,32767,32767,32767,32767,32767,32767,333, +32767,32767,32767,32767,32767,117,32767,32767,69,32767,32767,96, +32767,32767,32767,286,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,73,32767,32767,32767,32767, +32767,103,32767,164,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +92,32767,32767,32767,32767,32767,221,272,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,25,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,311, +225,32767,207,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,295,32767,108,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,290,384,32767,32767,32767,32767, +32767,32767,32767,32767,80,32767,346,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,366,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,128,32767,32767, +32767,32767,32767,83,243,32767,32767,32767,270,32767,32767,118, +32767,32767,249,32767,32767,241,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,229,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,86,32767,32767,260,50,32767,32767,227,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,23,32767,32767,32767,32767,32767,32767,309,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +371,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,114,32767,32767,32767,32767,32767,32767, +365,13,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,352,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,178,289,32767,32767,32767,32767,32767,32767, +32767,32767,81,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,60,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,105,32767,32767,32767,32767,32767,32767,32767,32767,32767, +168,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,350,32767,32767,32767,32767, +276,32767,32767,32767,32767,32767,32767,32767,199,59,32767,32767, +32767,32767,32767,32767,32767,322,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,339,32767,32767,32767,32767, +32767,32767,32767,94,32767,32767,228,32767,32767,32767,32767,293, +32767,32767,32767,55,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,244,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,66,32767,32767,32767,32767,258,357,32767,32767,32767, +32767,8,32767,32767,32767,12,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,124,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +111,32767,32767,32767,32767,32767,63,32767,32767,32767,95,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,329,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,159,32767,32767,32767,32767, +215,32767,32767,274,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,85,32767,6,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,312,113,32767,32767,32767,78, +32767,323,18,32767,32767,32767,32767,32767,32767,369,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,90,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +325,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +210,32767,32767,32767,32767,32767,9,32767,32767,121,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,319,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,220,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,39,32767,32767, +271,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,234, +32767,32767,32767,367,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,363,0,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +204,177,32767,32767,32767,32767,32767,32767,32767,32767,148,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,284,252,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,222,32767,75,32767,32767,32767,32767,292, +32767,32767,32767,32767,32767,32767,172,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,360,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,138,32767,32767,380,32767,359,32767, +32767,32767,32767,32767,32767,79,32767,32767,32767,32767,248,32767, +32767,32767,32767,32767,32767,32767,147,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,327,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,299,32767,32767,32767,32767,72,32767,32767,32767, +32767,240,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +343,32767,32767,32767,32767,32767,137,32767,32767,32767,32767,32767, +32767,32767,32767,130,32767,32767,32767,32767,32767,32767,32767,131, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,57,32767,5,32767,32767,32767, +32767,32767,32767,291,32767,32767,32767,32767,32767,213,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,375,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,68, +32767,32767,32767,32767,64,32767,32767,32767,32767,32767,32767,171, +32767,32767,32767,49,32767,32767,32767,32767,32767,48,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,275,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,345,331,32767,32767,32767,32767,32767,157,32767,32767,32767, +32767,32767,32767,32767,32767,190,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,74,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +334,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,179,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,264, +32767,32767,32767,32767,32767,32767,32767,32767,32767,53,32767,32767, +32767,32767,32767,32767,209,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,245,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,61,32767, +52,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,186,32767,41,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +70,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,247,32767,32767,32767,32767,136,36,32767,32767,32767, +32767,32767,32767,32767,32767,32767,31,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,336,32767,32767,32767,265,191,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,127,32767,32767,32767,32767,32767,32767, +321,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,116,32767,32767,32767,32767,32767,32767,26,32767,32767, +32767,32767,32767,32767,32767,32767,269,32767,32767,32767,32767,32767, +100,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,183,34,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,372,32767,32767,32767,32767,32767, +308,32767,32767,285,32767,32767,32767,32767,377,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,257,32767,32767,32767,32767,32767,97,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,89,32767,32767,302,160, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,170, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,110, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,16,32767,214,71,32767,32767,32767, +32767,32767,32767,197,32767,32767,32767,32767,32767,32767,32767,17, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +237,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,187,32767,218,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,304,32767,32767,32767,32767,32767,32767,32767,32767,185,32767, +348,32767,32767,32767,231,32767,32767,32767,32767,32767,251,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, +32767,132,32767,32767,32767,32767,32767,32767,32767,115,32767,32767, +32767,29,32767,32767,32767,32767,32767,32767,32767,32767,32767,47, +32767,32767,32767,32767,32767 +}; + + +/* t1= 45205 t2=3702303 type= 0 */ + +inline SYMBOL *get_hash_symbol(const char *s,unsigned int length,bool function) +{ + ulong idx = 2003+char_table[(uchar) *s]; + SYMBOL *sim; + const char *start=s; + int i=unique_length[(uchar) *s++]; + if (i > (int) length) i=(int) length; + while (--i > 0) + idx= (idx ^ (char_table[(uchar) *s++] + (idx << 7))); + idx=my_function_table[(idx & 8388607) % 4133]; + if (idx >= 262) + { + if (!function || idx >= 32767) return (SYMBOL*) 0; + sim=sql_functions + (idx - 262); + } + else + sim=symbols + idx; + if ((length != sim->length) || lex_casecmp(start,sim->name,length)) + return (SYMBOL *)0; + return sim; +} diff --git a/sql/Attic/mini_client.c b/sql/Attic/mini_client.c new file mode 100644 index 00000000000..56a6de14742 --- /dev/null +++ b/sql/Attic/mini_client.c @@ -0,0 +1,783 @@ +/* Copyright Abandoned 1996 TCX DataKonsult AB & Monty Program KB & Detron HB + This file is public domain and comes with NO WARRANTY of any kind */ + +/* + mini MySQL client to be included into the server to do server to server + commincation by Sasha Pachev + + Note: all file-global symbols must begin with mc_ , even the static ones, just + in case we decide to make them external at some point + */ + +#define DONT_USE_RAID +#if defined(__WIN32__) || defined(WIN32) +#include <winsock.h> +#include <odbcinst.h> +#endif +#include <global.h> +#include <my_sys.h> +#include <mysys_err.h> +#include <m_string.h> +#include <m_ctype.h> +#include "mysql.h" +#include "mini_client.h" +#include "mysql_version.h" +#include "mysqld_error.h" +#include "errmsg.h" +#include <violite.h> +#include <sys/stat.h> +#include <signal.h> +#ifdef HAVE_PWD_H +#include <pwd.h> +#endif +#if !defined(MSDOS) && !defined(__WIN32__) +#include <sys/socket.h> +#include <netinet/in.h> +#include <arpa/inet.h> +#include <netdb.h> +#ifdef HAVE_SELECT_H +# include <select.h> +#endif +#ifdef HAVE_SYS_SELECT_H +#include <sys/select.h> +#endif +#endif +#ifdef HAVE_SYS_UN_H +# include <sys/un.h> +#endif +#if defined(THREAD) && !defined(__WIN32__) +#include <my_pthread.h> /* because of signal() */ +#endif +#ifndef INADDR_NONE +#define INADDR_NONE -1 +#endif + + +static void mc_end_server(MYSQL *mysql); +static int mc_sock_connect(File s, const struct sockaddr *name, uint namelen, uint to); +static void mc_free_old_query(MYSQL *mysql); + + +#define CLIENT_CAPABILITIES (CLIENT_LONG_PASSWORD | CLIENT_LONG_FLAG | CLIENT_LOCAL_FILES) + +#if defined(MSDOS) || defined(__WIN32__) +#define ERRNO WSAGetLastError() +#define perror(A) +#else +#include <sys/errno.h> +#define ERRNO errno +#define SOCKET_ERROR -1 +#define closesocket(A) close(A) +#endif + +#ifdef __WIN32__ +static my_bool is_NT(void) +{ + char *os=getenv("OS"); + return (os && !strcmp(os, "Windows_NT")) ? 1 : 0; +} +#endif + +/* +** Create a named pipe connection +*/ + +#ifdef __WIN32__ + +HANDLE create_named_pipe(NET *net, uint connect_timeout, char **arg_host, + char **arg_unix_socket) +{ + HANDLE hPipe=INVALID_HANDLE_VALUE; + char szPipeName [ 257 ]; + DWORD dwMode; + int i; + my_bool testing_named_pipes=0; + char *host= *arg_host, *unix_socket= *arg_unix_socket; + + if (!host || !strcmp(host,LOCAL_HOST)) + host=LOCAL_HOST_NAMEDPIPE; + + sprintf( szPipeName, "\\\\%s\\pipe\\%s", host, unix_socket); + DBUG_PRINT("info",("Server name: '%s'. Named Pipe: %s", + host, unix_socket)); + + for (i=0 ; i < 100 ; i++) /* Don't retry forever */ + { + if ((hPipe = CreateFile(szPipeName, + GENERIC_READ | GENERIC_WRITE, + 0, + NULL, + OPEN_EXISTING, + 0, + NULL )) != INVALID_HANDLE_VALUE) + break; + if (GetLastError() != ERROR_PIPE_BUSY) + { + net->last_errno=CR_NAMEDPIPEOPEN_ERROR; + sprintf(net->last_error,ER(net->last_errno),host, unix_socket, + (ulong) GetLastError()); + return INVALID_HANDLE_VALUE; + } + /* wait for for an other instance */ + if (! WaitNamedPipe(szPipeName, connect_timeout*1000) ) + { + net->last_errno=CR_NAMEDPIPEWAIT_ERROR; + sprintf(net->last_error,ER(net->last_errno),host, unix_socket, + (ulong) GetLastError()); + return INVALID_HANDLE_VALUE; + } + } + if (hPipe == INVALID_HANDLE_VALUE) + { + net->last_errno=CR_NAMEDPIPEOPEN_ERROR; + sprintf(net->last_error,ER(net->last_errno),host, unix_socket, + (ulong) GetLastError()); + return INVALID_HANDLE_VALUE; + } + dwMode = PIPE_READMODE_BYTE | PIPE_WAIT; + if ( !SetNamedPipeHandleState(hPipe, &dwMode, NULL, NULL) ) + { + CloseHandle( hPipe ); + net->last_errno=CR_NAMEDPIPESETSTATE_ERROR; + sprintf(net->last_error,ER(net->last_errno),host, unix_socket, + (ulong) GetLastError()); + return INVALID_HANDLE_VALUE; + } + *arg_host=host ; *arg_unix_socket=unix_socket; /* connect arg */ + return (hPipe); +} +#endif + + +/**************************************************************************** +** Init MySQL structure or allocate one +****************************************************************************/ + +MYSQL * STDCALL +mc_mysql_init(MYSQL *mysql) +{ + if (!mysql) + { + if (!(mysql=(MYSQL*) my_malloc(sizeof(*mysql),MYF(MY_WME | MY_ZEROFILL)))) + return 0; + mysql->free_me=1; + mysql->net.vio = 0; + } + else + bzero((char*) (mysql),sizeof(*(mysql))); +#ifdef __WIN32__ + mysql->options.connect_timeout=20; +#endif + return mysql; +} + +/************************************************************************** +** Shut down connection +**************************************************************************/ + +static void +mc_end_server(MYSQL *mysql) +{ + DBUG_ENTER("mc_end_server"); + if (mysql->net.vio != 0) + { + DBUG_PRINT("info",("Net: %s", vio_description(mysql->net.vio))); + vio_delete(mysql->net.vio); + mysql->net.vio= 0; /* Marker */ + } + net_end(&mysql->net); + mc_free_old_query(mysql); + DBUG_VOID_RETURN; +} + +static void mc_free_old_query(MYSQL *mysql) +{ + DBUG_ENTER("mc_free_old_query"); + if (mysql->fields) + free_root(&mysql->field_alloc); + init_alloc_root(&mysql->field_alloc,8192); /* Assume rowlength < 8192 */ + mysql->fields=0; + mysql->field_count=0; /* For API */ + DBUG_VOID_RETURN; +} + + +/**************************************************************************** +* A modified version of connect(). mc_sock_connect() allows you to specify +* a timeout value, in seconds, that we should wait until we +* derermine we can't connect to a particular host. If timeout is 0, +* mc_sock_connect() will behave exactly like connect(). +* +* Base version coded by Steve Bernacki, Jr. <steve@navinet.net> +*****************************************************************************/ + +static int mc_sock_connect(File s, const struct sockaddr *name, uint namelen, uint to) +{ +#if defined(__WIN32__) + return connect(s, (struct sockaddr*) name, namelen); +#else + int flags, res, s_err; + size_socket s_err_size = sizeof(uint); + fd_set sfds; + struct timeval tv; + + /* If they passed us a timeout of zero, we should behave + * exactly like the normal connect() call does. + */ + + if (to == 0) + return connect(s, (struct sockaddr*) name, namelen); + + flags = fcntl(s, F_GETFL, 0); /* Set socket to not block */ +#ifdef O_NONBLOCK + fcntl(s, F_SETFL, flags | O_NONBLOCK); /* and save the flags.. */ +#endif + + res = connect(s, (struct sockaddr*) name, namelen); + s_err = errno; /* Save the error... */ + fcntl(s, F_SETFL, flags); + if ((res != 0) && (s_err != EINPROGRESS)) + { + errno = s_err; /* Restore it */ + return(-1); + } + if (res == 0) /* Connected quickly! */ + return(0); + + /* Otherwise, our connection is "in progress." We can use + * the select() call to wait up to a specified period of time + * for the connection to suceed. If select() returns 0 + * (after waiting howevermany seconds), our socket never became + * writable (host is probably unreachable.) Otherwise, if + * select() returns 1, then one of two conditions exist: + * + * 1. An error occured. We use getsockopt() to check for this. + * 2. The connection was set up sucessfully: getsockopt() will + * return 0 as an error. + * + * Thanks goes to Andrew Gierth <andrew@erlenstar.demon.co.uk> + * who posted this method of timing out a connect() in + * comp.unix.programmer on August 15th, 1997. + */ + + FD_ZERO(&sfds); + FD_SET(s, &sfds); + tv.tv_sec = (long) to; + tv.tv_usec = 0; + res = select(s+1, NULL, &sfds, NULL, &tv); + if (res <= 0) /* Never became writable */ + return(-1); + + /* select() returned something more interesting than zero, let's + * see if we have any errors. If the next two statements pass, + * we've got an open socket! + */ + + s_err=0; + if (getsockopt(s, SOL_SOCKET, SO_ERROR, (char*) &s_err, &s_err_size) != 0) + return(-1); + + if (s_err) + { /* getsockopt() could suceed */ + errno = s_err; + return(-1); /* but return an error... */ + } + return(0); /* It's all good! */ +#endif +} + +/***************************************************************************** +** read a packet from server. Give error message if socket was down +** or packet is an error message +*****************************************************************************/ + +uint STDCALL +mc_net_safe_read(MYSQL *mysql) +{ + NET *net= &mysql->net; + uint len=0; + + if (net->vio != 0) + len=my_net_read(net); + + if (len == packet_error || len == 0) + { + DBUG_PRINT("error",("Wrong connection or packet. fd: %s len: %d", + vio_description(net->vio),len)); + if(errno != EINTR) + { + mc_end_server(mysql); + net->last_errno=CR_SERVER_LOST; + strmov(net->last_error,ER(net->last_errno)); + } + return(packet_error); + } + if (net->read_pos[0] == 255) + { + if (len > 3) + { + char *pos=(char*) net->read_pos+1; + if (mysql->protocol_version > 9) + { /* New client protocol */ + net->last_errno=uint2korr(pos); + pos+=2; + len-=2; + if(!net->last_errno) + net->last_errno = CR_UNKNOWN_ERROR; + } + else + { + net->last_errno=CR_UNKNOWN_ERROR; + len--; + } + (void) strmake(net->last_error,(char*) pos, + min(len,sizeof(net->last_error)-1)); + } + else + { + net->last_errno=CR_UNKNOWN_ERROR; + (void) strmov(net->last_error,ER(net->last_errno)); + } + DBUG_PRINT("error",("Got error: %d (%s)", net->last_errno, + net->last_error)); + return(packet_error); + } + return len; +} + + +char * STDCALL mc_mysql_error(MYSQL *mysql) +{ + return (mysql)->net.last_error; +} + +my_bool STDCALL mc_mysql_reconnect(MYSQL *mysql) +{ + MYSQL tmp_mysql; + DBUG_ENTER("mc_mysql_reconnect"); + + mc_mysql_init(&tmp_mysql); + tmp_mysql.options=mysql->options; + if (!mc_mysql_connect(&tmp_mysql,mysql->host,mysql->user,mysql->passwd, + mysql->db, mysql->port, mysql->unix_socket, + mysql->client_flag)) + DBUG_RETURN(1); + tmp_mysql.free_me=mysql->free_me; + mysql->free_me=0; + bzero((char*) &mysql->options,sizeof(&mysql->options)); + mc_mysql_close(mysql); + *mysql=tmp_mysql; + net_clear(&mysql->net); + mysql->affected_rows= ~(my_ulonglong) 0; + DBUG_RETURN(0); +} + + + +int STDCALL +mc_simple_command(MYSQL *mysql,enum enum_server_command command, const char *arg, + uint length, my_bool skipp_check) +{ + NET *net= &mysql->net; + int result= -1; + + if (mysql->net.vio == 0) + { /* Do reconnect if possible */ + if (mc_mysql_reconnect(mysql)) + { + net->last_errno=CR_SERVER_GONE_ERROR; + strmov(net->last_error,ER(net->last_errno)); + goto end; + } + } + if (mysql->status != MYSQL_STATUS_READY) + { + strmov(net->last_error,ER(mysql->net.last_errno=CR_COMMANDS_OUT_OF_SYNC)); + goto end; + } + + mysql->net.last_error[0]=0; + mysql->net.last_errno=0; + mysql->info=0; + mysql->affected_rows= ~(my_ulonglong) 0; + net_clear(net); /* Clear receive buffer */ + if (!arg) + arg=""; + + if (net_write_command(net,(uchar) command,arg, + length ? length :strlen(arg))) + { + DBUG_PRINT("error",("Can't send command to server. Error: %d",errno)); + mc_end_server(mysql); + if (mc_mysql_reconnect(mysql) || + net_write_command(net,(uchar) command,arg, + length ? length :strlen(arg))) + { + net->last_errno=CR_SERVER_GONE_ERROR; + strmov(net->last_error,ER(net->last_errno)); + goto end; + } + } + result=0; + if (!skipp_check) + result= ((mysql->packet_length=mc_net_safe_read(mysql)) == packet_error ? + -1 : 0); + end: + return result; +} + + +MYSQL * STDCALL +mc_mysql_connect(MYSQL *mysql,const char *host, const char *user, + const char *passwd, const char *db, + uint port, const char *unix_socket,uint client_flag) +{ + char buff[100],*end,*host_info; + int sock; + ulong ip_addr; + struct sockaddr_in sock_addr; + uint pkt_length; + NET *net= &mysql->net; +#ifdef __WIN32__ + HANDLE hPipe=INVALID_HANDLE_VALUE; +#endif +#ifdef HAVE_SYS_UN_H + struct sockaddr_un UNIXaddr; +#endif + DBUG_ENTER("mysql_real_connect"); + + DBUG_PRINT("enter",("host: %s db: %s user: %s", + host ? host : "(Null)", + db ? db : "(Null)", + user ? user : "(Null)")); + + bzero((char*) &mysql->options,sizeof(mysql->options)); + net->vio = 0; /* If something goes wrong */ + mysql->charset=default_charset_info; /* Set character set */ + if (!port) + port = MYSQL_PORT; /* Should always be set by mysqld */ + if (!unix_socket) + unix_socket=MYSQL_UNIX_ADDR; + + mysql->reconnect=1; /* Reconnect as default */ + + /* + ** Grab a socket and connect it to the server + */ + +#if defined(HAVE_SYS_UN_H) + if (!host || !strcmp(host,LOCAL_HOST)) + { + host=LOCAL_HOST; + host_info=(char*) ER(CR_LOCALHOST_CONNECTION); + DBUG_PRINT("info",("Using UNIX sock '%s'",unix_socket)); + if ((sock = socket(AF_UNIX,SOCK_STREAM,0)) == SOCKET_ERROR) + { + net->last_errno=CR_SOCKET_CREATE_ERROR; + sprintf(net->last_error,ER(net->last_errno),ERRNO); + goto error; + } + net->vio = vio_new(sock, VIO_TYPE_SOCKET, TRUE); + bzero((char*) &UNIXaddr,sizeof(UNIXaddr)); + UNIXaddr.sun_family = AF_UNIX; + strmov(UNIXaddr.sun_path, unix_socket); + if (mc_sock_connect(sock,(struct sockaddr *) &UNIXaddr, sizeof(UNIXaddr), + mysql->options.connect_timeout) <0) + { + DBUG_PRINT("error",("Got error %d on connect to local server",ERRNO)); + net->last_errno=CR_CONNECTION_ERROR; + sprintf(net->last_error,ER(net->last_errno),unix_socket,ERRNO); + goto error; + } + } + else +#elif defined(__WIN32__) + { + if ((unix_socket || + !host && is_NT() || + host && !strcmp(host,LOCAL_HOST_NAMEDPIPE) || + mysql->options.named_pipe || !have_tcpip)) + { + sock=0; + if ((hPipe=create_named_pipe(net, mysql->options.connect_timeout, + (char**) &host, (char**) &unix_socket)) == + INVALID_HANDLE_VALUE) + { + DBUG_PRINT("error", + ("host: '%s' socket: '%s' named_pipe: %d have_tcpip: %d", + host ? host : "<null>", + unix_socket ? unix_socket : "<null>", + (int) mysql->options.named_pipe, + (int) have_tcpip)); + if (mysql->options.named_pipe || + (host && !strcmp(host,LOCAL_HOST_NAMEDPIPE)) || + (unix_socket && !strcmp(unix_socket,MYSQL_NAMEDPIPE))) + goto error; /* User only requested named pipes */ + /* Try also with TCP/IP */ + } + else + { + net->vio=vio_new_win32pipe(hPipe); + sprintf(host_info=buff, ER(CR_NAMEDPIPE_CONNECTION), host, + unix_socket); + } + } + } + if (hPipe == INVALID_HANDLE_VALUE) +#endif + { + unix_socket=0; /* This is not used */ + if (!host) + host=LOCAL_HOST; + sprintf(host_info=buff,ER(CR_TCP_CONNECTION),host); + DBUG_PRINT("info",("Server name: '%s'. TCP sock: %d", host,port)); + if ((sock = socket(AF_INET,SOCK_STREAM,0)) == SOCKET_ERROR) + { + net->last_errno=CR_IPSOCK_ERROR; + sprintf(net->last_error,ER(net->last_errno),ERRNO); + goto error; + } + net->vio = vio_new(sock,VIO_TYPE_TCPIP,FALSE); + bzero((char*) &sock_addr,sizeof(sock_addr)); + sock_addr.sin_family = AF_INET; + + /* + ** The server name may be a host name or IP address + */ + + if ((int) (ip_addr = inet_addr(host)) != (int) INADDR_NONE) + { + memcpy_fixed(&sock_addr.sin_addr,&ip_addr,sizeof(ip_addr)); + } + else +#if defined(HAVE_GETHOSTBYNAME_R) && defined(_REENTRANT) && defined(THREAD) + { + int tmp_errno; + struct hostent tmp_hostent,*hp; + char buff2[GETHOSTBYNAME_BUFF_SIZE]; + hp = my_gethostbyname_r(host,&tmp_hostent,buff2,sizeof(buff2), + &tmp_errno); + if (!hp) + { + net->last_errno=CR_UNKNOWN_HOST; + sprintf(net->last_error, ER(CR_UNKNOWN_HOST), host, tmp_errno); + goto error; + } + memcpy(&sock_addr.sin_addr,hp->h_addr, (size_t) hp->h_length); + } +#else + { + struct hostent *hp; + if (!(hp=gethostbyname(host))) + { + net->last_errno=CR_UNKNOWN_HOST; + sprintf(net->last_error, ER(CR_UNKNOWN_HOST), host, errno); + goto error; + } + memcpy(&sock_addr.sin_addr,hp->h_addr, (size_t) hp->h_length); + } +#endif + sock_addr.sin_port = (ushort) htons((ushort) port); + if (mc_sock_connect(sock,(struct sockaddr *) &sock_addr, sizeof(sock_addr), + mysql->options.connect_timeout) <0) + { + DBUG_PRINT("error",("Got error %d on connect to '%s'",ERRNO,host)); + net->last_errno= CR_CONN_HOST_ERROR; + sprintf(net->last_error ,ER(CR_CONN_HOST_ERROR), host, ERRNO); + goto error; + } + } + + if (!net->vio || my_net_init(net, net->vio)) + { + vio_delete(net->vio); + net->last_errno=CR_OUT_OF_MEMORY; + strmov(net->last_error,ER(net->last_errno)); + goto error; + } + vio_keepalive(net->vio,TRUE); + + /* Get version info */ + mysql->protocol_version= PROTOCOL_VERSION; /* Assume this */ + if ((pkt_length=mc_net_safe_read(mysql)) == packet_error) + goto error; + + /* Check if version of protocoll matches current one */ + + mysql->protocol_version= net->read_pos[0]; + DBUG_DUMP("packet",(char*) net->read_pos,10); + DBUG_PRINT("info",("mysql protocol version %d, server=%d", + PROTOCOL_VERSION, mysql->protocol_version)); + if (mysql->protocol_version != PROTOCOL_VERSION && + mysql->protocol_version != PROTOCOL_VERSION-1) + { + net->last_errno= CR_VERSION_ERROR; + sprintf(net->last_error, ER(CR_VERSION_ERROR), mysql->protocol_version, + PROTOCOL_VERSION); + goto error; + } + end=strend((char*) net->read_pos+1); + mysql->thread_id=uint4korr(end+1); + end+=5; + strmake(mysql->scramble_buff,end,8); + if (pkt_length > (uint) (end+9 - (char*) net->read_pos)) + mysql->server_capabilities=uint2korr(end+9); + + /* Save connection information */ + if (!user) user=""; + if (!passwd) passwd=""; + if (!my_multi_malloc(MYF(0), + &mysql->host_info,strlen(host_info)+1, + &mysql->host,strlen(host)+1, + &mysql->unix_socket,unix_socket ? strlen(unix_socket)+1 + :1, + &mysql->server_version, + (uint) (end - (char*) net->read_pos), + NullS) || + !(mysql->user=my_strdup(user,MYF(0))) || + !(mysql->passwd=my_strdup(passwd,MYF(0)))) + { + strmov(net->last_error, ER(net->last_errno=CR_OUT_OF_MEMORY)); + goto error; + } + strmov(mysql->host_info,host_info); + strmov(mysql->host,host); + if (unix_socket) + strmov(mysql->unix_socket,unix_socket); + else + mysql->unix_socket=0; + strmov(mysql->server_version,(char*) net->read_pos+1); + mysql->port=port; + mysql->client_flag=client_flag | mysql->options.client_flag; + DBUG_PRINT("info",("Server version = '%s' capabilites: %ld", + mysql->server_version,mysql->server_capabilities)); + + /* Send client information for access check */ + client_flag|=CLIENT_CAPABILITIES; + +#ifdef HAVE_OPENSSL + if (mysql->options.use_ssl) + client_flag|=CLIENT_SSL; +#endif /* HAVE_OPENSSL */ + + if (db) + client_flag|=CLIENT_CONNECT_WITH_DB; +#ifdef HAVE_COMPRESS + if (mysql->server_capabilities & CLIENT_COMPRESS && + (mysql->options.compress || client_flag & CLIENT_COMPRESS)) + client_flag|=CLIENT_COMPRESS; /* We will use compression */ + else +#endif + client_flag&= ~CLIENT_COMPRESS; + +#ifdef HAVE_OPENSSL + if ((mysql->server_capabilities & CLIENT_SSL) && + (mysql->options.use_ssl || (client_flag & CLIENT_SSL))) + { + DBUG_PRINT("info", ("Changing IO layer to SSL")); + client_flag |= CLIENT_SSL; + } + else + { + if (client_flag & CLIENT_SSL) + { + DBUG_PRINT("info", ("Leaving IO layer intact because server doesn't support SSL")); + } + client_flag &= ~CLIENT_SSL; + } +#endif /* HAVE_OPENSSL */ + + int2store(buff,client_flag); + mysql->client_flag=client_flag; + +#ifdef HAVE_OPENSSL + /* Oops.. are we careful enough to not send ANY information */ + /* without encryption? */ + if (client_flag & CLIENT_SSL) + { + if (my_net_write(net,buff,(uint) (2)) || net_flush(net)) + goto error; + /* Do the SSL layering. */ + DBUG_PRINT("info", ("IO layer change in progress...")); + VioSSLConnectorFd* connector_fd = (VioSSLConnectorFd*) + (mysql->connector_fd); + VioSocket* vio_socket = (VioSocket*)(mysql->net.vio); + VioSSL* vio_ssl = connector_fd->connect(vio_socket); + mysql->net.vio = (NetVio*)(vio_ssl); + } +#endif /* HAVE_OPENSSL */ + + int3store(buff+2,max_allowed_packet); + if (user && user[0]) + strmake(buff+5,user,32); + else + { + user = getenv("USER"); + if(!user) user = "mysql"; + strmov((char*) buff+5, user ); + } + + DBUG_PRINT("info",("user: %s",buff+5)); + end=scramble(strend(buff+5)+1, mysql->scramble_buff, passwd, + (my_bool) (mysql->protocol_version == 9)); + if (db) + { + end=strmov(end+1,db); + mysql->db=my_strdup(db,MYF(MY_WME)); + } + if (my_net_write(net,buff,(uint) (end-buff)) || net_flush(net) || + mc_net_safe_read(mysql) == packet_error) + goto error; + if (client_flag & CLIENT_COMPRESS) /* We will use compression */ + net->compress=1; + DBUG_PRINT("exit",("Mysql handler: %lx",mysql)); + DBUG_RETURN(mysql); + +error: + DBUG_PRINT("error",("message: %u (%s)",net->last_errno,net->last_error)); + { + /* Free alloced memory */ + my_bool free_me=mysql->free_me; + mc_end_server(mysql); + mysql->free_me=0; + mc_mysql_close(mysql); + mysql->free_me=free_me; + } + DBUG_RETURN(0); +} + +/************************************************************************* +** Send a QUIT to the server and close the connection +** If handle is alloced by mysql connect free it. +*************************************************************************/ + +void STDCALL +mc_mysql_close(MYSQL *mysql) +{ + DBUG_ENTER("mysql_close"); + if (mysql) /* Some simple safety */ + { + if (mysql->net.vio != 0) + { + mc_free_old_query(mysql); + mysql->status=MYSQL_STATUS_READY; /* Force command */ + mc_simple_command(mysql,COM_QUIT,NullS,0,1); + mc_end_server(mysql); + } + my_free((gptr) mysql->host_info,MYF(MY_ALLOW_ZERO_PTR)); + my_free(mysql->user,MYF(MY_ALLOW_ZERO_PTR)); + my_free(mysql->passwd,MYF(MY_ALLOW_ZERO_PTR)); + my_free(mysql->db,MYF(MY_ALLOW_ZERO_PTR)); + /* Clear pointers for better safety */ + mysql->host_info=mysql->user=mysql->passwd=mysql->db=0; + bzero((char*) &mysql->options,sizeof(mysql->options)); + mysql->net.vio = 0; +#ifdef HAVE_OPENSSL + ((VioConnectorFd*)(mysql->connector_fd))->delete(); + mysql->connector_fd = 0; +#endif /* HAVE_OPENSSL */ + if (mysql->free_me) + my_free((gptr) mysql,MYF(0)); + } + DBUG_VOID_RETURN; +} diff --git a/sql/Attic/mini_client_errors.c b/sql/Attic/mini_client_errors.c new file mode 100644 index 00000000000..96f1f415544 --- /dev/null +++ b/sql/Attic/mini_client_errors.c @@ -0,0 +1,64 @@ +/* Copyright Abandoned 1997 TCX DataKonsult AB & Monty Program KB & Detron HB + This file is public domain and comes with NO WARRANTY of any kind */ + +/* Error messages for MySQL clients */ +/* error messages for the demon is in share/language/errmsg.sys */ + +#include <global.h> +#include <my_sys.h> +#include "errmsg.h" + +#ifdef GERMAN +const char *client_errors[]= +{ + "Unbekannter MySQL Fehler", + "Kann UNIX-Socket nicht anlegen (%d)", + "Keine Verbindung zu lokalem MySQL Server, socket: '%-.64s' (%d)", + "Keine Verbindung zu MySQL Server auf %-.64s (%d)", + "Kann TCP/IP-Socket nicht anlegen (%d)", + "Unbekannter MySQL Server Host (%-.64s) (%d)", + "MySQL Server nicht vorhanden", + "Protokolle ungleich. Server Version = % d Client Version = %d", + "MySQL client got out of memory", + "Wrong host info", + "Localhost via UNIX socket", + "%s via TCP/IP", + "Error in server handshake", + "Lost connection to MySQL server during query", + "Commands out of sync; You can't run this command now", + "Verbindung ueber Named Pipe; Host: %-.64s", + "Kann nicht auf Named Pipe warten. Host: %-.64s pipe: %-.32s (%lu)", + "Kann Named Pipe nicht oeffnen. Host: %-.64s pipe: %-.32s (%lu)", + "Kann den Status der Named Pipe nicht setzen. Host: %-.64s pipe: %-.32s (%lu)" +}; + +#else /* ENGLISH */ +const char *client_errors[]= +{ + "Unknown MySQL error", + "Can't create UNIX socket (%d)", + "Can't connect to local MySQL server through socket '%-.64s' (%d)", + "Can't connect to MySQL server on '%-.64s' (%d)", + "Can't create TCP/IP socket (%d)", + "Unknown MySQL Server Host '%-.64s' (%d)", + "MySQL server has gone away", + "Protocol mismatch. Server Version = %d Client Version = %d", + "MySQL client run out of memory", + "Wrong host info", + "Localhost via UNIX socket", + "%s via TCP/IP", + "Error in server handshake", + "Lost connection to MySQL server during query", + "Commands out of sync; You can't run this command now", + "%s via named pipe", + "Can't wait for named pipe to host: %-.64s pipe: %-.32s (%lu)", + "Can't open named pipe to host: %-.64s pipe: %-.32s (%lu)", + "Can't set state of named pipe to host: %-.64s pipe: %-.32s (%lu)", +}; +#endif + + +void init_client_errs(void) +{ + errmsg[CLIENT_ERRMAP] = &client_errors[0]; +} diff --git a/sql/Attic/mybinlogdump.cc b/sql/Attic/mybinlogdump.cc new file mode 100644 index 00000000000..b94943c9847 --- /dev/null +++ b/sql/Attic/mybinlogdump.cc @@ -0,0 +1,138 @@ + +#undef MYSQL_SERVER +#include "log_event.h" +#include <getopt.h> +#include <config.h> + +static const char* default_dbug_option = "d:t:o,/tmp/mybinlogdump.trace"; + +static struct option long_options[] = +{ + {"short-form", no_argument, 0, 's'}, + {"offset", required_argument,0, 'o'}, + {"help", no_argument, 0, 'h'}, +#ifndef DBUG_OFF + {"debug", required_argument, 0, '#'} +#endif +}; + +static bool short_form = 0; +static int offset = 0; + +static int parse_args(int argc, char** argv); +static void dump_log_entries(); +static void die(char* fmt, ...); + +static void die(char* fmt, ...) +{ + va_list args; + va_start(args, fmt); + fprintf(stderr, "ERROR: "); + vfprintf(stderr, fmt, args); + fprintf(stderr, "\n"); + va_end(args); + exit(1); +} + +static void usage() +{ + fprintf(stderr, "Usage: mybinlogdump [options] log-files\n"); + fprintf(stderr, "Options:\n\ + -s,--short-form - just show the queries, no extra info\n\ + -o,--offset=N - skip the first N entries\n\ + -h,--help - this message\n"); +} + +static int parse_args(int *argc, char*** argv) +{ + int c, opt_index = 0; + + while((c = getopt_long(*argc, *argv, "so:#:h", long_options, + &opt_index)) != EOF) + { + switch(c) + { +#ifndef DBUG_OFF + case '#': + DBUG_PUSH(optarg ? optarg : default_dbug_option); + break; +#endif + case 's': + short_form = 1; + break; + + case 'o': + offset = atoi(optarg); + break; + + case 'h': + default: + usage(); + exit(0); + + } + } + + (*argc)-=optind; + (*argv)+=optind; + + + return 0; +} + + +static void dump_log_entries(const char* logname) +{ + FILE* file; + int rec_count = 0; + + if(logname && logname[0] != '-') + file = my_fopen(logname, O_RDONLY, MYF(MY_WME)); + else + file = stdin; + + if(!file) + die("Could not open log file %s", logname); + while(1) + { + Log_event* ev = Log_event::read_log_event(file); + if(!ev) + if(!feof(file)) + die("Could not read entry at offset %ld : Error in log format or \ +read error", + my_ftell(file, MYF(MY_WME))); + else + break; + + if(rec_count >= offset) + ev->print(stdout, short_form); + rec_count++; + delete ev; + } + + my_fclose(file, MYF(MY_WME)); +} + +int main(int argc, char** argv) +{ + MY_INIT(argv[0]); + parse_args(&argc, (char***)&argv); + + if(!argc) + { + usage(); + return -1; + } + + while(--argc >= 0) + { + dump_log_entries(*(argv++)); + } + + return 0; +} + + + + + diff --git a/sql/Attic/net_serv.c b/sql/Attic/net_serv.c new file mode 100644 index 00000000000..8f5ba20664a --- /dev/null +++ b/sql/Attic/net_serv.c @@ -0,0 +1,616 @@ +/* Copyright Abandoned 1996 TCX DataKonsult AB & Monty Program KB & Detron HB + This file is public domain and comes with NO WARRANTY of any kind */ + +/* Write and read of logical packets to/from socket +** Writes are cached into net_buffer_length big packets. +** Read packets are reallocated dynamicly when reading big packets. +** Each logical packet has the following pre-info: +** 3 byte length & 1 byte package-number. +*/ + +#ifdef _WIN32 +#include <winsock.h> +#endif +#include <global.h> +#include <violite.h> +#include <my_sys.h> +#include <m_string.h> +#include "mysql.h" +#include <signal.h> +#include <errno.h> +#include <sys/types.h> +#include <violite.h> + +#if !defined(__WIN32__) && !defined(MSDOS) +#include <sys/socket.h> +#endif +#if !defined(MSDOS) && !defined(__WIN32__) && !defined(HAVE_BROKEN_NETINET_INCLUDES) && !defined(__BEOS__) +#include <netinet/in_systm.h> +#include <netinet/in.h> +#include <netinet/ip.h> +#if !defined(alpha_linux_port) +#include <netinet/tcp.h> +#endif +#endif +#include "mysqld_error.h" +#ifdef MYSQL_SERVER +#include "my_pthread.h" +#include "thr_alarm.h" +void sql_print_error(const char *format,...); +#define RETRY_COUNT mysqld_net_retry_count +extern ulong mysqld_net_retry_count; +#else +typedef my_bool thr_alarm_t; +#define thr_alarm_init(A) (*A)=0 +#define thr_alarm_in_use(A) (A) +#define thr_end_alarm(A) +#define thr_alarm(A,B) local_thr_alarm((A),(B)) +static inline int local_thr_alarm(my_bool *A,int B __attribute__((unused))) +{ + *A=1; + return 0; +} +#define thr_got_alarm(A) 0 +#define RETRY_COUNT 1 +#endif + +#ifdef MYSQL_SERVER +extern ulong bytes_sent, bytes_received; +extern pthread_mutex_t LOCK_bytes_sent , LOCK_bytes_received; +#else +#undef thread_safe_add +#define thread_safe_add(A,B,C) +#endif + +/* +** Give error if a too big packet is found +** The server can change this with the -O switch, but because the client +** can't normally do this the client should have a bigger max-buffer. +*/ + +#ifdef MYSQL_SERVER +ulong max_allowed_packet=65536; +extern uint test_flags; +#else +ulong max_allowed_packet=16*1024*1024L; +#endif +ulong net_buffer_length=8192; /* Default length. Enlarged if necessary */ + +#define TEST_BLOCKING 8 +static int net_write_buff(NET *net,const char *packet,uint len); + + + /* Init with packet info */ + +int my_net_init(NET *net, Vio* vio) +{ + if (!(net->buff=(uchar*) my_malloc(net_buffer_length,MYF(MY_WME)))) + return 1; + if (net_buffer_length > max_allowed_packet) + max_allowed_packet=net_buffer_length; + net->buff_end=net->buff+(net->max_packet=net_buffer_length); + net->vio = vio; + net->error=net->return_errno=0; + net->timeout=NET_READ_TIMEOUT; /* Timeout for read */ + net->pkt_nr=0; + net->write_pos=net->read_pos = net->buff; + net->last_error[0]=0; + net->compress=0; net->reading_or_writing=0; + net->where_b = net->remain_in_buf=0; + net->last_errno=0; + + if (vio != 0) /* If real connection */ + { + net->fd = vio_fd(vio); /* For perl DBI/DBD */ +#if defined(MYSQL_SERVER) && !defined(___WIN32__) && !defined(__EMX__) + if (!(test_flags & TEST_BLOCKING)) + vio_blocking(vio, FALSE); +#endif + vio_fastsend(vio,TRUE); + } + return 0; +} + +void net_end(NET *net) +{ + my_free((gptr) net->buff,MYF(MY_ALLOW_ZERO_PTR)); + net->buff=0; +} + +/* Realloc the packet buffer */ + +static my_bool net_realloc(NET *net, ulong length) +{ + uchar *buff; + ulong pkt_length; + if (length >= max_allowed_packet) + { + DBUG_PRINT("error",("Packet too large (%ld)", length)); +#ifdef MYSQL_SERVER + sql_print_error("Packet too large (%ld)\n", length); +#else + fprintf(stderr,"Packet too large (%ld)\n", length); +#endif + net->error=1; +#ifdef MYSQL_SERVER + net->last_errno=ER_NET_PACKET_TOO_LARGE; +#endif + return 1; + } + pkt_length = (length+IO_SIZE-1) & ~(IO_SIZE-1); + if (!(buff=(uchar*) my_realloc((char*) net->buff, pkt_length, MYF(MY_WME)))) + { + net->error=1; +#ifdef MYSQL_SERVER + net->last_errno=ER_OUT_OF_RESOURCES; +#endif + return 1; + } + net->buff=net->write_pos=buff; + net->buff_end=buff+(net->max_packet=pkt_length); + return 0; +} + + /* Remove unwanted characters from connection */ + +void net_clear(NET *net) +{ +#ifndef EXTRA_DEBUG + int count; + bool is_blocking=vio_is_blocking(net->vio); + if (is_blocking) + vio_blocking(net->vio, FALSE); + if (!vio_is_blocking(net->vio)) /* Safety if SSL */ + { + while ( (count = vio_read(net->vio, (char*) (net->buff), + net->max_packet)) > 0) + DBUG_PRINT("info",("skipped %d bytes from file: %s", + count,vio_description(net->vio))); + if (is_blocking) + vio_blocking(net->vio, TRUE); + } +#endif /* EXTRA_DEBUG */ + net->pkt_nr=0; /* Ready for new command */ + net->write_pos=net->buff; +} + + /* Flush write_buffer if not empty. */ + +int net_flush(NET *net) +{ + int error=0; + DBUG_ENTER("net_flush"); + if (net->buff != net->write_pos) + { + error=net_real_write(net,(char*) net->buff, + (uint) (net->write_pos - net->buff)); + net->write_pos=net->buff; + } + DBUG_RETURN(error); +} + + +/***************************************************************************** +** Write something to server/client buffer +*****************************************************************************/ + + +/* +** Write a logical packet with packet header +** Format: Packet length (3 bytes), packet number(1 byte) +** When compression is used a 3 byte compression length is added +** NOTE: If compression is used the original package is destroyed! +*/ + +int +my_net_write(NET *net,const char *packet,ulong len) +{ + uchar buff[NET_HEADER_SIZE]; + int3store(buff,len); + buff[3]= (net->compress) ? 0 : (uchar) (net->pkt_nr++); + if (net_write_buff(net,(char*) buff,NET_HEADER_SIZE)) + return 1; + return net_write_buff(net,packet,len); +} + +int +net_write_command(NET *net,uchar command,const char *packet,ulong len) +{ + uchar buff[NET_HEADER_SIZE+1]; + uint length=len+1; /* 1 extra byte for command */ + + int3store(buff,length); + buff[3]= (net->compress) ? 0 : (uchar) (net->pkt_nr++); + buff[4]=command; + if (net_write_buff(net,(char*) buff,5)) + return 1; + return test(net_write_buff(net,packet,len) || net_flush(net)); +} + + +static int +net_write_buff(NET *net,const char *packet,uint len) +{ + uint left_length=(uint) (net->buff_end - net->write_pos); + + while (len > left_length) + { + memcpy((char*) net->write_pos,packet,left_length); + if (net_real_write(net,(char*) net->buff,net->max_packet)) + return 1; + net->write_pos=net->buff; + packet+=left_length; + len-=left_length; + left_length=net->max_packet; + } + memcpy((char*) net->write_pos,packet,len); + net->write_pos+=len; + return 0; +} + +/* Read and write using timeouts */ + +int +net_real_write(NET *net,const char *packet,ulong len) +{ + int length; + char *pos,*end; + thr_alarm_t alarmed; + uint retry_count=0; + my_bool net_blocking = vio_is_blocking(net->vio); + DBUG_ENTER("net_real_write"); + + net->reading_or_writing=2; +#ifdef HAVE_COMPRESS + if (net->compress) + { + ulong complen; + uchar *b; + uint header_length=NET_HEADER_SIZE+COMP_HEADER_SIZE; + if (!(b=(uchar*) my_malloc(len + NET_HEADER_SIZE + COMP_HEADER_SIZE, + MYF(MY_WME)))) + { +#ifdef MYSQL_SERVER + net->last_errno=ER_OUT_OF_RESOURCES; + net->error=1; +#endif + net->reading_or_writing=0; + DBUG_RETURN(1); + } + memcpy(b+header_length,packet,len); + + if (my_compress((byte*) b+header_length,&len,&complen)) + { + DBUG_PRINT("warning", + ("Compression error; Continuing without compression")); + complen=0; + } + int3store(&b[NET_HEADER_SIZE],complen); + int3store(b,len); + b[3]=(uchar) (net->pkt_nr++); + len+= header_length; + packet= (char*) b; + } +#endif /* HAVE_COMPRESS */ + + /* DBUG_DUMP("net",packet,len); */ +#ifdef MYSQL_SERVER + thr_alarm_init(&alarmed); + if (net_blocking) + thr_alarm(&alarmed,NET_WRITE_TIMEOUT); +#else + alarmed=0; +#endif /* MYSQL_SERVER */ + + pos=(char*) packet; end=pos+len; + while (pos != end) + { + if ((int) (length=vio_write(net->vio,pos,(size_t) (end-pos))) <= 0) + { + my_bool interrupted = vio_should_retry(net->vio); +#if (!defined(__WIN32__) && !defined(__EMX__)) + if ((interrupted || length==0) && !thr_alarm_in_use(alarmed)) + { + if (!thr_alarm(&alarmed,NET_WRITE_TIMEOUT)) + { /* Always true for client */ + if (!vio_is_blocking(net->vio)) + { + while (vio_blocking(net->vio, TRUE) < 0) + { + if (vio_should_retry(net->vio) && retry_count++ < RETRY_COUNT) + continue; +#ifdef EXTRA_DEBUG + fprintf(stderr, + "%s: my_net_write: fcntl returned error %d, aborting thread\n", + my_progname,vio_errno(net->vio)); +#endif /* EXTRA_DEBUG */ + net->error=1; /* Close socket */ + goto end; + } + } + retry_count=0; + continue; + } + } + else +#endif /* (!defined(__WIN32__) && !defined(__EMX__)) */ + if (thr_alarm_in_use(alarmed) && !thr_got_alarm(alarmed) && + interrupted) + { + if (retry_count++ < RETRY_COUNT) + continue; +#ifdef EXTRA_DEBUG + fprintf(stderr, "%s: write looped, aborting thread\n", + my_progname); +#endif /* EXTRA_DEBUG */ + } +#if defined(THREAD_SAFE_CLIENT) && !defined(MYSQL_SERVER) + if (vio_errno(net->vio) == EINTR) + { + DBUG_PRINT("warning",("Interrupted write. Retrying...")); + continue; + } +#endif /* defined(THREAD_SAFE_CLIENT) && !defined(MYSQL_SERVER) */ + net->error=1; /* Close socket */ +#ifdef MYSQL_SERVER + net->last_errno= (interrupted ? ER_NET_WRITE_INTERRUPTED : + ER_NET_ERROR_ON_WRITE); +#endif /* MYSQL_SERVER */ + break; + } + pos+=length; + thread_safe_add(bytes_sent,length,&LOCK_bytes_sent); + } +#ifndef __WIN32__ + end: +#endif +#ifdef HAVE_COMPRESS + if (net->compress) + my_free((char*) packet,MYF(0)); +#endif + if (thr_alarm_in_use(alarmed)) + { + thr_end_alarm(&alarmed); + vio_blocking(net->vio, net_blocking); + } + net->reading_or_writing=0; + DBUG_RETURN(((int) (pos != end))); +} + + +/***************************************************************************** +** Read something from server/clinet +*****************************************************************************/ + + +static uint +my_real_read(NET *net, ulong *complen) +{ + uchar *pos; + long length; + uint i,retry_count=0; + ulong len=packet_error; + thr_alarm_t alarmed; + my_bool net_blocking=vio_is_blocking(net->vio); + ulong remain= (net->compress ? NET_HEADER_SIZE+COMP_HEADER_SIZE : + NET_HEADER_SIZE); + *complen = 0; + + net->reading_or_writing=1; + thr_alarm_init(&alarmed); +#ifdef MYSQL_SERVER + if (net_blocking) + thr_alarm(&alarmed,net->timeout); +#endif /* MYSQL_SERVER */ + + pos = net->buff + net->where_b; /* net->packet -4 */ + for (i=0 ; i < 2 ; i++) + { + while (remain > 0) + { + /* First read is done with non blocking mode */ + if ((int) (length=vio_read(net->vio,(char*) pos,remain)) <= 0L) + { + my_bool interrupted = vio_should_retry(net->vio); + + DBUG_PRINT("info",("vio_read returned %d, errno: %d", + length, vio_errno(net->vio))); +#if (!defined(__WIN32__) && !defined(__EMX__)) || !defined(MYSQL_SERVER) + /* + We got an error that there was no data on the socket. We now set up + an alarm to not 'read forever', change the socket to non blocking + mode and try again + */ + if ((interrupted || length == 0) && !thr_alarm_in_use(alarmed)) + { + if (!thr_alarm(&alarmed,net->timeout)) /* Don't wait too long */ + { + if (!vio_is_blocking(net->vio)) + { + while (vio_blocking(net->vio,TRUE) < 0) + { + if (vio_should_retry(net->vio) && + retry_count++ < RETRY_COUNT) + continue; + DBUG_PRINT("error", + ("fcntl returned error %d, aborting thread", + vio_errno(net->vio))); +#ifdef EXTRA_DEBUG + fprintf(stderr, + "%s: read: fcntl returned error %d, aborting thread\n", + my_progname,vio_errno(net->vio)); +#endif /* EXTRA_DEBUG */ + len= packet_error; + net->error=1; /* Close socket */ +#ifdef MYSQL_SERVER + net->last_errno=ER_NET_FCNTL_ERROR; +#endif + goto end; + } + } + retry_count=0; + continue; + } + } +#endif /* (!defined(__WIN32__) && !defined(__EMX__)) || !defined(MYSQL_SERVER) */ + if (thr_alarm_in_use(alarmed) && !thr_got_alarm(alarmed) && + interrupted) + { /* Probably in MIT threads */ + if (retry_count++ < RETRY_COUNT) + continue; +#ifdef EXTRA_DEBUG + fprintf(stderr, "%s: read looped with error %d, aborting thread\n", + my_progname,vio_errno(net->vio)); +#endif /* EXTRA_DEBUG */ + } +#if defined(THREAD_SAFE_CLIENT) && !defined(MYSQL_SERVER) + if (vio_should_retry(net->vio)) + { + DBUG_PRINT("warning",("Interrupted read. Retrying...")); + continue; + } +#endif + DBUG_PRINT("error",("Couldn't read packet: remain: %d errno: %d length: %d alarmed: %d", remain,vio_errno(net->vio),length,alarmed)); + len= packet_error; + net->error=1; /* Close socket */ +#ifdef MYSQL_SERVER + net->last_errno= (interrupted ? ER_NET_READ_INTERRUPTED : + ER_NET_READ_ERROR); +#endif + goto end; + } + remain -= (ulong) length; + pos+= (ulong) length; + thread_safe_add(bytes_received,(ulong) length,&LOCK_bytes_received); + } + if (i == 0) + { /* First parts is packet length */ + ulong helping; + if (net->buff[net->where_b + 3] != (uchar) net->pkt_nr) + { + if (net->buff[net->where_b] != (uchar) 255) + { + DBUG_PRINT("error", + ("Packets out of order (Found: %d, expected %d)", + (int) net->buff[net->where_b + 3], + (uint) (uchar) net->pkt_nr)); +#ifdef EXTRA_DEBUG + fprintf(stderr,"Packets out of order (Found: %d, expected %d)\n", + (int) net->buff[net->where_b + 3], + (uint) (uchar) net->pkt_nr); +#endif + } + len= packet_error; +#ifdef MYSQL_SERVER + net->last_errno=ER_NET_PACKETS_OUT_OF_ORDER; +#endif + goto end; + } + net->pkt_nr++; +#ifdef HAVE_COMPRESS + if (net->compress) + { + /* complen is > 0 if package is really compressed */ + *complen=uint3korr(&(net->buff[net->where_b + NET_HEADER_SIZE])); + } +#endif + + len=uint3korr(net->buff+net->where_b); + helping = max(len,*complen) + net->where_b; + /* The necessary size of net->buff */ + if (helping >= net->max_packet) + { + /* We must allocate one extra byte for the end null */ + if (net_realloc(net,helping+1)) + { + len= packet_error; /* Return error */ + goto end; + } + } + pos=net->buff + net->where_b; + remain = len; + } + } + +end: + if (thr_alarm_in_use(alarmed)) + { + thr_end_alarm(&alarmed); + vio_blocking(net->vio, net_blocking); + } + net->reading_or_writing=0; + return(len); +} + + +uint +my_net_read(NET *net) +{ + ulong len,complen; + +#ifdef HAVE_COMPRESS + if (!net->compress) + { +#endif + len = my_real_read (net,&complen); + net->read_pos = net->buff + net->where_b; + if (len != packet_error) + net->read_pos[len]=0; /* Safeguard for mysql_use_result */ + return len; +#ifdef HAVE_COMPRESS + } + if (net->remain_in_buf) + net->buff[net->buf_length - net->remain_in_buf]=net->save_char; + for (;;) + { + if (net->remain_in_buf) + { + uchar *pos = net->buff + net->buf_length - net->remain_in_buf; + if (net->remain_in_buf >= 4) + { + net->length = uint3korr(pos); + if (net->length <= net->remain_in_buf - 4) + { + /* We have a full packet */ + len=net->length; + net->remain_in_buf -= net->length + 4; + net->read_pos=pos + 4; + break; /* We have a full packet */ + } + } + /* Move data down to read next data packet after current one */ + if (net->buf_length != net->remain_in_buf) + { + memmove(net->buff,pos,net->remain_in_buf); + net->buf_length=net->remain_in_buf; + } + net->where_b=net->buf_length; + } + else + { + net->where_b=0; + net->buf_length=0; + } + + if ((len = my_real_read(net,&complen)) == packet_error) + break; + if (my_uncompress((byte*) net->buff + net->where_b, &len, &complen)) + { + len= packet_error; + net->error=1; /* caller will close socket */ +#ifdef MYSQL_SERVER + net->last_errno=ER_NET_UNCOMPRESS_ERROR; +#endif + break; + } + net->buf_length+=len; + net->remain_in_buf+=len; + } + if (len != packet_error) + { + net->save_char= net->read_pos[len]; /* Must be saved */ + net->read_pos[len]=0; /* Safeguard for mysql_use_result */ + } + return len; +#endif +} |