📄 icutils.c
字号:
if (*str != (char *)0)
Z2Free (*str);
VOLT_LOG_ERROR (
(VtLibCtx)libCtx, VT_ERROR_MEMORY, VT_ERROR_TYPE_PRIMARY, fnctLine,
"icStrprependalloc", (char *)0)
return (VT_ERROR_MEMORY);
}
int icStrcatalloc (
char **str,
char *cat,
VoltLibCtx *libCtx
)
{
unsigned int currentLen, catLen;
char *newBuffer = (char *)0;
VOLT_DECLARE_FNCT_LINE (fnctLine)
currentLen = 0;
if (*str != (char *)0)
currentLen = Z2Strlen (*str);
catLen = 0;
if (cat != (char *)0)
catLen = Z2Strlen (cat);
VOLT_SET_FNCT_LINE (fnctLine)
newBuffer = (char *)Z3Malloc (currentLen + catLen + 1);
if (newBuffer != (char*)0)
{
if (currentLen != 0)
Z2Memcpy (newBuffer, *str, currentLen);
if (catLen != 0)
Z2Memcpy (newBuffer + currentLen, cat, catLen);
newBuffer[currentLen + catLen] = 0;
if (*str != (char *)0)
Z2Free (*str);
*str = newBuffer;
return (0);
}
if (*str != (char *)0)
Z2Free (*str);
VOLT_LOG_ERROR (
(VtLibCtx)libCtx, VT_ERROR_MEMORY, VT_ERROR_TYPE_PRIMARY, fnctLine,
"icStrcatalloc", (char *)0)
return (VT_ERROR_MEMORY);
}
int icStringlower (
char *str,
VoltLibCtx *libCtx
)
{
unsigned int index, len, currentVal, lowerA, capA, capZ, diff;
len = Z2Strlen (str);
lowerA = (unsigned int)'a';
capA = (unsigned int)'A';
capZ = (unsigned int)'Z';
diff = lowerA - capA;
for (index = 0; index < len; ++index)
{
currentVal = (unsigned int)(str[index]);
if ( (currentVal < capA) || (currentVal > capZ) )
continue;
currentVal += diff;
str[index] = (unsigned char)currentVal;
}
return (0);
}
int icIsStringlower (
char *str,
VoltLibCtx *libCtx
)
{
char *ptr;
for (ptr = str; *ptr != 0; ptr++)
{
/* if (isalpha(*ptr) && isupper(*ptr))
*/
if (( *ptr < ((int) 'a')) && (*ptr > ((int) 'z')))
return (0);
}
return (1);
}
int icTrim (
char *str,
VoltLibCtx *libCtx
)
{
int status;
unsigned int index, stringLen, count;
char current;
char *ptr;
VOLT_DECLARE_FNCT_LINE (fnctLine)
do
{
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_NULL_ARG;
stringLen = Z2Strlen (str);
if (stringLen == 0)
break;
/* Start at the end, find all the whitespace characters.
*/
ptr = str + stringLen - 1;
for (index = 0; index < stringLen; ++index)
{
current = *ptr;
if ( (current != ' ') && (current != '\n') && (current != '\r') )
break;
ptr--;
}
/* How many bytes remain?
*/
VOLT_SET_FNCT_LINE (fnctLine)
count = stringLen - index;
status = VT_ERROR_INVALID_INPUT;
if (count == 0)
break;
/* Set the count'th character with the NULL-terminating character
* so that the string now ends before whitespace.
*/
str[count] = 0;
stringLen = count;
/* Now count the whitespace characters at the beginning.
*/
ptr = str;
for (index = 0; index < stringLen; ++index)
{
current = *ptr;
if ( (current != ' ') && (current != '\n') && (current != '\r') )
break;
ptr++;
}
/* How many bytes remain?
*/
VOLT_SET_FNCT_LINE (fnctLine)
count = stringLen - index;
if (count == 0)
break;
/* If there are no whitespace characters at the beginning, the
* string is ready.
*/
status = 0;
if (count == stringLen)
break;
/* Move the string so the non-whitespace characters are at the
* beginning.
*/
Z2Memmove (str, str + index, count + 1);
} while (0);
VOLT_LOG_ERROR_COMPARE (
status, (VtLibCtx)libCtx, status, VT_ERROR_TYPE_PRIMARY, fnctLine,
"icTrim", (char *)0)
return (status);
}
int icPatimat (
char *pat,
char *str,
VoltLibCtx *libCtx
)
{
switch (*pat)
{
case '\0':
return !*str;
case '*' :
return (icPatimat(pat+1, str,libCtx) ) || (*str && icPatimat(pat, str+1, libCtx) );
case '?' :
return *str && icPatimat(pat+1, str+1, libCtx);
default :
return (Z2Toupper(*pat) == Z2Toupper(*str)) && icPatimat(pat+1, str+1, libCtx);
}
}
int icXstricmpsafe (
char *pat,
char *str,
VoltLibCtx *libCtx
)
{
if ( ((char *)0 == str) || ((char *)0 == pat) )
return (0);
return (icPatimat (pat, str, libCtx));
}
int icBuildURLAlloc (
VoltLibCtx *libCtx,
unsigned int format,
char *prefix,
char *server,
char *address,
char **result
)
{
int status;
unsigned int prefixLen, serverLen, addressLen, totalLen;
unsigned int middleLen, endLen;
char *middle, *end;
char *retVal = (char *)0;
VOLT_DECLARE_FNCT_LINE (fnctLine)
do
{
prefixLen = Z2Strlen (prefix);
serverLen = Z2Strlen (server);
addressLen = Z2Strlen (address);
if (format == VOLT_IC_URL_PARAMS)
{
middle = VOLT_IC_URL_PARAMS_MIDDLE;
end = VOLT_IC_URL_PARAMS_END;
middleLen = VOLT_IC_URL_PARAMS_MIDDLE_LEN;
endLen = VOLT_IC_URL_PARAMS_END_LEN;
}
else
{
middle = (char *)0;
end = (char *)0;
middleLen = 0;
endLen = 0;
}
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_MEMORY;
totalLen = prefixLen + serverLen + middleLen + addressLen + endLen;
retVal = (char *)Z3Malloc (totalLen + 1);
if (retVal == (char *)0)
break;
*result = retVal;
retVal[totalLen] = 0;
Z2Memcpy (retVal, prefix, prefixLen);
retVal += prefixLen;
Z2Memcpy (retVal, server, serverLen);
retVal += serverLen;
Z2Memcpy (retVal, middle, middleLen);
retVal += middleLen;
Z2Memcpy (retVal, address, addressLen);
retVal += addressLen;
Z2Memcpy (retVal, end, endLen);
status = 0;
} while (0);
VOLT_LOG_ERROR_COMPARE (
status, (VtLibCtx)libCtx, status, VT_ERROR_TYPE_PRIMARY, fnctLine,
"icBuildURLAlloc", (char *)0)
return (status);
}
int icStringXMLEscapeAlloc(
VoltLibCtx* libCtx,
char* str,
char** escapedStr
)
{
int status = 0;
int length;
int escapeSequenceLength;
char* p;
char* q;
char* escapeSequence;
char c;
VOLT_DECLARE_FNCT_LINE (fnctLine)
do
{
if (str == (char*)0)
{
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_NULL_ARG;
break;
}
length = Z2Strlen(str);
/* Look for XML characters that will be escaped and adjust the length
* for the length of the entity reference.
*/
p = str;
while ((c = *p++) != 0)
{
if ((c == '<') || (c == '>'))
{
length += 3;
}
else if ((c == '"') || (c == '\''))
{
length += 5;
}
else if (c == '&')
{
length += 4;
}
}
/* Allocate the escaped string */
*escapedStr = Z3Malloc(length + 1); // add 1 for null terminator
if (*escapedStr == (Pointer)0)
{
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_MEMORY;
break;
}
/* Copy over the input string, replacing the XML metacharacters with
* the appropriate entity reference.
*/
p = str;
q = *escapedStr;
while ((c = *p++) != 0)
{
if (c == '<')
{
escapeSequence = "<";
}
else if (c == '>')
{
escapeSequence = ">";
}
else if (c == '&')
{
escapeSequence = "&";
}
else if (c == '"')
{
escapeSequence = """;
}
else if (c == '\'')
{
escapeSequence = "'";
}
else
{
escapeSequence = (char*)0;
*q++ = c;
}
if (escapeSequence != (char*)0)
{
escapeSequenceLength = Z2Strlen(escapeSequence);
Z2Memcpy(q, escapeSequence, escapeSequenceLength);
q += escapeSequenceLength;
}
}
/* Add the null terminator */
*q = 0;
}
while (0);
VOLT_LOG_ERROR_COMPARE (
status, (VtLibCtx)libCtx, status, VT_ERROR_TYPE_PRIMARY, fnctLine,
"icStringXMLEscapeAlloc", (char *)0)
return status;
}
int icBuildServerRequestAlloc (
VoltLibCtx *libCtx,
char *requestData,
char *authTokens,
char *id64,
char *certReq64,
char **result
)
{
int status;
unsigned int reqLen, tokenLen, id64Len, certReqLen;
unsigned int part4Len, part5Len, totalLen;
char *part1, *part2, *part3, *part4, *part5;
char *retVal = (char *)0;
VOLT_DECLARE_FNCT_LINE (fnctLine)
do
{
reqLen = Z2Strlen (requestData);
tokenLen = Z2Strlen (authTokens);
id64Len = Z2Strlen (id64);
certReqLen = 0;
if (certReq64 != (char *)0)
certReqLen = Z2Strlen (certReq64);
part1 = VOLT_IC_SERVER_REQ_PART_1;
part2 = VOLT_IC_SERVER_REQ_PART_2;
part3 = VOLT_IC_SERVER_REQ_PART_3;
if (certReqLen != 0)
{
part4 = VOLT_IC_SERVER_REQ_PART_4_REQ;
part5 = VOLT_IC_SERVER_REQ_PART_5_REQ;
part4Len = VOLT_IC_SERVER_REQ_PART_4_REQ_LEN;
part5Len = VOLT_IC_SERVER_REQ_PART_5_REQ_LEN;
}
else
{
part4 = VOLT_IC_SERVER_REQ_PART_4_NO_REQ;
part5 = VOLT_IC_SERVER_REQ_PART_5_NO_REQ;
part4Len = VOLT_IC_SERVER_REQ_PART_4_NO_REQ_LEN;
part5Len = VOLT_IC_SERVER_REQ_PART_5_NO_REQ_LEN;
}
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_MEMORY;
totalLen =
VOLT_IC_SERVER_REQ_PART_1_LEN + reqLen +
VOLT_IC_SERVER_REQ_PART_2_LEN + tokenLen +
VOLT_IC_SERVER_REQ_PART_3_LEN + id64Len +
part4Len + certReqLen + part5Len;
retVal = (char *)Z3Malloc (totalLen + 1);
if (retVal == (char *)0)
break;
*result = retVal;
retVal[totalLen] = 0;
Z2Memcpy (retVal, part1, VOLT_IC_SERVER_REQ_PART_1_LEN);
retVal += VOLT_IC_SERVER_REQ_PART_1_LEN;
Z2Memcpy (retVal, requestData, reqLen);
retVal += reqLen;
Z2Memcpy (retVal, part2, VOLT_IC_SERVER_REQ_PART_2_LEN);
retVal += VOLT_IC_SERVER_REQ_PART_2_LEN;
Z2Memcpy (retVal, authTokens, tokenLen);
retVal += tokenLen;
Z2Memcpy (retVal, part3, VOLT_IC_SERVER_REQ_PART_3_LEN);
retVal += VOLT_IC_SERVER_REQ_PART_3_LEN;
Z2Memcpy (retVal, id64, id64Len);
retVal += id64Len;
Z2Memcpy (retVal, part4, part4Len);
retVal += part4Len;
Z2Memcpy (retVal, certReq64, certReqLen);
retVal += certReqLen;
Z2Memcpy (retVal, part5, part5Len);
status = 0;
} while (0);
VOLT_LOG_ERROR_COMPARE (
status, (VtLibCtx)libCtx, status, VT_ERROR_TYPE_PRIMARY, fnctLine,
"icBuildServerRequestAlloc", (char *)0)
return (status);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -