From 5b266515ac682da510498d5b34799d9dded0b70f Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Wed, 15 Sep 2021 18:05:22 +0800 Subject: [PATCH] [TD-6645/enhance]: make schemaless non-doube-quoted content case-insensitive --- src/client/src/tscParseLineProtocol.c | 44 +++++++++++---------------- src/client/src/tscParseOpenTSDB.c | 5 ++- 2 files changed, 22 insertions(+), 27 deletions(-) diff --git a/src/client/src/tscParseLineProtocol.c b/src/client/src/tscParseLineProtocol.c index e26e439492..6c5407d0a5 100644 --- a/src/client/src/tscParseLineProtocol.c +++ b/src/client/src/tscParseLineProtocol.c @@ -1212,7 +1212,7 @@ static bool isTinyInt(char *pVal, uint16_t len) { if (len <= 2) { return false; } - if (!strcmp(&pVal[len - 2], "i8")) { + if (!strcasecmp(&pVal[len - 2], "i8")) { //printf("Type is int8(%s)\n", pVal); return true; } @@ -1226,7 +1226,7 @@ static bool isTinyUint(char *pVal, uint16_t len) { if (pVal[0] == '-') { return false; } - if (!strcmp(&pVal[len - 2], "u8")) { + if (!strcasecmp(&pVal[len - 2], "u8")) { //printf("Type is uint8(%s)\n", pVal); return true; } @@ -1237,7 +1237,7 @@ static bool isSmallInt(char *pVal, uint16_t len) { if (len <= 3) { return false; } - if (!strcmp(&pVal[len - 3], "i16")) { + if (!strcasecmp(&pVal[len - 3], "i16")) { //printf("Type is int16(%s)\n", pVal); return true; } @@ -1251,7 +1251,7 @@ static bool isSmallUint(char *pVal, uint16_t len) { if (pVal[0] == '-') { return false; } - if (strcmp(&pVal[len - 3], "u16") == 0) { + if (strcasecmp(&pVal[len - 3], "u16") == 0) { //printf("Type is uint16(%s)\n", pVal); return true; } @@ -1262,7 +1262,7 @@ static bool isInt(char *pVal, uint16_t len) { if (len <= 3) { return false; } - if (strcmp(&pVal[len - 3], "i32") == 0) { + if (strcasecmp(&pVal[len - 3], "i32") == 0) { //printf("Type is int32(%s)\n", pVal); return true; } @@ -1276,7 +1276,7 @@ static bool isUint(char *pVal, uint16_t len) { if (pVal[0] == '-') { return false; } - if (strcmp(&pVal[len - 3], "u32") == 0) { + if (strcasecmp(&pVal[len - 3], "u32") == 0) { //printf("Type is uint32(%s)\n", pVal); return true; } @@ -1287,7 +1287,7 @@ static bool isBigInt(char *pVal, uint16_t len) { if (len <= 3) { return false; } - if (strcmp(&pVal[len - 3], "i64") == 0) { + if (strcasecmp(&pVal[len - 3], "i64") == 0) { //printf("Type is int64(%s)\n", pVal); return true; } @@ -1301,7 +1301,7 @@ static bool isBigUint(char *pVal, uint16_t len) { if (pVal[0] == '-') { return false; } - if (strcmp(&pVal[len - 3], "u64") == 0) { + if (strcasecmp(&pVal[len - 3], "u64") == 0) { //printf("Type is uint64(%s)\n", pVal); return true; } @@ -1312,7 +1312,7 @@ static bool isFloat(char *pVal, uint16_t len) { if (len <= 3) { return false; } - if (strcmp(&pVal[len - 3], "f32") == 0) { + if (strcasecmp(&pVal[len - 3], "f32") == 0) { //printf("Type is float(%s)\n", pVal); return true; } @@ -1323,7 +1323,7 @@ static bool isDouble(char *pVal, uint16_t len) { if (len <= 3) { return false; } - if (strcmp(&pVal[len - 3], "f64") == 0) { + if (strcasecmp(&pVal[len - 3], "f64") == 0) { //printf("Type is double(%s)\n", pVal); return true; } @@ -1331,34 +1331,24 @@ static bool isDouble(char *pVal, uint16_t len) { } static bool isBool(char *pVal, uint16_t len, bool *bVal) { - if ((len == 1) && - (pVal[len - 1] == 't' || - pVal[len - 1] == 'T')) { + if ((len == 1) && !strcasecmp(&pVal[len - 1], "t")) { //printf("Type is bool(%c)\n", pVal[len - 1]); *bVal = true; return true; } - if ((len == 1) && - (pVal[len - 1] == 'f' || - pVal[len - 1] == 'F')) { + if ((len == 1) && !strcasecmp(&pVal[len - 1], "f")) { //printf("Type is bool(%c)\n", pVal[len - 1]); *bVal = false; return true; } - if((len == 4) && - (!strcmp(&pVal[len - 4], "true") || - !strcmp(&pVal[len - 4], "True") || - !strcmp(&pVal[len - 4], "TRUE"))) { + if((len == 4) && !strcasecmp(&pVal[len - 4], "true")) { //printf("Type is bool(%s)\n", &pVal[len - 4]); *bVal = true; return true; } - if((len == 5) && - (!strcmp(&pVal[len - 5], "false") || - !strcmp(&pVal[len - 5], "False") || - !strcmp(&pVal[len - 5], "FALSE"))) { + if((len == 5) && !strcasecmp(&pVal[len - 5], "false")) { //printf("Type is bool(%s)\n", &pVal[len - 5]); *bVal = false; return true; @@ -1384,7 +1374,7 @@ static bool isNchar(char *pVal, uint16_t len) { if (len < 3) { return false; } - if (pVal[0] == 'L' && pVal[1] == '"' && pVal[len - 1] == '"') { + if ((pVal[0] == 'l' || pVal[0] == 'L')&& pVal[1] == '"' && pVal[len - 1] == '"') { //printf("Type is nchar(%s)\n", pVal); return true; } @@ -1434,7 +1424,7 @@ static bool isTimeStamp(char *pVal, uint16_t len, SMLTimeStampType *tsType) { return false; } -static bool convertStrToNumber(TAOS_SML_KV *pVal, char*str, SSmlLinesInfo* info) { +static bool convertStrToNumber(TAOS_SML_KV *pVal, char *str, SSmlLinesInfo* info) { errno = 0; uint8_t type = pVal->type; int16_t length = pVal->length; @@ -1442,6 +1432,7 @@ static bool convertStrToNumber(TAOS_SML_KV *pVal, char*str, SSmlLinesInfo* info) uint64_t val_u; double val_d; + strntolower_s(str, str, strlen(str)); if (IS_FLOAT_TYPE(type)) { val_d = strtod(str, NULL); } else { @@ -1724,6 +1715,7 @@ int32_t convertSmlTimeStamp(TAOS_SML_KV *pVal, char *value, SMLTimeStampType type; int64_t tsVal; + strntolower_s(value, value, len); if (!isTimeStamp(value, len, &type)) { return TSDB_CODE_TSC_INVALID_TIME_STAMP; } diff --git a/src/client/src/tscParseOpenTSDB.c b/src/client/src/tscParseOpenTSDB.c index 8e0322cab0..69a2db4345 100644 --- a/src/client/src/tscParseOpenTSDB.c +++ b/src/client/src/tscParseOpenTSDB.c @@ -38,7 +38,7 @@ static int32_t parseTelnetMetric(TAOS_SML_DATA_POINT *pSml, const char **index, uint16_t len = 0; pSml->stableName = tcalloc(TSDB_TABLE_NAME_LEN + 1, 1); // +1 to avoid 1772 line over write - if (pSml->stableName == NULL){ + if (pSml->stableName == NULL) { return TSDB_CODE_TSC_OUT_OF_MEMORY; } if (isdigit(*cur)) { @@ -485,6 +485,7 @@ int32_t parseTimestampFromJSONObj(cJSON *root, int64_t *tsVal, SSmlLinesInfo* in } size_t typeLen = strlen(type->valuestring); + strntolower_s(type->valuestring, type->valuestring, typeLen); if (typeLen == 1 && type->valuestring[0] == 's') { //seconds *tsVal = (int64_t)(*tsVal * 1e9); @@ -505,6 +506,8 @@ int32_t parseTimestampFromJSONObj(cJSON *root, int64_t *tsVal, SSmlLinesInfo* in default: return TSDB_CODE_TSC_INVALID_JSON; } + } else { + return TSDB_CODE_TSC_INVALID_JSON; } return TSDB_CODE_SUCCESS; -- GitLab