未验证 提交 02f6f5e4 编写于 作者: sangshuduo's avatar sangshuduo 提交者: GitHub

Feature/sangshuduo/td 5844 cmdline parameters align (#7239)

* [TD-5844]<feature>: make cmd line parameter similar.

* fix test case align with taosdemo change.

* fix windows stack overflow issue.

* fix mac compile error.

* fix taosdemo cmdline parameter in tests/pytest/tools/taosdemoAllTest/NanoTestCase/taosdemoTestSupportNanoInsert.py

* fix windows compiler options.

* make taos.exe use mysql style password input.

* make taos shell and taosdump use mysql style password input.

* determine scanf return value.
上级 0b6a2ffd
...@@ -180,7 +180,7 @@ IF (TD_WINDOWS) ...@@ -180,7 +180,7 @@ IF (TD_WINDOWS)
ADD_DEFINITIONS(-D_MBCS -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE) ADD_DEFINITIONS(-D_MBCS -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE)
SET(CMAKE_GENERATOR "NMake Makefiles" CACHE INTERNAL "" FORCE) SET(CMAKE_GENERATOR "NMake Makefiles" CACHE INTERNAL "" FORCE)
IF (NOT TD_GODLL) IF (NOT TD_GODLL)
SET(COMMON_FLAGS "/nologo /WX /wd4018 /wd2220 /Oi /Oy- /Gm- /EHsc /MT /GS /Gy /fp:precise /Zc:wchar_t /Zc:forScope /Gd /errorReport:prompt /analyze-") SET(COMMON_FLAGS "/nologo /WX /wd4018 /wd5999 /Oi /Oy- /Gm- /EHsc /MT /GS /Gy /fp:precise /Zc:wchar_t /Zc:forScope /Gd /errorReport:prompt /analyze-")
IF (MSVC AND (MSVC_VERSION GREATER_EQUAL 1900)) IF (MSVC AND (MSVC_VERSION GREATER_EQUAL 1900))
SET(COMMON_FLAGS "${COMMON_FLAGS} /Wv:18") SET(COMMON_FLAGS "${COMMON_FLAGS} /Wv:18")
ENDIF () ENDIF ()
......
...@@ -34,12 +34,22 @@ ENDIF () ...@@ -34,12 +34,22 @@ ENDIF ()
# #
# Set compiler options # Set compiler options
SET(COMMON_C_FLAGS "${COMMON_FLAGS} -std=gnu99") IF (TD_LINUX)
SET(COMMON_C_FLAGS "${COMMON_FLAGS} -std=gnu99")
ELSE ()
SET(COMMON_C_FLAGS "${COMMON_FLAGS} ")
ENDIF ()
SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${COMMON_C_FLAGS} ${DEBUG_FLAGS}") SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${COMMON_C_FLAGS} ${DEBUG_FLAGS}")
SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${COMMON_C_FLAGS} ${RELEASE_FLAGS}") SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${COMMON_C_FLAGS} ${RELEASE_FLAGS}")
# Set c++ compiler options # Set c++ compiler options
SET(COMMON_CXX_FLAGS "${COMMON_FLAGS} -std=c++11 -Wno-unused-function") IF (TD_WINDOWS)
SET(COMMON_CXX_FLAGS "${COMMON_FLAGS} -std=c++11")
ELSE ()
SET(COMMON_CXX_FLAGS "${COMMON_FLAGS} -std=c++11 -Wno-unused-function")
ENDIF ()
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${COMMON_CXX_FLAGS} ${DEBUG_FLAGS}") SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${COMMON_CXX_FLAGS} ${DEBUG_FLAGS}")
SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${COMMON_CXX_FLAGS} ${RELEASE_FLAGS}") SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${COMMON_CXX_FLAGS} ${RELEASE_FLAGS}")
......
...@@ -64,6 +64,10 @@ void printHelp() { ...@@ -64,6 +64,10 @@ void printHelp() {
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }
char DARWINCLIENT_VERSION[] = "Welcome to the TDengine shell from %s, Client Version:%s\n"
"Copyright (c) 2020 by TAOS Data, Inc. All rights reserved.\n\n";
char g_password[MAX_PASSWORD_SIZE];
void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) { void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) {
wordexp_t full_path; wordexp_t full_path;
for (int i = 1; i < argc; i++) { for (int i = 1; i < argc; i++) {
...@@ -77,10 +81,21 @@ void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) { ...@@ -77,10 +81,21 @@ 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; strcpy(tsOsName, "Darwin");
printf(DARWINCLIENT_VERSION, tsOsName, taos_get_client_info());
if (strlen(argv[i]) == 2) {
printf("Enter password: ");
if (scanf("%s", g_password) > 1) {
fprintf(stderr, "password read error\n");
}
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) {
if (i < argc - 1) { if (i < argc - 1) {
arguments->port = atoi(argv[++i]); arguments->port = atoi(argv[++i]);
...@@ -98,7 +113,7 @@ void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) { ...@@ -98,7 +113,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) {
if (strlen(argv[++i]) >= TSDB_FILENAME_LEN) { if (strlen(argv[++i]) >= TSDB_FILENAME_LEN) {
fprintf(stderr, "config file path: %s overflow max len %d\n", argv[i], TSDB_FILENAME_LEN - 1); fprintf(stderr, "config file path: %s overflow max len %d\n", argv[i], TSDB_FILENAME_LEN - 1);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
......
...@@ -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");
printf(CLIENT_VERSION, tsOsName, taos_get_client_info()); if (!_args->is_use_passwd) {
#ifdef TD_WINDOWS
strcpy(tsOsName, "Windows");
#elif defined(TD_DARWIN)
strcpy(tsOsName, "Darwin");
#endif
printf(CLIENT_VERSION, tsOsName, taos_get_client_info());
}
fflush(stdout); fflush(stdout);
// set options before initializing // set options before initializing
...@@ -73,9 +81,7 @@ TAOS *shellInit(SShellArguments *_args) { ...@@ -73,9 +81,7 @@ TAOS *shellInit(SShellArguments *_args) {
taos_options(TSDB_OPTION_TIMEZONE, _args->timezone); taos_options(TSDB_OPTION_TIMEZONE, _args->timezone);
} }
if (_args->is_use_passwd) { if (!_args->is_use_passwd) {
if (_args->password == NULL) _args->password = getpass("Enter password: ");
} else {
_args->password = TSDB_DEFAULT_PASS; _args->password = TSDB_DEFAULT_PASS;
} }
...@@ -169,7 +175,7 @@ static int32_t shellRunSingleCommand(TAOS *con, char *command) { ...@@ -169,7 +175,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");
...@@ -181,7 +187,7 @@ static int32_t shellRunSingleCommand(TAOS *con, char *command) { ...@@ -181,7 +187,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, " ;");
...@@ -246,7 +252,7 @@ int32_t shellRunCommand(TAOS* con, char* command) { ...@@ -246,7 +252,7 @@ int32_t shellRunCommand(TAOS* con, char* command) {
esc = false; esc = false;
continue; continue;
} }
if (c == '\\') { if (c == '\\') {
esc = true; esc = true;
continue; continue;
...@@ -335,8 +341,8 @@ void shellRunCommandOnServer(TAOS *con, char command[]) { ...@@ -335,8 +341,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);
...@@ -529,7 +535,7 @@ static int dumpResultToFile(const char* fname, TAOS_RES* tres) { ...@@ -529,7 +535,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);
...@@ -715,7 +721,7 @@ static int verticalPrintResult(TAOS_RES* tres) { ...@@ -715,7 +721,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);
...@@ -850,7 +856,7 @@ static int horizontalPrintResult(TAOS_RES* tres) { ...@@ -850,7 +856,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) {
...@@ -866,7 +872,7 @@ static int horizontalPrintResult(TAOS_RES* tres) { ...@@ -866,7 +872,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);
...@@ -908,7 +914,7 @@ void read_history() { ...@@ -908,7 +914,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;
} }
...@@ -933,9 +939,9 @@ void write_history() { ...@@ -933,9 +939,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;
} }
...@@ -981,13 +987,13 @@ void source_file(TAOS *con, char *fptr) { ...@@ -981,13 +987,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);
......
...@@ -34,7 +34,7 @@ static char doc[] = ""; ...@@ -34,7 +34,7 @@ static char doc[] = "";
static char args_doc[] = ""; static char args_doc[] = "";
static struct argp_option options[] = { static struct argp_option options[] = {
{"host", 'h', "HOST", 0, "TDengine server FQDN to connect. The default host is localhost."}, {"host", 'h', "HOST", 0, "TDengine server FQDN to connect. The default host is localhost."},
{"password", 'p', "PASSWORD", OPTION_ARG_OPTIONAL, "The password to use when connecting to the server."}, {"password", 'p', 0, 0, "The password to use when connecting to the server."},
{"port", 'P', "PORT", 0, "The TCP/IP port number to use for the connection."}, {"port", 'P', "PORT", 0, "The TCP/IP port number to use for the connection."},
{"user", 'u', "USER", 0, "The user name to use when connecting to the server."}, {"user", 'u', "USER", 0, "The user name to use when connecting to the server."},
{"auth", 'A', "Auth", 0, "The auth string to use when connecting to the server."}, {"auth", 'A', "Auth", 0, "The auth string to use when connecting to the server."},
...@@ -63,8 +63,6 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) { ...@@ -63,8 +63,6 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) {
arguments->host = arg; arguments->host = arg;
break; break;
case 'p': case 'p':
arguments->is_use_passwd = true;
if (arg) arguments->password = arg;
break; break;
case 'P': case 'P':
if (arg) { if (arg) {
...@@ -160,12 +158,41 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) { ...@@ -160,12 +158,41 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) {
/* Our argp parser. */ /* Our argp parser. */
static struct argp argp = {options, parse_opt, args_doc, doc}; static struct argp argp = {options, parse_opt, args_doc, doc};
char LINUXCLIENT_VERSION[] = "Welcome to the TDengine shell from %s, Client Version:%s\n"
"Copyright (c) 2020 by TAOS Data, Inc. All rights reserved.\n\n";
char g_password[MAX_PASSWORD_SIZE];
static void parse_password(
int argc, char *argv[], SShellArguments *arguments) {
for (int i = 1; i < argc; i++) {
if (strncmp(argv[i], "-p", 2) == 0) {
strcpy(tsOsName, "Linux");
printf(LINUXCLIENT_VERSION, tsOsName, taos_get_client_info());
if (strlen(argv[i]) == 2) {
printf("Enter password: ");
if (scanf("%20s", g_password) > 1) {
fprintf(stderr, "password reading error\n");
}
getchar();
} else {
tstrncpy(g_password, (char *)(argv[i] + 2), MAX_PASSWORD_SIZE);
}
arguments->password = g_password;
arguments->is_use_passwd = true;
}
}
}
void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) { void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) {
static char verType[32] = {0}; static char verType[32] = {0};
sprintf(verType, "version: %s\n", version); sprintf(verType, "version: %s\n", version);
argp_program_version = verType; argp_program_version = verType;
if (argc > 1) {
parse_password(argc, argv, arguments);
}
argp_parse(&argp, argc, argv, 0, 0, arguments); argp_parse(&argp, argc, argv, 0, 0, arguments);
if (arguments->abort) { if (arguments->abort) {
#ifndef _ALPINE #ifndef _ALPINE
......
...@@ -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,20 @@ void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) { ...@@ -73,11 +78,20 @@ 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: ");
if (scanf("%s", g_password) > 1) {
fprintf(stderr, "password read error!\n");
}
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 +118,7 @@ void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) { ...@@ -104,7 +118,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 +279,7 @@ void *shellLoopQuery(void *arg) { ...@@ -265,7 +279,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 +288,7 @@ void *shellLoopQuery(void *arg) { ...@@ -274,7 +288,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
...@@ -867,7 +867,9 @@ static void parse_args(int argc, char *argv[], SArguments *arguments) { ...@@ -867,7 +867,9 @@ static void parse_args(int argc, char *argv[], SArguments *arguments) {
} else if (strncmp(argv[i], "-p", 2) == 0) { } else if (strncmp(argv[i], "-p", 2) == 0) {
if (strlen(argv[i]) == 2) { if (strlen(argv[i]) == 2) {
printf("Enter password:"); printf("Enter password:");
scanf("%s", arguments->password); if (scanf("%s", arguments->password) > 1) {
fprintf(stderr, "password read error!\n");
}
} else { } else {
tstrncpy(arguments->password, (char *)(argv[i] + 2), MAX_PASSWORD_SIZE); tstrncpy(arguments->password, (char *)(argv[i] + 2), MAX_PASSWORD_SIZE);
} }
......
...@@ -206,9 +206,9 @@ static struct argp_option options[] = { ...@@ -206,9 +206,9 @@ static struct argp_option options[] = {
{"host", 'h', "HOST", 0, "Server host dumping data from. Default is localhost.", 0}, {"host", 'h', "HOST", 0, "Server host dumping data from. Default is localhost.", 0},
{"user", 'u', "USER", 0, "User name used to connect to server. Default is root.", 0}, {"user", 'u', "USER", 0, "User name used to connect to server. Default is root.", 0},
#ifdef _TD_POWER_ #ifdef _TD_POWER_
{"password", 'p', "PASSWORD", 0, "User password to connect to server. Default is powerdb.", 0}, {"password", 'p', 0, 0, "User password to connect to server. Default is powerdb.", 0},
#else #else
{"password", 'p', "PASSWORD", 0, "User password to connect to server. Default is taosdata.", 0}, {"password", 'p', 0, 0, "User password to connect to server. Default is taosdata.", 0},
#endif #endif
{"port", 'P', "PORT", 0, "Port to connect", 0}, {"port", 'P', "PORT", 0, "Port to connect", 0},
{"cversion", 'v', "CVERION", 0, "client version", 0}, {"cversion", 'v', "CVERION", 0, "client version", 0},
...@@ -248,12 +248,14 @@ static struct argp_option options[] = { ...@@ -248,12 +248,14 @@ static struct argp_option options[] = {
{0} {0}
}; };
#define MAX_PASSWORD_SIZE 20
/* Used by main to communicate with parse_opt. */ /* Used by main to communicate with parse_opt. */
typedef struct arguments { typedef struct arguments {
// connection option // connection option
char *host; char *host;
char *user; char *user;
char *password; char password[MAX_PASSWORD_SIZE];
uint16_t port; uint16_t port;
char cversion[12]; char cversion[12];
uint16_t mysqlFlag; uint16_t mysqlFlag;
...@@ -376,7 +378,6 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) { ...@@ -376,7 +378,6 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) {
g_args.user = arg; g_args.user = arg;
break; break;
case 'p': case 'p':
g_args.password = arg;
break; break;
case 'P': case 'P':
g_args.port = atoi(arg); g_args.port = atoi(arg);
...@@ -554,6 +555,23 @@ static void parse_precision_first( ...@@ -554,6 +555,23 @@ static void parse_precision_first(
} }
} }
static void parse_password(
int argc, char *argv[], SArguments *arguments) {
for (int i = 1; i < argc; i++) {
if (strncmp(argv[i], "-p", 2) == 0) {
if (strlen(argv[i]) == 2) {
printf("Enter password: ");
if(scanf("%20s", arguments->password) > 1) {
errorPrint("%s() LN%d, password read error!\n", __func__, __LINE__);
}
} else {
tstrncpy(arguments->password, (char *)(argv[i] + 2), MAX_PASSWORD_SIZE);
}
argv[i] = "";
}
}
}
static void parse_timestamp( static void parse_timestamp(
int argc, char *argv[], SArguments *arguments) { int argc, char *argv[], SArguments *arguments) {
for (int i = 1; i < argc; i++) { for (int i = 1; i < argc; i++) {
...@@ -616,9 +634,10 @@ int main(int argc, char *argv[]) { ...@@ -616,9 +634,10 @@ int main(int argc, char *argv[]) {
int ret = 0; int ret = 0;
/* Parse our arguments; every option seen by parse_opt will be /* Parse our arguments; every option seen by parse_opt will be
reflected in arguments. */ reflected in arguments. */
if (argc > 2) { if (argc > 1) {
parse_precision_first(argc, argv, &g_args); parse_precision_first(argc, argv, &g_args);
parse_timestamp(argc, argv, &g_args); parse_timestamp(argc, argv, &g_args);
parse_password(argc, argv, &g_args);
} }
argp_parse(&argp, argc, argv, 0, 0, &g_args); argp_parse(&argp, argc, argv, 0, 0, &g_args);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册