本文整理汇总了C++中CDateTime::Reset方法的典型用法代码示例。如果您正苦于以下问题:C++ CDateTime::Reset方法的具体用法?C++ CDateTime::Reset怎么用?C++ CDateTime::Reset使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CDateTime
的用法示例。
在下文中一共展示了CDateTime::Reset方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CreateFileDownloadResponse
int CWebServer::CreateFileDownloadResponse(struct MHD_Connection *connection, const string &strURL, HTTPMethod methodType, struct MHD_Response *&response, int &responseCode)
{
CFile *file = new CFile();
#ifdef WEBSERVER_DEBUG
CLog::Log(LOGDEBUG, "webserver [IN] %s", strURL.c_str());
multimap<string, string> headers;
if (GetRequestHeaderValues(connection, MHD_HEADER_KIND, headers) > 0)
{
for (multimap<string, string>::const_iterator header = headers.begin(); header != headers.end(); header++)
CLog::Log(LOGDEBUG, "webserver [IN] %s: %s", header->first.c_str(), header->second.c_str());
}
#endif
if (file->Open(strURL, READ_NO_CACHE))
{
bool getData = true;
bool ranged = false;
int64_t fileLength = file->GetLength();
// try to get the file's last modified date
CDateTime lastModified;
if (!GetLastModifiedDateTime(file, lastModified))
lastModified.Reset();
// get the MIME type for the Content-Type header
CStdString ext = URIUtils::GetExtension(strURL);
ext = ext.ToLower();
string mimeType = CreateMimeTypeFromExtension(ext.c_str());
if (methodType != HEAD)
{
int64_t firstPosition = 0;
int64_t lastPosition = fileLength - 1;
uint64_t totalLength = 0;
HttpFileDownloadContext *context = new HttpFileDownloadContext();
context->file = file;
context->rangesLength = fileLength;
context->contentType = mimeType;
context->boundaryWritten = false;
context->writePosition = 0;
if (methodType == GET)
{
// handle If-Modified-Since
string ifModifiedSince = GetRequestHeaderValue(connection, MHD_HEADER_KIND, "If-Modified-Since");
if (!ifModifiedSince.empty() && lastModified.IsValid())
{
CDateTime ifModifiedSinceDate;
ifModifiedSinceDate.SetFromRFC1123DateTime(ifModifiedSince);
if (lastModified.GetAsUTCDateTime() <= ifModifiedSinceDate)
{
getData = false;
response = MHD_create_response_from_data(0, NULL, MHD_NO, MHD_NO);
responseCode = MHD_HTTP_NOT_MODIFIED;
}
}
if (getData)
{
// handle Range header
context->rangesLength = ParseRangeHeader(GetRequestHeaderValue(connection, MHD_HEADER_KIND, "Range"), fileLength, context->ranges, firstPosition, lastPosition);
// handle If-Range header but only if the Range header is present
if (!context->ranges.empty())
{
string ifRange = GetRequestHeaderValue(connection, MHD_HEADER_KIND, "If-Range");
if (!ifRange.empty() && lastModified.IsValid())
{
CDateTime ifRangeDate;
ifRangeDate.SetFromRFC1123DateTime(ifRange);
// check if the last modification is newer than the If-Range date
// if so we have to server the whole file instead
if (lastModified.GetAsUTCDateTime() > ifRangeDate)
context->ranges.clear();
}
}
}
}
if (getData)
{
// if there are no ranges, add the whole range
if (context->ranges.empty() || context->rangesLength == fileLength)
{
if (context->rangesLength == fileLength)
context->ranges.clear();
context->ranges.push_back(HttpRange(0, fileLength - 1));
context->rangesLength = fileLength;
firstPosition = 0;
lastPosition = fileLength - 1;
}
else
responseCode = MHD_HTTP_PARTIAL_CONTENT;
// remember the total number of ranges
context->rangeCount = context->ranges.size();
//.........这里部分代码省略.........
示例2: CreateFileDownloadResponse
int CWebServer::CreateFileDownloadResponse(struct MHD_Connection *connection, const string &strURL, HTTPMethod methodType, struct MHD_Response *&response, int &responseCode)
{
boost::shared_ptr<CFile> file = boost::make_shared<CFile>();
#ifdef WEBSERVER_DEBUG
CLog::Log(LOGDEBUG, "webserver [IN] %s", strURL.c_str());
multimap<string, string> headers;
if (GetRequestHeaderValues(connection, MHD_HEADER_KIND, headers) > 0)
{
for (multimap<string, string>::const_iterator header = headers.begin(); header != headers.end(); header++)
CLog::Log(LOGDEBUG, "webserver [IN] %s: %s", header->first.c_str(), header->second.c_str());
}
#endif
if (!file->Open(strURL, READ_NO_CACHE))
{
CLog::Log(LOGERROR, "WebServer: Failed to open %s", strURL.c_str());
return SendErrorResponse(connection, MHD_HTTP_NOT_FOUND, methodType);
}
bool getData = true;
bool ranged = false;
int64_t fileLength = file->GetLength();
// try to get the file's last modified date
CDateTime lastModified;
if (!GetLastModifiedDateTime(file.get(), lastModified))
lastModified.Reset();
// get the MIME type for the Content-Type header
std::string ext = URIUtils::GetExtension(strURL);
StringUtils::ToLower(ext);
string mimeType = CreateMimeTypeFromExtension(ext.c_str());
if (methodType != HEAD)
{
int64_t firstPosition = 0;
int64_t lastPosition = fileLength - 1;
uint64_t totalLength = 0;
std::auto_ptr<HttpFileDownloadContext> context(new HttpFileDownloadContext());
context->file = file;
context->rangesLength = fileLength;
context->contentType = mimeType;
context->boundaryWritten = false;
context->writePosition = 0;
if (methodType == GET)
{
bool cacheable = true;
// handle Cache-Control
string cacheControl = GetRequestHeaderValue(connection, MHD_HEADER_KIND, MHD_HTTP_HEADER_CACHE_CONTROL);
if (!cacheControl.empty())
{
vector<string> cacheControls = StringUtils::Split(cacheControl, ",");
for (vector<string>::const_iterator it = cacheControls.begin(); it != cacheControls.end(); ++it)
{
string control = *it;
control = StringUtils::Trim(control);
// handle no-cache
if (control.compare(HEADER_VALUE_NO_CACHE) == 0)
cacheable = false;
}
}
if (cacheable)
{
// handle Pragma (but only if "Cache-Control: no-cache" hasn't been set)
string pragma = GetRequestHeaderValue(connection, MHD_HEADER_KIND, MHD_HTTP_HEADER_PRAGMA);
if (pragma.compare(HEADER_VALUE_NO_CACHE) == 0)
cacheable = false;
}
if (lastModified.IsValid())
{
// handle If-Modified-Since or If-Unmodified-Since
string ifModifiedSince = GetRequestHeaderValue(connection, MHD_HEADER_KIND, MHD_HTTP_HEADER_IF_MODIFIED_SINCE);
string ifUnmodifiedSince = GetRequestHeaderValue(connection, MHD_HEADER_KIND, MHD_HTTP_HEADER_IF_UNMODIFIED_SINCE);
CDateTime ifModifiedSinceDate;
CDateTime ifUnmodifiedSinceDate;
// handle If-Modified-Since (but only if the response is cacheable)
if (cacheable &&
ifModifiedSinceDate.SetFromRFC1123DateTime(ifModifiedSince) &&
lastModified.GetAsUTCDateTime() <= ifModifiedSinceDate)
{
getData = false;
response = MHD_create_response_from_data(0, NULL, MHD_NO, MHD_NO);
if (response == NULL)
return MHD_NO;
responseCode = MHD_HTTP_NOT_MODIFIED;
}
// handle If-Unmodified-Since
else if (ifUnmodifiedSinceDate.SetFromRFC1123DateTime(ifUnmodifiedSince) &&
lastModified.GetAsUTCDateTime() > ifUnmodifiedSinceDate)
return SendErrorResponse(connection, MHD_HTTP_PRECONDITION_FAILED, methodType);
}
//.........这里部分代码省略.........