提交 b675c55f 编写于 作者: S slguan

fix issue #506

上级 7a5ea90c
...@@ -134,11 +134,38 @@ TAOS *taos_connect(char *ip, char *user, char *pass, char *db, int port) { ...@@ -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); void *taos = taos_connect_imp(ip, user, pass, db, port, NULL, NULL, NULL);
if (taos != 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); char *server_version = taos_get_server_info(taos);
if (server_version && strcmp(server_version, version) != 0) { int serverVersionNumber[4] = {0};
tscError("taos:%p, server version:%s not equal with client version:%s, close connection", 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, server_version, version);
taos_close(taos);
globalCode = TSDB_CODE_INVALID_CLIENT_VERSION; globalCode = TSDB_CODE_INVALID_CLIENT_VERSION;
return NULL; return NULL;
} }
......
...@@ -221,6 +221,8 @@ bool taosUcs4ToMbs(void *ucs4, int32_t ucs4_max_len, char *mbs); ...@@ -221,6 +221,8 @@ bool taosUcs4ToMbs(void *ucs4, int32_t ucs4_max_len, char *mbs);
bool taosValidateEncodec(char *encodec); bool taosValidateEncodec(char *encodec);
bool taosGetVersionNumber(char *versionStr, int *versionNubmer);
static FORCE_INLINE void taosEncryptPass(uint8_t *inBuf, unsigned int inLen, char *target) { static FORCE_INLINE void taosEncryptPass(uint8_t *inBuf, unsigned int inLen, char *target) {
MD5_CTX context; MD5_CTX context;
MD5Init(&context); MD5Init(&context);
......
...@@ -469,4 +469,33 @@ bool taosValidateEncodec(char *encodec) { ...@@ -469,4 +469,33 @@ bool taosValidateEncodec(char *encodec) {
#else #else
return true; return true;
#endif #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;
} }
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册