📄 sacommon.c
字号:
/* Copyright 2005-2006, Voltage Security, all rights reserved.
*/
#include "vibe.h"
#include "environment.h"
#include "base.h"
#include "libctx.h"
#include "sacommon.h"
#include "vtassert.h"
#include "errorctx.h"
#include "stringutil.h"
const char* VoltSecureArchiveEntryListAttributeName = "Attachments";
const char* VoltSecureArchiveEntryAttributeName = "Attachment";
const char* VoltSecureArchiveModDateAttributeName = "ModDate";
const char* VoltSecureArchiveNameAttributeName = "Name";
const char* VoltSecureArchiveCompressionAttributeName = "Compression";
const char* VoltSecureArchiveSizeAttributeName = "Size";
const char* VoltSecureArchiveCompressedSizeAttributeName = "CompressedSize";
const char* VoltSecureArchiveDateAttributeFormat = "%d %d %d %d %d %d";
const char* VoltSecureArchiveIndexFilePathName = "Index";
const char* VoltSecureArchiveFilePrefixPathName = "File_";
const char* VoltSecureArchiveHeadersName = "ZDMv2Headers";
const char* VoltSecureArchiveYearAttributeName = "Year";
const char* VoltSecureArchiveMonthAttributeName = "Month";
const char* VoltSecureArchiveDayAttributeName = "Day";
const char* VoltSecureArchiveHourAttributeName = "Hour";
const char* VoltSecureArchiveMinuteAttributeName = "Minute";
const char* VoltSecureArchiveSecondAttributeName = "Second";
int VoltCreateTempBufferStream(
VtLibCtx libCtx,
VtBufferTypeInfo* bufferTypeInfo,
VtStreamObject* tempStream
)
{
int status = 0;
VtStreamImplMemoryInfo memInfo;
VtStreamImplFileInfo fileInfo;
VOLT_DECLARE_FNCT_LINE(fnctLine)
VT_ASSERT(libCtx != (VtLibCtx)0);
VT_ASSERT(bufferTypeInfo != (VtBufferTypeInfo*)0);
VT_ASSERT(tempStream != (VtStreamObject*)0);
do
{
*tempStream = (VtStreamObject)0;
if (bufferTypeInfo->bufferType == VT_BUFFER_TYPE_MEMORY)
{
Z2Memset(&memInfo, 0, sizeof(memInfo));
memInfo.openMode = VT_STREAM_OPEN_READ_WRITE;
memInfo.flags = VT_STREAM_OPEN_ON_ACCESS;
VOLT_SET_FNCT_LINE(fnctLine)
status = VtCreateStreamObject(libCtx, VtStreamImplMemory,
(Pointer)&memInfo, tempStream);
}
else
{
VT_ASSERT(bufferTypeInfo->bufferType == VT_BUFFER_TYPE_FILE);
Z2Memset(&fileInfo, 0, sizeof(fileInfo));
fileInfo.fileCtx = bufferTypeInfo->fileCtx;
fileInfo.openMode = VT_STREAM_OPEN_TEMPORARY;
fileInfo.flags = VT_STREAM_OPEN_ON_ACCESS;
fileInfo.fileName = "vt_";
VOLT_SET_FNCT_LINE(fnctLine)
status = VtCreateStreamObject(libCtx, VtStreamImplFile,
(Pointer)&fileInfo, tempStream);
}
}
while (0);
VOLT_LOG_ERROR_COMPARE(status, libCtx, status, 0,
fnctLine, "VoltSecureArchiveCreateTempStream", (unsigned char*)0)
return status;
}
int VoltSecureArchiveFormatEntryExpression(
VtLibCtx libCtx,
unsigned int entryIndex,
const unsigned char* attributeName,
unsigned char* expression,
unsigned int expressionSize
)
{
int status = 0;
unsigned int length;
unsigned char* p;
VOLT_DECLARE_FNCT_LINE(fnctLine)
VT_ASSERT(libCtx != (VtLibCtx)0);
VT_ASSERT(attributeName != (unsigned char*)0);
VT_ASSERT(expression != (unsigned char*)0);
do
{
/* Copy over the top-level entry array node name to the
* expression. And the opening bracket for the array index.
*/
length = Z2Strlen(VoltSecureArchiveEntryListAttributeName);
VT_ASSERT(expressionSize > length + 10);
Z2Memcpy(expression, VoltSecureArchiveEntryListAttributeName, length);
p = expression + length;
*p++ = '[';
/* Convert the entryIndex to a string in the num buffer. We
* work backwards in the buffer, starting with the null
* terminator.
*/
VOLT_SET_FNCT_LINE(fnctLine)
status = VoltNumToDecimalString(entryIndex, p,
expression + expressionSize - p, libCtx);
if (status != 0)
break;
length = Z2Strlen(p);
p += length;
*p++ = ']';
*p++ = '.';
/* Now append the entry-level expression. Currently this
* should just be a simple name, but in theory it could be
* an expression (i.e. with nested elements). We also do a
* check for the length of the name passed in to make sure
* we won't overflow the buffer we allocated on the stack.
*/
length = Z2Strlen(attributeName);
if (length >= (unsigned int) (expression + expressionSize - p))
{
VOLT_SET_FNCT_LINE(fnctLine)
status = VT_ERROR_BUFFER_TOO_SMALL;
break;
}
Z2Memcpy(p, attributeName, length);
p += length;
*p++ = 0;
}
while (0);
VOLT_LOG_ERROR_COMPARE(status, libCtx, status, 0,
fnctLine, "VoltSecureArchiveFormatEntryExpression", (unsigned char*)0)
return status;
}
int VoltSecureArchiveHasConsecutiveEOL(
const unsigned char* text
)
{
const unsigned char* p;
unsigned char previousEOL = 0;
unsigned char c;
if (text != (const unsigned char*)0)
{
p = text;
while ((c = *p++) != 0)
{
if ((c == '\r') || (c == '\n'))
{
if (previousEOL)
return 1;
if ((c == '\r') && (*p == '\n'))
p++;
previousEOL = 1;
}
else
{
previousEOL = 0;
}
}
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -