From da7fd6459a955b21942f567eb1c8b76d079bea4d Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Tue, 9 Jun 2020 02:40:31 +0000 Subject: [PATCH] [TD_543] fix coverity scan, cid:267831 --- src/plugins/http/src/gcHandle.c | 22 +++++++++++++++++++-- src/plugins/http/src/httpSql.c | 2 +- src/plugins/http/src/restHandle.c | 32 ++++++++++++++++++++++++++++--- src/plugins/http/src/tgHandle.c | 13 ++++++++++--- 4 files changed, 60 insertions(+), 9 deletions(-) diff --git a/src/plugins/http/src/gcHandle.c b/src/plugins/http/src/gcHandle.c index fbe6757ccb..4120980123 100644 --- a/src/plugins/http/src/gcHandle.c +++ b/src/plugins/http/src/gcHandle.c @@ -22,9 +22,27 @@ #include "taosdef.h" static HttpDecodeMethod gcDecodeMethod = {"grafana", gcProcessRequest}; -static HttpEncodeMethod gcHeartBeatMethod = {NULL, gcSendHeartBeatResp, NULL, NULL, NULL, NULL, NULL, NULL}; +static HttpEncodeMethod gcHeartBeatMethod = { + .startJsonFp = NULL, + .stopJsonFp = gcSendHeartBeatResp, + .buildQueryJsonFp = NULL, + .buildAffectRowJsonFp = NULL, + .initJsonFp = NULL, + .cleanJsonFp = NULL, + .checkFinishedFp = NULL, + .setNextCmdFp = NULL +}; + static HttpEncodeMethod gcQueryMethod = { - NULL, gcStopQueryJson, gcBuildQueryJson, NULL, gcInitQueryJson, gcCleanQueryJson, NULL, NULL}; + .startJsonFp = NULL, + .stopJsonFp = gcStopQueryJson, + .buildQueryJsonFp = gcBuildQueryJson, + .buildAffectRowJsonFp = NULL, + .initJsonFp = gcInitQueryJson, + .cleanJsonFp = gcCleanQueryJson, + .checkFinishedFp = NULL, + .setNextCmdFp = NULL +}; void gcInitHandle(HttpServer* pServer) { httpAddMethod(pServer, &gcDecodeMethod); } diff --git a/src/plugins/http/src/httpSql.c b/src/plugins/http/src/httpSql.c index af9ad8e38a..6ff93b3e8a 100644 --- a/src/plugins/http/src/httpSql.c +++ b/src/plugins/http/src/httpSql.c @@ -87,7 +87,7 @@ void httpProcessMultiSqlCallBack(void *param, TAOS_RES *result, int code) { } if (code < 0) { - if (encode->checkFinishedFp != NULL && !encode->checkFinishedFp(pContext, singleCmd, code >= 0 ? 0 : code)) { + if (encode->checkFinishedFp != NULL && !encode->checkFinishedFp(pContext, singleCmd, -code)) { singleCmd->code = code; httpTrace("context:%p, fd:%d, ip:%s, user:%s, process pos jump to:%d, last code:%s, last sql:%s", pContext, pContext->fd, pContext->ipstr, pContext->user, multiCmds->pos + 1, tstrerror(code), sql); diff --git a/src/plugins/http/src/restHandle.c b/src/plugins/http/src/restHandle.c index a2dc7d06a1..d481a654d8 100644 --- a/src/plugins/http/src/restHandle.c +++ b/src/plugins/http/src/restHandle.c @@ -22,11 +22,37 @@ static HttpDecodeMethod restDecodeMethod = {"rest", restProcessRequest}; static HttpDecodeMethod restDecodeMethod2 = {"restful", restProcessRequest}; static HttpEncodeMethod restEncodeSqlTimestampMethod = { - restStartSqlJson, restStopSqlJson, restBuildSqlTimestampJson, restBuildSqlAffectRowsJson, NULL, NULL, NULL, NULL}; + .startJsonFp = restStartSqlJson, + .stopJsonFp = restStopSqlJson, + .buildQueryJsonFp = restBuildSqlTimestampJson, + .buildAffectRowJsonFp = restBuildSqlAffectRowsJson, + .initJsonFp = NULL, + .cleanJsonFp = NULL, + .checkFinishedFp = NULL, + .setNextCmdFp = NULL +}; + static HttpEncodeMethod restEncodeSqlLocalTimeStringMethod = { - restStartSqlJson, restStopSqlJson, restBuildSqlLocalTimeStringJson, restBuildSqlAffectRowsJson, NULL, NULL, NULL, NULL}; + .startJsonFp = restStartSqlJson, + .stopJsonFp = restStopSqlJson, + .buildQueryJsonFp = restBuildSqlLocalTimeStringJson, + .buildAffectRowJsonFp = restBuildSqlAffectRowsJson, + .initJsonFp = NULL, + .cleanJsonFp = NULL, + .checkFinishedFp = NULL, + .setNextCmdFp = NULL +}; + static HttpEncodeMethod restEncodeSqlUtcTimeStringMethod = { - restStartSqlJson, restStopSqlJson, restBuildSqlUtcTimeStringJson, restBuildSqlAffectRowsJson, NULL, NULL, NULL, NULL}; + .startJsonFp = restStartSqlJson, + .stopJsonFp = restStopSqlJson, + .buildQueryJsonFp = restBuildSqlUtcTimeStringJson, + .buildAffectRowJsonFp = restBuildSqlAffectRowsJson, + .initJsonFp = NULL, + .cleanJsonFp = NULL, + .checkFinishedFp = NULL, + .setNextCmdFp = NULL +}; void restInitHandle(HttpServer* pServer) { httpAddMethod(pServer, &restDecodeMethod); diff --git a/src/plugins/http/src/tgHandle.c b/src/plugins/http/src/tgHandle.c index ac3df051fd..c6a2230bfb 100644 --- a/src/plugins/http/src/tgHandle.c +++ b/src/plugins/http/src/tgHandle.c @@ -62,9 +62,16 @@ #define TG_MAX_SORT_TAG_SIZE 20 static HttpDecodeMethod tgDecodeMethod = {"telegraf", tgProcessRquest}; -static HttpEncodeMethod tgQueryMethod = {tgStartQueryJson, tgStopQueryJson, NULL, - tgBuildSqlAffectRowsJson, tgInitQueryJson, tgCleanQueryJson, - tgCheckFinished, tgSetNextCmd}; +static HttpEncodeMethod tgQueryMethod = { + .startJsonFp = tgStartQueryJson, + .stopJsonFp = tgStopQueryJson, + .buildQueryJsonFp = NULL, + .buildAffectRowJsonFp = tgBuildSqlAffectRowsJson, + .initJsonFp = tgInitQueryJson, + .cleanJsonFp = tgCleanQueryJson, + .checkFinishedFp = tgCheckFinished, + .setNextCmdFp = tgSetNextCmd +}; static const char DEFAULT_TELEGRAF_CFG[] = "{\"metrics\":[" -- GitLab