fix issue #506
This commit is contained in:
parent
7a5ea90cba
commit
b675c55f6d
|
@ -134,11 +134,38 @@ TAOS *taos_connect(char *ip, char *user, char *pass, char *db, int port) {
|
|||
|
||||
void *taos = taos_connect_imp(ip, user, pass, db, port, NULL, NULL, NULL);
|
||||
if (taos != NULL) {
|
||||
int clientVersionNumber[4] = {0};
|
||||
if (!taosGetVersionNumber(version, clientVersionNumber)) {
|
||||
tscError("taos:%p, invalid client version:%s", taos, version);
|
||||
globalCode = TSDB_CODE_INVALID_CLIENT_VERSION;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *server_version = taos_get_server_info(taos);
|
||||
if (server_version && strcmp(server_version, version) != 0) {
|
||||
tscError("taos:%p, server version:%s not equal with client version:%s, close connection",
|
||||
int serverVersionNumber[4] = {0};
|
||||
if (!taosGetVersionNumber(server_version, serverVersionNumber)) {
|
||||
tscError("taos:%p, invalid server version:%s", taos, server_version);
|
||||
globalCode = TSDB_CODE_INVALID_CLIENT_VERSION;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (clientVersionNumber[0] != serverVersionNumber[0]) {
|
||||
tscError("taos:%p, the 1st number of server version:%s not matched with client version:%s, close connection",
|
||||
taos, server_version, version);
|
||||
globalCode = TSDB_CODE_INVALID_CLIENT_VERSION;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (clientVersionNumber[1] != serverVersionNumber[1]) {
|
||||
tscError("taos:%p, the 2nd number of server version:%s not matched with client version:%s, close connection",
|
||||
taos, server_version, version);
|
||||
globalCode = TSDB_CODE_INVALID_CLIENT_VERSION;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (clientVersionNumber[2] != serverVersionNumber[2]) {
|
||||
tscError("taos:%p, the 3rd number of server version:%s not matched with client version:%s, close connection",
|
||||
taos, server_version, version);
|
||||
taos_close(taos);
|
||||
globalCode = TSDB_CODE_INVALID_CLIENT_VERSION;
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -221,6 +221,8 @@ bool taosUcs4ToMbs(void *ucs4, int32_t ucs4_max_len, char *mbs);
|
|||
|
||||
bool taosValidateEncodec(char *encodec);
|
||||
|
||||
bool taosGetVersionNumber(char *versionStr, int *versionNubmer);
|
||||
|
||||
static FORCE_INLINE void taosEncryptPass(uint8_t *inBuf, unsigned int inLen, char *target) {
|
||||
MD5_CTX context;
|
||||
MD5Init(&context);
|
||||
|
|
|
@ -469,4 +469,33 @@ bool taosValidateEncodec(char *encodec) {
|
|||
#else
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool taosGetVersionNumber(char *versionStr, int *versionNubmer) {
|
||||
if (versionStr == NULL || versionNubmer == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int versionNumberPos[4] = {0};
|
||||
int len = strlen(versionStr);
|
||||
int dot = 0;
|
||||
for (int pos = 0; pos < len && dot < 4; ++pos) {
|
||||
if (versionStr[pos] == '.') {
|
||||
versionStr[pos] = 0;
|
||||
versionNumberPos[++dot] = pos + 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (dot != 3) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int pos = 0; pos < 4; ++pos) {
|
||||
versionNubmer[pos] = atoi(versionStr + versionNumberPos[pos]);
|
||||
}
|
||||
versionStr[versionNumberPos[1] - 1] = '.';
|
||||
versionStr[versionNumberPos[2] - 1] = '.';
|
||||
versionStr[versionNumberPos[3] - 1] = '.';
|
||||
|
||||
return true;
|
||||
}
|
Loading…
Reference in New Issue