本文整理汇总了C++中NPT_HttpEntity::SetInputStream方法的典型用法代码示例。如果您正苦于以下问题:C++ NPT_HttpEntity::SetInputStream方法的具体用法?C++ NPT_HttpEntity::SetInputStream怎么用?C++ NPT_HttpEntity::SetInputStream使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NPT_HttpEntity
的用法示例。
在下文中一共展示了NPT_HttpEntity::SetInputStream方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SetupResponse
NPT_Result SetupResponse(NPT_HttpRequest& /*request*/,
const NPT_HttpRequestContext& /*context*/,
NPT_HttpResponse& response) {
NPT_HttpEntity* entity = response.GetEntity();
entity->SetContentType("text/html");
entity->SetInputStream("<html><body>Bye Bye!</body></html>");
KillRequest = true;
return NPT_SUCCESS;
}
示例2: query
/*----------------------------------------------------------------------
| CUPnPRenderer::ProcessHttpRequest
+---------------------------------------------------------------------*/
NPT_Result
CUPnPRenderer::ProcessHttpGetRequest(NPT_HttpRequest& request,
const NPT_HttpRequestContext& context,
NPT_HttpResponse& response)
{
// get the address of who sent us some data back
NPT_String ip_address = context.GetRemoteAddress().GetIpAddress().ToString();
NPT_String method = request.GetMethod();
NPT_String protocol = request.GetProtocol();
NPT_HttpUrl url = request.GetUrl();
if (url.GetPath() == "/thumb") {
NPT_HttpUrlQuery query(url.GetQuery());
NPT_String filepath = query.GetField("path");
if (!filepath.IsEmpty()) {
NPT_HttpEntity* entity = response.GetEntity();
if (entity == NULL) return NPT_ERROR_INVALID_STATE;
// check the method
if (request.GetMethod() != NPT_HTTP_METHOD_GET &&
request.GetMethod() != NPT_HTTP_METHOD_HEAD) {
response.SetStatus(405, "Method Not Allowed");
return NPT_SUCCESS;
}
// prevent hackers from accessing files outside of our root
if ((filepath.Find("/..") >= 0) || (filepath.Find("\\..") >=0)) {
return NPT_FAILURE;
}
#if 1
std::string path;
//url
#else
// open the file
CStdString path = CURL::Decode((const char*) filepath);
#endif
NPT_File file(path.c_str());
NPT_Result result = file.Open(NPT_FILE_OPEN_MODE_READ);
if (NPT_FAILED(result)) {
response.SetStatus(404, "Not Found");
return NPT_SUCCESS;
}
NPT_InputStreamReference stream;
file.GetInputStream(stream);
entity->SetContentType(GetMimeType(filepath));
entity->SetInputStream(stream, true);
return NPT_SUCCESS;
}
}
return PLT_MediaRenderer::ProcessHttpGetRequest(request, context, response);
}
示例3:
/*----------------------------------------------------------------------
| NPT_HttpLoggerConfigurator::SetupResponse
+---------------------------------------------------------------------*/
NPT_Result
NPT_HttpLoggerConfigurator::SetupResponse(NPT_HttpRequest& request,
const NPT_HttpRequestContext& /*context*/,
NPT_HttpResponse& response)
{
// we only support GET here
if (request.GetMethod() != NPT_HTTP_METHOD_GET) return NPT_ERROR_HTTP_METHOD_NOT_SUPPORTED;
// construct the response message
NPT_String msg;
msg = "<ul>";
NPT_List<NPT_LogConfigEntry>& config = LogManager.GetConfig();
NPT_List<NPT_LogConfigEntry>::Iterator cit = config.GetFirstItem();
for (; cit; ++cit) {
NPT_LogConfigEntry& entry = (*cit);
msg += "<li>";
msg += entry.m_Key;
msg += "=";
msg += entry.m_Value;
msg += "</li>";
}
msg += "</ul>";
msg += "<ul>";
NPT_List<NPT_Logger*>& loggers = LogManager.GetLoggers();
NPT_List<NPT_Logger*>::Iterator lit = loggers.GetFirstItem();
for (;lit;++lit) {
NPT_Logger* logger = (*lit);
msg += "<li>";
msg += logger->GetName();
msg += ", level=";
msg += NPT_String::FromInteger(logger->GetLevel());
NPT_List<NPT_LogHandler*>& handlers = logger->GetHandlers();
NPT_List<NPT_LogHandler*>::Iterator hit = handlers.GetFirstItem();
msg += ", handlers=";
for (;hit;++hit) {
NPT_LogHandler* handler = (*hit);
msg += handler->ToString();
}
msg += "</li>";
}
msg += "</ul>";
// setup the response body
NPT_HttpEntity* entity = response.GetEntity();
entity->SetContentType("text/html");
entity->SetInputStream(msg);
return NPT_SUCCESS;
}
示例4: SetupResponse
/*----------------------------------------------------------------------
| PLT_HttpServerSocketTask::RespondToClient
+---------------------------------------------------------------------*/
NPT_Result
PLT_HttpServerSocketTask::RespondToClient(NPT_HttpRequest& request,
const NPT_HttpRequestContext& context,
NPT_HttpResponse*& response)
{
NPT_Result result = NPT_ERROR_NO_SUCH_ITEM;
// reset output params first
response = NULL;
// prepare the response body
NPT_HttpEntity* body = new NPT_HttpEntity();
response = new NPT_HttpResponse(200, "OK", NPT_HTTP_PROTOCOL_1_1);
response->SetEntity(body);
// ask to setup the response
result = SetupResponse(request, context, *response);
// handle result
if (result == NPT_ERROR_NO_SUCH_ITEM) {
body->SetInputStream(PLT_HTTP_DEFAULT_404_HTML);
body->SetContentType("text/html");
response->SetStatus(404, "Not Found");
} else if (result == NPT_ERROR_PERMISSION_DENIED) {
body->SetInputStream(PLT_HTTP_DEFAULT_403_HTML);
body->SetContentType("text/html");
response->SetStatus(403, "Forbidden");
} else if (result == NPT_ERROR_TERMINATED) {
// mark that we want to exit
delete response;
response = NULL;
} else if (NPT_FAILED(result)) {
body->SetInputStream(PLT_HTTP_DEFAULT_500_HTML);
body->SetContentType("text/html");
response->SetStatus(500, "Internal Error");
}
return NPT_SUCCESS;
}
示例5:
/*----------------------------------------------------------------------
| NPT_HttpMessage::SetBody
+---------------------------------------------------------------------*/
NPT_Result
PLT_HttpHelper::SetBody(NPT_HttpMessage* message, NPT_InputStreamReference& stream, NPT_Size len)
{
if (len == 0) {
NPT_CHECK_SEVERE(stream->GetAvailable(len));
}
// get the entity
NPT_HttpEntity* entity = message->GetEntity();
if (entity == NULL) {
// no entity yet, create one
message->SetEntity(entity = new NPT_HttpEntity());
}
// set the entity body
entity->SetInputStream(stream);
entity->SetContentLength(len);
return NPT_SUCCESS;
}
示例6: SetupResponse
NPT_Result SetupResponse(NPT_HttpRequest& request,
NPT_HttpResponse& response,
NPT_SocketInfo& /*info*/) {
NPT_String msg = "<HTML>";
msg += "PATH=";
msg += request.GetUrl().GetPath();
msg += " <P><UL>";
if (request.GetUrl().HasQuery()) {
NPT_HttpUrlQuery query(request.GetUrl().GetQuery());
for (NPT_List<NPT_HttpUrlQuery::Field>::Iterator it = query.GetFields().GetFirstItem();
it;
++it) {
NPT_HttpUrlQuery::Field& field = *it;
msg += "<LI>";
msg += field.m_Name;
msg += " = ";
msg += field.m_Value;
msg += " </LI>";
}
}
msg += "</UL></HTML>";
if (request.GetMethod() == NPT_HTTP_METHOD_POST) {
NPT_DataBuffer request_body;
request.GetEntity()->Load(request_body);
NPT_Debug("REQUEST: body = %d bytes\n", request_body.GetDataSize());
NPT_Debug("REQUEST: content type = %s\n", request.GetEntity()->GetContentType().GetChars());
if (request.GetEntity()->GetContentType().StartsWith("text") ||
request.GetEntity()->GetContentType() == "application/x-www-form-urlencoded") {
NPT_String body_string;
body_string.Assign((char*)request_body.GetData(), request_body.GetDataSize());
NPT_Debug("%s", body_string.GetChars());
}
}
NPT_HttpEntity* entity = response.GetEntity();
entity->SetContentType("text/html");
entity->SetInputStream(msg);
return NPT_SUCCESS;
}
示例7: body
/*----------------------------------------------------------------------
| PLT_HttpStreamRequestHandler::SetupResponse
+---------------------------------------------------------------------*/
NPT_Result
PLT_HttpStreamRequestHandler::SetupResponse(NPT_HttpRequest& request,
const NPT_HttpRequestContext& context,
NPT_HttpResponse& response)
{
PLT_LOG_HTTP_REQUEST(NPT_LOG_LEVEL_FINE, "PLT_HttpStreamRequestHandler::SetupResponse:", &request);
if (request.GetMethod().Compare("GET") &&
request.GetMethod().Compare("HEAD")) {
return NPT_FAILURE;
}
NPT_Reference<PLT_FrameBuffer> buffer;
if (!m_StreamValidator.OnNewRequestAccept(request, context, response, buffer)) {
return NPT_ERROR_NO_SUCH_ITEM;
}
response.SetProtocol(NPT_HTTP_PROTOCOL_1_0);
response.GetHeaders().SetHeader(NPT_HTTP_HEADER_CONNECTION, "close");
response.GetHeaders().SetHeader("Cache-Control", "no-store, no-cache, must-revalidate, pre-check=0, post-check=0, max-age=0");
response.GetHeaders().SetHeader("Pragma", "no-cache");
response.GetHeaders().SetHeader("Expires", "Tue, 4 Jan 2000 02:43:05 GMT");
// HEAD request has no entity or if status code is not 2xx
if (!request.GetMethod().Compare("HEAD") || response.GetStatusCode()/100 != 2)
return NPT_SUCCESS;
NPT_HttpEntity* entity = response.GetEntity();
NPT_CHECK_POINTER_FATAL(entity);
entity->SetContentType("multipart/x-mixed-replace;boundary=" BOUNDARY);
NPT_InputStreamReference body(new PLT_InputFrameStream(buffer, BOUNDARY));
entity->SetInputStream(body, false);
return NPT_SUCCESS;
}
示例8: lock
/*----------------------------------------------------------------------
| BtPlayerServer::SetupResponse
+---------------------------------------------------------------------*/
NPT_Result
BtPlayerServer::SetupResponse(NPT_HttpRequest& request,
const NPT_HttpRequestContext& /*context*/,
NPT_HttpResponse& response)
{
const NPT_Url& url = request.GetUrl();
const NPT_String& path = url.GetPath();
NPT_UrlQuery query;
// parse the query part, if any
if (url.HasQuery()) {
query.Parse(url.GetQuery());
}
// lock the player
NPT_AutoLock lock(m_Lock);
// handle form requests
if (path == "/") {
response.GetHeaders().SetHeader("Location", "/control/ajax");
response.SetStatus(301, "Moved Permanently");
return BLT_SUCCESS;
}
// handle form requests
if (path == "/control/form") {
return SendControlForm(response, NULL);
}
// handle status requests
if (path == "/player/status") {
return SendStatus(response, query);
}
// handle commands
const char* mode_field = query.GetField("mode");
const char* form_msg = "OK";
bool use_form = false;
if (mode_field && NPT_StringsEqual(mode_field, "form")) {
use_form = true;
}
if (path == "/player/set-input") {
const char* name_field = query.GetField("name");
if (name_field) {
NPT_String name = NPT_UrlQuery::UrlDecode(name_field);
m_Player.SetInput(name);
} else {
form_msg = "INVALID PARAMETERS";
}
} else if (path == "/player/set-output") {
const char* name_field = query.GetField("name");
if (name_field) {
NPT_String name = NPT_UrlQuery::UrlDecode(name_field);
m_Player.SetOutput(name);
} else {
form_msg = "INVALID PARAMETERS";
}
} else if (path == "/player/play") {
m_Player.Play();
} else if (path == "/player/pause") {
m_Player.Pause();
} else if (path == "/player/stop") {
m_Player.Stop();
} else if (path == "/player/seek") {
const char* timecode_field = query.GetField("timecode");
const char* position_field = query.GetField("position");
if (timecode_field) {
NPT_String timecode = NPT_UrlQuery::UrlDecode(timecode_field);
DoSeekToTimecode(timecode);
} else if (position_field) {
unsigned int position;
if (NPT_SUCCEEDED(NPT_ParseInteger(position_field, position))) {
m_Player.SeekToPosition(position, 100);
}
} else {
form_msg = "INVALID PARAMETER";
}
} else if (path == "/player/set-volume") {
const char* volume_field = query.GetField("volume");
if (volume_field) {
unsigned int volume;
if (NPT_SUCCEEDED(NPT_ParseInteger(volume_field, volume))) {
m_Player.SetVolume((float)volume/100.0f);
}
} else {
form_msg = "INVALID PARAMETER";
}
}
if (use_form) {
return SendControlForm(response, form_msg);
} else {
NPT_HttpEntity* entity = response.GetEntity();
entity->SetContentType("application/json");
entity->SetInputStream("{}");
return NPT_SUCCESS;
}
//.........这里部分代码省略.........
示例9: switch
/*----------------------------------------------------------------------
| BtPlayerServer::SendControlForm
+---------------------------------------------------------------------*/
NPT_Result
BtPlayerServer::SendControlForm(NPT_HttpResponse& response, const char* msg)
{
// create the html document
NPT_String html = "<html>";
// optional message
if (msg && msg[0]) {
html += "<";
html += msg;
html += "><p>";
}
// status
html += "<p><b>State: </b>";
switch (m_DecoderState) {
case BLT_DecoderServer::STATE_STOPPED:
html += "[STOPPED]";
break;
case BLT_DecoderServer::STATE_PLAYING:
html += "[PLAYING]";
break;
case BLT_DecoderServer::STATE_PAUSED:
html += "[PAUSED]";
break;
case BLT_DecoderServer::STATE_EOS:
html += "[END OF STREAM]";
break;
default:
html += "[UNKNOWN]";
break;
}
html += "</p><p><b>Time Code: </b>";
html += NPT_String::Format("\"%02d:%02d:%02d\"",
m_DecoderTimecode.h,
m_DecoderTimecode.m,
m_DecoderTimecode.s);
html += "</p>";
html += "<p>";
html += "<b>Content Format: </b>";
if (m_StreamInfo.data_type) {
html += m_StreamInfo.data_type;
}
html += "<br>";
// control form
html += BT_CONTROL_FORM;
html += "</html>";
// send the html document
NPT_HttpEntity* entity = response.GetEntity();
entity->SetContentType("text/html");
entity->SetInputStream(html);
return NPT_SUCCESS;
}