提交 33ac1a92 编写于 作者: sangshuduo's avatar sangshuduo

make taos.exe use mysql style password input.

上级 efe96a31
...@@ -65,7 +65,15 @@ extern TAOS *taos_connect_auth(const char *ip, const char *user, const char *aut ...@@ -65,7 +65,15 @@ extern TAOS *taos_connect_auth(const char *ip, const char *user, const char *aut
*/ */
TAOS *shellInit(SShellArguments *_args) { TAOS *shellInit(SShellArguments *_args) {
printf("\n"); printf("\n");
#ifndef WINDOWS
printf(CLIENT_VERSION, tsOsName, taos_get_client_info()); printf(CLIENT_VERSION, tsOsName, taos_get_client_info());
#else
if (!_args->is_use_passwd) {
strcpy(tsOsName, "Windows");
printf(CLIENT_VERSION, tsOsName, taos_get_client_info());
}
#endif
fflush(stdout); fflush(stdout);
// set options before initializing // set options before initializing
...@@ -74,7 +82,9 @@ TAOS *shellInit(SShellArguments *_args) { ...@@ -74,7 +82,9 @@ TAOS *shellInit(SShellArguments *_args) {
} }
if (_args->is_use_passwd) { if (_args->is_use_passwd) {
#ifndef TD_WINDOWS
if (_args->password == NULL) _args->password = getpass("Enter password: "); if (_args->password == NULL) _args->password = getpass("Enter password: ");
#endif
} else { } else {
_args->password = TSDB_DEFAULT_PASS; _args->password = TSDB_DEFAULT_PASS;
} }
...@@ -170,7 +180,7 @@ static int32_t shellRunSingleCommand(TAOS *con, char *command) { ...@@ -170,7 +180,7 @@ static int32_t shellRunSingleCommand(TAOS *con, char *command) {
system("clear"); system("clear");
return 0; return 0;
} }
if (regex_match(command, "^[\t ]*set[ \t]+max_binary_display_width[ \t]+(default|[1-9][0-9]*)[ \t;]*$", REG_EXTENDED | REG_ICASE)) { if (regex_match(command, "^[\t ]*set[ \t]+max_binary_display_width[ \t]+(default|[1-9][0-9]*)[ \t;]*$", REG_EXTENDED | REG_ICASE)) {
strtok(command, " \t"); strtok(command, " \t");
strtok(NULL, " \t"); strtok(NULL, " \t");
...@@ -182,7 +192,7 @@ static int32_t shellRunSingleCommand(TAOS *con, char *command) { ...@@ -182,7 +192,7 @@ static int32_t shellRunSingleCommand(TAOS *con, char *command) {
} }
return 0; return 0;
} }
if (regex_match(command, "^[ \t]*source[\t ]+[^ ]+[ \t;]*$", REG_EXTENDED | REG_ICASE)) { if (regex_match(command, "^[ \t]*source[\t ]+[^ ]+[ \t;]*$", REG_EXTENDED | REG_ICASE)) {
/* If source file. */ /* If source file. */
char *c_ptr = strtok(command, " ;"); char *c_ptr = strtok(command, " ;");
...@@ -247,7 +257,7 @@ int32_t shellRunCommand(TAOS* con, char* command) { ...@@ -247,7 +257,7 @@ int32_t shellRunCommand(TAOS* con, char* command) {
esc = false; esc = false;
continue; continue;
} }
if (c == '\\') { if (c == '\\') {
esc = true; esc = true;
continue; continue;
...@@ -336,8 +346,8 @@ void shellRunCommandOnServer(TAOS *con, char command[]) { ...@@ -336,8 +346,8 @@ void shellRunCommandOnServer(TAOS *con, char command[]) {
} }
if (!tscIsUpdateQuery(pSql)) { // select and show kinds of commands if (!tscIsUpdateQuery(pSql)) { // select and show kinds of commands
int error_no = 0; int error_no = 0;
int numOfRows = shellDumpResult(pSql, fname, &error_no, printMode); int numOfRows = shellDumpResult(pSql, fname, &error_no, printMode);
if (numOfRows < 0) { if (numOfRows < 0) {
atomic_store_64(&result, 0); atomic_store_64(&result, 0);
...@@ -530,7 +540,7 @@ static int dumpResultToFile(const char* fname, TAOS_RES* tres) { ...@@ -530,7 +540,7 @@ static int dumpResultToFile(const char* fname, TAOS_RES* tres) {
fprintf(fp, "%s", fields[col].name); fprintf(fp, "%s", fields[col].name);
} }
fputc('\n', fp); fputc('\n', fp);
int numOfRows = 0; int numOfRows = 0;
do { do {
int32_t* length = taos_fetch_lengths(tres); int32_t* length = taos_fetch_lengths(tres);
...@@ -716,7 +726,7 @@ static int verticalPrintResult(TAOS_RES* tres) { ...@@ -716,7 +726,7 @@ static int verticalPrintResult(TAOS_RES* tres) {
int numOfRows = 0; int numOfRows = 0;
int showMore = 1; int showMore = 1;
do { do {
if (numOfRows < resShowMaxNum) { if (numOfRows < resShowMaxNum) {
printf("*************************** %d.row ***************************\n", numOfRows + 1); printf("*************************** %d.row ***************************\n", numOfRows + 1);
...@@ -851,7 +861,7 @@ static int horizontalPrintResult(TAOS_RES* tres) { ...@@ -851,7 +861,7 @@ static int horizontalPrintResult(TAOS_RES* tres) {
int numOfRows = 0; int numOfRows = 0;
int showMore = 1; int showMore = 1;
do { do {
int32_t* length = taos_fetch_lengths(tres); int32_t* length = taos_fetch_lengths(tres);
if (numOfRows < resShowMaxNum) { if (numOfRows < resShowMaxNum) {
...@@ -867,7 +877,7 @@ static int horizontalPrintResult(TAOS_RES* tres) { ...@@ -867,7 +877,7 @@ static int horizontalPrintResult(TAOS_RES* tres) {
printf("[You can add limit statement to show more or redirect results to specific file to get all.]\n"); printf("[You can add limit statement to show more or redirect results to specific file to get all.]\n");
showMore = 0; showMore = 0;
} }
numOfRows++; numOfRows++;
row = taos_fetch_row(tres); row = taos_fetch_row(tres);
} while(row != NULL); } while(row != NULL);
...@@ -909,7 +919,7 @@ void read_history() { ...@@ -909,7 +919,7 @@ void read_history() {
if (errno != ENOENT) { if (errno != ENOENT) {
fprintf(stderr, "Failed to open file %s, reason:%s\n", f_history, strerror(errno)); fprintf(stderr, "Failed to open file %s, reason:%s\n", f_history, strerror(errno));
} }
#endif #endif
return; return;
} }
...@@ -934,9 +944,9 @@ void write_history() { ...@@ -934,9 +944,9 @@ void write_history() {
FILE *f = fopen(f_history, "w"); FILE *f = fopen(f_history, "w");
if (f == NULL) { if (f == NULL) {
#ifndef WINDOWS #ifndef WINDOWS
fprintf(stderr, "Failed to open file %s for write, reason:%s\n", f_history, strerror(errno)); fprintf(stderr, "Failed to open file %s for write, reason:%s\n", f_history, strerror(errno));
#endif #endif
return; return;
} }
...@@ -982,13 +992,13 @@ void source_file(TAOS *con, char *fptr) { ...@@ -982,13 +992,13 @@ void source_file(TAOS *con, char *fptr) {
/* /*
if (access(fname, F_OK) != 0) { if (access(fname, F_OK) != 0) {
fprintf(stderr, "ERROR: file %s is not exist\n", fptr); fprintf(stderr, "ERROR: file %s is not exist\n", fptr);
wordfree(&full_path); wordfree(&full_path);
free(cmd); free(cmd);
return; return;
} }
*/ */
FILE *f = fopen(fname, "r"); FILE *f = fopen(fname, "r");
if (f == NULL) { if (f == NULL) {
fprintf(stderr, "ERROR: failed to open file %s\n", fname); fprintf(stderr, "ERROR: failed to open file %s\n", fname);
......
...@@ -71,7 +71,9 @@ int checkVersion() { ...@@ -71,7 +71,9 @@ int checkVersion() {
// Global configurations // Global configurations
SShellArguments args = { SShellArguments args = {
.host = NULL, .host = NULL,
#ifndef TD_WINDOWS
.password = NULL, .password = NULL,
#endif
.user = NULL, .user = NULL,
.database = NULL, .database = NULL,
.timezone = NULL, .timezone = NULL,
......
...@@ -19,6 +19,9 @@ ...@@ -19,6 +19,9 @@
extern char configDir[]; extern char configDir[];
char WINCLIENT_VERSION[] = "Welcome to the TDengine shell from %s, Client Version:%s\n"
"Copyright (c) 2020 by TAOS Data, Inc. All rights reserved.\n\n";
void printVersion() { void printVersion() {
printf("version: %s\n", version); printf("version: %s\n", version);
} }
...@@ -61,6 +64,8 @@ void printHelp() { ...@@ -61,6 +64,8 @@ void printHelp() {
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }
char g_password[MAX_PASSWORD_SIZE];
void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) { void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) {
for (int i = 1; i < argc; i++) { for (int i = 1; i < argc; i++) {
// for host // for host
...@@ -73,11 +78,18 @@ void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) { ...@@ -73,11 +78,18 @@ void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) {
} }
} }
// for password // for password
else if (strcmp(argv[i], "-p") == 0) { else if (strncmp(argv[i], "-p", 2) == 0) {
arguments->is_use_passwd = true; arguments->is_use_passwd = true;
if (i < argc - 1 && argv[i + 1][0] != '-') { strcpy(tsOsName, "Windows");
arguments->password = argv[++i]; printf(WINCLIENT_VERSION, tsOsName, taos_get_client_info());
} if (strlen(argv[i]) == 2) {
printf("Enter password: ");
scanf("%s", g_password);
getchar();
} else {
tstrncpy(g_password, (char *)(argv[i] + 2), MAX_PASSWORD_SIZE);
}
arguments->password = g_password;
} }
// for management port // for management port
else if (strcmp(argv[i], "-P") == 0) { else if (strcmp(argv[i], "-P") == 0) {
...@@ -104,7 +116,7 @@ void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) { ...@@ -104,7 +116,7 @@ void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) {
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} else if (strcmp(argv[i], "-c") == 0) { } else if (strcmp(argv[i], "-c") == 0) {
if (i < argc - 1) { if (i < argc - 1) {
char *tmp = argv[++i]; char *tmp = argv[++i];
if (strlen(tmp) >= TSDB_FILENAME_LEN) { if (strlen(tmp) >= TSDB_FILENAME_LEN) {
fprintf(stderr, "config file path: %s overflow max len %d\n", tmp, TSDB_FILENAME_LEN - 1); fprintf(stderr, "config file path: %s overflow max len %d\n", tmp, TSDB_FILENAME_LEN - 1);
...@@ -265,7 +277,7 @@ void *shellLoopQuery(void *arg) { ...@@ -265,7 +277,7 @@ void *shellLoopQuery(void *arg) {
if (command == NULL) return NULL; if (command == NULL) return NULL;
int32_t err = 0; int32_t err = 0;
do { do {
memset(command, 0, MAX_COMMAND_SIZE); memset(command, 0, MAX_COMMAND_SIZE);
shellPrintPrompt(); shellPrintPrompt();
...@@ -274,7 +286,7 @@ void *shellLoopQuery(void *arg) { ...@@ -274,7 +286,7 @@ void *shellLoopQuery(void *arg) {
err = shellReadCommand(con, command); err = shellReadCommand(con, command);
if (err) { if (err) {
break; break;
} }
} while (shellRunCommand(con, command) == 0); } while (shellRunCommand(con, command) == 0);
return NULL; return NULL;
......
...@@ -77,7 +77,7 @@ extern char configDir[]; ...@@ -77,7 +77,7 @@ extern char configDir[];
#define COL_BUFFER_LEN ((TSDB_COL_NAME_LEN + 15) * TSDB_MAX_COLUMNS) #define COL_BUFFER_LEN ((TSDB_COL_NAME_LEN + 15) * TSDB_MAX_COLUMNS)
#define MAX_USERNAME_SIZE 64 #define MAX_USERNAME_SIZE 64
#define MAX_PASSWORD_SIZE 16 #define MAX_PASSWORD_SIZE 20
#define MAX_HOSTNAME_SIZE 253 // https://man7.org/linux/man-pages/man7/hostname.7.html #define MAX_HOSTNAME_SIZE 253 // https://man7.org/linux/man-pages/man7/hostname.7.html
#define MAX_TB_NAME_SIZE 64 #define MAX_TB_NAME_SIZE 64
#define MAX_DATA_SIZE (16*TSDB_MAX_COLUMNS)+20 // max record len: 16*MAX_COLUMNS, timestamp string and ,('') need extra space #define MAX_DATA_SIZE (16*TSDB_MAX_COLUMNS)+20 // max record len: 16*MAX_COLUMNS, timestamp string and ,('') need extra space
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册