fix(analytics): fix errors in parsing options.
This commit is contained in:
parent
af1c0c98bb
commit
ac3081a4a4
|
@ -128,30 +128,34 @@ void taosAnalUpdate(int64_t newVer, SHashObj *pHash) {
|
||||||
|
|
||||||
bool taosAnalGetOptStr(const char *option, const char *optName, char *optValue, int32_t optMaxLen) {
|
bool taosAnalGetOptStr(const char *option, const char *optName, char *optValue, int32_t optMaxLen) {
|
||||||
char buf[TSDB_ANALYTIC_ALGO_OPTION_LEN] = {0};
|
char buf[TSDB_ANALYTIC_ALGO_OPTION_LEN] = {0};
|
||||||
char *pStart = strstr(option, optName);
|
char *pStart = NULL;
|
||||||
char *pEnd = strstr(pStart, ANAL_ALGO_SPLIT);
|
char *pEnd = NULL;
|
||||||
|
|
||||||
if (pStart != NULL) {
|
pStart = strstr(option, optName);
|
||||||
if (optMaxLen > 0) {
|
if (pStart == NULL) {
|
||||||
int32_t copyLen = optMaxLen;
|
|
||||||
if (pEnd > pStart) {
|
|
||||||
copyLen = (int32_t)(pEnd - pStart - strlen(optName));
|
|
||||||
copyLen = MIN(copyLen, optMaxLen);
|
|
||||||
tstrncpy(buf, pStart, copyLen);
|
|
||||||
} else {
|
|
||||||
int32_t len = MIN(tListLen(buf), strlen(pStart) + 1);
|
|
||||||
tstrncpy(buf, pStart, len);
|
|
||||||
}
|
|
||||||
|
|
||||||
char *pRight = strstr(buf, "=") + 1;
|
|
||||||
strtrim(pRight);
|
|
||||||
|
|
||||||
tstrncpy(optValue, pRight, strlen(pRight) + 1);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pEnd = strstr(pStart, ANAL_ALGO_SPLIT);
|
||||||
|
if (optMaxLen > 0) {
|
||||||
|
int32_t copyLen = 0;
|
||||||
|
if (pEnd > pStart) {
|
||||||
|
copyLen = (int32_t)(pEnd - pStart);
|
||||||
|
copyLen = MIN(copyLen + 1, TSDB_ANALYTIC_ALGO_OPTION_LEN);
|
||||||
|
tstrncpy(buf, pStart, copyLen);
|
||||||
|
} else {
|
||||||
|
int32_t len = MIN(tListLen(buf), strlen(pStart) + 1);
|
||||||
|
tstrncpy(buf, pStart, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
char *pRight = strstr(buf, "=") + 1;
|
||||||
|
strtrim(pRight);
|
||||||
|
|
||||||
|
int32_t vLen = MIN(optMaxLen, strlen(pRight) + 1);
|
||||||
|
tstrncpy(optValue, pRight, vLen);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool taosAnalGetOptInt(const char *option, const char *optName, int64_t *optValue) {
|
bool taosAnalGetOptInt(const char *option, const char *optName, int64_t *optValue) {
|
||||||
|
|
Loading…
Reference in New Issue