tutil.h 2.4 KB
Newer Older
H
hzcheng 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/*
 * 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 GNU Affero General Public License, version 3
 * or later ("AGPL"), 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.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef TDENGINE_TUTIL_H
#define TDENGINE_TUTIL_H

#ifdef __cplusplus
extern "C" {
#endif

S
slguan 已提交
23 24
#include "os.h"
#include "tmd5.h"
H
hzcheng 已提交
25
#include "tcrc32c.h"
S
slguan 已提交
26
#include "taosdef.h"
H
hzcheng 已提交
27 28

int32_t strdequote(char *src);
D
dapan1121 已提交
29
int32_t strRmquote(char *z, int32_t len);
W
wpan 已提交
30
int32_t strRmquoteEscape(char *z, int32_t len);
S
Shengliang Guan 已提交
31
size_t  strtrim(char *src);
D
dapan1121 已提交
32
char *  tstrstr(char *src, char *dst, bool ignoreInEsc);
S
Shengliang Guan 已提交
33 34 35 36
char *  strnchr(char *haystack, char needle, int32_t len, bool skipquote);
char ** strsplit(char *src, const char *delim, int32_t *num);
char *  strtolower(char *dst, const char *src);
char *  strntolower(char *dst, const char *src, int32_t n);
37
char *  strntolower_s(char *dst, const char *src, int32_t n);
H
hzcheng 已提交
38
int64_t strnatoi(char *num, int32_t len);
S
Shengliang Guan 已提交
39 40
char *  strbetween(char *string, char *begin, char *end);
char *  paGetToken(char *src, char **token, int32_t *tokenLen);
H
hzcheng 已提交
41 42 43 44

int32_t taosByteArrayToHexStr(char bytes[], int32_t len, char hexstr[]);
int32_t taosHexStrToByteArray(char hexstr[], char bytes[]);

S
slguan 已提交
45
bool taosGetVersionNumber(char *versionStr, int *versionNubmer);
S
Shengliang Guan 已提交
46 47 48 49
int  taosCheckVersion(char *input_client_version, char *input_server_version, int compared_segments);

char *   taosIpStr(uint32_t ipInt);
uint32_t ip2uint(const char *const ip_addr);
50
void jsonKeyMd5(void *pMsg, int msgLen, void *pKey);
51
bool isValidateTag(char *input);
S
slguan 已提交
52

S
Shengliang Guan 已提交
53
static FORCE_INLINE void taosEncryptPass(uint8_t *inBuf, size_t inLen, char *target) {
54 55
  MD5_CTX context;
  MD5Init(&context);
S
Shengliang Guan 已提交
56
  MD5Update(&context, inBuf, (unsigned int)inLen);
57 58 59 60
  MD5Final(&context);
  memcpy(target, context.digest, TSDB_KEY_LEN);
}

61 62 63 64 65 66 67
//
// TSKEY util
//

// if time area(s1,e1) intersect with time area(s2,e2) then return true else return false
bool timeIntersect(TSKEY s1, TSKEY e1, TSKEY s2, TSKEY e2);

H
hzcheng 已提交
68 69 70 71
#ifdef __cplusplus
}
#endif

S
slguan 已提交
72
#endif  // TDENGINE_TUTIL_H