shell.h 3.0 KB
Newer Older
H
hzcheng 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/*
 * 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 __SHELL__
#define __SHELL__

#include "stdbool.h"
#include "taos.h"
S
slguan 已提交
21
#include "taosdef.h"
S
slguan 已提交
22
#include "stdbool.h"
H
Haojun Liao 已提交
23
#include "tsclient.h"
H
hzcheng 已提交
24 25 26 27 28

#define MAX_USERNAME_SIZE      64
#define MAX_DBNAME_SIZE        64
#define MAX_IP_SIZE            20
#define MAX_HISTORY_SIZE       1000
D
dapan1121 已提交
29
#define MAX_COMMAND_SIZE       1048586
30 31 32 33 34 35

#ifdef _TD_PRO_
    #define HISTORY_FILE           ".prodb_history"
#else
    #define HISTORY_FILE           ".taos_history"
#endif
H
hzcheng 已提交
36

D
fix bug  
dapan1121 已提交
37 38
#define DEFAULT_RES_SHOW_NUM   100

39
typedef struct SShellHistory {
H
hzcheng 已提交
40 41 42
  char* hist[MAX_HISTORY_SIZE];
  int   hstart;
  int   hend;
43
} SShellHistory;
H
hzcheng 已提交
44

45
typedef struct SShellArguments {
H
hzcheng 已提交
46 47 48
  char* host;
  char* password;
  char* user;
49
  char* auth;
H
hzcheng 已提交
50 51 52 53
  char* database;
  char* timezone;
  bool  is_raw_time;
  bool  is_use_passwd;
54
  bool  dump_config;
H
hzcheng 已提交
55
  char  file[TSDB_FILENAME_LEN];
S
#928  
slguan 已提交
56 57
  char  dir[TSDB_FILENAME_LEN];
  int   threadNum;
S
TD-3309  
Shengliang Guan 已提交
58
  int   check;
H
hzcheng 已提交
59 60
  char* commands;
  int   abort;
S
#1811  
slguan 已提交
61
  int   port;
H
Hui Li 已提交
62
  int   pktLen;
63 64
  int   pktNum;
  char* pktType;
H
Hui Li 已提交
65
  char* netTestRole;
66
} SShellArguments;
H
hzcheng 已提交
67 68

/**************** Function declarations ****************/
69 70
extern void shellParseArgument(int argc, char* argv[], SShellArguments* arguments);
extern TAOS* shellInit(SShellArguments* args);
H
hzcheng 已提交
71
extern void* shellLoopQuery(void* arg);
S
TD-1793  
Shengliang Guan 已提交
72
extern void taos_error(TAOS_RES* tres, int64_t st);
H
hzcheng 已提交
73
extern int regex_match(const char* s, const char* reg, int cflags);
D
fix bug  
dapan1121 已提交
74
int32_t shellReadCommand(TAOS* con, char command[]);
75
int32_t shellRunCommand(TAOS* con, char* command);
H
hzcheng 已提交
76 77 78 79
void shellRunCommandOnServer(TAOS* con, char command[]);
void read_history();
void write_history();
void source_file(TAOS* con, char* fptr);
80
void source_dir(TAOS* con, SShellArguments* args);
S
TD-3309  
Shengliang Guan 已提交
81
void shellCheck(TAOS* con, SShellArguments* args);
H
hzcheng 已提交
82
void get_history_path(char* history);
S
Shengliang Guan 已提交
83
void shellCheck(TAOS* con, SShellArguments* args);
H
hzcheng 已提交
84 85
void cleanup_handler(void* arg);
void exitShell();
86
int shellDumpResult(TAOS_RES* con, char* fname, int* error_no, bool printMode);
S
slguan 已提交
87
void shellGetGrantInfo(void *con);
S
#928  
slguan 已提交
88
int isCommentLine(char *line);
H
hzcheng 已提交
89 90 91 92 93

/**************** Global variable declarations ****************/
extern char           PROMPT_HEADER[];
extern char           CONTINUE_PROMPT[];
extern int            prompt_size;
94
extern SShellHistory  history;
H
hzcheng 已提交
95 96 97
extern struct termios oldtio;
extern void           set_terminal_mode();
extern int get_old_terminal_mode(struct termios* tio);
98 99
extern void            reset_terminal_mode();
extern SShellArguments args;
D
fix bug  
dapan1121 已提交
100
extern int64_t         result;
H
hzcheng 已提交
101 102

#endif