This commit is contained in:
Shengliang Guan 2022-02-28 14:29:54 +08:00
parent 1398172370
commit 869d3c1742
2 changed files with 56 additions and 55 deletions

View File

@ -13,18 +13,18 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _TD_UTIL_UTIL_H
#define _TD_UTIL_UTIL_H
#ifdef __cplusplus
extern "C" {
#endif
#ifndef _TD_UTIL_UTIL_H_
#define _TD_UTIL_UTIL_H_
#include "os.h"
#include "tcrc32c.h"
#include "tdef.h"
#include "tmd5.h"
#ifdef __cplusplus
extern "C" {
#endif
int32_t strdequote(char *src);
int32_t strndequote(char *dst, const 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
tMD5Update(&context, inBuf, (unsigned int)len);
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],
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]);
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], 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]);
}
#ifdef __cplusplus
}
#endif
#endif /*_TD_UTIL_UTIL_H*/
#endif /*_TD_UTIL_UTIL_H_*/

View File

@ -13,8 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "os.h"
#include "tdef.h"
#define _DEFAULT_SOURCE
#include "tutil.h"
int32_t strdequote(char *z) {
if (z == NULL) {
@ -47,7 +47,7 @@ int32_t strdequote(char *z) {
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: \\, \', \"
char delim = z[0];
if (delim != '\'' && delim != '\"') {
@ -59,7 +59,7 @@ int32_t strRmquote(char *z, int32_t len){
for (uint32_t k = 1; k < len - 1; ++k) {
if (z[k] == '\\' || (z[k] == delim && z[k + 1] == delim)) {
if (z[k] == '\\' && z[k + 1] == '_') {
//match '_' self
// match '_' self
} else {
z[j] = z[k + 1];
cnt++;
@ -78,7 +78,7 @@ int32_t strRmquote(char *z, int32_t len){
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);
if (z == NULL || len == 0) {
return 0;
@ -90,7 +90,7 @@ int32_t strndequote(char *dst, const char* z, int32_t len) {
while (z[i] != 0) {
if (z[i] == quote) {
if (z[i + 1] == quote) {
dst[j++] = (char) quote;
dst[j++] = (char)quote;
i++;
} else {
dst[j++] = 0;
@ -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) {
for (int32_t i = 0; i < len; ++i) {
// skip the needle in quote, jump to the end of quoted string
if (skipquote && (haystack[i] == '\'' || haystack[i] == '"')) {
char quote = haystack[i++];
while(i < len && haystack[i++] != quote);
while (i < len && haystack[i++] != quote)
;
if (i >= len) {
return NULL;
}
@ -186,7 +186,7 @@ char *strnchr(const char *haystack, char needle, int32_t len, bool skipquote) {
return NULL;
}
char* strtolower(char *dst, const char *src) {
char *strtolower(char *dst, const char *src) {
int32_t esc = 0;
char quote = 0, *p = dst, c;
@ -213,7 +213,7 @@ char* strtolower(char *dst, const char *src) {
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;
char quote = 0, *p = dst, c;
@ -243,7 +243,7 @@ char* strntolower(char *dst, const char *src, int32_t n) {
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;
assert(dst != NULL);
@ -405,7 +405,8 @@ char *taosIpStr(uint32_t ipInt) {
static int32_t ipStrIndex = 0;
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));
return ipStr;
}