本文整理汇总了C++中NPT_InputStreamReference::IsNull方法的典型用法代码示例。如果您正苦于以下问题:C++ NPT_InputStreamReference::IsNull方法的具体用法?C++ NPT_InputStreamReference::IsNull怎么用?C++ NPT_InputStreamReference::IsNull使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NPT_InputStreamReference
的用法示例。
在下文中一共展示了NPT_InputStreamReference::IsNull方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: query
/*----------------------------------------------------------------------
| CMediaCrawler::ProcessFileRequest
+---------------------------------------------------------------------*/
NPT_Result
CMediaCrawler::ProcessFileRequest(NPT_HttpRequest& request,
NPT_HttpResponse& response,
NPT_SocketInfo& info)
{
NPT_COMPILER_UNUSED(info);
NPT_LOG_FINE("CMediaCrawler::ProcessFileRequest Received Request:");
PLT_LOG_HTTP_MESSAGE(NPT_LOG_LEVEL_FINE, &request);
if (request.GetMethod().Compare("GET") && request.GetMethod().Compare("HEAD")) {
response.SetStatus(500, "Internal Server Error");
return NPT_SUCCESS;
}
// add the user agent header, some stupid media servers like YME needs it
if (!request.GetHeaders().GetHeader(NPT_HTTP_HEADER_USER_AGENT)) {
request.GetHeaders().SetHeader(NPT_HTTP_HEADER_USER_AGENT,
"Platinum/" PLT_PLATINUM_VERSION_STRING);
}
// File requested
NPT_HttpResponse* out_response = NULL;
NPT_HttpUrlQuery query(request.GetUrl().GetQuery());
const char* url = query.GetField("url");
if (url) {
// look for handler
CStreamHandler* handler = NULL;
NPT_ContainerFind(m_StreamHandlers, CStreamHandlerFinder(NULL, url), handler);
if (handler && NPT_SUCCEEDED(handler->ProcessFileRequest(request, out_response)) && out_response) {
// copy response code and reason
response.SetStatus(out_response->GetStatusCode(), out_response->GetReasonPhrase());
// copy headers
NPT_List<NPT_HttpHeader*>::Iterator headers = out_response->GetHeaders().GetHeaders().GetFirstItem();
while (headers) {
response.GetHeaders().SetHeader((*headers)->GetName(), (*headers)->GetValue());
++headers;
}
response.SetEntity(new NPT_HttpEntity(response.GetHeaders()));
// update inputstream
NPT_HttpEntity* out_entity;
if ((out_entity = out_response->GetEntity()) != NULL) {
NPT_InputStreamReference inputstream;
out_entity->GetInputStream(inputstream);
if (!inputstream.IsNull()) {
// set the stream but do not update the content length
response.GetEntity()->SetInputStream(inputstream, false);
}
}
delete out_response;
return NPT_SUCCESS;
}
}
response.SetStatus(404, "File Not Found");
return NPT_SUCCESS;
}
示例2: tmp_context
/*----------------------------------------------------------------------
| PLT_HttpServer::ServeFile
+---------------------------------------------------------------------*/
NPT_Result
PLT_HttpServer::ServeFile(const NPT_HttpRequest& request,
const NPT_HttpRequestContext& context,
NPT_HttpResponse& response,
NPT_String file_path)
{
NPT_InputStreamReference stream;
NPT_File file(file_path);
NPT_FileInfo file_info;
// prevent hackers from accessing files outside of our root
if ((file_path.Find("/..") >= 0) || (file_path.Find("\\..") >= 0) ||
NPT_FAILED(NPT_File::GetInfo(file_path, &file_info))) {
return NPT_ERROR_NO_SUCH_ITEM;
}
// check for range requests
const NPT_String* range_spec = request.GetHeaders().GetHeaderValue(NPT_HTTP_HEADER_RANGE);
// handle potential 304 only if range header not set
NPT_DateTime date;
NPT_TimeStamp timestamp;
if (NPT_SUCCEEDED(PLT_UPnPMessageHelper::GetIfModifiedSince((NPT_HttpMessage&)request, date)) &&
!range_spec) {
date.ToTimeStamp(timestamp);
NPT_LOG_INFO_5("File %s timestamps: request=%d (%s) vs file=%d (%s)",
(const char*)request.GetUrl().GetPath(),
(NPT_UInt32)timestamp.ToSeconds(),
(const char*)date.ToString(),
(NPT_UInt32)file_info.m_ModificationTime,
(const char*)NPT_DateTime(file_info.m_ModificationTime).ToString());
if (timestamp >= file_info.m_ModificationTime) {
// it's a match
NPT_LOG_FINE_1("Returning 304 for %s", request.GetUrl().GetPath().GetChars());
response.SetStatus(304, "Not Modified", NPT_HTTP_PROTOCOL_1_1);
return NPT_SUCCESS;
}
}
// open file
if (NPT_FAILED(file.Open(NPT_FILE_OPEN_MODE_READ)) ||
NPT_FAILED(file.GetInputStream(stream)) ||
stream.IsNull()) {
return NPT_ERROR_NO_SUCH_ITEM;
}
// set Last-Modified and Cache-Control headers
if (file_info.m_ModificationTime) {
NPT_DateTime last_modified = NPT_DateTime(file_info.m_ModificationTime);
response.GetHeaders().SetHeader("Last-Modified", last_modified.ToString(NPT_DateTime::FORMAT_RFC_1123), true);
response.GetHeaders().SetHeader("Cache-Control", "max-age=0,must-revalidate", true);
//response.GetHeaders().SetHeader("Cache-Control", "max-age=1800", true);
}
PLT_HttpRequestContext tmp_context(request, context);
return ServeStream(request, context, response, stream, PLT_MimeType::GetMimeType(file_path, &tmp_context));
}
示例3:
/*----------------------------------------------------------------------
| PLT_Downloader::ProcessResponse
+---------------------------------------------------------------------*/
NPT_Result
PLT_Downloader::ProcessResponse(NPT_Result res,
const NPT_HttpRequest& request,
const NPT_HttpRequestContext& context,
NPT_HttpResponse* response)
{
NPT_COMPILER_UNUSED(request);
NPT_COMPILER_UNUSED(context);
if (NPT_FAILED(res)) {
NPT_LOG_WARNING_2("Downloader error %d for %s", res, m_URL.ToString().GetChars());
m_State = PLT_DOWNLOADER_ERROR;
return res;
}
m_State = PLT_DOWNLOADER_DOWNLOADING;
NPT_HttpEntity* entity;
NPT_InputStreamReference body;
if (!response ||
!(entity = response->GetEntity()) ||
NPT_FAILED(entity->GetInputStream(body)) ||
body.IsNull()) {
m_State = PLT_DOWNLOADER_ERROR;
NPT_LOG_WARNING_2("No body %d for %s", res, m_URL.ToString().GetChars());
return NPT_FAILURE;
}
// Read body (no content length means until socket is closed)
res = NPT_StreamToStreamCopy(*body.AsPointer(),
*m_Output.AsPointer(),
0,
entity->GetContentLength());
if (NPT_FAILED(res)) {
NPT_LOG_WARNING_2("Downloader error %d for %s", res, m_URL.ToString().GetChars());
m_State = PLT_DOWNLOADER_ERROR;
return res;
}
NPT_LOG_INFO_1("Finished downloading %s", m_URL.ToString().GetChars());
m_State = PLT_DOWNLOADER_SUCCESS;
return NPT_SUCCESS;
}
示例4:
/*----------------------------------------------------------------------
| PLT_HttpHelper::IsBodyStreamSeekable
+---------------------------------------------------------------------*/
bool
PLT_HttpHelper::IsBodyStreamSeekable(NPT_HttpMessage& message)
{
NPT_HttpEntity* entity = message.GetEntity();
NPT_InputStreamReference stream;
if (!entity ||
NPT_FAILED(entity->GetInputStream(stream)) ||
stream.IsNull()) {
return true;
}
// try to get current position and seek there
NPT_Position position;
if (NPT_FAILED(stream->Tell(position)) ||
NPT_FAILED(stream->Seek(position))) {
return false;
}
return true;
}
示例5:
/*----------------------------------------------------------------------
| PLT_Downloader::ProcessResponse
+---------------------------------------------------------------------*/
NPT_Result
PLT_Downloader::ProcessResponse(NPT_Result res,
NPT_HttpRequest* request,
const NPT_HttpRequestContext& context,
NPT_HttpResponse* response)
{
NPT_COMPILER_UNUSED(request);
NPT_COMPILER_UNUSED(context);
if (NPT_FAILED(res)) {
m_State = PLT_DOWNLOADER_ERROR;
return res;
}
m_State = PLT_DOWNLOADER_DOWNLOADING;
NPT_HttpEntity* entity;
NPT_InputStreamReference body;
if (!response || !(entity = response->GetEntity()) ||
NPT_FAILED(entity->GetInputStream(body)) || body.IsNull()) {
m_State = PLT_DOWNLOADER_ERROR;
return NPT_FAILURE;
}
// Read body (no content length means until socket is closed)
res = NPT_StreamToStreamCopy(*body.AsPointer(),
*m_Output.AsPointer(),
0,
entity->GetContentLength());
if (NPT_FAILED(res)) {
m_State = PLT_DOWNLOADER_ERROR;
return res;
}
m_State = PLT_DOWNLOADER_SUCCESS;
return NPT_SUCCESS;
}