transactd 2.1.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/common/tdclc_32_2_2.dll +0 -0
- data/bin/common/tdclc_64_2_2.dll +0 -0
- data/build/swig/ruby/generate.cmd +45 -0
- data/build/swig/ruby/generate.sh +40 -0
- data/build/swig/ruby/tdclrb_wrap.cpp +406 -969
- data/build/swig/tdcl.i +88 -0
- data/build/tdclc/CMakeLists.txt +5 -1
- data/build/tdclc/tdclc.cbproj +1 -1
- data/build/tdclc/tdclc.rc +4 -4
- data/build/tdclcpp/tdclcpp.rc +4 -4
- data/build/tdclcpp/tdclcpp_bc.cbproj +1 -1
- data/build/tdclrb/tdclrb.rc +4 -4
- data/source/bzs/db/engine/mysql/database.cpp +165 -74
- data/source/bzs/db/engine/mysql/database.h +19 -5
- data/source/bzs/db/engine/mysql/dbManager.cpp +33 -11
- data/source/bzs/db/engine/mysql/dbManager.h +6 -1
- data/source/bzs/db/engine/mysql/mydebuglog.h +12 -0
- data/source/bzs/db/engine/mysql/mysqlInternal.h +10 -3
- data/source/bzs/db/engine/mysql/mysqlThd.cpp +20 -8
- data/source/bzs/db/protocol/hs/hsCommandExecuter.cpp +12 -7
- data/source/bzs/db/protocol/hs/hsCommandExecuter.h +1 -1
- data/source/bzs/db/protocol/tdap/client/activeTableImple.h +1 -0
- data/source/bzs/db/protocol/tdap/client/client.cpp +17 -15
- data/source/bzs/db/protocol/tdap/client/client.h +102 -30
- data/source/bzs/db/protocol/tdap/client/connectionPool.cpp +1 -1
- data/source/bzs/db/protocol/tdap/client/database.cpp +32 -10
- data/source/bzs/db/protocol/tdap/client/database.h +1 -0
- data/source/bzs/db/protocol/tdap/client/databaseFactory.cpp +0 -2
- data/source/bzs/db/protocol/tdap/client/dbDef.cpp +2 -0
- data/source/bzs/db/protocol/tdap/client/dllmain.cpp +47 -42
- data/source/bzs/db/protocol/tdap/client/fields.h +3 -1
- data/source/bzs/db/protocol/tdap/client/filter.h +3 -3
- data/source/bzs/db/protocol/tdap/client/nsDatabase.cpp +18 -2
- data/source/bzs/db/protocol/tdap/client/nsDatabase.h +3 -2
- data/source/bzs/db/protocol/tdap/client/nsTable.cpp +14 -6
- data/source/bzs/db/protocol/tdap/client/nsTable.h +12 -12
- data/source/bzs/db/protocol/tdap/client/recordsetImple.h +6 -3
- data/source/bzs/db/protocol/tdap/client/request.h +1 -0
- data/source/bzs/db/protocol/tdap/client/sqlBuilder.cpp +101 -64
- data/source/bzs/db/protocol/tdap/client/sqlBuilder.h +3 -0
- data/source/bzs/db/protocol/tdap/client/stringConverter.h +9 -13
- data/source/bzs/db/protocol/tdap/client/table.cpp +73 -56
- data/source/bzs/db/protocol/tdap/client/table.h +8 -8
- data/source/bzs/db/protocol/tdap/client/trdboostapi.h +52 -100
- data/source/bzs/db/protocol/tdap/mysql/databaseSchema.cpp +8 -1
- data/source/bzs/db/protocol/tdap/mysql/request.h +6 -0
- data/source/bzs/db/protocol/tdap/mysql/tdapCommandExecuter.cpp +349 -189
- data/source/bzs/db/protocol/tdap/mysql/tdapCommandExecuter.h +28 -12
- data/source/bzs/db/protocol/tdap/tdapRequest.h +5 -4
- data/source/bzs/db/protocol/tdap/tdapSchema.h +6 -1
- data/source/bzs/db/protocol/tdap/tdapcapi.h +29 -4
- data/source/bzs/db/protocol/tdap/uri.h +297 -0
- data/source/bzs/db/transactd/appModule.cpp +41 -16
- data/source/bzs/db/transactd/appModule.h +1 -2
- data/source/bzs/db/transactd/transactd.cpp +37 -14
- data/source/bzs/env/crosscompile.h +1 -3
- data/source/bzs/example/queryData.cpp +2 -2
- data/source/bzs/netsvc/client/iconnection.h +3 -1
- data/source/bzs/netsvc/client/tcpClient.cpp +75 -28
- data/source/bzs/netsvc/client/tcpClient.h +94 -62
- data/source/bzs/netsvc/server/IAppModule.h +2 -2
- data/source/bzs/netsvc/server/serverCpt.cpp +17 -10
- data/source/bzs/netsvc/server/serverPipe.cpp +26 -19
- data/source/bzs/netsvc/server/serverTpool.cpp +8 -2
- data/source/bzs/rtl/debuglog.cpp +21 -5
- data/source/bzs/rtl/debuglog.h +1 -1
- data/source/bzs/test/tdclphp/transactd_Test.php +183 -37
- data/source/bzs/test/tdclphp/transactd_pool_Test.php +1 -2
- data/source/bzs/test/tdclrb/transactd_spec.rb +183 -39
- data/source/bzs/test/transactdBench/scaling_bench.cpp +3 -3
- data/source/bzs/test/trdclengn/test_trdclengn.cpp +172 -57
- data/source/global/boost/sha1.hpp +223 -0
- data/source/global/tdclatl/ConnectParams.cpp +2 -2
- data/source/global/tdclatl/ConnectParams.h +1 -1
- data/source/global/tdclatl/Database.cpp +18 -0
- data/source/global/tdclatl/Database.h +5 -0
- data/source/global/tdclatl/tdclatl.idl +23 -1
- data/source/linux/linuxTypes.h +2 -0
- metadata +8 -6
- data/bin/common/tdclc_32_2_1.dll +0 -0
- data/bin/common/tdclc_64_2_1.dll +0 -0
- data/source/bzs/db/protocol/tdap/client/memRecordset.cpp +0 -448
- data/source/bzs/db/protocol/tdap/client/memRecordset.h +0 -159
|
@@ -24,6 +24,17 @@
|
|
|
24
24
|
#include "request.h"
|
|
25
25
|
#include <bzs/env/crosscompile.h>
|
|
26
26
|
|
|
27
|
+
|
|
28
|
+
#define GRANT_APPLY_NONE 0
|
|
29
|
+
#define GRANT_APPLY_ALL 1
|
|
30
|
+
|
|
31
|
+
#define AUTH_TYPE_NONE_STR "none"
|
|
32
|
+
#define AUTH_TYPE_MYSQL_STR "mysql_native"
|
|
33
|
+
|
|
34
|
+
#define AUTH_TYPE_NONE 0
|
|
35
|
+
#define AUTH_TYPE_MYSQL 1
|
|
36
|
+
|
|
37
|
+
extern char* g_auth_type;
|
|
27
38
|
extern int g_tableNmaeLower;
|
|
28
39
|
|
|
29
40
|
namespace bzs
|
|
@@ -31,6 +42,8 @@ namespace bzs
|
|
|
31
42
|
namespace db
|
|
32
43
|
{
|
|
33
44
|
class blobBuffer;
|
|
45
|
+
namespace engine{namespace mysql{class database;}}
|
|
46
|
+
|
|
34
47
|
namespace protocol
|
|
35
48
|
{
|
|
36
49
|
namespace tdap
|
|
@@ -53,12 +66,13 @@ class dbExecuter : public engine::mysql::dbManager
|
|
|
53
66
|
{
|
|
54
67
|
ReadRecordsHandler* m_readHandler;
|
|
55
68
|
blobBuffer* m_blobBuffer;
|
|
56
|
-
|
|
57
|
-
|
|
69
|
+
unsigned char m_scramble[MYSQL_SCRAMBLE_LENGTH+1];
|
|
70
|
+
netsvc::server::IAppModule* m_mod;
|
|
58
71
|
void releaseDatabase(request& req, int op);
|
|
59
72
|
std::string makeSQLcreateTable(const request& req);
|
|
60
|
-
|
|
61
|
-
inline
|
|
73
|
+
bool connect(request& req);
|
|
74
|
+
inline bool doCreateTable(request& req);
|
|
75
|
+
inline bool doOpenTable(request& req);
|
|
62
76
|
inline void doSeekKey(request& req, int op, engine::mysql::rowLockMode* lock);
|
|
63
77
|
inline void doMoveFirst(request& req, engine::mysql::rowLockMode* lock);
|
|
64
78
|
inline void doMoveKey(request& req, int op, engine::mysql::rowLockMode* lock);
|
|
@@ -75,16 +89,19 @@ class dbExecuter : public engine::mysql::dbManager
|
|
|
75
89
|
inline void doInsertBulk(request& req);
|
|
76
90
|
inline void doStat(request& req);
|
|
77
91
|
inline short seekEach(extRequestSeeks* ereq, bool noBookMark);
|
|
78
|
-
|
|
92
|
+
inline bool doAuthentication(request& req, engine::mysql::database* db);
|
|
93
|
+
bool getDatabaseWithAuth(request& req, engine::mysql::database** db, bool connect=false);
|
|
79
94
|
public:
|
|
80
|
-
dbExecuter();
|
|
95
|
+
dbExecuter(netsvc::server::IAppModule* mod);
|
|
81
96
|
~dbExecuter();
|
|
82
97
|
int commandExec(request& req, netsvc::server::netWriter* nw);
|
|
98
|
+
size_t getAcceptMessage(char* message, size_t size);
|
|
83
99
|
int errorCode(int ha_error);
|
|
84
100
|
short_td errorCodeSht(int ha_error)
|
|
85
101
|
{
|
|
86
102
|
return (short_td)errorCode(ha_error);
|
|
87
|
-
}
|
|
103
|
+
}
|
|
104
|
+
netsvc::server::IAppModule* mod() { return m_mod; };
|
|
88
105
|
};
|
|
89
106
|
|
|
90
107
|
/** Command dispatcher for connectionManager
|
|
@@ -110,17 +127,15 @@ class commandExecuter : public ICommandExecuter,
|
|
|
110
127
|
|
|
111
128
|
int readStatistics(char* buf, size_t& size);
|
|
112
129
|
int cmdStatistics(char* buf, size_t& size);
|
|
113
|
-
unsigned __int64 m_modHandle;
|
|
114
130
|
|
|
115
131
|
public:
|
|
116
|
-
commandExecuter(
|
|
132
|
+
commandExecuter(netsvc::server::IAppModule* mod);
|
|
117
133
|
~commandExecuter();
|
|
118
134
|
size_t perseRequestEnd(const char* p, size_t size, bool& comp) const;
|
|
119
135
|
|
|
120
136
|
size_t getAcceptMessage(char* message, size_t size)
|
|
121
137
|
{
|
|
122
|
-
|
|
123
|
-
return strlen(message);
|
|
138
|
+
return m_dbExec->getAcceptMessage(message, size);
|
|
124
139
|
}
|
|
125
140
|
|
|
126
141
|
bool parse(const char* p, size_t size);
|
|
@@ -128,7 +143,8 @@ public:
|
|
|
128
143
|
int execute(netsvc::server::netWriter* nw)
|
|
129
144
|
{
|
|
130
145
|
if (m_req.op == TD_STASTISTICS)
|
|
131
|
-
return connMgrExecuter(m_req,
|
|
146
|
+
return connMgrExecuter(m_req, (unsigned __int64)m_dbExec->mod())
|
|
147
|
+
.commandExec(nw);
|
|
132
148
|
return m_dbExec->commandExec(m_req, nw);
|
|
133
149
|
}
|
|
134
150
|
|
|
@@ -115,13 +115,14 @@ struct clientID
|
|
|
115
115
|
|
|
116
116
|
#ifdef __x86_64__
|
|
117
117
|
bzs::netsvc::client::connection* con;
|
|
118
|
-
|
|
119
|
-
|
|
118
|
+
unsigned short transaction_isolation;
|
|
119
|
+
unsigned short lock_wait_timeout;
|
|
120
120
|
#else // NOT __x86_64__
|
|
121
121
|
|
|
122
122
|
bzs::netsvc::client::connection* con;
|
|
123
|
-
|
|
124
|
-
|
|
123
|
+
unsigned short transaction_isolation;
|
|
124
|
+
unsigned short lock_wait_timeout;
|
|
125
|
+
char_td reserved[4];
|
|
125
126
|
#endif // NOT __x86_64__
|
|
126
127
|
char_td aid[2];
|
|
127
128
|
ushort_td id;
|
|
@@ -216,7 +216,12 @@ public:
|
|
|
216
216
|
uchar_td nullValue; // null value
|
|
217
217
|
ushort_td userOption; // ** option
|
|
218
218
|
uchar_td lookDBNum; // ** database number of reference bitD
|
|
219
|
-
|
|
219
|
+
|
|
220
|
+
/** The length of the mysql part key
|
|
221
|
+
|
|
222
|
+
If this field is used by two or more keys, and both this length is used.
|
|
223
|
+
*/
|
|
224
|
+
ushort_td keylen;
|
|
220
225
|
|
|
221
226
|
protected:
|
|
222
227
|
uchar_td m_charsetIndex; // charctor set index of this field data
|
|
@@ -68,7 +68,7 @@ typedef short_td(__STDCALL* DLLUNLOADCALLBACK_PTR)(dllUnloadCallback func);
|
|
|
68
68
|
#define MAX_KEYLEN 0X3FF // 1023
|
|
69
69
|
#endif
|
|
70
70
|
#define BTRV_MAX_DATA_SIZE 57000
|
|
71
|
-
#define TDAP_MAX_DATA_SIZE 6291456 //
|
|
71
|
+
#define TDAP_MAX_DATA_SIZE 6291456 // 6Mbyte
|
|
72
72
|
#define BOOKMARK_ALLOC_SIZE 40960
|
|
73
73
|
|
|
74
74
|
/** operation type
|
|
@@ -143,6 +143,7 @@ typedef short_td(__STDCALL* DLLUNLOADCALLBACK_PTR)(dllUnloadCallback func);
|
|
|
143
143
|
#define TD_GET_BLOB_BUF 93
|
|
144
144
|
#define TD_STASTISTICS 94
|
|
145
145
|
#define TD_KEY_SEEK_MULTI 95
|
|
146
|
+
#define TD_ACL_RELOAD 96
|
|
146
147
|
|
|
147
148
|
/** create sub operations
|
|
148
149
|
*/
|
|
@@ -246,6 +247,7 @@ typedef short_td(__STDCALL* DLLUNLOADCALLBACK_PTR)(dllUnloadCallback func);
|
|
|
246
247
|
|
|
247
248
|
/** btrv transaction lock options
|
|
248
249
|
*/
|
|
250
|
+
#define LOCK_BIAS_DEFAULT 0
|
|
249
251
|
#define LOCK_SINGLE_WAIT 100
|
|
250
252
|
#define LOCK_SINGLE_NOWAIT 200
|
|
251
253
|
#define LOCK_MULTI_WAIT 300
|
|
@@ -276,6 +278,12 @@ typedef short_td(__STDCALL* DLLUNLOADCALLBACK_PTR)(dllUnloadCallback func);
|
|
|
276
278
|
#define ROW_LOCK_X LOCK_SINGLE_NOWAIT
|
|
277
279
|
#define ROW_LOCK_S 5000 + LOCK_SINGLE_NOWAIT
|
|
278
280
|
|
|
281
|
+
//Server isoration
|
|
282
|
+
#define SRV_ISO_READ_UNCOMMITED 0
|
|
283
|
+
#define SRV_ISO_READ_COMMITED 1
|
|
284
|
+
#define SRV_ISO_REPEATABLE_READ 2
|
|
285
|
+
#define SRV_ISO_SERIALIZABLE 3
|
|
286
|
+
|
|
279
287
|
/** open mode
|
|
280
288
|
*/
|
|
281
289
|
#define TD_OPEN_NORMAL 0
|
|
@@ -365,6 +373,7 @@ typedef short_td(__STDCALL* DLLUNLOADCALLBACK_PTR)(dllUnloadCallback func);
|
|
|
365
373
|
#define STATUS_INVALID_DATASIZE STATUS_BUFFERTOOSMALL
|
|
366
374
|
#define STATUS_INVALID_FIELDNAME STATUS_INVALID_FIELD_OFFSET
|
|
367
375
|
#define ERROR_TD_INVALID_CLINETHOST 171
|
|
376
|
+
#define ERROR_NO_DATABASE 172
|
|
368
377
|
#define ERROR_NOSPECIFY_TABLE 176
|
|
369
378
|
#define ERROR_LOAD_CLIBRARY 200
|
|
370
379
|
#define ERROR_INDEX_RND_INIT 201
|
|
@@ -420,13 +429,29 @@ struct trdVersiton
|
|
|
420
429
|
ushort_td srvMinor;
|
|
421
430
|
ushort_td srvRelease;
|
|
422
431
|
};
|
|
432
|
+
|
|
433
|
+
#define MYSQL_SCRAMBLE_LENGTH 20
|
|
434
|
+
#define MYSQL_USERNAME_MAX 16
|
|
435
|
+
|
|
436
|
+
struct handshale_t
|
|
437
|
+
{
|
|
438
|
+
unsigned int size; // size of this
|
|
439
|
+
unsigned int options;
|
|
440
|
+
trdVersiton ver;
|
|
441
|
+
unsigned short transaction_isolation;
|
|
442
|
+
unsigned short lock_wait_timeout;
|
|
443
|
+
unsigned char scramble[MYSQL_SCRAMBLE_LENGTH+1]; //user auth scramble
|
|
444
|
+
};
|
|
445
|
+
|
|
446
|
+
#define HST_OPTION_NO_SCRAMBLE 1
|
|
447
|
+
|
|
423
448
|
/** @endcond */
|
|
424
449
|
|
|
425
450
|
/* In the case of "tdclcppxxx" library of msvc, The ($TargetName) is not changed automatically.
|
|
426
451
|
If you change this version then you need change The ($TargetName) project options too.
|
|
427
452
|
*/
|
|
428
453
|
#define C_INTERFACE_VER_MAJOR "2"//##1 Build marker! Don't remove
|
|
429
|
-
#define C_INTERFACE_VER_MINOR "
|
|
454
|
+
#define C_INTERFACE_VER_MINOR "2"//##2 Build marker! Don't remove
|
|
430
455
|
#define C_INTERFACE_VER_RELEASE "0"//##3 Build marker! Don't remove
|
|
431
456
|
|
|
432
457
|
/* dnamic load library name.
|
|
@@ -490,7 +515,7 @@ struct trdVersiton
|
|
|
490
515
|
*/
|
|
491
516
|
|
|
492
517
|
#define CPP_INTERFACE_VER_MAJOR "2"//##4 Build marker! Don't remove
|
|
493
|
-
#define CPP_INTERFACE_VER_MINOR "
|
|
518
|
+
#define CPP_INTERFACE_VER_MINOR "2"//##5 Build marker! Don't remove
|
|
494
519
|
#define CPP_INTERFACE_VER_RELEASE "0"//##6 Build marker! Don't remove
|
|
495
520
|
|
|
496
521
|
/* use autolink tdclcpp */
|
|
@@ -507,7 +532,7 @@ struct trdVersiton
|
|
|
507
532
|
#endif
|
|
508
533
|
|
|
509
534
|
#define TRANSACTD_VER_MAJOR 2//##7 Build marker! Don't remove
|
|
510
|
-
#define TRANSACTD_VER_MINOR
|
|
535
|
+
#define TRANSACTD_VER_MINOR 2//##8 Build marker! Don't remove
|
|
511
536
|
#define TRANSACTD_VER_RELEASE 0//##9 Build marker! Don't remove
|
|
512
537
|
|
|
513
538
|
#endif // BZS_DB_PROTOCOL_TDAP_TDAPCAPI_H
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
#ifndef BZS_DB_PROTOCOL_TDAP_URI_H
|
|
2
|
+
#define BZS_DB_PROTOCOL_TDAP_URI_H
|
|
3
|
+
/* =================================================================
|
|
4
|
+
Copyright (C) 2015 BizStation Corp All rights reserved.
|
|
5
|
+
|
|
6
|
+
This program is free software; you can redistribute it and/or
|
|
7
|
+
modify it under the terms of the GNU General Public License
|
|
8
|
+
as published by the Free Software Foundation; either version 2
|
|
9
|
+
of the License, or (at your option) any later version.
|
|
10
|
+
|
|
11
|
+
This program is distributed in the hope that it will be useful,
|
|
12
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14
|
+
GNU General Public License for more details.
|
|
15
|
+
|
|
16
|
+
You should have received a copy of the GNU General Public License
|
|
17
|
+
along with this program; if not, write to the Free Software
|
|
18
|
+
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
19
|
+
02111-1307, USA.
|
|
20
|
+
================================================================= */
|
|
21
|
+
#include <bzs/env/compiler.h>
|
|
22
|
+
#include <bzs/env/crosscompile.h>
|
|
23
|
+
#include <tchar.h>
|
|
24
|
+
#include <boost/version.hpp>
|
|
25
|
+
|
|
26
|
+
#if BOOST_VERSION > 103901
|
|
27
|
+
#include <boost/uuid/sha1.hpp>
|
|
28
|
+
#else
|
|
29
|
+
#include <global/boost/sha1.hpp>
|
|
30
|
+
#endif
|
|
31
|
+
#include <bzs/db/protocol/tdap/tdapcapi.h>
|
|
32
|
+
|
|
33
|
+
namespace bzs
|
|
34
|
+
{
|
|
35
|
+
namespace db
|
|
36
|
+
{
|
|
37
|
+
namespace protocol
|
|
38
|
+
{
|
|
39
|
+
namespace tdap
|
|
40
|
+
{
|
|
41
|
+
|
|
42
|
+
inline const _TCHAR* protocol(const _TCHAR* uri)
|
|
43
|
+
{
|
|
44
|
+
const _TCHAR* st = _tcsstr(uri, _T("tdap://"));
|
|
45
|
+
if (st)
|
|
46
|
+
return _T("tdap");
|
|
47
|
+
else
|
|
48
|
+
{
|
|
49
|
+
st = _tcsstr(uri, _T("btrv://"));
|
|
50
|
+
return _T("btrv");
|
|
51
|
+
}
|
|
52
|
+
return _T("");
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
inline const _TCHAR* hostName(const _TCHAR* uri, _TCHAR* buf, size_t size)
|
|
56
|
+
{
|
|
57
|
+
buf[0] = 0x00;
|
|
58
|
+
const _TCHAR* st = _tcsstr(uri, _T("@"));
|
|
59
|
+
if (st)
|
|
60
|
+
++st;
|
|
61
|
+
else
|
|
62
|
+
{
|
|
63
|
+
st = _tcsstr(uri, _T("://"));
|
|
64
|
+
if (st) st+=3;
|
|
65
|
+
}
|
|
66
|
+
if (st)
|
|
67
|
+
{
|
|
68
|
+
const _TCHAR* en = _tcsstr(st, _T("/"));
|
|
69
|
+
if (en)
|
|
70
|
+
{
|
|
71
|
+
_tcsncpy_s(buf, size, st, en - st);
|
|
72
|
+
buf[en - st] = 0x00;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return buf;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
inline const _TCHAR* dbname(const _TCHAR* uri, _TCHAR* buf, size_t size)
|
|
79
|
+
{
|
|
80
|
+
buf[0] = 0x00;
|
|
81
|
+
const _TCHAR* st = _tcsstr(uri, _T("://"));
|
|
82
|
+
if (st)
|
|
83
|
+
{
|
|
84
|
+
st = _tcsstr(st + 3, _T("/"));
|
|
85
|
+
if (st)
|
|
86
|
+
{
|
|
87
|
+
const _TCHAR* en = _tcsstr(st + 1, _T("?"));
|
|
88
|
+
if (en)
|
|
89
|
+
{
|
|
90
|
+
_tcsncpy_s(buf, size, st + 1, en - (st + 1));
|
|
91
|
+
buf[en - (st + 1)] = 0x00;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return buf;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
inline const _TCHAR* schemaTable(const _TCHAR* uri, _TCHAR* buf, size_t size)
|
|
99
|
+
{
|
|
100
|
+
buf[0] = 0x00;
|
|
101
|
+
const _TCHAR* st = _tcsstr(uri, _T("dbfile="));
|
|
102
|
+
if (st)
|
|
103
|
+
{
|
|
104
|
+
st+= 7;
|
|
105
|
+
const _TCHAR* en = _tcsrchr(uri, _T('.'));
|
|
106
|
+
if (en)
|
|
107
|
+
{
|
|
108
|
+
_tcsncpy_s(buf, size, st, en - st);
|
|
109
|
+
buf[en - st] = 0x00;
|
|
110
|
+
}else if (_tcsstr(st, TRANSACTD_SCHEMANAME))
|
|
111
|
+
_tcscpy_s(buf, size, TRANSACTD_SCHEMANAME);
|
|
112
|
+
}
|
|
113
|
+
return buf;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
inline const _TCHAR* userName(const _TCHAR* uri, _TCHAR* buf, size_t size)
|
|
117
|
+
{
|
|
118
|
+
buf[0] = 0x00;
|
|
119
|
+
const _TCHAR* st = _tcsstr(uri, _T("://"));
|
|
120
|
+
if (st) st+=3;
|
|
121
|
+
|
|
122
|
+
if (st)
|
|
123
|
+
{
|
|
124
|
+
const _TCHAR* en = _tcsstr(st, _T("@"));
|
|
125
|
+
if (en)
|
|
126
|
+
{
|
|
127
|
+
_tcsncpy_s(buf, size, st, en - st);
|
|
128
|
+
buf[en - st] = 0x00;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return buf;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
inline const _TCHAR* passwd(const _TCHAR* uri, _TCHAR* buf, size_t size)
|
|
135
|
+
{
|
|
136
|
+
buf[0] = 0x00;
|
|
137
|
+
const _TCHAR* st = _tcsstr(uri, _T("pwd="));
|
|
138
|
+
if (st)
|
|
139
|
+
_tcscpy_s(buf, size, st+4);
|
|
140
|
+
return buf;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
inline const _TCHAR* stripAuth(const _TCHAR* uri, _TCHAR* buf, size_t size)
|
|
144
|
+
{
|
|
145
|
+
_tcscpy_s(buf, size, uri);
|
|
146
|
+
_TCHAR* st = _tcsstr(buf, _T("://"));
|
|
147
|
+
if (st)
|
|
148
|
+
{
|
|
149
|
+
const _TCHAR* en = _tcsstr(uri, _T("@"));
|
|
150
|
+
if (en)
|
|
151
|
+
{
|
|
152
|
+
_tcscpy_s(st+3, size, ++en);
|
|
153
|
+
_TCHAR* st2 = _tcsstr(st, _T("&pwd="));
|
|
154
|
+
if (st2)
|
|
155
|
+
*st2 = 0x00;
|
|
156
|
+
else
|
|
157
|
+
{
|
|
158
|
+
st2 = _tcsstr(st, _T("?pwd="));
|
|
159
|
+
if (st2) *st2 = 0x00;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return buf;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
inline const _TCHAR* stripPasswd(const _TCHAR* uri, _TCHAR* buf, size_t size)
|
|
167
|
+
{
|
|
168
|
+
_tcscpy_s(buf, size, uri);
|
|
169
|
+
_TCHAR* st = _tcsstr(buf, _T("://"));
|
|
170
|
+
if (st)
|
|
171
|
+
{
|
|
172
|
+
st = _tcsstr(st, _T("pwd="));
|
|
173
|
+
if (st)
|
|
174
|
+
*(st + 4) = 0x00;
|
|
175
|
+
}
|
|
176
|
+
return buf;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
inline const _TCHAR* stripPasswdParam(const _TCHAR* uri, _TCHAR* buf, size_t size)
|
|
180
|
+
{
|
|
181
|
+
_tcscpy_s(buf, size, uri);
|
|
182
|
+
_TCHAR* st = _tcsstr(buf, _T("://"));
|
|
183
|
+
if (st)
|
|
184
|
+
{
|
|
185
|
+
_TCHAR* st2 = _tcsstr(st, _T("&pwd="));
|
|
186
|
+
if (st2)
|
|
187
|
+
*(st2) = 0x00;
|
|
188
|
+
else
|
|
189
|
+
{
|
|
190
|
+
st2 = _tcsstr(st, _T("?pwd="));
|
|
191
|
+
if (st2)
|
|
192
|
+
*(st2) = 0x00;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return buf;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
inline void reorder_digest(boost::uuids::detail::sha1::digest_type val)
|
|
199
|
+
{
|
|
200
|
+
for (int i=0;i<5;++i)
|
|
201
|
+
{
|
|
202
|
+
unsigned char* p = (unsigned char*)&val[i];
|
|
203
|
+
std::swap(*p, *(p+3));
|
|
204
|
+
std::swap(*(p+1), *(p+2));
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
inline void sha1Passwd(boost::uuids::detail::sha1::digest_type retVal ,
|
|
209
|
+
const char* src)
|
|
210
|
+
{
|
|
211
|
+
boost::uuids::detail::sha1 sha1;
|
|
212
|
+
sha1.reset();
|
|
213
|
+
sha1.process_bytes(src, strlen(src));
|
|
214
|
+
sha1.get_digest(retVal);
|
|
215
|
+
reorder_digest(retVal);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
inline void cryptKeyGen(boost::uuids::detail::sha1::digest_type retVal,
|
|
219
|
+
const unsigned int* sha1Passwd, const unsigned char *scramble)
|
|
220
|
+
{
|
|
221
|
+
boost::uuids::detail::sha1 sha1;
|
|
222
|
+
sha1.reset();
|
|
223
|
+
sha1.process_bytes(sha1Passwd, MYSQL_SCRAMBLE_LENGTH);
|
|
224
|
+
sha1.get_digest(retVal);
|
|
225
|
+
reorder_digest(retVal);
|
|
226
|
+
sha1.reset();
|
|
227
|
+
sha1.process_bytes(scramble, MYSQL_SCRAMBLE_LENGTH);
|
|
228
|
+
sha1.process_bytes(retVal, MYSQL_SCRAMBLE_LENGTH);
|
|
229
|
+
sha1.get_digest(retVal);
|
|
230
|
+
reorder_digest(retVal);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
inline void xorCrypt(char *retVal, const unsigned char *src, const unsigned char *key,
|
|
234
|
+
unsigned int len)
|
|
235
|
+
{
|
|
236
|
+
const unsigned char *end = src + len;
|
|
237
|
+
while (src < end)
|
|
238
|
+
*retVal++ = *src++ ^ *key++;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/* scramble size = MYSQL_SCRAMBLE_LENGTH only
|
|
242
|
+
retVal size = MYSQL_SCRAMBLE_LENGTH
|
|
243
|
+
*/
|
|
244
|
+
inline void mysqlCryptPwd(char *retVal, const char* src, const unsigned char *scramble)
|
|
245
|
+
{
|
|
246
|
+
unsigned int sha1pwd[5];
|
|
247
|
+
unsigned int key[5];
|
|
248
|
+
sha1Passwd(sha1pwd, src);
|
|
249
|
+
cryptKeyGen(key, sha1pwd, scramble);
|
|
250
|
+
xorCrypt(retVal, (const unsigned char*)sha1pwd, (const unsigned char*)key,
|
|
251
|
+
MYSQL_SCRAMBLE_LENGTH);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// binary to ascii return bytes = size * 2
|
|
255
|
+
inline char* binToHex(char* retVal, const unsigned char *src, int size)
|
|
256
|
+
{
|
|
257
|
+
const unsigned char* end = src + size;
|
|
258
|
+
char* p = retVal;
|
|
259
|
+
for (const unsigned char* n = src; n != end; ++n)
|
|
260
|
+
{
|
|
261
|
+
unsigned int v = (*n >> 4);
|
|
262
|
+
*p++ = (v < 10) ? '0' + v : 'A' + (v - 10);
|
|
263
|
+
v = *n & 0x0F;
|
|
264
|
+
*p++ = (v < 10) ? '0' + v : 'A' + (v - 10);
|
|
265
|
+
}
|
|
266
|
+
*p = 0x00;
|
|
267
|
+
return retVal;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
// ascii to binary return bytes = size / 2
|
|
271
|
+
inline unsigned char* hexTobin(unsigned char* retVal, const char *src, int size)
|
|
272
|
+
{
|
|
273
|
+
const char* end = src + size;
|
|
274
|
+
unsigned char* p = retVal;
|
|
275
|
+
for (const char* n = src; n != end; ++n)
|
|
276
|
+
{
|
|
277
|
+
if (*n >= '0' && *n <= '9')
|
|
278
|
+
*p = *n - '0';
|
|
279
|
+
else
|
|
280
|
+
*p = (*n - 'A')+10;
|
|
281
|
+
++n;
|
|
282
|
+
*p = *p << 4;
|
|
283
|
+
if (*n >= '0' && *n <= '9')
|
|
284
|
+
*p += *n - '0';
|
|
285
|
+
else
|
|
286
|
+
*p += (*n - 'A')+10;
|
|
287
|
+
++p;
|
|
288
|
+
}
|
|
289
|
+
return retVal;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
} // namespace tdap
|
|
294
|
+
} // namespace protocol
|
|
295
|
+
} // namespace db
|
|
296
|
+
} // namespace bzs
|
|
297
|
+
#endif // BZS_DB_PROTOCOL_TDAP_URI_H
|
|
@@ -308,12 +308,12 @@ module::module(const boost::asio::ip::tcp::endpoint& endpoint,
|
|
|
308
308
|
: m_endpoint(endpoint), m_connection(connection), m_useThreadPool(tpool)
|
|
309
309
|
{
|
|
310
310
|
if (type & PROTOCOL_TYPE_BTRV)
|
|
311
|
-
m_commandExecuter.reset(new protocol::tdap::mysql::commandExecuter(
|
|
312
|
-
|
|
311
|
+
m_commandExecuter.reset(new protocol::tdap::mysql::commandExecuter(this));
|
|
312
|
+
|
|
313
313
|
#ifdef USE_HANDLERSOCKET
|
|
314
314
|
else if (type & PROTOCOL_TYPE_HS)
|
|
315
315
|
m_commandExecuter.reset(
|
|
316
|
-
new protocol::hs::commandExecuter(
|
|
316
|
+
new protocol::hs::commandExecuter(this));
|
|
317
317
|
#endif
|
|
318
318
|
boost::mutex::scoped_lock lck(modulesMutex);
|
|
319
319
|
modules.push_back(this);
|
|
@@ -361,8 +361,8 @@ size_t module::onAccept(char* message, size_t bufsize)
|
|
|
361
361
|
|
|
362
362
|
static const char* addressMasks[3] = { ".0.0.0/255.0.0.0", ".0.0/255.255.0.0",
|
|
363
363
|
".0/255.255.255.0" };
|
|
364
|
-
|
|
365
|
-
char* addressClass(char* buf, int bufsize, const char* host, int type)
|
|
364
|
+
static const char* addressWildcard[3] = { ".%", ".%", ".%" };
|
|
365
|
+
char* addressClass(char* buf, int bufsize, const char* host, int type, const char* ar[] )
|
|
366
366
|
{
|
|
367
367
|
strcpy_s(buf, bufsize, host);
|
|
368
368
|
for (int i = 3; i >= type; i--)
|
|
@@ -372,43 +372,68 @@ char* addressClass(char* buf, int bufsize, const char* host, int type)
|
|
|
372
372
|
return buf;
|
|
373
373
|
*p = 0x00;
|
|
374
374
|
}
|
|
375
|
-
strcat_s(buf, bufsize,
|
|
375
|
+
strcat_s(buf, bufsize, ar[type - 1]);
|
|
376
376
|
return buf;
|
|
377
377
|
}
|
|
378
378
|
|
|
379
|
-
bool isAclUser(const char* host, const char* user)
|
|
379
|
+
bool isAclUser(const char* &host, const char* user, char* buf, int size)
|
|
380
380
|
{
|
|
381
381
|
bool ret = is_acl_user(host, user);
|
|
382
382
|
if (ret)
|
|
383
383
|
return true;
|
|
384
|
-
|
|
384
|
+
|
|
385
|
+
for (int i = 3; i >= 1; --i)
|
|
385
386
|
{
|
|
386
|
-
|
|
387
|
-
ret = is_acl_user(addressClass(buf, 256, host, i), user);
|
|
387
|
+
ret = is_acl_user(addressClass(buf, size, host, i, addressMasks), user);
|
|
388
388
|
if (ret)
|
|
389
|
+
{
|
|
390
|
+
host = buf;
|
|
389
391
|
return true;
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
for (int i = 3; i >= 1; --i)
|
|
395
|
+
{
|
|
396
|
+
ret = is_acl_user(addressClass(buf, size, host, i, addressWildcard), user);
|
|
397
|
+
if (ret)
|
|
398
|
+
{
|
|
399
|
+
host = buf;
|
|
400
|
+
return true;
|
|
401
|
+
}
|
|
390
402
|
}
|
|
391
403
|
return false;
|
|
392
404
|
}
|
|
393
405
|
|
|
394
|
-
bool module::checkHost(const char* hostCheckname)
|
|
406
|
+
bool module::checkHost(const char* hostCheckname, /*out*/char* hostName, int size)
|
|
395
407
|
{
|
|
408
|
+
// if size=0 called by server, size !=0 called by user auth
|
|
409
|
+
if ((size == 0) && (strcmp(g_auth_type, AUTH_TYPE_MYSQL_STR)==0))
|
|
410
|
+
return true;
|
|
396
411
|
std::string addr = m_endpoint.address().to_string();
|
|
397
412
|
size_t pos = addr.find_last_of(":");
|
|
398
413
|
if (pos != std::string::npos)
|
|
399
414
|
addr = addr.substr(pos + 1);
|
|
400
|
-
|
|
415
|
+
const char* p = addr.c_str();
|
|
401
416
|
bool ret = true;
|
|
402
|
-
|
|
417
|
+
char buf[256];
|
|
418
|
+
if (!isAclUser(p, hostCheckname, buf, 256))
|
|
403
419
|
{
|
|
404
|
-
|
|
405
|
-
|
|
420
|
+
p = m_endpoint.address().to_string().c_str();
|
|
421
|
+
ret = isAclUser(p, hostCheckname, buf, 256);
|
|
406
422
|
if (!ret && m_endpoint.address().is_v4())
|
|
407
423
|
{
|
|
408
424
|
if (addr == std::string("127.0.0.1"))
|
|
409
|
-
|
|
425
|
+
{
|
|
426
|
+
p = "localhost";
|
|
427
|
+
ret = isAclUser(p, hostCheckname, buf, 256);
|
|
428
|
+
}
|
|
410
429
|
}
|
|
411
430
|
}
|
|
431
|
+
if (hostName && (size > (int)strlen(p)))
|
|
432
|
+
{
|
|
433
|
+
if (strcmp(p , "127.0.0.1") == 0)
|
|
434
|
+
p = "localhost";
|
|
435
|
+
strcpy(hostName, p);
|
|
436
|
+
}
|
|
412
437
|
return ret;
|
|
413
438
|
}
|
|
414
439
|
|
|
@@ -52,7 +52,6 @@ class module : public netsvc::server::IAppModule, private boost::noncopyable
|
|
|
52
52
|
bool perseLineEnd(const char* p, size_t size) const;
|
|
53
53
|
size_t onRead(const char* data, size_t size, bool& complete);
|
|
54
54
|
size_t onAccept(char* message, size_t bufsize);
|
|
55
|
-
|
|
56
55
|
public:
|
|
57
56
|
module(const boost::asio::ip::tcp::endpoint& endpoint,
|
|
58
57
|
bzs::netsvc::server::iconnection* connection, bool tpool, int type);
|
|
@@ -62,7 +61,7 @@ public:
|
|
|
62
61
|
netsvc::server::buffers* optionalData);
|
|
63
62
|
void cleanup() { m_commandExecuter->cleanup(); };
|
|
64
63
|
bool isShutDown() { return m_commandExecuter->isShutDown(); }
|
|
65
|
-
bool checkHost(const char* hostCheckname);
|
|
64
|
+
bool checkHost(const char* hostCheckname, /*out*/char* hostName, int size);
|
|
66
65
|
void disconnect();
|
|
67
66
|
boost::mutex& mutex() const { return m_mutex; };
|
|
68
67
|
};
|