1 #ifndef BZS_DB_PROTOCOL_TDAP_URI_H
2 #define BZS_DB_PROTOCOL_TDAP_URI_H
21 #include <bzs/env/compiler.h>
22 #include <bzs/env/crosscompile.h>
24 #include <boost/version.hpp>
26 #if BOOST_VERSION > 103901
27 #include <boost/uuid/sha1.hpp>
29 #include <global/boost/sha1.hpp>
31 #include <bzs/db/protocol/tdap/tdapcapi.h>
42 inline const _TCHAR*
protocol(
const _TCHAR* uri)
44 const _TCHAR* st = _tcsstr(uri, _T(
"tdap://"));
49 st = _tcsstr(uri, _T(
"btrv://"));
55 _TCHAR* host,
size_t hostSize,
56 _TCHAR*
port,
size_t portSize)
58 if (host) host[0] = 0x00;
59 if (port) port[0] = 0x00;
60 const _TCHAR* st = _tcsstr(uri, _T(
"@"));
65 st = _tcsstr(uri, _T(
"://"));
70 const _TCHAR* en = _tcsstr(st, _T(
":"));
75 _tcsncpy_s(host, hostSize, st, en - st);
81 en = _tcsstr(st, _T(
"/"));
84 _tcsncpy_s(port, portSize, st, en - st);
91 en = _tcsstr(st, _T(
"/"));
94 _tcsncpy_s(host, hostSize, st, en - st);
101 inline const _TCHAR*
hostName(
const _TCHAR* uri, _TCHAR* buf,
size_t size)
107 inline const _TCHAR*
port(
const _TCHAR* uri, _TCHAR* buf,
size_t size)
113 inline const _TCHAR*
dbname(
const _TCHAR* uri, _TCHAR* buf,
size_t size)
116 const _TCHAR* st = _tcsstr(uri, _T(
"://"));
119 st = _tcsstr(st + 3, _T(
"/"));
122 const _TCHAR* en = _tcsstr(st + 1, _T(
"?"));
125 _tcsncpy_s(buf, size, st + 1, en - (st + 1));
126 buf[en - (st + 1)] = 0x00;
133 inline const _TCHAR*
schemaTable(
const _TCHAR* uri, _TCHAR* buf,
size_t size)
136 const _TCHAR* st = _tcsstr(uri, _T(
"dbfile="));
140 const _TCHAR* en = _tcsrchr(uri, _T(
'.'));
143 _tcsncpy_s(buf, size, st, en - st);
145 }
else if (_tcsstr(st, TRANSACTD_SCHEMANAME))
146 _tcscpy_s(buf, size, TRANSACTD_SCHEMANAME);
151 inline const _TCHAR*
userName(
const _TCHAR* uri, _TCHAR* buf,
size_t size)
154 const _TCHAR* st = _tcsstr(uri, _T(
"://"));
159 const _TCHAR* en = _tcsstr(st, _T(
"@"));
162 _tcsncpy_s(buf, size, st, en - st);
169 inline const _TCHAR*
passwd(
const _TCHAR* uri, _TCHAR* buf,
size_t size)
172 const _TCHAR* st = _tcsstr(uri, _T(
"pwd="));
174 _tcscpy_s(buf, size, st+4);
178 inline const _TCHAR*
stripAuth(
const _TCHAR* uri, _TCHAR* buf,
size_t size)
180 _tcscpy_s(buf, size, uri);
181 _TCHAR* st = _tcsstr(buf, _T(
"://"));
184 const _TCHAR* en = _tcsstr(uri, _T(
"@"));
187 _tcscpy_s(st+3, size, ++en);
188 _TCHAR* st2 = _tcsstr(st, _T(
"&pwd="));
193 st2 = _tcsstr(st, _T(
"?pwd="));
194 if (st2) *st2 = 0x00;
201 inline const _TCHAR*
stripPasswd(
const _TCHAR* uri, _TCHAR* buf,
size_t size)
203 _tcscpy_s(buf, size, uri);
204 _TCHAR* st = _tcsstr(buf, _T(
"://"));
207 st = _tcsstr(st, _T(
"pwd="));
216 _tcscpy_s(buf, size, uri);
217 _TCHAR* st = _tcsstr(buf, _T(
"://"));
220 _TCHAR* st2 = _tcsstr(st, _T(
"&pwd="));
225 st2 = _tcsstr(st, _T(
"?pwd="));
235 for (
int i=0;i<5;++i)
237 unsigned char* p = (
unsigned char*)&val[i];
238 std::swap(*p, *(p+3));
239 std::swap(*(p+1), *(p+2));
243 inline void sha1Passwd(boost::uuids::detail::sha1::digest_type retVal ,
246 boost::uuids::detail::sha1 sha1;
248 sha1.process_bytes(src, strlen(src));
249 sha1.get_digest(retVal);
253 inline void cryptKeyGen(boost::uuids::detail::sha1::digest_type retVal,
254 const unsigned int*
sha1Passwd,
const unsigned char *scramble)
256 boost::uuids::detail::sha1 sha1;
258 sha1.process_bytes(sha1Passwd, MYSQL_SCRAMBLE_LENGTH);
259 sha1.get_digest(retVal);
262 sha1.process_bytes(scramble, MYSQL_SCRAMBLE_LENGTH);
263 sha1.process_bytes(retVal, MYSQL_SCRAMBLE_LENGTH);
264 sha1.get_digest(retVal);
268 inline void xorCrypt(
char *retVal,
const unsigned char *src,
const unsigned char *key,
271 const unsigned char *end = src + len;
273 *retVal++ = *src++ ^ *key++;
279 inline void mysqlCryptPwd(
char *retVal,
const char* src,
const unsigned char *scramble)
281 unsigned int sha1pwd[5];
285 xorCrypt(retVal, (
const unsigned char*)sha1pwd, (
const unsigned char*)key,
286 MYSQL_SCRAMBLE_LENGTH);
290 inline char*
binToHex(
char* retVal,
const unsigned char *src,
int size)
292 const unsigned char* end = src + size;
294 for (
const unsigned char* n = src; n != end; ++n)
296 unsigned int v = (*n >> 4);
297 *p++ = (v < 10) ?
'0' + v :
'A' + (v - 10);
299 *p++ = (v < 10) ?
'0' + v :
'A' + (v - 10);
306 inline unsigned char*
hexTobin(
unsigned char* retVal,
const char *src,
int size)
308 const char* end = src + size;
309 unsigned char* p = retVal;
310 for (
const char* n = src; n != end; ++n)
312 if (*n >=
'0' && *n <=
'9')
318 if (*n >=
'0' && *n <=
'9')
332 #endif // BZS_DB_PROTOCOL_TDAP_URI_H
const _TCHAR * protocol(const _TCHAR *uri)
Definition: uri.h:42
const _TCHAR * port(const _TCHAR *uri, _TCHAR *buf, size_t size)
Definition: uri.h:107
char * binToHex(char *retVal, const unsigned char *src, int size)
Definition: uri.h:290
const _TCHAR * passwd(const _TCHAR *uri, _TCHAR *buf, size_t size)
Definition: uri.h:169
void mysqlCryptPwd(char *retVal, const char *src, const unsigned char *scramble)
Definition: uri.h:279
const _TCHAR * dbname(const _TCHAR *uri, _TCHAR *buf, size_t size)
Definition: uri.h:113
void reorder_digest(boost::uuids::detail::sha1::digest_type val)
Definition: uri.h:233
void endPoint(const _TCHAR *uri, _TCHAR *host, size_t hostSize, _TCHAR *port, size_t portSize)
Definition: uri.h:54
unsigned char * hexTobin(unsigned char *retVal, const char *src, int size)
Definition: uri.h:306
const _TCHAR * stripPasswd(const _TCHAR *uri, _TCHAR *buf, size_t size)
Definition: uri.h:201
void sha1Passwd(boost::uuids::detail::sha1::digest_type retVal, const char *src)
Definition: uri.h:243
const _TCHAR * schemaTable(const _TCHAR *uri, _TCHAR *buf, size_t size)
Definition: uri.h:133
const _TCHAR * stripPasswdParam(const _TCHAR *uri, _TCHAR *buf, size_t size)
Definition: uri.h:214
const _TCHAR * stripAuth(const _TCHAR *uri, _TCHAR *buf, size_t size)
Definition: uri.h:178
void xorCrypt(char *retVal, const unsigned char *src, const unsigned char *key, unsigned int len)
Definition: uri.h:268
void cryptKeyGen(boost::uuids::detail::sha1::digest_type retVal, const unsigned int *sha1Passwd, const unsigned char *scramble)
Definition: uri.h:253
const _TCHAR * userName(const _TCHAR *uri, _TCHAR *buf, size_t size)
Definition: uri.h:151
const _TCHAR * hostName(const _TCHAR *uri, _TCHAR *buf, size_t size)
Definition: uri.h:101