2019-07-11 08:36:16 +00:00
|
|
|
/*
|
|
|
|
|
* 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/>.
|
|
|
|
|
*/
|
|
|
|
|
|
2022-04-20 11:44:25 +00:00
|
|
|
#ifndef _TD_SHELL_INT_H_
|
|
|
|
|
#define _TD_SHELL_INT_H_
|
2019-07-11 08:36:16 +00:00
|
|
|
|
2021-12-17 07:49:27 +00:00
|
|
|
#include "os.h"
|
|
|
|
|
#include "taos.h"
|
2020-02-14 15:18:14 +00:00
|
|
|
#include "taosdef.h"
|
2022-04-21 13:09:43 +00:00
|
|
|
#include "taoserror.h"
|
|
|
|
|
#include "tconfig.h"
|
|
|
|
|
#include "tglobal.h"
|
2022-04-24 03:19:06 +00:00
|
|
|
#include "trpc.h"
|
2022-04-21 13:09:43 +00:00
|
|
|
#include "ttypes.h"
|
|
|
|
|
#include "tutil.h"
|
2019-07-11 08:36:16 +00:00
|
|
|
|
2022-07-23 01:35:00 +00:00
|
|
|
#ifdef WEBSOCKET
|
|
|
|
|
#include "taosws.h"
|
2023-03-19 05:18:30 +00:00
|
|
|
|
|
|
|
|
#define SHELL_WS_TIMEOUT 30
|
|
|
|
|
#define SHELL_WS_DSN_BUFF 256
|
|
|
|
|
#define SHELL_WS_DSN_MASK 10
|
2022-07-23 01:35:00 +00:00
|
|
|
#endif
|
|
|
|
|
|
2022-04-21 13:09:43 +00:00
|
|
|
#define SHELL_MAX_HISTORY_SIZE 1000
|
|
|
|
|
#define SHELL_MAX_COMMAND_SIZE 1048586
|
|
|
|
|
#define SHELL_HISTORY_FILE ".taos_history"
|
|
|
|
|
#define SHELL_DEFAULT_RES_SHOW_NUM 100
|
|
|
|
|
#define SHELL_DEFAULT_MAX_BINARY_DISPLAY_WIDTH 30
|
2022-04-24 03:19:06 +00:00
|
|
|
#define SHELL_MAX_PKG_LEN 2 * 1024 * 1024
|
|
|
|
|
#define SHELL_MIN_PKG_LEN 1
|
|
|
|
|
#define SHELL_DEF_PKG_LEN 1024
|
|
|
|
|
#define SHELL_MAX_PKG_NUM 1 * 1024 * 1024
|
|
|
|
|
#define SHELL_MIN_PKG_NUM 1
|
|
|
|
|
#define SHELL_DEF_PKG_NUM 100
|
2023-06-13 10:00:52 +00:00
|
|
|
#define SHELL_FLOAT_WIDTH 20
|
|
|
|
|
#define SHELL_DOUBLE_WIDTH 25
|
2021-02-24 10:43:48 +00:00
|
|
|
|
2022-04-20 11:44:25 +00:00
|
|
|
typedef struct {
|
2022-04-21 13:09:43 +00:00
|
|
|
char* hist[SHELL_MAX_HISTORY_SIZE];
|
|
|
|
|
char file[TSDB_FILENAME_LEN];
|
2022-04-20 11:44:25 +00:00
|
|
|
int32_t hstart;
|
|
|
|
|
int32_t hend;
|
2020-05-18 02:23:39 +00:00
|
|
|
} SShellHistory;
|
2019-07-11 08:36:16 +00:00
|
|
|
|
2022-04-20 11:44:25 +00:00
|
|
|
typedef struct {
|
|
|
|
|
const char* host;
|
|
|
|
|
const char* user;
|
|
|
|
|
const char* auth;
|
|
|
|
|
const char* database;
|
|
|
|
|
const char* cfgdir;
|
|
|
|
|
const char* commands;
|
2022-04-21 13:09:43 +00:00
|
|
|
const char* netrole;
|
2022-04-22 09:59:41 +00:00
|
|
|
char file[PATH_MAX];
|
2022-04-21 13:09:43 +00:00
|
|
|
char password[TSDB_USET_PASSWORD_LEN];
|
2022-04-20 11:44:25 +00:00
|
|
|
bool is_gen_auth;
|
2023-12-30 08:44:52 +00:00
|
|
|
bool is_bi_mode;
|
2022-04-20 11:44:25 +00:00
|
|
|
bool is_raw_time;
|
|
|
|
|
bool is_version;
|
|
|
|
|
bool is_dump_config;
|
|
|
|
|
bool is_check;
|
|
|
|
|
bool is_startup;
|
|
|
|
|
bool is_help;
|
2022-04-28 01:43:08 +00:00
|
|
|
int32_t port;
|
2022-04-20 11:44:25 +00:00
|
|
|
int32_t pktLen;
|
|
|
|
|
int32_t pktNum;
|
2022-04-21 13:09:43 +00:00
|
|
|
int32_t displayWidth;
|
2022-04-20 11:44:25 +00:00
|
|
|
int32_t abort;
|
2022-07-23 01:35:00 +00:00
|
|
|
#ifdef WEBSOCKET
|
|
|
|
|
bool restful;
|
|
|
|
|
bool cloud;
|
2023-10-25 08:46:32 +00:00
|
|
|
bool local;
|
2022-07-23 01:35:00 +00:00
|
|
|
char* dsn;
|
|
|
|
|
int32_t timeout;
|
|
|
|
|
#endif
|
2022-04-20 11:44:25 +00:00
|
|
|
} SShellArgs;
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
2022-12-30 05:06:21 +00:00
|
|
|
const char *clientVersion;
|
2023-01-05 12:24:26 +00:00
|
|
|
char cusName[32];
|
2022-12-30 05:06:21 +00:00
|
|
|
char promptHeader[32];
|
2023-03-09 11:04:25 +00:00
|
|
|
char promptContinue[32];
|
2022-04-21 13:09:43 +00:00
|
|
|
const char* osname;
|
|
|
|
|
int32_t promptSize;
|
2023-02-22 07:16:16 +00:00
|
|
|
char programVersion[256];
|
2022-04-21 13:09:43 +00:00
|
|
|
} SShellOsDetails;
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
SShellArgs args;
|
|
|
|
|
SShellHistory history;
|
|
|
|
|
SShellOsDetails info;
|
|
|
|
|
TAOS* conn;
|
|
|
|
|
TdThread pid;
|
|
|
|
|
tsem_t cancelSem;
|
2022-08-22 07:22:49 +00:00
|
|
|
bool exit;
|
2022-07-23 01:35:00 +00:00
|
|
|
#ifdef WEBSOCKET
|
|
|
|
|
WS_TAOS* ws_conn;
|
2023-03-19 05:18:30 +00:00
|
|
|
bool stop_query;
|
2022-07-23 01:35:00 +00:00
|
|
|
#endif
|
2022-04-20 11:44:25 +00:00
|
|
|
} SShellObj;
|
|
|
|
|
|
2022-09-07 02:16:00 +00:00
|
|
|
typedef struct {
|
|
|
|
|
char *buffer;
|
|
|
|
|
char *command;
|
|
|
|
|
uint32_t commandSize;
|
|
|
|
|
uint32_t bufferSize;
|
|
|
|
|
uint32_t cursorOffset;
|
|
|
|
|
uint32_t screenOffset;
|
|
|
|
|
uint32_t endOffset;
|
|
|
|
|
} SShellCmd;
|
|
|
|
|
|
2022-04-21 13:09:43 +00:00
|
|
|
// shellArguments.c
|
2022-04-20 11:44:25 +00:00
|
|
|
int32_t shellParseArgs(int32_t argc, char* argv[]);
|
|
|
|
|
|
2022-04-21 13:09:43 +00:00
|
|
|
// shellCommand.c
|
|
|
|
|
int32_t shellReadCommand(char* command);
|
|
|
|
|
|
|
|
|
|
// shellEngine.c
|
|
|
|
|
int32_t shellExecute();
|
2022-07-23 01:35:00 +00:00
|
|
|
int32_t shellCalcColWidth(TAOS_FIELD *field, int32_t precision);
|
|
|
|
|
void shellPrintHeader(TAOS_FIELD *fields, int32_t *width, int32_t num_fields);
|
|
|
|
|
void shellPrintField(const char *val, TAOS_FIELD *field, int32_t width, int32_t length, int32_t precision);
|
2022-08-30 09:21:38 +00:00
|
|
|
void shellDumpFieldToFile(TdFilePtr pFile, const char *val, TAOS_FIELD *field, int32_t length, int32_t precision);
|
2022-04-21 13:09:43 +00:00
|
|
|
// shellUtil.c
|
|
|
|
|
int32_t shellCheckIntSize();
|
|
|
|
|
void shellPrintVersion();
|
2022-04-22 09:59:41 +00:00
|
|
|
void shellPrintHelp();
|
2022-04-21 13:09:43 +00:00
|
|
|
void shellGenerateAuth();
|
|
|
|
|
void shellDumpConfig();
|
|
|
|
|
void shellCheckServerStatus();
|
|
|
|
|
bool shellRegexMatch(const char* s, const char* reg, int32_t cflags);
|
2022-04-21 13:29:21 +00:00
|
|
|
void shellExit();
|
2019-07-11 08:36:16 +00:00
|
|
|
|
2022-04-21 13:09:43 +00:00
|
|
|
// shellNettest.c
|
|
|
|
|
void shellTestNetWork();
|
2019-07-11 08:36:16 +00:00
|
|
|
|
2022-07-23 01:35:00 +00:00
|
|
|
#ifdef WEBSOCKET
|
2023-03-19 05:18:30 +00:00
|
|
|
void shellCheckConnectMode();
|
2022-07-23 01:35:00 +00:00
|
|
|
// shellWebsocket.c
|
|
|
|
|
int shell_conn_ws_server(bool first);
|
|
|
|
|
int32_t shell_run_websocket();
|
|
|
|
|
void shellRunSingleCommandWebsocketImp(char *command);
|
|
|
|
|
#endif
|
|
|
|
|
|
2022-04-21 13:09:43 +00:00
|
|
|
// shellMain.c
|
2022-04-20 11:44:25 +00:00
|
|
|
extern SShellObj shell;
|
2023-01-17 03:18:49 +00:00
|
|
|
extern void tscWriteCrashInfo(int signum, void *sigInfo, void *context);
|
2019-07-11 08:36:16 +00:00
|
|
|
|
2022-04-20 11:44:25 +00:00
|
|
|
#endif /*_TD_SHELL_INT_H_*/
|