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

taosdata / TDengine / #3625

26 Feb 2025 10:19AM UTC coverage: 63.633% (+0.1%) from 63.485%
#3625

push

travis-ci

web-flow
Merge pull request #29914 from taosdata/feat/TS-5613-3.0

feat:[TS-5613]support bool in cast

148738 of 299799 branches covered (49.61%)

Branch coverage included in aggregate %.

233124 of 300297 relevant lines covered (77.63%)

17654074.26 hits per line

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

63.43
/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,800,976✔
24
  regex_t regex = {0};
1,800,976✔
25
  char    msgbuf[100] = {0};
1,800,976✔
26

27
  /* Compile regular expression */
28
  if (regcomp(&regex, reg, cflags) != 0) {
1,800,976!
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,800,976✔
35
  if (!reti) {
1,800,976✔
36
    regfree(&regex);
122,474✔
37
    return true;
122,474✔
38
  } else if (reti == REG_NOMATCH) {
1,678,502!
39
    regfree(&regex);
1,678,502✔
40
    return false;
1,678,502✔
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,163✔
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,163✔
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() {
2✔
81
  SConfig *pCfg = taosGetCfg();
2✔
82
  if (pCfg == NULL) {
2!
83
    printf("read global config failed!\r\n");
×
84
  } else {
85
    cfgDumpCfg(pCfg, 1, true);
2✔
86
  }
87
  fflush(stdout);
2✔
88
}
2✔
89

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

93
  do {
×
94
    char details[1024] = {0};
5✔
95
    code = taos_check_server_status(shell.args.host, shell.args.port, details, 1024);
5✔
96
    switch (code) {
5!
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:
4✔
104
        printf("2: service ok\r\n");
4✔
105
        break;
4✔
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) {
5!
114
      printf("%s\r\n\r\n", details);
×
115
    }
116
    fflush(stdout);
5✔
117
    if (code == TSDB_SRV_STATUS_NETWORK_OK && shell.args.is_startup) {
5!
118
      taosMsleep(1000);
×
119
    } else {
120
      break;
121
    }
122
  } while (1);
123
}
5✔
124
#ifdef WEBSOCKET
125
char dsn[1024] = "ws://localhost:6041";
126
void shellCheckConnectMode() {
1,127✔
127
        if (shell.args.dsn) {
1,127✔
128
                shell.args.cloud = true;
10✔
129
                shell.args.restful = false;
10✔
130
                return;
10✔
131
        }
132
        if (shell.args.cloud) {
1,117✔
133
                shell.args.dsn = getenv("TDENGINE_CLOUD_DSN");
286✔
134
                if (shell.args.dsn && strlen(shell.args.dsn) > 4) {
286!
135
                        shell.args.cloud = true;
×
136
      shell.args.local = false;
×
137
                        shell.args.restful = false;
×
138
                        return;
×
139
                }
140

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

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

164
}
165
#endif
166

167
void shellExit() {
5✔
168
  if (shell.conn != NULL) {
5!
169
    taos_close(shell.conn);
5✔
170
    shell.conn = NULL;
5✔
171
  }
172
  shell.exit = true;
5✔
173
  taos_cleanup();
5✔
174
}
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