本文整理汇总了C++中NPT_HttpRequest::GetProtocol方法的典型用法代码示例。如果您正苦于以下问题:C++ NPT_HttpRequest::GetProtocol方法的具体用法?C++ NPT_HttpRequest::GetProtocol怎么用?C++ NPT_HttpRequest::GetProtocol使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NPT_HttpRequest
的用法示例。
在下文中一共展示了NPT_HttpRequest::GetProtocol方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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);
}
示例2: stream
/*----------------------------------------------------------------------
| PLT_HttpHelper::ToLog
+---------------------------------------------------------------------*/
NPT_Result
PLT_HttpHelper::ToLog(NPT_LoggerReference logger,
int level,
const NPT_HttpRequest& request)
{
NPT_COMPILER_UNUSED(logger);
NPT_COMPILER_UNUSED(level);
NPT_StringOutputStreamReference stream(new NPT_StringOutputStream);
NPT_OutputStreamReference output = stream;
request.GetHeaders().GetHeaders().Apply(NPT_HttpHeaderPrinter(output));
NPT_LOG_L4(logger, level, "\n%s %s %s\n%s",
(const char*)request.GetMethod(),
(const char*)request.GetUrl().ToRequestString(true),
(const char*)request.GetProtocol(),
(const char*)stream->GetString());
return NPT_SUCCESS;
}
示例3: processSsdpSearch
void FrontEnd::processSsdpSearch(SsdpServerTask *task, Interface *intf, const NPT_DataBuffer& data, const NPT_SocketAddress& fromAddr)
{
do {
NPT_HttpRequest *req;
NPT_InputStreamReference inputStream0(new NPT_MemoryStream(data.GetData(), data.GetDataSize()));
NPT_BufferedInputStream inputStream(inputStream0);
if (NPT_FAILED(NPT_HttpRequest::Parse(inputStream, NULL, req))) {
break;
}
PtrHolder<NPT_HttpRequest> req1(req);
if (req->GetMethod().Compare("M-SEARCH") != 0 || req->GetProtocol().Compare(NPT_HTTP_PROTOCOL_1_1) != 0 || req->GetUrl().GetPath().Compare("*") != 0) {
break;
}
NPT_HttpHeader *hdrMan = req->GetHeaders().GetHeader("MAN");
if (!hdrMan || hdrMan->GetValue().Compare("\"ssdp:discover\"") != 0) {
break;
}
NPT_HttpHeader *hdrHost = req->GetHeaders().GetHeader("HOST");
if (!hdrHost || (hdrHost->GetValue().Compare("239.255.255.250:1900") != 0 && hdrHost->GetValue().Compare("239.255.255.250") != 0)) {
break;
}
int mx;
NPT_HttpHeader *hdrMX = req->GetHeaders().GetHeader("MX");
if (!hdrMX || NPT_FAILED(NPT_ParseInteger(hdrMX->GetValue(), mx)) || mx < 1) {
break;
}
if (mx > 120) {
mx = 120;
}
NPT_HttpHeader *hdrST = req->GetHeaders().GetHeader("ST");
if (!hdrST) {
break;
}
NPT_List<MatchContext*> matchList;
NPT_UdpSocket sock(NPT_SOCKET_FLAG_CANCELLABLE);
sock.Bind(NPT_SocketAddress(intf->m_context.m_ifAddr, 0));
NPT_SharedVariable waitVar;
waitVar.SetValue(0);
{
ReadLocker locker(m_dsLock);
for (NPT_Ordinal i = 0; i < m_deviceImplList.GetItemCount(); i++) {
NPT_List<DeviceImplInfo*>::Iterator it = m_deviceImplList.GetItem(i);
DeviceImplInfo *info = *it;
MatchContext *matchContext = new MatchContext();
if (info->m_deviceImpl->match(hdrST->GetValue(), matchContext->matches)) {
matchList.Add(matchContext);
matchContext->deviceUuid = info->m_deviceImpl->uuid();
matchContext->expireSeconds = info->m_deviceImpl->m_expireSeconds;
matchContext->descPath = info->m_deviceImpl->m_descPath;
matchContext->httpRoot = info->m_context.m_httpRoot;
} else {
delete matchContext;
}
}
}
SsdpSearchAbortCallback abortCallback(&sock, &waitVar);
if (task->registerAbortCallback(&abortCallback)) {
for (NPT_Ordinal i = 0; i < matchList.GetItemCount(); i++) {
MatchContext *matchContext = *matchList.GetItem(i);
NPT_String location = NPT_String::Format("http://%s:%d%s%s", intf->m_context.m_ifAddr.ToString().GetChars(), intf->m_context.m_httpPort, matchContext->httpRoot.GetChars(), matchContext->descPath.GetChars());
bool broken = false;
for (NPT_Ordinal j = 0; j < matchContext->matches.GetItemCount(); j++) {
NPT_List<DeviceImplMatch>::Iterator it2 = matchContext->matches.GetItem(j);
NPT_Timeout timeout = NPT_System::GetRandomInteger() % (mx * 1000);
// TODO: wait or not ???
timeout = 0;
if (NPT_SUCCEEDED(waitVar.WaitWhileEquals(0, timeout))) {
break;
}
{
ReadLocker locker(m_dsLock);
if (m_deviceImplIndex.HasKey(matchContext->deviceUuid)) {
NPT_TimeStamp ts;
NPT_System::GetCurrentTimeStamp(ts);
NPT_String dateStr = NPT_DateTime(ts).ToString(NPT_DateTime::FORMAT_RFC_1123);
NPT_String resp = NPT_String::Format("HTTP/1.1 200 OK\r\nCACHE-CONTROL: max-age=%d\r\nDATE: %s\r\nEXT: \r\nLOCATION: %s\r\nSERVER: %s\r\nST: %s\r\nUSN: %s\r\nCUSTOM:%s\r\n\r\n",
matchContext->expireSeconds, dateStr.GetChars(), location.GetChars(), m_serverHeader.GetChars(), it2->m_st.GetChars(), it2->m_usn.GetChars(), m_DevName.GetChars());
NPT_DataBuffer packet(resp.GetChars(), resp.GetLength(), false);
sock.Send(packet, &fromAddr);
}
}
}
if (broken) {
//.........这里部分代码省略.........