Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
869d3c17
TDengine
项目概览
taosdata
/
TDengine
大约 2 年 前同步成功
通知
1192
Star
22018
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
869d3c17
编写于
2月 28, 2022
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
util
上级
13981723
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
56 addition
and
55 deletion
+56
-55
include/util/tutil.h
include/util/tutil.h
+11
-11
source/util/src/tutil.c
source/util/src/tutil.c
+45
-44
未找到文件。
include/util/tutil.h
浏览文件 @
869d3c17
...
@@ -13,18 +13,18 @@
...
@@ -13,18 +13,18 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
*/
#ifndef _TD_UTIL_UTIL_H
#ifndef _TD_UTIL_UTIL_H_
#define _TD_UTIL_UTIL_H
#define _TD_UTIL_UTIL_H_
#ifdef __cplusplus
extern
"C"
{
#endif
#include "os.h"
#include "os.h"
#include "tcrc32c.h"
#include "tcrc32c.h"
#include "tdef.h"
#include "tdef.h"
#include "tmd5.h"
#include "tmd5.h"
#ifdef __cplusplus
extern
"C"
{
#endif
int32_t
strdequote
(
char
*
src
);
int32_t
strdequote
(
char
*
src
);
int32_t
strndequote
(
char
*
dst
,
const
char
*
z
,
int32_t
len
);
int32_t
strndequote
(
char
*
dst
,
const
char
*
z
,
int32_t
len
);
int32_t
strRmquote
(
char
*
z
,
int32_t
len
);
int32_t
strRmquote
(
char
*
z
,
int32_t
len
);
...
@@ -60,14 +60,14 @@ static FORCE_INLINE void taosEncryptPass_c(uint8_t *inBuf, size_t len, char *tar
...
@@ -60,14 +60,14 @@ static FORCE_INLINE void taosEncryptPass_c(uint8_t *inBuf, size_t len, char *tar
tMD5Update
(
&
context
,
inBuf
,
(
unsigned
int
)
len
);
tMD5Update
(
&
context
,
inBuf
,
(
unsigned
int
)
len
);
tMD5Final
(
&
context
);
tMD5Final
(
&
context
);
sprintf
(
target
,
"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x"
,
context
.
digest
[
0
],
context
.
digest
[
1
],
context
.
digest
[
2
],
sprintf
(
target
,
"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x"
,
context
.
digest
[
0
],
context
.
digest
[
3
],
context
.
digest
[
4
],
context
.
digest
[
5
],
context
.
digest
[
6
],
context
.
digest
[
7
],
context
.
digest
[
1
],
context
.
digest
[
2
],
context
.
digest
[
3
],
context
.
digest
[
4
],
context
.
digest
[
5
],
context
.
digest
[
8
],
context
.
digest
[
9
],
context
.
digest
[
10
],
context
.
digest
[
11
],
context
.
digest
[
12
],
context
.
digest
[
6
],
context
.
digest
[
7
],
context
.
digest
[
8
],
context
.
digest
[
9
],
context
.
digest
[
10
],
context
.
digest
[
13
],
context
.
digest
[
14
],
context
.
digest
[
15
]);
context
.
digest
[
1
1
],
context
.
digest
[
12
],
context
.
digest
[
1
3
],
context
.
digest
[
14
],
context
.
digest
[
15
]);
}
}
#ifdef __cplusplus
#ifdef __cplusplus
}
}
#endif
#endif
#endif
/*_TD_UTIL_UTIL_H*/
#endif
/*_TD_UTIL_UTIL_H
_
*/
source/util/src/tutil.c
浏览文件 @
869d3c17
...
@@ -13,8 +13,8 @@
...
@@ -13,8 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
*/
#
include "os.h"
#
define _DEFAULT_SOURCE
#include "t
def
.h"
#include "t
util
.h"
int32_t
strdequote
(
char
*
z
)
{
int32_t
strdequote
(
char
*
z
)
{
if
(
z
==
NULL
)
{
if
(
z
==
NULL
)
{
...
@@ -47,38 +47,38 @@ int32_t strdequote(char *z) {
...
@@ -47,38 +47,38 @@ int32_t strdequote(char *z) {
return
j
+
1
;
// only one quote, do nothing
return
j
+
1
;
// only one quote, do nothing
}
}
int32_t
strRmquote
(
char
*
z
,
int32_t
len
){
int32_t
strRmquote
(
char
*
z
,
int32_t
len
)
{
// delete escape character: \\, \', \"
// delete escape character: \\, \', \"
char
delim
=
z
[
0
];
char
delim
=
z
[
0
];
if
(
delim
!=
'\''
&&
delim
!=
'\"'
)
{
if
(
delim
!=
'\''
&&
delim
!=
'\"'
)
{
return
len
;
return
len
;
}
}
int32_t
cnt
=
0
;
int32_t
cnt
=
0
;
int32_t
j
=
0
;
int32_t
j
=
0
;
for
(
uint32_t
k
=
1
;
k
<
len
-
1
;
++
k
)
{
for
(
uint32_t
k
=
1
;
k
<
len
-
1
;
++
k
)
{
if
(
z
[
k
]
==
'\\'
||
(
z
[
k
]
==
delim
&&
z
[
k
+
1
]
==
delim
))
{
if
(
z
[
k
]
==
'\\'
||
(
z
[
k
]
==
delim
&&
z
[
k
+
1
]
==
delim
))
{
if
(
z
[
k
]
==
'\\'
&&
z
[
k
+
1
]
==
'_'
)
{
if
(
z
[
k
]
==
'\\'
&&
z
[
k
+
1
]
==
'_'
)
{
//match '_' self
// match '_' self
}
else
{
}
else
{
z
[
j
]
=
z
[
k
+
1
];
z
[
j
]
=
z
[
k
+
1
];
cnt
++
;
cnt
++
;
j
++
;
j
++
;
k
++
;
k
++
;
continue
;
continue
;
}
}
}
z
[
j
]
=
z
[
k
];
j
++
;
}
}
z
[
j
]
=
0
;
z
[
j
]
=
z
[
k
];
j
++
;
return
len
-
2
-
cnt
;
}
z
[
j
]
=
0
;
return
len
-
2
-
cnt
;
}
}
int32_t
strndequote
(
char
*
dst
,
const
char
*
z
,
int32_t
len
)
{
int32_t
strndequote
(
char
*
dst
,
const
char
*
z
,
int32_t
len
)
{
assert
(
dst
!=
NULL
);
assert
(
dst
!=
NULL
);
if
(
z
==
NULL
||
len
==
0
)
{
if
(
z
==
NULL
||
len
==
0
)
{
return
0
;
return
0
;
...
@@ -90,7 +90,7 @@ int32_t strndequote(char *dst, const char* z, int32_t len) {
...
@@ -90,7 +90,7 @@ int32_t strndequote(char *dst, const char* z, int32_t len) {
while
(
z
[
i
]
!=
0
)
{
while
(
z
[
i
]
!=
0
)
{
if
(
z
[
i
]
==
quote
)
{
if
(
z
[
i
]
==
quote
)
{
if
(
z
[
i
+
1
]
==
quote
)
{
if
(
z
[
i
+
1
]
==
quote
)
{
dst
[
j
++
]
=
(
char
)
quote
;
dst
[
j
++
]
=
(
char
)
quote
;
i
++
;
i
++
;
}
else
{
}
else
{
dst
[
j
++
]
=
0
;
dst
[
j
++
]
=
0
;
...
@@ -139,7 +139,7 @@ size_t strtrim(char *z) {
...
@@ -139,7 +139,7 @@ size_t strtrim(char *z) {
}
else
if
(
j
!=
i
)
{
}
else
if
(
j
!=
i
)
{
z
[
i
]
=
0
;
z
[
i
]
=
0
;
}
}
return
i
;
return
i
;
}
}
...
@@ -168,11 +168,11 @@ char **strsplit(char *z, const char *delim, int32_t *num) {
...
@@ -168,11 +168,11 @@ char **strsplit(char *z, const char *delim, int32_t *num) {
char
*
strnchr
(
const
char
*
haystack
,
char
needle
,
int32_t
len
,
bool
skipquote
)
{
char
*
strnchr
(
const
char
*
haystack
,
char
needle
,
int32_t
len
,
bool
skipquote
)
{
for
(
int32_t
i
=
0
;
i
<
len
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
len
;
++
i
)
{
// skip the needle in quote, jump to the end of quoted string
// skip the needle in quote, jump to the end of quoted string
if
(
skipquote
&&
(
haystack
[
i
]
==
'\''
||
haystack
[
i
]
==
'"'
))
{
if
(
skipquote
&&
(
haystack
[
i
]
==
'\''
||
haystack
[
i
]
==
'"'
))
{
char
quote
=
haystack
[
i
++
];
char
quote
=
haystack
[
i
++
];
while
(
i
<
len
&&
haystack
[
i
++
]
!=
quote
);
while
(
i
<
len
&&
haystack
[
i
++
]
!=
quote
)
;
if
(
i
>=
len
)
{
if
(
i
>=
len
)
{
return
NULL
;
return
NULL
;
}
}
...
@@ -186,9 +186,9 @@ char *strnchr(const char *haystack, char needle, int32_t len, bool skipquote) {
...
@@ -186,9 +186,9 @@ char *strnchr(const char *haystack, char needle, int32_t len, bool skipquote) {
return
NULL
;
return
NULL
;
}
}
char
*
strtolower
(
char
*
dst
,
const
char
*
src
)
{
char
*
strtolower
(
char
*
dst
,
const
char
*
src
)
{
int32_t
esc
=
0
;
int32_t
esc
=
0
;
char
quote
=
0
,
*
p
=
dst
,
c
;
char
quote
=
0
,
*
p
=
dst
,
c
;
assert
(
dst
!=
NULL
);
assert
(
dst
!=
NULL
);
...
@@ -213,9 +213,9 @@ char* strtolower(char *dst, const char *src) {
...
@@ -213,9 +213,9 @@ char* strtolower(char *dst, const char *src) {
return
dst
;
return
dst
;
}
}
char
*
strntolower
(
char
*
dst
,
const
char
*
src
,
int32_t
n
)
{
char
*
strntolower
(
char
*
dst
,
const
char
*
src
,
int32_t
n
)
{
int32_t
esc
=
0
;
int32_t
esc
=
0
;
char
quote
=
0
,
*
p
=
dst
,
c
;
char
quote
=
0
,
*
p
=
dst
,
c
;
assert
(
dst
!=
NULL
);
assert
(
dst
!=
NULL
);
if
(
n
==
0
)
{
if
(
n
==
0
)
{
...
@@ -243,7 +243,7 @@ char* strntolower(char *dst, const char *src, int32_t n) {
...
@@ -243,7 +243,7 @@ char* strntolower(char *dst, const char *src, int32_t n) {
return
dst
;
return
dst
;
}
}
char
*
strntolower_s
(
char
*
dst
,
const
char
*
src
,
int32_t
n
)
{
char
*
strntolower_s
(
char
*
dst
,
const
char
*
src
,
int32_t
n
)
{
char
*
p
=
dst
,
c
;
char
*
p
=
dst
,
c
;
assert
(
dst
!=
NULL
);
assert
(
dst
!=
NULL
);
...
@@ -265,7 +265,7 @@ char* strntolower_s(char *dst, const char *src, int32_t n) {
...
@@ -265,7 +265,7 @@ char* strntolower_s(char *dst, const char *src, int32_t n) {
char
*
paGetToken
(
char
*
string
,
char
**
token
,
int32_t
*
tokenLen
)
{
char
*
paGetToken
(
char
*
string
,
char
**
token
,
int32_t
*
tokenLen
)
{
char
quote
=
0
;
char
quote
=
0
;
while
(
*
string
!=
0
)
{
while
(
*
string
!=
0
)
{
if
(
*
string
==
' '
||
*
string
==
'\t'
)
{
if
(
*
string
==
' '
||
*
string
==
'\t'
)
{
++
string
;
++
string
;
...
@@ -346,8 +346,8 @@ char *strbetween(char *string, char *begin, char *end) {
...
@@ -346,8 +346,8 @@ char *strbetween(char *string, char *begin, char *end) {
char
*
result
=
NULL
;
char
*
result
=
NULL
;
char
*
_begin
=
strstr
(
string
,
begin
);
char
*
_begin
=
strstr
(
string
,
begin
);
if
(
_begin
!=
NULL
)
{
if
(
_begin
!=
NULL
)
{
char
*
_end
=
strstr
(
_begin
+
strlen
(
begin
),
end
);
char
*
_end
=
strstr
(
_begin
+
strlen
(
begin
),
end
);
int32_t
size
=
(
int32_t
)(
_end
-
_begin
);
int32_t
size
=
(
int32_t
)(
_end
-
_begin
);
if
(
_end
!=
NULL
&&
size
>
0
)
{
if
(
_end
!=
NULL
&&
size
>
0
)
{
result
=
(
char
*
)
calloc
(
1
,
size
);
result
=
(
char
*
)
calloc
(
1
,
size
);
memcpy
(
result
,
_begin
+
strlen
(
begin
),
size
-
+
strlen
(
begin
));
memcpy
(
result
,
_begin
+
strlen
(
begin
),
size
-
+
strlen
(
begin
));
...
@@ -401,11 +401,12 @@ int32_t taosHexStrToByteArray(char hexstr[], char bytes[]) {
...
@@ -401,11 +401,12 @@ int32_t taosHexStrToByteArray(char hexstr[], char bytes[]) {
}
}
char
*
taosIpStr
(
uint32_t
ipInt
)
{
char
*
taosIpStr
(
uint32_t
ipInt
)
{
static
char
ipStrArray
[
3
][
30
];
static
char
ipStrArray
[
3
][
30
];
static
int32_t
ipStrIndex
=
0
;
static
int32_t
ipStrIndex
=
0
;
char
*
ipStr
=
ipStrArray
[(
ipStrIndex
++
)
%
3
];
char
*
ipStr
=
ipStrArray
[(
ipStrIndex
++
)
%
3
];
//sprintf(ipStr, "0x%x:%u.%u.%u.%u", ipInt, ipInt & 0xFF, (ipInt >> 8) & 0xFF, (ipInt >> 16) & 0xFF, (uint8_t)(ipInt >> 24));
// sprintf(ipStr, "0x%x:%u.%u.%u.%u", ipInt, ipInt & 0xFF, (ipInt >> 8) & 0xFF, (ipInt >> 16) & 0xFF, (uint8_t)(ipInt
// >> 24));
sprintf
(
ipStr
,
"%u.%u.%u.%u"
,
ipInt
&
0xFF
,
(
ipInt
>>
8
)
&
0xFF
,
(
ipInt
>>
16
)
&
0xFF
,
(
uint8_t
)(
ipInt
>>
24
));
sprintf
(
ipStr
,
"%u.%u.%u.%u"
,
ipInt
&
0xFF
,
(
ipInt
>>
8
)
&
0xFF
,
(
ipInt
>>
16
)
&
0xFF
,
(
uint8_t
)(
ipInt
>>
24
));
return
ipStr
;
return
ipStr
;
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录