tutil.h 2.7 KB
Newer Older
H
hzcheng 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*
 * 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/>.
 */

16 17
#ifndef _TD_UTIL_UTIL_H
#define _TD_UTIL_UTIL_H
H
hzcheng 已提交
18 19 20 21 22

#ifdef __cplusplus
extern "C" {
#endif

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

int32_t strdequote(char *src);
S
Shengliang Guan 已提交
29
int32_t strndequote(char *dst, const char *z, int32_t len);
D
dapan1121 已提交
30
int32_t strRmquote(char *z, int32_t len);
S
Shengliang Guan 已提交
31
size_t  strtrim(char *src);
X
Xiaoyu Wang 已提交
32
char   *strnchr(const char *haystack, char needle, int32_t len, bool skipquote);
S
Shengliang Guan 已提交
33 34 35 36
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);
char   *strntolower_s(char *dst, const char *src, int32_t n);
H
hzcheng 已提交
37
int64_t strnatoi(char *num, int32_t len);
S
Shengliang Guan 已提交
38 39
char   *strbetween(char *string, char *begin, char *end);
char   *paGetToken(char *src, char **token, int32_t *tokenLen);
H
hzcheng 已提交
40 41 42 43

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

S
Shengliang Guan 已提交
44
char    *taosIpStr(uint32_t ipInt);
S
Shengliang Guan 已提交
45
uint32_t ip2uint(const char *const ip_addr);
S
Shengliang Guan 已提交
46 47
void     taosIp2String(uint32_t ip, char *str);
void     taosIpPort2String(uint32_t ip, uint16_t port, char *str);
S
slguan 已提交
48

49
static FORCE_INLINE void taosEncryptPass(uint8_t *inBuf, size_t inLen, char *target) {
dengyihao's avatar
dengyihao 已提交
50 51 52 53
  T_MD5_CTX context;
  tMD5Init(&context);
  tMD5Update(&context, inBuf, (unsigned int)inLen);
  tMD5Final(&context);
54 55 56 57
  memcpy(target, context.digest, tListLen(context.digest));
}

static FORCE_INLINE void taosEncryptPass_c(uint8_t *inBuf, size_t len, char *target) {
H
Haojun Liao 已提交
58 59 60 61
  T_MD5_CTX context;
  tMD5Init(&context);
  tMD5Update(&context, inBuf, (unsigned int)len);
  tMD5Final(&context);
62

63
  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],
64 65 66
          context.digest[3], context.digest[4], context.digest[5], context.digest[6], context.digest[7],
          context.digest[8], context.digest[9], context.digest[10], context.digest[11], context.digest[12],
          context.digest[13], context.digest[14], context.digest[15]);
67 68
}

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

S
Shengliang Guan 已提交
73
#endif /*_TD_UTIL_UTIL_H*/