OCT 1. 更新格式化代码
This commit is contained in:
parent
f82cb95c05
commit
abd393322d
|
@ -2,6 +2,7 @@
|
||||||
Language: Cpp
|
Language: Cpp
|
||||||
AccessModifierOffset: -4
|
AccessModifierOffset: -4
|
||||||
InsertBraces: true
|
InsertBraces: true
|
||||||
|
AlignArrayOfStructures: Left
|
||||||
AlignAfterOpenBracket: Align
|
AlignAfterOpenBracket: Align
|
||||||
AlignConsecutiveMacros: Consecutive
|
AlignConsecutiveMacros: Consecutive
|
||||||
AlignConsecutiveAssignments: Consecutive
|
AlignConsecutiveAssignments: Consecutive
|
||||||
|
@ -26,8 +27,9 @@ AlwaysBreakBeforeMultilineStrings: true
|
||||||
AlwaysBreakTemplateDeclarations: MultiLine
|
AlwaysBreakTemplateDeclarations: MultiLine
|
||||||
AttributeMacros:
|
AttributeMacros:
|
||||||
- __capability
|
- __capability
|
||||||
|
- __unused
|
||||||
BinPackArguments: false
|
BinPackArguments: false
|
||||||
BinPackParameters: true
|
BinPackParameters: false
|
||||||
BraceWrapping:
|
BraceWrapping:
|
||||||
AfterCaseLabel: false
|
AfterCaseLabel: false
|
||||||
AfterClass: false
|
AfterClass: false
|
||||||
|
@ -57,7 +59,7 @@ BreakConstructorInitializersBeforeComma: false
|
||||||
BreakConstructorInitializers: BeforeColon
|
BreakConstructorInitializers: BeforeColon
|
||||||
BreakAfterJavaFieldAnnotations: false
|
BreakAfterJavaFieldAnnotations: false
|
||||||
BreakStringLiterals: true
|
BreakStringLiterals: true
|
||||||
ColumnLimit: 140
|
ColumnLimit: 120
|
||||||
CommentPragmas: '^ IWYU pragma:'
|
CommentPragmas: '^ IWYU pragma:'
|
||||||
CompactNamespaces: true
|
CompactNamespaces: true
|
||||||
ConstructorInitializerAllOnOneLineOrOnePerLine: true
|
ConstructorInitializerAllOnOneLineOrOnePerLine: true
|
||||||
|
@ -174,7 +176,7 @@ SpaceAroundPointerQualifiers: Default
|
||||||
SpaceBeforeRangeBasedForLoopColon: true
|
SpaceBeforeRangeBasedForLoopColon: true
|
||||||
SpaceInEmptyBlock: false
|
SpaceInEmptyBlock: false
|
||||||
SpaceInEmptyParentheses: false
|
SpaceInEmptyParentheses: false
|
||||||
SpacesBeforeTrailingComments: 0
|
SpacesBeforeTrailingComments: 4
|
||||||
SpacesInAngles: false
|
SpacesInAngles: false
|
||||||
SpacesInConditionalStatement: false
|
SpacesInConditionalStatement: false
|
||||||
SpacesInContainerLiterals: false
|
SpacesInContainerLiterals: false
|
||||||
|
@ -199,3 +201,6 @@ WhitespaceSensitiveMacros:
|
||||||
- BOOST_PP_STRINGIZE
|
- BOOST_PP_STRINGIZE
|
||||||
- NS_SWIFT_NAME
|
- NS_SWIFT_NAME
|
||||||
- CF_SWIFT_NAME
|
- CF_SWIFT_NAME
|
||||||
|
TypenameMacros:
|
||||||
|
- CONFIG_ITEM
|
||||||
|
- PCONFIG_ITEM
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -188,50 +188,110 @@ ARG_EXTERN struct arg_rem *arg_rem(const char *datatype, const char *glossary);
|
||||||
|
|
||||||
ARG_EXTERN struct arg_lit *arg_lit0(const char *shortopts, const char *longopts, const char *glossary);
|
ARG_EXTERN struct arg_lit *arg_lit0(const char *shortopts, const char *longopts, const char *glossary);
|
||||||
ARG_EXTERN struct arg_lit *arg_lit1(const char *shortopts, const char *longopts, const char *glossary);
|
ARG_EXTERN struct arg_lit *arg_lit1(const char *shortopts, const char *longopts, const char *glossary);
|
||||||
ARG_EXTERN struct arg_lit *arg_litn(const char *shortopts, const char *longopts, int mincount, int maxcount,
|
ARG_EXTERN struct arg_lit *arg_litn(const char *shortopts,
|
||||||
|
const char *longopts,
|
||||||
|
int mincount,
|
||||||
|
int maxcount,
|
||||||
const char *glossary);
|
const char *glossary);
|
||||||
|
|
||||||
ARG_EXTERN struct arg_int *arg_int0(const char *shortopts, const char *longopts, const char *datatype,
|
ARG_EXTERN struct arg_int *arg_int0(const char *shortopts,
|
||||||
|
const char *longopts,
|
||||||
|
const char *datatype,
|
||||||
const char *glossary);
|
const char *glossary);
|
||||||
ARG_EXTERN struct arg_int *arg_int1(const char *shortopts, const char *longopts, const char *datatype,
|
ARG_EXTERN struct arg_int *arg_int1(const char *shortopts,
|
||||||
|
const char *longopts,
|
||||||
|
const char *datatype,
|
||||||
|
const char *glossary);
|
||||||
|
ARG_EXTERN struct arg_int *arg_intn(const char *shortopts,
|
||||||
|
const char *longopts,
|
||||||
|
const char *datatype,
|
||||||
|
int mincount,
|
||||||
|
int maxcount,
|
||||||
const char *glossary);
|
const char *glossary);
|
||||||
ARG_EXTERN struct arg_int *arg_intn(const char *shortopts, const char *longopts, const char *datatype, int mincount,
|
|
||||||
int maxcount, const char *glossary);
|
|
||||||
|
|
||||||
ARG_EXTERN struct arg_dbl *arg_dbl0(const char *shortopts, const char *longopts, const char *datatype,
|
ARG_EXTERN struct arg_dbl *arg_dbl0(const char *shortopts,
|
||||||
|
const char *longopts,
|
||||||
|
const char *datatype,
|
||||||
const char *glossary);
|
const char *glossary);
|
||||||
ARG_EXTERN struct arg_dbl *arg_dbl1(const char *shortopts, const char *longopts, const char *datatype,
|
ARG_EXTERN struct arg_dbl *arg_dbl1(const char *shortopts,
|
||||||
|
const char *longopts,
|
||||||
|
const char *datatype,
|
||||||
|
const char *glossary);
|
||||||
|
ARG_EXTERN struct arg_dbl *arg_dbln(const char *shortopts,
|
||||||
|
const char *longopts,
|
||||||
|
const char *datatype,
|
||||||
|
int mincount,
|
||||||
|
int maxcount,
|
||||||
const char *glossary);
|
const char *glossary);
|
||||||
ARG_EXTERN struct arg_dbl *arg_dbln(const char *shortopts, const char *longopts, const char *datatype, int mincount,
|
|
||||||
int maxcount, const char *glossary);
|
|
||||||
|
|
||||||
ARG_EXTERN struct arg_str *arg_str0(const char *shortopts, const char *longopts, const char *datatype,
|
ARG_EXTERN struct arg_str *arg_str0(const char *shortopts,
|
||||||
|
const char *longopts,
|
||||||
|
const char *datatype,
|
||||||
const char *glossary);
|
const char *glossary);
|
||||||
ARG_EXTERN struct arg_str *arg_str1(const char *shortopts, const char *longopts, const char *datatype,
|
ARG_EXTERN struct arg_str *arg_str1(const char *shortopts,
|
||||||
|
const char *longopts,
|
||||||
|
const char *datatype,
|
||||||
|
const char *glossary);
|
||||||
|
ARG_EXTERN struct arg_str *arg_strn(const char *shortopts,
|
||||||
|
const char *longopts,
|
||||||
|
const char *datatype,
|
||||||
|
int mincount,
|
||||||
|
int maxcount,
|
||||||
const char *glossary);
|
const char *glossary);
|
||||||
ARG_EXTERN struct arg_str *arg_strn(const char *shortopts, const char *longopts, const char *datatype, int mincount,
|
|
||||||
int maxcount, const char *glossary);
|
|
||||||
|
|
||||||
ARG_EXTERN struct arg_rex *arg_rex0(const char *shortopts, const char *longopts, const char *pattern,
|
ARG_EXTERN struct arg_rex *arg_rex0(const char *shortopts,
|
||||||
const char *datatype, int flags, const char *glossary);
|
const char *longopts,
|
||||||
ARG_EXTERN struct arg_rex *arg_rex1(const char *shortopts, const char *longopts, const char *pattern,
|
const char *pattern,
|
||||||
const char *datatype, int flags, const char *glossary);
|
const char *datatype,
|
||||||
ARG_EXTERN struct arg_rex *arg_rexn(const char *shortopts, const char *longopts, const char *pattern,
|
int flags,
|
||||||
const char *datatype, int mincount, int maxcount, int flags, const char *glossary);
|
|
||||||
|
|
||||||
ARG_EXTERN struct arg_file *arg_file0(const char *shortopts, const char *longopts, const char *datatype,
|
|
||||||
const char *glossary);
|
const char *glossary);
|
||||||
ARG_EXTERN struct arg_file *arg_file1(const char *shortopts, const char *longopts, const char *datatype,
|
ARG_EXTERN struct arg_rex *arg_rex1(const char *shortopts,
|
||||||
|
const char *longopts,
|
||||||
|
const char *pattern,
|
||||||
|
const char *datatype,
|
||||||
|
int flags,
|
||||||
|
const char *glossary);
|
||||||
|
ARG_EXTERN struct arg_rex *arg_rexn(const char *shortopts,
|
||||||
|
const char *longopts,
|
||||||
|
const char *pattern,
|
||||||
|
const char *datatype,
|
||||||
|
int mincount,
|
||||||
|
int maxcount,
|
||||||
|
int flags,
|
||||||
const char *glossary);
|
const char *glossary);
|
||||||
ARG_EXTERN struct arg_file *arg_filen(const char *shortopts, const char *longopts, const char *datatype, int mincount,
|
|
||||||
int maxcount, const char *glossary);
|
|
||||||
|
|
||||||
ARG_EXTERN struct arg_date *arg_date0(const char *shortopts, const char *longopts, const char *format,
|
ARG_EXTERN struct arg_file *arg_file0(const char *shortopts,
|
||||||
const char *datatype, const char *glossary);
|
const char *longopts,
|
||||||
ARG_EXTERN struct arg_date *arg_date1(const char *shortopts, const char *longopts, const char *format,
|
const char *datatype,
|
||||||
const char *datatype, const char *glossary);
|
const char *glossary);
|
||||||
ARG_EXTERN struct arg_date *arg_daten(const char *shortopts, const char *longopts, const char *format,
|
ARG_EXTERN struct arg_file *arg_file1(const char *shortopts,
|
||||||
const char *datatype, int mincount, int maxcount, const char *glossary);
|
const char *longopts,
|
||||||
|
const char *datatype,
|
||||||
|
const char *glossary);
|
||||||
|
ARG_EXTERN struct arg_file *arg_filen(const char *shortopts,
|
||||||
|
const char *longopts,
|
||||||
|
const char *datatype,
|
||||||
|
int mincount,
|
||||||
|
int maxcount,
|
||||||
|
const char *glossary);
|
||||||
|
|
||||||
|
ARG_EXTERN struct arg_date *arg_date0(const char *shortopts,
|
||||||
|
const char *longopts,
|
||||||
|
const char *format,
|
||||||
|
const char *datatype,
|
||||||
|
const char *glossary);
|
||||||
|
ARG_EXTERN struct arg_date *arg_date1(const char *shortopts,
|
||||||
|
const char *longopts,
|
||||||
|
const char *format,
|
||||||
|
const char *datatype,
|
||||||
|
const char *glossary);
|
||||||
|
ARG_EXTERN struct arg_date *arg_daten(const char *shortopts,
|
||||||
|
const char *longopts,
|
||||||
|
const char *format,
|
||||||
|
const char *datatype,
|
||||||
|
int mincount,
|
||||||
|
int maxcount,
|
||||||
|
const char *glossary);
|
||||||
|
|
||||||
ARG_EXTERN struct arg_end *arg_end(int maxerrors);
|
ARG_EXTERN struct arg_end *arg_end(int maxerrors);
|
||||||
|
|
||||||
|
@ -242,14 +302,20 @@ ARG_EXTERN struct arg_end *arg_end(int maxerrors);
|
||||||
/**** other functions *******************************************/
|
/**** other functions *******************************************/
|
||||||
ARG_EXTERN int arg_nullcheck(void **argtable);
|
ARG_EXTERN int arg_nullcheck(void **argtable);
|
||||||
ARG_EXTERN int arg_parse(int argc, char **argv, void **argtable);
|
ARG_EXTERN int arg_parse(int argc, char **argv, void **argtable);
|
||||||
ARG_EXTERN void arg_print_option(FILE *fp, const char *shortopts, const char *longopts, const char *datatype,
|
ARG_EXTERN void arg_print_option(FILE *fp,
|
||||||
|
const char *shortopts,
|
||||||
|
const char *longopts,
|
||||||
|
const char *datatype,
|
||||||
const char *suffix);
|
const char *suffix);
|
||||||
ARG_EXTERN void arg_print_syntax(FILE *fp, void **argtable, const char *suffix);
|
ARG_EXTERN void arg_print_syntax(FILE *fp, void **argtable, const char *suffix);
|
||||||
ARG_EXTERN void arg_print_syntaxv(FILE *fp, void **argtable, const char *suffix);
|
ARG_EXTERN void arg_print_syntaxv(FILE *fp, void **argtable, const char *suffix);
|
||||||
ARG_EXTERN void arg_print_glossary(FILE *fp, void **argtable, const char *format);
|
ARG_EXTERN void arg_print_glossary(FILE *fp, void **argtable, const char *format);
|
||||||
ARG_EXTERN void arg_print_glossary_gnu(FILE *fp, void **argtable);
|
ARG_EXTERN void arg_print_glossary_gnu(FILE *fp, void **argtable);
|
||||||
ARG_EXTERN void arg_print_errors(FILE *fp, struct arg_end *end, const char *progname);
|
ARG_EXTERN void arg_print_errors(FILE *fp, struct arg_end *end, const char *progname);
|
||||||
ARG_EXTERN void arg_print_option_ds(arg_dstr_t ds, const char *shortopts, const char *longopts, const char *datatype,
|
ARG_EXTERN void arg_print_option_ds(arg_dstr_t ds,
|
||||||
|
const char *shortopts,
|
||||||
|
const char *longopts,
|
||||||
|
const char *datatype,
|
||||||
const char *suffix);
|
const char *suffix);
|
||||||
ARG_EXTERN void arg_print_syntax_ds(arg_dstr_t ds, void **argtable, const char *suffix);
|
ARG_EXTERN void arg_print_syntax_ds(arg_dstr_t ds, void **argtable, const char *suffix);
|
||||||
ARG_EXTERN void arg_print_syntaxv_ds(arg_dstr_t ds, void **argtable, const char *suffix);
|
ARG_EXTERN void arg_print_syntaxv_ds(arg_dstr_t ds, void **argtable, const char *suffix);
|
||||||
|
@ -285,8 +351,13 @@ ARG_EXTERN void arg_mgsort(void *data, int size, int esize, int i, in
|
||||||
ARG_EXTERN void arg_make_get_help_msg(arg_dstr_t res);
|
ARG_EXTERN void arg_make_get_help_msg(arg_dstr_t res);
|
||||||
ARG_EXTERN void arg_make_help_msg(arg_dstr_t ds, char *cmd_name, void **argtable);
|
ARG_EXTERN void arg_make_help_msg(arg_dstr_t ds, char *cmd_name, void **argtable);
|
||||||
ARG_EXTERN void arg_make_syntax_err_msg(arg_dstr_t ds, void **argtable, struct arg_end *end);
|
ARG_EXTERN void arg_make_syntax_err_msg(arg_dstr_t ds, void **argtable, struct arg_end *end);
|
||||||
ARG_EXTERN int arg_make_syntax_err_help_msg(arg_dstr_t ds, char *name, int help, int nerrors, void **argtable,
|
ARG_EXTERN int arg_make_syntax_err_help_msg(arg_dstr_t ds,
|
||||||
struct arg_end *end, int *exitcode);
|
char *name,
|
||||||
|
int help,
|
||||||
|
int nerrors,
|
||||||
|
void **argtable,
|
||||||
|
struct arg_end *end,
|
||||||
|
int *exitcode);
|
||||||
ARG_EXTERN void arg_set_module_name(const char *name);
|
ARG_EXTERN void arg_set_module_name(const char *name);
|
||||||
ARG_EXTERN void arg_set_module_version(int major, int minor, int patch, const char *tag);
|
ARG_EXTERN void arg_set_module_version(int major, int minor, int patch, const char *tag);
|
||||||
|
|
||||||
|
|
|
@ -77,7 +77,11 @@ static void onEVPWorkCb(uv_work_t *pWork) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int evp_add_crypto_task(CRYPTO_TYPE type, unsigned char *pInBuf, unsigned int iSize, unsigned char *pOutBuf, char *pKey,
|
int evp_add_crypto_task(CRYPTO_TYPE type,
|
||||||
|
unsigned char *pInBuf,
|
||||||
|
unsigned int iSize,
|
||||||
|
unsigned char *pOutBuf,
|
||||||
|
char *pKey,
|
||||||
on_evp_crypto onEvpCryptCb) {
|
on_evp_crypto onEvpCryptCb) {
|
||||||
uv_work_t *puvWork = NULL;
|
uv_work_t *puvWork = NULL;
|
||||||
PCRYPT_TASK_PARAMS pTask = NULL;
|
PCRYPT_TASK_PARAMS pTask = NULL;
|
||||||
|
|
|
@ -92,7 +92,10 @@ int hash_digest_file(HASH_TYPE hashType, const char *pFileName, char **pHashValu
|
||||||
* @param pHashValue
|
* @param pHashValue
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
int hash_digest_mem(HASH_TYPE hashType, const unsigned char *pBuf, unsigned int iBufLen, unsigned char **pHashValue,
|
int hash_digest_mem(HASH_TYPE hashType,
|
||||||
|
const unsigned char *pBuf,
|
||||||
|
unsigned int iBufLen,
|
||||||
|
unsigned char **pHashValue,
|
||||||
unsigned int *pOutSize) {
|
unsigned int *pOutSize) {
|
||||||
EVP_MD_CTX *pCtx;
|
EVP_MD_CTX *pCtx;
|
||||||
|
|
||||||
|
|
|
@ -110,8 +110,12 @@ static int sha1prng_for_aes_key(const char *pKey, unsigned char *pShaPrng16) {
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
int symmetric_decrypto(AES_TYPE algorithmType, unsigned char *pInBuf, unsigned int inSize, unsigned char **pOutBuf,
|
int symmetric_decrypto(AES_TYPE algorithmType,
|
||||||
int *pOutSize, const char *pKey) {
|
unsigned char *pInBuf,
|
||||||
|
unsigned int inSize,
|
||||||
|
unsigned char **pOutBuf,
|
||||||
|
int *pOutSize,
|
||||||
|
const char *pKey) {
|
||||||
int enBytes = 0;
|
int enBytes = 0;
|
||||||
EVP_CIPHER_CTX *pCtx;
|
EVP_CIPHER_CTX *pCtx;
|
||||||
unsigned char *pAesBuf;
|
unsigned char *pAesBuf;
|
||||||
|
@ -180,8 +184,12 @@ int symmetric_decrypto(AES_TYPE algorithmType, unsigned char *pInBuf, unsigned i
|
||||||
return ERR_SUCCESS;
|
return ERR_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int symmetric_encrypto(AES_TYPE algorithmType, unsigned char *pInBuf, unsigned int inSize, unsigned char **pOutBuf,
|
int symmetric_encrypto(AES_TYPE algorithmType,
|
||||||
int *pOutSize, const char *pKey) {
|
unsigned char *pInBuf,
|
||||||
|
unsigned int inSize,
|
||||||
|
unsigned char **pOutBuf,
|
||||||
|
int *pOutSize,
|
||||||
|
const char *pKey) {
|
||||||
int enBytes = 0;
|
int enBytes = 0;
|
||||||
unsigned char *pAesBuf;
|
unsigned char *pAesBuf;
|
||||||
EVP_CIPHER_CTX *pCtx;
|
EVP_CIPHER_CTX *pCtx;
|
||||||
|
|
|
@ -38,16 +38,27 @@ typedef enum {
|
||||||
HASH_TYPE_SHA256 = 2,
|
HASH_TYPE_SHA256 = 2,
|
||||||
} HASH_TYPE;
|
} HASH_TYPE;
|
||||||
|
|
||||||
typedef void (*on_evp_crypto)(CRYPTO_TYPE type, const unsigned char *pData, unsigned int iSize,
|
typedef void (*on_evp_crypto)(CRYPTO_TYPE type,
|
||||||
const unsigned char *pSrcData, int iError);
|
const unsigned char *pData,
|
||||||
|
unsigned int iSize,
|
||||||
|
const unsigned char *pSrcData,
|
||||||
|
int iError);
|
||||||
|
|
||||||
//*****************************************************
|
//*****************************************************
|
||||||
// AES
|
// AES
|
||||||
//*****************************************************
|
//*****************************************************
|
||||||
int symmetric_encrypto(AES_TYPE algorithmType, unsigned char *pInBuf, unsigned int inSize, unsigned char **pOutBuf,
|
int symmetric_encrypto(AES_TYPE algorithmType,
|
||||||
int *pOutSize, const char *pKey);
|
unsigned char *pInBuf,
|
||||||
int symmetric_decrypto(AES_TYPE algorithmType, unsigned char *pInBuf, unsigned int inSize, unsigned char **pOutBuf,
|
unsigned int inSize,
|
||||||
int *pOutSize, const char *pKey);
|
unsigned char **pOutBuf,
|
||||||
|
int *pOutSize,
|
||||||
|
const char *pKey);
|
||||||
|
int symmetric_decrypto(AES_TYPE algorithmType,
|
||||||
|
unsigned char *pInBuf,
|
||||||
|
unsigned int inSize,
|
||||||
|
unsigned char **pOutBuf,
|
||||||
|
int *pOutSize,
|
||||||
|
const char *pKey);
|
||||||
//*****************************************************
|
//*****************************************************
|
||||||
// BASE64
|
// BASE64
|
||||||
//*****************************************************
|
//*****************************************************
|
||||||
|
@ -62,13 +73,20 @@ unsigned char *base64_decode(const char *pBase64, unsigned int *pOutSize);
|
||||||
// MD5
|
// MD5
|
||||||
//*****************************************************
|
//*****************************************************
|
||||||
int hash_digest_file(HASH_TYPE hashType, const char *pFileName, char **pHashValue);
|
int hash_digest_file(HASH_TYPE hashType, const char *pFileName, char **pHashValue);
|
||||||
int hash_digest_mem(HASH_TYPE hashType, const unsigned char *pBuf, unsigned int iBufLen, unsigned char **pHashValue,
|
int hash_digest_mem(HASH_TYPE hashType,
|
||||||
|
const unsigned char *pBuf,
|
||||||
|
unsigned int iBufLen,
|
||||||
|
unsigned char **pHashValue,
|
||||||
unsigned int *pOutSize);
|
unsigned int *pOutSize);
|
||||||
|
|
||||||
//*****************************************************
|
//*****************************************************
|
||||||
// Async Engine
|
// Async Engine
|
||||||
//*****************************************************
|
//*****************************************************
|
||||||
int evp_add_crypto_task(CRYPTO_TYPE type, unsigned char *pInBuf, unsigned int iSize, unsigned char *pOutBuf, char *pKey,
|
int evp_add_crypto_task(CRYPTO_TYPE type,
|
||||||
|
unsigned char *pInBuf,
|
||||||
|
unsigned int iSize,
|
||||||
|
unsigned char *pOutBuf,
|
||||||
|
char *pKey,
|
||||||
on_evp_crypto onEvpCryptCb);
|
on_evp_crypto onEvpCryptCb);
|
||||||
|
|
||||||
void evp_system_init(void);
|
void evp_system_init(void);
|
||||||
|
|
|
@ -10,13 +10,23 @@ extern "C" {
|
||||||
|
|
||||||
int inet_api_init(void);
|
int inet_api_init(void);
|
||||||
|
|
||||||
typedef void (*on_http_response)(void *pData, unsigned int size, const char *pReqUrl, const char *pDlPath,
|
typedef void (*on_http_response)(void *pData,
|
||||||
const char *pTaskUuid, int iFinished, void *pUserData);
|
unsigned int size,
|
||||||
typedef void (*on_progress_changed)(const char *pReqUrl, const char *pTaskUuid, unsigned char uPercent,
|
const char *pReqUrl,
|
||||||
|
const char *pDlPath,
|
||||||
|
const char *pTaskUuid,
|
||||||
|
int iFinished,
|
||||||
|
void *pUserData);
|
||||||
|
typedef void (*on_progress_changed)(const char *pReqUrl,
|
||||||
|
const char *pTaskUuid,
|
||||||
|
unsigned char uPercent,
|
||||||
void *pUserData);
|
void *pUserData);
|
||||||
|
|
||||||
const char *inet_download_file_async(const char *pURL, const char *pPath, on_http_response onRespCb,
|
const char *inet_download_file_async(const char *pURL,
|
||||||
on_progress_changed onProgressCb, void *pData);
|
const char *pPath,
|
||||||
|
on_http_response onRespCb,
|
||||||
|
on_progress_changed onProgressCb,
|
||||||
|
void *pData);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,10 @@ int copy_file(const char *pSrc, const char *pDest);
|
||||||
char *bin2hex(char *p, const unsigned char *cp, unsigned int count);
|
char *bin2hex(char *p, const unsigned char *cp, unsigned int count);
|
||||||
int shell_with_output(const char *pCmd, char **pResult);
|
int shell_with_output(const char *pCmd, char **pResult);
|
||||||
int str_to_mac(const char *str, unsigned char mac[6]);
|
int str_to_mac(const char *str, unsigned char mac[6]);
|
||||||
int get_nic_info(const char *pName, unsigned int *pIp, unsigned int *pNetmask, unsigned int *pGateway,
|
int get_nic_info(const char *pName,
|
||||||
|
unsigned int *pIp,
|
||||||
|
unsigned int *pNetmask,
|
||||||
|
unsigned int *pGateway,
|
||||||
unsigned char *pMac);
|
unsigned char *pMac);
|
||||||
int str_to_ipaddr(const char *pIp, unsigned int *ipAddr);
|
int str_to_ipaddr(const char *pIp, unsigned int *ipAddr);
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -24,8 +24,7 @@
|
||||||
#define cJSON__h
|
#define cJSON__h
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C"
|
extern "C" {
|
||||||
{
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(__WINDOWS__) && (defined(WIN32) || defined(WIN64) || defined(_MSC_VER) || defined(_WIN32))
|
#if !defined(__WINDOWS__) && (defined(WIN32) || defined(WIN64) || defined(_MSC_VER) || defined(_WIN32))
|
||||||
|
@ -100,8 +99,7 @@ then using the CJSON_API_VISIBILITY flag to "export" the same symbols the way CJ
|
||||||
#define cJSON_StringIsConst 512
|
#define cJSON_StringIsConst 512
|
||||||
|
|
||||||
/* The cJSON structure: */
|
/* The cJSON structure: */
|
||||||
typedef struct cJSON
|
typedef struct cJSON {
|
||||||
{
|
|
||||||
/* next/prev allow you to walk array/object chains. Alternatively, use GetArraySize/GetArrayItem/GetObjectItem */
|
/* next/prev allow you to walk array/object chains. Alternatively, use GetArraySize/GetArrayItem/GetObjectItem */
|
||||||
struct cJSON *next;
|
struct cJSON *next;
|
||||||
struct cJSON *prev;
|
struct cJSON *prev;
|
||||||
|
@ -122,8 +120,7 @@ typedef struct cJSON
|
||||||
char *string;
|
char *string;
|
||||||
} cJSON;
|
} cJSON;
|
||||||
|
|
||||||
typedef struct cJSON_Hooks
|
typedef struct cJSON_Hooks {
|
||||||
{
|
|
||||||
/* malloc/free are CDECL on Windows regardless of the default calling convention of the compiler, so ensure the hooks allow passing those functions directly. */
|
/* malloc/free are CDECL on Windows regardless of the default calling convention of the compiler, so ensure the hooks allow passing those functions directly. */
|
||||||
void *(CJSON_CDECL *malloc_fn)(size_t sz);
|
void *(CJSON_CDECL *malloc_fn)(size_t sz);
|
||||||
void(CJSON_CDECL *free_fn)(void *ptr);
|
void(CJSON_CDECL *free_fn)(void *ptr);
|
||||||
|
@ -149,8 +146,13 @@ CJSON_PUBLIC(cJSON *) cJSON_Parse(const char *value);
|
||||||
CJSON_PUBLIC(cJSON *) cJSON_ParseWithLength(const char *value, size_t buffer_length);
|
CJSON_PUBLIC(cJSON *) cJSON_ParseWithLength(const char *value, size_t buffer_length);
|
||||||
/* ParseWithOpts allows you to require (and check) that the JSON is null terminated, and to retrieve the pointer to the final byte parsed. */
|
/* ParseWithOpts allows you to require (and check) that the JSON is null terminated, and to retrieve the pointer to the final byte parsed. */
|
||||||
/* If you supply a ptr in return_parse_end and parsing fails, then return_parse_end will contain a pointer to the error so will match cJSON_GetErrorPtr(). */
|
/* If you supply a ptr in return_parse_end and parsing fails, then return_parse_end will contain a pointer to the error so will match cJSON_GetErrorPtr(). */
|
||||||
CJSON_PUBLIC(cJSON *) cJSON_ParseWithOpts(const char *value, const char **return_parse_end, cJSON_bool require_null_terminated);
|
CJSON_PUBLIC(cJSON *)
|
||||||
CJSON_PUBLIC(cJSON *) cJSON_ParseWithLengthOpts(const char *value, size_t buffer_length, const char **return_parse_end, cJSON_bool require_null_terminated);
|
cJSON_ParseWithOpts(const char *value, const char **return_parse_end, cJSON_bool require_null_terminated);
|
||||||
|
CJSON_PUBLIC(cJSON *)
|
||||||
|
cJSON_ParseWithLengthOpts(const char *value,
|
||||||
|
size_t buffer_length,
|
||||||
|
const char **return_parse_end,
|
||||||
|
cJSON_bool require_null_terminated);
|
||||||
|
|
||||||
/* Render a cJSON entity to text for transfer/storage. */
|
/* Render a cJSON entity to text for transfer/storage. */
|
||||||
CJSON_PUBLIC(char *) cJSON_Print(const cJSON *item);
|
CJSON_PUBLIC(char *) cJSON_Print(const cJSON *item);
|
||||||
|
@ -160,7 +162,8 @@ CJSON_PUBLIC(char *) cJSON_PrintUnformatted(const cJSON *item);
|
||||||
CJSON_PUBLIC(char *) cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_bool fmt);
|
CJSON_PUBLIC(char *) cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_bool fmt);
|
||||||
/* Render a cJSON entity to text using a buffer already allocated in memory with given length. Returns 1 on success and 0 on failure. */
|
/* Render a cJSON entity to text using a buffer already allocated in memory with given length. Returns 1 on success and 0 on failure. */
|
||||||
/* NOTE: cJSON is not always 100% accurate in estimating how much memory it will use, so to be safe allocate 5 bytes more than you actually need */
|
/* NOTE: cJSON is not always 100% accurate in estimating how much memory it will use, so to be safe allocate 5 bytes more than you actually need */
|
||||||
CJSON_PUBLIC(cJSON_bool) cJSON_PrintPreallocated(cJSON *item, char *buffer, const int length, const cJSON_bool format);
|
CJSON_PUBLIC(cJSON_bool)
|
||||||
|
cJSON_PrintPreallocated(cJSON *item, char *buffer, const int length, const cJSON_bool format);
|
||||||
/* Delete a cJSON entity and all subentities. */
|
/* Delete a cJSON entity and all subentities. */
|
||||||
CJSON_PUBLIC(void) cJSON_Delete(cJSON *item);
|
CJSON_PUBLIC(void) cJSON_Delete(cJSON *item);
|
||||||
|
|
||||||
|
@ -239,7 +242,8 @@ CJSON_PUBLIC(void) cJSON_DeleteItemFromObject(cJSON *object, const char *string)
|
||||||
CJSON_PUBLIC(void) cJSON_DeleteItemFromObjectCaseSensitive(cJSON *object, const char *string);
|
CJSON_PUBLIC(void) cJSON_DeleteItemFromObjectCaseSensitive(cJSON *object, const char *string);
|
||||||
|
|
||||||
/* Update array items. */
|
/* Update array items. */
|
||||||
CJSON_PUBLIC(cJSON_bool) cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem); /* Shifts pre-existing items to the right. */
|
CJSON_PUBLIC(cJSON_bool)
|
||||||
|
cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem); /* Shifts pre-existing items to the right. */
|
||||||
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON *const parent, cJSON *const item, cJSON *replacement);
|
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON *const parent, cJSON *const item, cJSON *replacement);
|
||||||
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem);
|
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem);
|
||||||
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObject(cJSON *object, const char *string, cJSON *newitem);
|
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObject(cJSON *object, const char *string, cJSON *newitem);
|
||||||
|
@ -266,7 +270,8 @@ CJSON_PUBLIC(cJSON*) cJSON_AddTrueToObject(cJSON * const object, const char * co
|
||||||
CJSON_PUBLIC(cJSON *) cJSON_AddFalseToObject(cJSON *const object, const char *const name);
|
CJSON_PUBLIC(cJSON *) cJSON_AddFalseToObject(cJSON *const object, const char *const name);
|
||||||
CJSON_PUBLIC(cJSON *) cJSON_AddBoolToObject(cJSON *const object, const char *const name, const cJSON_bool boolean);
|
CJSON_PUBLIC(cJSON *) cJSON_AddBoolToObject(cJSON *const object, const char *const name, const cJSON_bool boolean);
|
||||||
CJSON_PUBLIC(cJSON *) cJSON_AddNumberToObject(cJSON *const object, const char *const name, const double number);
|
CJSON_PUBLIC(cJSON *) cJSON_AddNumberToObject(cJSON *const object, const char *const name, const double number);
|
||||||
CJSON_PUBLIC(cJSON*) cJSON_AddStringToObject(cJSON * const object, const char * const name, const char * const string);
|
CJSON_PUBLIC(cJSON *)
|
||||||
|
cJSON_AddStringToObject(cJSON *const object, const char *const name, const char *const string);
|
||||||
CJSON_PUBLIC(cJSON *) cJSON_AddRawToObject(cJSON *const object, const char *const name, const char *const raw);
|
CJSON_PUBLIC(cJSON *) cJSON_AddRawToObject(cJSON *const object, const char *const name, const char *const raw);
|
||||||
CJSON_PUBLIC(cJSON *) cJSON_AddObjectToObject(cJSON *const object, const char *const name);
|
CJSON_PUBLIC(cJSON *) cJSON_AddObjectToObject(cJSON *const object, const char *const name);
|
||||||
CJSON_PUBLIC(cJSON *) cJSON_AddArrayToObject(cJSON *const object, const char *const name);
|
CJSON_PUBLIC(cJSON *) cJSON_AddArrayToObject(cJSON *const object, const char *const name);
|
||||||
|
@ -275,12 +280,14 @@ CJSON_PUBLIC(cJSON*) cJSON_AddArrayToObject(cJSON * const object, const char * c
|
||||||
#define cJSON_SetIntValue(object, number) ((object) ? (object)->valueint = (object)->valuedouble = (number) : (number))
|
#define cJSON_SetIntValue(object, number) ((object) ? (object)->valueint = (object)->valuedouble = (number) : (number))
|
||||||
/* helper for the cJSON_SetNumberValue macro */
|
/* helper for the cJSON_SetNumberValue macro */
|
||||||
CJSON_PUBLIC(double) cJSON_SetNumberHelper(cJSON *object, double number);
|
CJSON_PUBLIC(double) cJSON_SetNumberHelper(cJSON *object, double number);
|
||||||
#define cJSON_SetNumberValue(object, number) ((object != NULL) ? cJSON_SetNumberHelper(object, (double)number) : (number))
|
#define cJSON_SetNumberValue(object, number) \
|
||||||
|
((object != NULL) ? cJSON_SetNumberHelper(object, (double)number) : (number))
|
||||||
/* Change the valuestring of a cJSON_String object, only takes effect when type of object is cJSON_String */
|
/* Change the valuestring of a cJSON_String object, only takes effect when type of object is cJSON_String */
|
||||||
CJSON_PUBLIC(char *) cJSON_SetValuestring(cJSON *object, const char *valuestring);
|
CJSON_PUBLIC(char *) cJSON_SetValuestring(cJSON *object, const char *valuestring);
|
||||||
|
|
||||||
/* Macro for iterating over an array or object */
|
/* Macro for iterating over an array or object */
|
||||||
#define cJSON_ArrayForEach(element, array) for(element = (array != NULL) ? (array)->child : NULL; element != NULL; element = element->next)
|
#define cJSON_ArrayForEach(element, array) \
|
||||||
|
for (element = (array != NULL) ? (array)->child : NULL; element != NULL; element = element->next)
|
||||||
|
|
||||||
/* malloc/free objects using the malloc/free functions that have been set with cJSON_InitHooks */
|
/* malloc/free objects using the malloc/free functions that have been set with cJSON_InitHooks */
|
||||||
CJSON_PUBLIC(void *) cJSON_malloc(size_t size);
|
CJSON_PUBLIC(void *) cJSON_malloc(size_t size);
|
||||||
|
|
|
@ -220,22 +220,14 @@ typedef struct {
|
||||||
for (; index_##_element < realsize_##_element && index_##_element < size; index_##_element++) { \
|
for (; index_##_element < realsize_##_element && index_##_element < size; index_##_element++) { \
|
||||||
array_item_##_element = cJSON_GetArrayItem(array_##_element, index_##_element); \
|
array_item_##_element = cJSON_GetArrayItem(array_##_element, index_##_element); \
|
||||||
if (array_item_##_element) { \
|
if (array_item_##_element) { \
|
||||||
S2J_STRUCT_ARRAY_GET_ELEMENT_EX(to_struct, \
|
S2J_STRUCT_ARRAY_GET_ELEMENT_EX( \
|
||||||
array_item_##_element, \
|
to_struct, array_item_##_element, type, _element, index_##_element, _defval); \
|
||||||
type, \
|
|
||||||
_element, \
|
|
||||||
index_##_element, \
|
|
||||||
_defval); \
|
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
} else { \
|
} else { \
|
||||||
for (; index_##_element < realsize_##_element && index_##_element < size; index_##_element++) { \
|
for (; index_##_element < realsize_##_element && index_##_element < size; index_##_element++) { \
|
||||||
S2J_STRUCT_ARRAY_GET_ELEMENT_EX(to_struct, \
|
S2J_STRUCT_ARRAY_GET_ELEMENT_EX( \
|
||||||
array_##_element, \
|
to_struct, array_##_element, type, _element, index_##_element, _defval); \
|
||||||
type, \
|
|
||||||
_element, \
|
|
||||||
index_##_element, \
|
|
||||||
_defval); \
|
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
} else { \
|
} else { \
|
||||||
|
|
|
@ -134,12 +134,10 @@ static inline size_t sdsavail(const sds s) {
|
||||||
static inline void sdssetlen(sds s, size_t newlen) {
|
static inline void sdssetlen(sds s, size_t newlen) {
|
||||||
unsigned char flags = s[-1];
|
unsigned char flags = s[-1];
|
||||||
switch (flags & SDS_TYPE_MASK) {
|
switch (flags & SDS_TYPE_MASK) {
|
||||||
case SDS_TYPE_5:
|
case SDS_TYPE_5: {
|
||||||
{
|
|
||||||
unsigned char *fp = ((unsigned char *)s) - 1;
|
unsigned char *fp = ((unsigned char *)s) - 1;
|
||||||
*fp = (unsigned char)(SDS_TYPE_5 | (newlen << SDS_TYPE_BITS));
|
*fp = (unsigned char)(SDS_TYPE_5 | (newlen << SDS_TYPE_BITS));
|
||||||
}
|
} break;
|
||||||
break;
|
|
||||||
case SDS_TYPE_8:
|
case SDS_TYPE_8:
|
||||||
SDS_HDR(8, s)->len = (uint8_t)newlen;
|
SDS_HDR(8, s)->len = (uint8_t)newlen;
|
||||||
break;
|
break;
|
||||||
|
@ -158,13 +156,11 @@ static inline void sdssetlen(sds s, size_t newlen) {
|
||||||
static inline void sdsinclen(sds s, size_t inc) {
|
static inline void sdsinclen(sds s, size_t inc) {
|
||||||
unsigned char flags = s[-1];
|
unsigned char flags = s[-1];
|
||||||
switch (flags & SDS_TYPE_MASK) {
|
switch (flags & SDS_TYPE_MASK) {
|
||||||
case SDS_TYPE_5:
|
case SDS_TYPE_5: {
|
||||||
{
|
|
||||||
unsigned char *fp = ((unsigned char *)s) - 1;
|
unsigned char *fp = ((unsigned char *)s) - 1;
|
||||||
unsigned char newlen = SDS_TYPE_5_LEN(flags) + (unsigned char)inc;
|
unsigned char newlen = SDS_TYPE_5_LEN(flags) + (unsigned char)inc;
|
||||||
*fp = SDS_TYPE_5 | (newlen << SDS_TYPE_BITS);
|
*fp = SDS_TYPE_5 | (newlen << SDS_TYPE_BITS);
|
||||||
}
|
} break;
|
||||||
break;
|
|
||||||
case SDS_TYPE_8:
|
case SDS_TYPE_8:
|
||||||
SDS_HDR(8, s)->len += (uint8_t)inc;
|
SDS_HDR(8, s)->len += (uint8_t)inc;
|
||||||
break;
|
break;
|
||||||
|
@ -233,8 +229,7 @@ sds sdscpy(sds s, const char *t);
|
||||||
|
|
||||||
sds sdscatvprintf(sds s, const char *fmt, va_list ap);
|
sds sdscatvprintf(sds s, const char *fmt, va_list ap);
|
||||||
#ifdef __GNUC__
|
#ifdef __GNUC__
|
||||||
sds sdscatprintf(sds s, const char *fmt, ...)
|
sds sdscatprintf(sds s, const char *fmt, ...) __attribute__((format(printf, 2, 3)));
|
||||||
__attribute__((format(printf, 2, 3)));
|
|
||||||
#else
|
#else
|
||||||
sds sdscatprintf(sds s, const char *fmt, ...);
|
sds sdscatprintf(sds s, const char *fmt, ...);
|
||||||
#endif
|
#endif
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -47,10 +47,8 @@ struct sqlite3_api_routines {
|
||||||
int (*busy_timeout)(sqlite3 *, int ms);
|
int (*busy_timeout)(sqlite3 *, int ms);
|
||||||
int (*changes)(sqlite3 *);
|
int (*changes)(sqlite3 *);
|
||||||
int (*close)(sqlite3 *);
|
int (*close)(sqlite3 *);
|
||||||
int (*collation_needed)(sqlite3*,void*,void(*)(void*,sqlite3*,
|
int (*collation_needed)(sqlite3 *, void *, void (*)(void *, sqlite3 *, int eTextRep, const char *));
|
||||||
int eTextRep,const char*));
|
int (*collation_needed16)(sqlite3 *, void *, void (*)(void *, sqlite3 *, int eTextRep, const void *));
|
||||||
int (*collation_needed16)(sqlite3*,void*,void(*)(void*,sqlite3*,
|
|
||||||
int eTextRep,const void*));
|
|
||||||
const void *(*column_blob)(sqlite3_stmt *, int iCol);
|
const void *(*column_blob)(sqlite3_stmt *, int iCol);
|
||||||
int (*column_bytes)(sqlite3_stmt *, int iCol);
|
int (*column_bytes)(sqlite3_stmt *, int iCol);
|
||||||
int (*column_bytes16)(sqlite3_stmt *, int iCol);
|
int (*column_bytes16)(sqlite3_stmt *, int iCol);
|
||||||
|
@ -75,15 +73,26 @@ struct sqlite3_api_routines {
|
||||||
void *(*commit_hook)(sqlite3 *, int (*)(void *), void *);
|
void *(*commit_hook)(sqlite3 *, int (*)(void *), void *);
|
||||||
int (*complete)(const char *sql);
|
int (*complete)(const char *sql);
|
||||||
int (*complete16)(const void *sql);
|
int (*complete16)(const void *sql);
|
||||||
int (*create_collation)(sqlite3*,const char*,int,void*,
|
int (
|
||||||
|
*create_collation)(sqlite3 *, const char *, int, void *, int (*)(void *, int, const void *, int, const void *));
|
||||||
|
int (*create_collation16)(sqlite3 *,
|
||||||
|
const void *,
|
||||||
|
int,
|
||||||
|
void *,
|
||||||
int (*)(void *, int, const void *, int, const void *));
|
int (*)(void *, int, const void *, int, const void *));
|
||||||
int (*create_collation16)(sqlite3*,const void*,int,void*,
|
int (*create_function)(sqlite3 *,
|
||||||
int(*)(void*,int,const void*,int,const void*));
|
const char *,
|
||||||
int (*create_function)(sqlite3*,const char*,int,int,void*,
|
int,
|
||||||
|
int,
|
||||||
|
void *,
|
||||||
void (*xFunc)(sqlite3_context *, int, sqlite3_value **),
|
void (*xFunc)(sqlite3_context *, int, sqlite3_value **),
|
||||||
void (*xStep)(sqlite3_context *, int, sqlite3_value **),
|
void (*xStep)(sqlite3_context *, int, sqlite3_value **),
|
||||||
void (*xFinal)(sqlite3_context *));
|
void (*xFinal)(sqlite3_context *));
|
||||||
int (*create_function16)(sqlite3*,const void*,int,int,void*,
|
int (*create_function16)(sqlite3 *,
|
||||||
|
const void *,
|
||||||
|
int,
|
||||||
|
int,
|
||||||
|
void *,
|
||||||
void (*xFunc)(sqlite3_context *, int, sqlite3_value **),
|
void (*xFunc)(sqlite3_context *, int, sqlite3_value **),
|
||||||
void (*xStep)(sqlite3_context *, int, sqlite3_value **),
|
void (*xStep)(sqlite3_context *, int, sqlite3_value **),
|
||||||
void (*xFinal)(sqlite3_context *));
|
void (*xFinal)(sqlite3_context *));
|
||||||
|
@ -131,19 +140,26 @@ struct sqlite3_api_routines {
|
||||||
void (*result_text16le)(sqlite3_context *, const void *, int, void (*)(void *));
|
void (*result_text16le)(sqlite3_context *, const void *, int, void (*)(void *));
|
||||||
void (*result_value)(sqlite3_context *, sqlite3_value *);
|
void (*result_value)(sqlite3_context *, sqlite3_value *);
|
||||||
void *(*rollback_hook)(sqlite3 *, void (*)(void *), void *);
|
void *(*rollback_hook)(sqlite3 *, void (*)(void *), void *);
|
||||||
int (*set_authorizer)(sqlite3*,int(*)(void*,int,const char*,const char*,
|
int (*set_authorizer)(sqlite3 *,
|
||||||
const char*,const char*),void*);
|
int (*)(void *, int, const char *, const char *, const char *, const char *),
|
||||||
|
void *);
|
||||||
void (*set_auxdata)(sqlite3_context *, int, void *, void (*)(void *));
|
void (*set_auxdata)(sqlite3_context *, int, void *, void (*)(void *));
|
||||||
char *(*xsnprintf)(int, char *, const char *, ...);
|
char *(*xsnprintf)(int, char *, const char *, ...);
|
||||||
int (*step)(sqlite3_stmt *);
|
int (*step)(sqlite3_stmt *);
|
||||||
int (*table_column_metadata)(sqlite3*,const char*,const char*,const char*,
|
int (*table_column_metadata)(sqlite3 *,
|
||||||
char const**,char const**,int*,int*,int*);
|
const char *,
|
||||||
|
const char *,
|
||||||
|
const char *,
|
||||||
|
char const **,
|
||||||
|
char const **,
|
||||||
|
int *,
|
||||||
|
int *,
|
||||||
|
int *);
|
||||||
void (*thread_cleanup)(void);
|
void (*thread_cleanup)(void);
|
||||||
int (*total_changes)(sqlite3 *);
|
int (*total_changes)(sqlite3 *);
|
||||||
void *(*trace)(sqlite3 *, void (*xTrace)(void *, const char *), void *);
|
void *(*trace)(sqlite3 *, void (*xTrace)(void *, const char *), void *);
|
||||||
int (*transfer_bindings)(sqlite3_stmt *, sqlite3_stmt *);
|
int (*transfer_bindings)(sqlite3_stmt *, sqlite3_stmt *);
|
||||||
void * (*update_hook)(sqlite3*,void(*)(void*,int ,char const*,char const*,
|
void *(*update_hook)(sqlite3 *, void (*)(void *, int, char const *, char const *, sqlite_int64), void *);
|
||||||
sqlite_int64),void*);
|
|
||||||
void *(*user_data)(sqlite3_context *);
|
void *(*user_data)(sqlite3_context *);
|
||||||
const void *(*value_blob)(sqlite3_value *);
|
const void *(*value_blob)(sqlite3_value *);
|
||||||
int (*value_bytes)(sqlite3_value *);
|
int (*value_bytes)(sqlite3_value *);
|
||||||
|
@ -165,17 +181,18 @@ struct sqlite3_api_routines {
|
||||||
int (*prepare16_v2)(sqlite3 *, const void *, int, sqlite3_stmt **, const void **);
|
int (*prepare16_v2)(sqlite3 *, const void *, int, sqlite3_stmt **, const void **);
|
||||||
int (*clear_bindings)(sqlite3_stmt *);
|
int (*clear_bindings)(sqlite3_stmt *);
|
||||||
/* Added by 3.4.1 */
|
/* Added by 3.4.1 */
|
||||||
int (*create_module_v2)(sqlite3*,const char*,const sqlite3_module*,void*,
|
int (*create_module_v2)(sqlite3 *, const char *, const sqlite3_module *, void *, void (*xDestroy)(void *));
|
||||||
void (*xDestroy)(void *));
|
|
||||||
/* Added by 3.5.0 */
|
/* Added by 3.5.0 */
|
||||||
int (*bind_zeroblob)(sqlite3_stmt *, int, int);
|
int (*bind_zeroblob)(sqlite3_stmt *, int, int);
|
||||||
int (*blob_bytes)(sqlite3_blob *);
|
int (*blob_bytes)(sqlite3_blob *);
|
||||||
int (*blob_close)(sqlite3_blob *);
|
int (*blob_close)(sqlite3_blob *);
|
||||||
int (*blob_open)(sqlite3*,const char*,const char*,const char*,sqlite3_int64,
|
int (*blob_open)(sqlite3 *, const char *, const char *, const char *, sqlite3_int64, int, sqlite3_blob **);
|
||||||
int,sqlite3_blob**);
|
|
||||||
int (*blob_read)(sqlite3_blob *, void *, int, int);
|
int (*blob_read)(sqlite3_blob *, void *, int, int);
|
||||||
int (*blob_write)(sqlite3_blob *, const void *, int, int);
|
int (*blob_write)(sqlite3_blob *, const void *, int, int);
|
||||||
int (*create_collation_v2)(sqlite3*,const char*,int,void*,
|
int (*create_collation_v2)(sqlite3 *,
|
||||||
|
const char *,
|
||||||
|
int,
|
||||||
|
void *,
|
||||||
int (*)(void *, int, const void *, int, const void *),
|
int (*)(void *, int, const void *, int, const void *),
|
||||||
void (*)(void *));
|
void (*)(void *));
|
||||||
int (*file_control)(sqlite3 *, const char *, int, void *);
|
int (*file_control)(sqlite3 *, const char *, int, void *);
|
||||||
|
@ -213,7 +230,11 @@ struct sqlite3_api_routines {
|
||||||
int (*backup_step)(sqlite3_backup *, int);
|
int (*backup_step)(sqlite3_backup *, int);
|
||||||
const char *(*compileoption_get)(int);
|
const char *(*compileoption_get)(int);
|
||||||
int (*compileoption_used)(const char *);
|
int (*compileoption_used)(const char *);
|
||||||
int (*create_function_v2)(sqlite3*,const char*,int,int,void*,
|
int (*create_function_v2)(sqlite3 *,
|
||||||
|
const char *,
|
||||||
|
int,
|
||||||
|
int,
|
||||||
|
void *,
|
||||||
void (*xFunc)(sqlite3_context *, int, sqlite3_value **),
|
void (*xFunc)(sqlite3_context *, int, sqlite3_value **),
|
||||||
void (*xStep)(sqlite3_context *, int, sqlite3_value **),
|
void (*xStep)(sqlite3_context *, int, sqlite3_value **),
|
||||||
void (*xFinal)(sqlite3_context *),
|
void (*xFinal)(sqlite3_context *),
|
||||||
|
@ -250,20 +271,16 @@ struct sqlite3_api_routines {
|
||||||
int (*wal_checkpoint_v2)(sqlite3 *, const char *, int, int *, int *);
|
int (*wal_checkpoint_v2)(sqlite3 *, const char *, int, int *, int *);
|
||||||
/* Version 3.8.7 and later */
|
/* Version 3.8.7 and later */
|
||||||
int (*auto_extension)(void (*)(void));
|
int (*auto_extension)(void (*)(void));
|
||||||
int (*bind_blob64)(sqlite3_stmt*,int,const void*,sqlite3_uint64,
|
int (*bind_blob64)(sqlite3_stmt *, int, const void *, sqlite3_uint64, void (*)(void *));
|
||||||
void(*)(void*));
|
int (*bind_text64)(sqlite3_stmt *, int, const char *, sqlite3_uint64, void (*)(void *), unsigned char);
|
||||||
int (*bind_text64)(sqlite3_stmt*,int,const char*,sqlite3_uint64,
|
|
||||||
void(*)(void*),unsigned char);
|
|
||||||
int (*cancel_auto_extension)(void (*)(void));
|
int (*cancel_auto_extension)(void (*)(void));
|
||||||
int (*load_extension)(sqlite3 *, const char *, const char *, char **);
|
int (*load_extension)(sqlite3 *, const char *, const char *, char **);
|
||||||
void *(*malloc64)(sqlite3_uint64);
|
void *(*malloc64)(sqlite3_uint64);
|
||||||
sqlite3_uint64 (*msize)(void *);
|
sqlite3_uint64 (*msize)(void *);
|
||||||
void *(*realloc64)(void *, sqlite3_uint64);
|
void *(*realloc64)(void *, sqlite3_uint64);
|
||||||
void (*reset_auto_extension)(void);
|
void (*reset_auto_extension)(void);
|
||||||
void (*result_blob64)(sqlite3_context*,const void*,sqlite3_uint64,
|
void (*result_blob64)(sqlite3_context *, const void *, sqlite3_uint64, void (*)(void *));
|
||||||
void(*)(void*));
|
void (*result_text64)(sqlite3_context *, const char *, sqlite3_uint64, void (*)(void *), unsigned char);
|
||||||
void (*result_text64)(sqlite3_context*,const char*,sqlite3_uint64,
|
|
||||||
void(*)(void*), unsigned char);
|
|
||||||
int (*strglob)(const char *, const char *);
|
int (*strglob)(const char *, const char *);
|
||||||
/* Version 3.8.11 and later */
|
/* Version 3.8.11 and later */
|
||||||
sqlite3_value *(*value_dup)(const sqlite3_value *);
|
sqlite3_value *(*value_dup)(const sqlite3_value *);
|
||||||
|
@ -285,10 +302,8 @@ struct sqlite3_api_routines {
|
||||||
/* Version 3.18.0 and later */
|
/* Version 3.18.0 and later */
|
||||||
void (*set_last_insert_rowid)(sqlite3 *, sqlite3_int64);
|
void (*set_last_insert_rowid)(sqlite3 *, sqlite3_int64);
|
||||||
/* Version 3.20.0 and later */
|
/* Version 3.20.0 and later */
|
||||||
int (*prepare_v3)(sqlite3*,const char*,int,unsigned int,
|
int (*prepare_v3)(sqlite3 *, const char *, int, unsigned int, sqlite3_stmt **, const char **);
|
||||||
sqlite3_stmt**,const char**);
|
int (*prepare16_v3)(sqlite3 *, const void *, int, unsigned int, sqlite3_stmt **, const void **);
|
||||||
int (*prepare16_v3)(sqlite3*,const void*,int,unsigned int,
|
|
||||||
sqlite3_stmt**,const void**);
|
|
||||||
int (*bind_pointer)(sqlite3_stmt *, int, void *, const char *, void (*)(void *));
|
int (*bind_pointer)(sqlite3_stmt *, int, void *, const char *, void (*)(void *));
|
||||||
void (*result_pointer)(sqlite3_context *, void *, const char *, void (*)(void *));
|
void (*result_pointer)(sqlite3_context *, void *, const char *, void (*)(void *));
|
||||||
void *(*value_pointer)(sqlite3_value *, const char *);
|
void *(*value_pointer)(sqlite3_value *, const char *);
|
||||||
|
@ -311,7 +326,11 @@ struct sqlite3_api_routines {
|
||||||
int (*str_length)(sqlite3_str *);
|
int (*str_length)(sqlite3_str *);
|
||||||
char *(*str_value)(sqlite3_str *);
|
char *(*str_value)(sqlite3_str *);
|
||||||
/* Version 3.25.0 and later */
|
/* Version 3.25.0 and later */
|
||||||
int (*create_window_function)(sqlite3*,const char*,int,int,void*,
|
int (*create_window_function)(sqlite3 *,
|
||||||
|
const char *,
|
||||||
|
int,
|
||||||
|
int,
|
||||||
|
void *,
|
||||||
void (*xStep)(sqlite3_context *, int, sqlite3_value **),
|
void (*xStep)(sqlite3_context *, int, sqlite3_value **),
|
||||||
void (*xFinal)(sqlite3_context *),
|
void (*xFinal)(sqlite3_context *),
|
||||||
void (*xValue)(sqlite3_context *),
|
void (*xValue)(sqlite3_context *),
|
||||||
|
@ -331,8 +350,7 @@ struct sqlite3_api_routines {
|
||||||
const char *(*filename_journal)(const char *);
|
const char *(*filename_journal)(const char *);
|
||||||
const char *(*filename_wal)(const char *);
|
const char *(*filename_wal)(const char *);
|
||||||
/* Version 3.32.0 and later */
|
/* Version 3.32.0 and later */
|
||||||
char *(*create_filename)(const char*,const char*,const char*,
|
char *(*create_filename)(const char *, const char *, const char *, int, const char **);
|
||||||
int,const char**);
|
|
||||||
void (*free_filename)(char *);
|
void (*free_filename)(char *);
|
||||||
sqlite3_file *(*database_file_object)(const char *);
|
sqlite3_file *(*database_file_object)(const char *);
|
||||||
/* Version 3.34.0 and later */
|
/* Version 3.34.0 and later */
|
||||||
|
@ -343,7 +361,8 @@ struct sqlite3_api_routines {
|
||||||
/* Version 3.37.0 and later */
|
/* Version 3.37.0 and later */
|
||||||
int (*autovacuum_pages)(sqlite3 *,
|
int (*autovacuum_pages)(sqlite3 *,
|
||||||
unsigned int (*)(void *, const char *, unsigned int, unsigned int, unsigned int),
|
unsigned int (*)(void *, const char *, unsigned int, unsigned int, unsigned int),
|
||||||
void*, void(*)(void*));
|
void *,
|
||||||
|
void (*)(void *));
|
||||||
/* Version 3.38.0 and later */
|
/* Version 3.38.0 and later */
|
||||||
int (*error_offset)(sqlite3 *);
|
int (*error_offset)(sqlite3 *);
|
||||||
int (*vtab_rhs_value)(sqlite3_index_info *, int, sqlite3_value **);
|
int (*vtab_rhs_value)(sqlite3_index_info *, int, sqlite3_value **);
|
||||||
|
@ -352,10 +371,8 @@ struct sqlite3_api_routines {
|
||||||
int (*vtab_in_first)(sqlite3_value *, sqlite3_value **);
|
int (*vtab_in_first)(sqlite3_value *, sqlite3_value **);
|
||||||
int (*vtab_in_next)(sqlite3_value *, sqlite3_value **);
|
int (*vtab_in_next)(sqlite3_value *, sqlite3_value **);
|
||||||
/* Version 3.39.0 and later */
|
/* Version 3.39.0 and later */
|
||||||
int (*deserialize)(sqlite3*,const char*,unsigned char*,
|
int (*deserialize)(sqlite3 *, const char *, unsigned char *, sqlite3_int64, sqlite3_int64, unsigned);
|
||||||
sqlite3_int64,sqlite3_int64,unsigned);
|
unsigned char *(*serialize)(sqlite3 *, const char *, sqlite3_int64 *, unsigned int);
|
||||||
unsigned char *(*serialize)(sqlite3*,const char *,sqlite3_int64*,
|
|
||||||
unsigned int);
|
|
||||||
const char *(*db_name)(sqlite3 *, int);
|
const char *(*db_name)(sqlite3 *, int);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -363,8 +380,7 @@ struct sqlite3_api_routines {
|
||||||
** This is the function signature used for all extension entry points. It
|
** This is the function signature used for all extension entry points. It
|
||||||
** is also defined in the file "loadext.c".
|
** is also defined in the file "loadext.c".
|
||||||
*/
|
*/
|
||||||
typedef int (*sqlite3_loadext_entry)(
|
typedef int (*sqlite3_loadext_entry)(sqlite3 *db, /* Handle to the sqlitecipher. */
|
||||||
sqlite3 *db, /* Handle to the sqlitecipher. */
|
|
||||||
char **pzErrMsg, /* Used to set error string on failure. */
|
char **pzErrMsg, /* Used to set error string on failure. */
|
||||||
const sqlite3_api_routines *pThunk /* Extension API function pointers. */
|
const sqlite3_api_routines *pThunk /* Extension API function pointers. */
|
||||||
);
|
);
|
||||||
|
@ -688,8 +704,7 @@ typedef int (*sqlite3_loadext_entry)(
|
||||||
** extension */
|
** extension */
|
||||||
#define SQLITE_EXTENSION_INIT1 const sqlite3_api_routines *sqlite3_api = 0;
|
#define SQLITE_EXTENSION_INIT1 const sqlite3_api_routines *sqlite3_api = 0;
|
||||||
#define SQLITE_EXTENSION_INIT2(v) sqlite3_api = v;
|
#define SQLITE_EXTENSION_INIT2(v) sqlite3_api = v;
|
||||||
# define SQLITE_EXTENSION_INIT3 \
|
#define SQLITE_EXTENSION_INIT3 extern const sqlite3_api_routines *sqlite3_api;
|
||||||
extern const sqlite3_api_routines *sqlite3_api;
|
|
||||||
#else
|
#else
|
||||||
/* This case when the file is being statically linked into the
|
/* This case when the file is being statically linked into the
|
||||||
** application */
|
** application */
|
||||||
|
|
|
@ -221,9 +221,8 @@ typedef struct {
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
if ((a)->i > ((pos) + (len))) { \
|
if ((a)->i > ((pos) + (len))) { \
|
||||||
memmove(_utarray_eltptr(a, pos), \
|
memmove( \
|
||||||
_utarray_eltptr(a, (pos) + (len)), \
|
_utarray_eltptr(a, pos), _utarray_eltptr(a, (pos) + (len)), ((a)->i - ((pos) + (len))) * (a)->icd.sz); \
|
||||||
((a)->i - ((pos) + (len))) * (a)->icd.sz); \
|
|
||||||
} \
|
} \
|
||||||
(a)->i -= (len); \
|
(a)->i -= (len); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
@ -274,9 +273,10 @@ static void utarray_str_cpy(void *dst, const void *src) {
|
||||||
}
|
}
|
||||||
static void utarray_str_dtor(void *elt) {
|
static void utarray_str_dtor(void *elt) {
|
||||||
char **eltc = (char **)elt;
|
char **eltc = (char **)elt;
|
||||||
if (*eltc != NULL)
|
if (*eltc != NULL) {
|
||||||
free(*eltc);
|
free(*eltc);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
static const UT_icd ut_str_icd UTARRAY_UNUSED = {sizeof(char *), NULL, utarray_str_cpy, utarray_str_dtor};
|
static const UT_icd ut_str_icd UTARRAY_UNUSED = {sizeof(char *), NULL, utarray_str_cpy, utarray_str_dtor};
|
||||||
static const UT_icd ut_int_icd UTARRAY_UNUSED = {sizeof(int), NULL, NULL, NULL};
|
static const UT_icd ut_int_icd UTARRAY_UNUSED = {sizeof(int), NULL, NULL, NULL};
|
||||||
static const UT_icd ut_ptr_icd UTARRAY_UNUSED = {sizeof(void *), NULL, NULL, NULL};
|
static const UT_icd ut_ptr_icd UTARRAY_UNUSED = {sizeof(void *), NULL, NULL, NULL};
|
||||||
|
|
|
@ -226,8 +226,8 @@ typedef unsigned char uint8_t;
|
||||||
(head)->hh.tbl->num_buckets = HASH_INITIAL_NUM_BUCKETS; \
|
(head)->hh.tbl->num_buckets = HASH_INITIAL_NUM_BUCKETS; \
|
||||||
(head)->hh.tbl->log2_num_buckets = HASH_INITIAL_NUM_BUCKETS_LOG2; \
|
(head)->hh.tbl->log2_num_buckets = HASH_INITIAL_NUM_BUCKETS_LOG2; \
|
||||||
(head)->hh.tbl->hho = (char *)(&(head)->hh) - (char *)(head); \
|
(head)->hh.tbl->hho = (char *)(&(head)->hh) - (char *)(head); \
|
||||||
(head)->hh.tbl->buckets = \
|
(head)->hh.tbl->buckets = (UT_hash_bucket *)uthash_malloc(HASH_INITIAL_NUM_BUCKETS \
|
||||||
(UT_hash_bucket *)uthash_malloc(HASH_INITIAL_NUM_BUCKETS * sizeof(struct UT_hash_bucket)); \
|
* sizeof(struct UT_hash_bucket)); \
|
||||||
(head)->hh.tbl->signature = HASH_SIGNATURE; \
|
(head)->hh.tbl->signature = HASH_SIGNATURE; \
|
||||||
if (!(head)->hh.tbl->buckets) { \
|
if (!(head)->hh.tbl->buckets) { \
|
||||||
HASH_RECORD_OOM(oomed); \
|
HASH_RECORD_OOM(oomed); \
|
||||||
|
@ -523,10 +523,8 @@ typedef unsigned char uint8_t;
|
||||||
_prev = NULL; \
|
_prev = NULL; \
|
||||||
while (_thh) { \
|
while (_thh) { \
|
||||||
if (_prev != (char *)(_thh->hh_prev)) { \
|
if (_prev != (char *)(_thh->hh_prev)) { \
|
||||||
HASH_OOPS("%s: invalid hh_prev %p, actual %p\n", \
|
HASH_OOPS( \
|
||||||
(where), \
|
"%s: invalid hh_prev %p, actual %p\n", (where), (void *)_thh->hh_prev, (void *)_prev); \
|
||||||
(void *)_thh->hh_prev, \
|
|
||||||
(void *)_prev); \
|
|
||||||
} \
|
} \
|
||||||
_bkt_count++; \
|
_bkt_count++; \
|
||||||
_prev = (char *)(_thh); \
|
_prev = (char *)(_thh); \
|
||||||
|
@ -888,8 +886,8 @@ typedef unsigned char uint8_t;
|
||||||
(tbl)->num_buckets *= 2U; \
|
(tbl)->num_buckets *= 2U; \
|
||||||
(tbl)->log2_num_buckets++; \
|
(tbl)->log2_num_buckets++; \
|
||||||
(tbl)->buckets = _he_new_buckets; \
|
(tbl)->buckets = _he_new_buckets; \
|
||||||
(tbl)->ineff_expands = \
|
(tbl)->ineff_expands = ((tbl)->nonideal_items > ((tbl)->num_items >> 1)) ? ((tbl)->ineff_expands + 1U) \
|
||||||
((tbl)->nonideal_items > ((tbl)->num_items >> 1)) ? ((tbl)->ineff_expands + 1U) : 0U; \
|
: 0U; \
|
||||||
if ((tbl)->ineff_expands > 1U) { \
|
if ((tbl)->ineff_expands > 1U) { \
|
||||||
(tbl)->noexpand = 1; \
|
(tbl)->noexpand = 1; \
|
||||||
uthash_noexpand_fyi(tbl); \
|
uthash_noexpand_fyi(tbl); \
|
||||||
|
|
|
@ -152,12 +152,13 @@ UTSTRING_UNUSED static void utstring_printf_va(UT_string *s, const char *fmt, va
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Else try again with more space. */
|
/* Else try again with more space. */
|
||||||
if (n > -1)
|
if (n > -1) {
|
||||||
utstring_reserve(s, n + 1); /* exact */
|
utstring_reserve(s, n + 1); /* exact */
|
||||||
else
|
} else {
|
||||||
utstring_reserve(s, (s->n) * 2); /* 2x */
|
utstring_reserve(s, (s->n) * 2); /* 2x */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
#ifdef __GNUC__
|
#ifdef __GNUC__
|
||||||
/* support printf format checking (2=the format string, 3=start of varargs) */
|
/* support printf format checking (2=the format string, 3=start of varargs) */
|
||||||
static void utstring_printf(UT_string *s, const char *fmt, ...) __attribute__((format(printf, 2, 3)));
|
static void utstring_printf(UT_string *s, const char *fmt, ...) __attribute__((format(printf, 2, 3)));
|
||||||
|
@ -227,8 +228,11 @@ UTSTRING_UNUSED static void _utstring_BuildTableR(const char *P_Needle, size_t P
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Search data from left to right. ( Multiple search mode. ) */
|
/* Search data from left to right. ( Multiple search mode. ) */
|
||||||
UTSTRING_UNUSED static long _utstring_find(const char *P_Haystack, size_t P_HaystackLen, const char *P_Needle,
|
UTSTRING_UNUSED static long _utstring_find(const char *P_Haystack,
|
||||||
size_t P_NeedleLen, long *P_KMP_Table) {
|
size_t P_HaystackLen,
|
||||||
|
const char *P_Needle,
|
||||||
|
size_t P_NeedleLen,
|
||||||
|
long *P_KMP_Table) {
|
||||||
long i, j;
|
long i, j;
|
||||||
long V_FindPosition = -1;
|
long V_FindPosition = -1;
|
||||||
|
|
||||||
|
@ -251,8 +255,11 @@ UTSTRING_UNUSED static long _utstring_find(const char *P_Haystack, size_t P_Hays
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Search data from right to left. ( Multiple search mode. ) */
|
/* Search data from right to left. ( Multiple search mode. ) */
|
||||||
UTSTRING_UNUSED static long _utstring_findR(const char *P_Haystack, size_t P_HaystackLen, const char *P_Needle,
|
UTSTRING_UNUSED static long _utstring_findR(const char *P_Haystack,
|
||||||
size_t P_NeedleLen, long *P_KMP_Table) {
|
size_t P_HaystackLen,
|
||||||
|
const char *P_Needle,
|
||||||
|
size_t P_NeedleLen,
|
||||||
|
long *P_KMP_Table) {
|
||||||
long i, j;
|
long i, j;
|
||||||
long V_FindPosition = -1;
|
long V_FindPosition = -1;
|
||||||
|
|
||||||
|
@ -278,7 +285,8 @@ UTSTRING_UNUSED static long _utstring_findR(const char *P_Haystack, size_t P_Hay
|
||||||
/* Search data from left to right. ( One time search mode. ) */
|
/* Search data from left to right. ( One time search mode. ) */
|
||||||
UTSTRING_UNUSED static long utstring_find(UT_string *s,
|
UTSTRING_UNUSED static long utstring_find(UT_string *s,
|
||||||
long P_StartPosition, /* Start from 0. -1 means last position. */
|
long P_StartPosition, /* Start from 0. -1 means last position. */
|
||||||
const char *P_Needle, size_t P_NeedleLen) {
|
const char *P_Needle,
|
||||||
|
size_t P_NeedleLen) {
|
||||||
long V_StartPosition;
|
long V_StartPosition;
|
||||||
long V_HaystackLen;
|
long V_HaystackLen;
|
||||||
long *V_KMP_Table;
|
long *V_KMP_Table;
|
||||||
|
@ -310,7 +318,8 @@ UTSTRING_UNUSED static long utstring_find(UT_string *s,
|
||||||
/* Search data from right to left. ( One time search mode. ) */
|
/* Search data from right to left. ( One time search mode. ) */
|
||||||
UTSTRING_UNUSED static long utstring_findR(UT_string *s,
|
UTSTRING_UNUSED static long utstring_findR(UT_string *s,
|
||||||
long P_StartPosition, /* Start from 0. -1 means last position. */
|
long P_StartPosition, /* Start from 0. -1 means last position. */
|
||||||
const char *P_Needle, size_t P_NeedleLen) {
|
const char *P_Needle,
|
||||||
|
size_t P_NeedleLen) {
|
||||||
long V_StartPosition;
|
long V_StartPosition;
|
||||||
long V_HaystackLen;
|
long V_HaystackLen;
|
||||||
long *V_KMP_Table;
|
long *V_KMP_Table;
|
||||||
|
|
|
@ -55,7 +55,8 @@ enum ZVECT_PROPERTIES {
|
||||||
ZV_NONE = 0, // Sets or Resets all vector's properties to 0.
|
ZV_NONE = 0, // Sets or Resets all vector's properties to 0.
|
||||||
ZV_SEC_WIPE = 1 << 0, // Sets the vector for automatic Secure Wipe of items.
|
ZV_SEC_WIPE = 1 << 0, // Sets the vector for automatic Secure Wipe of items.
|
||||||
ZV_BYREF = 1 << 1, // Sets the vector to store items by reference instead of copying them as per default.
|
ZV_BYREF = 1 << 1, // Sets the vector to store items by reference instead of copying them as per default.
|
||||||
ZV_CIRCULAR = 1 << 2, // Sets the vector to be a circular vector (so it will not grow in capacity automatically). Elements will be overwritten as in typical circular buffers!
|
ZV_CIRCULAR = 1
|
||||||
|
<< 2, // Sets the vector to be a circular vector (so it will not grow in capacity automatically). Elements will be overwritten as in typical circular buffers!
|
||||||
ZV_NOLOCKING = 1 << 3, // This Property means the vector will not use mutexes, be careful using it!
|
ZV_NOLOCKING = 1 << 3, // This Property means the vector will not use mutexes, be careful using it!
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -201,7 +202,8 @@ zvect_retval vect_unlock(vector const v);
|
||||||
* zvect_retval vect_lock_after_signal(const vector v);
|
* zvect_retval vect_lock_after_signal(const vector v);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
zvect_retval vect_move_on_signal(vector const v1, vector v2,
|
zvect_retval vect_move_on_signal(vector const v1,
|
||||||
|
vector v2,
|
||||||
const zvect_index s2,
|
const zvect_index s2,
|
||||||
const zvect_index e2,
|
const zvect_index e2,
|
||||||
zvect_retval (*f2)(void *, void *));
|
zvect_retval (*f2)(void *, void *));
|
||||||
|
@ -591,8 +593,7 @@ void vect_copy(vector const v1, vector const v2, zvect_index start, zvect_index
|
||||||
* you'll have such items "inserted"
|
* you'll have such items "inserted"
|
||||||
* inside v1.
|
* inside v1.
|
||||||
*/
|
*/
|
||||||
void vect_insert(vector const v1, vector const v2, const zvect_index s2,
|
void vect_insert(vector const v1, vector const v2, const zvect_index s2, const zvect_index e2, const zvect_index s1);
|
||||||
const zvect_index e2, const zvect_index s1);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* vect_move is a function that allows to move a specified
|
* vect_move is a function that allows to move a specified
|
||||||
|
@ -623,8 +624,11 @@ void vect_move(vector const v1, vector const v2, zvect_index start, zvect_index
|
||||||
* the end of v1 if check_data returns
|
* the end of v1 if check_data returns
|
||||||
* true.
|
* true.
|
||||||
*/
|
*/
|
||||||
zvect_retval vect_move_if(vector const v1, vector v2, const zvect_index s2,
|
zvect_retval vect_move_if(vector const v1,
|
||||||
const zvect_index e2, zvect_retval (*f2)(void *, void *));
|
vector v2,
|
||||||
|
const zvect_index s2,
|
||||||
|
const zvect_index e2,
|
||||||
|
zvect_retval (*f2)(void *, void *));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* vect_merge is a function that merges together 2 vectors of
|
* vect_merge is a function that merges together 2 vectors of
|
||||||
|
|
|
@ -20,8 +20,7 @@
|
||||||
#define macOS
|
#define macOS
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if ( defined(__GNU__) || defined(__gnu_linux__) || \
|
#if (defined(__GNU__) || defined(__gnu_linux__) || defined(__linux__) || defined(macOS))
|
||||||
defined(__linux__) || defined(macOS) )
|
|
||||||
#define OS_TYPE 1
|
#define OS_TYPE 1
|
||||||
#elif (defined(__WIN32__) || defined(WIN32) || defined(_WIN32))
|
#elif (defined(__WIN32__) || defined(WIN32) || defined(_WIN32))
|
||||||
#define OS_TYPE 2
|
#define OS_TYPE 2
|
||||||
|
@ -48,8 +47,7 @@
|
||||||
#define COMP_MAJRELEASE (__clang_major__)
|
#define COMP_MAJRELEASE (__clang_major__)
|
||||||
#define COMP_MINRELEASE (__clang_minor__)
|
#define COMP_MINRELEASE (__clang_minor__)
|
||||||
#define COMP_PATRELEASE (__clang_patchlevel__)
|
#define COMP_PATRELEASE (__clang_patchlevel__)
|
||||||
#elif defined(__INTEL_COMPILER) || defined(__ICC) || \
|
#elif defined(__INTEL_COMPILER) || defined(__ICC) || defined(__ECC) || defined(__ICL)
|
||||||
defined(__ECC) || defined(__ICL)
|
|
||||||
// For intel c compiler please remember to specify:
|
// For intel c compiler please remember to specify:
|
||||||
// /Qstd=c99 (on Windows)
|
// /Qstd=c99 (on Windows)
|
||||||
// -std=c99 on Linux and/or macOS
|
// -std=c99 on Linux and/or macOS
|
||||||
|
@ -64,8 +62,7 @@
|
||||||
#define COMP_MAJRELEASE (__LCC)
|
#define COMP_MAJRELEASE (__LCC)
|
||||||
#define COMP_MINRELEASE 0
|
#define COMP_MINRELEASE 0
|
||||||
#define COMP_PATRELEASE 0
|
#define COMP_PATRELEASE 0
|
||||||
#elif defined(__NORCROFT_C__) || defined(__CC_NORCROFT) || \
|
#elif defined(__NORCROFT_C__) || defined(__CC_NORCROFT) || defined(__ARMCC_VERSION)
|
||||||
defined(__ARMCC_VERSION)
|
|
||||||
// For Norcroft C please remember to specify:
|
// For Norcroft C please remember to specify:
|
||||||
// -c99
|
// -c99
|
||||||
#define compiler norcroftc
|
#define compiler norcroftc
|
||||||
|
@ -110,9 +107,8 @@
|
||||||
#elif defined(__aarch32__)
|
#elif defined(__aarch32__)
|
||||||
#define CPU_TYPE ARM32
|
#define CPU_TYPE ARM32
|
||||||
#define Arch32
|
#define Arch32
|
||||||
#elif defined(__amd64__) || defined(__x86_64__) || \
|
#elif defined(__amd64__) || defined(__x86_64__) || defined(__ia64__) || defined(_M_IA64) || defined(_M_AMD64) \
|
||||||
defined(__ia64__) || defined(_M_IA64) || \
|
|| defined(_M_X64)
|
||||||
defined(_M_AMD64) || defined(_M_X64)
|
|
||||||
#define CPU_TYPE x86_64
|
#define CPU_TYPE x86_64
|
||||||
#define Arch64
|
#define Arch64
|
||||||
#else
|
#else
|
||||||
|
@ -126,12 +122,10 @@
|
||||||
#if (OS_TYPE == 1)
|
#if (OS_TYPE == 1)
|
||||||
// We are on a Unix-like OS so we can use pthreads!
|
// We are on a Unix-like OS so we can use pthreads!
|
||||||
#define MUTEX_TYPE 1
|
#define MUTEX_TYPE 1
|
||||||
# elif ( OS_TYPE == 2 ) && ( defined(__CYGWIN__) || \
|
#elif (OS_TYPE == 2) && (defined(__CYGWIN__) || defined(__MINGW32__) || defined(__MINGW64__))
|
||||||
defined(__MINGW32__) || defined(__MINGW64__) )
|
|
||||||
// We are on MS Windows using CIGWIN so we can use pthreads!
|
// We are on MS Windows using CIGWIN so we can use pthreads!
|
||||||
#define MUTEX_TYPE 1
|
#define MUTEX_TYPE 1
|
||||||
# elif ( OS_TYPE == 2 ) && ( !defined(__CYGWIN__) && \
|
#elif (OS_TYPE == 2) && (!defined(__CYGWIN__) && !defined(__MINGW32__) && !defined(__MINGW64__))
|
||||||
!defined(__MINGW32__) && !defined(__MINGW64__) )
|
|
||||||
// We are on MS Windows, so we need to use
|
// We are on MS Windows, so we need to use
|
||||||
// Windows stuff:
|
// Windows stuff:
|
||||||
#define MUTEX_TYPE 2
|
#define MUTEX_TYPE 2
|
||||||
|
|
|
@ -36,7 +36,8 @@
|
||||||
// If you want a larger index you can
|
// If you want a larger index you can
|
||||||
// change it to, for example, uint64_t
|
// change it to, for example, uint64_t
|
||||||
typedef uint32_t zvect_index;
|
typedef uint32_t zvect_index;
|
||||||
#define zvect_index_max 4294967295 // If you change zvect_index type make sure you update this value
|
#define zvect_index_max \
|
||||||
|
4294967295 // If you change zvect_index type make sure you update this value \
|
||||||
// it's the maximum number that can be stored in a zvect_index.
|
// it's the maximum number that can be stored in a zvect_index.
|
||||||
|
|
||||||
// Default vector return type for
|
// Default vector return type for
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -183,7 +183,10 @@ int str_to_ipaddr(const char *pIp, unsigned int *ipAddr) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int get_nic_info(const char *pName, unsigned int *pIp, unsigned int *pNetmask, unsigned int *pGateway,
|
int get_nic_info(const char *pName,
|
||||||
|
unsigned int *pIp,
|
||||||
|
unsigned int *pNetmask,
|
||||||
|
unsigned int *pGateway,
|
||||||
unsigned char *pMac) {
|
unsigned char *pMac) {
|
||||||
int sock;
|
int sock;
|
||||||
struct ifreq ifr;
|
struct ifreq ifr;
|
||||||
|
|
|
@ -84,14 +84,18 @@ static inline int sdsHdrSize(char type) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline char sdsReqType(size_t string_size) {
|
static inline char sdsReqType(size_t string_size) {
|
||||||
if (string_size < 32)
|
if (string_size < 32) {
|
||||||
return SDS_TYPE_5;
|
return SDS_TYPE_5;
|
||||||
if (string_size < 0xff)
|
}
|
||||||
|
if (string_size < 0xff) {
|
||||||
return SDS_TYPE_8;
|
return SDS_TYPE_8;
|
||||||
if (string_size < 0xffff)
|
}
|
||||||
|
if (string_size < 0xffff) {
|
||||||
return SDS_TYPE_16;
|
return SDS_TYPE_16;
|
||||||
if (string_size < 0xffffffff)
|
}
|
||||||
|
if (string_size < 0xffffffff) {
|
||||||
return SDS_TYPE_32;
|
return SDS_TYPE_32;
|
||||||
|
}
|
||||||
return SDS_TYPE_64;
|
return SDS_TYPE_64;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,14 +117,19 @@ sds sdsnewlen(const void *init, size_t initlen) {
|
||||||
char type = sdsReqType(initlen);
|
char type = sdsReqType(initlen);
|
||||||
/* Empty strings are usually created in order to append. Use type 8
|
/* Empty strings are usually created in order to append. Use type 8
|
||||||
* since type 5 is not good at this. */
|
* since type 5 is not good at this. */
|
||||||
if (type == SDS_TYPE_5 && initlen == 0) type = SDS_TYPE_8;
|
if (type == SDS_TYPE_5 && initlen == 0) {
|
||||||
|
type = SDS_TYPE_8;
|
||||||
|
}
|
||||||
int hdrlen = sdsHdrSize(type);
|
int hdrlen = sdsHdrSize(type);
|
||||||
unsigned char *fp; /* flags pointer. */
|
unsigned char *fp; /* flags pointer. */
|
||||||
|
|
||||||
sh = s_malloc(hdrlen + initlen + 1);
|
sh = s_malloc(hdrlen + initlen + 1);
|
||||||
if (sh == NULL) return NULL;
|
if (sh == NULL) {
|
||||||
if (!init)
|
return NULL;
|
||||||
|
}
|
||||||
|
if (!init) {
|
||||||
memset(sh, 0, hdrlen + initlen + 1);
|
memset(sh, 0, hdrlen + initlen + 1);
|
||||||
|
}
|
||||||
s = (char *)sh + hdrlen;
|
s = (char *)sh + hdrlen;
|
||||||
fp = ((unsigned char *)s) - 1;
|
fp = ((unsigned char *)s) - 1;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
|
@ -157,8 +166,9 @@ sds sdsnewlen(const void *init, size_t initlen) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (initlen && init)
|
if (initlen && init) {
|
||||||
memcpy(s, init, initlen);
|
memcpy(s, init, initlen);
|
||||||
|
}
|
||||||
s[initlen] = '\0';
|
s[initlen] = '\0';
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
@ -182,7 +192,9 @@ sds sdsdup(const sds s) {
|
||||||
|
|
||||||
/* Free an sds string. No operation is performed if 's' is NULL. */
|
/* Free an sds string. No operation is performed if 's' is NULL. */
|
||||||
void sdsfree(sds s) {
|
void sdsfree(sds s) {
|
||||||
if (s == NULL) return;
|
if (s == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
s_free((char *)s - sdsHdrSize(s[-1]));
|
s_free((char *)s - sdsHdrSize(s[-1]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -228,33 +240,42 @@ sds sdsMakeRoomFor(sds s, size_t addlen) {
|
||||||
int hdrlen;
|
int hdrlen;
|
||||||
|
|
||||||
/* Return ASAP if there is enough space left. */
|
/* Return ASAP if there is enough space left. */
|
||||||
if (avail >= addlen) return s;
|
if (avail >= addlen) {
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
len = sdslen(s);
|
len = sdslen(s);
|
||||||
sh = (char *)s - sdsHdrSize(oldtype);
|
sh = (char *)s - sdsHdrSize(oldtype);
|
||||||
newlen = (len + addlen);
|
newlen = (len + addlen);
|
||||||
if (newlen < SDS_MAX_PREALLOC)
|
if (newlen < SDS_MAX_PREALLOC) {
|
||||||
newlen *= 2;
|
newlen *= 2;
|
||||||
else
|
} else {
|
||||||
newlen += SDS_MAX_PREALLOC;
|
newlen += SDS_MAX_PREALLOC;
|
||||||
|
}
|
||||||
|
|
||||||
type = sdsReqType(newlen);
|
type = sdsReqType(newlen);
|
||||||
|
|
||||||
/* Don't use type 5: the user is appending to the string and type 5 is
|
/* Don't use type 5: the user is appending to the string and type 5 is
|
||||||
* not able to remember empty space, so sdsMakeRoomFor() must be called
|
* not able to remember empty space, so sdsMakeRoomFor() must be called
|
||||||
* at every appending operation. */
|
* at every appending operation. */
|
||||||
if (type == SDS_TYPE_5) type = SDS_TYPE_8;
|
if (type == SDS_TYPE_5) {
|
||||||
|
type = SDS_TYPE_8;
|
||||||
|
}
|
||||||
|
|
||||||
hdrlen = sdsHdrSize(type);
|
hdrlen = sdsHdrSize(type);
|
||||||
if (oldtype == type) {
|
if (oldtype == type) {
|
||||||
newsh = s_realloc(sh, hdrlen + newlen + 1);
|
newsh = s_realloc(sh, hdrlen + newlen + 1);
|
||||||
if (newsh == NULL) return NULL;
|
if (newsh == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
s = (char *)newsh + hdrlen;
|
s = (char *)newsh + hdrlen;
|
||||||
} else {
|
} else {
|
||||||
/* Since the header size changes, need to move the string forward,
|
/* Since the header size changes, need to move the string forward,
|
||||||
* and can't use realloc */
|
* and can't use realloc */
|
||||||
newsh = s_malloc(hdrlen + newlen + 1);
|
newsh = s_malloc(hdrlen + newlen + 1);
|
||||||
if (newsh == NULL) return NULL;
|
if (newsh == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
memcpy((char *)newsh + hdrlen, s, len + 1);
|
memcpy((char *)newsh + hdrlen, s, len + 1);
|
||||||
s_free(sh);
|
s_free(sh);
|
||||||
s = (char *)newsh + hdrlen;
|
s = (char *)newsh + hdrlen;
|
||||||
|
@ -282,11 +303,15 @@ sds sdsRemoveFreeSpace(sds s) {
|
||||||
hdrlen = sdsHdrSize(type);
|
hdrlen = sdsHdrSize(type);
|
||||||
if (oldtype == type) {
|
if (oldtype == type) {
|
||||||
newsh = s_realloc(sh, hdrlen + len + 1);
|
newsh = s_realloc(sh, hdrlen + len + 1);
|
||||||
if (newsh == NULL) return NULL;
|
if (newsh == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
s = (char *)newsh + hdrlen;
|
s = (char *)newsh + hdrlen;
|
||||||
} else {
|
} else {
|
||||||
newsh = s_malloc(hdrlen + len + 1);
|
newsh = s_malloc(hdrlen + len + 1);
|
||||||
if (newsh == NULL) return NULL;
|
if (newsh == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
memcpy((char *)newsh + hdrlen, s, len + 1);
|
memcpy((char *)newsh + hdrlen, s, len + 1);
|
||||||
s_free(sh);
|
s_free(sh);
|
||||||
s = (char *)newsh + hdrlen;
|
s = (char *)newsh + hdrlen;
|
||||||
|
@ -364,7 +389,8 @@ void sdsIncrLen(sds s, int incr) {
|
||||||
}
|
}
|
||||||
case SDS_TYPE_32: {
|
case SDS_TYPE_32: {
|
||||||
SDS_HDR_VAR(32, s);
|
SDS_HDR_VAR(32, s);
|
||||||
assert((incr >= 0 && sh->alloc-sh->len >= (unsigned int)incr) || (incr < 0 && sh->len >= (unsigned int)(-incr)));
|
assert((incr >= 0 && sh->alloc - sh->len >= (unsigned int)incr)
|
||||||
|
|| (incr < 0 && sh->len >= (unsigned int)(-incr)));
|
||||||
len = (sh->len += incr);
|
len = (sh->len += incr);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -374,7 +400,8 @@ void sdsIncrLen(sds s, int incr) {
|
||||||
len = (sh->len += incr);
|
len = (sh->len += incr);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: len = 0; /* Just to avoid compilation warnings. */
|
default:
|
||||||
|
len = 0; /* Just to avoid compilation warnings. */
|
||||||
}
|
}
|
||||||
s[len] = '\0';
|
s[len] = '\0';
|
||||||
}
|
}
|
||||||
|
@ -387,9 +414,13 @@ void sdsIncrLen(sds s, int incr) {
|
||||||
sds sdsgrowzero(sds s, size_t len) {
|
sds sdsgrowzero(sds s, size_t len) {
|
||||||
size_t curlen = sdslen(s);
|
size_t curlen = sdslen(s);
|
||||||
|
|
||||||
if (len <= curlen) return s;
|
if (len <= curlen) {
|
||||||
|
return s;
|
||||||
|
}
|
||||||
s = sdsMakeRoomFor(s, len - curlen);
|
s = sdsMakeRoomFor(s, len - curlen);
|
||||||
if (s == NULL) return NULL;
|
if (s == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/* Make sure added region doesn't contain garbage */
|
/* Make sure added region doesn't contain garbage */
|
||||||
memset(s + curlen, 0, (len - curlen + 1)); /* also set trailing \0 byte */
|
memset(s + curlen, 0, (len - curlen + 1)); /* also set trailing \0 byte */
|
||||||
|
@ -406,7 +437,9 @@ sds sdscatlen(sds s, const void *t, size_t len) {
|
||||||
size_t curlen = sdslen(s);
|
size_t curlen = sdslen(s);
|
||||||
|
|
||||||
s = sdsMakeRoomFor(s, len);
|
s = sdsMakeRoomFor(s, len);
|
||||||
if (s == NULL) return NULL;
|
if (s == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
memcpy(s + curlen, t, len);
|
memcpy(s + curlen, t, len);
|
||||||
sdssetlen(s, curlen + len);
|
sdssetlen(s, curlen + len);
|
||||||
s[curlen + len] = '\0';
|
s[curlen + len] = '\0';
|
||||||
|
@ -434,7 +467,9 @@ sds sdscatsds(sds s, const sds t) {
|
||||||
sds sdscpylen(sds s, const char *t, size_t len) {
|
sds sdscpylen(sds s, const char *t, size_t len) {
|
||||||
if (sdsalloc(s) < len) {
|
if (sdsalloc(s) < len) {
|
||||||
s = sdsMakeRoomFor(s, len - sdslen(s));
|
s = sdsMakeRoomFor(s, len - sdslen(s));
|
||||||
if (s == NULL) return NULL;
|
if (s == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
memcpy(s, t, len);
|
memcpy(s, t, len);
|
||||||
s[len] = '\0';
|
s[len] = '\0';
|
||||||
|
@ -468,7 +503,9 @@ int sdsll2str(char *s, long long value) {
|
||||||
*p++ = '0' + (v % 10);
|
*p++ = '0' + (v % 10);
|
||||||
v /= 10;
|
v /= 10;
|
||||||
} while (v);
|
} while (v);
|
||||||
if (value < 0) *p++ = '-';
|
if (value < 0) {
|
||||||
|
*p++ = '-';
|
||||||
|
}
|
||||||
|
|
||||||
/* Compute length and add null term. */
|
/* Compute length and add null term. */
|
||||||
l = p - s;
|
l = p - s;
|
||||||
|
@ -536,7 +573,9 @@ sds sdscatvprintf(sds s, const char *fmt, va_list ap) {
|
||||||
* If not possible we revert to heap allocation. */
|
* If not possible we revert to heap allocation. */
|
||||||
if (buflen > sizeof(staticbuf)) {
|
if (buflen > sizeof(staticbuf)) {
|
||||||
buf = s_malloc(buflen);
|
buf = s_malloc(buflen);
|
||||||
if (buf == NULL) return NULL;
|
if (buf == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
buflen = sizeof(staticbuf);
|
buflen = sizeof(staticbuf);
|
||||||
}
|
}
|
||||||
|
@ -549,10 +588,14 @@ sds sdscatvprintf(sds s, const char *fmt, va_list ap) {
|
||||||
vsnprintf(buf, buflen, fmt, cpy);
|
vsnprintf(buf, buflen, fmt, cpy);
|
||||||
va_end(cpy);
|
va_end(cpy);
|
||||||
if (buf[buflen - 2] != '\0') {
|
if (buf[buflen - 2] != '\0') {
|
||||||
if (buf != staticbuf) s_free(buf);
|
if (buf != staticbuf) {
|
||||||
|
s_free(buf);
|
||||||
|
}
|
||||||
buflen *= 2;
|
buflen *= 2;
|
||||||
buf = s_malloc(buflen);
|
buf = s_malloc(buflen);
|
||||||
if (buf == NULL) return NULL;
|
if (buf == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -560,7 +603,9 @@ sds sdscatvprintf(sds s, const char *fmt, va_list ap) {
|
||||||
|
|
||||||
/* Finally concat the obtained string to the SDS string and return it. */
|
/* Finally concat the obtained string to the SDS string and return it. */
|
||||||
t = sdscat(s, buf);
|
t = sdscat(s, buf);
|
||||||
if (buf != staticbuf) s_free(buf);
|
if (buf != staticbuf) {
|
||||||
|
s_free(buf);
|
||||||
|
}
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -621,7 +666,9 @@ sds sdscatfmt(sds s, char const *fmt, ...) {
|
||||||
/* Make sure there is always space for at least 1 char. */
|
/* Make sure there is always space for at least 1 char. */
|
||||||
if (sdsavail(s) == 0) {
|
if (sdsavail(s) == 0) {
|
||||||
s = sdsMakeRoomFor(s, 1);
|
s = sdsMakeRoomFor(s, 1);
|
||||||
if (s == NULL) goto fmt_error;
|
if (s == NULL) {
|
||||||
|
goto fmt_error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (*f) {
|
switch (*f) {
|
||||||
|
@ -635,7 +682,9 @@ sds sdscatfmt(sds s, char const *fmt, ...) {
|
||||||
l = (next == 's') ? strlen(str) : sdslen(str);
|
l = (next == 's') ? strlen(str) : sdslen(str);
|
||||||
if (sdsavail(s) < l) {
|
if (sdsavail(s) < l) {
|
||||||
s = sdsMakeRoomFor(s, l);
|
s = sdsMakeRoomFor(s, l);
|
||||||
if (s == NULL) goto fmt_error;
|
if (s == NULL) {
|
||||||
|
goto fmt_error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
memcpy(s + i, str, l);
|
memcpy(s + i, str, l);
|
||||||
sdsinclen(s, l);
|
sdsinclen(s, l);
|
||||||
|
@ -643,16 +692,19 @@ sds sdscatfmt(sds s, char const *fmt, ...) {
|
||||||
break;
|
break;
|
||||||
case 'i':
|
case 'i':
|
||||||
case 'I':
|
case 'I':
|
||||||
if (next == 'i')
|
if (next == 'i') {
|
||||||
num = va_arg(ap, int);
|
num = va_arg(ap, int);
|
||||||
else
|
} else {
|
||||||
num = va_arg(ap, long long);
|
num = va_arg(ap, long long);
|
||||||
|
}
|
||||||
{
|
{
|
||||||
char buf[SDS_LLSTR_SIZE];
|
char buf[SDS_LLSTR_SIZE];
|
||||||
l = sdsll2str(buf, num);
|
l = sdsll2str(buf, num);
|
||||||
if (sdsavail(s) < l) {
|
if (sdsavail(s) < l) {
|
||||||
s = sdsMakeRoomFor(s, l);
|
s = sdsMakeRoomFor(s, l);
|
||||||
if (s == NULL) goto fmt_error;
|
if (s == NULL) {
|
||||||
|
goto fmt_error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
memcpy(s + i, buf, l);
|
memcpy(s + i, buf, l);
|
||||||
sdsinclen(s, l);
|
sdsinclen(s, l);
|
||||||
|
@ -661,16 +713,19 @@ sds sdscatfmt(sds s, char const *fmt, ...) {
|
||||||
break;
|
break;
|
||||||
case 'u':
|
case 'u':
|
||||||
case 'U':
|
case 'U':
|
||||||
if (next == 'u')
|
if (next == 'u') {
|
||||||
unum = va_arg(ap, unsigned int);
|
unum = va_arg(ap, unsigned int);
|
||||||
else
|
} else {
|
||||||
unum = va_arg(ap, unsigned long long);
|
unum = va_arg(ap, unsigned long long);
|
||||||
|
}
|
||||||
{
|
{
|
||||||
char buf[SDS_LLSTR_SIZE];
|
char buf[SDS_LLSTR_SIZE];
|
||||||
l = sdsull2str(buf, unum);
|
l = sdsull2str(buf, unum);
|
||||||
if (sdsavail(s) < l) {
|
if (sdsavail(s) < l) {
|
||||||
s = sdsMakeRoomFor(s, l);
|
s = sdsMakeRoomFor(s, l);
|
||||||
if (s == NULL) goto fmt_error;
|
if (s == NULL) {
|
||||||
|
goto fmt_error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
memcpy(s + i, buf, l);
|
memcpy(s + i, buf, l);
|
||||||
sdsinclen(s, l);
|
sdsinclen(s, l);
|
||||||
|
@ -721,10 +776,16 @@ sds sdstrim(sds s, const char *cset) {
|
||||||
|
|
||||||
sp = start = s;
|
sp = start = s;
|
||||||
ep = end = s + sdslen(s) - 1;
|
ep = end = s + sdslen(s) - 1;
|
||||||
while(sp <= end && strchr(cset, *sp)) sp++;
|
while (sp <= end && strchr(cset, *sp)) {
|
||||||
while(ep > sp && strchr(cset, *ep)) ep--;
|
sp++;
|
||||||
|
}
|
||||||
|
while (ep > sp && strchr(cset, *ep)) {
|
||||||
|
ep--;
|
||||||
|
}
|
||||||
len = (sp > ep) ? 0 : ((ep - sp) + 1);
|
len = (sp > ep) ? 0 : ((ep - sp) + 1);
|
||||||
if (s != sp) memmove(s, sp, len);
|
if (s != sp) {
|
||||||
|
memmove(s, sp, len);
|
||||||
|
}
|
||||||
s[len] = '\0';
|
s[len] = '\0';
|
||||||
sdssetlen(s, len);
|
sdssetlen(s, len);
|
||||||
return s;
|
return s;
|
||||||
|
@ -752,16 +813,24 @@ sds sdstrim(sds s, const char *cset) {
|
||||||
*/
|
*/
|
||||||
int sdsrange(sds s, ssize_t start, ssize_t end) {
|
int sdsrange(sds s, ssize_t start, ssize_t end) {
|
||||||
size_t newlen, len = sdslen(s);
|
size_t newlen, len = sdslen(s);
|
||||||
if (len > SSIZE_MAX) return -1;
|
if (len > SSIZE_MAX) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
if (len == 0) return 0;
|
if (len == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
if (start < 0) {
|
if (start < 0) {
|
||||||
start = len + start;
|
start = len + start;
|
||||||
if (start < 0) start = 0;
|
if (start < 0) {
|
||||||
|
start = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (end < 0) {
|
if (end < 0) {
|
||||||
end = len + end;
|
end = len + end;
|
||||||
if (end < 0) end = 0;
|
if (end < 0) {
|
||||||
|
end = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
newlen = (start > end) ? 0 : (end - start) + 1;
|
newlen = (start > end) ? 0 : (end - start) + 1;
|
||||||
if (newlen != 0) {
|
if (newlen != 0) {
|
||||||
|
@ -774,7 +843,9 @@ int sdsrange(sds s, ssize_t start, ssize_t end) {
|
||||||
} else {
|
} else {
|
||||||
start = 0;
|
start = 0;
|
||||||
}
|
}
|
||||||
if (start && newlen) memmove(s, s+start, newlen);
|
if (start && newlen) {
|
||||||
|
memmove(s, s + start, newlen);
|
||||||
|
}
|
||||||
s[newlen] = 0;
|
s[newlen] = 0;
|
||||||
sdssetlen(s, newlen);
|
sdssetlen(s, newlen);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -784,14 +855,18 @@ int sdsrange(sds s, ssize_t start, ssize_t end) {
|
||||||
void sdstolower(sds s) {
|
void sdstolower(sds s) {
|
||||||
int len = sdslen(s), j;
|
int len = sdslen(s), j;
|
||||||
|
|
||||||
for (j = 0; j < len; j++) s[j] = tolower(s[j]);
|
for (j = 0; j < len; j++) {
|
||||||
|
s[j] = tolower(s[j]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Apply toupper() to every character of the sds string 's'. */
|
/* Apply toupper() to every character of the sds string 's'. */
|
||||||
void sdstoupper(sds s) {
|
void sdstoupper(sds s) {
|
||||||
int len = sdslen(s), j;
|
int len = sdslen(s), j;
|
||||||
|
|
||||||
for (j = 0; j < len; j++) s[j] = toupper(s[j]);
|
for (j = 0; j < len; j++) {
|
||||||
|
s[j] = toupper(s[j]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Compare two sds strings s1 and s2 with memcmp().
|
/* Compare two sds strings s1 and s2 with memcmp().
|
||||||
|
@ -813,7 +888,9 @@ int sdscmp(const sds s1, const sds s2) {
|
||||||
l2 = sdslen(s2);
|
l2 = sdslen(s2);
|
||||||
minlen = (l1 < l2) ? l1 : l2;
|
minlen = (l1 < l2) ? l1 : l2;
|
||||||
cmp = memcmp(s1, s2, minlen);
|
cmp = memcmp(s1, s2, minlen);
|
||||||
if (cmp == 0) return l1-l2;
|
if (cmp == 0) {
|
||||||
|
return l1 - l2;
|
||||||
|
}
|
||||||
return cmp;
|
return cmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -837,10 +914,14 @@ sds *sdssplitlen(const char *s, int len, const char *sep, int seplen, int *count
|
||||||
int elements = 0, slots = 5, start = 0, j;
|
int elements = 0, slots = 5, start = 0, j;
|
||||||
sds *tokens;
|
sds *tokens;
|
||||||
|
|
||||||
if (seplen < 1 || len < 0) return NULL;
|
if (seplen < 1 || len < 0) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
tokens = s_malloc(sizeof(sds) * slots);
|
tokens = s_malloc(sizeof(sds) * slots);
|
||||||
if (tokens == NULL) return NULL;
|
if (tokens == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (len == 0) {
|
if (len == 0) {
|
||||||
*count = 0;
|
*count = 0;
|
||||||
|
@ -853,13 +934,17 @@ sds *sdssplitlen(const char *s, int len, const char *sep, int seplen, int *count
|
||||||
|
|
||||||
slots *= 2;
|
slots *= 2;
|
||||||
newtokens = s_realloc(tokens, sizeof(sds) * slots);
|
newtokens = s_realloc(tokens, sizeof(sds) * slots);
|
||||||
if (newtokens == NULL) goto cleanup;
|
if (newtokens == NULL) {
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
tokens = newtokens;
|
tokens = newtokens;
|
||||||
}
|
}
|
||||||
/* search the separator */
|
/* search the separator */
|
||||||
if ((seplen == 1 && *(s + j) == sep[0]) || (memcmp(s + j, sep, seplen) == 0)) {
|
if ((seplen == 1 && *(s + j) == sep[0]) || (memcmp(s + j, sep, seplen) == 0)) {
|
||||||
tokens[elements] = sdsnewlen(s + start, j - start);
|
tokens[elements] = sdsnewlen(s + start, j - start);
|
||||||
if (tokens[elements] == NULL) goto cleanup;
|
if (tokens[elements] == NULL) {
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
elements++;
|
elements++;
|
||||||
start = j + seplen;
|
start = j + seplen;
|
||||||
j = j + seplen - 1; /* skip the separator */
|
j = j + seplen - 1; /* skip the separator */
|
||||||
|
@ -867,15 +952,18 @@ sds *sdssplitlen(const char *s, int len, const char *sep, int seplen, int *count
|
||||||
}
|
}
|
||||||
/* Add the final element. We are sure there is room in the tokens array. */
|
/* Add the final element. We are sure there is room in the tokens array. */
|
||||||
tokens[elements] = sdsnewlen(s + start, len - start);
|
tokens[elements] = sdsnewlen(s + start, len - start);
|
||||||
if (tokens[elements] == NULL) goto cleanup;
|
if (tokens[elements] == NULL) {
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
elements++;
|
elements++;
|
||||||
*count = elements;
|
*count = elements;
|
||||||
return tokens;
|
return tokens;
|
||||||
|
|
||||||
cleanup:
|
cleanup : {
|
||||||
{
|
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < elements; i++) sdsfree(tokens[i]);
|
for (i = 0; i < elements; i++) {
|
||||||
|
sdsfree(tokens[i]);
|
||||||
|
}
|
||||||
s_free(tokens);
|
s_free(tokens);
|
||||||
*count = 0;
|
*count = 0;
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -884,9 +972,12 @@ cleanup:
|
||||||
|
|
||||||
/* Free the result returned by sdssplitlen(), or do nothing if 'tokens' is NULL. */
|
/* Free the result returned by sdssplitlen(), or do nothing if 'tokens' is NULL. */
|
||||||
void sdsfreesplitres(sds *tokens, int count) {
|
void sdsfreesplitres(sds *tokens, int count) {
|
||||||
if (!tokens) return;
|
if (!tokens) {
|
||||||
while(count--)
|
return;
|
||||||
|
}
|
||||||
|
while (count--) {
|
||||||
sdsfree(tokens[count]);
|
sdsfree(tokens[count]);
|
||||||
|
}
|
||||||
s_free(tokens);
|
s_free(tokens);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -904,16 +995,27 @@ sds sdscatrepr(sds s, const char *p, size_t len) {
|
||||||
case '"':
|
case '"':
|
||||||
s = sdscatprintf(s, "\\%c", *p);
|
s = sdscatprintf(s, "\\%c", *p);
|
||||||
break;
|
break;
|
||||||
case '\n': s = sdscatlen(s,"\\n",2); break;
|
case '\n':
|
||||||
case '\r': s = sdscatlen(s,"\\r",2); break;
|
s = sdscatlen(s, "\\n", 2);
|
||||||
case '\t': s = sdscatlen(s,"\\t",2); break;
|
break;
|
||||||
case '\a': s = sdscatlen(s,"\\a",2); break;
|
case '\r':
|
||||||
case '\b': s = sdscatlen(s,"\\b",2); break;
|
s = sdscatlen(s, "\\r", 2);
|
||||||
|
break;
|
||||||
|
case '\t':
|
||||||
|
s = sdscatlen(s, "\\t", 2);
|
||||||
|
break;
|
||||||
|
case '\a':
|
||||||
|
s = sdscatlen(s, "\\a", 2);
|
||||||
|
break;
|
||||||
|
case '\b':
|
||||||
|
s = sdscatlen(s, "\\b", 2);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
if (isprint(*p))
|
if (isprint(*p)) {
|
||||||
s = sdscatprintf(s, "%c", *p);
|
s = sdscatprintf(s, "%c", *p);
|
||||||
else
|
} else {
|
||||||
s = sdscatprintf(s, "\\x%02x", (unsigned char)*p);
|
s = sdscatprintf(s, "\\x%02x", (unsigned char)*p);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
p++;
|
p++;
|
||||||
|
@ -925,23 +1027,46 @@ sds sdscatrepr(sds s, const char *p, size_t len) {
|
||||||
* integer from 0 to 15 */
|
* integer from 0 to 15 */
|
||||||
int hex_digit_to_int(char c) {
|
int hex_digit_to_int(char c) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case '0': return 0;
|
case '0':
|
||||||
case '1': return 1;
|
return 0;
|
||||||
case '2': return 2;
|
case '1':
|
||||||
case '3': return 3;
|
return 1;
|
||||||
case '4': return 4;
|
case '2':
|
||||||
case '5': return 5;
|
return 2;
|
||||||
case '6': return 6;
|
case '3':
|
||||||
case '7': return 7;
|
return 3;
|
||||||
case '8': return 8;
|
case '4':
|
||||||
case '9': return 9;
|
return 4;
|
||||||
case 'a': case 'A': return 10;
|
case '5':
|
||||||
case 'b': case 'B': return 11;
|
return 5;
|
||||||
case 'c': case 'C': return 12;
|
case '6':
|
||||||
case 'd': case 'D': return 13;
|
return 6;
|
||||||
case 'e': case 'E': return 14;
|
case '7':
|
||||||
case 'f': case 'F': return 15;
|
return 7;
|
||||||
default: return 0;
|
case '8':
|
||||||
|
return 8;
|
||||||
|
case '9':
|
||||||
|
return 9;
|
||||||
|
case 'a':
|
||||||
|
case 'A':
|
||||||
|
return 10;
|
||||||
|
case 'b':
|
||||||
|
case 'B':
|
||||||
|
return 11;
|
||||||
|
case 'c':
|
||||||
|
case 'C':
|
||||||
|
return 12;
|
||||||
|
case 'd':
|
||||||
|
case 'D':
|
||||||
|
return 13;
|
||||||
|
case 'e':
|
||||||
|
case 'E':
|
||||||
|
return 14;
|
||||||
|
case 'f':
|
||||||
|
case 'F':
|
||||||
|
return 15;
|
||||||
|
default:
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -972,24 +1097,24 @@ sds *sdssplitargs(const char *line, int *argc) {
|
||||||
*argc = 0;
|
*argc = 0;
|
||||||
while (1) {
|
while (1) {
|
||||||
/* skip blanks */
|
/* skip blanks */
|
||||||
while(*p && isspace(*p)) p++;
|
while (*p && isspace(*p)) {
|
||||||
|
p++;
|
||||||
|
}
|
||||||
if (*p) {
|
if (*p) {
|
||||||
/* get a token */
|
/* get a token */
|
||||||
int inq = 0; /* set to 1 if we are in "quotes" */
|
int inq = 0; /* set to 1 if we are in "quotes" */
|
||||||
int insq = 0; /* set to 1 if we are in 'single quotes' */
|
int insq = 0; /* set to 1 if we are in 'single quotes' */
|
||||||
int done = 0;
|
int done = 0;
|
||||||
|
|
||||||
if (current == NULL) current = sdsempty();
|
if (current == NULL) {
|
||||||
|
current = sdsempty();
|
||||||
|
}
|
||||||
while (!done) {
|
while (!done) {
|
||||||
if (inq) {
|
if (inq) {
|
||||||
if (*p == '\\' && *(p+1) == 'x' &&
|
if (*p == '\\' && *(p + 1) == 'x' && isxdigit(*(p + 2)) && isxdigit(*(p + 3))) {
|
||||||
isxdigit(*(p+2)) &&
|
|
||||||
isxdigit(*(p+3)))
|
|
||||||
{
|
|
||||||
unsigned char byte;
|
unsigned char byte;
|
||||||
|
|
||||||
byte = (hex_digit_to_int(*(p+2))*16)+
|
byte = (hex_digit_to_int(*(p + 2)) * 16) + hex_digit_to_int(*(p + 3));
|
||||||
hex_digit_to_int(*(p+3));
|
|
||||||
current = sdscatlen(current, (char *)&byte, 1);
|
current = sdscatlen(current, (char *)&byte, 1);
|
||||||
p += 3;
|
p += 3;
|
||||||
} else if (*p == '\\' && *(p + 1)) {
|
} else if (*p == '\\' && *(p + 1)) {
|
||||||
|
@ -997,18 +1122,32 @@ sds *sdssplitargs(const char *line, int *argc) {
|
||||||
|
|
||||||
p++;
|
p++;
|
||||||
switch (*p) {
|
switch (*p) {
|
||||||
case 'n': c = '\n'; break;
|
case 'n':
|
||||||
case 'r': c = '\r'; break;
|
c = '\n';
|
||||||
case 't': c = '\t'; break;
|
break;
|
||||||
case 'b': c = '\b'; break;
|
case 'r':
|
||||||
case 'a': c = '\a'; break;
|
c = '\r';
|
||||||
default: c = *p; break;
|
break;
|
||||||
|
case 't':
|
||||||
|
c = '\t';
|
||||||
|
break;
|
||||||
|
case 'b':
|
||||||
|
c = '\b';
|
||||||
|
break;
|
||||||
|
case 'a':
|
||||||
|
c = '\a';
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
c = *p;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
current = sdscatlen(current, &c, 1);
|
current = sdscatlen(current, &c, 1);
|
||||||
} else if (*p == '"') {
|
} else if (*p == '"') {
|
||||||
/* closing quote must be followed by a space or
|
/* closing quote must be followed by a space or
|
||||||
* nothing at all. */
|
* nothing at all. */
|
||||||
if (*(p+1) && !isspace(*(p+1))) goto err;
|
if (*(p + 1) && !isspace(*(p + 1))) {
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
done = 1;
|
done = 1;
|
||||||
} else if (!*p) {
|
} else if (!*p) {
|
||||||
/* unterminated quotes */
|
/* unterminated quotes */
|
||||||
|
@ -1023,7 +1162,9 @@ sds *sdssplitargs(const char *line, int *argc) {
|
||||||
} else if (*p == '\'') {
|
} else if (*p == '\'') {
|
||||||
/* closing quote must be followed by a space or
|
/* closing quote must be followed by a space or
|
||||||
* nothing at all. */
|
* nothing at all. */
|
||||||
if (*(p+1) && !isspace(*(p+1))) goto err;
|
if (*(p + 1) && !isspace(*(p + 1))) {
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
done = 1;
|
done = 1;
|
||||||
} else if (!*p) {
|
} else if (!*p) {
|
||||||
/* unterminated quotes */
|
/* unterminated quotes */
|
||||||
|
@ -1051,7 +1192,9 @@ sds *sdssplitargs(const char *line, int *argc) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (*p) p++;
|
if (*p) {
|
||||||
|
p++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/* add the token to the vector */
|
/* add the token to the vector */
|
||||||
{
|
{
|
||||||
|
@ -1068,16 +1211,21 @@ sds *sdssplitargs(const char *line, int *argc) {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* Even on empty input string return something not NULL. */
|
/* Even on empty input string return something not NULL. */
|
||||||
if (vector == NULL) vector = s_malloc(sizeof(void*));
|
if (vector == NULL) {
|
||||||
|
vector = s_malloc(sizeof(void *));
|
||||||
|
}
|
||||||
return vector;
|
return vector;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err:
|
err:
|
||||||
while((*argc)--)
|
while ((*argc)--) {
|
||||||
sdsfree(vector[*argc]);
|
sdsfree(vector[*argc]);
|
||||||
|
}
|
||||||
s_free(vector);
|
s_free(vector);
|
||||||
if (current) sdsfree(current);
|
if (current) {
|
||||||
|
sdsfree(current);
|
||||||
|
}
|
||||||
*argc = 0;
|
*argc = 0;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -1113,7 +1261,9 @@ sds sdsjoin(char **argv, int argc, char *sep) {
|
||||||
|
|
||||||
for (j = 0; j < argc; j++) {
|
for (j = 0; j < argc; j++) {
|
||||||
join = sdscat(join, argv[j]);
|
join = sdscat(join, argv[j]);
|
||||||
if (j != argc-1) join = sdscat(join,sep);
|
if (j != argc - 1) {
|
||||||
|
join = sdscat(join, sep);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return join;
|
return join;
|
||||||
}
|
}
|
||||||
|
@ -1125,7 +1275,9 @@ sds sdsjoinsds(sds *argv, int argc, const char *sep, size_t seplen) {
|
||||||
|
|
||||||
for (j = 0; j < argc; j++) {
|
for (j = 0; j < argc; j++) {
|
||||||
join = sdscatsds(join, argv[j]);
|
join = sdscatsds(join, argv[j]);
|
||||||
if (j != argc-1) join = sdscatlen(join,sep,seplen);
|
if (j != argc - 1) {
|
||||||
|
join = sdscatlen(join, sep, seplen);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return join;
|
return join;
|
||||||
}
|
}
|
||||||
|
@ -1135,9 +1287,15 @@ sds sdsjoinsds(sds *argv, int argc, const char *sep, size_t seplen) {
|
||||||
* the overhead of function calls. Here we define these wrappers only for
|
* the overhead of function calls. Here we define these wrappers only for
|
||||||
* the programs SDS is linked to, if they want to touch the SDS internals
|
* the programs SDS is linked to, if they want to touch the SDS internals
|
||||||
* even if they use a different allocator. */
|
* even if they use a different allocator. */
|
||||||
void *sds_malloc(size_t size) { return s_malloc(size); }
|
void *sds_malloc(size_t size) {
|
||||||
void *sds_realloc(void *ptr, size_t size) { return s_realloc(ptr,size); }
|
return s_malloc(size);
|
||||||
void sds_free(void *ptr) { s_free(ptr); }
|
}
|
||||||
|
void *sds_realloc(void *ptr, size_t size) {
|
||||||
|
return s_realloc(ptr, size);
|
||||||
|
}
|
||||||
|
void sds_free(void *ptr) {
|
||||||
|
s_free(ptr);
|
||||||
|
}
|
||||||
|
|
||||||
#if defined(SDS_TEST_MAIN)
|
#if defined(SDS_TEST_MAIN)
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -1149,100 +1307,86 @@ int sdsTest(void) {
|
||||||
{
|
{
|
||||||
sds x = sdsnew("foo"), y;
|
sds x = sdsnew("foo"), y;
|
||||||
|
|
||||||
test_cond("Create a string and obtain the length",
|
test_cond("Create a string and obtain the length", sdslen(x) == 3 && memcmp(x, "foo\0", 4) == 0)
|
||||||
sdslen(x) == 3 && memcmp(x,"foo\0",4) == 0)
|
|
||||||
|
|
||||||
sdsfree(x);
|
sdsfree(x);
|
||||||
x = sdsnewlen("foo", 2);
|
x = sdsnewlen("foo", 2);
|
||||||
test_cond("Create a string with specified length",
|
test_cond("Create a string with specified length", sdslen(x) == 2 && memcmp(x, "fo\0", 3) == 0)
|
||||||
sdslen(x) == 2 && memcmp(x,"fo\0",3) == 0)
|
|
||||||
|
|
||||||
x = sdscat(x, "bar");
|
x = sdscat(x, "bar");
|
||||||
test_cond("Strings concatenation",
|
test_cond("Strings concatenation", sdslen(x) == 5 && memcmp(x, "fobar\0", 6) == 0);
|
||||||
sdslen(x) == 5 && memcmp(x,"fobar\0",6) == 0);
|
|
||||||
|
|
||||||
x = sdscpy(x, "a");
|
x = sdscpy(x, "a");
|
||||||
test_cond("sdscpy() against an originally longer string",
|
test_cond("sdscpy() against an originally longer string", sdslen(x) == 1 && memcmp(x, "a\0", 2) == 0)
|
||||||
sdslen(x) == 1 && memcmp(x,"a\0",2) == 0)
|
|
||||||
|
|
||||||
x = sdscpy(x, "xyzxxxxxxxxxxyyyyyyyyyykkkkkkkkkk");
|
x = sdscpy(x, "xyzxxxxxxxxxxyyyyyyyyyykkkkkkkkkk");
|
||||||
test_cond("sdscpy() against an originally shorter string",
|
test_cond("sdscpy() against an originally shorter string",
|
||||||
sdslen(x) == 33 &&
|
sdslen(x) == 33 && memcmp(x, "xyzxxxxxxxxxxyyyyyyyyyykkkkkkkkkk\0", 33) == 0)
|
||||||
memcmp(x,"xyzxxxxxxxxxxyyyyyyyyyykkkkkkkkkk\0",33) == 0)
|
|
||||||
|
|
||||||
sdsfree(x);
|
sdsfree(x);
|
||||||
x = sdscatprintf(sdsempty(), "%d", 123);
|
x = sdscatprintf(sdsempty(), "%d", 123);
|
||||||
test_cond("sdscatprintf() seems working in the base case",
|
test_cond("sdscatprintf() seems working in the base case", sdslen(x) == 3 && memcmp(x, "123\0", 4) == 0)
|
||||||
sdslen(x) == 3 && memcmp(x,"123\0",4) == 0)
|
|
||||||
|
|
||||||
sdsfree(x);
|
sdsfree(x);
|
||||||
x = sdsnew("--");
|
x = sdsnew("--");
|
||||||
x = sdscatfmt(x, "Hello %s World %I,%I--", "Hi!", LLONG_MIN, LLONG_MAX);
|
x = sdscatfmt(x, "Hello %s World %I,%I--", "Hi!", LLONG_MIN, LLONG_MAX);
|
||||||
test_cond("sdscatfmt() seems working in the base case",
|
test_cond("sdscatfmt() seems working in the base case",
|
||||||
sdslen(x) == 60 &&
|
sdslen(x) == 60
|
||||||
memcmp(x,"--Hello Hi! World -9223372036854775808,"
|
&& memcmp(x,
|
||||||
"9223372036854775807--",60) == 0)
|
"--Hello Hi! World -9223372036854775808,"
|
||||||
printf("[%s]\n",x);
|
"9223372036854775807--",
|
||||||
|
60)
|
||||||
|
== 0) printf("[%s]\n", x);
|
||||||
|
|
||||||
sdsfree(x);
|
sdsfree(x);
|
||||||
x = sdsnew("--");
|
x = sdsnew("--");
|
||||||
x = sdscatfmt(x, "%u,%U--", UINT_MAX, ULLONG_MAX);
|
x = sdscatfmt(x, "%u,%U--", UINT_MAX, ULLONG_MAX);
|
||||||
test_cond("sdscatfmt() seems working with unsigned numbers",
|
test_cond("sdscatfmt() seems working with unsigned numbers",
|
||||||
sdslen(x) == 35 &&
|
sdslen(x) == 35 && memcmp(x, "--4294967295,18446744073709551615--", 35) == 0)
|
||||||
memcmp(x,"--4294967295,18446744073709551615--",35) == 0)
|
|
||||||
|
|
||||||
sdsfree(x);
|
sdsfree(x);
|
||||||
x = sdsnew(" x ");
|
x = sdsnew(" x ");
|
||||||
sdstrim(x, " x");
|
sdstrim(x, " x");
|
||||||
test_cond("sdstrim() works when all chars match",
|
test_cond("sdstrim() works when all chars match", sdslen(x) == 0)
|
||||||
sdslen(x) == 0)
|
|
||||||
|
|
||||||
sdsfree(x);
|
sdsfree(x);
|
||||||
x = sdsnew(" x ");
|
x = sdsnew(" x ");
|
||||||
sdstrim(x, " ");
|
sdstrim(x, " ");
|
||||||
test_cond("sdstrim() works when a single char remains",
|
test_cond("sdstrim() works when a single char remains", sdslen(x) == 1 && x[0] == 'x')
|
||||||
sdslen(x) == 1 && x[0] == 'x')
|
|
||||||
|
|
||||||
sdsfree(x);
|
sdsfree(x);
|
||||||
x = sdsnew("xxciaoyyy");
|
x = sdsnew("xxciaoyyy");
|
||||||
sdstrim(x, "xy");
|
sdstrim(x, "xy");
|
||||||
test_cond("sdstrim() correctly trims characters",
|
test_cond("sdstrim() correctly trims characters", sdslen(x) == 4 && memcmp(x, "ciao\0", 5) == 0)
|
||||||
sdslen(x) == 4 && memcmp(x,"ciao\0",5) == 0)
|
|
||||||
|
|
||||||
y = sdsdup(x);
|
y = sdsdup(x);
|
||||||
sdsrange(y, 1, 1);
|
sdsrange(y, 1, 1);
|
||||||
test_cond("sdsrange(...,1,1)",
|
test_cond("sdsrange(...,1,1)", sdslen(y) == 1 && memcmp(y, "i\0", 2) == 0)
|
||||||
sdslen(y) == 1 && memcmp(y,"i\0",2) == 0)
|
|
||||||
|
|
||||||
sdsfree(y);
|
sdsfree(y);
|
||||||
y = sdsdup(x);
|
y = sdsdup(x);
|
||||||
sdsrange(y, 1, -1);
|
sdsrange(y, 1, -1);
|
||||||
test_cond("sdsrange(...,1,-1)",
|
test_cond("sdsrange(...,1,-1)", sdslen(y) == 3 && memcmp(y, "iao\0", 4) == 0)
|
||||||
sdslen(y) == 3 && memcmp(y,"iao\0",4) == 0)
|
|
||||||
|
|
||||||
sdsfree(y);
|
sdsfree(y);
|
||||||
y = sdsdup(x);
|
y = sdsdup(x);
|
||||||
sdsrange(y, -2, -1);
|
sdsrange(y, -2, -1);
|
||||||
test_cond("sdsrange(...,-2,-1)",
|
test_cond("sdsrange(...,-2,-1)", sdslen(y) == 2 && memcmp(y, "ao\0", 3) == 0)
|
||||||
sdslen(y) == 2 && memcmp(y,"ao\0",3) == 0)
|
|
||||||
|
|
||||||
sdsfree(y);
|
sdsfree(y);
|
||||||
y = sdsdup(x);
|
y = sdsdup(x);
|
||||||
sdsrange(y, 2, 1);
|
sdsrange(y, 2, 1);
|
||||||
test_cond("sdsrange(...,2,1)",
|
test_cond("sdsrange(...,2,1)", sdslen(y) == 0 && memcmp(y, "\0", 1) == 0)
|
||||||
sdslen(y) == 0 && memcmp(y,"\0",1) == 0)
|
|
||||||
|
|
||||||
sdsfree(y);
|
sdsfree(y);
|
||||||
y = sdsdup(x);
|
y = sdsdup(x);
|
||||||
sdsrange(y, 1, 100);
|
sdsrange(y, 1, 100);
|
||||||
test_cond("sdsrange(...,1,100)",
|
test_cond("sdsrange(...,1,100)", sdslen(y) == 3 && memcmp(y, "iao\0", 4) == 0)
|
||||||
sdslen(y) == 3 && memcmp(y,"iao\0",4) == 0)
|
|
||||||
|
|
||||||
sdsfree(y);
|
sdsfree(y);
|
||||||
y = sdsdup(x);
|
y = sdsdup(x);
|
||||||
sdsrange(y, 100, 100);
|
sdsrange(y, 100, 100);
|
||||||
test_cond("sdsrange(...,100,100)",
|
test_cond("sdsrange(...,100,100)", sdslen(y) == 0 && memcmp(y, "\0", 1) == 0)
|
||||||
sdslen(y) == 0 && memcmp(y,"\0",1) == 0)
|
|
||||||
|
|
||||||
sdsfree(y);
|
sdsfree(y);
|
||||||
sdsfree(x);
|
sdsfree(x);
|
||||||
|
@ -1266,8 +1410,7 @@ int sdsTest(void) {
|
||||||
sdsfree(x);
|
sdsfree(x);
|
||||||
x = sdsnewlen("\a\n\0foo\r", 7);
|
x = sdsnewlen("\a\n\0foo\r", 7);
|
||||||
y = sdscatrepr(sdsempty(), x, sdslen(x));
|
y = sdscatrepr(sdsempty(), x, sdslen(x));
|
||||||
test_cond("sdscatrepr(...data...)",
|
test_cond("sdscatrepr(...data...)", memcmp(y, "\"\\a\\n\\x00foo\\r\"", 15) == 0)
|
||||||
memcmp(y,"\"\\a\\n\\x00foo\\r\"",15) == 0)
|
|
||||||
|
|
||||||
{
|
{
|
||||||
unsigned int oldfree;
|
unsigned int oldfree;
|
||||||
|
@ -1298,14 +1441,17 @@ int sdsTest(void) {
|
||||||
sdsIncrLen(x, step);
|
sdsIncrLen(x, step);
|
||||||
}
|
}
|
||||||
test_cond("sdsMakeRoomFor() content",
|
test_cond("sdsMakeRoomFor() content",
|
||||||
memcmp("0ABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJ",x,101) == 0);
|
memcmp("0ABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGH"
|
||||||
|
"IJABCDEFGHIJ",
|
||||||
|
x,
|
||||||
|
101)
|
||||||
|
== 0);
|
||||||
test_cond("sdsMakeRoomFor() final length", sdslen(x) == 101);
|
test_cond("sdsMakeRoomFor() final length", sdslen(x) == 101);
|
||||||
|
|
||||||
sdsfree(x);
|
sdsfree(x);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
test_report()
|
test_report() return 0;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -229,10 +229,8 @@ static void checkMultiInfo(void) {
|
||||||
pReq->errCode = 0;
|
pReq->errCode = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
uv_fs_fdatasync(get_task_manager(),
|
uv_fs_fdatasync(
|
||||||
&pReq->uvFsDataSync,
|
get_task_manager(), &pReq->uvFsDataSync, (uv_file)pReq->uvFsOpen.result, uvFsDataSyncCb);
|
||||||
(uv_file)pReq->uvFsOpen.result,
|
|
||||||
uvFsDataSyncCb);
|
|
||||||
} else if (pReq->type == INET_HTTP_WEBSERVICE_POST) {
|
} else if (pReq->type == INET_HTTP_WEBSERVICE_POST) {
|
||||||
if (pMsg->data.result != CURLE_OK) {
|
if (pMsg->data.result != CURLE_OK) {
|
||||||
if (pReq->onRspCb && pReq->isCancel == FALSE) {
|
if (pReq->onRspCb && pReq->isCancel == FALSE) {
|
||||||
|
@ -402,13 +400,8 @@ static size_t writeDataCb(void *pData, size_t size, size_t nmemb, void *pParams)
|
||||||
|
|
||||||
pReq->uvFsBuf = uv_buf_init(pData, iMemSize);
|
pReq->uvFsBuf = uv_buf_init(pData, iMemSize);
|
||||||
|
|
||||||
wr = uv_fs_write(get_task_manager(),
|
wr = uv_fs_write(
|
||||||
&pReq->uvFsWrite,
|
get_task_manager(), &pReq->uvFsWrite, (uv_file)pReq->uvFsOpen.result, &pReq->uvFsBuf, 1, -1, NULL);
|
||||||
(uv_file)pReq->uvFsOpen.result,
|
|
||||||
&pReq->uvFsBuf,
|
|
||||||
1,
|
|
||||||
-1,
|
|
||||||
NULL);
|
|
||||||
|
|
||||||
if (wr > 0) {
|
if (wr > 0) {
|
||||||
pReq->dlSize += wr;
|
pReq->dlSize += wr;
|
||||||
|
@ -440,10 +433,8 @@ static int progressCb(void *pData, double total, double now, double UNUSED(ulTot
|
||||||
|
|
||||||
if (pParams->onPrgCb) {
|
if (pParams->onPrgCb) {
|
||||||
if (pParams->type == INET_HTTP_DOWNLOAD_FILE) {
|
if (pParams->type == INET_HTTP_DOWNLOAD_FILE) {
|
||||||
pParams->onPrgCb(pParams->pReqUrl,
|
pParams->onPrgCb(
|
||||||
pParams->pTaskUuid,
|
pParams->pReqUrl, pParams->pTaskUuid, (unsigned char)(now * 100.0 / total), pParams->pData);
|
||||||
(unsigned char)(now * 100.0 / total),
|
|
||||||
pParams->pData);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -554,8 +545,11 @@ static void onDlTimeoutCb(uv_timer_t *UNUSED(pufTimer)) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *inet_download_file_async(const char *pURL, const char *pPath, on_http_response onRespCb,
|
const char *inet_download_file_async(const char *pURL,
|
||||||
on_progress_changed onProgressCb, void *pData) {
|
const char *pPath,
|
||||||
|
on_http_response onRespCb,
|
||||||
|
on_progress_changed onProgressCb,
|
||||||
|
void *pData) {
|
||||||
CURLMcode ret;
|
CURLMcode ret;
|
||||||
uuid_t msgId;
|
uuid_t msgId;
|
||||||
char strMsgId[64];
|
char strMsgId[64];
|
||||||
|
@ -614,12 +608,8 @@ const char *inet_download_file_async(const char *pURL, const char *pPath, on_htt
|
||||||
|
|
||||||
dzlog_debug("[%s]: File %s used temp path %s\n", pParams->pTaskUuid, pParams->sPath, pParams->sDlPath);
|
dzlog_debug("[%s]: File %s used temp path %s\n", pParams->pTaskUuid, pParams->sPath, pParams->sDlPath);
|
||||||
|
|
||||||
uv_fs_open(get_task_manager(),
|
uv_fs_open(
|
||||||
&pParams->uvFsOpen,
|
get_task_manager(), &pParams->uvFsOpen, pParams->sDlPath, O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR, NULL);
|
||||||
pParams->sDlPath,
|
|
||||||
O_RDWR | O_CREAT | O_TRUNC,
|
|
||||||
S_IRUSR | S_IWUSR,
|
|
||||||
NULL);
|
|
||||||
|
|
||||||
curl_easy_setopt(pCurl, CURLOPT_WRITEFUNCTION, writeDataCb);
|
curl_easy_setopt(pCurl, CURLOPT_WRITEFUNCTION, writeDataCb);
|
||||||
curl_easy_setopt(pCurl, CURLOPT_WRITEDATA, pParams);
|
curl_easy_setopt(pCurl, CURLOPT_WRITEDATA, pParams);
|
||||||
|
|
Loading…
Reference in New Issue