[TD-6001]<enhance>: use db_name in url if exists
This commit is contained in:
parent
03c9253d9a
commit
96a4a48e43
|
@ -4,6 +4,7 @@ PROJECT(TDengine)
|
||||||
INCLUDE_DIRECTORIES(inc)
|
INCLUDE_DIRECTORIES(inc)
|
||||||
INCLUDE_DIRECTORIES(jni)
|
INCLUDE_DIRECTORIES(jni)
|
||||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/query/inc)
|
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/query/inc)
|
||||||
|
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/plugins/http/inc)
|
||||||
AUX_SOURCE_DIRECTORY(src SRC)
|
AUX_SOURCE_DIRECTORY(src SRC)
|
||||||
|
|
||||||
IF (TD_LINUX)
|
IF (TD_LINUX)
|
||||||
|
|
|
@ -38,6 +38,11 @@ extern "C" {
|
||||||
#include "qUtil.h"
|
#include "qUtil.h"
|
||||||
#include "tcmdtype.h"
|
#include "tcmdtype.h"
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
TAOS_REQ_FROM_SHELL,
|
||||||
|
TAOS_REQ_FROM_HTTP
|
||||||
|
} SReqOrigin;
|
||||||
|
|
||||||
// forward declaration
|
// forward declaration
|
||||||
struct SSqlInfo;
|
struct SSqlInfo;
|
||||||
|
|
||||||
|
@ -340,6 +345,7 @@ typedef struct STscObj {
|
||||||
SRpcCorEpSet *tscCorMgmtEpSet;
|
SRpcCorEpSet *tscCorMgmtEpSet;
|
||||||
pthread_mutex_t mutex;
|
pthread_mutex_t mutex;
|
||||||
int32_t numOfObj; // number of sqlObj from this tscObj
|
int32_t numOfObj; // number of sqlObj from this tscObj
|
||||||
|
SReqOrigin from;
|
||||||
} STscObj;
|
} STscObj;
|
||||||
|
|
||||||
typedef struct SSubqueryState {
|
typedef struct SSubqueryState {
|
||||||
|
|
|
@ -40,6 +40,7 @@
|
||||||
#include "qScript.h"
|
#include "qScript.h"
|
||||||
#include "ttype.h"
|
#include "ttype.h"
|
||||||
#include "qFilter.h"
|
#include "qFilter.h"
|
||||||
|
#include "httpInt.h"
|
||||||
|
|
||||||
#define DEFAULT_PRIMARY_TIMESTAMP_COL_NAME "_c0"
|
#define DEFAULT_PRIMARY_TIMESTAMP_COL_NAME "_c0"
|
||||||
|
|
||||||
|
@ -1687,8 +1688,28 @@ static bool has(SArray* pFieldList, int32_t startIdx, const char* name) {
|
||||||
static char* getAccountId(SSqlObj* pSql) { return pSql->pTscObj->acctId; }
|
static char* getAccountId(SSqlObj* pSql) { return pSql->pTscObj->acctId; }
|
||||||
|
|
||||||
static char* cloneCurrentDBName(SSqlObj* pSql) {
|
static char* cloneCurrentDBName(SSqlObj* pSql) {
|
||||||
|
char *p = NULL;
|
||||||
|
HttpContext *pCtx = NULL;
|
||||||
|
|
||||||
pthread_mutex_lock(&pSql->pTscObj->mutex);
|
pthread_mutex_lock(&pSql->pTscObj->mutex);
|
||||||
char *p = strdup(pSql->pTscObj->db);
|
STscObj *pTscObj = pSql->pTscObj;
|
||||||
|
switch (pTscObj->from) {
|
||||||
|
case TAOS_REQ_FROM_HTTP:
|
||||||
|
pCtx = pSql->param;
|
||||||
|
if (pCtx && pCtx->db[0] != '\0') {
|
||||||
|
char db[TSDB_ACCT_ID_LEN + TSDB_DB_NAME_LEN] = {0};
|
||||||
|
int32_t len = sprintf(db, "%s%s%s", pTscObj->acctId, TS_PATH_DELIMITER, pCtx->db);
|
||||||
|
assert(len <= sizeof(db));
|
||||||
|
|
||||||
|
p = strdup(db);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (p == NULL) {
|
||||||
|
p = strdup(pSql->pTscObj->db);
|
||||||
|
}
|
||||||
pthread_mutex_unlock(&pSql->pTscObj->mutex);
|
pthread_mutex_unlock(&pSql->pTscObj->mutex);
|
||||||
|
|
||||||
return p;
|
return p;
|
||||||
|
@ -8685,7 +8706,6 @@ static STableMeta* extractTempTableMetaFromSubquery(SQueryInfo* pUpstream) {
|
||||||
}
|
}
|
||||||
info->numOfColumns = n;
|
info->numOfColumns = n;
|
||||||
|
|
||||||
|
|
||||||
return meta;
|
return meta;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -150,6 +150,7 @@ typedef struct HttpContext {
|
||||||
char ipstr[22];
|
char ipstr[22];
|
||||||
char user[TSDB_USER_LEN]; // parsed from auth token or login message
|
char user[TSDB_USER_LEN]; // parsed from auth token or login message
|
||||||
char pass[HTTP_PASSWORD_LEN];
|
char pass[HTTP_PASSWORD_LEN];
|
||||||
|
char db[/*TSDB_ACCT_ID_LEN + */TSDB_DB_NAME_LEN];
|
||||||
TAOS * taos;
|
TAOS * taos;
|
||||||
void * ppContext;
|
void * ppContext;
|
||||||
HttpSession *session;
|
HttpSession *session;
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
|
|
||||||
#define REST_ROOT_URL_POS 0
|
#define REST_ROOT_URL_POS 0
|
||||||
#define REST_ACTION_URL_POS 1
|
#define REST_ACTION_URL_POS 1
|
||||||
#define REST_USER_URL_POS 2
|
#define REST_USER_USEDB_URL_POS 2
|
||||||
#define REST_PASS_URL_POS 3
|
#define REST_PASS_URL_POS 3
|
||||||
|
|
||||||
void restInitHandle(HttpServer* pServer);
|
void restInitHandle(HttpServer* pServer);
|
||||||
|
|
|
@ -62,11 +62,11 @@ void restInitHandle(HttpServer* pServer) {
|
||||||
|
|
||||||
bool restGetUserFromUrl(HttpContext* pContext) {
|
bool restGetUserFromUrl(HttpContext* pContext) {
|
||||||
HttpParser* pParser = pContext->parser;
|
HttpParser* pParser = pContext->parser;
|
||||||
if (pParser->path[REST_USER_URL_POS].pos >= TSDB_USER_LEN || pParser->path[REST_USER_URL_POS].pos <= 0) {
|
if (pParser->path[REST_USER_USEDB_URL_POS].pos >= TSDB_USER_LEN || pParser->path[REST_USER_USEDB_URL_POS].pos <= 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
tstrncpy(pContext->user, pParser->path[REST_USER_URL_POS].str, TSDB_USER_LEN);
|
tstrncpy(pContext->user, pParser->path[REST_USER_USEDB_URL_POS].str, TSDB_USER_LEN);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,6 +107,16 @@ bool restProcessSqlRequest(HttpContext* pContext, int32_t timestampFmt) {
|
||||||
HttpSqlCmd* cmd = &(pContext->singleCmd);
|
HttpSqlCmd* cmd = &(pContext->singleCmd);
|
||||||
cmd->nativSql = sql;
|
cmd->nativSql = sql;
|
||||||
|
|
||||||
|
/* find if there is db_name in url */
|
||||||
|
pContext->db[0] = '\0';
|
||||||
|
|
||||||
|
HttpString *path = &pContext->parser->path[REST_USER_USEDB_URL_POS];
|
||||||
|
if (path->pos > 0 && !(strlen(sql) > 4 && (sql[0] == 'u' || sql[0] == 'U') &&
|
||||||
|
(sql[1] == 's' || sql[1] == 'S') && (sql[2] == 'e' || sql[2] == 'E') && sql[3] == ' '))
|
||||||
|
{
|
||||||
|
snprintf(pContext->db, /*TSDB_ACCT_ID_LEN + */TSDB_DB_NAME_LEN, "%s", path->str);
|
||||||
|
}
|
||||||
|
|
||||||
pContext->reqType = HTTP_REQTYPE_SINGLE_SQL;
|
pContext->reqType = HTTP_REQTYPE_SINGLE_SQL;
|
||||||
if (timestampFmt == REST_TIMESTAMP_FMT_LOCAL_STRING) {
|
if (timestampFmt == REST_TIMESTAMP_FMT_LOCAL_STRING) {
|
||||||
pContext->encodeMethod = &restEncodeSqlLocalTimeStringMethod;
|
pContext->encodeMethod = &restEncodeSqlLocalTimeStringMethod;
|
||||||
|
|
|
@ -419,6 +419,11 @@ void httpProcessRequest(HttpContext *pContext) {
|
||||||
&(pContext->taos));
|
&(pContext->taos));
|
||||||
httpDebug("context:%p, fd:%d, user:%s, try connect tdengine, taos:%p", pContext, pContext->fd, pContext->user,
|
httpDebug("context:%p, fd:%d, user:%s, try connect tdengine, taos:%p", pContext, pContext->fd, pContext->user,
|
||||||
pContext->taos);
|
pContext->taos);
|
||||||
|
|
||||||
|
if (pContext->taos != NULL) {
|
||||||
|
STscObj *pObj = pContext->taos;
|
||||||
|
pObj->from = TAOS_REQ_FROM_HTTP;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
httpExecCmd(pContext);
|
httpExecCmd(pContext);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue