mirror of
https://github.com/taosdata/TDengine
synced 2026-05-24 10:09:01 +00:00
* fix: add show connMode string * fix: add stdbool.h to pub.h * fix: remove trash file army/output.txt * fix: caseBase.py modify syntax error * fix: restore -R option for taosdump * fix: taosdumpCommandline.py case * fix: native stmt write normal table failed * fix: taosdumpCommandline.py case passed * fix: restore test.py from main branch * fix: taosCli.py check default conn mode * fix: commandline-sml.py case pass * fix: websiteCase.py case passed * fix: connMode.py case * fix: modify default port is 0 * fix: taos_options with config dir not work * fix: websocket.py delete -D timeout options * fix: default_tmq_json.py context move to default_json.py, so delete * fix python kafka bug * chore: improve taos_init in wrapper * chore: add installation path preparation in build workflow * fix connMode bug * fix: fix tmq conf/consumer new error in wrapperFunc.c * fix: correct the spelling toss -> taosGetInstall... * chore: fix compile error in wrapperFunc.c * fix: createConnect fix memory leak * fix: tsim forbid CHECK ODR * modify userOperTest uuse static lib * reverse userOperTest use static lib --------- Co-authored-by: Alex Duan <417921451@qq.com> Co-authored-by: taos-support <it@taosdata.com> Co-authored-by: “chris <“zk662144@163.com”> Co-authored-by: t_max <1172915550@qq.com> Co-authored-by: sheyanjie-qq <249478495@qq.com>
148 lines
No EOL
3.8 KiB
C
148 lines
No EOL
3.8 KiB
C
/*
|
|
* 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 MIT license 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.
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
#include <taos.h>
|
|
#include "../inc/pub.h"
|
|
|
|
|
|
char* strToLowerCopy(const char *str) {
|
|
if (str == NULL) {
|
|
return NULL;
|
|
}
|
|
size_t len = strlen(str);
|
|
char *result = (char*)malloc(len + 1);
|
|
if (result == NULL) {
|
|
return NULL;
|
|
}
|
|
for (size_t i = 0; i < len; i++) {
|
|
result[i] = tolower((unsigned char)str[i]);
|
|
}
|
|
result[len] = '\0';
|
|
return result;
|
|
}
|
|
|
|
int32_t parseDsn(char* dsn, char **host, char **port, char **user, char **pwd, char *error) {
|
|
// dsn format:
|
|
// local http://127.0.0.1:6041
|
|
// cloud https://gw.cloud.taosdata.com?token=617ffdf...
|
|
// https://gw.cloud.taosdata.com:433?token=617ffdf...
|
|
|
|
// find "://"
|
|
char *p1 = strstr(dsn, "://");
|
|
if (p1 == NULL) {
|
|
sprintf(error, "%s", "dsn invalid, not found \"://\" ");
|
|
return -1;
|
|
}
|
|
*host = p1 + 3; // host
|
|
char *p = *host;
|
|
|
|
// find ":" - option
|
|
char *p2 = strstr(p, ":");
|
|
if (p2) {
|
|
p = p2 + 1;
|
|
*port = p2 + 1; // port
|
|
*p2 = 0;
|
|
}
|
|
|
|
// find "?"
|
|
char *p3 = strstr(p, "?");
|
|
if (p3) {
|
|
p = p3 + 1;
|
|
*user = p3 + 1;
|
|
*p3 = 0;
|
|
} else {
|
|
return 0;
|
|
}
|
|
|
|
// find "="
|
|
char *p4 = strstr(p, "=");
|
|
if (p4) {
|
|
*p4 = 0;
|
|
*pwd = p4 + 1;
|
|
} else {
|
|
sprintf(error, "%s", "dsn invalid, found \"?\" but not found \"=\" ");
|
|
return -1;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
// get comn mode, if invalid exit app
|
|
int8_t getConnMode(char *arg) {
|
|
// compare
|
|
if (strcasecmp(arg, STR_NATIVE) == 0 || strcasecmp(arg, "0") == 0) {
|
|
return CONN_MODE_NATIVE;
|
|
} else if (strcasecmp(arg, STR_WEBSOCKET) == 0 || strcasecmp(arg, "1") == 0) {
|
|
return CONN_MODE_WEBSOCKET;
|
|
} else {
|
|
fprintf(stderr, "invalid input %s for option -Z, only support: %s or %s\r\n", arg, STR_NATIVE, STR_WEBSOCKET);
|
|
exit(-1);
|
|
}
|
|
}
|
|
|
|
// set conn mode
|
|
int32_t setConnMode(int8_t connMode, char *dsn, bool show) {
|
|
// check default
|
|
if (connMode == CONN_MODE_INVALID) {
|
|
if (dsn && dsn[0] != 0) {
|
|
connMode = CONN_MODE_WEBSOCKET;
|
|
} else {
|
|
// default
|
|
connMode = CONN_MODE_DEFAULT;
|
|
}
|
|
}
|
|
|
|
// set conn mode
|
|
char * strMode = connMode == CONN_MODE_NATIVE ? STR_NATIVE : STR_WEBSOCKET;
|
|
int32_t code = taos_options(TSDB_OPTION_DRIVER, strMode);
|
|
if (code != 0) {
|
|
fprintf(stderr, "failed to load driver. since %s [0x%08X]\r\n", taos_errstr(NULL), taos_errno(NULL));
|
|
return code;
|
|
}
|
|
|
|
if (show) {
|
|
fprintf(stdout, "\nConnect mode is : %s\n\n", strMode);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
// default mode
|
|
int8_t workingMode(int8_t connMode, char *dsn) {
|
|
int8_t mode = connMode;
|
|
if (connMode == CONN_MODE_INVALID) {
|
|
// no input from command line or config
|
|
if (dsn && dsn[0] != 0) {
|
|
mode = CONN_MODE_WEBSOCKET;
|
|
} else {
|
|
// default
|
|
mode = CONN_MODE_DEFAULT;
|
|
}
|
|
}
|
|
return mode;
|
|
}
|
|
|
|
// get default port
|
|
uint16_t defaultPort(int8_t connMode, char *dsn) {
|
|
// port 0 is default
|
|
return 0;
|
|
|
|
/*
|
|
// consistent with setConnMode
|
|
int8_t mode = workingMode(connMode, dsn);
|
|
|
|
// default port
|
|
return mode == CONN_MODE_NATIVE ? DEFAULT_PORT_NATIVE : DEFAULT_PORT_WS_LOCAL;
|
|
*/
|
|
}
|
|
|