This commit is contained in:
Shengliang Guan 2020-09-14 06:49:00 +00:00
parent eff4b5807a
commit 7dd32d26cf
15 changed files with 255 additions and 456 deletions

View File

@ -248,37 +248,104 @@ TAOS_DEFINE_ERROR(TSDB_CODE_SYN_NOT_ENABLED, 0, 0x0901, "Sync modul
TAOS_DEFINE_ERROR(TSDB_CODE_WAL_APP_ERROR, 0, 0x1000, "Unexpected generic error in wal") TAOS_DEFINE_ERROR(TSDB_CODE_WAL_APP_ERROR, 0, 0x1000, "Unexpected generic error in wal")
// http // http
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_UNSUPPORT_URL, 0, 0x1100, "http url is not support") TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_SERVER_OFFLINE, 0, 0x1100, "http server is not onlin")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_NO_ENOUGH_MEMORY, 0, 0x1101, "no enough memory") TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_UNSUPPORT_URL, 0, 0x1101, "url is not support")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_INVALID_VERSION, 0, 0x1102, "invalid http version") TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_INVLALID_URL, 0, 0x1102, "invalid url format")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_INVALID_CONTENT_LENGTH, 0, 0x1103, "invalid content length") TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_NO_ENOUGH_MEMORY, 0, 0x1103, "no enough memory")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_CREATE_GZIP_FAILED, 0, 0x1104, "failed to create gzip") TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_REQUSET_TOO_BIG, 0, 0x1104, "request size is too big")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_FINISH_GZIP_FAILED, 0, 0x1105, "failed to finish gzip") TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_NO_AUTH_INFO, 0, 0x1105, "no auth info input")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_INVALID_AUTH_TYPE, 0, 0x1106, "invalid type of Authorization") TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_NO_MSG_INPUT, 0, 0x1106, "request is empty")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_INVALID_AUTH_FORMAT, 0, 0x1107, "invalid format of Authorization") TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_NO_SQL_INPUT, 0, 0x1107, "no sql input")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_INVALID_BASIC_AUTH, 0, 0x1108, "invalid basic Authorization") TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_NO_EXEC_USEDB, 0, 0x1108, "no need to execute use db cmd")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_INVALID_TAOSD_AUTH, 0, 0x1109, "invalid taosd Authorization") TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_SESSION_FULL, 0, 0x1109, "session list was full")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_PARSE_METHOD_FAILED, 0, 0x110A, "failed to parse method") TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_GEN_TAOSD_TOKEN_ERR, 0, 0x110A, "generate taosd token error")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_PARSE_TARGET_FAILED, 0, 0x110B, "failed to parse target") TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_INVALID_MULTI_REQUEST, 0, 0x110B, "size of multi request is 0")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_PARSE_VERSION_FAILED, 0, 0x110C, "failed to parse http version") TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_CREATE_GZIP_FAILED, 0, 0x110C, "failed to create gzip")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_PARSE_SP_FAILED, 0, 0x110D, "failed to parse sp") TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_FINISH_GZIP_FAILED, 0, 0x110D, "failed to finish gzip")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_PARSE_STATUS_FAILED, 0, 0x110E, "failed to parse status") TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_LOGIN_FAILED, 0, 0x110E, "failed to login")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_PARSE_PHRASE_FAILED, 0, 0x110F, "failed to parse phrase")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_PARSE_CRLF_FAILED, 0, 0x1110, "failed to parse crlf")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_PARSE_HEADER_FAILED, 0, 0x1111, "failed to parse header")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_PARSE_HEADER_KEY_FAILED, 0, 0x1112, "failed to parse header key")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_PARSE_HEADER_VAL_FAILED, 0, 0x1113, "failed to parse header val")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_PARSE_CHUNK_SIZE_FAILED, 0, 0x1114, "failed to parse chunk size")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_PARSE_CHUNK_FAILED, 0, 0x1115, "failed to parse chunk")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_PARSE_END_FAILED, 0, 0x1116, "failed to parse end section")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_PARSE_INVALID_STATE, 0, 0x1117, "invalid parse state")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_PARSE_ERROR_STATE, 0, 0x1118, "failed to parse error section")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_INVALID_VERSION, 0, 0x1120, "invalid http version")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_INVALID_CONTENT_LENGTH, 0, 0x1121, "invalid content length")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_INVALID_AUTH_TYPE, 0, 0x1122, "invalid type of Authorization")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_INVALID_AUTH_FORMAT, 0, 0x1123, "invalid format of Authorization")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_INVALID_BASIC_AUTH, 0, 0x1124, "invalid basic Authorization")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_INVALID_TAOSD_AUTH, 0, 0x1125, "invalid taosd Authorization")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_PARSE_METHOD_FAILED, 0, 0x1126, "failed to parse method")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_PARSE_TARGET_FAILED, 0, 0x1127, "failed to parse target")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_PARSE_VERSION_FAILED, 0, 0x1128, "failed to parse http version")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_PARSE_SP_FAILED, 0, 0x1129, "failed to parse sp")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_PARSE_STATUS_FAILED, 0, 0x112A, "failed to parse status")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_PARSE_PHRASE_FAILED, 0, 0x112B, "failed to parse phrase")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_PARSE_CRLF_FAILED, 0, 0x112C, "failed to parse crlf")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_PARSE_HEADER_FAILED, 0, 0x112D, "failed to parse header")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_PARSE_HEADER_KEY_FAILED, 0, 0x112E, "failed to parse header key")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_PARSE_HEADER_VAL_FAILED, 0, 0x112F, "failed to parse header val")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_PARSE_CHUNK_SIZE_FAILED, 0, 0x1130, "failed to parse chunk size")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_PARSE_CHUNK_FAILED, 0, 0x1131, "failed to parse chunk")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_PARSE_END_FAILED, 0, 0x1132, "failed to parse end section")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_PARSE_INVALID_STATE, 0, 0x1134, "invalid parse state")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_PARSE_ERROR_STATE, 0, 0x1135, "failed to parse error section")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_GC_QUERY_NULL, 0, 0x1150, "query size is 0")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_GC_QUERY_SIZE, 0, 0x1151, "query size can not more than 100")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_GC_REQ_PARSE_ERROR, 0, 0x1152, "parse grafana json error")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_TG_DB_NOT_INPUT, 0, 0x1160, "database name can not be null")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_TG_DB_TOO_LONG, 0, 0x1161, "database name too long")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_TG_INVALID_JSON, 0, 0x1162, "invalid telegraf json fromat")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_TG_METRICS_NULL, 0, 0x1163, "metrics size is 0")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_TG_METRICS_SIZE, 0, 0x1164, "metrics size can not more than 1K")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_TG_METRIC_NULL, 0, 0x1165, "metric name not find")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_TG_METRIC_TYPE, 0, 0x1166, "metric name type should be string")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_TG_METRIC_NAME_NULL, 0, 0x1167, "metric name length is 0")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_TG_METRIC_NAME_LONG, 0, 0x1168, "metric name length too long")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_TG_TIMESTAMP_NULL, 0, 0x1169, "timestamp not find")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_TG_TIMESTAMP_TYPE, 0, 0x116A, "timestamp type should be integer")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_TG_TIMESTAMP_VAL_NULL, 0, 0x116B, "timestamp value smaller than 0")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_TG_TAGS_NULL, 0, 0x116C, "tags not find")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_TG_TAGS_SIZE_0, 0, 0x116D, "tags size too long")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_TG_TAGS_SIZE_LONG, 0, 0x116E, "tags size is 0")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_TG_TAG_NULL, 0, 0x116F, "tag is null")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_TG_TAG_NAME_NULL, 0, 0x1170, "tag name is null")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_TG_TAG_NAME_SIZE, 0, 0x1171, "tag name length too long")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_TG_TAG_VALUE_TYPE, 0, 0x1172, "tag value type should be number or string")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_TG_TAG_VALUE_NULL, 0, 0x1173, "tag value is null")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_TG_TABLE_NULL, 0, 0x1174, "table is null")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_TG_TABLE_SIZE, 0, 0x1175, "table name length too long")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_TG_FIELDS_NULL, 0, 0x1176, "fields not find")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_TG_FIELDS_SIZE_0, 0, 0x1177, "fields size is 0")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_TG_FIELDS_SIZE_LONG, 0, 0x1178, "fields size too long")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_TG_FIELD_NULL, 0, 0x1179, "field is null")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_TG_FIELD_NAME_NULL, 0, 0x117A, "field name is null")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_TG_FIELD_NAME_SIZE, 0, 0x117B, "field name length too long")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_TG_FIELD_VALUE_TYPE, 0, 0x117C, "field value type should be number or string")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_TG_FIELD_VALUE_NULL, 0, 0x117D, "field value is null")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_TG_HOST_NOT_STRING, 0, 0x117E, "host type should be string")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_TG_STABLE_NOT_EXIST, 0, 0x117F, "stable not exist")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_OP_DB_NOT_INPUT, 0, 0x1190, "database name can not be null")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_OP_DB_TOO_LONG, 0, 0x1191, "database name too long")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_OP_INVALID_JSON, 0, 0x1192, "invalid opentsdb json fromat")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_OP_METRICS_NULL, 0, 0x1193, "metrics size is 0")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_OP_METRICS_SIZE, 0, 0x1194, "metrics size can not more than 10K")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_OP_METRIC_NULL, 0, 0x1195, "metric name not find")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_OP_METRIC_TYPE, 0, 0x1196, "metric name type should be string")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_OP_METRIC_NAME_NULL, 0, 0x1197, "metric name length is 0")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_OP_METRIC_NAME_LONG, 0, 0x1198, "metric name length can not more than 22")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_OP_TIMESTAMP_NULL, 0, 0x1199, "timestamp not find")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_OP_TIMESTAMP_TYPE, 0, 0x119A, "timestamp type should be integer")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_OP_TIMESTAMP_VAL_NULL, 0, 0x119B, "timestamp value smaller than 0")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_OP_TAGS_NULL, 0, 0x119C, "tags not find")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_OP_TAGS_SIZE_0, 0, 0x119D, "tags size is 0")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_OP_TAGS_SIZE_LONG, 0, 0x119E, "tags size too long")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_OP_TAG_NULL, 0, 0x119F, "tag is null")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_OP_TAG_NAME_NULL, 0, 0x11A0, "tag name is null")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_OP_TAG_NAME_SIZE, 0, 0x11A1, "tag name length too long")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_OP_TAG_VALUE_TYPE, 0, 0x11A2, "tag value type should be boolean, number or string")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_OP_TAG_VALUE_NULL, 0, 0x11A3, "tag value is null")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_OP_TAG_VALUE_TOO_LONG, 0, 0x11A4, "tag value can not more than 64")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_OP_VALUE_NULL, 0, 0x11A5, "value not find")
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_OP_VALUE_TYPE, 0, 0x11A5, "value type should be boolean, number or string")
#ifdef TAOS_ERROR_C #ifdef TAOS_ERROR_C
}; };

View File

@ -1,112 +0,0 @@
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TDENGINE_HTTP_CODE_H
#define TDENGINE_HTTP_CODE_H
//for fixed msg info
#define HTTP_SUCCESS 0
#define HTTP_SERVER_OFFLINE 1
#define HTTP_UNSUPPORT_URL 2
#define HTTP_PARSE_HTTP_METHOD_ERROR 3
#define HTTP_PARSE_HTTP_VERSION_ERROR 4
#define HTTP_PARSE_HEAD_ERROR 5
#define HTTP_REQUSET_TOO_BIG 6
#define HTTP_PARSE_BODY_ERROR 7
#define HTTP_PARSE_CHUNKED_BODY_ERROR 8
#define HTTP_PARSE_URL_ERROR 9
#define HTTP_INVALID_AUTH_TOKEN 10
#define HTTP_PARSE_USR_ERROR 11
#define HTTP_NO_SQL_INPUT 12
#define HTTP_SESSION_FULL 13
#define HTTP_NO_ENOUGH_MEMORY 14
#define HTTP_GEN_TAOSD_TOKEN_ERR 15
#define HTTP_INVALID_DB_TABLE 16
#define HTTP_NO_EXEC_USEDB 17
#define HTTP_PARSE_GC_REQ_ERROR 18
#define HTTP_INVALID_MULTI_REQUEST 19
#define HTTP_NO_MSG_INPUT 20
#define HTTP_NO_ENOUGH_SESSIONS 21
//telegraf
#define HTTP_TG_DB_NOT_INPUT 22
#define HTTP_TG_DB_TOO_LONG 23
#define HTTP_TG_INVALID_JSON 24
#define HTTP_TG_METRICS_NULL 25
#define HTTP_TG_METRICS_SIZE 26
#define HTTP_TG_METRIC_NULL 27
#define HTTP_TG_METRIC_TYPE 28
#define HTTP_TG_METRIC_NAME_NULL 29
#define HTTP_TG_METRIC_NAME_LONG 30
#define HTTP_TG_TIMESTAMP_NULL 31
#define HTTP_TG_TIMESTAMP_TYPE 32
#define HTTP_TG_TIMESTAMP_VAL_NULL 33
#define HTTP_TG_TAGS_NULL 34
#define HTTP_TG_TAGS_SIZE_0 35
#define HTTP_TG_TAGS_SIZE_LONG 36
#define HTTP_TG_TAG_NULL 37
#define HTTP_TG_TAG_NAME_NULL 38
#define HTTP_TG_TAG_NAME_SIZE 39
#define HTTP_TG_TAG_VALUE_TYPE 40
#define HTTP_TG_TAG_VALUE_NULL 41
#define HTTP_TG_TABLE_NULL 42
#define HTTP_TG_TABLE_SIZE 43
#define HTTP_TG_FIELDS_NULL 44
#define HTTP_TG_FIELDS_SIZE_0 45
#define HTTP_TG_FIELDS_SIZE_LONG 46
#define HTTP_TG_FIELD_NULL 47
#define HTTP_TG_FIELD_NAME_NULL 48
#define HTTP_TG_FIELD_NAME_SIZE 49
#define HTTP_TG_FIELD_VALUE_TYPE 50
#define HTTP_TG_FIELD_VALUE_NULL 51
#define HTTP_INVALID_BASIC_AUTH_TOKEN 52
#define HTTP_INVALID_TAOSD_AUTH_TOKEN 53
#define HTTP_TG_HOST_NOT_STRING 54
//grafana
#define HTTP_GC_QUERY_NULL 55
#define HTTP_GC_QUERY_SIZE 56
//opentsdb
#define HTTP_OP_DB_NOT_INPUT 57
#define HTTP_OP_DB_TOO_LONG 58
#define HTTP_OP_INVALID_JSON 59
#define HTTP_OP_METRICS_NULL 60
#define HTTP_OP_METRICS_SIZE 61
#define HTTP_OP_METRIC_NULL 62
#define HTTP_OP_METRIC_TYPE 63
#define HTTP_OP_METRIC_NAME_NULL 64
#define HTTP_OP_METRIC_NAME_LONG 65
#define HTTP_OP_TIMESTAMP_NULL 66
#define HTTP_OP_TIMESTAMP_TYPE 67
#define HTTP_OP_TIMESTAMP_VAL_NULL 68
#define HTTP_OP_TAGS_NULL 69
#define HTTP_OP_TAGS_SIZE_0 70
#define HTTP_OP_TAGS_SIZE_LONG 71
#define HTTP_OP_TAG_NULL 72
#define HTTP_OP_TAG_NAME_NULL 73
#define HTTP_OP_TAG_NAME_SIZE 74
#define HTTP_OP_TAG_VALUE_TYPE 75
#define HTTP_OP_TAG_VALUE_NULL 76
#define HTTP_OP_TAG_VALUE_TOO_LONG 77
#define HTTP_OP_VALUE_NULL 78
#define HTTP_OP_VALUE_TYPE 79
//tgf
#define HTTP_TG_STABLE_NOT_EXIST 80
extern char *httpMsg[];
#endif

View File

@ -24,7 +24,6 @@
#include "tutil.h" #include "tutil.h"
#include "zlib.h" #include "zlib.h"
#include "http.h" #include "http.h"
#include "httpCode.h"
#include "httpLog.h" #include "httpLog.h"
#include "httpJson.h" #include "httpJson.h"
#include "httpParser.h" #include "httpParser.h"
@ -37,7 +36,7 @@
#define HTTP_BUFFER_SIZE 8192000 #define HTTP_BUFFER_SIZE 8192000
#define HTTP_STEP_SIZE 1024 //http message get process step by step #define HTTP_STEP_SIZE 1024 //http message get process step by step
#define HTTP_METHOD_SCANNER_SIZE 7 //http method fp size #define HTTP_METHOD_SCANNER_SIZE 7 //http method fp size
#define HTTP_GC_TARGET_SIZE 512 #define TSDB_CODE_HTTP_GC_TARGET_SIZE 512
#define HTTP_WRITE_RETRY_TIMES 500 #define HTTP_WRITE_RETRY_TIMES 500
#define HTTP_WRITE_WAIT_TIME_MS 5 #define HTTP_WRITE_WAIT_TIME_MS 5
#define HTTP_SESSION_ID_LEN (TSDB_USER_LEN + TSDB_PASSWORD_LEN) #define HTTP_SESSION_ID_LEN (TSDB_USER_LEN + TSDB_PASSWORD_LEN)

View File

@ -33,8 +33,6 @@ enum _httpRespTempl {
extern const char *httpRespTemplate[]; extern const char *httpRespTemplate[];
void httpSendErrorResp(HttpContext *pContext, int32_t errNo); void httpSendErrorResp(HttpContext *pContext, int32_t errNo);
void httpSendErrorRespWithDesc(HttpContext *pContext, int32_t errNo, char *desc);
void httpSendTaosdErrorResp(HttpContext *pContext, int32_t errCode);
void httpSendTaosdInvalidSqlErrorResp(HttpContext *pContext, char* errMsg); void httpSendTaosdInvalidSqlErrorResp(HttpContext *pContext, char* errMsg);
void httpSendSuccResp(HttpContext *pContext, char *desc); void httpSendSuccResp(HttpContext *pContext, char *desc);
void httpSendOptionResp(HttpContext *pContext, char *desc); void httpSendOptionResp(HttpContext *pContext, char *desc);

View File

@ -1,108 +0,0 @@
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define _DEFAULT_SOURCE
char* httpMsg[] = {
"success", // 0
"http server is not online", // 1
"http url is not support", // 2
"http method parse error", // 3
"http version should be 1.0, 1.1 or 1.2", // 4
"http head parse error", // 5
"request size is too big",
"http body size invalid",
"http chunked body parse error", // 8
"http url parse error", // 9
"invalid type of Authorization",
"no auth info input",
"no sql input",
"session list was full",
"no enough memory to alloc sqls",
"generate taosd token error",
"db and table can not be null",
"no need to execute use db cmd",
"parse grafana json error",
"size of multi request is 0", // 19
"request is empty", // 20
"no enough connections for http", // 21
// telegraf
"database name can not be null", // 22
"database name too long",
"invalid telegraf json fromat",
"metrics size is 0",
"metrics size can not more than 1K", // 26
"metric name not find",
"metric name type should be string",
"metric name length is 0",
"metric name length too long",
"timestamp not find", // 31
"timestamp type should be integer",
"timestamp value smaller than 0",
"tags not find",
"tags size is 0",
"tags size too long", // 36
"tag is null",
"tag name is null",
"tag name length too long", // 39
"tag value type should be number or string",
"tag value is null",
"table is null", // 42
"table name length too long",
"fields not find", // 44
"fields size is 0",
"fields size too long",
"field is null", // 47
"field name is null",
"field name length too long", // 49
"field value type should be number or string",
"field value is null", // 51
"parse basic auth token error",
"parse http auth token error",
"host type should be string",
// grafana
"query size is 0", // 55
"query size can not more than 100",
// opentsdb
"database name can not be null", // 57
"database name too long",
"invalid opentsdb json fromat", // 59
"metrics size is 0",
"metrics size can not more than 10K", // 61
"metric name not find",
"metric name type should be string",
"metric name length is 0",
"metric name length can not more than 22",
"timestamp not find",
"timestamp type should be integer",
"timestamp value smaller than 0",
"tags not find",
"tags size is 0",
"tags size too long", // 71
"tag is null",
"tag name is null",
"tag name length too long", // 74
"tag value type should be boolean, number or string",
"tag value is null",
"tag value can not more than 64", // 77
"value not find",
"value type should be boolean, number or string",
"stable not exist",
};

View File

@ -16,6 +16,7 @@
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "os.h" #include "os.h"
#include "taosdef.h" #include "taosdef.h"
#include "taoserror.h"
#include "cJSON.h" #include "cJSON.h"
#include "httpLog.h" #include "httpLog.h"
#include "httpGcHandle.h" #include "httpGcHandle.h"
@ -146,31 +147,31 @@ bool gcProcessQueryRequest(HttpContext* pContext) {
char* filter = pContext->parser->body.str; char* filter = pContext->parser->body.str;
if (filter == NULL) { if (filter == NULL) {
httpSendErrorResp(pContext, HTTP_NO_MSG_INPUT); httpSendErrorResp(pContext, TSDB_CODE_HTTP_NO_MSG_INPUT);
return false; return false;
} }
cJSON* root = cJSON_Parse(filter); cJSON* root = cJSON_Parse(filter);
if (root == NULL) { if (root == NULL) {
httpSendErrorResp(pContext, HTTP_PARSE_GC_REQ_ERROR); httpSendErrorResp(pContext, TSDB_CODE_HTTP_GC_REQ_PARSE_ERROR);
return false; return false;
} }
int32_t size = cJSON_GetArraySize(root); int32_t size = cJSON_GetArraySize(root);
if (size <= 0) { if (size <= 0) {
httpSendErrorResp(pContext, HTTP_GC_QUERY_NULL); httpSendErrorResp(pContext, TSDB_CODE_HTTP_GC_QUERY_NULL);
cJSON_Delete(root); cJSON_Delete(root);
return false; return false;
} }
if (size > 100) { if (size > 100) {
httpSendErrorResp(pContext, HTTP_GC_QUERY_SIZE); httpSendErrorResp(pContext, TSDB_CODE_HTTP_GC_QUERY_SIZE);
cJSON_Delete(root); cJSON_Delete(root);
return false; return false;
} }
if (!httpMallocMultiCmds(pContext, size, HTTP_BUFFER_SIZE)) { if (!httpMallocMultiCmds(pContext, size, HTTP_BUFFER_SIZE)) {
httpSendErrorResp(pContext, HTTP_NO_ENOUGH_MEMORY); httpSendErrorResp(pContext, TSDB_CODE_HTTP_NO_ENOUGH_MEMORY);
cJSON_Delete(root); cJSON_Delete(root);
return false; return false;
} }
@ -218,7 +219,7 @@ bool gcProcessQueryRequest(HttpContext* pContext) {
HttpSqlCmd* cmd = httpNewSqlCmd(pContext); HttpSqlCmd* cmd = httpNewSqlCmd(pContext);
if (cmd == NULL) { if (cmd == NULL) {
httpSendErrorResp(pContext, HTTP_NO_ENOUGH_MEMORY); httpSendErrorResp(pContext, TSDB_CODE_HTTP_NO_ENOUGH_MEMORY);
cJSON_Delete(root); cJSON_Delete(root);
return false; return false;
} }
@ -227,7 +228,7 @@ bool gcProcessQueryRequest(HttpContext* pContext) {
cmd->values = refIdBuffer; cmd->values = refIdBuffer;
cmd->table = aliasBuffer; cmd->table = aliasBuffer;
cmd->numOfRows = 0; // hack way as target flags cmd->numOfRows = 0; // hack way as target flags
cmd->timestamp = httpAddToSqlCmdBufferWithSize(pContext, HTTP_GC_TARGET_SIZE + 1); // hack way cmd->timestamp = httpAddToSqlCmdBufferWithSize(pContext, TSDB_CODE_HTTP_GC_TARGET_SIZE + 1); // hack way
if (cmd->timestamp == -1) { if (cmd->timestamp == -1) {
httpWarn("context:%p, fd:%d, user:%s, cant't malloc target size, sql buffer is full", pContext, pContext->fd, httpWarn("context:%p, fd:%d, user:%s, cant't malloc target size, sql buffer is full", pContext, pContext->fd,
@ -260,7 +261,7 @@ bool gcProcessRequest(struct HttpContext* pContext) {
} }
if (strlen(pContext->user) == 0 || strlen(pContext->pass) == 0) { if (strlen(pContext->user) == 0 || strlen(pContext->pass) == 0) {
httpSendErrorResp(pContext, HTTP_PARSE_USR_ERROR); httpSendErrorResp(pContext, TSDB_CODE_HTTP_NO_AUTH_INFO);
return false; return false;
} }

View File

@ -129,48 +129,48 @@ bool gcBuildQueryJson(HttpContext *pContext, HttpSqlCmd *cmd, TAOS_RES *result,
// for group by // for group by
if (groupFields != -1) { if (groupFields != -1) {
char target[HTTP_GC_TARGET_SIZE] = {0}; char target[TSDB_CODE_HTTP_GC_TARGET_SIZE] = {0};
int32_t len; int32_t len;
len = snprintf(target,HTTP_GC_TARGET_SIZE,"%s{",aliasBuffer); len = snprintf(target,TSDB_CODE_HTTP_GC_TARGET_SIZE,"%s{",aliasBuffer);
for (int32_t i = dataFields + 1; i<num_fields; i++){ for (int32_t i = dataFields + 1; i<num_fields; i++){
switch (fields[i].type) { switch (fields[i].type) {
case TSDB_DATA_TYPE_BOOL: case TSDB_DATA_TYPE_BOOL:
case TSDB_DATA_TYPE_TINYINT: case TSDB_DATA_TYPE_TINYINT:
len += snprintf(target + len, HTTP_GC_TARGET_SIZE - len, "%s:%d", fields[i].name, *((int8_t *)row[i])); len += snprintf(target + len, TSDB_CODE_HTTP_GC_TARGET_SIZE - len, "%s:%d", fields[i].name, *((int8_t *)row[i]));
break; break;
case TSDB_DATA_TYPE_SMALLINT: case TSDB_DATA_TYPE_SMALLINT:
len += snprintf(target + len, HTTP_GC_TARGET_SIZE - len, "%s:%d", fields[i].name, *((int16_t *)row[i])); len += snprintf(target + len, TSDB_CODE_HTTP_GC_TARGET_SIZE - len, "%s:%d", fields[i].name, *((int16_t *)row[i]));
break; break;
case TSDB_DATA_TYPE_INT: case TSDB_DATA_TYPE_INT:
len += snprintf(target + len, HTTP_GC_TARGET_SIZE - len, "%s:%d,", fields[i].name, *((int32_t *)row[i])); len += snprintf(target + len, TSDB_CODE_HTTP_GC_TARGET_SIZE - len, "%s:%d,", fields[i].name, *((int32_t *)row[i]));
break; break;
case TSDB_DATA_TYPE_BIGINT: case TSDB_DATA_TYPE_BIGINT:
len += snprintf(target + len, HTTP_GC_TARGET_SIZE - len, "%s:%ld", fields[i].name, *((int64_t *)row[i])); len += snprintf(target + len, TSDB_CODE_HTTP_GC_TARGET_SIZE - len, "%s:%ld", fields[i].name, *((int64_t *)row[i]));
break; break;
case TSDB_DATA_TYPE_FLOAT: case TSDB_DATA_TYPE_FLOAT:
len += snprintf(target + len, HTTP_GC_TARGET_SIZE - len, "%s:%.5f", fields[i].name, *((float *)row[i])); len += snprintf(target + len, TSDB_CODE_HTTP_GC_TARGET_SIZE - len, "%s:%.5f", fields[i].name, *((float *)row[i]));
break; break;
case TSDB_DATA_TYPE_DOUBLE: case TSDB_DATA_TYPE_DOUBLE:
len += snprintf(target + len, HTTP_GC_TARGET_SIZE - len, "%s:%.9f", fields[i].name, *((double *)row[i])); len += snprintf(target + len, TSDB_CODE_HTTP_GC_TARGET_SIZE - len, "%s:%.9f", fields[i].name, *((double *)row[i]));
break; break;
case TSDB_DATA_TYPE_BINARY: case TSDB_DATA_TYPE_BINARY:
case TSDB_DATA_TYPE_NCHAR: case TSDB_DATA_TYPE_NCHAR:
if (row[i]!= NULL){ if (row[i]!= NULL){
len += snprintf(target + len, HTTP_GC_TARGET_SIZE - len, "%s:", fields[i].name); len += snprintf(target + len, TSDB_CODE_HTTP_GC_TARGET_SIZE - len, "%s:", fields[i].name);
memcpy(target + len, (char *) row[i], length[i]); memcpy(target + len, (char *) row[i], length[i]);
len = strlen(target); len = strlen(target);
} }
break; break;
default: default:
len += snprintf(target + len, HTTP_GC_TARGET_SIZE - len, "%s:%s", fields[i].name, "-"); len += snprintf(target + len, TSDB_CODE_HTTP_GC_TARGET_SIZE - len, "%s:%s", fields[i].name, "-");
break; break;
} }
if(i < num_fields - 1 ){ if(i < num_fields - 1 ){
len += snprintf(target + len, HTTP_GC_TARGET_SIZE - len, ", "); len += snprintf(target + len, TSDB_CODE_HTTP_GC_TARGET_SIZE - len, ", ");
} }
} }
len += snprintf(target + len, HTTP_GC_TARGET_SIZE - len, "}"); len += snprintf(target + len, TSDB_CODE_HTTP_GC_TARGET_SIZE - len, "}");
if (strcmp(target, targetBuffer) != 0) { if (strcmp(target, targetBuffer) != 0) {
// first target not write this section // first target not write this section
@ -180,7 +180,7 @@ bool gcBuildQueryJson(HttpContext *pContext, HttpSqlCmd *cmd, TAOS_RES *result,
// start new target // start new target
gcWriteTargetStartJson(jsonBuf, refIdBuffer, target); gcWriteTargetStartJson(jsonBuf, refIdBuffer, target);
strncpy(targetBuffer, target, HTTP_GC_TARGET_SIZE); strncpy(targetBuffer, target, TSDB_CODE_HTTP_GC_TARGET_SIZE);
} }
} // end of group by } // end of group by

View File

@ -20,7 +20,6 @@
#include "tglobal.h" #include "tglobal.h"
#include "http.h" #include "http.h"
#include "httpLog.h" #include "httpLog.h"
#include "httpCode.h"
#include "httpJson.h" #include "httpJson.h"
#include "httpResp.h" #include "httpResp.h"
#include "httpUtil.h" #include "httpUtil.h"

View File

@ -338,7 +338,7 @@ static int32_t httpOnBody(HttpParser *parser, const char *chunk, int32_t len) {
if (len + 1 >= avail) { if (len + 1 >= avail) {
if (buf->size >= HTTP_BUFFER_SIZE) { if (buf->size >= HTTP_BUFFER_SIZE) {
httpError("context:%p, fd:%d, failed parse body, exceeding buffer size %d", pContext, pContext->fd, buf->size); httpError("context:%p, fd:%d, failed parse body, exceeding buffer size %d", pContext, pContext->fd, buf->size);
httpOnError(parser, 0, TSDB_CODE_HTTP_NO_ENOUGH_MEMORY); httpOnError(parser, 0, TSDB_CODE_HTTP_REQUSET_TOO_BIG);
return -1; return -1;
} else { } else {
int32_t newSize = buf->size * 10; int32_t newSize = buf->size * 10;

View File

@ -19,7 +19,6 @@
#include "taosmsg.h" #include "taosmsg.h"
#include "httpLog.h" #include "httpLog.h"
#include "httpResp.h" #include "httpResp.h"
#include "httpCode.h"
#include "httpJson.h" #include "httpJson.h"
#include "httpContext.h" #include "httpContext.h"
@ -45,7 +44,7 @@ const char *httpRespTemplate[] = {
"%s 200 OK\r\nAccess-Control-Allow-Origin:*\r\n%sAccess-Control-Allow-Methods:POST, GET, OPTIONS, DELETE, PUT\r\nAccess-Control-Allow-Headers:Accept, Content-Type\r\nContent-Type: application/json;charset=utf-8\r\nContent-Length: %d\r\n\r\n" "%s 200 OK\r\nAccess-Control-Allow-Origin:*\r\n%sAccess-Control-Allow-Methods:POST, GET, OPTIONS, DELETE, PUT\r\nAccess-Control-Allow-Headers:Accept, Content-Type\r\nContent-Type: application/json;charset=utf-8\r\nContent-Length: %d\r\n\r\n"
}; };
static void httpSendErrorRespImp(HttpContext *pContext, int32_t httpCode, char *httpCodeStr, int32_t errNo, char *desc) { static void httpSendErrorRespImp(HttpContext *pContext, int32_t httpCode, char *httpCodeStr, int32_t errNo, const char *desc) {
httpError("context:%p, fd:%d, code:%d, error:%s", pContext, pContext->fd, httpCode, desc); httpError("context:%p, fd:%d, code:%d, error:%s", pContext, pContext->fd, httpCode, desc);
char head[512] = {0}; char head[512] = {0};
@ -60,132 +59,85 @@ static void httpSendErrorRespImp(HttpContext *pContext, int32_t httpCode, char *
httpCloseContextByApp(pContext); httpCloseContextByApp(pContext);
} }
void httpSendErrorRespWithDesc(HttpContext *pContext, int32_t errNo, char *desc) { void httpSendErrorResp(HttpContext *pContext, int32_t errNo) {
int32_t httpCode = 500; int32_t httpCode = 500;
char *httpCodeStr = "Internal Server Error"; if (errNo == TSDB_CODE_SUCCESS)
switch (errNo) {
case HTTP_SUCCESS:
httpCode = 200; httpCode = 200;
httpCodeStr = "OK"; else if (errNo == TSDB_CODE_HTTP_SERVER_OFFLINE)
break;
case HTTP_SERVER_OFFLINE:
case HTTP_UNSUPPORT_URL:
httpCode = 404; httpCode = 404;
httpCodeStr = "Not Found"; else if (errNo == TSDB_CODE_HTTP_UNSUPPORT_URL)
break; httpCode = 404;
case HTTP_PARSE_HTTP_METHOD_ERROR: else if (errNo == TSDB_CODE_HTTP_INVLALID_URL)
httpCode = 405; httpCode = 404;
httpCodeStr = "Method Not Allowed"; else if (errNo == TSDB_CODE_HTTP_NO_ENOUGH_MEMORY)
break;
case HTTP_PARSE_HTTP_VERSION_ERROR:
httpCode = 505;
httpCodeStr = "HTTP Version Not Supported";
break;
case HTTP_PARSE_HEAD_ERROR:
httpCode = 406;
httpCodeStr = "Not Acceptable";
break;
case HTTP_REQUSET_TOO_BIG:
httpCode = 413;
httpCodeStr = "Request Entity Too Large";
break;
case HTTP_PARSE_BODY_ERROR:
case HTTP_PARSE_CHUNKED_BODY_ERROR:
httpCode = 409;
httpCodeStr = "Conflict";
break;
case HTTP_PARSE_URL_ERROR:
httpCode = 414;
httpCodeStr = "Request-URI Invalid";
break;
case HTTP_INVALID_AUTH_TOKEN:
case HTTP_PARSE_USR_ERROR:
httpCode = 401;
httpCodeStr = "Unauthorized";
break;
case HTTP_NO_SQL_INPUT:
httpCode = 400;
httpCodeStr = "Bad Request";
break;
case HTTP_SESSION_FULL:
httpCode = 421;
httpCodeStr = "Too many connections";
break;
case HTTP_NO_ENOUGH_MEMORY:
case HTTP_GEN_TAOSD_TOKEN_ERR:
httpCode = 507; httpCode = 507;
httpCodeStr = "Insufficient Storage"; else if (errNo == TSDB_CODE_HTTP_REQUSET_TOO_BIG)
break; httpCode = 413;
case HTTP_INVALID_DB_TABLE: else if (errNo == TSDB_CODE_HTTP_NO_AUTH_INFO)
case HTTP_NO_EXEC_USEDB: httpCode = 401;
case HTTP_PARSE_GC_REQ_ERROR: else if (errNo == TSDB_CODE_HTTP_NO_MSG_INPUT)
case HTTP_INVALID_MULTI_REQUEST:
case HTTP_NO_MSG_INPUT:
httpCode = 400; httpCode = 400;
httpCodeStr = "Bad Request"; else if (errNo == TSDB_CODE_HTTP_NO_SQL_INPUT)
break; httpCode = 400;
case HTTP_NO_ENOUGH_SESSIONS: else if (errNo == TSDB_CODE_HTTP_NO_EXEC_USEDB)
httpCode = 400;
else if (errNo == TSDB_CODE_HTTP_SESSION_FULL)
httpCode = 421; httpCode = 421;
httpCodeStr = "Too many connections"; else if (errNo == TSDB_CODE_HTTP_GEN_TAOSD_TOKEN_ERR)
break; httpCode = 507;
// telegraf else if (errNo == TSDB_CODE_HTTP_INVALID_MULTI_REQUEST)
case HTTP_TG_DB_NOT_INPUT: httpCode = 400;
case HTTP_TG_DB_TOO_LONG: else if (errNo == TSDB_CODE_HTTP_CREATE_GZIP_FAILED)
case HTTP_TG_INVALID_JSON: httpCode = 507;
case HTTP_TG_METRICS_NULL: else if (errNo == TSDB_CODE_HTTP_FINISH_GZIP_FAILED)
case HTTP_TG_METRICS_SIZE: httpCode = 507;
case HTTP_TG_METRIC_NULL: else if (errNo == TSDB_CODE_HTTP_INVALID_VERSION)
case HTTP_TG_METRIC_TYPE: httpCode = 406;
case HTTP_TG_METRIC_NAME_NULL: else if (errNo == TSDB_CODE_HTTP_INVALID_CONTENT_LENGTH)
case HTTP_TG_METRIC_NAME_LONG: httpCode = 406;
case HTTP_TG_TIMESTAMP_NULL: else if (errNo == TSDB_CODE_HTTP_INVALID_AUTH_TYPE)
case HTTP_TG_TIMESTAMP_TYPE: httpCode = 406;
case HTTP_TG_TIMESTAMP_VAL_NULL: else if (errNo == TSDB_CODE_HTTP_INVALID_AUTH_FORMAT)
case HTTP_TG_TAGS_NULL: httpCode = 406;
case HTTP_TG_TAGS_SIZE_0: else if (errNo == TSDB_CODE_HTTP_INVALID_BASIC_AUTH)
case HTTP_TG_TAGS_SIZE_LONG: httpCode = 406;
case HTTP_TG_TAG_NULL: else if (errNo == TSDB_CODE_HTTP_INVALID_TAOSD_AUTH)
case HTTP_TG_TAG_NAME_NULL: httpCode = 406;
case HTTP_TG_TAG_NAME_SIZE: else if (errNo == TSDB_CODE_HTTP_PARSE_METHOD_FAILED)
case HTTP_TG_TAG_VALUE_TYPE: httpCode = 406;
case HTTP_TG_TAG_VALUE_NULL: else if (errNo == TSDB_CODE_HTTP_PARSE_TARGET_FAILED)
case HTTP_TG_TABLE_NULL: httpCode = 406;
case HTTP_TG_TABLE_SIZE: else if (errNo == TSDB_CODE_HTTP_PARSE_VERSION_FAILED)
case HTTP_TG_FIELDS_NULL: httpCode = 406;
case HTTP_TG_FIELDS_SIZE_0: else if (errNo == TSDB_CODE_HTTP_PARSE_SP_FAILED)
case HTTP_TG_FIELDS_SIZE_LONG: httpCode = 406;
case HTTP_TG_FIELD_NULL: else if (errNo == TSDB_CODE_HTTP_PARSE_STATUS_FAILED)
case HTTP_TG_FIELD_NAME_NULL: httpCode = 406;
case HTTP_TG_FIELD_NAME_SIZE: else if (errNo == TSDB_CODE_HTTP_PARSE_PHRASE_FAILED)
case HTTP_TG_FIELD_VALUE_TYPE: httpCode = 406;
case HTTP_TG_FIELD_VALUE_NULL: else if (errNo == TSDB_CODE_HTTP_PARSE_CRLF_FAILED)
case HTTP_INVALID_BASIC_AUTH_TOKEN: httpCode = 406;
case HTTP_INVALID_TAOSD_AUTH_TOKEN: else if (errNo == TSDB_CODE_HTTP_PARSE_HEADER_FAILED)
case HTTP_TG_HOST_NOT_STRING: httpCode = 406;
// grafana else if (errNo == TSDB_CODE_HTTP_PARSE_HEADER_KEY_FAILED)
case HTTP_GC_QUERY_NULL: httpCode = 406;
case HTTP_GC_QUERY_SIZE: else if (errNo == TSDB_CODE_HTTP_PARSE_HEADER_VAL_FAILED)
httpCode = 406;
else if (errNo == TSDB_CODE_HTTP_PARSE_CHUNK_SIZE_FAILED)
httpCode = 406;
else if (errNo == TSDB_CODE_HTTP_PARSE_CHUNK_FAILED)
httpCode = 406;
else if (errNo == TSDB_CODE_HTTP_PARSE_END_FAILED)
httpCode = 406;
else if (errNo == TSDB_CODE_HTTP_PARSE_INVALID_STATE)
httpCode = 406;
else if (errNo == TSDB_CODE_HTTP_PARSE_ERROR_STATE)
httpCode = 406;
else
httpCode = 400; httpCode = 400;
httpCodeStr = "Bad Request";
break;
default:
httpError("context:%p, fd:%d, error:%d not recognized", pContext, pContext->fd, errNo);
break;
}
if (desc == NULL) { char *httpCodeStr = httpGetStatusDesc(httpCode);
httpSendErrorRespImp(pContext, httpCode, httpCodeStr, errNo + 5000, httpMsg[errNo]); httpSendErrorRespImp(pContext, httpCode, httpCodeStr, errNo & 0XFFFF, tstrerror(errNo));
} else {
httpSendErrorRespImp(pContext, httpCode, httpCodeStr, errNo + 5000, desc);
}
}
void httpSendErrorResp(HttpContext *pContext, int32_t errNo) { httpSendErrorRespWithDesc(pContext, errNo, NULL); }
void httpSendTaosdErrorResp(HttpContext *pContext, int32_t errCode) {
int32_t httpCode = 400;
httpSendErrorRespImp(pContext, httpCode, "Bad Request", errCode & 0XFFFF, (char*)tstrerror(errCode));
} }
void httpSendTaosdInvalidSqlErrorResp(HttpContext *pContext, char *errMsg) { void httpSendTaosdInvalidSqlErrorResp(HttpContext *pContext, char *errMsg) {
@ -208,7 +160,7 @@ void httpSendSuccResp(HttpContext *pContext, char *desc) {
char head[1024] = {0}; char head[1024] = {0};
char body[1024] = {0}; char body[1024] = {0};
int32_t bodyLen = sprintf(body, httpRespTemplate[HTTP_RESPONSE_JSON_OK], HTTP_SUCCESS, desc); int32_t bodyLen = sprintf(body, httpRespTemplate[HTTP_RESPONSE_JSON_OK], TSDB_CODE_SUCCESS, desc);
int32_t headLen = sprintf(head, httpRespTemplate[HTTP_RESPONSE_OK], httpVersionStr[pContext->parser->httpVersion], int32_t headLen = sprintf(head, httpRespTemplate[HTTP_RESPONSE_OK], httpVersionStr[pContext->parser->httpVersion],
httpKeepAliveStr[pContext->parser->keepAlive], bodyLen); httpKeepAliveStr[pContext->parser->keepAlive], bodyLen);
@ -221,7 +173,7 @@ void httpSendOptionResp(HttpContext *pContext, char *desc) {
char head[1024] = {0}; char head[1024] = {0};
char body[1024] = {0}; char body[1024] = {0};
int32_t bodyLen = sprintf(body, httpRespTemplate[HTTP_RESPONSE_JSON_OK], HTTP_SUCCESS, desc); int32_t bodyLen = sprintf(body, httpRespTemplate[HTTP_RESPONSE_JSON_OK], TSDB_CODE_SUCCESS, desc);
int32_t headLen = sprintf(head, httpRespTemplate[HTTP_RESPONSE_OPTIONS], httpVersionStr[pContext->parser->httpVersion], int32_t headLen = sprintf(head, httpRespTemplate[HTTP_RESPONSE_OPTIONS], httpVersionStr[pContext->parser->httpVersion],
httpKeepAliveStr[pContext->parser->keepAlive], bodyLen); httpKeepAliveStr[pContext->parser->keepAlive], bodyLen);

View File

@ -15,6 +15,7 @@
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "os.h" #include "os.h"
#include "taoserror.h"
#include "httpLog.h" #include "httpLog.h"
#include "httpRestHandle.h" #include "httpRestHandle.h"
#include "httpRestJson.h" #include "httpRestJson.h"
@ -90,7 +91,7 @@ bool restProcessSqlRequest(HttpContext* pContext, int32_t timestampFmt) {
char* sql = pContext->parser->body.str; char* sql = pContext->parser->body.str;
if (sql == NULL) { if (sql == NULL) {
httpSendErrorResp(pContext, HTTP_NO_SQL_INPUT); httpSendErrorResp(pContext, TSDB_CODE_HTTP_NO_SQL_INPUT);
return false; return false;
} }
@ -99,7 +100,7 @@ bool restProcessSqlRequest(HttpContext* pContext, int32_t timestampFmt) {
* for async test * for async test
* *
if (httpCheckUsedbSql(sql)) { if (httpCheckUsedbSql(sql)) {
httpSendErrorResp(pContext, HTTP_NO_EXEC_USEDB); httpSendErrorResp(pContext, TSDB_CODE_HTTP_NO_EXEC_USEDB);
return false; return false;
} }
*/ */
@ -126,7 +127,7 @@ bool restProcessRequest(struct HttpContext* pContext) {
} }
if (strlen(pContext->user) == 0 || strlen(pContext->pass) == 0) { if (strlen(pContext->user) == 0 || strlen(pContext->pass) == 0) {
httpSendErrorResp(pContext, HTTP_PARSE_USR_ERROR); httpSendErrorResp(pContext, TSDB_CODE_HTTP_NO_AUTH_INFO);
return false; return false;
} }
@ -141,6 +142,6 @@ bool restProcessRequest(struct HttpContext* pContext) {
} else { } else {
} }
httpSendErrorResp(pContext, HTTP_PARSE_URL_ERROR); httpSendErrorResp(pContext, TSDB_CODE_HTTP_INVLALID_URL);
return false; return false;
} }

View File

@ -139,7 +139,7 @@ static void httpProcessHttpData(void *param) {
if (pServer->status != HTTP_SERVER_RUNNING) { if (pServer->status != HTTP_SERVER_RUNNING) {
httpDebug("context:%p, fd:%d, state:%s, server is not running, accessed:%d, close connect", pContext, httpDebug("context:%p, fd:%d, state:%s, server is not running, accessed:%d, close connect", pContext,
pContext->fd, httpContextStateStr(pContext->state), pContext->accessTimes); pContext->fd, httpContextStateStr(pContext->state), pContext->accessTimes);
httpSendErrorResp(pContext, HTTP_SERVER_OFFLINE); httpSendErrorResp(pContext, TSDB_CODE_HTTP_SERVER_OFFLINE);
httpNotifyContextClose(pContext); httpNotifyContextClose(pContext);
} else { } else {
if (httpReadData(pContext)) { if (httpReadData(pContext)) {

View File

@ -16,6 +16,7 @@
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "os.h" #include "os.h"
#include "taos.h" #include "taos.h"
#include "taoserror.h"
#include "tglobal.h" #include "tglobal.h"
#include "tcache.h" #include "tcache.h"
#include "httpInt.h" #include "httpInt.h"
@ -40,7 +41,7 @@ void httpCreateSession(HttpContext *pContext, void *taos) {
if (pContext->session == NULL) { if (pContext->session == NULL) {
httpError("context:%p, fd:%d, user:%s, error:%s", pContext, pContext->fd, pContext->user, httpError("context:%p, fd:%d, user:%s, error:%s", pContext, pContext->fd, pContext->user,
httpMsg[HTTP_SESSION_FULL]); tstrerror(TSDB_CODE_HTTP_SESSION_FULL));
taos_close(taos); taos_close(taos);
pthread_mutex_unlock(&server->serverMutex); pthread_mutex_unlock(&server->serverMutex);
return; return;

View File

@ -17,6 +17,7 @@
#include "os.h" #include "os.h"
#include "tnote.h" #include "tnote.h"
#include "taos.h" #include "taos.h"
#include "taoserror.h"
#include "tsclient.h" #include "tsclient.h"
#include "httpInt.h" #include "httpInt.h"
#include "httpContext.h" #include "httpContext.h"
@ -193,7 +194,7 @@ void httpProcessMultiSqlCmd(HttpContext *pContext) {
HttpSqlCmds *multiCmds = pContext->multiCmds; HttpSqlCmds *multiCmds = pContext->multiCmds;
if (multiCmds == NULL || multiCmds->size <= 0 || multiCmds->pos >= multiCmds->size || multiCmds->pos < 0) { if (multiCmds == NULL || multiCmds->size <= 0 || multiCmds->pos >= multiCmds->size || multiCmds->pos < 0) {
httpSendErrorResp(pContext, HTTP_INVALID_MULTI_REQUEST); httpSendErrorResp(pContext, TSDB_CODE_HTTP_INVALID_MULTI_REQUEST);
return; return;
} }
@ -282,7 +283,7 @@ void httpProcessSingleSqlCallBackImp(void *param, TAOS_RES *result, int unUsedCo
} else { } else {
httpError("context:%p, fd:%d, user:%s, query error, taos:%p, code:%s, sqlObj:%p", pContext, pContext->fd, httpError("context:%p, fd:%d, user:%s, query error, taos:%p, code:%s, sqlObj:%p", pContext, pContext->fd,
pContext->user, pContext->session->taos, tstrerror(code), pObj); pContext->user, pContext->session->taos, tstrerror(code), pObj);
httpSendTaosdErrorResp(pContext, code); httpSendErrorResp(pContext, code);
} }
taos_free_result(result); taos_free_result(result);
return; return;
@ -332,7 +333,7 @@ void httpProcessSingleSqlCmd(HttpContext *pContext) {
if (sql == NULL || sql[0] == 0) { if (sql == NULL || sql[0] == 0) {
httpError("context:%p, fd:%d, user:%s, error:no sql input", pContext, pContext->fd, pContext->user); httpError("context:%p, fd:%d, user:%s, error:no sql input", pContext, pContext->fd, pContext->user);
httpSendErrorResp(pContext, HTTP_NO_SQL_INPUT); httpSendErrorResp(pContext, TSDB_CODE_HTTP_NO_SQL_INPUT);
return; return;
} }
@ -344,7 +345,7 @@ void httpProcessSingleSqlCmd(HttpContext *pContext) {
void httpProcessLoginCmd(HttpContext *pContext) { void httpProcessLoginCmd(HttpContext *pContext) {
char token[128] = {0}; char token[128] = {0};
if (!httpGenTaosdAuthToken(pContext, token, 128)) { if (!httpGenTaosdAuthToken(pContext, token, 128)) {
httpSendErrorResp(pContext, HTTP_GEN_TAOSD_TOKEN_ERR); httpSendErrorResp(pContext, TSDB_CODE_HTTP_GEN_TAOSD_TOKEN_ERR);
} else { } else {
httpDebug("context:%p, fd:%d, user:%s, login via http, return token:%s", pContext, pContext->fd, pContext->user, httpDebug("context:%p, fd:%d, user:%s, login via http, return token:%s", pContext, pContext->fd, pContext->user,
token); token);
@ -395,7 +396,7 @@ void httpProcessRequestCb(void *param, TAOS_RES *result, int code) {
if (code < 0) { if (code < 0) {
httpError("context:%p, fd:%d, user:%s, login error, code:%s", pContext, pContext->fd, pContext->user, httpError("context:%p, fd:%d, user:%s, login error, code:%s", pContext, pContext->fd, pContext->user,
tstrerror(code)); tstrerror(code));
httpSendTaosdErrorResp(pContext, code); httpSendErrorResp(pContext, code);
return; return;
} }
@ -403,14 +404,14 @@ void httpProcessRequestCb(void *param, TAOS_RES *result, int code) {
pContext->taos); pContext->taos);
if (pContext->taos == NULL) { if (pContext->taos == NULL) {
httpError("context:%p, fd:%d, user:%s, login error, taos is empty", pContext, pContext->fd, pContext->user); httpError("context:%p, fd:%d, user:%s, login error, taos is empty", pContext, pContext->fd, pContext->user);
httpSendErrorResp(pContext, HTTP_NO_ENOUGH_SESSIONS); httpSendErrorResp(pContext, TSDB_CODE_HTTP_LOGIN_FAILED);
return; return;
} }
httpCreateSession(pContext, pContext->taos); httpCreateSession(pContext, pContext->taos);
if (pContext->session == NULL) { if (pContext->session == NULL) {
httpSendErrorResp(pContext, HTTP_SESSION_FULL); httpSendErrorResp(pContext, TSDB_CODE_HTTP_SESSION_FULL);
httpCloseContextByApp(pContext); httpCloseContextByApp(pContext);
} else { } else {
httpExecCmd(pContext); httpExecCmd(pContext);

View File

@ -335,12 +335,12 @@ bool tgGetPassFromUrl(HttpContext *pContext) {
char *tgGetDbFromUrl(HttpContext *pContext) { char *tgGetDbFromUrl(HttpContext *pContext) {
HttpParser *pParser = pContext->parser; HttpParser *pParser = pContext->parser;
if (pParser->path[TG_DB_URL_POS].pos <= 0) { if (pParser->path[TG_DB_URL_POS].pos <= 0) {
httpSendErrorResp(pContext, HTTP_TG_DB_NOT_INPUT); httpSendErrorResp(pContext, TSDB_CODE_HTTP_TG_DB_NOT_INPUT);
return NULL; return NULL;
} }
if (pParser->path[TG_DB_URL_POS].pos >= TSDB_DB_NAME_LEN) { if (pParser->path[TG_DB_URL_POS].pos >= TSDB_DB_NAME_LEN) {
httpSendErrorResp(pContext, HTTP_TG_DB_TOO_LONG); httpSendErrorResp(pContext, TSDB_CODE_HTTP_TG_DB_TOO_LONG);
return NULL; return NULL;
} }
@ -401,57 +401,57 @@ bool tgProcessSingleMetric(HttpContext *pContext, cJSON *metric, char *db) {
// metric name // metric name
cJSON *name = cJSON_GetObjectItem(metric, "name"); cJSON *name = cJSON_GetObjectItem(metric, "name");
if (name == NULL) { if (name == NULL) {
httpSendErrorResp(pContext, HTTP_TG_METRIC_NULL); httpSendErrorResp(pContext, TSDB_CODE_HTTP_TG_METRIC_NULL);
return false; return false;
} }
if (name->type != cJSON_String) { if (name->type != cJSON_String) {
httpSendErrorResp(pContext, HTTP_TG_METRIC_TYPE); httpSendErrorResp(pContext, TSDB_CODE_HTTP_TG_METRIC_TYPE);
return false; return false;
} }
if (name->valuestring == NULL) { if (name->valuestring == NULL) {
httpSendErrorResp(pContext, HTTP_TG_METRIC_NAME_NULL); httpSendErrorResp(pContext, TSDB_CODE_HTTP_TG_METRIC_NAME_NULL);
return false; return false;
} }
int32_t nameLen = (int32_t)strlen(name->valuestring); int32_t nameLen = (int32_t)strlen(name->valuestring);
if (nameLen == 0) { if (nameLen == 0) {
httpSendErrorResp(pContext, HTTP_TG_METRIC_NAME_NULL); httpSendErrorResp(pContext, TSDB_CODE_HTTP_TG_METRIC_NAME_NULL);
return false; return false;
} }
if (nameLen >= TSDB_TABLE_NAME_LEN - 8) { if (nameLen >= TSDB_TABLE_NAME_LEN - 8) {
httpSendErrorResp(pContext, HTTP_TG_METRIC_NAME_LONG); httpSendErrorResp(pContext, TSDB_CODE_HTTP_TG_METRIC_NAME_LONG);
return false; return false;
} }
// timestamp // timestamp
cJSON *timestamp = cJSON_GetObjectItem(metric, "timestamp"); cJSON *timestamp = cJSON_GetObjectItem(metric, "timestamp");
if (timestamp == NULL) { if (timestamp == NULL) {
httpSendErrorResp(pContext, HTTP_TG_TIMESTAMP_NULL); httpSendErrorResp(pContext, TSDB_CODE_HTTP_TG_TIMESTAMP_NULL);
return false; return false;
} }
if (timestamp->type != cJSON_Number) { if (timestamp->type != cJSON_Number) {
httpSendErrorResp(pContext, HTTP_TG_TIMESTAMP_TYPE); httpSendErrorResp(pContext, TSDB_CODE_HTTP_TG_TIMESTAMP_TYPE);
return false; return false;
} }
if (timestamp->valueint <= 0) { if (timestamp->valueint <= 0) {
httpSendErrorResp(pContext, HTTP_TG_TIMESTAMP_VAL_NULL); httpSendErrorResp(pContext, TSDB_CODE_HTTP_TG_TIMESTAMP_VAL_NULL);
return false; return false;
} }
// tags // tags
cJSON *tags = cJSON_GetObjectItem(metric, "tags"); cJSON *tags = cJSON_GetObjectItem(metric, "tags");
if (tags == NULL) { if (tags == NULL) {
httpSendErrorResp(pContext, HTTP_TG_TAGS_NULL); httpSendErrorResp(pContext, TSDB_CODE_HTTP_TG_TAGS_NULL);
return false; return false;
} }
int32_t tagsSize = cJSON_GetArraySize(tags); int32_t tagsSize = cJSON_GetArraySize(tags);
if (tagsSize <= 0) { if (tagsSize <= 0) {
httpSendErrorResp(pContext, HTTP_TG_TAGS_SIZE_0); httpSendErrorResp(pContext, TSDB_CODE_HTTP_TG_TAGS_SIZE_0);
return false; return false;
} }
if (tagsSize > TG_MAX_SORT_TAG_SIZE) { if (tagsSize > TG_MAX_SORT_TAG_SIZE) {
httpSendErrorResp(pContext, HTTP_TG_TAGS_SIZE_LONG); httpSendErrorResp(pContext, TSDB_CODE_HTTP_TG_TAGS_SIZE_LONG);
return false; return false;
} }
@ -460,11 +460,11 @@ bool tgProcessSingleMetric(HttpContext *pContext, cJSON *metric, char *db) {
for (int32_t i = 0; i < tagsSize; i++) { for (int32_t i = 0; i < tagsSize; i++) {
cJSON *tag = cJSON_GetArrayItem(tags, i); cJSON *tag = cJSON_GetArrayItem(tags, i);
if (tag == NULL) { if (tag == NULL) {
httpSendErrorResp(pContext, HTTP_TG_TAG_NULL); httpSendErrorResp(pContext, TSDB_CODE_HTTP_TG_TAG_NULL);
return false; return false;
} }
if (tag->string == NULL || strlen(tag->string) == 0) { if (tag->string == NULL || strlen(tag->string) == 0) {
httpSendErrorResp(pContext, HTTP_TG_TAG_NAME_NULL); httpSendErrorResp(pContext, TSDB_CODE_HTTP_TG_TAG_NAME_NULL);
return false; return false;
} }
@ -474,19 +474,19 @@ bool tgProcessSingleMetric(HttpContext *pContext, cJSON *metric, char *db) {
*/ */
if (0) { if (0) {
if (strlen(tag->string) >= TSDB_COL_NAME_LEN) { if (strlen(tag->string) >= TSDB_COL_NAME_LEN) {
httpSendErrorResp(pContext, HTTP_TG_TAG_NAME_SIZE); httpSendErrorResp(pContext, TSDB_CODE_HTTP_TG_TAG_NAME_SIZE);
return false; return false;
} }
} }
if (tag->type != cJSON_Number && tag->type != cJSON_String) { if (tag->type != cJSON_Number && tag->type != cJSON_String) {
httpSendErrorResp(pContext, HTTP_TG_TAG_VALUE_TYPE); httpSendErrorResp(pContext, TSDB_CODE_HTTP_TG_TAG_VALUE_TYPE);
return false; return false;
} }
if (tag->type == cJSON_String) { if (tag->type == cJSON_String) {
if (tag->valuestring == NULL || strlen(tag->valuestring) == 0) { if (tag->valuestring == NULL || strlen(tag->valuestring) == 0) {
httpSendErrorResp(pContext, HTTP_TG_TAG_VALUE_NULL); httpSendErrorResp(pContext, TSDB_CODE_HTTP_TG_TAG_VALUE_NULL);
return false; return false;
} }
} }
@ -497,46 +497,46 @@ bool tgProcessSingleMetric(HttpContext *pContext, cJSON *metric, char *db) {
} }
if (host == NULL) { if (host == NULL) {
httpSendErrorResp(pContext, HTTP_TG_TABLE_NULL); httpSendErrorResp(pContext, TSDB_CODE_HTTP_TG_TABLE_NULL);
return false; return false;
} }
if (host->type != cJSON_String) { if (host->type != cJSON_String) {
httpSendErrorResp(pContext, HTTP_TG_HOST_NOT_STRING); httpSendErrorResp(pContext, TSDB_CODE_HTTP_TG_HOST_NOT_STRING);
return false; return false;
} }
if (strlen(host->valuestring) >= TSDB_TABLE_NAME_LEN - 1) { if (strlen(host->valuestring) >= TSDB_TABLE_NAME_LEN - 1) {
httpSendErrorResp(pContext, HTTP_TG_TABLE_SIZE); httpSendErrorResp(pContext, TSDB_CODE_HTTP_TG_TABLE_SIZE);
return false; return false;
} }
// fields // fields
cJSON *fields = cJSON_GetObjectItem(metric, "fields"); cJSON *fields = cJSON_GetObjectItem(metric, "fields");
if (fields == NULL) { if (fields == NULL) {
httpSendErrorResp(pContext, HTTP_TG_FIELDS_NULL); httpSendErrorResp(pContext, TSDB_CODE_HTTP_TG_FIELDS_NULL);
return false; return false;
} }
int32_t fieldsSize = cJSON_GetArraySize(fields); int32_t fieldsSize = cJSON_GetArraySize(fields);
if (fieldsSize <= 0) { if (fieldsSize <= 0) {
httpSendErrorResp(pContext, HTTP_TG_FIELDS_SIZE_0); httpSendErrorResp(pContext, TSDB_CODE_HTTP_TG_FIELDS_SIZE_0);
return false; return false;
} }
if (fieldsSize > (TSDB_MAX_COLUMNS - TSDB_MAX_TAGS - 1)) { if (fieldsSize > (TSDB_MAX_COLUMNS - TSDB_MAX_TAGS - 1)) {
httpSendErrorResp(pContext, HTTP_TG_FIELDS_SIZE_LONG); httpSendErrorResp(pContext, TSDB_CODE_HTTP_TG_FIELDS_SIZE_LONG);
return false; return false;
} }
for (int32_t i = 0; i < fieldsSize; i++) { for (int32_t i = 0; i < fieldsSize; i++) {
cJSON *field = cJSON_GetArrayItem(fields, i); cJSON *field = cJSON_GetArrayItem(fields, i);
if (field == NULL) { if (field == NULL) {
httpSendErrorResp(pContext, HTTP_TG_FIELD_NULL); httpSendErrorResp(pContext, TSDB_CODE_HTTP_TG_FIELD_NULL);
return false; return false;
} }
if (field->string == NULL || strlen(field->string) == 0) { if (field->string == NULL || strlen(field->string) == 0) {
httpSendErrorResp(pContext, HTTP_TG_FIELD_NAME_NULL); httpSendErrorResp(pContext, TSDB_CODE_HTTP_TG_FIELD_NAME_NULL);
return false; return false;
} }
/* /*
@ -545,17 +545,17 @@ bool tgProcessSingleMetric(HttpContext *pContext, cJSON *metric, char *db) {
*/ */
if (0) { if (0) {
if (strlen(field->string) >= TSDB_COL_NAME_LEN) { if (strlen(field->string) >= TSDB_COL_NAME_LEN) {
httpSendErrorResp(pContext, HTTP_TG_FIELD_NAME_SIZE); httpSendErrorResp(pContext, TSDB_CODE_HTTP_TG_FIELD_NAME_SIZE);
return false; return false;
} }
} }
if (field->type != cJSON_Number && field->type != cJSON_String) { if (field->type != cJSON_Number && field->type != cJSON_String) {
httpSendErrorResp(pContext, HTTP_TG_FIELD_VALUE_TYPE); httpSendErrorResp(pContext, TSDB_CODE_HTTP_TG_FIELD_VALUE_TYPE);
return false; return false;
} }
if (field->type == cJSON_String) { if (field->type == cJSON_String) {
if (field->valuestring == NULL || strlen(field->valuestring) == 0) { if (field->valuestring == NULL || strlen(field->valuestring) == 0) {
httpSendErrorResp(pContext, HTTP_TG_FIELD_VALUE_NULL); httpSendErrorResp(pContext, TSDB_CODE_HTTP_TG_FIELD_VALUE_NULL);
return false; return false;
} }
} }
@ -564,7 +564,7 @@ bool tgProcessSingleMetric(HttpContext *pContext, cJSON *metric, char *db) {
// assembling cmds // assembling cmds
HttpSqlCmd *stable_cmd = httpNewSqlCmd(pContext); HttpSqlCmd *stable_cmd = httpNewSqlCmd(pContext);
if (stable_cmd == NULL) { if (stable_cmd == NULL) {
httpSendErrorResp(pContext, HTTP_NO_ENOUGH_MEMORY); httpSendErrorResp(pContext, TSDB_CODE_HTTP_NO_ENOUGH_MEMORY);
return false; return false;
} }
stable_cmd->cmdType = HTTP_CMD_TYPE_CREATE_STBALE; stable_cmd->cmdType = HTTP_CMD_TYPE_CREATE_STBALE;
@ -572,7 +572,7 @@ bool tgProcessSingleMetric(HttpContext *pContext, cJSON *metric, char *db) {
HttpSqlCmd *table_cmd = httpNewSqlCmd(pContext); HttpSqlCmd *table_cmd = httpNewSqlCmd(pContext);
if (table_cmd == NULL) { if (table_cmd == NULL) {
httpSendErrorResp(pContext, HTTP_NO_ENOUGH_MEMORY); httpSendErrorResp(pContext, TSDB_CODE_HTTP_NO_ENOUGH_MEMORY);
return false; return false;
} }
table_cmd->cmdType = HTTP_CMD_TYPE_INSERT; table_cmd->cmdType = HTTP_CMD_TYPE_INSERT;
@ -804,13 +804,13 @@ bool tgProcessQueryRequest(HttpContext *pContext, char *db) {
char *filter = pContext->parser->body.str; char *filter = pContext->parser->body.str;
if (filter == NULL) { if (filter == NULL) {
httpSendErrorResp(pContext, HTTP_NO_MSG_INPUT); httpSendErrorResp(pContext, TSDB_CODE_HTTP_NO_MSG_INPUT);
return false; return false;
} }
cJSON *root = cJSON_Parse(filter); cJSON *root = cJSON_Parse(filter);
if (root == NULL) { if (root == NULL) {
httpSendErrorResp(pContext, HTTP_TG_INVALID_JSON); httpSendErrorResp(pContext, TSDB_CODE_HTTP_TG_INVALID_JSON);
return false; return false;
} }
@ -819,27 +819,27 @@ bool tgProcessQueryRequest(HttpContext *pContext, char *db) {
int32_t size = cJSON_GetArraySize(metrics); int32_t size = cJSON_GetArraySize(metrics);
httpDebug("context:%p, fd:%d, multiple metrics:%d at one time", pContext, pContext->fd, size); httpDebug("context:%p, fd:%d, multiple metrics:%d at one time", pContext, pContext->fd, size);
if (size <= 0) { if (size <= 0) {
httpSendErrorResp(pContext, HTTP_TG_METRICS_NULL); httpSendErrorResp(pContext, TSDB_CODE_HTTP_TG_METRICS_NULL);
cJSON_Delete(root); cJSON_Delete(root);
return false; return false;
} }
int32_t cmdSize = size * 2 + 1; int32_t cmdSize = size * 2 + 1;
if (cmdSize > HTTP_MAX_CMD_SIZE) { if (cmdSize > HTTP_MAX_CMD_SIZE) {
httpSendErrorResp(pContext, HTTP_TG_METRICS_SIZE); httpSendErrorResp(pContext, TSDB_CODE_HTTP_TG_METRICS_SIZE);
cJSON_Delete(root); cJSON_Delete(root);
return false; return false;
} }
if (!httpMallocMultiCmds(pContext, cmdSize, HTTP_BUFFER_SIZE)) { if (!httpMallocMultiCmds(pContext, cmdSize, HTTP_BUFFER_SIZE)) {
httpSendErrorResp(pContext, HTTP_NO_ENOUGH_MEMORY); httpSendErrorResp(pContext, TSDB_CODE_HTTP_NO_ENOUGH_MEMORY);
cJSON_Delete(root); cJSON_Delete(root);
return false; return false;
} }
HttpSqlCmd *cmd = httpNewSqlCmd(pContext); HttpSqlCmd *cmd = httpNewSqlCmd(pContext);
if (cmd == NULL) { if (cmd == NULL) {
httpSendErrorResp(pContext, HTTP_NO_ENOUGH_MEMORY); httpSendErrorResp(pContext, TSDB_CODE_HTTP_NO_ENOUGH_MEMORY);
cJSON_Delete(root); cJSON_Delete(root);
return false; return false;
} }
@ -860,14 +860,14 @@ bool tgProcessQueryRequest(HttpContext *pContext, char *db) {
httpDebug("context:%p, fd:%d, single metric", pContext, pContext->fd); httpDebug("context:%p, fd:%d, single metric", pContext, pContext->fd);
if (!httpMallocMultiCmds(pContext, 3, HTTP_BUFFER_SIZE)) { if (!httpMallocMultiCmds(pContext, 3, HTTP_BUFFER_SIZE)) {
httpSendErrorResp(pContext, HTTP_NO_ENOUGH_MEMORY); httpSendErrorResp(pContext, TSDB_CODE_HTTP_NO_ENOUGH_MEMORY);
cJSON_Delete(root); cJSON_Delete(root);
return false; return false;
} }
HttpSqlCmd *cmd = httpNewSqlCmd(pContext); HttpSqlCmd *cmd = httpNewSqlCmd(pContext);
if (cmd == NULL) { if (cmd == NULL) {
httpSendErrorResp(pContext, HTTP_NO_ENOUGH_MEMORY); httpSendErrorResp(pContext, TSDB_CODE_HTTP_NO_ENOUGH_MEMORY);
cJSON_Delete(root); cJSON_Delete(root);
return false; return false;
} }
@ -892,7 +892,7 @@ bool tgProcessQueryRequest(HttpContext *pContext, char *db) {
bool tgProcessRquest(struct HttpContext *pContext) { bool tgProcessRquest(struct HttpContext *pContext) {
if (strlen(pContext->user) == 0 || strlen(pContext->pass) == 0) { if (strlen(pContext->user) == 0 || strlen(pContext->pass) == 0) {
httpSendErrorResp(pContext, HTTP_PARSE_USR_ERROR); httpSendErrorResp(pContext, TSDB_CODE_HTTP_NO_AUTH_INFO);
return false; return false;
} }