shellInt.h 3.8 KB
Newer Older
H
hzcheng 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*
 * 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/>.
 */

16 17
#ifndef _TD_SHELL_INT_H_
#define _TD_SHELL_INT_H_
H
hzcheng 已提交
18

S
Shengliang Guan 已提交
19 20
#include "os.h"
#include "taos.h"
S
slguan 已提交
21
#include "taosdef.h"
22 23 24
#include "taoserror.h"
#include "tconfig.h"
#include "tglobal.h"
25
#include "trpc.h"
26 27
#include "ttypes.h"
#include "tutil.h"
H
hzcheng 已提交
28

Y
Yang Zhao 已提交
29 30 31 32
#ifdef WEBSOCKET
#include "taosws.h"
#endif

33 34 35 36 37
#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
38 39 40 41 42 43
#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
D
fix bug  
dapan1121 已提交
44

45
typedef struct {
46 47
  char*   hist[SHELL_MAX_HISTORY_SIZE];
  char    file[TSDB_FILENAME_LEN];
48 49
  int32_t hstart;
  int32_t hend;
50
} SShellHistory;
H
hzcheng 已提交
51

52 53 54 55 56 57 58
typedef struct {
  const char* host;
  const char* user;
  const char* auth;
  const char* database;
  const char* cfgdir;
  const char* commands;
59
  const char* netrole;
60
  char        file[PATH_MAX];
61
  char        password[TSDB_USET_PASSWORD_LEN];
62 63 64 65 66 67 68
  bool        is_gen_auth;
  bool        is_raw_time;
  bool        is_version;
  bool        is_dump_config;
  bool        is_check;
  bool        is_startup;
  bool        is_help;
69
  int32_t     port;
70 71
  int32_t     pktLen;
  int32_t     pktNum;
72
  int32_t     displayWidth;
73
  int32_t     abort;
Y
Yang Zhao 已提交
74 75 76 77 78 79
#ifdef WEBSOCKET
  bool        restful;
  bool        cloud;
  char*       dsn;
  int32_t     timeout;
#endif
80 81 82
} SShellArgs;

typedef struct {
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
  const char* clientVersion;
  const char* promptHeader;
  const char* promptContinue;
  const char* osname;
  int32_t     promptSize;
  char        programVersion[32];
} SShellOsDetails;

typedef struct {
  SShellArgs      args;
  SShellHistory   history;
  SShellOsDetails info;
  TAOS*           conn;
  TdThread        pid;
  tsem_t          cancelSem;
Y
Yang Zhao 已提交
98 99 100 101
#ifdef WEBSOCKET
  WS_TAOS*        ws_conn;
  bool		      stop_query;
#endif
102 103
} SShellObj;

104
// shellArguments.c
105 106
int32_t shellParseArgs(int32_t argc, char* argv[]);

107 108 109 110 111
// shellCommand.c
int32_t shellReadCommand(char* command);

// shellEngine.c
int32_t shellExecute();
Y
Yang Zhao 已提交
112 113 114 115
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);
void shellDumpFieldToFile(TdFilePtr pFile, const char *val, TAOS_FIELD *field, int32_t length, int32_t precision); 
116 117 118
// shellUtil.c
int32_t shellCheckIntSize();
void    shellPrintVersion();
119
void    shellPrintHelp();
120 121 122 123
void    shellGenerateAuth();
void    shellDumpConfig();
void    shellCheckServerStatus();
bool    shellRegexMatch(const char* s, const char* reg, int32_t cflags);
124
void    shellExit();
H
hzcheng 已提交
125

126 127
// shellNettest.c
void shellTestNetWork();
H
hzcheng 已提交
128

Y
Yang Zhao 已提交
129 130 131 132 133 134 135 136
#ifdef WEBSOCKET
void	shellCheckConnectMode();
// shellWebsocket.c
int shell_conn_ws_server(bool first);
int32_t shell_run_websocket();
void shellRunSingleCommandWebsocketImp(char *command); 
#endif

137
// shellMain.c
138
extern SShellObj shell;
H
hzcheng 已提交
139

140
#endif /*_TD_SHELL_INT_H_*/