• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

taosdata / TDengine / #3616

19 Feb 2025 11:22AM UTC coverage: 63.315% (+0.4%) from 62.953%
#3616

push

travis-ci

web-flow
Merge pull request #29823 from taosdata/feat/TS-5928

fix:[TS-5928]add consumer parameters

148228 of 300186 branches covered (49.38%)

Branch coverage included in aggregate %.

232358 of 300909 relevant lines covered (77.22%)

17990742.15 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

52.17
/tools/shell/src/shellUtil.c
1
/*
2
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
3
 *
4
 * This program is free software: you can use, redistribute, and/or modify
5
 * it under the terms of the GNU Affero General Public License, version 3
6
 * or later ("AGPL"), as published by the Free Software Foundation.
7
 *
8
 * This program is distributed in the hope that it will be useful, but WITHOUT
9
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
 * FITNESS FOR A PARTICULAR PURPOSE.
11
 *
12
 * You should have received a copy of the GNU Affero General Public License
13
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14
 */
15

16
#define _BSD_SOURCE
17
#define _GNU_SOURCE
18
#define _XOPEN_SOURCE
19
#define _DEFAULT_SOURCE
20

21
#include "shellInt.h"
22

23
bool shellRegexMatch(const char *s, const char *reg, int32_t cflags) {
1,815,034✔
24
  regex_t regex = {0};
1,815,034✔
25
  char    msgbuf[100] = {0};
1,815,034✔
26

27
  /* Compile regular expression */
28
  if (regcomp(&regex, reg, cflags) != 0) {
1,815,034!
29
    fprintf(stderr, "Fail to compile regex");
×
30
    shellExit();
×
31
  }
32

33
  /* Execute regular expression */
34
  int32_t reti = regexec(&regex, s, 0, NULL, 0);
1,815,034✔
35
  if (!reti) {
1,815,034✔
36
    regfree(&regex);
122,432✔
37
    return true;
122,432✔
38
  } else if (reti == REG_NOMATCH) {
1,692,602!
39
    regfree(&regex);
1,692,602✔
40
    return false;
1,692,602✔
41
  } else {
42
    regerror(reti, &regex, msgbuf, sizeof(msgbuf));
×
43
    fprintf(stderr, "Regex match failed: %s\r\n", msgbuf);
×
44
    regfree(&regex);
×
45
    shellExit();
×
46
  }
47

48
  return false;
×
49
}
50

51
int32_t shellCheckIntSize() {
1,134✔
52
  if (sizeof(int8_t) != 1) {
53
    printf("int8 size is %d(!= 1)", (int)sizeof(int8_t));
54
    return -1;
55
  }
56
  if (sizeof(int16_t) != 2) {
57
    printf("int16 size is %d(!= 2)", (int)sizeof(int16_t));
58
    return -1;
59
  }
60
  if (sizeof(int32_t) != 4) {
61
    printf("int32 size is %d(!= 4)", (int)sizeof(int32_t));
62
    return -1;
63
  }
64
  if (sizeof(int64_t) != 8) {
65
    printf("int64 size is %d(!= 8)", (int)sizeof(int64_t));
66
    return -1;
67
  }
68
  return 0;
1,134✔
69
}
70

71
void shellPrintVersion() { printf("%s\r\n", shell.info.programVersion); }
×
72

73
void shellGenerateAuth() {
1✔
74
  char secretEncrypt[TSDB_PASSWORD_LEN + 1] = {0};
1✔
75
  taosEncryptPass_c((uint8_t *)shell.args.password, strlen(shell.args.password), secretEncrypt);
1✔
76
  printf("%s\r\n", secretEncrypt);
1✔
77
  fflush(stdout);
1✔
78
}
1✔
79

80
void shellDumpConfig() {
1✔
81
  SConfig *pCfg = taosGetCfg();
1✔
82
  if (pCfg == NULL) {
1!
83
    printf("read global config failed!\r\n");
×
84
  } else {
85
    cfgDumpCfg(pCfg, 1, true);
1✔
86
  }
87
  fflush(stdout);
1✔
88
}
1✔
89

90
void shellCheckServerStatus() {
4✔
91
  TSDB_SERVER_STATUS code;
92

93
  do {
×
94
    char details[1024] = {0};
4✔
95
    code = taos_check_server_status(shell.args.host, shell.args.port, details, 1024);
4✔
96
    switch (code) {
4!
97
      case TSDB_SRV_STATUS_UNAVAILABLE:
1✔
98
        printf("0: unavailable\r\n");
1✔
99
        break;
1✔
100
      case TSDB_SRV_STATUS_NETWORK_OK:
×
101
        printf("1: network ok\r\n");
×
102
        break;
×
103
      case TSDB_SRV_STATUS_SERVICE_OK:
3✔
104
        printf("2: service ok\r\n");
3✔
105
        break;
3✔
106
      case TSDB_SRV_STATUS_SERVICE_DEGRADED:
×
107
        printf("3: service degraded\r\n");
×
108
        break;
×
109
      case TSDB_SRV_STATUS_EXTING:
×
110
        printf("4: exiting\r\n");
×
111
        break;
×
112
    }
113
    if (strlen(details) != 0) {
4!
114
      printf("%s\r\n\r\n", details);
×
115
    }
116
    fflush(stdout);
4✔
117
    if (code == TSDB_SRV_STATUS_NETWORK_OK && shell.args.is_startup) {
4!
118
      taosMsleep(1000);
×
119
    } else {
120
      break;
121
    }
122
  } while (1);
123
}
4✔
124
#ifdef WEBSOCKET
125
void shellCheckConnectMode() {
1,111✔
126
        if (shell.args.dsn) {
1,111!
127
                shell.args.cloud = true;
×
128
                shell.args.restful = false;
×
129
                return;
×
130
        }
131
        if (shell.args.cloud) {
1,111✔
132
                shell.args.dsn = getenv("TDENGINE_CLOUD_DSN");
249✔
133
                if (shell.args.dsn && strlen(shell.args.dsn) > 4) {
249!
134
                        shell.args.cloud = true;
×
135
      shell.args.local = false;
×
136
                        shell.args.restful = false;
×
137
                        return;
×
138
                }
139

140
    shell.args.dsn = getenv("TDENGINE_DSN");
249✔
141
                if (shell.args.dsn && strlen(shell.args.dsn) > 4) {
249!
142
                        shell.args.cloud = true;
×
143
      shell.args.local = true;
×
144
                        shell.args.restful = false;
×
145
                        return;
×
146
                }
147

148
                if (shell.args.restful) {
249!
149
                        if (!shell.args.host) {
×
150
                                shell.args.host = "localhost";
×
151
                        }
152
                        if (!shell.args.port) {
×
153
                                shell.args.port = 6041;
×
154
                        }
155
                        shell.args.dsn = taosMemoryCalloc(1, 1024);
×
156
                        snprintf(shell.args.dsn, 1024, "ws://%s:%d",
×
157
                                        shell.args.host, shell.args.port);
158
                }
159
                shell.args.cloud = false;
249✔
160
                return;
249✔
161
        }
162
}
163
#endif
164

165
void shellExit() {
5✔
166
  if (shell.conn != NULL) {
5!
167
    taos_close(shell.conn);
5✔
168
    shell.conn = NULL;
5✔
169
  }
170
  shell.exit = true;
5✔
171
  taos_cleanup();
5✔
172
}
5✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc